sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

@@ -17,6 +17,7 @@ from deerflow.config.database_config import DatabaseConfig
from deerflow.config.extensions_config import ExtensionsConfig
from deerflow.config.gateway_config import GatewayConfig
from deerflow.config.guardrails_config import GuardrailsConfig, load_guardrails_config_from_dict
from deerflow.config.html_runtime_config import HtmlRuntimeConfig
from deerflow.config.knowledge_config import KnowledgeConfig
from deerflow.config.knowledge_ingest_config import KnowledgeIngestConfig
from deerflow.config.llmwiki_config import LlmWikiConfig
@@ -27,6 +28,7 @@ from deerflow.config.model_config import ModelConfig
from deerflow.config.report_collaboration_config import ReportCollaborationConfig
from deerflow.config.run_events_config import RunEventsConfig
from deerflow.config.runtime_paths import existing_project_file
from deerflow.config.runtime_performance_config import RuntimePerformanceConfig
from deerflow.config.sandbox_config import SandboxConfig
from deerflow.config.sentiment_agent_config import SentimentAgentConfig
from deerflow.config.skill_evolution_config import SkillEvolutionConfig
@@ -43,6 +45,7 @@ from deerflow.config.token_usage_config import TokenUsageConfig
from deerflow.config.tool_config import ToolConfig, ToolGroupConfig
from deerflow.config.tool_search_config import ToolSearchConfig, load_tool_search_config_from_dict
from deerflow.config.vision_config import VisionConfig
from deerflow.config.web_app_config import WebAppConfig
from deerflow.config.workflow_config import WorkflowConfig
from deerflow.config.y_log_config import YLogConfig
@@ -116,6 +119,7 @@ class AppConfig(BaseModel):
"""Config for the DeerFlow application"""
log_level: str = Field(default="info", description="Logging level for deerflow and app modules (debug/info/warning/error); third-party libraries are not affected")
runtime_performance: RuntimePerformanceConfig = Field(default_factory=RuntimePerformanceConfig, description="Skill-view reuse and cache default on; model timing and the Gateway executor stay off unless set. Set a skill-view switch false to disable it.")
token_usage: TokenUsageConfig = Field(default_factory=TokenUsageConfig, description="Token usage tracking configuration")
models: list[ModelConfig] = Field(default_factory=list, description="Available models")
vision: VisionConfig = Field(default_factory=VisionConfig, description="Image recognition (识图) configuration")
@@ -151,7 +155,15 @@ class AppConfig(BaseModel):
knowledge_ingest: KnowledgeIngestConfig = Field(default_factory=KnowledgeIngestConfig, description="External knowledge-ingest endpoint configuration")
task_deeplink: TaskDeeplinkConfig = Field(default_factory=TaskDeeplinkConfig, description="任务深链(rwfx)目的树闸门与跳转地址配置(前端经 /api/public/config/task-deeplink 读取)")
y_log: YLogConfig = Field(default_factory=YLogConfig, description="操作日志上报配置(前端经 /api/public/config/y-log 读取)")
html_runtime: HtmlRuntimeConfig = Field(
default_factory=HtmlRuntimeConfig,
description="后台生成 HTML 的浏览器绘图库与地图瓦片配置",
)
workflows: WorkflowConfig = Field(default_factory=WorkflowConfig, description="Workflow Studio limits / iframe origins")
web_app: WebAppConfig = Field(
default_factory=WebAppConfig,
description="Web App 产物模式(多页面站点生成/构建/预览,默认关闭、可降级)",
)
report_collaboration: ReportCollaborationConfig = Field(
default_factory=ReportCollaborationConfig,
description="AgentScope report-collaboration workbench (default off)",
@@ -211,6 +223,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 +285,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."""
@@ -427,6 +470,15 @@ def _load_and_cache_app_config(config_path: str | None = None) -> AppConfig:
summarization.keep,
summarization.trim_tokens_to_summarize,
)
performance = _app_config.runtime_performance
logger.info(
"RUNTIME_PERFORMANCE skill_view_reuse_enabled=%s skill_view_cache_enabled=%s model_timing_nonblocking_enabled=%s asyncio_thread_pool_enabled=%s asyncio_thread_pool_size=%d",
performance.skill_view_reuse_enabled,
performance.skill_view_cache_enabled,
performance.model_timing_nonblocking_enabled,
performance.asyncio_thread_pool_enabled,
performance.asyncio_thread_pool_size,
)
return _app_config
@@ -1,13 +1,25 @@
"""Unified extensions configuration for MCP servers and skills."""
import copy
import errno
import json
import logging
import os
import tempfile
import threading
import time
from collections.abc import Callable, Iterator
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Literal
from pydantic import BaseModel, ConfigDict, Field
from deerflow.config.runtime_paths import existing_project_file
logger = logging.getLogger(__name__)
_EXTENSIONS_CONFIG_WRITE_LOCK = threading.Lock()
class McpOAuthConfig(BaseModel):
@@ -350,6 +362,142 @@ def reload_extensions_config(config_path: str | None = None) -> ExtensionsConfig
return _extensions_config
def _read_raw_extensions_config(config_path: Path) -> dict[str, Any]:
"""Read the raw JSON document without resolving env placeholders."""
if not config_path.exists():
return {}
with config_path.open(encoding="utf-8") as config_file:
document = json.load(config_file)
if not isinstance(document, dict):
raise ValueError("Extensions config root must be a JSON object")
return document
def read_extensions_config_document(config_path: str | Path) -> dict[str, Any]:
"""Return a fresh raw document while coordinating with all writers."""
path = Path(config_path)
with _EXTENSIONS_CONFIG_WRITE_LOCK:
with _extensions_config_process_lock(path):
return _read_raw_extensions_config(path)
@contextmanager
def _extensions_config_process_lock(config_path: Path) -> Iterator[None]:
"""Serialize writers across processes on Windows and POSIX.
The stable sidecar is intentional: deleting it after unlock can let two
processes lock different inodes. Keeping it beside the config also lets
multiple processes sharing the writable config directory coordinate.
"""
lock_path = config_path.with_name(f".{config_path.name}.lock")
lock_path.parent.mkdir(parents=True, exist_ok=True)
with lock_path.open("a+b") as lock_file:
if os.name == "nt":
import msvcrt
lock_file.seek(0, os.SEEK_END)
if lock_file.tell() == 0:
lock_file.write(b"\0")
lock_file.flush()
lock_file.seek(0)
while True:
try:
msvcrt.locking(lock_file.fileno(), msvcrt.LK_NBLCK, 1)
break
except OSError as exc:
if exc.errno not in {errno.EACCES, errno.EAGAIN, errno.EDEADLK}:
raise
time.sleep(0.05)
try:
yield
finally:
lock_file.seek(0)
msvcrt.locking(lock_file.fileno(), msvcrt.LK_UNLCK, 1)
else:
import fcntl
fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX)
try:
yield
finally:
fcntl.flock(lock_file.fileno(), fcntl.LOCK_UN)
def _write_raw_extensions_config(config_path: Path, document: dict[str, Any]) -> None:
"""Durably replace raw JSON, with a bind-mounted-file EBUSY fallback."""
config_path.parent.mkdir(parents=True, exist_ok=True)
payload = json.dumps(document, indent=2, ensure_ascii=False) + "\n"
tmp_path: Path | None = None
try:
with tempfile.NamedTemporaryFile(
"w",
encoding="utf-8",
delete=False,
dir=str(config_path.parent),
) as tmp_file:
tmp_file.write(payload)
tmp_file.flush()
os.fsync(tmp_file.fileno())
tmp_path = Path(tmp_file.name)
try:
os.replace(tmp_path, config_path)
except OSError as exc:
if exc.errno != errno.EBUSY:
raise
logger.warning(
"Atomic replace is unavailable for bind-mounted extensions config %s; using in-place fallback",
config_path,
)
previous = config_path.read_bytes() if config_path.exists() else None
try:
mode = "r+" if config_path.exists() else "w"
with config_path.open(mode, encoding="utf-8") as config_file:
config_file.seek(0)
config_file.write(payload)
config_file.truncate()
config_file.flush()
os.fsync(config_file.fileno())
except Exception:
if previous is not None:
try:
with config_path.open("wb") as config_file:
config_file.write(previous)
config_file.flush()
os.fsync(config_file.fileno())
except Exception:
logger.exception("Failed to restore extensions config after in-place write failure")
raise
finally:
if tmp_path is not None and tmp_path.exists():
tmp_path.unlink()
def patch_extensions_config(
config_path: str | Path,
patch: Callable[[dict[str, Any]], None],
) -> ExtensionsConfig:
"""Apply a raw-document patch under thread and cross-process locks.
Callers should mutate only the fields they own. The document is read fresh
while locked, so concurrent MCP, skill-state, and display writes cannot
overwrite one another or resolve/persist secret ``$ENV`` placeholders.
"""
path = Path(config_path)
with _EXTENSIONS_CONFIG_WRITE_LOCK:
with _extensions_config_process_lock(path):
document = _read_raw_extensions_config(path)
patch(document)
if not isinstance(document, dict):
raise ValueError("Extensions config root must be a JSON object")
# Validate a deep copy before persisting. Environment expansion is
# intentionally confined to the copy so placeholders remain raw.
validation_document = copy.deepcopy(document)
ExtensionsConfig.resolve_env_variables(validation_document)
ExtensionsConfig.model_validate(validation_document)
_write_raw_extensions_config(path, document)
return reload_extensions_config(str(path))
def reset_extensions_config() -> None:
"""Reset the cached extensions config instance.
@@ -0,0 +1,20 @@
"""Browser runtime configuration for generated HTML artifacts."""
from pydantic import BaseModel, Field
DEFAULT_HTML_MAP_TILE_URL = "https://mt0.google.com/vt/lyrs=m&hl=zh-CN&x={x}&y={y}&z={z}"
class HtmlRuntimeConfig(BaseModel):
"""Resources used by standalone HTML pages generated in the sandbox."""
base_url: str = Field(
default="http://localhost:8001/api/public/html-runtime",
min_length=1,
description="Browser-accessible Gateway base URL for generated HTML runtime files",
)
map_tile_url: str = Field(
default=DEFAULT_HTML_MAP_TILE_URL,
min_length=1,
description="Leaflet tile URL template used when HTML maps use the map-webpage engine",
)
@@ -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)
@@ -155,6 +156,10 @@ class LocalWikiIndexConfig(BaseModel):
min_similarity: float = Field(default=0.35, ge=-1, le=1)
keyword_boost_enabled: bool = False
keyword_boost_weight: float = Field(default=0.15, ge=0, le=1)
# Lexical title matches receive a bounded score/RRF multiplier rather than
# an absolute priority. This is configurable without changing the index.
title_boost_enabled: bool = True
title_boost_weight: float = Field(default=0.25, ge=0, le=1)
cache_max_knowledge_bases: int = Field(default=20, ge=1, le=1000)
cache_revision_check_seconds: float = Field(default=5, ge=0, le=3600)
database_batch_size: int = Field(default=50, ge=1, le=500)
@@ -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
@@ -1,6 +1,21 @@
from enum import StrEnum
from pydantic import BaseModel, ConfigDict, Field
class WriteFileTransport(StrEnum):
"""How a model supplies the body of a ``write_file`` call."""
NATIVE = "native"
BUFFERED_GATEWAY = "buffered_gateway"
ARTIFACT_RENDERER = "artifact_renderer"
# Kept for existing deployments that already opted into the first bridge
# implementation. New buffered-gateway configurations should use
# ``buffered_gateway``; unlike the legacy free-form body bridge it keeps
# the original writer contract and enforces a typed transaction boundary.
TEXT_BRIDGE = "text_bridge"
class ModelConfig(BaseModel):
"""Config section for a model"""
@@ -10,9 +25,14 @@ class ModelConfig(BaseModel):
use: str = Field(
...,
description="Class path of the model provider(e.g. langchain_openai.ChatOpenAI)",
)
model: str = Field(..., description="Model name")
model_config = ConfigDict(extra="allow")
)
model: str = Field(..., description="Model name")
max_input_tokens: int | None = Field(
default=None,
ge=1,
description="Maximum input context tokens DeerFlow may send to the model",
)
model_config = ConfigDict(extra="allow")
use_responses_api: bool | None = Field(
default=None,
description="Whether to route OpenAI ChatOpenAI calls through the /v1/responses API",
@@ -21,8 +41,24 @@ class ModelConfig(BaseModel):
default=None,
description="Structured output version for OpenAI responses content, e.g. responses/v1",
)
write_file_transport: WriteFileTransport = Field(
default=WriteFileTransport.NATIVE,
description=(
"How DeerFlow receives write_file content. Use buffered_gateway to keep the "
"original write_file contract while obtaining its body from a second ordinary-text "
"stream when an OpenAI-compatible gateway buffers tool arguments. "
"artifact_renderer is the earlier internal-handshake compatibility mode. "
"text_bridge remains available only for backward compatibility."
),
)
supports_thinking: bool = Field(default_factory=lambda: False, description="Whether the model supports thinking")
supports_reasoning_effort: bool = Field(default_factory=lambda: False, description="Whether the model supports reasoning effort")
supports_reasoning_effort: bool = Field(
default_factory=lambda: False,
description=(
"Legacy parser compatibility only. Gateway reasoning-effort capability is stored in the "
"model_capabilities database table."
),
)
when_thinking_enabled: dict | None = Field(
default_factory=lambda: None,
description="Extra settings to be passed to the model when thinking is enabled",
@@ -18,7 +18,23 @@ class ReportCollaborationConfig(BaseModel):
default=False,
description="When true, a dispatcher/worker may claim run leases. Gateway-only processes keep this false.",
)
planner_llm_enabled: bool = Field(
default=False,
description="P1: LLM planner conversation (clarify + custom strategy). Off keeps the deterministic rule router and template plans.",
)
planner_model: str | None = Field(default=None, description="Model name from AppConfig.models for planning")
planner_timeout_seconds: int = Field(
default=120,
ge=30,
le=600,
description="Hard deadline for one streamed workflow-planning model call",
)
planner_max_tokens: int = Field(
default=1800,
ge=512,
le=8192,
description="Maximum output tokens for the workflow-planning model call",
)
coordinator_model: str | None = Field(default=None, description="Model name from AppConfig.models for the constrained coordinator")
research_model: str | None = Field(default=None, description="Model name from AppConfig.models for research members")
writer_model: str | None = Field(default=None, description="Model name from AppConfig.models for writing")
@@ -0,0 +1,36 @@
"""Runtime performance switches.
Skill-view reuse and cache are on when those keys are absent. Set them to
false in config.yaml to restore a full refresh on every tool call. Model
timing and the Gateway thread pool stay off unless configured. If application
configuration cannot be loaded, every switch stays off.
"""
from pydantic import BaseModel, ConfigDict, Field
class RuntimePerformanceConfig(BaseModel):
model_config = ConfigDict(frozen=True, extra="forbid")
skill_view_reuse_enabled: bool = Field(default=True, description="Reuse one verified skill view within each sandbox tool invocation. Set false to refresh on every call.")
skill_view_cache_enabled: bool = Field(default=True, description="Reuse unchanged skill views after validating source, target and availability versions. Set false to rebuild every call.")
model_timing_nonblocking_enabled: bool = Field(default=False, description="Dispatch model timing logs through a dedicated bounded queue, outside the shared tool executor")
asyncio_thread_pool_enabled: bool = Field(default=False, description="Override the Gateway event loop's default executor at startup; disabled preserves Python defaults")
asyncio_thread_pool_size: int = Field(default=100, ge=1, le=1024, strict=True, description="Maximum Gateway executor threads when enabled, unless overridden by the documented environment variables")
# Field defaults turn the skill-view fast path on. This fallback is only for
# callers that cannot read application configuration, and it keeps every
# switch off.
_DEFAULT = RuntimePerformanceConfig(skill_view_reuse_enabled=False, skill_view_cache_enabled=False)
def get_runtime_performance_config() -> RuntimePerformanceConfig:
# Lazy import: AppConfig owns this model. Never enable optimizations if
# called before application configuration is available (e.g. embedded SDK).
from deerflow.config.app_config import get_app_config
try:
return get_app_config().runtime_performance
except Exception:
return _DEFAULT
@@ -64,6 +64,12 @@ class SandboxConfig(BaseModel):
description="Environment variables to inject into the sandbox container. Values starting with $ will be resolved from host environment variables.",
)
command_timeout_seconds: float = Field(
default=600,
gt=0,
allow_inf_nan=False,
description="Maximum execution time of a local sandbox shell command in seconds. On timeout the command process tree is terminated.",
)
bash_output_max_chars: int = Field(
default=20000,
ge=0,
@@ -147,6 +147,15 @@ class CustomThemePreset(BaseModel):
return _normalize_optional_hex_color(value, "Theme text color")
WordHeadingNumberingStyle = Literal[
"hybrid_decimal",
"official_chinese",
"decimal",
"chapter_section",
"none",
]
class PromptPrefixSettings(BaseModel):
"""Admin-configurable first-message prompt prefix."""
@@ -157,6 +166,10 @@ class PromptPrefixSettings(BaseModel):
default=False,
description="Whether the formal Markdown heading rules are injected into ordinary Q&A system prompts.",
)
word_heading_numbering_style: WordHeadingNumberingStyle = Field(
default="hybrid_decimal",
description="Heading-numbering preset used by every Markdown-to-Word export.",
)
model_config = ConfigDict(extra="ignore")
@@ -273,6 +286,7 @@ class AppearanceSettings(BaseModel):
class CitationDisplaySettings(BaseModel):
"""System-wide controls for citation mode entry and display cleanup."""
retrieved_files_enabled: bool = True
reference_mode_enabled: bool = Field(
default=False,
description="Whether the reference-mode entry points are exposed to users.",
@@ -414,6 +428,22 @@ class AgentModuleSettings(BaseModel):
model_config = ConfigDict(extra="ignore")
class WxCommonAgentsSettings(BaseModel):
"""The gallery category shown in the wx chat route's common-agent panel.
``None`` keeps the original recommendation logic. ``mine`` and
``sentiment`` are built-in category values. Publish-square categories are
persisted as ``square:<square_id>`` so they cannot collide with the
built-ins.
"""
agent_type: str | None = Field(
default=None,
description="Selected gallery category; null retains the default recommendation logic",
)
model_config = ConfigDict(extra="ignore")
class PluginDomainAgentMapping(BaseModel):
"""One configured host -> agent mapping for iframe chat auto-selection."""
@@ -447,6 +477,16 @@ def set_module_tag_ids(settings: AgentModuleSettings, key: str, tag_ids: list[st
return settings.model_copy(update={"modules": modules})
class AuthenticationSettings(BaseModel):
"""Public login capabilities; administrator writes take effect immediately."""
password_login_enabled: bool = False
registration_enabled: bool = False
sso_enabled: bool = True
single_session_enabled: bool = False
model_config = ConfigDict(extra="forbid")
class LoginWhitelistSettings(BaseModel):
"""登录白名单总开关(管理员可在「白名单管理」页切换,即时生效、免重启)。
@@ -505,14 +545,93 @@ class ModelConcurrencySettings(BaseModel):
model_config = ConfigDict(extra="ignore")
class MemoryRuntimeSettings(BaseModel):
"""Deployment-wide switch for generic/personal 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
generic memory into prompts, and does not enqueue generic background memory
extraction. Project-scoped Q&A memory is an independent subsystem governed
by each project's own setting and is intentionally not controlled here.
"""
enabled: bool = Field(
default=False,
description="Whether generic/personal Q&A memory recall, injection and persistence are enabled.",
)
model_config = ConfigDict(extra="ignore")
class WriteFileCompatibilitySettings(BaseModel):
"""Deployment-wide compatibility for gateways buffering tool arguments."""
enabled: bool = Field(
default=False,
description=(
"Whether every compatible model uses the buffered-gateway "
"write_file streaming adapter."
),
)
model_config = ConfigDict(extra="ignore")
class ConversationContextSettings(BaseModel):
"""Deployment-wide short-context policy for chat model requests.
The recent-turn window is deliberately opt-in. When enabled, the lead
agent keeps the persisted conversation intact but sends only the latest
three real user turns (plus their assistant/tool continuations) to the
model. This avoids an extra summarization-model call while preserving the
complete transcript for the UI and checkpoint recovery.
"""
recent_turn_window_enabled: bool = Field(
default=False,
description="Whether model requests use the fixed recent-three-turn sliding window.",
)
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 HtmlMapSettings(BaseModel):
"""Which map engine newly generated HTML pages should use."""
engine: Literal["echarts", "leaflet"] = Field(
default="echarts",
description="echarts uses local GeoJSON; leaflet is the tile-based map webpage",
)
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")
@@ -521,6 +640,7 @@ class SystemSettings(BaseModel):
prompt_prefix: PromptPrefixSettings = Field(default_factory=PromptPrefixSettings)
login_whitelist: LoginWhitelistSettings = Field(default_factory=LoginWhitelistSettings)
authentication: AuthenticationSettings = Field(default_factory=AuthenticationSettings)
private_square: PrivateSquareSettings = Field(default_factory=PrivateSquareSettings)
publish_squares: PublishSquaresSettings = Field(default_factory=PublishSquaresSettings)
appearance: AppearanceSettings = Field(default_factory=AppearanceSettings)
@@ -529,14 +649,25 @@ class SystemSettings(BaseModel):
skill_compression: SkillCompressionSettings = Field(default_factory=SkillCompressionSettings)
plugin_management: PluginManagementSettings = Field(default_factory=PluginManagementSettings)
agent_modules: AgentModuleSettings = Field(default_factory=AgentModuleSettings)
wx_common_agents: WxCommonAgentsSettings = Field(default_factory=WxCommonAgentsSettings)
concurrency_monitor: ConcurrencyMonitorSettings = Field(default_factory=ConcurrencyMonitorSettings)
model_concurrency: ModelConcurrencySettings = Field(default_factory=ModelConcurrencySettings)
memory: MemoryRuntimeSettings = Field(default_factory=MemoryRuntimeSettings)
write_file_compatibility: WriteFileCompatibilitySettings = Field(
default_factory=WriteFileCompatibilitySettings
)
conversation_context: ConversationContextSettings = Field(default_factory=ConversationContextSettings)
local_wiki_encoder: LocalWikiEncoderSettings = Field(default_factory=LocalWikiEncoderSettings)
strategy_projects: StrategyProjectSettings = Field(default_factory=StrategyProjectSettings)
html_map: HtmlMapSettings = Field(default_factory=HtmlMapSettings)
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.",
description=(
"v1 keeps assistant-knowledge day-to-day surfaces admin-only; "
"v2 releases them to ordinary users while ordinary knowledge remains the default landing."
),
)
ordinary_knowledge_landing: Literal["wiki", "weknora"] = "wiki"
model_config = ConfigDict(extra="ignore")
@@ -591,12 +722,48 @@ 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 get_write_file_compatibility_settings() -> WriteFileCompatibilitySettings:
"""Return the global buffered-gateway switch, failing closed."""
try:
return load_system_settings().write_file_compatibility
except Exception:
logger.debug(
"Failed to read write_file compatibility setting; keeping native transport",
exc_info=True,
)
return WriteFileCompatibilitySettings()
def get_conversation_context_settings() -> ConversationContextSettings:
"""Return the admin-controlled recent-turn policy, failing closed."""
try:
return load_system_settings().conversation_context
except Exception:
logger.debug("Failed to read conversation context setting; keeping the recent-turn window disabled", exc_info=True)
return ConversationContextSettings()
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
@@ -0,0 +1,39 @@
"""Web App 产物模式配置(多页面站点生成/构建/预览)。"""
from __future__ import annotations
from pydantic import BaseModel, Field
class WebAppConfig(BaseModel):
"""站点产物(outputs/ 下的 site.json 站点)总开关与构建参数。
默认关闭:模板未预置 node_modules 或未启用时,所有站点 API 返回
结构化的"不可用"响应,智能体技能自动回退单页 HTML 模式,
不影响任何既有功能。
"""
enabled: bool = Field(
default=False,
description="总开关:关闭时 capability 返回不可用,入口按钮不渲染,技能回退单页 HTML",
)
template_dir: str = Field(
default="templates/web-app-template",
description="站点模板目录(相对 project root 或绝对路径;含预置 node_modules 与 scripts/build_site.py)",
)
build_timeout_seconds: int = Field(
default=180,
ge=10,
le=1800,
description="单次 vite build 超时(秒),超时强杀子进程",
)
preview_token_ttl_seconds: int = Field(
default=7200,
ge=60,
le=86400,
description="站点预览签名 URL 有效期(秒)",
)
node_path: str = Field(
default="",
description="node 可执行文件覆盖(空 = PATH 查找;一般无需配置)",
)