ai 3.0.31 → 3.0.33

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
@@ -48,7 +48,7 @@ __export(streams_exports, {
48
48
  MistralStream: () => MistralStream,
49
49
  OpenAIStream: () => OpenAIStream,
50
50
  ReplicateStream: () => ReplicateStream,
51
- StreamData: () => StreamData2,
51
+ StreamData: () => StreamData,
52
52
  StreamObjectResult: () => StreamObjectResult,
53
53
  StreamTextResult: () => StreamTextResult,
54
54
  StreamingTextResponse: () => StreamingTextResponse,
@@ -374,7 +374,7 @@ async function _retryWithExponentialBackoff(f, {
374
374
  try {
375
375
  return await f();
376
376
  } catch (error) {
377
- if (error instanceof Error && error.name === "AbortError") {
377
+ if ((0, import_provider_utils2.isAbortError)(error)) {
378
378
  throw error;
379
379
  }
380
380
  if (maxRetries === 0) {
@@ -1393,25 +1393,27 @@ function runToolsTransformation({
1393
1393
  });
1394
1394
  return new ReadableStream({
1395
1395
  async start(controller) {
1396
- generatorStream.pipeThrough(forwardStream).pipeTo(
1397
- new WritableStream({
1398
- write(chunk) {
1399
- controller.enqueue(chunk);
1400
- },
1401
- close() {
1402
- }
1403
- })
1404
- );
1405
- toolResultsStream.pipeTo(
1406
- new WritableStream({
1407
- write(chunk) {
1408
- controller.enqueue(chunk);
1409
- },
1410
- close() {
1411
- controller.close();
1412
- }
1413
- })
1414
- );
1396
+ return Promise.all([
1397
+ generatorStream.pipeThrough(forwardStream).pipeTo(
1398
+ new WritableStream({
1399
+ write(chunk) {
1400
+ controller.enqueue(chunk);
1401
+ },
1402
+ close() {
1403
+ }
1404
+ })
1405
+ ),
1406
+ toolResultsStream.pipeTo(
1407
+ new WritableStream({
1408
+ write(chunk) {
1409
+ controller.enqueue(chunk);
1410
+ },
1411
+ close() {
1412
+ controller.close();
1413
+ }
1414
+ })
1415
+ )
1416
+ ]);
1415
1417
  }
1416
1418
  });
1417
1419
  }
@@ -1517,7 +1519,7 @@ var StreamTextResult = class {
1517
1519
  /**
1518
1520
  Writes stream data output to a Node.js response-like object.
1519
1521
  It sets a `Content-Type` header to `text/plain; charset=utf-8` and
1520
- writes each text delta as a separate chunk.
1522
+ writes each stream data part as a separate chunk.
1521
1523
 
1522
1524
  @param response A Node.js response-like object (ServerResponse).
1523
1525
  @param init Optional headers and status code.
@@ -1546,6 +1548,38 @@ var StreamTextResult = class {
1546
1548
  read();
1547
1549
  }
1548
1550
  /**
1551
+ Writes text delta output to a Node.js response-like object.
1552
+ It sets a `Content-Type` header to `text/plain; charset=utf-8` and
1553
+ writes each text delta as a separate chunk.
1554
+
1555
+ @param response A Node.js response-like object (ServerResponse).
1556
+ @param init Optional headers and status code.
1557
+ */
1558
+ pipeTextStreamToResponse(response, init) {
1559
+ var _a;
1560
+ response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
1561
+ "Content-Type": "text/plain; charset=utf-8",
1562
+ ...init == null ? void 0 : init.headers
1563
+ });
1564
+ const reader = this.textStream.getReader();
1565
+ const read = async () => {
1566
+ const encoder = new TextEncoder();
1567
+ try {
1568
+ while (true) {
1569
+ const { done, value } = await reader.read();
1570
+ if (done)
1571
+ break;
1572
+ response.write(encoder.encode(value));
1573
+ }
1574
+ } catch (error) {
1575
+ throw error;
1576
+ } finally {
1577
+ response.end();
1578
+ }
1579
+ };
1580
+ read();
1581
+ }
1582
+ /**
1549
1583
  Converts the result to a streamed response object with a stream data part stream.
1550
1584
  It can be used with the `useChat` and `useCompletion` hooks.
1551
1585
 
@@ -1953,7 +1987,7 @@ function readableFromAsyncIterable(iterable) {
1953
1987
  }
1954
1988
 
1955
1989
  // streams/stream-data.ts
1956
- var StreamData2 = class {
1990
+ var StreamData = class {
1957
1991
  constructor() {
1958
1992
  this.encoder = new TextEncoder();
1959
1993
  this.controller = null;
@@ -2049,7 +2083,7 @@ function createStreamDataTransformer() {
2049
2083
  }
2050
2084
  });
2051
2085
  }
2052
- var experimental_StreamData = class extends StreamData2 {
2086
+ var experimental_StreamData = class extends StreamData {
2053
2087
  };
2054
2088
 
2055
2089
  // streams/anthropic-stream.ts