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,73 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
const SKILL_MARKER = /<!-- ccdx:image-skill:([a-f0-9]{64}) -->\n/;
|
|
6
|
+
const HELPER_MARKER = /^\/\/ ccdx:image-helper:([a-f0-9]{64})\n/;
|
|
7
|
+
const REFERENCE_MARKER = /^<!-- ccdx:image-reference:([a-f0-9]{64}) -->\n/;
|
|
8
|
+
const REFERENCE_FILES = ["editing.md", "helper.md"];
|
|
9
|
+
|
|
10
|
+
function digest(content) {
|
|
11
|
+
return createHash("sha256").update(content).digest("hex");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function conflict(message) {
|
|
15
|
+
return Object.assign(new Error(message), { code: "CCDX_IMAGE_SKILL_CONFLICT" });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function directoryCheck(directory) {
|
|
19
|
+
try {
|
|
20
|
+
if (!fs.lstatSync(directory).isDirectory()) throw conflict(`CCDX image skill path is not a regular directory: ${directory}`);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error?.code !== "ENOENT") throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ownedSnapshot(filePath, marker, preserveUnowned = false) {
|
|
27
|
+
try {
|
|
28
|
+
const stat = fs.lstatSync(filePath);
|
|
29
|
+
if (!stat.isFile()) throw conflict(`Refusing to replace an unowned CCDX image skill path: ${filePath}`);
|
|
30
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
31
|
+
const match = marker.exec(content);
|
|
32
|
+
if (!match || digest(content.replace(marker, "")) !== match[1]) {
|
|
33
|
+
throw conflict(`Preserving an existing or modified image skill file: ${filePath}`);
|
|
34
|
+
}
|
|
35
|
+
return { content };
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error?.code === "ENOENT") return null;
|
|
38
|
+
if (preserveUnowned && error?.code === "CCDX_IMAGE_SKILL_CONFLICT") return { unowned: true };
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function removeFile(filePath) {
|
|
44
|
+
try { fs.unlinkSync(filePath); }
|
|
45
|
+
catch (error) { if (error?.code !== "ENOENT") throw error; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function removeEmptyDirectories(skillDirectory) {
|
|
49
|
+
for (const directory of [path.join(skillDirectory, "scripts"), path.join(skillDirectory, "references"), skillDirectory]) {
|
|
50
|
+
try { fs.rmdirSync(directory); }
|
|
51
|
+
catch (error) { if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(error?.code)) throw error; }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function removeLegacyImageGuidance({ codexPath } = {}) {
|
|
56
|
+
const skillDirectory = path.join(path.dirname(codexPath), "skills", "ccdx-image");
|
|
57
|
+
const files = [["SKILL.md", SKILL_MARKER], ["scripts/generate.mjs", HELPER_MARKER],
|
|
58
|
+
...REFERENCE_FILES.map(name => [`references/${name}`, REFERENCE_MARKER])];
|
|
59
|
+
try {
|
|
60
|
+
for (const directory of [skillDirectory, path.join(skillDirectory, "scripts"), path.join(skillDirectory, "references")]) directoryCheck(directory);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error.code === "CCDX_IMAGE_SKILL_CONFLICT" || error.code === "ENOTDIR") return { changed: false, preserved: true };
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
let changed = false, preserved = false;
|
|
66
|
+
for (const [relative, marker] of files) {
|
|
67
|
+
const file = path.join(skillDirectory, relative), snapshot = ownedSnapshot(file, marker, true);
|
|
68
|
+
if (snapshot?.unowned) preserved = true;
|
|
69
|
+
else if (snapshot) { removeFile(file);changed = true; }
|
|
70
|
+
}
|
|
71
|
+
removeEmptyDirectories(skillDirectory);
|
|
72
|
+
return { changed, preserved };
|
|
73
|
+
}
|
package/src/live-models.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isImageModel, imageModelCatalog } from "./image-models.mjs";
|
|
1
2
|
import os from "node:os";
|
|
2
3
|
import { publicModelCatalog } from "./provider-metadata.mjs";
|
|
3
4
|
import { createAbortAwareSingleflight } from "./bounded-result-cache.mjs";
|
|
@@ -140,7 +141,7 @@ async function lookupLiveModels(credentials, { fetchImpl, timeoutMs, vscodeVersi
|
|
|
140
141
|
if (includeAll) {
|
|
141
142
|
const selected = new Set(catalog.models.map(model => model.id));
|
|
142
143
|
catalog.models = publicModelCatalog(Array.isArray(payload) ? payload : payload.data, {
|
|
143
|
-
selectable: model => selected.has(model.id), clients: model => selected.has(model.id) ? ["codex"] : [],
|
|
144
|
+
selectable: model => selected.has(model.id) || imageModelCatalog([model]).length > 0, clients: model => selected.has(model.id) || isImageModel(model) ? ["codex"] : [],
|
|
144
145
|
});
|
|
145
146
|
}
|
|
146
147
|
let upstreamHost = "GitHub Copilot";
|
|
@@ -75,6 +75,15 @@ export function claudeEffortsExpressible(values = {}) {
|
|
|
75
75
|
return levels.length > 0 && levels.every(value => native.includes(value)) && native.slice(0, Math.max(...levels.map(value => native.indexOf(value))) + 1).every(value => levels.includes(value));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
export function claudeEffortPrefix(values = {}) {
|
|
79
|
+
const levels = values.reasoning === false ? [] : values.reasoning_efforts || [];
|
|
80
|
+
const native = ["low", "medium", "high", "xhigh", "max"];
|
|
81
|
+
if (!Array.isArray(levels) || !levels.length || new Set(levels).size !== levels.length || levels.some(value => !native.includes(value))) return [];
|
|
82
|
+
const missing = native.findIndex(value => !levels.includes(value));
|
|
83
|
+
const prefix = native.slice(0, missing < 0 ? native.length : missing);
|
|
84
|
+
return prefix.length === levels.length || prefix.length >= 2 ? prefix : [];
|
|
85
|
+
}
|
|
86
|
+
|
|
78
87
|
export function constrainModelRequest(body, capability, protocol) {
|
|
79
88
|
const values = capability?.values || {}, outputKey = protocol === "messages" ? "max_tokens" : protocol === "responses" ? "max_output_tokens" : "max_completion_tokens";
|
|
80
89
|
let result = body;const applied = [];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createRequestAbort, readJsonBody, readBoundedResponseText, sendJsonError, sendUpstreamError, logRequestFailure } from "./http-transport.mjs";
|
|
2
|
+
import { httpError } from "./http-errors.mjs";
|
|
3
|
+
import { isLoopbackAddress, isLoopbackHostHeader } from "./security.mjs";
|
|
4
|
+
import { DEFAULT_IMAGE_MODEL, imageModelSelection } from "./image-models.mjs";
|
|
5
|
+
import { readAccessSettings } from "./access-settings.mjs";
|
|
6
|
+
import { servicePreferences } from "./user-settings.mjs";
|
|
7
|
+
import { observeRequestedModel, currentRequestContext } from "./request-context.mjs";
|
|
8
|
+
import { recordResponsesUsage } from "./usage-store.mjs";
|
|
9
|
+
|
|
10
|
+
export const NATIVE_IMAGE_MODEL = DEFAULT_IMAGE_MODEL;
|
|
11
|
+
export const IMAGE_MAX_BYTES = 32 * 1024 * 1024;
|
|
12
|
+
const INPUT_MAX_BYTES = 10 * 1024 * 1024;
|
|
13
|
+
const BODY_MAX_BYTES = 64 * 1024 * 1024;
|
|
14
|
+
const RESPONSE_MAX_BYTES = 48 * 1024 * 1024;
|
|
15
|
+
const SIZES = new Set(["auto", "1024x1024", "1536x1024", "1024x1536"]);
|
|
16
|
+
const FIELDS = new Set(["model", "prompt", "images", "background", "quality", "size", "n"]);
|
|
17
|
+
|
|
18
|
+
async function checkedImage(value, maxBytes, mime) {
|
|
19
|
+
if (typeof value !== "string" || !value || value.length > 4 * Math.ceil(maxBytes / 3)
|
|
20
|
+
|| value.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(value)) throw httpError("Invalid image data", 400);
|
|
21
|
+
const bytes = Buffer.from(value, "base64");
|
|
22
|
+
if (!bytes.length || bytes.length > maxBytes || bytes.toString("base64") !== value) throw httpError("Invalid image data", 400);
|
|
23
|
+
let info;
|
|
24
|
+
try { const { default: sharp } = await import("sharp");info = await sharp(bytes, { limitInputPixels: 40_000_000 }).metadata(); }
|
|
25
|
+
catch { throw httpError("Image must be a valid PNG, JPEG or WebP", 400); }
|
|
26
|
+
const type = { png: "image/png", jpeg: "image/jpeg", webp: "image/webp" }[info.format];
|
|
27
|
+
if (!type || mime && mime !== type) throw httpError("Image format does not match its data", 400);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function nativeImageRequest(body, operation, selectedModel = DEFAULT_IMAGE_MODEL) {
|
|
31
|
+
if (!body || typeof body !== "object" || Array.isArray(body) || Object.keys(body).some(key => !FIELDS.has(key))) throw httpError("Unsupported image request field", 400);
|
|
32
|
+
if (!["gpt-image-2", selectedModel].includes(body.model)) throw httpError("Choose an available image model", 400);
|
|
33
|
+
if (typeof body.prompt !== "string" || !body.prompt.trim() || Buffer.byteLength(body.prompt) > 128 * 1024) throw httpError("Image prompt is required and must not exceed 128 KiB", 400);
|
|
34
|
+
if (body.n !== undefined && body.n !== 1) throw httpError("Request one image at a time", 400);
|
|
35
|
+
if (body.quality !== undefined && !["auto", "low", "medium", "high"].includes(body.quality)) throw httpError("Unsupported image quality", 400);
|
|
36
|
+
if (body.size !== undefined && !SIZES.has(body.size)) throw httpError("Unsupported image size", 400);
|
|
37
|
+
if (body.background !== undefined && !["auto", "opaque", "transparent"].includes(body.background)) throw httpError("Unsupported image background", 400);
|
|
38
|
+
if (operation === "generations" && body.images !== undefined) throw httpError("Use images/edits for image inputs", 400);
|
|
39
|
+
if (operation === "edits") {
|
|
40
|
+
if (!Array.isArray(body.images) || !body.images.length || body.images.length > 5) throw httpError("Image editing requires one to five input images", 400);
|
|
41
|
+
for (const image of body.images) {
|
|
42
|
+
if (!image || Object.keys(image).length !== 1 || typeof image.image_url !== "string") throw httpError("Image editing requires inline image data; file IDs are unavailable through GHC", 400);
|
|
43
|
+
const match = /^data:(image\/(?:png|jpeg|webp));base64,(.*)$/s.exec(image.image_url);
|
|
44
|
+
if (!match) throw httpError("Image editing requires PNG, JPEG or WebP data URLs", 400);
|
|
45
|
+
await checkedImage(match[2], INPUT_MAX_BYTES, match[1]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { ...body, model: selectedModel, n: 1 };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function nativeImageAccess(options = {}) {
|
|
52
|
+
const access = readAccessSettings(options), codex = access.clients.codex;
|
|
53
|
+
return access.providers.github && codex.enabled && codex.allowed.includes("github");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createNativeImagesHandler({ client, acquireRequest, privacy, env = process.env, home,
|
|
57
|
+
models = () => [], selection = () => readAccessSettings({ env, home }).clients.codex.image_model,
|
|
58
|
+
requestBodyTimeoutMs = 120000, timeoutMs = 180000, enabled = () => servicePreferences({ env, home }).image_enabled,
|
|
59
|
+
allowed = () => nativeImageAccess({ env, home }) } = {}) {
|
|
60
|
+
let active = 0;
|
|
61
|
+
const metrics = { total: 0, succeeded: 0, failed: 0, busy: 0, cancelled: 0 };
|
|
62
|
+
const handler = async (req, res, operation) => {
|
|
63
|
+
const abort = createRequestAbort(req, res);
|
|
64
|
+
let release = () => {}, admitted = false;
|
|
65
|
+
metrics.total++;
|
|
66
|
+
try {
|
|
67
|
+
if (!isLoopbackAddress(req.socket?.remoteAddress) || req.headers.host !== undefined && !isLoopbackHostHeader(req.headers.host)
|
|
68
|
+
|| Object.hasOwn(req.headers, "origin")) throw httpError("Images require a native local Codex client", 403);
|
|
69
|
+
if (String(req.headers["content-type"] || "").split(";", 1)[0].trim().toLowerCase() !== "application/json") throw httpError("Images require application/json", 415);
|
|
70
|
+
if (!allowed()) throw httpError("GitHub Copilot access is disabled for Codex", 403);
|
|
71
|
+
if (!enabled()) throw httpError("Image requests are paused", 503);
|
|
72
|
+
if (active >= 2) { metrics.busy++;throw httpError("Two image requests are already active", 503); }
|
|
73
|
+
active++;admitted = true;
|
|
74
|
+
abort.setTimeout(requestBodyTimeoutMs, "request_body_timeout");
|
|
75
|
+
release = await acquireRequest(req, { signal: abort.signal });
|
|
76
|
+
const parsed = await readJsonBody(req, { admission: release, signal: abort.signal, maxBodyBytes: BODY_MAX_BYTES, maxDecodedBodyBytes: BODY_MAX_BYTES });
|
|
77
|
+
const available = models();
|
|
78
|
+
const image = parsed?.model === "gpt-image-2" ? imageModelSelection(available, selection()).selected_model : parsed?.model;
|
|
79
|
+
const selected = available.find(model => model.id === image);
|
|
80
|
+
if (!selected) throw httpError("The selected image model is unavailable; refresh the GitHub catalog or choose another image model", parsed?.model === "gpt-image-2" ? 503 : 400);
|
|
81
|
+
if (operation === "edits" && !selected.editing) throw httpError("The selected image model does not support editing", 400);
|
|
82
|
+
const body = await nativeImageRequest(parsed, operation, image);
|
|
83
|
+
observeRequestedModel(body);
|
|
84
|
+
const context = currentRequestContext();
|
|
85
|
+
if (context) { context.provider = "github";context.streamPerformance?.setProvider?.("github"); }
|
|
86
|
+
abort.setTimeout(timeoutMs);
|
|
87
|
+
const forward = input => client.images(operation, { ...body, prompt: input.input }, { signal: abort.signal });
|
|
88
|
+
const call = privacy?.wrap ? privacy.wrap(forward, { res, protocol: "responses", client: "codex" }) : forward;
|
|
89
|
+
const response = await call({ input: body.prompt }, { signal: abort.signal });
|
|
90
|
+
if (!response.ok) { metrics.failed++;await sendUpstreamError(res, response, "images", { signal: abort.signal });return; }
|
|
91
|
+
const text = await readBoundedResponseText(response, { maxBytes: RESPONSE_MAX_BYTES, signal: abort.signal, label: "Copilot image response" });
|
|
92
|
+
let result;
|
|
93
|
+
try { result = JSON.parse(text); } catch { throw httpError("Copilot returned invalid image JSON", 502); }
|
|
94
|
+
if (!Number.isSafeInteger(result.created) || !Array.isArray(result.data) || result.data.length !== 1) throw httpError("Copilot returned an invalid image response", 502);
|
|
95
|
+
try { await checkedImage(result.data[0]?.b64_json, IMAGE_MAX_BYTES); }
|
|
96
|
+
catch { throw httpError("Copilot returned invalid image data", 502); }
|
|
97
|
+
abort.signal.throwIfAborted();
|
|
98
|
+
void recordResponsesUsage({ surface: "images", mode: operation, model: body.model, response: result });
|
|
99
|
+
res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store", "X-CCDX-Image-Model": body.model });
|
|
100
|
+
res.end(text);
|
|
101
|
+
metrics.succeeded++;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
metrics.failed++;
|
|
104
|
+
if (abort.reason === "client_closed" || abort.reason === "client_aborted") metrics.cancelled++;
|
|
105
|
+
logRequestFailure("images", error, abort);
|
|
106
|
+
sendJsonError(res, error, error.statusCode || 502);
|
|
107
|
+
} finally { release();if (admitted) active--;abort.cleanup(); }
|
|
108
|
+
};
|
|
109
|
+
handler.stats = () => ({ ...metrics, active, native: true, model: imageModelSelection(models(), selection()).selected_model });
|
|
110
|
+
return handler;
|
|
111
|
+
}
|
package/src/observability.mjs
CHANGED
|
@@ -22,6 +22,7 @@ const ROUTE_NAMES = Object.freeze([
|
|
|
22
22
|
"messages_count_tokens",
|
|
23
23
|
"claude_models",
|
|
24
24
|
"image_mcp",
|
|
25
|
+
"images",
|
|
25
26
|
"not_found",
|
|
26
27
|
]);
|
|
27
28
|
|
|
@@ -110,6 +111,7 @@ export function classifyAdapterRoute(method, pathname) {
|
|
|
110
111
|
if (method === "POST" && pathname === "/v1/responses") return "responses";
|
|
111
112
|
if (method === "POST" && pathname === "/v1/responses/compact") return "responses_compact";
|
|
112
113
|
if (method === "GET" && pathname === "/v1/models") return "models";
|
|
114
|
+
if (["/v1/images/generations", "/v1/images/edits"].includes(pathname)) return "images";
|
|
113
115
|
if (pathname === "/mcp/image") return "image_mcp";
|
|
114
116
|
return "not_found";
|
|
115
117
|
}
|
package/src/optional-routes.mjs
CHANGED
|
@@ -9,22 +9,16 @@ export function isOptionalRoute(method, pathname) {
|
|
|
9
9
|
// Optional handlers load only on their own routes. Failure is contained by the
|
|
10
10
|
// shared HTTP dispatcher and cannot initialize or change core inference.
|
|
11
11
|
export function createOptionalRoutes(options = {}) {
|
|
12
|
-
let imageMcpHandler = options.imageMcpHandler || null;
|
|
13
12
|
let tools = null;
|
|
14
13
|
let pending = 0;
|
|
15
14
|
return {
|
|
16
15
|
dispose() { tools?.dispose(); },
|
|
17
16
|
busy: () => pending > 0 || tools?.busy?.() === true,
|
|
18
|
-
exportState() {
|
|
17
|
+
exportState() { return { images: [], bytes: 0 }; },
|
|
19
18
|
async importState(state) {
|
|
20
19
|
if (!state || !Array.isArray(state.images)) throw new Error("Invalid optional-service handoff");
|
|
21
|
-
|
|
22
|
-
const { createImageMcpHandler } = await import("./image-mcp.mjs");
|
|
23
|
-
imageMcpHandler ||= createImageMcpHandler({ localHostname: options.imageMcpHostname });
|
|
24
|
-
imageMcpHandler.importState(state.images);
|
|
25
|
-
}
|
|
20
|
+
// Old edit handles are retired; completed files remain user artifacts.
|
|
26
21
|
},
|
|
27
|
-
imageStats() { return imageMcpHandler?.stats?.(); },
|
|
28
22
|
async handle(req, res, pathname) {
|
|
29
23
|
pending++;
|
|
30
24
|
try {
|
|
@@ -41,11 +35,8 @@ export function createOptionalRoutes(options = {}) {
|
|
|
41
35
|
return await serveDashboard(req, res, pathname);
|
|
42
36
|
}
|
|
43
37
|
if (pathname === "/mcp/image") {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
imageMcpHandler ||= createImageMcpHandler({ localHostname: options.imageMcpHostname });
|
|
47
|
-
return imageMcpHandler(req, res);
|
|
48
|
-
});
|
|
38
|
+
res.writeHead(410, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
39
|
+
res.end(JSON.stringify({ error: { code: "ccdx_image_mcp_retired", message: "Use Codex's built-in image tool through CCDX. The image MCP is retired." } }));
|
|
49
40
|
}
|
|
50
41
|
} finally { pending--; }
|
|
51
42
|
},
|
|
@@ -29,6 +29,7 @@ export async function controlPrediction(operation, { integration, nativeOperatio
|
|
|
29
29
|
if (!native) throw new Error("Prediction bridge is unavailable");
|
|
30
30
|
await native.prepareRoute?.();
|
|
31
31
|
return { opened: await openCodex({ predictionPacUrl: native.pacUrl, predictionApp: native.app, predictionProfile: native.profile,
|
|
32
|
+
imageHost: await integration.imageHostLaunch?.({ env: { ...(options.env || process.env), CCDX_AUTO_LAUNCH: "1" } }),
|
|
32
33
|
env: { ...(options.env || process.env), CCDX_AUTO_LAUNCH: "1" }, persistedPredictionRoute: false,
|
|
33
34
|
preparePredictionRoute: () => native.prepareRoute?.(), onPredictionRoute: value => integration.launched(value) }) };
|
|
34
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isImageModel } from "./image-models.mjs";
|
|
1
2
|
import { autoReviewReasoningEfforts } from "./models.mjs";
|
|
2
3
|
import { modelDisplayName } from "./model-display.mjs";
|
|
3
4
|
// Public metadata only. Credentials and provider transport never enter this layer.
|
|
@@ -11,13 +12,13 @@ export function modelReasoningEfforts(model) {
|
|
|
11
12
|
|
|
12
13
|
export function publicModelCatalog(models, { clients = () => [], selectable = () => false, maker = model => model.publisher || model.vendor || model.owned_by || "Unknown" } = {}) {
|
|
13
14
|
return models.slice(0, 1000).filter(model => typeof model?.id === "string").map(model => ({
|
|
14
|
-
id: model.id, display_name: modelDisplayName(model), vendor: maker(model), ...(model.owned_by ? { owned_by: model.owned_by } : {}),
|
|
15
|
+
id: model.id, ...(isImageModel(model) ? { kind: "image" } : {}), display_name: modelDisplayName(model), vendor: maker(model), ...(model.owned_by ? { owned_by: model.owned_by } : {}),
|
|
15
16
|
endpoints: [["responses", ["/responses", "/v1/responses"]], ["chat", ["/chat/completions", "/v1/chat/completions"]],
|
|
16
|
-
["messages", ["/v1/messages"]]].filter(([, paths]) => paths.some(path => model.supported_endpoints?.includes(path))).map(([label]) => label),
|
|
17
|
+
["messages", ["/v1/messages"]], ["images", ["/images/generations", "/v1/images/generations"]], ["image_edits", ["/images/edits", "/v1/images/edits"]]].filter(([, paths]) => paths.some(path => model.supported_endpoints?.includes(path))).map(([label]) => label),
|
|
17
18
|
preview: model.preview === true, selectable: selectable(model), clients: clients(model),
|
|
18
|
-
reasoning_efforts: modelReasoningEfforts(model), auto_review_efforts: model.capability ? modelReasoningEfforts(model) || [] : autoReviewReasoningEfforts(model),
|
|
19
|
+
reasoning_efforts: isImageModel(model) ? null : modelReasoningEfforts(model), auto_review_efforts: isImageModel(model) ? [] : model.capability ? modelReasoningEfforts(model) || [] : autoReviewReasoningEfforts(model),
|
|
19
20
|
context_window: model.capability?.values.context_window ?? (Number.isSafeInteger(model.capabilities?.limits?.max_context_window_tokens)
|
|
20
21
|
&& model.capabilities.limits.max_context_window_tokens > 0 ? model.capabilities.limits.max_context_window_tokens : null),
|
|
21
|
-
state: model.policy?.state && model.policy.state !== "enabled" ? "restricted" : model.model_picker_enabled === false ? "hidden" : "listed",
|
|
22
|
+
state: model.policy?.state && model.policy.state !== "enabled" ? "restricted" : model.model_picker_enabled === false && !isImageModel(model) ? "hidden" : "listed",
|
|
22
23
|
}));
|
|
23
24
|
}
|
package/src/provider-runtime.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isImageModel, imageModelCatalog } from "./image-models.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import { providerDescriptors } from "./provider-descriptors.mjs";
|
|
3
4
|
import { autoReviewPreference, writeAutoReviewModel } from "./user-settings.mjs";
|
|
@@ -251,7 +252,7 @@ function createBuiltinProviderRuntime({ githubClient, githubRegistry, refreshGit
|
|
|
251
252
|
const selected = new Set(selectableCopilotModels(catalog).models.map(model => model.id));
|
|
252
253
|
const upstreamHost = githubClient.runtimeStatus?.().upstream_host;
|
|
253
254
|
return { source: "live", checkedAt: new Date().toISOString(), upstreamHost: upstreamHost && upstreamHost !== "unknown" ? upstreamHost : "GitHub Copilot", advertised: catalog.data.length,
|
|
254
|
-
models: publicModelCatalog(catalog.data, { selectable: model => selected.has(model.id), clients: model => selected.has(model.id) ? ["codex"] : [] }) };
|
|
255
|
+
models: publicModelCatalog(catalog.data, { selectable: model => selected.has(model.id) || imageModelCatalog([model]).length > 0, clients: model => selected.has(model.id) || isImageModel(model) ? ["codex"] : [] }) };
|
|
255
256
|
}
|
|
256
257
|
if (provider !== "m365") throw Object.assign(new Error("Unknown provider"), { statusCode: 400 });
|
|
257
258
|
if (!enabled || !["darwin", "win32"].includes(platform)) throw unavailable(!enabled ? "m365_disabled" : "m365_unsupported");
|
package/src/service-control.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { serviceSettingsSnapshot, servicePreferences, writeServicePreference,
|
|
2
2
|
writeTerminalAnimationTheme, writeTerminalColorTheme, responseHistoryLimitPreference, writeResponseHistoryLimitMib,
|
|
3
3
|
nightlyUpdatePreference, writeNightlyUpdatePreference, decodedBodyLimitPreference, writeDecodedBodyLimitMib } from "./user-settings.mjs";
|
|
4
|
-
import { readImageProviderConfig } from "./image-provider-config.mjs";
|
|
5
4
|
import { readPredictionSettings } from "./native-prediction-profile.mjs";
|
|
6
5
|
import { cacheRuntimeSnapshot, cleanRuntimeCaches, setHistoryCacheLimit } from "./cache-control.mjs";
|
|
7
6
|
import { isTerminalAnimationTheme } from "./terminal-animation.mjs";
|
|
@@ -13,7 +12,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
13
12
|
nightlyStatus = () => null, nightlyChanged = () => {},
|
|
14
13
|
manualUpdate, predictionControl = controlPrediction, imageControl = configureImageSetup,
|
|
15
14
|
adapterPort = 2026, adapterHost = "127.0.0.1",
|
|
16
|
-
readImages = () =>
|
|
15
|
+
readImages = () => imageSetupSummary({ env, home }).configured, readPrediction = () => readPredictionSettings({ env, home }) } = {}) {
|
|
17
16
|
const options = { env, home };
|
|
18
17
|
let serial = Promise.resolve(), lastOperation = null, pending = 0;
|
|
19
18
|
const featureSnapshot = read => { try { return read(options); } catch { return { status: "unavailable" }; } };
|
|
@@ -22,10 +21,11 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
22
21
|
let imageConfigured = false, predictionConfigured = false;
|
|
23
22
|
try { imageConfigured = Boolean(readImages()); } catch {}
|
|
24
23
|
try { predictionConfigured = readPrediction().enabled === true; } catch {}
|
|
24
|
+
const image = featureSnapshot(() => imageSetupSummary({ ...options, models: providerRuntime?.imageModels?.().models || [] }));
|
|
25
25
|
const enabled = nightlyUpdatePreference(options), nightly = nightlyStatus();
|
|
26
26
|
const localPrivacy = providerRuntime?.privacy?.snapshot();
|
|
27
27
|
return { source: "service_settings", saved, theme, color_theme, preferences: settingsPreferencesSnapshot(options), local_privacy: localPrivacy,
|
|
28
|
-
features: { prediction: { ...featureSnapshot(predictionControlSnapshot), bridge: prediction?.bridge || "stopped", active: prediction?.active === true }, image
|
|
28
|
+
features: { prediction: { ...featureSnapshot(predictionControlSnapshot), bridge: prediction?.bridge || "stopped", active: prediction?.active === true }, image },
|
|
29
29
|
decoded_body: decodedBodyLimitPreference(options), manual_update: { available: typeof manualUpdate === "function" }, last_operation: lastOperation,
|
|
30
30
|
nightly_update: { enabled, ...nightly, effect: enabled && !nightly ? "next_start" : "immediate" },
|
|
31
31
|
effective: {
|
|
@@ -33,7 +33,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
33
33
|
terminal_animation_enabled: { value: terminal?.enabled === true && saved.terminal_animation_enabled && !/^(0|false|no|off)$/i.test(env.CCDX_TERMINAL_ANIMATION || ""),
|
|
34
34
|
state: terminal?.enabled === true ? "immediate" : "terminal_unavailable", locked: /^(0|false|no|off)$/i.test(env.CCDX_TERMINAL_ANIMATION || "") },
|
|
35
35
|
open_webui: { value: saved.open_webui, state: "next_start" },
|
|
36
|
-
image_enabled: { value: saved.image_enabled && imageConfigured, state: imageConfigured ? "next_call" : "
|
|
36
|
+
image_enabled: { value: saved.image_enabled && imageConfigured && image.selected_available === true, state: !imageConfigured ? "needs_github_access" : image.selected_available ? "next_call" : "image_model_unavailable", configured: imageConfigured },
|
|
37
37
|
prediction_enabled: { value: prediction?.active === true, state: !predictionConfigured ? "needs_setup"
|
|
38
38
|
: prediction?.environment?.status === "needs_app_relaunch" ? "needs_app_relaunch" : prediction?.bridge !== "running" ? "needs_service_restart" : "next_config_request", configured: predictionConfigured },
|
|
39
39
|
}, history: { ...historyLimit, ...cacheRuntimeSnapshot().response_history },
|
|
@@ -43,7 +43,7 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
43
43
|
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Invalid setting action");
|
|
44
44
|
const allowed = { preference: ["action", "key", "value"], nightly_update: ["action", "enabled"], animation: ["action", "theme"], color_theme: ["action", "theme"],
|
|
45
45
|
history_limit: ["action", "mib"], history_clean: ["action"], prediction_fix: ["action"],
|
|
46
|
-
prediction: ["action", "operation"], image: ["action", "operation", "
|
|
46
|
+
prediction: ["action", "operation"], image: ["action", "operation", "model"],
|
|
47
47
|
update: ["action", "confirmed"], decoded_limit: ["action", "mib"],
|
|
48
48
|
preferences: ["action", "values", "revision"], reset_preferences: ["action", "revision", "backup_id", "scope"], restore_preferences: ["action", "revision", "backup_id", "scope"],
|
|
49
49
|
provider: ["action", "operation", "provider", "model", "auto_review_model", "auto_review_effort", "account_id"] }[input.action];
|
|
@@ -52,9 +52,8 @@ export function createServiceControl({ env = process.env, home, providerRuntime,
|
|
|
52
52
|
if (input.action === "prediction") {
|
|
53
53
|
lastOperation = { feature: "prediction", result: await predictionControl(input.operation, { ...options, integration: clientIntegration }) };
|
|
54
54
|
} else if (input.action === "image") {
|
|
55
|
-
for (const [key, limit] of [["endpoint", 2048], ["key", 8192], ["model", 200]]) if (input[key] !== undefined && (typeof input[key] !== "string" || input[key].length > limit)) throw new Error("Invalid image setup input");
|
|
56
55
|
if (["pause", "resume"].includes(input.operation)) writeServicePreference("image_enabled", input.operation === "resume", options);
|
|
57
|
-
else lastOperation = { feature: "image", result: await imageControl(input, { ...options, adapterPort, adapterHost }) };
|
|
56
|
+
else lastOperation = { feature: "image", result: await imageControl(input, { ...options, providerRuntime, adapterPort, adapterHost }) };
|
|
58
57
|
} else if (input.action === "update") {
|
|
59
58
|
if (input.confirmed !== true) throw new Error("Confirm installation and the idle service switch");
|
|
60
59
|
if (!manualUpdate) throw new Error("This launch cannot update itself; use the installer or start CCDX from its installed command");
|
package/src/service-worker.mjs
CHANGED
|
@@ -8,15 +8,15 @@ import { userSettingsPath } from './user-settings.mjs';
|
|
|
8
8
|
import { readBoundedFileSync } from './bounded-file.mjs';
|
|
9
9
|
import { authProfilePaths, readAuthProfileCredentials } from './auth-profile.mjs';
|
|
10
10
|
import { m365Paths } from './m365-settings.mjs';
|
|
11
|
-
import { imageProviderConfigPath } from './image-provider-config.mjs';
|
|
12
11
|
import { readPredictionSettings } from './native-prediction-profile.mjs';
|
|
12
|
+
import { legacyImageProviderPath } from './image-retirement.mjs';
|
|
13
13
|
|
|
14
14
|
export const HANDOFF_MAX_BYTES = 64 * 1024 * 1024;
|
|
15
15
|
export function clientStateFingerprint(options = {}) {
|
|
16
16
|
const codex = codexPaths(options), connections = accessSettingsPath(options);
|
|
17
17
|
const github = authProfilePaths('codex', options);
|
|
18
18
|
const files = [codex.config, path.join(codex.directory, 'auth.json'), connections, userSettingsPath(options),
|
|
19
|
-
github.tokenPath,
|
|
19
|
+
github.tokenPath, legacyImageProviderPath(options), m365Paths(options).settings, m365Paths(options).gateway,
|
|
20
20
|
path.join(path.dirname(connections), 'client-gateway-keys.json'), path.join(path.dirname(connections), 'codex-gateway-owner.json'), ...Object.values(claudeClientPaths(options))];
|
|
21
21
|
const hash = createHash('sha256');
|
|
22
22
|
const credentials = readAuthProfileCredentials('codex', options);
|