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

revert(ee): drop channel_config DB overlay from manager_ws_client

yechenzhen41592ce332d1
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/__init__.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/__init__.py
index 5f2dbccbcb..b86653a022 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/__init__.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/__init__.py
@@ -1,5 +1,3 @@
-from .channel_config import apply_channel_config
-
from .log_masking_rule import apply_log_masking_rule
from .logging_config import apply_logging_config
@@ -10,7 +8,6 @@ from .permissions_config import apply_permissions_config
from .memory_config import apply_memory_config
__all__ = (
- "apply_channel_config",
"apply_log_masking_rule",
"apply_logging_config",
"apply_task_memory_config",
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/channel_config.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/channel_config.py
deleted file mode 100644
index 8f03171d6c..0000000000
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/application_config/channel_config.py
+++ /dev/null
@@ -1,208 +0,0 @@
-# Copyright (c) Huawei Technologies Co., Ltd. 2026-2026. All rights reserved
-
-"""Channel 配置 WebSocket 同步:将 Claw Manager 下发的 channel_config 写入 Gateway 本地库。"""
-
-from __future__ import annotations
-
-import logging
-from typing import Any
-
-from openjiuwen_runtime.foundation.db.handler import DBHandler
-
-from jiuwenclaw.gateway.channel_config_reload import (
- channel_config_reload_change_for_row,
- maybe_trigger_channel_config_reload,
-)
-from jiuwenclaw.gateway.channel_config_overlay import ChannelConfigChange
-
-from ...infrastructure.utils import format_ts, get_jiuwenclaw_id, utc_now
-from ...models.application_config_models import CHANNEL_CONFIG_TABLE_DEF
-from ...schemas.application_config_schemas import ChannelConfigCreateRequest
-from ...infrastructure.db import ensure_db_handler
-
-_TABLE = CHANNEL_CONFIG_TABLE_DEF.table_name
-logger = logging.getLogger(__name__)
-
-
-def _channel_row_to_dict(obj: Any) -> dict[str, Any]:
- raw_cfg = getattr(obj, "config", None)
- config = dict(raw_cfg) if isinstance(raw_cfg, dict) else raw_cfg
- return {
- "id": getattr(obj, "id"),
- "jiuwenclaw_id": getattr(obj, "jiuwenclaw_id"),
- "channel_id": getattr(obj, "channel_id"),
- "channel_name": getattr(obj, "channel_name"),
- "channel_type": getattr(obj, "channel_type"),
- "bot_id": getattr(obj, "bot_id"),
- "config": config,
- "status": str(getattr(obj, "status")),
- "created_at": format_ts(getattr(obj, "created_at", None)),
- "updated_at": format_ts(getattr(obj, "updated_at", None)),
- }
-
-
-def _instance_filters(
- jiuwenclaw_id: str,
- channel_id: str | None = None,
-) -> dict[str, Any]:
- filters: dict[str, Any] = {"jiuwenclaw_id": jiuwenclaw_id}
- if channel_id is not None:
- filters["channel_id"] = channel_id
- return filters
-
-
-async def _create_channel_config_record(
- handler: DBHandler,
- request: ChannelConfigCreateRequest,
- *,
- jiuwenclaw_id: str,
-) -> dict[str, Any]:
- dup = await handler.get(_TABLE, _instance_filters(jiuwenclaw_id, request.channel_id))
- if dup is not None:
- raise ValueError("channel_id already exists")
- now = utc_now()
- row_data: dict[str, Any] = {
- "jiuwenclaw_id": jiuwenclaw_id,
- "channel_id": request.channel_id,
- "channel_name": request.channel_name,
- "channel_type": request.channel_type,
- "bot_id": request.bot_id,
- "config": request.config,
- "status": request.status,
- "created_at": now,
- "updated_at": now,
- }
- record = await handler.create(_TABLE, row_data)
- return _channel_row_to_dict(record)
-
-
-async def _get_channel_config_record(
- handler: DBHandler,
- channel_id: str,
- *,
- jiuwenclaw_id: str,
-) -> dict[str, Any] | None:
- row = await handler.get(_TABLE, _instance_filters(jiuwenclaw_id, channel_id))
- if row is None:
- return None
- return _channel_row_to_dict(row)
-
-
-async def _set_channel_status(
- handler: DBHandler,
- channel_id: str,
- target_status: str,
- *,
- jiuwenclaw_id: str,
-) -> dict[str, Any] | None:
- row = await handler.get(_TABLE, _instance_filters(jiuwenclaw_id, channel_id))
- if row is None:
- return None
- now = utc_now()
- updated = await handler.update(
- _TABLE,
- _instance_filters(jiuwenclaw_id, channel_id),
- {"status": target_status, "updated_at": now},
- )
- if updated is None:
- return None
- return _channel_row_to_dict(updated)
-
-
-async def _delete_channel_config_record(
- handler: DBHandler,
- channel_id: str,
- *,
- jiuwenclaw_id: str,
-) -> bool:
- return await handler.delete(_TABLE, _instance_filters(jiuwenclaw_id, channel_id))
-
-
-async def list_active_channel_config_rows(handler: DBHandler) -> list[dict[str, Any]]:
- """冷启动全量:返回当前实例 ``status=active`` 的 ``channel_config`` 行。"""
- jiuwenclaw_id = get_jiuwenclaw_id() or ""
- if not jiuwenclaw_id:
- return []
-
- rows = await handler.list_records(_TABLE, {"jiuwenclaw_id": jiuwenclaw_id})
- result: list[dict[str, Any]] = []
- for row in rows:
- record = _channel_row_to_dict(row)
- if str(record.get("status") or "").strip().lower() == "active":
- result.append(record)
- return result
-
-
-async def apply_channel_config(payload: dict[str, Any]) -> dict[str, Any] | None:
- """应用 Claw Manager 经 WebSocket 下发的 channel_config 变更。"""
- op = str(payload.get("op") or "").strip()
- if not op:
- raise ValueError("channel_config.op is required")
-
- jiuwenclaw_id = get_jiuwenclaw_id() or ""
- if not jiuwenclaw_id:
- raise ValueError("jiuwenclaw_id is not set")
-
- handler = await ensure_db_handler()
-
- if op == "create":
- channel = payload.get("channel")
- if not isinstance(channel, dict):
- raise ValueError("channel_config.create requires channel object")
- req = ChannelConfigCreateRequest.model_validate(channel)
- row = await _create_channel_config_record(handler, req, jiuwenclaw_id=jiuwenclaw_id)
- await maybe_trigger_channel_config_reload(
- channel_config_reload_change_for_row(row)
- )
- result: dict[str, Any] | None = {"channel_id": row["channel_id"]}
-
- elif op == "activate":
- channel_id = str(payload.get("channel_id") or "").strip()
- if not channel_id:
- raise ValueError("channel_config.activate requires channel_id")
- row = await _set_channel_status(
- handler, channel_id, "active", jiuwenclaw_id=jiuwenclaw_id
- )
- if row is None:
- raise ValueError(f"channel id={channel_id!r} not found")
- await maybe_trigger_channel_config_reload(ChannelConfigChange.upsert(row))
- result = {"channel_id": row["channel_id"], "status": row["status"]}
-
- elif op == "deactivate":
- channel_id = str(payload.get("channel_id") or "").strip()
- if not channel_id:
- raise ValueError("channel_config.deactivate requires channel_id")
- row = await _set_channel_status(
- handler, channel_id, "inactive", jiuwenclaw_id=jiuwenclaw_id
- )
- if row is None:
- raise ValueError(f"channel id={channel_id!r} not found")
- await maybe_trigger_channel_config_reload(ChannelConfigChange.remove(row))
- result = {"channel_id": row["channel_id"], "status": row["status"]}
-
- elif op == "delete":
- channel_id = str(payload.get("channel_id") or "").strip()
- if not channel_id:
- raise ValueError("channel_config.delete requires channel_id")
- row = await _get_channel_config_record(
- handler, channel_id, jiuwenclaw_id=jiuwenclaw_id
- )
- deleted = await _delete_channel_config_record(
- handler, channel_id, jiuwenclaw_id=jiuwenclaw_id
- )
- if not deleted:
- raise ValueError(f"channel id={channel_id!r} not found")
- if row is not None:
- await maybe_trigger_channel_config_reload(ChannelConfigChange.remove(row))
- result = None
-
- else:
- raise ValueError(f"unsupported channel_config.op: {op!r}")
-
- logger.info(
- "[ManagerWsClient] channel_config sync op=%s jiuwenclaw_id=%s channel_id=%s",
- op,
- jiuwenclaw_id,
- (result or {}).get("channel_id") or payload.get("channel_id"),
- )
- return result
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/instance/instance_data_lifecycle.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/instance/instance_data_lifecycle.py
index cc5d392918..9c60a14d9f 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/instance/instance_data_lifecycle.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/core/instance/instance_data_lifecycle.py
@@ -28,7 +28,6 @@ INSTANCE_PURGE_TABLES: tuple[str, ...] = (
"config_effective_agent_policy",
"config_default_template_mapping",
"log_masking_rule",
- "channel_config",
"logging_config",
"task_memory_config",
"permissions_config",
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/application_config_models.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/application_config_models.py
index 1669640234..4dd162f136 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/application_config_models.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/application_config_models.py
@@ -7,31 +7,6 @@ from openjiuwen_runtime.foundation.db.table_def import (
TableDefinition,
)
-CHANNEL_CONFIG_TABLE_DEF = TableDefinition(
- table_name="channel_config",
- columns=[
- ColumnDefinition(
- "id",
- "integer",
- primary_key=True,
- autoincrement=True,
- nullable=False,
- ),
- ColumnDefinition("jiuwenclaw_id", "string", length=64, nullable=False),
- ColumnDefinition("channel_id", "string", length=64, nullable=False),
- ColumnDefinition("channel_name", "string", length=128, nullable=False),
- ColumnDefinition("channel_type", "string", length=32, nullable=False),
- ColumnDefinition("bot_id", "string", length=64, nullable=False),
- ColumnDefinition("config", "json", nullable=True),
- ColumnDefinition("status", "string", length=32, nullable=False),
- ColumnDefinition("created_at", "datetime", nullable=False),
- ColumnDefinition("updated_at", "datetime", nullable=False),
- ],
- indexes=[
- IndexDefinition(["jiuwenclaw_id", "channel_id"], unique=True),
- ],
-)
-
LOG_MASKING_RULE_TABLE_DEF = TableDefinition(
table_name="log_masking_rule",
columns=[
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/table_init.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/table_init.py
index f3717f4a82..845c14686a 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/table_init.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/models/table_init.py
@@ -9,7 +9,6 @@ from openjiuwen_runtime.foundation.db.handler import DBHandler
from openjiuwen_runtime.foundation.db.table_def import TableDefinition
from .application_config_models import (
- CHANNEL_CONFIG_TABLE_DEF,
LOG_MASKING_RULE_TABLE_DEF,
LOGGING_CONFIG_TABLE_DEF,
TASK_MEMORY_CONFIG_TABLE_DEF,
@@ -45,7 +44,6 @@ ALL_TABLE_DEFINITIONS: tuple[TableDefinition, ...] = (
EXTENSION_CONFIG_TEMPLATE_TABLE_DEF,
SKILL_WHITELIST_TEMPLATE_TABLE_DEF,
SERVICE_CONFIG_TEMPLATE_TABLE_DEF,
- CHANNEL_CONFIG_TABLE_DEF,
LOG_MASKING_RULE_TABLE_DEF,
LOGGING_CONFIG_TABLE_DEF,
TASK_MEMORY_CONFIG_TABLE_DEF,
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/routers/manager_ws_client_router.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/routers/manager_ws_client_router.py
index fb84124489..93f6d05a59 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/routers/manager_ws_client_router.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/routers/manager_ws_client_router.py
@@ -6,7 +6,6 @@ from __future__ import annotations
import logging
from typing import Any
-from ..core.application_config.channel_config import apply_channel_config
from ..core.application_config.log_masking_rule import apply_log_masking_rule
from ..core.application_config.logging_config import apply_logging_config
from ..core.application_config.task_memory_config import apply_task_memory_config
@@ -82,7 +81,6 @@ async def apply_config_push(
result: dict[str, Any] | None = None
skip_runtime_update = False
- channel_config = config.get("channel_config")
log_masking_rule = config.get("log_masking_rule")
logging_config = config.get("logging_config")
task_memory_config = config.get("task_memory_config")
@@ -104,11 +102,6 @@ async def apply_config_push(
skip_runtime_update = True
result = await apply_instance_data_lifecycle(instance_data_lifecycle)
- elif isinstance(channel_config, dict) and channel_config.get("op"):
- matched_payload = channel_config
- skip_runtime_update = True
- result = await apply_channel_config(channel_config)
-
elif isinstance(log_masking_rule, dict) and log_masking_rule.get("op"):
matched_payload = log_masking_rule
result = await apply_log_masking_rule(log_masking_rule)
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/schemas/application_config_schemas.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/schemas/application_config_schemas.py
index bfe3db439d..4c1b0e148c 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/schemas/application_config_schemas.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_ws_client/schemas/application_config_schemas.py
@@ -2,24 +2,11 @@
from __future__ import annotations
-from typing import Any, Literal
+from typing import Any
from pydantic import BaseModel, ConfigDict, Field
-class ChannelConfigCreateRequest(BaseModel):
- """创建渠道配置(WS ``channel_config.create`` 的 ``channel`` 对象)。"""
-
- model_config = ConfigDict(str_strip_whitespace=True)
-
- channel_id: str = Field(..., min_length=1)
- channel_name: str = Field(..., min_length=1)
- channel_type: str = Field(..., min_length=1)
- bot_id: str = Field(..., min_length=1)
- config: dict[str, Any] | None = None
- status: Literal["active", "inactive"] = "active"
-
-
class LogMaskingRuleCreateRequest(BaseModel):
"""创建日志脱敏规则(WS ``log_masking_rule.create`` 的 ``rule`` 对象)。"""