|
| 1 | +import type { RooMessage } from "../../../core/task-persistence/rooMessage" |
1 | 2 | // npx vitest run src/api/providers/__tests__/anthropic-vertex.spec.ts |
2 | 3 |
|
3 | 4 | import { AnthropicVertexHandler } from "../anthropic-vertex" |
@@ -54,6 +55,7 @@ vitest.mock("../../transform/ai-sdk", () => ({ |
54 | 55 | }), |
55 | 56 | mapToolChoice: vitest.fn().mockReturnValue(undefined), |
56 | 57 | handleAiSdkError: vitest.fn().mockImplementation((error: any) => error), |
| 58 | + yieldResponseMessage: vitest.fn().mockImplementation(function* () {}), |
57 | 59 | })) |
58 | 60 |
|
59 | 61 | // Import mocked modules |
@@ -184,7 +186,7 @@ describe("AnthropicVertexHandler", () => { |
184 | 186 | }) |
185 | 187 |
|
186 | 188 | describe("createMessage", () => { |
187 | | - const mockMessages: Anthropic.Messages.MessageParam[] = [ |
| 189 | + const mockMessages: RooMessage[] = [ |
188 | 190 | { |
189 | 191 | role: "user", |
190 | 192 | content: "Hello", |
@@ -244,15 +246,20 @@ describe("AnthropicVertexHandler", () => { |
244 | 246 | ) |
245 | 247 | }) |
246 | 248 |
|
247 | | - it("should call convertToAiSdkMessages with the messages", async () => { |
| 249 | + it("should pass messages directly to streamText as ModelMessage[]", async () => { |
248 | 250 | mockStreamText.mockReturnValue(createMockStreamResult([])) |
249 | 251 |
|
250 | 252 | const stream = handler.createMessage(systemPrompt, mockMessages) |
251 | 253 | for await (const _chunk of stream) { |
252 | 254 | // consume |
253 | 255 | } |
254 | 256 |
|
255 | | - expect(convertToAiSdkMessages).toHaveBeenCalledWith(mockMessages) |
| 257 | + // Messages are now already in ModelMessage format, passed directly to streamText |
| 258 | + expect(mockStreamText).toHaveBeenCalledWith( |
| 259 | + expect.objectContaining({ |
| 260 | + messages: mockMessages, |
| 261 | + }), |
| 262 | + ) |
256 | 263 | }) |
257 | 264 |
|
258 | 265 | it("should pass tools through AI SDK conversion pipeline", async () => { |
@@ -363,55 +370,6 @@ describe("AnthropicVertexHandler", () => { |
363 | 370 | expect(textChunks[0].text).toBe("Here's my answer:") |
364 | 371 | }) |
365 | 372 |
|
366 | | - it("should capture thought signature from stream events", async () => { |
367 | | - const streamParts = [ |
368 | | - { |
369 | | - type: "reasoning-delta", |
370 | | - text: "thinking...", |
371 | | - providerMetadata: { |
372 | | - anthropic: { signature: "test-signature-abc123" }, |
373 | | - }, |
374 | | - }, |
375 | | - { type: "text-delta", text: "answer" }, |
376 | | - ] |
377 | | - |
378 | | - mockStreamText.mockReturnValue(createMockStreamResult(streamParts)) |
379 | | - |
380 | | - const stream = handler.createMessage(systemPrompt, mockMessages) |
381 | | - for await (const _chunk of stream) { |
382 | | - // consume |
383 | | - } |
384 | | - |
385 | | - expect(handler.getThoughtSignature()).toBe("test-signature-abc123") |
386 | | - }) |
387 | | - |
388 | | - it("should capture redacted thinking blocks from stream events", async () => { |
389 | | - const streamParts = [ |
390 | | - { |
391 | | - type: "reasoning-delta", |
392 | | - text: "", |
393 | | - providerMetadata: { |
394 | | - anthropic: { redactedData: "encrypted-redacted-data" }, |
395 | | - }, |
396 | | - }, |
397 | | - { type: "text-delta", text: "answer" }, |
398 | | - ] |
399 | | - |
400 | | - mockStreamText.mockReturnValue(createMockStreamResult(streamParts)) |
401 | | - |
402 | | - const stream = handler.createMessage(systemPrompt, mockMessages) |
403 | | - for await (const _chunk of stream) { |
404 | | - // consume |
405 | | - } |
406 | | - |
407 | | - const redactedBlocks = handler.getRedactedThinkingBlocks() |
408 | | - expect(redactedBlocks).toHaveLength(1) |
409 | | - expect(redactedBlocks![0]).toEqual({ |
410 | | - type: "redacted_thinking", |
411 | | - data: "encrypted-redacted-data", |
412 | | - }) |
413 | | - }) |
414 | | - |
415 | 373 | it("should configure thinking providerOptions for thinking models", async () => { |
416 | 374 | const thinkingHandler = new AnthropicVertexHandler({ |
417 | 375 | apiModelId: "claude-3-7-sonnet@20250219:thinking", |
@@ -674,50 +632,4 @@ describe("AnthropicVertexHandler", () => { |
674 | 632 | expect(handler.isAiSdkProvider()).toBe(true) |
675 | 633 | }) |
676 | 634 | }) |
677 | | - |
678 | | - describe("thought signature and redacted thinking", () => { |
679 | | - beforeEach(() => { |
680 | | - handler = new AnthropicVertexHandler({ |
681 | | - apiModelId: "claude-3-5-sonnet-v2@20241022", |
682 | | - vertexProjectId: "test-project", |
683 | | - vertexRegion: "us-central1", |
684 | | - }) |
685 | | - }) |
686 | | - |
687 | | - it("should return undefined for thought signature before any request", () => { |
688 | | - expect(handler.getThoughtSignature()).toBeUndefined() |
689 | | - }) |
690 | | - |
691 | | - it("should return undefined for redacted thinking blocks before any request", () => { |
692 | | - expect(handler.getRedactedThinkingBlocks()).toBeUndefined() |
693 | | - }) |
694 | | - |
695 | | - it("should reset thought signature on each createMessage call", async () => { |
696 | | - // First call with signature |
697 | | - mockStreamText.mockReturnValue( |
698 | | - createMockStreamResult([ |
699 | | - { |
700 | | - type: "reasoning-delta", |
701 | | - text: "thinking", |
702 | | - providerMetadata: { anthropic: { signature: "sig-1" } }, |
703 | | - }, |
704 | | - ]), |
705 | | - ) |
706 | | - |
707 | | - const stream1 = handler.createMessage("test", [{ role: "user", content: "Hello" }]) |
708 | | - for await (const _chunk of stream1) { |
709 | | - // consume |
710 | | - } |
711 | | - expect(handler.getThoughtSignature()).toBe("sig-1") |
712 | | - |
713 | | - // Second call without signature |
714 | | - mockStreamText.mockReturnValue(createMockStreamResult([{ type: "text-delta", text: "just text" }])) |
715 | | - |
716 | | - const stream2 = handler.createMessage("test", [{ role: "user", content: "Hello again" }]) |
717 | | - for await (const _chunk of stream2) { |
718 | | - // consume |
719 | | - } |
720 | | - expect(handler.getThoughtSignature()).toBeUndefined() |
721 | | - }) |
722 | | - }) |
723 | 635 | }) |
0 commit comments