Sign In

@ai-sdk/anthropic

Package Overview
Dependencies
Maintainers
3
Versions
580
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/anthropic - npm Package Compare versions

Comparing version
4.0.38
to
4.0.39
+1
-1
package.json
{
"name": "@ai-sdk/anthropic",
"version": "4.0.38",
"version": "4.0.39",
"type": "module",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -192,2 +192,3 @@ import type { JSONSchema7 } from '@ai-sdk/provider';

input: unknown;
caller?: AnthropicToolCallCaller;
cache_control: AnthropicCacheControl | undefined;

@@ -254,2 +255,3 @@ }

};
caller?: AnthropicToolCallCaller;
cache_control: AnthropicCacheControl | undefined;

@@ -403,2 +405,3 @@ }

};
caller?: AnthropicToolCallCaller;
cache_control: AnthropicCacheControl | undefined;

@@ -644,2 +647,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

@@ -707,17 +724,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(),
}),

@@ -729,13 +732,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(),
}),

@@ -763,2 +756,3 @@ z.object({

tool_use_id: z.string(),
caller: anthropicToolCallCallerSchema.optional(),
content: z.union([

@@ -796,2 +790,3 @@ z.object({

tool_use_id: z.string(),
caller: anthropicToolCallCallerSchema.optional(),
content: z.union([

@@ -1055,17 +1050,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(),
}),

@@ -1103,17 +1084,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(),
}),

@@ -1133,13 +1100,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(),
}),

@@ -1167,2 +1124,3 @@ z.object({

tool_use_id: z.string(),
caller: anthropicToolCallCallerSchema.optional(),
content: z.union([

@@ -1200,2 +1158,3 @@ z.object({

tool_use_id: z.string(),
caller: anthropicToolCallCallerSchema.optional(),
content: z.union([

@@ -1202,0 +1161,0 @@ z.array(

@@ -29,2 +29,3 @@ import {

type AnthropicToolChangeContent,
type AnthropicToolCallCaller,
type AnthropicToolResultContent,

@@ -727,2 +728,4 @@ type AnthropicUserMessage,

case 'tool-call': {
const caller = getAnthropicCaller(part.providerOptions);
if (part.providerExecuted) {

@@ -776,2 +779,3 @@ const providerToolName = toolNameMapping.toProviderToolName(

input: inputWithoutType,
...(caller && { caller }),
cache_control: cacheControl,

@@ -797,2 +801,3 @@ });

input: inputWithoutType,
...(caller && { caller }),
cache_control: cacheControl,

@@ -811,2 +816,3 @@ });

input: part.input,
...(caller && { caller }),
cache_control: cacheControl,

@@ -823,2 +829,3 @@ });

input: part.input,
...(caller && { caller }),
cache_control: cacheControl,

@@ -833,2 +840,3 @@ });

input: {},
...(caller && { caller }),
cache_control: cacheControl,

@@ -847,22 +855,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({

@@ -883,2 +871,3 @@ type: 'tool_use',

);
const caller = getAnthropicCaller(part.providerOptions);

@@ -1090,2 +1079,3 @@ if (mcpToolUseIds.has(part.toolCallId)) {

},
...(caller && { caller }),
cache_control: cacheControl,

@@ -1135,2 +1125,3 @@ });

},
...(caller && { caller }),
cache_control: cacheControl,

@@ -1155,2 +1146,3 @@ });

},
...(caller && { caller }),
cache_control: cacheControl,

@@ -1189,2 +1181,3 @@ });

})),
...(caller && { caller }),
cache_control: cacheControl,

@@ -1422,2 +1415,25 @@ });

function getAnthropicCaller(
providerOptions: SharedV4ProviderMetadata | 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;
}
// wrap invalid tool call input because Anthropic requires it to be an object

@@ -1424,0 +1440,0 @@ function toAnthropicToolInput(input: unknown): JSONObject {

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