/** * Shared utilities for Google Generative AI and Google Vertex providers. */ import { type Content, FinishReason, FunctionCallingConfigMode, type GenerateContentParameters, type GenerateContentResponse, type ThinkingConfig } from "@google/genai"; import type { Api, AssistantMessage, Context, Model, SimpleStreamOptions, StopReason, Tool, StreamOptions } from "../types.js"; import type { AssistantMessageEventStream } from "../utils/event-stream.js"; type GoogleApiType = "google-generative-ai" | "google-vertex"; /** * Thinking level for Gemini 3 models. * Mirrors Google's ThinkingLevel enum values. */ export type GoogleThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH"; type GoogleToolChoice = "auto" | "none" | "any"; type GoogleThinkingOptions = { enabled: boolean; budgetTokens?: number; level?: GoogleThinkingLevel; }; export type GoogleProviderOptions = StreamOptions & { toolChoice?: GoogleToolChoice; thinking?: GoogleThinkingOptions; }; type GoogleGenerateContentClient = { models: { generateContentStream(params: GenerateContentParameters): Promise> | AsyncIterable; }; }; /** * Retain thought signatures during streaming. * * Some backends only send `thoughtSignature` on the first delta for a given part/block; later deltas may omit it. * This helper preserves the last non-empty signature for the current block. * * Note: this does NOT merge or move signatures across distinct response parts. It only prevents * a signature from being overwritten with `undefined` within the same streamed block. */ export declare function retainThoughtSignature(existing: string | undefined, incoming: string | undefined): string | undefined; /** * Models via Google APIs that require explicit tool call IDs in function calls/responses. */ export declare function requiresToolCallId(modelId: string): boolean; /** * Convert internal messages to Gemini Content[] format. */ export declare function convertMessages(model: Model, context: Context): Content[]; /** * Convert tools to Gemini function declarations format. * * By default uses `parametersJsonSchema` which supports full JSON Schema (including * anyOf, oneOf, const, etc.). Set `useParameters` to true to use the legacy `parameters` * field instead (OpenAPI 3.03 Schema). This is needed for Cloud Code Assist with Claude * models, where the API translates `parameters` into Anthropic's `input_schema`. */ export declare function convertTools(tools: Tool[], useParameters?: boolean): { functionDeclarations: Record[]; }[] | undefined; /** * Map tool choice string to Gemini FunctionCallingConfigMode. */ export declare function mapToolChoice(choice: string): FunctionCallingConfigMode; export declare function createGoogleAssistantOutput(model: Model, api?: Api): AssistantMessage; export declare function runGoogleGenerateContentLifecycle(params: { stream: AssistantMessageEventStream; model: Model; output: AssistantMessage; options?: Pick; createClient: () => GoogleGenerateContentClient; buildParams: () => GenerateContentParameters; nextToolCallId: (name: string | undefined) => string; }): Promise; export declare function buildGoogleGenerateContentParams(model: Model, context: Context, options?: GoogleProviderOptions, configHooks?: { mapThinkingLevel?: (level: GoogleThinkingLevel) => ThinkingConfig["thinkingLevel"]; getDisabledThinkingConfig?: (model: Model) => ThinkingConfig; }): GenerateContentParameters; export declare function buildGoogleSimpleThinking(model: Model, options: SimpleStreamOptions | undefined, config?: { includeGemma4ThinkingLevel?: boolean; useFlashLiteBudgets?: boolean; }): GoogleThinkingOptions; export declare function getDisabledGoogleThinkingConfig(model: Model, config?: { includeGemma4?: boolean; mapThinkingLevel?: (level: GoogleThinkingLevel) => ThinkingConfig["thinkingLevel"]; }): ThinkingConfig; export declare function isGemma4Model(model: Model): boolean; /** * Map Gemini FinishReason to our StopReason. */ export declare function mapStopReason(reason: FinishReason): StopReason; export declare function consumeGoogleGenerateContentStream(params: { chunks: AsyncIterable; model: Model; output: AssistantMessage; stream: AssistantMessageEventStream; signal?: AbortSignal; nextToolCallId: (name: string | undefined) => string; }): Promise; export {};