ai 3.2.45 → 3.3.1
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.d.mts +221 -21
- package/dist/index.d.ts +221 -21
- package/dist/index.js +640 -278
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +618 -266
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -8
- package/rsc/dist/index.d.ts +3 -3
- package/rsc/dist/rsc-server.d.mts +3 -3
- package/rsc/dist/rsc-server.mjs +1299 -1033
- package/rsc/dist/rsc-server.mjs.map +1 -1
- package/rsc/dist/rsc-shared.mjs +23 -45
- package/rsc/dist/rsc-shared.mjs.map +1 -1
- package/svelte/dist/index.js +1 -1
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +1 -1
- package/svelte/dist/index.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
2
|
var __export = (target, all) => {
|
3
|
-
for (var
|
4
|
-
__defProp(target,
|
3
|
+
for (var name9 in all)
|
4
|
+
__defProp(target, name9, { get: all[name9], enumerable: true });
|
5
5
|
};
|
6
6
|
|
7
7
|
// streams/index.ts
|
@@ -13,15 +13,128 @@ import {
|
|
13
13
|
} from "@ai-sdk/ui-utils";
|
14
14
|
import { generateId as generateIdImpl } from "@ai-sdk/provider-utils";
|
15
15
|
|
16
|
+
// util/retry-with-exponential-backoff.ts
|
17
|
+
import { APICallError } from "@ai-sdk/provider";
|
18
|
+
import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
19
|
+
|
20
|
+
// util/delay.ts
|
21
|
+
async function delay(delayInMs) {
|
22
|
+
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
23
|
+
}
|
24
|
+
|
25
|
+
// util/retry-error.ts
|
26
|
+
import { AISDKError } from "@ai-sdk/provider";
|
27
|
+
var name = "AI_RetryError";
|
28
|
+
var marker = `vercel.ai.error.${name}`;
|
29
|
+
var symbol = Symbol.for(marker);
|
30
|
+
var _a;
|
31
|
+
var RetryError = class extends AISDKError {
|
32
|
+
constructor({
|
33
|
+
message,
|
34
|
+
reason,
|
35
|
+
errors
|
36
|
+
}) {
|
37
|
+
super({ name, message });
|
38
|
+
this[_a] = true;
|
39
|
+
this.reason = reason;
|
40
|
+
this.errors = errors;
|
41
|
+
this.lastError = errors[errors.length - 1];
|
42
|
+
}
|
43
|
+
static isInstance(error) {
|
44
|
+
return AISDKError.hasMarker(error, marker);
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* @deprecated use `isInstance` instead
|
48
|
+
*/
|
49
|
+
static isRetryError(error) {
|
50
|
+
return error instanceof Error && error.name === name && typeof error.reason === "string" && Array.isArray(error.errors);
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
54
|
+
*/
|
55
|
+
toJSON() {
|
56
|
+
return {
|
57
|
+
name: this.name,
|
58
|
+
message: this.message,
|
59
|
+
reason: this.reason,
|
60
|
+
lastError: this.lastError,
|
61
|
+
errors: this.errors
|
62
|
+
};
|
63
|
+
}
|
64
|
+
};
|
65
|
+
_a = symbol;
|
66
|
+
|
67
|
+
// util/retry-with-exponential-backoff.ts
|
68
|
+
var retryWithExponentialBackoff = ({
|
69
|
+
maxRetries = 2,
|
70
|
+
initialDelayInMs = 2e3,
|
71
|
+
backoffFactor = 2
|
72
|
+
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
73
|
+
maxRetries,
|
74
|
+
delayInMs: initialDelayInMs,
|
75
|
+
backoffFactor
|
76
|
+
});
|
77
|
+
async function _retryWithExponentialBackoff(f, {
|
78
|
+
maxRetries,
|
79
|
+
delayInMs,
|
80
|
+
backoffFactor
|
81
|
+
}, errors = []) {
|
82
|
+
try {
|
83
|
+
return await f();
|
84
|
+
} catch (error) {
|
85
|
+
if (isAbortError(error)) {
|
86
|
+
throw error;
|
87
|
+
}
|
88
|
+
if (maxRetries === 0) {
|
89
|
+
throw error;
|
90
|
+
}
|
91
|
+
const errorMessage = getErrorMessage(error);
|
92
|
+
const newErrors = [...errors, error];
|
93
|
+
const tryNumber = newErrors.length;
|
94
|
+
if (tryNumber > maxRetries) {
|
95
|
+
throw new RetryError({
|
96
|
+
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
97
|
+
reason: "maxRetriesExceeded",
|
98
|
+
errors: newErrors
|
99
|
+
});
|
100
|
+
}
|
101
|
+
if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
102
|
+
await delay(delayInMs);
|
103
|
+
return _retryWithExponentialBackoff(
|
104
|
+
f,
|
105
|
+
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
106
|
+
newErrors
|
107
|
+
);
|
108
|
+
}
|
109
|
+
if (tryNumber === 1) {
|
110
|
+
throw error;
|
111
|
+
}
|
112
|
+
throw new RetryError({
|
113
|
+
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
114
|
+
reason: "errorNotRetryable",
|
115
|
+
errors: newErrors
|
116
|
+
});
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
// core/telemetry/assemble-operation-name.ts
|
121
|
+
function assembleOperationName({
|
122
|
+
operationName,
|
123
|
+
telemetry
|
124
|
+
}) {
|
125
|
+
return {
|
126
|
+
"operation.name": `${operationName}${(telemetry == null ? void 0 : telemetry.functionId) != null ? ` ${telemetry.functionId}` : ""}`
|
127
|
+
};
|
128
|
+
}
|
129
|
+
|
16
130
|
// core/telemetry/get-base-telemetry-attributes.ts
|
17
131
|
function getBaseTelemetryAttributes({
|
18
|
-
operationName,
|
19
132
|
model,
|
20
133
|
settings,
|
21
134
|
telemetry,
|
22
135
|
headers
|
23
136
|
}) {
|
24
|
-
var
|
137
|
+
var _a9;
|
25
138
|
return {
|
26
139
|
"ai.model.provider": model.provider,
|
27
140
|
"ai.model.id": model.modelId,
|
@@ -31,11 +144,10 @@ function getBaseTelemetryAttributes({
|
|
31
144
|
return attributes;
|
32
145
|
}, {}),
|
33
146
|
// special telemetry information
|
34
|
-
"operation.name": operationName,
|
35
147
|
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
36
148
|
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
37
149
|
// add metadata as attributes:
|
38
|
-
...Object.entries((
|
150
|
+
...Object.entries((_a9 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a9 : {}).reduce(
|
39
151
|
(attributes, [key, value]) => {
|
40
152
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
41
153
|
return attributes;
|
@@ -60,7 +172,7 @@ var noopTracer = {
|
|
60
172
|
startSpan() {
|
61
173
|
return noopSpan;
|
62
174
|
},
|
63
|
-
startActiveSpan(
|
175
|
+
startActiveSpan(name9, arg1, arg2, arg3) {
|
64
176
|
if (typeof arg1 === "function") {
|
65
177
|
return arg1(noopSpan);
|
66
178
|
}
|
@@ -128,13 +240,13 @@ function getTracer({ isEnabled }) {
|
|
128
240
|
// core/telemetry/record-span.ts
|
129
241
|
import { SpanStatusCode } from "@opentelemetry/api";
|
130
242
|
function recordSpan({
|
131
|
-
name,
|
243
|
+
name: name9,
|
132
244
|
tracer,
|
133
245
|
attributes,
|
134
246
|
fn,
|
135
247
|
endWhenDone = true
|
136
248
|
}) {
|
137
|
-
return tracer.startActiveSpan(
|
249
|
+
return tracer.startActiveSpan(name9, { attributes }, async (span) => {
|
138
250
|
try {
|
139
251
|
const result = await fn(span);
|
140
252
|
if (endWhenDone) {
|
@@ -191,68 +303,6 @@ function selectTelemetryAttributes({
|
|
191
303
|
}, {});
|
192
304
|
}
|
193
305
|
|
194
|
-
// core/util/retry-with-exponential-backoff.ts
|
195
|
-
import { APICallError, RetryError } from "@ai-sdk/provider";
|
196
|
-
import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
197
|
-
|
198
|
-
// core/util/delay.ts
|
199
|
-
async function delay(delayInMs) {
|
200
|
-
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
201
|
-
}
|
202
|
-
|
203
|
-
// core/util/retry-with-exponential-backoff.ts
|
204
|
-
var retryWithExponentialBackoff = ({
|
205
|
-
maxRetries = 2,
|
206
|
-
initialDelayInMs = 2e3,
|
207
|
-
backoffFactor = 2
|
208
|
-
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
209
|
-
maxRetries,
|
210
|
-
delayInMs: initialDelayInMs,
|
211
|
-
backoffFactor
|
212
|
-
});
|
213
|
-
async function _retryWithExponentialBackoff(f, {
|
214
|
-
maxRetries,
|
215
|
-
delayInMs,
|
216
|
-
backoffFactor
|
217
|
-
}, errors = []) {
|
218
|
-
try {
|
219
|
-
return await f();
|
220
|
-
} catch (error) {
|
221
|
-
if (isAbortError(error)) {
|
222
|
-
throw error;
|
223
|
-
}
|
224
|
-
if (maxRetries === 0) {
|
225
|
-
throw error;
|
226
|
-
}
|
227
|
-
const errorMessage = getErrorMessage(error);
|
228
|
-
const newErrors = [...errors, error];
|
229
|
-
const tryNumber = newErrors.length;
|
230
|
-
if (tryNumber > maxRetries) {
|
231
|
-
throw new RetryError({
|
232
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
233
|
-
reason: "maxRetriesExceeded",
|
234
|
-
errors: newErrors
|
235
|
-
});
|
236
|
-
}
|
237
|
-
if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
238
|
-
await delay(delayInMs);
|
239
|
-
return _retryWithExponentialBackoff(
|
240
|
-
f,
|
241
|
-
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
242
|
-
newErrors
|
243
|
-
);
|
244
|
-
}
|
245
|
-
if (tryNumber === 1) {
|
246
|
-
throw error;
|
247
|
-
}
|
248
|
-
throw new RetryError({
|
249
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
250
|
-
reason: "errorNotRetryable",
|
251
|
-
errors: newErrors
|
252
|
-
});
|
253
|
-
}
|
254
|
-
}
|
255
|
-
|
256
306
|
// core/embed/embed.ts
|
257
307
|
async function embed({
|
258
308
|
model,
|
@@ -262,20 +312,20 @@ async function embed({
|
|
262
312
|
headers,
|
263
313
|
experimental_telemetry: telemetry
|
264
314
|
}) {
|
265
|
-
var
|
315
|
+
var _a9;
|
266
316
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
267
|
-
operationName: "ai.embed",
|
268
317
|
model,
|
269
318
|
telemetry,
|
270
319
|
headers,
|
271
320
|
settings: { maxRetries }
|
272
321
|
});
|
273
|
-
const tracer = getTracer({ isEnabled: (
|
322
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
274
323
|
return recordSpan({
|
275
324
|
name: "ai.embed",
|
276
325
|
attributes: selectTelemetryAttributes({
|
277
326
|
telemetry,
|
278
327
|
attributes: {
|
328
|
+
...assembleOperationName({ operationName: "ai.embed", telemetry }),
|
279
329
|
...baseTelemetryAttributes,
|
280
330
|
"ai.value": { input: () => JSON.stringify(value) }
|
281
331
|
}
|
@@ -291,6 +341,10 @@ async function embed({
|
|
291
341
|
attributes: selectTelemetryAttributes({
|
292
342
|
telemetry,
|
293
343
|
attributes: {
|
344
|
+
...assembleOperationName({
|
345
|
+
operationName: "ai.embed.doEmbed",
|
346
|
+
telemetry
|
347
|
+
}),
|
294
348
|
...baseTelemetryAttributes,
|
295
349
|
// specific settings that only make sense on the outer level:
|
296
350
|
"ai.values": { input: () => [JSON.stringify(value)] }
|
@@ -298,14 +352,14 @@ async function embed({
|
|
298
352
|
}),
|
299
353
|
tracer,
|
300
354
|
fn: async (doEmbedSpan) => {
|
301
|
-
var
|
355
|
+
var _a10;
|
302
356
|
const modelResponse = await model.doEmbed({
|
303
357
|
values: [value],
|
304
358
|
abortSignal,
|
305
359
|
headers
|
306
360
|
});
|
307
361
|
const embedding2 = modelResponse.embeddings[0];
|
308
|
-
const usage2 = (
|
362
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
309
363
|
doEmbedSpan.setAttributes(
|
310
364
|
selectTelemetryAttributes({
|
311
365
|
telemetry,
|
@@ -371,20 +425,20 @@ async function embedMany({
|
|
371
425
|
headers,
|
372
426
|
experimental_telemetry: telemetry
|
373
427
|
}) {
|
374
|
-
var
|
428
|
+
var _a9;
|
375
429
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
376
|
-
operationName: "ai.embedMany",
|
377
430
|
model,
|
378
431
|
telemetry,
|
379
432
|
headers,
|
380
433
|
settings: { maxRetries }
|
381
434
|
});
|
382
|
-
const tracer = getTracer({ isEnabled: (
|
435
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
383
436
|
return recordSpan({
|
384
437
|
name: "ai.embedMany",
|
385
438
|
attributes: selectTelemetryAttributes({
|
386
439
|
telemetry,
|
387
440
|
attributes: {
|
441
|
+
...assembleOperationName({ operationName: "ai.embedMany", telemetry }),
|
388
442
|
...baseTelemetryAttributes,
|
389
443
|
// specific settings that only make sense on the outer level:
|
390
444
|
"ai.values": {
|
@@ -403,6 +457,10 @@ async function embedMany({
|
|
403
457
|
attributes: selectTelemetryAttributes({
|
404
458
|
telemetry,
|
405
459
|
attributes: {
|
460
|
+
...assembleOperationName({
|
461
|
+
operationName: "ai.embedMany.doEmbed",
|
462
|
+
telemetry
|
463
|
+
}),
|
406
464
|
...baseTelemetryAttributes,
|
407
465
|
// specific settings that only make sense on the outer level:
|
408
466
|
"ai.values": {
|
@@ -412,14 +470,14 @@ async function embedMany({
|
|
412
470
|
}),
|
413
471
|
tracer,
|
414
472
|
fn: async (doEmbedSpan) => {
|
415
|
-
var
|
473
|
+
var _a10;
|
416
474
|
const modelResponse = await model.doEmbed({
|
417
475
|
values,
|
418
476
|
abortSignal,
|
419
477
|
headers
|
420
478
|
});
|
421
479
|
const embeddings3 = modelResponse.embeddings;
|
422
|
-
const usage2 = (
|
480
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
423
481
|
doEmbedSpan.setAttributes(
|
424
482
|
selectTelemetryAttributes({
|
425
483
|
telemetry,
|
@@ -458,6 +516,10 @@ async function embedMany({
|
|
458
516
|
attributes: selectTelemetryAttributes({
|
459
517
|
telemetry,
|
460
518
|
attributes: {
|
519
|
+
...assembleOperationName({
|
520
|
+
operationName: "ai.embedMany.doEmbed",
|
521
|
+
telemetry
|
522
|
+
}),
|
461
523
|
...baseTelemetryAttributes,
|
462
524
|
// specific settings that only make sense on the outer level:
|
463
525
|
"ai.values": {
|
@@ -467,14 +529,14 @@ async function embedMany({
|
|
467
529
|
}),
|
468
530
|
tracer,
|
469
531
|
fn: async (doEmbedSpan) => {
|
470
|
-
var
|
532
|
+
var _a10;
|
471
533
|
const modelResponse = await model.doEmbed({
|
472
534
|
values: chunk,
|
473
535
|
abortSignal,
|
474
536
|
headers
|
475
537
|
});
|
476
538
|
const embeddings2 = modelResponse.embeddings;
|
477
|
-
const usage2 = (
|
539
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
478
540
|
doEmbedSpan.setAttributes(
|
479
541
|
selectTelemetryAttributes({
|
480
542
|
telemetry,
|
@@ -521,35 +583,62 @@ var DefaultEmbedManyResult = class {
|
|
521
583
|
};
|
522
584
|
|
523
585
|
// core/generate-object/generate-object.ts
|
524
|
-
import { NoObjectGeneratedError } from "@ai-sdk/provider";
|
525
586
|
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
526
587
|
|
527
588
|
// core/prompt/convert-to-language-model-prompt.ts
|
528
589
|
import { getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider-utils";
|
529
590
|
|
530
|
-
//
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
591
|
+
// util/download-error.ts
|
592
|
+
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
593
|
+
var name2 = "AI_DownloadError";
|
594
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
595
|
+
var symbol2 = Symbol.for(marker2);
|
596
|
+
var _a2;
|
597
|
+
var DownloadError = class extends AISDKError2 {
|
598
|
+
constructor({
|
599
|
+
url,
|
600
|
+
statusCode,
|
601
|
+
statusText,
|
602
|
+
cause,
|
603
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
604
|
+
}) {
|
605
|
+
super({ name: name2, message, cause });
|
606
|
+
this[_a2] = true;
|
607
|
+
this.url = url;
|
608
|
+
this.statusCode = statusCode;
|
609
|
+
this.statusText = statusText;
|
542
610
|
}
|
543
|
-
|
544
|
-
|
611
|
+
static isInstance(error) {
|
612
|
+
return AISDKError2.hasMarker(error, marker2);
|
613
|
+
}
|
614
|
+
/**
|
615
|
+
* @deprecated use `isInstance` instead
|
616
|
+
*/
|
617
|
+
static isDownloadError(error) {
|
618
|
+
return error instanceof Error && error.name === name2 && typeof error.url === "string" && (error.statusCode == null || typeof error.statusCode === "number") && (error.statusText == null || typeof error.statusText === "string");
|
619
|
+
}
|
620
|
+
/**
|
621
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
622
|
+
*/
|
623
|
+
toJSON() {
|
624
|
+
return {
|
625
|
+
name: this.name,
|
626
|
+
message: this.message,
|
627
|
+
url: this.url,
|
628
|
+
statusCode: this.statusCode,
|
629
|
+
statusText: this.statusText,
|
630
|
+
cause: this.cause
|
631
|
+
};
|
632
|
+
}
|
633
|
+
};
|
634
|
+
_a2 = symbol2;
|
545
635
|
|
546
|
-
//
|
547
|
-
import { DownloadError } from "@ai-sdk/provider";
|
636
|
+
// util/download.ts
|
548
637
|
async function download({
|
549
638
|
url,
|
550
639
|
fetchImplementation = fetch
|
551
640
|
}) {
|
552
|
-
var
|
641
|
+
var _a9;
|
553
642
|
const urlText = url.toString();
|
554
643
|
try {
|
555
644
|
const response = await fetchImplementation(urlText);
|
@@ -562,22 +651,79 @@ async function download({
|
|
562
651
|
}
|
563
652
|
return {
|
564
653
|
data: new Uint8Array(await response.arrayBuffer()),
|
565
|
-
mimeType: (
|
654
|
+
mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
|
566
655
|
};
|
567
656
|
} catch (error) {
|
568
|
-
if (DownloadError.
|
657
|
+
if (DownloadError.isInstance(error)) {
|
569
658
|
throw error;
|
570
659
|
}
|
571
660
|
throw new DownloadError({ url: urlText, cause: error });
|
572
661
|
}
|
573
662
|
}
|
574
663
|
|
664
|
+
// core/util/detect-image-mimetype.ts
|
665
|
+
var mimeTypeSignatures = [
|
666
|
+
{ mimeType: "image/gif", bytes: [71, 73, 70] },
|
667
|
+
{ mimeType: "image/png", bytes: [137, 80, 78, 71] },
|
668
|
+
{ mimeType: "image/jpeg", bytes: [255, 216] },
|
669
|
+
{ mimeType: "image/webp", bytes: [82, 73, 70, 70] }
|
670
|
+
];
|
671
|
+
function detectImageMimeType(image) {
|
672
|
+
for (const { bytes, mimeType } of mimeTypeSignatures) {
|
673
|
+
if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
|
674
|
+
return mimeType;
|
675
|
+
}
|
676
|
+
}
|
677
|
+
return void 0;
|
678
|
+
}
|
679
|
+
|
575
680
|
// core/prompt/data-content.ts
|
576
|
-
import { InvalidDataContentError } from "@ai-sdk/provider";
|
577
681
|
import {
|
578
682
|
convertBase64ToUint8Array,
|
579
683
|
convertUint8ArrayToBase64
|
580
684
|
} from "@ai-sdk/provider-utils";
|
685
|
+
|
686
|
+
// core/prompt/invalid-data-content-error.ts
|
687
|
+
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
688
|
+
var name3 = "AI_InvalidDataContentError";
|
689
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
690
|
+
var symbol3 = Symbol.for(marker3);
|
691
|
+
var _a3;
|
692
|
+
var InvalidDataContentError = class extends AISDKError3 {
|
693
|
+
constructor({
|
694
|
+
content,
|
695
|
+
cause,
|
696
|
+
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
697
|
+
}) {
|
698
|
+
super({ name: name3, message, cause });
|
699
|
+
this[_a3] = true;
|
700
|
+
this.content = content;
|
701
|
+
}
|
702
|
+
static isInstance(error) {
|
703
|
+
return AISDKError3.hasMarker(error, marker3);
|
704
|
+
}
|
705
|
+
/**
|
706
|
+
* @deprecated use `isInstance` instead
|
707
|
+
*/
|
708
|
+
static isInvalidDataContentError(error) {
|
709
|
+
return error instanceof Error && error.name === name3 && error.content != null;
|
710
|
+
}
|
711
|
+
/**
|
712
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
713
|
+
*/
|
714
|
+
toJSON() {
|
715
|
+
return {
|
716
|
+
name: this.name,
|
717
|
+
message: this.message,
|
718
|
+
stack: this.stack,
|
719
|
+
cause: this.cause,
|
720
|
+
content: this.content
|
721
|
+
};
|
722
|
+
}
|
723
|
+
};
|
724
|
+
_a3 = symbol3;
|
725
|
+
|
726
|
+
// core/prompt/data-content.ts
|
581
727
|
function convertDataContentToBase64String(content) {
|
582
728
|
if (typeof content === "string") {
|
583
729
|
return content;
|
@@ -616,18 +762,32 @@ function convertUint8ArrayToText(uint8Array) {
|
|
616
762
|
}
|
617
763
|
|
618
764
|
// core/prompt/invalid-message-role-error.ts
|
619
|
-
|
765
|
+
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
766
|
+
var name4 = "AI_InvalidMessageRoleError";
|
767
|
+
var marker4 = `vercel.ai.error.${name4}`;
|
768
|
+
var symbol4 = Symbol.for(marker4);
|
769
|
+
var _a4;
|
770
|
+
var InvalidMessageRoleError = class extends AISDKError4 {
|
620
771
|
constructor({
|
621
772
|
role,
|
622
773
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
623
774
|
}) {
|
624
|
-
super(message);
|
625
|
-
this
|
775
|
+
super({ name: name4, message });
|
776
|
+
this[_a4] = true;
|
626
777
|
this.role = role;
|
627
778
|
}
|
779
|
+
static isInstance(error) {
|
780
|
+
return AISDKError4.hasMarker(error, marker4);
|
781
|
+
}
|
782
|
+
/**
|
783
|
+
* @deprecated use `isInstance` instead
|
784
|
+
*/
|
628
785
|
static isInvalidMessageRoleError(error) {
|
629
|
-
return error instanceof Error && error.name ===
|
786
|
+
return error instanceof Error && error.name === name4 && typeof error.role === "string";
|
630
787
|
}
|
788
|
+
/**
|
789
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
790
|
+
*/
|
631
791
|
toJSON() {
|
632
792
|
return {
|
633
793
|
name: this.name,
|
@@ -637,6 +797,7 @@ var InvalidMessageRoleError = class extends Error {
|
|
637
797
|
};
|
638
798
|
}
|
639
799
|
};
|
800
|
+
_a4 = symbol4;
|
640
801
|
|
641
802
|
// core/prompt/convert-to-language-model-prompt.ts
|
642
803
|
async function convertToLanguageModelPrompt({
|
@@ -690,7 +851,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
690
851
|
role: "user",
|
691
852
|
content: message.content.map(
|
692
853
|
(part) => {
|
693
|
-
var
|
854
|
+
var _a9, _b, _c;
|
694
855
|
switch (part.type) {
|
695
856
|
case "text": {
|
696
857
|
return part;
|
@@ -708,7 +869,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
708
869
|
return {
|
709
870
|
type: "image",
|
710
871
|
image: downloadedImage.data,
|
711
|
-
mimeType: (
|
872
|
+
mimeType: (_a9 = part.mimeType) != null ? _a9 : downloadedImage.mimeType
|
712
873
|
};
|
713
874
|
}
|
714
875
|
}
|
@@ -857,8 +1018,48 @@ function getValidatedPrompt(prompt) {
|
|
857
1018
|
};
|
858
1019
|
}
|
859
1020
|
|
1021
|
+
// errors/invalid-argument-error.ts
|
1022
|
+
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
1023
|
+
var name5 = "AI_InvalidArgumentError";
|
1024
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
1025
|
+
var symbol5 = Symbol.for(marker5);
|
1026
|
+
var _a5;
|
1027
|
+
var InvalidArgumentError = class extends AISDKError5 {
|
1028
|
+
constructor({
|
1029
|
+
parameter,
|
1030
|
+
value,
|
1031
|
+
message
|
1032
|
+
}) {
|
1033
|
+
super({
|
1034
|
+
name: name5,
|
1035
|
+
message: `Invalid argument for parameter ${parameter}: ${message}`
|
1036
|
+
});
|
1037
|
+
this[_a5] = true;
|
1038
|
+
this.parameter = parameter;
|
1039
|
+
this.value = value;
|
1040
|
+
}
|
1041
|
+
static isInstance(error) {
|
1042
|
+
return AISDKError5.hasMarker(error, marker5);
|
1043
|
+
}
|
1044
|
+
/**
|
1045
|
+
* @deprecated use `isInstance` instead
|
1046
|
+
*/
|
1047
|
+
static isInvalidArgumentError(error) {
|
1048
|
+
return error instanceof Error && error.name === name5 && typeof error.parameter === "string" && typeof error.value === "string";
|
1049
|
+
}
|
1050
|
+
toJSON() {
|
1051
|
+
return {
|
1052
|
+
name: this.name,
|
1053
|
+
message: this.message,
|
1054
|
+
stack: this.stack,
|
1055
|
+
parameter: this.parameter,
|
1056
|
+
value: this.value
|
1057
|
+
};
|
1058
|
+
}
|
1059
|
+
};
|
1060
|
+
_a5 = symbol5;
|
1061
|
+
|
860
1062
|
// core/prompt/prepare-call-settings.ts
|
861
|
-
import { InvalidArgumentError } from "@ai-sdk/provider";
|
862
1063
|
function prepareCallSettings({
|
863
1064
|
maxTokens,
|
864
1065
|
temperature,
|
@@ -972,8 +1173,8 @@ function prepareResponseHeaders(init, {
|
|
972
1173
|
contentType,
|
973
1174
|
dataStreamVersion
|
974
1175
|
}) {
|
975
|
-
var
|
976
|
-
const headers = new Headers((
|
1176
|
+
var _a9;
|
1177
|
+
const headers = new Headers((_a9 = init == null ? void 0 : init.headers) != null ? _a9 : {});
|
977
1178
|
if (!headers.has("Content-Type")) {
|
978
1179
|
headers.set("Content-Type", contentType);
|
979
1180
|
}
|
@@ -986,7 +1187,7 @@ function prepareResponseHeaders(init, {
|
|
986
1187
|
// core/util/schema.ts
|
987
1188
|
import { validatorSymbol } from "@ai-sdk/provider-utils";
|
988
1189
|
import zodToJsonSchema from "zod-to-json-schema";
|
989
|
-
var schemaSymbol = Symbol("vercel.ai.schema");
|
1190
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
990
1191
|
function jsonSchema(jsonSchema2, {
|
991
1192
|
validate
|
992
1193
|
} = {}) {
|
@@ -1037,6 +1238,41 @@ function injectJsonSchemaIntoSystem({
|
|
1037
1238
|
].filter((line) => line != null).join("\n");
|
1038
1239
|
}
|
1039
1240
|
|
1241
|
+
// core/generate-object/no-object-generated-error.ts
|
1242
|
+
import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
|
1243
|
+
var name6 = "AI_NoObjectGeneratedError";
|
1244
|
+
var marker6 = `vercel.ai.error.${name6}`;
|
1245
|
+
var symbol6 = Symbol.for(marker6);
|
1246
|
+
var _a6;
|
1247
|
+
var NoObjectGeneratedError = class extends AISDKError6 {
|
1248
|
+
// used in isInstance
|
1249
|
+
constructor({ message = "No object generated." } = {}) {
|
1250
|
+
super({ name: name6, message });
|
1251
|
+
this[_a6] = true;
|
1252
|
+
}
|
1253
|
+
static isInstance(error) {
|
1254
|
+
return AISDKError6.hasMarker(error, marker6);
|
1255
|
+
}
|
1256
|
+
/**
|
1257
|
+
* @deprecated Use isInstance instead.
|
1258
|
+
*/
|
1259
|
+
static isNoObjectGeneratedError(error) {
|
1260
|
+
return error instanceof Error && error.name === name6;
|
1261
|
+
}
|
1262
|
+
/**
|
1263
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
1264
|
+
*/
|
1265
|
+
toJSON() {
|
1266
|
+
return {
|
1267
|
+
name: this.name,
|
1268
|
+
cause: this.cause,
|
1269
|
+
message: this.message,
|
1270
|
+
stack: this.stack
|
1271
|
+
};
|
1272
|
+
}
|
1273
|
+
};
|
1274
|
+
_a6 = symbol6;
|
1275
|
+
|
1040
1276
|
// core/generate-object/generate-object.ts
|
1041
1277
|
async function generateObject({
|
1042
1278
|
model,
|
@@ -1051,21 +1287,24 @@ async function generateObject({
|
|
1051
1287
|
experimental_telemetry: telemetry,
|
1052
1288
|
...settings
|
1053
1289
|
}) {
|
1054
|
-
var
|
1290
|
+
var _a9;
|
1055
1291
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1056
|
-
operationName: "ai.generateObject",
|
1057
1292
|
model,
|
1058
1293
|
telemetry,
|
1059
1294
|
headers,
|
1060
1295
|
settings: { ...settings, maxRetries }
|
1061
1296
|
});
|
1062
1297
|
const schema = asSchema(inputSchema);
|
1063
|
-
const tracer = getTracer({ isEnabled: (
|
1298
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1064
1299
|
return recordSpan({
|
1065
1300
|
name: "ai.generateObject",
|
1066
1301
|
attributes: selectTelemetryAttributes({
|
1067
1302
|
telemetry,
|
1068
1303
|
attributes: {
|
1304
|
+
...assembleOperationName({
|
1305
|
+
operationName: "ai.generateObject",
|
1306
|
+
telemetry
|
1307
|
+
}),
|
1069
1308
|
...baseTelemetryAttributes,
|
1070
1309
|
// specific settings that only make sense on the outer level:
|
1071
1310
|
"ai.prompt": {
|
@@ -1110,6 +1349,10 @@ async function generateObject({
|
|
1110
1349
|
attributes: selectTelemetryAttributes({
|
1111
1350
|
telemetry,
|
1112
1351
|
attributes: {
|
1352
|
+
...assembleOperationName({
|
1353
|
+
operationName: "ai.generateObject.doGenerate",
|
1354
|
+
telemetry
|
1355
|
+
}),
|
1113
1356
|
...baseTelemetryAttributes,
|
1114
1357
|
"ai.prompt.format": {
|
1115
1358
|
input: () => inputFormat
|
@@ -1183,6 +1426,10 @@ async function generateObject({
|
|
1183
1426
|
attributes: selectTelemetryAttributes({
|
1184
1427
|
telemetry,
|
1185
1428
|
attributes: {
|
1429
|
+
...assembleOperationName({
|
1430
|
+
operationName: "ai.generateObject.doGenerate",
|
1431
|
+
telemetry
|
1432
|
+
}),
|
1186
1433
|
...baseTelemetryAttributes,
|
1187
1434
|
"ai.prompt.format": {
|
1188
1435
|
input: () => inputFormat
|
@@ -1201,7 +1448,7 @@ async function generateObject({
|
|
1201
1448
|
}),
|
1202
1449
|
tracer,
|
1203
1450
|
fn: async (span2) => {
|
1204
|
-
var
|
1451
|
+
var _a10, _b;
|
1205
1452
|
const result2 = await model.doGenerate({
|
1206
1453
|
mode: {
|
1207
1454
|
type: "object-tool",
|
@@ -1218,7 +1465,7 @@ async function generateObject({
|
|
1218
1465
|
abortSignal,
|
1219
1466
|
headers
|
1220
1467
|
});
|
1221
|
-
const objectText = (_b = (
|
1468
|
+
const objectText = (_b = (_a10 = result2.toolCalls) == null ? void 0 : _a10[0]) == null ? void 0 : _b.args;
|
1222
1469
|
if (objectText === void 0) {
|
1223
1470
|
throw new NoObjectGeneratedError();
|
1224
1471
|
}
|
@@ -1297,9 +1544,9 @@ var DefaultGenerateObjectResult = class {
|
|
1297
1544
|
this.logprobs = options.logprobs;
|
1298
1545
|
}
|
1299
1546
|
toJsonResponse(init) {
|
1300
|
-
var
|
1547
|
+
var _a9;
|
1301
1548
|
return new Response(JSON.stringify(this.object), {
|
1302
|
-
status: (
|
1549
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
1303
1550
|
headers: prepareResponseHeaders(init, {
|
1304
1551
|
contentType: "application/json; charset=utf-8"
|
1305
1552
|
})
|
@@ -1315,24 +1562,22 @@ import {
|
|
1315
1562
|
parsePartialJson
|
1316
1563
|
} from "@ai-sdk/ui-utils";
|
1317
1564
|
|
1318
|
-
//
|
1319
|
-
function
|
1320
|
-
|
1321
|
-
|
1322
|
-
)
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
};
|
1565
|
+
// util/create-resolvable-promise.ts
|
1566
|
+
function createResolvablePromise() {
|
1567
|
+
let resolve;
|
1568
|
+
let reject;
|
1569
|
+
const promise = new Promise((res, rej) => {
|
1570
|
+
resolve = res;
|
1571
|
+
reject = rej;
|
1572
|
+
});
|
1573
|
+
return {
|
1574
|
+
promise,
|
1575
|
+
resolve,
|
1576
|
+
reject
|
1331
1577
|
};
|
1332
|
-
return transformedStream;
|
1333
1578
|
}
|
1334
1579
|
|
1335
|
-
//
|
1580
|
+
// util/delayed-promise.ts
|
1336
1581
|
var DelayedPromise = class {
|
1337
1582
|
constructor() {
|
1338
1583
|
this.status = { type: "pending" };
|
@@ -1355,21 +1600,38 @@ var DelayedPromise = class {
|
|
1355
1600
|
return this.promise;
|
1356
1601
|
}
|
1357
1602
|
resolve(value) {
|
1358
|
-
var
|
1603
|
+
var _a9;
|
1359
1604
|
this.status = { type: "resolved", value };
|
1360
1605
|
if (this.promise) {
|
1361
|
-
(
|
1606
|
+
(_a9 = this._resolve) == null ? void 0 : _a9.call(this, value);
|
1362
1607
|
}
|
1363
1608
|
}
|
1364
1609
|
reject(error) {
|
1365
|
-
var
|
1610
|
+
var _a9;
|
1366
1611
|
this.status = { type: "rejected", error };
|
1367
1612
|
if (this.promise) {
|
1368
|
-
(
|
1613
|
+
(_a9 = this._reject) == null ? void 0 : _a9.call(this, error);
|
1369
1614
|
}
|
1370
1615
|
}
|
1371
1616
|
};
|
1372
1617
|
|
1618
|
+
// core/util/async-iterable-stream.ts
|
1619
|
+
function createAsyncIterableStream(source, transformer) {
|
1620
|
+
const transformedStream = source.pipeThrough(
|
1621
|
+
new TransformStream(transformer)
|
1622
|
+
);
|
1623
|
+
transformedStream[Symbol.asyncIterator] = () => {
|
1624
|
+
const reader = transformedStream.getReader();
|
1625
|
+
return {
|
1626
|
+
async next() {
|
1627
|
+
const { done, value } = await reader.read();
|
1628
|
+
return done ? { done: true, value: void 0 } : { done: false, value };
|
1629
|
+
}
|
1630
|
+
};
|
1631
|
+
};
|
1632
|
+
return transformedStream;
|
1633
|
+
}
|
1634
|
+
|
1373
1635
|
// core/generate-object/stream-object.ts
|
1374
1636
|
async function streamObject({
|
1375
1637
|
model,
|
@@ -1385,15 +1647,14 @@ async function streamObject({
|
|
1385
1647
|
onFinish,
|
1386
1648
|
...settings
|
1387
1649
|
}) {
|
1388
|
-
var
|
1650
|
+
var _a9;
|
1389
1651
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1390
|
-
operationName: "ai.streamObject",
|
1391
1652
|
model,
|
1392
1653
|
telemetry,
|
1393
1654
|
headers,
|
1394
1655
|
settings: { ...settings, maxRetries }
|
1395
1656
|
});
|
1396
|
-
const tracer = getTracer({ isEnabled: (
|
1657
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1397
1658
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1398
1659
|
const schema = asSchema(inputSchema);
|
1399
1660
|
return recordSpan({
|
@@ -1401,6 +1662,10 @@ async function streamObject({
|
|
1401
1662
|
attributes: selectTelemetryAttributes({
|
1402
1663
|
telemetry,
|
1403
1664
|
attributes: {
|
1665
|
+
...assembleOperationName({
|
1666
|
+
operationName: "ai.streamObject",
|
1667
|
+
telemetry
|
1668
|
+
}),
|
1404
1669
|
...baseTelemetryAttributes,
|
1405
1670
|
// specific settings that only make sense on the outer level:
|
1406
1671
|
"ai.prompt": {
|
@@ -1513,6 +1778,10 @@ async function streamObject({
|
|
1513
1778
|
attributes: selectTelemetryAttributes({
|
1514
1779
|
telemetry,
|
1515
1780
|
attributes: {
|
1781
|
+
...assembleOperationName({
|
1782
|
+
operationName: "ai.streamObject.doStream",
|
1783
|
+
telemetry
|
1784
|
+
}),
|
1516
1785
|
...baseTelemetryAttributes,
|
1517
1786
|
"ai.prompt.format": {
|
1518
1787
|
input: () => callOptions.inputFormat
|
@@ -1564,10 +1833,8 @@ var DefaultStreamObjectResult = class {
|
|
1564
1833
|
this.warnings = warnings;
|
1565
1834
|
this.rawResponse = rawResponse;
|
1566
1835
|
this.objectPromise = new DelayedPromise();
|
1567
|
-
|
1568
|
-
this.usage =
|
1569
|
-
resolveUsage = resolve;
|
1570
|
-
});
|
1836
|
+
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
1837
|
+
this.usage = usagePromise;
|
1571
1838
|
let usage;
|
1572
1839
|
let finishReason;
|
1573
1840
|
let object;
|
@@ -1742,8 +2009,8 @@ var DefaultStreamObjectResult = class {
|
|
1742
2009
|
});
|
1743
2010
|
}
|
1744
2011
|
pipeTextStreamToResponse(response, init) {
|
1745
|
-
var
|
1746
|
-
response.writeHead((
|
2012
|
+
var _a9;
|
2013
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
1747
2014
|
"Content-Type": "text/plain; charset=utf-8",
|
1748
2015
|
...init == null ? void 0 : init.headers
|
1749
2016
|
});
|
@@ -1765,9 +2032,9 @@ var DefaultStreamObjectResult = class {
|
|
1765
2032
|
read();
|
1766
2033
|
}
|
1767
2034
|
toTextStreamResponse(init) {
|
1768
|
-
var
|
2035
|
+
var _a9;
|
1769
2036
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
1770
|
-
status: (
|
2037
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
1771
2038
|
headers: prepareResponseHeaders(init, {
|
1772
2039
|
contentType: "text/plain; charset=utf-8"
|
1773
2040
|
})
|
@@ -1793,9 +2060,9 @@ function prepareToolsAndToolChoice({
|
|
1793
2060
|
};
|
1794
2061
|
}
|
1795
2062
|
return {
|
1796
|
-
tools: Object.entries(tools).map(([
|
2063
|
+
tools: Object.entries(tools).map(([name9, tool2]) => ({
|
1797
2064
|
type: "function",
|
1798
|
-
name,
|
2065
|
+
name: name9,
|
1799
2066
|
description: tool2.description,
|
1800
2067
|
parameters: asSchema(tool2.parameters).jsonSchema
|
1801
2068
|
})),
|
@@ -1804,11 +2071,95 @@ function prepareToolsAndToolChoice({
|
|
1804
2071
|
}
|
1805
2072
|
|
1806
2073
|
// core/generate-text/tool-call.ts
|
1807
|
-
import {
|
1808
|
-
InvalidToolArgumentsError,
|
1809
|
-
NoSuchToolError
|
1810
|
-
} from "@ai-sdk/provider";
|
1811
2074
|
import { safeParseJSON as safeParseJSON2 } from "@ai-sdk/provider-utils";
|
2075
|
+
|
2076
|
+
// errors/invalid-tool-arguments-error.ts
|
2077
|
+
import { AISDKError as AISDKError7, getErrorMessage as getErrorMessage3 } from "@ai-sdk/provider";
|
2078
|
+
var name7 = "AI_InvalidToolArgumentsError";
|
2079
|
+
var marker7 = `vercel.ai.error.${name7}`;
|
2080
|
+
var symbol7 = Symbol.for(marker7);
|
2081
|
+
var _a7;
|
2082
|
+
var InvalidToolArgumentsError = class extends AISDKError7 {
|
2083
|
+
constructor({
|
2084
|
+
toolArgs,
|
2085
|
+
toolName,
|
2086
|
+
cause,
|
2087
|
+
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage3(
|
2088
|
+
cause
|
2089
|
+
)}`
|
2090
|
+
}) {
|
2091
|
+
super({ name: name7, message, cause });
|
2092
|
+
this[_a7] = true;
|
2093
|
+
this.toolArgs = toolArgs;
|
2094
|
+
this.toolName = toolName;
|
2095
|
+
}
|
2096
|
+
static isInstance(error) {
|
2097
|
+
return AISDKError7.hasMarker(error, marker7);
|
2098
|
+
}
|
2099
|
+
/**
|
2100
|
+
* @deprecated use `isInstance` instead
|
2101
|
+
*/
|
2102
|
+
static isInvalidToolArgumentsError(error) {
|
2103
|
+
return error instanceof Error && error.name === name7 && typeof error.toolName === "string" && typeof error.toolArgs === "string";
|
2104
|
+
}
|
2105
|
+
/**
|
2106
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
2107
|
+
*/
|
2108
|
+
toJSON() {
|
2109
|
+
return {
|
2110
|
+
name: this.name,
|
2111
|
+
message: this.message,
|
2112
|
+
cause: this.cause,
|
2113
|
+
stack: this.stack,
|
2114
|
+
toolName: this.toolName,
|
2115
|
+
toolArgs: this.toolArgs
|
2116
|
+
};
|
2117
|
+
}
|
2118
|
+
};
|
2119
|
+
_a7 = symbol7;
|
2120
|
+
|
2121
|
+
// errors/no-such-tool-error.ts
|
2122
|
+
import { AISDKError as AISDKError8 } from "@ai-sdk/provider";
|
2123
|
+
var name8 = "AI_NoSuchToolError";
|
2124
|
+
var marker8 = `vercel.ai.error.${name8}`;
|
2125
|
+
var symbol8 = Symbol.for(marker8);
|
2126
|
+
var _a8;
|
2127
|
+
var NoSuchToolError = class extends AISDKError8 {
|
2128
|
+
constructor({
|
2129
|
+
toolName,
|
2130
|
+
availableTools = void 0,
|
2131
|
+
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
2132
|
+
}) {
|
2133
|
+
super({ name: name8, message });
|
2134
|
+
this[_a8] = true;
|
2135
|
+
this.toolName = toolName;
|
2136
|
+
this.availableTools = availableTools;
|
2137
|
+
}
|
2138
|
+
static isInstance(error) {
|
2139
|
+
return AISDKError8.hasMarker(error, marker8);
|
2140
|
+
}
|
2141
|
+
/**
|
2142
|
+
* @deprecated use `isInstance` instead
|
2143
|
+
*/
|
2144
|
+
static isNoSuchToolError(error) {
|
2145
|
+
return error instanceof Error && error.name === name8 && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
2146
|
+
}
|
2147
|
+
/**
|
2148
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
2149
|
+
*/
|
2150
|
+
toJSON() {
|
2151
|
+
return {
|
2152
|
+
name: this.name,
|
2153
|
+
message: this.message,
|
2154
|
+
stack: this.stack,
|
2155
|
+
toolName: this.toolName,
|
2156
|
+
availableTools: this.availableTools
|
2157
|
+
};
|
2158
|
+
}
|
2159
|
+
};
|
2160
|
+
_a8 = symbol8;
|
2161
|
+
|
2162
|
+
// core/generate-text/tool-call.ts
|
1812
2163
|
function parseToolCall({
|
1813
2164
|
toolCall,
|
1814
2165
|
tools
|
@@ -1859,20 +2210,23 @@ async function generateText({
|
|
1859
2210
|
experimental_telemetry: telemetry,
|
1860
2211
|
...settings
|
1861
2212
|
}) {
|
1862
|
-
var
|
2213
|
+
var _a9;
|
1863
2214
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1864
|
-
operationName: "ai.generateText",
|
1865
2215
|
model,
|
1866
2216
|
telemetry,
|
1867
2217
|
headers,
|
1868
2218
|
settings: { ...settings, maxRetries }
|
1869
2219
|
});
|
1870
|
-
const tracer = getTracer({ isEnabled: (
|
2220
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1871
2221
|
return recordSpan({
|
1872
2222
|
name: "ai.generateText",
|
1873
2223
|
attributes: selectTelemetryAttributes({
|
1874
2224
|
telemetry,
|
1875
2225
|
attributes: {
|
2226
|
+
...assembleOperationName({
|
2227
|
+
operationName: "ai.generateText",
|
2228
|
+
telemetry
|
2229
|
+
}),
|
1876
2230
|
...baseTelemetryAttributes,
|
1877
2231
|
// specific settings that only make sense on the outer level:
|
1878
2232
|
"ai.prompt": {
|
@@ -1883,7 +2237,7 @@ async function generateText({
|
|
1883
2237
|
}),
|
1884
2238
|
tracer,
|
1885
2239
|
fn: async (span) => {
|
1886
|
-
var
|
2240
|
+
var _a10, _b, _c, _d;
|
1887
2241
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1888
2242
|
const validatedPrompt = getValidatedPrompt({
|
1889
2243
|
system,
|
@@ -1918,6 +2272,10 @@ async function generateText({
|
|
1918
2272
|
attributes: selectTelemetryAttributes({
|
1919
2273
|
telemetry,
|
1920
2274
|
attributes: {
|
2275
|
+
...assembleOperationName({
|
2276
|
+
operationName: "ai.generateText.doGenerate",
|
2277
|
+
telemetry
|
2278
|
+
}),
|
1921
2279
|
...baseTelemetryAttributes,
|
1922
2280
|
"ai.prompt.format": { input: () => currentInputFormat },
|
1923
2281
|
"ai.prompt.messages": {
|
@@ -1965,7 +2323,7 @@ async function generateText({
|
|
1965
2323
|
}
|
1966
2324
|
})
|
1967
2325
|
);
|
1968
|
-
currentToolCalls = ((
|
2326
|
+
currentToolCalls = ((_a10 = currentModelResponse.toolCalls) != null ? _a10 : []).map(
|
1969
2327
|
(modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
|
1970
2328
|
);
|
1971
2329
|
currentToolResults = tools == null ? [] : await executeTools({
|
@@ -2057,6 +2415,10 @@ async function executeTools({
|
|
2057
2415
|
attributes: selectTelemetryAttributes({
|
2058
2416
|
telemetry,
|
2059
2417
|
attributes: {
|
2418
|
+
...assembleOperationName({
|
2419
|
+
operationName: "ai.toolCall",
|
2420
|
+
telemetry
|
2421
|
+
}),
|
2060
2422
|
"ai.toolCall.name": toolCall.toolName,
|
2061
2423
|
"ai.toolCall.id": toolCall.toolCallId,
|
2062
2424
|
"ai.toolCall.args": {
|
@@ -2223,7 +2585,6 @@ function mergeStreams(stream1, stream2) {
|
|
2223
2585
|
}
|
2224
2586
|
|
2225
2587
|
// core/generate-text/run-tools-transformation.ts
|
2226
|
-
import { NoSuchToolError as NoSuchToolError2 } from "@ai-sdk/provider";
|
2227
2588
|
import { generateId } from "@ai-sdk/ui-utils";
|
2228
2589
|
function runToolsTransformation({
|
2229
2590
|
tools,
|
@@ -2274,7 +2635,7 @@ function runToolsTransformation({
|
|
2274
2635
|
if (tools == null) {
|
2275
2636
|
toolResultsStreamController.enqueue({
|
2276
2637
|
type: "error",
|
2277
|
-
error: new
|
2638
|
+
error: new NoSuchToolError({ toolName: chunk.toolName })
|
2278
2639
|
});
|
2279
2640
|
break;
|
2280
2641
|
}
|
@@ -2282,7 +2643,7 @@ function runToolsTransformation({
|
|
2282
2643
|
if (tool2 == null) {
|
2283
2644
|
toolResultsStreamController.enqueue({
|
2284
2645
|
type: "error",
|
2285
|
-
error: new
|
2646
|
+
error: new NoSuchToolError({
|
2286
2647
|
toolName: chunk.toolName,
|
2287
2648
|
availableTools: Object.keys(tools)
|
2288
2649
|
})
|
@@ -2303,6 +2664,10 @@ function runToolsTransformation({
|
|
2303
2664
|
attributes: selectTelemetryAttributes({
|
2304
2665
|
telemetry,
|
2305
2666
|
attributes: {
|
2667
|
+
...assembleOperationName({
|
2668
|
+
operationName: "ai.toolCall",
|
2669
|
+
telemetry
|
2670
|
+
}),
|
2306
2671
|
"ai.toolCall.name": toolCall.toolName,
|
2307
2672
|
"ai.toolCall.id": toolCall.toolCallId,
|
2308
2673
|
"ai.toolCall.args": {
|
@@ -2422,20 +2787,20 @@ async function streamText({
|
|
2422
2787
|
onFinish,
|
2423
2788
|
...settings
|
2424
2789
|
}) {
|
2425
|
-
var
|
2790
|
+
var _a9;
|
2426
2791
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
2427
|
-
operationName: "ai.streamText",
|
2428
2792
|
model,
|
2429
2793
|
telemetry,
|
2430
2794
|
headers,
|
2431
2795
|
settings: { ...settings, maxRetries }
|
2432
2796
|
});
|
2433
|
-
const tracer = getTracer({ isEnabled: (
|
2797
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
2434
2798
|
return recordSpan({
|
2435
2799
|
name: "ai.streamText",
|
2436
2800
|
attributes: selectTelemetryAttributes({
|
2437
2801
|
telemetry,
|
2438
2802
|
attributes: {
|
2803
|
+
...assembleOperationName({ operationName: "ai.streamText", telemetry }),
|
2439
2804
|
...baseTelemetryAttributes,
|
2440
2805
|
// specific settings that only make sense on the outer level:
|
2441
2806
|
"ai.prompt": {
|
@@ -2461,6 +2826,10 @@ async function streamText({
|
|
2461
2826
|
attributes: selectTelemetryAttributes({
|
2462
2827
|
telemetry,
|
2463
2828
|
attributes: {
|
2829
|
+
...assembleOperationName({
|
2830
|
+
operationName: "ai.streamText.doStream",
|
2831
|
+
telemetry
|
2832
|
+
}),
|
2464
2833
|
...baseTelemetryAttributes,
|
2465
2834
|
"ai.prompt.format": {
|
2466
2835
|
input: () => validatedPrompt.type
|
@@ -2527,26 +2896,16 @@ var DefaultStreamTextResult = class {
|
|
2527
2896
|
this.warnings = warnings;
|
2528
2897
|
this.rawResponse = rawResponse;
|
2529
2898
|
this.onFinish = onFinish;
|
2530
|
-
|
2531
|
-
this.usage =
|
2532
|
-
|
2533
|
-
|
2534
|
-
|
2535
|
-
this.
|
2536
|
-
|
2537
|
-
|
2538
|
-
|
2539
|
-
this.
|
2540
|
-
resolveText = resolve;
|
2541
|
-
});
|
2542
|
-
let resolveToolCalls;
|
2543
|
-
this.toolCalls = new Promise((resolve) => {
|
2544
|
-
resolveToolCalls = resolve;
|
2545
|
-
});
|
2546
|
-
let resolveToolResults;
|
2547
|
-
this.toolResults = new Promise((resolve) => {
|
2548
|
-
resolveToolResults = resolve;
|
2549
|
-
});
|
2899
|
+
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
2900
|
+
this.usage = usagePromise;
|
2901
|
+
const { resolve: resolveFinishReason, promise: finishReasonPromise } = createResolvablePromise();
|
2902
|
+
this.finishReason = finishReasonPromise;
|
2903
|
+
const { resolve: resolveText, promise: textPromise } = createResolvablePromise();
|
2904
|
+
this.text = textPromise;
|
2905
|
+
const { resolve: resolveToolCalls, promise: toolCallsPromise } = createResolvablePromise();
|
2906
|
+
this.toolCalls = toolCallsPromise;
|
2907
|
+
const { resolve: resolveToolResults, promise: toolResultsPromise } = createResolvablePromise();
|
2908
|
+
this.toolResults = toolResultsPromise;
|
2550
2909
|
let finishReason;
|
2551
2910
|
let usage;
|
2552
2911
|
let text = "";
|
@@ -2593,7 +2952,7 @@ var DefaultStreamTextResult = class {
|
|
2593
2952
|
},
|
2594
2953
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
2595
2954
|
async flush(controller) {
|
2596
|
-
var
|
2955
|
+
var _a9;
|
2597
2956
|
try {
|
2598
2957
|
const finalUsage = usage != null ? usage : {
|
2599
2958
|
promptTokens: NaN,
|
@@ -2632,7 +2991,7 @@ var DefaultStreamTextResult = class {
|
|
2632
2991
|
})
|
2633
2992
|
);
|
2634
2993
|
resolveToolResults(toolResults);
|
2635
|
-
await ((
|
2994
|
+
await ((_a9 = self.onFinish) == null ? void 0 : _a9.call(self, {
|
2636
2995
|
finishReason: finalFinishReason,
|
2637
2996
|
usage: finalUsage,
|
2638
2997
|
text,
|
@@ -2787,8 +3146,8 @@ var DefaultStreamTextResult = class {
|
|
2787
3146
|
return this.pipeDataStreamToResponse(response, init);
|
2788
3147
|
}
|
2789
3148
|
pipeDataStreamToResponse(response, init) {
|
2790
|
-
var
|
2791
|
-
response.writeHead((
|
3149
|
+
var _a9;
|
3150
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
2792
3151
|
"Content-Type": "text/plain; charset=utf-8",
|
2793
3152
|
...init == null ? void 0 : init.headers
|
2794
3153
|
});
|
@@ -2810,8 +3169,8 @@ var DefaultStreamTextResult = class {
|
|
2810
3169
|
read();
|
2811
3170
|
}
|
2812
3171
|
pipeTextStreamToResponse(response, init) {
|
2813
|
-
var
|
2814
|
-
response.writeHead((
|
3172
|
+
var _a9;
|
3173
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
2815
3174
|
"Content-Type": "text/plain; charset=utf-8",
|
2816
3175
|
...init == null ? void 0 : init.headers
|
2817
3176
|
});
|
@@ -2836,7 +3195,7 @@ var DefaultStreamTextResult = class {
|
|
2836
3195
|
return this.toDataStreamResponse(options);
|
2837
3196
|
}
|
2838
3197
|
toDataStreamResponse(options) {
|
2839
|
-
var
|
3198
|
+
var _a9;
|
2840
3199
|
const init = options == null ? void 0 : "init" in options ? options.init : {
|
2841
3200
|
headers: "headers" in options ? options.headers : void 0,
|
2842
3201
|
status: "status" in options ? options.status : void 0,
|
@@ -2845,7 +3204,7 @@ var DefaultStreamTextResult = class {
|
|
2845
3204
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
2846
3205
|
const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
|
2847
3206
|
return new Response(stream, {
|
2848
|
-
status: (
|
3207
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
2849
3208
|
statusText: init == null ? void 0 : init.statusText,
|
2850
3209
|
headers: prepareResponseHeaders(init, {
|
2851
3210
|
contentType: "text/plain; charset=utf-8",
|
@@ -2854,9 +3213,9 @@ var DefaultStreamTextResult = class {
|
|
2854
3213
|
});
|
2855
3214
|
}
|
2856
3215
|
toTextStreamResponse(init) {
|
2857
|
-
var
|
3216
|
+
var _a9;
|
2858
3217
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
2859
|
-
status: (
|
3218
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
2860
3219
|
headers: prepareResponseHeaders(init, {
|
2861
3220
|
contentType: "text/plain; charset=utf-8"
|
2862
3221
|
})
|
@@ -2867,7 +3226,7 @@ var experimental_streamText = streamText;
|
|
2867
3226
|
|
2868
3227
|
// core/prompt/attachments-to-parts.ts
|
2869
3228
|
function attachmentsToParts(attachments) {
|
2870
|
-
var
|
3229
|
+
var _a9, _b, _c;
|
2871
3230
|
const parts = [];
|
2872
3231
|
for (const attachment of attachments) {
|
2873
3232
|
let url;
|
@@ -2879,7 +3238,7 @@ function attachmentsToParts(attachments) {
|
|
2879
3238
|
switch (url.protocol) {
|
2880
3239
|
case "http:":
|
2881
3240
|
case "https:": {
|
2882
|
-
if ((
|
3241
|
+
if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
|
2883
3242
|
parts.push({ type: "image", image: url });
|
2884
3243
|
}
|
2885
3244
|
break;
|
@@ -3096,18 +3455,18 @@ var DefaultProviderRegistry = class {
|
|
3096
3455
|
return [id.slice(0, index), id.slice(index + 1)];
|
3097
3456
|
}
|
3098
3457
|
languageModel(id) {
|
3099
|
-
var
|
3458
|
+
var _a9, _b;
|
3100
3459
|
const [providerId, modelId] = this.splitId(id);
|
3101
|
-
const model = (_b = (
|
3460
|
+
const model = (_b = (_a9 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a9, modelId);
|
3102
3461
|
if (model == null) {
|
3103
3462
|
throw new NoSuchModelError({ modelId: id, modelType: "language model" });
|
3104
3463
|
}
|
3105
3464
|
return model;
|
3106
3465
|
}
|
3107
3466
|
textEmbeddingModel(id) {
|
3108
|
-
var
|
3467
|
+
var _a9, _b;
|
3109
3468
|
const [providerId, modelId] = this.splitId(id);
|
3110
|
-
const model = (_b = (
|
3469
|
+
const model = (_b = (_a9 = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a9, modelId);
|
3111
3470
|
if (model == null) {
|
3112
3471
|
throw new NoSuchModelError({
|
3113
3472
|
modelId: id,
|
@@ -3123,26 +3482,6 @@ function tool(tool2) {
|
|
3123
3482
|
return tool2;
|
3124
3483
|
}
|
3125
3484
|
|
3126
|
-
// core/types/errors.ts
|
3127
|
-
import {
|
3128
|
-
APICallError as APICallError2,
|
3129
|
-
EmptyResponseBodyError,
|
3130
|
-
InvalidArgumentError as InvalidArgumentError2,
|
3131
|
-
InvalidDataContentError as InvalidDataContentError2,
|
3132
|
-
InvalidPromptError as InvalidPromptError2,
|
3133
|
-
InvalidResponseDataError,
|
3134
|
-
InvalidToolArgumentsError as InvalidToolArgumentsError2,
|
3135
|
-
JSONParseError,
|
3136
|
-
LoadAPIKeyError,
|
3137
|
-
NoObjectGeneratedError as NoObjectGeneratedError2,
|
3138
|
-
NoSuchToolError as NoSuchToolError3,
|
3139
|
-
RetryError as RetryError2,
|
3140
|
-
ToolCallParseError,
|
3141
|
-
TypeValidationError,
|
3142
|
-
UnsupportedFunctionalityError,
|
3143
|
-
UnsupportedJSONSchemaError
|
3144
|
-
} from "@ai-sdk/provider";
|
3145
|
-
|
3146
3485
|
// core/util/cosine-similarity.ts
|
3147
3486
|
function cosineSimilarity(vector1, vector2) {
|
3148
3487
|
if (vector1.length !== vector2.length) {
|
@@ -3162,6 +3501,19 @@ function magnitude(vector) {
|
|
3162
3501
|
return Math.sqrt(dotProduct(vector, vector));
|
3163
3502
|
}
|
3164
3503
|
|
3504
|
+
// errors/index.ts
|
3505
|
+
import {
|
3506
|
+
AISDKError as AISDKError9,
|
3507
|
+
APICallError as APICallError2,
|
3508
|
+
EmptyResponseBodyError,
|
3509
|
+
InvalidPromptError as InvalidPromptError2,
|
3510
|
+
InvalidResponseDataError,
|
3511
|
+
JSONParseError,
|
3512
|
+
LoadAPIKeyError,
|
3513
|
+
TypeValidationError,
|
3514
|
+
UnsupportedFunctionalityError
|
3515
|
+
} from "@ai-sdk/provider";
|
3516
|
+
|
3165
3517
|
// streams/ai-stream.ts
|
3166
3518
|
import {
|
3167
3519
|
createParser
|
@@ -3280,8 +3632,8 @@ function readableFromAsyncIterable(iterable) {
|
|
3280
3632
|
controller.enqueue(value);
|
3281
3633
|
},
|
3282
3634
|
async cancel(reason) {
|
3283
|
-
var
|
3284
|
-
await ((
|
3635
|
+
var _a9;
|
3636
|
+
await ((_a9 = it.return) == null ? void 0 : _a9.call(it, reason));
|
3285
3637
|
}
|
3286
3638
|
});
|
3287
3639
|
}
|
@@ -3415,7 +3767,7 @@ import {
|
|
3415
3767
|
function AssistantResponse({ threadId, messageId }, process2) {
|
3416
3768
|
const stream = new ReadableStream({
|
3417
3769
|
async start(controller) {
|
3418
|
-
var
|
3770
|
+
var _a9;
|
3419
3771
|
const textEncoder = new TextEncoder();
|
3420
3772
|
const sendMessage = (message) => {
|
3421
3773
|
controller.enqueue(
|
@@ -3433,7 +3785,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3433
3785
|
);
|
3434
3786
|
};
|
3435
3787
|
const forwardStream = async (stream2) => {
|
3436
|
-
var
|
3788
|
+
var _a10, _b;
|
3437
3789
|
let result = void 0;
|
3438
3790
|
for await (const value of stream2) {
|
3439
3791
|
switch (value.event) {
|
@@ -3450,7 +3802,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3450
3802
|
break;
|
3451
3803
|
}
|
3452
3804
|
case "thread.message.delta": {
|
3453
|
-
const content = (
|
3805
|
+
const content = (_a10 = value.data.delta.content) == null ? void 0 : _a10[0];
|
3454
3806
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
3455
3807
|
controller.enqueue(
|
3456
3808
|
textEncoder.encode(
|
@@ -3486,7 +3838,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3486
3838
|
forwardStream
|
3487
3839
|
});
|
3488
3840
|
} catch (error) {
|
3489
|
-
sendError((
|
3841
|
+
sendError((_a9 = error.message) != null ? _a9 : `${error}`);
|
3490
3842
|
} finally {
|
3491
3843
|
controller.close();
|
3492
3844
|
}
|
@@ -3507,9 +3859,9 @@ var experimental_AssistantResponse = AssistantResponse;
|
|
3507
3859
|
|
3508
3860
|
// streams/aws-bedrock-stream.ts
|
3509
3861
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
3510
|
-
var
|
3862
|
+
var _a9, _b;
|
3511
3863
|
const decoder = new TextDecoder();
|
3512
|
-
for await (const chunk of (
|
3864
|
+
for await (const chunk of (_a9 = response.body) != null ? _a9 : []) {
|
3513
3865
|
const bytes = (_b = chunk.chunk) == null ? void 0 : _b.bytes;
|
3514
3866
|
if (bytes != null) {
|
3515
3867
|
const chunkText = decoder.decode(bytes);
|
@@ -3523,8 +3875,8 @@ async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
|
3523
3875
|
}
|
3524
3876
|
function AWSBedrockAnthropicMessagesStream(response, callbacks) {
|
3525
3877
|
return AWSBedrockStream(response, callbacks, (chunk) => {
|
3526
|
-
var
|
3527
|
-
return (
|
3878
|
+
var _a9;
|
3879
|
+
return (_a9 = chunk.delta) == null ? void 0 : _a9.text;
|
3528
3880
|
});
|
3529
3881
|
}
|
3530
3882
|
function AWSBedrockAnthropicStream(response, callbacks) {
|
@@ -3571,8 +3923,8 @@ async function readAndProcessLines(reader, controller) {
|
|
3571
3923
|
controller.close();
|
3572
3924
|
}
|
3573
3925
|
function createParser2(res) {
|
3574
|
-
var
|
3575
|
-
const reader = (
|
3926
|
+
var _a9;
|
3927
|
+
const reader = (_a9 = res.body) == null ? void 0 : _a9.getReader();
|
3576
3928
|
return new ReadableStream({
|
3577
3929
|
async start(controller) {
|
3578
3930
|
if (!reader) {
|
@@ -3602,9 +3954,9 @@ function CohereStream(reader, callbacks) {
|
|
3602
3954
|
|
3603
3955
|
// streams/google-generative-ai-stream.ts
|
3604
3956
|
async function* streamable3(response) {
|
3605
|
-
var
|
3957
|
+
var _a9, _b, _c;
|
3606
3958
|
for await (const chunk of response.stream) {
|
3607
|
-
const parts = (_c = (_b = (
|
3959
|
+
const parts = (_c = (_b = (_a9 = chunk.candidates) == null ? void 0 : _a9[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
|
3608
3960
|
if (parts === void 0) {
|
3609
3961
|
continue;
|
3610
3962
|
}
|
@@ -3623,13 +3975,13 @@ function createParser3(res) {
|
|
3623
3975
|
const trimStartOfStream = trimStartOfStreamHelper();
|
3624
3976
|
return new ReadableStream({
|
3625
3977
|
async pull(controller) {
|
3626
|
-
var
|
3978
|
+
var _a9, _b;
|
3627
3979
|
const { value, done } = await res.next();
|
3628
3980
|
if (done) {
|
3629
3981
|
controller.close();
|
3630
3982
|
return;
|
3631
3983
|
}
|
3632
|
-
const text = trimStartOfStream((_b = (
|
3984
|
+
const text = trimStartOfStream((_b = (_a9 = value.token) == null ? void 0 : _a9.text) != null ? _b : "");
|
3633
3985
|
if (!text)
|
3634
3986
|
return;
|
3635
3987
|
if (value.generated_text != null && value.generated_text.length > 0) {
|
@@ -3654,11 +4006,11 @@ function InkeepStream(res, callbacks) {
|
|
3654
4006
|
let chat_session_id = "";
|
3655
4007
|
let records_cited;
|
3656
4008
|
const inkeepEventParser = (data, options) => {
|
3657
|
-
var
|
4009
|
+
var _a9, _b;
|
3658
4010
|
const { event } = options;
|
3659
4011
|
if (event === "records_cited") {
|
3660
4012
|
records_cited = JSON.parse(data);
|
3661
|
-
(
|
4013
|
+
(_a9 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a9.call(callbacks, records_cited);
|
3662
4014
|
}
|
3663
4015
|
if (event === "message_chunk") {
|
3664
4016
|
const inkeepMessageChunk = JSON.parse(data);
|
@@ -3671,12 +4023,12 @@ function InkeepStream(res, callbacks) {
|
|
3671
4023
|
passThroughCallbacks = {
|
3672
4024
|
...passThroughCallbacks,
|
3673
4025
|
onFinal: (completion) => {
|
3674
|
-
var
|
4026
|
+
var _a9;
|
3675
4027
|
const inkeepOnFinalMetadata = {
|
3676
4028
|
chat_session_id,
|
3677
4029
|
records_cited
|
3678
4030
|
};
|
3679
|
-
(
|
4031
|
+
(_a9 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a9.call(callbacks, completion, inkeepOnFinalMetadata);
|
3680
4032
|
}
|
3681
4033
|
};
|
3682
4034
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
@@ -3698,7 +4050,7 @@ function toDataStream(stream, callbacks) {
|
|
3698
4050
|
return stream.pipeThrough(
|
3699
4051
|
new TransformStream({
|
3700
4052
|
transform: async (value, controller) => {
|
3701
|
-
var
|
4053
|
+
var _a9;
|
3702
4054
|
if (typeof value === "string") {
|
3703
4055
|
controller.enqueue(value);
|
3704
4056
|
return;
|
@@ -3706,7 +4058,7 @@ function toDataStream(stream, callbacks) {
|
|
3706
4058
|
if ("event" in value) {
|
3707
4059
|
if (value.event === "on_chat_model_stream") {
|
3708
4060
|
forwardAIMessageChunk(
|
3709
|
-
(
|
4061
|
+
(_a9 = value.data) == null ? void 0 : _a9.chunk,
|
3710
4062
|
controller
|
3711
4063
|
);
|
3712
4064
|
}
|
@@ -3718,13 +4070,13 @@ function toDataStream(stream, callbacks) {
|
|
3718
4070
|
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
3719
4071
|
}
|
3720
4072
|
function toDataStreamResponse(stream, options) {
|
3721
|
-
var
|
4073
|
+
var _a9;
|
3722
4074
|
const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
|
3723
4075
|
const data = options == null ? void 0 : options.data;
|
3724
4076
|
const init = options == null ? void 0 : options.init;
|
3725
4077
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
3726
4078
|
return new Response(responseStream, {
|
3727
|
-
status: (
|
4079
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
3728
4080
|
statusText: init == null ? void 0 : init.statusText,
|
3729
4081
|
headers: prepareResponseHeaders(init, {
|
3730
4082
|
contentType: "text/plain; charset=utf-8",
|
@@ -3806,9 +4158,9 @@ function LangChainStream(callbacks) {
|
|
3806
4158
|
|
3807
4159
|
// streams/mistral-stream.ts
|
3808
4160
|
async function* streamable4(stream) {
|
3809
|
-
var
|
4161
|
+
var _a9, _b;
|
3810
4162
|
for await (const chunk of stream) {
|
3811
|
-
const content = (_b = (
|
4163
|
+
const content = (_b = (_a9 = chunk.choices[0]) == null ? void 0 : _a9.delta) == null ? void 0 : _b.content;
|
3812
4164
|
if (content === void 0 || content === "") {
|
3813
4165
|
continue;
|
3814
4166
|
}
|
@@ -3841,10 +4193,10 @@ async function* streamable5(stream) {
|
|
3841
4193
|
model: chunk.model,
|
3842
4194
|
// not exposed by Azure API
|
3843
4195
|
choices: chunk.choices.map((choice) => {
|
3844
|
-
var
|
4196
|
+
var _a9, _b, _c, _d, _e, _f, _g;
|
3845
4197
|
return {
|
3846
4198
|
delta: {
|
3847
|
-
content: (
|
4199
|
+
content: (_a9 = choice.delta) == null ? void 0 : _a9.content,
|
3848
4200
|
function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
|
3849
4201
|
role: (_c = choice.delta) == null ? void 0 : _c.role,
|
3850
4202
|
tool_calls: ((_e = (_d = choice.delta) == null ? void 0 : _d.toolCalls) == null ? void 0 : _e.length) ? (_g = (_f = choice.delta) == null ? void 0 : _f.toolCalls) == null ? void 0 : _g.map((toolCall, index) => ({
|
@@ -3869,9 +4221,9 @@ function chunkToText() {
|
|
3869
4221
|
const trimStartOfStream = trimStartOfStreamHelper();
|
3870
4222
|
let isFunctionStreamingIn;
|
3871
4223
|
return (json) => {
|
3872
|
-
var
|
4224
|
+
var _a9, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
3873
4225
|
if (isChatCompletionChunk(json)) {
|
3874
|
-
const delta = (
|
4226
|
+
const delta = (_a9 = json.choices[0]) == null ? void 0 : _a9.delta;
|
3875
4227
|
if ((_b = delta.function_call) == null ? void 0 : _b.name) {
|
3876
4228
|
isFunctionStreamingIn = true;
|
3877
4229
|
return {
|
@@ -4144,8 +4496,8 @@ function createFunctionCallTransformer(callbacks) {
|
|
4144
4496
|
|
4145
4497
|
// streams/replicate-stream.ts
|
4146
4498
|
async function ReplicateStream(res, cb, options) {
|
4147
|
-
var
|
4148
|
-
const url = (
|
4499
|
+
var _a9;
|
4500
|
+
const url = (_a9 = res.urls) == null ? void 0 : _a9.stream;
|
4149
4501
|
if (!url) {
|
4150
4502
|
if (res.error)
|
4151
4503
|
throw new Error(res.error);
|
@@ -4166,8 +4518,8 @@ async function ReplicateStream(res, cb, options) {
|
|
4166
4518
|
|
4167
4519
|
// streams/stream-to-response.ts
|
4168
4520
|
function streamToResponse(res, response, init, data) {
|
4169
|
-
var
|
4170
|
-
response.writeHead((
|
4521
|
+
var _a9;
|
4522
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
4171
4523
|
"Content-Type": "text/plain; charset=utf-8",
|
4172
4524
|
...init == null ? void 0 : init.headers
|
4173
4525
|
});
|
@@ -4210,6 +4562,7 @@ var StreamingTextResponse = class extends Response {
|
|
4210
4562
|
var generateId2 = generateIdImpl;
|
4211
4563
|
var nanoid = generateIdImpl;
|
4212
4564
|
export {
|
4565
|
+
AISDKError9 as AISDKError,
|
4213
4566
|
AIStream,
|
4214
4567
|
APICallError2 as APICallError,
|
4215
4568
|
AWSBedrockAnthropicMessagesStream,
|
@@ -4220,35 +4573,34 @@ export {
|
|
4220
4573
|
AnthropicStream,
|
4221
4574
|
AssistantResponse,
|
4222
4575
|
CohereStream,
|
4576
|
+
DownloadError,
|
4223
4577
|
EmptyResponseBodyError,
|
4224
4578
|
GoogleGenerativeAIStream,
|
4225
4579
|
HuggingFaceStream,
|
4226
4580
|
InkeepStream,
|
4227
|
-
|
4228
|
-
|
4581
|
+
InvalidArgumentError,
|
4582
|
+
InvalidDataContentError,
|
4229
4583
|
InvalidMessageRoleError,
|
4230
4584
|
InvalidModelIdError,
|
4231
4585
|
InvalidPromptError2 as InvalidPromptError,
|
4232
4586
|
InvalidResponseDataError,
|
4233
|
-
|
4587
|
+
InvalidToolArgumentsError,
|
4234
4588
|
JSONParseError,
|
4235
4589
|
langchain_adapter_exports as LangChainAdapter,
|
4236
4590
|
LangChainStream,
|
4237
4591
|
LoadAPIKeyError,
|
4238
4592
|
MistralStream,
|
4239
|
-
|
4593
|
+
NoObjectGeneratedError,
|
4240
4594
|
NoSuchModelError,
|
4241
4595
|
NoSuchProviderError,
|
4242
|
-
|
4596
|
+
NoSuchToolError,
|
4243
4597
|
OpenAIStream,
|
4244
4598
|
ReplicateStream,
|
4245
|
-
|
4599
|
+
RetryError,
|
4246
4600
|
StreamData2 as StreamData,
|
4247
4601
|
StreamingTextResponse,
|
4248
|
-
ToolCallParseError,
|
4249
4602
|
TypeValidationError,
|
4250
4603
|
UnsupportedFunctionalityError,
|
4251
|
-
UnsupportedJSONSchemaError,
|
4252
4604
|
convertDataContentToBase64String,
|
4253
4605
|
convertDataContentToUint8Array,
|
4254
4606
|
convertToCoreMessages,
|