agentgui 1.0.457 → 1.0.459

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/static/js/client.js +76 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentgui",
3
- "version": "1.0.457",
3
+ "version": "1.0.459",
4
4
  "description": "Multi-agent ACP client with real-time communication",
5
5
  "type": "module",
6
6
  "main": "server.js",
@@ -49,6 +49,7 @@ class AgentGUIClient {
49
49
  };
50
50
 
51
51
  this._agentLocked = false;
52
+ this._isLoadingConversation = false;
52
53
  this._modelCache = new Map();
53
54
 
54
55
  this.chunkPollState = {
@@ -217,11 +218,13 @@ class AgentGUIClient {
217
218
  this.routerState.currentSessionId = sessionId;
218
219
  }
219
220
  console.log('Restoring conversation from URL:', conversationId);
220
- this.state.currentConversation = conversationId;
221
+ this._isLoadingConversation = true;
221
222
  if (window.conversationManager) {
222
223
  window.conversationManager.select(conversationId);
223
224
  } else {
224
- this.loadConversationMessages(conversationId);
225
+ this.loadConversationMessages(conversationId).finally(() => {
226
+ this._isLoadingConversation = false;
227
+ });
225
228
  }
226
229
  }
227
230
  }
@@ -451,19 +454,31 @@ class AgentGUIClient {
451
454
  });
452
455
 
453
456
  // Listen for conversation selection
454
- window.addEventListener('conversation-selected', (event) => {
457
+ window.addEventListener('conversation-selected', async (event) => {
455
458
  const conversationId = event.detail.conversationId;
456
459
  this.updateUrlForConversation(conversationId);
457
- this.loadConversationMessages(conversationId);
460
+ this._isLoadingConversation = true;
461
+ try {
462
+ await this.loadConversationMessages(conversationId);
463
+ } finally {
464
+ this._isLoadingConversation = false;
465
+ }
458
466
  });
459
467
 
460
468
  // Listen for active conversation deletion
461
469
  window.addEventListener('conversation-deselected', () => {
462
470
  this.state.currentConversation = null;
471
+ this.state.currentSession = null;
463
472
  this.updateUrlForConversation(null);
473
+ this.stopChunkPolling();
474
+ this.enableControls();
464
475
  const outputEl = document.getElementById('output');
465
476
  if (outputEl) outputEl.innerHTML = '';
466
- if (this.ui.messageInput) this.ui.messageInput.value = '';
477
+ if (this.ui.messageInput) {
478
+ this.ui.messageInput.value = '';
479
+ this.ui.messageInput.disabled = false;
480
+ this.ui.messageInput.style.height = 'auto';
481
+ }
467
482
  this.unlockAgentAndModel();
468
483
  });
469
484
  }
@@ -1257,17 +1272,13 @@ class AgentGUIClient {
1257
1272
 
1258
1273
  async startExecution() {
1259
1274
  const prompt = this.ui.messageInput?.value || '';
1260
- const conv = this.state.currentConversation;
1261
- const isNewConversation = conv && !conv.messageCount && !this.state.streamingConversations.has(conv.id);
1262
- const agentId = (isNewConversation ? this.getCurrentAgent() : null) || conv?.agentType || this.getCurrentAgent();
1263
- const subAgent = this.getEffectiveSubAgent() || conv?.subAgent || null;
1264
- const model = this.ui.modelSelector?.value || null;
1265
1275
 
1266
1276
  if (!prompt.trim()) {
1267
1277
  this.showError('Please enter a prompt');
1268
1278
  return;
1269
1279
  }
1270
1280
 
1281
+ this.disableControls();
1271
1282
  const savedPrompt = prompt;
1272
1283
  if (this.ui.messageInput) {
1273
1284
  this.ui.messageInput.value = '';
@@ -1276,14 +1287,36 @@ class AgentGUIClient {
1276
1287
 
1277
1288
  const pendingId = 'pending-' + Date.now() + '-' + Math.random().toString(36).substr(2, 6);
1278
1289
  this._showOptimisticMessage(pendingId, savedPrompt);
1279
- this.disableControls();
1280
1290
 
1281
1291
  try {
1292
+ let conv = this.state.currentConversation;
1293
+
1294
+ if (this._isLoadingConversation) {
1295
+ this.showError('Conversation still loading. Please try again.');
1296
+ this.enableControls();
1297
+ return;
1298
+ }
1299
+
1300
+ if (conv && typeof conv === 'string') {
1301
+ this.showError('Conversation state invalid. Please reload.');
1302
+ this.enableControls();
1303
+ return;
1304
+ }
1305
+
1282
1306
  if (conv?.id) {
1307
+ const isNewConversation = !conv.messageCount && !this.state.streamingConversations.has(conv.id);
1308
+ const agentId = (isNewConversation ? this.getCurrentAgent() : null) || conv?.agentType || this.getCurrentAgent();
1309
+ const subAgent = this.getEffectiveSubAgent() || conv?.subAgent || null;
1310
+ const model = this.ui.modelSelector?.value || null;
1311
+
1283
1312
  this.lockAgentAndModel(agentId, model);
1284
1313
  await this.streamToConversation(conv.id, savedPrompt, agentId, model, subAgent);
1285
1314
  this._confirmOptimisticMessage(pendingId);
1286
1315
  } else {
1316
+ const agentId = this.getCurrentAgent();
1317
+ const subAgent = this.getEffectiveSubAgent() || null;
1318
+ const model = this.ui.modelSelector?.value || null;
1319
+
1287
1320
  const body = { agentId, title: savedPrompt.substring(0, 50) };
1288
1321
  if (model) body.model = model;
1289
1322
  if (subAgent) body.subAgent = subAgent;
@@ -2174,12 +2207,32 @@ class AgentGUIClient {
2174
2207
  * Disable UI controls during streaming
2175
2208
  */
2176
2209
  disableControls() {
2210
+ if (this.ui.messageInput) {
2211
+ this.ui.messageInput.disabled = true;
2212
+ }
2213
+ if (this.ui.sendButton) {
2214
+ this.ui.sendButton.disabled = true;
2215
+ }
2216
+ const injectBtn = document.getElementById('injectBtn');
2217
+ const stopBtn = document.getElementById('stopBtn');
2218
+ if (injectBtn) injectBtn.disabled = true;
2219
+ if (stopBtn) stopBtn.disabled = false;
2177
2220
  }
2178
2221
 
2179
2222
  /**
2180
2223
  * Enable UI controls
2181
2224
  */
2182
2225
  enableControls() {
2226
+ if (this.ui.messageInput) {
2227
+ this.ui.messageInput.disabled = false;
2228
+ }
2229
+ if (this.ui.sendButton) {
2230
+ this.ui.sendButton.disabled = false;
2231
+ }
2232
+ const injectBtn = document.getElementById('injectBtn');
2233
+ const stopBtn = document.getElementById('stopBtn');
2234
+ if (injectBtn) injectBtn.disabled = false;
2235
+ if (stopBtn) stopBtn.disabled = true;
2183
2236
  }
2184
2237
 
2185
2238
  /**
@@ -2259,6 +2312,13 @@ class AgentGUIClient {
2259
2312
  if (this.renderer.resetScrollState) this.renderer.resetScrollState();
2260
2313
  this._userScrolledUp = false;
2261
2314
  this._removeNewContentPill();
2315
+
2316
+ if (this.ui.messageInput) {
2317
+ this.ui.messageInput.value = '';
2318
+ this.ui.messageInput.style.height = 'auto';
2319
+ this.ui.messageInput.disabled = false;
2320
+ }
2321
+
2262
2322
  var prevId = this.state.currentConversation?.id;
2263
2323
  if (prevId && prevId !== conversationId) {
2264
2324
  if (this.wsManager.isConnected && !this.state.streamingConversations.has(prevId)) {
@@ -2267,6 +2327,11 @@ class AgentGUIClient {
2267
2327
  this.state.currentSession = null;
2268
2328
  }
2269
2329
 
2330
+ const cachedConv = this.state.conversations.find(c => c.id === conversationId);
2331
+ if (cachedConv && this.state.currentConversation?.id !== conversationId) {
2332
+ this.state.currentConversation = cachedConv;
2333
+ }
2334
+
2270
2335
  this.updateUrlForConversation(conversationId);
2271
2336
  if (this.wsManager.isConnected) {
2272
2337
  this.wsManager.sendMessage({ type: 'subscribe', conversationId });