codex-copilot-dx 1.2.6 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/bin/cli.mjs +42 -2
- package/docs/ARCHITECTURE.md +13 -1
- package/docs/README.md +5 -0
- package/docs/REFERENCE.md +31 -7
- package/package.json +1 -1
- package/src/account-tools.mjs +121 -0
- package/src/adapter.mjs +2 -0
- package/src/auth-credentials.mjs +18 -8
- package/src/auth-status.mjs +21 -7
- package/src/auth.mjs +1 -0
- package/src/claude-gateway.mjs +2 -2
- package/src/cli-auth.mjs +38 -1
- package/src/cli-options.mjs +46 -13
- package/src/cli-tools.mjs +25 -0
- package/src/cli-web.mjs +37 -0
- package/src/codex-config-doctor.mjs +4 -0
- package/src/copilot-client.mjs +1 -0
- package/src/copilot-token-session.mjs +9 -0
- package/src/dashboard/activity.js +27 -0
- package/src/dashboard/console.js +2 -1
- package/src/dashboard/icons.js +24 -0
- package/src/dashboard/index.html +63 -17
- package/src/dashboard/language.js +90 -0
- package/src/dashboard/status.js +10 -0
- package/src/dashboard/theme.js +3 -2
- package/src/dashboard/tools.js +151 -0
- package/src/dashboard/ui.css +73 -0
- package/src/dashboard/ui.js +5 -1
- package/src/dashboard-api.mjs +5 -0
- package/src/dashboard-tools.mjs +43 -0
- package/src/dashboard.mjs +3 -0
- package/src/doctor.mjs +3 -2
- package/src/local-tools.mjs +53 -0
- package/src/native-prediction-environment.mjs +1 -1
- package/src/observability.mjs +7 -1
- package/src/optional-routes.mjs +9 -3
- package/src/provider-runtime.mjs +2 -2
- package/src/stream-performance.mjs +7 -0
- package/src/terminal-colors.mjs +8 -3
- package/src/terminal-console.mjs +5 -3
- package/src/user-settings.mjs +2 -2
|
@@ -1,5 +1,91 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const translations = {
|
|
3
|
+
"cancel": ["Cancel", "取消"],
|
|
4
|
+
"tools_checks_title": ["Checks & repairs", "检查与修复"],
|
|
5
|
+
"tools_source_browse": ["Browsing a source does not change app settings.", "切换标签只查看来源,不改变应用设置。"],
|
|
6
|
+
"tools_saved_account": ["Saved GitHub sign-in", "已保存 GitHub 登录"],
|
|
7
|
+
"tools_not_signed_in": ["Not signed in", "尚未登录"],
|
|
8
|
+
"tools_signin_invalid": ["Sign-in invalid", "登录已失效"],
|
|
9
|
+
"tools_verified": ["Passed", "检查通过"],
|
|
10
|
+
"tools_unavailable": ["Unavailable", "无法使用"],
|
|
11
|
+
"tools_not_checked": ["Not checked", "尚未检查"],
|
|
12
|
+
"tools_login_hint": ["Sign in to check Copilot access and models.", "登录后检查 Copilot 权限和模型。"],
|
|
13
|
+
"tools_saved_not_valid": ["A saved sign-in does not confirm current access.", "保存过登录,不代表当前仍可用。"],
|
|
14
|
+
"tools_access_hint": ["Check access or network settings before changing sign-in.", "先检查权限或网络,再决定是否重新登录。"],
|
|
15
|
+
"tools_account_hint": ["Saved sign-in and online access are checked separately.", "本地登录与在线权限分别检查。"],
|
|
16
|
+
"tools_saved_signin": ["Saved sign-in", "本地登录"],
|
|
17
|
+
"tools_github_identity": ["GitHub identity", "GitHub 身份"],
|
|
18
|
+
"tools_copilot_access": ["Copilot access", "Copilot 权限"],
|
|
19
|
+
"tools_catalog_read": ["Model catalog", "模型读取"],
|
|
20
|
+
"tools_login": ["Sign in to GitHub", "登录 GitHub"],
|
|
21
|
+
"tools_reauth": ["Sign in again", "重新登录"],
|
|
22
|
+
"tools_check_connection": ["Check connection", "检查连接"],
|
|
23
|
+
"tools_logout": ["Sign out of CCDX", "退出 CCDX 登录"],
|
|
24
|
+
"tools_logout_scope": ["Other apps stay signed in.", "不会退出其他应用的登录。"],
|
|
25
|
+
"tools_logout_confirm": ["Sign out of CCDX? New requests will need a sign-in. Other apps stay signed in.", "退出 CCDX 登录?新请求需要重新登录。其他应用不受影响。"],
|
|
26
|
+
"tools_no_inference": ["Checks access and models. No chat request is sent.", "只检查权限和模型,不发送对话。"],
|
|
27
|
+
"tools_waiting": ["Waiting for GitHub", "等待 GitHub 授权"],
|
|
28
|
+
"tools_verifying": ["Verifying account and models", "正在检查账号和模型"],
|
|
29
|
+
"tools_device_instructions": ["Open GitHub, enter this code, and authorize CCDX.", "打开 GitHub,输入代码并授权。"],
|
|
30
|
+
"tools_open_github": ["Open GitHub", "打开 GitHub"],
|
|
31
|
+
"tools_keep_old_signin": ["Old sign-in is kept until verification succeeds.", "验证成功后才替换原登录。"],
|
|
32
|
+
"tools_signin_complete": ["Sign-in verified. Start a new conversation. Restart CCDX to change accounts.", "登录已验证,请开始新对话。切换账号需重启 CCDX。"],
|
|
33
|
+
"tools_check_complete": ["Account access and model catalog checks passed.", "账号权限和模型目录检查通过。"],
|
|
34
|
+
"tools_storage": ["Saved sign-in", "登录保存位置"],
|
|
35
|
+
"tools_error_code": ["Error code", "错误代码"],
|
|
36
|
+
"tools_ccdx_store": ["CCDX sign-in store", "CCDX 自有登录"],
|
|
37
|
+
"tools_legacy_store": ["Legacy sign-in (compatible read)", "兼容读取旧登录"],
|
|
38
|
+
"tools_details": ["Details", "详细结果"],
|
|
39
|
+
"tools_more_actions": ["More actions", "更多操作"],
|
|
40
|
+
"tools_reauth_hint": ["GitHub rejected this sign-in. Sign in again.", "GitHub 拒绝了当前登录,请重新登录。"],
|
|
41
|
+
"tools_access_denied": ["GitHub sign-in is valid. Check your Copilot access or company policy.", "GitHub 登录有效。请检查 Copilot 权限或公司策略。"],
|
|
42
|
+
"tools_network_hint": ["Connection could not be verified. Check network settings; saved sign-in is kept.", "连接未能验证。请检查网络,原登录已保留。"],
|
|
43
|
+
"tools_local_scope": ["Local checks do not contact external services.", "本机检查不访问外部服务。"],
|
|
44
|
+
"tools_check_local": ["Check this computer", "本机检查"],
|
|
45
|
+
"tools_export_report": ["Export report", "导出报告"],
|
|
46
|
+
"tools_checks_empty": ["Run a check to see the results.", "运行本机检查后显示结果。"],
|
|
47
|
+
"tools_checks_completed": ["Local checks completed at {time}.", "本机检查完成于 {time}。"],
|
|
48
|
+
"tools_check_item": ["Check", "检查项"],
|
|
49
|
+
"tools_github_signin": ["GitHub sign-in", "GitHub 登录"],
|
|
50
|
+
"tools_codex_settings": ["Codex settings", "Codex 配置"],
|
|
51
|
+
"tools_windows_command": ["Windows command", "Windows 命令"],
|
|
52
|
+
"tools_environment": ["Local environment", "本机环境"],
|
|
53
|
+
"tools_needs_attention": ["Needs attention", "需要处理"],
|
|
54
|
+
"tools_observed": ["Recorded", "已记录"],
|
|
55
|
+
"tools_codex_connection": ["Codex connection", "Codex 连接"],
|
|
56
|
+
"tools_config_scope": ["Review CCDX-managed fields before repair. Other settings are preserved.", "先查看 CCDX 管理的字段,再决定是否修复。其他设置保留。"],
|
|
57
|
+
"tools_review_repair": ["Review repair", "查看修复"],
|
|
58
|
+
"tools_repair_preview": ["Repair preview", "修复预览"],
|
|
59
|
+
"tools_managed_fields": ["Managed fields", "管理字段"],
|
|
60
|
+
"tools_backup": ["Backup", "配置备份"],
|
|
61
|
+
"tools_apply_repair": ["Back up and repair", "备份并修复"],
|
|
62
|
+
"tools_repair_complete": ["Configuration repaired and checked. Previous settings were backed up when present.", "配置已修复并检查。原配置存在时已备份。"],
|
|
63
|
+
"tools_repair_preserved": ["Settings preserved. Review the configuration before retrying.", "配置已保留,请先检查原文件。"],
|
|
64
|
+
"tools_more_checks": ["More checks", "更多检查"],
|
|
65
|
+
"tools_network_check": ["Network settings", "网络设置"],
|
|
66
|
+
"tools_network_read_only": ["Network settings read. Proxy and certificate policies are unchanged.", "已读取网络设置,代理和证书策略保持不变。"],
|
|
67
|
+
"tools_compatibility": ["Model compatibility", "模型兼容性"],
|
|
68
|
+
"tools_compatibility_scope": ["This test sends model requests and uses quota. Run it explicitly in your terminal:", "此检查会调用模型并产生用量。请在终端明确执行:"],
|
|
69
|
+
"tools_report_scope": ["Reports omit credentials, account details and chat content.", "报告不含凭据、账号详情和对话内容。"],
|
|
70
|
+
"tools_report_saved": ["Report exported. Share it only with people you trust.", "报告已导出,请仅分享给可信的人。"],
|
|
71
|
+
"tools_read_failed": ["Could not read tool status. Restart the updated CCDX service.", "无法读取工具状态,请重启新版 CCDX。"],
|
|
72
|
+
"tools_action_failed": ["Could not complete the action. Existing settings were preserved where possible.", "操作未完成,请查看当前状态。"],
|
|
73
|
+
"tools_invalid_action": ["Unsupported tool action.", "不支持此工具操作。"],
|
|
74
|
+
"auth_busy": ["A sign-in is already in progress.", "已有登录正在进行。"],
|
|
75
|
+
"auth_retry_later": ["Wait 30 seconds before starting another sign-in.", "请等待 30 秒后再开始登录。"],
|
|
76
|
+
"auth_invalid_account": ["Enter a valid GitHub account name.", "请输入有效的 GitHub 账号名。"],
|
|
77
|
+
"auth_start_failed": ["Could not start GitHub sign-in. Saved sign-in kept.", "无法开始 GitHub 登录,原登录已保留。"],
|
|
78
|
+
"auth_verification_failed": ["Could not verify the new sign-in. Saved sign-in kept.", "新登录未能验证,原登录已保留。"],
|
|
79
|
+
"auth_account_mismatch": ["The new account differs from the saved account. Saved sign-in kept. Use CLI --login to choose another account.", "新账号与原账号不同,原登录已保留。请在命令行用 --login 指定账号。"],
|
|
80
|
+
"auth_signin_changed": ["Saved sign-in changed during authorization. Retry; no credential was overwritten.", "授权期间登录已变化,请重试。未覆盖凭据。"],
|
|
81
|
+
"auth_cancelled": ["Sign-in cancelled. Previous sign-in kept.", "登录已取消,原登录已保留。"],
|
|
82
|
+
"auth_expired": ["Authorization code expired. Previous sign-in kept.", "授权代码已过期,原登录已保留。"],
|
|
83
|
+
"auth_denied": ["Authorization was not completed. Previous sign-in kept.", "授权未完成,原登录已保留。"],
|
|
84
|
+
"auth_operation_changed": ["Sign-in changed. Refresh this page.", "登录流程已变化,请刷新。"],
|
|
85
|
+
"auth_confirmation_required": ["Confirm sign-out before continuing.", "请先确认退出登录。"],
|
|
86
|
+
"auth_restart_required": ["Sign-in saved. Restart CCDX to apply it.", "登录已保存,请重启 CCDX 生效。"],
|
|
87
|
+
"copilot_access_denied": ["Copilot access denied. Check account permissions; previous sign-in kept.", "Copilot 拒绝访问。请检查权限,原登录已保留。"],
|
|
88
|
+
"config_preview_changed": ["Configuration changed. Review a fresh repair preview.", "配置已变化,请重新查看修复预览。"],
|
|
3
89
|
"chart_view": ["Chart view", "图表视图"],
|
|
4
90
|
"bar_chart": ["Bar chart", "柱状图"],
|
|
5
91
|
"line_chart": ["Line chart", "曲线图"],
|
|
@@ -60,6 +146,10 @@
|
|
|
60
146
|
"appearance_browser_scope": ["This browser only.", "只影响当前浏览器。"],
|
|
61
147
|
"appearance_classic_green": ["Classic green (default)", "经典绿(默认)"],
|
|
62
148
|
"appearance_klein_blue": ["Klein blue", "克莱因蓝"],
|
|
149
|
+
"appearance_soft_pink": ["Soft pink", "淡粉色"],
|
|
150
|
+
"model_activity_active": ["Processing {count} requests", "正在处理 {count} 个请求"],
|
|
151
|
+
"model_activity_idle": ["No model requests", "暂无模型请求"],
|
|
152
|
+
"model_activity_unknown": ["Activity unknown", "活动状态未知"],
|
|
63
153
|
"appearance_terminal_scope": ["Independent of the webpage theme.", "与网页主题分别设置。"],
|
|
64
154
|
"appearance_terminal_effect": ["Table updates now. Startup logo changes next launch.", "表格即时换色,启动 Logo 下次生效。"],
|
|
65
155
|
"appearance_sample": ["Sample data", "示例数据"],
|
package/src/dashboard/status.js
CHANGED
|
@@ -26,11 +26,20 @@
|
|
|
26
26
|
if (network) localize(authRow.children[3], "network_detail", { source: phrase(`network_source_${network.source}`),
|
|
27
27
|
stage: phrase(`network_stage_${network.stage}`), code: network.cause_code, category: provider.reason }, "title");
|
|
28
28
|
}
|
|
29
|
+
if (globalThis.ccdxIcons) {
|
|
30
|
+
globalThis.ccdxIcons.set(authRow.children[2], states[identity.state] || "unknown", globalThis.ccdxIcons.kind(identity.state));
|
|
31
|
+
globalThis.ccdxIcons.set(authRow.children[3], provider.reason ? "state_reason" : states[provider.state] || "unknown", globalThis.ccdxIcons.kind(provider.state),
|
|
32
|
+
provider.reason ? { state: phrase(states[provider.state] || "unknown"), reason: provider.network_diagnostic ? phrase(`network_cause_${provider.network_diagnostic.cause_code}`) : provider.reason } : {});
|
|
33
|
+
}
|
|
29
34
|
auth.append(authRow);
|
|
30
35
|
for (const client of provider.clients || []) {
|
|
31
36
|
const row = tableRow([provider.name, client.name, states[client.state] || client.state,
|
|
32
37
|
client.gateway || "—", client.last_request_at || "—"], { labels: [2, 3] });
|
|
33
38
|
if (client.reason) localize(row.children[2], "state_reason", { state: phrase(states[client.state] || "unknown"), reason: client.reason });
|
|
39
|
+
if (globalThis.ccdxIcons) {
|
|
40
|
+
globalThis.ccdxIcons.set(row.children[2], client.reason ? "state_reason" : states[client.state] || client.state, globalThis.ccdxIcons.kind(client.state), client.reason ? { state: phrase(states[client.state] || "unknown"), reason: client.reason } : {});
|
|
41
|
+
if (["running", "unavailable"].includes(client.gateway)) globalThis.ccdxIcons.set(row.children[3], client.gateway, globalThis.ccdxIcons.kind(client.gateway));
|
|
42
|
+
}
|
|
34
43
|
clients.append(row);
|
|
35
44
|
}
|
|
36
45
|
if (provider.requests) {
|
|
@@ -153,6 +162,7 @@
|
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
function render(data) {
|
|
165
|
+
globalThis.ccdxDashboardActivity?.update(data.model_activity);
|
|
156
166
|
text("version", `v${data.version || "?"}`);
|
|
157
167
|
text("uptime", "pid_pid_uptime_duration", { pid: number(data.pid), duration: duration(data.uptime_ms) });
|
|
158
168
|
|
package/src/dashboard/theme.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const key = "ccdx.dashboard.theme", paletteKey = "ccdx.dashboard.palette";
|
|
3
|
-
const valid = value => value === "green" || value === "klein";
|
|
3
|
+
const valid = value => value === "green" || value === "klein" || value === "pink";
|
|
4
4
|
let theme = "dark", palette = "green", saved = true;
|
|
5
5
|
try {
|
|
6
6
|
if (localStorage.getItem(key) === "light") theme = "light";
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
const applyTheme = () => {
|
|
19
19
|
document.documentElement.dataset.theme = theme;
|
|
20
20
|
document.documentElement.dataset.palette = palette;
|
|
21
|
-
const
|
|
21
|
+
const colors = { green: ["#a6f5a8", "#176b3a"], klein: ["#789aff", "#002fa7"], pink: ["#f3a8c8", "#a83e68"] };
|
|
22
|
+
const color = colors[palette][theme === "dark" ? 0 : 1];
|
|
22
23
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><g fill="none" stroke="${color}" stroke-width="3" stroke-linecap="round"><ellipse cx="32" cy="32" rx="26" ry="10"/><ellipse cx="32" cy="32" rx="26" ry="10" transform="rotate(60 32 32)"/><ellipse cx="32" cy="32" rx="26" ry="10" transform="rotate(120 32 32)"/></g><circle cx="32" cy="32" r="4.5" fill="${color}"/></svg>`;
|
|
23
24
|
document.getElementById("favicon").href = `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
24
25
|
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const el = id => document.getElementById(id), language = globalThis.ccdxLanguage;
|
|
3
|
+
const label = (node, key, values) => language.set(node, key, values);
|
|
4
|
+
const text = (id, key, values) => label(el(id), key, values);
|
|
5
|
+
let account = null, pending = false, pollTimer = null, stopped = false, repairPreview = null;
|
|
6
|
+
const activeFlow = () => ["starting", "authorizing", "verifying"].includes(account?.operation?.state);
|
|
7
|
+
async function api(path, body) {
|
|
8
|
+
const response = await fetch(`/_ccdx/ui/${path}`, { method: body ? "POST" : "GET", cache: "no-store",
|
|
9
|
+
headers: { "X-CCDX-Dashboard": "1", ...(body ? { "Content-Type": "application/json" } : {}) },
|
|
10
|
+
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(35000) });
|
|
11
|
+
const data = await response.json();
|
|
12
|
+
if (!response.ok) throw Object.assign(new Error("tools_action_failed"), { code: data.code || "tools_action_failed" });
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function status(id, key, kind, values) { globalThis.ccdxIcons.set(el(id), key, kind, values); }
|
|
16
|
+
function field(list, key, value, kind) {
|
|
17
|
+
const term = document.createElement("dt"), detail = document.createElement("dd");label(term, key);
|
|
18
|
+
if (kind) globalThis.ccdxIcons.set(detail, value, kind);else detail.textContent = value;
|
|
19
|
+
list.append(term, detail);
|
|
20
|
+
}
|
|
21
|
+
function syncSource() {
|
|
22
|
+
const github = selectedProvider === "github";
|
|
23
|
+
el("github-account").hidden = !github;
|
|
24
|
+
el("m365-source-access").hidden = selectedProvider !== "m365";
|
|
25
|
+
el("source-account-panel").setAttribute("aria-labelledby", `model-provider-${selectedProvider}`);
|
|
26
|
+
}
|
|
27
|
+
function renderAccount(data) {
|
|
28
|
+
account = data;
|
|
29
|
+
const online = data.online, op = data.operation;
|
|
30
|
+
const invalid = online?.reason === "github_token_invalid", failed = online?.checked && !online.ok;
|
|
31
|
+
text("github-account-name", data.login || (data.saved ? "tools_saved_account" : "tools_not_signed_in"));
|
|
32
|
+
status("github-account-state", invalid ? "tools_signin_invalid" : online?.ok ? "tools_verified" : data.saved ? "saved_locally" : "tools_not_signed_in",
|
|
33
|
+
invalid ? "warning" : online?.ok ? "ok" : data.saved ? "unknown" : "unavailable");
|
|
34
|
+
text("github-account-hint", !data.saved ? "tools_login_hint" : invalid ? "tools_saved_not_valid" : failed ? "tools_access_hint" : "tools_account_hint");
|
|
35
|
+
const fields = el("github-account-fields");fields.replaceChildren();
|
|
36
|
+
field(fields, "tools_saved_signin", data.saved ? "saved_locally" : "tools_not_signed_in", data.saved ? "ok" : "unavailable");
|
|
37
|
+
for (const [id, key] of [["identity", "tools_github_identity"], ["access", "tools_copilot_access"], ["models", "tools_catalog_read"]]) {
|
|
38
|
+
const result = online?.stages?.[id] || "not_checked";
|
|
39
|
+
field(fields, key, result === "passed" ? "tools_verified" : result === "invalid" ? "tools_signin_invalid" : result === "unavailable" ? "tools_unavailable" : "tools_not_checked",
|
|
40
|
+
result === "passed" ? "ok" : result === "invalid" ? "warning" : result === "unavailable" ? "unavailable" : "unknown");
|
|
41
|
+
}
|
|
42
|
+
field(fields, "last_verified", data.checked_at ? new Date(data.checked_at).toLocaleString() : "—");
|
|
43
|
+
label(el("github-signin"), data.saved ? "tools_reauth" : "tools_login");
|
|
44
|
+
el("github-signin").hidden = data.saved && !invalid;
|
|
45
|
+
el("github-signin").disabled = pending || activeFlow();el("github-check").disabled = pending || activeFlow() || !data.saved;
|
|
46
|
+
el("github-logout").disabled = pending || activeFlow() || !data.saved;
|
|
47
|
+
el("github-force-reauth").disabled = pending || activeFlow();
|
|
48
|
+
el("github-login-flow").hidden = !activeFlow();
|
|
49
|
+
text("github-flow-state", op?.state === "verifying" ? "tools_verifying" : "tools_waiting");
|
|
50
|
+
el("github-user-code").textContent = op?.user_code || "—";
|
|
51
|
+
el("github-authorize").hidden = op?.state !== "authorizing";
|
|
52
|
+
el("github-authorize").href = op?.verification_uri === "https://github.com/login/device" ? op.verification_uri : "https://github.com/login/device";
|
|
53
|
+
el("github-cancel").disabled = pending;
|
|
54
|
+
el("github-check-code").textContent = online?.reason || "—";
|
|
55
|
+
el("github-check-http").textContent = online?.http_status || "—";
|
|
56
|
+
text("github-store", data.store === "ccdx" ? "tools_ccdx_store" : "tools_legacy_store");
|
|
57
|
+
if (op?.state === "complete") text("github-account-note", op.reason === "auth_restart_required" ? "auth_restart_required" : "tools_signin_complete");
|
|
58
|
+
else if (["failed", "cancelled"].includes(op?.state)) text("github-account-note", op.reason || "tools_action_failed");
|
|
59
|
+
else if (failed) text("github-account-note", online.reason === "github_token_invalid" ? "tools_reauth_hint" : online.reason === "copilot_access_denied" ? "tools_access_denied" : "tools_network_hint");
|
|
60
|
+
else if (online?.ok) text("github-account-note", "tools_check_complete");
|
|
61
|
+
else if (!activeFlow()) el("github-account-note").textContent = "";
|
|
62
|
+
schedulePoll();
|
|
63
|
+
}
|
|
64
|
+
function schedulePoll() {
|
|
65
|
+
clearTimeout(pollTimer);pollTimer = null;
|
|
66
|
+
if (stopped || !activeFlow() || document.visibilityState !== "visible") return;
|
|
67
|
+
pollTimer = setTimeout(async () => {
|
|
68
|
+
try {
|
|
69
|
+
const before = account.operation.state, data = await api("account");renderAccount(data);
|
|
70
|
+
if (before !== data.operation?.state && data.operation?.state === "complete") {
|
|
71
|
+
dashboardRefresh.invalidate("auth");dashboardRefresh.invalidate("models", { clear: true });
|
|
72
|
+
void dashboardRefresh.refreshVisible({ force: true });
|
|
73
|
+
}
|
|
74
|
+
} catch { text("github-account-note", "tools_read_failed");schedulePoll(); }
|
|
75
|
+
}, 1500);
|
|
76
|
+
}
|
|
77
|
+
async function accountAction(action) {
|
|
78
|
+
if (pending) return;
|
|
79
|
+
pending = true;if (account) renderAccount(account);text("github-account-note", "checking");
|
|
80
|
+
let failureCode = null;
|
|
81
|
+
try { renderAccount(await api("account", action)); }
|
|
82
|
+
catch (error) { failureCode = error.code; }
|
|
83
|
+
finally { pending = false;if (account) renderAccount(account);if (failureCode) text("github-account-note", failureCode); }
|
|
84
|
+
}
|
|
85
|
+
el("github-signin").addEventListener("click", () => void accountAction({ action: "start", reauth: account?.saved === true }));
|
|
86
|
+
el("github-force-reauth").addEventListener("click", () => void accountAction({ action: "start", reauth: true }));
|
|
87
|
+
el("github-check").addEventListener("click", () => void accountAction({ action: "check" }));
|
|
88
|
+
el("github-cancel").addEventListener("click", () => { if (account?.operation) void accountAction({ action: "cancel", id: account.operation.id }); });
|
|
89
|
+
el("github-logout").addEventListener("click", () => { if (window.confirm(language.format("tools_logout_confirm"))) void accountAction({ action: "logout", confirmed: true }); });
|
|
90
|
+
async function loadAccount() { try { renderAccount(await api("account")); } catch { text("github-account-note", "tools_read_failed"); } }
|
|
91
|
+
function renderChecks(data) {
|
|
92
|
+
const body = el("checks-body");body.replaceChildren();
|
|
93
|
+
const groups = new Map();
|
|
94
|
+
for (const check of data.checks || []) { if (!groups.has(check.id)) groups.set(check.id, []);groups.get(check.id).push(check); }
|
|
95
|
+
for (const [id, checks] of groups) {
|
|
96
|
+
const row = document.createElement("tr"), name = document.createElement("td"), result = document.createElement("td"), details = document.createElement("td");
|
|
97
|
+
const kind = checks.some(check => check.kind === "err" || check.kind === "warn") ? "warning" : checks.some(check => check.kind === "ok") ? "ok" : "unknown";
|
|
98
|
+
label(name, ({ "github-auth": "tools_github_signin", "codex-config": "tools_codex_settings", "windows-command": "tools_windows_command", provider: "source" })[id] || "tools_environment");
|
|
99
|
+
globalThis.ccdxIcons.set(result, kind === "warning" ? "tools_needs_attention" : kind === "ok" ? "tools_verified" : "tools_observed", kind);
|
|
100
|
+
const disclosure = document.createElement("details"), summary = document.createElement("summary");label(summary, "tools_details");disclosure.append(summary);
|
|
101
|
+
for (const check of checks) { const p = document.createElement("p");p.className = "hint";p.textContent = check.message;disclosure.append(p); }
|
|
102
|
+
details.append(disclosure);row.append(name, result, details);body.append(row);
|
|
103
|
+
}
|
|
104
|
+
if (!groups.size) text("checks-note", "tools_checks_empty");
|
|
105
|
+
else text("checks-note", "tools_checks_completed", { time: new Date(data.checked_at).toLocaleTimeString() });
|
|
106
|
+
}
|
|
107
|
+
async function localAction(action, button) {
|
|
108
|
+
button.disabled = true;text("checks-note", "checking");
|
|
109
|
+
try {
|
|
110
|
+
const data = await api("checks", action);
|
|
111
|
+
if (action.action === "check") renderChecks(data);
|
|
112
|
+
else if (action.action === "preview") {
|
|
113
|
+
repairPreview = data;el("config-repair-preview").hidden = false;
|
|
114
|
+
const fields = el("config-repair-fields");fields.replaceChildren();
|
|
115
|
+
field(fields, "tools_managed_fields", data.managed_keys.join(", "));
|
|
116
|
+
field(fields, "tools_backup", data.backup);
|
|
117
|
+
el("config-preview-details").textContent = data.checks.map(check => check.message).join("\n");
|
|
118
|
+
text("checks-note", "tools_review_repair");
|
|
119
|
+
} else if (action.action === "repair") {
|
|
120
|
+
el("config-repair-preview").hidden = true;repairPreview = null;
|
|
121
|
+
if (data.local?.checked_at) renderChecks(data.local);
|
|
122
|
+
text("checks-note", ["verified", "unchanged"].includes(data.status) ? "tools_repair_complete" : "tools_repair_preserved");
|
|
123
|
+
} else if (action.action === "network") { el("network-check-result").textContent = data.summary;text("checks-note", "tools_network_read_only"); }
|
|
124
|
+
else if (action.action === "report") {
|
|
125
|
+
const url = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], { type: "application/json" }));
|
|
126
|
+
const link = document.createElement("a");link.href = url;link.download = "ccdx-diagnostic-report.json";link.click();
|
|
127
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);text("checks-note", "tools_report_saved");
|
|
128
|
+
}
|
|
129
|
+
} catch (error) { text("checks-note", error.code); }
|
|
130
|
+
finally { button.disabled = false; }
|
|
131
|
+
}
|
|
132
|
+
for (const [id, action] of [["check-local", "check"], ["check-network", "network"], ["export-report", "report"], ["preview-config-repair", "preview"]]) {
|
|
133
|
+
el(id).addEventListener("click", () => void localAction({ action }, el(id)));
|
|
134
|
+
}
|
|
135
|
+
el("apply-config-repair").addEventListener("click", () => { if (repairPreview) void localAction({ action: "repair", revision: repairPreview.revision }, el("apply-config-repair")); });
|
|
136
|
+
el("cancel-config-repair").addEventListener("click", () => { repairPreview = null;el("config-repair-preview").hidden = true; });
|
|
137
|
+
el("check-account-link").addEventListener("click", () => { chooseProvider("github");location.hash = "models"; });
|
|
138
|
+
async function navigate() {
|
|
139
|
+
syncSource();
|
|
140
|
+
if (location.hash === "#models") await loadAccount();
|
|
141
|
+
if (location.hash === "#checks") { try { const data = await api("checks");if (data.checked_at) renderChecks(data); } catch { text("checks-note", "tools_read_failed"); } }
|
|
142
|
+
}
|
|
143
|
+
window.addEventListener("ccdx:source-view", syncSource);
|
|
144
|
+
window.addEventListener("ccdx:providers", () => { queueMicrotask(() => { syncSource();if (location.hash === "#models" && !pending) void loadAccount(); }); });
|
|
145
|
+
el("refresh").addEventListener("click", () => { if (location.hash === "#models" && !pending) void loadAccount(); });
|
|
146
|
+
window.addEventListener("hashchange", () => void navigate());
|
|
147
|
+
window.addEventListener("pagehide", () => { stopped = true;clearTimeout(pollTimer); });
|
|
148
|
+
window.addEventListener("pageshow", () => { stopped = false;schedulePoll(); });
|
|
149
|
+
document.addEventListener("visibilitychange", schedulePoll);
|
|
150
|
+
void navigate();
|
|
151
|
+
})();
|
package/src/dashboard/ui.css
CHANGED
|
@@ -283,5 +283,78 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
283
283
|
:root:not([data-theme="light"]) #animation-settings { --ansi-white:#f5fff5;--ansi-159:#9af5e9;--ansi-123:#75e4d9;--ansi-87:#5ad0d4;--ansi-51:#42b9d8;--ansi-45:#3ca2d0;--ansi-39:#4389c2;--ansi-33:#4775b2; }
|
|
284
284
|
:root:not([data-theme="light"]) #animation-settings[data-terminal-palette="klein"] { --ansi-white:#789aff;--ansi-159:#789aff;--ansi-123:#789aff;--ansi-87:#789aff;--ansi-51:#789aff;--ansi-45:#789aff;--ansi-39:#789aff;--ansi-33:#789aff; }
|
|
285
285
|
|
|
286
|
+
:root[data-palette="pink"][data-theme="light"] {
|
|
287
|
+
--page:#fff7fa; --surface:#fff; --text:#432e39; --strong:#35202d;
|
|
288
|
+
--muted:#765365; --badge:#765365; --subtle:#765365; --quiet:#805d70; --footer:#805d70;
|
|
289
|
+
--border:#e8ccd8; --top-border:#dfbdcd; --accent:#a83e68; --accent-soft:#a83e68; --heading:#a83e68;
|
|
290
|
+
--button-border:#c38ba4; --button-bg:#fff0f6; --button-fg:#a83e68; --button-hover:#f8dce9;
|
|
291
|
+
--selected-bg:#fae5ef; --option-hover:#fff0f6; --table-text:#432e39; --preview:#805d70;
|
|
292
|
+
--ansi-white:#a83e68; --ansi-159:#aa4a72; --ansi-123:#b3527c; --ansi-87:#ab4671;
|
|
293
|
+
--ansi-51:#a13f69; --ansi-45:#963c66; --ansi-39:#8e3c65; --ansi-33:#843b62;
|
|
294
|
+
--bad:#a33625; --failed:#a33625; --incomplete:#835600;
|
|
295
|
+
}
|
|
296
|
+
:root[data-palette="pink"]:not([data-theme="light"]) {
|
|
297
|
+
--page:#160f16; --surface:#211720; --text:#f2e2eb; --strong:#fff0f6;
|
|
298
|
+
--muted:#c4a7b8; --badge:#d4b8c9; --subtle:#c4a7b8; --quiet:#b598aa; --footer:#b598aa;
|
|
299
|
+
--border:#513342; --top-border:#513342; --accent:#f3a8c8; --accent-soft:#f3a8c8; --heading:#f3a8c8;
|
|
300
|
+
--button-border:#9f6885; --button-bg:#31202d; --button-fg:#f3a8c8; --button-hover:#482b3e;
|
|
301
|
+
--selected-bg:#3b2333; --option-hover:#31202d; --table-text:#f2e2eb; --preview:#c4a7b8;
|
|
302
|
+
--ansi-white:#ffe7f3; --ansi-159:#f7c4da; --ansi-123:#f3b6d1; --ansi-87:#efa8c8;
|
|
303
|
+
--ansi-51:#e99bbd; --ansi-45:#da8bb0; --ansi-39:#cd7fa5; --ansi-33:#bd739a;
|
|
304
|
+
--bad:#ff947e; --failed:#ff9f91; --incomplete:#e3c77c;
|
|
305
|
+
}
|
|
306
|
+
.terminal-sample[data-terminal-palette="pink"] { --sample-logo:#f3a8c8; --sample-table:#f3a8c8; --sample-motion:#f3a8c8; }
|
|
307
|
+
:root:not([data-theme="light"]) #animation-settings[data-terminal-palette="pink"] { --ansi-white:#f3a8c8;--ansi-159:#f3a8c8;--ansi-123:#f3a8c8;--ansi-87:#f3a8c8;--ansi-51:#f3a8c8;--ansi-45:#f3a8c8;--ansi-39:#f3a8c8;--ansi-33:#f3a8c8; }
|
|
308
|
+
:root[data-theme="light"] #animation-settings[data-terminal-palette="pink"] { --ansi-white:#a83e68;--ansi-159:#a83e68;--ansi-123:#a83e68;--ansi-87:#a83e68;--ansi-51:#a83e68;--ansi-45:#a83e68;--ansi-39:#a83e68;--ansi-33:#a83e68; }
|
|
309
|
+
|
|
310
|
+
.model-activity { display:flex;align-items:center;height:30px;margin-top:-26px;padding-left:3px;color:var(--muted);font-size:11px; }
|
|
311
|
+
.activity-lamp,.activity-dots i { position:relative;display:block;flex:none;width:4px;height:4px;border-radius:50%;background:color-mix(in srgb,var(--accent) 72%,var(--surface)); }
|
|
312
|
+
.activity-dots { display:flex;align-items:center;gap:6px;width:0;height:22px;opacity:0;transition:width 320ms ease,padding 320ms ease,opacity 220ms ease; }
|
|
313
|
+
.activity-dots i { opacity:0;transform:scale(.4); }
|
|
314
|
+
.activity-label { margin-left:10px; }
|
|
315
|
+
.model-activity[data-state="active"] .activity-dots { width:50px;padding-left:6px;opacity:1; }
|
|
316
|
+
.model-activity[data-state="active"] .activity-dots i { animation:activity-second 4s ease-in-out infinite; }
|
|
317
|
+
.model-activity[data-state="active"] .activity-dots i:nth-child(2) { animation-name:activity-third; }
|
|
318
|
+
.model-activity[data-state="active"] .activity-dots i:nth-child(3) { animation-name:activity-fourth; }
|
|
319
|
+
.model-activity[data-state="active"] .activity-dots i:nth-child(4) { animation-name:activity-fifth; }
|
|
320
|
+
.model-activity[data-state="active"] .activity-dots i:nth-child(5) { animation-name:activity-sixth; }
|
|
321
|
+
.model-activity[data-state="idle"] .activity-lamp::before { content:"";position:absolute;left:50%;top:50%;width:20px;height:20px;border-radius:50%;background:radial-gradient(circle,color-mix(in srgb,var(--accent) 24%,var(--surface)) 0%,transparent 68%);transform:translate(-50%,-50%);animation:activity-breathe 3.2s ease-in-out infinite; }
|
|
322
|
+
.model-activity[data-state="unknown"] .activity-lamp { background:transparent;border:1px solid var(--muted); }
|
|
323
|
+
.model-activity[data-paused="true"] .activity-dots i,.model-activity[data-paused="true"] .activity-lamp::before { animation-play-state:paused; }
|
|
324
|
+
@keyframes activity-breathe { 0%,100%{opacity:.45;transform:translate(-50%,-50%) scale(.8)}50%{opacity:.95;transform:translate(-50%,-50%) scale(1.18)} }
|
|
325
|
+
@keyframes activity-second { 0%,6%,94%,100%{opacity:0;transform:scale(.4)}12%,88%{opacity:1;transform:scale(1)} }
|
|
326
|
+
@keyframes activity-third { 0%,14%,86%,100%{opacity:0;transform:scale(.4)}20%,80%{opacity:1;transform:scale(1)} }
|
|
327
|
+
@keyframes activity-fourth { 0%,22%,78%,100%{opacity:0;transform:scale(.4)}28%,72%{opacity:1;transform:scale(1)} }
|
|
328
|
+
@keyframes activity-fifth { 0%,30%,70%,100%{opacity:0;transform:scale(.4)}36%,64%{opacity:1;transform:scale(1)} }
|
|
329
|
+
@keyframes activity-sixth { 0%,38%,62%,100%{opacity:0;transform:scale(.4)}44%,56%{opacity:1;transform:scale(1)} }
|
|
330
|
+
@media(prefers-reduced-motion:reduce) {
|
|
331
|
+
.activity-dots { transition:none; }
|
|
332
|
+
.model-activity[data-state="active"] .activity-dots i { animation:none;opacity:1;transform:none; }
|
|
333
|
+
.model-activity[data-state="idle"] .activity-lamp::before { animation:none;opacity:.6; }
|
|
334
|
+
}
|
|
335
|
+
|
|
286
336
|
:root[data-theme="light"] #animation-settings { --ansi-white:#234231;--ansi-159:#116b64;--ansi-123:#0d7771;--ansi-87:#116b75;--ansi-51:#14697e;--ansi-45:#1a6183;--ansi-39:#265f8d;--ansi-33:#365a8d; }
|
|
287
337
|
:root[data-theme="light"] #animation-settings[data-terminal-palette="klein"] { --ansi-white:#002fa7;--ansi-159:#002fa7;--ansi-123:#002fa7;--ansi-87:#002fa7;--ansi-51:#002fa7;--ansi-45:#002fa7;--ansi-39:#002fa7;--ansi-33:#002fa7; }
|
|
338
|
+
|
|
339
|
+
.state-label { display:inline-flex; align-items:center; gap:8px; max-width:100%; vertical-align:middle; white-space:normal; }
|
|
340
|
+
.state-icon { width:16px; height:16px; flex:none; fill:none; stroke:currentColor; stroke-width:1.6; stroke-linecap:round; stroke-linejoin:round; }
|
|
341
|
+
.state-label.state-ok, .state-label.state-running { color:var(--accent); }
|
|
342
|
+
.state-label.state-warning { color:var(--bad); }
|
|
343
|
+
.state-label.state-unavailable, .state-label.state-unknown { color:var(--muted); }
|
|
344
|
+
.state-label > span { color:inherit; white-space:normal; }
|
|
345
|
+
.badge:has(.state-label)::before { display:none; }
|
|
346
|
+
.source-browse-note { margin:12px 0 20px; }
|
|
347
|
+
.account-name { margin:18px 0 6px; font-size:19px; color:var(--strong); font-weight:650; }
|
|
348
|
+
.account-fields { display:grid; grid-template-columns:minmax(110px,150px) minmax(0,1fr); gap:10px 18px; margin:20px 0; font-size:12px; line-height:1.7; }
|
|
349
|
+
.account-fields dt { color:var(--muted); }
|
|
350
|
+
.account-fields dd { margin:0; min-width:0; }
|
|
351
|
+
.tool-details, .tool-flow { margin-top:18px; padding-top:16px; border-top:1px solid var(--border); }
|
|
352
|
+
.tool-details summary, .tool-flow h3 { color:var(--heading); font-size:12px; }
|
|
353
|
+
.device-code { display:block; color:var(--accent); font-size:23px; letter-spacing:.1em; margin:16px 0; }
|
|
354
|
+
.tool-link { display:inline-flex; min-height:36px; align-items:center; color:var(--accent); margin-right:16px; }
|
|
355
|
+
.tool-code { background:var(--page); border:1px solid var(--border); padding:14px; font:inherit; font-size:12px; line-height:1.7; white-space:pre-wrap; overflow-wrap:anywhere; }
|
|
356
|
+
.checks-table td { vertical-align:top; white-space:normal; }
|
|
357
|
+
.checks-table th:first-child { width:23%; }
|
|
358
|
+
.checks-table th:nth-child(2) { width:21%; }
|
|
359
|
+
.checks-table details p { margin:8px 0; }
|
|
360
|
+
@media(max-width:640px) { .account-fields { grid-template-columns:100px minmax(0,1fr); gap:10px; } .checks-table { min-width:530px; } }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -269,6 +269,7 @@ function chooseProvider(id) {
|
|
|
269
269
|
if (previous) applyModels(previous, { changed: true });
|
|
270
270
|
else { emptyTable("live-models-body", 6, "reading_provider_catalog");text("models-note", "reading_provider_catalog"); }
|
|
271
271
|
element("live-models-body").setAttribute("aria-labelledby", `model-provider-${id}`);
|
|
272
|
+
window.dispatchEvent(new CustomEvent("ccdx:source-view"));
|
|
272
273
|
void loadModels();
|
|
273
274
|
}
|
|
274
275
|
|
|
@@ -303,7 +304,7 @@ function applyProviders(data, { changed }) {
|
|
|
303
304
|
let button = providerTabs.get(provider.id);
|
|
304
305
|
if (!button) {
|
|
305
306
|
button = document.createElement("button");button.type = "button";button.setAttribute("role", "tab");
|
|
306
|
-
button.id = `model-provider-${provider.id}`;button.setAttribute("aria-controls", "
|
|
307
|
+
button.id = `model-provider-${provider.id}`;button.setAttribute("aria-controls", "source-account-panel");
|
|
307
308
|
button.addEventListener("click", () => chooseProvider(provider.id));
|
|
308
309
|
button.addEventListener("keydown", event => {
|
|
309
310
|
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
@@ -391,8 +392,11 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
391
392
|
},
|
|
392
393
|
apply: render,
|
|
393
394
|
state: state => {
|
|
395
|
+
if (state.error || !state.value) globalThis.ccdxDashboardActivity?.unavailable();
|
|
394
396
|
text("connection", state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable");
|
|
395
397
|
element("connection").className = `badge ${state.pending ? "neutral" : state.error ? "bad" : "good"}`;
|
|
398
|
+
globalThis.ccdxIcons?.set(element("connection"), state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable",
|
|
399
|
+
state.pending && !state.value ? "unknown" : state.error ? "unavailable" : "running");
|
|
396
400
|
if (state.error) refreshTime(element("updated"), state);
|
|
397
401
|
for (const node of timestamps.get("status")) refreshTime(node, state);
|
|
398
402
|
},
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -148,6 +148,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
148
148
|
updateStatusFn,
|
|
149
149
|
serviceControl,
|
|
150
150
|
applyAnimation,
|
|
151
|
+
tools,
|
|
151
152
|
} = {}) {
|
|
152
153
|
if (!isLoopbackAddress(req.socket?.remoteAddress)
|
|
153
154
|
|| req.headers?.host === undefined
|
|
@@ -160,6 +161,10 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
160
161
|
return;
|
|
161
162
|
}
|
|
162
163
|
|
|
164
|
+
if (["/_ccdx/ui/account", "/_ccdx/ui/checks"].includes(pathname)) {
|
|
165
|
+
return tools.handle(req, res, pathname, sendJson, sameOrigin);
|
|
166
|
+
}
|
|
167
|
+
|
|
163
168
|
if (pathname === PROVIDERS_PATH && req.method === "GET") {
|
|
164
169
|
try { sendJson(res, 200, { source: "provider_status", providers: dashboardProviders(providerStateFn, authStatusFn) }); }
|
|
165
170
|
catch { sendJson(res, 500, { error: "Could not read provider status" }); }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createAccountTools } from "./account-tools.mjs";
|
|
2
|
+
import { createLocalTools } from "./local-tools.mjs";
|
|
3
|
+
import { createRequestAbort, readJsonBody } from "./http-transport.mjs";
|
|
4
|
+
|
|
5
|
+
export const TOOL_PATHS = new Set(["/_ccdx/ui/account", "/_ccdx/ui/checks"]);
|
|
6
|
+
export function createDashboardTools(options = {}) {
|
|
7
|
+
const accounts = options.accountTools || createAccountTools({ ...options, onChanged: options.credentialsChanged });
|
|
8
|
+
const local = options.localTools || createLocalTools(options);
|
|
9
|
+
return {
|
|
10
|
+
dispose() { accounts.dispose(); },
|
|
11
|
+
async handle(req, res, pathname, sendJson, sameOrigin) {
|
|
12
|
+
const account = pathname === "/_ccdx/ui/account";
|
|
13
|
+
if (req.method === "GET") {
|
|
14
|
+
try { sendJson(res, 200, account ? accounts.snapshot() : local.snapshot()); }
|
|
15
|
+
catch { sendJson(res, 409, { error: "tools_read_failed", code: "tools_read_failed" }); }
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (req.method !== "POST") { sendJson(res, 405, { error: "Use GET or POST" });return; }
|
|
19
|
+
if (!sameOrigin(req)) { sendJson(res, 403, { error: "Tools require the same-origin dashboard" });return; }
|
|
20
|
+
if (!/^application\/json(?:\s*;|$)/i.test(req.headers["content-type"] || "")) { sendJson(res, 415, { error: "Expected application/json" });return; }
|
|
21
|
+
const abort = createRequestAbort(req, res);abort.setTimeout(5000, "request_body_timeout");
|
|
22
|
+
try {
|
|
23
|
+
const input = await readJsonBody(req, { maxBodyBytes: 4096, maxDecodedBodyBytes: 4096, signal: abort.signal });
|
|
24
|
+
abort.clearTimeout();
|
|
25
|
+
const fields = account ? { check: ["action"], start: ["action", "reauth"], cancel: ["action", "id"], logout: ["action", "confirmed"], reload: ["action"] }
|
|
26
|
+
: { check: ["action"], preview: ["action"], repair: ["action", "revision"], network: ["action"], report: ["action"] };
|
|
27
|
+
const allowed = input && typeof input === "object" && !Array.isArray(input) && fields[input.action];
|
|
28
|
+
if (!allowed || Object.keys(input).some(key => !allowed.includes(key)) || (input.action === "start" && input.reauth !== undefined && typeof input.reauth !== "boolean")) {
|
|
29
|
+
sendJson(res, 400, { error: "tools_invalid_action", code: "tools_invalid_action" });return;
|
|
30
|
+
}
|
|
31
|
+
const target = account ? accounts : local;
|
|
32
|
+
if (!account && input.action === "report" && !local.snapshot().checked_at) await local.check();
|
|
33
|
+
const value = await (input.action === "start" ? target.start({ reauth: input.reauth })
|
|
34
|
+
: input.action === "cancel" ? target.cancel(input.id) : input.action === "logout" ? target.logout(input)
|
|
35
|
+
: input.action === "repair" ? target.repair(input) : target[input.action]());
|
|
36
|
+
if (!res.destroyed && !res.writableEnded) sendJson(res, 200, value);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const code = /^(auth|copilot|config|tools)_[a-z_]+$/.test(error.code || "") ? error.code : "tools_action_failed";
|
|
39
|
+
sendJson(res, error.statusCode || 409, { error: code, code });
|
|
40
|
+
} finally { abort.cleanup(); }
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/src/dashboard.mjs
CHANGED
|
@@ -10,8 +10,11 @@ const ASSETS = new Map([
|
|
|
10
10
|
["/console.js", ["./dashboard/console.js", "text/javascript; charset=utf-8"]],
|
|
11
11
|
["/updates.js", ["./dashboard/updates.js", "text/javascript; charset=utf-8"]],
|
|
12
12
|
["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
|
|
13
|
+
["/activity.js", ["./dashboard/activity.js", "text/javascript; charset=utf-8"]],
|
|
13
14
|
["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
|
|
14
15
|
["/refresh.js", ["./dashboard/refresh.js", "text/javascript; charset=utf-8"]],
|
|
16
|
+
["/icons.js", ["./dashboard/icons.js", "text/javascript; charset=utf-8"]],
|
|
17
|
+
["/tools.js", ["./dashboard/tools.js", "text/javascript; charset=utf-8"]],
|
|
15
18
|
]);
|
|
16
19
|
|
|
17
20
|
export async function serveDashboard(req, res, pathname) {
|
package/src/doctor.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import net from "node:net";
|
|
5
|
-
import { githubTokenPath, readGithubTokenMetadata, validateGithubToken } from "./auth.mjs";
|
|
5
|
+
import { githubTokenPath, managedGithubTokenPath, readGithubTokenMetadata, validateGithubToken } from "./auth.mjs";
|
|
6
6
|
import {
|
|
7
7
|
AUTH_PROFILE_CODEX,
|
|
8
8
|
readAuthProfileCredentials,
|
|
@@ -65,7 +65,8 @@ export function inspectGitHubToken({ home = os.homedir() } = {}) {
|
|
|
65
65
|
export function inspectAuthProfiles({ home = os.homedir() } = {}) {
|
|
66
66
|
return [
|
|
67
67
|
...inspectGitHubToken({ home }),
|
|
68
|
-
{ kind: "
|
|
68
|
+
{ kind: "info", message: githubTokenPath(home) === managedGithubTokenPath(home)
|
|
69
|
+
? "Codex authentication profile uses the CCDX-owned store" : "Codex authentication profile uses the legacy path" },
|
|
69
70
|
];
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { collectDoctorChecks } from "./doctor.mjs";
|
|
5
|
+
import { inspectCodexConfig, repairCodexConfig } from "./codex-config-doctor.mjs";
|
|
6
|
+
import { codexPaths } from "./codex-paths.mjs";
|
|
7
|
+
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
8
|
+
import { inspectPredictionEnvironment } from "./native-prediction-environment.mjs";
|
|
9
|
+
import { formatPredictionEnvironment } from "./native-prediction-state.mjs";
|
|
10
|
+
import { localPackageVersion } from "./version.mjs";
|
|
11
|
+
|
|
12
|
+
export function createLocalTools({ home = os.homedir(), env = process.env, host = "127.0.0.1", port = 2026,
|
|
13
|
+
platform = process.platform, collect = collectDoctorChecks, inspectConfig = inspectCodexConfig, repairConfig = repairCodexConfig,
|
|
14
|
+
inspectNetwork = inspectPredictionEnvironment } = {}) {
|
|
15
|
+
const options = { home, env, host, port, platform };
|
|
16
|
+
let last = null, flight = null;
|
|
17
|
+
const safe = text => redactDiagnosticText(String(text || "")).split(home).join("~")
|
|
18
|
+
.replace(/[\w.+-]+@[\w.-]+/g, "[account]").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 600);
|
|
19
|
+
const project = checks => checks.slice(0, 80).map(check => ({ id: /^[a-z-]{1,60}$/.test(check.id || "") ? check.id : "local",
|
|
20
|
+
kind: ["ok", "info", "warn", "err"].includes(check.kind) ? check.kind : "info", message: safe(check.message) }));
|
|
21
|
+
function snapshot() { return { source: "local_tools", ...last }; }
|
|
22
|
+
async function check() {
|
|
23
|
+
if (flight) return flight;
|
|
24
|
+
flight = Promise.resolve().then(async () => {
|
|
25
|
+
last = { checked_at: new Date().toISOString(), checks: project(await collect({ ...options, checkAdapter: false })) };
|
|
26
|
+
return snapshot();
|
|
27
|
+
}).finally(() => { flight = null; });
|
|
28
|
+
return flight;
|
|
29
|
+
}
|
|
30
|
+
function revision() {
|
|
31
|
+
try { return createHash("sha256").update(fs.readFileSync(codexPaths(options).config)).digest("hex"); }
|
|
32
|
+
catch (error) { if (error.code === "ENOENT") return "missing";throw error; }
|
|
33
|
+
}
|
|
34
|
+
function preview() {
|
|
35
|
+
return { source: "config_repair_preview", revision: revision(), checks: project(inspectConfig(options)),
|
|
36
|
+
managed_keys: ["openai_base_url", "model_context_window", "model_auto_compact_token_limit", "shell_environment_policy", "features.context_management"],
|
|
37
|
+
backup: "config.toml.ccdx-doctor.bak" };
|
|
38
|
+
}
|
|
39
|
+
function repair(input) {
|
|
40
|
+
if (typeof input.revision !== "string" || input.revision !== revision()) throw Object.assign(new Error("config_preview_changed"), { code: "config_preview_changed", statusCode: 409 });
|
|
41
|
+
const result = repairConfig({ ...options, expectedRevision: input.revision });
|
|
42
|
+
const checks = project(inspectConfig(options).map(check => ({ ...check, id: "codex-config" })));
|
|
43
|
+
if (last) last = { checked_at: new Date().toISOString(), checks: [...last.checks.filter(check => check.id !== "codex-config"), ...checks] };
|
|
44
|
+
return { source: "config_repair_result", status: result.status, changed: result.changed === true,
|
|
45
|
+
checks, local: snapshot() };
|
|
46
|
+
}
|
|
47
|
+
function network() {
|
|
48
|
+
const value = inspectNetwork({ env, platform });
|
|
49
|
+
return { source: "network_check", checked_at: new Date().toISOString(), summary: safe(formatPredictionEnvironment(value.summary)) };
|
|
50
|
+
}
|
|
51
|
+
return { snapshot, check, preview, repair, network, report: () => ({ version: localPackageVersion(),
|
|
52
|
+
exported_at: new Date().toISOString(), scope: "local checks only; accounts and credentials omitted", ...snapshot() }) };
|
|
53
|
+
}
|
|
@@ -42,7 +42,7 @@ export function inspectPredictionEnvironment({ env = process.env, platform = pro
|
|
|
42
42
|
network = { settings };
|
|
43
43
|
}
|
|
44
44
|
} else {
|
|
45
|
-
const systemProxy = exec("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 2000, maxBuffer: 64 * 1024 });
|
|
45
|
+
const systemProxy = platform === "darwin" ? exec("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 2000, maxBuffer: 64 * 1024 }) : "";
|
|
46
46
|
network = { networkRoute: resolveNetworkRoute({ env, systemProxy }) };
|
|
47
47
|
}
|
|
48
48
|
} catch (error) {
|
package/src/observability.mjs
CHANGED
|
@@ -187,6 +187,11 @@ export function runtimeStatusPayload({
|
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
const history = responseHistoryStats();
|
|
190
|
+
const requests = metrics?.snapshot?.() || createRequestMetrics().snapshot();
|
|
191
|
+
const activityCounts = ["responses", "responses_compact", "messages"].map(route => requests.by_route[route].active);
|
|
192
|
+
activityCounts.push(imageGeneration?.active ?? 0);
|
|
193
|
+
const active = activityCounts.every(value => Number.isSafeInteger(value) && value >= 0)
|
|
194
|
+
&& Number.isSafeInteger(activityCounts.reduce((sum, value) => sum + value, 0)) ? activityCounts.reduce((sum, value) => sum + value, 0) : null;
|
|
190
195
|
return {
|
|
191
196
|
...adapterHealthPayload(),
|
|
192
197
|
uptime_ms: Math.round(process.uptime() * 1000),
|
|
@@ -197,7 +202,8 @@ export function runtimeStatusPayload({
|
|
|
197
202
|
external_bytes: memory.external,
|
|
198
203
|
array_buffers_bytes: memory.arrayBuffers,
|
|
199
204
|
},
|
|
200
|
-
requests
|
|
205
|
+
requests,
|
|
206
|
+
model_activity: { active },
|
|
201
207
|
stream_performance: streamPerformance?.snapshot?.() || null,
|
|
202
208
|
admission: admission?.diagnostics?.() || admission?.stats?.() || null,
|
|
203
209
|
response_history: history,
|