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/dist/index.mjs CHANGED
@@ -1016,6 +1016,12 @@ function getChunkTimeoutMs(timeout) {
1016
1016
  }
1017
1017
  return timeout.chunkMs;
1018
1018
  }
1019
+ function getToolTimeoutMs(timeout) {
1020
+ if (timeout == null || typeof timeout === "number") {
1021
+ return void 0;
1022
+ }
1023
+ return timeout.toolMs;
1024
+ }
1019
1025
 
1020
1026
  // src/prompt/convert-to-language-model-prompt.ts
1021
1027
  import {
@@ -1262,7 +1268,7 @@ import {
1262
1268
  } from "@ai-sdk/provider-utils";
1263
1269
 
1264
1270
  // src/version.ts
1265
- var VERSION = true ? "7.0.0-beta.20" : "0.0.0-test";
1271
+ var VERSION = true ? "7.0.0-beta.21" : "0.0.0-test";
1266
1272
 
1267
1273
  // src/util/download/download.ts
1268
1274
  var download = async ({
@@ -3136,6 +3142,7 @@ async function executeToolCall({
3136
3142
  callId,
3137
3143
  messages,
3138
3144
  abortSignal,
3145
+ toolTimeoutMs,
3139
3146
  experimental_context,
3140
3147
  stepNumber,
3141
3148
  model,
@@ -3162,6 +3169,7 @@ async function executeToolCall({
3162
3169
  };
3163
3170
  let output;
3164
3171
  await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
3172
+ const toolAbortSignal = toolTimeoutMs != null ? abortSignal != null ? AbortSignal.any([abortSignal, AbortSignal.timeout(toolTimeoutMs)]) : AbortSignal.timeout(toolTimeoutMs) : abortSignal;
3165
3173
  const startTime = now();
3166
3174
  try {
3167
3175
  await executeToolInTelemetryContext({
@@ -3174,7 +3182,7 @@ async function executeToolCall({
3174
3182
  options: {
3175
3183
  toolCallId,
3176
3184
  messages,
3177
- abortSignal,
3185
+ abortSignal: toolAbortSignal,
3178
3186
  experimental_context
3179
3187
  }
3180
3188
  });
@@ -4448,6 +4456,7 @@ async function generateText({
4448
4456
  const stopConditions = asArray(stopWhen);
4449
4457
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
4450
4458
  const stepTimeoutMs = getStepTimeoutMs(timeout);
4459
+ const toolTimeoutMs = getToolTimeoutMs(timeout);
4451
4460
  const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
4452
4461
  const mergedAbortSignal = mergeAbortSignals(
4453
4462
  abortSignal,
@@ -4529,6 +4538,7 @@ async function generateText({
4529
4538
  callId,
4530
4539
  messages: initialMessages,
4531
4540
  abortSignal: mergedAbortSignal,
4541
+ toolTimeoutMs,
4532
4542
  experimental_context,
4533
4543
  stepNumber: 0,
4534
4544
  model: modelInfo,
@@ -4775,6 +4785,7 @@ async function generateText({
4775
4785
  callId,
4776
4786
  messages: stepInputMessages,
4777
4787
  abortSignal: mergedAbortSignal,
4788
+ toolTimeoutMs,
4778
4789
  experimental_context,
4779
4790
  stepNumber: steps.length,
4780
4791
  model: stepModelInfo,
@@ -4957,6 +4968,7 @@ async function executeTools({
4957
4968
  callId,
4958
4969
  messages,
4959
4970
  abortSignal,
4971
+ toolTimeoutMs,
4960
4972
  experimental_context,
4961
4973
  stepNumber,
4962
4974
  model,
@@ -4973,6 +4985,7 @@ async function executeTools({
4973
4985
  callId,
4974
4986
  messages,
4975
4987
  abortSignal,
4988
+ toolTimeoutMs,
4976
4989
  experimental_context,
4977
4990
  stepNumber,
4978
4991
  model,
@@ -6394,6 +6407,24 @@ function createStitchableStream() {
6394
6407
  };
6395
6408
  }
6396
6409
 
6410
+ // src/generate-text/create-stream-text-part-transform.ts
6411
+ function createStreamTextPartTransform() {
6412
+ return new TransformStream({
6413
+ async transform(chunk, controller) {
6414
+ if (chunk.type === "text-delta") {
6415
+ controller.enqueue({
6416
+ type: "text-delta",
6417
+ id: chunk.id,
6418
+ text: chunk.delta,
6419
+ providerMetadata: chunk.providerMetadata
6420
+ });
6421
+ } else {
6422
+ controller.enqueue(chunk);
6423
+ }
6424
+ }
6425
+ });
6426
+ }
6427
+
6397
6428
  // src/generate-text/run-tools-transformation.ts
6398
6429
  import {
6399
6430
  getErrorMessage as getErrorMessage6
@@ -6407,6 +6438,7 @@ function runToolsTransformation({
6407
6438
  messages,
6408
6439
  abortSignal,
6409
6440
  repairToolCall,
6441
+ toolTimeoutMs,
6410
6442
  experimental_context,
6411
6443
  generateId: generateId2,
6412
6444
  stepNumber,
@@ -6440,6 +6472,7 @@ function runToolsTransformation({
6440
6472
  switch (chunkType) {
6441
6473
  case "stream-start":
6442
6474
  case "text-start":
6475
+ case "text-delta":
6443
6476
  case "text-end":
6444
6477
  case "reasoning-start":
6445
6478
  case "reasoning-end":
@@ -6453,14 +6486,6 @@ function runToolsTransformation({
6453
6486
  controller.enqueue(chunk);
6454
6487
  break;
6455
6488
  }
6456
- case "text-delta":
6457
- controller.enqueue({
6458
- type: "text-delta",
6459
- id: chunk.id,
6460
- text: chunk.delta,
6461
- providerMetadata: chunk.providerMetadata
6462
- });
6463
- break;
6464
6489
  case "reasoning-delta":
6465
6490
  controller.enqueue({
6466
6491
  type: "reasoning-delta",
@@ -6570,6 +6595,7 @@ function runToolsTransformation({
6570
6595
  callId,
6571
6596
  messages,
6572
6597
  abortSignal,
6598
+ toolTimeoutMs,
6573
6599
  experimental_context,
6574
6600
  stepNumber,
6575
6601
  model,
@@ -6716,6 +6742,7 @@ function streamText({
6716
6742
  const totalTimeoutMs = getTotalTimeoutMs(timeout);
6717
6743
  const stepTimeoutMs = getStepTimeoutMs(timeout);
6718
6744
  const chunkTimeoutMs = getChunkTimeoutMs(timeout);
6745
+ const toolTimeoutMs = getToolTimeoutMs(timeout);
6719
6746
  const stepAbortController = stepTimeoutMs != null ? new AbortController() : void 0;
6720
6747
  const chunkAbortController = chunkTimeoutMs != null ? new AbortController() : void 0;
6721
6748
  return new DefaultStreamTextResult({
@@ -6734,6 +6761,7 @@ function streamText({
6734
6761
  stepAbortController,
6735
6762
  chunkTimeoutMs,
6736
6763
  chunkAbortController,
6764
+ toolTimeoutMs,
6737
6765
  system,
6738
6766
  prompt,
6739
6767
  messages,
@@ -6841,6 +6869,7 @@ var DefaultStreamTextResult = class {
6841
6869
  stepAbortController,
6842
6870
  chunkTimeoutMs,
6843
6871
  chunkAbortController,
6872
+ toolTimeoutMs,
6844
6873
  system,
6845
6874
  prompt,
6846
6875
  messages,
@@ -7272,6 +7301,7 @@ var DefaultStreamTextResult = class {
7272
7301
  callId,
7273
7302
  messages: initialMessages,
7274
7303
  abortSignal,
7304
+ toolTimeoutMs,
7275
7305
  experimental_context,
7276
7306
  stepNumber: recordedSteps.length,
7277
7307
  model: modelInfo,
@@ -7444,7 +7474,11 @@ var DefaultStreamTextResult = class {
7444
7474
  ]
7445
7475
  });
7446
7476
  const stepStartTimestampMs = now2();
7447
- const { stream: stream2, response, request } = await retry(
7477
+ const {
7478
+ stream: languageModelStream,
7479
+ response,
7480
+ request
7481
+ } = await retry(
7448
7482
  async () => stepModel.doStream({
7449
7483
  ...callSettings,
7450
7484
  tools: stepTools,
@@ -7457,6 +7491,9 @@ var DefaultStreamTextResult = class {
7457
7491
  includeRawChunks: includeRawChunks2
7458
7492
  })
7459
7493
  );
7494
+ const stream2 = languageModelStream.pipeThrough(
7495
+ createStreamTextPartTransform()
7496
+ );
7460
7497
  const streamWithToolResults = runToolsTransformation({
7461
7498
  tools,
7462
7499
  generatorStream: stream2,
@@ -7466,6 +7503,7 @@ var DefaultStreamTextResult = class {
7466
7503
  messages: stepInputMessages,
7467
7504
  repairToolCall,
7468
7505
  abortSignal,
7506
+ toolTimeoutMs,
7469
7507
  experimental_context,
7470
7508
  generateId: generateId2,
7471
7509
  stepNumber: recordedSteps.length,