@ai-sdk/anthropic 3.0.145 → 3.0.146
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 +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +32 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +31 -8
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +31 -8
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +23 -0
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +2 -2
- package/src/anthropic-messages-language-model.ts +2 -0
- package/src/anthropic-messages-options.ts +10 -0
- package/src/convert-to-anthropic-messages-prompt.ts +33 -4
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.146" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -988,6 +988,15 @@ var anthropicLanguageModelOptions = lazySchema3(() => {
|
|
|
988
988
|
* This allows you to deactivate reasoning inputs for models that do not support them.
|
|
989
989
|
*/
|
|
990
990
|
sendReasoning: z3.boolean().optional(),
|
|
991
|
+
/**
|
|
992
|
+
* Keep a system message that follows user or assistant messages in the
|
|
993
|
+
* `messages` array, even when no system message comes before it. By
|
|
994
|
+
* default the first system message becomes the top-level `system`
|
|
995
|
+
* prompt wherever it appears, which models without mid-conversation
|
|
996
|
+
* system message support require. Enable this only for models that
|
|
997
|
+
* support mid-conversation system messages.
|
|
998
|
+
*/
|
|
999
|
+
midConversationSystemMessages: z3.boolean().optional(),
|
|
991
1000
|
/**
|
|
992
1001
|
* Allow tool definitions supplied by value in system-message tool changes.
|
|
993
1002
|
* Defaults to false. Enable only for server-controlled messages: inline
|
|
@@ -2596,7 +2605,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2596
2605
|
toolNameMapping,
|
|
2597
2606
|
toolsetNames = {},
|
|
2598
2607
|
convertMediaPart,
|
|
2599
|
-
convertInlineTool
|
|
2608
|
+
convertInlineTool,
|
|
2609
|
+
keepMidConversationSystemMessages = false
|
|
2600
2610
|
}) {
|
|
2601
2611
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2602
2612
|
const betas = /* @__PURE__ */ new Set();
|
|
@@ -2645,7 +2655,8 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2645
2655
|
const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
|
|
2646
2656
|
const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
|
|
2647
2657
|
const content = [];
|
|
2648
|
-
|
|
2658
|
+
const emitsText = text !== "" || toolChanges.length === 0 && clearAt == null && effort == null;
|
|
2659
|
+
if (emitsText) {
|
|
2649
2660
|
content.push({
|
|
2650
2661
|
type: "text",
|
|
2651
2662
|
text,
|
|
@@ -2699,6 +2710,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2699
2710
|
}
|
|
2700
2711
|
});
|
|
2701
2712
|
}
|
|
2713
|
+
const lastToolChange = content.at(-1);
|
|
2714
|
+
const definesOwnCacheControl = (lastToolChange == null ? void 0 : lastToolChange.type) === "tool_addition" && lastToolChange.tool.type === "tool_definition" && "cache_control" in lastToolChange.tool.definition && lastToolChange.tool.definition.cache_control != null;
|
|
2715
|
+
if (!emitsText && lastToolChange != null && !definesOwnCacheControl) {
|
|
2716
|
+
const cacheControl = validator.getCacheControl(providerOptions, {
|
|
2717
|
+
type: "system message",
|
|
2718
|
+
canCache: true
|
|
2719
|
+
});
|
|
2720
|
+
if (cacheControl != null) {
|
|
2721
|
+
lastToolChange.cache_control = cacheControl;
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2702
2724
|
if (content.length === 0 && clearAt == null && effort == null) {
|
|
2703
2725
|
continue;
|
|
2704
2726
|
}
|
|
@@ -2710,7 +2732,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2710
2732
|
...effort != null && { output_config: { effort } }
|
|
2711
2733
|
});
|
|
2712
2734
|
}
|
|
2713
|
-
if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
|
|
2735
|
+
if (i === 0 || !keepMidConversationSystemMessages && system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
|
|
2714
2736
|
if (toolChangeCount > 0) {
|
|
2715
2737
|
warnings.push({
|
|
2716
2738
|
type: "other",
|
|
@@ -4221,7 +4243,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4221
4243
|
providerOptions,
|
|
4222
4244
|
stream
|
|
4223
4245
|
}) {
|
|
4224
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4246
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4225
4247
|
const warnings = [];
|
|
4226
4248
|
if (frequencyPenalty != null) {
|
|
4227
4249
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -4400,6 +4422,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4400
4422
|
toolNameMapping,
|
|
4401
4423
|
toolsetNames,
|
|
4402
4424
|
convertMediaPart: this.config.convertMediaPart,
|
|
4425
|
+
keepMidConversationSystemMessages: (_g = anthropicOptions == null ? void 0 : anthropicOptions.midConversationSystemMessages) != null ? _g : false,
|
|
4403
4426
|
convertInlineTool: async (tool) => {
|
|
4404
4427
|
const {
|
|
4405
4428
|
tools: definitions,
|
|
@@ -4550,7 +4573,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4550
4573
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
4551
4574
|
cache_control: anthropicOptions.cacheControl
|
|
4552
4575
|
},
|
|
4553
|
-
...((
|
|
4576
|
+
...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
|
|
4554
4577
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4555
4578
|
},
|
|
4556
4579
|
// mcp servers:
|
|
@@ -4780,9 +4803,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4780
4803
|
}
|
|
4781
4804
|
);
|
|
4782
4805
|
if ((toolChoice == null ? void 0 : toolChoice.type) === "tool" && ((anthropicToolChoice == null ? void 0 : anthropicToolChoice.type) === "auto" || jsonResponseTool != null) || (toolChoice == null ? void 0 : toolChoice.type) === "none" && jsonResponseTool != null) {
|
|
4783
|
-
for (const server of (
|
|
4806
|
+
for (const server of (_i = baseArgs.mcp_servers) != null ? _i : []) {
|
|
4784
4807
|
server.tool_configuration = {
|
|
4785
|
-
allowed_tools: (
|
|
4808
|
+
allowed_tools: (_j = server.tool_configuration) == null ? void 0 : _j.allowed_tools,
|
|
4786
4809
|
enabled: false
|
|
4787
4810
|
};
|
|
4788
4811
|
}
|
|
@@ -4817,7 +4840,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4817
4840
|
...betas,
|
|
4818
4841
|
...toolsBetas,
|
|
4819
4842
|
...userSuppliedBetas,
|
|
4820
|
-
...(
|
|
4843
|
+
...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
|
|
4821
4844
|
]),
|
|
4822
4845
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4823
4846
|
toolNameMapping,
|