@flatfile/anthropic
Advanced tools
| var __defProp = Object.defineProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| export { | ||
| __export, | ||
| __publicField, | ||
| __privateGet, | ||
| __privateAdd, | ||
| __privateSet | ||
| }; | ||
| //# sourceMappingURL=chunk-QQOYFPRJ.mjs.map |
| {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} |
| import "./chunk-QQOYFPRJ.mjs"; | ||
| // ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.8.3/node_modules/valibot/dist/index.js | ||
| // @__NO_SIDE_EFFECTS__ | ||
| function getDefault(schema, dataset, config2) { | ||
| return typeof schema.default === "function" ? ( | ||
| // @ts-expect-error | ||
| schema.default(dataset, config2) | ||
| ) : ( | ||
| // @ts-expect-error | ||
| schema.default | ||
| ); | ||
| } | ||
| // ../../node_modules/.pnpm/@valibot+to-json-schema@1.3.0_valibot@1.1.0/node_modules/@valibot/to-json-schema/dist/index.js | ||
| function addError(errors, message) { | ||
| if (errors) { | ||
| errors.push(message); | ||
| return errors; | ||
| } | ||
| return [message]; | ||
| } | ||
| function handleError(message, config) { | ||
| switch (config == null ? void 0 : config.errorMode) { | ||
| case "ignore": | ||
| break; | ||
| case "warn": { | ||
| console.warn(message); | ||
| break; | ||
| } | ||
| default: | ||
| throw new Error(message); | ||
| } | ||
| } | ||
| function convertAction(jsonSchema, valibotAction, config) { | ||
| var _a; | ||
| if ((_a = config == null ? void 0 : config.ignoreActions) == null ? void 0 : _a.includes(valibotAction.type)) return jsonSchema; | ||
| let errors; | ||
| switch (valibotAction.type) { | ||
| case "base64": { | ||
| jsonSchema.contentEncoding = "base64"; | ||
| break; | ||
| } | ||
| case "bic": | ||
| case "cuid2": | ||
| case "decimal": | ||
| case "digits": | ||
| case "emoji": | ||
| case "hexadecimal": | ||
| case "hex_color": | ||
| case "nanoid": | ||
| case "octal": | ||
| case "ulid": { | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "description": { | ||
| jsonSchema.description = valibotAction.description; | ||
| break; | ||
| } | ||
| case "email": { | ||
| jsonSchema.format = "email"; | ||
| break; | ||
| } | ||
| case "empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = 0; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = 0; | ||
| } | ||
| break; | ||
| } | ||
| case "entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "integer": { | ||
| jsonSchema.type = "integer"; | ||
| break; | ||
| } | ||
| case "ipv4": { | ||
| jsonSchema.format = "ipv4"; | ||
| break; | ||
| } | ||
| case "ipv6": { | ||
| jsonSchema.format = "ipv6"; | ||
| break; | ||
| } | ||
| case "iso_date": { | ||
| jsonSchema.format = "date"; | ||
| break; | ||
| } | ||
| case "iso_date_time": | ||
| case "iso_timestamp": { | ||
| jsonSchema.format = "date-time"; | ||
| break; | ||
| } | ||
| case "iso_time": { | ||
| jsonSchema.format = "time"; | ||
| break; | ||
| } | ||
| case "length": { | ||
| if (jsonSchema.type === "array") { | ||
| jsonSchema.minItems = valibotAction.requirement; | ||
| jsonSchema.maxItems = valibotAction.requirement; | ||
| } else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_entries": { | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "max_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maximum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "metadata": { | ||
| if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title; | ||
| if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description; | ||
| if (Array.isArray(valibotAction.metadata.examples)) jsonSchema.examples = valibotAction.metadata.examples; | ||
| break; | ||
| } | ||
| case "min_entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "min_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "min_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minimum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "multiple_of": { | ||
| jsonSchema.multipleOf = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "non_empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = 1; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = 1; | ||
| } | ||
| break; | ||
| } | ||
| case "regex": { | ||
| if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema."); | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "title": { | ||
| jsonSchema.title = valibotAction.title; | ||
| break; | ||
| } | ||
| case "url": { | ||
| jsonSchema.format = "uri"; | ||
| break; | ||
| } | ||
| case "uuid": { | ||
| jsonSchema.format = "uuid"; | ||
| break; | ||
| } | ||
| case "value": { | ||
| jsonSchema.const = valibotAction.requirement; | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideAction) { | ||
| const actionOverride = config.overrideAction({ | ||
| valibotAction, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (actionOverride) return { ...actionOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| function flattenPipe(pipe) { | ||
| return pipe.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item); | ||
| } | ||
| var refCount = 0; | ||
| function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) { | ||
| if (!skipRef) { | ||
| const referenceId = context.referenceMap.get(valibotSchema); | ||
| if (referenceId) { | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| } | ||
| if ("pipe" in valibotSchema) { | ||
| const flatPipe = flattenPipe(valibotSchema.pipe); | ||
| let startIndex = 0; | ||
| let stopIndex = flatPipe.length - 1; | ||
| if ((config == null ? void 0 : config.typeMode) === "input") { | ||
| const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "transform")); | ||
| if (inputStopIndex !== -1) stopIndex = inputStopIndex; | ||
| } else if ((config == null ? void 0 : config.typeMode) === "output") { | ||
| const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema"); | ||
| if (outputStartIndex !== -1) startIndex = outputStartIndex; | ||
| } | ||
| for (let index = startIndex; index <= stopIndex; index++) { | ||
| const valibotPipeItem = flatPipe[index]; | ||
| if (valibotPipeItem.kind === "schema") { | ||
| if (index > startIndex) handleError('Set the "typeMode" config to "input" or "output" to convert pipelines with multiple schemas.', config); | ||
| jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true); | ||
| } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config); | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| let errors; | ||
| switch (valibotSchema.type) { | ||
| case "boolean": { | ||
| jsonSchema.type = "boolean"; | ||
| break; | ||
| } | ||
| case "null": { | ||
| jsonSchema.type = "null"; | ||
| break; | ||
| } | ||
| case "number": { | ||
| jsonSchema.type = "number"; | ||
| break; | ||
| } | ||
| case "string": { | ||
| jsonSchema.type = "string"; | ||
| break; | ||
| } | ||
| case "array": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = convertSchema({}, valibotSchema.item, config, context); | ||
| break; | ||
| } | ||
| case "tuple": | ||
| case "tuple_with_rest": | ||
| case "loose_tuple": | ||
| case "strict_tuple": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = []; | ||
| jsonSchema.minItems = valibotSchema.items.length; | ||
| for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context)); | ||
| if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false; | ||
| break; | ||
| } | ||
| case "object": | ||
| case "object_with_rest": | ||
| case "loose_object": | ||
| case "strict_object": { | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.properties = {}; | ||
| jsonSchema.required = []; | ||
| for (const key in valibotSchema.entries) { | ||
| const entry = valibotSchema.entries[key]; | ||
| jsonSchema.properties[key] = convertSchema({}, entry, config, context); | ||
| if (entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key); | ||
| } | ||
| if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false; | ||
| break; | ||
| } | ||
| case "record": { | ||
| if ("pipe" in valibotSchema.key) errors = addError(errors, 'The "record" schema with a schema for the key that contains a "pipe" cannot be converted to JSON Schema.'); | ||
| if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`); | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context); | ||
| break; | ||
| } | ||
| case "any": | ||
| case "unknown": | ||
| break; | ||
| case "nullable": | ||
| case "nullish": { | ||
| jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }]; | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "exact_optional": | ||
| case "optional": | ||
| case "undefinedable": { | ||
| jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context); | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "literal": { | ||
| if (typeof valibotSchema.literal !== "boolean" && typeof valibotSchema.literal !== "number" && typeof valibotSchema.literal !== "string") errors = addError(errors, 'The value of the "literal" schema is not JSON compatible.'); | ||
| jsonSchema.const = valibotSchema.literal; | ||
| break; | ||
| } | ||
| case "enum": { | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "picklist": { | ||
| if (valibotSchema.options.some((option) => typeof option !== "number" && typeof option !== "string")) errors = addError(errors, 'An option of the "picklist" schema is not JSON compatible.'); | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "union": | ||
| case "variant": { | ||
| jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "intersect": { | ||
| jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "lazy": { | ||
| let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter); | ||
| if (!wrappedValibotSchema) { | ||
| wrappedValibotSchema = valibotSchema.getter(void 0); | ||
| context.getterMap.set(valibotSchema.getter, wrappedValibotSchema); | ||
| } | ||
| let referenceId = context.referenceMap.get(wrappedValibotSchema); | ||
| if (!referenceId) { | ||
| referenceId = `${refCount++}`; | ||
| context.referenceMap.set(wrappedValibotSchema, referenceId); | ||
| context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true); | ||
| } | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema: wrappedValibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideSchema) { | ||
| const schemaOverride = config.overrideSchema({ | ||
| ...context, | ||
| referenceId: context.referenceMap.get(valibotSchema), | ||
| valibotSchema, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (schemaOverride) return { ...schemaOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| var store; | ||
| function addGlobalDefs(definitions) { | ||
| store = { | ||
| ...store != null ? store : {}, | ||
| ...definitions | ||
| }; | ||
| } | ||
| function getGlobalDefs() { | ||
| return store; | ||
| } | ||
| function toJsonSchema(schema, config) { | ||
| var _a; | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| const definitions = (_a = config == null ? void 0 : config.definitions) != null ? _a : getGlobalDefs(); | ||
| if (definitions) { | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| } | ||
| const jsonSchema = convertSchema({ $schema: "http://json-schema.org/draft-07/schema#" }, schema, config, context); | ||
| if (context.referenceMap.size) jsonSchema.$defs = context.definitions; | ||
| return jsonSchema; | ||
| } | ||
| function toJsonSchemaDefs(definitions, config) { | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| return context.definitions; | ||
| } | ||
| export { | ||
| addGlobalDefs, | ||
| getGlobalDefs, | ||
| toJsonSchema, | ||
| toJsonSchemaDefs | ||
| }; | ||
| //# sourceMappingURL=dist-GPWRCAXD.mjs.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| var __defProp = Object.defineProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| export { | ||
| __export, | ||
| __publicField, | ||
| __privateGet, | ||
| __privateAdd, | ||
| __privateSet | ||
| }; | ||
| //# sourceMappingURL=chunk-QQOYFPRJ.mjs.map |
| {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} |
| import "./chunk-QQOYFPRJ.mjs"; | ||
| // ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.8.3/node_modules/valibot/dist/index.js | ||
| // @__NO_SIDE_EFFECTS__ | ||
| function getDefault(schema, dataset, config2) { | ||
| return typeof schema.default === "function" ? ( | ||
| // @ts-expect-error | ||
| schema.default(dataset, config2) | ||
| ) : ( | ||
| // @ts-expect-error | ||
| schema.default | ||
| ); | ||
| } | ||
| // ../../node_modules/.pnpm/@valibot+to-json-schema@1.3.0_valibot@1.1.0/node_modules/@valibot/to-json-schema/dist/index.js | ||
| function addError(errors, message) { | ||
| if (errors) { | ||
| errors.push(message); | ||
| return errors; | ||
| } | ||
| return [message]; | ||
| } | ||
| function handleError(message, config) { | ||
| switch (config == null ? void 0 : config.errorMode) { | ||
| case "ignore": | ||
| break; | ||
| case "warn": { | ||
| console.warn(message); | ||
| break; | ||
| } | ||
| default: | ||
| throw new Error(message); | ||
| } | ||
| } | ||
| function convertAction(jsonSchema, valibotAction, config) { | ||
| var _a; | ||
| if ((_a = config == null ? void 0 : config.ignoreActions) == null ? void 0 : _a.includes(valibotAction.type)) return jsonSchema; | ||
| let errors; | ||
| switch (valibotAction.type) { | ||
| case "base64": { | ||
| jsonSchema.contentEncoding = "base64"; | ||
| break; | ||
| } | ||
| case "bic": | ||
| case "cuid2": | ||
| case "decimal": | ||
| case "digits": | ||
| case "emoji": | ||
| case "hexadecimal": | ||
| case "hex_color": | ||
| case "nanoid": | ||
| case "octal": | ||
| case "ulid": { | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "description": { | ||
| jsonSchema.description = valibotAction.description; | ||
| break; | ||
| } | ||
| case "email": { | ||
| jsonSchema.format = "email"; | ||
| break; | ||
| } | ||
| case "empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = 0; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = 0; | ||
| } | ||
| break; | ||
| } | ||
| case "entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "integer": { | ||
| jsonSchema.type = "integer"; | ||
| break; | ||
| } | ||
| case "ipv4": { | ||
| jsonSchema.format = "ipv4"; | ||
| break; | ||
| } | ||
| case "ipv6": { | ||
| jsonSchema.format = "ipv6"; | ||
| break; | ||
| } | ||
| case "iso_date": { | ||
| jsonSchema.format = "date"; | ||
| break; | ||
| } | ||
| case "iso_date_time": | ||
| case "iso_timestamp": { | ||
| jsonSchema.format = "date-time"; | ||
| break; | ||
| } | ||
| case "iso_time": { | ||
| jsonSchema.format = "time"; | ||
| break; | ||
| } | ||
| case "length": { | ||
| if (jsonSchema.type === "array") { | ||
| jsonSchema.minItems = valibotAction.requirement; | ||
| jsonSchema.maxItems = valibotAction.requirement; | ||
| } else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_entries": { | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "max_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maximum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "metadata": { | ||
| if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title; | ||
| if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description; | ||
| if (Array.isArray(valibotAction.metadata.examples)) jsonSchema.examples = valibotAction.metadata.examples; | ||
| break; | ||
| } | ||
| case "min_entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "min_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "min_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minimum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "multiple_of": { | ||
| jsonSchema.multipleOf = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "non_empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = 1; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = 1; | ||
| } | ||
| break; | ||
| } | ||
| case "regex": { | ||
| if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema."); | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "title": { | ||
| jsonSchema.title = valibotAction.title; | ||
| break; | ||
| } | ||
| case "url": { | ||
| jsonSchema.format = "uri"; | ||
| break; | ||
| } | ||
| case "uuid": { | ||
| jsonSchema.format = "uuid"; | ||
| break; | ||
| } | ||
| case "value": { | ||
| jsonSchema.const = valibotAction.requirement; | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideAction) { | ||
| const actionOverride = config.overrideAction({ | ||
| valibotAction, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (actionOverride) return { ...actionOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| function flattenPipe(pipe) { | ||
| return pipe.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item); | ||
| } | ||
| var refCount = 0; | ||
| function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) { | ||
| if (!skipRef) { | ||
| const referenceId = context.referenceMap.get(valibotSchema); | ||
| if (referenceId) { | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| } | ||
| if ("pipe" in valibotSchema) { | ||
| const flatPipe = flattenPipe(valibotSchema.pipe); | ||
| let startIndex = 0; | ||
| let stopIndex = flatPipe.length - 1; | ||
| if ((config == null ? void 0 : config.typeMode) === "input") { | ||
| const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "transform")); | ||
| if (inputStopIndex !== -1) stopIndex = inputStopIndex; | ||
| } else if ((config == null ? void 0 : config.typeMode) === "output") { | ||
| const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema"); | ||
| if (outputStartIndex !== -1) startIndex = outputStartIndex; | ||
| } | ||
| for (let index = startIndex; index <= stopIndex; index++) { | ||
| const valibotPipeItem = flatPipe[index]; | ||
| if (valibotPipeItem.kind === "schema") { | ||
| if (index > startIndex) handleError('Set the "typeMode" config to "input" or "output" to convert pipelines with multiple schemas.', config); | ||
| jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true); | ||
| } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config); | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| let errors; | ||
| switch (valibotSchema.type) { | ||
| case "boolean": { | ||
| jsonSchema.type = "boolean"; | ||
| break; | ||
| } | ||
| case "null": { | ||
| jsonSchema.type = "null"; | ||
| break; | ||
| } | ||
| case "number": { | ||
| jsonSchema.type = "number"; | ||
| break; | ||
| } | ||
| case "string": { | ||
| jsonSchema.type = "string"; | ||
| break; | ||
| } | ||
| case "array": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = convertSchema({}, valibotSchema.item, config, context); | ||
| break; | ||
| } | ||
| case "tuple": | ||
| case "tuple_with_rest": | ||
| case "loose_tuple": | ||
| case "strict_tuple": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = []; | ||
| jsonSchema.minItems = valibotSchema.items.length; | ||
| for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context)); | ||
| if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false; | ||
| break; | ||
| } | ||
| case "object": | ||
| case "object_with_rest": | ||
| case "loose_object": | ||
| case "strict_object": { | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.properties = {}; | ||
| jsonSchema.required = []; | ||
| for (const key in valibotSchema.entries) { | ||
| const entry = valibotSchema.entries[key]; | ||
| jsonSchema.properties[key] = convertSchema({}, entry, config, context); | ||
| if (entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key); | ||
| } | ||
| if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false; | ||
| break; | ||
| } | ||
| case "record": { | ||
| if ("pipe" in valibotSchema.key) errors = addError(errors, 'The "record" schema with a schema for the key that contains a "pipe" cannot be converted to JSON Schema.'); | ||
| if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`); | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context); | ||
| break; | ||
| } | ||
| case "any": | ||
| case "unknown": | ||
| break; | ||
| case "nullable": | ||
| case "nullish": { | ||
| jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }]; | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "exact_optional": | ||
| case "optional": | ||
| case "undefinedable": { | ||
| jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context); | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "literal": { | ||
| if (typeof valibotSchema.literal !== "boolean" && typeof valibotSchema.literal !== "number" && typeof valibotSchema.literal !== "string") errors = addError(errors, 'The value of the "literal" schema is not JSON compatible.'); | ||
| jsonSchema.const = valibotSchema.literal; | ||
| break; | ||
| } | ||
| case "enum": { | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "picklist": { | ||
| if (valibotSchema.options.some((option) => typeof option !== "number" && typeof option !== "string")) errors = addError(errors, 'An option of the "picklist" schema is not JSON compatible.'); | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "union": | ||
| case "variant": { | ||
| jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "intersect": { | ||
| jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "lazy": { | ||
| let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter); | ||
| if (!wrappedValibotSchema) { | ||
| wrappedValibotSchema = valibotSchema.getter(void 0); | ||
| context.getterMap.set(valibotSchema.getter, wrappedValibotSchema); | ||
| } | ||
| let referenceId = context.referenceMap.get(wrappedValibotSchema); | ||
| if (!referenceId) { | ||
| referenceId = `${refCount++}`; | ||
| context.referenceMap.set(wrappedValibotSchema, referenceId); | ||
| context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true); | ||
| } | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema: wrappedValibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideSchema) { | ||
| const schemaOverride = config.overrideSchema({ | ||
| ...context, | ||
| referenceId: context.referenceMap.get(valibotSchema), | ||
| valibotSchema, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (schemaOverride) return { ...schemaOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| var store; | ||
| function addGlobalDefs(definitions) { | ||
| store = { | ||
| ...store != null ? store : {}, | ||
| ...definitions | ||
| }; | ||
| } | ||
| function getGlobalDefs() { | ||
| return store; | ||
| } | ||
| function toJsonSchema(schema, config) { | ||
| var _a; | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| const definitions = (_a = config == null ? void 0 : config.definitions) != null ? _a : getGlobalDefs(); | ||
| if (definitions) { | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| } | ||
| const jsonSchema = convertSchema({ $schema: "http://json-schema.org/draft-07/schema#" }, schema, config, context); | ||
| if (context.referenceMap.size) jsonSchema.$defs = context.definitions; | ||
| return jsonSchema; | ||
| } | ||
| function toJsonSchemaDefs(definitions, config) { | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| return context.definitions; | ||
| } | ||
| export { | ||
| addGlobalDefs, | ||
| getGlobalDefs, | ||
| toJsonSchema, | ||
| toJsonSchemaDefs | ||
| }; | ||
| //# sourceMappingURL=dist-UD37EB3F.mjs.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
+1458
-30
@@ -1,5 +0,1434 @@ | ||
| import { LanguageModelV3, JSONSchema7, LanguageModelV3CallOptions, LanguageModelV3CallWarning } from '@ai-sdk/provider'; | ||
| import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils'; | ||
| import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils'; | ||
| import { JSONSchema7 } from 'json-schema'; | ||
| /** | ||
| A JSON value can be a string, number, boolean, object, array, or null. | ||
| JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods. | ||
| */ | ||
| type JSONValue = null | string | number | boolean | JSONObject | JSONArray; | ||
| type JSONObject = { | ||
| [key: string]: JSONValue; | ||
| }; | ||
| type JSONArray = JSONValue[]; | ||
| /** | ||
| * Additional provider-specific options. | ||
| * Options are additional input to the provider. | ||
| * They are passed through to the provider from the AI SDK | ||
| * and enable provider-specific functionality | ||
| * that can be fully encapsulated in the provider. | ||
| * | ||
| * This enables us to quickly ship provider-specific functionality | ||
| * without affecting the core AI SDK. | ||
| * | ||
| * The outer record is keyed by the provider name, and the inner | ||
| * record is keyed by the provider-specific metadata key. | ||
| * | ||
| * ```ts | ||
| * { | ||
| * "anthropic": { | ||
| * "cacheControl": { "type": "ephemeral" } | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| type SharedV3ProviderOptions = Record<string, Record<string, JSONValue>>; | ||
| type SharedV2Headers = Record<string, string>; | ||
| /** | ||
| * Additional provider-specific metadata. | ||
| * Metadata are additional outputs from the provider. | ||
| * They are passed through to the provider from the AI SDK | ||
| * and enable provider-specific functionality | ||
| * that can be fully encapsulated in the provider. | ||
| * | ||
| * This enables us to quickly ship provider-specific functionality | ||
| * without affecting the core AI SDK. | ||
| * | ||
| * The outer record is keyed by the provider name, and the inner | ||
| * record is keyed by the provider-specific metadata key. | ||
| * | ||
| * ```ts | ||
| * { | ||
| * "anthropic": { | ||
| * "cacheControl": { "type": "ephemeral" } | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>; | ||
| /** | ||
| * Additional provider-specific options. | ||
| * Options are additional input to the provider. | ||
| * They are passed through to the provider from the AI SDK | ||
| * and enable provider-specific functionality | ||
| * that can be fully encapsulated in the provider. | ||
| * | ||
| * This enables us to quickly ship provider-specific functionality | ||
| * without affecting the core AI SDK. | ||
| * | ||
| * The outer record is keyed by the provider name, and the inner | ||
| * record is keyed by the provider-specific metadata key. | ||
| * | ||
| * ```ts | ||
| * { | ||
| * "anthropic": { | ||
| * "cacheControl": { "type": "ephemeral" } | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>; | ||
| /** | ||
| Tool result content part of a prompt. It contains the result of the tool call with the matching ID. | ||
| */ | ||
| interface LanguageModelV3ToolResultPart { | ||
| type: 'tool-result'; | ||
| /** | ||
| ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Result of the tool call. | ||
| */ | ||
| output: LanguageModelV3ToolResultOutput; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV3ProviderOptions; | ||
| } | ||
| /** | ||
| * Result of a tool call. | ||
| */ | ||
| type LanguageModelV3ToolResultOutput = { | ||
| type: 'text'; | ||
| value: string; | ||
| } | { | ||
| type: 'json'; | ||
| value: JSONValue; | ||
| } | { | ||
| /** | ||
| * Type when the user has denied the execution of the tool call. | ||
| */ | ||
| type: 'execution-denied'; | ||
| /** | ||
| * Optional reason for the execution denial. | ||
| */ | ||
| reason?: string; | ||
| } | { | ||
| type: 'error-text'; | ||
| value: string; | ||
| } | { | ||
| type: 'error-json'; | ||
| value: JSONValue; | ||
| } | { | ||
| type: 'content'; | ||
| value: Array<{ | ||
| type: 'text'; | ||
| /** | ||
| Text content. | ||
| */ | ||
| text: string; | ||
| } | { | ||
| type: 'media'; | ||
| /** | ||
| Base-64 encoded media data. | ||
| */ | ||
| data: string; | ||
| /** | ||
| IANA media type. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| }>; | ||
| }; | ||
| /** | ||
| A tool has a name, a description, and a set of parameters. | ||
| Note: this is **not** the user-facing tool definition. The AI SDK methods will | ||
| map the user-facing tool definitions to this format. | ||
| */ | ||
| type LanguageModelV2FunctionTool = { | ||
| /** | ||
| The type of the tool (always 'function'). | ||
| */ | ||
| type: 'function'; | ||
| /** | ||
| The name of the tool. Unique within this model call. | ||
| */ | ||
| name: string; | ||
| /** | ||
| A description of the tool. The language model uses this to understand the | ||
| tool's purpose and to provide better completion suggestions. | ||
| */ | ||
| description?: string; | ||
| /** | ||
| The parameters that the tool expects. The language model uses this to | ||
| understand the tool's input requirements and to provide matching suggestions. | ||
| */ | ||
| inputSchema: JSONSchema7; | ||
| /** | ||
| The provider-specific options for the tool. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| }; | ||
| /** | ||
| Data content. Can be a Uint8Array, base64 encoded data as a string or a URL. | ||
| */ | ||
| type LanguageModelV2DataContent = Uint8Array | string | URL; | ||
| /** | ||
| A prompt is a list of messages. | ||
| Note: Not all models and prompt formats support multi-modal inputs and | ||
| tool calls. The validation happens at runtime. | ||
| Note: This is not a user-facing prompt. The AI SDK methods will map the | ||
| user-facing prompt types such as chat or instruction prompts to this format. | ||
| */ | ||
| type LanguageModelV2Prompt = Array<LanguageModelV2Message>; | ||
| type LanguageModelV2Message = ({ | ||
| role: 'system'; | ||
| content: string; | ||
| } | { | ||
| role: 'user'; | ||
| content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>; | ||
| } | { | ||
| role: 'assistant'; | ||
| content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart | LanguageModelV2ToolResultPart>; | ||
| } | { | ||
| role: 'tool'; | ||
| content: Array<LanguageModelV2ToolResultPart>; | ||
| }) & { | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| }; | ||
| /** | ||
| Text content part of a prompt. It contains a string of text. | ||
| */ | ||
| interface LanguageModelV2TextPart { | ||
| type: 'text'; | ||
| /** | ||
| The text content. | ||
| */ | ||
| text: string; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| Reasoning content part of a prompt. It contains a string of reasoning text. | ||
| */ | ||
| interface LanguageModelV2ReasoningPart { | ||
| type: 'reasoning'; | ||
| /** | ||
| The reasoning text. | ||
| */ | ||
| text: string; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| File content part of a prompt. It contains a file. | ||
| */ | ||
| interface LanguageModelV2FilePart { | ||
| type: 'file'; | ||
| /** | ||
| * Optional filename of the file. | ||
| */ | ||
| filename?: string; | ||
| /** | ||
| File data. Can be a Uint8Array, base64 encoded data as a string or a URL. | ||
| */ | ||
| data: LanguageModelV2DataContent; | ||
| /** | ||
| IANA media type of the file. | ||
| Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action). | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| Tool call content part of a prompt. It contains a tool call (usually generated by the AI model). | ||
| */ | ||
| interface LanguageModelV2ToolCallPart { | ||
| type: 'tool-call'; | ||
| /** | ||
| ID of the tool call. This ID is used to match the tool call with the tool result. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that is being called. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. | ||
| */ | ||
| input: unknown; | ||
| /** | ||
| * Whether the tool call will be executed by the provider. | ||
| * If this flag is not set or is false, the tool call will be executed by the client. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| Tool result content part of a prompt. It contains the result of the tool call with the matching ID. | ||
| */ | ||
| interface LanguageModelV2ToolResultPart { | ||
| type: 'tool-result'; | ||
| /** | ||
| ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Result of the tool call. | ||
| */ | ||
| output: LanguageModelV2ToolResultOutput; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| type LanguageModelV2ToolResultOutput = { | ||
| type: 'text'; | ||
| value: string; | ||
| } | { | ||
| type: 'json'; | ||
| value: JSONValue; | ||
| } | { | ||
| type: 'error-text'; | ||
| value: string; | ||
| } | { | ||
| type: 'error-json'; | ||
| value: JSONValue; | ||
| } | { | ||
| type: 'content'; | ||
| value: Array<{ | ||
| type: 'text'; | ||
| /** | ||
| Text content. | ||
| */ | ||
| text: string; | ||
| } | { | ||
| type: 'media'; | ||
| /** | ||
| Base-64 encoded media data. | ||
| */ | ||
| data: string; | ||
| /** | ||
| IANA media type. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| }>; | ||
| }; | ||
| /** | ||
| The configuration of a tool that is defined by the provider. | ||
| */ | ||
| type LanguageModelV2ProviderDefinedTool = { | ||
| /** | ||
| The type of the tool (always 'provider-defined'). | ||
| */ | ||
| type: 'provider-defined'; | ||
| /** | ||
| The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`. | ||
| */ | ||
| id: `${string}.${string}`; | ||
| /** | ||
| The name of the tool that the user must use in the tool set. | ||
| */ | ||
| name: string; | ||
| /** | ||
| The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool. | ||
| */ | ||
| args: Record<string, unknown>; | ||
| }; | ||
| type LanguageModelV2ToolChoice = { | ||
| type: 'auto'; | ||
| } | { | ||
| type: 'none'; | ||
| } | { | ||
| type: 'required'; | ||
| } | { | ||
| type: 'tool'; | ||
| toolName: string; | ||
| }; | ||
| type LanguageModelV2CallOptions = { | ||
| /** | ||
| A language mode prompt is a standardized prompt type. | ||
| Note: This is **not** the user-facing prompt. The AI SDK methods will map the | ||
| user-facing prompt types such as chat or instruction prompts to this format. | ||
| That approach allows us to evolve the user facing prompts without breaking | ||
| the language model interface. | ||
| */ | ||
| prompt: LanguageModelV2Prompt; | ||
| /** | ||
| Maximum number of tokens to generate. | ||
| */ | ||
| maxOutputTokens?: number; | ||
| /** | ||
| Temperature setting. The range depends on the provider and model. | ||
| */ | ||
| temperature?: number; | ||
| /** | ||
| Stop sequences. | ||
| If set, the model will stop generating text when one of the stop sequences is generated. | ||
| Providers may have limits on the number of stop sequences. | ||
| */ | ||
| stopSequences?: string[]; | ||
| /** | ||
| Nucleus sampling. | ||
| */ | ||
| topP?: number; | ||
| /** | ||
| Only sample from the top K options for each subsequent token. | ||
| Used to remove "long tail" low probability responses. | ||
| Recommended for advanced use cases only. You usually only need to use temperature. | ||
| */ | ||
| topK?: number; | ||
| /** | ||
| Presence penalty setting. It affects the likelihood of the model to | ||
| repeat information that is already in the prompt. | ||
| */ | ||
| presencePenalty?: number; | ||
| /** | ||
| Frequency penalty setting. It affects the likelihood of the model | ||
| to repeatedly use the same words or phrases. | ||
| */ | ||
| frequencyPenalty?: number; | ||
| /** | ||
| Response format. The output can either be text or JSON. Default is text. | ||
| If JSON is selected, a schema can optionally be provided to guide the LLM. | ||
| */ | ||
| responseFormat?: { | ||
| type: 'text'; | ||
| } | { | ||
| type: 'json'; | ||
| /** | ||
| * JSON schema that the generated output should conform to. | ||
| */ | ||
| schema?: JSONSchema7; | ||
| /** | ||
| * Name of output that should be generated. Used by some providers for additional LLM guidance. | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * Description of the output that should be generated. Used by some providers for additional LLM guidance. | ||
| */ | ||
| description?: string; | ||
| }; | ||
| /** | ||
| The seed (integer) to use for random sampling. If set and supported | ||
| by the model, calls will generate deterministic results. | ||
| */ | ||
| seed?: number; | ||
| /** | ||
| The tools that are available for the model. | ||
| */ | ||
| tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>; | ||
| /** | ||
| Specifies how the tool should be selected. Defaults to 'auto'. | ||
| */ | ||
| toolChoice?: LanguageModelV2ToolChoice; | ||
| /** | ||
| Include raw chunks in the stream. Only applicable for streaming calls. | ||
| */ | ||
| includeRawChunks?: boolean; | ||
| /** | ||
| Abort signal for cancelling the operation. | ||
| */ | ||
| abortSignal?: AbortSignal; | ||
| /** | ||
| Additional HTTP headers to be sent with the request. | ||
| Only applicable for HTTP-based providers. | ||
| */ | ||
| headers?: Record<string, string | undefined>; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| }; | ||
| /** | ||
| Warning from the model provider for this call. The call will proceed, but e.g. | ||
| some settings might not be supported, which can lead to suboptimal results. | ||
| */ | ||
| type LanguageModelV2CallWarning = { | ||
| type: 'unsupported-setting'; | ||
| setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>; | ||
| details?: string; | ||
| } | { | ||
| type: 'unsupported-tool'; | ||
| tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool; | ||
| details?: string; | ||
| } | { | ||
| type: 'other'; | ||
| message: string; | ||
| }; | ||
| /** | ||
| A file that has been generated by the model. | ||
| Generated files as base64 encoded strings or binary data. | ||
| The files should be returned without any unnecessary conversion. | ||
| */ | ||
| type LanguageModelV2File = { | ||
| type: 'file'; | ||
| /** | ||
| The IANA media type of the file, e.g. `image/png` or `audio/mp3`. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| Generated file data as base64 encoded strings or binary data. | ||
| The file data should be returned without any unnecessary conversion. | ||
| If the API returns base64 encoded strings, the file data should be returned | ||
| as base64 encoded strings. If the API returns binary data, the file data should | ||
| be returned as binary data. | ||
| */ | ||
| data: string | Uint8Array; | ||
| }; | ||
| /** | ||
| Reasoning that the model has generated. | ||
| */ | ||
| type LanguageModelV2Reasoning = { | ||
| type: 'reasoning'; | ||
| text: string; | ||
| /** | ||
| * Optional provider-specific metadata for the reasoning part. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| A source that has been used as input to generate the response. | ||
| */ | ||
| type LanguageModelV2Source = { | ||
| type: 'source'; | ||
| /** | ||
| * The type of source - URL sources reference web content. | ||
| */ | ||
| sourceType: 'url'; | ||
| /** | ||
| * The ID of the source. | ||
| */ | ||
| id: string; | ||
| /** | ||
| * The URL of the source. | ||
| */ | ||
| url: string; | ||
| /** | ||
| * The title of the source. | ||
| */ | ||
| title?: string; | ||
| /** | ||
| * Additional provider metadata for the source. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'source'; | ||
| /** | ||
| * The type of source - document sources reference files/documents. | ||
| */ | ||
| sourceType: 'document'; | ||
| /** | ||
| * The ID of the source. | ||
| */ | ||
| id: string; | ||
| /** | ||
| * IANA media type of the document (e.g., 'application/pdf'). | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| * The title of the document. | ||
| */ | ||
| title: string; | ||
| /** | ||
| * Optional filename of the document. | ||
| */ | ||
| filename?: string; | ||
| /** | ||
| * Additional provider metadata for the source. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| Text that the model has generated. | ||
| */ | ||
| type LanguageModelV2Text = { | ||
| type: 'text'; | ||
| /** | ||
| The text content. | ||
| */ | ||
| text: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| * Tool calls that the model has generated. | ||
| */ | ||
| type LanguageModelV2ToolCall = { | ||
| type: 'tool-call'; | ||
| /** | ||
| * The identifier of the tool call. It must be unique across all tool calls. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * The name of the tool that should be called. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| * Stringified JSON object with the tool call arguments. Must match the | ||
| * parameters schema of the tool. | ||
| */ | ||
| input: string; | ||
| /** | ||
| * Whether the tool call will be executed by the provider. | ||
| * If this flag is not set or is false, the tool call will be executed by the client. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| /** | ||
| * Additional provider-specific metadata for the tool call. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| Result of a tool call that has been executed by the provider. | ||
| */ | ||
| type LanguageModelV2ToolResult = { | ||
| type: 'tool-result'; | ||
| /** | ||
| * The ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| * Result of the tool call. This is a JSON-serializable object. | ||
| */ | ||
| result: unknown; | ||
| /** | ||
| * Optional flag if the result is an error or an error message. | ||
| */ | ||
| isError?: boolean; | ||
| /** | ||
| * Whether the tool result was generated by the provider. | ||
| * If this flag is set to true, the tool result was generated by the provider. | ||
| * If this flag is not set or is false, the tool result was generated by the client. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| /** | ||
| * Additional provider-specific metadata for the tool result. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall | LanguageModelV2ToolResult; | ||
| /** | ||
| Reason why a language model finished generating a response. | ||
| Can be one of the following: | ||
| - `stop`: model generated stop sequence | ||
| - `length`: model generated maximum number of tokens | ||
| - `content-filter`: content filter violation stopped the model | ||
| - `tool-calls`: model triggered tool calls | ||
| - `error`: model stopped because of an error | ||
| - `other`: model stopped for other reasons | ||
| - `unknown`: the model has not transmitted a finish reason | ||
| */ | ||
| type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown'; | ||
| interface LanguageModelV2ResponseMetadata { | ||
| /** | ||
| ID for the generated response, if the provider sends one. | ||
| */ | ||
| id?: string; | ||
| /** | ||
| Timestamp for the start of the generated response, if the provider sends one. | ||
| */ | ||
| timestamp?: Date; | ||
| /** | ||
| The ID of the response model that was used to generate the response, if the provider sends one. | ||
| */ | ||
| modelId?: string; | ||
| } | ||
| /** | ||
| Usage information for a language model call. | ||
| If your API return additional usage information, you can add it to the | ||
| provider metadata under your provider's key. | ||
| */ | ||
| type LanguageModelV2Usage = { | ||
| /** | ||
| The number of input (prompt) tokens used. | ||
| */ | ||
| inputTokens: number | undefined; | ||
| /** | ||
| The number of output (completion) tokens used. | ||
| */ | ||
| outputTokens: number | undefined; | ||
| /** | ||
| The total number of tokens as reported by the provider. | ||
| This number might be different from the sum of `inputTokens` and `outputTokens` | ||
| and e.g. include reasoning tokens or other overhead. | ||
| */ | ||
| totalTokens: number | undefined; | ||
| /** | ||
| The number of reasoning tokens used. | ||
| */ | ||
| reasoningTokens?: number | undefined; | ||
| /** | ||
| The number of cached input tokens. | ||
| */ | ||
| cachedInputTokens?: number | undefined; | ||
| }; | ||
| type LanguageModelV2StreamPart = { | ||
| type: 'text-start'; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| id: string; | ||
| } | { | ||
| type: 'text-delta'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| delta: string; | ||
| } | { | ||
| type: 'text-end'; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| id: string; | ||
| } | { | ||
| type: 'reasoning-start'; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| id: string; | ||
| } | { | ||
| type: 'reasoning-delta'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| delta: string; | ||
| } | { | ||
| type: 'reasoning-end'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'tool-input-start'; | ||
| id: string; | ||
| toolName: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| providerExecuted?: boolean; | ||
| } | { | ||
| type: 'tool-input-delta'; | ||
| id: string; | ||
| delta: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'tool-input-end'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | LanguageModelV2ToolCall | LanguageModelV2ToolResult | LanguageModelV2File | LanguageModelV2Source | { | ||
| type: 'stream-start'; | ||
| warnings: Array<LanguageModelV2CallWarning>; | ||
| } | ({ | ||
| type: 'response-metadata'; | ||
| } & LanguageModelV2ResponseMetadata) | { | ||
| type: 'finish'; | ||
| usage: LanguageModelV2Usage; | ||
| finishReason: LanguageModelV2FinishReason; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'raw'; | ||
| rawValue: unknown; | ||
| } | { | ||
| type: 'error'; | ||
| error: unknown; | ||
| }; | ||
| /** | ||
| Specification for a language model that implements the language model interface version 2. | ||
| */ | ||
| type LanguageModelV2 = { | ||
| /** | ||
| The language model must specify which language model interface version it implements. | ||
| */ | ||
| readonly specificationVersion: 'v2'; | ||
| /** | ||
| Name of the provider for logging purposes. | ||
| */ | ||
| readonly provider: string; | ||
| /** | ||
| Provider-specific model ID for logging purposes. | ||
| */ | ||
| readonly modelId: string; | ||
| /** | ||
| Supported URL patterns by media type for the provider. | ||
| The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`). | ||
| and the values are arrays of regular expressions that match the URL paths. | ||
| The matching should be against lower-case URLs. | ||
| Matched URLs are supported natively by the model and are not downloaded. | ||
| @returns A map of supported URL patterns by media type (as a promise or a plain object). | ||
| */ | ||
| supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>; | ||
| /** | ||
| Generates a language model output (non-streaming). | ||
| Naming: "do" prefix to prevent accidental direct usage of the method | ||
| by the user. | ||
| */ | ||
| doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{ | ||
| /** | ||
| Ordered content that the model has generated. | ||
| */ | ||
| content: Array<LanguageModelV2Content>; | ||
| /** | ||
| Finish reason. | ||
| */ | ||
| finishReason: LanguageModelV2FinishReason; | ||
| /** | ||
| Usage information. | ||
| */ | ||
| usage: LanguageModelV2Usage; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| from the provider to the AI SDK and enable provider-specific | ||
| results that can be fully encapsulated in the provider. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| /** | ||
| Optional request information for telemetry and debugging purposes. | ||
| */ | ||
| request?: { | ||
| /** | ||
| Request HTTP body that was sent to the provider API. | ||
| */ | ||
| body?: unknown; | ||
| }; | ||
| /** | ||
| Optional response information for telemetry and debugging purposes. | ||
| */ | ||
| response?: LanguageModelV2ResponseMetadata & { | ||
| /** | ||
| Response headers. | ||
| */ | ||
| headers?: SharedV2Headers; | ||
| /** | ||
| Response HTTP body. | ||
| */ | ||
| body?: unknown; | ||
| }; | ||
| /** | ||
| Warnings for the call, e.g. unsupported settings. | ||
| */ | ||
| warnings: Array<LanguageModelV2CallWarning>; | ||
| }>; | ||
| /** | ||
| Generates a language model output (streaming). | ||
| Naming: "do" prefix to prevent accidental direct usage of the method | ||
| by the user. | ||
| * | ||
| @return A stream of higher-level language model output parts. | ||
| */ | ||
| doStream(options: LanguageModelV2CallOptions): PromiseLike<{ | ||
| stream: ReadableStream<LanguageModelV2StreamPart>; | ||
| /** | ||
| Optional request information for telemetry and debugging purposes. | ||
| */ | ||
| request?: { | ||
| /** | ||
| Request HTTP body that was sent to the provider API. | ||
| */ | ||
| body?: unknown; | ||
| }; | ||
| /** | ||
| Optional response data. | ||
| */ | ||
| response?: { | ||
| /** | ||
| Response headers. | ||
| */ | ||
| headers?: SharedV2Headers; | ||
| }; | ||
| }>; | ||
| }; | ||
| /** | ||
| * Fetch function type (standardizes the version of fetch used). | ||
| */ | ||
| type FetchFunction = typeof globalThis.fetch; | ||
| /** The Standard Schema interface. */ | ||
| interface StandardSchemaV1<Input = unknown, Output = Input> { | ||
| /** The Standard Schema properties. */ | ||
| readonly "~standard": StandardSchemaV1.Props<Input, Output>; | ||
| } | ||
| declare namespace StandardSchemaV1 { | ||
| /** The Standard Schema properties interface. */ | ||
| export interface Props<Input = unknown, Output = Input> { | ||
| /** The version number of the standard. */ | ||
| readonly version: 1; | ||
| /** The vendor name of the schema library. */ | ||
| readonly vendor: string; | ||
| /** Validates unknown input values. */ | ||
| readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>; | ||
| /** Inferred types associated with the schema. */ | ||
| readonly types?: Types<Input, Output> | undefined; | ||
| } | ||
| /** The result interface of the validate function. */ | ||
| export type Result<Output> = SuccessResult<Output> | FailureResult; | ||
| /** The result interface if validation succeeds. */ | ||
| export interface SuccessResult<Output> { | ||
| /** The typed output value. */ | ||
| readonly value: Output; | ||
| /** The non-existent issues. */ | ||
| readonly issues?: undefined; | ||
| } | ||
| /** The result interface if validation fails. */ | ||
| export interface FailureResult { | ||
| /** The issues of failed validation. */ | ||
| readonly issues: ReadonlyArray<Issue>; | ||
| } | ||
| /** The issue interface of the failure output. */ | ||
| export interface Issue { | ||
| /** The error message of the issue. */ | ||
| readonly message: string; | ||
| /** The path of the issue, if any. */ | ||
| readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined; | ||
| } | ||
| /** The path segment interface of the issue. */ | ||
| export interface PathSegment { | ||
| /** The key representing a path segment. */ | ||
| readonly key: PropertyKey; | ||
| } | ||
| /** The Standard Schema types interface. */ | ||
| export interface Types<Input = unknown, Output = Input> { | ||
| /** The input type of the schema. */ | ||
| readonly input: Input; | ||
| /** The output type of the schema. */ | ||
| readonly output: Output; | ||
| } | ||
| /** Infers the input type of a Standard Schema. */ | ||
| export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"]; | ||
| /** Infers the output type of a Standard Schema. */ | ||
| export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"]; | ||
| export { }; | ||
| } | ||
| /** | ||
| * Used to mark schemas so we can support both Zod and custom schemas. | ||
| */ | ||
| declare const schemaSymbol: unique symbol; | ||
| type ValidationResult<OBJECT> = { | ||
| success: true; | ||
| value: OBJECT; | ||
| } | { | ||
| success: false; | ||
| error: Error; | ||
| }; | ||
| type Schema<OBJECT = unknown> = { | ||
| /** | ||
| * Used to mark schemas so we can support both Zod and custom schemas. | ||
| */ | ||
| [schemaSymbol]: true; | ||
| /** | ||
| * Schema type for inference. | ||
| */ | ||
| _type: OBJECT; | ||
| /** | ||
| * Optional. Validates that the structure of a value matches this schema, | ||
| * and returns a typed version of the value if it does. | ||
| */ | ||
| readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>; | ||
| /** | ||
| * The JSON Schema for the schema. It is passed to the providers. | ||
| */ | ||
| readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>; | ||
| }; | ||
| type LazySchema<SCHEMA> = () => Schema<SCHEMA>; | ||
| type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | StandardSchemaV1<unknown, SCHEMA>; | ||
| /** | ||
| Additional provider-specific options. | ||
| They are passed through to the provider from the AI SDK and enable | ||
| provider-specific functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| type ProviderOptions = SharedV3ProviderOptions; | ||
| /** | ||
| Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer. | ||
| */ | ||
| type DataContent = string | Uint8Array | ArrayBuffer | Buffer; | ||
| /** | ||
| Text content part of a prompt. It contains a string of text. | ||
| */ | ||
| interface TextPart { | ||
| type: 'text'; | ||
| /** | ||
| The text content. | ||
| */ | ||
| text: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| Image content part of a prompt. It contains an image. | ||
| */ | ||
| interface ImagePart { | ||
| type: 'image'; | ||
| /** | ||
| Image data. Can either be: | ||
| - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer | ||
| - URL: a URL that points to the image | ||
| */ | ||
| image: DataContent | URL; | ||
| /** | ||
| Optional IANA media type of the image. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType?: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| File content part of a prompt. It contains a file. | ||
| */ | ||
| interface FilePart { | ||
| type: 'file'; | ||
| /** | ||
| File data. Can either be: | ||
| - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer | ||
| - URL: a URL that points to the image | ||
| */ | ||
| data: DataContent | URL; | ||
| /** | ||
| Optional filename of the file. | ||
| */ | ||
| filename?: string; | ||
| /** | ||
| IANA media type of the file. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| * Reasoning content part of a prompt. It contains a reasoning. | ||
| */ | ||
| interface ReasoningPart { | ||
| type: 'reasoning'; | ||
| /** | ||
| The reasoning text. | ||
| */ | ||
| text: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| Tool call content part of a prompt. It contains a tool call (usually generated by the AI model). | ||
| */ | ||
| interface ToolCallPart { | ||
| type: 'tool-call'; | ||
| /** | ||
| ID of the tool call. This ID is used to match the tool call with the tool result. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that is being called. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. | ||
| */ | ||
| input: unknown; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| /** | ||
| Whether the tool call was executed by the provider. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| } | ||
| /** | ||
| Tool result content part of a prompt. It contains the result of the tool call with the matching ID. | ||
| */ | ||
| interface ToolResultPart { | ||
| type: 'tool-result'; | ||
| /** | ||
| ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Result of the tool call. This is a JSON-serializable object. | ||
| */ | ||
| output: LanguageModelV3ToolResultOutput; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| * Tool approval request prompt part. | ||
| */ | ||
| type ToolApprovalRequest = { | ||
| type: 'tool-approval-request'; | ||
| /** | ||
| * ID of the tool approval. | ||
| */ | ||
| approvalId: string; | ||
| /** | ||
| * ID of the tool call that the approval request is for. | ||
| */ | ||
| toolCallId: string; | ||
| }; | ||
| /** | ||
| An assistant message. It can contain text, tool calls, or a combination of text and tool calls. | ||
| */ | ||
| type AssistantModelMessage = { | ||
| role: 'assistant'; | ||
| content: AssistantContent; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| Content of an assistant message. | ||
| It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts. | ||
| */ | ||
| type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>; | ||
| /** | ||
| A system message. It can contain system information. | ||
| Note: using the "system" part of the prompt is strongly preferred | ||
| to increase the resilience against prompt injection attacks, | ||
| and because not all providers support several system messages. | ||
| */ | ||
| type SystemModelMessage = { | ||
| role: 'system'; | ||
| content: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| * Tool approval response prompt part. | ||
| */ | ||
| type ToolApprovalResponse = { | ||
| type: 'tool-approval-response'; | ||
| /** | ||
| * ID of the tool approval. | ||
| */ | ||
| approvalId: string; | ||
| /** | ||
| * Flag indicating whether the approval was granted or denied. | ||
| */ | ||
| approved: boolean; | ||
| /** | ||
| * Optional reason for the approval or denial. | ||
| */ | ||
| reason?: string; | ||
| }; | ||
| /** | ||
| A tool message. It contains the result of one or more tool calls. | ||
| */ | ||
| type ToolModelMessage = { | ||
| role: 'tool'; | ||
| content: ToolContent; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| Content of a tool message. It is an array of tool result parts. | ||
| */ | ||
| type ToolContent = Array<ToolResultPart | ToolApprovalResponse>; | ||
| /** | ||
| A user message. It can contain text or a combination of text and images. | ||
| */ | ||
| type UserModelMessage = { | ||
| role: 'user'; | ||
| content: UserContent; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| Content of a user message. It can be a string or an array of text and image parts. | ||
| */ | ||
| type UserContent = string | Array<TextPart | ImagePart | FilePart>; | ||
| /** | ||
| A message that can be used in the `messages` field of a prompt. | ||
| It can be a user message, an assistant message, or a tool message. | ||
| */ | ||
| type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage; | ||
| /** | ||
| * Additional options that are sent into each tool call. | ||
| */ | ||
| interface ToolCallOptions { | ||
| /** | ||
| * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * Messages that were sent to the language model to initiate the response that contained the tool call. | ||
| * The messages **do not** include the system prompt nor the assistant response that contained the tool call. | ||
| */ | ||
| messages: ModelMessage[]; | ||
| /** | ||
| * An optional abort signal that indicates that the overall operation should be aborted. | ||
| */ | ||
| abortSignal?: AbortSignal; | ||
| /** | ||
| * Additional context. | ||
| * | ||
| * Experimental (can break in patch releases). | ||
| */ | ||
| experimental_context?: unknown; | ||
| } | ||
| type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT; | ||
| type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T; | ||
| type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, { | ||
| /** | ||
| An async function that is called with the arguments from the tool call and produces a result. | ||
| If not provided, the tool will not be executed automatically. | ||
| @args is the input of the tool call. | ||
| @options.abortSignal is a signal that can be used to abort the tool call. | ||
| */ | ||
| execute: ToolExecuteFunction<INPUT, OUTPUT>; | ||
| outputSchema?: FlexibleSchema<OUTPUT>; | ||
| } | { | ||
| outputSchema: FlexibleSchema<OUTPUT>; | ||
| execute?: never; | ||
| }>; | ||
| /** | ||
| A tool contains the description and the schema of the input that the tool expects. | ||
| This enables the language model to generate the input. | ||
| The tool can also contain an optional execute function for the actual execution function of the tool. | ||
| */ | ||
| type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any> = { | ||
| /** | ||
| An optional description of what the tool does. | ||
| Will be used by the language model to decide whether to use the tool. | ||
| Not used for provider-defined tools. | ||
| */ | ||
| description?: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| /** | ||
| The schema of the input that the tool expects. The language model will use this to generate the input. | ||
| It is also used to validate the output of the language model. | ||
| Use descriptions to make the input understandable for the language model. | ||
| */ | ||
| inputSchema: FlexibleSchema<INPUT>; | ||
| /** | ||
| Whether the tool needs approval before it can be executed. | ||
| */ | ||
| needsApproval?: boolean | ((input: [INPUT] extends [never] ? unknown : INPUT, options: { | ||
| /** | ||
| * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * Messages that were sent to the language model to initiate the response that contained the tool call. | ||
| * The messages **do not** include the system prompt nor the assistant response that contained the tool call. | ||
| */ | ||
| messages: ModelMessage[]; | ||
| /** | ||
| * Additional context. | ||
| * | ||
| * Experimental (can break in patch releases). | ||
| */ | ||
| experimental_context?: unknown; | ||
| }) => boolean | PromiseLike<boolean>); | ||
| /** | ||
| * Optional function that is called when the argument streaming starts. | ||
| * Only called when the tool is used in a streaming context. | ||
| */ | ||
| onInputStart?: (options: ToolCallOptions) => void | PromiseLike<void>; | ||
| /** | ||
| * Optional function that is called when an argument streaming delta is available. | ||
| * Only called when the tool is used in a streaming context. | ||
| */ | ||
| onInputDelta?: (options: { | ||
| inputTextDelta: string; | ||
| } & ToolCallOptions) => void | PromiseLike<void>; | ||
| /** | ||
| * Optional function that is called when a tool call can be started, | ||
| * even if the execute function is not provided. | ||
| */ | ||
| onInputAvailable?: (options: { | ||
| input: [INPUT] extends [never] ? unknown : INPUT; | ||
| } & ToolCallOptions) => void | PromiseLike<void>; | ||
| } & ToolOutputProperties<INPUT, OUTPUT> & { | ||
| /** | ||
| Optional conversion function that maps the tool result to an output that can be used by the language model. | ||
| If not provided, the tool result will be sent as a JSON object. | ||
| */ | ||
| toModelOutput?: (output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>) => LanguageModelV3ToolResultPart['output']; | ||
| } & ({ | ||
| /** | ||
| Tool with user-defined input and output schemas. | ||
| */ | ||
| type?: undefined | 'function'; | ||
| } | { | ||
| /** | ||
| Tool that is defined at runtime (e.g. an MCP tool). | ||
| The types of input and output are not known at development time. | ||
| */ | ||
| type: 'dynamic'; | ||
| } | { | ||
| /** | ||
| Tool with provider-defined input and output schemas. | ||
| */ | ||
| type: 'provider-defined'; | ||
| /** | ||
| The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`. | ||
| */ | ||
| id: `${string}.${string}`; | ||
| /** | ||
| The name of the tool that the user must use in the tool set. | ||
| */ | ||
| name: string; | ||
| /** | ||
| The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool. | ||
| */ | ||
| args: Record<string, unknown>; | ||
| }); | ||
| type ProviderDefinedToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & { | ||
| execute?: ToolExecuteFunction<INPUT, OUTPUT>; | ||
| needsApproval?: Tool<INPUT, OUTPUT>['needsApproval']; | ||
| toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput']; | ||
| onInputStart?: Tool<INPUT, OUTPUT>['onInputStart']; | ||
| onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta']; | ||
| onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable']; | ||
| }) => Tool<INPUT, OUTPUT>; | ||
| type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & { | ||
| execute?: ToolExecuteFunction<INPUT, OUTPUT>; | ||
| needsApproval?: Tool<INPUT, OUTPUT>['needsApproval']; | ||
| toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput']; | ||
| onInputStart?: Tool<INPUT, OUTPUT>['onInputStart']; | ||
| onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta']; | ||
| onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable']; | ||
| }) => Tool<INPUT, OUTPUT>; | ||
| type Resolvable<T> = T | PromiseLike<T> | (() => T) | (() => PromiseLike<T>); | ||
| type AnthropicMessagesModelId = 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {}); | ||
@@ -14,7 +1443,7 @@ | ||
| transformRequestBody?: (args: Record<string, any>) => Record<string, any>; | ||
| supportedUrls?: () => LanguageModelV3['supportedUrls']; | ||
| supportedUrls?: () => LanguageModelV2['supportedUrls']; | ||
| generateId?: () => string; | ||
| }; | ||
| declare class AnthropicMessagesLanguageModel implements LanguageModelV3 { | ||
| readonly specificationVersion = "v3"; | ||
| declare class AnthropicMessagesLanguageModel implements LanguageModelV2 { | ||
| readonly specificationVersion = "v2"; | ||
| readonly modelId: AnthropicMessagesModelId; | ||
@@ -24,3 +1453,2 @@ private readonly config; | ||
| constructor(modelId: AnthropicMessagesModelId, config: AnthropicMessagesConfig); | ||
| supportsUrl(url: URL): boolean; | ||
| get provider(): string; | ||
@@ -33,4 +1461,4 @@ get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>; | ||
| private extractCitationDocuments; | ||
| doGenerate(options: Parameters<LanguageModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>; | ||
| doStream(options: Parameters<LanguageModelV3['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>; | ||
| doGenerate(options: Parameters<LanguageModelV2['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>; | ||
| doStream(options: Parameters<LanguageModelV2['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>; | ||
| } | ||
@@ -47,3 +1475,3 @@ | ||
| */ | ||
| bash_20241022: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| bash_20241022: ProviderDefinedToolFactory<{ | ||
| command: string; | ||
@@ -60,3 +1488,3 @@ restart?: boolean; | ||
| */ | ||
| bash_20250124: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| bash_20250124: ProviderDefinedToolFactory<{ | ||
| command: string; | ||
@@ -75,3 +1503,3 @@ restart?: boolean; | ||
| */ | ||
| codeExecution_20250522: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| codeExecution_20250522: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| code: string; | ||
@@ -83,3 +1511,3 @@ }, { | ||
| return_code: number; | ||
| }, {}>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }, {}>>[0]) => Tool<{ | ||
| code: string; | ||
@@ -104,3 +1532,3 @@ }, { | ||
| */ | ||
| codeExecution_20250825: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| codeExecution_20250825: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| type: "bash_code_execution"; | ||
@@ -151,3 +1579,3 @@ command: string; | ||
| old_start: number | null; | ||
| }, {}>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }, {}>>[0]) => Tool<{ | ||
| type: "bash_code_execution"; | ||
@@ -211,3 +1639,3 @@ command: string; | ||
| */ | ||
| computer_20241022: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| computer_20241022: ProviderDefinedToolFactory<{ | ||
| action: "key" | "type" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position"; | ||
@@ -233,3 +1661,3 @@ coordinate?: number[]; | ||
| */ | ||
| computer_20250124: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| computer_20250124: ProviderDefinedToolFactory<{ | ||
| action: "key" | "hold_key" | "type" | "cursor_position" | "mouse_move" | "left_mouse_down" | "left_mouse_up" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "triple_click" | "scroll" | "wait" | "screenshot"; | ||
@@ -257,3 +1685,3 @@ coordinate?: [number, number]; | ||
| */ | ||
| memory_20250818: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| memory_20250818: ProviderDefinedToolFactory<{ | ||
| command: "view"; | ||
@@ -293,3 +1721,3 @@ path: string; | ||
| */ | ||
| textEditor_20241022: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20241022: ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert" | "undo_edit"; | ||
@@ -312,3 +1740,3 @@ path: string; | ||
| */ | ||
| textEditor_20250124: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20250124: ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert" | "undo_edit"; | ||
@@ -333,3 +1761,3 @@ path: string; | ||
| */ | ||
| textEditor_20250429: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20250429: ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert"; | ||
@@ -356,3 +1784,3 @@ path: string; | ||
| */ | ||
| textEditor_20250728: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20250728: (args?: Parameters<ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert"; | ||
@@ -367,3 +1795,3 @@ path: string; | ||
| maxCharacters?: number; | ||
| }>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }>>[0]) => Tool<{ | ||
| command: "view" | "create" | "str_replace" | "insert"; | ||
@@ -388,3 +1816,3 @@ path: string; | ||
| */ | ||
| webFetch_20250910: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| webFetch_20250910: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| url: string; | ||
@@ -419,3 +1847,3 @@ }, { | ||
| maxContentTokens?: number; | ||
| }>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }>>[0]) => Tool<{ | ||
| url: string; | ||
@@ -453,3 +1881,3 @@ }, { | ||
| */ | ||
| webSearch_20250305: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| webSearch_20250305: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| query: string; | ||
@@ -473,3 +1901,3 @@ }, { | ||
| }; | ||
| }>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }>>[0]) => Tool<{ | ||
| query: string; | ||
@@ -552,4 +1980,4 @@ }, { | ||
| declare function prepareTools({ tools, toolChoice, disableParallelToolUse, }: { | ||
| tools: LanguageModelV3CallOptions['tools']; | ||
| toolChoice?: LanguageModelV3CallOptions['toolChoice']; | ||
| tools: LanguageModelV2CallOptions['tools']; | ||
| toolChoice?: LanguageModelV2CallOptions['toolChoice']; | ||
| disableParallelToolUse?: boolean; | ||
@@ -559,3 +1987,3 @@ }): Promise<{ | ||
| toolChoice: AnthropicToolChoice | undefined; | ||
| toolWarnings: LanguageModelV3CallWarning[]; | ||
| toolWarnings: LanguageModelV2CallWarning[]; | ||
| betas: Set<string>; | ||
@@ -562,0 +1990,0 @@ }>; |
+1458
-30
@@ -1,5 +0,1434 @@ | ||
| import { LanguageModelV3, JSONSchema7, LanguageModelV3CallOptions, LanguageModelV3CallWarning } from '@ai-sdk/provider'; | ||
| import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils'; | ||
| import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils'; | ||
| import { JSONSchema7 } from 'json-schema'; | ||
| /** | ||
| A JSON value can be a string, number, boolean, object, array, or null. | ||
| JSON values can be serialized and deserialized by the JSON.stringify and JSON.parse methods. | ||
| */ | ||
| type JSONValue = null | string | number | boolean | JSONObject | JSONArray; | ||
| type JSONObject = { | ||
| [key: string]: JSONValue; | ||
| }; | ||
| type JSONArray = JSONValue[]; | ||
| /** | ||
| * Additional provider-specific options. | ||
| * Options are additional input to the provider. | ||
| * They are passed through to the provider from the AI SDK | ||
| * and enable provider-specific functionality | ||
| * that can be fully encapsulated in the provider. | ||
| * | ||
| * This enables us to quickly ship provider-specific functionality | ||
| * without affecting the core AI SDK. | ||
| * | ||
| * The outer record is keyed by the provider name, and the inner | ||
| * record is keyed by the provider-specific metadata key. | ||
| * | ||
| * ```ts | ||
| * { | ||
| * "anthropic": { | ||
| * "cacheControl": { "type": "ephemeral" } | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| type SharedV3ProviderOptions = Record<string, Record<string, JSONValue>>; | ||
| type SharedV2Headers = Record<string, string>; | ||
| /** | ||
| * Additional provider-specific metadata. | ||
| * Metadata are additional outputs from the provider. | ||
| * They are passed through to the provider from the AI SDK | ||
| * and enable provider-specific functionality | ||
| * that can be fully encapsulated in the provider. | ||
| * | ||
| * This enables us to quickly ship provider-specific functionality | ||
| * without affecting the core AI SDK. | ||
| * | ||
| * The outer record is keyed by the provider name, and the inner | ||
| * record is keyed by the provider-specific metadata key. | ||
| * | ||
| * ```ts | ||
| * { | ||
| * "anthropic": { | ||
| * "cacheControl": { "type": "ephemeral" } | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| type SharedV2ProviderMetadata = Record<string, Record<string, JSONValue>>; | ||
| /** | ||
| * Additional provider-specific options. | ||
| * Options are additional input to the provider. | ||
| * They are passed through to the provider from the AI SDK | ||
| * and enable provider-specific functionality | ||
| * that can be fully encapsulated in the provider. | ||
| * | ||
| * This enables us to quickly ship provider-specific functionality | ||
| * without affecting the core AI SDK. | ||
| * | ||
| * The outer record is keyed by the provider name, and the inner | ||
| * record is keyed by the provider-specific metadata key. | ||
| * | ||
| * ```ts | ||
| * { | ||
| * "anthropic": { | ||
| * "cacheControl": { "type": "ephemeral" } | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| type SharedV2ProviderOptions = Record<string, Record<string, JSONValue>>; | ||
| /** | ||
| Tool result content part of a prompt. It contains the result of the tool call with the matching ID. | ||
| */ | ||
| interface LanguageModelV3ToolResultPart { | ||
| type: 'tool-result'; | ||
| /** | ||
| ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Result of the tool call. | ||
| */ | ||
| output: LanguageModelV3ToolResultOutput; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV3ProviderOptions; | ||
| } | ||
| /** | ||
| * Result of a tool call. | ||
| */ | ||
| type LanguageModelV3ToolResultOutput = { | ||
| type: 'text'; | ||
| value: string; | ||
| } | { | ||
| type: 'json'; | ||
| value: JSONValue; | ||
| } | { | ||
| /** | ||
| * Type when the user has denied the execution of the tool call. | ||
| */ | ||
| type: 'execution-denied'; | ||
| /** | ||
| * Optional reason for the execution denial. | ||
| */ | ||
| reason?: string; | ||
| } | { | ||
| type: 'error-text'; | ||
| value: string; | ||
| } | { | ||
| type: 'error-json'; | ||
| value: JSONValue; | ||
| } | { | ||
| type: 'content'; | ||
| value: Array<{ | ||
| type: 'text'; | ||
| /** | ||
| Text content. | ||
| */ | ||
| text: string; | ||
| } | { | ||
| type: 'media'; | ||
| /** | ||
| Base-64 encoded media data. | ||
| */ | ||
| data: string; | ||
| /** | ||
| IANA media type. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| }>; | ||
| }; | ||
| /** | ||
| A tool has a name, a description, and a set of parameters. | ||
| Note: this is **not** the user-facing tool definition. The AI SDK methods will | ||
| map the user-facing tool definitions to this format. | ||
| */ | ||
| type LanguageModelV2FunctionTool = { | ||
| /** | ||
| The type of the tool (always 'function'). | ||
| */ | ||
| type: 'function'; | ||
| /** | ||
| The name of the tool. Unique within this model call. | ||
| */ | ||
| name: string; | ||
| /** | ||
| A description of the tool. The language model uses this to understand the | ||
| tool's purpose and to provide better completion suggestions. | ||
| */ | ||
| description?: string; | ||
| /** | ||
| The parameters that the tool expects. The language model uses this to | ||
| understand the tool's input requirements and to provide matching suggestions. | ||
| */ | ||
| inputSchema: JSONSchema7; | ||
| /** | ||
| The provider-specific options for the tool. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| }; | ||
| /** | ||
| Data content. Can be a Uint8Array, base64 encoded data as a string or a URL. | ||
| */ | ||
| type LanguageModelV2DataContent = Uint8Array | string | URL; | ||
| /** | ||
| A prompt is a list of messages. | ||
| Note: Not all models and prompt formats support multi-modal inputs and | ||
| tool calls. The validation happens at runtime. | ||
| Note: This is not a user-facing prompt. The AI SDK methods will map the | ||
| user-facing prompt types such as chat or instruction prompts to this format. | ||
| */ | ||
| type LanguageModelV2Prompt = Array<LanguageModelV2Message>; | ||
| type LanguageModelV2Message = ({ | ||
| role: 'system'; | ||
| content: string; | ||
| } | { | ||
| role: 'user'; | ||
| content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart>; | ||
| } | { | ||
| role: 'assistant'; | ||
| content: Array<LanguageModelV2TextPart | LanguageModelV2FilePart | LanguageModelV2ReasoningPart | LanguageModelV2ToolCallPart | LanguageModelV2ToolResultPart>; | ||
| } | { | ||
| role: 'tool'; | ||
| content: Array<LanguageModelV2ToolResultPart>; | ||
| }) & { | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| }; | ||
| /** | ||
| Text content part of a prompt. It contains a string of text. | ||
| */ | ||
| interface LanguageModelV2TextPart { | ||
| type: 'text'; | ||
| /** | ||
| The text content. | ||
| */ | ||
| text: string; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| Reasoning content part of a prompt. It contains a string of reasoning text. | ||
| */ | ||
| interface LanguageModelV2ReasoningPart { | ||
| type: 'reasoning'; | ||
| /** | ||
| The reasoning text. | ||
| */ | ||
| text: string; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| File content part of a prompt. It contains a file. | ||
| */ | ||
| interface LanguageModelV2FilePart { | ||
| type: 'file'; | ||
| /** | ||
| * Optional filename of the file. | ||
| */ | ||
| filename?: string; | ||
| /** | ||
| File data. Can be a Uint8Array, base64 encoded data as a string or a URL. | ||
| */ | ||
| data: LanguageModelV2DataContent; | ||
| /** | ||
| IANA media type of the file. | ||
| Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action). | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| Tool call content part of a prompt. It contains a tool call (usually generated by the AI model). | ||
| */ | ||
| interface LanguageModelV2ToolCallPart { | ||
| type: 'tool-call'; | ||
| /** | ||
| ID of the tool call. This ID is used to match the tool call with the tool result. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that is being called. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. | ||
| */ | ||
| input: unknown; | ||
| /** | ||
| * Whether the tool call will be executed by the provider. | ||
| * If this flag is not set or is false, the tool call will be executed by the client. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| /** | ||
| Tool result content part of a prompt. It contains the result of the tool call with the matching ID. | ||
| */ | ||
| interface LanguageModelV2ToolResultPart { | ||
| type: 'tool-result'; | ||
| /** | ||
| ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Result of the tool call. | ||
| */ | ||
| output: LanguageModelV2ToolResultOutput; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| } | ||
| type LanguageModelV2ToolResultOutput = { | ||
| type: 'text'; | ||
| value: string; | ||
| } | { | ||
| type: 'json'; | ||
| value: JSONValue; | ||
| } | { | ||
| type: 'error-text'; | ||
| value: string; | ||
| } | { | ||
| type: 'error-json'; | ||
| value: JSONValue; | ||
| } | { | ||
| type: 'content'; | ||
| value: Array<{ | ||
| type: 'text'; | ||
| /** | ||
| Text content. | ||
| */ | ||
| text: string; | ||
| } | { | ||
| type: 'media'; | ||
| /** | ||
| Base-64 encoded media data. | ||
| */ | ||
| data: string; | ||
| /** | ||
| IANA media type. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| }>; | ||
| }; | ||
| /** | ||
| The configuration of a tool that is defined by the provider. | ||
| */ | ||
| type LanguageModelV2ProviderDefinedTool = { | ||
| /** | ||
| The type of the tool (always 'provider-defined'). | ||
| */ | ||
| type: 'provider-defined'; | ||
| /** | ||
| The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`. | ||
| */ | ||
| id: `${string}.${string}`; | ||
| /** | ||
| The name of the tool that the user must use in the tool set. | ||
| */ | ||
| name: string; | ||
| /** | ||
| The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool. | ||
| */ | ||
| args: Record<string, unknown>; | ||
| }; | ||
| type LanguageModelV2ToolChoice = { | ||
| type: 'auto'; | ||
| } | { | ||
| type: 'none'; | ||
| } | { | ||
| type: 'required'; | ||
| } | { | ||
| type: 'tool'; | ||
| toolName: string; | ||
| }; | ||
| type LanguageModelV2CallOptions = { | ||
| /** | ||
| A language mode prompt is a standardized prompt type. | ||
| Note: This is **not** the user-facing prompt. The AI SDK methods will map the | ||
| user-facing prompt types such as chat or instruction prompts to this format. | ||
| That approach allows us to evolve the user facing prompts without breaking | ||
| the language model interface. | ||
| */ | ||
| prompt: LanguageModelV2Prompt; | ||
| /** | ||
| Maximum number of tokens to generate. | ||
| */ | ||
| maxOutputTokens?: number; | ||
| /** | ||
| Temperature setting. The range depends on the provider and model. | ||
| */ | ||
| temperature?: number; | ||
| /** | ||
| Stop sequences. | ||
| If set, the model will stop generating text when one of the stop sequences is generated. | ||
| Providers may have limits on the number of stop sequences. | ||
| */ | ||
| stopSequences?: string[]; | ||
| /** | ||
| Nucleus sampling. | ||
| */ | ||
| topP?: number; | ||
| /** | ||
| Only sample from the top K options for each subsequent token. | ||
| Used to remove "long tail" low probability responses. | ||
| Recommended for advanced use cases only. You usually only need to use temperature. | ||
| */ | ||
| topK?: number; | ||
| /** | ||
| Presence penalty setting. It affects the likelihood of the model to | ||
| repeat information that is already in the prompt. | ||
| */ | ||
| presencePenalty?: number; | ||
| /** | ||
| Frequency penalty setting. It affects the likelihood of the model | ||
| to repeatedly use the same words or phrases. | ||
| */ | ||
| frequencyPenalty?: number; | ||
| /** | ||
| Response format. The output can either be text or JSON. Default is text. | ||
| If JSON is selected, a schema can optionally be provided to guide the LLM. | ||
| */ | ||
| responseFormat?: { | ||
| type: 'text'; | ||
| } | { | ||
| type: 'json'; | ||
| /** | ||
| * JSON schema that the generated output should conform to. | ||
| */ | ||
| schema?: JSONSchema7; | ||
| /** | ||
| * Name of output that should be generated. Used by some providers for additional LLM guidance. | ||
| */ | ||
| name?: string; | ||
| /** | ||
| * Description of the output that should be generated. Used by some providers for additional LLM guidance. | ||
| */ | ||
| description?: string; | ||
| }; | ||
| /** | ||
| The seed (integer) to use for random sampling. If set and supported | ||
| by the model, calls will generate deterministic results. | ||
| */ | ||
| seed?: number; | ||
| /** | ||
| The tools that are available for the model. | ||
| */ | ||
| tools?: Array<LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool>; | ||
| /** | ||
| Specifies how the tool should be selected. Defaults to 'auto'. | ||
| */ | ||
| toolChoice?: LanguageModelV2ToolChoice; | ||
| /** | ||
| Include raw chunks in the stream. Only applicable for streaming calls. | ||
| */ | ||
| includeRawChunks?: boolean; | ||
| /** | ||
| Abort signal for cancelling the operation. | ||
| */ | ||
| abortSignal?: AbortSignal; | ||
| /** | ||
| Additional HTTP headers to be sent with the request. | ||
| Only applicable for HTTP-based providers. | ||
| */ | ||
| headers?: Record<string, string | undefined>; | ||
| /** | ||
| * Additional provider-specific options. They are passed through | ||
| * to the provider from the AI SDK and enable provider-specific | ||
| * functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: SharedV2ProviderOptions; | ||
| }; | ||
| /** | ||
| Warning from the model provider for this call. The call will proceed, but e.g. | ||
| some settings might not be supported, which can lead to suboptimal results. | ||
| */ | ||
| type LanguageModelV2CallWarning = { | ||
| type: 'unsupported-setting'; | ||
| setting: Omit<keyof LanguageModelV2CallOptions, 'prompt'>; | ||
| details?: string; | ||
| } | { | ||
| type: 'unsupported-tool'; | ||
| tool: LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool; | ||
| details?: string; | ||
| } | { | ||
| type: 'other'; | ||
| message: string; | ||
| }; | ||
| /** | ||
| A file that has been generated by the model. | ||
| Generated files as base64 encoded strings or binary data. | ||
| The files should be returned without any unnecessary conversion. | ||
| */ | ||
| type LanguageModelV2File = { | ||
| type: 'file'; | ||
| /** | ||
| The IANA media type of the file, e.g. `image/png` or `audio/mp3`. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| Generated file data as base64 encoded strings or binary data. | ||
| The file data should be returned without any unnecessary conversion. | ||
| If the API returns base64 encoded strings, the file data should be returned | ||
| as base64 encoded strings. If the API returns binary data, the file data should | ||
| be returned as binary data. | ||
| */ | ||
| data: string | Uint8Array; | ||
| }; | ||
| /** | ||
| Reasoning that the model has generated. | ||
| */ | ||
| type LanguageModelV2Reasoning = { | ||
| type: 'reasoning'; | ||
| text: string; | ||
| /** | ||
| * Optional provider-specific metadata for the reasoning part. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| A source that has been used as input to generate the response. | ||
| */ | ||
| type LanguageModelV2Source = { | ||
| type: 'source'; | ||
| /** | ||
| * The type of source - URL sources reference web content. | ||
| */ | ||
| sourceType: 'url'; | ||
| /** | ||
| * The ID of the source. | ||
| */ | ||
| id: string; | ||
| /** | ||
| * The URL of the source. | ||
| */ | ||
| url: string; | ||
| /** | ||
| * The title of the source. | ||
| */ | ||
| title?: string; | ||
| /** | ||
| * Additional provider metadata for the source. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'source'; | ||
| /** | ||
| * The type of source - document sources reference files/documents. | ||
| */ | ||
| sourceType: 'document'; | ||
| /** | ||
| * The ID of the source. | ||
| */ | ||
| id: string; | ||
| /** | ||
| * IANA media type of the document (e.g., 'application/pdf'). | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| * The title of the document. | ||
| */ | ||
| title: string; | ||
| /** | ||
| * Optional filename of the document. | ||
| */ | ||
| filename?: string; | ||
| /** | ||
| * Additional provider metadata for the source. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| Text that the model has generated. | ||
| */ | ||
| type LanguageModelV2Text = { | ||
| type: 'text'; | ||
| /** | ||
| The text content. | ||
| */ | ||
| text: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| * Tool calls that the model has generated. | ||
| */ | ||
| type LanguageModelV2ToolCall = { | ||
| type: 'tool-call'; | ||
| /** | ||
| * The identifier of the tool call. It must be unique across all tool calls. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * The name of the tool that should be called. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| * Stringified JSON object with the tool call arguments. Must match the | ||
| * parameters schema of the tool. | ||
| */ | ||
| input: string; | ||
| /** | ||
| * Whether the tool call will be executed by the provider. | ||
| * If this flag is not set or is false, the tool call will be executed by the client. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| /** | ||
| * Additional provider-specific metadata for the tool call. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| /** | ||
| Result of a tool call that has been executed by the provider. | ||
| */ | ||
| type LanguageModelV2ToolResult = { | ||
| type: 'tool-result'; | ||
| /** | ||
| * The ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| * Result of the tool call. This is a JSON-serializable object. | ||
| */ | ||
| result: unknown; | ||
| /** | ||
| * Optional flag if the result is an error or an error message. | ||
| */ | ||
| isError?: boolean; | ||
| /** | ||
| * Whether the tool result was generated by the provider. | ||
| * If this flag is set to true, the tool result was generated by the provider. | ||
| * If this flag is not set or is false, the tool result was generated by the client. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| /** | ||
| * Additional provider-specific metadata for the tool result. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| }; | ||
| type LanguageModelV2Content = LanguageModelV2Text | LanguageModelV2Reasoning | LanguageModelV2File | LanguageModelV2Source | LanguageModelV2ToolCall | LanguageModelV2ToolResult; | ||
| /** | ||
| Reason why a language model finished generating a response. | ||
| Can be one of the following: | ||
| - `stop`: model generated stop sequence | ||
| - `length`: model generated maximum number of tokens | ||
| - `content-filter`: content filter violation stopped the model | ||
| - `tool-calls`: model triggered tool calls | ||
| - `error`: model stopped because of an error | ||
| - `other`: model stopped for other reasons | ||
| - `unknown`: the model has not transmitted a finish reason | ||
| */ | ||
| type LanguageModelV2FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown'; | ||
| interface LanguageModelV2ResponseMetadata { | ||
| /** | ||
| ID for the generated response, if the provider sends one. | ||
| */ | ||
| id?: string; | ||
| /** | ||
| Timestamp for the start of the generated response, if the provider sends one. | ||
| */ | ||
| timestamp?: Date; | ||
| /** | ||
| The ID of the response model that was used to generate the response, if the provider sends one. | ||
| */ | ||
| modelId?: string; | ||
| } | ||
| /** | ||
| Usage information for a language model call. | ||
| If your API return additional usage information, you can add it to the | ||
| provider metadata under your provider's key. | ||
| */ | ||
| type LanguageModelV2Usage = { | ||
| /** | ||
| The number of input (prompt) tokens used. | ||
| */ | ||
| inputTokens: number | undefined; | ||
| /** | ||
| The number of output (completion) tokens used. | ||
| */ | ||
| outputTokens: number | undefined; | ||
| /** | ||
| The total number of tokens as reported by the provider. | ||
| This number might be different from the sum of `inputTokens` and `outputTokens` | ||
| and e.g. include reasoning tokens or other overhead. | ||
| */ | ||
| totalTokens: number | undefined; | ||
| /** | ||
| The number of reasoning tokens used. | ||
| */ | ||
| reasoningTokens?: number | undefined; | ||
| /** | ||
| The number of cached input tokens. | ||
| */ | ||
| cachedInputTokens?: number | undefined; | ||
| }; | ||
| type LanguageModelV2StreamPart = { | ||
| type: 'text-start'; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| id: string; | ||
| } | { | ||
| type: 'text-delta'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| delta: string; | ||
| } | { | ||
| type: 'text-end'; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| id: string; | ||
| } | { | ||
| type: 'reasoning-start'; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| id: string; | ||
| } | { | ||
| type: 'reasoning-delta'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| delta: string; | ||
| } | { | ||
| type: 'reasoning-end'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'tool-input-start'; | ||
| id: string; | ||
| toolName: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| providerExecuted?: boolean; | ||
| } | { | ||
| type: 'tool-input-delta'; | ||
| id: string; | ||
| delta: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'tool-input-end'; | ||
| id: string; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | LanguageModelV2ToolCall | LanguageModelV2ToolResult | LanguageModelV2File | LanguageModelV2Source | { | ||
| type: 'stream-start'; | ||
| warnings: Array<LanguageModelV2CallWarning>; | ||
| } | ({ | ||
| type: 'response-metadata'; | ||
| } & LanguageModelV2ResponseMetadata) | { | ||
| type: 'finish'; | ||
| usage: LanguageModelV2Usage; | ||
| finishReason: LanguageModelV2FinishReason; | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| } | { | ||
| type: 'raw'; | ||
| rawValue: unknown; | ||
| } | { | ||
| type: 'error'; | ||
| error: unknown; | ||
| }; | ||
| /** | ||
| Specification for a language model that implements the language model interface version 2. | ||
| */ | ||
| type LanguageModelV2 = { | ||
| /** | ||
| The language model must specify which language model interface version it implements. | ||
| */ | ||
| readonly specificationVersion: 'v2'; | ||
| /** | ||
| Name of the provider for logging purposes. | ||
| */ | ||
| readonly provider: string; | ||
| /** | ||
| Provider-specific model ID for logging purposes. | ||
| */ | ||
| readonly modelId: string; | ||
| /** | ||
| Supported URL patterns by media type for the provider. | ||
| The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`). | ||
| and the values are arrays of regular expressions that match the URL paths. | ||
| The matching should be against lower-case URLs. | ||
| Matched URLs are supported natively by the model and are not downloaded. | ||
| @returns A map of supported URL patterns by media type (as a promise or a plain object). | ||
| */ | ||
| supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>; | ||
| /** | ||
| Generates a language model output (non-streaming). | ||
| Naming: "do" prefix to prevent accidental direct usage of the method | ||
| by the user. | ||
| */ | ||
| doGenerate(options: LanguageModelV2CallOptions): PromiseLike<{ | ||
| /** | ||
| Ordered content that the model has generated. | ||
| */ | ||
| content: Array<LanguageModelV2Content>; | ||
| /** | ||
| Finish reason. | ||
| */ | ||
| finishReason: LanguageModelV2FinishReason; | ||
| /** | ||
| Usage information. | ||
| */ | ||
| usage: LanguageModelV2Usage; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| from the provider to the AI SDK and enable provider-specific | ||
| results that can be fully encapsulated in the provider. | ||
| */ | ||
| providerMetadata?: SharedV2ProviderMetadata; | ||
| /** | ||
| Optional request information for telemetry and debugging purposes. | ||
| */ | ||
| request?: { | ||
| /** | ||
| Request HTTP body that was sent to the provider API. | ||
| */ | ||
| body?: unknown; | ||
| }; | ||
| /** | ||
| Optional response information for telemetry and debugging purposes. | ||
| */ | ||
| response?: LanguageModelV2ResponseMetadata & { | ||
| /** | ||
| Response headers. | ||
| */ | ||
| headers?: SharedV2Headers; | ||
| /** | ||
| Response HTTP body. | ||
| */ | ||
| body?: unknown; | ||
| }; | ||
| /** | ||
| Warnings for the call, e.g. unsupported settings. | ||
| */ | ||
| warnings: Array<LanguageModelV2CallWarning>; | ||
| }>; | ||
| /** | ||
| Generates a language model output (streaming). | ||
| Naming: "do" prefix to prevent accidental direct usage of the method | ||
| by the user. | ||
| * | ||
| @return A stream of higher-level language model output parts. | ||
| */ | ||
| doStream(options: LanguageModelV2CallOptions): PromiseLike<{ | ||
| stream: ReadableStream<LanguageModelV2StreamPart>; | ||
| /** | ||
| Optional request information for telemetry and debugging purposes. | ||
| */ | ||
| request?: { | ||
| /** | ||
| Request HTTP body that was sent to the provider API. | ||
| */ | ||
| body?: unknown; | ||
| }; | ||
| /** | ||
| Optional response data. | ||
| */ | ||
| response?: { | ||
| /** | ||
| Response headers. | ||
| */ | ||
| headers?: SharedV2Headers; | ||
| }; | ||
| }>; | ||
| }; | ||
| /** | ||
| * Fetch function type (standardizes the version of fetch used). | ||
| */ | ||
| type FetchFunction = typeof globalThis.fetch; | ||
| /** The Standard Schema interface. */ | ||
| interface StandardSchemaV1<Input = unknown, Output = Input> { | ||
| /** The Standard Schema properties. */ | ||
| readonly "~standard": StandardSchemaV1.Props<Input, Output>; | ||
| } | ||
| declare namespace StandardSchemaV1 { | ||
| /** The Standard Schema properties interface. */ | ||
| export interface Props<Input = unknown, Output = Input> { | ||
| /** The version number of the standard. */ | ||
| readonly version: 1; | ||
| /** The vendor name of the schema library. */ | ||
| readonly vendor: string; | ||
| /** Validates unknown input values. */ | ||
| readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>; | ||
| /** Inferred types associated with the schema. */ | ||
| readonly types?: Types<Input, Output> | undefined; | ||
| } | ||
| /** The result interface of the validate function. */ | ||
| export type Result<Output> = SuccessResult<Output> | FailureResult; | ||
| /** The result interface if validation succeeds. */ | ||
| export interface SuccessResult<Output> { | ||
| /** The typed output value. */ | ||
| readonly value: Output; | ||
| /** The non-existent issues. */ | ||
| readonly issues?: undefined; | ||
| } | ||
| /** The result interface if validation fails. */ | ||
| export interface FailureResult { | ||
| /** The issues of failed validation. */ | ||
| readonly issues: ReadonlyArray<Issue>; | ||
| } | ||
| /** The issue interface of the failure output. */ | ||
| export interface Issue { | ||
| /** The error message of the issue. */ | ||
| readonly message: string; | ||
| /** The path of the issue, if any. */ | ||
| readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined; | ||
| } | ||
| /** The path segment interface of the issue. */ | ||
| export interface PathSegment { | ||
| /** The key representing a path segment. */ | ||
| readonly key: PropertyKey; | ||
| } | ||
| /** The Standard Schema types interface. */ | ||
| export interface Types<Input = unknown, Output = Input> { | ||
| /** The input type of the schema. */ | ||
| readonly input: Input; | ||
| /** The output type of the schema. */ | ||
| readonly output: Output; | ||
| } | ||
| /** Infers the input type of a Standard Schema. */ | ||
| export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"]; | ||
| /** Infers the output type of a Standard Schema. */ | ||
| export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"]; | ||
| export { }; | ||
| } | ||
| /** | ||
| * Used to mark schemas so we can support both Zod and custom schemas. | ||
| */ | ||
| declare const schemaSymbol: unique symbol; | ||
| type ValidationResult<OBJECT> = { | ||
| success: true; | ||
| value: OBJECT; | ||
| } | { | ||
| success: false; | ||
| error: Error; | ||
| }; | ||
| type Schema<OBJECT = unknown> = { | ||
| /** | ||
| * Used to mark schemas so we can support both Zod and custom schemas. | ||
| */ | ||
| [schemaSymbol]: true; | ||
| /** | ||
| * Schema type for inference. | ||
| */ | ||
| _type: OBJECT; | ||
| /** | ||
| * Optional. Validates that the structure of a value matches this schema, | ||
| * and returns a typed version of the value if it does. | ||
| */ | ||
| readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>; | ||
| /** | ||
| * The JSON Schema for the schema. It is passed to the providers. | ||
| */ | ||
| readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>; | ||
| }; | ||
| type LazySchema<SCHEMA> = () => Schema<SCHEMA>; | ||
| type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | StandardSchemaV1<unknown, SCHEMA>; | ||
| /** | ||
| Additional provider-specific options. | ||
| They are passed through to the provider from the AI SDK and enable | ||
| provider-specific functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| type ProviderOptions = SharedV3ProviderOptions; | ||
| /** | ||
| Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer. | ||
| */ | ||
| type DataContent = string | Uint8Array | ArrayBuffer | Buffer; | ||
| /** | ||
| Text content part of a prompt. It contains a string of text. | ||
| */ | ||
| interface TextPart { | ||
| type: 'text'; | ||
| /** | ||
| The text content. | ||
| */ | ||
| text: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| Image content part of a prompt. It contains an image. | ||
| */ | ||
| interface ImagePart { | ||
| type: 'image'; | ||
| /** | ||
| Image data. Can either be: | ||
| - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer | ||
| - URL: a URL that points to the image | ||
| */ | ||
| image: DataContent | URL; | ||
| /** | ||
| Optional IANA media type of the image. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType?: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| File content part of a prompt. It contains a file. | ||
| */ | ||
| interface FilePart { | ||
| type: 'file'; | ||
| /** | ||
| File data. Can either be: | ||
| - data: a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer | ||
| - URL: a URL that points to the image | ||
| */ | ||
| data: DataContent | URL; | ||
| /** | ||
| Optional filename of the file. | ||
| */ | ||
| filename?: string; | ||
| /** | ||
| IANA media type of the file. | ||
| @see https://www.iana.org/assignments/media-types/media-types.xhtml | ||
| */ | ||
| mediaType: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| * Reasoning content part of a prompt. It contains a reasoning. | ||
| */ | ||
| interface ReasoningPart { | ||
| type: 'reasoning'; | ||
| /** | ||
| The reasoning text. | ||
| */ | ||
| text: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| Tool call content part of a prompt. It contains a tool call (usually generated by the AI model). | ||
| */ | ||
| interface ToolCallPart { | ||
| type: 'tool-call'; | ||
| /** | ||
| ID of the tool call. This ID is used to match the tool call with the tool result. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that is being called. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema. | ||
| */ | ||
| input: unknown; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| /** | ||
| Whether the tool call was executed by the provider. | ||
| */ | ||
| providerExecuted?: boolean; | ||
| } | ||
| /** | ||
| Tool result content part of a prompt. It contains the result of the tool call with the matching ID. | ||
| */ | ||
| interface ToolResultPart { | ||
| type: 'tool-result'; | ||
| /** | ||
| ID of the tool call that this result is associated with. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| Name of the tool that generated this result. | ||
| */ | ||
| toolName: string; | ||
| /** | ||
| Result of the tool call. This is a JSON-serializable object. | ||
| */ | ||
| output: LanguageModelV3ToolResultOutput; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| } | ||
| /** | ||
| * Tool approval request prompt part. | ||
| */ | ||
| type ToolApprovalRequest = { | ||
| type: 'tool-approval-request'; | ||
| /** | ||
| * ID of the tool approval. | ||
| */ | ||
| approvalId: string; | ||
| /** | ||
| * ID of the tool call that the approval request is for. | ||
| */ | ||
| toolCallId: string; | ||
| }; | ||
| /** | ||
| An assistant message. It can contain text, tool calls, or a combination of text and tool calls. | ||
| */ | ||
| type AssistantModelMessage = { | ||
| role: 'assistant'; | ||
| content: AssistantContent; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| Content of an assistant message. | ||
| It can be a string or an array of text, image, reasoning, redacted reasoning, and tool call parts. | ||
| */ | ||
| type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>; | ||
| /** | ||
| A system message. It can contain system information. | ||
| Note: using the "system" part of the prompt is strongly preferred | ||
| to increase the resilience against prompt injection attacks, | ||
| and because not all providers support several system messages. | ||
| */ | ||
| type SystemModelMessage = { | ||
| role: 'system'; | ||
| content: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| * Tool approval response prompt part. | ||
| */ | ||
| type ToolApprovalResponse = { | ||
| type: 'tool-approval-response'; | ||
| /** | ||
| * ID of the tool approval. | ||
| */ | ||
| approvalId: string; | ||
| /** | ||
| * Flag indicating whether the approval was granted or denied. | ||
| */ | ||
| approved: boolean; | ||
| /** | ||
| * Optional reason for the approval or denial. | ||
| */ | ||
| reason?: string; | ||
| }; | ||
| /** | ||
| A tool message. It contains the result of one or more tool calls. | ||
| */ | ||
| type ToolModelMessage = { | ||
| role: 'tool'; | ||
| content: ToolContent; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| Content of a tool message. It is an array of tool result parts. | ||
| */ | ||
| type ToolContent = Array<ToolResultPart | ToolApprovalResponse>; | ||
| /** | ||
| A user message. It can contain text or a combination of text and images. | ||
| */ | ||
| type UserModelMessage = { | ||
| role: 'user'; | ||
| content: UserContent; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| }; | ||
| /** | ||
| Content of a user message. It can be a string or an array of text and image parts. | ||
| */ | ||
| type UserContent = string | Array<TextPart | ImagePart | FilePart>; | ||
| /** | ||
| A message that can be used in the `messages` field of a prompt. | ||
| It can be a user message, an assistant message, or a tool message. | ||
| */ | ||
| type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage; | ||
| /** | ||
| * Additional options that are sent into each tool call. | ||
| */ | ||
| interface ToolCallOptions { | ||
| /** | ||
| * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * Messages that were sent to the language model to initiate the response that contained the tool call. | ||
| * The messages **do not** include the system prompt nor the assistant response that contained the tool call. | ||
| */ | ||
| messages: ModelMessage[]; | ||
| /** | ||
| * An optional abort signal that indicates that the overall operation should be aborted. | ||
| */ | ||
| abortSignal?: AbortSignal; | ||
| /** | ||
| * Additional context. | ||
| * | ||
| * Experimental (can break in patch releases). | ||
| */ | ||
| experimental_context?: unknown; | ||
| } | ||
| type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT; | ||
| type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T; | ||
| type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, { | ||
| /** | ||
| An async function that is called with the arguments from the tool call and produces a result. | ||
| If not provided, the tool will not be executed automatically. | ||
| @args is the input of the tool call. | ||
| @options.abortSignal is a signal that can be used to abort the tool call. | ||
| */ | ||
| execute: ToolExecuteFunction<INPUT, OUTPUT>; | ||
| outputSchema?: FlexibleSchema<OUTPUT>; | ||
| } | { | ||
| outputSchema: FlexibleSchema<OUTPUT>; | ||
| execute?: never; | ||
| }>; | ||
| /** | ||
| A tool contains the description and the schema of the input that the tool expects. | ||
| This enables the language model to generate the input. | ||
| The tool can also contain an optional execute function for the actual execution function of the tool. | ||
| */ | ||
| type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONValue | unknown | never = any> = { | ||
| /** | ||
| An optional description of what the tool does. | ||
| Will be used by the language model to decide whether to use the tool. | ||
| Not used for provider-defined tools. | ||
| */ | ||
| description?: string; | ||
| /** | ||
| Additional provider-specific metadata. They are passed through | ||
| to the provider from the AI SDK and enable provider-specific | ||
| functionality that can be fully encapsulated in the provider. | ||
| */ | ||
| providerOptions?: ProviderOptions; | ||
| /** | ||
| The schema of the input that the tool expects. The language model will use this to generate the input. | ||
| It is also used to validate the output of the language model. | ||
| Use descriptions to make the input understandable for the language model. | ||
| */ | ||
| inputSchema: FlexibleSchema<INPUT>; | ||
| /** | ||
| Whether the tool needs approval before it can be executed. | ||
| */ | ||
| needsApproval?: boolean | ((input: [INPUT] extends [never] ? unknown : INPUT, options: { | ||
| /** | ||
| * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data. | ||
| */ | ||
| toolCallId: string; | ||
| /** | ||
| * Messages that were sent to the language model to initiate the response that contained the tool call. | ||
| * The messages **do not** include the system prompt nor the assistant response that contained the tool call. | ||
| */ | ||
| messages: ModelMessage[]; | ||
| /** | ||
| * Additional context. | ||
| * | ||
| * Experimental (can break in patch releases). | ||
| */ | ||
| experimental_context?: unknown; | ||
| }) => boolean | PromiseLike<boolean>); | ||
| /** | ||
| * Optional function that is called when the argument streaming starts. | ||
| * Only called when the tool is used in a streaming context. | ||
| */ | ||
| onInputStart?: (options: ToolCallOptions) => void | PromiseLike<void>; | ||
| /** | ||
| * Optional function that is called when an argument streaming delta is available. | ||
| * Only called when the tool is used in a streaming context. | ||
| */ | ||
| onInputDelta?: (options: { | ||
| inputTextDelta: string; | ||
| } & ToolCallOptions) => void | PromiseLike<void>; | ||
| /** | ||
| * Optional function that is called when a tool call can be started, | ||
| * even if the execute function is not provided. | ||
| */ | ||
| onInputAvailable?: (options: { | ||
| input: [INPUT] extends [never] ? unknown : INPUT; | ||
| } & ToolCallOptions) => void | PromiseLike<void>; | ||
| } & ToolOutputProperties<INPUT, OUTPUT> & { | ||
| /** | ||
| Optional conversion function that maps the tool result to an output that can be used by the language model. | ||
| If not provided, the tool result will be sent as a JSON object. | ||
| */ | ||
| toModelOutput?: (output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>) => LanguageModelV3ToolResultPart['output']; | ||
| } & ({ | ||
| /** | ||
| Tool with user-defined input and output schemas. | ||
| */ | ||
| type?: undefined | 'function'; | ||
| } | { | ||
| /** | ||
| Tool that is defined at runtime (e.g. an MCP tool). | ||
| The types of input and output are not known at development time. | ||
| */ | ||
| type: 'dynamic'; | ||
| } | { | ||
| /** | ||
| Tool with provider-defined input and output schemas. | ||
| */ | ||
| type: 'provider-defined'; | ||
| /** | ||
| The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`. | ||
| */ | ||
| id: `${string}.${string}`; | ||
| /** | ||
| The name of the tool that the user must use in the tool set. | ||
| */ | ||
| name: string; | ||
| /** | ||
| The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool. | ||
| */ | ||
| args: Record<string, unknown>; | ||
| }); | ||
| type ProviderDefinedToolFactory<INPUT, ARGS extends object> = <OUTPUT>(options: ARGS & { | ||
| execute?: ToolExecuteFunction<INPUT, OUTPUT>; | ||
| needsApproval?: Tool<INPUT, OUTPUT>['needsApproval']; | ||
| toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput']; | ||
| onInputStart?: Tool<INPUT, OUTPUT>['onInputStart']; | ||
| onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta']; | ||
| onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable']; | ||
| }) => Tool<INPUT, OUTPUT>; | ||
| type ProviderDefinedToolFactoryWithOutputSchema<INPUT, OUTPUT, ARGS extends object> = (options: ARGS & { | ||
| execute?: ToolExecuteFunction<INPUT, OUTPUT>; | ||
| needsApproval?: Tool<INPUT, OUTPUT>['needsApproval']; | ||
| toModelOutput?: Tool<INPUT, OUTPUT>['toModelOutput']; | ||
| onInputStart?: Tool<INPUT, OUTPUT>['onInputStart']; | ||
| onInputDelta?: Tool<INPUT, OUTPUT>['onInputDelta']; | ||
| onInputAvailable?: Tool<INPUT, OUTPUT>['onInputAvailable']; | ||
| }) => Tool<INPUT, OUTPUT>; | ||
| type Resolvable<T> = T | PromiseLike<T> | (() => T) | (() => PromiseLike<T>); | ||
| type AnthropicMessagesModelId = 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (string & {}); | ||
@@ -14,7 +1443,7 @@ | ||
| transformRequestBody?: (args: Record<string, any>) => Record<string, any>; | ||
| supportedUrls?: () => LanguageModelV3['supportedUrls']; | ||
| supportedUrls?: () => LanguageModelV2['supportedUrls']; | ||
| generateId?: () => string; | ||
| }; | ||
| declare class AnthropicMessagesLanguageModel implements LanguageModelV3 { | ||
| readonly specificationVersion = "v3"; | ||
| declare class AnthropicMessagesLanguageModel implements LanguageModelV2 { | ||
| readonly specificationVersion = "v2"; | ||
| readonly modelId: AnthropicMessagesModelId; | ||
@@ -24,3 +1453,2 @@ private readonly config; | ||
| constructor(modelId: AnthropicMessagesModelId, config: AnthropicMessagesConfig); | ||
| supportsUrl(url: URL): boolean; | ||
| get provider(): string; | ||
@@ -33,4 +1461,4 @@ get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>; | ||
| private extractCitationDocuments; | ||
| doGenerate(options: Parameters<LanguageModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>; | ||
| doStream(options: Parameters<LanguageModelV3['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>; | ||
| doGenerate(options: Parameters<LanguageModelV2['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>>; | ||
| doStream(options: Parameters<LanguageModelV2['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>; | ||
| } | ||
@@ -47,3 +1475,3 @@ | ||
| */ | ||
| bash_20241022: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| bash_20241022: ProviderDefinedToolFactory<{ | ||
| command: string; | ||
@@ -60,3 +1488,3 @@ restart?: boolean; | ||
| */ | ||
| bash_20250124: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| bash_20250124: ProviderDefinedToolFactory<{ | ||
| command: string; | ||
@@ -75,3 +1503,3 @@ restart?: boolean; | ||
| */ | ||
| codeExecution_20250522: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| codeExecution_20250522: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| code: string; | ||
@@ -83,3 +1511,3 @@ }, { | ||
| return_code: number; | ||
| }, {}>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }, {}>>[0]) => Tool<{ | ||
| code: string; | ||
@@ -104,3 +1532,3 @@ }, { | ||
| */ | ||
| codeExecution_20250825: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| codeExecution_20250825: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| type: "bash_code_execution"; | ||
@@ -151,3 +1579,3 @@ command: string; | ||
| old_start: number | null; | ||
| }, {}>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }, {}>>[0]) => Tool<{ | ||
| type: "bash_code_execution"; | ||
@@ -211,3 +1639,3 @@ command: string; | ||
| */ | ||
| computer_20241022: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| computer_20241022: ProviderDefinedToolFactory<{ | ||
| action: "key" | "type" | "mouse_move" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "screenshot" | "cursor_position"; | ||
@@ -233,3 +1661,3 @@ coordinate?: number[]; | ||
| */ | ||
| computer_20250124: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| computer_20250124: ProviderDefinedToolFactory<{ | ||
| action: "key" | "hold_key" | "type" | "cursor_position" | "mouse_move" | "left_mouse_down" | "left_mouse_up" | "left_click" | "left_click_drag" | "right_click" | "middle_click" | "double_click" | "triple_click" | "scroll" | "wait" | "screenshot"; | ||
@@ -257,3 +1685,3 @@ coordinate?: [number, number]; | ||
| */ | ||
| memory_20250818: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| memory_20250818: ProviderDefinedToolFactory<{ | ||
| command: "view"; | ||
@@ -293,3 +1721,3 @@ path: string; | ||
| */ | ||
| textEditor_20241022: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20241022: ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert" | "undo_edit"; | ||
@@ -312,3 +1740,3 @@ path: string; | ||
| */ | ||
| textEditor_20250124: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20250124: ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert" | "undo_edit"; | ||
@@ -333,3 +1761,3 @@ path: string; | ||
| */ | ||
| textEditor_20250429: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20250429: ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert"; | ||
@@ -356,3 +1784,3 @@ path: string; | ||
| */ | ||
| textEditor_20250728: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactory<{ | ||
| textEditor_20250728: (args?: Parameters<ProviderDefinedToolFactory<{ | ||
| command: "view" | "create" | "str_replace" | "insert"; | ||
@@ -367,3 +1795,3 @@ path: string; | ||
| maxCharacters?: number; | ||
| }>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }>>[0]) => Tool<{ | ||
| command: "view" | "create" | "str_replace" | "insert"; | ||
@@ -388,3 +1816,3 @@ path: string; | ||
| */ | ||
| webFetch_20250910: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| webFetch_20250910: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| url: string; | ||
@@ -419,3 +1847,3 @@ }, { | ||
| maxContentTokens?: number; | ||
| }>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }>>[0]) => Tool<{ | ||
| url: string; | ||
@@ -453,3 +1881,3 @@ }, { | ||
| */ | ||
| webSearch_20250305: (args?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| webSearch_20250305: (args?: Parameters<ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| query: string; | ||
@@ -473,3 +1901,3 @@ }, { | ||
| }; | ||
| }>>[0]) => _ai_sdk_provider_utils.Tool<{ | ||
| }>>[0]) => Tool<{ | ||
| query: string; | ||
@@ -552,4 +1980,4 @@ }, { | ||
| declare function prepareTools({ tools, toolChoice, disableParallelToolUse, }: { | ||
| tools: LanguageModelV3CallOptions['tools']; | ||
| toolChoice?: LanguageModelV3CallOptions['toolChoice']; | ||
| tools: LanguageModelV2CallOptions['tools']; | ||
| toolChoice?: LanguageModelV2CallOptions['toolChoice']; | ||
| disableParallelToolUse?: boolean; | ||
@@ -559,3 +1987,3 @@ }): Promise<{ | ||
| toolChoice: AnthropicToolChoice | undefined; | ||
| toolWarnings: LanguageModelV3CallWarning[]; | ||
| toolWarnings: LanguageModelV2CallWarning[]; | ||
| betas: Set<string>; | ||
@@ -562,0 +1990,0 @@ }>; |
+5
-11
| { | ||
| "name": "@flatfile/anthropic", | ||
| "version": "3.0.0-beta.25", | ||
| "version": "3.0.0-beta.26", | ||
| "license": "Apache-2.0", | ||
@@ -42,10 +42,7 @@ "sideEffects": false, | ||
| "dependencies": { | ||
| "@standard-schema/spec": "^1.0.0", | ||
| "eventsource-parser": "^3.0.5", | ||
| "json-schema": "^0.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@ai-sdk/test-server": "workspace:*", | ||
| "@types/json-schema": "7.0.15", | ||
| "@types/node": "20.17.24", | ||
| "@vercel/ai-tsconfig": "workspace:*", | ||
| "tsup": "^8", | ||
@@ -62,12 +59,9 @@ "typescript": "5.8.3", | ||
| "publishConfig": { | ||
| "access": "private" | ||
| "access": "public" | ||
| }, | ||
| "homepage": "https://ai-sdk.dev/docs", | ||
| "description": "Custom Anthropic provider with V2 interfaces and bundled dependencies", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/vercel/ai.git" | ||
| "url": "git+https://github.com/flatfile/ai.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/vercel/ai/issues" | ||
| }, | ||
| "keywords": [ | ||
@@ -74,0 +68,0 @@ "ai" |
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
| var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| export { | ||
| __export, | ||
| __reExport, | ||
| __publicField, | ||
| __privateGet, | ||
| __privateAdd, | ||
| __privateSet | ||
| }; | ||
| //# sourceMappingURL=chunk-ECM5KTO2.mjs.map |
| {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} |
| import "./chunk-ECM5KTO2.mjs"; | ||
| // ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.8.3/node_modules/valibot/dist/index.js | ||
| // @__NO_SIDE_EFFECTS__ | ||
| function getDefault(schema, dataset, config2) { | ||
| return typeof schema.default === "function" ? ( | ||
| // @ts-expect-error | ||
| schema.default(dataset, config2) | ||
| ) : ( | ||
| // @ts-expect-error | ||
| schema.default | ||
| ); | ||
| } | ||
| // ../../node_modules/.pnpm/@valibot+to-json-schema@1.3.0_valibot@1.1.0/node_modules/@valibot/to-json-schema/dist/index.js | ||
| function addError(errors, message) { | ||
| if (errors) { | ||
| errors.push(message); | ||
| return errors; | ||
| } | ||
| return [message]; | ||
| } | ||
| function handleError(message, config) { | ||
| switch (config == null ? void 0 : config.errorMode) { | ||
| case "ignore": | ||
| break; | ||
| case "warn": { | ||
| console.warn(message); | ||
| break; | ||
| } | ||
| default: | ||
| throw new Error(message); | ||
| } | ||
| } | ||
| function convertAction(jsonSchema, valibotAction, config) { | ||
| var _a; | ||
| if ((_a = config == null ? void 0 : config.ignoreActions) == null ? void 0 : _a.includes(valibotAction.type)) return jsonSchema; | ||
| let errors; | ||
| switch (valibotAction.type) { | ||
| case "base64": { | ||
| jsonSchema.contentEncoding = "base64"; | ||
| break; | ||
| } | ||
| case "bic": | ||
| case "cuid2": | ||
| case "decimal": | ||
| case "digits": | ||
| case "emoji": | ||
| case "hexadecimal": | ||
| case "hex_color": | ||
| case "nanoid": | ||
| case "octal": | ||
| case "ulid": { | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "description": { | ||
| jsonSchema.description = valibotAction.description; | ||
| break; | ||
| } | ||
| case "email": { | ||
| jsonSchema.format = "email"; | ||
| break; | ||
| } | ||
| case "empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = 0; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = 0; | ||
| } | ||
| break; | ||
| } | ||
| case "entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "integer": { | ||
| jsonSchema.type = "integer"; | ||
| break; | ||
| } | ||
| case "ipv4": { | ||
| jsonSchema.format = "ipv4"; | ||
| break; | ||
| } | ||
| case "ipv6": { | ||
| jsonSchema.format = "ipv6"; | ||
| break; | ||
| } | ||
| case "iso_date": { | ||
| jsonSchema.format = "date"; | ||
| break; | ||
| } | ||
| case "iso_date_time": | ||
| case "iso_timestamp": { | ||
| jsonSchema.format = "date-time"; | ||
| break; | ||
| } | ||
| case "iso_time": { | ||
| jsonSchema.format = "time"; | ||
| break; | ||
| } | ||
| case "length": { | ||
| if (jsonSchema.type === "array") { | ||
| jsonSchema.minItems = valibotAction.requirement; | ||
| jsonSchema.maxItems = valibotAction.requirement; | ||
| } else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_entries": { | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "max_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maximum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "metadata": { | ||
| if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title; | ||
| if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description; | ||
| if (Array.isArray(valibotAction.metadata.examples)) jsonSchema.examples = valibotAction.metadata.examples; | ||
| break; | ||
| } | ||
| case "min_entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "min_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "min_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minimum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "multiple_of": { | ||
| jsonSchema.multipleOf = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "non_empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = 1; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = 1; | ||
| } | ||
| break; | ||
| } | ||
| case "regex": { | ||
| if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema."); | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "title": { | ||
| jsonSchema.title = valibotAction.title; | ||
| break; | ||
| } | ||
| case "url": { | ||
| jsonSchema.format = "uri"; | ||
| break; | ||
| } | ||
| case "uuid": { | ||
| jsonSchema.format = "uuid"; | ||
| break; | ||
| } | ||
| case "value": { | ||
| jsonSchema.const = valibotAction.requirement; | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideAction) { | ||
| const actionOverride = config.overrideAction({ | ||
| valibotAction, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (actionOverride) return { ...actionOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| function flattenPipe(pipe) { | ||
| return pipe.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item); | ||
| } | ||
| var refCount = 0; | ||
| function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) { | ||
| if (!skipRef) { | ||
| const referenceId = context.referenceMap.get(valibotSchema); | ||
| if (referenceId) { | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| } | ||
| if ("pipe" in valibotSchema) { | ||
| const flatPipe = flattenPipe(valibotSchema.pipe); | ||
| let startIndex = 0; | ||
| let stopIndex = flatPipe.length - 1; | ||
| if ((config == null ? void 0 : config.typeMode) === "input") { | ||
| const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "transform")); | ||
| if (inputStopIndex !== -1) stopIndex = inputStopIndex; | ||
| } else if ((config == null ? void 0 : config.typeMode) === "output") { | ||
| const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema"); | ||
| if (outputStartIndex !== -1) startIndex = outputStartIndex; | ||
| } | ||
| for (let index = startIndex; index <= stopIndex; index++) { | ||
| const valibotPipeItem = flatPipe[index]; | ||
| if (valibotPipeItem.kind === "schema") { | ||
| if (index > startIndex) handleError('Set the "typeMode" config to "input" or "output" to convert pipelines with multiple schemas.', config); | ||
| jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true); | ||
| } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config); | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| let errors; | ||
| switch (valibotSchema.type) { | ||
| case "boolean": { | ||
| jsonSchema.type = "boolean"; | ||
| break; | ||
| } | ||
| case "null": { | ||
| jsonSchema.type = "null"; | ||
| break; | ||
| } | ||
| case "number": { | ||
| jsonSchema.type = "number"; | ||
| break; | ||
| } | ||
| case "string": { | ||
| jsonSchema.type = "string"; | ||
| break; | ||
| } | ||
| case "array": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = convertSchema({}, valibotSchema.item, config, context); | ||
| break; | ||
| } | ||
| case "tuple": | ||
| case "tuple_with_rest": | ||
| case "loose_tuple": | ||
| case "strict_tuple": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = []; | ||
| jsonSchema.minItems = valibotSchema.items.length; | ||
| for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context)); | ||
| if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false; | ||
| break; | ||
| } | ||
| case "object": | ||
| case "object_with_rest": | ||
| case "loose_object": | ||
| case "strict_object": { | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.properties = {}; | ||
| jsonSchema.required = []; | ||
| for (const key in valibotSchema.entries) { | ||
| const entry = valibotSchema.entries[key]; | ||
| jsonSchema.properties[key] = convertSchema({}, entry, config, context); | ||
| if (entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key); | ||
| } | ||
| if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false; | ||
| break; | ||
| } | ||
| case "record": { | ||
| if ("pipe" in valibotSchema.key) errors = addError(errors, 'The "record" schema with a schema for the key that contains a "pipe" cannot be converted to JSON Schema.'); | ||
| if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`); | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context); | ||
| break; | ||
| } | ||
| case "any": | ||
| case "unknown": | ||
| break; | ||
| case "nullable": | ||
| case "nullish": { | ||
| jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }]; | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "exact_optional": | ||
| case "optional": | ||
| case "undefinedable": { | ||
| jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context); | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "literal": { | ||
| if (typeof valibotSchema.literal !== "boolean" && typeof valibotSchema.literal !== "number" && typeof valibotSchema.literal !== "string") errors = addError(errors, 'The value of the "literal" schema is not JSON compatible.'); | ||
| jsonSchema.const = valibotSchema.literal; | ||
| break; | ||
| } | ||
| case "enum": { | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "picklist": { | ||
| if (valibotSchema.options.some((option) => typeof option !== "number" && typeof option !== "string")) errors = addError(errors, 'An option of the "picklist" schema is not JSON compatible.'); | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "union": | ||
| case "variant": { | ||
| jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "intersect": { | ||
| jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "lazy": { | ||
| let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter); | ||
| if (!wrappedValibotSchema) { | ||
| wrappedValibotSchema = valibotSchema.getter(void 0); | ||
| context.getterMap.set(valibotSchema.getter, wrappedValibotSchema); | ||
| } | ||
| let referenceId = context.referenceMap.get(wrappedValibotSchema); | ||
| if (!referenceId) { | ||
| referenceId = `${refCount++}`; | ||
| context.referenceMap.set(wrappedValibotSchema, referenceId); | ||
| context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true); | ||
| } | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema: wrappedValibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideSchema) { | ||
| const schemaOverride = config.overrideSchema({ | ||
| ...context, | ||
| referenceId: context.referenceMap.get(valibotSchema), | ||
| valibotSchema, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (schemaOverride) return { ...schemaOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| var store; | ||
| function addGlobalDefs(definitions) { | ||
| store = { | ||
| ...store != null ? store : {}, | ||
| ...definitions | ||
| }; | ||
| } | ||
| function getGlobalDefs() { | ||
| return store; | ||
| } | ||
| function toJsonSchema(schema, config) { | ||
| var _a; | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| const definitions = (_a = config == null ? void 0 : config.definitions) != null ? _a : getGlobalDefs(); | ||
| if (definitions) { | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| } | ||
| const jsonSchema = convertSchema({ $schema: "http://json-schema.org/draft-07/schema#" }, schema, config, context); | ||
| if (context.referenceMap.size) jsonSchema.$defs = context.definitions; | ||
| return jsonSchema; | ||
| } | ||
| function toJsonSchemaDefs(definitions, config) { | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| return context.definitions; | ||
| } | ||
| export { | ||
| addGlobalDefs, | ||
| getGlobalDefs, | ||
| toJsonSchema, | ||
| toJsonSchemaDefs | ||
| }; | ||
| //# sourceMappingURL=dist-75K6U4I7.mjs.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __typeError = (msg) => { | ||
| throw TypeError(msg); | ||
| }; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
| var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
| var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
| var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
| var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
| var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); | ||
| export { | ||
| __export, | ||
| __reExport, | ||
| __publicField, | ||
| __privateGet, | ||
| __privateAdd, | ||
| __privateSet | ||
| }; | ||
| //# sourceMappingURL=chunk-ECM5KTO2.mjs.map |
| {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]} |
| import "./chunk-ECM5KTO2.mjs"; | ||
| // ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.8.3/node_modules/valibot/dist/index.js | ||
| // @__NO_SIDE_EFFECTS__ | ||
| function getDefault(schema, dataset, config2) { | ||
| return typeof schema.default === "function" ? ( | ||
| // @ts-expect-error | ||
| schema.default(dataset, config2) | ||
| ) : ( | ||
| // @ts-expect-error | ||
| schema.default | ||
| ); | ||
| } | ||
| // ../../node_modules/.pnpm/@valibot+to-json-schema@1.3.0_valibot@1.1.0/node_modules/@valibot/to-json-schema/dist/index.js | ||
| function addError(errors, message) { | ||
| if (errors) { | ||
| errors.push(message); | ||
| return errors; | ||
| } | ||
| return [message]; | ||
| } | ||
| function handleError(message, config) { | ||
| switch (config == null ? void 0 : config.errorMode) { | ||
| case "ignore": | ||
| break; | ||
| case "warn": { | ||
| console.warn(message); | ||
| break; | ||
| } | ||
| default: | ||
| throw new Error(message); | ||
| } | ||
| } | ||
| function convertAction(jsonSchema, valibotAction, config) { | ||
| var _a; | ||
| if ((_a = config == null ? void 0 : config.ignoreActions) == null ? void 0 : _a.includes(valibotAction.type)) return jsonSchema; | ||
| let errors; | ||
| switch (valibotAction.type) { | ||
| case "base64": { | ||
| jsonSchema.contentEncoding = "base64"; | ||
| break; | ||
| } | ||
| case "bic": | ||
| case "cuid2": | ||
| case "decimal": | ||
| case "digits": | ||
| case "emoji": | ||
| case "hexadecimal": | ||
| case "hex_color": | ||
| case "nanoid": | ||
| case "octal": | ||
| case "ulid": { | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "description": { | ||
| jsonSchema.description = valibotAction.description; | ||
| break; | ||
| } | ||
| case "email": { | ||
| jsonSchema.format = "email"; | ||
| break; | ||
| } | ||
| case "empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = 0; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = 0; | ||
| } | ||
| break; | ||
| } | ||
| case "entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "integer": { | ||
| jsonSchema.type = "integer"; | ||
| break; | ||
| } | ||
| case "ipv4": { | ||
| jsonSchema.format = "ipv4"; | ||
| break; | ||
| } | ||
| case "ipv6": { | ||
| jsonSchema.format = "ipv6"; | ||
| break; | ||
| } | ||
| case "iso_date": { | ||
| jsonSchema.format = "date"; | ||
| break; | ||
| } | ||
| case "iso_date_time": | ||
| case "iso_timestamp": { | ||
| jsonSchema.format = "date-time"; | ||
| break; | ||
| } | ||
| case "iso_time": { | ||
| jsonSchema.format = "time"; | ||
| break; | ||
| } | ||
| case "length": { | ||
| if (jsonSchema.type === "array") { | ||
| jsonSchema.minItems = valibotAction.requirement; | ||
| jsonSchema.maxItems = valibotAction.requirement; | ||
| } else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_entries": { | ||
| jsonSchema.maxProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "max_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.maxItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maxLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "max_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.maximum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "metadata": { | ||
| if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title; | ||
| if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description; | ||
| if (Array.isArray(valibotAction.metadata.examples)) jsonSchema.examples = valibotAction.metadata.examples; | ||
| break; | ||
| } | ||
| case "min_entries": { | ||
| jsonSchema.minProperties = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "min_length": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = valibotAction.requirement; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = valibotAction.requirement; | ||
| } | ||
| break; | ||
| } | ||
| case "min_value": { | ||
| if (jsonSchema.type !== "number") errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minimum = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "multiple_of": { | ||
| jsonSchema.multipleOf = valibotAction.requirement; | ||
| break; | ||
| } | ||
| case "non_empty": { | ||
| if (jsonSchema.type === "array") jsonSchema.minItems = 1; | ||
| else { | ||
| if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`); | ||
| jsonSchema.minLength = 1; | ||
| } | ||
| break; | ||
| } | ||
| case "regex": { | ||
| if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema."); | ||
| jsonSchema.pattern = valibotAction.requirement.source; | ||
| break; | ||
| } | ||
| case "title": { | ||
| jsonSchema.title = valibotAction.title; | ||
| break; | ||
| } | ||
| case "url": { | ||
| jsonSchema.format = "uri"; | ||
| break; | ||
| } | ||
| case "uuid": { | ||
| jsonSchema.format = "uuid"; | ||
| break; | ||
| } | ||
| case "value": { | ||
| jsonSchema.const = valibotAction.requirement; | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideAction) { | ||
| const actionOverride = config.overrideAction({ | ||
| valibotAction, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (actionOverride) return { ...actionOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| function flattenPipe(pipe) { | ||
| return pipe.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item); | ||
| } | ||
| var refCount = 0; | ||
| function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) { | ||
| if (!skipRef) { | ||
| const referenceId = context.referenceMap.get(valibotSchema); | ||
| if (referenceId) { | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| } | ||
| if ("pipe" in valibotSchema) { | ||
| const flatPipe = flattenPipe(valibotSchema.pipe); | ||
| let startIndex = 0; | ||
| let stopIndex = flatPipe.length - 1; | ||
| if ((config == null ? void 0 : config.typeMode) === "input") { | ||
| const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "transform")); | ||
| if (inputStopIndex !== -1) stopIndex = inputStopIndex; | ||
| } else if ((config == null ? void 0 : config.typeMode) === "output") { | ||
| const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema"); | ||
| if (outputStartIndex !== -1) startIndex = outputStartIndex; | ||
| } | ||
| for (let index = startIndex; index <= stopIndex; index++) { | ||
| const valibotPipeItem = flatPipe[index]; | ||
| if (valibotPipeItem.kind === "schema") { | ||
| if (index > startIndex) handleError('Set the "typeMode" config to "input" or "output" to convert pipelines with multiple schemas.', config); | ||
| jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true); | ||
| } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config); | ||
| } | ||
| return jsonSchema; | ||
| } | ||
| let errors; | ||
| switch (valibotSchema.type) { | ||
| case "boolean": { | ||
| jsonSchema.type = "boolean"; | ||
| break; | ||
| } | ||
| case "null": { | ||
| jsonSchema.type = "null"; | ||
| break; | ||
| } | ||
| case "number": { | ||
| jsonSchema.type = "number"; | ||
| break; | ||
| } | ||
| case "string": { | ||
| jsonSchema.type = "string"; | ||
| break; | ||
| } | ||
| case "array": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = convertSchema({}, valibotSchema.item, config, context); | ||
| break; | ||
| } | ||
| case "tuple": | ||
| case "tuple_with_rest": | ||
| case "loose_tuple": | ||
| case "strict_tuple": { | ||
| jsonSchema.type = "array"; | ||
| jsonSchema.items = []; | ||
| jsonSchema.minItems = valibotSchema.items.length; | ||
| for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context)); | ||
| if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false; | ||
| break; | ||
| } | ||
| case "object": | ||
| case "object_with_rest": | ||
| case "loose_object": | ||
| case "strict_object": { | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.properties = {}; | ||
| jsonSchema.required = []; | ||
| for (const key in valibotSchema.entries) { | ||
| const entry = valibotSchema.entries[key]; | ||
| jsonSchema.properties[key] = convertSchema({}, entry, config, context); | ||
| if (entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key); | ||
| } | ||
| if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context); | ||
| else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false; | ||
| break; | ||
| } | ||
| case "record": { | ||
| if ("pipe" in valibotSchema.key) errors = addError(errors, 'The "record" schema with a schema for the key that contains a "pipe" cannot be converted to JSON Schema.'); | ||
| if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`); | ||
| jsonSchema.type = "object"; | ||
| jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context); | ||
| break; | ||
| } | ||
| case "any": | ||
| case "unknown": | ||
| break; | ||
| case "nullable": | ||
| case "nullish": { | ||
| jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }]; | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "exact_optional": | ||
| case "optional": | ||
| case "undefinedable": { | ||
| jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context); | ||
| if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema); | ||
| break; | ||
| } | ||
| case "literal": { | ||
| if (typeof valibotSchema.literal !== "boolean" && typeof valibotSchema.literal !== "number" && typeof valibotSchema.literal !== "string") errors = addError(errors, 'The value of the "literal" schema is not JSON compatible.'); | ||
| jsonSchema.const = valibotSchema.literal; | ||
| break; | ||
| } | ||
| case "enum": { | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "picklist": { | ||
| if (valibotSchema.options.some((option) => typeof option !== "number" && typeof option !== "string")) errors = addError(errors, 'An option of the "picklist" schema is not JSON compatible.'); | ||
| jsonSchema.enum = valibotSchema.options; | ||
| break; | ||
| } | ||
| case "union": | ||
| case "variant": { | ||
| jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "intersect": { | ||
| jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context)); | ||
| break; | ||
| } | ||
| case "lazy": { | ||
| let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter); | ||
| if (!wrappedValibotSchema) { | ||
| wrappedValibotSchema = valibotSchema.getter(void 0); | ||
| context.getterMap.set(valibotSchema.getter, wrappedValibotSchema); | ||
| } | ||
| let referenceId = context.referenceMap.get(wrappedValibotSchema); | ||
| if (!referenceId) { | ||
| referenceId = `${refCount++}`; | ||
| context.referenceMap.set(wrappedValibotSchema, referenceId); | ||
| context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true); | ||
| } | ||
| jsonSchema.$ref = `#/$defs/${referenceId}`; | ||
| if (config == null ? void 0 : config.overrideRef) { | ||
| const refOverride = config.overrideRef({ | ||
| ...context, | ||
| referenceId, | ||
| valibotSchema: wrappedValibotSchema, | ||
| jsonSchema | ||
| }); | ||
| if (refOverride) jsonSchema.$ref = refOverride; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`); | ||
| } | ||
| if (config == null ? void 0 : config.overrideSchema) { | ||
| const schemaOverride = config.overrideSchema({ | ||
| ...context, | ||
| referenceId: context.referenceMap.get(valibotSchema), | ||
| valibotSchema, | ||
| jsonSchema, | ||
| errors | ||
| }); | ||
| if (schemaOverride) return { ...schemaOverride }; | ||
| } | ||
| if (errors) for (const message of errors) handleError(message, config); | ||
| return jsonSchema; | ||
| } | ||
| var store; | ||
| function addGlobalDefs(definitions) { | ||
| store = { | ||
| ...store != null ? store : {}, | ||
| ...definitions | ||
| }; | ||
| } | ||
| function getGlobalDefs() { | ||
| return store; | ||
| } | ||
| function toJsonSchema(schema, config) { | ||
| var _a; | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| const definitions = (_a = config == null ? void 0 : config.definitions) != null ? _a : getGlobalDefs(); | ||
| if (definitions) { | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| } | ||
| const jsonSchema = convertSchema({ $schema: "http://json-schema.org/draft-07/schema#" }, schema, config, context); | ||
| if (context.referenceMap.size) jsonSchema.$defs = context.definitions; | ||
| return jsonSchema; | ||
| } | ||
| function toJsonSchemaDefs(definitions, config) { | ||
| const context = { | ||
| definitions: {}, | ||
| referenceMap: /* @__PURE__ */ new Map(), | ||
| getterMap: /* @__PURE__ */ new Map() | ||
| }; | ||
| for (const key in definitions) context.referenceMap.set(definitions[key], key); | ||
| for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true); | ||
| return context.definitions; | ||
| } | ||
| export { | ||
| addGlobalDefs, | ||
| getGlobalDefs, | ||
| toJsonSchema, | ||
| toJsonSchemaDefs | ||
| }; | ||
| //# sourceMappingURL=dist-HG3FXT6O.mjs.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
53009500
0.37%2
-50%5
-16.67%300747
0.65%68
-4.23%2
100%2
100%28
211.11%- Removed
- Removed
- Removed
- Removed