Skip to content

Commit f6ebd26

Browse files
authored
fix: default missing function call arguments
Co-authored-by: ndycode <ndycode@users.noreply.github.com>
1 parent 4b129f9 commit f6ebd26

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

lib/request/request-transformer.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,12 +741,21 @@ export function filterInput(
741741
})
742742
.map((item) => {
743743
// Strip IDs from all items (Codex API stateless mode)
744+
let normalizedItem = item;
744745
if (item.id) {
745746
const { id: _omit, ...itemWithoutId } = item;
746747
void _omit;
747-
return itemWithoutId as InputItem;
748+
normalizedItem = itemWithoutId as InputItem;
748749
}
749-
return item;
750+
751+
if (
752+
normalizedItem.type === "function_call" &&
753+
(normalizedItem.arguments === undefined || normalizedItem.arguments === null)
754+
) {
755+
return { ...normalizedItem, arguments: "{}" } as InputItem;
756+
}
757+
758+
return normalizedItem;
750759
});
751760
}
752761

test/request-transformer.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,20 @@ describe('Request Transformer Module', () => {
547547
expect(result![1]).not.toHaveProperty('id');
548548
});
549549

550+
it('should default missing function_call arguments to an empty JSON object', () => {
551+
const input: InputItem[] = [
552+
{ type: 'function_call', role: 'assistant', call_id: 'call_missing', name: 'read_file' },
553+
{ type: 'function_call', role: 'assistant', call_id: 'call_null', name: 'list_files', arguments: null },
554+
{ type: 'function_call', role: 'assistant', call_id: 'call_present', name: 'write_file', arguments: '{"path":"README.md"}' },
555+
];
556+
557+
const result = filterInput(input);
558+
559+
expect(result![0].arguments).toBe('{}');
560+
expect(result![1].arguments).toBe('{}');
561+
expect(result![2].arguments).toBe('{"path":"README.md"}');
562+
});
563+
550564
it('should return undefined for undefined input', () => {
551565
expect(filterInput(undefined)).toBeUndefined();
552566
});

0 commit comments

Comments
 (0)