@clagentic/console 1.12.0 → 1.13.0-beta.1
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/README.md +7 -1
- package/bin/cli.js +18 -15
- package/lib/agent-roster-ws.js +38 -13
- package/lib/agent-roster.js +111 -12
- package/lib/agents.js +68 -33
- package/lib/atomic-install.js +334 -0
- package/lib/build-changes.js +33 -4
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +12 -0
- package/lib/chat-width.js +31 -0
- package/lib/cli/agent-usage.js +126 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/compact-output.js +69 -0
- package/lib/cli/ipc-subcommands.js +92 -67
- package/lib/cli/output.js +28 -0
- package/lib/cli/restart-verb.js +132 -0
- package/lib/cli/schedule-input-subcommands.js +45 -8
- package/lib/cli/session-subcommands.js +37 -11
- package/lib/cli/settings-subcommands.js +74 -0
- package/lib/cli-transcript-title.js +56 -3
- package/lib/client-files.js +79 -0
- package/lib/daemon.js +100 -28
- package/lib/default-avatar-color.js +4 -0
- package/lib/drain.js +58 -10
- package/lib/mcp-tool-input.js +2 -2
- package/lib/model-families.js +49 -1
- package/lib/notify/type-registry.js +4 -0
- package/lib/notify/types.js +7 -4
- package/lib/pages.js +13 -63
- package/lib/permission-summary.js +12 -16
- package/lib/plan-usage-reader.js +70 -0
- package/lib/project-connection.js +4 -2
- package/lib/project-filesystem.js +6 -7
- package/lib/project-notifications.js +55 -8
- package/lib/project-prompt-expiry-settings.js +42 -0
- package/lib/project-sessions.js +52 -0
- package/lib/project-settings-gate.js +98 -0
- package/lib/project-user-mention.js +3 -2
- package/lib/project.js +1 -1
- package/lib/prompt-expiry-settings.js +49 -0
- package/lib/prompt-expiry.js +24 -3
- package/lib/prompt-kinds/codecs.js +6 -2
- package/lib/public/app.js +36 -36
- package/lib/public/css/admin.css +156 -170
- package/lib/public/css/agent-messages.css +24 -24
- package/lib/public/css/agent-picker.css +90 -38
- package/lib/public/css/agent-roster.css +61 -27
- package/lib/public/css/at-agents.css +10 -10
- package/lib/public/css/base.css +207 -184
- package/lib/public/css/chat-layout.css +228 -0
- package/lib/public/css/command-palette.css +86 -88
- package/lib/public/css/diagnostics.css +78 -204
- package/lib/public/css/diff.css +10 -10
- package/lib/public/css/filebrowser.css +32 -60
- package/lib/public/css/home-hub.css +100 -100
- package/lib/public/css/icon-strip.css +195 -238
- package/lib/public/css/input.css +191 -212
- package/lib/public/css/login-panel.css +16 -16
- package/lib/public/css/loop.css +96 -187
- package/lib/public/css/mention.css +49 -110
- package/lib/public/css/menus.css +162 -169
- package/lib/public/css/messages.css +49 -123
- package/lib/public/css/mobile-nav.css +207 -264
- package/lib/public/css/notifications-center.css +45 -124
- package/lib/public/css/overlay.css +269 -0
- package/lib/public/css/overlays.css +134 -156
- package/lib/public/css/playbook.css +41 -41
- package/lib/public/css/profile.css +43 -112
- package/lib/public/css/rewind.css +112 -112
- package/lib/public/css/scheduler-modal.css +27 -135
- package/lib/public/css/scheduler.css +204 -210
- package/lib/public/css/server-settings.css +173 -239
- package/lib/public/css/session-search.css +20 -20
- package/lib/public/css/settings-nav.css +197 -0
- package/lib/public/css/sidebar.css +213 -304
- package/lib/public/css/skills.css +121 -135
- package/lib/public/css/sticky-notes.css +114 -200
- package/lib/public/css/stt.css +17 -26
- package/lib/public/css/team-panel.css +36 -36
- package/lib/public/css/team-view.css +9 -9
- package/lib/public/css/title-bar.css +83 -100
- package/lib/public/css/tooltip.css +10 -10
- package/lib/public/css/user-settings.css +78 -131
- package/lib/public/css/user-shell.css +125 -29
- package/lib/public/index.html +178 -177
- package/lib/public/manifest.json +0 -2
- package/lib/public/modules/admin.js +54 -92
- package/lib/public/modules/agent-avatar.js +134 -3
- package/lib/public/modules/agent-messages.js +2 -1
- package/lib/public/modules/agent-picker.js +23 -21
- package/lib/public/modules/agent-roster-groups.js +128 -0
- package/lib/public/modules/agent-roster.js +40 -11
- package/lib/public/modules/app-connection.js +13 -1
- package/lib/public/modules/app-cursors.js +9 -9
- package/lib/public/modules/app-favicon.js +8 -16
- package/lib/public/modules/app-header.js +28 -19
- package/lib/public/modules/app-history-replay.js +67 -4
- package/lib/public/modules/app-home-hub.js +15 -0
- package/lib/public/modules/app-loop-ui.js +41 -47
- package/lib/public/modules/app-loop-wizard.js +9 -10
- package/lib/public/modules/app-messages.js +32 -36
- package/lib/public/modules/app-misc.js +22 -92
- package/lib/public/modules/app-modals.js +98 -0
- package/lib/public/modules/app-notifications.js +124 -135
- package/lib/public/modules/app-panels.js +28 -32
- package/lib/public/modules/app-projects.js +30 -40
- package/lib/public/modules/app-rate-limit.js +26 -9
- package/lib/public/modules/app-rendering.js +128 -110
- package/lib/public/modules/app-skills-install.js +6 -4
- package/lib/public/modules/assistant-identity.js +55 -0
- package/lib/public/modules/at-agents.js +3 -0
- package/lib/public/modules/build-guard.js +25 -11
- package/lib/public/modules/chat-width-choice.js +75 -0
- package/lib/public/modules/chat-width-prefs.js +52 -0
- package/lib/public/modules/chat-width.js +102 -0
- package/lib/public/modules/collapsible-text.js +36 -4
- package/lib/public/modules/command-palette.js +28 -34
- package/lib/public/modules/context-sources.js +3 -5
- package/lib/public/modules/diagnostics.js +130 -129
- package/lib/public/modules/info-panel.js +31 -0
- package/lib/public/modules/injected-identity.js +8 -8
- package/lib/public/modules/input-list-menu.js +39 -0
- package/lib/public/modules/input.js +22 -21
- package/lib/public/modules/markdown.js +10 -11
- package/lib/public/modules/mcp-ui.js +4 -14
- package/lib/public/modules/mention.js +100 -229
- package/lib/public/modules/message-header.js +80 -0
- package/lib/public/modules/message-participants.js +39 -0
- package/lib/public/modules/mobile-action-sheet.js +46 -0
- package/lib/public/modules/mobile-nav-sheet.js +104 -0
- package/lib/public/modules/model-families.js +41 -4
- package/lib/public/modules/note-order.js +39 -0
- package/lib/public/modules/notifications.js +35 -52
- package/lib/public/modules/overlay-history.js +73 -19
- package/lib/public/modules/overlay-menu.js +123 -0
- package/lib/public/modules/overlay-modal.js +186 -0
- package/lib/public/modules/overlay-registry.js +392 -0
- package/lib/public/modules/overlay-stack.js +110 -0
- package/lib/public/modules/overlay.js +117 -0
- package/lib/public/modules/popover-position.js +18 -2
- package/lib/public/modules/preference-sync.js +28 -0
- package/lib/public/modules/profile.js +24 -49
- package/lib/public/modules/project-settings.js +27 -172
- package/lib/public/modules/prompt-expiry-controls.js +46 -0
- package/lib/public/modules/prompt-kinds/command-summary.js +149 -0
- package/lib/public/modules/prompt-kinds/permission.js +70 -92
- package/lib/public/modules/prompts.js +1 -2
- package/lib/public/modules/qrcode.js +6 -21
- package/lib/public/modules/queued-button.js +15 -2
- package/lib/public/modules/rewind.js +9 -3
- package/lib/public/modules/schedule-time.js +32 -7
- package/lib/public/modules/scheduled-outbox.js +51 -18
- package/lib/public/modules/scheduler-config.js +87 -127
- package/lib/public/modules/scheduler.js +29 -26
- package/lib/public/modules/serialized-save.js +79 -0
- package/lib/public/modules/server-settings.js +75 -65
- package/lib/public/modules/session-grants.js +16 -19
- package/lib/public/modules/session-list-avatars.js +98 -0
- package/lib/public/modules/session-vendor-state.js +86 -0
- package/lib/public/modules/settings-access.js +35 -0
- package/lib/public/modules/settings-hub.js +125 -0
- package/lib/public/modules/settings-nav.js +182 -0
- package/lib/public/modules/shell-line.js +24 -0
- package/lib/public/modules/sidebar-mobile.js +151 -195
- package/lib/public/modules/sidebar-projects.js +88 -129
- package/lib/public/modules/sidebar-sessions.js +66 -34
- package/lib/public/modules/sidebar.js +2 -2
- package/lib/public/modules/skills.js +11 -26
- package/lib/public/modules/sticky-notes.js +19 -16
- package/lib/public/modules/stt.js +9 -23
- package/lib/public/modules/terminal.js +86 -90
- package/lib/public/modules/theme-choice.js +126 -0
- package/lib/public/modules/theme-colors.js +19 -0
- package/lib/public/modules/theme-prefs.js +121 -0
- package/lib/public/modules/theme.js +227 -605
- package/lib/public/modules/tool-palette.js +7 -17
- package/lib/public/modules/tools.js +8 -10
- package/lib/public/modules/user-settings.js +59 -115
- package/lib/public/modules/user-shell.js +9 -2
- package/lib/public/modules/utils.js +10 -12
- package/lib/public/modules/vendor-picker.js +4 -2
- package/lib/public/modules/vendor-registry.js +1 -2
- package/lib/public/style.css +3 -1
- package/lib/public/sw.js +9 -2
- package/lib/public/theme-core.js +411 -0
- package/lib/request-body.js +70 -0
- package/lib/sdk-bridge.js +227 -88
- package/lib/sdk-message-processor.js +44 -16
- package/lib/server-admin.js +198 -200
- package/lib/server-auth.js +16 -13
- package/lib/server-dm.js +4 -3
- package/lib/server-settings.js +177 -130
- package/lib/server.js +87 -36
- package/lib/session-background-tasks.js +79 -0
- package/lib/session-directory.js +138 -13
- package/lib/session-input-ipc.js +2 -0
- package/lib/session-input.js +39 -5
- package/lib/session-list-avatars.js +16 -0
- package/lib/session-reclaim.js +37 -25
- package/lib/session-vendor.js +37 -0
- package/lib/sessions.js +99 -34
- package/lib/settings-ipc.js +60 -0
- package/lib/settings-registry.js +86 -0
- package/lib/terminal-manager.js +17 -5
- package/lib/theme-files.js +132 -0
- package/lib/theme-seed.js +136 -0
- package/lib/themes/clagentic-dark.json +13 -6
- package/lib/themes/clagentic-light.json +12 -5
- package/lib/updater.js +6 -4
- package/lib/usage-store.js +97 -10
- package/lib/users-preferences.js +118 -19
- package/lib/users.js +19 -10
- package/lib/vendor-catalog.js +130 -0
- package/lib/ws-schema.js +4 -2
- package/lib/yoke/adapters/claude.js +81 -1
- package/lib/yoke/adapters/codex-user-shell.js +87 -23
- package/lib/yoke/adapters/codex.js +89 -5
- package/lib/yoke/codex-binary.js +59 -0
- package/package.json +1 -1
- package/scripts/check-test-count.js +5 -0
- package/scripts/install-local-test.js +50 -9
- package/scripts/write-build-sha.js +18 -2
- package/lib/public/css/channel-layout.css +0 -329
- package/lib/themes/ayu-light.json +0 -9
- package/lib/themes/catppuccin-latte.json +0 -9
- package/lib/themes/catppuccin-mocha.json +0 -9
- package/lib/themes/dracula.json +0 -9
- package/lib/themes/everforest-light.json +0 -9
- package/lib/themes/everforest.json +0 -9
- package/lib/themes/github-light.json +0 -9
- package/lib/themes/gruvbox-dark.json +0 -9
- package/lib/themes/gruvbox-light.json +0 -9
- package/lib/themes/monokai.json +0 -9
- package/lib/themes/nord-light.json +0 -9
- package/lib/themes/nord.json +0 -9
- package/lib/themes/one-dark.json +0 -9
- package/lib/themes/one-light.json +0 -9
- package/lib/themes/rose-pine-dawn.json +0 -9
- package/lib/themes/rose-pine.json +0 -9
- package/lib/themes/solarized-dark.json +0 -9
- package/lib/themes/solarized-light.json +0 -9
- package/lib/themes/tokyo-night-light.json +0 -9
- package/lib/themes/tokyo-night.json +0 -9
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "Dark",
|
|
3
3
|
"author": "Clagentic",
|
|
4
4
|
"variant": "dark",
|
|
5
|
-
"base00": "
|
|
6
|
-
"base04": "
|
|
7
|
-
"base08": "
|
|
8
|
-
"base0C": "
|
|
9
|
-
"accent2": "
|
|
5
|
+
"base00": "1C2433", "base01": "242E40", "base02": "364257", "base03": "8E9DB3",
|
|
6
|
+
"base04": "A7B5C8", "base05": "C5D0DE", "base06": "EAF0F8", "base07": "F5F9FF",
|
|
7
|
+
"base08": "FF8094", "base09": "00CFFF", "base0A": "7BA7F7", "base0B": "29D9A8",
|
|
8
|
+
"base0C": "A78BFA", "base0D": "7BA7F7", "base0E": "C084FC", "base0F": "818CF8",
|
|
9
|
+
"accent2": "7BA7F7",
|
|
10
|
+
"tokens": {
|
|
11
|
+
"sidebar-bg": "141B28", "sidebar-active": "263245", "user-bubble": "2E3A4F",
|
|
12
|
+
"input-bg": "374359", "code-bg": "101722",
|
|
13
|
+
"border-subtle": "2A3548", "border-strong": "8294AE",
|
|
14
|
+
"warning": "F59E0B", "on-accent": "0B1220", "on-av": "0B1220",
|
|
15
|
+
"av0": "7FD8F0", "av1": "B9A3F5", "av2": "7FE0C2", "av3": "F2C879"
|
|
16
|
+
}
|
|
10
17
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "Light",
|
|
3
3
|
"author": "Clagentic",
|
|
4
4
|
"variant": "light",
|
|
5
|
-
"base00": "
|
|
6
|
-
"base04": "
|
|
7
|
-
"base08": "
|
|
5
|
+
"base00": "F1F4F9", "base01": "FFFFFF", "base02": "CBD5E3", "base03": "566680",
|
|
6
|
+
"base04": "4A5B72", "base05": "2B3A4F", "base06": "0F1724", "base07": "060A12",
|
|
7
|
+
"base08": "B3122D", "base09": "006D94", "base0A": "2D5EB8", "base0B": "0A6B4A",
|
|
8
8
|
"base0C": "6128B8", "base0D": "2D5EB8", "base0E": "7C3AED", "base0F": "4F46E5",
|
|
9
|
-
"accent2": "2D5EB8"
|
|
9
|
+
"accent2": "2D5EB8",
|
|
10
|
+
"tokens": {
|
|
11
|
+
"sidebar-bg": "E2E8F1", "sidebar-active": "D3DEEE", "user-bubble": "D9E6F7",
|
|
12
|
+
"input-bg": "FFFFFF", "code-bg": "E9EEF5",
|
|
13
|
+
"border-subtle": "DDE4EE", "border-strong": "73849C",
|
|
14
|
+
"warning": "8A5300", "on-accent": "FFFFFF", "on-av": "FFFFFF",
|
|
15
|
+
"av0": "0B6E8A", "av1": "6A3FC4", "av2": "0D7A55", "av3": "9A5B00"
|
|
16
|
+
}
|
|
10
17
|
}
|
package/lib/updater.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const https = require("https");
|
|
2
|
-
const {
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
3
|
|
|
4
4
|
// ANSI helpers (mirrors cli.js)
|
|
5
5
|
var isBasicTerm = process.env.TERM_PROGRAM === "Apple_Terminal";
|
|
@@ -86,10 +86,12 @@ function isNewer(latest, current) {
|
|
|
86
86
|
// one isNewer() approved, which is how a beta machine got silently downgraded to
|
|
87
87
|
// whatever @latest happened to point at. Pinning the resolved version makes a
|
|
88
88
|
// downgrade structurally impossible.
|
|
89
|
-
|
|
89
|
+
// Goes through the staged install and atomic swap so the command stays on PATH
|
|
90
|
+
// while the new build is installed.
|
|
91
|
+
async function performUpdate(version) {
|
|
90
92
|
if (!version) return false;
|
|
91
93
|
try {
|
|
92
|
-
|
|
94
|
+
await require("./atomic-install").installGlobalAtomically({ spec: "@clagentic/console@" + version });
|
|
93
95
|
return true;
|
|
94
96
|
} catch (e) {
|
|
95
97
|
return false;
|
|
@@ -137,7 +139,7 @@ async function checkAndUpdate(currentVersion, skipUpdate, channel) {
|
|
|
137
139
|
|
|
138
140
|
// Install the exact resolved version, not a dist-tag — the announced version
|
|
139
141
|
// and the installed version are then guaranteed identical.
|
|
140
|
-
if (performUpdate(latest)) {
|
|
142
|
+
if (await performUpdate(latest)) {
|
|
141
143
|
log(sym.done + " Updated to " + a.green + latest + a.reset);
|
|
142
144
|
log("");
|
|
143
145
|
reExec();
|
package/lib/usage-store.js
CHANGED
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
// at start. Freshness is computed at read time and never stored, so a reloaded
|
|
7
7
|
// record reads stale/expired honestly and is never re-stamped as fresh.
|
|
8
8
|
//
|
|
9
|
+
// A reset (a changed resetsAt, or a status that drops to a lower severity) ends
|
|
10
|
+
// the window: an event with no utilization then reports utilization null, and
|
|
11
|
+
// the prior value moves to lastKnownUtilization/lastKnownObservedAt, labelled
|
|
12
|
+
// lastKnownPreReset in the snapshot. Within a window the value carries over.
|
|
13
|
+
// At read time an unconfirmed utilization older than the stale horizon is shown
|
|
14
|
+
// the same way, labelled lastKnownStale, so a carried value never reads as current.
|
|
15
|
+
// A value whose resetsAt has passed belongs to a closed window: it is shown as
|
|
16
|
+
// lastKnown with lastKnownPreReset, confirmed or not, ahead of the stale rule.
|
|
17
|
+
//
|
|
9
18
|
// Two timestamps per bucket: observedAt (the last reported event, i.e. the last
|
|
10
19
|
// time the value changed) and confirmedAt (the last evidence the value still
|
|
11
20
|
// holds). Some adapters report only on change, so a steady value goes silent
|
|
@@ -84,9 +93,16 @@ function validRecord(r) {
|
|
|
84
93
|
// confirmedAt is absent in files written before confirmation existed.
|
|
85
94
|
var confirmedAt = r.confirmedAt === undefined ? null : r.confirmedAt;
|
|
86
95
|
if (!isIsoOrNull(confirmedAt)) return null;
|
|
96
|
+
// The pre-reset pair is absent in files written before it existed, and is
|
|
97
|
+
// kept only when both halves are usable and the current value is unknown.
|
|
98
|
+
var lastKnown = finiteOrNull(r.lastKnownUtilization);
|
|
99
|
+
var lastKnownAt = typeof r.lastKnownObservedAt === "string" && isFinite(Date.parse(r.lastKnownObservedAt)) ? r.lastKnownObservedAt : null;
|
|
100
|
+
if (lastKnown === null || lastKnownAt === null || r.utilization !== null) { lastKnown = null; lastKnownAt = null; }
|
|
87
101
|
return {
|
|
88
102
|
utilization: r.utilization,
|
|
89
103
|
utilizationObservedAt: r.utilizationObservedAt,
|
|
104
|
+
lastKnownUtilization: lastKnown,
|
|
105
|
+
lastKnownObservedAt: lastKnownAt,
|
|
90
106
|
resetsAt: r.resetsAt,
|
|
91
107
|
status: r.status,
|
|
92
108
|
observedAt: r.observedAt,
|
|
@@ -96,6 +112,20 @@ function validRecord(r) {
|
|
|
96
112
|
};
|
|
97
113
|
}
|
|
98
114
|
|
|
115
|
+
// Severity of the statuses the adapters report. A status not listed here has no
|
|
116
|
+
// rank, so it is never evidence of a reset.
|
|
117
|
+
var STATUS_SEVERITY = { allowed: 0, allowed_warning: 1, rejected: 2 };
|
|
118
|
+
|
|
119
|
+
// True when the new event shows the reset window changed: a different resetsAt,
|
|
120
|
+
// or a status that dropped to a lower severity within the same resetsAt (an
|
|
121
|
+
// early account reset leaves resetsAt unchanged).
|
|
122
|
+
function isResetSignal(prev, resetsAt, status) {
|
|
123
|
+
if (prev.resetsAt !== resetsAt) return true;
|
|
124
|
+
var before = Object.prototype.hasOwnProperty.call(STATUS_SEVERITY, prev.status) ? STATUS_SEVERITY[prev.status] : null;
|
|
125
|
+
var after = Object.prototype.hasOwnProperty.call(STATUS_SEVERITY, status) ? STATUS_SEVERITY[status] : null;
|
|
126
|
+
return before !== null && after !== null && after < before;
|
|
127
|
+
}
|
|
128
|
+
|
|
99
129
|
function newestMs(rec) {
|
|
100
130
|
var o = Date.parse(rec.observedAt);
|
|
101
131
|
var c = rec.confirmedAt ? Date.parse(rec.confirmedAt) : -Infinity;
|
|
@@ -220,7 +250,8 @@ function createUsageStore(opts) {
|
|
|
220
250
|
//
|
|
221
251
|
// meta.processKey (optional) identifies the session's current process; with
|
|
222
252
|
// meta.sessionLocalId it registers the session as an emitter that confirm()
|
|
223
|
-
// may later act for.
|
|
253
|
+
// may later act for. meta.keepStatus carries the previous status of the same
|
|
254
|
+
// reset window when the event has none.
|
|
224
255
|
function record(vendor, info, meta) {
|
|
225
256
|
if (!vendor || !info) return;
|
|
226
257
|
if (!info.rateLimitType) {
|
|
@@ -231,23 +262,45 @@ function createUsageStore(opts) {
|
|
|
231
262
|
meta = meta || {};
|
|
232
263
|
var now = meta.now !== undefined ? meta.now : Date.now();
|
|
233
264
|
var util = finiteOrNull(info.utilization);
|
|
234
|
-
|
|
265
|
+
// Whole seconds: the window is compared by equality, and a fractional
|
|
266
|
+
// reset time from one source must match the whole-second one from another.
|
|
267
|
+
var resetsAt = epochSecondsToIsoOrNull(typeof info.resetsAt === "number" ? Math.floor(info.resetsAt) : info.resetsAt);
|
|
235
268
|
var byBucket = records[vendor] || (records[vendor] = newMap());
|
|
236
269
|
var prev = byBucket[info.rateLimitType];
|
|
237
270
|
var utilizationObservedAt = util !== null ? toIso(now) : null;
|
|
238
271
|
|
|
239
|
-
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
272
|
+
var status = strOrNull(info.status) || null;
|
|
273
|
+
// A source that reports no status (a plan-usage reading) must not erase the
|
|
274
|
+
// status of the same window that a rate-limit event reported.
|
|
275
|
+
if (status === null && meta.keepStatus && prev && prev.resetsAt === resetsAt) status = prev.status;
|
|
276
|
+
var lastKnown = null;
|
|
277
|
+
var lastKnownObservedAt = null;
|
|
278
|
+
|
|
279
|
+
if (util === null && prev) {
|
|
280
|
+
if (!isResetSignal(prev, resetsAt, status)) {
|
|
281
|
+
// An event without a utilization must not erase a known one for the same
|
|
282
|
+
// reset window; the old value keeps its own observation time.
|
|
283
|
+
util = prev.utilization;
|
|
284
|
+
utilizationObservedAt = prev.utilizationObservedAt;
|
|
285
|
+
lastKnown = prev.lastKnownUtilization;
|
|
286
|
+
lastKnownObservedAt = prev.lastKnownObservedAt;
|
|
287
|
+
} else if (prev.utilization !== null) {
|
|
288
|
+
// After a reset the old number is history, not the current reading.
|
|
289
|
+
lastKnown = prev.utilization;
|
|
290
|
+
lastKnownObservedAt = prev.utilizationObservedAt;
|
|
291
|
+
} else {
|
|
292
|
+
lastKnown = prev.lastKnownUtilization;
|
|
293
|
+
lastKnownObservedAt = prev.lastKnownObservedAt;
|
|
294
|
+
}
|
|
244
295
|
}
|
|
245
296
|
|
|
246
297
|
byBucket[info.rateLimitType] = {
|
|
247
298
|
utilization: util,
|
|
248
299
|
utilizationObservedAt: utilizationObservedAt,
|
|
300
|
+
lastKnownUtilization: util === null ? lastKnown : null,
|
|
301
|
+
lastKnownObservedAt: util === null ? lastKnownObservedAt : null,
|
|
249
302
|
resetsAt: resetsAt,
|
|
250
|
-
status:
|
|
303
|
+
status: status,
|
|
251
304
|
observedAt: toIso(now),
|
|
252
305
|
confirmedAt: null,
|
|
253
306
|
source: strOrNull(meta.source) || null,
|
|
@@ -291,7 +344,7 @@ function createUsageStore(opts) {
|
|
|
291
344
|
|
|
292
345
|
function view(rec, now, staleSec) {
|
|
293
346
|
if (!rec) {
|
|
294
|
-
return { utilization: null, resetsAt: null, status: null, observedAt: null, confirmedAt: null, ageSeconds: null, state: "unknown", source: null, utilizationConfirmed: false };
|
|
347
|
+
return { utilization: null, lastKnownUtilization: null, lastKnownObservedAt: null, lastKnownPreReset: false, lastKnownStale: false, lastKnownAgeSeconds: null, resetsAt: null, status: null, observedAt: null, confirmedAt: null, ageSeconds: null, state: "unknown", source: null, utilizationConfirmed: false };
|
|
295
348
|
}
|
|
296
349
|
var newest = newestMs(rec);
|
|
297
350
|
var ageSeconds = Math.max(0, Math.round((now - newest) / 1000));
|
|
@@ -302,10 +355,44 @@ function createUsageStore(opts) {
|
|
|
302
355
|
// confirms it, but only when the latest event itself carried the value.
|
|
303
356
|
var utilizationConfirmed = rec.utilization !== null && rec.confirmedAt !== null &&
|
|
304
357
|
rec.utilizationObservedAt === rec.observedAt;
|
|
358
|
+
// A carried utilization keeps its own observation time while every new event
|
|
359
|
+
// refreshes observedAt, so the bucket state cannot show its age. Decided here,
|
|
360
|
+
// not stored, so a record persisted before this rule is corrected on read.
|
|
361
|
+
var utilization = rec.utilization;
|
|
362
|
+
var lastKnown = rec.lastKnownUtilization;
|
|
363
|
+
var lastKnownAt = rec.lastKnownObservedAt;
|
|
364
|
+
var lastKnownStale = false;
|
|
365
|
+
var lastKnownAgeSeconds = null;
|
|
366
|
+
var lastKnownPreReset = rec.lastKnownUtilization !== null;
|
|
367
|
+
var utilMs = rec.utilizationObservedAt ? Date.parse(rec.utilizationObservedAt) : NaN;
|
|
368
|
+
if (utilization !== null && state === "expired") {
|
|
369
|
+
// The window the value belongs to has ended, so it is history whether or
|
|
370
|
+
// not it was confirmed. Wins over the stale rule below; no resetsAt means
|
|
371
|
+
// no evidence of an ended window, so state is never "expired" then.
|
|
372
|
+
lastKnown = utilization;
|
|
373
|
+
lastKnownAt = rec.utilizationObservedAt;
|
|
374
|
+
lastKnownPreReset = true;
|
|
375
|
+
utilization = null;
|
|
376
|
+
utilizationConfirmed = false;
|
|
377
|
+
} else if (utilization !== null && !utilizationConfirmed && isFinite(utilMs)) {
|
|
378
|
+
var utilAge = Math.max(0, Math.round((now - utilMs) / 1000));
|
|
379
|
+
if (utilAge > staleSec) {
|
|
380
|
+
lastKnown = utilization;
|
|
381
|
+
lastKnownAt = rec.utilizationObservedAt;
|
|
382
|
+
lastKnownStale = true;
|
|
383
|
+
lastKnownAgeSeconds = utilAge;
|
|
384
|
+
utilization = null;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
305
387
|
var out = {
|
|
306
|
-
utilization:
|
|
388
|
+
utilization: utilization,
|
|
307
389
|
utilizationObservedAt: rec.utilizationObservedAt,
|
|
308
390
|
utilizationConfirmed: utilizationConfirmed,
|
|
391
|
+
lastKnownUtilization: lastKnown,
|
|
392
|
+
lastKnownObservedAt: lastKnownAt,
|
|
393
|
+
lastKnownPreReset: lastKnownPreReset,
|
|
394
|
+
lastKnownStale: lastKnownStale,
|
|
395
|
+
lastKnownAgeSeconds: lastKnownAgeSeconds,
|
|
309
396
|
resetsAt: rec.resetsAt,
|
|
310
397
|
status: rec.status,
|
|
311
398
|
observedAt: rec.observedAt,
|
package/lib/users-preferences.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
var isValidThemeId = require("./theme-files").isValidThemeId;
|
|
2
|
+
var chatWidth = require("./chat-width");
|
|
3
|
+
var isChatWidth = chatWidth.isChatWidth;
|
|
4
|
+
var widthFromLegacyLayout = chatWidth.widthFromLegacyLayout;
|
|
5
|
+
|
|
1
6
|
function attachPreferences(deps) {
|
|
2
7
|
var loadUsers = deps.loadUsers;
|
|
3
8
|
var saveUsers = deps.saveUsers;
|
|
@@ -87,32 +92,88 @@ function attachPreferences(deps) {
|
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
|
|
90
|
-
// --- Per-user chat
|
|
95
|
+
// --- Per-user chat width ---
|
|
96
|
+
//
|
|
97
|
+
// chatWidth: one of CHAT_WIDTHS, or absent (the server's default applies).
|
|
98
|
+
|
|
99
|
+
function getChatWidth(userId) {
|
|
100
|
+
var data = loadUsers();
|
|
101
|
+
for (var i = 0; i < data.users.length; i++) {
|
|
102
|
+
if (data.users[i].id === userId) {
|
|
103
|
+
return isChatWidth(data.users[i].chatWidth) ? data.users[i].chatWidth : null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function setChatWidth(userId, width) {
|
|
110
|
+
if (!isChatWidth(width)) return { error: "Invalid chat width" };
|
|
111
|
+
var data = loadUsers();
|
|
112
|
+
for (var i = 0; i < data.users.length; i++) {
|
|
113
|
+
if (data.users[i].id === userId) {
|
|
114
|
+
data.users[i].chatWidth = width;
|
|
115
|
+
saveUsers(data);
|
|
116
|
+
return { ok: true, chatWidth: width };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { error: "User not found" };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// --- Per-user "Avatars in session list" ---
|
|
123
|
+
//
|
|
124
|
+
// sessionListAvatars: true | false, or absent (the server's default applies).
|
|
91
125
|
|
|
92
|
-
function
|
|
126
|
+
function getSessionListAvatars(userId) {
|
|
93
127
|
var data = loadUsers();
|
|
94
128
|
for (var i = 0; i < data.users.length; i++) {
|
|
95
129
|
if (data.users[i].id === userId) {
|
|
96
|
-
return data.users[i].
|
|
130
|
+
return typeof data.users[i].sessionListAvatars === "boolean" ? data.users[i].sessionListAvatars : null;
|
|
97
131
|
}
|
|
98
132
|
}
|
|
99
|
-
return
|
|
133
|
+
return null;
|
|
100
134
|
}
|
|
101
135
|
|
|
102
|
-
function
|
|
103
|
-
|
|
136
|
+
function setSessionListAvatars(userId, enabled) {
|
|
137
|
+
if (typeof enabled !== "boolean") return { error: "Invalid session list avatars value" };
|
|
104
138
|
var data = loadUsers();
|
|
105
139
|
for (var i = 0; i < data.users.length; i++) {
|
|
106
140
|
if (data.users[i].id === userId) {
|
|
107
|
-
data.users[i].
|
|
141
|
+
data.users[i].sessionListAvatars = enabled;
|
|
108
142
|
saveUsers(data);
|
|
109
|
-
return { ok: true,
|
|
143
|
+
return { ok: true, sessionListAvatars: enabled };
|
|
110
144
|
}
|
|
111
145
|
}
|
|
112
146
|
return { error: "User not found" };
|
|
113
147
|
}
|
|
114
148
|
|
|
115
|
-
//
|
|
149
|
+
// One-time rewrite of the retired bubble/channel choice: bubble becomes
|
|
150
|
+
// Comfortable and channel becomes Full, with no prompt. A user who never chose
|
|
151
|
+
// keeps no stored value and gets the default. The old key is always dropped, so
|
|
152
|
+
// this saves only when something changed and runs once. A width the user has
|
|
153
|
+
// already chosen is never overwritten. Returns { changed: <users rewritten> }.
|
|
154
|
+
function migrateAllChatLayouts() {
|
|
155
|
+
var data = loadUsers();
|
|
156
|
+
var changed = 0;
|
|
157
|
+
for (var i = 0; i < data.users.length; i++) {
|
|
158
|
+
var user = data.users[i];
|
|
159
|
+
if (!Object.prototype.hasOwnProperty.call(user, "chatLayout")) continue;
|
|
160
|
+
var mapped = widthFromLegacyLayout(user.chatLayout);
|
|
161
|
+
if (mapped && !isChatWidth(user.chatWidth)) user.chatWidth = mapped;
|
|
162
|
+
delete user.chatLayout;
|
|
163
|
+
changed++;
|
|
164
|
+
}
|
|
165
|
+
if (changed) saveUsers(data);
|
|
166
|
+
return { changed: changed };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// --- Per-user theme choice ---
|
|
170
|
+
//
|
|
171
|
+
// themeMode: "light" | "dark" | absent (follow the system).
|
|
172
|
+
// themeId: the id of a custom theme file, or absent. It overrides the mode
|
|
173
|
+
// while the file exists; choosing a mode clears it.
|
|
174
|
+
// themeBrand is retired (the Classic brand is gone). migrateAllThemePrefs drops
|
|
175
|
+
// it for every user when the server starts, so a stored value never
|
|
176
|
+
// outlives the upgrade.
|
|
116
177
|
|
|
117
178
|
function getThemeMode(userId) {
|
|
118
179
|
var data = loadUsers();
|
|
@@ -130,6 +191,8 @@ function attachPreferences(deps) {
|
|
|
130
191
|
for (var i = 0; i < data.users.length; i++) {
|
|
131
192
|
if (data.users[i].id === userId) {
|
|
132
193
|
data.users[i].themeMode = val;
|
|
194
|
+
// A mode choice (Dark, Light or Follow system) replaces a custom theme.
|
|
195
|
+
delete data.users[i].themeId;
|
|
133
196
|
saveUsers(data);
|
|
134
197
|
return { ok: true, themeMode: val };
|
|
135
198
|
}
|
|
@@ -137,29 +200,61 @@ function attachPreferences(deps) {
|
|
|
137
200
|
return { error: "User not found" };
|
|
138
201
|
}
|
|
139
202
|
|
|
140
|
-
function
|
|
203
|
+
function getThemeId(userId) {
|
|
141
204
|
var data = loadUsers();
|
|
142
205
|
for (var i = 0; i < data.users.length; i++) {
|
|
143
206
|
if (data.users[i].id === userId) {
|
|
144
|
-
return data.users[i].
|
|
207
|
+
return isValidThemeId(data.users[i].themeId) ? data.users[i].themeId : null;
|
|
145
208
|
}
|
|
146
209
|
}
|
|
147
210
|
return null;
|
|
148
211
|
}
|
|
149
212
|
|
|
150
|
-
function
|
|
151
|
-
var val = (
|
|
213
|
+
function setThemeId(userId, themeId) {
|
|
214
|
+
var val = isValidThemeId(themeId) ? themeId : null;
|
|
152
215
|
var data = loadUsers();
|
|
153
216
|
for (var i = 0; i < data.users.length; i++) {
|
|
154
217
|
if (data.users[i].id === userId) {
|
|
155
|
-
data.users[i].
|
|
218
|
+
if (val) data.users[i].themeId = val;
|
|
219
|
+
else delete data.users[i].themeId;
|
|
156
220
|
saveUsers(data);
|
|
157
|
-
return { ok: true,
|
|
221
|
+
return { ok: true, themeId: val };
|
|
158
222
|
}
|
|
159
223
|
}
|
|
160
224
|
return { error: "User not found" };
|
|
161
225
|
}
|
|
162
226
|
|
|
227
|
+
// One-time rewrite of every user's stored theme preferences. Dropping
|
|
228
|
+
// themeBrand is the whole mapping: the stored mode already says dark or
|
|
229
|
+
// light, and the Clagentic theme of that mode is what the browser applies
|
|
230
|
+
// (a classic-brand user with no stored mode follows the system, as before).
|
|
231
|
+
// A mode that is neither light nor dark, or a theme id that is not a legal
|
|
232
|
+
// id, is dropped too. Saves only when something changed, so it runs once.
|
|
233
|
+
// Returns { changed: <number of users rewritten> }.
|
|
234
|
+
function migrateAllThemePrefs() {
|
|
235
|
+
var data = loadUsers();
|
|
236
|
+
var changed = 0;
|
|
237
|
+
for (var i = 0; i < data.users.length; i++) {
|
|
238
|
+
var user = data.users[i];
|
|
239
|
+
var touched = false;
|
|
240
|
+
if (Object.prototype.hasOwnProperty.call(user, "themeBrand")) {
|
|
241
|
+
delete user.themeBrand;
|
|
242
|
+
touched = true;
|
|
243
|
+
}
|
|
244
|
+
if (user.themeMode !== undefined && user.themeMode !== null && user.themeMode !== "light" && user.themeMode !== "dark") {
|
|
245
|
+
delete user.themeMode;
|
|
246
|
+
touched = true;
|
|
247
|
+
}
|
|
248
|
+
if (user.themeId !== undefined && !isValidThemeId(user.themeId)) {
|
|
249
|
+
delete user.themeId;
|
|
250
|
+
touched = true;
|
|
251
|
+
}
|
|
252
|
+
if (touched) changed++;
|
|
253
|
+
}
|
|
254
|
+
if (changed) saveUsers(data);
|
|
255
|
+
return { changed: changed };
|
|
256
|
+
}
|
|
257
|
+
|
|
163
258
|
// --- Per-user auto-continue setting ---
|
|
164
259
|
|
|
165
260
|
function getAutoContinue(userId) {
|
|
@@ -238,12 +333,16 @@ function attachPreferences(deps) {
|
|
|
238
333
|
getDmHidden: getDmHidden,
|
|
239
334
|
addDmHidden: addDmHidden,
|
|
240
335
|
removeDmHidden: removeDmHidden,
|
|
241
|
-
|
|
242
|
-
|
|
336
|
+
getChatWidth: getChatWidth,
|
|
337
|
+
setChatWidth: setChatWidth,
|
|
338
|
+
getSessionListAvatars: getSessionListAvatars,
|
|
339
|
+
setSessionListAvatars: setSessionListAvatars,
|
|
340
|
+
migrateAllChatLayouts: migrateAllChatLayouts,
|
|
243
341
|
getThemeMode: getThemeMode,
|
|
244
342
|
setThemeMode: setThemeMode,
|
|
245
|
-
|
|
246
|
-
|
|
343
|
+
getThemeId: getThemeId,
|
|
344
|
+
setThemeId: setThemeId,
|
|
345
|
+
migrateAllThemePrefs: migrateAllThemePrefs,
|
|
247
346
|
getAutoContinue: getAutoContinue,
|
|
248
347
|
setAutoContinue: setAutoContinue,
|
|
249
348
|
getToolPalettes: getToolPalettes,
|
package/lib/users.js
CHANGED
|
@@ -3,6 +3,7 @@ var path = require("path");
|
|
|
3
3
|
var crypto = require("crypto");
|
|
4
4
|
var execFileSync = require("child_process").execFileSync;
|
|
5
5
|
var { CONFIG_DIR } = require("./config");
|
|
6
|
+
var { DEFAULT_AVATAR_COLOR } = require("./default-avatar-color");
|
|
6
7
|
var { attachAuth } = require("./users-auth");
|
|
7
8
|
var { DEFAULT_PERMISSIONS, ALL_PERMISSIONS, attachPermissions } = require("./users-permissions");
|
|
8
9
|
var { attachPreferences } = require("./users-preferences");
|
|
@@ -106,7 +107,7 @@ function createUser(opts) {
|
|
|
106
107
|
profile: opts.profile || {
|
|
107
108
|
name: opts.displayName || opts.username,
|
|
108
109
|
lang: "en-US",
|
|
109
|
-
avatarColor:
|
|
110
|
+
avatarColor: DEFAULT_AVATAR_COLOR,
|
|
110
111
|
avatarStyle: "thumbs",
|
|
111
112
|
avatarSeed: crypto.randomBytes(4).toString("hex"),
|
|
112
113
|
},
|
|
@@ -326,7 +327,7 @@ function createUserWithoutPin(opts) {
|
|
|
326
327
|
profile: opts.profile || {
|
|
327
328
|
name: opts.displayName || opts.username,
|
|
328
329
|
lang: "en-US",
|
|
329
|
-
avatarColor:
|
|
330
|
+
avatarColor: DEFAULT_AVATAR_COLOR,
|
|
330
331
|
avatarStyle: "thumbs",
|
|
331
332
|
avatarSeed: crypto.randomBytes(4).toString("hex"),
|
|
332
333
|
},
|
|
@@ -422,12 +423,16 @@ var removeDmFavorite = preferences.removeDmFavorite;
|
|
|
422
423
|
var getDmHidden = preferences.getDmHidden;
|
|
423
424
|
var addDmHidden = preferences.addDmHidden;
|
|
424
425
|
var removeDmHidden = preferences.removeDmHidden;
|
|
425
|
-
var
|
|
426
|
-
var
|
|
426
|
+
var getChatWidth = preferences.getChatWidth;
|
|
427
|
+
var setChatWidth = preferences.setChatWidth;
|
|
428
|
+
var getSessionListAvatars = preferences.getSessionListAvatars;
|
|
429
|
+
var setSessionListAvatars = preferences.setSessionListAvatars;
|
|
430
|
+
var migrateAllChatLayouts = preferences.migrateAllChatLayouts;
|
|
427
431
|
var getThemeMode = preferences.getThemeMode;
|
|
428
432
|
var setThemeMode = preferences.setThemeMode;
|
|
429
|
-
var
|
|
430
|
-
var
|
|
433
|
+
var getThemeId = preferences.getThemeId;
|
|
434
|
+
var setThemeId = preferences.setThemeId;
|
|
435
|
+
var migrateAllThemePrefs = preferences.migrateAllThemePrefs;
|
|
431
436
|
var getAutoContinue = preferences.getAutoContinue;
|
|
432
437
|
var setAutoContinue = preferences.setAutoContinue;
|
|
433
438
|
var getToolPalettes = preferences.getToolPalettes;
|
|
@@ -477,12 +482,16 @@ module.exports = {
|
|
|
477
482
|
getDmHidden: getDmHidden,
|
|
478
483
|
addDmHidden: addDmHidden,
|
|
479
484
|
removeDmHidden: removeDmHidden,
|
|
480
|
-
|
|
481
|
-
|
|
485
|
+
getChatWidth: getChatWidth,
|
|
486
|
+
setChatWidth: setChatWidth,
|
|
487
|
+
getSessionListAvatars: getSessionListAvatars,
|
|
488
|
+
setSessionListAvatars: setSessionListAvatars,
|
|
489
|
+
migrateAllChatLayouts: migrateAllChatLayouts,
|
|
482
490
|
getThemeMode: getThemeMode,
|
|
483
491
|
setThemeMode: setThemeMode,
|
|
484
|
-
|
|
485
|
-
|
|
492
|
+
getThemeId: getThemeId,
|
|
493
|
+
setThemeId: setThemeId,
|
|
494
|
+
migrateAllThemePrefs: migrateAllThemePrefs,
|
|
486
495
|
getAutoContinue: getAutoContinue,
|
|
487
496
|
setAutoContinue: setAutoContinue,
|
|
488
497
|
getToolPalettes: getToolPalettes,
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// vendor-catalog.js - what each agent vendor says it offers, kept as it was
|
|
2
|
+
// reported: the models it lists and the built-in helpers it ships, each entry
|
|
3
|
+
// tagged with the vendor that reported it.
|
|
4
|
+
//
|
|
5
|
+
// Nothing here names a model, a helper or a vendor. A vendor adapter calls
|
|
6
|
+
// report(vendor, {models, helpers}) with what its own listing call returned, so
|
|
7
|
+
// a model or helper a vendor newly reports is in the catalog and in every
|
|
8
|
+
// reader of it with no code change. A listing call that failed reports nothing:
|
|
9
|
+
// the catalog keeps what that vendor last reported (empty if it never did), and
|
|
10
|
+
// no built-in table is merged in to cover the gap.
|
|
11
|
+
//
|
|
12
|
+
// Readers: the Team view roster classifies identities with classify() (via
|
|
13
|
+
// lib/agent-roster.js), the browser receives snapshot() with the roster, and the
|
|
14
|
+
// model-family list is derived from the Claude alias entries (lib/model-families.js).
|
|
15
|
+
|
|
16
|
+
// models: [{value, displayName?, resolvedModel?}] a vendor's model list
|
|
17
|
+
// helpers: [{name, description?}] a vendor's built-in helper types
|
|
18
|
+
function cleanModels(list) {
|
|
19
|
+
var out = [];
|
|
20
|
+
var seen = Object.create(null);
|
|
21
|
+
(Array.isArray(list) ? list : []).forEach(function (m) {
|
|
22
|
+
var entry = typeof m === "string" ? { value: m } : m;
|
|
23
|
+
if (!entry || typeof entry.value !== "string" || !entry.value || seen[entry.value]) return;
|
|
24
|
+
seen[entry.value] = true;
|
|
25
|
+
var clean = { value: entry.value };
|
|
26
|
+
if (typeof entry.displayName === "string" && entry.displayName) clean.displayName = entry.displayName;
|
|
27
|
+
if (typeof entry.resolvedModel === "string" && entry.resolvedModel) clean.resolvedModel = entry.resolvedModel;
|
|
28
|
+
out.push(clean);
|
|
29
|
+
});
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function cleanHelpers(list) {
|
|
34
|
+
var out = [];
|
|
35
|
+
var seen = Object.create(null);
|
|
36
|
+
(Array.isArray(list) ? list : []).forEach(function (h) {
|
|
37
|
+
var entry = typeof h === "string" ? { name: h } : h;
|
|
38
|
+
if (!entry || typeof entry.name !== "string" || !entry.name || seen[entry.name]) return;
|
|
39
|
+
seen[entry.name] = true;
|
|
40
|
+
var clean = { name: entry.name };
|
|
41
|
+
if (typeof entry.description === "string" && entry.description) clean.description = entry.description;
|
|
42
|
+
out.push(clean);
|
|
43
|
+
});
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createVendorCatalog() {
|
|
48
|
+
// vendor id -> {models, helpers}. Insertion order is report order.
|
|
49
|
+
var vendors = new Map();
|
|
50
|
+
var listeners = [];
|
|
51
|
+
|
|
52
|
+
function notify() {
|
|
53
|
+
listeners.slice().forEach(function (fn) {
|
|
54
|
+
try { fn(); }
|
|
55
|
+
catch (e) { console.error("[vendor-catalog] change hook failed:", e && e.message ? e.message : e); }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Replaces what a vendor reported for each part given (models and/or
|
|
60
|
+
// helpers); a part left out is untouched. Returns true when the catalog changed.
|
|
61
|
+
function report(vendor, parts) {
|
|
62
|
+
if (typeof vendor !== "string" || !vendor || !parts || typeof parts !== "object") return false;
|
|
63
|
+
var held = vendors.get(vendor) || { models: [], helpers: [] };
|
|
64
|
+
var next = { models: held.models, helpers: held.helpers };
|
|
65
|
+
if (Array.isArray(parts.models)) next.models = cleanModels(parts.models);
|
|
66
|
+
if (Array.isArray(parts.helpers)) next.helpers = cleanHelpers(parts.helpers);
|
|
67
|
+
var changed = !vendors.has(vendor) || JSON.stringify(next) !== JSON.stringify(held);
|
|
68
|
+
if (!changed) return false;
|
|
69
|
+
vendors.set(vendor, next);
|
|
70
|
+
notify();
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// The reported data, copied: [{vendor, models, helpers}].
|
|
75
|
+
function snapshot() {
|
|
76
|
+
var out = [];
|
|
77
|
+
vendors.forEach(function (held, vendor) {
|
|
78
|
+
out.push({
|
|
79
|
+
vendor: vendor,
|
|
80
|
+
models: held.models.map(function (m) { return Object.assign({}, m); }),
|
|
81
|
+
helpers: held.helpers.map(function (h) { return Object.assign({}, h); }),
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The model entries one vendor reported (copies), [] when it reported none.
|
|
88
|
+
function modelsOf(vendor) {
|
|
89
|
+
var held = vendors.get(vendor);
|
|
90
|
+
return held ? held.models.map(function (m) { return Object.assign({}, m); }) : [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// What a roster identity is, by the vendor listings alone:
|
|
94
|
+
// {group: "model", vendor} its key is a reported model value or resolved model
|
|
95
|
+
// {group: "helper", vendor} isSubagent and its key is a reported helper name
|
|
96
|
+
// null the catalog does not know it (a named agent)
|
|
97
|
+
// A model match wins over a helper match; the first vendor that reported the
|
|
98
|
+
// key is the one named, so the vendor is the one whose list held it.
|
|
99
|
+
function classify(key, isSubagent) {
|
|
100
|
+
if (typeof key !== "string" || !key) return null;
|
|
101
|
+
var found = null;
|
|
102
|
+
vendors.forEach(function (held, vendor) {
|
|
103
|
+
if (found && found.group === "model") return;
|
|
104
|
+
for (var i = 0; i < held.models.length; i++) {
|
|
105
|
+
if (held.models[i].value === key || held.models[i].resolvedModel === key) {
|
|
106
|
+
found = { group: "model", vendor: vendor };
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (found || !isSubagent) return;
|
|
111
|
+
for (var j = 0; j < held.helpers.length; j++) {
|
|
112
|
+
if (held.helpers[j].name === key) { found = { group: "helper", vendor: vendor }; return; }
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return found;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Calls fn after every change. Returns a function that stops it.
|
|
119
|
+
function subscribe(fn) {
|
|
120
|
+
listeners.push(fn);
|
|
121
|
+
return function () { listeners = listeners.filter(function (f) { return f !== fn; }); };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { report: report, snapshot: snapshot, modelsOf: modelsOf, classify: classify, subscribe: subscribe };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// The daemon's catalog: vendor adapters report into it, the server reads it.
|
|
128
|
+
var defaultCatalog = createVendorCatalog();
|
|
129
|
+
|
|
130
|
+
module.exports = { createVendorCatalog: createVendorCatalog, defaultCatalog: defaultCatalog };
|