@ai-sdk/provider-utils 3.0.17 → 3.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.19
4
+
5
+ ### Patch Changes
6
+
7
+ - ef6d784: fix: generate zod4 json schema from input schema
8
+
9
+ ## 3.0.18
10
+
11
+ ### Patch Changes
12
+
13
+ - d1dbe5d: move DelayedPromise into provider utils
14
+
3
15
  ## 3.0.17
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -28,6 +28,24 @@ declare function delay(delayInMs?: number | null, options?: {
28
28
  abortSignal?: AbortSignal;
29
29
  }): Promise<void>;
30
30
 
31
+ /**
32
+ * Delayed promise. It is only constructed once the value is accessed.
33
+ * This is useful to avoid unhandled promise rejections when the promise is created
34
+ * but not accessed.
35
+ */
36
+ declare class DelayedPromise<T> {
37
+ private status;
38
+ private _promise;
39
+ private _resolve;
40
+ private _reject;
41
+ get promise(): Promise<T>;
42
+ resolve(value: T): void;
43
+ reject(error: unknown): void;
44
+ isResolved(): boolean;
45
+ isRejected(): boolean;
46
+ isPending(): boolean;
47
+ }
48
+
31
49
  /**
32
50
  Extracts the headers from a response object and returns them as a key-value object.
33
51
 
@@ -939,4 +957,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
939
957
  dynamic?: boolean;
940
958
  }
941
959
 
942
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
960
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -28,6 +28,24 @@ declare function delay(delayInMs?: number | null, options?: {
28
28
  abortSignal?: AbortSignal;
29
29
  }): Promise<void>;
30
30
 
31
+ /**
32
+ * Delayed promise. It is only constructed once the value is accessed.
33
+ * This is useful to avoid unhandled promise rejections when the promise is created
34
+ * but not accessed.
35
+ */
36
+ declare class DelayedPromise<T> {
37
+ private status;
38
+ private _promise;
39
+ private _resolve;
40
+ private _reject;
41
+ get promise(): Promise<T>;
42
+ resolve(value: T): void;
43
+ reject(error: unknown): void;
44
+ isResolved(): boolean;
45
+ isRejected(): boolean;
46
+ isPending(): boolean;
47
+ }
48
+
31
49
  /**
32
50
  Extracts the headers from a response object and returns them as a key-value object.
33
51
 
@@ -939,4 +957,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
939
957
  dynamic?: boolean;
940
958
  }
941
959
 
942
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
960
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type FlexibleValidator, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type InferValidator, type LazySchema, type LazyValidator, type ModelMessage, type ParseResult, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderOptions, type ReasoningPart, type Resolvable, type ResponseHandler, type Schema, type SystemModelMessage, type TextPart, type Tool, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolResult, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, lazySchema, lazyValidator, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, tool, validateTypes, validator, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/index.ts
32
32
  var src_exports = {};
33
33
  __export(src_exports, {
34
+ DelayedPromise: () => DelayedPromise,
34
35
  EventSourceParserStream: () => import_stream2.EventSourceParserStream,
35
36
  VERSION: () => VERSION,
36
37
  asSchema: () => asSchema,
@@ -169,6 +170,53 @@ function createAbortError() {
169
170
  return new DOMException("Delay was aborted", "AbortError");
170
171
  }
171
172
 
173
+ // src/delayed-promise.ts
174
+ var DelayedPromise = class {
175
+ constructor() {
176
+ this.status = { type: "pending" };
177
+ this._resolve = void 0;
178
+ this._reject = void 0;
179
+ }
180
+ get promise() {
181
+ if (this._promise) {
182
+ return this._promise;
183
+ }
184
+ this._promise = new Promise((resolve2, reject) => {
185
+ if (this.status.type === "resolved") {
186
+ resolve2(this.status.value);
187
+ } else if (this.status.type === "rejected") {
188
+ reject(this.status.error);
189
+ }
190
+ this._resolve = resolve2;
191
+ this._reject = reject;
192
+ });
193
+ return this._promise;
194
+ }
195
+ resolve(value) {
196
+ var _a;
197
+ this.status = { type: "resolved", value };
198
+ if (this._promise) {
199
+ (_a = this._resolve) == null ? void 0 : _a.call(this, value);
200
+ }
201
+ }
202
+ reject(error) {
203
+ var _a;
204
+ this.status = { type: "rejected", error };
205
+ if (this._promise) {
206
+ (_a = this._reject) == null ? void 0 : _a.call(this, error);
207
+ }
208
+ }
209
+ isResolved() {
210
+ return this.status.type === "resolved";
211
+ }
212
+ isRejected() {
213
+ return this.status.type === "rejected";
214
+ }
215
+ isPending() {
216
+ return this.status.type === "pending";
217
+ }
218
+ };
219
+
172
220
  // src/extract-response-headers.ts
173
221
  function extractResponseHeaders(response) {
174
222
  return Object.fromEntries([...response.headers]);
@@ -308,7 +356,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
308
356
  }
309
357
 
310
358
  // src/version.ts
311
- var VERSION = true ? "3.0.17" : "0.0.0-test";
359
+ var VERSION = true ? "3.0.19" : "0.0.0-test";
312
360
 
313
361
  // src/get-from-api.ts
314
362
  var getOriginalFetch = () => globalThis.fetch;
@@ -1112,6 +1160,33 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
1112
1160
  // src/zod-schema.ts
1113
1161
  var z4 = __toESM(require("zod/v4"));
1114
1162
 
1163
+ // src/add-additional-properties-to-json-schema.ts
1164
+ function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
1165
+ if (jsonSchema2.type === "object") {
1166
+ jsonSchema2.additionalProperties = false;
1167
+ const properties = jsonSchema2.properties;
1168
+ if (properties != null) {
1169
+ for (const property in properties) {
1170
+ properties[property] = addAdditionalPropertiesToJsonSchema(
1171
+ properties[property]
1172
+ );
1173
+ }
1174
+ }
1175
+ }
1176
+ if (jsonSchema2.type === "array" && jsonSchema2.items != null) {
1177
+ if (Array.isArray(jsonSchema2.items)) {
1178
+ jsonSchema2.items = jsonSchema2.items.map(
1179
+ (item) => addAdditionalPropertiesToJsonSchema(item)
1180
+ );
1181
+ } else {
1182
+ jsonSchema2.items = addAdditionalPropertiesToJsonSchema(
1183
+ jsonSchema2.items
1184
+ );
1185
+ }
1186
+ }
1187
+ return jsonSchema2;
1188
+ }
1189
+
1115
1190
  // src/zod-to-json-schema/get-relative-path.ts
1116
1191
  var getRelativePath = (pathA, pathB) => {
1117
1192
  let i = 0;
@@ -2315,11 +2390,13 @@ function zod4Schema(zodSchema2, options) {
2315
2390
  const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
2316
2391
  return jsonSchema(
2317
2392
  // defer json schema creation to avoid unnecessary computation when only validation is needed
2318
- () => z4.toJSONSchema(zodSchema2, {
2319
- target: "draft-7",
2320
- io: "output",
2321
- reused: useReferences ? "ref" : "inline"
2322
- }),
2393
+ () => addAdditionalPropertiesToJsonSchema(
2394
+ z4.toJSONSchema(zodSchema2, {
2395
+ target: "draft-7",
2396
+ io: "input",
2397
+ reused: useReferences ? "ref" : "inline"
2398
+ })
2399
+ ),
2323
2400
  {
2324
2401
  validate: async (value) => {
2325
2402
  const result = await z4.safeParseAsync(zodSchema2, value);
@@ -2429,6 +2506,7 @@ __reExport(src_exports, require("@standard-schema/spec"), module.exports);
2429
2506
  var import_stream2 = require("eventsource-parser/stream");
2430
2507
  // Annotate the CommonJS export names for ESM import in node:
2431
2508
  0 && (module.exports = {
2509
+ DelayedPromise,
2432
2510
  EventSourceParserStream,
2433
2511
  VERSION,
2434
2512
  asSchema,