@agent-inspect/viewer 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.
package/dist/index.cjs CHANGED
@@ -3174,25 +3174,86 @@ function asStringArray(value, label) {
3174
3174
  function asPositiveNumber(value, label) {
3175
3175
  if (value === void 0) return void 0;
3176
3176
  if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
3177
- throw new Error(`${label} must be a non-negative number.`);
3177
+ throw new Error(`${label} must be a non-negative finite number.`);
3178
3178
  }
3179
3179
  return value;
3180
3180
  }
3181
- function asExpectConfig(value, label) {
3181
+ function asBoolean(value, label) {
3182
3182
  if (value === void 0) return void 0;
3183
+ if (typeof value !== "boolean") {
3184
+ throw new Error(`${label} must be a boolean (not a string or other type).`);
3185
+ }
3186
+ return value;
3187
+ }
3188
+ function assertObject(value, label) {
3183
3189
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
3184
3190
  throw new Error(`${label} must be an object.`);
3185
3191
  }
3186
- const raw = value;
3192
+ return value;
3193
+ }
3194
+ function assertKnownKeys(raw, allowed, label) {
3195
+ const allowedSet = new Set(allowed);
3196
+ for (const key of Object.keys(raw)) {
3197
+ if (!allowedSet.has(key)) {
3198
+ throw new Error(`${label} has unknown key "${key}".`);
3199
+ }
3200
+ }
3201
+ }
3202
+ var CASE_KEYS = [
3203
+ "id",
3204
+ "trace",
3205
+ "runId",
3206
+ "input",
3207
+ "requireTools",
3208
+ "forbidTools",
3209
+ "maxDurationMs",
3210
+ "expectedObservations",
3211
+ "expect"
3212
+ ];
3213
+ var EXPECT_KEYS = [
3214
+ "checkStatus",
3215
+ "findingRuleIds",
3216
+ "rejectUnexpectedFindings",
3217
+ "minAssertions"
3218
+ ];
3219
+ var CHECKS_KEYS = ["select", "run", "tool", "llm"];
3220
+ var CHECKS_RUN_KEYS = ["maxDurationMs", "maxDepth"];
3221
+ var CHECKS_TOOL_KEYS = ["required", "forbidden"];
3222
+ var CHECKS_LLM_KEYS = ["allowedModels", "maxTotalTokens"];
3223
+ var EVAL_KEYS = [
3224
+ "requireSuccess",
3225
+ "requiredTools",
3226
+ "forbiddenTools",
3227
+ "maxDurationMs",
3228
+ "maxDepth",
3229
+ "maxRetries",
3230
+ "maxTotalTokens"
3231
+ ];
3232
+ var ROOT_KEYS = [
3233
+ "name",
3234
+ "traces",
3235
+ "cases",
3236
+ "checks",
3237
+ "eval",
3238
+ "redactionProfile",
3239
+ "artifacts",
3240
+ "baseline",
3241
+ "candidate"
3242
+ ];
3243
+ function asExpectConfig(value, label) {
3244
+ if (value === void 0) return void 0;
3245
+ const raw = assertObject(value, label);
3246
+ assertKnownKeys(raw, EXPECT_KEYS, label);
3187
3247
  const checkStatus = raw.checkStatus;
3188
3248
  if (checkStatus !== "pass" && checkStatus !== "fail" && checkStatus !== "error") {
3189
3249
  throw new Error(`${label}.checkStatus must be "pass", "fail", or "error".`);
3190
3250
  }
3191
3251
  const findingRuleIds = asStringArray(raw.findingRuleIds, `${label}.findingRuleIds`);
3192
3252
  const minAssertions = asPositiveNumber(raw.minAssertions, `${label}.minAssertions`);
3193
- const rejectUnexpectedFindings = raw.rejectUnexpectedFindings === void 0 ? void 0 : typeof raw.rejectUnexpectedFindings === "boolean" ? raw.rejectUnexpectedFindings : (() => {
3194
- throw new Error(`${label}.rejectUnexpectedFindings must be a boolean.`);
3195
- })();
3253
+ const rejectUnexpectedFindings = asBoolean(
3254
+ raw.rejectUnexpectedFindings,
3255
+ `${label}.rejectUnexpectedFindings`
3256
+ );
3196
3257
  return {
3197
3258
  checkStatus,
3198
3259
  ...findingRuleIds !== void 0 ? { findingRuleIds } : {},
@@ -3200,6 +3261,56 @@ function asExpectConfig(value, label) {
3200
3261
  ...minAssertions !== void 0 ? { minAssertions } : {}
3201
3262
  };
3202
3263
  }
3264
+ function asChecksConfig(value, label) {
3265
+ const raw = assertObject(value, label);
3266
+ assertKnownKeys(raw, CHECKS_KEYS, label);
3267
+ const checks = {};
3268
+ const select = asStringArray(raw.select, `${label}.select`);
3269
+ if (select !== void 0) checks.select = select;
3270
+ if (raw.run !== void 0) {
3271
+ const run = assertObject(raw.run, `${label}.run`);
3272
+ assertKnownKeys(run, CHECKS_RUN_KEYS, `${label}.run`);
3273
+ checks.run = {
3274
+ ...asPositiveNumber(run.maxDurationMs, `${label}.run.maxDurationMs`) !== void 0 ? { maxDurationMs: asPositiveNumber(run.maxDurationMs, `${label}.run.maxDurationMs`) } : {},
3275
+ ...asPositiveNumber(run.maxDepth, `${label}.run.maxDepth`) !== void 0 ? { maxDepth: asPositiveNumber(run.maxDepth, `${label}.run.maxDepth`) } : {}
3276
+ };
3277
+ }
3278
+ if (raw.tool !== void 0) {
3279
+ const tool = assertObject(raw.tool, `${label}.tool`);
3280
+ assertKnownKeys(tool, CHECKS_TOOL_KEYS, `${label}.tool`);
3281
+ checks.tool = {
3282
+ ...asStringArray(tool.required, `${label}.tool.required`) !== void 0 ? { required: asStringArray(tool.required, `${label}.tool.required`) } : {},
3283
+ ...asStringArray(tool.forbidden, `${label}.tool.forbidden`) !== void 0 ? { forbidden: asStringArray(tool.forbidden, `${label}.tool.forbidden`) } : {}
3284
+ };
3285
+ }
3286
+ if (raw.llm !== void 0) {
3287
+ const llm = assertObject(raw.llm, `${label}.llm`);
3288
+ assertKnownKeys(llm, CHECKS_LLM_KEYS, `${label}.llm`);
3289
+ checks.llm = {
3290
+ ...asStringArray(llm.allowedModels, `${label}.llm.allowedModels`) !== void 0 ? { allowedModels: asStringArray(llm.allowedModels, `${label}.llm.allowedModels`) } : {},
3291
+ ...asPositiveNumber(llm.maxTotalTokens, `${label}.llm.maxTotalTokens`) !== void 0 ? {
3292
+ maxTotalTokens: asPositiveNumber(
3293
+ llm.maxTotalTokens,
3294
+ `${label}.llm.maxTotalTokens`
3295
+ )
3296
+ } : {}
3297
+ };
3298
+ }
3299
+ return checks;
3300
+ }
3301
+ function asEvalConfig(value, label) {
3302
+ const raw = assertObject(value, label);
3303
+ assertKnownKeys(raw, EVAL_KEYS, label);
3304
+ return {
3305
+ ...asBoolean(raw.requireSuccess, `${label}.requireSuccess`) !== void 0 ? { requireSuccess: asBoolean(raw.requireSuccess, `${label}.requireSuccess`) } : {},
3306
+ ...asStringArray(raw.requiredTools, `${label}.requiredTools`) !== void 0 ? { requiredTools: asStringArray(raw.requiredTools, `${label}.requiredTools`) } : {},
3307
+ ...asStringArray(raw.forbiddenTools, `${label}.forbiddenTools`) !== void 0 ? { forbiddenTools: asStringArray(raw.forbiddenTools, `${label}.forbiddenTools`) } : {},
3308
+ ...asPositiveNumber(raw.maxDurationMs, `${label}.maxDurationMs`) !== void 0 ? { maxDurationMs: asPositiveNumber(raw.maxDurationMs, `${label}.maxDurationMs`) } : {},
3309
+ ...asPositiveNumber(raw.maxDepth, `${label}.maxDepth`) !== void 0 ? { maxDepth: asPositiveNumber(raw.maxDepth, `${label}.maxDepth`) } : {},
3310
+ ...asPositiveNumber(raw.maxRetries, `${label}.maxRetries`) !== void 0 ? { maxRetries: asPositiveNumber(raw.maxRetries, `${label}.maxRetries`) } : {},
3311
+ ...asPositiveNumber(raw.maxTotalTokens, `${label}.maxTotalTokens`) !== void 0 ? { maxTotalTokens: asPositiveNumber(raw.maxTotalTokens, `${label}.maxTotalTokens`) } : {}
3312
+ };
3313
+ }
3203
3314
  function validateCaseConfig(value, index) {
3204
3315
  const diagnostics = [];
3205
3316
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
@@ -3210,6 +3321,7 @@ function validateCaseConfig(value, index) {
3210
3321
  }
3211
3322
  const raw = value;
3212
3323
  try {
3324
+ assertKnownKeys(raw, CASE_KEYS, `cases[${index}]`);
3213
3325
  const id = asString(raw.id, `cases[${index}].id`);
3214
3326
  if (id === void 0) {
3215
3327
  diagnostics.push(
@@ -3258,6 +3370,7 @@ function normalizeSuiteConfig(value) {
3258
3370
  throw new Error("Suite config must export an object.");
3259
3371
  }
3260
3372
  const raw = value;
3373
+ assertKnownKeys(raw, ROOT_KEYS, "suite config");
3261
3374
  const name = asString(raw.name, "name");
3262
3375
  const traces = asString(raw.traces, "traces");
3263
3376
  if (name === void 0) throw new Error("name is required.");
@@ -3286,25 +3399,15 @@ function normalizeSuiteConfig(value) {
3286
3399
  }
3287
3400
  const config = { name, traces, cases };
3288
3401
  if (raw.checks !== void 0) {
3289
- if (typeof raw.checks !== "object" || Array.isArray(raw.checks)) {
3290
- throw new Error("checks must be an object.");
3291
- }
3292
- config.checks = raw.checks;
3402
+ config.checks = asChecksConfig(raw.checks, "checks");
3293
3403
  }
3294
3404
  if (raw.eval !== void 0) {
3295
- if (typeof raw.eval !== "object" || Array.isArray(raw.eval)) {
3296
- throw new Error("eval must be an object.");
3297
- }
3298
- config.eval = raw.eval;
3405
+ config.eval = asEvalConfig(raw.eval, "eval");
3299
3406
  }
3300
3407
  if (raw.artifacts !== void 0) {
3301
- if (typeof raw.artifacts !== "object" || Array.isArray(raw.artifacts)) {
3302
- throw new Error("artifacts must be an object.");
3303
- }
3304
- const outputDir = asString(
3305
- raw.artifacts.outputDir,
3306
- "artifacts.outputDir"
3307
- );
3408
+ const artifacts = assertObject(raw.artifacts, "artifacts");
3409
+ assertKnownKeys(artifacts, ["outputDir"], "artifacts");
3410
+ const outputDir = asString(artifacts.outputDir, "artifacts.outputDir");
3308
3411
  config.artifacts = outputDir !== void 0 ? { outputDir } : {};
3309
3412
  }
3310
3413
  if (raw.baseline !== void 0) {