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