ai 7.0.0-beta.20 → 7.0.0-beta.21

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.0-beta.21
4
+
5
+ ### Patch Changes
6
+
7
+ - 34fd051: feat(ai): add toolMs to timeout configuration
8
+
3
9
  ## 7.0.0-beta.20
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -635,6 +635,7 @@ type TimeoutConfiguration = number | {
635
635
  totalMs?: number;
636
636
  stepMs?: number;
637
637
  chunkMs?: number;
638
+ toolMs?: number;
638
639
  };
639
640
  type CallSettings = {
640
641
  /**
package/dist/index.d.ts CHANGED
@@ -635,6 +635,7 @@ type TimeoutConfiguration = number | {
635
635
  totalMs?: number;
636
636
  stepMs?: number;
637
637
  chunkMs?: number;
638
+ toolMs?: number;
638
639
  };
639
640
  type CallSettings = {
640
641
  /**
package/dist/index.js CHANGED
@@ -1135,6 +1135,12 @@ function getChunkTimeoutMs(timeout) {
1135
1135
  }
1136
1136
  return timeout.chunkMs;
1137
1137
  }
1138
+ function getToolTimeoutMs(timeout) {
1139
+ if (timeout == null || typeof timeout === "number") {
1140
+ return void 0;
1141
+ }
1142
+ return timeout.toolMs;
1143
+ }
1138
1144
 
1139
1145
  // src/prompt/convert-to-language-model-prompt.ts
1140
1146
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
@@ -1371,7 +1377,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
1371
1377
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1372
1378
 
1373
1379
  // src/version.ts
1374
- var VERSION = true ? "7.0.0-beta.20" : "0.0.0-test";
1380
+ var VERSION = true ? "7.0.0-beta.21" : "0.0.0-test";
1375
1381
 
1376
1382
  // src/util/download/download.ts
1377
1383
  var download = async ({
@@ -3236,6 +3242,7 @@ async function executeToolCall({
3236
3242
  callId,
3237
3243
  messages,
3238
3244
  abortSignal,
3245
+ toolTimeoutMs,
3239
3246
  experimental_context,
3240
3247
  stepNumber,
3241
3248
  model,
@@ -3262,6 +3269,7 @@ async function executeToolCall({
3262
3269
  };
3263
3270
  let output;
3264
3271
  await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
3272
+ const toolAbortSignal = toolTimeoutMs != null ? abortSignal != null ? AbortSignal.any([abortSignal, AbortSignal.timeout(toolTimeoutMs)]) : AbortSignal.timeout(toolTimeoutMs) : abortSignal;
3265
3273
  const startTime = now();
3266
3274
  try {
3267
3275
  await executeToolInTelemetryContext({
@@ -3274,7 +3282,7 @@ async function executeToolCall({
3274
3282
  options: {
3275
3283
  toolCallId,
3276
3284
  messages,
3277
- abortSignal,
3285
+ abortSignal: toolAbortSignal,
3278
3286
  experimental_context
3279
3287
  }
3280
3288
  });
@@ -4534,6 +4542,7 @@ async function generateText({
4534
4542
  const stopConditions = asArray(stopWhen);
4535
4543
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
4536
4544
  const stepTimeoutMs = getStepTimeoutMs(timeout);
4545
+ const toolTimeoutMs = getToolTimeoutMs(timeout);
4537
4546
  const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
4538
4547
  const mergedAbortSignal = mergeAbortSignals(
4539
4548
  abortSignal,
@@ -4615,6 +4624,7 @@ async function generateText({
4615
4624
  callId,
4616
4625
  messages: initialMessages,
4617
4626
  abortSignal: mergedAbortSignal,
4627
+ toolTimeoutMs,
4618
4628
  experimental_context,
4619
4629
  stepNumber: 0,
4620
4630
  model: modelInfo,
@@ -4861,6 +4871,7 @@ async function generateText({
4861
4871
  callId,
4862
4872
  messages: stepInputMessages,
4863
4873
  abortSignal: mergedAbortSignal,
4874
+ toolTimeoutMs,
4864
4875
  experimental_context,
4865
4876
  stepNumber: steps.length,
4866
4877
  model: stepModelInfo,
@@ -5043,6 +5054,7 @@ async function executeTools({
5043
5054
  callId,
5044
5055
  messages,
5045
5056
  abortSignal,
5057
+ toolTimeoutMs,
5046
5058
  experimental_context,
5047
5059
  stepNumber,
5048
5060
  model,
@@ -5059,6 +5071,7 @@ async function executeTools({
5059
5071
  callId,
5060
5072
  messages,
5061
5073
  abortSignal,
5074
+ toolTimeoutMs,
5062
5075
  experimental_context,
5063
5076
  stepNumber,
5064
5077
  model,
@@ -6473,6 +6486,24 @@ function createStitchableStream() {
6473
6486
  };
6474
6487
  }
6475
6488
 
6489
+ // src/generate-text/create-stream-text-part-transform.ts
6490
+ function createStreamTextPartTransform() {
6491
+ return new TransformStream({
6492
+ async transform(chunk, controller) {
6493
+ if (chunk.type === "text-delta") {
6494
+ controller.enqueue({
6495
+ type: "text-delta",
6496
+ id: chunk.id,
6497
+ text: chunk.delta,
6498
+ providerMetadata: chunk.providerMetadata
6499
+ });
6500
+ } else {
6501
+ controller.enqueue(chunk);
6502
+ }
6503
+ }
6504
+ });
6505
+ }
6506
+
6476
6507
  // src/generate-text/run-tools-transformation.ts
6477
6508
  var import_provider_utils18 = require("@ai-sdk/provider-utils");
6478
6509
  function runToolsTransformation({
@@ -6484,6 +6515,7 @@ function runToolsTransformation({
6484
6515
  messages,
6485
6516
  abortSignal,
6486
6517
  repairToolCall,
6518
+ toolTimeoutMs,
6487
6519
  experimental_context,
6488
6520
  generateId: generateId2,
6489
6521
  stepNumber,
@@ -6517,6 +6549,7 @@ function runToolsTransformation({
6517
6549
  switch (chunkType) {
6518
6550
  case "stream-start":
6519
6551
  case "text-start":
6552
+ case "text-delta":
6520
6553
  case "text-end":
6521
6554
  case "reasoning-start":
6522
6555
  case "reasoning-end":
@@ -6530,14 +6563,6 @@ function runToolsTransformation({
6530
6563
  controller.enqueue(chunk);
6531
6564
  break;
6532
6565
  }
6533
- case "text-delta":
6534
- controller.enqueue({
6535
- type: "text-delta",
6536
- id: chunk.id,
6537
- text: chunk.delta,
6538
- providerMetadata: chunk.providerMetadata
6539
- });
6540
- break;
6541
6566
  case "reasoning-delta":
6542
6567
  controller.enqueue({
6543
6568
  type: "reasoning-delta",
@@ -6647,6 +6672,7 @@ function runToolsTransformation({
6647
6672
  callId,
6648
6673
  messages,
6649
6674
  abortSignal,
6675
+ toolTimeoutMs,
6650
6676
  experimental_context,
6651
6677
  stepNumber,
6652
6678
  model,
@@ -6793,6 +6819,7 @@ function streamText({
6793
6819
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
6794
6820
  const stepTimeoutMs = getStepTimeoutMs(timeout);
6795
6821
  const chunkTimeoutMs = getChunkTimeoutMs(timeout);
6822
+ const toolTimeoutMs = getToolTimeoutMs(timeout);
6796
6823
  const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
6797
6824
  const chunkAbortController = chunkTimeoutMs != null ? new AbortController() : void 0;
6798
6825
  return new DefaultStreamTextResult({
@@ -6811,6 +6838,7 @@ function streamText({
6811
6838
  stepAbortController,
6812
6839
  chunkTimeoutMs,
6813
6840
  chunkAbortController,
6841
+ toolTimeoutMs,
6814
6842
  system,
6815
6843
  prompt,
6816
6844
  messages,
@@ -6918,6 +6946,7 @@ var DefaultStreamTextResult = class {
6918
6946
  stepAbortController,
6919
6947
  chunkTimeoutMs,
6920
6948
  chunkAbortController,
6949
+ toolTimeoutMs,
6921
6950
  system,
6922
6951
  prompt,
6923
6952
  messages,
@@ -7349,6 +7378,7 @@ var DefaultStreamTextResult = class {
7349
7378
  callId,
7350
7379
  messages: initialMessages,
7351
7380
  abortSignal,
7381
+ toolTimeoutMs,
7352
7382
  experimental_context,
7353
7383
  stepNumber: recordedSteps.length,
7354
7384
  model: modelInfo,
@@ -7521,7 +7551,11 @@ var DefaultStreamTextResult = class {
7521
7551
  ]
7522
7552
  });
7523
7553
  const stepStartTimestampMs = now2();
7524
- const { stream: stream2, response, request } = await retry(
7554
+ const {
7555
+ stream: languageModelStream,
7556
+ response,
7557
+ request
7558
+ } = await retry(
7525
7559
  async () => stepModel.doStream({
7526
7560
  ...callSettings,
7527
7561
  tools: stepTools,
@@ -7534,6 +7568,9 @@ var DefaultStreamTextResult = class {
7534
7568
  includeRawChunks: includeRawChunks2
7535
7569
  })
7536
7570
  );
7571
+ const stream2 = languageModelStream.pipeThrough(
7572
+ createStreamTextPartTransform()
7573
+ );
7537
7574
  const streamWithToolResults = runToolsTransformation({
7538
7575
  tools,
7539
7576
  generatorStream: stream2,
@@ -7543,6 +7580,7 @@ var DefaultStreamTextResult = class {
7543
7580
  messages: stepInputMessages,
7544
7581
  repairToolCall,
7545
7582
  abortSignal,
7583
+ toolTimeoutMs,
7546
7584
  experimental_context,
7547
7585
  generateId: generateId2,
7548
7586
  stepNumber: recordedSteps.length,