@ai-sdk/anthropic 3.0.72 → 3.0.74
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 +17 -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 +4 -4
- 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/internal/index.mjs
CHANGED
|
@@ -37,7 +37,10 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// src/anthropic-messages-api.ts
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
lazySchema as lazySchema2,
|
|
42
|
+
zodSchema as zodSchema2
|
|
43
|
+
} from "@ai-sdk/provider-utils";
|
|
41
44
|
import { z as z2 } from "zod/v4";
|
|
42
45
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
43
46
|
() => zodSchema2(
|
|
@@ -1041,9 +1044,12 @@ var CacheControlValidator = class {
|
|
|
1041
1044
|
};
|
|
1042
1045
|
|
|
1043
1046
|
// src/tool/text-editor_20250728.ts
|
|
1044
|
-
import {
|
|
1047
|
+
import {
|
|
1048
|
+
createProviderToolFactory,
|
|
1049
|
+
lazySchema as lazySchema3,
|
|
1050
|
+
zodSchema as zodSchema3
|
|
1051
|
+
} from "@ai-sdk/provider-utils";
|
|
1045
1052
|
import { z as z4 } from "zod/v4";
|
|
1046
|
-
import { lazySchema as lazySchema3, zodSchema as zodSchema3 } from "@ai-sdk/provider-utils";
|
|
1047
1053
|
var textEditor_20250728ArgsSchema = lazySchema3(
|
|
1048
1054
|
() => zodSchema3(
|
|
1049
1055
|
z4.object({
|
|
@@ -2853,6 +2859,152 @@ function mapAnthropicStopReason({
|
|
|
2853
2859
|
}
|
|
2854
2860
|
}
|
|
2855
2861
|
|
|
2862
|
+
// src/sanitize-json-schema.ts
|
|
2863
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
2864
|
+
"date-time",
|
|
2865
|
+
"time",
|
|
2866
|
+
"date",
|
|
2867
|
+
"duration",
|
|
2868
|
+
"email",
|
|
2869
|
+
"hostname",
|
|
2870
|
+
"uri",
|
|
2871
|
+
"ipv4",
|
|
2872
|
+
"ipv6",
|
|
2873
|
+
"uuid"
|
|
2874
|
+
]);
|
|
2875
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
2876
|
+
"minimum",
|
|
2877
|
+
"maximum",
|
|
2878
|
+
"exclusiveMinimum",
|
|
2879
|
+
"exclusiveMaximum",
|
|
2880
|
+
"multipleOf",
|
|
2881
|
+
"minLength",
|
|
2882
|
+
"maxLength",
|
|
2883
|
+
"pattern",
|
|
2884
|
+
"minItems",
|
|
2885
|
+
"maxItems",
|
|
2886
|
+
"uniqueItems",
|
|
2887
|
+
"minProperties",
|
|
2888
|
+
"maxProperties",
|
|
2889
|
+
"not"
|
|
2890
|
+
];
|
|
2891
|
+
function sanitizeJsonSchema(schema) {
|
|
2892
|
+
return sanitizeSchema(schema);
|
|
2893
|
+
}
|
|
2894
|
+
function sanitizeDefinition(definition) {
|
|
2895
|
+
if (typeof definition === "boolean" || !isPlainObject(definition)) {
|
|
2896
|
+
return definition;
|
|
2897
|
+
}
|
|
2898
|
+
return sanitizeSchema(definition);
|
|
2899
|
+
}
|
|
2900
|
+
function sanitizeSchema(schema) {
|
|
2901
|
+
const result = {};
|
|
2902
|
+
const schemaWithDefs = schema;
|
|
2903
|
+
if (schema.$ref != null) {
|
|
2904
|
+
return { $ref: schema.$ref };
|
|
2905
|
+
}
|
|
2906
|
+
if (schema.$schema != null) {
|
|
2907
|
+
result.$schema = schema.$schema;
|
|
2908
|
+
}
|
|
2909
|
+
if (schema.$id != null) {
|
|
2910
|
+
result.$id = schema.$id;
|
|
2911
|
+
}
|
|
2912
|
+
if (schema.title != null) {
|
|
2913
|
+
result.title = schema.title;
|
|
2914
|
+
}
|
|
2915
|
+
if (schema.description != null) {
|
|
2916
|
+
result.description = schema.description;
|
|
2917
|
+
}
|
|
2918
|
+
if (schema.default !== void 0) {
|
|
2919
|
+
result.default = schema.default;
|
|
2920
|
+
}
|
|
2921
|
+
if (schema.const !== void 0) {
|
|
2922
|
+
result.const = schema.const;
|
|
2923
|
+
}
|
|
2924
|
+
if (schema.enum != null) {
|
|
2925
|
+
result.enum = schema.enum;
|
|
2926
|
+
}
|
|
2927
|
+
if (schema.type != null) {
|
|
2928
|
+
result.type = schema.type;
|
|
2929
|
+
}
|
|
2930
|
+
if (schema.anyOf != null) {
|
|
2931
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
2932
|
+
} else if (schema.oneOf != null) {
|
|
2933
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
2934
|
+
}
|
|
2935
|
+
if (schema.allOf != null) {
|
|
2936
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
2937
|
+
}
|
|
2938
|
+
if (schema.definitions != null) {
|
|
2939
|
+
result.definitions = Object.fromEntries(
|
|
2940
|
+
Object.entries(schema.definitions).map(([name, definition]) => [
|
|
2941
|
+
name,
|
|
2942
|
+
sanitizeDefinition(definition)
|
|
2943
|
+
])
|
|
2944
|
+
);
|
|
2945
|
+
}
|
|
2946
|
+
if (schemaWithDefs.$defs != null) {
|
|
2947
|
+
const resultWithDefs = result;
|
|
2948
|
+
resultWithDefs.$defs = Object.fromEntries(
|
|
2949
|
+
Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
|
|
2950
|
+
name,
|
|
2951
|
+
sanitizeDefinition(definition)
|
|
2952
|
+
])
|
|
2953
|
+
);
|
|
2954
|
+
}
|
|
2955
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
2956
|
+
if (schema.properties != null) {
|
|
2957
|
+
result.properties = Object.fromEntries(
|
|
2958
|
+
Object.entries(schema.properties).map(([name, definition]) => [
|
|
2959
|
+
name,
|
|
2960
|
+
sanitizeDefinition(definition)
|
|
2961
|
+
])
|
|
2962
|
+
);
|
|
2963
|
+
}
|
|
2964
|
+
result.additionalProperties = false;
|
|
2965
|
+
if (schema.required != null) {
|
|
2966
|
+
result.required = schema.required;
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
if (schema.items != null) {
|
|
2970
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
2971
|
+
}
|
|
2972
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2973
|
+
result.format = schema.format;
|
|
2974
|
+
}
|
|
2975
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
2976
|
+
if (constraintDescription != null) {
|
|
2977
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
2978
|
+
${constraintDescription}`;
|
|
2979
|
+
}
|
|
2980
|
+
return result;
|
|
2981
|
+
}
|
|
2982
|
+
function getConstraintDescription(schema) {
|
|
2983
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
2984
|
+
const value = schema[key];
|
|
2985
|
+
if (value == null || value === false) {
|
|
2986
|
+
return [];
|
|
2987
|
+
}
|
|
2988
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
2989
|
+
});
|
|
2990
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2991
|
+
descriptions.push(`format: ${schema.format}`);
|
|
2992
|
+
}
|
|
2993
|
+
return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
|
|
2994
|
+
}
|
|
2995
|
+
function formatConstraintName(key) {
|
|
2996
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
2997
|
+
}
|
|
2998
|
+
function formatConstraintValue(value) {
|
|
2999
|
+
if (typeof value === "string") {
|
|
3000
|
+
return value;
|
|
3001
|
+
}
|
|
3002
|
+
return JSON.stringify(value);
|
|
3003
|
+
}
|
|
3004
|
+
function isPlainObject(value) {
|
|
3005
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3006
|
+
}
|
|
3007
|
+
|
|
2856
3008
|
// src/anthropic-messages-language-model.ts
|
|
2857
3009
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
2858
3010
|
var _a;
|
|
@@ -3108,7 +3260,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3108
3260
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3109
3261
|
format: {
|
|
3110
3262
|
type: "json_schema",
|
|
3111
|
-
schema: responseFormat.schema
|
|
3263
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
3112
3264
|
}
|
|
3113
3265
|
}
|
|
3114
3266
|
}
|