ai 3.0.30 → 3.0.32
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 +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +49 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -1445,7 +1445,7 @@ var StreamTextResult = class {
|
|
1445
1445
|
/**
|
1446
1446
|
Writes stream data output to a Node.js response-like object.
|
1447
1447
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
1448
|
-
writes each
|
1448
|
+
writes each stream data part as a separate chunk.
|
1449
1449
|
|
1450
1450
|
@param response A Node.js response-like object (ServerResponse).
|
1451
1451
|
@param init Optional headers and status code.
|
@@ -1474,9 +1474,54 @@ var StreamTextResult = class {
|
|
1474
1474
|
read();
|
1475
1475
|
}
|
1476
1476
|
/**
|
1477
|
+
Writes text delta output to a Node.js response-like object.
|
1478
|
+
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
1479
|
+
writes each text delta as a separate chunk.
|
1480
|
+
|
1481
|
+
@param response A Node.js response-like object (ServerResponse).
|
1482
|
+
@param init Optional headers and status code.
|
1483
|
+
*/
|
1484
|
+
pipeTextStreamToResponse(response, init) {
|
1485
|
+
var _a;
|
1486
|
+
response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
|
1487
|
+
"Content-Type": "text/plain; charset=utf-8",
|
1488
|
+
...init == null ? void 0 : init.headers
|
1489
|
+
});
|
1490
|
+
const reader = this.textStream.getReader();
|
1491
|
+
const read = async () => {
|
1492
|
+
const encoder = new TextEncoder();
|
1493
|
+
try {
|
1494
|
+
while (true) {
|
1495
|
+
const { done, value } = await reader.read();
|
1496
|
+
if (done)
|
1497
|
+
break;
|
1498
|
+
response.write(encoder.encode(value));
|
1499
|
+
}
|
1500
|
+
} catch (error) {
|
1501
|
+
throw error;
|
1502
|
+
} finally {
|
1503
|
+
response.end();
|
1504
|
+
}
|
1505
|
+
};
|
1506
|
+
read();
|
1507
|
+
}
|
1508
|
+
/**
|
1509
|
+
Converts the result to a streamed response object with a stream data part stream.
|
1510
|
+
It can be used with the `useChat` and `useCompletion` hooks.
|
1511
|
+
|
1512
|
+
@param init Optional headers.
|
1513
|
+
|
1514
|
+
@return A response object.
|
1515
|
+
*/
|
1516
|
+
toAIStreamResponse(init) {
|
1517
|
+
return new StreamingTextResponse(this.toAIStream(), init);
|
1518
|
+
}
|
1519
|
+
/**
|
1477
1520
|
Creates a simple text stream response.
|
1478
1521
|
Each text delta is encoded as UTF-8 and sent as a separate chunk.
|
1479
1522
|
Non-text-delta events are ignored.
|
1523
|
+
|
1524
|
+
@param init Optional headers and status code.
|
1480
1525
|
*/
|
1481
1526
|
toTextStreamResponse(init) {
|
1482
1527
|
var _a;
|
@@ -1870,7 +1915,7 @@ function readableFromAsyncIterable(iterable) {
|
|
1870
1915
|
}
|
1871
1916
|
|
1872
1917
|
// streams/stream-data.ts
|
1873
|
-
var
|
1918
|
+
var StreamData2 = class {
|
1874
1919
|
constructor() {
|
1875
1920
|
this.encoder = new TextEncoder();
|
1876
1921
|
this.controller = null;
|
@@ -1966,7 +2011,7 @@ function createStreamDataTransformer() {
|
|
1966
2011
|
}
|
1967
2012
|
});
|
1968
2013
|
}
|
1969
|
-
var experimental_StreamData = class extends
|
2014
|
+
var experimental_StreamData = class extends StreamData2 {
|
1970
2015
|
};
|
1971
2016
|
|
1972
2017
|
// streams/anthropic-stream.ts
|
@@ -2910,7 +2955,7 @@ export {
|
|
2910
2955
|
MistralStream,
|
2911
2956
|
OpenAIStream,
|
2912
2957
|
ReplicateStream,
|
2913
|
-
StreamData,
|
2958
|
+
StreamData2 as StreamData,
|
2914
2959
|
StreamObjectResult,
|
2915
2960
|
StreamTextResult,
|
2916
2961
|
StreamingTextResponse,
|