Skip to content
Open
Changes from 1 commit
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
38 changes: 26 additions & 12 deletions core/llm/openaiTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@
return list;
}

export function toResponsesInput(messages: ChatMessage[]): ResponseInput {

Check failure on line 777 in core/llm/openaiTypeConverters.ts

View workflow job for this annotation

GitHub Actions / core-checks

Function 'toResponsesInput' has a complexity of 40. Maximum allowed is 36
const input: ResponseInput = [];

const pushMessage = (
Expand Down Expand Up @@ -818,20 +818,34 @@
| undefined;
const toolCalls = msg.toolCalls as ToolCallDelta[] | undefined;

if (respId && Array.isArray(toolCalls) && toolCalls.length > 0) {
// Emit full function_call output item
if (Array.isArray(toolCalls) && toolCalls.length > 0) {
const tc = toolCalls[0];
const name = tc?.function?.name as string | undefined;
const args = tc?.function?.arguments as string | undefined;
const call_id = tc?.id as string | undefined;
const functionCallItem: ResponseFunctionToolCall = {
id: respId,
type: "function_call",
name: name || "",
arguments: typeof args === "string" ? args : "{}",
call_id: call_id || respId,
};
input.push(functionCallItem);

// Only emit function_call if we have an id to use (either respId or call_id)
const rawItemId = respId || call_id;
if (rawItemId) {
// Ensure the Responses item id uses the required prefix (e.g., 'fc')
const itemId = rawItemId.startsWith("fc")
? rawItemId
: `fc_${rawItemId}`;

const name = tc?.function?.name as string | undefined;
const args = tc?.function?.arguments as string | undefined;

const functionCallItem: ResponseFunctionToolCall = {
id: itemId,
type: "function_call",
name: name || "",
arguments: typeof args === "string" ? args : "{}",
call_id: call_id || respId || "",
};

input.push(functionCallItem);
} else {
// No IDs available, fallback to EasyInput assistant message to avoid emitting an invalid function_call
pushMessage("assistant", text || "");
}
} else if (respId) {
// Emit full assistant output message item
const outputMessageItem: ResponseOutputMessage = {
Expand Down
Loading