新增 Jira 渠道扩展,支持在 Yuxi 平台中集成 Jira 项目管理渠道。 包含以下功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - outbound: 外发消息与工单管理 - streaming: 流式消息处理 - parse: Jira 内容解析 - format: 消息格式转换 - agent_tools: Agent 工具集成 - security: 安全校验 - dedupe: 消息去重 - loopbreaker: 循环响应防护 - monitor: 渠道状态监控 - status: 会话与工单状态管理 - types: 类型定义
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.protocols import SecurityProtocol
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class JiraSecurity(SecurityProtocol):
|
|
def __init__(self):
|
|
self._allowed_projects: set[str] = set()
|
|
|
|
def configure(self, allowed_projects: list[str]):
|
|
self._allowed_projects = set(p.upper() for p in allowed_projects)
|
|
|
|
def is_project_allowed(self, project_key: str) -> bool:
|
|
if not self._allowed_projects:
|
|
return True
|
|
return project_key.upper() in self._allowed_projects
|
|
|
|
def is_self_authored(self, author_account_id: str, bot_account_id: str) -> bool:
|
|
return author_account_id == bot_account_id
|
|
|
|
def is_ai_comment(self, properties: list[dict]) -> bool:
|
|
for prop in properties:
|
|
if prop.get("key") == "ai.agent":
|
|
return True
|
|
return False
|
|
|
|
def is_self_changelog(self, changelog_items: list[dict], bot_account_id: str) -> bool:
|
|
for item in changelog_items:
|
|
author = item.get("author", {})
|
|
if author.get("accountId") == bot_account_id:
|
|
return True
|
|
return False
|
|
|
|
async def check_allowlist(self, peer_id: str, channel_type: str) -> bool:
|
|
return True
|
|
|
|
def resolve_dm_policy(self) -> dict:
|
|
return {"mode": "open", "allow_from": []}
|
|
|
|
def apply_config_fixes(self, config: dict) -> dict:
|
|
return config
|
|
|
|
def collect_warnings(self, config: dict, account_id: str | None = None, account: dict | None = None) -> list[str]:
|
|
warnings = []
|
|
if not account:
|
|
return warnings
|
|
if not account.get("allowed_projects"):
|
|
warnings.append("未设置 allowedProjects — Bot 将响应所有项目的 Issue")
|
|
return warnings
|
|
|
|
def collect_audit_findings(
|
|
self,
|
|
config: dict,
|
|
account_id: str | None = None,
|
|
account: dict | None = None,
|
|
source_config: dict | None = None,
|
|
ordered_account_ids: list[str] | None = None,
|
|
has_explicit_account_path: bool = False,
|
|
) -> list[dict]:
|
|
return []
|