ai 5.0.217 → 5.0.219
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 +21 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +129 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -64
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +26 -14
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +26 -14
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -641,32 +641,54 @@ var audioMediaTypeSignatures = [
|
|
|
641
641
|
},
|
|
642
642
|
{
|
|
643
643
|
mediaType: "audio/mp4",
|
|
644
|
-
bytesPrefix: [
|
|
644
|
+
bytesPrefix: [
|
|
645
|
+
0,
|
|
646
|
+
0,
|
|
647
|
+
0,
|
|
648
|
+
null,
|
|
649
|
+
102,
|
|
650
|
+
116,
|
|
651
|
+
121,
|
|
652
|
+
112
|
|
653
|
+
// ftyp
|
|
654
|
+
]
|
|
645
655
|
},
|
|
646
656
|
{
|
|
647
657
|
mediaType: "audio/webm",
|
|
648
658
|
bytesPrefix: [26, 69, 223, 163]
|
|
649
659
|
}
|
|
650
660
|
];
|
|
651
|
-
var
|
|
652
|
-
|
|
661
|
+
var DEFAULT_SNIFF_BYTES = 18;
|
|
662
|
+
var MAX_SIGNATURE_BYTES = 12;
|
|
663
|
+
var MAX_ID3_TAG_BYTES = 128 * 1024;
|
|
664
|
+
var ID3_SCAN_BYTES = MAX_ID3_TAG_BYTES + MAX_SIGNATURE_BYTES;
|
|
665
|
+
function decodePrefix(data, maxBytes) {
|
|
666
|
+
if (typeof data !== "string") {
|
|
667
|
+
return data.length > maxBytes ? data.subarray(0, maxBytes) : data;
|
|
668
|
+
}
|
|
669
|
+
const maxChars = Math.ceil(maxBytes / 3) * 4;
|
|
670
|
+
const bytes = convertBase64ToUint8Array(
|
|
671
|
+
data.substring(0, Math.min(data.length, maxChars))
|
|
672
|
+
);
|
|
673
|
+
return bytes.length > maxBytes ? bytes.subarray(0, maxBytes) : bytes;
|
|
674
|
+
}
|
|
675
|
+
function hasID3(bytes) {
|
|
676
|
+
return bytes.length > 10 && bytes[0] === 73 && // 'I'
|
|
677
|
+
bytes[1] === 68 && // 'D'
|
|
678
|
+
bytes[2] === 51;
|
|
679
|
+
}
|
|
680
|
+
var stripID3 = (bytes) => {
|
|
653
681
|
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
|
654
|
-
return bytes.
|
|
682
|
+
return bytes.subarray(id3Size + 10);
|
|
655
683
|
};
|
|
656
|
-
function stripID3TagsIfPresent(data) {
|
|
657
|
-
const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
|
|
658
|
-
data[1] === 68 && // 'D'
|
|
659
|
-
data[2] === 51;
|
|
660
|
-
return hasId3 ? stripID3(data) : data;
|
|
661
|
-
}
|
|
662
684
|
function detectMediaType({
|
|
663
685
|
data,
|
|
664
686
|
signatures
|
|
665
687
|
}) {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
688
|
+
let bytes = decodePrefix(data, DEFAULT_SNIFF_BYTES);
|
|
689
|
+
if (hasID3(bytes)) {
|
|
690
|
+
bytes = stripID3(decodePrefix(data, ID3_SCAN_BYTES));
|
|
691
|
+
}
|
|
670
692
|
for (const signature of signatures) {
|
|
671
693
|
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
672
694
|
(byte, index) => byte === null || bytes[index] === byte
|
|
@@ -689,7 +711,7 @@ import {
|
|
|
689
711
|
} from "@ai-sdk/provider-utils";
|
|
690
712
|
|
|
691
713
|
// src/version.ts
|
|
692
|
-
var VERSION = true ? "5.0.
|
|
714
|
+
var VERSION = true ? "5.0.219" : "0.0.0-test";
|
|
693
715
|
|
|
694
716
|
// src/util/download/download.ts
|
|
695
717
|
var download = async ({
|
|
@@ -2861,7 +2883,7 @@ function writeToServerResponse({
|
|
|
2861
2883
|
response.end();
|
|
2862
2884
|
}
|
|
2863
2885
|
};
|
|
2864
|
-
read();
|
|
2886
|
+
return read();
|
|
2865
2887
|
}
|
|
2866
2888
|
|
|
2867
2889
|
// src/text-stream/pipe-text-stream-to-response.ts
|
|
@@ -2872,7 +2894,7 @@ function pipeTextStreamToResponse({
|
|
|
2872
2894
|
headers,
|
|
2873
2895
|
textStream
|
|
2874
2896
|
}) {
|
|
2875
|
-
writeToServerResponse({
|
|
2897
|
+
return writeToServerResponse({
|
|
2876
2898
|
response,
|
|
2877
2899
|
status,
|
|
2878
2900
|
statusText,
|
|
@@ -3543,11 +3565,32 @@ function processUIMessageStream({
|
|
|
3543
3565
|
async transform(chunk, controller) {
|
|
3544
3566
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
3545
3567
|
var _a16, _b, _c, _d;
|
|
3568
|
+
function getCurrentStepParts() {
|
|
3569
|
+
const parts = state.message.parts;
|
|
3570
|
+
let currentStepStartIndex = parts.length - 1;
|
|
3571
|
+
while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
|
|
3572
|
+
currentStepStartIndex--;
|
|
3573
|
+
}
|
|
3574
|
+
return parts.slice(currentStepStartIndex + 1);
|
|
3575
|
+
}
|
|
3576
|
+
function getCurrentStepToolInvocations() {
|
|
3577
|
+
return getCurrentStepParts().filter(isToolUIPart);
|
|
3578
|
+
}
|
|
3546
3579
|
function getToolInvocation(toolCallId) {
|
|
3547
|
-
const toolInvocations =
|
|
3548
|
-
|
|
3580
|
+
const toolInvocations = getCurrentStepToolInvocations();
|
|
3581
|
+
let toolInvocation = toolInvocations.find(
|
|
3549
3582
|
(invocation) => invocation.toolCallId === toolCallId
|
|
3550
3583
|
);
|
|
3584
|
+
if (toolInvocation == null) {
|
|
3585
|
+
const parts = state.message.parts;
|
|
3586
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3587
|
+
const part = parts[i];
|
|
3588
|
+
if (isToolUIPart(part) && part.toolCallId === toolCallId) {
|
|
3589
|
+
toolInvocation = part;
|
|
3590
|
+
break;
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3551
3594
|
if (toolInvocation == null) {
|
|
3552
3595
|
throw new Error(
|
|
3553
3596
|
"tool-output-error must be preceded by a tool-input-available"
|
|
@@ -3556,12 +3599,22 @@ function processUIMessageStream({
|
|
|
3556
3599
|
return toolInvocation;
|
|
3557
3600
|
}
|
|
3558
3601
|
function getDynamicToolInvocation(toolCallId) {
|
|
3559
|
-
const toolInvocations =
|
|
3602
|
+
const toolInvocations = getCurrentStepParts().filter(
|
|
3560
3603
|
(part) => part.type === "dynamic-tool"
|
|
3561
3604
|
);
|
|
3562
|
-
|
|
3605
|
+
let toolInvocation = toolInvocations.find(
|
|
3563
3606
|
(invocation) => invocation.toolCallId === toolCallId
|
|
3564
3607
|
);
|
|
3608
|
+
if (toolInvocation == null) {
|
|
3609
|
+
const parts = state.message.parts;
|
|
3610
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3611
|
+
const part = parts[i];
|
|
3612
|
+
if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) {
|
|
3613
|
+
toolInvocation = part;
|
|
3614
|
+
break;
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3565
3618
|
if (toolInvocation == null) {
|
|
3566
3619
|
throw new Error(
|
|
3567
3620
|
"tool-output-error must be preceded by a tool-input-available"
|
|
@@ -3569,9 +3622,9 @@ function processUIMessageStream({
|
|
|
3569
3622
|
}
|
|
3570
3623
|
return toolInvocation;
|
|
3571
3624
|
}
|
|
3572
|
-
function updateToolPart(options) {
|
|
3625
|
+
function updateToolPart(options, existingPart) {
|
|
3573
3626
|
var _a17;
|
|
3574
|
-
const part =
|
|
3627
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3575
3628
|
(part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
3576
3629
|
);
|
|
3577
3630
|
const anyOptions = options;
|
|
@@ -3602,9 +3655,9 @@ function processUIMessageStream({
|
|
|
3602
3655
|
});
|
|
3603
3656
|
}
|
|
3604
3657
|
}
|
|
3605
|
-
function updateDynamicToolPart(options) {
|
|
3658
|
+
function updateDynamicToolPart(options, existingPart) {
|
|
3606
3659
|
var _a17, _b2;
|
|
3607
|
-
const part =
|
|
3660
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
3608
3661
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
3609
3662
|
);
|
|
3610
3663
|
const anyOptions = options;
|
|
@@ -3736,7 +3789,7 @@ function processUIMessageStream({
|
|
|
3736
3789
|
break;
|
|
3737
3790
|
}
|
|
3738
3791
|
case "tool-input-start": {
|
|
3739
|
-
const toolInvocations =
|
|
3792
|
+
const toolInvocations = getCurrentStepParts().filter(isToolUIPart);
|
|
3740
3793
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
3741
3794
|
text: "",
|
|
3742
3795
|
toolName: chunk.toolName,
|
|
@@ -3846,25 +3899,31 @@ function processUIMessageStream({
|
|
|
3846
3899
|
const toolInvocation = getDynamicToolInvocation(
|
|
3847
3900
|
chunk.toolCallId
|
|
3848
3901
|
);
|
|
3849
|
-
updateDynamicToolPart(
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3902
|
+
updateDynamicToolPart(
|
|
3903
|
+
{
|
|
3904
|
+
toolCallId: chunk.toolCallId,
|
|
3905
|
+
toolName: toolInvocation.toolName,
|
|
3906
|
+
state: "output-available",
|
|
3907
|
+
input: toolInvocation.input,
|
|
3908
|
+
output: chunk.output,
|
|
3909
|
+
preliminary: chunk.preliminary
|
|
3910
|
+
},
|
|
3911
|
+
toolInvocation
|
|
3912
|
+
);
|
|
3857
3913
|
} else {
|
|
3858
3914
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
3859
|
-
updateToolPart(
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3915
|
+
updateToolPart(
|
|
3916
|
+
{
|
|
3917
|
+
toolCallId: chunk.toolCallId,
|
|
3918
|
+
toolName: getToolName(toolInvocation),
|
|
3919
|
+
state: "output-available",
|
|
3920
|
+
input: toolInvocation.input,
|
|
3921
|
+
output: chunk.output,
|
|
3922
|
+
providerExecuted: chunk.providerExecuted,
|
|
3923
|
+
preliminary: chunk.preliminary
|
|
3924
|
+
},
|
|
3925
|
+
toolInvocation
|
|
3926
|
+
);
|
|
3868
3927
|
}
|
|
3869
3928
|
write();
|
|
3870
3929
|
break;
|
|
@@ -3874,25 +3933,31 @@ function processUIMessageStream({
|
|
|
3874
3933
|
const toolInvocation = getDynamicToolInvocation(
|
|
3875
3934
|
chunk.toolCallId
|
|
3876
3935
|
);
|
|
3877
|
-
updateDynamicToolPart(
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3936
|
+
updateDynamicToolPart(
|
|
3937
|
+
{
|
|
3938
|
+
toolCallId: chunk.toolCallId,
|
|
3939
|
+
toolName: toolInvocation.toolName,
|
|
3940
|
+
state: "output-error",
|
|
3941
|
+
input: toolInvocation.input,
|
|
3942
|
+
errorText: chunk.errorText,
|
|
3943
|
+
providerExecuted: chunk.providerExecuted
|
|
3944
|
+
},
|
|
3945
|
+
toolInvocation
|
|
3946
|
+
);
|
|
3885
3947
|
} else {
|
|
3886
3948
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
3887
|
-
updateToolPart(
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3949
|
+
updateToolPart(
|
|
3950
|
+
{
|
|
3951
|
+
toolCallId: chunk.toolCallId,
|
|
3952
|
+
toolName: getToolName(toolInvocation),
|
|
3953
|
+
state: "output-error",
|
|
3954
|
+
input: toolInvocation.input,
|
|
3955
|
+
rawInput: toolInvocation.rawInput,
|
|
3956
|
+
errorText: chunk.errorText,
|
|
3957
|
+
providerExecuted: chunk.providerExecuted
|
|
3958
|
+
},
|
|
3959
|
+
toolInvocation
|
|
3960
|
+
);
|
|
3896
3961
|
}
|
|
3897
3962
|
write();
|
|
3898
3963
|
break;
|
|
@@ -4066,7 +4131,7 @@ function pipeUIMessageStreamToResponse({
|
|
|
4066
4131
|
sseStream = stream1;
|
|
4067
4132
|
consumeSseStream({ stream: stream2 });
|
|
4068
4133
|
}
|
|
4069
|
-
writeToServerResponse({
|
|
4134
|
+
return writeToServerResponse({
|
|
4070
4135
|
response,
|
|
4071
4136
|
status,
|
|
4072
4137
|
statusText,
|
|
@@ -5817,7 +5882,7 @@ var DefaultStreamTextResult = class {
|
|
|
5817
5882
|
onError,
|
|
5818
5883
|
...init
|
|
5819
5884
|
} = {}) {
|
|
5820
|
-
pipeUIMessageStreamToResponse({
|
|
5885
|
+
return pipeUIMessageStreamToResponse({
|
|
5821
5886
|
response,
|
|
5822
5887
|
stream: this.toUIMessageStream({
|
|
5823
5888
|
originalMessages,
|
|
@@ -5834,7 +5899,7 @@ var DefaultStreamTextResult = class {
|
|
|
5834
5899
|
});
|
|
5835
5900
|
}
|
|
5836
5901
|
pipeTextStreamToResponse(response, init) {
|
|
5837
|
-
pipeTextStreamToResponse({
|
|
5902
|
+
return pipeTextStreamToResponse({
|
|
5838
5903
|
response,
|
|
5839
5904
|
textStream: this.textStream,
|
|
5840
5905
|
...init
|
|
@@ -7980,7 +8045,7 @@ var DefaultStreamObjectResult = class {
|
|
|
7980
8045
|
return createAsyncIterableStream(this.baseStream);
|
|
7981
8046
|
}
|
|
7982
8047
|
pipeTextStreamToResponse(response, init) {
|
|
7983
|
-
pipeTextStreamToResponse({
|
|
8048
|
+
return pipeTextStreamToResponse({
|
|
7984
8049
|
response,
|
|
7985
8050
|
textStream: this.textStream,
|
|
7986
8051
|
...init
|