agentgui 1.0.389 → 1.0.390

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 (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +10 -73
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.389",
3
+ "version": "1.0.390",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -2231,15 +2231,11 @@ const server = http.createServer(async (req, res) => {
2231
2231
  }
2232
2232
 
2233
2233
  activeExecutions.delete(threadId);
2234
+ activeProcessesByRunId.delete(runId);
2234
2235
  queries.setIsStreaming(threadId, false);
2235
2236
 
2236
- broadcastSync({
2237
- type: 'streaming_cancelled',
2238
- sessionId: execution?.sessionId || runId,
2239
- conversationId: threadId,
2240
- runId: runId,
2241
- timestamp: Date.now()
2242
- });
2237
+ broadcastSync({ type: 'run_cancelled', runId, threadId, sessionId: execution?.sessionId, timestamp: Date.now() });
2238
+ broadcastSync({ type: 'streaming_cancelled', sessionId: execution?.sessionId || runId, conversationId: threadId, runId, timestamp: Date.now() });
2243
2239
 
2244
2240
  sendJSON(req, res, 200, cancelledRun);
2245
2241
  } catch (err) {
@@ -2273,9 +2269,14 @@ const server = http.createServer(async (req, res) => {
2273
2269
  const startTime = Date.now();
2274
2270
  const pollInterval = setInterval(() => {
2275
2271
  const currentRun = queries.getRun(runId);
2276
- if (!currentRun || ['success', 'error', 'cancelled'].includes(currentRun.status) || (Date.now() - startTime) > 30000) {
2272
+ const elapsed = Date.now() - startTime;
2273
+ const done = currentRun && ['success', 'error', 'cancelled'].includes(currentRun.status);
2274
+ if (done) {
2277
2275
  clearInterval(pollInterval);
2278
- sendJSON(req, res, 200, currentRun || run);
2276
+ sendJSON(req, res, 200, currentRun);
2277
+ } else if (elapsed > 30000) {
2278
+ clearInterval(pollInterval);
2279
+ sendJSON(req, res, 408, { error: 'Run still pending after 30s', run_id: runId, status: currentRun?.status || run.status });
2279
2280
  }
2280
2281
  }, 500);
2281
2282
  req.on('close', () => clearInterval(pollInterval));
@@ -3034,70 +3035,6 @@ const server = http.createServer(async (req, res) => {
3034
3035
  return;
3035
3036
  }
3036
3037
 
3037
- // POST /threads/{thread_id}/runs/{run_id}/cancel - Cancel a run on a thread
3038
- const threadRunCancelMatch = pathOnly.match(/^\/api\/threads\/([a-f0-9-]{36})\/runs\/([a-f0-9-]{36})\/cancel$/);
3039
- if (threadRunCancelMatch && req.method === 'POST') {
3040
- const threadId = threadRunCancelMatch[1];
3041
- const runId = threadRunCancelMatch[2];
3042
- try {
3043
- const run = queries.getRun(runId);
3044
- if (!run || run.thread_id !== threadId) {
3045
- sendJSON(req, res, 404, { error: 'Run not found on thread', type: 'not_found' });
3046
- return;
3047
- }
3048
- if (['success', 'error', 'cancelled'].includes(run.status)) {
3049
- sendJSON(req, res, 409, { error: 'Run already completed or cancelled', type: 'conflict' });
3050
- return;
3051
- }
3052
- const cancelledRun = queries.cancelRun(runId);
3053
- const execution = activeExecutions.get(threadId);
3054
- if (execution?.pid) {
3055
- try { process.kill(-execution.pid, 'SIGTERM'); } catch { try { process.kill(execution.pid, 'SIGTERM'); } catch (e) {} }
3056
- setTimeout(() => {
3057
- try { process.kill(-execution.pid, 'SIGKILL'); } catch { try { process.kill(execution.pid, 'SIGKILL'); } catch (e) {} }
3058
- }, 3000);
3059
- }
3060
- if (execution?.sessionId) {
3061
- queries.updateSession(execution.sessionId, { status: 'error', error: 'Cancelled by user', completed_at: Date.now() });
3062
- }
3063
- activeExecutions.delete(threadId);
3064
- activeProcessesByRunId.delete(runId);
3065
- queries.setIsStreaming(threadId, false);
3066
- broadcastSync({ type: 'run_cancelled', runId, threadId, sessionId: execution?.sessionId, timestamp: Date.now() });
3067
- sendJSON(req, res, 200, cancelledRun);
3068
- } catch (err) {
3069
- sendJSON(req, res, 500, { error: err.message, type: 'internal_error' });
3070
- }
3071
- return;
3072
- }
3073
-
3074
- // GET /threads/{thread_id}/runs/{run_id}/wait - Long-poll for run completion on thread
3075
- const threadRunWaitMatch = pathOnly.match(/^\/api\/threads\/([a-f0-9-]{36})\/runs\/([a-f0-9-]{36})\/wait$/);
3076
- if (threadRunWaitMatch && req.method === 'GET') {
3077
- const threadId = threadRunWaitMatch[1];
3078
- const runId = threadRunWaitMatch[2];
3079
- const run = queries.getRun(runId);
3080
- if (!run || run.thread_id !== threadId) {
3081
- sendJSON(req, res, 404, { error: 'Run not found on thread', type: 'not_found' });
3082
- return;
3083
- }
3084
- const startTime = Date.now();
3085
- const pollInterval = setInterval(() => {
3086
- const currentRun = queries.getRun(runId);
3087
- const elapsed = Date.now() - startTime;
3088
- const done = currentRun && ['success', 'error', 'cancelled'].includes(currentRun.status);
3089
- if (done) {
3090
- clearInterval(pollInterval);
3091
- sendJSON(req, res, 200, currentRun);
3092
- } else if (elapsed > 30000) {
3093
- clearInterval(pollInterval);
3094
- sendJSON(req, res, 408, { error: 'Run still pending after 30s', run_id: runId, status: currentRun?.status || run.status });
3095
- }
3096
- }, 500);
3097
- req.on('close', () => clearInterval(pollInterval));
3098
- return;
3099
- }
3100
-
3101
3038
  if (routePath.startsWith('/api/image/')) {
3102
3039
  const imagePath = routePath.slice('/api/image/'.length);
3103
3040
  const decodedPath = decodeURIComponent(imagePath);