@langchain/google 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/chat_models/{api-types.d.ts → api_types/generate_content.d.cts} +198 -200
- package/dist/chat_models/{api-types.d.cts → api_types/generate_content.d.ts} +198 -200
- package/dist/chat_models/api_types/interactions.d.cts +1423 -0
- package/dist/chat_models/api_types/interactions.d.ts +1423 -0
- package/dist/chat_models/base.cjs +60 -403
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +13 -200
- package/dist/chat_models/base.d.ts +15 -202
- package/dist/chat_models/base.js +61 -402
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/handlers/base.cjs +62 -0
- package/dist/chat_models/handlers/base.cjs.map +1 -0
- package/dist/chat_models/handlers/base.d.cts +46 -0
- package/dist/chat_models/handlers/base.d.ts +46 -0
- package/dist/chat_models/handlers/base.js +62 -0
- package/dist/chat_models/handlers/base.js.map +1 -0
- package/dist/chat_models/handlers/generate_content.cjs +344 -0
- package/dist/chat_models/handlers/generate_content.cjs.map +1 -0
- package/dist/chat_models/handlers/generate_content.d.cts +32 -0
- package/dist/chat_models/handlers/generate_content.d.ts +32 -0
- package/dist/chat_models/handlers/generate_content.js +344 -0
- package/dist/chat_models/handlers/generate_content.js.map +1 -0
- package/dist/chat_models/handlers/index.cjs +6 -0
- package/dist/chat_models/handlers/index.d.cts +4 -0
- package/dist/chat_models/handlers/index.d.ts +4 -0
- package/dist/chat_models/handlers/index.js +4 -0
- package/dist/chat_models/handlers/interactions.cjs +303 -0
- package/dist/chat_models/handlers/interactions.cjs.map +1 -0
- package/dist/chat_models/handlers/interactions.d.cts +33 -0
- package/dist/chat_models/handlers/interactions.d.ts +33 -0
- package/dist/chat_models/handlers/interactions.js +303 -0
- package/dist/chat_models/handlers/interactions.js.map +1 -0
- package/dist/chat_models/index.cjs +14 -6
- package/dist/chat_models/index.cjs.map +1 -1
- package/dist/chat_models/index.d.cts +7 -3
- package/dist/chat_models/index.d.ts +7 -3
- package/dist/chat_models/index.js +8 -4
- package/dist/chat_models/index.js.map +1 -1
- package/dist/chat_models/node.cjs +4 -5
- package/dist/chat_models/node.cjs.map +1 -1
- package/dist/chat_models/node.d.cts +1 -3
- package/dist/chat_models/node.d.ts +1 -3
- package/dist/chat_models/node.js +3 -4
- package/dist/chat_models/node.js.map +1 -1
- package/dist/chat_models/profiles.cjs +1 -2
- package/dist/chat_models/profiles.js +1 -2
- package/dist/chat_models/types.cjs +1 -2
- package/dist/chat_models/types.cjs.map +1 -1
- package/dist/chat_models/types.d.cts +776 -88
- package/dist/chat_models/types.d.ts +776 -88
- package/dist/chat_models/types.js +1 -2
- package/dist/chat_models/types.js.map +1 -1
- package/dist/clients/index.cjs +3 -4
- package/dist/clients/index.d.cts +0 -2
- package/dist/clients/index.d.ts +0 -2
- package/dist/clients/index.js +3 -4
- package/dist/clients/node.cjs +4 -5
- package/dist/clients/node.d.cts +0 -2
- package/dist/clients/node.d.ts +0 -2
- package/dist/clients/node.js +4 -5
- package/dist/const.cjs +1 -2
- package/dist/const.js +1 -2
- package/dist/converters/{messages.cjs → generate_content/messages.cjs} +4 -5
- package/dist/converters/generate_content/messages.cjs.map +1 -0
- package/dist/converters/{messages.js → generate_content/messages.js} +4 -5
- package/dist/converters/generate_content/messages.js.map +1 -0
- package/dist/converters/generate_content/params.cjs +135 -0
- package/dist/converters/generate_content/params.cjs.map +1 -0
- package/dist/converters/generate_content/params.js +131 -0
- package/dist/converters/generate_content/params.js.map +1 -0
- package/dist/{utils → converters/generate_content}/stream_events.cjs +2 -3
- package/dist/converters/generate_content/stream_events.cjs.map +1 -0
- package/dist/{utils → converters/generate_content}/stream_events.js +2 -3
- package/dist/converters/generate_content/stream_events.js.map +1 -0
- package/dist/converters/{tools.cjs → generate_content/tools.cjs} +4 -5
- package/dist/converters/generate_content/tools.cjs.map +1 -0
- package/dist/converters/{tools.js → generate_content/tools.js} +4 -5
- package/dist/converters/generate_content/tools.js.map +1 -0
- package/dist/converters/interactions/messages.cjs +766 -0
- package/dist/converters/interactions/messages.cjs.map +1 -0
- package/dist/converters/interactions/messages.js +759 -0
- package/dist/converters/interactions/messages.js.map +1 -0
- package/dist/converters/interactions/params.cjs +244 -0
- package/dist/converters/interactions/params.cjs.map +1 -0
- package/dist/converters/interactions/params.js +237 -0
- package/dist/converters/interactions/params.js.map +1 -0
- package/dist/converters/interactions/stream_events.cjs +769 -0
- package/dist/converters/interactions/stream_events.cjs.map +1 -0
- package/dist/converters/interactions/stream_events.js +768 -0
- package/dist/converters/interactions/stream_events.js.map +1 -0
- package/dist/converters/interactions/tools.cjs +229 -0
- package/dist/converters/interactions/tools.cjs.map +1 -0
- package/dist/converters/interactions/tools.js +228 -0
- package/dist/converters/interactions/tools.js.map +1 -0
- package/dist/converters/{params.cjs → shared/params.cjs} +8 -94
- package/dist/converters/shared/params.cjs.map +1 -0
- package/dist/converters/{params.js → shared/params.js} +8 -92
- package/dist/converters/shared/params.js.map +1 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/utils/errors.cjs +1 -2
- package/dist/utils/errors.js +1 -2
- package/dist/utils/gcp-auth.cjs +3 -4
- package/dist/utils/gcp-auth.d.cts +0 -2
- package/dist/utils/gcp-auth.d.ts +0 -2
- package/dist/utils/gcp-auth.js +3 -4
- package/dist/utils/handler.cjs +1 -2
- package/dist/utils/handler.d.cts +0 -2
- package/dist/utils/handler.d.ts +0 -2
- package/dist/utils/handler.js +1 -2
- package/dist/utils/metadata.cjs +9 -2
- package/dist/utils/metadata.cjs.map +1 -1
- package/dist/utils/metadata.js +9 -3
- package/dist/utils/metadata.js.map +1 -1
- package/dist/utils/misc.cjs +1 -2
- package/dist/utils/misc.cjs.map +1 -1
- package/dist/utils/misc.d.cts +2 -3
- package/dist/utils/misc.d.ts +2 -3
- package/dist/utils/misc.js +1 -2
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/stream.cjs +1 -2
- package/dist/utils/stream.js +1 -2
- package/package.json +12 -10
- package/dist/converters/messages.cjs.map +0 -1
- package/dist/converters/messages.js.map +0 -1
- package/dist/converters/params.cjs.map +0 -1
- package/dist/converters/params.js.map +0 -1
- package/dist/converters/tools.cjs.map +0 -1
- package/dist/converters/tools.js.map +0 -1
- package/dist/utils/stream_events.cjs.map +0 -1
- package/dist/utils/stream_events.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/chat_models/types.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-namespace */\n\nimport type { InteropZodType } from \"@langchain/core/utils/types\";\nimport type { BindToolsInput } from \"@langchain/core/language_models/chat_models\";\nimport type { Gemini as GeminiBase } from \"./api-types.js\";\nimport type { LowercaseLiteral, Prettify } from \"../utils/misc.js\";\n\nexport interface ChatGoogleFields {\n /**\n * The temperature is used for sampling during response generation, which\n * occurs when topP and topK are applied. Temperature controls the degree of\n * randomness in token selection. Lower temperatures are good for prompts that\n * require a less open-ended or creative response, while higher temperatures\n * can lead to more diverse or creative results.\n *\n * Specify a lower value for less random responses and a higher value for more\n * random responses.\n */\n temperature?: number;\n\n /**\n * Top-P changes how the model selects tokens for output. Tokens are selected\n * from the most probable to least probable until the sum of their\n * probabilities equals the top-P value.\n *\n * Specify a lower value for less random responses and a higher value for more\n * random responses.\n */\n topP?: number;\n\n /**\n * Top-K changes how the model selects tokens for output. A top-K of 1 means\n * the selected token is the most probable among all tokens in the model's\n * vocabulary (also called greedy decoding), while a top-K of 3 means that the\n * next token is selected from among the 3 most probable tokens (using\n * temperature).\n */\n topK?: number;\n\n /**\n * Maximum number of tokens that can be generated in the response. A token is\n * approximately four characters. 100 tokens correspond to roughly 60-80 words.\n * Specify a lower value for shorter responses and a higher value for\n * potentially longer responses.\n */\n maxOutputTokens?: number;\n\n /**\n * Positive values penalize tokens that already appear in the generated text,\n * increasing the probability of generating more diverse content.\n */\n presencePenalty?: number;\n\n /**\n * Positive values penalize tokens that repeatedly appear in the generated\n * text, decreasing the probability of repeating content.\n */\n frequencyPenalty?: number;\n\n /**\n * Specifies a list of strings that tells the model to stop generating text if\n * one of the strings is encountered in the response. If a string appears\n * multiple times in the response, then the response truncates where it's\n * first encountered. The strings are case-sensitive.\n */\n stopSequences?: string[];\n\n /**\n * When seed is fixed to a specific value, the model makes a best effort to\n * provide the same response for repeated requests. Deterministic output isn't\n * guaranteed. Also, changing the model or parameter settings, such as the\n * temperature, can cause variations in the response even when you use the\n * same seed value. By default, a random seed value is used.\n */\n seed?: number;\n\n /**\n * If true, returns the log probabilities of the tokens that were chosen by\n * the model at each step. By default, this parameter is set to false.\n */\n responseLogprobs?: boolean;\n\n /**\n * Returns the log probabilities of the top candidate tokens at each generation\n * step. The model's chosen token might not be the same as the top candidate\n * token at each step. Specify the number of candidates to return by using an\n * integer value in the range of 1-20.\n */\n logprobs?: number;\n\n /**\n * Per request settings for blocking unsafe content\n */\n safetySettings?: Prettify<GeminiBase.SafetySetting>[];\n\n /**\n * Configuration for the model's thinking process\n */\n thinkingConfig?: Prettify<GeminiBase.ThinkingConfig>;\n\n /**\n * The schema that the generated response should match.\n * Can be a Zod schema or a JSON Schema object.\n * When set, the response will be structured according to this schema\n * and `responseMimeType` will automatically be set to \"application/json\".\n */\n responseSchema?: InteropZodType | Record<string, unknown>;\n\n /**\n * A list of tools the model may use to generate the next response.\n * Can be LangChain tools, OpenAI tools, or Gemini function declarations.\n */\n tools?: BindToolsInput[];\n\n /**\n * The requested modalities of the response.\n * Represents the set of modalities that the model can return.\n * An empty list is equivalent to requesting only text.\n */\n responseModalities?: Prettify<GeminiBase.GenerativeLanguageModality>[];\n\n /**\n * If true, enables enhanced civic answers feature.\n */\n enableEnhancedCivicAnswers?: boolean;\n\n /**\n * Speech generation configuration.\n * You can use either Google's definition of the speech configuration,\n * or a simplified version we've defined (which can be as simple\n * as the name of a pre-defined voice).\n */\n speechConfig?: Prettify<GeminiBase.SpeechConfig> | SimplifiedSpeechConfig;\n\n /**\n * Configuration for image generation.\n */\n imageConfig?: Prettify<GeminiBase.ImageConfig>;\n\n /**\n * Media resolution for input media processing.\n *\n * This maps to `generationConfig.mediaResolution`, which is a scalar enum-like\n * string value in the Gemini API.\n */\n mediaResolution?: GeminiBase.GenerationConfig[\"mediaResolution\"];\n\n /**\n * OpenAI-compatible alias for media input detail level.\n *\n * This is mapped to `generationConfig.mediaResolution`:\n * - `\"auto\"` => default Gemini behavior (`mediaResolution` omitted)\n * - `\"low\"` => `\"MEDIA_RESOLUTION_LOW\"`\n * - `\"high\"` => `\"MEDIA_RESOLUTION_HIGH\"`\n *\n * If both `mediaResolution` and `detail` are provided, `mediaResolution` wins.\n */\n detail?: \"auto\" | \"low\" | \"high\";\n\n /**\n * The number of reasoning tokens that the model should generate.\n * If explicitly set, then the reasoning blocks will be returned.\n */\n maxReasoningTokens?: number;\n\n /**\n * An alias for `maxReasoningTokens` for compatibility.\n */\n thinkingBudget?: number;\n\n /**\n * An alias for `maxReasoningTokens` under Gemini 2.5 or\n * the primary thinking/reasoning setting for Gemini 3.\n * If explicitly set, then the reasoning blocks will be returned.\n */\n reasoningEffort?: GeminiBase.ThinkingLevel;\n\n /**\n * An alias for `reasoningEffort` for compatibility.\n */\n thinkingLevel?: GeminiBase.ThinkingLevel;\n\n /**\n * Inference service tiers.\n * \"priority\" offers highest reliability for higher rates.\n * \"flex\" offers a discount for preemptable processing.\n * Other values are treated as the standard service tier.\n */\n serviceTier?: GeminiBase.ServiceTier;\n\n /**\n * Custom / additional headers to include with every request to the API.\n * When set on both constructor params and per-invocation call options,\n * per-invocation headers take precidence for matching keys.\n */\n customHeaders?: Record<string, string>;\n}\n\nexport type GooglePlatformType = \"gai\" | \"gcp\";\n\n// These are service tiers that we specifically need to send.\n// Other values will be ignored, resulting in the default\n// or \"standard\" setting.\nexport const settableServiceTier: GeminiBase.ServiceTier[] = [\n \"flex\",\n \"priority\",\n];\n\nexport { type Gemini } from \"./api-types.js\";\n\n// There's a fair number of utilities that we need to extract from the base\n// Gemini OpenAPI types, Adding these directly to the base types\n// would pollute the typegen output, so we're adding them here instead.\ndeclare module \"./api-types.js\" {\n export namespace Gemini {\n // Gemini parts are contained as one intersecting type\n // in the spec, so we need to pick out the specific parts we need.\n export namespace Part {\n export type CodeExecutionResult = Pick<\n GeminiBase.Part,\n \"codeExecutionResult\"\n >;\n export type ExecutableCode = Pick<GeminiBase.Part, \"executableCode\">;\n export type FileData = Pick<\n GeminiBase.Part,\n \"fileData\" | \"videoMetadata\"\n >;\n export type FunctionCall = Required<\n Pick<GeminiBase.Part, \"functionCall\">\n > &\n Pick<GeminiBase.Part, \"thoughtSignature\">;\n export type FunctionResponse = Pick<GeminiBase.Part, \"functionResponse\">;\n export type InlineData = Pick<\n GeminiBase.Part,\n \"inlineData\" | \"videoMetadata\"\n >;\n export type MediaResolution = Pick<GeminiBase.Part, \"mediaResolution\">;\n export type PartMetadata = Pick<GeminiBase.Part, \"partMetadata\">;\n export type Text = Pick<GeminiBase.Part, \"text\">;\n export type Thought = Pick<GeminiBase.Part, \"thought\">;\n export type ThoughtSignature = Pick<GeminiBase.Part, \"thoughtSignature\">;\n }\n\n export namespace PrebuiltVoiceConfig {\n /**\n * The name of a prebuilt voice that can be used for speech synthesis.\n *\n * Extracted as a non-nullable type from the GeminiBase.PrebuiltVoiceConfig[\"voiceName\"] property.\n */\n export type VoiceName = NonNullable<\n GeminiBase.PrebuiltVoiceConfig[\"voiceName\"]\n >;\n }\n\n export namespace SpeakerVoiceConfig {\n /**\n * The speaker identifier for a custom or multi-speaker TTS configuration.\n *\n * Extracted as a non-nullable type from the GeminiBase.SpeakerVoiceConfig[\"speaker\"] property.\n */\n export type Speaker = NonNullable<\n GeminiBase.SpeakerVoiceConfig[\"speaker\"]\n >;\n }\n\n export namespace SpeechConfig {\n /**\n * The BCP-47 language code for speech synthesis (e.g., \"en-US\").\n *\n * Extracted as a non-nullable type from the GeminiBase.SpeechConfig[\"languageCode\"] property.\n */\n export type LanguageCode = NonNullable<\n GeminiBase.SpeechConfig[\"languageCode\"]\n >;\n }\n\n /**\n * The level of \"thinking\" or reasoning configured for the model.\n *\n * Extends GeminiBase.ThinkingConfig[\"thinkingLevel\"] to also accept\n * lowercase variants (e.g. \"high\" in addition to \"HIGH\").\n */\n export type ThinkingLevel =\n | GeminiBase.ThinkingConfig[\"thinkingLevel\"]\n | LowercaseLiteral<GeminiBase.ThinkingConfig[\"thinkingLevel\"]>;\n\n /**\n * The role of a content message. The spec types this as `string`, but\n * the API only accepts these specific values.\n */\n export type Role = \"user\" | \"model\" | \"function\";\n\n /**\n * Alias for the unwieldy generated grounding support type name.\n */\n export type GroundingSupport =\n GeminiBase.GoogleAiGenerativelanguageV1betaGroundingSupport;\n\n /**\n * Alias for the unwieldy generated segment type name.\n */\n export type Segment = GeminiBase.GoogleAiGenerativelanguageV1betaSegment;\n\n export namespace Tools {\n /**\n * The mode for function calling configuration, extracted from the\n * FunctionCallingConfig interface.\n */\n export type FunctionCallingConfigMode =\n GeminiBase.Tools.FunctionCallingConfig[\"mode\"];\n }\n\n /**\n * Legacy URL retrieval metadata (predecessor of UrlContextMetadata).\n * Not in the current OpenAPI spec but still returned by the API.\n */\n export interface UrlRetrievalMetadata {\n urlRetrievalContexts?: Array<GeminiBase.UrlMetadata>;\n }\n\n // Augment Candidate with legacy field the API still returns.\n export interface Candidate {\n /** @deprecated Use urlContextMetadata instead. */\n readonly urlRetrievalMetadata?: UrlRetrievalMetadata;\n }\n }\n}\n\n/**\n * Simplified speaker/name pair for multi-speaker config.\n * - `speaker` derived from SpeakerVoiceConfig[\"speaker\"]\n * - `name` is the prebuilt voice name\n */\nexport interface SpeechSpeakerName {\n speaker: GeminiBase.SpeakerVoiceConfig.Speaker;\n name: GeminiBase.PrebuiltVoiceConfig.VoiceName;\n}\n\n/** A voice can be a prebuilt voice name, a speaker/name pair, or an array of pairs */\nexport type SpeechVoice =\n | GeminiBase.PrebuiltVoiceConfig.VoiceName\n | SpeechSpeakerName\n | SpeechSpeakerName[];\n\n/** Voice with language code (derived from SpeechConfig's languageCode) */\nexport interface SpeechVoiceLanguage {\n voice: SpeechVoice;\n languageCode: GeminiBase.SpeechConfig.LanguageCode;\n}\n\n/** Voices with language code */\nexport interface SpeechVoicesLanguage {\n voices: SpeechVoice;\n languageCode: GeminiBase.SpeechConfig.LanguageCode;\n}\n\n/** Simplified language config (with voice or voices) */\nexport type SimplifiedSpeechLanguageConfig =\n | SpeechVoiceLanguage\n | SpeechVoicesLanguage;\n\n/** Top-level simplified config: just a voice, or voice+language */\nexport type SimplifiedSpeechConfig =\n | SpeechVoice\n | SimplifiedSpeechLanguageConfig;\n"],"mappings":";AA2MA,MAAa,sBAAgD,CAC3D,QACA,UACF"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/chat_models/types.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-namespace */\n\nimport type { InteropZodType } from \"@langchain/core/utils/types\";\nimport type { SerializableSchema } from \"@langchain/core/utils/standard_schema\";\nimport type {\n BaseChatModelParams,\n BaseChatModelCallOptions,\n BindToolsInput,\n} from \"@langchain/core/language_models/chat_models\";\nimport type { AsyncCaller } from \"@langchain/core/utils/async_caller\";\nimport type { ApiClient } from \"../clients/index.js\";\nimport type { GenContent as GenContentNamespace } from \"./api_types/generate_content.js\";\nimport type { Interactions as InteractionsNamespace } from \"./api_types/interactions.js\";\nimport type { LowercaseLiteral, Prettify } from \"../utils/misc.js\";\nimport type { GoogleChatApiHandler } from \"./handlers/base.js\";\n\nexport interface BaseChatGoogleFields {\n /**\n * The temperature is used for sampling during response generation, which\n * occurs when topP and topK are applied. Temperature controls the degree of\n * randomness in token selection. Lower temperatures are good for prompts that\n * require a less open-ended or creative response, while higher temperatures\n * can lead to more diverse or creative results.\n *\n * Specify a lower value for less random responses and a higher value for more\n * random responses.\n */\n temperature?: number;\n\n /**\n * Top-P changes how the model selects tokens for output. Tokens are selected\n * from the most probable to least probable until the sum of their\n * probabilities equals the top-P value.\n *\n * Specify a lower value for less random responses and a higher value for more\n * random responses.\n */\n topP?: number;\n\n /**\n * Top-K changes how the model selects tokens for output. A top-K of 1 means\n * the selected token is the most probable among all tokens in the model's\n * vocabulary (also called greedy decoding), while a top-K of 3 means that the\n * next token is selected from among the 3 most probable tokens (using\n * temperature).\n */\n topK?: number;\n\n /**\n * Maximum number of tokens that can be generated in the response. A token is\n * approximately four characters. 100 tokens correspond to roughly 60-80 words.\n * Specify a lower value for shorter responses and a higher value for\n * potentially longer responses.\n */\n maxOutputTokens?: number;\n\n /**\n * Positive values penalize tokens that already appear in the generated text,\n * increasing the probability of generating more diverse content.\n */\n presencePenalty?: number;\n\n /**\n * Positive values penalize tokens that repeatedly appear in the generated\n * text, decreasing the probability of repeating content.\n */\n frequencyPenalty?: number;\n\n /**\n * Specifies a list of strings that tells the model to stop generating text if\n * one of the strings is encountered in the response. If a string appears\n * multiple times in the response, then the response truncates where it's\n * first encountered. The strings are case-sensitive.\n */\n stopSequences?: string[];\n\n /**\n * When seed is fixed to a specific value, the model makes a best effort to\n * provide the same response for repeated requests. Deterministic output isn't\n * guaranteed. Also, changing the model or parameter settings, such as the\n * temperature, can cause variations in the response even when you use the\n * same seed value. By default, a random seed value is used.\n */\n seed?: number;\n\n /**\n * A list of tools the model may use to generate the next response.\n * Can be LangChain tools, OpenAI tools, or Gemini function declarations.\n */\n tools?: BindToolsInput[];\n\n /**\n * OpenAI-compatible alias for media input detail level.\n *\n * This is mapped to `generationConfig.mediaResolution`:\n * - `\"auto\"` => default Gemini behavior (`mediaResolution` omitted)\n * - `\"low\"` => `\"MEDIA_RESOLUTION_LOW\"`\n * - `\"high\"` => `\"MEDIA_RESOLUTION_HIGH\"`\n *\n * If both `mediaResolution` and `detail` are provided, `mediaResolution` wins.\n */\n detail?: \"auto\" | \"low\" | \"high\";\n\n /**\n * The number of reasoning tokens that the model should generate.\n * If explicitly set, then the reasoning blocks will be returned.\n */\n maxReasoningTokens?: number;\n\n /**\n * An alias for `maxReasoningTokens` for compatibility.\n */\n thinkingBudget?: number;\n\n /**\n * An alias for `maxReasoningTokens` under Gemini 2.5 or\n * the primary thinking/reasoning setting for Gemini 3.\n * If explicitly set, then the reasoning blocks will be returned.\n */\n reasoningEffort?: Gemini.Shared.ThinkingLevel;\n\n /**\n * An alias for `reasoningEffort` for compatibility.\n */\n thinkingLevel?: Gemini.Shared.ThinkingLevel;\n\n /**\n * Custom / additional headers to include with every request to the API.\n * When set on both constructor params and per-invocation call options,\n * per-invocation headers take precidence for matching keys.\n */\n customHeaders?: Record<string, string>;\n\n /**\n * Per request settings for blocking unsafe content\n */\n safetySettings?: Prettify<Gemini.Shared.SafetySetting>[];\n\n /**\n * Media resolution for input media processing.\n *\n * This maps to `generationConfig.mediaResolution`, which is a scalar enum-like\n * string value in the Gemini API.\n */\n mediaResolution?: Gemini.Shared.MediaResolution;\n\n /**\n * The schema that the generated response should match.\n * Can be a Zod schema or a JSON Schema object.\n * When set, the response will be structured according to this schema\n * and `responseMimeType` will automatically be set to \"application/json\".\n */\n responseSchema?:\n | InteropZodType\n | SerializableSchema\n | Record<string, unknown>;\n\n /**\n * Desired MIME type of the generated candidate content.\n */\n responseMimeType?: string;\n\n /**\n * The requested modalities of the response.\n * Represents the set of modalities that the model can return.\n * An empty list is equivalent to requesting only text.\n */\n responseModalities?: Prettify<GenContentNamespace.GenerativeLanguageModality>[];\n\n /**\n * Configuration for the model's thinking process\n */\n thinkingConfig?: Prettify<GenContentNamespace.ThinkingConfig>;\n\n /**\n * Speech generation configuration.\n * You can use either Google's definition of the speech configuration,\n * or a simplified version we've defined (which can be as simple\n * as the name of a pre-defined voice).\n */\n speechConfig?:\n | Prettify<GenContentNamespace.SpeechConfig>\n | SimplifiedSpeechConfig;\n\n /**\n * Configuration for image generation.\n */\n imageConfig?: Prettify<GenContentNamespace.ImageConfig>;\n\n /**\n * Inference service tiers.\n * \"priority\" offers highest reliability for higher rates.\n * \"flex\" offers a discount for preemptable processing.\n * Other values are treated as the standard service tier.\n */\n serviceTier?: GenContentNamespace.ServiceTier;\n}\n\nexport interface GenerateContentSpecificFields {\n /**\n * If true, returns the log probabilities of the tokens that were chosen by\n * the model at each step. By default, this parameter is set to false.\n */\n responseLogprobs?: boolean;\n\n /**\n * Returns the log probabilities of the top candidate tokens at each generation\n * step. The model's chosen token might not be the same as the top candidate\n * token at each step. Specify the number of candidates to return by using an\n * integer value in the range of 1-20.\n */\n logprobs?: number;\n\n /**\n * If true, enables enhanced civic answers feature.\n */\n enableEnhancedCivicAnswers?: boolean;\n}\n\nexport interface InteractionsSpecificFields {\n /**\n * Native Interactions API `response_format` configuration (JSON Schema or media response format).\n * Note: `responseSchema`, `responseModalities`, `responseMimeType`, and `imageConfig` are also\n * automatically translated into `response_format` when using the Interactions API.\n */\n responseFormat?: Gemini.Interactions.CreateInteractionParameters[\"response_format\"];\n\n /**\n * The ID of a previous interaction to continue a stateful server-side conversation.\n */\n previousInteractionId?: string;\n\n /**\n * Whether to store the interaction on the server.\n */\n store?: boolean;\n\n /**\n * Whether to execute the interaction in the background (primarily for agents).\n */\n background?: boolean;\n\n /**\n * The name of the agent to use for the interaction (mutually exclusive with `model` in the raw API,\n * or used when invoking an agent endpoint).\n */\n agent?: string;\n\n /**\n * Configuration parameters for the specified agent.\n */\n agentConfig?: Gemini.Interactions.AgentConfig;\n\n /**\n * Optional webhook configuration for receiving asynchronous interaction events.\n */\n webhookConfig?: Gemini.Interactions.WebhookConfig;\n}\n\nexport interface GenerateContentFields\n extends BaseChatGoogleFields, GenerateContentSpecificFields {}\n\nexport interface InteractionsFields\n extends BaseChatGoogleFields, InteractionsSpecificFields {}\n\nexport interface ChatGoogleFields\n extends\n BaseChatGoogleFields,\n Partial<GenerateContentSpecificFields>,\n Partial<InteractionsSpecificFields> {}\n\nexport type GooglePlatformType = \"gai\" | \"gcp\";\n\nexport interface BaseChatGoogleParams\n extends BaseChatModelParams, ChatGoogleFields {\n model: string;\n apiClient?: ApiClient;\n endpoint?: string;\n location?: string;\n apiVersion?: string;\n platformType?: GooglePlatformType;\n vertexai?: boolean;\n streaming?: boolean;\n streamUsage?: boolean;\n apiHandler?: GoogleChatApiHandlerConfig;\n}\n\nexport interface BaseChatGoogleCallOptions\n extends BaseChatModelCallOptions, ChatGoogleFields {\n streamUsage?: boolean;\n}\n\nexport interface GoogleChatApiHandlerParams\n extends BaseChatModelParams, BaseChatGoogleFields {\n apiClient: ApiClient;\n caller: AsyncCaller;\n model: string;\n platform: GooglePlatformType;\n endpoint: string;\n location: string;\n apiVersion: string;\n isVertexExpress: boolean;\n publisher: string;\n streaming: boolean;\n streamUsage: boolean;\n customHeaders?: Record<string, string>;\n}\n\nexport interface GenerateContentApiHandlerParams\n extends GoogleChatApiHandlerParams, GenerateContentSpecificFields {}\n\nexport interface InteractionsApiHandlerParams\n extends GoogleChatApiHandlerParams, InteractionsSpecificFields {}\n\nexport type GoogleChatApiHandlerFactory = (\n params: GoogleChatApiHandlerParams\n) => GoogleChatApiHandler;\n\nexport type GoogleChatApiHandlerConfig =\n | \"generateContent\"\n | \"interactions\"\n | GoogleChatApiHandlerFactory;\n\nexport type GenerateContentInvocationParams = Partial<\n Omit<GenContentNamespace.GenerateContentRequest, \"contents\">\n> & {\n serviceTier?: GenContentNamespace.ServiceTier;\n};\n\nexport type InteractionsInvocationParams = Partial<\n Omit<Gemini.Interactions.CreateInteractionParameters, \"input\">\n>;\n\n// These are service tiers that we specifically need to send.\n// Other values will be ignored, resulting in the default\n// or \"standard\" setting.\nexport const settableServiceTier: GenContentNamespace.ServiceTier[] = [\n \"flex\",\n \"priority\",\n];\n\n// 1. Augment GenContent so internal references in generated types resolve\ndeclare module \"./api_types/generate_content.js\" {\n export namespace GenContent {\n // Gemini parts are contained as one intersecting type\n // in the spec, so we need to pick out the specific parts we need.\n export namespace Part {\n export type CodeExecutionResult = Pick<\n GenContentNamespace.Part,\n \"codeExecutionResult\"\n >;\n export type ExecutableCode = Pick<\n GenContentNamespace.Part,\n \"executableCode\"\n >;\n export type FileData = Pick<\n GenContentNamespace.Part,\n \"fileData\" | \"videoMetadata\"\n >;\n export type FunctionCall = Required<\n Pick<GenContentNamespace.Part, \"functionCall\">\n > &\n Pick<GenContentNamespace.Part, \"thoughtSignature\">;\n export type FunctionResponse = Pick<\n GenContentNamespace.Part,\n \"functionResponse\"\n >;\n export type InlineData = Pick<\n GenContentNamespace.Part,\n \"inlineData\" | \"videoMetadata\"\n >;\n export type MediaResolution = Pick<\n GenContentNamespace.Part,\n \"mediaResolution\"\n >;\n export type PartMetadata = Pick<GenContentNamespace.Part, \"partMetadata\">;\n export type Text = Pick<GenContentNamespace.Part, \"text\">;\n export type Thought = Pick<GenContentNamespace.Part, \"thought\">;\n export type ThoughtSignature = Pick<\n GenContentNamespace.Part,\n \"thoughtSignature\"\n >;\n }\n\n export namespace PrebuiltVoiceConfig {\n /**\n * The name of a prebuilt voice that can be used for speech synthesis.\n *\n * Extracted as a non-nullable type from the PrebuiltVoiceConfig[\"voiceName\"] property.\n */\n export type VoiceName = NonNullable<\n GenContentNamespace.PrebuiltVoiceConfig[\"voiceName\"]\n >;\n }\n\n export namespace SpeakerVoiceConfig {\n /**\n * The speaker identifier for a custom or multi-speaker TTS configuration.\n *\n * Extracted as a non-nullable type from the SpeakerVoiceConfig[\"speaker\"] property.\n */\n export type Speaker = NonNullable<\n GenContentNamespace.SpeakerVoiceConfig[\"speaker\"]\n >;\n }\n\n export namespace SpeechConfig {\n /**\n * The BCP-47 language code for speech synthesis (e.g., \"en-US\").\n *\n * Extracted as a non-nullable type from the SpeechConfig[\"languageCode\"] property.\n */\n export type LanguageCode = NonNullable<\n GenContentNamespace.SpeechConfig[\"languageCode\"]\n >;\n }\n\n /**\n * The level of \"thinking\" or reasoning configured for the model.\n *\n * Extends ThinkingConfig[\"thinkingLevel\"] to also accept\n * lowercase variants (e.g. \"high\" in addition to \"HIGH\").\n */\n export type ThinkingLevel =\n | GenContentNamespace.ThinkingConfig[\"thinkingLevel\"]\n | LowercaseLiteral<GenContentNamespace.ThinkingConfig[\"thinkingLevel\"]>;\n\n /**\n * The role of a content message. The spec types this as `string`, but\n * the API only accepts these specific values.\n */\n export type Role = \"user\" | \"model\" | \"function\";\n\n /**\n * Alias for the unwieldy generated grounding support type name.\n */\n export type GroundingSupport =\n GenContentNamespace.GoogleAiGenerativelanguageV1betaGroundingSupport;\n\n /**\n * Alias for the unwieldy generated segment type name.\n */\n export type Segment =\n GenContentNamespace.GoogleAiGenerativelanguageV1betaSegment;\n\n export namespace Tools {\n /**\n * The mode for function calling configuration, extracted from the\n * FunctionCallingConfig interface.\n */\n export type FunctionCallingConfigMode =\n GenContentNamespace.Tools.FunctionCallingConfig[\"mode\"];\n }\n\n /**\n * Legacy URL retrieval metadata (predecessor of UrlContextMetadata).\n * Not in the current OpenAPI spec but still returned by the API.\n */\n export interface UrlRetrievalMetadata {\n urlRetrievalContexts?: Array<GenContentNamespace.UrlMetadata>;\n }\n\n // Augment Candidate with legacy field the API still returns.\n export interface Candidate {\n /** @deprecated Use urlContextMetadata instead. */\n readonly urlRetrievalMetadata?: UrlRetrievalMetadata;\n }\n }\n}\n\n// 2. Expose the Gemini composite namespace\nexport declare namespace Gemini {\n export namespace Shared {\n export type HarmCategory = GenContentNamespace.HarmCategory;\n export type SafetySetting = GenContentNamespace.SafetySetting;\n export type MediaResolution =\n GenContentNamespace.GenerationConfig[\"mediaResolution\"];\n export type ThinkingLevel = GenContentNamespace.ThinkingLevel;\n }\n\n export namespace GenContent {\n export type Content = GenContentNamespace.Content;\n export type Candidate = GenContentNamespace.Candidate;\n export type GenerateContentRequest =\n GenContentNamespace.GenerateContentRequest;\n export type GenerateContentResponse =\n GenContentNamespace.GenerateContentResponse;\n export type GenerationConfig = GenContentNamespace.GenerationConfig;\n export type SafetyRating = GenContentNamespace.SafetyRating;\n export type SafetySetting = GenContentNamespace.SafetySetting;\n export type PromptFeedback = GenContentNamespace.PromptFeedback;\n export type Tool = GenContentNamespace.Tool;\n export type ThinkingConfig = GenContentNamespace.ThinkingConfig;\n export type ThinkingLevel = GenContentNamespace.ThinkingLevel;\n export type SpeechConfig = GenContentNamespace.SpeechConfig;\n export namespace SpeechConfig {\n export type LanguageCode = GenContentNamespace.SpeechConfig.LanguageCode;\n }\n export type PrebuiltVoiceConfig = GenContentNamespace.PrebuiltVoiceConfig;\n export namespace PrebuiltVoiceConfig {\n export type VoiceName = GenContentNamespace.PrebuiltVoiceConfig.VoiceName;\n }\n export type SpeakerVoiceConfig = GenContentNamespace.SpeakerVoiceConfig;\n export namespace SpeakerVoiceConfig {\n export type Speaker = GenContentNamespace.SpeakerVoiceConfig.Speaker;\n }\n export type ServiceTier = GenContentNamespace.ServiceTier;\n export type ImageConfig = GenContentNamespace.ImageConfig;\n export type Role = GenContentNamespace.Role;\n export type GroundingSupport = GenContentNamespace.GroundingSupport;\n export type GroundingMetadata = GenContentNamespace.GroundingMetadata;\n export type CitationMetadata = GenContentNamespace.CitationMetadata;\n export type UsageMetadata = GenContentNamespace.UsageMetadata;\n export type ModalityTokenCount = GenContentNamespace.ModalityTokenCount;\n export type Part = GenContentNamespace.Part;\n export namespace Part {\n export type CodeExecutionResult =\n GenContentNamespace.Part.CodeExecutionResult;\n export type ExecutableCode = GenContentNamespace.Part.ExecutableCode;\n export type FileData = GenContentNamespace.Part.FileData;\n export type FunctionCall = GenContentNamespace.Part.FunctionCall;\n export type FunctionResponse = GenContentNamespace.Part.FunctionResponse;\n export type InlineData = GenContentNamespace.Part.InlineData;\n export type MediaResolution = GenContentNamespace.Part.MediaResolution;\n export type PartMetadata = GenContentNamespace.Part.PartMetadata;\n export type Text = GenContentNamespace.Part.Text;\n export type Thought = GenContentNamespace.Part.Thought;\n export type ThoughtSignature = GenContentNamespace.Part.ThoughtSignature;\n }\n export namespace Tools {\n export type FunctionCallingConfigMode =\n GenContentNamespace.Tools.FunctionCallingConfigMode;\n export type FunctionDeclaration =\n GenContentNamespace.Tools.FunctionDeclaration;\n export type GoogleSearch = GenContentNamespace.Tools.GoogleSearch;\n export type CodeExecution = GenContentNamespace.Tools.CodeExecution;\n export type UrlContext = GenContentNamespace.Tools.UrlContext;\n export type GoogleMaps = GenContentNamespace.Tools.GoogleMaps;\n export type FileSearch = GenContentNamespace.Tools.FileSearch;\n export type ComputerUse = GenContentNamespace.Tools.ComputerUse;\n export type FunctionCallingConfig =\n GenContentNamespace.Tools.FunctionCallingConfig;\n export type RetrievalConfig = GenContentNamespace.Tools.RetrievalConfig;\n export type ToolConfig = GenContentNamespace.Tools.ToolConfig;\n export type Schema = GenContentNamespace.Tools.Schema;\n export type LatLng = GenContentNamespace.Tools.LatLng;\n export type Interval = GenContentNamespace.Tools.Interval;\n export type SearchTypes = GenContentNamespace.Tools.SearchTypes;\n export type Type = GenContentNamespace.Tools.Type;\n export type WebSearch = GenContentNamespace.Tools.WebSearch;\n export type ImageSearch = GenContentNamespace.Tools.ImageSearch;\n }\n }\n\n // Type aliases for generateContent wire types during Phase 1 transition\n export type Content = GenContentNamespace.Content;\n export type Candidate = GenContentNamespace.Candidate;\n export type GenerateContentRequest =\n GenContentNamespace.GenerateContentRequest;\n export type GenerateContentResponse =\n GenContentNamespace.GenerateContentResponse;\n export type GenerationConfig = GenContentNamespace.GenerationConfig;\n export type SafetyRating = GenContentNamespace.SafetyRating;\n export type SafetySetting = GenContentNamespace.SafetySetting;\n export type PromptFeedback = GenContentNamespace.PromptFeedback;\n export type Tool = GenContentNamespace.Tool;\n export type ThinkingConfig = GenContentNamespace.ThinkingConfig;\n export type ThinkingLevel = GenContentNamespace.ThinkingLevel;\n export type SpeechConfig = GenContentNamespace.SpeechConfig;\n export namespace SpeechConfig {\n export type LanguageCode = GenContentNamespace.SpeechConfig.LanguageCode;\n }\n export type PrebuiltVoiceConfig = GenContentNamespace.PrebuiltVoiceConfig;\n export namespace PrebuiltVoiceConfig {\n export type VoiceName = GenContentNamespace.PrebuiltVoiceConfig.VoiceName;\n }\n export type SpeakerVoiceConfig = GenContentNamespace.SpeakerVoiceConfig;\n export namespace SpeakerVoiceConfig {\n export type Speaker = GenContentNamespace.SpeakerVoiceConfig.Speaker;\n }\n export type ServiceTier = GenContentNamespace.ServiceTier;\n export type ImageConfig = GenContentNamespace.ImageConfig;\n export type Role = GenContentNamespace.Role;\n export type GroundingSupport = GenContentNamespace.GroundingSupport;\n export type GroundingMetadata = GenContentNamespace.GroundingMetadata;\n export type CitationMetadata = GenContentNamespace.CitationMetadata;\n export type UsageMetadata = GenContentNamespace.UsageMetadata;\n export type ModalityTokenCount = GenContentNamespace.ModalityTokenCount;\n\n export type Part = GenContentNamespace.Part;\n export namespace Part {\n export type CodeExecutionResult =\n GenContentNamespace.Part.CodeExecutionResult;\n export type ExecutableCode = GenContentNamespace.Part.ExecutableCode;\n export type FileData = GenContentNamespace.Part.FileData;\n export type FunctionCall = GenContentNamespace.Part.FunctionCall;\n export type FunctionResponse = GenContentNamespace.Part.FunctionResponse;\n export type InlineData = GenContentNamespace.Part.InlineData;\n export type MediaResolution = GenContentNamespace.Part.MediaResolution;\n export type PartMetadata = GenContentNamespace.Part.PartMetadata;\n export type Text = GenContentNamespace.Part.Text;\n export type Thought = GenContentNamespace.Part.Thought;\n export type ThoughtSignature = GenContentNamespace.Part.ThoughtSignature;\n }\n\n export namespace Tools {\n export type FunctionCallingConfigMode =\n GenContentNamespace.Tools.FunctionCallingConfigMode;\n export type FunctionDeclaration =\n GenContentNamespace.Tools.FunctionDeclaration;\n export type GoogleSearch = GenContentNamespace.Tools.GoogleSearch;\n export type CodeExecution = GenContentNamespace.Tools.CodeExecution;\n export type UrlContext = GenContentNamespace.Tools.UrlContext;\n export type GoogleMaps = GenContentNamespace.Tools.GoogleMaps;\n export type FileSearch = GenContentNamespace.Tools.FileSearch;\n export type ComputerUse = GenContentNamespace.Tools.ComputerUse;\n export type FunctionCallingConfig =\n GenContentNamespace.Tools.FunctionCallingConfig;\n export type RetrievalConfig = GenContentNamespace.Tools.RetrievalConfig;\n export type ToolConfig = GenContentNamespace.Tools.ToolConfig;\n export type Schema = GenContentNamespace.Tools.Schema;\n export type LatLng = GenContentNamespace.Tools.LatLng;\n export type Interval = GenContentNamespace.Tools.Interval;\n export type SearchTypes = GenContentNamespace.Tools.SearchTypes;\n export type Type = GenContentNamespace.Tools.Type;\n export type WebSearch = GenContentNamespace.Tools.WebSearch;\n export type ImageSearch = GenContentNamespace.Tools.ImageSearch;\n }\n\n export namespace Interactions {\n // =========================================================================\n // Narrowed Content & MediaProcessing types\n // Note: interactions-openapi.json uses JSON Schema `\"const\"` instead of\n // `\"enum\"` for `type` discriminators, which sparktype generates as\n // `type: unknown` in `./api_types/interactions.ts`. We narrow each\n // discriminator here so TypeScript discriminated unions work without\n // modifying the sparktype-generated file.\n // =========================================================================\n\n // Narrowed from InteractionsNamespace.StaticMediaProcessing because\n // interactions-openapi.json uses `\"const\": \"static\"`, which sparktype outputs as `unknown`.\n export type StaticMediaProcessing = Omit<\n InteractionsNamespace.StaticMediaProcessing,\n \"type\"\n > & {\n type: \"static\";\n };\n\n export type MediaProcessing = StaticMediaProcessing;\n\n // Narrowed from InteractionsNamespace.UrlCitation because\n // interactions-openapi.json uses `\"const\": \"url_citation\"`, which sparktype outputs as `unknown`.\n export type UrlCitation = Omit<\n InteractionsNamespace.UrlCitation,\n \"type\"\n > & {\n type: \"url_citation\";\n };\n\n // Narrowed from InteractionsNamespace.FileCitation because\n // interactions-openapi.json uses `\"const\": \"file_citation\"`, which sparktype outputs as `unknown`.\n export type FileCitation = Omit<\n InteractionsNamespace.FileCitation,\n \"type\"\n > & {\n type: \"file_citation\";\n };\n\n // Narrowed from InteractionsNamespace.PlaceCitation because\n // interactions-openapi.json uses `\"const\": \"place_citation\"`, which sparktype outputs as `unknown`.\n export type PlaceCitation = Omit<\n InteractionsNamespace.PlaceCitation,\n \"type\"\n > & {\n type: \"place_citation\";\n };\n\n // Narrowed from InteractionsNamespace.SpeechAnnotation because\n // interactions-openapi.json uses `\"const\": \"speech_metadata\"`, which sparktype outputs as `unknown`.\n export type SpeechAnnotation = Omit<\n InteractionsNamespace.SpeechAnnotation,\n \"type\"\n > & {\n type: \"speech_metadata\";\n };\n\n // Narrowed from InteractionsNamespace.WordInfo because\n // interactions-openapi.json uses `\"const\": \"word_info\"`, which sparktype outputs as `unknown`.\n export type WordInfo = Omit<InteractionsNamespace.WordInfo, \"type\"> & {\n type: \"word_info\";\n };\n\n // Narrowed union of Annotation types with literal `type` discriminators.\n export type Annotation =\n | UrlCitation\n | FileCitation\n | PlaceCitation\n | SpeechAnnotation\n | WordInfo;\n\n // Narrowed from InteractionsNamespace.TextContent because\n // interactions-openapi.json uses `\"const\": \"text\"`, which sparktype outputs as `unknown`.\n export type TextContent = Omit<\n InteractionsNamespace.TextContent,\n \"type\" | \"annotations\"\n > & {\n type: \"text\";\n annotations?: Array<Annotation>;\n };\n\n // Narrowed from InteractionsNamespace.ImageContent because\n // interactions-openapi.json uses `\"const\": \"image\"`, which sparktype outputs as `unknown`.\n export type ImageContent = Omit<\n InteractionsNamespace.ImageContent,\n \"type\"\n > & {\n type: \"image\";\n };\n\n // Narrowed from InteractionsNamespace.AudioContent because\n // interactions-openapi.json uses `\"const\": \"audio\"`, which sparktype outputs as `unknown`.\n export type AudioContent = Omit<\n InteractionsNamespace.AudioContent,\n \"type\"\n > & {\n type: \"audio\";\n };\n\n // Narrowed from InteractionsNamespace.DocumentContent because\n // interactions-openapi.json uses `\"const\": \"document\"`, which sparktype outputs as `unknown`.\n export type DocumentContent = Omit<\n InteractionsNamespace.DocumentContent,\n \"type\"\n > & {\n type: \"document\";\n };\n\n // Narrowed from InteractionsNamespace.VideoContent because\n // interactions-openapi.json uses `\"const\": \"video\"`, which sparktype outputs as `unknown`.\n export type VideoContent = Omit<\n InteractionsNamespace.VideoContent,\n \"type\" | \"processing\"\n > & {\n type: \"video\";\n processing?: MediaProcessing | \"static\" | \"agentic\" | (string & {});\n };\n\n // Narrowed union of Content types with literal `type` discriminators.\n export type Content =\n | TextContent\n | ImageContent\n | AudioContent\n | DocumentContent\n | VideoContent;\n\n // =========================================================================\n // Narrowed Step types\n // =========================================================================\n\n // Narrowed from InteractionsNamespace.UserInputStep because\n // interactions-openapi.json uses `\"const\": \"user_input\"`, which sparktype outputs as `unknown`.\n export type UserInputStep = Omit<\n InteractionsNamespace.UserInputStep,\n \"type\" | \"content\"\n > & {\n type: \"user_input\";\n content?: Array<Content> | string;\n };\n\n // Narrowed from InteractionsNamespace.ModelOutputStep because\n // interactions-openapi.json uses `\"const\": \"model_output\"`, which sparktype outputs as `unknown`.\n export type ModelOutputStep = Omit<\n InteractionsNamespace.ModelOutputStep,\n \"type\" | \"content\"\n > & {\n type: \"model_output\";\n content?: Array<Content> | string;\n };\n\n // Narrowed from InteractionsNamespace.ThoughtStep because\n // interactions-openapi.json uses `\"const\": \"thought\"`, which sparktype outputs as `unknown`.\n export type ThoughtStep = Omit<\n InteractionsNamespace.ThoughtStep,\n \"type\" | \"summary\"\n > & {\n type: \"thought\";\n summary?: Array<Content>;\n };\n\n // Narrowed from InteractionsNamespace.FunctionCallStep because\n // interactions-openapi.json uses `\"const\": \"function_call\"`, which sparktype outputs as `unknown`.\n export type FunctionCallStep = Omit<\n InteractionsNamespace.FunctionCallStep,\n \"type\"\n > & {\n type: \"function_call\";\n };\n\n // Narrowed from InteractionsNamespace.FunctionResultStep because\n // interactions-openapi.json uses `\"const\": \"function_result\"`, which sparktype outputs as `unknown`.\n export type FunctionResultStep = Omit<\n InteractionsNamespace.FunctionResultStep,\n \"type\" | \"result\"\n > & {\n type: \"function_result\";\n result: Array<Content> | string | Record<string, unknown>;\n };\n\n // Narrowed from InteractionsNamespace.CodeExecutionCallStep because\n // interactions-openapi.json uses `\"const\": \"code_execution_call\"`, which sparktype outputs as `unknown`.\n export type CodeExecutionCallStep = Omit<\n InteractionsNamespace.CodeExecutionCallStep,\n \"type\"\n > & {\n type: \"code_execution_call\";\n };\n\n // Narrowed from InteractionsNamespace.CodeExecutionResultStep because\n // interactions-openapi.json uses `\"const\": \"code_execution_result\"`, which sparktype outputs as `unknown`.\n export type CodeExecutionResultStep = Omit<\n InteractionsNamespace.CodeExecutionResultStep,\n \"type\"\n > & {\n type: \"code_execution_result\";\n };\n\n // Narrowed from InteractionsNamespace.GoogleSearchCallStep because\n // interactions-openapi.json uses `\"const\": \"google_search_call\"`, which sparktype outputs as `unknown`.\n export type GoogleSearchCallStep = Omit<\n InteractionsNamespace.GoogleSearchCallStep,\n \"type\"\n > & {\n type: \"google_search_call\";\n };\n\n // Narrowed from InteractionsNamespace.GoogleSearchResultStep because\n // interactions-openapi.json uses `\"const\": \"google_search_result\"`, which sparktype outputs as `unknown`.\n export type GoogleSearchResultStep = Omit<\n InteractionsNamespace.GoogleSearchResultStep,\n \"type\"\n > & {\n type: \"google_search_result\";\n };\n\n // Narrowed from InteractionsNamespace.UrlContextCallStep because\n // interactions-openapi.json uses `\"const\": \"url_context_call\"`, which sparktype outputs as `unknown`.\n export type UrlContextCallStep = Omit<\n InteractionsNamespace.UrlContextCallStep,\n \"type\"\n > & {\n type: \"url_context_call\";\n };\n\n // Narrowed from InteractionsNamespace.UrlContextResultStep because\n // interactions-openapi.json uses `\"const\": \"url_context_result\"`, which sparktype outputs as `unknown`.\n export type UrlContextResultStep = Omit<\n InteractionsNamespace.UrlContextResultStep,\n \"type\"\n > & {\n type: \"url_context_result\";\n };\n\n // Narrowed from InteractionsNamespace.FileSearchCallStep because\n // interactions-openapi.json uses `\"const\": \"file_search_call\"`, which sparktype outputs as `unknown`.\n export type FileSearchCallStep = Omit<\n InteractionsNamespace.FileSearchCallStep,\n \"type\"\n > & {\n type: \"file_search_call\";\n };\n\n // Narrowed from InteractionsNamespace.FileSearchResultStep because\n // interactions-openapi.json uses `\"const\": \"file_search_result\"`, which sparktype outputs as `unknown`.\n export type FileSearchResultStep = Omit<\n InteractionsNamespace.FileSearchResultStep,\n \"type\"\n > & {\n type: \"file_search_result\";\n result?: Array<FileSearchResultItem>;\n };\n\n // Narrowed from InteractionsNamespace.GoogleMapsCallStep because\n // interactions-openapi.json uses `\"const\": \"google_maps_call\"`, which sparktype outputs as `unknown`.\n export type GoogleMapsCallStep = Omit<\n InteractionsNamespace.GoogleMapsCallStep,\n \"type\"\n > & {\n type: \"google_maps_call\";\n };\n\n // Narrowed from InteractionsNamespace.GoogleMapsResultStep because\n // interactions-openapi.json uses `\"const\": \"google_maps_result\"`, which sparktype outputs as `unknown`.\n export type GoogleMapsResultStep = Omit<\n InteractionsNamespace.GoogleMapsResultStep,\n \"type\"\n > & {\n type: \"google_maps_result\";\n };\n\n // Narrowed from InteractionsNamespace.McpServerToolCallStep because\n // interactions-openapi.json uses `\"const\": \"mcp_server_tool_call\"`, which sparktype outputs as `unknown`.\n export type McpServerToolCallStep = Omit<\n InteractionsNamespace.McpServerToolCallStep,\n \"type\"\n > & {\n type: \"mcp_server_tool_call\";\n };\n\n // Narrowed from InteractionsNamespace.McpServerToolResultStep because\n // interactions-openapi.json uses `\"const\": \"mcp_server_tool_result\"`, which sparktype outputs as `unknown`.\n export type McpServerToolResultStep = Omit<\n InteractionsNamespace.McpServerToolResultStep,\n \"type\" | \"result\"\n > & {\n type: \"mcp_server_tool_result\";\n result: Array<Content> | string | Record<string, unknown>;\n };\n\n // Narrowed from InteractionsNamespace.ProcessingCallStep because\n // interactions-openapi.json uses `\"const\": \"processing_call\"`, which sparktype outputs as `unknown`.\n export type ProcessingCallStep = Omit<\n InteractionsNamespace.ProcessingCallStep,\n \"type\"\n > & {\n type: \"processing_call\";\n };\n\n // Narrowed from InteractionsNamespace.ProcessingResultStep because\n // interactions-openapi.json uses `\"const\": \"processing_result\"`, which sparktype outputs as `unknown`.\n export type ProcessingResultStep = Omit<\n InteractionsNamespace.ProcessingResultStep,\n \"type\"\n > & {\n type: \"processing_result\";\n };\n\n // Narrowed from InteractionsNamespace.RetrievalCallStep because\n // interactions-openapi.json uses `\"const\": \"retrieval_call\"`, which sparktype outputs as `unknown`.\n export type RetrievalCallStep = Omit<\n InteractionsNamespace.RetrievalCallStep,\n \"type\"\n > & {\n type: \"retrieval_call\";\n };\n\n // Narrowed from InteractionsNamespace.RetrievalResultStep because\n // interactions-openapi.json uses `\"const\": \"retrieval_result\"`, which sparktype outputs as `unknown`.\n export type RetrievalResultStep = Omit<\n InteractionsNamespace.RetrievalResultStep,\n \"type\"\n > & {\n type: \"retrieval_result\";\n };\n\n // Narrowed union of Step types with literal `type` discriminators.\n export type Step =\n | UserInputStep\n | ModelOutputStep\n | ThoughtStep\n | FunctionCallStep\n | FunctionResultStep\n | CodeExecutionCallStep\n | CodeExecutionResultStep\n | GoogleSearchCallStep\n | GoogleSearchResultStep\n | UrlContextCallStep\n | UrlContextResultStep\n | FileSearchCallStep\n | FileSearchResultStep\n | GoogleMapsCallStep\n | GoogleMapsResultStep\n | McpServerToolCallStep\n | McpServerToolResultStep\n | ProcessingCallStep\n | ProcessingResultStep\n | RetrievalCallStep\n | RetrievalResultStep;\n\n // =========================================================================\n // Narrowed Tool types\n // =========================================================================\n\n // Narrowed from InteractionsNamespace.Tools.Function because\n // interactions-openapi.json uses `\"const\": \"function\"`, which sparktype outputs as `unknown`.\n export type Function = Omit<\n InteractionsNamespace.Tools.Function,\n \"type\"\n > & {\n type: \"function\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.GoogleSearch because\n // interactions-openapi.json uses `\"const\": \"google_search\"`, which sparktype outputs as `unknown`.\n export type GoogleSearch = Omit<\n InteractionsNamespace.Tools.GoogleSearch,\n \"type\"\n > & {\n type: \"google_search\";\n time_range_filter?: {\n start_time?: string;\n end_time?: string;\n };\n };\n\n // Narrowed from InteractionsNamespace.Tools.CodeExecution because\n // interactions-openapi.json uses `\"const\": \"code_execution\"`, which sparktype outputs as `unknown`.\n export type CodeExecution = Omit<\n InteractionsNamespace.Tools.CodeExecution,\n \"type\"\n > & {\n type: \"code_execution\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.UrlContext because\n // interactions-openapi.json uses `\"const\": \"url_context\"`, which sparktype outputs as `unknown`.\n export type UrlContext = Omit<\n InteractionsNamespace.Tools.UrlContext,\n \"type\"\n > & {\n type: \"url_context\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.ComputerUse because\n // interactions-openapi.json uses `\"const\": \"computer_use\"`, which sparktype outputs as `unknown`.\n export type ComputerUse = Omit<\n InteractionsNamespace.Tools.ComputerUse,\n \"type\"\n > & {\n type: \"computer_use\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.FileSearch because\n // interactions-openapi.json uses `\"const\": \"file_search\"`, which sparktype outputs as `unknown`.\n export type FileSearch = Omit<\n InteractionsNamespace.Tools.FileSearch,\n \"type\"\n > & {\n type: \"file_search\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.GoogleMaps because\n // interactions-openapi.json uses `\"const\": \"google_maps\"`, which sparktype outputs as `unknown`.\n export type GoogleMaps = Omit<\n InteractionsNamespace.Tools.GoogleMaps,\n \"type\"\n > & {\n type: \"google_maps\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.McpServer because\n // interactions-openapi.json uses `\"const\": \"mcp_server\"`, which sparktype outputs as `unknown`.\n export type McpServer = Omit<\n InteractionsNamespace.Tools.McpServer,\n \"type\"\n > & {\n type: \"mcp_server\";\n };\n\n // Narrowed from InteractionsNamespace.Tools.Retrieval because\n // interactions-openapi.json uses `\"const\": \"retrieval\"`, which sparktype outputs as `unknown`.\n export type Retrieval = Omit<\n InteractionsNamespace.Tools.Retrieval,\n \"type\"\n > & {\n type: \"retrieval\";\n };\n\n // Narrowed union of Tool types with literal `type` discriminators.\n export type Tool =\n | Function\n | GoogleSearch\n | CodeExecution\n | UrlContext\n | ComputerUse\n | FileSearch\n | GoogleMaps\n | McpServer\n | Retrieval;\n\n export namespace Tools {\n export type AllowedTools = InteractionsNamespace.Tools.AllowedTools;\n export type CodeExecution = Gemini.Interactions.CodeExecution;\n export type ComputerUse = Gemini.Interactions.ComputerUse;\n export type FileSearch = Gemini.Interactions.FileSearch;\n export type Function = Gemini.Interactions.Function;\n export type GoogleMaps = Gemini.Interactions.GoogleMaps;\n export type GoogleSearch = Gemini.Interactions.GoogleSearch;\n export type McpServer = Gemini.Interactions.McpServer;\n export type Retrieval = Gemini.Interactions.Retrieval;\n export type Tool = Gemini.Interactions.Tool;\n export type UrlContext = Gemini.Interactions.UrlContext;\n export type VertexAISearchConfig =\n InteractionsNamespace.Tools.VertexAISearchConfig;\n }\n\n // =========================================================================\n // Narrowed ResponseFormat types\n // =========================================================================\n\n // Narrowed from InteractionsNamespace.TextResponseFormat because\n // interactions-openapi.json uses `\"const\": \"text\"`, which sparktype outputs as `unknown`.\n export type TextResponseFormat = Omit<\n InteractionsNamespace.TextResponseFormat,\n \"type\"\n > & {\n type: \"text\";\n };\n\n // Narrowed from InteractionsNamespace.ImageResponseFormat because\n // interactions-openapi.json uses `\"const\": \"image\"`, which sparktype outputs as `unknown`.\n export type ImageResponseFormat = Omit<\n InteractionsNamespace.ImageResponseFormat,\n \"type\"\n > & {\n type: \"image\";\n };\n\n // Narrowed from InteractionsNamespace.AudioResponseFormat because\n // interactions-openapi.json uses `\"const\": \"audio\"`, which sparktype outputs as `unknown`.\n export type AudioResponseFormat = Omit<\n InteractionsNamespace.AudioResponseFormat,\n \"type\"\n > & {\n type: \"audio\";\n };\n\n // Narrowed from InteractionsNamespace.VideoResponseFormat because\n // interactions-openapi.json uses `\"const\": \"video\"`, which sparktype outputs as `unknown`.\n export type VideoResponseFormat = Omit<\n InteractionsNamespace.VideoResponseFormat,\n \"type\"\n > & {\n type: \"video\";\n mime_type?: string;\n };\n\n // Narrowed union of ResponseFormat types with literal `type` discriminators.\n export type ResponseFormat =\n | TextResponseFormat\n | ImageResponseFormat\n | AudioResponseFormat\n | VideoResponseFormat;\n\n // =========================================================================\n // Narrowed AgentConfig types\n // =========================================================================\n\n // Narrowed from InteractionsNamespace.AntigravityAgentConfig because\n // interactions-openapi.json uses `\"const\": \"antigravity\"`, which sparktype outputs as `unknown`.\n export type AntigravityAgentConfig = Omit<\n InteractionsNamespace.AntigravityAgentConfig,\n \"type\"\n > & {\n type: \"antigravity\";\n };\n\n // Narrowed from InteractionsNamespace.CodeMenderAgentConfig because\n // interactions-openapi.json uses `\"const\": \"code-mender\"`, which sparktype outputs as `unknown`.\n export type CodeMenderAgentConfig = Omit<\n InteractionsNamespace.CodeMenderAgentConfig,\n \"type\"\n > & {\n type: \"code-mender\";\n };\n\n // Narrowed from InteractionsNamespace.DeepResearchAgentConfig because\n // interactions-openapi.json uses `\"const\": \"deep-research\"`, which sparktype outputs as `unknown`.\n export type DeepResearchAgentConfig = Omit<\n InteractionsNamespace.DeepResearchAgentConfig,\n \"type\"\n > & {\n type: \"deep-research\";\n };\n\n // Narrowed from InteractionsNamespace.DynamicAgentConfig because\n // interactions-openapi.json uses `\"const\": \"dynamic\"`, which sparktype outputs as `unknown`.\n export type DynamicAgentConfig = Omit<\n InteractionsNamespace.DynamicAgentConfig,\n \"type\"\n > & {\n type: \"dynamic\";\n };\n\n // Narrowed union of AgentConfig types with literal `type` discriminators.\n export type AgentConfig =\n | AntigravityAgentConfig\n | CodeMenderAgentConfig\n | DeepResearchAgentConfig\n | DynamicAgentConfig;\n\n // =========================================================================\n // Narrowed Top-Level Request & Response Container types\n // =========================================================================\n\n // Request parameters for creating an Interaction (`POST /v1beta/interactions`).\n // Combines the writable request fields from Interaction\n // with narrowed `input`, `tools`, `response_format`, `generation_config`, and `agent_config` unions.\n export type CreateInteractionParameters = Omit<\n InteractionsNamespace.Interaction,\n | \"agent_config\"\n | \"created\"\n | \"environment_id\"\n | \"errors\"\n | \"generation_config\"\n | \"id\"\n | \"input\"\n | \"model\"\n | \"response_format\"\n | \"status\"\n | \"steps\"\n | \"tools\"\n | \"updated\"\n | \"usage\"\n > & {\n model?: InteractionsNamespace.ModelOption;\n agent?: InteractionsNamespace.AgentOption;\n agent_config?: AgentConfig;\n generation_config?: GenerationConfig;\n input: Array<Content> | Array<Step> | Content | Step | string;\n response_format?:\n | Record<string, unknown>\n | ResponseFormat\n | Array<ResponseFormat>;\n tools?: Array<Tool>;\n };\n\n // Narrowed from InteractionsNamespace.Interaction so nested\n // `steps`, `input`, `tools`, `response_format`, `generation_config`, and `agent_config` use the narrowed\n // discriminator unions above. Also includes optional legacy `outputs` and `role` fields.\n export type Interaction = Omit<\n InteractionsNamespace.Interaction,\n | \"agent_config\"\n | \"generation_config\"\n | \"input\"\n | \"model\"\n | \"response_format\"\n | \"steps\"\n | \"tools\"\n > & {\n model?: InteractionsNamespace.ModelOption;\n agent?: InteractionsNamespace.AgentOption;\n agent_config?: AgentConfig;\n generation_config?: GenerationConfig;\n input?: Array<Content> | Array<Step> | Content | Step | string;\n response_format?:\n | Record<string, unknown>\n | ResponseFormat\n | Array<ResponseFormat>;\n role?: string;\n steps?: Array<Step>;\n outputs?: Array<Step | Content>;\n tools?: Array<Tool>;\n };\n\n // =========================================================================\n // Re-exported non-discriminated types from `./api_types/interactions.ts`\n // =========================================================================\n export type AllowedTools = InteractionsNamespace.Tools.AllowedTools;\n export type CodeExecutionCallStepArguments =\n InteractionsNamespace.CodeExecutionCallStepArguments;\n export type Error = InteractionsNamespace.Status;\n export type Status = InteractionsNamespace.Status;\n export interface FileSearchResultItem {\n title?: string;\n text?: string;\n file_search_store?: string;\n }\n export type GenerationConfig = Omit<\n InteractionsNamespace.GenerationConfig,\n \"image_config\"\n > & {\n top_k?: number;\n presence_penalty?: number;\n frequency_penalty?: number;\n response_logprobs?: boolean;\n logprobs?: number;\n image_config?: InteractionsNamespace.ImageConfig & {\n type?: \"image\";\n };\n };\n export type GoogleMapsCallStepArguments =\n InteractionsNamespace.GoogleMapsCallStepArguments;\n export type GoogleMapsCallArguments =\n InteractionsNamespace.GoogleMapsCallStepArguments;\n export type GoogleMapsResultItem =\n InteractionsNamespace.GoogleMapsResultItem;\n export type GoogleMapsResult = InteractionsNamespace.GoogleMapsResultItem;\n export type GoogleMapsResultPlaces =\n InteractionsNamespace.GoogleMapsResultPlaces;\n export type GoogleSearchCallStepArguments =\n InteractionsNamespace.GoogleSearchCallStepArguments;\n export type GoogleSearchResultItem =\n InteractionsNamespace.GoogleSearchResultItem;\n export type HarmCategory = InteractionsNamespace.HarmCategory;\n export type MediaResolution = InteractionsNamespace.MediaResolution;\n export type ModalityTokens = InteractionsNamespace.ModalityTokens;\n export type Model = InteractionsNamespace.ModelOption;\n export type ModelOption = InteractionsNamespace.ModelOption;\n export type ResponseModality = InteractionsNamespace.ResponseModality;\n export type ReviewSnippet = InteractionsNamespace.ReviewSnippet;\n export type PlaceCitationReviewSnippet =\n InteractionsNamespace.ReviewSnippet;\n export type RetrievalStepArguments =\n InteractionsNamespace.RetrievalStepArguments;\n export type RetrievalCallArguments =\n InteractionsNamespace.RetrievalStepArguments;\n export type SafetySetting = InteractionsNamespace.SafetySetting;\n export type ServiceTier = InteractionsNamespace.ServiceTier;\n export type SpeakerConfig = InteractionsNamespace.SpeakerConfig;\n export type SpeechConfig = InteractionsNamespace.SpeechConfig;\n export type ThinkingLevel = InteractionsNamespace.ThinkingLevel;\n export type ToolChoiceType =\n | \"auto\"\n | \"any\"\n | \"none\"\n | \"validated\"\n | (string & {});\n export type ToolChoiceConfig = InteractionsNamespace.ToolChoiceConfig;\n export type ToolChoice = ToolChoiceType | ToolChoiceConfig;\n export type UrlContextCallStepArguments =\n InteractionsNamespace.UrlContextCallArguments;\n export type UrlContextCallArguments =\n InteractionsNamespace.UrlContextCallArguments;\n export type UrlContextResultItem = InteractionsNamespace.UrlContextResult;\n export type UrlContextResult = InteractionsNamespace.UrlContextResult;\n export type Usage = InteractionsNamespace.Usage;\n export type VertexAISearchConfig =\n InteractionsNamespace.Tools.VertexAISearchConfig;\n export type VertexAiSearchConfig =\n InteractionsNamespace.Tools.VertexAISearchConfig;\n export type WebhookConfig = InteractionsNamespace.WebhookConfig;\n\n // =========================================================================\n // SSE Stream Event & Delta types from `interactions-openapi.json`\n // Note: sparktype did not emit the SSE `text/event-stream` response union\n // schemas into `./api_types/interactions.ts`, so we define them here with\n // narrowed discriminator literals (supporting both OpenAPI `step.*` /\n // `interaction.created` / `interaction.completed` and legacy `content.*` /\n // `interaction.start` / `interaction.complete` aliases).\n // =========================================================================\n\n export type InteractionSseEventInteraction = Omit<\n Interaction,\n \"steps\" | \"outputs\"\n > & {\n steps?: Array<Step>;\n outputs?: Array<Step | Content>;\n };\n\n export interface TextDelta {\n type: \"text\";\n text: string;\n }\n\n export interface TextAnnotationDelta {\n type: \"text_annotation_delta\" | \"text_annotation\";\n annotations?: Array<Annotation>;\n }\n\n export interface ImageDelta {\n type: \"image\";\n data?: string;\n mime_type?: ImageContent[\"mime_type\"];\n resolution?: MediaResolution;\n uri?: string;\n }\n\n export interface AudioDelta {\n type: \"audio\";\n channels?: number;\n data?: string;\n mime_type?: AudioContent[\"mime_type\"];\n rate?: number;\n sample_rate?: number;\n uri?: string;\n }\n\n export interface DocumentDelta {\n type: \"document\";\n data?: string;\n mime_type?: DocumentContent[\"mime_type\"];\n uri?: string;\n }\n\n export interface VideoDelta {\n type: \"video\";\n data?: string;\n mime_type?: VideoContent[\"mime_type\"];\n resolution?: MediaResolution;\n uri?: string;\n }\n\n export interface ThoughtSummaryDelta {\n type: \"thought_summary\";\n content?: Content;\n }\n\n export interface ThoughtSignatureDelta {\n type: \"thought_signature\";\n signature?: string;\n }\n\n export interface ArgumentsDelta {\n type: \"arguments_delta\" | \"function_call\";\n id?: string;\n name?: string;\n arguments?: string | Record<string, unknown>;\n }\n\n export interface CodeExecutionCallDelta {\n type: \"code_execution_call\";\n id?: string;\n arguments?: CodeExecutionCallStepArguments;\n signature?: string;\n }\n\n export interface CodeExecutionResultDelta {\n type: \"code_execution_result\";\n call_id?: string;\n is_error?: boolean;\n result?: string;\n signature?: string;\n }\n\n export interface GoogleSearchCallDelta {\n type: \"google_search_call\";\n id?: string;\n arguments?: GoogleSearchCallStepArguments;\n signature?: string;\n }\n\n export interface GoogleSearchResultDelta {\n type: \"google_search_result\";\n call_id?: string;\n is_error?: boolean;\n result?: Array<\n GoogleSearchResultItem & {\n title?: string;\n url?: string;\n rendered_content?: string;\n }\n >;\n signature?: string;\n }\n\n export interface UrlContextCallDelta {\n type: \"url_context_call\";\n id?: string;\n arguments?: UrlContextCallArguments;\n signature?: string;\n }\n\n export interface UrlContextResultDelta {\n type: \"url_context_result\";\n call_id?: string;\n is_error?: boolean;\n result?: Array<UrlContextResult>;\n signature?: string;\n }\n\n export interface FileSearchCallDelta {\n type: \"file_search_call\";\n id?: string;\n signature?: string;\n }\n\n export interface FileSearchResultDelta {\n type: \"file_search_result\";\n call_id?: string;\n result?: Array<FileSearchResultItem>;\n signature?: string;\n }\n\n export interface GoogleMapsCallDelta {\n type: \"google_maps_call\";\n id?: string;\n arguments?: GoogleMapsCallArguments;\n signature?: string;\n }\n\n export interface GoogleMapsResultDelta {\n type: \"google_maps_result\";\n call_id?: string;\n result?: Array<GoogleMapsResult>;\n signature?: string;\n }\n\n export interface McpServerToolCallDelta {\n type: \"mcp_server_tool_call\";\n id?: string;\n name?: string;\n server_name?: string;\n arguments?: string | Record<string, unknown>;\n signature?: string;\n }\n\n export interface McpServerToolResultDelta {\n type: \"mcp_server_tool_result\";\n call_id?: string;\n name?: string;\n server_name?: string;\n result?: Array<Content> | string | Record<string, unknown>;\n signature?: string;\n }\n\n export interface ProcessingCallDelta {\n type: \"processing_call\";\n id?: string;\n signature?: string;\n }\n\n export interface ProcessingResultDelta {\n type: \"processing_result\";\n call_id?: string;\n signature?: string;\n }\n\n export interface RetrievalCallDelta {\n type: \"retrieval_call\";\n id?: string;\n arguments?: RetrievalCallArguments;\n retrieval_type?: RetrievalCallStep[\"retrieval_type\"];\n signature?: string;\n }\n\n export interface RetrievalResultDelta {\n type: \"retrieval_result\";\n call_id?: string;\n is_error?: boolean;\n signature?: string;\n }\n\n export type StepDeltaData =\n | TextDelta\n | TextAnnotationDelta\n | ImageDelta\n | AudioDelta\n | DocumentDelta\n | VideoDelta\n | ThoughtSummaryDelta\n | ThoughtSignatureDelta\n | ArgumentsDelta\n | CodeExecutionCallDelta\n | CodeExecutionResultDelta\n | GoogleSearchCallDelta\n | GoogleSearchResultDelta\n | UrlContextCallDelta\n | UrlContextResultDelta\n | FileSearchCallDelta\n | FileSearchResultDelta\n | GoogleMapsCallDelta\n | GoogleMapsResultDelta\n | McpServerToolCallDelta\n | McpServerToolResultDelta\n | ProcessingCallDelta\n | ProcessingResultDelta\n | RetrievalCallDelta\n | RetrievalResultDelta;\n\n export interface InteractionCreatedEvent {\n event_id?: string;\n event_type: \"interaction.created\" | \"interaction.start\";\n interaction: InteractionSseEventInteraction;\n }\n\n export interface InteractionCompletedEvent {\n event_id?: string;\n event_type: \"interaction.completed\" | \"interaction.complete\";\n interaction: InteractionSseEventInteraction;\n }\n\n export interface InteractionStatusUpdate {\n continuation_token?: string;\n event_id?: string;\n event_type: \"interaction.status_update\";\n interaction_id: string;\n status: Interaction[\"status\"];\n usage?: Usage;\n }\n\n export interface StepStart {\n event_id?: string;\n event_type: \"step.start\" | \"content.start\";\n index: number;\n step?: Step;\n content?: Step | Content;\n }\n\n export interface StepDelta {\n delta: StepDeltaData;\n event_id?: string;\n event_type: \"step.delta\" | \"content.delta\";\n index: number;\n metadata?: {\n total_usage?: Usage;\n };\n }\n\n export interface StepStop {\n event_id?: string;\n event_type: \"step.stop\" | \"content.stop\";\n index: number;\n step_usage?: Usage;\n usage?: Usage;\n }\n\n export interface ErrorEvent {\n error?: Error;\n event_id?: string;\n event_type: \"error\";\n }\n\n export type InteractionSseEvent =\n | InteractionCreatedEvent\n | InteractionCompletedEvent\n | InteractionStatusUpdate\n | StepStart\n | StepDelta\n | StepStop\n | ErrorEvent;\n }\n}\n\nexport type {\n GenContentNamespace as GenContent,\n InteractionsNamespace as Interactions,\n};\n\n/**\n * Simplified speaker/name pair for multi-speaker config.\n * - `speaker` derived from SpeakerVoiceConfig[\"speaker\"]\n * - `name` is the prebuilt voice name\n */\nexport interface SpeechSpeakerName {\n speaker: Gemini.GenContent.SpeakerVoiceConfig.Speaker;\n name: Gemini.GenContent.PrebuiltVoiceConfig.VoiceName;\n}\n\n/** A voice can be a prebuilt voice name, a speaker/name pair, or an array of pairs */\nexport type SpeechVoice =\n | Gemini.GenContent.PrebuiltVoiceConfig.VoiceName\n | SpeechSpeakerName\n | SpeechSpeakerName[];\n\n/** Voice with language code (derived from SpeechConfig's languageCode) */\nexport interface SpeechVoiceLanguage {\n voice: SpeechVoice;\n languageCode: Gemini.GenContent.SpeechConfig.LanguageCode;\n}\n\n/** Voices with language code */\nexport interface SpeechVoicesLanguage {\n voices: SpeechVoice;\n languageCode: Gemini.GenContent.SpeechConfig.LanguageCode;\n}\n\n/** Simplified language config (with voice or voices) */\nexport type SimplifiedSpeechLanguageConfig =\n | SpeechVoiceLanguage\n | SpeechVoicesLanguage;\n\n/** Top-level simplified config: just a voice, or voice+language */\nexport type SimplifiedSpeechConfig =\n | SpeechVoice\n | SimplifiedSpeechLanguageConfig;\n"],"mappings":";AAgVA,MAAa,sBAAyD,CACpE,QACA,UACF"}
|
package/dist/clients/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_const = require("../const.cjs");
|
|
2
|
-
const require_misc = require("../utils/misc.cjs");
|
|
3
|
-
const require_errors = require("../utils/errors.cjs");
|
|
4
2
|
const require_gcp_auth = require("../utils/gcp-auth.cjs");
|
|
3
|
+
const require_errors = require("../utils/errors.cjs");
|
|
4
|
+
const require_misc = require("../utils/misc.cjs");
|
|
5
5
|
let _langchain_core_utils_env = require("@langchain/core/utils/env");
|
|
6
|
-
|
|
6
|
+
// src/clients/index.ts
|
|
7
7
|
/**
|
|
8
8
|
* Abstract base class for API clients that interact with Google services.
|
|
9
9
|
*
|
|
@@ -210,7 +210,6 @@ var WebApiClient = class extends ApiClient {
|
|
|
210
210
|
return fetch(request);
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
|
-
//#endregion
|
|
214
213
|
exports.ApiClient = ApiClient;
|
|
215
214
|
exports.WebApiClient = WebApiClient;
|
|
216
215
|
|
package/dist/clients/index.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/clients/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Abstract base class for API clients that interact with Google services.
|
|
4
3
|
*
|
|
@@ -44,5 +43,4 @@ export declare abstract class ApiClient {
|
|
|
44
43
|
*/
|
|
45
44
|
abstract fetch(request: Request): Promise<Response>;
|
|
46
45
|
}
|
|
47
|
-
//#endregion
|
|
48
46
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/clients/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/clients/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Abstract base class for API clients that interact with Google services.
|
|
4
3
|
*
|
|
@@ -44,5 +43,4 @@ export declare abstract class ApiClient {
|
|
|
44
43
|
*/
|
|
45
44
|
abstract fetch(request: Request): Promise<Response>;
|
|
46
45
|
}
|
|
47
|
-
//#endregion
|
|
48
46
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/clients/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { GCP_API_KEY_HEADER, GOOGLE_API_KEY_HEADER } from "../const.js";
|
|
2
|
-
import { iife } from "../utils/misc.js";
|
|
3
|
-
import { AuthError } from "../utils/errors.js";
|
|
4
2
|
import { getGCPCredentialsAccessToken, normalizeGCPCredentials } from "../utils/gcp-auth.js";
|
|
3
|
+
import { AuthError } from "../utils/errors.js";
|
|
4
|
+
import { iife } from "../utils/misc.js";
|
|
5
5
|
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
6
|
-
|
|
6
|
+
// src/clients/index.ts
|
|
7
7
|
/**
|
|
8
8
|
* Abstract base class for API clients that interact with Google services.
|
|
9
9
|
*
|
|
@@ -210,7 +210,6 @@ var WebApiClient = class extends ApiClient {
|
|
|
210
210
|
return fetch(request);
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
|
-
//#endregion
|
|
214
213
|
export { ApiClient, WebApiClient };
|
|
215
214
|
|
|
216
215
|
//# sourceMappingURL=index.js.map
|
package/dist/clients/node.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const require_const = require("../const.cjs");
|
|
2
|
-
const require_misc = require("../utils/misc.cjs");
|
|
3
|
-
const require_errors = require("../utils/errors.cjs");
|
|
4
|
-
const require_gcp_auth = require("../utils/gcp-auth.cjs");
|
|
5
2
|
const require_index = require("./index.cjs");
|
|
3
|
+
const require_gcp_auth = require("../utils/gcp-auth.cjs");
|
|
4
|
+
const require_errors = require("../utils/errors.cjs");
|
|
5
|
+
const require_misc = require("../utils/misc.cjs");
|
|
6
6
|
let _langchain_core_utils_env = require("@langchain/core/utils/env");
|
|
7
7
|
let google_auth_library = require("google-auth-library");
|
|
8
|
-
|
|
8
|
+
// src/clients/node.ts
|
|
9
9
|
/**
|
|
10
10
|
* Node.js-specific API client for Google services.
|
|
11
11
|
*
|
|
@@ -331,7 +331,6 @@ function ensureAuthScopes(authOptions, requiredScopes) {
|
|
|
331
331
|
}
|
|
332
332
|
return authOptions;
|
|
333
333
|
}
|
|
334
|
-
//#endregion
|
|
335
334
|
exports.NodeApiClient = NodeApiClient;
|
|
336
335
|
exports.ensureAuthScopes = ensureAuthScopes;
|
|
337
336
|
|
package/dist/clients/node.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GCPCredentials } from "../utils/gcp-auth.cjs";
|
|
2
2
|
import { GoogleAuthOptions } from "google-auth-library";
|
|
3
|
-
//#region src/clients/node.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Configuration parameters for the NodeApiClient.
|
|
6
5
|
*
|
|
@@ -52,5 +51,4 @@ export interface NodeApiClientParams {
|
|
|
52
51
|
*/
|
|
53
52
|
googleAuthOptions?: GoogleAuthOptions;
|
|
54
53
|
}
|
|
55
|
-
//#endregion
|
|
56
54
|
//# sourceMappingURL=node.d.cts.map
|
package/dist/clients/node.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GCPCredentials } from "../utils/gcp-auth.js";
|
|
2
2
|
import { GoogleAuth, GoogleAuthOptions } from "google-auth-library";
|
|
3
|
-
//#region src/clients/node.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Configuration parameters for the NodeApiClient.
|
|
6
5
|
*
|
|
@@ -52,5 +51,4 @@ export interface NodeApiClientParams {
|
|
|
52
51
|
*/
|
|
53
52
|
googleAuthOptions?: GoogleAuthOptions;
|
|
54
53
|
}
|
|
55
|
-
//#endregion
|
|
56
54
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/clients/node.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { GCP_API_KEY_HEADER, GOOGLE_API_KEY_HEADER, VERTEX_AI_AUTH_SCOPES } from "../const.js";
|
|
2
|
-
import { iife } from "../utils/misc.js";
|
|
3
|
-
import { ConfigurationError } from "../utils/errors.js";
|
|
4
|
-
import { getGCPCredentialsAccessToken, normalizeGCPCredentials } from "../utils/gcp-auth.js";
|
|
5
2
|
import { ApiClient } from "./index.js";
|
|
3
|
+
import { getGCPCredentialsAccessToken, normalizeGCPCredentials } from "../utils/gcp-auth.js";
|
|
4
|
+
import { ConfigurationError } from "../utils/errors.js";
|
|
5
|
+
import { iife } from "../utils/misc.js";
|
|
6
6
|
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
7
7
|
import { GoogleAuth } from "google-auth-library";
|
|
8
|
-
|
|
8
|
+
// src/clients/node.ts
|
|
9
9
|
/**
|
|
10
10
|
* Node.js-specific API client for Google services.
|
|
11
11
|
*
|
|
@@ -331,7 +331,6 @@ function ensureAuthScopes(authOptions, requiredScopes) {
|
|
|
331
331
|
}
|
|
332
332
|
return authOptions;
|
|
333
333
|
}
|
|
334
|
-
//#endregion
|
|
335
334
|
export { NodeApiClient, ensureAuthScopes };
|
|
336
335
|
|
|
337
336
|
//# sourceMappingURL=node.js.map
|
package/dist/const.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/const.ts
|
|
2
2
|
const GOOGLE_API_KEY_HEADER = "x-goog-api-key";
|
|
3
3
|
const GCP_API_KEY_HEADER = "Authorization";
|
|
4
4
|
const GENERATIVE_AI_AUTH_SCOPES = ["https://www.googleapis.com/auth/generative-language"];
|
|
5
5
|
const VERTEX_AI_AUTH_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
6
|
-
//#endregion
|
|
7
6
|
exports.GCP_API_KEY_HEADER = GCP_API_KEY_HEADER;
|
|
8
7
|
exports.GENERATIVE_AI_AUTH_SCOPES = GENERATIVE_AI_AUTH_SCOPES;
|
|
9
8
|
exports.GOOGLE_API_KEY_HEADER = GOOGLE_API_KEY_HEADER;
|
package/dist/const.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// src/const.ts
|
|
2
2
|
const GOOGLE_API_KEY_HEADER = "x-goog-api-key";
|
|
3
3
|
const GCP_API_KEY_HEADER = "Authorization";
|
|
4
4
|
const GENERATIVE_AI_AUTH_SCOPES = ["https://www.googleapis.com/auth/generative-language"];
|
|
5
5
|
const VERTEX_AI_AUTH_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
6
|
-
//#endregion
|
|
7
6
|
export { GCP_API_KEY_HEADER, GENERATIVE_AI_AUTH_SCOPES, GOOGLE_API_KEY_HEADER, VERTEX_AI_AUTH_SCOPES };
|
|
8
7
|
|
|
9
8
|
//# sourceMappingURL=const.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const require_misc = require("
|
|
2
|
-
const require_errors = require("
|
|
1
|
+
const require_misc = require("../../utils/misc.cjs");
|
|
2
|
+
const require_errors = require("../../utils/errors.cjs");
|
|
3
3
|
let _langchain_core_messages = require("@langchain/core/messages");
|
|
4
4
|
let _langchain_core_utils_uuid = require("@langchain/core/utils/uuid");
|
|
5
|
-
|
|
5
|
+
// src/converters/generate_content/messages.ts
|
|
6
6
|
/**
|
|
7
7
|
* Standard content block converter for Google Gemini API.
|
|
8
8
|
* Converts deprecated Data content blocks to Gemini Part format.
|
|
@@ -454,7 +454,7 @@ const convertMessagesToGeminiContents = (messages) => {
|
|
|
454
454
|
const contents = [];
|
|
455
455
|
for (const message of messages) {
|
|
456
456
|
const content = require_misc.iife(() => {
|
|
457
|
-
switch ("output_version" in message.response_metadata ? message.response_metadata?.output_version : "v0") {
|
|
457
|
+
switch (message.response_metadata && "output_version" in message.response_metadata ? message.response_metadata?.output_version : "v0") {
|
|
458
458
|
case "v1": return convertStandardContentMessageToGeminiContent(message, messages);
|
|
459
459
|
default: return convertLegacyContentMessageToGeminiContent(message, messages);
|
|
460
460
|
}
|
|
@@ -773,7 +773,6 @@ const convertGeminiGenerateContentResponseToUsageMetadata = (data) => {
|
|
|
773
773
|
output_token_details
|
|
774
774
|
};
|
|
775
775
|
};
|
|
776
|
-
//#endregion
|
|
777
776
|
exports.convertAIMessageToText = convertAIMessageToText;
|
|
778
777
|
exports.convertGeminiCandidateToAIMessage = convertGeminiCandidateToAIMessage;
|
|
779
778
|
exports.convertGeminiGenerateContentResponseToUsageMetadata = convertGeminiGenerateContentResponseToUsageMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.cjs","names":["isDataContentBlock","InvalidInputError","parseBase64DataUrl","SystemMessage","HumanMessage","AIMessage","ToolMessage","ChatMessage","convertToProviderContentBlock","iife","ToolCallNotFoundError","uuidv4"],"sources":["../../../src/converters/generate_content/messages.ts"],"sourcesContent":["import {\n BaseMessage,\n AIMessage,\n isDataContentBlock,\n ContentBlock,\n parseBase64DataUrl,\n SystemMessage,\n HumanMessage,\n ToolMessage,\n ChatMessage,\n StandardContentBlockConverter,\n convertToProviderContentBlock,\n type Data,\n UsageMetadata,\n InputTokenDetails,\n OutputTokenDetails,\n ModalitiesTokenDetails,\n MessageContentImageUrl,\n MessageContentComplex,\n MessageContentText,\n} from \"@langchain/core/messages\";\nimport { v4 as uuidv4 } from \"@langchain/core/utils/uuid\";\nimport { Converter } from \"@langchain/core/utils/format\";\nimport type { Gemini } from \"../../chat_models/types.js\";\nimport { iife } from \"../../utils/misc.js\";\nimport {\n InvalidInputError,\n ToolCallNotFoundError,\n} from \"../../utils/errors.js\";\n\n/**\n * Standard content block converter for Google Gemini API.\n * Converts deprecated Data content blocks to Gemini Part format.\n *\n * @deprecated This converter is for backward compatibility with older message formats.\n * Use ContentBlock.Multimodal.Standard instead.\n */\nexport const geminiContentBlockConverter: StandardContentBlockConverter<{\n text: Gemini.Part;\n image: Gemini.Part;\n audio: Gemini.Part;\n file: Gemini.Part;\n}> = {\n providerName: \"ChatGoogle\",\n\n fromStandardTextBlock(block: Data.StandardTextBlock): Gemini.Part {\n return { text: block.text };\n },\n\n fromStandardImageBlock(block: Data.StandardImageBlock): Gemini.Part {\n if (isDataContentBlock(block)) {\n if (block.source_type === \"base64\") {\n if (!block.mime_type) {\n throw new InvalidInputError(\n \"mime_type is required for base64 image blocks\"\n );\n }\n const dataStr =\n typeof block.data === \"string\"\n ? block.data\n : typeof block.data === \"object\" && block.data !== null\n ? // Convert Uint8Array to base64 string\n btoa(\n Array.from(block.data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n )\n : String(block.data);\n return {\n inlineData: {\n mimeType: block.mime_type,\n data: dataStr,\n },\n };\n }\n\n if (block.source_type === \"url\") {\n // Check if it's a data URL\n const parsed = parseBase64DataUrl({ dataUrl: block.url });\n if (parsed) {\n const dataStr =\n typeof parsed.data === \"string\"\n ? parsed.data\n : // Convert Uint8Array to base64 string\n btoa(\n Array.from(parsed.data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n );\n return {\n inlineData: {\n mimeType: parsed.mime_type || block.mime_type || \"image/jpeg\",\n data: dataStr,\n },\n };\n }\n // Otherwise, treat as file URI\n return {\n fileData: {\n mimeType: block.mime_type || \"image/jpeg\",\n fileUri: block.url,\n },\n };\n }\n\n if (block.source_type === \"id\") {\n return {\n fileData: {\n mimeType: block.mime_type || \"image/jpeg\",\n fileUri: block.id,\n },\n };\n }\n }\n\n throw new InvalidInputError(\n `Image content blocks with source_type \"${\n (block as Data.DataContentBlock).source_type\n }\" are not supported for ChatGoogle. Supported source types are: \"base64\", \"url\", \"id\".`\n );\n },\n\n fromStandardAudioBlock(block: Data.StandardAudioBlock): Gemini.Part {\n if (isDataContentBlock(block)) {\n if (block.source_type === \"base64\") {\n if (!block.mime_type) {\n throw new InvalidInputError(\n \"mime_type is required for base64 audio blocks\"\n );\n }\n const dataStr =\n typeof block.data === \"string\"\n ? block.data\n : typeof block.data === \"object\" && block.data !== null\n ? // Convert Uint8Array to base64 string\n btoa(\n Array.from(block.data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n )\n : String(block.data);\n return {\n inlineData: {\n mimeType: block.mime_type,\n data: dataStr,\n },\n };\n }\n\n if (block.source_type === \"url\") {\n // Check if it's a data URL\n const parsed = parseBase64DataUrl({ dataUrl: block.url });\n if (parsed) {\n const dataStr =\n typeof parsed.data === \"string\"\n ? parsed.data\n : // Convert Uint8Array to base64 string\n btoa(\n Array.from(parsed.data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n );\n return {\n inlineData: {\n mimeType: parsed.mime_type || block.mime_type || \"audio/mpeg\",\n data: dataStr,\n },\n };\n }\n // Otherwise, treat as file URI\n return {\n fileData: {\n mimeType: block.mime_type || \"audio/mpeg\",\n fileUri: block.url,\n },\n };\n }\n\n if (block.source_type === \"id\") {\n return {\n fileData: {\n mimeType: block.mime_type || \"audio/mpeg\",\n fileUri: block.id,\n },\n };\n }\n }\n\n throw new InvalidInputError(\n `Audio content blocks with source_type \"${\n (block as Data.DataContentBlock).source_type\n }\" are not supported for ChatGoogle. Supported source types are: \"base64\", \"url\", \"id\".`\n );\n },\n\n fromStandardFileBlock(block: Data.StandardFileBlock): Gemini.Part {\n if (isDataContentBlock(block)) {\n if (block.source_type === \"base64\") {\n if (!block.mime_type) {\n throw new InvalidInputError(\n \"mime_type is required for base64 file blocks\"\n );\n }\n const dataStr =\n typeof block.data === \"string\"\n ? block.data\n : typeof block.data === \"object\" && block.data !== null\n ? // Convert Uint8Array to base64 string\n btoa(\n Array.from(block.data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n )\n : String(block.data);\n return {\n inlineData: {\n mimeType: block.mime_type,\n data: dataStr,\n },\n };\n }\n\n if (block.source_type === \"url\") {\n // Check if it's a data URL\n const parsed = parseBase64DataUrl({ dataUrl: block.url });\n if (parsed) {\n const dataStr =\n typeof parsed.data === \"string\"\n ? parsed.data\n : // Convert Uint8Array to base64 string\n btoa(\n Array.from(parsed.data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n );\n return {\n inlineData: {\n mimeType:\n parsed.mime_type ||\n block.mime_type ||\n \"application/octet-stream\",\n data: dataStr,\n },\n };\n }\n // Otherwise, treat as file URI\n return {\n fileData: {\n mimeType: block.mime_type || \"application/octet-stream\",\n fileUri: block.url,\n },\n };\n }\n\n if (block.source_type === \"id\") {\n return {\n fileData: {\n mimeType: block.mime_type || \"application/octet-stream\",\n fileUri: block.id,\n },\n };\n }\n }\n\n // Handle text source type (for plain text file blocks)\n if (\n \"source_type\" in block &&\n block.source_type === \"text\" &&\n \"text\" in block\n ) {\n return {\n text: block.text,\n };\n }\n\n throw new InvalidInputError(\n `File content blocks with source_type \"${\n (block as Data.DataContentBlock).source_type\n }\" are not supported for ChatGoogle. Supported source types are: \"base64\", \"url\", \"id\", \"text\".`\n );\n },\n};\n\nconst MEDIA_BLOCK_TYPES = new Set([\n \"media\",\n \"image\",\n \"audio\",\n \"video\",\n \"file\",\n \"text-plain\",\n]);\n\nfunction isMediaContentBlock(item: unknown): boolean {\n if (typeof item !== \"object\" || item === null) {\n return false;\n }\n if (isDataContentBlock(item)) {\n return item.source_type !== \"text\";\n }\n if (\"image_url\" in item || \"inlineData\" in item || \"fileData\" in item) {\n return true;\n }\n return MEDIA_BLOCK_TYPES.has((item as { type?: unknown }).type as string);\n}\n\nfunction stripMediaBlocksForFunctionResponse(content: unknown): unknown {\n if (!Array.isArray(content)) {\n return content;\n }\n return content.filter((item) => !isMediaContentBlock(item));\n}\n\nfunction convertStandardDataContentBlockToGeminiPart(\n block: ContentBlock.Multimodal.Data\n): Gemini.Part | null {\n function uint8arrayToString(data: Uint8Array): string {\n return btoa(\n Array.from(data as Uint8Array)\n .map((byte) => String.fromCharCode(byte))\n .join(\"\")\n );\n }\n\n function extractMimeType(str: string): {\n mimeType: string | null;\n data: string | null;\n } {\n if (str.startsWith(\"data:\")) {\n return {\n mimeType: str.split(\":\")[1].split(\";\")[0],\n data: str.split(\",\")[1],\n };\n }\n return {\n mimeType: null,\n data: null,\n };\n }\n\n if (\"mimeType\" in block && \"data\" in block) {\n const mimeType = block.mimeType!;\n const data: string =\n typeof block.data === \"string\"\n ? block.data\n : uint8arrayToString(block.data!);\n return {\n inlineData: {\n mimeType,\n data,\n },\n };\n } else if (\"mimeType\" in block && \"url\" in block) {\n const mimeType = block.mimeType!;\n const fileUri = block.url!;\n return {\n fileData: {\n mimeType,\n fileUri,\n },\n };\n } else if (\"url\" in block && block.url?.startsWith(\"data:\")) {\n const { mimeType, data } = extractMimeType(block.url!);\n if (mimeType && data) {\n return {\n inlineData: {\n mimeType,\n data,\n },\n };\n }\n }\n // FIXME - report this somehow?\n return null;\n}\n\nfunction convertStandardVideoContentBlockToGeminiPart(\n block: ContentBlock.Multimodal.Video\n): Gemini.Part | null {\n const ret: Gemini.Part | null =\n convertStandardDataContentBlockToGeminiPart(block);\n if (ret && block.metadata && \"videoMetadata\" in block.metadata) {\n (ret as Gemini.Part.FileData).videoMetadata = block.metadata.videoMetadata!;\n }\n return ret;\n}\n\nfunction convertStandardReasoningBlockToGeminiPart(\n block: ContentBlock.Reasoning\n): Gemini.Part | null {\n // Reasoning blocks created from Gemini should contain the base\n // standard block they would be if \"thought\" wasn't set to true.\n // If it exists, we'll use that. Otherwise, we'll assume it was\n // originally a text block.\n const ret =\n \"reasoningContentBlock\" in block && block.reasoningContentBlock\n ? convertStandardContentBlockToGeminiPart(\n block.reasoningContentBlock as ContentBlock.Standard\n )\n : { text: block.reasoning };\n\n // Then add that this came from the thinking process\n if (ret) {\n ret.thought = true;\n }\n\n return ret;\n}\n\n/**\n * Converts a single LangChain standard content block (v1 format)\n * into a Gemini.Part.\n *\n * This is intended to be called from `convertStandardContentMessageToGeminiContent`\n */\nfunction convertStandardContentBlockToGeminiPart(\n block: ContentBlock.Standard\n): Gemini.Part | null {\n function baseGeminiPart(): Gemini.Part | null {\n switch (block.type) {\n case \"text\":\n return { text: block.text };\n case \"reasoning\":\n return convertStandardReasoningBlockToGeminiPart(block);\n case \"image\":\n case \"audio\":\n case \"text-plain\":\n case \"file\":\n return convertStandardDataContentBlockToGeminiPart(block);\n case \"video\":\n return convertStandardVideoContentBlockToGeminiPart(block);\n default:\n return null;\n }\n }\n\n const ret: Gemini.Part | null = baseGeminiPart();\n if (ret) {\n if (\"thoughtSignature\" in block) {\n ret.thoughtSignature = block.thoughtSignature! as string;\n }\n }\n return ret;\n}\n\n/**\n * Converts a single LangChain message with standard content blocks (v1 format) to Gemini Content.\n * This handles messages that have `response_metadata.output_version === \"v1\"`.\n *\n * This is intended to be called from `convertMessagesToGeminiContent`\n */\nfunction convertStandardContentMessageToGeminiContent(\n message: BaseMessage,\n messages: BaseMessage[]\n): Gemini.Content | null {\n // Skip system messages - they're handled separately\n if (SystemMessage.isInstance(message)) {\n return null;\n }\n\n let role: Gemini.Role;\n if (HumanMessage.isInstance(message)) {\n role = \"user\";\n } else if (AIMessage.isInstance(message)) {\n role = \"model\";\n } else if (ToolMessage.isInstance(message)) {\n // Tool messages in Gemini were represented as function responses, but now are \"user\"\n role = \"user\";\n } else if (ChatMessage.isInstance(message)) {\n // Map ChatMessage roles to Gemini roles\n const msgRole = message.role.toLowerCase();\n if (msgRole === \"user\" || msgRole === \"human\") {\n role = \"user\";\n } else if (\n msgRole === \"assistant\" ||\n msgRole === \"ai\" ||\n msgRole === \"model\"\n ) {\n role = \"model\";\n } else if (msgRole === \"function\" || msgRole === \"tool\") {\n role = \"user\";\n } else {\n // Default to user for unknown roles\n role = \"user\";\n }\n } else {\n // Unknown message type - default to user\n role = \"user\";\n }\n\n let parts: Gemini.Part[] = [];\n\n // Process standard content blocks\n const contentBlocks = Array.isArray(message.contentBlocks)\n ? message.contentBlocks\n : [];\n contentBlocks.forEach((block: ContentBlock.Standard) => {\n const contentBlock =\n (message.additional_kwargs\n .originalTextContentBlock as ContentBlock.Standard) || block;\n const part: Gemini.Part | null =\n convertStandardContentBlockToGeminiPart(contentBlock);\n if (part) {\n parts.push(part);\n }\n });\n\n // Convert tool_calls to functionCall parts, reading thoughtSignature from the matching content block, falling back to the tool_call itself.\n if (AIMessage.isInstance(message) && message.tool_calls?.length) {\n const signaturesById: Record<string, string> = {};\n for (const block of contentBlocks) {\n if (\n block.type === \"tool_call\" &&\n block.id &&\n \"thoughtSignature\" in block &&\n typeof block.thoughtSignature === \"string\"\n ) {\n signaturesById[block.id] = block.thoughtSignature;\n }\n }\n for (const toolCall of message.tool_calls) {\n const part = {\n functionCall: {\n name: toolCall.name,\n args: toolCall.args ?? {},\n },\n } as Gemini.Part.FunctionCall;\n const thoughtSignature =\n (toolCall.id && signaturesById[toolCall.id]) ??\n (\"thoughtSignature\" in toolCall\n ? (toolCall.thoughtSignature as string)\n : undefined);\n if (thoughtSignature) {\n part.thoughtSignature = thoughtSignature;\n }\n parts.push(part);\n }\n }\n\n // Handle tool messages as function responses\n if (ToolMessage.isInstance(message) && message.tool_call_id) {\n const responseContent = stripMediaBlocksForFunctionResponse(\n message.content\n );\n // Find the matching tool call in a preceding AIMessage to get the function name\n const aiMsg = messages\n .filter(AIMessage.isInstance)\n .find((msg) =>\n msg.tool_calls?.find((tc) => tc.id === message.tool_call_id)\n );\n const matchedToolCall = aiMsg?.tool_calls?.find(\n (tc) => tc.id === message.tool_call_id\n );\n const isGeneratedId = message.tool_call_id.startsWith(\"lc-tool-call-\");\n parts.push({\n functionResponse: {\n ...(isGeneratedId ? {} : { id: message.tool_call_id }),\n name: matchedToolCall?.name ?? message.name ?? \"unknown\",\n response: { result: responseContent },\n },\n });\n\n // For tool messages, keep only the functionResponse part(s): any text is\n // already included in functionResponse.response.result, and a `user`\n // content mixing a functionResponse with text is rejected or corrupted\n // by the API. Mirrors the legacy-path filter.\n parts = parts.filter((part) => \"functionResponse\" in part);\n }\n\n // Only return content if we have parts\n if (parts.length === 0) {\n return null;\n }\n\n return { role, parts };\n}\n\nfunction convertLegacyPartToGeminiPart(\n item: string | ContentBlock | Text\n): Gemini.Part {\n /**\n * @deprecated - This is for use by `convertLegacyContentMessageToGeminiContent` only\n */\n function isMessageContentText(\n content: object\n ): content is MessageContentText {\n return typeof content === \"object\" && content !== null && \"text\" in content;\n }\n\n /**\n * @deprecated - This is for use by `convertLegacyContentMessageToGeminiContent` only\n */\n function isMessageContentImageUrl(\n content: object\n ): content is MessageContentImageUrl {\n return (\n typeof content === \"object\" && content !== null && \"image_url\" in content\n );\n }\n\n /**\n * @deprecated - This is for use by `convertLegacyContentMessageToGeminiContent` only\n */\n function isMessageContentMedia(\n content: object\n ): content is MessageContentComplex {\n return (\n typeof content === \"object\" &&\n content !== null &&\n \"type\" in content &&\n content.type === \"media\"\n );\n }\n\n /**\n * Infers the MIME type from a URL based on its file extension.\n * This is used as a fallback when the MIME type is not provided.\n *\n * @param url - The URL to infer the MIME type from\n * @returns The inferred MIME type or a generic type if it cannot be determined\n */\n function inferMimeTypeFromUrl(url: string): string {\n const mimeTypeMap: Record<string, string> = {\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n png: \"image/png\",\n gif: \"image/gif\",\n webp: \"image/webp\",\n bmp: \"image/bmp\",\n svg: \"image/svg+xml\",\n ico: \"image/x-icon\",\n tiff: \"image/tiff\",\n tif: \"image/tiff\",\n };\n\n try {\n // Extract the pathname from the URL\n const pathname = new URL(url).pathname;\n // Get the file extension (handle query params and fragments)\n const extension = pathname\n .split(\".\")\n .pop()\n ?.toLowerCase()\n .split(/[?#]/)[0];\n return extension ? mimeTypeMap[extension] : \"application/octet-stream\";\n } catch {\n // If URL parsing fails, try a simple extension extraction\n const match = url.match(/\\.([a-zA-Z0-9]+)(?:[?#]|$)/);\n if (match) {\n const extension = match[1].toLowerCase();\n return mimeTypeMap[extension];\n }\n return \"application/octet-stream\";\n }\n }\n\n function messageContentImageUrlData(\n content: MessageContentImageUrl\n ): Gemini.Part.InlineData | Gemini.Part.FileData {\n const url: string =\n typeof content.image_url === \"string\"\n ? content.image_url\n : content.image_url.url;\n if (!url) {\n throw new InvalidInputError(\n \"Missing image URL in image_url content block.\"\n );\n }\n\n const dataUrl = parseBase64DataUrl({ dataUrl: url });\n if (dataUrl?.data && dataUrl?.mime_type) {\n return {\n inlineData: {\n data: dataUrl.data,\n mimeType: dataUrl.mime_type,\n },\n };\n } else {\n // Infer MIME type from URL extension\n const mimeType = inferMimeTypeFromUrl(url) || \"image/png\";\n return {\n fileData: {\n mimeType,\n fileUri: url,\n },\n };\n }\n }\n\n function messageContentImageUrl(\n content: MessageContentImageUrl\n ): Gemini.Part.InlineData | Gemini.Part.FileData {\n const ret = messageContentImageUrlData(content);\n supplementVideoMetadata(content, ret);\n return ret;\n }\n\n function messageContentMediaData(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n content: Record<string, any>\n ): Gemini.Part.InlineData | Gemini.Part.FileData {\n if (\"mimeType\" in content && \"data\" in content) {\n return {\n inlineData: {\n mimeType: content.mimeType,\n data: content.data,\n },\n };\n } else if (\"mimeType\" in content && \"fileUri\" in content) {\n return {\n fileData: {\n mimeType: content.mimeType,\n fileUri: content.fileUri,\n },\n };\n } else {\n // The old version would attempt to read the URL, but we're\n // not in an async function, so we can't do that.\n }\n\n throw new InvalidInputError(\n `Invalid media content: ${JSON.stringify(\n content,\n null,\n 1\n )}. Expected either { mimeType, data } for inline data or { mimeType, fileUri } for file references.`\n );\n }\n\n function supplementVideoMetadata(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n content: MessageContentImageUrl | Record<string, any>,\n ret: Gemini.Part.InlineData | Gemini.Part.FileData\n ): Gemini.Part.InlineData | Gemini.Part.FileData {\n // Add videoMetadata if defined\n if (\"videoMetadata\" in content && typeof ret === \"object\") {\n ret.videoMetadata = content.videoMetadata;\n }\n return ret;\n }\n\n function messageContentMedia(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n content: Record<string, any>\n ): Gemini.Part.InlineData | Gemini.Part.FileData {\n const ret = messageContentMediaData(content);\n supplementVideoMetadata(content, ret);\n return ret;\n }\n\n function baseGeminiPart(): Gemini.Part {\n if (typeof item === \"string\") {\n return { text: item };\n } else if (typeof item === \"object\" && item !== null) {\n if (isMessageContentText(item)) {\n return { text: item.text };\n } else if (isDataContentBlock(item)) {\n return convertToProviderContentBlock(item, geminiContentBlockConverter);\n } else if (\"type\" in item && item?.type === \"functionCall\") {\n const { type, functionCall, ...etc } = item;\n return {\n ...etc,\n functionCall,\n } as Gemini.Part.FunctionCall;\n } else if (\"type\" in item && item?.type === \"executableCode\") {\n const { type, executableCode, ...etc } = item;\n return {\n ...etc,\n executableCode,\n } as Gemini.Part.ExecutableCode;\n } else if (\"type\" in item && item?.type === \"codeExecutionResult\") {\n const { type, codeExecutionResult, ...etc } = item;\n return {\n ...etc,\n codeExecutionResult,\n } as Gemini.Part.CodeExecutionResult;\n } else if (isMessageContentImageUrl(item)) {\n return messageContentImageUrl(item);\n } else if (isMessageContentMedia(item)) {\n return messageContentMedia(item);\n }\n }\n return item as Gemini.Part;\n }\n\n const ret = baseGeminiPart();\n const itemRecord = item as Record<string, unknown>;\n if (\"thought\" in itemRecord) {\n ret.thought = itemRecord.thought as boolean;\n }\n if (\"thoughtSignature\" in itemRecord) {\n ret.thoughtSignature = itemRecord.thoughtSignature as string;\n }\n return ret;\n}\n\n/**\n * Converts a single LangChain message with legacy content blocks (v0 format) to Gemini Content.\n * This handles messages that have `response_metadata.output_version === \"v0\"`.\n *\n * This is intended to be called from `convertMessagesToGeminiContent`\n */\nfunction convertLegacyContentMessageToGeminiContent(\n message: BaseMessage,\n messages: BaseMessage[]\n): Gemini.Content | null {\n // Skip system messages - they're handled separately\n if (SystemMessage.isInstance(message)) {\n return null;\n }\n\n const role: Gemini.Role = iife(() => {\n if (HumanMessage.isInstance(message)) {\n return \"user\";\n } else if (AIMessage.isInstance(message)) {\n return \"model\";\n } else if (ToolMessage.isInstance(message)) {\n // Tool messages in Gemini were represented as function responses, but now are \"user\"\n return \"user\";\n } else if (ChatMessage.isInstance(message)) {\n // Map ChatMessage roles to Gemini roles\n const msgRole = message.role.toLowerCase();\n if (msgRole === \"user\" || msgRole === \"human\") {\n return \"user\";\n } else if (\n msgRole === \"assistant\" ||\n msgRole === \"ai\" ||\n msgRole === \"model\"\n ) {\n return \"model\";\n } else if (msgRole === \"function\" || msgRole === \"tool\") {\n return \"user\";\n } else {\n // Default to user for unknown roles\n return \"user\";\n }\n } else {\n // Unknown message type - skip or default to user\n return \"user\";\n }\n });\n\n let parts: Gemini.Part[] = [];\n\n // Handle legacy content formats\n if (typeof message.content === \"string\") {\n // Simple string content\n if (message.content.trim()) {\n parts.push({ text: message.content });\n }\n } else if (Array.isArray(message.content)) {\n // Array of content blocks (legacy format)\n for (const item of message.content) {\n const part = convertLegacyPartToGeminiPart(item);\n parts.push(part);\n }\n }\n\n // Handle tool messages as function responses\n if (ToolMessage.isInstance(message) && message.tool_call_id) {\n const responseContent = stripMediaBlocksForFunctionResponse(\n message.content\n );\n // Find the matching tool call in a preceding AIMessage to get the function name\n const aiMsg = messages\n .filter(AIMessage.isInstance)\n .find((msg) =>\n msg.tool_calls?.find((tc) => tc.id === message.tool_call_id)\n );\n if (!aiMsg) {\n throw new ToolCallNotFoundError(message.tool_call_id);\n }\n const isGeneratedId = message.tool_call_id.startsWith(\"lc-tool-call-\");\n const matchedToolCall = aiMsg.tool_calls?.find(\n (tc) => tc.id === message.tool_call_id\n );\n parts.push({\n functionResponse: {\n ...(isGeneratedId ? {} : { id: message.tool_call_id }),\n name: matchedToolCall?.name ?? message.name ?? \"unknown\",\n response: { result: responseContent },\n },\n });\n\n // For tool messages, drop the redundant text parts - their content is\n // already folded into functionResponse.response.result above - but keep\n // any media parts (inlineData/fileData) as siblings so images/audio/video\n // reach Gemini as real parts instead of being lost inside the JSON string.\n parts = parts.filter(\n (part) =>\n \"functionResponse\" in part || \"inlineData\" in part || \"fileData\" in part\n );\n }\n\n // Only add content if we have parts\n if (parts.length > 0) {\n return { role, parts };\n }\n\n return null;\n}\n\n/**\n * Converts an array of LangChain messages to Gemini API content format.\n *\n * This converter transforms LangChain's message types into the content structure\n * expected by Google's Gemini API.\n *\n * @remarks\n * The converter processes messages in two distinct ways based on their format:\n *\n * **V1 Standard Content Format**:\n * Messages with `output_version: \"v1\"` in their response metadata use the\n * standardized content block format. These are processed through\n * `convertStandardContentMessageToGeminiContent`, which extracts text blocks\n * from the `contentBlocks` array and maps message roles appropriately.\n *\n * **Google Format**:\n * Messages without the v1 marker are processed using generic logic that handles:\n * - String content: Simple text strings are converted to text parts\n * - Array content: Arrays of strings or content blocks are processed individually\n * - Tool messages: Converted to function response parts with tool call metadata\n *\n * @example\n * ```typescript\n * // Simple conversation with text messages\n * const messages = [\n * new HumanMessage(\"What is the weather?\"),\n * new AIMessage(\"I'll check that for you.\")\n * ];\n * const contents = convertMessagesToGeminiContents(messages);\n * // Returns: [\n * // { role: \"user\", parts: [{ text: \"What is the weather?\" }] },\n * // { role: \"model\", parts: [{ text: \"I'll check that for you.\" }] }\n * // ]\n * ```\n */\nexport const convertMessagesToGeminiContents: Converter<\n BaseMessage[],\n Gemini.GenerateContentRequest[\"contents\"]\n> = (messages) => {\n const contents: Gemini.Content[] = [];\n\n for (const message of messages) {\n // const content: Gemini.Content | null = convertContentMessageToGeminiContent(message, messages);\n const content: Gemini.Content | null = iife(() => {\n const outputVersion =\n message.response_metadata &&\n \"output_version\" in message.response_metadata\n ? (message.response_metadata?.output_version as string)\n : \"v0\";\n switch (outputVersion) {\n case \"v1\":\n return convertStandardContentMessageToGeminiContent(\n message,\n messages\n );\n case \"v0\":\n default:\n return convertLegacyContentMessageToGeminiContent(message, messages);\n }\n });\n if (content) {\n const prev = contents[contents.length - 1];\n if (canMergeInto(prev, content) && content.parts) {\n prev.parts ??= [];\n prev.parts.push(...content.parts);\n } else {\n contents.push(content);\n }\n }\n }\n\n return contents;\n};\n\n/**\n * Returns true if any part of the given content is a functionResponse part\n * (i.e. it was produced from a ToolMessage).\n */\nfunction hasFunctionResponse(content: Gemini.Content): boolean {\n return content.parts?.some((part) => \"functionResponse\" in part) === true;\n}\n\n/**\n * Adjacent same-role contents merge only when they are the same kind of\n * turn:\n *\n * - Both carry functionResponse parts (a run of tool responses answering\n * one model turn's parallel calls): the API requires those to share a\n * single `user` content whose part count matches the call count.\n * - Neither does (plain text turns): coalesced as before #11444.\n *\n * A functionResponse turn never merges with a plain one: a `user` content\n * mixing the two is rejected by newer Gemini models and corrupts\n * generation on older ones.\n */\nfunction canMergeInto(\n prev: Gemini.Content | undefined,\n content: Gemini.Content\n): boolean {\n return (\n prev !== undefined &&\n prev.role === content.role &&\n hasFunctionResponse(prev) === hasFunctionResponse(content)\n );\n}\n\n/**\n * Converts LangChain system messages to Gemini API system instruction format.\n *\n * This converter extracts system messages from a message array and transforms them\n * into the format expected by Google's Gemini API for system instructions. System\n * instructions provide context and guidelines that influence the model's behavior\n * throughout the conversation.\n *\n * @remarks\n * The converter handles two distinct message formats:\n *\n * 1. **V1 Standard Content Format**: Messages with `output_version: \"v1\"` in their\n * response metadata use the standardized content block format. Only text blocks\n * are extracted from the `contentBlocks` array.\n *\n * 2. **Legacy Google Format**: Messages without the v1 marker use the legacy format\n * where content can be:\n * - A simple string (trimmed and converted to a text part)\n * - An array of strings or objects with `type: \"text\"` and a `text` property\n *\n * The converter filters out non-SystemMessage instances and only processes text\n * content, ignoring other content types like images or tool calls that may be\n * present in the message array.\n *\n * @example\n * ```typescript\n * // Simple string system message\n * const messages = [\n * new SystemMessage(\"You are a helpful assistant.\")\n * ];\n * const instruction = convertMessagesToGeminiSystemInstruction(messages);\n * // Returns: { parts: [{ text: \"You are a helpful assistant.\" }] }\n * ```\n *\n * @param messages - Array of LangChain messages to extract system instructions from\n * @returns A Gemini system instruction object with text parts, or undefined if no\n * system messages with text content are found\n */\nexport const convertMessagesToGeminiSystemInstruction: Converter<\n BaseMessage[],\n Gemini.GenerateContentRequest[\"systemInstruction\"]\n> = (messages) => {\n const systemParts: Gemini.Part[] = [];\n\n for (const message of messages) {\n if (SystemMessage.isInstance(message)) {\n if (message.text.trim()) {\n systemParts.push({ text: message.text });\n }\n }\n }\n\n if (systemParts.length === 0) {\n return undefined;\n }\n\n return { parts: systemParts };\n};\n\n/**\n * Converts an array of Gemini API parts into an array of LangChain tool calls.\n *\n * This function iterates through a given array of `Gemini.Part` objects,\n * identifies parts that represent a function call, and transforms them into\n * LangChain's standardized `ToolCall` format. Each resulting tool call is\n * assigned a unique, sequential ID.\n *\n * @param parts - An array of `Gemini.Part` objects, which may or may not\n * contain function calls.\n * @returns An array of `ContentBlock.Tools.ToolCall` objects. If no function\n * call parts are found, an empty array is returned.\n *\n * @remarks\n * The `id` for each tool call is generated sequentially in the format `call_0`,\n * `call_1`, and so on, based on its order of appearance in the input array.\n *\n * @example\n * ```typescript\n * const geminiParts: Gemini.Part[] = [\n * { text: \"Thinking about what to do...\" },\n * {\n * functionCall: {\n * name: \"search_web\",\n * args: { query: \"latest AI news\" }\n * }\n * },\n * {\n * functionCall: {\n * name: \"calculator\",\n * args: { expression: \"2 + 2\" }\n * }\n * }\n * ];\n *\n * const toolCalls = convertGeminiPartsToToolCalls(geminiParts);\n * // toolCalls will be:\n * // [\n * // { type: \"tool_call\", id: \"call_0\", name: \"search_web\", args: { query: \"latest AI news\" } },\n * // { type: \"tool_call\", id: \"call_1\", name: \"calculator\", args: { expression: \"2 + 2\" } }\n * // ]\n * ```\n */\nexport const convertGeminiPartsToToolCalls: Converter<\n Gemini.Part[],\n ContentBlock.Tools.ToolCall<string, Record<string, unknown>>[]\n> = (\n parts: Gemini.Part[]\n): ContentBlock.Tools.ToolCall<string, Record<string, unknown>>[] => {\n const toolCalls: ContentBlock.Tools.ToolCall<\n string,\n Record<string, unknown>\n >[] = [];\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n if (\"functionCall\" in part && part.functionCall) {\n const functionCallPart = part as Gemini.Part.FunctionCall;\n toolCalls.push({\n type: \"tool_call\",\n id:\n functionCallPart.functionCall.id ??\n `lc-tool-call-${uuidv4().replace(/-/g, \"\")}`,\n name: functionCallPart.functionCall.name,\n args: functionCallPart.functionCall.args ?? {},\n thoughtSignature: functionCallPart.thoughtSignature,\n });\n }\n }\n\n return toolCalls;\n};\n\nexport const convertGeminiPartToContentBlock: Converter<\n Gemini.Part,\n ContentBlock\n> = (part: Gemini.Part): ContentBlock => {\n const block: ContentBlock = iife(() => {\n if (\"text\" in part && typeof part.text === \"string\") {\n return {\n type: \"text\",\n text: part.text,\n };\n } else if (\"inlineData\" in part && part.inlineData) {\n return {\n type: \"inlineData\",\n inlineData: part.inlineData,\n };\n } else if (\"fileData\" in part && part.fileData) {\n return {\n type: \"fileData\",\n fileData: part.fileData,\n };\n } else if (\"functionCall\" in part && part.functionCall) {\n return {\n type: \"functionCall\",\n functionCall: part.functionCall,\n };\n } else if (\"functionResponse\" in part && part.functionResponse) {\n return {\n type: \"functionResponse\",\n functionResponse: part.functionResponse,\n };\n } else if (\"executableCode\" in part && part.executableCode) {\n return {\n type: \"executableCode\",\n executableCode: part.executableCode,\n };\n } else if (\"codeExecutionResult\" in part && part.codeExecutionResult) {\n return {\n type: \"codeExecutionResult\",\n codeExecutionResult: part.codeExecutionResult,\n };\n }\n return part as unknown as ContentBlock;\n });\n const ret: ContentBlock = {\n thought: part.thought,\n thoughtSignature: part.thoughtSignature,\n partMetadata: part.partMetadata,\n ...block,\n };\n for (const attribute in ret) {\n if (ret[attribute] === undefined) {\n delete ret[attribute];\n }\n }\n\n return ret;\n};\n\n/**\n * Converts a Gemini API candidate response to a LangChain AIMessage.\n *\n * This converter transforms the response from Google's Gemini API into a standardized\n * AIMessage format that can be used throughout the LangChain ecosystem. It handles\n * various types of content including text, inline data, file data, function calls,\n * and code execution results.\n *\n * @remarks\n * The converter performs the following transformations:\n * - Extracts tool calls from function call parts and assigns sequential IDs\n * - Converts single text responses to string format for simplicity\n * - Converts multi-part responses to ContentBlock array format\n * - Preserves metadata including finish reason, safety ratings, and citations\n * - Handles various Gemini part types (text, inlineData, fileData, functionCall, etc.)\n *\n * @example\n * ```typescript\n * const candidate: Gemini.Candidate = {\n * content: {\n * parts: [\n * { text: \"Hello, how can I help you?\" }\n * ]\n * },\n * finishReason: \"STOP\",\n * safetyRatings: [...]\n * };\n *\n * const aiMessage = convertGeminiCandidateToAIMessage(candidate);\n * // Returns: AIMessage with content \"Hello, how can I help you?\"\n * ```\n *\n * @param candidate - The Gemini API candidate response containing content parts and metadata\n * @returns An AIMessage instance with converted content, tool calls, and metadata\n */\nexport const convertGeminiCandidateToAIMessage: Converter<\n Gemini.Candidate,\n AIMessage\n> = (candidate) => {\n function groundingSupportByPart(\n groundingSupports?: Gemini.GroundingSupport[]\n ): Gemini.GroundingSupport[][] {\n const ret: Gemini.GroundingSupport[][] = [];\n\n if (!groundingSupports || groundingSupports.length === 0) {\n return [[]];\n }\n\n groundingSupports?.forEach((groundingSupport) => {\n const segment = groundingSupport?.segment;\n const partIndex = segment?.partIndex ?? 0;\n if (ret[partIndex]) {\n ret[partIndex].push(groundingSupport);\n } else {\n ret[partIndex] = [groundingSupport];\n }\n });\n\n return ret;\n }\n\n const parts = candidate.content?.parts || [];\n\n // Extract tool calls from function call parts\n const toolCalls = convertGeminiPartsToToolCalls(parts);\n\n // Convert parts to content format that the translator understands\n // Format: array of objects with type field matching the part type\n let content: string | ContentBlock[];\n let originalTextContentBlock: ContentBlock | undefined = undefined;\n\n const groundingMetadata = candidate?.groundingMetadata;\n const citationMetadata = candidate?.citationMetadata;\n const groundingParts = groundingSupportByPart(\n groundingMetadata?.groundingSupports\n );\n\n // Determine if a part carries actual content vs. just metadata.\n // Metadata-only parts (e.g. empty text with only thoughtSignature) should not\n // prevent collapsing a single-text response into a string.\n const hasContentPayload = (p: Gemini.Part): boolean =>\n !!p.text ||\n !!p.thought ||\n !!p.inlineData ||\n !!p.fileData ||\n !!p.functionCall ||\n !!p.functionResponse ||\n !!p.executableCode ||\n !!p.codeExecutionResult;\n\n const contentParts = parts.filter(hasContentPayload);\n\n if (contentParts.length === 0) {\n // No content-bearing parts (may still have metadata-only parts)\n content = \"\";\n if (parts.length > 0) {\n originalTextContentBlock = convertGeminiPartToContentBlock(parts[0]);\n }\n } else if (\n contentParts.length === 1 &&\n \"text\" in contentParts[0] &&\n !(\"thought\" in contentParts[0])\n ) {\n // Single text content part (possibly alongside metadata-only parts like\n // thoughtSignature) - store as string\n content = contentParts[0].text ?? \"\";\n // Merge metadata from any metadata-only parts into the content block\n const mergedPart: Gemini.Part = { ...contentParts[0] };\n for (const p of parts) {\n if (p !== contentParts[0] && p.thoughtSignature) {\n mergedPart.thoughtSignature = p.thoughtSignature;\n }\n }\n originalTextContentBlock = convertGeminiPartToContentBlock(mergedPart);\n } else {\n // Multiple content parts - convert to array format with type fields\n content = parts.map((p: Gemini.Part) => convertGeminiPartToContentBlock(p));\n }\n\n const additional_kwargs: Record<string, unknown> = {\n finishReason: candidate.finishReason,\n finishMessage: candidate.finishMessage,\n safetyRatings: candidate.safetyRatings,\n tokenCount: candidate.tokenCount,\n citationMetadata: candidate.citationMetadata,\n groundingMetadata: candidate.groundingMetadata,\n groundingAttributions: candidate.groundingAttributions,\n urlRetrievalMetadata: candidate.urlRetrievalMetadata,\n urlContextMetadata: candidate.urlContextMetadata,\n avgLogprobs: candidate.avgLogprobs,\n logprobsResult: candidate.logprobsResult,\n originalTextContentBlock,\n };\n\n const response_metadata: Record<string, unknown> = {\n model_provider: \"google\",\n finish_reason: candidate.finishReason,\n safety_ratings: candidate.safetyRatings,\n citation_metadata: candidate.citationMetadata,\n grounding_metadata: candidate.groundingMetadata,\n grounding_attributions: candidate.groundingAttributions,\n url_retrieval_metadata: candidate.urlRetrievalMetadata,\n url_context_metadata: candidate.urlContextMetadata,\n avg_logprobs: candidate.avgLogprobs,\n logprobs_result: candidate.logprobsResult,\n\n // Backwards compatibility\n citationMetadata,\n groundingMetadata,\n groundingSupport: groundingParts[0],\n };\n // Remove any undefined properties, so we don't include them\n for (const attribute in additional_kwargs) {\n if (additional_kwargs[attribute] === undefined) {\n delete additional_kwargs[attribute];\n }\n }\n for (const attribute in response_metadata) {\n if (response_metadata[attribute] === undefined) {\n delete response_metadata[attribute];\n }\n }\n\n return new AIMessage({\n content,\n tool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n additional_kwargs,\n response_metadata,\n });\n};\n\nexport const convertAIMessageToText: Converter<AIMessage, string> = (\n message: AIMessage\n): string => {\n if (typeof message.content === \"string\") {\n return message.content;\n } else if (Array.isArray(message.content)) {\n return message.content\n .filter(\n (c) => typeof c === \"string\" || (c as { type?: string }).type === \"text\"\n )\n .map((c) =>\n typeof c === \"string\" ? c : (c as { text?: string }).text || \"\"\n )\n .join(\"\");\n } else {\n return \"\";\n }\n};\n\nexport const convertGeminiGenerateContentResponseToUsageMetadata: Converter<\n Gemini.GenerateContentResponse,\n UsageMetadata\n> = (data: Gemini.GenerateContentResponse): UsageMetadata => {\n function addModalityCounts(\n modalityTokenCounts: Gemini.ModalityTokenCount[] | undefined,\n details: InputTokenDetails | OutputTokenDetails\n ): void {\n modalityTokenCounts?.forEach((modalityTokenCount) => {\n const { modality, tokenCount } = modalityTokenCount;\n if (\n typeof modality === \"undefined\" ||\n typeof tokenCount === \"undefined\"\n ) {\n return;\n }\n const modalityLc: keyof ModalitiesTokenDetails =\n modality.toLowerCase() as keyof ModalitiesTokenDetails;\n const currentCount = details[modalityLc] ?? 0;\n details[modalityLc] = currentCount + tokenCount;\n });\n }\n\n const usageMetadata: Gemini.UsageMetadata | undefined = data.usageMetadata;\n\n const inputTokenCount = usageMetadata?.promptTokenCount ?? 0;\n const candidatesTokenCount = usageMetadata?.candidatesTokenCount ?? 0;\n const thoughtsTokenCount = usageMetadata?.thoughtsTokenCount ?? 0;\n const outputTokenCount = candidatesTokenCount + thoughtsTokenCount;\n const totalTokens =\n usageMetadata?.totalTokenCount ?? inputTokenCount + outputTokenCount;\n\n const input_token_details: InputTokenDetails = {};\n addModalityCounts(usageMetadata?.promptTokensDetails, input_token_details);\n input_token_details.cache_read = usageMetadata?.cachedContentTokenCount ?? 0;\n\n const output_token_details: OutputTokenDetails = {};\n addModalityCounts(\n usageMetadata?.candidatesTokensDetails,\n output_token_details\n );\n output_token_details.reasoning = usageMetadata?.thoughtsTokenCount ?? 0;\n\n return {\n input_tokens: inputTokenCount,\n output_tokens: outputTokenCount,\n total_tokens: totalTokens,\n input_token_details,\n output_token_details,\n };\n};\n"],"mappings":";;;;;;;;;;;;AAqCA,MAAa,8BAKR;CACH,cAAc;CAEd,sBAAsB,OAA4C;EAChE,OAAO,EAAE,MAAM,MAAM,KAAK;CAC5B;CAEA,uBAAuB,OAA6C;EAClE,KAAA,GAAIA,yBAAAA,mBAAAA,CAAmB,KAAK,GAAG;GAC7B,IAAI,MAAM,gBAAgB,UAAU;IAClC,IAAI,CAAC,MAAM,WACT,MAAM,IAAIC,eAAAA,kBACR,+CACF;IAEF,MAAM,UACJ,OAAO,MAAM,SAAS,WAClB,MAAM,OACN,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,OAE/C,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AM,YAAa,EAAwB,SAAS,MACpE,CAAC,CACA,KAAK,MACJ,OAAO,MAAM,WAAW,IAAK,EAAwB,QAAQ,EAC/D,CAAC,CACA,KAAK,EAAE;MAEV,OAAO;AAEX;AAEA,MAAa,uDAGR,SAAwD;CAC3D,SAAS,kBACP,qBACA,SACM;EACN,qBAAqB,SAAS,uBAAuB;GACnD,MAAM,EAAE,UAAU,eAAe;GACjC,IACE,OAAO,aAAa,eACpB,OAAO,eAAe,aAEtB;GAEF,MAAM,aACJ,SAAS,YAAY;GAEvB,QAAQ,eADa,QAAQ,eAAe,KACP;EACvC,CAAC;CACH;CAEA,MAAM,gBAAkD,KAAK;CAE7D,MAAM,kBAAkB,eAAe,oBAAoB;CAG3D,MAAM,oBAFuB,eAAe,wBAAwB,MACzC,eAAe,sBAAsB;CAEhE,MAAM,cACJ,eAAe,mBAAmB,kBAAkB;CAEtD,MAAM,sBAAyC,CAAC;CAChD,kBAAkB,eAAe,qBAAqB,mBAAmB;CACzE,oBAAoB,aAAa,eAAe,2BAA2B;CAE3E,MAAM,uBAA2C,CAAC;CAClD,kBACE,eAAe,yBACf,oBACF;CACA,qBAAqB,YAAY,eAAe,sBAAsB;CAEtE,OAAO;EACL,cAAc;EACd,eAAe;EACf,cAAc;EACd;EACA;CACF;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iife } from "
|
|
2
|
-
import { InvalidInputError, ToolCallNotFoundError } from "
|
|
1
|
+
import { iife } from "../../utils/misc.js";
|
|
2
|
+
import { InvalidInputError, ToolCallNotFoundError } from "../../utils/errors.js";
|
|
3
3
|
import { AIMessage, ChatMessage, HumanMessage, SystemMessage, ToolMessage, convertToProviderContentBlock, isDataContentBlock, parseBase64DataUrl } from "@langchain/core/messages";
|
|
4
4
|
import { v4 } from "@langchain/core/utils/uuid";
|
|
5
|
-
|
|
5
|
+
// src/converters/generate_content/messages.ts
|
|
6
6
|
/**
|
|
7
7
|
* Standard content block converter for Google Gemini API.
|
|
8
8
|
* Converts deprecated Data content blocks to Gemini Part format.
|
|
@@ -454,7 +454,7 @@ const convertMessagesToGeminiContents = (messages) => {
|
|
|
454
454
|
const contents = [];
|
|
455
455
|
for (const message of messages) {
|
|
456
456
|
const content = iife(() => {
|
|
457
|
-
switch ("output_version" in message.response_metadata ? message.response_metadata?.output_version : "v0") {
|
|
457
|
+
switch (message.response_metadata && "output_version" in message.response_metadata ? message.response_metadata?.output_version : "v0") {
|
|
458
458
|
case "v1": return convertStandardContentMessageToGeminiContent(message, messages);
|
|
459
459
|
default: return convertLegacyContentMessageToGeminiContent(message, messages);
|
|
460
460
|
}
|
|
@@ -773,7 +773,6 @@ const convertGeminiGenerateContentResponseToUsageMetadata = (data) => {
|
|
|
773
773
|
output_token_details
|
|
774
774
|
};
|
|
775
775
|
};
|
|
776
|
-
//#endregion
|
|
777
776
|
export { convertAIMessageToText, convertGeminiCandidateToAIMessage, convertGeminiGenerateContentResponseToUsageMetadata, convertGeminiPartToContentBlock, convertGeminiPartsToToolCalls, convertMessagesToGeminiContents, convertMessagesToGeminiSystemInstruction, geminiContentBlockConverter };
|
|
778
777
|
|
|
779
778
|
//# sourceMappingURL=messages.js.map
|