@symerian/symi 3.5.0 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-info.json +3 -3
- package/dist/bundled/boot-md/handler.js +4 -4
- package/dist/bundled/session-memory/handler.js +4 -4
- package/dist/canvas-host/a2ui/.bundle.hash +1 -1
- package/dist/{chrome-C_I81hbq.js → chrome-B7-rO4i9.js} +4 -4
- package/dist/{chrome-BKUACyeO.js → chrome-DPjznJQ-.js} +4 -4
- package/dist/control-ui/css/revert-red-theme.md +141 -0
- package/dist/control-ui/css/style.css +5843 -0
- package/dist/control-ui/css/style.css.backup-2026-03-03-162525 +3546 -0
- package/dist/control-ui/css/style.css.backup-before-red-2026-03-03-162525 +3546 -0
- package/dist/control-ui/css/style.css.backup-before-red-theme-2026-03-03-162530 +3546 -0
- package/dist/control-ui/css/style.css.pre-2row +2165 -0
- package/dist/control-ui/css/style.css.pre-brand +1776 -0
- package/dist/control-ui/css/style.css.pre-history +1974 -0
- package/dist/control-ui/css/style.css.pre-nav +2264 -0
- package/dist/control-ui/css/style.css.pre-newsession +1898 -0
- package/dist/control-ui/css/style.css.pre-queue +2195 -0
- package/dist/control-ui/css/style.css.pre-red-prompt +2524 -0
- package/dist/control-ui/css/style.css.pre-stop +2239 -0
- package/dist/control-ui/css/style.css.pre-textarea +2184 -0
- package/dist/control-ui/css/style.css.pre-watchdog +1848 -0
- package/dist/control-ui/css/style.css.red-theme +2999 -0
- package/dist/control-ui/index.html +1049 -0
- package/dist/control-ui/js/app.js +1304 -0
- package/dist/control-ui/js/app.js.pre-2row +463 -0
- package/dist/control-ui/js/app.js.pre-heartbeat-filter +595 -0
- package/dist/control-ui/js/app.js.pre-newsession +408 -0
- package/dist/control-ui/js/app.js.pre-queue +476 -0
- package/dist/control-ui/js/app.js.pre-stop +564 -0
- package/dist/control-ui/js/app.js.pre-textarea +467 -0
- package/dist/control-ui/js/app.js.pre-watchdog +293 -0
- package/dist/control-ui/js/connections.js +438 -0
- package/dist/control-ui/js/gateway.js +233 -0
- package/dist/control-ui/js/gateway.js.pre-stop +110 -0
- package/dist/control-ui/js/history.js +732 -0
- package/dist/control-ui/js/logs.js +238 -0
- package/dist/control-ui/js/menu.js +232 -0
- package/dist/control-ui/js/menu.js.pre-nav +66 -0
- package/dist/control-ui/js/metrics.js +53 -0
- package/dist/control-ui/js/models.js +138 -0
- package/dist/control-ui/js/render.js +882 -0
- package/dist/control-ui/js/render.test.js +112 -0
- package/dist/control-ui/js/scheduling.js +461 -0
- package/dist/control-ui/js/settings.js +910 -0
- package/dist/control-ui/js/slash-autocomplete.js +168 -0
- package/dist/control-ui/js/subagents.js +560 -0
- package/dist/control-ui/js/utils.js +29 -0
- package/dist/control-ui/vendor/highlight.min.js +2518 -0
- package/dist/control-ui/vendor/marked.min.js +69 -0
- package/dist/{deliver-DyO3QD8O.js → deliver-DTRkeYm3.js} +4 -4
- package/dist/{deliver-Cjyb6h4g.js → deliver-oWGJwzFf.js} +4 -4
- package/dist/extensionAPI.js +4 -4
- package/dist/llm-slug-generator.js +4 -4
- package/dist/{manager-rvtFoeFT.js → manager-CFenq_aO.js} +1 -1
- package/dist/{manager-PTSjHNVq.js → manager-CsxTf96V.js} +1 -1
- package/dist/{pi-embedded-BPuUM-gD.js → pi-embedded-Cdub5Vs9.js} +10 -10
- package/dist/{pw-ai-BFS9ezWe.js → pw-ai-BOOB8qoi.js} +1 -1
- package/dist/{pw-ai-Cx-Ko_FL.js → pw-ai-D2pEVS5n.js} +1 -1
- package/dist/{synthesis-7UL3pCpj.js → synthesis-Be9nYyDd.js} +4 -4
- package/dist/{synthesis-fD8J2vag.js → synthesis-CBIT6Vnk.js} +4 -4
- package/dist/{unified-runner-BIiKFnNF.js → unified-runner-BVvvnjXW.js} +10 -10
- package/package.json +3 -3
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
// ── Symi UI — Live Gateway App ────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
const responseArea = document.getElementById('response-area');
|
|
4
|
+
const promptInput = document.getElementById('prompt-input');
|
|
5
|
+
const sendBtn = document.getElementById('send-btn');
|
|
6
|
+
const newSessionBtn = document.getElementById('new-session-btn');
|
|
7
|
+
const stopBtn = document.getElementById('stop-btn');
|
|
8
|
+
|
|
9
|
+
let isStreaming = false;
|
|
10
|
+
let currentRunId = null;
|
|
11
|
+
let streamBubble = null;
|
|
12
|
+
let streamContent = null;
|
|
13
|
+
let streamStart = 0;
|
|
14
|
+
|
|
15
|
+
// ── Prompt queue ──────────────────────────────────────────────────
|
|
16
|
+
let chatQueue = []; // [{id, text}]
|
|
17
|
+
|
|
18
|
+
// ── Watchdog + elapsed timer state ────────────────────────────────
|
|
19
|
+
let watchdogTimer = null; // fires if no activity for WATCHDOG_MS
|
|
20
|
+
let elapsedTimer = null; // ticks every second to show run duration
|
|
21
|
+
let activityStart = 0; // timestamp of when current run began
|
|
22
|
+
let elapsedBaseText = ''; // base sub-text for the elapsed display
|
|
23
|
+
const WATCHDOG_MS = 90000; // 90 seconds of silence → failure
|
|
24
|
+
|
|
25
|
+
// ── Utility ───────────────────────────────────────────────────────
|
|
26
|
+
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
27
|
+
function escapeHtml(t) {
|
|
28
|
+
return t.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ── Status indicator (top-right of response area) ─────────────────
|
|
32
|
+
const statusEl = document.createElement('div');
|
|
33
|
+
statusEl.className = 'conn-status';
|
|
34
|
+
statusEl.innerHTML = '<span class="conn-dot dot-yellow pulse"></span><span class="conn-label">connecting…</span>';
|
|
35
|
+
responseArea.before(statusEl);
|
|
36
|
+
|
|
37
|
+
function setStatus(state) { // 'connecting' | 'online' | 'offline'
|
|
38
|
+
const dot = statusEl.querySelector('.conn-dot');
|
|
39
|
+
const label = statusEl.querySelector('.conn-label');
|
|
40
|
+
dot.className = `conn-dot ${state === 'online' ? 'dot-green pulse' : state === 'offline' ? 'dot-red' : 'dot-yellow pulse'}`;
|
|
41
|
+
label.textContent = state === 'online' ? 'live' : state === 'offline' ? 'disconnected' : 'connecting…';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── Render helpers ─────────────────────────────────────────────────
|
|
45
|
+
function addUserMessage(text) {
|
|
46
|
+
const msg = document.createElement('div');
|
|
47
|
+
msg.className = 'message user-msg';
|
|
48
|
+
msg.innerHTML = `<div class="bubble">${escapeHtml(text)}</div><div class="message-clearfix"></div>`;
|
|
49
|
+
responseArea.appendChild(msg);
|
|
50
|
+
msg.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ── Thinking bubble ────────────────────────────────────────────────
|
|
54
|
+
function createThinkingBubble() {
|
|
55
|
+
const msg = document.createElement('div');
|
|
56
|
+
msg.className = 'message symi-msg thinking-msg';
|
|
57
|
+
msg.innerHTML = `
|
|
58
|
+
<div class="bubble thinking-bubble">
|
|
59
|
+
<div class="think-header">
|
|
60
|
+
<span class="think-badge">◈ PROCESSING</span>
|
|
61
|
+
<span class="think-dots"><span>.</span><span>.</span><span>.</span></span>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="think-bar-wrap"><div class="think-bar"></div></div>
|
|
64
|
+
</div>
|
|
65
|
+
<div class="message-clearfix"></div>
|
|
66
|
+
`;
|
|
67
|
+
responseArea.appendChild(msg);
|
|
68
|
+
msg.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
69
|
+
return msg;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── Stream bubble lifecycle ────────────────────────────────────────
|
|
73
|
+
function openStreamBubble() {
|
|
74
|
+
streamStart = Date.now();
|
|
75
|
+
const msg = document.createElement('div');
|
|
76
|
+
msg.className = 'message symi-msg stream-msg';
|
|
77
|
+
msg.innerHTML = `<div class="bubble stream-bubble streaming"><div class="bubble-content"></div></div><div class="message-clearfix"></div>`;
|
|
78
|
+
responseArea.appendChild(msg);
|
|
79
|
+
streamBubble = msg.querySelector('.stream-bubble');
|
|
80
|
+
streamContent = msg.querySelector('.bubble-content');
|
|
81
|
+
msg.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
82
|
+
return msg;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function updateStream(text) {
|
|
86
|
+
if (!streamContent) return;
|
|
87
|
+
streamContent.textContent = text;
|
|
88
|
+
responseArea.scrollTop = responseArea.scrollHeight;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function closeStreamBubble(model = 'claude-sonnet-4-6') {
|
|
92
|
+
if (!streamBubble) return;
|
|
93
|
+
streamBubble.classList.remove('streaming');
|
|
94
|
+
streamBubble.classList.add('done');
|
|
95
|
+
|
|
96
|
+
// Apply full markdown rendering to the final text
|
|
97
|
+
const rawText = streamContent?.textContent ?? '';
|
|
98
|
+
if (streamContent && rawText) {
|
|
99
|
+
streamContent.innerHTML = '';
|
|
100
|
+
const textBlock = renderBlock({ type: 'text', text: rawText });
|
|
101
|
+
streamContent.appendChild(textBlock);
|
|
102
|
+
window.applyHighlighting(streamContent);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const elapsed = Date.now() - streamStart;
|
|
106
|
+
const chars = Math.round(rawText.length / 4);
|
|
107
|
+
|
|
108
|
+
// Add copy button
|
|
109
|
+
const copyBtn = document.createElement('button');
|
|
110
|
+
copyBtn.className = 'msg-copy-btn msg-copy-visible';
|
|
111
|
+
copyBtn.title = 'Copy';
|
|
112
|
+
copyBtn.onclick = function() { window.copyMessage(this); };
|
|
113
|
+
copyBtn.innerHTML = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none">
|
|
114
|
+
<rect x="9" y="9" width="13" height="13" rx="2" stroke="currentColor" stroke-width="2"/>
|
|
115
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" stroke="currentColor" stroke-width="2"/>
|
|
116
|
+
</svg>`;
|
|
117
|
+
streamBubble.appendChild(copyBtn);
|
|
118
|
+
|
|
119
|
+
const footer = document.createElement('div');
|
|
120
|
+
footer.className = 'telemetry';
|
|
121
|
+
footer.innerHTML = `
|
|
122
|
+
<span class="tele-item">✦ ${model}</span>
|
|
123
|
+
<span class="tele-sep">·</span>
|
|
124
|
+
<span class="tele-item">${chars} tokens</span>
|
|
125
|
+
<span class="tele-sep">·</span>
|
|
126
|
+
<span class="tele-item">${elapsed}ms</span>
|
|
127
|
+
`;
|
|
128
|
+
streamBubble.appendChild(footer);
|
|
129
|
+
requestAnimationFrame(() => {
|
|
130
|
+
footer.classList.add('tele-visible');
|
|
131
|
+
// Scroll to bottom immediately after markdown + footer are in the DOM
|
|
132
|
+
responseArea.scrollTop = responseArea.scrollHeight;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Second scroll after the fit-content width transition finishes (0.3s)
|
|
136
|
+
setTimeout(() => { responseArea.scrollTop = responseArea.scrollHeight; }, 350);
|
|
137
|
+
|
|
138
|
+
streamBubble = null;
|
|
139
|
+
streamContent = null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ── Elapsed timer ─────────────────────────────────────────────────
|
|
143
|
+
function startElapsedTimer(baseText) {
|
|
144
|
+
stopElapsedTimer();
|
|
145
|
+
activityStart = Date.now();
|
|
146
|
+
elapsedBaseText = baseText;
|
|
147
|
+
elapsedTimer = setInterval(() => {
|
|
148
|
+
const secs = Math.floor((Date.now() - activityStart) / 1000);
|
|
149
|
+
const m = Math.floor(secs / 60);
|
|
150
|
+
const s = String(secs % 60).padStart(2, '0');
|
|
151
|
+
if (asoSub) asoSub.textContent = `${elapsedBaseText} ${m}:${s}`;
|
|
152
|
+
}, 1000);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function stopElapsedTimer() {
|
|
156
|
+
if (elapsedTimer) { clearInterval(elapsedTimer); elapsedTimer = null; }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ── Watchdog ───────────────────────────────────────────────────────
|
|
160
|
+
function armWatchdog() {
|
|
161
|
+
clearWatchdog();
|
|
162
|
+
watchdogTimer = setTimeout(() => handleRunFailure('timeout'), WATCHDOG_MS);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function clearWatchdog() {
|
|
166
|
+
if (watchdogTimer) { clearTimeout(watchdogTimer); watchdogTimer = null; }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ── Unified run failure handler ────────────────────────────────────
|
|
170
|
+
// Called when: watchdog fires, gateway disconnects mid-run, or server
|
|
171
|
+
// sends an explicit error event. Cleans up all state and shows the user
|
|
172
|
+
// a clear error message + ERROR orb state.
|
|
173
|
+
function handleRunFailure(reason) {
|
|
174
|
+
// Stop timers immediately
|
|
175
|
+
stopElapsedTimer();
|
|
176
|
+
clearWatchdog();
|
|
177
|
+
|
|
178
|
+
// Clean up any in-flight UI elements
|
|
179
|
+
if (thinkingEl) { thinkingEl.remove(); thinkingEl = null; }
|
|
180
|
+
if (streamBubble) {
|
|
181
|
+
// Don't render markdown on a partial/failed response — just mark it failed
|
|
182
|
+
streamBubble.classList.remove('streaming');
|
|
183
|
+
streamBubble.classList.add('done', 'stream-failed');
|
|
184
|
+
streamBubble = null;
|
|
185
|
+
streamContent = null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Human-readable reason labels
|
|
189
|
+
const labels = {
|
|
190
|
+
timeout: `No response received after ${WATCHDOG_MS / 1000}s — the agent may still be running in the background`,
|
|
191
|
+
disconnected: 'Connection lost mid-run — gateway disconnected',
|
|
192
|
+
};
|
|
193
|
+
const label = labels[reason] || reason;
|
|
194
|
+
|
|
195
|
+
// Inject error bubble into the feed
|
|
196
|
+
const errEl = document.createElement('div');
|
|
197
|
+
errEl.className = 'message symi-msg';
|
|
198
|
+
errEl.innerHTML = `
|
|
199
|
+
<div class="bubble stream-bubble done run-error-bubble">
|
|
200
|
+
<div class="run-error-icon">⚠</div>
|
|
201
|
+
<div class="bubble-content run-error-text">${escapeHtml(label)}</div>
|
|
202
|
+
</div>
|
|
203
|
+
<div class="message-clearfix"></div>
|
|
204
|
+
`;
|
|
205
|
+
responseArea.appendChild(errEl);
|
|
206
|
+
requestAnimationFrame(() => { responseArea.scrollTop = responseArea.scrollHeight; });
|
|
207
|
+
|
|
208
|
+
// Show ERROR state on orb, then reset input
|
|
209
|
+
setAgentStatus('error');
|
|
210
|
+
isStreaming = false;
|
|
211
|
+
currentRunId = null;
|
|
212
|
+
stopBtn.style.opacity = '';
|
|
213
|
+
stopBtn.disabled = false;
|
|
214
|
+
enableInput();
|
|
215
|
+
updateQueueBtn(); // keep queue button visible if items remain
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ── Render history (on first connect) ─────────────────────────────
|
|
219
|
+
function renderHistory(messages) {
|
|
220
|
+
responseArea.innerHTML = '';
|
|
221
|
+
for (const m of messages) {
|
|
222
|
+
if (!m || !m.role) continue;
|
|
223
|
+
const hasContent = Array.isArray(m.content)
|
|
224
|
+
? m.content.some(b => (b.text ?? b.thinking ?? b.name ?? '').trim())
|
|
225
|
+
: extractText(m.content).trim();
|
|
226
|
+
if (!hasContent) continue;
|
|
227
|
+
|
|
228
|
+
const el = window.renderMessage(m);
|
|
229
|
+
responseArea.appendChild(el);
|
|
230
|
+
window.applyHighlighting(el);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Scroll to very bottom after history renders
|
|
234
|
+
requestAnimationFrame(() => { responseArea.scrollTop = responseArea.scrollHeight; });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ── Gateway event handler ──────────────────────────────────────────
|
|
238
|
+
let thinkingEl = null;
|
|
239
|
+
|
|
240
|
+
function handleGatewayEvent(event) {
|
|
241
|
+
if (event.event !== 'chat') return;
|
|
242
|
+
const p = event.payload;
|
|
243
|
+
if (!p || p.sessionKey !== window.SESSION_KEY) return;
|
|
244
|
+
|
|
245
|
+
if (p.state === 'delta') {
|
|
246
|
+
// Capture runId on first delta so abort can target the exact run
|
|
247
|
+
if (p.runId && !currentRunId) currentRunId = p.runId;
|
|
248
|
+
|
|
249
|
+
// Each delta proves the agent is alive — reset the watchdog
|
|
250
|
+
armWatchdog();
|
|
251
|
+
|
|
252
|
+
// First delta — remove thinking bubble, open stream bubble
|
|
253
|
+
if (thinkingEl) { thinkingEl.remove(); thinkingEl = null; }
|
|
254
|
+
if (!streamBubble) {
|
|
255
|
+
openStreamBubble();
|
|
256
|
+
setAgentStatus('streaming');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const text = extractText(p.message);
|
|
260
|
+
if (text) updateStream(text);
|
|
261
|
+
|
|
262
|
+
} else if (p.state === 'final') {
|
|
263
|
+
stopElapsedTimer();
|
|
264
|
+
clearWatchdog();
|
|
265
|
+
closeStreamBubble();
|
|
266
|
+
setAgentStatus('done');
|
|
267
|
+
isStreaming = false;
|
|
268
|
+
currentRunId = null;
|
|
269
|
+
stopBtn.style.opacity = ''; // reset stop button visual state
|
|
270
|
+
stopBtn.disabled = false;
|
|
271
|
+
enableInput();
|
|
272
|
+
drainQueue();
|
|
273
|
+
|
|
274
|
+
} else if (p.state === 'aborted') {
|
|
275
|
+
// Clean abort (user-initiated or model decided to stop) — not an error
|
|
276
|
+
stopElapsedTimer();
|
|
277
|
+
clearWatchdog();
|
|
278
|
+
if (streamBubble) closeStreamBubble();
|
|
279
|
+
if (thinkingEl) { thinkingEl.remove(); thinkingEl = null; }
|
|
280
|
+
setAgentStatus('idle');
|
|
281
|
+
isStreaming = false;
|
|
282
|
+
currentRunId = null;
|
|
283
|
+
stopBtn.style.opacity = ''; // reset stop button visual state
|
|
284
|
+
stopBtn.disabled = false;
|
|
285
|
+
enableInput();
|
|
286
|
+
drainQueue();
|
|
287
|
+
|
|
288
|
+
} else if (p.state === 'error') {
|
|
289
|
+
// Server-reported error — route through unified failure handler
|
|
290
|
+
handleRunFailure(p.error?.message || 'Server reported an error');
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ── Agent Status Orb ───────────────────────────────────────────────
|
|
295
|
+
const asoPanel = document.getElementById('agent-status-panel');
|
|
296
|
+
const asoLabel = document.getElementById('aso-label');
|
|
297
|
+
const asoSub = document.getElementById('aso-sub');
|
|
298
|
+
let asoDoneTimer = null;
|
|
299
|
+
|
|
300
|
+
const ASO_STATES = {
|
|
301
|
+
idle: { state: 'idle', label: 'STANDBY', sub: 'Awaiting your prompt' },
|
|
302
|
+
waiting: { state: 'waiting', label: 'WAITING', sub: 'Sending to Symi\u2026' },
|
|
303
|
+
thinking: { state: 'thinking', label: 'PROCESSING', sub: 'Reasoning through request' },
|
|
304
|
+
streaming: { state: 'streaming', label: 'RESPONDING', sub: 'Generating response' },
|
|
305
|
+
done: { state: 'done', label: 'COMPLETE', sub: 'Response ready' },
|
|
306
|
+
error: { state: 'error', label: 'FAILED', sub: 'Run ended unexpectedly' },
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
function setAgentStatus(key) {
|
|
310
|
+
if (!asoPanel) return;
|
|
311
|
+
|
|
312
|
+
// Clear any pending auto-transition timers
|
|
313
|
+
if (asoDoneTimer) { clearTimeout(asoDoneTimer); asoDoneTimer = null; }
|
|
314
|
+
|
|
315
|
+
const s = ASO_STATES[key] || ASO_STATES.idle;
|
|
316
|
+
asoPanel.dataset.state = s.state;
|
|
317
|
+
if (asoLabel) asoLabel.textContent = s.label;
|
|
318
|
+
if (asoSub) asoSub.textContent = s.sub;
|
|
319
|
+
|
|
320
|
+
// ── Elapsed timer management ──────────────────────────────────
|
|
321
|
+
if (key === 'thinking') {
|
|
322
|
+
// Start elapsed timer and watchdog when processing begins
|
|
323
|
+
armWatchdog();
|
|
324
|
+
startElapsedTimer('Reasoning through request');
|
|
325
|
+
} else if (key === 'streaming') {
|
|
326
|
+
// Transition from thinking → streaming: keep watchdog running (will be
|
|
327
|
+
// reset on each delta), switch elapsed timer base text
|
|
328
|
+
elapsedBaseText = 'Generating response';
|
|
329
|
+
} else {
|
|
330
|
+
// Any terminal/non-active state: stop elapsed timer and watchdog
|
|
331
|
+
stopElapsedTimer();
|
|
332
|
+
clearWatchdog();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ── Auto-revert timers ────────────────────────────────────────
|
|
336
|
+
if (key === 'done') {
|
|
337
|
+
asoDoneTimer = setTimeout(() => setAgentStatus('idle'), 3000);
|
|
338
|
+
}
|
|
339
|
+
if (key === 'error') {
|
|
340
|
+
asoDoneTimer = setTimeout(() => setAgentStatus('idle'), 4000);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ── Input state ────────────────────────────────────────────────────
|
|
345
|
+
function disableInput() {
|
|
346
|
+
// Keep textarea enabled so user can type their next queued message while AI responds
|
|
347
|
+
sendBtn.disabled = true;
|
|
348
|
+
newSessionBtn.disabled = true;
|
|
349
|
+
sendBtn.classList.add('btn-loading');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function enableInput() {
|
|
353
|
+
sendBtn.disabled = false;
|
|
354
|
+
newSessionBtn.disabled = false;
|
|
355
|
+
sendBtn.classList.remove('btn-loading');
|
|
356
|
+
promptInput.focus();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ── Queue helpers ──────────────────────────────────────────────────
|
|
360
|
+
const queueBtn = document.getElementById('queue-btn');
|
|
361
|
+
const queueCancelX = document.getElementById('queue-cancel-x');
|
|
362
|
+
|
|
363
|
+
function updateQueueBtn() {
|
|
364
|
+
const streaming = isStreaming;
|
|
365
|
+
const count = chatQueue.length;
|
|
366
|
+
|
|
367
|
+
if (streaming || count > 0) {
|
|
368
|
+
// Show stop + queue buttons, hide New Session
|
|
369
|
+
stopBtn.classList.add('visible');
|
|
370
|
+
queueBtn.classList.add('visible');
|
|
371
|
+
newSessionBtn.style.display = 'none';
|
|
372
|
+
|
|
373
|
+
if (count > 0) {
|
|
374
|
+
queueBtn.classList.add('has-queue');
|
|
375
|
+
queueBtn.querySelector('.queue-btn-label').textContent = `Queued (${count})`;
|
|
376
|
+
} else {
|
|
377
|
+
queueBtn.classList.remove('has-queue');
|
|
378
|
+
queueBtn.querySelector('.queue-btn-label').textContent = 'Queue ↵';
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
// Hide stop + queue, restore New Session
|
|
382
|
+
stopBtn.classList.remove('visible');
|
|
383
|
+
queueBtn.classList.remove('visible', 'has-queue');
|
|
384
|
+
newSessionBtn.style.display = '';
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function queueMessage(text) {
|
|
389
|
+
if (!text.trim()) return;
|
|
390
|
+
chatQueue = [...chatQueue, { id: Date.now(), text: text.trim() }];
|
|
391
|
+
updateQueueBtn();
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function clearQueue() {
|
|
395
|
+
chatQueue = [];
|
|
396
|
+
updateQueueBtn();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function drainQueue() {
|
|
400
|
+
if (chatQueue.length === 0) {
|
|
401
|
+
updateQueueBtn();
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const [next, ...rest] = chatQueue;
|
|
405
|
+
chatQueue = rest;
|
|
406
|
+
updateQueueBtn();
|
|
407
|
+
// Small delay so the UI settles before starting the next send
|
|
408
|
+
setTimeout(() => sendText(next.text), 120);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ── Core send (no input reading — accepts text directly) ───────────
|
|
412
|
+
async function sendText(text) {
|
|
413
|
+
if (!gateway.connected) return;
|
|
414
|
+
isStreaming = true;
|
|
415
|
+
disableInput();
|
|
416
|
+
updateQueueBtn();
|
|
417
|
+
|
|
418
|
+
addUserMessage(text);
|
|
419
|
+
await sleep(200);
|
|
420
|
+
|
|
421
|
+
setAgentStatus('waiting');
|
|
422
|
+
thinkingEl = createThinkingBubble();
|
|
423
|
+
setAgentStatus('thinking');
|
|
424
|
+
|
|
425
|
+
try {
|
|
426
|
+
await gateway.send(text);
|
|
427
|
+
} catch (err) {
|
|
428
|
+
handleRunFailure(err.message || 'Failed to send message');
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// ── Send handler (reads input, queues if busy) ─────────────────────
|
|
433
|
+
async function handleSend() {
|
|
434
|
+
const text = promptInput.value.trim();
|
|
435
|
+
if (!text) return;
|
|
436
|
+
|
|
437
|
+
// Clear the input immediately regardless of streaming state
|
|
438
|
+
promptInput.value = '';
|
|
439
|
+
promptInput.style.height = 'auto';
|
|
440
|
+
|
|
441
|
+
if (isStreaming) {
|
|
442
|
+
// AI is busy — queue it
|
|
443
|
+
queueMessage(text);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (!gateway.connected) return;
|
|
448
|
+
await sendText(text);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// ── New Session handler ────────────────────────────────────────────
|
|
452
|
+
async function handleNewSession() {
|
|
453
|
+
if (isStreaming || !gateway.connected) return;
|
|
454
|
+
|
|
455
|
+
promptInput.disabled = true; // lock textarea during reset
|
|
456
|
+
disableInput();
|
|
457
|
+
setAgentStatus('waiting');
|
|
458
|
+
|
|
459
|
+
try {
|
|
460
|
+
// Send the /new slash command — gateway resets the session
|
|
461
|
+
await gateway.send('/new');
|
|
462
|
+
|
|
463
|
+
// Fade out existing messages, then show cleared state
|
|
464
|
+
responseArea.style.transition = 'opacity 0.25s ease';
|
|
465
|
+
responseArea.style.opacity = '0';
|
|
466
|
+
|
|
467
|
+
await sleep(260);
|
|
468
|
+
|
|
469
|
+
responseArea.innerHTML = '';
|
|
470
|
+
responseArea.style.opacity = '1';
|
|
471
|
+
|
|
472
|
+
// Show empty-state indicator
|
|
473
|
+
const cleared = document.createElement('div');
|
|
474
|
+
cleared.className = 'session-cleared';
|
|
475
|
+
cleared.innerHTML = `
|
|
476
|
+
<div class="session-cleared-icon">◈</div>
|
|
477
|
+
<div class="session-cleared-text">NEW SESSION STARTED</div>
|
|
478
|
+
`;
|
|
479
|
+
responseArea.appendChild(cleared);
|
|
480
|
+
|
|
481
|
+
setAgentStatus('idle');
|
|
482
|
+
clearQueue(); // discard any queued prompts — new session = clean slate
|
|
483
|
+
|
|
484
|
+
// Show archive toast — lets user jump directly to history if they regret it
|
|
485
|
+
if (typeof window.showArchiveToast === 'function') window.showArchiveToast();
|
|
486
|
+
|
|
487
|
+
// After a short pause, remove the cleared indicator and let history load
|
|
488
|
+
await sleep(1800);
|
|
489
|
+
cleared.style.transition = 'opacity 0.4s ease';
|
|
490
|
+
cleared.style.opacity = '0';
|
|
491
|
+
await sleep(420);
|
|
492
|
+
cleared.remove();
|
|
493
|
+
|
|
494
|
+
} catch (err) {
|
|
495
|
+
handleRunFailure(err.message || 'Failed to start new session');
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
promptInput.disabled = false; // re-enable textarea after reset
|
|
500
|
+
enableInput();
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ── Stop handler ───────────────────────────────────────────────────
|
|
504
|
+
async function handleStop() {
|
|
505
|
+
if (!isStreaming || !gateway.connected) return;
|
|
506
|
+
try {
|
|
507
|
+
await gateway.abort(currentRunId);
|
|
508
|
+
// The gateway will send an 'aborted' event which cleans up state.
|
|
509
|
+
// Visually dim the stop button while we wait for confirmation.
|
|
510
|
+
stopBtn.style.opacity = '0.45';
|
|
511
|
+
stopBtn.disabled = true;
|
|
512
|
+
} catch (err) {
|
|
513
|
+
console.warn('[stop] abort failed:', err.message);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
sendBtn.addEventListener('click', handleSend);
|
|
518
|
+
newSessionBtn.addEventListener('click', handleNewSession);
|
|
519
|
+
stopBtn.addEventListener('click', handleStop);
|
|
520
|
+
|
|
521
|
+
// Queue button — queue current input (if idle text present) or show queued count
|
|
522
|
+
queueBtn.addEventListener('click', e => {
|
|
523
|
+
// Cancel X — clears the queue
|
|
524
|
+
if (e.target === queueCancelX || queueCancelX.contains(e.target)) {
|
|
525
|
+
clearQueue();
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
// Main button click — queue the current input if no item queued yet
|
|
529
|
+
if (chatQueue.length === 0) {
|
|
530
|
+
const text = promptInput.value.trim();
|
|
531
|
+
if (text) {
|
|
532
|
+
promptInput.value = '';
|
|
533
|
+
promptInput.style.height = 'auto';
|
|
534
|
+
queueMessage(text);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
promptInput.addEventListener('keydown', e => {
|
|
539
|
+
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); }
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// ── Textarea auto-resize (up to 3 lines) ──────────────────────────
|
|
543
|
+
function autoResizePrompt() {
|
|
544
|
+
promptInput.style.height = 'auto';
|
|
545
|
+
promptInput.style.height = promptInput.scrollHeight + 'px';
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
promptInput.addEventListener('input', autoResizePrompt);
|
|
549
|
+
|
|
550
|
+
// Clicking anywhere on the prompt bar (padding, icon, gaps) focuses the input
|
|
551
|
+
// Click anywhere on the main input row (not buttons) focuses the input
|
|
552
|
+
document.getElementById('prompt-bar').addEventListener('click', e => {
|
|
553
|
+
const inSend = sendBtn.contains(e.target) || e.target === sendBtn;
|
|
554
|
+
const inNewSession = newSessionBtn.contains(e.target) || e.target === newSessionBtn;
|
|
555
|
+
const inHistory = document.getElementById('history-btn').contains(e.target);
|
|
556
|
+
const inQueue = queueBtn.contains(e.target);
|
|
557
|
+
const inStop = stopBtn.contains(e.target);
|
|
558
|
+
// Only focus if clicking in the main row area (not the actions row)
|
|
559
|
+
const inActionsRow = e.target.closest('.prompt-row-actions');
|
|
560
|
+
if (!inSend && !inNewSession && !inHistory && !inQueue && !inStop && !inActionsRow) {
|
|
561
|
+
promptInput.focus();
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
// ── Gateway setup ──────────────────────────────────────────────────
|
|
566
|
+
const gateway = new SymiGateway();
|
|
567
|
+
window.gateway = gateway; // expose for native page viewers (logs, etc.)
|
|
568
|
+
|
|
569
|
+
gateway.addEventListener('connect', () => {
|
|
570
|
+
setStatus('online');
|
|
571
|
+
enableInput();
|
|
572
|
+
// History arrives via separate 'history' event pushed by the server
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
gateway.addEventListener('history', (e) => {
|
|
576
|
+
const msgs = Array.isArray(e.detail?.messages) ? e.detail.messages : [];
|
|
577
|
+
renderHistory(msgs);
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
gateway.addEventListener('disconnect', () => {
|
|
581
|
+
setStatus('offline');
|
|
582
|
+
// If the gateway drops while a run is in progress, surface the failure
|
|
583
|
+
// immediately rather than leaving the UI in a permanently locked state.
|
|
584
|
+
if (isStreaming) {
|
|
585
|
+
handleRunFailure('disconnected');
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
gateway.addEventListener('event', (e) => {
|
|
590
|
+
handleGatewayEvent(e.detail);
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
// Start connecting
|
|
594
|
+
disableInput();
|
|
595
|
+
gateway.start();
|