Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(updater): 修复被删除的恢复默认源按钮

kdgmpw9539d360573b
diff --git a/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py b/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py
index 56baab27b0..0162cb2137 100644
--- a/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py
+++ b/jiuwenswarm/gateway/channel_manager/web/app_web_handlers.py
@@ -83,7 +83,7 @@ from jiuwenswarm.server.runtime.a2ui.integration import (
validate_a2ui_config_update,
)
from jiuwenswarm.common.reasoning_injector import build_reasoning_model_request_kwargs
-from jiuwenswarm.common.updater import UpdaterService
+from jiuwenswarm.common.updater import DEFAULT_SOURCE_CONFIG, UpdaterService
from jiuwenswarm.common.utils import (
get_agent_sessions_dir,
get_env_file,
@@ -2409,6 +2409,18 @@ def _register_web_handlers(bind: WebHandlersBindParams) -> None:
service = updater_service or UpdaterService()
await channel.send_response(ws, req_id, ok=True, payload=service.get_runtime_config())
+ async def _updater_reset_source(ws, req_id, params, session_id):
+ try:
+ update_updater_in_config(dict(DEFAULT_SOURCE_CONFIG))
+ except Exception as exc: # noqa: BLE001
+ logger.warning("[updater.reset_source] 写回 config.yaml 失败: %s", exc)
+ await channel.send_response(ws, req_id, ok=False,
+ error=str(exc), code="INTERNAL_ERROR")
+ return
+
+ service = updater_service or UpdaterService()
+ await channel.send_response(ws, req_id, ok=True, payload=service.get_runtime_config())
+
async def _updater_set_conf(ws, req_id, params, session_id):
if not isinstance(params, dict):
await channel.send_response(ws, req_id, ok=False, error="params must be object", code="BAD_REQUEST")
@@ -5344,6 +5356,7 @@ def _register_web_handlers(bind: WebHandlersBindParams) -> None:
channel.register_method("updater.download", _updater_download)
channel.register_method("updater.upgrade", _updater_upgrade)
channel.register_method("updater.get_conf", _updater_get_conf)
+ channel.register_method("updater.reset_source", _updater_reset_source)
channel.register_method("updater.set_conf", _updater_set_conf)
channel.register_method("heartbeat.get_conf", _heartbeat_get_conf)
channel.register_method("heartbeat.set_conf", _heartbeat_set_conf)
diff --git a/tests/unit_tests/test_app_web_handlers.py b/tests/unit_tests/test_app_web_handlers.py
index a072fcc7b1..2c73c7d1c4 100644
--- a/tests/unit_tests/test_app_web_handlers.py
+++ b/tests/unit_tests/test_app_web_handlers.py
@@ -87,6 +87,11 @@ class FakeHeartbeatService:
return dict(self.config)
+class FakeUpdaterService:
+ def get_runtime_config(self):
+ return {"release_api_type": "gitcode", "release_api_url": ""}
+
+
@pytest.fixture
def cleared_openai_account_login_jobs():
with app_web_handlers._OPENAI_ACCOUNT_LOGIN_JOBS_LOCK:
@@ -178,6 +183,25 @@ async def test_openai_account_models_list_returns_refreshed_auth_status(
}
+async def test_updater_reset_source_registered_and_restores_defaults(monkeypatch):
+ captured: dict[str, object] = {}
+
+ def fake_update_updater_in_config(updates):
+ captured.update(updates)
+
+ monkeypatch.setattr(app_web_handlers, "update_updater_in_config", fake_update_updater_in_config)
+
+ channel = FakeWebChannel()
+ _register_web_handlers(WebHandlersBindParams(channel=channel, updater_service=FakeUpdaterService()))
+
+ await channel.methods["updater.reset_source"](object(), "req-reset", {}, "sess-1")
+
+ assert channel.responses[-1]["ok"] is True
+ assert channel.responses[-1]["payload"] == {"release_api_type": "gitcode", "release_api_url": ""}
+ assert captured == app_web_handlers.DEFAULT_SOURCE_CONFIG
+
+
@pytest.mark.asyncio
async def test_openai_account_logout_clears_pending_login_jobs(
monkeypatch,