@ai-sdk/provider-utils 5.0.0-beta.19 → 5.0.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -47,6 +47,54 @@ function convertAsyncIteratorToReadableStream(iterator) {
47
47
  });
48
48
  }
49
49
 
50
+ // src/uint8-utils.ts
51
+ var { btoa, atob } = globalThis;
52
+ function convertBase64ToUint8Array(base64String) {
53
+ const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
54
+ const latin1string = atob(base64Url);
55
+ return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
56
+ }
57
+ function convertUint8ArrayToBase64(array) {
58
+ let latin1string = "";
59
+ for (let i = 0; i < array.length; i++) {
60
+ latin1string += String.fromCodePoint(array[i]);
61
+ }
62
+ return btoa(latin1string);
63
+ }
64
+ function convertToBase64(value) {
65
+ return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
66
+ }
67
+
68
+ // src/convert-image-model-file-to-data-uri.ts
69
+ function convertImageModelFileToDataUri(file) {
70
+ if (file.type === "url") return file.url;
71
+ return `data:${file.mediaType};base64,${typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data)}`;
72
+ }
73
+
74
+ // src/convert-to-form-data.ts
75
+ function convertToFormData(input, options = {}) {
76
+ const { useArrayBrackets = true } = options;
77
+ const formData = new FormData();
78
+ for (const [key, value] of Object.entries(input)) {
79
+ if (value == null) {
80
+ continue;
81
+ }
82
+ if (Array.isArray(value)) {
83
+ if (value.length === 1) {
84
+ formData.append(key, value[0]);
85
+ continue;
86
+ }
87
+ const arrayKey = useArrayBrackets ? `${key}[]` : key;
88
+ for (const item of value) {
89
+ formData.append(arrayKey, item);
90
+ }
91
+ continue;
92
+ }
93
+ formData.append(key, value);
94
+ }
95
+ return formData;
96
+ }
97
+
50
98
  // src/create-tool-name-mapping.ts
51
99
  function createToolNameMapping({
52
100
  tools = [],
@@ -150,59 +198,6 @@ var DelayedPromise = class {
150
198
  }
151
199
  };
152
200
 
153
- // src/extract-response-headers.ts
154
- function extractResponseHeaders(response) {
155
- return Object.fromEntries([...response.headers]);
156
- }
157
-
158
- // src/uint8-utils.ts
159
- var { btoa, atob } = globalThis;
160
- function convertBase64ToUint8Array(base64String) {
161
- const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
162
- const latin1string = atob(base64Url);
163
- return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
164
- }
165
- function convertUint8ArrayToBase64(array) {
166
- let latin1string = "";
167
- for (let i = 0; i < array.length; i++) {
168
- latin1string += String.fromCodePoint(array[i]);
169
- }
170
- return btoa(latin1string);
171
- }
172
- function convertToBase64(value) {
173
- return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
174
- }
175
-
176
- // src/convert-image-model-file-to-data-uri.ts
177
- function convertImageModelFileToDataUri(file) {
178
- if (file.type === "url") return file.url;
179
- return `data:${file.mediaType};base64,${typeof file.data === "string" ? file.data : convertUint8ArrayToBase64(file.data)}`;
180
- }
181
-
182
- // src/convert-to-form-data.ts
183
- function convertToFormData(input, options = {}) {
184
- const { useArrayBrackets = true } = options;
185
- const formData = new FormData();
186
- for (const [key, value] of Object.entries(input)) {
187
- if (value == null) {
188
- continue;
189
- }
190
- if (Array.isArray(value)) {
191
- if (value.length === 1) {
192
- formData.append(key, value[0]);
193
- continue;
194
- }
195
- const arrayKey = useArrayBrackets ? `${key}[]` : key;
196
- for (const item of value) {
197
- formData.append(arrayKey, item);
198
- }
199
- continue;
200
- }
201
- formData.append(key, value);
202
- }
203
- return formData;
204
- }
205
-
206
201
  // src/download-error.ts
207
202
  import { AISDKError } from "@ai-sdk/provider";
208
203
  var name = "AI_DownloadError";
@@ -415,6 +410,11 @@ async function downloadBlob(url, options) {
415
410
  }
416
411
  }
417
412
 
413
+ // src/extract-response-headers.ts
414
+ function extractResponseHeaders(response) {
415
+ return Object.fromEntries([...response.headers]);
416
+ }
417
+
418
418
  // src/generate-id.ts
419
419
  import { InvalidArgumentError } from "@ai-sdk/provider";
420
420
  var createIdGenerator = ({
@@ -577,7 +577,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
577
577
  }
578
578
 
579
579
  // src/version.ts
580
- var VERSION = true ? "5.0.0-beta.19" : "0.0.0-test";
580
+ var VERSION = true ? "5.0.0-beta.20" : "0.0.0-test";
581
581
 
582
582
  // src/get-from-api.ts
583
583
  var getOriginalFetch = () => globalThis.fetch;
@@ -747,6 +747,59 @@ function loadApiKey({
747
747
  return apiKey;
748
748
  }
749
749
 
750
+ // src/load-optional-setting.ts
751
+ function loadOptionalSetting({
752
+ settingValue,
753
+ environmentVariableName
754
+ }) {
755
+ if (typeof settingValue === "string") {
756
+ return settingValue;
757
+ }
758
+ if (settingValue != null || typeof process === "undefined") {
759
+ return void 0;
760
+ }
761
+ settingValue = process.env[environmentVariableName];
762
+ if (settingValue == null || typeof settingValue !== "string") {
763
+ return void 0;
764
+ }
765
+ return settingValue;
766
+ }
767
+
768
+ // src/load-setting.ts
769
+ import { LoadSettingError } from "@ai-sdk/provider";
770
+ function loadSetting({
771
+ settingValue,
772
+ environmentVariableName,
773
+ settingName,
774
+ description
775
+ }) {
776
+ if (typeof settingValue === "string") {
777
+ return settingValue;
778
+ }
779
+ if (settingValue != null) {
780
+ throw new LoadSettingError({
781
+ message: `${description} setting must be a string.`
782
+ });
783
+ }
784
+ if (typeof process === "undefined") {
785
+ throw new LoadSettingError({
786
+ message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables are not supported in this environment.`
787
+ });
788
+ }
789
+ settingValue = process.env[environmentVariableName];
790
+ if (settingValue == null) {
791
+ throw new LoadSettingError({
792
+ message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
793
+ });
794
+ }
795
+ if (typeof settingValue !== "string") {
796
+ throw new LoadSettingError({
797
+ message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
798
+ });
799
+ }
800
+ return settingValue;
801
+ }
802
+
750
803
  // src/map-reasoning-to-provider.ts
751
804
  function isCustomReasoning(reasoning) {
752
805
  return reasoning !== void 0 && reasoning !== "provider-default";
@@ -804,59 +857,6 @@ function mapReasoningToProviderBudget({
804
857
  );
805
858
  }
806
859
 
807
- // src/load-optional-setting.ts
808
- function loadOptionalSetting({
809
- settingValue,
810
- environmentVariableName
811
- }) {
812
- if (typeof settingValue === "string") {
813
- return settingValue;
814
- }
815
- if (settingValue != null || typeof process === "undefined") {
816
- return void 0;
817
- }
818
- settingValue = process.env[environmentVariableName];
819
- if (settingValue == null || typeof settingValue !== "string") {
820
- return void 0;
821
- }
822
- return settingValue;
823
- }
824
-
825
- // src/load-setting.ts
826
- import { LoadSettingError } from "@ai-sdk/provider";
827
- function loadSetting({
828
- settingValue,
829
- environmentVariableName,
830
- settingName,
831
- description
832
- }) {
833
- if (typeof settingValue === "string") {
834
- return settingValue;
835
- }
836
- if (settingValue != null) {
837
- throw new LoadSettingError({
838
- message: `${description} setting must be a string.`
839
- });
840
- }
841
- if (typeof process === "undefined") {
842
- throw new LoadSettingError({
843
- message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables are not supported in this environment.`
844
- });
845
- }
846
- settingValue = process.env[environmentVariableName];
847
- if (settingValue == null) {
848
- throw new LoadSettingError({
849
- message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
850
- });
851
- }
852
- if (typeof settingValue !== "string") {
853
- throw new LoadSettingError({
854
- message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
855
- });
856
- }
857
- return settingValue;
858
- }
859
-
860
860
  // src/media-type-to-extension.ts
861
861
  function mediaTypeToExtension(mediaType) {
862
862
  var _a2;
@@ -2567,6 +2567,14 @@ function removeUndefinedEntries(record) {
2567
2567
  );
2568
2568
  }
2569
2569
 
2570
+ // src/resolve.ts
2571
+ async function resolve(value) {
2572
+ if (typeof value === "function") {
2573
+ value = value();
2574
+ }
2575
+ return Promise.resolve(value);
2576
+ }
2577
+
2570
2578
  // src/resolve-provider-reference.ts
2571
2579
  import {
2572
2580
  NoSuchProviderReferenceError
@@ -2585,14 +2593,6 @@ function resolveProviderReference({
2585
2593
  });
2586
2594
  }
2587
2595
 
2588
- // src/resolve.ts
2589
- async function resolve(value) {
2590
- if (typeof value === "function") {
2591
- value = value();
2592
- }
2593
- return Promise.resolve(value);
2594
- }
2595
-
2596
2596
  // src/response-handler.ts
2597
2597
  import { APICallError as APICallError4, EmptyResponseBodyError } from "@ai-sdk/provider";
2598
2598
  var createJsonErrorResponseHandler = ({
@@ -2732,6 +2732,50 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
2732
2732
  };
2733
2733
  };
2734
2734
 
2735
+ // src/is-json-serializable.ts
2736
+ function isJSONSerializable(value) {
2737
+ if (value === null || value === void 0) return true;
2738
+ const type = typeof value;
2739
+ if (type === "string" || type === "number" || type === "boolean") return true;
2740
+ if (type === "function" || type === "symbol" || type === "bigint")
2741
+ return false;
2742
+ if (Array.isArray(value)) {
2743
+ return value.every(isJSONSerializable);
2744
+ }
2745
+ if (Object.getPrototypeOf(value) === Object.prototype) {
2746
+ return Object.values(value).every(
2747
+ isJSONSerializable
2748
+ );
2749
+ }
2750
+ return false;
2751
+ }
2752
+
2753
+ // src/serialize-model-options.ts
2754
+ function serializeModelOptions(options) {
2755
+ const serializableConfig = {};
2756
+ for (const [key, value] of Object.entries(options.config)) {
2757
+ if (key === "headers") {
2758
+ const resolvedHeaders = resolveSync(value);
2759
+ if (isJSONSerializable(resolvedHeaders)) {
2760
+ serializableConfig[key] = resolvedHeaders;
2761
+ }
2762
+ } else if (isJSONSerializable(value)) {
2763
+ serializableConfig[key] = value;
2764
+ }
2765
+ }
2766
+ return { modelId: options.modelId, config: serializableConfig };
2767
+ }
2768
+ function resolveSync(value) {
2769
+ let next = value;
2770
+ if (typeof value === "function") {
2771
+ next = value();
2772
+ }
2773
+ if (next instanceof Promise) {
2774
+ throw new Error("Promise returned from resolveSync");
2775
+ }
2776
+ return next;
2777
+ }
2778
+
2735
2779
  // src/strip-file-extension.ts
2736
2780
  function stripFileExtension(filename) {
2737
2781
  const firstDotIndex = filename.indexOf(".");
@@ -2768,6 +2812,7 @@ async function* executeTool({
2768
2812
  }
2769
2813
 
2770
2814
  // src/index.ts
2815
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
2771
2816
  import {
2772
2817
  EventSourceParserStream as EventSourceParserStream2
2773
2818
  } from "eventsource-parser/stream";
@@ -2777,6 +2822,8 @@ export {
2777
2822
  DownloadError,
2778
2823
  EventSourceParserStream2 as EventSourceParserStream,
2779
2824
  VERSION,
2825
+ WORKFLOW_DESERIALIZE,
2826
+ WORKFLOW_SERIALIZE,
2780
2827
  asSchema,
2781
2828
  combineHeaders,
2782
2829
  convertAsyncIteratorToReadableStream,
@@ -2831,6 +2878,7 @@ export {
2831
2878
  resolveProviderReference,
2832
2879
  safeParseJSON,
2833
2880
  safeValidateTypes,
2881
+ serializeModelOptions,
2834
2882
  stripFileExtension,
2835
2883
  tool,
2836
2884
  validateDownloadUrl,