|
3 | 3 | * Determine agent state using SSE connection presence as the primary signal. |
4 | 4 | * |
5 | 5 | * States (priority order): |
6 | | - * Listening — SSE connected + last_activity is msg_wait (green ⏳) |
7 | | - * Working — SSE connected + NOT in msg_wait (amber ⚡) |
8 | | - * Offline — no SSE + heartbeat expired (dark ⚫) |
| 6 | + * Listening — SSE connected + last_activity is msg_wait (⏳) |
| 7 | + * Working — SSE connected + NOT msg_wait + activity within 60s (⚡) |
| 8 | + * Idle — SSE connected + NOT msg_wait + activity older than 60s (🔌) |
| 9 | + * (SSE open but agent stopped responding — may be processing |
| 10 | + * a long task or is a stale connection) |
| 11 | + * Offline — no SSE + heartbeat expired (⚫) |
9 | 12 | * |
10 | 13 | * For stdio agents (no SSE): fall back to heartbeat-based detection. |
11 | 14 | * stdio agents will show Listening when is_online=true, Offline otherwise. |
12 | 15 | */ |
| 16 | + const WORKING_TIMEOUT_S = 60; |
| 17 | + |
13 | 18 | function getAgentState(agent) { |
14 | 19 | if (!agent) return "Offline"; |
15 | 20 |
|
16 | 21 | if (agent.is_sse_connected) { |
17 | 22 | if (agent.last_activity === "msg_wait") return "Listening"; |
| 23 | + // Check how long ago the last activity was |
| 24 | + const lastActivityTime = agent.last_activity_time ? new Date(agent.last_activity_time) : null; |
| 25 | + if (lastActivityTime) { |
| 26 | + const elapsedS = (Date.now() - lastActivityTime.getTime()) / 1000; |
| 27 | + if (elapsedS > WORKING_TIMEOUT_S) return "Idle"; |
| 28 | + } |
18 | 29 | return "Working"; |
19 | 30 | } |
20 | 31 |
|
|
25 | 36 |
|
26 | 37 | /** |
27 | 38 | * Return the state emoji for display in the card. |
28 | | - * ⏳ Listening, ⚡ Working, ⚫ Offline |
| 39 | + * ⏳ Listening, ⚡ Working, 🔌 Idle, ⚫ Offline |
29 | 40 | */ |
30 | 41 | function getStateEmoji(state) { |
31 | | - const map = { Listening: "⏳", Working: "⚡", Offline: "⚫" }; |
| 42 | + const map = { Listening: "⏳", Working: "⚡", Idle: "🔌", Offline: "⚫" }; |
32 | 43 | return map[state] || "⚫"; |
33 | 44 | } |
34 | 45 |
|
|
0 commit comments