ai 5.1.0-beta.20 → 5.1.0-beta.22

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.js CHANGED
@@ -60,7 +60,7 @@ __export(src_exports, {
60
60
  UI_MESSAGE_STREAM_HEADERS: () => UI_MESSAGE_STREAM_HEADERS,
61
61
  UnsupportedFunctionalityError: () => import_provider18.UnsupportedFunctionalityError,
62
62
  UnsupportedModelVersionError: () => UnsupportedModelVersionError,
63
- asSchema: () => import_provider_utils35.asSchema,
63
+ asSchema: () => import_provider_utils36.asSchema,
64
64
  assistantModelMessageSchema: () => assistantModelMessageSchema,
65
65
  callCompletionApi: () => callCompletionApi,
66
66
  consumeStream: () => consumeStream,
@@ -74,14 +74,14 @@ __export(src_exports, {
74
74
  coreUserMessageSchema: () => coreUserMessageSchema,
75
75
  cosineSimilarity: () => cosineSimilarity,
76
76
  createGateway: () => import_gateway3.createGateway,
77
- createIdGenerator: () => import_provider_utils35.createIdGenerator,
77
+ createIdGenerator: () => import_provider_utils36.createIdGenerator,
78
78
  createProviderRegistry: () => createProviderRegistry,
79
79
  createTextStreamResponse: () => createTextStreamResponse,
80
80
  createUIMessageStream: () => createUIMessageStream,
81
81
  createUIMessageStreamResponse: () => createUIMessageStreamResponse,
82
82
  customProvider: () => customProvider,
83
83
  defaultSettingsMiddleware: () => defaultSettingsMiddleware,
84
- dynamicTool: () => import_provider_utils35.dynamicTool,
84
+ dynamicTool: () => import_provider_utils36.dynamicTool,
85
85
  embed: () => embed,
86
86
  embedMany: () => embedMany,
87
87
  experimental_createMCPClient: () => createMCPClient,
@@ -92,7 +92,7 @@ __export(src_exports, {
92
92
  experimental_transcribe: () => transcribe,
93
93
  extractReasoningMiddleware: () => extractReasoningMiddleware,
94
94
  gateway: () => import_gateway3.gateway,
95
- generateId: () => import_provider_utils35.generateId,
95
+ generateId: () => import_provider_utils36.generateId,
96
96
  generateObject: () => generateObject,
97
97
  generateText: () => generateText,
98
98
  getTextFromDataUrl: () => getTextFromDataUrl,
@@ -102,10 +102,11 @@ __export(src_exports, {
102
102
  isDeepEqualData: () => isDeepEqualData,
103
103
  isToolOrDynamicToolUIPart: () => isToolOrDynamicToolUIPart,
104
104
  isToolUIPart: () => isToolUIPart,
105
- jsonSchema: () => import_provider_utils35.jsonSchema,
105
+ jsonSchema: () => import_provider_utils36.jsonSchema,
106
+ lastAssistantMessageIsCompleteWithApprovalResponses: () => lastAssistantMessageIsCompleteWithApprovalResponses,
106
107
  lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
107
108
  modelMessageSchema: () => modelMessageSchema,
108
- parseJsonEventStream: () => import_provider_utils35.parseJsonEventStream,
109
+ parseJsonEventStream: () => import_provider_utils36.parseJsonEventStream,
109
110
  parsePartialJson: () => parsePartialJson,
110
111
  pipeTextStreamToResponse: () => pipeTextStreamToResponse,
111
112
  pipeUIMessageStreamToResponse: () => pipeUIMessageStreamToResponse,
@@ -118,21 +119,21 @@ __export(src_exports, {
118
119
  streamObject: () => streamObject,
119
120
  streamText: () => streamText,
120
121
  systemModelMessageSchema: () => systemModelMessageSchema,
121
- tool: () => import_provider_utils35.tool,
122
+ tool: () => import_provider_utils36.tool,
122
123
  toolModelMessageSchema: () => toolModelMessageSchema,
123
124
  uiMessageChunkSchema: () => uiMessageChunkSchema,
124
125
  userModelMessageSchema: () => userModelMessageSchema,
125
126
  validateUIMessages: () => validateUIMessages,
126
127
  wrapLanguageModel: () => wrapLanguageModel,
127
128
  wrapProvider: () => wrapProvider,
128
- zodSchema: () => import_provider_utils35.zodSchema
129
+ zodSchema: () => import_provider_utils36.zodSchema
129
130
  });
130
131
  module.exports = __toCommonJS(src_exports);
131
132
  var import_gateway3 = require("@ai-sdk/gateway");
132
- var import_provider_utils35 = require("@ai-sdk/provider-utils");
133
+ var import_provider_utils36 = require("@ai-sdk/provider-utils");
133
134
 
134
135
  // src/generate-text/generate-text.ts
135
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
136
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
136
137
 
137
138
  // src/error/no-output-specified-error.ts
138
139
  var import_provider = require("@ai-sdk/provider");
@@ -808,7 +809,7 @@ function detectMediaType({
808
809
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
809
810
 
810
811
  // src/version.ts
811
- var VERSION = true ? "5.1.0-beta.20" : "0.0.0-test";
812
+ var VERSION = true ? "5.1.0-beta.22" : "0.0.0-test";
812
813
 
813
814
  // src/util/download/download.ts
814
815
  var download = async ({ url }) => {
@@ -951,12 +952,26 @@ async function convertToLanguageModelPrompt({
951
952
  download2,
952
953
  supportedUrls
953
954
  );
954
- return [
955
+ const messages = [
955
956
  ...prompt.system != null ? [{ role: "system", content: prompt.system }] : [],
956
957
  ...prompt.messages.map(
957
958
  (message) => convertToLanguageModelMessage({ message, downloadedAssets })
958
959
  )
959
960
  ];
961
+ const combinedMessages = [];
962
+ for (const message of messages) {
963
+ if (message.role !== "tool") {
964
+ combinedMessages.push(message);
965
+ continue;
966
+ }
967
+ const lastCombinedMessage = combinedMessages.at(-1);
968
+ if ((lastCombinedMessage == null ? void 0 : lastCombinedMessage.role) === "tool") {
969
+ lastCombinedMessage.content.push(...message.content);
970
+ } else {
971
+ combinedMessages.push(message);
972
+ }
973
+ }
974
+ return combinedMessages;
960
975
  }
961
976
  function convertToLanguageModelMessage({
962
977
  message,
@@ -998,6 +1013,8 @@ function convertToLanguageModelMessage({
998
1013
  content: message.content.filter(
999
1014
  // remove empty text parts (no text, and no provider options):
1000
1015
  (part) => part.type !== "text" || part.text !== "" || part.providerOptions != null
1016
+ ).filter(
1017
+ (part) => part.type !== "tool-approval-request"
1001
1018
  ).map((part) => {
1002
1019
  const providerOptions = part.providerOptions;
1003
1020
  switch (part.type) {
@@ -1054,7 +1071,7 @@ function convertToLanguageModelMessage({
1054
1071
  case "tool": {
1055
1072
  return {
1056
1073
  role: "tool",
1057
- content: message.content.map((part) => ({
1074
+ content: message.content.filter((part) => part.type !== "tool-approval-response").map((part) => ({
1058
1075
  type: "tool-result",
1059
1076
  toolCallId: part.toolCallId,
1060
1077
  toolName: part.toolName,
@@ -1166,6 +1183,27 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
1166
1183
  }
1167
1184
  }
1168
1185
 
1186
+ // src/prompt/create-tool-model-output.ts
1187
+ var import_provider20 = require("@ai-sdk/provider");
1188
+ function createToolModelOutput({
1189
+ output,
1190
+ tool: tool3,
1191
+ errorMode
1192
+ }) {
1193
+ if (errorMode === "text") {
1194
+ return { type: "error-text", value: (0, import_provider20.getErrorMessage)(output) };
1195
+ } else if (errorMode === "json") {
1196
+ return { type: "error-json", value: toJSONValue(output) };
1197
+ }
1198
+ if (tool3 == null ? void 0 : tool3.toModelOutput) {
1199
+ return tool3.toModelOutput(output);
1200
+ }
1201
+ return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: toJSONValue(output) };
1202
+ }
1203
+ function toJSONValue(value) {
1204
+ return value === void 0 ? null : value;
1205
+ }
1206
+
1169
1207
  // src/prompt/prepare-call-settings.ts
1170
1208
  function prepareCallSettings({
1171
1209
  maxOutputTokens,
@@ -1314,7 +1352,7 @@ function prepareToolsAndToolChoice({
1314
1352
  }
1315
1353
 
1316
1354
  // src/prompt/standardize-prompt.ts
1317
- var import_provider20 = require("@ai-sdk/provider");
1355
+ var import_provider21 = require("@ai-sdk/provider");
1318
1356
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1319
1357
  var import_v46 = require("zod/v4");
1320
1358
 
@@ -1417,6 +1455,17 @@ var toolResultPartSchema = import_v44.z.object({
1417
1455
  output: outputSchema,
1418
1456
  providerOptions: providerMetadataSchema.optional()
1419
1457
  });
1458
+ var toolApprovalRequestSchema = import_v44.z.object({
1459
+ type: import_v44.z.literal("tool-approval-request"),
1460
+ approvalId: import_v44.z.string(),
1461
+ toolCallId: import_v44.z.string()
1462
+ });
1463
+ var toolApprovalResponseSchema = import_v44.z.object({
1464
+ type: import_v44.z.literal("tool-approval-response"),
1465
+ approvalId: import_v44.z.string(),
1466
+ approved: import_v44.z.boolean(),
1467
+ reason: import_v44.z.string().optional()
1468
+ });
1420
1469
 
1421
1470
  // src/prompt/message.ts
1422
1471
  var systemModelMessageSchema = import_v45.z.object(
@@ -1446,7 +1495,8 @@ var assistantModelMessageSchema = import_v45.z.object({
1446
1495
  filePartSchema,
1447
1496
  reasoningPartSchema,
1448
1497
  toolCallPartSchema,
1449
- toolResultPartSchema
1498
+ toolResultPartSchema,
1499
+ toolApprovalRequestSchema
1450
1500
  ])
1451
1501
  )
1452
1502
  ]),
@@ -1455,7 +1505,7 @@ var assistantModelMessageSchema = import_v45.z.object({
1455
1505
  var coreAssistantMessageSchema = assistantModelMessageSchema;
1456
1506
  var toolModelMessageSchema = import_v45.z.object({
1457
1507
  role: import_v45.z.literal("tool"),
1458
- content: import_v45.z.array(toolResultPartSchema),
1508
+ content: import_v45.z.array(import_v45.z.union([toolResultPartSchema, toolApprovalResponseSchema])),
1459
1509
  providerOptions: providerMetadataSchema.optional()
1460
1510
  });
1461
1511
  var coreToolMessageSchema = toolModelMessageSchema;
@@ -1470,19 +1520,19 @@ var coreMessageSchema = modelMessageSchema;
1470
1520
  // src/prompt/standardize-prompt.ts
1471
1521
  async function standardizePrompt(prompt) {
1472
1522
  if (prompt.prompt == null && prompt.messages == null) {
1473
- throw new import_provider20.InvalidPromptError({
1523
+ throw new import_provider21.InvalidPromptError({
1474
1524
  prompt,
1475
1525
  message: "prompt or messages must be defined"
1476
1526
  });
1477
1527
  }
1478
1528
  if (prompt.prompt != null && prompt.messages != null) {
1479
- throw new import_provider20.InvalidPromptError({
1529
+ throw new import_provider21.InvalidPromptError({
1480
1530
  prompt,
1481
1531
  message: "prompt and messages cannot be defined at the same time"
1482
1532
  });
1483
1533
  }
1484
1534
  if (prompt.system != null && typeof prompt.system !== "string") {
1485
- throw new import_provider20.InvalidPromptError({
1535
+ throw new import_provider21.InvalidPromptError({
1486
1536
  prompt,
1487
1537
  message: "system must be a string"
1488
1538
  });
@@ -1495,13 +1545,13 @@ async function standardizePrompt(prompt) {
1495
1545
  } else if (prompt.messages != null) {
1496
1546
  messages = prompt.messages;
1497
1547
  } else {
1498
- throw new import_provider20.InvalidPromptError({
1548
+ throw new import_provider21.InvalidPromptError({
1499
1549
  prompt,
1500
1550
  message: "prompt or messages must be defined"
1501
1551
  });
1502
1552
  }
1503
1553
  if (messages.length === 0) {
1504
- throw new import_provider20.InvalidPromptError({
1554
+ throw new import_provider21.InvalidPromptError({
1505
1555
  prompt,
1506
1556
  message: "messages must not be empty"
1507
1557
  });
@@ -1511,7 +1561,7 @@ async function standardizePrompt(prompt) {
1511
1561
  schema: import_v46.z.array(modelMessageSchema)
1512
1562
  });
1513
1563
  if (!validationResult.success) {
1514
- throw new import_provider20.InvalidPromptError({
1564
+ throw new import_provider21.InvalidPromptError({
1515
1565
  prompt,
1516
1566
  message: "The messages must be a ModelMessage[]. If you have passed a UIMessage[], you can use convertToModelMessages to convert them.",
1517
1567
  cause: validationResult.error
@@ -1525,10 +1575,10 @@ async function standardizePrompt(prompt) {
1525
1575
 
1526
1576
  // src/prompt/wrap-gateway-error.ts
1527
1577
  var import_gateway2 = require("@ai-sdk/gateway");
1528
- var import_provider21 = require("@ai-sdk/provider");
1578
+ var import_provider22 = require("@ai-sdk/provider");
1529
1579
  function wrapGatewayError(error) {
1530
1580
  if (import_gateway2.GatewayAuthenticationError.isInstance(error) || import_gateway2.GatewayModelNotFoundError.isInstance(error)) {
1531
- return new import_provider21.AISDKError({
1581
+ return new import_provider22.AISDKError({
1532
1582
  name: "GatewayError",
1533
1583
  message: "Vercel AI Gateway access failed. If you want to use AI SDK providers directly, use the providers, e.g. @ai-sdk/openai, or register a different global default provider.",
1534
1584
  cause: error
@@ -1774,7 +1824,7 @@ function asArray(value) {
1774
1824
  }
1775
1825
 
1776
1826
  // src/util/retry-with-exponential-backoff.ts
1777
- var import_provider22 = require("@ai-sdk/provider");
1827
+ var import_provider23 = require("@ai-sdk/provider");
1778
1828
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
1779
1829
  function getRetryDelayInMs({
1780
1830
  error,
@@ -1841,7 +1891,7 @@ async function _retryWithExponentialBackoff(f, {
1841
1891
  errors: newErrors
1842
1892
  });
1843
1893
  }
1844
- if (error instanceof Error && import_provider22.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
1894
+ if (error instanceof Error && import_provider23.APICallError.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
1845
1895
  await (0, import_provider_utils7.delay)(
1846
1896
  getRetryDelayInMs({
1847
1897
  error,
@@ -1902,6 +1952,164 @@ function prepareRetries({
1902
1952
  };
1903
1953
  }
1904
1954
 
1955
+ // src/generate-text/collect-tool-approvals.ts
1956
+ function collectToolApprovals({
1957
+ messages
1958
+ }) {
1959
+ const lastMessage = messages.at(-1);
1960
+ if ((lastMessage == null ? void 0 : lastMessage.role) != "tool") {
1961
+ return {
1962
+ approvedToolApprovals: [],
1963
+ deniedToolApprovals: []
1964
+ };
1965
+ }
1966
+ const toolCallsByToolCallId = {};
1967
+ for (const message of messages) {
1968
+ if (message.role === "assistant" && typeof message.content !== "string") {
1969
+ const content = message.content;
1970
+ for (const part of content) {
1971
+ if (part.type === "tool-call") {
1972
+ toolCallsByToolCallId[part.toolCallId] = part;
1973
+ }
1974
+ }
1975
+ }
1976
+ }
1977
+ const toolApprovalRequestsByApprovalId = {};
1978
+ for (const message of messages) {
1979
+ if (message.role === "assistant" && typeof message.content !== "string") {
1980
+ const content = message.content;
1981
+ for (const part of content) {
1982
+ if (part.type === "tool-approval-request") {
1983
+ toolApprovalRequestsByApprovalId[part.approvalId] = part;
1984
+ }
1985
+ }
1986
+ }
1987
+ }
1988
+ const toolResults = {};
1989
+ for (const part of lastMessage.content) {
1990
+ if (part.type === "tool-result") {
1991
+ toolResults[part.toolCallId] = part;
1992
+ }
1993
+ }
1994
+ const approvedToolApprovals = [];
1995
+ const deniedToolApprovals = [];
1996
+ const approvalResponses = lastMessage.content.filter(
1997
+ (part) => part.type === "tool-approval-response"
1998
+ );
1999
+ for (const approvalResponse of approvalResponses) {
2000
+ const approvalRequest = toolApprovalRequestsByApprovalId[approvalResponse.approvalId];
2001
+ if (toolResults[approvalRequest.toolCallId] != null) {
2002
+ continue;
2003
+ }
2004
+ const approval = {
2005
+ approvalRequest,
2006
+ approvalResponse,
2007
+ toolCall: toolCallsByToolCallId[approvalRequest.toolCallId]
2008
+ };
2009
+ if (approvalResponse.approved) {
2010
+ approvedToolApprovals.push(approval);
2011
+ } else {
2012
+ deniedToolApprovals.push(approval);
2013
+ }
2014
+ }
2015
+ return { approvedToolApprovals, deniedToolApprovals };
2016
+ }
2017
+
2018
+ // src/generate-text/execute-tool-call.ts
2019
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
2020
+ async function executeToolCall({
2021
+ toolCall,
2022
+ tools,
2023
+ tracer,
2024
+ telemetry,
2025
+ messages,
2026
+ abortSignal,
2027
+ experimental_context,
2028
+ onPreliminaryToolResult
2029
+ }) {
2030
+ const { toolName, toolCallId, input } = toolCall;
2031
+ const tool3 = tools == null ? void 0 : tools[toolName];
2032
+ if ((tool3 == null ? void 0 : tool3.execute) == null) {
2033
+ return void 0;
2034
+ }
2035
+ return recordSpan({
2036
+ name: "ai.toolCall",
2037
+ attributes: selectTelemetryAttributes({
2038
+ telemetry,
2039
+ attributes: {
2040
+ ...assembleOperationName({
2041
+ operationId: "ai.toolCall",
2042
+ telemetry
2043
+ }),
2044
+ "ai.toolCall.name": toolName,
2045
+ "ai.toolCall.id": toolCallId,
2046
+ "ai.toolCall.args": {
2047
+ output: () => JSON.stringify(input)
2048
+ }
2049
+ }
2050
+ }),
2051
+ tracer,
2052
+ fn: async (span) => {
2053
+ let output;
2054
+ try {
2055
+ const stream = (0, import_provider_utils8.executeTool)({
2056
+ execute: tool3.execute.bind(tool3),
2057
+ input,
2058
+ options: {
2059
+ toolCallId,
2060
+ messages,
2061
+ abortSignal,
2062
+ experimental_context
2063
+ }
2064
+ });
2065
+ for await (const part of stream) {
2066
+ if (part.type === "preliminary") {
2067
+ onPreliminaryToolResult == null ? void 0 : onPreliminaryToolResult({
2068
+ ...toolCall,
2069
+ type: "tool-result",
2070
+ output: part.output,
2071
+ preliminary: true
2072
+ });
2073
+ } else {
2074
+ output = part.output;
2075
+ }
2076
+ }
2077
+ } catch (error) {
2078
+ recordErrorOnSpan(span, error);
2079
+ return {
2080
+ type: "tool-error",
2081
+ toolCallId,
2082
+ toolName,
2083
+ input,
2084
+ error,
2085
+ dynamic: tool3.type === "dynamic"
2086
+ };
2087
+ }
2088
+ try {
2089
+ span.setAttributes(
2090
+ selectTelemetryAttributes({
2091
+ telemetry,
2092
+ attributes: {
2093
+ "ai.toolCall.result": {
2094
+ output: () => JSON.stringify(output)
2095
+ }
2096
+ }
2097
+ })
2098
+ );
2099
+ } catch (ignored) {
2100
+ }
2101
+ return {
2102
+ type: "tool-result",
2103
+ toolCallId,
2104
+ toolName,
2105
+ input,
2106
+ output,
2107
+ dynamic: tool3.type === "dynamic"
2108
+ };
2109
+ }
2110
+ });
2111
+ }
2112
+
1905
2113
  // src/generate-text/extract-text-content.ts
1906
2114
  function extractTextContent(content) {
1907
2115
  const parts = content.filter(
@@ -1914,7 +2122,7 @@ function extractTextContent(content) {
1914
2122
  }
1915
2123
 
1916
2124
  // src/generate-text/generated-file.ts
1917
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
2125
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1918
2126
  var DefaultGeneratedFile = class {
1919
2127
  constructor({
1920
2128
  data,
@@ -1928,14 +2136,14 @@ var DefaultGeneratedFile = class {
1928
2136
  // lazy conversion with caching to avoid unnecessary conversion overhead:
1929
2137
  get base64() {
1930
2138
  if (this.base64Data == null) {
1931
- this.base64Data = (0, import_provider_utils8.convertUint8ArrayToBase64)(this.uint8ArrayData);
2139
+ this.base64Data = (0, import_provider_utils9.convertUint8ArrayToBase64)(this.uint8ArrayData);
1932
2140
  }
1933
2141
  return this.base64Data;
1934
2142
  }
1935
2143
  // lazy conversion with caching to avoid unnecessary conversion overhead:
1936
2144
  get uint8Array() {
1937
2145
  if (this.uint8ArrayData == null) {
1938
- this.uint8ArrayData = (0, import_provider_utils8.convertBase64ToUint8Array)(this.base64Data);
2146
+ this.uint8ArrayData = (0, import_provider_utils9.convertBase64ToUint8Array)(this.base64Data);
1939
2147
  }
1940
2148
  return this.uint8ArrayData;
1941
2149
  }
@@ -1948,7 +2156,7 @@ var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
1948
2156
  };
1949
2157
 
1950
2158
  // src/generate-text/parse-tool-call.ts
1951
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2159
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1952
2160
  async function parseToolCall({
1953
2161
  toolCall,
1954
2162
  tools,
@@ -1973,7 +2181,7 @@ async function parseToolCall({
1973
2181
  tools,
1974
2182
  inputSchema: ({ toolName }) => {
1975
2183
  const { inputSchema } = tools[toolName];
1976
- return (0, import_provider_utils9.asSchema)(inputSchema).jsonSchema;
2184
+ return (0, import_provider_utils10.asSchema)(inputSchema).jsonSchema;
1977
2185
  },
1978
2186
  system,
1979
2187
  messages,
@@ -1991,7 +2199,7 @@ async function parseToolCall({
1991
2199
  return await doParseToolCall({ toolCall: repairedToolCall, tools });
1992
2200
  }
1993
2201
  } catch (error) {
1994
- const parsedInput = await (0, import_provider_utils9.safeParseJSON)({ text: toolCall.input });
2202
+ const parsedInput = await (0, import_provider_utils10.safeParseJSON)({ text: toolCall.input });
1995
2203
  const input = parsedInput.success ? parsedInput.value : toolCall.input;
1996
2204
  return {
1997
2205
  type: "tool-call",
@@ -2016,8 +2224,8 @@ async function doParseToolCall({
2016
2224
  availableTools: Object.keys(tools)
2017
2225
  });
2018
2226
  }
2019
- const schema = (0, import_provider_utils9.asSchema)(tool3.inputSchema);
2020
- const parseResult = toolCall.input.trim() === "" ? await (0, import_provider_utils9.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils9.safeParseJSON)({ text: toolCall.input, schema });
2227
+ const schema = (0, import_provider_utils10.asSchema)(tool3.inputSchema);
2228
+ const parseResult = toolCall.input.trim() === "" ? await (0, import_provider_utils10.safeValidateTypes)({ value: {}, schema }) : await (0, import_provider_utils10.safeParseJSON)({ text: toolCall.input, schema });
2021
2229
  if (parseResult.success === false) {
2022
2230
  throw new InvalidToolInputError({
2023
2231
  toolName,
@@ -2124,27 +2332,6 @@ async function isStopConditionMet({
2124
2332
  return (await Promise.all(stopConditions.map((condition) => condition({ steps })))).some((result) => result);
2125
2333
  }
2126
2334
 
2127
- // src/prompt/create-tool-model-output.ts
2128
- var import_provider23 = require("@ai-sdk/provider");
2129
- function createToolModelOutput({
2130
- output,
2131
- tool: tool3,
2132
- errorMode
2133
- }) {
2134
- if (errorMode === "text") {
2135
- return { type: "error-text", value: (0, import_provider23.getErrorMessage)(output) };
2136
- } else if (errorMode === "json") {
2137
- return { type: "error-json", value: toJSONValue(output) };
2138
- }
2139
- if (tool3 == null ? void 0 : tool3.toModelOutput) {
2140
- return tool3.toModelOutput(output);
2141
- }
2142
- return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: toJSONValue(output) };
2143
- }
2144
- function toJSONValue(value) {
2145
- return value === void 0 ? null : value;
2146
- }
2147
-
2148
2335
  // src/generate-text/to-response-messages.ts
2149
2336
  function toResponseMessages({
2150
2337
  content: inputContent,
@@ -2208,6 +2395,12 @@ function toResponseMessages({
2208
2395
  }),
2209
2396
  providerOptions: part.providerMetadata
2210
2397
  };
2398
+ case "tool-approval-request":
2399
+ return {
2400
+ type: "tool-approval-request",
2401
+ approvalId: part.approvalId,
2402
+ toolCallId: part.toolCall.toolCallId
2403
+ };
2211
2404
  }
2212
2405
  });
2213
2406
  if (content.length > 0) {
@@ -2236,7 +2429,7 @@ function toResponseMessages({
2236
2429
  }
2237
2430
 
2238
2431
  // src/generate-text/generate-text.ts
2239
- var originalGenerateId = (0, import_provider_utils10.createIdGenerator)({
2432
+ var originalGenerateId = (0, import_provider_utils11.createIdGenerator)({
2240
2433
  prefix: "aitxt",
2241
2434
  size: 24
2242
2435
  });
@@ -2262,7 +2455,7 @@ async function generateText({
2262
2455
  experimental_download: download2,
2263
2456
  experimental_context,
2264
2457
  _internal: {
2265
- generateId: generateId3 = originalGenerateId,
2458
+ generateId: generateId2 = originalGenerateId,
2266
2459
  currentDate = () => /* @__PURE__ */ new Date()
2267
2460
  } = {},
2268
2461
  onStepFinish,
@@ -2275,7 +2468,7 @@ async function generateText({
2275
2468
  abortSignal
2276
2469
  });
2277
2470
  const callSettings = prepareCallSettings(settings);
2278
- const headersWithUserAgent = (0, import_provider_utils10.withUserAgentSuffix)(
2471
+ const headersWithUserAgent = (0, import_provider_utils11.withUserAgentSuffix)(
2279
2472
  headers != null ? headers : {},
2280
2473
  `ai/${VERSION}`
2281
2474
  );
@@ -2314,17 +2507,55 @@ async function generateText({
2314
2507
  tracer,
2315
2508
  fn: async (span) => {
2316
2509
  var _a17, _b, _c, _d, _e, _f, _g;
2510
+ const initialMessages = initialPrompt.messages;
2511
+ const responseMessages = [];
2512
+ const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
2513
+ if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
2514
+ const toolOutputs = await executeTools({
2515
+ toolCalls: approvedToolApprovals.map(
2516
+ (toolApproval) => toolApproval.toolCall
2517
+ ),
2518
+ tools,
2519
+ tracer,
2520
+ telemetry,
2521
+ messages: initialMessages,
2522
+ abortSignal,
2523
+ experimental_context
2524
+ });
2525
+ responseMessages.push({
2526
+ role: "tool",
2527
+ content: [
2528
+ // add regular tool results for approved tool calls:
2529
+ ...toolOutputs.map((output2) => ({
2530
+ type: "tool-result",
2531
+ toolCallId: output2.toolCallId,
2532
+ toolName: output2.toolName,
2533
+ output: createToolModelOutput({
2534
+ tool: tools == null ? void 0 : tools[output2.toolName],
2535
+ output: output2.type === "tool-result" ? output2.output : output2.error,
2536
+ errorMode: output2.type === "tool-error" ? "json" : "none"
2537
+ })
2538
+ })),
2539
+ // add execution denied tool results for denied tool approvals:
2540
+ ...deniedToolApprovals.map((toolApproval) => ({
2541
+ type: "tool-result",
2542
+ toolCallId: toolApproval.toolCall.toolCallId,
2543
+ toolName: toolApproval.toolCall.toolName,
2544
+ output: {
2545
+ type: "execution-denied",
2546
+ reason: toolApproval.approvalResponse.reason
2547
+ }
2548
+ }))
2549
+ ]
2550
+ });
2551
+ }
2317
2552
  const callSettings2 = prepareCallSettings(settings);
2318
2553
  let currentModelResponse;
2319
2554
  let clientToolCalls = [];
2320
2555
  let clientToolOutputs = [];
2321
- const responseMessages = [];
2322
2556
  const steps = [];
2323
2557
  do {
2324
- const stepInputMessages = [
2325
- ...initialPrompt.messages,
2326
- ...responseMessages
2327
- ];
2558
+ const stepInputMessages = [...initialMessages, ...responseMessages];
2328
2559
  const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
2329
2560
  model,
2330
2561
  steps,
@@ -2400,7 +2631,7 @@ async function generateText({
2400
2631
  headers: headersWithUserAgent
2401
2632
  });
2402
2633
  const responseData = {
2403
- id: (_b2 = (_a19 = result.response) == null ? void 0 : _a19.id) != null ? _b2 : generateId3(),
2634
+ id: (_b2 = (_a19 = result.response) == null ? void 0 : _a19.id) != null ? _b2 : generateId2(),
2404
2635
  timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
2405
2636
  modelId: (_f2 = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f2 : stepModel.modelId,
2406
2637
  headers: (_g2 = result.response) == null ? void 0 : _g2.headers,
@@ -2456,6 +2687,7 @@ async function generateText({
2456
2687
  })
2457
2688
  )
2458
2689
  );
2690
+ const toolApprovalRequests = {};
2459
2691
  for (const toolCall of stepToolCalls) {
2460
2692
  if (toolCall.invalid) {
2461
2693
  continue;
@@ -2470,6 +2702,13 @@ async function generateText({
2470
2702
  experimental_context
2471
2703
  });
2472
2704
  }
2705
+ if (tool3 == null ? void 0 : tool3.needsApproval) {
2706
+ toolApprovalRequests[toolCall.toolCallId] = {
2707
+ type: "tool-approval-request",
2708
+ approvalId: generateId2(),
2709
+ toolCall
2710
+ };
2711
+ }
2473
2712
  }
2474
2713
  const invalidToolCalls = stepToolCalls.filter(
2475
2714
  (toolCall) => toolCall.invalid && toolCall.dynamic
@@ -2481,7 +2720,7 @@ async function generateText({
2481
2720
  toolCallId: toolCall.toolCallId,
2482
2721
  toolName: toolCall.toolName,
2483
2722
  input: toolCall.input,
2484
- error: (0, import_provider_utils10.getErrorMessage)(toolCall.error),
2723
+ error: (0, import_provider_utils11.getErrorMessage)(toolCall.error),
2485
2724
  dynamic: true
2486
2725
  });
2487
2726
  }
@@ -2492,7 +2731,7 @@ async function generateText({
2492
2731
  clientToolOutputs.push(
2493
2732
  ...await executeTools({
2494
2733
  toolCalls: clientToolCalls.filter(
2495
- (toolCall) => !toolCall.invalid
2734
+ (toolCall) => !toolCall.invalid && toolApprovalRequests[toolCall.toolCallId] == null
2496
2735
  ),
2497
2736
  tools,
2498
2737
  tracer,
@@ -2506,7 +2745,8 @@ async function generateText({
2506
2745
  const stepContent = asContent({
2507
2746
  content: currentModelResponse.content,
2508
2747
  toolCalls: stepToolCalls,
2509
- toolOutputs: clientToolOutputs
2748
+ toolOutputs: clientToolOutputs,
2749
+ toolApprovalRequests: Object.values(toolApprovalRequests)
2510
2750
  });
2511
2751
  responseMessages.push(
2512
2752
  ...toResponseMessages({
@@ -2587,81 +2827,17 @@ async function executeTools({
2587
2827
  experimental_context
2588
2828
  }) {
2589
2829
  const toolOutputs = await Promise.all(
2590
- toolCalls.map(async ({ toolCallId, toolName, input }) => {
2591
- const tool3 = tools[toolName];
2592
- if ((tool3 == null ? void 0 : tool3.execute) == null) {
2593
- return void 0;
2594
- }
2595
- return recordSpan({
2596
- name: "ai.toolCall",
2597
- attributes: selectTelemetryAttributes({
2598
- telemetry,
2599
- attributes: {
2600
- ...assembleOperationName({
2601
- operationId: "ai.toolCall",
2602
- telemetry
2603
- }),
2604
- "ai.toolCall.name": toolName,
2605
- "ai.toolCall.id": toolCallId,
2606
- "ai.toolCall.args": {
2607
- output: () => JSON.stringify(input)
2608
- }
2609
- }
2610
- }),
2830
+ toolCalls.map(
2831
+ async (toolCall) => executeToolCall({
2832
+ toolCall,
2833
+ tools,
2611
2834
  tracer,
2612
- fn: async (span) => {
2613
- try {
2614
- const stream = (0, import_provider_utils10.executeTool)({
2615
- execute: tool3.execute.bind(tool3),
2616
- input,
2617
- options: {
2618
- toolCallId,
2619
- messages,
2620
- abortSignal,
2621
- experimental_context
2622
- }
2623
- });
2624
- let output;
2625
- for await (const part of stream) {
2626
- if (part.type === "final") {
2627
- output = part.output;
2628
- }
2629
- }
2630
- try {
2631
- span.setAttributes(
2632
- selectTelemetryAttributes({
2633
- telemetry,
2634
- attributes: {
2635
- "ai.toolCall.result": {
2636
- output: () => JSON.stringify(output)
2637
- }
2638
- }
2639
- })
2640
- );
2641
- } catch (ignored) {
2642
- }
2643
- return {
2644
- type: "tool-result",
2645
- toolCallId,
2646
- toolName,
2647
- input,
2648
- output,
2649
- dynamic: tool3.type === "dynamic"
2650
- };
2651
- } catch (error) {
2652
- recordErrorOnSpan(span, error);
2653
- return {
2654
- type: "tool-error",
2655
- toolCallId,
2656
- toolName,
2657
- input,
2658
- error,
2659
- dynamic: tool3.type === "dynamic"
2660
- };
2661
- }
2662
- }
2663
- });
2664
- })
2835
+ telemetry,
2836
+ messages,
2837
+ abortSignal,
2838
+ experimental_context
2839
+ })
2840
+ )
2665
2841
  );
2666
2842
  return toolOutputs.filter(
2667
2843
  (output) => output != null
@@ -2766,7 +2942,8 @@ function asToolCalls(content) {
2766
2942
  function asContent({
2767
2943
  content,
2768
2944
  toolCalls,
2769
- toolOutputs
2945
+ toolOutputs,
2946
+ toolApprovalRequests
2770
2947
  }) {
2771
2948
  return [
2772
2949
  ...content.map((part) => {
@@ -2816,13 +2993,14 @@ function asContent({
2816
2993
  }
2817
2994
  }
2818
2995
  }),
2819
- ...toolOutputs
2996
+ ...toolOutputs,
2997
+ ...toolApprovalRequests
2820
2998
  ];
2821
2999
  }
2822
3000
 
2823
3001
  // src/generate-text/stream-text.ts
2824
3002
  var import_provider24 = require("@ai-sdk/provider");
2825
- var import_provider_utils14 = require("@ai-sdk/provider-utils");
3003
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
2826
3004
 
2827
3005
  // src/util/prepare-headers.ts
2828
3006
  function prepareHeaders(headers, defaultHeaders) {
@@ -2959,7 +3137,7 @@ function getResponseUIMessageId({
2959
3137
  }
2960
3138
 
2961
3139
  // src/ui/process-ui-message-stream.ts
2962
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
3140
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
2963
3141
 
2964
3142
  // src/ui-message-stream/ui-message-chunks.ts
2965
3143
  var import_v47 = require("zod/v4");
@@ -3015,6 +3193,11 @@ var uiMessageChunkSchema = import_v47.z.union([
3015
3193
  dynamic: import_v47.z.boolean().optional(),
3016
3194
  errorText: import_v47.z.string()
3017
3195
  }),
3196
+ import_v47.z.strictObject({
3197
+ type: import_v47.z.literal("tool-approval-request"),
3198
+ approvalId: import_v47.z.string(),
3199
+ toolCallId: import_v47.z.string()
3200
+ }),
3018
3201
  import_v47.z.strictObject({
3019
3202
  type: import_v47.z.literal("tool-output-available"),
3020
3203
  toolCallId: import_v47.z.string(),
@@ -3030,6 +3213,10 @@ var uiMessageChunkSchema = import_v47.z.union([
3030
3213
  providerExecuted: import_v47.z.boolean().optional(),
3031
3214
  dynamic: import_v47.z.boolean().optional()
3032
3215
  }),
3216
+ import_v47.z.strictObject({
3217
+ type: import_v47.z.literal("tool-output-denied"),
3218
+ toolCallId: import_v47.z.string()
3219
+ }),
3033
3220
  import_v47.z.strictObject({
3034
3221
  type: import_v47.z.literal("reasoning-start"),
3035
3222
  id: import_v47.z.string(),
@@ -3137,7 +3324,7 @@ function mergeObjects(base, overrides) {
3137
3324
  }
3138
3325
 
3139
3326
  // src/util/parse-partial-json.ts
3140
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
3327
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
3141
3328
 
3142
3329
  // src/util/fix-json.ts
3143
3330
  function fixJson(input) {
@@ -3462,11 +3649,11 @@ async function parsePartialJson(jsonText) {
3462
3649
  if (jsonText === void 0) {
3463
3650
  return { value: void 0, state: "undefined-input" };
3464
3651
  }
3465
- let result = await (0, import_provider_utils11.safeParseJSON)({ text: jsonText });
3652
+ let result = await (0, import_provider_utils12.safeParseJSON)({ text: jsonText });
3466
3653
  if (result.success) {
3467
3654
  return { value: result.value, state: "successful-parse" };
3468
3655
  }
3469
- result = await (0, import_provider_utils11.safeParseJSON)({ text: fixJson(jsonText) });
3656
+ result = await (0, import_provider_utils12.safeParseJSON)({ text: fixJson(jsonText) });
3470
3657
  if (result.success) {
3471
3658
  return { value: result.value, state: "repaired-parse" };
3472
3659
  }
@@ -3616,7 +3803,7 @@ function processUIMessageStream({
3616
3803
  if (metadata != null) {
3617
3804
  const mergedMetadata = state.message.metadata != null ? mergeObjects(state.message.metadata, metadata) : metadata;
3618
3805
  if (messageMetadataSchema != null) {
3619
- await (0, import_provider_utils12.validateTypes)({
3806
+ await (0, import_provider_utils13.validateTypes)({
3620
3807
  value: mergedMetadata,
3621
3808
  schema: messageMetadataSchema
3622
3809
  });
@@ -3814,6 +4001,21 @@ function processUIMessageStream({
3814
4001
  write();
3815
4002
  break;
3816
4003
  }
4004
+ case "tool-approval-request": {
4005
+ const toolInvocation = getToolInvocation(chunk.toolCallId);
4006
+ toolInvocation.state = "approval-requested";
4007
+ toolInvocation.approval = {
4008
+ id: chunk.approvalId
4009
+ };
4010
+ write();
4011
+ break;
4012
+ }
4013
+ case "tool-output-denied": {
4014
+ const toolInvocation = getToolInvocation(chunk.toolCallId);
4015
+ toolInvocation.state = "output-denied";
4016
+ write();
4017
+ break;
4018
+ }
3817
4019
  case "tool-output-available": {
3818
4020
  if (chunk.dynamic) {
3819
4021
  const toolInvocation = getDynamicToolInvocation(
@@ -3908,7 +4110,7 @@ function processUIMessageStream({
3908
4110
  default: {
3909
4111
  if (isDataUIMessageChunk(chunk)) {
3910
4112
  if ((dataPartSchemas == null ? void 0 : dataPartSchemas[chunk.type]) != null) {
3911
- await (0, import_provider_utils12.validateTypes)({
4113
+ await (0, import_provider_utils13.validateTypes)({
3912
4114
  value: chunk.data,
3913
4115
  schema: dataPartSchemas[chunk.type]
3914
4116
  });
@@ -4165,10 +4367,10 @@ function createStitchableStream() {
4165
4367
  const { value, done } = await innerStreamReaders[0].read();
4166
4368
  if (done) {
4167
4369
  innerStreamReaders.shift();
4168
- if (innerStreamReaders.length > 0) {
4169
- await processPull();
4170
- } else if (isClosed) {
4370
+ if (innerStreamReaders.length === 0 && isClosed) {
4171
4371
  controller == null ? void 0 : controller.close();
4372
+ } else {
4373
+ await processPull();
4172
4374
  }
4173
4375
  } else {
4174
4376
  controller == null ? void 0 : controller.enqueue(value);
@@ -4264,7 +4466,7 @@ function now() {
4264
4466
  }
4265
4467
 
4266
4468
  // src/generate-text/run-tools-transformation.ts
4267
- var import_provider_utils13 = require("@ai-sdk/provider-utils");
4469
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
4268
4470
  function runToolsTransformation({
4269
4471
  tools,
4270
4472
  generatorStream,
@@ -4274,7 +4476,8 @@ function runToolsTransformation({
4274
4476
  messages,
4275
4477
  abortSignal,
4276
4478
  repairToolCall,
4277
- experimental_context
4479
+ experimental_context,
4480
+ generateId: generateId2
4278
4481
  }) {
4279
4482
  let toolResultsStreamController = null;
4280
4483
  const toolResultsStream = new ReadableStream({
@@ -4350,13 +4553,12 @@ function runToolsTransformation({
4350
4553
  toolCallId: toolCall.toolCallId,
4351
4554
  toolName: toolCall.toolName,
4352
4555
  input: toolCall.input,
4353
- error: (0, import_provider_utils13.getErrorMessage)(toolCall.error),
4556
+ error: (0, import_provider_utils14.getErrorMessage)(toolCall.error),
4354
4557
  dynamic: true
4355
4558
  });
4356
4559
  break;
4357
4560
  }
4358
4561
  const tool3 = tools[toolCall.toolName];
4359
- toolInputs.set(toolCall.toolCallId, toolCall.input);
4360
4562
  if (tool3.onInputAvailable != null) {
4361
4563
  await tool3.onInputAvailable({
4362
4564
  input: toolCall.input,
@@ -4366,79 +4568,33 @@ function runToolsTransformation({
4366
4568
  experimental_context
4367
4569
  });
4368
4570
  }
4571
+ if (tool3.needsApproval) {
4572
+ toolResultsStreamController.enqueue({
4573
+ type: "tool-approval-request",
4574
+ approvalId: generateId2(),
4575
+ toolCall
4576
+ });
4577
+ break;
4578
+ }
4579
+ toolInputs.set(toolCall.toolCallId, toolCall.input);
4369
4580
  if (tool3.execute != null && toolCall.providerExecuted !== true) {
4370
- const toolExecutionId = (0, import_provider_utils13.generateId)();
4581
+ const toolExecutionId = generateId2();
4371
4582
  outstandingToolResults.add(toolExecutionId);
4372
- recordSpan({
4373
- name: "ai.toolCall",
4374
- attributes: selectTelemetryAttributes({
4375
- telemetry,
4376
- attributes: {
4377
- ...assembleOperationName({
4378
- operationId: "ai.toolCall",
4379
- telemetry
4380
- }),
4381
- "ai.toolCall.name": toolCall.toolName,
4382
- "ai.toolCall.id": toolCall.toolCallId,
4383
- "ai.toolCall.args": {
4384
- output: () => JSON.stringify(toolCall.input)
4385
- }
4386
- }
4387
- }),
4583
+ executeToolCall({
4584
+ toolCall,
4585
+ tools,
4388
4586
  tracer,
4389
- fn: async (span) => {
4390
- let output;
4391
- try {
4392
- const stream = (0, import_provider_utils13.executeTool)({
4393
- execute: tool3.execute.bind(tool3),
4394
- input: toolCall.input,
4395
- options: {
4396
- toolCallId: toolCall.toolCallId,
4397
- messages,
4398
- abortSignal,
4399
- experimental_context
4400
- }
4401
- });
4402
- for await (const part of stream) {
4403
- toolResultsStreamController.enqueue({
4404
- ...toolCall,
4405
- type: "tool-result",
4406
- output: part.output,
4407
- ...part.type === "preliminary" && {
4408
- preliminary: true
4409
- }
4410
- });
4411
- if (part.type === "final") {
4412
- output = part.output;
4413
- }
4414
- }
4415
- } catch (error) {
4416
- recordErrorOnSpan(span, error);
4417
- toolResultsStreamController.enqueue({
4418
- ...toolCall,
4419
- type: "tool-error",
4420
- error
4421
- });
4422
- outstandingToolResults.delete(toolExecutionId);
4423
- attemptClose();
4424
- return;
4425
- }
4426
- outstandingToolResults.delete(toolExecutionId);
4427
- attemptClose();
4428
- try {
4429
- span.setAttributes(
4430
- selectTelemetryAttributes({
4431
- telemetry,
4432
- attributes: {
4433
- "ai.toolCall.result": {
4434
- output: () => JSON.stringify(output)
4435
- }
4436
- }
4437
- })
4438
- );
4439
- } catch (ignored) {
4440
- }
4587
+ telemetry,
4588
+ messages,
4589
+ abortSignal,
4590
+ experimental_context,
4591
+ onPreliminaryToolResult: (result) => {
4592
+ toolResultsStreamController.enqueue(result);
4441
4593
  }
4594
+ }).then((result) => {
4595
+ toolResultsStreamController.enqueue(result);
4596
+ outstandingToolResults.delete(toolExecutionId);
4597
+ attemptClose();
4442
4598
  });
4443
4599
  }
4444
4600
  } catch (error) {
@@ -4508,7 +4664,7 @@ function runToolsTransformation({
4508
4664
  }
4509
4665
 
4510
4666
  // src/generate-text/stream-text.ts
4511
- var originalGenerateId2 = (0, import_provider_utils14.createIdGenerator)({
4667
+ var originalGenerateId2 = (0, import_provider_utils15.createIdGenerator)({
4512
4668
  prefix: "aitxt",
4513
4669
  size: 24
4514
4670
  });
@@ -4543,7 +4699,7 @@ function streamText({
4543
4699
  experimental_context,
4544
4700
  _internal: {
4545
4701
  now: now2 = now,
4546
- generateId: generateId3 = originalGenerateId2,
4702
+ generateId: generateId2 = originalGenerateId2,
4547
4703
  currentDate = () => /* @__PURE__ */ new Date()
4548
4704
  } = {},
4549
4705
  ...settings
@@ -4575,7 +4731,7 @@ function streamText({
4575
4731
  onStepFinish,
4576
4732
  now: now2,
4577
4733
  currentDate,
4578
- generateId: generateId3,
4734
+ generateId: generateId2,
4579
4735
  experimental_context,
4580
4736
  download: download2
4581
4737
  });
@@ -4668,7 +4824,7 @@ var DefaultStreamTextResult = class {
4668
4824
  includeRawChunks,
4669
4825
  now: now2,
4670
4826
  currentDate,
4671
- generateId: generateId3,
4827
+ generateId: generateId2,
4672
4828
  onChunk,
4673
4829
  onError,
4674
4830
  onFinish,
@@ -4793,10 +4949,16 @@ var DefaultStreamTextResult = class {
4793
4949
  if (part.type === "tool-result" && !part.preliminary) {
4794
4950
  recordedContent.push(part);
4795
4951
  }
4952
+ if (part.type === "tool-approval-request") {
4953
+ recordedContent.push(part);
4954
+ }
4796
4955
  if (part.type === "tool-error") {
4797
4956
  recordedContent.push(part);
4798
4957
  }
4799
4958
  if (part.type === "start-step") {
4959
+ recordedContent = [];
4960
+ activeReasoningContent = {};
4961
+ activeTextContent = {};
4800
4962
  recordedRequest = part.request;
4801
4963
  recordedWarnings = part.warnings;
4802
4964
  }
@@ -4820,9 +4982,6 @@ var DefaultStreamTextResult = class {
4820
4982
  await (onStepFinish == null ? void 0 : onStepFinish(currentStepResult));
4821
4983
  logWarnings(recordedWarnings);
4822
4984
  recordedSteps.push(currentStepResult);
4823
- recordedContent = [];
4824
- activeReasoningContent = {};
4825
- activeTextContent = {};
4826
4985
  recordedResponseMessages.push(...stepMessages);
4827
4986
  stepFinish.resolve();
4828
4987
  }
@@ -4930,7 +5089,7 @@ var DefaultStreamTextResult = class {
4930
5089
  }
4931
5090
  controller.enqueue(value);
4932
5091
  } catch (error) {
4933
- if ((0, import_provider_utils14.isAbortError)(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
5092
+ if ((0, import_provider_utils15.isAbortError)(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
4934
5093
  abort();
4935
5094
  } else {
4936
5095
  controller.error(error);
@@ -4982,6 +5141,82 @@ var DefaultStreamTextResult = class {
4982
5141
  endWhenDone: false,
4983
5142
  fn: async (rootSpanArg) => {
4984
5143
  rootSpan = rootSpanArg;
5144
+ const initialPrompt = await standardizePrompt({
5145
+ system,
5146
+ prompt,
5147
+ messages
5148
+ });
5149
+ const initialMessages = initialPrompt.messages;
5150
+ const initialResponseMessages = [];
5151
+ const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
5152
+ if (deniedToolApprovals.length > 0 || approvedToolApprovals.length > 0) {
5153
+ let toolExecutionStepStreamController;
5154
+ const toolExecutionStepStream = new ReadableStream({
5155
+ start(controller) {
5156
+ toolExecutionStepStreamController = controller;
5157
+ }
5158
+ });
5159
+ self.addStream(toolExecutionStepStream);
5160
+ try {
5161
+ for (const toolApproval of deniedToolApprovals) {
5162
+ toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue({
5163
+ type: "tool-output-denied",
5164
+ toolCallId: toolApproval.toolCall.toolCallId,
5165
+ toolName: toolApproval.toolCall.toolName
5166
+ });
5167
+ }
5168
+ const toolOutputs = [];
5169
+ await Promise.all(
5170
+ approvedToolApprovals.map(async (toolApproval) => {
5171
+ const result = await executeToolCall({
5172
+ toolCall: toolApproval.toolCall,
5173
+ tools,
5174
+ tracer,
5175
+ telemetry,
5176
+ messages: initialMessages,
5177
+ abortSignal,
5178
+ experimental_context,
5179
+ onPreliminaryToolResult: (result2) => {
5180
+ toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue(result2);
5181
+ }
5182
+ });
5183
+ if (result != null) {
5184
+ toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue(result);
5185
+ toolOutputs.push(result);
5186
+ }
5187
+ })
5188
+ );
5189
+ initialResponseMessages.push({
5190
+ role: "tool",
5191
+ content: [
5192
+ // add regular tool results for approved tool calls:
5193
+ ...toolOutputs.map((output2) => ({
5194
+ type: "tool-result",
5195
+ toolCallId: output2.toolCallId,
5196
+ toolName: output2.toolName,
5197
+ output: createToolModelOutput({
5198
+ tool: tools == null ? void 0 : tools[output2.toolName],
5199
+ output: output2.type === "tool-result" ? output2.output : output2.error,
5200
+ errorMode: output2.type === "tool-error" ? "json" : "none"
5201
+ })
5202
+ })),
5203
+ // add execution denied tool results for denied tool approvals:
5204
+ ...deniedToolApprovals.map((toolApproval) => ({
5205
+ type: "tool-result",
5206
+ toolCallId: toolApproval.toolCall.toolCallId,
5207
+ toolName: toolApproval.toolCall.toolName,
5208
+ output: {
5209
+ type: "execution-denied",
5210
+ reason: toolApproval.approvalResponse.reason
5211
+ }
5212
+ }))
5213
+ ]
5214
+ });
5215
+ } finally {
5216
+ toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.close();
5217
+ }
5218
+ }
5219
+ recordedResponseMessages.push(...initialResponseMessages);
4985
5220
  async function streamStep({
4986
5221
  currentStep,
4987
5222
  responseMessages,
@@ -4990,15 +5225,7 @@ var DefaultStreamTextResult = class {
4990
5225
  var _a17, _b, _c, _d, _e;
4991
5226
  const includeRawChunks2 = self.includeRawChunks;
4992
5227
  stepFinish = new DelayedPromise();
4993
- const initialPrompt = await standardizePrompt({
4994
- system,
4995
- prompt,
4996
- messages
4997
- });
4998
- const stepInputMessages = [
4999
- ...initialPrompt.messages,
5000
- ...responseMessages
5001
- ];
5228
+ const stepInputMessages = [...initialMessages, ...responseMessages];
5002
5229
  const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
5003
5230
  model,
5004
5231
  steps: recordedSteps,
@@ -5064,24 +5291,22 @@ var DefaultStreamTextResult = class {
5064
5291
  }),
5065
5292
  tracer,
5066
5293
  endWhenDone: false,
5067
- fn: async (doStreamSpan2) => {
5068
- return {
5069
- startTimestampMs: now2(),
5070
- // get before the call
5071
- doStreamSpan: doStreamSpan2,
5072
- result: await stepModel.doStream({
5073
- ...callSettings,
5074
- tools: stepTools,
5075
- toolChoice: stepToolChoice,
5076
- responseFormat: output == null ? void 0 : output.responseFormat,
5077
- prompt: promptMessages,
5078
- providerOptions,
5079
- abortSignal,
5080
- headers,
5081
- includeRawChunks: includeRawChunks2
5082
- })
5083
- };
5084
- }
5294
+ fn: async (doStreamSpan2) => ({
5295
+ startTimestampMs: now2(),
5296
+ // get before the call
5297
+ doStreamSpan: doStreamSpan2,
5298
+ result: await stepModel.doStream({
5299
+ ...callSettings,
5300
+ tools: stepTools,
5301
+ toolChoice: stepToolChoice,
5302
+ responseFormat: output == null ? void 0 : output.responseFormat,
5303
+ prompt: promptMessages,
5304
+ providerOptions,
5305
+ abortSignal,
5306
+ headers,
5307
+ includeRawChunks: includeRawChunks2
5308
+ })
5309
+ })
5085
5310
  })
5086
5311
  );
5087
5312
  const streamWithToolResults = runToolsTransformation({
@@ -5093,7 +5318,8 @@ var DefaultStreamTextResult = class {
5093
5318
  messages: stepInputMessages,
5094
5319
  repairToolCall,
5095
5320
  abortSignal,
5096
- experimental_context
5321
+ experimental_context,
5322
+ generateId: generateId2
5097
5323
  });
5098
5324
  const stepRequest = request != null ? request : {};
5099
5325
  const stepToolCalls = [];
@@ -5109,7 +5335,7 @@ var DefaultStreamTextResult = class {
5109
5335
  let stepProviderMetadata;
5110
5336
  let stepFirstChunk = true;
5111
5337
  let stepResponse = {
5112
- id: generateId3(),
5338
+ id: generateId2(),
5113
5339
  timestamp: currentDate(),
5114
5340
  modelId: model.modelId
5115
5341
  };
@@ -5140,6 +5366,7 @@ var DefaultStreamTextResult = class {
5140
5366
  }
5141
5367
  const chunkType = chunk.type;
5142
5368
  switch (chunkType) {
5369
+ case "tool-approval-request":
5143
5370
  case "text-start":
5144
5371
  case "text-end": {
5145
5372
  controller.enqueue(chunk);
@@ -5368,7 +5595,7 @@ var DefaultStreamTextResult = class {
5368
5595
  }
5369
5596
  await streamStep({
5370
5597
  currentStep: 0,
5371
- responseMessages: [],
5598
+ responseMessages: initialResponseMessages,
5372
5599
  usage: {
5373
5600
  inputTokens: void 0,
5374
5601
  outputTokens: void 0,
@@ -5675,6 +5902,14 @@ var DefaultStreamTextResult = class {
5675
5902
  }
5676
5903
  break;
5677
5904
  }
5905
+ case "tool-approval-request": {
5906
+ controller.enqueue({
5907
+ type: "tool-approval-request",
5908
+ approvalId: part.approvalId,
5909
+ toolCallId: part.toolCall.toolCallId
5910
+ });
5911
+ break;
5912
+ }
5678
5913
  case "tool-result": {
5679
5914
  const dynamic = isDynamic(part.toolCallId);
5680
5915
  controller.enqueue({
@@ -5698,6 +5933,13 @@ var DefaultStreamTextResult = class {
5698
5933
  });
5699
5934
  break;
5700
5935
  }
5936
+ case "tool-output-denied": {
5937
+ controller.enqueue({
5938
+ type: "tool-output-denied",
5939
+ toolCallId: part.toolCallId
5940
+ });
5941
+ break;
5942
+ }
5701
5943
  case "error": {
5702
5944
  controller.enqueue({
5703
5945
  type: "error",
@@ -5942,6 +6184,13 @@ function convertToModelMessages(messages, options) {
5942
6184
  providerExecuted: part.providerExecuted,
5943
6185
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
5944
6186
  });
6187
+ if (part.approval != null) {
6188
+ content.push({
6189
+ type: "tool-approval-request",
6190
+ approvalId: part.approval.id,
6191
+ toolCallId: part.toolCallId
6192
+ });
6193
+ }
5945
6194
  if (part.providerExecuted === true && (part.state === "output-available" || part.state === "output-error")) {
5946
6195
  content.push({
5947
6196
  type: "tool-result",
@@ -5970,29 +6219,49 @@ function convertToModelMessages(messages, options) {
5970
6219
  if (toolParts.length > 0) {
5971
6220
  modelMessages.push({
5972
6221
  role: "tool",
5973
- content: toolParts.map((toolPart) => {
5974
- var _a18;
5975
- switch (toolPart.state) {
5976
- case "output-error":
5977
- case "output-available": {
5978
- const toolName = toolPart.type === "dynamic-tool" ? toolPart.toolName : getToolName(toolPart);
5979
- return {
5980
- type: "tool-result",
5981
- toolCallId: toolPart.toolCallId,
5982
- toolName,
5983
- output: createToolModelOutput({
5984
- output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
5985
- tool: (_a18 = options == null ? void 0 : options.tools) == null ? void 0 : _a18[toolName],
5986
- errorMode: toolPart.state === "output-error" ? "text" : "none"
5987
- })
5988
- };
6222
+ content: toolParts.flatMap(
6223
+ (toolPart) => {
6224
+ var _a18, _b2, _c;
6225
+ const outputs = [];
6226
+ if (toolPart.type !== "dynamic-tool" && ((_a18 = toolPart.approval) == null ? void 0 : _a18.approved) != null) {
6227
+ outputs.push({
6228
+ type: "tool-approval-response",
6229
+ approvalId: toolPart.approval.id,
6230
+ approved: toolPart.approval.approved,
6231
+ reason: toolPart.approval.reason
6232
+ });
5989
6233
  }
5990
- default: {
5991
- return null;
6234
+ switch (toolPart.state) {
6235
+ case "output-denied": {
6236
+ outputs.push({
6237
+ type: "tool-result",
6238
+ toolCallId: toolPart.toolCallId,
6239
+ toolName: getToolName(toolPart),
6240
+ output: {
6241
+ type: "error-text",
6242
+ value: (_b2 = toolPart.approval.reason) != null ? _b2 : "Tool execution denied."
6243
+ }
6244
+ });
6245
+ break;
6246
+ }
6247
+ case "output-error":
6248
+ case "output-available": {
6249
+ const toolName = toolPart.type === "dynamic-tool" ? toolPart.toolName : getToolName(toolPart);
6250
+ outputs.push({
6251
+ type: "tool-result",
6252
+ toolCallId: toolPart.toolCallId,
6253
+ toolName,
6254
+ output: createToolModelOutput({
6255
+ output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
6256
+ tool: (_c = options == null ? void 0 : options.tools) == null ? void 0 : _c[toolName],
6257
+ errorMode: toolPart.state === "output-error" ? "text" : "none"
6258
+ })
6259
+ });
6260
+ break;
6261
+ }
5992
6262
  }
6263
+ return outputs;
5993
6264
  }
5994
- }).filter(
5995
- (output) => output != null
5996
6265
  )
5997
6266
  });
5998
6267
  }
@@ -6069,7 +6338,7 @@ var Agent = class {
6069
6338
  };
6070
6339
 
6071
6340
  // src/embed/embed.ts
6072
- var import_provider_utils15 = require("@ai-sdk/provider-utils");
6341
+ var import_provider_utils16 = require("@ai-sdk/provider-utils");
6073
6342
  async function embed({
6074
6343
  model: modelArg,
6075
6344
  value,
@@ -6084,7 +6353,7 @@ async function embed({
6084
6353
  maxRetries: maxRetriesArg,
6085
6354
  abortSignal
6086
6355
  });
6087
- const headersWithUserAgent = (0, import_provider_utils15.withUserAgentSuffix)(
6356
+ const headersWithUserAgent = (0, import_provider_utils16.withUserAgentSuffix)(
6088
6357
  headers != null ? headers : {},
6089
6358
  `ai/${VERSION}`
6090
6359
  );
@@ -6188,7 +6457,7 @@ var DefaultEmbedResult = class {
6188
6457
  };
6189
6458
 
6190
6459
  // src/embed/embed-many.ts
6191
- var import_provider_utils16 = require("@ai-sdk/provider-utils");
6460
+ var import_provider_utils17 = require("@ai-sdk/provider-utils");
6192
6461
 
6193
6462
  // src/util/split-array.ts
6194
6463
  function splitArray(array, chunkSize) {
@@ -6218,7 +6487,7 @@ async function embedMany({
6218
6487
  maxRetries: maxRetriesArg,
6219
6488
  abortSignal
6220
6489
  });
6221
- const headersWithUserAgent = (0, import_provider_utils16.withUserAgentSuffix)(
6490
+ const headersWithUserAgent = (0, import_provider_utils17.withUserAgentSuffix)(
6222
6491
  headers != null ? headers : {},
6223
6492
  `ai/${VERSION}`
6224
6493
  );
@@ -6437,7 +6706,7 @@ var DefaultEmbedManyResult = class {
6437
6706
  };
6438
6707
 
6439
6708
  // src/generate-image/generate-image.ts
6440
- var import_provider_utils17 = require("@ai-sdk/provider-utils");
6709
+ var import_provider_utils18 = require("@ai-sdk/provider-utils");
6441
6710
  async function generateImage({
6442
6711
  model,
6443
6712
  prompt,
@@ -6459,7 +6728,7 @@ async function generateImage({
6459
6728
  modelId: model.modelId
6460
6729
  });
6461
6730
  }
6462
- const headersWithUserAgent = (0, import_provider_utils17.withUserAgentSuffix)(
6731
+ const headersWithUserAgent = (0, import_provider_utils18.withUserAgentSuffix)(
6463
6732
  headers != null ? headers : {},
6464
6733
  `ai/${VERSION}`
6465
6734
  );
@@ -6555,7 +6824,7 @@ async function invokeModelMaxImagesPerCall(model) {
6555
6824
  }
6556
6825
 
6557
6826
  // src/generate-object/generate-object.ts
6558
- var import_provider_utils20 = require("@ai-sdk/provider-utils");
6827
+ var import_provider_utils21 = require("@ai-sdk/provider-utils");
6559
6828
 
6560
6829
  // src/generate-text/extract-reasoning-content.ts
6561
6830
  function extractReasoningContent(content) {
@@ -6567,7 +6836,7 @@ function extractReasoningContent(content) {
6567
6836
 
6568
6837
  // src/generate-object/output-strategy.ts
6569
6838
  var import_provider25 = require("@ai-sdk/provider");
6570
- var import_provider_utils18 = require("@ai-sdk/provider-utils");
6839
+ var import_provider_utils19 = require("@ai-sdk/provider-utils");
6571
6840
  var noSchemaOutputStrategy = {
6572
6841
  type: "no-schema",
6573
6842
  jsonSchema: void 0,
@@ -6606,7 +6875,7 @@ var objectOutputStrategy = (schema) => ({
6606
6875
  };
6607
6876
  },
6608
6877
  async validateFinalResult(value) {
6609
- return (0, import_provider_utils18.safeValidateTypes)({ value, schema });
6878
+ return (0, import_provider_utils19.safeValidateTypes)({ value, schema });
6610
6879
  },
6611
6880
  createElementStream() {
6612
6881
  throw new import_provider25.UnsupportedFunctionalityError({
@@ -6650,7 +6919,7 @@ var arrayOutputStrategy = (schema) => {
6650
6919
  const resultArray = [];
6651
6920
  for (let i = 0; i < inputArray.length; i++) {
6652
6921
  const element = inputArray[i];
6653
- const result = await (0, import_provider_utils18.safeValidateTypes)({ value: element, schema });
6922
+ const result = await (0, import_provider_utils19.safeValidateTypes)({ value: element, schema });
6654
6923
  if (i === inputArray.length - 1 && !isFinalDelta) {
6655
6924
  continue;
6656
6925
  }
@@ -6691,7 +6960,7 @@ var arrayOutputStrategy = (schema) => {
6691
6960
  }
6692
6961
  const inputArray = value.elements;
6693
6962
  for (const element of inputArray) {
6694
- const result = await (0, import_provider_utils18.safeValidateTypes)({ value: element, schema });
6963
+ const result = await (0, import_provider_utils19.safeValidateTypes)({ value: element, schema });
6695
6964
  if (!result.success) {
6696
6965
  return result;
6697
6966
  }
@@ -6809,9 +7078,9 @@ function getOutputStrategy({
6809
7078
  }) {
6810
7079
  switch (output) {
6811
7080
  case "object":
6812
- return objectOutputStrategy((0, import_provider_utils18.asSchema)(schema));
7081
+ return objectOutputStrategy((0, import_provider_utils19.asSchema)(schema));
6813
7082
  case "array":
6814
- return arrayOutputStrategy((0, import_provider_utils18.asSchema)(schema));
7083
+ return arrayOutputStrategy((0, import_provider_utils19.asSchema)(schema));
6815
7084
  case "enum":
6816
7085
  return enumOutputStrategy(enumValues);
6817
7086
  case "no-schema":
@@ -6825,9 +7094,9 @@ function getOutputStrategy({
6825
7094
 
6826
7095
  // src/generate-object/parse-and-validate-object-result.ts
6827
7096
  var import_provider26 = require("@ai-sdk/provider");
6828
- var import_provider_utils19 = require("@ai-sdk/provider-utils");
7097
+ var import_provider_utils20 = require("@ai-sdk/provider-utils");
6829
7098
  async function parseAndValidateObjectResult(result, outputStrategy, context) {
6830
- const parseResult = await (0, import_provider_utils19.safeParseJSON)({ text: result });
7099
+ const parseResult = await (0, import_provider_utils20.safeParseJSON)({ text: result });
6831
7100
  if (!parseResult.success) {
6832
7101
  throw new NoObjectGeneratedError({
6833
7102
  message: "No object generated: could not parse the response.",
@@ -6999,7 +7268,7 @@ function validateObjectGenerationInput({
6999
7268
  }
7000
7269
 
7001
7270
  // src/generate-object/generate-object.ts
7002
- var originalGenerateId3 = (0, import_provider_utils20.createIdGenerator)({ prefix: "aiobj", size: 24 });
7271
+ var originalGenerateId3 = (0, import_provider_utils21.createIdGenerator)({ prefix: "aiobj", size: 24 });
7003
7272
  async function generateObject(options) {
7004
7273
  const {
7005
7274
  model: modelArg,
@@ -7015,7 +7284,7 @@ async function generateObject(options) {
7015
7284
  experimental_download: download2,
7016
7285
  providerOptions,
7017
7286
  _internal: {
7018
- generateId: generateId3 = originalGenerateId3,
7287
+ generateId: generateId2 = originalGenerateId3,
7019
7288
  currentDate = () => /* @__PURE__ */ new Date()
7020
7289
  } = {},
7021
7290
  ...settings
@@ -7044,7 +7313,7 @@ async function generateObject(options) {
7044
7313
  enumValues
7045
7314
  });
7046
7315
  const callSettings = prepareCallSettings(settings);
7047
- const headersWithUserAgent = (0, import_provider_utils20.withUserAgentSuffix)(
7316
+ const headersWithUserAgent = (0, import_provider_utils21.withUserAgentSuffix)(
7048
7317
  headers != null ? headers : {},
7049
7318
  `ai/${VERSION}`
7050
7319
  );
@@ -7139,7 +7408,7 @@ async function generateObject(options) {
7139
7408
  headers: headersWithUserAgent
7140
7409
  });
7141
7410
  const responseData = {
7142
- id: (_b = (_a18 = result2.response) == null ? void 0 : _a18.id) != null ? _b : generateId3(),
7411
+ id: (_b = (_a18 = result2.response) == null ? void 0 : _a18.id) != null ? _b : generateId2(),
7143
7412
  timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
7144
7413
  modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId,
7145
7414
  headers: (_g = result2.response) == null ? void 0 : _g.headers,
@@ -7263,7 +7532,7 @@ var DefaultGenerateObjectResult = class {
7263
7532
  };
7264
7533
 
7265
7534
  // src/generate-object/stream-object.ts
7266
- var import_provider_utils22 = require("@ai-sdk/provider-utils");
7535
+ var import_provider_utils23 = require("@ai-sdk/provider-utils");
7267
7536
 
7268
7537
  // src/util/cosine-similarity.ts
7269
7538
  function cosineSimilarity(vector1, vector2) {
@@ -7373,7 +7642,7 @@ var SerialJobExecutor = class {
7373
7642
  };
7374
7643
 
7375
7644
  // src/util/simulate-readable-stream.ts
7376
- var import_provider_utils21 = require("@ai-sdk/provider-utils");
7645
+ var import_provider_utils22 = require("@ai-sdk/provider-utils");
7377
7646
  function simulateReadableStream({
7378
7647
  chunks,
7379
7648
  initialDelayInMs = 0,
@@ -7381,7 +7650,7 @@ function simulateReadableStream({
7381
7650
  _internal
7382
7651
  }) {
7383
7652
  var _a17;
7384
- const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 : import_provider_utils21.delay;
7653
+ const delay2 = (_a17 = _internal == null ? void 0 : _internal.delay) != null ? _a17 : import_provider_utils22.delay;
7385
7654
  let index = 0;
7386
7655
  return new ReadableStream({
7387
7656
  async pull(controller) {
@@ -7396,7 +7665,7 @@ function simulateReadableStream({
7396
7665
  }
7397
7666
 
7398
7667
  // src/generate-object/stream-object.ts
7399
- var originalGenerateId4 = (0, import_provider_utils22.createIdGenerator)({ prefix: "aiobj", size: 24 });
7668
+ var originalGenerateId4 = (0, import_provider_utils23.createIdGenerator)({ prefix: "aiobj", size: 24 });
7400
7669
  function streamObject(options) {
7401
7670
  const {
7402
7671
  model,
@@ -7416,7 +7685,7 @@ function streamObject(options) {
7416
7685
  },
7417
7686
  onFinish,
7418
7687
  _internal: {
7419
- generateId: generateId3 = originalGenerateId4,
7688
+ generateId: generateId2 = originalGenerateId4,
7420
7689
  currentDate = () => /* @__PURE__ */ new Date(),
7421
7690
  now: now2 = now
7422
7691
  } = {},
@@ -7458,7 +7727,7 @@ function streamObject(options) {
7458
7727
  onError,
7459
7728
  onFinish,
7460
7729
  download: download2,
7461
- generateId: generateId3,
7730
+ generateId: generateId2,
7462
7731
  currentDate,
7463
7732
  now: now2
7464
7733
  });
@@ -7482,7 +7751,7 @@ var DefaultStreamObjectResult = class {
7482
7751
  onError,
7483
7752
  onFinish,
7484
7753
  download: download2,
7485
- generateId: generateId3,
7754
+ generateId: generateId2,
7486
7755
  currentDate,
7487
7756
  now: now2
7488
7757
  }) {
@@ -7630,7 +7899,7 @@ var DefaultStreamObjectResult = class {
7630
7899
  let accumulatedText = "";
7631
7900
  let textDelta = "";
7632
7901
  let fullResponse = {
7633
- id: generateId3(),
7902
+ id: generateId2(),
7634
7903
  timestamp: currentDate(),
7635
7904
  modelId: model.modelId
7636
7905
  };
@@ -7917,7 +8186,7 @@ var DefaultStreamObjectResult = class {
7917
8186
  };
7918
8187
 
7919
8188
  // src/generate-speech/generate-speech.ts
7920
- var import_provider_utils23 = require("@ai-sdk/provider-utils");
8189
+ var import_provider_utils24 = require("@ai-sdk/provider-utils");
7921
8190
 
7922
8191
  // src/generate-speech/generated-audio-file.ts
7923
8192
  var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
@@ -7959,14 +8228,14 @@ async function generateSpeech({
7959
8228
  headers
7960
8229
  }) {
7961
8230
  var _a17;
7962
- if (model.specificationVersion !== "v2") {
8231
+ if (model.specificationVersion !== "v3") {
7963
8232
  throw new UnsupportedModelVersionError({
7964
8233
  version: model.specificationVersion,
7965
8234
  provider: model.provider,
7966
8235
  modelId: model.modelId
7967
8236
  });
7968
8237
  }
7969
- const headersWithUserAgent = (0, import_provider_utils23.withUserAgentSuffix)(
8238
+ const headersWithUserAgent = (0, import_provider_utils24.withUserAgentSuffix)(
7970
8239
  headers != null ? headers : {},
7971
8240
  `ai/${VERSION}`
7972
8241
  );
@@ -8020,7 +8289,7 @@ __export(output_exports, {
8020
8289
  object: () => object,
8021
8290
  text: () => text
8022
8291
  });
8023
- var import_provider_utils24 = require("@ai-sdk/provider-utils");
8292
+ var import_provider_utils25 = require("@ai-sdk/provider-utils");
8024
8293
  var text = () => ({
8025
8294
  type: "text",
8026
8295
  responseFormat: { type: "text" },
@@ -8034,7 +8303,7 @@ var text = () => ({
8034
8303
  var object = ({
8035
8304
  schema: inputSchema
8036
8305
  }) => {
8037
- const schema = (0, import_provider_utils24.asSchema)(inputSchema);
8306
+ const schema = (0, import_provider_utils25.asSchema)(inputSchema);
8038
8307
  return {
8039
8308
  type: "object",
8040
8309
  responseFormat: {
@@ -8060,7 +8329,7 @@ var object = ({
8060
8329
  }
8061
8330
  },
8062
8331
  async parseOutput({ text: text2 }, context) {
8063
- const parseResult = await (0, import_provider_utils24.safeParseJSON)({ text: text2 });
8332
+ const parseResult = await (0, import_provider_utils25.safeParseJSON)({ text: text2 });
8064
8333
  if (!parseResult.success) {
8065
8334
  throw new NoObjectGeneratedError({
8066
8335
  message: "No object generated: could not parse the response.",
@@ -8071,7 +8340,7 @@ var object = ({
8071
8340
  finishReason: context.finishReason
8072
8341
  });
8073
8342
  }
8074
- const validationResult = await (0, import_provider_utils24.safeValidateTypes)({
8343
+ const validationResult = await (0, import_provider_utils25.safeValidateTypes)({
8075
8344
  value: parseResult.value,
8076
8345
  schema
8077
8346
  });
@@ -8091,7 +8360,7 @@ var object = ({
8091
8360
  };
8092
8361
 
8093
8362
  // src/generate-text/smooth-stream.ts
8094
- var import_provider_utils25 = require("@ai-sdk/provider-utils");
8363
+ var import_provider_utils26 = require("@ai-sdk/provider-utils");
8095
8364
  var import_provider27 = require("@ai-sdk/provider");
8096
8365
  var CHUNKING_REGEXPS = {
8097
8366
  word: /\S+\s+/m,
@@ -8100,7 +8369,7 @@ var CHUNKING_REGEXPS = {
8100
8369
  function smoothStream({
8101
8370
  delayInMs = 10,
8102
8371
  chunking = "word",
8103
- _internal: { delay: delay2 = import_provider_utils25.delay } = {}
8372
+ _internal: { delay: delay2 = import_provider_utils26.delay } = {}
8104
8373
  } = {}) {
8105
8374
  let detectChunk;
8106
8375
  if (typeof chunking === "function") {
@@ -8699,10 +8968,10 @@ var DefaultProviderRegistry = class {
8699
8968
  };
8700
8969
 
8701
8970
  // src/tool/mcp/mcp-client.ts
8702
- var import_provider_utils27 = require("@ai-sdk/provider-utils");
8971
+ var import_provider_utils28 = require("@ai-sdk/provider-utils");
8703
8972
 
8704
8973
  // src/tool/mcp/mcp-sse-transport.ts
8705
- var import_provider_utils26 = require("@ai-sdk/provider-utils");
8974
+ var import_provider_utils27 = require("@ai-sdk/provider-utils");
8706
8975
 
8707
8976
  // src/tool/mcp/json-rpc-message.ts
8708
8977
  var import_v49 = require("zod/v4");
@@ -8861,13 +9130,13 @@ var SseMCPTransport = class {
8861
9130
  const establishConnection = async () => {
8862
9131
  var _a17, _b, _c;
8863
9132
  try {
8864
- const headers = (0, import_provider_utils26.withUserAgentSuffix)(
9133
+ const headers = (0, import_provider_utils27.withUserAgentSuffix)(
8865
9134
  {
8866
9135
  ...this.headers,
8867
9136
  Accept: "text/event-stream"
8868
9137
  },
8869
9138
  `ai-sdk/${VERSION}`,
8870
- (0, import_provider_utils26.getRuntimeEnvironmentUserAgent)()
9139
+ (0, import_provider_utils27.getRuntimeEnvironmentUserAgent)()
8871
9140
  );
8872
9141
  const response = await fetch(this.url.href, {
8873
9142
  headers,
@@ -8880,7 +9149,7 @@ var SseMCPTransport = class {
8880
9149
  (_b = this.onerror) == null ? void 0 : _b.call(this, error);
8881
9150
  return reject(error);
8882
9151
  }
8883
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils26.EventSourceParserStream());
9152
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils27.EventSourceParserStream());
8884
9153
  const reader = stream.getReader();
8885
9154
  const processEvents = async () => {
8886
9155
  var _a18, _b2, _c2;
@@ -8959,13 +9228,13 @@ var SseMCPTransport = class {
8959
9228
  });
8960
9229
  }
8961
9230
  try {
8962
- const headers = (0, import_provider_utils26.withUserAgentSuffix)(
9231
+ const headers = (0, import_provider_utils27.withUserAgentSuffix)(
8963
9232
  {
8964
9233
  ...this.headers,
8965
9234
  "Content-Type": "application/json"
8966
9235
  },
8967
9236
  `ai-sdk/${VERSION}`,
8968
- (0, import_provider_utils26.getRuntimeEnvironmentUserAgent)()
9237
+ (0, import_provider_utils27.getRuntimeEnvironmentUserAgent)()
8969
9238
  );
8970
9239
  const init = {
8971
9240
  method: "POST",
@@ -9216,15 +9485,15 @@ var DefaultMCPClient = class {
9216
9485
  (_a18 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a18.throwIfAborted();
9217
9486
  return self.callTool({ name: name17, args, options });
9218
9487
  };
9219
- const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils27.dynamicTool)({
9488
+ const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils28.dynamicTool)({
9220
9489
  description,
9221
- inputSchema: (0, import_provider_utils27.jsonSchema)({
9490
+ inputSchema: (0, import_provider_utils28.jsonSchema)({
9222
9491
  ...inputSchema,
9223
9492
  properties: (_a17 = inputSchema.properties) != null ? _a17 : {},
9224
9493
  additionalProperties: false
9225
9494
  }),
9226
9495
  execute
9227
- }) : (0, import_provider_utils27.tool)({
9496
+ }) : (0, import_provider_utils28.tool)({
9228
9497
  description,
9229
9498
  inputSchema: schemas[name17].inputSchema,
9230
9499
  execute
@@ -9274,7 +9543,7 @@ var DefaultMCPClient = class {
9274
9543
  };
9275
9544
 
9276
9545
  // src/transcribe/transcribe.ts
9277
- var import_provider_utils28 = require("@ai-sdk/provider-utils");
9546
+ var import_provider_utils29 = require("@ai-sdk/provider-utils");
9278
9547
 
9279
9548
  // src/error/no-transcript-generated-error.ts
9280
9549
  var import_provider31 = require("@ai-sdk/provider");
@@ -9297,7 +9566,7 @@ async function transcribe({
9297
9566
  abortSignal,
9298
9567
  headers
9299
9568
  }) {
9300
- if (model.specificationVersion !== "v2") {
9569
+ if (model.specificationVersion !== "v3") {
9301
9570
  throw new UnsupportedModelVersionError({
9302
9571
  version: model.specificationVersion,
9303
9572
  provider: model.provider,
@@ -9308,7 +9577,7 @@ async function transcribe({
9308
9577
  maxRetries: maxRetriesArg,
9309
9578
  abortSignal
9310
9579
  });
9311
- const headersWithUserAgent = (0, import_provider_utils28.withUserAgentSuffix)(
9580
+ const headersWithUserAgent = (0, import_provider_utils29.withUserAgentSuffix)(
9312
9581
  headers != null ? headers : {},
9313
9582
  `ai/${VERSION}`
9314
9583
  );
@@ -9356,7 +9625,7 @@ var DefaultTranscriptionResult = class {
9356
9625
  };
9357
9626
 
9358
9627
  // src/ui/call-completion-api.ts
9359
- var import_provider_utils29 = require("@ai-sdk/provider-utils");
9628
+ var import_provider_utils30 = require("@ai-sdk/provider-utils");
9360
9629
 
9361
9630
  // src/ui/process-text-stream.ts
9362
9631
  async function processTextStream({
@@ -9404,13 +9673,13 @@ async function callCompletionApi({
9404
9673
  ...body
9405
9674
  }),
9406
9675
  credentials,
9407
- headers: (0, import_provider_utils29.withUserAgentSuffix)(
9676
+ headers: (0, import_provider_utils30.withUserAgentSuffix)(
9408
9677
  {
9409
9678
  "Content-Type": "application/json",
9410
9679
  ...headers
9411
9680
  },
9412
9681
  `ai-sdk/${VERSION}`,
9413
- (0, import_provider_utils29.getRuntimeEnvironmentUserAgent)()
9682
+ (0, import_provider_utils30.getRuntimeEnvironmentUserAgent)()
9414
9683
  ),
9415
9684
  signal: abortController.signal
9416
9685
  }).catch((err) => {
@@ -9438,7 +9707,7 @@ async function callCompletionApi({
9438
9707
  }
9439
9708
  case "data": {
9440
9709
  await consumeStream({
9441
- stream: (0, import_provider_utils29.parseJsonEventStream)({
9710
+ stream: (0, import_provider_utils30.parseJsonEventStream)({
9442
9711
  stream: response.body,
9443
9712
  schema: uiMessageChunkSchema
9444
9713
  }).pipeThrough(
@@ -9490,7 +9759,7 @@ async function callCompletionApi({
9490
9759
  }
9491
9760
 
9492
9761
  // src/ui/chat.ts
9493
- var import_provider_utils32 = require("@ai-sdk/provider-utils");
9762
+ var import_provider_utils33 = require("@ai-sdk/provider-utils");
9494
9763
 
9495
9764
  // src/ui/convert-file-list-to-file-ui-parts.ts
9496
9765
  async function convertFileListToFileUIParts(files) {
@@ -9523,10 +9792,10 @@ async function convertFileListToFileUIParts(files) {
9523
9792
  }
9524
9793
 
9525
9794
  // src/ui/default-chat-transport.ts
9526
- var import_provider_utils31 = require("@ai-sdk/provider-utils");
9795
+ var import_provider_utils32 = require("@ai-sdk/provider-utils");
9527
9796
 
9528
9797
  // src/ui/http-chat-transport.ts
9529
- var import_provider_utils30 = require("@ai-sdk/provider-utils");
9798
+ var import_provider_utils31 = require("@ai-sdk/provider-utils");
9530
9799
  var HttpChatTransport = class {
9531
9800
  constructor({
9532
9801
  api = "/api/chat",
@@ -9550,9 +9819,9 @@ var HttpChatTransport = class {
9550
9819
  ...options
9551
9820
  }) {
9552
9821
  var _a17, _b, _c, _d, _e;
9553
- const resolvedBody = await (0, import_provider_utils30.resolve)(this.body);
9554
- const resolvedHeaders = await (0, import_provider_utils30.resolve)(this.headers);
9555
- const resolvedCredentials = await (0, import_provider_utils30.resolve)(this.credentials);
9822
+ const resolvedBody = await (0, import_provider_utils31.resolve)(this.body);
9823
+ const resolvedHeaders = await (0, import_provider_utils31.resolve)(this.headers);
9824
+ const resolvedCredentials = await (0, import_provider_utils31.resolve)(this.credentials);
9556
9825
  const preparedRequest = await ((_a17 = this.prepareSendMessagesRequest) == null ? void 0 : _a17.call(this, {
9557
9826
  api: this.api,
9558
9827
  id: options.chatId,
@@ -9578,13 +9847,13 @@ var HttpChatTransport = class {
9578
9847
  const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
9579
9848
  const response = await fetch2(api, {
9580
9849
  method: "POST",
9581
- headers: (0, import_provider_utils30.withUserAgentSuffix)(
9850
+ headers: (0, import_provider_utils31.withUserAgentSuffix)(
9582
9851
  {
9583
9852
  "Content-Type": "application/json",
9584
9853
  ...headers
9585
9854
  },
9586
9855
  `ai-sdk/${VERSION}`,
9587
- (0, import_provider_utils30.getRuntimeEnvironmentUserAgent)()
9856
+ (0, import_provider_utils31.getRuntimeEnvironmentUserAgent)()
9588
9857
  ),
9589
9858
  body: JSON.stringify(body),
9590
9859
  credentials,
@@ -9602,9 +9871,9 @@ var HttpChatTransport = class {
9602
9871
  }
9603
9872
  async reconnectToStream(options) {
9604
9873
  var _a17, _b, _c, _d, _e;
9605
- const resolvedBody = await (0, import_provider_utils30.resolve)(this.body);
9606
- const resolvedHeaders = await (0, import_provider_utils30.resolve)(this.headers);
9607
- const resolvedCredentials = await (0, import_provider_utils30.resolve)(this.credentials);
9874
+ const resolvedBody = await (0, import_provider_utils31.resolve)(this.body);
9875
+ const resolvedHeaders = await (0, import_provider_utils31.resolve)(this.headers);
9876
+ const resolvedCredentials = await (0, import_provider_utils31.resolve)(this.credentials);
9608
9877
  const preparedRequest = await ((_a17 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a17.call(this, {
9609
9878
  api: this.api,
9610
9879
  id: options.chatId,
@@ -9619,10 +9888,10 @@ var HttpChatTransport = class {
9619
9888
  const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
9620
9889
  const response = await fetch2(api, {
9621
9890
  method: "GET",
9622
- headers: (0, import_provider_utils30.withUserAgentSuffix)(
9891
+ headers: (0, import_provider_utils31.withUserAgentSuffix)(
9623
9892
  headers,
9624
9893
  `ai-sdk/${VERSION}`,
9625
- (0, import_provider_utils30.getRuntimeEnvironmentUserAgent)()
9894
+ (0, import_provider_utils31.getRuntimeEnvironmentUserAgent)()
9626
9895
  ),
9627
9896
  credentials
9628
9897
  });
@@ -9647,7 +9916,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
9647
9916
  super(options);
9648
9917
  }
9649
9918
  processResponseStream(stream) {
9650
- return (0, import_provider_utils31.parseJsonEventStream)({
9919
+ return (0, import_provider_utils32.parseJsonEventStream)({
9651
9920
  stream,
9652
9921
  schema: uiMessageChunkSchema
9653
9922
  }).pipeThrough(
@@ -9666,8 +9935,8 @@ var DefaultChatTransport = class extends HttpChatTransport {
9666
9935
  // src/ui/chat.ts
9667
9936
  var AbstractChat = class {
9668
9937
  constructor({
9669
- generateId: generateId3 = import_provider_utils32.generateId,
9670
- id = generateId3(),
9938
+ generateId: generateId2 = import_provider_utils33.generateId,
9939
+ id = generateId2(),
9671
9940
  transport = new DefaultChatTransport(),
9672
9941
  messageMetadataSchema,
9673
9942
  dataPartSchemas,
@@ -9779,6 +10048,33 @@ var AbstractChat = class {
9779
10048
  this.setStatus({ status: "ready" });
9780
10049
  }
9781
10050
  };
10051
+ this.addToolApprovalResponse = async ({
10052
+ id,
10053
+ approved,
10054
+ reason
10055
+ }) => this.jobExecutor.run(async () => {
10056
+ var _a17, _b;
10057
+ const messages = this.state.messages;
10058
+ const lastMessage = messages[messages.length - 1];
10059
+ const updatePart = (part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id ? {
10060
+ ...part,
10061
+ state: "approval-responded",
10062
+ approval: { id, approved, reason }
10063
+ } : part;
10064
+ this.state.replaceMessage(messages.length - 1, {
10065
+ ...lastMessage,
10066
+ parts: lastMessage.parts.map(updatePart)
10067
+ });
10068
+ if (this.activeResponse) {
10069
+ this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
10070
+ }
10071
+ if (this.status !== "streaming" && this.status !== "submitted" && ((_a17 = this.sendAutomaticallyWhen) == null ? void 0 : _a17.call(this, { messages: this.state.messages }))) {
10072
+ this.makeRequest({
10073
+ trigger: "submit-message",
10074
+ messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
10075
+ });
10076
+ }
10077
+ });
9782
10078
  this.addToolResult = async ({
9783
10079
  state = "output-available",
9784
10080
  tool: tool3,
@@ -9789,21 +10085,13 @@ var AbstractChat = class {
9789
10085
  var _a17, _b;
9790
10086
  const messages = this.state.messages;
9791
10087
  const lastMessage = messages[messages.length - 1];
10088
+ const updatePart = (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part;
9792
10089
  this.state.replaceMessage(messages.length - 1, {
9793
10090
  ...lastMessage,
9794
- parts: lastMessage.parts.map(
9795
- (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state, output, errorText } : part
9796
- )
10091
+ parts: lastMessage.parts.map(updatePart)
9797
10092
  });
9798
10093
  if (this.activeResponse) {
9799
- this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
9800
- (part) => isToolOrDynamicToolUIPart(part) && part.toolCallId === toolCallId ? {
9801
- ...part,
9802
- state,
9803
- output,
9804
- errorText
9805
- } : part
9806
- );
10094
+ this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
9807
10095
  }
9808
10096
  if (this.status !== "streaming" && this.status !== "submitted" && ((_a17 = this.sendAutomaticallyWhen) == null ? void 0 : _a17.call(this, { messages: this.state.messages }))) {
9809
10097
  this.makeRequest({
@@ -9825,7 +10113,7 @@ var AbstractChat = class {
9825
10113
  };
9826
10114
  this.id = id;
9827
10115
  this.transport = transport;
9828
- this.generateId = generateId3;
10116
+ this.generateId = generateId2;
9829
10117
  this.messageMetadataSchema = messageMetadataSchema;
9830
10118
  this.dataPartSchemas = dataPartSchemas;
9831
10119
  this.state = state;
@@ -9995,6 +10283,30 @@ var AbstractChat = class {
9995
10283
  }
9996
10284
  };
9997
10285
 
10286
+ // src/ui/last-assistant-message-is-complete-with-approval-responses.ts
10287
+ function lastAssistantMessageIsCompleteWithApprovalResponses({
10288
+ messages
10289
+ }) {
10290
+ const message = messages[messages.length - 1];
10291
+ if (!message) {
10292
+ return false;
10293
+ }
10294
+ if (message.role !== "assistant") {
10295
+ return false;
10296
+ }
10297
+ const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
10298
+ return part.type === "step-start" ? index : lastIndex;
10299
+ }, -1);
10300
+ const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolOrDynamicToolUIPart);
10301
+ return (
10302
+ // has at least one tool approval response
10303
+ lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
10304
+ lastStepToolInvocations.every(
10305
+ (part) => part.state === "output-available" || part.state === "output-error" || part.state === "approval-responded"
10306
+ )
10307
+ );
10308
+ }
10309
+
9998
10310
  // src/ui/last-assistant-message-is-complete-with-tool-calls.ts
9999
10311
  function lastAssistantMessageIsCompleteWithToolCalls({
10000
10312
  messages
@@ -10052,7 +10364,7 @@ var TextStreamChatTransport = class extends HttpChatTransport {
10052
10364
 
10053
10365
  // src/ui/validate-ui-messages.ts
10054
10366
  var import_provider32 = require("@ai-sdk/provider");
10055
- var import_provider_utils33 = require("@ai-sdk/provider-utils");
10367
+ var import_provider_utils34 = require("@ai-sdk/provider-utils");
10056
10368
  var import_v410 = require("zod/v4");
10057
10369
  var textUIPartSchema = import_v410.z.object({
10058
10370
  type: import_v410.z.literal("text"),
@@ -10146,7 +10458,8 @@ var toolUIPartSchemas = [
10146
10458
  providerExecuted: import_v410.z.boolean().optional(),
10147
10459
  input: import_v410.z.unknown().optional(),
10148
10460
  output: import_v410.z.never().optional(),
10149
- errorText: import_v410.z.never().optional()
10461
+ errorText: import_v410.z.never().optional(),
10462
+ approval: import_v410.z.never().optional()
10150
10463
  }),
10151
10464
  import_v410.z.object({
10152
10465
  type: import_v410.z.string().startsWith("tool-"),
@@ -10156,7 +10469,38 @@ var toolUIPartSchemas = [
10156
10469
  input: import_v410.z.unknown(),
10157
10470
  output: import_v410.z.never().optional(),
10158
10471
  errorText: import_v410.z.never().optional(),
10159
- callProviderMetadata: providerMetadataSchema.optional()
10472
+ callProviderMetadata: providerMetadataSchema.optional(),
10473
+ approval: import_v410.z.never().optional()
10474
+ }),
10475
+ import_v410.z.object({
10476
+ type: import_v410.z.string().startsWith("tool-"),
10477
+ toolCallId: import_v410.z.string(),
10478
+ state: import_v410.z.literal("approval-requested"),
10479
+ input: import_v410.z.unknown(),
10480
+ providerExecuted: import_v410.z.boolean().optional(),
10481
+ output: import_v410.z.never().optional(),
10482
+ errorText: import_v410.z.never().optional(),
10483
+ callProviderMetadata: providerMetadataSchema.optional(),
10484
+ approval: import_v410.z.object({
10485
+ id: import_v410.z.string(),
10486
+ approved: import_v410.z.never().optional(),
10487
+ reason: import_v410.z.never().optional()
10488
+ })
10489
+ }),
10490
+ import_v410.z.object({
10491
+ type: import_v410.z.string().startsWith("tool-"),
10492
+ toolCallId: import_v410.z.string(),
10493
+ state: import_v410.z.literal("approval-responded"),
10494
+ input: import_v410.z.unknown(),
10495
+ providerExecuted: import_v410.z.boolean().optional(),
10496
+ output: import_v410.z.never().optional(),
10497
+ errorText: import_v410.z.never().optional(),
10498
+ callProviderMetadata: providerMetadataSchema.optional(),
10499
+ approval: import_v410.z.object({
10500
+ id: import_v410.z.string(),
10501
+ approved: import_v410.z.boolean(),
10502
+ reason: import_v410.z.string().optional()
10503
+ })
10160
10504
  }),
10161
10505
  import_v410.z.object({
10162
10506
  type: import_v410.z.string().startsWith("tool-"),
@@ -10167,7 +10511,12 @@ var toolUIPartSchemas = [
10167
10511
  output: import_v410.z.unknown(),
10168
10512
  errorText: import_v410.z.never().optional(),
10169
10513
  callProviderMetadata: providerMetadataSchema.optional(),
10170
- preliminary: import_v410.z.boolean().optional()
10514
+ preliminary: import_v410.z.boolean().optional(),
10515
+ approval: import_v410.z.object({
10516
+ id: import_v410.z.string(),
10517
+ approved: import_v410.z.literal(true),
10518
+ reason: import_v410.z.string().optional()
10519
+ }).optional()
10171
10520
  }),
10172
10521
  import_v410.z.object({
10173
10522
  type: import_v410.z.string().startsWith("tool-"),
@@ -10177,7 +10526,27 @@ var toolUIPartSchemas = [
10177
10526
  input: import_v410.z.unknown(),
10178
10527
  output: import_v410.z.never().optional(),
10179
10528
  errorText: import_v410.z.string(),
10180
- callProviderMetadata: providerMetadataSchema.optional()
10529
+ callProviderMetadata: providerMetadataSchema.optional(),
10530
+ approval: import_v410.z.object({
10531
+ id: import_v410.z.string(),
10532
+ approved: import_v410.z.literal(true),
10533
+ reason: import_v410.z.string().optional()
10534
+ }).optional()
10535
+ }),
10536
+ import_v410.z.object({
10537
+ type: import_v410.z.string().startsWith("tool-"),
10538
+ toolCallId: import_v410.z.string(),
10539
+ state: import_v410.z.literal("output-denied"),
10540
+ providerExecuted: import_v410.z.boolean().optional(),
10541
+ input: import_v410.z.unknown(),
10542
+ output: import_v410.z.never().optional(),
10543
+ errorText: import_v410.z.never().optional(),
10544
+ callProviderMetadata: providerMetadataSchema.optional(),
10545
+ approval: import_v410.z.object({
10546
+ id: import_v410.z.string(),
10547
+ approved: import_v410.z.literal(false),
10548
+ reason: import_v410.z.string().optional()
10549
+ })
10181
10550
  })
10182
10551
  ];
10183
10552
  var uiMessageSchema = import_v410.z.object({
@@ -10215,13 +10584,13 @@ async function safeValidateUIMessages({
10215
10584
  })
10216
10585
  };
10217
10586
  }
10218
- const validatedMessages = await (0, import_provider_utils33.validateTypes)({
10587
+ const validatedMessages = await (0, import_provider_utils34.validateTypes)({
10219
10588
  value: messages,
10220
10589
  schema: import_v410.z.array(uiMessageSchema)
10221
10590
  });
10222
10591
  if (metadataSchema) {
10223
10592
  for (const message of validatedMessages) {
10224
- await (0, import_provider_utils33.validateTypes)({
10593
+ await (0, import_provider_utils34.validateTypes)({
10225
10594
  value: message.metadata,
10226
10595
  schema: metadataSchema
10227
10596
  });
@@ -10244,7 +10613,7 @@ async function safeValidateUIMessages({
10244
10613
  })
10245
10614
  };
10246
10615
  }
10247
- await (0, import_provider_utils33.validateTypes)({
10616
+ await (0, import_provider_utils34.validateTypes)({
10248
10617
  value: dataPart.data,
10249
10618
  schema: dataSchema
10250
10619
  });
@@ -10269,13 +10638,13 @@ async function safeValidateUIMessages({
10269
10638
  };
10270
10639
  }
10271
10640
  if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
10272
- await (0, import_provider_utils33.validateTypes)({
10641
+ await (0, import_provider_utils34.validateTypes)({
10273
10642
  value: toolPart.input,
10274
10643
  schema: tool3.inputSchema
10275
10644
  });
10276
10645
  }
10277
10646
  if (toolPart.state === "output-available" && tool3.outputSchema) {
10278
- await (0, import_provider_utils33.validateTypes)({
10647
+ await (0, import_provider_utils34.validateTypes)({
10279
10648
  value: toolPart.output,
10280
10649
  schema: tool3.outputSchema
10281
10650
  });
@@ -10313,13 +10682,13 @@ async function validateUIMessages({
10313
10682
  }
10314
10683
 
10315
10684
  // src/ui-message-stream/create-ui-message-stream.ts
10316
- var import_provider_utils34 = require("@ai-sdk/provider-utils");
10685
+ var import_provider_utils35 = require("@ai-sdk/provider-utils");
10317
10686
  function createUIMessageStream({
10318
10687
  execute,
10319
- onError = import_provider_utils34.getErrorMessage,
10688
+ onError = import_provider_utils35.getErrorMessage,
10320
10689
  originalMessages,
10321
10690
  onFinish,
10322
- generateId: generateId3 = import_provider_utils34.generateId
10691
+ generateId: generateId2 = import_provider_utils35.generateId
10323
10692
  }) {
10324
10693
  let controller;
10325
10694
  const ongoingStreamPromises = [];
@@ -10391,7 +10760,7 @@ function createUIMessageStream({
10391
10760
  });
10392
10761
  return handleUIMessageStreamFinish({
10393
10762
  stream,
10394
- messageId: generateId3(),
10763
+ messageId: generateId2(),
10395
10764
  originalMessages,
10396
10765
  onFinish,
10397
10766
  onError
@@ -10530,6 +10899,7 @@ function readUIMessageStream({
10530
10899
  isToolOrDynamicToolUIPart,
10531
10900
  isToolUIPart,
10532
10901
  jsonSchema,
10902
+ lastAssistantMessageIsCompleteWithApprovalResponses,
10533
10903
  lastAssistantMessageIsCompleteWithToolCalls,
10534
10904
  modelMessageSchema,
10535
10905
  parseJsonEventStream,