sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
+133
-1
@@ -5,9 +5,10 @@ import os
|
||||
import re
|
||||
import threading
|
||||
from typing import Any
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
import yaml
|
||||
from pydantic import BaseModel, field_validator, model_validator
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator
|
||||
|
||||
from deerflow.config.paths import get_paths
|
||||
|
||||
@@ -82,6 +83,124 @@ class CommonQuestion(BaseModel):
|
||||
return value
|
||||
|
||||
|
||||
_CHAT_LINK_URL_MAX = 2048
|
||||
_CHAT_LINK_PARAM_MAX = 30
|
||||
|
||||
|
||||
class AgentChatRouteParam(BaseModel):
|
||||
"""One query parameter appended when an agent's gallery 「对话」 button opens its link.
|
||||
|
||||
Same shape as a light-app route param: login values are resolved in the
|
||||
browser from the current user, theme values follow the active theme.
|
||||
"""
|
||||
|
||||
key: str = ""
|
||||
paramType: str = "login"
|
||||
source: str | None = None
|
||||
customValue: str | None = None
|
||||
themeValue: str | None = None
|
||||
|
||||
|
||||
class AgentChatLinkConfig(BaseModel):
|
||||
"""Optional external (or in-app) destination for the gallery chat button."""
|
||||
|
||||
url: str = ""
|
||||
open_mode: str = "blank"
|
||||
route_params: list[AgentChatRouteParam] = Field(default_factory=list)
|
||||
|
||||
|
||||
def _is_allowed_agent_chat_url(url: str) -> bool:
|
||||
lowered = url.lower()
|
||||
if lowered.startswith(("javascript:", "data:", "vbscript:", "file:")):
|
||||
return False
|
||||
if url.startswith("#/"):
|
||||
return True
|
||||
if url.startswith("/") and not url.startswith("//") and not url.startswith("/\\"):
|
||||
return True
|
||||
parsed = urlsplit(url)
|
||||
return parsed.scheme in {"http", "https"} and bool(parsed.netloc)
|
||||
|
||||
|
||||
def normalize_agent_chat_link(value: Any, *, strict: bool = False) -> dict[str, Any] | None:
|
||||
"""Return a clean chat-link dict, or None when the link is unset.
|
||||
|
||||
``strict=True`` raises ``ValueError`` for a non-empty but illegal link so
|
||||
the API can reject it. Disk loads stay lenient: a bad value is dropped
|
||||
instead of making the whole agent unloadable.
|
||||
"""
|
||||
|
||||
if value is None:
|
||||
return None
|
||||
if hasattr(value, "model_dump"):
|
||||
value = value.model_dump()
|
||||
if not isinstance(value, dict):
|
||||
if strict:
|
||||
raise ValueError("对话跳转配置格式不正确")
|
||||
return None
|
||||
|
||||
url = str(value.get("url") or "").strip()
|
||||
if not url:
|
||||
return None
|
||||
if len(url) > _CHAT_LINK_URL_MAX or not _is_allowed_agent_chat_url(url):
|
||||
if strict:
|
||||
raise ValueError("对话链接只支持 http(s) 地址,或以 /、#/ 开头的站内路径")
|
||||
return None
|
||||
|
||||
mode = str(value.get("open_mode") or "blank").strip() or "blank"
|
||||
if mode not in {"self", "blank"}:
|
||||
if strict:
|
||||
raise ValueError("打开方式只支持当前窗口或新窗口")
|
||||
mode = "blank"
|
||||
|
||||
raw_params = value.get("route_params") or []
|
||||
if raw_params is None:
|
||||
raw_params = []
|
||||
if not isinstance(raw_params, list):
|
||||
if strict:
|
||||
raise ValueError("路由参数格式不正确")
|
||||
raw_params = []
|
||||
if len(raw_params) > _CHAT_LINK_PARAM_MAX:
|
||||
if strict:
|
||||
raise ValueError("路由参数最多 30 个")
|
||||
raw_params = raw_params[:_CHAT_LINK_PARAM_MAX]
|
||||
|
||||
params: list[dict[str, Any]] = []
|
||||
for item in raw_params:
|
||||
if hasattr(item, "model_dump"):
|
||||
item = item.model_dump()
|
||||
if not isinstance(item, dict):
|
||||
if strict:
|
||||
raise ValueError("路由参数格式不正确")
|
||||
continue
|
||||
key = str(item.get("key") or "").strip()
|
||||
if not key:
|
||||
if strict:
|
||||
raise ValueError("路由参数键名不可为空")
|
||||
continue
|
||||
if len(key) > 128:
|
||||
if strict:
|
||||
raise ValueError("路由参数键名过长")
|
||||
continue
|
||||
param_type = str(item.get("paramType") or "login").strip() or "login"
|
||||
if param_type not in {"login", "theme"}:
|
||||
if strict:
|
||||
raise ValueError("路由参数类型只支持登录参数或主题参数")
|
||||
continue
|
||||
source = None if item.get("source") is None else str(item.get("source"))[:64]
|
||||
custom = None if item.get("customValue") is None else str(item.get("customValue"))[:2048]
|
||||
theme = None if item.get("themeValue") is None else str(item.get("themeValue"))[:2048]
|
||||
params.append(
|
||||
{
|
||||
"key": key,
|
||||
"paramType": param_type,
|
||||
"source": source if param_type == "login" else None,
|
||||
"customValue": custom if param_type == "login" and source == "other" else None,
|
||||
"themeValue": theme if param_type == "theme" else None,
|
||||
}
|
||||
)
|
||||
return {"url": url, "open_mode": mode, "route_params": params}
|
||||
|
||||
|
||||
class AgentConfig(BaseModel):
|
||||
"""Configuration for a custom agent."""
|
||||
|
||||
@@ -89,6 +208,10 @@ class AgentConfig(BaseModel):
|
||||
name: str
|
||||
description: str = ""
|
||||
model: str | None = None
|
||||
# Whether this agent inherits the administrator-configured prompt suffix
|
||||
# for its selected model. Existing configs omit the field, so True keeps
|
||||
# their current behavior without a migration.
|
||||
model_prompt_suffix_enabled: bool = True
|
||||
tool_groups: list[str] | None = None
|
||||
# skills controls which skills are loaded into a custom agent's prompt:
|
||||
# - None (or omitted): no skills (custom agents require explicit selection)
|
||||
@@ -112,6 +235,15 @@ class AgentConfig(BaseModel):
|
||||
# DeerFlow mapping ids this agent may offer in its new-conversation
|
||||
# knowledge selector. WeKnora ids and credentials never enter agent files.
|
||||
llmwiki_knowledge_base_ids: list[str] | None = None
|
||||
# Gallery 「对话」 button destination. None / empty url keeps the in-app chat.
|
||||
# ``open_mode`` is ``blank`` (new window) or ``self`` (current window).
|
||||
# ``route_params`` match light-app route params and are resolved in the browser.
|
||||
chat_link: dict[str, Any] | None = None
|
||||
|
||||
@field_validator("chat_link", mode="before")
|
||||
@classmethod
|
||||
def _normalize_chat_link(cls, value: Any) -> dict[str, Any] | None:
|
||||
return normalize_agent_chat_link(value, strict=False)
|
||||
|
||||
@field_validator("llmwiki_knowledge_base_ids")
|
||||
@classmethod
|
||||
|
||||
Reference in new issue
Block a user