ai 6.0.266 → 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.266" : "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 ({
@@ -3009,6 +3009,7 @@ async function executeToolCall({
3009
3009
  onToolCallStart,
3010
3010
  onToolCallFinish
3011
3011
  }) {
3012
+ var _a22;
3012
3013
  const { toolName, toolCallId, input } = toolCall;
3013
3014
  const tool2 = tools == null ? void 0 : tools[toolName];
3014
3015
  if ((tool2 == null ? void 0 : tool2.execute) == null) {
@@ -3033,6 +3034,12 @@ async function executeToolCall({
3033
3034
  operationId: "ai.toolCall",
3034
3035
  telemetry
3035
3036
  }),
3037
+ ...Object.fromEntries(
3038
+ Object.entries((_a22 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a22 : {}).map(([key, value]) => [
3039
+ `ai.telemetry.metadata.${key}`,
3040
+ value
3041
+ ])
3042
+ ),
3036
3043
  "ai.toolCall.name": toolName,
3037
3044
  "ai.toolCall.id": toolCallId,
3038
3045
  "ai.toolCall.args": {
@@ -5202,7 +5209,7 @@ async function generateText({
5202
5209
  ]
5203
5210
  });
5204
5211
  let resolvedOutput;
5205
- if (lastStep.finishReason === "stop") {
5212
+ if (lastStep.finishReason === "stop" || lastStep.finishReason !== "tool-calls" && lastStep.text.length > 0) {
5206
5213
  const outputSpecification = output != null ? output : text();
5207
5214
  resolvedOutput = await outputSpecification.parseCompleteOutput(
5208
5215
  { text: lastStep.text },
@@ -6673,8 +6680,12 @@ function createStitchableStream() {
6673
6680
  let innerStreams = [];
6674
6681
  let controller = null;
6675
6682
  let isClosed = false;
6683
+ let isCancelled = false;
6676
6684
  let waitForNewStream = createResolvablePromise();
6677
6685
  const terminate = () => {
6686
+ if (isCancelled) {
6687
+ return;
6688
+ }
6678
6689
  isClosed = true;
6679
6690
  waitForNewStream.resolve();
6680
6691
  innerStreams.forEach(({ reader, onCancel }) => {
@@ -6685,7 +6696,10 @@ function createStitchableStream() {
6685
6696
  controller == null ? void 0 : controller.close();
6686
6697
  };
6687
6698
  const processPull = async () => {
6688
- var _a22, _b;
6699
+ var _a22;
6700
+ if (isCancelled) {
6701
+ return;
6702
+ }
6689
6703
  if (isClosed && innerStreams.length === 0) {
6690
6704
  controller == null ? void 0 : controller.close();
6691
6705
  return;
@@ -6695,8 +6709,12 @@ function createStitchableStream() {
6695
6709
  await waitForNewStream.promise;
6696
6710
  return processPull();
6697
6711
  }
6712
+ const currentStream = innerStreams[0];
6698
6713
  try {
6699
- const { value, done } = await innerStreams[0].reader.read();
6714
+ const { value, done } = await currentStream.reader.read();
6715
+ if (isCancelled) {
6716
+ return;
6717
+ }
6700
6718
  if (done) {
6701
6719
  innerStreams.shift();
6702
6720
  if (innerStreams.length === 0 && isClosed) {
@@ -6708,7 +6726,10 @@ function createStitchableStream() {
6708
6726
  controller == null ? void 0 : controller.enqueue(value);
6709
6727
  }
6710
6728
  } catch (error) {
6711
- (_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);
6712
6733
  controller == null ? void 0 : controller.error(error);
6713
6734
  innerStreams.shift();
6714
6735
  terminate();
@@ -6721,15 +6742,24 @@ function createStitchableStream() {
6721
6742
  },
6722
6743
  pull: processPull,
6723
6744
  async cancel() {
6745
+ isCancelled = true;
6746
+ isClosed = true;
6747
+ waitForNewStream.resolve();
6724
6748
  for (const { reader, onCancel } of innerStreams) {
6725
6749
  onCancel == null ? void 0 : onCancel();
6726
6750
  await reader.cancel();
6727
6751
  }
6728
6752
  innerStreams = [];
6729
- isClosed = true;
6730
6753
  }
6731
6754
  }),
6732
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
+ }
6733
6763
  if (isClosed) {
6734
6764
  throw new Error("Cannot add inner stream: outer stream is closed");
6735
6765
  }
@@ -6744,6 +6774,9 @@ function createStitchableStream() {
6744
6774
  * finish processing and then close the outer stream.
6745
6775
  */
6746
6776
  close: () => {
6777
+ if (isCancelled) {
6778
+ return;
6779
+ }
6747
6780
  isClosed = true;
6748
6781
  waitForNewStream.resolve();
6749
6782
  if (innerStreams.length === 0) {
@@ -10116,7 +10149,13 @@ var DefaultEmbedResult = class {
10116
10149
  };
10117
10150
 
10118
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
10119
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
+ }
10120
10159
 
10121
10160
  // src/util/split-array.ts
10122
10161
  function splitArray(array2, chunkSize) {
@@ -10146,7 +10185,7 @@ async function embedMany({
10146
10185
  maxRetries: maxRetriesArg,
10147
10186
  abortSignal
10148
10187
  });
10149
- const headersWithUserAgent = (0, import_provider_utils26.withUserAgentSuffix)(
10188
+ const headersWithUserAgent = (0, import_provider_utils27.withUserAgentSuffix)(
10150
10189
  headers != null ? headers : {},
10151
10190
  `ai/${VERSION}`
10152
10191
  );
@@ -10173,11 +10212,18 @@ async function embedMany({
10173
10212
  tracer,
10174
10213
  fn: async (span) => {
10175
10214
  var _a22;
10176
- const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
10215
+ const [
10216
+ maxEmbeddingsPerCall,
10217
+ maxInputBytesPerCall,
10218
+ supportsParallelCalls
10219
+ ] = await Promise.all([
10177
10220
  model.maxEmbeddingsPerCall,
10221
+ getEmbeddingModelMaxInputBytesPerCall(model),
10178
10222
  model.supportsParallelCalls
10179
10223
  ]);
10180
- if (maxEmbeddingsPerCall == null || maxEmbeddingsPerCall === Infinity) {
10224
+ const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
10225
+ const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
10226
+ if (!hasEmbeddingLimit && !hasInputByteLimit) {
10181
10227
  const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(() => {
10182
10228
  return recordSpan({
10183
10229
  name: "ai.embedMany.doEmbed",
@@ -10254,7 +10300,11 @@ async function embedMany({
10254
10300
  responses: [response]
10255
10301
  });
10256
10302
  }
10257
- const valueChunks = splitArray(values, maxEmbeddingsPerCall);
10303
+ const valueChunks = splitByEmbeddingLimits({
10304
+ values,
10305
+ maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
10306
+ maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
10307
+ });
10258
10308
  const embeddings = [];
10259
10309
  const warnings = [];
10260
10310
  const responses = [];
@@ -10368,6 +10418,37 @@ async function embedMany({
10368
10418
  }
10369
10419
  });
10370
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
+ }
10371
10452
  var DefaultEmbedManyResult = class {
10372
10453
  constructor(options) {
10373
10454
  this.values = options.values;
@@ -10380,7 +10461,7 @@ var DefaultEmbedManyResult = class {
10380
10461
  };
10381
10462
 
10382
10463
  // src/generate-image/generate-image.ts
10383
- var import_provider_utils27 = require("@ai-sdk/provider-utils");
10464
+ var import_provider_utils28 = require("@ai-sdk/provider-utils");
10384
10465
  async function generateImage({
10385
10466
  model: modelArg,
10386
10467
  prompt: promptArg,
@@ -10396,7 +10477,7 @@ async function generateImage({
10396
10477
  }) {
10397
10478
  var _a22, _b;
10398
10479
  const model = resolveImageModel(modelArg);
10399
- const headersWithUserAgent = (0, import_provider_utils27.withUserAgentSuffix)(
10480
+ const headersWithUserAgent = (0, import_provider_utils28.withUserAgentSuffix)(
10400
10481
  headers != null ? headers : {},
10401
10482
  `ai/${VERSION}`
10402
10483
  );
@@ -10539,7 +10620,7 @@ function toImageModelV3File(dataContent) {
10539
10620
  if (typeof dataContent === "string" && dataContent.startsWith("data:")) {
10540
10621
  const { mediaType: dataUrlMediaType, base64Content } = splitDataUrl(dataContent);
10541
10622
  if (base64Content != null) {
10542
- const uint8Data2 = (0, import_provider_utils27.convertBase64ToUint8Array)(base64Content);
10623
+ const uint8Data2 = (0, import_provider_utils28.convertBase64ToUint8Array)(base64Content);
10543
10624
  return {
10544
10625
  type: "file",
10545
10626
  data: uint8Data2,
@@ -10565,11 +10646,11 @@ function toImageModelV3File(dataContent) {
10565
10646
  var experimental_generateImage = generateImage;
10566
10647
 
10567
10648
  // src/generate-object/generate-object.ts
10568
- var import_provider_utils30 = require("@ai-sdk/provider-utils");
10649
+ var import_provider_utils31 = require("@ai-sdk/provider-utils");
10569
10650
 
10570
10651
  // src/generate-object/output-strategy.ts
10571
10652
  var import_provider31 = require("@ai-sdk/provider");
10572
- var import_provider_utils28 = require("@ai-sdk/provider-utils");
10653
+ var import_provider_utils29 = require("@ai-sdk/provider-utils");
10573
10654
  var noSchemaOutputStrategy = {
10574
10655
  type: "no-schema",
10575
10656
  jsonSchema: async () => void 0,
@@ -10608,7 +10689,7 @@ var objectOutputStrategy = (schema) => ({
10608
10689
  };
10609
10690
  },
10610
10691
  async validateFinalResult(value) {
10611
- return (0, import_provider_utils28.safeValidateTypes)({ value, schema });
10692
+ return (0, import_provider_utils29.safeValidateTypes)({ value, schema });
10612
10693
  },
10613
10694
  createElementStream() {
10614
10695
  throw new import_provider31.UnsupportedFunctionalityError({
@@ -10654,7 +10735,7 @@ var arrayOutputStrategy = (schema) => {
10654
10735
  const resultArray = [];
10655
10736
  for (let i = 0; i < inputArray.length; i++) {
10656
10737
  const element = inputArray[i];
10657
- const result = await (0, import_provider_utils28.safeValidateTypes)({ value: element, schema });
10738
+ const result = await (0, import_provider_utils29.safeValidateTypes)({ value: element, schema });
10658
10739
  if (i === inputArray.length - 1 && !isFinalDelta) {
10659
10740
  continue;
10660
10741
  }
@@ -10696,7 +10777,7 @@ var arrayOutputStrategy = (schema) => {
10696
10777
  const inputArray = value.elements;
10697
10778
  const resultArray = [];
10698
10779
  for (const element of inputArray) {
10699
- const result = await (0, import_provider_utils28.safeValidateTypes)({ value: element, schema });
10780
+ const result = await (0, import_provider_utils29.safeValidateTypes)({ value: element, schema });
10700
10781
  if (!result.success) {
10701
10782
  return result;
10702
10783
  }
@@ -10815,9 +10896,9 @@ function getOutputStrategy({
10815
10896
  }) {
10816
10897
  switch (output) {
10817
10898
  case "object":
10818
- return objectOutputStrategy((0, import_provider_utils28.asSchema)(schema));
10899
+ return objectOutputStrategy((0, import_provider_utils29.asSchema)(schema));
10819
10900
  case "array":
10820
- return arrayOutputStrategy((0, import_provider_utils28.asSchema)(schema));
10901
+ return arrayOutputStrategy((0, import_provider_utils29.asSchema)(schema));
10821
10902
  case "enum":
10822
10903
  return enumOutputStrategy(enumValues);
10823
10904
  case "no-schema":
@@ -10831,9 +10912,9 @@ function getOutputStrategy({
10831
10912
 
10832
10913
  // src/generate-object/parse-and-validate-object-result.ts
10833
10914
  var import_provider32 = require("@ai-sdk/provider");
10834
- var import_provider_utils29 = require("@ai-sdk/provider-utils");
10915
+ var import_provider_utils30 = require("@ai-sdk/provider-utils");
10835
10916
  async function parseAndValidateObjectResult(result, outputStrategy, context2) {
10836
- const parseResult = await (0, import_provider_utils29.safeParseJSON)({ text: result });
10917
+ const parseResult = await (0, import_provider_utils30.safeParseJSON)({ text: result });
10837
10918
  if (!parseResult.success) {
10838
10919
  throw new NoObjectGeneratedError({
10839
10920
  message: "No object generated: could not parse the response.",
@@ -11005,7 +11086,7 @@ function validateObjectGenerationInput({
11005
11086
  }
11006
11087
 
11007
11088
  // src/generate-object/generate-object.ts
11008
- var originalGenerateId3 = (0, import_provider_utils30.createIdGenerator)({ prefix: "aiobj", size: 24 });
11089
+ var originalGenerateId3 = (0, import_provider_utils31.createIdGenerator)({ prefix: "aiobj", size: 24 });
11009
11090
  async function generateObject(options) {
11010
11091
  const {
11011
11092
  model: modelArg,
@@ -11051,7 +11132,7 @@ async function generateObject(options) {
11051
11132
  enumValues
11052
11133
  });
11053
11134
  const callSettings = prepareCallSettings(settings);
11054
- const headersWithUserAgent = (0, import_provider_utils30.withUserAgentSuffix)(
11135
+ const headersWithUserAgent = (0, import_provider_utils31.withUserAgentSuffix)(
11055
11136
  headers != null ? headers : {},
11056
11137
  `ai/${VERSION}`
11057
11138
  );
@@ -11278,7 +11359,7 @@ var DefaultGenerateObjectResult = class {
11278
11359
  };
11279
11360
 
11280
11361
  // src/generate-object/stream-object.ts
11281
- var import_provider_utils32 = require("@ai-sdk/provider-utils");
11362
+ var import_provider_utils33 = require("@ai-sdk/provider-utils");
11282
11363
 
11283
11364
  // src/util/cosine-similarity.ts
11284
11365
  function cosineSimilarity(vector1, vector2) {
@@ -11393,7 +11474,7 @@ var SerialJobExecutor = class {
11393
11474
  };
11394
11475
 
11395
11476
  // src/util/simulate-readable-stream.ts
11396
- var import_provider_utils31 = require("@ai-sdk/provider-utils");
11477
+ var import_provider_utils32 = require("@ai-sdk/provider-utils");
11397
11478
  function simulateReadableStream({
11398
11479
  chunks,
11399
11480
  initialDelayInMs = 0,
@@ -11401,7 +11482,7 @@ function simulateReadableStream({
11401
11482
  _internal
11402
11483
  }) {
11403
11484
  var _a22;
11404
- 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;
11405
11486
  let index = 0;
11406
11487
  return new ReadableStream({
11407
11488
  async pull(controller) {
@@ -11416,7 +11497,7 @@ function simulateReadableStream({
11416
11497
  }
11417
11498
 
11418
11499
  // src/generate-object/stream-object.ts
11419
- var originalGenerateId4 = (0, import_provider_utils32.createIdGenerator)({ prefix: "aiobj", size: 24 });
11500
+ var originalGenerateId4 = (0, import_provider_utils33.createIdGenerator)({ prefix: "aiobj", size: 24 });
11420
11501
  async function markPromiseAsHandled(promise) {
11421
11502
  try {
11422
11503
  await promise;
@@ -11515,13 +11596,13 @@ var DefaultStreamObjectResult = class {
11515
11596
  currentDate,
11516
11597
  now: now2
11517
11598
  }) {
11518
- this._object = new import_provider_utils32.DelayedPromise();
11519
- this._usage = new import_provider_utils32.DelayedPromise();
11520
- this._providerMetadata = new import_provider_utils32.DelayedPromise();
11521
- this._warnings = new import_provider_utils32.DelayedPromise();
11522
- this._request = new import_provider_utils32.DelayedPromise();
11523
- this._response = new import_provider_utils32.DelayedPromise();
11524
- 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();
11525
11606
  const model = resolveLanguageModel(modelArg);
11526
11607
  const { maxRetries, retry } = prepareRetries({
11527
11608
  maxRetries: maxRetriesArg,
@@ -11998,7 +12079,7 @@ var DefaultStreamObjectResult = class {
11998
12079
  };
11999
12080
 
12000
12081
  // src/generate-speech/generate-speech.ts
12001
- var import_provider_utils33 = require("@ai-sdk/provider-utils");
12082
+ var import_provider_utils34 = require("@ai-sdk/provider-utils");
12002
12083
 
12003
12084
  // src/generate-speech/generated-audio-file.ts
12004
12085
  var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
@@ -12044,7 +12125,7 @@ async function generateSpeech({
12044
12125
  if (!resolvedModel) {
12045
12126
  throw new Error("Model could not be resolved");
12046
12127
  }
12047
- const headersWithUserAgent = (0, import_provider_utils33.withUserAgentSuffix)(
12128
+ const headersWithUserAgent = (0, import_provider_utils34.withUserAgentSuffix)(
12048
12129
  headers != null ? headers : {},
12049
12130
  `ai/${VERSION}`
12050
12131
  );
@@ -12191,7 +12272,7 @@ function pruneMessages({
12191
12272
  }
12192
12273
 
12193
12274
  // src/generate-text/smooth-stream.ts
12194
- var import_provider_utils34 = require("@ai-sdk/provider-utils");
12275
+ var import_provider_utils35 = require("@ai-sdk/provider-utils");
12195
12276
  var import_provider33 = require("@ai-sdk/provider");
12196
12277
  var CHUNKING_REGEXPS = {
12197
12278
  word: /\S+\s+/m,
@@ -12200,7 +12281,7 @@ var CHUNKING_REGEXPS = {
12200
12281
  function smoothStream({
12201
12282
  delayInMs = 10,
12202
12283
  chunking = "word",
12203
- _internal: { delay = import_provider_utils34.delay } = {}
12284
+ _internal: { delay = import_provider_utils35.delay } = {}
12204
12285
  } = {}) {
12205
12286
  let detectChunk;
12206
12287
  if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
@@ -12289,7 +12370,7 @@ function smoothStream({
12289
12370
  }
12290
12371
 
12291
12372
  // src/generate-video/generate-video.ts
12292
- var import_provider_utils35 = require("@ai-sdk/provider-utils");
12373
+ var import_provider_utils36 = require("@ai-sdk/provider-utils");
12293
12374
  var defaultDownload = createDownload();
12294
12375
  async function experimental_generateVideo({
12295
12376
  model: modelArg,
@@ -12312,7 +12393,7 @@ async function experimental_generateVideo({
12312
12393
  }) {
12313
12394
  var _a22, _b;
12314
12395
  const model = resolveVideoModel(modelArg);
12315
- const headersWithUserAgent = (0, import_provider_utils35.withUserAgentSuffix)(
12396
+ const headersWithUserAgent = (0, import_provider_utils36.withUserAgentSuffix)(
12316
12397
  headers != null ? headers : {},
12317
12398
  `ai/${VERSION}`
12318
12399
  );
@@ -12497,14 +12578,14 @@ function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
12497
12578
  }
12498
12579
  if (dataContent.startsWith("data:")) {
12499
12580
  const { mediaType, base64Content } = splitDataUrl(dataContent);
12500
- const data = (0, import_provider_utils35.convertBase64ToUint8Array)(base64Content != null ? base64Content : "");
12581
+ const data = (0, import_provider_utils36.convertBase64ToUint8Array)(base64Content != null ? base64Content : "");
12501
12582
  return {
12502
12583
  type: "file",
12503
12584
  mediaType: mediaType != null ? mediaType : detectFileMediaType(data, restrictToImages),
12504
12585
  data
12505
12586
  };
12506
12587
  }
12507
- const bytes = (0, import_provider_utils35.convertBase64ToUint8Array)(dataContent);
12588
+ const bytes = (0, import_provider_utils36.convertBase64ToUint8Array)(dataContent);
12508
12589
  return {
12509
12590
  type: "file",
12510
12591
  mediaType: detectFileMediaType(bytes, restrictToImages),
@@ -13041,6 +13122,7 @@ var doWrap = ({
13041
13122
  };
13042
13123
 
13043
13124
  // src/middleware/wrap-embedding-model.ts
13125
+ var import_provider_utils37 = require("@ai-sdk/provider-utils");
13044
13126
  var wrapEmbeddingModel = ({
13045
13127
  model,
13046
13128
  middleware: middlewareArg,
@@ -13075,6 +13157,7 @@ var doWrap2 = ({
13075
13157
  provider: (_a22 = providerId != null ? providerId : overrideProvider == null ? void 0 : overrideProvider({ model })) != null ? _a22 : model.provider,
13076
13158
  modelId: (_b = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b : model.modelId,
13077
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),
13078
13161
  supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
13079
13162
  async doEmbed(params) {
13080
13163
  const transformedParams = await doTransform({ params });
@@ -13563,7 +13646,7 @@ var DefaultRerankResult = class {
13563
13646
  };
13564
13647
 
13565
13648
  // src/transcribe/transcribe.ts
13566
- var import_provider_utils36 = require("@ai-sdk/provider-utils");
13649
+ var import_provider_utils38 = require("@ai-sdk/provider-utils");
13567
13650
  var defaultDownload2 = createDownload();
13568
13651
  async function transcribe({
13569
13652
  model,
@@ -13582,7 +13665,7 @@ async function transcribe({
13582
13665
  maxRetries: maxRetriesArg,
13583
13666
  abortSignal
13584
13667
  });
13585
- const headersWithUserAgent = (0, import_provider_utils36.withUserAgentSuffix)(
13668
+ const headersWithUserAgent = (0, import_provider_utils38.withUserAgentSuffix)(
13586
13669
  headers != null ? headers : {},
13587
13670
  `ai/${VERSION}`
13588
13671
  );
@@ -13634,7 +13717,7 @@ var DefaultTranscriptionResult = class {
13634
13717
  };
13635
13718
 
13636
13719
  // src/ui/call-completion-api.ts
13637
- var import_provider_utils37 = require("@ai-sdk/provider-utils");
13720
+ var import_provider_utils39 = require("@ai-sdk/provider-utils");
13638
13721
 
13639
13722
  // src/ui/process-text-stream.ts
13640
13723
  async function processTextStream({
@@ -13682,13 +13765,13 @@ async function callCompletionApi({
13682
13765
  ...body
13683
13766
  }),
13684
13767
  credentials,
13685
- headers: (0, import_provider_utils37.withUserAgentSuffix)(
13768
+ headers: (0, import_provider_utils39.withUserAgentSuffix)(
13686
13769
  {
13687
13770
  "Content-Type": "application/json",
13688
13771
  ...headers
13689
13772
  },
13690
13773
  `ai-sdk/${VERSION}`,
13691
- (0, import_provider_utils37.getRuntimeEnvironmentUserAgent)()
13774
+ (0, import_provider_utils39.getRuntimeEnvironmentUserAgent)()
13692
13775
  ),
13693
13776
  signal: abortController.signal
13694
13777
  }).catch((err) => {
@@ -13716,7 +13799,7 @@ async function callCompletionApi({
13716
13799
  }
13717
13800
  case "data": {
13718
13801
  await consumeStream({
13719
- stream: (0, import_provider_utils37.parseJsonEventStream)({
13802
+ stream: (0, import_provider_utils39.parseJsonEventStream)({
13720
13803
  stream: response.body,
13721
13804
  schema: uiMessageChunkSchema
13722
13805
  }).pipeThrough(
@@ -13768,7 +13851,7 @@ async function callCompletionApi({
13768
13851
  }
13769
13852
 
13770
13853
  // src/ui/chat.ts
13771
- var import_provider_utils40 = require("@ai-sdk/provider-utils");
13854
+ var import_provider_utils42 = require("@ai-sdk/provider-utils");
13772
13855
 
13773
13856
  // src/ui/convert-file-list-to-file-ui-parts.ts
13774
13857
  async function convertFileListToFileUIParts(files) {
@@ -13801,10 +13884,10 @@ async function convertFileListToFileUIParts(files) {
13801
13884
  }
13802
13885
 
13803
13886
  // src/ui/default-chat-transport.ts
13804
- var import_provider_utils39 = require("@ai-sdk/provider-utils");
13887
+ var import_provider_utils41 = require("@ai-sdk/provider-utils");
13805
13888
 
13806
13889
  // src/ui/http-chat-transport.ts
13807
- var import_provider_utils38 = require("@ai-sdk/provider-utils");
13890
+ var import_provider_utils40 = require("@ai-sdk/provider-utils");
13808
13891
  var HttpChatTransport = class {
13809
13892
  constructor({
13810
13893
  api = "/api/chat",
@@ -13828,12 +13911,12 @@ var HttpChatTransport = class {
13828
13911
  ...options
13829
13912
  }) {
13830
13913
  var _a22, _b, _c, _d, _e;
13831
- const resolvedBody = await (0, import_provider_utils38.resolve)(this.body);
13832
- const resolvedHeaders = await (0, import_provider_utils38.resolve)(this.headers);
13833
- 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);
13834
13917
  const baseHeaders = {
13835
- ...(0, import_provider_utils38.normalizeHeaders)(resolvedHeaders),
13836
- ...(0, import_provider_utils38.normalizeHeaders)(options.headers)
13918
+ ...(0, import_provider_utils40.normalizeHeaders)(resolvedHeaders),
13919
+ ...(0, import_provider_utils40.normalizeHeaders)(options.headers)
13837
13920
  };
13838
13921
  const preparedRequest = await ((_a22 = this.prepareSendMessagesRequest) == null ? void 0 : _a22.call(this, {
13839
13922
  api: this.api,
@@ -13847,7 +13930,7 @@ var HttpChatTransport = class {
13847
13930
  messageId: options.messageId
13848
13931
  }));
13849
13932
  const api = (_b = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b : this.api;
13850
- 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;
13851
13934
  const body = (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : {
13852
13935
  ...resolvedBody,
13853
13936
  ...options.body,
@@ -13880,12 +13963,12 @@ var HttpChatTransport = class {
13880
13963
  }
13881
13964
  async reconnectToStream(options) {
13882
13965
  var _a22, _b, _c, _d, _e;
13883
- const resolvedBody = await (0, import_provider_utils38.resolve)(this.body);
13884
- const resolvedHeaders = await (0, import_provider_utils38.resolve)(this.headers);
13885
- 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);
13886
13969
  const baseHeaders = {
13887
- ...(0, import_provider_utils38.normalizeHeaders)(resolvedHeaders),
13888
- ...(0, import_provider_utils38.normalizeHeaders)(options.headers)
13970
+ ...(0, import_provider_utils40.normalizeHeaders)(resolvedHeaders),
13971
+ ...(0, import_provider_utils40.normalizeHeaders)(options.headers)
13889
13972
  };
13890
13973
  const preparedRequest = await ((_a22 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a22.call(this, {
13891
13974
  api: this.api,
@@ -13896,7 +13979,7 @@ var HttpChatTransport = class {
13896
13979
  requestMetadata: options.metadata
13897
13980
  }));
13898
13981
  const api = (_b = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b : `${this.api}/${options.chatId}/stream`;
13899
- 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;
13900
13983
  const credentials = (_c = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _c : resolvedCredentials;
13901
13984
  const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
13902
13985
  const response = await fetch2(api, {
@@ -13926,7 +14009,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
13926
14009
  super(options);
13927
14010
  }
13928
14011
  processResponseStream(stream) {
13929
- return (0, import_provider_utils39.parseJsonEventStream)({
14012
+ return (0, import_provider_utils41.parseJsonEventStream)({
13930
14013
  stream,
13931
14014
  schema: uiMessageChunkSchema
13932
14015
  }).pipeThrough(
@@ -13945,7 +14028,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
13945
14028
  // src/ui/chat.ts
13946
14029
  var AbstractChat = class {
13947
14030
  constructor({
13948
- generateId: generateId2 = import_provider_utils40.generateId,
14031
+ generateId: generateId2 = import_provider_utils42.generateId,
13949
14032
  id = generateId2(),
13950
14033
  transport = new DefaultChatTransport(),
13951
14034
  messageMetadataSchema,
@@ -14449,7 +14532,7 @@ function lastAssistantMessageIsCompleteWithApprovalResponses({
14449
14532
  // has at least one tool approval response
14450
14533
  lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
14451
14534
  lastStepToolInvocations.every(
14452
- (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"
14453
14536
  )
14454
14537
  );
14455
14538
  }