mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 09:01:14 +00:00
fix(ai): port openai responses handoff guard
This commit is contained in:
parent
5edec3a40a
commit
bd7049b7d1
2 changed files with 16 additions and 2 deletions
|
|
@ -6,7 +6,7 @@ if (typeof process !== "undefined" && (process.versions?.node || process.version
|
|||
});
|
||||
}
|
||||
|
||||
import type { ResponseInput, ResponseStreamEvent, Tool as OpenAITool } from "openai/resources/responses/responses.js";
|
||||
import type { Tool as OpenAITool, ResponseInput, ResponseStreamEvent } from "openai/resources/responses/responses.js";
|
||||
import { getEnvApiKey } from "../stream.js";
|
||||
import type { Api, AssistantMessage, Context, Model, StreamFunction, StreamOptions } from "../types.js";
|
||||
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
||||
|
|
|
|||
|
|
@ -135,6 +135,11 @@ export function convertResponsesMessages<TApi extends Api>(
|
|||
}
|
||||
} else if (msg.role === "assistant") {
|
||||
const output: ResponseInput = [];
|
||||
const assistantMsg = msg as AssistantMessage;
|
||||
const isDifferentModel =
|
||||
assistantMsg.model !== model.id &&
|
||||
assistantMsg.provider === model.provider &&
|
||||
assistantMsg.api === model.api;
|
||||
|
||||
for (const block of msg.content) {
|
||||
if (block.type === "thinking") {
|
||||
|
|
@ -160,7 +165,16 @@ export function convertResponsesMessages<TApi extends Api>(
|
|||
} satisfies ResponseOutputMessage);
|
||||
} else if (block.type === "toolCall") {
|
||||
const toolCall = block as ToolCall;
|
||||
const [callId, itemId] = toolCall.id.split("|");
|
||||
const [callId, itemIdRaw] = toolCall.id.split("|");
|
||||
let itemId: string | undefined = itemIdRaw;
|
||||
|
||||
// For different-model messages, set id to undefined to avoid pairing validation.
|
||||
// OpenAI tracks which fc_xxx IDs were paired with rs_xxx reasoning items.
|
||||
// By omitting the id, we avoid triggering that validation (like cross-provider does).
|
||||
if (isDifferentModel && itemId?.startsWith("fc_")) {
|
||||
itemId = undefined;
|
||||
}
|
||||
|
||||
output.push({
|
||||
type: "function_call",
|
||||
id: itemId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue