Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/__tests__/tool-call-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/providers/cerebras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -101,7 +101,7 @@ interface CerebrasResponse {
index: number;
message: {
role: string;
content: string | null;
content?: string | null;
tool_calls?: Array<{
id: string;
type: 'function';
Expand Down