@ai-sdk/anthropic 4.0.94 → 4.0.95
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 +10 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +12 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +10 -5
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +7 -1
- package/package.json +2 -2
- package/src/anthropic-language-model.ts +17 -2
- package/src/convert-to-anthropic-prompt.ts +17 -1
- package/src/internal/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.95
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2cd0a97: 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
|
+
- 4ae6986: fix(anthropic): parse valid JSON string tool input and safely serialize BigInt and cycles in tool results
|
|
9
|
+
- Updated dependencies [51ca5b7]
|
|
10
|
+
- Updated dependencies [dc6f1c3]
|
|
11
|
+
- Updated dependencies [4ae6986]
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.73
|
|
13
|
+
|
|
3
14
|
## 4.0.94
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APICallError, InvalidArgumentError, InvalidResponseDataError, NoSuchModelError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
2
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, normalizeBatchRequestCounts, normalizeHeaders, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, validateBaseURL, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, normalizeBatchRequestCounts, normalizeHeaders, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, validateBaseURL, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { Experimental_DecisionLanguageModel } from "@ai-sdk/provider-utils/experimental-decision";
|
|
4
4
|
import { z } from "zod/v4";
|
|
5
5
|
//#region src/anthropic-error.ts
|
|
@@ -2963,7 +2963,7 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2963
2963
|
case "execution-denied":
|
|
2964
2964
|
contentValue = output.reason ?? "Tool call execution denied.";
|
|
2965
2965
|
break;
|
|
2966
|
-
default: contentValue =
|
|
2966
|
+
default: contentValue = stringifyWithBigIntAndCycles(output.value);
|
|
2967
2967
|
}
|
|
2968
2968
|
const toolsetName = getAnthropicToolsetName({
|
|
2969
2969
|
toolName: part.toolName,
|
|
@@ -3634,6 +3634,10 @@ function getAnthropicCaller(providerOptions) {
|
|
|
3634
3634
|
return caller?.type === "direct" ? { type: "direct" } : void 0;
|
|
3635
3635
|
}
|
|
3636
3636
|
function toAnthropicToolInput(input) {
|
|
3637
|
+
if (typeof input === "string") try {
|
|
3638
|
+
const parsed = secureJsonParse(input);
|
|
3639
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return parsed;
|
|
3640
|
+
} catch {}
|
|
3637
3641
|
return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
|
|
3638
3642
|
}
|
|
3639
3643
|
//#endregion
|
|
@@ -4151,9 +4155,10 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4151
4155
|
}
|
|
4152
4156
|
const isAnthropicModel = isKnownModel || modelId.includes("claude-");
|
|
4153
4157
|
const supportsStructuredOutput = (config.supportsNativeStructuredOutput ?? true) && modelSupportsStructuredOutput;
|
|
4158
|
+
const supportsResponseSchema = responseFormat?.type !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
|
|
4154
4159
|
const supportsStrictTools = (config.supportsStrictTools ?? true) && modelSupportsStructuredOutput;
|
|
4155
4160
|
const structureOutputMode = anthropicOptions?.structuredOutputMode ?? "auto";
|
|
4156
|
-
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
4161
|
+
let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
|
|
4157
4162
|
if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
|
|
4158
4163
|
warnings.push({
|
|
4159
4164
|
type: "unsupported",
|
|
@@ -4453,7 +4458,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4453
4458
|
else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) betas.add("server-side-fallback-2026-06-01");
|
|
4454
4459
|
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4455
4460
|
const { tools: anthropicTools, toolChoice: anthropicToolChoice, toolWarnings, betas: toolsBetas } = await prepareTools(jsonResponseTool != null ? {
|
|
4456
|
-
tools: [...tools ?? [], jsonResponseTool],
|
|
4461
|
+
tools: [...(tools ?? []).filter((tool) => toolChoice?.type !== "none" && (toolChoice?.type !== "tool" || tool.name === toolChoice.toolName)), jsonResponseTool],
|
|
4457
4462
|
toolChoice: { type: "required" },
|
|
4458
4463
|
disableParallelToolUse: true,
|
|
4459
4464
|
cacheControlValidator,
|
|
@@ -7344,7 +7349,7 @@ var AnthropicSkills = class {
|
|
|
7344
7349
|
};
|
|
7345
7350
|
//#endregion
|
|
7346
7351
|
//#region src/version.ts
|
|
7347
|
-
const VERSION = "4.0.
|
|
7352
|
+
const VERSION = "4.0.95";
|
|
7348
7353
|
//#endregion
|
|
7349
7354
|
//#region src/anthropic-provider.ts
|
|
7350
7355
|
const ANTHROPIC_API_URL = "https://api.anthropic.com";
|