feat: AI Notes 智能纪要链接自动获取与月记背景支持
- snooper_calendar.py: 新增 fetch_ai_notes_links(),优先从 AI Notes 会话获取纪要链接 - 支持 docx/minutes 格式,不限制三级域名 - 优先读本地缓存,本地无 topic 时从网络补充 - 按链接类型区分匹配窗口:permission_change ±24h,finish_recording ±6h - 具体主题要求与日历事件标题匹配,通用主题(视频会议)允许匹配 - 返回未匹配链接列表,供日报保留展示 - snooper_storage.py: 保存时从 content_data 提取 URL 和 topic 到 content - 递归遍历 bytes 提取 URL,避免 JSON 序列化丢失 - 新增 _extract_links_with_topics() 同时提取 URL 和会议主题 - lark_snooper.py: 未匹配链接插入今日会议章节的相关智能纪要子章节 - snooper_monthly.py: 新增 load_previous_monthly_background(),支持前5个工作日读取上月月记 - tests/test_calendar.py: 适配 fetch_calendar_events 返回 tuple
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
@ -12,6 +13,9 @@ from sqlalchemy import BigInteger, Column, DateTime, Integer, String, asc
|
||||
from snooper_client import extract_card_text
|
||||
|
||||
|
||||
_URL_RE = re.compile(r"https?://[A-Za-z0-9./_?=&%#:-]+")
|
||||
|
||||
|
||||
class SyncProgress(Base):
|
||||
__tablename__ = "sync_progress"
|
||||
|
||||
@ -29,6 +33,61 @@ class SnifferStorage(Storage):
|
||||
url = f"sqlite:///{db_path}"
|
||||
super().__init__(url)
|
||||
|
||||
def save_message(self, msg: dict, sender_name='', chat_name='', direction='in') -> bool:
|
||||
"""Save message, preserving URLs from card content_data in plain content."""
|
||||
content_data = msg.get('content_data')
|
||||
if content_data and (not msg.get('content') or msg.get('content') == '[卡片]'):
|
||||
urls = self._extract_urls_from_content_data(content_data)
|
||||
if urls:
|
||||
msg = dict(msg)
|
||||
msg['content'] = '\n'.join(urls)
|
||||
return super().save_message(msg, sender_name=sender_name, chat_name=chat_name, direction=direction)
|
||||
|
||||
@staticmethod
|
||||
def _extract_urls_from_content_data(data, urls=None):
|
||||
"""Recursively extract URLs from bytes in content_data."""
|
||||
if urls is None:
|
||||
urls = []
|
||||
if isinstance(data, bytes):
|
||||
try:
|
||||
text = data.decode('utf-8', errors='ignore')
|
||||
urls.extend(_URL_RE.findall(text))
|
||||
except Exception:
|
||||
pass
|
||||
elif isinstance(data, dict):
|
||||
for value in data.values():
|
||||
SnifferStorage._extract_urls_from_content_data(value, urls)
|
||||
elif isinstance(data, (list, tuple)):
|
||||
for item in data:
|
||||
SnifferStorage._extract_urls_from_content_data(item, urls)
|
||||
return urls
|
||||
|
||||
@staticmethod
|
||||
def _extract_links_with_topics(data, links=None):
|
||||
"""Recursively extract URLs with their following topic text from bytes."""
|
||||
if links is None:
|
||||
links = []
|
||||
if isinstance(data, bytes):
|
||||
try:
|
||||
text = data.decode('utf-8', errors='ignore')
|
||||
# Match URL followed by optional protobuf field marker and topic text
|
||||
pattern = re.compile(
|
||||
r"(https?://[A-Za-z0-9./_?=&%#:-]+)(?:\x12\x18([\u4e00-\u9fffA-Za-z0-9_\s\-()()]+))?"
|
||||
)
|
||||
for match in pattern.finditer(text):
|
||||
url = match.group(1)
|
||||
topic = match.group(2).strip() if match.group(2) else ""
|
||||
links.append({"url": url, "topic": topic})
|
||||
except Exception:
|
||||
pass
|
||||
elif isinstance(data, dict):
|
||||
for value in data.values():
|
||||
SnifferStorage._extract_links_with_topics(value, links)
|
||||
elif isinstance(data, (list, tuple)):
|
||||
for item in data:
|
||||
SnifferStorage._extract_links_with_topics(item, links)
|
||||
return links
|
||||
|
||||
def get_received_messages(
|
||||
self,
|
||||
start_ts: int,
|
||||
|
||||
Reference in New Issue
Block a user