codex-copilot-dx 1.4.12 → 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/docs/ARCHITECTURE.md +6 -0
- package/docs/REFERENCE.md +12 -11
- package/package.json +1 -1
- package/src/access-settings.mjs +1 -0
- package/src/antigravity-chat-bridge.mjs +38 -8
- package/src/antigravity-handler.mjs +49 -29
- package/src/antigravity-runtime.mjs +79 -29
- package/src/cli-command-spec.mjs +1 -1
- package/src/cli-management.mjs +8 -6
- package/src/connection-management.mjs +2 -0
- package/src/connection-routing.mjs +14 -5
- package/src/context-compaction-wire.mjs +6 -6
- package/src/dashboard/connections.js +13 -3
- package/src/dashboard/features.js +2 -2
- package/src/dashboard/index.html +41 -37
- package/src/dashboard/language.js +32 -17
- package/src/dashboard/status.js +20 -28
- 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 +24 -3
- package/src/dashboard/ui.js +14 -0
- package/src/dashboard/usage.js +9 -1
- package/src/dashboard.mjs +1 -0
- package/src/response-failures.mjs +7 -3
- package/src/safe-upstream-error.mjs +2 -2
- package/src/stream-performance.mjs +1 -1
- package/src/terminal-state.mjs +8 -2
|
@@ -9,20 +9,23 @@ import {createAntigravityImages} from "./antigravity-images.mjs";
|
|
|
9
9
|
import {createCopilotWeb} from "./copilot-web.mjs";
|
|
10
10
|
import {inspectGeminiApp,planGeminiAppLaunch} from "./gemini-app.mjs";
|
|
11
11
|
import {readUserSettings,userSettingsPath} from "./user-settings.mjs";
|
|
12
|
-
import {readAccessSettings} from "./access-settings.mjs";
|
|
12
|
+
import {accessSettingsPath,readAccessSettings} from "./access-settings.mjs";
|
|
13
13
|
import {readClientGatewayKeys} from "./client-gateway-keys.mjs";
|
|
14
14
|
import {createConversationSourceGuard} from "./conversation-source-guard.mjs";
|
|
15
15
|
import {readSavedGithubToken} from "./auth-credentials.mjs";
|
|
16
16
|
import {githubTokenFingerprint} from "./github-identity.mjs";
|
|
17
|
-
import {atomicWriteFileIfChangedSync} from "./atomic-file.mjs";
|
|
18
|
-
import {withFileLockSync} from "./lock.mjs";
|
|
17
|
+
import {atomicWriteFile,atomicWriteFileIfChangedSync} from "./atomic-file.mjs";
|
|
18
|
+
import {withFileLock,withFileLockSync} from "./lock.mjs";
|
|
19
|
+
import {readBoundedFile} from "./bounded-file.mjs";
|
|
20
|
+
import {redactDiagnosticText} from "./diagnostic-text.mjs";
|
|
19
21
|
import {httpError} from "./http-errors.mjs";
|
|
20
|
-
import {antigravityCopilotModels,ANTIGRAVITY_NATIVE_PREFIX} from "./antigravity-models.mjs";
|
|
22
|
+
import {antigravityCopilotModels,ANTIGRAVITY_MODEL_PREFIX,ANTIGRAVITY_NATIVE_PREFIX} from "./antigravity-models.mjs";
|
|
21
23
|
|
|
22
24
|
const execute=promisify(execFile),key="gemini_antigravity_enabled",modelKey="gemini_antigravity_models",defaultKey="gemini_antigravity_default_model";
|
|
23
25
|
const timeoutKey="gemini_antigravity_copilot_timeout_seconds";
|
|
24
26
|
const nativeSourceKey="gemini_antigravity_native_source";
|
|
25
27
|
const validTimeout=value=>Number.isSafeInteger(value)&&value>=1&&value<=600;
|
|
28
|
+
const validModel=id=>typeof id==="string"&&/^[\w][\w./:@+-]{0,159}$/.test(id)&&redactDiagnosticText(id)===id;
|
|
26
29
|
const validAlias=id=>typeof id==="string"&&/^ccdx-copilot-[a-z0-9._-]{1,140}$/.test(id);
|
|
27
30
|
|
|
28
31
|
export function createAntigravityRuntime({client,models=()=>[],refreshModels,privacy,home=os.homedir(),env=process.env,inspect=inspectGeminiApp,
|
|
@@ -30,7 +33,17 @@ export function createAntigravityRuntime({client,models=()=>[],refreshModels,pri
|
|
|
30
33
|
upstreamTimeoutMs=180000,copilotTimeoutMs,nativeSources=()=>[],getSource=()=>null,...timeouts}={}) {
|
|
31
34
|
const options={home,env},guard=createConversationSourceGuard(options);
|
|
32
35
|
const web=searchFn?null:createCopilotWeb({client,readToken});
|
|
33
|
-
let app={status:"unknown"},route=null,lastOperation=null,compactionSalt;
|
|
36
|
+
let app={status:"unknown"},route=null,lastOperation=null,compactionSalt,conversationRoutes;
|
|
37
|
+
const routeFile=path.join(path.dirname(accessSettingsPath(options)),"antigravity-conversations.json");
|
|
38
|
+
const readRoutes=async()=>{
|
|
39
|
+
let value;
|
|
40
|
+
try{value=JSON.parse(await readBoundedFile(routeFile,{encoding:"utf8",maxBytes:128*1024}));}
|
|
41
|
+
catch(error){if(error.code==="ENOENT")return {};throw httpError("Antigravity conversation routing data could not be read",409);}
|
|
42
|
+
if(!value||typeof value!=="object"||Array.isArray(value)||Object.keys(value).length>256||
|
|
43
|
+
Object.entries(value).some(([id,item])=>!/^[a-f0-9]{64}$/.test(id)||!item||
|
|
44
|
+
!/^[a-f0-9]{64}$/.test(item.owner)||!validModel(item.model)))throw httpError("Invalid Antigravity conversation routing data",409);
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
34
47
|
const conversationKey=body=>{
|
|
35
48
|
const id=body?.request?.labels?.root_cascade_id||body?.request?.labels?.cascade_id;
|
|
36
49
|
if(typeof id!=="string"||!id||id.length>160||/[\u0000-\u001f\u007f]/.test(id))return null;
|
|
@@ -46,7 +59,7 @@ export function createAntigravityRuntime({client,models=()=>[],refreshModels,pri
|
|
|
46
59
|
copilot_timeout_seconds:validTimeout(saved[timeoutKey])?saved[timeoutKey]:null,native_source:typeof saved[nativeSourceKey]==="string"?saved[nativeSourceKey]:null};
|
|
47
60
|
};
|
|
48
61
|
const configuredTimeout=saved=>copilotTimeoutMs??(saved.copilot_timeout_seconds===null?undefined:saved.copilot_timeout_seconds*1000);
|
|
49
|
-
const available=(
|
|
62
|
+
const available=(saved=settings())=>saved.enabled&&readAccessSettings(options).providers.github?models():[];
|
|
50
63
|
const nativeModels=(sourceId=settings().native_source)=>{
|
|
51
64
|
if(!sourceId)return [];
|
|
52
65
|
const source=nativeSources().find(item=>item.id===sourceId);
|
|
@@ -55,38 +68,75 @@ export function createAntigravityRuntime({client,models=()=>[],refreshModels,pri
|
|
|
55
68
|
displayName:`${model.display_name||model.id} (${source.name})`,maxTokens:model.capability?.values.context_window,
|
|
56
69
|
maxOutputTokens:model.capability?.values.max_output_tokens,supportsImages:model.capability?.values.input_modalities?.includes("image")===true}));
|
|
57
70
|
};
|
|
58
|
-
const
|
|
71
|
+
const profileFor=source=>source==="github"?"codex:"+githubTokenFingerprint(readToken()||"")
|
|
72
|
+
:source==="google"?"google:gemini-native":getSource(source)?.profileId("gemini");
|
|
73
|
+
const hashProfile=profile=>createHmac("sha256",compactionSalt).update(profile).digest("hex");
|
|
74
|
+
const sourceGuard=guardSource||(async(body,source,signal)=>{
|
|
59
75
|
const labels=body.request?.labels||{},id=labels.root_cascade_id||labels.cascade_id;
|
|
60
76
|
if(typeof id!=="string"||!id||id.length>160)throw httpError("Antigravity request has no stable conversation identifier",400);
|
|
61
|
-
const profile=
|
|
77
|
+
const profile=profileFor(source);
|
|
62
78
|
if(!profile)throw httpError("Antigravity source is unavailable",503);
|
|
63
|
-
|
|
79
|
+
await guard("gemini",profile,{messages:[]},{session_id:id},readClientGatewayKeys({...options,create:false}).codex,undefined,signal);
|
|
80
|
+
return profile;
|
|
64
81
|
});
|
|
65
|
-
const handler=createAntigravityHandler({client,models:available,selectedModels:(
|
|
66
|
-
|
|
82
|
+
const handler=createAntigravityHandler({client,models:available,selectedModels:(saved=settings())=>saved.selected_models,
|
|
83
|
+
defaultModel:(saved=settings())=>saved.default_model,enabled:(saved=settings())=>saved.configured||saved.native_source!==null,
|
|
84
|
+
requestSettings:settings,privacy,searchFn:searchFn||web.search,
|
|
85
|
+
nativeModels:(saved=settings())=>nativeModels(saved.native_source),
|
|
86
|
+
resolveNativeModel(id,saved=settings()){
|
|
87
|
+
const model=nativeModels(saved.native_source).find(entry=>entry.id===id);if(!model)return null;
|
|
88
|
+
const source=getSource(model.source);return source?.client?.gemini?{...model,transport:source}:null;
|
|
89
|
+
},
|
|
67
90
|
imageFn:imageFn||createAntigravityImages({client,models:available,privacy}),guardSource:sourceGuard,compactionProfile:()=>githubTokenFingerprint(readToken()||""),
|
|
68
|
-
rememberConversationSource(body,source
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
async rememberConversationSource(body,source,signal,observedProfile){
|
|
92
|
+
const key=conversationKey(body);if(!key||!validModel(body.model))return;
|
|
93
|
+
const profile=typeof observedProfile==="string"?observedProfile:profileFor(source);if(!profile)return;
|
|
94
|
+
const owner=hashProfile(profile), cached=conversationRoutes?.[key];
|
|
95
|
+
if(cached?.owner===owner&&cached.model===body.model)return;
|
|
96
|
+
const remember=routes=>{
|
|
97
|
+
delete routes[key];routes[key]={owner,model:body.model};
|
|
98
|
+
const keys=Object.keys(routes);for(const id of keys.slice(0,Math.max(0,keys.length-256)))delete routes[id];
|
|
99
|
+
};
|
|
100
|
+
try{
|
|
101
|
+
await withFileLock(routeFile+".lock",async()=>{
|
|
102
|
+
const routes=await readRoutes();signal?.throwIfAborted();
|
|
103
|
+
if(routes[key]?.owner!==owner||routes[key].model!==body.model){
|
|
104
|
+
remember(routes);
|
|
105
|
+
await atomicWriteFile(routeFile,JSON.stringify(routes)+"\n",{mode:0o600});
|
|
106
|
+
}
|
|
107
|
+
conversationRoutes=routes;
|
|
108
|
+
},{timeoutMs:1000,signal});
|
|
109
|
+
}catch{
|
|
110
|
+
signal?.throwIfAborted();
|
|
111
|
+
// Existing source ownership still governs routing if this optional model record cannot be saved.
|
|
112
|
+
remember(conversationRoutes||={});
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
async resolveCompactionSource(body,saved=settings()){
|
|
116
|
+
const key=conversationKey(body);if(!key)return null;
|
|
117
|
+
const id=body.request.labels.root_cascade_id||body.request.labels.cascade_id;
|
|
118
|
+
const owner=await guard.owner("gemini",id,compactionSalt);
|
|
119
|
+
if(!owner)return null;
|
|
120
|
+
conversationRoutes ||= await readRoutes();
|
|
121
|
+
const entry=conversationRoutes[key], pinned=entry?.owner===owner?entry.model:null;
|
|
122
|
+
if(owner===hashProfile(profileFor("google"))){
|
|
123
|
+
const model=pinned||body.model;
|
|
124
|
+
if(!validModel(model)||model.startsWith(ANTIGRAVITY_MODEL_PREFIX)||model.startsWith(ANTIGRAVITY_NATIVE_PREFIX))throw httpError("The conversation belongs to another model source",409);
|
|
125
|
+
return{source:"google",model};
|
|
76
126
|
}
|
|
77
|
-
if(owner===
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const model=nativeModels(selected).find(entry=>entry.id===body.model);
|
|
81
|
-
if(profile&&owner===profileHash(profile)&&model)return{source:selected,model:model.id};
|
|
82
|
-
throw httpError("The conversation belongs to another model source",409);
|
|
127
|
+
if(owner===hashProfile(profileFor("github"))){
|
|
128
|
+
const model=pinned||(validAlias(body.model)?body.model:null);
|
|
129
|
+
return model?{source:"github",model}:{source:"github",background:true};
|
|
83
130
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
131
|
+
const selected=saved.native_source, profile=selected&&profileFor(selected);
|
|
132
|
+
const model=profile&&owner===hashProfile(profile)&&nativeModels(selected).find(entry=>entry.id===(pinned||body.model));
|
|
133
|
+
if(model)return{source:selected,model:model.id};
|
|
134
|
+
throw httpError("The conversation belongs to another model source",409);
|
|
135
|
+
},fetchGoogle:googleFetch,acquireRequest,upstreamTimeoutMs,...timeouts,generationSettings(saved){
|
|
136
|
+
return { selection:saved.selected_models, copilotTimeoutMs:configuredTimeout(saved), preferred:saved.default_model };
|
|
87
137
|
}});
|
|
88
138
|
function snapshot(){
|
|
89
|
-
const config=settings(),sourceEnabled=readAccessSettings(options).providers.github,activity=handler.snapshot();
|
|
139
|
+
const config=settings(),sourceEnabled=readAccessSettings(options).providers.github,activity=handler.snapshot(config);
|
|
90
140
|
const sources=nativeSources(), selectedNative=sources.find(item=>item.id===config.native_source);
|
|
91
141
|
const listed=antigravityCopilotModels(models()).map(({id,model,displayName,effort,maxTokens})=>({id,model,name:displayName,effort,context_window:maxTokens,default:id===config.default_model,selected:config.selected_models===null||config.selected_models.includes(id)}));
|
|
92
142
|
const groups=new Map();
|
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,13 +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
293
|
auto_review: { model: reviewModel?.id || reviewId, source: reviewModel?.source || client.source,
|
|
293
|
-
...(preference.followModel ? { mode: "Follow conversation model" } : {}),
|
|
294
|
-
effort: client.
|
|
295
|
-
?? (
|
|
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 } };
|
|
296
298
|
if (feature) return print({ client: "Codex", feature, state: details[{ prediction: "predictions", image: "images", review: "auto_review" }[feature]] });
|
|
297
299
|
const observed = retainedRequests(snapshot).filter(row => id === "codex" ? ["codex", "codex_app", "codex_cli"].includes(row.application) : row.application === id).at(-1);
|
|
298
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,6 +193,8 @@ 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
|
+
if (c.source === "github" && String(env.CCDX_AUTO_REVIEW_MODEL || "").trim())
|
|
197
|
+
throw accessError("ccdx_review_environment_override", 409);
|
|
196
198
|
const follow = input.model === "";
|
|
197
199
|
const record = follow ? compiled.routes.get(compiled.defaultModel) : [...compiled.routes.values()].find(
|
|
198
200
|
record => record.source === input.provider && record.upstreamModel === input.model
|
|
@@ -102,19 +102,28 @@ export function createConnectionRouting({ legacy, legacyClaudeAccess, isManaged,
|
|
|
102
102
|
if (!Array.isArray(codex.deployments)) return null;
|
|
103
103
|
if (codexRequiresKey()) requireCodexKey(req);
|
|
104
104
|
const context = currentRequestContext(), review = body.model === "codex-auto-review";
|
|
105
|
-
const
|
|
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;
|
|
106
107
|
let requested = body.model;
|
|
107
108
|
if (review) {
|
|
108
109
|
const compiled = plan("codex"), remembered = key && reviewSessions.get(key);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
}
|
|
112
120
|
delete body.service_tier;
|
|
113
121
|
}
|
|
114
122
|
const record = resolveDeployment("codex", requested);
|
|
115
123
|
if (review) {
|
|
116
124
|
const supports = record.model.capability.values.reasoning_efforts || [];
|
|
117
|
-
const
|
|
125
|
+
const configured = !override || codex.auto_review_model === requested ? codex.auto_review_effort : undefined;
|
|
126
|
+
const chosen = configured && supports.includes(configured) ? configured
|
|
118
127
|
: body.reasoning?.effort === undefined && supports.includes("low") ? "low" : undefined;
|
|
119
128
|
if (chosen) body.reasoning = { ...body.reasoning, effort: chosen };
|
|
120
129
|
} else if (key && context) context.noteReviewModel = () => {
|
|
@@ -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("");
|
|
@@ -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);
|
|
@@ -323,7 +323,7 @@
|
|
|
323
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); });
|
|
@@ -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;
|