@ai-sdk/anthropic 2.0.77 → 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/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.77" : "0.0.0-test";
14
+ var VERSION = true ? "2.0.79" : "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 { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
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 { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
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({
@@ -1953,6 +1959,152 @@ function mapAnthropicStopReason({
1953
1959
  }
1954
1960
  }
1955
1961
 
1962
+ // src/sanitize-json-schema.ts
1963
+ var SUPPORTED_STRING_FORMATS = /* @__PURE__ */ new Set([
1964
+ "date-time",
1965
+ "time",
1966
+ "date",
1967
+ "duration",
1968
+ "email",
1969
+ "hostname",
1970
+ "uri",
1971
+ "ipv4",
1972
+ "ipv6",
1973
+ "uuid"
1974
+ ]);
1975
+ var DESCRIPTION_CONSTRAINT_KEYS = [
1976
+ "minimum",
1977
+ "maximum",
1978
+ "exclusiveMinimum",
1979
+ "exclusiveMaximum",
1980
+ "multipleOf",
1981
+ "minLength",
1982
+ "maxLength",
1983
+ "pattern",
1984
+ "minItems",
1985
+ "maxItems",
1986
+ "uniqueItems",
1987
+ "minProperties",
1988
+ "maxProperties",
1989
+ "not"
1990
+ ];
1991
+ function sanitizeJsonSchema(schema) {
1992
+ return sanitizeSchema(schema);
1993
+ }
1994
+ function sanitizeDefinition(definition) {
1995
+ if (typeof definition === "boolean" || !isPlainObject(definition)) {
1996
+ return definition;
1997
+ }
1998
+ return sanitizeSchema(definition);
1999
+ }
2000
+ function sanitizeSchema(schema) {
2001
+ const result = {};
2002
+ const schemaWithDefs = schema;
2003
+ if (schema.$ref != null) {
2004
+ return { $ref: schema.$ref };
2005
+ }
2006
+ if (schema.$schema != null) {
2007
+ result.$schema = schema.$schema;
2008
+ }
2009
+ if (schema.$id != null) {
2010
+ result.$id = schema.$id;
2011
+ }
2012
+ if (schema.title != null) {
2013
+ result.title = schema.title;
2014
+ }
2015
+ if (schema.description != null) {
2016
+ result.description = schema.description;
2017
+ }
2018
+ if (schema.default !== void 0) {
2019
+ result.default = schema.default;
2020
+ }
2021
+ if (schema.const !== void 0) {
2022
+ result.const = schema.const;
2023
+ }
2024
+ if (schema.enum != null) {
2025
+ result.enum = schema.enum;
2026
+ }
2027
+ if (schema.type != null) {
2028
+ result.type = schema.type;
2029
+ }
2030
+ if (schema.anyOf != null) {
2031
+ result.anyOf = schema.anyOf.map(sanitizeDefinition);
2032
+ } else if (schema.oneOf != null) {
2033
+ result.anyOf = schema.oneOf.map(sanitizeDefinition);
2034
+ }
2035
+ if (schema.allOf != null) {
2036
+ result.allOf = schema.allOf.map(sanitizeDefinition);
2037
+ }
2038
+ if (schema.definitions != null) {
2039
+ result.definitions = Object.fromEntries(
2040
+ Object.entries(schema.definitions).map(([name, definition]) => [
2041
+ name,
2042
+ sanitizeDefinition(definition)
2043
+ ])
2044
+ );
2045
+ }
2046
+ if (schemaWithDefs.$defs != null) {
2047
+ const resultWithDefs = result;
2048
+ resultWithDefs.$defs = Object.fromEntries(
2049
+ Object.entries(schemaWithDefs.$defs).map(([name, definition]) => [
2050
+ name,
2051
+ sanitizeDefinition(definition)
2052
+ ])
2053
+ );
2054
+ }
2055
+ if (schema.type === "object" || schema.properties != null) {
2056
+ if (schema.properties != null) {
2057
+ result.properties = Object.fromEntries(
2058
+ Object.entries(schema.properties).map(([name, definition]) => [
2059
+ name,
2060
+ sanitizeDefinition(definition)
2061
+ ])
2062
+ );
2063
+ }
2064
+ result.additionalProperties = false;
2065
+ if (schema.required != null) {
2066
+ result.required = schema.required;
2067
+ }
2068
+ }
2069
+ if (schema.items != null) {
2070
+ result.items = Array.isArray(schema.items) ? schema.items.map(sanitizeDefinition) : sanitizeDefinition(schema.items);
2071
+ }
2072
+ if (typeof schema.format === "string" && SUPPORTED_STRING_FORMATS.has(schema.format)) {
2073
+ result.format = schema.format;
2074
+ }
2075
+ const constraintDescription = getConstraintDescription(schema);
2076
+ if (constraintDescription != null) {
2077
+ result.description = result.description == null ? constraintDescription : `${result.description}
2078
+ ${constraintDescription}`;
2079
+ }
2080
+ return result;
2081
+ }
2082
+ function getConstraintDescription(schema) {
2083
+ const descriptions = DESCRIPTION_CONSTRAINT_KEYS.flatMap((key) => {
2084
+ const value = schema[key];
2085
+ if (value == null || value === false) {
2086
+ return [];
2087
+ }
2088
+ return `${formatConstraintName(key)}: ${formatConstraintValue(value)}`;
2089
+ });
2090
+ if (typeof schema.format === "string" && !SUPPORTED_STRING_FORMATS.has(schema.format)) {
2091
+ descriptions.push(`format: ${schema.format}`);
2092
+ }
2093
+ return descriptions.length === 0 ? void 0 : `${descriptions.join("; ")}.`;
2094
+ }
2095
+ function formatConstraintName(key) {
2096
+ return key.replace(/[A-Z]/g, (match) => ` ${match.toLowerCase()}`);
2097
+ }
2098
+ function formatConstraintValue(value) {
2099
+ if (typeof value === "string") {
2100
+ return value;
2101
+ }
2102
+ return JSON.stringify(value);
2103
+ }
2104
+ function isPlainObject(value) {
2105
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2106
+ }
2107
+
1956
2108
  // src/anthropic-messages-language-model.ts
1957
2109
  function createCitationSource(citation, citationDocuments, generateId3) {
1958
2110
  var _a;
@@ -2159,7 +2311,7 @@ var AnthropicMessagesLanguageModel = class {
2159
2311
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
2160
2312
  format: {
2161
2313
  type: "json_schema",
2162
- schema: responseFormat.schema
2314
+ schema: sanitizeJsonSchema(responseFormat.schema)
2163
2315
  }
2164
2316
  }
2165
2317
  }
@@ -2176,13 +2328,6 @@ var AnthropicMessagesLanguageModel = class {
2176
2328
  ...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
2177
2329
  metadata: { user_id: anthropicOptions.metadata.userId }
2178
2330
  },
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
2331
  // container with agent skills:
2187
2332
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2188
2333
  container: {