feat: expose api_base on Ollama provider metadata schema#522
feat: expose api_base on Ollama provider metadata schema#522paultancre-bt wants to merge 2 commits intomainfrom
Conversation
Add a typed `api_base` field to the Ollama provider's metadata so it can be customized in the AI providers form (e.g. to point at a self-hosted or tunnelled Ollama instance instead of the default `http://127.0.0.1:11434/v1`). The proxy already honors `secret.metadata.api_base` generically at runtime, so this is a schema-only change. It mirrors the existing `MistralMetadataSchema` shape: - Promote `ollama` from the bulk `z.enum` to its own discriminated union arm with `OllamaMetadataSchema` metadata. - `OllamaMetadataSchema` is `BaseMetadataSchema` plus an optional `api_base` (allows valid URL, empty string, null, or undefined to preserve the default). Existing Ollama secrets continue to validate (the new schema is a strict superset), so no migration is required.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a5f98e0ff
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".
|
|
||
| export const OllamaMetadataSchema = BaseMetadataSchema.merge( | ||
| z.object({ | ||
| api_base: z.union([z.string().url(), z.string().length(0)]).nullish(), |
There was a problem hiding this comment.
Preserve passthrough Ollama api_base values
For existing Ollama secrets that already have a non-string or otherwise non-URL metadata.api_base, this new provider-specific arm rejects the secret where the old BaseMetadataSchema.passthrough() arm accepted it and the proxy runtime would ignore non-string values and fall back to the default base URL. The edge loader parses every fetched secret with APISecretSchema.parse (packages/proxy/edge/index.ts lines 246 and 251), so one such stored Ollama secret can now make the secret list fail to load instead of preserving the previous fallback behavior.
Useful? React with 👍 / 👎.
Address Codex review on #522. The new `OllamaMetadataSchema` arm tightens validation on `metadata.api_base` (must be a valid URL, empty string, null, or undefined), where the previous bulk-enum arm used `BaseMetadataSchema.passthrough()` and silently accepted any value. The edge loader parses every fetched secret with `APISecretSchema.parse`, so a single stored Ollama secret with a non-URL/non-string `api_base` (e.g. `"localhost"`, a number, or a bool from a legacy direct API call) would throw and break the whole secret list lookup, instead of falling through to the runtime's existing `typeof api_base === "string"` check that uses the default base URL. Add `.catch(undefined)` to `OllamaMetadataSchema.api_base` so invalid stored values silently coerce to `undefined`, exactly matching the prior "ignore and use default" semantics. Form input still surfaces validation errors via `zodResolver` in the AI providers form, since the form parses fresh user input separately. Includes a regression test in `APISecretSchema compatibility` covering invalid strings, bare hostnames, numbers, booleans, and objects. Co-authored-by: Cursor <cursoragent@cursor.com>
Add a typed
api_basefield to the Ollama provider's metadata so it can be customized in the AI providers form (e.g. to point at a self-hosted or tunnelled Ollama instance instead of the defaulthttp://127.0.0.1:11434/v1).The proxy already honors
secret.metadata.api_basegenerically at runtime, so this is a schema-only change. It mirrors the existingMistralMetadataSchemashape:ollamafrom the bulkz.enumto its own discriminated union arm withOllamaMetadataSchemametadata.OllamaMetadataSchemaisBaseMetadataSchemaplus an optionalapi_base(allows valid URL, empty string, null, or undefined to preserve the default).Existing Ollama secrets continue to validate (the new schema is a strict superset), so no migration is required.