sync update from LAN repo (source master-nj @ 067eb808)
This commit is contained in:
1 parent
1244fb1f2f
commit
1d5dd8fc90
182 files changed
+18973
-769
No files matched your search
@@ -211,6 +211,7 @@ class AppConfig(BaseModel):
|
||||
cls._check_config_version(config_data, resolved_path)
|
||||
|
||||
config_data = cls.resolve_env_variables(config_data)
|
||||
cls._resolve_relative_mount_paths(config_data, resolved_path.parent)
|
||||
cls._apply_database_defaults(config_data)
|
||||
|
||||
# Load title config if present
|
||||
@@ -272,6 +273,36 @@ class AppConfig(BaseModel):
|
||||
result = cls.model_validate(config_data)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def _resolve_relative_mount_paths(
|
||||
cls,
|
||||
config_data: dict[str, Any],
|
||||
config_dir: Path,
|
||||
) -> None:
|
||||
"""Resolve portable sandbox mount paths beside ``config.yaml``.
|
||||
|
||||
Deployment copies frequently live at different absolute paths. A
|
||||
relative ``sandbox.mounts[*].host_path`` therefore means "relative to
|
||||
the config file", never relative to the process working directory.
|
||||
Providers continue to receive absolute paths, which keeps both the
|
||||
local path mapper and Docker bind mounts deterministic.
|
||||
"""
|
||||
sandbox = config_data.get("sandbox")
|
||||
if not isinstance(sandbox, dict):
|
||||
return
|
||||
mounts = sandbox.get("mounts")
|
||||
if not isinstance(mounts, list):
|
||||
return
|
||||
for mount in mounts:
|
||||
if not isinstance(mount, dict):
|
||||
continue
|
||||
raw_host_path = mount.get("host_path")
|
||||
if not isinstance(raw_host_path, str) or not raw_host_path.strip():
|
||||
continue
|
||||
host_path = Path(raw_host_path)
|
||||
if not host_path.is_absolute():
|
||||
mount["host_path"] = str((config_dir / host_path).resolve())
|
||||
|
||||
@classmethod
|
||||
def _apply_database_defaults(cls, config_data: dict[str, Any]) -> None:
|
||||
"""Apply config.yaml defaults for persistence when the section is absent."""
|
||||
|
||||
@@ -77,6 +77,7 @@ class LocalWikiEmbeddingConfig(BaseModel):
|
||||
base_url: str = ""
|
||||
api_key: str = Field(default="", repr=False)
|
||||
local_model_path: str = ""
|
||||
local_model_revision: str = ""
|
||||
local_cache_dir: str = ""
|
||||
local_process_isolation: bool = True
|
||||
local_threads: int = Field(default=2, ge=1, le=32)
|
||||
|
||||
@@ -12,8 +12,11 @@
|
||||
injection: {...} # 系统提示词注入
|
||||
security: {...} # 内容安全扫描
|
||||
|
||||
两层配置覆盖
|
||||
============
|
||||
运行时总开关与配置覆盖
|
||||
======================
|
||||
管理员维护的 ``system_settings.json -> memory.enabled`` 是权威总开关,默认
|
||||
``false``。关闭时下面所有 provider 参数都不生效。
|
||||
|
||||
``get_effective_memory_config(user_id)`` 按优先级合并 (高 -> 低):
|
||||
1. per-user 覆盖 数据库 ``user_memory_configs`` 表 (经进程内 cache 读取)
|
||||
(有 per-user 记录时自动强制 enabled=True)
|
||||
@@ -32,6 +35,8 @@ from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from deerflow.config.system_settings import get_memory_runtime_settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -126,7 +131,7 @@ class V1MemoryConfig(BaseModel):
|
||||
class MemoryConfig(BaseModel):
|
||||
"""记忆子系统的全局配置 (config.yaml 的 ``memory:`` 段)。"""
|
||||
|
||||
enabled: bool = Field(default=True, description="记忆子系统总开关")
|
||||
enabled: bool = Field(default=False, description="记忆子系统总开关")
|
||||
version: str = Field(
|
||||
default="v2",
|
||||
description="记忆系统版本:v1(原版 DeerFlow,memory.json + LLM 自动提取) 或 v2(USER.md/MEMORY.md)",
|
||||
@@ -253,10 +258,18 @@ def get_recall_budget_from_cache(user_id: str) -> str | None:
|
||||
def get_effective_memory_config(user_id: str) -> MemoryConfig:
|
||||
"""返回某用户的生效记忆配置 (同步,从进程内 cache 读取 per-user 覆盖)。
|
||||
|
||||
优先级 (高 -> 低):per-user DB 覆盖 (经 cache) > config.yaml > 默认值。
|
||||
有 per-user 记录时自动强制 enabled=True。
|
||||
管理员运行时总开关关闭时直接返回 ``enabled=False``;开启后再按
|
||||
per-user DB 覆盖 (经 cache) > config.yaml > 默认值 合并参数。
|
||||
"""
|
||||
# The admin-managed runtime switch is authoritative and defaults to off.
|
||||
# ``config.yaml`` supplies provider parameters only; it cannot silently
|
||||
# turn memory on after a fresh deployment or settings-file reset.
|
||||
runtime_enabled = get_memory_runtime_settings().enabled
|
||||
if not runtime_enabled:
|
||||
return _memory_config.model_copy(update={"enabled": False}, deep=True)
|
||||
|
||||
base = _memory_config.model_dump()
|
||||
base["enabled"] = True
|
||||
recall_budget = _recall_budget_cache.get(user_id)
|
||||
if recall_budget is not None:
|
||||
base.setdefault("hindsight", {})["recall_budget"] = recall_budget
|
||||
|
||||
+57
-3
@@ -505,14 +505,51 @@ class ModelConcurrencySettings(BaseModel):
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
class MemoryRuntimeSettings(BaseModel):
|
||||
"""Deployment-wide switch for Q&A memory.
|
||||
|
||||
Memory is deliberately opt-in. When this setting is false the lead agent
|
||||
does not mount memory middleware or memory tools, does not inject stored
|
||||
memory into prompts, and does not enqueue background memory extraction.
|
||||
"""
|
||||
|
||||
enabled: bool = Field(
|
||||
default=False,
|
||||
description="Whether Q&A memory recall, injection and persistence are enabled.",
|
||||
)
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
class LocalWikiEncoderSettings(BaseModel):
|
||||
"""Runtime override for the administrator-managed offline Wiki encoder."""
|
||||
|
||||
mode: Literal["configured", "local"] = Field(
|
||||
default="configured",
|
||||
description=(
|
||||
"Use the embedding provider from config.yaml, or explicitly override it "
|
||||
"with the administrator-managed offline BGE-M3 encoder."
|
||||
),
|
||||
)
|
||||
model_path: str = Field(
|
||||
default="",
|
||||
max_length=4096,
|
||||
description="Absolute or project-relative directory containing the offline BGE-M3 ONNX model.",
|
||||
)
|
||||
model_revision: str = Field(
|
||||
default="",
|
||||
max_length=64,
|
||||
description="Opaque revision changed whenever an offline model directory is activated.",
|
||||
)
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
class StrategyProjectSettings(BaseModel):
|
||||
"""Global visibility controls for the strategy-project experience."""
|
||||
|
||||
taiwan_strait_demo_enabled: bool = Field(
|
||||
default=False,
|
||||
description="Whether Taiwan Strait demo entry points are visible in My Projects.",
|
||||
)
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
@@ -531,13 +568,16 @@ class SystemSettings(BaseModel):
|
||||
agent_modules: AgentModuleSettings = Field(default_factory=AgentModuleSettings)
|
||||
concurrency_monitor: ConcurrencyMonitorSettings = Field(default_factory=ConcurrencyMonitorSettings)
|
||||
model_concurrency: ModelConcurrencySettings = Field(default_factory=ModelConcurrencySettings)
|
||||
memory: MemoryRuntimeSettings = Field(default_factory=MemoryRuntimeSettings)
|
||||
local_wiki_encoder: LocalWikiEncoderSettings = Field(default_factory=LocalWikiEncoderSettings)
|
||||
strategy_projects: StrategyProjectSettings = Field(default_factory=StrategyProjectSettings)
|
||||
llmwiki: LlmWikiRuntimeOverride = Field(default_factory=LlmWikiRuntimeOverride)
|
||||
skill_knowledge_auto_sync: SkillKnowledgeAutoSyncSettings = Field(default_factory=SkillKnowledgeAutoSyncSettings)
|
||||
knowledge_base_product_version: Literal["v1", "v2"] = Field(
|
||||
default="v1",
|
||||
description="v1 opens the ordinary WeKnora experience; v2 opens the DeerFlow assistant knowledge base.",
|
||||
)
|
||||
ordinary_knowledge_landing: Literal["wiki", "weknora"] = "wiki"
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
|
||||
@@ -590,12 +630,26 @@ def get_model_concurrency_settings() -> ModelConcurrencySettings:
|
||||
return ModelConcurrencySettings()
|
||||
|
||||
|
||||
def get_memory_runtime_settings() -> MemoryRuntimeSettings:
|
||||
"""Return the admin-controlled Q&A memory switch, failing closed."""
|
||||
try:
|
||||
return load_system_settings().memory
|
||||
except Exception:
|
||||
logger.debug("Failed to read memory runtime setting; keeping memory disabled", exc_info=True)
|
||||
return MemoryRuntimeSettings()
|
||||
|
||||
|
||||
def save_system_settings(settings: SystemSettings) -> SystemSettings:
|
||||
"""Persist the settings document atomically, returning the saved value."""
|
||||
path = _settings_path()
|
||||
payload = settings.model_dump(mode="json")
|
||||
with _lock:
|
||||
tmp = path.with_suffix(path.suffix + ".tmp")
|
||||
tmp.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
tmp.replace(path)
|
||||
# Multiple Gateway workers share this file. A unique temporary name
|
||||
# prevents their atomic replaces from racing over one common `.tmp`.
|
||||
tmp = path.with_name(f".{path.name}.{uuid4().hex}.tmp")
|
||||
try:
|
||||
tmp.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
tmp.replace(path)
|
||||
finally:
|
||||
tmp.unlink(missing_ok=True)
|
||||
return settings
|
||||
Reference in new issue
Block a user