fix(onboard): default custom Ollama URL to native API

This commit is contained in:
Peter Steinberger
2026-03-11 20:08:41 +00:00
parent 620bae4ec7
commit e65011dc29
2 changed files with 20 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import { CONTEXT_WINDOW_HARD_MIN_TOKENS } from "../agents/context-window-guard.js"; import { CONTEXT_WINDOW_HARD_MIN_TOKENS } from "../agents/context-window-guard.js";
import { OLLAMA_DEFAULT_BASE_URL } from "../agents/ollama-models.js";
import type { OpenClawConfig } from "../config/config.js"; import type { OpenClawConfig } from "../config/config.js";
import { defaultRuntime } from "../runtime.js"; import { defaultRuntime } from "../runtime.js";
import { import {
@@ -133,6 +134,23 @@ describe("promptCustomApiConfig", () => {
expect(result.config.agents?.defaults?.models?.["custom/llama3"]?.alias).toBe("local"); expect(result.config.agents?.defaults?.models?.["custom/llama3"]?.alias).toBe("local");
}); });
it("defaults custom onboarding to the native Ollama base URL", async () => {
const prompter = createTestPrompter({
text: ["http://localhost:11434", "", "llama3", "custom", ""],
select: ["plaintext", "openai"],
});
stubFetchSequence([{ ok: true }]);
await runPromptCustomApi(prompter);
expect(prompter.text).toHaveBeenCalledWith(
expect.objectContaining({
message: "API Base URL",
initialValue: OLLAMA_DEFAULT_BASE_URL,
}),
);
});
it("retries when verification fails", async () => { it("retries when verification fails", async () => {
const prompter = createTestPrompter({ const prompter = createTestPrompter({
text: ["http://localhost:11434/v1", "", "bad-model", "good-model", "custom", ""], text: ["http://localhost:11434/v1", "", "bad-model", "good-model", "custom", ""],

View File

@@ -1,6 +1,7 @@
import { CONTEXT_WINDOW_HARD_MIN_TOKENS } from "../agents/context-window-guard.js"; import { CONTEXT_WINDOW_HARD_MIN_TOKENS } from "../agents/context-window-guard.js";
import { DEFAULT_PROVIDER } from "../agents/defaults.js"; import { DEFAULT_PROVIDER } from "../agents/defaults.js";
import { buildModelAliasIndex, modelKey } from "../agents/model-selection.js"; import { buildModelAliasIndex, modelKey } from "../agents/model-selection.js";
import { OLLAMA_DEFAULT_BASE_URL } from "../agents/ollama-models.js";
import type { OpenClawConfig } from "../config/config.js"; import type { OpenClawConfig } from "../config/config.js";
import type { ModelProviderConfig } from "../config/types.models.js"; import type { ModelProviderConfig } from "../config/types.models.js";
import { isSecretRef, type SecretInput } from "../config/types.secrets.js"; import { isSecretRef, type SecretInput } from "../config/types.secrets.js";
@@ -16,7 +17,6 @@ import { applyPrimaryModel } from "./model-picker.js";
import { normalizeAlias } from "./models/shared.js"; import { normalizeAlias } from "./models/shared.js";
import type { SecretInputMode } from "./onboard-types.js"; import type { SecretInputMode } from "./onboard-types.js";
const DEFAULT_OLLAMA_BASE_URL = "http://127.0.0.1:11434/v1";
const DEFAULT_CONTEXT_WINDOW = CONTEXT_WINDOW_HARD_MIN_TOKENS; const DEFAULT_CONTEXT_WINDOW = CONTEXT_WINDOW_HARD_MIN_TOKENS;
const DEFAULT_MAX_TOKENS = 4096; const DEFAULT_MAX_TOKENS = 4096;
const VERIFY_TIMEOUT_MS = 30_000; const VERIFY_TIMEOUT_MS = 30_000;
@@ -389,7 +389,7 @@ async function promptBaseUrlAndKey(params: {
}): Promise<{ baseUrl: string; apiKey?: SecretInput; resolvedApiKey: string }> { }): Promise<{ baseUrl: string; apiKey?: SecretInput; resolvedApiKey: string }> {
const baseUrlInput = await params.prompter.text({ const baseUrlInput = await params.prompter.text({
message: "API Base URL", message: "API Base URL",
initialValue: params.initialBaseUrl ?? DEFAULT_OLLAMA_BASE_URL, initialValue: params.initialBaseUrl ?? OLLAMA_DEFAULT_BASE_URL,
placeholder: "https://api.example.com/v1", placeholder: "https://api.example.com/v1",
validate: (val) => { validate: (val) => {
try { try {