All files / api/src/ai-providers/ollama types.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 0/0
100% Lines 13/13

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    1x                                                                                                               1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x      
import type { ErrorResponseBody } from '@shared/types/api/response/body';
import type { ChatCompletionResponseBody } from '@shared/types/api/routes/chat-completions-api';
import z from 'zod';
 
/**
 * Ollama chat completion response interface
 */
export interface OllamaChatCompleteResponse extends ChatCompletionResponseBody {
  system_fingerprint?: string;
  prompt_eval_count?: number;
  eval_count?: number;
}
 
/**
 * Ollama error response interface
 */
export interface OllamaErrorResponse extends ErrorResponseBody {
  error: {
    message: string;
    type?: string;
    code?: string;
  };
}
 
/**
 * Ollama stream chunk interface for streaming responses
 */
export interface OllamaStreamChunk {
  id: string;
  object: string;
  created: number;
  model: string;
  system_fingerprint?: string;
  choices: {
    delta: {
      role?: string;
      content?: string;
      tool_calls?: object[];
    };
    index: number;
    finish_reason: string | null;
  }[];
}
 
/**
 * Ollama embedding response interface
 */
export interface OllamaEmbedResponse {
  embedding: number[];
  model?: string;
  prompt_eval_count?: number;
  eval_count?: number;
}
 
/**
 * Custom fields schema for Ollama AI provider configuration
 * These fields are stored in the ai_providers.custom_fields JSONB column
 */
export const OllamaCustomFieldsSchema = z.object({
  custom_host: z
    .string()
    .url('Please enter a valid URL')
    .max(2048, 'URL is too long (maximum 2048 characters)')
    .refine(
      (url) => url.startsWith('http://') || url.startsWith('https://'),
      'Custom host must use HTTP or HTTPS protocol',
    )
    .optional()
    .describe('Custom Ollama server URL (e.g., http://localhost:11434)'),
});
 
export type OllamaCustomFields = z.infer<typeof OllamaCustomFieldsSchema>;