Repository navigation
Custom engine (issue #209): OpenAI-compatible endpoints through the Codex provider passthrough - #227
RemilioNubilio wants to merge 3 commits into
Conversation
…ough the Codex provider passthrough Ported onto main after IQCoreTeam#218 and the engineBin refactor: the registry's binary lookup goes through engineBin.ts (custom resolves the codex binary), customEngineStatus reuses detectCli as its binary probe, and the panel's custom tab (hidden until the host announces a saved endpoint config), engine mark and slash guards live in the panel modules with jsdom coverage; the bundle is regenerated.
Reject whitespace-only model ids at save time, keep invalid-URL errors from echoing the pasted input (it can contain a key), and correct the keyless-auth comments. The approval policy change that shipped alongside this in the spike now lives in IQCoreTeam#221 and is not part of this commit.
customEngineStatus answers in CliReport's own vocabulary (missing, no-login, ok) so the CLI, the VS Code host and the chat session stop re-deriving "codex present AND config saved" each on their own; the unread binaryOk/configured fields and the unused keyless-placeholder export are gone, and the VS Code host reuses the boot probe instead of running a second one.
445b0ba to
5699afd
Compare
|
Hands-on browser QA found a custom-provider resume failure: after reopening a chat and updating its custom config, the next turn failed with a ChatGPT-account model error instead of reaching the configured endpoint. Explicit modelProvider on thread/start and thread/resume fixes the reproduced case. The regression failed before the fix; 481 tests and core typechecking pass afterward. Both keyless and synthetic-key turns were exercised through the real Codex 0.154.0 process against a loopback mock. This proves the local app/transport flow, not real-model, hosted-provider, mobile-device, or MCP support. Keeping this PR draft. Fix commit. NubsCarson does not have push access to this PR's source fork, so the fix is published on the NubsCarson fork for now. |
|
Superseded by #238, which includes the completed implementation and testing. |


Opened as a draft for direction on #209, not for merge yet. nubs has not fully hand-tested this inside the app and the CLI himself; what is verified is below, and the rest is stated as not verified.
This is the ranked-first approach from the issue: reuse the Codex CLI's provider passthrough so AgentNet points the codex binary at an OpenAI-compatible endpoint, instead of adding a second LLM client, a streaming parser, or a proxy. The agent loop, approvals, session transport and tool mapping stay as they are; each surface keeps its transport and gains a config row or tab. A third engine key,
custom, rides the codex engine with five-coverrides and one environment variable.What it does
tokens/custom-engine.json(mode 0600), holds endpoint, model and an optional key. The key never enters argv; it reaches codex through theCUSTOM_ENGINE_API_KEYenvironment variable, and the UI only ever sees a masked view.engineRegistry.tsdescribes the three engines in one table (EngineKey,engineBinary,coerceEngineKey);customresolves its binary through yourengineBin.ts, so a GUI-launched host finds codex the same way every status line does.spawn.tsadds the passthrough as five-coverrides incustomProviderFlags:model_providers.custom.name,.base_url, an always-declared.env_key,model_provider=custom, andmodel=<configured id>. It does not setwire_api; codex 0.153.3 defaults a custom provider to the Responses wire, which the mock run confirms (POST /v1/responses). Theenv_keyone is deliberate, see below.customEngineStatus, returning the sameCliStatus(missing,no-login,ok) the other engines use, feeds the CLI (app.tsx,Chat.tsx,LoginGate.tsx), the VS Code host (pushCustomEngine) and core's custommodelOptionspush insession.ts, which is what localhost and the mobile app receive. The browser bundle cannot import core, sostore.tsxmirrors the rule client-side (engineStatus) from the host-pushedcliStatusandcustomEngine; that is one deliberate duplicate. localhost'spushCustomEnginesends the masked summary without the binary check the VS Code host applies.customin the engine cycle, a connect form (preset, base URL, key, model), reconfigure and remove, and the custom label drawn in the theme'siqViolettoken, which the mono palette currently maps to the same warm gray asdim, so it reads as secondary rather than violet; the VS Code panel and mobile app use--an-violet. Mobile and localhost: config messages and the same connect flow. VS Code panel: a hiddencustomtab that appears once the host announces a usable config (saved endpoint and codex binary both present);/engine customis offered only while a config exists;/loginand/logoutare refused on that tab because there is no account behind it. The panel work is written against the modules from chat panel: move the inline webview script into real modules (#215) #218, with five jsdom cases; the one new panel message iscustomEngine(the host's masked summary, which gates the tab), added to the contract fixtures.Two things worth knowing before you read the code
wire_api = "chat"at config load (the installed 0.153.3 does, and so does every codex release on this machine back to 0.144.3), so a plain chat-completions endpoint does not work through this path; LM Studio serves Responses directly, hosted providers vary. The warning copy says so. Nothing in the UI marks the presets as untested, and the comment overCUSTOM_ENGINE_PRESETSnow says only two of them have carried a real turn; I will drop the hosted presets if you want only exercised endpoints listed.env_keymakes codex attach the user's real ChatGPT login token to the third-party endpoint. Observed once during the 2026-09-02 spike against a logging endpoint (a 1,752-character bearer, the ChatGPT login JWT); not re-run on the port and without a receipt in the repo. What the port's receipts prove is the fix: withenv_keyalways declared, every request in both mock runs carried exactly the placeholder or the configured key.Verified
PANEL_CHROME_REQUIRED=1 npx vitest runin packages/core: 62 files, 461 tests.tsc --noEmitclean for core, the panel tsconfig, CLI, localhost and VS Code.tsupbuilds for CLI, MCP and VS Code and the webviewvite buildsucceed.spawnCli({ cli: "custom" })and the installed codex 0.153.3 against a local mock that speaks the Responses wire, with a scratch home: keyless sendsBearer keylesson all three requests, keyed sends the configured key on all three, both complete the turn.74d8ccd3; the port carries the same custom-engine runtime code (customProviderFlags, theCUSTOM_ENGINE_API_KEYenv, both missing-config gates), while the surroundingspawn.tsmoved under your resume-fallback, rate-limit and engineBin commits.codexApprovalPolicyhunk from the validation commit because Codex: use a supported approval policy for Auto mode #221 landed the identical change. The panel bundle is regenerated andpanel.generated.spec.tsis green.Not verified
/v1/responses.ready. Two leftovers from the fuller SPA flow ride along: the host'sclearCustomEnginehandler has no sender in the panel, and thepresetsfield in itscustomEnginepush is unread there. Both go if the panel stays read-only. That is a scope choice for you.Code rules
customEngineStatusreturns the existingCliStatus;engineBinaryis where a key becomes a binary name on the node side. Two spots still spell custom-to-codex by hand,pickinLoginGate.tsxand the browser-sideengineStatusinstore.tsx, which cannot import the registry; I can route the first throughengineBinary.hasCustomEngineis the one thin helper (a null check three callers share);CUSTOM_ENGINE_KEYLESS_PLACEHOLDERis exported only for the proof driver outside the repo and can lose the export.codexEngineand yourengineBin.tsresolution; the connect form is one new component,CustomEngineForm, mounted by both the login gate and onboarding so the copy cannot drift; it brings@inkjs/ui'sPasswordInputinto the CLI, and the codex API-key step in onboarding now uses it too. The panel tab reuses the codex mode list (CODEX_MODES, referenced twice) and the existingmodelOptionsmessage for its model chip.EngineKeyis shared by every surface; the CLI's ownEnginealias inuseChat.tsis gone,SlashEnginenow points atEngineKey, and no other aliases are added.spawnClitakes the config as one new optional field,custom, on theSpawnOptsbag it already had; no new positional parameter anywhere. Optional parameters added:report?on the status helpers so a probe already in hand is reused,tint?on the welcome panel'sBandfor the engine band, andlabel?oncustomModelOption.customEngineAuth.tsowns the config file and its validation,spawn.tsowns the flags, surfaces own their forms. Two checks are deliberately doubled: the blank-model rejection runs at save (saveCustomEngineConfig) and again at spawn (customProviderFlags) for configs saved before the save-time rule, and the missing-config throw sits in bothstartSessionandspawnCliso a caller that skips the runtime still cannot run stock codex. Each pair carries its message string twice; I will hoist them into one constant each if you want. Said out loud: the endpoint capability check (is this an agentic Responses endpoint or a chat-only model) is a warning today, not a probe; a release should add the probe.Happy to trim this to whatever slice you want to land first, for example the registry and passthrough alone with the CLI form, and to leave the panel and mobile parts for a second PR.