codex-copilot-dx 1.2.15 → 1.2.17

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.
@@ -20,21 +20,51 @@ function send(res, code, value) {
20
20
  res.writeHead(code, { "Content-Type": "application/json", "Cache-Control": "no-store" });res.end(JSON.stringify(value));
21
21
  }
22
22
  const apiError = (code, message) => ({ type: "error", error: { type: "api_error", code, message } });
23
+ function desktopMessages(body) {
24
+ const messages = [], instructions = [];
25
+ const blocks = content => {
26
+ if (typeof content === "string") return [{ type: "text", text: content }];
27
+ if (Array.isArray(content) && content.every(block => block?.type === "text" && typeof block.text === "string")) return content;
28
+ throw Object.assign(new Error("System instructions must contain text"), { code: "ccdx_messages_system_invalid", statusCode: 400 });
29
+ };
30
+ for (const message of body.messages) {
31
+ if (message?.role === "system") instructions.push(...blocks(message.content));
32
+ else messages.push(message);
33
+ }
34
+ return instructions.length ? { ...body, system: [...(body.system === undefined ? [] : blocks(body.system)), ...instructions], messages } : body;
35
+ }
23
36
  function authenticated(headers, key) {
24
37
  const candidates = [headers["x-api-key"], typeof headers.authorization === "string" ? /^Bearer (.+)$/i.exec(headers.authorization)?.[1] : null];
25
38
  const expected = Buffer.from(key);
26
39
  return candidates.some(value => typeof value === "string" && Buffer.byteLength(value) === expected.length && timingSafeEqual(Buffer.from(value), expected));
27
40
  }
28
41
 
29
- // Observe bounded SSE frames while retaining the original wire bytes for the
30
- // client. A slow client controls upstream reads; there is no independent tee.
31
- export function createMessagesObserver(onEvent, maxBytes = 8 * 1024 * 1024) {
32
- const decoder = new TextDecoder();let fragments = [], lineBytes = 0, data = [], frameBytes = 0;
42
+ // Observe bounded SSE frames. Alias clients rewrite only message_start.model;
43
+ // other frames retain their wire text. Client backpressure controls upstream reads.
44
+ export function createMessagesObserver(onEvent, maxBytes = 8 * 1024 * 1024, clientModel = null) {
45
+ const decoder = new TextDecoder("utf-8", { fatal: Boolean(clientModel) });let fragments = [], lineBytes = 0, data = [], frameBytes = 0, wire = [], wireBytes = 0, output = [];
33
46
  const frame = () => {
34
- if (data.length) { let value;try { value = JSON.parse(data.join("\n")); } catch { throw new Error("Invalid Claude stream event"); }onEvent(value); }
47
+ let value;
48
+ if (data.length) { try { value = JSON.parse(data.join("\n")); } catch { throw new Error("Invalid Claude stream event"); }onEvent(value); }
49
+ if (clientModel && wire.length) {
50
+ if (value?.type === "message_start" && value.message && typeof value.message === "object" && !Array.isArray(value.message)) {
51
+ const replacement = JSON.stringify({ ...value, message: { ...value.message, model: clientModel } });let replaced = false;
52
+ wire = wire.map(line => {
53
+ if (!line.startsWith("data:")) return line;
54
+ if (replaced) return "";replaced = true;
55
+ return `data: ${replacement}${line.endsWith("\r\n") ? "\r\n" : line.endsWith("\n") ? "\n" : ""}`;
56
+ });
57
+ }
58
+ output.push(Buffer.from(wire.join("")));wire = [];wireBytes = 0;
59
+ }
35
60
  data = [];frameBytes = 0;
36
61
  };
37
- const line = value => {
62
+ const line = (value, newline = true) => {
63
+ if (clientModel) {
64
+ wireBytes += Buffer.byteLength(value) + (newline ? 1 : 0);
65
+ if (wireBytes > maxBytes) throw new Error("Claude stream event exceeds its limit");
66
+ wire.push(value + (newline ? "\n" : ""));
67
+ }
38
68
  if (value.endsWith("\r")) value = value.slice(0, -1);
39
69
  if (!value) frame();
40
70
  else if (value.startsWith("data:")) {
@@ -47,23 +77,24 @@ export function createMessagesObserver(onEvent, maxBytes = 8 * 1024 * 1024) {
47
77
  while (start < text.length) {
48
78
  const newline = text.indexOf("\n", start), end = newline < 0 ? text.length : newline, part = text.slice(start, end);
49
79
  lineBytes += Buffer.byteLength(part);
50
- if (lineBytes > maxBytes) throw new Error("Claude stream line exceeds its limit");
80
+ if (lineBytes > maxBytes || clientModel && wireBytes + lineBytes > maxBytes) throw new Error("Claude stream line exceeds its limit");
51
81
  fragments.push(part);
52
82
  if (newline < 0) break;
53
83
  line(fragments.join(""));fragments = [];lineBytes = 0;start = newline + 1;
54
84
  }
55
85
  }
56
- return { write(chunk) { consume(decoder.decode(chunk, { stream: true })); },
57
- finish() { consume(decoder.decode());if (fragments.length) line(fragments.join(""));frame(); } };
86
+ return { write(chunk) { output = [];consume(decoder.decode(chunk, { stream: true }));return output; },
87
+ finish() { output = [];consume(decoder.decode());if (fragments.length) line(fragments.join(""), false);frame();return output; } };
58
88
  }
59
89
 
60
- export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, onRequest = () => {}, env = process.env, performance: sharedPerformance, validateConversation,
61
- record = recordUsage, acquireRequest = createRequestAdmission({ maxBytes: 16 * 1024 * 1024, maxQueued: 8 }) } = {}) {
90
+ export function createClaudeGatewayHandler({ provider, apiKey, desktopAliases = false, log = () => {}, onRequest = () => {}, env = process.env, performance: sharedPerformance, validateConversation,
91
+ resolveRequest, record = recordUsage, acquireRequest = createRequestAdmission({ maxBytes: 16 * 1024 * 1024, maxQueued: 8 }) } = {}) {
62
92
  if (!provider || !isProviderId(provider.id) || typeof apiKey !== "string" || apiKey.length < 32) throw new Error("Claude gateway requires a provider and private local key");
63
93
  const config = loadRuntimeConfig(env), performance = sharedPerformance || createStreamPerformanceMetrics({ routeNames: ["messages"] });
64
94
  const decodedLimit = decodedBodyLimitPreference({ env }).bytes;
65
95
  const stats = { total: 0, active: 0, completed: 0, incomplete: 0, failed: 0, cancelled: 0, last_request_at: null, last_model: null };
66
96
  async function dispatch(req, res) {
97
+ let selectedProvider = provider, finishProvider = () => {};
67
98
  if (!isLoopbackAddress(req.socket?.remoteAddress) || req.headers.host === undefined || !isLoopbackHostHeader(req.headers.host)
68
99
  || Object.hasOwn(req.headers, "origin")) { send(res, 403, apiError("ccdx_local_only", "The Claude gateway accepts native local clients only"));return; }
69
100
  if (!authenticated(req.headers, apiKey)) { send(res, 401, apiError("ccdx_gateway_auth", "Invalid local gateway credential"));return; }
@@ -71,7 +102,7 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
71
102
  if (req.method === "GET" && pathname === "/v1/models") {
72
103
  try {
73
104
  const entries = provider.models("claude");
74
- const models = claudeModelEntries(entries).map((entry, index) => ({ id: entry.name, type: "model", display_name: typeof entries[index].name === "string" && entries[index].name || entry.name }));
105
+ const models = claudeModelEntries(entries, { desktopAliases }).map((entry, index) => ({ id: entry.name, type: "model", ...(entry.supports1m ? { supports_1m: true } : {}), display_name: entry.labelOverride || typeof entries[index].name === "string" && entries[index].name || entry.name }));
75
106
  send(res, 200, { data: models, has_more: false, first_id: models[0]?.id || null, last_id: models.at(-1)?.id || null });
76
107
  } catch (error) { send(res, 503, apiError(error.code || "ccdx_catalog_unavailable", "Claude model discovery is unavailable; refresh the provider catalog.")); }
77
108
  return;
@@ -83,12 +114,12 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
83
114
  if (parent) parent.provider = provider.id;
84
115
  const countTokens = pathname.endsWith("/count_tokens"), requestId = parent?.requestId || randomUUID();
85
116
  const tracker = countTokens ? null : performance.begin("messages", { requestId, application: requestApplication(req.headers, "claude") });
86
- tracker?.setProvider(provider.id);
117
+ if (!resolveRequest) tracker?.setProvider(provider.id);
87
118
  const abort = createRequestAbort(req, res);
88
- let release = () => {}, outcome = "failed", model = null, configuredModel = null, responseId = null, usage = null, stopReason = null, streamed = false, sawStop = false, failedEvent = false;
119
+ let release = () => {}, outcome = "failed", model = null, configuredModel = null, clientModel = null, responseId = null, usage = null, stopReason = null, streamed = false, sawStop = false, failedEvent = false;
89
120
  let terminalOrigin = "client_validation", failureStatus = null;
90
121
  if (!countTokens) { stats.total++;stats.active++;stats.last_request_at = new Date().toISOString(); }
91
- await runWithRequestContext({ requestId, provider: provider.id, route: "messages", streamPerformance: tracker }, async () => {
122
+ await runWithRequestContext({ requestId, provider: selectedProvider.id, route: "messages", streamPerformance: tracker }, async () => {
92
123
  try {
93
124
  release = await acquireRequest(req, { signal: abort.signal });
94
125
  abort.setTimeout(config.requestBodyTimeoutMs, "request_body_timeout");
@@ -96,12 +127,23 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
96
127
  if (!body || typeof body.model !== "string" || !Array.isArray(body.messages)) {
97
128
  send(res, 400, apiError("ccdx_messages_invalid", "Expected a model and messages array"));return;
98
129
  }
99
- model = body.model;stats.last_model = model;streamed = !countTokens && body.stream === true;
100
- configuredModel = provider.configuredModels ? resolveClaudeModel(provider.models("claude"), model)?.id : null;
130
+ if (resolveRequest) {
131
+ const resolved = await resolveRequest(body, req);
132
+ selectedProvider = resolved.provider;finishProvider = resolved.finish || finishProvider;
133
+ configuredModel = resolved.model;clientModel = body.model === configuredModel ? null : body.model;
134
+ body = { ...body, model: configuredModel };tracker?.setProvider(selectedProvider.id);
135
+ const context = currentRequestContext();if (context) context.provider = selectedProvider.id;
136
+ }
137
+ if (desktopAliases) body = desktopMessages(body);
138
+ model = body.model;streamed = !countTokens && body.stream === true;
139
+ if (!resolveRequest) configuredModel = provider.configuredModels || desktopAliases ? resolveClaudeModel(provider.models("claude"), model, { desktopAliases })?.id : null;
140
+ if (desktopAliases && !configuredModel) throw Object.assign(new Error("The selected model is unavailable"), { code: "ccdx_api_model_unavailable", statusCode: 400 });
141
+ if (desktopAliases && configuredModel !== model) { clientModel = model;model = configuredModel;body = { ...body, model }; }
142
+ stats.last_model = model;
101
143
  tracker?.setModel(configuredModel || model, { configured: Boolean(configuredModel) });
102
- validateConversation?.(body, req.headers);
144
+ validateConversation?.(body, req.headers, selectedProvider);
103
145
  terminalOrigin = "transport";
104
- const upstream = await provider.client.messages(body, { headers: req.headers, countTokens, signal: abort.signal,
146
+ const upstream = await selectedProvider.client.messages(body, { headers: req.headers, countTokens, signal: abort.signal,
105
147
  onUpstreamStart() { abort.setTimeout(streamed ? config.streamHandshakeTimeoutMs : config.upstreamTimeoutMs, "upstream_timeout"); } });
106
148
  body = null;
107
149
  terminalOrigin = upstream.ok ? "upstream_response" : "upstream_http";
@@ -118,7 +160,8 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
118
160
  model = value.model || model;responseId = value.id;usage = value.usage;stopReason = value.stop_reason;
119
161
  sawStop = typeof stopReason === "string";outcome = stopReason === "max_tokens" ? "incomplete" : sawStop ? "completed" : "failed";
120
162
  } else if (countTokens && upstream.ok) outcome = "completed";
121
- if (!res.destroyed && !res.writableEnded) { res.writeHead(upstream.status, headers);res.end(raw); }
163
+ const outgoing = clientModel && !countTokens && upstream.ok && value?.type === "message" ? JSON.stringify({ ...value, model: clientModel }) : raw;
164
+ if (!res.destroyed && !res.writableEnded) { res.writeHead(upstream.status, headers);res.end(outgoing); }
122
165
  } else {
123
166
  if (!/^text\/event-stream(?:\s*;|$)/i.test(upstream.headers.get("content-type") || "")) throw new Error("Expected a Claude event stream");
124
167
  abort.setTimeout(config.streamIdleTimeoutMs, "stream_idle_timeout");
@@ -130,17 +173,19 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
130
173
  if (event.type === "content_block_delta" && isMessagesOutputDelta(event.delta)) tracker?.firstOutput();
131
174
  if (event.type === "message_delta") { usage = { ...usage, ...event.usage };stopReason = event.delta?.stop_reason || stopReason; }
132
175
  if (event.type === "message_stop") { sawStop = true;outcome = stopReason === "max_tokens" ? "incomplete" : "completed"; }
133
- }, config.maxSseBufferBytes);
176
+ }, config.maxSseBufferBytes, clientModel);
134
177
  const reader = upstream.body.getReader();
135
178
  try {
136
179
  while (true) {
137
180
  const { value, done } = await reader.read();if (done) break;
138
181
  tracker?.upstreamActivity();abort.setTimeout(config.streamIdleTimeoutMs, "stream_idle_timeout");
139
- observer.write(value);
140
- if (!await writeOrDrain(res, value, { signal: abort.signal })) break;
182
+ const frames = observer.write(value);
183
+ let writable = true;
184
+ for (const chunk of clientModel ? frames : [value]) if (!await writeOrDrain(res, chunk, { signal: abort.signal })) { writable = false;break; }
185
+ if (!writable) break;
141
186
  if (sawStop || failedEvent) break;
142
187
  }
143
- observer.finish();
188
+ for (const chunk of observer.finish()) if (!await writeOrDrain(res, chunk, { signal: abort.signal })) break;
144
189
  if (!sawStop && !failedEvent) throw new Error("Claude stream ended before message_stop");
145
190
  if (!res.writableEnded) res.end();
146
191
  } finally { await reader.cancel().catch(() => {});reader.releaseLock(); }
@@ -162,14 +207,14 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
162
207
  }
163
208
  else if (!res.destroyed && !res.writableEnded) res.end(`event: error\ndata: ${JSON.stringify(apiError("ccdx_gateway_error", message))}\n\n`);
164
209
  } finally {
165
- release();abort.cleanup();
210
+ release();abort.cleanup();finishProvider();
166
211
  if (!countTokens) {
167
212
  stats.active--;stats[outcome]++;
168
213
  tracker?.setModel(configuredModel || model, { configured: Boolean(configuredModel) });tracker?.setOutputTokens(usage?.output_tokens);
169
214
  tracker?.terminal(outcome, { origin: failedEvent ? "upstream_event" : terminalOrigin, reason: stopReason === "max_tokens" ? "max_output_tokens" : undefined });
170
215
  tracker?.finish({ failed: outcome === "failed" || outcome === "cancelled", aborted: outcome === "cancelled", statusCode: failureStatus || res.statusCode });
171
216
  const client = req.headers["x-ccdx-client"] === "claude-app" ? "claude_app" : req.headers["x-ccdx-client"] === "claude-code" ? "claude_code" : "claude";
172
- try { void Promise.resolve(record(buildMessagesUsageRecord({ model, responseId, usage, mode: streamed ? "stream" : "json", client, provider: provider.id }))).catch(() => {}); } catch {}
217
+ try { void Promise.resolve(record(buildMessagesUsageRecord({ model: configuredModel || model, responseId, usage, mode: streamed ? "stream" : "json", client, provider: selectedProvider.id }))).catch(() => {}); } catch {}
173
218
  }
174
219
  }
175
220
  });
@@ -1,4 +1,5 @@
1
1
  import { modelReasoningEfforts } from "./provider-metadata.mjs";
2
+ import { createHash } from "node:crypto";
2
3
 
3
4
  const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
4
5
 
@@ -8,19 +9,30 @@ export function claudeClientModelId(id) {
8
9
  return id.replace(/^(claude-(?:opus|sonnet|haiku)-\d+)\.(\d+)$/, "$1-$2");
9
10
  }
10
11
 
11
- export function claudeModelEntries(models) {
12
- const ids = new Set();
12
+ function desktopModelId(id) {
13
+ // Keep native Claude identities, including their family/capability detection.
14
+ if (/^claude-(?:(?:opus|sonnet|haiku)-\d[\d.-]*|\d[\d.-]*-(?:opus|sonnet|haiku)(?:-\d{8})?)(?:-latest)?$/.test(id)) return claudeClientModelId(id);
15
+ // Digits avoid accidentally embedding a vendor name in an opaque route ID.
16
+ const digest = createHash("sha256").update(id).digest("hex").slice(0, 24);
17
+ return `ccdx/claude-compatible-${BigInt(`0x${digest}`).toString(10)}`;
18
+ }
19
+
20
+ export function claudeModelEntries(models, { desktopAliases = false } = {}) {
21
+ const ids = new Set(), upstreamIds = new Set(models.map(model => model.id));
13
22
  return models.map(model => {
14
- const name = claudeClientModelId(model.id);
15
- if (ids.has(name)) throw Object.assign(new Error("Claude model aliases collide; refresh the provider catalog"), { code: "claude_model_alias_collision", statusCode: 503 });
23
+ const name = model.client_id || (desktopAliases ? desktopModelId(model.id) : claudeClientModelId(model.id));
24
+ if (ids.has(name) || name !== model.id && upstreamIds.has(name)) throw Object.assign(new Error("Claude model aliases collide; refresh the provider catalog"), { code: "claude_model_alias_collision", statusCode: 503 });
16
25
  ids.add(name);
17
- const advertised = modelReasoningEfforts(model);
26
+ const advertised = model.capability?.values.reasoning === false ? [] : model.capability?.values.reasoning_efforts || modelReasoningEfforts(model);
18
27
  const maxEffort = EFFORTS.filter(value => advertised?.includes(value)).at(-1);
19
- return { name, ...(maxEffort ? { maxEffort } : {}) };
28
+ return { name, ...(model.display_name || desktopAliases && name !== claudeClientModelId(model.id) ? { labelOverride: model.display_name || model.id } : {}),
29
+ ...(model.capability?.values.context_window >= 1000000 ? { supports1m: true } : {}), ...(maxEffort ? { maxEffort } : {}) };
20
30
  });
21
31
  }
22
32
 
23
- export function resolveClaudeModel(models, id) {
24
- claudeModelEntries(models); // Refuse ambiguous catalogs, including exact-ID collisions.
25
- return models.find(model => model.id === id || claudeClientModelId(model.id) === id);
33
+ export function resolveClaudeModel(models, id, options) {
34
+ const entries = claudeModelEntries(models, options); // Refuse ambiguous catalogs, including exact-ID collisions.
35
+ const alias = entries.findIndex(entry => entry.name === id);
36
+ if (alias >= 0) return models[alias];
37
+ const exact = models.filter(model => model.id === id);return exact.length === 1 ? exact[0] : undefined;
26
38
  }
@@ -0,0 +1,75 @@
1
+ import { deploymentModelId, resolveModelCapabilities, claudeEffortsExpressible } from "./model-capabilities.mjs";
2
+ import { claudeModelEntries } from "./claude-models.mjs";
3
+
4
+ const endpoints = { codex: ["/responses", "/v1/responses"], claude_app: ["/v1/messages"], claude_code: ["/v1/messages"] };
5
+ export function sourceModels(source, client) {
6
+ if (!source) return [];
7
+ const models = source.models?.(client === "codex" ? "gpt" : "claude") || source.registry?.models?.data || [];
8
+ return models.filter(model => model.supported_endpoints?.some(endpoint => endpoints[client].includes(endpoint)
9
+ || client === "codex" && source.id === "github" && ["/chat/completions", "/v1/chat/completions"].includes(endpoint)));
10
+ }
11
+
12
+ export function compileClientModels({ client, binding, source, enabled, names = {}, desktopEffortAliases = false }) {
13
+ if (!binding.enabled) return { models: [], routes: new Map(), defaultModel: null, revision: "disabled" };
14
+ const explicit = Array.isArray(binding.deployments), selected = explicit ? binding.deployments : binding.source
15
+ ? sourceModels(source(binding.source), client).map(model => ({ source: binding.source, model: model.id })) : [];
16
+ const models = [], routes = new Map(), raw = new Map();
17
+ for (const item of selected) {
18
+ if (!binding.allowed.includes(item.source) || !enabled(item.source)) continue;
19
+ const provider = source(item.source), model = sourceModels(provider, client).find(model => model.id === item.model);
20
+ if (!model || model.policy?.state && model.policy.state !== "enabled" || model.model_picker_enabled === false) continue;
21
+ const route = deploymentModelId(item.source, model.id), capability = model.capability || resolveModelCapabilities(model, { builtin: true });
22
+ const entry = { ...model, capability, source_id: item.source, route_id: route,
23
+ ...(explicit ? { client_id: route, display_name: `${model.id} · ${names[item.source] || item.source}` } : {}) };
24
+ if (client === "claude_app" && explicit) {
25
+ const number = route.slice("ccdx/model-".length);
26
+ const efforts = capability.values.reasoning === false ? [] : capability.values.reasoning_efforts || [];
27
+ const native = /^claude-(?:opus|sonnet|haiku)-\d[\d.-]*(?:-latest)?$/.test(model.id);
28
+ entry.client_id = native ? `ccdx-${number}.anthropic.${model.id.replace(/(\d)\.(\d)/g, "$1-$2")}`
29
+ : desktopEffortAliases && claudeEffortsExpressible(capability.values) ? `mythos-ccdx-${number}` : `ccdx/claude-compatible-${number}`;
30
+ }
31
+ const publicId = explicit ? entry.client_id : client === "codex" ? model.id : claudeModelEntries([entry], { desktopAliases: client === "claude_app" && provider.id.startsWith("api_") })[0].name;
32
+ entry.public_id = publicId;
33
+ const record = { provider, model: entry, source: item.source, upstreamModel: model.id, publicId };
34
+ if (routes.has(publicId)) throw Object.assign(new Error("Model routes collide"), { code: "ccdx_model_route_collision", statusCode: 503 });
35
+ routes.set(publicId, record);routes.set(route, record);
36
+ if (client === "claude_app" && explicit) {
37
+ const number = route.slice("ccdx/model-".length);routes.set(`mythos-ccdx-${number}`, record);routes.set(`ccdx/claude-compatible-${number}`, record);
38
+ }
39
+ models.push(entry);
40
+ raw.set(model.id, raw.has(model.id) ? null : record);
41
+ }
42
+ // Old model IDs/desktop aliases remain valid only when they resolve to one
43
+ // authorized deployment. Same-named deployments never pick the first source.
44
+ for (const [id, record] of raw) if (record && !routes.has(id)) {
45
+ routes.set(id, record);
46
+ if (client !== "codex") {
47
+ for (const options of [{ desktopAliases: false }, { desktopAliases: true }]) {
48
+ const old = claudeModelEntries([{ ...record.model, client_id: undefined }], options)[0].name;
49
+ if (!routes.has(old)) routes.set(old, record);
50
+ }
51
+ }
52
+ }
53
+ const fallback = models.find(model => model.id === binding.model || model.route_id === binding.default_model) || models[0];
54
+ return { models, routes, defaultModel: routes.get(binding.default_model)?.publicId || fallback?.public_id || null,
55
+ revision: models.map(model => model.route_id + ":" + model.capability.revision).join(";") };
56
+ }
57
+
58
+ // Client metadata is a projection, never a source of deployment capabilities.
59
+ export function codexModelEntry(model, { priority = 0, name = "", template = {} } = {}) {
60
+ const values = model.capability?.values || {}, efforts = values.reasoning === false ? [] : values.reasoning_efforts || [];
61
+ return { shell_type: "unified_exec", availability_nux: null, upgrade: null, additional_speed_tiers: [], service_tiers: [],
62
+ base_instructions: "", support_verbosity: false, default_verbosity: null, apply_patch_tool_type: null,
63
+ supports_reasoning_summary_parameter: false, default_reasoning_summary: "none", truncation_policy: { mode: "bytes", limit: 10000 },
64
+ experimental_supported_tools: [], input_modalities: values.input_modalities || ["text"], ...template,
65
+ slug: model.public_id || model.id, display_name: model.display_name || model.id, description: name, visibility: "list", supported_in_api: true, priority,
66
+ default_reasoning_level: efforts[0] || null, supported_reasoning_levels: efforts.map(effort => ({ effort, description: effort })),
67
+ context_window: values.context_window || template.context_window || null, max_context_window: values.context_window || template.max_context_window || null };
68
+ }
69
+ export function codexClientCatalog(plan, source) {
70
+ return Object.assign((value, nativeCatalog) => ({ ...value, models: plan.models.map((model, priority) => {
71
+ const template = model.source_id === "github" ? nativeCatalog?.models?.find(entry => entry.slug === model.id)
72
+ : source(model.source_id).codexCatalog?.({ models: [] })?.models?.find(entry => entry.slug === model.id);
73
+ return codexModelEntry(model, { priority, template, name: model.source_id });
74
+ }) }), { needsNativeCatalog: plan.models.some(model => model.source_id === "github") });
75
+ }