ai 6.0.12 → 6.0.14

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.12" : "0.0.0-test";
901
+ var VERSION = true ? "6.0.14" : "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
  );
@@ -5598,6 +5631,7 @@ function streamText({
5598
5631
  messages,
5599
5632
  maxRetries,
5600
5633
  abortSignal,
5634
+ timeout,
5601
5635
  headers,
5602
5636
  stopWhen = stepCountIs(1),
5603
5637
  experimental_output,
@@ -5632,7 +5666,10 @@ function streamText({
5632
5666
  headers,
5633
5667
  settings,
5634
5668
  maxRetries,
5635
- abortSignal,
5669
+ abortSignal: mergeAbortSignals(
5670
+ abortSignal,
5671
+ timeout != null ? AbortSignal.timeout(timeout) : void 0
5672
+ ),
5636
5673
  system,
5637
5674
  prompt,
5638
5675
  messages,
@@ -7128,11 +7165,13 @@ var ToolLoopAgent = class {
7128
7165
  */
7129
7166
  async generate({
7130
7167
  abortSignal,
7168
+ timeout,
7131
7169
  ...options
7132
7170
  }) {
7133
7171
  return generateText({
7134
7172
  ...await this.prepareCall(options),
7135
- abortSignal
7173
+ abortSignal,
7174
+ timeout
7136
7175
  });
7137
7176
  }
7138
7177
  /**
@@ -7140,12 +7179,14 @@ var ToolLoopAgent = class {
7140
7179
  */
7141
7180
  async stream({
7142
7181
  abortSignal,
7182
+ timeout,
7143
7183
  experimental_transform,
7144
7184
  ...options
7145
7185
  }) {
7146
7186
  return streamText({
7147
7187
  ...await this.prepareCall(options),
7148
7188
  abortSignal,
7189
+ timeout,
7149
7190
  experimental_transform
7150
7191
  });
7151
7192
  }
@@ -7908,6 +7949,7 @@ async function createAgentUIStream({
7908
7949
  uiMessages,
7909
7950
  options,
7910
7951
  abortSignal,
7952
+ timeout,
7911
7953
  experimental_transform,
7912
7954
  ...uiMessageStreamOptions
7913
7955
  }) {
@@ -7922,6 +7964,7 @@ async function createAgentUIStream({
7922
7964
  prompt: modelMessages,
7923
7965
  options,
7924
7966
  abortSignal,
7967
+ timeout,
7925
7968
  experimental_transform
7926
7969
  });
7927
7970
  return result.toUIMessageStream(uiMessageStreamOptions);
@@ -10152,25 +10195,29 @@ function smoothStream({
10152
10195
  return () => {
10153
10196
  let buffer = "";
10154
10197
  let id = "";
10198
+ let type = void 0;
10199
+ function flushBuffer(controller) {
10200
+ if (buffer.length > 0 && type !== void 0) {
10201
+ controller.enqueue({ type, text: buffer, id });
10202
+ buffer = "";
10203
+ }
10204
+ }
10155
10205
  return new TransformStream({
10156
10206
  async transform(chunk, controller) {
10157
- if (chunk.type !== "text-delta") {
10158
- if (buffer.length > 0) {
10159
- controller.enqueue({ type: "text-delta", text: buffer, id });
10160
- buffer = "";
10161
- }
10207
+ if (chunk.type !== "text-delta" && chunk.type !== "reasoning-delta") {
10208
+ flushBuffer(controller);
10162
10209
  controller.enqueue(chunk);
10163
10210
  return;
10164
10211
  }
10165
- if (chunk.id !== id && buffer.length > 0) {
10166
- controller.enqueue({ type: "text-delta", text: buffer, id });
10167
- buffer = "";
10212
+ if ((chunk.type !== type || chunk.id !== id) && buffer.length > 0) {
10213
+ flushBuffer(controller);
10168
10214
  }
10169
10215
  buffer += chunk.text;
10170
10216
  id = chunk.id;
10217
+ type = chunk.type;
10171
10218
  let match;
10172
10219
  while ((match = detectChunk(buffer)) != null) {
10173
- controller.enqueue({ type: "text-delta", text: match, id });
10220
+ controller.enqueue({ type, text: match, id });
10174
10221
  buffer = buffer.slice(match.length);
10175
10222
  await delay2(delayInMs);
10176
10223
  }