Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge #7175 into train K

milind-sonicb4c7cc0a73e
diff --cc server/drivers/codex-catalog.test.ts
index 0dc2dd4788,7d899db844..5244ea792a
--- a/server/drivers/codex-catalog.test.ts
+++ b/server/drivers/codex-catalog.test.ts
@@@ -158,69 -163,55 +163,118 @@@ describe("readCodexModelCatalog", () =
});
});
+ it("reads per-model supportedReasoningEfforts so only supporting models advertise ultra", async () => {
+ chmodSync(FAKE_CLI, 0o755);
+ const catalog = await readCodexModelCatalog(
+ { HOME: join(tmpdir(), "omb-codex-app-server-efforts"), PATH: process.env.PATH, FAKE_CODEX_TIERS: "1", FAKE_CODEX_EFFORTS: "1" },
+ fetch,
+ FAKE_CLI,
+ );
+
+ expect(catalog).toEqual({
+ default: "gpt-fake-default",
+ options: [
+ {
+ id: "gpt-fake-default",
+ label: "GPT Fake Default",
+ effortLevels: ["low", "medium", "high", "xhigh", "max", "ultra"],
+ },
+ {
+ id: "gpt-fake-default+priority",
+ label: "GPT Fake Default · Fast",
+ effortLevels: ["low", "medium", "high", "xhigh", "max", "ultra"],
+ },
+ {
+ id: "gpt-page-two",
+ label: "GPT Page Two",
+ effortLevels: ["low", "medium", "high", "xhigh", "max"],
+ },
+ ],
+ });
+ });
+
+ it("preserves CLI-listed effortLevels when model_catalog_json also matches the configured model", async () => {
+ chmodSync(FAKE_CLI, 0o755);
+ const home = scratchHome({
+ "config.toml": `
+model_provider = "omlx"
+model = "gpt-fake-default"
+model_catalog_json = "omlx-catalog.json"
+
+[model_providers.omlx]
+name = "oMLX"
+`,
+ "omlx-catalog.json": JSON.stringify({ models: [{ slug: "gpt-fake-default" }] }),
+ });
+ const catalog = await readCodexModelCatalog(
+ { HOME: home, PATH: process.env.PATH, FAKE_CODEX_EFFORTS: "1" },
+ fetch,
+ FAKE_CLI,
+ );
+
+ expect(catalog.options).toContainEqual({
+ id: encodeCodexSelection("omlx", "gpt-fake-default"),
+ label: "gpt-fake-default (oMLX)",
+ custom: true,
+ effortLevels: ["low", "medium", "high", "xhigh", "max", "ultra"],
+ });
+ expect(catalog.options).toContainEqual({
+ id: encodeCodexSelection("omlx", "gpt-page-two"),
+ label: "gpt-page-two (oMLX)",
+ custom: true,
+ effortLevels: ["low", "medium", "high", "xhigh", "max"],
+ });
+ });
+
+ it("emits every distinct non-default fast tier (Fast and Ultrafast) without dropping later tiers", async () => {
+ chmodSync(FAKE_CLI, 0o755);
+ const catalog = await readCodexModelCatalog(
+ {
+ HOME: join(tmpdir(), "omb-codex-app-server-ultrafast"),
+ PATH: process.env.PATH,
+ FAKE_CODEX_TIERS: "1",
+ FAKE_CODEX_ULTRAFAST: "1",
+ },
+ fetch,
+ FAKE_CLI,
+ );
+
+ expect(catalog).toEqual({
+ default: "gpt-fake-default",
+ options: [
+ { id: "gpt-fake-default", label: "GPT Fake Default" },
+ { id: "gpt-fake-default+priority", label: "GPT Fake Default · Fast" },
+ { id: "gpt-fake-default+ultrafast", label: "GPT Fake Default · Ultrafast" },
+ { id: "gpt-page-two", label: "GPT Page Two" },
+ { id: "gpt-page-two+ultrafast", label: "GPT Page Two · Ultrafast" },
+ ],
+ });
+ });
+
+ it("strips all tiered options when model_catalog_json routes models to a custom provider", async () => {
+ chmodSync(FAKE_CLI, 0o755);
+ const home = scratchHome({
+ "config.toml": [
+ 'model = "gpt-fake-default"',
+ 'model_provider = "gw"',
+ "model_catalog_json = 'gw-models.json'",
+ "",
+ "[model_providers.gw]",
+ 'name = "My gateway"',
+ 'base_url = "http://127.0.0.1:9/v1"',
+ "",
+ ].join("\n"),
+ });
+
+ const catalog = await readCodexModelCatalog(
+ { HOME: home, PATH: process.env.PATH, FAKE_CODEX_TIERS: "1", FAKE_CODEX_ULTRAFAST: "1" },
+ fetch,
+ FAKE_CLI,
+ );
+
+ expect(catalog.options.map((option) => option.id)).toEqual(["gw::gpt-fake-default", "gw::gpt-page-two"]);
+ });
+
it("appends the configured local model and cached catalog slugs as custom", async () => {
const home = scratchHome({
"config.toml": `
diff --cc server/drivers/codex-catalog.ts
index 4c3e41325c,d1d589ff05..44840e0854
--- a/server/drivers/codex-catalog.ts
+++ b/server/drivers/codex-catalog.ts
@@@ -84,29 -82,21 +84,35 @@@ interface CodexAppServerModel
const FAST_TIER = /fast/i;
+/** Parse per-model `supportedReasoningEfforts` (`string[]` or `{ reasoningEffort: string }[]`) in canonical ascending order. */
+function supportedEffortLevels(row: CodexAppServerModel): readonly EffortLevel[] | undefined {
+ if (!Array.isArray(row.supportedReasoningEfforts)) return undefined;
+ const present = new Set<EffortLevel>();
+ for (const item of row.supportedReasoningEfforts) {
+ const raw = typeof item === "string" ? item
+ : item && typeof item === "object"
+ ? (item as { reasoningEffort?: unknown; effort?: unknown }).reasoningEffort ?? (item as { effort?: unknown }).effort
+ : undefined;
+ if (isEffortLevel(raw)) present.add(raw);
+ }
- return EFFORT_LEVELS.filter((level) => present.has(level));
++ return present.size ? EFFORT_LEVELS.filter((level) => present.has(level)) : undefined;
+}
+
- /** The model's Fast tier (codex-cli 0.167 lists `{id: "priority", name: "Fast"}`), unless it already runs on it. */
- function fastTier(row: CodexAppServerModel): { id: string; name: string } | null {
- if (!Array.isArray(row.serviceTiers)) return null;
+ /** Non-default fast tiers the model advertises (e.g. Fast, Ultrafast), in advertised order without duplicates. */
+ function fastTiers(row: CodexAppServerModel): Array<{ id: string; name: string }> {
+ if (!Array.isArray(row.serviceTiers)) return [];
+ const tiers: Array<{ id: string; name: string }> = [];
+ const seen = new Set<string>();
for (const tier of row.serviceTiers) {
- const id = tier?.id, name = tier?.name;
- if (typeof id !== "string" || typeof name !== "string" || !FAST_TIER.test(name) || !PROVIDER_ID.test(id)) continue;
- return id === row.defaultServiceTier ? null : { id, name };
+ if (!tier || typeof tier !== "object") continue;
+ const { id, name } = tier as { id?: unknown; name?: unknown };
+ const trimmedName = typeof name === "string" ? name.trim() : "";
+ if (typeof id !== "string" || !trimmedName || !FAST_TIER.test(trimmedName) || !PROVIDER_ID.test(id)) continue;
+ if (id === row.defaultServiceTier || seen.has(id)) continue;
+ seen.add(id);
+ tiers.push({ id, name: trimmedName });
}
- return null;
+ return tiers;
}
/** The installed Codex CLI's own ChatGPT catalog, every page: it changes more often than our releases. */
@@@ -193,16 -183,22 +199,24 @@@ export function readCodexAppServerModel
const options: ModelCatalog["options"] = [];
const seen = new Set<string>();
+ const seenOptions = new Set<string>();
let defaultModel: string | null = null;
for (const row of models) {
- if (row.hidden === true || typeof row.id !== "string" || !MODEL_ID.test(row.id) || seen.has(row.id)) continue;
+ if (row.hidden === true || typeof row.id !== "string" || !MODEL_ID.test(row.id) || seenOptions.has(row.id)) continue;
seen.add(row.id);
+ seenOptions.add(row.id);
const label = typeof row.displayName === "string" && row.displayName.trim() ? row.displayName : row.id;
- options.push({ id: row.id, label });
+ const effortLevels = supportedEffortLevels(row);
+ const meta = effortLevels !== undefined ? { effortLevels } : {};
+ options.push({ id: row.id, label, ...meta });
- const fast = fastTier(row);
- if (fast && !TIERED_ID.test(row.id)) options.push({ id: `${row.id}+${fast.id}`, label: `${label} · ${fast.name}`, ...meta });
+ if (!TIERED_ID.test(row.id)) {
+ for (const tier of fastTiers(row)) {
+ const tierId = `${row.id}+${tier.id}`;
+ if (seenOptions.has(tierId)) continue;
+ seenOptions.add(tierId);
- options.push({ id: tierId, label: `${label} · ${tier.name}` });
++ options.push({ id: tierId, label: `${label} · ${tier.name}`, ...meta });
+ }
+ }
if (row.isDefault === true) defaultModel = row.id;
}
if (!options.length) {
diff --cc server/testing/fake-codex-app-server.ts
index 545ce140f1,0b2ed0dfae..63b79bb8f4
--- a/server/testing/fake-codex-app-server.ts
+++ b/server/testing/fake-codex-app-server.ts
@@@ -58,8 -58,7 +58,8 @@@
// FAKE_CODEX_TEXT_BLOCK `codex exec`: comma-separated models answered with the 403 OpenAI sends a region it does not serve
// FAKE_CODEX_LUNA "1": model/list also offers gpt-6-luna
// FAKE_CODEX_TIERS "1": model/list rows list a Fast service tier, as codex-cli 0.167.2 does; gpt-page-two
- // already runs on it by default
+ // already runs on it by default. Set FAKE_CODEX_ULTRAFAST="1" alongside it to also include Ultrafast.
+// FAKE_CODEX_EFFORTS "1": model/list rows declare supportedReasoningEfforts (gpt-fake-default includes "ultra", gpt-page-two stops at "max")
// FAKE_CODEX_UPDATED_FILE while this file exists, the CLI was updated in place: --version answers codex-cli 0.162.1
// and model/list also offers gpt-6.1-sol
// FAKE_CODEX_MCP_START "1": on thread/start, start each `-c mcp_servers.*` mount as codex-cli 0.160.1 does
@@@ -90,8 -89,20 +90,21 @@@ import { appendFileSync, existsSync, re
const mode = process.env.FAKE_CODEX_MODE ?? "happy";
const tiers = process.env.FAKE_CODEX_TIERS === "1";
+const efforts = process.env.FAKE_CODEX_EFFORTS === "1";
- const FAST_TIERS = [{ id: "priority", name: "Fast", description: "Fastest inference with increased plan usage" }];
+ const ultrafastTier = process.env.FAKE_CODEX_ULTRAFAST === "1";
+ const FAST_TIERS = [
+ { id: "priority", name: "Fast", description: "Fastest inference with increased plan usage" },
+ ...(ultrafastTier
+ ? [
+ null,
+ { id: "flex", name: "Flex", description: "Non-fast tier should not be emitted." },
+ { id: "bad tier", name: "Fast", description: "Invalid tier id should be ignored." },
+ { id: "blank", name: " ", description: "Whitespace-only tier name should be ignored." },
+ { id: "ultrafast", name: "Ultrafast", description: "The fastest available responses for latency-sensitive work." },
+ { id: "ultrafast", name: "Ultrafast", description: "Duplicate entry to verify deduplication." },
+ ]
+ : []),
+ ];
// Follow the spawning server down; on Windows ppid does not change after parent exit.
{