ai 4.1.31 → 4.1.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.mjs CHANGED
@@ -2732,6 +2732,7 @@ var DefaultGenerateObjectResult = class {
2732
2732
  this.finishReason = options.finishReason;
2733
2733
  this.usage = options.usage;
2734
2734
  this.warnings = options.warnings;
2735
+ this.providerMetadata = options.providerMetadata;
2735
2736
  this.experimental_providerMetadata = options.providerMetadata;
2736
2737
  this.response = options.response;
2737
2738
  this.request = options.request;
@@ -3345,6 +3346,7 @@ var DefaultStreamObjectResult = class {
3345
3346
  headers: rawResponse == null ? void 0 : rawResponse.headers
3346
3347
  },
3347
3348
  warnings,
3349
+ providerMetadata,
3348
3350
  experimental_providerMetadata: providerMetadata
3349
3351
  }));
3350
3352
  } catch (error2) {
@@ -3380,6 +3382,9 @@ var DefaultStreamObjectResult = class {
3380
3382
  get experimental_providerMetadata() {
3381
3383
  return this.providerMetadataPromise.value;
3382
3384
  }
3385
+ get providerMetadata() {
3386
+ return this.providerMetadataPromise.value;
3387
+ }
3383
3388
  get warnings() {
3384
3389
  return this.warningsPromise.value;
3385
3390
  }
@@ -4039,6 +4044,7 @@ async function generateText({
4039
4044
  // deep clone msgs to avoid mutating past messages in multi-step:
4040
4045
  messages: structuredClone(responseMessages)
4041
4046
  },
4047
+ providerMetadata: currentModelResponse.providerMetadata,
4042
4048
  experimental_providerMetadata: currentModelResponse.providerMetadata,
4043
4049
  isContinued: nextStepType === "continue"
4044
4050
  };
@@ -4181,6 +4187,7 @@ var DefaultGenerateTextResult = class {
4181
4187
  this.response = options.response;
4182
4188
  this.steps = options.steps;
4183
4189
  this.experimental_providerMetadata = options.providerMetadata;
4190
+ this.providerMetadata = options.providerMetadata;
4184
4191
  this.logprobs = options.logprobs;
4185
4192
  this.outputResolver = options.outputResolver;
4186
4193
  this.sources = options.sources;
@@ -4714,13 +4721,23 @@ function createOutputTransformStream(output) {
4714
4721
  let text2 = "";
4715
4722
  let textChunk = "";
4716
4723
  let lastPublishedJson = "";
4724
+ function publishTextChunk({
4725
+ controller,
4726
+ partialOutput = void 0
4727
+ }) {
4728
+ controller.enqueue({
4729
+ part: { type: "text-delta", textDelta: textChunk },
4730
+ partialOutput
4731
+ });
4732
+ textChunk = "";
4733
+ }
4717
4734
  return new TransformStream({
4718
4735
  transform(chunk, controller) {
4736
+ if (chunk.type === "step-finish") {
4737
+ publishTextChunk({ controller });
4738
+ }
4719
4739
  if (chunk.type !== "text-delta") {
4720
- controller.enqueue({
4721
- part: chunk,
4722
- partialOutput: void 0
4723
- });
4740
+ controller.enqueue({ part: chunk, partialOutput: void 0 });
4724
4741
  return;
4725
4742
  }
4726
4743
  text2 += chunk.textDelta;
@@ -4729,27 +4746,14 @@ function createOutputTransformStream(output) {
4729
4746
  if (result != null) {
4730
4747
  const currentJson = JSON.stringify(result.partial);
4731
4748
  if (currentJson !== lastPublishedJson) {
4732
- controller.enqueue({
4733
- part: {
4734
- type: "text-delta",
4735
- textDelta: textChunk
4736
- },
4737
- partialOutput: result.partial
4738
- });
4749
+ publishTextChunk({ controller, partialOutput: result.partial });
4739
4750
  lastPublishedJson = currentJson;
4740
- textChunk = "";
4741
4751
  }
4742
4752
  }
4743
4753
  },
4744
4754
  flush(controller) {
4745
4755
  if (textChunk.length > 0) {
4746
- controller.enqueue({
4747
- part: {
4748
- type: "text-delta",
4749
- textDelta: textChunk
4750
- },
4751
- partialOutput: void 0
4752
- });
4756
+ publishTextChunk({ controller });
4753
4757
  }
4754
4758
  }
4755
4759
  });
@@ -4891,6 +4895,7 @@ var DefaultStreamTextResult = class {
4891
4895
  ...part.response,
4892
4896
  messages: [...recordedResponse.messages, ...stepMessages]
4893
4897
  },
4898
+ providerMetadata: part.experimental_providerMetadata,
4894
4899
  experimental_providerMetadata: part.experimental_providerMetadata,
4895
4900
  isContinued: part.isContinued
4896
4901
  };
@@ -4956,6 +4961,7 @@ var DefaultStreamTextResult = class {
4956
4961
  request: (_a16 = lastStep.request) != null ? _a16 : {},
4957
4962
  response: lastStep.response,
4958
4963
  warnings: lastStep.warnings,
4964
+ providerMetadata: lastStep.providerMetadata,
4959
4965
  experimental_providerMetadata: lastStep.experimental_providerMetadata,
4960
4966
  steps: recordedSteps
4961
4967
  }));
@@ -5336,6 +5342,7 @@ var DefaultStreamTextResult = class {
5336
5342
  type: "step-finish",
5337
5343
  finishReason: stepFinishReason,
5338
5344
  usage: stepUsage,
5345
+ providerMetadata: stepProviderMetadata,
5339
5346
  experimental_providerMetadata: stepProviderMetadata,
5340
5347
  logprobs: stepLogProbs,
5341
5348
  request: stepRequest,
@@ -5353,6 +5360,7 @@ var DefaultStreamTextResult = class {
5353
5360
  type: "finish",
5354
5361
  finishReason: stepFinishReason,
5355
5362
  usage: combinedUsage,
5363
+ providerMetadata: stepProviderMetadata,
5356
5364
  experimental_providerMetadata: stepProviderMetadata,
5357
5365
  logprobs: stepLogProbs,
5358
5366
  response: {
@@ -5440,6 +5448,9 @@ var DefaultStreamTextResult = class {
5440
5448
  get experimental_providerMetadata() {
5441
5449
  return this.providerMetadataPromise.value;
5442
5450
  }
5451
+ get providerMetadata() {
5452
+ return this.providerMetadataPromise.value;
5453
+ }
5443
5454
  get text() {
5444
5455
  return this.textPromise.value;
5445
5456
  }
@@ -5528,118 +5539,110 @@ var DefaultStreamTextResult = class {
5528
5539
  sendUsage = true,
5529
5540
  sendReasoning = false
5530
5541
  }) {
5531
- let aggregatedResponse = "";
5532
- const callbackTransformer = new TransformStream({
5533
- async transform(chunk, controller) {
5534
- controller.enqueue(chunk);
5535
- if (chunk.type === "text-delta") {
5536
- aggregatedResponse += chunk.textDelta;
5537
- }
5538
- }
5539
- });
5540
- const streamPartsTransformer = new TransformStream({
5541
- transform: async (chunk, controller) => {
5542
- const chunkType = chunk.type;
5543
- switch (chunkType) {
5544
- case "text-delta": {
5545
- controller.enqueue(formatDataStreamPart2("text", chunk.textDelta));
5546
- break;
5547
- }
5548
- case "reasoning": {
5549
- if (sendReasoning) {
5542
+ return this.fullStream.pipeThrough(
5543
+ new TransformStream({
5544
+ transform: async (chunk, controller) => {
5545
+ const chunkType = chunk.type;
5546
+ switch (chunkType) {
5547
+ case "text-delta": {
5548
+ controller.enqueue(formatDataStreamPart2("text", chunk.textDelta));
5549
+ break;
5550
+ }
5551
+ case "reasoning": {
5552
+ if (sendReasoning) {
5553
+ controller.enqueue(
5554
+ formatDataStreamPart2("reasoning", chunk.textDelta)
5555
+ );
5556
+ }
5557
+ break;
5558
+ }
5559
+ case "source": {
5560
+ break;
5561
+ }
5562
+ case "tool-call-streaming-start": {
5550
5563
  controller.enqueue(
5551
- formatDataStreamPart2("reasoning", chunk.textDelta)
5564
+ formatDataStreamPart2("tool_call_streaming_start", {
5565
+ toolCallId: chunk.toolCallId,
5566
+ toolName: chunk.toolName
5567
+ })
5552
5568
  );
5569
+ break;
5570
+ }
5571
+ case "tool-call-delta": {
5572
+ controller.enqueue(
5573
+ formatDataStreamPart2("tool_call_delta", {
5574
+ toolCallId: chunk.toolCallId,
5575
+ argsTextDelta: chunk.argsTextDelta
5576
+ })
5577
+ );
5578
+ break;
5579
+ }
5580
+ case "tool-call": {
5581
+ controller.enqueue(
5582
+ formatDataStreamPart2("tool_call", {
5583
+ toolCallId: chunk.toolCallId,
5584
+ toolName: chunk.toolName,
5585
+ args: chunk.args
5586
+ })
5587
+ );
5588
+ break;
5589
+ }
5590
+ case "tool-result": {
5591
+ controller.enqueue(
5592
+ formatDataStreamPart2("tool_result", {
5593
+ toolCallId: chunk.toolCallId,
5594
+ result: chunk.result
5595
+ })
5596
+ );
5597
+ break;
5598
+ }
5599
+ case "error": {
5600
+ controller.enqueue(
5601
+ formatDataStreamPart2("error", getErrorMessage5(chunk.error))
5602
+ );
5603
+ break;
5604
+ }
5605
+ case "step-start": {
5606
+ controller.enqueue(
5607
+ formatDataStreamPart2("start_step", {
5608
+ messageId: chunk.messageId
5609
+ })
5610
+ );
5611
+ break;
5612
+ }
5613
+ case "step-finish": {
5614
+ controller.enqueue(
5615
+ formatDataStreamPart2("finish_step", {
5616
+ finishReason: chunk.finishReason,
5617
+ usage: sendUsage ? {
5618
+ promptTokens: chunk.usage.promptTokens,
5619
+ completionTokens: chunk.usage.completionTokens
5620
+ } : void 0,
5621
+ isContinued: chunk.isContinued
5622
+ })
5623
+ );
5624
+ break;
5625
+ }
5626
+ case "finish": {
5627
+ controller.enqueue(
5628
+ formatDataStreamPart2("finish_message", {
5629
+ finishReason: chunk.finishReason,
5630
+ usage: sendUsage ? {
5631
+ promptTokens: chunk.usage.promptTokens,
5632
+ completionTokens: chunk.usage.completionTokens
5633
+ } : void 0
5634
+ })
5635
+ );
5636
+ break;
5637
+ }
5638
+ default: {
5639
+ const exhaustiveCheck = chunkType;
5640
+ throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
5553
5641
  }
5554
- break;
5555
- }
5556
- case "source": {
5557
- break;
5558
- }
5559
- case "tool-call-streaming-start": {
5560
- controller.enqueue(
5561
- formatDataStreamPart2("tool_call_streaming_start", {
5562
- toolCallId: chunk.toolCallId,
5563
- toolName: chunk.toolName
5564
- })
5565
- );
5566
- break;
5567
- }
5568
- case "tool-call-delta": {
5569
- controller.enqueue(
5570
- formatDataStreamPart2("tool_call_delta", {
5571
- toolCallId: chunk.toolCallId,
5572
- argsTextDelta: chunk.argsTextDelta
5573
- })
5574
- );
5575
- break;
5576
- }
5577
- case "tool-call": {
5578
- controller.enqueue(
5579
- formatDataStreamPart2("tool_call", {
5580
- toolCallId: chunk.toolCallId,
5581
- toolName: chunk.toolName,
5582
- args: chunk.args
5583
- })
5584
- );
5585
- break;
5586
- }
5587
- case "tool-result": {
5588
- controller.enqueue(
5589
- formatDataStreamPart2("tool_result", {
5590
- toolCallId: chunk.toolCallId,
5591
- result: chunk.result
5592
- })
5593
- );
5594
- break;
5595
- }
5596
- case "error": {
5597
- controller.enqueue(
5598
- formatDataStreamPart2("error", getErrorMessage5(chunk.error))
5599
- );
5600
- break;
5601
- }
5602
- case "step-start": {
5603
- controller.enqueue(
5604
- formatDataStreamPart2("start_step", {
5605
- messageId: chunk.messageId
5606
- })
5607
- );
5608
- break;
5609
- }
5610
- case "step-finish": {
5611
- controller.enqueue(
5612
- formatDataStreamPart2("finish_step", {
5613
- finishReason: chunk.finishReason,
5614
- usage: sendUsage ? {
5615
- promptTokens: chunk.usage.promptTokens,
5616
- completionTokens: chunk.usage.completionTokens
5617
- } : void 0,
5618
- isContinued: chunk.isContinued
5619
- })
5620
- );
5621
- break;
5622
- }
5623
- case "finish": {
5624
- controller.enqueue(
5625
- formatDataStreamPart2("finish_message", {
5626
- finishReason: chunk.finishReason,
5627
- usage: sendUsage ? {
5628
- promptTokens: chunk.usage.promptTokens,
5629
- completionTokens: chunk.usage.completionTokens
5630
- } : void 0
5631
- })
5632
- );
5633
- break;
5634
- }
5635
- default: {
5636
- const exhaustiveCheck = chunkType;
5637
- throw new Error(`Unknown chunk type: ${exhaustiveCheck}`);
5638
5642
  }
5639
5643
  }
5640
- }
5641
- });
5642
- return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamPartsTransformer);
5644
+ })
5645
+ );
5643
5646
  }
5644
5647
  pipeDataStreamToResponse(response, {
5645
5648
  status,