All files types.ts

100% Statements 35/35
100% Branches 2/2
100% Functions 8/8
100% Lines 35/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179            3x 3x 3x 3x 3x 3x 3x 3x     3x       19x 19x 19x       3x       4x 4x 4x       3x       5x 5x 5x                 3x       3x 3x 3x       3x   2x 2x       3x       2x 2x 2x       3x       2x 2x 2x                                                                                                                                                                                            
// 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 PluginSettings {
  ollamaUrl: string;
  model: string;
  vaultSearchLimit: number;
  maxMessageHistory: number;
  lastIndexTime: number;
}
 
// ============================================================
// Ollama Protocol Types
// ============================================================
 
export interface OllamaTool {
  type: 'function';
  function: {
    name: string;
    description: string;
    parameters: {
      type: 'object';
      properties: Record<string, unknown>;
      required: string[];
    };
  };
}
 
export interface OllamaToolCall {
  id: string;
  type: 'function';
  function: {
    name: string;
    arguments: string | Record<string, unknown>;
  };
}
 
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<string, unknown>;
  };
}
 
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;
}