feat(gateway): expose context usage and warning events
This commit is contained in:
@@ -200,6 +200,47 @@ export class SessionBridge {
|
||||
return results;
|
||||
}
|
||||
|
||||
/** Get estimated context budget for all active sessions. */
|
||||
getAllContextUsage(): Array<{
|
||||
sessionId: string;
|
||||
budget: {
|
||||
estimatedTokens: number;
|
||||
contextWindow: number;
|
||||
remainingTokens: number;
|
||||
usagePct: number;
|
||||
thresholdPct: number;
|
||||
thresholdTokens: number;
|
||||
shouldCompact: boolean;
|
||||
};
|
||||
}> {
|
||||
const results: Array<{
|
||||
sessionId: string;
|
||||
budget: {
|
||||
estimatedTokens: number;
|
||||
contextWindow: number;
|
||||
remainingTokens: number;
|
||||
usagePct: number;
|
||||
thresholdPct: number;
|
||||
thresholdTokens: number;
|
||||
shouldCompact: boolean;
|
||||
};
|
||||
}> = [];
|
||||
|
||||
const seen = new Set<string>();
|
||||
for (const client of this.clients.values()) {
|
||||
if (seen.has(client.sessionId)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(client.sessionId);
|
||||
results.push({
|
||||
sessionId: client.sessionId,
|
||||
budget: client.agent.getContextBudget(),
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private getOrCreateAgent(sessionId: string): AgentOrchestrator {
|
||||
let agent = this.agents.get(sessionId);
|
||||
if (!agent) {
|
||||
@@ -233,6 +274,14 @@ export class SessionBridge {
|
||||
keepTurns: config.compaction.keep_turns,
|
||||
summaryMaxTokens: config.compaction.summary_max_tokens,
|
||||
importanceThreshold: config.compaction.importance_threshold,
|
||||
proactive: {
|
||||
enabled: config.compaction.proactive.enabled,
|
||||
warnPct: config.compaction.proactive.warn_pct,
|
||||
checkpointPct: config.compaction.proactive.checkpoint_pct,
|
||||
autoCompactPct: config.compaction.proactive.auto_compact_pct,
|
||||
checkpointCooldownMs: config.compaction.proactive.checkpoint_cooldown_ms,
|
||||
memoryNamespace: config.compaction.proactive.memory_namespace,
|
||||
},
|
||||
} : undefined,
|
||||
modelName: config?.models.default.model,
|
||||
contextWindow: config?.models.default.context_window,
|
||||
|
||||
Reference in New Issue
Block a user