codex-copilot-dx 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/bin/cli.mjs +5 -4
- package/docs/ARCHITECTURE.md +16 -0
- package/docs/REFERENCE.md +34 -8
- package/package.json +1 -1
- package/src/access-settings.mjs +3 -1
- package/src/adapter.mjs +9 -1
- package/src/antigravity-chat-bridge.mjs +4 -2
- package/src/antigravity-handler.mjs +28 -16
- package/src/antigravity-images.mjs +3 -2
- package/src/antigravity-runtime.mjs +13 -3
- package/src/application-configuration.mjs +43 -0
- package/src/application-control.mjs +114 -0
- package/src/application-evidence.mjs +42 -0
- package/src/application-process.mjs +114 -0
- package/src/claude-gateway.mjs +24 -15
- package/src/cli-command-spec.mjs +7 -4
- package/src/cli-management.mjs +27 -2
- package/src/codex-image-host-launch.mjs +1 -2
- package/src/codex-launch-control.mjs +7 -7
- package/src/connection-management.mjs +18 -3
- package/src/connection-policy.mjs +3 -1
- package/src/connection-routing.mjs +7 -2
- package/src/connection-runtime.mjs +21 -5
- package/src/connection-view.mjs +9 -3
- package/src/context-compaction-wire.mjs +7 -6
- package/src/context-compaction.mjs +6 -4
- package/src/copilot-client.mjs +17 -13
- package/src/copilot-responses-compat.mjs +1 -0
- package/src/copilot-web.mjs +6 -2
- package/src/dashboard/applications.js +83 -0
- package/src/dashboard/connections.js +52 -14
- package/src/dashboard/console.js +19 -9
- package/src/dashboard/gemini.js +8 -5
- package/src/dashboard/index.html +16 -0
- package/src/dashboard/language.js +41 -0
- package/src/dashboard/ui.css +9 -0
- package/src/dashboard-api.mjs +6 -1
- package/src/dashboard.mjs +1 -0
- package/src/gemini-app.mjs +3 -2
- package/src/http-transport.mjs +5 -2
- package/src/launcher.mjs +6 -5
- package/src/native-images.mjs +1 -1
- package/src/provider-runtime.mjs +14 -9
- package/src/providers/api.mjs +18 -12
- package/src/providers/m365.mjs +9 -5
- package/src/request-admission.mjs +6 -0
- package/src/responses-bridge.mjs +5 -2
- package/src/responses-handler.mjs +2 -0
- package/src/responses-proxy.mjs +9 -4
- package/src/safe-upstream-error.mjs +9 -11
- package/src/service-control.mjs +29 -5
- package/src/settings-preferences.mjs +3 -3
- package/src/source-admission-state.mjs +29 -0
- package/src/source-admission.mjs +310 -0
- package/src/source-discovery-probe.mjs +35 -0
- package/src/source-discovery.mjs +112 -0
- package/src/source-response.mjs +134 -0
- package/src/source-transport.mjs +19 -0
- package/src/stream-contract.mjs +3 -1
- package/src/stream-performance.mjs +3 -1
- package/src/stream.mjs +6 -4
- package/src/upstream-body.mjs +9 -8
- package/src/user-settings.mjs +2 -2
|
@@ -7,11 +7,24 @@
|
|
|
7
7
|
let memoryAction = null, memoryOrigin = null;
|
|
8
8
|
let disableRevision = null;
|
|
9
9
|
const drafts = new Map();let editorOrigin = null, discovery = null, desiredSource = null;
|
|
10
|
+
let importSequence = 0;
|
|
10
11
|
const apiForm = el("connection-api-form"), clientForm = el("connection-client-form");
|
|
11
12
|
const node = (tag, text, className) => { const item = document.createElement(tag);if (text !== undefined) item.textContent = text;if (className) item.className = className;return item; };
|
|
12
13
|
const source = id => data.providers.find(item => item.id === id), client = id => data.clients.find(item => item.id === id);
|
|
13
14
|
const accessDrafts = new Map(), accessResults = new Map();
|
|
15
|
+
const sourceLimitDrafts = new Map();
|
|
14
16
|
const accessForm = el("source-access-form");
|
|
17
|
+
el("source-limit-maximum").addEventListener("input", event => {
|
|
18
|
+
sourceLimitDrafts.set(selectedProvider, event.target.value);
|
|
19
|
+
el("source-limit-save").disabled = busy || (event.target.value === "" ? null : Number(event.target.value)) === (source(selectedProvider)?.concurrency?.maximum ?? null);
|
|
20
|
+
});
|
|
21
|
+
el("source-limit-form").addEventListener("submit", event => {
|
|
22
|
+
event.preventDefault();const id = selectedProvider, field = el("source-limit-maximum");
|
|
23
|
+
if (!field.reportValidity()) return;
|
|
24
|
+
void change({ operation: "source_limits", id, maximum: field.value === "" ? null : Number(field.value), impact_revision: data.source_impacts?.[id]?.revision }, () => {
|
|
25
|
+
sourceLimitDrafts.delete(id);renderAccess();words(el("source-limit-note"), "api_saved");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
15
28
|
const sameAccess = (a,b) => JSON.stringify([...a].sort()) === JSON.stringify([...b].sort());
|
|
16
29
|
function accessChoices(id) {
|
|
17
30
|
const provider=source(id);if(!provider)return [];
|
|
@@ -22,6 +35,10 @@
|
|
|
22
35
|
}
|
|
23
36
|
function renderAccess() {
|
|
24
37
|
const id=selectedProvider,provider=source(id),root=el("source-app-access");root.hidden=!provider;if(!provider)return;
|
|
38
|
+
const limit = el("source-limit-maximum"), maximum = provider.concurrency?.maximum ?? null;
|
|
39
|
+
if (document.activeElement !== limit || limit.dataset.source !== id) limit.value = sourceLimitDrafts.has(id) ? sourceLimitDrafts.get(id) : maximum ?? "";
|
|
40
|
+
limit.dataset.source = id;limit.placeholder = format("source_concurrency_auto");
|
|
41
|
+
limit.disabled = busy;el("source-limit-save").disabled = busy || (limit.value === "" ? null : Number(limit.value)) === maximum;
|
|
25
42
|
const waiting=id==="github"&&!globalThis.ccdxAntigravity?.state,pending=busy||id==="github"&&Boolean(globalThis.ccdxAntigravity?.pending);
|
|
26
43
|
const saved=savedAccess(id),selected=accessDrafts.get(id)||saved,dirty=!sameAccess(saved,selected),area=el("source-allowed-apps");
|
|
27
44
|
const focus=area.contains(document.activeElement)?document.activeElement.value:null;
|
|
@@ -130,9 +147,10 @@
|
|
|
130
147
|
if (busy) return;busy = true;generation++;
|
|
131
148
|
const previousImage = imageViewRevision(data);
|
|
132
149
|
const trigger = ["client", "image_model"].includes(input.operation) ? clientForm.querySelector('button[type="submit"]') : input.operation === "preview_client" ? el("connection-sync-preview")
|
|
133
|
-
: input.operation === "save_api" ? apiForm.querySelector('button[type="submit"]') : document.activeElement;
|
|
150
|
+
: input.operation === "save_api" ? apiForm.querySelector('button[type="submit"]') : input.operation === "source_limits" ? el("source-limit-save") : document.activeElement;
|
|
134
151
|
const oldKey = trigger?.dataset.i18n, oldText = trigger?.textContent;
|
|
135
152
|
if (trigger?.tagName === "BUTTON") { trigger.setAttribute("aria-busy", "true");trigger.disabled = true;words(trigger, input.operation === "preview_client" ? "api_reading" : "api_saving"); }
|
|
153
|
+
if (input.operation === "source_limits") renderAccess();
|
|
136
154
|
try { if (input.operation === "save_api") await stopDiscovery();data = await api(input);if (["client", "image_model"].includes(input.operation)) { drafts.delete(input.id);if (editingClient === input.id) bindingDirty = false; }mountClient();list();done?.(data);if (!done) {
|
|
137
155
|
if (input.operation === "save_api") {
|
|
138
156
|
desiredSource = input.id || data.providers.find(p => !p.builtin && p.name === input.config.name)?.id;
|
|
@@ -159,7 +177,7 @@
|
|
|
159
177
|
}
|
|
160
178
|
finally { busy = false;if (trigger?.tagName === "BUTTON") { trigger.removeAttribute("aria-busy");trigger.disabled = false;if (oldKey) words(trigger, oldKey);else trigger.textContent = oldText; }
|
|
161
179
|
if (["client", "preview_client", "image_model"].includes(input.operation)) bindingRows();
|
|
162
|
-
if (input.operation
|
|
180
|
+
if (["source_access", "source_limits"].includes(input.operation)) renderAccess();
|
|
163
181
|
if (input.operation === "save_api") words(apiForm.querySelector('button[type="submit"]'), editing ? "api_save" : "api_save_read");
|
|
164
182
|
}
|
|
165
183
|
return true;
|
|
@@ -529,29 +547,49 @@
|
|
|
529
547
|
impact_revision: disableRevision,
|
|
530
548
|
replacements: Object.fromEntries([...el("connection-replacements").querySelectorAll("select")].map(select => [select.name, select.value || null])) }); });
|
|
531
549
|
el("connection-add").addEventListener("click", () => { if (data) editApi(); });
|
|
532
|
-
el("connection-import").
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const preview = el("connection-import-preview");preview.hidden = true;preview.replaceChildren();
|
|
536
|
-
if (file.size > 256 * 1024) { message("ccdx_import_size_invalid");return; }
|
|
537
|
-
try {
|
|
538
|
-
const result = await api({ operation: "preview_import", content: JSON.parse(await file.text()) });
|
|
550
|
+
function closeImport() { importSequence++;el("connection-import-preview").hidden = true;el("connection-import").focus(); }
|
|
551
|
+
function importPreview(result) {
|
|
552
|
+
const preview = el("connection-import-preview");preview.replaceChildren();
|
|
539
553
|
const heading = node("h3");words(heading, "import_preview");preview.append(heading);
|
|
540
|
-
const note = node("p", undefined, "hint");words(note, "import_scope");preview.append(note);
|
|
554
|
+
if (result.drafts.length) { const note = node("p", undefined, "hint");words(note, "import_scope");preview.append(note); }
|
|
555
|
+
if (result.discovery && !result.drafts.length) { const state = node("p");words(state, "import_discovery_" + result.discovery.state);preview.append(state); }
|
|
556
|
+
if (result.discovery?.skipped) { const skipped = node("p", undefined, "hint");words(skipped, "import_discovery_skipped");preview.append(skipped); }
|
|
557
|
+
if (result.discovery?.truncated) { const limit = node("p", undefined, "hint");words(limit, "import_discovery_truncated");preview.append(limit); }
|
|
541
558
|
for (const draft of result.drafts) {
|
|
542
559
|
const row = node("div", undefined, "connection-row"), info = node("div"), actions = node("div", undefined, "connection-actions");
|
|
543
560
|
info.append(node("h3", draft.config.name), node("p", draft.config.base_url, "hint"));
|
|
544
561
|
for (const warning of draft.warnings) { const text = node("p", undefined, "hint");words(text, "import_" + warning);info.append(text); }
|
|
545
562
|
actions.append(button("import_review", () => {
|
|
546
|
-
editApi();const config = draft.config;
|
|
563
|
+
editApi();editorOrigin = el("connection-import");const config = draft.config;
|
|
547
564
|
apiForm.elements.name.value = config.name;apiForm.elements.base.value = config.base_url;apiForm.elements.auth_header.value = config.auth_header;
|
|
548
565
|
apiForm.elements.key_env.value = config.key_env || "";keyMode();
|
|
549
566
|
for (const input of apiForm.querySelectorAll('[name="protocol"]')) input.checked = Boolean(config.endpoints[input.value]);
|
|
550
|
-
setEndpoints(config.base_url, config.endpoints);models = structuredClone(config.models);selectedModels = new Set(models.map(model => model.id));modelRows();preview.hidden = true;
|
|
567
|
+
setEndpoints(config.base_url, config.endpoints);models = structuredClone(config.models);selectedModels = new Set(models.map(model => model.id));modelRows();importSequence++;preview.hidden = true;
|
|
551
568
|
}));row.append(info, actions);preview.append(row);
|
|
552
569
|
}
|
|
553
|
-
preview.hidden = false;
|
|
554
|
-
|
|
570
|
+
preview.append(button("cancel", closeImport));preview.hidden = false;
|
|
571
|
+
}
|
|
572
|
+
async function importTool(tool) {
|
|
573
|
+
const sequence = ++importSequence, preview = el("connection-import-preview"), reading = node("p");words(reading, "reading");
|
|
574
|
+
preview.replaceChildren(reading, button("cancel", closeImport));preview.hidden = false;
|
|
575
|
+
try { const result = await api({ operation: "preview_import", tool });if (sequence === importSequence) importPreview(result); }
|
|
576
|
+
catch (error) { if (sequence === importSequence) { preview.hidden = true;message(/^ccdx_import_/.test(error.message) ? error.message : "ccdx_import_discovery_invalid"); } }
|
|
577
|
+
}
|
|
578
|
+
el("connection-import").addEventListener("click", () => {
|
|
579
|
+
if (!data || busy) return;importSequence++;
|
|
580
|
+
const preview = el("connection-import-preview"), heading = node("h3"), actions = node("div", undefined, "section-actions");words(heading, "import_source");
|
|
581
|
+
const file = button("import_file", () => el("connection-import-file").click());
|
|
582
|
+
const cc = node("button", "CC Switch"), magpie = node("button", "Magpie");cc.type = magpie.type = "button";
|
|
583
|
+
cc.dataset.importTool = "cc-switch";magpie.dataset.importTool = "magpie";
|
|
584
|
+
cc.addEventListener("click", () => void importTool("cc-switch"));magpie.addEventListener("click", () => void importTool("magpie"));
|
|
585
|
+
actions.append(file, cc, magpie, button("cancel", closeImport));preview.replaceChildren(heading, actions);preview.hidden = false;file.focus();
|
|
586
|
+
});
|
|
587
|
+
el("connection-import-file").addEventListener("change", async event => {
|
|
588
|
+
const file = event.target.files?.[0];event.target.value = "";if (!file) return;
|
|
589
|
+
const sequence = ++importSequence, preview = el("connection-import-preview");preview.hidden = true;preview.replaceChildren();
|
|
590
|
+
if (file.size > 256 * 1024) { message("ccdx_import_size_invalid");return; }
|
|
591
|
+
try { const result = await api({ operation: "preview_import", content: JSON.parse(await file.text()) });if (sequence === importSequence) importPreview(result); }
|
|
592
|
+
catch (error) { if (sequence === importSequence) message(/^ccdx_import_/.test(error.message) ? error.message : "ccdx_import_format_invalid"); }
|
|
555
593
|
});
|
|
556
594
|
for (const id of ["connection-cancel", "connection-disable-cancel"]) el(id).addEventListener("click", () => { panels();(editorOrigin?.isConnected ? editorOrigin : el("connection-source-list").querySelector("button") || el("connection-add")).focus(); });
|
|
557
595
|
el("refresh").addEventListener("click", () => { if (["#models", "#codex", "#claude"].includes(location.hash)) void load(); });
|
package/src/dashboard/console.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
const el = id => document.getElementById(id);
|
|
3
3
|
const label = (node, key, values = {}) => globalThis.ccdxLanguage.set(node, key, values);
|
|
4
4
|
const titles = { overview: "overview", codex: "Codex", claude: "Claude", gemini: "Antigravity", models: "model_services", usage: "usage_and_diagnostics", requests: "request_records", checks: "tools_checks_title", system: "system_and_settings" };
|
|
5
|
-
const settingsViews = ["codex", "claude", "models", "system", "checks"];
|
|
6
|
-
let current = "overview", settings = null, settingsPending = false, stopped = false, timer = null, ticks = 0;
|
|
5
|
+
const settingsViews = ["codex", "claude", "gemini", "models", "system", "checks"];
|
|
6
|
+
let current = "overview", settings = null, settingsPending = false, settingsReadPending = null, stopped = false, timer = null, ticks = 0;
|
|
7
7
|
let sourceDirty = false, reviewDirty = false, sourceModels = [], modelsPreference = null, sourceGeneration = 0, modelsSource = null;
|
|
8
8
|
let settingsReadAt = null;
|
|
9
9
|
let accountsPending = false;
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
if (item.dataset.route === next) item.setAttribute("aria-current", "page");else item.removeAttribute("aria-current");
|
|
65
65
|
}
|
|
66
66
|
label(el("page-title"), titles[next]);
|
|
67
|
+
applications?.routeChanged();
|
|
67
68
|
el("page-settings-note").textContent = "";
|
|
68
69
|
window.scrollTo(0, 0);
|
|
69
70
|
el("main-content").focus({ preventScroll: true });
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
async function api(body) {
|
|
80
81
|
const response = await fetch("/_ccdx/ui/settings", { method: body ? "POST" : "GET", cache: "no-store",
|
|
81
82
|
headers: { "X-CCDX-Dashboard": "1", ...(body ? { "Content-Type": "application/json" } : {}) },
|
|
82
|
-
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout((body?.action === "prediction" || ["image", "codex_app"].includes(body?.action) && ["open", "restart"].includes(body?.operation)) ? 210000 : ["image", "codex_app"].includes(body?.action) || body?.operation === "account" ? 65000 : 15000) });
|
|
83
|
+
...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout((body?.action === "prediction" || ["image", "codex_app"].includes(body?.action) && ["open", "restart"].includes(body?.operation)) ? 210000 : ["image", "codex_app", "application"].includes(body?.action) || body?.operation === "account" ? 65000 : 15000) });
|
|
83
84
|
const data = await response.json();if (!response.ok) throw Object.assign(new Error(data.error || `HTTP ${response.status}`), { code: data.code });return data;
|
|
84
85
|
}
|
|
85
86
|
const preferences = globalThis.ccdxDashboardPreferences?.create({ element: el, api, applied: applySettings, time,
|
|
@@ -87,6 +88,8 @@
|
|
|
87
88
|
refreshAnimation() { dashboardRefresh.invalidate("animation");if (current === "system") void dashboardRefresh.refresh("animation", { force: true }); } });
|
|
88
89
|
globalThis.ccdxSettingsPreferences = preferences;
|
|
89
90
|
const features = globalThis.ccdxDashboardFeatures?.create({ element: el, api, apply: applySettings, change, localize: label });
|
|
91
|
+
const applications = globalThis.ccdxApplications?.create({ element: el, change, localize: label, isBusy: () => settingsPending });
|
|
92
|
+
globalThis.ccdxApplicationControls = applications;
|
|
90
93
|
const states = { needs_github_access: "image_needs_github", image_model_unavailable: "image_no_models", immediate: "effective_now", terminal_unavailable: "terminal_animation_unavailable_in_this_output_mode", next_start: "next_ccdx_start", next_call: "applies_to_new_calls", needs_setup: "setup_required",
|
|
91
94
|
next_config_request: "next_configuration_request_cached_suggestions_may_remain", needs_app_relaunch: "reopen_the_client_to_finish", needs_service_restart: "restart_ccdx_to_finish" };
|
|
92
95
|
const selectedSource = () => providerEntries.find(source => source.id === el("source-provider").value);
|
|
@@ -189,30 +192,34 @@
|
|
|
189
192
|
}
|
|
190
193
|
el("process-notice").textContent = data.terminal?.last_notice || "";
|
|
191
194
|
preferences?.sync(data, meta);
|
|
195
|
+
applications?.sync(data);
|
|
192
196
|
}
|
|
193
197
|
window.addEventListener("ccdx:connections", event => { if (current === "codex" && event.detail?.imageChanged) void loadSettings(); });
|
|
194
198
|
async function loadSettings() {
|
|
195
|
-
if (settingsPending) return;
|
|
199
|
+
if (settingsPending) return settingsReadPending;
|
|
196
200
|
settingsPending = true;
|
|
201
|
+
applications?.render();
|
|
197
202
|
el("terminal-color-theme").disabled = true;
|
|
198
203
|
syncAccountControls();
|
|
199
204
|
const readVersion = preferences?.version;
|
|
200
|
-
try { applySettings(await
|
|
205
|
+
try { settingsReadPending = api();applySettings(await settingsReadPending, { readVersion });settingsReadAt = time(Date.now());void globalThis.ccdxConnections?.load(); }
|
|
201
206
|
catch (error) {
|
|
202
207
|
for (const id of ["settings-note", ...(settingsViews.includes(current) ? ["page-settings-note"] : [])]) {
|
|
203
208
|
label(el(id), settingsReadAt ? "showing_previous_data_updated_time" : "could_not_read_settings", { time: settingsReadAt });
|
|
204
209
|
el(id).title = error.message;
|
|
205
210
|
}
|
|
206
211
|
}
|
|
207
|
-
finally { settingsPending = false;el("m365-enabled").disabled = !settings;el("terminal-color-theme").disabled = !settings;el("apply-source").disabled = !sourceReady();syncReviewButton();syncAccountControls(); }
|
|
212
|
+
finally { settingsReadPending = null;settingsPending = false;applications?.render();el("m365-enabled").disabled = !settings;el("terminal-color-theme").disabled = !settings;el("apply-source").disabled = !sourceReady();syncReviewButton();syncAccountControls(); }
|
|
208
213
|
}
|
|
209
214
|
async function change(body, button, { quiet = false } = {}) {
|
|
215
|
+
if (settingsReadPending) await settingsReadPending.catch(() => {});
|
|
210
216
|
if (settingsPending) return;
|
|
211
217
|
settingsPending = true;
|
|
218
|
+
applications?.render();
|
|
212
219
|
syncAccountControls();
|
|
213
220
|
const controls = [...document.querySelectorAll("[role=switch], #save-history, #clean-history, #fix-prediction, #apply-source, #save-review, #source-provider, #source-model, #source-review, #source-review-effort, #terminal-color-theme, #m365-enabled, #prediction-continue, #prediction-open, #prediction-setup, #prediction-remove, #image-models input, #image-check, #image-repair, #image-open, #decoded-limit, #decoded-limit-save, #decoded-limit-default, #install-update")];
|
|
214
221
|
controls.forEach(input => { input.disabled = true; });
|
|
215
|
-
const note = el(body.action === "codex_app" ? body.intent === "prediction" ? "prediction-open-note" : "image-action-note" : body.action === "prediction" ? body.operation === "open" ? "prediction-open-note" : "prediction-action-note" : body.action === "image" ? "effect-image_enabled" : body.action === "update" ? "manual-update-note" : body.action === "decoded_limit" ? "decoded-limit-note" : body.action === "nightly_update" ? "nightly-state" : body.key ? `effect-${body.key}` : body.action === "color_theme" ? "terminal-color-note"
|
|
222
|
+
const note = el(body.action === "application" ? "application-state" : body.key === "codex_auto_launch" ? "codex-auto-launch-note" : body.action === "codex_app" ? body.intent === "prediction" ? "prediction-open-note" : "image-action-note" : body.action === "prediction" ? body.operation === "open" ? "prediction-open-note" : "prediction-action-note" : body.action === "image" ? "effect-image_enabled" : body.action === "update" ? "manual-update-note" : body.action === "decoded_limit" ? "decoded-limit-note" : body.action === "nightly_update" ? "nightly-state" : body.key ? `effect-${body.key}` : body.action === "color_theme" ? "terminal-color-note"
|
|
216
223
|
: body.action.startsWith("history_") ? "effect-history" : body.action === "prediction_fix" ? "prediction-note"
|
|
217
224
|
: body.operation === "switch" ? "source-control-note" : body.operation === "auto-review" ? "review-control-note"
|
|
218
225
|
: body.operation === "account" ? "m365-account-note" : "m365-control-note");
|
|
@@ -248,10 +255,12 @@
|
|
|
248
255
|
} finally {
|
|
249
256
|
settingsPending = false;controls.forEach(input => { input.disabled = false; });
|
|
250
257
|
syncAccountControls();
|
|
251
|
-
if (settings) for (const [key, value] of Object.entries(settings.effective)) if (value.locked)
|
|
258
|
+
if (settings) for (const [key, value] of Object.entries(settings.effective)) if (value.locked) {
|
|
259
|
+
const node = el(key === "codex_auto_launch" ? "codex-auto-launch" : `setting-${key}`);if (node) node.disabled = true;
|
|
260
|
+
}
|
|
252
261
|
if (settings?.history.source === "environment") el("save-history").disabled = true;
|
|
253
262
|
el("apply-source").disabled = !sourceReady();el("source-model").disabled = !selectedSource()?.selection.models_required;syncReviewButton();
|
|
254
|
-
features?.render(settings, { notes: false });
|
|
263
|
+
features?.render(settings, { notes: false });applications?.render();
|
|
255
264
|
button?.removeAttribute("aria-busy");
|
|
256
265
|
}
|
|
257
266
|
}
|
|
@@ -343,6 +352,7 @@
|
|
|
343
352
|
});
|
|
344
353
|
el("auto-refresh").addEventListener("click", schedule);
|
|
345
354
|
el("refresh").addEventListener("click", () => { if (settingsViews.includes(current)) void loadSettings(); });
|
|
355
|
+
el("refresh").addEventListener("click", () => applications?.refresh());
|
|
346
356
|
document.addEventListener("ccdx:privacy-preferences", event => { if (event.detail?.preferences) preferences?.sync(event.detail);else if (settingsViews.includes(current)) void loadSettings(); });
|
|
347
357
|
window.addEventListener("pagehide", () => { stopped = true;clearTimeout(timer); });
|
|
348
358
|
window.addEventListener("pageshow", () => { stopped = false;schedule(); });
|
package/src/dashboard/gemini.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const el=id=>document.getElementById(id),language=globalThis.ccdxLanguage;
|
|
3
3
|
let busy=false,state=null,draft=null,notice=null,pendingAction=null;
|
|
4
|
+
let sharedApplication=null,sharedPending=false;
|
|
4
5
|
const words=(id,key)=>language.set(el(id),key);
|
|
5
6
|
const clear=id=>{el(id).removeAttribute('data-i18n');el(id).removeAttribute('data-i18n-args');el(id).textContent='';el(id).title=''};
|
|
6
7
|
const controls=['gemini-enabled','gemini-open','gemini-refresh','gemini-save','gemini-cancel'];
|
|
@@ -18,10 +19,11 @@
|
|
|
18
19
|
return [...groups.values()];
|
|
19
20
|
};
|
|
20
21
|
function render(){
|
|
21
|
-
for(const id of controls)el(id).disabled=busy||!state;
|
|
22
|
+
for(const id of controls)el(id).disabled=busy||sharedPending||!state;
|
|
22
23
|
if(!state)return;
|
|
24
|
+
if(sharedApplication&&(sharedApplication.inspection||0)>=(state.application?.inspection||0))state.app={...state.app,status:sharedApplication.status,version:sharedApplication.version||state.app.version};
|
|
23
25
|
if(!busy)el('gemini-enabled').checked=state.enabled;
|
|
24
|
-
el('gemini-save').disabled=busy||!dirty();el('gemini-cancel').disabled=busy||!dirty();
|
|
26
|
+
el('gemini-save').disabled=busy||sharedPending||!dirty();el('gemini-cancel').disabled=busy||sharedPending||!dirty();
|
|
25
27
|
words('gemini-save',busy&&pendingAction==='models'?'api_saving':'api_save');if(busy&&pendingAction==='models')el('gemini-save').setAttribute('aria-busy','true');else el('gemini-save').removeAttribute('aria-busy');
|
|
26
28
|
words('gemini-draft-state',dirty()?'cap_unsaved':'cap_saved');
|
|
27
29
|
words('gemini-route-state',!state.enabled?'gemini_disabled':state.source_enabled===false?'gemini_source_disabled':state.app.status==='starting'?'gemini_route_waiting':state.models_reload_required===null?'gemini_catalog_unknown':state.models_reload_required?'gemini_models_pending':state.route_observed?'gemini_route_observed':'gemini_route_waiting');
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
const needsReload=state.enabled&&state.source_enabled!==false&&(state.models_reload_required===true||state.models_reload_required===null);
|
|
31
33
|
const hint=!state.enabled&&state.app.status==='running'?'gemini_pause_reopen':needsReload?(state.app.status==='running'?(state.models_reload_required===null?'gemini_maybe_reopen':'gemini_reopen'):state.app.status==='stopped'?'gemini_open_to_load':null):null;
|
|
32
34
|
el('gemini-reopen').hidden=!hint;if(hint)words('gemini-reopen',hint);
|
|
33
|
-
el('gemini-open').disabled=busy||state.app.status!=='stopped';
|
|
35
|
+
el('gemini-open').disabled=busy||sharedPending||state.app.status!=='stopped';
|
|
34
36
|
const list=el('gemini-models'),focus=list.contains(document.activeElement)?document.activeElement.value:null;list.replaceChildren();
|
|
35
37
|
for(const model of groupedModels()){
|
|
36
38
|
const chosen=new Set(draft||selected()),ids=model.efforts.map(item=>item.id);
|
|
@@ -63,13 +65,14 @@
|
|
|
63
65
|
}
|
|
64
66
|
return state;
|
|
65
67
|
}catch(error){if(!report)throw error;notice='gemini_operation_failed';words('gemini-note',notice);el('gemini-note').title=error.message}
|
|
66
|
-
finally{busy=false;pendingAction=null;render();window.dispatchEvent(new
|
|
68
|
+
finally{busy=false;pendingAction=null;render();window.dispatchEvent(new CustomEvent('ccdx-gemini-state',{detail:{application:state?.application}}))}
|
|
67
69
|
}
|
|
68
70
|
globalThis.ccdxAntigravity={get state(){return state},get pending(){return busy},setEnabled:enabled=>load(enabled?'enable':'disable',{},false)};
|
|
69
71
|
el('gemini-enabled').addEventListener('change',event=>void load(event.target.checked?'enable':'disable'));
|
|
70
72
|
el('gemini-model-form').addEventListener('submit',event=>{event.preventDefault();if(dirty())void load('models',{models:draft})});
|
|
71
73
|
el('gemini-cancel').addEventListener('click',()=>{draft=null;notice=null;clear('gemini-note');render()});
|
|
72
|
-
el('gemini-open').addEventListener('click',()=>void load('open'));
|
|
74
|
+
el('gemini-open').addEventListener('click',()=>{if(globalThis.ccdxApplicationControls)globalThis.ccdxApplicationControls.open('antigravity');else void load('open')});
|
|
75
|
+
window.addEventListener('ccdx:application-state',event=>{if(event.detail?.id==='antigravity'){sharedApplication=event.detail.application;sharedPending=event.detail.pending;render()}});
|
|
73
76
|
el('gemini-refresh').addEventListener('click',()=>void load('refresh'));
|
|
74
77
|
el('refresh').addEventListener('click',()=>{if(['#gemini','#models'].includes(location.hash))void load(location.hash==='#models'?'summary':'refresh')});
|
|
75
78
|
window.addEventListener('hashchange',()=>{if(['#gemini','#models'].includes(location.hash))void load(location.hash==='#models'?'summary':undefined)});
|
package/src/dashboard/index.html
CHANGED
|
@@ -38,8 +38,17 @@
|
|
|
38
38
|
<section class="intro">
|
|
39
39
|
<h1><span id="page-title" data-i18n="overview">Overview</span></h1>
|
|
40
40
|
<p id="page-settings-note" class="hint" role="status"></p>
|
|
41
|
+
<div id="application-launch" hidden>
|
|
42
|
+
<button type="button" id="application-open"><span aria-hidden="true">↗</span><span id="application-open-label" data-i18n="application_open">Open app</span></button>
|
|
43
|
+
<span id="application-state" class="hint" role="status" aria-live="polite"></span>
|
|
44
|
+
</div>
|
|
41
45
|
<div id="preferences-status" class="preferences-status" role="status" aria-live="polite" hidden></div>
|
|
42
46
|
</section>
|
|
47
|
+
<div id="application-reopen-confirm" class="section-actions" hidden>
|
|
48
|
+
<span data-i18n="application_reopen_warning">Reopening may interrupt current tasks.</span>
|
|
49
|
+
<button type="button" id="application-reopen-cancel" data-i18n="cancel">Cancel</button>
|
|
50
|
+
<button type="button" id="application-reopen-apply" data-i18n="application_reopen">Reopen</button>
|
|
51
|
+
</div>
|
|
43
52
|
|
|
44
53
|
|
|
45
54
|
<div data-view="overview">
|
|
@@ -54,6 +63,7 @@
|
|
|
54
63
|
<section class="panel dashboard-section"><h2 data-i18n="this_run_usage">THIS RUN</h2><p id="runtime-usage" class="table-note"></p><p class="table-note"><span data-i18n="approx_cache_hit_rate">Approx. cache hit rate</span>: <strong id="runtime-cache-hit" data-i18n-title="runtime_cache_hit_basis" title="Reused / input tokens from records with valid counts for both. ~ Partial coverage. — No valid input basis.">—</strong></p><p class="hint" data-i18n="updated_from_returned_usage_not_a_live_bill_pending_usage_is_not">Counts returned usage only. Pending usage is not included. This is not a live bill.</p></section>
|
|
55
64
|
</div>
|
|
56
65
|
<div data-view="codex" hidden>
|
|
66
|
+
<div class="setting-row" id="codex-auto-launch-row"><label for="codex-auto-launch" data-i18n="codex_auto_launch">Open Codex when CCDX starts</label><input id="codex-auto-launch" type="checkbox" role="switch"><span id="codex-auto-launch-note" class="hint" data-i18n="next_ccdx_start">Next CCDX start.</span></div>
|
|
57
67
|
<div id="codex-model-management"> <section class="connection-access" id="connection-clients">
|
|
58
68
|
<div id="connection-client-list"></div>
|
|
59
69
|
<details id="connection-disabled-clients" class="connection-disabled" hidden><summary data-i18n="api_disabled_clients">Disabled clients</summary><div id="connection-disabled-client-list"></div></details>
|
|
@@ -269,6 +279,12 @@
|
|
|
269
279
|
<div class="section-actions"><button id="source-access-save" type="submit" data-i18n="api_save" disabled>Save</button><button id="source-access-cancel" type="button" data-i18n="cap_discard_changes" disabled>Discard changes</button></div>
|
|
270
280
|
<p id="source-access-note" class="hint" role="status" aria-live="polite"></p>
|
|
271
281
|
</form>
|
|
282
|
+
<details class="tool-details" id="source-concurrency"><summary data-i18n="source_concurrency">Concurrency · Auto</summary>
|
|
283
|
+
<form id="source-limit-form"><div class="connection-fields"><label><span data-i18n="source_concurrency_maximum">Maximum concurrency</span><input id="source-limit-maximum" type="number" min="1" max="128" step="1" inputmode="numeric" placeholder="Auto" data-i18n-placeholder="source_concurrency_auto"></label></div>
|
|
284
|
+
<p class="hint" data-i18n="source_concurrency_hint">Leave blank for Auto. A value only sets its ceiling.</p>
|
|
285
|
+
<div class="section-actions"><button id="source-limit-save" type="submit" data-i18n="api_save" disabled>Save</button></div><p id="source-limit-note" class="hint" role="status" aria-live="polite"></p>
|
|
286
|
+
</form>
|
|
287
|
+
</details>
|
|
272
288
|
</section>
|
|
273
289
|
<details class="panel dashboard-section model-catalog" id="upstream-models" open>
|
|
274
290
|
<summary class="panel-heading"><h2 data-i18n="model_catalog">MODEL LIST</h2><span id="models-state" role="status" aria-live="polite" data-i18n="checking_live">CHECKING</span></summary>
|
|
@@ -366,6 +366,38 @@
|
|
|
366
366
|
"cap_context": ["Context", "上下文"],
|
|
367
367
|
"cap_reasoning": ["Reasoning", "推理"],
|
|
368
368
|
"cap_effort_follow": ["Follow app", "跟随应用"],
|
|
369
|
+
"application_open": ["Open app", "打开应用"],
|
|
370
|
+
"application_focus": ["Switch to app", "切换到应用"],
|
|
371
|
+
"application_reopen": ["Reopen", "重新打开"],
|
|
372
|
+
"application_check": ["Check state", "检查状态"],
|
|
373
|
+
"application_opening": ["Opening…", "正在打开…"],
|
|
374
|
+
"application_connected": ["Connected", "已接入"],
|
|
375
|
+
"application_pending": ["Connection unconfirmed", "接入待确认"],
|
|
376
|
+
"application_stopped": ["Not running", "未运行"],
|
|
377
|
+
"application_unknown": ["App state unconfirmed", "应用状态待确认"],
|
|
378
|
+
"application_not_installed": ["Not installed", "未安装"],
|
|
379
|
+
"application_unsupported": ["Unavailable on this platform", "当前平台暂不支持"],
|
|
380
|
+
"application_multiple": ["Multiple app processes found", "检测到多个应用进程"],
|
|
381
|
+
"application_reload_pending": ["Configuration pending load", "配置待加载"],
|
|
382
|
+
"application_reopen_warning": ["Reopening may interrupt current tasks.", "重新打开可能中断当前任务。"],
|
|
383
|
+
"application_action_failed": ["Could not open the app. Check its state and retry.", "未能打开应用,请检查状态后重试。"],
|
|
384
|
+
"application_action_open_failed": ["Could not open the app.", "未能打开应用。"],
|
|
385
|
+
"application_action_focus_unavailable": ["Could not switch to the running app.", "无法切换到运行中的应用。"],
|
|
386
|
+
"application_action_quit_refused": ["The app did not accept the quit request.", "应用未接受退出请求。"],
|
|
387
|
+
"application_action_quit_timeout": ["Finish tasks and quit the app manually, then open it here.", "请完成任务并手动退出应用,再从这里打开。"],
|
|
388
|
+
"application_action_app_changed": ["The app process changed. Check its state again.", "应用进程已变化,请重新检查。"],
|
|
389
|
+
"application_action_needs_app_relaunch": ["Reopen the app to load the configuration.", "重新打开应用以加载配置。"],
|
|
390
|
+
"application_action_route_conflict": ["Existing routing was preserved. Check the app configuration.", "已有路由已保留,请检查应用配置。"],
|
|
391
|
+
"codex_auto_launch": ["Open Codex when CCDX starts", "启动 CCDX 时打开 Codex"],
|
|
392
|
+
"application_preference_failed": ["Not saved. Try again.", "未保存,请重试。"],
|
|
393
|
+
"source_concurrency": ["Concurrency · Auto", "并发 · 自动"],
|
|
394
|
+
"source_concurrency_auto": ["Auto", "自动"],
|
|
395
|
+
"source_concurrency_maximum": ["Maximum concurrency", "最大并发"],
|
|
396
|
+
"source_concurrency_hint": ["Leave blank for Auto. A value only sets its ceiling.", "留空自动调节,填写数值仅设上限。"],
|
|
397
|
+
"ccdx_source_queue_full": ["The source is busy; its waiting queue is full.", "来源繁忙,等待队列已满。"],
|
|
398
|
+
"ccdx_source_queue_timeout": ["Waiting for the source timed out.", "等待来源超时。"],
|
|
399
|
+
"ccdx_source_limited": ["The source is limited. Retry after its recovery time.", "来源限流,请在恢复后重试。"],
|
|
400
|
+
"ccdx_source_limit_invalid": ["Choose Auto or a maximum from 1 to 128.", "请选择自动,或设置 1~128 的上限。"],
|
|
369
401
|
"cap_effort_scope": ["Used only when the app omits a reasoning level.", "应用未指定档位时生效。"],
|
|
370
402
|
"cap_effort_unavailable": ["{effort} (unavailable)", "{effort}(已不可用)"],
|
|
371
403
|
"ccdx_client_effort_unavailable": ["The saved reasoning level is unavailable. Choose a declared level or follow the app.", "已保存的推理档位不可用,请选择支持的档位或跟随应用。"],
|
|
@@ -394,6 +426,15 @@
|
|
|
394
426
|
"cap_details_draft": ["Details updated. Save the source to apply.", "能力已加入草稿,请保存来源。"],
|
|
395
427
|
"cap_preview_scope": ["Save to apply. Restart Claude after its settings change.", "保存后同步;Claude 配置更新后需重启。"],
|
|
396
428
|
"import_source": ["Import", "导入"],
|
|
429
|
+
"import_file": ["Choose file", "选择文件"],
|
|
430
|
+
"import_discovery_not_found": ["No configuration found. You can import an exported file.", "未找到配置,可使用导出文件导入。"],
|
|
431
|
+
"import_discovery_empty": ["No supported API configuration found.", "没有可直接导入的 API 配置。"],
|
|
432
|
+
"import_discovery_busy": ["Configuration is busy. Try again later or import a file.", "配置正忙,请稍后重试或使用文件导入。"],
|
|
433
|
+
"import_discovery_unreadable": ["Could not read configuration. Existing settings were kept.", "无法读取配置,已有设置已保留。"],
|
|
434
|
+
"import_discovery_unsupported": ["Unsupported configuration format. Use an exported JSON file.", "配置格式暂不支持,请使用导出的 JSON 文件。"],
|
|
435
|
+
"import_discovery_skipped": ["Some configurations need manual review and were skipped.", "已跳过需手动核对的配置。"],
|
|
436
|
+
"import_discovery_truncated": ["Results are limited. Import a file for other configurations.", "列表已限量,其余配置可使用文件导入。"],
|
|
437
|
+
"ccdx_import_discovery_invalid": ["Choose CC Switch or Magpie, or import a JSON file.", "请选择 CC Switch、Magpie,或导入 JSON 文件。"],
|
|
397
438
|
"import_preview": ["Import preview", "导入预览"],
|
|
398
439
|
"import_review": ["Review draft", "检查草稿"],
|
|
399
440
|
"import_scope": ["API metadata only. Configure the key before saving; client access is granted separately.", "只导入 API 元数据。保存前配置密钥,应用权限另行设置。"],
|
package/src/dashboard/ui.css
CHANGED
|
@@ -38,6 +38,15 @@ button[aria-busy="true"] { cursor: progress; }
|
|
|
38
38
|
h1 { margin: 0; font-size: clamp(20px, 3vw, 27px); font-weight: 650; letter-spacing: -.035em; }
|
|
39
39
|
.status-icon { display: block; grid-row: 1 / 3; width: 44px; height: 44px; color: var(--accent); }
|
|
40
40
|
.intro p { margin: 0; color: var(--subtle); font-size: 11px; }
|
|
41
|
+
.intro.has-application-launch { align-items:center; flex-wrap:wrap; }
|
|
42
|
+
.intro.has-application-launch #page-settings-note { order:3; flex-basis:100%; }
|
|
43
|
+
.intro.has-application-launch #page-settings-note:empty { display:none; }
|
|
44
|
+
#application-launch { display:flex; flex-direction:column; align-items:flex-end; gap:5px; margin-left:auto; }
|
|
45
|
+
#application-open { min-width:116px; display:inline-flex; align-items:center; justify-content:center; gap:8px; }
|
|
46
|
+
#application-state { margin:0; min-height:18px; }
|
|
47
|
+
#application-reopen-confirm { justify-content:flex-end; flex-wrap:wrap; margin:0 0 18px; }
|
|
48
|
+
#application-reopen-confirm > span { flex:1 1 200px; }
|
|
49
|
+
#codex-auto-launch-row { margin-bottom:18px; }
|
|
41
50
|
.snapshot-meta { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 8px 18px; min-width: 0; }
|
|
42
51
|
.intro .snapshot-meta p { margin: 0; overflow-wrap: anywhere; }
|
|
43
52
|
.overview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -248,7 +248,12 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
248
248
|
if (pathname === "/_ccdx/ui/settings") {
|
|
249
249
|
if (!serviceControl) { sendJson(res, 503, { error: "Settings require the running service; restart the updated CCDX" });return; }
|
|
250
250
|
if (req.method === "GET") {
|
|
251
|
-
try {
|
|
251
|
+
try {
|
|
252
|
+
const query = new URL(req.url, "http://localhost").searchParams, app = query.get("application");
|
|
253
|
+
if (app && !["codex", "claude_app", "antigravity"].includes(app)) { sendJson(res, 400, { error: "Unknown application" });return; }
|
|
254
|
+
const data = app && serviceControl.inspectApplication ? await serviceControl.inspectApplication(app, query.get("fresh") === "1") : serviceControl.snapshot();
|
|
255
|
+
sendJson(res, 200, data);
|
|
256
|
+
} catch { sendJson(res, 409, { error: "Service settings are unreadable; existing settings were preserved" }); }
|
|
252
257
|
return;
|
|
253
258
|
}
|
|
254
259
|
if (req.method !== "POST") { sendJson(res, 405, { error: "Use GET or POST" });return; }
|
package/src/dashboard.mjs
CHANGED
|
@@ -25,6 +25,7 @@ const ASSETS = new Map([
|
|
|
25
25
|
["/ui.js", ["./dashboard/ui.js", "text/javascript; charset=utf-8"]],
|
|
26
26
|
["/preferences.js", ["./dashboard/preferences.js", "text/javascript; charset=utf-8"]],
|
|
27
27
|
["/features.js", ["./dashboard/features.js", "text/javascript; charset=utf-8"]],
|
|
28
|
+
["/applications.js", ["./dashboard/applications.js", "text/javascript; charset=utf-8"]],
|
|
28
29
|
["/console.js", ["./dashboard/console.js", "text/javascript; charset=utf-8"]],
|
|
29
30
|
["/tools.js", ["./dashboard/tools.js", "text/javascript; charset=utf-8"]],
|
|
30
31
|
["/connections.js", ["./dashboard/connections.js", "text/javascript; charset=utf-8"]],
|
package/src/gemini-app.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
3
4
|
import {execFile} from "node:child_process";
|
|
4
5
|
import {promisify} from "node:util";
|
|
5
6
|
|
|
@@ -23,9 +24,9 @@ export async function inspectGeminiApp({platform=process.platform,app="/Applicat
|
|
|
23
24
|
|
|
24
25
|
// A launch plan is reviewable without changing files, credentials, or running apps.
|
|
25
26
|
// A prepared environment is not evidence that the App has adopted the route.
|
|
26
|
-
export function planGeminiAppLaunch(state,{cloudCodeUrl,env=process.env,managedGateway=false}={}) {
|
|
27
|
+
export function planGeminiAppLaunch(state,{cloudCodeUrl,env=process.env,home=os.homedir(),managedGateway=false}={}) {
|
|
27
28
|
if(!["running","stopped","multiple"].includes(state?.status))return {status:state?.status||"unknown"};
|
|
28
|
-
if(state.status==="stopped"
|
|
29
|
+
if(state.status==="stopped"&&!["/Applications/Gemini.app",path.join(home,"Applications/Gemini.app")].includes(state.app))throw new Error("Unrecognized Gemini App location");
|
|
29
30
|
const url=new URL(cloudCodeUrl);
|
|
30
31
|
if(url.protocol!=="http:"||url.hostname!=="127.0.0.1"||!url.port||Number(url.port)<1||url.username||url.password||url.search||url.hash)throw new Error("Gemini route must use a local CCDX endpoint");
|
|
31
32
|
if(managedGateway||Object.entries(env).some(([key,value])=>key.startsWith("AGY_LLM_GATEWAY_")&&value)||env.CLOUD_CODE_URL&&env.CLOUD_CODE_URL!==url.href)return {status:"route_conflict"};
|
package/src/http-transport.mjs
CHANGED
|
@@ -99,7 +99,7 @@ async function readRequestBuffer(req, maxBytes, signal) {
|
|
|
99
99
|
return Buffer.concat(chunks);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
async function readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal) {
|
|
102
|
+
async function readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal, onBytes) {
|
|
103
103
|
const contentLength = requestContentLength(req);
|
|
104
104
|
if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) {
|
|
105
105
|
throw payloadTooLarge("Raw", maxBodyBytes);
|
|
@@ -138,6 +138,7 @@ async function readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal)
|
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
});
|
|
141
|
+
onBytes?.(total);
|
|
141
142
|
if (preallocatedLength) {
|
|
142
143
|
if (!allocated) return "";
|
|
143
144
|
return new TextDecoder().decode(overflow ? Buffer.concat(overflow, total) : allocated.subarray(0, total));
|
|
@@ -198,9 +199,10 @@ export async function readJsonBody(req, {
|
|
|
198
199
|
if (signal?.aborted) throw admissionAbortError(signal);
|
|
199
200
|
const encodings = contentEncodings(req.headers?.["content-encoding"]);
|
|
200
201
|
if (encodings.every((encoding) => encoding === "identity")) {
|
|
201
|
-
return parse(await readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal));
|
|
202
|
+
return parse(await readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal, bytes => admission?.resize?.(bytes)));
|
|
202
203
|
}
|
|
203
204
|
const buffer = await readRequestBuffer(req, maxBodyBytes, signal);
|
|
205
|
+
admission?.resize?.(buffer.length);
|
|
204
206
|
let releaseDecompression = () => {};
|
|
205
207
|
let decodedReservation;
|
|
206
208
|
let retainDecodedReservation = false;
|
|
@@ -272,6 +274,7 @@ export function sendJsonError(res, err, fallbackStatus = 400) {
|
|
|
272
274
|
context?.onHttpError?.({ code: err?.code || err?.jsonBody?.error?.code,
|
|
273
275
|
origin: context.errorOrigin || (statusCode < 500 ? "client_validation" : "local_transport") });
|
|
274
276
|
const headers = { "Content-Type": "application/json" };
|
|
277
|
+
if (Number.isFinite(err?.retryAfterMs) && err.retryAfterMs > 0) headers["Retry-After"] = String(Math.ceil(err.retryAfterMs / 1000));
|
|
275
278
|
if (err?.origin === "privacy" && Number.isInteger(err.retryAfter) && err.retryAfter > 0) headers["Retry-After"] = String(err.retryAfter);
|
|
276
279
|
if (statusCode === 408 || statusCode === 413) headers.Connection = "close";
|
|
277
280
|
res.writeHead(statusCode, headers);
|
package/src/launcher.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { installedWindowsPredictionApp, windowsPredictionAppProcesses } from "./native-prediction-windows.mjs";
|
|
5
5
|
import { status } from "./status.mjs";
|
|
6
6
|
import { isPredictionPacUrl } from "./prediction-pac.mjs";
|
|
7
|
+
import { readUserSettings } from "./user-settings.mjs";
|
|
7
8
|
|
|
8
9
|
export { ensureAuth } from "./auth.mjs";
|
|
9
10
|
|
|
@@ -14,9 +15,9 @@ const APP_PATH_CANDIDATES = [
|
|
|
14
15
|
"/Applications/ChatGPT.app",
|
|
15
16
|
];
|
|
16
17
|
|
|
17
|
-
export function autoLaunchEnabled(env = process.env) {
|
|
18
|
+
export function autoLaunchEnabled(env = process.env, options = {}) {
|
|
18
19
|
const raw = env.CCDX_AUTO_LAUNCH;
|
|
19
|
-
if (raw === undefined || raw === "") return true;
|
|
20
|
+
if (raw === undefined || raw === "") return readUserSettings({ ...options, env, strict: true }).codex_auto_launch === true;
|
|
20
21
|
return !/^(0|false|no|off)$/i.test(String(raw).trim());
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -88,7 +89,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
88
89
|
if (running.length === 1 && running[0].readable && !running[0].route && persistedPredictionRoute) {
|
|
89
90
|
onPredictionRoute("persisted");log(status("info", "Codex already running"));return true;
|
|
90
91
|
}
|
|
91
|
-
throw new Error("Running Codex App uses an old or unverified prediction route. Fully quit the App, then
|
|
92
|
+
throw new Error("Running Codex App uses an old or unverified prediction route. Fully quit the App, then open it from its CCDX page; no process was stopped");
|
|
92
93
|
}
|
|
93
94
|
await preparePredictionRoute?.();
|
|
94
95
|
const launched = await new Promise(resolve => {
|
|
@@ -120,7 +121,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
if (!autoLaunchEnabled(env)) {
|
|
123
|
-
log(status("info", "Auto-open is off. Open Codex
|
|
124
|
+
log(status("info", "Auto-open is off. Open Codex from its Web UI page."));
|
|
124
125
|
return false;
|
|
125
126
|
}
|
|
126
127
|
|
|
@@ -143,7 +144,7 @@ export async function openCodex({ env = process.env, spawnImpl = spawn, platform
|
|
|
143
144
|
if (running.length === 1 && running[0].readable && !running[0].route && persistedPredictionRoute) {
|
|
144
145
|
onPredictionRoute("persisted");log(status("info", "Codex already running"));return true;
|
|
145
146
|
}
|
|
146
|
-
throw new Error("Running Codex App uses an old or unverified prediction route. Fully quit the App, then
|
|
147
|
+
throw new Error("Running Codex App uses an old or unverified prediction route. Fully quit the App, then open it from its CCDX page; no process was stopped");
|
|
147
148
|
}
|
|
148
149
|
await preparePredictionRoute?.();
|
|
149
150
|
if (!await tryOpen([predictionApp, ...imageArgs, ...extraArgs], { spawnImpl })) {
|
package/src/native-images.mjs
CHANGED
|
@@ -86,7 +86,7 @@ export function createNativeImagesHandler({ client, acquireRequest, privacy, env
|
|
|
86
86
|
const context = currentRequestContext();
|
|
87
87
|
if (context) { context.provider = "github";context.streamPerformance?.setProvider?.("github"); }
|
|
88
88
|
abort.setTimeout(timeoutMs);
|
|
89
|
-
const forward = input => client.images(operation, { ...body, prompt: input.input }, { signal: abort.signal });
|
|
89
|
+
const forward = input => client.images(operation, { ...body, prompt: input.input }, { signal: abort.signal, sourceBodyManaged: true });
|
|
90
90
|
const call = privacy?.wrap ? privacy.wrap(forward, { res, protocol: "responses", client: "codex" }) : forward;
|
|
91
91
|
const response = await call({ input: body.prompt }, { signal: abort.signal });
|
|
92
92
|
if (!response.ok) {
|
package/src/provider-runtime.mjs
CHANGED
|
@@ -19,6 +19,9 @@ import { accessSettingsPath, readAccessSettings } from "./access-settings.mjs";
|
|
|
19
19
|
import { createStreamPerformanceMetrics } from "./stream-performance.mjs";
|
|
20
20
|
import { M365_API_HOST } from "./providers/m365-endpoint.mjs";
|
|
21
21
|
import { m365CatalogDiagnostic, m365CatalogMessage } from "./providers/m365-catalog-diagnostic.mjs";
|
|
22
|
+
import { admittedSource } from "./source-admission.mjs";
|
|
23
|
+
import { createRuntimeSourceAdmission } from "./source-admission-state.mjs";
|
|
24
|
+
import { createApplicationEvidence } from "./application-evidence.mjs";
|
|
22
25
|
|
|
23
26
|
const unavailable = reason => Object.assign(new Error(`Microsoft 365 is unavailable (${reason}); GitHub routing was not substituted`),
|
|
24
27
|
{ code: reason, statusCode: 503 });
|
|
@@ -27,6 +30,8 @@ const unavailable = reason => Object.assign(new Error(`Microsoft 365 is unavaila
|
|
|
27
30
|
// image configuration or each other's credentials.
|
|
28
31
|
export function createProviderRuntime(options = {}) {
|
|
29
32
|
options = { ...options, corePort: options.corePort ?? Number((options.env || process.env).ADAPTER_PORT || 2026) };
|
|
33
|
+
options.sourceAdmission ||= createRuntimeSourceAdmission(options);
|
|
34
|
+
options.applicationEvidence ||= createApplicationEvidence();
|
|
30
35
|
const compaction = options.compaction || createContextCompactionService({ enabled() { try { return servicePreferences(options).context_compaction_enabled; } catch { return false; } } });
|
|
31
36
|
let connections;
|
|
32
37
|
const legacy = createBuiltinProviderRuntime({ ...options, compaction, managedClaude: () => connections?.managesClaude() !== false,
|
|
@@ -37,10 +42,10 @@ export function createProviderRuntime(options = {}) {
|
|
|
37
42
|
|
|
38
43
|
function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGithubCatalog, githubCredentialFingerprint = "", githubClientConfigured = true, home, env = process.env, platform = process.platform,
|
|
39
44
|
corePort = Number(env.ADAPTER_PORT || 2026), log = () => {}, createM365, startGateway, configureClients, restoreClients,
|
|
40
|
-
discoverM365 = requestM365Accounts, managedClaude, onClaudeReady, preserveClientConfiguration, privacy, compaction } = {}) {
|
|
41
|
-
const options = { home, env, platform }, github = { ...createGithubProvider({ client: githubClient,
|
|
45
|
+
discoverM365 = requestM365Accounts, managedClaude, onClaudeReady, preserveClientConfiguration, privacy, compaction, sourceAdmission, applicationEvidence } = {}) {
|
|
46
|
+
const options = { home, env, platform }, github = admittedSource({ ...createGithubProvider({ client: githubClient,
|
|
42
47
|
profileId: () => { const value = typeof githubCredentialFingerprint === "function" ? githubCredentialFingerprint() : githubCredentialFingerprint;
|
|
43
|
-
return value ? `codex:${value}` : "codex"; } }), registry: githubRegistry };
|
|
48
|
+
return value ? `codex:${value}` : "codex"; } }), registry: githubRegistry }, sourceAdmission);
|
|
44
49
|
let selection = readProviderSettings(options), m365 = null, gateway = null, pending = null, closed = false, serial = null;
|
|
45
50
|
let reason = null, claudeReason = null, lastClients = {};
|
|
46
51
|
let changingAccount = false;
|
|
@@ -76,10 +81,10 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
|
|
|
76
81
|
if (!m365) {
|
|
77
82
|
const factory = createM365 || (await import("./providers/m365.mjs")).createM365Provider;
|
|
78
83
|
if (closed || !enabled) return null;
|
|
79
|
-
m365 = factory({ home, env, log, onCatalog() {
|
|
84
|
+
m365 = admittedSource(factory({ home, env, log, onCatalog() {
|
|
80
85
|
// Reconcile after refresh, outside inference serialization and without a watcher.
|
|
81
86
|
setImmediate(() => { if (!pending && gateway && !closed && enabled) void syncClaudeClients(); });
|
|
82
|
-
} });
|
|
87
|
+
} }), sourceAdmission);
|
|
83
88
|
sources.set(m365.id, m365);
|
|
84
89
|
}
|
|
85
90
|
await m365.refresh();if (closed || !enabled) return null;
|
|
@@ -90,7 +95,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
|
|
|
90
95
|
if (!gateway) {
|
|
91
96
|
const start = startGateway || (await import("./claude-gateway.mjs")).createClaudeGateway;
|
|
92
97
|
const opened = await start({ privacy, compaction, provider: m365, apiKey, port: corePort, env, log, performance: claudePerformance,
|
|
93
|
-
onRequest({ client }) { lastClients[client] = new Date().toISOString(); } });
|
|
98
|
+
onRequest({ client }, req) { lastClients[client] = new Date().toISOString();applicationEvidence?.accept(req, "claude_app", "inference"); } });
|
|
94
99
|
if (closed || !enabled) { await opened.close();return null; }
|
|
95
100
|
gateway = opened;
|
|
96
101
|
}
|
|
@@ -149,15 +154,15 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
|
|
|
149
154
|
if (!chosen) throw Object.assign(new Error("Account list changed. Check again and select an available account."), { code: "m365_account_selection_stale", statusCode: 409 });
|
|
150
155
|
const switched = discovered.binding && m365AccountKey(discovered.binding) !== m365AccountKey(chosen);
|
|
151
156
|
const factory = createM365 || (await import("./providers/m365.mjs")).createM365Provider;
|
|
152
|
-
candidate = factory({ home, env, log, persist: false,
|
|
157
|
+
candidate = admittedSource(factory({ home, env, log, persist: false,
|
|
153
158
|
account: { ...chosen, selection_source: "manual", ...(switched || discovered.binding?.history_isolation ? { history_isolation: true } : {}) },
|
|
154
|
-
onCatalog() { if (candidate === m365 && !closed) setImmediate(() => { if (candidate === m365 && !closed) void syncClaudeClients(); }); } });
|
|
159
|
+
onCatalog() { if (candidate === m365 && !closed) setImmediate(() => { if (candidate === m365 && !closed) void syncClaudeClients(); }); } }), sourceAdmission);
|
|
155
160
|
await candidate.refresh();
|
|
156
161
|
if (closed) throw unavailable("m365_runtime_closed");
|
|
157
162
|
if (candidate.models("claude").length) {
|
|
158
163
|
const start = startGateway || (await import("./claude-gateway.mjs")).createClaudeGateway;
|
|
159
164
|
opened = await start({ privacy, compaction, provider: candidate, apiKey: ensureM365GatewayKey(options), port: corePort, env, log, performance: claudePerformance,
|
|
160
|
-
onRequest({ client }) { lastClients[client] = new Date().toISOString(); } });
|
|
165
|
+
onRequest({ client }, req) { lastClients[client] = new Date().toISOString();applicationEvidence?.accept(req, "claude_app", "inference"); } });
|
|
161
166
|
}
|
|
162
167
|
candidate.commitSelection(discovered.binding);
|
|
163
168
|
const previous = m365, previousGateway = gateway;
|