codex-copilot-dx 0.9.31 → 0.9.33
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 +5 -5
- package/docs/ARCHITECTURE.md +34 -1
- package/docs/REFERENCE.md +25 -2
- package/package.json +3 -2
- package/src/adapter.mjs +13 -6
- package/src/auth-credentials.mjs +242 -0
- package/src/auth-device-flow.mjs +210 -0
- package/src/auth-profile.mjs +2 -2
- package/src/auth.mjs +10 -450
- package/src/bounded-file.mjs +28 -0
- package/src/cli-status.mjs +1 -0
- package/src/credential-permissions.mjs +21 -0
- package/src/dashboard/index.html +2 -0
- package/src/dashboard/language.js +2 -0
- package/src/dashboard/status.js +192 -0
- package/src/dashboard/ui.js +6 -343
- package/src/dashboard/usage.js +161 -0
- package/src/dashboard-api.mjs +5 -4
- package/src/dashboard.mjs +2 -0
- package/src/doctor.mjs +20 -0
- package/src/http-transport.mjs +7 -0
- package/src/image-provider-config.mjs +2 -2
- package/src/live-models.mjs +16 -0
- package/src/model-cache.mjs +2 -1
- package/src/native-prediction-profile.mjs +2 -1
- package/src/package-update.mjs +44 -7
- package/src/response-failures.mjs +7 -0
- package/src/stream-performance.mjs +4 -0
- package/src/user-settings.mjs +2 -2
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
function create({ element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator }) {
|
|
3
|
+
let contextRequests = [];
|
|
4
|
+
let contextCompactions = {};
|
|
5
|
+
let failureSignature;
|
|
6
|
+
let contextSignature;
|
|
7
|
+
|
|
8
|
+
function renderAuth(data, { failed = false } = {}) {
|
|
9
|
+
const account = data.login ? `@${data.login}` : data.id ? `ID ${data.id}` : phrase("account unknown");
|
|
10
|
+
const label = data.reason === "credential_read_failed" ? "UNAVAILABLE"
|
|
11
|
+
: !data.configured ? "NOT CONFIGURED" : !data.valid ? "INVALID" : "SAVED";
|
|
12
|
+
text("auth-account", failed ? "GitHub / {account} / UPDATE FAILED" : label === "SAVED" ? "GitHub / {account} / SAVED" : `GitHub / ${label}`, { account });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function duration(value) {
|
|
16
|
+
if (!finite(value)) return "—";
|
|
17
|
+
const seconds = Math.max(0, Math.round(Number(value) / 1000));
|
|
18
|
+
const days = Math.floor(seconds / 86400);
|
|
19
|
+
const hours = Math.floor((seconds % 86400) / 3600);
|
|
20
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
21
|
+
return days ? `${days}d ${hours}h` : hours ? `${hours}h ${minutes}m` : `${minutes}m`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function renderFailures(recent, recentRequests = []) {
|
|
25
|
+
const signature = JSON.stringify([recent, recentRequests]);
|
|
26
|
+
if (signature === failureSignature) return;
|
|
27
|
+
failureSignature = signature;
|
|
28
|
+
const list = element("failures");
|
|
29
|
+
const expanded = new Set([...list.querySelectorAll("details[open]")].map((item) => item.dataset.key));
|
|
30
|
+
list.replaceChildren();
|
|
31
|
+
const requests = Array.isArray(recentRequests) ? recentRequests.slice(-20) : [];
|
|
32
|
+
const byRequest = new Map(requests.filter((request) => request.request_id).map((request) => [request.request_id, request]));
|
|
33
|
+
const failures = Array.isArray(recent) ? recent.slice(-10).map((failure) => ({ ...failure, timeline: byRequest.get(failure.request_id) })) : [];
|
|
34
|
+
const recorded = new Set(failures.map((failure) => failure.request_id).filter(Boolean));
|
|
35
|
+
for (const request of requests) {
|
|
36
|
+
if (!request.failed || recorded.has(request.request_id)) continue;
|
|
37
|
+
failures.push({ at: request.at, model: request.model, request_id: request.request_id,
|
|
38
|
+
event_type: `request.${request.outcome}`, code: request.origin, timeline: request,
|
|
39
|
+
message: "Request ended without successful completion.", local_message: true, retried: request.upstream_attempts > 1 });
|
|
40
|
+
}
|
|
41
|
+
failures.sort((a, b) => (Date.parse(a.at) || 0) - (Date.parse(b.at) || 0));
|
|
42
|
+
failures.splice(0, Math.max(0, failures.length - 10));
|
|
43
|
+
failures.reverse();
|
|
44
|
+
text("failure-count", "{count} retained / requests + events", { count: failures.length });
|
|
45
|
+
if (!failures.length) {
|
|
46
|
+
const item = document.createElement("li");
|
|
47
|
+
item.className = "empty";
|
|
48
|
+
localize(item, "No recent request failures recorded.");
|
|
49
|
+
list.append(item);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (const failure of failures) {
|
|
53
|
+
const item = document.createElement("li");
|
|
54
|
+
const details = document.createElement("details");
|
|
55
|
+
details.dataset.key = `${failure.at}/${failure.request_id || failure.response_id}/${failure.code}`;
|
|
56
|
+
details.open = expanded.has(details.dataset.key);
|
|
57
|
+
const title = document.createElement("summary");
|
|
58
|
+
localize(title, "{detail} / {retry}", {
|
|
59
|
+
detail: phrase("{time} / {model} / {code}", {
|
|
60
|
+
time: failure.at ? String(failure.at) : phrase("unknown time"),
|
|
61
|
+
model: failure.model ? String(failure.model).slice(0, 80) : phrase("unknown_model"),
|
|
62
|
+
code: failure.code ? String(failure.code).slice(0, 80) : phrase("unknown_error"),
|
|
63
|
+
}),
|
|
64
|
+
retry: phrase(failure.retried ? "retry attempted" : "no retry"),
|
|
65
|
+
});
|
|
66
|
+
const timeline = failure.timeline;
|
|
67
|
+
const timings = timeline?.timings_ms || {};
|
|
68
|
+
const timingText = ["admission", "body", "history", "images", "serialization", "upstream_start", "upstream_headers", "first_output", "last_activity", "terminal", "finished"]
|
|
69
|
+
.filter((key) => finite(timings[key])).map((key) => `${key}=${Number(timings[key]).toFixed(1)}`).join(" / ");
|
|
70
|
+
const fields = { time: failure.at, model: failure.model, event: failure.event_type, code: failure.code,
|
|
71
|
+
message: failure.message, response_id: failure.response_id, upstream_request_id: failure.upstream_request_id,
|
|
72
|
+
retry: failure.retried ? (timeline ? "attempted" : "attempted (outcome not recorded here)") : "not attempted",
|
|
73
|
+
retry_policy: failure.retry_policy, retry_skipped: failure.retry_skipped,
|
|
74
|
+
recovery: failure.recovery ? JSON.stringify(failure.recovery) : undefined,
|
|
75
|
+
request_id: failure.request_id, outcome: timeline?.outcome, origin: failure.origin || timeline?.origin,
|
|
76
|
+
phase: timeline?.phase, http_status: failure.http_status ?? timeline?.http_status, route: failure.route,
|
|
77
|
+
upstream_attempts: timeline?.upstream_attempts,
|
|
78
|
+
timings_ms: timingText };
|
|
79
|
+
const diagnostic = document.createElement("dl");
|
|
80
|
+
diagnostic.className = "failure-detail";
|
|
81
|
+
const lines = [];
|
|
82
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
83
|
+
if (value === undefined || value === null || value === "") continue;
|
|
84
|
+
const label = document.createElement("dt");
|
|
85
|
+
const content = document.createElement("dd");
|
|
86
|
+
localize(label, key);
|
|
87
|
+
const rawValue = String(value).slice(0, 500);
|
|
88
|
+
if (key === "retry" || (key === "message" && failure.local_message)) localize(content, rawValue);
|
|
89
|
+
else content.textContent = rawValue;
|
|
90
|
+
diagnostic.append(label, content);
|
|
91
|
+
lines.push(`${key}: ${rawValue}`);
|
|
92
|
+
}
|
|
93
|
+
const copy = document.createElement("button");
|
|
94
|
+
copy.type = "button";
|
|
95
|
+
localize(copy, "Copy diagnostic");
|
|
96
|
+
copy.addEventListener("click", async () => {
|
|
97
|
+
try {
|
|
98
|
+
await navigator.clipboard.writeText(lines.join("\n"));
|
|
99
|
+
localize(copy, "Copied");
|
|
100
|
+
} catch { localize(copy, "Copy unavailable"); }
|
|
101
|
+
});
|
|
102
|
+
details.append(title, diagnostic, copy);
|
|
103
|
+
item.append(details);
|
|
104
|
+
list.append(item);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function render(data) {
|
|
109
|
+
text("version", `v${data.version || "?"}`);
|
|
110
|
+
text("uptime", "pid {pid} / uptime {duration}", { pid: number(data.pid), duration: duration(data.uptime_ms) });
|
|
111
|
+
|
|
112
|
+
const copilot = data.copilot || {};
|
|
113
|
+
text("copilot", copilot.account_bound ? "BOUND" : "UNCONFIRMED");
|
|
114
|
+
text("token", copilot.token_cached ? "service token / TTL {duration}" : "service token not cached", { duration: duration(copilot.token_expires_in_ms) });
|
|
115
|
+
|
|
116
|
+
const models = data.models || {};
|
|
117
|
+
text("models", number(models.models));
|
|
118
|
+
text("model-source", "source {source} / live: ccdx models", { source: phrase(String(models.source || "unknown").slice(0, 80)) });
|
|
119
|
+
|
|
120
|
+
const requests = data.requests || {};
|
|
121
|
+
text("requests", number(requests.total));
|
|
122
|
+
text("request-errors", "4xx {client} / 5xx {server} / active {active}", { client: number(requests.status_4xx), server: number(requests.status_5xx), active: number(requests.active) });
|
|
123
|
+
text("body-limits", "raw {raw} / decoded {decoded}", { raw: mib(data.limits?.max_body_bytes), decoded: mib(data.limits?.max_decoded_body_bytes) });
|
|
124
|
+
|
|
125
|
+
const outcomes = data.stream_performance?.by_route?.responses?.terminal_outcomes?.totals || {};
|
|
126
|
+
for (const key of ["completed", "incomplete", "failed", "cancelled"]) text(key, number(outcomes[key]));
|
|
127
|
+
const timing = data.stream_performance?.by_route?.responses || {};
|
|
128
|
+
for (const [id, metric, scale, unit] of [["ttft", timing.ttft_ms, 1, "ms"], ["tpot", timing.tpot_us, timing.tpot_us?.unit === "us" ? 1000 : 1, "ms/token"]]) {
|
|
129
|
+
const value = metric?.samples > 0 && finite(metric.avg) ? `${(Number(metric.avg) / scale).toFixed(1)} ${unit}` : "—";
|
|
130
|
+
text(id, "{value} / {samples} samples", { value, samples: number(metric?.samples) });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const history = data.response_history || {};
|
|
134
|
+
const limit = Number(history.maxBytes || data.limits?.response_history_max_bytes || 0);
|
|
135
|
+
const used = Number(history.bytes || 0);
|
|
136
|
+
text("history", `${mib(used)} / ${mib(limit)}`);
|
|
137
|
+
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) });
|
|
138
|
+
element("history-meter").value = limit > 0 ? Math.min(100, Math.max(0, used / limit * 100)) : 0;
|
|
139
|
+
|
|
140
|
+
const image = data.image_generation;
|
|
141
|
+
text("image", image ? "{count} succeeded" : "NOT INITIALIZED", { count: number(image?.succeeded) });
|
|
142
|
+
text("image-detail", image
|
|
143
|
+
? "active {active} / failed {failed} / delivery failures {delivery}"
|
|
144
|
+
: "Setup state unknown / ccdx image-status", { active: number(image?.active), failed: number(image?.failed), delivery: number(image?.delivery_failures) });
|
|
145
|
+
|
|
146
|
+
renderFailures([...(data.response_failures?.recent || []), ...(data.http_errors?.recent || [])]
|
|
147
|
+
.sort((a, b) => (Date.parse(a.at) || 0) - (Date.parse(b.at) || 0)), data.stream_performance?.recent_requests);
|
|
148
|
+
renderContext(data.stream_performance);
|
|
149
|
+
if (element("prediction-preference")) {
|
|
150
|
+
const prediction = data.client_integrations?.prediction;
|
|
151
|
+
text("prediction-preference", prediction ? prediction.configured ? "Enabled" : "Disabled" : "Unknown");
|
|
152
|
+
text("prediction-bridge", ({ running: "Running", stopped: "Stopped", unavailable: "Unavailable" })[prediction?.bridge] || "Unknown");
|
|
153
|
+
text("prediction-route", prediction?.client_route === "observed" ? "Observed" : "Unknown");
|
|
154
|
+
text("prediction-candidate", "Unknown");
|
|
155
|
+
const note = element("prediction-note");
|
|
156
|
+
if (note) note.textContent = prediction?.reason || "";
|
|
157
|
+
}
|
|
158
|
+
text("updated", "Snapshot {time}", { time: new Date().toLocaleTimeString() });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function renderContext(performance) {
|
|
162
|
+
if (performance !== undefined) {
|
|
163
|
+
contextRequests = Array.isArray(performance?.recent_requests) ? performance.recent_requests.slice(-20).reverse() : [];
|
|
164
|
+
contextCompactions = performance?.by_route?.responses_compact?.terminal_outcomes?.totals || {};
|
|
165
|
+
}
|
|
166
|
+
const body = element("context-body");
|
|
167
|
+
if (!body) return;
|
|
168
|
+
text("context-note", "20 latest finished requests / compactions: {completed} completed, {incomplete} incomplete, {failed} failed", {
|
|
169
|
+
completed: number(contextCompactions.completed), incomplete: number(contextCompactions.incomplete), failed: number(contextCompactions.failed),
|
|
170
|
+
});
|
|
171
|
+
if (element("request-context")?.open === false) return;
|
|
172
|
+
const signature = JSON.stringify(contextRequests);
|
|
173
|
+
if (signature === contextSignature) return;
|
|
174
|
+
contextSignature = signature;
|
|
175
|
+
body.replaceChildren();
|
|
176
|
+
for (const request of contextRequests) {
|
|
177
|
+
const context = request.context || {};
|
|
178
|
+
const outcome = ["completed", "incomplete", "failed", "cancelled"].includes(request.outcome)
|
|
179
|
+
? request.outcome[0].toUpperCase() + request.outcome.slice(1) : "Unknown";
|
|
180
|
+
const ratio = finite(context.input_tokens) && finite(context.context_window_tokens) && Number(context.context_window_tokens) > 0
|
|
181
|
+
? `${(100 * Number(context.input_tokens) / Number(context.context_window_tokens)).toFixed(1)}%` : "—";
|
|
182
|
+
body.append(tableRow([String(request.model || "unknown").slice(0, 80),
|
|
183
|
+
finite(context.payload_bytes) ? (Number(context.payload_bytes) / 1048576).toFixed(2) : "—",
|
|
184
|
+
number(context.images), number(context.input_tokens), number(context.context_window_tokens), ratio,
|
|
185
|
+
outcome], { labels: [6] }));
|
|
186
|
+
}
|
|
187
|
+
if (!contextRequests.length) emptyTable("context-body", 7, "No observed request metadata.");
|
|
188
|
+
}
|
|
189
|
+
return { render, renderAuth, renderFailures, renderContext };
|
|
190
|
+
}
|
|
191
|
+
globalThis.ccdxDashboardStatus = { create };
|
|
192
|
+
})();
|
package/src/dashboard/ui.js
CHANGED
|
@@ -15,193 +15,12 @@ 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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function renderAuth(data, { failed = false } = {}) {
|
|
24
|
-
const account = data.login ? `@${data.login}` : data.id ? `ID ${data.id}` : phrase("account unknown");
|
|
25
|
-
const label = data.reason === "credential_read_failed" ? "UNAVAILABLE"
|
|
26
|
-
: !data.configured ? "NOT CONFIGURED" : !data.valid ? "INVALID" : "SAVED";
|
|
27
|
-
text("auth-account", failed ? "GitHub / {account} / UPDATE FAILED" : label === "SAVED" ? "GitHub / {account} / SAVED" : `GitHub / ${label}`, { account });
|
|
28
|
-
}
|
|
29
|
-
|
|
18
|
+
const viewHelpers = { element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator: globalThis.navigator };
|
|
19
|
+
const { render, renderAuth, renderFailures, renderContext } = globalThis.ccdxDashboardStatus.create(viewHelpers);
|
|
20
|
+
const usageView = globalThis.ccdxDashboardUsage.create(viewHelpers);
|
|
21
|
+
const { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay } = usageView;
|
|
30
22
|
const loadAuth = () => dashboardRefresh.refresh("auth", { force: true });
|
|
31
23
|
|
|
32
|
-
function duration(value) {
|
|
33
|
-
if (!finite(value)) return "—";
|
|
34
|
-
const seconds = Math.max(0, Math.round(Number(value) / 1000));
|
|
35
|
-
const days = Math.floor(seconds / 86400);
|
|
36
|
-
const hours = Math.floor((seconds % 86400) / 3600);
|
|
37
|
-
const minutes = Math.floor((seconds % 3600) / 60);
|
|
38
|
-
return days ? `${days}d ${hours}h` : hours ? `${hours}h ${minutes}m` : `${minutes}m`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function renderFailures(recent, recentRequests = []) {
|
|
42
|
-
const signature = JSON.stringify([recent, recentRequests]);
|
|
43
|
-
if (signature === failureSignature) return;
|
|
44
|
-
failureSignature = signature;
|
|
45
|
-
const list = element("failures");
|
|
46
|
-
const expanded = new Set([...list.querySelectorAll("details[open]")].map((item) => item.dataset.key));
|
|
47
|
-
list.replaceChildren();
|
|
48
|
-
const requests = Array.isArray(recentRequests) ? recentRequests.slice(-20) : [];
|
|
49
|
-
const byRequest = new Map(requests.filter((request) => request.request_id).map((request) => [request.request_id, request]));
|
|
50
|
-
const failures = Array.isArray(recent) ? recent.slice(-10).map((failure) => ({ ...failure, timeline: byRequest.get(failure.request_id) })) : [];
|
|
51
|
-
const recorded = new Set(failures.map((failure) => failure.request_id).filter(Boolean));
|
|
52
|
-
for (const request of requests) {
|
|
53
|
-
if (!request.failed || recorded.has(request.request_id)) continue;
|
|
54
|
-
failures.push({ at: request.at, model: request.model, request_id: request.request_id,
|
|
55
|
-
event_type: `request.${request.outcome}`, code: request.origin, timeline: request,
|
|
56
|
-
message: "Request ended without successful completion.", local_message: true, retried: request.upstream_attempts > 1 });
|
|
57
|
-
}
|
|
58
|
-
failures.sort((a, b) => (Date.parse(a.at) || 0) - (Date.parse(b.at) || 0));
|
|
59
|
-
failures.splice(0, Math.max(0, failures.length - 10));
|
|
60
|
-
failures.reverse();
|
|
61
|
-
text("failure-count", "{count} retained / requests + events", { count: failures.length });
|
|
62
|
-
if (!failures.length) {
|
|
63
|
-
const item = document.createElement("li");
|
|
64
|
-
item.className = "empty";
|
|
65
|
-
localize(item, "No recent request failures recorded.");
|
|
66
|
-
list.append(item);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
for (const failure of failures) {
|
|
70
|
-
const item = document.createElement("li");
|
|
71
|
-
const details = document.createElement("details");
|
|
72
|
-
details.dataset.key = `${failure.at}/${failure.request_id || failure.response_id}/${failure.code}`;
|
|
73
|
-
details.open = expanded.has(details.dataset.key);
|
|
74
|
-
const title = document.createElement("summary");
|
|
75
|
-
localize(title, "{detail} / {retry}", {
|
|
76
|
-
detail: phrase("{time} / {model} / {code}", {
|
|
77
|
-
time: failure.at ? String(failure.at) : phrase("unknown time"),
|
|
78
|
-
model: failure.model ? String(failure.model).slice(0, 80) : phrase("unknown_model"),
|
|
79
|
-
code: failure.code ? String(failure.code).slice(0, 80) : phrase("unknown_error"),
|
|
80
|
-
}),
|
|
81
|
-
retry: phrase(failure.retried ? "retry attempted" : "no retry"),
|
|
82
|
-
});
|
|
83
|
-
const timeline = failure.timeline;
|
|
84
|
-
const timings = timeline?.timings_ms || {};
|
|
85
|
-
const timingText = ["admission", "body", "history", "images", "serialization", "upstream_start", "upstream_headers", "first_output", "last_activity", "terminal", "finished"]
|
|
86
|
-
.filter((key) => finite(timings[key])).map((key) => `${key}=${Number(timings[key]).toFixed(1)}`).join(" / ");
|
|
87
|
-
const fields = { time: failure.at, model: failure.model, event: failure.event_type, code: failure.code,
|
|
88
|
-
message: failure.message, response_id: failure.response_id, upstream_request_id: failure.upstream_request_id,
|
|
89
|
-
retry: failure.retried ? (timeline ? "attempted" : "attempted (outcome not recorded here)") : "not attempted",
|
|
90
|
-
retry_policy: failure.retry_policy, retry_skipped: failure.retry_skipped,
|
|
91
|
-
recovery: failure.recovery ? JSON.stringify(failure.recovery) : undefined,
|
|
92
|
-
request_id: failure.request_id, outcome: timeline?.outcome, origin: timeline?.origin,
|
|
93
|
-
phase: timeline?.phase, http_status: timeline?.http_status, upstream_attempts: timeline?.upstream_attempts,
|
|
94
|
-
timings_ms: timingText };
|
|
95
|
-
const diagnostic = document.createElement("dl");
|
|
96
|
-
diagnostic.className = "failure-detail";
|
|
97
|
-
const lines = [];
|
|
98
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
99
|
-
if (value === undefined || value === null || value === "") continue;
|
|
100
|
-
const label = document.createElement("dt");
|
|
101
|
-
const content = document.createElement("dd");
|
|
102
|
-
localize(label, key);
|
|
103
|
-
const rawValue = String(value).slice(0, 500);
|
|
104
|
-
if (key === "retry" || (key === "message" && failure.local_message)) localize(content, rawValue);
|
|
105
|
-
else content.textContent = rawValue;
|
|
106
|
-
diagnostic.append(label, content);
|
|
107
|
-
lines.push(`${key}: ${rawValue}`);
|
|
108
|
-
}
|
|
109
|
-
const copy = document.createElement("button");
|
|
110
|
-
copy.type = "button";
|
|
111
|
-
localize(copy, "Copy diagnostic");
|
|
112
|
-
copy.addEventListener("click", async () => {
|
|
113
|
-
try {
|
|
114
|
-
await navigator.clipboard.writeText(lines.join("\n"));
|
|
115
|
-
localize(copy, "Copied");
|
|
116
|
-
} catch { localize(copy, "Copy unavailable"); }
|
|
117
|
-
});
|
|
118
|
-
details.append(title, diagnostic, copy);
|
|
119
|
-
item.append(details);
|
|
120
|
-
list.append(item);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function render(data) {
|
|
125
|
-
text("version", `v${data.version || "?"}`);
|
|
126
|
-
text("uptime", "pid {pid} / uptime {duration}", { pid: number(data.pid), duration: duration(data.uptime_ms) });
|
|
127
|
-
|
|
128
|
-
const copilot = data.copilot || {};
|
|
129
|
-
text("copilot", copilot.account_bound ? "BOUND" : "UNCONFIRMED");
|
|
130
|
-
text("token", copilot.token_cached ? "service token / TTL {duration}" : "service token not cached", { duration: duration(copilot.token_expires_in_ms) });
|
|
131
|
-
|
|
132
|
-
const models = data.models || {};
|
|
133
|
-
text("models", number(models.models));
|
|
134
|
-
text("model-source", "source {source} / live: ccdx models", { source: phrase(String(models.source || "unknown").slice(0, 80)) });
|
|
135
|
-
|
|
136
|
-
const requests = data.requests || {};
|
|
137
|
-
text("requests", number(requests.total));
|
|
138
|
-
text("request-errors", "4xx {client} / 5xx {server} / active {active}", { client: number(requests.status_4xx), server: number(requests.status_5xx), active: number(requests.active) });
|
|
139
|
-
text("body-limits", "raw {raw} / decoded {decoded}", { raw: mib(data.limits?.max_body_bytes), decoded: mib(data.limits?.max_decoded_body_bytes) });
|
|
140
|
-
|
|
141
|
-
const outcomes = data.stream_performance?.by_route?.responses?.terminal_outcomes?.totals || {};
|
|
142
|
-
for (const key of ["completed", "incomplete", "failed", "cancelled"]) text(key, number(outcomes[key]));
|
|
143
|
-
const timing = data.stream_performance?.by_route?.responses || {};
|
|
144
|
-
for (const [id, metric, scale, unit] of [["ttft", timing.ttft_ms, 1, "ms"], ["tpot", timing.tpot_us, timing.tpot_us?.unit === "us" ? 1000 : 1, "ms/token"]]) {
|
|
145
|
-
const value = metric?.samples > 0 && finite(metric.avg) ? `${(Number(metric.avg) / scale).toFixed(1)} ${unit}` : "—";
|
|
146
|
-
text(id, "{value} / {samples} samples", { value, samples: number(metric?.samples) });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const history = data.response_history || {};
|
|
150
|
-
const limit = Number(history.maxBytes || data.limits?.response_history_max_bytes || 0);
|
|
151
|
-
const used = Number(history.bytes || 0);
|
|
152
|
-
text("history", `${mib(used)} / ${mib(limit)}`);
|
|
153
|
-
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) });
|
|
154
|
-
element("history-meter").value = limit > 0 ? Math.min(100, Math.max(0, used / limit * 100)) : 0;
|
|
155
|
-
|
|
156
|
-
const image = data.image_generation;
|
|
157
|
-
text("image", image ? "{count} succeeded" : "NOT INITIALIZED", { count: number(image?.succeeded) });
|
|
158
|
-
text("image-detail", image
|
|
159
|
-
? "active {active} / failed {failed} / delivery failures {delivery}"
|
|
160
|
-
: "Setup state unknown / ccdx image-status", { active: number(image?.active), failed: number(image?.failed), delivery: number(image?.delivery_failures) });
|
|
161
|
-
|
|
162
|
-
renderFailures(data.response_failures?.recent, data.stream_performance?.recent_requests);
|
|
163
|
-
renderContext(data.stream_performance);
|
|
164
|
-
if (element("prediction-preference")) {
|
|
165
|
-
const prediction = data.client_integrations?.prediction;
|
|
166
|
-
text("prediction-preference", prediction ? prediction.configured ? "Enabled" : "Disabled" : "Unknown");
|
|
167
|
-
text("prediction-bridge", ({ running: "Running", stopped: "Stopped", unavailable: "Unavailable" })[prediction?.bridge] || "Unknown");
|
|
168
|
-
text("prediction-route", prediction?.client_route === "observed" ? "Observed" : "Unknown");
|
|
169
|
-
text("prediction-candidate", "Unknown");
|
|
170
|
-
const note = element("prediction-note");
|
|
171
|
-
if (note) note.textContent = prediction?.reason || "";
|
|
172
|
-
}
|
|
173
|
-
text("updated", "Snapshot {time}", { time: new Date().toLocaleTimeString() });
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function renderContext(performance) {
|
|
177
|
-
if (performance !== undefined) {
|
|
178
|
-
contextRequests = Array.isArray(performance?.recent_requests) ? performance.recent_requests.slice(-20).reverse() : [];
|
|
179
|
-
contextCompactions = performance?.by_route?.responses_compact?.terminal_outcomes?.totals || {};
|
|
180
|
-
}
|
|
181
|
-
const body = element("context-body");
|
|
182
|
-
if (!body) return;
|
|
183
|
-
text("context-note", "20 latest finished requests / compactions: {completed} completed, {incomplete} incomplete, {failed} failed", {
|
|
184
|
-
completed: number(contextCompactions.completed), incomplete: number(contextCompactions.incomplete), failed: number(contextCompactions.failed),
|
|
185
|
-
});
|
|
186
|
-
if (element("request-context")?.open === false) return;
|
|
187
|
-
const signature = JSON.stringify(contextRequests);
|
|
188
|
-
if (signature === contextSignature) return;
|
|
189
|
-
contextSignature = signature;
|
|
190
|
-
body.replaceChildren();
|
|
191
|
-
for (const request of contextRequests) {
|
|
192
|
-
const context = request.context || {};
|
|
193
|
-
const outcome = ["completed", "incomplete", "failed", "cancelled"].includes(request.outcome)
|
|
194
|
-
? request.outcome[0].toUpperCase() + request.outcome.slice(1) : "Unknown";
|
|
195
|
-
const ratio = finite(context.input_tokens) && finite(context.context_window_tokens) && Number(context.context_window_tokens) > 0
|
|
196
|
-
? `${(100 * Number(context.input_tokens) / Number(context.context_window_tokens)).toFixed(1)}%` : "—";
|
|
197
|
-
body.append(tableRow([String(request.model || "unknown").slice(0, 80),
|
|
198
|
-
finite(context.payload_bytes) ? (Number(context.payload_bytes) / 1048576).toFixed(2) : "—",
|
|
199
|
-
number(context.images), number(context.input_tokens), number(context.context_window_tokens), ratio,
|
|
200
|
-
outcome], { labels: [6] }));
|
|
201
|
-
}
|
|
202
|
-
if (!contextRequests.length) emptyTable("context-body", 7, "No observed request metadata.");
|
|
203
|
-
}
|
|
204
|
-
|
|
205
24
|
const refresh = () => dashboardRefresh.refresh("status", { force: true });
|
|
206
25
|
|
|
207
26
|
element("refresh").addEventListener("click", () => dashboardRefresh.refreshVisible({ force: true }));
|
|
@@ -420,164 +239,8 @@ function applyModels(data, { changed }) {
|
|
|
420
239
|
text("models-note", "{selectable} selectable / {advertised} advertised / {host} / {time}", { selectable: number(data.selectable), advertised: number(data.advertised), host: data.upstream_host, time: new Date(data.checked_at).toLocaleTimeString() });
|
|
421
240
|
}
|
|
422
241
|
|
|
423
|
-
function usageValues(row) {
|
|
424
|
-
const rate = Number.isFinite(row.cache_hit_rate) && row.cache_hit_rate >= 0 && row.cache_hit_rate <= 1
|
|
425
|
-
? `${row.cache_hit_rate_partial ? "~" : ""}${(row.cache_hit_rate * 100).toFixed(1)}%` : "—";
|
|
426
|
-
return [row.model, number(row.requests), number(row.input_tokens), number(row.cache_read_tokens), number(row.output_tokens), number(row.total_tokens), rate];
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
let usageData = null;
|
|
430
|
-
let analyticsSignature;
|
|
431
|
-
let selectedUsageDate = "";
|
|
432
|
-
|
|
433
|
-
function renderUsageTable() {
|
|
434
|
-
const day = selectedUsageDate && usageData.analytics?.days.find((entry) => entry.date === selectedUsageDate);
|
|
435
|
-
const model = element("analytics-model").value;
|
|
436
|
-
const total = day ? { ...analyticsPoint(day, model), model: "TOTAL" } : usageData.total;
|
|
437
|
-
const rows = day ? day.models.filter((row) => !model || row.model === model).sort((a, b) => b.total_tokens - a.total_tokens || a.model.localeCompare(b.model)) : usageData.rows;
|
|
438
|
-
const body = element("usage-body");
|
|
439
|
-
body.replaceChildren();
|
|
440
|
-
if (total.requests > 0) {
|
|
441
|
-
body.append(tableRow(usageValues(total), { total: true }));
|
|
442
|
-
for (const row of rows) body.append(tableRow(usageValues(row)));
|
|
443
|
-
} else { emptyTable("usage-body", 7, "No usage records."); }
|
|
444
|
-
element("clear-usage-day").hidden = !day;
|
|
445
|
-
text("usage-state", day ? day.date : "LOCAL LOG");
|
|
446
|
-
text("usage-note", "{records} records / {shown} of {models} models shown{day}", {
|
|
447
|
-
records: number(total.requests), shown: number(rows.length), models: number(day ? rows.length : usageData.model_count),
|
|
448
|
-
day: day ? phrase(" / {zone} / {model}", { zone: usageData.analytics.time_zone, model: model || phrase("All models") }) : "",
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function renderUsageState() {
|
|
453
|
-
text("usage-state", selectedUsageDate && usageData.analytics?.days.some(day => day.date === selectedUsageDate) ? selectedUsageDate : "LOCAL LOG");
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function analyticsPoint(day, model) {
|
|
457
|
-
return model ? day.models.find((row) => row.model === model) || { requests: 0, input_tokens: 0, output_tokens: 0 } : day;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
function selectUsageDay(date) {
|
|
461
|
-
selectedUsageDate = date;
|
|
462
|
-
renderUsageTable();
|
|
463
|
-
renderAnalytics();
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
function dayButton(day, point) {
|
|
467
|
-
const button = document.createElement("button");
|
|
468
|
-
button.type = "button";
|
|
469
|
-
button.disabled = !day.available;
|
|
470
|
-
button.setAttribute("aria-pressed", String(day.date === selectedUsageDate));
|
|
471
|
-
const description = !day.available ? phrase("no retained history")
|
|
472
|
-
: phrase("{calls} recorded calls / input {input} / output {output} / cached {cached} (included in input){partial}", {
|
|
473
|
-
calls: number(point.requests), input: number(point.input_tokens), output: number(point.output_tokens), cached: number(point.cache_read_tokens), partial: point.tokens_partial ? phrase(" / partial token counts") : "",
|
|
474
|
-
});
|
|
475
|
-
for (const attribute of ["title", "aria-label"]) localize(button, "{date} / {description}", { date: day.date, description }, attribute);
|
|
476
|
-
button.addEventListener("click", () => selectUsageDay(day.date));
|
|
477
|
-
return button;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
function renderAnalytics() {
|
|
481
|
-
const analytics = usageData?.analytics;
|
|
482
|
-
if (!analytics) return;
|
|
483
|
-
const model = element("analytics-model").value;
|
|
484
|
-
const signature = JSON.stringify([analytics, model, element("analytics-range").value, element("analytics-metric").value, selectedUsageDate]);
|
|
485
|
-
if (signature === analyticsSignature) return;
|
|
486
|
-
analyticsSignature = signature;
|
|
487
|
-
const days = analytics.days;
|
|
488
|
-
const daily = days.slice(-Number(element("analytics-range").value));
|
|
489
|
-
const maximum = Math.max(1, ...daily.map((day) => {
|
|
490
|
-
const point = analyticsPoint(day, model);
|
|
491
|
-
return point.input_tokens + point.output_tokens;
|
|
492
|
-
}));
|
|
493
|
-
const bars = element("daily-bars");
|
|
494
|
-
bars.replaceChildren();
|
|
495
|
-
for (const day of daily) {
|
|
496
|
-
const point = analyticsPoint(day, model);
|
|
497
|
-
const button = dayButton(day, point);
|
|
498
|
-
button.className = "daily-bar";
|
|
499
|
-
for (const key of ["output_tokens", "input_tokens"]) {
|
|
500
|
-
const segment = document.createElement("span");
|
|
501
|
-
segment.className = key === "input_tokens" ? "bar-input" : "bar-output";
|
|
502
|
-
segment.style.height = `${point[key] / maximum * 100}%`;
|
|
503
|
-
button.append(segment);
|
|
504
|
-
}
|
|
505
|
-
bars.append(button);
|
|
506
|
-
}
|
|
507
|
-
text("daily-from", daily[0].date);
|
|
508
|
-
text("daily-to", analytics.to);
|
|
509
|
-
const metric = element("analytics-metric").value;
|
|
510
|
-
const value = (day) => {
|
|
511
|
-
const point = analyticsPoint(day, model);
|
|
512
|
-
return metric === "tokens" ? point.input_tokens + point.output_tokens : point.requests;
|
|
513
|
-
};
|
|
514
|
-
const peak = Math.max(1, ...days.map(value));
|
|
515
|
-
text("activity-scale", "{metric} / PEAK {peak}", { metric: phrase(metric === "tokens" ? "INPUT + OUTPUT" : "RECORDED CALLS"), peak: number(peak === 1 && days.every((day) => value(day) === 0) ? 0 : peak) });
|
|
516
|
-
const calendar = element("activity-calendar");
|
|
517
|
-
calendar.replaceChildren();
|
|
518
|
-
const offset = (new Date(`${days[0].date}T00:00:00Z`).getUTCDay() + 6) % 7;
|
|
519
|
-
const months = element("calendar-months");
|
|
520
|
-
months.replaceChildren();
|
|
521
|
-
const columns = Math.ceil((offset + days.length) / 7);
|
|
522
|
-
let previousColumn = -4;
|
|
523
|
-
days.forEach((day, index) => {
|
|
524
|
-
if (index !== 0 && !day.date.endsWith("-01")) return;
|
|
525
|
-
const column = Math.floor((offset + index) / 7);
|
|
526
|
-
if (column - previousColumn < 4 || column + 4 > columns) return;
|
|
527
|
-
previousColumn = column;
|
|
528
|
-
const label = document.createElement("span");
|
|
529
|
-
label.textContent = day.date.slice(0, 7);
|
|
530
|
-
label.style.gridColumn = `${column + 1} / span 4`;
|
|
531
|
-
months.append(label);
|
|
532
|
-
});
|
|
533
|
-
for (let index = 0; index < offset; index += 1) {
|
|
534
|
-
const spacer = document.createElement("span");
|
|
535
|
-
spacer.setAttribute("aria-hidden", "true");
|
|
536
|
-
calendar.append(spacer);
|
|
537
|
-
}
|
|
538
|
-
for (const day of days) {
|
|
539
|
-
const button = dayButton(day, analyticsPoint(day, model));
|
|
540
|
-
button.className = "calendar-day";
|
|
541
|
-
const count = value(day);
|
|
542
|
-
button.dataset.level = String(count > 0 ? Math.min(4, Math.ceil(count / peak * 4)) : 0);
|
|
543
|
-
calendar.append(button);
|
|
544
|
-
}
|
|
545
|
-
text("analytics-note", "{zone} / {from} — {to} / retained history starts {first}; oldest day may be partial.{excluded}{limit}", {
|
|
546
|
-
zone: analytics.time_zone, from: daily[0].date, to: analytics.to, first: analytics.first_date || phrase("unknown"),
|
|
547
|
-
excluded: analytics.undated_records ? phrase(" {count} records with invalid/future timestamps excluded.", { count: number(analytics.undated_records) }) : "",
|
|
548
|
-
limit: analytics.models_truncated ? phrase(" Model filters limited to 100; all-model totals include the remainder.") : "",
|
|
549
|
-
});
|
|
550
|
-
text("analytics-selection", selectedUsageDate ? "Selected {date} / {model}: totals in the Usage table above / All history resets the table." : "Select a day for model totals. Calls are usage records, not messages or time. Hatched cells: no retained history; empty cells: zero recorded calls.", { date: selectedUsageDate, model: model || phrase("All models") });
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function updateAnalyticsModels() {
|
|
554
|
-
const select = element("analytics-model");
|
|
555
|
-
const previous = select.value;
|
|
556
|
-
select.replaceChildren();
|
|
557
|
-
for (const model of [...new Set(["", ...usageData.analytics.models, ...(previous ? [previous] : [])])]) {
|
|
558
|
-
const option = document.createElement("option");
|
|
559
|
-
option.value = model;
|
|
560
|
-
if (model) option.textContent = model;
|
|
561
|
-
else localize(option, "All models");
|
|
562
|
-
select.append(option);
|
|
563
|
-
}
|
|
564
|
-
select.value = previous;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
242
|
async function loadUsage() { return dashboardRefresh.refresh("usage", { force: true }); }
|
|
568
243
|
|
|
569
|
-
function applyUsage(data, { changed }) {
|
|
570
|
-
usageData = { ...data, ...(!data.analytics && usageData?.analytics ? { analytics: usageData.analytics } : {}) };
|
|
571
|
-
if (changed) {
|
|
572
|
-
if (data.analytics) updateAnalyticsModels();
|
|
573
|
-
renderUsageTable();
|
|
574
|
-
if (data.analytics) renderAnalytics();
|
|
575
|
-
}
|
|
576
|
-
if (data.analytics) {
|
|
577
|
-
text("analytics-updated", "Updated {time}", { time: new Date().toLocaleTimeString() });
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
244
|
async function readDashboard(url, { signal, timeout = 15000, source } = {}) {
|
|
582
245
|
const response = await fetch(url, { cache: "no-store", headers: { "X-CCDX-Dashboard": "1", Accept: "application/json" },
|
|
583
246
|
signal: AbortSignal.any([signal, AbortSignal.timeout(timeout)]) });
|
|
@@ -655,7 +318,7 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
655
318
|
},
|
|
656
319
|
usage: {
|
|
657
320
|
visible: () => element("model-usage").open,
|
|
658
|
-
variant: () => ((element("model-usage").open && element("usage-analytics").open) || Boolean(
|
|
321
|
+
variant: () => ((element("model-usage").open && element("usage-analytics").open) || Boolean(usageView.selectedDate)) ? "analytics" : "summary",
|
|
659
322
|
load: async ({ variant, signal }) => {
|
|
660
323
|
const data = await readDashboard(`/_ccdx/ui/usage${variant === "analytics" ? `?analytics=1&time_zone=${encodeURIComponent(Intl.DateTimeFormat().resolvedOptions().timeZone)}` : ""}`, { signal, source: "local_usage_log" });
|
|
661
324
|
if (!data.total || !Array.isArray(data.rows) || (variant === "analytics" && (!Array.isArray(data.analytics?.days) || !data.analytics.days.length))) throw new Error("Invalid usage snapshot");
|
|
@@ -734,7 +397,7 @@ element("usage-analytics").addEventListener("toggle", () => {
|
|
|
734
397
|
});
|
|
735
398
|
for (const id of ["analytics-model", "analytics-range", "analytics-metric"]) element(id).addEventListener("change", () => {
|
|
736
399
|
renderAnalytics();
|
|
737
|
-
if (
|
|
400
|
+
if (usageView.data && usageView.selectedDate) renderUsageTable();
|
|
738
401
|
});
|
|
739
402
|
element("clear-usage-day").addEventListener("click", () => selectUsageDay(""));
|
|
740
403
|
element("refresh-models").addEventListener("click", loadModels);
|