autotel
Version:
Write Once, Observe Anywhere
57 lines (55 loc) • 2.12 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
//#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
exports.CAPTURE_COVERAGE_ATTR = CAPTURE_COVERAGE_ATTR;
exports.CAPTURE_SURFACES = CAPTURE_SURFACES;
exports.EVIDENCE_ATTR_PREFIX = EVIDENCE_ATTR_PREFIX;
exports.captureCoverageAttributes = captureCoverageAttributes;
exports.evidenceAttribute = evidenceAttribute;
exports.recordEvidence = recordEvidence;