Files
agent-ui/server/routes/session-state-proxy.ts
josedario87 25bca2625b feat: centralized PTY-scoped session state, sync engine debug panel, lifecycle states, WS monitor
- Refactor session state to use ptySessionId as primary key across all components
- Add SessionStateManager with PTY-scoped hook processing, approval tracking, notifications
- Add sync-engine debug panel (AgentStatesSection, HookTimelineSection, TerminalRegistrySection, WsMonitorSection)
- Add useLifecycleStates composable for continuous state chips (session, responding, tool, subagent, compacting)
- Add WS monitor endpoint and composable for real-time connection health
- Enhance SessionLifecycleStatus with animated state chips and badge counts
- Enhance SystemMessage with expanded content and better formatting
- Update hooks (approval-permission, approval-plan, notify) with pty_session injection
- Update approval system to derive pending lists from PTY-scoped state
- Update ChatContainer with PTY-derived agent status and lifecycle events
- Update AgentBadge with PTY-scoped status colors
- Improve PiP window, approval window, and loading window handling
2026-02-24 20:10:31 -06:00

35 lines
1.2 KiB
TypeScript

import { jsonResponse, errorResponse } from '../utils/cors'
import { PORT_TERMINAL } from '../config'
/**
* Proxy GET /api/session-state → terminal server.
* Returns session-state + terminal-registry combined,
* so external clients (Android widget) get everything in one call.
*/
export async function handleSessionStateProxy(url: URL): Promise<Response> {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), 6000)
try {
const [stateResp, registryResp] = await Promise.all([
fetch(`http://localhost:${PORT_TERMINAL}/session-state`, { signal: controller.signal }),
fetch(`http://localhost:${PORT_TERMINAL}/terminal-registry`, { signal: controller.signal })
])
const stateData = stateResp.ok ? await stateResp.json() : { ptySessions: {} }
const registryData = registryResp.ok ? await registryResp.json() : { registry: [] }
return jsonResponse({
ptySessions: stateData.ptySessions ?? {},
registry: registryData.registry ?? []
})
} catch (e: any) {
const msg = e.name === 'AbortError'
? 'Terminal server timeout (6s)'
: `Failed to reach terminal server: ${e.message}`
return errorResponse(msg, 502)
} finally {
clearTimeout(timeout)
}
}