@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/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "2.0.
|
|
14
|
+
var VERSION = true ? "2.0.80" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -51,7 +51,10 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
// src/anthropic-messages-api.ts
|
|
54
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
lazySchema as lazySchema2,
|
|
56
|
+
zodSchema as zodSchema2
|
|
57
|
+
} from "@ai-sdk/provider-utils";
|
|
55
58
|
import { z as z2 } from "zod/v4";
|
|
56
59
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
57
60
|
() => zodSchema2(
|
|
@@ -839,9 +842,12 @@ var CacheControlValidator = class {
|
|
|
839
842
|
};
|
|
840
843
|
|
|
841
844
|
// src/tool/text-editor_20250728.ts
|
|
842
|
-
import {
|
|
845
|
+
import {
|
|
846
|
+
createProviderDefinedToolFactory,
|
|
847
|
+
lazySchema as lazySchema3,
|
|
848
|
+
zodSchema as zodSchema3
|
|
849
|
+
} from "@ai-sdk/provider-utils";
|
|
843
850
|
import { z as z4 } from "zod/v4";
|
|
844
|
-
import { lazySchema as lazySchema3, zodSchema as zodSchema3 } from "@ai-sdk/provider-utils";
|
|
845
851
|
var textEditor_20250728ArgsSchema = lazySchema3(
|
|
846
852
|
() => zodSchema3(
|
|
847
853
|
z4.object({
|
|
@@ -1427,19 +1433,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1427
1433
|
const type = block.type;
|
|
1428
1434
|
switch (type) {
|
|
1429
1435
|
case "system": {
|
|
1430
|
-
|
|
1431
|
-
throw new UnsupportedFunctionalityError2({
|
|
1432
|
-
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
1433
|
-
});
|
|
1434
|
-
}
|
|
1435
|
-
system = block.messages.map(({ content, providerOptions }) => ({
|
|
1436
|
+
const content = block.messages.map(({ content: content2, providerOptions }) => ({
|
|
1436
1437
|
type: "text",
|
|
1437
|
-
text:
|
|
1438
|
+
text: content2,
|
|
1438
1439
|
cache_control: validator.getCacheControl(providerOptions, {
|
|
1439
1440
|
type: "system message",
|
|
1440
1441
|
canCache: true
|
|
1441
1442
|
})
|
|
1442
1443
|
}));
|
|
1444
|
+
if (system == null) {
|
|
1445
|
+
system = content;
|
|
1446
|
+
} else {
|
|
1447
|
+
messages.push({ role: "system", content });
|
|
1448
|
+
betas.add("mid-conversation-system-2026-04-07");
|
|
1449
|
+
}
|
|
1443
1450
|
break;
|
|
1444
1451
|
}
|
|
1445
1452
|
case "user": {
|
|
@@ -1953,6 +1960,152 @@ function mapAnthropicStopReason({
|
|
|
1953
1960
|
}
|
|
1954
1961
|
}
|
|
1955
1962
|
|
|
1963
|
+
// src/sanitize-json-schema.ts
|
|
1964
|
+
var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
|
|
1965
|
+
"date-time",
|
|
1966
|
+
"time",
|
|
1967
|
+
"date",
|
|
1968
|
+
"duration",
|
|
1969
|
+
"email",
|
|
1970
|
+
"hostname",
|
|
1971
|
+
"uri",
|
|
1972
|
+
"ipv4",
|
|
1973
|
+
"ipv6",
|
|
1974
|
+
"uuid"
|
|
1975
|
+
]);
|
|
1976
|
+
var DESCRIPTION_CONSTRAINT_KEYS = [
|
|
1977
|
+
"minimum",
|
|
1978
|
+
"maximum",
|
|
1979
|
+
"exclusiveMinimum",
|
|
1980
|
+
"exclusiveMaximum",
|
|
1981
|
+
"multipleOf",
|
|
1982
|
+
"minLength",
|
|
1983
|
+
"maxLength",
|
|
1984
|
+
"pattern",
|
|
1985
|
+
"minItems",
|
|
1986
|
+
"maxItems",
|
|
1987
|
+
"uniqueItems",
|
|
1988
|
+
"minProperties",
|
|
1989
|
+
"maxProperties",
|
|
1990
|
+
"not"
|
|
1991
|
+
];
|
|
1992
|
+
function sanitizeJsonSchema(schema) {
|
|
1993
|
+
return sanitizeSchema(schema);
|
|
1994
|
+
}
|
|
1995
|
+
function sanitizeDefinition(definition) {
|
|
1996
|
+
if (typeof definition === "boolean" || !isPlainObject(definition)) {
|
|
1997
|
+
return definition;
|
|
1998
|
+
}
|
|
1999
|
+
return sanitizeSchema(definition);
|
|
2000
|
+
}
|
|
2001
|
+
function sanitizeSchema(schema) {
|
|
2002
|
+
const result = {};
|
|
2003
|
+
const schemaWithDefs = schema;
|
|
2004
|
+
if (schema.$ref != null) {
|
|
2005
|
+
return { $ref: schema.$ref };
|
|
2006
|
+
}
|
|
2007
|
+
if (schema.$schema != null) {
|
|
2008
|
+
result.$schema = schema.$schema;
|
|
2009
|
+
}
|
|
2010
|
+
if (schema.$id != null) {
|
|
2011
|
+
result.$id = schema.$id;
|
|
2012
|
+
}
|
|
2013
|
+
if (schema.title != null) {
|
|
2014
|
+
result.title = schema.title;
|
|
2015
|
+
}
|
|
2016
|
+
if (schema.description != null) {
|
|
2017
|
+
result.description = schema.description;
|
|
2018
|
+
}
|
|
2019
|
+
if (schema.default !== void 0) {
|
|
2020
|
+
result.default = schema.default;
|
|
2021
|
+
}
|
|
2022
|
+
if (schema.const !== void 0) {
|
|
2023
|
+
result.const = schema.const;
|
|
2024
|
+
}
|
|
2025
|
+
if (schema.enum != null) {
|
|
2026
|
+
result.enum = schema.enum;
|
|
2027
|
+
}
|
|
2028
|
+
if (schema.type != null) {
|
|
2029
|
+
result.type = schema.type;
|
|
2030
|
+
}
|
|
2031
|
+
if (schema.anyOf != null) {
|
|
2032
|
+
result.anyOf = schema.anyOf.map(sanitizeDefinition);
|
|
2033
|
+
} else if (schema.oneOf != null) {
|
|
2034
|
+
result.anyOf = schema.oneOf.map(sanitizeDefinition);
|
|
2035
|
+
}
|
|
2036
|
+
if (schema.allOf != null) {
|
|
2037
|
+
result.allOf = schema.allOf.map(sanitizeDefinition);
|
|
2038
|
+
}
|
|
2039
|
+
if (schema.definitions != null) {
|
|
2040
|
+
result.definitions = Object.fromEntries(
|
|
2041
|
+
Object.entries(schema.definitions).map(([name, definition]) => [
|
|
2042
|
+
name,
|
|
2043
|
+
sanitizeDefinition(definition)
|
|
2044
|
+
])
|
|
2045
|
+
);
|
|
2046
|
+
}
|
|
2047
|
+
if (schemaWithDefs.$defs != null) {
|
|
2048
|
+
const resultWithDefs = result;
|
|
2049
|
+
resultWithDefs.$defs = Object.fromEntries(
|
|
2050
|
+
Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
|
|
2051
|
+
name,
|
|
2052
|
+
sanitizeDefinition(definition)
|
|
2053
|
+
])
|
|
2054
|
+
);
|
|
2055
|
+
}
|
|
2056
|
+
if (schema.type === "object" || schema.properties != null) {
|
|
2057
|
+
if (schema.properties != null) {
|
|
2058
|
+
result.properties = Object.fromEntries(
|
|
2059
|
+
Object.entries(schema.properties).map(([name, definition]) => [
|
|
2060
|
+
name,
|
|
2061
|
+
sanitizeDefinition(definition)
|
|
2062
|
+
])
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
2065
|
+
result.additionalProperties = false;
|
|
2066
|
+
if (schema.required != null) {
|
|
2067
|
+
result.required = schema.required;
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
if (schema.items != null) {
|
|
2071
|
+
result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
|
|
2072
|
+
}
|
|
2073
|
+
if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2074
|
+
result.format = schema.format;
|
|
2075
|
+
}
|
|
2076
|
+
const constraintDescription = getConstraintDescription(schema);
|
|
2077
|
+
if (constraintDescription != null) {
|
|
2078
|
+
result.description = result.description == null ? constraintDescription : `${result.description}
|
|
2079
|
+
${constraintDescription}`;
|
|
2080
|
+
}
|
|
2081
|
+
return result;
|
|
2082
|
+
}
|
|
2083
|
+
function getConstraintDescription(schema) {
|
|
2084
|
+
const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
|
|
2085
|
+
const value = schema[key];
|
|
2086
|
+
if (value == null || value === false) {
|
|
2087
|
+
return [];
|
|
2088
|
+
}
|
|
2089
|
+
return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
|
|
2090
|
+
});
|
|
2091
|
+
if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
|
|
2092
|
+
descriptions.push(`format: ${schema.format}`);
|
|
2093
|
+
}
|
|
2094
|
+
return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
|
|
2095
|
+
}
|
|
2096
|
+
function formatConstraintName(key) {
|
|
2097
|
+
return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
|
|
2098
|
+
}
|
|
2099
|
+
function formatConstraintValue(value) {
|
|
2100
|
+
if (typeof value === "string") {
|
|
2101
|
+
return value;
|
|
2102
|
+
}
|
|
2103
|
+
return JSON.stringify(value);
|
|
2104
|
+
}
|
|
2105
|
+
function isPlainObject(value) {
|
|
2106
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2107
|
+
}
|
|
2108
|
+
|
|
1956
2109
|
// src/anthropic-messages-language-model.ts
|
|
1957
2110
|
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
1958
2111
|
var _a;
|
|
@@ -2159,7 +2312,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2159
2312
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2160
2313
|
format: {
|
|
2161
2314
|
type: "json_schema",
|
|
2162
|
-
schema: responseFormat.schema
|
|
2315
|
+
schema: sanitizeJsonSchema(responseFormat.schema)
|
|
2163
2316
|
}
|
|
2164
2317
|
}
|
|
2165
2318
|
}
|
|
@@ -2176,13 +2329,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2176
2329
|
...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
|
|
2177
2330
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
2178
2331
|
},
|
|
2179
|
-
// structured output:
|
|
2180
|
-
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2181
|
-
output_format: {
|
|
2182
|
-
type: "json_schema",
|
|
2183
|
-
schema: responseFormat.schema
|
|
2184
|
-
}
|
|
2185
|
-
},
|
|
2186
2332
|
// container with agent skills:
|
|
2187
2333
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2188
2334
|
container: {
|
|
@@ -3323,7 +3469,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3323
3469
|
}
|
|
3324
3470
|
};
|
|
3325
3471
|
function getModelCapabilities(modelId) {
|
|
3326
|
-
if (modelId.includes("claude-opus-4-7")) {
|
|
3472
|
+
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
|
|
3327
3473
|
return {
|
|
3328
3474
|
maxOutputTokens: 128e3,
|
|
3329
3475
|
supportsStructuredOutput: true,
|