@ai-sdk/anthropic 4.0.0-beta.39 → 4.0.0-beta.40
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.js +148 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +147 -1
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-language-model.ts +2 -1
- package/src/sanitize-json-schema.ts +203 -0
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -2978,6 +2978,152 @@ function mapAnthropicStopReason({
|
|
|
2978
2978
|
}
|
|
2979
2979
|
}
|
|
2980
2980
|
|
|
2981
|
+
// src/sanitize-json-schema.ts
|
|
2982
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
2983
|
+
"date-time",
|
|
2984
|
+
"time",
|
|
2985
|
+
"date",
|
|
2986
|
+
"duration",
|
|
2987
|
+
"email",
|
|
2988
|
+
"hostname",
|
|
2989
|
+
"uri",
|
|
2990
|
+
"ipv4",
|
|
2991
|
+
"ipv6",
|
|
2992
|
+
"uuid"
|
|
2993
|
+
]);
|
|
2994
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
2995
|
+
"minimum",
|
|
2996
|
+
"maximum",
|
|
2997
|
+
"exclusiveMinimum",
|
|
2998
|
+
"exclusiveMaximum",
|
|
2999
|
+
"multipleOf",
|
|
3000
|
+
"minLength",
|
|
3001
|
+
"maxLength",
|
|
3002
|
+
"pattern",
|
|
3003
|
+
"minItems",
|
|
3004
|
+
"maxItems",
|
|
3005
|
+
"uniqueItems",
|
|
3006
|
+
"minProperties",
|
|
3007
|
+
"maxProperties",
|
|
3008
|
+
"not"
|
|
3009
|
+
];
|
|
3010
|
+
function sanitizeJsonSchema(schema) {
|
|
3011
|
+
return sanitizeSchema(schema);
|
|
3012
|
+
}
|
|
3013
|
+
function sanitizeDefinition(definition) {
|
|
3014
|
+
if (typeof definition === "boolean" || !isPlainObject(definition)) {
|
|
3015
|
+
return definition;
|
|
3016
|
+
}
|
|
3017
|
+
return sanitizeSchema(definition);
|
|
3018
|
+
}
|
|
3019
|
+
function sanitizeSchema(schema) {
|
|
3020
|
+
const result = {};
|
|
3021
|
+
const schemaWithDefs = schema;
|
|
3022
|
+
if (schema.$ref != null) {
|
|
3023
|
+
return { $ref: schema.$ref };
|
|
3024
|
+
}
|
|
3025
|
+
if (schema.$schema != null) {
|
|
3026
|
+
result.$schema = schema.$schema;
|
|
3027
|
+
}
|
|
3028
|
+
if (schema.$id != null) {
|
|
3029
|
+
result.$id = schema.$id;
|
|
3030
|
+
}
|
|
3031
|
+
if (schema.title != null) {
|
|
3032
|
+
result.title = schema.title;
|
|
3033
|
+
}
|
|
3034
|
+
if (schema.description != null) {
|
|
3035
|
+
result.description = schema.description;
|
|
3036
|
+
}
|
|
3037
|
+
if (schema.default !== void 0) {
|
|
3038
|
+
result.default = schema.default;
|
|
3039
|
+
}
|
|
3040
|
+
if (schema.const !== void 0) {
|
|
3041
|
+
result.const = schema.const;
|
|
3042
|
+
}
|
|
3043
|
+
if (schema.enum != null) {
|
|
3044
|
+
result.enum = schema.enum;
|
|
3045
|
+
}
|
|
3046
|
+
if (schema.type != null) {
|
|
3047
|
+
result.type = schema.type;
|
|
3048
|
+
}
|
|
3049
|
+
if (schema.anyOf != null) {
|
|
3050
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
3051
|
+
} else if (schema.oneOf != null) {
|
|
3052
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
3053
|
+
}
|
|
3054
|
+
if (schema.allOf != null) {
|
|
3055
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
3056
|
+
}
|
|
3057
|
+
if (schema.definitions != null) {
|
|
3058
|
+
result.definitions = Object.fromEntries(
|
|
3059
|
+
Object.entries(schema.definitions).map(([name, definition]) => [
|
|
3060
|
+
name,
|
|
3061
|
+
sanitizeDefinition(definition)
|
|
3062
|
+
])
|
|
3063
|
+
);
|
|
3064
|
+
}
|
|
3065
|
+
if (schemaWithDefs.$defs != null) {
|
|
3066
|
+
const resultWithDefs = result;
|
|
3067
|
+
resultWithDefs.$defs = Object.fromEntries(
|
|
3068
|
+
Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
|
|
3069
|
+
name,
|
|
3070
|
+
sanitizeDefinition(definition)
|
|
3071
|
+
])
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
3075
|
+
if (schema.properties != null) {
|
|
3076
|
+
result.properties = Object.fromEntries(
|
|
3077
|
+
Object.entries(schema.properties).map(([name, definition]) => [
|
|
3078
|
+
name,
|
|
3079
|
+
sanitizeDefinition(definition)
|
|
3080
|
+
])
|
|
3081
|
+
);
|
|
3082
|
+
}
|
|
3083
|
+
result.additionalProperties = false;
|
|
3084
|
+
if (schema.required != null) {
|
|
3085
|
+
result.required = schema.required;
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
if (schema.items != null) {
|
|
3089
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
3090
|
+
}
|
|
3091
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
3092
|
+
result.format = schema.format;
|
|
3093
|
+
}
|
|
3094
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
3095
|
+
if (constraintDescription != null) {
|
|
3096
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
3097
|
+
${constraintDescription}`;
|
|
3098
|
+
}
|
|
3099
|
+
return result;
|
|
3100
|
+
}
|
|
3101
|
+
function getConstraintDescription(schema) {
|
|
3102
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
3103
|
+
const value = schema[key];
|
|
3104
|
+
if (value == null || value === false) {
|
|
3105
|
+
return [];
|
|
3106
|
+
}
|
|
3107
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
3108
|
+
});
|
|
3109
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
3110
|
+
descriptions.push(`format: ${schema.format}`);
|
|
3111
|
+
}
|
|
3112
|
+
return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
|
|
3113
|
+
}
|
|
3114
|
+
function formatConstraintName(key) {
|
|
3115
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
3116
|
+
}
|
|
3117
|
+
function formatConstraintValue(value) {
|
|
3118
|
+
if (typeof value === "string") {
|
|
3119
|
+
return value;
|
|
3120
|
+
}
|
|
3121
|
+
return JSON.stringify(value);
|
|
3122
|
+
}
|
|
3123
|
+
function isPlainObject(value) {
|
|
3124
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3125
|
+
}
|
|
3126
|
+
|
|
2981
3127
|
// src/anthropic-language-model.ts
|
|
2982
3128
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
2983
3129
|
var _a;
|
|
@@ -3262,7 +3408,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3262
3408
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3263
3409
|
format: {
|
|
3264
3410
|
type: "json_schema",
|
|
3265
|
-
schema: responseFormat.schema
|
|
3411
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
3266
3412
|
}
|
|
3267
3413
|
}
|
|
3268
3414
|
}
|
|
@@ -5567,7 +5713,7 @@ var AnthropicSkills = class {
|
|
|
5567
5713
|
};
|
|
5568
5714
|
|
|
5569
5715
|
// src/version.ts
|
|
5570
|
-
var VERSION = true ? "4.0.0-beta.
|
|
5716
|
+
var VERSION = true ? "4.0.0-beta.40" : "0.0.0-test";
|
|
5571
5717
|
|
|
5572
5718
|
// src/anthropic-provider.ts
|
|
5573
5719
|
function createAnthropic(options = {}) {
|