ai 5.0.44 → 5.0.46
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 +14 -0
- package/dist/index.d.mts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +319 -226
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +247 -140
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +61 -36
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +51 -23
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
createIdGenerator,
|
|
22
22
|
executeTool,
|
|
23
23
|
getErrorMessage as getErrorMessage5,
|
|
24
|
-
withUserAgentSuffix
|
|
24
|
+
withUserAgentSuffix as withUserAgentSuffix2
|
|
25
25
|
} from "@ai-sdk/provider-utils";
|
|
26
26
|
|
|
27
27
|
// src/error/no-output-specified-error.ts
|
|
@@ -491,38 +491,50 @@ import { convertBase64ToUint8Array } from "@ai-sdk/provider-utils";
|
|
|
491
491
|
var imageMediaTypeSignatures = [
|
|
492
492
|
{
|
|
493
493
|
mediaType: "image/gif",
|
|
494
|
-
bytesPrefix: [71, 73, 70]
|
|
495
|
-
|
|
494
|
+
bytesPrefix: [71, 73, 70]
|
|
495
|
+
// GIF
|
|
496
496
|
},
|
|
497
497
|
{
|
|
498
498
|
mediaType: "image/png",
|
|
499
|
-
bytesPrefix: [137, 80, 78, 71]
|
|
500
|
-
|
|
499
|
+
bytesPrefix: [137, 80, 78, 71]
|
|
500
|
+
// PNG
|
|
501
501
|
},
|
|
502
502
|
{
|
|
503
503
|
mediaType: "image/jpeg",
|
|
504
|
-
bytesPrefix: [255, 216]
|
|
505
|
-
|
|
504
|
+
bytesPrefix: [255, 216]
|
|
505
|
+
// JPEG
|
|
506
506
|
},
|
|
507
507
|
{
|
|
508
508
|
mediaType: "image/webp",
|
|
509
|
-
bytesPrefix: [
|
|
510
|
-
|
|
509
|
+
bytesPrefix: [
|
|
510
|
+
82,
|
|
511
|
+
73,
|
|
512
|
+
70,
|
|
513
|
+
70,
|
|
514
|
+
// "RIFF"
|
|
515
|
+
null,
|
|
516
|
+
null,
|
|
517
|
+
null,
|
|
518
|
+
null,
|
|
519
|
+
// file size (variable)
|
|
520
|
+
87,
|
|
521
|
+
69,
|
|
522
|
+
66,
|
|
523
|
+
80
|
|
524
|
+
// "WEBP"
|
|
525
|
+
]
|
|
511
526
|
},
|
|
512
527
|
{
|
|
513
528
|
mediaType: "image/bmp",
|
|
514
|
-
bytesPrefix: [66, 77]
|
|
515
|
-
base64Prefix: "Qk"
|
|
529
|
+
bytesPrefix: [66, 77]
|
|
516
530
|
},
|
|
517
531
|
{
|
|
518
532
|
mediaType: "image/tiff",
|
|
519
|
-
bytesPrefix: [73, 73, 42, 0]
|
|
520
|
-
base64Prefix: "SUkqAA"
|
|
533
|
+
bytesPrefix: [73, 73, 42, 0]
|
|
521
534
|
},
|
|
522
535
|
{
|
|
523
536
|
mediaType: "image/tiff",
|
|
524
|
-
bytesPrefix: [77, 77, 0, 42]
|
|
525
|
-
base64Prefix: "TU0AKg"
|
|
537
|
+
bytesPrefix: [77, 77, 0, 42]
|
|
526
538
|
},
|
|
527
539
|
{
|
|
528
540
|
mediaType: "image/avif",
|
|
@@ -539,8 +551,7 @@ var imageMediaTypeSignatures = [
|
|
|
539
551
|
118,
|
|
540
552
|
105,
|
|
541
553
|
102
|
|
542
|
-
]
|
|
543
|
-
base64Prefix: "AAAAIGZ0eXBhdmlm"
|
|
554
|
+
]
|
|
544
555
|
},
|
|
545
556
|
{
|
|
546
557
|
mediaType: "image/heic",
|
|
@@ -557,70 +568,78 @@ var imageMediaTypeSignatures = [
|
|
|
557
568
|
101,
|
|
558
569
|
105,
|
|
559
570
|
99
|
|
560
|
-
]
|
|
561
|
-
base64Prefix: "AAAAIGZ0eXBoZWlj"
|
|
571
|
+
]
|
|
562
572
|
}
|
|
563
573
|
];
|
|
564
574
|
var audioMediaTypeSignatures = [
|
|
565
575
|
{
|
|
566
576
|
mediaType: "audio/mpeg",
|
|
567
|
-
bytesPrefix: [255, 251]
|
|
568
|
-
base64Prefix: "//s="
|
|
577
|
+
bytesPrefix: [255, 251]
|
|
569
578
|
},
|
|
570
579
|
{
|
|
571
580
|
mediaType: "audio/mpeg",
|
|
572
|
-
bytesPrefix: [255, 250]
|
|
573
|
-
base64Prefix: "//o="
|
|
581
|
+
bytesPrefix: [255, 250]
|
|
574
582
|
},
|
|
575
583
|
{
|
|
576
584
|
mediaType: "audio/mpeg",
|
|
577
|
-
bytesPrefix: [255, 243]
|
|
578
|
-
base64Prefix: "//M="
|
|
585
|
+
bytesPrefix: [255, 243]
|
|
579
586
|
},
|
|
580
587
|
{
|
|
581
588
|
mediaType: "audio/mpeg",
|
|
582
|
-
bytesPrefix: [255, 242]
|
|
583
|
-
base64Prefix: "//I="
|
|
589
|
+
bytesPrefix: [255, 242]
|
|
584
590
|
},
|
|
585
591
|
{
|
|
586
592
|
mediaType: "audio/mpeg",
|
|
587
|
-
bytesPrefix: [255, 227]
|
|
588
|
-
base64Prefix: "/+M="
|
|
593
|
+
bytesPrefix: [255, 227]
|
|
589
594
|
},
|
|
590
595
|
{
|
|
591
596
|
mediaType: "audio/mpeg",
|
|
592
|
-
bytesPrefix: [255, 226]
|
|
593
|
-
base64Prefix: "/+I="
|
|
597
|
+
bytesPrefix: [255, 226]
|
|
594
598
|
},
|
|
595
599
|
{
|
|
596
600
|
mediaType: "audio/wav",
|
|
597
|
-
bytesPrefix: [
|
|
598
|
-
|
|
601
|
+
bytesPrefix: [
|
|
602
|
+
82,
|
|
603
|
+
// R
|
|
604
|
+
73,
|
|
605
|
+
// I
|
|
606
|
+
70,
|
|
607
|
+
// F
|
|
608
|
+
70,
|
|
609
|
+
// F
|
|
610
|
+
null,
|
|
611
|
+
null,
|
|
612
|
+
null,
|
|
613
|
+
null,
|
|
614
|
+
87,
|
|
615
|
+
// W
|
|
616
|
+
65,
|
|
617
|
+
// A
|
|
618
|
+
86,
|
|
619
|
+
// V
|
|
620
|
+
69
|
|
621
|
+
// E
|
|
622
|
+
]
|
|
599
623
|
},
|
|
600
624
|
{
|
|
601
625
|
mediaType: "audio/ogg",
|
|
602
|
-
bytesPrefix: [79, 103, 103, 83]
|
|
603
|
-
base64Prefix: "T2dnUw"
|
|
626
|
+
bytesPrefix: [79, 103, 103, 83]
|
|
604
627
|
},
|
|
605
628
|
{
|
|
606
629
|
mediaType: "audio/flac",
|
|
607
|
-
bytesPrefix: [102, 76, 97, 67]
|
|
608
|
-
base64Prefix: "ZkxhQw"
|
|
630
|
+
bytesPrefix: [102, 76, 97, 67]
|
|
609
631
|
},
|
|
610
632
|
{
|
|
611
633
|
mediaType: "audio/aac",
|
|
612
|
-
bytesPrefix: [64, 21, 0, 0]
|
|
613
|
-
base64Prefix: "QBUA"
|
|
634
|
+
bytesPrefix: [64, 21, 0, 0]
|
|
614
635
|
},
|
|
615
636
|
{
|
|
616
637
|
mediaType: "audio/mp4",
|
|
617
|
-
bytesPrefix: [102, 116, 121, 112]
|
|
618
|
-
base64Prefix: "ZnR5cA"
|
|
638
|
+
bytesPrefix: [102, 116, 121, 112]
|
|
619
639
|
},
|
|
620
640
|
{
|
|
621
641
|
mediaType: "audio/webm",
|
|
622
|
-
bytesPrefix: [26, 69, 223, 163]
|
|
623
|
-
base64Prefix: "GkXf"
|
|
642
|
+
bytesPrefix: [26, 69, 223, 163]
|
|
624
643
|
}
|
|
625
644
|
];
|
|
626
645
|
var stripID3 = (data) => {
|
|
@@ -639,9 +658,12 @@ function detectMediaType({
|
|
|
639
658
|
signatures
|
|
640
659
|
}) {
|
|
641
660
|
const processedData = stripID3TagsIfPresent(data);
|
|
661
|
+
const bytes = typeof processedData === "string" ? convertBase64ToUint8Array(
|
|
662
|
+
processedData.substring(0, Math.min(processedData.length, 24))
|
|
663
|
+
) : processedData;
|
|
642
664
|
for (const signature of signatures) {
|
|
643
|
-
if (
|
|
644
|
-
(byte, index) =>
|
|
665
|
+
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
666
|
+
(byte, index) => byte === null || bytes[index] === byte
|
|
645
667
|
)) {
|
|
646
668
|
return signature.mediaType;
|
|
647
669
|
}
|
|
@@ -649,12 +671,27 @@ function detectMediaType({
|
|
|
649
671
|
return void 0;
|
|
650
672
|
}
|
|
651
673
|
|
|
674
|
+
// src/util/download/download.ts
|
|
675
|
+
import {
|
|
676
|
+
withUserAgentSuffix,
|
|
677
|
+
getRuntimeEnvironmentUserAgent
|
|
678
|
+
} from "@ai-sdk/provider-utils";
|
|
679
|
+
|
|
680
|
+
// src/version.ts
|
|
681
|
+
var VERSION = true ? "5.0.46" : "0.0.0-test";
|
|
682
|
+
|
|
652
683
|
// src/util/download/download.ts
|
|
653
684
|
var download = async ({ url }) => {
|
|
654
685
|
var _a17;
|
|
655
686
|
const urlText = url.toString();
|
|
656
687
|
try {
|
|
657
|
-
const response = await fetch(urlText
|
|
688
|
+
const response = await fetch(urlText, {
|
|
689
|
+
headers: withUserAgentSuffix(
|
|
690
|
+
{},
|
|
691
|
+
`ai-sdk/${VERSION}`,
|
|
692
|
+
getRuntimeEnvironmentUserAgent()
|
|
693
|
+
)
|
|
694
|
+
});
|
|
658
695
|
if (!response.ok) {
|
|
659
696
|
throw new DownloadError({
|
|
660
697
|
url: urlText,
|
|
@@ -832,8 +869,8 @@ function convertToLanguageModelMessage({
|
|
|
832
869
|
return {
|
|
833
870
|
role: "assistant",
|
|
834
871
|
content: message.content.filter(
|
|
835
|
-
// remove empty text parts:
|
|
836
|
-
(part) => part.type !== "text" || part.text !== ""
|
|
872
|
+
// remove empty text parts (no text, and no provider options):
|
|
873
|
+
(part) => part.type !== "text" || part.text !== "" || part.providerOptions != null
|
|
837
874
|
).map((part) => {
|
|
838
875
|
const providerOptions = part.providerOptions;
|
|
839
876
|
switch (part.type) {
|
|
@@ -1928,7 +1965,7 @@ var DefaultStepResult = class {
|
|
|
1928
1965
|
}
|
|
1929
1966
|
get staticToolCalls() {
|
|
1930
1967
|
return this.toolCalls.filter(
|
|
1931
|
-
(toolCall) => toolCall.dynamic
|
|
1968
|
+
(toolCall) => toolCall.dynamic !== true
|
|
1932
1969
|
);
|
|
1933
1970
|
}
|
|
1934
1971
|
get dynamicToolCalls() {
|
|
@@ -1941,7 +1978,7 @@ var DefaultStepResult = class {
|
|
|
1941
1978
|
}
|
|
1942
1979
|
get staticToolResults() {
|
|
1943
1980
|
return this.toolResults.filter(
|
|
1944
|
-
(toolResult) => toolResult.dynamic
|
|
1981
|
+
(toolResult) => toolResult.dynamic !== true
|
|
1945
1982
|
);
|
|
1946
1983
|
}
|
|
1947
1984
|
get dynamicToolResults() {
|
|
@@ -2083,9 +2120,6 @@ function toResponseMessages({
|
|
|
2083
2120
|
return responseMessages;
|
|
2084
2121
|
}
|
|
2085
2122
|
|
|
2086
|
-
// src/version.ts
|
|
2087
|
-
var VERSION = true ? "5.0.44" : "0.0.0-test";
|
|
2088
|
-
|
|
2089
2123
|
// src/generate-text/generate-text.ts
|
|
2090
2124
|
var originalGenerateId = createIdGenerator({
|
|
2091
2125
|
prefix: "aitxt",
|
|
@@ -2126,7 +2160,7 @@ async function generateText({
|
|
|
2126
2160
|
abortSignal
|
|
2127
2161
|
});
|
|
2128
2162
|
const callSettings = prepareCallSettings(settings);
|
|
2129
|
-
const headersWithUserAgent =
|
|
2163
|
+
const headersWithUserAgent = withUserAgentSuffix2(
|
|
2130
2164
|
headers != null ? headers : {},
|
|
2131
2165
|
`ai/${VERSION}`
|
|
2132
2166
|
);
|
|
@@ -5905,7 +5939,7 @@ var Agent = class {
|
|
|
5905
5939
|
};
|
|
5906
5940
|
|
|
5907
5941
|
// src/embed/embed.ts
|
|
5908
|
-
import { withUserAgentSuffix as
|
|
5942
|
+
import { withUserAgentSuffix as withUserAgentSuffix3 } from "@ai-sdk/provider-utils";
|
|
5909
5943
|
async function embed({
|
|
5910
5944
|
model: modelArg,
|
|
5911
5945
|
value,
|
|
@@ -5920,7 +5954,7 @@ async function embed({
|
|
|
5920
5954
|
maxRetries: maxRetriesArg,
|
|
5921
5955
|
abortSignal
|
|
5922
5956
|
});
|
|
5923
|
-
const headersWithUserAgent =
|
|
5957
|
+
const headersWithUserAgent = withUserAgentSuffix3(
|
|
5924
5958
|
headers != null ? headers : {},
|
|
5925
5959
|
`ai/${VERSION}`
|
|
5926
5960
|
);
|
|
@@ -6024,7 +6058,7 @@ var DefaultEmbedResult = class {
|
|
|
6024
6058
|
};
|
|
6025
6059
|
|
|
6026
6060
|
// src/embed/embed-many.ts
|
|
6027
|
-
import { withUserAgentSuffix as
|
|
6061
|
+
import { withUserAgentSuffix as withUserAgentSuffix4 } from "@ai-sdk/provider-utils";
|
|
6028
6062
|
|
|
6029
6063
|
// src/util/split-array.ts
|
|
6030
6064
|
function splitArray(array, chunkSize) {
|
|
@@ -6054,7 +6088,7 @@ async function embedMany({
|
|
|
6054
6088
|
maxRetries: maxRetriesArg,
|
|
6055
6089
|
abortSignal
|
|
6056
6090
|
});
|
|
6057
|
-
const headersWithUserAgent =
|
|
6091
|
+
const headersWithUserAgent = withUserAgentSuffix4(
|
|
6058
6092
|
headers != null ? headers : {},
|
|
6059
6093
|
`ai/${VERSION}`
|
|
6060
6094
|
);
|
|
@@ -6273,7 +6307,7 @@ var DefaultEmbedManyResult = class {
|
|
|
6273
6307
|
};
|
|
6274
6308
|
|
|
6275
6309
|
// src/generate-image/generate-image.ts
|
|
6276
|
-
import { withUserAgentSuffix as
|
|
6310
|
+
import { withUserAgentSuffix as withUserAgentSuffix5 } from "@ai-sdk/provider-utils";
|
|
6277
6311
|
async function generateImage({
|
|
6278
6312
|
model,
|
|
6279
6313
|
prompt,
|
|
@@ -6295,7 +6329,7 @@ async function generateImage({
|
|
|
6295
6329
|
modelId: model.modelId
|
|
6296
6330
|
});
|
|
6297
6331
|
}
|
|
6298
|
-
const headersWithUserAgent =
|
|
6332
|
+
const headersWithUserAgent = withUserAgentSuffix5(
|
|
6299
6333
|
headers != null ? headers : {},
|
|
6300
6334
|
`ai/${VERSION}`
|
|
6301
6335
|
);
|
|
@@ -6393,7 +6427,7 @@ async function invokeModelMaxImagesPerCall(model) {
|
|
|
6393
6427
|
// src/generate-object/generate-object.ts
|
|
6394
6428
|
import {
|
|
6395
6429
|
createIdGenerator as createIdGenerator3,
|
|
6396
|
-
withUserAgentSuffix as
|
|
6430
|
+
withUserAgentSuffix as withUserAgentSuffix6
|
|
6397
6431
|
} from "@ai-sdk/provider-utils";
|
|
6398
6432
|
|
|
6399
6433
|
// src/generate-text/extract-reasoning-content.ts
|
|
@@ -6891,7 +6925,7 @@ async function generateObject(options) {
|
|
|
6891
6925
|
enumValues
|
|
6892
6926
|
});
|
|
6893
6927
|
const callSettings = prepareCallSettings(settings);
|
|
6894
|
-
const headersWithUserAgent =
|
|
6928
|
+
const headersWithUserAgent = withUserAgentSuffix6(
|
|
6895
6929
|
headers != null ? headers : {},
|
|
6896
6930
|
`ai/${VERSION}`
|
|
6897
6931
|
);
|
|
@@ -7766,7 +7800,7 @@ var DefaultStreamObjectResult = class {
|
|
|
7766
7800
|
};
|
|
7767
7801
|
|
|
7768
7802
|
// src/generate-speech/generate-speech.ts
|
|
7769
|
-
import { withUserAgentSuffix as
|
|
7803
|
+
import { withUserAgentSuffix as withUserAgentSuffix7 } from "@ai-sdk/provider-utils";
|
|
7770
7804
|
|
|
7771
7805
|
// src/error/no-speech-generated-error.ts
|
|
7772
7806
|
import { AISDKError as AISDKError20 } from "@ai-sdk/provider";
|
|
@@ -7827,7 +7861,7 @@ async function generateSpeech({
|
|
|
7827
7861
|
modelId: model.modelId
|
|
7828
7862
|
});
|
|
7829
7863
|
}
|
|
7830
|
-
const headersWithUserAgent =
|
|
7864
|
+
const headersWithUserAgent = withUserAgentSuffix7(
|
|
7831
7865
|
headers != null ? headers : {},
|
|
7832
7866
|
`ai/${VERSION}`
|
|
7833
7867
|
);
|
|
@@ -8575,7 +8609,11 @@ import {
|
|
|
8575
8609
|
} from "@ai-sdk/provider-utils";
|
|
8576
8610
|
|
|
8577
8611
|
// src/tool/mcp/mcp-sse-transport.ts
|
|
8578
|
-
import {
|
|
8612
|
+
import {
|
|
8613
|
+
EventSourceParserStream,
|
|
8614
|
+
withUserAgentSuffix as withUserAgentSuffix8,
|
|
8615
|
+
getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent2
|
|
8616
|
+
} from "@ai-sdk/provider-utils";
|
|
8579
8617
|
|
|
8580
8618
|
// src/tool/mcp/json-rpc-message.ts
|
|
8581
8619
|
import { z as z9 } from "zod/v4";
|
|
@@ -8734,8 +8772,14 @@ var SseMCPTransport = class {
|
|
|
8734
8772
|
const establishConnection = async () => {
|
|
8735
8773
|
var _a17, _b, _c;
|
|
8736
8774
|
try {
|
|
8737
|
-
const headers =
|
|
8738
|
-
|
|
8775
|
+
const headers = withUserAgentSuffix8(
|
|
8776
|
+
{
|
|
8777
|
+
...this.headers,
|
|
8778
|
+
Accept: "text/event-stream"
|
|
8779
|
+
},
|
|
8780
|
+
`ai-sdk/${VERSION}`,
|
|
8781
|
+
getRuntimeEnvironmentUserAgent2()
|
|
8782
|
+
);
|
|
8739
8783
|
const response = await fetch(this.url.href, {
|
|
8740
8784
|
headers,
|
|
8741
8785
|
signal: (_a17 = this.abortController) == null ? void 0 : _a17.signal
|
|
@@ -8826,8 +8870,14 @@ var SseMCPTransport = class {
|
|
|
8826
8870
|
});
|
|
8827
8871
|
}
|
|
8828
8872
|
try {
|
|
8829
|
-
const headers =
|
|
8830
|
-
|
|
8873
|
+
const headers = withUserAgentSuffix8(
|
|
8874
|
+
{
|
|
8875
|
+
...this.headers,
|
|
8876
|
+
"Content-Type": "application/json"
|
|
8877
|
+
},
|
|
8878
|
+
`ai-sdk/${VERSION}`,
|
|
8879
|
+
getRuntimeEnvironmentUserAgent2()
|
|
8880
|
+
);
|
|
8831
8881
|
const init = {
|
|
8832
8882
|
method: "POST",
|
|
8833
8883
|
headers,
|
|
@@ -9135,7 +9185,7 @@ var DefaultMCPClient = class {
|
|
|
9135
9185
|
};
|
|
9136
9186
|
|
|
9137
9187
|
// src/transcribe/transcribe.ts
|
|
9138
|
-
import { withUserAgentSuffix as
|
|
9188
|
+
import { withUserAgentSuffix as withUserAgentSuffix9 } from "@ai-sdk/provider-utils";
|
|
9139
9189
|
|
|
9140
9190
|
// src/error/no-transcript-generated-error.ts
|
|
9141
9191
|
import { AISDKError as AISDKError22 } from "@ai-sdk/provider";
|
|
@@ -9169,7 +9219,7 @@ async function transcribe({
|
|
|
9169
9219
|
maxRetries: maxRetriesArg,
|
|
9170
9220
|
abortSignal
|
|
9171
9221
|
});
|
|
9172
|
-
const headersWithUserAgent =
|
|
9222
|
+
const headersWithUserAgent = withUserAgentSuffix9(
|
|
9173
9223
|
headers != null ? headers : {},
|
|
9174
9224
|
`ai/${VERSION}`
|
|
9175
9225
|
);
|
|
@@ -9217,7 +9267,11 @@ var DefaultTranscriptionResult = class {
|
|
|
9217
9267
|
};
|
|
9218
9268
|
|
|
9219
9269
|
// src/ui/call-completion-api.ts
|
|
9220
|
-
import {
|
|
9270
|
+
import {
|
|
9271
|
+
parseJsonEventStream,
|
|
9272
|
+
withUserAgentSuffix as withUserAgentSuffix10,
|
|
9273
|
+
getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent3
|
|
9274
|
+
} from "@ai-sdk/provider-utils";
|
|
9221
9275
|
|
|
9222
9276
|
// src/ui/process-text-stream.ts
|
|
9223
9277
|
async function processTextStream({
|
|
@@ -9265,10 +9319,14 @@ async function callCompletionApi({
|
|
|
9265
9319
|
...body
|
|
9266
9320
|
}),
|
|
9267
9321
|
credentials,
|
|
9268
|
-
headers:
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9322
|
+
headers: withUserAgentSuffix10(
|
|
9323
|
+
{
|
|
9324
|
+
"Content-Type": "application/json",
|
|
9325
|
+
...headers
|
|
9326
|
+
},
|
|
9327
|
+
`ai-sdk/${VERSION}`,
|
|
9328
|
+
getRuntimeEnvironmentUserAgent3()
|
|
9329
|
+
),
|
|
9272
9330
|
signal: abortController.signal
|
|
9273
9331
|
}).catch((err) => {
|
|
9274
9332
|
throw err;
|
|
@@ -9385,7 +9443,11 @@ async function convertFileListToFileUIParts(files) {
|
|
|
9385
9443
|
import { parseJsonEventStream as parseJsonEventStream2 } from "@ai-sdk/provider-utils";
|
|
9386
9444
|
|
|
9387
9445
|
// src/ui/http-chat-transport.ts
|
|
9388
|
-
import {
|
|
9446
|
+
import {
|
|
9447
|
+
resolve,
|
|
9448
|
+
withUserAgentSuffix as withUserAgentSuffix11,
|
|
9449
|
+
getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent4
|
|
9450
|
+
} from "@ai-sdk/provider-utils";
|
|
9389
9451
|
var HttpChatTransport = class {
|
|
9390
9452
|
constructor({
|
|
9391
9453
|
api = "/api/chat",
|
|
@@ -9437,10 +9499,14 @@ var HttpChatTransport = class {
|
|
|
9437
9499
|
const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
|
|
9438
9500
|
const response = await fetch2(api, {
|
|
9439
9501
|
method: "POST",
|
|
9440
|
-
headers:
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9502
|
+
headers: withUserAgentSuffix11(
|
|
9503
|
+
{
|
|
9504
|
+
"Content-Type": "application/json",
|
|
9505
|
+
...headers
|
|
9506
|
+
},
|
|
9507
|
+
`ai-sdk/${VERSION}`,
|
|
9508
|
+
getRuntimeEnvironmentUserAgent4()
|
|
9509
|
+
),
|
|
9444
9510
|
body: JSON.stringify(body),
|
|
9445
9511
|
credentials,
|
|
9446
9512
|
signal: abortSignal
|
|
@@ -9474,7 +9540,11 @@ var HttpChatTransport = class {
|
|
|
9474
9540
|
const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
|
|
9475
9541
|
const response = await fetch2(api, {
|
|
9476
9542
|
method: "GET",
|
|
9477
|
-
headers
|
|
9543
|
+
headers: withUserAgentSuffix11(
|
|
9544
|
+
headers,
|
|
9545
|
+
`ai-sdk/${VERSION}`,
|
|
9546
|
+
getRuntimeEnvironmentUserAgent4()
|
|
9547
|
+
),
|
|
9478
9548
|
credentials
|
|
9479
9549
|
});
|
|
9480
9550
|
if (response.status === 204) {
|
|
@@ -10047,82 +10117,118 @@ var uiMessageSchema = z10.object({
|
|
|
10047
10117
|
])
|
|
10048
10118
|
)
|
|
10049
10119
|
});
|
|
10050
|
-
async function
|
|
10120
|
+
async function safeValidateUIMessages({
|
|
10051
10121
|
messages,
|
|
10052
10122
|
metadataSchema,
|
|
10053
10123
|
dataSchemas,
|
|
10054
10124
|
tools
|
|
10055
10125
|
}) {
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10126
|
+
try {
|
|
10127
|
+
if (messages == null) {
|
|
10128
|
+
return {
|
|
10129
|
+
success: false,
|
|
10130
|
+
error: new InvalidArgumentError({
|
|
10131
|
+
parameter: "messages",
|
|
10132
|
+
value: messages,
|
|
10133
|
+
message: "messages parameter must be provided"
|
|
10134
|
+
})
|
|
10135
|
+
};
|
|
10136
|
+
}
|
|
10137
|
+
const validatedMessages = await validateTypes2({
|
|
10059
10138
|
value: messages,
|
|
10060
|
-
|
|
10139
|
+
schema: z10.array(uiMessageSchema)
|
|
10061
10140
|
});
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
value: messages,
|
|
10065
|
-
schema: z10.array(uiMessageSchema)
|
|
10066
|
-
});
|
|
10067
|
-
if (metadataSchema) {
|
|
10068
|
-
for (const message of validatedMessages) {
|
|
10069
|
-
await validateTypes2({
|
|
10070
|
-
value: message.metadata,
|
|
10071
|
-
schema: metadataSchema
|
|
10072
|
-
});
|
|
10073
|
-
}
|
|
10074
|
-
}
|
|
10075
|
-
if (dataSchemas) {
|
|
10076
|
-
for (const message of validatedMessages) {
|
|
10077
|
-
const dataParts = message.parts.filter(
|
|
10078
|
-
(part) => part.type.startsWith("data-")
|
|
10079
|
-
);
|
|
10080
|
-
for (const dataPart of dataParts) {
|
|
10081
|
-
const dataName = dataPart.type.slice(5);
|
|
10082
|
-
const dataSchema = dataSchemas[dataName];
|
|
10083
|
-
if (!dataSchema) {
|
|
10084
|
-
throw new TypeValidationError4({
|
|
10085
|
-
value: dataPart.data,
|
|
10086
|
-
cause: `No data schema found for data part ${dataName}`
|
|
10087
|
-
});
|
|
10088
|
-
}
|
|
10141
|
+
if (metadataSchema) {
|
|
10142
|
+
for (const message of validatedMessages) {
|
|
10089
10143
|
await validateTypes2({
|
|
10090
|
-
value:
|
|
10091
|
-
schema:
|
|
10144
|
+
value: message.metadata,
|
|
10145
|
+
schema: metadataSchema
|
|
10092
10146
|
});
|
|
10093
10147
|
}
|
|
10094
10148
|
}
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10149
|
+
if (dataSchemas) {
|
|
10150
|
+
for (const message of validatedMessages) {
|
|
10151
|
+
const dataParts = message.parts.filter(
|
|
10152
|
+
(part) => part.type.startsWith("data-")
|
|
10153
|
+
);
|
|
10154
|
+
for (const dataPart of dataParts) {
|
|
10155
|
+
const dataName = dataPart.type.slice(5);
|
|
10156
|
+
const dataSchema = dataSchemas[dataName];
|
|
10157
|
+
if (!dataSchema) {
|
|
10158
|
+
return {
|
|
10159
|
+
success: false,
|
|
10160
|
+
error: new TypeValidationError4({
|
|
10161
|
+
value: dataPart.data,
|
|
10162
|
+
cause: `No data schema found for data part ${dataName}`
|
|
10163
|
+
})
|
|
10164
|
+
};
|
|
10165
|
+
}
|
|
10111
10166
|
await validateTypes2({
|
|
10112
|
-
value:
|
|
10113
|
-
schema:
|
|
10167
|
+
value: dataPart.data,
|
|
10168
|
+
schema: dataSchema
|
|
10114
10169
|
});
|
|
10115
10170
|
}
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10171
|
+
}
|
|
10172
|
+
}
|
|
10173
|
+
if (tools) {
|
|
10174
|
+
for (const message of validatedMessages) {
|
|
10175
|
+
const toolParts = message.parts.filter(
|
|
10176
|
+
(part) => part.type.startsWith("tool-")
|
|
10177
|
+
);
|
|
10178
|
+
for (const toolPart of toolParts) {
|
|
10179
|
+
const toolName = toolPart.type.slice(5);
|
|
10180
|
+
const tool3 = tools[toolName];
|
|
10181
|
+
if (!tool3) {
|
|
10182
|
+
return {
|
|
10183
|
+
success: false,
|
|
10184
|
+
error: new TypeValidationError4({
|
|
10185
|
+
value: toolPart.input,
|
|
10186
|
+
cause: `No tool schema found for tool part ${toolName}`
|
|
10187
|
+
})
|
|
10188
|
+
};
|
|
10189
|
+
}
|
|
10190
|
+
if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
|
|
10191
|
+
await validateTypes2({
|
|
10192
|
+
value: toolPart.input,
|
|
10193
|
+
schema: tool3.inputSchema
|
|
10194
|
+
});
|
|
10195
|
+
}
|
|
10196
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
10197
|
+
await validateTypes2({
|
|
10198
|
+
value: toolPart.output,
|
|
10199
|
+
schema: tool3.outputSchema
|
|
10200
|
+
});
|
|
10201
|
+
}
|
|
10121
10202
|
}
|
|
10122
10203
|
}
|
|
10123
10204
|
}
|
|
10205
|
+
return {
|
|
10206
|
+
success: true,
|
|
10207
|
+
data: validatedMessages
|
|
10208
|
+
};
|
|
10209
|
+
} catch (error) {
|
|
10210
|
+
const err = error;
|
|
10211
|
+
return {
|
|
10212
|
+
success: false,
|
|
10213
|
+
error: err
|
|
10214
|
+
};
|
|
10124
10215
|
}
|
|
10125
|
-
|
|
10216
|
+
}
|
|
10217
|
+
async function validateUIMessages({
|
|
10218
|
+
messages,
|
|
10219
|
+
metadataSchema,
|
|
10220
|
+
dataSchemas,
|
|
10221
|
+
tools
|
|
10222
|
+
}) {
|
|
10223
|
+
const response = await safeValidateUIMessages({
|
|
10224
|
+
messages,
|
|
10225
|
+
metadataSchema,
|
|
10226
|
+
dataSchemas,
|
|
10227
|
+
tools
|
|
10228
|
+
});
|
|
10229
|
+
if (!response.success)
|
|
10230
|
+
throw response.error;
|
|
10231
|
+
return response.data;
|
|
10126
10232
|
}
|
|
10127
10233
|
|
|
10128
10234
|
// src/ui-message-stream/create-ui-message-stream.ts
|
|
@@ -10349,6 +10455,7 @@ export {
|
|
|
10349
10455
|
pipeTextStreamToResponse,
|
|
10350
10456
|
pipeUIMessageStreamToResponse,
|
|
10351
10457
|
readUIMessageStream,
|
|
10458
|
+
safeValidateUIMessages,
|
|
10352
10459
|
simulateReadableStream,
|
|
10353
10460
|
simulateStreamingMiddleware,
|
|
10354
10461
|
smoothStream,
|