ai 7.0.77 → 7.0.79

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,25 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.79
4
+
5
+ ### Patch Changes
6
+
7
+ - b251584: Preserve active text and reasoning parts when another merged UI message stream finishes a step, and align workflow stream normalization with the explicit part end chunks.
8
+ - 591d25b: feat: add batch completion webhooks. `experimental_startTextBatch` accepts a `webhookUrl`, and the gateway provider registers it through the batch `callbackUrl` contract and exports typed async-job metadata. Direct Anthropic and OpenAI batch providers return an unsupported warning when the option is provided.
9
+ - 9de0baf: Parse structured generateText output when providers omit finishReason but return text.
10
+ - Updated dependencies [591d25b]
11
+ - @ai-sdk/gateway@4.0.64
12
+ - @ai-sdk/provider@4.0.8
13
+ - @ai-sdk/provider-utils@5.0.30
14
+
15
+ ## 7.0.78
16
+
17
+ ### Patch Changes
18
+
19
+ - 96970bb: Continue approved `generateText`, `streamText`, and `WorkflowAgent` turns with a model-visible tool error when revalidated tool input is invalid.
20
+ - Updated dependencies [e12e068]
21
+ - @ai-sdk/gateway@4.0.63
22
+
3
23
  ## 7.0.77
4
24
 
5
25
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { EmbeddingModelV4, EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV4Embedding, EmbeddingModelV4Middleware, ImageModelV4, ImageModelV3, ImageModelV2, ImageModelV4ProviderMetadata, ImageModelV2ProviderMetadata, ImageModelV4Middleware, JSONValue as JSONValue$1, LanguageModelV4, LanguageModelV3, LanguageModelV2, SharedV4Warning, LanguageModelV4Source, LanguageModelV4Middleware, RerankingModelV4, RerankingModelV3, SharedV4ProviderMetadata, SharedV4ProviderReference, SpeechModelV4, SpeechModelV3, SpeechModelV2, TranscriptionModelV4, TranscriptionModelV3, TranscriptionModelV2, JSONObject, ImageModelV4Usage, LanguageModelV4CallOptions, LanguageModelV4Prompt, AISDKError, LanguageModelV4ToolCall, JSONSchema7, ProviderV4, ProviderV3, ProviderV2, Experimental_BatchLanguageModelV4, Experimental_BatchV4Error, Experimental_BatchV4Status, Experimental_BatchV4StartResult, SharedV4Headers, JSONParseError, TypeValidationError, Experimental_VideoModelV4, Experimental_VideoModelV3, Experimental_VideoModelV4FrameType, Experimental_VideoModelV4OperationWebhook, Experimental_VideoModelV4OperationStatusResult, EmbeddingModelV4CallOptions, Experimental_RealtimeFactoryV4, Experimental_RealtimeFactoryV4GetTokenOptions, Experimental_RealtimeFactoryV4GetTokenResult, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4SessionConfig, Experimental_RealtimeModelV4ToolDefinition, FilesV4, SkillsV4, NoSuchModelError, SharedV4AudioFormat, Experimental_SpeechTranslationModelV4, Experimental_SpeechTranslationModelV4Usage, FilesV4UploadFileCallOptions, SkillsV4UploadSkillResult, SkillsV4UploadSkillCallOptions, SkillsV4File } from '@ai-sdk/provider';
2
2
  export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
3
3
  import { GatewayModelId } from '@ai-sdk/gateway';
4
- export { GatewayModelId, createGateway, gateway } from '@ai-sdk/gateway';
4
+ export { GatewayAsyncJobMetadata, GatewayModelId, GatewayProviderMetadata, createGateway, gateway } from '@ai-sdk/gateway';
5
5
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
6
6
  import { ModelMessage, AssistantModelMessage, ToolModelMessage, ProviderOptions, ToolSet, SystemModelMessage, UserModelMessage, DataContent, FlexibleSchema, InferSchema, Context, Arrayable, InferToolSetContext, InferToolInput, InferToolOutput, ReasoningPart, ReasoningFilePart, Experimental_SandboxSession, Tool, ToolCall, IdGenerator, ToolExecutionOptions, MaybePromiseLike, InferToolContext, Experimental_ToolCallerTool, HasRequiredKey, TextPart, FilePart, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
7
7
  export { AssistantContent, AssistantModelMessage, DataContent, DownloadError, Experimental_SandboxProcess, Experimental_SandboxSession, Experimental_ToolCallerTool, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallPart, ToolContent, ToolExecuteFunction, ToolExecutionOptions, ToolModelMessage, ToolResultPart, ToolSet, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, experimental_toolCaller, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
@@ -6163,6 +6163,12 @@ type StartTextBatchOptions = {
6163
6163
  model: BatchLanguageModel;
6164
6164
  requests: ReadonlyArray<TextBatchRequest>;
6165
6165
  providerOptions?: ProviderOptions;
6166
+ /**
6167
+ * URL that the provider should notify when the batch reaches a terminal
6168
+ * state. Providers that do not support completion webhooks return an
6169
+ * unsupported warning.
6170
+ */
6171
+ webhookUrl?: string;
6166
6172
  } & BatchRequestOptions;
6167
6173
  /**
6168
6174
  * The acknowledged text batch and warnings produced while starting it.
@@ -6215,7 +6221,7 @@ type TextBatchItemResult = (TextBatchGenerationResult & {
6215
6221
  /**
6216
6222
  * Starts a durable text-generation batch.
6217
6223
  */
6218
- declare function startTextBatch({ model: modelArg, requests, providerOptions, abortSignal, headers, timeout, }: StartTextBatchOptions): Promise<StartTextBatchResult>;
6224
+ declare function startTextBatch({ model: modelArg, requests, providerOptions, webhookUrl, abortSignal, headers, timeout, }: StartTextBatchOptions): Promise<StartTextBatchResult>;
6219
6225
  /**
6220
6226
  * Retrieves the latest normalized status for a durable batch.
6221
6227
  */
package/dist/index.js CHANGED
@@ -5,7 +5,10 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/index.ts
8
- import { createGateway, gateway as gateway2 } from "@ai-sdk/gateway";
8
+ import {
9
+ createGateway,
10
+ gateway as gateway2
11
+ } from "@ai-sdk/gateway";
9
12
  import {
10
13
  asSchema as asSchema8,
11
14
  createIdGenerator as createIdGenerator9,
@@ -1143,7 +1146,7 @@ import {
1143
1146
  } from "@ai-sdk/provider-utils";
1144
1147
 
1145
1148
  // src/version.ts
1146
- var VERSION = true ? "7.0.77" : "0.0.0-test";
1149
+ var VERSION = true ? "7.0.79" : "0.0.0-test";
1147
1150
 
1148
1151
  // src/util/download/download.ts
1149
1152
  var download = async ({
@@ -5163,6 +5166,7 @@ async function validateApprovedToolApprovals({
5163
5166
  var _a23;
5164
5167
  const approved = [];
5165
5168
  const denied = [];
5169
+ const invalid = [];
5166
5170
  for (const approval of approvedToolApprovals) {
5167
5171
  const { toolCall, approvalRequest } = approval;
5168
5172
  const tool2 = getOwn(tools, toolCall.toolName);
@@ -5196,11 +5200,15 @@ async function validateApprovedToolApprovals({
5196
5200
  schema: asSchema4(tool2.inputSchema)
5197
5201
  });
5198
5202
  if (!validation.success) {
5199
- throw new InvalidToolInputError({
5200
- toolName: toolCall.toolName,
5201
- toolInput: JSON.stringify(toolCall.input),
5202
- cause: validation.error
5203
+ invalid.push({
5204
+ ...approval,
5205
+ error: new InvalidToolInputError({
5206
+ toolName: toolCall.toolName,
5207
+ toolInput: JSON.stringify(toolCall.input),
5208
+ cause: validation.error
5209
+ })
5203
5210
  });
5211
+ continue;
5204
5212
  }
5205
5213
  }
5206
5214
  const approvalStatus = await resolveToolApproval({
@@ -5224,7 +5232,11 @@ async function validateApprovedToolApprovals({
5224
5232
  approved.push(approval);
5225
5233
  }
5226
5234
  }
5227
- return { approvedToolApprovals: approved, deniedToolApprovals: denied };
5235
+ return {
5236
+ approvedToolApprovals: approved,
5237
+ deniedToolApprovals: denied,
5238
+ invalidToolApprovals: invalid
5239
+ };
5228
5240
  }
5229
5241
 
5230
5242
  // src/generate-text/generate-text.ts
@@ -5407,7 +5419,8 @@ async function generateText({
5407
5419
  } = collectToolApprovals({ messages: initialMessages });
5408
5420
  const {
5409
5421
  approvedToolApprovals: localApprovedToolApprovals,
5410
- deniedToolApprovals: revalidationDeniedToolApprovals
5422
+ deniedToolApprovals: revalidationDeniedToolApprovals,
5423
+ invalidToolApprovals
5411
5424
  } = await validateApprovedToolApprovals({
5412
5425
  approvedToolApprovals: approvedToolApprovals.filter(
5413
5426
  (toolApproval2) => !toolApproval2.toolCall.providerExecuted
@@ -5426,7 +5439,7 @@ async function generateText({
5426
5439
  const deniedToolApprovalsWithoutResults = deniedToolApprovals.filter(
5427
5440
  (toolApproval2) => toolApproval2.existingToolResult == null
5428
5441
  );
5429
- if (deniedToolApprovalsWithoutResults.length > 0 || localApprovedToolApprovals.length > 0) {
5442
+ if (deniedToolApprovalsWithoutResults.length > 0 || localApprovedToolApprovals.length > 0 || invalidToolApprovals.length > 0) {
5430
5443
  const toolResults2 = await executeTools({
5431
5444
  toolCalls: localApprovedToolApprovals.map(
5432
5445
  (toolApproval2) => toolApproval2.toolCall
@@ -5472,6 +5485,20 @@ async function generateText({
5472
5485
  output: modelOutput
5473
5486
  });
5474
5487
  }
5488
+ for (const toolApproval2 of invalidToolApprovals) {
5489
+ toolContent.push({
5490
+ type: "tool-result",
5491
+ toolCallId: toolApproval2.toolCall.toolCallId,
5492
+ toolName: toolApproval2.toolCall.toolName,
5493
+ output: await createToolModelOutput({
5494
+ toolCallId: toolApproval2.toolCall.toolCallId,
5495
+ input: toolApproval2.toolCall.input,
5496
+ tool: getOwn(tools, toolApproval2.toolCall.toolName),
5497
+ output: toolApproval2.error,
5498
+ errorMode: "text"
5499
+ })
5500
+ });
5501
+ }
5475
5502
  for (const toolApproval2 of deniedToolApprovalsWithoutResults) {
5476
5503
  toolContent.push({
5477
5504
  type: "tool-result",
@@ -6056,7 +6083,7 @@ async function generateText({
6056
6083
  callbacks: [onEnd, telemetryDispatcher.onEnd]
6057
6084
  });
6058
6085
  let resolvedOutput;
6059
- if (lastStep.finishReason === "stop") {
6086
+ if (lastStep.finishReason === "stop" || lastStep.finishReason == null && lastStep.text.length > 0) {
6060
6087
  const outputSpecification = output != null ? output : text();
6061
6088
  resolvedOutput = await outputSpecification.parseCompleteOutput(
6062
6089
  { text: lastStep.text },
@@ -7369,8 +7396,6 @@ function processUIMessageStream({
7369
7396
  break;
7370
7397
  }
7371
7398
  case "finish-step": {
7372
- state.activeTextParts = createIdMap();
7373
- state.activeReasoningParts = createIdMap();
7374
7399
  break;
7375
7400
  }
7376
7401
  case "reset-step": {
@@ -9533,7 +9558,8 @@ var DefaultStreamTextResult = class {
9533
9558
  if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
9534
9559
  const {
9535
9560
  approvedToolApprovals: localApprovedToolApprovals,
9536
- deniedToolApprovals: revalidationDeniedToolApprovals
9561
+ deniedToolApprovals: revalidationDeniedToolApprovals,
9562
+ invalidToolApprovals
9537
9563
  } = await validateApprovedToolApprovals({
9538
9564
  approvedToolApprovals: approvedToolApprovals.filter(
9539
9565
  (toolApproval2) => !toolApproval2.toolCall.providerExecuted
@@ -9575,6 +9601,18 @@ var DefaultStreamTextResult = class {
9575
9601
  toolName: toolApproval2.toolCall.toolName
9576
9602
  });
9577
9603
  }
9604
+ for (const toolApproval2 of invalidToolApprovals) {
9605
+ toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue({
9606
+ type: "tool-error",
9607
+ toolCallId: toolApproval2.toolCall.toolCallId,
9608
+ toolName: toolApproval2.toolCall.toolName,
9609
+ input: toolApproval2.toolCall.input,
9610
+ error: getErrorMessage6(toolApproval2.error),
9611
+ title: toolApproval2.toolCall.title,
9612
+ ...toolApproval2.toolCall.dynamic === true ? { dynamic: true } : {},
9613
+ ...toolApproval2.toolCall.toolMetadata != null ? { toolMetadata: toolApproval2.toolCall.toolMetadata } : {}
9614
+ });
9615
+ }
9578
9616
  const toolOutputs = [];
9579
9617
  await Promise.all(
9580
9618
  localApprovedToolApprovals.map(async (toolApproval2) => {
@@ -9607,7 +9645,7 @@ var DefaultStreamTextResult = class {
9607
9645
  }
9608
9646
  })
9609
9647
  );
9610
- if (toolOutputs.length > 0 || localDeniedToolApprovalsWithoutResults.length > 0) {
9648
+ if (toolOutputs.length > 0 || localDeniedToolApprovalsWithoutResults.length > 0 || invalidToolApprovals.length > 0) {
9611
9649
  const localToolContent = [];
9612
9650
  for (const output2 of toolOutputs) {
9613
9651
  localToolContent.push({
@@ -9623,6 +9661,20 @@ var DefaultStreamTextResult = class {
9623
9661
  })
9624
9662
  });
9625
9663
  }
9664
+ for (const toolApproval2 of invalidToolApprovals) {
9665
+ localToolContent.push({
9666
+ type: "tool-result",
9667
+ toolCallId: toolApproval2.toolCall.toolCallId,
9668
+ toolName: toolApproval2.toolCall.toolName,
9669
+ output: await createToolModelOutput({
9670
+ toolCallId: toolApproval2.toolCall.toolCallId,
9671
+ input: toolApproval2.toolCall.input,
9672
+ tool: getOwn(tools, toolApproval2.toolCall.toolName),
9673
+ output: toolApproval2.error,
9674
+ errorMode: "text"
9675
+ })
9676
+ });
9677
+ }
9626
9678
  for (const toolApproval2 of localDeniedToolApprovalsWithoutResults) {
9627
9679
  localToolContent.push({
9628
9680
  type: "tool-result",
@@ -11700,6 +11752,7 @@ async function startTextBatch({
11700
11752
  model: modelArg,
11701
11753
  requests,
11702
11754
  providerOptions,
11755
+ webhookUrl,
11703
11756
  abortSignal,
11704
11757
  headers,
11705
11758
  timeout
@@ -11739,7 +11792,8 @@ async function startTextBatch({
11739
11792
  requests: normalizedRequests,
11740
11793
  providerOptions,
11741
11794
  abortSignal: operationAbortSignal,
11742
- headers: headersWithUserAgent
11795
+ headers: headersWithUserAgent,
11796
+ ...webhookUrl != null && { webhookUrl }
11743
11797
  });
11744
11798
  const { batchId, warnings, ...status } = result;
11745
11799
  logWarnings({