@ai-sdk/provider-utils 4.0.0-beta.36 → 4.0.0-beta.38

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,18 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 4.0.0-beta.38
4
+
5
+ ### Patch Changes
6
+
7
+ - 03849b0: move DelayedPromise into provider utils
8
+
9
+ ## 4.0.0-beta.37
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [457318b]
14
+ - @ai-sdk/provider@3.0.0-beta.20
15
+
3
16
  ## 4.0.0-beta.36
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -27,6 +27,24 @@ declare function delay(delayInMs?: number | null, options?: {
27
27
  abortSignal?: AbortSignal;
28
28
  }): Promise<void>;
29
29
 
30
+ /**
31
+ * Delayed promise. It is only constructed once the value is accessed.
32
+ * This is useful to avoid unhandled promise rejections when the promise is created
33
+ * but not accessed.
34
+ */
35
+ declare class DelayedPromise<T> {
36
+ private status;
37
+ private _promise;
38
+ private _resolve;
39
+ private _reject;
40
+ get promise(): Promise<T>;
41
+ resolve(value: T): void;
42
+ reject(error: unknown): void;
43
+ isResolved(): boolean;
44
+ isRejected(): boolean;
45
+ isPending(): boolean;
46
+ }
47
+
30
48
  /**
31
49
  Extracts the headers from a response object and returns them as a key-value object.
32
50
 
@@ -1155,4 +1173,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1155
1173
  dynamic?: boolean;
1156
1174
  }
1157
1175
 
1158
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1176
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,24 @@ declare function delay(delayInMs?: number | null, options?: {
27
27
  abortSignal?: AbortSignal;
28
28
  }): Promise<void>;
29
29
 
30
+ /**
31
+ * Delayed promise. It is only constructed once the value is accessed.
32
+ * This is useful to avoid unhandled promise rejections when the promise is created
33
+ * but not accessed.
34
+ */
35
+ declare class DelayedPromise<T> {
36
+ private status;
37
+ private _promise;
38
+ private _resolve;
39
+ private _reject;
40
+ get promise(): Promise<T>;
41
+ resolve(value: T): void;
42
+ reject(error: unknown): void;
43
+ isResolved(): boolean;
44
+ isRejected(): boolean;
45
+ isPending(): boolean;
46
+ }
47
+
30
48
  /**
31
49
  Extracts the headers from a response object and returns them as a key-value object.
32
50
 
@@ -1155,4 +1173,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
1155
1173
  dynamic?: boolean;
1156
1174
  }
1157
1175
 
1158
- export { type AssistantContent, type AssistantModelMessage, type DataContent, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
1176
+ export { type AssistantContent, type AssistantModelMessage, type DataContent, DelayedPromise, type FetchFunction, type FilePart, type FlexibleSchema, type IdGenerator, type ImagePart, type InferSchema, type InferToolInput, type InferToolOutput, type LazySchema, type MaybePromiseLike, 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 ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallOptions, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolModelMessage, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type UserContent, type UserModelMessage, VERSION, type ValidationResult, asSchema, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createStatusCodeErrorResponseHandler, delay, dynamicTool, executeTool, extractResponseHeaders, generateId, getErrorMessage, getFromApi, getRuntimeEnvironmentUserAgent, injectJsonInstructionIntoMessages, isAbortError, isNonNullable, isParsableJson, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mediaTypeToExtension, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, tool, validateTypes, 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,
@@ -164,6 +165,53 @@ function createAbortError() {
164
165
  return new DOMException("Delay was aborted", "AbortError");
165
166
  }
166
167
 
168
+ // src/delayed-promise.ts
169
+ var DelayedPromise = class {
170
+ constructor() {
171
+ this.status = { type: "pending" };
172
+ this._resolve = void 0;
173
+ this._reject = void 0;
174
+ }
175
+ get promise() {
176
+ if (this._promise) {
177
+ return this._promise;
178
+ }
179
+ this._promise = new Promise((resolve2, reject) => {
180
+ if (this.status.type === "resolved") {
181
+ resolve2(this.status.value);
182
+ } else if (this.status.type === "rejected") {
183
+ reject(this.status.error);
184
+ }
185
+ this._resolve = resolve2;
186
+ this._reject = reject;
187
+ });
188
+ return this._promise;
189
+ }
190
+ resolve(value) {
191
+ var _a;
192
+ this.status = { type: "resolved", value };
193
+ if (this._promise) {
194
+ (_a = this._resolve) == null ? void 0 : _a.call(this, value);
195
+ }
196
+ }
197
+ reject(error) {
198
+ var _a;
199
+ this.status = { type: "rejected", error };
200
+ if (this._promise) {
201
+ (_a = this._reject) == null ? void 0 : _a.call(this, error);
202
+ }
203
+ }
204
+ isResolved() {
205
+ return this.status.type === "resolved";
206
+ }
207
+ isRejected() {
208
+ return this.status.type === "rejected";
209
+ }
210
+ isPending() {
211
+ return this.status.type === "pending";
212
+ }
213
+ };
214
+
167
215
  // src/extract-response-headers.ts
168
216
  function extractResponseHeaders(response) {
169
217
  return Object.fromEntries([...response.headers]);
@@ -303,7 +351,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
303
351
  }
304
352
 
305
353
  // src/version.ts
306
- var VERSION = true ? "4.0.0-beta.36" : "0.0.0-test";
354
+ var VERSION = true ? "4.0.0-beta.38" : "0.0.0-test";
307
355
 
308
356
  // src/get-from-api.ts
309
357
  var getOriginalFetch = () => globalThis.fetch;
@@ -2441,6 +2489,7 @@ __reExport(src_exports, require("@standard-schema/spec"), module.exports);
2441
2489
  var import_stream2 = require("eventsource-parser/stream");
2442
2490
  // Annotate the CommonJS export names for ESM import in node:
2443
2491
  0 && (module.exports = {
2492
+ DelayedPromise,
2444
2493
  EventSourceParserStream,
2445
2494
  VERSION,
2446
2495
  asSchema,