@ai-sdk/anthropic 3.0.0-beta.75 → 3.0.0-beta.77
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 +14 -0
- package/dist/index.d.mts +80 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +151 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +150 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +150 -5
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.0-beta.
|
|
14
|
+
var VERSION = true ? "3.0.0-beta.77" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -290,6 +290,22 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
290
290
|
version: z2.string()
|
|
291
291
|
})
|
|
292
292
|
).nullish()
|
|
293
|
+
}).nullish(),
|
|
294
|
+
context_management: z2.object({
|
|
295
|
+
applied_edits: z2.array(
|
|
296
|
+
z2.union([
|
|
297
|
+
z2.object({
|
|
298
|
+
type: z2.literal("clear_tool_uses_20250919"),
|
|
299
|
+
cleared_tool_uses: z2.number(),
|
|
300
|
+
cleared_input_tokens: z2.number()
|
|
301
|
+
}),
|
|
302
|
+
z2.object({
|
|
303
|
+
type: z2.literal("clear_thinking_20251015"),
|
|
304
|
+
cleared_thinking_turns: z2.number(),
|
|
305
|
+
cleared_input_tokens: z2.number()
|
|
306
|
+
})
|
|
307
|
+
])
|
|
308
|
+
)
|
|
293
309
|
}).nullish()
|
|
294
310
|
})
|
|
295
311
|
)
|
|
@@ -572,6 +588,22 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
572
588
|
version: z2.string()
|
|
573
589
|
})
|
|
574
590
|
).nullish()
|
|
591
|
+
}).nullish(),
|
|
592
|
+
context_management: z2.object({
|
|
593
|
+
applied_edits: z2.array(
|
|
594
|
+
z2.union([
|
|
595
|
+
z2.object({
|
|
596
|
+
type: z2.literal("clear_tool_uses_20250919"),
|
|
597
|
+
cleared_tool_uses: z2.number(),
|
|
598
|
+
cleared_input_tokens: z2.number()
|
|
599
|
+
}),
|
|
600
|
+
z2.object({
|
|
601
|
+
type: z2.literal("clear_thinking_20251015"),
|
|
602
|
+
cleared_thinking_turns: z2.number(),
|
|
603
|
+
cleared_input_tokens: z2.number()
|
|
604
|
+
})
|
|
605
|
+
])
|
|
606
|
+
)
|
|
575
607
|
}).nullish()
|
|
576
608
|
}),
|
|
577
609
|
usage: z2.looseObject({
|
|
@@ -702,7 +734,46 @@ var anthropicProviderOptions = z3.object({
|
|
|
702
734
|
/**
|
|
703
735
|
* @default 'high'
|
|
704
736
|
*/
|
|
705
|
-
effort: z3.enum(["low", "medium", "high"]).optional()
|
|
737
|
+
effort: z3.enum(["low", "medium", "high"]).optional(),
|
|
738
|
+
contextManagement: z3.object({
|
|
739
|
+
edits: z3.array(
|
|
740
|
+
z3.discriminatedUnion("type", [
|
|
741
|
+
z3.object({
|
|
742
|
+
type: z3.literal("clear_tool_uses_20250919"),
|
|
743
|
+
trigger: z3.discriminatedUnion("type", [
|
|
744
|
+
z3.object({
|
|
745
|
+
type: z3.literal("input_tokens"),
|
|
746
|
+
value: z3.number()
|
|
747
|
+
}),
|
|
748
|
+
z3.object({
|
|
749
|
+
type: z3.literal("tool_uses"),
|
|
750
|
+
value: z3.number()
|
|
751
|
+
})
|
|
752
|
+
]).optional(),
|
|
753
|
+
keep: z3.object({
|
|
754
|
+
type: z3.literal("tool_uses"),
|
|
755
|
+
value: z3.number()
|
|
756
|
+
}).optional(),
|
|
757
|
+
clearAtLeast: z3.object({
|
|
758
|
+
type: z3.literal("input_tokens"),
|
|
759
|
+
value: z3.number()
|
|
760
|
+
}).optional(),
|
|
761
|
+
clearToolInputs: z3.boolean().optional(),
|
|
762
|
+
excludeTools: z3.array(z3.string()).optional()
|
|
763
|
+
}),
|
|
764
|
+
z3.object({
|
|
765
|
+
type: z3.literal("clear_thinking_20251015"),
|
|
766
|
+
keep: z3.union([
|
|
767
|
+
z3.literal("all"),
|
|
768
|
+
z3.object({
|
|
769
|
+
type: z3.literal("thinking_turns"),
|
|
770
|
+
value: z3.number()
|
|
771
|
+
})
|
|
772
|
+
]).optional()
|
|
773
|
+
})
|
|
774
|
+
])
|
|
775
|
+
)
|
|
776
|
+
}).optional()
|
|
706
777
|
});
|
|
707
778
|
|
|
708
779
|
// src/anthropic-prepare-tools.ts
|
|
@@ -2033,6 +2104,8 @@ function mapAnthropicStopReason({
|
|
|
2033
2104
|
return isJsonResponseFromTool ? "stop" : "tool-calls";
|
|
2034
2105
|
case "max_tokens":
|
|
2035
2106
|
return "length";
|
|
2107
|
+
case "model_context_window_exceeded":
|
|
2108
|
+
return "length";
|
|
2036
2109
|
default:
|
|
2037
2110
|
return "unknown";
|
|
2038
2111
|
}
|
|
@@ -2156,6 +2229,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2156
2229
|
description: "Respond with a JSON object.",
|
|
2157
2230
|
inputSchema: responseFormat.schema
|
|
2158
2231
|
} : void 0;
|
|
2232
|
+
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
2159
2233
|
const cacheControlValidator = new CacheControlValidator();
|
|
2160
2234
|
const toolNameMapping = createToolNameMapping({
|
|
2161
2235
|
tools,
|
|
@@ -2236,7 +2310,44 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2236
2310
|
},
|
|
2237
2311
|
// prompt:
|
|
2238
2312
|
system: messagesPrompt.system,
|
|
2239
|
-
messages: messagesPrompt.messages
|
|
2313
|
+
messages: messagesPrompt.messages,
|
|
2314
|
+
...contextManagement && {
|
|
2315
|
+
context_management: {
|
|
2316
|
+
edits: contextManagement.edits.map((edit) => {
|
|
2317
|
+
const strategy = edit.type;
|
|
2318
|
+
switch (strategy) {
|
|
2319
|
+
case "clear_tool_uses_20250919":
|
|
2320
|
+
return {
|
|
2321
|
+
type: edit.type,
|
|
2322
|
+
...edit.trigger !== void 0 && {
|
|
2323
|
+
trigger: edit.trigger
|
|
2324
|
+
},
|
|
2325
|
+
...edit.keep !== void 0 && { keep: edit.keep },
|
|
2326
|
+
...edit.clearAtLeast !== void 0 && {
|
|
2327
|
+
clear_at_least: edit.clearAtLeast
|
|
2328
|
+
},
|
|
2329
|
+
...edit.clearToolInputs !== void 0 && {
|
|
2330
|
+
clear_tool_inputs: edit.clearToolInputs
|
|
2331
|
+
},
|
|
2332
|
+
...edit.excludeTools !== void 0 && {
|
|
2333
|
+
exclude_tools: edit.excludeTools
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
case "clear_thinking_20251015":
|
|
2337
|
+
return {
|
|
2338
|
+
type: edit.type,
|
|
2339
|
+
...edit.keep !== void 0 && { keep: edit.keep }
|
|
2340
|
+
};
|
|
2341
|
+
default:
|
|
2342
|
+
warnings.push({
|
|
2343
|
+
type: "other",
|
|
2344
|
+
message: `Unknown context management strategy: ${strategy}`
|
|
2345
|
+
});
|
|
2346
|
+
return void 0;
|
|
2347
|
+
}
|
|
2348
|
+
}).filter((edit) => edit !== void 0)
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2240
2351
|
};
|
|
2241
2352
|
if (isThinking) {
|
|
2242
2353
|
if (thinkingBudget == null) {
|
|
@@ -2283,6 +2394,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2283
2394
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
2284
2395
|
betas.add("mcp-client-2025-04-04");
|
|
2285
2396
|
}
|
|
2397
|
+
if (contextManagement) {
|
|
2398
|
+
betas.add("context-management-2025-06-27");
|
|
2399
|
+
}
|
|
2286
2400
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
|
|
2287
2401
|
betas.add("code-execution-2025-08-25");
|
|
2288
2402
|
betas.add("skills-2025-10-02");
|
|
@@ -2394,7 +2508,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2394
2508
|
});
|
|
2395
2509
|
}
|
|
2396
2510
|
async doGenerate(options) {
|
|
2397
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2511
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2398
2512
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2399
2513
|
...options,
|
|
2400
2514
|
stream: false,
|
|
@@ -2720,7 +2834,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2720
2834
|
skillId: skill.skill_id,
|
|
2721
2835
|
version: skill.version
|
|
2722
2836
|
}))) != null ? _h : null
|
|
2723
|
-
} : null
|
|
2837
|
+
} : null,
|
|
2838
|
+
contextManagement: (_i = mapAnthropicResponseContextManagement(
|
|
2839
|
+
response.context_management
|
|
2840
|
+
)) != null ? _i : null
|
|
2724
2841
|
}
|
|
2725
2842
|
}
|
|
2726
2843
|
};
|
|
@@ -2759,6 +2876,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2759
2876
|
};
|
|
2760
2877
|
const contentBlocks = {};
|
|
2761
2878
|
const mcpToolCalls = {};
|
|
2879
|
+
let contextManagement = null;
|
|
2762
2880
|
let rawUsage = void 0;
|
|
2763
2881
|
let cacheCreationInputTokens = null;
|
|
2764
2882
|
let stopSequence = null;
|
|
@@ -3241,6 +3359,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3241
3359
|
version: skill.version
|
|
3242
3360
|
}))) != null ? _j : null
|
|
3243
3361
|
} : null;
|
|
3362
|
+
if (value.delta.context_management) {
|
|
3363
|
+
contextManagement = mapAnthropicResponseContextManagement(
|
|
3364
|
+
value.delta.context_management
|
|
3365
|
+
);
|
|
3366
|
+
}
|
|
3244
3367
|
rawUsage = {
|
|
3245
3368
|
...rawUsage,
|
|
3246
3369
|
...value.usage
|
|
@@ -3257,7 +3380,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3257
3380
|
usage: rawUsage != null ? rawUsage : null,
|
|
3258
3381
|
cacheCreationInputTokens,
|
|
3259
3382
|
stopSequence,
|
|
3260
|
-
container
|
|
3383
|
+
container,
|
|
3384
|
+
contextManagement
|
|
3261
3385
|
}
|
|
3262
3386
|
}
|
|
3263
3387
|
});
|
|
@@ -3352,6 +3476,27 @@ function getModelCapabilities(modelId) {
|
|
|
3352
3476
|
};
|
|
3353
3477
|
}
|
|
3354
3478
|
}
|
|
3479
|
+
function mapAnthropicResponseContextManagement(contextManagement) {
|
|
3480
|
+
return contextManagement ? {
|
|
3481
|
+
appliedEdits: contextManagement.applied_edits.map((edit) => {
|
|
3482
|
+
const strategy = edit.type;
|
|
3483
|
+
switch (strategy) {
|
|
3484
|
+
case "clear_tool_uses_20250919":
|
|
3485
|
+
return {
|
|
3486
|
+
type: edit.type,
|
|
3487
|
+
clearedToolUses: edit.cleared_tool_uses,
|
|
3488
|
+
clearedInputTokens: edit.cleared_input_tokens
|
|
3489
|
+
};
|
|
3490
|
+
case "clear_thinking_20251015":
|
|
3491
|
+
return {
|
|
3492
|
+
type: edit.type,
|
|
3493
|
+
clearedThinkingTurns: edit.cleared_thinking_turns,
|
|
3494
|
+
clearedInputTokens: edit.cleared_input_tokens
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
}).filter((edit) => edit !== void 0)
|
|
3498
|
+
} : null;
|
|
3499
|
+
}
|
|
3355
3500
|
|
|
3356
3501
|
// src/tool/bash_20241022.ts
|
|
3357
3502
|
import {
|