mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 22:30:21 +00:00
refactor: move provider runtime into extensions
This commit is contained in:
@@ -227,24 +227,6 @@ describe("config cli", () => {
|
||||
expect(written.gateway?.auth).toEqual({ mode: "token" });
|
||||
});
|
||||
|
||||
it("auto-seeds a valid Ollama provider when setting only models.providers.ollama.apiKey", async () => {
|
||||
const resolved: OpenClawConfig = {
|
||||
gateway: { port: 18789 },
|
||||
};
|
||||
setSnapshot(resolved, resolved);
|
||||
|
||||
await runConfigCommand(["config", "set", "models.providers.ollama.apiKey", '"ollama-local"']);
|
||||
|
||||
expect(mockWriteConfigFile).toHaveBeenCalledTimes(1);
|
||||
const written = mockWriteConfigFile.mock.calls[0]?.[0];
|
||||
expect(written.models?.providers?.ollama).toEqual({
|
||||
baseUrl: "http://127.0.0.1:11434",
|
||||
api: "ollama",
|
||||
models: [],
|
||||
apiKey: "ollama-local", // pragma: allowlist secret
|
||||
});
|
||||
});
|
||||
|
||||
it("drops gateway.auth.password when switching mode to token", async () => {
|
||||
const resolved: OpenClawConfig = {
|
||||
gateway: {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { Command } from "commander";
|
||||
import JSON5 from "json5";
|
||||
import { OLLAMA_DEFAULT_BASE_URL } from "../agents/ollama-defaults.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { readConfigFileSnapshot, writeConfigFile } from "../config/config.js";
|
||||
import { formatConfigIssueLines, normalizeConfigIssues } from "../config/issue-format.js";
|
||||
@@ -69,8 +68,6 @@ type ConfigSetOperation = {
|
||||
assignedRef?: SecretRef;
|
||||
};
|
||||
|
||||
const OLLAMA_API_KEY_PATH: PathSegment[] = ["models", "providers", "ollama", "apiKey"];
|
||||
const OLLAMA_PROVIDER_PATH: PathSegment[] = ["models", "providers", "ollama"];
|
||||
const GATEWAY_AUTH_MODE_PATH: PathSegment[] = ["gateway", "auth", "mode"];
|
||||
const SECRET_PROVIDER_PATH_PREFIX: PathSegment[] = ["secrets", "providers"];
|
||||
const CONFIG_SET_EXAMPLE_VALUE = formatCliCommand(
|
||||
@@ -337,24 +334,6 @@ function pathEquals(path: PathSegment[], expected: PathSegment[]): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function ensureValidOllamaProviderForApiKeySet(
|
||||
root: Record<string, unknown>,
|
||||
path: PathSegment[],
|
||||
): void {
|
||||
if (!pathEquals(path, OLLAMA_API_KEY_PATH)) {
|
||||
return;
|
||||
}
|
||||
const existing = getAtPath(root, OLLAMA_PROVIDER_PATH);
|
||||
if (existing.found) {
|
||||
return;
|
||||
}
|
||||
setAtPath(root, OLLAMA_PROVIDER_PATH, {
|
||||
baseUrl: OLLAMA_DEFAULT_BASE_URL,
|
||||
api: "ollama",
|
||||
models: [],
|
||||
});
|
||||
}
|
||||
|
||||
function pruneInactiveGatewayAuthCredentials(params: {
|
||||
root: Record<string, unknown>;
|
||||
operations: ConfigSetOperation[];
|
||||
@@ -1006,7 +985,6 @@ export async function runConfigSet(opts: {
|
||||
// This prevents runtime defaults from leaking into the written config file (issue #6070)
|
||||
const next = structuredClone(snapshot.resolved) as Record<string, unknown>;
|
||||
for (const operation of operations) {
|
||||
ensureValidOllamaProviderForApiKeySet(next, operation.setPath);
|
||||
setAtPath(next, operation.setPath, operation.value);
|
||||
}
|
||||
const removedGatewayAuthPaths = pruneInactiveGatewayAuthCredentials({
|
||||
|
||||
Reference in New Issue
Block a user