feat: 从卡片文本提取智能纪要标题

This commit is contained in:
Benature
2026-11-29 00:13:59 +08:00
parent d79be58dfa
commit 313605f01b
3 changed files with 62 additions and 10 deletions

View File

@ -1 +1 @@
0.2.11
0.2.12

View File

@ -16,6 +16,7 @@ AI_NOTES_CHAT_ID = "7391681490647744513"
AI_NOTES_URL_RE = re.compile(
r"https://[A-Za-z0-9.-]+\.feishu\.cn/(?:docx|minutes)/[A-Za-z0-9]+(?:\?[^\s\x00-\x1f]*)?"
)
TOPIC_RE = re.compile(r"Topic:\s*([^\n]+?)(?=Owner:|\Z)")
def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
@ -35,6 +36,12 @@ def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
return resolved
def _extract_topic(text: str) -> str:
"""Extract a meeting topic from card text like 'Topic: 标题Owner: ...'."""
match = TOPIC_RE.search(text or "")
return match.group(1).strip() if match else ""
def fetch_ai_notes_links(
client: Any,
target_day: date,
@ -69,13 +76,15 @@ def fetch_ai_notes_links(
{"chat_id": chat_id, "start": start_ts, "end": end_ts},
)
for content, content_data, ts in result:
# Search content and content_data separately to avoid mixing with JSON
for text_to_search in (str(content or ""), str(content_data or "")):
text = str(content or "")
data_text = str(content_data or "")
topic = _extract_topic(text) or _extract_topic(data_text)
for text_to_search in (text, data_text):
for match in AI_NOTES_URL_RE.finditer(text_to_search):
url = match.group(0)
if url not in seen_urls:
seen_urls.add(url)
links.append({"url": url, "create_time": int(ts), "topic": ""})
links.append({"url": url, "create_time": int(ts), "topic": topic})
except Exception:
pass # Fall back to network if storage read fails
@ -133,7 +142,10 @@ def _fetch_ai_notes_links_from_network(
if ts:
batch_min_time = ts if batch_min_time is None else min(batch_min_time, ts)
if start_ts <= ts < end_ts:
content = str(msg.get("content") or "")
content_data = msg.get("content_data")
content_data_str = str(content_data or "")
topic = _extract_topic(content) or _extract_topic(content_data_str)
if content_data and storage is not None:
# Extract URLs with topics from raw content_data
extracted = storage._extract_links_with_topics(content_data)
@ -141,17 +153,15 @@ def _fetch_ai_notes_links_from_network(
url = item["url"]
if url not in seen_urls:
seen_urls.add(url)
links.append({"url": url, "create_time": ts, "topic": item.get("topic", "")})
links.append({"url": url, "create_time": ts, "topic": topic or item.get("topic", "")})
else:
# Fallback to plain text search
content = str(msg.get("content") or "")
content_data_str = str(content_data or "")
text_to_search = content + content_data_str
for match in AI_NOTES_URL_RE.finditer(text_to_search):
url = match.group(0)
if url not in seen_urls:
seen_urls.add(url)
links.append({"url": url, "create_time": ts, "topic": ""})
links.append({"url": url, "create_time": ts, "topic": topic})
if batch_min_time and batch_min_time < start_ts:
break
upper = lower - 1

View File

@ -1,7 +1,49 @@
from datetime import date
from datetime import date, datetime
from zoneinfo import ZoneInfo
from snooper_calendar import fetch_calendar_events
from snooper_calendar import (
AI_NOTES_CHAT_ID,
_extract_topic,
fetch_ai_notes_links,
fetch_calendar_events,
)
from snooper_storage import SnifferStorage
def test_extract_topic_from_card_text():
text = (
"[卡片]\nMeeting recording completed"
"Topic: 指数-金科定期AI业务讨论会Owner: 万轶伦"
)
assert _extract_topic(text) == "指数-金科定期AI业务讨论会"
assert _extract_topic("https://efund.feishu.cn/docx/abc") == ""
def test_fetch_ai_notes_links_reads_topic_from_local_content():
tz = ZoneInfo("Asia/Shanghai")
storage = SnifferStorage(url="sqlite:///:memory:")
ts = int(datetime(2026, 11, 17, 14, 0, tzinfo=tz).timestamp())
storage.save_message({
"msg_id": "minutes-1",
"chat_id": AI_NOTES_CHAT_ID,
"chat_type": 2,
"from_id": "bot",
"msg_type": 14,
"create_time": ts,
"content": (
"[卡片]\nMeeting recording completed"
"Topic: 指数-金科定期AI业务讨论会Owner: 万轶伦\n"
"https://efund.feishu.cn/minutes/abc123"
),
})
links = fetch_ai_notes_links(
object(), date(2026, 11, 17), tz, storage=storage
)
assert len(links) == 1
assert links[0]["url"].startswith("https://efund.feishu.cn/minutes/abc123")
assert links[0]["topic"] == "指数-金科定期AI业务讨论会"
class FakeCalendarClient: