@ai-sdk/anthropic
Advanced tools
+8
-0
| # @ai-sdk/anthropic | ||
| ## 3.0.111 | ||
| ### Patch Changes | ||
| - 8533108: Preserve Anthropic server-tool caller metadata in multi-turn conversations. | ||
| - Updated dependencies [31205a4] | ||
| - @ai-sdk/provider-utils@4.0.46 | ||
| ## 3.0.110 | ||
@@ -4,0 +12,0 @@ |
+2
-2
| { | ||
| "name": "@ai-sdk/anthropic", | ||
| "version": "3.0.110", | ||
| "version": "3.0.111", | ||
| "license": "Apache-2.0", | ||
@@ -40,3 +40,3 @@ "sideEffects": false, | ||
| "@ai-sdk/provider": "3.0.15", | ||
| "@ai-sdk/provider-utils": "4.0.45" | ||
| "@ai-sdk/provider-utils": "4.0.46" | ||
| }, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
@@ -181,2 +181,3 @@ import type { JSONSchema7 } from '@ai-sdk/provider'; | ||
| input: unknown; | ||
| caller?: AnthropicToolCallCaller; | ||
| cache_control: AnthropicCacheControl | undefined; | ||
@@ -243,2 +244,3 @@ } | ||
| }; | ||
| caller?: AnthropicToolCallCaller; | ||
| cache_control: AnthropicCacheControl | undefined; | ||
@@ -390,2 +392,3 @@ } | ||
| }; | ||
| caller?: AnthropicToolCallCaller; | ||
| cache_control: AnthropicCacheControl | undefined; | ||
@@ -630,2 +633,16 @@ } | ||
| const anthropicToolCallCallerSchema = z.union([ | ||
| z.object({ | ||
| type: z.literal('code_execution_20250825'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('code_execution_20260120'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('direct'), | ||
| }), | ||
| ]); | ||
| // limited version of the schema, focussed on what is needed for the implementation | ||
@@ -693,17 +710,3 @@ // this approach limits breakages when the API changes and increases efficiency | ||
| // Programmatic tool calling: caller info when triggered from code execution | ||
| caller: z | ||
| .union([ | ||
| z.object({ | ||
| type: z.literal('code_execution_20250825'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('code_execution_20260120'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('direct'), | ||
| }), | ||
| ]) | ||
| .optional(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| }), | ||
@@ -715,13 +718,3 @@ z.object({ | ||
| input: z.record(z.string(), z.unknown()).nullish(), | ||
| caller: z | ||
| .union([ | ||
| z.object({ | ||
| type: z.literal('code_execution_20260120'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('direct'), | ||
| }), | ||
| ]) | ||
| .optional(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| }), | ||
@@ -749,2 +742,3 @@ z.object({ | ||
| tool_use_id: z.string(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| content: z.union([ | ||
@@ -782,2 +776,3 @@ z.object({ | ||
| tool_use_id: z.string(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| content: z.union([ | ||
@@ -1039,17 +1034,3 @@ z.array( | ||
| input: z.unknown(), | ||
| caller: z | ||
| .union([ | ||
| z.object({ | ||
| type: z.literal('code_execution_20250825'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('code_execution_20260120'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('direct'), | ||
| }), | ||
| ]) | ||
| .optional(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| }), | ||
@@ -1087,17 +1068,3 @@ ]), | ||
| // Programmatic tool calling: caller info when triggered from code execution | ||
| caller: z | ||
| .union([ | ||
| z.object({ | ||
| type: z.literal('code_execution_20250825'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('code_execution_20260120'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('direct'), | ||
| }), | ||
| ]) | ||
| .optional(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| }), | ||
@@ -1117,13 +1084,3 @@ z.object({ | ||
| input: z.record(z.string(), z.unknown()).nullish(), | ||
| caller: z | ||
| .union([ | ||
| z.object({ | ||
| type: z.literal('code_execution_20260120'), | ||
| tool_id: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('direct'), | ||
| }), | ||
| ]) | ||
| .optional(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| }), | ||
@@ -1151,2 +1108,3 @@ z.object({ | ||
| tool_use_id: z.string(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| content: z.union([ | ||
@@ -1184,2 +1142,3 @@ z.object({ | ||
| tool_use_id: z.string(), | ||
| caller: anthropicToolCallCallerSchema.optional(), | ||
| content: z.union([ | ||
@@ -1186,0 +1145,0 @@ z.array( |
@@ -26,2 +26,3 @@ import { | ||
| type AnthropicToolChangeContent, | ||
| type AnthropicToolCallCaller, | ||
| type AnthropicToolResultContent, | ||
@@ -649,2 +650,4 @@ type AnthropicUserMessage, | ||
| case 'tool-call': { | ||
| const caller = getAnthropicCaller(part.providerOptions); | ||
| if (part.providerExecuted) { | ||
@@ -696,2 +699,3 @@ const providerToolName = toolNameMapping.toProviderToolName( | ||
| input, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -717,2 +721,3 @@ }); | ||
| input: inputWithoutType, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -731,2 +736,3 @@ }); | ||
| input: part.input, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -743,2 +749,3 @@ }); | ||
| input: part.input, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -753,2 +760,3 @@ }); | ||
| input: {}, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -767,22 +775,2 @@ }); | ||
| // Extract caller info from provider options for programmatic tool calling | ||
| const callerOptions = part.providerOptions?.anthropic as | ||
| | { caller?: { type: string; toolId?: string } } | ||
| | undefined; | ||
| const caller = callerOptions?.caller | ||
| ? (callerOptions.caller.type === 'code_execution_20250825' || | ||
| callerOptions.caller.type === | ||
| 'code_execution_20260120') && | ||
| callerOptions.caller.toolId | ||
| ? { | ||
| type: callerOptions.caller.type as | ||
| | 'code_execution_20250825' | ||
| | 'code_execution_20260120', | ||
| tool_id: callerOptions.caller.toolId, | ||
| } | ||
| : callerOptions.caller.type === 'direct' | ||
| ? { type: 'direct' as const } | ||
| : undefined | ||
| : undefined; | ||
| anthropicContent.push({ | ||
@@ -803,2 +791,3 @@ type: 'tool_use', | ||
| ); | ||
| const caller = getAnthropicCaller(part.providerOptions); | ||
@@ -1010,2 +999,3 @@ if (mcpToolUseIds.has(part.toolCallId)) { | ||
| }, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -1055,2 +1045,3 @@ }); | ||
| }, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -1075,2 +1066,3 @@ }); | ||
| }, | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -1109,2 +1101,3 @@ }); | ||
| })), | ||
| ...(caller && { caller }), | ||
| cache_control: cacheControl, | ||
@@ -1335,1 +1328,24 @@ }); | ||
| } | ||
| function getAnthropicCaller( | ||
| providerOptions: SharedV3ProviderMetadata | undefined, | ||
| ): AnthropicToolCallCaller | undefined { | ||
| const caller = ( | ||
| providerOptions?.anthropic as | ||
| | { caller?: { type: string; toolId?: string } } | ||
| | undefined | ||
| )?.caller; | ||
| if ( | ||
| (caller?.type === 'code_execution_20250825' || | ||
| caller?.type === 'code_execution_20260120') && | ||
| caller.toolId | ||
| ) { | ||
| return { | ||
| type: caller.type, | ||
| tool_id: caller.toolId, | ||
| }; | ||
| } | ||
| return caller?.type === 'direct' ? { type: 'direct' } : undefined; | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
3353992
-0.08%35602
-0.19%+ Added
+ Added
- Removed
- Removed
- Removed