@ai-sdk/anthropic 2.0.78 → 2.0.79
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 +10 -0
- package/dist/index.js +248 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -12
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +241 -103
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +156 -11
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/internal/index.mjs
CHANGED
|
@@ -36,7 +36,10 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// src/anthropic-messages-api.ts
|
|
39
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
lazySchema as lazySchema2,
|
|
41
|
+
zodSchema as zodSchema2
|
|
42
|
+
} from "@ai-sdk/provider-utils";
|
|
40
43
|
import { z as z2 } from "zod/v4";
|
|
41
44
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
42
45
|
() => zodSchema2(
|
|
@@ -824,9 +827,12 @@ var CacheControlValidator = class {
|
|
|
824
827
|
};
|
|
825
828
|
|
|
826
829
|
// src/tool/text-editor_20250728.ts
|
|
827
|
-
import {
|
|
830
|
+
import {
|
|
831
|
+
createProviderDefinedToolFactory,
|
|
832
|
+
lazySchema as lazySchema3,
|
|
833
|
+
zodSchema as zodSchema3
|
|
834
|
+
} from "@ai-sdk/provider-utils";
|
|
828
835
|
import { z as z4 } from "zod/v4";
|
|
829
|
-
import { lazySchema as lazySchema3, zodSchema as zodSchema3 } from "@ai-sdk/provider-utils";
|
|
830
836
|
var textEditor_20250728ArgsSchema = lazySchema3(
|
|
831
837
|
() => zodSchema3(
|
|
832
838
|
z4.object({
|
|
@@ -1938,6 +1944,152 @@ function mapAnthropicStopReason({
|
|
|
1938
1944
|
}
|
|
1939
1945
|
}
|
|
1940
1946
|
|
|
1947
|
+
// src/sanitize-json-schema.ts
|
|
1948
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
1949
|
+
"date-time",
|
|
1950
|
+
"time",
|
|
1951
|
+
"date",
|
|
1952
|
+
"duration",
|
|
1953
|
+
"email",
|
|
1954
|
+
"hostname",
|
|
1955
|
+
"uri",
|
|
1956
|
+
"ipv4",
|
|
1957
|
+
"ipv6",
|
|
1958
|
+
"uuid"
|
|
1959
|
+
]);
|
|
1960
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
1961
|
+
"minimum",
|
|
1962
|
+
"maximum",
|
|
1963
|
+
"exclusiveMinimum",
|
|
1964
|
+
"exclusiveMaximum",
|
|
1965
|
+
"multipleOf",
|
|
1966
|
+
"minLength",
|
|
1967
|
+
"maxLength",
|
|
1968
|
+
"pattern",
|
|
1969
|
+
"minItems",
|
|
1970
|
+
"maxItems",
|
|
1971
|
+
"uniqueItems",
|
|
1972
|
+
"minProperties",
|
|
1973
|
+
"maxProperties",
|
|
1974
|
+
"not"
|
|
1975
|
+
];
|
|
1976
|
+
function sanitizeJsonSchema(schema) {
|
|
1977
|
+
return sanitizeSchema(schema);
|
|
1978
|
+
}
|
|
1979
|
+
function sanitizeDefinition(definition) {
|
|
1980
|
+
if (typeof definition === "boolean" || !isPlainObject(definition)) {
|
|
1981
|
+
return definition;
|
|
1982
|
+
}
|
|
1983
|
+
return sanitizeSchema(definition);
|
|
1984
|
+
}
|
|
1985
|
+
function sanitizeSchema(schema) {
|
|
1986
|
+
const result = {};
|
|
1987
|
+
const schemaWithDefs = schema;
|
|
1988
|
+
if (schema.$ref != null) {
|
|
1989
|
+
return { $ref: schema.$ref };
|
|
1990
|
+
}
|
|
1991
|
+
if (schema.$schema != null) {
|
|
1992
|
+
result.$schema = schema.$schema;
|
|
1993
|
+
}
|
|
1994
|
+
if (schema.$id != null) {
|
|
1995
|
+
result.$id = schema.$id;
|
|
1996
|
+
}
|
|
1997
|
+
if (schema.title != null) {
|
|
1998
|
+
result.title = schema.title;
|
|
1999
|
+
}
|
|
2000
|
+
if (schema.description != null) {
|
|
2001
|
+
result.description = schema.description;
|
|
2002
|
+
}
|
|
2003
|
+
if (schema.default !== void 0) {
|
|
2004
|
+
result.default = schema.default;
|
|
2005
|
+
}
|
|
2006
|
+
if (schema.const !== void 0) {
|
|
2007
|
+
result.const = schema.const;
|
|
2008
|
+
}
|
|
2009
|
+
if (schema.enum != null) {
|
|
2010
|
+
result.enum = schema.enum;
|
|
2011
|
+
}
|
|
2012
|
+
if (schema.type != null) {
|
|
2013
|
+
result.type = schema.type;
|
|
2014
|
+
}
|
|
2015
|
+
if (schema.anyOf != null) {
|
|
2016
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
2017
|
+
} else if (schema.oneOf != null) {
|
|
2018
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
2019
|
+
}
|
|
2020
|
+
if (schema.allOf != null) {
|
|
2021
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
2022
|
+
}
|
|
2023
|
+
if (schema.definitions != null) {
|
|
2024
|
+
result.definitions = Object.fromEntries(
|
|
2025
|
+
Object.entries(schema.definitions).map(([name, definition]) => [
|
|
2026
|
+
name,
|
|
2027
|
+
sanitizeDefinition(definition)
|
|
2028
|
+
])
|
|
2029
|
+
);
|
|
2030
|
+
}
|
|
2031
|
+
if (schemaWithDefs.$defs != null) {
|
|
2032
|
+
const resultWithDefs = result;
|
|
2033
|
+
resultWithDefs.$defs = Object.fromEntries(
|
|
2034
|
+
Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
|
|
2035
|
+
name,
|
|
2036
|
+
sanitizeDefinition(definition)
|
|
2037
|
+
])
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
2041
|
+
if (schema.properties != null) {
|
|
2042
|
+
result.properties = Object.fromEntries(
|
|
2043
|
+
Object.entries(schema.properties).map(([name, definition]) => [
|
|
2044
|
+
name,
|
|
2045
|
+
sanitizeDefinition(definition)
|
|
2046
|
+
])
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
2049
|
+
result.additionalProperties = false;
|
|
2050
|
+
if (schema.required != null) {
|
|
2051
|
+
result.required = schema.required;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
if (schema.items != null) {
|
|
2055
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
2056
|
+
}
|
|
2057
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2058
|
+
result.format = schema.format;
|
|
2059
|
+
}
|
|
2060
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
2061
|
+
if (constraintDescription != null) {
|
|
2062
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
2063
|
+
${constraintDescription}`;
|
|
2064
|
+
}
|
|
2065
|
+
return result;
|
|
2066
|
+
}
|
|
2067
|
+
function getConstraintDescription(schema) {
|
|
2068
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
2069
|
+
const value = schema[key];
|
|
2070
|
+
if (value == null || value === false) {
|
|
2071
|
+
return [];
|
|
2072
|
+
}
|
|
2073
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
2074
|
+
});
|
|
2075
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2076
|
+
descriptions.push(`format: ${schema.format}`);
|
|
2077
|
+
}
|
|
2078
|
+
return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
|
|
2079
|
+
}
|
|
2080
|
+
function formatConstraintName(key) {
|
|
2081
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
2082
|
+
}
|
|
2083
|
+
function formatConstraintValue(value) {
|
|
2084
|
+
if (typeof value === "string") {
|
|
2085
|
+
return value;
|
|
2086
|
+
}
|
|
2087
|
+
return JSON.stringify(value);
|
|
2088
|
+
}
|
|
2089
|
+
function isPlainObject(value) {
|
|
2090
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2091
|
+
}
|
|
2092
|
+
|
|
1941
2093
|
// src/anthropic-messages-language-model.ts
|
|
1942
2094
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
1943
2095
|
var _a;
|
|
@@ -2144,7 +2296,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2144
2296
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2145
2297
|
format: {
|
|
2146
2298
|
type: "json_schema",
|
|
2147
|
-
schema: responseFormat.schema
|
|
2299
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
2148
2300
|
}
|
|
2149
2301
|
}
|
|
2150
2302
|
}
|
|
@@ -2161,13 +2313,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2161
2313
|
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
2162
2314
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
2163
2315
|
},
|
|
2164
|
-
// structured output:
|
|
2165
|
-
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2166
|
-
output_format: {
|
|
2167
|
-
type: "json_schema",
|
|
2168
|
-
schema: responseFormat.schema
|
|
2169
|
-
}
|
|
2170
|
-
},
|
|
2171
2316
|
// container with agent skills:
|
|
2172
2317
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2173
2318
|
container: {
|