@agent-inspect/eval 6.8.0 → 6.9.0

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
@@ -251,7 +251,12 @@ var SHARE_PROFILE_EXTRA_KEYS = [
251
251
  "organizationId",
252
252
  "traceId",
253
253
  "spanId",
254
- "parentSpanId"
254
+ "parentSpanId",
255
+ "currentTask",
256
+ "task",
257
+ "userInput",
258
+ "requestText",
259
+ "conversationText"
255
260
  ];
256
261
  var STRICT_PROFILE_EXTRA_KEYS = [
257
262
  "prompt",
@@ -319,6 +324,61 @@ function passesLuhn(value) {
319
324
  }
320
325
  return sum % 10 === 0;
321
326
  }
327
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
328
+ var EPOCH_MS_RE = /^1[0-9]{12}$/;
329
+ var EMAIL_RE = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi;
330
+ function pathSuggestsNonCard(path) {
331
+ const normalized = path.toLowerCase().replace(/[^a-z0-9._]/g, "");
332
+ return /(^|\.)(tokenusage|usage)(\.|$)/.test(normalized) || /(startedat|endedat|durationms|timestamp|createdat|updatedat)(\.|$)/.test(normalized) || /(^|\.)(runid|traceid|spanid|eventid|sessionid|userid|parentid|requestid|correlationid)(\.|$)/.test(
333
+ normalized
334
+ ) || /(^|\.)ts(\.|$)/.test(normalized);
335
+ }
336
+ function isUuidLike(value) {
337
+ return UUID_RE.test(value.trim());
338
+ }
339
+ function isPlausibleCardCandidate(candidate, fullValue) {
340
+ const digits = digitsOnly(candidate);
341
+ if (digits.length < 13 || digits.length > 19) return false;
342
+ if (!passesLuhn(candidate)) return false;
343
+ const trimmed = fullValue.trim();
344
+ if (isUuidLike(trimmed)) return false;
345
+ if (EPOCH_MS_RE.test(digits) && digitsOnly(trimmed) === digits && /^\d+$/.test(trimmed)) {
346
+ return false;
347
+ }
348
+ const start = fullValue.indexOf(candidate);
349
+ if (start >= 0) {
350
+ const before = fullValue[start - 1];
351
+ const after = fullValue[start + candidate.length];
352
+ if (before && /[A-Za-z0-9_]/.test(before)) return false;
353
+ if (after && /[A-Za-z0-9_]/.test(after)) return false;
354
+ }
355
+ return true;
356
+ }
357
+ function looksLikePathOrPackageOrUrl(value) {
358
+ const trimmed = value.trim();
359
+ if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(trimmed)) return true;
360
+ if (/^webpack:/i.test(trimmed)) return true;
361
+ if (/^@[A-Za-z0-9_.-]+\/[A-Za-z0-9_.@/-]+$/.test(trimmed)) return true;
362
+ if (/^[A-Za-z]:[\\/]/.test(trimmed) || /^[/\\]/.test(trimmed)) return true;
363
+ if (/[\\/]/.test(trimmed) && !/\s/.test(trimmed)) return true;
364
+ return false;
365
+ }
366
+ function emailMatchIsPathAdjacent(value, index, length) {
367
+ const before = value[index - 1];
368
+ const after = value[index + length];
369
+ return before === "/" || before === "\\" || after === "/" || after === "\\";
370
+ }
371
+ function valueContainsEmail(value) {
372
+ if (looksLikePathOrPackageOrUrl(value)) return false;
373
+ EMAIL_RE.lastIndex = 0;
374
+ for (const match of value.matchAll(EMAIL_RE)) {
375
+ const text = match[0] ?? "";
376
+ const index = match.index ?? 0;
377
+ if (emailMatchIsPathAdjacent(value, index, text.length)) continue;
378
+ return true;
379
+ }
380
+ return false;
381
+ }
322
382
  var credentialDetectors = [
323
383
  patternDetector({
324
384
  id: "value.authorizationHeader",
@@ -366,10 +426,12 @@ var credentialDetectors = [
366
426
  matchKind: "value",
367
427
  detect(input) {
368
428
  if (typeof input.value !== "string") return [];
429
+ if (pathSuggestsNonCard(input.path)) return [];
430
+ if (isUuidLike(input.value)) return [];
369
431
  const candidatePattern = /(?:\d[ -]?){13,19}/g;
370
432
  for (const match of input.value.matchAll(candidatePattern)) {
371
433
  const candidate = match[0] ?? "";
372
- if (passesLuhn(candidate)) {
434
+ if (isPlausibleCardCandidate(candidate, input.value)) {
373
435
  return [{ action: "replace", severity: "error", matchKind: "value" }];
374
436
  }
375
437
  }
@@ -378,10 +440,15 @@ var credentialDetectors = [
378
440
  }
379
441
  ];
380
442
  var identifierDetectors = [
381
- patternDetector({
443
+ {
382
444
  id: "value.email",
383
- pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i
384
- }),
445
+ severity: "warning",
446
+ matchKind: "value",
447
+ detect(input) {
448
+ if (typeof input.value !== "string") return [];
449
+ return valueContainsEmail(input.value) ? [{ action: "replace", severity: "warning", matchKind: "value" }] : [];
450
+ }
451
+ },
385
452
  patternDetector({
386
453
  id: "value.phone",
387
454
  pattern: /\b(?:\+\d{1,3}[\s.-]?)?(?:\(?\d{3}\)?[\s.-])\d{3}[\s.-]\d{4}\b/