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 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,9 +762,32 @@ 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
+ /**
777
+ Converts the result to a streamed response object with a stream data part stream.
778
+ It can be used with the `useChat` and `useCompletion` hooks.
779
+
780
+ @param init Optional headers.
781
+
782
+ @return A response object.
783
+ */
784
+ toAIStreamResponse(init?: ResponseInit): Response;
785
+ /**
765
786
  Creates a simple text stream response.
766
787
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
767
788
  Non-text-delta events are ignored.
789
+
790
+ @param init Optional headers and status code.
768
791
  */
769
792
  toTextStreamResponse(init?: ResponseInit): Response;
770
793
  }
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,9 +762,32 @@ 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
+ /**
777
+ Converts the result to a streamed response object with a stream data part stream.
778
+ It can be used with the `useChat` and `useCompletion` hooks.
779
+
780
+ @param init Optional headers.
781
+
782
+ @return A response object.
783
+ */
784
+ toAIStreamResponse(init?: ResponseInit): Response;
785
+ /**
765
786
  Creates a simple text stream response.
766
787
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
767
788
  Non-text-delta events are ignored.
789
+
790
+ @param init Optional headers and status code.
768
791
  */
769
792
  toTextStreamResponse(init?: ResponseInit): Response;
770
793
  }
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ __export(streams_exports, {
48
48
  MistralStream: () => MistralStream,
49
49
  OpenAIStream: () => OpenAIStream,
50
50
  ReplicateStream: () => ReplicateStream,
51
- StreamData: () => StreamData,
51
+ StreamData: () => StreamData2,
52
52
  StreamObjectResult: () => StreamObjectResult,
53
53
  StreamTextResult: () => StreamTextResult,
54
54
  StreamingTextResponse: () => StreamingTextResponse,
@@ -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,9 +1546,54 @@ 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
+ /**
1581
+ Converts the result to a streamed response object with a stream data part stream.
1582
+ It can be used with the `useChat` and `useCompletion` hooks.
1583
+
1584
+ @param init Optional headers.
1585
+
1586
+ @return A response object.
1587
+ */
1588
+ toAIStreamResponse(init) {
1589
+ return new StreamingTextResponse(this.toAIStream(), init);
1590
+ }
1591
+ /**
1549
1592
  Creates a simple text stream response.
1550
1593
  Each text delta is encoded as UTF-8 and sent as a separate chunk.
1551
1594
  Non-text-delta events are ignored.
1595
+
1596
+ @param init Optional headers and status code.
1552
1597
  */
1553
1598
  toTextStreamResponse(init) {
1554
1599
  var _a;
@@ -1940,7 +1985,7 @@ function readableFromAsyncIterable(iterable) {
1940
1985
  }
1941
1986
 
1942
1987
  // streams/stream-data.ts
1943
- var StreamData = class {
1988
+ var StreamData2 = class {
1944
1989
  constructor() {
1945
1990
  this.encoder = new TextEncoder();
1946
1991
  this.controller = null;
@@ -2036,7 +2081,7 @@ function createStreamDataTransformer() {
2036
2081
  }
2037
2082
  });
2038
2083
  }
2039
- var experimental_StreamData = class extends StreamData {
2084
+ var experimental_StreamData = class extends StreamData2 {
2040
2085
  };
2041
2086
 
2042
2087
  // streams/anthropic-stream.ts