7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(google): preserve Gemini thought_signature in tool calls (#32)
Thiago Freitas130c395c8c72
diff --git a/server/src/__tests__/providers/google.test.ts b/server/src/__tests__/providers/google.test.tsindex 928d1906..1c92fd0b 100644--- a/server/src/__tests__/providers/google.test.ts+++ b/server/src/__tests__/providers/google.test.ts@@ -171,4 +171,63 @@ describe('GoogleProvider', () => {expect(result.choices[0].message.tool_calls?.[0].function.name).toBe('get_weather');expect(result.choices[0].message.tool_calls?.[0].function.arguments).toBe('{"city":"Lahore"}');});++ it('should preserve and pass through thought_signature', async () => {+ let capturedBody: any;+ vi.spyOn(global, 'fetch').mockImplementation(async (_url, init) => {+ capturedBody = JSON.parse((init as any).body);+ return {+ ok: true,+ json: () => Promise.resolve({+ candidates: [{+ content: {+ parts: [{+ thought_signature: 'sig_123',+ functionCall: {+ id: 'call_123',+ name: 'get_weather',+ args: { city: 'London' },+ },+ }],+ },+ finishReason: 'STOP',+ }],+ usageMetadata: { promptTokenCount: 1, candidatesTokenCount: 1, totalTokenCount: 2 },+ }),+ } as any;+ });++ // 1. Check extraction+ const result = await provider.chatCompletion(+ 'test-key',+ [{ role: 'user', content: 'Weather?' }],+ 'gemini-2.5-pro',+ );++ expect(result.choices[0].message.tool_calls?.[0].thought_signature).toBe('sig_123');++ // 2. Check injection in next turn+ await provider.chatCompletion(+ 'test-key',+ [+ { role: 'user', content: 'Weather?' },+ {+ role: 'assistant',+ content: null,+ tool_calls: [{+ id: 'call_123',+ type: 'function',+ function: { name: 'get_weather', arguments: '{"city":"London"}' },+ thought_signature: 'sig_123',+ }],+ },+ { role: 'tool', tool_call_id: 'call_123', content: '{"temp": 20}' },+ ],+ 'gemini-2.5-pro',+ );++ const assistantEntry = capturedBody.contents.find((c: any) => c.role === 'model');+ expect(assistantEntry.parts[0].thought_signature).toBe('sig_123');+ expect(assistantEntry.parts[0].functionCall.name).toBe('get_weather');+ });});diff --git a/server/src/providers/google.ts b/server/src/providers/google.tsindex 4a79420a..ba5722b7 100644--- a/server/src/providers/google.ts+++ b/server/src/providers/google.ts@@ -13,6 +13,7 @@ const API_BASE = 'https://generativelanguage.googleapis.com/v1beta';interface GeminiPart {text?: string;+ thoughtSignature?: string;functionCall?: {id?: string;name?: string;@@ -124,6 +125,7 @@ function toGeminiContents(messages: ChatMessage[]) {for (const call of m.tool_calls ?? []) {parts.push({+ thoughtSignature: call.thought_signature,functionCall: {id: call.id,name: call.function.name,@@ -189,6 +191,7 @@ function extractToolCalls(parts: GeminiPart[] | undefined): ChatToolCall[] {name: part.functionCall.name,arguments: normalizeGeminiArgs(part.functionCall.args),},+ thought_signature: part.thoughtSignature,});}diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.tsindex b63b1d77..0136d776 100644--- a/server/src/routes/proxy.ts+++ b/server/src/routes/proxy.ts@@ -84,6 +84,7 @@ const toolCallSchema = z.object({name: z.string().min(1),arguments: z.string(),}),+ thought_signature: z.string().optional(),});const systemMessageSchema = z.object({@@ -202,7 +203,12 @@ proxyRouter.post('/chat/completions', async (req: Request, res: Response) => {role: 'assistant',content: m.content ?? null,...(m.name ? { name: m.name } : {}),- ...(m.tool_calls ? { tool_calls: m.tool_calls } : {}),+ ...(m.tool_calls ? { tool_calls: m.tool_calls.map(tc => ({+ id: tc.id,+ type: tc.type,+ function: tc.function,+ thought_signature: tc.thought_signature,+ })) } : {}),};}diff --git a/shared/types.ts b/shared/types.tsindex 1b81762b..f605ab78 100644--- a/shared/types.ts+++ b/shared/types.ts@@ -76,6 +76,7 @@ export interface ChatToolCall {id: string;type: 'function';function: ChatToolCallFunction;+ thought_signature?: string;}export interface ChatToolFunctionDefinition {