@ai-sdk/anthropic 3.0.137 → 3.0.138
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 +11 -0
- package/dist/index.js +23 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -5
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +12 -1
- package/dist/internal/index.d.ts +12 -1
- package/dist/internal/index.js +26 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +25 -5
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +7 -1
- package/package.json +2 -2
- package/src/anthropic-messages-language-model.ts +17 -2
- package/src/convert-to-anthropic-messages-prompt.ts +21 -2
- package/src/internal/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.138
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d900e58: Enable native structured output and strict tools for supported Claude 5 models on Bedrock. In automatic mode, Bedrock and Anthropic now fall back for schemas that native structured output cannot represent: recursive references, open objects, or more than ten optional properties. Anthropic uses the JSON response tool; Bedrock Converse uses the JSON tool or JSON instructions for models that reject forced tool use. The JSON-tool fallback excludes disabled and unselected application tools. Explicit `outputFormat` selection remains unchanged.
|
|
8
|
+
- d900e58: fix(anthropic): parse valid JSON string tool input and safely serialize BigInt and cycles in tool results
|
|
9
|
+
- Updated dependencies [d900e58]
|
|
10
|
+
- Updated dependencies [d900e58]
|
|
11
|
+
- Updated dependencies [d900e58]
|
|
12
|
+
- @ai-sdk/provider-utils@4.0.64
|
|
13
|
+
|
|
3
14
|
## 3.0.137
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils28 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.138" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2797,7 +2797,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2797
2797
|
case "json":
|
|
2798
2798
|
case "error-json":
|
|
2799
2799
|
default:
|
|
2800
|
-
contentValue =
|
|
2800
|
+
contentValue = (0, import_provider_utils16.stringifyWithBigIntAndCycles)(output.value);
|
|
2801
2801
|
break;
|
|
2802
2802
|
}
|
|
2803
2803
|
const toolsetName = getAnthropicToolsetName({
|
|
@@ -3035,7 +3035,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3035
3035
|
type: "tool_use",
|
|
3036
3036
|
id: part.toolCallId,
|
|
3037
3037
|
name: part.toolName,
|
|
3038
|
-
input: part.input,
|
|
3038
|
+
input: parseToolCallInput(part.input),
|
|
3039
3039
|
...caller && { caller },
|
|
3040
3040
|
cache_control: cacheControl
|
|
3041
3041
|
});
|
|
@@ -3520,6 +3520,18 @@ function getAnthropicCaller(providerOptions) {
|
|
|
3520
3520
|
}
|
|
3521
3521
|
return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
|
|
3522
3522
|
}
|
|
3523
|
+
function parseToolCallInput(input) {
|
|
3524
|
+
if (typeof input === "string") {
|
|
3525
|
+
try {
|
|
3526
|
+
const parsed = (0, import_provider_utils16.secureJsonParse)(input);
|
|
3527
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
3528
|
+
return parsed;
|
|
3529
|
+
}
|
|
3530
|
+
} catch (e) {
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
return input;
|
|
3534
|
+
}
|
|
3523
3535
|
|
|
3524
3536
|
// src/map-anthropic-stop-reason.ts
|
|
3525
3537
|
function mapAnthropicStopReason({
|
|
@@ -4112,9 +4124,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4112
4124
|
}
|
|
4113
4125
|
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
4114
4126
|
const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
4127
|
+
const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
|
|
4115
4128
|
const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
|
|
4116
4129
|
const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
|
|
4117
|
-
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
4130
|
+
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
|
|
4118
4131
|
if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
|
|
4119
4132
|
warnings.push({
|
|
4120
4133
|
type: "unsupported",
|
|
@@ -4487,7 +4500,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4487
4500
|
betas: toolsBetas
|
|
4488
4501
|
} = await prepareTools(
|
|
4489
4502
|
jsonResponseTool != null ? {
|
|
4490
|
-
tools: [
|
|
4503
|
+
tools: [
|
|
4504
|
+
...(tools != null ? tools : []).filter(
|
|
4505
|
+
(tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
|
|
4506
|
+
),
|
|
4507
|
+
jsonResponseTool
|
|
4508
|
+
],
|
|
4491
4509
|
toolChoice: { type: "required" },
|
|
4492
4510
|
disableParallelToolUse: true,
|
|
4493
4511
|
cacheControlValidator,
|