ai 7.0.160 → 7.0.162

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
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
2
  import { GatewayAuthenticationError, GatewayError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
3
- import { DEFAULT_MAX_DOWNLOAD_SIZE, DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, cancelResponseBody, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getWebSocketConstructor, isAbortError, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, readWebSocketMessageText, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, tool as tool$1, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
3
+ import { DEFAULT_MAX_DOWNLOAD_SIZE, DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, cancelResponseBody, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getWebSocketConstructor, isAbortError, isArrayBuffer, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUint8Array, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, readWebSocketMessageText, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, tool as tool$1, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
4
4
  import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1, Experimental_DecisionRefusalError, Experimental_DecisionRefusalError as Experimental_DecisionRefusalError$1, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_DecisionUnsupportedQuestionTypeError as Experimental_DecisionUnsupportedQuestionTypeError$1, InvalidPromptError, InvalidPromptError as InvalidPromptError$1, InvalidResponseDataError, InvalidResponseDataError as InvalidResponseDataError$1, JSONParseError, JSONParseError as JSONParseError$1, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchModelError as NoSuchModelError$1, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, TypeValidationError as TypeValidationError$1, UnsupportedFunctionalityError, UnsupportedFunctionalityError as UnsupportedFunctionalityError$1, getErrorMessage as getErrorMessage$1, isJSONArray, isJSONObject } from "@ai-sdk/provider";
5
5
  import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
6
6
  //#region src/error/invalid-argument-error.ts
@@ -1162,20 +1162,52 @@ function asEvaluationModel(model) {
1162
1162
  * currently rejects URL objects, which are valid file/image prompt payloads.
1163
1163
  */
1164
1164
  function cloneModelMessages(messages) {
1165
- return messages.map((message) => cloneValue(message));
1166
- }
1167
- function cloneValue(value) {
1168
- if (value instanceof URL) return new URL(value.href);
1169
- if (Array.isArray(value)) return value.map((item) => cloneValue(item));
1170
- if (value instanceof Uint8Array) return new Uint8Array(value);
1171
- if (value instanceof ArrayBuffer) return value.slice(0);
1172
- if (value instanceof Date) return new Date(value);
1173
- if (value != null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, value]) => [key, cloneValue(value)]));
1174
- return value;
1165
+ return cloneValue(messages, /* @__PURE__ */ new Map());
1166
+ }
1167
+ function cloneValue(value, seen) {
1168
+ if (value == null || typeof value !== "object") return value;
1169
+ if (seen.has(value)) return seen.get(value);
1170
+ if (value instanceof URL) {
1171
+ const copy = new URL(value.href);
1172
+ seen.set(value, copy);
1173
+ return copy;
1174
+ }
1175
+ if (Array.isArray(value)) {
1176
+ const copy = new Array(value.length);
1177
+ seen.set(value, copy);
1178
+ value.forEach((item, index) => {
1179
+ copy[index] = cloneValue(item, seen);
1180
+ });
1181
+ return copy;
1182
+ }
1183
+ if (isUint8Array(value)) {
1184
+ const copy = new Uint8Array(value);
1185
+ seen.set(value, copy);
1186
+ return copy;
1187
+ }
1188
+ if (isArrayBuffer(value)) {
1189
+ const copy = new Uint8Array(value).slice().buffer;
1190
+ seen.set(value, copy);
1191
+ return copy;
1192
+ }
1193
+ if (value instanceof Date || Object.prototype.toString.call(value) === "[object Date]") try {
1194
+ const copy = new Date(Date.prototype.getTime.call(value));
1195
+ seen.set(value, copy);
1196
+ return copy;
1197
+ } catch {}
1198
+ const copy = {};
1199
+ seen.set(value, copy);
1200
+ for (const [key, val] of Object.entries(value)) Object.defineProperty(copy, key, {
1201
+ value: cloneValue(val, seen),
1202
+ writable: true,
1203
+ enumerable: true,
1204
+ configurable: true
1205
+ });
1206
+ return copy;
1175
1207
  }
1176
1208
  //#endregion
1177
1209
  //#region src/version.ts
1178
- const VERSION = "7.0.160";
1210
+ const VERSION = "7.0.162";
1179
1211
  //#endregion
1180
1212
  //#region src/util/download/download.ts
1181
1213
  /**
@@ -1266,6 +1298,42 @@ function mergeObjects(base, overrides) {
1266
1298
  return result;
1267
1299
  }
1268
1300
  //#endregion
1301
+ //#region src/prompt/data-content.ts
1302
+ /**
1303
+ * Converts data content to a base64-encoded string.
1304
+ *
1305
+ * @param content - Data content to convert.
1306
+ * @returns Base64-encoded string.
1307
+ */
1308
+ function convertDataContentToBase64String(content) {
1309
+ if (typeof content === "string") return content;
1310
+ return convertUint8ArrayToBase64(convertDataContentToUint8Array(content));
1311
+ }
1312
+ /**
1313
+ * Converts data content to a Uint8Array.
1314
+ *
1315
+ * @param content - Data content to convert.
1316
+ * @returns Uint8Array.
1317
+ */
1318
+ function convertDataContentToUint8Array(content) {
1319
+ if (isUint8Array(content)) {
1320
+ if (content instanceof Uint8Array) return content;
1321
+ const { buffer, byteOffset, byteLength } = content;
1322
+ return new Uint8Array(buffer, byteOffset, byteLength);
1323
+ }
1324
+ if (typeof content === "string") try {
1325
+ return convertBase64ToUint8Array(content);
1326
+ } catch (error) {
1327
+ throw new InvalidDataContentError({
1328
+ message: "Invalid data content. Content string is not a base64-encoded media.",
1329
+ content,
1330
+ cause: error
1331
+ });
1332
+ }
1333
+ if (isArrayBuffer(content)) return new Uint8Array(content);
1334
+ throw new InvalidDataContentError({ content });
1335
+ }
1336
+ //#endregion
1269
1337
  //#region src/prompt/split-data-url.ts
1270
1338
  function splitDataUrl(dataUrl) {
1271
1339
  try {
@@ -1318,17 +1386,10 @@ function convertUrlStringToFilePartData(content) {
1318
1386
  return result;
1319
1387
  }
1320
1388
  function convertInlineDataToFilePartData(content) {
1321
- if (content instanceof Uint8Array) return {
1389
+ if (isUint8Array(content) || isArrayBuffer(content)) return {
1322
1390
  data: {
1323
1391
  type: "data",
1324
- data: content
1325
- },
1326
- mediaType: void 0
1327
- };
1328
- if (content instanceof ArrayBuffer) return {
1329
- data: {
1330
- type: "data",
1331
- data: new Uint8Array(content)
1392
+ data: convertDataContentToUint8Array(content)
1332
1393
  },
1333
1394
  mediaType: void 0
1334
1395
  };
@@ -1384,6 +1445,7 @@ function convertToLanguageModelV4FilePart(content) {
1384
1445
  } catch {
1385
1446
  return convertInlineDataToFilePartData(content);
1386
1447
  }
1448
+ if (isUint8Array(content) || isArrayBuffer(content)) return convertInlineDataToFilePartData(content);
1387
1449
  if (isProviderReference(content)) return {
1388
1450
  data: {
1389
1451
  type: "reference",
@@ -2399,9 +2461,8 @@ function collectToolApprovals({ messages }) {
2399
2461
  //#region src/generate-text/generated-file.ts
2400
2462
  var DefaultGeneratedFile = class {
2401
2463
  constructor({ data, mediaType, providerMetadata }) {
2402
- const isUint8Array = data instanceof Uint8Array;
2403
- this.base64Data = isUint8Array ? void 0 : data;
2404
- this.uint8ArrayData = isUint8Array ? data : void 0;
2464
+ this.base64Data = typeof data === "string" ? data : void 0;
2465
+ this.uint8ArrayData = typeof data === "string" ? void 0 : convertDataContentToUint8Array(data);
2405
2466
  this.mediaType = mediaType;
2406
2467
  this.providerMetadata = providerMetadata;
2407
2468
  }
@@ -4912,9 +4973,19 @@ async function validateApprovedToolApprovals({ approvedToolApprovals, tools, too
4912
4973
  const approved = [];
4913
4974
  const denied = [];
4914
4975
  const invalid = [];
4915
- for (const approval of approvedToolApprovals) {
4976
+ for (const collectedApproval of approvedToolApprovals) {
4977
+ const tool = getOwn(tools, collectedApproval.toolCall.toolName);
4978
+ const { toolMetadata: _toolMetadata, dynamic: _dynamic, ...toolCallFromHistory } = collectedApproval.toolCall;
4979
+ const approval = {
4980
+ ...collectedApproval,
4981
+ toolCall: {
4982
+ ...toolCallFromHistory,
4983
+ ...tool?.metadata != null ? { toolMetadata: tool.metadata } : {},
4984
+ ...tool?.type === "dynamic" ? { dynamic: true } : {},
4985
+ title: tool?.title
4986
+ }
4987
+ };
4916
4988
  const { approvalRequest, toolCall } = approval;
4917
- const tool = getOwn(tools, toolCall.toolName);
4918
4989
  if (toolApprovalSecret != null) {
4919
4990
  if (approvalRequest.signature == null) throw new InvalidToolApprovalSignatureError({
4920
4991
  approvalId: approvalRequest.approvalId,
@@ -11771,39 +11842,6 @@ function setOwn(object, key, value) {
11771
11842
  });
11772
11843
  }
11773
11844
  //#endregion
11774
- //#region src/prompt/data-content.ts
11775
- /**
11776
- * Converts data content to a base64-encoded string.
11777
- *
11778
- * @param content - Data content to convert.
11779
- * @returns Base64-encoded string.
11780
- */
11781
- function convertDataContentToBase64String(content) {
11782
- if (typeof content === "string") return content;
11783
- if (content instanceof ArrayBuffer) return convertUint8ArrayToBase64(new Uint8Array(content));
11784
- return convertUint8ArrayToBase64(content);
11785
- }
11786
- /**
11787
- * Converts data content to a Uint8Array.
11788
- *
11789
- * @param content - Data content to convert.
11790
- * @returns Uint8Array.
11791
- */
11792
- function convertDataContentToUint8Array(content) {
11793
- if (content instanceof Uint8Array) return content;
11794
- if (typeof content === "string") try {
11795
- return convertBase64ToUint8Array(content);
11796
- } catch (error) {
11797
- throw new InvalidDataContentError({
11798
- message: "Invalid data content. Content string is not a base64-encoded media.",
11799
- content,
11800
- cause: error
11801
- });
11802
- }
11803
- if (content instanceof ArrayBuffer) return new Uint8Array(content);
11804
- throw new InvalidDataContentError({ content });
11805
- }
11806
- //#endregion
11807
11845
  //#region src/generate-image/generate-image.ts
11808
11846
  const gatewayCostMetadataKeys = [
11809
11847
  "cost",
@@ -16514,8 +16552,8 @@ function wrapProvider({ provider, languageModelMiddleware, imageModelMiddleware
16514
16552
  //#region src/prompt/content-part.ts
16515
16553
  const fileInlineDataSchema = z.union([
16516
16554
  z.string(),
16517
- z.instanceof(Uint8Array),
16518
- z.instanceof(ArrayBuffer),
16555
+ z.custom(isUint8Array, { message: "Must be a Uint8Array" }),
16556
+ z.custom(isArrayBuffer, { message: "Must be an ArrayBuffer" }),
16519
16557
  z.custom(isBuffer, { message: "Must be a Buffer" })
16520
16558
  ]);
16521
16559
  const providerReferenceSchema = z.record(z.string(), z.string());