@@ -12,6 +12,13 @@ describe("anthropic-filter", () => {
1212 expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "thinking" ) ) . toBe ( true )
1313 expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "redacted_thinking" ) ) . toBe ( true )
1414 expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "document" ) ) . toBe ( true )
15+ expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "server_tool_use" ) ) . toBe ( true )
16+ expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "advisor_tool_result" ) ) . toBe ( true )
17+ } )
18+
19+ it ( "should contain server_tool_use and advisor_tool_result" , ( ) => {
20+ expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "server_tool_use" ) ) . toBe ( true )
21+ expect ( VALID_ANTHROPIC_BLOCK_TYPES . has ( "advisor_tool_result" ) ) . toBe ( true )
1522 } )
1623
1724 it ( "should not contain internal or provider-specific types" , ( ) => {
@@ -140,5 +147,59 @@ describe("anthropic-filter", () => {
140147 expect ( result ) . toHaveLength ( 1 )
141148 expect ( result [ 0 ] . content ) . toEqual ( [ { type : "text" , text : "Valid text" } ] )
142149 } )
150+
151+ it ( "should preserve server_tool_use blocks in assistant turns" , ( ) => {
152+ const messages : Anthropic . Messages . MessageParam [ ] = [
153+ { role : "user" , content : "Hello" } ,
154+ {
155+ role : "assistant" ,
156+ content : [
157+ { type : "server_tool_use" as any , id : "srvtoolu_abc123" , name : "advisor" , input : { } } ,
158+ { type : "text" , text : "Response" } ,
159+ ] ,
160+ } ,
161+ ]
162+ const result = filterNonAnthropicBlocks ( messages )
163+ expect ( result ) . toHaveLength ( 2 )
164+ expect ( result [ 1 ] . content ) . toHaveLength ( 2 )
165+ expect ( ( result [ 1 ] . content as any [ ] ) [ 0 ] . type ) . toBe ( "server_tool_use" )
166+ } )
167+
168+ it ( "should preserve advisor_tool_result blocks in assistant turns" , ( ) => {
169+ const messages : Anthropic . Messages . MessageParam [ ] = [
170+ { role : "user" , content : "Hello" } ,
171+ {
172+ role : "assistant" ,
173+ content : [
174+ {
175+ type : "advisor_tool_result" as any ,
176+ tool_use_id : "srvtoolu_abc123" ,
177+ content : "Advisor says hi" ,
178+ } ,
179+ { type : "text" , text : "Response" } ,
180+ ] ,
181+ } ,
182+ ]
183+ const result = filterNonAnthropicBlocks ( messages )
184+ expect ( result ) . toHaveLength ( 2 )
185+ expect ( result [ 1 ] . content ) . toHaveLength ( 2 )
186+ expect ( ( result [ 1 ] . content as any [ ] ) [ 0 ] . type ) . toBe ( "advisor_tool_result" )
187+ } )
188+
189+ it ( "should preserve both server_tool_use and advisor_tool_result block types alongside text blocks" , ( ) => {
190+ const messages : Anthropic . Messages . MessageParam [ ] = [
191+ {
192+ role : "assistant" ,
193+ content : [
194+ { type : "server_tool_use" as any , id : "srvtoolu_abc123" , name : "advisor" , input : { } } ,
195+ { type : "advisor_tool_result" as any , tool_use_id : "srvtoolu_abc123" , content : "ok" } ,
196+ { type : "text" , text : "Final answer" } ,
197+ ] ,
198+ } ,
199+ ]
200+ const result = filterNonAnthropicBlocks ( messages )
201+ expect ( result ) . toHaveLength ( 1 )
202+ expect ( result [ 0 ] . content ) . toHaveLength ( 3 )
203+ } )
143204 } )
144205} )
0 commit comments