|
1 | 1 | import { Anthropic } from "@anthropic-ai/sdk" |
| 2 | +import type OpenAI from "openai" |
2 | 3 |
|
3 | 4 | import { LiteLLMHandler } from "../lite-llm" |
| 5 | +import type { ApiHandlerCreateMessageMetadata } from "../../index" |
4 | 6 | import { ApiHandlerOptions } from "../../../shared/api" |
5 | 7 | import { litellmDefaultModelId, litellmDefaultModelInfo } from "@roo-code/types" |
6 | 8 | import { asyncStreamFrom, collectStream } from "../../../test-utils/stream" |
@@ -754,6 +756,47 @@ describe("LiteLLMHandler", () => { |
754 | 756 | expect(assistantMessage.tool_calls[0].provider_specific_fields.thought_signature).toBe(dummySignature) |
755 | 757 | }) |
756 | 758 |
|
| 759 | + it("should send tool call ids that carry a thought signature unchanged", async () => { |
| 760 | + // LiteLLM encodes the Gemini signature into the id; truncating it breaks the signature. |
| 761 | + const signature = "AY89a18ErUKBAfkTYnDbzq6mGnRG5QS8VFogncpDzYVXzC0i_aDwY5o-0123456789abcdef" |
| 762 | + const toolCallId = `call_864944__thought__${signature}` |
| 763 | + expect(toolCallId.length).toBeGreaterThan(64) |
| 764 | + |
| 765 | + const messages: Anthropic.Messages.MessageParam[] = [ |
| 766 | + { role: "user", content: "Hello" }, |
| 767 | + { |
| 768 | + role: "assistant", |
| 769 | + content: [{ type: "tool_use", id: toolCallId, name: "read_file", input: { path: "test.txt" } }], |
| 770 | + }, |
| 771 | + { |
| 772 | + role: "user", |
| 773 | + content: [{ type: "tool_result", tool_use_id: toolCallId, content: "file contents" }], |
| 774 | + }, |
| 775 | + ] |
| 776 | + mockCreate.mockReturnValue({ |
| 777 | + withResponse: vi.fn().mockResolvedValue({ |
| 778 | + data: asyncStreamFrom([{ choices: [{ delta: { content: "ok" } }] }]), |
| 779 | + }), |
| 780 | + }) |
| 781 | + const metadata: ApiHandlerCreateMessageMetadata = { |
| 782 | + taskId: "task-1", |
| 783 | + tools: [ |
| 784 | + { |
| 785 | + type: "function", |
| 786 | + function: { name: "read_file", description: "Read a file", parameters: {} }, |
| 787 | + }, |
| 788 | + ], |
| 789 | + } |
| 790 | + |
| 791 | + await collectStream(handler.createMessage("You are a helpful assistant", messages, metadata)) |
| 792 | + |
| 793 | + const sent: OpenAI.Chat.ChatCompletionMessageParam[] = mockCreate.mock.calls[0][0].messages |
| 794 | + const assistantMessage = sent.find((msg) => msg.role === "assistant" && msg.tool_calls?.length) |
| 795 | + const toolMessage = sent.find((msg) => msg.role === "tool") |
| 796 | + expect(assistantMessage?.role === "assistant" && assistantMessage.tool_calls?.[0].id).toBe(toolCallId) |
| 797 | + expect(toolMessage?.role === "tool" && toolMessage.tool_call_id).toBe(toolCallId) |
| 798 | + }) |
| 799 | + |
757 | 800 | it("should not inject thought signatures for non-Gemini models", async () => { |
758 | 801 | const optionsWithGPT4: ApiHandlerOptions = { |
759 | 802 | ...mockOptions, |
|
0 commit comments