refactor: remove redundant model picker conversions

This commit is contained in:
Peter Steinberger
2026-04-10 21:57:01 +01:00
parent fdaebf587c
commit fc50e23262

View File

@@ -99,7 +99,7 @@ function resolveConfiguredModelRaw(cfg: OpenClawConfig): string {
function resolveConfiguredModelKeys(cfg: OpenClawConfig): string[] {
const models = cfg.agents?.defaults?.models ?? {};
return Object.keys(models)
.map((key) => String(key ?? "").trim())
.map((key) => key.trim())
.filter((key) => key.length > 0);
}
@@ -107,7 +107,7 @@ function normalizeModelKeys(values: string[]): string[] {
const seen = new Set<string>();
const next: string[] = [];
for (const raw of values) {
const value = String(raw ?? "").trim();
const value = raw.trim();
if (!value || seen.has(value)) {
continue;
}
@@ -226,7 +226,7 @@ async function promptManualModel(params: {
? undefined
: (value) => (normalizeOptionalString(value) ? undefined : "Required"),
});
const model = String(modelInput ?? "").trim();
const model = (modelInput ?? "").trim();
if (!model) {
return {};
}
@@ -532,10 +532,11 @@ export async function promptDefaultModel(
options,
initialValue,
});
if (selection === KEEP_VALUE) {
const selectedValue = selection ?? "";
if (selectedValue === KEEP_VALUE) {
return {};
}
if (selection === MANUAL_VALUE) {
if (selectedValue === MANUAL_VALUE) {
return promptManualModel({
prompter: params.prompter,
allowBlank: false,
@@ -544,7 +545,7 @@ export async function promptDefaultModel(
}
const providerPluginResult = await maybeHandleProviderPluginSelection({
selection: String(selection),
selection: selectedValue,
cfg,
prompter: params.prompter,
agentDir: params.agentDir,
@@ -556,7 +557,7 @@ export async function promptDefaultModel(
return providerPluginResult;
}
const model = String(selection);
const model = selectedValue;
const { runProviderModelSelectedHook } = await loadResolvedModelPickerRuntime();
await runProviderModelSelectedHook({
config: cfg,
@@ -610,7 +611,7 @@ export async function promptModelAllowlist(params: {
initialValue: existingKeys.join(", "),
placeholder: "provider/model, other-provider/model",
});
const parsed = String(raw ?? "")
const parsed = (raw ?? "")
.split(",")
.map((value) => value.trim())
.filter((value) => value.length > 0);
@@ -668,7 +669,7 @@ export async function promptModelAllowlist(params: {
initialValues: initialKeys.length > 0 ? initialKeys : undefined,
searchable: true,
});
const selected = normalizeModelKeys(selection.map((value) => String(value)));
const selected = normalizeModelKeys(selection);
if (selected.length > 0) {
return { models: selected };
}