xonecas.io
64875
Mc

mini-coder / commit 8141960

feat: wire custom providers into startup and model selection

Adds customModels and startupWarnings to AppState. init() now calls
discoverCustomProviders() and merges results into the available models
list. getAvailableModels() includes custom models alongside built-in ones.

Andy Nutter-Upham2026-04-10 81419604b65c454ba7c1861e1f5e0552b1605437 parent 0023906

2 files changed

src/index.test.ts+32−0
@@ -3,10 +3,12 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
33 import { tmpdir } from "node:os";
44 import { join } from "node:path";
55 import { pathToFileURL } from "node:url";
6+import type { Model } from "@mariozechner/pi-ai";
67 import {
78 type AppState,
89 didOAuthCredentialsChange,
910 discoverCustomProviders,
11+ getAvailableModels,
1012 loadOAuthCredentials,
1113 loadPromptContext,
1214 reloadPromptContext,
@@ -50,6 +52,8 @@ function createTestState(plugins: LoadedPlugin[] = []): AppState {
5052 activeTurnPromise: null,
5153 showReasoning: true,
5254 verbose: false,
55+ customModels: [],
56+ startupWarnings: [],
5357 };
5458 }
5559
@@ -412,3 +416,31 @@ test("discoverCustomProviders handles empty model list from endpoint", async ()
412416 server.stop(true);
413417 }
414418 });
419+
420+// ---------------------------------------------------------------------------
421+// getAvailableModels with custom models
422+// ---------------------------------------------------------------------------
423+
424+test("getAvailableModels includes custom models alongside built-in models", () => {
425+ const state = createTestState();
426+ try {
427+ const customModel: Model<"openai-completions"> = {
428+ id: "gemma4:31b",
429+ name: "gemma4:31b",
430+ api: "openai-completions",
431+ provider: "ollama",
432+ baseUrl: "http://localhost:11434/v1",
433+ reasoning: false,
434+ input: ["text"],
435+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
436+ contextWindow: 131072,
437+ maxTokens: 8192,
438+ };
439+ state.customModels = [customModel];
440+
441+ const models = getAvailableModels(state);
442+ expect(models).toContainEqual(customModel);
443+ } finally {
444+ state.db.close();
445+ }
446+});
src/index.ts+22−2
@@ -559,6 +559,10 @@ export interface AppState {
559559 showReasoning: boolean;
560560 /** Whether to show full (un-truncated) tool output. */
561561 verbose: boolean;
562+ /** Models discovered from custom OpenAI-compatible providers. */
563+ customModels: Model<string>[];
564+ /** Warnings from startup (e.g. unreachable custom providers). */
565+ startupWarnings: string[];
562566 }
563567
564568 // ---------------------------------------------------------------------------
@@ -577,7 +581,21 @@ export async function init(): Promise<AppState> {
577581
578582 // Load user settings and resolve startup defaults
579583 const settings = loadSettings(SETTINGS_PATH);
580- const availableModels = listAvailableModels(providers);
584+
585+ // Discover custom providers from settings
586+ const builtInProviderNames = new Set(providers.keys());
587+ const customResult = await discoverCustomProviders(
588+ settings.customProviders ?? [],
589+ builtInProviderNames,
590+ );
591+
592+ // Merge custom provider credentials
593+ for (const [name, key] of customResult.providers) {
594+ providers.set(name, key);
595+ }
596+
597+ const builtInModels = listAvailableModels(providers);
598+ const availableModels = [...builtInModels, ...customResult.models];
581599 const startup = resolveStartupSettings(
582600 settings,
583601 availableModels.map((model) => `${model.provider}/${model.id}`),
@@ -616,6 +634,8 @@ export async function init(): Promise<AppState> {
616634 activeTurnPromise: null,
617635 showReasoning: startup.showReasoning,
618636 verbose: startup.verbose,
637+ customModels: customResult.models,
638+ startupWarnings: customResult.warnings,
619639 };
620640 }
621641
@@ -688,7 +708,7 @@ export function ensureSession(
688708 * for, suitable for the `/model` selector.
689709 */
690710 export function getAvailableModels(state: AppState): Model<string>[] {
691- return listAvailableModels(state.providers);
711+ return [...listAvailableModels(state.providers), ...state.customModels];
692712 }
693713
694714 /** Clean up resources on shutdown. */