fix(webui): activate existing model presets safely

This commit is contained in:
Xubin Ren
2026-09-02 16:25:07 +08:00
parent 7ba4bc02f0
commit da96c5c6eb
3 changed files with 43 additions and 8 deletions
+5 -1
View File
@@ -269,7 +269,11 @@ def update_model_call_order(
config_path: Path | None = None,
) -> dict[str, Any]:
config = _load_settings_config(config_path)
if models.update_model_call_order(config, query):
if models.update_model_call_order(
config,
query,
oauth_status=_oauth_provider_status,
):
_save_settings_config(config, config_path)
return settings_payload(config_path=config_path)
+11 -5
View File
@@ -1312,7 +1312,12 @@ def update_model_configuration(
return changed
def update_model_call_order(config: Config, query: QueryParams) -> bool:
def update_model_call_order(
config: Config,
query: QueryParams,
*,
oauth_status: OAuthStatusReader,
) -> bool:
raw_order = query_first_alias(query, "order", "presetNames")
if raw_order is None:
raise WebUISettingsError("model call order is required")
@@ -1331,15 +1336,16 @@ def update_model_call_order(config: Config, query: QueryParams) -> bool:
raise WebUISettingsError("model call order must contain at least one preset")
normalized_order = [cast(str, name).strip() for name in cast(list[object], order)]
unknown = [name for name in normalized_order if name not in config.model_presets]
if unknown:
raise WebUISettingsError(f"unknown model preset: {unknown[0]}")
_, editable = _model_call_order_state(config)
if not editable:
if not editable and _legacy_model_configuration_migratable(config, oauth_status):
raise WebUISettingsError(
"convert the existing model configuration to presets first",
status=409,
)
unknown = [name for name in normalized_order if name not in config.model_presets]
if unknown:
raise WebUISettingsError(f"unknown model preset: {unknown[0]}")
defaults = config.agents.defaults
fallback_models: list[FallbackCandidate] = list(normalized_order[1:])