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.d.mts CHANGED
@@ -752,7 +752,7 @@ declare class StreamTextResult<TOOLS extends Record<string, ExperimentalTool>> {
752
752
  /**
753
753
  Writes stream data output to a Node.js response-like object.
754
754
  It sets a `Content-Type` header to `text/plain; charset=utf-8` and
755
- writes each text delta as a separate chunk.
755
+ writes each stream data part as a separate chunk.
756
756
 
757
757
  @param response A Node.js response-like object (ServerResponse).
758
758
  @param init Optional headers and status code.
@@ -762,6 +762,18 @@ declare class StreamTextResult<TOOLS extends Record<string, ExperimentalTool>> {
762
762
  status?: number;
763
763
  }): void;
764
764
  /**
765
+ Writes text delta output to a Node.js response-like object.
766
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
767
+ writes each text delta as a separate chunk.
768
+
769
+ @param response A Node.js response-like object (ServerResponse).
770
+ @param init Optional headers and status code.
771
+ */
772
+ pipeTextStreamToResponse(response: ServerResponse, init?: {
773
+ headers?: Record<string, string>;
774
+ status?: number;
775
+ }): void;
776
+ /**
765
777
  Converts the result to a streamed response object with a stream data part stream.
766
778
  It can be used with the `useChat` and `useCompletion` hooks.
767
779
 
package/dist/index.d.ts CHANGED
@@ -752,7 +752,7 @@ declare class StreamTextResult<TOOLS extends Record<string, ExperimentalTool>> {
752
752
  /**
753
753
  Writes stream data output to a Node.js response-like object.
754
754
  It sets a `Content-Type` header to `text/plain; charset=utf-8` and
755
- writes each text delta as a separate chunk.
755
+ writes each stream data part as a separate chunk.
756
756
 
757
757
  @param response A Node.js response-like object (ServerResponse).
758
758
  @param init Optional headers and status code.
@@ -762,6 +762,18 @@ declare class StreamTextResult<TOOLS extends Record<string, ExperimentalTool>> {
762
762
  status?: number;
763
763
  }): void;
764
764
  /**
765
+ Writes text delta output to a Node.js response-like object.
766
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
767
+ writes each text delta as a separate chunk.
768
+
769
+ @param response A Node.js response-like object (ServerResponse).
770
+ @param init Optional headers and status code.
771
+ */
772
+ pipeTextStreamToResponse(response: ServerResponse, init?: {
773
+ headers?: Record<string, string>;
774
+ status?: number;
775
+ }): void;
776
+ /**
765
777
  Converts the result to a streamed response object with a stream data part stream.
766
778
  It can be used with the `useChat` and `useCompletion` hooks.
767
779
 
package/dist/index.js CHANGED
@@ -1517,7 +1517,7 @@ var StreamTextResult = class {
1517
1517
  /**
1518
1518
  Writes stream data output to a Node.js response-like object.
1519
1519
  It sets a `Content-Type` header to `text/plain; charset=utf-8` and
1520
- writes each text delta as a separate chunk.
1520
+ writes each stream data part as a separate chunk.
1521
1521
 
1522
1522
  @param response A Node.js response-like object (ServerResponse).
1523
1523
  @param init Optional headers and status code.
@@ -1546,6 +1546,38 @@ var StreamTextResult = class {
1546
1546
  read();
1547
1547
  }
1548
1548
  /**
1549
+ Writes text delta output to a Node.js response-like object.
1550
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
1551
+ writes each text delta as a separate chunk.
1552
+
1553
+ @param response A Node.js response-like object (ServerResponse).
1554
+ @param init Optional headers and status code.
1555
+ */
1556
+ pipeTextStreamToResponse(response, init) {
1557
+ var _a;
1558
+ response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
1559
+ "Content-Type": "text/plain; charset=utf-8",
1560
+ ...init == null ? void 0 : init.headers
1561
+ });
1562
+ const reader = this.textStream.getReader();
1563
+ const read = async () => {
1564
+ const encoder = new TextEncoder();
1565
+ try {
1566
+ while (true) {
1567
+ const { done, value } = await reader.read();
1568
+ if (done)
1569
+ break;
1570
+ response.write(encoder.encode(value));
1571
+ }
1572
+ } catch (error) {
1573
+ throw error;
1574
+ } finally {
1575
+ response.end();
1576
+ }
1577
+ };
1578
+ read();
1579
+ }
1580
+ /**
1549
1581
  Converts the result to a streamed response object with a stream data part stream.
1550
1582
  It can be used with the `useChat` and `useCompletion` hooks.
1551
1583