const fs = require('fs'); const path = 'vibn-frontend/lib/ai/gemini-chat.ts'; let code = fs.readFileSync(path, 'utf8'); // The issue is in `toGeminiContents()`. // For `gemini-3.1-pro-preview` thinking models, `thoughtSignature` MUST be passed back // as a sibling to `functionCall` in the `parts` array for assistant responses, // OR inside the `functionResponse` for tool responses (depending on API version). // Also we need to extract it from the response. code = code.replace( ` const part: any = { functionCall: { name: tc.name, args: tc.args }, }; parts.push(part);`, ` const part: any = { functionCall: { name: tc.name, args: tc.args }, }; if (tc.thoughtSignature) { part.thoughtSignature = tc.thoughtSignature; } parts.push(part);` ); code = code.replace( ` toolCalls.push({ id: \`tc-\${Date.now()}-\${Math.random().toString(36).slice(2)}\`, name: part.functionCall.name, args: part.functionCall.args as Record ?? {}, });`, ` toolCalls.push({ id: \`tc-\${Date.now()}-\${Math.random().toString(36).slice(2)}\`, name: part.functionCall.name, args: part.functionCall.args as Record ?? {}, thoughtSignature: (part as any).thoughtSignature, });` ); fs.writeFileSync(path, code);