codex-copilot-dx 1.2.3 → 1.2.5
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 +3 -3
- package/docs/ARCHITECTURE.md +4 -0
- package/docs/README.md +2 -0
- package/docs/REFERENCE.md +17 -3
- package/package.json +1 -1
- package/src/dashboard/console.js +2 -3
- package/src/dashboard/index.html +25 -10
- package/src/dashboard/language.js +28 -0
- package/src/dashboard/status.js +7 -6
- package/src/dashboard/ui.css +29 -4
- package/src/dashboard/ui.js +18 -12
- package/src/dashboard/updates.js +73 -0
- package/src/dashboard/usage.js +101 -19
- package/src/dashboard-api.mjs +9 -0
- package/src/dashboard-updates.mjs +71 -0
- package/src/dashboard.mjs +1 -0
- package/src/optional-routes.mjs +2 -2
- package/src/usage-store.mjs +21 -10
package/README.md
CHANGED
|
@@ -14,11 +14,11 @@ npm install -g codex-copilot-dx@latest
|
|
|
14
14
|
ccdx
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
No Node or Git? Download [install.sh](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.
|
|
17
|
+
No Node or Git? Download [install.sh](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.5/install.sh) (macOS/Linux) or [install.ps1](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.5/install.ps1) (Windows), then run `sh install.sh` or `./install.ps1` under your current shell policy. The bootstrap reuses compatible Node/npm or installs verified official Node 24.22.0 privately for CCDX. It adds no Git, compiler or system package manager. It keeps registry/proxy/certificate policy, verifies the Release package and installed runtime, and restores the prior CCDX package if installation fails. Dependencies still need your configured registry. See [installation limits and private command paths](docs/REFERENCE.md#install-without-node-or-git).
|
|
18
18
|
|
|
19
19
|
CCDX reuses a compatible local credential or starts GitHub Device Flow, listens on `127.0.0.1:2026`, configures Codex, and opens the App. Interactive desktop starts also open the local WebUI once; use `ccdx --no-browser` or disable this in WebUI settings. No client binary patch is needed. On Windows, open the App manually unless native prediction setup is enabled. In restricted Windows PowerShell, use `npm.cmd` to install and `ccdx.cmd` for the first launch, or run `ccdx.cmd doctor --fix`. Startup, updates and explicit repair remove only CCDX's exact npm-generated `.ps1` launchers so later calls can use `ccdx`. The npm package adds no install hook or policy change; custom launchers are preserved. npm's own script is untouched. The configured `dummy` API key is a placeholder, not a credential.
|
|
20
20
|
|
|
21
|
-
The [local control console](http://127.0.0.1:2026/) keeps indented Codex/Claude pages, Model sources, Usage, Requests and Settings. Codex owns source/model, Auto Review, images, input suggestions and conversation buffering; Model sources owns accounts, catalogs and Microsoft 365 access. Browsing a catalog never changes routing. The existing visual style
|
|
21
|
+
The [local control console](http://127.0.0.1:2026/) keeps indented Codex/Claude pages, Model sources, Usage, Requests and Settings. Codex owns source/model, Auto Review, images, input suggestions and conversation buffering; Model sources owns accounts, catalogs and Microsoft 365 access. Browsing a catalog never changes routing. Usage offers animated bars (default) or curves without extra requests; reduced motion keeps them static. Overview shows an approximate token cache hit rate, retaining partial/unknown states. The existing visual style and logo remain.
|
|
22
22
|
|
|
23
23
|
Startup shows bounded checks, sources with discovered model lists and Claude Code/App configuration. Prediction normally uses one summary line; `ccdx prediction status` retains recovery and environment details. After Ready, an interactive terminal shows current source/Claude state and a line-framed table of this process's returned usage and inference counters. Notices and activity each have their own line; individual requests do not scroll. Input includes reused input tokens. `ccdx --verbose` (also `--show-request-id`, or debug logging) retains detail output; optional file logging remains independently controlled. Source and Claude summaries wrap on narrow terminals. Failed reads show previous-data status and the last successful update time. Non-TTY, CI, dumb, or terminals too small for the full region use plain output (at least 40 columns / 16 rows are required). `Ready` only means the core service is available; discovered catalogs and configured clients do not prove inference access.
|
|
24
24
|
|
|
@@ -110,7 +110,7 @@ See the [M365 reference](docs/REFERENCE.md#microsoft-365-provider) for ownership
|
|
|
110
110
|
expose it to the public internet. The dashboard is not an authentication wall
|
|
111
111
|
for the API. Inference rejects browser Origin headers; native clients remain supported. Diagnostic errors may contain sensitive upstream text.
|
|
112
112
|
|
|
113
|
-
Startup checks GitHub's latest-release web redirect, not npm or the anonymous REST quota, and suggests `ccdx update github`.
|
|
113
|
+
Startup checks GitHub's latest-release web redirect, not npm or the anonymous REST quota, and suggests `ccdx update github`. Settings → Version & updates shows the running version, release dates and newer releases, with copyable update and macOS/Windows recovery commands. This separate, cached GitHub metadata check never installs automatically; failed checks remain unknown. See the [reference](docs/REFERENCE.md#version-and-update-information).
|
|
114
114
|
GitHub updates verify and install the exact Release tarball without Git; dependencies still use npm's configured registry. Lookup errors identify HTTP refusal, timeout, network failure or invalid redirects. For npm `EALLOWREMOTE`, only if policy permits and the update is trusted, use `ccdx update github --allow-remote`: explicit URL-download permission for that installation's whole dependency tree, not a hostname allowlist. Persistent npm settings stay unchanged.
|
|
115
115
|
Updates back up the discovered CCDX package and commands, restore them on install/runtime-check failure, and verify the installed version (exact for GitHub). Mismatched npm targets warn without changing PATH/prefix. Restart the adapter separately. Full `ccdx doctor` reports this target and readonly credential permissions; it never changes ACLs.
|
|
116
116
|
Recent errors separate HTTP and model failures. By default HTTP metadata retains status, source and IDs, not error bodies or prompts; original errors still reach Codex unchanged. Explicit, bounded error-excerpt collection is described in the [reference](docs/REFERENCE.md#http-error-diagnostics).
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -277,6 +277,10 @@ while visible/automatic, and source/settings evidence every eight status ticks.
|
|
|
277
277
|
Catalog and retained-log reads retain their slower, view-scoped policy. Animation
|
|
278
278
|
frames still load once per page when opened.
|
|
279
279
|
|
|
280
|
+
`dashboard/usage.js` owns bar/curve geometry and viewport-gated, one-shot Web Animations. The two views share retained analytics and accessible day buttons; their paths never connect unavailable history or overshoot adjacent values. View-only changes leave the calendar nodes intact. The UI lifecycle cancels motion on hidden/suspended views and reduced-motion changes; no animation timer or chart dependency is added. `usage-store.mjs` shares cache-evidence validation between retained summaries and process-local totals; runtime snapshots expose the weighted cache ratio plus a partial-evidence flag, without new persistence or log scans. The Overview renderer formats that snapshot and preserves unknown/invalid values.
|
|
281
|
+
|
|
282
|
+
`dashboard-updates.mjs` is loaded only by the protected update-information route. It projects bounded public stable-release metadata and publication dates, with process-local single-flight, five-minute success and one-minute failure caches. Its asynchronous npm network-configuration read reuses the installer's existing policy-preserving downloader; it adds no runtime dependency, credentials or synchronous child process on the service event loop. Metadata has a four-second per-request deadline and 128 KiB decoded-body bound. It never installs or restarts anything and does not alter startup's independent web-redirect lookup. `dashboard/updates.js` renders current/available/unknown states and validated, pinned installation command text; `refresh.js` owns its visible Settings refresh cadence. Failed checks preserve explicitly labeled prior metadata. No provider authentication or inference is involved.
|
|
283
|
+
|
|
280
284
|
`claude-models.mjs` owns exact ID spelling and capability-cap projection shared by
|
|
281
285
|
configuration and model discovery. M365 resolves both canonical and existing raw
|
|
282
286
|
IDs to the same catalog entry and checks explicit effort lists without modifying
|
package/docs/README.md
CHANGED
|
@@ -17,6 +17,8 @@ effective Codex configuration or validate every field against the installed app.
|
|
|
17
17
|
|
|
18
18
|
## Historical release evidence
|
|
19
19
|
|
|
20
|
+
- [1.2.4: Navigation clarity and bounded version discovery](RELEASE_1.2.4.md)
|
|
21
|
+
|
|
20
22
|
These reports record a specific release and test environment. Their version,
|
|
21
23
|
test counts, timings, live-provider observations, and limitations remain
|
|
22
24
|
historical facts rather than current guarantees.
|
package/docs/REFERENCE.md
CHANGED
|
@@ -848,6 +848,16 @@ Terminal color uses `terminal_color_theme: "klein"` in the normal CCDX user conf
|
|
|
848
848
|
|
|
849
849
|
The terminal sample in Settings is labeled Preview and uses sample numbers, not current usage. Existing nine animation previews and their save operation remain available beneath the color choice. Red errors and amber warnings keep their meaning across webpage themes.
|
|
850
850
|
|
|
851
|
+
### Version and update information
|
|
852
|
+
|
|
853
|
+
Settings ends with Version & updates. The current version belongs to the running service, which can differ from a newly installed package until CCDX restarts. Dates are GitHub Release publication dates, not local installation dates; an unavailable date is explicitly unknown. A verified newer stable release shows its version/date and `ccdx update github`. Copying a command never executes it. No background installation or service restart is added.
|
|
854
|
+
|
|
855
|
+
Opening Settings reads `GET /_ccdx/ui/updates`, protected by the existing loopback/Host/dashboard-header checks. It reads public GitHub REST release metadata without credentials, accepting stable, non-draft releases only. The first successful check needs at most two serial metadata requests: latest, and the exact current tag when different. The current publication date is retained in memory. Concurrent reads share one lookup; successful results are cached for five minutes and failures for one minute. The page reuses the visible-view 30-minute refresh controller, so the two-second status timer never polls GitHub. Manual checks also respect the service cache. Network configuration discovery is asynchronous and reads only npm's named proxy/CA/TLS/offline settings; no registry or policy is rewritten. Each metadata request has a four-second deadline and a 128 KiB decoded-body limit, with no automatic retry.
|
|
856
|
+
|
|
857
|
+
Failed/rate-limited checks never claim that the installed version is latest. Last-known release details remain labeled as such, separate from the latest check attempt. A failed current-tag date lookup does not hide an otherwise verified available update. The startup web-redirect check remains unchanged and independent of this REST check. If npm/network settings cannot be read or company policy blocks GitHub, the version card reports the check as unavailable.
|
|
858
|
+
|
|
859
|
+
Expand the recovery instructions to choose macOS Terminal or Windows PowerShell. Commands download the version-pinned Release installer into a unique temporary directory and remove that directory afterward. They use the newer of the running version and last-known stable release, falling back to the running version if no release is known; stale metadata cannot select a downgrade. Installers retain the documented no-Git, minimum-runtime, rollback and configured-registry behavior. Windows instructions keep the current execution policy; if company policy blocks scripts, use its approved installation method. Dependencies still require the configured npm registry.
|
|
860
|
+
|
|
851
861
|
Model-list failures name the selected source, retain its last successful list when available, and distinguish that list's timestamp from the failed check. Expand Check details for the bounded public reason, source, available HTTP status and check time. A retry time is shown only when the source supplies an actual retry delay; no new retry or automatic provider failover is added. Existing diagnostic redaction and size limits remain.
|
|
852
862
|
|
|
853
863
|
### Terminal animation
|
|
@@ -994,7 +1004,7 @@ Unknown support prevents an explicitly requested exception from starting.
|
|
|
994
1004
|
For an older updater that still requires Git, install the Release tarball directly:
|
|
995
1005
|
|
|
996
1006
|
```sh
|
|
997
|
-
npm install -g https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.
|
|
1007
|
+
npm install -g https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.5/codex-copilot-dx-1.2.5.tgz
|
|
998
1008
|
# Windows PowerShell: use npm.cmd instead of npm.
|
|
999
1009
|
```
|
|
1000
1010
|
|
|
@@ -1166,7 +1176,7 @@ A locally saved GitHub credential is not online entitlement. Account names with
|
|
|
1166
1176
|
underscores retain their exact display value; identity, keys and environment
|
|
1167
1177
|
values are not inferred from model names. Client configuration, gateway state,
|
|
1168
1178
|
recent requests and actual inference are separate observations. The top summary
|
|
1169
|
-
|
|
1179
|
+
describes source/application status without mapping arrows. The source card counts and lists every discovered registered source, including disabled sources; availability and account evidence remain in the detailed tables. Each sidebar tab has a decorative inline SVG icon, with application entries indented. Terminal appearance has one Settings entry, and the animation selector has one separating rule.
|
|
1170
1180
|
|
|
1171
1181
|
Catalog tabs browse registered Provider directories without changing routing.
|
|
1172
1182
|
Rows retain protocol, eligible clients, reasoning metadata and directory state.
|
|
@@ -1190,14 +1200,18 @@ are not guessed into one. Legacy untagged Provider records retain their historic
|
|
|
1190
1200
|
GitHub attribution. Cache-read tokens are included in input, not added twice.
|
|
1191
1201
|
The separate current-run summary updates from returned usage in memory, without
|
|
1192
1202
|
rescanning retained logs at the status cadence.
|
|
1203
|
+
Overview adds an approximate token cache hit rate: returned reused input tokens divided by returned input tokens, weighted by tokens rather than request percentages. Missing evidence is distinct from an explicit zero; all-unknown cache evidence, zero input and invalid counts display `—`. Mixed complete/incomplete cache evidence displays `~` before the recorded aggregate ratio. This describes recorded input reuse, not a request success ratio, invoice or whole-account cache statistic. Missing output alone does not invalidate usable input/cache evidence.
|
|
1193
1204
|
|
|
1194
|
-
Usage analytics remains collapsed until opened: 7/30/90-day
|
|
1205
|
+
Usage analytics remains collapsed until opened: 7/30/90-day charts and a bounded
|
|
1195
1206
|
365-day calendar in the browser time zone. Model/range/day selection reuses its
|
|
1196
1207
|
snapshot. Days outside retained history are distinct from zero recorded activity.
|
|
1197
1208
|
Filters, chart nodes and unsaved animation selection survive unrelated refreshes.
|
|
1198
1209
|
Dark/light, English/Chinese and reduced motion remain supported. Language changes
|
|
1199
1210
|
translate page labels in place without fetching models or rebuilding charts;
|
|
1200
1211
|
commands, identifiers and upstream error text retain their original values.
|
|
1212
|
+
Chart view defaults to Bar chart on each page load; its dropdown switches to Line chart without another request or log scan. Both views retain the same input/output values, scale, model/source/range filters and date selection. Lines show separate input/output series, pass through each known day's value, stay between neighboring values and break across unavailable history; a lone known day is a point. The calendar is unchanged by view switching.
|
|
1213
|
+
|
|
1214
|
+
Visible bar stacks rise from the baseline once over 450 ms; curves draw left to right over 600 ms (a lone point fades in over 200 ms). Opening/revealing a chart and changing its data, filters or view can replay the entrance. Selecting a day, changing calendar measure and unchanged background refreshes do not replay it. Hidden/collapsed views, page suspension and reduced-motion preferences cancel active chart motion; reduced-motion or unsupported animation APIs retain the complete static chart. Chart motion adds no polling loop, chart library or runtime dependency.
|
|
1201
1215
|
|
|
1202
1216
|
The atom logo stays in the sidebar brand (compact top navigation on narrow screens).
|
|
1203
1217
|
It rotates once on load and manual Refresh, never on scheduled reads, and respects
|
package/package.json
CHANGED
package/src/dashboard/console.js
CHANGED
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
label(el("page-title"), titles[next]);
|
|
48
48
|
if (["codex", "models", "system"].includes(next)) void loadSettings();
|
|
49
49
|
if (next === "models") { void dashboardRefresh.refresh("models");void dashboardRefresh.refresh("auth"); }
|
|
50
|
-
if (next === "usage") void dashboardRefresh.refresh("usage");
|
|
51
|
-
if (next === "system") void dashboardRefresh.refresh("animation");
|
|
50
|
+
if (next === "usage") { void dashboardRefresh.refresh("usage");usageView.revealChart(); } else usageView.stopMotion();
|
|
51
|
+
if (next === "system") { void dashboardRefresh.refresh("animation");void dashboardRefresh.refresh("updates"); }
|
|
52
52
|
syncAnimationPreview();
|
|
53
53
|
}
|
|
54
54
|
async function api(body) {
|
|
@@ -266,6 +266,5 @@
|
|
|
266
266
|
el("refresh").addEventListener("click", () => { if (["codex", "models", "system"].includes(current)) void loadSettings(); });
|
|
267
267
|
window.addEventListener("pagehide", () => { stopped = true;clearTimeout(timer); });
|
|
268
268
|
window.addEventListener("pageshow", () => { stopped = false;schedule(); });
|
|
269
|
-
el("open-animation").addEventListener("click", () => { location.hash = "system";navigate(); });
|
|
270
269
|
navigate();schedule();
|
|
271
270
|
})();
|
package/src/dashboard/index.html
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
<script src="/refresh.js" defer></script>
|
|
12
12
|
<script src="/status.js" defer></script>
|
|
13
13
|
<script src="/usage.js" defer></script>
|
|
14
|
+
<script src="/updates.js" defer></script>
|
|
14
15
|
<script src="/ui.js" defer></script>
|
|
15
16
|
<script src="/console.js" defer></script>
|
|
16
17
|
<title data-i18n="ccdx_local_dashboard">CCDX · Dashboard</title>
|
|
@@ -20,16 +21,15 @@
|
|
|
20
21
|
<aside class="sidebar">
|
|
21
22
|
<a class="sidebar-brand" href="#overview"><svg id="status-icon" class="status-icon" viewBox="0 0 64 64" aria-hidden="true" focusable="false"><g fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round"><ellipse cx="32" cy="32" rx="26" ry="10"/><ellipse cx="32" cy="32" rx="26" ry="10" transform="rotate(60 32 32)"/><ellipse cx="32" cy="32" rx="26" ry="10" transform="rotate(120 32 32)"/></g><circle cx="32" cy="32" r="4.5" fill="currentColor"/></svg><span class="brand-name">CCDX</span><span class="brand-caption" data-i18n="local_control">LOCAL CONTROL</span></a>
|
|
22
23
|
<nav aria-label="Navigation" data-i18n-label="main_navigation">
|
|
23
|
-
<a href="#overview" data-route="overview" aria-current="page" data-i18n="overview">Overview</a>
|
|
24
|
+
<a href="#overview" data-route="overview" aria-current="page"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg><span data-i18n="overview">Overview</span></a>
|
|
24
25
|
<span class="nav-group" data-i18n="clients">Apps</span>
|
|
25
|
-
<a class="nav-child" href="#codex" data-route="codex">Codex</a>
|
|
26
|
-
<a class="nav-child" href="#claude" data-route="claude">Claude</a>
|
|
27
|
-
<a href="#models" data-route="models" data-i18n="model_services">Model sources</a>
|
|
28
|
-
<a href="#usage" data-route="usage" data-i18n="usage_and_diagnostics">Usage</a>
|
|
29
|
-
<a href="#requests" data-route="requests" data-i18n="request_records">Requests</a>
|
|
30
|
-
<a href="#system" data-route="system" data-i18n="system_and_settings">Settings</a>
|
|
26
|
+
<a class="nav-child" href="#codex" data-route="codex"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="m7 8 4 4-4 4m7 0h3"/></svg><span>Codex</span></a>
|
|
27
|
+
<a class="nav-child" href="#claude" data-route="claude"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M21 15a3 3 0 0 1-3 3H8l-5 3V6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3Z"/></svg><span>Claude</span></a>
|
|
28
|
+
<a href="#models" data-route="models"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m12 3 10 5-10 5L2 8Zm-10 9 10 5 10-5M2 16l10 5 10-5"/></svg><span data-i18n="model_services">Model sources</span></a>
|
|
29
|
+
<a href="#usage" data-route="usage"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3 3v18h18M7 16v-5m5 5V7m5 9V4"/></svg><span data-i18n="usage_and_diagnostics">Usage</span></a>
|
|
30
|
+
<a href="#requests" data-route="requests"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"/></svg><span data-i18n="request_records">Requests</span></a>
|
|
31
|
+
<a href="#system" data-route="system"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3 6h4m4 0h10M3 12h10m4 0h4M3 18h4m4 0h10"/><circle cx="9" cy="6" r="2"/><circle cx="15" cy="12" r="2"/><circle cx="9" cy="18" r="2"/></svg><span data-i18n="system_and_settings">Settings</span></a>
|
|
31
32
|
</nav>
|
|
32
|
-
<div class="sidebar-bottom"><button id="open-animation" type="button" aria-controls="animation-settings" aria-expanded="false" data-i18n="terminal_appearance">Terminal appearance</button></div>
|
|
33
33
|
</aside>
|
|
34
34
|
|
|
35
35
|
<header class="topbar">
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
<div class="table-wrap"><table><thead><tr><th data-i18n="source">Source</th><th data-i18n="client">APP</th><th data-i18n="state">STATE</th><th data-i18n="gateway">LOCAL ACCESS</th><th data-i18n="last_request">LAST REQUEST</th></tr></thead><tbody id="provider-clients"></tbody></table></div>
|
|
53
53
|
<div id="provider-requests" class="hint"></div>
|
|
54
54
|
</details>
|
|
55
|
-
<section class="panel dashboard-section"><h2 data-i18n="this_run_usage">THIS RUN</h2><p id="runtime-usage" class="table-note"></p><p class="hint" data-i18n="updated_from_returned_usage_not_a_live_bill_pending_usage_is_not">Counts returned usage only. Pending usage is not included. This is not a live bill.</p></section>
|
|
55
|
+
<section class="panel dashboard-section"><h2 data-i18n="this_run_usage">THIS RUN</h2><p id="runtime-usage" class="table-note"></p><p class="table-note"><span data-i18n="approx_cache_hit_rate">Approx. cache hit rate</span>: <strong id="runtime-cache-hit" data-i18n-title="runtime_cache_hit_basis" title="Reused input / input tokens. ~ Partial counts. — Unknown or invalid.">—</strong></p><p class="hint" data-i18n="updated_from_returned_usage_not_a_live_bill_pending_usage_is_not">Counts returned usage only. Pending usage is not included. This is not a live bill.</p></section>
|
|
56
56
|
</div>
|
|
57
57
|
<div data-view="codex" hidden>
|
|
58
58
|
<section class="panel dashboard-section" aria-labelledby="routing-heading">
|
|
@@ -166,6 +166,7 @@
|
|
|
166
166
|
<div class="analytics-controls">
|
|
167
167
|
<label><span data-i18n="model_5e2c6">Model</span> <select id="analytics-model"><option value="" data-i18n="all_models">All models</option></select></label>
|
|
168
168
|
<label><span data-i18n="daily_range">Date range</span> <select id="analytics-range"><option value="7" data-i18n="7_days">Last 7 days</option><option value="30" selected data-i18n="30_days">Last 30 days</option><option value="90" data-i18n="90_days">Last 90 days</option></select></label>
|
|
169
|
+
<label><span data-i18n="chart_view">Chart view</span> <select id="analytics-view"><option value="bars" selected data-i18n="bar_chart">Bar chart</option><option value="line" data-i18n="line_chart">Line chart</option></select></label>
|
|
169
170
|
<label><span data-i18n="activity">Measure</span> <select id="analytics-metric"><option value="requests" data-i18n="calls_b73a5">Requests</option><option value="tokens" data-i18n="tokens">Usage (Token)</option></select></label>
|
|
170
171
|
</div>
|
|
171
172
|
<p id="analytics-note" class="table-note" role="status" data-i18n="open_to_read_retained_usage_history">Open to view usage trends.</p>
|
|
@@ -245,7 +246,7 @@ Missing data is unknown. This panel keeps no prompts or images.</p>
|
|
|
245
246
|
<pre class="terminal-motion"><span id="terminal-sample-frame">[ :::::::]</span> <span id="terminal-sample-status">Working</span></pre>
|
|
246
247
|
</div>
|
|
247
248
|
|
|
248
|
-
<div class="setting-row"><label for="setting-terminal_animation_enabled" data-i18n="terminal_animation">Terminal animation</label><input id="setting-terminal_animation_enabled" type="checkbox" role="switch" disabled><span id="effect-terminal_animation_enabled" class="hint" role="status"></span></div>
|
|
249
|
+
<div class="setting-row terminal-animation-toggle"><label for="setting-terminal_animation_enabled" data-i18n="terminal_animation">Terminal animation</label><input id="setting-terminal_animation_enabled" type="checkbox" role="switch" disabled><span id="effect-terminal_animation_enabled" class="hint" role="status"></span></div>
|
|
249
250
|
<details id="animation-settings" class="appearance-animation settings-panel">
|
|
250
251
|
<summary class="panel-heading"><h2 data-i18n="terminal_animation_9edf6">TERMINAL ANIMATION</h2><span id="animation-state" data-i18n="reading">READING</span></summary>
|
|
251
252
|
<div id="animation-options" class="animation-options" role="group" aria-label="Animation style" data-i18n-label="animation_theme"></div>
|
|
@@ -262,6 +263,20 @@ Missing data is unknown. This panel keeps no prompts or images.</p>
|
|
|
262
263
|
|
|
263
264
|
<section class="panel dashboard-section"><h2 data-i18n="process_listener">LOCAL SERVICE</h2><p id="process-state" class="table-note"></p><p id="process-memory" class="hint"></p><p id="process-queues" class="hint"></p><p id="process-notice" class="hint" role="status"></p></section>
|
|
264
265
|
<section class="overview client-overview"><article class="card"><h2 data-i18n="http_traffic">SERVICE REQUESTS</h2><strong id="requests">—</strong><p id="request-errors">—</p><p id="http-error-breakdown">—</p><p><span data-i18n="per_request_limits_active">Per-request limits</span><br><span id="body-limits">—</span></p></article></section>
|
|
266
|
+
<section class="panel dashboard-section" id="version-updates" aria-labelledby="version-updates-title">
|
|
267
|
+
<div class="version-heading"><h2 id="version-updates-title" data-i18n="version_updates">VERSION & UPDATES</h2><button id="check-updates" type="button" data-i18n="check_updates">Check for updates</button></div>
|
|
268
|
+
<dl class="version-list"><div><dt data-i18n="current_version">Current version</dt><dd id="update-current-version">—</dd><dd id="update-current-date" class="hint">—</dd></div><div id="update-latest-row" hidden><dt data-i18n="available_update">Update available</dt><dd id="update-latest-version">—</dd><dd id="update-latest-date" class="hint">—</dd></div></dl>
|
|
269
|
+
<p id="update-state" class="hint" role="status" data-i18n="reading">READING</p>
|
|
270
|
+
<div id="update-command-row" class="update-command"><code id="update-command">ccdx update github</code><button type="button" id="copy-update" data-i18n="copy_command">Copy command</button></div>
|
|
271
|
+
<p class="hint" data-i18n="update_restart">Run in your terminal, then restart CCDX.</p>
|
|
272
|
+
<p id="update-checked" class="refresh-time"></p>
|
|
273
|
+
<details class="update-install"><summary data-i18n="update_install_help">Update failed? View full installation commands</summary><p class="hint" data-i18n="update_install_hint">Download the official installer. No Git required.</p>
|
|
274
|
+
<div class="section-actions install-platforms" role="group" aria-label="Installation platform" data-i18n-label="installation_platform"><button type="button" data-install-platform="macos" aria-pressed="true">macOS</button><button type="button" data-install-platform="windows" aria-pressed="false">Windows</button></div>
|
|
275
|
+
<div class="install-command-heading"><span id="install-shell" class="hint">macOS · Terminal</span><button type="button" id="copy-install" data-i18n="copy_command">Copy command</button></div><pre id="install-command" class="install-command"></pre>
|
|
276
|
+
<p class="hint" data-i18n="update_install_policy">Reuses compatible Node/npm or installs a private runtime. Keeps your registry, proxy, certificates and shell policy.</p>
|
|
277
|
+
<p id="install-windows-policy" class="hint" hidden data-i18n="update_windows_policy">If scripts are blocked, use your company’s approved installation method.</p>
|
|
278
|
+
</details><p id="update-copy-note" class="hint" role="status"></p>
|
|
279
|
+
</section>
|
|
265
280
|
</div>
|
|
266
281
|
</main>
|
|
267
282
|
<footer data-i18n="local_only_visible_page_updates">THIS COMPUTER ONLY / UPDATES WHILE VISIBLE</footer>
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const translations = {
|
|
3
|
+
"chart_view": ["Chart view", "图表视图"],
|
|
4
|
+
"bar_chart": ["Bar chart", "柱状图"],
|
|
5
|
+
"line_chart": ["Line chart", "曲线图"],
|
|
6
|
+
"approx_cache_hit_rate": ["Approx. cache hit rate", "粗略缓存命中率"],
|
|
7
|
+
"runtime_cache_hit_basis": ["Reused input / input tokens. ~ Partial counts. — Unknown or invalid.", "复用输入 ÷ 输入 Token。\n~:数据不完整。—:未知或无效。"],
|
|
8
|
+
"provider_status_scope": ["Source and application status", "模型来源与应用状态"],
|
|
9
|
+
"version_updates": ["VERSION & UPDATES", "版本与更新"],
|
|
10
|
+
"copy_command": ["Copy command", "复制指令"],
|
|
11
|
+
"check_updates": ["Check for updates", "检查更新"],
|
|
12
|
+
"checking_updates": ["Checking…", "正在检查…"],
|
|
13
|
+
"current_version": ["Current version", "当前版本"],
|
|
14
|
+
"available_update": ["Update available", "可用更新"],
|
|
15
|
+
"last_known_version": ["Last known version", "上次查到的版本"],
|
|
16
|
+
"released_date": ["Released {date}", "发布于 {date}"],
|
|
17
|
+
"release_date_unknown": ["Release date unknown", "发布日期未知"],
|
|
18
|
+
"new_version_available": ["A new version is available.", "发现新版本。"],
|
|
19
|
+
"already_latest": ["You’re up to date.", "已是最新版本。"],
|
|
20
|
+
"update_check_failed": ["Could not check updates. Latest version unknown.", "暂时无法检查,最新版本未知。"],
|
|
21
|
+
"update_rate_limited": ["GitHub limited update checks. Try again later.", "GitHub 限制了检查,请稍后再试。"],
|
|
22
|
+
"update_restart": ["Run in your terminal, then restart CCDX.", "在终端运行,完成后重启 CCDX。"],
|
|
23
|
+
"update_checked_time": ["Last checked: {time}", "上次检查:{time}"],
|
|
24
|
+
"update_attempted_time": ["Last attempt: {time}", "最近尝试:{time}"],
|
|
25
|
+
"update_install_help": ["Update failed? View full installation commands", "更新遇到问题?查看完整安装指令"],
|
|
26
|
+
"installation_platform": ["Installation platform", "安装平台"],
|
|
27
|
+
"update_install_hint": ["Download the official installer. No Git required.", "下载官方安装器,无需 Git。"],
|
|
28
|
+
"update_install_policy": ["Reuses compatible Node/npm or installs a private runtime. Keeps your registry, proxy, certificates and shell policy.", "复用可用的 Node/npm,否则安装专用运行环境。\n保留镜像、代理、证书和脚本策略。"],
|
|
29
|
+
"update_windows_policy": ["If scripts are blocked, use your company’s approved installation method.", "若公司禁止运行脚本,请使用公司批准的安装方式。"],
|
|
30
|
+
"update_copy_unavailable": ["Clipboard unavailable. Select the command and copy it.", "无法自动复制,请选中指令复制。"],
|
|
3
31
|
"company_account": ["Company account", "公司账号"],
|
|
4
32
|
"check_accounts": ["Check accounts", "检查账号"],
|
|
5
33
|
"choose_company_account": ["Choose a company account", "选择公司账号"],
|
package/src/dashboard/status.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
restored: "settings_restored", not_installed: "not_installed", configuration_unavailable: "setup_unavailable", not_configured: "unknown", standby: "standby" };
|
|
15
15
|
const auth = element("provider-auth"), clients = element("provider-clients"), requests = element("provider-requests");
|
|
16
16
|
auth.replaceChildren();clients.replaceChildren();requests.replaceChildren();
|
|
17
|
-
const routes = [];
|
|
18
17
|
for (const provider of providers) {
|
|
19
18
|
sourceNames.set(provider.id, provider.name);
|
|
20
19
|
const identity = provider.auth || {};
|
|
@@ -27,7 +26,6 @@
|
|
|
27
26
|
client.gateway || "—", client.last_request_at || "—"], { labels: [2, 3] });
|
|
28
27
|
if (client.reason) localize(row.children[2], "state_reason", { state: phrase(states[client.state] || "unknown"), reason: client.reason });
|
|
29
28
|
clients.append(row);
|
|
30
|
-
if (client.selected && client.id === "codex") routes.push(`${client.name} → ${provider.name}`);
|
|
31
29
|
}
|
|
32
30
|
if (provider.requests) {
|
|
33
31
|
const item = document.createElement("p");
|
|
@@ -36,10 +34,11 @@
|
|
|
36
34
|
requests.append(item);
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
|
-
text("source-summary", "count_providers", { count: providers.
|
|
40
|
-
element("source-detail").
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
text("source-summary", "count_providers", { count: providers.length });
|
|
38
|
+
element("source-detail").replaceChildren(...providers.map(provider => {
|
|
39
|
+
const item = document.createElement("span");item.textContent = provider.name;return item;
|
|
40
|
+
}));
|
|
41
|
+
text("auth-account", "provider_status_scope");
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
function duration(value) {
|
|
@@ -215,6 +214,8 @@
|
|
|
215
214
|
const usage = data.runtime_usage;
|
|
216
215
|
text("runtime-usage", usage ? "records_usage_records_input_input_cache_read_cached_output_outpu" : "—",
|
|
217
216
|
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 ? " ~" : "" } : {});
|
|
217
|
+
const rate = usage?.cache_hit_rate;
|
|
218
|
+
text("runtime-cache-hit", Number.isFinite(rate) && rate >= 0 && rate <= 1 ? `${usage.cache_hit_rate_partial ? "~" : ""}${(rate * 100).toFixed(1)}%` : "—");
|
|
218
219
|
element("process-state").textContent = `PID ${data.pid || "—"} / ${globalThis.location?.origin || ""}`;
|
|
219
220
|
text("process-memory", "rss_rss_heap_heap", { rss: mib(data.process?.rss_bytes), heap: mib(data.process?.heap_used_bytes) });
|
|
220
221
|
text("process-queues", "codex_body_admission_active_active_queued_queued_queue_limit_lim", {
|
package/src/dashboard/ui.css
CHANGED
|
@@ -110,6 +110,14 @@ select { max-width: 260px; padding: 5px; font: inherit; color: var(--text); back
|
|
|
110
110
|
.daily-bars { display: flex; align-items: end; gap: 3px; height: 130px; border-bottom: 1px solid var(--border); }
|
|
111
111
|
.daily-bar { height: 100%; flex: 1; min-width: 0; padding: 0; border: 0; display: flex; flex-direction: column; justify-content: end; background: transparent; border-radius: 0; }
|
|
112
112
|
.daily-bar span { display: block; flex-shrink: 0; width: 100%; }
|
|
113
|
+
.daily-bar .bar-stack { display:flex; flex-direction:column; justify-content:end; height:100%; transform-origin:center bottom; }
|
|
114
|
+
.daily-lines { position:relative; gap:0; }
|
|
115
|
+
.daily-line-plot { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; overflow:visible; }
|
|
116
|
+
.daily-curve { fill:none; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; stroke-dasharray:1; stroke-dashoffset:0; }
|
|
117
|
+
.curve-input { stroke:var(--accent-soft); }
|
|
118
|
+
.curve-output { stroke:var(--ansi-39); }
|
|
119
|
+
.daily-lines .daily-bar { z-index:1; }
|
|
120
|
+
.daily-lines .daily-bar:hover { background:color-mix(in srgb, var(--accent-soft) 10%, transparent); }
|
|
113
121
|
.bar-input { background: var(--accent-soft); }
|
|
114
122
|
.bar-output { background: var(--ansi-39); }
|
|
115
123
|
.daily-bar:hover { background: var(--option-hover); }
|
|
@@ -119,6 +127,7 @@ select { max-width: 260px; padding: 5px; font: inherit; color: var(--text); back
|
|
|
119
127
|
.chart-legend span::before { content: "■"; margin-right: 6px; }
|
|
120
128
|
.legend-input::before { color: var(--accent-soft); }
|
|
121
129
|
.legend-output::before { color: var(--ansi-39); }
|
|
130
|
+
.daily-lines ~ .chart-legend span::before { content:"━"; }
|
|
122
131
|
.calendar-scroll { overflow-x: auto; padding: 4px; }
|
|
123
132
|
.calendar-grid { width: max-content; }
|
|
124
133
|
.calendar-months { display: grid; grid-auto-columns: 12px; gap: 4px; margin-bottom: 7px; color: var(--muted); font-size: 9px; height: 14px; }
|
|
@@ -159,9 +168,6 @@ footer { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; color:
|
|
|
159
168
|
.sidebar nav a[aria-current="page"] { color: var(--accent); background: var(--selected-bg); border-left-color: var(--accent); }
|
|
160
169
|
.sidebar nav a:focus-visible, .sidebar-brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
|
|
161
170
|
.nav-group { color: var(--subtle); font-size: 10px; padding: 18px 12px 4px; text-transform: uppercase; letter-spacing: .08em; }
|
|
162
|
-
.sidebar-bottom { margin-top: auto; padding-top: 24px; }
|
|
163
|
-
.sidebar-bottom button { width: 100%; text-align: left; }
|
|
164
|
-
.sidebar-bottom p { color: var(--subtle); font-size: 11px; line-height: 1.7; }
|
|
165
171
|
.topbar, main, footer { grid-column: 2; min-width: 0; }
|
|
166
172
|
.topbar { min-height: 76px; gap: 14px; }
|
|
167
173
|
.brand { font-size: 12px; }
|
|
@@ -188,7 +194,7 @@ input[role="switch"]:focus-visible, input[type="number"]:focus-visible { outline
|
|
|
188
194
|
input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
189
195
|
#process-queues { overflow-wrap: anywhere; font-size: 11px; }
|
|
190
196
|
@media (max-width: 900px) { .shell { grid-template-columns: 170px minmax(0, 1fr); column-gap: 20px; padding: 0 20px; } .topbar .brand { display: none; } .topbar { justify-content: flex-end; } .setting-row { grid-template-columns: minmax(0, 1fr) 44px; } .setting-row .hint { grid-column: 1 / -1; } .overview { grid-template-columns: 1fr; } }
|
|
191
|
-
@media (max-width: 640px) { .shell { display: block; padding: 0 16px; } .sidebar { position: static; height: auto; padding: 20px 0 14px; border-right: 0; border-bottom: 1px solid var(--border); } .sidebar-brand { font-size: 20px; width: fit-content; } .sidebar-brand .brand-caption { margin-top: 4px; } .sidebar nav { display: flex; flex-direction: row; flex-wrap: wrap; gap: 4px; margin-top: 16px; } .sidebar nav a { padding: 9px 10px; font-size: 12px; border-left: 0; border-bottom: 2px solid transparent; } .sidebar nav a[aria-current="page"] { border-bottom-color: var(--accent); } .nav-group
|
|
197
|
+
@media (max-width: 640px) { .shell { display: block; padding: 0 16px; } .sidebar { position: static; height: auto; padding: 20px 0 14px; border-right: 0; border-bottom: 1px solid var(--border); } .sidebar-brand { font-size: 20px; width: fit-content; } .sidebar-brand .brand-caption { margin-top: 4px; } .sidebar nav { display: flex; flex-direction: row; flex-wrap: wrap; gap: 4px; margin-top: 16px; } .sidebar nav a { padding: 9px 10px; font-size: 12px; border-left: 0; border-bottom: 2px solid transparent; } .sidebar nav a[aria-current="page"] { border-bottom-color: var(--accent); } .nav-group { display: none; } .topbar { min-height: 62px; justify-content: flex-start; } .topbar-actions { justify-content: flex-start; gap: 9px; } .intro { padding: 24px 0 18px; } .panel, .lower { padding: 17px; } .section-actions > label { width: 100%; } .stats { gap: 12px; } }
|
|
192
198
|
|
|
193
199
|
/* Keep forms aligned with the existing dashboard controls. */
|
|
194
200
|
.dashboard-section + .client-overview { margin-top: 10px; }
|
|
@@ -234,6 +240,25 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
234
240
|
.appearance-select { width:100%; max-width:100%; min-width:0; height:36px; box-sizing:border-box; border-radius:2px; padding:0 10px; font-size:12px; }
|
|
235
241
|
.appearance-note { color:var(--subtle); margin:17px 0 0; font-size:12px; line-height:1.7; }
|
|
236
242
|
.appearance-animation { margin-top:22px; border-top:1px solid var(--border); padding-top:18px; }
|
|
243
|
+
.terminal-animation-toggle { border-bottom:0; }
|
|
244
|
+
.sidebar nav a { display:flex; align-items:center; gap:10px; }
|
|
245
|
+
.nav-icon { width:17px; height:17px; flex:none; fill:none; stroke:currentColor; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; }
|
|
246
|
+
#source-detail { display:flex; flex-wrap:wrap; gap:5px 22px; }
|
|
247
|
+
.version-heading, .install-command-heading { display:flex; align-items:center; justify-content:space-between; gap:14px; flex-wrap:wrap; }
|
|
248
|
+
.version-heading h2 { margin:0; }
|
|
249
|
+
.version-list { margin:18px 0 0; }
|
|
250
|
+
.version-list > div { display:grid; grid-template-columns:minmax(110px,1fr) auto minmax(150px,1fr); align-items:baseline; gap:16px; padding:14px 0; border-bottom:1px solid var(--border); }
|
|
251
|
+
.version-list dt { font-size:12px; }
|
|
252
|
+
.version-list dd { margin:0; }
|
|
253
|
+
.version-list dd:nth-child(2) { font-size:18px; font-weight:650; color:var(--strong); }
|
|
254
|
+
.version-list dd:last-child { text-align:right; }
|
|
255
|
+
.update-command { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:12px; padding:12px; margin-top:16px; background:var(--page); border:1px solid var(--border); }
|
|
256
|
+
.update-command code { overflow-wrap:anywhere; }
|
|
257
|
+
.update-install { margin-top:20px; padding-top:16px; border-top:1px solid var(--border); }
|
|
258
|
+
.update-install > summary { color:var(--heading); font-size:12px; }
|
|
259
|
+
.install-command-heading { margin-top:16px; }
|
|
260
|
+
.install-command { white-space:pre-wrap; overflow-wrap:anywhere; word-break:break-word; font-size:12px; line-height:1.75; padding:14px; background:var(--page); border:1px solid var(--border); }
|
|
261
|
+
@media(max-width:700px) { .version-list > div { grid-template-columns:1fr auto; gap:8px; } .version-list dd:last-child { grid-column:1/-1; text-align:left; } }
|
|
237
262
|
.appearance-animation > summary { color:var(--heading); font-size:12px; font-weight:700; }
|
|
238
263
|
.terminal-sample { --sample-bg:#0F151D; --sample-text:#DFE7F2; --sample-muted:#A2B0C2; --sample-line:#304054; --sample-logo:#A6F5A8; --sample-table:#DFE7F2; --sample-motion:#84E99E; padding:16px; margin-top:20px; border:1px solid var(--sample-line); border-radius:2px; background:var(--sample-bg); color:var(--sample-text); }
|
|
239
264
|
.terminal-sample[data-terminal-palette="klein"] { --sample-logo:#4C9FFF; --sample-table:#4C9FFF; --sample-motion:#4C9FFF; }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -15,7 +15,8 @@ const text = (id, key, values) => { localize(element(id), key, values); };
|
|
|
15
15
|
const finite = (value) => value !== null && value !== undefined && Number.isFinite(Number(value));
|
|
16
16
|
const number = (value) => finite(value) ? Math.max(0, Math.round(Number(value))).toLocaleString() : "—";
|
|
17
17
|
const mib = (value) => finite(value) ? `${(Number(value) / 1048576).toFixed(1)} MiB` : "—";
|
|
18
|
-
const viewHelpers = { element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator: globalThis.navigator
|
|
18
|
+
const viewHelpers = { element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator: globalThis.navigator,
|
|
19
|
+
motionAllowed: () => !reducedMotion.matches && document.visibilityState === "visible" && element("usage-analytics").open && element("model-usage").open && !element("model-usage").closest("[hidden]") };
|
|
19
20
|
const { render, renderProviders, renderFailures, renderContext } = globalThis.ccdxDashboardStatus.create(viewHelpers);
|
|
20
21
|
const usageView = globalThis.ccdxDashboardUsage.create(viewHelpers);
|
|
21
22
|
const { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay } = usageView;
|
|
@@ -104,6 +105,9 @@ new IntersectionObserver(([entry]) => {
|
|
|
104
105
|
}).observe(element("animation-options"));
|
|
105
106
|
document.addEventListener("visibilitychange", syncAnimationPreview);
|
|
106
107
|
reducedMotion.addEventListener("change", syncAnimationPreview);
|
|
108
|
+
reducedMotion.addEventListener("change", () => { if (reducedMotion.matches) usageView.stopMotion(); });
|
|
109
|
+
document.addEventListener("visibilitychange", () => { if (document.visibilityState !== "visible") usageView.stopMotion(); });
|
|
110
|
+
new IntersectionObserver(([entry]) => usageView.setChartVisible(entry.isIntersecting)).observe(element("daily-bars"));
|
|
107
111
|
|
|
108
112
|
function buildAnimationOptions(data) {
|
|
109
113
|
const container = element("animation-options");
|
|
@@ -362,15 +366,22 @@ for (const [key, ids] of [["auth", ["account-authorization"]], ["status", ["clie
|
|
|
362
366
|
}));
|
|
363
367
|
}
|
|
364
368
|
|
|
369
|
+
const updateView = globalThis.ccdxDashboardUpdates.create(viewHelpers);
|
|
365
370
|
const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
366
371
|
visible: () => document.visibilityState === "visible",
|
|
367
372
|
onState: ({ pendingKeys }) => {
|
|
368
|
-
//
|
|
369
|
-
const busy = pendingKeys.some(key => key !== "auth");
|
|
373
|
+
// Account and release reads must not block normal dashboard refreshes.
|
|
374
|
+
const busy = pendingKeys.some(key => key !== "auth" && key !== "updates");
|
|
370
375
|
element("refresh").disabled = busy;
|
|
371
376
|
element("refresh").setAttribute("aria-busy", String(busy));
|
|
372
377
|
},
|
|
373
378
|
resources: {
|
|
379
|
+
updates: {
|
|
380
|
+
visible: () => !element("version-updates").closest("[hidden]"),
|
|
381
|
+
load: ({ signal }) => readDashboard("/_ccdx/ui/updates", { signal, timeout: 20000, source: "release_status" }),
|
|
382
|
+
apply: updateView.render,
|
|
383
|
+
state: updateView.state,
|
|
384
|
+
},
|
|
374
385
|
status: {
|
|
375
386
|
visible: () => true,
|
|
376
387
|
load: async ({ signal }) => {
|
|
@@ -509,7 +520,7 @@ element("auto-refresh").addEventListener("click", () => {
|
|
|
509
520
|
try { localStorage.setItem(autoRefreshKey, dashboardRefresh.automatic ? "on" : "off"); } catch { /* Keep the current choice. */ }
|
|
510
521
|
});
|
|
511
522
|
document.addEventListener("visibilitychange", () => dashboardRefresh.visibilityChanged());
|
|
512
|
-
window.addEventListener("pagehide", () => { dashboardRefresh.suspend(); stopAnimationPreview(); });
|
|
523
|
+
window.addEventListener("pagehide", () => { dashboardRefresh.suspend(); stopAnimationPreview();usageView.stopMotion(); });
|
|
513
524
|
window.addEventListener("pageshow", () => { dashboardRefresh.resume(); syncAnimationPreview(); });
|
|
514
525
|
|
|
515
526
|
for (const [id, key] of [["account-authorization", "auth"], ["client-features", "status"], ["request-context", "status"], ["recent-failures", "status"], ["upstream-models", "models"], ["model-usage", "usage"]]) {
|
|
@@ -522,21 +533,16 @@ for (const [id, key] of [["account-authorization", "auth"], ["client-features",
|
|
|
522
533
|
}
|
|
523
534
|
|
|
524
535
|
element("save-animation").addEventListener("click", saveAnimation);
|
|
536
|
+
element("check-updates").addEventListener("click", () => dashboardRefresh.refresh("updates", { force: true }));
|
|
525
537
|
element("animation-settings").addEventListener("toggle", () => {
|
|
526
|
-
element("open-animation").setAttribute("aria-expanded", String(element("animation-settings").open));
|
|
527
538
|
if (element("animation-settings").open) loadAnimation();
|
|
528
539
|
syncAnimationPreview();
|
|
529
540
|
});
|
|
530
|
-
element("open-animation").addEventListener("click", () => {
|
|
531
|
-
const settings = element("animation-settings");
|
|
532
|
-
settings.open = true;
|
|
533
|
-
settings.scrollIntoView({ block: "center" });
|
|
534
|
-
settings.querySelector("summary").focus();
|
|
535
|
-
});
|
|
536
541
|
element("usage-analytics").addEventListener("toggle", () => {
|
|
542
|
+
if (element("usage-analytics").open) usageView.revealChart();else usageView.stopMotion();
|
|
537
543
|
if (element("usage-analytics").open && element("model-usage").open) dashboardRefresh.refresh("usage");
|
|
538
544
|
});
|
|
539
|
-
for (const id of ["analytics-model", "analytics-range", "analytics-metric"]) element(id).addEventListener("change", () => {
|
|
545
|
+
for (const id of ["analytics-model", "analytics-range", "analytics-metric", "analytics-view"]) element(id).addEventListener("change", () => {
|
|
540
546
|
renderAnalytics();
|
|
541
547
|
if (usageView.data && usageView.selectedDate) renderUsageTable();
|
|
542
548
|
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const stable = value => typeof value === "string" && /^(0|[1-9]\d{0,14})\.(0|[1-9]\d{0,14})\.(0|[1-9]\d{0,14})$/.test(value) ? value : null;
|
|
3
|
+
function installationCommand(platform, version, latestVersion) {
|
|
4
|
+
const current = stable(version), latest = stable(latestVersion);
|
|
5
|
+
if (latest && (!current || ([0, 1, 2].map(index => Number(latest.split(".")[index]) - Number(current.split(".")[index])).find(value => value !== 0) || 0) > 0)) version = latest;
|
|
6
|
+
if (!stable(version)) return "";
|
|
7
|
+
const base = `https://github.com/DaleXiao/codex-copilot-dx/releases/download/v${version}`;
|
|
8
|
+
if (platform === "windows") return `$ccdxInstallDir = Join-Path ([IO.Path]::GetTempPath()) ("ccdx-install-" + [guid]::NewGuid().ToString("N"))
|
|
9
|
+
New-Item -ItemType Directory -Path $ccdxInstallDir -ErrorAction Stop | Out-Null
|
|
10
|
+
try {
|
|
11
|
+
$ccdxInstaller = Join-Path $ccdxInstallDir "install.ps1"
|
|
12
|
+
Invoke-WebRequest -UseBasicParsing -Uri "${base}/install.ps1" -OutFile $ccdxInstaller -TimeoutSec 300 -ErrorAction Stop
|
|
13
|
+
& $ccdxInstaller
|
|
14
|
+
} finally {
|
|
15
|
+
Remove-Item -LiteralPath $ccdxInstallDir -Recurse -Force
|
|
16
|
+
}`;
|
|
17
|
+
return `(
|
|
18
|
+
set -e
|
|
19
|
+
ccdx_install_dir="$(mktemp -d)"
|
|
20
|
+
trap 'rm -rf "$ccdx_install_dir"' EXIT
|
|
21
|
+
curl --fail --location --proto '=https' --proto-redir '=https' --connect-timeout 20 --max-time 300 \\
|
|
22
|
+
${base}/install.sh \\
|
|
23
|
+
--output "$ccdx_install_dir/install.sh"
|
|
24
|
+
sh "$ccdx_install_dir/install.sh"
|
|
25
|
+
)`;
|
|
26
|
+
}
|
|
27
|
+
function create({ element, localize, navigator }) {
|
|
28
|
+
let snapshot = null, platform = "macos";
|
|
29
|
+
const date = value => typeof value === "string" && Number.isFinite(Date.parse(value)) ? value.slice(0, 10) : null;
|
|
30
|
+
function install() {
|
|
31
|
+
const command = installationCommand(platform, snapshot?.current?.version, snapshot?.latest?.version);
|
|
32
|
+
element("install-command").textContent = command;
|
|
33
|
+
element("copy-install").disabled = !command;
|
|
34
|
+
element("install-shell").textContent = platform === "windows" ? "Windows · PowerShell" : "macOS · Terminal";
|
|
35
|
+
element("install-windows-policy").hidden = platform !== "windows";
|
|
36
|
+
}
|
|
37
|
+
function render(data) {
|
|
38
|
+
snapshot = data;
|
|
39
|
+
const checked = data.status === "checked", latest = stable(data.latest?.version), current = stable(data.current?.version);
|
|
40
|
+
element("update-current-version").textContent = current ? `v${current}` : "—";
|
|
41
|
+
const currentDate = date(data.current?.published_at), latestDate = date(data.latest?.published_at);
|
|
42
|
+
localize(element("update-current-date"), currentDate ? "released_date" : "release_date_unknown", { date: currentDate });
|
|
43
|
+
element("update-latest-row").hidden = !latest || checked && !data.update_available;
|
|
44
|
+
localize(element("update-latest-row").querySelector("dt"), checked ? "available_update" : "last_known_version");
|
|
45
|
+
element("update-latest-version").textContent = latest ? `v${latest}` : "—";
|
|
46
|
+
localize(element("update-latest-date"), latestDate ? "released_date" : "release_date_unknown", { date: latestDate });
|
|
47
|
+
localize(element("update-state"), checked ? data.update_available ? "new_version_available" : "already_latest" : data.status === "rate_limited" ? "update_rate_limited" : "update_check_failed");
|
|
48
|
+
element("update-command-row").hidden = checked && !data.update_available;
|
|
49
|
+
const time = typeof data.checked_at === "string" && Number.isFinite(Date.parse(data.checked_at)) ? new Date(data.checked_at).toLocaleString() : "—";
|
|
50
|
+
localize(element("update-checked"), checked ? "update_checked_time" : "update_attempted_time", { time });
|
|
51
|
+
install();
|
|
52
|
+
}
|
|
53
|
+
function state(value) {
|
|
54
|
+
element("check-updates").disabled = Boolean(value.pending);
|
|
55
|
+
localize(element("check-updates"), value.pending ? "checking_updates" : "check_updates");
|
|
56
|
+
if (value.error) {
|
|
57
|
+
render({ ...snapshot, status: "unavailable", checked_at: new Date().toISOString(), current: snapshot?.current || { version: stable(element("version").textContent.replace(/^v/, "")) } });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const button of document.querySelectorAll("[data-install-platform]")) button.addEventListener("click", () => {
|
|
61
|
+
platform = button.dataset.installPlatform;
|
|
62
|
+
for (const item of document.querySelectorAll("[data-install-platform]")) item.setAttribute("aria-pressed", String(item === button));
|
|
63
|
+
install();
|
|
64
|
+
});
|
|
65
|
+
for (const [button, target] of [["copy-update", "update-command"], ["copy-install", "install-command"]]) element(button).addEventListener("click", async () => {
|
|
66
|
+
try { await navigator.clipboard.writeText(element(target).textContent);localize(element("update-copy-note"), "copied"); }
|
|
67
|
+
catch { localize(element("update-copy-note"), "update_copy_unavailable"); }
|
|
68
|
+
});
|
|
69
|
+
element("copy-install").disabled = true;
|
|
70
|
+
return { render, state };
|
|
71
|
+
}
|
|
72
|
+
globalThis.ccdxDashboardUpdates = { create, installationCommand };
|
|
73
|
+
})();
|
package/src/dashboard/usage.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
function
|
|
2
|
+
function curvePath(points) {
|
|
3
|
+
return points.map(([x, y], index) => {
|
|
4
|
+
if (!index) return `M${x},${y}`;
|
|
5
|
+
const [previousX, previousY] = points[index - 1], middle = (previousX + x) / 2;
|
|
6
|
+
return `C${middle},${previousY} ${middle},${y} ${x},${y}`;
|
|
7
|
+
}).join(" ");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function create({ element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator, motionAllowed = () => false }) {
|
|
3
11
|
function usageValues(row) {
|
|
4
12
|
const rate = Number.isFinite(row.cache_hit_rate) && row.cache_hit_rate >= 0 && row.cache_hit_rate <= 1
|
|
5
13
|
? `${row.cache_hit_rate_partial ? "~" : ""}${(row.cache_hit_rate * 100).toFixed(1)}%` : "—";
|
|
@@ -7,8 +15,92 @@
|
|
|
7
15
|
}
|
|
8
16
|
|
|
9
17
|
let usageData = null;
|
|
10
|
-
let analyticsSignature;
|
|
18
|
+
let analyticsSignature, calendarSignature;
|
|
11
19
|
let selectedUsageDate = "";
|
|
20
|
+
let dailySignature, dailySelection, chartVisible = false, motionPending = false;
|
|
21
|
+
let motionTargets = [];
|
|
22
|
+
const animations = new Set();
|
|
23
|
+
|
|
24
|
+
function stopMotion() {
|
|
25
|
+
for (const animation of animations) animation.cancel();
|
|
26
|
+
animations.clear();motionPending = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function playMotion() {
|
|
30
|
+
if (!motionPending || !chartVisible || !motionAllowed()) return;
|
|
31
|
+
stopMotion();
|
|
32
|
+
for (const { node, line, point } of motionTargets) {
|
|
33
|
+
if (!node.animate) continue;
|
|
34
|
+
const animation = node.animate(point ? [{ opacity: 0 }, { opacity: 1 }] : line
|
|
35
|
+
? [{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }]
|
|
36
|
+
: [{ transform: "scaleY(0)" }, { transform: "scaleY(1)" }],
|
|
37
|
+
{ duration: point ? 200 : line ? 600 : 450, easing: "cubic-bezier(0.25, 1, 0.5, 1)" });
|
|
38
|
+
animations.add(animation);
|
|
39
|
+
animation.finished?.then(() => animations.delete(animation), () => animations.delete(animation));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function revealChart() { motionPending = true;playMotion(); }
|
|
44
|
+
function setChartVisible(value) { chartVisible = value;if (value) playMotion();else if (animations.size) stopMotion(); }
|
|
45
|
+
|
|
46
|
+
function svgNode(tag, attributes) {
|
|
47
|
+
const node = document.createElementNS("http://www.w3.org/2000/svg", tag);
|
|
48
|
+
for (const [key, value] of Object.entries(attributes)) node.setAttribute(key, String(value));
|
|
49
|
+
return node;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function renderDaily(daily, model, maximum) {
|
|
53
|
+
const line = element("analytics-view").value === "line";
|
|
54
|
+
const signature = JSON.stringify([daily, model, line]);
|
|
55
|
+
if (signature === dailySignature && selectedUsageDate === dailySelection) return;
|
|
56
|
+
const changed = signature !== dailySignature;
|
|
57
|
+
dailySignature = signature;dailySelection = selectedUsageDate;
|
|
58
|
+
stopMotion();motionTargets = [];
|
|
59
|
+
const chart = element("daily-bars");
|
|
60
|
+
chart.className = line ? "daily-bars daily-lines" : "daily-bars";
|
|
61
|
+
chart.replaceChildren();
|
|
62
|
+
if (line) {
|
|
63
|
+
const plot = svgNode("svg", { class: "daily-line-plot", viewBox: "0 0 1000 130", preserveAspectRatio: "none", "aria-hidden": "true", focusable: "false" });
|
|
64
|
+
for (const key of ["input_tokens", "output_tokens"]) {
|
|
65
|
+
let segment = [];
|
|
66
|
+
const color = key === "input_tokens" ? "curve-input" : "curve-output";
|
|
67
|
+
const flush = () => {
|
|
68
|
+
if (segment.length > 1) {
|
|
69
|
+
const path = svgNode("path", { d: curvePath(segment), class: `daily-curve ${color}`, pathLength: 1, "vector-effect": "non-scaling-stroke" });
|
|
70
|
+
plot.append(path);motionTargets.push({ node: path, line: true });
|
|
71
|
+
} else if (segment.length === 1) {
|
|
72
|
+
const [x, y] = segment[0];
|
|
73
|
+
const circle = svgNode("circle", { cx: x, cy: y, r: 2, class: color, fill: "none", "stroke-width": 2, "vector-effect": "non-scaling-stroke" });
|
|
74
|
+
plot.append(circle);motionTargets.push({ node: circle, point: true });
|
|
75
|
+
}
|
|
76
|
+
segment = [];
|
|
77
|
+
};
|
|
78
|
+
daily.forEach((day, index) => {
|
|
79
|
+
if (!day.available) { flush();return; }
|
|
80
|
+
const point = analyticsPoint(day, model), x = (index + 0.5) / daily.length * 1000, y = 128 - point[key] / maximum * 124;
|
|
81
|
+
segment.push([x, y]);
|
|
82
|
+
});
|
|
83
|
+
flush();
|
|
84
|
+
}
|
|
85
|
+
chart.append(plot);
|
|
86
|
+
}
|
|
87
|
+
for (const day of daily) {
|
|
88
|
+
const point = analyticsPoint(day, model), button = dayButton(day, point);
|
|
89
|
+
button.className = "daily-bar";
|
|
90
|
+
if (!line) {
|
|
91
|
+
const stack = document.createElement("span");stack.className = "bar-stack";
|
|
92
|
+
for (const key of ["output_tokens", "input_tokens"]) {
|
|
93
|
+
const segment = document.createElement("span");
|
|
94
|
+
segment.className = key === "input_tokens" ? "bar-input" : "bar-output";
|
|
95
|
+
segment.style.height = `${point[key] / maximum * 100}%`;
|
|
96
|
+
stack.append(segment);
|
|
97
|
+
}
|
|
98
|
+
button.append(stack);motionTargets.push({ node: stack, line: false });
|
|
99
|
+
}
|
|
100
|
+
chart.append(button);
|
|
101
|
+
}
|
|
102
|
+
motionPending = changed;playMotion();
|
|
103
|
+
}
|
|
12
104
|
|
|
13
105
|
function renderUsageTable() {
|
|
14
106
|
const day = selectedUsageDate && usageData.analytics?.days.find((entry) => entry.date === selectedUsageDate);
|
|
@@ -61,7 +153,8 @@
|
|
|
61
153
|
const analytics = usageData?.analytics;
|
|
62
154
|
if (!analytics) return;
|
|
63
155
|
const model = element("analytics-model").value;
|
|
64
|
-
const
|
|
156
|
+
const commonSignature = JSON.stringify([analytics, model, element("analytics-range").value, element("analytics-metric").value, selectedUsageDate]);
|
|
157
|
+
const signature = `${commonSignature}:${element("analytics-view").value}`;
|
|
65
158
|
if (signature === analyticsSignature) return;
|
|
66
159
|
analyticsSignature = signature;
|
|
67
160
|
const days = analytics.days;
|
|
@@ -70,22 +163,11 @@
|
|
|
70
163
|
const point = analyticsPoint(day, model);
|
|
71
164
|
return point.input_tokens + point.output_tokens;
|
|
72
165
|
}));
|
|
73
|
-
|
|
74
|
-
bars.replaceChildren();
|
|
75
|
-
for (const day of daily) {
|
|
76
|
-
const point = analyticsPoint(day, model);
|
|
77
|
-
const button = dayButton(day, point);
|
|
78
|
-
button.className = "daily-bar";
|
|
79
|
-
for (const key of ["output_tokens", "input_tokens"]) {
|
|
80
|
-
const segment = document.createElement("span");
|
|
81
|
-
segment.className = key === "input_tokens" ? "bar-input" : "bar-output";
|
|
82
|
-
segment.style.height = `${point[key] / maximum * 100}%`;
|
|
83
|
-
button.append(segment);
|
|
84
|
-
}
|
|
85
|
-
bars.append(button);
|
|
86
|
-
}
|
|
166
|
+
renderDaily(daily, model, maximum);
|
|
87
167
|
text("daily-from", daily[0].date);
|
|
88
168
|
text("daily-to", analytics.to);
|
|
169
|
+
if (commonSignature === calendarSignature) return;
|
|
170
|
+
calendarSignature = commonSignature;
|
|
89
171
|
const metric = element("analytics-metric").value;
|
|
90
172
|
const value = (day) => {
|
|
91
173
|
const point = analyticsPoint(day, model);
|
|
@@ -157,7 +239,7 @@
|
|
|
157
239
|
text("analytics-updated", "updated_time", { time: new Date().toLocaleTimeString() });
|
|
158
240
|
}
|
|
159
241
|
}
|
|
160
|
-
return { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay, usageValues, get data() { return usageData; }, get selectedDate() { return selectedUsageDate; } };
|
|
242
|
+
return { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay, usageValues, setChartVisible, revealChart, stopMotion, get data() { return usageData; }, get selectedDate() { return selectedUsageDate; } };
|
|
161
243
|
}
|
|
162
|
-
globalThis.ccdxDashboardUsage = { create };
|
|
244
|
+
globalThis.ccdxDashboardUsage = { create, curvePath };
|
|
163
245
|
})();
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -143,6 +143,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
143
143
|
providerCatalogFn,
|
|
144
144
|
providerStateFn,
|
|
145
145
|
providerAccountsFn,
|
|
146
|
+
updateStatusFn,
|
|
146
147
|
serviceControl,
|
|
147
148
|
applyAnimation,
|
|
148
149
|
} = {}) {
|
|
@@ -163,6 +164,14 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
163
164
|
return;
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
if (pathname === "/_ccdx/ui/updates") {
|
|
168
|
+
if (req.method !== "GET") { sendJson(res, 405, { error: "Use GET" });return; }
|
|
169
|
+
const { dashboardUpdateStatus } = await import("./dashboard-updates.mjs");
|
|
170
|
+
try { sendJson(res, 200, await (updateStatusFn || dashboardUpdateStatus)()); }
|
|
171
|
+
catch { sendJson(res, 503, { error: "Could not check releases" }); }
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
166
175
|
if (pathname === "/_ccdx/ui/m365/accounts" && req.method === "GET") {
|
|
167
176
|
if (!providerAccountsFn) { sendJson(res, 503, { error: "Account selection requires the updated running service" });return; }
|
|
168
177
|
try {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { createNpmReleaseFetch, stableVersion } from "./release-install.mjs";
|
|
6
|
+
import { isVersionGreater } from "./version.mjs";
|
|
7
|
+
import { ADAPTER_VERSION } from "./running-adapter.mjs";
|
|
8
|
+
import { readBoundedResponseText } from "./upstream-body.mjs";
|
|
9
|
+
|
|
10
|
+
const API = "https://api.github.com/repos/DaleXiao/codex-copilot-dx/releases";
|
|
11
|
+
const run = promisify(execFile);
|
|
12
|
+
|
|
13
|
+
async function releaseFetch() {
|
|
14
|
+
const env = process.env, windows = process.platform === "win32", paths = windows ? path.win32 : path;
|
|
15
|
+
const search = Object.entries(env).find(([key]) => key.toLowerCase() === "path")?.[1] || "";
|
|
16
|
+
const npm = search.split(windows ? ";" : ":").filter(Boolean)
|
|
17
|
+
.map(directory => paths.join(directory.replace(/^"|"$/g, ""), windows ? "npm.cmd" : "npm"))
|
|
18
|
+
.find(file => { try { return fs.statSync(file).isFile(); } catch { return false; } });
|
|
19
|
+
if (!npm) throw new Error("npm unavailable");
|
|
20
|
+
const cli = windows ? paths.join(paths.dirname(npm), "node_modules", "npm", "bin", "npm-cli.js") : fs.realpathSync(npm);
|
|
21
|
+
// Read only the installer's named network settings, off the service event loop.
|
|
22
|
+
const { stdout } = await run(process.execPath, [cli, "config", "get", "--global", "https-proxy", "proxy", "noproxy", "cafile", "strict-ssl", "offline"],
|
|
23
|
+
{ env, encoding: "utf8", timeout: 5000, maxBuffer: 128 * 1024, windowsHide: true });
|
|
24
|
+
return createNpmReleaseFetch(cli, { env, exec: () => stdout });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createDashboardUpdateStatus({ currentVersion = ADAPTER_VERSION, fetchFactory = releaseFetch, now = Date.now, timeoutMs = 4000 } = {}) {
|
|
28
|
+
let pending, snapshot, attemptedAt = -Infinity, currentDate = null;
|
|
29
|
+
const current = () => ({ version: currentVersion, published_at: currentDate });
|
|
30
|
+
async function metadata(fetchImpl, suffix, expectedVersion) {
|
|
31
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
32
|
+
const response = await fetchImpl(`${API}/${suffix}`, { signal, redirect: "error",
|
|
33
|
+
headers: { Accept: "application/vnd.github+json", "User-Agent": "codex-copilot-dx", "X-GitHub-Api-Version": "2022-11-28" } });
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
await response.body?.cancel();
|
|
36
|
+
throw Object.assign(new Error("Release metadata unavailable"), { code: [403, 429].includes(response.status) ? "rate_limited" : "unavailable" });
|
|
37
|
+
}
|
|
38
|
+
const value = JSON.parse(await readBoundedResponseText(response, { maxBytes: 128 * 1024, signal, label: "Release metadata" }));
|
|
39
|
+
const version = stableVersion(value.tag_name);
|
|
40
|
+
if (!version || value.draft !== false || value.prerelease !== false || expectedVersion && version !== expectedVersion) throw new Error("Invalid stable release");
|
|
41
|
+
const date = typeof value.published_at === "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/.test(value.published_at) && Number.isFinite(Date.parse(value.published_at))
|
|
42
|
+
&& new Date(value.published_at).toISOString().replace(".000Z", "Z") === value.published_at
|
|
43
|
+
? new Date(value.published_at).toISOString() : null;
|
|
44
|
+
return { version, published_at: date };
|
|
45
|
+
}
|
|
46
|
+
return async () => {
|
|
47
|
+
if (pending) return structuredClone(await pending);
|
|
48
|
+
const ttl = snapshot?.status === "checked" ? 5 * 60 * 1000 : 60 * 1000;
|
|
49
|
+
if (snapshot && now() - attemptedAt < ttl) return structuredClone(snapshot);
|
|
50
|
+
attemptedAt = now();
|
|
51
|
+
pending = (async () => {
|
|
52
|
+
try {
|
|
53
|
+
const fetchImpl = await fetchFactory();
|
|
54
|
+
const latest = await metadata(fetchImpl, "latest");
|
|
55
|
+
if (latest.version === currentVersion) currentDate = latest.published_at;
|
|
56
|
+
else if (!currentDate && stableVersion(currentVersion)) {
|
|
57
|
+
try { currentDate = (await metadata(fetchImpl, `tags/v${currentVersion}`, currentVersion)).published_at; } catch { /* The date can be unknown without hiding a verified newer release. */ }
|
|
58
|
+
}
|
|
59
|
+
snapshot = { source: "release_status", status: "checked", current: current(), latest,
|
|
60
|
+
update_available: isVersionGreater(latest.version, currentVersion), checked_at: new Date(now()).toISOString(), last_success_at: new Date(now()).toISOString() };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
snapshot = { source: "release_status", status: error.code === "rate_limited" ? "rate_limited" : "unavailable", current: current(),
|
|
63
|
+
latest: snapshot?.latest || null, update_available: false, checked_at: new Date(now()).toISOString(), last_success_at: snapshot?.last_success_at || null };
|
|
64
|
+
}
|
|
65
|
+
return snapshot;
|
|
66
|
+
})();
|
|
67
|
+
try { return structuredClone(await pending); } finally { pending = null; }
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const dashboardUpdateStatus = createDashboardUpdateStatus();
|
package/src/dashboard.mjs
CHANGED
|
@@ -8,6 +8,7 @@ const ASSETS = new Map([
|
|
|
8
8
|
["/language.js", ["./dashboard/language.js", "text/javascript; charset=utf-8"]],
|
|
9
9
|
["/ui.js", ["./dashboard/ui.js", "text/javascript; charset=utf-8"]],
|
|
10
10
|
["/console.js", ["./dashboard/console.js", "text/javascript; charset=utf-8"]],
|
|
11
|
+
["/updates.js", ["./dashboard/updates.js", "text/javascript; charset=utf-8"]],
|
|
11
12
|
["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
|
|
12
13
|
["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
|
|
13
14
|
["/refresh.js", ["./dashboard/refresh.js", "text/javascript; charset=utf-8"]],
|
package/src/optional-routes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/status.js", "/usage.js", "/ui.js", "/console.js"]);
|
|
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"]);
|
|
1
|
+
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/status.js", "/usage.js", "/ui.js", "/console.js", "/updates.js"]);
|
|
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"]);
|
|
3
3
|
|
|
4
4
|
export function isOptionalRoute(method, pathname) {
|
|
5
5
|
return DASHBOARD_API_PATHS.has(pathname) || pathname === "/mcp/image"
|
package/src/usage-store.mjs
CHANGED
|
@@ -27,7 +27,12 @@ let writeFailures = 0;
|
|
|
27
27
|
const runtimeUsage = { since: new Date().toISOString(), records: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, partial_records: 0 };
|
|
28
28
|
const runtimeUsageByProvider = new Map();
|
|
29
29
|
|
|
30
|
-
export function runtimeUsageSnapshot() {
|
|
30
|
+
export function runtimeUsageSnapshot() {
|
|
31
|
+
const snapshot = totals => ({ ...totals,
|
|
32
|
+
cache_hit_rate: totals.records > (totals.cache_hit_unknown_requests || 0) ? usageCacheHitRate(totals) : null,
|
|
33
|
+
cache_hit_rate_partial: (totals.cache_hit_unknown_requests || 0) > 0 });
|
|
34
|
+
return { ...snapshot(runtimeUsage), by_provider: Object.fromEntries([...runtimeUsageByProvider].map(([id, totals]) => [id, snapshot(totals)])) };
|
|
35
|
+
}
|
|
31
36
|
|
|
32
37
|
export function usageLoggingStats() {
|
|
33
38
|
return { pending_records: pendingRecords, pending_bytes: pendingBytes, dropped_records: droppedRecords,
|
|
@@ -186,14 +191,17 @@ function scheduleUsageWriteDrain() {
|
|
|
186
191
|
export function recordUsage(record) {
|
|
187
192
|
if (!record) return Promise.resolve();
|
|
188
193
|
const usage = record.usage || {};
|
|
194
|
+
const { cached, unknown, invalid } = usageCacheEvidence(usage);
|
|
189
195
|
const provider = usageProvider(record), label = runtimeUsageByProvider.has(provider) || runtimeUsageByProvider.size < 16 ? provider : "other";
|
|
190
196
|
if (!runtimeUsageByProvider.has(label)) runtimeUsageByProvider.set(label, { records: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0, partial_records: 0 });
|
|
191
197
|
for (const totals of [runtimeUsage, runtimeUsageByProvider.get(label)]) {
|
|
192
198
|
totals.records++;
|
|
193
|
-
for (const [target, value] of [["input_tokens", usage.input_tokens], ["cached_input_tokens",
|
|
199
|
+
for (const [target, value] of [["input_tokens", usage.input_tokens], ["cached_input_tokens", cached], ["output_tokens", usage.output_tokens]]) {
|
|
194
200
|
if (Number.isFinite(value) && value >= 0) totals[target] += value;
|
|
195
201
|
}
|
|
196
|
-
if (!Number.isFinite(usage.input_tokens) || !Number.isFinite(usage.output_tokens) ||
|
|
202
|
+
if (!Number.isFinite(usage.input_tokens) || !Number.isFinite(usage.output_tokens) || cached === undefined) totals.partial_records++;
|
|
203
|
+
if (unknown) totals.cache_hit_unknown_requests = (totals.cache_hit_unknown_requests || 0) + 1;
|
|
204
|
+
if (invalid) totals.cache_hit_invalid_requests = (totals.cache_hit_invalid_requests || 0) + 1;
|
|
197
205
|
}
|
|
198
206
|
if (process.env.CCDX_DISABLE_USAGE === "1") return Promise.resolve();
|
|
199
207
|
const filePath = usageLogPath();
|
|
@@ -320,13 +328,7 @@ export function summarizeUsage(records, { provider = "" } = {}) {
|
|
|
320
328
|
const modelTotals = summary.byModel[model];
|
|
321
329
|
modelTotals.requests += 1;
|
|
322
330
|
addUsageTotals(modelTotals, record.usage);
|
|
323
|
-
const
|
|
324
|
-
const cached = cacheReadTokens(record.usage || {});
|
|
325
|
-
const cacheCounts = [record.usage?.cached_input_tokens, record.usage?.cache_read_input_tokens];
|
|
326
|
-
const unknown = !Number.isFinite(input) || input < 0 || !Number.isFinite(cached) || cached < 0 || cached > input;
|
|
327
|
-
const invalid = (input != null && (!Number.isFinite(input) || input < 0))
|
|
328
|
-
|| cacheCounts.some(value => value != null && (!Number.isFinite(value) || value < 0))
|
|
329
|
-
|| (Number.isFinite(input) && Number.isFinite(cached) && cached > input);
|
|
331
|
+
const { unknown, invalid } = usageCacheEvidence(record.usage || {});
|
|
330
332
|
const qualified = `${source} / ${model}`;
|
|
331
333
|
if (!Object.hasOwn(summary.bySourceModel, qualified)) summary.bySourceModel[qualified] = { requests: 0 };
|
|
332
334
|
const sourceTotals = summary.bySourceModel[qualified];
|
|
@@ -424,3 +426,12 @@ export function usageCacheHitRate(usage = {}) {
|
|
|
424
426
|
|| !Number.isFinite(cached) || cached < 0 || cached > input) return null;
|
|
425
427
|
return cached / input;
|
|
426
428
|
}
|
|
429
|
+
|
|
430
|
+
function usageCacheEvidence(usage) {
|
|
431
|
+
const input = usage.input_tokens, cached = cacheReadTokens(usage);
|
|
432
|
+
const unknown = !Number.isFinite(input) || input < 0 || !Number.isFinite(cached) || cached < 0 || cached > input;
|
|
433
|
+
const invalid = (input != null && (!Number.isFinite(input) || input < 0))
|
|
434
|
+
|| [usage.cached_input_tokens, usage.cache_read_input_tokens].some(value => value != null && (!Number.isFinite(value) || value < 0))
|
|
435
|
+
|| (Number.isFinite(input) && Number.isFinite(cached) && cached > input);
|
|
436
|
+
return { cached, unknown, invalid };
|
|
437
|
+
}
|