codex-copilot-dx 1.3.13 → 1.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/cli.mjs +7 -10
- package/bin/codex-image-host.mjs +11 -0
- package/docs/ARCHITECTURE.md +9 -6
- package/docs/REFERENCE.md +26 -37
- package/package.json +1 -1
- package/src/access-settings.mjs +2 -1
- package/src/adapter.mjs +14 -4
- package/src/claude-capability-config.mjs +5 -4
- package/src/claude-client-config.mjs +5 -3
- package/src/claude-models.mjs +3 -1
- package/src/cli-command-spec.mjs +4 -11
- package/src/cli-image.mjs +24 -180
- package/src/cli-management.mjs +21 -6
- package/src/cli-options.mjs +1 -1
- package/src/cli-secret.mjs +39 -0
- package/src/cli-tools.mjs +1 -1
- package/src/client-integration.mjs +17 -12
- package/src/client-model-plan.mjs +3 -1
- package/src/clients/claude-models.mjs +3 -3
- package/src/codex-image-host-launch.mjs +38 -0
- package/src/codex-image-host.mjs +216 -0
- package/src/config.mjs +9 -54
- package/src/connection-runtime.mjs +24 -3
- package/src/copilot-client.mjs +16 -1
- package/src/dashboard/connections.js +41 -10
- package/src/dashboard/console.js +6 -4
- package/src/dashboard/features.js +19 -29
- package/src/dashboard/index.html +3 -3
- package/src/dashboard/language.js +8 -7
- package/src/dashboard/ui.css +6 -0
- package/src/dashboard/ui.js +11 -2
- package/src/dashboard/usage.js +10 -5
- package/src/dashboard-api.mjs +2 -1
- package/src/doctor.mjs +4 -5
- package/src/image-models.mjs +20 -0
- package/src/image-retirement.mjs +33 -0
- package/src/image-setup.mjs +16 -105
- package/src/launcher.mjs +7 -4
- package/src/legacy-image-guidance.mjs +73 -0
- package/src/live-models.mjs +2 -1
- package/src/model-capabilities.mjs +9 -0
- package/src/native-images.mjs +111 -0
- package/src/observability.mjs +2 -0
- package/src/optional-routes.mjs +4 -13
- package/src/prediction-control.mjs +1 -0
- package/src/provider-metadata.mjs +5 -4
- package/src/provider-runtime.mjs +2 -1
- package/src/service-control.mjs +6 -7
- package/src/service-worker.mjs +2 -2
- package/src/image-mcp.mjs +0 -328
- package/src/image-provider-config.mjs +0 -194
- package/src/image-provider.mjs +0 -369
- package/src/image-readiness.mjs +0 -55
- package/src/image-references.mjs +0 -50
- package/src/image-skill/SKILL.md +0 -28
- package/src/image-skill/references/editing.md +0 -15
- package/src/image-skill/references/helper.md +0 -27
- package/src/image-skill.mjs +0 -142
- package/src/image-tool-client.mjs +0 -150
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { once } from "node:events";
|
|
6
|
+
import { StringDecoder } from "node:string_decoder";
|
|
7
|
+
|
|
8
|
+
export const IMAGE_HOST_NAMESPACE = "ccdx_images";
|
|
9
|
+
export const IMAGE_HOST_TOOL = Object.freeze({
|
|
10
|
+
type: "namespace", name: IMAGE_HOST_NAMESPACE,
|
|
11
|
+
description: "Codex host image generation and editing through CCDX. Generated images appear in the native image gallery.",
|
|
12
|
+
tools: [{ type: "function", name: "imagegen", deferLoading: false,
|
|
13
|
+
description: "Generate an image or edit reference images. Use this host tool for image requests in this chat. Edit defaults to the last generated image when no references are supplied. Results include native image content and a saved local file.",
|
|
14
|
+
inputSchema: { type: "object", additionalProperties: false, required: ["mode", "prompt"], properties: {
|
|
15
|
+
mode: { type: "string", enum: ["generate", "edit"] }, prompt: { type: "string" },
|
|
16
|
+
transparent_background: { type: "boolean" },
|
|
17
|
+
referenced_image_paths: { type: "array", maxItems: 5, items: { type: "string" }, description: "Images within this workspace, attached by the user, or generated in this chat." },
|
|
18
|
+
num_last_images_to_include: { type: "integer", minimum: 0, maximum: 5 },
|
|
19
|
+
quality: { type: "string", enum: ["auto", "low", "medium", "high"] },
|
|
20
|
+
size: { type: "string", enum: ["auto", "1024x1024", "1536x1024", "1024x1536"] },
|
|
21
|
+
} } }],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export function addImageHostTool(params) {
|
|
25
|
+
const existing = params.dynamicTools || [];
|
|
26
|
+
if (!Array.isArray(existing) || existing.some(tool => tool?.name === IMAGE_HOST_NAMESPACE)) {
|
|
27
|
+
throw new Error("The CCDX image host namespace is already configured");
|
|
28
|
+
}
|
|
29
|
+
return { ...params, dynamicTools: [...existing, IMAGE_HOST_TOOL] };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function imageHostBaseUrl(value) {
|
|
33
|
+
const url = new URL(value);
|
|
34
|
+
if (url.protocol !== "http:" || !["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)
|
|
35
|
+
|| url.pathname !== "/v1" || url.username || url.password || url.search || url.hash) {
|
|
36
|
+
throw new Error("Image host requires the local CCDX /v1 endpoint");
|
|
37
|
+
}
|
|
38
|
+
return url.href.replace(/\/$/, "");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function boundedJson(response) {
|
|
42
|
+
let size = 0;const chunks = [];
|
|
43
|
+
for await (const chunk of response.body) {
|
|
44
|
+
size += chunk.length;
|
|
45
|
+
if (size > 48 * 1024 * 1024) throw new Error("Image backend response exceeds its limit");
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
}
|
|
48
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function imageType(bytes) {
|
|
52
|
+
if (bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) return ["png", "image/png"];
|
|
53
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return ["jpg", "image/jpeg"];
|
|
54
|
+
if (bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP") return ["webp", "image/webp"];
|
|
55
|
+
throw new Error("The image backend did not return a supported image");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const inside = (root, file) => file === root || file.startsWith(root + path.sep);
|
|
59
|
+
|
|
60
|
+
export function createImageHostBridge({ baseUrl, codexHome, sendToCodex, fetchImpl = fetch, imageEnabled,
|
|
61
|
+
now = Date.now } = {}) {
|
|
62
|
+
baseUrl = imageHostBaseUrl(baseUrl);
|
|
63
|
+
const requests = new Map(), threads = new Map(), active = new Map();
|
|
64
|
+
let experimental = false, sequence = 0;
|
|
65
|
+
const root = path.join(codexHome, "generated_images", "ccdx");
|
|
66
|
+
const folder = id => path.join(root, createHash("sha256").update(id).digest("hex").slice(0, 32));
|
|
67
|
+
const enabled = imageEnabled || (async () => {
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetchImpl(baseUrl.replace(/\/v1$/, "/_ccdx/settings"), { signal: AbortSignal.timeout(1000) });
|
|
70
|
+
if (!response.ok) return false;
|
|
71
|
+
const settings = await boundedJson(response);return settings.features?.image?.enabled === true;
|
|
72
|
+
} catch { return false; }
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
async function readReference(value, context, id) {
|
|
76
|
+
if (value.startsWith("data:image/")) return value;
|
|
77
|
+
let file;
|
|
78
|
+
try {
|
|
79
|
+
file = await fs.realpath(path.resolve(context.cwd, value));
|
|
80
|
+
const own = await fs.realpath(folder(id)).catch(() => folder(id));
|
|
81
|
+
const attached = await Promise.all(context.attachments.filter(v => !v.startsWith("data:")).map(v => fs.realpath(v).catch(() => null)));
|
|
82
|
+
const roots = await Promise.all([context.cwd, ...context.roots].map(v => fs.realpath(v).catch(() => null)));
|
|
83
|
+
const generated = await Promise.all(context.generated.map(v => fs.realpath(v).catch(() => null)));
|
|
84
|
+
if (!inside(own, file) && !generated.includes(file) && !attached.includes(file)
|
|
85
|
+
&& !roots.some(v => v && inside(v, file))) throw new Error("scope");
|
|
86
|
+
const stat = await fs.stat(file);
|
|
87
|
+
if (!stat.isFile() || stat.size > 10 * 1024 * 1024) throw new Error("size");
|
|
88
|
+
const bytes = await fs.readFile(file), [, mime] = imageType(bytes);
|
|
89
|
+
return "data:" + mime + ";base64," + bytes.toString("base64");
|
|
90
|
+
} catch { throw new Error("Reference images must be readable images in this workspace, user attachments, or this chat"); }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function recentImages(id, context, count) {
|
|
94
|
+
let disk = [];
|
|
95
|
+
try { disk = (await fs.readdir(folder(id))).filter(v => /\.(png|jpg|webp)$/.test(v)).sort().map(v => path.join(folder(id), v)); }
|
|
96
|
+
catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
97
|
+
return [...new Set([...disk, ...context.generated])].slice(-count);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function runImage(params, signal) {
|
|
101
|
+
const args = params.arguments;
|
|
102
|
+
if (!args || typeof args !== "object" || Array.isArray(args) || !["generate", "edit"].includes(args.mode)
|
|
103
|
+
|| typeof args.prompt !== "string" || !args.prompt.trim()) throw new Error("Choose generate or edit and supply an image prompt");
|
|
104
|
+
const id = params.threadId, context = threads.get(id);
|
|
105
|
+
if (!context) throw new Error("Resume this chat through CCDX before using the image host");
|
|
106
|
+
const references = args.referenced_image_paths || [];
|
|
107
|
+
if (!Array.isArray(references) || references.some(v => typeof v !== "string") || references.length > 5) throw new Error("Choose up to five image references");
|
|
108
|
+
const count = args.num_last_images_to_include;
|
|
109
|
+
if (count !== undefined && (!Number.isInteger(count) || count < 0 || count > 5)) throw new Error("Choose zero to five recent images");
|
|
110
|
+
const body = { model: "gpt-image-2", prompt: args.prompt,
|
|
111
|
+
background: args.transparent_background === true ? "transparent" : "auto",
|
|
112
|
+
quality: args.quality || "auto", size: args.size || "auto" };
|
|
113
|
+
if (args.mode === "edit") {
|
|
114
|
+
let selected = references.length ? references : context.attachments;
|
|
115
|
+
if (count !== undefined ? count > 0 : !selected.length) selected = [...selected, ...await recentImages(id, context, count ?? 1)];
|
|
116
|
+
if (!selected.length || selected.length > 5) throw new Error("Editing requires one to five images");
|
|
117
|
+
body.images = await Promise.all(selected.map(async value => ({ image_url: await readReference(value, context, id) })));
|
|
118
|
+
} else if (references.length || count) throw new Error("Use edit mode with image references");
|
|
119
|
+
const response = await fetchImpl(baseUrl + "/images/" + (args.mode === "edit" ? "edits" : "generations"), {
|
|
120
|
+
method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), signal,
|
|
121
|
+
});
|
|
122
|
+
const result = await boundedJson(response);
|
|
123
|
+
if (!response.ok) throw new Error(result.error?.message || "Image backend returned HTTP " + response.status);
|
|
124
|
+
const pixels = result.data?.[0]?.b64_json;
|
|
125
|
+
if (typeof pixels !== "string") throw new Error("Image backend returned no image");
|
|
126
|
+
const bytes = Buffer.from(pixels, "base64");
|
|
127
|
+
if (!bytes.length || bytes.length > 32 * 1024 * 1024 || bytes.toString("base64") !== pixels) throw new Error("Image backend returned invalid image data");
|
|
128
|
+
const [ext, mime] = imageType(bytes);
|
|
129
|
+
signal.throwIfAborted();
|
|
130
|
+
const directory = folder(id);await fs.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
131
|
+
const savedPath = path.join(directory, String(now()).padStart(16, "0") + "-" + String(sequence++).padStart(6, "0") + "-" + randomUUID() + "." + ext);
|
|
132
|
+
await fs.writeFile(savedPath, bytes, { mode: 0o600, flag: "wx" });
|
|
133
|
+
if (signal.aborted) { await fs.unlink(savedPath);signal.throwIfAborted(); }
|
|
134
|
+
context.generated.push(savedPath);
|
|
135
|
+
return { success: true, contentItems: [{ type: "inputImage", imageUrl: "data:" + mime + ";base64," + pixels },
|
|
136
|
+
{ type: "inputText", text: JSON.stringify({ savedPath, model: response.headers.get("x-ccdx-image-model") || "selected GitHub image model" }) }] };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
async client(message) {
|
|
141
|
+
if (message.method === "initialize") experimental = message.params?.capabilities?.experimentalApi === true;
|
|
142
|
+
if (["thread/start", "thread/resume", "thread/fork"].includes(message.method)) {
|
|
143
|
+
requests.set(JSON.stringify(message.id), { method: message.method, params: message.params || {} });
|
|
144
|
+
if (message.method === "thread/start" && experimental && await enabled()) return { ...message, params: addImageHostTool(message.params || {}) };
|
|
145
|
+
}
|
|
146
|
+
if (message.method === "turn/start") {
|
|
147
|
+
const context = threads.get(message.params?.threadId);
|
|
148
|
+
if (context) context.attachments = (message.params.input || []).flatMap(value => value.type === "localImage" ? [path.resolve(context.cwd, value.path)]
|
|
149
|
+
: value.type === "image" && typeof value.url === "string" && value.url.startsWith("data:image/") ? [value.url] : []);
|
|
150
|
+
}
|
|
151
|
+
if (message.method === "turn/interrupt") for (const value of active.values()) if (value.threadId === message.params?.threadId) value.controller.abort(new Error("Image request cancelled"));
|
|
152
|
+
return message;
|
|
153
|
+
},
|
|
154
|
+
codex(message) {
|
|
155
|
+
const pending = requests.get(JSON.stringify(message.id));
|
|
156
|
+
if (pending && !message.method) {
|
|
157
|
+
requests.delete(JSON.stringify(message.id));const thread = message.result?.thread;
|
|
158
|
+
if (thread?.id && thread.cwd) threads.set(thread.id, { cwd: thread.cwd, roots: pending.params.runtimeWorkspaceRoots || [], attachments: [], generated: [] });
|
|
159
|
+
}
|
|
160
|
+
if (message.method === "item/completed" && message.params?.item?.type === "imageGeneration" && message.params.item.savedPath) {
|
|
161
|
+
threads.get(message.params.threadId)?.generated.push(message.params.item.savedPath);
|
|
162
|
+
}
|
|
163
|
+
if (message.id === undefined || message.method !== "item/tool/call" || message.params?.namespace !== IMAGE_HOST_NAMESPACE || message.params?.tool !== "imagegen") return false;
|
|
164
|
+
const controller = new AbortController(), key = JSON.stringify(message.id);
|
|
165
|
+
active.set(key, { controller, threadId: message.params.threadId });
|
|
166
|
+
void runImage(message.params, AbortSignal.any([controller.signal, AbortSignal.timeout(180000)]))
|
|
167
|
+
.then(result => sendToCodex({ id: message.id, result }))
|
|
168
|
+
.catch(error => sendToCodex({ id: message.id, result: { success: false, contentItems: [{ type: "inputText", text: error.message }] } }))
|
|
169
|
+
.finally(() => active.delete(key));
|
|
170
|
+
return true;
|
|
171
|
+
},
|
|
172
|
+
close() { for (const value of active.values()) value.controller.abort(new Error("Image host closed")); },
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function lines(stream, accept) {
|
|
177
|
+
const decoder = new StringDecoder("utf8");let buffer = "";
|
|
178
|
+
const data = chunk => {
|
|
179
|
+
buffer += decoder.write(chunk);let boundary;
|
|
180
|
+
while ((boundary = buffer.indexOf("\n")) >= 0) { const line = buffer.slice(0, boundary);buffer = buffer.slice(boundary + 1);accept(line); }
|
|
181
|
+
};
|
|
182
|
+
const end = () => { buffer += decoder.end();if (buffer) accept(buffer); };
|
|
183
|
+
stream.on("data", data);stream.on("end", end);
|
|
184
|
+
return () => { stream.removeListener("data", data);stream.removeListener("end", end); };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function runCodexImageHost({ codex, argv, baseUrl, env = process.env, input = process.stdin, output = process.stdout, error = process.stderr, spawnImpl = spawn } = {}) {
|
|
188
|
+
const args = argv || [], at = args.indexOf("app-server"), rest = args.slice(at + 1);
|
|
189
|
+
const stdio = at >= 0 && !["daemon", "proxy", "generate-ts", "generate-json-schema"].includes(rest[0])
|
|
190
|
+
&& !rest.some(value => /^--listen=(?!stdio:\/\/)/.test(value))
|
|
191
|
+
&& (rest.indexOf("--listen") < 0 || rest[rest.indexOf("--listen") + 1] === "stdio://");
|
|
192
|
+
const childEnv = { ...env, CODEX_APP_RUNTIME_CLI_PATH: codex };delete childEnv.CODEX_CLI_PATH;
|
|
193
|
+
const child = spawnImpl(codex, args, { env: childEnv, stdio: ["pipe", "pipe", "pipe"] });
|
|
194
|
+
child.stdin.on("error", () => {});child.stderr.pipe(error, { end: false });
|
|
195
|
+
let bridge, queue = Promise.resolve();const cleanups = [];
|
|
196
|
+
const write = message => { if (!child.stdin.destroyed) child.stdin.write(JSON.stringify(message) + "\n"); };
|
|
197
|
+
if (!stdio) { input.pipe(child.stdin);child.stdout.pipe(output, { end: false }); }
|
|
198
|
+
else {
|
|
199
|
+
bridge = createImageHostBridge({ baseUrl, codexHome: path.resolve(env.CODEX_HOME || path.join(env.HOME || process.env.HOME, ".codex")), sendToCodex: write });
|
|
200
|
+
cleanups.push(lines(input, raw => {
|
|
201
|
+
queue = queue.then(async () => {
|
|
202
|
+
let message;try { message = JSON.parse(raw); } catch { child.stdin.write(raw + "\n");return; }
|
|
203
|
+
try { const next = await bridge.client(message);if (next === message) child.stdin.write(raw + "\n");else write(next); }
|
|
204
|
+
catch (failure) { output.write(JSON.stringify({ id: message.id, error: { code: -32602, message: failure.message } }) + "\n"); }
|
|
205
|
+
});
|
|
206
|
+
}));
|
|
207
|
+
cleanups.push(lines(child.stdout, raw => { let value;try { value = JSON.parse(raw); } catch {}if (!value || !bridge.codex(value)) output.write(raw + "\n"); }));
|
|
208
|
+
const end = () => { void queue.finally(() => { bridge.close();child.stdin.end(); }); };
|
|
209
|
+
input.on("end", end);cleanups.push(() => input.removeListener("end", end));
|
|
210
|
+
}
|
|
211
|
+
const stop = signal => { bridge?.close();child.kill(signal); };
|
|
212
|
+
const interrupt = () => stop("SIGINT"), terminate = () => stop("SIGTERM");
|
|
213
|
+
process.once("SIGINT", interrupt);process.once("SIGTERM", terminate);
|
|
214
|
+
try { const [code, signal] = await once(child, "exit");await queue;return code ?? (signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 1); }
|
|
215
|
+
finally { bridge?.close();for (const cleanup of cleanups) cleanup();input.unpipe(child.stdin);input.pause();process.removeListener("SIGINT", interrupt);process.removeListener("SIGTERM", terminate); }
|
|
216
|
+
}
|
package/src/config.mjs
CHANGED
|
@@ -12,10 +12,9 @@ const MODEL_CONTEXT_WINDOW = 1_000_000;
|
|
|
12
12
|
const MODEL_AUTO_COMPACT_TOKEN_LIMIT = 900_000;
|
|
13
13
|
const IMAGE_MCP_START = "# ccdx:image-mcp:start";
|
|
14
14
|
const IMAGE_MCP_END = "# ccdx:image-mcp:end";
|
|
15
|
-
const IMAGE_MCP_SECTION = "mcp_servers.ccdx_image";
|
|
16
15
|
const IMAGE_MCP_KEYS = ["enabled", "tool_timeout_sec", "url"];
|
|
17
16
|
|
|
18
|
-
//
|
|
17
|
+
// Legacy setup is rejected; cleanup preserves unowned settings.
|
|
19
18
|
export class ImageMcpConfigError extends Error {}
|
|
20
19
|
const STARTUP_MANAGED_PATHS = [
|
|
21
20
|
"openai_base_url",
|
|
@@ -158,46 +157,20 @@ function removeImageMcpDeclarations(content, statements, markers) {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
function ensureImageMcp(lines, enabled, adapterPort, adapterHost, previousBaseUrl) {
|
|
160
|
+
if (enabled) throw new ImageMcpConfigError("The image MCP is retired; use native Codex images");
|
|
161
161
|
const previous = lines.join("\n");
|
|
162
162
|
const config = parseCodexToml(previous);
|
|
163
163
|
const section = configValue(config, IMAGE_MANAGED_PATH);
|
|
164
164
|
const url = `${adapterBaseUrl(imageMcpHost(adapterHost), adapterPort)}/mcp/image`;
|
|
165
165
|
if (section !== undefined) {
|
|
166
|
-
// Reuse compatible registrations without rewriting comments, formatting,
|
|
167
|
-
// user tool policies, or timeouts. An explicit disabled flag is preserved.
|
|
168
|
-
if (enabled && imageMcpUrl(section?.url)?.href === new URL(url).href
|
|
169
|
-
&& [undefined, true].includes(section?.enabled)) return false;
|
|
170
166
|
const statements = codexTomlStatements(previous);
|
|
171
167
|
const markers = imageMcpMarkers(previous, statements);
|
|
172
|
-
if (!knownImageMcp(section, url, previousBaseUrl, statements, markers))
|
|
173
|
-
if (!enabled) return false;
|
|
174
|
-
throw new ImageMcpConfigError(`Codex config already defines [${IMAGE_MCP_SECTION}] outside the CCDX-managed block; its settings were preserved`);
|
|
175
|
-
}
|
|
168
|
+
if (!knownImageMcp(section, url, previousBaseUrl, statements, markers)) return false;
|
|
176
169
|
const removed = removeImageMcpDeclarations(previous, statements, markers);
|
|
177
|
-
if (removed === null)
|
|
178
|
-
if (!enabled) return false;
|
|
179
|
-
throw new ImageMcpConfigError(`Cannot safely update [${IMAGE_MCP_SECTION}] inside a shared inline table; its settings were preserved`);
|
|
180
|
-
}
|
|
170
|
+
if (removed === null) return false;
|
|
181
171
|
lines.splice(0, lines.length, ...removed.split("\n"));
|
|
182
172
|
while (lines.length && !lines.at(-1).trim()) lines.pop();
|
|
183
173
|
}
|
|
184
|
-
if (enabled) {
|
|
185
|
-
const parent = config.mcp_servers;
|
|
186
|
-
if (parent !== undefined && (typeof parent !== "object" || parent === null || Array.isArray(parent)
|
|
187
|
-
|| codexTomlStatements(previous).some((item) => item.kind === "value" && sameKeys(item.keys, ["mcp_servers"])))) {
|
|
188
|
-
throw new ImageMcpConfigError("Cannot append the image MCP to an inline or non-table mcp_servers setting; its settings were preserved");
|
|
189
|
-
}
|
|
190
|
-
while (lines.length && lines.at(-1).trim() === "") lines.pop();
|
|
191
|
-
if (lines.length) lines.push("");
|
|
192
|
-
lines.push(
|
|
193
|
-
IMAGE_MCP_START,
|
|
194
|
-
`[${IMAGE_MCP_SECTION}]`,
|
|
195
|
-
`url = ${JSON.stringify(url)}`,
|
|
196
|
-
"enabled = true",
|
|
197
|
-
"tool_timeout_sec = 210",
|
|
198
|
-
IMAGE_MCP_END,
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
174
|
return lines.join("\n") !== previous;
|
|
202
175
|
}
|
|
203
176
|
|
|
@@ -227,7 +200,8 @@ export function computeUpdatedCodexConfig(
|
|
|
227
200
|
changed = setTomlKey(lines, "shell_environment_policy.set", "OPENAI_BASE_URL", baseUrl) || changed;
|
|
228
201
|
changed = setTomlKey(lines, "shell_environment_policy.set", "OPENAI_API_KEY", "dummy") || changed;
|
|
229
202
|
changed = ensureContextManagementDefault(lines) || changed;
|
|
230
|
-
if (
|
|
203
|
+
if (imageProviderEnabled === true) throw new ImageMcpConfigError("The image MCP is retired; use native Codex images");
|
|
204
|
+
if (imageProviderEnabled === false) {
|
|
231
205
|
changed = ensureImageMcp(lines, imageProviderEnabled, adapterPort, adapterHost, config.openai_base_url) || changed;
|
|
232
206
|
}
|
|
233
207
|
|
|
@@ -238,7 +212,7 @@ export function computeUpdatedCodexConfig(
|
|
|
238
212
|
return { content: updated, changed };
|
|
239
213
|
}
|
|
240
214
|
|
|
241
|
-
export function initialCodexConfig(adapterPort, adapterHost
|
|
215
|
+
export function initialCodexConfig(adapterPort, adapterHost) {
|
|
242
216
|
const baseUrl = `${adapterBaseUrl(adapterHost, adapterPort)}/v1`;
|
|
243
217
|
const base = `openai_base_url = "${baseUrl}"
|
|
244
218
|
model_context_window = ${MODEL_CONTEXT_WINDOW}
|
|
@@ -254,9 +228,7 @@ OPENAI_API_KEY = "dummy"
|
|
|
254
228
|
[features]
|
|
255
229
|
context_management = true
|
|
256
230
|
`;
|
|
257
|
-
return
|
|
258
|
-
? computeUpdatedCodexConfig(base, adapterPort, adapterHost, { imageProviderEnabled }).content
|
|
259
|
-
: base;
|
|
231
|
+
return base;
|
|
260
232
|
}
|
|
261
233
|
|
|
262
234
|
function computeImageConfig(
|
|
@@ -287,7 +259,6 @@ export function ensureCodexConfig(adapterPort = 2026, options = {}) {
|
|
|
287
259
|
function ensureCodexConfigUnlocked(adapterPort = 2026, {
|
|
288
260
|
filePath,
|
|
289
261
|
host = "127.0.0.1",
|
|
290
|
-
imageProviderEnabled = false,
|
|
291
262
|
log = console.log,
|
|
292
263
|
...options
|
|
293
264
|
} = {}) {
|
|
@@ -313,22 +284,6 @@ function ensureCodexConfigUnlocked(adapterPort = 2026, {
|
|
|
313
284
|
atomicWriteFileIfChangedSync(filePath, core.content);
|
|
314
285
|
log(status("ok", content === undefined ? `Created Codex configuration: ${filePath}` : parseCodexToml(core.content).openai_base_url === baseUrl ? `Configured Codex base URL: ${baseUrl}` : "Codex startup settings updated; existing base URL preserved"));
|
|
315
286
|
}
|
|
316
|
-
// Disabled means no image maintenance, including no implicit removal of old
|
|
317
|
-
// or user-owned entries. Explicit disable-image owns the cleanup operation.
|
|
318
287
|
const coreSetup = parseCodexToml(core.content).openai_base_url === baseUrl ? "configured" : "preserved";
|
|
319
|
-
|
|
320
|
-
try {
|
|
321
|
-
const previousBaseUrl = content === undefined ? undefined : parseCodexToml(content).openai_base_url;
|
|
322
|
-
const image = computeImageConfig(core.content, { enabled: true, adapterPort, adapterHost: host }, previousBaseUrl);
|
|
323
|
-
if (image.changed) {
|
|
324
|
-
if (fs.readFileSync(filePath, "utf8") !== core.content) {
|
|
325
|
-
throw new ImageMcpConfigError("Codex config changed during image setup; the newer configuration was preserved");
|
|
326
|
-
}
|
|
327
|
-
atomicWriteFileIfChangedSync(filePath, image.content);
|
|
328
|
-
}
|
|
329
|
-
return { coreSetup, imageMcpSkipped: false };
|
|
330
|
-
} catch (error) {
|
|
331
|
-
console.warn(status("warn", `Image MCP setup was skipped: ${error.message}. Core proxy startup will continue.`));
|
|
332
|
-
return { coreSetup, imageMcpSkipped: true };
|
|
333
|
-
}
|
|
288
|
+
return { coreSetup, imageMcpSkipped: false };
|
|
334
289
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { imageModelCatalog, imageModelSelection } from "./image-models.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import { randomBytes, createHash } from "node:crypto";
|
|
3
4
|
import {
|
|
@@ -313,6 +314,11 @@ export function createConnectionRuntime({
|
|
|
313
314
|
});
|
|
314
315
|
return summaries.get(api);
|
|
315
316
|
}
|
|
317
|
+
function imageModels() {
|
|
318
|
+
const c = binding("codex");
|
|
319
|
+
return imageModelSelection(enabled("github") && c.allowed.includes("github")
|
|
320
|
+
? imageModelCatalog(legacy.github?.registry?.models) : [], c.image_model);
|
|
321
|
+
}
|
|
316
322
|
function clientSnapshot(id, config, compact, readPlan) {
|
|
317
323
|
const base = {
|
|
318
324
|
id,
|
|
@@ -330,6 +336,7 @@ export function createConnectionRuntime({
|
|
|
330
336
|
...base,
|
|
331
337
|
revision,
|
|
332
338
|
model_plan: {
|
|
339
|
+
...(id === "codex" ? { image: imageModels() } : {}),
|
|
333
340
|
default_model: compiled.defaultModel,
|
|
334
341
|
default_unavailable: compiled.defaultUnavailable,
|
|
335
342
|
models: compiled.models.map(model => ({
|
|
@@ -378,7 +385,7 @@ export function createConnectionRuntime({
|
|
|
378
385
|
const selected = new Map(CLIENT_IDS.map(id => [id, new Set(plan(id).models.filter(model => model.source_id === sourceId).map(model => model.id))]));
|
|
379
386
|
return { ...catalog, models: catalog.models.map(model => ({ ...model,
|
|
380
387
|
client_visibility: CLIENT_IDS.map(id => ({ client: id,
|
|
381
|
-
reason: modelExclusion(id, sourceId, model.id, model, selected.get(id).has(model.id)) })) })) };
|
|
388
|
+
reason: modelExclusion(id, sourceId, model.id, model, selected.get(id).has(model.id) || id === "codex" && sourceId === "github" && model.kind === "image" && imageModels().selected_model === model.id) })) })) };
|
|
382
389
|
}
|
|
383
390
|
function snapshot(compact = false) {
|
|
384
391
|
const state = legacy.snapshot(),
|
|
@@ -912,6 +919,10 @@ export function createConnectionRuntime({
|
|
|
912
919
|
...(input.auto_review_model ? { auto_review_model: input.auto_review_model } : {}),
|
|
913
920
|
...(input.auto_review_effort !== undefined ? { auto_review_effort: input.auto_review_effort } : {}),
|
|
914
921
|
};
|
|
922
|
+
if (input.image_model !== undefined) {
|
|
923
|
+
if (input.id !== "codex" || input.image_model !== old.image_model && !imageModels().models.some(model => model.id === input.image_model)) throw accessError("ccdx_api_model_unavailable");
|
|
924
|
+
next.clients.codex.image_model = input.image_model;
|
|
925
|
+
}
|
|
915
926
|
if (input.id !== "codex") next.claude_private_keys = true;
|
|
916
927
|
if (old.source !== input.source) next.clients[input.id].history_isolation = true;
|
|
917
928
|
const c = next.clients[input.id];
|
|
@@ -1001,6 +1012,7 @@ export function createConnectionRuntime({
|
|
|
1001
1012
|
return {
|
|
1002
1013
|
...snapshot(),
|
|
1003
1014
|
preview: {
|
|
1015
|
+
...(input.id === "codex" ? { image: imageModelSelection(imageModels().models, c.image_model) } : {}),
|
|
1004
1016
|
models: proposed.models.map(model => ({
|
|
1005
1017
|
source: model.source_id,
|
|
1006
1018
|
id: model.id,
|
|
@@ -1090,22 +1102,30 @@ export function createConnectionRuntime({
|
|
|
1090
1102
|
"deployments",
|
|
1091
1103
|
"default_model",
|
|
1092
1104
|
"auto_sync",
|
|
1105
|
+
"image_model",
|
|
1093
1106
|
"client_revision",
|
|
1094
1107
|
])
|
|
1095
1108
|
)
|
|
1096
1109
|
throw accessError("ccdx_connections_action_invalid");
|
|
1097
1110
|
if (
|
|
1098
|
-
["client", "preview_client", "sync_client", "client_state"].includes(input.operation) &&
|
|
1111
|
+
["client", "preview_client", "sync_client", "client_state", "image_model"].includes(input.operation) &&
|
|
1099
1112
|
input.client_revision !== undefined &&
|
|
1100
1113
|
(!CLIENT_IDS.includes(input.id) || input.client_revision !== clientRevision(input.id))
|
|
1101
1114
|
)
|
|
1102
1115
|
throw accessError("ccdx_connections_conflict", 409);
|
|
1103
1116
|
if (
|
|
1104
|
-
!["client", "preview_client", "sync_client", "client_state"].includes(input.operation) &&
|
|
1117
|
+
!["client", "preview_client", "sync_client", "client_state", "image_model"].includes(input.operation) &&
|
|
1105
1118
|
input.impact_revision !== undefined &&
|
|
1106
1119
|
input.impact_revision !== sourceImpact(input.id).revision
|
|
1107
1120
|
)
|
|
1108
1121
|
throw accessError("ccdx_connections_conflict", 409);
|
|
1122
|
+
if (input.operation === "image_model") {
|
|
1123
|
+
if (!validObject(input, ["operation", "id", "model", "client_revision"]) || input.id !== "codex"
|
|
1124
|
+
|| !imageModels().models.some(model => model.id === input.model)) throw accessError("ccdx_api_model_unavailable");
|
|
1125
|
+
const next = editable();next.clients.codex.image_model = input.model;save(next);
|
|
1126
|
+
await syncClients(["codex"]);
|
|
1127
|
+
return snapshot();
|
|
1128
|
+
}
|
|
1109
1129
|
if (input.operation === "sync_client") {
|
|
1110
1130
|
if (
|
|
1111
1131
|
!validObject(input, ["operation", "id", "client_revision"]) ||
|
|
@@ -1279,6 +1299,7 @@ export function createConnectionRuntime({
|
|
|
1279
1299
|
void catalogRefresh.refresh(input.id).catch(() => {});
|
|
1280
1300
|
return input.operation === "save_api" ? snapshot() : result;
|
|
1281
1301
|
},
|
|
1302
|
+
imageModels,
|
|
1282
1303
|
async start() {
|
|
1283
1304
|
if (binding("codex").enabled) void memoryModel.refresh();
|
|
1284
1305
|
const old = legacy.start();
|
package/src/copilot-client.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { debugLog } from "./log.mjs";
|
|
|
5
5
|
import { enforceResponsesPayloadByteBudget } from "./responses-byte-budget.mjs";
|
|
6
6
|
import { status } from "./status.mjs";
|
|
7
7
|
import { withChatStreamUsage } from "./stream-contract.mjs";
|
|
8
|
-
import { markRequestObservation, markUpstreamStarted } from "./stream-performance.mjs";
|
|
8
|
+
import { markRequestObservation, markUpstreamStarted, markUpstreamHeaders } from "./stream-performance.mjs";
|
|
9
9
|
import { currentRequestContext } from "./request-context.mjs";
|
|
10
10
|
import { requestOptionsEvidence } from "./response-failures.mjs";
|
|
11
11
|
|
|
@@ -205,6 +205,20 @@ export function createCopilotClientRuntime({
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
async function images(operation, body, { signal, fetchImpl } = {}) {
|
|
209
|
+
if (!["generations", "edits"].includes(operation)) throw new Error("Unsupported image operation");
|
|
210
|
+
const token = await tokenSession.getToken({ signal });
|
|
211
|
+
const headers = buildHeaders({ token, version: getVSCodeVersion(), initiator: "user", vision: operation === "edits" });
|
|
212
|
+
const bodyText = JSON.stringify(body);
|
|
213
|
+
markRequestObservation({ payload_bytes: Buffer.byteLength(bodyText), images: body.images?.length || 0 });
|
|
214
|
+
markUpstreamStarted(false);
|
|
215
|
+
const response = await fetchCopilotUpstream(`${tokenSession.getApiBase()}/v1/images/${operation}`, {
|
|
216
|
+
method: "POST", headers, body: bodyText, signal, redirect: "error",
|
|
217
|
+
}, { fetchImpl, retries: 0 });
|
|
218
|
+
markUpstreamHeaders(response.status);
|
|
219
|
+
return response;
|
|
220
|
+
}
|
|
221
|
+
|
|
208
222
|
function responsesCompact(reqBody, options = {}) {
|
|
209
223
|
return responses(reqBody, options);
|
|
210
224
|
}
|
|
@@ -239,6 +253,7 @@ export function createCopilotClientRuntime({
|
|
|
239
253
|
resetModelListSingleflightForTests,
|
|
240
254
|
responses,
|
|
241
255
|
responsesCompact,
|
|
256
|
+
images,
|
|
242
257
|
resetForTests,
|
|
243
258
|
});
|
|
244
259
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const el = id => document.getElementById(id), root = el("connection-sources");if (!root) return;
|
|
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
|
-
let claudeClient = "claude_app", bindingSelection = new Set(), bindingDefault = null, bindingDirty = false;
|
|
5
|
+
let claudeClient = "claude_app", bindingSelection = new Set(), bindingDefault = null, bindingImageModel = null, bindingImageDirty = false, bindingDirty = false;
|
|
6
6
|
let memoryAction = null, memoryOrigin = null;
|
|
7
7
|
let disableRevision = null;
|
|
8
8
|
const drafts = new Map();let editorOrigin = null, discovery = null, desiredSource = null;
|
|
@@ -100,18 +100,23 @@
|
|
|
100
100
|
try { const result = await api();if (current !== generation) return;data = result;mountClient();list(); }
|
|
101
101
|
catch (error) { if (!data) message(error.message); }
|
|
102
102
|
}
|
|
103
|
+
const imageViewRevision = value => {
|
|
104
|
+
const c = value?.clients.find(client => client.id === "codex"), image = c?.model_plan?.image;
|
|
105
|
+
return JSON.stringify([c?.enabled, image?.selected_model, image?.selected_available, image?.models]);
|
|
106
|
+
};
|
|
103
107
|
async function change(input, done) {
|
|
104
108
|
if (busy) return;busy = true;generation++;
|
|
105
|
-
const
|
|
109
|
+
const previousImage = imageViewRevision(data);
|
|
110
|
+
const trigger = ["client", "image_model"].includes(input.operation) ? clientForm.querySelector('button[type="submit"]') : input.operation === "preview_client" ? el("connection-sync-preview")
|
|
106
111
|
: input.operation === "save_api" ? apiForm.querySelector('button[type="submit"]') : document.activeElement;
|
|
107
112
|
const oldKey = trigger?.dataset.i18n, oldText = trigger?.textContent;
|
|
108
113
|
if (trigger?.tagName === "BUTTON") { trigger.setAttribute("aria-busy", "true");trigger.disabled = true;words(trigger, input.operation === "preview_client" ? "api_reading" : "api_saving"); }
|
|
109
|
-
try { if (input.operation === "save_api") await stopDiscovery();data = await api(input);if (input.operation
|
|
114
|
+
try { if (input.operation === "save_api") await stopDiscovery();data = await api(input);if (["client", "image_model"].includes(input.operation)) { drafts.delete(input.id);if (editingClient === input.id) bindingDirty = false; }mountClient();list();done?.(data);if (!done) {
|
|
110
115
|
if (input.operation === "save_api") {
|
|
111
116
|
desiredSource = input.id || data.providers.find(p => !p.builtin && p.name === input.config.name)?.id;
|
|
112
117
|
stopDiscovery();
|
|
113
118
|
} else if (input.operation === "provider" && input.enabled) desiredSource = input.id;
|
|
114
|
-
panels();let key = input.operation === "save_api" ? "api_config_saved" : input.operation === "provider" ? input.enabled ? "api_provider_enabled" : "api_provider_disabled"
|
|
119
|
+
panels();let key = input.operation === "image_model" ? "api_saved" : input.operation === "save_api" ? "api_config_saved" : input.operation === "provider" ? input.enabled ? "api_provider_enabled" : "api_provider_disabled"
|
|
115
120
|
: !input.enabled ? "api_client_disabled" : !input.source ? "api_client_enabled" : "api_saved";
|
|
116
121
|
const setup = data.clients.find(c => c.id === input.id)?.setup;
|
|
117
122
|
if (input.operation === "client" && ["preserved", "partially_preserved"].includes(setup)) key = "api_client_preserved";
|
|
@@ -123,15 +128,15 @@
|
|
|
123
128
|
if (input.operation === "save_api" && input.config.models.length) for (const c of data.clients.filter(c => c.enabled && input.allowed.includes(c.id))) {
|
|
124
129
|
const link = node("a", c.name, "section-link");link.href = c.id === "codex" ? "#codex" : "#claude";link.addEventListener("click", event => { event.preventDefault();editClient(c); });el("connection-note").append(" ", link);
|
|
125
130
|
}
|
|
126
|
-
}window.dispatchEvent(new CustomEvent("ccdx:connections"));void dashboardRefresh.refresh("auth", { force: true });void dashboardRefresh.refresh("status", { force: true }); }
|
|
131
|
+
}if (input.operation !== "preview_client") window.dispatchEvent(new CustomEvent("ccdx:connections", { detail: { imageChanged: imageViewRevision(data) !== previousImage } }));void dashboardRefresh.refresh("auth", { force: true });void dashboardRefresh.refresh("status", { force: true }); }
|
|
127
132
|
catch (error) {
|
|
128
133
|
if (input.operation === "provider" && !input.enabled && error.message === "ccdx_connections_conflict") {
|
|
129
134
|
try { data = await api();list();disableSource(source(input.id));message("api_impact_changed"); } catch { message(error.message); }return;
|
|
130
135
|
}
|
|
131
|
-
if (input.operation === "source_access") accessError = error.message;else if (input.operation
|
|
136
|
+
if (input.operation === "source_access") accessError = error.message;else if (["client", "image_model"].includes(input.operation)) words(el("connection-client-note"), error.message);else message(error.message);return;
|
|
132
137
|
}
|
|
133
138
|
finally { busy = false;if (trigger?.tagName === "BUTTON") { trigger.removeAttribute("aria-busy");trigger.disabled = false;if (oldKey) words(trigger, oldKey);else trigger.textContent = oldText; }
|
|
134
|
-
if (["client", "preview_client"].includes(input.operation)) bindingRows();
|
|
139
|
+
if (["client", "preview_client", "image_model"].includes(input.operation)) bindingRows();
|
|
135
140
|
if (input.operation === "source_access") renderAccess();
|
|
136
141
|
if (input.operation === "save_api") words(apiForm.querySelector('button[type="submit"]'), editing ? "api_save" : "api_save_read");
|
|
137
142
|
}
|
|
@@ -226,6 +231,7 @@
|
|
|
226
231
|
node("td", count(preview?.shared?.budgets?.[proposed?.public_id])), node("td", reasoningText(values)), node("td", searchText(values)));body.append(row);
|
|
227
232
|
}
|
|
228
233
|
const wrap = node("div", undefined, "table-wrap");wrap.append(table);result.append(wrap);
|
|
234
|
+
if (preview?.image?.selected_model) { const image = node("p");image.textContent = `${format("image_model")}: ${preview.image.selected_model}`;result.append(image); }
|
|
229
235
|
const note = node("p", undefined, "hint");words(note, "cap_preview_scope");result.append(note);
|
|
230
236
|
const sync = preview?.shared || c.model_plan?.sync;
|
|
231
237
|
if (c.credential_state === "encrypted_unverified") { const kept = node("p", undefined, "hint");words(kept, "client_key_encrypted_kept");result.append(kept); }
|
|
@@ -359,7 +365,7 @@
|
|
|
359
365
|
const bindingKey = (source, model) => source + "\0" + model;
|
|
360
366
|
const routeId = item => item.route_id || item.public_id;
|
|
361
367
|
function rememberDraft() {
|
|
362
|
-
if (editingClient && bindingDirty) drafts.set(editingClient, { selection: new Set(bindingSelection), defaultModel: bindingDefault, autoSync: el("connection-auto-sync").checked });
|
|
368
|
+
if (editingClient && bindingDirty) drafts.set(editingClient, { selection: new Set(bindingSelection), defaultModel: bindingDefault, imageModel: bindingImageModel, imageDirty: bindingImageDirty, autoSync: el("connection-auto-sync").checked });
|
|
363
369
|
}
|
|
364
370
|
function mountClient(force = false) {
|
|
365
371
|
if (!data) return;
|
|
@@ -374,9 +380,12 @@
|
|
|
374
380
|
const selected = Array.isArray(c.deployments) ? c.deployments : (c.model_plan?.models || []).map(model => ({ source: model.source, model: model.id }));
|
|
375
381
|
bindingSelection = draft ? new Set(draft.selection) : new Set(selected.map(item => bindingKey(item.source, item.model)));
|
|
376
382
|
bindingDefault = draft ? draft.defaultModel : c.default_model || c.model_plan?.models.find(model => model.public_id === c.model_plan?.default_model)?.route_id || null;
|
|
383
|
+
bindingImageModel = draft?.imageDirty ? draft.imageModel : c.image_model || c.model_plan?.image?.selected_model || null;
|
|
384
|
+
bindingImageDirty = draft?.imageDirty === true;
|
|
377
385
|
el("connection-auto-sync").checked = draft ? draft.autoSync : c.auto_sync !== false;
|
|
378
386
|
el("connection-sync-result").hidden = true;el("connection-client-note").textContent = "";
|
|
379
387
|
}
|
|
388
|
+
if (id === "codex" && !bindingImageDirty) bindingImageModel = c.image_model || c.model_plan?.image?.selected_model || null;
|
|
380
389
|
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();
|
|
381
390
|
}
|
|
382
391
|
function bindingRows(focus) {
|
|
@@ -408,6 +417,19 @@
|
|
|
408
417
|
details.forEach((cell, i) => cell.dataset.label = format(["source", "cap_context", "cap_reasoning"][i]));
|
|
409
418
|
row.append(name, ...details, cell);body.append(row);
|
|
410
419
|
}
|
|
420
|
+
if (editingClient === "codex") {
|
|
421
|
+
for (const image of c.model_plan?.image?.models || []) {
|
|
422
|
+
const row = node("tr"), name = node("td"), label = node("label"), radio = node("input");
|
|
423
|
+
radio.type = "radio";radio.name = "binding-image-model";radio.value = image.id;radio.checked = bindingImageModel === image.id;
|
|
424
|
+
radio.addEventListener("change", () => { if (radio.checked) { bindingImageModel = image.id;bindingImageDirty = true;bindingDirty = true;rememberDraft();bindingRows({ kind: "image", key: image.id }); } });
|
|
425
|
+
label.append(radio, node("span", image.name || image.id));name.append(label);
|
|
426
|
+
const purpose = node("td");words(purpose, "image_purpose");
|
|
427
|
+
row.dataset.imageModel = image.id;row.append(name, node("td", source("github")?.name || "GitHub Copilot"), node("td", "—"), node("td", "—"), purpose);body.append(row);
|
|
428
|
+
}
|
|
429
|
+
if (bindingImageModel && !c.model_plan?.image?.models.some(model => model.id === bindingImageModel)) {
|
|
430
|
+
const row = node("tr"), cell = node("td", bindingImageModel);cell.colSpan = 5;const warning = node("span", undefined, "hint binding-unavailable");words(warning, "image_selected_unavailable");cell.append(" ", warning);row.append(cell);body.append(row);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
411
433
|
const unavailableDefault = bindingSelection.size > 0 && !available.some(item => routeId(item) === bindingDefault && bindingSelection.has(bindingKey(item.source, item.id)));
|
|
412
434
|
const warning = el("connection-default-note");warning.hidden = !unavailableDefault;words(warning, "cap_default_unavailable");
|
|
413
435
|
clientForm.querySelector('button[type="submit"]').disabled = unavailableDefault || busy;
|
|
@@ -419,7 +441,7 @@
|
|
|
419
441
|
const capabilityNote = el("connection-capability-state");capabilityNote.hidden = !c.model_plan?.sync?.limitations?.some(item => item.code === "client_version_unknown");
|
|
420
442
|
if (!capabilityNote.hidden) words(capabilityNote, "sync_capability_unverified");
|
|
421
443
|
words(clientForm.querySelector('button[type="submit"]'), el("connection-auto-sync").checked ? "cap_save_sync" : "api_save");
|
|
422
|
-
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(); }
|
|
444
|
+
if (focus) { const selector = focus.kind === "selection" ? 'input[name="binding-model"]' : focus.kind === "image" ? 'input[name="binding-image-model"]' : 'button[data-binding]';[...body.querySelectorAll(selector)].find(input => (input.value || input.dataset.binding) === focus.key)?.focus(); }
|
|
423
445
|
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); }
|
|
424
446
|
}
|
|
425
447
|
function editClient(c) { location.hash = c.id === "codex" ? "codex" : "claude";if (c.id !== "codex") claudeClient = c.id;mountClient(true); }
|
|
@@ -430,8 +452,17 @@
|
|
|
430
452
|
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"); });
|
|
431
453
|
el("connection-client-cancel").addEventListener("click", () => { drafts.delete(editingClient);bindingDirty = false;mountClient(true); });
|
|
432
454
|
function bindingInput(operation) {
|
|
433
|
-
const c = client(editingClient);
|
|
455
|
+
const c = client(editingClient);
|
|
456
|
+
if (operation === "client" && editingClient === "codex" && bindingImageModel && bindingImageModel !== c.model_plan?.image?.selected_model) {
|
|
457
|
+
const selected = c.deployments || c.model_plan?.models.map(model => ({ source: model.source, model: model.id })) || [];
|
|
458
|
+
const keys = selected.map(item => bindingKey(item.source, item.model));
|
|
459
|
+
const defaultModel = c.default_model || c.model_plan?.models.find(model => model.public_id === c.model_plan?.default_model)?.route_id || null;
|
|
460
|
+
if (keys.length === bindingSelection.size && keys.every(key => bindingSelection.has(key)) && defaultModel === bindingDefault && (c.auto_sync !== false) === el("connection-auto-sync").checked)
|
|
461
|
+
return { operation: "image_model", id: "codex", model: bindingImageModel, client_revision: c.revision };
|
|
462
|
+
}
|
|
463
|
+
return { operation, id: c.id, enabled: true, allowed: c.allowed,
|
|
434
464
|
deployments: [...bindingSelection].map(key => { const [source, model] = key.split("\0");return { source, model }; }),
|
|
465
|
+
...(editingClient === "codex" && bindingImageModel ? { image_model: bindingImageModel } : {}),
|
|
435
466
|
default_model: bindingDefault, auto_sync: el("connection-auto-sync").checked };
|
|
436
467
|
}
|
|
437
468
|
clientForm.addEventListener("submit", event => { event.preventDefault();void change(bindingInput("client")); });
|