From fc9c49b2181b625d6d69e53366b0aa146e5d3767 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 25 Nov 2025 08:59:39 +0530 Subject: [PATCH] fix types in core gemini llm --- core/llm/llms/Gemini.ts | 56 +++++++++++++++++++++-------------- core/llm/llms/gemini-types.ts | 1 + 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/core/llm/llms/Gemini.ts b/core/llm/llms/Gemini.ts index d9ae2a77b..79462607d 100644 --- a/core/llm/llms/Gemini.ts +++ b/core/llm/llms/Gemini.ts @@ -23,6 +23,14 @@ import { convertContinueToolToGeminiFunction, } from "./gemini-types"; +interface GeminiToolCallDelta extends ToolCallDelta { + extra_content?: { + google?: { + thought_signature?: string; + }; + }; +} + class Gemini extends BaseLLM { static providerName = "gemini"; @@ -268,31 +276,33 @@ class Gemini extends BaseLLM { }; if (msg.toolCalls && msg.toolCalls.length) { - msg.toolCalls.forEach((toolCall, index) => { - if (toolCall.function?.name) { - const signatureForCall = (toolCall as any)?.extra_content - ?.google?.thought_signature; + (msg.toolCalls as GeminiToolCallDelta[]).forEach( + (toolCall, index) => { + if (toolCall.function?.name) { + const signatureForCall = + toolCall?.extra_content?.google?.thought_signature; - let thoughtSignature: string | undefined; - if (index === 0) { - if (typeof signatureForCall === "string") { - thoughtSignature = signatureForCall; - } else { - // Fallback per https://ai.google.dev/gemini-api/docs/thought-signatures - // for histories that were not generated by Gemini or are missing signatures. - thoughtSignature = "skip_thought_signature_validator"; + let thoughtSignature: string | undefined; + if (index === 0) { + if (typeof signatureForCall === "string") { + thoughtSignature = signatureForCall; + } else { + // Fallback per https://ai.google.dev/gemini-api/docs/thought-signatures + // for histories that were not generated by Gemini or are missing signatures. + thoughtSignature = "skip_thought_signature_validator"; + } } - } - assistantMsg.parts.push({ - functionCall: { - name: toolCall.function.name, - args: safeParseToolCallArgs(toolCall), - }, - ...(thoughtSignature && { thoughtSignature }), - }); - } - }); + assistantMsg.parts.push({ + functionCall: { + name: toolCall.function.name, + args: safeParseToolCallArgs(toolCall), + }, + ...(thoughtSignature && { thoughtSignature }), + }); + } + }, + ); } return assistantMsg; @@ -387,7 +397,7 @@ class Gemini extends BaseLLM { if ("text" in part) { textParts.push({ type: "text", text: part.text }); } else if ("functionCall" in part) { - const thoughtSignature = (part as any)?.thoughtSignature; + const thoughtSignature = part.thoughtSignature; toolCalls.push({ type: "function", id: part.functionCall.id ?? uuidv4(), diff --git a/core/llm/llms/gemini-types.ts b/core/llm/llms/gemini-types.ts index 355d1c942..f1944930b 100644 --- a/core/llm/llms/gemini-types.ts +++ b/core/llm/llms/gemini-types.ts @@ -192,6 +192,7 @@ export type GeminiFunctionCallContentPart = { name: string; args: JSONSchema7Object; }; + thoughtSignature?: string; }; export type GeminiFunctionResponseContentPart = {