@symerian/symi 3.4.30 → 3.4.31

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.
Files changed (177) hide show
  1. package/dist/{agent-O3PihJOY.js → agent-ZFfYdexc.js} +10 -10
  2. package/dist/{agents-C2MpIr16.js → agents-C8naPegc.js} +5 -5
  3. package/dist/{audit-yf3H4Y1h.js → audit-DOfexJi4.js} +8 -8
  4. package/dist/{auth-choice-CyBcsQ9T.js → auth-choice-DxH-c3vK.js} +4 -4
  5. package/dist/{banner-D7__HlM-.js → banner-D7zYLyA8.js} +1 -1
  6. package/dist/{browser-cli-B_6WWHm_.js → browser-cli-MYIql1Ic.js} +3 -3
  7. package/dist/build-info.json +1 -1
  8. package/dist/bundled/boot-md/handler.js +4 -4
  9. package/dist/bundled/session-memory/handler.js +4 -4
  10. package/dist/{call-IfleM0ap.js → call-D9U2Sfhp.js} +1 -1
  11. package/dist/{channel-options-B5974x-7.js → channel-options-9PzSNQLG.js} +1 -1
  12. package/dist/{channels-cli-C6Nv9mzy.js → channels-cli-C3XnNkE5.js} +30 -30
  13. package/dist/{chrome-DT1fIVG1.js → chrome-B4P7ycw5.js} +7 -7
  14. package/dist/{chrome-DJCkCRLf.js → chrome-ClVIwINy.js} +1 -1
  15. package/dist/{cli-DZoms4qg.js → cli-DhTdzhjk.js} +26 -26
  16. package/dist/{command-registry--D98SJ6k.js → command-registry-BOwku-e8.js} +11 -11
  17. package/dist/{completion-cli-CHYvpIPw.js → completion-cli-KZYbGY4H.js} +2 -2
  18. package/dist/{config-BTSBEAnk.js → config-Byd2Y9rr.js} +5 -5
  19. package/dist/{config-cli-DstpcB33.js → config-cli-CJ1CRfG8.js} +5 -5
  20. package/dist/{config-guard-CCJrDmON.js → config-guard-zt0zhFHl.js} +2 -2
  21. package/dist/{config-validation-YCrMlM9Z.js → config-validation-CRazk6Kd.js} +1 -1
  22. package/dist/{configure-B-UvSZZ7.js → configure-CFY_XEps.js} +10 -10
  23. package/dist/{control-service-CwRG4M_O.js → control-service-DN6-IdFk.js} +4 -4
  24. package/dist/{cron-cli-DUETe3Of.js → cron-cli-fmiz43Pz.js} +3 -3
  25. package/dist/{daemon-cli-Dy5eY4M7.js → daemon-cli-BilAL40g.js} +6 -6
  26. package/dist/{daemon-runtime-ChztAKDA.js → daemon-runtime-D4KHzQq2.js} +1 -1
  27. package/dist/{deliver-59sRVaYQ.js → deliver-BkCYBlzi.js} +4 -4
  28. package/dist/{deliver-BHmK4isn.js → deliver-CnsfN7km.js} +1 -1
  29. package/dist/{devices-cli-BCZ2HHjT.js → devices-cli-D7HdOwRI.js} +2 -2
  30. package/dist/{directory-cli-BVGd0l0T.js → directory-cli-ed6QacBC.js} +1 -1
  31. package/dist/{dns-cli-DH-ksmiI.js → dns-cli-RPa1dGTQ.js} +1 -1
  32. package/dist/{docs-cli-BuX8FDdh.js → docs-cli-ZTdS_Gak.js} +2 -2
  33. package/dist/{doctor-completion-C4Sf8CFV.js → doctor-completion-DpGX8dau.js} +1 -1
  34. package/dist/{doctor-config-flow-BhmF6EAq.js → doctor-config-flow-CIrG_yW_.js} +4 -4
  35. package/dist/entry.js +3 -3
  36. package/dist/{exec-approvals-cli-CyXTXgft.js → exec-approvals-cli-65pcsa1y.js} +6 -6
  37. package/dist/{frontmatter-BH3ExkUY.js → frontmatter-B4levtVg.js} +2 -2
  38. package/dist/{gateway-cli-fT43bqlv.js → gateway-cli-CTi7Wl2k.js} +50 -50
  39. package/dist/{gateway-rpc-BEqCo2JK.js → gateway-rpc-2VPLhMhx.js} +1 -1
  40. package/dist/{glass-ui-ws-BfMKuf9v.js → glass-ui-ws-Bah_A-jn.js} +38 -38
  41. package/dist/{gmail-setup-utils-Cz9Tb30q.js → gmail-setup-utils-C9WBC6Cd.js} +1 -1
  42. package/dist/{health-DDxrkioj.js → health-B5rRzhyV.js} +3 -3
  43. package/dist/{hooks-cli-Btgk__9z.js → hooks-cli-CSDCGO-W.js} +29 -29
  44. package/dist/{hooks-status-BaV4_YaJ.js → hooks-status-OorbLcc2.js} +2 -2
  45. package/dist/index.js +0 -0
  46. package/dist/{lifecycle-core-B0tG8ERp.js → lifecycle-core-BRc-XqTk.js} +2 -2
  47. package/dist/llm-slug-generator.js +4 -4
  48. package/dist/{logs-cli-CUhZrDw7.js → logs-cli-D5phVUOT.js} +3 -3
  49. package/dist/{manager-BeNnzSJv.js → manager-BfhHvsI9.js} +1 -1
  50. package/dist/{manager-Di9qtuZF.js → manager-DzBH9uQG.js} +1 -1
  51. package/dist/{memory-BDeydRz3.js → memory-BCj0cj5v.js} +3 -3
  52. package/dist/{memory-cli-D4hZiGr5.js → memory-cli-9WUMBHol.js} +3 -3
  53. package/dist/{model-catalog-DPnCNs5N.js → model-catalog-CD2kTz4V.js} +2 -2
  54. package/dist/{model-picker-DuPommMc.js → model-picker-CVd5UuXV.js} +2 -2
  55. package/dist/{models-cli-CL5K06Wu.js → models-cli-rd4eX_6P.js} +30 -30
  56. package/dist/{models-config-CPlvO1b0.js → models-config-oxaGiRUT.js} +1 -1
  57. package/dist/{models-B0wNKA18.js → models-sbKIrJBG.js} +9 -9
  58. package/dist/{node-cli-CWWMajKF.js → node-cli-ClLXSdFL.js} +9 -9
  59. package/dist/{nodes-cli-YmE7S-JB.js → nodes-cli-DY38p5In.js} +3 -3
  60. package/dist/{onboard-HqUZVKyD.js → onboard-BAyp_UFm.js} +7 -7
  61. package/dist/{onboard-channels-BbF5-N3g.js → onboard-channels-CUpkV_IJ.js} +1 -1
  62. package/dist/{onboard-custom-63SI3jrk.js → onboard-custom-BMgLK-vo.js} +2 -2
  63. package/dist/{onboard-helpers-Cb3WFLl9.js → onboard-helpers-DIQjpQ-s.js} +2 -2
  64. package/dist/{onboard-hooks-DXXg3YH9.js → onboard-hooks-KZKmj5Dk.js} +3 -3
  65. package/dist/{onboard-remote-CqtCrqtm.js → onboard-remote-C-_NUgBl.js} +1 -1
  66. package/dist/{onboard-skills-CS3l5fhH.js → onboard-skills-CwvicFTi.js} +3 -3
  67. package/dist/{onboarding-Be_HJIFA.js → onboarding-BxCNNo75.js} +11 -11
  68. package/dist/{onboarding.finalize-dsCUTKCQ.js → onboarding.finalize-DgMPXTtO.js} +18 -18
  69. package/dist/{onboarding.gateway-config-Ctd1_QW4.js → onboarding.gateway-config-BAaWvPSX.js} +4 -4
  70. package/dist/{outbound-send-deps-DPsU_Xdy.js → outbound-send-deps-qhFaNYAY.js} +1 -1
  71. package/dist/{pairing-cli-PtlNv7Gr.js → pairing-cli-CFkiSx8t.js} +1 -1
  72. package/dist/{pi-embedded-helpers-CVKIHnFv.js → pi-embedded-helpers-CRG5LMS7.js} +1 -1
  73. package/dist/{pi-tools.policy-8_wTu7v2.js → pi-tools.policy-De6xHjVL.js} +2 -2
  74. package/dist/{plugin-registry-BG51uZOA.js → plugin-registry-BNe5jtPK.js} +2 -2
  75. package/dist/plugin-sdk/index.js +6 -6
  76. package/dist/{plugins-cli-B-zVOiQN.js → plugins-cli-CWj33_Hj.js} +27 -27
  77. package/dist/{program-BOh0XGsA.js → program-Z2OLlhsB.js} +33 -33
  78. package/dist/{prompt-select-styled-Bj-hrPCx.js → prompt-select-styled-BNwbBBcH.js} +16 -16
  79. package/dist/{provider-auth-helpers-BK6NFk2Q.js → provider-auth-helpers-5qb15Hje.js} +2 -2
  80. package/dist/{push-apns-CMxk3Hxf.js → push-apns-D6qV5P4h.js} +1 -1
  81. package/dist/{pw-ai-C5MJKzUM.js → pw-ai-BsEf8C15.js} +1 -1
  82. package/dist/{pw-ai-CE2TBGif.js → pw-ai-C7mvVllB.js} +2 -2
  83. package/dist/{qr-cli-BeHlC33g.js → qr-cli-oENcXq8d.js} +1 -1
  84. package/dist/{redact-identifier-B1VHIbnd.js → redact-identifier-ZE8OIUof.js} +1 -1
  85. package/dist/{register.agent-COv5OPLQ.js → register.agent-DpiHPMca.js} +36 -36
  86. package/dist/{register.configure-RhKVlfWH.js → register.configure-DRFaroYF.js} +40 -40
  87. package/dist/{register.maintenance-BAK-DiQY.js → register.maintenance-BGNNTt_1.js} +38 -38
  88. package/dist/{register.message-CCBmn5ja.js → register.message-R4AIHhlU.js} +28 -28
  89. package/dist/{register.onboard-B3jO_Goy.js → register.onboard-Cl-_Suyv.js} +13 -13
  90. package/dist/{register.setup-CYSISTDO.js → register.setup-Dt98v2V3.js} +15 -15
  91. package/dist/{register.status-health-sessions-CGbg9k6d.js → register.status-health-sessions-DiX5lVyr.js} +23 -23
  92. package/dist/{register.subclis-loifbhVx.js → register.subclis-DVObuR_P.js} +28 -28
  93. package/dist/{replies-Dj640LxQ.js → replies-VTJu1jUK.js} +1 -1
  94. package/dist/{routes-B5y-oAKp.js → routes-DOFg6X5M.js} +3 -3
  95. package/dist/{rpc-qWm1bRo5.js → rpc-BIHKXdlN.js} +1 -1
  96. package/dist/{run-main-B7Ria3zD.js → run-main-NAgYKzSu.js} +44 -44
  97. package/dist/{sandbox-BJgHc4Vu.js → sandbox-EB7cFSML.js} +6 -6
  98. package/dist/{sandbox-cli-CSudrHYL.js → sandbox-cli-D4dy6sUK.js} +8 -8
  99. package/dist/{security-cli-B2lCR2xX.js → security-cli-DwCKOrFm.js} +11 -11
  100. package/dist/{send-CY9na-Jw.js → send-CkRtuQbr.js} +1 -1
  101. package/dist/{server-context-DdWWaDf6.js → server-context-ww1jytet.js} +5 -5
  102. package/dist/{server-methods-Dk_EnINI.js → server-methods-BDiZyPvS.js} +23 -23
  103. package/dist/{server-node-events-BHegSgG9.js → server-node-events-9cY40B4m.js} +29 -29
  104. package/dist/{session-utils-CAVPV2Hh.js → session-utils-CStjqGE6.js} +3 -3
  105. package/dist/{sessions-BDM9kNY0.js → sessions-BSRHJH8T.js} +3 -3
  106. package/dist/{sessions-CqLQkkWg.js → sessions-CInbrqsF.js} +1 -1
  107. package/dist/{shared-CpwtQRJB.js → shared-DEAo94kI.js} +1 -1
  108. package/dist/{skill-commands-CRQniaHy.js → skill-commands-BkKfrbHt.js} +2 -2
  109. package/dist/{skills-CTcjFd_F.js → skills-CFLijAZ-.js} +1 -1
  110. package/dist/{skills-cli-9Mlb7VRg.js → skills-cli-BbagnO6p.js} +5 -5
  111. package/dist/{skills-install-D5ikt72d.js → skills-install-dLRO1KGp.js} +2 -2
  112. package/dist/{skills-remote-BASG1Doo.js → skills-remote-DQVB-3Pj.js} +1 -1
  113. package/dist/{skills-status-1iVfuVIG.js → skills-status-HWybfj0K.js} +2 -2
  114. package/dist/{status-Bci6O3aA.js → status-BSrVEUoJ.js} +2 -2
  115. package/dist/{status-D5RhVO0A.js → status-FIp7UKru.js} +12 -12
  116. package/dist/{status.update-D5CachQ_.js → status.update-Cm8Fm8QD.js} +1 -1
  117. package/dist/{subagent-registry-CsXaK_sy.js → subagent-registry-DqryocLT.js} +31 -31
  118. package/dist/{synthesis-dplLmFIP.js → synthesis-CS-lrEGy.js} +4 -4
  119. package/dist/{synthesis-BoZf8BeO.js → synthesis-DKhH0YwU.js} +26 -26
  120. package/dist/{system-cli-D5FffFX5.js → system-cli-DYSI6cIB.js} +3 -3
  121. package/dist/{systemd-hints-CufcSfMk.js → systemd-hints-EIfW5y8K.js} +1 -1
  122. package/dist/{tui-DZ8gksSZ.js → tui-C20rHOeB.js} +4 -4
  123. package/dist/{tui-cli-CyBJYh9u.js → tui-cli-JwlzHCza.js} +11 -11
  124. package/dist/{unified-runner-BFLLzEHE.js → unified-runner-AM9tFC5q.js} +10 -10
  125. package/dist/{update-cli-yW6Xl6fs.js → update-cli-BYfA3RPc.js} +41 -41
  126. package/dist/{update-runner-CIgLduhH.js → update-runner-CBG8p9iG.js} +1 -1
  127. package/dist/{webhooks-cli-4bmyKzwb.js → webhooks-cli-MuG_QGLp.js} +4 -4
  128. package/dist/{with-timeout-bWr6yBeX.js → with-timeout-BvxaeAo6.js} +1 -1
  129. package/dist/{workspace-DxscDsm6.js → workspace-D0d7Gi4-.js} +1 -1
  130. package/extensions/memory-core/node_modules/.bin/symi +0 -0
  131. package/extensions/msteams/node_modules/.bin/symi +0 -0
  132. package/extensions/outlook/node_modules/.bin/symi +0 -0
  133. package/extensions/slack/node_modules/.bin/symi +0 -0
  134. package/package.json +108 -79
  135. package/dist/control-ui/css/revert-red-theme.md +0 -141
  136. package/dist/control-ui/css/style.css +0 -5843
  137. package/dist/control-ui/css/style.css.backup-2026-03-03-162525 +0 -3546
  138. package/dist/control-ui/css/style.css.backup-before-red-2026-03-03-162525 +0 -3546
  139. package/dist/control-ui/css/style.css.backup-before-red-theme-2026-03-03-162530 +0 -3546
  140. package/dist/control-ui/css/style.css.pre-2row +0 -2165
  141. package/dist/control-ui/css/style.css.pre-brand +0 -1776
  142. package/dist/control-ui/css/style.css.pre-history +0 -1974
  143. package/dist/control-ui/css/style.css.pre-nav +0 -2264
  144. package/dist/control-ui/css/style.css.pre-newsession +0 -1898
  145. package/dist/control-ui/css/style.css.pre-queue +0 -2195
  146. package/dist/control-ui/css/style.css.pre-red-prompt +0 -2524
  147. package/dist/control-ui/css/style.css.pre-stop +0 -2239
  148. package/dist/control-ui/css/style.css.pre-textarea +0 -2184
  149. package/dist/control-ui/css/style.css.pre-watchdog +0 -1848
  150. package/dist/control-ui/css/style.css.red-theme +0 -2999
  151. package/dist/control-ui/index.html +0 -1042
  152. package/dist/control-ui/js/app.js +0 -1304
  153. package/dist/control-ui/js/app.js.pre-2row +0 -463
  154. package/dist/control-ui/js/app.js.pre-heartbeat-filter +0 -595
  155. package/dist/control-ui/js/app.js.pre-newsession +0 -408
  156. package/dist/control-ui/js/app.js.pre-queue +0 -476
  157. package/dist/control-ui/js/app.js.pre-stop +0 -564
  158. package/dist/control-ui/js/app.js.pre-textarea +0 -467
  159. package/dist/control-ui/js/app.js.pre-watchdog +0 -293
  160. package/dist/control-ui/js/connections.js +0 -438
  161. package/dist/control-ui/js/gateway.js +0 -233
  162. package/dist/control-ui/js/gateway.js.pre-stop +0 -110
  163. package/dist/control-ui/js/history.js +0 -732
  164. package/dist/control-ui/js/logs.js +0 -238
  165. package/dist/control-ui/js/menu.js +0 -230
  166. package/dist/control-ui/js/menu.js.pre-nav +0 -66
  167. package/dist/control-ui/js/metrics.js +0 -53
  168. package/dist/control-ui/js/models.js +0 -138
  169. package/dist/control-ui/js/render.js +0 -882
  170. package/dist/control-ui/js/render.test.js +0 -112
  171. package/dist/control-ui/js/scheduling.js +0 -461
  172. package/dist/control-ui/js/settings.js +0 -909
  173. package/dist/control-ui/js/slash-autocomplete.js +0 -168
  174. package/dist/control-ui/js/subagents.js +0 -560
  175. package/dist/control-ui/js/utils.js +0 -29
  176. package/dist/control-ui/vendor/highlight.min.js +0 -2518
  177. package/dist/control-ui/vendor/marked.min.js +0 -69
@@ -1,564 +0,0 @@
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
-
8
- let isStreaming = false;
9
- let currentRunId = null;
10
- let streamBubble = null;
11
- let streamContent = null;
12
- let streamStart = 0;
13
-
14
- // ── Prompt queue ──────────────────────────────────────────────────
15
- let chatQueue = []; // [{id, text}]
16
-
17
- // ── Watchdog + elapsed timer state ────────────────────────────────
18
- let watchdogTimer = null; // fires if no activity for WATCHDOG_MS
19
- let elapsedTimer = null; // ticks every second to show run duration
20
- let activityStart = 0; // timestamp of when current run began
21
- let elapsedBaseText = ''; // base sub-text for the elapsed display
22
- const WATCHDOG_MS = 90000; // 90 seconds of silence → failure
23
-
24
- // ── Utility ───────────────────────────────────────────────────────
25
- const sleep = ms => new Promise(r => setTimeout(r, ms));
26
- function escapeHtml(t) {
27
- return t.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
28
- }
29
-
30
- // ── Status indicator (top-right of response area) ─────────────────
31
- const statusEl = document.createElement('div');
32
- statusEl.className = 'conn-status';
33
- statusEl.innerHTML = '<span class="conn-dot dot-yellow pulse"></span><span class="conn-label">connecting…</span>';
34
- responseArea.before(statusEl);
35
-
36
- function setStatus(state) { // 'connecting' | 'online' | 'offline'
37
- const dot = statusEl.querySelector('.conn-dot');
38
- const label = statusEl.querySelector('.conn-label');
39
- dot.className = `conn-dot ${state === 'online' ? 'dot-green pulse' : state === 'offline' ? 'dot-red' : 'dot-yellow pulse'}`;
40
- label.textContent = state === 'online' ? 'live' : state === 'offline' ? 'disconnected' : 'connecting…';
41
- }
42
-
43
- // ── Render helpers ─────────────────────────────────────────────────
44
- function addUserMessage(text) {
45
- const msg = document.createElement('div');
46
- msg.className = 'message user-msg';
47
- msg.innerHTML = `<div class="bubble">${escapeHtml(text)}</div><div class="message-clearfix"></div>`;
48
- responseArea.appendChild(msg);
49
- msg.scrollIntoView({ behavior: 'smooth', block: 'end' });
50
- }
51
-
52
- // ── Thinking bubble ────────────────────────────────────────────────
53
- function createThinkingBubble() {
54
- const msg = document.createElement('div');
55
- msg.className = 'message symi-msg thinking-msg';
56
- msg.innerHTML = `
57
- <div class="bubble thinking-bubble">
58
- <div class="think-header">
59
- <span class="think-badge">◈ PROCESSING</span>
60
- <span class="think-dots"><span>.</span><span>.</span><span>.</span></span>
61
- </div>
62
- <div class="think-bar-wrap"><div class="think-bar"></div></div>
63
- </div>
64
- <div class="message-clearfix"></div>
65
- `;
66
- responseArea.appendChild(msg);
67
- msg.scrollIntoView({ behavior: 'smooth', block: 'end' });
68
- return msg;
69
- }
70
-
71
- // ── Stream bubble lifecycle ────────────────────────────────────────
72
- function openStreamBubble() {
73
- streamStart = Date.now();
74
- const msg = document.createElement('div');
75
- msg.className = 'message symi-msg stream-msg';
76
- msg.innerHTML = `<div class="bubble stream-bubble streaming"><div class="bubble-content"></div></div><div class="message-clearfix"></div>`;
77
- responseArea.appendChild(msg);
78
- streamBubble = msg.querySelector('.stream-bubble');
79
- streamContent = msg.querySelector('.bubble-content');
80
- msg.scrollIntoView({ behavior: 'smooth', block: 'end' });
81
- return msg;
82
- }
83
-
84
- function updateStream(text) {
85
- if (!streamContent) return;
86
- streamContent.textContent = text;
87
- responseArea.scrollTop = responseArea.scrollHeight;
88
- }
89
-
90
- function closeStreamBubble(model = 'claude-sonnet-4-6') {
91
- if (!streamBubble) return;
92
- streamBubble.classList.remove('streaming');
93
- streamBubble.classList.add('done');
94
-
95
- // Apply full markdown rendering to the final text
96
- const rawText = streamContent?.textContent ?? '';
97
- if (streamContent && rawText) {
98
- streamContent.innerHTML = '';
99
- const textBlock = renderBlock({ type: 'text', text: rawText });
100
- streamContent.appendChild(textBlock);
101
- window.applyHighlighting(streamContent);
102
- }
103
-
104
- const elapsed = Date.now() - streamStart;
105
- const chars = Math.round(rawText.length / 4);
106
-
107
- // Add copy button
108
- const copyBtn = document.createElement('button');
109
- copyBtn.className = 'msg-copy-btn msg-copy-visible';
110
- copyBtn.title = 'Copy';
111
- copyBtn.onclick = function() { window.copyMessage(this); };
112
- copyBtn.innerHTML = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none">
113
- <rect x="9" y="9" width="13" height="13" rx="2" stroke="currentColor" stroke-width="2"/>
114
- <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"/>
115
- </svg>`;
116
- streamBubble.appendChild(copyBtn);
117
-
118
- const footer = document.createElement('div');
119
- footer.className = 'telemetry';
120
- footer.innerHTML = `
121
- <span class="tele-item">✦ ${model}</span>
122
- <span class="tele-sep">·</span>
123
- <span class="tele-item">${chars} tokens</span>
124
- <span class="tele-sep">·</span>
125
- <span class="tele-item">${elapsed}ms</span>
126
- `;
127
- streamBubble.appendChild(footer);
128
- requestAnimationFrame(() => {
129
- footer.classList.add('tele-visible');
130
- // Scroll to bottom immediately after markdown + footer are in the DOM
131
- responseArea.scrollTop = responseArea.scrollHeight;
132
- });
133
-
134
- // Second scroll after the fit-content width transition finishes (0.3s)
135
- setTimeout(() => { responseArea.scrollTop = responseArea.scrollHeight; }, 350);
136
-
137
- streamBubble = null;
138
- streamContent = null;
139
- }
140
-
141
- // ── Elapsed timer ─────────────────────────────────────────────────
142
- function startElapsedTimer(baseText) {
143
- stopElapsedTimer();
144
- activityStart = Date.now();
145
- elapsedBaseText = baseText;
146
- elapsedTimer = setInterval(() => {
147
- const secs = Math.floor((Date.now() - activityStart) / 1000);
148
- const m = Math.floor(secs / 60);
149
- const s = String(secs % 60).padStart(2, '0');
150
- if (asoSub) asoSub.textContent = `${elapsedBaseText} ${m}:${s}`;
151
- }, 1000);
152
- }
153
-
154
- function stopElapsedTimer() {
155
- if (elapsedTimer) { clearInterval(elapsedTimer); elapsedTimer = null; }
156
- }
157
-
158
- // ── Watchdog ───────────────────────────────────────────────────────
159
- function armWatchdog() {
160
- clearWatchdog();
161
- watchdogTimer = setTimeout(() => handleRunFailure('timeout'), WATCHDOG_MS);
162
- }
163
-
164
- function clearWatchdog() {
165
- if (watchdogTimer) { clearTimeout(watchdogTimer); watchdogTimer = null; }
166
- }
167
-
168
- // ── Unified run failure handler ────────────────────────────────────
169
- // Called when: watchdog fires, gateway disconnects mid-run, or server
170
- // sends an explicit error event. Cleans up all state and shows the user
171
- // a clear error message + ERROR orb state.
172
- function handleRunFailure(reason) {
173
- // Stop timers immediately
174
- stopElapsedTimer();
175
- clearWatchdog();
176
-
177
- // Clean up any in-flight UI elements
178
- if (thinkingEl) { thinkingEl.remove(); thinkingEl = null; }
179
- if (streamBubble) {
180
- // Don't render markdown on a partial/failed response — just mark it failed
181
- streamBubble.classList.remove('streaming');
182
- streamBubble.classList.add('done', 'stream-failed');
183
- streamBubble = null;
184
- streamContent = null;
185
- }
186
-
187
- // Human-readable reason labels
188
- const labels = {
189
- timeout: `No response received after ${WATCHDOG_MS / 1000}s — the agent may still be running in the background`,
190
- disconnected: 'Connection lost mid-run — gateway disconnected',
191
- };
192
- const label = labels[reason] || reason;
193
-
194
- // Inject error bubble into the feed
195
- const errEl = document.createElement('div');
196
- errEl.className = 'message symi-msg';
197
- errEl.innerHTML = `
198
- <div class="bubble stream-bubble done run-error-bubble">
199
- <div class="run-error-icon">⚠</div>
200
- <div class="bubble-content run-error-text">${escapeHtml(label)}</div>
201
- </div>
202
- <div class="message-clearfix"></div>
203
- `;
204
- responseArea.appendChild(errEl);
205
- requestAnimationFrame(() => { responseArea.scrollTop = responseArea.scrollHeight; });
206
-
207
- // Show ERROR state on orb, then reset input
208
- setAgentStatus('error');
209
- isStreaming = false;
210
- currentRunId = null;
211
- enableInput();
212
- updateQueueBtn(); // keep queue button visible if items remain
213
- }
214
-
215
- // ── Render history (on first connect) ─────────────────────────────
216
- function renderHistory(messages) {
217
- responseArea.innerHTML = '';
218
- for (const m of messages) {
219
- if (!m || !m.role) continue;
220
- const hasContent = Array.isArray(m.content)
221
- ? m.content.some(b => (b.text ?? b.thinking ?? b.name ?? '').trim())
222
- : extractText(m.content).trim();
223
- if (!hasContent) continue;
224
-
225
- const el = window.renderMessage(m);
226
- responseArea.appendChild(el);
227
- window.applyHighlighting(el);
228
- }
229
-
230
- // Scroll to very bottom after history renders
231
- requestAnimationFrame(() => { responseArea.scrollTop = responseArea.scrollHeight; });
232
- }
233
-
234
- // ── Gateway event handler ──────────────────────────────────────────
235
- let thinkingEl = null;
236
-
237
- function handleGatewayEvent(event) {
238
- if (event.event !== 'chat') return;
239
- const p = event.payload;
240
- if (!p || p.sessionKey !== window.SESSION_KEY) return;
241
-
242
- if (p.state === 'delta') {
243
- // Each delta proves the agent is alive — reset the watchdog
244
- armWatchdog();
245
-
246
- // First delta — remove thinking bubble, open stream bubble
247
- if (thinkingEl) { thinkingEl.remove(); thinkingEl = null; }
248
- if (!streamBubble) {
249
- openStreamBubble();
250
- setAgentStatus('streaming');
251
- }
252
-
253
- const text = extractText(p.message);
254
- if (text) updateStream(text);
255
-
256
- } else if (p.state === 'final') {
257
- stopElapsedTimer();
258
- clearWatchdog();
259
- closeStreamBubble();
260
- setAgentStatus('done');
261
- isStreaming = false;
262
- currentRunId = null;
263
- enableInput();
264
- drainQueue();
265
-
266
- } else if (p.state === 'aborted') {
267
- // Clean abort (user-initiated or model decided to stop) — not an error
268
- stopElapsedTimer();
269
- clearWatchdog();
270
- if (streamBubble) closeStreamBubble();
271
- if (thinkingEl) { thinkingEl.remove(); thinkingEl = null; }
272
- setAgentStatus('idle');
273
- isStreaming = false;
274
- currentRunId = null;
275
- enableInput();
276
- drainQueue();
277
-
278
- } else if (p.state === 'error') {
279
- // Server-reported error — route through unified failure handler
280
- handleRunFailure(p.error?.message || 'Server reported an error');
281
- }
282
- }
283
-
284
- // ── Agent Status Orb ───────────────────────────────────────────────
285
- const asoPanel = document.getElementById('agent-status-panel');
286
- const asoLabel = document.getElementById('aso-label');
287
- const asoSub = document.getElementById('aso-sub');
288
- let asoDoneTimer = null;
289
-
290
- const ASO_STATES = {
291
- idle: { state: 'idle', label: 'STANDBY', sub: 'Awaiting your prompt' },
292
- waiting: { state: 'waiting', label: 'WAITING', sub: 'Sending to Symi\u2026' },
293
- thinking: { state: 'thinking', label: 'PROCESSING', sub: 'Reasoning through request' },
294
- streaming: { state: 'streaming', label: 'RESPONDING', sub: 'Generating response' },
295
- done: { state: 'done', label: 'COMPLETE', sub: 'Response ready' },
296
- error: { state: 'error', label: 'FAILED', sub: 'Run ended unexpectedly' },
297
- };
298
-
299
- function setAgentStatus(key) {
300
- if (!asoPanel) return;
301
-
302
- // Clear any pending auto-transition timers
303
- if (asoDoneTimer) { clearTimeout(asoDoneTimer); asoDoneTimer = null; }
304
-
305
- const s = ASO_STATES[key] || ASO_STATES.idle;
306
- asoPanel.dataset.state = s.state;
307
- if (asoLabel) asoLabel.textContent = s.label;
308
- if (asoSub) asoSub.textContent = s.sub;
309
-
310
- // ── Elapsed timer management ──────────────────────────────────
311
- if (key === 'thinking') {
312
- // Start elapsed timer and watchdog when processing begins
313
- armWatchdog();
314
- startElapsedTimer('Reasoning through request');
315
- } else if (key === 'streaming') {
316
- // Transition from thinking → streaming: keep watchdog running (will be
317
- // reset on each delta), switch elapsed timer base text
318
- elapsedBaseText = 'Generating response';
319
- } else {
320
- // Any terminal/non-active state: stop elapsed timer and watchdog
321
- stopElapsedTimer();
322
- clearWatchdog();
323
- }
324
-
325
- // ── Auto-revert timers ────────────────────────────────────────
326
- if (key === 'done') {
327
- asoDoneTimer = setTimeout(() => setAgentStatus('idle'), 3000);
328
- }
329
- if (key === 'error') {
330
- asoDoneTimer = setTimeout(() => setAgentStatus('idle'), 4000);
331
- }
332
- }
333
-
334
- // ── Input state ────────────────────────────────────────────────────
335
- function disableInput() {
336
- // Keep textarea enabled so user can type their next queued message while AI responds
337
- sendBtn.disabled = true;
338
- newSessionBtn.disabled = true;
339
- sendBtn.classList.add('btn-loading');
340
- }
341
-
342
- function enableInput() {
343
- sendBtn.disabled = false;
344
- newSessionBtn.disabled = false;
345
- sendBtn.classList.remove('btn-loading');
346
- promptInput.focus();
347
- }
348
-
349
- // ── Queue helpers ──────────────────────────────────────────────────
350
- const queueBtn = document.getElementById('queue-btn');
351
- const queueCancelX = document.getElementById('queue-cancel-x');
352
-
353
- function updateQueueBtn() {
354
- const streaming = isStreaming;
355
- const count = chatQueue.length;
356
-
357
- if (streaming || count > 0) {
358
- queueBtn.classList.add('visible');
359
- newSessionBtn.style.display = 'none';
360
-
361
- if (count > 0) {
362
- queueBtn.classList.add('has-queue');
363
- queueBtn.querySelector('.queue-btn-label').textContent = `Queued (${count})`;
364
- } else {
365
- queueBtn.classList.remove('has-queue');
366
- queueBtn.querySelector('.queue-btn-label').textContent = 'Queue ↵';
367
- }
368
- } else {
369
- queueBtn.classList.remove('visible', 'has-queue');
370
- newSessionBtn.style.display = '';
371
- }
372
- }
373
-
374
- function queueMessage(text) {
375
- if (!text.trim()) return;
376
- chatQueue = [...chatQueue, { id: Date.now(), text: text.trim() }];
377
- updateQueueBtn();
378
- }
379
-
380
- function clearQueue() {
381
- chatQueue = [];
382
- updateQueueBtn();
383
- }
384
-
385
- function drainQueue() {
386
- if (chatQueue.length === 0) {
387
- updateQueueBtn();
388
- return;
389
- }
390
- const [next, ...rest] = chatQueue;
391
- chatQueue = rest;
392
- updateQueueBtn();
393
- // Small delay so the UI settles before starting the next send
394
- setTimeout(() => sendText(next.text), 120);
395
- }
396
-
397
- // ── Core send (no input reading — accepts text directly) ───────────
398
- async function sendText(text) {
399
- if (!gateway.connected) return;
400
- isStreaming = true;
401
- disableInput();
402
- updateQueueBtn();
403
-
404
- addUserMessage(text);
405
- await sleep(200);
406
-
407
- setAgentStatus('waiting');
408
- thinkingEl = createThinkingBubble();
409
- setAgentStatus('thinking');
410
-
411
- try {
412
- await gateway.send(text);
413
- } catch (err) {
414
- handleRunFailure(err.message || 'Failed to send message');
415
- }
416
- }
417
-
418
- // ── Send handler (reads input, queues if busy) ─────────────────────
419
- async function handleSend() {
420
- const text = promptInput.value.trim();
421
- if (!text) return;
422
-
423
- // Clear the input immediately regardless of streaming state
424
- promptInput.value = '';
425
- promptInput.style.height = 'auto';
426
-
427
- if (isStreaming) {
428
- // AI is busy — queue it
429
- queueMessage(text);
430
- return;
431
- }
432
-
433
- if (!gateway.connected) return;
434
- await sendText(text);
435
- }
436
-
437
- // ── New Session handler ────────────────────────────────────────────
438
- async function handleNewSession() {
439
- if (isStreaming || !gateway.connected) return;
440
-
441
- promptInput.disabled = true; // lock textarea during reset
442
- disableInput();
443
- setAgentStatus('waiting');
444
-
445
- try {
446
- // Send the /new slash command — gateway resets the session
447
- await gateway.send('/new');
448
-
449
- // Fade out existing messages, then show cleared state
450
- responseArea.style.transition = 'opacity 0.25s ease';
451
- responseArea.style.opacity = '0';
452
-
453
- await sleep(260);
454
-
455
- responseArea.innerHTML = '';
456
- responseArea.style.opacity = '1';
457
-
458
- // Show empty-state indicator
459
- const cleared = document.createElement('div');
460
- cleared.className = 'session-cleared';
461
- cleared.innerHTML = `
462
- <div class="session-cleared-icon">◈</div>
463
- <div class="session-cleared-text">NEW SESSION STARTED</div>
464
- `;
465
- responseArea.appendChild(cleared);
466
-
467
- setAgentStatus('idle');
468
- clearQueue(); // discard any queued prompts — new session = clean slate
469
-
470
- // Show archive toast — lets user jump directly to history if they regret it
471
- if (typeof window.showArchiveToast === 'function') window.showArchiveToast();
472
-
473
- // After a short pause, remove the cleared indicator and let history load
474
- await sleep(1800);
475
- cleared.style.transition = 'opacity 0.4s ease';
476
- cleared.style.opacity = '0';
477
- await sleep(420);
478
- cleared.remove();
479
-
480
- } catch (err) {
481
- handleRunFailure(err.message || 'Failed to start new session');
482
- return;
483
- }
484
-
485
- promptInput.disabled = false; // re-enable textarea after reset
486
- enableInput();
487
- }
488
-
489
- sendBtn.addEventListener('click', handleSend);
490
- newSessionBtn.addEventListener('click', handleNewSession);
491
-
492
- // Queue button — queue current input (if idle text present) or show queued count
493
- queueBtn.addEventListener('click', e => {
494
- // Cancel X — clears the queue
495
- if (e.target === queueCancelX || queueCancelX.contains(e.target)) {
496
- clearQueue();
497
- return;
498
- }
499
- // Main button click — queue the current input if no item queued yet
500
- if (chatQueue.length === 0) {
501
- const text = promptInput.value.trim();
502
- if (text) {
503
- promptInput.value = '';
504
- promptInput.style.height = 'auto';
505
- queueMessage(text);
506
- }
507
- }
508
- });
509
- promptInput.addEventListener('keydown', e => {
510
- if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); }
511
- });
512
-
513
- // ── Textarea auto-resize (up to 3 lines) ──────────────────────────
514
- function autoResizePrompt() {
515
- promptInput.style.height = 'auto';
516
- promptInput.style.height = promptInput.scrollHeight + 'px';
517
- }
518
-
519
- promptInput.addEventListener('input', autoResizePrompt);
520
-
521
- // Clicking anywhere on the prompt bar (padding, icon, gaps) focuses the input
522
- // Click anywhere on the main input row (not buttons) focuses the input
523
- document.getElementById('prompt-bar').addEventListener('click', e => {
524
- const inSend = sendBtn.contains(e.target) || e.target === sendBtn;
525
- const inNewSession = newSessionBtn.contains(e.target) || e.target === newSessionBtn;
526
- const inHistory = document.getElementById('history-btn').contains(e.target);
527
- const inQueue = queueBtn.contains(e.target);
528
- // Only focus if clicking in the main row area (not the actions row)
529
- const inActionsRow = e.target.closest('.prompt-row-actions');
530
- if (!inSend && !inNewSession && !inHistory && !inQueue && !inActionsRow) {
531
- promptInput.focus();
532
- }
533
- });
534
-
535
- // ── Gateway setup ──────────────────────────────────────────────────
536
- const gateway = new SymiGateway();
537
-
538
- gateway.addEventListener('connect', () => {
539
- setStatus('online');
540
- enableInput();
541
- // History arrives via separate 'history' event pushed by the server
542
- });
543
-
544
- gateway.addEventListener('history', (e) => {
545
- const msgs = Array.isArray(e.detail?.messages) ? e.detail.messages : [];
546
- renderHistory(msgs);
547
- });
548
-
549
- gateway.addEventListener('disconnect', () => {
550
- setStatus('offline');
551
- // If the gateway drops while a run is in progress, surface the failure
552
- // immediately rather than leaving the UI in a permanently locked state.
553
- if (isStreaming) {
554
- handleRunFailure('disconnected');
555
- }
556
- });
557
-
558
- gateway.addEventListener('event', (e) => {
559
- handleGatewayEvent(e.detail);
560
- });
561
-
562
- // Start connecting
563
- disableInput();
564
- gateway.start();