Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ocx-cursor",
"version": "1.0.3",
"version": "1.0.4",
"description": "Use OpenCodex models in Cursor through an authenticated HTTPS gateway",
"keywords": [
"opencodex",
Expand Down
29 changes: 27 additions & 2 deletions src/catalog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ export function priorityModelIds(catalogFile = configuredCodexCatalogFile()) {
}
}

export function codexNativeModels(catalogFile = configuredCodexCatalogFile()) {
try {
const payload = JSON.parse(readFileSync(catalogFile, "utf8"));
return payload.models
.filter((model) => typeof model?.slug === "string"
&& !model.slug.includes("/")
&& model.visibility === "list"
&& model.supported_in_api === true
&& model.opencodex_capability_provenance === undefined)
.map((model) => ({
id: model.slug,
owned_by: "openai",
capabilities: {
input_modalities: model.input_modalities,
context_length: model.context_window,
max_output_tokens: model.max_output_tokens,
reasoning_effort: model.supported_reasoning_levels?.map(({ effort }) => effort),
},
}));
} catch {
return [];
}
}

export function normalizeActiveCatalog(configured, active, fastModelIds = new Set()) {
const configuredById = new Map(configured
.filter((model) => typeof model.provider === "string" && typeof model.model === "string")
Expand Down Expand Up @@ -141,9 +165,10 @@ export async function activeModels(fetchImpl = fetch) {
}

export async function buildActiveCatalog(options = {}) {
const codexCatalogFile = options.codexCatalogFile || configuredCodexCatalogFile();
return normalizeActiveCatalog(
configuredModels(options.ocxBin),
await activeModels(options.fetchImpl),
options.fastModelIds || priorityModelIds(options.codexCatalogFile),
[...await activeModels(options.fetchImpl), ...codexNativeModels(codexCatalogFile)],
options.fastModelIds || priorityModelIds(codexCatalogFile),
);
}
34 changes: 33 additions & 1 deletion test/catalog.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import test from "node:test";
import { mkdtemp, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { aliasFor, normalizeActiveCatalog, priorityModelIds } from "../src/catalog.mjs";
import { aliasFor, codexNativeModels, normalizeActiveCatalog, priorityModelIds } from "../src/catalog.mjs";

test("aliases Anthropic models without exposing the provider segment", () => {
assert.equal(aliasFor("anthropic/claude-sonnet-5"), "opencodex/claude-sonnet-5");
Expand Down Expand Up @@ -62,3 +62,35 @@ test("reads Fast support from the OpenCodex priority service tier", async () =>
] }));
assert.deepEqual([...priorityModelIds(file)], ["gpt-fast"]);
});

test("reads visible native models from the Codex catalog", async () => {
const directory = await mkdtemp(join(tmpdir(), "ocx-cursor-native-catalog-"));
const file = join(directory, "models.json");
await writeFile(file, JSON.stringify({ models: [
{
slug: "gpt-daybreak-blue-latest",
visibility: "list",
supported_in_api: true,
context_window: 272_000,
input_modalities: ["text", "image"],
supported_reasoning_levels: [{ effort: "low" }, { effort: "high" }, { effort: "ultra" }],
},
{ slug: "gpt-hidden", visibility: "hide", supported_in_api: true },
{
slug: "anthropic/claude-sonnet-5",
visibility: "list",
supported_in_api: true,
},
] }));

assert.deepEqual(codexNativeModels(file), [{
id: "gpt-daybreak-blue-latest",
owned_by: "openai",
capabilities: {
input_modalities: ["text", "image"],
context_length: 272_000,
max_output_tokens: undefined,
reasoning_effort: ["low", "high", "ultra"],
},
}]);
});
Loading