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.js
CHANGED
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
8
|
var __export = (target, all) => {
|
9
|
-
for (var
|
10
|
-
__defProp(target,
|
9
|
+
for (var name9 in all)
|
10
|
+
__defProp(target, name9, { get: all[name9], enumerable: true });
|
11
11
|
};
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
@@ -30,8 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
30
30
|
// streams/index.ts
|
31
31
|
var streams_exports = {};
|
32
32
|
__export(streams_exports, {
|
33
|
+
AISDKError: () => import_provider11.AISDKError,
|
33
34
|
AIStream: () => AIStream,
|
34
|
-
APICallError: () =>
|
35
|
+
APICallError: () => import_provider11.APICallError,
|
35
36
|
AWSBedrockAnthropicMessagesStream: () => AWSBedrockAnthropicMessagesStream,
|
36
37
|
AWSBedrockAnthropicStream: () => AWSBedrockAnthropicStream,
|
37
38
|
AWSBedrockCohereStream: () => AWSBedrockCohereStream,
|
@@ -40,35 +41,34 @@ __export(streams_exports, {
|
|
40
41
|
AnthropicStream: () => AnthropicStream,
|
41
42
|
AssistantResponse: () => AssistantResponse,
|
42
43
|
CohereStream: () => CohereStream,
|
43
|
-
|
44
|
+
DownloadError: () => DownloadError,
|
45
|
+
EmptyResponseBodyError: () => import_provider11.EmptyResponseBodyError,
|
44
46
|
GoogleGenerativeAIStream: () => GoogleGenerativeAIStream,
|
45
47
|
HuggingFaceStream: () => HuggingFaceStream,
|
46
48
|
InkeepStream: () => InkeepStream,
|
47
|
-
InvalidArgumentError: () =>
|
48
|
-
InvalidDataContentError: () =>
|
49
|
+
InvalidArgumentError: () => InvalidArgumentError,
|
50
|
+
InvalidDataContentError: () => InvalidDataContentError,
|
49
51
|
InvalidMessageRoleError: () => InvalidMessageRoleError,
|
50
52
|
InvalidModelIdError: () => InvalidModelIdError,
|
51
|
-
InvalidPromptError: () =>
|
52
|
-
InvalidResponseDataError: () =>
|
53
|
-
InvalidToolArgumentsError: () =>
|
54
|
-
JSONParseError: () =>
|
53
|
+
InvalidPromptError: () => import_provider11.InvalidPromptError,
|
54
|
+
InvalidResponseDataError: () => import_provider11.InvalidResponseDataError,
|
55
|
+
InvalidToolArgumentsError: () => InvalidToolArgumentsError,
|
56
|
+
JSONParseError: () => import_provider11.JSONParseError,
|
55
57
|
LangChainAdapter: () => langchain_adapter_exports,
|
56
58
|
LangChainStream: () => LangChainStream,
|
57
|
-
LoadAPIKeyError: () =>
|
59
|
+
LoadAPIKeyError: () => import_provider11.LoadAPIKeyError,
|
58
60
|
MistralStream: () => MistralStream,
|
59
|
-
NoObjectGeneratedError: () =>
|
61
|
+
NoObjectGeneratedError: () => NoObjectGeneratedError,
|
60
62
|
NoSuchModelError: () => NoSuchModelError,
|
61
63
|
NoSuchProviderError: () => NoSuchProviderError,
|
62
|
-
NoSuchToolError: () =>
|
64
|
+
NoSuchToolError: () => NoSuchToolError,
|
63
65
|
OpenAIStream: () => OpenAIStream,
|
64
66
|
ReplicateStream: () => ReplicateStream,
|
65
|
-
RetryError: () =>
|
67
|
+
RetryError: () => RetryError,
|
66
68
|
StreamData: () => StreamData2,
|
67
69
|
StreamingTextResponse: () => StreamingTextResponse,
|
68
|
-
|
69
|
-
|
70
|
-
UnsupportedFunctionalityError: () => import_provider9.UnsupportedFunctionalityError,
|
71
|
-
UnsupportedJSONSchemaError: () => import_provider9.UnsupportedJSONSchemaError,
|
70
|
+
TypeValidationError: () => import_provider11.TypeValidationError,
|
71
|
+
UnsupportedFunctionalityError: () => import_provider11.UnsupportedFunctionalityError,
|
72
72
|
convertDataContentToBase64String: () => convertDataContentToBase64String,
|
73
73
|
convertDataContentToUint8Array: () => convertDataContentToUint8Array,
|
74
74
|
convertToCoreMessages: () => convertToCoreMessages,
|
@@ -107,15 +107,128 @@ module.exports = __toCommonJS(streams_exports);
|
|
107
107
|
var import_ui_utils6 = require("@ai-sdk/ui-utils");
|
108
108
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
109
109
|
|
110
|
+
// util/retry-with-exponential-backoff.ts
|
111
|
+
var import_provider2 = require("@ai-sdk/provider");
|
112
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
113
|
+
|
114
|
+
// util/delay.ts
|
115
|
+
async function delay(delayInMs) {
|
116
|
+
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
117
|
+
}
|
118
|
+
|
119
|
+
// util/retry-error.ts
|
120
|
+
var import_provider = require("@ai-sdk/provider");
|
121
|
+
var name = "AI_RetryError";
|
122
|
+
var marker = `vercel.ai.error.${name}`;
|
123
|
+
var symbol = Symbol.for(marker);
|
124
|
+
var _a;
|
125
|
+
var RetryError = class extends import_provider.AISDKError {
|
126
|
+
constructor({
|
127
|
+
message,
|
128
|
+
reason,
|
129
|
+
errors
|
130
|
+
}) {
|
131
|
+
super({ name, message });
|
132
|
+
this[_a] = true;
|
133
|
+
this.reason = reason;
|
134
|
+
this.errors = errors;
|
135
|
+
this.lastError = errors[errors.length - 1];
|
136
|
+
}
|
137
|
+
static isInstance(error) {
|
138
|
+
return import_provider.AISDKError.hasMarker(error, marker);
|
139
|
+
}
|
140
|
+
/**
|
141
|
+
* @deprecated use `isInstance` instead
|
142
|
+
*/
|
143
|
+
static isRetryError(error) {
|
144
|
+
return error instanceof Error && error.name === name && typeof error.reason === "string" && Array.isArray(error.errors);
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
148
|
+
*/
|
149
|
+
toJSON() {
|
150
|
+
return {
|
151
|
+
name: this.name,
|
152
|
+
message: this.message,
|
153
|
+
reason: this.reason,
|
154
|
+
lastError: this.lastError,
|
155
|
+
errors: this.errors
|
156
|
+
};
|
157
|
+
}
|
158
|
+
};
|
159
|
+
_a = symbol;
|
160
|
+
|
161
|
+
// util/retry-with-exponential-backoff.ts
|
162
|
+
var retryWithExponentialBackoff = ({
|
163
|
+
maxRetries = 2,
|
164
|
+
initialDelayInMs = 2e3,
|
165
|
+
backoffFactor = 2
|
166
|
+
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
167
|
+
maxRetries,
|
168
|
+
delayInMs: initialDelayInMs,
|
169
|
+
backoffFactor
|
170
|
+
});
|
171
|
+
async function _retryWithExponentialBackoff(f, {
|
172
|
+
maxRetries,
|
173
|
+
delayInMs,
|
174
|
+
backoffFactor
|
175
|
+
}, errors = []) {
|
176
|
+
try {
|
177
|
+
return await f();
|
178
|
+
} catch (error) {
|
179
|
+
if ((0, import_provider_utils.isAbortError)(error)) {
|
180
|
+
throw error;
|
181
|
+
}
|
182
|
+
if (maxRetries === 0) {
|
183
|
+
throw error;
|
184
|
+
}
|
185
|
+
const errorMessage = (0, import_provider_utils.getErrorMessage)(error);
|
186
|
+
const newErrors = [...errors, error];
|
187
|
+
const tryNumber = newErrors.length;
|
188
|
+
if (tryNumber > maxRetries) {
|
189
|
+
throw new RetryError({
|
190
|
+
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
191
|
+
reason: "maxRetriesExceeded",
|
192
|
+
errors: newErrors
|
193
|
+
});
|
194
|
+
}
|
195
|
+
if (error instanceof Error && import_provider2.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
196
|
+
await delay(delayInMs);
|
197
|
+
return _retryWithExponentialBackoff(
|
198
|
+
f,
|
199
|
+
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
200
|
+
newErrors
|
201
|
+
);
|
202
|
+
}
|
203
|
+
if (tryNumber === 1) {
|
204
|
+
throw error;
|
205
|
+
}
|
206
|
+
throw new RetryError({
|
207
|
+
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
208
|
+
reason: "errorNotRetryable",
|
209
|
+
errors: newErrors
|
210
|
+
});
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
// core/telemetry/assemble-operation-name.ts
|
215
|
+
function assembleOperationName({
|
216
|
+
operationName,
|
217
|
+
telemetry
|
218
|
+
}) {
|
219
|
+
return {
|
220
|
+
"operation.name": `${operationName}${(telemetry == null ? void 0 : telemetry.functionId) != null ? ` ${telemetry.functionId}` : ""}`
|
221
|
+
};
|
222
|
+
}
|
223
|
+
|
110
224
|
// core/telemetry/get-base-telemetry-attributes.ts
|
111
225
|
function getBaseTelemetryAttributes({
|
112
|
-
operationName,
|
113
226
|
model,
|
114
227
|
settings,
|
115
228
|
telemetry,
|
116
229
|
headers
|
117
230
|
}) {
|
118
|
-
var
|
231
|
+
var _a9;
|
119
232
|
return {
|
120
233
|
"ai.model.provider": model.provider,
|
121
234
|
"ai.model.id": model.modelId,
|
@@ -125,11 +238,10 @@ function getBaseTelemetryAttributes({
|
|
125
238
|
return attributes;
|
126
239
|
}, {}),
|
127
240
|
// special telemetry information
|
128
|
-
"operation.name": operationName,
|
129
241
|
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
130
242
|
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
131
243
|
// add metadata as attributes:
|
132
|
-
...Object.entries((
|
244
|
+
...Object.entries((_a9 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a9 : {}).reduce(
|
133
245
|
(attributes, [key, value]) => {
|
134
246
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
135
247
|
return attributes;
|
@@ -154,7 +266,7 @@ var noopTracer = {
|
|
154
266
|
startSpan() {
|
155
267
|
return noopSpan;
|
156
268
|
},
|
157
|
-
startActiveSpan(
|
269
|
+
startActiveSpan(name9, arg1, arg2, arg3) {
|
158
270
|
if (typeof arg1 === "function") {
|
159
271
|
return arg1(noopSpan);
|
160
272
|
}
|
@@ -222,13 +334,13 @@ function getTracer({ isEnabled }) {
|
|
222
334
|
// core/telemetry/record-span.ts
|
223
335
|
var import_api2 = require("@opentelemetry/api");
|
224
336
|
function recordSpan({
|
225
|
-
name,
|
337
|
+
name: name9,
|
226
338
|
tracer,
|
227
339
|
attributes,
|
228
340
|
fn,
|
229
341
|
endWhenDone = true
|
230
342
|
}) {
|
231
|
-
return tracer.startActiveSpan(
|
343
|
+
return tracer.startActiveSpan(name9, { attributes }, async (span) => {
|
232
344
|
try {
|
233
345
|
const result = await fn(span);
|
234
346
|
if (endWhenDone) {
|
@@ -285,68 +397,6 @@ function selectTelemetryAttributes({
|
|
285
397
|
}, {});
|
286
398
|
}
|
287
399
|
|
288
|
-
// core/util/retry-with-exponential-backoff.ts
|
289
|
-
var import_provider = require("@ai-sdk/provider");
|
290
|
-
var import_provider_utils = require("@ai-sdk/provider-utils");
|
291
|
-
|
292
|
-
// core/util/delay.ts
|
293
|
-
async function delay(delayInMs) {
|
294
|
-
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
295
|
-
}
|
296
|
-
|
297
|
-
// core/util/retry-with-exponential-backoff.ts
|
298
|
-
var retryWithExponentialBackoff = ({
|
299
|
-
maxRetries = 2,
|
300
|
-
initialDelayInMs = 2e3,
|
301
|
-
backoffFactor = 2
|
302
|
-
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
303
|
-
maxRetries,
|
304
|
-
delayInMs: initialDelayInMs,
|
305
|
-
backoffFactor
|
306
|
-
});
|
307
|
-
async function _retryWithExponentialBackoff(f, {
|
308
|
-
maxRetries,
|
309
|
-
delayInMs,
|
310
|
-
backoffFactor
|
311
|
-
}, errors = []) {
|
312
|
-
try {
|
313
|
-
return await f();
|
314
|
-
} catch (error) {
|
315
|
-
if ((0, import_provider_utils.isAbortError)(error)) {
|
316
|
-
throw error;
|
317
|
-
}
|
318
|
-
if (maxRetries === 0) {
|
319
|
-
throw error;
|
320
|
-
}
|
321
|
-
const errorMessage = (0, import_provider_utils.getErrorMessage)(error);
|
322
|
-
const newErrors = [...errors, error];
|
323
|
-
const tryNumber = newErrors.length;
|
324
|
-
if (tryNumber > maxRetries) {
|
325
|
-
throw new import_provider.RetryError({
|
326
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
327
|
-
reason: "maxRetriesExceeded",
|
328
|
-
errors: newErrors
|
329
|
-
});
|
330
|
-
}
|
331
|
-
if (error instanceof Error && import_provider.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
332
|
-
await delay(delayInMs);
|
333
|
-
return _retryWithExponentialBackoff(
|
334
|
-
f,
|
335
|
-
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
336
|
-
newErrors
|
337
|
-
);
|
338
|
-
}
|
339
|
-
if (tryNumber === 1) {
|
340
|
-
throw error;
|
341
|
-
}
|
342
|
-
throw new import_provider.RetryError({
|
343
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
344
|
-
reason: "errorNotRetryable",
|
345
|
-
errors: newErrors
|
346
|
-
});
|
347
|
-
}
|
348
|
-
}
|
349
|
-
|
350
400
|
// core/embed/embed.ts
|
351
401
|
async function embed({
|
352
402
|
model,
|
@@ -356,20 +406,20 @@ async function embed({
|
|
356
406
|
headers,
|
357
407
|
experimental_telemetry: telemetry
|
358
408
|
}) {
|
359
|
-
var
|
409
|
+
var _a9;
|
360
410
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
361
|
-
operationName: "ai.embed",
|
362
411
|
model,
|
363
412
|
telemetry,
|
364
413
|
headers,
|
365
414
|
settings: { maxRetries }
|
366
415
|
});
|
367
|
-
const tracer = getTracer({ isEnabled: (
|
416
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
368
417
|
return recordSpan({
|
369
418
|
name: "ai.embed",
|
370
419
|
attributes: selectTelemetryAttributes({
|
371
420
|
telemetry,
|
372
421
|
attributes: {
|
422
|
+
...assembleOperationName({ operationName: "ai.embed", telemetry }),
|
373
423
|
...baseTelemetryAttributes,
|
374
424
|
"ai.value": { input: () => JSON.stringify(value) }
|
375
425
|
}
|
@@ -385,6 +435,10 @@ async function embed({
|
|
385
435
|
attributes: selectTelemetryAttributes({
|
386
436
|
telemetry,
|
387
437
|
attributes: {
|
438
|
+
...assembleOperationName({
|
439
|
+
operationName: "ai.embed.doEmbed",
|
440
|
+
telemetry
|
441
|
+
}),
|
388
442
|
...baseTelemetryAttributes,
|
389
443
|
// specific settings that only make sense on the outer level:
|
390
444
|
"ai.values": { input: () => [JSON.stringify(value)] }
|
@@ -392,14 +446,14 @@ async function embed({
|
|
392
446
|
}),
|
393
447
|
tracer,
|
394
448
|
fn: async (doEmbedSpan) => {
|
395
|
-
var
|
449
|
+
var _a10;
|
396
450
|
const modelResponse = await model.doEmbed({
|
397
451
|
values: [value],
|
398
452
|
abortSignal,
|
399
453
|
headers
|
400
454
|
});
|
401
455
|
const embedding2 = modelResponse.embeddings[0];
|
402
|
-
const usage2 = (
|
456
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
403
457
|
doEmbedSpan.setAttributes(
|
404
458
|
selectTelemetryAttributes({
|
405
459
|
telemetry,
|
@@ -465,20 +519,20 @@ async function embedMany({
|
|
465
519
|
headers,
|
466
520
|
experimental_telemetry: telemetry
|
467
521
|
}) {
|
468
|
-
var
|
522
|
+
var _a9;
|
469
523
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
470
|
-
operationName: "ai.embedMany",
|
471
524
|
model,
|
472
525
|
telemetry,
|
473
526
|
headers,
|
474
527
|
settings: { maxRetries }
|
475
528
|
});
|
476
|
-
const tracer = getTracer({ isEnabled: (
|
529
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
477
530
|
return recordSpan({
|
478
531
|
name: "ai.embedMany",
|
479
532
|
attributes: selectTelemetryAttributes({
|
480
533
|
telemetry,
|
481
534
|
attributes: {
|
535
|
+
...assembleOperationName({ operationName: "ai.embedMany", telemetry }),
|
482
536
|
...baseTelemetryAttributes,
|
483
537
|
// specific settings that only make sense on the outer level:
|
484
538
|
"ai.values": {
|
@@ -497,6 +551,10 @@ async function embedMany({
|
|
497
551
|
attributes: selectTelemetryAttributes({
|
498
552
|
telemetry,
|
499
553
|
attributes: {
|
554
|
+
...assembleOperationName({
|
555
|
+
operationName: "ai.embedMany.doEmbed",
|
556
|
+
telemetry
|
557
|
+
}),
|
500
558
|
...baseTelemetryAttributes,
|
501
559
|
// specific settings that only make sense on the outer level:
|
502
560
|
"ai.values": {
|
@@ -506,14 +564,14 @@ async function embedMany({
|
|
506
564
|
}),
|
507
565
|
tracer,
|
508
566
|
fn: async (doEmbedSpan) => {
|
509
|
-
var
|
567
|
+
var _a10;
|
510
568
|
const modelResponse = await model.doEmbed({
|
511
569
|
values,
|
512
570
|
abortSignal,
|
513
571
|
headers
|
514
572
|
});
|
515
573
|
const embeddings3 = modelResponse.embeddings;
|
516
|
-
const usage2 = (
|
574
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
517
575
|
doEmbedSpan.setAttributes(
|
518
576
|
selectTelemetryAttributes({
|
519
577
|
telemetry,
|
@@ -552,6 +610,10 @@ async function embedMany({
|
|
552
610
|
attributes: selectTelemetryAttributes({
|
553
611
|
telemetry,
|
554
612
|
attributes: {
|
613
|
+
...assembleOperationName({
|
614
|
+
operationName: "ai.embedMany.doEmbed",
|
615
|
+
telemetry
|
616
|
+
}),
|
555
617
|
...baseTelemetryAttributes,
|
556
618
|
// specific settings that only make sense on the outer level:
|
557
619
|
"ai.values": {
|
@@ -561,14 +623,14 @@ async function embedMany({
|
|
561
623
|
}),
|
562
624
|
tracer,
|
563
625
|
fn: async (doEmbedSpan) => {
|
564
|
-
var
|
626
|
+
var _a10;
|
565
627
|
const modelResponse = await model.doEmbed({
|
566
628
|
values: chunk,
|
567
629
|
abortSignal,
|
568
630
|
headers
|
569
631
|
});
|
570
632
|
const embeddings2 = modelResponse.embeddings;
|
571
|
-
const usage2 = (
|
633
|
+
const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
|
572
634
|
doEmbedSpan.setAttributes(
|
573
635
|
selectTelemetryAttributes({
|
574
636
|
telemetry,
|
@@ -615,40 +677,67 @@ var DefaultEmbedManyResult = class {
|
|
615
677
|
};
|
616
678
|
|
617
679
|
// core/generate-object/generate-object.ts
|
618
|
-
var import_provider6 = require("@ai-sdk/provider");
|
619
680
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
620
681
|
|
621
682
|
// core/prompt/convert-to-language-model-prompt.ts
|
622
683
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
623
684
|
|
624
|
-
//
|
625
|
-
var
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
685
|
+
// util/download-error.ts
|
686
|
+
var import_provider3 = require("@ai-sdk/provider");
|
687
|
+
var name2 = "AI_DownloadError";
|
688
|
+
var marker2 = `vercel.ai.error.${name2}`;
|
689
|
+
var symbol2 = Symbol.for(marker2);
|
690
|
+
var _a2;
|
691
|
+
var DownloadError = class extends import_provider3.AISDKError {
|
692
|
+
constructor({
|
693
|
+
url,
|
694
|
+
statusCode,
|
695
|
+
statusText,
|
696
|
+
cause,
|
697
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
698
|
+
}) {
|
699
|
+
super({ name: name2, message, cause });
|
700
|
+
this[_a2] = true;
|
701
|
+
this.url = url;
|
702
|
+
this.statusCode = statusCode;
|
703
|
+
this.statusText = statusText;
|
636
704
|
}
|
637
|
-
|
638
|
-
|
705
|
+
static isInstance(error) {
|
706
|
+
return import_provider3.AISDKError.hasMarker(error, marker2);
|
707
|
+
}
|
708
|
+
/**
|
709
|
+
* @deprecated use `isInstance` instead
|
710
|
+
*/
|
711
|
+
static isDownloadError(error) {
|
712
|
+
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");
|
713
|
+
}
|
714
|
+
/**
|
715
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
716
|
+
*/
|
717
|
+
toJSON() {
|
718
|
+
return {
|
719
|
+
name: this.name,
|
720
|
+
message: this.message,
|
721
|
+
url: this.url,
|
722
|
+
statusCode: this.statusCode,
|
723
|
+
statusText: this.statusText,
|
724
|
+
cause: this.cause
|
725
|
+
};
|
726
|
+
}
|
727
|
+
};
|
728
|
+
_a2 = symbol2;
|
639
729
|
|
640
|
-
//
|
641
|
-
var import_provider2 = require("@ai-sdk/provider");
|
730
|
+
// util/download.ts
|
642
731
|
async function download({
|
643
732
|
url,
|
644
733
|
fetchImplementation = fetch
|
645
734
|
}) {
|
646
|
-
var
|
735
|
+
var _a9;
|
647
736
|
const urlText = url.toString();
|
648
737
|
try {
|
649
738
|
const response = await fetchImplementation(urlText);
|
650
739
|
if (!response.ok) {
|
651
|
-
throw new
|
740
|
+
throw new DownloadError({
|
652
741
|
url: urlText,
|
653
742
|
statusCode: response.status,
|
654
743
|
statusText: response.statusText
|
@@ -656,19 +745,76 @@ async function download({
|
|
656
745
|
}
|
657
746
|
return {
|
658
747
|
data: new Uint8Array(await response.arrayBuffer()),
|
659
|
-
mimeType: (
|
748
|
+
mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
|
660
749
|
};
|
661
750
|
} catch (error) {
|
662
|
-
if (
|
751
|
+
if (DownloadError.isInstance(error)) {
|
663
752
|
throw error;
|
664
753
|
}
|
665
|
-
throw new
|
754
|
+
throw new DownloadError({ url: urlText, cause: error });
|
666
755
|
}
|
667
756
|
}
|
668
757
|
|
758
|
+
// core/util/detect-image-mimetype.ts
|
759
|
+
var mimeTypeSignatures = [
|
760
|
+
{ mimeType: "image/gif", bytes: [71, 73, 70] },
|
761
|
+
{ mimeType: "image/png", bytes: [137, 80, 78, 71] },
|
762
|
+
{ mimeType: "image/jpeg", bytes: [255, 216] },
|
763
|
+
{ mimeType: "image/webp", bytes: [82, 73, 70, 70] }
|
764
|
+
];
|
765
|
+
function detectImageMimeType(image) {
|
766
|
+
for (const { bytes, mimeType } of mimeTypeSignatures) {
|
767
|
+
if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
|
768
|
+
return mimeType;
|
769
|
+
}
|
770
|
+
}
|
771
|
+
return void 0;
|
772
|
+
}
|
773
|
+
|
669
774
|
// core/prompt/data-content.ts
|
670
|
-
var import_provider3 = require("@ai-sdk/provider");
|
671
775
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
776
|
+
|
777
|
+
// core/prompt/invalid-data-content-error.ts
|
778
|
+
var import_provider4 = require("@ai-sdk/provider");
|
779
|
+
var name3 = "AI_InvalidDataContentError";
|
780
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
781
|
+
var symbol3 = Symbol.for(marker3);
|
782
|
+
var _a3;
|
783
|
+
var InvalidDataContentError = class extends import_provider4.AISDKError {
|
784
|
+
constructor({
|
785
|
+
content,
|
786
|
+
cause,
|
787
|
+
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
788
|
+
}) {
|
789
|
+
super({ name: name3, message, cause });
|
790
|
+
this[_a3] = true;
|
791
|
+
this.content = content;
|
792
|
+
}
|
793
|
+
static isInstance(error) {
|
794
|
+
return import_provider4.AISDKError.hasMarker(error, marker3);
|
795
|
+
}
|
796
|
+
/**
|
797
|
+
* @deprecated use `isInstance` instead
|
798
|
+
*/
|
799
|
+
static isInvalidDataContentError(error) {
|
800
|
+
return error instanceof Error && error.name === name3 && error.content != null;
|
801
|
+
}
|
802
|
+
/**
|
803
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
804
|
+
*/
|
805
|
+
toJSON() {
|
806
|
+
return {
|
807
|
+
name: this.name,
|
808
|
+
message: this.message,
|
809
|
+
stack: this.stack,
|
810
|
+
cause: this.cause,
|
811
|
+
content: this.content
|
812
|
+
};
|
813
|
+
}
|
814
|
+
};
|
815
|
+
_a3 = symbol3;
|
816
|
+
|
817
|
+
// core/prompt/data-content.ts
|
672
818
|
function convertDataContentToBase64String(content) {
|
673
819
|
if (typeof content === "string") {
|
674
820
|
return content;
|
@@ -686,7 +832,7 @@ function convertDataContentToUint8Array(content) {
|
|
686
832
|
try {
|
687
833
|
return (0, import_provider_utils2.convertBase64ToUint8Array)(content);
|
688
834
|
} catch (error) {
|
689
|
-
throw new
|
835
|
+
throw new InvalidDataContentError({
|
690
836
|
message: "Invalid data content. Content string is not a base64-encoded media.",
|
691
837
|
content,
|
692
838
|
cause: error
|
@@ -696,7 +842,7 @@ function convertDataContentToUint8Array(content) {
|
|
696
842
|
if (content instanceof ArrayBuffer) {
|
697
843
|
return new Uint8Array(content);
|
698
844
|
}
|
699
|
-
throw new
|
845
|
+
throw new InvalidDataContentError({ content });
|
700
846
|
}
|
701
847
|
function convertUint8ArrayToText(uint8Array) {
|
702
848
|
try {
|
@@ -707,18 +853,32 @@ function convertUint8ArrayToText(uint8Array) {
|
|
707
853
|
}
|
708
854
|
|
709
855
|
// core/prompt/invalid-message-role-error.ts
|
710
|
-
var
|
856
|
+
var import_provider5 = require("@ai-sdk/provider");
|
857
|
+
var name4 = "AI_InvalidMessageRoleError";
|
858
|
+
var marker4 = `vercel.ai.error.${name4}`;
|
859
|
+
var symbol4 = Symbol.for(marker4);
|
860
|
+
var _a4;
|
861
|
+
var InvalidMessageRoleError = class extends import_provider5.AISDKError {
|
711
862
|
constructor({
|
712
863
|
role,
|
713
864
|
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
714
865
|
}) {
|
715
|
-
super(message);
|
716
|
-
this
|
866
|
+
super({ name: name4, message });
|
867
|
+
this[_a4] = true;
|
717
868
|
this.role = role;
|
718
869
|
}
|
870
|
+
static isInstance(error) {
|
871
|
+
return import_provider5.AISDKError.hasMarker(error, marker4);
|
872
|
+
}
|
873
|
+
/**
|
874
|
+
* @deprecated use `isInstance` instead
|
875
|
+
*/
|
719
876
|
static isInvalidMessageRoleError(error) {
|
720
|
-
return error instanceof Error && error.name ===
|
877
|
+
return error instanceof Error && error.name === name4 && typeof error.role === "string";
|
721
878
|
}
|
879
|
+
/**
|
880
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
881
|
+
*/
|
722
882
|
toJSON() {
|
723
883
|
return {
|
724
884
|
name: this.name,
|
@@ -728,6 +888,7 @@ var InvalidMessageRoleError = class extends Error {
|
|
728
888
|
};
|
729
889
|
}
|
730
890
|
};
|
891
|
+
_a4 = symbol4;
|
731
892
|
|
732
893
|
// core/prompt/convert-to-language-model-prompt.ts
|
733
894
|
async function convertToLanguageModelPrompt({
|
@@ -781,7 +942,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
781
942
|
role: "user",
|
782
943
|
content: message.content.map(
|
783
944
|
(part) => {
|
784
|
-
var
|
945
|
+
var _a9, _b, _c;
|
785
946
|
switch (part.type) {
|
786
947
|
case "text": {
|
787
948
|
return part;
|
@@ -799,7 +960,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
799
960
|
return {
|
800
961
|
type: "image",
|
801
962
|
image: downloadedImage.data,
|
802
|
-
mimeType: (
|
963
|
+
mimeType: (_a9 = part.mimeType) != null ? _a9 : downloadedImage.mimeType
|
803
964
|
};
|
804
965
|
}
|
805
966
|
}
|
@@ -910,16 +1071,16 @@ async function downloadImages(messages, downloadImplementation) {
|
|
910
1071
|
}
|
911
1072
|
|
912
1073
|
// core/prompt/get-validated-prompt.ts
|
913
|
-
var
|
1074
|
+
var import_provider6 = require("@ai-sdk/provider");
|
914
1075
|
function getValidatedPrompt(prompt) {
|
915
1076
|
if (prompt.prompt == null && prompt.messages == null) {
|
916
|
-
throw new
|
1077
|
+
throw new import_provider6.InvalidPromptError({
|
917
1078
|
prompt,
|
918
1079
|
message: "prompt or messages must be defined"
|
919
1080
|
});
|
920
1081
|
}
|
921
1082
|
if (prompt.prompt != null && prompt.messages != null) {
|
922
|
-
throw new
|
1083
|
+
throw new import_provider6.InvalidPromptError({
|
923
1084
|
prompt,
|
924
1085
|
message: "prompt and messages cannot be defined at the same time"
|
925
1086
|
});
|
@@ -927,7 +1088,7 @@ function getValidatedPrompt(prompt) {
|
|
927
1088
|
if (prompt.messages != null) {
|
928
1089
|
for (const message of prompt.messages) {
|
929
1090
|
if (message.role === "system" && typeof message.content !== "string") {
|
930
|
-
throw new
|
1091
|
+
throw new import_provider6.InvalidPromptError({
|
931
1092
|
prompt,
|
932
1093
|
message: "system message content must be a string"
|
933
1094
|
});
|
@@ -948,8 +1109,48 @@ function getValidatedPrompt(prompt) {
|
|
948
1109
|
};
|
949
1110
|
}
|
950
1111
|
|
1112
|
+
// errors/invalid-argument-error.ts
|
1113
|
+
var import_provider7 = require("@ai-sdk/provider");
|
1114
|
+
var name5 = "AI_InvalidArgumentError";
|
1115
|
+
var marker5 = `vercel.ai.error.${name5}`;
|
1116
|
+
var symbol5 = Symbol.for(marker5);
|
1117
|
+
var _a5;
|
1118
|
+
var InvalidArgumentError = class extends import_provider7.AISDKError {
|
1119
|
+
constructor({
|
1120
|
+
parameter,
|
1121
|
+
value,
|
1122
|
+
message
|
1123
|
+
}) {
|
1124
|
+
super({
|
1125
|
+
name: name5,
|
1126
|
+
message: `Invalid argument for parameter ${parameter}: ${message}`
|
1127
|
+
});
|
1128
|
+
this[_a5] = true;
|
1129
|
+
this.parameter = parameter;
|
1130
|
+
this.value = value;
|
1131
|
+
}
|
1132
|
+
static isInstance(error) {
|
1133
|
+
return import_provider7.AISDKError.hasMarker(error, marker5);
|
1134
|
+
}
|
1135
|
+
/**
|
1136
|
+
* @deprecated use `isInstance` instead
|
1137
|
+
*/
|
1138
|
+
static isInvalidArgumentError(error) {
|
1139
|
+
return error instanceof Error && error.name === name5 && typeof error.parameter === "string" && typeof error.value === "string";
|
1140
|
+
}
|
1141
|
+
toJSON() {
|
1142
|
+
return {
|
1143
|
+
name: this.name,
|
1144
|
+
message: this.message,
|
1145
|
+
stack: this.stack,
|
1146
|
+
parameter: this.parameter,
|
1147
|
+
value: this.value
|
1148
|
+
};
|
1149
|
+
}
|
1150
|
+
};
|
1151
|
+
_a5 = symbol5;
|
1152
|
+
|
951
1153
|
// core/prompt/prepare-call-settings.ts
|
952
|
-
var import_provider5 = require("@ai-sdk/provider");
|
953
1154
|
function prepareCallSettings({
|
954
1155
|
maxTokens,
|
955
1156
|
temperature,
|
@@ -962,14 +1163,14 @@ function prepareCallSettings({
|
|
962
1163
|
}) {
|
963
1164
|
if (maxTokens != null) {
|
964
1165
|
if (!Number.isInteger(maxTokens)) {
|
965
|
-
throw new
|
1166
|
+
throw new InvalidArgumentError({
|
966
1167
|
parameter: "maxTokens",
|
967
1168
|
value: maxTokens,
|
968
1169
|
message: "maxTokens must be an integer"
|
969
1170
|
});
|
970
1171
|
}
|
971
1172
|
if (maxTokens < 1) {
|
972
|
-
throw new
|
1173
|
+
throw new InvalidArgumentError({
|
973
1174
|
parameter: "maxTokens",
|
974
1175
|
value: maxTokens,
|
975
1176
|
message: "maxTokens must be >= 1"
|
@@ -978,7 +1179,7 @@ function prepareCallSettings({
|
|
978
1179
|
}
|
979
1180
|
if (temperature != null) {
|
980
1181
|
if (typeof temperature !== "number") {
|
981
|
-
throw new
|
1182
|
+
throw new InvalidArgumentError({
|
982
1183
|
parameter: "temperature",
|
983
1184
|
value: temperature,
|
984
1185
|
message: "temperature must be a number"
|
@@ -987,7 +1188,7 @@ function prepareCallSettings({
|
|
987
1188
|
}
|
988
1189
|
if (topP != null) {
|
989
1190
|
if (typeof topP !== "number") {
|
990
|
-
throw new
|
1191
|
+
throw new InvalidArgumentError({
|
991
1192
|
parameter: "topP",
|
992
1193
|
value: topP,
|
993
1194
|
message: "topP must be a number"
|
@@ -996,7 +1197,7 @@ function prepareCallSettings({
|
|
996
1197
|
}
|
997
1198
|
if (presencePenalty != null) {
|
998
1199
|
if (typeof presencePenalty !== "number") {
|
999
|
-
throw new
|
1200
|
+
throw new InvalidArgumentError({
|
1000
1201
|
parameter: "presencePenalty",
|
1001
1202
|
value: presencePenalty,
|
1002
1203
|
message: "presencePenalty must be a number"
|
@@ -1005,7 +1206,7 @@ function prepareCallSettings({
|
|
1005
1206
|
}
|
1006
1207
|
if (frequencyPenalty != null) {
|
1007
1208
|
if (typeof frequencyPenalty !== "number") {
|
1008
|
-
throw new
|
1209
|
+
throw new InvalidArgumentError({
|
1009
1210
|
parameter: "frequencyPenalty",
|
1010
1211
|
value: frequencyPenalty,
|
1011
1212
|
message: "frequencyPenalty must be a number"
|
@@ -1014,7 +1215,7 @@ function prepareCallSettings({
|
|
1014
1215
|
}
|
1015
1216
|
if (seed != null) {
|
1016
1217
|
if (!Number.isInteger(seed)) {
|
1017
|
-
throw new
|
1218
|
+
throw new InvalidArgumentError({
|
1018
1219
|
parameter: "seed",
|
1019
1220
|
value: seed,
|
1020
1221
|
message: "seed must be an integer"
|
@@ -1023,14 +1224,14 @@ function prepareCallSettings({
|
|
1023
1224
|
}
|
1024
1225
|
if (maxRetries != null) {
|
1025
1226
|
if (!Number.isInteger(maxRetries)) {
|
1026
|
-
throw new
|
1227
|
+
throw new InvalidArgumentError({
|
1027
1228
|
parameter: "maxRetries",
|
1028
1229
|
value: maxRetries,
|
1029
1230
|
message: "maxRetries must be an integer"
|
1030
1231
|
});
|
1031
1232
|
}
|
1032
1233
|
if (maxRetries < 0) {
|
1033
|
-
throw new
|
1234
|
+
throw new InvalidArgumentError({
|
1034
1235
|
parameter: "maxRetries",
|
1035
1236
|
value: maxRetries,
|
1036
1237
|
message: "maxRetries must be >= 0"
|
@@ -1063,8 +1264,8 @@ function prepareResponseHeaders(init, {
|
|
1063
1264
|
contentType,
|
1064
1265
|
dataStreamVersion
|
1065
1266
|
}) {
|
1066
|
-
var
|
1067
|
-
const headers = new Headers((
|
1267
|
+
var _a9;
|
1268
|
+
const headers = new Headers((_a9 = init == null ? void 0 : init.headers) != null ? _a9 : {});
|
1068
1269
|
if (!headers.has("Content-Type")) {
|
1069
1270
|
headers.set("Content-Type", contentType);
|
1070
1271
|
}
|
@@ -1077,7 +1278,7 @@ function prepareResponseHeaders(init, {
|
|
1077
1278
|
// core/util/schema.ts
|
1078
1279
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
1079
1280
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
|
1080
|
-
var schemaSymbol = Symbol("vercel.ai.schema");
|
1281
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
1081
1282
|
function jsonSchema(jsonSchema2, {
|
1082
1283
|
validate
|
1083
1284
|
} = {}) {
|
@@ -1128,6 +1329,41 @@ function injectJsonSchemaIntoSystem({
|
|
1128
1329
|
].filter((line) => line != null).join("\n");
|
1129
1330
|
}
|
1130
1331
|
|
1332
|
+
// core/generate-object/no-object-generated-error.ts
|
1333
|
+
var import_provider8 = require("@ai-sdk/provider");
|
1334
|
+
var name6 = "AI_NoObjectGeneratedError";
|
1335
|
+
var marker6 = `vercel.ai.error.${name6}`;
|
1336
|
+
var symbol6 = Symbol.for(marker6);
|
1337
|
+
var _a6;
|
1338
|
+
var NoObjectGeneratedError = class extends import_provider8.AISDKError {
|
1339
|
+
// used in isInstance
|
1340
|
+
constructor({ message = "No object generated." } = {}) {
|
1341
|
+
super({ name: name6, message });
|
1342
|
+
this[_a6] = true;
|
1343
|
+
}
|
1344
|
+
static isInstance(error) {
|
1345
|
+
return import_provider8.AISDKError.hasMarker(error, marker6);
|
1346
|
+
}
|
1347
|
+
/**
|
1348
|
+
* @deprecated Use isInstance instead.
|
1349
|
+
*/
|
1350
|
+
static isNoObjectGeneratedError(error) {
|
1351
|
+
return error instanceof Error && error.name === name6;
|
1352
|
+
}
|
1353
|
+
/**
|
1354
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
1355
|
+
*/
|
1356
|
+
toJSON() {
|
1357
|
+
return {
|
1358
|
+
name: this.name,
|
1359
|
+
cause: this.cause,
|
1360
|
+
message: this.message,
|
1361
|
+
stack: this.stack
|
1362
|
+
};
|
1363
|
+
}
|
1364
|
+
};
|
1365
|
+
_a6 = symbol6;
|
1366
|
+
|
1131
1367
|
// core/generate-object/generate-object.ts
|
1132
1368
|
async function generateObject({
|
1133
1369
|
model,
|
@@ -1142,21 +1378,24 @@ async function generateObject({
|
|
1142
1378
|
experimental_telemetry: telemetry,
|
1143
1379
|
...settings
|
1144
1380
|
}) {
|
1145
|
-
var
|
1381
|
+
var _a9;
|
1146
1382
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1147
|
-
operationName: "ai.generateObject",
|
1148
1383
|
model,
|
1149
1384
|
telemetry,
|
1150
1385
|
headers,
|
1151
1386
|
settings: { ...settings, maxRetries }
|
1152
1387
|
});
|
1153
1388
|
const schema = asSchema(inputSchema);
|
1154
|
-
const tracer = getTracer({ isEnabled: (
|
1389
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1155
1390
|
return recordSpan({
|
1156
1391
|
name: "ai.generateObject",
|
1157
1392
|
attributes: selectTelemetryAttributes({
|
1158
1393
|
telemetry,
|
1159
1394
|
attributes: {
|
1395
|
+
...assembleOperationName({
|
1396
|
+
operationName: "ai.generateObject",
|
1397
|
+
telemetry
|
1398
|
+
}),
|
1160
1399
|
...baseTelemetryAttributes,
|
1161
1400
|
// specific settings that only make sense on the outer level:
|
1162
1401
|
"ai.prompt": {
|
@@ -1201,6 +1440,10 @@ async function generateObject({
|
|
1201
1440
|
attributes: selectTelemetryAttributes({
|
1202
1441
|
telemetry,
|
1203
1442
|
attributes: {
|
1443
|
+
...assembleOperationName({
|
1444
|
+
operationName: "ai.generateObject.doGenerate",
|
1445
|
+
telemetry
|
1446
|
+
}),
|
1204
1447
|
...baseTelemetryAttributes,
|
1205
1448
|
"ai.prompt.format": {
|
1206
1449
|
input: () => inputFormat
|
@@ -1228,7 +1471,7 @@ async function generateObject({
|
|
1228
1471
|
headers
|
1229
1472
|
});
|
1230
1473
|
if (result2.text === void 0) {
|
1231
|
-
throw new
|
1474
|
+
throw new NoObjectGeneratedError();
|
1232
1475
|
}
|
1233
1476
|
span2.setAttributes(
|
1234
1477
|
selectTelemetryAttributes({
|
@@ -1274,6 +1517,10 @@ async function generateObject({
|
|
1274
1517
|
attributes: selectTelemetryAttributes({
|
1275
1518
|
telemetry,
|
1276
1519
|
attributes: {
|
1520
|
+
...assembleOperationName({
|
1521
|
+
operationName: "ai.generateObject.doGenerate",
|
1522
|
+
telemetry
|
1523
|
+
}),
|
1277
1524
|
...baseTelemetryAttributes,
|
1278
1525
|
"ai.prompt.format": {
|
1279
1526
|
input: () => inputFormat
|
@@ -1292,7 +1539,7 @@ async function generateObject({
|
|
1292
1539
|
}),
|
1293
1540
|
tracer,
|
1294
1541
|
fn: async (span2) => {
|
1295
|
-
var
|
1542
|
+
var _a10, _b;
|
1296
1543
|
const result2 = await model.doGenerate({
|
1297
1544
|
mode: {
|
1298
1545
|
type: "object-tool",
|
@@ -1309,9 +1556,9 @@ async function generateObject({
|
|
1309
1556
|
abortSignal,
|
1310
1557
|
headers
|
1311
1558
|
});
|
1312
|
-
const objectText = (_b = (
|
1559
|
+
const objectText = (_b = (_a10 = result2.toolCalls) == null ? void 0 : _a10[0]) == null ? void 0 : _b.args;
|
1313
1560
|
if (objectText === void 0) {
|
1314
|
-
throw new
|
1561
|
+
throw new NoObjectGeneratedError();
|
1315
1562
|
}
|
1316
1563
|
span2.setAttributes(
|
1317
1564
|
selectTelemetryAttributes({
|
@@ -1388,9 +1635,9 @@ var DefaultGenerateObjectResult = class {
|
|
1388
1635
|
this.logprobs = options.logprobs;
|
1389
1636
|
}
|
1390
1637
|
toJsonResponse(init) {
|
1391
|
-
var
|
1638
|
+
var _a9;
|
1392
1639
|
return new Response(JSON.stringify(this.object), {
|
1393
|
-
status: (
|
1640
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
1394
1641
|
headers: prepareResponseHeaders(init, {
|
1395
1642
|
contentType: "application/json; charset=utf-8"
|
1396
1643
|
})
|
@@ -1403,24 +1650,22 @@ var experimental_generateObject = generateObject;
|
|
1403
1650
|
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
1404
1651
|
var import_ui_utils = require("@ai-sdk/ui-utils");
|
1405
1652
|
|
1406
|
-
//
|
1407
|
-
function
|
1408
|
-
|
1409
|
-
|
1410
|
-
)
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
};
|
1653
|
+
// util/create-resolvable-promise.ts
|
1654
|
+
function createResolvablePromise() {
|
1655
|
+
let resolve;
|
1656
|
+
let reject;
|
1657
|
+
const promise = new Promise((res, rej) => {
|
1658
|
+
resolve = res;
|
1659
|
+
reject = rej;
|
1660
|
+
});
|
1661
|
+
return {
|
1662
|
+
promise,
|
1663
|
+
resolve,
|
1664
|
+
reject
|
1419
1665
|
};
|
1420
|
-
return transformedStream;
|
1421
1666
|
}
|
1422
1667
|
|
1423
|
-
//
|
1668
|
+
// util/delayed-promise.ts
|
1424
1669
|
var DelayedPromise = class {
|
1425
1670
|
constructor() {
|
1426
1671
|
this.status = { type: "pending" };
|
@@ -1443,21 +1688,38 @@ var DelayedPromise = class {
|
|
1443
1688
|
return this.promise;
|
1444
1689
|
}
|
1445
1690
|
resolve(value) {
|
1446
|
-
var
|
1691
|
+
var _a9;
|
1447
1692
|
this.status = { type: "resolved", value };
|
1448
1693
|
if (this.promise) {
|
1449
|
-
(
|
1694
|
+
(_a9 = this._resolve) == null ? void 0 : _a9.call(this, value);
|
1450
1695
|
}
|
1451
1696
|
}
|
1452
1697
|
reject(error) {
|
1453
|
-
var
|
1698
|
+
var _a9;
|
1454
1699
|
this.status = { type: "rejected", error };
|
1455
1700
|
if (this.promise) {
|
1456
|
-
(
|
1701
|
+
(_a9 = this._reject) == null ? void 0 : _a9.call(this, error);
|
1457
1702
|
}
|
1458
1703
|
}
|
1459
1704
|
};
|
1460
1705
|
|
1706
|
+
// core/util/async-iterable-stream.ts
|
1707
|
+
function createAsyncIterableStream(source, transformer) {
|
1708
|
+
const transformedStream = source.pipeThrough(
|
1709
|
+
new TransformStream(transformer)
|
1710
|
+
);
|
1711
|
+
transformedStream[Symbol.asyncIterator] = () => {
|
1712
|
+
const reader = transformedStream.getReader();
|
1713
|
+
return {
|
1714
|
+
async next() {
|
1715
|
+
const { done, value } = await reader.read();
|
1716
|
+
return done ? { done: true, value: void 0 } : { done: false, value };
|
1717
|
+
}
|
1718
|
+
};
|
1719
|
+
};
|
1720
|
+
return transformedStream;
|
1721
|
+
}
|
1722
|
+
|
1461
1723
|
// core/generate-object/stream-object.ts
|
1462
1724
|
async function streamObject({
|
1463
1725
|
model,
|
@@ -1473,15 +1735,14 @@ async function streamObject({
|
|
1473
1735
|
onFinish,
|
1474
1736
|
...settings
|
1475
1737
|
}) {
|
1476
|
-
var
|
1738
|
+
var _a9;
|
1477
1739
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1478
|
-
operationName: "ai.streamObject",
|
1479
1740
|
model,
|
1480
1741
|
telemetry,
|
1481
1742
|
headers,
|
1482
1743
|
settings: { ...settings, maxRetries }
|
1483
1744
|
});
|
1484
|
-
const tracer = getTracer({ isEnabled: (
|
1745
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1485
1746
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1486
1747
|
const schema = asSchema(inputSchema);
|
1487
1748
|
return recordSpan({
|
@@ -1489,6 +1750,10 @@ async function streamObject({
|
|
1489
1750
|
attributes: selectTelemetryAttributes({
|
1490
1751
|
telemetry,
|
1491
1752
|
attributes: {
|
1753
|
+
...assembleOperationName({
|
1754
|
+
operationName: "ai.streamObject",
|
1755
|
+
telemetry
|
1756
|
+
}),
|
1492
1757
|
...baseTelemetryAttributes,
|
1493
1758
|
// specific settings that only make sense on the outer level:
|
1494
1759
|
"ai.prompt": {
|
@@ -1601,6 +1866,10 @@ async function streamObject({
|
|
1601
1866
|
attributes: selectTelemetryAttributes({
|
1602
1867
|
telemetry,
|
1603
1868
|
attributes: {
|
1869
|
+
...assembleOperationName({
|
1870
|
+
operationName: "ai.streamObject.doStream",
|
1871
|
+
telemetry
|
1872
|
+
}),
|
1604
1873
|
...baseTelemetryAttributes,
|
1605
1874
|
"ai.prompt.format": {
|
1606
1875
|
input: () => callOptions.inputFormat
|
@@ -1652,10 +1921,8 @@ var DefaultStreamObjectResult = class {
|
|
1652
1921
|
this.warnings = warnings;
|
1653
1922
|
this.rawResponse = rawResponse;
|
1654
1923
|
this.objectPromise = new DelayedPromise();
|
1655
|
-
|
1656
|
-
this.usage =
|
1657
|
-
resolveUsage = resolve;
|
1658
|
-
});
|
1924
|
+
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
1925
|
+
this.usage = usagePromise;
|
1659
1926
|
let usage;
|
1660
1927
|
let finishReason;
|
1661
1928
|
let object;
|
@@ -1830,8 +2097,8 @@ var DefaultStreamObjectResult = class {
|
|
1830
2097
|
});
|
1831
2098
|
}
|
1832
2099
|
pipeTextStreamToResponse(response, init) {
|
1833
|
-
var
|
1834
|
-
response.writeHead((
|
2100
|
+
var _a9;
|
2101
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
1835
2102
|
"Content-Type": "text/plain; charset=utf-8",
|
1836
2103
|
...init == null ? void 0 : init.headers
|
1837
2104
|
});
|
@@ -1853,9 +2120,9 @@ var DefaultStreamObjectResult = class {
|
|
1853
2120
|
read();
|
1854
2121
|
}
|
1855
2122
|
toTextStreamResponse(init) {
|
1856
|
-
var
|
2123
|
+
var _a9;
|
1857
2124
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
1858
|
-
status: (
|
2125
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
1859
2126
|
headers: prepareResponseHeaders(init, {
|
1860
2127
|
contentType: "text/plain; charset=utf-8"
|
1861
2128
|
})
|
@@ -1881,9 +2148,9 @@ function prepareToolsAndToolChoice({
|
|
1881
2148
|
};
|
1882
2149
|
}
|
1883
2150
|
return {
|
1884
|
-
tools: Object.entries(tools).map(([
|
2151
|
+
tools: Object.entries(tools).map(([name9, tool2]) => ({
|
1885
2152
|
type: "function",
|
1886
|
-
name,
|
2153
|
+
name: name9,
|
1887
2154
|
description: tool2.description,
|
1888
2155
|
parameters: asSchema(tool2.parameters).jsonSchema
|
1889
2156
|
})),
|
@@ -1892,19 +2159,106 @@ function prepareToolsAndToolChoice({
|
|
1892
2159
|
}
|
1893
2160
|
|
1894
2161
|
// core/generate-text/tool-call.ts
|
1895
|
-
var import_provider7 = require("@ai-sdk/provider");
|
1896
2162
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
2163
|
+
|
2164
|
+
// errors/invalid-tool-arguments-error.ts
|
2165
|
+
var import_provider9 = require("@ai-sdk/provider");
|
2166
|
+
var name7 = "AI_InvalidToolArgumentsError";
|
2167
|
+
var marker7 = `vercel.ai.error.${name7}`;
|
2168
|
+
var symbol7 = Symbol.for(marker7);
|
2169
|
+
var _a7;
|
2170
|
+
var InvalidToolArgumentsError = class extends import_provider9.AISDKError {
|
2171
|
+
constructor({
|
2172
|
+
toolArgs,
|
2173
|
+
toolName,
|
2174
|
+
cause,
|
2175
|
+
message = `Invalid arguments for tool ${toolName}: ${(0, import_provider9.getErrorMessage)(
|
2176
|
+
cause
|
2177
|
+
)}`
|
2178
|
+
}) {
|
2179
|
+
super({ name: name7, message, cause });
|
2180
|
+
this[_a7] = true;
|
2181
|
+
this.toolArgs = toolArgs;
|
2182
|
+
this.toolName = toolName;
|
2183
|
+
}
|
2184
|
+
static isInstance(error) {
|
2185
|
+
return import_provider9.AISDKError.hasMarker(error, marker7);
|
2186
|
+
}
|
2187
|
+
/**
|
2188
|
+
* @deprecated use `isInstance` instead
|
2189
|
+
*/
|
2190
|
+
static isInvalidToolArgumentsError(error) {
|
2191
|
+
return error instanceof Error && error.name === name7 && typeof error.toolName === "string" && typeof error.toolArgs === "string";
|
2192
|
+
}
|
2193
|
+
/**
|
2194
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
2195
|
+
*/
|
2196
|
+
toJSON() {
|
2197
|
+
return {
|
2198
|
+
name: this.name,
|
2199
|
+
message: this.message,
|
2200
|
+
cause: this.cause,
|
2201
|
+
stack: this.stack,
|
2202
|
+
toolName: this.toolName,
|
2203
|
+
toolArgs: this.toolArgs
|
2204
|
+
};
|
2205
|
+
}
|
2206
|
+
};
|
2207
|
+
_a7 = symbol7;
|
2208
|
+
|
2209
|
+
// errors/no-such-tool-error.ts
|
2210
|
+
var import_provider10 = require("@ai-sdk/provider");
|
2211
|
+
var name8 = "AI_NoSuchToolError";
|
2212
|
+
var marker8 = `vercel.ai.error.${name8}`;
|
2213
|
+
var symbol8 = Symbol.for(marker8);
|
2214
|
+
var _a8;
|
2215
|
+
var NoSuchToolError = class extends import_provider10.AISDKError {
|
2216
|
+
constructor({
|
2217
|
+
toolName,
|
2218
|
+
availableTools = void 0,
|
2219
|
+
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
2220
|
+
}) {
|
2221
|
+
super({ name: name8, message });
|
2222
|
+
this[_a8] = true;
|
2223
|
+
this.toolName = toolName;
|
2224
|
+
this.availableTools = availableTools;
|
2225
|
+
}
|
2226
|
+
static isInstance(error) {
|
2227
|
+
return import_provider10.AISDKError.hasMarker(error, marker8);
|
2228
|
+
}
|
2229
|
+
/**
|
2230
|
+
* @deprecated use `isInstance` instead
|
2231
|
+
*/
|
2232
|
+
static isNoSuchToolError(error) {
|
2233
|
+
return error instanceof Error && error.name === name8 && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
|
2234
|
+
}
|
2235
|
+
/**
|
2236
|
+
* @deprecated Do not use this method. It will be removed in the next major version.
|
2237
|
+
*/
|
2238
|
+
toJSON() {
|
2239
|
+
return {
|
2240
|
+
name: this.name,
|
2241
|
+
message: this.message,
|
2242
|
+
stack: this.stack,
|
2243
|
+
toolName: this.toolName,
|
2244
|
+
availableTools: this.availableTools
|
2245
|
+
};
|
2246
|
+
}
|
2247
|
+
};
|
2248
|
+
_a8 = symbol8;
|
2249
|
+
|
2250
|
+
// core/generate-text/tool-call.ts
|
1897
2251
|
function parseToolCall({
|
1898
2252
|
toolCall,
|
1899
2253
|
tools
|
1900
2254
|
}) {
|
1901
2255
|
const toolName = toolCall.toolName;
|
1902
2256
|
if (tools == null) {
|
1903
|
-
throw new
|
2257
|
+
throw new NoSuchToolError({ toolName: toolCall.toolName });
|
1904
2258
|
}
|
1905
2259
|
const tool2 = tools[toolName];
|
1906
2260
|
if (tool2 == null) {
|
1907
|
-
throw new
|
2261
|
+
throw new NoSuchToolError({
|
1908
2262
|
toolName: toolCall.toolName,
|
1909
2263
|
availableTools: Object.keys(tools)
|
1910
2264
|
});
|
@@ -1914,7 +2268,7 @@ function parseToolCall({
|
|
1914
2268
|
schema: asSchema(tool2.parameters)
|
1915
2269
|
});
|
1916
2270
|
if (parseResult.success === false) {
|
1917
|
-
throw new
|
2271
|
+
throw new InvalidToolArgumentsError({
|
1918
2272
|
toolName,
|
1919
2273
|
toolArgs: toolCall.args,
|
1920
2274
|
cause: parseResult.error
|
@@ -1944,20 +2298,23 @@ async function generateText({
|
|
1944
2298
|
experimental_telemetry: telemetry,
|
1945
2299
|
...settings
|
1946
2300
|
}) {
|
1947
|
-
var
|
2301
|
+
var _a9;
|
1948
2302
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
1949
|
-
operationName: "ai.generateText",
|
1950
2303
|
model,
|
1951
2304
|
telemetry,
|
1952
2305
|
headers,
|
1953
2306
|
settings: { ...settings, maxRetries }
|
1954
2307
|
});
|
1955
|
-
const tracer = getTracer({ isEnabled: (
|
2308
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
1956
2309
|
return recordSpan({
|
1957
2310
|
name: "ai.generateText",
|
1958
2311
|
attributes: selectTelemetryAttributes({
|
1959
2312
|
telemetry,
|
1960
2313
|
attributes: {
|
2314
|
+
...assembleOperationName({
|
2315
|
+
operationName: "ai.generateText",
|
2316
|
+
telemetry
|
2317
|
+
}),
|
1961
2318
|
...baseTelemetryAttributes,
|
1962
2319
|
// specific settings that only make sense on the outer level:
|
1963
2320
|
"ai.prompt": {
|
@@ -1968,7 +2325,7 @@ async function generateText({
|
|
1968
2325
|
}),
|
1969
2326
|
tracer,
|
1970
2327
|
fn: async (span) => {
|
1971
|
-
var
|
2328
|
+
var _a10, _b, _c, _d;
|
1972
2329
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
1973
2330
|
const validatedPrompt = getValidatedPrompt({
|
1974
2331
|
system,
|
@@ -2003,6 +2360,10 @@ async function generateText({
|
|
2003
2360
|
attributes: selectTelemetryAttributes({
|
2004
2361
|
telemetry,
|
2005
2362
|
attributes: {
|
2363
|
+
...assembleOperationName({
|
2364
|
+
operationName: "ai.generateText.doGenerate",
|
2365
|
+
telemetry
|
2366
|
+
}),
|
2006
2367
|
...baseTelemetryAttributes,
|
2007
2368
|
"ai.prompt.format": { input: () => currentInputFormat },
|
2008
2369
|
"ai.prompt.messages": {
|
@@ -2050,7 +2411,7 @@ async function generateText({
|
|
2050
2411
|
}
|
2051
2412
|
})
|
2052
2413
|
);
|
2053
|
-
currentToolCalls = ((
|
2414
|
+
currentToolCalls = ((_a10 = currentModelResponse.toolCalls) != null ? _a10 : []).map(
|
2054
2415
|
(modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
|
2055
2416
|
);
|
2056
2417
|
currentToolResults = tools == null ? [] : await executeTools({
|
@@ -2142,6 +2503,10 @@ async function executeTools({
|
|
2142
2503
|
attributes: selectTelemetryAttributes({
|
2143
2504
|
telemetry,
|
2144
2505
|
attributes: {
|
2506
|
+
...assembleOperationName({
|
2507
|
+
operationName: "ai.toolCall",
|
2508
|
+
telemetry
|
2509
|
+
}),
|
2145
2510
|
"ai.toolCall.name": toolCall.toolName,
|
2146
2511
|
"ai.toolCall.id": toolCall.toolCallId,
|
2147
2512
|
"ai.toolCall.args": {
|
@@ -2308,7 +2673,6 @@ function mergeStreams(stream1, stream2) {
|
|
2308
2673
|
}
|
2309
2674
|
|
2310
2675
|
// core/generate-text/run-tools-transformation.ts
|
2311
|
-
var import_provider8 = require("@ai-sdk/provider");
|
2312
2676
|
var import_ui_utils2 = require("@ai-sdk/ui-utils");
|
2313
2677
|
function runToolsTransformation({
|
2314
2678
|
tools,
|
@@ -2359,7 +2723,7 @@ function runToolsTransformation({
|
|
2359
2723
|
if (tools == null) {
|
2360
2724
|
toolResultsStreamController.enqueue({
|
2361
2725
|
type: "error",
|
2362
|
-
error: new
|
2726
|
+
error: new NoSuchToolError({ toolName: chunk.toolName })
|
2363
2727
|
});
|
2364
2728
|
break;
|
2365
2729
|
}
|
@@ -2367,7 +2731,7 @@ function runToolsTransformation({
|
|
2367
2731
|
if (tool2 == null) {
|
2368
2732
|
toolResultsStreamController.enqueue({
|
2369
2733
|
type: "error",
|
2370
|
-
error: new
|
2734
|
+
error: new NoSuchToolError({
|
2371
2735
|
toolName: chunk.toolName,
|
2372
2736
|
availableTools: Object.keys(tools)
|
2373
2737
|
})
|
@@ -2388,6 +2752,10 @@ function runToolsTransformation({
|
|
2388
2752
|
attributes: selectTelemetryAttributes({
|
2389
2753
|
telemetry,
|
2390
2754
|
attributes: {
|
2755
|
+
...assembleOperationName({
|
2756
|
+
operationName: "ai.toolCall",
|
2757
|
+
telemetry
|
2758
|
+
}),
|
2391
2759
|
"ai.toolCall.name": toolCall.toolName,
|
2392
2760
|
"ai.toolCall.id": toolCall.toolCallId,
|
2393
2761
|
"ai.toolCall.args": {
|
@@ -2507,20 +2875,20 @@ async function streamText({
|
|
2507
2875
|
onFinish,
|
2508
2876
|
...settings
|
2509
2877
|
}) {
|
2510
|
-
var
|
2878
|
+
var _a9;
|
2511
2879
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
2512
|
-
operationName: "ai.streamText",
|
2513
2880
|
model,
|
2514
2881
|
telemetry,
|
2515
2882
|
headers,
|
2516
2883
|
settings: { ...settings, maxRetries }
|
2517
2884
|
});
|
2518
|
-
const tracer = getTracer({ isEnabled: (
|
2885
|
+
const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
|
2519
2886
|
return recordSpan({
|
2520
2887
|
name: "ai.streamText",
|
2521
2888
|
attributes: selectTelemetryAttributes({
|
2522
2889
|
telemetry,
|
2523
2890
|
attributes: {
|
2891
|
+
...assembleOperationName({ operationName: "ai.streamText", telemetry }),
|
2524
2892
|
...baseTelemetryAttributes,
|
2525
2893
|
// specific settings that only make sense on the outer level:
|
2526
2894
|
"ai.prompt": {
|
@@ -2546,6 +2914,10 @@ async function streamText({
|
|
2546
2914
|
attributes: selectTelemetryAttributes({
|
2547
2915
|
telemetry,
|
2548
2916
|
attributes: {
|
2917
|
+
...assembleOperationName({
|
2918
|
+
operationName: "ai.streamText.doStream",
|
2919
|
+
telemetry
|
2920
|
+
}),
|
2549
2921
|
...baseTelemetryAttributes,
|
2550
2922
|
"ai.prompt.format": {
|
2551
2923
|
input: () => validatedPrompt.type
|
@@ -2612,26 +2984,16 @@ var DefaultStreamTextResult = class {
|
|
2612
2984
|
this.warnings = warnings;
|
2613
2985
|
this.rawResponse = rawResponse;
|
2614
2986
|
this.onFinish = onFinish;
|
2615
|
-
|
2616
|
-
this.usage =
|
2617
|
-
|
2618
|
-
|
2619
|
-
|
2620
|
-
this.
|
2621
|
-
|
2622
|
-
|
2623
|
-
|
2624
|
-
this.
|
2625
|
-
resolveText = resolve;
|
2626
|
-
});
|
2627
|
-
let resolveToolCalls;
|
2628
|
-
this.toolCalls = new Promise((resolve) => {
|
2629
|
-
resolveToolCalls = resolve;
|
2630
|
-
});
|
2631
|
-
let resolveToolResults;
|
2632
|
-
this.toolResults = new Promise((resolve) => {
|
2633
|
-
resolveToolResults = resolve;
|
2634
|
-
});
|
2987
|
+
const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
|
2988
|
+
this.usage = usagePromise;
|
2989
|
+
const { resolve: resolveFinishReason, promise: finishReasonPromise } = createResolvablePromise();
|
2990
|
+
this.finishReason = finishReasonPromise;
|
2991
|
+
const { resolve: resolveText, promise: textPromise } = createResolvablePromise();
|
2992
|
+
this.text = textPromise;
|
2993
|
+
const { resolve: resolveToolCalls, promise: toolCallsPromise } = createResolvablePromise();
|
2994
|
+
this.toolCalls = toolCallsPromise;
|
2995
|
+
const { resolve: resolveToolResults, promise: toolResultsPromise } = createResolvablePromise();
|
2996
|
+
this.toolResults = toolResultsPromise;
|
2635
2997
|
let finishReason;
|
2636
2998
|
let usage;
|
2637
2999
|
let text = "";
|
@@ -2678,7 +3040,7 @@ var DefaultStreamTextResult = class {
|
|
2678
3040
|
},
|
2679
3041
|
// invoke onFinish callback and resolve toolResults promise when the stream is about to close:
|
2680
3042
|
async flush(controller) {
|
2681
|
-
var
|
3043
|
+
var _a9;
|
2682
3044
|
try {
|
2683
3045
|
const finalUsage = usage != null ? usage : {
|
2684
3046
|
promptTokens: NaN,
|
@@ -2717,7 +3079,7 @@ var DefaultStreamTextResult = class {
|
|
2717
3079
|
})
|
2718
3080
|
);
|
2719
3081
|
resolveToolResults(toolResults);
|
2720
|
-
await ((
|
3082
|
+
await ((_a9 = self.onFinish) == null ? void 0 : _a9.call(self, {
|
2721
3083
|
finishReason: finalFinishReason,
|
2722
3084
|
usage: finalUsage,
|
2723
3085
|
text,
|
@@ -2872,8 +3234,8 @@ var DefaultStreamTextResult = class {
|
|
2872
3234
|
return this.pipeDataStreamToResponse(response, init);
|
2873
3235
|
}
|
2874
3236
|
pipeDataStreamToResponse(response, init) {
|
2875
|
-
var
|
2876
|
-
response.writeHead((
|
3237
|
+
var _a9;
|
3238
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
2877
3239
|
"Content-Type": "text/plain; charset=utf-8",
|
2878
3240
|
...init == null ? void 0 : init.headers
|
2879
3241
|
});
|
@@ -2895,8 +3257,8 @@ var DefaultStreamTextResult = class {
|
|
2895
3257
|
read();
|
2896
3258
|
}
|
2897
3259
|
pipeTextStreamToResponse(response, init) {
|
2898
|
-
var
|
2899
|
-
response.writeHead((
|
3260
|
+
var _a9;
|
3261
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
2900
3262
|
"Content-Type": "text/plain; charset=utf-8",
|
2901
3263
|
...init == null ? void 0 : init.headers
|
2902
3264
|
});
|
@@ -2921,7 +3283,7 @@ var DefaultStreamTextResult = class {
|
|
2921
3283
|
return this.toDataStreamResponse(options);
|
2922
3284
|
}
|
2923
3285
|
toDataStreamResponse(options) {
|
2924
|
-
var
|
3286
|
+
var _a9;
|
2925
3287
|
const init = options == null ? void 0 : "init" in options ? options.init : {
|
2926
3288
|
headers: "headers" in options ? options.headers : void 0,
|
2927
3289
|
status: "status" in options ? options.status : void 0,
|
@@ -2930,7 +3292,7 @@ var DefaultStreamTextResult = class {
|
|
2930
3292
|
const data = options == null ? void 0 : "data" in options ? options.data : void 0;
|
2931
3293
|
const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
|
2932
3294
|
return new Response(stream, {
|
2933
|
-
status: (
|
3295
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
2934
3296
|
statusText: init == null ? void 0 : init.statusText,
|
2935
3297
|
headers: prepareResponseHeaders(init, {
|
2936
3298
|
contentType: "text/plain; charset=utf-8",
|
@@ -2939,9 +3301,9 @@ var DefaultStreamTextResult = class {
|
|
2939
3301
|
});
|
2940
3302
|
}
|
2941
3303
|
toTextStreamResponse(init) {
|
2942
|
-
var
|
3304
|
+
var _a9;
|
2943
3305
|
return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
|
2944
|
-
status: (
|
3306
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
2945
3307
|
headers: prepareResponseHeaders(init, {
|
2946
3308
|
contentType: "text/plain; charset=utf-8"
|
2947
3309
|
})
|
@@ -2952,7 +3314,7 @@ var experimental_streamText = streamText;
|
|
2952
3314
|
|
2953
3315
|
// core/prompt/attachments-to-parts.ts
|
2954
3316
|
function attachmentsToParts(attachments) {
|
2955
|
-
var
|
3317
|
+
var _a9, _b, _c;
|
2956
3318
|
const parts = [];
|
2957
3319
|
for (const attachment of attachments) {
|
2958
3320
|
let url;
|
@@ -2964,7 +3326,7 @@ function attachmentsToParts(attachments) {
|
|
2964
3326
|
switch (url.protocol) {
|
2965
3327
|
case "http:":
|
2966
3328
|
case "https:": {
|
2967
|
-
if ((
|
3329
|
+
if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
|
2968
3330
|
parts.push({ type: "image", image: url });
|
2969
3331
|
}
|
2970
3332
|
break;
|
@@ -3181,18 +3543,18 @@ var DefaultProviderRegistry = class {
|
|
3181
3543
|
return [id.slice(0, index), id.slice(index + 1)];
|
3182
3544
|
}
|
3183
3545
|
languageModel(id) {
|
3184
|
-
var
|
3546
|
+
var _a9, _b;
|
3185
3547
|
const [providerId, modelId] = this.splitId(id);
|
3186
|
-
const model = (_b = (
|
3548
|
+
const model = (_b = (_a9 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a9, modelId);
|
3187
3549
|
if (model == null) {
|
3188
3550
|
throw new NoSuchModelError({ modelId: id, modelType: "language model" });
|
3189
3551
|
}
|
3190
3552
|
return model;
|
3191
3553
|
}
|
3192
3554
|
textEmbeddingModel(id) {
|
3193
|
-
var
|
3555
|
+
var _a9, _b;
|
3194
3556
|
const [providerId, modelId] = this.splitId(id);
|
3195
|
-
const model = (_b = (
|
3557
|
+
const model = (_b = (_a9 = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a9, modelId);
|
3196
3558
|
if (model == null) {
|
3197
3559
|
throw new NoSuchModelError({
|
3198
3560
|
modelId: id,
|
@@ -3208,9 +3570,6 @@ function tool(tool2) {
|
|
3208
3570
|
return tool2;
|
3209
3571
|
}
|
3210
3572
|
|
3211
|
-
// core/types/errors.ts
|
3212
|
-
var import_provider9 = require("@ai-sdk/provider");
|
3213
|
-
|
3214
3573
|
// core/util/cosine-similarity.ts
|
3215
3574
|
function cosineSimilarity(vector1, vector2) {
|
3216
3575
|
if (vector1.length !== vector2.length) {
|
@@ -3230,6 +3589,9 @@ function magnitude(vector) {
|
|
3230
3589
|
return Math.sqrt(dotProduct(vector, vector));
|
3231
3590
|
}
|
3232
3591
|
|
3592
|
+
// errors/index.ts
|
3593
|
+
var import_provider11 = require("@ai-sdk/provider");
|
3594
|
+
|
3233
3595
|
// streams/ai-stream.ts
|
3234
3596
|
var import_eventsource_parser = require("eventsource-parser");
|
3235
3597
|
function createEventStreamTransformer(customParser) {
|
@@ -3346,8 +3708,8 @@ function readableFromAsyncIterable(iterable) {
|
|
3346
3708
|
controller.enqueue(value);
|
3347
3709
|
},
|
3348
3710
|
async cancel(reason) {
|
3349
|
-
var
|
3350
|
-
await ((
|
3711
|
+
var _a9;
|
3712
|
+
await ((_a9 = it.return) == null ? void 0 : _a9.call(it, reason));
|
3351
3713
|
}
|
3352
3714
|
});
|
3353
3715
|
}
|
@@ -3479,7 +3841,7 @@ var import_ui_utils4 = require("@ai-sdk/ui-utils");
|
|
3479
3841
|
function AssistantResponse({ threadId, messageId }, process2) {
|
3480
3842
|
const stream = new ReadableStream({
|
3481
3843
|
async start(controller) {
|
3482
|
-
var
|
3844
|
+
var _a9;
|
3483
3845
|
const textEncoder = new TextEncoder();
|
3484
3846
|
const sendMessage = (message) => {
|
3485
3847
|
controller.enqueue(
|
@@ -3497,7 +3859,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3497
3859
|
);
|
3498
3860
|
};
|
3499
3861
|
const forwardStream = async (stream2) => {
|
3500
|
-
var
|
3862
|
+
var _a10, _b;
|
3501
3863
|
let result = void 0;
|
3502
3864
|
for await (const value of stream2) {
|
3503
3865
|
switch (value.event) {
|
@@ -3514,7 +3876,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3514
3876
|
break;
|
3515
3877
|
}
|
3516
3878
|
case "thread.message.delta": {
|
3517
|
-
const content = (
|
3879
|
+
const content = (_a10 = value.data.delta.content) == null ? void 0 : _a10[0];
|
3518
3880
|
if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
|
3519
3881
|
controller.enqueue(
|
3520
3882
|
textEncoder.encode(
|
@@ -3550,7 +3912,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
|
|
3550
3912
|
forwardStream
|
3551
3913
|
});
|
3552
3914
|
} catch (error) {
|
3553
|
-
sendError((
|
3915
|
+
sendError((_a9 = error.message) != null ? _a9 : `${error}`);
|
3554
3916
|
} finally {
|
3555
3917
|
controller.close();
|
3556
3918
|
}
|
@@ -3571,9 +3933,9 @@ var experimental_AssistantResponse = AssistantResponse;
|
|
3571
3933
|
|
3572
3934
|
// streams/aws-bedrock-stream.ts
|
3573
3935
|
async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
3574
|
-
var
|
3936
|
+
var _a9, _b;
|
3575
3937
|
const decoder = new TextDecoder();
|
3576
|
-
for await (const chunk of (
|
3938
|
+
for await (const chunk of (_a9 = response.body) != null ? _a9 : []) {
|
3577
3939
|
const bytes = (_b = chunk.chunk) == null ? void 0 : _b.bytes;
|
3578
3940
|
if (bytes != null) {
|
3579
3941
|
const chunkText = decoder.decode(bytes);
|
@@ -3587,8 +3949,8 @@ async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
|
|
3587
3949
|
}
|
3588
3950
|
function AWSBedrockAnthropicMessagesStream(response, callbacks) {
|
3589
3951
|
return AWSBedrockStream(response, callbacks, (chunk) => {
|
3590
|
-
var
|
3591
|
-
return (
|
3952
|
+
var _a9;
|
3953
|
+
return (_a9 = chunk.delta) == null ? void 0 : _a9.text;
|
3592
3954
|
});
|
3593
3955
|
}
|
3594
3956
|
function AWSBedrockAnthropicStream(response, callbacks) {
|
@@ -3635,8 +3997,8 @@ async function readAndProcessLines(reader, controller) {
|
|
3635
3997
|
controller.close();
|
3636
3998
|
}
|
3637
3999
|
function createParser2(res) {
|
3638
|
-
var
|
3639
|
-
const reader = (
|
4000
|
+
var _a9;
|
4001
|
+
const reader = (_a9 = res.body) == null ? void 0 : _a9.getReader();
|
3640
4002
|
return new ReadableStream({
|
3641
4003
|
async start(controller) {
|
3642
4004
|
if (!reader) {
|
@@ -3666,9 +4028,9 @@ function CohereStream(reader, callbacks) {
|
|
3666
4028
|
|
3667
4029
|
// streams/google-generative-ai-stream.ts
|
3668
4030
|
async function* streamable3(response) {
|
3669
|
-
var
|
4031
|
+
var _a9, _b, _c;
|
3670
4032
|
for await (const chunk of response.stream) {
|
3671
|
-
const parts = (_c = (_b = (
|
4033
|
+
const parts = (_c = (_b = (_a9 = chunk.candidates) == null ? void 0 : _a9[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
|
3672
4034
|
if (parts === void 0) {
|
3673
4035
|
continue;
|
3674
4036
|
}
|
@@ -3687,13 +4049,13 @@ function createParser3(res) {
|
|
3687
4049
|
const trimStartOfStream = trimStartOfStreamHelper();
|
3688
4050
|
return new ReadableStream({
|
3689
4051
|
async pull(controller) {
|
3690
|
-
var
|
4052
|
+
var _a9, _b;
|
3691
4053
|
const { value, done } = await res.next();
|
3692
4054
|
if (done) {
|
3693
4055
|
controller.close();
|
3694
4056
|
return;
|
3695
4057
|
}
|
3696
|
-
const text = trimStartOfStream((_b = (
|
4058
|
+
const text = trimStartOfStream((_b = (_a9 = value.token) == null ? void 0 : _a9.text) != null ? _b : "");
|
3697
4059
|
if (!text)
|
3698
4060
|
return;
|
3699
4061
|
if (value.generated_text != null && value.generated_text.length > 0) {
|
@@ -3718,11 +4080,11 @@ function InkeepStream(res, callbacks) {
|
|
3718
4080
|
let chat_session_id = "";
|
3719
4081
|
let records_cited;
|
3720
4082
|
const inkeepEventParser = (data, options) => {
|
3721
|
-
var
|
4083
|
+
var _a9, _b;
|
3722
4084
|
const { event } = options;
|
3723
4085
|
if (event === "records_cited") {
|
3724
4086
|
records_cited = JSON.parse(data);
|
3725
|
-
(
|
4087
|
+
(_a9 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a9.call(callbacks, records_cited);
|
3726
4088
|
}
|
3727
4089
|
if (event === "message_chunk") {
|
3728
4090
|
const inkeepMessageChunk = JSON.parse(data);
|
@@ -3735,12 +4097,12 @@ function InkeepStream(res, callbacks) {
|
|
3735
4097
|
passThroughCallbacks = {
|
3736
4098
|
...passThroughCallbacks,
|
3737
4099
|
onFinal: (completion) => {
|
3738
|
-
var
|
4100
|
+
var _a9;
|
3739
4101
|
const inkeepOnFinalMetadata = {
|
3740
4102
|
chat_session_id,
|
3741
4103
|
records_cited
|
3742
4104
|
};
|
3743
|
-
(
|
4105
|
+
(_a9 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a9.call(callbacks, completion, inkeepOnFinalMetadata);
|
3744
4106
|
}
|
3745
4107
|
};
|
3746
4108
|
return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
|
@@ -3762,7 +4124,7 @@ function toDataStream(stream, callbacks) {
|
|
3762
4124
|
return stream.pipeThrough(
|
3763
4125
|
new TransformStream({
|
3764
4126
|
transform: async (value, controller) => {
|
3765
|
-
var
|
4127
|
+
var _a9;
|
3766
4128
|
if (typeof value === "string") {
|
3767
4129
|
controller.enqueue(value);
|
3768
4130
|
return;
|
@@ -3770,7 +4132,7 @@ function toDataStream(stream, callbacks) {
|
|
3770
4132
|
if ("event" in value) {
|
3771
4133
|
if (value.event === "on_chat_model_stream") {
|
3772
4134
|
forwardAIMessageChunk(
|
3773
|
-
(
|
4135
|
+
(_a9 = value.data) == null ? void 0 : _a9.chunk,
|
3774
4136
|
controller
|
3775
4137
|
);
|
3776
4138
|
}
|
@@ -3782,13 +4144,13 @@ function toDataStream(stream, callbacks) {
|
|
3782
4144
|
).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
3783
4145
|
}
|
3784
4146
|
function toDataStreamResponse(stream, options) {
|
3785
|
-
var
|
4147
|
+
var _a9;
|
3786
4148
|
const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
|
3787
4149
|
const data = options == null ? void 0 : options.data;
|
3788
4150
|
const init = options == null ? void 0 : options.init;
|
3789
4151
|
const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
|
3790
4152
|
return new Response(responseStream, {
|
3791
|
-
status: (
|
4153
|
+
status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
|
3792
4154
|
statusText: init == null ? void 0 : init.statusText,
|
3793
4155
|
headers: prepareResponseHeaders(init, {
|
3794
4156
|
contentType: "text/plain; charset=utf-8",
|
@@ -3870,9 +4232,9 @@ function LangChainStream(callbacks) {
|
|
3870
4232
|
|
3871
4233
|
// streams/mistral-stream.ts
|
3872
4234
|
async function* streamable4(stream) {
|
3873
|
-
var
|
4235
|
+
var _a9, _b;
|
3874
4236
|
for await (const chunk of stream) {
|
3875
|
-
const content = (_b = (
|
4237
|
+
const content = (_b = (_a9 = chunk.choices[0]) == null ? void 0 : _a9.delta) == null ? void 0 : _b.content;
|
3876
4238
|
if (content === void 0 || content === "") {
|
3877
4239
|
continue;
|
3878
4240
|
}
|
@@ -3902,10 +4264,10 @@ async function* streamable5(stream) {
|
|
3902
4264
|
model: chunk.model,
|
3903
4265
|
// not exposed by Azure API
|
3904
4266
|
choices: chunk.choices.map((choice) => {
|
3905
|
-
var
|
4267
|
+
var _a9, _b, _c, _d, _e, _f, _g;
|
3906
4268
|
return {
|
3907
4269
|
delta: {
|
3908
|
-
content: (
|
4270
|
+
content: (_a9 = choice.delta) == null ? void 0 : _a9.content,
|
3909
4271
|
function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
|
3910
4272
|
role: (_c = choice.delta) == null ? void 0 : _c.role,
|
3911
4273
|
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) => ({
|
@@ -3930,9 +4292,9 @@ function chunkToText() {
|
|
3930
4292
|
const trimStartOfStream = trimStartOfStreamHelper();
|
3931
4293
|
let isFunctionStreamingIn;
|
3932
4294
|
return (json) => {
|
3933
|
-
var
|
4295
|
+
var _a9, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
3934
4296
|
if (isChatCompletionChunk(json)) {
|
3935
|
-
const delta = (
|
4297
|
+
const delta = (_a9 = json.choices[0]) == null ? void 0 : _a9.delta;
|
3936
4298
|
if ((_b = delta.function_call) == null ? void 0 : _b.name) {
|
3937
4299
|
isFunctionStreamingIn = true;
|
3938
4300
|
return {
|
@@ -4205,8 +4567,8 @@ function createFunctionCallTransformer(callbacks) {
|
|
4205
4567
|
|
4206
4568
|
// streams/replicate-stream.ts
|
4207
4569
|
async function ReplicateStream(res, cb, options) {
|
4208
|
-
var
|
4209
|
-
const url = (
|
4570
|
+
var _a9;
|
4571
|
+
const url = (_a9 = res.urls) == null ? void 0 : _a9.stream;
|
4210
4572
|
if (!url) {
|
4211
4573
|
if (res.error)
|
4212
4574
|
throw new Error(res.error);
|
@@ -4227,8 +4589,8 @@ async function ReplicateStream(res, cb, options) {
|
|
4227
4589
|
|
4228
4590
|
// streams/stream-to-response.ts
|
4229
4591
|
function streamToResponse(res, response, init, data) {
|
4230
|
-
var
|
4231
|
-
response.writeHead((
|
4592
|
+
var _a9;
|
4593
|
+
response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
|
4232
4594
|
"Content-Type": "text/plain; charset=utf-8",
|
4233
4595
|
...init == null ? void 0 : init.headers
|
4234
4596
|
});
|
@@ -4272,6 +4634,7 @@ var generateId2 = import_provider_utils8.generateId;
|
|
4272
4634
|
var nanoid = import_provider_utils8.generateId;
|
4273
4635
|
// Annotate the CommonJS export names for ESM import in node:
|
4274
4636
|
0 && (module.exports = {
|
4637
|
+
AISDKError,
|
4275
4638
|
AIStream,
|
4276
4639
|
APICallError,
|
4277
4640
|
AWSBedrockAnthropicMessagesStream,
|
@@ -4282,6 +4645,7 @@ var nanoid = import_provider_utils8.generateId;
|
|
4282
4645
|
AnthropicStream,
|
4283
4646
|
AssistantResponse,
|
4284
4647
|
CohereStream,
|
4648
|
+
DownloadError,
|
4285
4649
|
EmptyResponseBodyError,
|
4286
4650
|
GoogleGenerativeAIStream,
|
4287
4651
|
HuggingFaceStream,
|
@@ -4307,10 +4671,8 @@ var nanoid = import_provider_utils8.generateId;
|
|
4307
4671
|
RetryError,
|
4308
4672
|
StreamData,
|
4309
4673
|
StreamingTextResponse,
|
4310
|
-
ToolCallParseError,
|
4311
4674
|
TypeValidationError,
|
4312
4675
|
UnsupportedFunctionalityError,
|
4313
|
-
UnsupportedJSONSchemaError,
|
4314
4676
|
convertDataContentToBase64String,
|
4315
4677
|
convertDataContentToUint8Array,
|
4316
4678
|
convertToCoreMessages,
|