agentgui 1.0.930 → 1.0.932

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 (128) hide show
  1. package/AGENTS.md +35 -12
  2. package/database.js +31 -2
  3. package/lib/http-handler.js +11 -25
  4. package/lib/routes-registry.js +4 -48
  5. package/lib/server-startup.js +3 -11
  6. package/lib/ws-setup.js +2 -1
  7. package/package.json +3 -3
  8. package/server.js +7 -1
  9. package/site/app/js/app.js +64 -68
  10. package/site/app/js/backend.js +1 -1
  11. package/static/lib/xstate.umd.min.js +1 -1
  12. package/lib/db-queries-chunks.js +0 -195
  13. package/lib/db-queries-chunks2.js +0 -82
  14. package/lib/db-queries-cleanup.js +0 -74
  15. package/lib/db-queries-del.js +0 -141
  16. package/lib/db-queries-events.js +0 -68
  17. package/lib/db-queries-import.js +0 -133
  18. package/lib/db-queries-messages.js +0 -102
  19. package/lib/db-queries-sessions.js +0 -112
  20. package/lib/db-queries-streams.js +0 -100
  21. package/lib/db-queries.js +0 -89
  22. package/lib/jsonl-parser.js +0 -190
  23. package/lib/jsonl-watcher.js +0 -64
  24. package/lib/routes-agent-actions.js +0 -61
  25. package/lib/routes-auth-config.js +0 -30
  26. package/lib/routes-conversations.js +0 -96
  27. package/lib/routes-debug.js +0 -119
  28. package/lib/routes-messages.js +0 -139
  29. package/lib/routes-runs.js +0 -156
  30. package/lib/routes-scripts.js +0 -135
  31. package/lib/routes-sessions.js +0 -144
  32. package/lib/routes-threads.js +0 -100
  33. package/lib/routes-util.js +0 -110
  34. package/lib/ws-handlers-conv.js +0 -138
  35. package/lib/ws-handlers-conv2.js +0 -169
  36. package/lib/ws-handlers-msg.js +0 -121
  37. package/lib/ws-handlers-queue.js +0 -56
  38. package/lib/ws-handlers-run.js +0 -182
  39. package/lib/ws-handlers-scripts.js +0 -66
  40. package/lib/ws-handlers-session.js +0 -105
  41. package/lib/ws-handlers-session2.js +0 -85
  42. package/lib/ws-legacy-handlers.js +0 -51
  43. package/static/app.js +0 -261
  44. package/static/css/app-shell.css +0 -419
  45. package/static/css/brand-bible.css +0 -591
  46. package/static/css/colors_and_type.css +0 -568
  47. package/static/css/gmail-skin.css +0 -663
  48. package/static/css/main.css +0 -4015
  49. package/static/css/tools-popup.css +0 -472
  50. package/static/index.html +0 -418
  51. package/static/js/agent-auth.js +0 -146
  52. package/static/js/app-shortcuts.js +0 -30
  53. package/static/js/audio-recorder-processor.js +0 -18
  54. package/static/js/client-agents.js +0 -155
  55. package/static/js/client-cache.js +0 -171
  56. package/static/js/client-conv.js +0 -198
  57. package/static/js/client-events.js +0 -164
  58. package/static/js/client-exec.js +0 -160
  59. package/static/js/client-helpers.js +0 -199
  60. package/static/js/client-load.js +0 -175
  61. package/static/js/client-render.js +0 -132
  62. package/static/js/client-scroll.js +0 -178
  63. package/static/js/client-status.js +0 -167
  64. package/static/js/client-streaming.js +0 -117
  65. package/static/js/client-streaming2.js +0 -116
  66. package/static/js/client-streaming3.js +0 -153
  67. package/static/js/client-streaming4.js +0 -194
  68. package/static/js/client-ui-controls.js +0 -170
  69. package/static/js/client-ui.js +0 -128
  70. package/static/js/client-ui2.js +0 -160
  71. package/static/js/client-url.js +0 -93
  72. package/static/js/client-utils.js +0 -174
  73. package/static/js/client-ws-msg.js +0 -88
  74. package/static/js/client-ws.js +0 -161
  75. package/static/js/client.js +0 -145
  76. package/static/js/codec.js +0 -4
  77. package/static/js/conv-list-machine.js +0 -145
  78. package/static/js/conv-list-renderer.js +0 -198
  79. package/static/js/conv-machine.js +0 -110
  80. package/static/js/conv-sidebar-actions.js +0 -188
  81. package/static/js/conv-sidebar-clone.js +0 -91
  82. package/static/js/conversations.js +0 -116
  83. package/static/js/dialogs-types.js +0 -111
  84. package/static/js/dialogs.js +0 -53
  85. package/static/js/event-filter-config.js +0 -36
  86. package/static/js/event-processor.js +0 -181
  87. package/static/js/features.js +0 -187
  88. package/static/js/image-loader-element.js +0 -76
  89. package/static/js/image-loader.js +0 -146
  90. package/static/js/prompt-machine.js +0 -108
  91. package/static/js/recording-machine.js +0 -49
  92. package/static/js/script-runner.js +0 -192
  93. package/static/js/state-barrier.js +0 -105
  94. package/static/js/streaming-renderer-dispatch.js +0 -144
  95. package/static/js/streaming-renderer-events.js +0 -163
  96. package/static/js/streaming-renderer-events2.js +0 -125
  97. package/static/js/streaming-renderer-params.js +0 -38
  98. package/static/js/streaming-renderer-render-misc.js +0 -107
  99. package/static/js/streaming-renderer-render.js +0 -181
  100. package/static/js/streaming-renderer-render2.js +0 -149
  101. package/static/js/streaming-renderer-render3.js +0 -142
  102. package/static/js/streaming-renderer-static.js +0 -181
  103. package/static/js/streaming-renderer-static2.js +0 -140
  104. package/static/js/streaming-renderer-stream.js +0 -170
  105. package/static/js/streaming-renderer-text.js +0 -185
  106. package/static/js/streaming-renderer-tools.js +0 -189
  107. package/static/js/streaming-renderer-tools2.js +0 -92
  108. package/static/js/streaming-renderer.js +0 -200
  109. package/static/js/syntax-highlighter-render.js +0 -72
  110. package/static/js/syntax-highlighter.js +0 -131
  111. package/static/js/terminal-machine.js +0 -51
  112. package/static/js/terminal.js +0 -178
  113. package/static/js/ui-components-rendering.js +0 -62
  114. package/static/js/ui-components.js +0 -88
  115. package/static/js/websocket-manager.js +0 -107
  116. package/static/js/ws-client.js +0 -87
  117. package/static/js/ws-core.js +0 -162
  118. package/static/js/ws-latency.js +0 -88
  119. package/static/js/ws-machine.js +0 -68
  120. package/static/lib/msgpackr.min.js +0 -2
  121. package/static/theme.js +0 -74
  122. package/static/vendor/highlight-js.css +0 -10
  123. package/static/vendor/highlight.min.js +0 -1244
  124. package/static/vendor/prism-dark.css +0 -129
  125. package/static/vendor/rippleui.css +0 -35
  126. package/static/vendor/xterm-addon-fit.min.js +0 -8
  127. package/static/vendor/xterm.css +0 -8
  128. package/static/vendor/xterm.min.js +0 -8
@@ -1,160 +0,0 @@
1
- Object.assign(AgentGUIClient.prototype, {
2
- _showWelcomeScreen() {
3
- const outputEl = document.getElementById('output');
4
- if (!outputEl) return;
5
- const agents = this.state.agents || [];
6
- const agentOptions = agents.map(a =>
7
- `<option value="${this.escapeHtml(a.id)}">${this.escapeHtml(a.name.split(/[\s\-]+/)[0])}</option>`
8
- ).join('');
9
- const agentList = agents.length > 0 ? agents.map(a => a.name.split(/[\s\-]+/)[0].toLowerCase()).join(', ') : 'claude, gemini, opencode, kilo, codex';
10
- outputEl.innerHTML = `
11
- <div class="welcome-pane">
12
- <div class="welcome-head">
13
- <div class="t-micro">247420 / agentgui / welcome</div>
14
- <h1 class="welcome-title">a state machine for coding agents.</h1>
15
- <p class="welcome-lede">start a new conversation or pick one from the sidebar. pick your agent and model below.</p>
16
- </div>
17
- ${agents.length > 0 ? `
18
- <div class="welcome-select-row">
19
- <span class="t-label mono-dim">select agent</span>
20
- <select id="welcomeAgentSelect" class="input">${agentOptions}</select>
21
- </div>` : ''}
22
- <div class="welcome-rows">
23
- <div class="row">
24
- <span class="row-code">01</span>
25
- <span class="row-title">new conversation</span>
26
- <span class="row-meta">create a new chat with any agent</span>
27
- </div>
28
- <div class="row">
29
- <span class="row-code">02</span>
30
- <span class="row-title">available agents</span>
31
- <span class="row-meta">${this.escapeHtml(agentList)}</span>
32
- </div>
33
- </div>
34
- </div>
35
- `;
36
- const welcomeSel = document.getElementById('welcomeAgentSelect');
37
- if (welcomeSel) {
38
- if (this.ui.cliSelector) welcomeSel.value = this.ui.cliSelector.value;
39
- welcomeSel.addEventListener('change', () => {
40
- if (this.ui.cliSelector) {
41
- this.ui.cliSelector.value = welcomeSel.value;
42
- this.ui.cliSelector.dispatchEvent(new Event('change'));
43
- }
44
- });
45
- }
46
- },
47
-
48
-
49
- _showSkeletonLoading(conversationId) {
50
- const outputEl = document.getElementById('output');
51
- if (!outputEl) return;
52
- const conv = this.state.conversations.find(c => c.id === conversationId);
53
- const title = conv?.title || 'Conversation';
54
- const wdInfo = conv?.workingDirectory ? `${this.escapeHtml(conv.workingDirectory)}` : '';
55
- const timestamp = conv ? new Date(conv.created_at).toLocaleDateString() : '';
56
- const metaParts = [timestamp];
57
- if (wdInfo) metaParts.push(wdInfo);
58
- outputEl.innerHTML = `
59
- <div class="conversation-header">
60
- <h2>${this.escapeHtml(title)}</h2>
61
- <p class="text-secondary">${metaParts.join(' - ')}</p>
62
- </div>
63
- <div class="conversation-messages">
64
- <div class="skeleton-loading">
65
- <div class="skeleton-block skeleton-pulse" style="height:3rem;margin-bottom:0.75rem;border-radius:0.5rem;background:var(--color-bg-secondary);"></div>
66
- <div class="skeleton-block skeleton-pulse" style="height:6rem;margin-bottom:0.75rem;border-radius:0.5rem;background:var(--color-bg-secondary);"></div>
67
- <div class="skeleton-block skeleton-pulse" style="height:2rem;margin-bottom:0.75rem;border-radius:0.5rem;background:var(--color-bg-secondary);"></div>
68
- <div class="skeleton-block skeleton-pulse" style="height:5rem;margin-bottom:0.75rem;border-radius:0.5rem;background:var(--color-bg-secondary);"></div>
69
- </div>
70
- </div>
71
- `;
72
- },
73
-
74
-
75
- async streamToConversation(conversationId, prompt, agentId, model, subAgent) {
76
- try {
77
- if (this.wsManager.isConnected) {
78
- this.wsManager.sendMessage({ type: 'subscribe', conversationId });
79
- }
80
-
81
- let finalPrompt = prompt;
82
- const streamBody = { id: conversationId, content: finalPrompt, agentId };
83
- if (model) streamBody.model = model;
84
- if (subAgent) streamBody.subAgent = subAgent;
85
- let result;
86
- try {
87
- result = await window.wsClient.rpc('msg.stream', streamBody);
88
- } catch (e) {
89
- if (e.code === 404) {
90
- console.warn('Conversation not found, recreating:', conversationId);
91
- const conv = this.state.currentConversation;
92
- const createBody = { agentId, title: conv?.title || prompt.substring(0, 50), workingDirectory: conv?.workingDirectory || null };
93
- if (model) createBody.model = model;
94
- if (subAgent) createBody.subAgent = subAgent;
95
- const { conversation: newConv } = await window.wsClient.rpc('conv.new', createBody);
96
- window.ConversationState?.selectConversation(newConv.id, 'stream_recreate', 1);
97
- this.state.currentConversation = newConv;
98
- if (window.conversationManager) {
99
- window.conversationManager.loadConversations();
100
- window.conversationManager.select(newConv.id);
101
- }
102
- this.updateUrlForConversation(newConv.id);
103
- return this.streamToConversation(newConv.id, prompt, agentId, model, subAgent);
104
- }
105
- throw e;
106
- }
107
-
108
- if (result.queued) {
109
- this._dbg('Message queued, position:', result.queuePosition);
110
- this.enableControls();
111
- return;
112
- }
113
-
114
- if (result.session && this.wsManager.isConnected) {
115
- this.wsManager.subscribeToSession(result.session.id);
116
- }
117
-
118
- this._lastSendTime = Date.now();
119
- this.emit('execution:started', result);
120
- } catch (error) {
121
- console.error('Stream execution error:', error);
122
- this.showError('Failed to stream execution: ' + error.message);
123
- this.enableControls();
124
- }
125
- },
126
-
127
-
128
- _hydrateSessionBlocks(blocksEl, list) {
129
- const blockFrag = document.createDocumentFragment();
130
- const deferred = [];
131
- for (const chunk of list) {
132
- if (!chunk.block?.type) continue;
133
- const bt = chunk.block.type;
134
- if (bt === 'tool_result' || bt === 'tool_status' || bt === 'hook_progress') { deferred.push(chunk); continue; }
135
- const el = this.renderer.renderBlock(chunk.block, chunk, blockFrag);
136
- if (!el) continue;
137
- el.classList.add('block-loaded');
138
- blockFrag.appendChild(el);
139
- }
140
- blocksEl.appendChild(blockFrag);
141
- const toolUseIndex = new Map();
142
- blocksEl.querySelectorAll('.block-tool-use[data-tool-use-id]').forEach(el => toolUseIndex.set(el.dataset.toolUseId, el));
143
- for (const chunk of deferred) {
144
- const b = chunk.block;
145
- if (b.type === 'tool_result') {
146
- const toolUseEl = (b.tool_use_id && toolUseIndex.get(b.tool_use_id))
147
- || (blocksEl.lastElementChild?.classList.contains('block-tool-use') ? blocksEl.lastElementChild : null);
148
- if (toolUseEl) this.renderer.mergeResultIntoToolUse(toolUseEl, b);
149
- } else if (b.type === 'tool_status') {
150
- const toolUseEl = b.tool_use_id && toolUseIndex.get(b.tool_use_id);
151
- if (toolUseEl) {
152
- const isError = b.status === 'failed';
153
- const isDone = b.status === 'completed';
154
- if (isDone || isError) toolUseEl.classList.add(isError ? 'tool-result-error' : 'tool-result-success');
155
- }
156
- }
157
- }
158
- }
159
-
160
- });
@@ -1,93 +0,0 @@
1
- Object.assign(AgentGUIClient.prototype, {
2
- updateUrlForConversation(conversationId, sessionId) {
3
- if (!this.isValidId(conversationId)) return;
4
- if (!this.routerState) return;
5
-
6
- this.routerState.currentConversationId = conversationId;
7
- if (sessionId && this.isValidId(sessionId)) {
8
- this.routerState.currentSessionId = sessionId;
9
- }
10
-
11
- const basePath = window.location.pathname.replace(/\/conversations\/[^\/]+$/, '').replace(/\/$/, '');
12
- let url = `${basePath}/conversations/${conversationId}`;
13
-
14
- if (sessionId && this.isValidId(sessionId)) {
15
- url += `?session=${sessionId}`;
16
- }
17
-
18
- window.history.pushState({ conversationId, sessionId }, '', url);
19
- },
20
-
21
-
22
- saveScrollPosition(conversationId) {
23
- if (!this.isValidId(conversationId)) return;
24
-
25
- const scrollContainer = document.getElementById(this.config.scrollContainerId);
26
- if (scrollContainer) {
27
- const position = scrollContainer.scrollTop;
28
- try {
29
- localStorage.setItem(`scroll_${conversationId}`, position.toString());
30
- } catch (e) {
31
- console.warn('Failed to save scroll position:', e);
32
- }
33
- }
34
- },
35
-
36
-
37
- restoreScrollPosition(conversationId) {
38
- if (!this.isValidId(conversationId)) return;
39
-
40
- try {
41
- const position = localStorage.getItem(`scroll_${conversationId}`);
42
- const scrollContainer = document.getElementById(this.config.scrollContainerId);
43
- if (!scrollContainer) return;
44
-
45
- if (position !== null) {
46
- const scrollTop = parseInt(position, 10);
47
- if (!isNaN(scrollTop)) {
48
- requestAnimationFrame(() => {
49
- requestAnimationFrame(() => {
50
- const maxScroll = scrollContainer.scrollHeight - scrollContainer.clientHeight;
51
- scrollContainer.scrollTop = Math.min(scrollTop, maxScroll);
52
- });
53
- });
54
- }
55
- } else {
56
- requestAnimationFrame(() => {
57
- requestAnimationFrame(() => {
58
- scrollContainer.scrollTop = 0;
59
- });
60
- });
61
- }
62
- } catch (e) {
63
- console.warn('Failed to restore scroll position:', e);
64
- }
65
- },
66
-
67
-
68
- setupScrollTracking() {
69
- const scrollContainer = document.getElementById(this.config.scrollContainerId);
70
- if (!scrollContainer) return;
71
-
72
- this._userScrolledUp = false;
73
- let scrollTimer = null;
74
- let lastScrollTop = scrollContainer.scrollTop;
75
- scrollContainer.addEventListener('scroll', () => {
76
- const distFromBottom = scrollContainer.scrollHeight - scrollContainer.scrollTop - scrollContainer.clientHeight;
77
- if (scrollContainer.scrollTop < lastScrollTop && distFromBottom > 200) {
78
- this._userScrolledUp = true;
79
- } else if (distFromBottom < 50) {
80
- this._userScrolledUp = false;
81
- this._removeNewContentPill();
82
- }
83
- lastScrollTop = scrollContainer.scrollTop;
84
- if (scrollTimer) clearTimeout(scrollTimer);
85
- scrollTimer = setTimeout(() => {
86
- if (this.state.currentConversation?.id) {
87
- this.saveScrollPosition(this.state.currentConversation.id);
88
- }
89
- }, 500);
90
- });
91
- }
92
-
93
- });
@@ -1,174 +0,0 @@
1
- Object.assign(AgentGUIClient.prototype, {
2
- renderMessages(messages) {
3
- if (messages.length === 0) {
4
- return '<p class="text-secondary">No messages in this conversation yet</p>';
5
- }
6
- return messages.map(msg => `<div class="message message-${msg.role}"><div class="message-role">${msg.role.charAt(0).toUpperCase() + msg.role.slice(1)}</div>${this.renderMessageContent(msg.content)}<div class="message-timestamp">${new Date(msg.created_at).toLocaleString()}</div></div>`).join('');
7
- },
8
-
9
-
10
- escapeHtml(text) {
11
- return window._escHtml(text);
12
- },
13
-
14
-
15
- showError(message) {
16
- console.error(message);
17
- if (window.UIDialog) {
18
- window.UIDialog.alert(message, 'Error');
19
- }
20
- },
21
-
22
-
23
- on(event, callback) {
24
- if (!this.eventHandlers[event]) {
25
- this.eventHandlers[event] = [];
26
- }
27
- this.eventHandlers[event].push(callback);
28
- },
29
-
30
-
31
- emit(event, data) {
32
- if (this.eventHandlers[event]) {
33
- this.eventHandlers[event].forEach(callback => {
34
- try {
35
- callback(data);
36
- } catch (error) {
37
- console.error(`Event handler error for ${event}:`, error);
38
- }
39
- });
40
- }
41
- },
42
-
43
-
44
- getEffectiveAgentId() {
45
- return this.ui.cliSelector?.value || null;
46
- },
47
-
48
-
49
- getEffectiveSubAgent() {
50
- if (this.ui.agentSelector?.value && this.ui.agentSelector.style.display !== 'none') {
51
- return this.ui.agentSelector.value;
52
- }
53
- return null;
54
- },
55
-
56
-
57
- getCurrentAgent() {
58
- return this.getEffectiveAgentId();
59
- },
60
-
61
-
62
- saveAgentAndModelToConversation() {
63
- const convId = this.state.currentConversation?.id;
64
- if (!convId || this._agentLocked) return;
65
- const agentId = this.getEffectiveAgentId();
66
- const subAgent = this.getEffectiveSubAgent();
67
- const model = this.getCurrentModel();
68
- window.wsClient.rpc('conv.upd', { id: convId, agentType: agentId, subAgent: subAgent || undefined, model: model || undefined }).catch(() => {});
69
- },
70
-
71
-
72
- getCurrentModel() {
73
- return this.ui.modelSelector?.value || null;
74
- },
75
-
76
-
77
- getMetrics() {
78
- return {
79
- renderer: this.renderer.getMetrics(),
80
- websocket: this.wsManager.getStatus(),
81
- eventProcessor: this.eventProcessor.getStats(),
82
- state: this.state
83
- };
84
- },
85
-
86
-
87
- saveDraftPrompt() {
88
- const convId = this.state.currentConversation?.id;
89
- if (convId && this.ui.messageInput) {
90
- const draft = this.ui.messageInput.value;
91
- this.draftPrompts.set(convId, draft);
92
- if (draft) {
93
- localStorage.setItem(`draft-${convId}`, draft);
94
- }
95
- }
96
- },
97
-
98
-
99
- restoreDraftPrompt(conversationId) {
100
- if (!this.ui.messageInput) return;
101
-
102
- let draft = this.draftPrompts.get(conversationId) || '';
103
- if (!draft) {
104
- draft = localStorage.getItem(`draft-${conversationId}`) || '';
105
- if (draft) this.draftPrompts.set(conversationId, draft);
106
- }
107
-
108
- this.ui.messageInput.value = draft;
109
- },
110
-
111
-
112
- clearDraft(conversationId) {
113
- this.draftPrompts.delete(conversationId);
114
- localStorage.removeItem(`draft-${conversationId}`);
115
- },
116
-
117
-
118
- updateSendButtonState() {
119
- if (this.ui.sendButton) {
120
- this.ui.sendButton.disabled = !this.wsManager.isConnected;
121
- }
122
- if (this.ui.injectButton && this.ui.injectButton.classList.contains('visible')) {
123
- this.ui.injectButton.disabled = !this.wsManager.isConnected;
124
- }
125
- if (this.ui.queueButton && this.ui.queueButton.classList.contains('visible')) {
126
- this.ui.queueButton.disabled = !this.wsManager.isConnected;
127
- }
128
- },
129
-
130
-
131
- disablePromptArea() {
132
- },
133
-
134
-
135
- enablePromptArea() {
136
- if (this.ui.messageInput) {
137
- this.ui.messageInput.disabled = false;
138
- }
139
- const injectBtn = document.getElementById('injectBtn');
140
- if (injectBtn) injectBtn.disabled = false;
141
- },
142
-
143
-
144
- showStreamingPromptButtons() {
145
- if (this.ui.injectButton) {
146
- this.ui.injectButton.classList.add('visible');
147
- this.ui.injectButton.disabled = !this.wsManager.isConnected;
148
- }
149
- if (this.ui.queueButton) {
150
- this.ui.queueButton.classList.add('visible');
151
- this.ui.queueButton.disabled = !this.wsManager.isConnected;
152
- }
153
- },
154
-
155
-
156
- ensurePromptAreaAlwaysEnabled() {
157
- if (this.ui.messageInput) {
158
- this.ui.messageInput.disabled = false;
159
- }
160
- },
161
-
162
-
163
- destroy() {
164
-
165
- this.renderer.destroy();
166
- this.wsManager.destroy();
167
- this.eventHandlers = {};
168
- }
169
- });
170
-
171
- window.__convPerfMetrics = () => {
172
- const entries = performance.getEntriesByType('measure').filter(e => e.name.startsWith('conv-'));
173
- return entries.map(e => ({ name: e.name, ms: Math.round(e.duration) }));
174
- };
@@ -1,88 +0,0 @@
1
- Object.assign(AgentGUIClient.prototype, {
2
- async connectWebSocket() {
3
- try {
4
- await this.wsManager.connect();
5
- this.updateConnectionStatus('connected');
6
- } catch (error) {
7
- console.error('WebSocket connection failed:', error);
8
- this.updateConnectionStatus('error');
9
- throw error;
10
- }
11
- },
12
-
13
-
14
- handleWebSocketMessage(data) {
15
- try {
16
- window.dispatchEvent(new CustomEvent('ws-message', { detail: data }));
17
-
18
- switch (data.type) {
19
- case 'streaming_start':
20
- this.handleStreamingStart(data).catch(e => console.error('handleStreamingStart error:', e));
21
- break;
22
- case 'streaming_resumed':
23
- this.handleStreamingResumed(data).catch(e => console.error('handleStreamingResumed error:', e));
24
- break;
25
- case 'streaming_progress':
26
- this.handleStreamingProgress(data);
27
- break;
28
- case 'streaming_complete':
29
- this.handleStreamingComplete(data);
30
- break;
31
- case 'streaming_error':
32
- this.handleStreamingError(data);
33
- break;
34
- case 'conversation_created':
35
- this.handleConversationCreated(data);
36
- break;
37
- case 'all_conversations_deleted':
38
- this.handleAllConversationsDeleted(data);
39
- break;
40
- case 'message_created':
41
- this.handleMessageCreated(data);
42
- break;
43
- case 'conversation_updated':
44
- this.handleConversationUpdated(data);
45
- break;
46
- case 'queue_status':
47
- this.handleQueueStatus(data);
48
- break;
49
- case 'queue_updated':
50
- this.handleQueueUpdated(data);
51
- break;
52
- case 'queue_item_dequeued':
53
- this.handleQueueItemDequeued(data);
54
- break;
55
- case 'rate_limit_hit':
56
- this.handleRateLimitHit(data);
57
- break;
58
- case 'rate_limit_clear':
59
- this.handleRateLimitClear(data);
60
- break;
61
- case 'model_download_progress':
62
- this._handleModelDownloadProgress(data.progress || data);
63
- break;
64
- case 'tts_setup_progress':
65
- this._handleTTSSetupProgress(data);
66
- break;
67
- default:
68
- break;
69
- }
70
- } catch (error) {
71
- console.error('Message handling error:', error);
72
- }
73
- },
74
-
75
-
76
- queueEvent(data) {
77
- try {
78
- const processed = this.eventProcessor.processEvent(data);
79
- if (!processed) return;
80
- if (data.sessionId && this.state.currentSession?.id === data.sessionId) {
81
- this.state.sessionEvents.push(processed);
82
- }
83
- } catch (error) {
84
- console.error('Event queuing error:', error);
85
- }
86
- }
87
-
88
- });
@@ -1,161 +0,0 @@
1
- Object.assign(AgentGUIClient.prototype, {
2
- setupWebSocketListeners() {
3
- this.wsManager.on('connected', () => {
4
- this._dbg('WebSocket connected');
5
- this.updateConnectionStatus('connected');
6
- this._subscribeToConversationUpdates();
7
- if (this.wsManager.stats.totalReconnects > 0 && this.state.currentConversation?.id) {
8
- this.invalidateCache(this.state.currentConversation.id);
9
- }
10
- this._recoverMissedChunks();
11
- this.updateSendButtonState();
12
- this.enablePromptArea();
13
- if (this.state.currentConversation?.id) {
14
- this.updateBusyPromptArea(this.state.currentConversation.id);
15
- }
16
- this.emit('ws:connected');
17
- if (window.__SERVER_VERSION) {
18
- fetch((window.__BASE_URL || '') + '/api/version').then(r => r.json()).then(d => {
19
- if (d.version && d.version !== window.__SERVER_VERSION) {
20
- this._dbg(`Server updated ${window.__SERVER_VERSION} → ${d.version}, reloading`);
21
- window.location.reload();
22
- }
23
- }).catch(() => {});
24
- }
25
- });
26
-
27
- this.wsManager.on('disconnected', () => {
28
- this._dbg('WebSocket disconnected');
29
- this.updateConnectionStatus('disconnected');
30
- this.updateSendButtonState();
31
- this.disablePromptArea();
32
- this.emit('ws:disconnected');
33
- });
34
-
35
- this.wsManager.on('reconnecting', (data) => {
36
- this._dbg('WebSocket reconnecting:', data);
37
- this.updateConnectionStatus('reconnecting');
38
- });
39
-
40
- this.wsManager.on('message', (data) => {
41
- this.handleWebSocketMessage(data);
42
- });
43
-
44
- this.wsManager.on('error', (data) => {
45
- console.error('WebSocket error:', data);
46
- });
47
-
48
- this.wsManager.on('latency_update', (data) => {
49
- this._updateConnectionIndicator(data.quality);
50
- });
51
-
52
- this.wsManager.on('connection_degrading', () => {
53
- const dot = document.querySelector('.connection-dot');
54
- if (dot) dot.classList.add('degrading');
55
- });
56
-
57
- this.wsManager.on('connection_recovering', () => {
58
- const dot = document.querySelector('.connection-dot');
59
- if (dot) dot.classList.remove('degrading');
60
- });
61
-
62
- window.addEventListener('conversation-selected', (e) => {
63
- const convId = e.detail.conversationId;
64
- this.saveDraftPrompt();
65
-
66
- const isStreaming = this._convIsStreaming(convId);
67
- if (!isStreaming && window.switchView) {
68
- window.switchView('chat');
69
- }
70
-
71
- this.restoreDraftPrompt(convId);
72
- });
73
-
74
- window.addEventListener('view-switched', (e) => {
75
- const view = e.detail.view;
76
- if (view === 'chat') {
77
- const convId = this.state.currentConversation?.id;
78
- const isStreaming = this._convIsStreaming(convId);
79
- if (isStreaming) {
80
- this.disableControls();
81
- } else {
82
- this.enableControls();
83
- }
84
- }
85
- });
86
- },
87
-
88
-
89
- _convIsStreaming(convId) {
90
- if (!convId) return false;
91
- if (typeof convMachineAPI !== 'undefined') return convMachineAPI.isStreaming(convId);
92
- return this.state.streamingConversations.has(convId);
93
- },
94
-
95
-
96
- _setConvStreaming(convId, streaming, sessionId, agentId) {
97
- if (!convId) return;
98
- if (streaming) {
99
- this.state.streamingConversations.set(convId, true);
100
- if (typeof convMachineAPI !== 'undefined') convMachineAPI.send(convId, { type: 'STREAM_START', sessionId, agentId });
101
- } else {
102
- this.state.streamingConversations.delete(convId);
103
- if (typeof convMachineAPI !== 'undefined') convMachineAPI.send(convId, { type: 'COMPLETE' });
104
- }
105
- },
106
-
107
-
108
- setupRendererListeners() {
109
- this.renderer.on('batch:complete', (data) => {
110
- this._dbg('Batch rendered:', data);
111
- this.updateMetrics(data.metrics);
112
- });
113
-
114
- this.renderer.on('error:render', (data) => {
115
- console.error('Render error:', data.error);
116
- });
117
- },
118
-
119
-
120
- restoreStateFromUrl() {
121
- const pathMatch = window.location.pathname.match(/\/conversations\/([^\/]+)$/);
122
- const conversationId = pathMatch ? pathMatch[1] : null;
123
-
124
- const params = new URLSearchParams(window.location.search);
125
- const sessionId = params.get('session');
126
-
127
- if (conversationId && this.isValidId(conversationId)) {
128
- this.routerState.currentConversationId = conversationId;
129
- if (sessionId && this.isValidId(sessionId)) {
130
- this.routerState.currentSessionId = sessionId;
131
- }
132
- this._dbg('Restoring conversation from URL:', conversationId);
133
- this._isLoadingConversation = true;
134
- if (window.conversationManager) {
135
- window.conversationManager.select(conversationId);
136
- } else {
137
- this.loadConversationMessages(conversationId).catch((err) => {
138
- console.warn('Failed to restore conversation from URL, loading latest instead:', err);
139
- if (this.state.conversations && this.state.conversations.length > 0) {
140
- const latestConv = this.state.conversations[0];
141
- this._dbg('Loading latest conversation instead:', latestConv.id);
142
- return this.loadConversationMessages(latestConv.id);
143
- } else {
144
- this._showWelcomeScreen();
145
- }
146
- }).finally(() => {
147
- this._isLoadingConversation = false;
148
- });
149
- }
150
- } else {
151
- this._showWelcomeScreen();
152
- }
153
- },
154
-
155
-
156
- isValidId(id) {
157
- if (!id || typeof id !== 'string') return false;
158
- return /^[a-zA-Z0-9_-]+$/.test(id) && id.length < 256;
159
- }
160
-
161
- });