@clagentic/console 1.12.0-beta.2 → 1.12.0
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/bin/cli.js +4 -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-sha.json +2 -2
- package/lib/build-update-notify.js +45 -0
- package/lib/build-update-offer.js +3 -4
- package/lib/build-update-standing.js +34 -14
- package/lib/cli/session-subcommands.js +26 -8
- package/lib/client-address.js +44 -0
- package/lib/daemon.js +25 -10
- package/lib/idle-compaction-setting.js +203 -0
- package/lib/mcp-bridge-credential.js +41 -0
- package/lib/notification-prefs.js +16 -22
- package/lib/notify/core.js +53 -18
- package/lib/notify/payload.js +2 -3
- package/lib/notify/type-registry.js +17 -0
- package/lib/notify/types.js +38 -1
- package/lib/outbound-access.js +12 -1
- package/lib/outbound-entry.js +8 -1
- package/lib/project-connection.js +9 -8
- package/lib/project-filesystem.js +23 -0
- package/lib/project-loop.js +16 -19
- package/lib/project-notifications.js +68 -7
- package/lib/project-sessions.js +9 -0
- 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 +26 -4
- package/lib/prompt-answer.js +145 -0
- package/lib/prompt-expiry.js +50 -0
- package/lib/prompt-registry.js +24 -1
- package/lib/prompt-source.js +16 -0
- package/lib/public/app.js +31 -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 +1 -1
- 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/sidebar.css +11 -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 +41 -7
- 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 +12 -0
- package/lib/public/modules/app-messages.js +55 -16
- package/lib/public/modules/app-notifications.js +59 -29
- package/lib/public/modules/app-panels.js +26 -3
- package/lib/public/modules/app-rate-limit.js +8 -165
- package/lib/public/modules/app-rendering.js +22 -7
- 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 +52 -55
- 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 +114 -21
- package/lib/public/modules/pending-term-request.js +30 -0
- package/lib/public/modules/project-icon.js +22 -2
- 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 +47 -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 +18 -0
- package/lib/public/modules/terminal.js +65 -4
- package/lib/public/modules/tools.js +19 -0
- package/lib/public/modules/user-shell.js +824 -0
- package/lib/public/notify-sw-logic.js +35 -83
- package/lib/public/notify-target.js +70 -10
- package/lib/public/style.css +5 -0
- package/lib/public/sw.js +7 -3
- package/lib/queued-chat.js +392 -0
- package/lib/scheduled-input/ws.js +67 -9
- package/lib/sdk-bridge.js +122 -43
- package/lib/sdk-message-processor.js +46 -39
- 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 +83 -19
- package/lib/session-directory.js +33 -8
- package/lib/session-end.js +97 -0
- package/lib/session-input-ipc.js +26 -0
- package/lib/session-input.js +176 -9
- package/lib/session-resume.js +1 -0
- package/lib/session-settings-file.js +53 -0
- package/lib/sessions.js +49 -5
- package/lib/team-traffic-ws.js +68 -0
- package/lib/team-traffic.js +318 -0
- package/lib/usage-store.js +7 -0
- package/lib/user-shell-settings.js +105 -0
- package/lib/ws-schema.js +27 -4
- package/lib/yoke/adapters/claude-capabilities.js +2 -0
- package/lib/yoke/adapters/claude-vendor.js +6 -0
- package/lib/yoke/adapters/claude-worker.js +39 -11
- package/lib/yoke/adapters/claude.js +218 -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/codex-app-server.js +8 -2
- package/lib/yoke/interface.js +54 -1
- package/lib/yoke/mcp-bridge-server.js +12 -8
- package/lib/yoke/registry.js +32 -0
- package/lib/yoke/user-shell.js +224 -0
- package/package.json +1 -1
- package/lib/public/modules/build-notice-gate.js +0 -73
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// agent-avatar-picker.js - the control that chooses an agent's avatar: a built-in
|
|
2
|
+
// robot style (seeded, from avatar.js) or an icon from the global custom-icon
|
|
3
|
+
// store, the one project icons use. Uploads go through custom-icons.js to
|
|
4
|
+
// /api/custom-emoji; this module keeps no image and has no store of its own.
|
|
5
|
+
//
|
|
6
|
+
// It only builds the control and reports a choice through onChoose(ref), where
|
|
7
|
+
// ref is {style, seed}, {custom} or null (clear the choice). Sending the choice
|
|
8
|
+
// to the server is the caller's.
|
|
9
|
+
|
|
10
|
+
import { AVATAR_STYLES, avatarUrl } from "./avatar.js";
|
|
11
|
+
import { fetchCustomIconListStrict, uploadCustomIcon, slugifyFilename } from "./custom-icons.js";
|
|
12
|
+
import { customIconUrl } from "./project-icon.js";
|
|
13
|
+
import { agentAvatarChoice } from "./agent-avatar.js";
|
|
14
|
+
|
|
15
|
+
var PREVIEW_SIZE = 40;
|
|
16
|
+
var MAX_SLUG_LENGTH = 64;
|
|
17
|
+
|
|
18
|
+
function el(tag, className, text) {
|
|
19
|
+
var node = document.createElement(tag);
|
|
20
|
+
if (className) node.className = className;
|
|
21
|
+
if (text !== undefined && text !== null) node.textContent = text;
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A slug that is not in taken: slug itself, else slug-2, slug-3 and so on, kept
|
|
27
|
+
* inside the store's 64-character limit. An upload under it never replaces an
|
|
28
|
+
* icon that something else already uses.
|
|
29
|
+
*/
|
|
30
|
+
export function uniqueSlug(slug, taken) {
|
|
31
|
+
var used = {};
|
|
32
|
+
(taken || []).forEach(function (s) { used[s] = true; });
|
|
33
|
+
if (!used[slug]) return slug;
|
|
34
|
+
for (var n = 2; ; n++) {
|
|
35
|
+
var suffix = "-" + n;
|
|
36
|
+
var candidate = slug.slice(0, MAX_SLUG_LENGTH - suffix.length) + suffix;
|
|
37
|
+
if (!used[candidate]) return candidate;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function previewButton(className, label, src) {
|
|
42
|
+
var btn = el("button", className);
|
|
43
|
+
btn.setAttribute("type", "button");
|
|
44
|
+
var img = el("img", "ar-preview");
|
|
45
|
+
img.alt = "";
|
|
46
|
+
img.width = PREVIEW_SIZE;
|
|
47
|
+
img.height = PREVIEW_SIZE;
|
|
48
|
+
img.src = src;
|
|
49
|
+
btn.appendChild(img);
|
|
50
|
+
btn.appendChild(el("span", "ar-choice-label", label));
|
|
51
|
+
return { button: btn, img: img };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* deps (all optional): { fetchList(), upload(slug, file) } stand in for the
|
|
56
|
+
* custom-icon store calls.
|
|
57
|
+
*/
|
|
58
|
+
export function buildAvatarPicker(key, onChoose, deps) {
|
|
59
|
+
deps = deps || {};
|
|
60
|
+
var fetchList = deps.fetchList || fetchCustomIconListStrict;
|
|
61
|
+
// Create-only: the picker adds an icon to the store and never replaces one that
|
|
62
|
+
// a project, a folder or another agent already uses.
|
|
63
|
+
var upload = deps.upload || function (slug, file) { return uploadCustomIcon(slug, file, { createOnly: true }); };
|
|
64
|
+
var current = agentAvatarChoice(key);
|
|
65
|
+
|
|
66
|
+
var root = el("div", "ar-picker");
|
|
67
|
+
root.setAttribute("data-agent-key", key);
|
|
68
|
+
|
|
69
|
+
// --- Robot styles ---
|
|
70
|
+
root.appendChild(el("div", "ar-picker-title", "Built-in style"));
|
|
71
|
+
var seedRow = el("label", "ar-seed-row");
|
|
72
|
+
seedRow.appendChild(el("span", "ar-seed-label", "Seed"));
|
|
73
|
+
var seedInput = el("input", "ar-seed");
|
|
74
|
+
seedInput.setAttribute("type", "text");
|
|
75
|
+
seedInput.value = current && current.seed ? current.seed : key;
|
|
76
|
+
seedRow.appendChild(seedInput);
|
|
77
|
+
root.appendChild(seedRow);
|
|
78
|
+
|
|
79
|
+
var styleGrid = el("div", "ar-grid");
|
|
80
|
+
var styleImgs = [];
|
|
81
|
+
AVATAR_STYLES.forEach(function (style) {
|
|
82
|
+
var chosen = !!current && current.style === style.id;
|
|
83
|
+
var item = previewButton("ar-choice" + (chosen ? " selected" : ""), style.name, avatarUrl(style.id, seedInput.value, PREVIEW_SIZE));
|
|
84
|
+
item.button.setAttribute("data-style", style.id);
|
|
85
|
+
item.button.addEventListener("click", function () {
|
|
86
|
+
onChoose({ style: style.id, seed: seedInput.value || key });
|
|
87
|
+
});
|
|
88
|
+
styleImgs.push({ id: style.id, img: item.img });
|
|
89
|
+
styleGrid.appendChild(item.button);
|
|
90
|
+
});
|
|
91
|
+
seedInput.addEventListener("input", function () {
|
|
92
|
+
styleImgs.forEach(function (s) { s.img.src = avatarUrl(s.id, seedInput.value || key, PREVIEW_SIZE); });
|
|
93
|
+
});
|
|
94
|
+
root.appendChild(styleGrid);
|
|
95
|
+
|
|
96
|
+
// --- Custom icons (the global store) ---
|
|
97
|
+
root.appendChild(el("div", "ar-picker-title", "Custom icons"));
|
|
98
|
+
var iconGrid = el("div", "ar-grid");
|
|
99
|
+
iconGrid.appendChild(el("div", "ar-note", "Loading custom icons."));
|
|
100
|
+
root.appendChild(iconGrid);
|
|
101
|
+
|
|
102
|
+
var slugs = [];
|
|
103
|
+
function paintIcons(list) {
|
|
104
|
+
iconGrid.innerHTML = "";
|
|
105
|
+
slugs = list.map(function (i) { return i.slug; });
|
|
106
|
+
if (!list.length) {
|
|
107
|
+
iconGrid.appendChild(el("div", "ar-note", "No custom icons uploaded yet."));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
list.forEach(function (icon) {
|
|
111
|
+
var chosen = !!current && current.custom === icon.slug;
|
|
112
|
+
var item = previewButton("ar-choice" + (chosen ? " selected" : ""), icon.slug, customIconUrl(icon.slug));
|
|
113
|
+
item.button.setAttribute("data-custom", icon.slug);
|
|
114
|
+
item.button.addEventListener("click", function () { onChoose({ custom: icon.slug }); });
|
|
115
|
+
iconGrid.appendChild(item.button);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// A list that could not be loaded is an error, not an empty store: an empty
|
|
119
|
+
// state would tell the operator there is nothing to choose from.
|
|
120
|
+
function paintIconsFailed() {
|
|
121
|
+
iconGrid.innerHTML = "";
|
|
122
|
+
var failed = el("div", "ar-note ar-icons-error", "Custom icons could not be loaded.");
|
|
123
|
+
failed.setAttribute("role", "alert");
|
|
124
|
+
iconGrid.appendChild(failed);
|
|
125
|
+
}
|
|
126
|
+
new Promise(function (resolve) { resolve(fetchList()); }).then(paintIcons).catch(paintIconsFailed);
|
|
127
|
+
|
|
128
|
+
// --- Upload ---
|
|
129
|
+
var note = el("div", "ar-note");
|
|
130
|
+
var uploadRow = el("label", "ar-upload");
|
|
131
|
+
uploadRow.appendChild(el("span", "ar-upload-label", "Upload an image"));
|
|
132
|
+
var fileInput = el("input", "ar-file");
|
|
133
|
+
fileInput.setAttribute("type", "file");
|
|
134
|
+
fileInput.setAttribute("accept", "image/*");
|
|
135
|
+
fileInput.addEventListener("change", function () {
|
|
136
|
+
var file = fileInput.files && fileInput.files[0];
|
|
137
|
+
if (!file) return;
|
|
138
|
+
var slug = uniqueSlug(slugifyFilename(file.name), slugs);
|
|
139
|
+
note.textContent = "Uploading.";
|
|
140
|
+
Promise.resolve(upload(slug, file)).then(function (res) {
|
|
141
|
+
if (res && res.ok) {
|
|
142
|
+
note.textContent = "";
|
|
143
|
+
onChoose({ custom: res.slug || slug });
|
|
144
|
+
} else {
|
|
145
|
+
note.textContent = "Upload failed: " + ((res && res.error) || "unknown error") + ".";
|
|
146
|
+
}
|
|
147
|
+
}, function () {
|
|
148
|
+
note.textContent = "Upload failed: unknown error.";
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
uploadRow.appendChild(fileInput);
|
|
152
|
+
root.appendChild(uploadRow);
|
|
153
|
+
root.appendChild(note);
|
|
154
|
+
|
|
155
|
+
// --- Default ---
|
|
156
|
+
var reset = el("button", "ar-reset", "Use the default robot");
|
|
157
|
+
reset.setAttribute("type", "button");
|
|
158
|
+
reset.addEventListener("click", function () { onChoose(null); });
|
|
159
|
+
root.appendChild(reset);
|
|
160
|
+
|
|
161
|
+
return root;
|
|
162
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// agent-avatar.js - the one place that decides which avatar an agent shows.
|
|
2
|
+
//
|
|
3
|
+
// Every place the console draws an agent (the Team view roster, the Agent
|
|
4
|
+
// messages section, an injected message's sender, a sub-agent's label in the
|
|
5
|
+
// transcript) asks here, by the agent's key as the roster records it. The
|
|
6
|
+
// server's roster (lib/agent-roster.js) holds the operator's choices and sends
|
|
7
|
+
// them to every client as agent_roster; handleAgentRoster in agent-roster.js
|
|
8
|
+
// feeds them to setAgentAvatars, and refreshAgentAvatars redraws every avatar
|
|
9
|
+
// already on the page.
|
|
10
|
+
//
|
|
11
|
+
// A choice is {style, seed} (a built-in style from avatar.js) or {custom} (a
|
|
12
|
+
// slug in the global custom-icon store, served by /api/custom-emoji, the same
|
|
13
|
+
// store project icons use). With no choice the caller's default shows, or the
|
|
14
|
+
// seeded robot. A custom icon that is deleted, or fails to load, falls back to
|
|
15
|
+
// that default: no broken image, no error.
|
|
16
|
+
//
|
|
17
|
+
// DOM-free except createAgentAvatar / bindAgentAvatar / refreshAgentAvatars.
|
|
18
|
+
|
|
19
|
+
import { AVATAR_STYLES, avatarUrl } from "./avatar.js";
|
|
20
|
+
import { customIconUrl, isCustomIconSlug } from "./project-icon.js";
|
|
21
|
+
|
|
22
|
+
// The robot every agent falls back to, seeded by its key.
|
|
23
|
+
export var ROBOT_STYLE = "bottts";
|
|
24
|
+
|
|
25
|
+
var choices = Object.create(null);
|
|
26
|
+
var listeners = [];
|
|
27
|
+
|
|
28
|
+
function knownStyle(style) {
|
|
29
|
+
for (var i = 0; i < AVATAR_STYLES.length; i++) if (AVATAR_STYLES[i].id === style) return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The seeded robot URL for a key: what an agent shows when nothing else applies. */
|
|
34
|
+
export function robotAvatarUrl(key, size) {
|
|
35
|
+
return avatarUrl(ROBOT_STYLE, key, size);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function urlOfChoice(choice, key, size) {
|
|
39
|
+
if (choice.custom !== undefined) return isCustomIconSlug(choice.custom) ? customIconUrl(choice.custom) : null;
|
|
40
|
+
if (!knownStyle(choice.style)) return null;
|
|
41
|
+
return avatarUrl(choice.style, choice.seed || key, size);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Replace the known choices with the roster's: agents is the agent_roster
|
|
46
|
+
* message's list ({key, avatar}). Entries with no avatar hold no choice.
|
|
47
|
+
*/
|
|
48
|
+
export function setAgentAvatars(agents) {
|
|
49
|
+
var next = Object.create(null);
|
|
50
|
+
(Array.isArray(agents) ? agents : []).forEach(function (a) {
|
|
51
|
+
if (a && typeof a.key === "string" && a.avatar && typeof a.avatar === "object") next[a.key] = a.avatar;
|
|
52
|
+
});
|
|
53
|
+
choices = next;
|
|
54
|
+
listeners.slice().forEach(function (fn) { fn(); });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The operator's choice for a key ({style, seed} or {custom}), or null. */
|
|
58
|
+
export function agentAvatarChoice(key) {
|
|
59
|
+
return (typeof key === "string" && choices[key]) || null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Calls fn after every setAgentAvatars. Returns a function that stops it. */
|
|
63
|
+
export function onAgentAvatarsChanged(fn) {
|
|
64
|
+
listeners.push(fn);
|
|
65
|
+
return function () { listeners = listeners.filter(function (f) { return f !== fn; }); };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the avatar for an agent key.
|
|
70
|
+
* defaultUrl what the agent shows with no choice (an existing mate or agent
|
|
71
|
+
* avatar, say); the seeded robot when absent.
|
|
72
|
+
* Returns { url, fallbackUrl, custom }: url is what to show, fallbackUrl what to
|
|
73
|
+
* show when url fails to load, custom the slug when url is a custom icon.
|
|
74
|
+
*/
|
|
75
|
+
export function resolveAgentAvatar(key, size, defaultUrl) {
|
|
76
|
+
var fallbackUrl = defaultUrl || robotAvatarUrl(key, size);
|
|
77
|
+
var choice = agentAvatarChoice(key);
|
|
78
|
+
var chosen = choice ? urlOfChoice(choice, key, size) : null;
|
|
79
|
+
if (!chosen) return { url: fallbackUrl, fallbackUrl: fallbackUrl, custom: null };
|
|
80
|
+
return { url: chosen, fallbackUrl: fallbackUrl, custom: choice.custom !== undefined ? choice.custom : null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The roster key of an injected sender, or null when it names no agent. The same
|
|
85
|
+
* rule as senderKey in lib/agent-roster.js: an extracted sender is keyed by its
|
|
86
|
+
* agent name (its fromName is the "<agent or vendor>@<project>" label), a
|
|
87
|
+
* declared one by the name it gave.
|
|
88
|
+
*/
|
|
89
|
+
export function senderAgentKey(injected) {
|
|
90
|
+
if (!injected) return null;
|
|
91
|
+
if (injected.senderKind === "extracted") return injected.senderAgent || injected.fromName || null;
|
|
92
|
+
if (injected.senderKind === "declared") return injected.fromName || null;
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function paint(img) {
|
|
97
|
+
var key = img.dataset.agentKey;
|
|
98
|
+
var size = Number(img.dataset.agentSize) || 64;
|
|
99
|
+
var resolved = resolveAgentAvatar(key, size, img._agentDefaultUrl);
|
|
100
|
+
img._agentFallbackUrl = resolved.fallbackUrl;
|
|
101
|
+
img._agentFellBack = false;
|
|
102
|
+
img.src = resolved.url;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Make img show the avatar for key, and keep it current: refreshAgentAvatars
|
|
107
|
+
* repaints it when the roster changes, and a custom icon that fails to load
|
|
108
|
+
* (deleted from the store) is replaced by the default.
|
|
109
|
+
*/
|
|
110
|
+
export function bindAgentAvatar(img, key, size, defaultUrl) {
|
|
111
|
+
img.dataset.agentKey = key;
|
|
112
|
+
img.dataset.agentSize = String(size);
|
|
113
|
+
img._agentDefaultUrl = defaultUrl || null;
|
|
114
|
+
if (!img._agentErrorBound) {
|
|
115
|
+
img._agentErrorBound = true;
|
|
116
|
+
img.addEventListener("error", function () {
|
|
117
|
+
// One swap only: a default that also fails must not loop.
|
|
118
|
+
if (img._agentFellBack || !img._agentFallbackUrl || img.src === img._agentFallbackUrl) return;
|
|
119
|
+
img._agentFellBack = true;
|
|
120
|
+
img.src = img._agentFallbackUrl;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
paint(img);
|
|
124
|
+
return img;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** A new <img> showing the avatar for key. */
|
|
128
|
+
export function createAgentAvatar(key, size, className, defaultUrl) {
|
|
129
|
+
var img = document.createElement("img");
|
|
130
|
+
if (className) img.className = className;
|
|
131
|
+
img.alt = "";
|
|
132
|
+
img.width = size;
|
|
133
|
+
img.height = size;
|
|
134
|
+
return bindAgentAvatar(img, key, size, defaultUrl);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Show an identity from injected-identity.js on img: bound to its agent when it
|
|
139
|
+
* names one, otherwise the plain avatar it resolved.
|
|
140
|
+
*/
|
|
141
|
+
export function applyIdentityAvatar(img, identity, size) {
|
|
142
|
+
if (identity.agentKey) return bindAgentAvatar(img, identity.agentKey, size, identity.defaultAvatarUrl);
|
|
143
|
+
img.src = identity.avatarUrl;
|
|
144
|
+
return img;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Repaint every avatar under root (default: the page) from the current choices. */
|
|
148
|
+
export function refreshAgentAvatars(root) {
|
|
149
|
+
var scope = root || (typeof document !== "undefined" ? document.body : null);
|
|
150
|
+
if (!scope || typeof scope.querySelectorAll !== "function") return;
|
|
151
|
+
var imgs = scope.querySelectorAll("img[data-agent-key]");
|
|
152
|
+
for (var i = 0; i < imgs.length; i++) paint(imgs[i]);
|
|
153
|
+
}
|
|
@@ -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
|
+
}
|