@yeaft/webchat-agent 0.1.484 → 0.1.485

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.1.484",
3
+ "version": "0.1.485",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,6 +16,7 @@
16
16
  import { loadSession } from './session.js';
17
17
  import { sendToServer } from '../connection/buffer.js';
18
18
  import ctx from '../context.js';
19
+ import { getThreadStore } from './threads/store.js';
19
20
 
20
21
  /** @type {import('./session.js').Session | null} */
21
22
  let session = null;
@@ -72,6 +73,49 @@ function sendUnifyEvent(event) {
72
73
  });
73
74
  }
74
75
 
76
+ /**
77
+ * task-301 Part 2: push the full thread list snapshot to the web client.
78
+ * Called after any ThreadStore-mutating tool completes and at turn_end so
79
+ * the sidebar V2 always shows a fresh picture. Cheap — ThreadStore keeps
80
+ * cached counters so list() is O(n) over a small n.
81
+ */
82
+ function sendThreadListUpdate() {
83
+ try {
84
+ const store = getThreadStore();
85
+ const threads = store.list().map(t => ({
86
+ id: t.id,
87
+ name: t.name,
88
+ goal: t.goal || '',
89
+ parentThreadId: t.parentThreadId || null,
90
+ status: t.status,
91
+ archived: !!t.archived,
92
+ messageCount: t.messageCount || 0,
93
+ lastMessageAt: t.lastMessageAt || null,
94
+ lastActivityAt: t.lastActivityAt || t.lastMessageAt || t.updatedAt || null,
95
+ unread: t.unread || 0,
96
+ preview: t.preview || '',
97
+ createdAt: t.createdAt,
98
+ updatedAt: t.updatedAt,
99
+ // `running` — the thread whose id equals the store's currentId is
100
+ // considered the active/running track. The UI uses this for the
101
+ // green halo in the Active group.
102
+ running: t.id === store.currentId,
103
+ }));
104
+ sendUnifyEvent({ type: 'thread_list_updated', threads, currentThreadId: store.currentId });
105
+ } catch (err) {
106
+ // Best-effort; sidebar update must never block the main query path.
107
+ console.warn('[Unify] sendThreadListUpdate failed:', err?.message || err);
108
+ }
109
+ }
110
+
111
+ /** Tool names that mutate ThreadStore. After any of these we push an update. */
112
+ const THREAD_MUTATING_TOOLS = new Set([
113
+ 'SpawnThread',
114
+ 'SwitchThread',
115
+ 'ArchiveThread',
116
+ 'AttachThreadToTask',
117
+ ]);
118
+
75
119
  /**
76
120
  * Handle a unify_chat message from the web UI.
77
121
  *
@@ -118,6 +162,9 @@ export async function handleUnifyChat(msg) {
118
162
  mcpServers: session.status.mcpServers,
119
163
  tools: session.status.tools,
120
164
  });
165
+ // task-301 Part 2: initial thread snapshot so sidebar V2 renders
166
+ // the real 'main' thread (and any restored threads) right away.
167
+ sendThreadListUpdate();
121
168
  }
122
169
 
123
170
  // ─── Cancel any in-flight query ──
@@ -214,6 +261,11 @@ export async function handleUnifyChat(msg) {
214
261
  }],
215
262
  threadId: event.threadId,
216
263
  });
264
+ // task-301 Part 2: if this tool mutates ThreadStore, push a
265
+ // fresh snapshot to the sidebar immediately.
266
+ if (THREAD_MUTATING_TOOLS.has(event.name)) {
267
+ sendThreadListUpdate();
268
+ }
217
269
  break;
218
270
 
219
271
  // ── Turn boundaries ──
@@ -476,6 +528,8 @@ export async function handleUnifyLoadHistory(msg) {
476
528
  mcpServers: session.status.mcpServers,
477
529
  tools: session.status.tools,
478
530
  });
531
+ // task-301 Part 2: initial thread snapshot for history-load session.
532
+ sendThreadListUpdate();
479
533
  }
480
534
 
481
535
  const limit = msg.limit || 50;
@@ -548,6 +602,8 @@ export async function resetUnifySession() {
548
602
  mcpServers: session.status.mcpServers,
549
603
  tools: session.status.tools,
550
604
  });
605
+ // task-301 Part 2: re-push thread snapshot after session reset.
606
+ sendThreadListUpdate();
551
607
  } catch (err) {
552
608
  console.error('[Unify] Failed to re-initialize session after reset:', err.message);
553
609
  }