ai 3.3.0 → 3.3.2
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 +575 -270
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +553 -258
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -9
- 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,6 +13,110 @@ 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
|
+
|
16
120
|
// core/telemetry/assemble-operation-name.ts
|
17
121
|
function assembleOperationName({
|
18
122
|
operationName,
|
@@ -30,7 +134,7 @@ function getBaseTelemetryAttributes({
|
|
30
134
|
telemetry,
|
31
135
|
headers
|
32
136
|
}) {
|
33
|
-
var
|
137
|
+
var _a9;
|
34
138
|
return {
|
35
139
|
"ai.model.provider": model.provider,
|
36
140
|
"ai.model.id": model.modelId,
|
@@ -43,7 +147,7 @@ function getBaseTelemetryAttributes({
|
|
43
147
|
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
44
148
|
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
45
149
|
// add metadata as attributes:
|
46
|
-
...Object.entries((
|
150
|
+
...Object.entries((_a9 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a9 : {}).reduce(
|
47
151
|
(attributes, [key, value]) => {
|
48
152
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
49
153
|
return attributes;
|
@@ -68,7 +172,7 @@ var noopTracer = {
|
|
68
172
|
startSpan() {
|
69
173
|
return noopSpan;
|
70
174
|
},
|
71
|
-
startActiveSpan(
|
175
|
+
startActiveSpan(name9, arg1, arg2, arg3) {
|
72
176
|
if (typeof arg1 === "function") {
|
73
177
|
return arg1(noopSpan);
|
74
178
|
}
|
@@ -136,13 +240,13 @@ function getTracer({ isEnabled }) {
|
|
136
240
|
// core/telemetry/record-span.ts
|
137
241
|
import { SpanStatusCode } from "@opentelemetry/api";
|
138
242
|
function recordSpan({
|
139
|
-
name,
|
243
|
+
name: name9,
|
140
244
|
tracer,
|
141
245
|
attributes,
|
142
246
|
fn,
|
143
247
|
endWhenDone = true
|
144
248
|
}) {
|
145
|
-
return tracer.startActiveSpan(
|
249
|
+
return tracer.startActiveSpan(name9, { attributes }, async (span) => {
|
146
250
|
try {
|
147
251
|
const result = await fn(span);
|
148
252
|
if (endWhenDone) {
|
@@ -199,68 +303,6 @@ function selectTelemetryAttributes({
|
|
199
303
|
}, {});
|
200
304
|
}
|
201
305
|
|
202
|
-
// core/util/retry-with-exponential-backoff.ts
|
203
|
-
import { APICallError, RetryError } from "@ai-sdk/provider";
|
204
|
-
import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
205
|
-
|
206
|
-
// core/util/delay.ts
|
207
|
-
async function delay(delayInMs) {
|
208
|
-
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
209
|
-
}
|
210
|
-
|
211
|
-
// core/util/retry-with-exponential-backoff.ts
|
212
|
-
var retryWithExponentialBackoff = ({
|
213
|
-
maxRetries = 2,
|
214
|
-
initialDelayInMs = 2e3,
|
215
|
-
backoffFactor = 2
|
216
|
-
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
217
|
-
maxRetries,
|
218
|
-
delayInMs: initialDelayInMs,
|
219
|
-
backoffFactor
|
220
|
-
});
|
221
|
-
async function _retryWithExponentialBackoff(f, {
|
222
|
-
maxRetries,
|
223
|
-
delayInMs,
|
224
|
-
backoffFactor
|
225
|
-
}, errors = []) {
|
226
|
-
try {
|
227
|
-
return await f();
|
228
|
-
} catch (error) {
|
229
|
-
if (isAbortError(error)) {
|
230
|
-
throw error;
|
231
|
-
}
|
232
|
-
if (maxRetries === 0) {
|
233
|
-
throw error;
|
234
|
-
}
|
235
|
-
const errorMessage = getErrorMessage(error);
|
236
|
-
const newErrors = [...errors, error];
|
237
|
-
const tryNumber = newErrors.length;
|
238
|
-
if (tryNumber > maxRetries) {
|
239
|
-
throw new RetryError({
|
240
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
241
|
-
reason: "maxRetriesExceeded",
|
242
|
-
errors: newErrors
|
243
|
-
});
|
244
|
-
}
|
245
|
-
if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
246
|
-
await delay(delayInMs);
|
247
|
-
return _retryWithExponentialBackoff(
|
248
|
-
f,
|
249
|
-
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
250
|
-
newErrors
|
251
|
-
);
|
252
|
-
}
|
253
|
-
if (tryNumber === 1) {
|
254
|
-
throw error;
|
255
|
-
}
|
256
|
-
throw new RetryError({
|
257
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
258
|
-
reason: "errorNotRetryable",
|
259
|
-
errors: newErrors
|
260
|
-
});
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
306
|
// core/embed/embed.ts
|
265
307
|
async function embed({
|
266
308
|
model,
|
@@ -270,14 +312,14 @@ async function embed({
|
|
270
312
|
headers,
|
271
313
|
experimental_telemetry: telemetry
|
272
314
|
}) {
|
273
|
-
var
|
315
|
+
var _a9;
|
274
316
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
275
317
|
model,
|
276
318
|
telemetry,
|
277
319
|
headers,
|
278
320
|
settings: { maxRetries }
|
279
321
|
});
|
280
|
-
const tracer = getTracer({ isEnabled: (
|
322
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
281
323
|
return recordSpan({
|
282
324
|
name: "ai.embed",
|
283
325
|
attributes: selectTelemetryAttributes({
|
@@ -310,14 +352,14 @@ async function embed({
|
|
310
352
|
}),
|
311
353
|
tracer,
|
312
354
|
fn: async (doEmbedSpan) => {
|
313
|
-
var
|
355
|
+
var _a10;
|
314
356
|
const modelResponse = await model.doEmbed({
|
315
357
|
values: [value],
|
316
358
|
abortSignal,
|
317
359
|
headers
|
318
360
|
});
|
319
361
|
const embedding2 = modelResponse.embeddings[0];
|
320
|
-
const usage2 = (
|
362
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
321
363
|
doEmbedSpan.setAttributes(
|
322
364
|
selectTelemetryAttributes({
|
323
365
|
telemetry,
|
@@ -383,14 +425,14 @@ async function embedMany({
|
|
383
425
|
headers,
|
384
426
|
experimental_telemetry: telemetry
|
385
427
|
}) {
|
386
|
-
var
|
428
|
+
var _a9;
|
387
429
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
388
430
|
model,
|
389
431
|
telemetry,
|
390
432
|
headers,
|
391
433
|
settings: { maxRetries }
|
392
434
|
});
|
393
|
-
const tracer = getTracer({ isEnabled: (
|
435
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
394
436
|
return recordSpan({
|
395
437
|
name: "ai.embedMany",
|
396
438
|
attributes: selectTelemetryAttributes({
|
@@ -428,14 +470,14 @@ async function embedMany({
|
|
428
470
|
}),
|
429
471
|
tracer,
|
430
472
|
fn: async (doEmbedSpan) => {
|
431
|
-
var
|
473
|
+
var _a10;
|
432
474
|
const modelResponse = await model.doEmbed({
|
433
475
|
values,
|
434
476
|
abortSignal,
|
435
477
|
headers
|
436
478
|
});
|
437
479
|
const embeddings3 = modelResponse.embeddings;
|
438
|
-
const usage2 = (
|
480
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
439
481
|
doEmbedSpan.setAttributes(
|
440
482
|
selectTelemetryAttributes({
|
441
483
|
telemetry,
|
@@ -487,14 +529,14 @@ async function embedMany({
|
|
487
529
|
}),
|
488
530
|
tracer,
|
489
531
|
fn: async (doEmbedSpan) => {
|
490
|
-
var
|
532
|
+
var _a10;
|
491
533
|
const modelResponse = await model.doEmbed({
|
492
534
|
values: chunk,
|
493
535
|
abortSignal,
|
494
536
|
headers
|
495
537
|
});
|
496
538
|
const embeddings2 = modelResponse.embeddings;
|
497
|
-
const usage2 = (
|
539
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
498
540
|
doEmbedSpan.setAttributes(
|
499
541
|
selectTelemetryAttributes({
|
500
542
|
telemetry,
|
@@ -541,35 +583,62 @@ var DefaultEmbedManyResult = class {
|
|
541
583
|
};
|
542
584
|
|
543
585
|
// core/generate-object/generate-object.ts
|
544
|
-
import { NoObjectGeneratedError } from "@ai-sdk/provider";
|
545
586
|
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
546
587
|
|
547
588
|
// core/prompt/convert-to-language-model-prompt.ts
|
548
589
|
import { getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider-utils";
|
549
590
|
|
550
|
-
//
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
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;
|
562
610
|
}
|
563
|
-
|
564
|
-
|
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;
|
565
635
|
|
566
|
-
//
|
567
|
-
import { DownloadError } from "@ai-sdk/provider";
|
636
|
+
// util/download.ts
|
568
637
|
async function download({
|
569
638
|
url,
|
570
639
|
fetchImplementation = fetch
|
571
640
|
}) {
|
572
|
-
var
|
641
|
+
var _a9;
|
573
642
|
const urlText = url.toString();
|
574
643
|
try {
|
575
644
|
const response = await fetchImplementation(urlText);
|
@@ -582,22 +651,79 @@ async function download({
|
|
582
651
|
}
|
583
652
|
return {
|
584
653
|
data: new Uint8Array(await response.arrayBuffer()),
|
585
|
-
mimeType: (
|
654
|
+
mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
|
586
655
|
};
|
587
656
|
} catch (error) {
|
588
|
-
if (DownloadError.
|
657
|
+
if (DownloadError.isInstance(error)) {
|
589
658
|
throw error;
|
590
659
|
}
|
591
660
|
throw new DownloadError({ url: urlText, cause: error });
|
592
661
|
}
|
593
662
|
}
|
594
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
|
+
|
595
680
|
// core/prompt/data-content.ts
|
596
|
-
import { InvalidDataContentError } from "@ai-sdk/provider";
|
597
681
|
import {
|
598
682
|
convertBase64ToUint8Array,
|
599
683
|
convertUint8ArrayToBase64
|
600
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
|
601
727
|
function convertDataContentToBase64String(content) {
|
602
728
|
if (typeof content === "string") {
|
603
729
|
return content;
|
@@ -636,18 +762,32 @@ function convertUint8ArrayToText(uint8Array) {
|
|
636
762
|
}
|
637
763
|
|
638
764
|
// core/prompt/invalid-message-role-error.ts
|
639
|
-
|
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 {
|
640
771
|
constructor({
|
641
772
|
role,
|
642
773
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
643
774
|
}) {
|
644
|
-
super(message);
|
645
|
-
this
|
775
|
+
super({ name: name4, message });
|
776
|
+
this[_a4] = true;
|
646
777
|
this.role = role;
|
647
778
|
}
|
779
|
+
static isInstance(error) {
|
780
|
+
return AISDKError4.hasMarker(error, marker4);
|
781
|
+
}
|
782
|
+
/**
|
783
|
+
* @deprecated use `isInstance` instead
|
784
|
+
*/
|
648
785
|
static isInvalidMessageRoleError(error) {
|
649
|
-
return error instanceof Error && error.name ===
|
786
|
+
return error instanceof Error && error.name === name4 && typeof error.role === "string";
|
650
787
|
}
|
788
|
+
/**
|
789
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
790
|
+
*/
|
651
791
|
toJSON() {
|
652
792
|
return {
|
653
793
|
name: this.name,
|
@@ -657,6 +797,7 @@ var InvalidMessageRoleError = class extends Error {
|
|
657
797
|
};
|
658
798
|
}
|
659
799
|
};
|
800
|
+
_a4 = symbol4;
|
660
801
|
|
661
802
|
// core/prompt/convert-to-language-model-prompt.ts
|
662
803
|
async function convertToLanguageModelPrompt({
|
@@ -710,7 +851,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
710
851
|
role: "user",
|
711
852
|
content: message.content.map(
|
712
853
|
(part) => {
|
713
|
-
var
|
854
|
+
var _a9, _b, _c;
|
714
855
|
switch (part.type) {
|
715
856
|
case "text": {
|
716
857
|
return part;
|
@@ -728,7 +869,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
728
869
|
return {
|
729
870
|
type: "image",
|
730
871
|
image: downloadedImage.data,
|
731
|
-
mimeType: (
|
872
|
+
mimeType: (_a9 = part.mimeType) != null ? _a9 : downloadedImage.mimeType
|
732
873
|
};
|
733
874
|
}
|
734
875
|
}
|
@@ -877,8 +1018,48 @@ function getValidatedPrompt(prompt) {
|
|
877
1018
|
};
|
878
1019
|
}
|
879
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
|
+
|
880
1062
|
// core/prompt/prepare-call-settings.ts
|
881
|
-
import { InvalidArgumentError } from "@ai-sdk/provider";
|
882
1063
|
function prepareCallSettings({
|
883
1064
|
maxTokens,
|
884
1065
|
temperature,
|
@@ -992,8 +1173,8 @@ function prepareResponseHeaders(init, {
|
|
992
1173
|
contentType,
|
993
1174
|
dataStreamVersion
|
994
1175
|
}) {
|
995
|
-
var
|
996
|
-
const headers = new Headers((
|
1176
|
+
var _a9;
|
1177
|
+
const headers = new Headers((_a9 = init == null ? void 0 : init.headers) != null ? _a9 : {});
|
997
1178
|
if (!headers.has("Content-Type")) {
|
998
1179
|
headers.set("Content-Type", contentType);
|
999
1180
|
}
|
@@ -1006,7 +1187,7 @@ function prepareResponseHeaders(init, {
|
|
1006
1187
|
// core/util/schema.ts
|
1007
1188
|
import { validatorSymbol } from "@ai-sdk/provider-utils";
|
1008
1189
|
import zodToJsonSchema from "zod-to-json-schema";
|
1009
|
-
var schemaSymbol = Symbol("vercel.ai.schema");
|
1190
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
1010
1191
|
function jsonSchema(jsonSchema2, {
|
1011
1192
|
validate
|
1012
1193
|
} = {}) {
|
@@ -1057,6 +1238,41 @@ function injectJsonSchemaIntoSystem({
|
|
1057
1238
|
].filter((line) => line != null).join("\n");
|
1058
1239
|
}
|
1059
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
|
+
|
1060
1276
|
// core/generate-object/generate-object.ts
|
1061
1277
|
async function generateObject({
|
1062
1278
|
model,
|
@@ -1071,7 +1287,7 @@ async function generateObject({
|
|
1071
1287
|
experimental_telemetry: telemetry,
|
1072
1288
|
...settings
|
1073
1289
|
}) {
|
1074
|
-
var
|
1290
|
+
var _a9;
|
1075
1291
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1076
1292
|
model,
|
1077
1293
|
telemetry,
|
@@ -1079,7 +1295,7 @@ async function generateObject({
|
|
1079
1295
|
settings: { ...settings, maxRetries }
|
1080
1296
|
});
|
1081
1297
|
const schema = asSchema(inputSchema);
|
1082
|
-
const tracer = getTracer({ isEnabled: (
|
1298
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1083
1299
|
return recordSpan({
|
1084
1300
|
name: "ai.generateObject",
|
1085
1301
|
attributes: selectTelemetryAttributes({
|
@@ -1232,7 +1448,7 @@ async function generateObject({
|
|
1232
1448
|
}),
|
1233
1449
|
tracer,
|
1234
1450
|
fn: async (span2) => {
|
1235
|
-
var
|
1451
|
+
var _a10, _b;
|
1236
1452
|
const result2 = await model.doGenerate({
|
1237
1453
|
mode: {
|
1238
1454
|
type: "object-tool",
|
@@ -1249,7 +1465,7 @@ async function generateObject({
|
|
1249
1465
|
abortSignal,
|
1250
1466
|
headers
|
1251
1467
|
});
|
1252
|
-
const objectText = (_b = (
|
1468
|
+
const objectText = (_b = (_a10 = result2.toolCalls) == null ? void 0 : _a10[0]) == null ? void 0 : _b.args;
|
1253
1469
|
if (objectText === void 0) {
|
1254
1470
|
throw new NoObjectGeneratedError();
|
1255
1471
|
}
|
@@ -1328,9 +1544,9 @@ var DefaultGenerateObjectResult = class {
|
|
1328
1544
|
this.logprobs = options.logprobs;
|
1329
1545
|
}
|
1330
1546
|
toJsonResponse(init) {
|
1331
|
-
var
|
1547
|
+
var _a9;
|
1332
1548
|
return new Response(JSON.stringify(this.object), {
|
1333
|
-
status: (
|
1549
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
1334
1550
|
headers: prepareResponseHeaders(init, {
|
1335
1551
|
contentType: "application/json; charset=utf-8"
|
1336
1552
|
})
|
@@ -1346,24 +1562,22 @@ import {
|
|
1346
1562
|
parsePartialJson
|
1347
1563
|
} from "@ai-sdk/ui-utils";
|
1348
1564
|
|
1349
|
-
//
|
1350
|
-
function
|
1351
|
-
|
1352
|
-
|
1353
|
-
)
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
};
|
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
|
1362
1577
|
};
|
1363
|
-
return transformedStream;
|
1364
1578
|
}
|
1365
1579
|
|
1366
|
-
//
|
1580
|
+
// util/delayed-promise.ts
|
1367
1581
|
var DelayedPromise = class {
|
1368
1582
|
constructor() {
|
1369
1583
|
this.status = { type: "pending" };
|
@@ -1386,21 +1600,38 @@ var DelayedPromise = class {
|
|
1386
1600
|
return this.promise;
|
1387
1601
|
}
|
1388
1602
|
resolve(value) {
|
1389
|
-
var
|
1603
|
+
var _a9;
|
1390
1604
|
this.status = { type: "resolved", value };
|
1391
1605
|
if (this.promise) {
|
1392
|
-
(
|
1606
|
+
(_a9 = this._resolve) == null ? void 0 : _a9.call(this, value);
|
1393
1607
|
}
|
1394
1608
|
}
|
1395
1609
|
reject(error) {
|
1396
|
-
var
|
1610
|
+
var _a9;
|
1397
1611
|
this.status = { type: "rejected", error };
|
1398
1612
|
if (this.promise) {
|
1399
|
-
(
|
1613
|
+
(_a9 = this._reject) == null ? void 0 : _a9.call(this, error);
|
1400
1614
|
}
|
1401
1615
|
}
|
1402
1616
|
};
|
1403
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
|
+
|
1404
1635
|
// core/generate-object/stream-object.ts
|
1405
1636
|
async function streamObject({
|
1406
1637
|
model,
|
@@ -1416,14 +1647,14 @@ async function streamObject({
|
|
1416
1647
|
onFinish,
|
1417
1648
|
...settings
|
1418
1649
|
}) {
|
1419
|
-
var
|
1650
|
+
var _a9;
|
1420
1651
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1421
1652
|
model,
|
1422
1653
|
telemetry,
|
1423
1654
|
headers,
|
1424
1655
|
settings: { ...settings, maxRetries }
|
1425
1656
|
});
|
1426
|
-
const tracer = getTracer({ isEnabled: (
|
1657
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1427
1658
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1428
1659
|
const schema = asSchema(inputSchema);
|
1429
1660
|
return recordSpan({
|
@@ -1602,10 +1833,8 @@ var DefaultStreamObjectResult = class {
|
|
1602
1833
|
this.warnings = warnings;
|
1603
1834
|
this.rawResponse = rawResponse;
|
1604
1835
|
this.objectPromise = new DelayedPromise();
|
1605
|
-
|
1606
|
-
this.usage =
|
1607
|
-
resolveUsage = resolve;
|
1608
|
-
});
|
1836
|
+
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
1837
|
+
this.usage = usagePromise;
|
1609
1838
|
let usage;
|
1610
1839
|
let finishReason;
|
1611
1840
|
let object;
|
@@ -1780,8 +2009,8 @@ var DefaultStreamObjectResult = class {
|
|
1780
2009
|
});
|
1781
2010
|
}
|
1782
2011
|
pipeTextStreamToResponse(response, init) {
|
1783
|
-
var
|
1784
|
-
response.writeHead((
|
2012
|
+
var _a9;
|
2013
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
1785
2014
|
"Content-Type": "text/plain; charset=utf-8",
|
1786
2015
|
...init == null ? void 0 : init.headers
|
1787
2016
|
});
|
@@ -1803,9 +2032,9 @@ var DefaultStreamObjectResult = class {
|
|
1803
2032
|
read();
|
1804
2033
|
}
|
1805
2034
|
toTextStreamResponse(init) {
|
1806
|
-
var
|
2035
|
+
var _a9;
|
1807
2036
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
1808
|
-
status: (
|
2037
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
1809
2038
|
headers: prepareResponseHeaders(init, {
|
1810
2039
|
contentType: "text/plain; charset=utf-8"
|
1811
2040
|
})
|
@@ -1831,9 +2060,9 @@ function prepareToolsAndToolChoice({
|
|
1831
2060
|
};
|
1832
2061
|
}
|
1833
2062
|
return {
|
1834
|
-
tools: Object.entries(tools).map(([
|
2063
|
+
tools: Object.entries(tools).map(([name9, tool2]) => ({
|
1835
2064
|
type: "function",
|
1836
|
-
name,
|
2065
|
+
name: name9,
|
1837
2066
|
description: tool2.description,
|
1838
2067
|
parameters: asSchema(tool2.parameters).jsonSchema
|
1839
2068
|
})),
|
@@ -1842,11 +2071,95 @@ function prepareToolsAndToolChoice({
|
|
1842
2071
|
}
|
1843
2072
|
|
1844
2073
|
// core/generate-text/tool-call.ts
|
1845
|
-
import {
|
1846
|
-
InvalidToolArgumentsError,
|
1847
|
-
NoSuchToolError
|
1848
|
-
} from "@ai-sdk/provider";
|
1849
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
|
1850
2163
|
function parseToolCall({
|
1851
2164
|
toolCall,
|
1852
2165
|
tools
|
@@ -1897,14 +2210,14 @@ async function generateText({
|
|
1897
2210
|
experimental_telemetry: telemetry,
|
1898
2211
|
...settings
|
1899
2212
|
}) {
|
1900
|
-
var
|
2213
|
+
var _a9;
|
1901
2214
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1902
2215
|
model,
|
1903
2216
|
telemetry,
|
1904
2217
|
headers,
|
1905
2218
|
settings: { ...settings, maxRetries }
|
1906
2219
|
});
|
1907
|
-
const tracer = getTracer({ isEnabled: (
|
2220
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1908
2221
|
return recordSpan({
|
1909
2222
|
name: "ai.generateText",
|
1910
2223
|
attributes: selectTelemetryAttributes({
|
@@ -1924,7 +2237,7 @@ async function generateText({
|
|
1924
2237
|
}),
|
1925
2238
|
tracer,
|
1926
2239
|
fn: async (span) => {
|
1927
|
-
var
|
2240
|
+
var _a10, _b, _c, _d;
|
1928
2241
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1929
2242
|
const validatedPrompt = getValidatedPrompt({
|
1930
2243
|
system,
|
@@ -2010,7 +2323,7 @@ async function generateText({
|
|
2010
2323
|
}
|
2011
2324
|
})
|
2012
2325
|
);
|
2013
|
-
currentToolCalls = ((
|
2326
|
+
currentToolCalls = ((_a10 = currentModelResponse.toolCalls) != null ? _a10 : []).map(
|
2014
2327
|
(modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
|
2015
2328
|
);
|
2016
2329
|
currentToolResults = tools == null ? [] : await executeTools({
|
@@ -2272,7 +2585,6 @@ function mergeStreams(stream1, stream2) {
|
|
2272
2585
|
}
|
2273
2586
|
|
2274
2587
|
// core/generate-text/run-tools-transformation.ts
|
2275
|
-
import { NoSuchToolError as NoSuchToolError2 } from "@ai-sdk/provider";
|
2276
2588
|
import { generateId } from "@ai-sdk/ui-utils";
|
2277
2589
|
function runToolsTransformation({
|
2278
2590
|
tools,
|
@@ -2323,7 +2635,7 @@ function runToolsTransformation({
|
|
2323
2635
|
if (tools == null) {
|
2324
2636
|
toolResultsStreamController.enqueue({
|
2325
2637
|
type: "error",
|
2326
|
-
error: new
|
2638
|
+
error: new NoSuchToolError({ toolName: chunk.toolName })
|
2327
2639
|
});
|
2328
2640
|
break;
|
2329
2641
|
}
|
@@ -2331,7 +2643,7 @@ function runToolsTransformation({
|
|
2331
2643
|
if (tool2 == null) {
|
2332
2644
|
toolResultsStreamController.enqueue({
|
2333
2645
|
type: "error",
|
2334
|
-
error: new
|
2646
|
+
error: new NoSuchToolError({
|
2335
2647
|
toolName: chunk.toolName,
|
2336
2648
|
availableTools: Object.keys(tools)
|
2337
2649
|
})
|
@@ -2475,14 +2787,14 @@ async function streamText({
|
|
2475
2787
|
onFinish,
|
2476
2788
|
...settings
|
2477
2789
|
}) {
|
2478
|
-
var
|
2790
|
+
var _a9;
|
2479
2791
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
2480
2792
|
model,
|
2481
2793
|
telemetry,
|
2482
2794
|
headers,
|
2483
2795
|
settings: { ...settings, maxRetries }
|
2484
2796
|
});
|
2485
|
-
const tracer = getTracer({ isEnabled: (
|
2797
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
2486
2798
|
return recordSpan({
|
2487
2799
|
name: "ai.streamText",
|
2488
2800
|
attributes: selectTelemetryAttributes({
|
@@ -2584,26 +2896,16 @@ var DefaultStreamTextResult = class {
|
|
2584
2896
|
this.warnings = warnings;
|
2585
2897
|
this.rawResponse = rawResponse;
|
2586
2898
|
this.onFinish = onFinish;
|
2587
|
-
|
2588
|
-
this.usage =
|
2589
|
-
|
2590
|
-
|
2591
|
-
|
2592
|
-
this.
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
this.
|
2597
|
-
resolveText = resolve;
|
2598
|
-
});
|
2599
|
-
let resolveToolCalls;
|
2600
|
-
this.toolCalls = new Promise((resolve) => {
|
2601
|
-
resolveToolCalls = resolve;
|
2602
|
-
});
|
2603
|
-
let resolveToolResults;
|
2604
|
-
this.toolResults = new Promise((resolve) => {
|
2605
|
-
resolveToolResults = resolve;
|
2606
|
-
});
|
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;
|
2607
2909
|
let finishReason;
|
2608
2910
|
let usage;
|
2609
2911
|
let text = "";
|
@@ -2650,7 +2952,7 @@ var DefaultStreamTextResult = class {
|
|
2650
2952
|
},
|
2651
2953
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
2652
2954
|
async flush(controller) {
|
2653
|
-
var
|
2955
|
+
var _a9;
|
2654
2956
|
try {
|
2655
2957
|
const finalUsage = usage != null ? usage : {
|
2656
2958
|
promptTokens: NaN,
|
@@ -2689,7 +2991,7 @@ var DefaultStreamTextResult = class {
|
|
2689
2991
|
})
|
2690
2992
|
);
|
2691
2993
|
resolveToolResults(toolResults);
|
2692
|
-
await ((
|
2994
|
+
await ((_a9 = self.onFinish) == null ? void 0 : _a9.call(self, {
|
2693
2995
|
finishReason: finalFinishReason,
|
2694
2996
|
usage: finalUsage,
|
2695
2997
|
text,
|
@@ -2844,8 +3146,8 @@ var DefaultStreamTextResult = class {
|
|
2844
3146
|
return this.pipeDataStreamToResponse(response, init);
|
2845
3147
|
}
|
2846
3148
|
pipeDataStreamToResponse(response, init) {
|
2847
|
-
var
|
2848
|
-
response.writeHead((
|
3149
|
+
var _a9;
|
3150
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
2849
3151
|
"Content-Type": "text/plain; charset=utf-8",
|
2850
3152
|
...init == null ? void 0 : init.headers
|
2851
3153
|
});
|
@@ -2867,8 +3169,8 @@ var DefaultStreamTextResult = class {
|
|
2867
3169
|
read();
|
2868
3170
|
}
|
2869
3171
|
pipeTextStreamToResponse(response, init) {
|
2870
|
-
var
|
2871
|
-
response.writeHead((
|
3172
|
+
var _a9;
|
3173
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
2872
3174
|
"Content-Type": "text/plain; charset=utf-8",
|
2873
3175
|
...init == null ? void 0 : init.headers
|
2874
3176
|
});
|
@@ -2893,7 +3195,7 @@ var DefaultStreamTextResult = class {
|
|
2893
3195
|
return this.toDataStreamResponse(options);
|
2894
3196
|
}
|
2895
3197
|
toDataStreamResponse(options) {
|
2896
|
-
var
|
3198
|
+
var _a9;
|
2897
3199
|
const init = options == null ? void 0 : "init" in options ? options.init : {
|
2898
3200
|
headers: "headers" in options ? options.headers : void 0,
|
2899
3201
|
status: "status" in options ? options.status : void 0,
|
@@ -2902,7 +3204,7 @@ var DefaultStreamTextResult = class {
|
|
2902
3204
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
2903
3205
|
const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
|
2904
3206
|
return new Response(stream, {
|
2905
|
-
status: (
|
3207
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
2906
3208
|
statusText: init == null ? void 0 : init.statusText,
|
2907
3209
|
headers: prepareResponseHeaders(init, {
|
2908
3210
|
contentType: "text/plain; charset=utf-8",
|
@@ -2911,9 +3213,9 @@ var DefaultStreamTextResult = class {
|
|
2911
3213
|
});
|
2912
3214
|
}
|
2913
3215
|
toTextStreamResponse(init) {
|
2914
|
-
var
|
3216
|
+
var _a9;
|
2915
3217
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
2916
|
-
status: (
|
3218
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
2917
3219
|
headers: prepareResponseHeaders(init, {
|
2918
3220
|
contentType: "text/plain; charset=utf-8"
|
2919
3221
|
})
|
@@ -2924,7 +3226,7 @@ var experimental_streamText = streamText;
|
|
2924
3226
|
|
2925
3227
|
// core/prompt/attachments-to-parts.ts
|
2926
3228
|
function attachmentsToParts(attachments) {
|
2927
|
-
var
|
3229
|
+
var _a9, _b, _c;
|
2928
3230
|
const parts = [];
|
2929
3231
|
for (const attachment of attachments) {
|
2930
3232
|
let url;
|
@@ -2936,7 +3238,7 @@ function attachmentsToParts(attachments) {
|
|
2936
3238
|
switch (url.protocol) {
|
2937
3239
|
case "http:":
|
2938
3240
|
case "https:": {
|
2939
|
-
if ((
|
3241
|
+
if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
|
2940
3242
|
parts.push({ type: "image", image: url });
|
2941
3243
|
}
|
2942
3244
|
break;
|
@@ -3153,18 +3455,18 @@ var DefaultProviderRegistry = class {
|
|
3153
3455
|
return [id.slice(0, index), id.slice(index + 1)];
|
3154
3456
|
}
|
3155
3457
|
languageModel(id) {
|
3156
|
-
var
|
3458
|
+
var _a9, _b;
|
3157
3459
|
const [providerId, modelId] = this.splitId(id);
|
3158
|
-
const model = (_b = (
|
3460
|
+
const model = (_b = (_a9 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a9, modelId);
|
3159
3461
|
if (model == null) {
|
3160
3462
|
throw new NoSuchModelError({ modelId: id, modelType: "language model" });
|
3161
3463
|
}
|
3162
3464
|
return model;
|
3163
3465
|
}
|
3164
3466
|
textEmbeddingModel(id) {
|
3165
|
-
var
|
3467
|
+
var _a9, _b;
|
3166
3468
|
const [providerId, modelId] = this.splitId(id);
|
3167
|
-
const model = (_b = (
|
3469
|
+
const model = (_b = (_a9 = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a9, modelId);
|
3168
3470
|
if (model == null) {
|
3169
3471
|
throw new NoSuchModelError({
|
3170
3472
|
modelId: id,
|
@@ -3180,26 +3482,6 @@ function tool(tool2) {
|
|
3180
3482
|
return tool2;
|
3181
3483
|
}
|
3182
3484
|
|
3183
|
-
// core/types/errors.ts
|
3184
|
-
import {
|
3185
|
-
APICallError as APICallError2,
|
3186
|
-
EmptyResponseBodyError,
|
3187
|
-
InvalidArgumentError as InvalidArgumentError2,
|
3188
|
-
InvalidDataContentError as InvalidDataContentError2,
|
3189
|
-
InvalidPromptError as InvalidPromptError2,
|
3190
|
-
InvalidResponseDataError,
|
3191
|
-
InvalidToolArgumentsError as InvalidToolArgumentsError2,
|
3192
|
-
JSONParseError,
|
3193
|
-
LoadAPIKeyError,
|
3194
|
-
NoObjectGeneratedError as NoObjectGeneratedError2,
|
3195
|
-
NoSuchToolError as NoSuchToolError3,
|
3196
|
-
RetryError as RetryError2,
|
3197
|
-
ToolCallParseError,
|
3198
|
-
TypeValidationError,
|
3199
|
-
UnsupportedFunctionalityError,
|
3200
|
-
UnsupportedJSONSchemaError
|
3201
|
-
} from "@ai-sdk/provider";
|
3202
|
-
|
3203
3485
|
// core/util/cosine-similarity.ts
|
3204
3486
|
function cosineSimilarity(vector1, vector2) {
|
3205
3487
|
if (vector1.length !== vector2.length) {
|
@@ -3219,6 +3501,19 @@ function magnitude(vector) {
|
|
3219
3501
|
return Math.sqrt(dotProduct(vector, vector));
|
3220
3502
|
}
|
3221
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
|
+
|
3222
3517
|
// streams/ai-stream.ts
|
3223
3518
|
import {
|
3224
3519
|
createParser
|
@@ -3337,8 +3632,8 @@ function readableFromAsyncIterable(iterable) {
|
|
3337
3632
|
controller.enqueue(value);
|
3338
3633
|
},
|
3339
3634
|
async cancel(reason) {
|
3340
|
-
var
|
3341
|
-
await ((
|
3635
|
+
var _a9;
|
3636
|
+
await ((_a9 = it.return) == null ? void 0 : _a9.call(it, reason));
|
3342
3637
|
}
|
3343
3638
|
});
|
3344
3639
|
}
|
@@ -3472,7 +3767,7 @@ import {
|
|
3472
3767
|
function AssistantResponse({ threadId, messageId }, process2) {
|
3473
3768
|
const stream = new ReadableStream({
|
3474
3769
|
async start(controller) {
|
3475
|
-
var
|
3770
|
+
var _a9;
|
3476
3771
|
const textEncoder = new TextEncoder();
|
3477
3772
|
const sendMessage = (message) => {
|
3478
3773
|
controller.enqueue(
|
@@ -3490,7 +3785,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3490
3785
|
);
|
3491
3786
|
};
|
3492
3787
|
const forwardStream = async (stream2) => {
|
3493
|
-
var
|
3788
|
+
var _a10, _b;
|
3494
3789
|
let result = void 0;
|
3495
3790
|
for await (const value of stream2) {
|
3496
3791
|
switch (value.event) {
|
@@ -3507,7 +3802,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3507
3802
|
break;
|
3508
3803
|
}
|
3509
3804
|
case "thread.message.delta": {
|
3510
|
-
const content = (
|
3805
|
+
const content = (_a10 = value.data.delta.content) == null ? void 0 : _a10[0];
|
3511
3806
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
3512
3807
|
controller.enqueue(
|
3513
3808
|
textEncoder.encode(
|
@@ -3543,7 +3838,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3543
3838
|
forwardStream
|
3544
3839
|
});
|
3545
3840
|
} catch (error) {
|
3546
|
-
sendError((
|
3841
|
+
sendError((_a9 = error.message) != null ? _a9 : `${error}`);
|
3547
3842
|
} finally {
|
3548
3843
|
controller.close();
|
3549
3844
|
}
|
@@ -3564,9 +3859,9 @@ var experimental_AssistantResponse = AssistantResponse;
|
|
3564
3859
|
|
3565
3860
|
// streams/aws-bedrock-stream.ts
|
3566
3861
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
3567
|
-
var
|
3862
|
+
var _a9, _b;
|
3568
3863
|
const decoder = new TextDecoder();
|
3569
|
-
for await (const chunk of (
|
3864
|
+
for await (const chunk of (_a9 = response.body) != null ? _a9 : []) {
|
3570
3865
|
const bytes = (_b = chunk.chunk) == null ? void 0 : _b.bytes;
|
3571
3866
|
if (bytes != null) {
|
3572
3867
|
const chunkText = decoder.decode(bytes);
|
@@ -3580,8 +3875,8 @@ async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
|
3580
3875
|
}
|
3581
3876
|
function AWSBedrockAnthropicMessagesStream(response, callbacks) {
|
3582
3877
|
return AWSBedrockStream(response, callbacks, (chunk) => {
|
3583
|
-
var
|
3584
|
-
return (
|
3878
|
+
var _a9;
|
3879
|
+
return (_a9 = chunk.delta) == null ? void 0 : _a9.text;
|
3585
3880
|
});
|
3586
3881
|
}
|
3587
3882
|
function AWSBedrockAnthropicStream(response, callbacks) {
|
@@ -3628,8 +3923,8 @@ async function readAndProcessLines(reader, controller) {
|
|
3628
3923
|
controller.close();
|
3629
3924
|
}
|
3630
3925
|
function createParser2(res) {
|
3631
|
-
var
|
3632
|
-
const reader = (
|
3926
|
+
var _a9;
|
3927
|
+
const reader = (_a9 = res.body) == null ? void 0 : _a9.getReader();
|
3633
3928
|
return new ReadableStream({
|
3634
3929
|
async start(controller) {
|
3635
3930
|
if (!reader) {
|
@@ -3659,9 +3954,9 @@ function CohereStream(reader, callbacks) {
|
|
3659
3954
|
|
3660
3955
|
// streams/google-generative-ai-stream.ts
|
3661
3956
|
async function* streamable3(response) {
|
3662
|
-
var
|
3957
|
+
var _a9, _b, _c;
|
3663
3958
|
for await (const chunk of response.stream) {
|
3664
|
-
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;
|
3665
3960
|
if (parts === void 0) {
|
3666
3961
|
continue;
|
3667
3962
|
}
|
@@ -3680,13 +3975,13 @@ function createParser3(res) {
|
|
3680
3975
|
const trimStartOfStream = trimStartOfStreamHelper();
|
3681
3976
|
return new ReadableStream({
|
3682
3977
|
async pull(controller) {
|
3683
|
-
var
|
3978
|
+
var _a9, _b;
|
3684
3979
|
const { value, done } = await res.next();
|
3685
3980
|
if (done) {
|
3686
3981
|
controller.close();
|
3687
3982
|
return;
|
3688
3983
|
}
|
3689
|
-
const text = trimStartOfStream((_b = (
|
3984
|
+
const text = trimStartOfStream((_b = (_a9 = value.token) == null ? void 0 : _a9.text) != null ? _b : "");
|
3690
3985
|
if (!text)
|
3691
3986
|
return;
|
3692
3987
|
if (value.generated_text != null && value.generated_text.length > 0) {
|
@@ -3711,11 +4006,11 @@ function InkeepStream(res, callbacks) {
|
|
3711
4006
|
let chat_session_id = "";
|
3712
4007
|
let records_cited;
|
3713
4008
|
const inkeepEventParser = (data, options) => {
|
3714
|
-
var
|
4009
|
+
var _a9, _b;
|
3715
4010
|
const { event } = options;
|
3716
4011
|
if (event === "records_cited") {
|
3717
4012
|
records_cited = JSON.parse(data);
|
3718
|
-
(
|
4013
|
+
(_a9 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a9.call(callbacks, records_cited);
|
3719
4014
|
}
|
3720
4015
|
if (event === "message_chunk") {
|
3721
4016
|
const inkeepMessageChunk = JSON.parse(data);
|
@@ -3728,12 +4023,12 @@ function InkeepStream(res, callbacks) {
|
|
3728
4023
|
passThroughCallbacks = {
|
3729
4024
|
...passThroughCallbacks,
|
3730
4025
|
onFinal: (completion) => {
|
3731
|
-
var
|
4026
|
+
var _a9;
|
3732
4027
|
const inkeepOnFinalMetadata = {
|
3733
4028
|
chat_session_id,
|
3734
4029
|
records_cited
|
3735
4030
|
};
|
3736
|
-
(
|
4031
|
+
(_a9 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a9.call(callbacks, completion, inkeepOnFinalMetadata);
|
3737
4032
|
}
|
3738
4033
|
};
|
3739
4034
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
@@ -3755,7 +4050,7 @@ function toDataStream(stream, callbacks) {
|
|
3755
4050
|
return stream.pipeThrough(
|
3756
4051
|
new TransformStream({
|
3757
4052
|
transform: async (value, controller) => {
|
3758
|
-
var
|
4053
|
+
var _a9;
|
3759
4054
|
if (typeof value === "string") {
|
3760
4055
|
controller.enqueue(value);
|
3761
4056
|
return;
|
@@ -3763,7 +4058,7 @@ function toDataStream(stream, callbacks) {
|
|
3763
4058
|
if ("event" in value) {
|
3764
4059
|
if (value.event === "on_chat_model_stream") {
|
3765
4060
|
forwardAIMessageChunk(
|
3766
|
-
(
|
4061
|
+
(_a9 = value.data) == null ? void 0 : _a9.chunk,
|
3767
4062
|
controller
|
3768
4063
|
);
|
3769
4064
|
}
|
@@ -3775,13 +4070,13 @@ function toDataStream(stream, callbacks) {
|
|
3775
4070
|
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
3776
4071
|
}
|
3777
4072
|
function toDataStreamResponse(stream, options) {
|
3778
|
-
var
|
4073
|
+
var _a9;
|
3779
4074
|
const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
|
3780
4075
|
const data = options == null ? void 0 : options.data;
|
3781
4076
|
const init = options == null ? void 0 : options.init;
|
3782
4077
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
3783
4078
|
return new Response(responseStream, {
|
3784
|
-
status: (
|
4079
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
3785
4080
|
statusText: init == null ? void 0 : init.statusText,
|
3786
4081
|
headers: prepareResponseHeaders(init, {
|
3787
4082
|
contentType: "text/plain; charset=utf-8",
|
@@ -3863,9 +4158,9 @@ function LangChainStream(callbacks) {
|
|
3863
4158
|
|
3864
4159
|
// streams/mistral-stream.ts
|
3865
4160
|
async function* streamable4(stream) {
|
3866
|
-
var
|
4161
|
+
var _a9, _b;
|
3867
4162
|
for await (const chunk of stream) {
|
3868
|
-
const content = (_b = (
|
4163
|
+
const content = (_b = (_a9 = chunk.choices[0]) == null ? void 0 : _a9.delta) == null ? void 0 : _b.content;
|
3869
4164
|
if (content === void 0 || content === "") {
|
3870
4165
|
continue;
|
3871
4166
|
}
|
@@ -3898,10 +4193,10 @@ async function* streamable5(stream) {
|
|
3898
4193
|
model: chunk.model,
|
3899
4194
|
// not exposed by Azure API
|
3900
4195
|
choices: chunk.choices.map((choice) => {
|
3901
|
-
var
|
4196
|
+
var _a9, _b, _c, _d, _e, _f, _g;
|
3902
4197
|
return {
|
3903
4198
|
delta: {
|
3904
|
-
content: (
|
4199
|
+
content: (_a9 = choice.delta) == null ? void 0 : _a9.content,
|
3905
4200
|
function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
|
3906
4201
|
role: (_c = choice.delta) == null ? void 0 : _c.role,
|
3907
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) => ({
|
@@ -3926,9 +4221,9 @@ function chunkToText() {
|
|
3926
4221
|
const trimStartOfStream = trimStartOfStreamHelper();
|
3927
4222
|
let isFunctionStreamingIn;
|
3928
4223
|
return (json) => {
|
3929
|
-
var
|
4224
|
+
var _a9, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
3930
4225
|
if (isChatCompletionChunk(json)) {
|
3931
|
-
const delta = (
|
4226
|
+
const delta = (_a9 = json.choices[0]) == null ? void 0 : _a9.delta;
|
3932
4227
|
if ((_b = delta.function_call) == null ? void 0 : _b.name) {
|
3933
4228
|
isFunctionStreamingIn = true;
|
3934
4229
|
return {
|
@@ -4201,8 +4496,8 @@ function createFunctionCallTransformer(callbacks) {
|
|
4201
4496
|
|
4202
4497
|
// streams/replicate-stream.ts
|
4203
4498
|
async function ReplicateStream(res, cb, options) {
|
4204
|
-
var
|
4205
|
-
const url = (
|
4499
|
+
var _a9;
|
4500
|
+
const url = (_a9 = res.urls) == null ? void 0 : _a9.stream;
|
4206
4501
|
if (!url) {
|
4207
4502
|
if (res.error)
|
4208
4503
|
throw new Error(res.error);
|
@@ -4223,8 +4518,8 @@ async function ReplicateStream(res, cb, options) {
|
|
4223
4518
|
|
4224
4519
|
// streams/stream-to-response.ts
|
4225
4520
|
function streamToResponse(res, response, init, data) {
|
4226
|
-
var
|
4227
|
-
response.writeHead((
|
4521
|
+
var _a9;
|
4522
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
4228
4523
|
"Content-Type": "text/plain; charset=utf-8",
|
4229
4524
|
...init == null ? void 0 : init.headers
|
4230
4525
|
});
|
@@ -4267,6 +4562,7 @@ var StreamingTextResponse = class extends Response {
|
|
4267
4562
|
var generateId2 = generateIdImpl;
|
4268
4563
|
var nanoid = generateIdImpl;
|
4269
4564
|
export {
|
4565
|
+
AISDKError9 as AISDKError,
|
4270
4566
|
AIStream,
|
4271
4567
|
APICallError2 as APICallError,
|
4272
4568
|
AWSBedrockAnthropicMessagesStream,
|
@@ -4277,35 +4573,34 @@ export {
|
|
4277
4573
|
AnthropicStream,
|
4278
4574
|
AssistantResponse,
|
4279
4575
|
CohereStream,
|
4576
|
+
DownloadError,
|
4280
4577
|
EmptyResponseBodyError,
|
4281
4578
|
GoogleGenerativeAIStream,
|
4282
4579
|
HuggingFaceStream,
|
4283
4580
|
InkeepStream,
|
4284
|
-
|
4285
|
-
|
4581
|
+
InvalidArgumentError,
|
4582
|
+
InvalidDataContentError,
|
4286
4583
|
InvalidMessageRoleError,
|
4287
4584
|
InvalidModelIdError,
|
4288
4585
|
InvalidPromptError2 as InvalidPromptError,
|
4289
4586
|
InvalidResponseDataError,
|
4290
|
-
|
4587
|
+
InvalidToolArgumentsError,
|
4291
4588
|
JSONParseError,
|
4292
4589
|
langchain_adapter_exports as LangChainAdapter,
|
4293
4590
|
LangChainStream,
|
4294
4591
|
LoadAPIKeyError,
|
4295
4592
|
MistralStream,
|
4296
|
-
|
4593
|
+
NoObjectGeneratedError,
|
4297
4594
|
NoSuchModelError,
|
4298
4595
|
NoSuchProviderError,
|
4299
|
-
|
4596
|
+
NoSuchToolError,
|
4300
4597
|
OpenAIStream,
|
4301
4598
|
ReplicateStream,
|
4302
|
-
|
4599
|
+
RetryError,
|
4303
4600
|
StreamData2 as StreamData,
|
4304
4601
|
StreamingTextResponse,
|
4305
|
-
ToolCallParseError,
|
4306
4602
|
TypeValidationError,
|
4307
4603
|
UnsupportedFunctionalityError,
|
4308
|
-
UnsupportedJSONSchemaError,
|
4309
4604
|
convertDataContentToBase64String,
|
4310
4605
|
convertDataContentToUint8Array,
|
4311
4606
|
convertToCoreMessages,
|