ai 6.0.268 → 6.0.271

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index.d.mts +48 -21
  3. package/dist/index.d.ts +48 -21
  4. package/dist/index.js +378 -130
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +317 -68
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/internal/index.js +1 -1
  9. package/dist/internal/index.mjs +1 -1
  10. package/dist/test/index.d.mts +4 -1
  11. package/dist/test/index.d.ts +4 -1
  12. package/dist/test/index.js +6 -0
  13. package/dist/test/index.js.map +1 -1
  14. package/dist/test/index.mjs +6 -0
  15. package/dist/test/index.mjs.map +1 -1
  16. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
  17. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +6 -2
  18. package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +33 -5
  19. package/package.json +3 -3
  20. package/src/agent/create-agent-ui-stream.ts +2 -2
  21. package/src/embed/embed-many.ts +75 -6
  22. package/src/generate-text/stream-text.ts +84 -1
  23. package/src/middleware/wrap-embedding-model.ts +8 -1
  24. package/src/model/get-embedding-model-max-input-bytes-per-call.ts +15 -0
  25. package/src/test/mock-embedding-model-v3.ts +9 -0
  26. package/src/ui/direct-chat-transport.ts +2 -2
  27. package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +1 -0
  28. package/src/ui/validate-ui-messages.ts +136 -55
  29. package/src/ui-message-stream/create-ui-message-stream.ts +47 -17
  30. package/src/ui-message-stream/handle-ui-message-stream-finish.ts +58 -15
  31. package/src/ui-message-stream/index.ts +5 -1
  32. package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +7 -0
  33. package/src/ui-message-stream/ui-message-stream-outcome.ts +12 -0
  34. package/src/ui-message-stream/ui-message-stream-writer.ts +15 -0
  35. package/src/util/create-stitchable-stream.ts +35 -3
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ __export(src_exports, {
69
69
  UnsupportedFunctionalityError: () => import_provider22.UnsupportedFunctionalityError,
70
70
  UnsupportedModelVersionError: () => UnsupportedModelVersionError,
71
71
  addToolInputExamplesMiddleware: () => addToolInputExamplesMiddleware,
72
- asSchema: () => import_provider_utils41.asSchema,
72
+ asSchema: () => import_provider_utils43.asSchema,
73
73
  assistantModelMessageSchema: () => assistantModelMessageSchema,
74
74
  bindTelemetryIntegration: () => bindTelemetryIntegration,
75
75
  callCompletionApi: () => callCompletionApi,
@@ -81,7 +81,7 @@ __export(src_exports, {
81
81
  createAgentUIStreamResponse: () => createAgentUIStreamResponse,
82
82
  createDownload: () => createDownload,
83
83
  createGateway: () => import_gateway4.createGateway,
84
- createIdGenerator: () => import_provider_utils41.createIdGenerator,
84
+ createIdGenerator: () => import_provider_utils43.createIdGenerator,
85
85
  createProviderRegistry: () => createProviderRegistry,
86
86
  createTextStreamResponse: () => createTextStreamResponse,
87
87
  createUIMessageStream: () => createUIMessageStream,
@@ -89,7 +89,7 @@ __export(src_exports, {
89
89
  customProvider: () => customProvider,
90
90
  defaultEmbeddingSettingsMiddleware: () => defaultEmbeddingSettingsMiddleware,
91
91
  defaultSettingsMiddleware: () => defaultSettingsMiddleware,
92
- dynamicTool: () => import_provider_utils41.dynamicTool,
92
+ dynamicTool: () => import_provider_utils43.dynamicTool,
93
93
  embed: () => embed,
94
94
  embedMany: () => embedMany,
95
95
  experimental_createProviderRegistry: () => experimental_createProviderRegistry,
@@ -101,7 +101,7 @@ __export(src_exports, {
101
101
  extractJsonMiddleware: () => extractJsonMiddleware,
102
102
  extractReasoningMiddleware: () => extractReasoningMiddleware,
103
103
  gateway: () => import_gateway4.gateway,
104
- generateId: () => import_provider_utils41.generateId,
104
+ generateId: () => import_provider_utils43.generateId,
105
105
  generateImage: () => generateImage,
106
106
  generateObject: () => generateObject,
107
107
  generateText: () => generateText,
@@ -120,11 +120,11 @@ __export(src_exports, {
120
120
  isTextUIPart: () => isTextUIPart,
121
121
  isToolOrDynamicToolUIPart: () => isToolOrDynamicToolUIPart,
122
122
  isToolUIPart: () => isToolUIPart,
123
- jsonSchema: () => import_provider_utils41.jsonSchema,
123
+ jsonSchema: () => import_provider_utils43.jsonSchema,
124
124
  lastAssistantMessageIsCompleteWithApprovalResponses: () => lastAssistantMessageIsCompleteWithApprovalResponses,
125
125
  lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
126
126
  modelMessageSchema: () => modelMessageSchema,
127
- parseJsonEventStream: () => import_provider_utils41.parseJsonEventStream,
127
+ parseJsonEventStream: () => import_provider_utils43.parseJsonEventStream,
128
128
  parsePartialJson: () => parsePartialJson,
129
129
  pipeAgentUIStreamToResponse: () => pipeAgentUIStreamToResponse,
130
130
  pipeTextStreamToResponse: () => pipeTextStreamToResponse,
@@ -141,7 +141,7 @@ __export(src_exports, {
141
141
  streamObject: () => streamObject,
142
142
  streamText: () => streamText,
143
143
  systemModelMessageSchema: () => systemModelMessageSchema,
144
- tool: () => import_provider_utils41.tool,
144
+ tool: () => import_provider_utils43.tool,
145
145
  toolModelMessageSchema: () => toolModelMessageSchema,
146
146
  uiMessageChunkSchema: () => uiMessageChunkSchema,
147
147
  userModelMessageSchema: () => userModelMessageSchema,
@@ -150,11 +150,11 @@ __export(src_exports, {
150
150
  wrapImageModel: () => wrapImageModel,
151
151
  wrapLanguageModel: () => wrapLanguageModel,
152
152
  wrapProvider: () => wrapProvider,
153
- zodSchema: () => import_provider_utils41.zodSchema
153
+ zodSchema: () => import_provider_utils43.zodSchema
154
154
  });
155
155
  module.exports = __toCommonJS(src_exports);
156
156
  var import_gateway4 = require("@ai-sdk/gateway");
157
- var import_provider_utils41 = require("@ai-sdk/provider-utils");
157
+ var import_provider_utils43 = require("@ai-sdk/provider-utils");
158
158
 
159
159
  // src/agent/tool-loop-agent.ts
160
160
  var import_provider_utils21 = require("@ai-sdk/provider-utils");
@@ -1304,7 +1304,7 @@ function detectMediaType({
1304
1304
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1305
1305
 
1306
1306
  // src/version.ts
1307
- var VERSION = true ? "6.0.268" : "0.0.0-test";
1307
+ var VERSION = true ? "6.0.271" : "0.0.0-test";
1308
1308
 
1309
1309
  // src/util/download/download.ts
1310
1310
  var download = async ({
@@ -6446,7 +6446,8 @@ function handleUIMessageStreamFinish({
6446
6446
  onStepFinish,
6447
6447
  onFinish,
6448
6448
  onError,
6449
- stream
6449
+ stream,
6450
+ getOutcome
6450
6451
  }) {
6451
6452
  let lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
6452
6453
  if ((lastMessage == null ? void 0 : lastMessage.role) !== "assistant") {
@@ -6455,19 +6456,34 @@ function handleUIMessageStreamFinish({
6455
6456
  messageId = lastMessage.id;
6456
6457
  }
6457
6458
  let isAborted = false;
6459
+ let hasProcessingFailure = false;
6460
+ let processingError;
6461
+ const recordProcessingFailure = (error) => {
6462
+ hasProcessingFailure = true;
6463
+ processingError = error;
6464
+ };
6458
6465
  const idInjectedStream = stream.pipeThrough(
6459
6466
  new TransformStream({
6460
6467
  transform(chunk, controller) {
6461
- if (chunk.type === "start") {
6462
- const startChunk = chunk;
6463
- if (startChunk.messageId == null && messageId != null) {
6464
- startChunk.messageId = messageId;
6468
+ try {
6469
+ let outputChunk = chunk;
6470
+ if (chunk.type === "start") {
6471
+ const startChunk = chunk;
6472
+ if (startChunk.messageId == null && messageId != null) {
6473
+ outputChunk = {
6474
+ ...startChunk,
6475
+ messageId
6476
+ };
6477
+ }
6465
6478
  }
6479
+ if (chunk.type === "abort") {
6480
+ isAborted = true;
6481
+ }
6482
+ controller.enqueue(outputChunk);
6483
+ } catch (error) {
6484
+ recordProcessingFailure(error);
6485
+ throw error;
6466
6486
  }
6467
- if (chunk.type === "abort") {
6468
- isAborted = true;
6469
- }
6470
- controller.enqueue(chunk);
6471
6487
  }
6472
6488
  })
6473
6489
  );
@@ -6480,19 +6496,28 @@ function handleUIMessageStreamFinish({
6480
6496
  // will be overridden by the stream
6481
6497
  });
6482
6498
  const runUpdateMessageJob = async (job) => {
6483
- await job({ state, write: () => {
6484
- } });
6499
+ try {
6500
+ await job({ state, write: () => {
6501
+ } });
6502
+ } catch (error) {
6503
+ recordProcessingFailure(error);
6504
+ throw error;
6505
+ }
6485
6506
  };
6486
6507
  let finishCalled = false;
6487
6508
  const callOnFinish = async () => {
6509
+ var _a22;
6488
6510
  if (finishCalled || !onFinish) {
6489
6511
  return;
6490
6512
  }
6491
6513
  finishCalled = true;
6492
6514
  const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
6515
+ const declaredOutcome = (_a22 = getOutcome == null ? void 0 : getOutcome()) != null ? _a22 : { status: "unknown" };
6516
+ const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
6493
6517
  await onFinish({
6494
- isAborted,
6518
+ isAborted: isAborted || outcome.status === "aborted",
6495
6519
  isContinuation,
6520
+ outcome,
6496
6521
  responseMessage: state.message,
6497
6522
  messages: [
6498
6523
  ...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
@@ -6516,7 +6541,13 @@ function handleUIMessageStreamFinish({
6516
6541
  ]
6517
6542
  });
6518
6543
  } catch (error) {
6519
- onError(error);
6544
+ try {
6545
+ onError(error);
6546
+ } catch (onErrorError) {
6547
+ recordProcessingFailure(onErrorError);
6548
+ await callOnFinish();
6549
+ throw onErrorError;
6550
+ }
6520
6551
  }
6521
6552
  };
6522
6553
  return processUIMessageStream({
@@ -6680,8 +6711,12 @@ function createStitchableStream() {
6680
6711
  let innerStreams = [];
6681
6712
  let controller = null;
6682
6713
  let isClosed = false;
6714
+ let isCancelled = false;
6683
6715
  let waitForNewStream = createResolvablePromise();
6684
6716
  const terminate = () => {
6717
+ if (isCancelled) {
6718
+ return;
6719
+ }
6685
6720
  isClosed = true;
6686
6721
  waitForNewStream.resolve();
6687
6722
  innerStreams.forEach(({ reader, onCancel }) => {
@@ -6692,7 +6727,10 @@ function createStitchableStream() {
6692
6727
  controller == null ? void 0 : controller.close();
6693
6728
  };
6694
6729
  const processPull = async () => {
6695
- var _a22, _b;
6730
+ var _a22;
6731
+ if (isCancelled) {
6732
+ return;
6733
+ }
6696
6734
  if (isClosed && innerStreams.length === 0) {
6697
6735
  controller == null ? void 0 : controller.close();
6698
6736
  return;
@@ -6702,8 +6740,12 @@ function createStitchableStream() {
6702
6740
  await waitForNewStream.promise;
6703
6741
  return processPull();
6704
6742
  }
6743
+ const currentStream = innerStreams[0];
6705
6744
  try {
6706
- const { value, done } = await innerStreams[0].reader.read();
6745
+ const { value, done } = await currentStream.reader.read();
6746
+ if (isCancelled) {
6747
+ return;
6748
+ }
6707
6749
  if (done) {
6708
6750
  innerStreams.shift();
6709
6751
  if (innerStreams.length === 0 && isClosed) {
@@ -6715,7 +6757,10 @@ function createStitchableStream() {
6715
6757
  controller == null ? void 0 : controller.enqueue(value);
6716
6758
  }
6717
6759
  } catch (error) {
6718
- (_b = (_a22 = innerStreams[0]).onError) == null ? void 0 : _b.call(_a22, error);
6760
+ if (isCancelled) {
6761
+ return;
6762
+ }
6763
+ (_a22 = currentStream.onError) == null ? void 0 : _a22.call(currentStream, error);
6719
6764
  controller == null ? void 0 : controller.error(error);
6720
6765
  innerStreams.shift();
6721
6766
  terminate();
@@ -6728,15 +6773,24 @@ function createStitchableStream() {
6728
6773
  },
6729
6774
  pull: processPull,
6730
6775
  async cancel() {
6776
+ isCancelled = true;
6777
+ isClosed = true;
6778
+ waitForNewStream.resolve();
6731
6779
  for (const { reader, onCancel } of innerStreams) {
6732
6780
  onCancel == null ? void 0 : onCancel();
6733
6781
  await reader.cancel();
6734
6782
  }
6735
6783
  innerStreams = [];
6736
- isClosed = true;
6737
6784
  }
6738
6785
  }),
6739
6786
  addStream: (innerStream, callbacks) => {
6787
+ var _a22;
6788
+ if (isCancelled) {
6789
+ (_a22 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a22.call(callbacks);
6790
+ void innerStream.cancel().catch(() => {
6791
+ });
6792
+ return;
6793
+ }
6740
6794
  if (isClosed) {
6741
6795
  throw new Error("Cannot add inner stream: outer stream is closed");
6742
6796
  }
@@ -6751,6 +6805,9 @@ function createStitchableStream() {
6751
6805
  * finish processing and then close the outer stream.
6752
6806
  */
6753
6807
  close: () => {
6808
+ if (isCancelled) {
6809
+ return;
6810
+ }
6754
6811
  isClosed = true;
6755
6812
  waitForNewStream.resolve();
6756
6813
  if (innerStreams.length === 0) {
@@ -8647,6 +8704,17 @@ var DefaultStreamTextResult = class {
8647
8704
  onError = () => "An error occurred."
8648
8705
  // prevent leaking server error details to the client by default
8649
8706
  } = {}) {
8707
+ let outcome = { status: "unknown" };
8708
+ let hasFatalFailure = false;
8709
+ const setSourceOutcome = (newOutcome) => {
8710
+ if (!hasFatalFailure && outcome.status !== "completed" && outcome.status !== "aborted" && newOutcome.status !== "unknown" && (outcome.status === "unknown" || newOutcome.status !== "failed")) {
8711
+ outcome = newOutcome;
8712
+ }
8713
+ };
8714
+ const failOutcome = (error) => {
8715
+ hasFatalFailure = true;
8716
+ outcome = { status: "failed", error };
8717
+ };
8650
8718
  const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
8651
8719
  originalMessages,
8652
8720
  responseMessageId: generateMessageId
@@ -8659,7 +8727,51 @@ var DefaultStreamTextResult = class {
8659
8727
  }
8660
8728
  return (tool2 == null ? void 0 : tool2.type) === "dynamic" ? true : void 0;
8661
8729
  };
8662
- const baseStream = this.fullStream.pipeThrough(
8730
+ const trackFatalFailures = (stream) => {
8731
+ const reader = stream.getReader();
8732
+ let readerReleased = false;
8733
+ let streamCancelled = false;
8734
+ const releaseReader = () => {
8735
+ if (!readerReleased) {
8736
+ reader.releaseLock();
8737
+ readerReleased = true;
8738
+ }
8739
+ };
8740
+ return new ReadableStream({
8741
+ async pull(controller) {
8742
+ try {
8743
+ const { done, value } = await reader.read();
8744
+ if (done) {
8745
+ releaseReader();
8746
+ if (!streamCancelled) {
8747
+ controller.close();
8748
+ }
8749
+ } else {
8750
+ controller.enqueue(value);
8751
+ }
8752
+ } catch (error) {
8753
+ releaseReader();
8754
+ if (!streamCancelled) {
8755
+ failOutcome(error);
8756
+ controller.error(error);
8757
+ }
8758
+ }
8759
+ },
8760
+ async cancel(reason) {
8761
+ streamCancelled = true;
8762
+ if (readerReleased) {
8763
+ return;
8764
+ }
8765
+ try {
8766
+ await reader.cancel(reason);
8767
+ } finally {
8768
+ releaseReader();
8769
+ }
8770
+ }
8771
+ });
8772
+ };
8773
+ const sourceStream = trackFatalFailures(this.fullStream);
8774
+ const convertedStream = sourceStream.pipeThrough(
8663
8775
  new TransformStream({
8664
8776
  transform: async (part, controller) => {
8665
8777
  const messageMetadataValue = messageMetadata == null ? void 0 : messageMetadata({ part });
@@ -8896,16 +9008,25 @@ var DefaultStreamTextResult = class {
8896
9008
  messageMetadata: messageMetadataValue
8897
9009
  });
8898
9010
  }
9011
+ if (part.type === "finish") {
9012
+ setSourceOutcome({ status: "completed" });
9013
+ } else if (part.type === "abort") {
9014
+ setSourceOutcome({ status: "aborted" });
9015
+ } else if (part.type === "error") {
9016
+ setSourceOutcome({ status: "failed", error: part.error });
9017
+ }
8899
9018
  }
8900
9019
  })
8901
9020
  );
9021
+ const baseStream = trackFatalFailures(convertedStream);
8902
9022
  return createAsyncIterableStream(
8903
9023
  handleUIMessageStreamFinish({
8904
9024
  stream: baseStream,
8905
9025
  messageId: responseMessageId != null ? responseMessageId : generateMessageId == null ? void 0 : generateMessageId(),
8906
9026
  originalMessages,
8907
9027
  onFinish,
8908
- onError
9028
+ onError,
9029
+ getOutcome: () => outcome
8909
9030
  })
8910
9031
  );
8911
9032
  }
@@ -9096,6 +9217,7 @@ function createUIMessageStream({
9096
9217
  }) {
9097
9218
  let controller;
9098
9219
  const ongoingStreamPromises = [];
9220
+ let outcome = { status: "unknown" };
9099
9221
  const stream = new ReadableStream({
9100
9222
  start(controllerArg) {
9101
9223
  controller = controllerArg;
@@ -9107,6 +9229,35 @@ function createUIMessageStream({
9107
9229
  } catch (error) {
9108
9230
  }
9109
9231
  }
9232
+ function setOutcome(newOutcome) {
9233
+ if (outcome.status === "unknown" && newOutcome.status !== "unknown") {
9234
+ outcome = newOutcome;
9235
+ }
9236
+ }
9237
+ function failOutcome(error) {
9238
+ outcome = { status: "failed", error };
9239
+ }
9240
+ function safeError(error) {
9241
+ try {
9242
+ controller.error(error);
9243
+ } catch (e) {
9244
+ }
9245
+ }
9246
+ function handleError(error) {
9247
+ failOutcome(error);
9248
+ let errorText;
9249
+ try {
9250
+ errorText = onError(error);
9251
+ } catch (onErrorError) {
9252
+ failOutcome(onErrorError);
9253
+ safeError(onErrorError);
9254
+ return;
9255
+ }
9256
+ safeEnqueue({
9257
+ type: "error",
9258
+ errorText
9259
+ });
9260
+ }
9110
9261
  try {
9111
9262
  const result = execute({
9112
9263
  writer: {
@@ -9124,38 +9275,29 @@ function createUIMessageStream({
9124
9275
  safeEnqueue(value);
9125
9276
  }
9126
9277
  })().catch((error) => {
9127
- safeEnqueue({
9128
- type: "error",
9129
- errorText: onError(error)
9130
- });
9278
+ handleError(error);
9131
9279
  })
9132
9280
  );
9133
9281
  },
9282
+ setOutcome,
9134
9283
  onError
9135
9284
  }
9136
9285
  });
9137
9286
  if (result) {
9138
9287
  ongoingStreamPromises.push(
9139
9288
  result.catch((error) => {
9140
- safeEnqueue({
9141
- type: "error",
9142
- errorText: onError(error)
9143
- });
9289
+ handleError(error);
9144
9290
  })
9145
9291
  );
9146
9292
  }
9147
9293
  } catch (error) {
9148
- safeEnqueue({
9149
- type: "error",
9150
- errorText: onError(error)
9151
- });
9294
+ handleError(error);
9152
9295
  }
9153
- const waitForStreams = new Promise(async (resolve3) => {
9296
+ const waitForStreams = (async () => {
9154
9297
  while (ongoingStreamPromises.length > 0) {
9155
9298
  await ongoingStreamPromises.shift();
9156
9299
  }
9157
- resolve3();
9158
- });
9300
+ })();
9159
9301
  waitForStreams.finally(() => {
9160
9302
  try {
9161
9303
  controller.close();
@@ -9168,7 +9310,8 @@ function createUIMessageStream({
9168
9310
  originalMessages,
9169
9311
  onStepFinish,
9170
9312
  onFinish,
9171
- onError
9313
+ onError,
9314
+ getOutcome: () => outcome
9172
9315
  });
9173
9316
  }
9174
9317
 
@@ -9486,6 +9629,17 @@ var toolMetadataSchema2 = import_v48.z.record(
9486
9629
  import_v48.z.string(),
9487
9630
  jsonValueSchema.optional()
9488
9631
  );
9632
+ function isEmptyObject(value) {
9633
+ return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
9634
+ }
9635
+ function asDynamicToolPart(toolPart) {
9636
+ const { type, ...part } = toolPart;
9637
+ return {
9638
+ ...part,
9639
+ type: "dynamic-tool",
9640
+ toolName: type.slice(5)
9641
+ };
9642
+ }
9489
9643
  var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(
9490
9644
  () => (0, import_provider_utils24.zodSchema)(
9491
9645
  import_v48.z.array(
@@ -9789,11 +9943,13 @@ var uiMessagesSchema = (0, import_provider_utils24.lazySchema)(
9789
9943
  ).nonempty("Messages array must not be empty")
9790
9944
  )
9791
9945
  );
9792
- async function safeValidateUIMessages({
9946
+ async function safeValidateUIMessagesInternal({
9793
9947
  messages,
9794
9948
  metadataSchema,
9795
9949
  dataSchemas,
9796
9950
  tools
9951
+ }, {
9952
+ convertMissingTerminalToolsToDynamic
9797
9953
  }) {
9798
9954
  try {
9799
9955
  if (messages == null) {
@@ -9822,7 +9978,8 @@ async function safeValidateUIMessages({
9822
9978
  });
9823
9979
  }
9824
9980
  }
9825
- if (dataSchemas || tools) {
9981
+ const shouldValidateToolParts = tools != null || convertMissingTerminalToolsToDynamic;
9982
+ if (dataSchemas || shouldValidateToolParts) {
9826
9983
  for (const [msgIdx, message] of validatedMessages.entries()) {
9827
9984
  for (const [partIdx, part] of message.parts.entries()) {
9828
9985
  if (dataSchemas && part.type.startsWith("data-")) {
@@ -9853,11 +10010,17 @@ async function safeValidateUIMessages({
9853
10010
  }
9854
10011
  });
9855
10012
  }
9856
- if (tools && part.type.startsWith("tool-")) {
10013
+ if (shouldValidateToolParts && part.type.startsWith("tool-")) {
9857
10014
  const toolPart = part;
9858
10015
  const toolName = toolPart.type.slice(5);
9859
- const tool2 = tools[toolName];
9860
- if (!tool2 && (toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied")) {
10016
+ const tool2 = tools == null ? void 0 : tools[toolName];
10017
+ const isTerminal = toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied";
10018
+ if (!tool2 && isTerminal) {
10019
+ if (tools != null || convertMissingTerminalToolsToDynamic) {
10020
+ message.parts[partIdx] = asDynamicToolPart(
10021
+ toolPart
10022
+ );
10023
+ }
9861
10024
  continue;
9862
10025
  }
9863
10026
  if (!tool2) {
@@ -9874,15 +10037,39 @@ async function safeValidateUIMessages({
9874
10037
  })
9875
10038
  };
9876
10039
  }
9877
- if (toolPart.state === "input-available") {
9878
- await (0, import_provider_utils24.validateTypes)({
10040
+ const inputValidationContext = {
10041
+ field: `messages[${msgIdx}].parts[${partIdx}].input`,
10042
+ entityName: toolName,
10043
+ entityId: toolPart.toolCallId
10044
+ };
10045
+ let convertToDynamic = false;
10046
+ if (toolPart.state === "output-error") {
10047
+ if (toolPart.input !== void 0) {
10048
+ const result = await (0, import_provider_utils24.safeValidateTypes)({
10049
+ value: toolPart.input,
10050
+ schema: tool2.inputSchema,
10051
+ context: inputValidationContext
10052
+ });
10053
+ convertToDynamic = !result.success;
10054
+ }
10055
+ } else if (toolPart.state === "output-available") {
10056
+ const result = await (0, import_provider_utils24.safeValidateTypes)({
9879
10057
  value: toolPart.input,
9880
10058
  schema: tool2.inputSchema,
9881
- context: {
9882
- field: `messages[${msgIdx}].parts[${partIdx}].input`,
9883
- entityName: toolName,
9884
- entityId: toolPart.toolCallId
10059
+ context: inputValidationContext
10060
+ });
10061
+ if (!result.success) {
10062
+ if (isEmptyObject(toolPart.input)) {
10063
+ convertToDynamic = true;
10064
+ } else {
10065
+ throw result.error;
9885
10066
  }
10067
+ }
10068
+ } else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
10069
+ await (0, import_provider_utils24.validateTypes)({
10070
+ value: toolPart.input,
10071
+ schema: tool2.inputSchema,
10072
+ context: inputValidationContext
9886
10073
  });
9887
10074
  }
9888
10075
  if (toolPart.state === "output-available" && tool2.outputSchema) {
@@ -9896,6 +10083,11 @@ async function safeValidateUIMessages({
9896
10083
  }
9897
10084
  });
9898
10085
  }
10086
+ if (convertToDynamic) {
10087
+ message.parts[partIdx] = asDynamicToolPart(
10088
+ toolPart
10089
+ );
10090
+ }
9899
10091
  }
9900
10092
  }
9901
10093
  }
@@ -9912,17 +10104,23 @@ async function safeValidateUIMessages({
9912
10104
  };
9913
10105
  }
9914
10106
  }
9915
- async function validateUIMessages({
9916
- messages,
9917
- metadataSchema,
9918
- dataSchemas,
9919
- tools
9920
- }) {
9921
- const response = await safeValidateUIMessages({
9922
- messages,
9923
- metadataSchema,
9924
- dataSchemas,
9925
- tools
10107
+ async function safeValidateUIMessages(options) {
10108
+ return safeValidateUIMessagesInternal(options, {
10109
+ convertMissingTerminalToolsToDynamic: false
10110
+ });
10111
+ }
10112
+ async function validateUIMessages(options) {
10113
+ const response = await safeValidateUIMessages(options);
10114
+ if (!response.success)
10115
+ throw response.error;
10116
+ return response.data;
10117
+ }
10118
+ async function validateUIMessagesForAgent(options) {
10119
+ const response = await safeValidateUIMessagesInternal(options, {
10120
+ // Agent tool sets can include ephemeral tools (for example, tools from a
10121
+ // disconnected MCP server), so terminal history is converted to dynamic
10122
+ // tool parts when those tools are no longer registered.
10123
+ convertMissingTerminalToolsToDynamic: true
9926
10124
  });
9927
10125
  if (!response.success)
9928
10126
  throw response.error;
@@ -9941,7 +10139,7 @@ async function createAgentUIStream({
9941
10139
  ...uiMessageStreamOptions
9942
10140
  }) {
9943
10141
  var _a22;
9944
- const validatedMessages = await validateUIMessages({
10142
+ const validatedMessages = await validateUIMessagesForAgent({
9945
10143
  messages: uiMessages,
9946
10144
  tools: agent.tools
9947
10145
  });
@@ -10123,7 +10321,13 @@ var DefaultEmbedResult = class {
10123
10321
  };
10124
10322
 
10125
10323
  // src/embed/embed-many.ts
10324
+ var import_provider_utils27 = require("@ai-sdk/provider-utils");
10325
+
10326
+ // src/model/get-embedding-model-max-input-bytes-per-call.ts
10126
10327
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
10328
+ function getEmbeddingModelMaxInputBytesPerCall(model) {
10329
+ return model[import_provider_utils26.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
10330
+ }
10127
10331
 
10128
10332
  // src/util/split-array.ts
10129
10333
  function splitArray(array2, chunkSize) {
@@ -10153,7 +10357,7 @@ async function embedMany({
10153
10357
  maxRetries: maxRetriesArg,
10154
10358
  abortSignal
10155
10359
  });
10156
- const headersWithUserAgent = (0, import_provider_utils26.withUserAgentSuffix)(
10360
+ const headersWithUserAgent = (0, import_provider_utils27.withUserAgentSuffix)(
10157
10361
  headers != null ? headers : {},
10158
10362
  `ai/${VERSION}`
10159
10363
  );
@@ -10180,11 +10384,18 @@ async function embedMany({
10180
10384
  tracer,
10181
10385
  fn: async (span) => {
10182
10386
  var _a22;
10183
- const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
10387
+ const [
10388
+ maxEmbeddingsPerCall,
10389
+ maxInputBytesPerCall,
10390
+ supportsParallelCalls
10391
+ ] = await Promise.all([
10184
10392
  model.maxEmbeddingsPerCall,
10393
+ getEmbeddingModelMaxInputBytesPerCall(model),
10185
10394
  model.supportsParallelCalls
10186
10395
  ]);
10187
- if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
10396
+ const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
10397
+ const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
10398
+ if (!hasEmbeddingLimit && !hasInputByteLimit) {
10188
10399
  const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(() => {
10189
10400
  return recordSpan({
10190
10401
  name: "ai.embedMany.doEmbed",
@@ -10261,7 +10472,11 @@ async function embedMany({
10261
10472
  responses: [response]
10262
10473
  });
10263
10474
  }
10264
- const valueChunks = splitArray(values, maxEmbeddingsPerCall);
10475
+ const valueChunks = splitByEmbeddingLimits({
10476
+ values,
10477
+ maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
10478
+ maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
10479
+ });
10265
10480
  const embeddings = [];
10266
10481
  const warnings = [];
10267
10482
  const responses = [];
@@ -10375,6 +10590,37 @@ async function embedMany({
10375
10590
  }
10376
10591
  });
10377
10592
  }
10593
+ var textEncoder = new TextEncoder();
10594
+ function splitByEmbeddingLimits({
10595
+ values,
10596
+ maxEmbeddingsPerCall,
10597
+ maxInputBytesPerCall
10598
+ }) {
10599
+ if (maxEmbeddingsPerCall <= 0) {
10600
+ throw new Error("maxEmbeddingsPerCall must be greater than 0");
10601
+ }
10602
+ if (maxInputBytesPerCall <= 0) {
10603
+ throw new Error("maxInputBytesPerCall must be greater than 0");
10604
+ }
10605
+ if (values.length === 0) {
10606
+ return [];
10607
+ }
10608
+ const chunks = [];
10609
+ let currentChunk = [];
10610
+ let currentInputBytes = 0;
10611
+ for (const value of values) {
10612
+ const inputBytes = textEncoder.encode(value).length;
10613
+ if (currentChunk.length > 0 && (currentChunk.length >= maxEmbeddingsPerCall || currentInputBytes + inputBytes > maxInputBytesPerCall)) {
10614
+ chunks.push(currentChunk);
10615
+ currentChunk = [];
10616
+ currentInputBytes = 0;
10617
+ }
10618
+ currentChunk.push(value);
10619
+ currentInputBytes += inputBytes;
10620
+ }
10621
+ chunks.push(currentChunk);
10622
+ return chunks;
10623
+ }
10378
10624
  var DefaultEmbedManyResult = class {
10379
10625
  constructor(options) {
10380
10626
  this.values = options.values;
@@ -10387,7 +10633,7 @@ var DefaultEmbedManyResult = class {
10387
10633
  };
10388
10634
 
10389
10635
  // src/generate-image/generate-image.ts
10390
- var import_provider_utils27 = require("@ai-sdk/provider-utils");
10636
+ var import_provider_utils28 = require("@ai-sdk/provider-utils");
10391
10637
  async function generateImage({
10392
10638
  model: modelArg,
10393
10639
  prompt: promptArg,
@@ -10403,7 +10649,7 @@ async function generateImage({
10403
10649
  }) {
10404
10650
  var _a22, _b;
10405
10651
  const model = resolveImageModel(modelArg);
10406
- const headersWithUserAgent = (0, import_provider_utils27.withUserAgentSuffix)(
10652
+ const headersWithUserAgent = (0, import_provider_utils28.withUserAgentSuffix)(
10407
10653
  headers != null ? headers : {},
10408
10654
  `ai/${VERSION}`
10409
10655
  );
@@ -10546,7 +10792,7 @@ function toImageModelV3File(dataContent) {
10546
10792
  if (typeof dataContent === "string" && dataContent.startsWith("data:")) {
10547
10793
  const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(dataContent);
10548
10794
  if (base64Content != null) {
10549
- const uint8Data2 = (0, import_provider_utils27.convertBase64ToUint8Array)(base64Content);
10795
+ const uint8Data2 = (0, import_provider_utils28.convertBase64ToUint8Array)(base64Content);
10550
10796
  return {
10551
10797
  type: "file",
10552
10798
  data: uint8Data2,
@@ -10572,11 +10818,11 @@ function toImageModelV3File(dataContent) {
10572
10818
  var experimental_generateImage = generateImage;
10573
10819
 
10574
10820
  // src/generate-object/generate-object.ts
10575
- var import_provider_utils30 = require("@ai-sdk/provider-utils");
10821
+ var import_provider_utils31 = require("@ai-sdk/provider-utils");
10576
10822
 
10577
10823
  // src/generate-object/output-strategy.ts
10578
10824
  var import_provider31 = require("@ai-sdk/provider");
10579
- var import_provider_utils28 = require("@ai-sdk/provider-utils");
10825
+ var import_provider_utils29 = require("@ai-sdk/provider-utils");
10580
10826
  var noSchemaOutputStrategy = {
10581
10827
  type: "no-schema",
10582
10828
  jsonSchema: async () => void 0,
@@ -10615,7 +10861,7 @@ var objectOutputStrategy = (schema) => ({
10615
10861
  };
10616
10862
  },
10617
10863
  async validateFinalResult(value) {
10618
- return (0, import_provider_utils28.safeValidateTypes)({ value, schema });
10864
+ return (0, import_provider_utils29.safeValidateTypes)({ value, schema });
10619
10865
  },
10620
10866
  createElementStream() {
10621
10867
  throw new import_provider31.UnsupportedFunctionalityError({
@@ -10661,7 +10907,7 @@ var arrayOutputStrategy = (schema) => {
10661
10907
  const resultArray = [];
10662
10908
  for (let i = 0; i < inputArray.length; i++) {
10663
10909
  const element = inputArray[i];
10664
- const result = await (0, import_provider_utils28.safeValidateTypes)({ value: element, schema });
10910
+ const result = await (0, import_provider_utils29.safeValidateTypes)({ value: element, schema });
10665
10911
  if (i === inputArray.length - 1 && !isFinalDelta) {
10666
10912
  continue;
10667
10913
  }
@@ -10703,7 +10949,7 @@ var arrayOutputStrategy = (schema) => {
10703
10949
  const inputArray = value.elements;
10704
10950
  const resultArray = [];
10705
10951
  for (const element of inputArray) {
10706
- const result = await (0, import_provider_utils28.safeValidateTypes)({ value: element, schema });
10952
+ const result = await (0, import_provider_utils29.safeValidateTypes)({ value: element, schema });
10707
10953
  if (!result.success) {
10708
10954
  return result;
10709
10955
  }
@@ -10822,9 +11068,9 @@ function getOutputStrategy({
10822
11068
  }) {
10823
11069
  switch (output) {
10824
11070
  case "object":
10825
- return objectOutputStrategy((0, import_provider_utils28.asSchema)(schema));
11071
+ return objectOutputStrategy((0, import_provider_utils29.asSchema)(schema));
10826
11072
  case "array":
10827
- return arrayOutputStrategy((0, import_provider_utils28.asSchema)(schema));
11073
+ return arrayOutputStrategy((0, import_provider_utils29.asSchema)(schema));
10828
11074
  case "enum":
10829
11075
  return enumOutputStrategy(enumValues);
10830
11076
  case "no-schema":
@@ -10838,9 +11084,9 @@ function getOutputStrategy({
10838
11084
 
10839
11085
  // src/generate-object/parse-and-validate-object-result.ts
10840
11086
  var import_provider32 = require("@ai-sdk/provider");
10841
- var import_provider_utils29 = require("@ai-sdk/provider-utils");
11087
+ var import_provider_utils30 = require("@ai-sdk/provider-utils");
10842
11088
  async function parseAndValidateObjectResult(result, outputStrategy, context2) {
10843
- const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: result });
11089
+ const parseResult = await (0, import_provider_utils30.safeParseJSON)({ text: result });
10844
11090
  if (!parseResult.success) {
10845
11091
  throw new NoObjectGeneratedError({
10846
11092
  message: "No object generated: could not parse the response.",
@@ -11012,7 +11258,7 @@ function validateObjectGenerationInput({
11012
11258
  }
11013
11259
 
11014
11260
  // src/generate-object/generate-object.ts
11015
- var originalGenerateId3 = (0, import_provider_utils30.createIdGenerator)({ prefix: "aiobj", size: 24 });
11261
+ var originalGenerateId3 = (0, import_provider_utils31.createIdGenerator)({ prefix: "aiobj", size: 24 });
11016
11262
  async function generateObject(options) {
11017
11263
  const {
11018
11264
  model: modelArg,
@@ -11058,7 +11304,7 @@ async function generateObject(options) {
11058
11304
  enumValues
11059
11305
  });
11060
11306
  const callSettings = prepareCallSettings(settings);
11061
- const headersWithUserAgent = (0, import_provider_utils30.withUserAgentSuffix)(
11307
+ const headersWithUserAgent = (0, import_provider_utils31.withUserAgentSuffix)(
11062
11308
  headers != null ? headers : {},
11063
11309
  `ai/${VERSION}`
11064
11310
  );
@@ -11285,7 +11531,7 @@ var DefaultGenerateObjectResult = class {
11285
11531
  };
11286
11532
 
11287
11533
  // src/generate-object/stream-object.ts
11288
- var import_provider_utils32 = require("@ai-sdk/provider-utils");
11534
+ var import_provider_utils33 = require("@ai-sdk/provider-utils");
11289
11535
 
11290
11536
  // src/util/cosine-similarity.ts
11291
11537
  function cosineSimilarity(vector1, vector2) {
@@ -11400,7 +11646,7 @@ var SerialJobExecutor = class {
11400
11646
  };
11401
11647
 
11402
11648
  // src/util/simulate-readable-stream.ts
11403
- var import_provider_utils31 = require("@ai-sdk/provider-utils");
11649
+ var import_provider_utils32 = require("@ai-sdk/provider-utils");
11404
11650
  function simulateReadableStream({
11405
11651
  chunks,
11406
11652
  initialDelayInMs = 0,
@@ -11408,7 +11654,7 @@ function simulateReadableStream({
11408
11654
  _internal
11409
11655
  }) {
11410
11656
  var _a22;
11411
- const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : import_provider_utils31.delay;
11657
+ const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : import_provider_utils32.delay;
11412
11658
  let index = 0;
11413
11659
  return new ReadableStream({
11414
11660
  async pull(controller) {
@@ -11423,7 +11669,7 @@ function simulateReadableStream({
11423
11669
  }
11424
11670
 
11425
11671
  // src/generate-object/stream-object.ts
11426
- var originalGenerateId4 = (0, import_provider_utils32.createIdGenerator)({ prefix: "aiobj", size: 24 });
11672
+ var originalGenerateId4 = (0, import_provider_utils33.createIdGenerator)({ prefix: "aiobj", size: 24 });
11427
11673
  async function markPromiseAsHandled(promise) {
11428
11674
  try {
11429
11675
  await promise;
@@ -11522,13 +11768,13 @@ var DefaultStreamObjectResult = class {
11522
11768
  currentDate,
11523
11769
  now: now2
11524
11770
  }) {
11525
- this._object = new import_provider_utils32.DelayedPromise();
11526
- this._usage = new import_provider_utils32.DelayedPromise();
11527
- this._providerMetadata = new import_provider_utils32.DelayedPromise();
11528
- this._warnings = new import_provider_utils32.DelayedPromise();
11529
- this._request = new import_provider_utils32.DelayedPromise();
11530
- this._response = new import_provider_utils32.DelayedPromise();
11531
- this._finishReason = new import_provider_utils32.DelayedPromise();
11771
+ this._object = new import_provider_utils33.DelayedPromise();
11772
+ this._usage = new import_provider_utils33.DelayedPromise();
11773
+ this._providerMetadata = new import_provider_utils33.DelayedPromise();
11774
+ this._warnings = new import_provider_utils33.DelayedPromise();
11775
+ this._request = new import_provider_utils33.DelayedPromise();
11776
+ this._response = new import_provider_utils33.DelayedPromise();
11777
+ this._finishReason = new import_provider_utils33.DelayedPromise();
11532
11778
  const model = resolveLanguageModel(modelArg);
11533
11779
  const { maxRetries, retry } = prepareRetries({
11534
11780
  maxRetries: maxRetriesArg,
@@ -12005,7 +12251,7 @@ var DefaultStreamObjectResult = class {
12005
12251
  };
12006
12252
 
12007
12253
  // src/generate-speech/generate-speech.ts
12008
- var import_provider_utils33 = require("@ai-sdk/provider-utils");
12254
+ var import_provider_utils34 = require("@ai-sdk/provider-utils");
12009
12255
 
12010
12256
  // src/generate-speech/generated-audio-file.ts
12011
12257
  var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
@@ -12051,7 +12297,7 @@ async function generateSpeech({
12051
12297
  if (!resolvedModel) {
12052
12298
  throw new Error("Model could not be resolved");
12053
12299
  }
12054
- const headersWithUserAgent = (0, import_provider_utils33.withUserAgentSuffix)(
12300
+ const headersWithUserAgent = (0, import_provider_utils34.withUserAgentSuffix)(
12055
12301
  headers != null ? headers : {},
12056
12302
  `ai/${VERSION}`
12057
12303
  );
@@ -12198,7 +12444,7 @@ function pruneMessages({
12198
12444
  }
12199
12445
 
12200
12446
  // src/generate-text/smooth-stream.ts
12201
- var import_provider_utils34 = require("@ai-sdk/provider-utils");
12447
+ var import_provider_utils35 = require("@ai-sdk/provider-utils");
12202
12448
  var import_provider33 = require("@ai-sdk/provider");
12203
12449
  var CHUNKING_REGEXPS = {
12204
12450
  word: /\S+\s+/m,
@@ -12207,7 +12453,7 @@ var CHUNKING_REGEXPS = {
12207
12453
  function smoothStream({
12208
12454
  delayInMs = 10,
12209
12455
  chunking = "word",
12210
- _internal: { delay = import_provider_utils34.delay } = {}
12456
+ _internal: { delay = import_provider_utils35.delay } = {}
12211
12457
  } = {}) {
12212
12458
  let detectChunk;
12213
12459
  if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
@@ -12296,7 +12542,7 @@ function smoothStream({
12296
12542
  }
12297
12543
 
12298
12544
  // src/generate-video/generate-video.ts
12299
- var import_provider_utils35 = require("@ai-sdk/provider-utils");
12545
+ var import_provider_utils36 = require("@ai-sdk/provider-utils");
12300
12546
  var defaultDownload = createDownload();
12301
12547
  async function experimental_generateVideo({
12302
12548
  model: modelArg,
@@ -12319,7 +12565,7 @@ async function experimental_generateVideo({
12319
12565
  }) {
12320
12566
  var _a22, _b;
12321
12567
  const model = resolveVideoModel(modelArg);
12322
- const headersWithUserAgent = (0, import_provider_utils35.withUserAgentSuffix)(
12568
+ const headersWithUserAgent = (0, import_provider_utils36.withUserAgentSuffix)(
12323
12569
  headers != null ? headers : {},
12324
12570
  `ai/${VERSION}`
12325
12571
  );
@@ -12504,14 +12750,14 @@ function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
12504
12750
  }
12505
12751
  if (dataContent.startsWith("data:")) {
12506
12752
  const { mediaType, base64Content } = splitDataUrl(dataContent);
12507
- const data = (0, import_provider_utils35.convertBase64ToUint8Array)(base64Content != null ? base64Content : "");
12753
+ const data = (0, import_provider_utils36.convertBase64ToUint8Array)(base64Content != null ? base64Content : "");
12508
12754
  return {
12509
12755
  type: "file",
12510
12756
  mediaType: mediaType != null ? mediaType : detectFileMediaType(data, restrictToImages),
12511
12757
  data
12512
12758
  };
12513
12759
  }
12514
- const bytes = (0, import_provider_utils35.convertBase64ToUint8Array)(dataContent);
12760
+ const bytes = (0, import_provider_utils36.convertBase64ToUint8Array)(dataContent);
12515
12761
  return {
12516
12762
  type: "file",
12517
12763
  mediaType: detectFileMediaType(bytes, restrictToImages),
@@ -13048,6 +13294,7 @@ var doWrap = ({
13048
13294
  };
13049
13295
 
13050
13296
  // src/middleware/wrap-embedding-model.ts
13297
+ var import_provider_utils37 = require("@ai-sdk/provider-utils");
13051
13298
  var wrapEmbeddingModel = ({
13052
13299
  model,
13053
13300
  middleware: middlewareArg,
@@ -13082,6 +13329,7 @@ var doWrap2 = ({
13082
13329
  provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
13083
13330
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
13084
13331
  maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
13332
+ [import_provider_utils37.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL]: getEmbeddingModelMaxInputBytesPerCall(model),
13085
13333
  supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
13086
13334
  async doEmbed(params) {
13087
13335
  const transformedParams = await doTransform({ params });
@@ -13570,7 +13818,7 @@ var DefaultRerankResult = class {
13570
13818
  };
13571
13819
 
13572
13820
  // src/transcribe/transcribe.ts
13573
- var import_provider_utils36 = require("@ai-sdk/provider-utils");
13821
+ var import_provider_utils38 = require("@ai-sdk/provider-utils");
13574
13822
  var defaultDownload2 = createDownload();
13575
13823
  async function transcribe({
13576
13824
  model,
@@ -13589,7 +13837,7 @@ async function transcribe({
13589
13837
  maxRetries: maxRetriesArg,
13590
13838
  abortSignal
13591
13839
  });
13592
- const headersWithUserAgent = (0, import_provider_utils36.withUserAgentSuffix)(
13840
+ const headersWithUserAgent = (0, import_provider_utils38.withUserAgentSuffix)(
13593
13841
  headers != null ? headers : {},
13594
13842
  `ai/${VERSION}`
13595
13843
  );
@@ -13641,7 +13889,7 @@ var DefaultTranscriptionResult = class {
13641
13889
  };
13642
13890
 
13643
13891
  // src/ui/call-completion-api.ts
13644
- var import_provider_utils37 = require("@ai-sdk/provider-utils");
13892
+ var import_provider_utils39 = require("@ai-sdk/provider-utils");
13645
13893
 
13646
13894
  // src/ui/process-text-stream.ts
13647
13895
  async function processTextStream({
@@ -13689,13 +13937,13 @@ async function callCompletionApi({
13689
13937
  ...body
13690
13938
  }),
13691
13939
  credentials,
13692
- headers: (0, import_provider_utils37.withUserAgentSuffix)(
13940
+ headers: (0, import_provider_utils39.withUserAgentSuffix)(
13693
13941
  {
13694
13942
  "Content-Type": "application/json",
13695
13943
  ...headers
13696
13944
  },
13697
13945
  `ai-sdk/${VERSION}`,
13698
- (0, import_provider_utils37.getRuntimeEnvironmentUserAgent)()
13946
+ (0, import_provider_utils39.getRuntimeEnvironmentUserAgent)()
13699
13947
  ),
13700
13948
  signal: abortController.signal
13701
13949
  }).catch((err) => {
@@ -13723,7 +13971,7 @@ async function callCompletionApi({
13723
13971
  }
13724
13972
  case "data": {
13725
13973
  await consumeStream({
13726
- stream: (0, import_provider_utils37.parseJsonEventStream)({
13974
+ stream: (0, import_provider_utils39.parseJsonEventStream)({
13727
13975
  stream: response.body,
13728
13976
  schema: uiMessageChunkSchema
13729
13977
  }).pipeThrough(
@@ -13775,7 +14023,7 @@ async function callCompletionApi({
13775
14023
  }
13776
14024
 
13777
14025
  // src/ui/chat.ts
13778
- var import_provider_utils40 = require("@ai-sdk/provider-utils");
14026
+ var import_provider_utils42 = require("@ai-sdk/provider-utils");
13779
14027
 
13780
14028
  // src/ui/convert-file-list-to-file-ui-parts.ts
13781
14029
  async function convertFileListToFileUIParts(files) {
@@ -13808,10 +14056,10 @@ async function convertFileListToFileUIParts(files) {
13808
14056
  }
13809
14057
 
13810
14058
  // src/ui/default-chat-transport.ts
13811
- var import_provider_utils39 = require("@ai-sdk/provider-utils");
14059
+ var import_provider_utils41 = require("@ai-sdk/provider-utils");
13812
14060
 
13813
14061
  // src/ui/http-chat-transport.ts
13814
- var import_provider_utils38 = require("@ai-sdk/provider-utils");
14062
+ var import_provider_utils40 = require("@ai-sdk/provider-utils");
13815
14063
  var HttpChatTransport = class {
13816
14064
  constructor({
13817
14065
  api = "/api/chat",
@@ -13835,12 +14083,12 @@ var HttpChatTransport = class {
13835
14083
  ...options
13836
14084
  }) {
13837
14085
  var _a22, _b, _c, _d, _e;
13838
- const resolvedBody = await (0, import_provider_utils38.resolve)(this.body);
13839
- const resolvedHeaders = await (0, import_provider_utils38.resolve)(this.headers);
13840
- const resolvedCredentials = await (0, import_provider_utils38.resolve)(this.credentials);
14086
+ const resolvedBody = await (0, import_provider_utils40.resolve)(this.body);
14087
+ const resolvedHeaders = await (0, import_provider_utils40.resolve)(this.headers);
14088
+ const resolvedCredentials = await (0, import_provider_utils40.resolve)(this.credentials);
13841
14089
  const baseHeaders = {
13842
- ...(0, import_provider_utils38.normalizeHeaders)(resolvedHeaders),
13843
- ...(0, import_provider_utils38.normalizeHeaders)(options.headers)
14090
+ ...(0, import_provider_utils40.normalizeHeaders)(resolvedHeaders),
14091
+ ...(0, import_provider_utils40.normalizeHeaders)(options.headers)
13844
14092
  };
13845
14093
  const preparedRequest = await ((_a22 = this.prepareSendMessagesRequest) == null ? void 0 : _a22.call(this, {
13846
14094
  api: this.api,
@@ -13854,7 +14102,7 @@ var HttpChatTransport = class {
13854
14102
  messageId: options.messageId
13855
14103
  }));
13856
14104
  const api = (_b = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b : this.api;
13857
- const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils38.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
14105
+ const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils40.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
13858
14106
  const body = (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : {
13859
14107
  ...resolvedBody,
13860
14108
  ...options.body,
@@ -13887,12 +14135,12 @@ var HttpChatTransport = class {
13887
14135
  }
13888
14136
  async reconnectToStream(options) {
13889
14137
  var _a22, _b, _c, _d, _e;
13890
- const resolvedBody = await (0, import_provider_utils38.resolve)(this.body);
13891
- const resolvedHeaders = await (0, import_provider_utils38.resolve)(this.headers);
13892
- const resolvedCredentials = await (0, import_provider_utils38.resolve)(this.credentials);
14138
+ const resolvedBody = await (0, import_provider_utils40.resolve)(this.body);
14139
+ const resolvedHeaders = await (0, import_provider_utils40.resolve)(this.headers);
14140
+ const resolvedCredentials = await (0, import_provider_utils40.resolve)(this.credentials);
13893
14141
  const baseHeaders = {
13894
- ...(0, import_provider_utils38.normalizeHeaders)(resolvedHeaders),
13895
- ...(0, import_provider_utils38.normalizeHeaders)(options.headers)
14142
+ ...(0, import_provider_utils40.normalizeHeaders)(resolvedHeaders),
14143
+ ...(0, import_provider_utils40.normalizeHeaders)(options.headers)
13896
14144
  };
13897
14145
  const preparedRequest = await ((_a22 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a22.call(this, {
13898
14146
  api: this.api,
@@ -13903,7 +14151,7 @@ var HttpChatTransport = class {
13903
14151
  requestMetadata: options.metadata
13904
14152
  }));
13905
14153
  const api = (_b = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b : `${this.api}/${options.chatId}/stream`;
13906
- const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils38.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
14154
+ const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils40.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
13907
14155
  const credentials = (_c = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _c : resolvedCredentials;
13908
14156
  const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
13909
14157
  const response = await fetch2(api, {
@@ -13933,7 +14181,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
13933
14181
  super(options);
13934
14182
  }
13935
14183
  processResponseStream(stream) {
13936
- return (0, import_provider_utils39.parseJsonEventStream)({
14184
+ return (0, import_provider_utils41.parseJsonEventStream)({
13937
14185
  stream,
13938
14186
  schema: uiMessageChunkSchema
13939
14187
  }).pipeThrough(
@@ -13952,7 +14200,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
13952
14200
  // src/ui/chat.ts
13953
14201
  var AbstractChat = class {
13954
14202
  constructor({
13955
- generateId: generateId2 = import_provider_utils40.generateId,
14203
+ generateId: generateId2 = import_provider_utils42.generateId,
13956
14204
  id = generateId2(),
13957
14205
  transport = new DefaultChatTransport(),
13958
14206
  messageMetadataSchema,
@@ -14412,7 +14660,7 @@ var DirectChatTransport = class {
14412
14660
  messages,
14413
14661
  abortSignal
14414
14662
  }) {
14415
- const validatedMessages = await validateUIMessages({
14663
+ const validatedMessages = await validateUIMessagesForAgent({
14416
14664
  messages,
14417
14665
  tools: this.agent.tools
14418
14666
  });
@@ -14456,7 +14704,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
14456
14704
  // has at least one tool approval response
14457
14705
  lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
14458
14706
  lastStepToolInvocations.every(
14459
- (part) => part.state === "output-available" || part.state === "output-error" || part.state === "approval-responded"
14707
+ (part) => part.state === "output-available" || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
14460
14708
  )
14461
14709
  );
14462
14710
  }