// src/types.ts // ============================================================ // Error Type Hierarchy // ============================================================ export enum ErrorType { NETWORK_ERROR = 'network_error', API_ERROR = 'api_error', VALIDATION_ERROR = 'validation_error', STREAMING_ERROR = 'streaming_error', TOOL_EXECUTION_ERROR = 'tool_execution_error', PATH_VALIDATION_ERROR = 'path_validation_error', UNKNOWN_ERROR = 'unknown_error', } export class OllamaError extends Error { public readonly type: ErrorType; constructor(message: string, type: ErrorType) { super(message); this.type = type; Object.setPrototypeOf(this, OllamaError.prototype); } } export class NetworkError extends OllamaError { public readonly statusCode?: number; constructor(message: string, statusCode?: number) { super(message, ErrorType.NETWORK_ERROR); this.statusCode = statusCode; Object.setPrototypeOf(this, NetworkError.prototype); } } export class ApiError extends OllamaError { public readonly statusCode?: number; constructor(message: string, statusCode?: number) { super(message, ErrorType.API_ERROR); this.statusCode = statusCode; Object.setPrototypeOf(this, ApiError.prototype); } } export interface ValidationFieldDetails { field?: string; message?: string; } export class ValidationError extends OllamaError { public readonly details?: ValidationFieldDetails; constructor(message: string, details?: ValidationFieldDetails) { super(message, ErrorType.VALIDATION_ERROR); this.details = details; Object.setPrototypeOf(this, ValidationError.prototype); } } export class StreamingError extends OllamaError { constructor(message: string) { super(message, ErrorType.STREAMING_ERROR); Object.setPrototypeOf(this, StreamingError.prototype); } } export class ToolExecutionError extends OllamaError { public readonly toolName: string; constructor(message: string, toolName: string) { super(message, ErrorType.TOOL_EXECUTION_ERROR); this.toolName = toolName; Object.setPrototypeOf(this, ToolExecutionError.prototype); } } export class PathValidationError extends OllamaError { public readonly path: string; constructor(message: string, path: string) { super(message, ErrorType.PATH_VALIDATION_ERROR); this.path = path; Object.setPrototypeOf(this, PathValidationError.prototype); } } // ============================================================ // Plugin Configuration // ============================================================ export interface CacheConfig { enabled: boolean; similarityThreshold: number; collectionName: string; embeddingModel: string; } export interface PluginSettings { ollamaUrl: string; model: string; vaultSearchLimit: number; maxMessageHistory: number; lastIndexTime: number; cacheConfig: CacheConfig; } // ============================================================ // Ollama Protocol Types // ============================================================ export interface OllamaTool { type: 'function'; function: { name: string; description: string; parameters: { type: 'object'; properties: Record; required: string[]; }; }; } export interface OllamaToolCall { id: string; type: 'function'; function: { name: string; arguments: string | Record; }; } export interface OllamaMessage { role: 'system' | 'user' | 'assistant' | 'tool'; content: string; tool_calls?: OllamaToolCall[]; } // ============================================================ // Tool Execution Types // ============================================================ export interface ToolCall { id: string; type: 'function'; function: { name: string; arguments: string | Record; }; } export interface ToolResult { success: boolean; message: string; } export interface ExecutionResult { success: boolean; output: string; } // ============================================================ // Chat Message Types // ============================================================ export interface ChatMessage { id: string; role: 'user' | 'assistant'; content: string; timestamp: number; isStreaming?: boolean; tool_calls?: ToolCall[]; } // ============================================================ // Vault Index Types // ============================================================ export interface VaultIndexEntry { path: string; title: string; content: string; score: number; }