mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 15:14:57 +00:00
fix(agents): harden openai ws tool call id handling
This commit is contained in:
@@ -424,6 +424,41 @@ describe("convertMessagesToInputItems", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("drops tool result messages with empty tool call id", () => {
|
||||
const msg = {
|
||||
role: "toolResult" as const,
|
||||
toolCallId: " ",
|
||||
toolName: "test_tool",
|
||||
content: [{ type: "text", text: "output" }],
|
||||
isError: false,
|
||||
timestamp: 0,
|
||||
};
|
||||
const items = convertMessagesToInputItems([msg] as Parameters<
|
||||
typeof convertMessagesToInputItems
|
||||
>[0]);
|
||||
expect(items).toEqual([]);
|
||||
});
|
||||
|
||||
it("falls back to toolUseId when toolCallId is missing", () => {
|
||||
const msg = {
|
||||
role: "toolResult" as const,
|
||||
toolUseId: "call_from_tool_use",
|
||||
toolName: "test_tool",
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
isError: false,
|
||||
timestamp: 0,
|
||||
};
|
||||
const items = convertMessagesToInputItems([msg] as Parameters<
|
||||
typeof convertMessagesToInputItems
|
||||
>[0]);
|
||||
expect(items).toHaveLength(1);
|
||||
expect(items[0]).toMatchObject({
|
||||
type: "function_call_output",
|
||||
call_id: "call_from_tool_use",
|
||||
output: "ok",
|
||||
});
|
||||
});
|
||||
|
||||
it("converts a full multi-turn conversation", () => {
|
||||
const messages: FakeMessage[] = [
|
||||
userMsg("Run ls"),
|
||||
@@ -454,6 +489,14 @@ describe("convertMessagesToInputItems", () => {
|
||||
expect(items[0]?.type).toBe("function_call");
|
||||
});
|
||||
|
||||
it("drops assistant tool calls with empty ids", () => {
|
||||
const msg = assistantMsg([], [{ id: " ", name: "read", args: { path: "/tmp/a" } }]);
|
||||
const items = convertMessagesToInputItems([msg] as Parameters<
|
||||
typeof convertMessagesToInputItems
|
||||
>[0]);
|
||||
expect(items).toEqual([]);
|
||||
});
|
||||
|
||||
it("skips thinking blocks in assistant messages", () => {
|
||||
const msg = {
|
||||
role: "assistant" as const,
|
||||
|
||||
Reference in New Issue
Block a user