ai 6.0.331 → 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/CHANGELOG.md +18 -0
- package/dist/index.js +115 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -50
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +6 -6
- package/src/ui/validate-ui-messages.ts +36 -87
- package/src/util/normalize-json-value.ts +182 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.333
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2771b61: Reduce memory and CPU usage when validating UI messages with deeply nested provider or tool metadata. `validateUIMessages` and `safeValidateUIMessages`, which the agent UI stream helpers also use, validated JSON values in `providerMetadata`, `callProviderMetadata`, `resultProviderMetadata`, and `toolMetadata` with a recursive union schema that needed several times the memory of the value. These values are now validated in a single pass and are no longer copied, except to remove `__proto__` keys.
|
|
8
|
+
- Updated dependencies [9faffa5]
|
|
9
|
+
- Updated dependencies [3cf16af]
|
|
10
|
+
- Updated dependencies [d59eee0]
|
|
11
|
+
- @ai-sdk/gateway@3.0.238
|
|
12
|
+
- @ai-sdk/provider-utils@4.0.67
|
|
13
|
+
|
|
14
|
+
## 6.0.332
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [23ff635]
|
|
19
|
+
- @ai-sdk/gateway@3.0.237
|
|
20
|
+
|
|
3
21
|
## 6.0.331
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1335,7 +1335,7 @@ function detectMediaType({
|
|
|
1335
1335
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1336
1336
|
|
|
1337
1337
|
// src/version.ts
|
|
1338
|
-
var VERSION = true ? "6.0.
|
|
1338
|
+
var VERSION = true ? "6.0.333" : "0.0.0-test";
|
|
1339
1339
|
|
|
1340
1340
|
// src/util/download/download.ts
|
|
1341
1341
|
var download = async ({
|
|
@@ -3453,7 +3453,7 @@ async function validateApprovedToolApprovals({
|
|
|
3453
3453
|
var _a23;
|
|
3454
3454
|
const approved = [];
|
|
3455
3455
|
const denied = [];
|
|
3456
|
-
const
|
|
3456
|
+
const invalid2 = [];
|
|
3457
3457
|
for (const approval of approvedToolApprovals) {
|
|
3458
3458
|
const { toolCall, approvalRequest } = approval;
|
|
3459
3459
|
const tool2 = tools == null ? void 0 : tools[toolCall.toolName];
|
|
@@ -3499,7 +3499,7 @@ async function validateApprovedToolApprovals({
|
|
|
3499
3499
|
);
|
|
3500
3500
|
}
|
|
3501
3501
|
if (validationError != null) {
|
|
3502
|
-
|
|
3502
|
+
invalid2.push({
|
|
3503
3503
|
...approval,
|
|
3504
3504
|
error: new InvalidToolInputError({
|
|
3505
3505
|
toolName: toolCall.toolName,
|
|
@@ -3532,7 +3532,7 @@ async function validateApprovedToolApprovals({
|
|
|
3532
3532
|
return {
|
|
3533
3533
|
approvedToolApprovals: approved,
|
|
3534
3534
|
deniedToolApprovals: denied,
|
|
3535
|
-
invalidToolApprovals:
|
|
3535
|
+
invalidToolApprovals: invalid2
|
|
3536
3536
|
};
|
|
3537
3537
|
}
|
|
3538
3538
|
|
|
@@ -10235,62 +10235,127 @@ async function convertToModelMessages(messages, options) {
|
|
|
10235
10235
|
var import_provider31 = require("@ai-sdk/provider");
|
|
10236
10236
|
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
10237
10237
|
var import_v48 = require("zod/v4");
|
|
10238
|
-
|
|
10238
|
+
|
|
10239
|
+
// src/util/normalize-json-value.ts
|
|
10240
|
+
var invalid = Symbol("invalid");
|
|
10241
|
+
function normalizeJsonValue(value) {
|
|
10242
|
+
const path = [];
|
|
10243
|
+
const normalized = normalize(value, path, /* @__PURE__ */ new Set());
|
|
10244
|
+
return normalized === invalid ? { success: false, path } : { success: true, value: normalized };
|
|
10245
|
+
}
|
|
10246
|
+
function normalize(value, path, ancestors) {
|
|
10239
10247
|
switch (typeof value) {
|
|
10248
|
+
case "string":
|
|
10249
|
+
case "boolean":
|
|
10250
|
+
return value;
|
|
10240
10251
|
case "number":
|
|
10241
|
-
return Number.isFinite(value) ?
|
|
10242
|
-
case "bigint":
|
|
10243
|
-
case "symbol":
|
|
10244
|
-
case "function":
|
|
10245
|
-
return [...path];
|
|
10252
|
+
return Number.isFinite(value) ? value : invalid;
|
|
10246
10253
|
case "object": {
|
|
10247
|
-
if (value === null
|
|
10248
|
-
return
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
path.push(key);
|
|
10256
|
-
const invalidPath = findInvalidJsonValuePath(
|
|
10257
|
-
value[key],
|
|
10258
|
-
path,
|
|
10259
|
-
visited
|
|
10260
|
-
);
|
|
10261
|
-
if (invalidPath != null)
|
|
10262
|
-
return invalidPath;
|
|
10263
|
-
path.pop();
|
|
10264
|
-
}
|
|
10265
|
-
return void 0;
|
|
10254
|
+
if (value === null)
|
|
10255
|
+
return value;
|
|
10256
|
+
if (ancestors.has(value))
|
|
10257
|
+
return invalid;
|
|
10258
|
+
ancestors.add(value);
|
|
10259
|
+
const normalized = Array.isArray(value) ? normalizeArray(value, path, ancestors) : normalizeObject(value, path, ancestors);
|
|
10260
|
+
ancestors.delete(value);
|
|
10261
|
+
return normalized;
|
|
10266
10262
|
}
|
|
10267
10263
|
default:
|
|
10268
|
-
return
|
|
10264
|
+
return invalid;
|
|
10265
|
+
}
|
|
10266
|
+
}
|
|
10267
|
+
function normalizeArray(array2, path, ancestors) {
|
|
10268
|
+
let copy;
|
|
10269
|
+
for (let index = 0; index < array2.length; index++) {
|
|
10270
|
+
const element = array2[index];
|
|
10271
|
+
path.push(index);
|
|
10272
|
+
const normalized = normalize(element, path, ancestors);
|
|
10273
|
+
if (normalized === invalid)
|
|
10274
|
+
return invalid;
|
|
10275
|
+
path.pop();
|
|
10276
|
+
if (copy != null) {
|
|
10277
|
+
copy.push(normalized);
|
|
10278
|
+
} else if (normalized !== element) {
|
|
10279
|
+
copy = array2.slice(0, index);
|
|
10280
|
+
copy.push(normalized);
|
|
10281
|
+
}
|
|
10282
|
+
}
|
|
10283
|
+
return copy != null ? copy : array2;
|
|
10284
|
+
}
|
|
10285
|
+
function normalizeObject(object2, path, ancestors) {
|
|
10286
|
+
if (!isPlainObject(object2) || hasEnumerableSymbolKey(object2))
|
|
10287
|
+
return invalid;
|
|
10288
|
+
const keys = Object.keys(object2);
|
|
10289
|
+
let copy;
|
|
10290
|
+
for (let index = 0; index < keys.length; index++) {
|
|
10291
|
+
const key = keys[index];
|
|
10292
|
+
if (key === "__proto__") {
|
|
10293
|
+
copy != null ? copy : copy = copyProperties(object2, keys, index);
|
|
10294
|
+
continue;
|
|
10295
|
+
}
|
|
10296
|
+
const property = object2[key];
|
|
10297
|
+
let normalized = property;
|
|
10298
|
+
if (property !== void 0) {
|
|
10299
|
+
path.push(key);
|
|
10300
|
+
normalized = normalize(property, path, ancestors);
|
|
10301
|
+
if (normalized === invalid)
|
|
10302
|
+
return invalid;
|
|
10303
|
+
path.pop();
|
|
10304
|
+
}
|
|
10305
|
+
if (copy != null) {
|
|
10306
|
+
copy[key] = normalized;
|
|
10307
|
+
} else if (normalized !== property) {
|
|
10308
|
+
copy = copyProperties(object2, keys, index);
|
|
10309
|
+
copy[key] = normalized;
|
|
10310
|
+
}
|
|
10269
10311
|
}
|
|
10312
|
+
return copy != null ? copy : object2;
|
|
10270
10313
|
}
|
|
10271
|
-
function
|
|
10272
|
-
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10314
|
+
function copyProperties(object2, keys, count) {
|
|
10315
|
+
const copy = {};
|
|
10316
|
+
for (let index = 0; index < count; index++) {
|
|
10317
|
+
copy[keys[index]] = object2[keys[index]];
|
|
10318
|
+
}
|
|
10319
|
+
return copy;
|
|
10320
|
+
}
|
|
10321
|
+
function isPlainObject(object2) {
|
|
10322
|
+
const constructor = object2.constructor;
|
|
10323
|
+
if (typeof constructor !== "function")
|
|
10324
|
+
return true;
|
|
10325
|
+
const prototype = constructor.prototype;
|
|
10326
|
+
return prototype !== null && typeof prototype === "object" && Object.prototype.hasOwnProperty.call(prototype, "isPrototypeOf");
|
|
10327
|
+
}
|
|
10328
|
+
function hasEnumerableSymbolKey(object2) {
|
|
10329
|
+
const symbols = Object.getOwnPropertySymbols(object2);
|
|
10330
|
+
for (let index = 0; index < symbols.length; index++) {
|
|
10331
|
+
if (Object.prototype.propertyIsEnumerable.call(object2, symbols[index])) {
|
|
10332
|
+
return true;
|
|
10285
10333
|
}
|
|
10286
|
-
}
|
|
10334
|
+
}
|
|
10335
|
+
return false;
|
|
10287
10336
|
}
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10337
|
+
|
|
10338
|
+
// src/ui/validate-ui-messages.ts
|
|
10339
|
+
var jsonValueSchema2 = import_v48.z.unknown().transform((value, context2) => {
|
|
10340
|
+
const result = normalizeJsonValue(value);
|
|
10341
|
+
if (!result.success) {
|
|
10342
|
+
context2.issues.push({
|
|
10343
|
+
code: "custom",
|
|
10344
|
+
message: "Invalid JSON value. Expected null, a string, a finite number, a boolean, an array, or an object.",
|
|
10345
|
+
input: value,
|
|
10346
|
+
path: result.path
|
|
10347
|
+
});
|
|
10348
|
+
return import_v48.z.NEVER;
|
|
10349
|
+
}
|
|
10350
|
+
return result.value;
|
|
10351
|
+
});
|
|
10352
|
+
var validatedJsonValueSchema = import_v48.z.custom();
|
|
10353
|
+
var toolMetadataSchema2 = jsonValueSchema2.pipe(
|
|
10354
|
+
import_v48.z.record(import_v48.z.string(), validatedJsonValueSchema)
|
|
10355
|
+
);
|
|
10356
|
+
var providerMetadataSchema2 = jsonValueSchema2.pipe(
|
|
10357
|
+
import_v48.z.record(import_v48.z.string(), import_v48.z.record(import_v48.z.string(), validatedJsonValueSchema))
|
|
10291
10358
|
);
|
|
10292
|
-
var toolMetadataSchema2 = withJsonValueCheck(toolMetadataRecordSchema);
|
|
10293
|
-
var providerMetadataSchema2 = withJsonValueCheck(providerMetadataSchema);
|
|
10294
10359
|
function isEmptyObject(value) {
|
|
10295
10360
|
return value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
10296
10361
|
}
|