@ai-sdk/anthropic 4.0.97 → 4.0.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -43
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +276 -9
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +184 -43
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +205 -1
- package/package.json +1 -1
- package/src/anthropic-api.ts +19 -6
- package/src/anthropic-batch.ts +6 -0
- package/src/anthropic-error.ts +7 -0
- package/src/anthropic-language-model-options.ts +46 -5
- package/src/anthropic-language-model.ts +106 -12
- package/src/anthropic-model-catalog.ts +4 -0
- package/src/anthropic-prepare-tools.ts +21 -9
- package/src/anthropic-provider.ts +1 -0
- package/src/convert-to-anthropic-prompt.ts +136 -2
- package/src/get-cache-control.ts +6 -1
- package/src/internal/index.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.98
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 067dd77: Refactor Amazon Bedrock model ID logic into a model catalog that declares capabilities and provider options, and generate provider capability documentation from it. Export the Anthropic catalog capability helper under its compatibility name for Bedrock to reuse. Request behavior is unchanged.
|
|
8
|
+
- 25240d9: Refactor Anthropic AWS model ID logic into a model catalog that declares capabilities and provider options, and generate provider capability documentation from it. Export Anthropic catalog metadata internally for Anthropic AWS to reuse. Request behavior is unchanged.
|
|
9
|
+
- 457dc40: feat(anthropic): support adding tools by value in mid-conversation `toolChanges` (`inline-tools-2026-09-15`)
|
|
10
|
+
- 6b101ac: Add support for creating and continuing Anthropic message threads, including automatic beta headers and thread error details for application-managed recovery.
|
|
11
|
+
|
|
3
12
|
## 4.0.97
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -581,6 +581,20 @@ declare const anthropicSystemMessageProviderOptions: import("@ai-sdk/provider-ut
|
|
|
581
581
|
toolChanges?: ({
|
|
582
582
|
type: "tool_addition";
|
|
583
583
|
toolName: string;
|
|
584
|
+
} | {
|
|
585
|
+
type: "tool_addition";
|
|
586
|
+
tool: {
|
|
587
|
+
[x: string]: unknown;
|
|
588
|
+
type: "function";
|
|
589
|
+
name: string;
|
|
590
|
+
inputSchema: Record<string, unknown>;
|
|
591
|
+
} | {
|
|
592
|
+
[x: string]: unknown;
|
|
593
|
+
type: "provider";
|
|
594
|
+
id: string;
|
|
595
|
+
name: string;
|
|
596
|
+
args: Record<string, unknown>;
|
|
597
|
+
};
|
|
584
598
|
} | {
|
|
585
599
|
type: "tool_removal";
|
|
586
600
|
toolName: string;
|
|
@@ -588,6 +602,12 @@ declare const anthropicSystemMessageProviderOptions: import("@ai-sdk/provider-ut
|
|
|
588
602
|
}>;
|
|
589
603
|
type AnthropicSystemMessageProviderOptions = InferSchema<typeof anthropicSystemMessageProviderOptions>;
|
|
590
604
|
declare const anthropicLanguageModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
605
|
+
thread?: {
|
|
606
|
+
type: "create";
|
|
607
|
+
} | {
|
|
608
|
+
type: "continue";
|
|
609
|
+
previousMessageId: string;
|
|
610
|
+
} | undefined;
|
|
591
611
|
sendReasoning?: boolean | undefined;
|
|
592
612
|
structuredOutputMode?: "outputFormat" | "jsonTool" | "auto" | undefined;
|
|
593
613
|
includePings?: boolean | undefined;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member","DecisionModelV4","BatchV4"],"sources":["../src/anthropic-api.ts","../src/anthropic-message-metadata.ts","../src/anthropic-provider-metadata.ts","../src/anthropic-language-model-options.ts","../src/anthropic-prepare-tools.ts","../src/tool/computer-toolset_20260801.ts","../src/tool/bash_20241022.ts","../src/tool/bash_20250124.ts","../src/anthropic-tools.ts","../src/anthropic-provider.ts","../src/forward-anthropic-container-id-from-last-step.ts","../src/version.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","_$__tool_computer_toolset_202608010.ComputerToolset_20260801Member","DecisionModelV4","BatchV4"],"sources":["../src/anthropic-api.ts","../src/anthropic-message-metadata.ts","../src/anthropic-provider-metadata.ts","../src/anthropic-language-model-options.ts","../src/anthropic-prepare-tools.ts","../src/tool/computer-toolset_20260801.ts","../src/tool/bash_20241022.ts","../src/tool/bash_20250124.ts","../src/anthropic-tools.ts","../src/anthropic-provider.ts","../src/forward-anthropic-container-id-from-last-step.ts","../src/version.ts"],"mappings":";;;;cAgtBM,sCAA8B,EAAA;;;;;;;;;;GAgBhC,EAAA,KAAA;KAEQ,2BAA2B,EAAE,MACvC,kBAAkB;cA2FP,0DAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqwBxB,WAAW,aACpB,mBAAmB;EAClB;;;;;;;;;;;;;;;;;;;KCnjDQ;EACV;;;;;;EAOA;;;;EAKA;;;;EAKA;;;;EAKA;;;;EAKA;;UAGe;EACf,OAAO;EACP;;EAGA;;;;;;;EAQA,uBA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D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAQP;MACF;MACJ;MAEwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAJlB;MACF;MACJ;MAEwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAHxB;MACA;MAEa;MACK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCFJ,0BAA0B;;;;GAIxC,SAAS,mBAAmB;;;;EAK7B,cAAc,SAAS,mBAAmB;EAE1C,KAAK,SAAS,mBAAmB;EAEjC,SAAS,SAAS,mBAAmB;;EAGrC,cAAc,SAAS,mBAAmBE;;EAE1C,gBAAgB,SAAS,mBAAmBA;IAC1C,YAAYA;;EAGd,sBAAsBC;IAAU,MAAM;;;;;EAKtC,mBAAmB;EAEnB,SAAS;;;;EAKT,UAAU;;;;EAKV,cAAc;;UAGC;;EAEf;;IAEE;;;;;;EAOF;;;;;;EAOA;;;;;;;EAQA,YAAY;;;;EAKZ,UAAU;;;;;EAMV,QAAQ;EAER;;;;;EAMA;;;;;wBAMc,gBACd,UAAS,4BACR;;;;qBAuIU,WAAS;;;;;;;;;;wBCvQN,0CACd;EAEA,OAAO;IACL,mBAAmB,eAAe;;;EAEpB,kBAAkB,eAAe;;;;qBCdtC"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,11 @@ const anthropicErrorDataSchema = lazySchema(() => zodSchema(z.object({
|
|
|
7
7
|
type: z.literal("error"),
|
|
8
8
|
error: z.object({
|
|
9
9
|
type: z.string(),
|
|
10
|
-
message: z.string()
|
|
10
|
+
message: z.string(),
|
|
11
|
+
details: z.object({
|
|
12
|
+
error_code: z.string().nullish().catch(void 0),
|
|
13
|
+
unsupported: z.array(z.string()).nullish().catch(void 0)
|
|
14
|
+
}).nullish().catch(void 0)
|
|
11
15
|
})
|
|
12
16
|
})));
|
|
13
17
|
const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -151,6 +155,7 @@ var AnthropicFiles = class {
|
|
|
151
155
|
* keeps this list in sync with the option schema.
|
|
152
156
|
*/
|
|
153
157
|
const anthropicProviderOptions = { language: {
|
|
158
|
+
thread: { description: "Create or continue a short-lived message thread." },
|
|
154
159
|
sendReasoning: { description: "Whether to send reasoning to the model." },
|
|
155
160
|
includePings: { description: "Include transient ping events in streams." },
|
|
156
161
|
structuredOutputMode: { description: "How structured outputs are generated." },
|
|
@@ -1260,20 +1265,55 @@ const anthropicSystemMessageProviderOptions = lazySchema(() => zodSchema(z.objec
|
|
|
1260
1265
|
* initial system prompt). A system message carrying tool changes must come
|
|
1261
1266
|
* right before an assistant message or at the end of the messages.
|
|
1262
1267
|
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
* the
|
|
1266
|
-
* `
|
|
1268
|
+
* A `tool_addition` either references a tool by `toolName` or defines it
|
|
1269
|
+
* by value with `tool`:
|
|
1270
|
+
* - By reference: the tool must be declared in the `tools` option
|
|
1271
|
+
* (typically with `deferLoading: true` so it is not loaded until the
|
|
1272
|
+
* addition surfaces it). The required
|
|
1273
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added
|
|
1274
|
+
* automatically.
|
|
1275
|
+
* - By value: `tool` is a function or provider tool, in the same shape as
|
|
1276
|
+
* an entry of the `tools` option. The tool does not need to be declared
|
|
1277
|
+
* in `tools`, and defining a tool under an existing name replaces it
|
|
1278
|
+
* from that point on. The required `inline-tools-2026-09-15` beta is
|
|
1279
|
+
* added automatically.
|
|
1280
|
+
*
|
|
1281
|
+
* A `tool_removal` always references the tool by `toolName`.
|
|
1267
1282
|
*/
|
|
1268
|
-
toolChanges: z.array(z.
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1283
|
+
toolChanges: z.array(z.union([
|
|
1284
|
+
z.object({
|
|
1285
|
+
type: z.literal("tool_addition"),
|
|
1286
|
+
toolName: z.string()
|
|
1287
|
+
}),
|
|
1288
|
+
z.object({
|
|
1289
|
+
type: z.literal("tool_addition"),
|
|
1290
|
+
tool: z.union([z.looseObject({
|
|
1291
|
+
type: z.literal("function"),
|
|
1292
|
+
name: z.string(),
|
|
1293
|
+
inputSchema: z.record(z.string(), z.unknown())
|
|
1294
|
+
}), z.looseObject({
|
|
1295
|
+
type: z.literal("provider"),
|
|
1296
|
+
id: z.string(),
|
|
1297
|
+
name: z.string(),
|
|
1298
|
+
args: z.record(z.string(), z.unknown())
|
|
1299
|
+
})])
|
|
1300
|
+
}),
|
|
1301
|
+
z.object({
|
|
1302
|
+
type: z.literal("tool_removal"),
|
|
1303
|
+
toolName: z.string()
|
|
1304
|
+
})
|
|
1305
|
+
])).optional()
|
|
1275
1306
|
})));
|
|
1276
1307
|
const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
1308
|
+
/**
|
|
1309
|
+
* Create or continue a short-lived server-side message thread.
|
|
1310
|
+
* On continuation, messages must contain only new messages. Keep the full
|
|
1311
|
+
* conversation locally so it can be replayed when the thread expires.
|
|
1312
|
+
*/
|
|
1313
|
+
thread: z.discriminatedUnion("type", [z.object({ type: z.literal("create") }), z.object({
|
|
1314
|
+
type: z.literal("continue"),
|
|
1315
|
+
previousMessageId: z.string().min(1)
|
|
1316
|
+
})]).optional(),
|
|
1277
1317
|
/**
|
|
1278
1318
|
* Whether to send reasoning to the model.
|
|
1279
1319
|
*
|
|
@@ -1565,10 +1605,11 @@ function getCacheControl(providerMetadata, providerOptionsName) {
|
|
|
1565
1605
|
return custom?.cacheControl ?? custom?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1566
1606
|
}
|
|
1567
1607
|
var CacheControlValidator = class {
|
|
1568
|
-
constructor(providerOptionsName = "anthropic") {
|
|
1608
|
+
constructor(providerOptionsName = "anthropic", initialBreakpointCount = 0) {
|
|
1569
1609
|
this.providerOptionsName = providerOptionsName;
|
|
1570
1610
|
this.breakpointCount = 0;
|
|
1571
1611
|
this.warnings = [];
|
|
1612
|
+
this.breakpointCount = initialBreakpointCount;
|
|
1572
1613
|
}
|
|
1573
1614
|
getCacheControl(providerMetadata, context) {
|
|
1574
1615
|
const cacheControlValue = getCacheControl(providerMetadata, this.providerOptionsName);
|
|
@@ -1925,19 +1966,19 @@ const webFetch_20250910 = (args = {}) => {
|
|
|
1925
1966
|
};
|
|
1926
1967
|
//#endregion
|
|
1927
1968
|
//#region src/anthropic-prepare-tools.ts
|
|
1928
|
-
async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false, rejectsForcedToolUse = false }) {
|
|
1969
|
+
async function prepareTools({ tools, toolChoice, hasInlineTools = false, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false, rejectsForcedToolUse = false }) {
|
|
1929
1970
|
tools = tools?.length ? tools : void 0;
|
|
1930
1971
|
const toolWarnings = [];
|
|
1931
1972
|
const betas = /* @__PURE__ */ new Set();
|
|
1932
1973
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1933
|
-
if (tools == null) return {
|
|
1974
|
+
if (tools == null && !hasInlineTools) return {
|
|
1934
1975
|
tools: void 0,
|
|
1935
1976
|
toolChoice: void 0,
|
|
1936
1977
|
toolWarnings,
|
|
1937
1978
|
betas
|
|
1938
1979
|
};
|
|
1939
1980
|
const anthropicTools = [];
|
|
1940
|
-
for (const tool of tools) switch (tool.type) {
|
|
1981
|
+
for (const tool of tools ?? []) switch (tool.type) {
|
|
1941
1982
|
case "function": {
|
|
1942
1983
|
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
1943
1984
|
type: "tool definition",
|
|
@@ -2244,8 +2285,9 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2244
2285
|
feature: `tool ${tool}`
|
|
2245
2286
|
});
|
|
2246
2287
|
}
|
|
2288
|
+
const declaredTools = tools == null ? void 0 : anthropicTools;
|
|
2247
2289
|
if (toolChoice == null) return {
|
|
2248
|
-
tools:
|
|
2290
|
+
tools: declaredTools,
|
|
2249
2291
|
toolChoice: disableParallelToolUse ? {
|
|
2250
2292
|
type: "auto",
|
|
2251
2293
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2256,7 +2298,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2256
2298
|
const type = toolChoice.type;
|
|
2257
2299
|
switch (type) {
|
|
2258
2300
|
case "auto": return {
|
|
2259
|
-
tools:
|
|
2301
|
+
tools: declaredTools,
|
|
2260
2302
|
toolChoice: {
|
|
2261
2303
|
type: "auto",
|
|
2262
2304
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2272,7 +2314,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2272
2314
|
details: "toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."
|
|
2273
2315
|
});
|
|
2274
2316
|
return {
|
|
2275
|
-
tools:
|
|
2317
|
+
tools: declaredTools,
|
|
2276
2318
|
toolChoice: {
|
|
2277
2319
|
type: "auto",
|
|
2278
2320
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2282,7 +2324,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2282
2324
|
};
|
|
2283
2325
|
}
|
|
2284
2326
|
return {
|
|
2285
|
-
tools:
|
|
2327
|
+
tools: declaredTools,
|
|
2286
2328
|
toolChoice: {
|
|
2287
2329
|
type: "any",
|
|
2288
2330
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2291,7 +2333,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2291
2333
|
betas
|
|
2292
2334
|
};
|
|
2293
2335
|
case "none": return {
|
|
2294
|
-
tools:
|
|
2336
|
+
tools: declaredTools,
|
|
2295
2337
|
toolChoice: { type: "none" },
|
|
2296
2338
|
toolWarnings,
|
|
2297
2339
|
betas
|
|
@@ -2304,7 +2346,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2304
2346
|
details: `toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
|
|
2305
2347
|
});
|
|
2306
2348
|
return {
|
|
2307
|
-
tools:
|
|
2349
|
+
tools: declaredTools?.filter((tool) => "name" in tool && tool.name === toolChoice.toolName),
|
|
2308
2350
|
toolChoice: {
|
|
2309
2351
|
type: "auto",
|
|
2310
2352
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2314,7 +2356,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2314
2356
|
};
|
|
2315
2357
|
}
|
|
2316
2358
|
return {
|
|
2317
|
-
tools:
|
|
2359
|
+
tools: declaredTools,
|
|
2318
2360
|
toolChoice: {
|
|
2319
2361
|
type: "tool",
|
|
2320
2362
|
name: toolChoice.toolName,
|
|
@@ -2692,7 +2734,31 @@ function extractErrorValue(value) {
|
|
|
2692
2734
|
}
|
|
2693
2735
|
return {};
|
|
2694
2736
|
}
|
|
2695
|
-
|
|
2737
|
+
function isComputerTool(tool) {
|
|
2738
|
+
return tool.type === "provider" && tool.id.startsWith("anthropic.computer_");
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* Collects the tools that mid-conversation tool changes add by value, so they
|
|
2742
|
+
* can take part in tool name mapping like the tools of the `tools` option.
|
|
2743
|
+
* Tools that cannot be added by value are left out because they are ignored.
|
|
2744
|
+
*/
|
|
2745
|
+
async function getInlineToolsFromPrompt(prompt) {
|
|
2746
|
+
const inlineTools = [];
|
|
2747
|
+
for (const message of prompt) {
|
|
2748
|
+
if (message.role !== "system" || message.providerOptions == null) continue;
|
|
2749
|
+
const options = await parseProviderOptions({
|
|
2750
|
+
provider: "anthropic",
|
|
2751
|
+
providerOptions: message.providerOptions,
|
|
2752
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2753
|
+
});
|
|
2754
|
+
for (const toolChange of options?.toolChanges ?? []) if ("tool" in toolChange) {
|
|
2755
|
+
const tool = toolChange.tool;
|
|
2756
|
+
if (!isComputerTool(tool)) inlineTools.push(tool);
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
return inlineTools;
|
|
2760
|
+
}
|
|
2761
|
+
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart, convertInlineTool }) {
|
|
2696
2762
|
const betas = /* @__PURE__ */ new Set();
|
|
2697
2763
|
const blocks = groupIntoBlocks(prompt);
|
|
2698
2764
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2747,18 +2813,50 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2747
2813
|
canCache: true
|
|
2748
2814
|
})
|
|
2749
2815
|
});
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2816
|
+
let toolChangeCount = 0;
|
|
2817
|
+
let hasInlineToolDefinition = false;
|
|
2818
|
+
for (const toolChange of toolChanges) {
|
|
2819
|
+
if ("tool" in toolChange) {
|
|
2820
|
+
if (convertInlineTool == null) throw new UnsupportedFunctionalityError({ functionality: "tool additions by value in mid-conversation tool changes" });
|
|
2821
|
+
const tool = toolChange.tool;
|
|
2822
|
+
if (isComputerTool(tool)) {
|
|
2823
|
+
warnings.push({
|
|
2824
|
+
type: "other",
|
|
2825
|
+
message: `The tool '${tool.name}' cannot be added by value in a tool change. Declare it in the tools option and add it by reference with toolName. The tool change has been ignored.`
|
|
2826
|
+
});
|
|
2827
|
+
continue;
|
|
2828
|
+
}
|
|
2829
|
+
const { definition, warnings: toolWarnings, betas: toolBetas } = await convertInlineTool(tool);
|
|
2830
|
+
warnings.push(...toolWarnings);
|
|
2831
|
+
for (const beta of toolBetas) betas.add(beta);
|
|
2832
|
+
if (definition == null) continue;
|
|
2833
|
+
content.push({
|
|
2834
|
+
type: "tool_addition",
|
|
2835
|
+
tool: {
|
|
2836
|
+
type: "tool_definition",
|
|
2837
|
+
definition
|
|
2838
|
+
}
|
|
2839
|
+
});
|
|
2840
|
+
toolChangeCount++;
|
|
2841
|
+
hasInlineToolDefinition = true;
|
|
2842
|
+
continue;
|
|
2755
2843
|
}
|
|
2756
|
-
|
|
2844
|
+
content.push({
|
|
2845
|
+
type: toolChange.type,
|
|
2846
|
+
tool: {
|
|
2847
|
+
type: "tool_reference",
|
|
2848
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2849
|
+
}
|
|
2850
|
+
});
|
|
2851
|
+
toolChangeCount++;
|
|
2852
|
+
}
|
|
2853
|
+
if (content.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) continue;
|
|
2757
2854
|
convertedMessages.push({
|
|
2758
2855
|
content,
|
|
2759
2856
|
clearAt: systemMessageOptions?.clearAt,
|
|
2760
2857
|
effort: systemMessageOptions?.effort,
|
|
2761
|
-
toolChangeCount
|
|
2858
|
+
toolChangeCount,
|
|
2859
|
+
hasInlineToolDefinition
|
|
2762
2860
|
});
|
|
2763
2861
|
}
|
|
2764
2862
|
const toolChangeCount = convertedMessages.reduce((count, message) => count + message.toolChangeCount, 0);
|
|
@@ -2789,7 +2887,8 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2789
2887
|
...message.clearAt != null && { clear_at: message.clearAt },
|
|
2790
2888
|
...message.effort != null && { output_config: { effort: message.effort } }
|
|
2791
2889
|
});
|
|
2792
|
-
if (message.
|
|
2890
|
+
if (message.hasInlineToolDefinition) betas.add("inline-tools-2026-09-15");
|
|
2891
|
+
else if (message.toolChangeCount > 0) betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2793
2892
|
if (message.clearAt != null) betas.add("mid-conversation-system-clear-at-2026-08-21");
|
|
2794
2893
|
if (message.effort != null) betas.add("mid-conversation-output-config-2026-07-01");
|
|
2795
2894
|
}
|
|
@@ -4294,9 +4393,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4294
4393
|
argument: "providerOptions",
|
|
4295
4394
|
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
4296
4395
|
});
|
|
4297
|
-
const
|
|
4396
|
+
const thread = anthropicOptions?.thread;
|
|
4397
|
+
if (thread != null && config.supportsMessageThreads !== true) throw new UnsupportedFunctionalityError({
|
|
4398
|
+
functionality: "Anthropic message threads",
|
|
4399
|
+
message: `${config.provider} does not support Anthropic message threads.`
|
|
4400
|
+
});
|
|
4401
|
+
if (thread != null && (compaction != null || contextManagement?.edits.some((edit) => edit.type !== "clear_thinking_20251015" || edit.keep !== "all"))) throw new InvalidArgumentError({
|
|
4402
|
+
argument: "providerOptions.anthropic.thread",
|
|
4403
|
+
message: "Anthropic message threads do not support compaction or context editing, except clear_thinking_20251015 with keep: \"all\"."
|
|
4404
|
+
});
|
|
4405
|
+
const cacheControlValidator = new CacheControlValidator(config.cacheControlProviderOptionsName, thread != null && anthropicOptions?.cacheControl != null ? 1 : 0);
|
|
4406
|
+
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4407
|
+
const inlineTools = await getInlineToolsFromPrompt(prompt);
|
|
4298
4408
|
const toolNameMapping = createToolNameMapping({
|
|
4299
|
-
tools,
|
|
4409
|
+
tools: [...inlineTools, ...tools ?? []],
|
|
4300
4410
|
providerToolNames: {
|
|
4301
4411
|
"anthropic.code_execution_20250522": "code_execution",
|
|
4302
4412
|
"anthropic.code_execution_20250825": "code_execution",
|
|
@@ -4331,8 +4441,35 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4331
4441
|
cacheControlValidator,
|
|
4332
4442
|
toolNameMapping,
|
|
4333
4443
|
toolsetNames,
|
|
4334
|
-
convertMediaPart: config.convertMediaPart
|
|
4444
|
+
convertMediaPart: config.convertMediaPart,
|
|
4445
|
+
convertInlineTool: async (tool) => {
|
|
4446
|
+
const { tools: definitions, toolWarnings, betas } = await prepareTools({
|
|
4447
|
+
tools: [tool],
|
|
4448
|
+
toolChoice: void 0,
|
|
4449
|
+
cacheControlValidator,
|
|
4450
|
+
supportsStructuredOutput,
|
|
4451
|
+
supportsStrictTools
|
|
4452
|
+
});
|
|
4453
|
+
return {
|
|
4454
|
+
definition: definitions?.[0],
|
|
4455
|
+
warnings: toolWarnings,
|
|
4456
|
+
betas
|
|
4457
|
+
};
|
|
4458
|
+
}
|
|
4335
4459
|
});
|
|
4460
|
+
if (thread != null) {
|
|
4461
|
+
const unpinnedBetas = [...betas].filter((beta) => !userSuppliedBetas.has(beta) && !anthropicOptions?.anthropicBeta?.includes(beta));
|
|
4462
|
+
if (unpinnedBetas.length > 0) warnings.push({
|
|
4463
|
+
type: "compatibility",
|
|
4464
|
+
feature: "providerOptions.anthropic.thread",
|
|
4465
|
+
details: `Message content enabled beta headers: ${unpinnedBetas.join(", ")}. Thread requests require the same beta set on every turn. Pin these values with anthropicBeta on every request, or start a new thread when the set changes.`
|
|
4466
|
+
});
|
|
4467
|
+
if (thread.type === "continue" && (messagesPrompt.system != null || (tools?.length ?? 0) > 0)) warnings.push({
|
|
4468
|
+
type: "compatibility",
|
|
4469
|
+
feature: "providerOptions.anthropic.thread",
|
|
4470
|
+
details: "Continuation uses the system prompt and tool definitions stored by the create request; supplied definitions are omitted from the wire request. Supply identical tools for local tool handling and fixed request settings. To change system instructions or tools, start a new thread."
|
|
4471
|
+
});
|
|
4472
|
+
}
|
|
4336
4473
|
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
4337
4474
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
4338
4475
|
reasoning,
|
|
@@ -4450,7 +4587,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4450
4587
|
version: skill.version
|
|
4451
4588
|
}))
|
|
4452
4589
|
} : anthropicOptions.container.id },
|
|
4453
|
-
system: messagesPrompt.system,
|
|
4590
|
+
system: thread?.type === "continue" ? void 0 : messagesPrompt.system,
|
|
4591
|
+
...thread != null && { thread: thread.type === "create" ? { type: "create" } : {
|
|
4592
|
+
type: "continue",
|
|
4593
|
+
previous_message_id: thread.previousMessageId
|
|
4594
|
+
} },
|
|
4454
4595
|
messages: messagesPrompt.messages,
|
|
4455
4596
|
...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && { safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4456
4597
|
type: safeguard.type,
|
|
@@ -4566,7 +4707,6 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4566
4707
|
if (thinkingBlockBinding != null) betas.add("thinking-binding-controls-2026-08-01");
|
|
4567
4708
|
if (anthropicOptions?.fallbacks === "default") betas.add("server-side-fallback-2026-07-01");
|
|
4568
4709
|
else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) betas.add("server-side-fallback-2026-06-01");
|
|
4569
|
-
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4570
4710
|
const { tools: anthropicTools, toolChoice: anthropicToolChoice, toolWarnings, betas: toolsBetas } = await prepareTools(jsonResponseTool != null ? {
|
|
4571
4711
|
tools: [...(tools ?? []).filter((tool) => toolChoice?.type !== "none" && (toolChoice?.type !== "tool" || tool.name === toolChoice.toolName)), jsonResponseTool],
|
|
4572
4712
|
toolChoice: { type: "required" },
|
|
@@ -4579,6 +4719,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4579
4719
|
} : {
|
|
4580
4720
|
tools: tools ?? [],
|
|
4581
4721
|
toolChoice,
|
|
4722
|
+
hasInlineTools: inlineTools.length > 0,
|
|
4582
4723
|
disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
|
|
4583
4724
|
cacheControlValidator,
|
|
4584
4725
|
supportsStructuredOutput,
|
|
@@ -4590,7 +4731,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4590
4731
|
return {
|
|
4591
4732
|
args: {
|
|
4592
4733
|
...baseArgs,
|
|
4593
|
-
tools: anthropicTools,
|
|
4734
|
+
tools: thread?.type === "continue" ? void 0 : anthropicTools,
|
|
4594
4735
|
tool_choice: anthropicToolChoice,
|
|
4595
4736
|
stream: stream === true ? true : void 0
|
|
4596
4737
|
},
|
|
@@ -4600,11 +4741,13 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4600
4741
|
...cacheWarnings
|
|
4601
4742
|
],
|
|
4602
4743
|
betas: /* @__PURE__ */ new Set([
|
|
4744
|
+
...thread != null ? ["message-threads-2026-08-12"] : [],
|
|
4603
4745
|
...betas,
|
|
4604
4746
|
...toolsBetas,
|
|
4605
4747
|
...userSuppliedBetas,
|
|
4606
4748
|
...anthropicOptions?.anthropicBeta ?? []
|
|
4607
4749
|
]),
|
|
4750
|
+
markCodeExecutionDynamic: hasDynamicFilteringWebToolWithoutCodeExecution(anthropicTools),
|
|
4608
4751
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4609
4752
|
includePings: stream === true && anthropicOptions?.includePings === true,
|
|
4610
4753
|
toolNameMapping,
|
|
@@ -4651,13 +4794,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4651
4794
|
}
|
|
4652
4795
|
async doGenerate(options) {
|
|
4653
4796
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4654
|
-
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4797
|
+
const { args, warnings, betas, usesJsonResponseTool, markCodeExecutionDynamic, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4655
4798
|
...options,
|
|
4656
4799
|
stream: false,
|
|
4657
4800
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
4658
4801
|
});
|
|
4659
4802
|
const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
|
|
4660
|
-
const markCodeExecutionDynamic = hasDynamicFilteringWebToolWithoutCodeExecution(args.tools);
|
|
4661
4803
|
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
4662
4804
|
url: this.buildRequestUrl(false),
|
|
4663
4805
|
headers: await this.getHeaders({
|
|
@@ -5076,13 +5218,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5076
5218
|
async doStream(options) {
|
|
5077
5219
|
"use step";
|
|
5078
5220
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
5079
|
-
const { args: body, warnings, betas, usesJsonResponseTool, includePings, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
5221
|
+
const { args: body, warnings, betas, usesJsonResponseTool, markCodeExecutionDynamic, includePings, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
5080
5222
|
...options,
|
|
5081
5223
|
stream: true,
|
|
5082
5224
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
5083
5225
|
});
|
|
5084
5226
|
const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
|
|
5085
|
-
const markCodeExecutionDynamic = hasDynamicFilteringWebToolWithoutCodeExecution(body.tools);
|
|
5086
5227
|
const url = this.buildRequestUrl(true);
|
|
5087
5228
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
5088
5229
|
url,
|
|
@@ -6173,6 +6314,10 @@ var AnthropicBatch = class {
|
|
|
6173
6314
|
userSuppliedBetas: new Set(explicitBatchBetas)
|
|
6174
6315
|
}
|
|
6175
6316
|
});
|
|
6317
|
+
if (prepared.args.thread != null) throw new UnsupportedFunctionalityError({
|
|
6318
|
+
functionality: "message threads in batches",
|
|
6319
|
+
message: `Anthropic Message Batches do not support message threads (request "${request.id}").`
|
|
6320
|
+
});
|
|
6176
6321
|
if (prepared.usesJsonResponseTool) throw new UnsupportedFunctionalityError({
|
|
6177
6322
|
functionality: "batch responseFormat JSON-tool fallback",
|
|
6178
6323
|
message: `Anthropic Message Batches cannot decode the JSON-tool structured-output fallback (request "${request.id}") because batch results are retrieved independently of the start call. Use a model that supports native output_format structured outputs.`
|
|
@@ -7470,7 +7615,7 @@ var AnthropicSkills = class {
|
|
|
7470
7615
|
};
|
|
7471
7616
|
//#endregion
|
|
7472
7617
|
//#region src/version.ts
|
|
7473
|
-
const VERSION = "4.0.
|
|
7618
|
+
const VERSION = "4.0.98";
|
|
7474
7619
|
//#endregion
|
|
7475
7620
|
//#region src/anthropic-provider.ts
|
|
7476
7621
|
const ANTHROPIC_API_URL = "https://api.anthropic.com";
|
|
@@ -7516,6 +7661,7 @@ function createAnthropic(options = {}) {
|
|
|
7516
7661
|
};
|
|
7517
7662
|
const languageModelConfig = {
|
|
7518
7663
|
provider: providerName,
|
|
7664
|
+
supportsMessageThreads: true,
|
|
7519
7665
|
baseURL,
|
|
7520
7666
|
headers: getHeaders,
|
|
7521
7667
|
fetch: options.fetch,
|