新增 Jira 渠道扩展,支持在 Yuxi 平台中集成 Jira 项目管理渠道。 包含以下功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - outbound: 外发消息与工单管理 - streaming: 流式消息处理 - parse: Jira 内容解析 - format: 消息格式转换 - agent_tools: Agent 工具集成 - security: 安全校验 - dedupe: 消息去重 - loopbreaker: 循环响应防护 - monitor: 渠道状态监控 - status: 会话与工单状态管理 - types: 类型定义
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
import time
|
|
from collections import OrderedDict
|
|
|
|
from yuxi.channel.protocols import DedupeProtocol
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class JiraDeduplicator(DedupeProtocol):
|
|
def __init__(self, max_entries: int = 5000, ttl_seconds: int = 86400):
|
|
self._cache: OrderedDict[str, float] = OrderedDict()
|
|
self._max_entries = max_entries
|
|
self._ttl_seconds = ttl_seconds
|
|
|
|
@property
|
|
def ttl_seconds(self) -> int:
|
|
return self._ttl_seconds
|
|
|
|
@property
|
|
def max_entries(self) -> int:
|
|
return self._max_entries
|
|
|
|
def is_duplicate(self, key: str) -> bool:
|
|
if not key:
|
|
return False
|
|
now = time.monotonic()
|
|
self._evict_expired(now)
|
|
if key in self._cache:
|
|
return True
|
|
self._cache[key] = now
|
|
while len(self._cache) > self._max_entries:
|
|
self._cache.popitem(last=False)
|
|
return False
|
|
|
|
def mark_seen(self, key: str) -> None:
|
|
if not key:
|
|
return
|
|
now = time.monotonic()
|
|
self._evict_expired(now)
|
|
self._cache[key] = now
|
|
|
|
def _evict_expired(self, now: float):
|
|
expired = [k for k, v in self._cache.items() if now - v > self._ttl_seconds]
|
|
for k in expired:
|
|
del self._cache[k]
|
|
|
|
def reset(self):
|
|
self._cache.clear()
|
|
|
|
|
|
_deduplicators: dict[str, JiraDeduplicator] = {}
|
|
|
|
|
|
def get_deduplicator(account_id: str) -> JiraDeduplicator:
|
|
if account_id not in _deduplicators:
|
|
_deduplicators[account_id] = JiraDeduplicator()
|
|
return _deduplicators[account_id]
|