/** * Shared utilities for Google Generative AI and Google Vertex providers. */ import { type Content, FinishReason, FunctionCallingConfigMode, type GenerateContentResponsePromptFeedback, ThinkingLevel as GoogleSdkThinkingLevel, type Part, type ThinkingConfig } from "@google/genai"; import type { Api, Model, StopReason, StreamOptions, ThinkingBudgets, ThinkingLevel, Tool, TranscriptContext } from "../types.ts"; type GoogleApiType = "google-generative-ai" | "google-vertex"; /** * Thinking level for Gemini models that use `thinkingLevel` instead of `thinkingBudget`. * Mirrors Google's ThinkingLevel enum values. */ export type GoogleApiThinkingLevel = "THINKING_LEVEL_UNSPECIFIED" | "MINIMAL" | "LOW" | "MEDIUM" | "HIGH" | "XHIGH"; export type ResolvedGoogleThinkingLevel = Exclude; /** Resolve a supported pi level or model-specific Google mapping to a standard Google level. */ export declare function resolveGoogleThinkingLevel(model: Model, level: ThinkingLevel): ResolvedGoogleThinkingLevel; /** * Whether this model uses Gemini's discrete `thinkingLevel` control instead of * the token-based `thinkingBudget` control. Supported levels come from the * model's `thinkingLevelMap`; this only selects the Google wire format. */ export declare function usesGoogleThinkingLevel(model: Model): boolean; export declare function toGoogleThinkingLevel(level: ResolvedGoogleThinkingLevel): GoogleApiThinkingLevel; /** Token budget for Gemini models that use `thinkingBudget`: custom budgets first, then per-model defaults, else -1 (dynamic). */ export declare function getGoogleBudget(model: Model, resolvedLevel: ResolvedGoogleThinkingLevel, customBudgets?: ThinkingBudgets): number; export declare function toGoogleSdkThinkingLevel(level: GoogleApiThinkingLevel): GoogleSdkThinkingLevel; export declare function getDisabledGoogleThinkingConfig(model: Model): ThinkingConfig; /** * Determines whether a streamed Gemini `Part` should be treated as "thinking". * * Protocol note (Gemini / Vertex AI thought signatures): * - `thought: true` is the definitive marker for thinking content (thought summaries). * - `thoughtSignature` is an encrypted representation of the model's internal thought process * used to preserve reasoning context across multi-turn interactions. * - `thoughtSignature` can appear on ANY part type (text, functionCall, etc.) - it does NOT * indicate the part itself is thinking content. * - For non-functionCall responses, the signature appears on the last part for context replay. * - When persisting/replaying model outputs, signature-bearing parts must be preserved as-is; * do not merge/move signatures across parts. * * See: https://ai.google.dev/gemini-api/docs/thought-signatures */ export declare function isThinkingPart(part: Pick): boolean; /** * 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: TranscriptContext): Content[]; /** * Convert tools to Gemini function declarations format. * * By default uses `parametersJsonSchema` which supports full JSON Schema (including * anyOf, oneOf, etc.). Gemini ignores `const` there, so string and number `const` * values are sent as single-value `enum`s. 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, supportsStrictMode?: boolean): { functionDeclarations: Record[]; }[] | undefined; /** * Gemini 3+ enforces required function parameters in validated tool-calling modes. * `compat.supportsStrictMode` overrides the model ID detection, e.g. for Gemini models served under IDs without the version. */ export declare function supportsGoogleStrictToolSampling(model: Model): boolean; /** Map tool choice string to Gemini FunctionCallingConfigMode. */ export declare function mapToolChoice(choice: string): FunctionCallingConfigMode; export declare function resolveGoogleFunctionCallingMode(tools: Tool[], toolChoice: string | undefined, supportsStrictMode: boolean): FunctionCallingConfigMode | undefined; /** Format prompt-block metadata returned instead of response candidates. */ export declare function formatGooglePromptBlockError(providerName: string, feedback: GenerateContentResponsePromptFeedback): string; /** * Map Gemini FinishReason to our StopReason. */ export declare function mapStopReason(reason: FinishReason): StopReason; /** * Run a Google GenAI SDK request with the shared provider retry policy * (408/409/429/5xx with backoff, honoring retry-after), mirroring how the * Anthropic and OpenAI adapters wrap their initial request in * retryProviderRequest. The SDK's ApiError has a `status` property but no * `headers` property, and retryProviderRequest only retries errors that carry * both, so normalize the error by adding the missing `headers` before * rethrowing. Failed attempts reach `onResponse` with their status and no * headers. */ export declare function retryGoogleRequest(request: () => Promise, model: Model, options?: Pick): Promise; export {}; //# sourceMappingURL=google-shared.d.ts.map