refactor: split providers commands

This commit is contained in:
Peter Steinberger
2026-01-08 06:46:40 +01:00
parent da9bc80bf2
commit 9b152ecb12
7 changed files with 1380 additions and 1180 deletions

View File

@@ -0,0 +1,47 @@
import {
type ClawdbotConfig,
readConfigFileSnapshot,
} from "../../config/config.js";
import {
type ChatProviderId,
getChatProviderMeta,
} from "../../providers/registry.js";
import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js";
import { defaultRuntime, type RuntimeEnv } from "../../runtime.js";
export type ChatProvider = ChatProviderId;
export async function requireValidConfig(
runtime: RuntimeEnv = defaultRuntime,
): Promise<ClawdbotConfig | null> {
const snapshot = await readConfigFileSnapshot();
if (snapshot.exists && !snapshot.valid) {
const issues =
snapshot.issues.length > 0
? snapshot.issues
.map((issue) => `- ${issue.path}: ${issue.message}`)
.join("\n")
: "Unknown validation issue.";
runtime.error(`Config invalid:\n${issues}`);
runtime.error("Fix the config or run clawdbot doctor.");
runtime.exit(1);
return null;
}
return snapshot.config;
}
export function formatAccountLabel(params: {
accountId: string;
name?: string;
}) {
const base = params.accountId || DEFAULT_ACCOUNT_ID;
if (params.name?.trim()) return `${base} (${params.name.trim()})`;
return base;
}
export const providerLabel = (provider: ChatProvider) =>
getChatProviderMeta(provider).label;
export function shouldUseWizard(params?: { hasFlags?: boolean }) {
return params?.hasFlags === false;
}