ai 6.0.233 → 6.0.235
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 +19 -0
- package/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +33 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -21
- 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/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +29 -0
- 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/docs/08-migration-guides/24-migration-guide-6-0.mdx +28 -0
- package/package.json +2 -2
- 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-message-stream/pipe-ui-message-stream-to-response.ts +3 -2
- package/src/util/detect-media-type.ts +47 -26
- package/src/util/write-to-server-response.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.235
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5d7b986]
|
|
8
|
+
- @ai-sdk/gateway@3.0.157
|
|
9
|
+
|
|
10
|
+
## 6.0.234
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 1efdef8: fix(ai): bound media-type sniffing decode for ID3-prefixed input
|
|
15
|
+
|
|
16
|
+
Media-type detection stripped ID3 tags before the ~18-byte prefix cap, decoding the entire base64 attachment (plus a full-size copy) whenever the data began with `ID3`/`SUQz`. This turned the intended O(1) sniff into an O(N) decode of the whole attachment. Detection now decodes at most a bounded prefix and skips the ID3 tag within that bound, keeping cost O(1) in input size on all paths (image, audio, and combined).
|
|
17
|
+
|
|
18
|
+
- 49414cf: Return response piping promises so callers can catch stream read and write errors.
|
|
19
|
+
- Updated dependencies [e7d064f]
|
|
20
|
+
- @ai-sdk/gateway@3.0.156
|
|
21
|
+
|
|
3
22
|
## 6.0.233
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -2395,7 +2395,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2395
2395
|
/**
|
|
2396
2396
|
* Writes UI message stream output to a Node.js response-like object.
|
|
2397
2397
|
*/
|
|
2398
|
-
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void
|
|
2398
|
+
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Promise<void>;
|
|
2399
2399
|
/**
|
|
2400
2400
|
* Writes text delta output to a Node.js response-like object.
|
|
2401
2401
|
* It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
|
@@ -2404,7 +2404,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2404
2404
|
* @param response A Node.js response-like object (ServerResponse).
|
|
2405
2405
|
* @param init Optional headers, status code, and status text.
|
|
2406
2406
|
*/
|
|
2407
|
-
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void
|
|
2407
|
+
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): Promise<void>;
|
|
2408
2408
|
/**
|
|
2409
2409
|
* Converts the result to a streamed response object with a stream data part stream.
|
|
2410
2410
|
*
|
|
@@ -4245,11 +4245,12 @@ declare class JsonToSseTransformStream extends TransformStream<unknown, string>
|
|
|
4245
4245
|
* @param options.headers - Additional HTTP headers to include in the response.
|
|
4246
4246
|
* @param options.stream - The UI message chunk stream to send.
|
|
4247
4247
|
* @param options.consumeSseStream - Optional callback to consume a copy of the SSE stream independently.
|
|
4248
|
+
* @returns A promise that resolves when the stream has been written.
|
|
4248
4249
|
*/
|
|
4249
4250
|
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
|
4250
4251
|
response: ServerResponse;
|
|
4251
4252
|
stream: ReadableStream<UIMessageChunk>;
|
|
4252
|
-
} & UIMessageStreamResponseInit): void
|
|
4253
|
+
} & UIMessageStreamResponseInit): Promise<void>;
|
|
4253
4254
|
|
|
4254
4255
|
/**
|
|
4255
4256
|
* Transforms a stream of `UIMessageChunk`s into an `AsyncIterableStream` of `UIMessage`s.
|
|
@@ -5398,7 +5399,7 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
|
|
5398
5399
|
* @param response A Node.js response-like object (ServerResponse).
|
|
5399
5400
|
* @param init Optional headers, status code, and status text.
|
|
5400
5401
|
*/
|
|
5401
|
-
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void
|
|
5402
|
+
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): Promise<void>;
|
|
5402
5403
|
/**
|
|
5403
5404
|
* Creates a simple text stream response.
|
|
5404
5405
|
* The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
|
|
@@ -6283,11 +6284,12 @@ declare function createTextStreamResponse({ status, statusText, headers, textStr
|
|
|
6283
6284
|
* @param options.statusText - Optional HTTP status text.
|
|
6284
6285
|
* @param options.headers - Optional response headers.
|
|
6285
6286
|
* @param options.textStream - The text stream to pipe.
|
|
6287
|
+
* @returns A promise that resolves when the stream has been written.
|
|
6286
6288
|
*/
|
|
6287
6289
|
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
|
6288
6290
|
response: ServerResponse;
|
|
6289
6291
|
textStream: ReadableStream<string>;
|
|
6290
|
-
} & ResponseInit): void
|
|
6292
|
+
} & ResponseInit): Promise<void>;
|
|
6291
6293
|
|
|
6292
6294
|
/**
|
|
6293
6295
|
* The result of a `transcribe` call.
|
package/dist/index.d.ts
CHANGED
|
@@ -2395,7 +2395,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2395
2395
|
/**
|
|
2396
2396
|
* Writes UI message stream output to a Node.js response-like object.
|
|
2397
2397
|
*/
|
|
2398
|
-
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): void
|
|
2398
|
+
pipeUIMessageStreamToResponse<UI_MESSAGE extends UIMessage>(response: ServerResponse, options?: UIMessageStreamResponseInit & UIMessageStreamOptions<UI_MESSAGE>): Promise<void>;
|
|
2399
2399
|
/**
|
|
2400
2400
|
* Writes text delta output to a Node.js response-like object.
|
|
2401
2401
|
* It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
|
@@ -2404,7 +2404,7 @@ interface StreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
2404
2404
|
* @param response A Node.js response-like object (ServerResponse).
|
|
2405
2405
|
* @param init Optional headers, status code, and status text.
|
|
2406
2406
|
*/
|
|
2407
|
-
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): void
|
|
2407
|
+
pipeTextStreamToResponse(response: ServerResponse, init?: ResponseInit): Promise<void>;
|
|
2408
2408
|
/**
|
|
2409
2409
|
* Converts the result to a streamed response object with a stream data part stream.
|
|
2410
2410
|
*
|
|
@@ -4245,11 +4245,12 @@ declare class JsonToSseTransformStream extends TransformStream<unknown, string>
|
|
|
4245
4245
|
* @param options.headers - Additional HTTP headers to include in the response.
|
|
4246
4246
|
* @param options.stream - The UI message chunk stream to send.
|
|
4247
4247
|
* @param options.consumeSseStream - Optional callback to consume a copy of the SSE stream independently.
|
|
4248
|
+
* @returns A promise that resolves when the stream has been written.
|
|
4248
4249
|
*/
|
|
4249
4250
|
declare function pipeUIMessageStreamToResponse({ response, status, statusText, headers, stream, consumeSseStream, }: {
|
|
4250
4251
|
response: ServerResponse;
|
|
4251
4252
|
stream: ReadableStream<UIMessageChunk>;
|
|
4252
|
-
} & UIMessageStreamResponseInit): void
|
|
4253
|
+
} & UIMessageStreamResponseInit): Promise<void>;
|
|
4253
4254
|
|
|
4254
4255
|
/**
|
|
4255
4256
|
* Transforms a stream of `UIMessageChunk`s into an `AsyncIterableStream` of `UIMessage`s.
|
|
@@ -5398,7 +5399,7 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
|
|
5398
5399
|
* @param response A Node.js response-like object (ServerResponse).
|
|
5399
5400
|
* @param init Optional headers, status code, and status text.
|
|
5400
5401
|
*/
|
|
5401
|
-
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): void
|
|
5402
|
+
pipeTextStreamToResponse(response: ServerResponse$1, init?: ResponseInit): Promise<void>;
|
|
5402
5403
|
/**
|
|
5403
5404
|
* Creates a simple text stream response.
|
|
5404
5405
|
* The response has a `Content-Type` header set to `text/plain; charset=utf-8`.
|
|
@@ -6283,11 +6284,12 @@ declare function createTextStreamResponse({ status, statusText, headers, textStr
|
|
|
6283
6284
|
* @param options.statusText - Optional HTTP status text.
|
|
6284
6285
|
* @param options.headers - Optional response headers.
|
|
6285
6286
|
* @param options.textStream - The text stream to pipe.
|
|
6287
|
+
* @returns A promise that resolves when the stream has been written.
|
|
6286
6288
|
*/
|
|
6287
6289
|
declare function pipeTextStreamToResponse({ response, status, statusText, headers, textStream, }: {
|
|
6288
6290
|
response: ServerResponse;
|
|
6289
6291
|
textStream: ReadableStream<string>;
|
|
6290
|
-
} & ResponseInit): void
|
|
6292
|
+
} & ResponseInit): Promise<void>;
|
|
6291
6293
|
|
|
6292
6294
|
/**
|
|
6293
6295
|
* The result of a `transcribe` call.
|
package/dist/index.js
CHANGED
|
@@ -1259,25 +1259,37 @@ var videoMediaTypeSignatures = [
|
|
|
1259
1259
|
// RIFF (AVI)
|
|
1260
1260
|
}
|
|
1261
1261
|
];
|
|
1262
|
-
var
|
|
1263
|
-
|
|
1262
|
+
var DEFAULT_SNIFF_BYTES = 18;
|
|
1263
|
+
var MAX_SIGNATURE_BYTES = 12;
|
|
1264
|
+
var MAX_ID3_TAG_BYTES = 128 * 1024;
|
|
1265
|
+
var ID3_SCAN_BYTES = MAX_ID3_TAG_BYTES + MAX_SIGNATURE_BYTES;
|
|
1266
|
+
function decodePrefix(data, maxBytes) {
|
|
1267
|
+
if (typeof data !== "string") {
|
|
1268
|
+
return data.length > maxBytes ? data.subarray(0, maxBytes) : data;
|
|
1269
|
+
}
|
|
1270
|
+
const maxChars = Math.ceil(maxBytes / 3) * 4;
|
|
1271
|
+
const bytes = (0, import_provider_utils2.convertBase64ToUint8Array)(
|
|
1272
|
+
data.substring(0, Math.min(data.length, maxChars))
|
|
1273
|
+
);
|
|
1274
|
+
return bytes.length > maxBytes ? bytes.subarray(0, maxBytes) : bytes;
|
|
1275
|
+
}
|
|
1276
|
+
function hasID3(bytes) {
|
|
1277
|
+
return bytes.length > 10 && bytes[0] === 73 && // 'I'
|
|
1278
|
+
bytes[1] === 68 && // 'D'
|
|
1279
|
+
bytes[2] === 51;
|
|
1280
|
+
}
|
|
1281
|
+
var stripID3 = (bytes) => {
|
|
1264
1282
|
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
|
1265
|
-
return bytes.
|
|
1283
|
+
return bytes.subarray(id3Size + 10);
|
|
1266
1284
|
};
|
|
1267
|
-
function stripID3TagsIfPresent(data) {
|
|
1268
|
-
const hasId3 = typeof data === "string" && data.startsWith("SUQz") || typeof data !== "string" && data.length > 10 && data[0] === 73 && // 'I'
|
|
1269
|
-
data[1] === 68 && // 'D'
|
|
1270
|
-
data[2] === 51;
|
|
1271
|
-
return hasId3 ? stripID3(data) : data;
|
|
1272
|
-
}
|
|
1273
1285
|
function detectMediaType({
|
|
1274
1286
|
data,
|
|
1275
1287
|
signatures
|
|
1276
1288
|
}) {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1289
|
+
let bytes = decodePrefix(data, DEFAULT_SNIFF_BYTES);
|
|
1290
|
+
if (hasID3(bytes)) {
|
|
1291
|
+
bytes = stripID3(decodePrefix(data, ID3_SCAN_BYTES));
|
|
1292
|
+
}
|
|
1281
1293
|
for (const signature of signatures) {
|
|
1282
1294
|
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
1283
1295
|
(byte, index) => byte === null || bytes[index] === byte
|
|
@@ -1292,7 +1304,7 @@ function detectMediaType({
|
|
|
1292
1304
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1293
1305
|
|
|
1294
1306
|
// src/version.ts
|
|
1295
|
-
var VERSION = true ? "6.0.
|
|
1307
|
+
var VERSION = true ? "6.0.235" : "0.0.0-test";
|
|
1296
1308
|
|
|
1297
1309
|
// src/util/download/download.ts
|
|
1298
1310
|
var download = async ({
|
|
@@ -5462,7 +5474,7 @@ function writeToServerResponse({
|
|
|
5462
5474
|
response.end();
|
|
5463
5475
|
}
|
|
5464
5476
|
};
|
|
5465
|
-
read();
|
|
5477
|
+
return read();
|
|
5466
5478
|
}
|
|
5467
5479
|
|
|
5468
5480
|
// src/text-stream/pipe-text-stream-to-response.ts
|
|
@@ -5473,7 +5485,7 @@ function pipeTextStreamToResponse({
|
|
|
5473
5485
|
headers,
|
|
5474
5486
|
textStream
|
|
5475
5487
|
}) {
|
|
5476
|
-
writeToServerResponse({
|
|
5488
|
+
return writeToServerResponse({
|
|
5477
5489
|
response,
|
|
5478
5490
|
status,
|
|
5479
5491
|
statusText,
|
|
@@ -6484,7 +6496,7 @@ function pipeUIMessageStreamToResponse({
|
|
|
6484
6496
|
sseStream = stream1;
|
|
6485
6497
|
consumeSseStream({ stream: stream2 });
|
|
6486
6498
|
}
|
|
6487
|
-
writeToServerResponse({
|
|
6499
|
+
return writeToServerResponse({
|
|
6488
6500
|
response,
|
|
6489
6501
|
status,
|
|
6490
6502
|
statusText,
|
|
@@ -8721,7 +8733,7 @@ var DefaultStreamTextResult = class {
|
|
|
8721
8733
|
onError,
|
|
8722
8734
|
...init
|
|
8723
8735
|
} = {}) {
|
|
8724
|
-
pipeUIMessageStreamToResponse({
|
|
8736
|
+
return pipeUIMessageStreamToResponse({
|
|
8725
8737
|
response,
|
|
8726
8738
|
stream: this.toUIMessageStream({
|
|
8727
8739
|
originalMessages,
|
|
@@ -8738,7 +8750,7 @@ var DefaultStreamTextResult = class {
|
|
|
8738
8750
|
});
|
|
8739
8751
|
}
|
|
8740
8752
|
pipeTextStreamToResponse(response, init) {
|
|
8741
|
-
pipeTextStreamToResponse({
|
|
8753
|
+
return pipeTextStreamToResponse({
|
|
8742
8754
|
response,
|
|
8743
8755
|
textStream: this.textStream,
|
|
8744
8756
|
...init
|
|
@@ -9765,7 +9777,7 @@ async function pipeAgentUIStreamToResponse({
|
|
|
9765
9777
|
consumeSseStream,
|
|
9766
9778
|
...options
|
|
9767
9779
|
}) {
|
|
9768
|
-
pipeUIMessageStreamToResponse({
|
|
9780
|
+
return pipeUIMessageStreamToResponse({
|
|
9769
9781
|
response,
|
|
9770
9782
|
headers,
|
|
9771
9783
|
status,
|
|
@@ -11712,7 +11724,7 @@ var DefaultStreamObjectResult = class {
|
|
|
11712
11724
|
return createAsyncIterableStream(this.baseStream);
|
|
11713
11725
|
}
|
|
11714
11726
|
pipeTextStreamToResponse(response, init) {
|
|
11715
|
-
pipeTextStreamToResponse({
|
|
11727
|
+
return pipeTextStreamToResponse({
|
|
11716
11728
|
response,
|
|
11717
11729
|
textStream: this.textStream,
|
|
11718
11730
|
...init
|