[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
95
application/state/useAgentCompactionUi.ts
Normal file
95
application/state/useAgentCompactionUi.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { ContextPrepareTrigger } from '../../infrastructure/ai/harness/types';
|
||||
import { getAgentRuntime } from '../../infrastructure/ai/harness/globalAgentRuntime';
|
||||
import { CATTY_COMPACTION_STATUS_KEYS } from '../../infrastructure/ai/harness/compactionStatusKeys';
|
||||
|
||||
export interface ActiveCompactionUi {
|
||||
sessionId: string;
|
||||
trigger: ContextPrepareTrigger;
|
||||
}
|
||||
|
||||
export interface AgentContextUsage {
|
||||
sessionId: string;
|
||||
inputTokens: number;
|
||||
contextWindow: number;
|
||||
estimated: boolean;
|
||||
}
|
||||
|
||||
function statusKeyForTrigger(trigger: ContextPrepareTrigger): string {
|
||||
switch (trigger) {
|
||||
case 'step':
|
||||
return CATTY_COMPACTION_STATUS_KEYS.step;
|
||||
case '413-retry':
|
||||
return CATTY_COMPACTION_STATUS_KEYS.retry;
|
||||
default:
|
||||
return CATTY_COMPACTION_STATUS_KEYS.preTurn;
|
||||
}
|
||||
}
|
||||
|
||||
export function useAgentCompactionUi(): ActiveCompactionUi | null {
|
||||
const [active, setActive] = useState<ActiveCompactionUi | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = getAgentRuntime().subscribe((event) => {
|
||||
const sessionId = event.chatSessionId ?? event.sessionId;
|
||||
if (event.type === 'compaction_start') {
|
||||
setActive({ sessionId, trigger: event.trigger });
|
||||
return;
|
||||
}
|
||||
if (event.type === 'compaction' || event.type === 'turn_end') {
|
||||
setActive((prev) => (prev?.sessionId === sessionId ? null : prev));
|
||||
}
|
||||
});
|
||||
return unsubscribe;
|
||||
}, []);
|
||||
|
||||
return active;
|
||||
}
|
||||
|
||||
export function compactionStatusText(
|
||||
trigger: ContextPrepareTrigger,
|
||||
translate: (key: string, params?: Record<string, string | number>) => string,
|
||||
): string {
|
||||
return translate(statusKeyForTrigger(trigger));
|
||||
}
|
||||
|
||||
export function resolveCompactionStatusText(
|
||||
statusText: string | undefined,
|
||||
translate: (key: string) => string,
|
||||
): string | undefined {
|
||||
if (!statusText) return undefined;
|
||||
if (statusText.startsWith('ai.')) return translate(statusText);
|
||||
return statusText;
|
||||
}
|
||||
|
||||
export function useAgentContextUsage(sessionId: string | null | undefined): AgentContextUsage | null {
|
||||
const [usage, setUsage] = useState<AgentContextUsage | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!sessionId) {
|
||||
setUsage(null);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const unsubscribe = getAgentRuntime().subscribe((event) => {
|
||||
const eventSessionId = event.chatSessionId ?? event.sessionId;
|
||||
if (eventSessionId !== sessionId || event.type !== 'context_snapshot') return;
|
||||
const snapshot = event.snapshot;
|
||||
if (
|
||||
typeof snapshot.contextWindow !== 'number'
|
||||
|| typeof snapshot.estimatedInputTokens !== 'number'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setUsage({
|
||||
sessionId,
|
||||
inputTokens: Math.max(0, snapshot.estimatedInputTokens),
|
||||
contextWindow: Math.max(1, snapshot.contextWindow),
|
||||
estimated: true,
|
||||
});
|
||||
});
|
||||
return unsubscribe;
|
||||
}, [sessionId]);
|
||||
|
||||
return usage?.sessionId === sessionId ? usage : null;
|
||||
}
|
||||
Reference in New Issue
Block a user