ai 3.1.19 → 3.1.20
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 +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +113 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/rsc/dist/rsc-server.mjs +61 -57
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/package.json
CHANGED
package/rsc/dist/rsc-server.mjs
CHANGED
@@ -288,7 +288,8 @@ function convertToLanguageModelPrompt(prompt) {
|
|
288
288
|
if (prompt.system != null) {
|
289
289
|
languageModelMessages.push({ role: "system", content: prompt.system });
|
290
290
|
}
|
291
|
-
|
291
|
+
const promptType = prompt.type;
|
292
|
+
switch (promptType) {
|
292
293
|
case "prompt": {
|
293
294
|
languageModelMessages.push({
|
294
295
|
role: "user",
|
@@ -298,72 +299,75 @@ function convertToLanguageModelPrompt(prompt) {
|
|
298
299
|
}
|
299
300
|
case "messages": {
|
300
301
|
languageModelMessages.push(
|
301
|
-
...prompt.messages.map(
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
302
|
+
...prompt.messages.map(convertToLanguageModelMessage)
|
303
|
+
);
|
304
|
+
break;
|
305
|
+
}
|
306
|
+
default: {
|
307
|
+
const _exhaustiveCheck = promptType;
|
308
|
+
throw new Error(`Unsupported prompt type: ${_exhaustiveCheck}`);
|
309
|
+
}
|
310
|
+
}
|
311
|
+
return languageModelMessages;
|
312
|
+
}
|
313
|
+
function convertToLanguageModelMessage(message) {
|
314
|
+
switch (message.role) {
|
315
|
+
case "system": {
|
316
|
+
return { role: "system", content: message.content };
|
317
|
+
}
|
318
|
+
case "user": {
|
319
|
+
if (typeof message.content === "string") {
|
320
|
+
return {
|
321
|
+
role: "user",
|
322
|
+
content: [{ type: "text", text: message.content }]
|
323
|
+
};
|
324
|
+
}
|
325
|
+
return {
|
326
|
+
role: "user",
|
327
|
+
content: message.content.map(
|
328
|
+
(part) => {
|
329
|
+
var _a;
|
330
|
+
switch (part.type) {
|
331
|
+
case "text": {
|
332
|
+
return part;
|
312
333
|
}
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
case "image": {
|
323
|
-
if (part.image instanceof URL) {
|
324
|
-
return {
|
325
|
-
type: "image",
|
326
|
-
image: part.image,
|
327
|
-
mimeType: part.mimeType
|
328
|
-
};
|
329
|
-
}
|
330
|
-
const imageUint8 = convertDataContentToUint8Array(
|
331
|
-
part.image
|
332
|
-
);
|
333
|
-
return {
|
334
|
-
type: "image",
|
335
|
-
image: imageUint8,
|
336
|
-
mimeType: (_a = part.mimeType) != null ? _a : detectImageMimeType(imageUint8)
|
337
|
-
};
|
338
|
-
}
|
339
|
-
}
|
340
|
-
}
|
341
|
-
)
|
342
|
-
};
|
343
|
-
}
|
344
|
-
case "assistant": {
|
345
|
-
if (typeof message.content === "string") {
|
334
|
+
case "image": {
|
335
|
+
if (part.image instanceof URL) {
|
336
|
+
return {
|
337
|
+
type: "image",
|
338
|
+
image: part.image,
|
339
|
+
mimeType: part.mimeType
|
340
|
+
};
|
341
|
+
}
|
342
|
+
const imageUint8 = convertDataContentToUint8Array(part.image);
|
346
343
|
return {
|
347
|
-
|
348
|
-
|
344
|
+
type: "image",
|
345
|
+
image: imageUint8,
|
346
|
+
mimeType: (_a = part.mimeType) != null ? _a : detectImageMimeType(imageUint8)
|
349
347
|
};
|
350
348
|
}
|
351
|
-
return { role: "assistant", content: message.content };
|
352
|
-
}
|
353
|
-
case "tool": {
|
354
|
-
return message;
|
355
349
|
}
|
356
350
|
}
|
357
|
-
|
358
|
-
|
359
|
-
|
351
|
+
)
|
352
|
+
};
|
353
|
+
}
|
354
|
+
case "assistant": {
|
355
|
+
if (typeof message.content === "string") {
|
356
|
+
return {
|
357
|
+
role: "assistant",
|
358
|
+
content: [{ type: "text", text: message.content }]
|
359
|
+
};
|
360
|
+
}
|
361
|
+
return { role: "assistant", content: message.content };
|
362
|
+
}
|
363
|
+
case "tool": {
|
364
|
+
return message;
|
360
365
|
}
|
361
366
|
default: {
|
362
|
-
const _exhaustiveCheck =
|
363
|
-
throw new Error(`Unsupported
|
367
|
+
const _exhaustiveCheck = message;
|
368
|
+
throw new Error(`Unsupported message role: ${_exhaustiveCheck}`);
|
364
369
|
}
|
365
370
|
}
|
366
|
-
return languageModelMessages;
|
367
371
|
}
|
368
372
|
|
369
373
|
// core/prompt/get-validated-prompt.ts
|