ai 3.0.24 → 3.0.26
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/dist/index.d.mts +46 -10
- package/dist/index.d.ts +46 -10
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/react/dist/index.d.mts +9 -0
- package/react/dist/index.d.ts +9 -0
- package/react/dist/index.js +22 -12
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +22 -12
- package/react/dist/index.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -1420,11 +1420,43 @@ var StreamTextResult = class {
|
|
1420
1420
|
return this.textStream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
|
1421
1421
|
}
|
1422
1422
|
/**
|
1423
|
+
Writes stream data output to a Node.js response-like object.
|
1424
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
1425
|
+
writes each text delta as a separate chunk.
|
1426
|
+
|
1427
|
+
@param response A Node.js response-like object (ServerResponse).
|
1428
|
+
@param init Optional headers and status code.
|
1429
|
+
*/
|
1430
|
+
pipeAIStreamToResponse(response, init) {
|
1431
|
+
var _a;
|
1432
|
+
response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
|
1433
|
+
"Content-Type": "text/plain; charset=utf-8",
|
1434
|
+
...init == null ? void 0 : init.headers
|
1435
|
+
});
|
1436
|
+
const reader = this.textStream.pipeThrough(createCallbacksTransformer(void 0)).pipeThrough(createStreamDataTransformer()).getReader();
|
1437
|
+
const read = async () => {
|
1438
|
+
try {
|
1439
|
+
while (true) {
|
1440
|
+
const { done, value } = await reader.read();
|
1441
|
+
if (done)
|
1442
|
+
break;
|
1443
|
+
response.write(value);
|
1444
|
+
}
|
1445
|
+
} catch (error) {
|
1446
|
+
throw error;
|
1447
|
+
} finally {
|
1448
|
+
response.end();
|
1449
|
+
}
|
1450
|
+
};
|
1451
|
+
read();
|
1452
|
+
}
|
1453
|
+
/**
|
1423
1454
|
Creates a simple text stream response.
|
1424
1455
|
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
1425
1456
|
Non-text-delta events are ignored.
|
1426
1457
|
*/
|
1427
1458
|
toTextStreamResponse(init) {
|
1459
|
+
var _a;
|
1428
1460
|
const encoder = new TextEncoder();
|
1429
1461
|
return new Response(
|
1430
1462
|
this.textStream.pipeThrough(
|
@@ -1435,8 +1467,7 @@ var StreamTextResult = class {
|
|
1435
1467
|
})
|
1436
1468
|
),
|
1437
1469
|
{
|
1438
|
-
|
1439
|
-
status: 200,
|
1470
|
+
status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
|
1440
1471
|
headers: {
|
1441
1472
|
"Content-Type": "text/plain; charset=utf-8",
|
1442
1473
|
...init == null ? void 0 : init.headers
|