@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/dist/internal/index.js
CHANGED
|
@@ -6,7 +6,11 @@ const anthropicErrorDataSchema = lazySchema(() => zodSchema(z.object({
|
|
|
6
6
|
type: z.literal("error"),
|
|
7
7
|
error: z.object({
|
|
8
8
|
type: z.string(),
|
|
9
|
-
message: z.string()
|
|
9
|
+
message: z.string(),
|
|
10
|
+
details: z.object({
|
|
11
|
+
error_code: z.string().nullish().catch(void 0),
|
|
12
|
+
unsupported: z.array(z.string()).nullish().catch(void 0)
|
|
13
|
+
}).nullish().catch(void 0)
|
|
10
14
|
})
|
|
11
15
|
})));
|
|
12
16
|
const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -150,6 +154,7 @@ var AnthropicFiles = class {
|
|
|
150
154
|
* keeps this list in sync with the option schema.
|
|
151
155
|
*/
|
|
152
156
|
const anthropicProviderOptions = { language: {
|
|
157
|
+
thread: { description: "Create or continue a short-lived message thread." },
|
|
153
158
|
sendReasoning: { description: "Whether to send reasoning to the model." },
|
|
154
159
|
includePings: { description: "Include transient ping events in streams." },
|
|
155
160
|
structuredOutputMode: { description: "How structured outputs are generated." },
|
|
@@ -1259,20 +1264,55 @@ const anthropicSystemMessageProviderOptions = lazySchema(() => zodSchema(z.objec
|
|
|
1259
1264
|
* initial system prompt). A system message carrying tool changes must come
|
|
1260
1265
|
* right before an assistant message or at the end of the messages.
|
|
1261
1266
|
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
* the
|
|
1265
|
-
* `
|
|
1267
|
+
* A `tool_addition` either references a tool by `toolName` or defines it
|
|
1268
|
+
* by value with `tool`:
|
|
1269
|
+
* - By reference: the tool must be declared in the `tools` option
|
|
1270
|
+
* (typically with `deferLoading: true` so it is not loaded until the
|
|
1271
|
+
* addition surfaces it). The required
|
|
1272
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added
|
|
1273
|
+
* automatically.
|
|
1274
|
+
* - By value: `tool` is a function or provider tool, in the same shape as
|
|
1275
|
+
* an entry of the `tools` option. The tool does not need to be declared
|
|
1276
|
+
* in `tools`, and defining a tool under an existing name replaces it
|
|
1277
|
+
* from that point on. The required `inline-tools-2026-09-15` beta is
|
|
1278
|
+
* added automatically.
|
|
1279
|
+
*
|
|
1280
|
+
* A `tool_removal` always references the tool by `toolName`.
|
|
1266
1281
|
*/
|
|
1267
|
-
toolChanges: z.array(z.
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1282
|
+
toolChanges: z.array(z.union([
|
|
1283
|
+
z.object({
|
|
1284
|
+
type: z.literal("tool_addition"),
|
|
1285
|
+
toolName: z.string()
|
|
1286
|
+
}),
|
|
1287
|
+
z.object({
|
|
1288
|
+
type: z.literal("tool_addition"),
|
|
1289
|
+
tool: z.union([z.looseObject({
|
|
1290
|
+
type: z.literal("function"),
|
|
1291
|
+
name: z.string(),
|
|
1292
|
+
inputSchema: z.record(z.string(), z.unknown())
|
|
1293
|
+
}), z.looseObject({
|
|
1294
|
+
type: z.literal("provider"),
|
|
1295
|
+
id: z.string(),
|
|
1296
|
+
name: z.string(),
|
|
1297
|
+
args: z.record(z.string(), z.unknown())
|
|
1298
|
+
})])
|
|
1299
|
+
}),
|
|
1300
|
+
z.object({
|
|
1301
|
+
type: z.literal("tool_removal"),
|
|
1302
|
+
toolName: z.string()
|
|
1303
|
+
})
|
|
1304
|
+
])).optional()
|
|
1274
1305
|
})));
|
|
1275
1306
|
const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
1307
|
+
/**
|
|
1308
|
+
* Create or continue a short-lived server-side message thread.
|
|
1309
|
+
* On continuation, messages must contain only new messages. Keep the full
|
|
1310
|
+
* conversation locally so it can be replayed when the thread expires.
|
|
1311
|
+
*/
|
|
1312
|
+
thread: z.discriminatedUnion("type", [z.object({ type: z.literal("create") }), z.object({
|
|
1313
|
+
type: z.literal("continue"),
|
|
1314
|
+
previousMessageId: z.string().min(1)
|
|
1315
|
+
})]).optional(),
|
|
1276
1316
|
/**
|
|
1277
1317
|
* Whether to send reasoning to the model.
|
|
1278
1318
|
*
|
|
@@ -1564,10 +1604,11 @@ function getCacheControl(providerMetadata, providerOptionsName) {
|
|
|
1564
1604
|
return custom?.cacheControl ?? custom?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1565
1605
|
}
|
|
1566
1606
|
var CacheControlValidator = class {
|
|
1567
|
-
constructor(providerOptionsName = "anthropic") {
|
|
1607
|
+
constructor(providerOptionsName = "anthropic", initialBreakpointCount = 0) {
|
|
1568
1608
|
this.providerOptionsName = providerOptionsName;
|
|
1569
1609
|
this.breakpointCount = 0;
|
|
1570
1610
|
this.warnings = [];
|
|
1611
|
+
this.breakpointCount = initialBreakpointCount;
|
|
1571
1612
|
}
|
|
1572
1613
|
getCacheControl(providerMetadata, context) {
|
|
1573
1614
|
const cacheControlValue = getCacheControl(providerMetadata, this.providerOptionsName);
|
|
@@ -1924,19 +1965,19 @@ const webFetch_20250910 = (args = {}) => {
|
|
|
1924
1965
|
};
|
|
1925
1966
|
//#endregion
|
|
1926
1967
|
//#region src/anthropic-prepare-tools.ts
|
|
1927
|
-
async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false, rejectsForcedToolUse = false }) {
|
|
1968
|
+
async function prepareTools({ tools, toolChoice, hasInlineTools = false, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false, rejectsForcedToolUse = false }) {
|
|
1928
1969
|
tools = tools?.length ? tools : void 0;
|
|
1929
1970
|
const toolWarnings = [];
|
|
1930
1971
|
const betas = /* @__PURE__ */ new Set();
|
|
1931
1972
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1932
|
-
if (tools == null) return {
|
|
1973
|
+
if (tools == null && !hasInlineTools) return {
|
|
1933
1974
|
tools: void 0,
|
|
1934
1975
|
toolChoice: void 0,
|
|
1935
1976
|
toolWarnings,
|
|
1936
1977
|
betas
|
|
1937
1978
|
};
|
|
1938
1979
|
const anthropicTools = [];
|
|
1939
|
-
for (const tool of tools) switch (tool.type) {
|
|
1980
|
+
for (const tool of tools ?? []) switch (tool.type) {
|
|
1940
1981
|
case "function": {
|
|
1941
1982
|
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
1942
1983
|
type: "tool definition",
|
|
@@ -2243,8 +2284,9 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2243
2284
|
feature: `tool ${tool}`
|
|
2244
2285
|
});
|
|
2245
2286
|
}
|
|
2287
|
+
const declaredTools = tools == null ? void 0 : anthropicTools;
|
|
2246
2288
|
if (toolChoice == null) return {
|
|
2247
|
-
tools:
|
|
2289
|
+
tools: declaredTools,
|
|
2248
2290
|
toolChoice: disableParallelToolUse ? {
|
|
2249
2291
|
type: "auto",
|
|
2250
2292
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2255,7 +2297,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2255
2297
|
const type = toolChoice.type;
|
|
2256
2298
|
switch (type) {
|
|
2257
2299
|
case "auto": return {
|
|
2258
|
-
tools:
|
|
2300
|
+
tools: declaredTools,
|
|
2259
2301
|
toolChoice: {
|
|
2260
2302
|
type: "auto",
|
|
2261
2303
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2271,7 +2313,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2271
2313
|
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."
|
|
2272
2314
|
});
|
|
2273
2315
|
return {
|
|
2274
|
-
tools:
|
|
2316
|
+
tools: declaredTools,
|
|
2275
2317
|
toolChoice: {
|
|
2276
2318
|
type: "auto",
|
|
2277
2319
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2281,7 +2323,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2281
2323
|
};
|
|
2282
2324
|
}
|
|
2283
2325
|
return {
|
|
2284
|
-
tools:
|
|
2326
|
+
tools: declaredTools,
|
|
2285
2327
|
toolChoice: {
|
|
2286
2328
|
type: "any",
|
|
2287
2329
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2290,7 +2332,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2290
2332
|
betas
|
|
2291
2333
|
};
|
|
2292
2334
|
case "none": return {
|
|
2293
|
-
tools:
|
|
2335
|
+
tools: declaredTools,
|
|
2294
2336
|
toolChoice: { type: "none" },
|
|
2295
2337
|
toolWarnings,
|
|
2296
2338
|
betas
|
|
@@ -2303,7 +2345,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2303
2345
|
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.`
|
|
2304
2346
|
});
|
|
2305
2347
|
return {
|
|
2306
|
-
tools:
|
|
2348
|
+
tools: declaredTools?.filter((tool) => "name" in tool && tool.name === toolChoice.toolName),
|
|
2307
2349
|
toolChoice: {
|
|
2308
2350
|
type: "auto",
|
|
2309
2351
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2313,7 +2355,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2313
2355
|
};
|
|
2314
2356
|
}
|
|
2315
2357
|
return {
|
|
2316
|
-
tools:
|
|
2358
|
+
tools: declaredTools,
|
|
2317
2359
|
toolChoice: {
|
|
2318
2360
|
type: "tool",
|
|
2319
2361
|
name: toolChoice.toolName,
|
|
@@ -2691,7 +2733,31 @@ function extractErrorValue(value) {
|
|
|
2691
2733
|
}
|
|
2692
2734
|
return {};
|
|
2693
2735
|
}
|
|
2694
|
-
|
|
2736
|
+
function isComputerTool(tool) {
|
|
2737
|
+
return tool.type === "provider" && tool.id.startsWith("anthropic.computer_");
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Collects the tools that mid-conversation tool changes add by value, so they
|
|
2741
|
+
* can take part in tool name mapping like the tools of the `tools` option.
|
|
2742
|
+
* Tools that cannot be added by value are left out because they are ignored.
|
|
2743
|
+
*/
|
|
2744
|
+
async function getInlineToolsFromPrompt(prompt) {
|
|
2745
|
+
const inlineTools = [];
|
|
2746
|
+
for (const message of prompt) {
|
|
2747
|
+
if (message.role !== "system" || message.providerOptions == null) continue;
|
|
2748
|
+
const options = await parseProviderOptions({
|
|
2749
|
+
provider: "anthropic",
|
|
2750
|
+
providerOptions: message.providerOptions,
|
|
2751
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2752
|
+
});
|
|
2753
|
+
for (const toolChange of options?.toolChanges ?? []) if ("tool" in toolChange) {
|
|
2754
|
+
const tool = toolChange.tool;
|
|
2755
|
+
if (!isComputerTool(tool)) inlineTools.push(tool);
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
return inlineTools;
|
|
2759
|
+
}
|
|
2760
|
+
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart, convertInlineTool }) {
|
|
2695
2761
|
const betas = /* @__PURE__ */ new Set();
|
|
2696
2762
|
const blocks = groupIntoBlocks(prompt);
|
|
2697
2763
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2746,18 +2812,50 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2746
2812
|
canCache: true
|
|
2747
2813
|
})
|
|
2748
2814
|
});
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2815
|
+
let toolChangeCount = 0;
|
|
2816
|
+
let hasInlineToolDefinition = false;
|
|
2817
|
+
for (const toolChange of toolChanges) {
|
|
2818
|
+
if ("tool" in toolChange) {
|
|
2819
|
+
if (convertInlineTool == null) throw new UnsupportedFunctionalityError({ functionality: "tool additions by value in mid-conversation tool changes" });
|
|
2820
|
+
const tool = toolChange.tool;
|
|
2821
|
+
if (isComputerTool(tool)) {
|
|
2822
|
+
warnings.push({
|
|
2823
|
+
type: "other",
|
|
2824
|
+
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.`
|
|
2825
|
+
});
|
|
2826
|
+
continue;
|
|
2827
|
+
}
|
|
2828
|
+
const { definition, warnings: toolWarnings, betas: toolBetas } = await convertInlineTool(tool);
|
|
2829
|
+
warnings.push(...toolWarnings);
|
|
2830
|
+
for (const beta of toolBetas) betas.add(beta);
|
|
2831
|
+
if (definition == null) continue;
|
|
2832
|
+
content.push({
|
|
2833
|
+
type: "tool_addition",
|
|
2834
|
+
tool: {
|
|
2835
|
+
type: "tool_definition",
|
|
2836
|
+
definition
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
toolChangeCount++;
|
|
2840
|
+
hasInlineToolDefinition = true;
|
|
2841
|
+
continue;
|
|
2754
2842
|
}
|
|
2755
|
-
|
|
2843
|
+
content.push({
|
|
2844
|
+
type: toolChange.type,
|
|
2845
|
+
tool: {
|
|
2846
|
+
type: "tool_reference",
|
|
2847
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2848
|
+
}
|
|
2849
|
+
});
|
|
2850
|
+
toolChangeCount++;
|
|
2851
|
+
}
|
|
2852
|
+
if (content.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) continue;
|
|
2756
2853
|
convertedMessages.push({
|
|
2757
2854
|
content,
|
|
2758
2855
|
clearAt: systemMessageOptions?.clearAt,
|
|
2759
2856
|
effort: systemMessageOptions?.effort,
|
|
2760
|
-
toolChangeCount
|
|
2857
|
+
toolChangeCount,
|
|
2858
|
+
hasInlineToolDefinition
|
|
2761
2859
|
});
|
|
2762
2860
|
}
|
|
2763
2861
|
const toolChangeCount = convertedMessages.reduce((count, message) => count + message.toolChangeCount, 0);
|
|
@@ -2788,7 +2886,8 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2788
2886
|
...message.clearAt != null && { clear_at: message.clearAt },
|
|
2789
2887
|
...message.effort != null && { output_config: { effort: message.effort } }
|
|
2790
2888
|
});
|
|
2791
|
-
if (message.
|
|
2889
|
+
if (message.hasInlineToolDefinition) betas.add("inline-tools-2026-09-15");
|
|
2890
|
+
else if (message.toolChangeCount > 0) betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2792
2891
|
if (message.clearAt != null) betas.add("mid-conversation-system-clear-at-2026-08-21");
|
|
2793
2892
|
if (message.effort != null) betas.add("mid-conversation-output-config-2026-07-01");
|
|
2794
2893
|
}
|
|
@@ -4293,9 +4392,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4293
4392
|
argument: "providerOptions",
|
|
4294
4393
|
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
4295
4394
|
});
|
|
4296
|
-
const
|
|
4395
|
+
const thread = anthropicOptions?.thread;
|
|
4396
|
+
if (thread != null && config.supportsMessageThreads !== true) throw new UnsupportedFunctionalityError({
|
|
4397
|
+
functionality: "Anthropic message threads",
|
|
4398
|
+
message: `${config.provider} does not support Anthropic message threads.`
|
|
4399
|
+
});
|
|
4400
|
+
if (thread != null && (compaction != null || contextManagement?.edits.some((edit) => edit.type !== "clear_thinking_20251015" || edit.keep !== "all"))) throw new InvalidArgumentError({
|
|
4401
|
+
argument: "providerOptions.anthropic.thread",
|
|
4402
|
+
message: "Anthropic message threads do not support compaction or context editing, except clear_thinking_20251015 with keep: \"all\"."
|
|
4403
|
+
});
|
|
4404
|
+
const cacheControlValidator = new CacheControlValidator(config.cacheControlProviderOptionsName, thread != null && anthropicOptions?.cacheControl != null ? 1 : 0);
|
|
4405
|
+
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4406
|
+
const inlineTools = await getInlineToolsFromPrompt(prompt);
|
|
4297
4407
|
const toolNameMapping = createToolNameMapping({
|
|
4298
|
-
tools,
|
|
4408
|
+
tools: [...inlineTools, ...tools ?? []],
|
|
4299
4409
|
providerToolNames: {
|
|
4300
4410
|
"anthropic.code_execution_20250522": "code_execution",
|
|
4301
4411
|
"anthropic.code_execution_20250825": "code_execution",
|
|
@@ -4330,8 +4440,35 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4330
4440
|
cacheControlValidator,
|
|
4331
4441
|
toolNameMapping,
|
|
4332
4442
|
toolsetNames,
|
|
4333
|
-
convertMediaPart: config.convertMediaPart
|
|
4443
|
+
convertMediaPart: config.convertMediaPart,
|
|
4444
|
+
convertInlineTool: async (tool) => {
|
|
4445
|
+
const { tools: definitions, toolWarnings, betas } = await prepareTools({
|
|
4446
|
+
tools: [tool],
|
|
4447
|
+
toolChoice: void 0,
|
|
4448
|
+
cacheControlValidator,
|
|
4449
|
+
supportsStructuredOutput,
|
|
4450
|
+
supportsStrictTools
|
|
4451
|
+
});
|
|
4452
|
+
return {
|
|
4453
|
+
definition: definitions?.[0],
|
|
4454
|
+
warnings: toolWarnings,
|
|
4455
|
+
betas
|
|
4456
|
+
};
|
|
4457
|
+
}
|
|
4334
4458
|
});
|
|
4459
|
+
if (thread != null) {
|
|
4460
|
+
const unpinnedBetas = [...betas].filter((beta) => !userSuppliedBetas.has(beta) && !anthropicOptions?.anthropicBeta?.includes(beta));
|
|
4461
|
+
if (unpinnedBetas.length > 0) warnings.push({
|
|
4462
|
+
type: "compatibility",
|
|
4463
|
+
feature: "providerOptions.anthropic.thread",
|
|
4464
|
+
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.`
|
|
4465
|
+
});
|
|
4466
|
+
if (thread.type === "continue" && (messagesPrompt.system != null || (tools?.length ?? 0) > 0)) warnings.push({
|
|
4467
|
+
type: "compatibility",
|
|
4468
|
+
feature: "providerOptions.anthropic.thread",
|
|
4469
|
+
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."
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
4335
4472
|
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
4336
4473
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
4337
4474
|
reasoning,
|
|
@@ -4449,7 +4586,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4449
4586
|
version: skill.version
|
|
4450
4587
|
}))
|
|
4451
4588
|
} : anthropicOptions.container.id },
|
|
4452
|
-
system: messagesPrompt.system,
|
|
4589
|
+
system: thread?.type === "continue" ? void 0 : messagesPrompt.system,
|
|
4590
|
+
...thread != null && { thread: thread.type === "create" ? { type: "create" } : {
|
|
4591
|
+
type: "continue",
|
|
4592
|
+
previous_message_id: thread.previousMessageId
|
|
4593
|
+
} },
|
|
4453
4594
|
messages: messagesPrompt.messages,
|
|
4454
4595
|
...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && { safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4455
4596
|
type: safeguard.type,
|
|
@@ -4565,7 +4706,6 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4565
4706
|
if (thinkingBlockBinding != null) betas.add("thinking-binding-controls-2026-08-01");
|
|
4566
4707
|
if (anthropicOptions?.fallbacks === "default") betas.add("server-side-fallback-2026-07-01");
|
|
4567
4708
|
else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) betas.add("server-side-fallback-2026-06-01");
|
|
4568
|
-
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4569
4709
|
const { tools: anthropicTools, toolChoice: anthropicToolChoice, toolWarnings, betas: toolsBetas } = await prepareTools(jsonResponseTool != null ? {
|
|
4570
4710
|
tools: [...(tools ?? []).filter((tool) => toolChoice?.type !== "none" && (toolChoice?.type !== "tool" || tool.name === toolChoice.toolName)), jsonResponseTool],
|
|
4571
4711
|
toolChoice: { type: "required" },
|
|
@@ -4578,6 +4718,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4578
4718
|
} : {
|
|
4579
4719
|
tools: tools ?? [],
|
|
4580
4720
|
toolChoice,
|
|
4721
|
+
hasInlineTools: inlineTools.length > 0,
|
|
4581
4722
|
disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
|
|
4582
4723
|
cacheControlValidator,
|
|
4583
4724
|
supportsStructuredOutput,
|
|
@@ -4589,7 +4730,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4589
4730
|
return {
|
|
4590
4731
|
args: {
|
|
4591
4732
|
...baseArgs,
|
|
4592
|
-
tools: anthropicTools,
|
|
4733
|
+
tools: thread?.type === "continue" ? void 0 : anthropicTools,
|
|
4593
4734
|
tool_choice: anthropicToolChoice,
|
|
4594
4735
|
stream: stream === true ? true : void 0
|
|
4595
4736
|
},
|
|
@@ -4599,11 +4740,13 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4599
4740
|
...cacheWarnings
|
|
4600
4741
|
],
|
|
4601
4742
|
betas: /* @__PURE__ */ new Set([
|
|
4743
|
+
...thread != null ? ["message-threads-2026-08-12"] : [],
|
|
4602
4744
|
...betas,
|
|
4603
4745
|
...toolsBetas,
|
|
4604
4746
|
...userSuppliedBetas,
|
|
4605
4747
|
...anthropicOptions?.anthropicBeta ?? []
|
|
4606
4748
|
]),
|
|
4749
|
+
markCodeExecutionDynamic: hasDynamicFilteringWebToolWithoutCodeExecution(anthropicTools),
|
|
4607
4750
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4608
4751
|
includePings: stream === true && anthropicOptions?.includePings === true,
|
|
4609
4752
|
toolNameMapping,
|
|
@@ -4650,13 +4793,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4650
4793
|
}
|
|
4651
4794
|
async doGenerate(options) {
|
|
4652
4795
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4653
|
-
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4796
|
+
const { args, warnings, betas, usesJsonResponseTool, markCodeExecutionDynamic, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4654
4797
|
...options,
|
|
4655
4798
|
stream: false,
|
|
4656
4799
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
4657
4800
|
});
|
|
4658
4801
|
const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
|
|
4659
|
-
const markCodeExecutionDynamic = hasDynamicFilteringWebToolWithoutCodeExecution(args.tools);
|
|
4660
4802
|
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
4661
4803
|
url: this.buildRequestUrl(false),
|
|
4662
4804
|
headers: await this.getHeaders({
|
|
@@ -5075,13 +5217,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5075
5217
|
async doStream(options) {
|
|
5076
5218
|
"use step";
|
|
5077
5219
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
5078
|
-
const { args: body, warnings, betas, usesJsonResponseTool, includePings, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
5220
|
+
const { args: body, warnings, betas, usesJsonResponseTool, markCodeExecutionDynamic, includePings, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
5079
5221
|
...options,
|
|
5080
5222
|
stream: true,
|
|
5081
5223
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
5082
5224
|
});
|
|
5083
5225
|
const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
|
|
5084
|
-
const markCodeExecutionDynamic = hasDynamicFilteringWebToolWithoutCodeExecution(body.tools);
|
|
5085
5226
|
const url = this.buildRequestUrl(true);
|
|
5086
5227
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
5087
5228
|
url,
|
|
@@ -6736,6 +6877,6 @@ var AnthropicSkills = class {
|
|
|
6736
6877
|
}
|
|
6737
6878
|
};
|
|
6738
6879
|
//#endregion
|
|
6739
|
-
export { AnthropicFiles, AnthropicLanguageModel, AnthropicLanguageModel as AnthropicMessagesLanguageModel, AnthropicSkills, anthropicTools, getAnthropicModelCapabilities as getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
|
|
6880
|
+
export { AnthropicFiles, AnthropicLanguageModel, AnthropicLanguageModel as AnthropicMessagesLanguageModel, AnthropicSkills, anthropicModelCatalog, anthropicProviderOptions, anthropicTools, getAnthropicLanguageModelEntry, getAnthropicModelCapabilities as getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
|
|
6740
6881
|
|
|
6741
6882
|
//# sourceMappingURL=index.js.map
|