ai 6.0.13 → 6.0.15

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
@@ -898,7 +898,7 @@ import {
898
898
  } from "@ai-sdk/provider-utils";
899
899
 
900
900
  // src/version.ts
901
- var VERSION = true ? "6.0.13" : "0.0.0-test";
901
+ var VERSION = true ? "6.0.15" : "0.0.0-test";
902
902
 
903
903
  // src/util/download/download.ts
904
904
  var download = async ({ url }) => {
@@ -3498,6 +3498,34 @@ async function toResponseMessages({
3498
3498
  return responseMessages;
3499
3499
  }
3500
3500
 
3501
+ // src/util/merge-abort-signals.ts
3502
+ function mergeAbortSignals(...signals) {
3503
+ const validSignals = signals.filter(
3504
+ (signal) => signal != null
3505
+ );
3506
+ if (validSignals.length === 0) {
3507
+ return void 0;
3508
+ }
3509
+ if (validSignals.length === 1) {
3510
+ return validSignals[0];
3511
+ }
3512
+ const controller = new AbortController();
3513
+ for (const signal of validSignals) {
3514
+ if (signal.aborted) {
3515
+ controller.abort(signal.reason);
3516
+ return controller.signal;
3517
+ }
3518
+ signal.addEventListener(
3519
+ "abort",
3520
+ () => {
3521
+ controller.abort(signal.reason);
3522
+ },
3523
+ { once: true }
3524
+ );
3525
+ }
3526
+ return controller.signal;
3527
+ }
3528
+
3501
3529
  // src/generate-text/generate-text.ts
3502
3530
  var originalGenerateId = createIdGenerator({
3503
3531
  prefix: "aitxt",
@@ -3512,6 +3540,7 @@ async function generateText({
3512
3540
  messages,
3513
3541
  maxRetries: maxRetriesArg,
3514
3542
  abortSignal,
3543
+ timeout,
3515
3544
  headers,
3516
3545
  stopWhen = stepCountIs(1),
3517
3546
  experimental_output,
@@ -3535,9 +3564,13 @@ async function generateText({
3535
3564
  }) {
3536
3565
  const model = resolveLanguageModel(modelArg);
3537
3566
  const stopConditions = asArray(stopWhen);
3567
+ const mergedAbortSignal = mergeAbortSignals(
3568
+ abortSignal,
3569
+ timeout != null ? AbortSignal.timeout(timeout) : void 0
3570
+ );
3538
3571
  const { maxRetries, retry } = prepareRetries({
3539
3572
  maxRetries: maxRetriesArg,
3540
- abortSignal
3573
+ abortSignal: mergedAbortSignal
3541
3574
  });
3542
3575
  const callSettings = prepareCallSettings(settings);
3543
3576
  const headersWithUserAgent = withUserAgentSuffix2(
@@ -3594,7 +3627,7 @@ async function generateText({
3594
3627
  tracer,
3595
3628
  telemetry,
3596
3629
  messages: initialMessages,
3597
- abortSignal,
3630
+ abortSignal: mergedAbortSignal,
3598
3631
  experimental_context
3599
3632
  });
3600
3633
  const toolContent = [];
@@ -3740,7 +3773,7 @@ async function generateText({
3740
3773
  responseFormat: await (output == null ? void 0 : output.responseFormat),
3741
3774
  prompt: promptMessages,
3742
3775
  providerOptions: stepProviderOptions,
3743
- abortSignal,
3776
+ abortSignal: mergedAbortSignal,
3744
3777
  headers: headersWithUserAgent
3745
3778
  });
3746
3779
  const responseData = {
@@ -3816,7 +3849,7 @@ async function generateText({
3816
3849
  input: toolCall.input,
3817
3850
  toolCallId: toolCall.toolCallId,
3818
3851
  messages: stepInputMessages,
3819
- abortSignal,
3852
+ abortSignal: mergedAbortSignal,
3820
3853
  experimental_context
3821
3854
  });
3822
3855
  }
@@ -3860,7 +3893,7 @@ async function generateText({
3860
3893
  tracer,
3861
3894
  telemetry,
3862
3895
  messages: stepInputMessages,
3863
- abortSignal,
3896
+ abortSignal: mergedAbortSignal,
3864
3897
  experimental_context
3865
3898
  })
3866
3899
  );
@@ -4542,7 +4575,8 @@ var uiMessageChunkSchema = lazySchema(
4542
4575
  messageMetadata: z7.unknown().optional()
4543
4576
  }),
4544
4577
  z7.strictObject({
4545
- type: z7.literal("abort")
4578
+ type: z7.literal("abort"),
4579
+ reason: z7.string().optional()
4546
4580
  }),
4547
4581
  z7.strictObject({
4548
4582
  type: z7.literal("message-metadata"),
@@ -5598,6 +5632,7 @@ function streamText({
5598
5632
  messages,
5599
5633
  maxRetries,
5600
5634
  abortSignal,
5635
+ timeout,
5601
5636
  headers,
5602
5637
  stopWhen = stepCountIs(1),
5603
5638
  experimental_output,
@@ -5632,7 +5667,10 @@ function streamText({
5632
5667
  headers,
5633
5668
  settings,
5634
5669
  maxRetries,
5635
- abortSignal,
5670
+ abortSignal: mergeAbortSignals(
5671
+ abortSignal,
5672
+ timeout != null ? AbortSignal.timeout(timeout) : void 0
5673
+ ),
5636
5674
  system,
5637
5675
  prompt,
5638
5676
  messages,
@@ -6002,7 +6040,13 @@ var DefaultStreamTextResult = class {
6002
6040
  async pull(controller) {
6003
6041
  function abort() {
6004
6042
  onAbort == null ? void 0 : onAbort({ steps: recordedSteps });
6005
- controller.enqueue({ type: "abort" });
6043
+ controller.enqueue({
6044
+ type: "abort",
6045
+ // The `reason` is usually of type DOMException, but it can also be of any type,
6046
+ // so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
6047
+ // See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
6048
+ ...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage7(abortSignal.reason) } : {}
6049
+ });
6006
6050
  controller.close();
6007
6051
  }
6008
6052
  try {
@@ -7128,11 +7172,13 @@ var ToolLoopAgent = class {
7128
7172
  */
7129
7173
  async generate({
7130
7174
  abortSignal,
7175
+ timeout,
7131
7176
  ...options
7132
7177
  }) {
7133
7178
  return generateText({
7134
7179
  ...await this.prepareCall(options),
7135
- abortSignal
7180
+ abortSignal,
7181
+ timeout
7136
7182
  });
7137
7183
  }
7138
7184
  /**
@@ -7140,12 +7186,14 @@ var ToolLoopAgent = class {
7140
7186
  */
7141
7187
  async stream({
7142
7188
  abortSignal,
7189
+ timeout,
7143
7190
  experimental_transform,
7144
7191
  ...options
7145
7192
  }) {
7146
7193
  return streamText({
7147
7194
  ...await this.prepareCall(options),
7148
7195
  abortSignal,
7196
+ timeout,
7149
7197
  experimental_transform
7150
7198
  });
7151
7199
  }
@@ -7908,6 +7956,7 @@ async function createAgentUIStream({
7908
7956
  uiMessages,
7909
7957
  options,
7910
7958
  abortSignal,
7959
+ timeout,
7911
7960
  experimental_transform,
7912
7961
  ...uiMessageStreamOptions
7913
7962
  }) {
@@ -7922,6 +7971,7 @@ async function createAgentUIStream({
7922
7971
  prompt: modelMessages,
7923
7972
  options,
7924
7973
  abortSignal,
7974
+ timeout,
7925
7975
  experimental_transform
7926
7976
  });
7927
7977
  return result.toUIMessageStream(uiMessageStreamOptions);