ai 5.1.0-beta.8 → 6.0.0-beta.100
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 +704 -0
- package/README.md +130 -45
- package/dist/index.d.mts +2212 -1704
- package/dist/index.d.ts +2212 -1704
- package/dist/index.js +4435 -3547
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4385 -3515
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -7
- package/dist/internal/index.d.ts +7 -7
- package/dist/internal/index.js +186 -79
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +186 -79
- package/dist/internal/index.mjs.map +1 -1
- package/dist/test/index.d.mts +69 -53
- package/dist/test/index.d.ts +69 -53
- package/dist/test/index.js +61 -27
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +55 -22
- package/dist/test/index.mjs.map +1 -1
- package/package.json +12 -15
- package/dist/mcp-stdio/index.d.mts +0 -89
- package/dist/mcp-stdio/index.d.ts +0 -89
- package/dist/mcp-stdio/index.js +0 -349
- package/dist/mcp-stdio/index.js.map +0 -1
- package/dist/mcp-stdio/index.mjs +0 -322
- package/dist/mcp-stdio/index.mjs.map +0 -1
- package/mcp-stdio.d.ts +0 -1
package/dist/internal/index.mjs
CHANGED
|
@@ -153,7 +153,7 @@ import {
|
|
|
153
153
|
} from "@ai-sdk/provider-utils";
|
|
154
154
|
|
|
155
155
|
// src/version.ts
|
|
156
|
-
var VERSION = true ? "
|
|
156
|
+
var VERSION = true ? "6.0.0-beta.100" : "0.0.0-test";
|
|
157
157
|
|
|
158
158
|
// src/util/download/download.ts
|
|
159
159
|
var download = async ({ url }) => {
|
|
@@ -231,7 +231,7 @@ var dataContentSchema = z.union([
|
|
|
231
231
|
{ message: "Must be a Buffer" }
|
|
232
232
|
)
|
|
233
233
|
]);
|
|
234
|
-
function
|
|
234
|
+
function convertToLanguageModelV3DataContent(content) {
|
|
235
235
|
if (content instanceof Uint8Array) {
|
|
236
236
|
return { data: content, mediaType: void 0 };
|
|
237
237
|
}
|
|
@@ -291,12 +291,26 @@ async function convertToLanguageModelPrompt({
|
|
|
291
291
|
download2,
|
|
292
292
|
supportedUrls
|
|
293
293
|
);
|
|
294
|
-
|
|
294
|
+
const messages = [
|
|
295
295
|
...prompt.system != null ? [{ role: "system", content: prompt.system }] : [],
|
|
296
296
|
...prompt.messages.map(
|
|
297
297
|
(message) => convertToLanguageModelMessage({ message, downloadedAssets })
|
|
298
298
|
)
|
|
299
299
|
];
|
|
300
|
+
const combinedMessages = [];
|
|
301
|
+
for (const message of messages) {
|
|
302
|
+
if (message.role !== "tool") {
|
|
303
|
+
combinedMessages.push(message);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const lastCombinedMessage = combinedMessages.at(-1);
|
|
307
|
+
if ((lastCombinedMessage == null ? void 0 : lastCombinedMessage.role) === "tool") {
|
|
308
|
+
lastCombinedMessage.content.push(...message.content);
|
|
309
|
+
} else {
|
|
310
|
+
combinedMessages.push(message);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return combinedMessages;
|
|
300
314
|
}
|
|
301
315
|
function convertToLanguageModelMessage({
|
|
302
316
|
message,
|
|
@@ -338,11 +352,13 @@ function convertToLanguageModelMessage({
|
|
|
338
352
|
content: message.content.filter(
|
|
339
353
|
// remove empty text parts (no text, and no provider options):
|
|
340
354
|
(part) => part.type !== "text" || part.text !== "" || part.providerOptions != null
|
|
355
|
+
).filter(
|
|
356
|
+
(part) => part.type !== "tool-approval-request"
|
|
341
357
|
).map((part) => {
|
|
342
358
|
const providerOptions = part.providerOptions;
|
|
343
359
|
switch (part.type) {
|
|
344
360
|
case "file": {
|
|
345
|
-
const { data, mediaType } =
|
|
361
|
+
const { data, mediaType } = convertToLanguageModelV3DataContent(
|
|
346
362
|
part.data
|
|
347
363
|
);
|
|
348
364
|
return {
|
|
@@ -382,7 +398,7 @@ function convertToLanguageModelMessage({
|
|
|
382
398
|
type: "tool-result",
|
|
383
399
|
toolCallId: part.toolCallId,
|
|
384
400
|
toolName: part.toolName,
|
|
385
|
-
output: part.output,
|
|
401
|
+
output: mapToolResultOutput(part.output),
|
|
386
402
|
providerOptions
|
|
387
403
|
};
|
|
388
404
|
}
|
|
@@ -394,11 +410,11 @@ function convertToLanguageModelMessage({
|
|
|
394
410
|
case "tool": {
|
|
395
411
|
return {
|
|
396
412
|
role: "tool",
|
|
397
|
-
content: message.content.map((part) => ({
|
|
413
|
+
content: message.content.filter((part) => part.type !== "tool-approval-response").map((part) => ({
|
|
398
414
|
type: "tool-result",
|
|
399
415
|
toolCallId: part.toolCallId,
|
|
400
416
|
toolName: part.toolName,
|
|
401
|
-
output: part.output,
|
|
417
|
+
output: mapToolResultOutput(part.output),
|
|
402
418
|
providerOptions: part.providerOptions
|
|
403
419
|
})),
|
|
404
420
|
providerOptions: message.providerOptions
|
|
@@ -438,12 +454,12 @@ async function downloadAssets(messages, download2, supportedUrls) {
|
|
|
438
454
|
}));
|
|
439
455
|
const downloadedFiles = await download2(plannedDownloads);
|
|
440
456
|
return Object.fromEntries(
|
|
441
|
-
downloadedFiles.
|
|
442
|
-
(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
457
|
+
downloadedFiles.map(
|
|
458
|
+
(file, index) => file == null ? null : [
|
|
459
|
+
plannedDownloads[index].url.toString(),
|
|
460
|
+
{ data: file.data, mediaType: file.mediaType }
|
|
461
|
+
]
|
|
462
|
+
).filter((file) => file != null)
|
|
447
463
|
);
|
|
448
464
|
}
|
|
449
465
|
function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
@@ -467,7 +483,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
467
483
|
default:
|
|
468
484
|
throw new Error(`Unsupported part type: ${type}`);
|
|
469
485
|
}
|
|
470
|
-
const { data: convertedData, mediaType: convertedMediaType } =
|
|
486
|
+
const { data: convertedData, mediaType: convertedMediaType } = convertToLanguageModelV3DataContent(originalData);
|
|
471
487
|
let mediaType = convertedMediaType != null ? convertedMediaType : part.mediaType;
|
|
472
488
|
let data = convertedData;
|
|
473
489
|
if (data instanceof URL) {
|
|
@@ -505,6 +521,31 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
505
521
|
}
|
|
506
522
|
}
|
|
507
523
|
}
|
|
524
|
+
function mapToolResultOutput(output) {
|
|
525
|
+
if (output.type !== "content") {
|
|
526
|
+
return output;
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
type: "content",
|
|
530
|
+
value: output.value.map((item) => {
|
|
531
|
+
if (item.type !== "media") {
|
|
532
|
+
return item;
|
|
533
|
+
}
|
|
534
|
+
if (item.mediaType.startsWith("image/")) {
|
|
535
|
+
return {
|
|
536
|
+
type: "image-data",
|
|
537
|
+
data: item.data,
|
|
538
|
+
mediaType: item.mediaType
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
type: "file-data",
|
|
543
|
+
data: item.data,
|
|
544
|
+
mediaType: item.mediaType
|
|
545
|
+
};
|
|
546
|
+
})
|
|
547
|
+
};
|
|
548
|
+
}
|
|
508
549
|
|
|
509
550
|
// src/prompt/prepare-tools-and-tool-choice.ts
|
|
510
551
|
import { asSchema } from "@ai-sdk/provider-utils";
|
|
@@ -515,7 +556,7 @@ function isNonEmptyObject(object) {
|
|
|
515
556
|
}
|
|
516
557
|
|
|
517
558
|
// src/prompt/prepare-tools-and-tool-choice.ts
|
|
518
|
-
function prepareToolsAndToolChoice({
|
|
559
|
+
async function prepareToolsAndToolChoice({
|
|
519
560
|
tools,
|
|
520
561
|
toolChoice,
|
|
521
562
|
activeTools
|
|
@@ -529,33 +570,37 @@ function prepareToolsAndToolChoice({
|
|
|
529
570
|
const filteredTools = activeTools != null ? Object.entries(tools).filter(
|
|
530
571
|
([name5]) => activeTools.includes(name5)
|
|
531
572
|
) : Object.entries(tools);
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
573
|
+
const languageModelTools = [];
|
|
574
|
+
for (const [name5, tool] of filteredTools) {
|
|
575
|
+
const toolType = tool.type;
|
|
576
|
+
switch (toolType) {
|
|
577
|
+
case void 0:
|
|
578
|
+
case "dynamic":
|
|
579
|
+
case "function":
|
|
580
|
+
languageModelTools.push({
|
|
581
|
+
type: "function",
|
|
582
|
+
name: name5,
|
|
583
|
+
description: tool.description,
|
|
584
|
+
inputSchema: await asSchema(tool.inputSchema).jsonSchema,
|
|
585
|
+
providerOptions: tool.providerOptions
|
|
586
|
+
});
|
|
587
|
+
break;
|
|
588
|
+
case "provider-defined":
|
|
589
|
+
languageModelTools.push({
|
|
590
|
+
type: "provider-defined",
|
|
591
|
+
name: name5,
|
|
592
|
+
id: tool.id,
|
|
593
|
+
args: tool.args
|
|
594
|
+
});
|
|
595
|
+
break;
|
|
596
|
+
default: {
|
|
597
|
+
const exhaustiveCheck = toolType;
|
|
598
|
+
throw new Error(`Unsupported tool type: ${exhaustiveCheck}`);
|
|
557
599
|
}
|
|
558
|
-
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
tools: languageModelTools,
|
|
559
604
|
toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
|
|
560
605
|
};
|
|
561
606
|
}
|
|
@@ -579,7 +624,7 @@ var jsonValueSchema = z2.lazy(
|
|
|
579
624
|
z2.string(),
|
|
580
625
|
z2.number(),
|
|
581
626
|
z2.boolean(),
|
|
582
|
-
z2.record(z2.string(), jsonValueSchema),
|
|
627
|
+
z2.record(z2.string(), jsonValueSchema.optional()),
|
|
583
628
|
z2.array(jsonValueSchema)
|
|
584
629
|
])
|
|
585
630
|
);
|
|
@@ -587,7 +632,7 @@ var jsonValueSchema = z2.lazy(
|
|
|
587
632
|
// src/types/provider-metadata.ts
|
|
588
633
|
var providerMetadataSchema = z3.record(
|
|
589
634
|
z3.string(),
|
|
590
|
-
z3.record(z3.string(), jsonValueSchema)
|
|
635
|
+
z3.record(z3.string(), jsonValueSchema.optional())
|
|
591
636
|
);
|
|
592
637
|
|
|
593
638
|
// src/prompt/content-part.ts
|
|
@@ -623,40 +668,90 @@ var toolCallPartSchema = z4.object({
|
|
|
623
668
|
providerOptions: providerMetadataSchema.optional(),
|
|
624
669
|
providerExecuted: z4.boolean().optional()
|
|
625
670
|
});
|
|
626
|
-
var outputSchema = z4.discriminatedUnion(
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
z4.
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
671
|
+
var outputSchema = z4.discriminatedUnion(
|
|
672
|
+
"type",
|
|
673
|
+
[
|
|
674
|
+
z4.object({
|
|
675
|
+
type: z4.literal("text"),
|
|
676
|
+
value: z4.string(),
|
|
677
|
+
providerOptions: providerMetadataSchema.optional()
|
|
678
|
+
}),
|
|
679
|
+
z4.object({
|
|
680
|
+
type: z4.literal("json"),
|
|
681
|
+
value: jsonValueSchema,
|
|
682
|
+
providerOptions: providerMetadataSchema.optional()
|
|
683
|
+
}),
|
|
684
|
+
z4.object({
|
|
685
|
+
type: z4.literal("execution-denied"),
|
|
686
|
+
reason: z4.string().optional(),
|
|
687
|
+
providerOptions: providerMetadataSchema.optional()
|
|
688
|
+
}),
|
|
689
|
+
z4.object({
|
|
690
|
+
type: z4.literal("error-text"),
|
|
691
|
+
value: z4.string(),
|
|
692
|
+
providerOptions: providerMetadataSchema.optional()
|
|
693
|
+
}),
|
|
694
|
+
z4.object({
|
|
695
|
+
type: z4.literal("error-json"),
|
|
696
|
+
value: jsonValueSchema,
|
|
697
|
+
providerOptions: providerMetadataSchema.optional()
|
|
698
|
+
}),
|
|
699
|
+
z4.object({
|
|
700
|
+
type: z4.literal("content"),
|
|
701
|
+
value: z4.array(
|
|
702
|
+
z4.union([
|
|
703
|
+
z4.object({
|
|
704
|
+
type: z4.literal("text"),
|
|
705
|
+
text: z4.string(),
|
|
706
|
+
providerOptions: providerMetadataSchema.optional()
|
|
707
|
+
}),
|
|
708
|
+
z4.object({
|
|
709
|
+
type: z4.literal("media"),
|
|
710
|
+
data: z4.string(),
|
|
711
|
+
mediaType: z4.string()
|
|
712
|
+
}),
|
|
713
|
+
z4.object({
|
|
714
|
+
type: z4.literal("file-data"),
|
|
715
|
+
data: z4.string(),
|
|
716
|
+
mediaType: z4.string(),
|
|
717
|
+
filename: z4.string().optional(),
|
|
718
|
+
providerOptions: providerMetadataSchema.optional()
|
|
719
|
+
}),
|
|
720
|
+
z4.object({
|
|
721
|
+
type: z4.literal("file-url"),
|
|
722
|
+
url: z4.string(),
|
|
723
|
+
providerOptions: providerMetadataSchema.optional()
|
|
724
|
+
}),
|
|
725
|
+
z4.object({
|
|
726
|
+
type: z4.literal("file-id"),
|
|
727
|
+
fileId: z4.union([z4.string(), z4.record(z4.string(), z4.string())]),
|
|
728
|
+
providerOptions: providerMetadataSchema.optional()
|
|
729
|
+
}),
|
|
730
|
+
z4.object({
|
|
731
|
+
type: z4.literal("image-data"),
|
|
732
|
+
data: z4.string(),
|
|
733
|
+
mediaType: z4.string(),
|
|
734
|
+
providerOptions: providerMetadataSchema.optional()
|
|
735
|
+
}),
|
|
736
|
+
z4.object({
|
|
737
|
+
type: z4.literal("image-url"),
|
|
738
|
+
url: z4.string(),
|
|
739
|
+
providerOptions: providerMetadataSchema.optional()
|
|
740
|
+
}),
|
|
741
|
+
z4.object({
|
|
742
|
+
type: z4.literal("image-file-id"),
|
|
743
|
+
fileId: z4.union([z4.string(), z4.record(z4.string(), z4.string())]),
|
|
744
|
+
providerOptions: providerMetadataSchema.optional()
|
|
745
|
+
}),
|
|
746
|
+
z4.object({
|
|
747
|
+
type: z4.literal("custom"),
|
|
748
|
+
providerOptions: providerMetadataSchema.optional()
|
|
749
|
+
})
|
|
750
|
+
])
|
|
751
|
+
)
|
|
752
|
+
})
|
|
753
|
+
]
|
|
754
|
+
);
|
|
660
755
|
var toolResultPartSchema = z4.object({
|
|
661
756
|
type: z4.literal("tool-result"),
|
|
662
757
|
toolCallId: z4.string(),
|
|
@@ -664,6 +759,17 @@ var toolResultPartSchema = z4.object({
|
|
|
664
759
|
output: outputSchema,
|
|
665
760
|
providerOptions: providerMetadataSchema.optional()
|
|
666
761
|
});
|
|
762
|
+
var toolApprovalRequestSchema = z4.object({
|
|
763
|
+
type: z4.literal("tool-approval-request"),
|
|
764
|
+
approvalId: z4.string(),
|
|
765
|
+
toolCallId: z4.string()
|
|
766
|
+
});
|
|
767
|
+
var toolApprovalResponseSchema = z4.object({
|
|
768
|
+
type: z4.literal("tool-approval-response"),
|
|
769
|
+
approvalId: z4.string(),
|
|
770
|
+
approved: z4.boolean(),
|
|
771
|
+
reason: z4.string().optional()
|
|
772
|
+
});
|
|
667
773
|
|
|
668
774
|
// src/prompt/message.ts
|
|
669
775
|
var systemModelMessageSchema = z5.object(
|
|
@@ -691,7 +797,8 @@ var assistantModelMessageSchema = z5.object({
|
|
|
691
797
|
filePartSchema,
|
|
692
798
|
reasoningPartSchema,
|
|
693
799
|
toolCallPartSchema,
|
|
694
|
-
toolResultPartSchema
|
|
800
|
+
toolResultPartSchema,
|
|
801
|
+
toolApprovalRequestSchema
|
|
695
802
|
])
|
|
696
803
|
)
|
|
697
804
|
]),
|
|
@@ -699,7 +806,7 @@ var assistantModelMessageSchema = z5.object({
|
|
|
699
806
|
});
|
|
700
807
|
var toolModelMessageSchema = z5.object({
|
|
701
808
|
role: z5.literal("tool"),
|
|
702
|
-
content: z5.array(toolResultPartSchema),
|
|
809
|
+
content: z5.array(z5.union([toolResultPartSchema, toolApprovalResponseSchema])),
|
|
703
810
|
providerOptions: providerMetadataSchema.optional()
|
|
704
811
|
});
|
|
705
812
|
var modelMessageSchema = z5.union([
|