/** * Google Gemini Provider Adapter * * Implements the unified ILLMProvider interface for Google Gemini's API. * Uses fetch-based HTTP requests (no SDK dependency) for maximum compatibility. * Supports Gemini 3.5 Flash, Gemini 3 Flash Preview, Gemini Omni Flash Preview * route metadata, and legacy Gemini 1.5 models. * * Function calling uses the standard generateContent API (not the Interactions/ * Live API). Tool calls appear as `functionCall` parts in the response * candidates, and tool results are fed back as `functionResponse` parts in * the next `contents[]` turn. * * Interactions API note (A-020, 2026-06-08): The Gemini Interactions API * removed the `outputs` field and replaced it with a `steps[]` array * (user_input + model_output step types). This adapter uses `generateContent` * (not the Interactions/Live endpoint) and therefore reads `candidates[0]` * directly. If this adapter is ever extended to use the Interactions API, * iterate `response.steps` (not `response.outputs`) and find * `step.type === 'model_output'` for content. History for Interactions API * multi-turn goes in `input.steps[]`, not `contents[]`. * * @version 1.1.0 */ import { BaseLLMAdapter } from '../base-adapter'; import type { Capabilities, LLMCompletionRequest, LLMCompletionResponse, GeminiProviderConfig, ToolSpec } from '../types'; export declare const GEMINI_MODELS: readonly ["gemini-3.5-flash", "gemini-3.1-flash-tts-preview", "gemini-omni-flash-preview", "gemini-3-flash-preview", "gemini-1.5-pro", "gemini-1.5-flash", "gemini-1.5-flash-8b"]; export type GeminiModel = (typeof GEMINI_MODELS)[number]; export type GeminiApiSurface = 'generateContent' | 'interactions'; export interface GeminiModelMetadata { id: GeminiModel; status: 'ga' | 'preview' | 'legacy'; apiSurface: GeminiApiSurface; defaultRoutingEligible: boolean; supportsTextCompletion: boolean; supportsFunctionCalling: boolean; supportsVideoGeneration?: boolean; supportsVideoEditing?: boolean; supportsImageAnimation?: boolean; supportsConversationalMediaEditing?: boolean; lastVerified: string; routingNotes: readonly string[]; sources: readonly string[]; } export declare const GEMINI_MODEL_METADATA: { readonly 'gemini-3.5-flash': GeminiModelMetadata; readonly 'gemini-3.1-flash-tts-preview': GeminiModelMetadata; readonly 'gemini-omni-flash-preview': GeminiModelMetadata; readonly 'gemini-3-flash-preview': GeminiModelMetadata; readonly 'gemini-1.5-pro': GeminiModelMetadata; readonly 'gemini-1.5-flash': GeminiModelMetadata; readonly 'gemini-1.5-flash-8b': GeminiModelMetadata; }; export declare function getGeminiModelMetadata(model: string): GeminiModelMetadata | undefined; export declare function isGeminiDefaultRoutingEligible(model: string): boolean; /** A single part inside a Gemini `content` object. */ interface GeminiPart { text?: string; /** Emitted by the model when it wants to invoke a function. */ functionCall?: { name: string; args: Record; }; /** Provided by the caller to return a function result to the model. */ functionResponse?: { name: string; response: Record; }; } /** * Gemini `generateContent` response shape. * * NOTE: The Interactions/Live API (not used here) replaced the `outputs` * field with `steps[]` as of the May 2026 breaking-change notice * (A-020, 2026-06-08). This adapter reads `candidates[]` from the * standard REST `generateContent` endpoint, which is unaffected. */ interface GeminiResponse { candidates?: Array<{ content: { parts: GeminiPart[]; role: string; }; finishReason: string; }>; usageMetadata?: { promptTokenCount: number; candidatesTokenCount: number; totalTokenCount: number; }; error?: { code: number; message: string; status: string; }; } /** Gemini function declaration for the `tools` request field. */ interface GeminiFunctionDeclaration { name: string; description: string; parameters: { type: string; properties: Record; required?: string[]; }; } /** * Google Gemini provider adapter for HoloScript. * * @example * ```typescript * const gemini = new GeminiAdapter({ * apiKey: process.env.GEMINI_API_KEY!, * }); * * const scene = await gemini.generateHoloScript({ * prompt: "an underwater scene with glowing fish and coral", * }); * console.log(scene.code); * ``` */ /** * Capability manifest sourced from `docs/LLM_CAPABILITIES.md` * Google (Gemini). Native multimodal is Gemini's strongest differentiator: * text + image + video + audio in one model. Search Grounding (first-party * Google Search citations) and cached_content (long-context reuse) are the * other major routing signals. * * `contextWindow` / `maxOutput` reflect the current Gemini 3.5 Flash model * card as verified against Google AI docs on 2026-05-25. `costPerMillion` * omitted (varies per model + Vertex vs Studio pricing delta). * * Exported as a constant so the capability-aware router can read it * without instantiating the adapter: single source of truth per W.GOLD.006. */ export declare const GEMINI_CAPABILITIES: Capabilities; export declare class GeminiAdapter extends BaseLLMAdapter { readonly name: "gemini"; readonly models: readonly ["gemini-3.5-flash", "gemini-3.1-flash-tts-preview", "gemini-omni-flash-preview", "gemini-3-flash-preview", "gemini-1.5-pro", "gemini-1.5-flash", "gemini-1.5-flash-8b"]; readonly defaultHoloScriptModel: string; readonly capabilities: Capabilities; constructor(config: GeminiProviderConfig); protected getDefaultModel(): string; complete(request: LLMCompletionRequest, model?: string): Promise; /** * Translate a provider-neutral LLMMessage to a Gemini `content` object. * * Handles three message shapes: * 1. Plain string content → single `text` part. * 2. Assistant message with `tool_use` blocks → `functionCall` parts so * Gemini sees the model's prior tool invocations in history. * 3. User message with `tool_result` blocks → `functionResponse` parts so * Gemini receives the results of those invocations. */ private messageToGeminiContent; private mapGeminiError; } /** * Map a Gemini `finishReason` string to the provider-neutral finish reason. */ export declare function mapGeminiFinishReason(reason: string | undefined): LLMCompletionResponse['finishReason']; /** * Convert an array of provider-neutral `ToolSpec` objects to Gemini function * declarations for the `tools[0].functionDeclarations` request field. */ export declare function geminiToolsFromToolSpecs(tools: ToolSpec[]): GeminiFunctionDeclaration[]; /** * Parse a Gemini `generateContent` response into the provider-neutral * `LLMCompletionResponse` shape. * * Handles both plain text responses and function-call responses: * - Text parts → `content` string + `TextBlock` entries in `assistantBlocks`. * - `functionCall` parts → `ToolUseBlock` entries in `toolUses` and * `assistantBlocks`. Caller must execute tools and re-feed results via a * follow-up request containing the prior assistant turn + `functionResponse` * user messages. * * Exported for unit-testing without live API access. */ export declare function parseGeminiResponse(data: GeminiResponse, fallbackModel: string): LLMCompletionResponse; export {};