@clagentic/console 1.5.0-beta.1 → 1.5.0-beta.3

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.
@@ -3,13 +3,9 @@
3
3
  // Contains only human-user functionality; all mate-specific rendering is removed.
4
4
 
5
5
  import { userAvatarUrl } from './avatar.js';
6
- import { escapeHtml } from './utils.js';
7
- import { iconHtml, refreshIcons } from './icons.js';
8
6
  import { store } from './store.js';
9
7
  import { getWs } from './ws-ref.js';
10
- import { closeProjectCtxMenu } from './sidebar-projects.js';
11
- import { spawnDustParticles } from './sidebar.js';
12
- import { openDm } from './app-dm.js';
8
+ import { toggleTeamPanel } from './team-panel.js';
13
9
 
14
10
  function sendWs(msg) {
15
11
  var ws = getWs();
@@ -18,7 +14,6 @@ function sendWs(msg) {
18
14
 
19
15
  // --- User strip state ---
20
16
  var cachedAllUsers = [];
21
- var cachedOnlineUserIds = [];
22
17
  var cachedDmFavorites = [];
23
18
  var cachedDmConversations = [];
24
19
  var cachedDmUnread = {};
@@ -27,34 +22,50 @@ var currentDmUserId = null;
27
22
  var dmPickerOpen = false;
28
23
  var cachedDmRemovedUsers = {};
29
24
 
25
+
30
26
  // setMentionActive / clearAllMentionActive kept as no-ops for call-site
31
27
  // compatibility — mentions were a mates-only feature.
32
28
  export function setMentionActive(mateId, active) { /* no-op: mates removed */ }
33
29
  export function clearAllMentionActive() { /* no-op: mates removed */ }
34
30
 
35
- var _lastUserStripJson = "";
36
-
37
31
  // --- Icon strip tooltip ---
38
32
  var iconStripTooltip = null;
39
33
 
40
- // --- DM user context menu ---
41
- var userCtxMenu = null;
42
-
43
34
  export function initSidebarUsers() {
44
- // Reactive UI sync for user strip
45
- store.subscribe(['cachedAllUsers', 'cachedOnlineIds', 'cachedDmFavorites', 'cachedDmConversations', 'dmUnread', 'dmRemovedUsers', 'myUserId'], function (state, prev) {
46
- if (state.cachedAllUsers !== prev.cachedAllUsers ||
47
- state.cachedOnlineIds !== prev.cachedOnlineIds ||
48
- state.cachedDmFavorites !== prev.cachedDmFavorites ||
49
- state.cachedDmConversations !== prev.cachedDmConversations ||
50
- state.dmUnread !== prev.dmUnread ||
51
- state.dmRemovedUsers !== prev.dmRemovedUsers ||
52
- state.myUserId !== prev.myUserId) {
53
- renderUserStrip();
35
+ // Wire the permanent Teams button in the icon strip.
36
+ var teamBtn = document.getElementById("icon-strip-team-btn");
37
+ if (teamBtn) {
38
+ teamBtn.addEventListener("click", function () {
39
+ if (typeof toggleTeamPanel === "function") toggleTeamPanel();
40
+ });
41
+ teamBtn.addEventListener("mouseenter", function () { showIconTooltip(teamBtn, "Team"); });
42
+ teamBtn.addEventListener("mouseleave", hideIconTooltip);
43
+ }
44
+
45
+ // Keep local caches in sync with the store so getCachedDm* accessors and
46
+ // the DM picker remain accurate even though nothing renders in the icon strip.
47
+ store.subscribe(['cachedAllUsers', 'cachedOnlineIds', 'cachedDmFavorites', 'cachedDmConversations', 'dmUnread', 'dmRemovedUsers', 'myUserId'], function (state) {
48
+ cachedAllUsers = state.cachedAllUsers || [];
49
+ cachedDmFavorites = state.cachedDmFavorites || [];
50
+ cachedDmConversations = state.cachedDmConversations || [];
51
+ cachedDmUnread = state.dmUnread || {};
52
+ cachedDmRemovedUsers = state.dmRemovedUsers || {};
53
+ cachedMyUserId = state.myUserId;
54
+ });
55
+
56
+ // Request agent list on connect/reconnect so favorites are populated.
57
+ store.subscribe(['connected'], function (state, prev) {
58
+ if (state.connected && !prev.connected) {
59
+ sendWs({ type: "list_agents" });
54
60
  }
55
61
  });
56
62
  }
57
63
 
64
+ // handleAgentsList: no-op stub — agent-picker.js is the authoritative consumer.
65
+ // This export is kept because app-messages.js imports it as handleAgentsListTeam.
66
+ // TODO(lr-teams-icon-strip): remove this alias once app-messages.js import is cleaned up.
67
+ export function handleAgentsList(_msg) { /* no-op: agent-picker.js handles agents_list */ }
68
+
58
69
  export function showIconTooltip(el, text) {
59
70
  hideIconTooltip();
60
71
  var tip = document.createElement("div");
@@ -94,63 +105,10 @@ export function hideIconTooltip() {
94
105
  }
95
106
  }
96
107
 
97
- export function closeUserCtxMenu() {
98
- if (userCtxMenu) {
99
- userCtxMenu.remove();
100
- userCtxMenu = null;
101
- }
102
- document.removeEventListener("click", handleUserCtxOutsideClick, true);
103
- }
104
-
105
- function showUserCtxMenu(anchorEl, user) {
106
- closeUserCtxMenu();
107
- if (closeProjectCtxMenu) closeProjectCtxMenu();
108
-
109
- var menu = document.createElement("div");
110
- menu.className = "project-ctx-menu";
111
-
112
- var removeItem = document.createElement("button");
113
- removeItem.className = "project-ctx-item project-ctx-delete";
114
- removeItem.innerHTML = iconHtml("user-minus") + " <span>Remove from favorites</span>";
115
- removeItem.addEventListener("click", function (e) {
116
- e.stopPropagation();
117
- var iconRect = anchorEl.getBoundingClientRect();
118
- if (spawnDustParticles) spawnDustParticles(iconRect.left + iconRect.width / 2, iconRect.top + iconRect.height / 2);
119
- closeUserCtxMenu();
120
- cachedDmRemovedUsers[user.id] = true;
121
- var dr = Object.assign({}, store.get('dmRemovedUsers')); dr[user.id] = true; store.set({ dmRemovedUsers: dr });
122
- sendWs({ type: "dm_remove_favorite", targetUserId: user.id });
123
- });
124
- menu.appendChild(removeItem);
125
-
126
- document.body.appendChild(menu);
127
- userCtxMenu = menu;
128
- refreshIcons();
129
-
130
- requestAnimationFrame(function () {
131
- var rect = anchorEl.getBoundingClientRect();
132
- menu.style.position = "fixed";
133
- menu.style.left = (rect.right + 6) + "px";
134
- menu.style.top = rect.top + "px";
135
- var menuRect = menu.getBoundingClientRect();
136
- if (menuRect.right > window.innerWidth - 8) {
137
- menu.style.left = (rect.left - menuRect.width - 6) + "px";
138
- }
139
- if (menuRect.bottom > window.innerHeight - 8) {
140
- menu.style.top = (window.innerHeight - menuRect.height - 8) + "px";
141
- }
142
- });
143
-
144
- setTimeout(function () {
145
- document.addEventListener("click", handleUserCtxOutsideClick, true);
146
- }, 0);
147
- }
148
-
149
- function handleUserCtxOutsideClick(e) {
150
- if (userCtxMenu && !userCtxMenu.contains(e.target)) {
151
- closeUserCtxMenu();
152
- }
153
- }
108
+ // closeUserCtxMenu: no-op stub retained for sidebar-projects.js and sidebar.js
109
+ // imports. The user context menu was attached to per-user icon-strip items that
110
+ // no longer exist; nothing can open it, so nothing needs to close it.
111
+ export function closeUserCtxMenu() { /* no-op: icon-strip user context menu removed */ }
154
112
 
155
113
  var _lastSidebarPresenceIds = [];
156
114
  export function renderSidebarPresence(onlineUsers) {
@@ -185,216 +143,12 @@ export function renderSidebarPresence(onlineUsers) {
185
143
  }
186
144
  }
187
145
 
188
- // renderUserStrip: call with no args to read from store (subscriber pattern).
189
- export function renderUserStrip(allUsers, onlineUserIds, myUserId, dmFavorites, dmConversations, dmUnread, dmRemovedUsers) {
190
- if (arguments.length === 0) {
191
- var s = store.snap();
192
- allUsers = s.cachedAllUsers;
193
- onlineUserIds = s.cachedOnlineIds;
194
- myUserId = s.myUserId;
195
- dmFavorites = s.cachedDmFavorites;
196
- dmConversations = s.cachedDmConversations;
197
- dmUnread = s.dmUnread;
198
- dmRemovedUsers = s.dmRemovedUsers;
199
- }
200
-
201
- var fingerprint = JSON.stringify([allUsers, onlineUserIds, dmFavorites, dmConversations, dmUnread, dmRemovedUsers]);
202
- if (fingerprint === _lastUserStripJson) return;
203
- _lastUserStripJson = fingerprint;
204
-
205
- cachedAllUsers = allUsers || [];
206
- cachedOnlineUserIds = onlineUserIds || [];
207
- cachedDmFavorites = dmFavorites || [];
208
- cachedDmConversations = dmConversations || [];
209
- cachedDmUnread = dmUnread || {};
210
- cachedDmRemovedUsers = dmRemovedUsers || {};
211
- cachedMyUserId = myUserId;
212
-
213
- var container = document.getElementById("icon-strip-users");
214
- if (!container) return;
215
-
216
- var allOthers = cachedAllUsers.filter(function (u) { return u.id !== myUserId; });
217
-
218
- // Hide section if no other users
219
- if (allOthers.length === 0) {
220
- container.innerHTML = "";
221
- container.classList.add("hidden");
222
- return;
223
- }
224
-
225
- // Show only favorites + users with unread + users with DM conversations
226
- var others = allOthers.filter(function (u) {
227
- if (cachedDmRemovedUsers[u.id]) return false;
228
- if (cachedDmFavorites.indexOf(u.id) !== -1) return true;
229
- if (cachedDmUnread[u.id] && cachedDmUnread[u.id] > 0) return true;
230
- if (cachedDmConversations.indexOf(u.id) !== -1) return true;
231
- return false;
232
- });
233
-
234
- container.classList.remove("hidden");
235
- container.innerHTML = "";
236
-
237
- for (var i = 0; i < others.length; i++) {
238
- (function (u) {
239
- var el = document.createElement("div");
240
- el.className = "icon-strip-user";
241
- el.dataset.userId = u.id;
242
- if (u.id === currentDmUserId) el.classList.add("active");
243
- if (onlineUserIds.indexOf(u.id) !== -1) el.classList.add("online");
244
-
245
- var pill = document.createElement("span");
246
- pill.className = "icon-strip-pill";
247
- el.appendChild(pill);
248
-
249
- var avatar = document.createElement("img");
250
- avatar.className = "icon-strip-user-avatar";
251
- avatar.src = userAvatarUrl(u, 34);
252
- avatar.alt = u.displayName;
253
- el.appendChild(avatar);
254
-
255
- var onlineDot = document.createElement("span");
256
- onlineDot.className = "icon-strip-user-online";
257
- el.appendChild(onlineDot);
258
-
259
- var badge = document.createElement("span");
260
- badge.className = "icon-strip-user-badge";
261
- badge.dataset.userId = u.id;
262
- el.appendChild(badge);
263
-
264
- var unreadCount = cachedDmUnread[u.id] || 0;
265
- if (unreadCount > 0 && u.id !== currentDmUserId) {
266
- badge.textContent = unreadCount > 99 ? "99+" : String(unreadCount);
267
- badge.classList.add("has-unread");
268
- }
269
-
270
- el.addEventListener("mouseenter", function () { showIconTooltip(el, u.displayName); });
271
- el.addEventListener("mouseleave", hideIconTooltip);
272
-
273
- el.addEventListener("click", function () {
274
- if (openDm) openDm(u.id);
275
- });
276
-
277
- el.addEventListener("contextmenu", function (e) {
278
- e.preventDefault();
279
- e.stopPropagation();
280
- showUserCtxMenu(el, u);
281
- });
282
-
283
- container.appendChild(el);
284
- })(others[i]);
285
- }
286
-
287
- // Add user (+) button — only shown in multi-user mode
288
- if (store.get('isMultiUserMode')) {
289
- var addBtn = document.createElement("button");
290
- addBtn.className = "icon-strip-invite";
291
- addBtn.innerHTML = iconHtml("user-plus");
292
- addBtn.addEventListener("click", function (e) {
293
- e.stopPropagation();
294
- toggleDmUserPicker(addBtn);
295
- });
296
- addBtn.addEventListener("mouseenter", function () { showIconTooltip(addBtn, "Add user"); });
297
- addBtn.addEventListener("mouseleave", hideIconTooltip);
298
- container.appendChild(addBtn);
299
- refreshIcons();
300
- }
301
- }
302
-
303
- function toggleDmUserPicker(anchorEl) {
304
- if (dmPickerOpen) {
305
- closeDmUserPicker();
306
- return;
307
- }
308
- dmPickerOpen = true;
309
-
310
- var picker = document.createElement("div");
311
- picker.className = "dm-user-picker";
312
- picker.id = "dm-user-picker";
313
-
314
- var searchInput = document.createElement("input");
315
- searchInput.className = "dm-user-picker-search";
316
- searchInput.type = "text";
317
- searchInput.placeholder = "Search users...";
318
- picker.appendChild(searchInput);
319
-
320
- var usersLabel = document.createElement("div");
321
- usersLabel.className = "dm-user-picker-section";
322
- usersLabel.textContent = "Users";
323
- picker.appendChild(usersLabel);
324
-
325
- var listEl = document.createElement("div");
326
- listEl.className = "dm-user-picker-list";
327
- picker.appendChild(listEl);
328
-
329
- document.body.appendChild(picker);
330
- var rect = anchorEl.getBoundingClientRect();
331
- picker.style.left = (rect.right + 8) + "px";
332
- picker.style.bottom = (window.innerHeight - rect.bottom) + "px";
146
+ // renderUserStrip: retained as a no-op export — callers in app-messages.js
147
+ // invoke this on projects_updated. The icon strip no longer shows per-user
148
+ // avatars; all that lives in the team panel (opened via #icon-strip-team-btn).
149
+ // TODO(lr-teams-icon-strip): remove call sites in app-messages.js once callers are updated.
150
+ export function renderUserStrip() { /* no-op: team panel replaced icon-strip avatars */ }
333
151
 
334
- function renderPickerList(filter) {
335
- listEl.innerHTML = "";
336
- var allOthers = cachedAllUsers.filter(function (u) { return u.id !== cachedMyUserId; });
337
- var available = allOthers.filter(function (u) {
338
- return cachedDmFavorites.indexOf(u.id) === -1;
339
- });
340
- if (filter) {
341
- var lf = filter.toLowerCase();
342
- available = available.filter(function (u) {
343
- return (u.displayName && u.displayName.toLowerCase().indexOf(lf) !== -1) ||
344
- (u.username && u.username.toLowerCase().indexOf(lf) !== -1);
345
- });
346
- }
347
- if (available.length === 0) {
348
- var emptyEl = document.createElement("div");
349
- emptyEl.className = "dm-user-picker-empty";
350
- emptyEl.textContent = filter ? "No users found" : "No more users to add";
351
- listEl.appendChild(emptyEl);
352
- return;
353
- }
354
- for (var i = 0; i < available.length; i++) {
355
- (function (u) {
356
- var item = document.createElement("div");
357
- item.className = "dm-user-picker-item";
358
-
359
- var av = document.createElement("img");
360
- av.className = "dm-user-picker-avatar";
361
- av.src = userAvatarUrl(u, 28);
362
- av.alt = u.displayName;
363
- item.appendChild(av);
364
-
365
- var name = document.createElement("span");
366
- name.className = "dm-user-picker-name";
367
- name.textContent = u.displayName;
368
- item.appendChild(name);
369
-
370
- item.addEventListener("click", function () {
371
- sendWs({ type: "dm_add_favorite", targetUserId: u.id });
372
- closeDmUserPicker();
373
- });
374
-
375
- listEl.appendChild(item);
376
- })(available[i]);
377
- }
378
- }
379
-
380
- renderPickerList("");
381
- searchInput.addEventListener("input", function () {
382
- renderPickerList(searchInput.value);
383
- });
384
-
385
- setTimeout(function () { searchInput.focus(); }, 50);
386
-
387
- function onDocClick(e) {
388
- if (!picker.contains(e.target) && e.target !== anchorEl && !anchorEl.contains(e.target)) {
389
- closeDmUserPicker();
390
- document.removeEventListener("click", onDocClick, true);
391
- }
392
- }
393
- setTimeout(function () {
394
- document.addEventListener("click", onDocClick, true);
395
- }, 10);
396
- picker._docClickHandler = onDocClick;
397
- }
398
152
 
399
153
  export function closeDmUserPicker() {
400
154
  dmPickerOpen = false;
@@ -409,28 +163,14 @@ export function closeDmUserPicker() {
409
163
 
410
164
  export function setCurrentDmUser(userId) {
411
165
  currentDmUserId = userId;
412
- // Update active state on icon strip items
413
- var items = document.querySelectorAll("#icon-strip-users .icon-strip-user");
414
- for (var i = 0; i < items.length; i++) {
415
- if (items[i].dataset.userId === userId) {
416
- items[i].classList.add("active");
417
- } else {
418
- items[i].classList.remove("active");
419
- }
420
- }
166
+ // Icon-strip user avatars are gone; active DM state is tracked in currentDmUserId
167
+ // for use by the team panel and DM picker.
421
168
  }
422
169
 
423
- export function updateDmBadge(userId, count) {
424
- var badge = document.querySelector("#icon-strip-users .icon-strip-user-badge[data-user-id='" + userId + "']");
425
- if (!badge) return;
426
- if (count && count > 0) {
427
- badge.textContent = count > 99 ? "99+" : String(count);
428
- badge.classList.add("has-unread");
429
- } else {
430
- badge.textContent = "";
431
- badge.classList.remove("has-unread");
432
- }
433
- }
170
+ // updateDmBadge: retained as a no-op export — DM unread counts are now shown
171
+ // only inside the team panel, not in the icon strip.
172
+ // TODO(lr-teams-icon-strip): wire to team panel badge once panel shows DM counts.
173
+ export function updateDmBadge(userId, count) { /* no-op: icon-strip user badges removed */ }
434
174
 
435
175
  export function getCurrentDmUserId() {
436
176
  return currentDmUserId;