@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
package/lib/public/index.html
CHANGED
|
@@ -332,13 +332,6 @@
|
|
|
332
332
|
<div class="usage-row"><span class="usage-label">Terminals</span><span id="status-terminals" class="usage-value">-</span></div>
|
|
333
333
|
</div>
|
|
334
334
|
</div>
|
|
335
|
-
<div id="team-panel" class="hidden">
|
|
336
|
-
<div class="usage-panel-header">
|
|
337
|
-
<span>Team <span class="beta-badge">Beta</span></span>
|
|
338
|
-
<button id="team-panel-close" aria-label="Close"><i data-lucide="x"></i></button>
|
|
339
|
-
</div>
|
|
340
|
-
<div id="team-panel-body" class="usage-panel-body team-panel-body"></div>
|
|
341
|
-
</div>
|
|
342
335
|
<!-- Diagnostics panel (lr-8294, epic lr-1a52) -->
|
|
343
336
|
<div id="diagnostics-panel" class="hidden" role="region" aria-label="Diagnostics" aria-expanded="false" tabindex="-1">
|
|
344
337
|
<div class="usage-panel-header">
|
|
@@ -568,6 +561,13 @@
|
|
|
568
561
|
</div>
|
|
569
562
|
<div class="file-viewer-body" id="file-viewer-body"></div>
|
|
570
563
|
</div>
|
|
564
|
+
<div id="team-view" class="hidden" role="region" aria-label="Team">
|
|
565
|
+
<div class="team-view-header">
|
|
566
|
+
<h2 class="team-view-title">Team <span class="beta-badge">Beta</span></h2>
|
|
567
|
+
<button id="team-view-close" class="team-view-close" aria-label="Close"><i data-lucide="x"></i></button>
|
|
568
|
+
</div>
|
|
569
|
+
<div id="team-view-body" class="team-view-body"></div>
|
|
570
|
+
</div>
|
|
571
571
|
<div id="project-settings" class="hidden panel-fullscreen">
|
|
572
572
|
<div class="project-settings-layout">
|
|
573
573
|
<div class="project-settings-nav">
|
|
@@ -744,6 +744,7 @@
|
|
|
744
744
|
</div>
|
|
745
745
|
<div class="ps-env-tab-content active" data-tab="project">
|
|
746
746
|
<p class="settings-hint" id="ps-env-scope-hint" style="margin-bottom: 12px;"></p>
|
|
747
|
+
<div class="settings-hint ps-env-notice hidden" id="ps-env-shadow-notice"></div>
|
|
747
748
|
<div class="ps-env-header">
|
|
748
749
|
<button class="settings-btn-sm" id="ps-env-add-btn"><i data-lucide="plus"></i> Add Variable</button>
|
|
749
750
|
<span class="ps-save-status" id="ps-env-save-status"></span>
|
|
@@ -754,6 +755,7 @@
|
|
|
754
755
|
</div>
|
|
755
756
|
<div class="ps-env-tab-content" data-tab="shared">
|
|
756
757
|
<p class="settings-hint" style="margin-bottom: 12px;">Shared variables apply to every session in every project. Only administrators can change them. Project-level variables take precedence where they apply. Applies to sessions started after saving.</p>
|
|
758
|
+
<div class="settings-hint ps-env-notice hidden" id="ps-shared-env-shadow-notice"></div>
|
|
757
759
|
<div class="ps-env-header">
|
|
758
760
|
<button class="settings-btn-sm" id="ps-shared-env-add-btn"><i data-lucide="plus"></i> Add Variable</button>
|
|
759
761
|
<span class="ps-save-status" id="ps-shared-env-save-status"></span>
|
|
@@ -1237,6 +1239,29 @@
|
|
|
1237
1239
|
</label>
|
|
1238
1240
|
</div>
|
|
1239
1241
|
</div>
|
|
1242
|
+
<div class="settings-card settings-admin-only">
|
|
1243
|
+
<div class="settings-field">
|
|
1244
|
+
<label class="settings-toggle-row">
|
|
1245
|
+
<div>
|
|
1246
|
+
<span class="settings-label">Run commands typed with !</span>
|
|
1247
|
+
<div class="settings-hint">On (the default): a message that starts with <code>!</code> runs as a shell command in the session's folder and its output is added to the conversation without starting a turn. It asks first exactly as the agent's own Bash call would, and it is not available in plan mode or while OS-user isolation is on. Off: such a message is sent as ordinary text. Only an admin can change this.</div>
|
|
1248
|
+
</div>
|
|
1249
|
+
<input type="checkbox" id="ss-user-shell-enabled" checked>
|
|
1250
|
+
<span class="toggle-track"><span class="toggle-thumb"></span></span>
|
|
1251
|
+
</label>
|
|
1252
|
+
</div>
|
|
1253
|
+
<div class="settings-field">
|
|
1254
|
+
<label class="settings-label" for="ss-user-shell-timeout">Stop a command after (minutes)</label>
|
|
1255
|
+
<div class="settings-hint">Whole minutes, 1 to 1440. A command that runs longer is stopped and its card says so.</div>
|
|
1256
|
+
<input type="number" id="ss-user-shell-timeout" class="settings-budget-input" min="1" max="1440" step="1" value="10">
|
|
1257
|
+
</div>
|
|
1258
|
+
<div class="settings-field">
|
|
1259
|
+
<label class="settings-label" for="ss-user-shell-cap">Keep at most this much output (KiB)</label>
|
|
1260
|
+
<div class="settings-hint">Whole KiB, 1 to 4096. Output beyond it is cut and the card says so.</div>
|
|
1261
|
+
<input type="number" id="ss-user-shell-cap" class="settings-budget-input" min="1" max="4096" step="1" value="256">
|
|
1262
|
+
<div class="settings-hint" id="ss-user-shell-problem" role="alert"></div>
|
|
1263
|
+
</div>
|
|
1264
|
+
</div>
|
|
1240
1265
|
<div class="settings-card">
|
|
1241
1266
|
<div class="settings-field">
|
|
1242
1267
|
<label class="settings-label">Mode for sessions opened by the CLI or a trigger</label>
|
|
@@ -1307,6 +1332,17 @@
|
|
|
1307
1332
|
<div class="server-settings-section" data-section="claudemd">
|
|
1308
1333
|
<h2>CLAUDE.md</h2>
|
|
1309
1334
|
<p class="ps-section-desc">Edit the global CLAUDE.md file. These instructions apply to all projects and sessions on this server.</p>
|
|
1335
|
+
<h3 class="settings-subheading">Idle compaction (Claude)</h3>
|
|
1336
|
+
<div class="settings-card">
|
|
1337
|
+
<div class="settings-field">
|
|
1338
|
+
<div class="settings-hint">Whether Claude Code compacts a long conversation while a session is idle. This is the <code>idleCompaction</code> key in the Claude user settings file, the same file the CLI reads.</div>
|
|
1339
|
+
<div id="ss-idle-compaction-status" class="settings-hint"></div>
|
|
1340
|
+
<div class="ps-textarea-actions">
|
|
1341
|
+
<button class="settings-btn-sm" id="ss-idle-compaction-off">Turn off</button>
|
|
1342
|
+
<button class="settings-btn-sm" id="ss-idle-compaction-default">Use CLI default</button>
|
|
1343
|
+
</div>
|
|
1344
|
+
</div>
|
|
1345
|
+
</div>
|
|
1310
1346
|
<div class="settings-card">
|
|
1311
1347
|
<div class="settings-field">
|
|
1312
1348
|
<div id="ss-claudemd-status" class="settings-hint"></div>
|
|
@@ -1325,6 +1361,7 @@
|
|
|
1325
1361
|
<div class="server-settings-section" data-section="environment">
|
|
1326
1362
|
<h2>Environment</h2>
|
|
1327
1363
|
<p class="settings-hint" style="margin-bottom: 16px;">Define environment variables shared across all projects. Project-level variables take precedence over shared ones. Applies to sessions started after saving.</p>
|
|
1364
|
+
<div class="settings-hint ps-env-notice hidden" id="ss-env-shadow-notice"></div>
|
|
1328
1365
|
<div class="ps-env-header">
|
|
1329
1366
|
<button class="settings-btn-sm" id="ss-env-add-btn"><i data-lucide="plus"></i> Add Variable</button>
|
|
1330
1367
|
<span class="ps-save-status" id="ss-env-save-status"></span>
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
//
|
|
14
14
|
// Design notes:
|
|
15
15
|
//
|
|
16
|
+
// - Waiting: a session the daemon reports as blocked on an
|
|
17
|
+
// operator prompt (the `waiting` wire field, derived once in
|
|
18
|
+
// lib/session-liveness.js from the same pending-prompt data list-sessions
|
|
19
|
+
// serves) is its own tone, "waiting", and outranks alert: a blocked
|
|
20
|
+
// session is the one the operator must act on, and an unread badge on it
|
|
21
|
+
// must not hide that. It has its own class, "waiting", distinct from
|
|
22
|
+
// running and idle.
|
|
23
|
+
//
|
|
16
24
|
// - Precedence (LOCKED, operator ruling lr-0aa7b6, promoted here from its
|
|
17
25
|
// former home-hub-only special case): alert > processing > live > idle.
|
|
18
26
|
// "live" and "processing" collapse to the same visual state today (no
|
|
@@ -38,7 +46,7 @@
|
|
|
38
46
|
* @typedef {Object} ActivityState
|
|
39
47
|
* @property {boolean} active - true if there is any live activity to show a dot for.
|
|
40
48
|
* @property {boolean} alert - true if this represents unread/alert state (wins over active).
|
|
41
|
-
* @property {"alert"|"self"|"other"|"idle"} tone - which color family to render.
|
|
49
|
+
* @property {"waiting"|"alert"|"self"|"other"|"idle"} tone - which color family to render.
|
|
42
50
|
* @property {string} label - short human label for a title/tooltip attribute.
|
|
43
51
|
*/
|
|
44
52
|
|
|
@@ -61,6 +69,9 @@
|
|
|
61
69
|
* self-vs-other tone. Omit (or pass null/undefined) in single-user mode —
|
|
62
70
|
* every session then renders as 'self'.
|
|
63
71
|
* @param {object} [opts]
|
|
72
|
+
* @param {boolean} [opts.ignoreWaiting] - read only the turn flag, for the
|
|
73
|
+
* transcript footer, which says whether a turn is running and must not be
|
|
74
|
+
* pinned on by a session that is merely waiting on a prompt.
|
|
64
75
|
* @param {boolean} [opts.ignoreUnread] - suppress alert/unread from flipping
|
|
65
76
|
* `.active`/tone, for a consumer that has no unread-alert affordance of
|
|
66
77
|
* its own. Project-level dots (icon strip, mobile project rows, folder
|
|
@@ -81,6 +92,10 @@ export function sessionActivity(sess, currentUserId, opts) {
|
|
|
81
92
|
return { active: false, alert: false, tone: "idle", label: "Idle" };
|
|
82
93
|
}
|
|
83
94
|
|
|
95
|
+
if (sess.waiting && !(opts && opts.ignoreWaiting)) {
|
|
96
|
+
return { active: true, alert: false, tone: "waiting", label: "Waiting on a prompt" };
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
var alert = !(opts && opts.ignoreUnread) && (sess.unread || 0) > 0;
|
|
85
100
|
var active = !!sess.isProcessing;
|
|
86
101
|
|
|
@@ -123,7 +138,7 @@ export function deriveSessionListProcessing(sessions, activeSessionId) {
|
|
|
123
138
|
if (activeSessionId == null || !sessions) return { found: false, active: false };
|
|
124
139
|
for (var i = 0; i < sessions.length; i++) {
|
|
125
140
|
if (sessions[i].id === activeSessionId) {
|
|
126
|
-
return { found: true, active: sessionActivity(sessions[i], null, { ignoreUnread: true }).active };
|
|
141
|
+
return { found: true, active: sessionActivity(sessions[i], null, { ignoreUnread: true, ignoreWaiting: true }).active };
|
|
127
142
|
}
|
|
128
143
|
}
|
|
129
144
|
return { found: false, active: false };
|
|
@@ -132,7 +147,7 @@ export function deriveSessionListProcessing(sessions, activeSessionId) {
|
|
|
132
147
|
// Precedence used by both sessionActivity's tone choice above and
|
|
133
148
|
// rollupActivity's OR-reduce below. Higher wins. 'self' outranks 'other'
|
|
134
149
|
// per the locked rollup rule; 'alert' outranks everything.
|
|
135
|
-
var TONE_RANK = { idle: 0, other: 1, self: 2, alert: 3 };
|
|
150
|
+
var TONE_RANK = { idle: 0, other: 1, self: 2, alert: 3, waiting: 4 };
|
|
136
151
|
|
|
137
152
|
/**
|
|
138
153
|
* Roll up a list of already-derived (or raw session/project) items into a
|
|
@@ -180,10 +195,11 @@ export function rollupActivity(list, currentUserId, opts) {
|
|
|
180
195
|
/**
|
|
181
196
|
* The one place a CSS class suffix is chosen from an ActivityState.
|
|
182
197
|
* @param {ActivityState} state
|
|
183
|
-
* @returns {string} "" | "processing" | "alert" | "other"
|
|
198
|
+
* @returns {string} "" | "processing" | "alert" | "other" | "waiting"
|
|
184
199
|
*/
|
|
185
200
|
export function indicatorClass(state) {
|
|
186
201
|
if (!state || !state.active) return "";
|
|
202
|
+
if (state.tone === "waiting") return "waiting";
|
|
187
203
|
if (state.tone === "alert") return "alert";
|
|
188
204
|
if (state.tone === "other") return "other";
|
|
189
205
|
// tone === "self": the reconciled state. home-hub.css's stale comment
|
|
@@ -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
|
+
}
|