Compare commits

...

22 Commits

Author SHA1 Message Date
cc
e3441e03e1 Merge pull request #1008 from Jasonzhu1207/main
feat: AI Summaries for Group Chats
2026-05-23 22:23:23 +08:00
Jason
fbd3b78b87 fix: Group Chat Summary 2026-05-23 17:57:24 +08:00
cc
90b309064b Merge branch 'dev' of https://github.com/hicccc77/WeFlow into dev 2026-05-23 09:58:09 +08:00
cc
5f8b27de80 修复朋友圈图片正则匹配 2026-05-23 09:58:04 +08:00
cc
738ea01f5d Merge pull request #1003 from Moxiaoyuan1003/fix/sns-thumb-and-backup-v2
fix: 修复朋友圈图片显示"已删除"和数据库备份卡住的两个 Bug
2026-05-23 02:03:14 +08:00
Moxiaoyuan1003
9cb6f04674 Merge branch 'dev' into fix/sns-thumb-and-backup-v2 2026-05-23 00:32:06 +08:00
Jason
87b39196c1 feat: Add AI Summaries for Group Chats 2026-05-22 23:50:49 +08:00
墨洛洛
89eef5a922 fix: 修复朋友圈图片显示"已删除"和数据库备份卡住的两个 Bug
1. snsService.ts: fixSnsUrl 正则只处理 /150 缩略图路径,
   实际 CDN 返回 /200 导致 HTTP 400,改为支持 /150|200|480

2. backupService.ts: inspectBackup 缺少完成事件导致界面卡死,
   ensureConnected 中 accountDirName 变量名未定义
2026-05-22 22:14:53 +08:00
cc
2e7d6ae62b Merge pull request #998 from Jasonzhu1207/main
feat: Add manually trigger AI insights in conversations
2026-05-22 17:47:45 +08:00
Jason
52ba55ee80 feat: Add manually trigger AI insights in conversations 2026-05-21 00:10:17 +08:00
cc
628bcdd90a 修复导出页函数传参错误 2026-05-20 23:02:52 +08:00
cc
95a9d04afe Merge pull request #989 from Jasonzhu1207/main
fix: ExportDate Page
2026-05-20 21:41:17 +08:00
Jason
9ca6581643 fix: ExportDate Page 2026-05-19 23:07:50 +08:00
Jason
4424d9d205 fix: ExportDate Page 2026-05-19 00:04:02 +08:00
H3CoF6
75136ad834 Merge pull request #977 from TMYTiMidlY/fix/linux-key-service-packaged-build
fix(linux): initialize key service in packaged builds
2026-05-18 02:03:11 +08:00
cc
1d7bed8434 Merge pull request #979 from Jasonzhu1207/main
feat: Add Chat Analysis
2026-05-17 23:30:20 +08:00
Jason
0cf338b94c fix: Chat Analysis 2026-05-17 23:17:34 +08:00
Jason
a07a6de645 fix: Mailbox Message Location 2026-05-17 22:45:27 +08:00
Jason
a300d3c5d3 fix: Chat Analysis 2026-05-17 21:32:31 +08:00
Jason
1df4f0e523 feat: Add Chat Analysis 2026-05-17 21:04:14 +08:00
TMYTiMidlY
7eeec7d930 fix(linux): initialize key service in packaged builds 2026-05-17 14:11:55 +08:00
cc
d008359d70 修复:足迹页面分段失效的问题;#972 #974 所提到的问题;数据库备份中目录错误的问题;
优化:足迹页面的索引扫描性能;导出页面的消息缓存逻辑
2026-05-17 11:54:42 +08:00
32 changed files with 4474 additions and 147 deletions

View File

@@ -16,6 +16,7 @@ interface ExportWorkerConfig {
resourcesPath?: string
userDataPath?: string
logEnabled?: boolean
isPackaged?: boolean
}
const config = workerData as ExportWorkerConfig
@@ -150,7 +151,10 @@ async function run() {
decryptKey: config.decryptKey,
myWxid: config.myWxid,
imageXorKey: config.imageXorKey,
imageAesKey: config.imageAesKey
imageAesKey: config.imageAesKey,
resourcesPath: config.resourcesPath,
appPath: config.resourcesPath ? require('path').dirname(config.resourcesPath) : __dirname,
isPackaged: config.isPackaged
})
const onProgress = (progress: any) => queueProgress(progress)
@@ -173,7 +177,10 @@ async function run() {
chatService.setRuntimeConfig({
dbPath: config.dbPath,
decryptKey: config.decryptKey,
myWxid: config.myWxid
myWxid: config.myWxid,
resourcesPath: config.resourcesPath,
appPath: config.resourcesPath ? require('path').dirname(config.resourcesPath) : __dirname,
isPackaged: config.isPackaged
})
result = await contactExportService.exportContacts(
String(config.outputDir || ''),

View File

@@ -32,6 +32,7 @@ import { httpService } from './services/httpService'
import { messagePushService } from './services/messagePushService'
import { insightService } from './services/insightService'
import { insightRecordService } from './services/insightRecordService'
import { groupSummaryService } from './services/groupSummaryService'
import { normalizeWeiboCookieInput, weiboService } from './services/social/weiboService'
import { bizService } from './services/bizService'
import { backupService } from './services/backupService'
@@ -397,13 +398,7 @@ let keyService: any
if (process.platform === 'darwin') {
keyService = new KeyServiceMac()
} else if (process.platform === 'linux') {
// const { KeyServiceLinux } = require('./services/keyServiceLinux')
// keyService = new KeyServiceLinux()
import('./services/keyServiceLinux').then(({ KeyServiceLinux }) => {
keyService = new KeyServiceLinux();
});
keyService = new KeyServiceLinux()
} else {
keyService = new KeyService()
}
@@ -1775,6 +1770,7 @@ function registerIpcHandlers() {
}
void messagePushService.handleConfigChanged(key)
void insightService.handleConfigChanged(key)
void groupSummaryService.handleConfigChanged(key)
return result
})
@@ -1792,6 +1788,7 @@ function registerIpcHandlers() {
sessionId?: string
startTime?: number
endTime?: number
sourceType?: 'insight' | 'message_analysis' | 'all'
limit?: number
offset?: number
}) => {
@@ -1818,6 +1815,14 @@ function registerIpcHandlers() {
return insightService.triggerTest()
})
ipcMain.handle('insight:triggerSessionInsight', async (_, payload: {
sessionId: string
displayName?: string
avatarUrl?: string
}) => {
return insightService.triggerSessionInsight(payload)
})
ipcMain.handle('insight:generateFootprintInsight', async (_, payload: {
rangeLabel: string
summary: {
@@ -1834,6 +1839,54 @@ function registerIpcHandlers() {
return insightService.generateFootprintInsight(payload)
})
ipcMain.handle('insight:generateMessageInsight', async (_, payload: {
sessionId: string
displayName?: string
avatarUrl?: string
targetLocalId?: number
targetCreateTime?: number
targetMessageKey?: string
targetText: string
targetSenderName?: string
contextCount?: number
forceRefresh?: boolean
}) => {
return insightService.generateMessageInsight(payload)
})
ipcMain.handle('groupSummary:listRecords', async (_, filters?: {
sessionId?: string
startTime?: number
endTime?: number
limit?: number
offset?: number
}) => {
return groupSummaryService.listRecords(filters || {})
})
ipcMain.handle('groupSummary:getRecord', async (_, id: string) => {
return groupSummaryService.getRecord(id)
})
ipcMain.handle('groupSummary:triggerManual', async (_, payload: {
sessionId: string
displayName?: string
avatarUrl?: string
startTime: number
endTime: number
}) => {
return groupSummaryService.triggerManual(payload)
})
ipcMain.handle('groupSummary:triggerDay', async (_, payload: {
sessionId: string
displayName?: string
avatarUrl?: string
date: string
}) => {
return groupSummaryService.triggerDay(payload)
})
ipcMain.handle('social:saveWeiboCookie', async (_, rawInput: string) => {
try {
if (!configService) {
@@ -1870,6 +1923,7 @@ function registerIpcHandlers() {
configService?.clear()
messagePushService.handleConfigCleared()
insightService.handleConfigCleared()
groupSummaryService.handleConfigCleared()
return true
})
@@ -2349,8 +2403,8 @@ function registerIpcHandlers() {
return chatService.getContactTypeCounts()
})
ipcMain.handle('chat:getSessionMessageCounts', async (_, sessionIds: string[]) => {
return chatService.getSessionMessageCounts(sessionIds)
ipcMain.handle('chat:getSessionMessageCounts', async (_, sessionIds: string[], options?: { preferHintCache?: boolean; bypassSessionCache?: boolean }) => {
return chatService.getSessionMessageCounts(sessionIds, options)
})
ipcMain.handle('chat:enrichSessionsContactInfo', async (_, usernames: string[], options?: {
@@ -3213,7 +3267,8 @@ function registerIpcHandlers() {
imageAesKey: imageKeys.aesKey,
resourcesPath,
userDataPath,
logEnabled
logEnabled,
isPackaged: app.isPackaged
}
})
@@ -3344,7 +3399,8 @@ function registerIpcHandlers() {
imageAesKey: imageKeys.aesKey,
resourcesPath: app.isPackaged ? join(process.resourcesPath, 'resources') : join(app.getAppPath(), 'resources'),
userDataPath: app.getPath('userData'),
logEnabled: cfg.get('logEnabled')
logEnabled: cfg.get('logEnabled'),
isPackaged: app.isPackaged
}
})
@@ -3411,7 +3467,8 @@ function registerIpcHandlers() {
myWxid: String(cfg.getMyWxidCleaned() || '').trim(),
resourcesPath: app.isPackaged ? join(process.resourcesPath, 'resources') : join(app.getAppPath(), 'resources'),
userDataPath: app.getPath('userData'),
logEnabled: cfg.get('logEnabled')
logEnabled: cfg.get('logEnabled'),
isPackaged: app.isPackaged
}
})
@@ -4202,6 +4259,7 @@ app.whenReady().then(async () => {
})
messagePushService.start()
insightService.start()
groupSummaryService.start()
await delay(200)
// 已完成引导时,在 Splash 阶段预热核心数据(联系人、消息库索引等)
@@ -4360,6 +4418,7 @@ const shutdownAppServices = async (): Promise<void> => {
destroyNotificationWindow()
messagePushService.stop()
insightService.stop()
groupSummaryService.stop()
// 兜底5秒后强制退出防止某个异步任务卡住导致进程残留
const forceExitTimer = setTimeout(() => {
console.warn('[App] Force exit after timeout')

View File

@@ -195,7 +195,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
getSessionStatuses: (usernames: string[]) => ipcRenderer.invoke('chat:getSessionStatuses', usernames),
getExportTabCounts: () => ipcRenderer.invoke('chat:getExportTabCounts'),
getContactTypeCounts: () => ipcRenderer.invoke('chat:getContactTypeCounts'),
getSessionMessageCounts: (sessionIds: string[]) => ipcRenderer.invoke('chat:getSessionMessageCounts', sessionIds),
getSessionMessageCounts: (sessionIds: string[], options?: { preferHintCache?: boolean; bypassSessionCache?: boolean }) => ipcRenderer.invoke('chat:getSessionMessageCounts', sessionIds, options),
enrichSessionsContactInfo: (
usernames: string[],
options?: { skipDisplayName?: boolean; onlyMissingAvatar?: boolean }
@@ -583,6 +583,11 @@ contextBridge.exposeInMainWorld('electronAPI', {
markRecordRead: (id: string) => ipcRenderer.invoke('insight:markRecordRead', id),
clearRecords: (filters?: any) => ipcRenderer.invoke('insight:clearRecords', filters),
triggerTest: () => ipcRenderer.invoke('insight:triggerTest'),
triggerSessionInsight: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
}) => ipcRenderer.invoke('insight:triggerSessionInsight', payload),
generateFootprintInsight: (payload: {
rangeLabel: string
summary: {
@@ -595,7 +600,37 @@ contextBridge.exposeInMainWorld('electronAPI', {
}
privateSegments?: Array<{ displayName?: string; session_id?: string; incoming_count?: number; outgoing_count?: number; message_count?: number; replied?: boolean }>
mentionGroups?: Array<{ displayName?: string; session_id?: string; count?: number }>
}) => ipcRenderer.invoke('insight:generateFootprintInsight', payload)
}) => ipcRenderer.invoke('insight:generateFootprintInsight', payload),
generateMessageInsight: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
targetLocalId?: number
targetCreateTime?: number
targetMessageKey?: string
targetText: string
targetSenderName?: string
contextCount?: number
forceRefresh?: boolean
}) => ipcRenderer.invoke('insight:generateMessageInsight', payload)
},
groupSummary: {
listRecords: (filters?: any) => ipcRenderer.invoke('groupSummary:listRecords', filters),
getRecord: (id: string) => ipcRenderer.invoke('groupSummary:getRecord', id),
triggerManual: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
startTime: number
endTime: number
}) => ipcRenderer.invoke('groupSummary:triggerManual', payload),
triggerDay: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
date: string
}) => ipcRenderer.invoke('groupSummary:triggerDay', payload)
},
social: {

View File

@@ -460,6 +460,7 @@ export class BackupService {
const dbStorage = join(accountDir, 'db_storage')
if (!existsSync(dbStorage)) return { success: false, error: '未找到 db_storage 目录' }
const accountDirName = basename(accountDir)
const opened = await withTimeout(
wcdbService.open(accountDir, decryptKey),
15000,
@@ -467,10 +468,10 @@ export class BackupService {
)
if (!opened) {
const detail = await wcdbService.getLastInitError().catch(() => null)
return { success: false, error: detail || `目标账号 ${accountDirName} 数据库连接失败` }
return { success: false, error: detail || `目标账号 ${accountDir} 数据库连接失败` }
}
return { success: true, wxid: accountDirName, dbPath, dbStorage }
return { success: true, wxid: accountDir, dbPath, dbStorage }
}
private buildDbId(kind: BackupDbKind, index: number, dbPath: string): string {
@@ -857,10 +858,13 @@ export class BackupService {
if (!existsSync(manifestPath)) return { success: false, error: '备份包缺少 manifest.json' }
const manifest = JSON.parse(await readFileAsync(manifestPath, 'utf8')) as BackupManifest
if (manifest?.type !== 'weflow-db-snapshots' || manifest.version !== 1) {
emitBackupProgress({ phase: 'failed', message: '不支持的备份包格式' })
return { success: false, error: '不支持的备份包格式' }
}
emitBackupProgress({ phase: 'done', message: '备份包已读取' })
return { success: true, manifest }
} catch (e) {
emitBackupProgress({ phase: 'failed', message: e instanceof Error ? e.message : String(e) })
return { success: false, error: e instanceof Error ? e.message : String(e) }
} finally {
if (extractDir) {

View File

@@ -1,5 +1,6 @@
import { join, dirname, basename, extname } from 'path'
import { existsSync, mkdirSync, readdirSync, statSync, readFileSync, writeFileSync, copyFileSync, unlinkSync, watch, promises as fsPromises } from 'fs'
import { createRequire } from 'module'
import * as path from 'path'
import * as fs from 'fs'
import * as https from 'https'
@@ -453,7 +454,7 @@ class ChatService {
this.voiceTranscriptCache = new LRUCache(1000) // 最多缓存1000条转写记录
}
setRuntimeConfig(config: { dbPath?: string; decryptKey?: string; myWxid?: string }): void {
setRuntimeConfig(config: { dbPath?: string; decryptKey?: string; myWxid?: string; resourcesPath?: string; appPath?: string; isPackaged?: boolean }): void {
this.runtimeConfig = config
}
@@ -2585,6 +2586,93 @@ class ChatService {
}
}
async getMessagesAround(
sessionId: string,
target: { localId?: number; createTime: number; messageKey?: string },
totalContextCount: number = 50
): Promise<{
success: boolean
before: Message[]
after: Message[]
requested: number
error?: string
}> {
const requested = Math.max(1, Math.min(200, Math.floor(Number(totalContextCount) || 50)))
const targetCreateTime = Math.floor(Number(target?.createTime || 0))
if (!sessionId || targetCreateTime <= 0) {
return { success: false, before: [], after: [], requested, error: '无效的目标消息' }
}
const collect = async (ascending: boolean): Promise<Message[]> => {
let cursor: number | undefined
try {
const cursorResult = await wcdbService.openMessageCursorLite(
sessionId,
Math.min(240, Math.max(60, requested + 20)),
ascending,
ascending ? targetCreateTime : 0,
ascending ? 0 : targetCreateTime + 1
)
if (!cursorResult.success || !cursorResult.cursor) {
throw new Error(cursorResult.error || '打开消息游标失败')
}
cursor = cursorResult.cursor
const collected = await this.collectVisibleMessagesFromCursor(sessionId, cursor, requested + 1)
if (!collected.success) {
throw new Error(collected.error || '读取上下文消息失败')
}
const targetLocalId = Math.floor(Number(target?.localId || 0))
const targetMessageKey = String(target?.messageKey || '').trim()
return (collected.messages || []).filter((message) => {
const sameLocalId = targetLocalId > 0 && Number(message.localId || 0) === targetLocalId
const sameCreateTime = Number(message.createTime || 0) === targetCreateTime
const sameKey = Boolean(targetMessageKey && message.messageKey === targetMessageKey)
return !(sameKey || (sameLocalId && sameCreateTime))
})
} finally {
if (cursor) {
await wcdbService.closeMessageCursor(cursor).catch(() => {})
}
}
}
try {
const [beforeCandidatesRaw, afterCandidatesRaw] = await Promise.all([
collect(false),
collect(true)
])
const beforeCandidates = beforeCandidatesRaw
.filter((message) => Number(message.createTime || 0) <= targetCreateTime)
.sort((a, b) => (a.createTime - b.createTime) || (a.sortSeq - b.sortSeq))
const afterCandidates = afterCandidatesRaw
.filter((message) => Number(message.createTime || 0) >= targetCreateTime)
.sort((a, b) => (a.createTime - b.createTime) || (a.sortSeq - b.sortSeq))
const baseBefore = Math.floor(requested / 2)
const baseAfter = requested - baseBefore
const takeAfter = Math.min(baseAfter, afterCandidates.length)
const takeBefore = Math.min(requested - takeAfter, beforeCandidates.length)
const remainingAfter = Math.max(0, requested - takeBefore - takeAfter)
const finalAfter = Math.min(afterCandidates.length, takeAfter + remainingAfter)
const finalBefore = Math.min(beforeCandidates.length, requested - finalAfter)
return {
success: true,
before: beforeCandidates.slice(Math.max(0, beforeCandidates.length - finalBefore)),
after: afterCandidates.slice(0, finalAfter),
requested
}
} catch (error) {
return {
success: false,
before: [],
after: [],
requested,
error: (error as Error).message || String(error)
}
}
}
async getNewMessages(sessionId: string, minTime: number, limit: number = this.messageBatchDefault): Promise<{ success: boolean; messages?: Message[]; error?: string }> {
try {
const connectResult = await this.ensureConnected()
@@ -8613,13 +8701,17 @@ class ChatService {
private async decodeSilkToPcm(silkData: Buffer, sampleRate: number): Promise<Buffer | null> {
try {
let wasmPath: string
if (app.isPackaged) {
wasmPath = join(process.resourcesPath, 'app.asar.unpacked', 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
const isPackaged = this.runtimeConfig?.isPackaged ?? app.isPackaged
const resourcesPath = this.runtimeConfig?.resourcesPath ?? process.resourcesPath
const appPath = this.runtimeConfig?.appPath ?? app.getAppPath()
if (isPackaged) {
wasmPath = join(resourcesPath, 'app.asar.unpacked', 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
if (!existsSync(wasmPath)) {
wasmPath = join(process.resourcesPath, 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
wasmPath = join(resourcesPath, 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
}
} else {
wasmPath = join(app.getAppPath(), 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
wasmPath = join(appPath, 'node_modules', 'silk-wasm', 'lib', 'silk.wasm')
}
if (!existsSync(wasmPath)) {
@@ -8627,7 +8719,9 @@ class ChatService {
return null
}
const silkWasm = require('silk-wasm')
// 在 worker 环境中使用 createRequire 来正确加载模块
const requireFromApp = createRequire(join(appPath, 'package.json'))
const silkWasm = requireFromApp('silk-wasm')
if (!silkWasm || !silkWasm.decode) {
console.error('[ChatService][Voice] silk-wasm module invalid')
return null
@@ -9456,12 +9550,13 @@ class ChatService {
data = this.filterMyFootprintMentionsBySource(nativeRaw, myWxid, mentionLimit)
if (privateSessionIds.length > 0 && data.private_segments.length === 0) {
if (data.private_sessions.length > 0) {
const sessionsWithMessages = data.private_sessions.map(s => s.session_id)
const privateSegments = await this.rebuildMyFootprintPrivateSegments({
begin,
end: normalizedEnd,
myWxid,
privateSessionIds
privateSessionIds: sessionsWithMessages
})
if (privateSegments.length > 0) {
data = {
@@ -9561,7 +9656,7 @@ class ChatService {
myWxid: string
privateSessionIds: string[]
}): Promise<MyFootprintPrivateSegment[]> {
const sessionGapSeconds = 10 * 60
const sessionGapSeconds = 5 * 60
const segments: MyFootprintPrivateSegment[] = []
type WorkingSegment = {
@@ -9579,14 +9674,17 @@ class ChatService {
}
for (const sessionId of params.privateSessionIds) {
const cursorResult = await wcdbService.openMessageCursorLite(
const cursorResult = await wcdbService.openMessageCursor(
sessionId,
360,
true,
params.begin,
params.end
0,
0
)
if (!cursorResult.success || !cursorResult.cursor) continue
if (!cursorResult.success || !cursorResult.cursor) {
console.log(`[足迹分段] 打开游标失败: ${sessionId}, 原因: ${cursorResult.error || '未知'}`)
continue
}
let segmentCursor = 0
let active: WorkingSegment | null = null
@@ -9620,19 +9718,30 @@ class ChatService {
}
let hasMore = true
let batchCount = 0
let totalMessages = 0
try {
while (hasMore) {
const batchResult = await wcdbService.fetchMessageBatch(cursorResult.cursor)
batchCount++
if (!batchResult.success || !Array.isArray(batchResult.rows)) break
hasMore = Boolean(batchResult.hasMore)
totalMessages += batchResult.rows.length
for (const row of batchResult.rows as Array<Record<string, any>>) {
const createTime = this.toSafeInt(row.create_time, 0)
const localId = this.toSafeInt(row.local_id, 0)
const isSend = this.resolveFootprintRowIsSend(row, params.myWxid)
// 过滤时间范围外的消息
if (createTime > 0 && (createTime < params.begin || createTime > params.end)) {
continue
}
if (createTime > 0) {
const needNew = !active || (lastMessageTs > 0 && createTime - lastMessageTs > sessionGapSeconds)
const referenceTs = lastMessageTs > 0 ? lastMessageTs : (active ? active.end_ts : 0)
const timeDiff = referenceTs > 0 ? createTime - referenceTs : 0
const needNew = !active || (referenceTs > 0 && timeDiff > sessionGapSeconds)
if (needNew) {
commit()
segmentCursor += 1

View File

@@ -129,6 +129,14 @@ interface ConfigSchema {
// AI 足迹
aiFootprintEnabled: boolean
aiFootprintSystemPrompt: string
aiGroupSummaryEnabled: boolean
aiGroupSummaryIntervalHours: number
aiGroupSummarySystemPrompt: string
aiGroupSummaryFilterMode: 'whitelist' | 'blacklist'
aiGroupSummaryFilterList: string[]
aiMessageInsightEnabled: boolean
aiMessageInsightContextCount: number
aiMessageInsightSystemPrompt: string
/** 是否将 AI 见解调试日志输出到桌面 */
aiInsightDebugLogEnabled: boolean
autoDownloadHighRes: boolean
@@ -252,6 +260,14 @@ export class ConfigService {
aiInsightWeiboBindings: {},
aiFootprintEnabled: false,
aiFootprintSystemPrompt: '',
aiGroupSummaryEnabled: false,
aiGroupSummaryIntervalHours: 4,
aiGroupSummarySystemPrompt: '',
aiGroupSummaryFilterMode: 'whitelist',
aiGroupSummaryFilterList: [],
aiMessageInsightEnabled: false,
aiMessageInsightContextCount: 50,
aiMessageInsightSystemPrompt: '',
aiInsightDebugLogEnabled: false,
autoDownloadHighRes: false,
autoDownloadWhitelist: []
@@ -817,6 +833,12 @@ export class ConfigService {
if (!sharedModel && legacyModel) {
this.set('aiModelApiModel', legacyModel)
}
const groupSummaryFilterMode = String(this.store.get('aiGroupSummaryFilterMode' as any) || '').trim()
if (groupSummaryFilterMode === 'blacklist') {
this.store.set('aiGroupSummaryFilterList' as any, [] as any)
this.store.set('aiGroupSummaryFilterMode' as any, 'whitelist' as any)
}
}
// === 验证 ===

View File

@@ -323,7 +323,7 @@ class ExportService {
return error
}
setRuntimeConfig(config: { dbPath?: string; decryptKey?: string; myWxid?: string; imageXorKey?: unknown; imageAesKey?: string } | null): void {
setRuntimeConfig(config: { dbPath?: string; decryptKey?: string; myWxid?: string; imageXorKey?: unknown; imageAesKey?: string; resourcesPath?: string; appPath?: string; isPackaged?: boolean } | null): void {
this.runtimeConfig = config
imageDecryptService.setRuntimeConfig({
dbPath: config?.dbPath,
@@ -331,6 +331,14 @@ class ExportService {
imageXorKey: config?.imageXorKey,
imageAesKey: config?.imageAesKey
})
chatService.setRuntimeConfig({
dbPath: config?.dbPath,
decryptKey: config?.decryptKey,
myWxid: config?.myWxid,
resourcesPath: config?.resourcesPath,
appPath: config?.appPath,
isPackaged: config?.isPackaged
})
}
private getConfiguredDbPath(): string {
@@ -6651,7 +6659,7 @@ class ExportService {
if (msg.localType === 34 && options.exportVoiceAsText) {
// 使用预先转写的文字
content = voiceTranscriptMap.get(this.getStableMessageKey(msg)) || '[语音消息 - 转文字失败]'
} else if (mediaItem && msg.localType === 3) {
} else if (mediaItem && msg.localType !== 47) {
content = mediaItem.relativePath
} else {
content = this.parseMessageContent(

View File

@@ -0,0 +1,384 @@
import { app } from 'electron'
import fs from 'fs'
import path from 'path'
import { createHash, randomUUID } from 'crypto'
import { ConfigService } from './config'
export type GroupSummaryTriggerType = 'auto' | 'manual'
export interface GroupSummaryTopic {
title: string
participants: string[]
keyPoints: string[]
conclusion: string
}
export interface GroupSummaryLog {
endpoint: string
model: string
temperature: number
triggerType: GroupSummaryTriggerType
periodStart: number
periodEnd: number
messageCount: number
readableMessageCount: number
systemPrompt: string
userPrompt: string
rawOutput: string
finalSummary: string
durationMs: number
createdAt: number
responseFormatJson?: boolean
responseFormatFallback?: boolean
responseFormatFallbackReason?: string
parsedTopics?: GroupSummaryTopic[]
}
export interface GroupSummaryRecord {
id: string
accountScope: string
createdAt: number
sessionId: string
displayName: string
avatarUrl?: string
triggerType: GroupSummaryTriggerType
periodStart: number
periodEnd: number
messageCount: number
readableMessageCount: number
topics: GroupSummaryTopic[]
summaryText: string
rawOutput: string
log: GroupSummaryLog
}
export interface GroupSummaryRecordSummary {
id: string
createdAt: number
sessionId: string
displayName: string
avatarUrl?: string
triggerType: GroupSummaryTriggerType
periodStart: number
periodEnd: number
messageCount: number
readableMessageCount: number
topics: GroupSummaryTopic[]
summaryText: string
}
export interface GroupSummaryRecordFilters {
sessionId?: string
startTime?: number
endTime?: number
limit?: number
offset?: number
}
export interface GroupSummaryRecordListResult {
success: boolean
records: GroupSummaryRecordSummary[]
total: number
error?: string
}
interface GroupSummaryIndexRecord extends GroupSummaryRecordSummary {
accountScope: string
logFile?: string
}
interface LegacyGroupSummaryRecord extends GroupSummaryIndexRecord {
rawOutput?: string
log?: GroupSummaryLog
}
class GroupSummaryRecordService {
private readonly maxRecordsPerScope = 2000
private filePath: string | null = null
private logDir: string | null = null
private loaded = false
private records: GroupSummaryIndexRecord[] = []
private resolveUserDataPath(): string {
const workerUserDataPath = String(process.env.WEFLOW_USER_DATA_PATH || process.env.WEFLOW_CONFIG_CWD || '').trim()
const userDataPath = workerUserDataPath || app?.getPath?.('userData') || process.cwd()
fs.mkdirSync(userDataPath, { recursive: true })
return userDataPath
}
private resolveFilePath(): string {
if (this.filePath) return this.filePath
this.filePath = path.join(this.resolveUserDataPath(), 'weflow-group-summary-records.json')
return this.filePath
}
private resolveLogDir(): string {
if (this.logDir) return this.logDir
this.logDir = path.join(this.resolveUserDataPath(), 'weflow-group-summary-logs')
fs.mkdirSync(this.logDir, { recursive: true })
return this.logDir
}
private normalizeTimestampSeconds(value: unknown): number {
const numeric = Number(value || 0)
if (!Number.isFinite(numeric) || numeric <= 0) return 0
let normalized = Math.floor(numeric)
while (normalized > 10000000000) {
normalized = Math.floor(normalized / 1000)
}
return normalized
}
private safeLogFileName(id: string): string {
const normalized = String(id || '').replace(/[^a-zA-Z0-9_-]/g, '')
return `${normalized || randomUUID()}.json`
}
private writeLogFile(recordId: string, log: GroupSummaryLog, rawOutput: string): string | undefined {
try {
const fileName = this.safeLogFileName(recordId)
const logPath = path.join(this.resolveLogDir(), fileName)
fs.writeFileSync(logPath, JSON.stringify({ version: 1, rawOutput, log }, null, 2), 'utf-8')
return fileName
} catch {
return undefined
}
}
private readLogFile(fileName?: string): { rawOutput: string; log: GroupSummaryLog } | null {
if (!fileName) return null
try {
const logPath = path.join(this.resolveLogDir(), this.safeLogFileName(fileName.replace(/\.json$/i, '')))
if (!fs.existsSync(logPath)) return null
const parsed = JSON.parse(fs.readFileSync(logPath, 'utf-8'))
const log = parsed?.log
if (!log || typeof log !== 'object') return null
return {
rawOutput: typeof parsed?.rawOutput === 'string' ? parsed.rawOutput : String(log.rawOutput || ''),
log: log as GroupSummaryLog
}
} catch {
return null
}
}
private ensureLoaded(): void {
if (this.loaded) return
this.loaded = true
const filePath = this.resolveFilePath()
try {
if (!fs.existsSync(filePath)) return
const raw = fs.readFileSync(filePath, 'utf-8')
const parsed = JSON.parse(raw)
const records = Array.isArray(parsed) ? parsed : parsed?.records
if (!Array.isArray(records)) return
const legacyRecords = records.filter((item) => item && typeof item === 'object') as LegacyGroupSummaryRecord[]
const needsMigration = legacyRecords.some((record) => Boolean(record.log || record.rawOutput))
if (needsMigration) {
this.backupLegacyFile(filePath)
}
this.records = legacyRecords.map((record) => {
const id = String(record.id || randomUUID())
const logFile = record.log
? this.writeLogFile(id, record.log, String(record.rawOutput || record.log.rawOutput || ''))
: record.logFile
return {
id,
accountScope: String(record.accountScope || 'default'),
createdAt: Number(record.createdAt || Date.now()),
sessionId: String(record.sessionId || ''),
displayName: String(record.displayName || record.sessionId || ''),
avatarUrl: record.avatarUrl,
triggerType: record.triggerType === 'auto' ? 'auto' : 'manual',
periodStart: this.normalizeTimestampSeconds(record.periodStart),
periodEnd: this.normalizeTimestampSeconds(record.periodEnd),
messageCount: Math.max(0, Math.floor(Number(record.messageCount || 0))),
readableMessageCount: Math.max(0, Math.floor(Number(record.readableMessageCount || 0))),
topics: Array.isArray(record.topics) ? record.topics : [],
summaryText: String(record.summaryText || ''),
logFile
}
}).filter((record) => record.sessionId && record.periodStart > 0 && record.periodEnd > record.periodStart)
if (needsMigration) {
this.persist()
}
} catch {
this.records = []
}
}
private backupLegacyFile(filePath: string): void {
try {
const backupPath = `${filePath}.legacy-${Date.now()}.bak`
if (!fs.existsSync(backupPath)) {
fs.copyFileSync(filePath, backupPath)
}
} catch {
// Backup failure should not block reading existing records.
}
}
private persist(): void {
try {
const filePath = this.resolveFilePath()
fs.writeFileSync(filePath, JSON.stringify({ version: 2, records: this.records }, null, 2), 'utf-8')
} catch {
// Summary generation should not fail because local record persistence failed.
}
}
private getCurrentAccountScope(): string {
const config = ConfigService.getInstance()
const myWxid = String(config.getMyWxidCleaned() || '').trim()
if (myWxid) return `wxid:${myWxid}`
const dbPath = String(config.get('dbPath') || '').trim()
if (dbPath) {
const hash = createHash('sha1').update(dbPath).digest('hex').slice(0, 16)
return `db:${hash}`
}
return 'default'
}
private toSummary(record: GroupSummaryIndexRecord): GroupSummaryRecordSummary {
return {
id: record.id,
createdAt: record.createdAt,
sessionId: record.sessionId,
displayName: record.displayName,
avatarUrl: record.avatarUrl,
triggerType: record.triggerType,
periodStart: record.periodStart,
periodEnd: record.periodEnd,
messageCount: record.messageCount,
readableMessageCount: record.readableMessageCount,
topics: Array.isArray(record.topics) ? record.topics : [],
summaryText: record.summaryText || ''
}
}
private getScopedRecords(): GroupSummaryIndexRecord[] {
this.ensureLoaded()
const scope = this.getCurrentAccountScope()
return this.records.filter((record) => record.accountScope === scope)
}
addRecord(input: {
sessionId: string
displayName: string
avatarUrl?: string
triggerType: GroupSummaryTriggerType
periodStart: number
periodEnd: number
messageCount: number
readableMessageCount: number
topics: GroupSummaryTopic[]
summaryText: string
rawOutput: string
log: GroupSummaryLog
}): GroupSummaryRecordSummary {
this.ensureLoaded()
const scope = this.getCurrentAccountScope()
const id = randomUUID()
const logFile = this.writeLogFile(id, input.log, input.rawOutput)
const record: GroupSummaryIndexRecord = {
id,
accountScope: scope,
createdAt: Date.now(),
sessionId: input.sessionId,
displayName: input.displayName,
avatarUrl: input.avatarUrl,
triggerType: input.triggerType,
periodStart: input.periodStart,
periodEnd: input.periodEnd,
messageCount: input.messageCount,
readableMessageCount: input.readableMessageCount,
topics: input.topics,
summaryText: input.summaryText,
logFile
}
this.records.push(record)
const scopedRecords = this.records
.filter((item) => item.accountScope === scope)
.sort((a, b) => b.createdAt - a.createdAt)
const keepIds = new Set(scopedRecords.slice(0, this.maxRecordsPerScope).map((item) => item.id))
this.records = this.records.filter((item) => item.accountScope !== scope || keepIds.has(item.id))
this.persist()
return this.toSummary(record)
}
hasAutoRecord(sessionId: string, periodStart: number, periodEnd: number): boolean {
const normalizedSessionId = String(sessionId || '').trim()
if (!normalizedSessionId) return false
return this.getScopedRecords().some((record) =>
record.triggerType === 'auto' &&
record.sessionId === normalizedSessionId &&
Number(record.periodStart || 0) === periodStart &&
Number(record.periodEnd || 0) === periodEnd
)
}
listRecords(filters: GroupSummaryRecordFilters = {}): GroupSummaryRecordListResult {
try {
const sessionId = String(filters.sessionId || '').trim()
const startTime = this.normalizeTimestampSeconds(filters.startTime)
const endTime = this.normalizeTimestampSeconds(filters.endTime)
const offset = Math.max(0, Math.floor(Number(filters.offset || 0)))
const limit = Math.min(200, Math.max(1, Math.floor(Number(filters.limit || 100))))
const filtered = this.getScopedRecords()
.filter((record) => {
if (sessionId && record.sessionId !== sessionId) return false
const periodStart = Number(record.periodStart || 0)
const periodEnd = Number(record.periodEnd || 0)
if (startTime > 0 && periodEnd < startTime) return false
if (endTime > 0 && periodStart > endTime) return false
return true
})
.sort((a, b) => Number(b.periodStart || b.createdAt) - Number(a.periodStart || a.createdAt))
return {
success: true,
records: filtered.slice(offset, offset + limit).map((record) => this.toSummary(record)),
total: filtered.length
}
} catch (error) {
return { success: false, records: [], total: 0, error: (error as Error).message || String(error) }
}
}
getRecord(id: string): { success: boolean; record?: GroupSummaryRecord; error?: string } {
this.ensureLoaded()
const normalizedId = String(id || '').trim()
if (!normalizedId) return { success: false, error: '记录 ID 为空' }
const scope = this.getCurrentAccountScope()
const record = this.records.find((item) => item.id === normalizedId && item.accountScope === scope)
if (!record) return { success: false, error: '未找到该群聊总结记录' }
const logData = this.readLogFile(record.logFile)
if (!logData) return { success: false, error: '未找到该群聊总结日志' }
return {
success: true,
record: {
...this.toSummary(record),
accountScope: record.accountScope,
rawOutput: logData.rawOutput,
log: logData.log
}
}
}
clearRuntimeCache(): void {
this.loaded = false
this.records = []
this.filePath = null
this.logDir = null
}
}
export const groupSummaryRecordService = new GroupSummaryRecordService()

View File

@@ -0,0 +1,801 @@
import https from 'https'
import http from 'http'
import { URL } from 'url'
import groupSummaryPrompt from '../../shared/groupSummaryPrompt.json'
import { ConfigService } from './config'
import { chatService, type Message } from './chatService'
import { wcdbService } from './wcdbService'
import {
groupSummaryRecordService,
type GroupSummaryLog,
type GroupSummaryRecord,
type GroupSummaryRecordFilters,
type GroupSummaryRecordListResult,
type GroupSummaryRecordSummary,
type GroupSummaryTopic,
type GroupSummaryTriggerType
} from './groupSummaryRecordService'
const API_TIMEOUT_MS = 90_000
const API_TEMPERATURE = 0.4
const MIN_SUMMARY_MESSAGES = 5
const MAX_MANUAL_RANGE_SECONDS = 48 * 60 * 60
const MAX_MESSAGES_PER_SUMMARY = 3000
const SUMMARY_CURSOR_BATCH_SIZE = 360
const DEFAULT_GROUP_SUMMARY_SYSTEM_PROMPT = String(groupSummaryPrompt.defaultSystemPrompt || '').trim()
const SUMMARY_CONFIG_KEYS = new Set([
'aiGroupSummaryEnabled',
'aiGroupSummaryIntervalHours',
'aiGroupSummarySystemPrompt',
'aiGroupSummaryFilterMode',
'aiGroupSummaryFilterList',
'aiModelApiBaseUrl',
'aiModelApiKey',
'aiModelApiModel',
'aiInsightApiBaseUrl',
'aiInsightApiKey',
'aiInsightApiModel',
'dbPath',
'decryptKey',
'myWxid'
])
interface SharedAiModelConfig {
apiBaseUrl: string
apiKey: string
model: string
}
interface GroupSummaryTriggerResult {
success: boolean
message: string
recordId?: string
record?: GroupSummaryRecordSummary
skipped?: boolean
skippedReason?: string
}
interface GroupSummaryDayTriggerResult {
success: boolean
message: string
generated: number
skipped: number
records: GroupSummaryRecordSummary[]
}
class ApiRequestError extends Error {
statusCode?: number
responseBody?: string
constructor(message: string, statusCode?: number, responseBody?: string) {
super(message)
this.name = 'ApiRequestError'
this.statusCode = statusCode
this.responseBody = responseBody
}
}
function buildApiUrl(baseUrl: string, path: string): string {
const base = baseUrl.replace(/\/+$/, '')
const suffix = path.startsWith('/') ? path : `/${path}`
return `${base}${suffix}`
}
function normalizeSessionIdList(value: unknown): string[] {
if (!Array.isArray(value)) return []
return Array.from(new Set(value.map((item) => String(item || '').trim()).filter(Boolean)))
}
function normalizeIntervalHours(value: unknown): number {
const allowed = new Set([1, 2, 4, 8, 12, 24])
const numeric = Math.floor(Number(value) || 4)
return allowed.has(numeric) ? numeric : 4
}
function getStartOfDaySeconds(date: Date = new Date()): number {
const next = new Date(date)
next.setHours(0, 0, 0, 0)
return Math.floor(next.getTime() / 1000)
}
function clampText(value: unknown, maxLength: number): string {
const text = String(value || '').replace(/\s+/g, ' ').trim()
if (text.length <= maxLength) return text
return `${text.slice(0, Math.max(0, maxLength - 1))}`
}
function stripJsonFence(value: string): string {
const text = String(value || '').trim()
const fenced = text.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)
if (fenced) return fenced[1].trim()
const firstBrace = text.indexOf('{')
const lastBrace = text.lastIndexOf('}')
if (firstBrace >= 0 && lastBrace > firstBrace) {
return text.slice(firstBrace, lastBrace + 1).trim()
}
return text
}
function shouldFallbackJsonMode(error: unknown): boolean {
const statusCode = (error as ApiRequestError)?.statusCode
if (statusCode === 400 || statusCode === 404 || statusCode === 422) return true
const text = `${(error as Error)?.message || ''}\n${(error as ApiRequestError)?.responseBody || ''}`.toLowerCase()
return text.includes('response_format') || text.includes('json_object') || text.includes('json mode')
}
function formatTimestamp(createTime: number): string {
const ms = createTime > 1_000_000_000_000 ? createTime : createTime * 1000
const date = new Date(ms)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).padStart(2, '0')
const minutes = String(date.getMinutes()).padStart(2, '0')
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
function callChatCompletions(
apiBaseUrl: string,
apiKey: string,
model: string,
messages: Array<{ role: string; content: string }>,
options?: { responseFormatJson?: boolean }
): Promise<string> {
return new Promise((resolve, reject) => {
const endpoint = buildApiUrl(apiBaseUrl, '/chat/completions')
let urlObj: URL
try {
urlObj = new URL(endpoint)
} catch {
reject(new Error(`无效的 API URL: ${endpoint}`))
return
}
const payload: Record<string, unknown> = {
model,
messages,
temperature: API_TEMPERATURE,
stream: false
}
if (options?.responseFormatJson) {
payload.response_format = { type: 'json_object' }
}
const body = JSON.stringify(payload)
const requestOptions = {
hostname: urlObj.hostname,
port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
path: urlObj.pathname + urlObj.search,
method: 'POST' as const,
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body).toString(),
Authorization: `Bearer ${apiKey}`
}
}
const requestFn = urlObj.protocol === 'https:' ? https.request : http.request
const req = requestFn(requestOptions, (res) => {
let data = ''
res.on('data', (chunk) => { data += chunk })
res.on('end', () => {
try {
if (res.statusCode && res.statusCode >= 400) {
reject(new ApiRequestError(`API 请求失败 (${res.statusCode}): ${data.slice(0, 200)}`, res.statusCode, data))
return
}
const parsed = JSON.parse(data)
const content = parsed?.choices?.[0]?.message?.content
if (typeof content === 'string' && content.trim()) {
resolve(content.trim())
} else {
reject(new Error(`API 返回格式异常: ${data.slice(0, 200)}`))
}
} catch {
reject(new Error(`JSON 解析失败: ${data.slice(0, 200)}`))
}
})
})
req.setTimeout(API_TIMEOUT_MS, () => {
req.destroy()
reject(new Error('API 请求超时'))
})
req.on('error', reject)
req.write(body)
req.end()
})
}
function parseTopics(rawOutput: string): GroupSummaryTopic[] {
const parsed = JSON.parse(stripJsonFence(rawOutput)) as unknown
if (!parsed || typeof parsed !== 'object') {
throw new Error('模型输出格式异常JSON 根节点不是对象')
}
const source = parsed as Record<string, unknown>
const rawTopics = Array.isArray(source.topics) ? source.topics : []
const topics = rawTopics.map((item, index) => {
const topic = item && typeof item === 'object' ? item as Record<string, unknown> : {}
const participantsRaw = Array.isArray(topic.participants) ? topic.participants : []
const keyPointsRaw = Array.isArray(topic.key_points)
? topic.key_points
: (Array.isArray(topic.keyPoints) ? topic.keyPoints : [])
return {
title: clampText(topic.title || `话题 ${index + 1}`, 48) || `话题 ${index + 1}`,
participants: participantsRaw.map((value) => clampText(value, 24)).filter(Boolean).slice(0, 12),
keyPoints: keyPointsRaw.map((value) => clampText(value, 120)).filter(Boolean).slice(0, 8),
conclusion: clampText(topic.conclusion, 180) || '无明确结论'
}
}).filter((topic) => topic.title || topic.keyPoints.length > 0 || topic.conclusion)
if (topics.length === 0) {
throw new Error('模型输出格式异常topics 为空')
}
return topics
}
function buildSummaryText(topics: GroupSummaryTopic[]): string {
return topics.map((topic) => {
const participants = topic.participants.length > 0 ? topic.participants.join('、') : '未明确'
const keyPoints = topic.keyPoints.length > 0 ? topic.keyPoints.join('') : '无'
return `${topic.title}】参与者:${participants}。关键/矛盾点:${keyPoints}。结论:${topic.conclusion}`
}).join('\n')
}
function fallbackTopicFromRaw(rawOutput: string): GroupSummaryTopic {
return {
title: '未归类总结',
participants: [],
keyPoints: [clampText(rawOutput, 500)],
conclusion: '模型未按固定 JSON 格式返回,请查看完整日志。'
}
}
class GroupSummaryService {
private config: ConfigService
private started = false
private scanTimer: NodeJS.Timeout | null = null
private processing = false
private pendingAutoRun = false
private dbConnected = false
constructor() {
this.config = ConfigService.getInstance()
}
start(): void {
if (this.started) return
this.started = true
void this.refreshConfiguration('startup')
}
stop(): void {
this.started = false
this.clearTimers()
this.processing = false
this.pendingAutoRun = false
this.dbConnected = false
}
async handleConfigChanged(key: string): Promise<void> {
const normalizedKey = String(key || '').trim()
if (!SUMMARY_CONFIG_KEYS.has(normalizedKey)) return
if (normalizedKey === 'aiGroupSummarySystemPrompt') return
if (normalizedKey === 'dbPath' || normalizedKey === 'decryptKey' || normalizedKey === 'myWxid') {
this.dbConnected = false
groupSummaryRecordService.clearRuntimeCache()
}
await this.refreshConfiguration(`config:${normalizedKey}`)
}
handleConfigCleared(): void {
this.clearTimers()
this.processing = false
this.pendingAutoRun = false
this.dbConnected = false
groupSummaryRecordService.clearRuntimeCache()
}
listRecords(filters?: GroupSummaryRecordFilters): GroupSummaryRecordListResult {
return groupSummaryRecordService.listRecords(filters || {})
}
getRecord(id: string): { success: boolean; record?: GroupSummaryRecord; error?: string } {
return groupSummaryRecordService.getRecord(id)
}
async triggerManual(params: {
sessionId: string
displayName?: string
avatarUrl?: string
startTime: number
endTime: number
}): Promise<GroupSummaryTriggerResult> {
if (!this.isEnabled()) {
return { success: false, message: '请先在设置中开启「AI 群聊总结」' }
}
const sessionId = String(params?.sessionId || '').trim()
if (!sessionId.endsWith('@chatroom')) {
return { success: false, message: 'AI 群聊总结仅支持群聊' }
}
const startTime = this.normalizeTimestampSeconds(params?.startTime)
const endTime = this.normalizeTimestampSeconds(params?.endTime)
if (startTime <= 0 || endTime <= startTime) {
return { success: false, message: '请选择有效的总结时段' }
}
if (endTime - startTime > MAX_MANUAL_RANGE_SECONDS) {
return { success: false, message: '手动总结时段不能超过 48 小时' }
}
const displayName = String(params?.displayName || sessionId).trim() || sessionId
const avatarUrl = String(params?.avatarUrl || '').trim() || undefined
return this.generateSummaryForPeriod({
sessionId,
displayName,
avatarUrl,
periodStart: startTime,
periodEnd: endTime,
triggerType: 'manual'
})
}
async triggerDay(params: {
sessionId: string
displayName?: string
avatarUrl?: string
date: string
}): Promise<GroupSummaryDayTriggerResult> {
if (!this.isEnabled()) {
return { success: false, message: '请先在设置中开启「AI 群聊总结」', generated: 0, skipped: 0, records: [] }
}
const sessionId = String(params?.sessionId || '').trim()
if (!sessionId.endsWith('@chatroom')) {
return { success: false, message: 'AI 群聊总结仅支持群聊', generated: 0, skipped: 0, records: [] }
}
const dayRange = this.parseLocalDateDayRange(params?.date)
if (!dayRange) {
return { success: false, message: '请选择有效日期', generated: 0, skipped: 0, records: [] }
}
const todayStart = getStartOfDaySeconds(new Date())
if (dayRange.start > todayStart) {
return { success: false, message: '不能总结未来日期', generated: 0, skipped: 0, records: [] }
}
const now = Math.floor(Date.now() / 1000)
const effectiveEnd = dayRange.start === todayStart ? Math.min(dayRange.end, now) : dayRange.end
const periods = this.getIntervalPeriods(dayRange.start, effectiveEnd, false)
if (periods.length === 0) {
return { success: true, message: '当前日期暂无已完成的总结时段', generated: 0, skipped: 0, records: [] }
}
const displayName = String(params?.displayName || sessionId).trim() || sessionId
const avatarUrl = String(params?.avatarUrl || '').trim() || undefined
return this.generateSummariesForPeriods({
sessionId,
displayName,
avatarUrl,
periods,
triggerType: 'manual'
})
}
private async refreshConfiguration(_reason: string): Promise<void> {
if (!this.started) return
this.clearTimers()
if (!this.isEnabled()) return
await this.queueDueAutoSummaries()
this.scheduleNextAutoRun()
}
private isEnabled(): boolean {
return this.config.get('aiGroupSummaryEnabled') === true
}
private clearTimers(): void {
if (this.scanTimer !== null) {
clearTimeout(this.scanTimer)
this.scanTimer = null
}
}
private scheduleNextAutoRun(): void {
if (!this.started || !this.isEnabled()) return
const intervalHours = normalizeIntervalHours(this.config.get('aiGroupSummaryIntervalHours'))
const now = Math.floor(Date.now() / 1000)
const dayStart = getStartOfDaySeconds(new Date())
const intervalSeconds = intervalHours * 60 * 60
const elapsed = Math.max(0, now - dayStart)
const nextBoundary = dayStart + (Math.floor(elapsed / intervalSeconds) + 1) * intervalSeconds
const delayMs = Math.max(1_000, (nextBoundary - now) * 1000 + 1_000)
this.scanTimer = setTimeout(async () => {
this.scanTimer = null
await this.queueDueAutoSummaries()
this.scheduleNextAutoRun()
}, delayMs)
}
private async ensureConnected(): Promise<boolean> {
if (this.dbConnected) return true
const result = await chatService.connect()
this.dbConnected = result.success === true
return this.dbConnected
}
private getSharedAiModelConfig(): SharedAiModelConfig {
const apiBaseUrl = String(
this.config.get('aiModelApiBaseUrl')
|| this.config.get('aiInsightApiBaseUrl')
|| ''
).trim()
const apiKey = String(
this.config.get('aiModelApiKey')
|| this.config.get('aiInsightApiKey')
|| ''
).trim()
const model = String(
this.config.get('aiModelApiModel')
|| this.config.get('aiInsightApiModel')
|| 'gpt-4o-mini'
).trim() || 'gpt-4o-mini'
return { apiBaseUrl, apiKey, model }
}
private getAutoScopeSessionIds(): string[] {
return normalizeSessionIdList(this.config.get('aiGroupSummaryFilterList'))
.filter((sessionId) => sessionId.endsWith('@chatroom'))
}
private normalizeTimestampSeconds(value: unknown): number {
const numeric = Number(value || 0)
if (!Number.isFinite(numeric) || numeric <= 0) return 0
let normalized = Math.floor(numeric)
while (normalized > 10000000000) {
normalized = Math.floor(normalized / 1000)
}
return normalized
}
private parseLocalDateDayRange(value: unknown): { start: number; end: number } | null {
const text = String(value || '').trim()
const match = text.match(/^(\d{4})-(\d{2})-(\d{2})$/)
if (!match) return null
const year = Number(match[1])
const month = Number(match[2])
const day = Number(match[3])
const start = new Date(year, month - 1, day, 0, 0, 0, 0)
if (
!Number.isFinite(start.getTime()) ||
start.getFullYear() !== year ||
start.getMonth() !== month - 1 ||
start.getDate() !== day
) {
return null
}
const end = new Date(start)
end.setDate(end.getDate() + 1)
return {
start: Math.floor(start.getTime() / 1000),
end: Math.floor(end.getTime() / 1000)
}
}
private getIntervalPeriods(startTime: number, endTime: number, includePartial: boolean): Array<{ start: number; end: number }> {
const intervalHours = normalizeIntervalHours(this.config.get('aiGroupSummaryIntervalHours'))
const intervalSeconds = intervalHours * 60 * 60
const periods: Array<{ start: number; end: number }> = []
for (let start = startTime; start < endTime; start += intervalSeconds) {
const end = Math.min(start + intervalSeconds, endTime)
if (!includePartial && end - start < intervalSeconds) continue
if (end > start) periods.push({ start, end })
}
return periods
}
private getCompletedPeriodsToday(): Array<{ start: number; end: number }> {
const dayStart = getStartOfDaySeconds(new Date())
const now = Math.floor(Date.now() / 1000)
return this.getIntervalPeriods(dayStart, now, false)
}
private async queueDueAutoSummaries(): Promise<void> {
if (!this.started || !this.isEnabled()) return
if (this.processing) {
this.pendingAutoRun = true
return
}
this.processing = true
try {
do {
this.pendingAutoRun = false
await this.runDueAutoSummariesOnce()
} while (this.pendingAutoRun && this.started && this.isEnabled())
} finally {
this.processing = false
}
}
private async runDueAutoSummariesOnce(): Promise<void> {
if (!this.started || !this.isEnabled()) return
try {
const { apiBaseUrl, apiKey } = this.getSharedAiModelConfig()
if (!apiBaseUrl || !apiKey) return
const scopeSessionIds = this.getAutoScopeSessionIds()
if (scopeSessionIds.length === 0) return
if (!await this.ensureConnected()) return
const contacts = (await chatService.enrichSessionsContactInfo(scopeSessionIds).catch(() => null))?.contacts || {}
const periods = this.getCompletedPeriodsToday()
for (const period of periods) {
for (const sessionId of scopeSessionIds) {
if (!this.started || !this.isEnabled()) return
if (!sessionId) continue
if (groupSummaryRecordService.hasAutoRecord(sessionId, period.start, period.end)) continue
await this.generateSummaryForPeriod({
sessionId,
displayName: contacts[sessionId]?.displayName || sessionId,
avatarUrl: contacts[sessionId]?.avatarUrl,
periodStart: period.start,
periodEnd: period.end,
triggerType: 'auto'
})
}
}
} catch (error) {
console.warn('[GroupSummaryService] 自动总结失败:', error)
}
}
private async readMessagesInPeriod(sessionId: string, startTime: number, endTime: number): Promise<Message[]> {
if (!await this.ensureConnected()) {
throw new Error('数据库连接失败,请先在“数据库连接”页完成配置')
}
const cursorResult = await wcdbService.openMessageCursorLite(
sessionId,
SUMMARY_CURSOR_BATCH_SIZE,
true,
startTime,
endTime
)
if (!cursorResult.success || !cursorResult.cursor) {
throw new Error(cursorResult.error || '打开消息游标失败')
}
const cursor = cursorResult.cursor
const messages: Message[] = []
try {
let hasMore = true
while (hasMore && messages.length < MAX_MESSAGES_PER_SUMMARY) {
const batch = await wcdbService.fetchMessageBatch(cursor)
if (!batch.success) {
throw new Error(batch.error || '读取消息失败')
}
hasMore = batch.hasMore === true
const rows = Array.isArray(batch.rows) ? batch.rows as Record<string, any>[] : []
if (rows.length === 0) {
if (!hasMore) break
continue
}
const mapped = chatService.mapRowsToMessagesForApi(rows, sessionId)
for (const message of mapped) {
const createTime = Number(message.createTime || 0)
if (createTime < startTime || createTime > endTime) continue
messages.push(message)
if (messages.length >= MAX_MESSAGES_PER_SUMMARY) break
}
}
} finally {
await wcdbService.closeMessageCursor(cursor).catch(() => {})
}
return messages.sort((a, b) => {
if (a.createTime !== b.createTime) return a.createTime - b.createTime
if (a.sortSeq !== b.sortSeq) return a.sortSeq - b.sortSeq
return a.localId - b.localId
})
}
private normalizeMessageText(message: Message): string {
const parsedContent = String(message.parsedContent || '').replace(/\s+/g, ' ').trim()
const quotedContent = String(message.quotedContent || '').replace(/\s+/g, ' ').trim()
const quotedSender = String(message.quotedSender || '').replace(/\s+/g, ' ').trim()
let text = parsedContent
if (quotedContent) {
const quote = quotedSender ? `${quotedSender}${quotedContent}` : quotedContent
text = text && text !== '[引用消息]' ? `${text} [引用 ${quote}]` : `[引用 ${quote}]`
}
if (!text) {
text = String(message.linkTitle || message.fileName || message.appMsgDesc || '').replace(/\s+/g, ' ').trim()
}
if (!text) return ''
if (/^<\?xml|^<msg\b|^<appmsg\b|^<img\b|^<emoji\b/i.test(text)) return ''
return text
}
private async buildTranscript(sessionId: string, messages: Message[]): Promise<{ transcript: string; readableMessages: Message[] }> {
const readableMessages = messages.filter((message) => this.normalizeMessageText(message))
const senderIds = Array.from(new Set(
readableMessages
.map((message) => String(message.senderUsername || '').trim())
.filter(Boolean)
))
const contacts = senderIds.length > 0
? (await chatService.enrichSessionsContactInfo(senderIds).catch(() => null))?.contacts || {}
: {}
const myWxid = String(this.config.getMyWxidCleaned() || '').trim()
const lines = readableMessages.map((message) => {
const senderUsername = String(message.senderUsername || '').trim()
const senderName = message.isSend === 1 || (senderUsername && myWxid && senderUsername === myWxid)
? '我'
: (contacts[senderUsername]?.displayName || senderUsername || '未知成员')
return `${formatTimestamp(message.createTime)} ${senderName}${this.normalizeMessageText(message)}`
})
return {
transcript: lines.join('\n'),
readableMessages
}
}
private async generateSummaryForPeriod(params: {
sessionId: string
displayName: string
avatarUrl?: string
periodStart: number
periodEnd: number
triggerType: GroupSummaryTriggerType
}): Promise<GroupSummaryTriggerResult> {
const { apiBaseUrl, apiKey, model } = this.getSharedAiModelConfig()
if (!apiBaseUrl || !apiKey) {
return { success: false, message: '请先填写通用 AI 模型配置API 地址和 Key' }
}
try {
const messages = await this.readMessagesInPeriod(params.sessionId, params.periodStart, params.periodEnd)
const { transcript, readableMessages } = await this.buildTranscript(params.sessionId, messages)
if (readableMessages.length < MIN_SUMMARY_MESSAGES) {
return {
success: true,
skipped: true,
skippedReason: 'message_count_too_low',
message: `该时段可总结消息少于 ${MIN_SUMMARY_MESSAGES} 条,已跳过`
}
}
const customPrompt = String(this.config.get('aiGroupSummarySystemPrompt') || '').trim()
const systemPrompt = customPrompt || DEFAULT_GROUP_SUMMARY_SYSTEM_PROMPT
const userPrompt = `群聊:${params.displayName}
总结时段:${formatTimestamp(params.periodStart)}${formatTimestamp(params.periodEnd)}
消息数量:${readableMessages.length}
群聊记录:
${transcript}
请只输出指定 JSON。`
const endpoint = buildApiUrl(apiBaseUrl, '/chat/completions')
const requestMessages = [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
]
let rawOutput = ''
let responseFormatJson = true
let responseFormatFallback = false
let responseFormatFallbackReason = ''
const startedAt = Date.now()
try {
rawOutput = await callChatCompletions(apiBaseUrl, apiKey, model, requestMessages, { responseFormatJson: true })
} catch (error) {
if (!shouldFallbackJsonMode(error)) throw error
responseFormatJson = false
responseFormatFallback = true
responseFormatFallbackReason = (error as Error).message || 'response_format 不受支持'
rawOutput = await callChatCompletions(apiBaseUrl, apiKey, model, requestMessages)
}
let topics: GroupSummaryTopic[]
let finalSummary: string
try {
topics = parseTopics(rawOutput)
finalSummary = buildSummaryText(topics)
} catch {
topics = [fallbackTopicFromRaw(rawOutput)]
finalSummary = buildSummaryText(topics)
}
const log: GroupSummaryLog = {
endpoint,
model,
temperature: API_TEMPERATURE,
triggerType: params.triggerType,
periodStart: params.periodStart,
periodEnd: params.periodEnd,
messageCount: messages.length,
readableMessageCount: readableMessages.length,
systemPrompt,
userPrompt,
rawOutput,
finalSummary,
durationMs: Date.now() - startedAt,
createdAt: Date.now(),
responseFormatJson,
responseFormatFallback,
responseFormatFallbackReason,
parsedTopics: topics
}
const record = groupSummaryRecordService.addRecord({
sessionId: params.sessionId,
displayName: params.displayName,
avatarUrl: params.avatarUrl,
triggerType: params.triggerType,
periodStart: params.periodStart,
periodEnd: params.periodEnd,
messageCount: messages.length,
readableMessageCount: readableMessages.length,
topics,
summaryText: finalSummary,
rawOutput,
log
})
return { success: true, message: '群聊总结已生成', recordId: record.id, record }
} catch (error) {
return { success: false, message: `生成失败:${(error as Error).message || String(error)}` }
}
}
private async generateSummariesForPeriods(params: {
sessionId: string
displayName: string
avatarUrl?: string
periods: Array<{ start: number; end: number }>
triggerType: GroupSummaryTriggerType
}): Promise<GroupSummaryDayTriggerResult> {
const records: GroupSummaryRecordSummary[] = []
let skipped = 0
let failed = 0
let firstError = ''
for (const period of params.periods) {
const result = await this.generateSummaryForPeriod({
sessionId: params.sessionId,
displayName: params.displayName,
avatarUrl: params.avatarUrl,
periodStart: period.start,
periodEnd: period.end,
triggerType: params.triggerType
})
if (result.success && result.record) {
records.push(result.record)
continue
}
if (result.success && result.skipped) {
skipped += 1
continue
}
failed += 1
if (!firstError) firstError = result.message
}
const generated = records.length
const parts = [`生成 ${generated}`, `跳过 ${skipped}`]
if (failed > 0) parts.push(`失败 ${failed}`)
const message = failed > 0 && generated === 0 && skipped === 0
? (firstError || '群聊总结生成失败')
: `群聊总结完成:${parts.join('')}`
return {
success: generated > 0 || skipped > 0 || failed === 0,
message,
generated,
skipped,
records
}
}
}
export const groupSummaryService = new GroupSummaryService()

View File

@@ -4,7 +4,24 @@ import path from 'path'
import { createHash, randomUUID } from 'crypto'
import { ConfigService } from './config'
export type InsightRecordTriggerReason = 'activity' | 'silence' | 'test'
export type InsightRecordTriggerReason = 'activity' | 'silence' | 'test' | 'manual' | 'message_analysis'
export type InsightRecordSourceType = 'insight' | 'message_analysis'
export interface MessageInsightAnalysis {
explicitText: string
emotion: string
intent: string
topic: string
}
export interface MessageInsightTarget {
targetLocalId: number
targetCreateTime: number
targetMessageKey: string
targetSenderName: string
targetTextPreview: string
analysis: MessageInsightAnalysis
}
export interface InsightRecordLog {
endpoint: string
@@ -20,11 +37,29 @@ export interface InsightRecordLog {
finalInsight: string
durationMs: number
createdAt: number
responseFormatJson?: boolean
responseFormatFallback?: boolean
responseFormatFallbackReason?: string
targetMessage?: {
localId: number
createTime: number
messageKey: string
senderName: string
textPreview: string
}
contextStats?: {
requested: number
beforeTarget: number
afterTarget: number
readError?: string
}
parsedAnalysis?: MessageInsightAnalysis
}
export interface InsightRecord {
id: string
accountScope: string
sourceType: InsightRecordSourceType
createdAt: number
sessionId: string
displayName: string
@@ -32,11 +67,13 @@ export interface InsightRecord {
triggerReason: InsightRecordTriggerReason
insight: string
read: boolean
messageInsight?: MessageInsightTarget
log: InsightRecordLog
}
export interface InsightRecordSummary {
id: string
sourceType: InsightRecordSourceType
createdAt: number
sessionId: string
displayName: string
@@ -44,6 +81,7 @@ export interface InsightRecordSummary {
triggerReason: InsightRecordTriggerReason
insight: string
read: boolean
messageInsight?: MessageInsightTarget
}
export interface InsightRecordContactFacet {
@@ -58,6 +96,7 @@ export interface InsightRecordFilters {
sessionId?: string
startTime?: number
endTime?: number
sourceType?: InsightRecordSourceType | 'all'
limit?: number
offset?: number
}
@@ -136,13 +175,15 @@ class InsightRecordService {
private toSummary(record: InsightRecord): InsightRecordSummary {
return {
id: record.id,
sourceType: record.sourceType || 'insight',
createdAt: record.createdAt,
sessionId: record.sessionId,
displayName: record.displayName,
avatarUrl: record.avatarUrl,
triggerReason: record.triggerReason,
insight: record.insight,
read: record.read
read: record.read,
messageInsight: record.messageInsight
}
}
@@ -156,8 +197,10 @@ class InsightRecordService {
sessionId: string
displayName: string
avatarUrl?: string
sourceType?: InsightRecordSourceType
triggerReason: InsightRecordTriggerReason
insight: string
messageInsight?: MessageInsightTarget
log: InsightRecordLog
}): InsightRecord {
this.ensureLoaded()
@@ -166,6 +209,7 @@ class InsightRecordService {
const record: InsightRecord = {
id: randomUUID(),
accountScope: scope,
sourceType: input.sourceType || 'insight',
createdAt: now,
sessionId: input.sessionId,
displayName: input.displayName,
@@ -173,6 +217,7 @@ class InsightRecordService {
triggerReason: input.triggerReason,
insight: input.insight,
read: false,
messageInsight: input.messageInsight,
log: input.log
}
@@ -207,6 +252,7 @@ class InsightRecordService {
const keyword = String(filters.keyword || '').trim().toLowerCase()
const sessionId = String(filters.sessionId || '').trim()
const sourceType = String(filters.sourceType || 'all').trim()
const startTime = Number(filters.startTime || 0)
const endTime = Number(filters.endTime || 0)
const offset = Math.max(0, Math.floor(Number(filters.offset || 0)))
@@ -215,10 +261,22 @@ class InsightRecordService {
const filtered = allScoped
.filter((record) => {
if (sessionId && record.sessionId !== sessionId) return false
const recordSourceType = record.sourceType || 'insight'
if (sourceType !== 'all' && sourceType && recordSourceType !== sourceType) return false
if (startTime > 0 && record.createdAt < startTime) return false
if (endTime > 0 && record.createdAt > endTime) return false
if (keyword) {
const haystack = `${record.displayName}\n${record.sessionId}\n${record.insight}`.toLowerCase()
const haystack = [
record.displayName,
record.sessionId,
record.insight,
record.messageInsight?.targetSenderName,
record.messageInsight?.targetTextPreview,
record.messageInsight?.analysis?.explicitText,
record.messageInsight?.analysis?.emotion,
record.messageInsight?.analysis?.intent,
record.messageInsight?.analysis?.topic
].join('\n').toLowerCase()
if (!haystack.includes(keyword)) return false
}
return true
@@ -256,6 +314,36 @@ class InsightRecordService {
return { success: true, record }
}
findLatestMessageAnalysis(input: {
sessionId: string
targetLocalId?: number
targetCreateTime?: number
targetMessageKey?: string
}): InsightRecord | null {
this.ensureLoaded()
const scope = this.getCurrentAccountScope()
const sessionId = String(input.sessionId || '').trim()
if (!sessionId) return null
const targetLocalId = Math.floor(Number(input.targetLocalId || 0))
const targetCreateTime = Math.floor(Number(input.targetCreateTime || 0))
const targetMessageKey = String(input.targetMessageKey || '').trim()
const matches = this.records
.filter((record) => {
if (record.accountScope !== scope) return false
if ((record.sourceType || 'insight') !== 'message_analysis') return false
if (record.sessionId !== sessionId) return false
const target = record.messageInsight
if (!target) return false
if (targetLocalId > 0 && Number(target.targetLocalId || 0) === targetLocalId) {
if (targetCreateTime <= 0 || Number(target.targetCreateTime || 0) === targetCreateTime) return true
}
if (targetMessageKey && target.targetMessageKey === targetMessageKey) return true
return false
})
.sort((a, b) => b.createdAt - a.createdAt)
return matches[0] || null
}
markRecordRead(id: string): { success: boolean; error?: string } {
this.ensureLoaded()
const normalizedId = String(id || '').trim()

View File

@@ -21,7 +21,12 @@ import { chatService, ChatSession, Message } from './chatService'
import { snsService } from './snsService'
import { weiboService } from './social/weiboService'
import { showNotification } from '../windows/notificationWindow'
import { insightRecordService, type InsightRecordLog, type InsightRecordTriggerReason } from './insightRecordService'
import {
insightRecordService,
type InsightRecordLog,
type InsightRecordTriggerReason,
type MessageInsightAnalysis
} from './insightRecordService'
// ─── 常量 ────────────────────────────────────────────────────────────────────
@@ -79,8 +84,29 @@ interface SharedAiModelConfig {
maxTokens: number
}
interface SessionInsightTriggerResult {
success: boolean
message: string
recordId?: string
insight?: string
skipped?: boolean
notificationEnabled?: boolean
}
type InsightFilterMode = 'whitelist' | 'blacklist'
class ApiRequestError extends Error {
statusCode?: number
responseBody?: string
constructor(message: string, statusCode?: number, responseBody?: string) {
super(message)
this.name = 'ApiRequestError'
this.statusCode = statusCode
this.responseBody = responseBody
}
}
// ─── 日志 ─────────────────────────────────────────────────────────────────────
type InsightLogLevel = 'INFO' | 'WARN' | 'ERROR'
@@ -161,6 +187,52 @@ function normalizeSessionIdList(value: unknown): string[] {
return Array.from(new Set(value.map((item) => String(item || '').trim()).filter(Boolean)))
}
function clampText(value: unknown, maxLength: number): string {
const text = String(value || '').replace(/\s+/g, ' ').trim()
if (text.length <= maxLength) return text
return `${text.slice(0, Math.max(0, maxLength - 1))}`
}
function stripJsonFence(value: string): string {
const text = String(value || '').trim()
const fenced = text.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)
if (fenced) return fenced[1].trim()
const firstBrace = text.indexOf('{')
const lastBrace = text.lastIndexOf('}')
if (firstBrace >= 0 && lastBrace > firstBrace) {
return text.slice(firstBrace, lastBrace + 1).trim()
}
return text
}
function parseMessageInsightAnalysis(rawOutput: string): MessageInsightAnalysis {
let parsed: unknown
try {
parsed = JSON.parse(stripJsonFence(rawOutput))
} catch {
throw new Error('模型输出格式异常:不是合法 JSON')
}
if (!parsed || typeof parsed !== 'object') {
throw new Error('模型输出格式异常JSON 根节点不是对象')
}
const source = parsed as Record<string, unknown>
const explicitText = clampText(source.explicit_text ?? source.explicitText, 120)
const emotion = clampText(source.emotion, 16)
const intent = clampText(source.intent, 20)
const topic = clampText(source.topic, 20)
if (!explicitText || !emotion || !intent || !topic) {
throw new Error('模型输出格式异常:缺少必要字段')
}
return { explicitText, emotion, intent, topic }
}
function shouldFallbackJsonMode(error: unknown): boolean {
const statusCode = Number((error as ApiRequestError)?.statusCode || 0)
if (statusCode === 400 || statusCode === 404 || statusCode === 422) return true
const text = `${(error as Error)?.message || ''}\n${(error as ApiRequestError)?.responseBody || ''}`.toLowerCase()
return text.includes('response_format') || text.includes('json_object') || text.includes('json mode')
}
/**
* 调用 OpenAI 兼容 API非流式返回模型第一条消息内容。
* 使用 Node 原生 https/http 模块,无需任何第三方 SDK。
@@ -171,7 +243,8 @@ function callApi(
model: string,
messages: Array<{ role: string; content: string }>,
timeoutMs: number = API_TIMEOUT_MS,
maxTokens: number = API_MAX_TOKENS_DEFAULT
maxTokens: number = API_MAX_TOKENS_DEFAULT,
options?: { responseFormatJson?: boolean }
): Promise<string> {
return new Promise((resolve, reject) => {
const endpoint = buildApiUrl(apiBaseUrl, '/chat/completions')
@@ -183,15 +256,19 @@ function callApi(
return
}
const body = JSON.stringify({
const payload: Record<string, unknown> = {
model,
messages,
max_tokens: normalizeApiMaxTokens(maxTokens),
temperature: API_TEMPERATURE,
stream: false
})
}
if (options?.responseFormatJson) {
payload.response_format = { type: 'json_object' }
}
const body = JSON.stringify(payload)
const options = {
const requestOptions = {
hostname: urlObj.hostname,
port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
path: urlObj.pathname + urlObj.search,
@@ -205,11 +282,15 @@ function callApi(
const isHttps = urlObj.protocol === 'https:'
const requestFn = isHttps ? https.request : http.request
const req = requestFn(options, (res) => {
const req = requestFn(requestOptions, (res) => {
let data = ''
res.on('data', (chunk) => { data += chunk })
res.on('end', () => {
try {
if (res.statusCode && res.statusCode >= 400) {
reject(new ApiRequestError(`API 请求失败 (${res.statusCode}): ${data.slice(0, 200)}`, res.statusCode, data))
return
}
const parsed = JSON.parse(data)
const content = parsed?.choices?.[0]?.message?.content
if (typeof content === 'string' && content.trim()) {
@@ -465,11 +546,14 @@ class InsightService {
const sessionId = session.username?.trim() || ''
const displayName = session.displayName || sessionId
insightLog('INFO', `测试目标会话:${displayName} (${sessionId})`)
await this.generateInsightForSession({
const result = await this.generateInsightForSession({
sessionId,
displayName,
triggerReason: 'test'
})
if (!result.success) {
return { success: false, message: result.message }
}
const notificationEnabled = this.config.get('aiInsightNotificationEnabled') !== false
return {
success: true,
@@ -482,6 +566,47 @@ class InsightService {
}
}
/**
* 手动对指定会话立即触发一次 AI 见解。
* 只新增触发入口;实际上下文、朋友圈/微博拼接、prompt 和入库仍走 generateInsightForSession。
*/
async triggerSessionInsight(params: {
sessionId: string
displayName?: string
avatarUrl?: string
}): Promise<SessionInsightTriggerResult> {
const sessionId = String(params?.sessionId || '').trim()
if (!sessionId) {
return { success: false, message: '当前会话无效,无法触发 AI 见解' }
}
if (!this.isEnabled()) {
return { success: false, message: '请先在设置中开启「AI 见解」' }
}
const { apiBaseUrl, apiKey } = this.getSharedAiModelConfig()
if (!apiBaseUrl || !apiKey) {
return { success: false, message: '请先填写通用 AI 模型配置API 地址和 Key' }
}
try {
const connectResult = await chatService.connect()
if (!connectResult.success) {
return { success: false, message: '数据库连接失败,请先在"数据库连接"页完成配置' }
}
this.dbConnected = true
const displayName = String(params?.displayName || sessionId).trim() || sessionId
insightLog('INFO', `手动触发当前会话见解:${displayName} (${sessionId})`)
return await this.generateInsightForSession({
sessionId,
displayName,
triggerReason: 'manual'
})
} catch (error) {
return { success: false, message: `触发失败:${(error as Error).message}` }
}
}
/** 获取今日触发统计(供设置页展示) */
getTodayStats(): { sessionId: string; count: number; times: string[] }[] {
this.resetIfNewDay()
@@ -590,6 +715,207 @@ ${topMentionText}
}
}
async generateMessageInsight(params: {
sessionId: string
displayName?: string
avatarUrl?: string
targetLocalId?: number
targetCreateTime?: number
targetMessageKey?: string
targetText: string
targetSenderName?: string
contextCount?: number
forceRefresh?: boolean
}): Promise<{ success: boolean; message: string; cached?: boolean; recordId?: string; data?: MessageInsightAnalysis }> {
const enabled = this.config.get('aiMessageInsightEnabled') === true
if (!enabled) {
return { success: false, message: '请先在设置中开启「消息解析」' }
}
const sessionId = String(params?.sessionId || '').trim()
const targetText = clampText(params?.targetText || '', 500)
const targetCreateTime = Math.floor(Number(params?.targetCreateTime || 0))
const targetLocalId = Math.floor(Number(params?.targetLocalId || 0))
const targetMessageKey = String(params?.targetMessageKey || '').trim()
if (!sessionId || !targetText || targetCreateTime <= 0) {
return { success: false, message: '目标消息无效,无法解析' }
}
if (params?.forceRefresh !== true) {
const cached = insightRecordService.findLatestMessageAnalysis({
sessionId,
targetLocalId,
targetCreateTime,
targetMessageKey
})
if (cached?.messageInsight?.analysis) {
return {
success: true,
message: '已读取缓存解析',
cached: true,
recordId: cached.id,
data: cached.messageInsight.analysis
}
}
}
const { apiBaseUrl, apiKey, model, maxTokens } = this.getSharedAiModelConfig()
if (!apiBaseUrl || !apiKey) {
return { success: false, message: '请先填写通用 AI 模型配置API 地址和 Key' }
}
const configuredContextCount = Number(this.config.get('aiMessageInsightContextCount') || 50)
const contextCount = Math.max(1, Math.min(200, Math.floor(Number(params?.contextCount || configuredContextCount) || 50)))
const displayName = await this.resolveInsightSessionDisplayName(sessionId, String(params?.displayName || sessionId))
const targetSenderName = clampText(params?.targetSenderName || displayName, 40) || displayName
const targetTextPreview = clampText(targetText, 120)
let avatarUrl = String(params?.avatarUrl || '').trim() || undefined
if (!avatarUrl) {
try {
const contact = await chatService.getContactAvatar(sessionId)
avatarUrl = String(contact?.avatarUrl || '').trim() || undefined
} catch {
avatarUrl = undefined
}
}
let beforeMessages: Message[] = []
let afterMessages: Message[] = []
let contextReadError = ''
try {
const aroundResult = await chatService.getMessagesAround(
sessionId,
{ localId: targetLocalId, createTime: targetCreateTime, messageKey: targetMessageKey },
contextCount
)
if (aroundResult.success) {
beforeMessages = aroundResult.before || []
afterMessages = aroundResult.after || []
} else {
contextReadError = aroundResult.error || '读取上下文失败'
}
} catch (error) {
contextReadError = (error as Error).message || String(error)
}
const formatLine = (message: Message) => {
const senderName = message.isSend === 1 ? '我' : (message.senderDisplayName || targetSenderName || displayName)
return `${this.formatInsightMessageTimestamp(message.createTime)} ${senderName}${this.formatInsightMessageContent(message)}`
}
const beforeText = beforeMessages.length > 0 ? beforeMessages.map(formatLine).join('\n') : '无'
const afterText = afterMessages.length > 0 ? afterMessages.map(formatLine).join('\n') : '无'
const DEFAULT_MESSAGE_INSIGHT_PROMPT = `你是一个克制、准确的聊天语义分析助手。你的任务是把用户选中的一句聊天消息做深度解析,帮助用户理解对方未明说的含义。
严格要求:
1. 必须且只能输出合法的纯 JSON。
2. 禁止输出解释说明、前言后语,禁止使用 Markdown 或代码块。
3. 不要编造上下文没有支持的信息;不确定时用谨慎表述。
4. explicit_text 用自然中文说明这句话可能想表达的真实含义80字以内。
5. emotion、intent、topic 必须是短标签。
JSON 输出格式:
{
"explicit_text": "暗示转明示80字以内",
"emotion": "2-6字情绪标签",
"intent": "2-8字意图标签",
"topic": "2-8字话题标签"
}`
const customPrompt = String(this.config.get('aiMessageInsightSystemPrompt') || '').trim()
const systemPrompt = customPrompt || DEFAULT_MESSAGE_INSIGHT_PROMPT
const userPromptBase = `会话:${displayName}
目标发送者:${targetSenderName}
目标消息时间:${this.formatInsightMessageTimestamp(targetCreateTime)}
目标消息:
${targetText}
目标消息之前的上下文(${beforeMessages.length} 条):
${beforeText}
目标消息之后的上下文(${afterMessages.length} 条):
${afterText}
请分析目标消息,只输出指定 JSON。`
const userPrompt = appendPromptCurrentTime(userPromptBase)
const endpoint = buildApiUrl(apiBaseUrl, '/chat/completions')
const requestMessages = [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
]
let rawOutput = ''
let responseFormatJson = true
let responseFormatFallback = false
let responseFormatFallbackReason = ''
const startedAt = Date.now()
try {
try {
rawOutput = await callApi(apiBaseUrl, apiKey, model, requestMessages, API_TIMEOUT_MS, maxTokens, { responseFormatJson: true })
} catch (error) {
if (!shouldFallbackJsonMode(error)) throw error
responseFormatJson = false
responseFormatFallback = true
responseFormatFallbackReason = (error as Error).message || 'response_format 不受支持'
rawOutput = await callApi(apiBaseUrl, apiKey, model, requestMessages, API_TIMEOUT_MS, maxTokens)
}
const analysis = parseMessageInsightAnalysis(rawOutput)
const finalInsight = analysis.explicitText
const log: InsightRecordLog = {
endpoint,
model,
maxTokens,
temperature: API_TEMPERATURE,
triggerReason: 'message_analysis',
allowContext: true,
contextCount,
systemPrompt,
userPrompt,
rawOutput,
finalInsight,
durationMs: Date.now() - startedAt,
createdAt: Date.now(),
responseFormatJson,
responseFormatFallback,
responseFormatFallbackReason,
targetMessage: {
localId: targetLocalId,
createTime: targetCreateTime,
messageKey: targetMessageKey,
senderName: targetSenderName,
textPreview: targetTextPreview
},
contextStats: {
requested: contextCount,
beforeTarget: beforeMessages.length,
afterTarget: afterMessages.length,
readError: contextReadError || undefined
},
parsedAnalysis: analysis
}
const record = insightRecordService.addRecord({
sessionId,
displayName,
avatarUrl,
sourceType: 'message_analysis',
triggerReason: 'message_analysis',
insight: finalInsight,
messageInsight: {
targetLocalId,
targetCreateTime,
targetMessageKey,
targetSenderName,
targetTextPreview,
analysis
},
log
})
return { success: true, message: '解析完成', cached: false, recordId: record.id, data: analysis }
} catch (error) {
return { success: false, message: `解析失败:${(error as Error).message}` }
}
}
// ── 私有方法 ────────────────────────────────────────────────────────────────
private isEnabled(): boolean {
@@ -1099,10 +1425,10 @@ ${topMentionText}
displayName: string
triggerReason: InsightRecordTriggerReason
silentDays?: number
}): Promise<void> {
}): Promise<SessionInsightTriggerResult> {
const { sessionId, displayName, triggerReason, silentDays } = params
if (!sessionId) return
if (!this.isEnabled()) return
if (!sessionId) return { success: false, message: '会话无效,无法生成见解' }
if (!this.isEnabled()) return { success: false, message: '请先在设置中开启「AI 见解」' }
const { apiBaseUrl, apiKey, model, maxTokens } = this.getSharedAiModelConfig()
const allowContext = this.config.get('aiInsightAllowContext') as boolean
@@ -1120,7 +1446,7 @@ ${topMentionText}
if (!apiBaseUrl || !apiKey) {
insightLog('WARN', 'API 地址或 Key 未配置,跳过见解生成')
return
return { success: false, message: '请先填写通用 AI 模型配置API 地址和 Key' }
}
// ── 构建 prompt ────────────────────────────────────────────────────────────
@@ -1210,9 +1536,9 @@ ${topMentionText}
// 模型主动选择跳过
if (result.trim().toUpperCase() === 'SKIP' || result.trim().startsWith('SKIP')) {
insightLog('INFO', `模型选择跳过 ${resolvedDisplayName}`)
return
return { success: true, message: `模型判断「${resolvedDisplayName}」暂无可生成的见解`, skipped: true }
}
if (!this.isEnabled()) return
if (!this.isEnabled()) return { success: false, message: 'AI 见解已关闭,生成结果未保存' }
const insight = result.trim()
const notifTitle = `见解 · ${resolvedDisplayName}`
@@ -1277,6 +1603,15 @@ ${topMentionText}
insightLog('INFO', `已完成 ${resolvedDisplayName} 的见解处理`)
this.recordTrigger(sessionId)
return {
success: true,
message: insightNotificationEnabled
? `已生成「${resolvedDisplayName}」的 AI 见解,请查看通知弹窗`
: `已生成「${resolvedDisplayName}」的 AI 见解AI 见解消息通知当前已关闭`,
recordId: record.id,
insight,
notificationEnabled: insightNotificationEnabled
}
} catch (e) {
insightDebugSection(
'ERROR',
@@ -1284,6 +1619,7 @@ ${topMentionText}
`错误信息:${(e as Error).message}\n\n堆栈\n${(e as Error).stack || '[无堆栈]'}`
)
insightLog('ERROR', `API 调用失败 (${resolvedDisplayName}): ${(e as Error).message}`)
return { success: false, message: `生成失败:${(e as Error).message}` }
}
}

View File

@@ -5,7 +5,7 @@ import { execFile, exec, spawn } from 'child_process'
import { promisify } from 'util'
import crypto from 'crypto'
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const require = createRequire(__filename);
const execFileAsync = promisify(execFile)
const execAsync = promisify(exec)

View File

@@ -14,6 +14,7 @@ export interface SnsLivePhoto {
thumb: string
md5?: string
token?: string
thumbToken?: string
key?: string
encIdx?: string
}
@@ -23,6 +24,7 @@ export interface SnsMedia {
thumb: string
md5?: string
token?: string
thumbToken?: string
key?: string
encIdx?: string
livePhoto?: SnsLivePhoto
@@ -126,12 +128,22 @@ const fixSnsUrl = (url: string, token?: string, isVideo: boolean = false) => {
let fixedUrl = url.replace('http://', 'https://')
// 只有非视频(即图片)才需要处理 /150 变 /0
// 只有非视频(即图片)才需要处理路径末尾的尺寸标识(/150、/200等变为 /0
if (!isVideo) {
fixedUrl = fixedUrl.replace(/\/150($|\?)/, '/0$1')
const [pathPart, queryPart] = fixedUrl.split('?')
const fixedPath = pathPart.replace(/\/(150|200|480)($|\?)/, '/0$2')
fixedUrl = queryPart ? `${fixedPath}?${queryPart}` : fixedPath
}
if (!token || fixedUrl.includes('token=')) return fixedUrl
// 如果没有提供新token直接返回
if (!token) return fixedUrl
// 移除已有的token和idx参数
const [pathPart, queryPart] = fixedUrl.split('?')
if (queryPart) {
const params = queryPart.split('&').filter(p => !p.startsWith('token=') && !p.startsWith('idx='))
fixedUrl = params.length > 0 ? `${pathPart}?${params.join('&')}` : pathPart
}
// 根据用户要求,视频链接组合方式为: BASE_URL + "?" + "token=" + token + "&idx=1" + 原有参数
if (isVideo) {
@@ -704,6 +716,7 @@ class SnsService {
url: urlMatch ? urlMatch[1].trim() : '',
thumb: thumbMatch ? thumbMatch[1].trim() : '',
token: urlToken || thumbToken,
thumbToken: thumbToken,
key: urlKey || thumbKey,
md5: urlMd5,
encIdx: urlEncIdx || thumbEncIdx
@@ -716,19 +729,24 @@ class SnsService {
const lpUrlTag = lx.match(/<url([^>]*)>/i)
const lpThumb = lx.match(/<thumb[^>]*>([^<]+)<\/thumb>/i)
const lpThumbTag = lx.match(/<thumb([^>]*)>/i)
let lpToken: string | undefined, lpKey: string | undefined, lpEncIdx: string | undefined
let lpUrlToken: string | undefined, lpThumbToken: string | undefined
let lpKey: string | undefined, lpEncIdx: string | undefined
if (lpUrlTag?.[1]) {
const a = lpUrlTag[1]
lpToken = a.match(/token="([^"]+)"/i)?.[1]
lpUrlToken = a.match(/token="([^"]+)"/i)?.[1]
lpKey = a.match(/key="([^"]+)"/i)?.[1]
lpEncIdx = a.match(/enc_idx="([^"]+)"/i)?.[1]
}
if (!lpToken && lpThumbTag?.[1]) lpToken = lpThumbTag[1].match(/token="([^"]+)"/i)?.[1]
if (!lpKey && lpThumbTag?.[1]) lpKey = lpThumbTag[1].match(/key="([^"]+)"/i)?.[1]
if (lpThumbTag?.[1]) {
const a = lpThumbTag[1]
lpThumbToken = a.match(/token="([^"]+)"/i)?.[1]
if (!lpKey) lpKey = a.match(/key="([^"]+)"/i)?.[1]
}
item.livePhoto = {
url: lpUrl ? lpUrl[1].trim() : '',
thumb: lpThumb ? lpThumb[1].trim() : '',
token: lpToken,
token: lpUrlToken || lpThumbToken,
thumbToken: lpThumbToken,
key: lpKey,
encIdx: lpEncIdx
}
@@ -1181,16 +1199,18 @@ class SnsService {
const fixedMedia = (post.media || []).map((m: any) => ({
url: fixSnsUrl(m.url, m.token, isVideoPost),
thumb: fixSnsUrl(m.thumb, m.token, false),
thumb: fixSnsUrl(m.thumb, m.thumbToken || m.token, false),
md5: m.md5,
token: m.token,
thumbToken: m.thumbToken,
key: isVideoPost ? (videoKey || m.key) : m.key,
encIdx: m.encIdx || m.enc_idx,
livePhoto: m.livePhoto ? {
...m.livePhoto,
url: fixSnsUrl(m.livePhoto.url, m.livePhoto.token, true),
thumb: fixSnsUrl(m.livePhoto.thumb, m.livePhoto.token, false),
thumb: fixSnsUrl(m.livePhoto.thumb, m.livePhoto.thumbToken || m.livePhoto.token, false),
token: m.livePhoto.token,
thumbToken: m.livePhoto.thumbToken,
key: videoKey || m.livePhoto.key || m.key,
encIdx: m.livePhoto.encIdx || m.livePhoto.enc_idx
} : undefined
@@ -2060,6 +2080,8 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
const zlib = require('zlib')
const urlObj = new URL(url)
console.log(`[SnsService] 开始下载图片: url=${url.substring(0, 100)}..., key=${key || 'undefined'}`)
const options = {
hostname: urlObj.hostname,
path: urlObj.pathname + urlObj.search,
@@ -2074,7 +2096,9 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
}
const req = https.request(options, (res: any) => {
console.log(`[SnsService] CDN 响应: statusCode=${res.statusCode}, x-enc=${res.headers['x-enc']}, content-type=${res.headers['content-type']}`)
if (res.statusCode !== 200 && res.statusCode !== 206) {
console.error(`[SnsService] CDN 请求失败: HTTP ${res.statusCode}`)
resolve({ success: false, error: `HTTP ${res.statusCode}` })
return
}
@@ -2094,9 +2118,11 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
let decoded = raw
const rawMagicMime = detectImageMime(raw, '')
console.log(`[SnsService] 原始数据: size=${raw.length}, mime=${rawMagicMime}, xEnc=${xEnc}`)
// 图片逻辑
const shouldDecrypt = (xEnc === '1' || !!key) && key !== undefined && key !== null && String(key).trim().length > 0
console.log(`[SnsService] 解密判断: shouldDecrypt=${shouldDecrypt}, key=${key || 'undefined'}`)
if (shouldDecrypt) {
try {
const keyStr = String(key).trim()
@@ -2112,6 +2138,7 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
}
const decryptedMagicMime = detectImageMime(decrypted, '')
console.log(`[SnsService] 解密后: mime=${decryptedMagicMime}`)
if (decryptedMagicMime.startsWith('image/')) {
decoded = decrypted
} else if (!rawMagicMime.startsWith('image/')) {
@@ -2124,7 +2151,9 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
}
const decodedMagicMime = detectImageMime(decoded, '')
console.log(`[SnsService] 最终结果: mime=${decodedMagicMime}, isImage=${decodedMagicMime.startsWith('image/')}`)
if (!decodedMagicMime.startsWith('image/')) {
console.error(`[SnsService] 图片解密失败: 原始mime=${rawMagicMime}, 解密后mime=${decodedMagicMime}, key=${key}`)
resolve({ success: false, error: '图片解密失败:无法识别图片格式' })
return
}

View File

@@ -0,0 +1,3 @@
{
"defaultSystemPrompt": "你是一个群聊会议纪要式总结助手。你只根据用户提供的群聊记录总结,不编造记录中没有的信息。\n\n严格要求\n1. 必须且只能输出合法纯 JSON禁止 Markdown 和解释说明。\n2. 按话题分类总结,每个话题包含参与者、关键/矛盾点、结论。\n3. 参与者写群成员显示名;不确定参与者时写已有发言人。\n4. 关键/矛盾点必须来自聊天记录,避免泛泛而谈。\n5. 结论要短、具体;没有结论时写“暂无明确结论”。\n\nJSON 输出格式:\n{\n \"topics\": [\n {\n \"title\": \"话题名称\",\n \"participants\": [\"参与者A\", \"参与者B\"],\n \"key_points\": [\"关键点或矛盾点\"],\n \"conclusion\": \"结论\"\n }\n ]\n}"
}

View File

@@ -551,8 +551,13 @@ export function ExportDateRangeDialog({
if (!open) return null
return createPortal(
<div className="export-date-range-dialog-overlay" onClick={onClose}>
<div className="export-date-range-dialog" role="dialog" aria-modal="true" onClick={(event) => event.stopPropagation()}>
<div
className="export-date-range-dialog-overlay"
onClick={(event) => {
event.stopPropagation()
onClose()
}}
> <div className="export-date-range-dialog" role="dialog" aria-modal="true" onClick={(event) => event.stopPropagation()}>
<div className="export-date-range-dialog-header">
<h4>{title}</h4>
<button

View File

@@ -231,7 +231,8 @@
label {
display: inline-flex;
align-items: center;
gap: 5px;
gap: 6px;
position: relative;
margin-bottom: 0;
font-size: 13px;
line-height: 1;
@@ -239,11 +240,55 @@
color: var(--text-primary);
cursor: pointer;
white-space: nowrap;
transition: border-color 0.16s ease, background 0.16s ease;
}
input[type='checkbox'] {
margin: 0;
accent-color: var(--primary);
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
pointer-events: none;
&:checked + .media-default-check {
border-color: var(--primary);
background: color-mix(in srgb, var(--primary) 88%, #fff);
}
&:checked + .media-default-check::after {
opacity: 1;
transform: rotate(-45deg) scale(1);
}
&:focus-visible + .media-default-check {
box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
}
.media-default-check {
width: 14px;
height: 14px;
flex: 0 0 14px;
border: 1px solid color-mix(in srgb, var(--border-color) 82%, var(--text-tertiary));
border-radius: 4px;
background: var(--bg-primary);
display: inline-flex;
align-items: center;
justify-content: center;
transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
&::after {
content: '';
width: 7px;
height: 4px;
border-left: 2px solid #fff;
border-bottom: 2px solid #fff;
opacity: 0;
transform: rotate(-45deg) scale(0.72);
transform-origin: center;
transition: opacity 0.16s ease, transform 0.16s ease;
}
}
}
@@ -563,15 +608,69 @@
gap: 8px;
label {
min-height: 36px;
padding: 8px 10px;
min-height: 34px;
padding: 7px 10px;
border: 1px solid var(--border-color);
border-radius: 8px;
background: var(--bg-primary);
&:hover {
border-color: color-mix(in srgb, var(--primary) 38%, var(--border-color));
background: color-mix(in srgb, var(--text-tertiary) 4%, var(--bg-primary));
}
}
}
}
.select-dropdown-floating {
background: color-mix(in srgb, var(--bg-primary) 85%, var(--bg-secondary));
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 6px;
box-shadow: var(--shadow-md);
overflow-y: auto;
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
.select-option {
width: 100%;
text-align: left;
display: flex;
flex-direction: column;
gap: 4px;
padding: 10px 12px;
border: none;
border-radius: 10px;
background: transparent;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease;
color: var(--text-primary);
font-size: 14px;
&:hover {
background: var(--bg-tertiary);
}
&.active {
background: color-mix(in srgb, var(--primary) 12%, transparent);
color: var(--primary);
}
}
.option-label {
font-weight: 500;
}
.option-desc {
font-size: 12px;
color: var(--text-tertiary);
}
.select-option.active .option-desc {
color: var(--primary);
}
}
@media (max-width: 980px) {
.export-defaults-settings-form.layout-split {
.form-group {

View File

@@ -1,4 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import type { CSSProperties } from 'react'
import { createPortal } from 'react-dom'
import { ChevronDown } from 'lucide-react'
import * as configService from '../../services/config'
import { ExportDateRangeDialog } from './ExportDateRangeDialog'
@@ -56,6 +58,48 @@ const getOptionLabel = (options: ReadonlyArray<{ value: string; label: string }>
return options.find((option) => option.value === value)?.label ?? value
}
interface SelectDropdownPlacement {
left: number
width: number
maxHeight: number
top?: number
bottom?: number
}
const resolveSelectDropdownPlacement = (anchor: HTMLElement | null): SelectDropdownPlacement | null => {
if (!anchor || typeof window === 'undefined') return null
const rect = anchor.getBoundingClientRect()
const viewportWidth = window.innerWidth || document.documentElement.clientWidth
const viewportHeight = window.innerHeight || document.documentElement.clientHeight
const viewportMargin = 12
const dropdownGap = 6
const minDropdownHeight = 128
const availableWidth = Math.max(160, viewportWidth - viewportMargin * 2)
const width = Math.min(Math.max(rect.width, 220), availableWidth)
const left = Math.max(viewportMargin, Math.min(rect.left, viewportWidth - width - viewportMargin))
const spaceBelow = Math.max(0, viewportHeight - rect.bottom - viewportMargin - dropdownGap)
const spaceAbove = Math.max(0, rect.top - viewportMargin - dropdownGap)
const shouldOpenAbove = spaceBelow < minDropdownHeight && spaceAbove > spaceBelow
const availableHeight = shouldOpenAbove ? spaceAbove : spaceBelow
const maxHeight = Math.max(96, Math.min(320, availableHeight))
return shouldOpenAbove
? { left, width, maxHeight, bottom: viewportHeight - rect.top + dropdownGap }
: { left, width, maxHeight, top: rect.bottom + dropdownGap }
}
const getSelectDropdownStyle = (placement: SelectDropdownPlacement): CSSProperties => ({
position: 'fixed',
top: placement.top,
bottom: placement.bottom,
left: placement.left,
right: 'auto',
width: placement.width,
maxHeight: placement.maxHeight,
zIndex: 9300
})
export function ExportDefaultsSettingsForm({
onNotify,
onDefaultsChanged,
@@ -66,6 +110,10 @@ export function ExportDefaultsSettingsForm({
const [isExportDateRangeDialogOpen, setIsExportDateRangeDialogOpen] = useState(false)
const exportExcelColumnsDropdownRef = useRef<HTMLDivElement>(null)
const exportFileNamingModeDropdownRef = useRef<HTMLDivElement>(null)
const exportExcelColumnsMenuRef = useRef<HTMLDivElement>(null)
const exportFileNamingModeMenuRef = useRef<HTMLDivElement>(null)
const [exportExcelColumnsPlacement, setExportExcelColumnsPlacement] = useState<SelectDropdownPlacement | null>(null)
const [exportFileNamingModePlacement, setExportFileNamingModePlacement] = useState<SelectDropdownPlacement | null>(null)
const [exportDefaultFormat, setExportDefaultFormat] = useState('excel')
const [exportDefaultAvatars, setExportDefaultAvatars] = useState(true)
@@ -122,10 +170,20 @@ export function ExportDefaultsSettingsForm({
useEffect(() => {
const handleClickOutside = (e: MouseEvent) => {
const target = e.target as Node
if (showExportExcelColumnsSelect && exportExcelColumnsDropdownRef.current && !exportExcelColumnsDropdownRef.current.contains(target)) {
if (
showExportExcelColumnsSelect &&
exportExcelColumnsDropdownRef.current &&
!exportExcelColumnsDropdownRef.current.contains(target) &&
!exportExcelColumnsMenuRef.current?.contains(target)
) {
setShowExportExcelColumnsSelect(false)
}
if (showExportFileNamingModeSelect && exportFileNamingModeDropdownRef.current && !exportFileNamingModeDropdownRef.current.contains(target)) {
if (
showExportFileNamingModeSelect &&
exportFileNamingModeDropdownRef.current &&
!exportFileNamingModeDropdownRef.current.contains(target) &&
!exportFileNamingModeMenuRef.current?.contains(target)
) {
setShowExportFileNamingModeSelect(false)
}
}
@@ -134,6 +192,30 @@ export function ExportDefaultsSettingsForm({
return () => document.removeEventListener('mousedown', handleClickOutside)
}, [showExportExcelColumnsSelect, showExportFileNamingModeSelect])
const updateSelectDropdownPlacements = useCallback(() => {
if (showExportExcelColumnsSelect) {
setExportExcelColumnsPlacement(resolveSelectDropdownPlacement(exportExcelColumnsDropdownRef.current))
}
if (showExportFileNamingModeSelect) {
setExportFileNamingModePlacement(resolveSelectDropdownPlacement(exportFileNamingModeDropdownRef.current))
}
}, [showExportExcelColumnsSelect, showExportFileNamingModeSelect])
useEffect(() => {
if (!showExportExcelColumnsSelect) setExportExcelColumnsPlacement(null)
if (!showExportFileNamingModeSelect) setExportFileNamingModePlacement(null)
if (!showExportExcelColumnsSelect && !showExportFileNamingModeSelect) return
updateSelectDropdownPlacements()
window.addEventListener('resize', updateSelectDropdownPlacements)
document.addEventListener('scroll', updateSelectDropdownPlacements, true)
return () => {
window.removeEventListener('resize', updateSelectDropdownPlacements)
document.removeEventListener('scroll', updateSelectDropdownPlacements, true)
}
}, [showExportExcelColumnsSelect, showExportFileNamingModeSelect, updateSelectDropdownPlacements])
const exportExcelColumnsValue = exportDefaultExcelCompactColumns ? 'compact' : 'full'
const exportDateRangeLabel = useMemo(() => getExportDateRangeLabel(exportDefaultDateRange), [exportDefaultDateRange])
const exportExcelColumnsLabel = useMemo(() => getOptionLabel(exportExcelColumnOptions, exportExcelColumnsValue), [exportExcelColumnsValue])
@@ -143,6 +225,73 @@ export function ExportDefaultsSettingsForm({
onNotify?.(text, success)
}
const fileNamingModeDropdown = showExportFileNamingModeSelect && exportFileNamingModePlacement
? createPortal(
<div
ref={exportFileNamingModeMenuRef}
className="select-dropdown select-dropdown-floating"
role="listbox"
style={getSelectDropdownStyle(exportFileNamingModePlacement)}
onClick={(event) => event.stopPropagation()}
>
{exportFileNamingModeOptions.map((option) => (
<button
key={option.value}
type="button"
role="option"
aria-selected={exportDefaultFileNamingMode === option.value}
className={`select-option ${exportDefaultFileNamingMode === option.value ? 'active' : ''}`}
onClick={async () => {
setExportDefaultFileNamingMode(option.value)
await configService.setExportDefaultFileNamingMode(option.value)
onDefaultsChanged?.({ fileNamingMode: option.value })
notify('已更新导出文件命名方式', true)
setShowExportFileNamingModeSelect(false)
}}
>
<span className="option-label">{option.label}</span>
<span className="option-desc">{option.desc}</span>
</button>
))}
</div>,
document.body
)
: null
const excelColumnsDropdown = showExportExcelColumnsSelect && exportExcelColumnsPlacement
? createPortal(
<div
ref={exportExcelColumnsMenuRef}
className="select-dropdown select-dropdown-floating"
role="listbox"
style={getSelectDropdownStyle(exportExcelColumnsPlacement)}
onClick={(event) => event.stopPropagation()}
>
{exportExcelColumnOptions.map((option) => (
<button
key={option.value}
type="button"
role="option"
aria-selected={exportExcelColumnsValue === option.value}
className={`select-option ${exportExcelColumnsValue === option.value ? 'active' : ''}`}
onClick={async () => {
const compact = option.value === 'compact'
setExportDefaultExcelCompactColumns(compact)
await configService.setExportDefaultExcelCompactColumns(compact)
onDefaultsChanged?.({ excelCompactColumns: compact })
notify(compact ? '已启用精简列' : '已启用完整列', true)
setShowExportExcelColumnsSelect(false)
}}
>
<span className="option-label">{option.label}</span>
<span className="option-desc">{option.desc}</span>
</button>
))}
</div>,
document.body
)
: null
return (
<div className={`export-defaults-settings-form ${layout === 'split' ? 'layout-split' : 'layout-stacked'}`}>
<div className="form-group">
@@ -273,6 +422,8 @@ export function ExportDefaultsSettingsForm({
<button
type="button"
className={`select-trigger ${showExportFileNamingModeSelect ? 'open' : ''}`}
aria-haspopup="listbox"
aria-expanded={showExportFileNamingModeSelect}
onClick={() => {
setShowExportFileNamingModeSelect(!showExportFileNamingModeSelect)
setShowExportExcelColumnsSelect(false)
@@ -282,27 +433,7 @@ export function ExportDefaultsSettingsForm({
<span className="select-value">{exportFileNamingModeLabel}</span>
<ChevronDown size={16} />
</button>
{showExportFileNamingModeSelect && (
<div className="select-dropdown">
{exportFileNamingModeOptions.map((option) => (
<button
key={option.value}
type="button"
className={`select-option ${exportDefaultFileNamingMode === option.value ? 'active' : ''}`}
onClick={async () => {
setExportDefaultFileNamingMode(option.value)
await configService.setExportDefaultFileNamingMode(option.value)
onDefaultsChanged?.({ fileNamingMode: option.value })
notify('已更新导出文件命名方式', true)
setShowExportFileNamingModeSelect(false)
}}
>
<span className="option-label">{option.label}</span>
<span className="option-desc">{option.desc}</span>
</button>
))}
</div>
)}
{fileNamingModeDropdown}
</div>
</div>
</div>
@@ -317,6 +448,8 @@ export function ExportDefaultsSettingsForm({
<button
type="button"
className={`select-trigger ${showExportExcelColumnsSelect ? 'open' : ''}`}
aria-haspopup="listbox"
aria-expanded={showExportExcelColumnsSelect}
onClick={() => {
setShowExportExcelColumnsSelect(!showExportExcelColumnsSelect)
setShowExportFileNamingModeSelect(false)
@@ -326,28 +459,7 @@ export function ExportDefaultsSettingsForm({
<span className="select-value">{exportExcelColumnsLabel}</span>
<ChevronDown size={16} />
</button>
{showExportExcelColumnsSelect && (
<div className="select-dropdown">
{exportExcelColumnOptions.map((option) => (
<button
key={option.value}
type="button"
className={`select-option ${exportExcelColumnsValue === option.value ? 'active' : ''}`}
onClick={async () => {
const compact = option.value === 'compact'
setExportDefaultExcelCompactColumns(compact)
await configService.setExportDefaultExcelCompactColumns(compact)
onDefaultsChanged?.({ excelCompactColumns: compact })
notify(compact ? '已启用精简列' : '已启用完整列', true)
setShowExportExcelColumnsSelect(false)
}}
>
<span className="option-label">{option.label}</span>
<span className="option-desc">{option.desc}</span>
</button>
))}
</div>
)}
{excelColumnsDropdown}
</div>
</div>
</div>
@@ -371,7 +483,8 @@ export function ExportDefaultsSettingsForm({
notify(`${e.target.checked ? '开启' : '关闭'}默认导出图片`, true)
}}
/>
<span className="media-default-check" aria-hidden="true" />
<span></span>
</label>
<label>
<input
@@ -385,7 +498,8 @@ export function ExportDefaultsSettingsForm({
notify(`${e.target.checked ? '开启' : '关闭'}默认导出语音`, true)
}}
/>
<span className="media-default-check" aria-hidden="true" />
<span></span>
</label>
<label>
<input
@@ -399,7 +513,8 @@ export function ExportDefaultsSettingsForm({
notify(`${e.target.checked ? '开启' : '关闭'}默认导出视频`, true)
}}
/>
<span className="media-default-check" aria-hidden="true" />
<span></span>
</label>
<label>
<input
@@ -413,7 +528,8 @@ export function ExportDefaultsSettingsForm({
notify(`${e.target.checked ? '开启' : '关闭'}默认导出表情包`, true)
}}
/>
<span className="media-default-check" aria-hidden="true" />
<span></span>
</label>
<label>
<input
@@ -427,7 +543,8 @@ export function ExportDefaultsSettingsForm({
notify(`${e.target.checked ? '开启' : '关闭'}默认导出文件`, true)
}}
/>
<span className="media-default-check" aria-hidden="true" />
<span></span>
</label>
</div>
</div>

View File

@@ -15,6 +15,7 @@ interface JumpToDatePopoverProps {
messageDateCounts?: Record<string, number>
loadingDates?: boolean
loadingDateCounts?: boolean
maxDate?: Date
}
const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
@@ -29,7 +30,8 @@ const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
hasLoadedMessageDates = false,
messageDateCounts,
loadingDates = false,
loadingDateCounts = false
loadingDateCounts = false,
maxDate
}) => {
type CalendarViewMode = 'day' | 'month' | 'year'
const getYearPageStart = (year: number): number => Math.floor(year / 12) * 12
@@ -73,6 +75,14 @@ const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
return messageDates.has(toDateKey(day))
}
const isAfterMaxDate = (day: number): boolean => {
if (!maxDate) return false
const max = new Date(maxDate)
max.setHours(23, 59, 59, 999)
const candidate = new Date(calendarDate.getFullYear(), calendarDate.getMonth(), day, 0, 0, 0, 0)
return candidate.getTime() > max.getTime()
}
const isToday = (day: number): boolean => {
const today = new Date()
return day === today.getDate()
@@ -102,6 +112,7 @@ const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
const handleDateClick = (day: number) => {
if (hasLoadedMessageDates && !hasMessage(day)) return
if (isAfterMaxDate(day)) return
const targetDate = new Date(calendarDate.getFullYear(), calendarDate.getMonth(), day)
setSelectedDate(targetDate)
onSelect(targetDate)
@@ -113,7 +124,7 @@ const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
const classes = ['day-cell']
if (isToday(day)) classes.push('today')
if (isSelected(day)) classes.push('selected')
if (hasLoadedMessageDates && !hasMessage(day)) classes.push('no-message')
if ((hasLoadedMessageDates && !hasMessage(day)) || isAfterMaxDate(day)) classes.push('no-message')
return classes.join(' ')
}
@@ -225,6 +236,7 @@ const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
if (day === null) return <div key={index} className="day-cell empty" />
const dateKey = toDateKey(day)
const hasMessageOnDay = hasMessage(day)
const isDisabled = (hasLoadedMessageDates && !hasMessageOnDay) || isAfterMaxDate(day)
const count = Number(messageDateCounts?.[dateKey] || 0)
const showCount = count > 0
const showCountLoading = hasMessageOnDay && loadingDateCounts && !showCount
@@ -233,7 +245,7 @@ const JumpToDatePopover: React.FC<JumpToDatePopoverProps> = ({
key={index}
className={getDayClassName(day)}
onClick={() => handleDateClick(day)}
disabled={hasLoadedMessageDates && !hasMessageOnDay}
disabled={isDisabled}
type="button"
>
<span className="day-number">{day}</span>

View File

@@ -8,8 +8,10 @@ import {
Info,
Loader2,
Mic,
Newspaper,
RefreshCw,
Search,
Sparkles,
Users
} from 'lucide-react'
import { Avatar } from '../../components/Avatar'
@@ -21,9 +23,11 @@ export interface ChatHeaderProps {
isGroupChat: boolean
standaloneSessionWindow: boolean
showGroupMembersPanel: boolean
showGroupSummaryPanel: boolean
showJumpPopover: boolean
showInSessionSearch: boolean
showDetailPanel: boolean
aiGroupSummaryEnabled: boolean
shouldHideStandaloneDetailButton: boolean
isPrivateSnsSupported: boolean
isExportActionBusy: boolean
@@ -32,10 +36,13 @@ export interface ChatHeaderProps {
isBatchTranscribing: boolean
runningBatchVoiceTaskType?: BatchVoiceTaskType
isBatchDecrypting: boolean
isTriggeringSessionInsight: boolean
isRefreshingMessages: boolean
isLoadingMessages: boolean
currentSessionId?: string | null
jumpCalendarWrapRef: React.RefObject<HTMLDivElement | null>
onTriggerSessionInsight: () => void
onToggleGroupSummaryPanel: () => void
onGroupAnalytics: () => void
onToggleGroupMembersPanel: () => void
onExportCurrentSession: () => void
@@ -53,9 +60,11 @@ function ChatHeader({
isGroupChat,
standaloneSessionWindow,
showGroupMembersPanel,
showGroupSummaryPanel,
showJumpPopover,
showInSessionSearch,
showDetailPanel,
aiGroupSummaryEnabled,
shouldHideStandaloneDetailButton,
isPrivateSnsSupported,
isExportActionBusy,
@@ -64,10 +73,13 @@ function ChatHeader({
isBatchTranscribing,
runningBatchVoiceTaskType,
isBatchDecrypting,
isTriggeringSessionInsight,
isRefreshingMessages,
isLoadingMessages,
currentSessionId,
jumpCalendarWrapRef,
onTriggerSessionInsight,
onToggleGroupSummaryPanel,
onGroupAnalytics,
onToggleGroupMembersPanel,
onExportCurrentSession,
@@ -102,6 +114,26 @@ function ChatHeader({
{isGroupChat && <div className="header-subtitle"></div>}
</div>
<div className="header-actions">
<button
className={`icon-btn session-insight-btn${isTriggeringSessionInsight ? ' triggering' : ''}`}
onClick={onTriggerSessionInsight}
disabled={!currentSessionId || isTriggeringSessionInsight}
title={isTriggeringSessionInsight ? '正在生成 AI 见解' : '立即触发当前聊天 AI 见解'}
aria-label="立即触发当前聊天 AI 见解"
>
{isTriggeringSessionInsight ? <Loader2 size={18} className="spin" /> : <Sparkles size={18} />}
</button>
{isGroupChat && aiGroupSummaryEnabled && (
<button
className={`icon-btn group-summary-btn ${showGroupSummaryPanel ? 'active' : ''}`}
onClick={onToggleGroupSummaryPanel}
disabled={!currentSessionId}
title="AI 群聊总结"
aria-label="AI 群聊总结"
>
<Newspaper size={18} />
</button>
)}
{!standaloneSessionWindow && isGroupChat && (
<button className="icon-btn group-analytics-btn" onClick={onGroupAnalytics} title="群聊分析">
<BarChart3 size={18} />
@@ -203,9 +235,11 @@ function areEqual(prev: ChatHeaderProps, next: ChatHeaderProps) {
prev.isGroupChat === next.isGroupChat &&
prev.standaloneSessionWindow === next.standaloneSessionWindow &&
prev.showGroupMembersPanel === next.showGroupMembersPanel &&
prev.showGroupSummaryPanel === next.showGroupSummaryPanel &&
prev.showJumpPopover === next.showJumpPopover &&
prev.showInSessionSearch === next.showInSessionSearch &&
prev.showDetailPanel === next.showDetailPanel &&
prev.aiGroupSummaryEnabled === next.aiGroupSummaryEnabled &&
prev.shouldHideStandaloneDetailButton === next.shouldHideStandaloneDetailButton &&
prev.isPrivateSnsSupported === next.isPrivateSnsSupported &&
prev.isExportActionBusy === next.isExportActionBusy &&
@@ -214,10 +248,13 @@ function areEqual(prev: ChatHeaderProps, next: ChatHeaderProps) {
prev.isBatchTranscribing === next.isBatchTranscribing &&
prev.runningBatchVoiceTaskType === next.runningBatchVoiceTaskType &&
prev.isBatchDecrypting === next.isBatchDecrypting &&
prev.isTriggeringSessionInsight === next.isTriggeringSessionInsight &&
prev.isRefreshingMessages === next.isRefreshingMessages &&
prev.isLoadingMessages === next.isLoadingMessages &&
prev.currentSessionId === next.currentSessionId &&
prev.jumpCalendarWrapRef === next.jumpCalendarWrapRef &&
prev.onTriggerSessionInsight === next.onTriggerSessionInsight &&
prev.onToggleGroupSummaryPanel === next.onToggleGroupSummaryPanel &&
prev.onGroupAnalytics === next.onGroupAnalytics &&
prev.onToggleGroupMembersPanel === next.onToggleGroupMembersPanel &&
prev.onExportCurrentSession === next.onExportCurrentSession &&

View File

@@ -24,6 +24,7 @@ export interface ChatMessageBubbleProps {
isSelected?: boolean
onContextMenu?: (event: React.MouseEvent, message: Message) => void
onToggleSelection?: (messageKey: string, isShiftKey?: boolean) => void
actionNode?: React.ReactNode
children: React.ReactNode
portal?: React.ReactNode
}
@@ -57,6 +58,7 @@ function ChatMessageBubble({
isSelected,
onContextMenu,
onToggleSelection,
actionNode,
children,
portal
}: ChatMessageBubbleProps) {
@@ -92,12 +94,20 @@ function ChatMessageBubble({
</div>
<div className="bubble-body">
{isGroupChat && !isSent && (
<div className="sender-name">
{resolvedSenderName || '群成员'}
<div className="sender-line">
<div className="sender-name">
{resolvedSenderName || '群成员'}
</div>
{actionNode}
</div>
)}
{children}
</div>
{!isGroupChat && !isSent && actionNode ? (
<div className="message-action-inline">
{actionNode}
</div>
) : null}
</div>
{isSelectionMode && isSent && <SelectionCheckbox checked={isSelected} side="right" />}
@@ -131,6 +141,7 @@ function areEqual(prev: ChatMessageBubbleProps, next: ChatMessageBubbleProps) {
prev.isSelected === next.isSelected &&
prev.onContextMenu === next.onContextMenu &&
prev.onToggleSelection === next.onToggleSelection &&
prev.actionNode === next.actionNode &&
prev.children === next.children &&
prev.portal === next.portal
)

View File

@@ -1747,6 +1747,29 @@
}
}
.session-insight-hint {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 20px;
font-size: 12px;
color: var(--text-secondary);
border-bottom: 1px solid var(--border-color);
background: var(--bg-tertiary);
&.success {
color: var(--text-secondary);
}
&.error {
color: var(--danger);
}
.spin {
animation: spin 1s linear infinite;
}
}
.message-list {
flex: 1;
overflow-y: auto;
@@ -1922,6 +1945,10 @@
.message-wrapper.new-message {
animation: messagePop 0.35s ease-out;
.message-bubble:not(.system) .bubble-content {
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 45%, transparent);
}
}
@keyframes messagePop {
@@ -3542,6 +3569,271 @@
}
}
.group-summary-panel {
width: clamp(320px, 30vw, 420px);
min-width: 320px;
max-width: 420px;
.group-summary-controls {
padding: 12px;
border-bottom: 1px solid var(--border-color);
display: flex;
flex-direction: column;
gap: 10px;
background: var(--bg-primary);
}
.group-summary-date-row {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 8px;
label {
font-size: 12px;
color: var(--text-secondary);
font-weight: 600;
}
input,
.group-summary-date-trigger {
height: 32px;
min-width: 0;
border: 1px solid var(--border-color);
border-radius: 8px;
background: var(--card-bg);
color: var(--text-primary);
padding: 0 9px;
font-size: 12px;
}
}
.group-summary-date-picker {
position: relative;
min-width: 0;
}
.group-summary-date-trigger {
width: 100%;
display: inline-flex;
align-items: center;
justify-content: space-between;
gap: 8px;
cursor: pointer;
transition: all 0.16s ease;
svg {
color: var(--text-secondary);
flex-shrink: 0;
}
&:hover,
&.open {
border-color: color-mix(in srgb, var(--primary) 36%, var(--border-color));
background: var(--bg-hover);
}
}
.group-summary-calendar-popover {
right: auto;
left: 0;
top: calc(100% + 8px);
width: min(312px, calc(100vw - 32px));
border-radius: 10px;
}
.group-summary-icon-btn,
.group-summary-code-btn {
width: 30px;
height: 30px;
border: 1px solid color-mix(in srgb, var(--border-color) 78%, transparent);
border-radius: 8px;
background: var(--card-bg);
color: var(--text-secondary);
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.16s ease;
&:hover {
color: var(--primary);
background: var(--bg-hover);
border-color: color-mix(in srgb, var(--primary) 34%, var(--border-color));
}
.spin {
animation: spin 1s linear infinite;
}
}
.group-summary-range-tabs {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 6px;
button {
height: 30px;
border: 1px solid color-mix(in srgb, var(--border-color) 78%, transparent);
border-radius: 8px;
background: var(--card-bg);
color: var(--text-secondary);
font-size: 12px;
cursor: pointer;
transition: all 0.16s ease;
&.active {
color: var(--primary);
border-color: color-mix(in srgb, var(--primary) 42%, var(--border-color));
background: color-mix(in srgb, var(--primary) 10%, var(--card-bg));
font-weight: 600;
}
}
}
.group-summary-generate-btn {
height: 34px;
border: none;
border-radius: 8px;
background: var(--primary);
color: #fff;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 7px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: transform 0.16s ease, opacity 0.16s ease;
&:disabled {
opacity: 0.7;
cursor: not-allowed;
}
&:hover:not(:disabled) {
transform: translateY(-1px);
}
.spin {
animation: spin 1s linear infinite;
}
}
.group-summary-rule-hint,
.group-summary-count {
font-size: 12px;
color: var(--text-tertiary);
}
.group-summary-list {
flex: 1;
overflow-y: auto;
padding: 12px;
display: flex;
flex-direction: column;
gap: 10px;
}
.group-summary-record {
border: 1px solid color-mix(in srgb, var(--border-color) 74%, transparent);
background: var(--bg-secondary);
border-radius: 10px;
padding: 10px;
display: flex;
flex-direction: column;
gap: 10px;
}
.group-summary-record-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.group-summary-period {
display: block;
color: var(--text-primary);
font-size: 12px;
font-weight: 600;
line-height: 1.35;
}
.group-summary-meta {
display: block;
margin-top: 3px;
color: var(--text-tertiary);
font-size: 12px;
}
.group-summary-topic-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.group-summary-topic {
border-radius: 8px;
border: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
background: color-mix(in srgb, var(--card-bg) 88%, transparent);
padding: 9px;
h5 {
margin: 0 0 7px;
font-size: 13px;
color: var(--text-primary);
line-height: 1.35;
}
}
.group-summary-topic-row {
display: grid;
grid-template-columns: 72px 1fr;
gap: 8px;
padding: 5px 0;
border-top: 1px dashed color-mix(in srgb, var(--border-color) 72%, transparent);
span {
color: var(--text-tertiary);
font-size: 12px;
line-height: 1.45;
}
p {
margin: 0;
color: var(--text-secondary);
font-size: 12px;
line-height: 1.5;
word-break: break-word;
}
}
}
.group-summary-log-modal {
width: min(860px, calc(100vw - 32px));
max-height: min(760px, calc(100vh - 32px));
.detail-content {
max-height: calc(100vh - 120px);
}
}
.group-summary-log-pre {
margin: 0;
max-height: 260px;
overflow: auto;
padding: 10px;
border-radius: 8px;
background: color-mix(in srgb, var(--card-bg) 86%, transparent);
border: 1px solid color-mix(in srgb, var(--border-color) 72%, transparent);
color: var(--text-secondary);
font-size: 12px;
line-height: 1.5;
white-space: pre-wrap;
word-break: break-word;
}
@keyframes detailCardEnter {
from {
opacity: 0;
@@ -5828,6 +6120,245 @@
margin-bottom: 5px;
}
.sender-line {
display: flex;
align-items: center;
gap: 8px;
max-width: 100%;
min-height: 18px;
margin-bottom: 5px;
.sender-name {
min-width: 0;
margin-bottom: 0;
}
}
.message-action-inline {
width: 24px;
height: 24px;
margin: 6px 0 0 4px;
display: flex;
align-items: center;
justify-content: flex-start;
flex-shrink: 0;
}
.message-insight-trigger {
height: 18px;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--text-tertiary);
display: inline-flex;
align-items: center;
gap: 4px;
padding: 0 5px;
font-size: 12px;
line-height: 18px;
opacity: 0;
transform: translateX(3px);
cursor: pointer;
transition: opacity 0.16s ease, color 0.16s ease, background 0.16s ease;
-webkit-app-region: no-drag;
svg {
flex-shrink: 0;
}
&:hover {
color: var(--primary);
background: color-mix(in srgb, var(--primary) 10%, transparent);
}
&.compact {
width: 24px;
height: 24px;
padding: 0;
justify-content: center;
border-radius: 50%;
color: var(--primary);
background: transparent;
transform: none;
svg {
width: 14px;
height: 14px;
}
}
}
.message-wrapper-with-selection:hover .message-insight-trigger,
.message-insight-trigger:focus-visible {
opacity: 0.78;
}
.message-wrapper-with-selection:hover .message-insight-trigger.compact,
.message-insight-trigger.compact:focus-visible {
opacity: 0.72;
}
.message-insight-trigger.compact:hover {
opacity: 1;
background: color-mix(in srgb, var(--primary) 10%, transparent);
}
.message-insight-trigger:focus-visible {
outline: 2px solid color-mix(in srgb, var(--primary) 42%, transparent);
outline-offset: 2px;
}
.message-insight-backdrop {
position: fixed;
inset: 0;
z-index: 4100;
border: 0;
background: transparent;
cursor: default;
}
.message-insight-card {
position: fixed;
z-index: 4101;
width: min(336px, calc(100vw - 16px));
border: 1px solid var(--border-color);
border-radius: 8px;
background: var(--bg-secondary);
color: var(--text-primary);
box-shadow: 0 16px 42px rgba(0, 0, 0, 0.18);
overflow: hidden;
animation: messageInsightPop 0.14s ease-out;
-webkit-app-region: no-drag;
}
.message-insight-card-header {
height: 38px;
padding: 0 10px 0 12px;
display: flex;
align-items: center;
gap: 7px;
border-bottom: 1px solid var(--border-color);
background: var(--bg-tertiary);
font-size: 13px;
font-weight: 700;
svg {
color: var(--primary);
}
}
.message-insight-refresh {
margin-left: auto;
width: 26px;
height: 26px;
border: 0;
border-radius: 6px;
background: transparent;
color: var(--text-secondary);
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
&:hover:not(:disabled) {
color: var(--primary);
background: color-mix(in srgb, var(--primary) 10%, transparent);
}
&:disabled {
cursor: default;
opacity: 0.62;
}
}
.message-insight-card-body {
min-height: 132px;
padding: 13px 14px 14px;
}
.message-insight-loading,
.message-insight-error {
min-height: 104px;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
color: var(--text-secondary);
font-size: 13px;
}
.message-insight-error {
flex-direction: column;
text-align: center;
button {
border: 1px solid var(--border-color);
border-radius: 6px;
background: var(--bg-primary);
color: var(--primary);
padding: 5px 10px;
cursor: pointer;
}
}
.message-insight-text {
margin: 0;
color: var(--text-primary);
font-size: 14px;
line-height: 1.62;
white-space: pre-wrap;
word-break: break-word;
}
.message-insight-divider {
height: 1px;
margin: 12px 0;
background: var(--border-color);
}
.message-insight-tags {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.message-insight-tag {
max-width: 100%;
border-radius: 6px;
background: var(--bg-tertiary);
color: var(--text-secondary);
padding: 4px 7px;
font-size: 12px;
line-height: 1.3;
word-break: break-word;
&.mood {
color: #8a5a00;
background: rgba(245, 158, 11, 0.13);
}
&.intent {
color: #225f5c;
background: rgba(91, 147, 144, 0.14);
}
}
.spin {
animation: spin 1s linear infinite;
}
@keyframes messageInsightPop {
from {
opacity: 0;
transform: translateY(4px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
// Ambient Reply dark mode / alternate adjustments handled via CSS variables
.link-message,

File diff suppressed because it is too large Load Diff

View File

@@ -1177,10 +1177,18 @@
}
.export-defaults-modal-actions {
padding: 0 18px 16px;
padding: 12px 18px 16px;
border-top: 1px solid color-mix(in srgb, var(--border-color) 64%, transparent);
background: var(--bg-primary);
}
.export-defaults-close-action {
min-width: 96px;
min-height: 38px;
justify-content: center;
border-radius: 8px;
}
.task-center-card-label {
line-height: 1;
white-space: nowrap;
@@ -5753,7 +5761,8 @@
line-height: 1.6;
}
.close-icon-btn {
.automation-modal .close-icon-btn,
.automation-editor-modal .close-icon-btn {
border: none;
background: color-mix(in srgb, var(--text-tertiary) 8%, transparent);
color: var(--text-secondary);

View File

@@ -4364,7 +4364,7 @@ function ExportPage() {
try {
if (prioritizedSessionIds.length > 0) {
patchSessionLoadTraceStage(prioritizedSessionIds, 'messageCount', 'loading')
const priorityResult = await window.electronAPI.chat.getSessionMessageCounts(prioritizedSessionIds)
const priorityResult = await window.electronAPI.chat.getSessionMessageCounts(prioritizedSessionIds, { bypassSessionCache: true, preferHintCache: false })
if (isStale()) return { ...accumulatedCounts }
if (priorityResult.success) {
applyCounts(priorityResult.counts)
@@ -4381,7 +4381,7 @@ function ExportPage() {
if (remainingSessionIds.length > 0) {
patchSessionLoadTraceStage(remainingSessionIds, 'messageCount', 'loading')
const remainingResult = await window.electronAPI.chat.getSessionMessageCounts(remainingSessionIds)
const remainingResult = await window.electronAPI.chat.getSessionMessageCounts(remainingSessionIds, { bypassSessionCache: true, preferHintCache: false })
if (isStale()) return { ...accumulatedCounts }
if (remainingResult.success) {
applyCounts(remainingResult.counts)
@@ -7613,12 +7613,29 @@ function ExportPage() {
scheduleSessionMutualFriendsWorker()
}
// 记录刷新前的会话时间戳
const oldTimestamps = new Map(
sessionsRef.current.map(s => [s.username, s.lastTimestamp || s.sortTimestamp || 0])
)
await Promise.all([
loadContactsList({ scopeKey }),
loadSnsStats({ full: true }),
loadSnsUserPostCounts({ force: true })
])
// 找出有变动的会话(最后消息时间变化)
const changedSessions = sessionsRef.current.filter(session => {
const oldTs = oldTimestamps.get(session.username) || 0
const newTs = session.lastTimestamp || session.sortTimestamp || 0
return newTs > oldTs
})
// 只对有变动的会话重新加载消息数量
if (changedSessions.length > 0) {
await loadSessionMessageCounts(changedSessions, activeTabRef.current, { scopeKey })
}
const currentDetailSessionId = showSessionDetailPanel
? String(sessionDetail?.wxid || '').trim()
: ''
@@ -9250,7 +9267,7 @@ function ExportPage() {
<div className="export-defaults-modal-actions">
<button
type="button"
className="secondary-btn"
className="secondary-btn export-defaults-close-action"
onClick={() => setIsExportDefaultsModalOpen(false)}
>

View File

@@ -265,6 +265,25 @@
color: #5b55a0;
background: rgba(99, 102, 241, 0.12);
}
&.manual {
color: #0f766e;
background: rgba(20, 184, 166, 0.13);
}
}
.insight-source-pill {
padding: 5px 8px;
border-radius: 999px;
background: rgba(91, 147, 144, 0.1);
color: var(--primary);
font-size: 12px;
white-space: nowrap;
&.message_analysis {
background: rgba(245, 158, 11, 0.13);
color: #8a5a00;
}
}
.insight-time {
@@ -282,6 +301,43 @@
word-break: break-word;
}
.message-analysis-target {
display: flex;
align-items: flex-start;
gap: 8px;
padding: 8px 10px;
border-radius: 8px;
background: var(--bg-tertiary);
color: var(--text-secondary);
font-size: 13px;
line-height: 1.45;
}
.message-analysis-target-label {
flex: 0 0 auto;
color: var(--text-tertiary);
font-weight: 700;
}
.message-analysis-target-text {
min-width: 0;
word-break: break-word;
}
.message-analysis-tags {
display: flex;
flex-wrap: wrap;
gap: 7px;
span {
border-radius: 6px;
background: var(--bg-tertiary);
color: var(--text-secondary);
padding: 4px 7px;
font-size: 12px;
}
}
.insight-filter-panel {
width: var(--insight-panel-width);
flex-shrink: 0;
@@ -376,6 +432,28 @@
}
}
.insight-source-tabs {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
button {
min-height: 34px;
border: 1px solid var(--border-color);
border-radius: 8px;
background: var(--bg-primary);
color: var(--text-secondary);
cursor: pointer;
font-size: 13px;
&.active {
border-color: var(--primary);
color: var(--primary);
background: rgba(91, 147, 144, 0.08);
}
}
}
.insight-custom-dates {
display: grid;
grid-template-columns: 1fr;

View File

@@ -7,6 +7,7 @@ import type {
InsightRecordContactFacet,
InsightRecordFilters,
InsightRecordListResult,
InsightRecordSourceType,
InsightRecordSummary,
InsightRecordTriggerReason
} from '../types/electron'
@@ -15,6 +16,7 @@ import './InsightInboxPage.scss'
const INSIGHT_AVATAR_URL = './assets/insight/AI_Insight.png'
type DateFilterMode = 'all' | 'today' | 'week' | 'custom'
type SourceFilterMode = InsightRecordSourceType | 'all'
function getStartOfDay(date: Date): number {
const next = new Date(date)
@@ -62,16 +64,23 @@ function formatGroupDate(timestamp: number): string {
}
function getTriggerLabel(reason: InsightRecordTriggerReason): string {
if (reason === 'message_analysis') return '深度解析'
if (reason === 'silence') return '沉默提醒'
if (reason === 'test') return '测试见解'
if (reason === 'manual') return '手动触发'
return '活跃分析'
}
function getSourceLabel(sourceType?: InsightRecordSourceType): string {
return sourceType === 'message_analysis' ? '深度解析' : 'AI 见解'
}
function buildLogText(record: InsightRecord): string {
const log = record.log
return [
const lines = [
`时间:${new Date(record.createdAt).toLocaleString('zh-CN')}`,
`联系人:${record.displayName} (${record.sessionId})`,
`来源:${getSourceLabel(record.sourceType)}`,
`触发类型:${getTriggerLabel(record.triggerReason)}`,
`接口地址:${log.endpoint}`,
`模型:${log.model}`,
@@ -90,7 +99,23 @@ function buildLogText(record: InsightRecord): string {
'',
'最终见解:',
log.finalInsight
].join('\n')
]
if (record.sourceType === 'message_analysis') {
lines.splice(8, 0,
`JSON Mode${log.responseFormatJson ? '启用' : '未启用'}`,
`JSON Mode 降级:${log.responseFormatFallback ? '是' : '否'}`,
`降级原因:${log.responseFormatFallbackReason || '无'}`,
`上下文:请求 ${log.contextStats?.requested ?? log.contextCount} 条,前 ${log.contextStats?.beforeTarget ?? 0} 条,后 ${log.contextStats?.afterTarget ?? 0}`,
`上下文读取异常:${log.contextStats?.readError || '无'}`
)
lines.splice(4, 0,
`目标消息:${record.messageInsight?.targetSenderName || log.targetMessage?.senderName || ''}${record.messageInsight?.targetTextPreview || log.targetMessage?.textPreview || ''}`,
`目标定位localId=${record.messageInsight?.targetLocalId || log.targetMessage?.localId || 0}, createTime=${record.messageInsight?.targetCreateTime || log.targetMessage?.createTime || 0}, key=${record.messageInsight?.targetMessageKey || log.targetMessage?.messageKey || ''}`
)
}
return lines.join('\n')
}
export default function InsightInboxPage() {
@@ -101,6 +126,7 @@ export default function InsightInboxPage() {
const [keyword, setKeyword] = useState('')
const [contactSearch, setContactSearch] = useState('')
const [selectedSessionId, setSelectedSessionId] = useState('')
const [sourceType, setSourceType] = useState<SourceFilterMode>('all')
const [dateMode, setDateMode] = useState<DateFilterMode>('all')
const [customStart, setCustomStart] = useState(formatDateInput(new Date()))
const [customEnd, setCustomEnd] = useState(formatDateInput(new Date()))
@@ -133,11 +159,12 @@ export default function InsightInboxPage() {
const filters = useMemo<InsightRecordFilters>(() => ({
keyword: keyword.trim() || undefined,
sessionId: selectedSessionId || undefined,
sourceType,
startTime: dateRange.startTime,
endTime: dateRange.endTime,
limit: 200,
offset: 0
}), [dateRange.endTime, dateRange.startTime, keyword, selectedSessionId])
}), [dateRange.endTime, dateRange.startTime, keyword, selectedSessionId, sourceType])
const loadRecords = useCallback(async () => {
setLoading(true)
@@ -200,6 +227,16 @@ export default function InsightInboxPage() {
}, [contactSearch, contacts])
const openChat = (record: InsightRecordSummary) => {
if (record.sourceType === 'message_analysis' && record.messageInsight) {
const query = new URLSearchParams({
sessionId: record.sessionId,
jumpSource: 'messageAnalysis',
jumpLocalId: String(record.messageInsight.targetLocalId || 0),
jumpCreateTime: String(record.messageInsight.targetCreateTime || 0)
})
navigate(`/chat?${query.toString()}`)
return
}
navigate(`/chat?sessionId=${encodeURIComponent(record.sessionId)}`)
}
@@ -305,6 +342,7 @@ export default function InsightInboxPage() {
</div>
</div>
<div className="insight-card-actions">
<span className={`insight-source-pill ${record.sourceType || 'insight'}`}>{getSourceLabel(record.sourceType)}</span>
<span className={`insight-trigger-pill ${record.triggerReason}`}>{getTriggerLabel(record.triggerReason)}</span>
<span className="insight-time">{formatRecordTime(record.createdAt)}</span>
<button className="insight-action-btn" onClick={() => openChat(record)} title="打开聊天">
@@ -318,7 +356,22 @@ export default function InsightInboxPage() {
</button>
</div>
</div>
{record.sourceType === 'message_analysis' && record.messageInsight && (
<div className="message-analysis-target">
<span className="message-analysis-target-label"></span>
<span className="message-analysis-target-text">
{record.messageInsight.targetSenderName}{record.messageInsight.targetTextPreview}
</span>
</div>
)}
<p className="insight-body">{record.insight}</p>
{record.sourceType === 'message_analysis' && record.messageInsight && (
<div className="message-analysis-tags">
<span>{record.messageInsight.analysis.emotion}</span>
<span>{record.messageInsight.analysis.intent}</span>
<span>{record.messageInsight.analysis.topic}</span>
</div>
)}
</div>
</article>
))}
@@ -347,6 +400,28 @@ export default function InsightInboxPage() {
</div>
</div>
<div className="insight-filter-widget">
<div className="insight-widget-title">
<Sparkles size={14} />
<span></span>
</div>
<div className="insight-source-tabs">
{[
{ value: 'all', label: '全部' },
{ value: 'insight', label: 'AI 见解' },
{ value: 'message_analysis', label: '深度解析' }
].map((option) => (
<button
key={option.value}
className={sourceType === option.value ? 'active' : ''}
onClick={() => setSourceType(option.value as SourceFilterMode)}
>
{option.label}
</button>
))}
</div>
</div>
<div className="insight-filter-widget">
<div className="insight-widget-title">
<CalendarDays size={14} />
@@ -440,9 +515,44 @@ export default function InsightInboxPage() {
`Max Tokens: ${logRecord.log.maxTokens}`,
`Temperature: ${logRecord.log.temperature}`,
`Duration: ${logRecord.log.durationMs}ms`,
`Trigger: ${getTriggerLabel(logRecord.triggerReason)}`
`Source: ${getSourceLabel(logRecord.sourceType)}`,
`Trigger: ${getTriggerLabel(logRecord.triggerReason)}`,
...(logRecord.sourceType === 'message_analysis'
? [
`JSON Mode: ${logRecord.log.responseFormatJson ? 'enabled' : 'disabled'}`,
`JSON Fallback: ${logRecord.log.responseFormatFallback ? 'yes' : 'no'}`,
`Fallback Reason: ${logRecord.log.responseFormatFallbackReason || 'none'}`
]
: [])
].join('\n')}</pre>
</section>
{logRecord.sourceType === 'message_analysis' && (
<section>
<h4></h4>
<pre>{[
`Sender: ${logRecord.messageInsight?.targetSenderName || logRecord.log.targetMessage?.senderName || ''}`,
`Preview: ${logRecord.messageInsight?.targetTextPreview || logRecord.log.targetMessage?.textPreview || ''}`,
`LocalId: ${logRecord.messageInsight?.targetLocalId || logRecord.log.targetMessage?.localId || 0}`,
`CreateTime: ${logRecord.messageInsight?.targetCreateTime || logRecord.log.targetMessage?.createTime || 0}`,
`MessageKey: ${logRecord.messageInsight?.targetMessageKey || logRecord.log.targetMessage?.messageKey || ''}`,
`Context Requested: ${logRecord.log.contextStats?.requested ?? logRecord.log.contextCount}`,
`Context Before: ${logRecord.log.contextStats?.beforeTarget ?? 0}`,
`Context After: ${logRecord.log.contextStats?.afterTarget ?? 0}`,
`Context Error: ${logRecord.log.contextStats?.readError || 'none'}`
].join('\n')}</pre>
</section>
)}
{logRecord.sourceType === 'message_analysis' && logRecord.log.parsedAnalysis && (
<section>
<h4></h4>
<pre>{[
`explicitText: ${logRecord.log.parsedAnalysis.explicitText}`,
`emotion: ${logRecord.log.parsedAnalysis.emotion}`,
`intent: ${logRecord.log.parsedAnalysis.intent}`,
`topic: ${logRecord.log.parsedAnalysis.topic}`
].join('\n')}</pre>
</section>
)}
<section>
<h4>System Prompt</h4>
<pre>{logRecord.log.systemPrompt}</pre>

View File

@@ -770,12 +770,12 @@ function MyFootprintPage() {
<>
<section className="kpi-grid">
<button type="button" className="kpi-card" onClick={() => setTimelineMode('private')}>
<span className="kpi-label"></span>
<span className="kpi-label"></span>
<strong>{data.summary.private_inbound_people}</strong>
<small> {data.summary.private_replied_people} </small>
</button>
<button type="button" className="kpi-card" onClick={() => setTimelineMode('private')}>
<span className="kpi-label"></span>
<span className="kpi-label"></span>
<strong>{data.summary.private_outbound_people}</strong>
<small> {formatPercent(data.summary.private_reply_rate)}</small>
</button>

View File

@@ -6,6 +6,7 @@ import { useThemeStore, themes } from '../stores/themeStore'
import { useAnalyticsStore } from '../stores/analyticsStore'
import { dialog } from '../services/ipc'
import * as configService from '../services/config'
import groupSummaryPrompt from '../../shared/groupSummaryPrompt.json'
import type { ChatSession, ContactInfo } from '../types/models'
import {
Eye, EyeOff, FolderSearch, FolderOpen, Search, Copy,
@@ -32,9 +33,11 @@ type SettingsTab =
| 'aiCommon'
| 'insight'
| 'aiFootprint'
| 'aiGroupSummary'
| 'aiMessageInsight'
| 'autoDownload'
const tabs: { id: Exclude<SettingsTab, 'insight' | 'aiFootprint'>; label: string; icon: React.ElementType }[] = [
const tabs: { id: Exclude<SettingsTab, 'insight' | 'aiFootprint' | 'aiMessageInsight'>; label: string; icon: React.ElementType }[] = [
{ id: 'appearance', label: '外观', icon: Palette },
{ id: 'notification', label: '通知', icon: Bell },
{ id: 'antiRevoke', label: '防撤回', icon: RotateCcw },
@@ -56,16 +59,19 @@ const filteredTabs = tabs.filter(tab => {
return true
})
const aiTabs: Array<{ id: Extract<SettingsTab, 'aiCommon' | 'insight' | 'aiFootprint'>; label: string }> = [
const aiTabs: Array<{ id: Extract<SettingsTab, 'aiCommon' | 'insight' | 'aiFootprint' | 'aiGroupSummary' | 'aiMessageInsight'>; label: string }> = [
{ id: 'aiCommon', label: '基础配置' },
{ id: 'insight', label: 'AI 见解' },
{ id: 'aiFootprint', label: 'AI 足迹' }
{ id: 'aiFootprint', label: 'AI 足迹' },
{ id: 'aiGroupSummary', label: '群聊总结' },
{ id: 'aiMessageInsight', label: '消息解析' }
]
const isMac = navigator.userAgent.toLowerCase().includes('mac')
const isLinux = navigator.userAgent.toLowerCase().includes('linux')
const isWindows = !isMac && !isLinux
const MAC_KEY_FAQ_URL = 'https://github.com/hicccc77/WeFlow/blob/main/docs/MAC-KEY-FAQ.md'
const DEFAULT_GROUP_SUMMARY_SYSTEM_PROMPT = String(groupSummaryPrompt.defaultSystemPrompt || '').trim()
const dbDirName = isMac ? '2.0b4.0.9 目录' : 'xwechat_files 目录'
const dbPathPlaceholder = isMac
@@ -327,6 +333,14 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const [weiboBindingLoadingSessionId, setWeiboBindingLoadingSessionId] = useState<string | null>(null)
const [aiFootprintEnabled, setAiFootprintEnabled] = useState(false)
const [aiFootprintSystemPrompt, setAiFootprintSystemPrompt] = useState('')
const [aiGroupSummaryEnabled, setAiGroupSummaryEnabled] = useState(false)
const [aiGroupSummaryIntervalHours, setAiGroupSummaryIntervalHours] = useState(4)
const [aiGroupSummarySystemPrompt, setAiGroupSummarySystemPrompt] = useState('')
const [aiGroupSummaryFilterList, setAiGroupSummaryFilterList] = useState<string[]>([])
const [aiGroupSummaryFilterSearchKeyword, setAiGroupSummaryFilterSearchKeyword] = useState('')
const [aiMessageInsightEnabled, setAiMessageInsightEnabled] = useState(false)
const [aiMessageInsightContextCount, setAiMessageInsightContextCount] = useState(50)
const [aiMessageInsightSystemPrompt, setAiMessageInsightSystemPrompt] = useState('')
// 自动下载图片
const [autoDownloadStatus, setAutoDownloadStatus] = useState<{ isHooked: boolean; pid: number | null; supported: boolean } | null>(null)
@@ -372,7 +386,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
}, [location.state])
useEffect(() => {
if (activeTab === 'aiCommon' || activeTab === 'insight' || activeTab === 'aiFootprint') {
if (activeTab === 'aiCommon' || activeTab === 'insight' || activeTab === 'aiFootprint' || activeTab === 'aiGroupSummary' || activeTab === 'aiMessageInsight') {
setAiGroupExpanded(true)
}
}, [activeTab])
@@ -590,6 +604,13 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
const savedAiInsightWeiboBindings = await configService.getAiInsightWeiboBindings()
const savedAiFootprintEnabled = await configService.getAiFootprintEnabled()
const savedAiFootprintSystemPrompt = await configService.getAiFootprintSystemPrompt()
const savedAiGroupSummaryEnabled = await configService.getAiGroupSummaryEnabled()
const savedAiGroupSummaryIntervalHours = await configService.getAiGroupSummaryIntervalHours()
const savedAiGroupSummarySystemPrompt = await configService.getAiGroupSummarySystemPrompt()
const savedAiGroupSummaryFilterList = await configService.getAiGroupSummaryFilterList()
const savedAiMessageInsightEnabled = await configService.getAiMessageInsightEnabled()
const savedAiMessageInsightContextCount = await configService.getAiMessageInsightContextCount()
const savedAiMessageInsightSystemPrompt = await configService.getAiMessageInsightSystemPrompt()
setAiInsightEnabled(savedAiInsightEnabled)
setAiModelApiBaseUrl(savedAiModelApiBaseUrl)
@@ -616,6 +637,13 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
setAiInsightWeiboBindings(savedAiInsightWeiboBindings)
setAiFootprintEnabled(savedAiFootprintEnabled)
setAiFootprintSystemPrompt(savedAiFootprintSystemPrompt)
setAiGroupSummaryEnabled(savedAiGroupSummaryEnabled)
setAiGroupSummaryIntervalHours(savedAiGroupSummaryIntervalHours)
setAiGroupSummarySystemPrompt(savedAiGroupSummarySystemPrompt)
setAiGroupSummaryFilterList(savedAiGroupSummaryFilterList)
setAiMessageInsightEnabled(savedAiMessageInsightEnabled)
setAiMessageInsightContextCount(savedAiMessageInsightContextCount)
setAiMessageInsightSystemPrompt(savedAiMessageInsightSystemPrompt)
} catch (e: any) {
console.error('加载配置失败:', e)
@@ -2903,6 +2931,15 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
messagePushFilterSearchKeyword
)
const groupSummaryFilterOptions = sessionFilterOptions.filter((session) => session.type === 'group')
const groupSummaryAvailableSessions = groupSummaryFilterOptions.filter((session) => {
const keyword = aiGroupSummaryFilterSearchKeyword.trim().toLowerCase()
if (aiGroupSummaryFilterList.includes(session.username)) return false
if (!keyword) return true
return String(session.displayName || '').toLowerCase().includes(keyword) ||
session.username.toLowerCase().includes(keyword)
})
const handleAddAllNotificationFilterSessions = async () => {
const usernames = notificationAvailableSessions.map(session => session.username)
if (usernames.length === 0) return
@@ -4021,6 +4058,320 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
</div>
)
const renderAiGroupSummaryTab = () => {
const groupSummaryPromptDisplayValue = aiGroupSummarySystemPrompt || DEFAULT_GROUP_SUMMARY_SYSTEM_PROMPT
const addToFilterList = async (username: string) => {
if (!username.endsWith('@chatroom') || aiGroupSummaryFilterList.includes(username)) return
const next = [...aiGroupSummaryFilterList, username]
setAiGroupSummaryFilterList(next)
await configService.setAiGroupSummaryFilterList(next)
showMessage('已添加到群聊总结作用域', true)
}
const removeFromFilterList = async (username: string) => {
const next = aiGroupSummaryFilterList.filter((item) => item !== username)
setAiGroupSummaryFilterList(next)
await configService.setAiGroupSummaryFilterList(next)
showMessage('已从群聊总结作用域移除', true)
}
const addAllFiltered = async () => {
const usernames = groupSummaryAvailableSessions.map((session) => session.username)
if (usernames.length === 0) return
const next = Array.from(new Set([...aiGroupSummaryFilterList, ...usernames]))
setAiGroupSummaryFilterList(next)
await configService.setAiGroupSummaryFilterList(next)
showMessage(`已添加 ${usernames.length} 个群聊`, true)
}
const clearFilterList = async () => {
if (aiGroupSummaryFilterList.length === 0) return
setAiGroupSummaryFilterList([])
await configService.setAiGroupSummaryFilterList([])
showMessage('已清空群聊总结作用域', true)
}
return (
<div className="tab-content">
<div className="form-group">
<label>AI </label>
<span className="form-hint">
AI token
</span>
<div className="log-toggle-line">
<span className="log-status">{aiGroupSummaryEnabled ? '已开启' : '已关闭'}</span>
<label className="switch">
<input
type="checkbox"
checked={aiGroupSummaryEnabled}
onChange={async (e) => {
const val = e.target.checked
setAiGroupSummaryEnabled(val)
await configService.setAiGroupSummaryEnabled(val)
showMessage(val ? 'AI 群聊总结已开启' : 'AI 群聊总结已关闭', true)
}}
/>
<span className="switch-slider" />
</label>
</div>
</div>
<div className="divider" />
<div className="form-group">
<label></label>
<span className="form-hint">
00:00 5
</span>
<div className="push-filter-type-tabs" style={{ marginTop: 10 }}>
{[1, 2, 4, 8, 12, 24].map((hours) => (
<button
key={hours}
type="button"
className={`push-filter-type-tab ${aiGroupSummaryIntervalHours === hours ? 'active' : ''}`}
onClick={() => {
setAiGroupSummaryIntervalHours(hours)
scheduleConfigSave('aiGroupSummaryIntervalHours', () => configService.setAiGroupSummaryIntervalHours(hours))
}}
>
{hours}
</button>
))}
</div>
</div>
<div className="form-group">
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 12 }}>
<label style={{ marginBottom: 0 }}></label>
<button
type="button"
className="btn btn-secondary btn-sm"
onClick={async () => {
setAiGroupSummarySystemPrompt('')
await configService.setAiGroupSummarySystemPrompt('')
}}
>
</button>
</div>
<span className="form-hint">
使
</span>
<textarea
className="field-input ai-prompt-textarea"
rows={10}
style={{ width: '100%', resize: 'vertical', marginTop: 8 }}
value={groupSummaryPromptDisplayValue}
onChange={(e) => {
const val = e.target.value
setAiGroupSummarySystemPrompt(val)
scheduleConfigSave('aiGroupSummarySystemPrompt', () => configService.setAiGroupSummarySystemPrompt(val))
}}
/>
<span className="form-hint" style={{ color: 'var(--danger, #ef4444)', marginTop: 8, display: 'block' }}>
JSON
</span>
</div>
<div className="divider" />
<div className="form-group">
<label></label>
<span className="form-hint">
AI
</span>
{aiGroupSummaryFilterList.length === 0 && (
<div className="api-docs" style={{ marginTop: 12 }}>
<div className="api-item">
<p className="api-desc"></p>
</div>
</div>
)}
<div className="notification-filter-container" style={{ marginTop: 12 }}>
<div className="filter-panel">
<div className="filter-panel-header">
<span></span>
{groupSummaryAvailableSessions.length > 0 && (
<button type="button" className="filter-panel-action" onClick={() => { void addAllFiltered() }}>
</button>
)}
<div className="filter-search-box">
<Search size={14} />
<input
type="text"
placeholder="搜索群聊..."
value={aiGroupSummaryFilterSearchKeyword}
onChange={(e) => setAiGroupSummaryFilterSearchKeyword(e.target.value)}
/>
</div>
</div>
<div className="filter-panel-list">
{groupSummaryAvailableSessions.length > 0 ? (
groupSummaryAvailableSessions.map(session => (
<div
key={session.username}
className="filter-panel-item"
onClick={() => { void addToFilterList(session.username) }}
>
<Avatar src={session.avatarUrl} name={session.displayName || session.username} size={28} />
<span className="filter-item-name">{session.displayName || session.username}</span>
<span className="filter-item-type"></span>
<span className="filter-item-action">+</span>
</div>
))
) : (
<div className="filter-panel-empty">
{aiGroupSummaryFilterSearchKeyword ? '没有匹配的群聊' : '暂无可添加的群聊'}
</div>
)}
</div>
</div>
<div className="filter-panel">
<div className="filter-panel-header">
<span></span>
{aiGroupSummaryFilterList.length > 0 && (
<span className="filter-panel-count">{aiGroupSummaryFilterList.length}</span>
)}
{aiGroupSummaryFilterList.length > 0 && (
<button type="button" className="filter-panel-action" onClick={() => { void clearFilterList() }}>
</button>
)}
</div>
<div className="filter-panel-list">
{aiGroupSummaryFilterList.length > 0 ? (
aiGroupSummaryFilterList.map(username => {
const info = getSessionFilterOptionInfo(username)
return (
<div
key={username}
className="filter-panel-item selected"
onClick={() => { void removeFromFilterList(username) }}
>
<Avatar src={info.avatarUrl} name={info.displayName} size={28} />
<span className="filter-item-name">{info.displayName}</span>
<span className="filter-item-type"></span>
<span className="filter-item-action">×</span>
</div>
)
})
) : (
<div className="filter-panel-empty"></div>
)}
</div>
</div>
</div>
</div>
</div>
)
}
const renderAiMessageInsightTab = () => (
<div className="tab-content">
{(() => {
const DEFAULT_MESSAGE_INSIGHT_PROMPT = `你是一个克制、准确的聊天语义分析助手。你的任务是把用户选中的一句聊天消息做深度解析,帮助用户理解对方未明说的含义。
严格要求:
1. 必须且只能输出合法的纯 JSON。
2. 禁止输出解释说明、前言后语,禁止使用 Markdown 或代码块。
3. 不要编造上下文没有支持的信息;不确定时用谨慎表述。
4. explicit_text 用自然中文说明这句话可能想表达的真实含义80字以内。
5. emotion、intent、topic 必须是短标签。
JSON 输出格式:
{
"explicit_text": "暗示转明示80字以内",
"emotion": "2-6字情绪标签",
"intent": "2-8字意图标签",
"topic": "2-8字话题标签"
}`
const displayValue = aiMessageInsightSystemPrompt || DEFAULT_MESSAGE_INSIGHT_PROMPT
return (
<>
<div className="form-group">
<label></label>
<span className="form-hint">
AI
</span>
<div className="log-toggle-line">
<span className="log-status">{aiMessageInsightEnabled ? '已开启' : '已关闭'}</span>
<label className="switch">
<input
type="checkbox"
checked={aiMessageInsightEnabled}
onChange={async (e) => {
const val = e.target.checked
setAiMessageInsightEnabled(val)
await configService.setAiMessageInsightEnabled(val)
}}
/>
<span className="switch-slider" />
</label>
</div>
</div>
<div className="form-group">
<label></label>
<span className="form-hint">
token
</span>
<input
type="number"
className="field-input"
value={aiMessageInsightContextCount}
min={1}
max={200}
onChange={(e) => {
const val = Math.max(1, Math.min(200, parseInt(e.target.value, 10) || 50))
setAiMessageInsightContextCount(val)
scheduleConfigSave('aiMessageInsightContextCount', () => configService.setAiMessageInsightContextCount(val))
}}
style={{ width: 100 }}
/>
</div>
<div className="form-group">
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 6 }}>
<label style={{ marginBottom: 0 }}></label>
<button
className="btn btn-secondary btn-sm"
onClick={async () => {
setAiMessageInsightSystemPrompt('')
await configService.setAiMessageInsightSystemPrompt('')
}}
>
</button>
</div>
<span className="form-hint">
使
</span>
<textarea
className="field-input ai-prompt-textarea"
rows={10}
style={{ width: '100%', resize: 'vertical' }}
value={displayValue}
onChange={(e) => {
const val = e.target.value
setAiMessageInsightSystemPrompt(val)
scheduleConfigSave('aiMessageInsightSystemPrompt', () => configService.setAiMessageInsightSystemPrompt(val))
}}
/>
<span className="form-hint" style={{ color: 'var(--danger, #ef4444)', marginTop: 8, display: 'block' }}>
JSON
</span>
</div>
</>
)
})()}
</div>
)
const renderApiTab = () => (
<div className="tab-content">
<div className="form-group">
@@ -5049,7 +5400,7 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
row.push(
<div key="ai-settings-group" className={`tab-group ${aiGroupExpanded ? 'expanded' : ''}`}>
<button
className={`tab-btn tab-group-trigger ${(activeTab === 'aiCommon' || activeTab === 'insight' || activeTab === 'aiFootprint') ? 'active' : ''}`}
className={`tab-btn tab-group-trigger ${(activeTab === 'aiCommon' || activeTab === 'insight' || activeTab === 'aiFootprint' || activeTab === 'aiGroupSummary' || activeTab === 'aiMessageInsight') ? 'active' : ''}`}
onClick={() => setAiGroupExpanded((prev) => !prev)}
aria-expanded={aiGroupExpanded}
>
@@ -5091,6 +5442,8 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
{activeTab === 'aiCommon' && renderAiCommonTab()}
{activeTab === 'insight' && renderInsightTab()}
{activeTab === 'aiFootprint' && renderAiFootprintTab()}
{activeTab === 'aiGroupSummary' && renderAiGroupSummaryTab()}
{activeTab === 'aiMessageInsight' && renderAiMessageInsightTab()}
{activeTab === 'autoDownload' && renderAutoDownloadTab()}
{activeTab === 'updates' && renderUpdatesTab()}
{activeTab === 'analytics' && renderAnalyticsTab()}

View File

@@ -120,6 +120,14 @@ export const CONFIG_KEYS = {
// AI 足迹
AI_FOOTPRINT_ENABLED: 'aiFootprintEnabled',
AI_FOOTPRINT_SYSTEM_PROMPT: 'aiFootprintSystemPrompt',
AI_GROUP_SUMMARY_ENABLED: 'aiGroupSummaryEnabled',
AI_GROUP_SUMMARY_INTERVAL_HOURS: 'aiGroupSummaryIntervalHours',
AI_GROUP_SUMMARY_SYSTEM_PROMPT: 'aiGroupSummarySystemPrompt',
AI_GROUP_SUMMARY_FILTER_MODE: 'aiGroupSummaryFilterMode',
AI_GROUP_SUMMARY_FILTER_LIST: 'aiGroupSummaryFilterList',
AI_MESSAGE_INSIGHT_ENABLED: 'aiMessageInsightEnabled',
AI_MESSAGE_INSIGHT_CONTEXT_COUNT: 'aiMessageInsightContextCount',
AI_MESSAGE_INSIGHT_SYSTEM_PROMPT: 'aiMessageInsightSystemPrompt',
AI_INSIGHT_DEBUG_LOG_ENABLED: 'aiInsightDebugLogEnabled',
AUTO_DOWNLOAD_HIGH_RES: 'autoDownloadHighRes',
AUTO_DOWNLOAD_WHITELIST: 'autoDownloadWhitelist'
@@ -2175,6 +2183,97 @@ export async function setAiFootprintSystemPrompt(prompt: string): Promise<void>
await config.set(CONFIG_KEYS.AI_FOOTPRINT_SYSTEM_PROMPT, prompt)
}
// Legacy only: 群聊总结现在只使用 aiGroupSummaryFilterList 作为作用域白名单。
export type AiGroupSummaryFilterMode = 'whitelist' | 'blacklist'
const AI_GROUP_SUMMARY_INTERVALS = new Set([1, 2, 4, 8, 12, 24])
const normalizeAiGroupSummaryFilterList = (value: unknown): string[] => {
if (!Array.isArray(value)) return []
return Array.from(new Set(
value
.map((item) => String(item || '').trim())
.filter((item) => item.endsWith('@chatroom'))
))
}
export async function getAiGroupSummaryEnabled(): Promise<boolean> {
const value = await config.get(CONFIG_KEYS.AI_GROUP_SUMMARY_ENABLED)
return value === true
}
export async function setAiGroupSummaryEnabled(enabled: boolean): Promise<void> {
await config.set(CONFIG_KEYS.AI_GROUP_SUMMARY_ENABLED, enabled)
}
export async function getAiGroupSummaryIntervalHours(): Promise<number> {
const value = Number(await config.get(CONFIG_KEYS.AI_GROUP_SUMMARY_INTERVAL_HOURS))
const normalized = Number.isFinite(value) ? Math.floor(value) : 4
return AI_GROUP_SUMMARY_INTERVALS.has(normalized) ? normalized : 4
}
export async function setAiGroupSummaryIntervalHours(hours: number): Promise<void> {
const normalized = Math.floor(Number(hours) || 4)
await config.set(CONFIG_KEYS.AI_GROUP_SUMMARY_INTERVAL_HOURS, AI_GROUP_SUMMARY_INTERVALS.has(normalized) ? normalized : 4)
}
export async function getAiGroupSummarySystemPrompt(): Promise<string> {
const value = await config.get(CONFIG_KEYS.AI_GROUP_SUMMARY_SYSTEM_PROMPT)
return typeof value === 'string' ? value : ''
}
export async function setAiGroupSummarySystemPrompt(prompt: string): Promise<void> {
await config.set(CONFIG_KEYS.AI_GROUP_SUMMARY_SYSTEM_PROMPT, prompt)
}
export async function getAiGroupSummaryFilterMode(): Promise<AiGroupSummaryFilterMode> {
const value = await config.get(CONFIG_KEYS.AI_GROUP_SUMMARY_FILTER_MODE)
return value === 'blacklist' ? 'blacklist' : 'whitelist'
}
export async function setAiGroupSummaryFilterMode(mode: AiGroupSummaryFilterMode): Promise<void> {
await config.set(CONFIG_KEYS.AI_GROUP_SUMMARY_FILTER_MODE, mode === 'blacklist' ? 'blacklist' : 'whitelist')
}
export async function getAiGroupSummaryFilterList(): Promise<string[]> {
const value = await config.get(CONFIG_KEYS.AI_GROUP_SUMMARY_FILTER_LIST)
return normalizeAiGroupSummaryFilterList(value)
}
export async function setAiGroupSummaryFilterList(list: string[]): Promise<void> {
await config.set(CONFIG_KEYS.AI_GROUP_SUMMARY_FILTER_LIST, normalizeAiGroupSummaryFilterList(list))
}
export async function getAiMessageInsightEnabled(): Promise<boolean> {
const value = await config.get(CONFIG_KEYS.AI_MESSAGE_INSIGHT_ENABLED)
return value === true
}
export async function setAiMessageInsightEnabled(enabled: boolean): Promise<void> {
await config.set(CONFIG_KEYS.AI_MESSAGE_INSIGHT_ENABLED, enabled)
}
export async function getAiMessageInsightContextCount(): Promise<number> {
const value = await config.get(CONFIG_KEYS.AI_MESSAGE_INSIGHT_CONTEXT_COUNT)
const numeric = Number(value)
if (!Number.isFinite(numeric)) return 50
return Math.max(1, Math.min(200, Math.floor(numeric)))
}
export async function setAiMessageInsightContextCount(count: number): Promise<void> {
const normalized = Number.isFinite(count) ? Math.max(1, Math.min(200, Math.floor(count))) : 50
await config.set(CONFIG_KEYS.AI_MESSAGE_INSIGHT_CONTEXT_COUNT, normalized)
}
export async function getAiMessageInsightSystemPrompt(): Promise<string> {
const value = await config.get(CONFIG_KEYS.AI_MESSAGE_INSIGHT_SYSTEM_PROMPT)
return typeof value === 'string' ? value : ''
}
export async function setAiMessageInsightSystemPrompt(prompt: string): Promise<void> {
await config.set(CONFIG_KEYS.AI_MESSAGE_INSIGHT_SYSTEM_PROMPT, prompt)
}
export async function getAiInsightDebugLogEnabled(): Promise<boolean> {
const value = await config.get(CONFIG_KEYS.AI_INSIGHT_DEBUG_LOG_ENABLED)
return value === true

View File

@@ -21,7 +21,24 @@ export interface SocialSaveWeiboCookieResult {
error?: string
}
export type InsightRecordTriggerReason = 'activity' | 'silence' | 'test'
export type InsightRecordTriggerReason = 'activity' | 'silence' | 'test' | 'manual' | 'message_analysis'
export type InsightRecordSourceType = 'insight' | 'message_analysis'
export interface MessageInsightAnalysis {
explicitText: string
emotion: string
intent: string
topic: string
}
export interface MessageInsightTarget {
targetLocalId: number
targetCreateTime: number
targetMessageKey: string
targetSenderName: string
targetTextPreview: string
analysis: MessageInsightAnalysis
}
export interface InsightRecordLog {
endpoint: string
@@ -37,10 +54,28 @@ export interface InsightRecordLog {
finalInsight: string
durationMs: number
createdAt: number
responseFormatJson?: boolean
responseFormatFallback?: boolean
responseFormatFallbackReason?: string
targetMessage?: {
localId: number
createTime: number
messageKey: string
senderName: string
textPreview: string
}
contextStats?: {
requested: number
beforeTarget: number
afterTarget: number
readError?: string
}
parsedAnalysis?: MessageInsightAnalysis
}
export interface InsightRecordSummary {
id: string
sourceType: InsightRecordSourceType
createdAt: number
sessionId: string
displayName: string
@@ -48,6 +83,7 @@ export interface InsightRecordSummary {
triggerReason: InsightRecordTriggerReason
insight: string
read: boolean
messageInsight?: MessageInsightTarget
}
export interface InsightRecord extends InsightRecordSummary {
@@ -67,6 +103,7 @@ export interface InsightRecordFilters {
sessionId?: string
startTime?: number
endTime?: number
sourceType?: InsightRecordSourceType | 'all'
limit?: number
offset?: number
}
@@ -87,6 +124,78 @@ export interface InsightRecordResult {
error?: string
}
export type GroupSummaryTriggerType = 'auto' | 'manual'
export interface GroupSummaryTopic {
title: string
participants: string[]
keyPoints: string[]
conclusion: string
}
export interface GroupSummaryLog {
endpoint: string
model: string
temperature: number
triggerType: GroupSummaryTriggerType
periodStart: number
periodEnd: number
messageCount: number
readableMessageCount: number
systemPrompt: string
userPrompt: string
rawOutput: string
finalSummary: string
durationMs: number
createdAt: number
responseFormatJson?: boolean
responseFormatFallback?: boolean
responseFormatFallbackReason?: string
parsedTopics?: GroupSummaryTopic[]
}
export interface GroupSummaryRecordSummary {
id: string
createdAt: number
sessionId: string
displayName: string
avatarUrl?: string
triggerType: GroupSummaryTriggerType
periodStart: number
periodEnd: number
messageCount: number
readableMessageCount: number
topics: GroupSummaryTopic[]
summaryText: string
}
export interface GroupSummaryRecord extends GroupSummaryRecordSummary {
accountScope: string
rawOutput: string
log: GroupSummaryLog
}
export interface GroupSummaryRecordFilters {
sessionId?: string
startTime?: number
endTime?: number
limit?: number
offset?: number
}
export interface GroupSummaryRecordListResult {
success: boolean
records: GroupSummaryRecordSummary[]
total: number
error?: string
}
export interface GroupSummaryRecordResult {
success: boolean
record?: GroupSummaryRecord
error?: string
}
export interface BackupProgress {
phase: 'preparing' | 'scanning' | 'exporting' | 'packing' | 'inspecting' | 'restoring' | 'done' | 'failed'
message: string
@@ -365,7 +474,7 @@ export interface ElectronAPI {
}
error?: string
}>
getSessionMessageCounts: (sessionIds: string[]) => Promise<{
getSessionMessageCounts: (sessionIds: string[], options?: { preferHintCache?: boolean; bypassSessionCache?: boolean }) => Promise<{
success: boolean
counts?: Record<string, number>
error?: string
@@ -1307,6 +1416,11 @@ export interface ElectronAPI {
markRecordRead: (id: string) => Promise<{ success: boolean; error?: string }>
clearRecords: (filters?: InsightRecordFilters) => Promise<{ success: boolean; removed: number; error?: string }>
triggerTest: () => Promise<{ success: boolean; message: string }>
triggerSessionInsight: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
}) => Promise<{ success: boolean; message: string; recordId?: string; insight?: string; skipped?: boolean; notificationEnabled?: boolean }>
generateFootprintInsight: (payload: {
rangeLabel: string
summary: {
@@ -1320,6 +1434,35 @@ export interface ElectronAPI {
privateSegments?: Array<{ displayName?: string; session_id?: string; incoming_count?: number; outgoing_count?: number; message_count?: number; replied?: boolean }>
mentionGroups?: Array<{ displayName?: string; session_id?: string; count?: number }>
}) => Promise<{ success: boolean; message: string; insight?: string }>
generateMessageInsight: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
targetLocalId?: number
targetCreateTime?: number
targetMessageKey?: string
targetText: string
targetSenderName?: string
contextCount?: number
forceRefresh?: boolean
}) => Promise<{ success: boolean; message: string; cached?: boolean; recordId?: string; data?: MessageInsightAnalysis }>
}
groupSummary: {
listRecords: (filters?: GroupSummaryRecordFilters) => Promise<GroupSummaryRecordListResult>
getRecord: (id: string) => Promise<GroupSummaryRecordResult>
triggerManual: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
startTime: number
endTime: number
}) => Promise<{ success: boolean; message: string; recordId?: string; record?: GroupSummaryRecordSummary; skipped?: boolean; skippedReason?: string }>
triggerDay: (payload: {
sessionId: string
displayName?: string
avatarUrl?: string
date: string
}) => Promise<{ success: boolean; message: string; generated: number; skipped: number; records: GroupSummaryRecordSummary[] }>
}
}

View File

@@ -19,6 +19,6 @@
"@/*": ["./src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts"],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "shared/**/*.json"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@@ -4,6 +4,7 @@
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"target": "ES2022",
@@ -14,6 +15,7 @@
"include": [
"vite.config.ts",
"electron/**/*.ts",
"electron/**/*.d.ts"
"electron/**/*.d.ts",
"shared/**/*.json"
]
}