codex-copilot-dx 1.2.18 → 1.2.20
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 +3 -3
- package/docs/ARCHITECTURE.md +47 -4
- package/docs/REFERENCE.md +59 -8
- package/package.json +1 -1
- package/src/access-settings.mjs +3 -1
- package/src/api-catalog-refresh.mjs +72 -0
- package/src/api-target.mjs +10 -0
- package/src/client-model-plan.mjs +14 -37
- package/src/clients/claude-models.mjs +20 -0
- package/src/clients/codex-models.mjs +22 -0
- package/src/connection-runtime.mjs +73 -35
- package/src/dashboard/connections.js +103 -40
- package/src/dashboard/console.js +2 -2
- package/src/dashboard/index.html +16 -16
- package/src/dashboard/language.js +16 -3
- package/src/dashboard/status.js +6 -4
- package/src/dashboard/tools.js +1 -1
- package/src/dashboard/ui.css +21 -1
- package/src/model-capabilities.mjs +21 -11
- package/src/provider-metadata.mjs +4 -4
- package/src/providers/api-model-metadata.mjs +36 -0
- package/src/providers/api-network.mjs +3 -2
- package/src/providers/api.mjs +26 -18
- package/src/windows-http-network.mjs +2 -1
- package/src/windows-prediction-network.cs +7 -1
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import { randomBytes } from "node:crypto";
|
|
3
3
|
import { accessSettingsPath, readAccessSettings, updateAccessSettings, checkedApi, checkedAccessSettings, accessError, CLIENT_IDS, CLIENT_NAMES } from "./access-settings.mjs";
|
|
4
4
|
import { createApiSecretStore, checkedApiKey } from "./api-secrets.mjs";
|
|
5
|
+
import { createApiCatalogRefresh } from "./api-catalog-refresh.mjs";
|
|
5
6
|
import { createApiProvider } from "./providers/api.mjs";
|
|
6
7
|
import { readClientGatewayKeys, gatewayClient } from "./client-gateway-keys.mjs";
|
|
7
8
|
import { createClaudeGatewayHandler } from "./claude-gateway.mjs";
|
|
@@ -10,7 +11,8 @@ import { configureCodexApi } from "./codex-api-config.mjs";
|
|
|
10
11
|
import { autoReviewReasoningEfforts } from "./models.mjs";
|
|
11
12
|
import { createRequestAdmission } from "./request-admission.mjs";
|
|
12
13
|
import { createConversationSourceGuard } from "./conversation-source-guard.mjs";
|
|
13
|
-
import { compileClientModels, sourceModels
|
|
14
|
+
import { compileClientModels, sourceModels } from "./client-model-plan.mjs";
|
|
15
|
+
import { codexClientCatalog, codexSourceCatalog } from "./clients/codex-models.mjs";
|
|
14
16
|
import { currentRequestContext } from "./request-context.mjs";
|
|
15
17
|
import { claudeSharedCapabilityPlan, syncClaudeCapabilities, inspectClaudeCapabilitySupport, inspectClaudeCapabilityConfiguration } from "./claude-capability-config.mjs";
|
|
16
18
|
import { deploymentModelId, resolveModelCapabilities, deploymentRevision } from "./model-capabilities.mjs";
|
|
@@ -18,14 +20,18 @@ import { deploymentModelId, resolveModelCapabilities, deploymentRevision } from
|
|
|
18
20
|
const validObject = (value, keys) => value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).every(key => keys.includes(key));
|
|
19
21
|
export function createConnectionRuntime({ legacy, home, env = process.env, platform = process.platform, corePort = 2026,
|
|
20
22
|
secretStore, createApi = createApiProvider, configureClaude = configureClaudeClients, restoreClaude = restoreClaudeClients,
|
|
21
|
-
configureCodex = configureCodexApi, inspectDesktop = inspectClaudeDesktopPolicy, clientAccessChanged, log = () => {} } = {}) {
|
|
23
|
+
configureCodex = configureCodexApi, inspectDesktop = inspectClaudeDesktopPolicy, clientAccessChanged, now = Date.now, log = () => {} } = {}) {
|
|
22
24
|
const options = { home, env, platform }, secrets = secretStore || createApiSecretStore(options);
|
|
23
25
|
const guardConversation = createConversationSourceGuard(options), acquireClaudeRequest = createRequestAdmission({ maxBytes: 16 * 1024 * 1024, maxQueued: 8 });
|
|
24
26
|
let settings = readAccessSettings(options), managed = fs.existsSync(accessSettingsPath(options)), serial = Promise.resolve(), keys, closed = false;
|
|
25
27
|
const instances = new Map(), active = new Map(), retired = new Set(), handlers = new Map(), summaries = new WeakMap(), sourceSecrets = new WeakMap(), setup = {}, lastClients = {};
|
|
26
28
|
const retiredSecrets = new Map(), cleanups = new Set(), plans = new Map(), discoveries = new Map();
|
|
29
|
+
const catalogRefresh = createApiCatalogRefresh({ config: id => settings.apis.find(api => api.id === id), source: getSource, track,
|
|
30
|
+
revision: api => deploymentRevision(api, env), now,
|
|
31
|
+
commit: (...args) => enqueue(() => applyCatalog(...args)),
|
|
32
|
+
onState: (id, state) => state ? discoveries.set(id, state) : discoveries.delete(id) });
|
|
27
33
|
const capabilitySupport = inspectClaudeCapabilitySupport(options);
|
|
28
|
-
let sharedSync = null, syncFlight = null, syncAgain = false;
|
|
34
|
+
let sharedSync = null, syncFlight = null, syncAgain = false;const syncTargets = new Set();
|
|
29
35
|
function cleanSecrets(id) {
|
|
30
36
|
const refs = retiredSecrets.get(id);if (!refs) return;
|
|
31
37
|
for (const ref of refs) {
|
|
@@ -52,10 +58,10 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
52
58
|
function getSource(id) {
|
|
53
59
|
if (!id?.startsWith("api_")) return legacy.source(id);
|
|
54
60
|
const config = settings.apis.find(value => value.id === id);if (!config) return null;
|
|
55
|
-
const previous = instances.get(id);if (previous?.config === config) return previous.source;
|
|
56
|
-
const signature = JSON.stringify(config);
|
|
61
|
+
const previous = instances.get(id), revision = deploymentRevision(config, env);if (previous?.config === config && previous.revision === revision) return previous.source;
|
|
62
|
+
const signature = JSON.stringify(config) + revision;
|
|
57
63
|
if (previous?.signature === signature) return previous.source;
|
|
58
|
-
const source = createApi({ config, secrets, env, platform });instances.set(id, { signature, source, config });sourceSecrets.set(source, config.secret_ref);
|
|
64
|
+
const source = createApi({ config, secrets, env: { ...env }, platform });instances.set(id, { signature, source, config, revision });sourceSecrets.set(source, config.secret_ref);
|
|
59
65
|
if (previous) retire(previous.source);return source;
|
|
60
66
|
}
|
|
61
67
|
function plan(id) {
|
|
@@ -92,10 +98,10 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
92
98
|
plans.clear();
|
|
93
99
|
settings = structuredClone(updateAccessSettings(current => {
|
|
94
100
|
if (JSON.stringify(current) !== JSON.stringify(settings)) throw accessError("ccdx_connections_conflict", 409);return next;
|
|
95
|
-
}, options));managed = true;
|
|
101
|
+
}, options));managed = true;catalogRefresh.invalidate();
|
|
96
102
|
for (const [id, item] of instances) {
|
|
97
103
|
const current = settings.apis.find(api => api.id === id);
|
|
98
|
-
if (!current?.enabled || JSON.stringify(current) !== item.signature) { instances.delete(id);retire(item.source); }else item.config = current;
|
|
104
|
+
if (!current?.enabled || JSON.stringify(current) + deploymentRevision(current, env) !== item.signature) { instances.delete(id);retire(item.source); }else item.config = current;
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
function summary(api) {
|
|
@@ -110,27 +116,34 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
110
116
|
...config.apis.map(api => { const { secret_ref, ...publicApi } = api;return { ...(compact ? { id: api.id, name: api.name, enabled: api.enabled } : publicApi),
|
|
111
117
|
...summary(api), ...(compact ? {} : { deployment_revision: deploymentRevision(api, env) }), discovery: discoveries.get(api.id) || null, builtin: false, key_saved: api.key_env ? Boolean(env[api.key_env]) : Boolean(secret_ref) }; }),
|
|
112
118
|
], clients: CLIENT_IDS.map(id => ({ id, name: CLIENT_NAMES[id], ...config.clients[id], setup: setup[id] || null,
|
|
113
|
-
observed_at: lastClients[id] || null, ...(compact ? {} : { model_plan: { default_model: plan(id).defaultModel,
|
|
119
|
+
observed_at: lastClients[id] || null, ...(compact ? {} : { model_plan: { default_model: plan(id).defaultModel, default_unavailable: plan(id).defaultUnavailable,
|
|
114
120
|
models: plan(id).models.map(model => ({ source: model.source_id, id: model.id, public_id: model.public_id, route_id: model.route_id, capability: model.capability })),
|
|
121
|
+
unavailable: (config.clients[id].deployments || []).filter(item => !plan(id).models.some(model => model.source_id === item.source && model.id === item.model))
|
|
122
|
+
.map(item => ({ source: item.source, id: item.model, route_id: deploymentModelId(item.source, item.model) })),
|
|
115
123
|
available: config.clients[id].allowed.filter(enabled).flatMap(source => sourceModels(getSource(source), id).map(model => ({ source, id: model.id,
|
|
116
124
|
route_id: deploymentModelId(source, model.id), capability: model.capability || resolveModelCapabilities(model, { builtin: true }) }))), sync: sharedSync, support: capabilitySupport } }) })), managed, m365_state: state.m365.state });
|
|
117
125
|
}
|
|
118
|
-
async function syncClients() {
|
|
126
|
+
async function syncClients(ids = CLIENT_IDS) {
|
|
127
|
+
for (const id of ids) syncTargets.add(id);
|
|
119
128
|
syncAgain = true;if (syncFlight) return syncFlight;
|
|
120
|
-
syncFlight = (async () => { do { syncAgain = false;await performClientSync(); } while (syncAgain && !closed); })();
|
|
129
|
+
syncFlight = (async () => { do { syncAgain = false;const targets = new Set(syncTargets);syncTargets.clear();await performClientSync(targets); } while (syncAgain && !closed); })();
|
|
121
130
|
try { return await syncFlight; } finally { syncFlight = null; }
|
|
122
131
|
}
|
|
123
|
-
async function performClientSync() {
|
|
132
|
+
async function performClientSync(targets) {
|
|
124
133
|
if (!managed || closed) return;
|
|
125
134
|
const codex = binding("codex");
|
|
126
|
-
try { if (
|
|
135
|
+
try { if (!targets.has("codex")) { /* Unrelated source metadata does not write Codex settings. */ }
|
|
136
|
+
else if (codex.enabled && plan("codex").defaultUnavailable) setup.codex = "default_unavailable";
|
|
137
|
+
else if (codex.enabled && codex.auto_sync === false) setup.codex = "manual_sync";else setup.codex = configureCodex({ ...options, ...(codex.enabled && (Array.isArray(codex.deployments) || codex.source?.startsWith("api_"))
|
|
127
138
|
? { baseUrl: `http://127.0.0.1:${corePort}/v1`, apiKey: identities().codex, model: plan("codex").defaultModel || codex.model } : { restore: true }) }).state; }
|
|
128
139
|
catch { setup.codex = "configuration_unavailable"; }
|
|
129
|
-
if (!settings.claude_private_keys) return;
|
|
140
|
+
if (!settings.claude_private_keys || !["claude_app", "claude_code"].some(id => targets.has(id))) return;
|
|
130
141
|
let desktopManaged;
|
|
131
142
|
for (const id of ["claude_app", "claude_code"]) {
|
|
143
|
+
if (!targets.has(id)) continue;
|
|
132
144
|
const selected = binding(id), compiled = plan(id), source = selected.source && permitted(id, selected.source) ? getSource(selected.source) : null;
|
|
133
145
|
try {
|
|
146
|
+
if (selected.enabled && compiled.defaultUnavailable) { setup[id] = "default_unavailable";continue; }
|
|
134
147
|
if (!selected.enabled || !compiled.models.length) { const result = restoreClaude({ ...options, client: id });setup[id] = result.preserved ? "preserved" : "not_configured";continue; }
|
|
135
148
|
if (selected.auto_sync === false) { setup[id] = "manual_sync";continue; }
|
|
136
149
|
if (id === "claude_app") desktopManaged ??= await inspectDesktop(options);
|
|
@@ -141,6 +154,9 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
141
154
|
setup[id] = result[id === "claude_app" ? "app" : "code"] || "not_configured";
|
|
142
155
|
} catch { setup[id] = "configuration_unavailable"; }
|
|
143
156
|
}
|
|
157
|
+
if (["claude_app", "claude_code"].some(id => setup[id] === "default_unavailable")) {
|
|
158
|
+
sharedSync = { ...sharedSync, state: "partially_preserved", limitations: [{ code: "default_model_unavailable" }] };return;
|
|
159
|
+
}
|
|
144
160
|
const shared = claudeSharedCapabilityPlan({ app: setup.claude_app === "configured" ? plan("claude_app").models : [],
|
|
145
161
|
code: setup.claude_code === "configured" ? plan("claude_code").models : [], support: capabilitySupport });
|
|
146
162
|
if (["claude_app", "claude_code"].some(id => setup[id] === "manual_sync")) {
|
|
@@ -158,6 +174,19 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
158
174
|
if (!body || typeof body !== "object" || Array.isArray(body)) return;
|
|
159
175
|
if (managed && (binding(client).history_isolation || source?.id.startsWith("api_"))) guardConversation(client, source.profileId(client === "codex" ? "responses" : "messages"), body, headers, identities()[client]);
|
|
160
176
|
}
|
|
177
|
+
async function applyCatalog(id, models, revision, checkedAt, active) {
|
|
178
|
+
if (!active()) throw accessError("ccdx_connections_conflict", 409);
|
|
179
|
+
const next = editable(), current = next.apis.find(api => api.id === id);
|
|
180
|
+
if (!current?.enabled || deploymentRevision(current, env) !== revision) throw accessError("ccdx_connections_conflict", 409);
|
|
181
|
+
const byId = new Map(models.map(model => [model.id, model]));
|
|
182
|
+
for (const model of current.models) if (byId.get(model.id)?.metadata) model.metadata = byId.get(model.id).metadata;
|
|
183
|
+
current.checked_at = checkedAt;
|
|
184
|
+
if (JSON.stringify(current) !== JSON.stringify(settings.apis.find(api => api.id === id))) {
|
|
185
|
+
save(next);await syncClients(CLIENT_IDS.filter(client => binding(client).source === id || binding(client).deployments?.some(model => model.source === id)));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function enqueue(work) { const job = serial.then(work);serial = job.catch(() => {});return job; }
|
|
189
|
+
const refreshApis = () => !closed && managed ? catalogRefresh.refreshAll(settings.apis.filter(api => api.enabled).map(api => api.id)) : Promise.resolve();
|
|
161
190
|
async function change(input) {
|
|
162
191
|
if (closed) throw accessError("ccdx_connections_closed", 503);
|
|
163
192
|
if (!validObject(input, ["operation", "id", "config", "key", "allowed", "source", "enabled", "replacements", "model", "auto_review_model", "auto_review_effort", "deployments", "default_model", "auto_sync"])) throw accessError("ccdx_connections_action_invalid");
|
|
@@ -221,7 +250,7 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
221
250
|
const previous = c.source === "m365" ? legacy.selection().m365 : null;
|
|
222
251
|
c.model = input.model || previous?.model || target.models("gpt")[0].id;c.auto_review_model = input.auto_review_model || previous?.auto_review_model || c.model;
|
|
223
252
|
if (![c.model, c.auto_review_model].every(id => target.models("gpt").some(model => model.id === id))) throw accessError("ccdx_api_model_unavailable");
|
|
224
|
-
const efforts = api ?
|
|
253
|
+
const efforts = api ? sourceModels(target, "codex").find(model => model.id === c.auto_review_model)?.capability.values.reasoning_efforts || []
|
|
225
254
|
: autoReviewReasoningEfforts(target.models("gpt").find(model => model.id === c.auto_review_model));
|
|
226
255
|
if (c.auto_review_effort !== undefined && c.auto_review_effort !== null && !efforts.includes(c.auto_review_effort)) throw accessError("ccdx_api_effort_unavailable");
|
|
227
256
|
}
|
|
@@ -270,17 +299,6 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
270
299
|
const source = await legacy.pauseM365();if (source) retire(source);
|
|
271
300
|
}
|
|
272
301
|
}
|
|
273
|
-
} else if (input.operation === "discover") {
|
|
274
|
-
if (!settings.apis.some(api => api.id === input.id && api.enabled)) throw accessError("ccdx_client_source_disabled", 503);
|
|
275
|
-
try {
|
|
276
|
-
const models = await getSource(input.id).discover({ signal: AbortSignal.timeout(20000) });
|
|
277
|
-
const byId = new Map(models.map(model => [model.id, model]));
|
|
278
|
-
const config = next.apis.find(api => api.id === input.id);
|
|
279
|
-
for (const model of config.models) if (byId.get(model.id)?.metadata) model.metadata = byId.get(model.id).metadata;
|
|
280
|
-
config.checked_at = new Date().toISOString();save(next);
|
|
281
|
-
discoveries.set(input.id, { state: "ready", checked_at: config.checked_at });await syncClients();
|
|
282
|
-
return { ...snapshot(), discovered: models };
|
|
283
|
-
} catch (error) { discoveries.set(input.id, { state: "stale", code: error.code || "ccdx_api_catalog_unavailable", checked_at: new Date().toISOString() });throw error; }
|
|
284
302
|
} else throw accessError("ccdx_connections_action_invalid");
|
|
285
303
|
await syncClients();
|
|
286
304
|
if (input.operation === "client" && input.id === "codex") await clientAccessChanged?.(binding("codex").enabled);
|
|
@@ -292,9 +310,21 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
292
310
|
source: getSource,
|
|
293
311
|
connections: snapshot,
|
|
294
312
|
syncClients,
|
|
295
|
-
manageConnections(input) {
|
|
296
|
-
|
|
297
|
-
|
|
313
|
+
async manageConnections(input) {
|
|
314
|
+
if (!input) return snapshot();
|
|
315
|
+
if (validObject(input, ["operation", "id"]) && input.operation === "discover") {
|
|
316
|
+
const models = await catalogRefresh.refresh(input.id, true);return { ...snapshot(), discovered: models };
|
|
317
|
+
}
|
|
318
|
+
if (validObject(input, ["operation", "id"]) && input.operation === "cancel_discovery") { catalogRefresh.cancel(input.id);return snapshot(); }
|
|
319
|
+
const result = await enqueue(() => change(input));
|
|
320
|
+
if (input.operation === "save_api") {
|
|
321
|
+
const id = input.id || result.providers.find(api => !api.builtin && api.name === input.config.name)?.id;
|
|
322
|
+
if (enabled(id)) void catalogRefresh.refresh(id).catch(() => {});
|
|
323
|
+
} else if (input.operation === "provider" && input.enabled && input.id?.startsWith("api_")) void catalogRefresh.refresh(input.id).catch(() => {});
|
|
324
|
+
return input.operation === "save_api" ? snapshot() : result;
|
|
325
|
+
},
|
|
326
|
+
async start() { const old = legacy.start();if (managed) await syncClients();const result = await old;if (managed) await syncClients();void refreshApis();return result; },
|
|
327
|
+
async refresh() { const result = await Promise.allSettled([!managed || settings.providers.m365 ? legacy.refresh() : Promise.resolve(), refreshApis()]);if (result[0].status === "rejected") throw result[0].reason; },
|
|
298
328
|
selection() { return { ...legacy.selection(), codex: binding("codex").enabled ? binding("codex").source : null }; },
|
|
299
329
|
providerPreference(id) {
|
|
300
330
|
const c = settings.clients.codex;
|
|
@@ -319,15 +349,22 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
319
349
|
current(req) {
|
|
320
350
|
if (!managed) return legacy.current();
|
|
321
351
|
const c = binding("codex"), compiled = plan("codex");
|
|
322
|
-
const source = requireSource("codex", Array.isArray(c.deployments) ? compiled.routes.get(compiled.defaultModel)?.source : c.source);
|
|
323
352
|
if (Array.isArray(c.deployments) && req?.method === "GET") {
|
|
353
|
+
if (!c.enabled) throw accessError("ccdx_client_source_disabled", 503);
|
|
324
354
|
if (codexRequiresKey()) requireCodexKey(req);
|
|
325
|
-
return {
|
|
326
|
-
client: {
|
|
327
|
-
codexCatalog: codexClientCatalog(compiled
|
|
355
|
+
return { id: "connections", registry: { models: { data: compiled.models.map(model => ({ ...model, id: model.public_id })) } },
|
|
356
|
+
client: { listModels: async () => ({ status: 200, body: JSON.stringify({ data: compiled.models.map(model => ({ ...model, id: model.public_id })) }) }) },
|
|
357
|
+
codexCatalog: codexClientCatalog(compiled) };
|
|
328
358
|
}
|
|
359
|
+
if (Array.isArray(c.deployments) && compiled.defaultUnavailable) {
|
|
360
|
+
if (req && codexRequiresKey()) requireCodexKey(req);
|
|
361
|
+
// Admission uses the common handler; resolveCodex must resolve the
|
|
362
|
+
// explicitly requested model before any provider request is opened.
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
const source = requireSource("codex", Array.isArray(c.deployments) ? compiled.routes.get(compiled.defaultModel)?.source : c.source);
|
|
329
366
|
if (source?.id.startsWith("api_") && req) requireCodexKey(req);
|
|
330
|
-
return source;
|
|
367
|
+
return req?.method === "GET" && source?.configuredModels && source.id.startsWith("api_") ? { ...source, codexCatalog: codexSourceCatalog(source) } : source;
|
|
331
368
|
},
|
|
332
369
|
hasModelBindings(client = "codex") { return managed && Array.isArray(binding(client).deployments); },
|
|
333
370
|
resolveCodex(body, req) {
|
|
@@ -349,6 +386,7 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
349
386
|
track,
|
|
350
387
|
validateConversation,
|
|
351
388
|
historyContext(headers, target) {
|
|
389
|
+
if (target.id === "connections") return {};
|
|
352
390
|
if (!target.id.startsWith("api_")) return legacy.historyContext(headers, target);
|
|
353
391
|
// Opaque Responses state never transfers to another API/key/configuration.
|
|
354
392
|
return { historyNamespace: target.profileId() };
|
|
@@ -429,6 +467,6 @@ export function createConnectionRuntime({ legacy, home, env = process.env, platf
|
|
|
429
467
|
if (managed && input.action === "switch") { const next = editable();if (next.clients.codex.source !== input.provider) next.clients.codex.history_isolation = true;next.clients.codex.source = input.provider;next.clients.codex.deployments = null;next.clients.codex.default_model = null;for (const key of ["model", "auto_review_model", "auto_review_effort"]) delete next.clients.codex[key];if (input.provider === "m365") Object.assign(next.clients.codex, legacy.selection().m365);save(next);await syncClients(); }
|
|
430
468
|
return result;
|
|
431
469
|
},
|
|
432
|
-
async close() { closed = true;await serial;await syncFlight;for (const { source } of instances.values()) source.close();for (const source of retired) source.close();active.clear();for (const id of retiredSecrets.keys()) cleanSecrets(id);await Promise.allSettled([...cleanups]);secrets.close();await legacy.close(); },
|
|
470
|
+
async close() { closed = true;await catalogRefresh.close();await serial;await syncFlight;for (const { source } of instances.values()) source.close();for (const source of retired) source.close();active.clear();for (const id of retiredSecrets.keys()) cleanSecrets(id);await Promise.allSettled([...cleanups]);secrets.close();await legacy.close(); },
|
|
433
471
|
};
|
|
434
472
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const words = (node, key, args) => globalThis.ccdxLanguage.set(node, key, args), format = key => globalThis.ccdxLanguage.format(key);
|
|
4
4
|
let data = null, editing = null, editingClient = null, disabling = null, models = [], selectedModels = new Set(), busy = false, generation = 0;
|
|
5
5
|
let claudeClient = "claude_app", bindingSelection = new Set(), bindingDefault = null, bindingDirty = false;
|
|
6
|
+
const drafts = new Map();let editorOrigin = null, discovery = null, desiredSource = null;
|
|
6
7
|
const apiForm = el("connection-api-form"), clientForm = el("connection-client-form");
|
|
7
8
|
const node = (tag, text, className) => { const item = document.createElement(tag);if (text !== undefined) item.textContent = text;if (className) item.className = className;return item; };
|
|
8
9
|
const source = id => data.providers.find(item => item.id === id), client = id => data.clients.find(item => item.id === id);
|
|
@@ -12,13 +13,14 @@
|
|
|
12
13
|
const message = (key, values) => words(el("connection-note"), key, values);
|
|
13
14
|
function button(key, action) { const item = node("button");item.type = "button";words(item, key);item.addEventListener("click", action);return item; }
|
|
14
15
|
function check(name, value, checked, text) { const label = node("label"), input = node("input");input.type = "checkbox";input.name = name;input.value = value;input.checked = checked;label.append(input, node("span", text));return label; }
|
|
15
|
-
async function api(input) {
|
|
16
|
+
async function api(input, signal) {
|
|
16
17
|
const response = await fetch("/_ccdx/ui/connections", { method: input ? "POST" : "GET", headers: { "X-CCDX-Dashboard": "1", ...(input ? { "Content-Type": "application/json" } : {}) },
|
|
17
|
-
cache: "no-store", signal: AbortSignal.timeout(35000), ...(input ? { body: JSON.stringify(input) } : {}) });
|
|
18
|
+
cache: "no-store", signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(35000)]) : AbortSignal.timeout(35000), ...(input ? { body: JSON.stringify(input) } : {}) });
|
|
18
19
|
const result = await response.json();if (!response.ok) throw new Error(result.error || "ccdx_connections_action_failed");
|
|
19
20
|
if (result.source !== "connections" || !Array.isArray(result.providers) || !Array.isArray(result.clients)) throw new Error("ccdx_connections_unavailable");return result;
|
|
20
21
|
}
|
|
21
22
|
function panels(which = "list") {
|
|
23
|
+
if (which !== "api") stopDiscovery();
|
|
22
24
|
root.hidden = which !== "list";
|
|
23
25
|
el("source-account-panel").hidden = el("model-providers").hidden = which !== "list";
|
|
24
26
|
el("connection-editor").hidden = which !== "api";el("connection-disable-editor").hidden = which !== "disable";
|
|
@@ -39,11 +41,11 @@
|
|
|
39
41
|
const allowed = data.clients.filter(c => c.enabled && c.allowed.includes(provider.id)).map(c => c.name).join(" / ");
|
|
40
42
|
const line = node("p", undefined, "hint");words(line, "api_allowed_summary", { clients: allowed || format("api_none") });info.append(line);
|
|
41
43
|
if (provider.discovery?.state === "stale") { const warning = node("p", undefined, "hint");words(warning, "cap_catalog_stale");warning.append(" ", provider.discovery.code);info.append(warning); }
|
|
42
|
-
actions.append(button(
|
|
44
|
+
if (!provider.builtin) actions.append(button("api_manage", () => editApi(provider)));
|
|
43
45
|
const toggle = node("input");toggle.type = "checkbox";toggle.checked = true;toggle.setAttribute("role", "switch");toggle.setAttribute("aria-label", format("api_disable_source") + " " + provider.name);
|
|
44
46
|
toggle.addEventListener("change", () => { toggle.checked = true;disableSource(provider); });actions.append(toggle);
|
|
45
47
|
} else actions.append(button("api_restore", () => void change({ operation: "provider", id: provider.id, enabled: true })));
|
|
46
|
-
row.append(info, actions);(provider.enabled
|
|
48
|
+
row.append(info, actions);if (!provider.enabled) disabledSources.append(row);else if (provider.id === selectedProvider) providerList.append(row);
|
|
47
49
|
}
|
|
48
50
|
const current = editingClient && client(editingClient);
|
|
49
51
|
if (current) {
|
|
@@ -67,11 +69,19 @@
|
|
|
67
69
|
async function load() {
|
|
68
70
|
if (busy) return;const current = ++generation;
|
|
69
71
|
try { const result = await api();if (current !== generation) return;data = result;mountClient();list(); }
|
|
70
|
-
catch (error) { message(error.message); }
|
|
72
|
+
catch (error) { if (!data) message(error.message); }
|
|
71
73
|
}
|
|
72
74
|
async function change(input, done) {
|
|
73
|
-
if (busy) return;busy = true;generation++;
|
|
74
|
-
|
|
75
|
+
if (busy) return;busy = true;generation++;
|
|
76
|
+
const trigger = input.operation === "client" ? clientForm.querySelector('button[type="submit"]') : input.operation === "preview_client" ? el("connection-sync-preview")
|
|
77
|
+
: input.operation === "save_api" ? apiForm.querySelector('button[type="submit"]') : document.activeElement;
|
|
78
|
+
const oldKey = trigger?.dataset.i18n, oldText = trigger?.textContent;
|
|
79
|
+
if (trigger?.tagName === "BUTTON") { trigger.setAttribute("aria-busy", "true");trigger.disabled = true;words(trigger, input.operation === "preview_client" ? "api_reading" : "api_saving"); }
|
|
80
|
+
try { if (input.operation === "save_api") await stopDiscovery();data = await api(input);if (input.operation === "client") { drafts.delete(input.id);if (editingClient === input.id) bindingDirty = false; }mountClient();list();done?.(data);if (!done) {
|
|
81
|
+
if (input.operation === "save_api") {
|
|
82
|
+
desiredSource = input.id || data.providers.find(p => !p.builtin && p.name === input.config.name)?.id;
|
|
83
|
+
stopDiscovery();
|
|
84
|
+
} else if (input.operation === "provider" && input.enabled) desiredSource = input.id;
|
|
75
85
|
panels();let key = input.operation === "save_api" ? "api_config_saved" : input.operation === "provider" ? input.enabled ? "api_provider_enabled" : "api_provider_disabled"
|
|
76
86
|
: !input.enabled ? "api_client_disabled" : !input.source ? "api_client_enabled" : "api_saved";
|
|
77
87
|
const setup = data.clients.find(c => c.id === input.id)?.setup;
|
|
@@ -81,21 +91,33 @@
|
|
|
81
91
|
if (input.operation === "client") words(el("connection-client-note"), key);else message(key);
|
|
82
92
|
}window.dispatchEvent(new CustomEvent("ccdx:connections"));void dashboardRefresh.refresh("auth", { force: true });void dashboardRefresh.refresh("status", { force: true }); }
|
|
83
93
|
catch (error) { if (input.operation === "client") words(el("connection-client-note"), error.message);else message(error.message); }
|
|
84
|
-
finally { busy = false;
|
|
94
|
+
finally { busy = false;if (trigger?.tagName === "BUTTON") { trigger.removeAttribute("aria-busy");trigger.disabled = false;if (oldKey) words(trigger, oldKey);else trigger.textContent = oldText; }
|
|
95
|
+
if (["client", "preview_client"].includes(input.operation)) bindingRows();
|
|
96
|
+
}
|
|
85
97
|
}
|
|
86
|
-
const resolved = model
|
|
87
|
-
|
|
98
|
+
const resolved = (model, protocol = model.protocols.includes("messages") ? "messages" : model.protocols[0]) => {
|
|
99
|
+
const metadata = model.metadata?.deployment === source(editing)?.deployment_revision ? model.metadata : null;
|
|
100
|
+
const values = { ...metadata?.values, ...metadata?.protocols?.[protocol], ...(model.context_window === undefined ? {} : { context_window: model.context_window }),
|
|
101
|
+
...(model.reasoning_efforts === undefined ? {} : { reasoning_efforts: model.reasoning_efforts }), ...(model.capabilities || {}) };
|
|
102
|
+
if (values.reasoning_format && values.reasoning_format !== protocol) for (const key of Object.keys(values).filter(key => key.startsWith("reasoning"))) delete values[key];
|
|
103
|
+
if (values.reasoning === false) delete values.reasoning_efforts;
|
|
104
|
+
return values;
|
|
105
|
+
};
|
|
88
106
|
const count = value => !value ? format("cap_unknown") : value >= 1000000 ? `${Number((value / 1000000).toFixed(2))}M` : value >= 1000 ? `${Number((value / 1000).toFixed(1))}K` : String(value);
|
|
89
107
|
const reasoningText = values => values.reasoning === false ? format("cap_unsupported") : values.reasoning_efforts?.length ? values.reasoning_efforts.join(" / ") : values.reasoning === true ? format("cap_supported") : format("cap_unknown");
|
|
90
108
|
const searchText = values => values.web_search === undefined ? format("cap_unknown") : values.web_search.length ? values.web_search.map(protocol => protocol === "messages" ? "Messages" : protocol === "responses" ? "Responses" : "Chat").join(" / ") : format("cap_unsupported");
|
|
91
109
|
function modelDetail(model) {
|
|
92
110
|
const detail = el("connection-model-detail");detail.hidden = false;detail.replaceChildren();
|
|
93
111
|
const heading = node("div", undefined, "panel-heading");heading.append(node("h3", model.id), button("close", () => { detail.hidden = true; }));detail.append(heading);
|
|
94
|
-
const
|
|
95
|
-
|
|
112
|
+
const protocol = choice(model.protocols.map(id => ({ id, name: id === "messages" ? "Messages" : id === "responses" ? "Responses" : "Chat" })), model.protocols.includes("messages") ? "messages" : model.protocols[0], false);
|
|
113
|
+
protocol.setAttribute("aria-label", format("cap_api"));detail.append(protocol);
|
|
114
|
+
const status = node("p", undefined, "hint"), table = node("table"), body = node("tbody");table.append(body);detail.append(status, table);
|
|
115
|
+
const advanced = node("details"), summary = node("summary");words(summary, "cap_manual");advanced.append(summary);detail.append(advanced);
|
|
116
|
+
const note = node("p", undefined, "hint");words(note, "cap_metadata_scope");advanced.append(note);
|
|
117
|
+
const fields = node("div", undefined, "connection-fields");
|
|
96
118
|
const numeric = ["context_window", "max_input_tokens", "max_output_tokens", "reasoning_budget_min", "reasoning_budget_max"];
|
|
97
119
|
const flags = ["reasoning", "reasoning_required", "reasoning_adaptive", "tools", "parallel_tools", "streaming", "structured_output"];
|
|
98
|
-
const arrays = ["reasoning_efforts", "input_modalities", "web_search"];
|
|
120
|
+
const arrays = ["reasoning_efforts", "thinking_modes", "input_modalities", "web_search"];
|
|
99
121
|
for (const key of [...numeric, ...flags, ...arrays, "reasoning_format"]) {
|
|
100
122
|
const label = node("label"), title = node("span");words(title, "cap_field_" + key);label.append(title);
|
|
101
123
|
let input;
|
|
@@ -107,10 +129,22 @@
|
|
|
107
129
|
input.dataset.capability = key;
|
|
108
130
|
const manual = model.capabilities?.[key] ?? (key === "context_window" ? model.context_window : key === "reasoning_efforts" ? model.reasoning_efforts : undefined);
|
|
109
131
|
input.value = manual === undefined ? "" : Array.isArray(manual) ? manual.length ? manual.join(", ") : "[]" : String(manual);
|
|
110
|
-
|
|
111
|
-
|
|
132
|
+
const evidence = node("span", undefined, "hint");words(evidence, manual !== undefined ? "cap_manual" : "cap_follow_catalog");label.append(input, evidence);fields.append(label);
|
|
133
|
+
}
|
|
134
|
+
function showCapabilities() {
|
|
135
|
+
const values = resolved(model, protocol.value), fresh = model.metadata?.deployment === source(editing)?.deployment_revision;
|
|
136
|
+
words(status, fresh ? "cap_catalog_" + (model.metadata.state || "reported") : "cap_unknown");
|
|
137
|
+
if (fresh && model.metadata.checked_at) status.append(" · ", new Date(model.metadata.checked_at).toLocaleString());
|
|
138
|
+
body.replaceChildren();
|
|
139
|
+
for (const key of ["context_window", "max_input_tokens", "max_output_tokens", "reasoning_efforts", "reasoning_adaptive", "tools", "input_modalities", "web_search"]) {
|
|
140
|
+
const row = node("tr"), label = node("th");words(label, ({ reasoning_efforts: "cap_reasoning", input_modalities: "cap_input_types", web_search: "cap_search" })[key] || "cap_field_" + key);
|
|
141
|
+
const value = values[key], text = key === "reasoning_efforts" ? reasoningText(values) : key === "web_search" ? searchText(values)
|
|
142
|
+
: value === undefined ? format("cap_unknown") : typeof value === "boolean" ? format(value ? "cap_supported" : "cap_unsupported") : Array.isArray(value) ? value.join(" / ") || format("cap_unsupported") : count(value);
|
|
143
|
+
row.append(label, node("td", text));body.append(row);
|
|
144
|
+
}
|
|
145
|
+
for (const input of fields.querySelectorAll("input[data-capability]")) { const value = values[input.dataset.capability];input.placeholder = value === undefined ? format("cap_unknown") : Array.isArray(value) ? value.join(", ") : String(value); }
|
|
112
146
|
}
|
|
113
|
-
|
|
147
|
+
protocol.addEventListener("change", showCapabilities);showCapabilities();advanced.append(fields);
|
|
114
148
|
const save = button("cap_apply_details", () => {
|
|
115
149
|
const override = {};
|
|
116
150
|
for (const input of fields.querySelectorAll("[data-capability]")) {
|
|
@@ -118,7 +152,7 @@
|
|
|
118
152
|
override[key] = numeric.includes(key) ? Number(text) : flags.includes(key) ? text === "true" : arrays.includes(key) ? text === "[]" ? [] : text.split(/[,,]\s*/).filter(Boolean) : text;
|
|
119
153
|
}
|
|
120
154
|
model.capabilities = override;delete model.context_window;delete model.reasoning_efforts;modelRows();detail.hidden = true;message("cap_details_draft");
|
|
121
|
-
});
|
|
155
|
+
});advanced.append(save);detail.scrollIntoView({ block: "nearest", behavior: "auto" });
|
|
122
156
|
}
|
|
123
157
|
function syncPreview(preview) {
|
|
124
158
|
const c = client(editingClient), result = el("connection-sync-result");result.hidden = false;result.replaceChildren();
|
|
@@ -158,7 +192,7 @@
|
|
|
158
192
|
}
|
|
159
193
|
function setEndpoints(base, endpoints) { for (const [api, path] of [["messages", "messages"], ["responses", "responses"], ["chat", "chat/completions"]]) apiForm.elements[api + "_url"].value = endpoints?.[api] || base.replace(/\/+$/, "") + "/" + path; }
|
|
160
194
|
function editApi(provider) {
|
|
161
|
-
editing = provider?.id || null;panels("api");apiForm.reset();words(el("connection-editor-title"), provider ? "api_manage" : "api_add");
|
|
195
|
+
stopDiscovery();editorOrigin = document.activeElement;editing = provider?.id || null;panels("api");apiForm.reset();words(el("connection-editor-title"), provider ? "api_manage" : "api_add");
|
|
162
196
|
apiForm.elements.name.value = provider?.name || "";apiForm.elements.base.value = provider?.base_url || "";
|
|
163
197
|
apiForm.elements.key.required = !provider;globalThis.ccdxLanguage.set(apiForm.elements.key, provider ? "api_key_keep" : "api_key_enter", {}, "placeholder");
|
|
164
198
|
apiForm.elements.auth_header.value = provider?.auth_header || "x-api-key";
|
|
@@ -167,7 +201,7 @@
|
|
|
167
201
|
setEndpoints(provider?.base_url || "", provider?.endpoints);
|
|
168
202
|
const allowed = el("connection-allowed-clients");allowed.replaceChildren(...data.clients.filter(c => c.enabled).map(c => check("allowed", c.id, c.allowed.includes(editing), c.name)));
|
|
169
203
|
el("connection-model-detail").hidden = true;
|
|
170
|
-
models = structuredClone(provider?.models || []);selectedModels = new Set(models.map(model => model.id));modelRows();el("connection-manual-model").open = false;el("connection-discover").disabled = !editing;el("connection-model-id").value = "";
|
|
204
|
+
models = structuredClone(provider?.models || []);selectedModels = new Set(models.map(model => model.id));modelRows();el("connection-manual-model").open = false;el("connection-discover").disabled = !editing;el("connection-model-id").value = "";apiForm.elements.name.focus();
|
|
171
205
|
}
|
|
172
206
|
apiForm.elements.base.addEventListener("change", () => setEndpoints(apiForm.elements.base.value));
|
|
173
207
|
for (const input of apiForm.querySelectorAll('[name="protocol"]')) input.addEventListener("change", () => {
|
|
@@ -195,56 +229,83 @@
|
|
|
195
229
|
const id = el("connection-model-id").value.trim();if (!id || models.some(model => model.id === id) || models.length >= 500) return;
|
|
196
230
|
models.push({ id, protocols: [] });selectedModels.add(id);el("connection-model-id").value = "";modelRows();
|
|
197
231
|
});
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
232
|
+
function stopDiscovery() {
|
|
233
|
+
const previous = discovery;if (!previous) return;discovery = null;previous.controller.abort();
|
|
234
|
+
const cancelled = api({ operation: "cancel_discovery", id: previous.id }).catch(() => {});
|
|
235
|
+
el("connection-discover").disabled = !editing;el("connection-discover").removeAttribute("aria-busy");words(el("connection-discover"), "api_read_models");el("connection-discover-cancel").hidden = true;return cancelled;
|
|
236
|
+
}
|
|
237
|
+
el("connection-discover-cancel").addEventListener("click", () => { stopDiscovery();message("api_read_cancelled");el("connection-discover").focus(); });
|
|
238
|
+
el("connection-discover").addEventListener("click", async () => {
|
|
239
|
+
if (discovery || !editing) return;
|
|
240
|
+
const read = { id: editing, controller: new AbortController() };discovery = read;
|
|
241
|
+
const trigger = el("connection-discover");trigger.disabled = true;trigger.setAttribute("aria-busy", "true");words(trigger, "api_reading");el("connection-discover-cancel").hidden = false;
|
|
242
|
+
try {
|
|
243
|
+
const result = await api({ operation: "discover", id: read.id }, read.controller.signal);if (discovery !== read || editing !== read.id) return;
|
|
244
|
+
data = result;
|
|
245
|
+
const known = new Map(models.map(model => [model.id, model]));for (const model of result.discovered || []) { const previous = known.get(model.id);known.set(model.id, previous ? { ...previous, ...(model.metadata ? { metadata: model.metadata } : {}) } : model); }
|
|
246
|
+
models = [...known.values()].slice(0, 500);modelRows();message("api_models_read");
|
|
247
|
+
} catch (error) { if (discovery === read) message(error.message); }
|
|
248
|
+
finally { if (discovery === read) { discovery = null;trigger.disabled = false;trigger.removeAttribute("aria-busy");words(trigger, "api_read_models");el("connection-discover-cancel").hidden = true; } }
|
|
249
|
+
});
|
|
202
250
|
const bindingKey = (source, model) => source + "\0" + model;
|
|
203
251
|
const routeId = item => item.route_id || item.public_id;
|
|
252
|
+
function rememberDraft() {
|
|
253
|
+
if (editingClient && bindingDirty) drafts.set(editingClient, { selection: new Set(bindingSelection), defaultModel: bindingDefault, autoSync: el("connection-auto-sync").checked });
|
|
254
|
+
}
|
|
204
255
|
function mountClient(force = false) {
|
|
205
256
|
if (!data) return;
|
|
206
257
|
const route = location.hash.slice(1), id = route === "claude" ? claudeClient : "codex";
|
|
207
|
-
const mount = el(route === "claude" ? "claude-model-management" : "codex-model-management");
|
|
208
258
|
if (!["codex", "claude"].includes(route)) return;
|
|
259
|
+
rememberDraft();
|
|
260
|
+
const mount = el(route === "claude" ? "claude-model-management" : "codex-model-management");
|
|
209
261
|
mount.append(el("connection-clients"), el("connection-client-editor"));
|
|
210
262
|
const c = client(id);el("connection-client-editor").hidden = !c.enabled;
|
|
211
263
|
if (editingClient !== id || force || !bindingDirty) {
|
|
212
|
-
editingClient = id;bindingDirty =
|
|
264
|
+
editingClient = id;const draft = drafts.get(id);bindingDirty = Boolean(draft);
|
|
213
265
|
const selected = Array.isArray(c.deployments) ? c.deployments : (c.model_plan?.models || []).map(model => ({ source: model.source, model: model.id }));
|
|
214
|
-
bindingSelection = new Set(selected.map(item => bindingKey(item.source, item.model)));
|
|
215
|
-
bindingDefault = c.default_model || c.model_plan?.models.find(model => model.public_id === c.model_plan?.default_model)?.route_id || null;
|
|
216
|
-
el("connection-auto-sync").checked = c.auto_sync !== false;
|
|
266
|
+
bindingSelection = draft ? new Set(draft.selection) : new Set(selected.map(item => bindingKey(item.source, item.model)));
|
|
267
|
+
bindingDefault = draft ? draft.defaultModel : c.default_model || c.model_plan?.models.find(model => model.public_id === c.model_plan?.default_model)?.route_id || null;
|
|
268
|
+
el("connection-auto-sync").checked = draft ? draft.autoSync : c.auto_sync !== false;
|
|
217
269
|
el("connection-sync-result").hidden = true;el("connection-client-note").textContent = "";
|
|
218
270
|
}
|
|
219
|
-
words(el("connection-client-title"), "cap_visible_model");list();
|
|
271
|
+
bindingRows(document.activeElement?.name === "binding-model" ? { kind: "selection", key: document.activeElement.value } : document.activeElement?.dataset.binding ? { kind: "default", key: document.activeElement.dataset.binding } : null);words(el("connection-client-title"), "cap_visible_model");list();
|
|
220
272
|
}
|
|
221
|
-
function bindingRows() {
|
|
273
|
+
function bindingRows(focus) {
|
|
222
274
|
el("connection-client-cancel").disabled = !bindingDirty;
|
|
223
275
|
const body = el("connection-bindings"), c = client(editingClient);body.replaceChildren();
|
|
224
276
|
const available = c.model_plan?.available || [], availableKeys = new Set(available.map(item => bindingKey(item.source, item.id)));
|
|
225
|
-
const missing = [...bindingSelection].filter(key => !availableKeys.has(key)).map(key => { const [source, id] = key.split("\0");return { source, id, unavailable: true }; });
|
|
277
|
+
const missing = [...bindingSelection].filter(key => !availableKeys.has(key)).map(key => { const [source, id] = key.split("\0");return { source, id, route_id: c.model_plan?.unavailable?.find(item => item.source === source && item.id === id)?.route_id, unavailable: true }; });
|
|
226
278
|
for (const item of [...available, ...missing]) {
|
|
227
279
|
const key = bindingKey(item.source, item.id), row = node("tr"), name = node("td"), capability = item.capability?.values || {};
|
|
228
280
|
const selection = check("binding-model", key, bindingSelection.has(key), item.id);
|
|
229
281
|
selection.firstChild.addEventListener("change", event => {
|
|
230
282
|
bindingDirty = true;if (event.target.checked) { bindingSelection.add(key);bindingDefault ||= routeId(item); }
|
|
231
|
-
else { bindingSelection.delete(key);if (bindingDefault === routeId(item) || !
|
|
232
|
-
bindingRows();
|
|
283
|
+
else { bindingSelection.delete(key);if (bindingDefault === routeId(item) || !bindingSelection.size) bindingDefault = null; }
|
|
284
|
+
rememberDraft();bindingRows({ kind: "selection", key });
|
|
233
285
|
});name.append(selection);
|
|
234
|
-
const action = button(bindingDefault === routeId(item) && bindingSelection.has(key) ? "cap_default" : "cap_set_default", () => { bindingDirty = true;bindingSelection.add(key);bindingDefault = routeId(item);bindingRows(); });
|
|
286
|
+
const action = button(bindingDefault === routeId(item) && bindingSelection.has(key) ? "cap_default" : "cap_set_default", () => { bindingDirty = true;bindingSelection.add(key);bindingDefault = routeId(item);rememberDraft();bindingRows({ kind: "default", key }); });
|
|
235
287
|
action.setAttribute("aria-pressed", String(bindingDefault === routeId(item) && bindingSelection.has(key)));
|
|
236
|
-
|
|
237
|
-
|
|
288
|
+
action.dataset.binding = key;action.disabled = Boolean(item.unavailable);action.setAttribute("aria-label", item.id + " · " + format(bindingDefault === routeId(item) ? "cap_default" : "cap_set_default"));
|
|
289
|
+
if (item.unavailable) { const warning = node("span", undefined, "hint binding-unavailable");words(warning, "cap_model_unavailable");name.append(warning); }
|
|
290
|
+
const cell = node("td");cell.append(action);
|
|
291
|
+
const details = [node("td", source(item.source)?.name || item.source), node("td", count(capability.context_window)), node("td", reasoningText(capability))];
|
|
292
|
+
details.forEach((cell, i) => cell.dataset.label = format(["source", "cap_context", "cap_reasoning"][i]));
|
|
293
|
+
row.append(name, ...details, cell);body.append(row);
|
|
238
294
|
}
|
|
295
|
+
const unavailableDefault = bindingSelection.size > 0 && !available.some(item => routeId(item) === bindingDefault && bindingSelection.has(bindingKey(item.source, item.id)));
|
|
296
|
+
const warning = el("connection-default-note");warning.hidden = !unavailableDefault;words(warning, "cap_default_unavailable");
|
|
297
|
+
clientForm.querySelector('button[type="submit"]').disabled = unavailableDefault || busy;
|
|
298
|
+
words(el("connection-draft-state"), bindingDirty ? "cap_unsaved" : "cap_saved");
|
|
299
|
+
if (focus) { const selector = focus.kind === "selection" ? 'input[name="binding-model"]' : 'button[data-binding]';[...body.querySelectorAll(selector)].find(input => (input.value || input.dataset.binding) === focus.key)?.focus(); }
|
|
239
300
|
if (!body.children.length) { const row = node("tr"), cell = node("td");cell.colSpan = 5;words(cell, "cap_no_models");const link = node("a");link.href = "#models";words(link, "model_services");cell.append(" ", link);row.append(cell);body.append(row); }
|
|
240
301
|
}
|
|
241
302
|
function editClient(c) { location.hash = c.id === "codex" ? "codex" : "claude";if (c.id !== "codex") claudeClient = c.id;mountClient(true); }
|
|
242
303
|
for (const segment of document.querySelectorAll("[data-claude-client]")) segment.addEventListener("click", () => {
|
|
243
|
-
claudeClient = segment.dataset.claudeClient;
|
|
304
|
+
rememberDraft();claudeClient = segment.dataset.claudeClient;
|
|
244
305
|
for (const button of document.querySelectorAll("[data-claude-client]")) button.setAttribute("aria-pressed", String(button === segment));mountClient(true);
|
|
245
306
|
});
|
|
246
|
-
el("connection-auto-sync").addEventListener("change", () => { bindingDirty = true;el("connection-client-cancel").disabled = false; });
|
|
247
|
-
el("connection-client-cancel").addEventListener("click", () => mountClient(true));
|
|
307
|
+
el("connection-auto-sync").addEventListener("change", () => { bindingDirty = true;rememberDraft();el("connection-client-cancel").disabled = false;words(el("connection-draft-state"), "cap_unsaved"); });
|
|
308
|
+
el("connection-client-cancel").addEventListener("click", () => { drafts.delete(editingClient);bindingDirty = false;mountClient(true); });
|
|
248
309
|
function bindingInput(operation) {
|
|
249
310
|
const c = client(editingClient);return { operation, id: c.id, enabled: true, allowed: c.allowed,
|
|
250
311
|
deployments: [...bindingSelection].map(key => { const [source, model] = key.split("\0");return { source, model }; }),
|
|
@@ -261,9 +322,11 @@
|
|
|
261
322
|
el("connection-disable-form").addEventListener("submit", e => { e.preventDefault();void change({ operation: "provider", id: disabling, enabled: false,
|
|
262
323
|
replacements: Object.fromEntries([...el("connection-replacements").querySelectorAll("select")].map(select => [select.name, select.value || null])) }); });
|
|
263
324
|
el("connection-add").addEventListener("click", () => { if (data) editApi(); });
|
|
264
|
-
for (const id of ["connection-cancel", "connection-disable-cancel"]) el(id).addEventListener("click", () => panels());
|
|
325
|
+
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(); });
|
|
265
326
|
window.addEventListener("hashchange", () => { apiForm.elements.key.value = "";mountClient();if (["#models", "#claude", "#codex"].includes(location.hash)) void load(); });
|
|
266
327
|
window.addEventListener("ccdx:choose-source", event => { if (typeof event.detail?.id === "string" && providerEntries.some(p => p.id === event.detail.id)) chooseProvider(event.detail.id); });
|
|
328
|
+
window.addEventListener("ccdx:source-view", () => { if (data) list(); });
|
|
329
|
+
window.addEventListener("ccdx:providers", () => { if (desiredSource && providerEntries.some(p => p.id === desiredSource)) { const id = desiredSource;desiredSource = null;chooseProvider(id); }if (data) list(); });
|
|
267
330
|
new MutationObserver(() => { if (data) list(); }).observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
|
|
268
331
|
globalThis.ccdxConnections = { load, editClient: id => { if (data && client(id)) { editClient(client(id)); } } };
|
|
269
332
|
for (const button of document.querySelectorAll("[data-client-access]")) button.addEventListener("click", () => globalThis.ccdxConnections.editClient(button.dataset.clientAccess));
|
package/src/dashboard/console.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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", models: "model_services", usage: "usage_and_diagnostics", requests: "request_records", checks: "tools_checks_title", system: "system_and_settings" };
|
|
5
|
-
const settingsViews = ["codex", "models", "system", "checks"];
|
|
5
|
+
const settingsViews = ["codex", "claude", "models", "system", "checks"];
|
|
6
6
|
let current = "overview", settings = null, settingsPending = false, 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;
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
settingsPending = true;
|
|
167
167
|
el("terminal-color-theme").disabled = true;
|
|
168
168
|
syncAccountControls();
|
|
169
|
-
try { applySettings(await api());settingsReadAt = time(Date.now()); }
|
|
169
|
+
try { applySettings(await api());settingsReadAt = time(Date.now());void globalThis.ccdxConnections?.load(); }
|
|
170
170
|
catch (error) {
|
|
171
171
|
for (const id of ["settings-note", ...(settingsViews.includes(current) ? ["page-settings-note"] : [])]) {
|
|
172
172
|
label(el(id), settingsReadAt ? "showing_previous_data_updated_time" : "could_not_read_settings", { time: settingsReadAt });
|