ai 6.0.332 → 6.0.333

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.mjs CHANGED
@@ -1225,7 +1225,7 @@ import {
1225
1225
  } from "@ai-sdk/provider-utils";
1226
1226
 
1227
1227
  // src/version.ts
1228
- var VERSION = true ? "6.0.332" : "0.0.0-test";
1228
+ var VERSION = true ? "6.0.333" : "0.0.0-test";
1229
1229
 
1230
1230
  // src/util/download/download.ts
1231
1231
  var download = async ({
@@ -3364,7 +3364,7 @@ async function validateApprovedToolApprovals({
3364
3364
  var _a23;
3365
3365
  const approved = [];
3366
3366
  const denied = [];
3367
- const invalid = [];
3367
+ const invalid2 = [];
3368
3368
  for (const approval of approvedToolApprovals) {
3369
3369
  const { toolCall, approvalRequest } = approval;
3370
3370
  const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
@@ -3410,7 +3410,7 @@ async function validateApprovedToolApprovals({
3410
3410
  );
3411
3411
  }
3412
3412
  if (validationError != null) {
3413
- invalid.push({
3413
+ invalid2.push({
3414
3414
  ...approval,
3415
3415
  error: new InvalidToolInputError({
3416
3416
  toolName: toolCall.toolName,
@@ -3443,7 +3443,7 @@ async function validateApprovedToolApprovals({
3443
3443
  return {
3444
3444
  approvedToolApprovals: approved,
3445
3445
  deniedToolApprovals: denied,
3446
- invalidToolApprovals: invalid
3446
+ invalidToolApprovals: invalid2
3447
3447
  };
3448
3448
  }
3449
3449
 
@@ -10180,62 +10180,127 @@ import {
10180
10180
  zodSchema as zodSchema2
10181
10181
  } from "@ai-sdk/provider-utils";
10182
10182
  import { z as z8 } from "zod/v4";
10183
- function findInvalidJsonValuePath(value, path = [], visited = /* @__PURE__ */ new WeakSet()) {
10183
+
10184
+ // src/util/normalize-json-value.ts
10185
+ var invalid = Symbol("invalid");
10186
+ function normalizeJsonValue(value) {
10187
+ const path = [];
10188
+ const normalized = normalize(value, path, /* @__PURE__ */ new Set());
10189
+ return normalized === invalid ? { success: false, path } : { success: true, value: normalized };
10190
+ }
10191
+ function normalize(value, path, ancestors) {
10184
10192
  switch (typeof value) {
10193
+ case "string":
10194
+ case "boolean":
10195
+ return value;
10185
10196
  case "number":
10186
- return Number.isFinite(value) ? void 0 : [...path];
10187
- case "bigint":
10188
- case "symbol":
10189
- case "function":
10190
- return [...path];
10197
+ return Number.isFinite(value) ? value : invalid;
10191
10198
  case "object": {
10192
- if (value === null || visited.has(value)) {
10193
- return void 0;
10194
- }
10195
- visited.add(value);
10196
- const keys = Array.isArray(value) ? value.keys() : Object.keys(value);
10197
- for (const key of keys) {
10198
- if (key === "__proto__")
10199
- continue;
10200
- path.push(key);
10201
- const invalidPath = findInvalidJsonValuePath(
10202
- value[key],
10203
- path,
10204
- visited
10205
- );
10206
- if (invalidPath != null)
10207
- return invalidPath;
10208
- path.pop();
10209
- }
10210
- return void 0;
10199
+ if (value === null)
10200
+ return value;
10201
+ if (ancestors.has(value))
10202
+ return invalid;
10203
+ ancestors.add(value);
10204
+ const normalized = Array.isArray(value) ? normalizeArray(value, path, ancestors) : normalizeObject(value, path, ancestors);
10205
+ ancestors.delete(value);
10206
+ return normalized;
10211
10207
  }
10212
10208
  default:
10213
- return void 0;
10209
+ return invalid;
10210
+ }
10211
+ }
10212
+ function normalizeArray(array2, path, ancestors) {
10213
+ let copy;
10214
+ for (let index = 0; index < array2.length; index++) {
10215
+ const element = array2[index];
10216
+ path.push(index);
10217
+ const normalized = normalize(element, path, ancestors);
10218
+ if (normalized === invalid)
10219
+ return invalid;
10220
+ path.pop();
10221
+ if (copy != null) {
10222
+ copy.push(normalized);
10223
+ } else if (normalized !== element) {
10224
+ copy = array2.slice(0, index);
10225
+ copy.push(normalized);
10226
+ }
10227
+ }
10228
+ return copy != null ? copy : array2;
10229
+ }
10230
+ function normalizeObject(object2, path, ancestors) {
10231
+ if (!isPlainObject(object2) || hasEnumerableSymbolKey(object2))
10232
+ return invalid;
10233
+ const keys = Object.keys(object2);
10234
+ let copy;
10235
+ for (let index = 0; index < keys.length; index++) {
10236
+ const key = keys[index];
10237
+ if (key === "__proto__") {
10238
+ copy != null ? copy : copy = copyProperties(object2, keys, index);
10239
+ continue;
10240
+ }
10241
+ const property = object2[key];
10242
+ let normalized = property;
10243
+ if (property !== void 0) {
10244
+ path.push(key);
10245
+ normalized = normalize(property, path, ancestors);
10246
+ if (normalized === invalid)
10247
+ return invalid;
10248
+ path.pop();
10249
+ }
10250
+ if (copy != null) {
10251
+ copy[key] = normalized;
10252
+ } else if (normalized !== property) {
10253
+ copy = copyProperties(object2, keys, index);
10254
+ copy[key] = normalized;
10255
+ }
10214
10256
  }
10257
+ return copy != null ? copy : object2;
10215
10258
  }
10216
- function withJsonValueCheck(schema, jsonValuePath = []) {
10217
- return z8.unknown().check((context2) => {
10218
- let jsonValue = context2.value;
10219
- for (const key of jsonValuePath) {
10220
- jsonValue = jsonValue != null && typeof jsonValue === "object" ? jsonValue[key] : void 0;
10221
- }
10222
- const invalidPath = findInvalidJsonValuePath(jsonValue);
10223
- if (invalidPath != null) {
10224
- context2.issues.push({
10225
- code: "custom",
10226
- message: "Invalid JSON value. Expected null, a string, a finite number, a boolean, an array, or an object.",
10227
- input: context2.value,
10228
- path: [...jsonValuePath, ...invalidPath]
10229
- });
10259
+ function copyProperties(object2, keys, count) {
10260
+ const copy = {};
10261
+ for (let index = 0; index < count; index++) {
10262
+ copy[keys[index]] = object2[keys[index]];
10263
+ }
10264
+ return copy;
10265
+ }
10266
+ function isPlainObject(object2) {
10267
+ const constructor = object2.constructor;
10268
+ if (typeof constructor !== "function")
10269
+ return true;
10270
+ const prototype = constructor.prototype;
10271
+ return prototype !== null && typeof prototype === "object" && Object.prototype.hasOwnProperty.call(prototype, "isPrototypeOf");
10272
+ }
10273
+ function hasEnumerableSymbolKey(object2) {
10274
+ const symbols = Object.getOwnPropertySymbols(object2);
10275
+ for (let index = 0; index < symbols.length; index++) {
10276
+ if (Object.prototype.propertyIsEnumerable.call(object2, symbols[index])) {
10277
+ return true;
10230
10278
  }
10231
- }).pipe(schema);
10279
+ }
10280
+ return false;
10232
10281
  }
10233
- var toolMetadataRecordSchema = z8.record(
10234
- z8.string(),
10235
- jsonValueSchema.optional()
10282
+
10283
+ // src/ui/validate-ui-messages.ts
10284
+ var jsonValueSchema2 = z8.unknown().transform((value, context2) => {
10285
+ const result = normalizeJsonValue(value);
10286
+ if (!result.success) {
10287
+ context2.issues.push({
10288
+ code: "custom",
10289
+ message: "Invalid JSON value. Expected null, a string, a finite number, a boolean, an array, or an object.",
10290
+ input: value,
10291
+ path: result.path
10292
+ });
10293
+ return z8.NEVER;
10294
+ }
10295
+ return result.value;
10296
+ });
10297
+ var validatedJsonValueSchema = z8.custom();
10298
+ var toolMetadataSchema2 = jsonValueSchema2.pipe(
10299
+ z8.record(z8.string(), validatedJsonValueSchema)
10300
+ );
10301
+ var providerMetadataSchema2 = jsonValueSchema2.pipe(
10302
+ z8.record(z8.string(), z8.record(z8.string(), validatedJsonValueSchema))
10236
10303
  );
10237
- var toolMetadataSchema2 = withJsonValueCheck(toolMetadataRecordSchema);
10238
- var providerMetadataSchema2 = withJsonValueCheck(providerMetadataSchema);
10239
10304
  function isEmptyObject(value) {
10240
10305
  return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
10241
10306
  }