From febccbacc5b29a38d23022d099dff74c57ebce98 Mon Sep 17 00:00:00 2001 From: Stackbilt Date: Sun, 7 Jun 2026 16:31:38 -0500 Subject: [PATCH] fix: accept Cerebras tool calls without content --- src/__tests__/tool-call-validation.test.ts | 34 ++++++++++++++++++++++ src/providers/cerebras.ts | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/__tests__/tool-call-validation.test.ts b/src/__tests__/tool-call-validation.test.ts index cbc86e5..9e14129 100644 --- a/src/__tests__/tool-call-validation.test.ts +++ b/src/__tests__/tool-call-validation.test.ts @@ -361,6 +361,40 @@ describe('Tool call validation at provider boundary', () => { provider = new CerebrasProvider({ apiKey: 'test-key' }); }); + it('should pass Cerebras tool calls when message.content is omitted', async () => { + mockFetch.mockResolvedValueOnce({ + ok: true, + json: async () => ({ + id: 'chatcmpl-1', + model: 'zai-glm-4.7', + choices: [{ + index: 0, + message: { + role: 'assistant', + tool_calls: [{ + id: 'call_ok', + type: 'function', + function: { name: 'lookup', arguments: '{}' } + }] + }, + finish_reason: 'tool_calls' + }], + usage: baseUsage + }), + headers: new Headers({ 'content-type': 'application/json' }) + }); + + const res = await provider.generateResponse({ + messages: [{ role: 'user', content: 'hi' }], + model: 'zai-glm-4.7' + }); + + expect(res.content).toBe(''); + expect(res.toolCalls).toHaveLength(1); + expect(res.toolCalls![0].id).toBe('call_ok'); + expect(res.toolCalls![0].function.name).toBe('lookup'); + }); + it('should drop Cerebras tool call with empty function.name', async () => { mockFetch.mockResolvedValueOnce({ ok: true, diff --git a/src/providers/cerebras.ts b/src/providers/cerebras.ts index c3eee06..67745b9 100644 --- a/src/providers/cerebras.ts +++ b/src/providers/cerebras.ts @@ -27,7 +27,7 @@ const CEREBRAS_RESPONSE_SCHEMA: SchemaField[] = [ items: { shape: [ { path: 'message', type: 'object' }, - { path: 'message.content', type: 'string-or-null' }, + { path: 'message.content', type: 'string-or-null', optional: true }, { path: 'finish_reason', type: 'string' }, { path: 'message.tool_calls', @@ -101,7 +101,7 @@ interface CerebrasResponse { index: number; message: { role: string; - content: string | null; + content?: string | null; tool_calls?: Array<{ id: string; type: 'function';