ai 3.1.2 → 3.1.3

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
@@ -788,6 +788,14 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
788
788
  */
789
789
  readonly warnings: CallWarning[] | undefined;
790
790
  /**
791
+ The token usage of the generated text. Resolved when the response is finished.
792
+ */
793
+ readonly usage: Promise<TokenUsage>;
794
+ /**
795
+ The reason why the generation finished. Resolved when the response is finished.
796
+ */
797
+ readonly finishReason: Promise<FinishReason>;
798
+ /**
791
799
  Optional raw response data.
792
800
  */
793
801
  rawResponse?: {
package/dist/index.d.ts CHANGED
@@ -788,6 +788,14 @@ declare class StreamTextResult<TOOLS extends Record<string, CoreTool>> {
788
788
  */
789
789
  readonly warnings: CallWarning[] | undefined;
790
790
  /**
791
+ The token usage of the generated text. Resolved when the response is finished.
792
+ */
793
+ readonly usage: Promise<TokenUsage>;
794
+ /**
795
+ The reason why the generation finished. Resolved when the response is finished.
796
+ */
797
+ readonly finishReason: Promise<FinishReason>;
798
+ /**
791
799
  Optional raw response data.
792
800
  */
793
801
  rawResponse?: {
package/dist/index.js CHANGED
@@ -755,6 +755,7 @@ function fixJson(input) {
755
755
  break;
756
756
  }
757
757
  case "}": {
758
+ lastValidIndex = i;
758
759
  stack.pop();
759
760
  break;
760
761
  }
@@ -1486,9 +1487,27 @@ var StreamTextResult = class {
1486
1487
  warnings,
1487
1488
  rawResponse
1488
1489
  }) {
1489
- this.originalStream = stream;
1490
1490
  this.warnings = warnings;
1491
1491
  this.rawResponse = rawResponse;
1492
+ let resolveUsage;
1493
+ this.usage = new Promise((resolve) => {
1494
+ resolveUsage = resolve;
1495
+ });
1496
+ let resolveFinishReason;
1497
+ this.finishReason = new Promise((resolve) => {
1498
+ resolveFinishReason = resolve;
1499
+ });
1500
+ this.originalStream = stream.pipeThrough(
1501
+ new TransformStream({
1502
+ async transform(chunk, controller) {
1503
+ controller.enqueue(chunk);
1504
+ if (chunk.type === "finish") {
1505
+ resolveUsage(chunk.usage);
1506
+ resolveFinishReason(chunk.finishReason);
1507
+ }
1508
+ }
1509
+ })
1510
+ );
1492
1511
  }
1493
1512
  /**
1494
1513
  Split out a new stream from the original stream.