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

update: config

douran3a237b955ad2
diff --git a/jiuwenclaw/app.py b/jiuwenclaw/app.py
index f0fe3bbca4..4f2f92bfe1 100644
--- a/jiuwenclaw/app.py
+++ b/jiuwenclaw/app.py
@@ -58,10 +58,13 @@ from jiuwenclaw.utils import (
)
from jiuwenclaw.config import (
get_config,
+ get_config_raw,
update_heartbeat_in_config,
update_channel_in_config,
update_browser_in_config,
update_preferred_language_in_config,
+ update_context_engine_enabled_in_config,
+ update_permissions_enabled_in_config,
)
_PROJECT_ROOT = get_root_dir()
@@ -169,6 +172,9 @@ _CONFIG_SET_ENV_MAP = {
# 配置项键名列表,用于日志等说明
CONFIG_KEYS = tuple(_CONFIG_SET_ENV_MAP.keys())
+# 来自 config.yaml 的配置项(前端 param 名 -> config.yaml 路径)
+_CONFIG_YAML_KEYS = frozenset({"context_engine_enabled", "permissions_enabled"})
+
def _clear_agent_config_cache() -> None:
"""写回 config.yaml 后清除 agent 侧配置缓存,使下次读取时得到最新文件内容。"""
@@ -261,6 +267,16 @@ def _register_web_handlers(
param_key: (os.getenv(env_key) or "")
for param_key, env_key in _CONFIG_SET_ENV_MAP.items()
}
+ # 合并 config.yaml 中的配置项
+ try:
+ raw = get_config_raw()
+ ctx_cfg = (raw.get("react") or {}).get("context_engine_config") or {}
+ payload["context_engine_enabled"] = "true" if ctx_cfg.get("enabled", False) else "false"
+ perm_cfg = raw.get("permissions") or {}
+ payload["permissions_enabled"] = "true" if perm_cfg.get("enabled", False) else "false"
+ except Exception: # noqa: BLE001
+ payload.setdefault("context_engine_enabled", "false")
+ payload.setdefault("permissions_enabled", "false")
await channel.send_response(ws, req_id, ok=True, payload=payload)
def _persist_env_updates(updates: dict[str, str]) -> None:
@@ -295,39 +311,63 @@ def _register_web_handlers(
logger.warning("[config.set] 写回 .env 失败: %s", e)
async def _config_set(ws, req_id, params, session_id):
- """根据前端消息内容更新配置(仅允许 _CONFIG_SET_ENV_MAP 中的键),并写回 .env。"""
+ """根据前端消息内容更新配置(支持 .env 与 config.yaml 中的键),并写回对应文件。"""
if not isinstance(params, dict):
await channel.send_response(ws, req_id, ok=False, error="params must be object", code="BAD_REQUEST")
return
- updates: dict[str, str] = {}
+ env_updates: dict[str, str] = {}
+ yaml_updated: list[str] = []
available_model_providers = [provider.value for provider in ProviderType]
+
for param_key, env_key in _CONFIG_SET_ENV_MAP.items():
if param_key not in params:
continue
val = params[param_key]
if param_key.endswith("_provider") and val and val not in available_model_providers:
await channel.send_response(
- ws, req_id, ok=False,
- error=f"Model provider must in: {available_model_providers} ",
+ ws, req_id, ok=False,
+ error=f"Model provider must in: {available_model_providers} ",
code="BAD_REQUEST"
)
return
if val is None:
- updates[env_key] = ""
+ env_updates[env_key] = ""
else:
- updates[env_key] = str(val).strip()
- for env_key, value in updates.items():
+ env_updates[env_key] = str(val).strip()
+
+ for param_key in _CONFIG_YAML_KEYS:
+ if param_key not in params:
+ continue
+ val = params[param_key]
+ parsed = str(val).strip().lower() in ("true", "1", "yes")
+ try:
+ if param_key == "context_engine_enabled":
+ update_context_engine_enabled_in_config(parsed)
+ elif param_key == "permissions_enabled":
+ update_permissions_enabled_in_config(parsed)
+ yaml_updated.append(param_key)
+ except Exception as e: # noqa: BLE001
+ logger.warning("[config.set] 写回 config.yaml 失败 %s: %s", param_key, e)
+
+ for env_key, value in env_updates.items():
os.environ[env_key] = value
applied_without_restart = True
- if updates:
- _persist_env_updates(updates)
- logger.info("[config.set] 已更新: %s", list(updates.keys()))
+
+ if env_updates:
+ _persist_env_updates(env_updates)
+ logger.info("[config.set] 已更新 .env: %s", list(env_updates.keys()))
+ if yaml_updated:
+ _clear_agent_config_cache()
+ logger.info("[config.set] 已更新 config.yaml: %s", yaml_updated)
+
+ if env_updates or yaml_updated:
if on_config_saved:
- callback_result = on_config_saved(set(updates.keys()))
+ callback_result = on_config_saved(set(env_updates.keys()) | set(yaml_updated))
if inspect.isawaitable(callback_result):
callback_result = await callback_result
applied_without_restart = bool(callback_result)
- updated_param_keys = [k for k, e in _CONFIG_SET_ENV_MAP.items() if e in updates]
+
+ updated_param_keys = [k for k, e in _CONFIG_SET_ENV_MAP.items() if e in env_updates] + yaml_updated
await channel.send_response(
ws, req_id, ok=True,
payload={"updated": updated_param_keys, "applied_without_restart": applied_without_restart},
diff --git a/jiuwenclaw/config.py b/jiuwenclaw/config.py
index d1662059d3..688d217a9f 100644
--- a/jiuwenclaw/config.py
+++ b/jiuwenclaw/config.py
@@ -149,4 +149,25 @@ def update_browser_in_config(updates: dict[str, Any]) -> None:
section = data["browser"]
for k, v in updates.items():
section[k] = v
+ _dump_yaml_round_trip(_CONFIG_YAML_PATH, data)
+
+
+def update_context_engine_enabled_in_config(value: bool) -> None:
+ """更新 react.context_engine_config.enabled(上下文压缩开关)并写回。"""
+ data = _load_yaml_round_trip(_CONFIG_YAML_PATH)
+ if "react" not in data:
+ data["react"] = {}
+ react = data["react"]
+ if "context_engine_config" not in react:
+ react["context_engine_config"] = {}
+ react["context_engine_config"]["enabled"] = value
+ _dump_yaml_round_trip(_CONFIG_YAML_PATH, data)
+
+
+def update_permissions_enabled_in_config(value: bool) -> None:
+ """更新 permissions.enabled(工具安全护栏开关)并写回。"""
+ data = _load_yaml_round_trip(_CONFIG_YAML_PATH)
+ if "permissions" not in data:
+ data["permissions"] = {}
+ data["permissions"]["enabled"] = value
_dump_yaml_round_trip(_CONFIG_YAML_PATH, data)
\ No newline at end of file
diff --git a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
index b8fbd612a7..00a80445fc 100644
--- a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx
@@ -40,6 +40,8 @@ function classifyKey(key: string): string {
if (THIRD_PARTY_API_KEYS.has(key)) return "third_party_api";
if (EMAIL_KEYS.has(key)) return "email";
if (EVOLUTION_KEYS.has(key)) return "evolution";
+ if (key === "context_engine_enabled") return "context_engine";
+ if (key === "permissions_enabled") return "permissions";
if (key.startsWith("feishu")) return "feishu";
return "other";
}
@@ -86,6 +88,20 @@ function getGroupIcon(tag: string) {
</svg>
);
}
+ if (tag === "context_engine") {
+ return (
+ <svg className="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={1.8}>
+ <path strokeLinecap="round" strokeLinejoin="round" d="M3.75 3v11.25A2.25 2.25 0 006 16.5h2.25M3.75 3h-1.5m1.5 0h16.5m0 0h1.5m-1.5 0v11.25A2.25 2.25 0 0118 16.5h-2.25m-7.5 0h7.5m-7.5 0l-1 3m8.5-3l1 3m0 0l.5 1.5m-.5-1.5h-9.5m0 0l-.5 1.5" />
+ </svg>
+ );
+ }
+ if (tag === "permissions") {
+ return (
+ <svg className="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={1.8}>
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z" />
+ </svg>
+ );
+ }
return (
<svg className="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={1.8}>
<path strokeLinecap="round" strokeLinejoin="round" d="M11.25 6h9m-9 6h9m-9 6h9M3.75 6h.008v.008H3.75V6zm0 6h.008v.008H3.75V12zm0 6h.008v.008H3.75V18z" />
@@ -101,6 +117,8 @@ function getGroupToneClass(tag: string): string {
if (tag === "embed") return "text-cyan-500 bg-cyan-500/10 border-cyan-500/20";
if (tag === "third_party_api") return "text-indigo-500 bg-indigo-500/10 border-indigo-500/20";
if (tag === "evolution") return "text-amber-500 bg-amber-500/10 border-amber-500/20";
+ if (tag === "context_engine") return "text-sky-500 bg-sky-500/10 border-sky-500/20";
+ if (tag === "permissions") return "text-rose-500 bg-rose-500/10 border-rose-500/20";
if (tag === "email") return "text-emerald-500 bg-emerald-500/10 border-emerald-500/20";
return "text-text-muted bg-secondary/70 border-border";
}
@@ -111,11 +129,13 @@ function getNestedModelStyle(tag: string): string {
if (tag === "model_video") return "border-l-2 border-l-violet-500/60 bg-violet-500/[0.06]";
if (tag === "model_audio") return "border-l-2 border-l-orange-500/60 bg-orange-500/[0.06]";
if (tag === "model_vision") return "border-l-2 border-l-teal-500/60 bg-teal-500/[0.06]";
+ if (tag === "context_engine") return "border-l-2 border-l-sky-500/60 bg-sky-500/[0.06]";
+ if (tag === "permissions") return "border-l-2 border-l-rose-500/60 bg-rose-500/[0.06]";
return "border-l-2 border-l-border bg-secondary/20";
}
function isBooleanKey(key: string): boolean {
- return EVOLUTION_KEYS.has(key);
+ return EVOLUTION_KEYS.has(key) || key === "context_engine_enabled" || key === "permissions_enabled";
}
function parseBoolValue(value: string): boolean {
@@ -124,6 +144,8 @@ function parseBoolValue(value: string): boolean {
const BOOL_KEY_LABELS: Record<string, string> = {
evolution_auto_scan: "自动检测可演进信号",
+ context_engine_enabled: "启用",
+ permissions_enabled: "启用",
};
function isSensitiveKey(key: string): boolean {
@@ -157,8 +179,10 @@ function getGroupMeta(t: (key: string) => string): Record<string, { label: strin
embed: { label: t('config.groups.embed.label'), order: 4, hint: t('config.groups.embed.hint') },
third_party_api: { label: t('config.groups.thirdParty.label'), order: 5, hint: t('config.groups.thirdParty.hint') },
evolution: { label: t('config.groups.evolution.label'), order: 6, hint: t('config.groups.evolution.hint') },
- email: { label: t('config.groups.email.label'), order: 7, hint: t('config.groups.email.hint') },
- other: { label: t('config.groups.other.label'), order: 8, hint: t('config.groups.other.hint') },
+ context_engine: { label: t('config.groups.contextEngine.label'), order: 7, hint: t('config.groups.contextEngine.hint') },
+ permissions: { label: t('config.groups.permissions.label'), order: 8, hint: t('config.groups.permissions.hint') },
+ email: { label: t('config.groups.email.label'), order: 9, hint: t('config.groups.email.hint') },
+ other: { label: t('config.groups.other.label'), order: 10, hint: t('config.groups.other.hint') },
};
}
@@ -173,7 +197,8 @@ function isProviderKey(key: string): boolean {
/** 表格列显示用:video_api_base -> api_base,避免与分组标题重复 */
function getKeyDisplayLabel(key: string): string {
const m = key.match(/^(video|audio|vision)_(.+)$/);
- return m ? m[2] : key;
+ if (m) return m[2];
+ return BOOL_KEY_LABELS[key] ?? key;
}
function GroupSection({
diff --git a/jiuwenclaw/web/src/components/LogsPanel/index.tsx b/jiuwenclaw/web/src/components/LogsPanel/index.tsx
index 4d42bcaaff..697c384610 100644
--- a/jiuwenclaw/web/src/components/LogsPanel/index.tsx
+++ b/jiuwenclaw/web/src/components/LogsPanel/index.tsx
@@ -65,7 +65,7 @@ export function LogsPanel({ isConnected: _isConnected }: LogsPanelProps) {
const fetchLogs = useCallback(async () => {
setLoading(true);
try {
- const filePath = encodeURIComponent('logs/ws-dev.log');
+ const filePath = encodeURIComponent('.logs/ws-dev.log');
const response = await fetch(`/file-api/file-content?path=${filePath}`);
if (!response.ok) {
const detail = await response.text();
diff --git a/jiuwenclaw/web/src/i18n/locales/en.json b/jiuwenclaw/web/src/i18n/locales/en.json
index 3567a404c0..73f29c4030 100644
--- a/jiuwenclaw/web/src/i18n/locales/en.json
+++ b/jiuwenclaw/web/src/i18n/locales/en.json
@@ -332,6 +332,8 @@
"embed": { "label": "Embed Configuration", "hint": "Embed service and authentication settings" },
"thirdParty": { "label": "Third-Party Services", "hint": "API key settings" },
"evolution": { "label": "Evolution Settings", "hint": "Online skill evolution settings" },
+ "contextEngine": { "label": "Context Compression", "hint": "Enable or disable dialogue context compression" },
+ "permissions": { "label": "Tool Safety Guardrail", "hint": "Enable or disable permission checks for tool calls" },
"email": { "label": "Email Settings", "hint": "Email account and token settings" },
"other": { "label": "Other Settings", "hint": "Unclassified extended parameters" }
},
diff --git a/jiuwenclaw/web/src/i18n/locales/zh.json b/jiuwenclaw/web/src/i18n/locales/zh.json
index 4524307afc..dc68865ba2 100644
--- a/jiuwenclaw/web/src/i18n/locales/zh.json
+++ b/jiuwenclaw/web/src/i18n/locales/zh.json
@@ -332,6 +332,8 @@
"embed": { "label": "Embed配置", "hint": "Embed 服务与鉴权参数" },
"thirdParty": { "label": "第三方服务配置", "hint": "API Key 配置" },
"evolution": { "label": "自演进配置", "hint": "Skills 在线自演进参数" },
+ "contextEngine": { "label": "上下文压缩", "hint": "控制对话上下文是否启用压缩" },
+ "permissions": { "label": "工具安全护栏", "hint": "控制工具调用时的权限检查" },
"email": { "label": "邮箱配置", "hint": "邮件账号与令牌参数" },
"other": { "label": "其他配置", "hint": "未归类的扩展参数" }
},