sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
@@ -9,6 +9,7 @@ SOUL 从当前 DeerFlow 智能体目录读取,避免维护两份行为规则
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
@@ -18,9 +19,9 @@ from pathlib import Path
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
BASE = "http://localhost:8001"
|
||||
USERNAME = "admin"
|
||||
PASSWORD = "123ewq"
|
||||
BASE = os.environ.get("DEERFLOW_SETUP_BASE", "http://localhost:8001").rstrip("/")
|
||||
USERNAME = os.environ.get("DEERFLOW_SETUP_USERNAME", "admin")
|
||||
PASSWORD = os.environ.get("DEERFLOW_SETUP_PASSWORD", "123ewq")
|
||||
AGENT_ID = "biz-detail-assistant"
|
||||
AGENT_NAME = "商业QB助理(全量检索版)"
|
||||
MAPPING_CODE = "3q-0"
|
||||
@@ -36,13 +37,21 @@ AGENT_DIR = Path(__file__).resolve().parents[1] / ".deer-flow" / "agents" / AGEN
|
||||
SOUL_PATH = AGENT_DIR / "SOUL.md"
|
||||
|
||||
|
||||
def call(method: str, path: str, body: dict | None, token: str | None):
|
||||
headers = {"Content-Type": "application/json", "Accept": "application/json"}
|
||||
def call(method: str, path: str, body: dict | None, token: str | None, *, form: dict | None = None):
|
||||
if body is not None and form is not None:
|
||||
raise ValueError("请求不能同时包含 JSON 与表单数据")
|
||||
headers = {"Accept": "application/json"}
|
||||
if form is not None:
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
data = urllib.parse.urlencode(form).encode()
|
||||
else:
|
||||
headers["Content-Type"] = "application/json"
|
||||
data = json.dumps(body).encode() if body is not None else None
|
||||
if token:
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
request = urllib.request.Request(
|
||||
BASE + path,
|
||||
data=json.dumps(body).encode() if body is not None else None,
|
||||
data=data,
|
||||
headers=headers,
|
||||
method=method,
|
||||
)
|
||||
@@ -63,13 +72,23 @@ def main() -> int:
|
||||
return 1
|
||||
soul = SOUL_PATH.read_text(encoding="utf-8")
|
||||
|
||||
query = urllib.parse.urlencode({"password": PASSWORD})
|
||||
status, login = call(
|
||||
"POST",
|
||||
f"/api/v1/auth/login/username?{query}",
|
||||
{"username": USERNAME},
|
||||
"/api/v1/auth/login/local",
|
||||
None,
|
||||
None,
|
||||
form={"username": USERNAME, "password": PASSWORD},
|
||||
)
|
||||
# 与两个任务详情技能保持一致:旧部署关闭密码登录、但仍开启 SSO 兼容直登时,
|
||||
# 仅对策略拒绝(403)回退;凭据错误、限流等失败不能绕过账号密码校验。
|
||||
if status == 403:
|
||||
query = urllib.parse.urlencode({"password": PASSWORD})
|
||||
status, login = call(
|
||||
"POST",
|
||||
f"/api/v1/auth/login/username?{query}",
|
||||
{"username": USERNAME},
|
||||
None,
|
||||
)
|
||||
if status != 200:
|
||||
print("登录失败", status, login)
|
||||
return 1
|
||||
|
||||
Reference in new issue
Block a user