agent-inspect 6.31.11 → 6.31.12

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.
@@ -3394,25 +3394,86 @@ function asStringArray(value, label) {
3394
3394
  function asPositiveNumber(value, label) {
3395
3395
  if (value === void 0) return void 0;
3396
3396
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
3397
- throw new Error(`${label} must be a non-negative number.`);
3397
+ throw new Error(`${label} must be a non-negative finite number.`);
3398
3398
  }
3399
3399
  return value;
3400
3400
  }
3401
- function asExpectConfig(value, label) {
3401
+ function asBoolean(value, label) {
3402
3402
  if (value === void 0) return void 0;
3403
+ if (typeof value !== "boolean") {
3404
+ throw new Error(`${label} must be a boolean (not a string or other type).`);
3405
+ }
3406
+ return value;
3407
+ }
3408
+ function assertObject(value, label) {
3403
3409
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
3404
3410
  throw new Error(`${label} must be an object.`);
3405
3411
  }
3406
- const raw = value;
3412
+ return value;
3413
+ }
3414
+ function assertKnownKeys(raw, allowed, label) {
3415
+ const allowedSet = new Set(allowed);
3416
+ for (const key of Object.keys(raw)) {
3417
+ if (!allowedSet.has(key)) {
3418
+ throw new Error(`${label} has unknown key "${key}".`);
3419
+ }
3420
+ }
3421
+ }
3422
+ var CASE_KEYS = [
3423
+ "id",
3424
+ "trace",
3425
+ "runId",
3426
+ "input",
3427
+ "requireTools",
3428
+ "forbidTools",
3429
+ "maxDurationMs",
3430
+ "expectedObservations",
3431
+ "expect"
3432
+ ];
3433
+ var EXPECT_KEYS = [
3434
+ "checkStatus",
3435
+ "findingRuleIds",
3436
+ "rejectUnexpectedFindings",
3437
+ "minAssertions"
3438
+ ];
3439
+ var CHECKS_KEYS = ["select", "run", "tool", "llm"];
3440
+ var CHECKS_RUN_KEYS = ["maxDurationMs", "maxDepth"];
3441
+ var CHECKS_TOOL_KEYS = ["required", "forbidden"];
3442
+ var CHECKS_LLM_KEYS = ["allowedModels", "maxTotalTokens"];
3443
+ var EVAL_KEYS = [
3444
+ "requireSuccess",
3445
+ "requiredTools",
3446
+ "forbiddenTools",
3447
+ "maxDurationMs",
3448
+ "maxDepth",
3449
+ "maxRetries",
3450
+ "maxTotalTokens"
3451
+ ];
3452
+ var ROOT_KEYS = [
3453
+ "name",
3454
+ "traces",
3455
+ "cases",
3456
+ "checks",
3457
+ "eval",
3458
+ "redactionProfile",
3459
+ "artifacts",
3460
+ "baseline",
3461
+ "candidate"
3462
+ ];
3463
+ function asExpectConfig(value, label) {
3464
+ if (value === void 0) return void 0;
3465
+ const raw = assertObject(value, label);
3466
+ assertKnownKeys(raw, EXPECT_KEYS, label);
3407
3467
  const checkStatus = raw.checkStatus;
3408
3468
  if (checkStatus !== "pass" && checkStatus !== "fail" && checkStatus !== "error") {
3409
3469
  throw new Error(`${label}.checkStatus must be "pass", "fail", or "error".`);
3410
3470
  }
3411
3471
  const findingRuleIds = asStringArray(raw.findingRuleIds, `${label}.findingRuleIds`);
3412
3472
  const minAssertions = asPositiveNumber(raw.minAssertions, `${label}.minAssertions`);
3413
- const rejectUnexpectedFindings = raw.rejectUnexpectedFindings === void 0 ? void 0 : typeof raw.rejectUnexpectedFindings === "boolean" ? raw.rejectUnexpectedFindings : (() => {
3414
- throw new Error(`${label}.rejectUnexpectedFindings must be a boolean.`);
3415
- })();
3473
+ const rejectUnexpectedFindings = asBoolean(
3474
+ raw.rejectUnexpectedFindings,
3475
+ `${label}.rejectUnexpectedFindings`
3476
+ );
3416
3477
  return {
3417
3478
  checkStatus,
3418
3479
  ...findingRuleIds !== void 0 ? { findingRuleIds } : {},
@@ -3420,6 +3481,56 @@ function asExpectConfig(value, label) {
3420
3481
  ...minAssertions !== void 0 ? { minAssertions } : {}
3421
3482
  };
3422
3483
  }
3484
+ function asChecksConfig(value, label) {
3485
+ const raw = assertObject(value, label);
3486
+ assertKnownKeys(raw, CHECKS_KEYS, label);
3487
+ const checks = {};
3488
+ const select = asStringArray(raw.select, `${label}.select`);
3489
+ if (select !== void 0) checks.select = select;
3490
+ if (raw.run !== void 0) {
3491
+ const run = assertObject(raw.run, `${label}.run`);
3492
+ assertKnownKeys(run, CHECKS_RUN_KEYS, `${label}.run`);
3493
+ checks.run = {
3494
+ ...asPositiveNumber(run.maxDurationMs, `${label}.run.maxDurationMs`) !== void 0 ? { maxDurationMs: asPositiveNumber(run.maxDurationMs, `${label}.run.maxDurationMs`) } : {},
3495
+ ...asPositiveNumber(run.maxDepth, `${label}.run.maxDepth`) !== void 0 ? { maxDepth: asPositiveNumber(run.maxDepth, `${label}.run.maxDepth`) } : {}
3496
+ };
3497
+ }
3498
+ if (raw.tool !== void 0) {
3499
+ const tool = assertObject(raw.tool, `${label}.tool`);
3500
+ assertKnownKeys(tool, CHECKS_TOOL_KEYS, `${label}.tool`);
3501
+ checks.tool = {
3502
+ ...asStringArray(tool.required, `${label}.tool.required`) !== void 0 ? { required: asStringArray(tool.required, `${label}.tool.required`) } : {},
3503
+ ...asStringArray(tool.forbidden, `${label}.tool.forbidden`) !== void 0 ? { forbidden: asStringArray(tool.forbidden, `${label}.tool.forbidden`) } : {}
3504
+ };
3505
+ }
3506
+ if (raw.llm !== void 0) {
3507
+ const llm = assertObject(raw.llm, `${label}.llm`);
3508
+ assertKnownKeys(llm, CHECKS_LLM_KEYS, `${label}.llm`);
3509
+ checks.llm = {
3510
+ ...asStringArray(llm.allowedModels, `${label}.llm.allowedModels`) !== void 0 ? { allowedModels: asStringArray(llm.allowedModels, `${label}.llm.allowedModels`) } : {},
3511
+ ...asPositiveNumber(llm.maxTotalTokens, `${label}.llm.maxTotalTokens`) !== void 0 ? {
3512
+ maxTotalTokens: asPositiveNumber(
3513
+ llm.maxTotalTokens,
3514
+ `${label}.llm.maxTotalTokens`
3515
+ )
3516
+ } : {}
3517
+ };
3518
+ }
3519
+ return checks;
3520
+ }
3521
+ function asEvalConfig(value, label) {
3522
+ const raw = assertObject(value, label);
3523
+ assertKnownKeys(raw, EVAL_KEYS, label);
3524
+ return {
3525
+ ...asBoolean(raw.requireSuccess, `${label}.requireSuccess`) !== void 0 ? { requireSuccess: asBoolean(raw.requireSuccess, `${label}.requireSuccess`) } : {},
3526
+ ...asStringArray(raw.requiredTools, `${label}.requiredTools`) !== void 0 ? { requiredTools: asStringArray(raw.requiredTools, `${label}.requiredTools`) } : {},
3527
+ ...asStringArray(raw.forbiddenTools, `${label}.forbiddenTools`) !== void 0 ? { forbiddenTools: asStringArray(raw.forbiddenTools, `${label}.forbiddenTools`) } : {},
3528
+ ...asPositiveNumber(raw.maxDurationMs, `${label}.maxDurationMs`) !== void 0 ? { maxDurationMs: asPositiveNumber(raw.maxDurationMs, `${label}.maxDurationMs`) } : {},
3529
+ ...asPositiveNumber(raw.maxDepth, `${label}.maxDepth`) !== void 0 ? { maxDepth: asPositiveNumber(raw.maxDepth, `${label}.maxDepth`) } : {},
3530
+ ...asPositiveNumber(raw.maxRetries, `${label}.maxRetries`) !== void 0 ? { maxRetries: asPositiveNumber(raw.maxRetries, `${label}.maxRetries`) } : {},
3531
+ ...asPositiveNumber(raw.maxTotalTokens, `${label}.maxTotalTokens`) !== void 0 ? { maxTotalTokens: asPositiveNumber(raw.maxTotalTokens, `${label}.maxTotalTokens`) } : {}
3532
+ };
3533
+ }
3423
3534
  function validateCaseConfig(value, index) {
3424
3535
  const diagnostics = [];
3425
3536
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -3430,6 +3541,7 @@ function validateCaseConfig(value, index) {
3430
3541
  }
3431
3542
  const raw = value;
3432
3543
  try {
3544
+ assertKnownKeys(raw, CASE_KEYS, `cases[${index}]`);
3433
3545
  const id = asString(raw.id, `cases[${index}].id`);
3434
3546
  if (id === void 0) {
3435
3547
  diagnostics.push(
@@ -3478,6 +3590,7 @@ function normalizeSuiteConfig(value) {
3478
3590
  throw new Error("Suite config must export an object.");
3479
3591
  }
3480
3592
  const raw = value;
3593
+ assertKnownKeys(raw, ROOT_KEYS, "suite config");
3481
3594
  const name = asString(raw.name, "name");
3482
3595
  const traces = asString(raw.traces, "traces");
3483
3596
  if (name === void 0) throw new Error("name is required.");
@@ -3506,25 +3619,15 @@ function normalizeSuiteConfig(value) {
3506
3619
  }
3507
3620
  const config = { name, traces, cases };
3508
3621
  if (raw.checks !== void 0) {
3509
- if (typeof raw.checks !== "object" || Array.isArray(raw.checks)) {
3510
- throw new Error("checks must be an object.");
3511
- }
3512
- config.checks = raw.checks;
3622
+ config.checks = asChecksConfig(raw.checks, "checks");
3513
3623
  }
3514
3624
  if (raw.eval !== void 0) {
3515
- if (typeof raw.eval !== "object" || Array.isArray(raw.eval)) {
3516
- throw new Error("eval must be an object.");
3517
- }
3518
- config.eval = raw.eval;
3625
+ config.eval = asEvalConfig(raw.eval, "eval");
3519
3626
  }
3520
3627
  if (raw.artifacts !== void 0) {
3521
- if (typeof raw.artifacts !== "object" || Array.isArray(raw.artifacts)) {
3522
- throw new Error("artifacts must be an object.");
3523
- }
3524
- const outputDir = asString(
3525
- raw.artifacts.outputDir,
3526
- "artifacts.outputDir"
3527
- );
3628
+ const artifacts = assertObject(raw.artifacts, "artifacts");
3629
+ assertKnownKeys(artifacts, ["outputDir"], "artifacts");
3630
+ const outputDir = asString(artifacts.outputDir, "artifacts.outputDir");
3528
3631
  config.artifacts = outputDir !== void 0 ? { outputDir } : {};
3529
3632
  }
3530
3633
  if (raw.baseline !== void 0) {