From 32a8d58725aeccb7352557ddbd1f5fb0086174e0 Mon Sep 17 00:00:00 2001 From: TDFSE <77169190+TDFSE@users.noreply.github.com> Date: Fri, 10 Apr 2026 14:02:00 -0400 Subject: [PATCH] Add tool use/result to VALID_ANTHROPIC_BLOCK_TYPES --- .../__tests__/anthropic-filter.spec.ts | 61 +++++++++++++++++++ src/api/transform/anthropic-filter.ts | 2 + 2 files changed, 63 insertions(+) diff --git a/src/api/transform/__tests__/anthropic-filter.spec.ts b/src/api/transform/__tests__/anthropic-filter.spec.ts index 46ad1a1952..ceb0fdb34d 100644 --- a/src/api/transform/__tests__/anthropic-filter.spec.ts +++ b/src/api/transform/__tests__/anthropic-filter.spec.ts @@ -12,6 +12,13 @@ describe("anthropic-filter", () => { expect(VALID_ANTHROPIC_BLOCK_TYPES.has("thinking")).toBe(true) expect(VALID_ANTHROPIC_BLOCK_TYPES.has("redacted_thinking")).toBe(true) expect(VALID_ANTHROPIC_BLOCK_TYPES.has("document")).toBe(true) + expect(VALID_ANTHROPIC_BLOCK_TYPES.has("server_tool_use")).toBe(true) + expect(VALID_ANTHROPIC_BLOCK_TYPES.has("advisor_tool_result")).toBe(true) + }) + + it("should contain server_tool_use and advisor_tool_result", () => { + expect(VALID_ANTHROPIC_BLOCK_TYPES.has("server_tool_use")).toBe(true) + expect(VALID_ANTHROPIC_BLOCK_TYPES.has("advisor_tool_result")).toBe(true) }) it("should not contain internal or provider-specific types", () => { @@ -140,5 +147,59 @@ describe("anthropic-filter", () => { expect(result).toHaveLength(1) expect(result[0].content).toEqual([{ type: "text", text: "Valid text" }]) }) + + it("should preserve server_tool_use blocks in assistant turns", () => { + const messages: Anthropic.Messages.MessageParam[] = [ + { role: "user", content: "Hello" }, + { + role: "assistant", + content: [ + { type: "server_tool_use" as any, id: "srvtoolu_abc123", name: "advisor", input: {} }, + { type: "text", text: "Response" }, + ], + }, + ] + const result = filterNonAnthropicBlocks(messages) + expect(result).toHaveLength(2) + expect(result[1].content).toHaveLength(2) + expect((result[1].content as any[])[0].type).toBe("server_tool_use") + }) + + it("should preserve advisor_tool_result blocks in assistant turns", () => { + const messages: Anthropic.Messages.MessageParam[] = [ + { role: "user", content: "Hello" }, + { + role: "assistant", + content: [ + { + type: "advisor_tool_result" as any, + tool_use_id: "srvtoolu_abc123", + content: "Advisor says hi", + }, + { type: "text", text: "Response" }, + ], + }, + ] + const result = filterNonAnthropicBlocks(messages) + expect(result).toHaveLength(2) + expect(result[1].content).toHaveLength(2) + expect((result[1].content as any[])[0].type).toBe("advisor_tool_result") + }) + + it("should preserve both server_tool_use and advisor_tool_result block types alongside text blocks", () => { + const messages: Anthropic.Messages.MessageParam[] = [ + { + role: "assistant", + content: [ + { type: "server_tool_use" as any, id: "srvtoolu_abc123", name: "advisor", input: {} }, + { type: "advisor_tool_result" as any, tool_use_id: "srvtoolu_abc123", content: "ok" }, + { type: "text", text: "Final answer" }, + ], + }, + ] + const result = filterNonAnthropicBlocks(messages) + expect(result).toHaveLength(1) + expect(result[0].content).toHaveLength(3) + }) }) }) diff --git a/src/api/transform/anthropic-filter.ts b/src/api/transform/anthropic-filter.ts index 2bfc6dccfd..c82634995f 100644 --- a/src/api/transform/anthropic-filter.ts +++ b/src/api/transform/anthropic-filter.ts @@ -13,6 +13,8 @@ export const VALID_ANTHROPIC_BLOCK_TYPES = new Set([ "thinking", "redacted_thinking", "document", + "server_tool_use", + "advisor_tool_result", ]) /**