feat(gateway): expose context usage and warning events
This commit is contained in:
@@ -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;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user