|
| 1 | +export type NoteTag = { tag: string }; |
| 2 | + |
| 3 | +const SUMMARY_NOTE_TAG = "AI-Generated"; |
| 4 | +const TABLE_NOTE_TAG = "AI-Table"; |
| 5 | +const CHAT_NOTE_TAG = "AI-Butler-Chat"; |
| 6 | +const MINDMAP_NOTE_TAG = "AI-Mindmap"; |
| 7 | +const IMAGE_NOTE_TAGS = ["AI-Image-Summary", "AI-ImageSummary"]; |
| 8 | + |
| 9 | +const AI_BUTLER_SUMMARY_HEADING_RE = /<h2>\s*AI\s*管家\s*-\s*(?!后续追问)/; |
| 10 | +const AI_BUTLER_CHAT_HEADING_RE = |
| 11 | + /<h2>\s*AI\s*管家\s*-\s*后续追问(?:\s*-|\s*笔记|[\s<])/; |
| 12 | +const AI_BUTLER_MINDMAP_HEADING_RE = /AI\s*管家思维导图\s*-/; |
| 13 | +const AI_BUTLER_IMAGE_HEADING_RE = /AI\s*管家一图总结\s*-/; |
| 14 | + |
| 15 | +export function hasNoteTag(tags: NoteTag[], tag: string): boolean { |
| 16 | + return tags.some((t) => t.tag === tag); |
| 17 | +} |
| 18 | + |
| 19 | +export function isFollowUpChatNote(tags: NoteTag[], noteHtml: string): boolean { |
| 20 | + const hasSummaryTag = hasNoteTag(tags, SUMMARY_NOTE_TAG); |
| 21 | + return ( |
| 22 | + hasNoteTag(tags, CHAT_NOTE_TAG) || |
| 23 | + (!hasSummaryTag && AI_BUTLER_CHAT_HEADING_RE.test(noteHtml)) |
| 24 | + ); |
| 25 | +} |
| 26 | + |
| 27 | +export function isRegularSummaryNote( |
| 28 | + tags: NoteTag[], |
| 29 | + noteHtml: string, |
| 30 | +): boolean { |
| 31 | + const isTableNote = hasNoteTag(tags, TABLE_NOTE_TAG); |
| 32 | + const isMindmapNote = |
| 33 | + hasNoteTag(tags, MINDMAP_NOTE_TAG) || |
| 34 | + AI_BUTLER_MINDMAP_HEADING_RE.test(noteHtml); |
| 35 | + const isImageNote = |
| 36 | + IMAGE_NOTE_TAGS.some((tag) => hasNoteTag(tags, tag)) || |
| 37 | + AI_BUTLER_IMAGE_HEADING_RE.test(noteHtml); |
| 38 | + |
| 39 | + if ( |
| 40 | + isTableNote || |
| 41 | + isMindmapNote || |
| 42 | + isImageNote || |
| 43 | + isFollowUpChatNote(tags, noteHtml) |
| 44 | + ) { |
| 45 | + return false; |
| 46 | + } |
| 47 | + |
| 48 | + return ( |
| 49 | + hasNoteTag(tags, SUMMARY_NOTE_TAG) || |
| 50 | + AI_BUTLER_SUMMARY_HEADING_RE.test(noteHtml) |
| 51 | + ); |
| 52 | +} |
0 commit comments