ai 6.0.268 → 6.0.270

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
@@ -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.270" : "0.0.0-test";
1308
1308
 
1309
1309
  // src/util/download/download.ts
1310
1310
  var download = async ({
@@ -6680,8 +6680,12 @@ function createStitchableStream() {
6680
6680
  let innerStreams = [];
6681
6681
  let controller = null;
6682
6682
  let isClosed = false;
6683
+ let isCancelled = false;
6683
6684
  let waitForNewStream = createResolvablePromise();
6684
6685
  const terminate = () => {
6686
+ if (isCancelled) {
6687
+ return;
6688
+ }
6685
6689
  isClosed = true;
6686
6690
  waitForNewStream.resolve();
6687
6691
  innerStreams.forEach(({ reader, onCancel }) => {
@@ -6692,7 +6696,10 @@ function createStitchableStream() {
6692
6696
  controller == null ? void 0 : controller.close();
6693
6697
  };
6694
6698
  const processPull = async () => {
6695
- var _a22, _b;
6699
+ var _a22;
6700
+ if (isCancelled) {
6701
+ return;
6702
+ }
6696
6703
  if (isClosed && innerStreams.length === 0) {
6697
6704
  controller == null ? void 0 : controller.close();
6698
6705
  return;
@@ -6702,8 +6709,12 @@ function createStitchableStream() {
6702
6709
  await waitForNewStream.promise;
6703
6710
  return processPull();
6704
6711
  }
6712
+ const currentStream = innerStreams[0];
6705
6713
  try {
6706
- const { value, done } = await innerStreams[0].reader.read();
6714
+ const { value, done } = await currentStream.reader.read();
6715
+ if (isCancelled) {
6716
+ return;
6717
+ }
6707
6718
  if (done) {
6708
6719
  innerStreams.shift();
6709
6720
  if (innerStreams.length === 0 && isClosed) {
@@ -6715,7 +6726,10 @@ function createStitchableStream() {
6715
6726
  controller == null ? void 0 : controller.enqueue(value);
6716
6727
  }
6717
6728
  } catch (error) {
6718
- (_b = (_a22 = innerStreams[0]).onError) == null ? void 0 : _b.call(_a22, error);
6729
+ if (isCancelled) {
6730
+ return;
6731
+ }
6732
+ (_a22 = currentStream.onError) == null ? void 0 : _a22.call(currentStream, error);
6719
6733
  controller == null ? void 0 : controller.error(error);
6720
6734
  innerStreams.shift();
6721
6735
  terminate();
@@ -6728,15 +6742,24 @@ function createStitchableStream() {
6728
6742
  },
6729
6743
  pull: processPull,
6730
6744
  async cancel() {
6745
+ isCancelled = true;
6746
+ isClosed = true;
6747
+ waitForNewStream.resolve();
6731
6748
  for (const { reader, onCancel } of innerStreams) {
6732
6749
  onCancel == null ? void 0 : onCancel();
6733
6750
  await reader.cancel();
6734
6751
  }
6735
6752
  innerStreams = [];
6736
- isClosed = true;
6737
6753
  }
6738
6754
  }),
6739
6755
  addStream: (innerStream, callbacks) => {
6756
+ var _a22;
6757
+ if (isCancelled) {
6758
+ (_a22 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a22.call(callbacks);
6759
+ void innerStream.cancel().catch(() => {
6760
+ });
6761
+ return;
6762
+ }
6740
6763
  if (isClosed) {
6741
6764
  throw new Error("Cannot add inner stream: outer stream is closed");
6742
6765
  }
@@ -6751,6 +6774,9 @@ function createStitchableStream() {
6751
6774
  * finish processing and then close the outer stream.
6752
6775
  */
6753
6776
  close: () => {
6777
+ if (isCancelled) {
6778
+ return;
6779
+ }
6754
6780
  isClosed = true;
6755
6781
  waitForNewStream.resolve();
6756
6782
  if (innerStreams.length === 0) {
@@ -10123,7 +10149,13 @@ var DefaultEmbedResult = class {
10123
10149
  };
10124
10150
 
10125
10151
  // src/embed/embed-many.ts
10152
+ var import_provider_utils27 = require("@ai-sdk/provider-utils");
10153
+
10154
+ // src/model/get-embedding-model-max-input-bytes-per-call.ts
10126
10155
  var import_provider_utils26 = require("@ai-sdk/provider-utils");
10156
+ function getEmbeddingModelMaxInputBytesPerCall(model) {
10157
+ return model[import_provider_utils26.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
10158
+ }
10127
10159
 
10128
10160
  // src/util/split-array.ts
10129
10161
  function splitArray(array2, chunkSize) {
@@ -10153,7 +10185,7 @@ async function embedMany({
10153
10185
  maxRetries: maxRetriesArg,
10154
10186
  abortSignal
10155
10187
  });
10156
- const headersWithUserAgent = (0, import_provider_utils26.withUserAgentSuffix)(
10188
+ const headersWithUserAgent = (0, import_provider_utils27.withUserAgentSuffix)(
10157
10189
  headers != null ? headers : {},
10158
10190
  `ai/${VERSION}`
10159
10191
  );
@@ -10180,11 +10212,18 @@ async function embedMany({
10180
10212
  tracer,
10181
10213
  fn: async (span) => {
10182
10214
  var _a22;
10183
- const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
10215
+ const [
10216
+ maxEmbeddingsPerCall,
10217
+ maxInputBytesPerCall,
10218
+ supportsParallelCalls
10219
+ ] = await Promise.all([
10184
10220
  model.maxEmbeddingsPerCall,
10221
+ getEmbeddingModelMaxInputBytesPerCall(model),
10185
10222
  model.supportsParallelCalls
10186
10223
  ]);
10187
- if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
10224
+ const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
10225
+ const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
10226
+ if (!hasEmbeddingLimit && !hasInputByteLimit) {
10188
10227
  const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(() => {
10189
10228
  return recordSpan({
10190
10229
  name: "ai.embedMany.doEmbed",
@@ -10261,7 +10300,11 @@ async function embedMany({
10261
10300
  responses: [response]
10262
10301
  });
10263
10302
  }
10264
- const valueChunks = splitArray(values, maxEmbeddingsPerCall);
10303
+ const valueChunks = splitByEmbeddingLimits({
10304
+ values,
10305
+ maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
10306
+ maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
10307
+ });
10265
10308
  const embeddings = [];
10266
10309
  const warnings = [];
10267
10310
  const responses = [];
@@ -10375,6 +10418,37 @@ async function embedMany({
10375
10418
  }
10376
10419
  });
10377
10420
  }
10421
+ var textEncoder = new TextEncoder();
10422
+ function splitByEmbeddingLimits({
10423
+ values,
10424
+ maxEmbeddingsPerCall,
10425
+ maxInputBytesPerCall
10426
+ }) {
10427
+ if (maxEmbeddingsPerCall <= 0) {
10428
+ throw new Error("maxEmbeddingsPerCall must be greater than 0");
10429
+ }
10430
+ if (maxInputBytesPerCall <= 0) {
10431
+ throw new Error("maxInputBytesPerCall must be greater than 0");
10432
+ }
10433
+ if (values.length === 0) {
10434
+ return [];
10435
+ }
10436
+ const chunks = [];
10437
+ let currentChunk = [];
10438
+ let currentInputBytes = 0;
10439
+ for (const value of values) {
10440
+ const inputBytes = textEncoder.encode(value).length;
10441
+ if (currentChunk.length > 0 && (currentChunk.length >= maxEmbeddingsPerCall || currentInputBytes + inputBytes > maxInputBytesPerCall)) {
10442
+ chunks.push(currentChunk);
10443
+ currentChunk = [];
10444
+ currentInputBytes = 0;
10445
+ }
10446
+ currentChunk.push(value);
10447
+ currentInputBytes += inputBytes;
10448
+ }
10449
+ chunks.push(currentChunk);
10450
+ return chunks;
10451
+ }
10378
10452
  var DefaultEmbedManyResult = class {
10379
10453
  constructor(options) {
10380
10454
  this.values = options.values;
@@ -10387,7 +10461,7 @@ var DefaultEmbedManyResult = class {
10387
10461
  };
10388
10462
 
10389
10463
  // src/generate-image/generate-image.ts
10390
- var import_provider_utils27 = require("@ai-sdk/provider-utils");
10464
+ var import_provider_utils28 = require("@ai-sdk/provider-utils");
10391
10465
  async function generateImage({
10392
10466
  model: modelArg,
10393
10467
  prompt: promptArg,
@@ -10403,7 +10477,7 @@ async function generateImage({
10403
10477
  }) {
10404
10478
  var _a22, _b;
10405
10479
  const model = resolveImageModel(modelArg);
10406
- const headersWithUserAgent = (0, import_provider_utils27.withUserAgentSuffix)(
10480
+ const headersWithUserAgent = (0, import_provider_utils28.withUserAgentSuffix)(
10407
10481
  headers != null ? headers : {},
10408
10482
  `ai/${VERSION}`
10409
10483
  );
@@ -10546,7 +10620,7 @@ function toImageModelV3File(dataContent) {
10546
10620
  if (typeof dataContent === "string" && dataContent.startsWith("data:")) {
10547
10621
  const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(dataContent);
10548
10622
  if (base64Content != null) {
10549
- const uint8Data2 = (0, import_provider_utils27.convertBase64ToUint8Array)(base64Content);
10623
+ const uint8Data2 = (0, import_provider_utils28.convertBase64ToUint8Array)(base64Content);
10550
10624
  return {
10551
10625
  type: "file",
10552
10626
  data: uint8Data2,
@@ -10572,11 +10646,11 @@ function toImageModelV3File(dataContent) {
10572
10646
  var experimental_generateImage = generateImage;
10573
10647
 
10574
10648
  // src/generate-object/generate-object.ts
10575
- var import_provider_utils30 = require("@ai-sdk/provider-utils");
10649
+ var import_provider_utils31 = require("@ai-sdk/provider-utils");
10576
10650
 
10577
10651
  // src/generate-object/output-strategy.ts
10578
10652
  var import_provider31 = require("@ai-sdk/provider");
10579
- var import_provider_utils28 = require("@ai-sdk/provider-utils");
10653
+ var import_provider_utils29 = require("@ai-sdk/provider-utils");
10580
10654
  var noSchemaOutputStrategy = {
10581
10655
  type: "no-schema",
10582
10656
  jsonSchema: async () => void 0,
@@ -10615,7 +10689,7 @@ var objectOutputStrategy = (schema) => ({
10615
10689
  };
10616
10690
  },
10617
10691
  async validateFinalResult(value) {
10618
- return (0, import_provider_utils28.safeValidateTypes)({ value, schema });
10692
+ return (0, import_provider_utils29.safeValidateTypes)({ value, schema });
10619
10693
  },
10620
10694
  createElementStream() {
10621
10695
  throw new import_provider31.UnsupportedFunctionalityError({
@@ -10661,7 +10735,7 @@ var arrayOutputStrategy = (schema) => {
10661
10735
  const resultArray = [];
10662
10736
  for (let i = 0; i < inputArray.length; i++) {
10663
10737
  const element = inputArray[i];
10664
- const result = await (0, import_provider_utils28.safeValidateTypes)({ value: element, schema });
10738
+ const result = await (0, import_provider_utils29.safeValidateTypes)({ value: element, schema });
10665
10739
  if (i === inputArray.length - 1 && !isFinalDelta) {
10666
10740
  continue;
10667
10741
  }
@@ -10703,7 +10777,7 @@ var arrayOutputStrategy = (schema) => {
10703
10777
  const inputArray = value.elements;
10704
10778
  const resultArray = [];
10705
10779
  for (const element of inputArray) {
10706
- const result = await (0, import_provider_utils28.safeValidateTypes)({ value: element, schema });
10780
+ const result = await (0, import_provider_utils29.safeValidateTypes)({ value: element, schema });
10707
10781
  if (!result.success) {
10708
10782
  return result;
10709
10783
  }
@@ -10822,9 +10896,9 @@ function getOutputStrategy({
10822
10896
  }) {
10823
10897
  switch (output) {
10824
10898
  case "object":
10825
- return objectOutputStrategy((0, import_provider_utils28.asSchema)(schema));
10899
+ return objectOutputStrategy((0, import_provider_utils29.asSchema)(schema));
10826
10900
  case "array":
10827
- return arrayOutputStrategy((0, import_provider_utils28.asSchema)(schema));
10901
+ return arrayOutputStrategy((0, import_provider_utils29.asSchema)(schema));
10828
10902
  case "enum":
10829
10903
  return enumOutputStrategy(enumValues);
10830
10904
  case "no-schema":
@@ -10838,9 +10912,9 @@ function getOutputStrategy({
10838
10912
 
10839
10913
  // src/generate-object/parse-and-validate-object-result.ts
10840
10914
  var import_provider32 = require("@ai-sdk/provider");
10841
- var import_provider_utils29 = require("@ai-sdk/provider-utils");
10915
+ var import_provider_utils30 = require("@ai-sdk/provider-utils");
10842
10916
  async function parseAndValidateObjectResult(result, outputStrategy, context2) {
10843
- const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: result });
10917
+ const parseResult = await (0, import_provider_utils30.safeParseJSON)({ text: result });
10844
10918
  if (!parseResult.success) {
10845
10919
  throw new NoObjectGeneratedError({
10846
10920
  message: "No object generated: could not parse the response.",
@@ -11012,7 +11086,7 @@ function validateObjectGenerationInput({
11012
11086
  }
11013
11087
 
11014
11088
  // src/generate-object/generate-object.ts
11015
- var originalGenerateId3 = (0, import_provider_utils30.createIdGenerator)({ prefix: "aiobj", size: 24 });
11089
+ var originalGenerateId3 = (0, import_provider_utils31.createIdGenerator)({ prefix: "aiobj", size: 24 });
11016
11090
  async function generateObject(options) {
11017
11091
  const {
11018
11092
  model: modelArg,
@@ -11058,7 +11132,7 @@ async function generateObject(options) {
11058
11132
  enumValues
11059
11133
  });
11060
11134
  const callSettings = prepareCallSettings(settings);
11061
- const headersWithUserAgent = (0, import_provider_utils30.withUserAgentSuffix)(
11135
+ const headersWithUserAgent = (0, import_provider_utils31.withUserAgentSuffix)(
11062
11136
  headers != null ? headers : {},
11063
11137
  `ai/${VERSION}`
11064
11138
  );
@@ -11285,7 +11359,7 @@ var DefaultGenerateObjectResult = class {
11285
11359
  };
11286
11360
 
11287
11361
  // src/generate-object/stream-object.ts
11288
- var import_provider_utils32 = require("@ai-sdk/provider-utils");
11362
+ var import_provider_utils33 = require("@ai-sdk/provider-utils");
11289
11363
 
11290
11364
  // src/util/cosine-similarity.ts
11291
11365
  function cosineSimilarity(vector1, vector2) {
@@ -11400,7 +11474,7 @@ var SerialJobExecutor = class {
11400
11474
  };
11401
11475
 
11402
11476
  // src/util/simulate-readable-stream.ts
11403
- var import_provider_utils31 = require("@ai-sdk/provider-utils");
11477
+ var import_provider_utils32 = require("@ai-sdk/provider-utils");
11404
11478
  function simulateReadableStream({
11405
11479
  chunks,
11406
11480
  initialDelayInMs = 0,
@@ -11408,7 +11482,7 @@ function simulateReadableStream({
11408
11482
  _internal
11409
11483
  }) {
11410
11484
  var _a22;
11411
- const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : import_provider_utils31.delay;
11485
+ const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : import_provider_utils32.delay;
11412
11486
  let index = 0;
11413
11487
  return new ReadableStream({
11414
11488
  async pull(controller) {
@@ -11423,7 +11497,7 @@ function simulateReadableStream({
11423
11497
  }
11424
11498
 
11425
11499
  // src/generate-object/stream-object.ts
11426
- var originalGenerateId4 = (0, import_provider_utils32.createIdGenerator)({ prefix: "aiobj", size: 24 });
11500
+ var originalGenerateId4 = (0, import_provider_utils33.createIdGenerator)({ prefix: "aiobj", size: 24 });
11427
11501
  async function markPromiseAsHandled(promise) {
11428
11502
  try {
11429
11503
  await promise;
@@ -11522,13 +11596,13 @@ var DefaultStreamObjectResult = class {
11522
11596
  currentDate,
11523
11597
  now: now2
11524
11598
  }) {
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();
11599
+ this._object = new import_provider_utils33.DelayedPromise();
11600
+ this._usage = new import_provider_utils33.DelayedPromise();
11601
+ this._providerMetadata = new import_provider_utils33.DelayedPromise();
11602
+ this._warnings = new import_provider_utils33.DelayedPromise();
11603
+ this._request = new import_provider_utils33.DelayedPromise();
11604
+ this._response = new import_provider_utils33.DelayedPromise();
11605
+ this._finishReason = new import_provider_utils33.DelayedPromise();
11532
11606
  const model = resolveLanguageModel(modelArg);
11533
11607
  const { maxRetries, retry } = prepareRetries({
11534
11608
  maxRetries: maxRetriesArg,
@@ -12005,7 +12079,7 @@ var DefaultStreamObjectResult = class {
12005
12079
  };
12006
12080
 
12007
12081
  // src/generate-speech/generate-speech.ts
12008
- var import_provider_utils33 = require("@ai-sdk/provider-utils");
12082
+ var import_provider_utils34 = require("@ai-sdk/provider-utils");
12009
12083
 
12010
12084
  // src/generate-speech/generated-audio-file.ts
12011
12085
  var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
@@ -12051,7 +12125,7 @@ async function generateSpeech({
12051
12125
  if (!resolvedModel) {
12052
12126
  throw new Error("Model could not be resolved");
12053
12127
  }
12054
- const headersWithUserAgent = (0, import_provider_utils33.withUserAgentSuffix)(
12128
+ const headersWithUserAgent = (0, import_provider_utils34.withUserAgentSuffix)(
12055
12129
  headers != null ? headers : {},
12056
12130
  `ai/${VERSION}`
12057
12131
  );
@@ -12198,7 +12272,7 @@ function pruneMessages({
12198
12272
  }
12199
12273
 
12200
12274
  // src/generate-text/smooth-stream.ts
12201
- var import_provider_utils34 = require("@ai-sdk/provider-utils");
12275
+ var import_provider_utils35 = require("@ai-sdk/provider-utils");
12202
12276
  var import_provider33 = require("@ai-sdk/provider");
12203
12277
  var CHUNKING_REGEXPS = {
12204
12278
  word: /\S+\s+/m,
@@ -12207,7 +12281,7 @@ var CHUNKING_REGEXPS = {
12207
12281
  function smoothStream({
12208
12282
  delayInMs = 10,
12209
12283
  chunking = "word",
12210
- _internal: { delay = import_provider_utils34.delay } = {}
12284
+ _internal: { delay = import_provider_utils35.delay } = {}
12211
12285
  } = {}) {
12212
12286
  let detectChunk;
12213
12287
  if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
@@ -12296,7 +12370,7 @@ function smoothStream({
12296
12370
  }
12297
12371
 
12298
12372
  // src/generate-video/generate-video.ts
12299
- var import_provider_utils35 = require("@ai-sdk/provider-utils");
12373
+ var import_provider_utils36 = require("@ai-sdk/provider-utils");
12300
12374
  var defaultDownload = createDownload();
12301
12375
  async function experimental_generateVideo({
12302
12376
  model: modelArg,
@@ -12319,7 +12393,7 @@ async function experimental_generateVideo({
12319
12393
  }) {
12320
12394
  var _a22, _b;
12321
12395
  const model = resolveVideoModel(modelArg);
12322
- const headersWithUserAgent = (0, import_provider_utils35.withUserAgentSuffix)(
12396
+ const headersWithUserAgent = (0, import_provider_utils36.withUserAgentSuffix)(
12323
12397
  headers != null ? headers : {},
12324
12398
  `ai/${VERSION}`
12325
12399
  );
@@ -12504,14 +12578,14 @@ function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
12504
12578
  }
12505
12579
  if (dataContent.startsWith("data:")) {
12506
12580
  const { mediaType, base64Content } = splitDataUrl(dataContent);
12507
- const data = (0, import_provider_utils35.convertBase64ToUint8Array)(base64Content != null ? base64Content : "");
12581
+ const data = (0, import_provider_utils36.convertBase64ToUint8Array)(base64Content != null ? base64Content : "");
12508
12582
  return {
12509
12583
  type: "file",
12510
12584
  mediaType: mediaType != null ? mediaType : detectFileMediaType(data, restrictToImages),
12511
12585
  data
12512
12586
  };
12513
12587
  }
12514
- const bytes = (0, import_provider_utils35.convertBase64ToUint8Array)(dataContent);
12588
+ const bytes = (0, import_provider_utils36.convertBase64ToUint8Array)(dataContent);
12515
12589
  return {
12516
12590
  type: "file",
12517
12591
  mediaType: detectFileMediaType(bytes, restrictToImages),
@@ -13048,6 +13122,7 @@ var doWrap = ({
13048
13122
  };
13049
13123
 
13050
13124
  // src/middleware/wrap-embedding-model.ts
13125
+ var import_provider_utils37 = require("@ai-sdk/provider-utils");
13051
13126
  var wrapEmbeddingModel = ({
13052
13127
  model,
13053
13128
  middleware: middlewareArg,
@@ -13082,6 +13157,7 @@ var doWrap2 = ({
13082
13157
  provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
13083
13158
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
13084
13159
  maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
13160
+ [import_provider_utils37.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL]: getEmbeddingModelMaxInputBytesPerCall(model),
13085
13161
  supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
13086
13162
  async doEmbed(params) {
13087
13163
  const transformedParams = await doTransform({ params });
@@ -13570,7 +13646,7 @@ var DefaultRerankResult = class {
13570
13646
  };
13571
13647
 
13572
13648
  // src/transcribe/transcribe.ts
13573
- var import_provider_utils36 = require("@ai-sdk/provider-utils");
13649
+ var import_provider_utils38 = require("@ai-sdk/provider-utils");
13574
13650
  var defaultDownload2 = createDownload();
13575
13651
  async function transcribe({
13576
13652
  model,
@@ -13589,7 +13665,7 @@ async function transcribe({
13589
13665
  maxRetries: maxRetriesArg,
13590
13666
  abortSignal
13591
13667
  });
13592
- const headersWithUserAgent = (0, import_provider_utils36.withUserAgentSuffix)(
13668
+ const headersWithUserAgent = (0, import_provider_utils38.withUserAgentSuffix)(
13593
13669
  headers != null ? headers : {},
13594
13670
  `ai/${VERSION}`
13595
13671
  );
@@ -13641,7 +13717,7 @@ var DefaultTranscriptionResult = class {
13641
13717
  };
13642
13718
 
13643
13719
  // src/ui/call-completion-api.ts
13644
- var import_provider_utils37 = require("@ai-sdk/provider-utils");
13720
+ var import_provider_utils39 = require("@ai-sdk/provider-utils");
13645
13721
 
13646
13722
  // src/ui/process-text-stream.ts
13647
13723
  async function processTextStream({
@@ -13689,13 +13765,13 @@ async function callCompletionApi({
13689
13765
  ...body
13690
13766
  }),
13691
13767
  credentials,
13692
- headers: (0, import_provider_utils37.withUserAgentSuffix)(
13768
+ headers: (0, import_provider_utils39.withUserAgentSuffix)(
13693
13769
  {
13694
13770
  "Content-Type": "application/json",
13695
13771
  ...headers
13696
13772
  },
13697
13773
  `ai-sdk/${VERSION}`,
13698
- (0, import_provider_utils37.getRuntimeEnvironmentUserAgent)()
13774
+ (0, import_provider_utils39.getRuntimeEnvironmentUserAgent)()
13699
13775
  ),
13700
13776
  signal: abortController.signal
13701
13777
  }).catch((err) => {
@@ -13723,7 +13799,7 @@ async function callCompletionApi({
13723
13799
  }
13724
13800
  case "data": {
13725
13801
  await consumeStream({
13726
- stream: (0, import_provider_utils37.parseJsonEventStream)({
13802
+ stream: (0, import_provider_utils39.parseJsonEventStream)({
13727
13803
  stream: response.body,
13728
13804
  schema: uiMessageChunkSchema
13729
13805
  }).pipeThrough(
@@ -13775,7 +13851,7 @@ async function callCompletionApi({
13775
13851
  }
13776
13852
 
13777
13853
  // src/ui/chat.ts
13778
- var import_provider_utils40 = require("@ai-sdk/provider-utils");
13854
+ var import_provider_utils42 = require("@ai-sdk/provider-utils");
13779
13855
 
13780
13856
  // src/ui/convert-file-list-to-file-ui-parts.ts
13781
13857
  async function convertFileListToFileUIParts(files) {
@@ -13808,10 +13884,10 @@ async function convertFileListToFileUIParts(files) {
13808
13884
  }
13809
13885
 
13810
13886
  // src/ui/default-chat-transport.ts
13811
- var import_provider_utils39 = require("@ai-sdk/provider-utils");
13887
+ var import_provider_utils41 = require("@ai-sdk/provider-utils");
13812
13888
 
13813
13889
  // src/ui/http-chat-transport.ts
13814
- var import_provider_utils38 = require("@ai-sdk/provider-utils");
13890
+ var import_provider_utils40 = require("@ai-sdk/provider-utils");
13815
13891
  var HttpChatTransport = class {
13816
13892
  constructor({
13817
13893
  api = "/api/chat",
@@ -13835,12 +13911,12 @@ var HttpChatTransport = class {
13835
13911
  ...options
13836
13912
  }) {
13837
13913
  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);
13914
+ const resolvedBody = await (0, import_provider_utils40.resolve)(this.body);
13915
+ const resolvedHeaders = await (0, import_provider_utils40.resolve)(this.headers);
13916
+ const resolvedCredentials = await (0, import_provider_utils40.resolve)(this.credentials);
13841
13917
  const baseHeaders = {
13842
- ...(0, import_provider_utils38.normalizeHeaders)(resolvedHeaders),
13843
- ...(0, import_provider_utils38.normalizeHeaders)(options.headers)
13918
+ ...(0, import_provider_utils40.normalizeHeaders)(resolvedHeaders),
13919
+ ...(0, import_provider_utils40.normalizeHeaders)(options.headers)
13844
13920
  };
13845
13921
  const preparedRequest = await ((_a22 = this.prepareSendMessagesRequest) == null ? void 0 : _a22.call(this, {
13846
13922
  api: this.api,
@@ -13854,7 +13930,7 @@ var HttpChatTransport = class {
13854
13930
  messageId: options.messageId
13855
13931
  }));
13856
13932
  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;
13933
+ const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils40.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
13858
13934
  const body = (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : {
13859
13935
  ...resolvedBody,
13860
13936
  ...options.body,
@@ -13887,12 +13963,12 @@ var HttpChatTransport = class {
13887
13963
  }
13888
13964
  async reconnectToStream(options) {
13889
13965
  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);
13966
+ const resolvedBody = await (0, import_provider_utils40.resolve)(this.body);
13967
+ const resolvedHeaders = await (0, import_provider_utils40.resolve)(this.headers);
13968
+ const resolvedCredentials = await (0, import_provider_utils40.resolve)(this.credentials);
13893
13969
  const baseHeaders = {
13894
- ...(0, import_provider_utils38.normalizeHeaders)(resolvedHeaders),
13895
- ...(0, import_provider_utils38.normalizeHeaders)(options.headers)
13970
+ ...(0, import_provider_utils40.normalizeHeaders)(resolvedHeaders),
13971
+ ...(0, import_provider_utils40.normalizeHeaders)(options.headers)
13896
13972
  };
13897
13973
  const preparedRequest = await ((_a22 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a22.call(this, {
13898
13974
  api: this.api,
@@ -13903,7 +13979,7 @@ var HttpChatTransport = class {
13903
13979
  requestMetadata: options.metadata
13904
13980
  }));
13905
13981
  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;
13982
+ const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils40.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
13907
13983
  const credentials = (_c = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _c : resolvedCredentials;
13908
13984
  const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
13909
13985
  const response = await fetch2(api, {
@@ -13933,7 +14009,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
13933
14009
  super(options);
13934
14010
  }
13935
14011
  processResponseStream(stream) {
13936
- return (0, import_provider_utils39.parseJsonEventStream)({
14012
+ return (0, import_provider_utils41.parseJsonEventStream)({
13937
14013
  stream,
13938
14014
  schema: uiMessageChunkSchema
13939
14015
  }).pipeThrough(
@@ -13952,7 +14028,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
13952
14028
  // src/ui/chat.ts
13953
14029
  var AbstractChat = class {
13954
14030
  constructor({
13955
- generateId: generateId2 = import_provider_utils40.generateId,
14031
+ generateId: generateId2 = import_provider_utils42.generateId,
13956
14032
  id = generateId2(),
13957
14033
  transport = new DefaultChatTransport(),
13958
14034
  messageMetadataSchema,
@@ -14456,7 +14532,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
14456
14532
  // has at least one tool approval response
14457
14533
  lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
14458
14534
  lastStepToolInvocations.every(
14459
- (part) => part.state === "output-available" || part.state === "output-error" || part.state === "approval-responded"
14535
+ (part) => part.state === "output-available" || part.state === "output-error" || part.state === "output-denied" || part.state === "approval-responded"
14460
14536
  )
14461
14537
  );
14462
14538
  }