ai 6.0.0-beta.98 → 6.0.0
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 +829 -0
- package/README.md +17 -13
- package/dist/index.d.mts +931 -626
- package/dist/index.d.ts +931 -626
- package/dist/index.js +1409 -979
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1216 -780
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +103 -6
- package/dist/internal/index.d.ts +103 -6
- package/dist/internal/index.js +124 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +97 -79
- package/dist/internal/index.mjs.map +1 -1
- package/dist/test/index.d.mts +19 -19
- package/dist/test/index.d.ts +19 -19
- package/dist/test/index.js +2 -2
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +2 -2
- package/dist/test/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/internal/index.js
CHANGED
|
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __export = (target, all) => {
|
|
7
|
-
for (var
|
|
8
|
-
__defProp(target,
|
|
7
|
+
for (var name4 in all)
|
|
8
|
+
__defProp(target, name4, { get: all[name4], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// internal/index.ts
|
|
21
21
|
var internal_exports = {};
|
|
22
22
|
__export(internal_exports, {
|
|
23
|
-
|
|
23
|
+
asLanguageModelUsage: () => asLanguageModelUsage,
|
|
24
|
+
convertAsyncIteratorToReadableStream: () => import_provider_utils9.convertAsyncIteratorToReadableStream,
|
|
24
25
|
convertToLanguageModelPrompt: () => convertToLanguageModelPrompt,
|
|
25
26
|
prepareCallSettings: () => prepareCallSettings,
|
|
26
27
|
prepareRetries: () => prepareRetries,
|
|
@@ -28,10 +29,10 @@ __export(internal_exports, {
|
|
|
28
29
|
standardizePrompt: () => standardizePrompt
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(internal_exports);
|
|
31
|
-
var
|
|
32
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
32
33
|
|
|
33
34
|
// src/prompt/convert-to-language-model-prompt.ts
|
|
34
|
-
var
|
|
35
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
35
36
|
|
|
36
37
|
// src/util/detect-media-type.ts
|
|
37
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
@@ -147,52 +148,27 @@ function detectMediaType({
|
|
|
147
148
|
return void 0;
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
// src/util/download/download-error.ts
|
|
151
|
-
var import_provider = require("@ai-sdk/provider");
|
|
152
|
-
var name = "AI_DownloadError";
|
|
153
|
-
var marker = `vercel.ai.error.${name}`;
|
|
154
|
-
var symbol = Symbol.for(marker);
|
|
155
|
-
var _a;
|
|
156
|
-
var DownloadError = class extends import_provider.AISDKError {
|
|
157
|
-
constructor({
|
|
158
|
-
url,
|
|
159
|
-
statusCode,
|
|
160
|
-
statusText,
|
|
161
|
-
cause,
|
|
162
|
-
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
163
|
-
}) {
|
|
164
|
-
super({ name, message, cause });
|
|
165
|
-
this[_a] = true;
|
|
166
|
-
this.url = url;
|
|
167
|
-
this.statusCode = statusCode;
|
|
168
|
-
this.statusText = statusText;
|
|
169
|
-
}
|
|
170
|
-
static isInstance(error) {
|
|
171
|
-
return import_provider.AISDKError.hasMarker(error, marker);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
_a = symbol;
|
|
175
|
-
|
|
176
151
|
// src/util/download/download.ts
|
|
177
152
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
153
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
178
154
|
|
|
179
155
|
// src/version.ts
|
|
180
|
-
var VERSION = true ? "6.0.0
|
|
156
|
+
var VERSION = true ? "6.0.0" : "0.0.0-test";
|
|
181
157
|
|
|
182
158
|
// src/util/download/download.ts
|
|
183
159
|
var download = async ({ url }) => {
|
|
184
|
-
var
|
|
160
|
+
var _a4;
|
|
185
161
|
const urlText = url.toString();
|
|
186
162
|
try {
|
|
187
163
|
const response = await fetch(urlText, {
|
|
188
|
-
headers: (0,
|
|
164
|
+
headers: (0, import_provider_utils3.withUserAgentSuffix)(
|
|
189
165
|
{},
|
|
190
166
|
`ai-sdk/${VERSION}`,
|
|
191
|
-
(0,
|
|
167
|
+
(0, import_provider_utils3.getRuntimeEnvironmentUserAgent)()
|
|
192
168
|
)
|
|
193
169
|
});
|
|
194
170
|
if (!response.ok) {
|
|
195
|
-
throw new DownloadError({
|
|
171
|
+
throw new import_provider_utils2.DownloadError({
|
|
196
172
|
url: urlText,
|
|
197
173
|
statusCode: response.status,
|
|
198
174
|
statusText: response.statusText
|
|
@@ -200,13 +176,13 @@ var download = async ({ url }) => {
|
|
|
200
176
|
}
|
|
201
177
|
return {
|
|
202
178
|
data: new Uint8Array(await response.arrayBuffer()),
|
|
203
|
-
mediaType: (
|
|
179
|
+
mediaType: (_a4 = response.headers.get("content-type")) != null ? _a4 : void 0
|
|
204
180
|
};
|
|
205
181
|
} catch (error) {
|
|
206
|
-
if (DownloadError.isInstance(error)) {
|
|
182
|
+
if (import_provider_utils2.DownloadError.isInstance(error)) {
|
|
207
183
|
throw error;
|
|
208
184
|
}
|
|
209
|
-
throw new DownloadError({ url: urlText, cause: error });
|
|
185
|
+
throw new import_provider_utils2.DownloadError({ url: urlText, cause: error });
|
|
210
186
|
}
|
|
211
187
|
};
|
|
212
188
|
|
|
@@ -218,8 +194,8 @@ var createDefaultDownloadFunction = (download2 = download) => (requestedDownload
|
|
|
218
194
|
);
|
|
219
195
|
|
|
220
196
|
// src/prompt/data-content.ts
|
|
221
|
-
var
|
|
222
|
-
var
|
|
197
|
+
var import_provider = require("@ai-sdk/provider");
|
|
198
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
223
199
|
var import_v4 = require("zod/v4");
|
|
224
200
|
|
|
225
201
|
// src/prompt/split-data-url.ts
|
|
@@ -246,8 +222,8 @@ var dataContentSchema = import_v4.z.union([
|
|
|
246
222
|
import_v4.z.custom(
|
|
247
223
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
248
224
|
(value) => {
|
|
249
|
-
var
|
|
250
|
-
return (_b = (
|
|
225
|
+
var _a4, _b;
|
|
226
|
+
return (_b = (_a4 = globalThis.Buffer) == null ? void 0 : _a4.isBuffer(value)) != null ? _b : false;
|
|
251
227
|
},
|
|
252
228
|
{ message: "Must be a Buffer" }
|
|
253
229
|
)
|
|
@@ -270,7 +246,7 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
270
246
|
content.toString()
|
|
271
247
|
);
|
|
272
248
|
if (dataUrlMediaType == null || base64Content == null) {
|
|
273
|
-
throw new
|
|
249
|
+
throw new import_provider.AISDKError({
|
|
274
250
|
name: "InvalidDataContentError",
|
|
275
251
|
message: `Invalid data URL format in content ${content.toString()}`
|
|
276
252
|
});
|
|
@@ -281,25 +257,30 @@ function convertToLanguageModelV3DataContent(content) {
|
|
|
281
257
|
}
|
|
282
258
|
|
|
283
259
|
// src/prompt/invalid-message-role-error.ts
|
|
284
|
-
var
|
|
285
|
-
var
|
|
286
|
-
var
|
|
287
|
-
var
|
|
288
|
-
var
|
|
289
|
-
var InvalidMessageRoleError = class extends
|
|
260
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
261
|
+
var name = "AI_InvalidMessageRoleError";
|
|
262
|
+
var marker = `vercel.ai.error.${name}`;
|
|
263
|
+
var symbol = Symbol.for(marker);
|
|
264
|
+
var _a;
|
|
265
|
+
var InvalidMessageRoleError = class extends import_provider2.AISDKError {
|
|
290
266
|
constructor({
|
|
291
267
|
role,
|
|
292
268
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
|
293
269
|
}) {
|
|
294
|
-
super({ name
|
|
295
|
-
this[
|
|
270
|
+
super({ name, message });
|
|
271
|
+
this[_a] = true;
|
|
296
272
|
this.role = role;
|
|
297
273
|
}
|
|
298
274
|
static isInstance(error) {
|
|
299
|
-
return
|
|
275
|
+
return import_provider2.AISDKError.hasMarker(error, marker);
|
|
300
276
|
}
|
|
301
277
|
};
|
|
302
|
-
|
|
278
|
+
_a = symbol;
|
|
279
|
+
|
|
280
|
+
// src/util/as-array.ts
|
|
281
|
+
function asArray(value) {
|
|
282
|
+
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
283
|
+
}
|
|
303
284
|
|
|
304
285
|
// src/prompt/convert-to-language-model-prompt.ts
|
|
305
286
|
async function convertToLanguageModelPrompt({
|
|
@@ -313,7 +294,11 @@ async function convertToLanguageModelPrompt({
|
|
|
313
294
|
supportedUrls
|
|
314
295
|
);
|
|
315
296
|
const messages = [
|
|
316
|
-
...prompt.system != null ? [{ role: "system", content: prompt.system }] :
|
|
297
|
+
...prompt.system != null ? typeof prompt.system === "string" ? [{ role: "system", content: prompt.system }] : asArray(prompt.system).map((message) => ({
|
|
298
|
+
role: "system",
|
|
299
|
+
content: message.content,
|
|
300
|
+
providerOptions: message.providerOptions
|
|
301
|
+
})) : [],
|
|
317
302
|
...prompt.messages.map(
|
|
318
303
|
(message) => convertToLanguageModelMessage({ message, downloadedAssets })
|
|
319
304
|
)
|
|
@@ -453,8 +438,8 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
453
438
|
).flat().filter(
|
|
454
439
|
(part) => part.type === "image" || part.type === "file"
|
|
455
440
|
).map((part) => {
|
|
456
|
-
var
|
|
457
|
-
const mediaType = (
|
|
441
|
+
var _a4;
|
|
442
|
+
const mediaType = (_a4 = part.mediaType) != null ? _a4 : part.type === "image" ? "image/*" : void 0;
|
|
458
443
|
let data = part.type === "image" ? part.image : part.data;
|
|
459
444
|
if (typeof data === "string") {
|
|
460
445
|
try {
|
|
@@ -467,7 +452,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
467
452
|
(part) => part.data instanceof URL
|
|
468
453
|
).map((part) => ({
|
|
469
454
|
url: part.data,
|
|
470
|
-
isUrlSupportedByModel: part.mediaType != null && (0,
|
|
455
|
+
isUrlSupportedByModel: part.mediaType != null && (0, import_provider_utils5.isUrlSupported)({
|
|
471
456
|
url: part.data.toString(),
|
|
472
457
|
mediaType: part.mediaType,
|
|
473
458
|
supportedUrls
|
|
@@ -484,7 +469,7 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
484
469
|
);
|
|
485
470
|
}
|
|
486
471
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
487
|
-
var
|
|
472
|
+
var _a4;
|
|
488
473
|
if (part.type === "text") {
|
|
489
474
|
return {
|
|
490
475
|
type: "text",
|
|
@@ -517,7 +502,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
517
502
|
switch (type) {
|
|
518
503
|
case "image": {
|
|
519
504
|
if (data instanceof Uint8Array || typeof data === "string") {
|
|
520
|
-
mediaType = (
|
|
505
|
+
mediaType = (_a4 = detectMediaType({ data, signatures: imageMediaTypeSignatures })) != null ? _a4 : mediaType;
|
|
521
506
|
}
|
|
522
507
|
return {
|
|
523
508
|
type: "file",
|
|
@@ -569,7 +554,7 @@ function mapToolResultOutput(output) {
|
|
|
569
554
|
}
|
|
570
555
|
|
|
571
556
|
// src/prompt/prepare-tools-and-tool-choice.ts
|
|
572
|
-
var
|
|
557
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
573
558
|
|
|
574
559
|
// src/util/is-non-empty-object.ts
|
|
575
560
|
function isNonEmptyObject(object) {
|
|
@@ -589,10 +574,10 @@ async function prepareToolsAndToolChoice({
|
|
|
589
574
|
};
|
|
590
575
|
}
|
|
591
576
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
592
|
-
([
|
|
577
|
+
([name4]) => activeTools.includes(name4)
|
|
593
578
|
) : Object.entries(tools);
|
|
594
579
|
const languageModelTools = [];
|
|
595
|
-
for (const [
|
|
580
|
+
for (const [name4, tool] of filteredTools) {
|
|
596
581
|
const toolType = tool.type;
|
|
597
582
|
switch (toolType) {
|
|
598
583
|
case void 0:
|
|
@@ -600,16 +585,18 @@ async function prepareToolsAndToolChoice({
|
|
|
600
585
|
case "function":
|
|
601
586
|
languageModelTools.push({
|
|
602
587
|
type: "function",
|
|
603
|
-
name:
|
|
588
|
+
name: name4,
|
|
604
589
|
description: tool.description,
|
|
605
|
-
inputSchema: await (0,
|
|
606
|
-
|
|
590
|
+
inputSchema: await (0, import_provider_utils6.asSchema)(tool.inputSchema).jsonSchema,
|
|
591
|
+
...tool.inputExamples != null ? { inputExamples: tool.inputExamples } : {},
|
|
592
|
+
providerOptions: tool.providerOptions,
|
|
593
|
+
...tool.strict != null ? { strict: tool.strict } : {}
|
|
607
594
|
});
|
|
608
595
|
break;
|
|
609
|
-
case "provider
|
|
596
|
+
case "provider":
|
|
610
597
|
languageModelTools.push({
|
|
611
|
-
type: "provider
|
|
612
|
-
name:
|
|
598
|
+
type: "provider",
|
|
599
|
+
name: name4,
|
|
613
600
|
id: tool.id,
|
|
614
601
|
args: tool.args
|
|
615
602
|
});
|
|
@@ -627,8 +614,8 @@ async function prepareToolsAndToolChoice({
|
|
|
627
614
|
}
|
|
628
615
|
|
|
629
616
|
// src/prompt/standardize-prompt.ts
|
|
630
|
-
var
|
|
631
|
-
var
|
|
617
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
618
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
632
619
|
var import_v46 = require("zod/v4");
|
|
633
620
|
|
|
634
621
|
// src/prompt/message.ts
|
|
@@ -840,21 +827,23 @@ var modelMessageSchema = import_v45.z.union([
|
|
|
840
827
|
// src/prompt/standardize-prompt.ts
|
|
841
828
|
async function standardizePrompt(prompt) {
|
|
842
829
|
if (prompt.prompt == null && prompt.messages == null) {
|
|
843
|
-
throw new
|
|
830
|
+
throw new import_provider3.InvalidPromptError({
|
|
844
831
|
prompt,
|
|
845
832
|
message: "prompt or messages must be defined"
|
|
846
833
|
});
|
|
847
834
|
}
|
|
848
835
|
if (prompt.prompt != null && prompt.messages != null) {
|
|
849
|
-
throw new
|
|
836
|
+
throw new import_provider3.InvalidPromptError({
|
|
850
837
|
prompt,
|
|
851
838
|
message: "prompt and messages cannot be defined at the same time"
|
|
852
839
|
});
|
|
853
840
|
}
|
|
854
|
-
if (prompt.system != null && typeof prompt.system !== "string")
|
|
855
|
-
|
|
841
|
+
if (prompt.system != null && typeof prompt.system !== "string" && !asArray(prompt.system).every(
|
|
842
|
+
(message) => typeof message === "object" && message !== null && "role" in message && message.role === "system"
|
|
843
|
+
)) {
|
|
844
|
+
throw new import_provider3.InvalidPromptError({
|
|
856
845
|
prompt,
|
|
857
|
-
message: "system must be a string"
|
|
846
|
+
message: "system must be a string, SystemModelMessage, or array of SystemModelMessage"
|
|
858
847
|
});
|
|
859
848
|
}
|
|
860
849
|
let messages;
|
|
@@ -865,25 +854,25 @@ async function standardizePrompt(prompt) {
|
|
|
865
854
|
} else if (prompt.messages != null) {
|
|
866
855
|
messages = prompt.messages;
|
|
867
856
|
} else {
|
|
868
|
-
throw new
|
|
857
|
+
throw new import_provider3.InvalidPromptError({
|
|
869
858
|
prompt,
|
|
870
859
|
message: "prompt or messages must be defined"
|
|
871
860
|
});
|
|
872
861
|
}
|
|
873
862
|
if (messages.length === 0) {
|
|
874
|
-
throw new
|
|
863
|
+
throw new import_provider3.InvalidPromptError({
|
|
875
864
|
prompt,
|
|
876
865
|
message: "messages must not be empty"
|
|
877
866
|
});
|
|
878
867
|
}
|
|
879
|
-
const validationResult = await (0,
|
|
868
|
+
const validationResult = await (0, import_provider_utils7.safeValidateTypes)({
|
|
880
869
|
value: messages,
|
|
881
870
|
schema: import_v46.z.array(modelMessageSchema)
|
|
882
871
|
});
|
|
883
872
|
if (!validationResult.success) {
|
|
884
|
-
throw new
|
|
873
|
+
throw new import_provider3.InvalidPromptError({
|
|
885
874
|
prompt,
|
|
886
|
-
message: "The messages
|
|
875
|
+
message: "The messages do not match the ModelMessage[] schema.",
|
|
887
876
|
cause: validationResult.error
|
|
888
877
|
});
|
|
889
878
|
}
|
|
@@ -894,30 +883,30 @@ async function standardizePrompt(prompt) {
|
|
|
894
883
|
}
|
|
895
884
|
|
|
896
885
|
// src/error/invalid-argument-error.ts
|
|
897
|
-
var
|
|
898
|
-
var
|
|
899
|
-
var
|
|
900
|
-
var
|
|
901
|
-
var
|
|
902
|
-
var InvalidArgumentError = class extends
|
|
886
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
887
|
+
var name2 = "AI_InvalidArgumentError";
|
|
888
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
|
889
|
+
var symbol2 = Symbol.for(marker2);
|
|
890
|
+
var _a2;
|
|
891
|
+
var InvalidArgumentError = class extends import_provider4.AISDKError {
|
|
903
892
|
constructor({
|
|
904
893
|
parameter,
|
|
905
894
|
value,
|
|
906
895
|
message
|
|
907
896
|
}) {
|
|
908
897
|
super({
|
|
909
|
-
name:
|
|
898
|
+
name: name2,
|
|
910
899
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
911
900
|
});
|
|
912
|
-
this[
|
|
901
|
+
this[_a2] = true;
|
|
913
902
|
this.parameter = parameter;
|
|
914
903
|
this.value = value;
|
|
915
904
|
}
|
|
916
905
|
static isInstance(error) {
|
|
917
|
-
return
|
|
906
|
+
return import_provider4.AISDKError.hasMarker(error, marker2);
|
|
918
907
|
}
|
|
919
908
|
};
|
|
920
|
-
|
|
909
|
+
_a2 = symbol2;
|
|
921
910
|
|
|
922
911
|
// src/prompt/prepare-call-settings.ts
|
|
923
912
|
function prepareCallSettings({
|
|
@@ -1013,32 +1002,32 @@ function prepareCallSettings({
|
|
|
1013
1002
|
}
|
|
1014
1003
|
|
|
1015
1004
|
// src/util/retry-with-exponential-backoff.ts
|
|
1016
|
-
var
|
|
1017
|
-
var
|
|
1005
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
1006
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1018
1007
|
|
|
1019
1008
|
// src/util/retry-error.ts
|
|
1020
|
-
var
|
|
1021
|
-
var
|
|
1022
|
-
var
|
|
1023
|
-
var
|
|
1024
|
-
var
|
|
1025
|
-
var RetryError = class extends
|
|
1009
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
1010
|
+
var name3 = "AI_RetryError";
|
|
1011
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
|
1012
|
+
var symbol3 = Symbol.for(marker3);
|
|
1013
|
+
var _a3;
|
|
1014
|
+
var RetryError = class extends import_provider5.AISDKError {
|
|
1026
1015
|
constructor({
|
|
1027
1016
|
message,
|
|
1028
1017
|
reason,
|
|
1029
1018
|
errors
|
|
1030
1019
|
}) {
|
|
1031
|
-
super({ name:
|
|
1032
|
-
this[
|
|
1020
|
+
super({ name: name3, message });
|
|
1021
|
+
this[_a3] = true;
|
|
1033
1022
|
this.reason = reason;
|
|
1034
1023
|
this.errors = errors;
|
|
1035
1024
|
this.lastError = errors[errors.length - 1];
|
|
1036
1025
|
}
|
|
1037
1026
|
static isInstance(error) {
|
|
1038
|
-
return
|
|
1027
|
+
return import_provider5.AISDKError.hasMarker(error, marker3);
|
|
1039
1028
|
}
|
|
1040
1029
|
};
|
|
1041
|
-
|
|
1030
|
+
_a3 = symbol3;
|
|
1042
1031
|
|
|
1043
1032
|
// src/util/retry-with-exponential-backoff.ts
|
|
1044
1033
|
function getRetryDelayInMs({
|
|
@@ -1090,13 +1079,13 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1090
1079
|
try {
|
|
1091
1080
|
return await f();
|
|
1092
1081
|
} catch (error) {
|
|
1093
|
-
if ((0,
|
|
1082
|
+
if ((0, import_provider_utils8.isAbortError)(error)) {
|
|
1094
1083
|
throw error;
|
|
1095
1084
|
}
|
|
1096
1085
|
if (maxRetries === 0) {
|
|
1097
1086
|
throw error;
|
|
1098
1087
|
}
|
|
1099
|
-
const errorMessage = (0,
|
|
1088
|
+
const errorMessage = (0, import_provider_utils8.getErrorMessage)(error);
|
|
1100
1089
|
const newErrors = [...errors, error];
|
|
1101
1090
|
const tryNumber = newErrors.length;
|
|
1102
1091
|
if (tryNumber > maxRetries) {
|
|
@@ -1106,8 +1095,8 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1106
1095
|
errors: newErrors
|
|
1107
1096
|
});
|
|
1108
1097
|
}
|
|
1109
|
-
if (error instanceof Error &&
|
|
1110
|
-
await (0,
|
|
1098
|
+
if (error instanceof Error && import_provider6.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
|
1099
|
+
await (0, import_provider_utils8.delay)(
|
|
1111
1100
|
getRetryDelayInMs({
|
|
1112
1101
|
error,
|
|
1113
1102
|
exponentialBackoffDelay: delayInMs
|
|
@@ -1166,8 +1155,36 @@ function prepareRetries({
|
|
|
1166
1155
|
})
|
|
1167
1156
|
};
|
|
1168
1157
|
}
|
|
1158
|
+
|
|
1159
|
+
// src/types/usage.ts
|
|
1160
|
+
function asLanguageModelUsage(usage) {
|
|
1161
|
+
return {
|
|
1162
|
+
inputTokens: usage.inputTokens.total,
|
|
1163
|
+
inputTokenDetails: {
|
|
1164
|
+
noCacheTokens: usage.inputTokens.noCache,
|
|
1165
|
+
cacheReadTokens: usage.inputTokens.cacheRead,
|
|
1166
|
+
cacheWriteTokens: usage.inputTokens.cacheWrite
|
|
1167
|
+
},
|
|
1168
|
+
outputTokens: usage.outputTokens.total,
|
|
1169
|
+
outputTokenDetails: {
|
|
1170
|
+
textTokens: usage.outputTokens.text,
|
|
1171
|
+
reasoningTokens: usage.outputTokens.reasoning
|
|
1172
|
+
},
|
|
1173
|
+
totalTokens: addTokenCounts(
|
|
1174
|
+
usage.inputTokens.total,
|
|
1175
|
+
usage.outputTokens.total
|
|
1176
|
+
),
|
|
1177
|
+
raw: usage.raw,
|
|
1178
|
+
reasoningTokens: usage.outputTokens.reasoning,
|
|
1179
|
+
cachedInputTokens: usage.inputTokens.cacheRead
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
function addTokenCounts(tokenCount1, tokenCount2) {
|
|
1183
|
+
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
|
1184
|
+
}
|
|
1169
1185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1170
1186
|
0 && (module.exports = {
|
|
1187
|
+
asLanguageModelUsage,
|
|
1171
1188
|
convertAsyncIteratorToReadableStream,
|
|
1172
1189
|
convertToLanguageModelPrompt,
|
|
1173
1190
|
prepareCallSettings,
|