feat(gateway): expose context usage and warning events

This commit is contained in:
William Valentin
2026-02-16 15:44:09 -08:00
parent 8758ea8f1c
commit fee8be1de0
11 changed files with 645 additions and 334 deletions
+31
View File
@@ -411,6 +411,37 @@ export function createGateway(deps: GatewayDeps): GatewayServer {
}
}
return results;
},
getContextUsage: () => {
const results: Array<{
sessionId: string;
budget: {
estimatedTokens: number;
contextWindow: number;
remainingTokens: number;
usagePct: number;
thresholdPct: number;
thresholdTokens: number;
shouldCompact: boolean;
};
}> = [];
const sessionBridge = gateway.getSessionBridge();
for (const entry of sessionBridge.getAllContextUsage()) {
results.push(entry);
}
const channelAgents = getChannelAgents();
if (channelAgents) {
for (const [sessionId, { orchestrator }] of channelAgents) {
results.push({
sessionId,
budget: orchestrator.getContextBudget(),
});
}
}
return results;
},
});