@obsunified/collector 2.1.1 → 2.2.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/{chunk-XKQTVIRE.js → chunk-ZSF5XP3B.js} +8 -2
- package/dist/chunk-ZSF5XP3B.js.map +1 -0
- package/dist/index.d.ts +309 -2
- package/dist/index.js +4159 -256
- package/dist/index.js.map +1 -1
- package/dist/{openai-FJYOQ7WO.js → openai-GSJZGFGL.js} +2 -2
- package/package.json +2 -2
- package/src/__tests__/autosre-closed-loop.test.ts +1275 -0
- package/src/index.ts +43 -0
- package/src/lib/analyses-runner.ts +9 -0
- package/src/lib/autosre-change-correlation.ts +780 -0
- package/src/lib/autosre-findings.ts +725 -0
- package/src/lib/autosre-ontology.ts +914 -0
- package/src/lib/autosre-remediation-gate.ts +1663 -0
- package/src/lib/eval-cases-store.ts +63 -1
- package/src/lib/evidence-references.ts +6 -0
- package/src/lib/housekeeping.test.ts +80 -0
- package/src/lib/housekeeping.ts +101 -1
- package/src/lib/store/ingest.ts +94 -6
- package/src/migrations/050_autosre_causal_ontology.sql +216 -0
- package/src/migrations/alert-state-notified.test.ts +3 -3
- package/src/migrations/parity.test.ts +4 -0
- package/src/migrations/project-scoped-keys.test.ts +1 -1
- package/src/migrations-postgres/050_autosre_causal_ontology.sql +216 -0
- package/src/plugins/alerts-evaluator.ts +17 -1
- package/src/plugins/autosre-routes.ts +1019 -0
- package/src/plugins/connected-routes/manifest.ts +13 -1
- package/src/plugins/connected-routes.ts +271 -0
- package/src/plugins/default-span-enrichment.ts +13 -1
- package/src/plugins/eval-cases-routes.ts +57 -2
- package/src/plugins/evidence-retrieval-routes.ts +300 -4
- package/dist/chunk-XKQTVIRE.js.map +0 -1
- /package/dist/{openai-FJYOQ7WO.js.map → openai-GSJZGFGL.js.map} +0 -0
|
@@ -12,6 +12,13 @@ import type {
|
|
|
12
12
|
TelemetryTraceDetailResponse,
|
|
13
13
|
} from "@obsunified/types";
|
|
14
14
|
import type { CollectorPlugin } from "../framework/collector";
|
|
15
|
+
import {
|
|
16
|
+
computeChangeBlastRadius,
|
|
17
|
+
listChangeEvents,
|
|
18
|
+
} from "../lib/autosre-change-correlation";
|
|
19
|
+
import { searchInvestigationFindings } from "../lib/autosre-findings";
|
|
20
|
+
import { loadTraceFaultLocusFromDb } from "../lib/autosre-ontology";
|
|
21
|
+
import { getIncidentInvestigation } from "../lib/autosre-remediation-gate";
|
|
15
22
|
import type {
|
|
16
23
|
ActionRef,
|
|
17
24
|
EntityManifestExtended,
|
|
@@ -75,7 +82,7 @@ interface ReplayEvidenceRow {
|
|
|
75
82
|
|
|
76
83
|
interface AICallEvidenceRow {
|
|
77
84
|
call_id: string;
|
|
78
|
-
trace_id: string
|
|
85
|
+
trace_id: string;
|
|
79
86
|
span_id?: string | null;
|
|
80
87
|
service_name?: string | null;
|
|
81
88
|
model_name: string;
|
|
@@ -105,6 +112,7 @@ const DEFAULT_PROFILE_FRAME_LIMIT = 50;
|
|
|
105
112
|
const MAX_PROFILE_FRAME_LIMIT = 200;
|
|
106
113
|
const EVIDENCE_INTENTS = new Set<EvidenceBundleIntent>([
|
|
107
114
|
"debug_failure",
|
|
115
|
+
"triage_incident",
|
|
108
116
|
"explain_latency",
|
|
109
117
|
"explain_cost",
|
|
110
118
|
"inspect_agent_run",
|
|
@@ -1460,6 +1468,187 @@ const buildActionGraphBundle = (
|
|
|
1460
1468
|
return bundle;
|
|
1461
1469
|
};
|
|
1462
1470
|
|
|
1471
|
+
const attachAutoSreTriageContext = async (
|
|
1472
|
+
db: SqlDb,
|
|
1473
|
+
projectId: string,
|
|
1474
|
+
traceId: string | null,
|
|
1475
|
+
bundle: EvidenceBundle,
|
|
1476
|
+
): Promise<EvidenceBundle> => {
|
|
1477
|
+
try {
|
|
1478
|
+
const faultLocus = traceId
|
|
1479
|
+
? await loadTraceFaultLocusFromDb(db, projectId, traceId)
|
|
1480
|
+
: null;
|
|
1481
|
+
const environment = (
|
|
1482
|
+
faultLocus?.faultLocusSpan?.environment ??
|
|
1483
|
+
bundle.environment ??
|
|
1484
|
+
"default"
|
|
1485
|
+
).toLowerCase();
|
|
1486
|
+
const recentChanges = await listChangeEvents(db, {
|
|
1487
|
+
projectId,
|
|
1488
|
+
environment,
|
|
1489
|
+
limit: 5,
|
|
1490
|
+
});
|
|
1491
|
+
const blastRadii = (
|
|
1492
|
+
await Promise.all(
|
|
1493
|
+
recentChanges
|
|
1494
|
+
.slice(0, 3)
|
|
1495
|
+
.map((ch) =>
|
|
1496
|
+
computeChangeBlastRadius(db, projectId, ch.id, { environment }),
|
|
1497
|
+
),
|
|
1498
|
+
)
|
|
1499
|
+
).filter((br): br is NonNullable<typeof br> => Boolean(br));
|
|
1500
|
+
|
|
1501
|
+
const candidateChanges = blastRadii.map((br) => ({
|
|
1502
|
+
changeId: br.change.id,
|
|
1503
|
+
kind: br.change.kind,
|
|
1504
|
+
version: br.change.version,
|
|
1505
|
+
previousVersion: br.change.previousVersion,
|
|
1506
|
+
occurredAt: br.change.occurredAt,
|
|
1507
|
+
cohortVerdict: br.cohortVerdict,
|
|
1508
|
+
causalProofTier: br.causalProofTier,
|
|
1509
|
+
rateNew: br.newCohort.errorRate,
|
|
1510
|
+
rateOld: br.oldCohort.errorRate,
|
|
1511
|
+
sampleNew: br.newCohort.requestCount,
|
|
1512
|
+
sampleOld: br.oldCohort.requestCount,
|
|
1513
|
+
overlappingCodePaths: br.overlappingCodePaths,
|
|
1514
|
+
}));
|
|
1515
|
+
const contentionCandidates = blastRadii
|
|
1516
|
+
.flatMap((br) => br.sharedResourceAggressors)
|
|
1517
|
+
.map((ag) => ({
|
|
1518
|
+
aggressorTraceId: ag.aggressorTraceId,
|
|
1519
|
+
aggressorSpanId: ag.aggressorSpanId,
|
|
1520
|
+
aggressorServiceName: ag.aggressorServiceName,
|
|
1521
|
+
sharedTargetNodeId: ag.sharedTargetNodeId,
|
|
1522
|
+
relationshipCertainty: ag.relationshipCertainty,
|
|
1523
|
+
totalResourceTimeMs: ag.totalResourceTimeMs,
|
|
1524
|
+
}));
|
|
1525
|
+
let priorFindingsList = await searchInvestigationFindings(db, {
|
|
1526
|
+
projectId,
|
|
1527
|
+
environment,
|
|
1528
|
+
rootCauseEntityId:
|
|
1529
|
+
faultLocus?.faultLocusNodeId ??
|
|
1530
|
+
faultLocus?.faultLocusSpan?.span_id ??
|
|
1531
|
+
undefined,
|
|
1532
|
+
limit: 5,
|
|
1533
|
+
});
|
|
1534
|
+
if (priorFindingsList.length === 0 && faultLocus?.faultLocusSpan?.span_id) {
|
|
1535
|
+
priorFindingsList = await searchInvestigationFindings(db, {
|
|
1536
|
+
projectId,
|
|
1537
|
+
environment,
|
|
1538
|
+
rootCauseEntityId: faultLocus.faultLocusSpan.span_id,
|
|
1539
|
+
limit: 5,
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
if (priorFindingsList.length === 0) {
|
|
1543
|
+
priorFindingsList = await searchInvestigationFindings(db, {
|
|
1544
|
+
projectId,
|
|
1545
|
+
environment,
|
|
1546
|
+
limit: 5,
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
const priorFindings = priorFindingsList.map((f) => ({
|
|
1550
|
+
findingId: f.id,
|
|
1551
|
+
title: f.title,
|
|
1552
|
+
causalProofTier: f.causalProofTier,
|
|
1553
|
+
causalVerificationStatus: f.causalVerificationStatus,
|
|
1554
|
+
recoveryStatus: f.recoveryStatus,
|
|
1555
|
+
contributingChangeId: f.contributingChangeId,
|
|
1556
|
+
occurredAt: f.createdAt,
|
|
1557
|
+
}));
|
|
1558
|
+
|
|
1559
|
+
for (const br of blastRadii) {
|
|
1560
|
+
const changeId = br.change.id;
|
|
1561
|
+
const changeRoute = `#/changes/${encodeURIComponent(changeId)}`;
|
|
1562
|
+
bundle.evidenceReferences.push({
|
|
1563
|
+
evidenceId: `change:${changeId}`,
|
|
1564
|
+
entityKind: "change",
|
|
1565
|
+
entityId: changeId,
|
|
1566
|
+
route: changeRoute,
|
|
1567
|
+
source: br.overlappingCodePaths.length
|
|
1568
|
+
? "stack_frame_overlap"
|
|
1569
|
+
: "cohort_comparison",
|
|
1570
|
+
confidence:
|
|
1571
|
+
br.cohortVerdict === "isolated_to_new_version" ? 0.9 : 0.65,
|
|
1572
|
+
relationshipCertainty: br.relationshipCertainty,
|
|
1573
|
+
causalProofTier: br.causalProofTier,
|
|
1574
|
+
reason: br.summary,
|
|
1575
|
+
citations: [
|
|
1576
|
+
{
|
|
1577
|
+
label: `change ${changeId} (${br.change.version ?? br.change.kind})`,
|
|
1578
|
+
entityKind: "change",
|
|
1579
|
+
entityId: changeId,
|
|
1580
|
+
route: changeRoute,
|
|
1581
|
+
},
|
|
1582
|
+
],
|
|
1583
|
+
suggestedNextPivots: [
|
|
1584
|
+
{
|
|
1585
|
+
label: "Inspect change blast radius",
|
|
1586
|
+
entityKind: "change",
|
|
1587
|
+
entityId: changeId,
|
|
1588
|
+
route: changeRoute,
|
|
1589
|
+
reason: "Inspect traffic-normalized cohort lift and contention.",
|
|
1590
|
+
},
|
|
1591
|
+
],
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
for (const finding of priorFindingsList) {
|
|
1596
|
+
const findingRoute = `#/findings/${encodeURIComponent(finding.id)}`;
|
|
1597
|
+
bundle.evidenceReferences.push({
|
|
1598
|
+
evidenceId: `finding:${finding.id}`,
|
|
1599
|
+
entityKind: "finding",
|
|
1600
|
+
entityId: finding.id,
|
|
1601
|
+
route: findingRoute,
|
|
1602
|
+
source: "incident_memory_fingerprint",
|
|
1603
|
+
confidence: finding.confidence,
|
|
1604
|
+
relationshipCertainty: "exact",
|
|
1605
|
+
causalProofTier: finding.causalProofTier,
|
|
1606
|
+
reason: `Prior finding (${finding.causalProofTier}): ${finding.title}`,
|
|
1607
|
+
citations: [
|
|
1608
|
+
{
|
|
1609
|
+
label: finding.title,
|
|
1610
|
+
entityKind: "finding",
|
|
1611
|
+
entityId: finding.id,
|
|
1612
|
+
route: findingRoute,
|
|
1613
|
+
},
|
|
1614
|
+
],
|
|
1615
|
+
suggestedNextPivots: [
|
|
1616
|
+
{
|
|
1617
|
+
label: "Open prior finding",
|
|
1618
|
+
entityKind: "finding",
|
|
1619
|
+
entityId: finding.id,
|
|
1620
|
+
route: findingRoute,
|
|
1621
|
+
reason: "Search incident memory for similar recurring findings.",
|
|
1622
|
+
},
|
|
1623
|
+
],
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
bundle.autosre = {
|
|
1628
|
+
faultLocus: faultLocus?.faultLocusNodeId
|
|
1629
|
+
? {
|
|
1630
|
+
nodeId: faultLocus.faultLocusNodeId,
|
|
1631
|
+
spanId: faultLocus.faultLocusSpan?.span_id,
|
|
1632
|
+
relationshipCertainty: faultLocus.relationshipCertainty,
|
|
1633
|
+
isBlackoutSuspected: false,
|
|
1634
|
+
}
|
|
1635
|
+
: undefined,
|
|
1636
|
+
candidateChanges,
|
|
1637
|
+
contentionCandidates,
|
|
1638
|
+
priorFindings,
|
|
1639
|
+
};
|
|
1640
|
+
if (bundle.budget) {
|
|
1641
|
+
bundle.budget = {
|
|
1642
|
+
...bundle.budget,
|
|
1643
|
+
estimatedTokens: estimateTokens(bundle),
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
} catch {
|
|
1647
|
+
// Gracefully degrade if AutoSRE tables are absent in minimal test setups
|
|
1648
|
+
}
|
|
1649
|
+
return bundle;
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1463
1652
|
const parseBundleRequest = async (request: Request) => {
|
|
1464
1653
|
try {
|
|
1465
1654
|
const body = await request.json();
|
|
@@ -1550,7 +1739,7 @@ export const evidenceRetrievalRoutesPlugin: CollectorPlugin = {
|
|
|
1550
1739
|
all.findIndex((candidate) => candidate.id === profile.id) ===
|
|
1551
1740
|
index,
|
|
1552
1741
|
);
|
|
1553
|
-
|
|
1742
|
+
let bundle = buildActionGraphBundle(
|
|
1554
1743
|
projectId,
|
|
1555
1744
|
anchor.entityKind,
|
|
1556
1745
|
anchor.entityId,
|
|
@@ -1560,15 +1749,114 @@ export const evidenceRetrievalRoutesPlugin: CollectorPlugin = {
|
|
|
1560
1749
|
targetTokens,
|
|
1561
1750
|
detailLevel,
|
|
1562
1751
|
);
|
|
1752
|
+
if (intent === "triage_incident") {
|
|
1753
|
+
bundle = await attachAutoSreTriageContext(
|
|
1754
|
+
db,
|
|
1755
|
+
projectId,
|
|
1756
|
+
traceIds[0] ?? null,
|
|
1757
|
+
bundle,
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1563
1760
|
return c.json(await materializeBundle(db, projectId, bundle));
|
|
1564
1761
|
}
|
|
1565
1762
|
|
|
1763
|
+
if (anchor.entityKind === "incident") {
|
|
1764
|
+
const incident = await getIncidentInvestigation(
|
|
1765
|
+
db,
|
|
1766
|
+
projectId,
|
|
1767
|
+
anchor.entityId,
|
|
1768
|
+
);
|
|
1769
|
+
if (!incident) {
|
|
1770
|
+
return c.json(
|
|
1771
|
+
{ error: "Not Found", message: "Incident not found" },
|
|
1772
|
+
404,
|
|
1773
|
+
);
|
|
1774
|
+
}
|
|
1775
|
+
const recentErrSpan = await db
|
|
1776
|
+
.prepare(
|
|
1777
|
+
`SELECT trace_id FROM telemetry_spans
|
|
1778
|
+
WHERE project_id = ? AND environment = ? AND status_code = 2
|
|
1779
|
+
ORDER BY start_time DESC LIMIT 1`,
|
|
1780
|
+
)
|
|
1781
|
+
.bind(projectId, incident.environment)
|
|
1782
|
+
.first<{ trace_id: string }>();
|
|
1783
|
+
|
|
1784
|
+
const incRoute = `#/incidents/${encodeURIComponent(incident.id)}`;
|
|
1785
|
+
const baseBundle: EvidenceBundle = {
|
|
1786
|
+
schemaVersion: BUNDLE_SCHEMA_VERSION,
|
|
1787
|
+
intent,
|
|
1788
|
+
environment: incident.environment,
|
|
1789
|
+
incidentId: incident.id,
|
|
1790
|
+
symptomFingerprint: incident.symptomFingerprint ?? undefined,
|
|
1791
|
+
anchor: { entityKind: "incident", entityId: incident.id },
|
|
1792
|
+
budget: { targetTokens, detailLevel },
|
|
1793
|
+
summary: `Incident ${incident.id} (${incident.status}) on ${incident.targetNodeId} in environment ${incident.environment}.`,
|
|
1794
|
+
derivedSummaries: [
|
|
1795
|
+
{
|
|
1796
|
+
title: `Incident ${incident.id}`,
|
|
1797
|
+
reason: `Trigger ${incident.symptomAnchorKind}:${incident.symptomAnchorId} on ${incident.targetNodeId} (status=${incident.status}).`,
|
|
1798
|
+
confidence: 1.0,
|
|
1799
|
+
evidenceIds: [`incident:${incident.id}`],
|
|
1800
|
+
retrievalRefIds: [],
|
|
1801
|
+
},
|
|
1802
|
+
],
|
|
1803
|
+
findings: [],
|
|
1804
|
+
compactions: [],
|
|
1805
|
+
evidenceReferences: [
|
|
1806
|
+
{
|
|
1807
|
+
evidenceId: `incident:${incident.id}`,
|
|
1808
|
+
entityKind: "incident",
|
|
1809
|
+
entityId: incident.id,
|
|
1810
|
+
route: incRoute,
|
|
1811
|
+
source: "incident_investigations",
|
|
1812
|
+
confidence: 1.0,
|
|
1813
|
+
relationshipCertainty: "exact",
|
|
1814
|
+
reason: `Incident triggered by ${incident.symptomAnchorKind}:${incident.symptomAnchorId}.`,
|
|
1815
|
+
citations: [
|
|
1816
|
+
{
|
|
1817
|
+
label: incident.targetNodeId,
|
|
1818
|
+
entityKind: "incident",
|
|
1819
|
+
entityId: incident.id,
|
|
1820
|
+
route: incRoute,
|
|
1821
|
+
},
|
|
1822
|
+
],
|
|
1823
|
+
suggestedNextPivots: [
|
|
1824
|
+
{
|
|
1825
|
+
label: "Open incident",
|
|
1826
|
+
entityKind: "incident",
|
|
1827
|
+
entityId: incident.id,
|
|
1828
|
+
route: incRoute,
|
|
1829
|
+
reason: "Inspect incident investigation and candidate changes.",
|
|
1830
|
+
},
|
|
1831
|
+
],
|
|
1832
|
+
},
|
|
1833
|
+
],
|
|
1834
|
+
retrievalRefs: [],
|
|
1835
|
+
suggestedNextPivots: [
|
|
1836
|
+
{
|
|
1837
|
+
label: "Open incident",
|
|
1838
|
+
entityKind: "incident",
|
|
1839
|
+
entityId: incident.id,
|
|
1840
|
+
route: incRoute,
|
|
1841
|
+
reason: "Inspect incident investigation and candidate changes.",
|
|
1842
|
+
},
|
|
1843
|
+
],
|
|
1844
|
+
};
|
|
1845
|
+
const enriched = await attachAutoSreTriageContext(
|
|
1846
|
+
db,
|
|
1847
|
+
projectId,
|
|
1848
|
+
recentErrSpan?.trace_id ?? null,
|
|
1849
|
+
baseBundle,
|
|
1850
|
+
);
|
|
1851
|
+
return c.json(await materializeBundle(db, projectId, enriched));
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1566
1854
|
if (anchor.entityKind !== "trace") {
|
|
1567
1855
|
return c.json(
|
|
1568
1856
|
{
|
|
1569
1857
|
error: "Bad Request",
|
|
1570
1858
|
message:
|
|
1571
|
-
"Supported evidence bundle anchors are trace, action, agent_run, and
|
|
1859
|
+
"Supported evidence bundle anchors are trace, action, agent_run, tool_call, and incident.",
|
|
1572
1860
|
},
|
|
1573
1861
|
400,
|
|
1574
1862
|
);
|
|
@@ -1588,7 +1876,7 @@ export const evidenceRetrievalRoutesPlugin: CollectorPlugin = {
|
|
|
1588
1876
|
limit: MAX_LOGS_FOR_BUNDLE,
|
|
1589
1877
|
});
|
|
1590
1878
|
const profiles = await profilesForTrace(db, projectId, traceId);
|
|
1591
|
-
|
|
1879
|
+
let bundle = await buildTraceBundle(
|
|
1592
1880
|
projectId,
|
|
1593
1881
|
detail,
|
|
1594
1882
|
logs.logs,
|
|
@@ -1598,6 +1886,14 @@ export const evidenceRetrievalRoutesPlugin: CollectorPlugin = {
|
|
|
1598
1886
|
detailLevel,
|
|
1599
1887
|
hours,
|
|
1600
1888
|
);
|
|
1889
|
+
if (intent === "triage_incident" || intent === "debug_failure") {
|
|
1890
|
+
bundle = await attachAutoSreTriageContext(
|
|
1891
|
+
db,
|
|
1892
|
+
projectId,
|
|
1893
|
+
traceId,
|
|
1894
|
+
bundle,
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1601
1897
|
return c.json(await materializeBundle(db, projectId, bundle));
|
|
1602
1898
|
});
|
|
1603
1899
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/evidence-references.ts","../src/lib/llm.ts"],"sourcesContent":["import type {\n\tAIEvaluationRecord,\n\tAlertEvaluation,\n\tAlertRule,\n\tAnalysisResult,\n\tAskEvidence,\n\tEvidenceCitation,\n\tEvidenceEntityKind,\n\tEvidenceNextPivot,\n\tEvidenceReference,\n\tJsonValue,\n} from \"@obsunified/types\";\n\nconst analysisRoute = (analysisId: string) =>\n\t`#/investigate/${encodeURIComponent(analysisId)}`;\n\nexport const analysisEvidenceReference = (\n\tevidence: AskEvidence,\n): EvidenceReference => {\n\tconst route = analysisRoute(evidence.analysisId);\n\tconst status = evidence.result?.status ?? \"unknown\";\n\treturn {\n\t\tevidenceId: `ask:analysis:${evidence.analysisId}`,\n\t\tentityKind: \"analysis\",\n\t\tentityId: evidence.analysisId,\n\t\troute,\n\t\tsource: \"ask.run_analysis\",\n\t\tconfidence: evidence.result ? 1 : 0.55,\n\t\treason: evidence.result\n\t\t\t? `Ask consulted analysis \"${evidence.definition.title}\" with latest status ${status}.`\n\t\t\t: `Ask consulted analysis \"${evidence.definition.title}\", but no latest result was available.`,\n\t\tcitations: [\n\t\t\t{\n\t\t\t\tlabel: evidence.definition.title,\n\t\t\t\tentityKind: \"analysis\",\n\t\t\t\tentityId: evidence.analysisId,\n\t\t\t\troute,\n\t\t\t},\n\t\t],\n\t\tsuggestedNextPivots: [\n\t\t\t{\n\t\t\t\tlabel: \"Open investigation\",\n\t\t\t\tentityKind: \"analysis\",\n\t\t\t\tentityId: evidence.analysisId,\n\t\t\t\troute,\n\t\t\t\treason:\n\t\t\t\t\t\"Review the analysis payload, narrative, and connected telemetry rail.\",\n\t\t\t},\n\t\t],\n\t};\n};\n\nexport const askEvidenceReferences = (\n\tevidence: Iterable<AskEvidence>,\n): EvidenceReference[] =>\n\t[...evidence].map((item) => analysisEvidenceReference(item));\n\nconst MAX_ANALYSIS_EVIDENCE_REFERENCES = 50;\n\ninterface EvidenceTable {\n\ttitle?: string | null;\n\theaders: string[];\n\trows: JsonValue[][];\n}\n\ninterface RowEntity {\n\tentityKind: EvidenceEntityKind;\n\tentityId: string;\n\troute: string;\n\tlabel: string;\n\tconfidence: number;\n\tcitations: EvidenceCitation[];\n\tsuggestedNextPivots: EvidenceNextPivot[];\n}\n\nconst isRecord = (value: unknown): value is Record<string, JsonValue> =>\n\t!!value && typeof value === \"object\" && !Array.isArray(value);\n\nconst asString = (value: JsonValue | undefined): string | null => {\n\tif (typeof value === \"string\" && value.trim()) return value.trim();\n\tif (typeof value === \"number\" && Number.isFinite(value)) return String(value);\n\treturn null;\n};\n\nconst normalizeHeader = (header: string) =>\n\theader\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/[\\s-]+/g, \"_\");\n\nconst valueFor = (\n\trow: JsonValue[],\n\theaderIndex: Map<string, number>,\n\tnames: string[],\n): string | null => {\n\tfor (const name of names) {\n\t\tconst index = headerIndex.get(name);\n\t\tif (index === undefined) continue;\n\t\tconst value = asString(row[index]);\n\t\tif (value) return value;\n\t}\n\treturn null;\n};\n\nconst traceRoute = (traceId: string) =>\n\t`#/traces/${encodeURIComponent(traceId)}`;\n\nconst spanRoute = (traceId: string, spanId: string) =>\n\t`${traceRoute(traceId)}#span=${encodeURIComponent(spanId)}`;\n\nexport const evidenceRouteFor = (\n\tentityKind: EvidenceEntityKind,\n\tentityId: string,\n\ttraceId?: string | null,\n) => {\n\tswitch (entityKind) {\n\t\tcase \"analysis\":\n\t\t\treturn analysisRoute(entityId);\n\t\tcase \"action\":\n\t\t\treturn `#/actions/${encodeURIComponent(entityId)}`;\n\t\tcase \"alert\":\n\t\t\treturn `#/alerts?alert=${encodeURIComponent(entityId)}`;\n\t\tcase \"agent_run\":\n\t\t\treturn `#/agent-runs/${encodeURIComponent(entityId)}`;\n\t\tcase \"ai_call\":\n\t\t\treturn `#/ai/calls/${encodeURIComponent(entityId)}`;\n\t\tcase \"eval\":\n\t\t\treturn `#/evals/${encodeURIComponent(entityId)}`;\n\t\tcase \"log\":\n\t\t\treturn `#/logs?id=${encodeURIComponent(entityId)}`;\n\t\tcase \"profile\":\n\t\t\treturn traceId\n\t\t\t\t? `#/profiles/${encodeURIComponent(entityId)}?trace_id=${encodeURIComponent(traceId)}`\n\t\t\t\t: `#/profiles/${encodeURIComponent(entityId)}`;\n\t\tcase \"replay\":\n\t\t\treturn `#/replay?session=${encodeURIComponent(entityId)}`;\n\t\tcase \"service\":\n\t\t\treturn `#/traces?service=${encodeURIComponent(entityId)}`;\n\t\tcase \"span\": {\n\t\t\tconst [tracePart, spanPart] = entityId.split(\":\");\n\t\t\treturn spanPart ? spanRoute(tracePart, spanPart) : `#/spans/${entityId}`;\n\t\t}\n\t\tcase \"tool_call\":\n\t\t\treturn `#/tool-calls/${encodeURIComponent(entityId)}`;\n\t\tcase \"trace\":\n\t\t\treturn traceRoute(entityId);\n\t\tcase \"docs\":\n\t\t\treturn entityId.startsWith(\"#/\") ? entityId : `#/docs/${entityId}`;\n\t}\n\tconst exhaustive: never = entityKind;\n\treturn exhaustive;\n};\n\nconst parseEvidenceTables = (\n\tpayload: Record<string, unknown>,\n): Array<{ sectionName: string; table: EvidenceTable }> => {\n\tconst evidence = payload.evidence;\n\tif (!isRecord(evidence)) return [];\n\n\tconst tables: Array<{ sectionName: string; table: EvidenceTable }> = [];\n\tfor (const [sectionName, section] of Object.entries(evidence)) {\n\t\tif (!isRecord(section)) continue;\n\t\tconst headers = section.headers;\n\t\tconst rows = section.rows;\n\t\tif (\n\t\t\t!Array.isArray(headers) ||\n\t\t\t!headers.every(\n\t\t\t\t(header): header is string => typeof header === \"string\",\n\t\t\t) ||\n\t\t\t!Array.isArray(rows)\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst normalizedRows = rows.filter((row): row is JsonValue[] =>\n\t\t\tArray.isArray(row),\n\t\t);\n\t\ttables.push({\n\t\t\tsectionName,\n\t\t\ttable: {\n\t\t\t\ttitle: asString(section.title),\n\t\t\t\theaders,\n\t\t\t\trows: normalizedRows,\n\t\t\t},\n\t\t});\n\t}\n\treturn tables;\n};\n\nconst instrumentationGapEvidenceReferences = (\n\tresult: Pick<AnalysisResult, \"analysisId\" | \"payload\">,\n): EvidenceReference[] => {\n\tconst gaps = result.payload.instrumentationGaps;\n\tif (!isRecord(gaps)) return [];\n\tconst traceId = asString(gaps.traceId);\n\tconst blindspots = gaps.blindspots;\n\tif (!traceId || !Array.isArray(blindspots)) return [];\n\n\treturn blindspots\n\t\t.filter(isRecord)\n\t\t.map((gap, index): EvidenceReference | null => {\n\t\t\tconst spanId = asString(gap.parentSpanId);\n\t\t\tif (!spanId) return null;\n\t\t\tconst serviceName = asString(gap.parentServiceName);\n\t\t\tconst spanName = asString(gap.parentSpanName);\n\t\t\tconst durationMs =\n\t\t\t\ttypeof gap.durationMs === \"number\" && Number.isFinite(gap.durationMs)\n\t\t\t\t\t? gap.durationMs\n\t\t\t\t\t: null;\n\t\t\tconst ratio =\n\t\t\t\ttypeof gap.ratioOfParent === \"number\" &&\n\t\t\t\tNumber.isFinite(gap.ratioOfParent)\n\t\t\t\t\t? gap.ratioOfParent\n\t\t\t\t\t: null;\n\t\t\tconst recommendation = asString(gap.recommendation);\n\t\t\tconst thresholdVersion =\n\t\t\t\tasString(gap.thresholdVersion) ??\n\t\t\t\t(isRecord(gaps.thresholds) ? asString(gaps.thresholds.version) : null);\n\t\t\tconst entityId = `${traceId}:${spanId}`;\n\t\t\tconst route = spanRoute(traceId, spanId);\n\t\t\tconst label = spanName ? `${spanName} (${spanId})` : `span ${spanId}`;\n\t\t\tconst durationText =\n\t\t\t\tdurationMs === null ? \"unknown duration\" : `${durationMs}ms`;\n\t\t\tconst ratioText =\n\t\t\t\tratio === null ? \"\" : `, ${(ratio * 100).toFixed(1)}% of parent`;\n\t\t\tconst thresholdText = thresholdVersion\n\t\t\t\t? ` Thresholds: ${thresholdVersion}.`\n\t\t\t\t: \"\";\n\t\t\tconst docsRoute = \"#/docs/howto/ebpf\";\n\t\t\treturn {\n\t\t\t\tevidenceId: `analysis:${result.analysisId}:instrumentation-gap:${index}:span:${entityId}`,\n\t\t\t\tentityKind: \"span\",\n\t\t\t\tentityId,\n\t\t\t\troute,\n\t\t\t\tsource: \"analysis.payload.instrumentationGaps\",\n\t\t\t\tconfidence: 0.9,\n\t\t\t\treason: `Analysis \"${result.analysisId}\" found uninstrumented self-time on ${label}: ${durationText}${ratioText}.${thresholdText}${recommendation ? ` ${recommendation}` : \"\"}`,\n\t\t\t\tcitations: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: `trace ${traceId}`,\n\t\t\t\t\t\tentityKind: \"trace\",\n\t\t\t\t\t\tentityId: traceId,\n\t\t\t\t\t\troute: traceRoute(traceId),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tsuggestedNextPivots: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: \"Open uninstrumented span\",\n\t\t\t\t\t\tentityKind: \"span\",\n\t\t\t\t\t\tentityId,\n\t\t\t\t\t\troute,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\"Inspect the parent span whose self-time suggests missing child instrumentation.\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: \"Open trace gap data\",\n\t\t\t\t\t\tentityKind: \"trace\",\n\t\t\t\t\t\tentityId: traceId,\n\t\t\t\t\t\troute: `${traceRoute(traceId)}/gaps`,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\"Review all structured instrumentation blindspots for this trace.\",\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: \"Open profiler setup docs\",\n\t\t\t\t\t\tentityKind: \"docs\",\n\t\t\t\t\t\tentityId: \"howto/ebpf\",\n\t\t\t\t\t\troute: docsRoute,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\tserviceName != null\n\t\t\t\t\t\t\t\t? `Use profiler or eBPF setup guidance to cover missing spans in ${serviceName}.`\n\t\t\t\t\t\t\t\t: \"Use profiler or eBPF setup guidance to cover missing spans.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t})\n\t\t.filter((ref): ref is EvidenceReference => ref !== null)\n\t\t.slice(0, MAX_ANALYSIS_EVIDENCE_REFERENCES);\n};\n\nconst entityFromRow = (\n\trow: JsonValue[],\n\theaders: string[],\n): RowEntity | null => {\n\tconst headerIndex = new Map(headers.map((header, index) => [header, index]));\n\tconst traceId = valueFor(row, headerIndex, [\"trace_id\", \"traceid\", \"trace\"]);\n\tconst spanId = valueFor(row, headerIndex, [\"span_id\", \"spanid\"]);\n\tconst logId = valueFor(row, headerIndex, [\"log_id\", \"logid\"]);\n\tconst profileId = valueFor(row, headerIndex, [\"profile_id\", \"profileid\"]);\n\tconst actionId = valueFor(row, headerIndex, [\"action_id\", \"actionid\"]);\n\tconst agentRunId = valueFor(row, headerIndex, [\n\t\t\"agent_run_id\",\n\t\t\"agentrunid\",\n\t\t\"agent_run\",\n\t]);\n\tconst toolCallId = valueFor(row, headerIndex, [\n\t\t\"tool_call_id\",\n\t\t\"toolcallid\",\n\t\t\"tool_call\",\n\t]);\n\tconst evalId = valueFor(row, headerIndex, [\"eval_id\", \"evalid\"]);\n\tconst service = valueFor(row, headerIndex, [\"service\", \"service_name\"]);\n\n\tconst traceCitation = traceId\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tlabel: `trace ${traceId}`,\n\t\t\t\t\tentityKind: \"trace\" as const,\n\t\t\t\t\tentityId: traceId,\n\t\t\t\t\troute: traceRoute(traceId),\n\t\t\t\t},\n\t\t\t]\n\t\t: [];\n\n\tif (traceId && spanId) {\n\t\tconst entityId = `${traceId}:${spanId}`;\n\t\treturn {\n\t\t\tentityKind: \"span\",\n\t\t\tentityId,\n\t\t\troute: spanRoute(traceId, spanId),\n\t\t\tlabel: `span ${spanId}`,\n\t\t\tconfidence: 0.95,\n\t\t\tcitations: traceCitation,\n\t\t\tsuggestedNextPivots: [\n\t\t\t\t{\n\t\t\t\t\tlabel: \"Open span\",\n\t\t\t\t\tentityKind: \"span\",\n\t\t\t\t\tentityId,\n\t\t\t\t\troute: spanRoute(traceId, spanId),\n\t\t\t\t\treason: \"Inspect the cited span in its trace context.\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: \"Open trace\",\n\t\t\t\t\tentityKind: \"trace\",\n\t\t\t\t\tentityId: traceId,\n\t\t\t\t\troute: traceRoute(traceId),\n\t\t\t\t\treason: \"Review the surrounding trace context.\",\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\n\tconst candidates: Array<{\n\t\tentityKind: EvidenceEntityKind;\n\t\tentityId: string | null;\n\t\tlabelPrefix: string;\n\t\tconfidence: number;\n\t}> = [\n\t\t{\n\t\t\tentityKind: \"trace\",\n\t\t\tentityId: traceId,\n\t\t\tlabelPrefix: \"trace\",\n\t\t\tconfidence: 0.95,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"action\",\n\t\t\tentityId: actionId,\n\t\t\tlabelPrefix: \"action\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"tool_call\",\n\t\t\tentityId: toolCallId,\n\t\t\tlabelPrefix: \"tool call\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"agent_run\",\n\t\t\tentityId: agentRunId,\n\t\t\tlabelPrefix: \"agent run\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"profile\",\n\t\t\tentityId: profileId,\n\t\t\tlabelPrefix: \"profile\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"log\",\n\t\t\tentityId: logId,\n\t\t\tlabelPrefix: \"log\",\n\t\t\tconfidence: 0.85,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"eval\",\n\t\t\tentityId: evalId,\n\t\t\tlabelPrefix: \"eval\",\n\t\t\tconfidence: 0.85,\n\t\t},\n\t\t{\n\t\t\tentityKind: \"service\",\n\t\t\tentityId: service,\n\t\t\tlabelPrefix: \"service\",\n\t\t\tconfidence: 0.7,\n\t\t},\n\t];\n\n\tconst candidate = candidates.find((item) => item.entityId);\n\tif (!candidate?.entityId) return null;\n\n\tconst route = evidenceRouteFor(\n\t\tcandidate.entityKind,\n\t\tcandidate.entityId,\n\t\ttraceId,\n\t);\n\treturn {\n\t\tentityKind: candidate.entityKind,\n\t\tentityId: candidate.entityId,\n\t\troute,\n\t\tlabel: `${candidate.labelPrefix} ${candidate.entityId}`,\n\t\tconfidence: candidate.confidence,\n\t\tcitations: traceCitation.filter(\n\t\t\t(citation) =>\n\t\t\t\tcitation.entityKind !== candidate.entityKind ||\n\t\t\t\tcitation.entityId !== candidate.entityId,\n\t\t),\n\t\tsuggestedNextPivots: [\n\t\t\t{\n\t\t\t\tlabel: `Open ${candidate.labelPrefix}`,\n\t\t\t\tentityKind: candidate.entityKind,\n\t\t\t\tentityId: candidate.entityId,\n\t\t\t\troute,\n\t\t\t\treason: \"Inspect the cited evidence row.\",\n\t\t\t},\n\t\t],\n\t};\n};\n\nexport const alertEvidenceReferences = (\n\trule: AlertRule,\n\tevaluation?: AlertEvaluation | null,\n): EvidenceReference[] => {\n\tconst route = evidenceRouteFor(\"alert\", rule.id);\n\tconst references: EvidenceReference[] = [\n\t\t{\n\t\t\tevidenceId: evaluation\n\t\t\t\t? `alert:${rule.id}:evaluation:${evaluation.id}`\n\t\t\t\t: `alert:${rule.id}:rule`,\n\t\t\tentityKind: \"alert\",\n\t\t\tentityId: rule.id,\n\t\t\troute,\n\t\t\tsource: evaluation\n\t\t\t\t? \"alert_evaluations\"\n\t\t\t\t: \"alerts.rule_evaluation_preview\",\n\t\t\tconfidence: evaluation ? 1 : 0.8,\n\t\t\treason: evaluation\n\t\t\t\t? `Alert \"${rule.name}\" evaluated to ${evaluation.value} and state ${evaluation.state}.`\n\t\t\t\t: `Alert \"${rule.name}\" was evaluated against its configured threshold.`,\n\t\t\tcitations: [\n\t\t\t\t{\n\t\t\t\t\tlabel: rule.name,\n\t\t\t\t\tentityKind: \"alert\",\n\t\t\t\t\tentityId: rule.id,\n\t\t\t\t\troute,\n\t\t\t\t},\n\t\t\t],\n\t\t\tsuggestedNextPivots: [\n\t\t\t\t{\n\t\t\t\t\tlabel: \"Open alert\",\n\t\t\t\t\tentityKind: \"alert\",\n\t\t\t\t\tentityId: rule.id,\n\t\t\t\t\troute,\n\t\t\t\t\treason: \"Inspect the alert rule, threshold, and recent evaluations.\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n\n\tif (rule.analysisId) {\n\t\tconst analysisRouteValue = analysisRoute(rule.analysisId);\n\t\treferences.push({\n\t\t\tevidenceId: evaluation\n\t\t\t\t? `alert:${rule.id}:evaluation:${evaluation.id}:analysis:${rule.analysisId}`\n\t\t\t\t: `alert:${rule.id}:analysis:${rule.analysisId}`,\n\t\t\tentityKind: \"analysis\",\n\t\t\tentityId: rule.analysisId,\n\t\t\troute: analysisRouteValue,\n\t\t\tsource: \"alert_rules.analysis_id\",\n\t\t\tconfidence: 0.9,\n\t\t\treason: `Alert \"${rule.name}\" is bound to analysis \"${rule.analysisId}\".`,\n\t\t\tcitations: [\n\t\t\t\t{\n\t\t\t\t\tlabel: rule.name,\n\t\t\t\t\tentityKind: \"alert\",\n\t\t\t\t\tentityId: rule.id,\n\t\t\t\t\troute,\n\t\t\t\t},\n\t\t\t],\n\t\t\tsuggestedNextPivots: [\n\t\t\t\t{\n\t\t\t\t\tlabel: \"Open investigation\",\n\t\t\t\t\tentityKind: \"analysis\",\n\t\t\t\t\tentityId: rule.analysisId,\n\t\t\t\t\troute: analysisRouteValue,\n\t\t\t\t\treason: \"Review the analysis result that drives this alert.\",\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n\n\treturn references;\n};\n\nexport const aiEvaluationEvidenceReferences = (\n\tevaluation: Pick<\n\t\tAIEvaluationRecord,\n\t\t\"evaluationId\" | \"traceId\" | \"spanId\" | \"name\" | \"source\"\n\t>,\n): EvidenceReference[] => {\n\tconst spanEntityId = `${evaluation.traceId}:${evaluation.spanId}`;\n\tconst spanRouteValue = evidenceRouteFor(\n\t\t\"span\",\n\t\tspanEntityId,\n\t\tevaluation.traceId,\n\t);\n\treturn [\n\t\t{\n\t\t\tevidenceId: `ai-evaluation:${evaluation.evaluationId}`,\n\t\t\tentityKind: \"eval\",\n\t\t\tentityId: evaluation.evaluationId,\n\t\t\troute: evidenceRouteFor(\"eval\", evaluation.evaluationId),\n\t\t\tsource: `ai_span_evaluations.${evaluation.source}`,\n\t\t\tconfidence: 0.95,\n\t\t\treason: `AI evaluation \"${evaluation.name}\" graded span \"${evaluation.spanId}\".`,\n\t\t\tcitations: [\n\t\t\t\t{\n\t\t\t\t\tlabel: `span ${evaluation.spanId}`,\n\t\t\t\t\tentityKind: \"span\",\n\t\t\t\t\tentityId: spanEntityId,\n\t\t\t\t\troute: spanRouteValue,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: `trace ${evaluation.traceId}`,\n\t\t\t\t\tentityKind: \"trace\",\n\t\t\t\t\tentityId: evaluation.traceId,\n\t\t\t\t\troute: evidenceRouteFor(\"trace\", evaluation.traceId),\n\t\t\t\t},\n\t\t\t],\n\t\t\tsuggestedNextPivots: [\n\t\t\t\t{\n\t\t\t\t\tlabel: \"Open span\",\n\t\t\t\t\tentityKind: \"span\",\n\t\t\t\t\tentityId: spanEntityId,\n\t\t\t\t\troute: spanRouteValue,\n\t\t\t\t\treason: \"Inspect the evaluated AI span and its surrounding trace.\",\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t];\n};\n\nexport interface SourceEvidenceLinks {\n\tsourceAgentRunId?: string | null;\n\tsourceActionId?: string | null;\n\tsourceToolCallId?: string | null;\n\tsourceTraceId?: string | null;\n\tsourceSpanId?: string | null;\n}\n\nexport const sourceLinkEvidenceReferences = (\n\tsource: {\n\t\tsourceLabel: string;\n\t\tsourceId: string;\n\t\tsourceKind: \"eval_case\" | \"eval_case_result\" | \"eval_run\";\n\t\tsourceRoute?: string | null;\n\t\tsourceName?: string | null;\n\t},\n\tlinks: SourceEvidenceLinks,\n): EvidenceReference[] => {\n\tconst citations: EvidenceCitation[] = [];\n\tif (source.sourceRoute) {\n\t\tcitations.push({\n\t\t\tlabel: source.sourceName ?? source.sourceId,\n\t\t\tentityKind: \"eval\",\n\t\t\tentityId: source.sourceId,\n\t\t\troute: source.sourceRoute,\n\t\t});\n\t}\n\n\tconst candidates: Array<{\n\t\tkind: EvidenceEntityKind;\n\t\tid: string | null | undefined;\n\t\tlabel: string;\n\t\tconfidence: number;\n\t}> = [\n\t\t{\n\t\t\tkind: \"action\",\n\t\t\tid: links.sourceActionId,\n\t\t\tlabel: \"source action\",\n\t\t\tconfidence: 0.92,\n\t\t},\n\t\t{\n\t\t\tkind: \"tool_call\",\n\t\t\tid: links.sourceToolCallId,\n\t\t\tlabel: \"source tool call\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tkind: \"agent_run\",\n\t\t\tid: links.sourceAgentRunId,\n\t\t\tlabel: \"source agent run\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tkind: \"span\",\n\t\t\tid:\n\t\t\t\tlinks.sourceTraceId && links.sourceSpanId\n\t\t\t\t\t? `${links.sourceTraceId}:${links.sourceSpanId}`\n\t\t\t\t\t: null,\n\t\t\tlabel: \"source span\",\n\t\t\tconfidence: 0.9,\n\t\t},\n\t\t{\n\t\t\tkind: \"trace\",\n\t\t\tid: links.sourceTraceId,\n\t\t\tlabel: \"source trace\",\n\t\t\tconfidence: 0.88,\n\t\t},\n\t];\n\n\treturn candidates\n\t\t.filter((candidate): candidate is typeof candidate & { id: string } =>\n\t\t\tBoolean(candidate.id),\n\t\t)\n\t\t.map((candidate) => {\n\t\t\tconst route = evidenceRouteFor(\n\t\t\t\tcandidate.kind,\n\t\t\t\tcandidate.id,\n\t\t\t\tlinks.sourceTraceId,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tevidenceId: `${source.sourceKind}:${source.sourceId}:${candidate.kind}:${candidate.id}`,\n\t\t\t\tentityKind: candidate.kind,\n\t\t\t\tentityId: candidate.id,\n\t\t\t\troute,\n\t\t\t\tsource: `${source.sourceKind}.source_links`,\n\t\t\t\tconfidence: candidate.confidence,\n\t\t\t\treason: `${source.sourceLabel} links to ${candidate.label} \"${candidate.id}\".`,\n\t\t\t\tcitations,\n\t\t\t\tsuggestedNextPivots: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: `Open ${candidate.label}`,\n\t\t\t\t\t\tentityKind: candidate.kind,\n\t\t\t\t\t\tentityId: candidate.id,\n\t\t\t\t\t\troute,\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\"Inspect the production evidence behind this evaluation item.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t} satisfies EvidenceReference;\n\t\t});\n};\n\nexport const analysisResultEvidenceReferences = (\n\tresult: Pick<AnalysisResult, \"analysisId\" | \"payload\">,\n): EvidenceReference[] => {\n\tconst references: EvidenceReference[] = [\n\t\t...instrumentationGapEvidenceReferences(result),\n\t];\n\tfor (const { sectionName, table } of parseEvidenceTables(result.payload)) {\n\t\tconst headers = table.headers.map(normalizeHeader);\n\t\tfor (const [rowIndex, row] of table.rows.entries()) {\n\t\t\tif (references.length >= MAX_ANALYSIS_EVIDENCE_REFERENCES) {\n\t\t\t\treturn references;\n\t\t\t}\n\t\t\tconst entity = entityFromRow(row, headers);\n\t\t\tif (!entity) continue;\n\n\t\t\tconst title = table.title ?? sectionName;\n\t\t\treferences.push({\n\t\t\t\tevidenceId: `analysis:${result.analysisId}:${sectionName}:${rowIndex}:${entity.entityKind}:${entity.entityId}`,\n\t\t\t\tentityKind: entity.entityKind,\n\t\t\t\tentityId: entity.entityId,\n\t\t\t\troute: entity.route,\n\t\t\t\tsource: `analysis.payload.evidence.${sectionName}`,\n\t\t\t\tconfidence: entity.confidence,\n\t\t\t\treason: `Analysis \"${result.analysisId}\" cited ${entity.label} in \"${title}\" row ${rowIndex + 1}.`,\n\t\t\t\tcitations: entity.citations,\n\t\t\t\tsuggestedNextPivots: entity.suggestedNextPivots,\n\t\t\t});\n\t\t}\n\t}\n\treturn references;\n};\n","/**\n * RFC 0002 Stage 3 — narrative LLM adapter.\n *\n * Single-provider for v1 (Anthropic). The shape is \"stuff in a system\n * prompt that bakes the rendering rules, ask for one declarative\n * sentence, return text\" — a different provider plugs in here without\n * changing callers.\n *\n * Rendering rules from the RFC's UX section, enforced at the system\n * prompt layer so the model can't accidentally drift:\n *\n * 1. Never start with \"I\" or \"Here's\" — declarative, not chatbot.\n * 2. Always cite — if the prompt mentions \"the trace\", a trace_id\n * must follow inline.\n * 3. Include a time anchor (\"starting 8 min ago\", \"since 14:32\").\n * 4. ≤2 sentences. We're labelling tiles, not writing essays.\n */\n\nimport type { AnalysisDefinition, AnalysisResult } from \"@obsunified/types\";\nimport type { ChildSpanRunner } from \"../framework/logger\";\n\nexport interface NarrativeRequest {\n\tdefinition: AnalysisDefinition;\n\tcurrent: AnalysisResult;\n\tprevious: AnalysisResult | null;\n}\n\n/**\n * Provider discriminator. The collector picks one based on which API key\n * env var is set (OpenAI takes precedence when both are set, since users\n * who configure both presumably did so deliberately for OpenAI).\n *\n * anthropic → POST https://api.anthropic.com/v1/messages\n * openai → POST https://api.openai.com/v1/chat/completions\n * (apiUrl override lets you point at openrouter, vLLM,\n * azure-openai-compat, ollama, etc.)\n */\nexport type LlmProvider = \"anthropic\" | \"openai\";\n\nexport interface LlmConfig {\n\tprovider: LlmProvider;\n\tapiKey: string;\n\t/** Model id. Provider-specific. e.g. \"claude-haiku-4-5\" / \"gpt-4o-mini\". */\n\tmodel: string;\n\t/** Override base URL — Anthropic-compatible or OpenAI-compatible. */\n\tapiUrl?: string;\n\t/** Optional abort signal used to cap provider calls from schedulers. */\n\tsignal?: AbortSignal;\n\t/**\n\t * Optional child-span runner. When set, every LLM API call (and tool\n\t * dispatch in the agent loop) is wrapped in an OpenInference-shaped span\n\t * with `gen_ai.system`, `gen_ai.request.model`, and post-call usage\n\t * attributes. Wired by the worker entrypoint via `runtime.withChildSpan`.\n\t */\n\ttracer?: ChildSpanRunner;\n}\n\nconst DEFAULT_API_URL = \"https://api.anthropic.com/v1/messages\";\n\nconst SYSTEM_PROMPT = `You write one-sentence operational narratives for a self-hosted observability dashboard.\n\nHard rules — violations are unusable:\n1. Never start with \"I\", \"Here's\", \"We\", \"It looks\", or any first-person/chatbot framing. Write declarative statements about the system.\n2. If you reference a trace, span, log, or service, include the supplied identifier inline (e.g. \"trace abc12345\").\n3. Include a time anchor: \"starting Nm ago\", \"for the last Nm\", \"since HH:MM\" — pull from the inputs.\n4. ≤ 2 sentences total, ≤ 220 characters. Numbers belong in the sentence, not in a separate label.\n5. If the inputs are insufficient to write a useful sentence, output exactly the string NO_NARRATIVE (no quotes).\n\nTone: like a senior on-call writing a Slack message. Specific, blunt, no hedging, no advice (\"you should...\"), no questions.`;\n\nconst renderTemplate = (\n\ttemplate: string,\n\tdef: AnalysisDefinition,\n\tr: AnalysisResult,\n): string => {\n\tconst scope = (def.scope ?? {}) as Record<string, unknown>;\n\tconst traceIds = Array.isArray(r.payload?.trace_ids)\n\t\t? (r.payload.trace_ids as unknown[])\n\t\t\t\t.filter((x): x is string => typeof x === \"string\")\n\t\t\t\t.slice(0, 5)\n\t\t\t\t.join(\", \")\n\t\t: \"\";\n\tconst subs: Record<string, string> = {\n\t\ttitle: def.title,\n\t\tstatus: r.status,\n\t\tprimary: r.primaryValue === null ? \"n/a\" : String(r.primaryValue),\n\t\tbaseline: r.baselineValue === null ? \"n/a\" : String(r.baselineValue),\n\t\tdelta_pct: r.deltaPct === null ? \"n/a\" : `${r.deltaPct.toFixed(1)}%`,\n\t\tservice: typeof scope.service === \"string\" ? scope.service : \"\",\n\t\ttrace_ids: traceIds,\n\t};\n\treturn template.replace(/\\{\\{(\\w+)\\}\\}/g, (_, k) => subs[k] ?? \"\");\n};\n\nconst buildUserPrompt = ({\n\tdefinition,\n\tcurrent,\n\tprevious,\n}: NarrativeRequest): string => {\n\tconst lines: string[] = [];\n\tconst tmplRendered = renderTemplate(\n\t\tdefinition.narrate?.prompt ?? \"\",\n\t\tdefinition,\n\t\tcurrent,\n\t).trim();\n\tif (tmplRendered) lines.push(tmplRendered);\n\n\tlines.push(\"\");\n\tlines.push(\"Current state:\");\n\tlines.push(`- panel: ${definition.title}`);\n\tlines.push(`- status: ${current.status}`);\n\tif (current.primaryValue !== null)\n\t\tlines.push(`- primary: ${current.primaryValue}`);\n\tif (current.baselineValue !== null)\n\t\tlines.push(`- baseline (1h): ${current.baselineValue}`);\n\tif (current.deltaPct !== null)\n\t\tlines.push(`- delta vs baseline: ${current.deltaPct.toFixed(1)}%`);\n\n\tconst since = previous\n\t\t? Math.max(\n\t\t\t\t1,\n\t\t\t\tMath.round(\n\t\t\t\t\t(new Date(current.generatedAt).getTime() -\n\t\t\t\t\t\tnew Date(previous.generatedAt).getTime()) /\n\t\t\t\t\t\t60000,\n\t\t\t\t),\n\t\t\t)\n\t\t: null;\n\tif (since !== null) {\n\t\tlines.push(\n\t\t\t`- previous run was ${since} minute${since === 1 ? \"\" : \"s\"} ago, status=${previous?.status ?? \"n/a\"}`,\n\t\t);\n\t}\n\n\tconst payloadKeys = Object.keys(current.payload ?? {}).filter(\n\t\t(k) => k !== \"sparkline\",\n\t);\n\tif (payloadKeys.length > 0) {\n\t\tlines.push(\"\");\n\t\tlines.push(\"Payload details:\");\n\t\tfor (const k of payloadKeys) {\n\t\t\tconst v = current.payload[k];\n\t\t\tconst rendered =\n\t\t\t\ttypeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\"\n\t\t\t\t\t? String(v)\n\t\t\t\t\t: JSON.stringify(v);\n\t\t\tif (rendered.length <= 200) lines.push(`- ${k}: ${rendered}`);\n\t\t}\n\t}\n\n\tlines.push(\"\");\n\tlines.push(\n\t\t\"Output: a single sentence (max two), no preamble, no quotes, no Markdown.\",\n\t);\n\treturn lines.join(\"\\n\");\n};\n\nexport class LlmCallError extends Error {\n\treadonly status: number | null;\n\tconstructor(message: string, status: number | null = null) {\n\t\tsuper(message);\n\t\tthis.name = \"LlmCallError\";\n\t\tthis.status = status;\n\t}\n}\n\n/**\n * Provider dispatcher for narrative generation.\n *\n * Returns `null` when:\n * - the model returns the sentinel NO_NARRATIVE\n * - the response is empty\n * Throws `LlmCallError` on non-2xx HTTP responses so the runner can\n * count the failure against the budget without writing a bogus narrative.\n */\nexport async function generateNarrative(\n\treq: NarrativeRequest,\n\tconfig: LlmConfig,\n): Promise<string | null> {\n\tif (config.provider === \"openai\") {\n\t\t// Lazy import to keep the Anthropic-only path zero-cost on the worker\n\t\t// boot and avoid a circular import between llm.ts and openai.ts.\n\t\tconst { generateNarrativeOpenAI } = await import(\"./openai\");\n\t\treturn generateNarrativeOpenAI(req, config);\n\t}\n\treturn generateNarrativeAnthropic(req, config);\n}\n\nasync function generateNarrativeAnthropic(\n\treq: NarrativeRequest,\n\tconfig: LlmConfig,\n): Promise<string | null> {\n\tconst url = config.apiUrl ?? DEFAULT_API_URL;\n\tconst userPrompt = buildUserPrompt(req);\n\n\tconst tracer = config.tracer;\n\tconst callLLM = async (\n\t\tspan: { setAttribute(k: string, v: unknown): void } | null,\n\t): Promise<string | null> => {\n\t\tconst response = await fetch(url, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"x-api-key\": config.apiKey,\n\t\t\t\t\"anthropic-version\": \"2023-06-01\",\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tmodel: config.model,\n\t\t\t\tmax_tokens: 200,\n\t\t\t\tsystem: SYSTEM_PROMPT,\n\t\t\t\tmessages: [{ role: \"user\", content: userPrompt }],\n\t\t\t}),\n\t\t\tsignal: config.signal,\n\t\t});\n\t\tif (span) {\n\t\t\tspan.setAttribute(\"http.response.status_code\", response.status);\n\t\t}\n\n\t\tif (!response.ok) {\n\t\t\tconst text = await response.text().catch(() => \"\");\n\t\t\tthrow new LlmCallError(\n\t\t\t\t`anthropic ${response.status}: ${text.slice(0, 200)}`,\n\t\t\t\tresponse.status,\n\t\t\t);\n\t\t}\n\n\t\tconst body = (await response.json()) as {\n\t\t\tcontent?: Array<{ type?: string; text?: string }>;\n\t\t\tusage?: { input_tokens?: number; output_tokens?: number };\n\t\t\tstop_reason?: string;\n\t\t};\n\t\tif (body.stop_reason === \"max_tokens\") {\n\t\t\tthrow new LlmCallError(\"anthropic response truncated by max_tokens\");\n\t\t}\n\t\tif (span && body.usage) {\n\t\t\tif (typeof body.usage.input_tokens === \"number\")\n\t\t\t\tspan.setAttribute(\"gen_ai.usage.input_tokens\", body.usage.input_tokens);\n\t\t\tif (typeof body.usage.output_tokens === \"number\")\n\t\t\t\tspan.setAttribute(\n\t\t\t\t\t\"gen_ai.usage.output_tokens\",\n\t\t\t\t\tbody.usage.output_tokens,\n\t\t\t\t);\n\t\t}\n\t\tconst text = (body.content ?? [])\n\t\t\t.filter((block) => block?.type === \"text\")\n\t\t\t.map((block) => block?.text ?? \"\")\n\t\t\t.join(\"\")\n\t\t\t.trim();\n\n\t\tif (!text || text === \"NO_NARRATIVE\") return null;\n\t\t// Strip any accidental wrapping quotes the model might add despite the\n\t\t// system prompt.\n\t\treturn text.replace(/^[\"']|[\"']$/g, \"\").trim();\n\t};\n\n\tif (!tracer) return callLLM(null);\n\treturn tracer(\"llm.anthropic.messages\", async (span) => callLLM(span), {\n\t\t\"openinference.span.kind\": \"LLM\",\n\t\t\"gen_ai.system\": \"anthropic\",\n\t\t\"gen_ai.request.model\": config.model,\n\t\t\"gen_ai.request.max_tokens\": 200,\n\t});\n}\n"],"mappings":";AAaA,IAAM,gBAA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