agentgui 1.0.831 → 1.0.832

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.
@@ -14,7 +14,6 @@ function validate(schema, params) {
14
14
 
15
15
  const ConvNewSchema = z.object({ agentId: z.string().optional(), title: z.string().optional(), workingDirectory: z.string().optional(), model: z.string().optional(), subAgent: z.string().optional() }).passthrough();
16
16
  const ConvUpdSchema = z.object({ id: z.string().min(1, 'id required') }).passthrough();
17
- const ConvSteerSchema = z.object({ id: z.string().min(1, 'conversation id required'), content: z.union([z.string(), z.record(z.any())]).refine(v => v !== undefined && v !== null && v !== '', { message: 'content required' }) }).passthrough();
18
17
 
19
18
  export function register(router, deps) {
20
19
  const { queries, activeExecutions, rateLimitState,
@@ -72,7 +71,6 @@ export function register(router, deps) {
72
71
  });
73
72
 
74
73
  router.handle('conv.del.all', (p) => {
75
- // Clean up all execution machine actors
76
74
  const convs = queries.getConversationsList();
77
75
  for (const c of convs) { cleanupExecution(c.id); execMachine.remove(c.id); }
78
76
  if (!queries.deleteAllConversations()) fail(500, 'Failed to delete all conversations');
@@ -137,146 +135,4 @@ export function register(router, deps) {
137
135
  }
138
136
  return { ok: true };
139
137
  });
140
-
141
- router.handle('conv.export', (p) => {
142
- const conv = queries.getConversation(p.id);
143
- if (!conv) notFound();
144
- const msgs = queries.getConversationMessages(p.id);
145
- const format = p.format || 'markdown';
146
- if (format === 'json') return { conversation: conv, messages: msgs };
147
- let md = `# ${conv.title || 'Conversation'}\n\n`;
148
- md += `Agent: ${conv.agentType || 'unknown'} | Created: ${new Date(conv.created_at).toISOString()}\n\n---\n\n`;
149
- for (const m of msgs) {
150
- const role = m.role === 'user' ? 'User' : 'Assistant';
151
- md += `## ${role}\n\n`;
152
- let content = m.content;
153
- try { const parsed = JSON.parse(content); if (Array.isArray(parsed)) { content = parsed.map(b => b.text || b.content || JSON.stringify(b)).join('\n'); } } catch {}
154
- md += content + '\n\n---\n\n';
155
- }
156
- return { markdown: md, title: conv.title };
157
- });
158
-
159
- router.handle('conv.import', (p) => {
160
- if (!p.conversation || !p.messages) throw Object.assign(new Error('Missing conversation or messages'), { code: 400 });
161
- const src = p.conversation;
162
- const conv = queries.createConversation(
163
- src.agentId || src.agentType || 'claude-code',
164
- src.title || 'Imported Conversation',
165
- src.workingDirectory || null,
166
- src.model || null
167
- );
168
- for (const msg of p.messages) {
169
- queries.createMessage(conv.id, msg.role || 'user', msg.content || '');
170
- }
171
- broadcastSync({ type: 'conversation_created', conversation: queries.getConversation(conv.id) });
172
- return { conversation: queries.getConversation(conv.id), importedMessages: p.messages.length };
173
- });
174
-
175
- router.handle('conv.sync', (p) => {
176
- const conv = queries.getConversation(p.id);
177
- if (!conv) notFound();
178
- const machineSnap = execMachine.snapshot(p.id);
179
- const executionState = machineSnap?.value || 'idle';
180
- const latestSession = queries.getLatestSession(p.id);
181
- const sinceSeq = parseInt(p.sinceSeq || '-1');
182
- const since = parseInt(p.since || '0');
183
- let missedChunks = [];
184
- if (latestSession && sinceSeq >= 0) {
185
- missedChunks = queries.getChunksSinceSeq(latestSession.id, sinceSeq);
186
- } else if (latestSession && since > 0) {
187
- missedChunks = queries.getConversationChunksSince(p.id, since);
188
- }
189
- return {
190
- conversation: conv,
191
- executionState,
192
- isActivelyStreaming: execMachine.isActive(p.id),
193
- latestSession,
194
- missedChunks,
195
- missedCount: missedChunks.length,
196
- queueLength: machineSnap?.context?.queue?.length || 0
197
- };
198
- });
199
-
200
- router.handle('conv.search', (p) => {
201
- if (!p.query || typeof p.query !== 'string' || p.query.trim().length < 2) return { results: [] };
202
- const limit = Math.min(parseInt(p.limit || '50'), 200);
203
- return { results: queries.searchMessages(p.query.trim(), limit) };
204
- });
205
-
206
- router.handle('conv.prune', (p) => {
207
- const conv = queries.getConversation(p.id);
208
- if (!conv) notFound();
209
- const keep = Math.max(parseInt(p.keep || '500'), 100);
210
- const sessions = queries.getConversationSessions(p.id);
211
- if (!sessions || sessions.length === 0) return { pruned: 0 };
212
- const latestSessionId = sessions[0]?.id;
213
- let pruned = 0;
214
- for (const sess of sessions) {
215
- if (sess.id === latestSessionId) continue;
216
- const count = queries.getSessionChunks(sess.id)?.length || 0;
217
- if (count > 0) { queries.deleteSessionChunks(sess.id); pruned += count; }
218
- }
219
- return { pruned, kept: latestSessionId, sessionsProcessed: sessions.length };
220
- });
221
-
222
- router.handle('conv.cancel', (p) => {
223
- if (!execMachine.isActive(p.id)) notFound('No active execution to cancel');
224
- const ctx = execMachine.getContext(p.id);
225
- const pid = ctx?.pid || activeExecutions.get(p.id)?.pid;
226
- const sessionId = ctx?.sessionId || activeExecutions.get(p.id)?.sessionId;
227
- if (pid) { try { process.kill(-pid, 'SIGKILL'); } catch { try { process.kill(pid, 'SIGKILL'); } catch {} } }
228
- if (sessionId) queries.updateSession(sessionId, { status: 'interrupted', completed_at: Date.now() });
229
- cleanupExecution(p.id, false);
230
- broadcastSync({ type: 'streaming_complete', sessionId, conversationId: p.id, interrupted: true, timestamp: Date.now() });
231
- return { ok: true, cancelled: true, conversationId: p.id, sessionId };
232
- });
233
-
234
- router.handle('conv.inject', (p) => {
235
- const conv = queries.getConversation(p.id);
236
- if (!conv) notFound('Conversation not found');
237
- if (!p.content) fail(400, 'Missing content');
238
- const message = queries.createMessage(p.id, 'user', '[INJECTED] ' + p.content);
239
- if (!execMachine.isActive(p.id)) {
240
- const agentId = conv.agentId || 'claude-code';
241
- const session = queries.createSession(p.id, agentId, 'pending');
242
- processMessageWithStreaming(p.id, message.id, session.id, message.content, agentId, conv.model || null, conv.subAgent || null);
243
- }
244
- return { ok: true, injected: true, conversationId: p.id, messageId: message.id };
245
- });
246
-
247
- router.handle('conv.steer', (p) => {
248
- p = validate(ConvSteerSchema, p);
249
- const conv = queries.getConversation(p.id);
250
- if (!conv) notFound('Conversation not found');
251
-
252
- if (!execMachine.isActive(p.id)) fail(409, 'No active execution to steer');
253
-
254
- const ctx = execMachine.getContext(p.id);
255
- const pid = ctx?.pid || activeExecutions.get(p.id)?.pid;
256
- const sessionId = ctx?.sessionId || activeExecutions.get(p.id)?.sessionId;
257
-
258
- if (pid) {
259
- try { process.kill(-pid, 'SIGKILL'); } catch { try { process.kill(pid, 'SIGKILL'); } catch (e) {} }
260
- }
261
-
262
- if (sessionId) queries.updateSession(sessionId, { status: 'interrupted', completed_at: Date.now() });
263
- cleanupExecution(p.id);
264
-
265
- // Clear claudeSessionId so new execution starts fresh without --resume on a killed session
266
- queries.setClaudeSessionId(p.id, null);
267
-
268
- broadcastSync({ type: 'streaming_complete', sessionId, conversationId: p.id, interrupted: true, timestamp: Date.now() });
269
-
270
- const agentId = conv.agentType || conv.agentId || 'claude-code';
271
- const model = conv.model || null;
272
- const subAgent = conv.subAgent || null;
273
- const steerContent = typeof p.content === 'string' ? p.content : (p.content ? JSON.stringify(p.content) : '');
274
- const message = queries.createMessage(p.id, 'user', steerContent);
275
- queries.createEvent('message.created', { role: 'user', messageId: message.id }, p.id);
276
- broadcastSync({ type: 'message_created', conversationId: p.id, message, timestamp: Date.now() });
277
- startExecution(p.id, message, agentId, model, steerContent, subAgent);
278
-
279
- return { ok: true, steered: true, conversationId: p.id, messageId: message.id };
280
- });
281
-
282
138
  }
@@ -0,0 +1,169 @@
1
+ import { z } from 'zod';
2
+ import * as execMachine from './execution-machine.js';
3
+
4
+ function fail(code, message) { const e = new Error(message); e.code = code; throw e; }
5
+ function notFound(msg = 'Not found') { fail(404, msg); }
6
+ function validate(schema, params) {
7
+ const result = schema.safeParse(params);
8
+ if (!result.success) fail(400, result.error.issues.map(i => i.message).join('; '));
9
+ return result.data;
10
+ }
11
+
12
+ const ConvSteerSchema = z.object({ id: z.string().min(1, 'conversation id required'), content: z.union([z.string(), z.record(z.any())]).refine(v => v !== undefined && v !== null && v !== '', { message: 'content required' }) }).passthrough();
13
+
14
+ export function register(router, deps) {
15
+ const { queries, activeExecutions, rateLimitState,
16
+ broadcastSync, processMessageWithStreaming, cleanupExecution,
17
+ getJsonlWatcher = () => null, logError = () => {} } = deps;
18
+
19
+ function startExecution(convId, message, agentId, model, content, subAgent) {
20
+ const session = queries.createSession(convId);
21
+ queries.createEvent('session.created', { messageId: message.id, sessionId: session.id }, convId, session.id);
22
+ execMachine.send(convId, { type: 'START', sessionId: session.id });
23
+ activeExecutions.set(convId, { pid: null, startTime: Date.now(), sessionId: session.id, lastActivity: Date.now() });
24
+ queries.setIsStreaming(convId, true);
25
+ broadcastSync({ type: 'streaming_start', sessionId: session.id, conversationId: convId, messageId: message.id, agentId, timestamp: Date.now() });
26
+ processMessageWithStreaming(convId, message.id, session.id, content, agentId, model, subAgent).catch(e => logError('startExecution', e, { convId }));
27
+ return session;
28
+ }
29
+
30
+ router.handle('conv.export', (p) => {
31
+ const conv = queries.getConversation(p.id);
32
+ if (!conv) notFound();
33
+ const msgs = queries.getConversationMessages(p.id);
34
+ const format = p.format || 'markdown';
35
+ if (format === 'json') return { conversation: conv, messages: msgs };
36
+ let md = `# ${conv.title || 'Conversation'}\n\n`;
37
+ md += `Agent: ${conv.agentType || 'unknown'} | Created: ${new Date(conv.created_at).toISOString()}\n\n---\n\n`;
38
+ for (const m of msgs) {
39
+ const role = m.role === 'user' ? 'User' : 'Assistant';
40
+ md += `## ${role}\n\n`;
41
+ let content = m.content;
42
+ try { const parsed = JSON.parse(content); if (Array.isArray(parsed)) { content = parsed.map(b => b.text || b.content || JSON.stringify(b)).join('\n'); } } catch {}
43
+ md += content + '\n\n---\n\n';
44
+ }
45
+ return { markdown: md, title: conv.title };
46
+ });
47
+
48
+ router.handle('conv.import', (p) => {
49
+ if (!p.conversation || !p.messages) throw Object.assign(new Error('Missing conversation or messages'), { code: 400 });
50
+ const src = p.conversation;
51
+ const conv = queries.createConversation(
52
+ src.agentId || src.agentType || 'claude-code',
53
+ src.title || 'Imported Conversation',
54
+ src.workingDirectory || null,
55
+ src.model || null
56
+ );
57
+ for (const msg of p.messages) {
58
+ queries.createMessage(conv.id, msg.role || 'user', msg.content || '');
59
+ }
60
+ broadcastSync({ type: 'conversation_created', conversation: queries.getConversation(conv.id) });
61
+ return { conversation: queries.getConversation(conv.id), importedMessages: p.messages.length };
62
+ });
63
+
64
+ router.handle('conv.sync', (p) => {
65
+ const conv = queries.getConversation(p.id);
66
+ if (!conv) notFound();
67
+ const machineSnap = execMachine.snapshot(p.id);
68
+ const executionState = machineSnap?.value || 'idle';
69
+ const latestSession = queries.getLatestSession(p.id);
70
+ const sinceSeq = parseInt(p.sinceSeq || '-1');
71
+ const since = parseInt(p.since || '0');
72
+ let missedChunks = [];
73
+ if (latestSession && sinceSeq >= 0) {
74
+ missedChunks = queries.getChunksSinceSeq(latestSession.id, sinceSeq);
75
+ } else if (latestSession && since > 0) {
76
+ missedChunks = queries.getConversationChunksSince(p.id, since);
77
+ }
78
+ return {
79
+ conversation: conv,
80
+ executionState,
81
+ isActivelyStreaming: execMachine.isActive(p.id),
82
+ latestSession,
83
+ missedChunks,
84
+ missedCount: missedChunks.length,
85
+ queueLength: machineSnap?.context?.queue?.length || 0
86
+ };
87
+ });
88
+
89
+ router.handle('conv.search', (p) => {
90
+ if (!p.query || typeof p.query !== 'string' || p.query.trim().length < 2) return { results: [] };
91
+ const limit = Math.min(parseInt(p.limit || '50'), 200);
92
+ return { results: queries.searchMessages(p.query.trim(), limit) };
93
+ });
94
+
95
+ router.handle('conv.prune', (p) => {
96
+ const conv = queries.getConversation(p.id);
97
+ if (!conv) notFound();
98
+ const keep = Math.max(parseInt(p.keep || '500'), 100);
99
+ const sessions = queries.getConversationSessions(p.id);
100
+ if (!sessions || sessions.length === 0) return { pruned: 0 };
101
+ const latestSessionId = sessions[0]?.id;
102
+ let pruned = 0;
103
+ for (const sess of sessions) {
104
+ if (sess.id === latestSessionId) continue;
105
+ const count = queries.getSessionChunks(sess.id)?.length || 0;
106
+ if (count > 0) { queries.deleteSessionChunks(sess.id); pruned += count; }
107
+ }
108
+ return { pruned, kept: latestSessionId, sessionsProcessed: sessions.length };
109
+ });
110
+
111
+ router.handle('conv.cancel', (p) => {
112
+ if (!execMachine.isActive(p.id)) notFound('No active execution to cancel');
113
+ const ctx = execMachine.getContext(p.id);
114
+ const pid = ctx?.pid || activeExecutions.get(p.id)?.pid;
115
+ const sessionId = ctx?.sessionId || activeExecutions.get(p.id)?.sessionId;
116
+ if (pid) { try { process.kill(-pid, 'SIGKILL'); } catch { try { process.kill(pid, 'SIGKILL'); } catch {} } }
117
+ if (sessionId) queries.updateSession(sessionId, { status: 'interrupted', completed_at: Date.now() });
118
+ cleanupExecution(p.id, false);
119
+ broadcastSync({ type: 'streaming_complete', sessionId, conversationId: p.id, interrupted: true, timestamp: Date.now() });
120
+ return { ok: true, cancelled: true, conversationId: p.id, sessionId };
121
+ });
122
+
123
+ router.handle('conv.inject', (p) => {
124
+ const conv = queries.getConversation(p.id);
125
+ if (!conv) notFound('Conversation not found');
126
+ if (!p.content) fail(400, 'Missing content');
127
+ const message = queries.createMessage(p.id, 'user', '[INJECTED] ' + p.content);
128
+ if (!execMachine.isActive(p.id)) {
129
+ const agentId = conv.agentId || 'claude-code';
130
+ const session = queries.createSession(p.id, agentId, 'pending');
131
+ processMessageWithStreaming(p.id, message.id, session.id, message.content, agentId, conv.model || null, conv.subAgent || null);
132
+ }
133
+ return { ok: true, injected: true, conversationId: p.id, messageId: message.id };
134
+ });
135
+
136
+ router.handle('conv.steer', (p) => {
137
+ p = validate(ConvSteerSchema, p);
138
+ const conv = queries.getConversation(p.id);
139
+ if (!conv) notFound('Conversation not found');
140
+
141
+ if (!execMachine.isActive(p.id)) fail(409, 'No active execution to steer');
142
+
143
+ const ctx = execMachine.getContext(p.id);
144
+ const pid = ctx?.pid || activeExecutions.get(p.id)?.pid;
145
+ const sessionId = ctx?.sessionId || activeExecutions.get(p.id)?.sessionId;
146
+
147
+ if (pid) {
148
+ try { process.kill(-pid, 'SIGKILL'); } catch { try { process.kill(pid, 'SIGKILL'); } catch (e) {} }
149
+ }
150
+
151
+ if (sessionId) queries.updateSession(sessionId, { status: 'interrupted', completed_at: Date.now() });
152
+ cleanupExecution(p.id);
153
+
154
+ queries.setClaudeSessionId(p.id, null);
155
+
156
+ broadcastSync({ type: 'streaming_complete', sessionId, conversationId: p.id, interrupted: true, timestamp: Date.now() });
157
+
158
+ const agentId = conv.agentType || conv.agentId || 'claude-code';
159
+ const model = conv.model || null;
160
+ const subAgent = conv.subAgent || null;
161
+ const steerContent = typeof p.content === 'string' ? p.content : (p.content ? JSON.stringify(p.content) : '');
162
+ const message = queries.createMessage(p.id, 'user', steerContent);
163
+ queries.createEvent('message.created', { role: 'user', messageId: message.id }, p.id);
164
+ broadcastSync({ type: 'message_created', conversationId: p.id, message, timestamp: Date.now() });
165
+ startExecution(p.id, message, agentId, model, steerContent, subAgent);
166
+
167
+ return { ok: true, steered: true, conversationId: p.id, messageId: message.id };
168
+ });
169
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.831",
3
+ "version": "1.0.832",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "electron/main.js",
package/server.js CHANGED
@@ -33,7 +33,9 @@ import { WsRouter } from './lib/ws-protocol.js';
33
33
  import { encode as wsEncode } from './lib/codec.js';
34
34
  const sendWs = (ws, obj) => { if (ws.readyState === 1) ws.send(wsEncode(obj)); };
35
35
  import { register as registerConvHandlers } from './lib/ws-handlers-conv.js';
36
+ import { register as registerConvHandlers2 } from './lib/ws-handlers-conv2.js';
36
37
  import { register as registerSessionHandlers } from './lib/ws-handlers-session.js';
38
+ import { register as registerSessionHandlers2 } from './lib/ws-handlers-session2.js';
37
39
  import { register as registerRunHandlers } from './lib/ws-handlers-run.js';
38
40
  import { register as registerUtilHandlers } from './lib/ws-handlers-util.js';
39
41
  import { register as registerOAuthHandlers } from './lib/ws-handlers-oauth.js';
@@ -2627,6 +2629,11 @@ registerConvHandlers(wsRouter, {
2627
2629
  broadcastSync, processMessageWithStreaming, cleanupExecution,
2628
2630
  getJsonlWatcher: () => jsonlWatcher
2629
2631
  });
2632
+ registerConvHandlers2(wsRouter, {
2633
+ queries, activeExecutions, rateLimitState,
2634
+ broadcastSync, processMessageWithStreaming, cleanupExecution,
2635
+ getJsonlWatcher: () => jsonlWatcher
2636
+ });
2630
2637
 
2631
2638
  registerMsgHandlers(wsRouter, {
2632
2639
  queries, activeExecutions, messageQueues,
@@ -2641,6 +2648,10 @@ registerSessionHandlers(wsRouter, {
2641
2648
  getAgentDescriptor, activeScripts, broadcastSync,
2642
2649
  startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState
2643
2650
  });
2651
+ registerSessionHandlers2(wsRouter, {
2652
+ discoveredAgents, modelCache, activeScripts, broadcastSync,
2653
+ startGeminiOAuth: (req) => startGeminiOAuth(req, { PORT, BASE_URL, rootDir }), geminiOAuthState: getGeminiOAuthState
2654
+ });
2644
2655
  debugLog('[INIT] registerSessionHandlers completed');
2645
2656
 
2646
2657
  registerRunHandlers(wsRouter, {