import { SummarizeParams, SummarizeResult } from "./summarize.types.js"; import { BaseModel } from "./baseModel.js"; import { ChatParams, ChatResult, ParallelChatCompletionsCallbacks, ChatCompletionMessage } from "./chat.types.js"; import { ClassifyParams, ClassifyResult } from "./classify.types.js"; /** * Type for thinking stream state management */ type ThinkingStreamState = { accumulatedThinking: string; inThinkingBlock: boolean; pendingContent: string; thinkingComplete: boolean; }; /** * Describes the native file input capabilities of an LLM driver. * Returned by BaseLLM.GetFileCapabilities(). When null, the driver * does not support file input and artifact tools should be used instead. */ export interface FileCapabilities { /** MIME type patterns this driver can accept natively (e.g. 'application/pdf', 'image/*') */ SupportedMimeTypes: string[]; /** Maximum size in bytes for a single file attachment */ MaxFileSize: number; /** Maximum number of file attachments per API request */ MaxFilesPerRequest: number; /** Whether this driver has a separate file upload API (e.g. Gemini Files API) vs inline base64 */ HasFileAPI: boolean; } /** * Base class for all LLM sub-class implementations. Not all sub-classes will support all methods. * If a method is not supported an exception will be thrown. */ export declare abstract class BaseLLM extends BaseModel { /** * Protected property to store additional provider-specific settings */ protected _additionalSettings: Record; /** * Get the current additional settings */ get AdditionalSettings(): Record; /** * Set additional provider-specific settings * Subclasses should override this method to validate required settings * * @param settings Provider-specific settings */ SetAdditionalSettings(settings: Record): void; /** * Clear all additional settings * This is useful for resetting the state of the provider * or when switching between different configurations. */ ClearAdditionalSettings(): void; /** * Process a chat completion request. If streaming is enabled and supported, * this will route to the streaming implementation. */ ChatCompletion(params: ChatParams): Promise; /** * Process multiple chat completion requests in parallel. This is useful for: * - Generating multiple variations with different parameters (temperature, etc.) * - Getting multiple responses to compare or select from * - Improving reliability by sending the same request multiple times * * @param paramsArray Array of chat completion parameter objects * @param callbacks Optional callbacks for progress and individual completions * @returns Promise resolving to an array of ChatResults in the same order as the input params */ ChatCompletions(paramsArray: ChatParams[], callbacks?: ParallelChatCompletionsCallbacks): Promise; /** * Implementation for non-streaming chat completion */ protected abstract nonStreamingChatCompletion(params: ChatParams): Promise; abstract ClassifyText(params: ClassifyParams): Promise; abstract SummarizeText(params: SummarizeParams): Promise; /** * Check if this provider supports streaming * @returns true if streaming is supported, false otherwise */ get SupportsStreaming(): boolean; /** * Whether this LLM provider supports assistant prefill (pre-seeding the start of the model's response). * Providers that support prefill should override this to return true. * This is used as a code-level default when database metadata (AIModelType/AIModel/AIModelVendor.SupportsPrefill) * is null. Database values of true/false override this getter. */ get SupportsPrefill(): boolean; /** * Returns the native file input capabilities of this LLM driver, or null if * the driver does not support file attachments. Subclasses that accept files * (PDFs, images, etc.) should override this method. */ GetFileCapabilities(): FileCapabilities | null; /** * Template method for handling streaming chat completion * This implements the common pattern across providers while delegating * provider-specific logic to abstract methods. */ protected handleStreamingChatCompletion(params: ChatParams): Promise; /** * Hook invoked at the start AND end (in `finally`) of every streaming chat * completion to reset per-request streaming state. Default is a no-op; * providers that maintain instance-level streaming state (e.g., Anthropic / * OpenAI thinking-block accumulators) MUST override this. See audit R2-C5 * for context — without this, state from a prior request bleeds into the * next one and accumulated buffers grow unbounded across the singleton's * lifetime. */ protected resetStreamingState(): void; /** * Create a provider-specific streaming request * @param params Chat parameters * @returns A stream object that can be iterated with for await */ protected abstract createStreamingRequest(params: ChatParams): Promise; /** * Process a streaming chunk from the provider * @param chunk The raw chunk from the provider * @returns Processed content and metadata */ protected abstract processStreamingChunk(chunk: any): { content: string; finishReason?: string | undefined; usage?: any | null; }; /** * Create the final response object from streaming results * @param accumulatedContent The complete content accumulated from all chunks * @param lastChunk The last chunk received from the stream * @param usage The usage information (tokens, etc.) * @returns A complete ChatResult object */ protected abstract finalizeStreamingResponse(accumulatedContent: string | null | undefined, lastChunk: any | null | undefined, usage: any | null | undefined): ChatResult; /** * State tracking for streaming thinking extraction * Providers should initialize this if they support thinking models */ protected thinkingStreamState: ThinkingStreamState | null; /** * Check if the provider supports thinking models * Providers should override this to return true if they support thinking extraction */ protected supportsThinkingModels(): boolean; /** * Get the thinking tag format for this provider * Providers can override this to customize the thinking tag format */ protected getThinkingTagFormat(): { open: string; close: string; }; /** * Extract thinking content from non-streaming content * This method handles case-insensitive extraction of thinking blocks */ protected extractThinkingFromContent(content: string): { content: string; thinking?: string; }; /** * Initialize thinking stream state for streaming extraction */ protected initializeThinkingStreamState(): void; /** * Reset thinking stream state */ protected resetThinkingStreamState(): void; /** * Process streaming chunk with thinking extraction * This method handles case-insensitive extraction across chunk boundaries */ protected processStreamChunkWithThinking(rawContent: string): string; /** * Add thinking content to a chat completion message */ protected addThinkingToMessage(message: ChatCompletionMessage, thinkingContent?: string): ChatCompletionMessage; } /** * Result of ResolveFileInputStrategy — tells the caller whether to attach * a file natively or fall back to artifact-tool exploration. */ export interface FileInputStrategy { UseNativeFileInput: boolean; UseFileAPI: boolean; Reason: string; } /** * Determines whether to use native file input or artifact tools for a given file, * based on LLM driver capabilities and an optional prompt-level override. * * Resolution order: * 1. Prompt-level forceNativeFileInput override (if non-null, returns immediately) * 2. Driver capabilities null-check (null = no file support) * 3. MIME type, size, and count constraints checked against driver capabilities * 4. Falls back to artifact tools when any constraint is violated */ export declare function ResolveFileInputStrategy(mimeType: string, fileSizeBytes: number, capabilities: FileCapabilities | null, forceNativeFileInput: boolean | null, currentFileCount: number): FileInputStrategy; export {}; //# sourceMappingURL=baseLLM.d.ts.map