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,49 +0,0 @@
1
- (function() {
2
- const { createMachine, createActor, assign } = XState;
3
-
4
- const recordingMachine = createMachine({
5
- id: 'recording',
6
- initial: 'idle',
7
- context: {
8
- error: null,
9
- },
10
- states: {
11
- idle: {
12
- entry: assign({ error: null }),
13
- on: {
14
- START: { target: 'recording' },
15
- },
16
- },
17
- recording: {
18
- on: {
19
- STOP: { target: 'processing' },
20
- ERROR: {
21
- target: 'idle',
22
- actions: assign(({ event }) => ({ error: event.error || 'Recording failed' })),
23
- },
24
- },
25
- },
26
- processing: {
27
- on: {
28
- COMPLETE: { target: 'idle' },
29
- ERROR: {
30
- target: 'idle',
31
- actions: assign(({ event }) => ({ error: event.error || 'Processing failed' })),
32
- },
33
- },
34
- },
35
- },
36
- });
37
-
38
- const actor = createActor(recordingMachine);
39
- actor.start();
40
-
41
- window.recordingMachineAPI = {
42
- send: function(event) { actor.send(event); },
43
- getState: function() { return actor.getSnapshot().value; },
44
- isRecording: function() { return actor.getSnapshot().value === 'recording'; },
45
- isProcessing: function() { return actor.getSnapshot().value === 'processing'; },
46
- subscribe: function(fn) { return actor.subscribe(fn); },
47
- };
48
- window.__recordingMachine = actor;
49
- })();
@@ -1,192 +0,0 @@
1
- (function() {
2
- let currentConversationId = null;
3
- let currentWorkingDirectory = null;
4
- let scriptState = { running: false, script: null, hasStart: false, hasDev: false };
5
- let hasTerminalContent = false;
6
-
7
- function init() {
8
- setupListeners();
9
- setupButtons();
10
- }
11
-
12
- function setupListeners() {
13
- window.addEventListener('conversation-selected', function(e) {
14
- currentConversationId = e.detail.conversationId;
15
- hasTerminalContent = false;
16
- fetchConversationAndCheckScripts();
17
- });
18
-
19
- window.addEventListener('ws-message', function(e) {
20
- const data = e.detail;
21
- if (!data || !currentConversationId) return;
22
- if (data.conversationId !== currentConversationId) return;
23
-
24
- const term = getTerminal();
25
-
26
- if (data.type === 'script_started') {
27
- scriptState.running = true;
28
- scriptState.script = data.script;
29
- hasTerminalContent = false;
30
- if (term) term.clear();
31
- updateButtons();
32
- showTerminalTab();
33
- } else if (data.type === 'script_stopped') {
34
- scriptState.running = false;
35
- const msg = data.error ? data.error : ('exited with code ' + (data.code || 0));
36
- if (term) term.writeln('\r\n\x1b[90m[process ' + msg + ']\x1b[0m');
37
- updateButtons();
38
- } else if (data.type === 'script_output') {
39
- hasTerminalContent = true;
40
- showTerminalTab();
41
- if (term) term.write(data.data);
42
- }
43
- });
44
-
45
- window.addEventListener('resize', debounce(fitTerminal, 200));
46
- }
47
-
48
- function setupButtons() {
49
- var startBtn = document.getElementById('scriptStartBtn');
50
- var devBtn = document.getElementById('scriptDevBtn');
51
- var stopBtn = document.getElementById('scriptStopBtn');
52
-
53
- if (startBtn) startBtn.addEventListener('click', function() { runScript('start'); });
54
- if (devBtn) devBtn.addEventListener('click', function() { runScript('dev'); });
55
- if (stopBtn) stopBtn.addEventListener('click', function() { stopScript(); });
56
- }
57
-
58
- function fetchConversationAndCheckScripts() {
59
- if (!currentConversationId) return;
60
- window.wsClient.rpc('conv.get', { id: currentConversationId })
61
- .then(function(data) {
62
- currentWorkingDirectory = data.conversation?.workingDirectory || null;
63
- showTerminalTab();
64
- checkScripts();
65
- })
66
- .catch(function() {
67
- showTerminalTab();
68
- checkScripts();
69
- });
70
- }
71
-
72
- function checkScripts() {
73
- if (!currentConversationId) return;
74
- window.wsClient.rpc('conv.scripts', { id: currentConversationId })
75
- .then(function(data) {
76
- scriptState.hasStart = data.hasStart;
77
- scriptState.hasDev = data.hasDev;
78
- scriptState.running = data.running;
79
- scriptState.script = data.runningScript;
80
- updateButtons();
81
- if (data.running || hasTerminalContent) showTerminalTab();
82
- })
83
- .catch(function() {
84
- scriptState.hasStart = false;
85
- scriptState.hasDev = false;
86
- updateButtons();
87
- });
88
- }
89
-
90
- function updateButtons() {
91
- var container = document.getElementById('scriptButtons');
92
- var startBtn = document.getElementById('scriptStartBtn');
93
- var devBtn = document.getElementById('scriptDevBtn');
94
- var stopBtn = document.getElementById('scriptStopBtn');
95
-
96
- var showAny = scriptState.hasStart || scriptState.hasDev || scriptState.running;
97
- if (container) container.style.display = showAny ? 'flex' : 'none';
98
-
99
- if (scriptState.running) {
100
- if (startBtn) startBtn.style.display = 'none';
101
- if (devBtn) devBtn.style.display = 'none';
102
- if (stopBtn) stopBtn.style.display = 'flex';
103
- } else {
104
- if (startBtn) startBtn.style.display = scriptState.hasStart ? 'flex' : 'none';
105
- if (devBtn) devBtn.style.display = scriptState.hasDev ? 'flex' : 'none';
106
- if (stopBtn) stopBtn.style.display = 'none';
107
- }
108
- }
109
-
110
- function runScript(script) {
111
- if (!currentConversationId || scriptState.running) return;
112
- window.wsClient.rpc('conv.run-script', { id: currentConversationId, script: script })
113
- .then(function(data) {
114
- if (data.ok) {
115
- scriptState.running = true;
116
- scriptState.script = script;
117
- hasTerminalContent = false;
118
- updateButtons();
119
- showTerminalTab();
120
- switchToTerminalView();
121
- var term = getTerminal();
122
- if (term) {
123
- term.clear();
124
- term.writeln('\x1b[36m[running npm run ' + script + ']\x1b[0m\r\n');
125
- }
126
- }
127
- })
128
- .catch(function(err) { console.error('Failed to start script:', err); });
129
- }
130
-
131
- function stopScript() {
132
- if (!currentConversationId) return;
133
- window.wsClient.rpc('conv.stop-script', { id: currentConversationId })
134
- .catch(function(err) { console.error('Failed to stop script:', err); });
135
- }
136
-
137
- function showTerminalTab() {
138
- var btn = document.getElementById('terminalTabBtn');
139
- if (btn) btn.style.display = '';
140
- }
141
-
142
- function hideTerminalTab() {
143
- var btn = document.getElementById('terminalTabBtn');
144
- if (btn) btn.style.display = 'none';
145
- }
146
-
147
- function switchToTerminalView() {
148
- var bar = document.getElementById('viewToggleBar');
149
- if (!bar) return;
150
- var termBtn = bar.querySelector('[data-view="terminal"]');
151
- if (termBtn) termBtn.click();
152
- }
153
-
154
- function getTerminal() {
155
- if (window.terminalModule && window.terminalModule.getTerminal) {
156
- return window.terminalModule.getTerminal();
157
- }
158
- return null;
159
- }
160
-
161
- function fitTerminal() {
162
- var term = getTerminal();
163
- if (term && term._core && term._core._renderService) {
164
- try { term.fit(); } catch {}
165
- }
166
- }
167
-
168
- function debounce(fn, ms) {
169
- var timer;
170
- return function() {
171
- clearTimeout(timer);
172
- timer = setTimeout(fn, ms);
173
- };
174
- }
175
-
176
- window.addEventListener('view-switched', function(e) {
177
- if (e.detail && e.detail.view === 'terminal') {
178
- setTimeout(fitTerminal, 100);
179
- }
180
- });
181
-
182
- if (document.readyState === 'loading') {
183
- document.addEventListener('DOMContentLoaded', init);
184
- } else {
185
- init();
186
- }
187
-
188
- window.scriptRunner = {
189
- getState: function() { return scriptState; },
190
- getTerminal: getTerminal
191
- };
192
- })();
@@ -1,105 +0,0 @@
1
-
2
- class ConversationState {
3
- constructor() {
4
- this.current = {
5
- id: null,
6
- version: 0,
7
- data: null,
8
- timestamp: 0,
9
- reason: null
10
- };
11
- this.history = [];
12
- this.MAX_HISTORY = 50;
13
- }
14
-
15
- selectConversation(id, reason, serverVersion) {
16
- if (id === this.current.id && serverVersion === this.current.version) {
17
- return { success: false, reason: 'already_selected', prevState: this.current, newState: this.current };
18
- }
19
- const prevState = { ...this.current };
20
- this.current.id = id;
21
- this.current.version = serverVersion || (this.current.version + 1);
22
- this.current.timestamp = Date.now();
23
- this.current.reason = reason;
24
- this.current.data = null;
25
- this._recordHistory('selectConversation', prevState, this.current, reason);
26
- return { success: true, reason: 'selected', prevState, newState: { ...this.current } };
27
- }
28
-
29
- updateConversation(id, data, serverVersion) {
30
- if (id !== this.current.id) {
31
- return { success: false, reason: 'id_mismatch', prevState: this.current, newState: this.current };
32
- }
33
- if (serverVersion && serverVersion < this.current.version) {
34
- return { success: false, reason: 'stale_version', prevState: this.current, newState: this.current };
35
- }
36
- const prevState = { ...this.current };
37
- this.current.data = { ...this.current.data, ...data };
38
- this.current.version = serverVersion || (this.current.version + 1);
39
- this.current.timestamp = Date.now();
40
- this._recordHistory('updateConversation', prevState, this.current, 'update');
41
- return { success: true, reason: 'updated', prevState, newState: { ...this.current } };
42
- }
43
-
44
- deleteConversation(id, serverVersion) {
45
- if (id !== this.current.id) {
46
- return { success: false, reason: 'not_current', prevState: this.current, newState: this.current };
47
- }
48
- const prevState = { ...this.current };
49
- this.current.id = null;
50
- this.current.version = 0;
51
- this.current.data = null;
52
- this.current.timestamp = Date.now();
53
- this.current.reason = 'deleted';
54
- this._recordHistory('deleteConversation', prevState, this.current, 'delete');
55
- return { success: true, reason: 'deleted', prevState, newState: { ...this.current } };
56
- }
57
-
58
- clear(reason) {
59
- const prevState = { ...this.current };
60
- this.current.id = null;
61
- this.current.version = 0;
62
- this.current.data = null;
63
- this.current.timestamp = Date.now();
64
- this.current.reason = reason;
65
- this._recordHistory('clear', prevState, this.current, reason);
66
- return { success: true, reason: 'cleared', prevState, newState: { ...this.current } };
67
- }
68
-
69
- getCurrent() {
70
- return { ...this.current };
71
- }
72
-
73
- getVersion() {
74
- return this.current.version;
75
- }
76
-
77
- _recordHistory(operation, prevState, newState, detail) {
78
- this.history.push({
79
- operation,
80
- prevState,
81
- newState,
82
- detail,
83
- timestamp: Date.now()
84
- });
85
- if (this.history.length > this.MAX_HISTORY) {
86
- this.history.shift();
87
- }
88
- }
89
-
90
- getHistory() {
91
- return [...this.history];
92
- }
93
-
94
- debugDump() {
95
- return {
96
- current: { ...this.current },
97
- history: this.getHistory(),
98
- timestamp: Date.now()
99
- };
100
- }
101
- }
102
-
103
- if (typeof window !== 'undefined') {
104
- window.ConversationState = new ConversationState();
105
- }
@@ -1,144 +0,0 @@
1
- Object.assign(StreamingRenderer.prototype, {
2
- renderBatch(batch) {
3
- if (!this.outputContainer) return;
4
-
5
- this.emit('render:start', { eventCount: batch.length });
6
- const renderStart = performance.now();
7
-
8
- try {
9
- const fragment = document.createDocumentFragment();
10
- let nodeCount = 0;
11
-
12
- for (const event of batch) {
13
- try {
14
- const element = this.renderEvent(event);
15
- if (element) {
16
- fragment.appendChild(element);
17
- nodeCount++;
18
- }
19
- } catch (error) {
20
- console.error('Event render error:', error, event);
21
- }
22
- }
23
-
24
- if (nodeCount > 0) {
25
- this.outputContainer.appendChild(fragment);
26
- this.domNodeCount += nodeCount;
27
-
28
- this.nestToolResultsInToolUses();
29
- }
30
-
31
- this.autoScroll();
32
-
33
- const renderTime = performance.now() - renderStart;
34
- this.lastRenderTime = renderTime;
35
-
36
- this.emit('render:complete', {
37
- eventCount: batch.length,
38
- nodeCount,
39
- renderTime
40
- });
41
- } catch (error) {
42
- console.error('Batch render error:', error);
43
- this.emit('error:render', { error, batch });
44
- }
45
- },
46
-
47
- renderEvent(event) {
48
- if (!event.type) return null;
49
-
50
- try {
51
- if (event.type === 'streaming_progress' && event.block) {
52
- return this.renderBlock(event.block, event);
53
- }
54
-
55
- if (event.type === 'streaming_error' && event.isPrematureEnd) {
56
- return this.renderBlockPremature({ type: 'premature', error: event.error, exitCode: event.exitCode });
57
- }
58
-
59
- switch (event.type) {
60
- case 'streaming_start':
61
- return this.renderStreamingStart(event);
62
- case 'streaming_progress':
63
- return this.renderStreamingProgress(event);
64
- case 'streaming_complete':
65
- return this.renderStreamingComplete(event);
66
- case 'file_read':
67
- return this.renderFileRead(event);
68
- case 'file_write':
69
- return this.renderFileWrite(event);
70
- case 'git_status':
71
- return this.renderGitStatus(event);
72
- case 'command_execute':
73
- return this.renderCommand(event);
74
- case 'error':
75
- return this.renderError(event);
76
- case 'text_block':
77
- return this.renderText(event);
78
- case 'code_block':
79
- return this.renderCode(event);
80
- case 'thinking_block':
81
- return null;
82
- case 'tool_use':
83
- return this.renderToolUse(event);
84
- case 'compact_boundary':
85
- return this.renderCompactBoundary(event);
86
- case 'compact_summary':
87
- return this.renderCompactBoundary(event);
88
- case 'turn_duration':
89
- return this.renderTurnDuration(event);
90
- case 'agent_progress':
91
- return this.renderAgentProgress(event);
92
- case 'mcp_progress':
93
- return this.renderMcpProgress(event);
94
- default:
95
- return this.renderGeneric(event);
96
- }
97
- } catch (error) {
98
- console.error('Event render error:', error, event);
99
- return this.renderError({ message: error.message, event });
100
- }
101
- },
102
-
103
- renderBlock(block, context = {}, targetContainer = null) {
104
- if (!block || !block.type) return null;
105
-
106
- try {
107
- switch (block.type) {
108
- case 'text':
109
- return this.renderBlockText(block, context, targetContainer);
110
- case 'code':
111
- return this.renderBlockCode(block, context);
112
- case 'thinking':
113
- return this.renderBlockThinking(block, context);
114
- case 'tool_use':
115
- return this.renderBlockToolUse(block, context);
116
- case 'tool_result':
117
- return this.renderBlockToolResult(block, context);
118
- case 'image':
119
- return this.renderBlockImage(block, context);
120
- case 'bash':
121
- return this.renderBlockBash(block, context);
122
- case 'system':
123
- return this.renderBlockSystem(block, context);
124
- case 'result':
125
- return this.renderBlockResult(block, context);
126
- case 'tool_status':
127
- return this.renderBlockToolStatus(block, context);
128
- case 'usage':
129
- return this.renderBlockUsage(block, context);
130
- case 'plan':
131
- return this.renderBlockPlan(block, context);
132
- case 'premature':
133
- return this.renderBlockPremature(block, context);
134
- case 'hook_progress':
135
- return this.renderBlockHookProgress(block, context);
136
- default:
137
- return this.renderBlockGeneric(block, context);
138
- }
139
- } catch (error) {
140
- console.error('Block render error:', error, block);
141
- return this.renderBlockError(block, error);
142
- }
143
- }
144
- });
@@ -1,163 +0,0 @@
1
- Object.assign(StreamingRenderer.prototype, {
2
- renderBlockImage(block, context) {
3
- const div = document.createElement('div');
4
- div.className = 'block-image';
5
- div.classList.add(this._getBlockTypeClass('image'));
6
-
7
- let src = block.image || block.src || '';
8
- const alt = block.alt || 'Image';
9
-
10
- if (block.data && block.media_type) {
11
- src = `data:${block.media_type};base64,${block.data}`;
12
- }
13
-
14
- div.innerHTML = `
15
- <img src="${this.escapeHtml(src)}" alt="${this.escapeHtml(alt)}" loading="lazy">
16
- ${block.alt ? `<div class="image-caption">${this.escapeHtml(alt)}</div>` : ''}
17
- `;
18
-
19
- return div;
20
- },
21
-
22
- renderBlockBash(block, context) {
23
- const div = document.createElement('div');
24
- div.className = 'block-bash';
25
- div.classList.add(this._getBlockTypeClass('bash'));
26
-
27
- const command = block.command || block.code || '';
28
- const output = block.output || '';
29
-
30
- let html = `<div class="bash-command"><span class="prompt">$</span><code>${this.escapeHtml(command)}</code></div>`;
31
-
32
- if (output) {
33
- if (StreamingRenderer.detectCodeContent(output)) {
34
- html += StreamingRenderer.renderCodeWithHighlight(output, this.escapeHtml.bind(this), true);
35
- } else {
36
- html += `<pre class="bash-output"><code>${this.escapeHtml(output)}</code></pre>`;
37
- }
38
- }
39
-
40
- div.innerHTML = html;
41
- return div;
42
- },
43
-
44
- renderBlockSystem(block, context) {
45
- if (block.subtype === 'compact_boundary') return this.renderCompactBoundary(block);
46
- if (block.subtype === 'turn_duration') return this.renderTurnDuration(block);
47
- if (!block.model && !block.cwd && !block.tools) return null;
48
- const details = document.createElement('details');
49
- details.className = 'folded-tool folded-tool-info permanently-expanded';
50
- details.dataset.eventType = 'system';
51
- details.classList.add(this._getBlockTypeClass('system'));
52
- const desc = block.model ? this.escapeHtml(block.model) : 'Session';
53
- const summary = document.createElement('summary');
54
- summary.className = 'folded-tool-bar';
55
- summary.innerHTML = `
56
- <span class="folded-tool-icon"><svg viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/></svg></span>
57
- <span class="folded-tool-name">Session</span>
58
- <span class="folded-tool-desc">${desc}</span>
59
- `;
60
- details.appendChild(summary);
61
- const body = document.createElement('div');
62
- body.className = 'folded-tool-body block-system';
63
- body.innerHTML = `
64
- <div class="system-body">
65
- ${block.model ? `<div class="sys-field"><span class="sys-label">Model</span><span class="sys-value"><code>${this.escapeHtml(block.model)}</code></span></div>` : ''}
66
- ${block.cwd ? `<div class="sys-field"><span class="sys-label">Directory</span><span class="sys-value"><code>${this.escapeHtml(block.cwd)}</code></span></div>` : ''}
67
- ${block.session_id ? `<div class="sys-field"><span class="sys-label">Session</span><span class="sys-value"><code>${this.escapeHtml(block.session_id)}</code></span></div>` : ''}
68
- ${block.tools && Array.isArray(block.tools) ? `<div class="sys-field" style="flex-direction:column;gap:0.375rem"><span class="sys-label">Tools (${block.tools.length})</span><div class="tools-list">${block.tools.map(t => `<span class="tool-badge">${this.escapeHtml(t)}</span>`).join('')}</div></div>` : ''}
69
- </div>
70
- `;
71
- details.appendChild(body);
72
- return details;
73
- },
74
-
75
- renderBlockResult(block, context) {
76
- const isError = block.is_error || false;
77
- const duration = block.duration_ms ? (block.duration_ms / 1000).toFixed(1) + 's' : '';
78
- const cost = block.total_cost_usd ? '$' + block.total_cost_usd.toFixed(4) : '';
79
- const turns = block.num_turns || '';
80
- const statsDesc = [duration, cost, turns ? turns + ' turns' : ''].filter(Boolean).join(' / ');
81
-
82
- const details = document.createElement('details');
83
- details.className = isError ? 'folded-tool folded-tool-error permanently-expanded' : 'folded-tool permanently-expanded';
84
- details.dataset.eventType = 'result';
85
- details.classList.add(this._getBlockTypeClass(isError ? 'error' : 'result'));
86
-
87
- const iconSvg = isError
88
- ? '<svg viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/></svg>'
89
- : '<svg viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg>';
90
-
91
- const summary = document.createElement('summary');
92
- summary.className = 'folded-tool-bar';
93
- summary.innerHTML = `
94
- <span class="folded-tool-icon">${iconSvg}</span>
95
- <span class="folded-tool-name">${isError ? 'Failed' : 'Complete'}</span>
96
- <span class="folded-tool-desc">${this.escapeHtml(statsDesc)}</span>
97
- `;
98
- details.appendChild(summary);
99
-
100
- if (block.result || duration || cost || turns) {
101
- const body = document.createElement('div');
102
- body.className = 'folded-tool-body';
103
- let bodyHtml = '';
104
- if (duration || cost || turns) {
105
- bodyHtml += `<div class="block-result"><div class="result-stats">
106
- ${duration ? `<div class="result-stat"><span class="stat-icon">&#9202;</span><span class="stat-value">${this.escapeHtml(duration)}</span><span class="stat-label">duration</span></div>` : ''}
107
- ${cost ? `<div class="result-stat"><span class="stat-icon">&#128176;</span><span class="stat-value">${this.escapeHtml(cost)}</span><span class="stat-label">cost</span></div>` : ''}
108
- ${turns ? `<div class="result-stat"><span class="stat-icon">&#128260;</span><span class="stat-value">${this.escapeHtml(String(turns))}</span><span class="stat-label">turns</span></div>` : ''}
109
- </div></div>`;
110
- }
111
- if (block.result) {
112
- const r = typeof block.result === 'string' ? block.result : JSON.stringify(block.result, null, 2);
113
- const rendered = this.containsHtmlTags(r) ? '<div class="html-content">' + this.sanitizeHtml(r) + '</div>' : `<div style="font-size:0.8rem;white-space:pre-wrap;word-break:break-word;line-height:1.5">${this.escapeHtml(r)}</div>`;
114
- bodyHtml += rendered;
115
- }
116
- body.innerHTML = bodyHtml;
117
- details.appendChild(body);
118
- }
119
-
120
- return details;
121
- },
122
-
123
- renderBlockToolStatus(block, context) {
124
- const status = block.status || 'pending';
125
- const statusIcons = {
126
- pending: '<svg viewBox="0 0 20 20" fill="currentColor" style="color:var(--color-text-secondary)"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clip-rule="evenodd"/></svg>',
127
- in_progress: '<svg viewBox="0 0 20 20" fill="currentColor" class="animate-spin" style="color:var(--color-info)"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clip-rule="evenodd"/></svg>'
128
- };
129
- const statusLabels = {
130
- pending: 'Pending',
131
- in_progress: 'Running...'
132
- };
133
-
134
- const div = document.createElement('div');
135
- div.className = 'block-tool-status';
136
- div.dataset.toolUseId = block.tool_use_id || '';
137
- div.classList.add(this._getBlockTypeClass('tool_status'));
138
- div.innerHTML = `
139
- <div style="display:flex;align-items:center;gap:0.5rem;padding:0.25rem 0.5rem;font-size:0.75rem;color:var(--color-text-secondary)">
140
- ${statusIcons[status] || statusIcons.pending}
141
- <span>${statusLabels[status] || this.escapeHtml(status)}</span>
142
- </div>
143
- `;
144
- return div;
145
- },
146
-
147
- renderBlockHookProgress(block, context) {
148
- const hookEvent = block.hookEvent || block.hookName || '';
149
- const hookIcons = {
150
- PreToolUse: '<svg viewBox="0 0 20 20" fill="currentColor" style="width:0.75rem;height:0.75rem"><path fill-rule="evenodd" d="M11.3 1.046A1 1 0 0112 2v5h4a1 1 0 01.82 1.573l-7 10.666a1 1 0 11-1.64-1.118L9.687 10H5a1 1 0 01-.82-1.573l7-10.666a1 1 0 011.12-.373z" clip-rule="evenodd"/></svg>',
151
- PostToolUse: '<svg viewBox="0 0 20 20" fill="currentColor" style="width:0.75rem;height:0.75rem"><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/></svg>',
152
- Stop: '<svg viewBox="0 0 20 20" fill="currentColor" style="width:0.75rem;height:0.75rem"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8 7a1 1 0 00-1 1v4a1 1 0 001 1h4a1 1 0 001-1V8a1 1 0 00-1-1H8z" clip-rule="evenodd"/></svg>'
153
- };
154
- const icon = hookIcons[hookEvent.split(':')[0]] || hookIcons.PreToolUse;
155
- const label = hookEvent.includes(':') ? hookEvent.split(':').pop() : hookEvent;
156
- const div = document.createElement('div');
157
- div.className = 'block-hook-progress';
158
- div.dataset.hookEvent = hookEvent;
159
- div.style.cssText = 'display:none';
160
- div.innerHTML = '<span class="hook-badge" style="display:inline-flex;align-items:center;gap:0.25rem;padding:0.125rem 0.5rem;font-size:0.65rem;color:var(--color-text-secondary);opacity:0.5">' + icon + '<span>' + this.escapeHtml(label) + '</span></span>';
161
- return div;
162
- }
163
- });