fix(cli): implement documented --base-url flag with a generic custom OpenAI-compatible provider#82
Open
LivinTribunal wants to merge 2 commits into
Open
fix(cli): implement documented --base-url flag with a generic custom OpenAI-compatible provider#82LivinTribunal wants to merge 2 commits into
LivinTribunal wants to merge 2 commits into
Conversation
…tible provider --base-url was documented but unrecognized: parseArgs silently dropped the flag and its URL value leaked into args.messages as prompt text (#80). - parse --base-url / --api-key in args.ts and document them in --help - new custom.ts builder generalizing the ollama pattern to any OpenAI-compatible endpoint; /v1 appended only when the URL has no path - sdk: baseUrl/apiKey session options, custom model-resolution branch, ollama baseUrl override, streamFn seeds the caller apiKey for every provider and injects a placeholder key for keyless custom endpoints (prevents pi-ai falling back to $OPENAI_API_KEY against arbitrary URLs) - --base-url implies --provider custom; other providers error clearly - ensureAuth short-circuits on CLI overrides: never prompts, never persists - custom provider hidden from interactive pickers for now
…thProviderAuth refactor from #65
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #80.
--base-urlwas documented at harnext.dev but never implemented:parseArgssilently dropped the flag token and its URL value fell intoargs.messages, i.e. it was sent to the model as literal prompt text. There was also no way to reach a self-hosted OpenAI-compatible endpoint, sinceresolveModelonly special-cased ollama/nvidia/openrouter.What this does
--base-url <url>— real flag, parsed inargs.ts, documented in--help. Implies--provider customwhen no--provideris given (matching the documented exampleharnext --base-url http://localhost:8000/v1 --model my-finetune). Also honored for--provider ollama(overrides the stored Ollama URL). Any other explicit provider errors clearly — registry providers use non-OpenAI APIs where a URL swap would half-work at best.--api-key <key>— generic per-run key for whatever provider is resolved (env-var injection for registry providers, threaded into the stream call for custom/ollama/nvidia). Never persisted. Interplay with--fallback-model(feat: request-time model fallback at streamFn — honor --fallback-model (#51) #65): the key seeds only the primary provider; a fallback on a different provider resolves its own env key, so the primary key never reaches the fallback endpoint.customprovider (packages/core/src/custom.ts) — generalizes the Ollama builder to any OpenAI-compatible endpoint (vLLM, llama.cpp, LiteLLM, LM Studio)./v1is appended only when the URL has no path, sohttp://host:8000,http://host:8000/v1, and non-standard mounts all work.createAgentSessiongainsbaseUrl/apiKeyoptions; a storedauth.jsonconfig (getProviderConfig('custom')?.baseUrl) works as fallback for SDK/heartbeat callers.Semantics worth noting
baseUrl/apiKeyare never written toauth.jsonor preferences, consistent with-m/--providernot persisting.ensureAuthshort-circuits on CLI overrides, so a fresh machine never sees the onboarding prompt in headless runs.$OPENAI_API_KEY— leaking the user's real OpenAI key to an arbitrary URL. The placeholder is both a correctness and a security fix.customis hidden from the interactive pickers (newhiddenflag onProviderInfo): an unbranched menu entry would crash on the registry lookup. Full picker integration (base-URL prompt +/v1/modelslisting, mirroring the NVIDIA/Ollama flows) is a clean follow-up.--base-urlno longer silently reuses the resumed session's provider/model — the old model id (e.g. an Anthropic id) would be meaningless against the new endpoint, so the user gets the explicit "requires --model" error instead.Validation errors (all exit 1 with a clear message)
--base-urlwith a non-custom/non-ollama provider--base-urlcustomwithout a model idcustomwithout any base URL (flag or stored config)Tests
Four new files (21 cases): builder/URL-normalization + registry assertions (
custom.test.ts), offline SDK model resolution incl. stored-config fallback and the Ollama override (sdk-model-resolution.test.ts), the args regression — documented example parses with emptymessages(args-base-url.test.ts), andensureAuthoverride short-circuit with nothing persisted (ensure-auth-overrides.test.ts). Full suite: 76 files / 649 tests green; typecheck + lint clean.E2E verified on a clean
HARNEXT_HOME: the documented command goes straight to the endpoint (connection error against a dead port, no onboarding, no "Unknown model"), and each error path prints its message.Updated after merging main: the custom-provider resolution now lives in the shared
resolveModel()(new optionalbaseUrlparam, 2-arg callers unchanged) and the key injection inwithProviderAuth(), both introduced by the #65 fallback refactor.