codex-copilot-dx 0.10.1 → 1.0.0
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 +4 -3
- package/docs/ARCHITECTURE.md +27 -9
- package/docs/README.md +2 -0
- package/docs/REFERENCE.md +76 -10
- package/package.json +2 -2
- package/src/adapter.mjs +2 -1
- package/src/claude-client-config.mjs +15 -3
- package/src/claude-gateway.mjs +12 -6
- package/src/claude-models.mjs +26 -0
- package/src/cli-options.mjs +4 -3
- package/src/dashboard/index.html +40 -37
- package/src/dashboard/language.js +38 -0
- package/src/dashboard/refresh.js +2 -1
- package/src/dashboard/status.js +35 -26
- package/src/dashboard/ui.css +6 -0
- package/src/dashboard/ui.js +109 -21
- package/src/dashboard-api.mjs +48 -7
- package/src/live-models.mjs +11 -3
- package/src/optional-routes.mjs +1 -1
- package/src/provider-metadata.mjs +21 -0
- package/src/provider-runtime.mjs +62 -15
- package/src/providers/m365-auth.mjs +4 -4
- package/src/providers/m365.mjs +10 -2
- package/src/usage-analysis.mjs +1 -1
- package/src/usage-analytics.mjs +3 -3
- package/src/usage-store.mjs +29 -16
- package/src/usage.mjs +13 -7
package/src/dashboard/status.js
CHANGED
|
@@ -5,13 +5,40 @@
|
|
|
5
5
|
let failureSignature;
|
|
6
6
|
let contextSignature;
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
:
|
|
12
|
-
|
|
8
|
+
function renderProviders(data) {
|
|
9
|
+
const providers = data.providers || [];
|
|
10
|
+
const states = { saved: "Saved locally", authorized: "Authorized", disabled: "Disabled", unavailable: "Unavailable",
|
|
11
|
+
unknown: "Unknown", unconfigured: "Not configured", ready: "Ready", checking: "Checking", unsupported: "Unsupported",
|
|
12
|
+
configured: "Configured", preserved: "Existing settings kept", partially_preserved: "Existing settings kept",
|
|
13
|
+
not_installed: "Not installed", configuration_unavailable: "Setup unavailable", not_configured: "Not configured", standby: "Standby" };
|
|
14
|
+
const auth = element("provider-auth"), clients = element("provider-clients"), requests = element("provider-requests");
|
|
15
|
+
auth.replaceChildren();clients.replaceChildren();requests.replaceChildren();
|
|
16
|
+
const routes = [];
|
|
17
|
+
for (const provider of providers) {
|
|
18
|
+
const identity = provider.auth || {};
|
|
19
|
+
const authRow = tableRow([provider.name, identity.account || "—", states[identity.state] || "Unknown",
|
|
20
|
+
states[provider.state] || "Unknown", identity.checked_at || "—", duration(identity.expires_in_ms)], { labels: [2, 3] });
|
|
21
|
+
if (provider.reason) localize(authRow.children[3], "{state} / {reason}", { state: phrase(states[provider.state] || "Unknown"), reason: provider.reason });
|
|
22
|
+
auth.append(authRow);
|
|
23
|
+
for (const client of provider.clients || []) {
|
|
24
|
+
const row = tableRow([provider.name, client.name, states[client.state] || client.state,
|
|
25
|
+
client.gateway || "—", client.last_request_at || "—"], { labels: [2, 3] });
|
|
26
|
+
if (client.reason) localize(row.children[2], "{state} / {reason}", { state: phrase(states[client.state] || "Unknown"), reason: client.reason });
|
|
27
|
+
clients.append(row);
|
|
28
|
+
if (client.selected && client.id === "codex") routes.push(`${client.name} → ${provider.name}`);
|
|
29
|
+
}
|
|
30
|
+
if (provider.requests) {
|
|
31
|
+
const item = document.createElement("p");
|
|
32
|
+
localize(item, "{provider}: {done} done / {incomplete} incomplete / {failed} failed", { provider: provider.name,
|
|
33
|
+
done: number(provider.requests.completed), incomplete: number(provider.requests.incomplete), failed: number(provider.requests.failed) });
|
|
34
|
+
requests.append(item);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
text("source-summary", "{count} providers", { count: providers.filter(provider => provider.enabled).length });
|
|
38
|
+
element("source-detail").textContent = routes.join(" / ") || "—";
|
|
39
|
+
element("auth-account").textContent = routes.join(" / ") || "—";
|
|
13
40
|
}
|
|
14
|
-
|
|
41
|
+
|
|
15
42
|
function duration(value) {
|
|
16
43
|
if (!finite(value)) return "—";
|
|
17
44
|
const seconds = Math.max(0, Math.round(Number(value) / 1000));
|
|
@@ -114,10 +141,6 @@
|
|
|
114
141
|
text("version", `v${data.version || "?"}`);
|
|
115
142
|
text("uptime", "pid {pid} / uptime {duration}", { pid: number(data.pid), duration: duration(data.uptime_ms) });
|
|
116
143
|
|
|
117
|
-
const copilot = data.copilot || {};
|
|
118
|
-
text("copilot", copilot.account_bound ? "BOUND" : "UNCONFIRMED");
|
|
119
|
-
text("token", copilot.token_cached ? "service token / TTL {duration}" : "service token not cached", { duration: duration(copilot.token_expires_in_ms) });
|
|
120
|
-
|
|
121
144
|
const models = data.models || {};
|
|
122
145
|
text("models", number(models.models));
|
|
123
146
|
text("model-source", "source {source} / live: ccdx models", { source: phrase(String(models.source || "unknown").slice(0, 80)) });
|
|
@@ -151,20 +174,6 @@
|
|
|
151
174
|
? "active {active} / failed {failed} / delivery failures {delivery}"
|
|
152
175
|
: "Setup state unknown / ccdx image-status", { active: number(image?.active), failed: number(image?.failed), delivery: number(image?.delivery_failures) });
|
|
153
176
|
|
|
154
|
-
if (element("m365-state")) {
|
|
155
|
-
const providers = data.providers || {}, m365 = providers.m365 || {}, claude = m365.claude || {};
|
|
156
|
-
const state = { ready: "M365 READY", checking: "M365 CHECKING", disabled: "M365 OFF", unsupported: "M365 UNSUPPORTED", unavailable: "M365 UNAVAILABLE", idle: "M365 CHECKING" };
|
|
157
|
-
text("m365-state", state[m365.state] || "M365 UNKNOWN");
|
|
158
|
-
text("m365-account", m365.account?.login || "Account unavailable");
|
|
159
|
-
text("m365-models", "Claude {claude} / GPT {gpt}", { claude: number(m365.models?.claude), gpt: number(m365.models?.gpt) });
|
|
160
|
-
text("m365-claude", claude.gateway === "running" ? "Claude gateway running" : "Claude gateway unavailable");
|
|
161
|
-
if (element("m365-requests")) text("m365-requests", claude.requests ? "Claude: {done} done / {incomplete} incomplete / {failed} failed" : "Claude requests unavailable",
|
|
162
|
-
{ done: number(claude.requests?.completed), incomplete: number(claude.requests?.incomplete), failed: number(claude.requests?.failed) });
|
|
163
|
-
const labels = { configured: "Configured", preserved: "Existing settings kept", partially_preserved: "Existing settings kept", restored: "Restored", not_installed: "Not installed", configuration_unavailable: "Setup unavailable", not_configured: "Not configured" };
|
|
164
|
-
text("m365-clients", "Code: {code} / App: {app}", { code: phrase(labels[claude.clients?.code] || "Unknown"), app: phrase(labels[claude.clients?.app] || "Unknown") });
|
|
165
|
-
text("m365-codex", providers.codex_provider === "m365" ? "Codex source: Microsoft 365" : "Codex source: GitHub Copilot");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
177
|
renderFailures([...(data.response_failures?.recent || []), ...(data.http_errors?.actionable_recent || data.http_errors?.recent || [])]
|
|
169
178
|
.sort((a, b) => (Date.parse(a.at) || 0) - (Date.parse(b.at) || 0)), data.stream_performance?.recent_requests);
|
|
170
179
|
renderContext(data.stream_performance);
|
|
@@ -201,14 +210,14 @@
|
|
|
201
210
|
? request.outcome[0].toUpperCase() + request.outcome.slice(1) : "Unknown";
|
|
202
211
|
const ratio = finite(context.input_tokens) && finite(context.context_window_tokens) && Number(context.context_window_tokens) > 0
|
|
203
212
|
? `${(100 * Number(context.input_tokens) / Number(context.context_window_tokens)).toFixed(1)}%` : "—";
|
|
204
|
-
body.append(tableRow([String(request.model || "unknown").slice(0, 80) + (request.provider
|
|
213
|
+
body.append(tableRow([String(request.model || "unknown").slice(0, 80) + (request.provider ? ` / ${request.provider}` : ""),
|
|
205
214
|
finite(context.payload_bytes) ? (Number(context.payload_bytes) / 1048576).toFixed(2) : "—",
|
|
206
215
|
number(context.images), number(context.input_tokens), number(context.context_window_tokens), ratio,
|
|
207
216
|
outcome], { labels: [6] }));
|
|
208
217
|
}
|
|
209
218
|
if (!contextRequests.length) emptyTable("context-body", 7, "No observed request metadata.");
|
|
210
219
|
}
|
|
211
|
-
return { render,
|
|
220
|
+
return { render, renderProviders, renderFailures, renderContext };
|
|
212
221
|
}
|
|
213
222
|
globalThis.ccdxDashboardStatus = { create };
|
|
214
223
|
})();
|
package/src/dashboard/ui.css
CHANGED
|
@@ -140,3 +140,9 @@ footer { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; color:
|
|
|
140
140
|
@media (max-width: 460px) { .topbar { flex-wrap: wrap; padding: 12px 0; gap: 10px; } .topbar-actions { gap: 9px; } .panel-heading { flex-wrap: wrap; } .heading-actions { gap: 10px; } .failure-detail { grid-template-columns: 1fr; gap: 3px; } .failure-detail dd { margin-bottom: 7px; } select { max-width: 210px; } }
|
|
141
141
|
.timing-stats { grid-template-columns: 1fr; }
|
|
142
142
|
.timing-stats dt { white-space: nowrap; }
|
|
143
|
+
|
|
144
|
+
.provider-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
|
|
145
|
+
.provider-tabs [aria-selected="true"] { color: var(--accent); border-color: var(--accent-soft); background: var(--selected-bg); }
|
|
146
|
+
#provider-auth td, #provider-clients td { overflow-wrap: anywhere; }
|
|
147
|
+
.details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
148
|
+
@media (max-width: 700px) { .details { grid-template-columns: 1fr; } }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -16,7 +16,7 @@ const finite = (value) => value !== null && value !== undefined && Number.isFini
|
|
|
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
18
|
const viewHelpers = { element, phrase, localize, text, finite, number, mib, tableRow, emptyTable, document, navigator: globalThis.navigator };
|
|
19
|
-
const { render,
|
|
19
|
+
const { render, renderProviders, renderFailures, renderContext } = globalThis.ccdxDashboardStatus.create(viewHelpers);
|
|
20
20
|
const usageView = globalThis.ccdxDashboardUsage.create(viewHelpers);
|
|
21
21
|
const { applyUsage, renderUsageState, renderAnalytics, renderUsageTable, selectUsageDay } = usageView;
|
|
22
22
|
const loadAuth = () => dashboardRefresh.refresh("auth", { force: true });
|
|
@@ -235,16 +235,98 @@ function tableRow(values, { total = false, labels = [] } = {}) {
|
|
|
235
235
|
return row;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
let providerEntries = [];
|
|
239
|
+
let usageProviders = {};
|
|
240
|
+
let selectedProvider = "";
|
|
241
|
+
const modelSnapshots = new Map();
|
|
242
|
+
const providerTabs = new Map();
|
|
243
|
+
try { selectedProvider = localStorage.getItem("ccdx.dashboard.modelProvider") || ""; } catch { /* Page-local choice still works. */ }
|
|
244
|
+
|
|
245
|
+
function syncUsageProviders() {
|
|
246
|
+
const selector = element("usage-provider"), selected = selector.value;
|
|
247
|
+
const entries = new Map(providerEntries.map(provider => [provider.id, provider.name]));
|
|
248
|
+
for (const id of Object.keys(usageProviders)) if (usageProviders[id] > 0 && !entries.has(id)) entries.set(id, id);
|
|
249
|
+
const signature = JSON.stringify([...entries]);
|
|
250
|
+
if (selector.dataset.providers === signature) return;
|
|
251
|
+
selector.dataset.providers = signature;
|
|
252
|
+
selector.replaceChildren();
|
|
253
|
+
const all = document.createElement("option");all.value = "";localize(all, "All providers");selector.append(all);
|
|
254
|
+
for (const [id, name] of entries) { const option = document.createElement("option");option.value = id;option.textContent = name;selector.append(option); }
|
|
255
|
+
selector.value = entries.has(selected) ? selected : "";
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function chooseProvider(id) {
|
|
259
|
+
if (selectedProvider === id) return;
|
|
260
|
+
selectedProvider = id;
|
|
261
|
+
try { localStorage.setItem("ccdx.dashboard.modelProvider", id); } catch { /* Keep the current choice. */ }
|
|
262
|
+
for (const [key, button] of providerTabs) { button.setAttribute("aria-selected", String(key === id));button.tabIndex = key === id ? 0 : -1; }
|
|
263
|
+
dashboardRefresh.invalidate("models", { clear: true });
|
|
264
|
+
const previous = modelSnapshots.get(id);
|
|
265
|
+
if (previous) applyModels(previous, { changed: true });
|
|
266
|
+
else { emptyTable("live-models-body", 6, "Reading provider catalog…");text("models-note", "Reading provider catalog…"); }
|
|
267
|
+
element("live-models-body").setAttribute("aria-labelledby", `model-provider-${id}`);
|
|
268
|
+
void loadModels();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function applyProviders(data, { changed }) {
|
|
272
|
+
const wasInitialized = providerEntries.length > 0, previousSelection = selectedProvider;
|
|
273
|
+
let reloadModels = false;
|
|
274
|
+
const previous = new Map(providerEntries.map(entry => [entry.id, JSON.stringify([entry.generation, entry.auth?.account])]));
|
|
275
|
+
providerEntries = data.providers;
|
|
276
|
+
for (const [id] of modelSnapshots) {
|
|
277
|
+
const provider = providerEntries.find(entry => entry.id === id);
|
|
278
|
+
if (!provider) {
|
|
279
|
+
modelSnapshots.delete(id);
|
|
280
|
+
if (id === selectedProvider) { reloadModels = true;dashboardRefresh.invalidate("models", { clear: true });emptyTable("live-models-body", 6, "Reading provider catalog…"); }
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (const provider of providerEntries) {
|
|
284
|
+
if (previous.has(provider.id) && previous.get(provider.id) !== JSON.stringify([provider.generation, provider.auth?.account])) {
|
|
285
|
+
modelSnapshots.delete(provider.id);
|
|
286
|
+
if (provider.id === selectedProvider) { reloadModels = true;dashboardRefresh.invalidate("models", { clear: true });emptyTable("live-models-body", 6, "Reading provider catalog…"); }
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (changed || dashboardRefresh.state("auth").error) renderProviders(data);
|
|
290
|
+
syncUsageProviders();
|
|
291
|
+
const available = providerEntries.some(provider => provider.id === selectedProvider);
|
|
292
|
+
if (!available) selectedProvider = providerEntries.find(provider => provider.clients?.some(client => client.id === "codex" && client.selected))?.id || providerEntries[0]?.id || "";
|
|
293
|
+
const container = element("model-providers");
|
|
294
|
+
for (const [id, button] of providerTabs) if (!providerEntries.some(provider => provider.id === id)) { button.remove();providerTabs.delete(id); }
|
|
295
|
+
for (const provider of providerEntries) {
|
|
296
|
+
let button = providerTabs.get(provider.id);
|
|
297
|
+
if (!button) {
|
|
298
|
+
button = document.createElement("button");button.type = "button";button.setAttribute("role", "tab");
|
|
299
|
+
button.id = `model-provider-${provider.id}`;button.setAttribute("aria-controls", "live-models-body");
|
|
300
|
+
button.addEventListener("click", () => chooseProvider(provider.id));
|
|
301
|
+
button.addEventListener("keydown", event => {
|
|
302
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
303
|
+
event.preventDefault();
|
|
304
|
+
const ids = [...providerTabs.keys()], index = ids.indexOf(provider.id);
|
|
305
|
+
const next = event.key === "Home" ? 0 : event.key === "End" ? ids.length - 1 : (index + (event.key === "ArrowRight" ? 1 : -1) + ids.length) % ids.length;
|
|
306
|
+
chooseProvider(ids[next]);providerTabs.get(ids[next]).focus();
|
|
307
|
+
});
|
|
308
|
+
providerTabs.set(provider.id, button);container.append(button);
|
|
309
|
+
}
|
|
310
|
+
button.textContent = provider.name;button.setAttribute("aria-selected", String(provider.id === selectedProvider));button.tabIndex = provider.id === selectedProvider ? 0 : -1;
|
|
311
|
+
}
|
|
312
|
+
element("live-models-body").setAttribute("aria-labelledby", `model-provider-${selectedProvider}`);
|
|
313
|
+
if (wasInitialized && (reloadModels || selectedProvider !== previousSelection)) { dashboardRefresh.invalidate("models", { clear: true });void loadModels(); }
|
|
314
|
+
}
|
|
315
|
+
|
|
238
316
|
async function loadModels() { return dashboardRefresh.refresh("models", { force: true }); }
|
|
239
317
|
|
|
240
318
|
function applyModels(data, { changed }) {
|
|
319
|
+
if (data.provider && data.provider !== selectedProvider) return;
|
|
320
|
+
modelSnapshots.set(selectedProvider, data);
|
|
241
321
|
if (changed) {
|
|
242
|
-
const body = element("live-models-body");
|
|
243
|
-
body.replaceChildren();
|
|
322
|
+
const body = element("live-models-body");body.replaceChildren();
|
|
244
323
|
for (const model of data.models) {
|
|
245
|
-
|
|
324
|
+
const clients = (model.clients || []).map(id => ({ codex: "Codex App", claude_app: "Claude App", claude_code: "Claude Code" })[id] || id).join(" / ") || "—";
|
|
325
|
+
body.append(tableRow([model.id, model.vendor, model.endpoints.join(" / "), clients,
|
|
326
|
+
model.reasoning_efforts === null || model.reasoning_efforts === undefined ? "—" : model.reasoning_efforts.join(" / ") || "—",
|
|
327
|
+
model.preview ? "preview" : model.state || "listed"], { labels: [5] }));
|
|
246
328
|
}
|
|
247
|
-
if (!data.models.length) emptyTable("live-models-body",
|
|
329
|
+
if (!data.models.length) emptyTable("live-models-body", 6, "No models advertised.");
|
|
248
330
|
}
|
|
249
331
|
text("models-note", "{selectable} selectable / {advertised} advertised / {host} / {time}", { selectable: number(data.selectable), advertised: number(data.advertised), host: data.upstream_host, time: data.checked_at ? new Date(data.checked_at).toLocaleTimeString() : phrase("Unknown") });
|
|
250
332
|
}
|
|
@@ -266,7 +348,7 @@ function refreshTime(target, state) {
|
|
|
266
348
|
}
|
|
267
349
|
|
|
268
350
|
const timestamps = new Map();
|
|
269
|
-
for (const [key, ids] of [["status", ["client-features", "request-context", "recent-failures"]], ["models", ["upstream-models"]], ["usage", ["model-usage"]], ["animation", ["animation-settings"]]]) {
|
|
351
|
+
for (const [key, ids] of [["auth", ["account-authorization"]], ["status", ["client-features", "request-context", "recent-failures", "runtime-resources", "additional-capabilities"]], ["models", ["upstream-models"]], ["usage", ["model-usage"]], ["animation", ["animation-settings"]]]) {
|
|
270
352
|
timestamps.set(key, ids.map(id => {
|
|
271
353
|
const node = document.createElement("p");
|
|
272
354
|
node.className = "refresh-time";
|
|
@@ -301,22 +383,26 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
301
383
|
},
|
|
302
384
|
auth: {
|
|
303
385
|
visible: () => true,
|
|
304
|
-
load: ({ signal }) => readDashboard("/_ccdx/ui/
|
|
305
|
-
apply:
|
|
386
|
+
load: ({ signal }) => readDashboard("/_ccdx/ui/providers", { signal, timeout: 5000, source: "provider_status" }),
|
|
387
|
+
apply: applyProviders,
|
|
306
388
|
state: state => {
|
|
307
|
-
if (state.
|
|
308
|
-
|
|
309
|
-
|
|
389
|
+
if (state.error) {
|
|
390
|
+
if (state.value) localize(element("auth-account"), "Update failed / last {time}", { time: new Date(state.updatedAt).toLocaleTimeString() });
|
|
391
|
+
else text("auth-account", "UNAVAILABLE");
|
|
392
|
+
}
|
|
393
|
+
for (const node of timestamps.get("auth")) refreshTime(node, state);
|
|
310
394
|
},
|
|
311
395
|
},
|
|
312
396
|
models: {
|
|
313
|
-
visible: () => element("upstream-models").open,
|
|
314
|
-
|
|
315
|
-
|
|
397
|
+
visible: () => providerEntries.length > 0 && element("upstream-models").open,
|
|
398
|
+
variant: () => selectedProvider,
|
|
399
|
+
load: async ({ signal, variant }) => {
|
|
400
|
+
if (!variant) throw new Error("Reading provider catalog…");
|
|
401
|
+
const data = await readDashboard(`/_ccdx/ui/models/live?provider=${encodeURIComponent(variant)}`, { signal, source: ["live", "catalog"] });
|
|
316
402
|
if (!Array.isArray(data.models) || data.models.some(model => !model || typeof model.id !== "string" || !Array.isArray(model.endpoints))) throw new Error("Invalid model snapshot");
|
|
317
|
-
return data;
|
|
403
|
+
return { ...data, provider: variant };
|
|
318
404
|
},
|
|
319
|
-
project: data => [data.models, data.selectable, data.advertised, data.upstream_host],
|
|
405
|
+
project: data => [data.provider, data.models, data.selectable, data.advertised, data.upstream_host],
|
|
320
406
|
apply: applyModels,
|
|
321
407
|
state: state => {
|
|
322
408
|
element("refresh-models").disabled = Boolean(state.pending);
|
|
@@ -327,7 +413,7 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
327
413
|
if (httpError) text("models-note", "Live model lookup failed (HTTP {status}). Run ccdx models for details.", { status: httpError[1] });
|
|
328
414
|
else text("models-note", message);
|
|
329
415
|
}
|
|
330
|
-
if (state.error && !
|
|
416
|
+
if (state.error && !modelSnapshots.has(selectedProvider)) emptyTable("live-models-body", 6, "No catalog available.");
|
|
331
417
|
for (const node of timestamps.get("models")) refreshTime(node, state);
|
|
332
418
|
},
|
|
333
419
|
},
|
|
@@ -346,7 +432,10 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
346
432
|
if (!data.total || !Array.isArray(data.rows) || (mode === "analytics" && (!Array.isArray(data.analytics?.days) || !data.analytics.days.length))) throw new Error("Invalid usage snapshot");
|
|
347
433
|
return data;
|
|
348
434
|
},
|
|
349
|
-
apply:
|
|
435
|
+
apply: (data, options) => {
|
|
436
|
+
usageProviders = data.provider && data.provider !== "all" ? { ...usageProviders, ...data.providers } : data.providers || {};
|
|
437
|
+
syncUsageProviders();applyUsage(data, options);
|
|
438
|
+
},
|
|
350
439
|
state: state => {
|
|
351
440
|
element("refresh-usage").disabled = Boolean(state.pending);
|
|
352
441
|
if (element("usage-provider")) element("usage-provider").disabled = Boolean(state.pending);
|
|
@@ -394,7 +483,7 @@ document.addEventListener("visibilitychange", () => dashboardRefresh.visibilityC
|
|
|
394
483
|
window.addEventListener("pagehide", () => { dashboardRefresh.suspend(); stopAnimationPreview(); });
|
|
395
484
|
window.addEventListener("pageshow", () => { dashboardRefresh.resume(); syncAnimationPreview(); });
|
|
396
485
|
|
|
397
|
-
for (const [id, key] of [["client-features", "status"], ["request-context", "status"], ["recent-failures", "status"], ["upstream-models", "models"], ["model-usage", "usage"]]) {
|
|
486
|
+
for (const [id, key] of [["account-authorization", "auth"], ["client-features", "status"], ["request-context", "status"], ["recent-failures", "status"], ["upstream-models", "models"], ["model-usage", "usage"]]) {
|
|
398
487
|
element(id).addEventListener("toggle", () => {
|
|
399
488
|
if (element(id).open) {
|
|
400
489
|
if (id === "request-context") renderContext();
|
|
@@ -427,8 +516,7 @@ element("usage-provider")?.addEventListener("change", () => { dashboardRefresh.i
|
|
|
427
516
|
element("refresh-models").addEventListener("click", loadModels);
|
|
428
517
|
element("refresh-usage").addEventListener("click", loadUsage);
|
|
429
518
|
loadAnimation();
|
|
430
|
-
loadModels();
|
|
431
519
|
loadUsage();
|
|
432
520
|
refresh();
|
|
433
|
-
loadAuth();
|
|
521
|
+
loadAuth().then(() => loadModels());
|
|
434
522
|
animateRefresh();
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
|
+
import { isProviderId } from "./provider-metadata.mjs";
|
|
2
3
|
import { fetchLiveCopilotModels } from "./live-models.mjs";
|
|
3
4
|
import { authStatus } from "./auth-status.mjs";
|
|
4
5
|
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
renderTerminalAnimationFrame,
|
|
12
13
|
TERMINAL_ANIMATION_THEMES,
|
|
13
14
|
} from "./terminal-animation.mjs";
|
|
14
|
-
import { cacheReadTokens, summarizeUsageLogs, usageCacheHitRate } from "./usage-store.mjs";
|
|
15
|
+
import { cacheReadTokens, summarizeUsageLogs, usageCacheHitRate, usageModelGroups } from "./usage-store.mjs";
|
|
15
16
|
import { createUsageAnalytics } from "./usage-analytics.mjs";
|
|
16
17
|
import { analyzeUsageLogs } from "./usage-analysis.mjs";
|
|
17
18
|
import { readUserSettings, terminalAnimationPreference, writeTerminalAnimationTheme } from "./user-settings.mjs";
|
|
@@ -19,6 +20,7 @@ import { readUserSettings, terminalAnimationPreference, writeTerminalAnimationTh
|
|
|
19
20
|
const ANIMATION_PATH = "/_ccdx/ui/animation";
|
|
20
21
|
const MODELS_PATH = "/_ccdx/ui/models/live";
|
|
21
22
|
const USAGE_PATH = "/_ccdx/ui/usage";
|
|
23
|
+
const PROVIDERS_PATH = "/_ccdx/ui/providers";
|
|
22
24
|
const AUTH_PATH = "/_ccdx/ui/auth";
|
|
23
25
|
const DISABLED_ANIMATION = /^(0|false|no|off)$/i;
|
|
24
26
|
|
|
@@ -98,7 +100,7 @@ function usageRow(model, values) {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
function usageTable(summary) {
|
|
101
|
-
const models = Object.entries(summary
|
|
103
|
+
const models = Object.entries(usageModelGroups(summary))
|
|
102
104
|
.sort(([leftName, left], [rightName, right]) => (right.total_tokens || 0) - (left.total_tokens || 0)
|
|
103
105
|
|| leftName.localeCompare(rightName, "en"));
|
|
104
106
|
return {
|
|
@@ -108,6 +110,28 @@ function usageTable(summary) {
|
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
function dashboardProviders(providerStateFn, authStatusFn) {
|
|
114
|
+
const local = authStatusFn()?.profiles?.codex || {};
|
|
115
|
+
const entries = providerStateFn?.() || [{ id: "github", name: "GitHub Copilot", enabled: true, state: "unknown",
|
|
116
|
+
clients: [{ id: "codex", name: "Codex App", selected: true, state: "configured" }] }];
|
|
117
|
+
return entries.slice(0, 16).filter(entry => isProviderId(entry.id)).map(entry => {
|
|
118
|
+
const auth = entry.id === "github" ? { ...entry.auth,
|
|
119
|
+
state: local.valid ? "saved" : local.configured ? "unavailable" : "unconfigured",
|
|
120
|
+
account: local.valid ? local.login || "" : "" } : entry.auth || {};
|
|
121
|
+
const label = value => safeText(redactDiagnosticText(value || ""), 160);
|
|
122
|
+
const code = value => typeof value === "string" && /^[a-z0-9_:-]{1,80}$/.test(value) ? value : null;
|
|
123
|
+
return { id: entry.id, name: label(entry.name) || entry.id, enabled: entry.enabled === true,
|
|
124
|
+
state: code(entry.state) || "unknown", reason: code(entry.reason), generation: finite(entry.generation),
|
|
125
|
+
auth: { state: code(auth.state) || "unknown", account: label(auth.account), token_cached: auth.token_cached === true,
|
|
126
|
+
expires_in_ms: finite(auth.expires_in_ms), checked_at: label(auth.checked_at) || null },
|
|
127
|
+
models: { count: finite(entry.models?.count), source: code(entry.models?.source) || "unknown", checked_at: label(entry.models?.checked_at) || null },
|
|
128
|
+
clients: (entry.clients || []).slice(0, 8).map(client => ({ id: code(client.id), name: label(client.name),
|
|
129
|
+
selected: client.selected === true, state: code(client.state) || "unknown", gateway: code(client.gateway),
|
|
130
|
+
reason: code(client.reason), last_request_at: label(client.last_request_at) || null })),
|
|
131
|
+
requests: entry.requests ? Object.fromEntries(["total", "active", "completed", "incomplete", "failed", "cancelled"].map(key => [key, finite(entry.requests[key])])) : null };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
111
135
|
export async function handleDashboardApi(req, res, pathname, {
|
|
112
136
|
env = process.env,
|
|
113
137
|
home = os.homedir(),
|
|
@@ -115,6 +139,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
115
139
|
usageSummaryFn,
|
|
116
140
|
authStatusFn = () => authStatus({ home }),
|
|
117
141
|
providerCatalogFn,
|
|
142
|
+
providerStateFn,
|
|
118
143
|
} = {}) {
|
|
119
144
|
if (!isLoopbackAddress(req.socket?.remoteAddress)
|
|
120
145
|
|| req.headers?.host === undefined
|
|
@@ -127,6 +152,12 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
127
152
|
return;
|
|
128
153
|
}
|
|
129
154
|
|
|
155
|
+
if (pathname === PROVIDERS_PATH && req.method === "GET") {
|
|
156
|
+
try { sendJson(res, 200, { source: "provider_status", providers: dashboardProviders(providerStateFn, authStatusFn) }); }
|
|
157
|
+
catch { sendJson(res, 500, { error: "Could not read provider status" }); }
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
130
161
|
if (pathname === AUTH_PATH && req.method === "GET") {
|
|
131
162
|
try {
|
|
132
163
|
const profile = authStatusFn()?.profiles?.codex;
|
|
@@ -194,7 +225,12 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
194
225
|
if (pathname === MODELS_PATH && req.method === "GET") {
|
|
195
226
|
const abort = createRequestAbort(req, res);
|
|
196
227
|
try {
|
|
197
|
-
const
|
|
228
|
+
const provider = new URL(req.url, "http://localhost").searchParams.get("provider") || "";
|
|
229
|
+
if (provider && (!isProviderId(provider) || !dashboardProviders(providerStateFn, authStatusFn).some(entry => entry.id === provider))) {
|
|
230
|
+
sendJson(res, 400, { error: "Select a registered provider" });return;
|
|
231
|
+
}
|
|
232
|
+
const catalog = await providerCatalogFn?.({ ...(provider ? { provider } : {}), signal: abort.signal })
|
|
233
|
+
|| await liveModelsFn({ signal: abort.signal, includeAll: true });
|
|
198
234
|
if (!Array.isArray(catalog?.models) || !Number.isFinite(catalog?.advertised)) {
|
|
199
235
|
throw new Error("Invalid live model catalog");
|
|
200
236
|
}
|
|
@@ -204,16 +240,21 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
204
240
|
checked_at: catalog.source === "catalog" ? catalog.checkedAt : new Date().toISOString(),
|
|
205
241
|
upstream_host: safeText(catalog?.upstreamHost || "GitHub Copilot", 120),
|
|
206
242
|
advertised: finite(catalog?.advertised),
|
|
207
|
-
selectable: models.length,
|
|
243
|
+
selectable: models.filter(model => model.selectable !== false).length,
|
|
208
244
|
models: models.slice(0, 500).map((model) => ({
|
|
209
245
|
id: safeText(model.id, 100),
|
|
210
246
|
vendor: safeText(model.vendor, 80),
|
|
211
247
|
endpoints: Array.isArray(model.endpoints) ? model.endpoints.filter((value) => ["responses", "chat", "messages"].includes(value)) : [],
|
|
212
248
|
preview: model.preview === true,
|
|
249
|
+
selectable: model.selectable !== false,
|
|
250
|
+
clients: Array.isArray(model.clients) ? model.clients.filter(value => typeof value === "string").slice(0, 8).map(value => safeText(value, 40)) : [],
|
|
251
|
+
reasoning_efforts: Array.isArray(model.reasoning_efforts) ? model.reasoning_efforts.slice(0, 16).map(value => safeText(value, 16)) : null,
|
|
252
|
+
state: ["listed", "restricted", "hidden"].includes(model.state) ? model.state : "listed",
|
|
253
|
+
context_window: finite(model.context_window),
|
|
213
254
|
})),
|
|
214
255
|
});
|
|
215
256
|
} catch (error) {
|
|
216
|
-
if (!res.destroyed && !res.writableEnded) sendJson(res, 502, { error: liveModelError(error) });
|
|
257
|
+
if (!res.destroyed && !res.writableEnded) sendJson(res, error.statusCode || 502, { error: /^m365_[a-z0-9_]+$/.test(error.code || "") ? `Model catalog unavailable / ${error.code}` : liveModelError(error) });
|
|
217
258
|
} finally { abort.cleanup(); }
|
|
218
259
|
return;
|
|
219
260
|
}
|
|
@@ -221,13 +262,13 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
221
262
|
if (pathname === USAGE_PATH && req.method === "GET") {
|
|
222
263
|
const query = new URL(req.url, "http://localhost").searchParams;
|
|
223
264
|
const provider = query.get("provider") || "";
|
|
224
|
-
if (provider && !
|
|
265
|
+
if (provider && !isProviderId(provider)) { sendJson(res, 400, { error: "Select a valid provider" });return; }
|
|
225
266
|
let analytics = null;
|
|
226
267
|
if (query.get("analytics") === "1") {
|
|
227
268
|
try {
|
|
228
269
|
const timeZone = query.get("time_zone") || "UTC";
|
|
229
270
|
if (timeZone.length > 100) throw new Error("Invalid time zone");
|
|
230
|
-
analytics = createUsageAnalytics({ timeZone });
|
|
271
|
+
analytics = createUsageAnalytics({ timeZone, qualifyProviders: !provider });
|
|
231
272
|
} catch {
|
|
232
273
|
sendJson(res, 400, { error: "Select a valid usage time zone" });
|
|
233
274
|
return;
|
package/src/live-models.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
|
+
import { publicModelCatalog } from "./provider-metadata.mjs";
|
|
2
3
|
import { createAbortAwareSingleflight } from "./bounded-result-cache.mjs";
|
|
3
4
|
import { githubTokenFingerprint } from "./github-identity.mjs";
|
|
4
5
|
import { validateGithubToken } from "./auth.mjs";
|
|
@@ -82,16 +83,17 @@ export async function fetchLiveCopilotModels({
|
|
|
82
83
|
timeoutMs = DEFAULT_MODELS_TIMEOUT_MS,
|
|
83
84
|
vscodeVersion = FALLBACK_VSCODE_VERSION,
|
|
84
85
|
signal,
|
|
86
|
+
includeAll = false,
|
|
85
87
|
} = {}) {
|
|
86
88
|
const credentials = readModelCredentials(home);
|
|
87
89
|
let flights = modelFlights.get(fetchImpl);
|
|
88
90
|
if (!flights) { flights = createAbortAwareSingleflight();modelFlights.set(fetchImpl, flights); }
|
|
89
|
-
const key = `${home}\0${githubTokenFingerprint(credentials.token)}\0${vscodeVersion}\0${timeoutMs}`;
|
|
90
|
-
const result = await flights.run(key, sharedSignal => lookupLiveModels(credentials, { fetchImpl, timeoutMs, vscodeVersion, signal: sharedSignal }), { signal });
|
|
91
|
+
const key = `${home}\0${githubTokenFingerprint(credentials.token)}\0${vscodeVersion}\0${timeoutMs}\0${includeAll}`;
|
|
92
|
+
const result = await flights.run(key, sharedSignal => lookupLiveModels(credentials, { fetchImpl, timeoutMs, vscodeVersion, includeAll, signal: sharedSignal }), { signal });
|
|
91
93
|
return structuredClone(result); // Independent callers retain independent catalog values.
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
async function lookupLiveModels(credentials, { fetchImpl, timeoutMs, vscodeVersion, signal }) {
|
|
96
|
+
async function lookupLiveModels(credentials, { fetchImpl, timeoutMs, vscodeVersion, includeAll, signal }) {
|
|
95
97
|
const controller = new AbortController();
|
|
96
98
|
const cancel = () => controller.abort(signal.reason);
|
|
97
99
|
signal.addEventListener("abort", cancel, { once: true });
|
|
@@ -135,6 +137,12 @@ async function lookupLiveModels(credentials, { fetchImpl, timeoutMs, vscodeVersi
|
|
|
135
137
|
throw new Error("Copilot models endpoint returned invalid JSON");
|
|
136
138
|
}
|
|
137
139
|
const catalog = selectableCopilotModels(payload);
|
|
140
|
+
if (includeAll) {
|
|
141
|
+
const selected = new Set(catalog.models.map(model => model.id));
|
|
142
|
+
catalog.models = publicModelCatalog(Array.isArray(payload) ? payload : payload.data, {
|
|
143
|
+
selectable: model => selected.has(model.id), clients: model => selected.has(model.id) ? ["codex"] : [],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
138
146
|
let upstreamHost = "GitHub Copilot";
|
|
139
147
|
try { upstreamHost = new URL(apiBase).hostname; } catch {}
|
|
140
148
|
return { ...catalog, profile: AUTH_PROFILE_CODEX, upstreamHost: safeText(upstreamHost, "GitHub Copilot") };
|
package/src/optional-routes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const DASHBOARD_PATHS = new Set(["/", "/ui.css", "/theme.js", "/language.js", "/refresh.js", "/status.js", "/usage.js", "/ui.js"]);
|
|
2
|
-
export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth"]);
|
|
2
|
+
export const DASHBOARD_API_PATHS = new Set(["/_ccdx/ui/animation", "/_ccdx/ui/models/live", "/_ccdx/ui/usage", "/_ccdx/ui/auth", "/_ccdx/ui/providers"]);
|
|
3
3
|
|
|
4
4
|
export function isOptionalRoute(method, pathname) {
|
|
5
5
|
return DASHBOARD_API_PATHS.has(pathname) || pathname === "/mcp/image"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Public metadata only. Credentials and provider transport never enter this layer.
|
|
2
|
+
export const isProviderId = value => typeof value === "string" && /^[a-z][a-z0-9_-]{0,63}$/.test(value)
|
|
3
|
+
&& !["constructor", "prototype"].includes(value);
|
|
4
|
+
|
|
5
|
+
export function modelReasoningEfforts(model) {
|
|
6
|
+
const values = model?.capabilities?.supports?.reasoning_effort;
|
|
7
|
+
return Array.isArray(values) ? [...new Set(values.filter(value => typeof value === "string" && /^[a-z][a-z0-9_-]{0,15}$/.test(value)))].slice(0, 16) : null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function publicModelCatalog(models, { clients = () => [], selectable = () => false } = {}) {
|
|
11
|
+
return models.slice(0, 1000).filter(model => typeof model?.id === "string").map(model => ({
|
|
12
|
+
id: model.id, vendor: model.publisher || model.vendor || model.owned_by || "Unknown",
|
|
13
|
+
endpoints: [["responses", ["/responses", "/v1/responses"]], ["chat", ["/chat/completions", "/v1/chat/completions"]],
|
|
14
|
+
["messages", ["/v1/messages"]]].filter(([, paths]) => paths.some(path => model.supported_endpoints?.includes(path))).map(([label]) => label),
|
|
15
|
+
preview: model.preview === true, selectable: selectable(model), clients: clients(model),
|
|
16
|
+
reasoning_efforts: modelReasoningEfforts(model),
|
|
17
|
+
context_window: Number.isSafeInteger(model.capabilities?.limits?.max_context_window_tokens)
|
|
18
|
+
&& model.capabilities.limits.max_context_window_tokens > 0 ? model.capabilities.limits.max_context_window_tokens : null,
|
|
19
|
+
state: model.policy?.state && model.policy.state !== "enabled" ? "restricted" : model.model_picker_enabled === false ? "hidden" : "listed",
|
|
20
|
+
}));
|
|
21
|
+
}
|
package/src/provider-runtime.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { publicModelCatalog } from "./provider-metadata.mjs";
|
|
2
3
|
import { createGithubProvider } from "./providers/github.mjs";
|
|
3
4
|
import { readProviderSettings, writeProviderSettings } from "./provider-settings.mjs";
|
|
4
5
|
import { readM365Settings, updateM365Settings, m365Paths, ensureM365GatewayKey, M365_GATEWAY_PORT } from "./m365-settings.mjs";
|
|
@@ -15,11 +16,36 @@ export function createProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
15
16
|
return value ? `codex:${value}` : "codex"; } }), registry: githubRegistry };
|
|
16
17
|
let selection = readProviderSettings(options), m365 = null, gateway = null, pending = null, closed = false, serial = null;
|
|
17
18
|
let reason = null, claudeReason = null, clients = { code: "not_configured", app: "not_configured" }, lastClients = {};
|
|
19
|
+
const dashboardProfiles = new Map();
|
|
20
|
+
const dashboardGeneration = provider => {
|
|
21
|
+
const profile = provider.profileId(), previous = dashboardProfiles.get(provider.id);
|
|
22
|
+
if (!previous || previous.profile !== profile) dashboardProfiles.set(provider.id, { profile, generation: (previous?.generation || 0) + 1 });
|
|
23
|
+
return dashboardProfiles.get(provider.id).generation;
|
|
24
|
+
};
|
|
18
25
|
const sessions = new Map();let priorNamespace = null, requestOrder = 0, activeM365Requests = 0;
|
|
19
26
|
let enabled;
|
|
20
27
|
try { enabled = readM365Settings(options).enabled && env.CCDX_M365 !== "0"; }
|
|
21
28
|
catch { enabled = false;reason = "m365_config_invalid"; }
|
|
22
29
|
|
|
30
|
+
let clientSync = null;
|
|
31
|
+
async function syncClaudeClients() {
|
|
32
|
+
if (clientSync) return clientSync;
|
|
33
|
+
clientSync = (async () => {
|
|
34
|
+
const source = m365, profile = source?.profileId();
|
|
35
|
+
if (!source || !gateway || closed || !enabled) return;
|
|
36
|
+
try {
|
|
37
|
+
const integration = configureClients ? null : await import("./claude-client-config.mjs");
|
|
38
|
+
const configure = configureClients || integration.configureClaudeClients;
|
|
39
|
+
const desktopManaged = integration ? await integration.inspectClaudeDesktopPolicy(options) : false;
|
|
40
|
+
if (closed || !enabled || source !== m365 || source.profileId() !== profile || !gateway) return;
|
|
41
|
+
claudeReason = source.models("claude").length ? null : "m365_no_claude_models";
|
|
42
|
+
clients = configure({ ...options, desktopManaged, baseUrl: `http://127.0.0.1:${gateway.port}`,
|
|
43
|
+
apiKey: ensureM365GatewayKey(options), models: source.models("claude") });
|
|
44
|
+
} catch { clients = { code: "configuration_unavailable", app: "configuration_unavailable" };claudeReason = "m365_claude_config_unavailable"; }
|
|
45
|
+
})().finally(() => { clientSync = null; });
|
|
46
|
+
return clientSync;
|
|
47
|
+
}
|
|
48
|
+
|
|
23
49
|
async function startM365(forceRefresh = false) {
|
|
24
50
|
if (closed || !enabled || !["darwin", "win32"].includes(platform)) return null;
|
|
25
51
|
if (pending) return pending;
|
|
@@ -28,7 +54,10 @@ export function createProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
28
54
|
if (!m365) {
|
|
29
55
|
const factory = createM365 || (await import("./providers/m365.mjs")).createM365Provider;
|
|
30
56
|
if (closed || !enabled) return null;
|
|
31
|
-
m365 = factory({ home, env, log
|
|
57
|
+
m365 = factory({ home, env, log, onCatalog() {
|
|
58
|
+
// Reconcile after refresh, outside inference serialization and without a watcher.
|
|
59
|
+
setImmediate(() => { if (!pending && gateway && !closed && enabled) void syncClaudeClients(); });
|
|
60
|
+
} });
|
|
32
61
|
}
|
|
33
62
|
await m365.refresh();if (closed || !enabled) return null;
|
|
34
63
|
const claudeModels = m365.models("claude");
|
|
@@ -43,13 +72,7 @@ export function createProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
43
72
|
if (closed || !enabled) { await opened.close();return null; }
|
|
44
73
|
gateway = opened;
|
|
45
74
|
}
|
|
46
|
-
|
|
47
|
-
const integration = configureClients ? null : await import("./claude-client-config.mjs");
|
|
48
|
-
const configure = configureClients || integration.configureClaudeClients;
|
|
49
|
-
const desktopManaged = integration ? await integration.inspectClaudeDesktopPolicy(options) : false;
|
|
50
|
-
if (closed || !enabled) return null;
|
|
51
|
-
clients = configure({ ...options, desktopManaged, baseUrl: `http://127.0.0.1:${gateway.port}`, apiKey, models: claudeModels });
|
|
52
|
-
} catch { clients = { code: "configuration_unavailable", app: "configuration_unavailable" };claudeReason = "m365_claude_config_unavailable"; }
|
|
75
|
+
await syncClaudeClients();
|
|
53
76
|
} catch (error) {
|
|
54
77
|
claudeReason = error.code === "EADDRINUSE" ? "m365_gateway_port_busy" : "m365_claude_setup_unavailable";
|
|
55
78
|
log("warn", `Claude setup unavailable: ${claudeReason}; M365 GPT routing is independent`);
|
|
@@ -124,13 +147,37 @@ export function createProviderRuntime({ githubClient, githubRegistry, githubCred
|
|
|
124
147
|
return {
|
|
125
148
|
github, current, snapshot, start: startM365, refresh: () => startM365(true),
|
|
126
149
|
selection: () => selection,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
150
|
+
dashboardProviders() {
|
|
151
|
+
const state = snapshot(), service = githubClient.runtimeStatus?.() || {}, ms = state.m365;
|
|
152
|
+
return [
|
|
153
|
+
{ id: "github", name: "GitHub Copilot", generation: dashboardGeneration(github), enabled: true, state: service.token_cached ? "ready" : "unknown",
|
|
154
|
+
auth: { state: "unknown", token_cached: service.token_cached === true, expires_in_ms: service.token_expires_in_ms ?? null },
|
|
155
|
+
models: { count: githubRegistry?.models?.data?.length ?? null, source: githubRegistry?.source || "unknown" },
|
|
156
|
+
clients: [{ id: "codex", name: "Codex App", selected: selection.codex === "github", state: "configured" }] },
|
|
157
|
+
{ id: "m365", name: "Microsoft 365", generation: m365 ? dashboardGeneration(m365) : 0, enabled, state: ms.state, reason: ms.reason,
|
|
158
|
+
auth: { state: ms.token_cached ? "authorized" : !enabled ? "disabled" : ms.reason ? "unavailable" : "unknown",
|
|
159
|
+
account: ms.account?.login || "", token_cached: ms.token_cached === true,
|
|
160
|
+
expires_in_ms: ms.token_expires_in_ms ?? null, checked_at: ms.token_checked_at || null },
|
|
161
|
+
models: { count: ms.models?.total ?? null, source: ms.models?.source || "unavailable", checked_at: ms.models?.refreshed_at || null },
|
|
162
|
+
clients: [{ id: "codex", name: "Codex App", selected: selection.codex === "m365", state: selection.codex === "m365" ? ms.state : "standby" },
|
|
163
|
+
...[["code", "Claude Code"], ["app", "Claude App"]].map(([id, name]) => ({ id: `claude_${id}`, name,
|
|
164
|
+
selected: enabled, state: clients[id], gateway: gateway ? "running" : "unavailable", reason: claudeReason,
|
|
165
|
+
last_request_at: lastClients[`claude_${id}`] || null }))],
|
|
166
|
+
requests: ms.claude.requests },
|
|
167
|
+
];
|
|
168
|
+
},
|
|
169
|
+
async dashboardCatalog({ provider = selection.codex } = {}) {
|
|
170
|
+
if (provider === "github") return null;
|
|
171
|
+
if (provider !== "m365") throw Object.assign(new Error("Unknown provider"), { statusCode: 400 });
|
|
172
|
+
if (!enabled || !["darwin", "win32"].includes(platform)) throw unavailable(!enabled ? "m365_disabled" : "m365_unsupported");
|
|
173
|
+
if (!m365) throw unavailable(reason || "m365_not_ready");
|
|
174
|
+
await m365.refresh();
|
|
175
|
+
const eligible = new Set([...m365.models("gpt"), ...m365.models("claude")]);
|
|
176
|
+
return { source: "catalog", checkedAt: m365.snapshot().models.refreshed_at, upstreamHost: "Microsoft 365",
|
|
177
|
+
advertised: m365.catalog().length, models: publicModelCatalog(m365.catalog(), {
|
|
178
|
+
selectable: model => eligible.has(model),
|
|
179
|
+
clients: model => !eligible.has(model) ? [] : model.publisher?.toLowerCase() === "anthropic" ? ["claude_code", "claude_app"] : ["codex"],
|
|
180
|
+
}) };
|
|
134
181
|
},
|
|
135
182
|
track(target) {
|
|
136
183
|
if (target.id !== "m365") return undefined;
|