@ai-sdk/anthropic 2.0.78 → 2.0.80
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 +16 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +257 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -20
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +250 -111
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +165 -19
- 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({
|
|
@@ -1412,19 +1418,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1412
1418
|
const type = block.type;
|
|
1413
1419
|
switch (type) {
|
|
1414
1420
|
case "system": {
|
|
1415
|
-
|
|
1416
|
-
throw new UnsupportedFunctionalityError2({
|
|
1417
|
-
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
system = block.messages.map(({ content, providerOptions }) => ({
|
|
1421
|
+
const content = block.messages.map(({ content: content2, providerOptions }) => ({
|
|
1421
1422
|
type: "text",
|
|
1422
|
-
text:
|
|
1423
|
+
text: content2,
|
|
1423
1424
|
cache_control: validator.getCacheControl(providerOptions, {
|
|
1424
1425
|
type: "system message",
|
|
1425
1426
|
canCache: true
|
|
1426
1427
|
})
|
|
1427
1428
|
}));
|
|
1429
|
+
if (system == null) {
|
|
1430
|
+
system = content;
|
|
1431
|
+
} else {
|
|
1432
|
+
messages.push({ role: "system", content });
|
|
1433
|
+
betas.add("mid-conversation-system-2026-04-07");
|
|
1434
|
+
}
|
|
1428
1435
|
break;
|
|
1429
1436
|
}
|
|
1430
1437
|
case "user": {
|
|
@@ -1938,6 +1945,152 @@ function mapAnthropicStopReason({
|
|
|
1938
1945
|
}
|
|
1939
1946
|
}
|
|
1940
1947
|
|
|
1948
|
+
// src/sanitize-json-schema.ts
|
|
1949
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
1950
|
+
"date-time",
|
|
1951
|
+
"time",
|
|
1952
|
+
"date",
|
|
1953
|
+
"duration",
|
|
1954
|
+
"email",
|
|
1955
|
+
"hostname",
|
|
1956
|
+
"uri",
|
|
1957
|
+
"ipv4",
|
|
1958
|
+
"ipv6",
|
|
1959
|
+
"uuid"
|
|
1960
|
+
]);
|
|
1961
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
1962
|
+
"minimum",
|
|
1963
|
+
"maximum",
|
|
1964
|
+
"exclusiveMinimum",
|
|
1965
|
+
"exclusiveMaximum",
|
|
1966
|
+
"multipleOf",
|
|
1967
|
+
"minLength",
|
|
1968
|
+
"maxLength",
|
|
1969
|
+
"pattern",
|
|
1970
|
+
"minItems",
|
|
1971
|
+
"maxItems",
|
|
1972
|
+
"uniqueItems",
|
|
1973
|
+
"minProperties",
|
|
1974
|
+
"maxProperties",
|
|
1975
|
+
"not"
|
|
1976
|
+
];
|
|
1977
|
+
function sanitizeJsonSchema(schema) {
|
|
1978
|
+
return sanitizeSchema(schema);
|
|
1979
|
+
}
|
|
1980
|
+
function sanitizeDefinition(definition) {
|
|
1981
|
+
if (typeof definition === "boolean" || !isPlainObject(definition)) {
|
|
1982
|
+
return definition;
|
|
1983
|
+
}
|
|
1984
|
+
return sanitizeSchema(definition);
|
|
1985
|
+
}
|
|
1986
|
+
function sanitizeSchema(schema) {
|
|
1987
|
+
const result = {};
|
|
1988
|
+
const schemaWithDefs = schema;
|
|
1989
|
+
if (schema.$ref != null) {
|
|
1990
|
+
return { $ref: schema.$ref };
|
|
1991
|
+
}
|
|
1992
|
+
if (schema.$schema != null) {
|
|
1993
|
+
result.$schema = schema.$schema;
|
|
1994
|
+
}
|
|
1995
|
+
if (schema.$id != null) {
|
|
1996
|
+
result.$id = schema.$id;
|
|
1997
|
+
}
|
|
1998
|
+
if (schema.title != null) {
|
|
1999
|
+
result.title = schema.title;
|
|
2000
|
+
}
|
|
2001
|
+
if (schema.description != null) {
|
|
2002
|
+
result.description = schema.description;
|
|
2003
|
+
}
|
|
2004
|
+
if (schema.default !== void 0) {
|
|
2005
|
+
result.default = schema.default;
|
|
2006
|
+
}
|
|
2007
|
+
if (schema.const !== void 0) {
|
|
2008
|
+
result.const = schema.const;
|
|
2009
|
+
}
|
|
2010
|
+
if (schema.enum != null) {
|
|
2011
|
+
result.enum = schema.enum;
|
|
2012
|
+
}
|
|
2013
|
+
if (schema.type != null) {
|
|
2014
|
+
result.type = schema.type;
|
|
2015
|
+
}
|
|
2016
|
+
if (schema.anyOf != null) {
|
|
2017
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
2018
|
+
} else if (schema.oneOf != null) {
|
|
2019
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
2020
|
+
}
|
|
2021
|
+
if (schema.allOf != null) {
|
|
2022
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
2023
|
+
}
|
|
2024
|
+
if (schema.definitions != null) {
|
|
2025
|
+
result.definitions = Object.fromEntries(
|
|
2026
|
+
Object.entries(schema.definitions).map(([name, definition]) => [
|
|
2027
|
+
name,
|
|
2028
|
+
sanitizeDefinition(definition)
|
|
2029
|
+
])
|
|
2030
|
+
);
|
|
2031
|
+
}
|
|
2032
|
+
if (schemaWithDefs.$defs != null) {
|
|
2033
|
+
const resultWithDefs = result;
|
|
2034
|
+
resultWithDefs.$defs = Object.fromEntries(
|
|
2035
|
+
Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
|
|
2036
|
+
name,
|
|
2037
|
+
sanitizeDefinition(definition)
|
|
2038
|
+
])
|
|
2039
|
+
);
|
|
2040
|
+
}
|
|
2041
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
2042
|
+
if (schema.properties != null) {
|
|
2043
|
+
result.properties = Object.fromEntries(
|
|
2044
|
+
Object.entries(schema.properties).map(([name, definition]) => [
|
|
2045
|
+
name,
|
|
2046
|
+
sanitizeDefinition(definition)
|
|
2047
|
+
])
|
|
2048
|
+
);
|
|
2049
|
+
}
|
|
2050
|
+
result.additionalProperties = false;
|
|
2051
|
+
if (schema.required != null) {
|
|
2052
|
+
result.required = schema.required;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
if (schema.items != null) {
|
|
2056
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
2057
|
+
}
|
|
2058
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2059
|
+
result.format = schema.format;
|
|
2060
|
+
}
|
|
2061
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
2062
|
+
if (constraintDescription != null) {
|
|
2063
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
2064
|
+
${constraintDescription}`;
|
|
2065
|
+
}
|
|
2066
|
+
return result;
|
|
2067
|
+
}
|
|
2068
|
+
function getConstraintDescription(schema) {
|
|
2069
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
2070
|
+
const value = schema[key];
|
|
2071
|
+
if (value == null || value === false) {
|
|
2072
|
+
return [];
|
|
2073
|
+
}
|
|
2074
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
2075
|
+
});
|
|
2076
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2077
|
+
descriptions.push(`format: ${schema.format}`);
|
|
2078
|
+
}
|
|
2079
|
+
return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
|
|
2080
|
+
}
|
|
2081
|
+
function formatConstraintName(key) {
|
|
2082
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
2083
|
+
}
|
|
2084
|
+
function formatConstraintValue(value) {
|
|
2085
|
+
if (typeof value === "string") {
|
|
2086
|
+
return value;
|
|
2087
|
+
}
|
|
2088
|
+
return JSON.stringify(value);
|
|
2089
|
+
}
|
|
2090
|
+
function isPlainObject(value) {
|
|
2091
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2092
|
+
}
|
|
2093
|
+
|
|
1941
2094
|
// src/anthropic-messages-language-model.ts
|
|
1942
2095
|
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
1943
2096
|
var _a;
|
|
@@ -2144,7 +2297,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2144
2297
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2145
2298
|
format: {
|
|
2146
2299
|
type: "json_schema",
|
|
2147
|
-
schema: responseFormat.schema
|
|
2300
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
2148
2301
|
}
|
|
2149
2302
|
}
|
|
2150
2303
|
}
|
|
@@ -2161,13 +2314,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2161
2314
|
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
2162
2315
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
2163
2316
|
},
|
|
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
2317
|
// container with agent skills:
|
|
2172
2318
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2173
2319
|
container: {
|
|
@@ -3308,7 +3454,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3308
3454
|
}
|
|
3309
3455
|
};
|
|
3310
3456
|
function getModelCapabilities(modelId) {
|
|
3311
|
-
if (modelId.includes("claude-opus-4-7")) {
|
|
3457
|
+
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
|
|
3312
3458
|
return {
|
|
3313
3459
|
maxOutputTokens: 128e3,
|
|
3314
3460
|
supportsStructuredOutput: true,
|