mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:28:26 +00:00
refactor: split providers commands
This commit is contained in:
47
src/commands/providers/shared.ts
Normal file
47
src/commands/providers/shared.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user