codex-copilot-dx 1.4.11 → 1.4.13
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/bin/cli.mjs +2 -0
- package/docs/ARCHITECTURE.md +6 -0
- package/docs/REFERENCE.md +21 -10
- package/package.json +1 -1
- package/src/access-settings.mjs +4 -1
- package/src/adapter.mjs +14 -5
- package/src/antigravity-chat-bridge.mjs +38 -8
- package/src/antigravity-handler.mjs +141 -26
- package/src/antigravity-models.mjs +3 -2
- package/src/antigravity-runtime.mjs +129 -36
- package/src/antigravity-usage.mjs +3 -3
- package/src/api-target.mjs +12 -1
- package/src/application-configuration.mjs +2 -1
- package/src/application-control.mjs +6 -3
- package/src/cli-command-spec.mjs +1 -1
- package/src/cli-management.mjs +9 -4
- package/src/connection-management.mjs +6 -2
- package/src/connection-policy.mjs +3 -3
- package/src/connection-routing.mjs +37 -10
- package/src/connection-runtime.mjs +4 -0
- package/src/connection-view.mjs +12 -0
- package/src/context-compaction-wire.mjs +6 -6
- package/src/copilot-client.mjs +3 -2
- package/src/copilot.mjs +13 -2
- package/src/dashboard/connections.js +18 -8
- package/src/dashboard/console.js +9 -4
- package/src/dashboard/context.js +15 -5
- package/src/dashboard/features.js +2 -2
- package/src/dashboard/flow.js +1 -0
- package/src/dashboard/gemini.js +40 -10
- package/src/dashboard/index.html +47 -40
- package/src/dashboard/language.js +44 -16
- package/src/dashboard/status.js +35 -30
- package/src/dashboard/tool-activity-machines.js +362 -0
- package/src/dashboard/tool-activity.js +24 -115
- package/src/dashboard/tools.js +3 -4
- package/src/dashboard/ui.css +44 -14
- package/src/dashboard/ui.js +14 -0
- package/src/dashboard/usage.js +9 -1
- package/src/dashboard.mjs +1 -0
- package/src/failure-history.mjs +97 -0
- package/src/model-capabilities.mjs +1 -1
- package/src/privacy-transform.mjs +22 -4
- package/src/provider-metadata.mjs +1 -1
- package/src/providers/api-network.mjs +4 -3
- package/src/providers/api.mjs +79 -15
- package/src/response-failures.mjs +10 -4
- package/src/runtime-config.mjs +1 -0
- package/src/safe-upstream-error.mjs +2 -2
- package/src/source-admission.mjs +1 -1
- package/src/stream-performance.mjs +1 -1
- package/src/terminal-state.mjs +8 -2
- package/src/windows-http-network.mjs +4 -3
- package/src/windows-prediction-network.cs +11 -0
|
@@ -97,11 +97,14 @@ export function createApplicationControl({ providerRuntime, clientIntegration, i
|
|
|
97
97
|
return { status: "opened", app: states[id] };
|
|
98
98
|
}
|
|
99
99
|
async function antigravityPlan(app) {
|
|
100
|
-
const
|
|
101
|
-
|
|
100
|
+
const bridgeEnabled = () => {
|
|
101
|
+
const config = readUserSettings({ env, home, strict: true });
|
|
102
|
+
return config.gemini_antigravity_enabled === true || typeof config.gemini_antigravity_native_source === "string";
|
|
103
|
+
};
|
|
104
|
+
if (!bridgeEnabled()) return { status: "prepared", command: "/usr/bin/open", args: ["-a", app.app] };
|
|
102
105
|
const verified = await inspectGemini({ ...options, app: app.app });
|
|
103
106
|
if (verified.status !== "stopped") return { status: verified.status === "running" ? "app_changed" : verified.status };
|
|
104
|
-
if (
|
|
107
|
+
if (!bridgeEnabled()) return { status: "prepared", command: "/usr/bin/open", args: ["-a", app.app] };
|
|
105
108
|
return planGeminiAppLaunch(verified, { cloudCodeUrl: `http://${host}:${port}/antigravity`, env, home });
|
|
106
109
|
}
|
|
107
110
|
return { snapshot, evidence, check, busy: () => operations > 0,
|
package/src/cli-command-spec.mjs
CHANGED
|
@@ -295,7 +295,7 @@ const extras = {
|
|
|
295
295
|
config:
|
|
296
296
|
"Only service and terminal preferences are in scope. Browser appearance stays in WebUI.\nReset keeps accounts, keys, model plans and chats and stores a pre-reset backup.\nSaved and effective values can differ; restart requirements remain explicit.",
|
|
297
297
|
requests:
|
|
298
|
-
"Only retained records are available. Use requests tools to inspect observed tool metadata without model calls. Unknown clients are not guessed from an API route.\nApp filters: codex, claude-app, claude-code, antigravity.\n--failed filters failed model outcomes and
|
|
298
|
+
"Only retained records are available. Use requests tools to inspect observed tool metadata without model calls. Unknown clients are not guessed from an API route.\nApp filters: codex, claude-app, claude-code, antigravity.\n--failed filters failed model outcomes and request errors. Token-count and access notices stay in the unfiltered list.\nUsage records, HTTP calls and model outcomes are distinct counters.",
|
|
299
299
|
status:
|
|
300
300
|
"Default interactive status is brief; --details retains the complete diagnostic view.\nThe installed package version can differ from the running service.\nA listening gateway does not prove upstream model access.",
|
|
301
301
|
usage:
|
package/src/cli-management.mjs
CHANGED
|
@@ -144,9 +144,9 @@ export async function runManagementCommand(command, options = {}) {
|
|
|
144
144
|
if (ids.request) {
|
|
145
145
|
const found = rows.find(row => row.request_id === ids.request);if (!found) throw new Error("Request not retained. No full-history lookup is available.");return print(found);
|
|
146
146
|
}
|
|
147
|
-
rows = rows.filter(row => (!flags.active || row.active) && (!flags.failed || row.state !== "cancelled" && (row.state === "failed" || row.error))
|
|
147
|
+
rows = rows.filter(row => (!flags.active || row.active) && (!flags.failed || row.state !== "cancelled" && row.failure_category !== "capability" && (row.state === "failed" || row.error))
|
|
148
148
|
&& (!flags.purpose || (row.purpose || "unknown") === flags.purpose) && (!flags.source || row.provider === flags.source) && (!flags.app || (flags.app === "codex" ? ["codex", "codex_app", "codex_cli"].includes(row.application) : row.application === (flags.app === "antigravity" ? "gemini_app" : CLI_CLIENTS[flags.app])))).slice(-(flags.limit || 20));
|
|
149
|
-
return print(flags.format === "json" ? rows : rows.map(row => ({ ...row, state_label: terminalRequestState(row) })), [["request_id", "Request"], ["application", "Client"], ["provider", "Source"], ["model", "Model"], ["
|
|
149
|
+
return print(flags.format === "json" ? rows : rows.map(row => ({ ...row, state_label: terminalRequestState(row) })), [["request_id", "Request"], ["application", "Client"], ["provider", "Source"], ["model", "Model"], ["state_label", "State"], ["upstream_attempts", "Attempts"]]);
|
|
150
150
|
}
|
|
151
151
|
if (group === "usage") {
|
|
152
152
|
if (flags.scope === "run") {
|
|
@@ -286,10 +286,15 @@ export async function runManagementCommand(command, options = {}) {
|
|
|
286
286
|
if (feature || action === "status") {
|
|
287
287
|
const settings = id === "codex" && (flags.details || feature) ? await request({ path: "settings" }) : null;
|
|
288
288
|
const preference = settings?.providers?.[client.source || "github"]?.preference || {};
|
|
289
|
-
const
|
|
289
|
+
const locked = preference.source === "environment";
|
|
290
|
+
const reviewId = (locked ? preference.model : client.auto_review_model || preference.auto_review_model || preference.model) || null;
|
|
290
291
|
const reviewModel = modelPlan?.models.find(model => [model.id, model.public_id, model.route_id].includes(reviewId));
|
|
291
292
|
const details = { predictions: snapshot.client_integrations?.prediction || null, images: settings?.effective?.image_enabled || null,
|
|
292
|
-
auto_review: { model: reviewModel?.id || reviewId, source: reviewModel?.source || client.source,
|
|
293
|
+
auto_review: { model: reviewModel?.id || reviewId, source: reviewModel?.source || client.source,
|
|
294
|
+
...(locked ? { mode: "Startup override" } : preference.followModel ? { mode: "Follow conversation model" } : {}),
|
|
295
|
+
effort: (locked && client.auto_review_model !== reviewModel?.route_id ? undefined : client.auto_review_effort)
|
|
296
|
+
?? (locked ? undefined : preference.auto_review_effort ?? preference.reasoningEffort)
|
|
297
|
+
?? (reviewModel?.capability?.values?.reasoning_efforts?.includes("low") ? "low if omitted" : "Follows client") }, memory_model: client.memory_model || { model: null } };
|
|
293
298
|
if (feature) return print({ client: "Codex", feature, state: details[{ prediction: "predictions", image: "images", review: "auto_review" }[feature]] });
|
|
294
299
|
const observed = retainedRequests(snapshot).filter(row => id === "codex" ? ["codex", "codex_app", "codex_cli"].includes(row.application) : row.application === id).at(-1);
|
|
295
300
|
return print({ id: ids.app, access: client.enabled ? clientSetup(client) === "Paused" ? "Paused" : "Enabled" : "Disabled", setup: view.clients.find(row => row.id === id)?.setup || clientSetup(client),
|
|
@@ -193,14 +193,18 @@ export function createConnectionManagement({ binding, catalogRefresh, save, disc
|
|
|
193
193
|
const c = binding("codex"),
|
|
194
194
|
compiled = plan("codex");
|
|
195
195
|
if (!c.enabled || input.provider !== c.source) throw accessError("ccdx_client_source_mismatch", 409);
|
|
196
|
-
|
|
196
|
+
if (c.source === "github" && String(env.CCDX_AUTO_REVIEW_MODEL || "").trim())
|
|
197
|
+
throw accessError("ccdx_review_environment_override", 409);
|
|
198
|
+
const follow = input.model === "";
|
|
199
|
+
const record = follow ? compiled.routes.get(compiled.defaultModel) : [...compiled.routes.values()].find(
|
|
197
200
|
record => record.source === input.provider && record.upstreamModel === input.model
|
|
198
201
|
);
|
|
199
202
|
if (!record) throw accessError("ccdx_api_model_unavailable");
|
|
200
203
|
if (input.effort && !record.model.capability.values.reasoning_efforts?.includes(input.effort))
|
|
201
204
|
throw accessError("ccdx_api_effort_unavailable");
|
|
202
205
|
const next = editable();
|
|
203
|
-
next.clients.codex.auto_review_model
|
|
206
|
+
if(follow)delete next.clients.codex.auto_review_model;
|
|
207
|
+
else next.clients.codex.auto_review_model = record.model.route_id;
|
|
204
208
|
next.clients.codex.auto_review_effort = input.effort || null;
|
|
205
209
|
save(next);
|
|
206
210
|
return this.snapshot();
|
|
@@ -198,10 +198,10 @@ export function createConnectionPolicy({ validObject, binding, catalogRefresh, s
|
|
|
198
198
|
[...compiled.routes.values()].find(
|
|
199
199
|
record => record.source === old.source && record.upstreamModel === old.auto_review_model
|
|
200
200
|
);
|
|
201
|
-
if (c.
|
|
202
|
-
c.auto_review_model = review
|
|
201
|
+
if (review?.source === c.source)
|
|
202
|
+
c.auto_review_model = review.model.route_id;
|
|
203
203
|
else delete c.auto_review_model;
|
|
204
|
-
if (review?.source === c.source && old.auto_review_effort !== undefined)
|
|
204
|
+
if ((review?.source === c.source || !old.auto_review_model) && old.auto_review_effort !== undefined)
|
|
205
205
|
c.auto_review_effort = old.auto_review_effort;
|
|
206
206
|
else delete c.auto_review_effort;
|
|
207
207
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
1
2
|
import { accessError } from "./access-settings.mjs";
|
|
2
3
|
import { gatewayClient } from "./client-gateway-keys.mjs";
|
|
3
4
|
import { createClaudeGatewayHandler } from "./claude-gateway.mjs";
|
|
@@ -8,6 +9,12 @@ export function createConnectionRouting({ legacy, legacyClaudeAccess, isManaged,
|
|
|
8
9
|
resolveDeployment, codexAccessMode, codexRequiresKey, requireCodexKey, identities, track, guardConversation, messagesTransfer,
|
|
9
10
|
acquireClaudeRequest, privacy, env, log, lastClients, capabilitySupport, applicationEvidence }) {
|
|
10
11
|
const handlers = new Map();
|
|
12
|
+
const reviewSessions = new Map(), reviewSalt = randomBytes(32);
|
|
13
|
+
const reviewSession = (headers, app) => {
|
|
14
|
+
const id = headers.session_id || headers["session-id"] || headers["x-conversation-id"];
|
|
15
|
+
return typeof id === "string" && id.length > 0 && id.length <= 512 && !/[\x00-\x1f\x7f]/.test(id)
|
|
16
|
+
? createHmac("sha256", reviewSalt).update((app || "codex") + "\0" + id).digest("hex") : null;
|
|
17
|
+
};
|
|
11
18
|
function requireSource(clientId, id) {
|
|
12
19
|
if (!permitted(clientId, id)) throw accessError("ccdx_client_source_disabled", 503);
|
|
13
20
|
if (id === "m365" && legacy.snapshot().m365.account_change_in_flight)
|
|
@@ -91,19 +98,39 @@ export function createConnectionRouting({ legacy, legacyClaudeAccess, isManaged,
|
|
|
91
98
|
if (!isManaged()) return null;
|
|
92
99
|
const mode = codexAccessMode();
|
|
93
100
|
if (mode === "paused" || mode === "disabled") throw accessError("ccdx_client_source_disabled", 503);
|
|
94
|
-
|
|
101
|
+
const codex = binding("codex");
|
|
102
|
+
if (!Array.isArray(codex.deployments)) return null;
|
|
95
103
|
if (codexRequiresKey()) requireCodexKey(req);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
104
|
+
const context = currentRequestContext(), review = body.model === "codex-auto-review";
|
|
105
|
+
const override = review && codex.source === "github" ? String(env.CCDX_AUTO_REVIEW_MODEL || "").trim() : "";
|
|
106
|
+
const key = !override && !codex.auto_review_model && (review || context?.purpose === "conversation") ? reviewSession(req.headers, context?.application) : null;
|
|
107
|
+
let requested = body.model;
|
|
108
|
+
if (review) {
|
|
109
|
+
const compiled = plan("codex"), remembered = key && reviewSessions.get(key);
|
|
110
|
+
if (override) {
|
|
111
|
+
const selected = [...compiled.routes.values()].find(record => record.source === "github"
|
|
112
|
+
&& (record.upstreamModel === override || record.model.route_id === override));
|
|
113
|
+
if (!selected) throw accessError("ccdx_api_model_unavailable", 503);
|
|
114
|
+
requested = selected.model.route_id;
|
|
115
|
+
} else {
|
|
116
|
+
const candidate = remembered && Date.now() - remembered.at <= 1800000 && compiled.routes.get(remembered.route);
|
|
117
|
+
const sameProfile = candidate && typeof remembered.profile === "string" && candidate.provider.profileId?.("responses") === remembered.profile;
|
|
118
|
+
requested = codex.auto_review_model || (sameProfile ? remembered.route : compiled.defaultModel);
|
|
119
|
+
}
|
|
101
120
|
delete body.service_tier;
|
|
102
|
-
if (binding("codex").auto_review_effort)
|
|
103
|
-
body.reasoning = { ...body.reasoning, effort: binding("codex").auto_review_effort };
|
|
104
121
|
}
|
|
105
|
-
const record = resolveDeployment("codex", requested)
|
|
106
|
-
|
|
122
|
+
const record = resolveDeployment("codex", requested);
|
|
123
|
+
if (review) {
|
|
124
|
+
const supports = record.model.capability.values.reasoning_efforts || [];
|
|
125
|
+
const configured = !override || codex.auto_review_model === requested ? codex.auto_review_effort : undefined;
|
|
126
|
+
const chosen = configured && supports.includes(configured) ? configured
|
|
127
|
+
: body.reasoning?.effort === undefined && supports.includes("low") ? "low" : undefined;
|
|
128
|
+
if (chosen) body.reasoning = { ...body.reasoning, effort: chosen };
|
|
129
|
+
} else if (key && context) context.noteReviewModel = () => {
|
|
130
|
+
reviewSessions.delete(key);
|
|
131
|
+
reviewSessions.set(key, { route: record.model.route_id, profile: record.provider.profileId?.("responses"), at: Date.now() });
|
|
132
|
+
if (reviewSessions.size > 256) reviewSessions.delete(reviewSessions.keys().next().value);
|
|
133
|
+
};
|
|
107
134
|
if (context) {
|
|
108
135
|
context.finishProvider?.();
|
|
109
136
|
context.finishProvider = track(record.provider);
|
|
@@ -86,6 +86,10 @@ export function createConnectionRuntime({
|
|
|
86
86
|
const catalogRefresh = createApiCatalogRefresh({
|
|
87
87
|
config: id => settings.apis.find(api => api.id === id),
|
|
88
88
|
source: getSource,
|
|
89
|
+
antigravitySources() {
|
|
90
|
+
return settings.apis.filter(api => api.enabled && api.endpoints.gemini && api.models.some(model => model.protocols.includes("gemini")))
|
|
91
|
+
.map(api => ({ id: api.id, name: api.name, models: getSource(api.id)?.models("gemini") || [] }));
|
|
92
|
+
},
|
|
89
93
|
track,
|
|
90
94
|
complete: api => modelDisplay.has(api.id, deploymentRevision(api, env)),
|
|
91
95
|
revision: api => deploymentRevision(api, env),
|
package/src/connection-view.mjs
CHANGED
|
@@ -208,6 +208,17 @@ export function createConnectionView({ legacy, env, binding, plan, getSource, en
|
|
|
208
208
|
snapshot() {
|
|
209
209
|
const result = legacy.snapshot();
|
|
210
210
|
if (!isManaged()) return result;
|
|
211
|
+
const codex = binding("codex");
|
|
212
|
+
let githubPreference;
|
|
213
|
+
if (codex.source === "github" && Array.isArray(codex.deployments) && result.github?.preference?.source !== "environment") {
|
|
214
|
+
const compiled = plan("codex"), reviewId = codex.auto_review_model || compiled.defaultModel;
|
|
215
|
+
const model = compiled.routes.get(reviewId)?.upstreamModel ??
|
|
216
|
+
(reviewId ? codex.deployments.find(item => deploymentModelId(item.source, item.model) === reviewId)?.model : null);
|
|
217
|
+
if (model) githubPreference = {
|
|
218
|
+
model, source: codex.auto_review_model ? "settings" : "default", reasoningEffort: codex.auto_review_effort,
|
|
219
|
+
...(!codex.auto_review_model ? { followModel: true } : {}),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
211
222
|
const performance = legacy.claudePerformance.snapshot(),
|
|
212
223
|
totals = performance.by_route.messages.terminal_outcomes.totals;
|
|
213
224
|
const ms = performance.by_route.messages.by_provider.m365;
|
|
@@ -226,6 +237,7 @@ export function createConnectionView({ legacy, env, binding, plan, getSource, en
|
|
|
226
237
|
: null;
|
|
227
238
|
return {
|
|
228
239
|
...result,
|
|
240
|
+
...(githubPreference ? { github: { ...result.github, preference: githubPreference } } : {}),
|
|
229
241
|
codex_provider: this.selection().codex,
|
|
230
242
|
connections: snapshot(true),
|
|
231
243
|
m365: {
|
|
@@ -22,10 +22,10 @@ export function summaryRequest(body, protocol, text) {
|
|
|
22
22
|
throw fail("The compression interface is unsupported.");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function compactionSummarizer(body, protocol, call) {
|
|
25
|
+
export function compactionSummarizer(body, protocol, call, { requireChatDone = false } = {}) {
|
|
26
26
|
return async (text, options) => {
|
|
27
27
|
const response = await call(summaryRequest(body, protocol, text), { ...options, sourceBodyManaged: true, bodyText: undefined, payloadPrepared: false, currentInputStart: 0, countTokens: false, retryOptions: { ...options.retryOptions, retries: 0 } });
|
|
28
|
-
return readCompactionSummary(response, protocol, { signal: options.signal, onActivity: options.onActivity, onUsage: options.onUsage });
|
|
28
|
+
return readCompactionSummary(response, protocol, { signal: options.signal, onActivity: options.onActivity, onUsage: options.onUsage, requireChatDone });
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -44,7 +44,7 @@ function safeResponse(response, signal) {
|
|
|
44
44
|
return { body, headers: response.headers };
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export async function readCompactionSummary(response, protocol, { signal, onActivity = () => {}, onUsage = () => {} } = {}) {
|
|
47
|
+
export async function readCompactionSummary(response, protocol, { signal, onActivity = () => {}, onUsage = () => {}, requireChatDone = false } = {}) {
|
|
48
48
|
if (!response.ok) {
|
|
49
49
|
try { void cancelSourceResponse(response).catch(() => {}); } catch {}
|
|
50
50
|
throw Object.assign(new Error("The source rejected an internal compression request."), { code: "ccdx_compaction_upstream_error", statusCode: response.status });
|
|
@@ -115,9 +115,9 @@ export async function readCompactionSummary(response, protocol, { signal, onActi
|
|
|
115
115
|
onActivity();const raw = await readBoundedResponseText(incoming, { maxBytes: MAX_WIRE, label: "Compression response", signal });
|
|
116
116
|
let value;try { value = JSON.parse(raw); } catch { throw fail("The compression response is not valid JSON."); }accept(value);
|
|
117
117
|
} else {
|
|
118
|
-
let data = [], frameBytes = 0;
|
|
118
|
+
let data = [], frameBytes = 0, chatDone = false;
|
|
119
119
|
const flush = () => {
|
|
120
|
-
if (!data.length) return;const raw = data.join("\n");data = [];frameBytes = 0;if (raw === "[DONE]") return;
|
|
120
|
+
if (!data.length) return;const raw = data.join("\n");data = [];frameBytes = 0;if (raw === "[DONE]") { chatDone = true;return; }
|
|
121
121
|
let value;try { value = JSON.parse(raw); } catch { throw fail("The compression stream contains invalid JSON."); }accept(value);
|
|
122
122
|
};
|
|
123
123
|
for await (const line of webStreamLines(incoming, { maxBufferBytes: MAX_TEXT, onChunk(chunk) {
|
|
@@ -129,7 +129,7 @@ export async function readCompactionSummary(response, protocol, { signal, onActi
|
|
|
129
129
|
const value = line.slice(5).replace(/^ /, "");frameBytes += Buffer.byteLength(value);if (frameBytes > MAX_TEXT) throw fail("The compression event exceeds its budget.");data.push(value);
|
|
130
130
|
}
|
|
131
131
|
flush();
|
|
132
|
-
if (protocol === "messages" && !messageStopped) complete = false;
|
|
132
|
+
if (protocol === "messages" && !messageStopped || protocol === "chat" && requireChatDone && !chatDone) complete = false;
|
|
133
133
|
}
|
|
134
134
|
if (protocol === "messages" && parts.size) { reset();for (const [, part] of [...parts].sort(([a], [b]) => a - b)) for (const fragment of part.fragments) append(fragment); }
|
|
135
135
|
const text = fragments.join("");
|
package/src/copilot-client.mjs
CHANGED
|
@@ -92,6 +92,7 @@ export function createCopilotClientRuntime({
|
|
|
92
92
|
retryOptions,
|
|
93
93
|
bodyText,
|
|
94
94
|
observeBodyWrite,
|
|
95
|
+
onBodySent,
|
|
95
96
|
onUpstreamStart,
|
|
96
97
|
...sourceOptions
|
|
97
98
|
} = {}) {
|
|
@@ -109,13 +110,13 @@ export function createCopilotClientRuntime({
|
|
|
109
110
|
});
|
|
110
111
|
const bodyBytes = Buffer.byteLength(serializedBody);
|
|
111
112
|
headers["Content-Length"] = String(bodyBytes);
|
|
112
|
-
return sourceTransport({ ...sourceOptions, signal, onUpstreamStart }, { send: fetchCopilotUpstream, model: upstreamReq.model,
|
|
113
|
+
return sourceTransport({ ...sourceOptions, signal, onUpstreamStart }, { send: fetchCopilotUpstream, model: upstreamReq.model, bodyBytes, stream: upstreamReq.stream === true, observe: true,
|
|
113
114
|
evidence: { payload_bytes: bodyBytes }, args: [`${tokenSession.getApiBase()}/chat/completions`, {
|
|
114
115
|
method: "POST",
|
|
115
116
|
headers,
|
|
116
117
|
body: serializedBody,
|
|
117
118
|
signal,
|
|
118
|
-
}, { fetchImpl, ...retryOptions, observeBodyWrite }] });
|
|
119
|
+
}, { fetchImpl, ...retryOptions, observeBodyWrite, onBodySent }] });
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
async function fetchModels({ signal, fetchImpl, retryOptions }) {
|
package/src/copilot.mjs
CHANGED
|
@@ -163,6 +163,7 @@ export async function fetchCopilotUpstream(
|
|
|
163
163
|
retries = UPSTREAM_RETRIES,
|
|
164
164
|
retryDelayMs = UPSTREAM_RETRY_DELAY_MS,
|
|
165
165
|
observeBodyWrite = false,
|
|
166
|
+
onBodySent,
|
|
166
167
|
} = {},
|
|
167
168
|
) {
|
|
168
169
|
const retryCount = parseUpstreamRetries(retries);
|
|
@@ -176,8 +177,18 @@ export async function fetchCopilotUpstream(
|
|
|
176
177
|
const attemptStart = Date.now();
|
|
177
178
|
debugLog(`upstream ${method} ${target} attempt=${attempt + 1}/${retryCount + 1}`);
|
|
178
179
|
try {
|
|
179
|
-
const
|
|
180
|
-
const
|
|
180
|
+
const observedPost = observeBodyWrite && method === "POST" && fetchImpl === fetch;
|
|
181
|
+
const observe = observedPost && observeUpstreamBodyWrite(init.headers?.["X-Request-Id"]);
|
|
182
|
+
const releaseInput = observedPost && retryCount === 0 && typeof onBodySent === "function";
|
|
183
|
+
const report = releaseInput ? (kind, value) => {
|
|
184
|
+
if (observe) observe(kind, value);
|
|
185
|
+
if (kind === "sent" && !signal?.aborted) {
|
|
186
|
+
delete init.body;
|
|
187
|
+
onBodySent();
|
|
188
|
+
}
|
|
189
|
+
} : observe;
|
|
190
|
+
if (releaseInput) init.redirect = "error";
|
|
191
|
+
const resp = await (report ? fetchWithBodyWriteTiming(url, init, report) : fetchImpl(url, init));
|
|
181
192
|
debugLog(`upstream ${method} ${target} status=${resp.status} attempt=${attempt + 1}/${retryCount + 1} attempt_ms=${Date.now() - attemptStart} total_ms=${Date.now() - totalStart}`);
|
|
182
193
|
if (attempt < retryCount && isRetryableUpstreamStatus(resp.status, method)) {
|
|
183
194
|
await discardBoundedResponseBody(resp);
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
toggle.addEventListener("change", () => { toggle.checked = true;disableSource(provider); });const hit = node("label", undefined, "switch-hit");hit.append(toggle);actions.append(hit);
|
|
110
110
|
} else actions.append(button("api_restore", () => void change({ operation: "provider", id: provider.id, enabled: true })));
|
|
111
111
|
if (!provider.builtin && !provider.enabled) {
|
|
112
|
-
const remove = button("api_remove_source", () => { if (
|
|
112
|
+
const remove = button("api_remove_source", async () => { if (await globalThis.ccdxConfirmAction("api_remove_source", "api_remove_source_confirm")) void change({ operation: "remove_api", id: provider.id, impact_revision: data.source_impacts?.[provider.id]?.revision }); });
|
|
113
113
|
remove.disabled = data.clients.some(c => c.source === provider.id || c.deployments?.some(item => item.source === provider.id));actions.append(remove);
|
|
114
114
|
}
|
|
115
115
|
row.dataset.source = provider.id;row.append(info, actions);if (!provider.enabled) disabledSources.append(row);else if (provider.id === selectedProvider) providerList.append(row);
|
|
@@ -210,7 +210,7 @@
|
|
|
210
210
|
cell.append(detail);row.append(cell);modelRow.after(row);
|
|
211
211
|
trigger.setAttribute("aria-expanded", "true");
|
|
212
212
|
const heading = node("div", undefined, "panel-heading");heading.append(node("h3", model.id), button("close", () => { closeModelDetail();trigger.focus(); }));detail.append(heading);
|
|
213
|
-
const protocol = choice(model.protocols.map(id => ({ id, name:
|
|
213
|
+
const protocol = choice(model.protocols.map(id => ({ id, name: { messages: "Messages", responses: "Responses", chat: "Chat", gemini: "Gemini" }[id] || id })), model.protocols.includes("messages") ? "messages" : model.protocols[0], false);
|
|
214
214
|
protocol.setAttribute("aria-label", format("cap_api"));detail.append(protocol);
|
|
215
215
|
const status = node("p", undefined, "hint"), table = node("table"), body = node("tbody");table.append(body);detail.append(status, table);
|
|
216
216
|
const maker = model.display || source(editing)?.model_display?.[model.id] || {};
|
|
@@ -296,8 +296,8 @@
|
|
|
296
296
|
selection.firstChild.addEventListener("change", e => { if (e.target.checked) selectedModels.add(model.id);else selectedModels.delete(model.id); });name.append(selection);
|
|
297
297
|
const maker = model.display || source(editing)?.model_display?.[model.id];
|
|
298
298
|
if (maker?.publisher || maker?.vendor) name.append(node("span", maker.publisher || maker.vendor, "model-maker"));
|
|
299
|
-
for (const protocol of
|
|
300
|
-
const label = check("model-api", protocol, model.protocols.includes(protocol),
|
|
299
|
+
for (const [protocol, title] of Object.entries({ messages: "Messages", responses: "Responses", chat: "Chat", gemini: "Gemini" })) {
|
|
300
|
+
const label = check("model-api", protocol, model.protocols.includes(protocol), title);
|
|
301
301
|
label.firstChild.disabled = !apiForm.querySelector(`[name="protocol"][value="${protocol}"]`).checked;
|
|
302
302
|
label.firstChild.addEventListener("change", e => {
|
|
303
303
|
model.protocols = [...new Set([...model.protocols.filter(api => api !== protocol), ...(e.target.checked ? [protocol] : [])])];
|
|
@@ -313,17 +313,17 @@
|
|
|
313
313
|
apis.append(group);actions.append(details, button("api_remove_model", () => { models = models.filter(item => item !== model);selectedModels.delete(model.id);modelRows(); }));tr.append(name, apis, context, reasoning, search, actions);body.append(tr);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
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; }
|
|
316
|
+
function setEndpoints(base, endpoints) { for (const [api, path] of [["messages", "messages"], ["responses", "responses"], ["chat", "chat/completions"], ["gemini", "models"]]) apiForm.elements[api + "_url"].value = endpoints?.[api] || base.replace(/\/+$/, "") + "/" + path; }
|
|
317
317
|
function editApi(provider) {
|
|
318
318
|
stopDiscovery();editorOrigin = document.activeElement;editing = provider?.id || null;panels("api");apiForm.reset();words(el("connection-editor-title"), provider ? "api_manage" : "api_add");
|
|
319
319
|
apiForm.elements.name.value = provider?.name || "";apiForm.elements.base.value = provider?.base_url || "";
|
|
320
320
|
apiForm.elements.key.required = !provider;globalThis.ccdxLanguage.set(apiForm.elements.key, provider ? "api_key_keep" : "api_key_enter", {}, "placeholder");
|
|
321
321
|
apiForm.elements.auth_header.value = provider?.auth_header || "x-api-key";
|
|
322
322
|
apiForm.elements.key_env.value = provider?.key_env || "";keyMode();
|
|
323
|
-
for (const input of apiForm.querySelectorAll('[name="protocol"]')) input.checked = provider ? Boolean(provider.endpoints?.[input.value]) : input.value
|
|
323
|
+
for (const input of apiForm.querySelectorAll('[name="protocol"]')) input.checked = provider ? Boolean(provider.endpoints?.[input.value]) : ["messages", "responses"].includes(input.value);
|
|
324
324
|
setEndpoints(provider?.base_url || "", provider?.endpoints);
|
|
325
325
|
el("connection-model-detail").hidden = true;
|
|
326
|
-
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();
|
|
326
|
+
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-discover-note").hidden = editing;el("connection-model-id").value = "";apiForm.elements.name.focus();
|
|
327
327
|
words(apiForm.querySelector('button[type="submit"]'), provider ? "api_save" : "api_save_read");
|
|
328
328
|
}
|
|
329
329
|
apiForm.elements.base.addEventListener("change", () => setEndpoints(apiForm.elements.base.value));
|
|
@@ -507,7 +507,17 @@
|
|
|
507
507
|
function editClient(c) { location.hash = c.id === "codex" ? "codex" : "claude";if (c.id !== "codex") claudeClient = c.id;mountClient(true); }
|
|
508
508
|
for (const segment of document.querySelectorAll("[data-claude-client]")) segment.addEventListener("click", () => {
|
|
509
509
|
rememberDraft();claudeClient = segment.dataset.claudeClient;
|
|
510
|
-
for (const button of document.querySelectorAll("[data-claude-client]"))
|
|
510
|
+
for (const button of document.querySelectorAll("[data-claude-client]")) {
|
|
511
|
+
button.setAttribute("aria-selected", String(button === segment));button.tabIndex = button === segment ? 0 : -1;
|
|
512
|
+
}
|
|
513
|
+
el("claude-model-management").setAttribute("aria-labelledby", segment.id);mountClient(true);
|
|
514
|
+
});
|
|
515
|
+
const claudeTabs = [...document.querySelectorAll("[data-claude-client]")];
|
|
516
|
+
for (const [index, tab] of claudeTabs.entries()) tab.addEventListener("keydown", event => {
|
|
517
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
518
|
+
event.preventDefault();
|
|
519
|
+
const next = claudeTabs[event.key === "Home" ? 0 : event.key === "End" ? claudeTabs.length - 1 : 1 - index];
|
|
520
|
+
next.click();next.focus();
|
|
511
521
|
});
|
|
512
522
|
el("connection-auto-sync").addEventListener("change", () => { bindingDirty = true;rememberDraft();el("connection-client-cancel").disabled = false;words(el("connection-draft-state"), "cap_unsaved");words(clientForm.querySelector('button[type="submit"]'), el("connection-auto-sync").checked ? "cap_save_sync" : "api_save"); });
|
|
513
523
|
el("connection-client-cancel").addEventListener("click", () => { drafts.delete(editingClient);bindingDirty = false;mountClient(true); });
|
package/src/dashboard/console.js
CHANGED
|
@@ -95,16 +95,18 @@
|
|
|
95
95
|
const selectedSource = () => providerEntries.find(source => source.id === el("source-provider").value);
|
|
96
96
|
const sourceReady = () => Boolean(selectedSource()) && (!selectedSource().selection.models_required || Boolean(modelsSource === selectedSource().id && el("source-model").value && el("source-review").value));
|
|
97
97
|
const reviewLocked = () => selectedSource()?.id === "github" && settings?.providers?.github?.preference?.source === "environment";
|
|
98
|
+
const reviewCanFollow = () => selectedSource()?.id === "github" && settings?.providers?.codex_provider === "github" &&
|
|
99
|
+
Array.isArray(settings?.providers?.connections?.clients?.find(client => client.id === "codex")?.deployments);
|
|
98
100
|
function syncReviewButton() {
|
|
99
101
|
const sameSource = selectedSource()?.id === settings?.providers?.codex_provider;
|
|
100
|
-
el("save-review").disabled = settingsPending || !sameSource || reviewLocked() || modelsSource !== selectedSource()?.id || !el("source-review").value;
|
|
102
|
+
el("save-review").disabled = settingsPending || !sameSource || reviewLocked() || modelsSource !== selectedSource()?.id || !el("source-review").value && !reviewCanFollow();
|
|
101
103
|
el("source-review").disabled = settingsPending || reviewLocked() || !sourceModels.length;
|
|
102
104
|
el("source-review-effort").disabled = el("source-review").disabled;
|
|
103
105
|
if (reviewLocked()) label(el("review-control-note"), "review_environment_override");
|
|
104
106
|
else if (!sameSource) label(el("review-control-note"), "review_save_source_first");
|
|
105
107
|
}
|
|
106
108
|
function syncEfforts(chosen) {
|
|
107
|
-
const model = sourceModels.find(model => model.id === el("source-review").value);
|
|
109
|
+
const model = sourceModels.find(model => model.id === (el("source-review").value || settings?.providers?.github?.preference?.model));
|
|
108
110
|
const efforts = model?.auto_review_efforts || model?.reasoning_efforts || [];
|
|
109
111
|
const follow = document.createElement("option");follow.value = "";label(follow, "follow_client");
|
|
110
112
|
el("source-review-effort").replaceChildren(follow, ...efforts.map(effort => { const option = document.createElement("option");option.value = effort;option.textContent = effort;return option; }));
|
|
@@ -301,9 +303,12 @@
|
|
|
301
303
|
const preference = settings?.providers?.[source.id]?.preference;
|
|
302
304
|
for (const [id, key] of [["source-model", "model"], ["source-review", "auto_review_model"]]) {
|
|
303
305
|
el(id).replaceChildren(...models.map(model => { const option = document.createElement("option");option.value = model.id;option.textContent = model.id;return option; }));
|
|
304
|
-
const
|
|
305
|
-
const
|
|
306
|
+
const follow = key === "auto_review_model" && reviewCanFollow();
|
|
307
|
+
if (follow) { const option = document.createElement("option");option.value = "";label(option, "review_follow_model");el(id).prepend(option); }
|
|
308
|
+
const saved = key === "auto_review_model" && source.id === "github" ? (follow && preference?.followModel ? "" : preference?.model) : preference?.[key];
|
|
309
|
+
const chosen = unsaved?.[key] ?? saved;
|
|
306
310
|
if (chosen && models.some(model => model.id === chosen)) el(id).value = chosen;
|
|
311
|
+
else if (follow && chosen === "") el(id).value = "";
|
|
307
312
|
}
|
|
308
313
|
modelsSource = source.id;modelsPreference = JSON.stringify(preference);
|
|
309
314
|
const savedEffort = source.id === "github" ? preference?.reasoningEffort : preference?.auto_review_effort === undefined ? "low" : preference.auto_review_effort;
|
package/src/dashboard/context.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
if (!points.some(point => valid(point.input_tokens))) { label(host, "context_no_input");return; }
|
|
21
21
|
if (!entry.identified) { label(host, "context_unassigned");return; }
|
|
22
22
|
const width = host.clientWidth;if (!width) return;
|
|
23
|
-
const height =
|
|
23
|
+
const height = 225, right = 12, top = 40, bottom = 35;
|
|
24
24
|
const measured = Math.max(...points.map(point => valid(point.input_tokens) ? point.input_tokens : 0), 1);
|
|
25
25
|
const maximum = Math.max(measured, latest(entry).context_window_tokens || 0);
|
|
26
26
|
const svg = document.createElementNS(ns, "svg");svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
shape("line", { x1: left, x2: width - right, y1: py, y2: py, class: "context-grid" });
|
|
42
42
|
shape("text", { x: left - 8, y: py + 4, "text-anchor": "end" }, ticks[index]);
|
|
43
43
|
}
|
|
44
|
-
shape("text", { x: left, y: 12 }, "
|
|
44
|
+
shape("text", { x: left, y: 12, class: "context-unit" }, "Token");
|
|
45
45
|
let path = "", continuing = false;
|
|
46
46
|
points.forEach((point, index) => {
|
|
47
47
|
if (!valid(point.input_tokens)) { continuing = false;return; }
|
|
@@ -54,11 +54,21 @@
|
|
|
54
54
|
for (const index of new Set([0, Math.floor((points.length - 1) / 2), points.length - 1])) {
|
|
55
55
|
shape("text", { x: x(index), y: height - 14, "text-anchor": index === 0 ? "start" : "end" }, String(index + 1));
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
const marker = language.format("context_compact_event");
|
|
58
|
+
const measurement = shape("text", { visibility: "hidden" }, marker);
|
|
59
|
+
const markerWidth = measurement.getComputedTextLength();
|
|
60
|
+
measurement.remove();
|
|
61
|
+
let previousEnd = -Infinity;
|
|
62
|
+
for (const compact of [...entry.compactions].sort((a, b) => a.order - b.order)) {
|
|
58
63
|
const index = points.findIndex(point => point.order >= compact.order);
|
|
59
64
|
if (index < 0 || compact.outcome !== "completed") continue;
|
|
60
|
-
const px = x(index)
|
|
61
|
-
|
|
65
|
+
const px = x(index), line = shape("line", { x1: px, x2: px, y1: top, y2: height - bottom, class: "context-compact" });
|
|
66
|
+
const title = document.createElementNS(ns, "title");title.textContent = marker;line.append(title);
|
|
67
|
+
if (width - right - left < markerWidth) continue;
|
|
68
|
+
const center = Math.min(width - right - markerWidth / 2, Math.max(left + markerWidth / 2, px));
|
|
69
|
+
if (center - markerWidth / 2 < previousEnd + 8) continue;
|
|
70
|
+
shape("text", { x: center, y: top - 8, "text-anchor": "middle", class: "context-compact-label" }, marker);
|
|
71
|
+
previousEnd = center + markerWidth / 2;
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
function render() {
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
inflightField.addEventListener("keydown", event => {
|
|
84
84
|
if (event.key === "Enter") { event.preventDefault();void saveInflight(false); }
|
|
85
85
|
});
|
|
86
|
-
el("install-update").addEventListener("click", () => {
|
|
87
|
-
if (
|
|
86
|
+
el("install-update").addEventListener("click", async () => {
|
|
87
|
+
if (await globalThis.ccdxConfirmAction("update_install_now", "update_install_confirm")) void change({ action: "update", confirmed: true }, el("install-update"));
|
|
88
88
|
});
|
|
89
89
|
function render(data, { notes = true } = {}) {
|
|
90
90
|
if (!data) return;
|
package/src/dashboard/flow.js
CHANGED
|
@@ -181,6 +181,7 @@
|
|
|
181
181
|
el("flow-hub").addEventListener("click", () => { selected = null;render(); });
|
|
182
182
|
el("flow-more").addEventListener("click", () => { expanded = !expanded;render(); });
|
|
183
183
|
el("flow-active").addEventListener("toggle", details);
|
|
184
|
+
el("flow-network").parentElement?.addEventListener("scroll", () => { positions = null;draw(); }, { passive: true });
|
|
184
185
|
document.addEventListener("visibilitychange", visibilityChanged);
|
|
185
186
|
globalThis.addEventListener("pagehide", () => { root.dataset.paused = "true"; });
|
|
186
187
|
globalThis.addEventListener("pageshow", visibilityChanged);
|
package/src/dashboard/gemini.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const el=id=>document.getElementById(id),language=globalThis.ccdxLanguage;
|
|
3
|
-
let busy=false,state=null,draft=null,defaultDraft,notice=null,pendingAction=null;
|
|
4
|
-
let sharedApplication=null,sharedPending=false,savedTimer,showSaved=false;
|
|
3
|
+
let busy=false,state=null,draft=null,defaultDraft,timeoutDraft,nativeDraft,notice=null,pendingAction=null;
|
|
4
|
+
let sharedApplication=null,sharedPending=false,savedTimer,showSaved=false,savedModels=false;
|
|
5
5
|
const words=(id,key)=>language.set(el(id),key);
|
|
6
6
|
const clear=id=>{el(id).removeAttribute('data-i18n');el(id).removeAttribute('data-i18n-args');el(id).textContent='';el(id).title=''};
|
|
7
7
|
const controls=['gemini-enabled','gemini-open','gemini-refresh','gemini-save','gemini-cancel','gemini-use-app-default'];
|
|
8
8
|
const selected=()=>state?.models.filter(model=>model.selected!==false).map(model=>model.id)||[];
|
|
9
9
|
const savedDefault=()=>state?.default_model??null;
|
|
10
10
|
const currentDefault=()=>defaultDraft===undefined?savedDefault():defaultDraft;
|
|
11
|
-
const
|
|
11
|
+
const modelsDirty=()=>currentDefault()!==savedDefault()||draft!==null&&JSON.stringify([...draft].sort())!==JSON.stringify(selected().sort());
|
|
12
|
+
const savedTimeout=()=>String(state?.copilot_timeout_seconds??'');
|
|
13
|
+
const timeoutDirty=()=>timeoutDraft!==undefined&&timeoutDraft!==savedTimeout();
|
|
14
|
+
const nativeDirty=()=>nativeDraft!==undefined&&nativeDraft!==(state?.native_source??null);
|
|
15
|
+
const dirty=()=>modelsDirty()||timeoutDirty()||nativeDirty();
|
|
16
|
+
const syncSaveControls=()=>{
|
|
17
|
+
el('gemini-save').disabled=busy||sharedPending||!dirty();
|
|
18
|
+
el('gemini-cancel').disabled=busy||sharedPending||!dirty();
|
|
19
|
+
el('gemini-draft-state').hidden=dirty()||!showSaved||savedModels&&state.app.status==='running'&&(state.models_reload_required===true||sharedApplication?.needs_reload===true);
|
|
20
|
+
if(!el('gemini-draft-state').hidden)words('gemini-draft-state','cap_saved');
|
|
21
|
+
};
|
|
12
22
|
const count=value=>!value?'—':value>=1000000?`${Number((value/1000000).toFixed(2))}M`:value>=1000?`${Number((value/1000).toFixed(1))}K`:String(value);
|
|
13
23
|
const groupedModels=()=>{
|
|
14
24
|
if(Array.isArray(state.model_groups))return state.model_groups;
|
|
@@ -25,10 +35,23 @@
|
|
|
25
35
|
if(!state)return;
|
|
26
36
|
if(sharedApplication&&(sharedApplication.inspection||0)>=(state.application?.inspection||0))state.app={...state.app,status:sharedApplication.status,version:sharedApplication.version||state.app.version};
|
|
27
37
|
if(!busy)el('gemini-enabled').checked=state.enabled;
|
|
28
|
-
el('gemini-
|
|
38
|
+
const timeout=el('gemini-copilot-timeout'),limit=state.copilot_timeout;
|
|
39
|
+
timeout.disabled=busy||sharedPending||!limit||limit.locked;
|
|
40
|
+
el('gemini-timeout-lock').hidden=limit?.locked!==true;
|
|
41
|
+
if(limit){
|
|
42
|
+
const value=limit.locked?String(limit.effective_ms/1000):timeoutDraft??savedTimeout();
|
|
43
|
+
if(timeout.value!==value)timeout.value=value;
|
|
44
|
+
timeout.placeholder=language.format('gemini_timeout_default',{seconds:limit.default_ms/1000});
|
|
45
|
+
}
|
|
46
|
+
const native=el('gemini-native-source'), sources=state.native_sources||[];
|
|
47
|
+
el('gemini-native-source-field').hidden=!sources.length&&!state.native_source;
|
|
48
|
+
native.disabled=busy||sharedPending;
|
|
49
|
+
const options=[{id:'',name:language.format('gemini_native_source_none')},...sources];
|
|
50
|
+
if(state.native_source&&!sources.some(source=>source.id===state.native_source))options.push({id:state.native_source,name:language.format('unknown'),disabled:true});
|
|
51
|
+
native.replaceChildren(...options.map(source=>{const option=document.createElement('option');option.value=source.id;option.textContent=source.name;option.disabled=source.disabled===true;return option}));
|
|
52
|
+
native.value=nativeDraft===undefined?state.native_source??'':nativeDraft??'';
|
|
53
|
+
syncSaveControls();
|
|
29
54
|
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');
|
|
30
|
-
el('gemini-draft-state').hidden=dirty()||!showSaved||state.app.status==='running'&&(state.models_reload_required===true||sharedApplication?.needs_reload===true);
|
|
31
|
-
if(!el('gemini-draft-state').hidden)words('gemini-draft-state','cap_saved');
|
|
32
55
|
el('gemini-use-app-default').hidden=currentDefault()===null;
|
|
33
56
|
el('gemini-default-note').hidden=!state.default_model_unavailable||currentDefault()!==savedDefault();
|
|
34
57
|
if(!el('gemini-default-note').hidden)words('gemini-default-note','gemini_default_unavailable');
|
|
@@ -82,7 +105,7 @@
|
|
|
82
105
|
const write=action&&action!=='summary',response=await fetch('/_ccdx/ui/gemini'+(action==='summary'?'?scope=summary':''),{method:write?'POST':'GET',headers:{'X-CCDX-Dashboard':'1',...(write?{'Content-Type':'application/json'}:{})},cache:'no-store',signal:AbortSignal.timeout(20000),...(write?{body:JSON.stringify({action,...(action==='enable'?{accept_background_copilot:true}:{}),...extra})}:{})});
|
|
83
106
|
const value=await response.json();if(!response.ok)throw Error(value.error||'Antigravity setup failed');
|
|
84
107
|
state=value;if(action==='models'){
|
|
85
|
-
draft=null;defaultDraft=undefined;showSaved=true;clearTimeout(savedTimer);savedTimer=setTimeout(()=>{showSaved=false;render()},2200);
|
|
108
|
+
draft=null;defaultDraft=undefined;timeoutDraft=undefined;nativeDraft=undefined;showSaved=true;savedModels=extra.models!==undefined||extra.native_source!==undefined;clearTimeout(savedTimer);savedTimer=setTimeout(()=>{showSaved=false;render()},2200);
|
|
86
109
|
}
|
|
87
110
|
globalThis.ccdxGeminiStatus=state;
|
|
88
111
|
if(action&&action!=='summary'){
|
|
@@ -91,12 +114,19 @@
|
|
|
91
114
|
}
|
|
92
115
|
return state;
|
|
93
116
|
}catch(error){if(!report)throw error;notice='gemini_operation_failed';words('gemini-note',notice);el('gemini-note').title=error.message}
|
|
94
|
-
finally{busy=false;pendingAction=null;render();window.dispatchEvent(new CustomEvent('ccdx-gemini-state',{detail:{application:state?.application,needsCatalogReload:state?.enabled===true&&state.source_enabled!==false&&state.models_reload_required===true&&state.default_model_unavailable!==true}}))}
|
|
117
|
+
finally{busy=false;pendingAction=null;render();window.dispatchEvent(new CustomEvent('ccdx-gemini-state',{detail:{application:state?.application,needsCatalogReload:(state?.enabled===true&&state.source_enabled!==false||Boolean(state?.native_source))&&state.models_reload_required===true&&state.default_model_unavailable!==true}}))}
|
|
95
118
|
}
|
|
96
119
|
globalThis.ccdxAntigravity={get state(){return state},get pending(){return busy},refreshStatus:()=>load('summary'),setEnabled:enabled=>load(enabled?'enable':'disable',{},false)};
|
|
97
120
|
el('gemini-enabled').addEventListener('change',event=>void load(event.target.checked?'enable':'disable'));
|
|
98
|
-
el('gemini-model-form').addEventListener('submit',event=>{
|
|
99
|
-
|
|
121
|
+
el('gemini-model-form').addEventListener('submit',event=>{
|
|
122
|
+
event.preventDefault();if(!dirty())return;
|
|
123
|
+
void load('models',{...(modelsDirty()?{models:draft||selected(),...(defaultDraft!==undefined?{default_model:defaultDraft}:{})}:{}),
|
|
124
|
+
...(timeoutDirty()?{copilot_timeout_seconds:timeoutDraft===''?null:Number(timeoutDraft)}:{}),
|
|
125
|
+
...(nativeDirty()?{native_source:nativeDraft}:{})});
|
|
126
|
+
});
|
|
127
|
+
el('gemini-copilot-timeout').addEventListener('input',event=>{timeoutDraft=event.target.value;notice=null;clear('gemini-note');syncSaveControls()});
|
|
128
|
+
el('gemini-native-source').addEventListener('change',event=>{nativeDraft=event.target.value||null;notice=null;clear('gemini-note');syncSaveControls()});
|
|
129
|
+
el('gemini-cancel').addEventListener('click',()=>{draft=null;defaultDraft=undefined;timeoutDraft=undefined;nativeDraft=undefined;notice=null;clear('gemini-note');render()});
|
|
100
130
|
el('gemini-use-app-default').addEventListener('click',()=>{defaultDraft=null;render();el('gemini-save').focus();});
|
|
101
131
|
el('gemini-open').addEventListener('click',()=>{if(globalThis.ccdxApplicationControls)globalThis.ccdxApplicationControls.open('antigravity');else void load('open')});
|
|
102
132
|
window.addEventListener('ccdx:application-state',event=>{if(event.detail?.id==='antigravity'){sharedApplication=event.detail.application;sharedPending=event.detail.pending;render()}});
|