server/backend_provider.ts view source
Base class for all backend AI providers. Provides shared functionality for completion handlers and logging.
generics
TClient
unknownname
type string
client
type TClient | null
provider_status
type ProviderStatus | null
on_completion_progress
type OnCompletionProgress
constructor
type new <TClient = unknown>(options: BackendProviderOptions): BackendProvider<TClient>
options
handle_streaming_completion
type (options: CompletionHandlerOptions): Promise<{ completion_response: { created: string & $brand<"Datetime">; provider_name: "ollama" | "claude" | "chatgpt" | "gemini"; model: string; data: { ...; } | ... 2 more ... | { ...; }; }; _meta?: { ...; } | undefined; }>
options
Promise<{ completion_response: { created: string & $brand<"Datetime">; provider_name: "ollama" | "claude" | "chatgpt" | "gemini"; model: string; data: { type: "ollama"; value: any; } | { ...; } | { ...; } | { ...; }; }; _meta?: { ...; } | undefined; }>handle_non_streaming_completion
type (options: CompletionHandlerOptions): Promise<{ completion_response: { created: string & $brand<"Datetime">; provider_name: "ollama" | "claude" | "chatgpt" | "gemini"; model: string; data: { ...; } | ... 2 more ... | { ...; }; }; _meta?: { ...; } | undefined; }>
options
Promise<{ completion_response: { created: string & $brand<"Datetime">; provider_name: "ollama" | "claude" | "chatgpt" | "gemini"; model: string; data: { type: "ollama"; value: any; } | { ...; } | { ...; } | { ...; }; }; _meta?: { ...; } | undefined; }>get_handler
type (streaming: boolean): CompletionHandler
streaming
booleancreate_client
type (): void
voidget_client
Get the client, throwing an error if not configured.
type (): TClient
TClientload_status
Get status for this provider. Override for custom availability checks.
type (reload?: boolean | undefined): Promise<{ name: string; available: true; checked_at: number; } | { name: string; available: false; error: string; checked_at: number; }>
reload?
boolean | undefinedPromise<{ name: string; available: true; checked_at: number; } | { name: string; available: false; error: string; checked_at: number; }>invalidate_status
Invalidate cached status, forcing next load to fetch fresh data.
type (): void
voidvalidate_streaming_requirements
Validates that progress_token is provided for streaming requests.
type (progress_token?: (string & $brand<"Uuid">) | undefined): asserts progress_token
progress_token?
(string & $brand<"Uuid">) | undefinedvoidsend_streaming_progress
Sends streaming progress notification to frontend
type (progress_token: string & $brand<"Uuid">, chunk: { [x: string]: unknown; model?: string | undefined; created_at?: string | undefined; done?: boolean | undefined; message?: { [x: string]: unknown; role: string; content: string; } | undefined; } | undefined): Promise<...>
progress_token
string & $brand<"Uuid">chunk
{ [x: string]: unknown; model?: string | undefined; created_at?: string | undefined; done?: boolean | undefined; message?: { [x: string]: unknown; role: string; content: string; } | undefined; } | undefinedPromise<void>log_streaming_chunk
Logs streaming chunk information
type (chunk: unknown): void
chunk
unknownvoidlog_streaming_completion
Logs streaming completion information
type (accumulated_length: number): void
accumulated_length
numbervoidlog_non_streaming_response
Logs non-streaming response information
type (response: unknown): void
response
unknownvoidlog_api_response
Logs final API response information
type (api_response: unknown): void
api_response
unknownvoid