codex-copilot-dx 0.9.41 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/bin/cli.mjs +38 -11
- package/docs/ARCHITECTURE.md +62 -8
- package/docs/REFERENCE.md +161 -4
- package/package.json +4 -1
- package/src/adapter.mjs +83 -22
- package/src/auto-review-model.mjs +4 -3
- package/src/claude-client-config.mjs +217 -0
- package/src/claude-gateway.mjs +163 -0
- package/src/cli-m365.mjs +133 -0
- package/src/cli-models.mjs +1 -1
- package/src/cli-options.mjs +20 -6
- package/src/cli-status.mjs +6 -0
- package/src/codex-model-catalog.mjs +7 -2
- package/src/copilot-responses-policy.mjs +2 -64
- package/src/dashboard/index.html +11 -1
- package/src/dashboard/language.js +26 -0
- package/src/dashboard/status.js +16 -2
- package/src/dashboard/ui.css +2 -2
- package/src/dashboard/ui.js +16 -7
- package/src/dashboard/usage.js +3 -1
- package/src/dashboard-api.mjs +10 -7
- package/src/doctor-repair.mjs +2 -0
- package/src/doctor.mjs +18 -2
- package/src/m365-settings.mjs +89 -0
- package/src/native-prediction-windows.mjs +2 -7
- package/src/profile-model-runtime.mjs +4 -2
- package/src/provider-management.mjs +28 -0
- package/src/provider-runtime.mjs +180 -0
- package/src/provider-settings.mjs +32 -0
- package/src/providers/github.mjs +62 -0
- package/src/providers/m365-auth-helper.mjs +72 -0
- package/src/providers/m365-auth.mjs +105 -0
- package/src/providers/m365-messages-policy.mjs +20 -0
- package/src/providers/m365-network.mjs +73 -0
- package/src/providers/m365.mjs +238 -0
- package/src/response-failures.mjs +4 -2
- package/src/response-history.mjs +20 -3
- package/src/responses-handler.mjs +40 -95
- package/src/responses-image-tools.mjs +61 -0
- package/src/responses-proxy.mjs +5 -5
- package/src/responses-request.mjs +25 -0
- package/src/stream-performance.mjs +7 -4
- package/src/usage-analysis.mjs +3 -2
- package/src/usage-store.mjs +41 -12
- package/src/usage.mjs +8 -2
- package/src/windows-http-network.mjs +122 -0
- package/src/windows-prediction-network.cs +13 -6
- package/src/windows-prediction-network.mjs +4 -108
- package/src/windows-process.mjs +8 -0
package/src/cli-m365.mjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { readM365Settings, updateM365Settings } from "./m365-settings.mjs";
|
|
3
|
+
import { readProviderSettings } from "./provider-settings.mjs";
|
|
4
|
+
import { autoReviewPreference } from "./user-settings.mjs";
|
|
5
|
+
import { PROVIDER_MANAGEMENT_PATH } from "./provider-management.mjs";
|
|
6
|
+
import { adapterBaseUrl } from "./running-adapter.mjs";
|
|
7
|
+
import { isLoopbackHost } from "./security.mjs";
|
|
8
|
+
import { terminalCell } from "./terminal-text.mjs";
|
|
9
|
+
import { readBoundedResponseText } from "./upstream-body.mjs";
|
|
10
|
+
import { parseAdapterAddressOptions } from "./cli-options.mjs";
|
|
11
|
+
import { autoReviewReasoningEfforts } from "./models.mjs";
|
|
12
|
+
|
|
13
|
+
export async function fetchActiveProviderModels({ control = providerControl, ...options } = {}) {
|
|
14
|
+
if (readProviderSettings(options).codex !== "m365") {
|
|
15
|
+
const { fetchLiveCopilotModels } = await import("./live-models.mjs");
|
|
16
|
+
return fetchLiveCopilotModels(options);
|
|
17
|
+
}
|
|
18
|
+
const address = parseAdapterAddressOptions(options.env || process.env);
|
|
19
|
+
const result = await control({ host: address.adapterHost, port: address.adapterPort, ...options, action: { action: "models", family: "gpt" } });
|
|
20
|
+
return { source: "catalog", upstreamHost: "Microsoft 365", advertised: result.models.length,
|
|
21
|
+
models: result.models.map(model => ({ id: model.id, vendor: model.publisher, endpoints: ["responses"], preview: false })) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function providerControl({ host = "127.0.0.1", port = 2026, action, fetchImpl = fetch, timeoutMs = 35000 } = {}) {
|
|
25
|
+
const url = `${adapterBaseUrl(isLoopbackHost(host) ? host : "127.0.0.1", port)}${PROVIDER_MANAGEMENT_PATH}`;
|
|
26
|
+
const response = await fetchImpl(url, { method: action ? "POST" : "GET", headers: { Accept: "application/json", ...(action ? { "Content-Type": "application/json" } : {}) },
|
|
27
|
+
...(action ? { body: JSON.stringify(action) } : {}), redirect: "error", signal: AbortSignal.timeout(timeoutMs) });
|
|
28
|
+
const value = JSON.parse(await readBoundedResponseText(response, { maxBytes: 4 * 1024 * 1024, label: "Provider status" }));
|
|
29
|
+
if (!response.ok) throw Object.assign(new Error(value.error?.message || "Provider management is unavailable; restart the updated CCDX service"), { code: value.error?.code || "ccdx_provider_management_unavailable" });
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function formatM365Status(state) {
|
|
34
|
+
const m = state.m365 || {}, claude = m.claude || {}, models = m.models || {};
|
|
35
|
+
return [
|
|
36
|
+
`Microsoft 365: ${terminalCell(m.state || "not running")}${m.reason ? ` (${terminalCell(m.reason)})` : ""}`,
|
|
37
|
+
...(m.account?.login ? [`Account: ${terminalCell(m.account.login)}`] : []),
|
|
38
|
+
`Models: ${models.claude || 0} Claude / ${models.gpt || 0} GPT (${models.source || "unavailable"})`,
|
|
39
|
+
`Claude gateway: ${claude.gateway || "not running"}${claude.port ? ` / http://127.0.0.1:${claude.port}` : ""}`,
|
|
40
|
+
...(claude.reason ? [`Claude detail: ${terminalCell(claude.reason)}`] : []),
|
|
41
|
+
...(claude.requests ? [`Claude requests: ${claude.requests.completed} completed / ${claude.requests.incomplete} incomplete / ${claude.requests.failed} failed / ${claude.requests.active} active`] : []),
|
|
42
|
+
`Claude Code: ${claude.clients?.code || "unknown"}; Claude App: ${claude.clients?.app || "unknown"}`,
|
|
43
|
+
`Codex provider: ${state.codex_provider || "github"} (default: github)`,
|
|
44
|
+
].join("\n");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function runProviderAutoReviewCommand(options = {}) {
|
|
48
|
+
const { runAutoReviewModelCommand } = await import("./auto-review-model.mjs");
|
|
49
|
+
const settings = readProviderSettings(options);
|
|
50
|
+
if (settings.codex !== "m365") return runAutoReviewModelCommand(options);
|
|
51
|
+
const state = await providerControl(options);
|
|
52
|
+
if (state.codex_provider !== "m365") throw new Error("The running provider does not match the saved selection; restart ccdx before changing Auto-review");
|
|
53
|
+
const preference = state.m365?.preference || settings.m365;
|
|
54
|
+
return runAutoReviewModelCommand({ ...options, env: { ...(options.env || process.env), CCDX_AUTO_REVIEW_MODEL: "" },
|
|
55
|
+
loadCatalog: async () => {
|
|
56
|
+
const result = await providerControl({ ...options, action: { action: "models", family: "gpt" } });
|
|
57
|
+
return { modelIds: result.models.map(model => model.id), source: "Microsoft 365",
|
|
58
|
+
reasoningEfforts: Object.fromEntries(result.models.map(model => [model.id, autoReviewReasoningEfforts(model)])) };
|
|
59
|
+
},
|
|
60
|
+
getPreference: () => ({ model: preference.auto_review_model, source: "m365", reasoningEffort: preference.auto_review_effort === undefined ? "low" : preference.auto_review_effort }),
|
|
61
|
+
savePreference: (model, { reasoningEffort }) => providerControl({ ...options, action: { action: "auto-review", model, effort: reasoningEffort } }),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function runM365Command({ action = "status", provider, model, autoReviewModel, host, port, home,
|
|
66
|
+
env = process.env, input = process.stdin, output = process.stdout, prompt, control = providerControl } = {}) {
|
|
67
|
+
const options = { home, env };
|
|
68
|
+
let readline;
|
|
69
|
+
const ask = prompt || (question => { if (!input.isTTY || !output.isTTY) throw new Error("Use explicit provider/model arguments outside an interactive terminal");
|
|
70
|
+
readline ||= createInterface({ input, output });return readline.question(question); });
|
|
71
|
+
const request = value => control({ host, port, action: value });
|
|
72
|
+
try {
|
|
73
|
+
if (action === "status") {
|
|
74
|
+
try { const state = await request();output.write(formatM365Status(state) + "\n");return state; }
|
|
75
|
+
catch (error) {
|
|
76
|
+
const saved = readM365Settings(options), selected = readProviderSettings(options);
|
|
77
|
+
output.write(`Microsoft 365 preference: ${saved.enabled ? "auto" : "off"}\nCodex provider: ${selected.codex}\nRuntime status unavailable; start or restart ccdx to inspect it.\n`);
|
|
78
|
+
return { saved: true, runtime: "unavailable" };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (action === "switch") {
|
|
82
|
+
if (!provider) {
|
|
83
|
+
output.write("Codex provider:\n 1. GitHub Copilot (default)\n 2. Microsoft 365 (backup)\n");
|
|
84
|
+
const answer = String(await ask("Select 1 or 2, or q to cancel: ")).trim();
|
|
85
|
+
if (answer === "q") return { cancelled: true };
|
|
86
|
+
if (!["1", "2"].includes(answer)) throw new Error("Select 1 or 2");provider = answer === "1" ? "github" : "m365";
|
|
87
|
+
}
|
|
88
|
+
if (provider === "m365") {
|
|
89
|
+
const available = await request({ action: "models", family: "gpt" });
|
|
90
|
+
const models = available.models || [], ids = models.map(entry => entry.id);
|
|
91
|
+
if (!ids.length) throw new Error("No M365 GPT models are available; the current provider was retained");
|
|
92
|
+
const saved = readProviderSettings(options).m365;
|
|
93
|
+
const choose = async (label, supplied, preferred) => {
|
|
94
|
+
if (supplied) { if (!ids.includes(supplied)) throw new Error(`${label} model is not available: ${terminalCell(supplied)}`);return supplied; }
|
|
95
|
+
const current = ids.includes(preferred) ? preferred : null;
|
|
96
|
+
if (!prompt && (!input.isTTY || !output.isTTY)) {
|
|
97
|
+
if (current) return current;
|
|
98
|
+
throw new Error(`Specify --${label === "Auto-review" ? "auto-review-model" : "model"} with an available M365 model: ${ids.join(", ")}`);
|
|
99
|
+
}
|
|
100
|
+
output.write(`${label} model:\n${ids.map((id, index) => ` ${index + 1}. ${id}${id === current ? " [current]" : ""}`).join("\n")}\n`);
|
|
101
|
+
const answer = String(await ask(`Select a model${current ? ` [${ids.indexOf(current) + 1}]` : ""}, or q to cancel: `)).trim();
|
|
102
|
+
if (answer === "q") return null;
|
|
103
|
+
const index = answer === "" && current ? ids.indexOf(current) : Number(answer) - 1;
|
|
104
|
+
if (!Number.isInteger(index) || !ids[index]) throw new Error("Invalid model selection");return ids[index];
|
|
105
|
+
};
|
|
106
|
+
model = await choose("Codex", model, saved?.model);if (!model) return { cancelled: true };
|
|
107
|
+
autoReviewModel = await choose("Auto-review", autoReviewModel, saved?.auto_review_model || autoReviewPreference(options).model);
|
|
108
|
+
if (!autoReviewModel) return { cancelled: true };
|
|
109
|
+
output.write("M365 fast tier is not verified. Use Standard in Codex; existing threads keep their selected model until you change it.\n");
|
|
110
|
+
}
|
|
111
|
+
const state = await request({ action: "switch", provider, model, auto_review_model: autoReviewModel });
|
|
112
|
+
output.write(formatM365Status(state) + "\n");
|
|
113
|
+
if (provider === "m365") output.write(`Select ${model} in Codex. Auto-review uses ${autoReviewModel} / low on this provider.\n`);
|
|
114
|
+
return state;
|
|
115
|
+
}
|
|
116
|
+
if (action === "models") {
|
|
117
|
+
const value = await request({ action: "models", family: "claude" });
|
|
118
|
+
output.write((value.models || []).map(model => terminalCell(model.id)).join("\n") + "\n");return value;
|
|
119
|
+
}
|
|
120
|
+
if (["on", "off", "remove"].includes(action)) {
|
|
121
|
+
try { const state = await request({ action });output.write(formatM365Status(state) + "\n");return state; }
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error.cause?.code !== "ECONNREFUSED") throw error;
|
|
124
|
+
if (action === "on") { updateM365Settings({ enabled: true }, options);output.write("M365 auto-discovery enabled. Run ccdx to start it.\n");return; }
|
|
125
|
+
const { createProviderRuntime } = await import("./provider-runtime.mjs");
|
|
126
|
+
const runtime = createProviderRuntime({ ...options });
|
|
127
|
+
try { const state = await runtime.action({ action });output.write(formatM365Status(state) + "\n");return state; }
|
|
128
|
+
finally { await runtime.close(); }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
throw new Error("Unknown M365 action");
|
|
132
|
+
} finally { readline?.close(); }
|
|
133
|
+
}
|
package/src/cli-models.mjs
CHANGED
|
@@ -21,7 +21,7 @@ function liveCatalogHeader(catalog, { commandName, models }) {
|
|
|
21
21
|
const chat = models.filter((model) => model.endpoints.includes("chat")).length;
|
|
22
22
|
return [
|
|
23
23
|
`${commandName} models`,
|
|
24
|
-
status("ok",
|
|
24
|
+
status("ok", `${catalog?.source === "catalog" ? "Available catalog" : "Live catalog"} from ${safeText(catalog?.upstreamHost, "GitHub Copilot")}: ${models.length} selectable GPT models of ${Number(catalog?.advertised) || 0} advertised`),
|
|
25
25
|
status("info", `Responses: ${responses}; Chat: ${chat}`),
|
|
26
26
|
];
|
|
27
27
|
}
|
package/src/cli-options.mjs
CHANGED
|
@@ -29,6 +29,7 @@ const HELP_TOPICS = new Set([
|
|
|
29
29
|
"auto-review-model",
|
|
30
30
|
"suggestion",
|
|
31
31
|
"prediction",
|
|
32
|
+
"m365",
|
|
32
33
|
"update",
|
|
33
34
|
"version",
|
|
34
35
|
]);
|
|
@@ -151,13 +152,23 @@ export function parseCliArgs(args = []) {
|
|
|
151
152
|
return baseCommand("version");
|
|
152
153
|
}
|
|
153
154
|
if (command === "start") return parseStartOptions(rest);
|
|
155
|
+
if (command === "m365") {
|
|
156
|
+
const [action = "status", ...args] = rest;
|
|
157
|
+
if (!["status", "models", "switch", "on", "off", "remove"].includes(action)) throw new Error("M365 action must be status, models, switch, on, off or remove");
|
|
158
|
+
let provider, remaining = args;
|
|
159
|
+
if (action === "switch" && args[0] && !args[0].startsWith("--")) { provider = args[0];remaining = args.slice(1); }
|
|
160
|
+
if (provider && !["github", "m365"].includes(provider)) throw new Error("Provider must be github or m365");
|
|
161
|
+
const values = parseOptions(remaining, new Map(action === "switch" ? [["--model", "value"], ["--auto-review-model", "value"]] : []));
|
|
162
|
+
return baseCommand("m365", { action, provider, model: values["--model"], autoReviewModel: values["--auto-review-model"] });
|
|
163
|
+
}
|
|
154
164
|
if (command === "status" || command === "--status") {
|
|
155
165
|
if (rest.length) unexpectedArgs(rest);
|
|
156
166
|
return baseCommand("status");
|
|
157
167
|
}
|
|
158
168
|
if (command === "usage") {
|
|
159
|
-
const options = parseOptions(rest, new Map([["--format", "value"]]));
|
|
160
|
-
|
|
169
|
+
const options = parseOptions(rest, new Map([["--format", "value"], ["--provider", "value"]]));
|
|
170
|
+
if (options["--provider"] && !["github", "m365"].includes(options["--provider"])) throw new Error("Usage provider must be github or m365");
|
|
171
|
+
return baseCommand("usage", { ...outputFormatOption(options["--format"]), ...(options["--provider"] ? { provider: options["--provider"] } : {}) });
|
|
161
172
|
}
|
|
162
173
|
if (command === "cache") {
|
|
163
174
|
let cacheArgs = rest;
|
|
@@ -370,8 +381,8 @@ function topicHelp(name, topic) {
|
|
|
370
381
|
doctor: `Usage:\n ${name} doctor [--online] [--compat] [--fix] [--json]\n ${name} doctor config\n\nChecks credentials, managed configuration, command launchers, adapter, enabled optional features and observed client catalog. Default is read-only; no inference requests. --online validates account entitlement; --compat sends minimal inference requests and consumes a small amount of Copilot usage, requiring successful model completion rather than HTTP 200 alone. --fix repairs owned Windows launchers and managed config, imports a verified existing credential only if none is saved, and asks the running adapter to repair enabled predictions once. No interactive login, client program edits, forced App restarts, policy changes or optional feature activation. Missing-credential repair can contact GitHub without --online. Changed existing config is backed up to config.toml.ccdx-doctor.bak. Partial repairs exit 1. --json emits a redacted report, including before_checks for repairs. App-internal cache and visible predictions are not externally verified. The config subcommand remains strictly read-only.`,
|
|
371
382
|
"doctor config": `Usage:\n ${name} doctor config\n\nReads ~/.codex/config.toml, checks TOML syntax and CCDX-managed settings, and previews the existing startup writer's changes. Does not merge Codex profiles or validate the complete installed Codex schema. No authentication, network requests, file writes, or adapter/GUI startup. Existing context_management=false is valid. Exit 1 for errors, 0 for OK/warnings; unsupported arguments exit 2.`,
|
|
372
383
|
status: `Usage:\n ${name} status\n\nShows bounded runtime, routing, performance, queue, and cache metrics from a running adapter.`,
|
|
373
|
-
models: `Usage:\n ${name} models [--format table|plain]\n\
|
|
374
|
-
usage: `Usage:\n ${name} usage [--format table|plain]\n\nSummarizes local token usage metadata without reading prompt or completion content. Interactive terminals use a table by default.`,
|
|
384
|
+
models: `Usage:\n ${name} models [--format table|plain]\n\nShows GPT models for the selected Codex provider. GitHub performs a fresh read-only lookup; M365 uses its isolated catalog in the running service. Interactive terminals use a table by default.`,
|
|
385
|
+
usage: `Usage:\n ${name} usage [--format table|plain] [--provider github|m365]\n\nSummarizes local token usage metadata without reading prompt or completion content. Optional provider filtering separates sources; default totals include both. Interactive terminals use a table by default.`,
|
|
375
386
|
cache: `Usage:\n ${name} cache\n ${name} cache --limit <MiB|default>\n ${name} cache --clean [--history] [--yes]\n\nShows runtime cache use, saves and applies the shared response-history limit, or clears the rebuildable image-transform cache. --history also clears in-memory response history for all tasks and can make their next continuation fail, so interactive confirmation or --yes is required. Generated image files and saved Codex transcripts are never deleted. Short aliases: -128 sets 128 MiB and -clean equals --clean.`,
|
|
376
387
|
limits: `Usage:\n ${name} limits\n ${name} limits --decoded <MiB|default>\n\nShows configured and running request-body limits, or saves a decoded request-body limit from 128 to 512 MiB. The raw-body limit is unchanged. Restart ccdx to apply a saved change; no conversation or cache is cleared. Short alias: -256 sets 256 MiB.`,
|
|
377
388
|
animation: `Usage:\n ${name} animation\n\nPreviews all terminal activity animations together and selects the theme used the next time the adapter starts.`,
|
|
@@ -380,6 +391,7 @@ function topicHelp(name, topic) {
|
|
|
380
391
|
"image-status": `Usage:\n ${name} image-status\n\nShows provider configuration and locally advertised generation/editing tools without generating an image or exposing its API key.`,
|
|
381
392
|
"auto-review-model": `Usage:\n ${name} auto-review-model\n\nSelect a Responses model, then an advertised reasoning effort. Enter keeps the default/current choice; q cancels both steps without saving. Effort 0 follows the client (low when omitted). Settings apply only to Auto-review on the next request; no client patch or restart is required for adapters running 0.9.13 or newer.`,
|
|
382
393
|
"suggestion": `The CCDX prediction panel has been retired. Run ${name} suggestion off to safely remove unchanged CCDX registrations. This cleanup does not change native predictions; see ${name} prediction --help for that separate opt-in feature.`,
|
|
394
|
+
m365: `Usage:\n ${name} m365 [status|models|on|off|remove]\n ${name} m365 switch [github|m365] [--model ID] [--auto-review-model ID]\n\nM365 is discovered silently at startup on supported managed environments. Claude uses its separate local gateway. Codex stays on GitHub unless you explicitly switch. M365 switching requires a running compatible adapter and available GPT/Auto-review choices; it never substitutes unavailable models. Select an available model in Codex after switching an existing thread. Off restores only owned Claude settings and selects GitHub. Remove also clears the CCDX M365 profile, retaining a disabled preference and historical usage. System Microsoft sign-in, GitHub credentials, predictions and images are preserved.`,
|
|
383
395
|
prediction: `Usage:\n ${name} prediction [status|on|off|fix]\n\nOptional native next-message predictions; off by default. macOS and Windows. Windows requires the registered official MSIX App, an initialized profile, Windows PowerShell and .NET Framework 4.7.2+; Git/OpenSSL is not required for prediction setup. Quit Codex before on/off, then restart ccdx. On adds private App-profile certificate trust and an App-only route for chatgpt.com and ab.chatgpt.com. HTTPS on those hosts is decrypted locally; only prediction configuration is changed. No client program files, OS trust, account permissions, MCP or Hooks are changed. Static HTTP/HTTPS/SOCKS5 proxies and bypass rules are preserved. Windows supports company PAC/WPAD; macOS dynamic PAC/WPAD remains unsupported. Static IPv4/IPv6 CIDRs match URL IP literals without DNS. The bridge port persists across restarts/updates; a busy saved port disables only predictions. Launch/reuse checks the App's actual route; an older random or missing route may require one full App quit. Official prediction configuration is preserved; the conversation's model is used. App updates require another compatibility check. Status distinguishes saved preference and observed config traffic from unverified candidate visibility.\n\nFix asks a compatible running CCDX adapter to repair the enabled bridge once on its saved port. It never enables predictions, renews certificates or force-restarts Codex. Healthy unchanged bridges are retained. Fix rechecks system proxy settings. Changed routes may need a normal App relaunch to reload cached PAC; failed rechecks preserve the previous bridge with a nonzero exit. Process environment variables and Node trust are not hot-reloaded; changed trust inputs need a CCDX service restart. Startup, status and doctor share sanitized environment diagnostics. Missing App routes require a normal full quit and ccdx launch; partial repair exits 1. An older adapter must first be upgraded and restarted once to gain this repair endpoint.`,
|
|
384
396
|
update: `Usage:\n ${name} update [npm|github] [--allow-remote]\n\nUpdates the global package from the configured npm registry or the latest stable GitHub release. With no source, an interactive terminal prompts for one. Windows uses system cmd.exe to run npm.cmd without changing PowerShell policy; use the .cmd entrypoint if scripts are blocked. GitHub installs require Git on PATH and dependencies may still use the configured npm registry. By default npm's remote-download policy is preserved. If npm reports EALLOWREMOTE for a trusted mirror tarball, --allow-remote explicitly permits URL dependencies for this one installation's entire dependency tree; it is not a hostname allowlist. No .npmrc, registry or persistent policy is changed, and failed installations are not retried automatically. Use this only if company policy permits it. Restart the running adapter after installation.`,
|
|
385
397
|
version: `Usage:\n ${name} --version`,
|
|
@@ -398,7 +410,7 @@ export function cliHelp(commandName = "ccdx", topic = "") {
|
|
|
398
410
|
${name} doctor config
|
|
399
411
|
${name} status
|
|
400
412
|
${name} models [--format table|plain]
|
|
401
|
-
${name} usage [--format table|plain]
|
|
413
|
+
${name} usage [--format table|plain] [--provider github|m365]
|
|
402
414
|
${name} cache [--limit <MiB|default> | --clean [--history] [--yes]]
|
|
403
415
|
${name} limits [--decoded <MiB|default>]
|
|
404
416
|
${name} animation
|
|
@@ -407,6 +419,7 @@ export function cliHelp(commandName = "ccdx", topic = "") {
|
|
|
407
419
|
${name} image-status
|
|
408
420
|
${name} auto-review-model
|
|
409
421
|
${name} prediction [status|on|off|fix]
|
|
422
|
+
${name} m365 [status|models|switch|on|off|remove]
|
|
410
423
|
${name} update [npm|github] [--allow-remote]
|
|
411
424
|
${name} --version
|
|
412
425
|
${name} --help
|
|
@@ -416,7 +429,7 @@ Commands:
|
|
|
416
429
|
auth Inspect the saved GitHub Copilot account
|
|
417
430
|
doctor Diagnose local config; optional live and inference checks
|
|
418
431
|
status Show runtime routing, performance, queue, and cache health
|
|
419
|
-
models
|
|
432
|
+
models Show the selected Codex provider's GPT model catalog
|
|
420
433
|
usage Summarize locally recorded token usage
|
|
421
434
|
cache Inspect, size, or clear bounded runtime caches
|
|
422
435
|
limits Inspect or configure the decoded request-body limit
|
|
@@ -426,6 +439,7 @@ Commands:
|
|
|
426
439
|
image-status Show the optional image provider status
|
|
427
440
|
auto-review-model Select the Codex Auto-review model and reasoning effort
|
|
428
441
|
prediction Toggle optional native next-message predictions
|
|
442
|
+
m365 Manage M365 Claude access and the optional Codex backup
|
|
429
443
|
update Update the global package from npm or GitHub
|
|
430
444
|
|
|
431
445
|
Run ${name} <command> --help for command details.`;
|
package/src/cli-status.mjs
CHANGED
|
@@ -71,6 +71,7 @@ function profileSummary(label, profile = {}) {
|
|
|
71
71
|
|
|
72
72
|
function routingTarget(value) {
|
|
73
73
|
if (value === "codex") return "Codex";
|
|
74
|
+
if (value === "m365") return "Codex (Microsoft 365 backup)";
|
|
74
75
|
return "unknown";
|
|
75
76
|
}
|
|
76
77
|
|
|
@@ -213,6 +214,11 @@ export function formatAdapterStatus({ baseUrl, data }, { commandName = "ccdx", c
|
|
|
213
214
|
if (data.routing?.responses) {
|
|
214
215
|
lines.push(status("info", `Routing: /v1/responses -> ${routingTarget(data.routing.responses)}`));
|
|
215
216
|
}
|
|
217
|
+
if (data.providers?.m365) {
|
|
218
|
+
const m365 = data.providers.m365;
|
|
219
|
+
lines.push(status("info", `Microsoft 365: ${terminalCell(m365.state)}; ${count(m365.models?.claude)} Claude, ${count(m365.models?.gpt)} GPT; gateway ${terminalCell(m365.claude?.gateway || "unavailable")}`));
|
|
220
|
+
if (m365.reason) lines.push(status("info", `Microsoft 365 detail: ${terminalCell(m365.reason)}`));
|
|
221
|
+
}
|
|
216
222
|
lines.push(status("info", `Limits: request body ${mebibytes(limits.max_body_bytes)}, decoded body ${mebibytes(limits.max_decoded_body_bytes)}`));
|
|
217
223
|
const recentContext = data.stream_performance?.recent_requests?.at(-1)?.context;
|
|
218
224
|
const contextValue = (value, format) => value === null || value === undefined ? "n/a" : format(value);
|
|
@@ -155,11 +155,16 @@ function insertByPriority(models, model) {
|
|
|
155
155
|
else models.splice(index, 0, model);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
export function buildCodexModelResponse({ copilotModels, codexCatalog } = {}) {
|
|
158
|
+
export function buildCodexModelResponse({ copilotModels, codexCatalog, restrictToUpstream = false } = {}) {
|
|
159
159
|
if (!copilotModelData(copilotModels) || !codexCatalogIsValid(codexCatalog)) return null;
|
|
160
160
|
|
|
161
161
|
const bundledSlugs = new Set(codexCatalog.models.map(({ slug }) => slug));
|
|
162
162
|
const models = codexCatalog.models.map((model) => {
|
|
163
|
+
if (restrictToUpstream) {
|
|
164
|
+
return isEligibleCopilotGpt6(copilotModels, model.slug)
|
|
165
|
+
? { ...catalogModelForCopilot(model, copilotModels, { filterReasoning: true }), upgrade: null }
|
|
166
|
+
: { ...model, visibility: "hide", upgrade: null };
|
|
167
|
+
}
|
|
163
168
|
if (!MANAGED_GPT6_MODELS.has(model.slug)) return model;
|
|
164
169
|
if (!isEligibleCopilotGpt6(copilotModels, model.slug)) return { ...model, visibility: "hide" };
|
|
165
170
|
return catalogModelForCopilot(model, copilotModels, { filterReasoning: model.slug === "gpt-6.1-sol" });
|
|
@@ -168,7 +173,7 @@ export function buildCodexModelResponse({ copilotModels, codexCatalog } = {}) {
|
|
|
168
173
|
if (bundledSlugs.has(slug) || !isEligibleCopilotGpt6(copilotModels, slug)) continue;
|
|
169
174
|
const model = compatibilityModel(codexCatalog, slug);
|
|
170
175
|
if (!model) continue;
|
|
171
|
-
insertByPriority(models, catalogModelForCopilot(model, copilotModels, { filterReasoning: true }));
|
|
176
|
+
insertByPriority(models, { ...catalogModelForCopilot(model, copilotModels, { filterReasoning: true }), ...(restrictToUpstream ? { upgrade: null } : {}) });
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
return { ...copilotModels, object: copilotModels.object || "list", models };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { errorEvidenceText } from "./operation-error.mjs";
|
|
2
|
+
import { removeNativeImageTools as applyCopilotResponsesRequestPolicies } from "./responses-image-tools.mjs";
|
|
3
|
+
export { removeNativeImageTools as applyCopilotResponsesRequestPolicies, isNativeImageTool as isCopilotImageNamespaceTool } from "./responses-image-tools.mjs";
|
|
2
4
|
|
|
3
5
|
function cloneJson(value) {
|
|
4
6
|
return value === undefined ? undefined : structuredClone(value);
|
|
@@ -43,70 +45,6 @@ export function isImageNamespaceCollisionError(statusCode, text) {
|
|
|
43
45
|
&& lower.includes("collid");
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
export function isCopilotImageNamespaceTool(tool, { collisionFallback = false } = {}) {
|
|
47
|
-
if (!tool || typeof tool !== "object") return false;
|
|
48
|
-
const type = String(tool.type || "").toLowerCase();
|
|
49
|
-
if (["image_gen", "image_generation"].includes(type)) return true;
|
|
50
|
-
if (!collisionFallback) return false;
|
|
51
|
-
const name = String(tool.name || tool.function?.name || "").toLowerCase();
|
|
52
|
-
const namespace = String(tool.namespace || "").toLowerCase();
|
|
53
|
-
if (["image_gen", "image_generation"].includes(name)) return true;
|
|
54
|
-
if (namespace === "image_gen" || namespace === "image_generation") return true;
|
|
55
|
-
return [type, name, namespace].some((value) => value.startsWith("image_gen"));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function toolName(tool) {
|
|
59
|
-
return String(tool?.name || tool?.function?.name || "").trim();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Copilot currently rejects the public image-generation tool. Keep this
|
|
63
|
-
// provider-owned policy paired with tool_choice so request invariants survive
|
|
64
|
-
// the removal. Revalidate against Copilot before deleting or broadening it.
|
|
65
|
-
// Reference: https://github.com/Menci/Floway/blob/ac2bbb04352033a7d9d74574a9d465d40395ef06/packages/provider-copilot/src/interceptors/openai-responses/strip-image-generation.ts
|
|
66
|
-
export function applyCopilotResponsesRequestPolicies(body, options = {}) {
|
|
67
|
-
if (!body || typeof body !== "object") return false;
|
|
68
|
-
const removedNames = new Set();
|
|
69
|
-
const survivingNames = new Set();
|
|
70
|
-
let survivingTools = 0;
|
|
71
|
-
let changed = false;
|
|
72
|
-
const filter = (container, topLevel = false) => {
|
|
73
|
-
if (!Array.isArray(container?.tools)) return;
|
|
74
|
-
const tools = container.tools;
|
|
75
|
-
const filtered = tools.filter((tool) => {
|
|
76
|
-
const removed = isCopilotImageNamespaceTool(tool, options);
|
|
77
|
-
const name = toolName(tool);
|
|
78
|
-
if (removed && name) removedNames.add(name);
|
|
79
|
-
if (!removed) {
|
|
80
|
-
survivingTools += 1;
|
|
81
|
-
if (name) survivingNames.add(name);
|
|
82
|
-
}
|
|
83
|
-
return !removed;
|
|
84
|
-
});
|
|
85
|
-
if (filtered.length === tools.length) return;
|
|
86
|
-
changed = true;
|
|
87
|
-
if (topLevel && !filtered.length) delete container.tools;
|
|
88
|
-
else container.tools = filtered;
|
|
89
|
-
};
|
|
90
|
-
filter(body, true);
|
|
91
|
-
for (const item of Array.isArray(body.input) ? body.input : []) {
|
|
92
|
-
if (["additional_tools", "tool_search_output"].includes(item?.type)) filter(item);
|
|
93
|
-
}
|
|
94
|
-
if (!changed) return false;
|
|
95
|
-
|
|
96
|
-
const removedChoice = (choice) => isCopilotImageNamespaceTool(choice, options)
|
|
97
|
-
|| (removedNames.has(toolName(choice)) && !survivingNames.has(toolName(choice)));
|
|
98
|
-
if (body.tool_choice?.type === "allowed_tools" && Array.isArray(body.tool_choice.tools)) {
|
|
99
|
-
const choices = body.tool_choice.tools.filter((choice) => !removedChoice(choice));
|
|
100
|
-
body.tool_choice = choices.length ? { ...body.tool_choice, tools: choices } : "none";
|
|
101
|
-
} else if (removedChoice(body.tool_choice)) {
|
|
102
|
-
if (survivingTools) body.tool_choice = "none";
|
|
103
|
-
else delete body.tool_choice;
|
|
104
|
-
} else if (body.tool_choice === "required" && !survivingTools) {
|
|
105
|
-
delete body.tool_choice;
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
48
|
export function sanitizeImageNamespaceCollisionRequest(reqContext) {
|
|
111
49
|
if (!Array.isArray(reqContext?.body?.tools)) return null;
|
|
112
50
|
const body = cloneJson(reqContext.body);
|
package/src/dashboard/index.html
CHANGED
|
@@ -51,6 +51,16 @@
|
|
|
51
51
|
<div class="panel-heading"><h2 data-i18n>IMAGE GENERATION</h2><span data-i18n>OPTIONAL</span></div>
|
|
52
52
|
<strong id="image">—</strong><p id="image-detail" class="hint">—</p>
|
|
53
53
|
</article>
|
|
54
|
+
<article class="panel">
|
|
55
|
+
<div class="panel-heading"><h2>Microsoft 365</h2><span data-i18n>SEPARATE PROFILE</span></div>
|
|
56
|
+
<strong id="m365-state">—</strong>
|
|
57
|
+
<p id="m365-account" class="hint">—</p>
|
|
58
|
+
<p id="m365-models" class="hint">—</p>
|
|
59
|
+
<p id="m365-claude" class="hint">—</p>
|
|
60
|
+
<p id="m365-requests" class="hint">—</p>
|
|
61
|
+
<p id="m365-clients" class="hint">—</p>
|
|
62
|
+
<p id="m365-codex" class="hint">—</p>
|
|
63
|
+
</article>
|
|
54
64
|
</section>
|
|
55
65
|
|
|
56
66
|
<details class="panel dashboard-section" id="client-features" open>
|
|
@@ -77,7 +87,7 @@
|
|
|
77
87
|
|
|
78
88
|
<details class="panel dashboard-section" id="model-usage" open>
|
|
79
89
|
<summary class="panel-heading"><h2 data-i18n>USAGE</h2><span id="usage-state" data-i18n>READING LOG</span></summary>
|
|
80
|
-
<div class="section-actions"><button id="clear-usage-day" type="button" hidden data-i18n>All history</button><button id="refresh-usage" type="button" data-i18n>Refresh</button></div>
|
|
90
|
+
<div class="section-actions"><label><span data-i18n>Source</span> <select id="usage-provider"><option value="" data-i18n>All providers</option><option value="github">GitHub Copilot</option><option value="m365">Microsoft 365</option></select></label><button id="clear-usage-day" type="button" hidden data-i18n>All history</button><button id="refresh-usage" type="button" data-i18n>Refresh</button></div>
|
|
81
91
|
<p id="usage-note" class="table-note" data-i18n>Aggregating local usage metadata…</p>
|
|
82
92
|
<div class="table-wrap"><table class="usage-table"><thead><tr><th scope="col" data-i18n>MODEL</th><th scope="col" data-i18n>CALLS</th><th scope="col" data-i18n>INPUT</th><th scope="col" data-i18n>CACHE READ</th><th scope="col" data-i18n>OUTPUT</th><th scope="col" data-i18n>TOTAL</th><th scope="col" data-i18n>CACHE HIT</th></tr></thead><tbody id="usage-body"><tr><td colspan="7" data-i18n>Loading…</td></tr></tbody></table></div>
|
|
83
93
|
<p class="hint" data-i18n>Cache hit = recorded cached / input tokens. ~ = incomplete history. — = unavailable or invalid counts.</p>
|
|
@@ -77,6 +77,32 @@
|
|
|
77
77
|
"History cache usage": ["Local history usage", "对话暂存"],
|
|
78
78
|
"IMAGE GENERATION": ["IMAGE GENERATION", "图片生成"],
|
|
79
79
|
"OPTIONAL": ["OPT-IN", "按需开启"],
|
|
80
|
+
"SEPARATE PROFILE": ["SEPARATE PROFILE", "独立授权"],
|
|
81
|
+
"Source": ["Source", "来源"],
|
|
82
|
+
"provider": ["Source", "来源"],
|
|
83
|
+
"CATALOG SNAPSHOT": ["SAVED CATALOG", "目录快照"],
|
|
84
|
+
"All providers": ["All providers", "全部来源"],
|
|
85
|
+
"M365 READY": ["AUTHORIZED", "已授权"],
|
|
86
|
+
"M365 CHECKING": ["CHECKING", "检查中"],
|
|
87
|
+
"M365 OFF": ["OFF", "已关闭"],
|
|
88
|
+
"M365 UNSUPPORTED": ["NOT SUPPORTED", "暂不支持"],
|
|
89
|
+
"M365 UNAVAILABLE": ["UNAVAILABLE", "未接入"],
|
|
90
|
+
"M365 UNKNOWN": ["UNKNOWN", "未知"],
|
|
91
|
+
"Account unavailable": ["Account unavailable", "暂无账号信息"],
|
|
92
|
+
"Claude {claude} / GPT {gpt}": ["Claude {claude} / GPT {gpt}", "Claude {claude}个 / GPT {gpt}个"],
|
|
93
|
+
"Claude gateway running": ["Claude gateway running", "Claude 网关已运行"],
|
|
94
|
+
"Claude gateway unavailable": ["Claude gateway unavailable", "Claude 网关未运行"],
|
|
95
|
+
"Claude: {done} done / {incomplete} incomplete / {failed} failed": ["Claude: {done} done / {incomplete} incomplete / {failed} failed", "完成 {done} / 未完成 {incomplete} / 失败 {failed}"],
|
|
96
|
+
"Claude requests unavailable": ["Claude requests unavailable", "暂无请求数据"],
|
|
97
|
+
"Code: {code} / App: {app}": ["Code: {code}\nApp: {app}", "Code:{code}\nApp:{app}"],
|
|
98
|
+
"Configured": ["Configured", "已配置"],
|
|
99
|
+
"Existing settings kept": ["Existing settings kept", "保留原配置"],
|
|
100
|
+
"Restored": ["Restored", "已恢复"],
|
|
101
|
+
"Not installed": ["Not installed", "未安装"],
|
|
102
|
+
"Setup unavailable": ["Setup unavailable", "配置失败"],
|
|
103
|
+
"Not configured": ["Not configured", "未配置"],
|
|
104
|
+
"Codex source: Microsoft 365": ["Codex source: Microsoft 365", "Codex:M365"],
|
|
105
|
+
"Codex source: GitHub Copilot": ["Codex source: GitHub Copilot", "Codex:GitHub Copilot"],
|
|
80
106
|
"Live upstream models": ["Online models", "在线模型"],
|
|
81
107
|
"UPSTREAM GPT MODELS": ["ONLINE MODELS", "在线模型"],
|
|
82
108
|
"CHECKING LIVE": ["CHECKING", "查询中"],
|
package/src/dashboard/status.js
CHANGED
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
error_type: failure.error_type, parameter: failure.parameter, error_body: failure.error_body,
|
|
79
79
|
diagnostic_message: failure.diagnostic_message, method: failure.method, target: failure.target,
|
|
80
80
|
request_options: failure.request_options ? JSON.stringify(failure.request_options) : undefined,
|
|
81
|
-
requested_model: failure.requested_model, request_kind: failure.request_kind,
|
|
81
|
+
requested_model: failure.requested_model, request_kind: failure.request_kind, provider: failure.provider || timeline?.provider,
|
|
82
82
|
attempt_timings: failure.attempt_timings || timeline?.attempts ? JSON.stringify(failure.attempt_timings || timeline.attempts) : undefined,
|
|
83
83
|
timings_ms: timingText };
|
|
84
84
|
const diagnostic = document.createElement("dl");
|
|
@@ -150,6 +150,20 @@
|
|
|
150
150
|
text("image-detail", image
|
|
151
151
|
? "active {active} / failed {failed} / delivery failures {delivery}"
|
|
152
152
|
: "Setup state unknown / ccdx image-status", { active: number(image?.active), failed: number(image?.failed), delivery: number(image?.delivery_failures) });
|
|
153
|
+
|
|
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
|
+
}
|
|
153
167
|
|
|
154
168
|
renderFailures([...(data.response_failures?.recent || []), ...(data.http_errors?.actionable_recent || data.http_errors?.recent || [])]
|
|
155
169
|
.sort((a, b) => (Date.parse(a.at) || 0) - (Date.parse(b.at) || 0)), data.stream_performance?.recent_requests);
|
|
@@ -187,7 +201,7 @@
|
|
|
187
201
|
? request.outcome[0].toUpperCase() + request.outcome.slice(1) : "Unknown";
|
|
188
202
|
const ratio = finite(context.input_tokens) && finite(context.context_window_tokens) && Number(context.context_window_tokens) > 0
|
|
189
203
|
? `${(100 * Number(context.input_tokens) / Number(context.context_window_tokens)).toFixed(1)}%` : "—";
|
|
190
|
-
body.append(tableRow([String(request.model || "unknown").slice(0, 80),
|
|
204
|
+
body.append(tableRow([String(request.model || "unknown").slice(0, 80) + (request.provider === "m365" ? " / M365" : ""),
|
|
191
205
|
finite(context.payload_bytes) ? (Number(context.payload_bytes) / 1048576).toFixed(2) : "—",
|
|
192
206
|
number(context.images), number(context.input_tokens), number(context.context_window_tokens), ratio,
|
|
193
207
|
outcome], { labels: [6] }));
|
package/src/dashboard/ui.css
CHANGED
|
@@ -34,7 +34,7 @@ h1 { margin: 0; font-size: clamp(20px, 3vw, 27px); font-weight: 650; letter-spac
|
|
|
34
34
|
.card h2, .panel h2, .lower h2, .panel > summary, .analytics-section > summary { color: var(--heading); font-size: 11px; font-weight: 700; letter-spacing: .08em; line-height: 1.6; margin: 0; }
|
|
35
35
|
.card strong, .panel > strong { display: block; margin-top: 21px; color: var(--strong); font-size: 23px; font-weight: 650; line-height: 1.25; letter-spacing: -.035em; overflow-wrap: anywhere; }
|
|
36
36
|
.card p { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
|
|
37
|
-
.details { display: grid; grid-template-columns: repeat(
|
|
37
|
+
.details { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; margin-top: 11px; }
|
|
38
38
|
.panel { min-height: 205px; padding: 18px; }
|
|
39
39
|
.panel-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
|
|
40
40
|
.panel-heading span { color: var(--quiet); font-size: 10px; white-space: nowrap; }
|
|
@@ -133,7 +133,7 @@ footer { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; color:
|
|
|
133
133
|
#auto-refresh[aria-pressed="false"] { background: transparent; color: var(--muted); border-color: var(--border); }
|
|
134
134
|
.refresh-time { display: block; margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
|
|
135
135
|
@media (max-width: 1000px) { .animation-options { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
136
|
-
@media (max-width:
|
|
136
|
+
@media (max-width: 1000px) { .overview { grid-template-columns: repeat(2, minmax(0, 1fr)); } .details { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
137
137
|
@media (max-width: 680px) { .animation-options { grid-template-columns: 1fr; } }
|
|
138
138
|
@media (max-width: 620px) { .snapshot-meta { justify-content: flex-start; margin-top: 9px; } }
|
|
139
139
|
@media (max-width: 620px) { .shell { padding: 0 16px; } .topbar { min-height: 60px; } .brand-detail { display: none; } .topbar-actions { gap: 11px; } .intro { display: block; padding: 29px 0 21px; } .intro p { margin-top: 9px; } .overview, .details { grid-template-columns: 1fr; } .details .panel:last-child { grid-column: auto; } .card { min-height: 122px; } .card strong { margin-top: 14px; } .lower li { display: block; } .lower li span { display: block; margin-top: 5px; } }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -246,7 +246,7 @@ function applyModels(data, { changed }) {
|
|
|
246
246
|
}
|
|
247
247
|
if (!data.models.length) emptyTable("live-models-body", 4, "No selectable GPT models advertised.");
|
|
248
248
|
}
|
|
249
|
-
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() });
|
|
249
|
+
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
250
|
}
|
|
251
251
|
|
|
252
252
|
async function loadUsage() { return dashboardRefresh.refresh("usage", { force: true }); }
|
|
@@ -255,7 +255,7 @@ async function readDashboard(url, { signal, timeout = 15000, source } = {}) {
|
|
|
255
255
|
const response = await fetch(url, { cache: "no-store", headers: { "X-CCDX-Dashboard": "1", Accept: "application/json" },
|
|
256
256
|
signal: AbortSignal.any([signal, AbortSignal.timeout(timeout)]) });
|
|
257
257
|
const data = await response.json();
|
|
258
|
-
if (!response.ok || (source &&
|
|
258
|
+
if (!response.ok || (source && !(Array.isArray(source) ? source : [source]).includes(data.source))) throw new Error(data.error || `HTTP ${response.status}`);
|
|
259
259
|
return data;
|
|
260
260
|
}
|
|
261
261
|
|
|
@@ -312,7 +312,7 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
312
312
|
models: {
|
|
313
313
|
visible: () => element("upstream-models").open,
|
|
314
314
|
load: async ({ signal }) => {
|
|
315
|
-
const data = await readDashboard("/_ccdx/ui/models/live", { signal, source: "live" });
|
|
315
|
+
const data = await readDashboard("/_ccdx/ui/models/live", { signal, source: ["live", "catalog"] });
|
|
316
316
|
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
317
|
return data;
|
|
318
318
|
},
|
|
@@ -320,7 +320,7 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
320
320
|
apply: applyModels,
|
|
321
321
|
state: state => {
|
|
322
322
|
element("refresh-models").disabled = Boolean(state.pending);
|
|
323
|
-
text("models-state", state.pending ? "CHECKING LIVE" : state.error ? "LIVE LOOKUP FAILED" : "LIVE SNAPSHOT");
|
|
323
|
+
text("models-state", state.pending ? "CHECKING LIVE" : state.error ? "LIVE LOOKUP FAILED" : state.value?.source === "catalog" ? "CATALOG SNAPSHOT" : "LIVE SNAPSHOT");
|
|
324
324
|
if (state.error) {
|
|
325
325
|
const message = String(state.error.message || state.error).slice(0, 240);
|
|
326
326
|
const httpError = /^Live model lookup failed \(HTTP (\d{3})\)\. Run ccdx models for details\.$/.exec(message);
|
|
@@ -333,15 +333,23 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
333
333
|
},
|
|
334
334
|
usage: {
|
|
335
335
|
visible: () => element("model-usage").open,
|
|
336
|
-
variant: () =>
|
|
336
|
+
variant: () => {
|
|
337
|
+
const mode = ((element("model-usage").open && element("usage-analytics").open) || Boolean(usageView.selectedDate)) ? "analytics" : "summary";
|
|
338
|
+
const provider = element("usage-provider")?.value || "";
|
|
339
|
+
return mode + (provider ? `:${provider}` : "");
|
|
340
|
+
},
|
|
337
341
|
load: async ({ variant, signal }) => {
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
342
|
+
const [mode, provider = ""] = variant.split(":"), query = new URLSearchParams();
|
|
343
|
+
if (mode === "analytics") { query.set("analytics", "1");query.set("time_zone", Intl.DateTimeFormat().resolvedOptions().timeZone); }
|
|
344
|
+
if (provider) query.set("provider", provider);
|
|
345
|
+
const data = await readDashboard(`/_ccdx/ui/usage${query.size ? `?${query}` : ""}`, { signal, source: "local_usage_log" });
|
|
346
|
+
if (!data.total || !Array.isArray(data.rows) || (mode === "analytics" && (!Array.isArray(data.analytics?.days) || !data.analytics.days.length))) throw new Error("Invalid usage snapshot");
|
|
340
347
|
return data;
|
|
341
348
|
},
|
|
342
349
|
apply: applyUsage,
|
|
343
350
|
state: state => {
|
|
344
351
|
element("refresh-usage").disabled = Boolean(state.pending);
|
|
352
|
+
if (element("usage-provider")) element("usage-provider").disabled = Boolean(state.pending);
|
|
345
353
|
if (state.pending) text("usage-state", "READING LOG");
|
|
346
354
|
else if (state.error) {
|
|
347
355
|
text("usage-state", "LOG UNAVAILABLE");
|
|
@@ -415,6 +423,7 @@ for (const id of ["analytics-model", "analytics-range", "analytics-metric"]) ele
|
|
|
415
423
|
if (usageView.data && usageView.selectedDate) renderUsageTable();
|
|
416
424
|
});
|
|
417
425
|
element("clear-usage-day").addEventListener("click", () => selectUsageDay(""));
|
|
426
|
+
element("usage-provider")?.addEventListener("change", () => { dashboardRefresh.invalidate("usage");dashboardRefresh.refresh("usage", { force: true }); });
|
|
418
427
|
element("refresh-models").addEventListener("click", loadModels);
|
|
419
428
|
element("refresh-usage").addEventListener("click", loadUsage);
|
|
420
429
|
loadAnimation();
|
package/src/dashboard/usage.js
CHANGED
|
@@ -145,7 +145,9 @@
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
function applyUsage(data, { changed }) {
|
|
148
|
-
|
|
148
|
+
const sameProvider = (data.provider || "all") === (usageData?.provider || "all");
|
|
149
|
+
if (!sameProvider) selectedUsageDate = "";
|
|
150
|
+
usageData = { ...data, ...(!data.analytics && sameProvider && usageData?.analytics ? { analytics: usageData.analytics } : {}) };
|
|
149
151
|
if (changed) {
|
|
150
152
|
if (data.analytics) updateAnalyticsModels();
|
|
151
153
|
renderUsageTable();
|