codex-copilot-dx 1.2.25 → 1.2.27

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.
@@ -0,0 +1,194 @@
1
+ (() => {
2
+ function create({ element: el, api, applied, refreshAnimation, selectAnimation, time }) {
3
+ const label = (id, key, values) => globalThis.ccdxLanguage.set(el(id), key, values);
4
+ const theme = () => globalThis.ccdxDashboardTheme;
5
+ const backupKey = "ccdx.dashboard.preferences-backup";
6
+ const fields = { terminal_color_theme: "terminal-color-theme", terminal_animation_enabled: "setting-terminal_animation_enabled",
7
+ open_webui: "setting-open_webui", nightly_updates: "nightly-update" };
8
+ let base, draft = {}, appearance, appearanceBase, pending, timer, error = null, conflict = false, version = 0, dialog, dialogRevision, resetting = false, retrying = false, locks = {}, terminalMode;
9
+ const dirty = () => Object.keys(draft).length + (appearance ? 1 : 0);
10
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
11
+ const active = () => !el("settings-preferences").closest("[hidden]");
12
+ function browserBackup() {
13
+ const raw = localStorage.getItem(backupKey);if (raw === null) return { version: 1, entries: [] };
14
+ const value = JSON.parse(raw);
15
+ if (value?.version !== 1 || !Array.isArray(value.entries) || value.entries.length > 2 || value.entries.some(entry => typeof entry.id !== "string"
16
+ || !["dark", "light"].includes(entry.values?.theme) || !["green", "klein", "pink"].includes(entry.values?.palette))) throw Error("preferences_browser_backup_invalid");
17
+ return value;
18
+ }
19
+ function render() {
20
+ el("preferences-status").hidden = !active();
21
+ if (!base) return;
22
+ const current = { ...base.values, ...draft }, count = dirty(), busy = Boolean(pending || retrying);
23
+ el("preferences-auto").checked = current.auto_save_settings;el("preferences-auto").disabled = busy || conflict;
24
+ for (const [key, id] of Object.entries(fields)) {
25
+ const node = el(id);if (node.type === "checkbox") node.checked = current[key];else node.value = current[key];
26
+ node.disabled = Boolean(locks[key] || resetting);
27
+ }
28
+ el("web-color-theme").disabled = resetting;
29
+ for (const row of document.querySelectorAll("#animation-options [data-theme]")) row.disabled = resetting;
30
+ el("terminal-color-sample").dataset.terminalPalette = current.terminal_color_theme;
31
+ el("animation-settings").dataset.terminalPalette = current.terminal_color_theme;
32
+ el("preferences-reset").disabled = busy;el("preferences-restore").disabled = busy;
33
+ el("preferences-backup").hidden = !base.backup;
34
+ el("preferences-backup-time").textContent = base.backup ? time(base.backup.created_at, { date: true }) : "";
35
+ el("preferences-manual").hidden = current.auto_save_settings && !conflict;
36
+ el("preferences-save").disabled = !count || busy || conflict;el("preferences-discard").disabled = (!count && !conflict) || busy;
37
+ label("preferences-manual-note", conflict ? "preferences_conflict" : count ? "preferences_unsaved" : "preferences_manual", { count });
38
+ globalThis.ccdxIcons.set(el("preferences-status"), busy ? "saving" : error ? "preferences_failed" : count ? "preferences_unsaved" : "preferences_saved",
39
+ error ? "warning" : busy || count ? "unknown" : "ok", { count });
40
+ el("preferences-retry").hidden = !error || conflict || busy;
41
+ el("preferences-error").parentElement.hidden = !error;
42
+ if (!error) el("preferences-error").textContent = "";
43
+ else label("preferences-error", error);
44
+ el("save-animation").hidden = true;
45
+ if (appearance) theme()?.preview(appearance);
46
+ if (appearance) label("web-color-note", "preferences_appearance_preview");
47
+ else theme()?.sync();
48
+ label("terminal-color-note", Object.hasOwn(draft, "terminal_color_theme") ? "preferences_terminal_preview"
49
+ : terminalMode === "status" ? "terminal_theme_applied" : "terminal_theme_unavailable");
50
+ if (draft.terminal_animation) {
51
+ for (const row of document.querySelectorAll("#animation-options [data-theme]")) row.setAttribute("aria-pressed", String(row.dataset.theme === draft.terminal_animation));
52
+ }
53
+ selectAnimation(current.terminal_animation);
54
+ }
55
+ function sync(data, { readVersion } = {}) {
56
+ if (!data.preferences) return;
57
+ terminalMode = data.terminal?.mode;
58
+ if (readVersion !== undefined && readVersion !== version || pending) { render();return; }
59
+ const next = data.preferences;
60
+ locks.terminal_animation_enabled = data.effective?.terminal_animation_enabled?.locked;
61
+ if (base) for (const key of Object.keys(draft)) {
62
+ if (next.values[key] === draft[key]) delete draft[key];
63
+ else if (next.values[key] !== base.values[key]) { conflict = true;error = "preferences_changed"; }
64
+ }
65
+ base = next;
66
+ if (!appearance) { try { appearanceBase = theme()?.read(); } catch { appearanceBase = theme()?.snapshot(); } }
67
+ try {
68
+ const backup = browserBackup(), retained = backup.entries.filter(entry => entry.id === base.backup?.id);
69
+ if (retained.length && backup.entries.length > 1) localStorage.setItem(backupKey, JSON.stringify({ version: 1, entries: retained }));
70
+ } catch { /* A damaged browser backup is reported if it is used, not erased. */ }
71
+ render();
72
+ }
73
+ function schedule() {
74
+ clearTimeout(timer);
75
+ if (base?.values.auto_save_settings && !error) timer = setTimeout(() => { void save(); }, 300);
76
+ }
77
+ function edit(key, value) {
78
+ if (!base) return;
79
+ if (value === base.values[key]) delete draft[key];else draft[key] = value;
80
+ if (!conflict) error = null;render();schedule();
81
+ }
82
+ async function commit(values, { local = appearance, action = "preferences", backup_id, revision = base?.revision } = {}) {
83
+ if (pending || !base || conflict) return;
84
+ clearTimeout(timer);
85
+ const captured = { ...values }, capturedLocal = local ? { ...local } : null;
86
+ resetting = action !== "preferences";
87
+ error = null;
88
+ const operation = (async () => {
89
+ try {
90
+ if (capturedLocal && appearanceBase && !same(theme().read(), appearanceBase)) throw Error("preferences_browser_changed");
91
+ const data = action !== "preferences" || Object.keys(captured).length
92
+ ? await api({ action, revision, ...(action === "preferences" ? { values: captured } : { backup_id }) }) : null;
93
+ if (data) { base = data.preferences;version++; }
94
+ for (const [key, value] of Object.entries(captured)) if (draft[key] === value) delete draft[key];
95
+ if (capturedLocal) {
96
+ if (!theme().persist(capturedLocal)) throw Error("preferences_browser_failed");
97
+ appearanceBase = capturedLocal;
98
+ if (same(appearance, capturedLocal)) appearance = null;
99
+ }
100
+ if (data) applied(data);
101
+ if (Object.hasOwn(captured, "terminal_animation") || action !== "preferences") refreshAnimation();
102
+ return data || { preferences: base };
103
+ } catch (cause) {
104
+ error = cause.code === "ccdx_settings_changed" ? "preferences_changed"
105
+ : ["preferences_browser_failed", "preferences_browser_changed"].includes(cause.message) ? cause.message : "preferences_failed";
106
+ conflict = error === "preferences_changed" || error === "preferences_browser_changed";
107
+ }
108
+ })();
109
+ pending = operation;render();
110
+ try { return await operation; }
111
+ finally { pending = null;resetting = false;render();if (!error && dirty() && base.values.auto_save_settings) schedule(); }
112
+ }
113
+ function save() { if (dirty()) return commit(draft); }
114
+ async function discard() {
115
+ clearTimeout(timer);if (pending) return;
116
+ try {
117
+ const data = await api();draft = {};appearance = null;error = null;conflict = false;
118
+ appearanceBase = theme().read();theme().preview(appearanceBase);base = data.preferences;version++;applied(data);refreshAnimation();render();
119
+ } catch { error = "preferences_failed";render(); }
120
+ }
121
+ function open(kind) {
122
+ if (!base || pending) return;
123
+ dialog = kind;dialogRevision = base.revision;
124
+ label("preferences-dialog-title", `preferences_${kind}_question`);
125
+ label("preferences-dialog-intro", `preferences_${kind}_intro`, { count: dirty() });
126
+ label("preferences-dialog-confirm", `preferences_${kind}_confirm`);
127
+ el("preferences-dialog-scope").hidden = !["reset", "restore"].includes(kind);
128
+ if (kind === "reset") label("preferences-dialog-note", dirty() ? "preferences_draft_discard" : "preferences_backup_latest");
129
+ else { el("preferences-dialog-note").textContent = "";el("preferences-dialog-note").removeAttribute("data-i18n"); }
130
+ el("preferences-dialog").showModal();
131
+ }
132
+ async function confirmed() {
133
+ const kind = dialog;el("preferences-dialog").close();
134
+ if (kind === "enable") { draft.auto_save_settings = true;await save();return; }
135
+ if (kind === "nightly") { edit("nightly_updates", true);return; }
136
+ if (kind === "restore" || kind === "reset") {
137
+ let local, id = base.backup?.id;
138
+ try {
139
+ const backup = browserBackup();
140
+ if (kind === "reset") {
141
+ id = crypto.randomUUID();local = { theme: "dark", palette: "green" };
142
+ const previous = { id, values: theme().read() };
143
+ localStorage.setItem(backupKey, JSON.stringify({ version: 1, entries: [previous, ...backup.entries].slice(0, 2) }));
144
+ } else {
145
+ local = backup.entries.find(entry => entry.id === id)?.values;
146
+ if (!local) throw Error("preferences_browser_backup_missing");
147
+ }
148
+ } catch (cause) { error = cause.message === "preferences_browser_backup_missing" ? cause.message : "preferences_browser_backup_invalid";render();return; }
149
+ if (conflict) { error = "preferences_changed";render();return; }
150
+ const oldDraft = draft, oldAppearance = appearance;
151
+ draft = {};appearance = local;
152
+ const data = await commit({}, { action: `${kind === "reset" ? "reset" : "restore"}_preferences`, backup_id: id, local, revision: dialogRevision });
153
+ if (data) { theme().preview(local);appearance = null; }
154
+ else if (error === "preferences_browser_failed") appearance = local;
155
+ else { draft = oldDraft;appearance = oldAppearance; }
156
+ render();
157
+ }
158
+ }
159
+ for (const [key, id] of Object.entries(fields)) el(id).addEventListener("change", () => {
160
+ const node = el(id), value = node.type === "checkbox" ? node.checked : node.value;
161
+ if (key === "nightly_updates" && value) { node.checked = false;open("nightly");return; }
162
+ edit(key, value);
163
+ });
164
+ function appearanceChanged() {
165
+ if (!base) return false;
166
+ appearance = same(theme().snapshot(), appearanceBase) ? null : theme().snapshot();
167
+ if (!conflict) error = null;render();schedule();return true;
168
+ }
169
+ el("preferences-auto").addEventListener("change", async () => {
170
+ if (el("preferences-auto").checked && dirty()) { el("preferences-auto").checked = false;open("enable");return; }
171
+ const value = el("preferences-auto").checked;
172
+ draft.auto_save_settings = value;
173
+ const result = await commit({ auto_save_settings: value }, { local: null });
174
+ if (!result) { delete draft.auto_save_settings;render(); }
175
+ });
176
+ el("preferences-save").addEventListener("click", () => { void save(); });
177
+ el("preferences-discard").addEventListener("click", () => { void discard(); });
178
+ el("preferences-retry").addEventListener("click", async () => {
179
+ if (retrying || pending) return;
180
+ const wasError = error;error = null;
181
+ retrying = true;render();
182
+ try { sync(await api());retrying = false;if (!conflict) await save(); } catch { error = wasError; }
183
+ finally { retrying = false;render(); }
184
+ });
185
+ el("preferences-reset").addEventListener("click", () => open("reset"));el("preferences-restore").addEventListener("click", () => open("restore"));
186
+ el("preferences-dialog-cancel").addEventListener("click", () => el("preferences-dialog").close());
187
+ el("preferences-dialog-confirm").addEventListener("click", () => { void confirmed(); });
188
+ globalThis.addEventListener("beforeunload", event => { if (dirty()) { event.preventDefault();event.returnValue = ""; } });
189
+ return { sync, render, appearanceChanged, selectAnimation: value => edit("terminal_animation", value),
190
+ externalAppearance() { if (!appearance) return false;conflict = true;error = "preferences_browser_changed";render();return true; },
191
+ get version() { return version; }, get busy() { return Boolean(pending || retrying); } };
192
+ }
193
+ globalThis.ccdxDashboardPreferences = { create };
194
+ })();
@@ -1,5 +1,8 @@
1
1
  (() => {
2
2
  function create({ time, element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator }) {
3
+ const visible = node => !node?.closest?.('[data-view]')?.hidden;
4
+ const writeText = text;
5
+ text = (id, ...args) => { if (visible(element(id))) writeText(id, ...args); };
3
6
  let contextRequests = [];
4
7
  let contextCompactions = {};
5
8
  let failureSignature;
@@ -87,6 +90,7 @@
87
90
  }
88
91
 
89
92
  function renderFailures(recent, recentRequests = []) {
93
+ if (!visible(element("failures"))) return;
90
94
  const signature = JSON.stringify([element("failure-kind")?.value, recent, recentRequests]);
91
95
  if (signature === failureSignature) return;
92
96
  failureSignature = signature;
@@ -200,6 +204,14 @@
200
204
  }
201
205
 
202
206
  function render(data) {
207
+ if (data.scope === "summary") {
208
+ globalThis.ccdxDashboardActivity?.update(data.model_activity);
209
+ text("version", `v${data.version || "?"}`);
210
+ text("uptime", "pid_pid_uptime_duration", { pid: number(data.pid), duration: duration(data.uptime_ms) });
211
+ renderRuntimeUsage(data);
212
+ text("updated", "snapshot_time", { time: time(Date.now()) });
213
+ return;
214
+ }
203
215
  for (const source of data.providers?.connections?.providers || []) sourceNames.set(source.id, source.name);
204
216
  globalThis.ccdxConnections?.updateMemory?.(data.providers?.connections);
205
217
  globalThis.ccdxDashboardActivity?.update(data.model_activity);
@@ -237,7 +249,7 @@
237
249
  const used = Number(history.bytes || 0);
238
250
  text("history", `${mib(used)} / ${mib(limit)}`);
239
251
  text("history-detail", "entries_entries_trees_trees_misses_misses_evicted_evicted", { entries: number(history.entries), trees: number(history.tree_count), misses: number(history.lookup_misses), evicted: number(history.evicted_lookup_misses) });
240
- element("history-meter").value = limit > 0 ? Math.min(100, Math.max(0, used / limit * 100)) : 0;
252
+ if (visible(element("history-meter"))) element("history-meter").value = limit > 0 ? Math.min(100, Math.max(0, used / limit * 100)) : 0;
241
253
 
242
254
  const image = data.image_generation;
243
255
  text("image", image ? "count_succeeded" : "not_initialized", { count: number(image?.succeeded) });
@@ -248,7 +260,7 @@
248
260
  const claude = data.providers?.claude || data.providers?.m365?.claude, claudeMetrics = claude?.requests?.performance;
249
261
  percentiles("claude-ttft-percentiles", claudeMetrics?.by_route?.messages?.ttft_ms);
250
262
  const sourceBody = element("source-requests-body");
251
- if (sourceBody) {
263
+ if (sourceBody && visible(sourceBody)) {
252
264
  sourceBody.replaceChildren();
253
265
  const routes = { ...data.stream_performance?.by_route, ...claudeMetrics?.by_route };
254
266
  for (const [protocol, route] of Object.entries(routes)) for (const [source, stats] of Object.entries(route.by_provider || {})) {
@@ -269,7 +281,7 @@
269
281
  const kind = element("failure-kind")?.value || "issues";
270
282
  renderFailures(issueGroups[kind] || [], kind === "issues" ? recentRequests : []);
271
283
  renderContext({ ...data.stream_performance, recent_requests: recentRequests });
272
- if (element("claude-route")) {
284
+ if (element("claude-route") && visible(element("claude-route"))) {
273
285
  element("claude-route").textContent = claude?.base_url || "—";
274
286
  const clientState = value => ({ configured: "configured", restored: "settings_restored", preserved: "existing_settings_kept", partially_preserved: "existing_settings_kept",
275
287
  not_installed: "not_installed", configuration_unavailable: "setup_unavailable" })[value] || "unknown";
@@ -280,27 +292,32 @@
280
292
  text(id, metric?.samples > 0 ? `${Number(metric.avg).toFixed(1)} ${unit} / ${metric.samples}` : "—");
281
293
  }
282
294
  }
283
- if (element("runtime-usage")) {
295
+ renderRuntimeUsage(data);
296
+ if (element("prediction-preference") && visible(element("prediction-preference"))) {
297
+ const prediction = data.client_integrations?.prediction;
298
+ text("prediction-preference", prediction ? prediction.configured ? "configured" : "not_configured" : "unknown");
299
+ text("prediction-bridge", ({ running: "running_f4cca", recovering: "recovering", stopped: "stopped", unavailable: "unavailable_ca184" })[prediction?.bridge] || "unknown");
300
+ text("prediction-route", prediction?.client_route === "observed" ? "observed" : "unknown");
301
+ text("prediction-candidate", "unknown");
302
+ const note = element("prediction-note");
303
+ if (note) note.textContent = prediction?.reason || "";
304
+ }
305
+ text("updated", "snapshot_time", { time: time(Date.now()) });
306
+ }
307
+ function renderRuntimeUsage(data) {
308
+ if (element("runtime-usage") && visible(element("runtime-usage"))) {
284
309
  const usage = data.runtime_usage;
285
310
  text("runtime-usage", usage ? "records_usage_records_input_input_cache_read_cached_output_outpu" : "—",
286
311
  usage ? { records: number(usage.records), input: number(usage.input_tokens), cached: number(usage.cached_input_tokens), output: number(usage.output_tokens), partial: usage.partial_records ? " ~" : "" } : {});
287
312
  const rate = usage?.cache_hit_rate;
288
313
  text("runtime-cache-hit", Number.isFinite(rate) && rate >= 0 && rate <= 1 ? `${usage.cache_hit_rate_partial ? "~" : ""}${(rate * 100).toFixed(1)}%` : "—");
314
+ }
315
+ if (element("process-state") && visible(element("process-state"))) {
289
316
  element("process-state").textContent = `PID ${data.pid || "—"} / ${globalThis.location?.origin || ""}`;
290
317
  text("process-memory", "rss_rss_heap_heap", { rss: mib(data.process?.rss_bytes), heap: mib(data.process?.heap_used_bytes) });
291
318
  text("process-queues", "codex_body_admission_active_active_queued_queued_queue_limit_lim", {
292
319
  active: number(data.admission?.activeRequests), queued: number(data.admission?.queued), limit: number(data.admission?.maxQueued) });
293
320
  }
294
- if (element("prediction-preference")) {
295
- const prediction = data.client_integrations?.prediction;
296
- text("prediction-preference", prediction ? prediction.configured ? "configured" : "not_configured" : "unknown");
297
- text("prediction-bridge", ({ running: "running_f4cca", recovering: "recovering", stopped: "stopped", unavailable: "unavailable_ca184" })[prediction?.bridge] || "unknown");
298
- text("prediction-route", prediction?.client_route === "observed" ? "observed" : "unknown");
299
- text("prediction-candidate", "unknown");
300
- const note = element("prediction-note");
301
- if (note) note.textContent = prediction?.reason || "";
302
- }
303
- text("updated", "snapshot_time", { time: time(Date.now()) });
304
321
  }
305
322
 
306
323
  function renderContext(performance) {
@@ -309,7 +326,7 @@
309
326
  contextCompactions = performance?.by_route?.responses_compact?.terminal_outcomes?.totals || {};
310
327
  }
311
328
  const body = element("context-body");
312
- if (!body) return;
329
+ if (!body || !visible(body)) return;
313
330
  text("context-note", "20_latest_finished_requests_compactions_completed_completed_inco", {
314
331
  completed: number(contextCompactions.completed), incomplete: number(contextCompactions.incomplete), failed: number(contextCompactions.failed),
315
332
  });
@@ -24,10 +24,11 @@
24
24
  document.getElementById("favicon").href = `data:image/svg+xml,${encodeURIComponent(svg)}`;
25
25
  };
26
26
  applyTheme();
27
- function persist() {
28
- try { localStorage.setItem(key, theme);localStorage.setItem(paletteKey, palette);saved = true; }
27
+ function persist(values = { theme, palette }) {
28
+ try { localStorage.setItem(key, values.theme);localStorage.setItem(paletteKey, values.palette);saved = true; }
29
29
  catch { saved = false; }
30
30
  sync();
31
+ return saved;
31
32
  }
32
33
  document.addEventListener("DOMContentLoaded", () => {
33
34
  const button = document.getElementById("theme-toggle");
@@ -47,10 +48,16 @@
47
48
  document.getElementById("web-color-theme")?.addEventListener("change", event => {
48
49
  if (!valid(event.target.value)) return;
49
50
  palette = event.target.value;applyTheme();
50
- persist();
51
+ if (!globalThis.ccdxSettingsPreferences?.appearanceChanged()) persist();
51
52
  });
53
+ globalThis.ccdxDashboardTheme = {
54
+ snapshot: () => ({ theme, palette }), persist, sync,
55
+ read: () => ({ theme: localStorage.getItem(key) === "light" ? "light" : "dark", palette: valid(localStorage.getItem(paletteKey)) ? localStorage.getItem(paletteKey) : "green" }),
56
+ preview(values) { if (["light", "dark"].includes(values.theme)) theme = values.theme;if (valid(values.palette)) palette = values.palette;applyTheme();updateLabel();sync(); },
57
+ };
52
58
  globalThis.addEventListener?.("storage", event => {
53
59
  if (event.key !== paletteKey && event.key !== key) return;
60
+ if (globalThis.ccdxSettingsPreferences?.externalAppearance()) return;
54
61
  if (event.key === paletteKey) palette = valid(event.newValue) ? event.newValue : "green";
55
62
  else theme = event.newValue === "light" ? "light" : "dark";
56
63
  applyTheme();updateLabel();sync();
@@ -553,3 +553,22 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
553
553
  .memory-model-value .hint { margin:0; }
554
554
  .memory-model-value { min-width:0;max-width:100%; }
555
555
  .memory-model-value strong { min-width:0;overflow-wrap:anywhere; }
556
+
557
+ /* Settings-page preferences keep their own draft, save and recovery controls. */
558
+ .preferences-status { color:var(--muted); font-size:11px; }
559
+ .preferences-row { display:flex; align-items:center; justify-content:space-between; gap:20px; padding:20px 0; font-size:13px; }
560
+ .preferences-row:last-of-type { padding-bottom:0; }
561
+ .preferences-row .hint { margin-top:5px; }
562
+ .preferences-row input[role="switch"] { flex:none; }
563
+ .preferences-separator { border-top:1px solid var(--border); margin-top:14px; }
564
+ #preferences-backup-time { margin-bottom:0; }
565
+ #preferences-error { margin:0; color:var(--failed); }
566
+ #preferences-save, #preferences-dialog-confirm { background:var(--accent); color:var(--page); border-color:var(--accent); }
567
+ .preferences-dialog { width:480px; max-width:calc(100% - 32px); padding:25px; border:1px solid var(--border); border-radius:2px; background:var(--surface); color:var(--text); font:inherit; }
568
+ .preferences-dialog::backdrop { background:#0007; }
569
+ .preferences-dialog h2 { font-size:19px; margin:0 0 18px; color:var(--strong); }
570
+ .preferences-dialog p, .preferences-dialog dl { font-size:12px; line-height:1.8; }
571
+ .preferences-dialog dl > div { display:grid; grid-template-columns:80px minmax(0,1fr); gap:12px; margin-top:12px; }
572
+ .preferences-dialog dt { color:var(--muted); }.preferences-dialog dd { margin:0; }
573
+ .preferences-dialog .section-actions { justify-content:flex-end; margin-top:24px; }
574
+ @media(max-width:640px) { .preferences-row { gap:14px; flex-wrap:wrap; }.preferences-row > div:first-child { flex:1; min-width:150px; }.preferences-dialog { padding:20px; }.preferences-dialog dl > div { grid-template-columns:1fr; gap:3px; } }
@@ -23,7 +23,9 @@ const usageView = globalThis.ccdxViewBoundary.create("usage-analytics", () => gl
23
23
  const { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay } = usageView;
24
24
  const loadAuth = () => dashboardRefresh.refresh("auth", { force: true });
25
25
 
26
- const refresh = () => dashboardRefresh.refresh("status", { force: true });
26
+ const statusResourceKey = () => ["codex", "claude", "models", "usage", "requests", "checks"].includes((globalThis.location?.hash || "").slice(1)) ? "status" : "status-summary";
27
+ const refreshStatus = () => dashboardRefresh.refresh(statusResourceKey(), { force: true });
28
+ const refresh = refreshStatus;
27
29
 
28
30
  function animateRefresh() {
29
31
  const icon = element("status-icon");
@@ -39,7 +41,7 @@ element("refresh").addEventListener("click", () => {
39
41
 
40
42
  const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
41
43
  const animationView = globalThis.ccdxViewBoundary.create("animation-settings", () => globalThis.ccdxDashboardAnimation.create({ element, phrase, localize, text, reducedMotion,
42
- getRefresh: () => dashboardRefresh, document }), ["apply", "load", "save", "sync", "stop"]);
44
+ getRefresh: () => dashboardRefresh, document }), ["apply", "load", "save", "sync", "stop", "select"]);
43
45
  const { apply: applyAnimation, load: loadAnimation, save: saveAnimation, sync: syncAnimationPreview, stop: stopAnimationPreview } = animationView;
44
46
  reducedMotion.addEventListener("change", () => { if (reducedMotion.matches) usageView.stopMotion(); });
45
47
  document.addEventListener("visibilitychange", () => { if (document.visibilityState !== "visible") usageView.stopMotion(); });
@@ -234,6 +236,16 @@ for (const [key, ids] of [["auth", ["account-authorization", "client-features",
234
236
  }
235
237
 
236
238
  const updateView = globalThis.ccdxDashboardUpdates.create(viewHelpers);
239
+ function statusState(state) {
240
+ if (state.error || !state.value) globalThis.ccdxDashboardActivity?.unavailable();
241
+ if ((state.error || !state.value) && statusResourceKey() === "status") globalThis.ccdxDashboardFlow?.unavailable();
242
+ text("connection", state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable");
243
+ element("connection").className = `badge ${state.pending ? "neutral" : state.error ? "bad" : "good"}`;
244
+ globalThis.ccdxIcons?.set(element("connection"), state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable",
245
+ state.pending && !state.value ? "unknown" : state.error ? "unavailable" : "running");
246
+ if (state.error) refreshTime(element("updated"), state);
247
+ for (const node of timestamps.get("status")) refreshTime(node, state);
248
+ }
237
249
  const dashboardRefresh = globalThis.ccdxRefresh.createController({
238
250
  visible: () => document.visibilityState === "visible",
239
251
  onState: ({ pendingKeys }) => {
@@ -250,23 +262,24 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
250
262
  state: updateView.state,
251
263
  },
252
264
  status: {
253
- visible: () => true,
265
+ visible: () => statusResourceKey() === "status",
254
266
  load: async ({ signal }) => {
255
267
  const data = await readDashboard("/_ccdx/status", { signal, timeout: 5000 });
256
268
  if (data.ok !== true || data.name !== "codex-copilot-dx") throw new Error("Unexpected status response");
257
269
  return data;
258
270
  },
259
- apply: render,
260
- state: state => {
261
- if (state.error || !state.value) globalThis.ccdxDashboardActivity?.unavailable();
262
- if (state.error || !state.value) globalThis.ccdxDashboardFlow?.unavailable();
263
- text("connection", state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable");
264
- element("connection").className = `badge ${state.pending ? "neutral" : state.error ? "bad" : "good"}`;
265
- globalThis.ccdxIcons?.set(element("connection"), state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable",
266
- state.pending && !state.value ? "unknown" : state.error ? "unavailable" : "running");
267
- if (state.error) refreshTime(element("updated"), state);
268
- for (const node of timestamps.get("status")) refreshTime(node, state);
271
+ apply: data => { if (statusResourceKey() === "status") render(data); },
272
+ state: state => { if (statusResourceKey() === "status") statusState(state); },
273
+ },
274
+ "status-summary": {
275
+ visible: () => statusResourceKey() === "status-summary",
276
+ load: async ({ signal }) => {
277
+ const data = await readDashboard("/_ccdx/status?scope=summary", { signal, timeout: 5000 });
278
+ if (data.ok !== true || data.name !== "codex-copilot-dx") throw new Error("Unexpected status response");
279
+ return data;
269
280
  },
281
+ apply: data => { if (statusResourceKey() === "status-summary") render(data); },
282
+ state: state => { if (statusResourceKey() === "status-summary") statusState(state); },
270
283
  },
271
284
  auth: {
272
285
  visible: () => true,
@@ -221,7 +221,7 @@ export async function handleDashboardApi(req, res, pathname, {
221
221
  if (!res.destroyed && !res.writableEnded) sendJson(res, 200, data);
222
222
  } catch (error) {
223
223
  sendJson(res, error.statusCode || (error.code?.startsWith("ccdx_cache_") ? 409 : 400), { error: safeText(error.message, 300),
224
- ...(/^m365_[a-z_]+$/.test(error.code || "") ? { code: error.code } : {}) });
224
+ ...(/^(?:m365_[a-z_]+|ccdx_settings_[a-z_]+)$/.test(error.code || "") ? { code: error.code } : {}) });
225
225
  } finally { abort.cleanup(); }
226
226
  return;
227
227
  }
package/src/dashboard.mjs CHANGED
@@ -12,6 +12,7 @@ const ASSETS = new Map([
12
12
  ["/ui.js", ["./dashboard/ui.js", "text/javascript; charset=utf-8"]],
13
13
  ["/console.js", ["./dashboard/console.js", "text/javascript; charset=utf-8"]],
14
14
  ["/updates.js", ["./dashboard/updates.js", "text/javascript; charset=utf-8"]],
15
+ ["/preferences.js", ["./dashboard/preferences.js", "text/javascript; charset=utf-8"]],
15
16
  ["/time.js", ["./dashboard/time.js", "text/javascript; charset=utf-8"]],
16
17
  ["/view-boundary.js", ["./dashboard/view-boundary.js", "text/javascript; charset=utf-8"]],
17
18
  ["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
@@ -3,6 +3,7 @@ import { ADAPTER_CACHE_PATH, cacheRuntimeSnapshot, cleanRuntimeCaches, setHistor
3
3
  import { createRequestAbort, readJsonBody, sendJsonError } from "./http-transport.mjs";
4
4
  import { httpError } from "./http-errors.mjs";
5
5
  import { isLoopbackAddress, isLoopbackHostHeader } from "./security.mjs";
6
+ import { statusSummary } from "./status-summary.mjs";
6
7
 
7
8
  export function isManagementRoute(method, pathname) {
8
9
  return (method === "GET" && [ADAPTER_STATUS_PATH, ADAPTER_HEALTH_PATH].includes(pathname))
@@ -21,7 +22,8 @@ export function createManagementHandler({ statusSnapshot, nativePredictionPac, f
21
22
  return;
22
23
  }
23
24
  res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
24
- res.end(JSON.stringify(statusSnapshot()));
25
+ const snapshot = statusSnapshot();
26
+ res.end(JSON.stringify(new URL(req.url, "http://localhost").searchParams.get("scope") === "summary" ? statusSummary(snapshot) : snapshot));
25
27
  return;
26
28
  }
27
29
 
@@ -1,4 +1,4 @@
1
- export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/time.js", "/animation.js", "/status.js", "/view-boundary.js", "/activity.js", "/flow.js", "/usage.js", "/ui.js", "/console.js", "/updates.js", "/icons.js", "/tools.js", "/connections.js"]);
1
+ export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/time.js", "/animation.js", "/status.js", "/view-boundary.js", "/activity.js", "/flow.js", "/usage.js", "/ui.js", "/console.js", "/updates.js", "/preferences.js", "/icons.js", "/tools.js", "/connections.js"]);
2
2
  export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers", "/_ccdx/ui/settings", "/_ccdx/ui/m365/accounts", "/_ccdx/ui/updates", "/_ccdx/ui/account", "/_ccdx/ui/checks", "/_ccdx/ui/connections"]);
3
3
 
4
4
  export function isOptionalRoute(method, pathname) {
@@ -14,6 +14,7 @@ import { m365NetworkMessage } from "./providers/m365-network-diagnostic.mjs";
14
14
  import { createConnectionRuntime } from "./connection-runtime.mjs";
15
15
  import { accessSettingsPath, readAccessSettings } from "./access-settings.mjs";
16
16
  import { createStreamPerformanceMetrics } from "./stream-performance.mjs";
17
+ import { M365_API_HOST } from "./providers/m365-endpoint.mjs";
17
18
 
18
19
  const unavailable = reason => Object.assign(new Error(`Microsoft 365 is unavailable (${reason}); GitHub routing was not substituted`),
19
20
  { code: reason, statusCode: 503 });
@@ -250,7 +251,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, githubCred
250
251
  if (closed || !enabled || source !== m365 || changingAccount) throw unavailable("m365_refresh_cancelled");
251
252
  reason = null;
252
253
  const eligible = new Set([...source.models("gpt"), ...source.models("claude")]);
253
- return { source: "catalog", checkedAt: m365.snapshot().models.refreshed_at, upstreamHost: "Microsoft 365",
254
+ return { source: "catalog", checkedAt: m365.snapshot().models.refreshed_at, upstreamHost: M365_API_HOST,
254
255
  advertised: m365.catalog().length, models: publicModelCatalog(m365.catalog(), {
255
256
  selectable: model => eligible.has(model),
256
257
  clients: model => !eligible.has(model) ? [] : model.publisher?.toLowerCase() === "anthropic" ? ["claude_code", "claude_app"] : ["codex"],
@@ -0,0 +1,4 @@
1
+ export const M365_API_ORIGIN = "https://loki.delve.office.com";
2
+ export const M365_API_HOST = new URL(M365_API_ORIGIN).hostname;
3
+ export const M365_API_PATH = "/api/v1/llmapi";
4
+ export const M365_API_BASE = `${M365_API_ORIGIN}${M365_API_PATH}`;
@@ -7,16 +7,16 @@ import { createProxyAgent } from "../proxy-tunnel.mjs";
7
7
  import { loadRuntimeConfig } from "../runtime-config.mjs";
8
8
  import { m365HelperEnvironment } from "./m365-auth.mjs";
9
9
  import { m365ProxyFailure } from "./m365-network-diagnostic.mjs";
10
+ import { M365_API_HOST as HOST, M365_API_BASE, M365_API_PATH } from "./m365-endpoint.mjs";
10
11
 
11
- const HOST = "df.loki.delve.office.com";
12
- const targetUrl = new URL(`https://${HOST}/api/v1/llmapi/models`);
12
+ const targetUrl = new URL(`${M365_API_BASE}/models`);
13
13
  const fail = code => Object.assign(new Error(`Microsoft 365 network is unavailable (${code})`), { code: `m365_${code}`, statusCode: 503 });
14
14
 
15
15
  export function requestFetch(requestImpl, agent) {
16
16
  return (raw, init = {}) => new Promise((resolve, reject) => {
17
17
  let url;try { url = new URL(raw); } catch { reject(fail("target_invalid"));return; }
18
18
  if (url.protocol !== "https:" || url.hostname !== HOST || url.port || url.username || url.password || url.hash
19
- || !url.pathname.startsWith("/api/v1/llmapi/") || !["GET", "POST", "HEAD"].includes(init.method || "GET")) { reject(fail("target_invalid"));return; }
19
+ || !url.pathname.startsWith(`${M365_API_PATH}/`) || !["GET", "POST", "HEAD"].includes(init.method || "GET")) { reject(fail("target_invalid"));return; }
20
20
  if (init.signal?.aborted) { reject(init.signal.reason);return; }
21
21
  const headers = Object.fromEntries(new Headers(init.headers));
22
22
  headers["accept-encoding"] = "identity";
@@ -19,7 +19,8 @@ import { createM365ConversationGuard } from "./m365-conversation-accounts.mjs";
19
19
  import { catalogFailure, m365CatalogDiagnostic } from "./m365-catalog-diagnostic.mjs";
20
20
  import { m365NetworkDiagnostic } from "./m365-network-diagnostic.mjs";
21
21
 
22
- export const M365_API_BASE = "https://df.loki.delve.office.com/api/v1/llmapi";
22
+ import { M365_API_BASE, M365_API_ORIGIN } from "./m365-endpoint.mjs";
23
+ export { M365_API_BASE } from "./m365-endpoint.mjs";
23
24
  const SOFT_TTL_MS = 2 * 60 * 60 * 1000;
24
25
  const HARD_TTL_MS = 7 * 24 * 60 * 60 * 1000;
25
26
  const protocolError = (code, message, statusCode = 400) => Object.assign(new Error(message), {
@@ -79,7 +80,7 @@ export function createM365Provider({ home, env = process.env, account: accountOv
79
80
  let networkDiagnostic = null, catalogDiagnostic = null;
80
81
  const registry = { models: null, source: "unavailable", cacheState: "none", cacheSavedAtMs: null,
81
82
  refreshInFlight: false, generation: 0, lastError: null, lastErrorAtMs: null };
82
- const profile = () => account ? `m365:${m365AccountKey(account)}` : "m365:unavailable";
83
+ const profile = () => account ? `m365:${M365_API_ORIGIN}:${m365AccountKey(account)}` : "m365:unavailable";
83
84
  async function transport(signal) {
84
85
  if (network?.healthy()) return network.fetch;
85
86
  if (!networkFlight) {
@@ -103,7 +104,7 @@ export function createM365Provider({ home, env = process.env, account: accountOv
103
104
  try {
104
105
  account = accountOverride || readM365Account({ home });
105
106
  const saved = readM365Json(paths.catalog);
106
- if (account && saved?.account_key === m365AccountKey(account) && Number.isFinite(saved.saved_at)
107
+ if (account && saved?.service_origin === M365_API_ORIGIN && saved.account_key === m365AccountKey(account) && Number.isFinite(saved.saved_at)
107
108
  && now() - saved.saved_at < HARD_TTL_MS) applyCatalog(saved.models, "cache", saved.saved_at);
108
109
  } catch { reason = "m365_cache_unavailable"; }
109
110
 
@@ -154,7 +155,7 @@ export function createM365Provider({ home, env = process.env, account: accountOv
154
155
  if (current !== generation || signal.aborted) throw m365Error("m365_refresh_cancelled");
155
156
  const savedAt = now();
156
157
  const nextAccount = { ...credential.account, ...(account?.history_isolation ? { history_isolation: true } : {}) };
157
- if (persist) writeM365Binding(nextAccount, { account_key: m365AccountKey(nextAccount), saved_at: savedAt, models: value }, { home, expectedAccount: account });
158
+ if (persist) writeM365Binding(nextAccount, { account_key: m365AccountKey(nextAccount), service_origin: M365_API_ORIGIN, saved_at: savedAt, models: value }, { home, expectedAccount: account });
158
159
  account = nextAccount;
159
160
  applyCatalog(value, "live", savedAt);catalogDiagnostic = null;state = "ready";reason = null;registry.lastError = null;registry.lastErrorAtMs = null;
160
161
  try { await onCatalog(value); } catch { log("warn", "M365 models are ready; optional client configuration could not be updated"); }
@@ -252,10 +253,11 @@ export function createM365Provider({ home, env = process.env, account: accountOv
252
253
  },
253
254
  commitSelection(expectedAccount) {
254
255
  if (!catalog || state !== "ready" || !account) throw m365Error("m365_not_ready");
255
- writeM365Binding(account, { account_key: m365AccountKey(account), saved_at: catalogAt, models: catalog }, { home, expectedAccount });
256
+ writeM365Binding(account, { account_key: m365AccountKey(account), service_origin: M365_API_ORIGIN, saved_at: catalogAt, models: catalog }, { home, expectedAccount });
256
257
  persist = true;
257
258
  },
258
259
  snapshot: () => ({ ...auth.snapshot(), state, reason: reason || auth.snapshot().reason, account: account ? { login: account.login, tenant: account.tenant, selection_source: account.selection_source || "legacy" } : null,
260
+ service_origin: M365_API_ORIGIN,
259
261
  network: network?.snapshot() || null,
260
262
  network_diagnostic: networkDiagnostic ? { ...networkDiagnostic } : null,
261
263
  catalog_diagnostic: m365CatalogDiagnostic(catalogDiagnostic),
@@ -5,6 +5,7 @@ import { readImageProviderConfig } from "./image-provider-config.mjs";
5
5
  import { readPredictionSettings } from "./native-prediction-profile.mjs";
6
6
  import { cacheRuntimeSnapshot, cleanRuntimeCaches, setHistoryCacheLimit } from "./cache-control.mjs";
7
7
  import { isTerminalAnimationTheme } from "./terminal-animation.mjs";
8
+ import { settingsPreferencesSnapshot, writeSettingsPreferences } from "./settings-preferences.mjs";
8
9
 
9
10
  export function createServiceControl({ env = process.env, home, providerRuntime, clientIntegration, terminal,
10
11
  nightlyStatus = () => null, nightlyChanged = () => {},
@@ -17,7 +18,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
17
18
  try { imageConfigured = Boolean(readImages()); } catch {}
18
19
  try { predictionConfigured = readPrediction().enabled === true; } catch {}
19
20
  const enabled = nightlyUpdatePreference(options), nightly = nightlyStatus();
20
- return { source: "service_settings", saved, theme, color_theme,
21
+ return { source: "service_settings", saved, theme, color_theme, preferences: settingsPreferencesSnapshot(options),
21
22
  nightly_update: { enabled, ...nightly, effect: enabled && !nightly ? "next_start" : "immediate" },
22
23
  effective: {
23
24
  terminal_animation_enabled: { value: terminal?.enabled === true && saved.terminal_animation_enabled && !/^(0|false|no|off)$/i.test(env.CCDX_TERMINAL_ANIMATION || ""),
@@ -33,9 +34,16 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
33
34
  if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Invalid setting action");
34
35
  const allowed = { preference: ["action", "key", "value"], nightly_update: ["action", "enabled"], animation: ["action", "theme"], color_theme: ["action", "theme"],
35
36
  history_limit: ["action", "mib"], history_clean: ["action"], prediction_fix: ["action"],
37
+ preferences: ["action", "values", "revision"], reset_preferences: ["action", "revision", "backup_id"], restore_preferences: ["action", "revision", "backup_id"],
36
38
  provider: ["action", "operation", "provider", "model", "auto_review_model", "auto_review_effort", "account_id"] }[input.action];
37
39
  if (!allowed || Object.keys(input).some(key => !allowed.includes(key))) throw new Error("Unknown setting action or field");
38
- if (input.action === "nightly_update") {
40
+ if (["preferences", "reset_preferences", "restore_preferences"].includes(input.action)) {
41
+ const before = nightlyUpdatePreference(options);
42
+ writeSettingsPreferences(input, options);
43
+ const current = settingsPreferencesSnapshot(options).values;
44
+ terminal?.apply?.({ ...servicePreferences(options), theme: current.terminal_animation, color_theme: current.terminal_color_theme });
45
+ if (before !== current.nightly_updates) nightlyChanged(current.nightly_updates);
46
+ } else if (input.action === "nightly_update") {
39
47
  writeNightlyUpdatePreference(input.enabled, options);nightlyChanged(input.enabled);
40
48
  } else if (input.action === "preference") {
41
49
  writeServicePreference(input.key, input.value, options);