All files / src/llm-provider llm-provider.interface.ts

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

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                              19x 19x 19x 19x 19x 19x 19x                                                                                                                                           19x  
// Define content structure locally to avoid @google/genai dependency in interface
export interface LlmContentPart {
  text: string;
}
 
export interface LlmContent {
  role: 'user' | 'model' | 'tool';
  parts: LlmContentPart[];
  tool_calls?: LlmToolCall[]; // For tool call responses in history
  tool_call_id?: string; // For tool result messages (OpenAI/OpenRouter format)
  tool_name?: string; // For tool result messages (Ollama format)
  thoughts?: string; // Reasoning/thinking content for model responses
  shortId?: string; // Compact message ID for provider context (e.g. "a1b90")
}
 
export enum ReasoningEffort {
  XHIGH = 'xhigh',
  HIGH = 'high',
  MEDIUM = 'medium',
  LOW = 'low',
  MINIMAL = 'minimal',
  NONE = 'none',
}
 
export interface LlmReasoningConfig {
  effort?: ReasoningEffort;
}
 
export interface LlmGenerationConfig {
  temperature?: number;
  maxOutputTokens?: number;
  topP?: number;
  topK?: number;
  reasoning?: LlmReasoningConfig;
}
 
// Tool calling types
export interface LlmFunctionTool {
  type: 'function';
  function: {
    name: string;
    description: string;
    parameters: object; // JSON Schema
  };
}
 
export interface LlmToolCall {
  id: string;
  type: 'function' | 'web_search' | 'retrieval';
  function: {
    name: string;
    arguments: object | string; // Can be string during streaming accumulation
  };
}
 
export interface LlmProviderRequest {
  prompt: string;
  systemInstruction?: string;
  history?: LlmContent[];
  modelId?: string;
  generationConfig?: LlmGenerationConfig;
  tools?: LlmFunctionTool[];
  tool_choice?: 'auto' | 'required' | 'none';
  onToken?: (token: string, isFirst: boolean, thoughtChunk?: string) => void;
  abortController?: AbortController;
}
 
export interface LlmModel {
  id: string;
  name: string;
  provider: 'gemini' | 'openrouter' | 'zai' | 'alibaba' | 'ollama' | 'openai';
}
 
export interface LlmUsage {
  inputTokens?: number;
  outputTokens?: number;
  cachedTokens?: number;
}
 
export interface LlmResponse {
  text: string;
  usage?: LlmUsage;
  tool_calls?: LlmToolCall[];
  thoughts?: string;
}
 
export interface LlmProvider {
  generateContent(request: LlmProviderRequest): Promise<LlmResponse>;
  getModels(): Promise<LlmModel[]>;
}
 
export const LLM_PROVIDER = 'LLM_PROVIDER';