fix(providers): model list empty in settings panel (#581) (#591)

Co-authored-by: Kagura Chen <daniyuu19@sjtu.edu.cn>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kagura
2026-03-21 15:35:30 +08:00
committed by GitHub
Unverified
parent 5e519f9aa6
commit 5836ba6b13
3 changed files with 295 additions and 7 deletions

View File

@@ -747,6 +747,42 @@ export async function getActiveOpenClawProviders(): Promise<Set<string>> {
return activeProviders;
}
/**
* Read models.providers entries and agents.defaults.model from openclaw.json.
* Used by ClawX to seed the provider store when it's empty but providers are
* configured externally (e.g. via CLI or by editing openclaw.json directly).
*/
export async function getOpenClawProvidersConfig(): Promise<{
providers: Record<string, Record<string, unknown>>;
defaultModel: string | undefined;
}> {
try {
const config = await readOpenClawJson();
const models = config.models as Record<string, unknown> | undefined;
const providers =
models?.providers && typeof models.providers === 'object'
? (models.providers as Record<string, Record<string, unknown>>)
: {};
const agents = config.agents as Record<string, unknown> | undefined;
const defaults =
agents?.defaults && typeof agents.defaults === 'object'
? (agents.defaults as Record<string, unknown>)
: undefined;
const modelConfig =
defaults?.model && typeof defaults.model === 'object'
? (defaults.model as Record<string, unknown>)
: undefined;
const defaultModel =
typeof modelConfig?.primary === 'string' ? modelConfig.primary : undefined;
return { providers, defaultModel };
} catch {
return { providers: {}, defaultModel: undefined };
}
}
/**
* Write the ClawX gateway token into ~/.openclaw/openclaw.json.
*/