ai 3.0.31 → 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.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 text delta as a separate chunk.
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,6 +1474,38 @@ 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
+ /**
1477
1509
  Converts the result to a streamed response object with a stream data part stream.
1478
1510
  It can be used with the `useChat` and `useCompletion` hooks.
1479
1511