mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 21:10:43 +00:00
fix(ollama): inject default config fields during normalization to unblock implicit discovery
This commit is contained in:
committed by
Peter Steinberger
parent
5c85624eeb
commit
2549dfe59b
40
extensions/ollama/provider-policy-api.js
Normal file
40
extensions/ollama/provider-policy-api.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { OLLAMA_DEFAULT_BASE_URL } from "./src/defaults.js";
|
||||
|
||||
/**
|
||||
* Provider policy surface for Ollama: normalize provider configs used by
|
||||
* core defaults/normalizers. This runs during config defaults application and
|
||||
* normalization paths (not Zod validation). It ensures the Ollama provider
|
||||
* config uses the native Ollama default base URL when baseUrl is omitted.
|
||||
*
|
||||
* Keep this intentionally small: do not change types or try to sidestep core
|
||||
* schema validation. This helper makes runtime normalization and defaults
|
||||
* consistent for Ollama-only paths.
|
||||
*/
|
||||
export function normalizeConfig({ provider, providerConfig }) {
|
||||
if (!providerConfig || typeof providerConfig !== "object") {
|
||||
return providerConfig;
|
||||
}
|
||||
|
||||
// Only normalize the Ollama provider; be tolerant of provider aliasing/case.
|
||||
const normalizedProviderId = String(provider ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (normalizedProviderId !== "ollama") {
|
||||
return providerConfig;
|
||||
}
|
||||
|
||||
const next = { ...providerConfig };
|
||||
// If baseUrl is missing/empty, default to local Ollama host. Do not override
|
||||
// a deliberately-set empty string or non-string value beyond normalization.
|
||||
if (typeof next.baseUrl !== "string" || !next.baseUrl.trim()) {
|
||||
next.baseUrl = OLLAMA_DEFAULT_BASE_URL;
|
||||
}
|
||||
|
||||
// If models is missing/not an array, default to empty array to signal
|
||||
// that discovery should run to populate models.
|
||||
if (!Array.isArray(next.models)) {
|
||||
next.models = [];
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user