ai 5.0.0-canary.2 → 5.0.0-canary.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +356 -0
- package/README.md +4 -4
- package/dist/index.d.mts +3023 -2408
- package/dist/index.d.ts +3023 -2408
- package/dist/index.js +4039 -3790
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4017 -3774
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +467 -0
- package/dist/internal/index.d.ts +467 -0
- package/dist/internal/index.js +957 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/index.mjs +930 -0
- package/dist/internal/index.mjs.map +1 -0
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.js +5 -8
- package/dist/mcp-stdio/index.js.map +1 -0
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.mjs +5 -20
- package/dist/mcp-stdio/index.mjs.map +1 -0
- package/{test/dist → dist/test}/index.d.mts +23 -24
- package/{test/dist → dist/test}/index.d.ts +23 -24
- package/{test/dist → dist/test}/index.js +39 -16
- package/dist/test/index.js.map +1 -0
- package/{test/dist → dist/test}/index.mjs +38 -15
- package/dist/test/index.mjs.map +1 -0
- package/internal.d.ts +1 -0
- package/mcp-stdio.d.ts +1 -0
- package/package.json +32 -49
- package/test.d.ts +1 -0
- package/mcp-stdio/create-child-process.test.ts +0 -92
- package/mcp-stdio/create-child-process.ts +0 -21
- package/mcp-stdio/dist/index.js.map +0 -1
- package/mcp-stdio/dist/index.mjs.map +0 -1
- package/mcp-stdio/get-environment.ts +0 -43
- package/mcp-stdio/index.ts +0 -4
- package/mcp-stdio/mcp-stdio-transport.test.ts +0 -262
- package/mcp-stdio/mcp-stdio-transport.ts +0 -157
- package/rsc/dist/index.d.ts +0 -813
- package/rsc/dist/index.mjs +0 -18
- package/rsc/dist/rsc-client.d.mts +0 -1
- package/rsc/dist/rsc-client.mjs +0 -18
- package/rsc/dist/rsc-client.mjs.map +0 -1
- package/rsc/dist/rsc-server.d.mts +0 -748
- package/rsc/dist/rsc-server.mjs +0 -2142
- package/rsc/dist/rsc-server.mjs.map +0 -1
- package/rsc/dist/rsc-shared.d.mts +0 -101
- package/rsc/dist/rsc-shared.mjs +0 -308
- package/rsc/dist/rsc-shared.mjs.map +0 -1
- package/test/dist/index.js.map +0 -1
- package/test/dist/index.mjs.map +0 -1
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.mts +8 -8
- package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.ts +8 -8
package/rsc/dist/rsc-server.mjs
DELETED
@@ -1,2142 +0,0 @@
|
|
1
|
-
// rsc/ai-state.tsx
|
2
|
-
import * as jsondiffpatch from "jsondiffpatch";
|
3
|
-
import { AsyncLocalStorage } from "async_hooks";
|
4
|
-
|
5
|
-
// util/create-resolvable-promise.ts
|
6
|
-
function createResolvablePromise() {
|
7
|
-
let resolve;
|
8
|
-
let reject;
|
9
|
-
const promise = new Promise((res, rej) => {
|
10
|
-
resolve = res;
|
11
|
-
reject = rej;
|
12
|
-
});
|
13
|
-
return {
|
14
|
-
promise,
|
15
|
-
resolve,
|
16
|
-
reject
|
17
|
-
};
|
18
|
-
}
|
19
|
-
|
20
|
-
// util/is-function.ts
|
21
|
-
var isFunction = (value) => typeof value === "function";
|
22
|
-
|
23
|
-
// rsc/ai-state.tsx
|
24
|
-
var asyncAIStateStorage = new AsyncLocalStorage();
|
25
|
-
function getAIStateStoreOrThrow(message) {
|
26
|
-
const store = asyncAIStateStorage.getStore();
|
27
|
-
if (!store) {
|
28
|
-
throw new Error(message);
|
29
|
-
}
|
30
|
-
return store;
|
31
|
-
}
|
32
|
-
function withAIState({ state, options }, fn) {
|
33
|
-
return asyncAIStateStorage.run(
|
34
|
-
{
|
35
|
-
currentState: JSON.parse(JSON.stringify(state)),
|
36
|
-
// deep clone object
|
37
|
-
originalState: state,
|
38
|
-
sealed: false,
|
39
|
-
options
|
40
|
-
},
|
41
|
-
fn
|
42
|
-
);
|
43
|
-
}
|
44
|
-
function getAIStateDeltaPromise() {
|
45
|
-
const store = getAIStateStoreOrThrow("Internal error occurred.");
|
46
|
-
return store.mutationDeltaPromise;
|
47
|
-
}
|
48
|
-
function sealMutableAIState() {
|
49
|
-
const store = getAIStateStoreOrThrow("Internal error occurred.");
|
50
|
-
store.sealed = true;
|
51
|
-
}
|
52
|
-
function getAIState(...args) {
|
53
|
-
const store = getAIStateStoreOrThrow(
|
54
|
-
"`getAIState` must be called within an AI Action."
|
55
|
-
);
|
56
|
-
if (args.length > 0) {
|
57
|
-
const key = args[0];
|
58
|
-
if (typeof store.currentState !== "object") {
|
59
|
-
throw new Error(
|
60
|
-
`You can't get the "${String(
|
61
|
-
key
|
62
|
-
)}" field from the AI state because it's not an object.`
|
63
|
-
);
|
64
|
-
}
|
65
|
-
return store.currentState[key];
|
66
|
-
}
|
67
|
-
return store.currentState;
|
68
|
-
}
|
69
|
-
function getMutableAIState(...args) {
|
70
|
-
const store = getAIStateStoreOrThrow(
|
71
|
-
"`getMutableAIState` must be called within an AI Action."
|
72
|
-
);
|
73
|
-
if (store.sealed) {
|
74
|
-
throw new Error(
|
75
|
-
"`getMutableAIState` must be called before returning from an AI Action. Please move it to the top level of the Action's function body."
|
76
|
-
);
|
77
|
-
}
|
78
|
-
if (!store.mutationDeltaPromise) {
|
79
|
-
const { promise, resolve } = createResolvablePromise();
|
80
|
-
store.mutationDeltaPromise = promise;
|
81
|
-
store.mutationDeltaResolve = resolve;
|
82
|
-
}
|
83
|
-
function doUpdate(newState, done) {
|
84
|
-
var _a9, _b;
|
85
|
-
if (args.length > 0) {
|
86
|
-
if (typeof store.currentState !== "object") {
|
87
|
-
const key = args[0];
|
88
|
-
throw new Error(
|
89
|
-
`You can't modify the "${String(
|
90
|
-
key
|
91
|
-
)}" field of the AI state because it's not an object.`
|
92
|
-
);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
if (isFunction(newState)) {
|
96
|
-
if (args.length > 0) {
|
97
|
-
store.currentState[args[0]] = newState(store.currentState[args[0]]);
|
98
|
-
} else {
|
99
|
-
store.currentState = newState(store.currentState);
|
100
|
-
}
|
101
|
-
} else {
|
102
|
-
if (args.length > 0) {
|
103
|
-
store.currentState[args[0]] = newState;
|
104
|
-
} else {
|
105
|
-
store.currentState = newState;
|
106
|
-
}
|
107
|
-
}
|
108
|
-
(_b = (_a9 = store.options).onSetAIState) == null ? void 0 : _b.call(_a9, {
|
109
|
-
key: args.length > 0 ? args[0] : void 0,
|
110
|
-
state: store.currentState,
|
111
|
-
done
|
112
|
-
});
|
113
|
-
}
|
114
|
-
const mutableState = {
|
115
|
-
get: () => {
|
116
|
-
if (args.length > 0) {
|
117
|
-
const key = args[0];
|
118
|
-
if (typeof store.currentState !== "object") {
|
119
|
-
throw new Error(
|
120
|
-
`You can't get the "${String(
|
121
|
-
key
|
122
|
-
)}" field from the AI state because it's not an object.`
|
123
|
-
);
|
124
|
-
}
|
125
|
-
return store.currentState[key];
|
126
|
-
}
|
127
|
-
return store.currentState;
|
128
|
-
},
|
129
|
-
update: function update(newAIState) {
|
130
|
-
doUpdate(newAIState, false);
|
131
|
-
},
|
132
|
-
done: function done(...doneArgs) {
|
133
|
-
if (doneArgs.length > 0) {
|
134
|
-
doUpdate(doneArgs[0], true);
|
135
|
-
}
|
136
|
-
const delta = jsondiffpatch.diff(store.originalState, store.currentState);
|
137
|
-
store.mutationDeltaResolve(delta);
|
138
|
-
}
|
139
|
-
};
|
140
|
-
return mutableState;
|
141
|
-
}
|
142
|
-
|
143
|
-
// rsc/provider.tsx
|
144
|
-
import * as React from "react";
|
145
|
-
import { InternalAIProvider } from "./rsc-shared.mjs";
|
146
|
-
import { jsx } from "react/jsx-runtime";
|
147
|
-
async function innerAction({
|
148
|
-
action,
|
149
|
-
options
|
150
|
-
}, state, ...args) {
|
151
|
-
"use server";
|
152
|
-
return await withAIState(
|
153
|
-
{
|
154
|
-
state,
|
155
|
-
options
|
156
|
-
},
|
157
|
-
async () => {
|
158
|
-
const result = await action(...args);
|
159
|
-
sealMutableAIState();
|
160
|
-
return [getAIStateDeltaPromise(), result];
|
161
|
-
}
|
162
|
-
);
|
163
|
-
}
|
164
|
-
function wrapAction(action, options) {
|
165
|
-
return innerAction.bind(null, { action, options });
|
166
|
-
}
|
167
|
-
function createAI({
|
168
|
-
actions,
|
169
|
-
initialAIState,
|
170
|
-
initialUIState,
|
171
|
-
onSetAIState,
|
172
|
-
onGetUIState
|
173
|
-
}) {
|
174
|
-
const wrappedActions = {};
|
175
|
-
for (const name9 in actions) {
|
176
|
-
wrappedActions[name9] = wrapAction(actions[name9], {
|
177
|
-
onSetAIState
|
178
|
-
});
|
179
|
-
}
|
180
|
-
const wrappedSyncUIState = onGetUIState ? wrapAction(onGetUIState, {}) : void 0;
|
181
|
-
const AI = async (props) => {
|
182
|
-
var _a9, _b;
|
183
|
-
if ("useState" in React) {
|
184
|
-
throw new Error(
|
185
|
-
"This component can only be used inside Server Components."
|
186
|
-
);
|
187
|
-
}
|
188
|
-
let uiState = (_a9 = props.initialUIState) != null ? _a9 : initialUIState;
|
189
|
-
let aiState = (_b = props.initialAIState) != null ? _b : initialAIState;
|
190
|
-
let aiStateDelta = void 0;
|
191
|
-
if (wrappedSyncUIState) {
|
192
|
-
const [newAIStateDelta, newUIState] = await wrappedSyncUIState(aiState);
|
193
|
-
if (newUIState !== void 0) {
|
194
|
-
aiStateDelta = newAIStateDelta;
|
195
|
-
uiState = newUIState;
|
196
|
-
}
|
197
|
-
}
|
198
|
-
return /* @__PURE__ */ jsx(
|
199
|
-
InternalAIProvider,
|
200
|
-
{
|
201
|
-
wrappedActions,
|
202
|
-
wrappedSyncUIState,
|
203
|
-
initialUIState: uiState,
|
204
|
-
initialAIState: aiState,
|
205
|
-
initialAIStatePatch: aiStateDelta,
|
206
|
-
children: props.children
|
207
|
-
}
|
208
|
-
);
|
209
|
-
};
|
210
|
-
return AI;
|
211
|
-
}
|
212
|
-
|
213
|
-
// rsc/stream-ui/stream-ui.tsx
|
214
|
-
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
215
|
-
|
216
|
-
// util/download-error.ts
|
217
|
-
import { AISDKError } from "@ai-sdk/provider";
|
218
|
-
var name = "AI_DownloadError";
|
219
|
-
var marker = `vercel.ai.error.${name}`;
|
220
|
-
var symbol = Symbol.for(marker);
|
221
|
-
var _a;
|
222
|
-
var DownloadError = class extends AISDKError {
|
223
|
-
constructor({
|
224
|
-
url,
|
225
|
-
statusCode,
|
226
|
-
statusText,
|
227
|
-
cause,
|
228
|
-
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
229
|
-
}) {
|
230
|
-
super({ name, message, cause });
|
231
|
-
this[_a] = true;
|
232
|
-
this.url = url;
|
233
|
-
this.statusCode = statusCode;
|
234
|
-
this.statusText = statusText;
|
235
|
-
}
|
236
|
-
static isInstance(error) {
|
237
|
-
return AISDKError.hasMarker(error, marker);
|
238
|
-
}
|
239
|
-
};
|
240
|
-
_a = symbol;
|
241
|
-
|
242
|
-
// util/download.ts
|
243
|
-
async function download({ url }) {
|
244
|
-
var _a9;
|
245
|
-
const urlText = url.toString();
|
246
|
-
try {
|
247
|
-
const response = await fetch(urlText);
|
248
|
-
if (!response.ok) {
|
249
|
-
throw new DownloadError({
|
250
|
-
url: urlText,
|
251
|
-
statusCode: response.status,
|
252
|
-
statusText: response.statusText
|
253
|
-
});
|
254
|
-
}
|
255
|
-
return {
|
256
|
-
data: new Uint8Array(await response.arrayBuffer()),
|
257
|
-
mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
|
258
|
-
};
|
259
|
-
} catch (error) {
|
260
|
-
if (DownloadError.isInstance(error)) {
|
261
|
-
throw error;
|
262
|
-
}
|
263
|
-
throw new DownloadError({ url: urlText, cause: error });
|
264
|
-
}
|
265
|
-
}
|
266
|
-
|
267
|
-
// core/util/detect-image-mimetype.ts
|
268
|
-
var mimeTypeSignatures = [
|
269
|
-
{
|
270
|
-
mimeType: "image/gif",
|
271
|
-
bytesPrefix: [71, 73, 70],
|
272
|
-
base64Prefix: "R0lG"
|
273
|
-
},
|
274
|
-
{
|
275
|
-
mimeType: "image/png",
|
276
|
-
bytesPrefix: [137, 80, 78, 71],
|
277
|
-
base64Prefix: "iVBORw"
|
278
|
-
},
|
279
|
-
{
|
280
|
-
mimeType: "image/jpeg",
|
281
|
-
bytesPrefix: [255, 216],
|
282
|
-
base64Prefix: "/9j/"
|
283
|
-
},
|
284
|
-
{
|
285
|
-
mimeType: "image/webp",
|
286
|
-
bytesPrefix: [82, 73, 70, 70],
|
287
|
-
base64Prefix: "UklGRg"
|
288
|
-
},
|
289
|
-
{
|
290
|
-
mimeType: "image/bmp",
|
291
|
-
bytesPrefix: [66, 77],
|
292
|
-
base64Prefix: "Qk"
|
293
|
-
},
|
294
|
-
{
|
295
|
-
mimeType: "image/tiff",
|
296
|
-
bytesPrefix: [73, 73, 42, 0],
|
297
|
-
base64Prefix: "SUkqAA"
|
298
|
-
},
|
299
|
-
{
|
300
|
-
mimeType: "image/tiff",
|
301
|
-
bytesPrefix: [77, 77, 0, 42],
|
302
|
-
base64Prefix: "TU0AKg"
|
303
|
-
},
|
304
|
-
{
|
305
|
-
mimeType: "image/avif",
|
306
|
-
bytesPrefix: [
|
307
|
-
0,
|
308
|
-
0,
|
309
|
-
0,
|
310
|
-
32,
|
311
|
-
102,
|
312
|
-
116,
|
313
|
-
121,
|
314
|
-
112,
|
315
|
-
97,
|
316
|
-
118,
|
317
|
-
105,
|
318
|
-
102
|
319
|
-
],
|
320
|
-
base64Prefix: "AAAAIGZ0eXBhdmlm"
|
321
|
-
},
|
322
|
-
{
|
323
|
-
mimeType: "image/heic",
|
324
|
-
bytesPrefix: [
|
325
|
-
0,
|
326
|
-
0,
|
327
|
-
0,
|
328
|
-
32,
|
329
|
-
102,
|
330
|
-
116,
|
331
|
-
121,
|
332
|
-
112,
|
333
|
-
104,
|
334
|
-
101,
|
335
|
-
105,
|
336
|
-
99
|
337
|
-
],
|
338
|
-
base64Prefix: "AAAAIGZ0eXBoZWlj"
|
339
|
-
}
|
340
|
-
];
|
341
|
-
function detectImageMimeType(image) {
|
342
|
-
for (const signature of mimeTypeSignatures) {
|
343
|
-
if (typeof image === "string" ? image.startsWith(signature.base64Prefix) : image.length >= signature.bytesPrefix.length && signature.bytesPrefix.every((byte, index) => image[index] === byte)) {
|
344
|
-
return signature.mimeType;
|
345
|
-
}
|
346
|
-
}
|
347
|
-
return void 0;
|
348
|
-
}
|
349
|
-
|
350
|
-
// core/prompt/data-content.ts
|
351
|
-
import {
|
352
|
-
convertBase64ToUint8Array,
|
353
|
-
convertUint8ArrayToBase64
|
354
|
-
} from "@ai-sdk/provider-utils";
|
355
|
-
|
356
|
-
// core/prompt/invalid-data-content-error.ts
|
357
|
-
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
358
|
-
var name2 = "AI_InvalidDataContentError";
|
359
|
-
var marker2 = `vercel.ai.error.${name2}`;
|
360
|
-
var symbol2 = Symbol.for(marker2);
|
361
|
-
var _a2;
|
362
|
-
var InvalidDataContentError = class extends AISDKError2 {
|
363
|
-
constructor({
|
364
|
-
content,
|
365
|
-
cause,
|
366
|
-
message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
|
367
|
-
}) {
|
368
|
-
super({ name: name2, message, cause });
|
369
|
-
this[_a2] = true;
|
370
|
-
this.content = content;
|
371
|
-
}
|
372
|
-
static isInstance(error) {
|
373
|
-
return AISDKError2.hasMarker(error, marker2);
|
374
|
-
}
|
375
|
-
};
|
376
|
-
_a2 = symbol2;
|
377
|
-
|
378
|
-
// core/prompt/data-content.ts
|
379
|
-
import { z } from "zod";
|
380
|
-
var dataContentSchema = z.union([
|
381
|
-
z.string(),
|
382
|
-
z.instanceof(Uint8Array),
|
383
|
-
z.instanceof(ArrayBuffer),
|
384
|
-
z.custom(
|
385
|
-
// Buffer might not be available in some environments such as CloudFlare:
|
386
|
-
(value) => {
|
387
|
-
var _a9, _b;
|
388
|
-
return (_b = (_a9 = globalThis.Buffer) == null ? void 0 : _a9.isBuffer(value)) != null ? _b : false;
|
389
|
-
},
|
390
|
-
{ message: "Must be a Buffer" }
|
391
|
-
)
|
392
|
-
]);
|
393
|
-
function convertDataContentToBase64String(content) {
|
394
|
-
if (typeof content === "string") {
|
395
|
-
return content;
|
396
|
-
}
|
397
|
-
if (content instanceof ArrayBuffer) {
|
398
|
-
return convertUint8ArrayToBase64(new Uint8Array(content));
|
399
|
-
}
|
400
|
-
return convertUint8ArrayToBase64(content);
|
401
|
-
}
|
402
|
-
function convertDataContentToUint8Array(content) {
|
403
|
-
if (content instanceof Uint8Array) {
|
404
|
-
return content;
|
405
|
-
}
|
406
|
-
if (typeof content === "string") {
|
407
|
-
try {
|
408
|
-
return convertBase64ToUint8Array(content);
|
409
|
-
} catch (error) {
|
410
|
-
throw new InvalidDataContentError({
|
411
|
-
message: "Invalid data content. Content string is not a base64-encoded media.",
|
412
|
-
content,
|
413
|
-
cause: error
|
414
|
-
});
|
415
|
-
}
|
416
|
-
}
|
417
|
-
if (content instanceof ArrayBuffer) {
|
418
|
-
return new Uint8Array(content);
|
419
|
-
}
|
420
|
-
throw new InvalidDataContentError({ content });
|
421
|
-
}
|
422
|
-
function convertUint8ArrayToText(uint8Array) {
|
423
|
-
try {
|
424
|
-
return new TextDecoder().decode(uint8Array);
|
425
|
-
} catch (error) {
|
426
|
-
throw new Error("Error decoding Uint8Array to text");
|
427
|
-
}
|
428
|
-
}
|
429
|
-
|
430
|
-
// core/prompt/invalid-message-role-error.ts
|
431
|
-
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
432
|
-
var name3 = "AI_InvalidMessageRoleError";
|
433
|
-
var marker3 = `vercel.ai.error.${name3}`;
|
434
|
-
var symbol3 = Symbol.for(marker3);
|
435
|
-
var _a3;
|
436
|
-
var InvalidMessageRoleError = class extends AISDKError3 {
|
437
|
-
constructor({
|
438
|
-
role,
|
439
|
-
message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
|
440
|
-
}) {
|
441
|
-
super({ name: name3, message });
|
442
|
-
this[_a3] = true;
|
443
|
-
this.role = role;
|
444
|
-
}
|
445
|
-
static isInstance(error) {
|
446
|
-
return AISDKError3.hasMarker(error, marker3);
|
447
|
-
}
|
448
|
-
};
|
449
|
-
_a3 = symbol3;
|
450
|
-
|
451
|
-
// core/prompt/split-data-url.ts
|
452
|
-
function splitDataUrl(dataUrl) {
|
453
|
-
try {
|
454
|
-
const [header, base64Content] = dataUrl.split(",");
|
455
|
-
return {
|
456
|
-
mimeType: header.split(";")[0].split(":")[1],
|
457
|
-
base64Content
|
458
|
-
};
|
459
|
-
} catch (error) {
|
460
|
-
return {
|
461
|
-
mimeType: void 0,
|
462
|
-
base64Content: void 0
|
463
|
-
};
|
464
|
-
}
|
465
|
-
}
|
466
|
-
|
467
|
-
// core/prompt/convert-to-language-model-prompt.ts
|
468
|
-
async function convertToLanguageModelPrompt({
|
469
|
-
prompt,
|
470
|
-
modelSupportsImageUrls = true,
|
471
|
-
modelSupportsUrl = () => false,
|
472
|
-
downloadImplementation = download
|
473
|
-
}) {
|
474
|
-
const downloadedAssets = await downloadAssets(
|
475
|
-
prompt.messages,
|
476
|
-
downloadImplementation,
|
477
|
-
modelSupportsImageUrls,
|
478
|
-
modelSupportsUrl
|
479
|
-
);
|
480
|
-
return [
|
481
|
-
...prompt.system != null ? [{ role: "system", content: prompt.system }] : [],
|
482
|
-
...prompt.messages.map(
|
483
|
-
(message) => convertToLanguageModelMessage(message, downloadedAssets)
|
484
|
-
)
|
485
|
-
];
|
486
|
-
}
|
487
|
-
function convertToLanguageModelMessage(message, downloadedAssets) {
|
488
|
-
var _a9, _b, _c, _d, _e, _f;
|
489
|
-
const role = message.role;
|
490
|
-
switch (role) {
|
491
|
-
case "system": {
|
492
|
-
return {
|
493
|
-
role: "system",
|
494
|
-
content: message.content,
|
495
|
-
providerMetadata: (_a9 = message.providerOptions) != null ? _a9 : message.experimental_providerMetadata
|
496
|
-
};
|
497
|
-
}
|
498
|
-
case "user": {
|
499
|
-
if (typeof message.content === "string") {
|
500
|
-
return {
|
501
|
-
role: "user",
|
502
|
-
content: [{ type: "text", text: message.content }],
|
503
|
-
providerMetadata: (_b = message.providerOptions) != null ? _b : message.experimental_providerMetadata
|
504
|
-
};
|
505
|
-
}
|
506
|
-
return {
|
507
|
-
role: "user",
|
508
|
-
content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
509
|
-
providerMetadata: (_c = message.providerOptions) != null ? _c : message.experimental_providerMetadata
|
510
|
-
};
|
511
|
-
}
|
512
|
-
case "assistant": {
|
513
|
-
if (typeof message.content === "string") {
|
514
|
-
return {
|
515
|
-
role: "assistant",
|
516
|
-
content: [{ type: "text", text: message.content }],
|
517
|
-
providerMetadata: (_d = message.providerOptions) != null ? _d : message.experimental_providerMetadata
|
518
|
-
};
|
519
|
-
}
|
520
|
-
return {
|
521
|
-
role: "assistant",
|
522
|
-
content: message.content.filter(
|
523
|
-
// remove empty text parts:
|
524
|
-
(part) => part.type !== "text" || part.text !== ""
|
525
|
-
).map((part) => {
|
526
|
-
var _a10;
|
527
|
-
const providerOptions = (_a10 = part.providerOptions) != null ? _a10 : part.experimental_providerMetadata;
|
528
|
-
switch (part.type) {
|
529
|
-
case "file": {
|
530
|
-
return {
|
531
|
-
type: "file",
|
532
|
-
data: part.data instanceof URL ? part.data : convertDataContentToBase64String(part.data),
|
533
|
-
filename: part.filename,
|
534
|
-
mimeType: part.mimeType,
|
535
|
-
providerMetadata: providerOptions
|
536
|
-
};
|
537
|
-
}
|
538
|
-
case "reasoning": {
|
539
|
-
return {
|
540
|
-
type: "reasoning",
|
541
|
-
text: part.text,
|
542
|
-
signature: part.signature,
|
543
|
-
providerMetadata: providerOptions
|
544
|
-
};
|
545
|
-
}
|
546
|
-
case "redacted-reasoning": {
|
547
|
-
return {
|
548
|
-
type: "redacted-reasoning",
|
549
|
-
data: part.data,
|
550
|
-
providerMetadata: providerOptions
|
551
|
-
};
|
552
|
-
}
|
553
|
-
case "text": {
|
554
|
-
return {
|
555
|
-
type: "text",
|
556
|
-
text: part.text,
|
557
|
-
providerMetadata: providerOptions
|
558
|
-
};
|
559
|
-
}
|
560
|
-
case "tool-call": {
|
561
|
-
return {
|
562
|
-
type: "tool-call",
|
563
|
-
toolCallId: part.toolCallId,
|
564
|
-
toolName: part.toolName,
|
565
|
-
args: part.args,
|
566
|
-
providerMetadata: providerOptions
|
567
|
-
};
|
568
|
-
}
|
569
|
-
}
|
570
|
-
}),
|
571
|
-
providerMetadata: (_e = message.providerOptions) != null ? _e : message.experimental_providerMetadata
|
572
|
-
};
|
573
|
-
}
|
574
|
-
case "tool": {
|
575
|
-
return {
|
576
|
-
role: "tool",
|
577
|
-
content: message.content.map((part) => {
|
578
|
-
var _a10;
|
579
|
-
return {
|
580
|
-
type: "tool-result",
|
581
|
-
toolCallId: part.toolCallId,
|
582
|
-
toolName: part.toolName,
|
583
|
-
result: part.result,
|
584
|
-
content: part.experimental_content,
|
585
|
-
isError: part.isError,
|
586
|
-
providerMetadata: (_a10 = part.providerOptions) != null ? _a10 : part.experimental_providerMetadata
|
587
|
-
};
|
588
|
-
}),
|
589
|
-
providerMetadata: (_f = message.providerOptions) != null ? _f : message.experimental_providerMetadata
|
590
|
-
};
|
591
|
-
}
|
592
|
-
default: {
|
593
|
-
const _exhaustiveCheck = role;
|
594
|
-
throw new InvalidMessageRoleError({ role: _exhaustiveCheck });
|
595
|
-
}
|
596
|
-
}
|
597
|
-
}
|
598
|
-
async function downloadAssets(messages, downloadImplementation, modelSupportsImageUrls, modelSupportsUrl) {
|
599
|
-
const urls = messages.filter((message) => message.role === "user").map((message) => message.content).filter(
|
600
|
-
(content) => Array.isArray(content)
|
601
|
-
).flat().filter(
|
602
|
-
(part) => part.type === "image" || part.type === "file"
|
603
|
-
).filter(
|
604
|
-
(part) => !(part.type === "image" && modelSupportsImageUrls === true)
|
605
|
-
).map((part) => part.type === "image" ? part.image : part.data).map(
|
606
|
-
(part) => (
|
607
|
-
// support string urls:
|
608
|
-
typeof part === "string" && (part.startsWith("http:") || part.startsWith("https:")) ? new URL(part) : part
|
609
|
-
)
|
610
|
-
).filter((image) => image instanceof URL).filter((url) => !modelSupportsUrl(url));
|
611
|
-
const downloadedImages = await Promise.all(
|
612
|
-
urls.map(async (url) => ({
|
613
|
-
url,
|
614
|
-
data: await downloadImplementation({ url })
|
615
|
-
}))
|
616
|
-
);
|
617
|
-
return Object.fromEntries(
|
618
|
-
downloadedImages.map(({ url, data }) => [url.toString(), data])
|
619
|
-
);
|
620
|
-
}
|
621
|
-
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
622
|
-
var _a9, _b, _c, _d;
|
623
|
-
if (part.type === "text") {
|
624
|
-
return {
|
625
|
-
type: "text",
|
626
|
-
text: part.text,
|
627
|
-
providerMetadata: (_a9 = part.providerOptions) != null ? _a9 : part.experimental_providerMetadata
|
628
|
-
};
|
629
|
-
}
|
630
|
-
let mimeType = part.mimeType;
|
631
|
-
let data;
|
632
|
-
let content;
|
633
|
-
let normalizedData;
|
634
|
-
const type = part.type;
|
635
|
-
switch (type) {
|
636
|
-
case "image":
|
637
|
-
data = part.image;
|
638
|
-
break;
|
639
|
-
case "file":
|
640
|
-
data = part.data;
|
641
|
-
break;
|
642
|
-
default:
|
643
|
-
throw new Error(`Unsupported part type: ${type}`);
|
644
|
-
}
|
645
|
-
try {
|
646
|
-
content = typeof data === "string" ? new URL(data) : data;
|
647
|
-
} catch (error) {
|
648
|
-
content = data;
|
649
|
-
}
|
650
|
-
if (content instanceof URL) {
|
651
|
-
if (content.protocol === "data:") {
|
652
|
-
const { mimeType: dataUrlMimeType, base64Content } = splitDataUrl(
|
653
|
-
content.toString()
|
654
|
-
);
|
655
|
-
if (dataUrlMimeType == null || base64Content == null) {
|
656
|
-
throw new Error(`Invalid data URL format in part ${type}`);
|
657
|
-
}
|
658
|
-
mimeType = dataUrlMimeType;
|
659
|
-
normalizedData = convertDataContentToUint8Array(base64Content);
|
660
|
-
} else {
|
661
|
-
const downloadedFile = downloadedAssets[content.toString()];
|
662
|
-
if (downloadedFile) {
|
663
|
-
normalizedData = downloadedFile.data;
|
664
|
-
mimeType != null ? mimeType : mimeType = downloadedFile.mimeType;
|
665
|
-
} else {
|
666
|
-
normalizedData = content;
|
667
|
-
}
|
668
|
-
}
|
669
|
-
} else {
|
670
|
-
normalizedData = convertDataContentToUint8Array(content);
|
671
|
-
}
|
672
|
-
switch (type) {
|
673
|
-
case "image": {
|
674
|
-
if (normalizedData instanceof Uint8Array) {
|
675
|
-
mimeType = (_b = detectImageMimeType(normalizedData)) != null ? _b : mimeType;
|
676
|
-
}
|
677
|
-
return {
|
678
|
-
type: "image",
|
679
|
-
image: normalizedData,
|
680
|
-
mimeType,
|
681
|
-
providerMetadata: (_c = part.providerOptions) != null ? _c : part.experimental_providerMetadata
|
682
|
-
};
|
683
|
-
}
|
684
|
-
case "file": {
|
685
|
-
if (mimeType == null) {
|
686
|
-
throw new Error(`Mime type is missing for file part`);
|
687
|
-
}
|
688
|
-
return {
|
689
|
-
type: "file",
|
690
|
-
data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
|
691
|
-
filename: part.filename,
|
692
|
-
mimeType,
|
693
|
-
providerMetadata: (_d = part.providerOptions) != null ? _d : part.experimental_providerMetadata
|
694
|
-
};
|
695
|
-
}
|
696
|
-
}
|
697
|
-
}
|
698
|
-
|
699
|
-
// errors/invalid-argument-error.ts
|
700
|
-
import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
|
701
|
-
var name4 = "AI_InvalidArgumentError";
|
702
|
-
var marker4 = `vercel.ai.error.${name4}`;
|
703
|
-
var symbol4 = Symbol.for(marker4);
|
704
|
-
var _a4;
|
705
|
-
var InvalidArgumentError = class extends AISDKError4 {
|
706
|
-
constructor({
|
707
|
-
parameter,
|
708
|
-
value,
|
709
|
-
message
|
710
|
-
}) {
|
711
|
-
super({
|
712
|
-
name: name4,
|
713
|
-
message: `Invalid argument for parameter ${parameter}: ${message}`
|
714
|
-
});
|
715
|
-
this[_a4] = true;
|
716
|
-
this.parameter = parameter;
|
717
|
-
this.value = value;
|
718
|
-
}
|
719
|
-
static isInstance(error) {
|
720
|
-
return AISDKError4.hasMarker(error, marker4);
|
721
|
-
}
|
722
|
-
};
|
723
|
-
_a4 = symbol4;
|
724
|
-
|
725
|
-
// core/prompt/prepare-call-settings.ts
|
726
|
-
function prepareCallSettings({
|
727
|
-
maxTokens,
|
728
|
-
temperature,
|
729
|
-
topP,
|
730
|
-
topK,
|
731
|
-
presencePenalty,
|
732
|
-
frequencyPenalty,
|
733
|
-
stopSequences,
|
734
|
-
seed
|
735
|
-
}) {
|
736
|
-
if (maxTokens != null) {
|
737
|
-
if (!Number.isInteger(maxTokens)) {
|
738
|
-
throw new InvalidArgumentError({
|
739
|
-
parameter: "maxTokens",
|
740
|
-
value: maxTokens,
|
741
|
-
message: "maxTokens must be an integer"
|
742
|
-
});
|
743
|
-
}
|
744
|
-
if (maxTokens < 1) {
|
745
|
-
throw new InvalidArgumentError({
|
746
|
-
parameter: "maxTokens",
|
747
|
-
value: maxTokens,
|
748
|
-
message: "maxTokens must be >= 1"
|
749
|
-
});
|
750
|
-
}
|
751
|
-
}
|
752
|
-
if (temperature != null) {
|
753
|
-
if (typeof temperature !== "number") {
|
754
|
-
throw new InvalidArgumentError({
|
755
|
-
parameter: "temperature",
|
756
|
-
value: temperature,
|
757
|
-
message: "temperature must be a number"
|
758
|
-
});
|
759
|
-
}
|
760
|
-
}
|
761
|
-
if (topP != null) {
|
762
|
-
if (typeof topP !== "number") {
|
763
|
-
throw new InvalidArgumentError({
|
764
|
-
parameter: "topP",
|
765
|
-
value: topP,
|
766
|
-
message: "topP must be a number"
|
767
|
-
});
|
768
|
-
}
|
769
|
-
}
|
770
|
-
if (topK != null) {
|
771
|
-
if (typeof topK !== "number") {
|
772
|
-
throw new InvalidArgumentError({
|
773
|
-
parameter: "topK",
|
774
|
-
value: topK,
|
775
|
-
message: "topK must be a number"
|
776
|
-
});
|
777
|
-
}
|
778
|
-
}
|
779
|
-
if (presencePenalty != null) {
|
780
|
-
if (typeof presencePenalty !== "number") {
|
781
|
-
throw new InvalidArgumentError({
|
782
|
-
parameter: "presencePenalty",
|
783
|
-
value: presencePenalty,
|
784
|
-
message: "presencePenalty must be a number"
|
785
|
-
});
|
786
|
-
}
|
787
|
-
}
|
788
|
-
if (frequencyPenalty != null) {
|
789
|
-
if (typeof frequencyPenalty !== "number") {
|
790
|
-
throw new InvalidArgumentError({
|
791
|
-
parameter: "frequencyPenalty",
|
792
|
-
value: frequencyPenalty,
|
793
|
-
message: "frequencyPenalty must be a number"
|
794
|
-
});
|
795
|
-
}
|
796
|
-
}
|
797
|
-
if (seed != null) {
|
798
|
-
if (!Number.isInteger(seed)) {
|
799
|
-
throw new InvalidArgumentError({
|
800
|
-
parameter: "seed",
|
801
|
-
value: seed,
|
802
|
-
message: "seed must be an integer"
|
803
|
-
});
|
804
|
-
}
|
805
|
-
}
|
806
|
-
return {
|
807
|
-
maxTokens,
|
808
|
-
// TODO v5 remove default 0 for temperature
|
809
|
-
temperature: temperature != null ? temperature : 0,
|
810
|
-
topP,
|
811
|
-
topK,
|
812
|
-
presencePenalty,
|
813
|
-
frequencyPenalty,
|
814
|
-
stopSequences: stopSequences != null && stopSequences.length > 0 ? stopSequences : void 0,
|
815
|
-
seed
|
816
|
-
};
|
817
|
-
}
|
818
|
-
|
819
|
-
// util/retry-with-exponential-backoff.ts
|
820
|
-
import { APICallError } from "@ai-sdk/provider";
|
821
|
-
import { delay, getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
|
822
|
-
|
823
|
-
// util/retry-error.ts
|
824
|
-
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
825
|
-
var name5 = "AI_RetryError";
|
826
|
-
var marker5 = `vercel.ai.error.${name5}`;
|
827
|
-
var symbol5 = Symbol.for(marker5);
|
828
|
-
var _a5;
|
829
|
-
var RetryError = class extends AISDKError5 {
|
830
|
-
constructor({
|
831
|
-
message,
|
832
|
-
reason,
|
833
|
-
errors
|
834
|
-
}) {
|
835
|
-
super({ name: name5, message });
|
836
|
-
this[_a5] = true;
|
837
|
-
this.reason = reason;
|
838
|
-
this.errors = errors;
|
839
|
-
this.lastError = errors[errors.length - 1];
|
840
|
-
}
|
841
|
-
static isInstance(error) {
|
842
|
-
return AISDKError5.hasMarker(error, marker5);
|
843
|
-
}
|
844
|
-
};
|
845
|
-
_a5 = symbol5;
|
846
|
-
|
847
|
-
// util/retry-with-exponential-backoff.ts
|
848
|
-
var retryWithExponentialBackoff = ({
|
849
|
-
maxRetries = 2,
|
850
|
-
initialDelayInMs = 2e3,
|
851
|
-
backoffFactor = 2
|
852
|
-
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
853
|
-
maxRetries,
|
854
|
-
delayInMs: initialDelayInMs,
|
855
|
-
backoffFactor
|
856
|
-
});
|
857
|
-
async function _retryWithExponentialBackoff(f, {
|
858
|
-
maxRetries,
|
859
|
-
delayInMs,
|
860
|
-
backoffFactor
|
861
|
-
}, errors = []) {
|
862
|
-
try {
|
863
|
-
return await f();
|
864
|
-
} catch (error) {
|
865
|
-
if (isAbortError(error)) {
|
866
|
-
throw error;
|
867
|
-
}
|
868
|
-
if (maxRetries === 0) {
|
869
|
-
throw error;
|
870
|
-
}
|
871
|
-
const errorMessage = getErrorMessage(error);
|
872
|
-
const newErrors = [...errors, error];
|
873
|
-
const tryNumber = newErrors.length;
|
874
|
-
if (tryNumber > maxRetries) {
|
875
|
-
throw new RetryError({
|
876
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
877
|
-
reason: "maxRetriesExceeded",
|
878
|
-
errors: newErrors
|
879
|
-
});
|
880
|
-
}
|
881
|
-
if (error instanceof Error && APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
882
|
-
await delay(delayInMs);
|
883
|
-
return _retryWithExponentialBackoff(
|
884
|
-
f,
|
885
|
-
{ maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
|
886
|
-
newErrors
|
887
|
-
);
|
888
|
-
}
|
889
|
-
if (tryNumber === 1) {
|
890
|
-
throw error;
|
891
|
-
}
|
892
|
-
throw new RetryError({
|
893
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
894
|
-
reason: "errorNotRetryable",
|
895
|
-
errors: newErrors
|
896
|
-
});
|
897
|
-
}
|
898
|
-
}
|
899
|
-
|
900
|
-
// core/prompt/prepare-retries.ts
|
901
|
-
function prepareRetries({
|
902
|
-
maxRetries
|
903
|
-
}) {
|
904
|
-
if (maxRetries != null) {
|
905
|
-
if (!Number.isInteger(maxRetries)) {
|
906
|
-
throw new InvalidArgumentError({
|
907
|
-
parameter: "maxRetries",
|
908
|
-
value: maxRetries,
|
909
|
-
message: "maxRetries must be an integer"
|
910
|
-
});
|
911
|
-
}
|
912
|
-
if (maxRetries < 0) {
|
913
|
-
throw new InvalidArgumentError({
|
914
|
-
parameter: "maxRetries",
|
915
|
-
value: maxRetries,
|
916
|
-
message: "maxRetries must be >= 0"
|
917
|
-
});
|
918
|
-
}
|
919
|
-
}
|
920
|
-
const maxRetriesResult = maxRetries != null ? maxRetries : 2;
|
921
|
-
return {
|
922
|
-
maxRetries: maxRetriesResult,
|
923
|
-
retry: retryWithExponentialBackoff({ maxRetries: maxRetriesResult })
|
924
|
-
};
|
925
|
-
}
|
926
|
-
|
927
|
-
// core/prompt/prepare-tools-and-tool-choice.ts
|
928
|
-
import { asSchema } from "@ai-sdk/ui-utils";
|
929
|
-
|
930
|
-
// core/util/is-non-empty-object.ts
|
931
|
-
function isNonEmptyObject(object) {
|
932
|
-
return object != null && Object.keys(object).length > 0;
|
933
|
-
}
|
934
|
-
|
935
|
-
// core/prompt/prepare-tools-and-tool-choice.ts
|
936
|
-
function prepareToolsAndToolChoice({
|
937
|
-
tools,
|
938
|
-
toolChoice,
|
939
|
-
activeTools
|
940
|
-
}) {
|
941
|
-
if (!isNonEmptyObject(tools)) {
|
942
|
-
return {
|
943
|
-
tools: void 0,
|
944
|
-
toolChoice: void 0
|
945
|
-
};
|
946
|
-
}
|
947
|
-
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
948
|
-
([name9]) => activeTools.includes(name9)
|
949
|
-
) : Object.entries(tools);
|
950
|
-
return {
|
951
|
-
tools: filteredTools.map(([name9, tool]) => {
|
952
|
-
const toolType = tool.type;
|
953
|
-
switch (toolType) {
|
954
|
-
case void 0:
|
955
|
-
case "function":
|
956
|
-
return {
|
957
|
-
type: "function",
|
958
|
-
name: name9,
|
959
|
-
description: tool.description,
|
960
|
-
parameters: asSchema(tool.parameters).jsonSchema
|
961
|
-
};
|
962
|
-
case "provider-defined":
|
963
|
-
return {
|
964
|
-
type: "provider-defined",
|
965
|
-
name: name9,
|
966
|
-
id: tool.id,
|
967
|
-
args: tool.args
|
968
|
-
};
|
969
|
-
default: {
|
970
|
-
const exhaustiveCheck = toolType;
|
971
|
-
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
972
|
-
}
|
973
|
-
}
|
974
|
-
}),
|
975
|
-
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
976
|
-
};
|
977
|
-
}
|
978
|
-
|
979
|
-
// core/prompt/standardize-prompt.ts
|
980
|
-
import { InvalidPromptError } from "@ai-sdk/provider";
|
981
|
-
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
982
|
-
import { z as z7 } from "zod";
|
983
|
-
|
984
|
-
// core/prompt/attachments-to-parts.ts
|
985
|
-
function attachmentsToParts(attachments) {
|
986
|
-
var _a9, _b, _c;
|
987
|
-
const parts = [];
|
988
|
-
for (const attachment of attachments) {
|
989
|
-
let url;
|
990
|
-
try {
|
991
|
-
url = new URL(attachment.url);
|
992
|
-
} catch (error) {
|
993
|
-
throw new Error(`Invalid URL: ${attachment.url}`);
|
994
|
-
}
|
995
|
-
switch (url.protocol) {
|
996
|
-
case "http:":
|
997
|
-
case "https:": {
|
998
|
-
if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
|
999
|
-
parts.push({ type: "image", image: url });
|
1000
|
-
} else {
|
1001
|
-
if (!attachment.contentType) {
|
1002
|
-
throw new Error(
|
1003
|
-
"If the attachment is not an image, it must specify a content type"
|
1004
|
-
);
|
1005
|
-
}
|
1006
|
-
parts.push({
|
1007
|
-
type: "file",
|
1008
|
-
data: url,
|
1009
|
-
mimeType: attachment.contentType
|
1010
|
-
});
|
1011
|
-
}
|
1012
|
-
break;
|
1013
|
-
}
|
1014
|
-
case "data:": {
|
1015
|
-
let header;
|
1016
|
-
let base64Content;
|
1017
|
-
let mimeType;
|
1018
|
-
try {
|
1019
|
-
[header, base64Content] = attachment.url.split(",");
|
1020
|
-
mimeType = header.split(";")[0].split(":")[1];
|
1021
|
-
} catch (error) {
|
1022
|
-
throw new Error(`Error processing data URL: ${attachment.url}`);
|
1023
|
-
}
|
1024
|
-
if (mimeType == null || base64Content == null) {
|
1025
|
-
throw new Error(`Invalid data URL format: ${attachment.url}`);
|
1026
|
-
}
|
1027
|
-
if ((_b = attachment.contentType) == null ? void 0 : _b.startsWith("image/")) {
|
1028
|
-
parts.push({
|
1029
|
-
type: "image",
|
1030
|
-
image: convertDataContentToUint8Array(base64Content)
|
1031
|
-
});
|
1032
|
-
} else if ((_c = attachment.contentType) == null ? void 0 : _c.startsWith("text/")) {
|
1033
|
-
parts.push({
|
1034
|
-
type: "text",
|
1035
|
-
text: convertUint8ArrayToText(
|
1036
|
-
convertDataContentToUint8Array(base64Content)
|
1037
|
-
)
|
1038
|
-
});
|
1039
|
-
} else {
|
1040
|
-
if (!attachment.contentType) {
|
1041
|
-
throw new Error(
|
1042
|
-
"If the attachment is not an image or text, it must specify a content type"
|
1043
|
-
);
|
1044
|
-
}
|
1045
|
-
parts.push({
|
1046
|
-
type: "file",
|
1047
|
-
data: base64Content,
|
1048
|
-
mimeType: attachment.contentType
|
1049
|
-
});
|
1050
|
-
}
|
1051
|
-
break;
|
1052
|
-
}
|
1053
|
-
default: {
|
1054
|
-
throw new Error(`Unsupported URL protocol: ${url.protocol}`);
|
1055
|
-
}
|
1056
|
-
}
|
1057
|
-
}
|
1058
|
-
return parts;
|
1059
|
-
}
|
1060
|
-
|
1061
|
-
// core/prompt/message-conversion-error.ts
|
1062
|
-
import { AISDKError as AISDKError6 } from "@ai-sdk/provider";
|
1063
|
-
var name6 = "AI_MessageConversionError";
|
1064
|
-
var marker6 = `vercel.ai.error.${name6}`;
|
1065
|
-
var symbol6 = Symbol.for(marker6);
|
1066
|
-
var _a6;
|
1067
|
-
var MessageConversionError = class extends AISDKError6 {
|
1068
|
-
constructor({
|
1069
|
-
originalMessage,
|
1070
|
-
message
|
1071
|
-
}) {
|
1072
|
-
super({ name: name6, message });
|
1073
|
-
this[_a6] = true;
|
1074
|
-
this.originalMessage = originalMessage;
|
1075
|
-
}
|
1076
|
-
static isInstance(error) {
|
1077
|
-
return AISDKError6.hasMarker(error, marker6);
|
1078
|
-
}
|
1079
|
-
};
|
1080
|
-
_a6 = symbol6;
|
1081
|
-
|
1082
|
-
// core/prompt/convert-to-core-messages.ts
|
1083
|
-
function convertToCoreMessages(messages, options) {
|
1084
|
-
var _a9, _b;
|
1085
|
-
const tools = (_a9 = options == null ? void 0 : options.tools) != null ? _a9 : {};
|
1086
|
-
const coreMessages = [];
|
1087
|
-
for (let i = 0; i < messages.length; i++) {
|
1088
|
-
const message = messages[i];
|
1089
|
-
const isLastMessage = i === messages.length - 1;
|
1090
|
-
const { role, content, experimental_attachments } = message;
|
1091
|
-
switch (role) {
|
1092
|
-
case "system": {
|
1093
|
-
coreMessages.push({
|
1094
|
-
role: "system",
|
1095
|
-
content
|
1096
|
-
});
|
1097
|
-
break;
|
1098
|
-
}
|
1099
|
-
case "user": {
|
1100
|
-
if (message.parts == null) {
|
1101
|
-
coreMessages.push({
|
1102
|
-
role: "user",
|
1103
|
-
content: experimental_attachments ? [
|
1104
|
-
{ type: "text", text: content },
|
1105
|
-
...attachmentsToParts(experimental_attachments)
|
1106
|
-
] : content
|
1107
|
-
});
|
1108
|
-
} else {
|
1109
|
-
const textParts = message.parts.filter((part) => part.type === "text").map((part) => ({
|
1110
|
-
type: "text",
|
1111
|
-
text: part.text
|
1112
|
-
}));
|
1113
|
-
coreMessages.push({
|
1114
|
-
role: "user",
|
1115
|
-
content: experimental_attachments ? [...textParts, ...attachmentsToParts(experimental_attachments)] : textParts
|
1116
|
-
});
|
1117
|
-
}
|
1118
|
-
break;
|
1119
|
-
}
|
1120
|
-
case "assistant": {
|
1121
|
-
if (message.parts != null) {
|
1122
|
-
let processBlock2 = function() {
|
1123
|
-
const content2 = [];
|
1124
|
-
for (const part of block) {
|
1125
|
-
switch (part.type) {
|
1126
|
-
case "file":
|
1127
|
-
case "text": {
|
1128
|
-
content2.push(part);
|
1129
|
-
break;
|
1130
|
-
}
|
1131
|
-
case "reasoning": {
|
1132
|
-
for (const detail of part.details) {
|
1133
|
-
switch (detail.type) {
|
1134
|
-
case "text":
|
1135
|
-
content2.push({
|
1136
|
-
type: "reasoning",
|
1137
|
-
text: detail.text,
|
1138
|
-
signature: detail.signature
|
1139
|
-
});
|
1140
|
-
break;
|
1141
|
-
case "redacted":
|
1142
|
-
content2.push({
|
1143
|
-
type: "redacted-reasoning",
|
1144
|
-
data: detail.data
|
1145
|
-
});
|
1146
|
-
break;
|
1147
|
-
}
|
1148
|
-
}
|
1149
|
-
break;
|
1150
|
-
}
|
1151
|
-
case "tool-invocation":
|
1152
|
-
content2.push({
|
1153
|
-
type: "tool-call",
|
1154
|
-
toolCallId: part.toolInvocation.toolCallId,
|
1155
|
-
toolName: part.toolInvocation.toolName,
|
1156
|
-
args: part.toolInvocation.args
|
1157
|
-
});
|
1158
|
-
break;
|
1159
|
-
default: {
|
1160
|
-
const _exhaustiveCheck = part;
|
1161
|
-
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
1162
|
-
}
|
1163
|
-
}
|
1164
|
-
}
|
1165
|
-
coreMessages.push({
|
1166
|
-
role: "assistant",
|
1167
|
-
content: content2
|
1168
|
-
});
|
1169
|
-
const stepInvocations = block.filter(
|
1170
|
-
(part) => part.type === "tool-invocation"
|
1171
|
-
).map((part) => part.toolInvocation);
|
1172
|
-
if (stepInvocations.length > 0) {
|
1173
|
-
coreMessages.push({
|
1174
|
-
role: "tool",
|
1175
|
-
content: stepInvocations.map(
|
1176
|
-
(toolInvocation) => {
|
1177
|
-
if (!("result" in toolInvocation)) {
|
1178
|
-
throw new MessageConversionError({
|
1179
|
-
originalMessage: message,
|
1180
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
1181
|
-
});
|
1182
|
-
}
|
1183
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
1184
|
-
const tool = tools[toolName];
|
1185
|
-
return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
|
1186
|
-
type: "tool-result",
|
1187
|
-
toolCallId,
|
1188
|
-
toolName,
|
1189
|
-
result: tool.experimental_toToolResultContent(result),
|
1190
|
-
experimental_content: tool.experimental_toToolResultContent(result)
|
1191
|
-
} : {
|
1192
|
-
type: "tool-result",
|
1193
|
-
toolCallId,
|
1194
|
-
toolName,
|
1195
|
-
result
|
1196
|
-
};
|
1197
|
-
}
|
1198
|
-
)
|
1199
|
-
});
|
1200
|
-
}
|
1201
|
-
block = [];
|
1202
|
-
blockHasToolInvocations = false;
|
1203
|
-
currentStep++;
|
1204
|
-
};
|
1205
|
-
var processBlock = processBlock2;
|
1206
|
-
let currentStep = 0;
|
1207
|
-
let blockHasToolInvocations = false;
|
1208
|
-
let block = [];
|
1209
|
-
for (const part of message.parts) {
|
1210
|
-
switch (part.type) {
|
1211
|
-
case "text": {
|
1212
|
-
if (blockHasToolInvocations) {
|
1213
|
-
processBlock2();
|
1214
|
-
}
|
1215
|
-
block.push(part);
|
1216
|
-
break;
|
1217
|
-
}
|
1218
|
-
case "file":
|
1219
|
-
case "reasoning": {
|
1220
|
-
block.push(part);
|
1221
|
-
break;
|
1222
|
-
}
|
1223
|
-
case "tool-invocation": {
|
1224
|
-
if (((_b = part.toolInvocation.step) != null ? _b : 0) !== currentStep) {
|
1225
|
-
processBlock2();
|
1226
|
-
}
|
1227
|
-
block.push(part);
|
1228
|
-
blockHasToolInvocations = true;
|
1229
|
-
break;
|
1230
|
-
}
|
1231
|
-
}
|
1232
|
-
}
|
1233
|
-
processBlock2();
|
1234
|
-
break;
|
1235
|
-
}
|
1236
|
-
const toolInvocations = message.toolInvocations;
|
1237
|
-
if (toolInvocations == null || toolInvocations.length === 0) {
|
1238
|
-
coreMessages.push({ role: "assistant", content });
|
1239
|
-
break;
|
1240
|
-
}
|
1241
|
-
const maxStep = toolInvocations.reduce((max, toolInvocation) => {
|
1242
|
-
var _a10;
|
1243
|
-
return Math.max(max, (_a10 = toolInvocation.step) != null ? _a10 : 0);
|
1244
|
-
}, 0);
|
1245
|
-
for (let i2 = 0; i2 <= maxStep; i2++) {
|
1246
|
-
const stepInvocations = toolInvocations.filter(
|
1247
|
-
(toolInvocation) => {
|
1248
|
-
var _a10;
|
1249
|
-
return ((_a10 = toolInvocation.step) != null ? _a10 : 0) === i2;
|
1250
|
-
}
|
1251
|
-
);
|
1252
|
-
if (stepInvocations.length === 0) {
|
1253
|
-
continue;
|
1254
|
-
}
|
1255
|
-
coreMessages.push({
|
1256
|
-
role: "assistant",
|
1257
|
-
content: [
|
1258
|
-
...isLastMessage && content && i2 === 0 ? [{ type: "text", text: content }] : [],
|
1259
|
-
...stepInvocations.map(
|
1260
|
-
({ toolCallId, toolName, args }) => ({
|
1261
|
-
type: "tool-call",
|
1262
|
-
toolCallId,
|
1263
|
-
toolName,
|
1264
|
-
args
|
1265
|
-
})
|
1266
|
-
)
|
1267
|
-
]
|
1268
|
-
});
|
1269
|
-
coreMessages.push({
|
1270
|
-
role: "tool",
|
1271
|
-
content: stepInvocations.map((toolInvocation) => {
|
1272
|
-
if (!("result" in toolInvocation)) {
|
1273
|
-
throw new MessageConversionError({
|
1274
|
-
originalMessage: message,
|
1275
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
1276
|
-
});
|
1277
|
-
}
|
1278
|
-
const { toolCallId, toolName, result } = toolInvocation;
|
1279
|
-
const tool = tools[toolName];
|
1280
|
-
return (tool == null ? void 0 : tool.experimental_toToolResultContent) != null ? {
|
1281
|
-
type: "tool-result",
|
1282
|
-
toolCallId,
|
1283
|
-
toolName,
|
1284
|
-
result: tool.experimental_toToolResultContent(result),
|
1285
|
-
experimental_content: tool.experimental_toToolResultContent(result)
|
1286
|
-
} : {
|
1287
|
-
type: "tool-result",
|
1288
|
-
toolCallId,
|
1289
|
-
toolName,
|
1290
|
-
result
|
1291
|
-
};
|
1292
|
-
})
|
1293
|
-
});
|
1294
|
-
}
|
1295
|
-
if (content && !isLastMessage) {
|
1296
|
-
coreMessages.push({ role: "assistant", content });
|
1297
|
-
}
|
1298
|
-
break;
|
1299
|
-
}
|
1300
|
-
case "data": {
|
1301
|
-
break;
|
1302
|
-
}
|
1303
|
-
default: {
|
1304
|
-
const _exhaustiveCheck = role;
|
1305
|
-
throw new MessageConversionError({
|
1306
|
-
originalMessage: message,
|
1307
|
-
message: `Unsupported role: ${_exhaustiveCheck}`
|
1308
|
-
});
|
1309
|
-
}
|
1310
|
-
}
|
1311
|
-
}
|
1312
|
-
return coreMessages;
|
1313
|
-
}
|
1314
|
-
|
1315
|
-
// core/prompt/detect-prompt-type.ts
|
1316
|
-
function detectPromptType(prompt) {
|
1317
|
-
if (!Array.isArray(prompt)) {
|
1318
|
-
return "other";
|
1319
|
-
}
|
1320
|
-
if (prompt.length === 0) {
|
1321
|
-
return "messages";
|
1322
|
-
}
|
1323
|
-
const characteristics = prompt.map(detectSingleMessageCharacteristics);
|
1324
|
-
if (characteristics.some((c) => c === "has-ui-specific-parts")) {
|
1325
|
-
return "ui-messages";
|
1326
|
-
} else if (characteristics.every(
|
1327
|
-
(c) => c === "has-core-specific-parts" || c === "message"
|
1328
|
-
)) {
|
1329
|
-
return "messages";
|
1330
|
-
} else {
|
1331
|
-
return "other";
|
1332
|
-
}
|
1333
|
-
}
|
1334
|
-
function detectSingleMessageCharacteristics(message) {
|
1335
|
-
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
1336
|
-
message.role === "data" || // UI-only role
|
1337
|
-
"toolInvocations" in message || // UI-specific field
|
1338
|
-
"parts" in message || // UI-specific field
|
1339
|
-
"experimental_attachments" in message)) {
|
1340
|
-
return "has-ui-specific-parts";
|
1341
|
-
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
1342
|
-
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
1343
|
-
return "has-core-specific-parts";
|
1344
|
-
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
1345
|
-
return "message";
|
1346
|
-
} else {
|
1347
|
-
return "other";
|
1348
|
-
}
|
1349
|
-
}
|
1350
|
-
|
1351
|
-
// core/prompt/message.ts
|
1352
|
-
import { z as z6 } from "zod";
|
1353
|
-
|
1354
|
-
// core/types/provider-metadata.ts
|
1355
|
-
import { z as z3 } from "zod";
|
1356
|
-
|
1357
|
-
// core/types/json-value.ts
|
1358
|
-
import { z as z2 } from "zod";
|
1359
|
-
var jsonValueSchema = z2.lazy(
|
1360
|
-
() => z2.union([
|
1361
|
-
z2.null(),
|
1362
|
-
z2.string(),
|
1363
|
-
z2.number(),
|
1364
|
-
z2.boolean(),
|
1365
|
-
z2.record(z2.string(), jsonValueSchema),
|
1366
|
-
z2.array(jsonValueSchema)
|
1367
|
-
])
|
1368
|
-
);
|
1369
|
-
|
1370
|
-
// core/types/provider-metadata.ts
|
1371
|
-
var providerMetadataSchema = z3.record(
|
1372
|
-
z3.string(),
|
1373
|
-
z3.record(z3.string(), jsonValueSchema)
|
1374
|
-
);
|
1375
|
-
|
1376
|
-
// core/prompt/content-part.ts
|
1377
|
-
import { z as z5 } from "zod";
|
1378
|
-
|
1379
|
-
// core/prompt/tool-result-content.ts
|
1380
|
-
import { z as z4 } from "zod";
|
1381
|
-
var toolResultContentSchema = z4.array(
|
1382
|
-
z4.union([
|
1383
|
-
z4.object({ type: z4.literal("text"), text: z4.string() }),
|
1384
|
-
z4.object({
|
1385
|
-
type: z4.literal("image"),
|
1386
|
-
data: z4.string(),
|
1387
|
-
mimeType: z4.string().optional()
|
1388
|
-
})
|
1389
|
-
])
|
1390
|
-
);
|
1391
|
-
|
1392
|
-
// core/prompt/content-part.ts
|
1393
|
-
var textPartSchema = z5.object({
|
1394
|
-
type: z5.literal("text"),
|
1395
|
-
text: z5.string(),
|
1396
|
-
providerOptions: providerMetadataSchema.optional(),
|
1397
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1398
|
-
});
|
1399
|
-
var imagePartSchema = z5.object({
|
1400
|
-
type: z5.literal("image"),
|
1401
|
-
image: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
1402
|
-
mimeType: z5.string().optional(),
|
1403
|
-
providerOptions: providerMetadataSchema.optional(),
|
1404
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1405
|
-
});
|
1406
|
-
var filePartSchema = z5.object({
|
1407
|
-
type: z5.literal("file"),
|
1408
|
-
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
1409
|
-
filename: z5.string().optional(),
|
1410
|
-
mimeType: z5.string(),
|
1411
|
-
providerOptions: providerMetadataSchema.optional(),
|
1412
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1413
|
-
});
|
1414
|
-
var reasoningPartSchema = z5.object({
|
1415
|
-
type: z5.literal("reasoning"),
|
1416
|
-
text: z5.string(),
|
1417
|
-
providerOptions: providerMetadataSchema.optional(),
|
1418
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1419
|
-
});
|
1420
|
-
var redactedReasoningPartSchema = z5.object({
|
1421
|
-
type: z5.literal("redacted-reasoning"),
|
1422
|
-
data: z5.string(),
|
1423
|
-
providerOptions: providerMetadataSchema.optional(),
|
1424
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1425
|
-
});
|
1426
|
-
var toolCallPartSchema = z5.object({
|
1427
|
-
type: z5.literal("tool-call"),
|
1428
|
-
toolCallId: z5.string(),
|
1429
|
-
toolName: z5.string(),
|
1430
|
-
args: z5.unknown(),
|
1431
|
-
providerOptions: providerMetadataSchema.optional(),
|
1432
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1433
|
-
});
|
1434
|
-
var toolResultPartSchema = z5.object({
|
1435
|
-
type: z5.literal("tool-result"),
|
1436
|
-
toolCallId: z5.string(),
|
1437
|
-
toolName: z5.string(),
|
1438
|
-
result: z5.unknown(),
|
1439
|
-
content: toolResultContentSchema.optional(),
|
1440
|
-
isError: z5.boolean().optional(),
|
1441
|
-
providerOptions: providerMetadataSchema.optional(),
|
1442
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1443
|
-
});
|
1444
|
-
|
1445
|
-
// core/prompt/message.ts
|
1446
|
-
var coreSystemMessageSchema = z6.object({
|
1447
|
-
role: z6.literal("system"),
|
1448
|
-
content: z6.string(),
|
1449
|
-
providerOptions: providerMetadataSchema.optional(),
|
1450
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1451
|
-
});
|
1452
|
-
var coreUserMessageSchema = z6.object({
|
1453
|
-
role: z6.literal("user"),
|
1454
|
-
content: z6.union([
|
1455
|
-
z6.string(),
|
1456
|
-
z6.array(z6.union([textPartSchema, imagePartSchema, filePartSchema]))
|
1457
|
-
]),
|
1458
|
-
providerOptions: providerMetadataSchema.optional(),
|
1459
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1460
|
-
});
|
1461
|
-
var coreAssistantMessageSchema = z6.object({
|
1462
|
-
role: z6.literal("assistant"),
|
1463
|
-
content: z6.union([
|
1464
|
-
z6.string(),
|
1465
|
-
z6.array(
|
1466
|
-
z6.union([
|
1467
|
-
textPartSchema,
|
1468
|
-
filePartSchema,
|
1469
|
-
reasoningPartSchema,
|
1470
|
-
redactedReasoningPartSchema,
|
1471
|
-
toolCallPartSchema
|
1472
|
-
])
|
1473
|
-
)
|
1474
|
-
]),
|
1475
|
-
providerOptions: providerMetadataSchema.optional(),
|
1476
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1477
|
-
});
|
1478
|
-
var coreToolMessageSchema = z6.object({
|
1479
|
-
role: z6.literal("tool"),
|
1480
|
-
content: z6.array(toolResultPartSchema),
|
1481
|
-
providerOptions: providerMetadataSchema.optional(),
|
1482
|
-
experimental_providerMetadata: providerMetadataSchema.optional()
|
1483
|
-
});
|
1484
|
-
var coreMessageSchema = z6.union([
|
1485
|
-
coreSystemMessageSchema,
|
1486
|
-
coreUserMessageSchema,
|
1487
|
-
coreAssistantMessageSchema,
|
1488
|
-
coreToolMessageSchema
|
1489
|
-
]);
|
1490
|
-
|
1491
|
-
// core/prompt/standardize-prompt.ts
|
1492
|
-
function standardizePrompt({
|
1493
|
-
prompt,
|
1494
|
-
tools
|
1495
|
-
}) {
|
1496
|
-
if (prompt.prompt == null && prompt.messages == null) {
|
1497
|
-
throw new InvalidPromptError({
|
1498
|
-
prompt,
|
1499
|
-
message: "prompt or messages must be defined"
|
1500
|
-
});
|
1501
|
-
}
|
1502
|
-
if (prompt.prompt != null && prompt.messages != null) {
|
1503
|
-
throw new InvalidPromptError({
|
1504
|
-
prompt,
|
1505
|
-
message: "prompt and messages cannot be defined at the same time"
|
1506
|
-
});
|
1507
|
-
}
|
1508
|
-
if (prompt.system != null && typeof prompt.system !== "string") {
|
1509
|
-
throw new InvalidPromptError({
|
1510
|
-
prompt,
|
1511
|
-
message: "system must be a string"
|
1512
|
-
});
|
1513
|
-
}
|
1514
|
-
if (prompt.prompt != null) {
|
1515
|
-
if (typeof prompt.prompt !== "string") {
|
1516
|
-
throw new InvalidPromptError({
|
1517
|
-
prompt,
|
1518
|
-
message: "prompt must be a string"
|
1519
|
-
});
|
1520
|
-
}
|
1521
|
-
return {
|
1522
|
-
type: "prompt",
|
1523
|
-
system: prompt.system,
|
1524
|
-
messages: [
|
1525
|
-
{
|
1526
|
-
role: "user",
|
1527
|
-
content: prompt.prompt
|
1528
|
-
}
|
1529
|
-
]
|
1530
|
-
};
|
1531
|
-
}
|
1532
|
-
if (prompt.messages != null) {
|
1533
|
-
const promptType = detectPromptType(prompt.messages);
|
1534
|
-
if (promptType === "other") {
|
1535
|
-
throw new InvalidPromptError({
|
1536
|
-
prompt,
|
1537
|
-
message: "messages must be an array of CoreMessage or UIMessage"
|
1538
|
-
});
|
1539
|
-
}
|
1540
|
-
const messages = promptType === "ui-messages" ? convertToCoreMessages(prompt.messages, {
|
1541
|
-
tools
|
1542
|
-
}) : prompt.messages;
|
1543
|
-
if (messages.length === 0) {
|
1544
|
-
throw new InvalidPromptError({
|
1545
|
-
prompt,
|
1546
|
-
message: "messages must not be empty"
|
1547
|
-
});
|
1548
|
-
}
|
1549
|
-
const validationResult = safeValidateTypes({
|
1550
|
-
value: messages,
|
1551
|
-
schema: z7.array(coreMessageSchema)
|
1552
|
-
});
|
1553
|
-
if (!validationResult.success) {
|
1554
|
-
throw new InvalidPromptError({
|
1555
|
-
prompt,
|
1556
|
-
message: "messages must be an array of CoreMessage or UIMessage",
|
1557
|
-
cause: validationResult.error
|
1558
|
-
});
|
1559
|
-
}
|
1560
|
-
return {
|
1561
|
-
type: "messages",
|
1562
|
-
messages,
|
1563
|
-
system: prompt.system
|
1564
|
-
};
|
1565
|
-
}
|
1566
|
-
throw new Error("unreachable");
|
1567
|
-
}
|
1568
|
-
|
1569
|
-
// core/types/usage.ts
|
1570
|
-
function calculateLanguageModelUsage({
|
1571
|
-
promptTokens,
|
1572
|
-
completionTokens
|
1573
|
-
}) {
|
1574
|
-
return {
|
1575
|
-
promptTokens,
|
1576
|
-
completionTokens,
|
1577
|
-
totalTokens: promptTokens + completionTokens
|
1578
|
-
};
|
1579
|
-
}
|
1580
|
-
|
1581
|
-
// errors/invalid-tool-arguments-error.ts
|
1582
|
-
import { AISDKError as AISDKError7, getErrorMessage as getErrorMessage2 } from "@ai-sdk/provider";
|
1583
|
-
var name7 = "AI_InvalidToolArgumentsError";
|
1584
|
-
var marker7 = `vercel.ai.error.${name7}`;
|
1585
|
-
var symbol7 = Symbol.for(marker7);
|
1586
|
-
var _a7;
|
1587
|
-
var InvalidToolArgumentsError = class extends AISDKError7 {
|
1588
|
-
constructor({
|
1589
|
-
toolArgs,
|
1590
|
-
toolName,
|
1591
|
-
cause,
|
1592
|
-
message = `Invalid arguments for tool ${toolName}: ${getErrorMessage2(
|
1593
|
-
cause
|
1594
|
-
)}`
|
1595
|
-
}) {
|
1596
|
-
super({ name: name7, message, cause });
|
1597
|
-
this[_a7] = true;
|
1598
|
-
this.toolArgs = toolArgs;
|
1599
|
-
this.toolName = toolName;
|
1600
|
-
}
|
1601
|
-
static isInstance(error) {
|
1602
|
-
return AISDKError7.hasMarker(error, marker7);
|
1603
|
-
}
|
1604
|
-
};
|
1605
|
-
_a7 = symbol7;
|
1606
|
-
|
1607
|
-
// errors/no-such-tool-error.ts
|
1608
|
-
import { AISDKError as AISDKError8 } from "@ai-sdk/provider";
|
1609
|
-
var name8 = "AI_NoSuchToolError";
|
1610
|
-
var marker8 = `vercel.ai.error.${name8}`;
|
1611
|
-
var symbol8 = Symbol.for(marker8);
|
1612
|
-
var _a8;
|
1613
|
-
var NoSuchToolError = class extends AISDKError8 {
|
1614
|
-
constructor({
|
1615
|
-
toolName,
|
1616
|
-
availableTools = void 0,
|
1617
|
-
message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
|
1618
|
-
}) {
|
1619
|
-
super({ name: name8, message });
|
1620
|
-
this[_a8] = true;
|
1621
|
-
this.toolName = toolName;
|
1622
|
-
this.availableTools = availableTools;
|
1623
|
-
}
|
1624
|
-
static isInstance(error) {
|
1625
|
-
return AISDKError8.hasMarker(error, marker8);
|
1626
|
-
}
|
1627
|
-
};
|
1628
|
-
_a8 = symbol8;
|
1629
|
-
|
1630
|
-
// util/is-async-generator.ts
|
1631
|
-
function isAsyncGenerator(value) {
|
1632
|
-
return value != null && typeof value === "object" && Symbol.asyncIterator in value;
|
1633
|
-
}
|
1634
|
-
|
1635
|
-
// util/is-generator.ts
|
1636
|
-
function isGenerator(value) {
|
1637
|
-
return value != null && typeof value === "object" && Symbol.iterator in value;
|
1638
|
-
}
|
1639
|
-
|
1640
|
-
// util/constants.ts
|
1641
|
-
var HANGING_STREAM_WARNING_TIME_MS = 15 * 1e3;
|
1642
|
-
|
1643
|
-
// rsc/streamable-ui/create-suspended-chunk.tsx
|
1644
|
-
import { Suspense } from "react";
|
1645
|
-
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
1646
|
-
var R = [
|
1647
|
-
async ({
|
1648
|
-
c: current,
|
1649
|
-
n: next
|
1650
|
-
}) => {
|
1651
|
-
const chunk = await next;
|
1652
|
-
if (chunk.done) {
|
1653
|
-
return chunk.value;
|
1654
|
-
}
|
1655
|
-
if (chunk.append) {
|
1656
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
1657
|
-
current,
|
1658
|
-
/* @__PURE__ */ jsx2(Suspense, { fallback: chunk.value, children: /* @__PURE__ */ jsx2(R, { c: chunk.value, n: chunk.next }) })
|
1659
|
-
] });
|
1660
|
-
}
|
1661
|
-
return /* @__PURE__ */ jsx2(Suspense, { fallback: chunk.value, children: /* @__PURE__ */ jsx2(R, { c: chunk.value, n: chunk.next }) });
|
1662
|
-
}
|
1663
|
-
][0];
|
1664
|
-
function createSuspendedChunk(initialValue) {
|
1665
|
-
const { promise, resolve, reject } = createResolvablePromise();
|
1666
|
-
return {
|
1667
|
-
row: /* @__PURE__ */ jsx2(Suspense, { fallback: initialValue, children: /* @__PURE__ */ jsx2(R, { c: initialValue, n: promise }) }),
|
1668
|
-
resolve,
|
1669
|
-
reject
|
1670
|
-
};
|
1671
|
-
}
|
1672
|
-
|
1673
|
-
// rsc/streamable-ui/create-streamable-ui.tsx
|
1674
|
-
function createStreamableUI(initialValue) {
|
1675
|
-
let currentValue = initialValue;
|
1676
|
-
let closed = false;
|
1677
|
-
let { row, resolve, reject } = createSuspendedChunk(initialValue);
|
1678
|
-
function assertStream(method) {
|
1679
|
-
if (closed) {
|
1680
|
-
throw new Error(method + ": UI stream is already closed.");
|
1681
|
-
}
|
1682
|
-
}
|
1683
|
-
let warningTimeout;
|
1684
|
-
function warnUnclosedStream() {
|
1685
|
-
if (process.env.NODE_ENV === "development") {
|
1686
|
-
if (warningTimeout) {
|
1687
|
-
clearTimeout(warningTimeout);
|
1688
|
-
}
|
1689
|
-
warningTimeout = setTimeout(() => {
|
1690
|
-
console.warn(
|
1691
|
-
"The streamable UI has been slow to update. This may be a bug or a performance issue or you forgot to call `.done()`."
|
1692
|
-
);
|
1693
|
-
}, HANGING_STREAM_WARNING_TIME_MS);
|
1694
|
-
}
|
1695
|
-
}
|
1696
|
-
warnUnclosedStream();
|
1697
|
-
const streamable = {
|
1698
|
-
value: row,
|
1699
|
-
update(value) {
|
1700
|
-
assertStream(".update()");
|
1701
|
-
if (value === currentValue) {
|
1702
|
-
warnUnclosedStream();
|
1703
|
-
return streamable;
|
1704
|
-
}
|
1705
|
-
const resolvable = createResolvablePromise();
|
1706
|
-
currentValue = value;
|
1707
|
-
resolve({ value: currentValue, done: false, next: resolvable.promise });
|
1708
|
-
resolve = resolvable.resolve;
|
1709
|
-
reject = resolvable.reject;
|
1710
|
-
warnUnclosedStream();
|
1711
|
-
return streamable;
|
1712
|
-
},
|
1713
|
-
append(value) {
|
1714
|
-
assertStream(".append()");
|
1715
|
-
const resolvable = createResolvablePromise();
|
1716
|
-
currentValue = value;
|
1717
|
-
resolve({ value, done: false, append: true, next: resolvable.promise });
|
1718
|
-
resolve = resolvable.resolve;
|
1719
|
-
reject = resolvable.reject;
|
1720
|
-
warnUnclosedStream();
|
1721
|
-
return streamable;
|
1722
|
-
},
|
1723
|
-
error(error) {
|
1724
|
-
assertStream(".error()");
|
1725
|
-
if (warningTimeout) {
|
1726
|
-
clearTimeout(warningTimeout);
|
1727
|
-
}
|
1728
|
-
closed = true;
|
1729
|
-
reject(error);
|
1730
|
-
return streamable;
|
1731
|
-
},
|
1732
|
-
done(...args) {
|
1733
|
-
assertStream(".done()");
|
1734
|
-
if (warningTimeout) {
|
1735
|
-
clearTimeout(warningTimeout);
|
1736
|
-
}
|
1737
|
-
closed = true;
|
1738
|
-
if (args.length) {
|
1739
|
-
resolve({ value: args[0], done: true });
|
1740
|
-
return streamable;
|
1741
|
-
}
|
1742
|
-
resolve({ value: currentValue, done: true });
|
1743
|
-
return streamable;
|
1744
|
-
}
|
1745
|
-
};
|
1746
|
-
return streamable;
|
1747
|
-
}
|
1748
|
-
|
1749
|
-
// rsc/stream-ui/stream-ui.tsx
|
1750
|
-
var defaultTextRenderer = ({ content }) => content;
|
1751
|
-
async function streamUI({
|
1752
|
-
model,
|
1753
|
-
tools,
|
1754
|
-
toolChoice,
|
1755
|
-
system,
|
1756
|
-
prompt,
|
1757
|
-
messages,
|
1758
|
-
maxRetries,
|
1759
|
-
abortSignal,
|
1760
|
-
headers,
|
1761
|
-
initial,
|
1762
|
-
text,
|
1763
|
-
experimental_providerMetadata,
|
1764
|
-
providerOptions = experimental_providerMetadata,
|
1765
|
-
onFinish,
|
1766
|
-
...settings
|
1767
|
-
}) {
|
1768
|
-
if (typeof model === "string") {
|
1769
|
-
throw new Error(
|
1770
|
-
"`model` cannot be a string in `streamUI`. Use the actual model instance instead."
|
1771
|
-
);
|
1772
|
-
}
|
1773
|
-
if ("functions" in settings) {
|
1774
|
-
throw new Error(
|
1775
|
-
"`functions` is not supported in `streamUI`, use `tools` instead."
|
1776
|
-
);
|
1777
|
-
}
|
1778
|
-
if ("provider" in settings) {
|
1779
|
-
throw new Error(
|
1780
|
-
"`provider` is no longer needed in `streamUI`. Use `model` instead."
|
1781
|
-
);
|
1782
|
-
}
|
1783
|
-
if (tools) {
|
1784
|
-
for (const [name9, tool] of Object.entries(tools)) {
|
1785
|
-
if ("render" in tool) {
|
1786
|
-
throw new Error(
|
1787
|
-
"Tool definition in `streamUI` should not have `render` property. Use `generate` instead. Found in tool: " + name9
|
1788
|
-
);
|
1789
|
-
}
|
1790
|
-
}
|
1791
|
-
}
|
1792
|
-
const ui = createStreamableUI(initial);
|
1793
|
-
const textRender = text || defaultTextRenderer;
|
1794
|
-
let finished;
|
1795
|
-
let finishEvent = null;
|
1796
|
-
async function render({
|
1797
|
-
args,
|
1798
|
-
renderer,
|
1799
|
-
streamableUI,
|
1800
|
-
isLastCall = false
|
1801
|
-
}) {
|
1802
|
-
if (!renderer)
|
1803
|
-
return;
|
1804
|
-
const renderFinished = createResolvablePromise();
|
1805
|
-
finished = finished ? finished.then(() => renderFinished.promise) : renderFinished.promise;
|
1806
|
-
const rendererResult = renderer(...args);
|
1807
|
-
if (isAsyncGenerator(rendererResult) || isGenerator(rendererResult)) {
|
1808
|
-
while (true) {
|
1809
|
-
const { done, value } = await rendererResult.next();
|
1810
|
-
const node = await value;
|
1811
|
-
if (isLastCall && done) {
|
1812
|
-
streamableUI.done(node);
|
1813
|
-
} else {
|
1814
|
-
streamableUI.update(node);
|
1815
|
-
}
|
1816
|
-
if (done)
|
1817
|
-
break;
|
1818
|
-
}
|
1819
|
-
} else {
|
1820
|
-
const node = await rendererResult;
|
1821
|
-
if (isLastCall) {
|
1822
|
-
streamableUI.done(node);
|
1823
|
-
} else {
|
1824
|
-
streamableUI.update(node);
|
1825
|
-
}
|
1826
|
-
}
|
1827
|
-
renderFinished.resolve(void 0);
|
1828
|
-
}
|
1829
|
-
const { retry } = prepareRetries({ maxRetries });
|
1830
|
-
const validatedPrompt = standardizePrompt({
|
1831
|
-
prompt: { system, prompt, messages },
|
1832
|
-
tools: void 0
|
1833
|
-
// streamUI tools don't support multi-modal tool result conversion
|
1834
|
-
});
|
1835
|
-
const result = await retry(
|
1836
|
-
async () => {
|
1837
|
-
var _a9;
|
1838
|
-
return model.doStream({
|
1839
|
-
mode: {
|
1840
|
-
type: "regular",
|
1841
|
-
...prepareToolsAndToolChoice({
|
1842
|
-
tools,
|
1843
|
-
toolChoice,
|
1844
|
-
activeTools: void 0
|
1845
|
-
})
|
1846
|
-
},
|
1847
|
-
...prepareCallSettings(settings),
|
1848
|
-
inputFormat: validatedPrompt.type,
|
1849
|
-
prompt: await convertToLanguageModelPrompt({
|
1850
|
-
prompt: validatedPrompt,
|
1851
|
-
modelSupportsImageUrls: model.supportsImageUrls,
|
1852
|
-
modelSupportsUrl: (_a9 = model.supportsUrl) == null ? void 0 : _a9.bind(model)
|
1853
|
-
// support 'this' context
|
1854
|
-
}),
|
1855
|
-
providerMetadata: providerOptions,
|
1856
|
-
abortSignal,
|
1857
|
-
headers
|
1858
|
-
});
|
1859
|
-
}
|
1860
|
-
);
|
1861
|
-
const [stream, forkedStream] = result.stream.tee();
|
1862
|
-
(async () => {
|
1863
|
-
try {
|
1864
|
-
let content = "";
|
1865
|
-
let hasToolCall = false;
|
1866
|
-
const reader = forkedStream.getReader();
|
1867
|
-
while (true) {
|
1868
|
-
const { done, value } = await reader.read();
|
1869
|
-
if (done)
|
1870
|
-
break;
|
1871
|
-
switch (value.type) {
|
1872
|
-
case "text-delta": {
|
1873
|
-
content += value.textDelta;
|
1874
|
-
render({
|
1875
|
-
renderer: textRender,
|
1876
|
-
args: [{ content, done: false, delta: value.textDelta }],
|
1877
|
-
streamableUI: ui
|
1878
|
-
});
|
1879
|
-
break;
|
1880
|
-
}
|
1881
|
-
case "tool-call-delta": {
|
1882
|
-
hasToolCall = true;
|
1883
|
-
break;
|
1884
|
-
}
|
1885
|
-
case "tool-call": {
|
1886
|
-
const toolName = value.toolName;
|
1887
|
-
if (!tools) {
|
1888
|
-
throw new NoSuchToolError({ toolName });
|
1889
|
-
}
|
1890
|
-
const tool = tools[toolName];
|
1891
|
-
if (!tool) {
|
1892
|
-
throw new NoSuchToolError({
|
1893
|
-
toolName,
|
1894
|
-
availableTools: Object.keys(tools)
|
1895
|
-
});
|
1896
|
-
}
|
1897
|
-
hasToolCall = true;
|
1898
|
-
const parseResult = safeParseJSON({
|
1899
|
-
text: value.args,
|
1900
|
-
schema: tool.parameters
|
1901
|
-
});
|
1902
|
-
if (parseResult.success === false) {
|
1903
|
-
throw new InvalidToolArgumentsError({
|
1904
|
-
toolName,
|
1905
|
-
toolArgs: value.args,
|
1906
|
-
cause: parseResult.error
|
1907
|
-
});
|
1908
|
-
}
|
1909
|
-
render({
|
1910
|
-
renderer: tool.generate,
|
1911
|
-
args: [
|
1912
|
-
parseResult.value,
|
1913
|
-
{
|
1914
|
-
toolName,
|
1915
|
-
toolCallId: value.toolCallId
|
1916
|
-
}
|
1917
|
-
],
|
1918
|
-
streamableUI: ui,
|
1919
|
-
isLastCall: true
|
1920
|
-
});
|
1921
|
-
break;
|
1922
|
-
}
|
1923
|
-
case "error": {
|
1924
|
-
throw value.error;
|
1925
|
-
}
|
1926
|
-
case "finish": {
|
1927
|
-
finishEvent = {
|
1928
|
-
finishReason: value.finishReason,
|
1929
|
-
usage: calculateLanguageModelUsage(value.usage),
|
1930
|
-
warnings: result.warnings,
|
1931
|
-
rawResponse: result.rawResponse
|
1932
|
-
};
|
1933
|
-
break;
|
1934
|
-
}
|
1935
|
-
}
|
1936
|
-
}
|
1937
|
-
if (!hasToolCall) {
|
1938
|
-
render({
|
1939
|
-
renderer: textRender,
|
1940
|
-
args: [{ content, done: true }],
|
1941
|
-
streamableUI: ui,
|
1942
|
-
isLastCall: true
|
1943
|
-
});
|
1944
|
-
}
|
1945
|
-
await finished;
|
1946
|
-
if (finishEvent && onFinish) {
|
1947
|
-
await onFinish({
|
1948
|
-
...finishEvent,
|
1949
|
-
value: ui.value
|
1950
|
-
});
|
1951
|
-
}
|
1952
|
-
} catch (error) {
|
1953
|
-
ui.error(error);
|
1954
|
-
}
|
1955
|
-
})();
|
1956
|
-
return {
|
1957
|
-
...result,
|
1958
|
-
stream,
|
1959
|
-
value: ui.value
|
1960
|
-
};
|
1961
|
-
}
|
1962
|
-
|
1963
|
-
// rsc/streamable-value/streamable-value.ts
|
1964
|
-
var STREAMABLE_VALUE_TYPE = Symbol.for("ui.streamable.value");
|
1965
|
-
|
1966
|
-
// rsc/streamable-value/create-streamable-value.ts
|
1967
|
-
var STREAMABLE_VALUE_INTERNAL_LOCK = Symbol("streamable.value.lock");
|
1968
|
-
function createStreamableValue(initialValue) {
|
1969
|
-
const isReadableStream = initialValue instanceof ReadableStream || typeof initialValue === "object" && initialValue !== null && "getReader" in initialValue && typeof initialValue.getReader === "function" && "locked" in initialValue && typeof initialValue.locked === "boolean";
|
1970
|
-
if (!isReadableStream) {
|
1971
|
-
return createStreamableValueImpl(initialValue);
|
1972
|
-
}
|
1973
|
-
const streamableValue = createStreamableValueImpl();
|
1974
|
-
streamableValue[STREAMABLE_VALUE_INTERNAL_LOCK] = true;
|
1975
|
-
(async () => {
|
1976
|
-
try {
|
1977
|
-
const reader = initialValue.getReader();
|
1978
|
-
while (true) {
|
1979
|
-
const { value, done } = await reader.read();
|
1980
|
-
if (done) {
|
1981
|
-
break;
|
1982
|
-
}
|
1983
|
-
streamableValue[STREAMABLE_VALUE_INTERNAL_LOCK] = false;
|
1984
|
-
if (typeof value === "string") {
|
1985
|
-
streamableValue.append(value);
|
1986
|
-
} else {
|
1987
|
-
streamableValue.update(value);
|
1988
|
-
}
|
1989
|
-
streamableValue[STREAMABLE_VALUE_INTERNAL_LOCK] = true;
|
1990
|
-
}
|
1991
|
-
streamableValue[STREAMABLE_VALUE_INTERNAL_LOCK] = false;
|
1992
|
-
streamableValue.done();
|
1993
|
-
} catch (e) {
|
1994
|
-
streamableValue[STREAMABLE_VALUE_INTERNAL_LOCK] = false;
|
1995
|
-
streamableValue.error(e);
|
1996
|
-
}
|
1997
|
-
})();
|
1998
|
-
return streamableValue;
|
1999
|
-
}
|
2000
|
-
function createStreamableValueImpl(initialValue) {
|
2001
|
-
let closed = false;
|
2002
|
-
let locked = false;
|
2003
|
-
let resolvable = createResolvablePromise();
|
2004
|
-
let currentValue = initialValue;
|
2005
|
-
let currentError;
|
2006
|
-
let currentPromise = resolvable.promise;
|
2007
|
-
let currentPatchValue;
|
2008
|
-
function assertStream(method) {
|
2009
|
-
if (closed) {
|
2010
|
-
throw new Error(method + ": Value stream is already closed.");
|
2011
|
-
}
|
2012
|
-
if (locked) {
|
2013
|
-
throw new Error(
|
2014
|
-
method + ": Value stream is locked and cannot be updated."
|
2015
|
-
);
|
2016
|
-
}
|
2017
|
-
}
|
2018
|
-
let warningTimeout;
|
2019
|
-
function warnUnclosedStream() {
|
2020
|
-
if (process.env.NODE_ENV === "development") {
|
2021
|
-
if (warningTimeout) {
|
2022
|
-
clearTimeout(warningTimeout);
|
2023
|
-
}
|
2024
|
-
warningTimeout = setTimeout(() => {
|
2025
|
-
console.warn(
|
2026
|
-
"The streamable value has been slow to update. This may be a bug or a performance issue or you forgot to call `.done()`."
|
2027
|
-
);
|
2028
|
-
}, HANGING_STREAM_WARNING_TIME_MS);
|
2029
|
-
}
|
2030
|
-
}
|
2031
|
-
warnUnclosedStream();
|
2032
|
-
function createWrapped(initialChunk) {
|
2033
|
-
let init;
|
2034
|
-
if (currentError !== void 0) {
|
2035
|
-
init = { error: currentError };
|
2036
|
-
} else {
|
2037
|
-
if (currentPatchValue && !initialChunk) {
|
2038
|
-
init = { diff: currentPatchValue };
|
2039
|
-
} else {
|
2040
|
-
init = { curr: currentValue };
|
2041
|
-
}
|
2042
|
-
}
|
2043
|
-
if (currentPromise) {
|
2044
|
-
init.next = currentPromise;
|
2045
|
-
}
|
2046
|
-
if (initialChunk) {
|
2047
|
-
init.type = STREAMABLE_VALUE_TYPE;
|
2048
|
-
}
|
2049
|
-
return init;
|
2050
|
-
}
|
2051
|
-
function updateValueStates(value) {
|
2052
|
-
currentPatchValue = void 0;
|
2053
|
-
if (typeof value === "string") {
|
2054
|
-
if (typeof currentValue === "string") {
|
2055
|
-
if (value.startsWith(currentValue)) {
|
2056
|
-
currentPatchValue = [0, value.slice(currentValue.length)];
|
2057
|
-
}
|
2058
|
-
}
|
2059
|
-
}
|
2060
|
-
currentValue = value;
|
2061
|
-
}
|
2062
|
-
const streamable = {
|
2063
|
-
set [STREAMABLE_VALUE_INTERNAL_LOCK](state) {
|
2064
|
-
locked = state;
|
2065
|
-
},
|
2066
|
-
get value() {
|
2067
|
-
return createWrapped(true);
|
2068
|
-
},
|
2069
|
-
update(value) {
|
2070
|
-
assertStream(".update()");
|
2071
|
-
const resolvePrevious = resolvable.resolve;
|
2072
|
-
resolvable = createResolvablePromise();
|
2073
|
-
updateValueStates(value);
|
2074
|
-
currentPromise = resolvable.promise;
|
2075
|
-
resolvePrevious(createWrapped());
|
2076
|
-
warnUnclosedStream();
|
2077
|
-
return streamable;
|
2078
|
-
},
|
2079
|
-
append(value) {
|
2080
|
-
assertStream(".append()");
|
2081
|
-
if (typeof currentValue !== "string" && typeof currentValue !== "undefined") {
|
2082
|
-
throw new Error(
|
2083
|
-
`.append(): The current value is not a string. Received: ${typeof currentValue}`
|
2084
|
-
);
|
2085
|
-
}
|
2086
|
-
if (typeof value !== "string") {
|
2087
|
-
throw new Error(
|
2088
|
-
`.append(): The value is not a string. Received: ${typeof value}`
|
2089
|
-
);
|
2090
|
-
}
|
2091
|
-
const resolvePrevious = resolvable.resolve;
|
2092
|
-
resolvable = createResolvablePromise();
|
2093
|
-
if (typeof currentValue === "string") {
|
2094
|
-
currentPatchValue = [0, value];
|
2095
|
-
currentValue = currentValue + value;
|
2096
|
-
} else {
|
2097
|
-
currentPatchValue = void 0;
|
2098
|
-
currentValue = value;
|
2099
|
-
}
|
2100
|
-
currentPromise = resolvable.promise;
|
2101
|
-
resolvePrevious(createWrapped());
|
2102
|
-
warnUnclosedStream();
|
2103
|
-
return streamable;
|
2104
|
-
},
|
2105
|
-
error(error) {
|
2106
|
-
assertStream(".error()");
|
2107
|
-
if (warningTimeout) {
|
2108
|
-
clearTimeout(warningTimeout);
|
2109
|
-
}
|
2110
|
-
closed = true;
|
2111
|
-
currentError = error;
|
2112
|
-
currentPromise = void 0;
|
2113
|
-
resolvable.resolve({ error });
|
2114
|
-
return streamable;
|
2115
|
-
},
|
2116
|
-
done(...args) {
|
2117
|
-
assertStream(".done()");
|
2118
|
-
if (warningTimeout) {
|
2119
|
-
clearTimeout(warningTimeout);
|
2120
|
-
}
|
2121
|
-
closed = true;
|
2122
|
-
currentPromise = void 0;
|
2123
|
-
if (args.length) {
|
2124
|
-
updateValueStates(args[0]);
|
2125
|
-
resolvable.resolve(createWrapped());
|
2126
|
-
return streamable;
|
2127
|
-
}
|
2128
|
-
resolvable.resolve({});
|
2129
|
-
return streamable;
|
2130
|
-
}
|
2131
|
-
};
|
2132
|
-
return streamable;
|
2133
|
-
}
|
2134
|
-
export {
|
2135
|
-
createAI,
|
2136
|
-
createStreamableUI,
|
2137
|
-
createStreamableValue,
|
2138
|
-
getAIState,
|
2139
|
-
getMutableAIState,
|
2140
|
-
streamUI
|
2141
|
-
};
|
2142
|
-
//# sourceMappingURL=rsc-server.mjs.map
|