ai 6.0.232 → 6.0.234
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 +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +132 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -77
- 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/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
- package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +6 -1
- package/package.json +4 -4
- package/src/agent/pipe-agent-ui-stream-to-response.ts +1 -1
- package/src/generate-object/stream-object-result.ts +4 -1
- package/src/generate-object/stream-object.ts +1 -1
- package/src/generate-text/stream-text-result.ts +5 -2
- package/src/generate-text/stream-text.ts +2 -2
- package/src/text-stream/pipe-text-stream-to-response.ts +3 -2
- package/src/ui/process-ui-message-stream.ts +109 -61
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +3 -2
- package/src/util/detect-media-type.ts +57 -27
- package/src/util/write-to-server-response.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1081,7 +1081,17 @@ var audioMediaTypeSignatures = [
|
|
|
1081
1081
|
},
|
|
1082
1082
|
{
|
|
1083
1083
|
mediaType: "audio/mp4",
|
|
1084
|
-
bytesPrefix: [
|
|
1084
|
+
bytesPrefix: [
|
|
1085
|
+
0,
|
|
1086
|
+
0,
|
|
1087
|
+
0,
|
|
1088
|
+
null,
|
|
1089
|
+
102,
|
|
1090
|
+
116,
|
|
1091
|
+
121,
|
|
1092
|
+
112
|
|
1093
|
+
// ftyp
|
|
1094
|
+
]
|
|
1085
1095
|
},
|
|
1086
1096
|
{
|
|
1087
1097
|
mediaType: "audio/webm",
|
|
@@ -1130,25 +1140,37 @@ var videoMediaTypeSignatures = [
|
|
|
1130
1140
|
// RIFF (AVI)
|
|
1131
1141
|
}
|
|
1132
1142
|
];
|
|
1133
|
-
var
|
|
1134
|
-
|
|
1143
|
+
var DEFAULT_SNIFF_BYTES = 18;
|
|
1144
|
+
var MAX_SIGNATURE_BYTES = 12;
|
|
1145
|
+
var MAX_ID3_TAG_BYTES = 128 * 1024;
|
|
1146
|
+
var ID3_SCAN_BYTES = MAX_ID3_TAG_BYTES + MAX_SIGNATURE_BYTES;
|
|
1147
|
+
function decodePrefix(data, maxBytes) {
|
|
1148
|
+
if (typeof data !== "string") {
|
|
1149
|
+
return data.length > maxBytes ? data.subarray(0, maxBytes) : data;
|
|
1150
|
+
}
|
|
1151
|
+
const maxChars = Math.ceil(maxBytes / 3) * 4;
|
|
1152
|
+
const bytes = convertBase64ToUint8Array(
|
|
1153
|
+
data.substring(0, Math.min(data.length, maxChars))
|
|
1154
|
+
);
|
|
1155
|
+
return bytes.length > maxBytes ? bytes.subarray(0, maxBytes) : bytes;
|
|
1156
|
+
}
|
|
1157
|
+
function hasID3(bytes) {
|
|
1158
|
+
return bytes.length > 10 && bytes[0] === 73 && // 'I'
|
|
1159
|
+
bytes[1] === 68 && // 'D'
|
|
1160
|
+
bytes[2] === 51;
|
|
1161
|
+
}
|
|
1162
|
+
var stripID3 = (bytes) => {
|
|
1135
1163
|
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
|
1136
|
-
return bytes.
|
|
1164
|
+
return bytes.subarray(id3Size + 10);
|
|
1137
1165
|
};
|
|
1138
|
-
function stripID3TagsIfPresent(data) {
|
|
1139
|
-
const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
|
|
1140
|
-
data[1] === 68 && // 'D'
|
|
1141
|
-
data[2] === 51;
|
|
1142
|
-
return hasId3 ? stripID3(data) : data;
|
|
1143
|
-
}
|
|
1144
1166
|
function detectMediaType({
|
|
1145
1167
|
data,
|
|
1146
1168
|
signatures
|
|
1147
1169
|
}) {
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1170
|
+
let bytes = decodePrefix(data, DEFAULT_SNIFF_BYTES);
|
|
1171
|
+
if (hasID3(bytes)) {
|
|
1172
|
+
bytes = stripID3(decodePrefix(data, ID3_SCAN_BYTES));
|
|
1173
|
+
}
|
|
1152
1174
|
for (const signature of signatures) {
|
|
1153
1175
|
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
1154
1176
|
(byte, index) => byte === null || bytes[index] === byte
|
|
@@ -1171,7 +1193,7 @@ import {
|
|
|
1171
1193
|
} from "@ai-sdk/provider-utils";
|
|
1172
1194
|
|
|
1173
1195
|
// src/version.ts
|
|
1174
|
-
var VERSION = true ? "6.0.
|
|
1196
|
+
var VERSION = true ? "6.0.234" : "0.0.0-test";
|
|
1175
1197
|
|
|
1176
1198
|
// src/util/download/download.ts
|
|
1177
1199
|
var download = async ({
|
|
@@ -5378,7 +5400,7 @@ function writeToServerResponse({
|
|
|
5378
5400
|
response.end();
|
|
5379
5401
|
}
|
|
5380
5402
|
};
|
|
5381
|
-
read();
|
|
5403
|
+
return read();
|
|
5382
5404
|
}
|
|
5383
5405
|
|
|
5384
5406
|
// src/text-stream/pipe-text-stream-to-response.ts
|
|
@@ -5389,7 +5411,7 @@ function pipeTextStreamToResponse({
|
|
|
5389
5411
|
headers,
|
|
5390
5412
|
textStream
|
|
5391
5413
|
}) {
|
|
5392
|
-
writeToServerResponse({
|
|
5414
|
+
return writeToServerResponse({
|
|
5393
5415
|
response,
|
|
5394
5416
|
status,
|
|
5395
5417
|
statusText,
|
|
@@ -5712,11 +5734,32 @@ function processUIMessageStream({
|
|
|
5712
5734
|
async transform(chunk, controller) {
|
|
5713
5735
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
5714
5736
|
var _a22, _b, _c, _d;
|
|
5737
|
+
function getCurrentStepParts() {
|
|
5738
|
+
const parts = state.message.parts;
|
|
5739
|
+
let currentStepStartIndex = parts.length - 1;
|
|
5740
|
+
while (currentStepStartIndex >= 0 && parts[currentStepStartIndex].type !== "step-start") {
|
|
5741
|
+
currentStepStartIndex--;
|
|
5742
|
+
}
|
|
5743
|
+
return parts.slice(currentStepStartIndex + 1);
|
|
5744
|
+
}
|
|
5745
|
+
function getCurrentStepToolInvocations() {
|
|
5746
|
+
return getCurrentStepParts().filter(isToolUIPart);
|
|
5747
|
+
}
|
|
5715
5748
|
function getToolInvocation(toolCallId) {
|
|
5716
|
-
const toolInvocations =
|
|
5717
|
-
|
|
5749
|
+
const toolInvocations = getCurrentStepToolInvocations();
|
|
5750
|
+
let toolInvocation = toolInvocations.find(
|
|
5718
5751
|
(invocation) => invocation.toolCallId === toolCallId
|
|
5719
5752
|
);
|
|
5753
|
+
if (toolInvocation == null) {
|
|
5754
|
+
const parts = state.message.parts;
|
|
5755
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
5756
|
+
const part = parts[i];
|
|
5757
|
+
if (isToolUIPart(part) && part.toolCallId === toolCallId) {
|
|
5758
|
+
toolInvocation = part;
|
|
5759
|
+
break;
|
|
5760
|
+
}
|
|
5761
|
+
}
|
|
5762
|
+
}
|
|
5720
5763
|
if (toolInvocation == null) {
|
|
5721
5764
|
throw new UIMessageStreamError({
|
|
5722
5765
|
chunkType: "tool-invocation",
|
|
@@ -5726,9 +5769,9 @@ function processUIMessageStream({
|
|
|
5726
5769
|
}
|
|
5727
5770
|
return toolInvocation;
|
|
5728
5771
|
}
|
|
5729
|
-
function updateToolPart(options) {
|
|
5772
|
+
function updateToolPart(options, existingPart) {
|
|
5730
5773
|
var _a23;
|
|
5731
|
-
const part =
|
|
5774
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
5732
5775
|
(part2) => isStaticToolUIPart(part2) && part2.toolCallId === options.toolCallId
|
|
5733
5776
|
);
|
|
5734
5777
|
const anyOptions = options;
|
|
@@ -5774,9 +5817,9 @@ function processUIMessageStream({
|
|
|
5774
5817
|
});
|
|
5775
5818
|
}
|
|
5776
5819
|
}
|
|
5777
|
-
function updateDynamicToolPart(options) {
|
|
5820
|
+
function updateDynamicToolPart(options, existingPart) {
|
|
5778
5821
|
var _a23, _b2;
|
|
5779
|
-
const part =
|
|
5822
|
+
const part = existingPart != null ? existingPart : getCurrentStepParts().find(
|
|
5780
5823
|
(part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
|
|
5781
5824
|
);
|
|
5782
5825
|
const anyOptions = options;
|
|
@@ -5956,7 +5999,7 @@ function processUIMessageStream({
|
|
|
5956
5999
|
break;
|
|
5957
6000
|
}
|
|
5958
6001
|
case "tool-input-start": {
|
|
5959
|
-
const toolInvocations =
|
|
6002
|
+
const toolInvocations = getCurrentStepParts().filter(isStaticToolUIPart);
|
|
5960
6003
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
5961
6004
|
text: "",
|
|
5962
6005
|
toolName: chunk.toolName,
|
|
@@ -6059,7 +6102,7 @@ function processUIMessageStream({
|
|
|
6059
6102
|
break;
|
|
6060
6103
|
}
|
|
6061
6104
|
case "tool-input-error": {
|
|
6062
|
-
const existingPart =
|
|
6105
|
+
const existingPart = getCurrentStepParts().filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
|
|
6063
6106
|
const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
|
|
6064
6107
|
if (isDynamic) {
|
|
6065
6108
|
updateDynamicToolPart({
|
|
@@ -6107,31 +6150,37 @@ function processUIMessageStream({
|
|
|
6107
6150
|
case "tool-output-available": {
|
|
6108
6151
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
6109
6152
|
if (toolInvocation.type === "dynamic-tool") {
|
|
6110
|
-
updateDynamicToolPart(
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6153
|
+
updateDynamicToolPart(
|
|
6154
|
+
{
|
|
6155
|
+
toolCallId: chunk.toolCallId,
|
|
6156
|
+
toolName: toolInvocation.toolName,
|
|
6157
|
+
state: "output-available",
|
|
6158
|
+
input: toolInvocation.input,
|
|
6159
|
+
output: chunk.output,
|
|
6160
|
+
preliminary: chunk.preliminary,
|
|
6161
|
+
providerExecuted: chunk.providerExecuted,
|
|
6162
|
+
providerMetadata: chunk.providerMetadata,
|
|
6163
|
+
title: toolInvocation.title,
|
|
6164
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6165
|
+
},
|
|
6166
|
+
toolInvocation
|
|
6167
|
+
);
|
|
6122
6168
|
} else {
|
|
6123
|
-
updateToolPart(
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6169
|
+
updateToolPart(
|
|
6170
|
+
{
|
|
6171
|
+
toolCallId: chunk.toolCallId,
|
|
6172
|
+
toolName: getStaticToolName(toolInvocation),
|
|
6173
|
+
state: "output-available",
|
|
6174
|
+
input: toolInvocation.input,
|
|
6175
|
+
output: chunk.output,
|
|
6176
|
+
providerExecuted: chunk.providerExecuted,
|
|
6177
|
+
preliminary: chunk.preliminary,
|
|
6178
|
+
providerMetadata: chunk.providerMetadata,
|
|
6179
|
+
title: toolInvocation.title,
|
|
6180
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6181
|
+
},
|
|
6182
|
+
toolInvocation
|
|
6183
|
+
);
|
|
6135
6184
|
}
|
|
6136
6185
|
write();
|
|
6137
6186
|
break;
|
|
@@ -6139,30 +6188,36 @@ function processUIMessageStream({
|
|
|
6139
6188
|
case "tool-output-error": {
|
|
6140
6189
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
6141
6190
|
if (toolInvocation.type === "dynamic-tool") {
|
|
6142
|
-
updateDynamicToolPart(
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6191
|
+
updateDynamicToolPart(
|
|
6192
|
+
{
|
|
6193
|
+
toolCallId: chunk.toolCallId,
|
|
6194
|
+
toolName: toolInvocation.toolName,
|
|
6195
|
+
state: "output-error",
|
|
6196
|
+
input: toolInvocation.input,
|
|
6197
|
+
errorText: chunk.errorText,
|
|
6198
|
+
providerExecuted: chunk.providerExecuted,
|
|
6199
|
+
providerMetadata: chunk.providerMetadata,
|
|
6200
|
+
title: toolInvocation.title,
|
|
6201
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6202
|
+
},
|
|
6203
|
+
toolInvocation
|
|
6204
|
+
);
|
|
6153
6205
|
} else {
|
|
6154
|
-
updateToolPart(
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6206
|
+
updateToolPart(
|
|
6207
|
+
{
|
|
6208
|
+
toolCallId: chunk.toolCallId,
|
|
6209
|
+
toolName: getStaticToolName(toolInvocation),
|
|
6210
|
+
state: "output-error",
|
|
6211
|
+
input: toolInvocation.input,
|
|
6212
|
+
rawInput: toolInvocation.rawInput,
|
|
6213
|
+
errorText: chunk.errorText,
|
|
6214
|
+
providerExecuted: chunk.providerExecuted,
|
|
6215
|
+
providerMetadata: chunk.providerMetadata,
|
|
6216
|
+
title: toolInvocation.title,
|
|
6217
|
+
toolMetadata: toolInvocation.toolMetadata
|
|
6218
|
+
},
|
|
6219
|
+
toolInvocation
|
|
6220
|
+
);
|
|
6166
6221
|
}
|
|
6167
6222
|
write();
|
|
6168
6223
|
break;
|
|
@@ -6367,7 +6422,7 @@ function pipeUIMessageStreamToResponse({
|
|
|
6367
6422
|
sseStream = stream1;
|
|
6368
6423
|
consumeSseStream({ stream: stream2 });
|
|
6369
6424
|
}
|
|
6370
|
-
writeToServerResponse({
|
|
6425
|
+
return writeToServerResponse({
|
|
6371
6426
|
response,
|
|
6372
6427
|
status,
|
|
6373
6428
|
statusText,
|
|
@@ -8606,7 +8661,7 @@ var DefaultStreamTextResult = class {
|
|
|
8606
8661
|
onError,
|
|
8607
8662
|
...init
|
|
8608
8663
|
} = {}) {
|
|
8609
|
-
pipeUIMessageStreamToResponse({
|
|
8664
|
+
return pipeUIMessageStreamToResponse({
|
|
8610
8665
|
response,
|
|
8611
8666
|
stream: this.toUIMessageStream({
|
|
8612
8667
|
originalMessages,
|
|
@@ -8623,7 +8678,7 @@ var DefaultStreamTextResult = class {
|
|
|
8623
8678
|
});
|
|
8624
8679
|
}
|
|
8625
8680
|
pipeTextStreamToResponse(response, init) {
|
|
8626
|
-
pipeTextStreamToResponse({
|
|
8681
|
+
return pipeTextStreamToResponse({
|
|
8627
8682
|
response,
|
|
8628
8683
|
textStream: this.textStream,
|
|
8629
8684
|
...init
|
|
@@ -9660,7 +9715,7 @@ async function pipeAgentUIStreamToResponse({
|
|
|
9660
9715
|
consumeSseStream,
|
|
9661
9716
|
...options
|
|
9662
9717
|
}) {
|
|
9663
|
-
pipeUIMessageStreamToResponse({
|
|
9718
|
+
return pipeUIMessageStreamToResponse({
|
|
9664
9719
|
response,
|
|
9665
9720
|
headers,
|
|
9666
9721
|
status,
|
|
@@ -11628,7 +11683,7 @@ var DefaultStreamObjectResult = class {
|
|
|
11628
11683
|
return createAsyncIterableStream(this.baseStream);
|
|
11629
11684
|
}
|
|
11630
11685
|
pipeTextStreamToResponse(response, init) {
|
|
11631
|
-
pipeTextStreamToResponse({
|
|
11686
|
+
return pipeTextStreamToResponse({
|
|
11632
11687
|
response,
|
|
11633
11688
|
textStream: this.textStream,
|
|
11634
11689
|
...init
|