fix agent: remove UUID requirement, add Notion connection check

This commit is contained in:
root 2026-05-19 19:35:14 +08:00
parent bf6b686030
commit d9047c3ef5

View File

@ -26,10 +26,12 @@ SYSTEM_PROMPT = """你是铸渊(Zhùyuān),光湖语言世界的引导主
【Notion 能力】(重要)
- 用户需要在首页点击「连接 Notion」授权后才能使用
- 当用户说"读取我的Notion"或"搜索我的Notion"时,先让用户提供具体的页面ID或关键词
- 用户提供页面ID(32位UUID格式)后,调用内部接口读取
- 用户提供关键词后,调用内部接口搜索
- ⚠ 权限限制: 你只能读取用户明确指定的页面,不能编辑/删除现有页面
- ⚠ 如果 Notion 未连接,如实告知用户先连接 Notion,不要假装能操作
- 当用户说「打开我的Notion」「搜索我的Notion里关于XXX」时,铸渊会自动读取或搜索
- 用户只需自然描述,不需要提供任何ID或UUID
- 铸渊读取页面后会把内容呈现给用户,搜索后列出结果让用户选择
- 如果用户说「新建XXX」,铸渊会引导提供标题和内容
- ⚠ 权限限制: 只能读取和新建页面,不能编辑/删除现有页面
- 回答风格:直接、务实、有条理。"""
# ── 知识库 ──
@ -74,8 +76,25 @@ def call_notion(endpoint, data):
except Exception as e:
return {"ok": False, "error": str(e)}
def check_notion_connected():
"""检查Notion是否真的已连接,返回(connected, workspace_name)"""
try:
req = urllib.request.Request(f"{NOTION_MCP}/status")
resp = urllib.request.urlopen(req, timeout=5)
data = json.loads(resp.read())
if data.get("connected_users") and len(data["connected_users"]) > 0:
return True, data["connected_users"][0].get("workspace", "未知工作区")
return False, None
except Exception:
return False, None
def handle_notion_action(msg, user):
"""检测并执行Notion操作 — 自然语言触发,无需UUID"""
# 先检查 Notion 是否真正连接
connected, workspace = check_notion_connected()
if not connected:
return {"ok": True, "reply": "❌ Notion 尚未连接,铸渊无法操作。\n\n请先在首页点击 **「连接 Notion」** 按钮完成 OAuth 授权。授权后告诉铸渊「搜索我的Notion」即可开始。"}
msg_l = msg.lower()
has_notion = "notion" in msg_l