@ai-sdk/anthropic 3.0.71 → 3.0.73
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 +19 -0
- package/dist/index.js +288 -143
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -5
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +281 -136
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +156 -4
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/anthropic-error.ts +1 -1
- package/src/anthropic-message-metadata.ts +1 -1
- package/src/anthropic-messages-api.ts +6 -2
- package/src/anthropic-messages-language-model.ts +28 -27
- package/src/anthropic-prepare-tools.ts +6 -3
- package/src/anthropic-provider.ts +4 -4
- package/src/convert-anthropic-messages-usage.ts +1 -1
- package/src/convert-to-anthropic-messages-prompt.ts +11 -11
- package/src/forward-anthropic-container-id-from-last-step.ts +2 -2
- package/src/get-cache-control.ts +5 -2
- package/src/map-anthropic-stop-reason.ts +1 -1
- package/src/sanitize-json-schema.ts +203 -0
- package/src/tool/text-editor_20250728.ts +5 -2
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.73" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -53,7 +53,10 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
// src/anthropic-messages-api.ts
|
|
56
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
lazySchema as lazySchema2,
|
|
58
|
+
zodSchema as zodSchema2
|
|
59
|
+
} from "@ai-sdk/provider-utils";
|
|
57
60
|
import { z as z2 } from "zod/v4";
|
|
58
61
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
59
62
|
() => zodSchema2(
|
|
@@ -1057,9 +1060,12 @@ var CacheControlValidator = class {
|
|
|
1057
1060
|
};
|
|
1058
1061
|
|
|
1059
1062
|
// src/tool/text-editor_20250728.ts
|
|
1060
|
-
import {
|
|
1063
|
+
import {
|
|
1064
|
+
createProviderToolFactory,
|
|
1065
|
+
lazySchema as lazySchema3,
|
|
1066
|
+
zodSchema as zodSchema3
|
|
1067
|
+
} from "@ai-sdk/provider-utils";
|
|
1061
1068
|
import { z as z4 } from "zod/v4";
|
|
1062
|
-
import { lazySchema as lazySchema3, zodSchema as zodSchema3 } from "@ai-sdk/provider-utils";
|
|
1063
1069
|
var textEditor_20250728ArgsSchema = lazySchema3(
|
|
1064
1070
|
() => zodSchema3(
|
|
1065
1071
|
z4.object({
|
|
@@ -2869,6 +2875,152 @@ function mapAnthropicStopReason({
|
|
|
2869
2875
|
}
|
|
2870
2876
|
}
|
|
2871
2877
|
|
|
2878
|
+
// src/sanitize-json-schema.ts
|
|
2879
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
2880
|
+
"date-time",
|
|
2881
|
+
"time",
|
|
2882
|
+
"date",
|
|
2883
|
+
"duration",
|
|
2884
|
+
"email",
|
|
2885
|
+
"hostname",
|
|
2886
|
+
"uri",
|
|
2887
|
+
"ipv4",
|
|
2888
|
+
"ipv6",
|
|
2889
|
+
"uuid"
|
|
2890
|
+
]);
|
|
2891
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
2892
|
+
"minimum",
|
|
2893
|
+
"maximum",
|
|
2894
|
+
"exclusiveMinimum",
|
|
2895
|
+
"exclusiveMaximum",
|
|
2896
|
+
"multipleOf",
|
|
2897
|
+
"minLength",
|
|
2898
|
+
"maxLength",
|
|
2899
|
+
"pattern",
|
|
2900
|
+
"minItems",
|
|
2901
|
+
"maxItems",
|
|
2902
|
+
"uniqueItems",
|
|
2903
|
+
"minProperties",
|
|
2904
|
+
"maxProperties",
|
|
2905
|
+
"not"
|
|
2906
|
+
];
|
|
2907
|
+
function sanitizeJsonSchema(schema) {
|
|
2908
|
+
return sanitizeSchema(schema);
|
|
2909
|
+
}
|
|
2910
|
+
function sanitizeDefinition(definition) {
|
|
2911
|
+
if (typeof definition === "boolean" || !isPlainObject(definition)) {
|
|
2912
|
+
return definition;
|
|
2913
|
+
}
|
|
2914
|
+
return sanitizeSchema(definition);
|
|
2915
|
+
}
|
|
2916
|
+
function sanitizeSchema(schema) {
|
|
2917
|
+
const result = {};
|
|
2918
|
+
const schemaWithDefs = schema;
|
|
2919
|
+
if (schema.$ref != null) {
|
|
2920
|
+
return { $ref: schema.$ref };
|
|
2921
|
+
}
|
|
2922
|
+
if (schema.$schema != null) {
|
|
2923
|
+
result.$schema = schema.$schema;
|
|
2924
|
+
}
|
|
2925
|
+
if (schema.$id != null) {
|
|
2926
|
+
result.$id = schema.$id;
|
|
2927
|
+
}
|
|
2928
|
+
if (schema.title != null) {
|
|
2929
|
+
result.title = schema.title;
|
|
2930
|
+
}
|
|
2931
|
+
if (schema.description != null) {
|
|
2932
|
+
result.description = schema.description;
|
|
2933
|
+
}
|
|
2934
|
+
if (schema.default !== void 0) {
|
|
2935
|
+
result.default = schema.default;
|
|
2936
|
+
}
|
|
2937
|
+
if (schema.const !== void 0) {
|
|
2938
|
+
result.const = schema.const;
|
|
2939
|
+
}
|
|
2940
|
+
if (schema.enum != null) {
|
|
2941
|
+
result.enum = schema.enum;
|
|
2942
|
+
}
|
|
2943
|
+
if (schema.type != null) {
|
|
2944
|
+
result.type = schema.type;
|
|
2945
|
+
}
|
|
2946
|
+
if (schema.anyOf != null) {
|
|
2947
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
2948
|
+
} else if (schema.oneOf != null) {
|
|
2949
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
2950
|
+
}
|
|
2951
|
+
if (schema.allOf != null) {
|
|
2952
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
2953
|
+
}
|
|
2954
|
+
if (schema.definitions != null) {
|
|
2955
|
+
result.definitions = Object.fromEntries(
|
|
2956
|
+
Object.entries(schema.definitions).map(([name, definition]) => [
|
|
2957
|
+
name,
|
|
2958
|
+
sanitizeDefinition(definition)
|
|
2959
|
+
])
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
if (schemaWithDefs.$defs != null) {
|
|
2963
|
+
const resultWithDefs = result;
|
|
2964
|
+
resultWithDefs.$defs = Object.fromEntries(
|
|
2965
|
+
Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
|
|
2966
|
+
name,
|
|
2967
|
+
sanitizeDefinition(definition)
|
|
2968
|
+
])
|
|
2969
|
+
);
|
|
2970
|
+
}
|
|
2971
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
2972
|
+
if (schema.properties != null) {
|
|
2973
|
+
result.properties = Object.fromEntries(
|
|
2974
|
+
Object.entries(schema.properties).map(([name, definition]) => [
|
|
2975
|
+
name,
|
|
2976
|
+
sanitizeDefinition(definition)
|
|
2977
|
+
])
|
|
2978
|
+
);
|
|
2979
|
+
}
|
|
2980
|
+
result.additionalProperties = false;
|
|
2981
|
+
if (schema.required != null) {
|
|
2982
|
+
result.required = schema.required;
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
if (schema.items != null) {
|
|
2986
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
2987
|
+
}
|
|
2988
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2989
|
+
result.format = schema.format;
|
|
2990
|
+
}
|
|
2991
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
2992
|
+
if (constraintDescription != null) {
|
|
2993
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
2994
|
+
${constraintDescription}`;
|
|
2995
|
+
}
|
|
2996
|
+
return result;
|
|
2997
|
+
}
|
|
2998
|
+
function getConstraintDescription(schema) {
|
|
2999
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
3000
|
+
const value = schema[key];
|
|
3001
|
+
if (value == null || value === false) {
|
|
3002
|
+
return [];
|
|
3003
|
+
}
|
|
3004
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
3005
|
+
});
|
|
3006
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
3007
|
+
descriptions.push(`format: ${schema.format}`);
|
|
3008
|
+
}
|
|
3009
|
+
return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
|
|
3010
|
+
}
|
|
3011
|
+
function formatConstraintName(key) {
|
|
3012
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
3013
|
+
}
|
|
3014
|
+
function formatConstraintValue(value) {
|
|
3015
|
+
if (typeof value === "string") {
|
|
3016
|
+
return value;
|
|
3017
|
+
}
|
|
3018
|
+
return JSON.stringify(value);
|
|
3019
|
+
}
|
|
3020
|
+
function isPlainObject(value) {
|
|
3021
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3022
|
+
}
|
|
3023
|
+
|
|
2872
3024
|
// src/anthropic-messages-language-model.ts
|
|
2873
3025
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
2874
3026
|
var _a;
|
|
@@ -3124,7 +3276,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3124
3276
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3125
3277
|
format: {
|
|
3126
3278
|
type: "json_schema",
|
|
3127
|
-
schema: responseFormat.schema
|
|
3279
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
3128
3280
|
}
|
|
3129
3281
|
}
|
|
3130
3282
|
}
|