UNPKG

autotel

Version:
50 lines (49 loc) 1.87 kB
//#region src/evidence.ts /** Prefix for per-field evidence labels. */ const EVIDENCE_ATTR_PREFIX = "autotel.evidence."; /** The span attribute key carrying `field`'s evidence label. */ function evidenceAttribute(field) { return `${EVIDENCE_ATTR_PREFIX}${field}`; } /** Label how `field` on this span came to be. */ function recordEvidence(ctx, field, quality) { ctx.setAttribute(evidenceAttribute(field), quality); } /** * The capture surfaces a deployment can be asked about. Closed set, because the * point is that a backend can query `unobserved` across services and get * comparable answers. */ const CAPTURE_SURFACES = [ "llm_calls", "tool_calls", "user_prompts", "file_io", "subprocess", "network", "ide_context" ]; const CAPTURE_COVERAGE_ATTR = { observed: "autotel.coverage.observed", unobserved: "autotel.coverage.unobserved" }; /** * Resource attributes declaring {@link CaptureCoverage}. * * An empty list is omitted rather than emitted: `unobserved: []` would read as * "this process has no blind spots", which is a stronger claim than declaring * nothing. A surface claimed as both is dropped from both — a contradiction * that left `observed` intact would let a reader conclude a gap does not exist. */ function captureCoverageAttributes(coverage) { const claimedBoth = new Set(coverage.observed.filter((s) => coverage.unobserved.includes(s))); const keep = (surfaces) => [...new Set(surfaces.filter((s) => !claimedBoth.has(s)))]; const observed = keep(coverage.observed); const unobserved = keep(coverage.unobserved); return { ...observed.length > 0 && { [CAPTURE_COVERAGE_ATTR.observed]: observed }, ...unobserved.length > 0 && { [CAPTURE_COVERAGE_ATTR.unobserved]: unobserved } }; } //#endregion export { CAPTURE_COVERAGE_ATTR, CAPTURE_SURFACES, EVIDENCE_ATTR_PREFIX, captureCoverageAttributes, evidenceAttribute, recordEvidence };