新增了完整的Confluence集成插件,包含以下核心功能: 1. 基础认证与配置管理,支持API Token和OAuth2两种认证方式 2. 评论去重、权限控制与提及解析 3. 知识库检索与页面内容处理 4. 评论收发、编辑删除与流式回复支持 5. 附件与页面标签管理 6. 内容属性存储与AI元数据管理 7. Webhook事件接收与处理 8. 完整的插件配置与状态检查
98 lines
3.2 KiB
Python
98 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from yuxi.channel.extensions.confluence.gateway import ConfluenceClient
|
|
from yuxi.channel.extensions.confluence.types import ConfluenceAccount
|
|
|
|
|
|
@dataclass
|
|
class ChannelAccountSnapshot:
|
|
account_id: str
|
|
configured: bool
|
|
status_state: str
|
|
running: bool
|
|
connected: bool
|
|
health_state: str
|
|
dm_policy: str
|
|
|
|
|
|
class ConfluenceStatus:
|
|
async def probe(
|
|
self,
|
|
account: ConfluenceAccount,
|
|
client: ConfluenceClient,
|
|
) -> dict:
|
|
if not account.is_configured:
|
|
return {"success": False, "error": "Not configured"}
|
|
|
|
try:
|
|
spaces = await client.get_spaces(limit=1)
|
|
total = spaces.get("meta", {}).get("total_count", -1) if "meta" in spaces else -1
|
|
return {"success": True, "total_spaces": total}
|
|
except Exception as e:
|
|
return {"success": False, "error": str(e)}
|
|
|
|
async def check_space_permissions(
|
|
self,
|
|
account: ConfluenceAccount,
|
|
client: ConfluenceClient,
|
|
) -> list[dict]:
|
|
results = []
|
|
for space_key in account.space_keys:
|
|
try:
|
|
cql = f'space = "{space_key}" AND type = "page"'
|
|
search = await client.cql_search(cql, limit=1)
|
|
results.append(
|
|
{
|
|
"space_key": space_key,
|
|
"accessible": len(search.get("results", [])) > 0,
|
|
"error": None,
|
|
}
|
|
)
|
|
except Exception as e:
|
|
results.append(
|
|
{
|
|
"space_key": space_key,
|
|
"accessible": False,
|
|
"error": str(e),
|
|
}
|
|
)
|
|
return results
|
|
|
|
def build_account_snapshot(
|
|
self,
|
|
account: ConfluenceAccount,
|
|
running: bool,
|
|
probe_result: dict,
|
|
) -> ChannelAccountSnapshot:
|
|
return ChannelAccountSnapshot(
|
|
account_id=account.account_id,
|
|
configured=account.is_configured,
|
|
status_state="linked" if running else "stopped",
|
|
running=running,
|
|
connected=probe_result.get("success", False),
|
|
health_state="ok" if probe_result.get("success") else "unknown",
|
|
dm_policy=account.comment_policy,
|
|
)
|
|
|
|
def collect_status_issues(
|
|
self,
|
|
account: ConfluenceAccount,
|
|
probe_result: dict,
|
|
running: bool,
|
|
) -> list[str]:
|
|
issues = []
|
|
if not account.is_configured:
|
|
issues.append("未配置:请设置 CONFLUENCE_URL, CONFLUENCE_EMAIL, CONFLUENCE_API_TOKEN")
|
|
if not probe_result.get("success"):
|
|
issues.append(f"API 连通性检查失败: {probe_result.get('error', 'Unknown error')}")
|
|
if not running:
|
|
issues.append("Gateway 未启动")
|
|
if account.space_keys and probe_result.get("success"):
|
|
space_list = ", ".join(account.space_keys)
|
|
issues.append(f"监听空间: {space_list},请确认 Bot 用户对各空间有 View + Add Comments 权限")
|
|
return issues
|