@clagentic/console 1.12.0-beta.1 → 1.12.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.
- package/LICENSES/README.md +5 -0
- package/README.md +1 -0
- package/bin/cli.js +5 -2
- package/lib/agent-roster-ws.js +84 -0
- package/lib/agent-roster.js +312 -0
- package/lib/auth-required-notify.js +42 -0
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-notify.js +45 -0
- package/lib/build-update-offer.js +34 -11
- package/lib/build-update-standing.js +34 -14
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/duration.js +27 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +60 -11
- package/lib/client-address.js +44 -0
- package/lib/daemon.js +31 -10
- package/lib/idle-compaction-setting.js +203 -0
- package/lib/mcp-bridge-credential.js +41 -0
- package/lib/notification-prefs.js +18 -22
- package/lib/notify/core.js +210 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +62 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +81 -0
- package/lib/notify/types.js +57 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +85 -0
- package/lib/outbound-entry.js +116 -0
- package/lib/outbound-ledger.js +306 -0
- package/lib/outbound-query.js +153 -0
- package/lib/pending-prompts.js +31 -16
- package/lib/project-connection.js +48 -8
- package/lib/project-filesystem.js +43 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +38 -26
- package/lib/project-notifications.js +122 -39
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +11 -1
- package/lib/project-user-mention.js +22 -34
- package/lib/project-user-message.js +208 -4
- package/lib/project-user-shell.js +298 -0
- package/lib/project.js +41 -5
- package/lib/prompt-answer.js +145 -0
- package/lib/prompt-expiry.js +50 -0
- package/lib/prompt-registry.js +98 -25
- package/lib/prompt-reminders.js +38 -33
- package/lib/prompt-source.js +59 -8
- package/lib/public/app.js +32 -2
- package/lib/public/css/agent-messages.css +96 -0
- package/lib/public/css/agent-roster.css +93 -0
- package/lib/public/css/diagnostics.css +29 -1
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/input.css +20 -141
- package/lib/public/css/login-panel.css +73 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/sidebar.css +18 -0
- package/lib/public/css/team-panel.css +1 -6
- package/lib/public/css/team-view.css +101 -0
- package/lib/public/css/title-bar.css +10 -0
- package/lib/public/css/user-shell.css +144 -0
- package/lib/public/index.html +44 -7
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/agent-avatar-picker.js +162 -0
- package/lib/public/modules/agent-avatar.js +153 -0
- package/lib/public/modules/agent-messages.js +285 -0
- package/lib/public/modules/agent-roster.js +157 -0
- package/lib/public/modules/app-connection.js +34 -5
- package/lib/public/modules/app-messages.js +55 -16
- package/lib/public/modules/app-notifications.js +104 -75
- package/lib/public/modules/app-panels.js +26 -3
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +8 -165
- package/lib/public/modules/app-rendering.js +32 -7
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/collapsible-text.js +33 -18
- package/lib/public/modules/compaction-state.js +34 -0
- package/lib/public/modules/custom-icons.js +23 -5
- package/lib/public/modules/diagnostics.js +61 -57
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/injected-identity.js +24 -21
- package/lib/public/modules/input.js +176 -15
- package/lib/public/modules/login-panel.js +136 -0
- package/lib/public/modules/login-parser.js +73 -0
- package/lib/public/modules/login-tab.js +66 -0
- package/lib/public/modules/notifications.js +9 -1
- package/lib/public/modules/notify-client.js +246 -0
- package/lib/public/modules/pending-term-request.js +30 -0
- package/lib/public/modules/project-icon.js +22 -2
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/queued-button.js +11 -0
- package/lib/public/modules/scheduled-input-actions.js +12 -4
- package/lib/public/modules/scheduled-outbox.js +230 -0
- package/lib/public/modules/send-now.js +200 -0
- package/lib/public/modules/server-settings.js +50 -1
- package/lib/public/modules/shell-card.js +76 -0
- package/lib/public/modules/shell-line.js +49 -0
- package/lib/public/modules/shell-queue.js +253 -0
- package/lib/public/modules/shell-settings-controls.js +76 -0
- package/lib/public/modules/sidebar-mobile.js +3 -3
- package/lib/public/modules/sidebar-sessions.js +8 -0
- package/lib/public/modules/sidebar-users.js +5 -7
- package/lib/public/modules/team-panel.js +30 -88
- package/lib/public/modules/team-view.js +211 -0
- package/lib/public/modules/terminal-links.js +193 -0
- package/lib/public/modules/terminal.js +84 -107
- package/lib/public/modules/tools.js +19 -0
- package/lib/public/modules/user-shell.js +824 -0
- package/lib/public/notify-sw-logic.js +252 -0
- package/lib/public/notify-target.js +157 -0
- package/lib/public/style.css +5 -0
- package/lib/public/sw.js +20 -69
- package/lib/push.js +63 -19
- package/lib/queued-chat.js +392 -0
- package/lib/runtime-env.js +1 -0
- package/lib/scheduled-input/ws.js +67 -9
- package/lib/sdk-bridge.js +184 -73
- package/lib/sdk-message-processor.js +124 -76
- package/lib/server-auth.js +6 -4
- package/lib/server-dm.js +11 -20
- package/lib/server-settings.js +39 -1
- package/lib/server.js +112 -16
- package/lib/session-directory.js +39 -12
- package/lib/session-end.js +97 -0
- package/lib/session-input-ipc.js +37 -1
- package/lib/session-input.js +263 -21
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/session-resume.js +1 -0
- package/lib/session-settings-file.js +53 -0
- package/lib/sessions.js +80 -9
- package/lib/team-traffic-ws.js +68 -0
- package/lib/team-traffic.js +318 -0
- package/lib/usage-store.js +36 -7
- package/lib/user-shell-settings.js +105 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +33 -5
- package/lib/yoke/adapters/claude-capabilities.js +2 -0
- package/lib/yoke/adapters/claude-vendor.js +17 -1
- package/lib/yoke/adapters/claude-worker.js +39 -11
- package/lib/yoke/adapters/claude.js +225 -6
- package/lib/yoke/adapters/codex-capabilities.js +6 -1
- package/lib/yoke/adapters/codex-user-shell.js +265 -0
- package/lib/yoke/adapters/codex-vendor.js +7 -0
- package/lib/yoke/adapters/codex.js +186 -52
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/codex-app-server.js +8 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/interface.js +54 -1
- package/lib/yoke/mcp-bridge-server.js +12 -8
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +40 -1
- package/lib/yoke/user-shell.js +224 -0
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
- package/lib/public/modules/build-notice-gate.js +0 -73
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// agent-messages.js - the Team view's agent-messages section: the agent-to-agent
|
|
2
|
+
// traffic that went through the console (open-session, send-input, scheduled
|
|
3
|
+
// input, replies), as a map of who talks to whom and a thread per pair.
|
|
4
|
+
//
|
|
5
|
+
// Read-only. The server (lib/team-traffic.js) builds the snapshot from the
|
|
6
|
+
// outbound ledger under the ledger's own read rules and sends it when this
|
|
7
|
+
// connection asks; nothing is kept here except the last snapshot, so a reload or
|
|
8
|
+
// a daemon restart rebuilds the same view. A team_traffic_changed message
|
|
9
|
+
// carries no content; it only makes the section ask again.
|
|
10
|
+
|
|
11
|
+
import { store } from './store.js';
|
|
12
|
+
import { getWs } from './ws-ref.js';
|
|
13
|
+
import { registerTeamSection, closeTeamView, isSectionContainerShown } from './team-view.js';
|
|
14
|
+
import { isMobileViewport } from './popover-position.js';
|
|
15
|
+
import { resolveInjectedIdentity } from './injected-identity.js';
|
|
16
|
+
import { applyIdentityAvatar } from './agent-avatar.js';
|
|
17
|
+
import { relativeTime } from './relative-time.js';
|
|
18
|
+
|
|
19
|
+
var SECTION_ID = "agent-messages";
|
|
20
|
+
var AVATAR_SIZE = 24;
|
|
21
|
+
var REQUEST_GAP_MS = 1000;
|
|
22
|
+
|
|
23
|
+
var snapshot = null;
|
|
24
|
+
var selectedKey = null;
|
|
25
|
+
var activeContainer = null;
|
|
26
|
+
var lastRequestAt = 0;
|
|
27
|
+
var trailingTimer = null;
|
|
28
|
+
var openSessionFn = null;
|
|
29
|
+
var knownAgentsFn = function () { return []; };
|
|
30
|
+
|
|
31
|
+
// --- Transport ---
|
|
32
|
+
|
|
33
|
+
// Every request is held to REQUEST_GAP_MS. A request inside the gap is not
|
|
34
|
+
// dropped (the nudge would be lost): one trailing request is scheduled for when
|
|
35
|
+
// the gap ends, and only if the section is still on screen by then.
|
|
36
|
+
function requestTraffic() {
|
|
37
|
+
var now = Date.now();
|
|
38
|
+
var wait = REQUEST_GAP_MS - (now - lastRequestAt);
|
|
39
|
+
if (wait > 0) {
|
|
40
|
+
if (!trailingTimer) {
|
|
41
|
+
trailingTimer = setTimeout(function () {
|
|
42
|
+
trailingTimer = null;
|
|
43
|
+
if (releaseIfClosed()) requestTraffic();
|
|
44
|
+
}, wait);
|
|
45
|
+
if (trailingTimer && typeof trailingTimer.unref === "function") trailingTimer.unref();
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var ws = getWs();
|
|
50
|
+
if (!ws || ws.readyState !== 1) return;
|
|
51
|
+
lastRequestAt = now;
|
|
52
|
+
ws.send(JSON.stringify({ type: "team_traffic_request" }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// --- Text ---
|
|
56
|
+
|
|
57
|
+
var KIND_LABEL = { open: "open", input: "input", scheduled: "scheduled", reply: "reply", loop: "loop" };
|
|
58
|
+
|
|
59
|
+
export function emptyStateText(snap) {
|
|
60
|
+
if (!snap) return "Loading agent messages.";
|
|
61
|
+
if (snap.ok === false) return "Agent messages could not be read: " + (snap.reason || "unknown error") + ".";
|
|
62
|
+
if (snap.note) return snap.note.charAt(0).toUpperCase() + snap.note.slice(1) + ".";
|
|
63
|
+
var withheld = snap.withheld || { count: 0, reasons: [] };
|
|
64
|
+
if (withheld.count > 0) {
|
|
65
|
+
var why = withheld.reasons && withheld.reasons.length ? ": " + withheld.reasons.join("; ") : "";
|
|
66
|
+
return withheld.count + (withheld.count === 1 ? " message is" : " messages are") + " withheld from you" + why + ".";
|
|
67
|
+
}
|
|
68
|
+
return "No agent messages recorded yet. Messages one session sends another with open-session, send-input and scheduled input appear here.";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function endpointLabel(target) {
|
|
72
|
+
var who = target.name || target.agent || "session";
|
|
73
|
+
return target.project ? who + "@" + target.project : who;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function el(tag, className, text) {
|
|
77
|
+
var node = document.createElement(tag);
|
|
78
|
+
if (className) node.className = className;
|
|
79
|
+
if (text !== undefined && text !== null) node.textContent = text;
|
|
80
|
+
return node;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function avatarOf(identity) {
|
|
84
|
+
var img = el("img", "am-avatar");
|
|
85
|
+
img.alt = "";
|
|
86
|
+
img.width = AVATAR_SIZE;
|
|
87
|
+
img.height = AVATAR_SIZE;
|
|
88
|
+
return applyIdentityAvatar(img, identity, AVATAR_SIZE);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function senderIdentity(sender) {
|
|
92
|
+
return resolveInjectedIdentity(sender, "injected:" + (sender.initiator || "unknown"), knownAgentsFn(), AVATAR_SIZE);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function targetIdentity(target) {
|
|
96
|
+
return resolveInjectedIdentity({ senderKind: "extracted", fromName: endpointLabel(target), senderAgent: target.agent }, undefined, knownAgentsFn(), AVATAR_SIZE);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function timeText(ts) {
|
|
100
|
+
return ts ? relativeTime(ts) : "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function senderLabel(pair) {
|
|
104
|
+
var id = senderIdentity(pair.sender);
|
|
105
|
+
var unverified = pair.sender.attribution === "unverified" ? " (unverified)" : "";
|
|
106
|
+
return { identity: id, text: id.name + unverified };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- Views ---
|
|
110
|
+
|
|
111
|
+
function renderPairRow(pair, onSelect) {
|
|
112
|
+
var row = el("button", "am-pair" + (pair.key === selectedKey ? " selected" : ""));
|
|
113
|
+
row.setAttribute("type", "button");
|
|
114
|
+
row.setAttribute("data-pair-key", pair.key);
|
|
115
|
+
var from = senderLabel(pair);
|
|
116
|
+
row.appendChild(avatarOf(from.identity));
|
|
117
|
+
row.appendChild(el("span", "am-pair-name", from.text));
|
|
118
|
+
row.appendChild(el("span", "am-arrow", "→"));
|
|
119
|
+
row.appendChild(avatarOf(targetIdentity(pair.target)));
|
|
120
|
+
row.appendChild(el("span", "am-pair-name", endpointLabel(pair.target)));
|
|
121
|
+
row.appendChild(el("span", "am-count", String(pair.count)));
|
|
122
|
+
if (pair.lastAt) row.appendChild(el("span", "am-last", timeText(pair.lastAt)));
|
|
123
|
+
if (pair.pendingCount > 0) row.appendChild(el("span", "am-chip pending", pair.pendingCount + " pending"));
|
|
124
|
+
row.addEventListener("click", function () { onSelect(pair.key); });
|
|
125
|
+
return row;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function sessionLinkButton(label, link) {
|
|
129
|
+
var btn = el("button", "am-link", label);
|
|
130
|
+
btn.setAttribute("type", "button");
|
|
131
|
+
btn.addEventListener("click", function () {
|
|
132
|
+
if (typeof openSessionFn === "function") openSessionFn(link.project, link.id);
|
|
133
|
+
closeTeamView();
|
|
134
|
+
});
|
|
135
|
+
return btn;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function renderMessage(pair, msg) {
|
|
139
|
+
var item = el("div", "am-message");
|
|
140
|
+
item.setAttribute("data-kind", msg.kind);
|
|
141
|
+
var head = el("div", "am-message-head");
|
|
142
|
+
head.appendChild(avatarOf(senderLabel(pair).identity));
|
|
143
|
+
head.appendChild(el("span", "am-sender", senderLabel(pair).text));
|
|
144
|
+
head.appendChild(el("span", "am-chip kind", KIND_LABEL[msg.kind] || msg.kind));
|
|
145
|
+
var when = el("span", "am-time", timeText(msg.ts));
|
|
146
|
+
when.title = msg.ts;
|
|
147
|
+
head.appendChild(when);
|
|
148
|
+
head.appendChild(el("span", "am-chip result " + msg.result, msg.result + (msg.reason ? ": " + msg.reason : "")));
|
|
149
|
+
item.appendChild(head);
|
|
150
|
+
if (msg.contextNote) item.appendChild(el("div", "am-note", msg.contextNote));
|
|
151
|
+
var text = msg.text === null ? "(no text recorded)" : msg.text + (msg.truncated ? "\n[text cut]" : "");
|
|
152
|
+
item.appendChild(el("div", "am-text", text));
|
|
153
|
+
var links = el("div", "am-links");
|
|
154
|
+
if (pair.sender.link) links.appendChild(sessionLinkButton("Sender session", pair.sender.link));
|
|
155
|
+
if (pair.target.link) links.appendChild(sessionLinkButton("Target session", pair.target.link));
|
|
156
|
+
if (pair.sender.link || pair.target.link) item.appendChild(links);
|
|
157
|
+
return item;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function renderPending(pair, p) {
|
|
161
|
+
var item = el("div", "am-message pending");
|
|
162
|
+
item.setAttribute("data-kind", "scheduled");
|
|
163
|
+
var head = el("div", "am-message-head");
|
|
164
|
+
head.appendChild(el("span", "am-sender", senderLabel(pair).text));
|
|
165
|
+
head.appendChild(el("span", "am-chip kind", "scheduled"));
|
|
166
|
+
head.appendChild(el("span", "am-chip pending", "pending"));
|
|
167
|
+
var next = p.nextAt ? "next " + new Date(p.nextAt).toLocaleString() : "";
|
|
168
|
+
head.appendChild(el("span", "am-time", next));
|
|
169
|
+
item.appendChild(head);
|
|
170
|
+
if (p.createdBy) item.appendChild(el("div", "am-note", "scheduled by " + p.createdBy));
|
|
171
|
+
item.appendChild(el("div", "am-text", p.text === null ? "(no text)" : p.text + (p.truncated ? "\n[text cut]" : "")));
|
|
172
|
+
return item;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderThread(container, pair, onBack) {
|
|
176
|
+
var thread = el("div", "am-thread");
|
|
177
|
+
var head = el("div", "am-thread-head");
|
|
178
|
+
if (onBack) {
|
|
179
|
+
var back = el("button", "am-back", "Back");
|
|
180
|
+
back.setAttribute("type", "button");
|
|
181
|
+
back.addEventListener("click", onBack);
|
|
182
|
+
head.appendChild(back);
|
|
183
|
+
}
|
|
184
|
+
head.appendChild(el("span", "am-thread-title", senderLabel(pair).text + " → " + endpointLabel(pair.target)));
|
|
185
|
+
thread.appendChild(head);
|
|
186
|
+
|
|
187
|
+
var shown = (snapshot.messages || []).filter(function (m) { return m.pairKey === pair.key; });
|
|
188
|
+
shown.forEach(function (m) { thread.appendChild(renderMessage(pair, m)); });
|
|
189
|
+
(snapshot.pending || []).filter(function (p) { return p.pairKey === pair.key; }).forEach(function (p) {
|
|
190
|
+
thread.appendChild(renderPending(pair, p));
|
|
191
|
+
});
|
|
192
|
+
if (snapshot.messagesTruncated > 0) {
|
|
193
|
+
thread.appendChild(el("div", "am-footnote", snapshot.messagesTruncated + " older messages are not listed."));
|
|
194
|
+
}
|
|
195
|
+
container.appendChild(thread);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function selectedPair() {
|
|
199
|
+
var pairs = (snapshot && snapshot.pairs) || [];
|
|
200
|
+
for (var i = 0; i < pairs.length; i++) if (pairs[i].key === selectedKey) return pairs[i];
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function paint(container) {
|
|
205
|
+
container.innerHTML = "";
|
|
206
|
+
var pairs = snapshot && snapshot.ok !== false ? snapshot.pairs || [] : [];
|
|
207
|
+
if (!pairs.length) {
|
|
208
|
+
var empty = el("div", "am-empty", emptyStateText(snapshot));
|
|
209
|
+
empty.setAttribute("data-empty", "true");
|
|
210
|
+
container.appendChild(empty);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (selectedKey && !selectedPair()) selectedKey = null;
|
|
214
|
+
|
|
215
|
+
function select(key) {
|
|
216
|
+
selectedKey = key;
|
|
217
|
+
paint(container);
|
|
218
|
+
}
|
|
219
|
+
function back() {
|
|
220
|
+
selectedKey = null;
|
|
221
|
+
paint(container);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
var phone = isMobileViewport();
|
|
225
|
+
var layout = el("div", "am-layout" + (phone ? " phone" : ""));
|
|
226
|
+
var pair = selectedPair();
|
|
227
|
+
|
|
228
|
+
if (!(phone && pair)) {
|
|
229
|
+
var map = el("div", "am-map");
|
|
230
|
+
map.appendChild(el("div", "team-section-header", "Who talks to whom"));
|
|
231
|
+
pairs.forEach(function (p) { map.appendChild(renderPairRow(p, select)); });
|
|
232
|
+
layout.appendChild(map);
|
|
233
|
+
}
|
|
234
|
+
if (pair) {
|
|
235
|
+
renderThread(layout, pair, phone ? back : null);
|
|
236
|
+
} else if (!phone) {
|
|
237
|
+
layout.appendChild(el("div", "am-hint", "Select a pair to read its messages."));
|
|
238
|
+
}
|
|
239
|
+
container.appendChild(layout);
|
|
240
|
+
|
|
241
|
+
var withheld = snapshot.withheld || { count: 0, reasons: [] };
|
|
242
|
+
if (withheld.count > 0) {
|
|
243
|
+
container.appendChild(el("div", "am-footnote", emptyStateText({ ok: true, withheld: withheld })));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function renderSection(container) {
|
|
248
|
+
activeContainer = container;
|
|
249
|
+
paint(container);
|
|
250
|
+
requestTraffic();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
registerTeamSection({ id: SECTION_ID, title: "Agent messages", render: renderSection });
|
|
254
|
+
|
|
255
|
+
// --- Exports ---
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* opts.openSession(project, id): show a session of the console (the caller owns
|
|
259
|
+
* how a project switch happens). opts.knownAgents(): the project's agents, for
|
|
260
|
+
* the avatar lookup shared with injected messages.
|
|
261
|
+
*/
|
|
262
|
+
export function initAgentMessages(opts) {
|
|
263
|
+
opts = opts || {};
|
|
264
|
+
if (typeof opts.openSession === "function") openSessionFn = opts.openSession;
|
|
265
|
+
if (typeof opts.knownAgents === "function") knownAgentsFn = opts.knownAgents;
|
|
266
|
+
store.subscribe(["connected"], function (state, prev) {
|
|
267
|
+
if (state.connected && !prev.connected && releaseIfClosed()) requestTraffic();
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function handleTeamTraffic(msg) {
|
|
272
|
+
snapshot = msg;
|
|
273
|
+
if (releaseIfClosed()) paint(activeContainer);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// The registry has no close hook, so the section checks that the container it
|
|
277
|
+
// last drew into is still on screen.
|
|
278
|
+
function releaseIfClosed() {
|
|
279
|
+
if (activeContainer && !isSectionContainerShown(activeContainer)) activeContainer = null;
|
|
280
|
+
return !!activeContainer;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function handleTeamTrafficChanged() {
|
|
284
|
+
if (releaseIfClosed()) requestTraffic();
|
|
285
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// agent-roster.js - the Team view's agent roster: every agent identity the
|
|
2
|
+
// console has seen (a session's agent, a sub-agent a Task or Agent call named,
|
|
3
|
+
// an injected sender), with first and last seen, where it was seen, and an
|
|
4
|
+
// avatar the operator can change.
|
|
5
|
+
//
|
|
6
|
+
// The server (lib/agent-roster.js) owns the roster. It sends agent_roster on
|
|
7
|
+
// connect and on request, limited to the projects this connection may read, and
|
|
8
|
+
// nudges every client with agent_roster_changed after a change; the client then
|
|
9
|
+
// asks again, so the section updates live and a reload or daemon restart rebuilds
|
|
10
|
+
// the same view. Choosing an avatar sends agent_avatar_set; the nudge brings the
|
|
11
|
+
// new roster back, and agent-avatar.js redraws each avatar on the page, not just
|
|
12
|
+
// this section's.
|
|
13
|
+
|
|
14
|
+
import { getWs } from "./ws-ref.js";
|
|
15
|
+
import { registerTeamSection, isSectionContainerShown } from "./team-view.js";
|
|
16
|
+
import { relativeTime } from "./relative-time.js";
|
|
17
|
+
import { setAgentAvatars, refreshAgentAvatars, createAgentAvatar } from "./agent-avatar.js";
|
|
18
|
+
import { buildAvatarPicker } from "./agent-avatar-picker.js";
|
|
19
|
+
|
|
20
|
+
var SECTION_ID = "agent-roster";
|
|
21
|
+
var AVATAR_SIZE = 40;
|
|
22
|
+
|
|
23
|
+
var agents = null;
|
|
24
|
+
var pickerKey = null;
|
|
25
|
+
var failure = null;
|
|
26
|
+
var activeContainer = null;
|
|
27
|
+
|
|
28
|
+
var SOURCE_LABEL = { session: "session agent", subagent: "sub-agent", sender: "sender" };
|
|
29
|
+
|
|
30
|
+
function el(tag, className, text) {
|
|
31
|
+
var node = document.createElement(tag);
|
|
32
|
+
if (className) node.className = className;
|
|
33
|
+
if (text !== undefined && text !== null) node.textContent = text;
|
|
34
|
+
return node;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function send(payload) {
|
|
38
|
+
var ws = getWs();
|
|
39
|
+
if (!ws || ws.readyState !== 1) return false;
|
|
40
|
+
ws.send(JSON.stringify(payload));
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function emptyStateText(list) {
|
|
45
|
+
if (list === null) return "Loading the agent roster.";
|
|
46
|
+
return "No agents seen yet. An agent appears here once it runs a session, is started as a sub-agent, or sends input to a session.";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function placeText(place) {
|
|
50
|
+
var where = [];
|
|
51
|
+
if (place.project) where.push(place.project);
|
|
52
|
+
return (SOURCE_LABEL[place.source] || place.source) + (where.length ? " in " + where.join(", ") : "");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function timeText(ts) {
|
|
56
|
+
return ts ? relativeTime(ts) : "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --- Views ---
|
|
60
|
+
|
|
61
|
+
function choose(key, ref) {
|
|
62
|
+
failure = null;
|
|
63
|
+
send({ type: "agent_avatar_set", key: key, avatar: ref });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function renderRow(agent) {
|
|
67
|
+
var open = agent.key === pickerKey;
|
|
68
|
+
var row = el("div", "ar-row" + (open ? " open" : ""));
|
|
69
|
+
row.setAttribute("data-agent-key", agent.key);
|
|
70
|
+
|
|
71
|
+
var head = el("div", "ar-head");
|
|
72
|
+
head.appendChild(createAgentAvatar(agent.key, AVATAR_SIZE, "ar-avatar"));
|
|
73
|
+
|
|
74
|
+
var main = el("div", "ar-main");
|
|
75
|
+
main.appendChild(el("div", "ar-name", agent.key));
|
|
76
|
+
var seen = el("div", "ar-seen");
|
|
77
|
+
seen.appendChild(el("span", "ar-first", "First seen " + timeText(agent.firstSeen)));
|
|
78
|
+
seen.appendChild(el("span", "ar-last", "Last seen " + timeText(agent.lastSeen)));
|
|
79
|
+
main.appendChild(seen);
|
|
80
|
+
var places = el("div", "ar-places");
|
|
81
|
+
(agent.places || []).forEach(function (p) { places.appendChild(el("span", "ar-place", placeText(p))); });
|
|
82
|
+
main.appendChild(places);
|
|
83
|
+
head.appendChild(main);
|
|
84
|
+
|
|
85
|
+
var change = el("button", "ar-change", open ? "Close" : "Change avatar");
|
|
86
|
+
change.setAttribute("type", "button");
|
|
87
|
+
change.addEventListener("click", function () {
|
|
88
|
+
pickerKey = open ? null : agent.key;
|
|
89
|
+
paint();
|
|
90
|
+
});
|
|
91
|
+
head.appendChild(change);
|
|
92
|
+
row.appendChild(head);
|
|
93
|
+
|
|
94
|
+
if (open) {
|
|
95
|
+
row.appendChild(buildAvatarPicker(agent.key, function (ref) { choose(agent.key, ref); }));
|
|
96
|
+
if (failure && failure.key === agent.key) row.appendChild(el("div", "ar-failure", "The avatar could not be saved: " + failure.error + "."));
|
|
97
|
+
}
|
|
98
|
+
return row;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function paint() {
|
|
102
|
+
var container = activeContainer;
|
|
103
|
+
if (!container) return;
|
|
104
|
+
container.innerHTML = "";
|
|
105
|
+
var list = agents || [];
|
|
106
|
+
if (!list.length) {
|
|
107
|
+
var empty = el("div", "ar-empty", emptyStateText(agents));
|
|
108
|
+
empty.setAttribute("data-empty", "true");
|
|
109
|
+
container.appendChild(empty);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
var wrap = el("div", "ar-list");
|
|
113
|
+
list.forEach(function (agent) { wrap.appendChild(renderRow(agent)); });
|
|
114
|
+
container.appendChild(wrap);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function renderSection(container) {
|
|
118
|
+
activeContainer = container;
|
|
119
|
+
paint();
|
|
120
|
+
send({ type: "agent_roster_request" });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
registerTeamSection({ id: SECTION_ID, title: "Agents", render: renderSection });
|
|
124
|
+
|
|
125
|
+
// --- Messages from the server ---
|
|
126
|
+
|
|
127
|
+
// The agents and their avatar choices, without the sighting times that change
|
|
128
|
+
// on every use: while a picker is open, a roster that differs only in times does
|
|
129
|
+
// not redraw it, so a seed being typed is not lost.
|
|
130
|
+
function choicesSignature(list) {
|
|
131
|
+
return JSON.stringify((list || []).map(function (a) { return [a.key, a.avatar || null]; }));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function handleAgentRoster(msg) {
|
|
135
|
+
var before = choicesSignature(agents);
|
|
136
|
+
agents = Array.isArray(msg.agents) ? msg.agents : [];
|
|
137
|
+
setAgentAvatars(agents);
|
|
138
|
+
refreshAgentAvatars();
|
|
139
|
+
if (activeContainer && !isSectionContainerShown(activeContainer)) activeContainer = null;
|
|
140
|
+
if (!activeContainer) return;
|
|
141
|
+
if (pickerKey && before === choicesSignature(agents)) return;
|
|
142
|
+
paint();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// The roster changed. The nudge carries no content: this connection asks, and the
|
|
146
|
+
// server answers with only what it may read. Asked whether or not the Team view
|
|
147
|
+
// is open, since every avatar on the page resolves from the answer.
|
|
148
|
+
export function handleAgentRosterChanged() {
|
|
149
|
+
send({ type: "agent_roster_request" });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function handleAgentAvatarSetResult(msg) {
|
|
153
|
+
if (msg.ok) return;
|
|
154
|
+
failure = { key: msg.key, error: msg.error || "unknown error" };
|
|
155
|
+
if (activeContainer && !isSectionContainerShown(activeContainer)) activeContainer = null;
|
|
156
|
+
if (activeContainer) paint();
|
|
157
|
+
}
|
|
@@ -15,8 +15,11 @@ import { isHomeHubVisible } from './app-home-hub.js';
|
|
|
15
15
|
import { resetTerminals } from './terminal.js';
|
|
16
16
|
import { closeDmUserPicker } from './sidebar-users.js';
|
|
17
17
|
import { openDm } from './app-dm.js';
|
|
18
|
+
import { takePendingPeer } from './notify-client.js';
|
|
18
19
|
import { getPaletteVersion } from './command-palette.js';
|
|
19
20
|
import { sessionActivity, indicatorClass } from './activity-state.js';
|
|
21
|
+
import { clearScheduledOutboxOnReconnect } from './scheduled-outbox.js';
|
|
22
|
+
import { requestScheduledInputList } from './scheduled-input-actions.js';
|
|
20
23
|
import { createBuildGuard, showReloadBanner } from './build-guard.js';
|
|
21
24
|
|
|
22
25
|
var reconnectTimer = null;
|
|
@@ -197,6 +200,11 @@ export function setStatus(status) {
|
|
|
197
200
|
}
|
|
198
201
|
|
|
199
202
|
function onConnected() {
|
|
203
|
+
// A Fire now or Cancel sent before the drop may never be answered: free the
|
|
204
|
+
// rows and ask for the server's list, which redraws what is armed.
|
|
205
|
+
clearScheduledOutboxOnReconnect();
|
|
206
|
+
requestScheduledInputList();
|
|
207
|
+
|
|
200
208
|
// Flush any extension messages that arrived before WS was ready
|
|
201
209
|
flushPendingExtMessages();
|
|
202
210
|
|
|
@@ -216,6 +224,10 @@ function onConnected() {
|
|
|
216
224
|
|
|
217
225
|
// Session restore is now server-driven (user-presence.json).
|
|
218
226
|
try { localStorage.removeItem("clagentic-active-dm"); localStorage.removeItem("clay-active-dm"); } catch (e) {}
|
|
227
|
+
// A tapped message notification opened this page before the connection: open
|
|
228
|
+
// its conversation now.
|
|
229
|
+
var pendingPeer = takePendingPeer();
|
|
230
|
+
if (pendingPeer) openDm(pendingPeer);
|
|
219
231
|
|
|
220
232
|
// If the home hub was visible when the connection came up (common on mobile
|
|
221
233
|
// PWA cold-start where showHomeHub() fires before the WS is open), re-request
|
|
@@ -277,6 +289,10 @@ function fetchWsTicket() {
|
|
|
277
289
|
.catch(function () { return { ticket: null }; });
|
|
278
290
|
}
|
|
279
291
|
|
|
292
|
+
// Bumped by every connect() call; an attempt whose generation is no longer
|
|
293
|
+
// current is superseded and must not touch the socket or the UI.
|
|
294
|
+
var connectGeneration = 0;
|
|
295
|
+
|
|
280
296
|
// Milliseconds to wait before re-verifying a single ws-ticket 401 (lr-e5c1fe).
|
|
281
297
|
var UNAUTH_RETRY_BACKOFF_MS = 400;
|
|
282
298
|
|
|
@@ -291,21 +307,27 @@ var UNAUTH_RETRY_BACKOFF_MS = 400;
|
|
|
291
307
|
// re-run) then proved was still good. Re-verify once, after a short backoff,
|
|
292
308
|
// before declaring the session gone — only two consecutive 401s (auth
|
|
293
309
|
// actually confirmed absent) route to handleUnauthenticated().
|
|
310
|
+
//
|
|
311
|
+
// Single-flight: each call takes a new generation. An earlier attempt still
|
|
312
|
+
// awaiting its ticket sees the bump and neither opens nor registers a socket,
|
|
313
|
+
// so no orphan socket can keep feeding processMessage.
|
|
294
314
|
export function connect() {
|
|
315
|
+
var gen = ++connectGeneration;
|
|
316
|
+
cancelReconnect();
|
|
295
317
|
var ws = getWs();
|
|
296
318
|
if (ws) { ws.onclose = null; ws.onmessage = null; ws.onerror = null; ws.close(); }
|
|
297
319
|
if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
|
|
298
320
|
|
|
299
321
|
fetchWsTicket().then(function (result) {
|
|
322
|
+
if (gen !== connectGeneration) return;
|
|
300
323
|
if (result.unauthenticated) {
|
|
301
324
|
setTimeout(function () {
|
|
325
|
+
if (gen !== connectGeneration) return;
|
|
302
326
|
fetchWsTicket().then(function (retryResult) {
|
|
327
|
+
if (gen !== connectGeneration) return;
|
|
303
328
|
if (retryResult.unauthenticated) {
|
|
304
329
|
// Two consecutive 401s: auth is confirmed gone, not a transient
|
|
305
|
-
// wake-from-background cookie
|
|
306
|
-
// instead of opening a socket that would only 401 on the
|
|
307
|
-
// upgrade too — ties into the Surface-1 unauth-vs-unreachable
|
|
308
|
-
// split below.
|
|
330
|
+
// wake-from-background cookie gap. Route to sign-in.
|
|
309
331
|
handleUnauthenticated();
|
|
310
332
|
return;
|
|
311
333
|
}
|
|
@@ -333,9 +355,13 @@ function openSocket(ticket) {
|
|
|
333
355
|
var newWs = ticket ? new WebSocket(url, ["clagentic.auth." + ticket]) : new WebSocket(url);
|
|
334
356
|
setWs(newWs);
|
|
335
357
|
|
|
358
|
+
// Handlers fire only while this socket is still the tracked one; a socket
|
|
359
|
+
// that was replaced must not mutate connection state or feed messages.
|
|
360
|
+
function isCurrent() { return getWs() === newWs; }
|
|
361
|
+
|
|
336
362
|
// If not connected within 3s, force retry
|
|
337
363
|
connectTimeoutId = setTimeout(function () {
|
|
338
|
-
if (!store.get('connected')) {
|
|
364
|
+
if (isCurrent() && !store.get('connected')) {
|
|
339
365
|
newWs.onclose = null;
|
|
340
366
|
newWs.onerror = null;
|
|
341
367
|
newWs.onmessage = null;
|
|
@@ -353,6 +379,7 @@ function openSocket(ticket) {
|
|
|
353
379
|
var everOpened = false;
|
|
354
380
|
|
|
355
381
|
newWs.onopen = function () {
|
|
382
|
+
if (!isCurrent()) return;
|
|
356
383
|
everOpened = true;
|
|
357
384
|
if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
|
|
358
385
|
setStatus("connected");
|
|
@@ -373,6 +400,7 @@ function openSocket(ticket) {
|
|
|
373
400
|
};
|
|
374
401
|
|
|
375
402
|
newWs.onclose = function (e) {
|
|
403
|
+
if (!isCurrent()) return;
|
|
376
404
|
if (connectTimeoutId) { clearTimeout(connectTimeoutId); connectTimeoutId = null; }
|
|
377
405
|
closeDmUserPicker();
|
|
378
406
|
setStatus("disconnected");
|
|
@@ -399,6 +427,7 @@ function openSocket(ticket) {
|
|
|
399
427
|
newWs.onerror = function () {};
|
|
400
428
|
|
|
401
429
|
newWs.onmessage = function (event) {
|
|
430
|
+
if (!isCurrent()) return;
|
|
402
431
|
// Backup: if we're receiving messages, we're connected
|
|
403
432
|
if (!store.get('connected')) {
|
|
404
433
|
setStatus("connected");
|