dsh-qq-affinity 1.0.0 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -20,7 +20,7 @@ window.__ModuleLoader__.load({
20
20
  * This bundle's version. The Host reports its own; when the two differ the
21
21
  * panel says so, because a stale bundle otherwise looks like a broken button.
22
22
  */
23
- const VERSION = '0.15.3'
23
+ const VERSION = '1.5.5'
24
24
 
25
25
  // ---------------------------------------------------------------- palette
26
26
 
@@ -92,6 +92,15 @@ window.__ModuleLoader__.load({
92
92
  ]
93
93
  const traitColor = (index) => (supportsColorMix ? TRAIT_COLORS[index % TRAIT_COLORS.length]() : C.brand)
94
94
 
95
+ /** "正在分析" 已经跑了多久: 12 秒 / 3 分 5 秒 / 1 小时 2 分. */
96
+ function formatElapsed(ms) {
97
+ const total = Math.max(0, Math.round(Number(ms) / 1000))
98
+ if (total < 60) return `${total} 秒`
99
+ const minutes = Math.floor(total / 60)
100
+ if (minutes < 60) return `${minutes} 分 ${total % 60} 秒`
101
+ return `${Math.floor(minutes / 60)} 小时 ${minutes % 60} 分`
102
+ }
103
+
95
104
  /** "完整 / 增量(+12 条)": how one stored analysis was produced. */
96
105
  function analysisMode(entry) {
97
106
  const based = entry?.basedOn ?? {}
@@ -1209,7 +1218,18 @@ window.__ModuleLoader__.load({
1209
1218
  }, [
1210
1219
  h('div', { key: 'top', style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } }, [
1211
1220
  h(Chip, { key: 's', color: OUTBOX_COLOR(row.status) }, OUTBOX_LABEL[row.status] ?? row.status),
1221
+ row.kind === 'excuse' ? h(Chip, { key: 'k', color: C.warn }, '推辞(到上限)') : null,
1222
+ row.personaId === undefined || row.personaId === '' ? null : h(Chip, {
1223
+ key: 'p',
1224
+ color: row.personaId === 'default' ? C.idle : C.brand,
1225
+ title: row.personaId === 'default' ? '用你自己的口吻写的' : `用「${row.personaName || row.personaId}」这个人设写的`,
1226
+ }, row.personaId === 'default' ? '默认人设' : (row.personaName || row.personaId)),
1212
1227
  h('span', { key: 't', style: { fontSize: 10.5, color: C.label2, fontVariantNumeric: 'tabular-nums' } }, fmtTime(row.createdAt)),
1228
+ row.promptChars > 0 ? h('span', {
1229
+ key: 'size',
1230
+ title: '这次请求发给模型的字数(上限 6000 字,单条消息最多 500 字);越大越费 token',
1231
+ style: { fontSize: 10.5, color: C.label2, fontVariantNumeric: 'tabular-nums' },
1232
+ }, `输入 ${row.promptChars} 字`) : null,
1213
1233
  nameOf === undefined ? null : h('span', {
1214
1234
  key: 'to',
1215
1235
  style: { fontSize: 10.5, color: C.label2 },
@@ -1251,13 +1271,18 @@ window.__ModuleLoader__.load({
1251
1271
  }
1252
1272
 
1253
1273
  /** Per-person automatic reply settings. */
1254
- function CarePanel({ person, channel, careEnabled, busy, usage, onChange }) {
1274
+ function CarePanel({ person, channel, careEnabled, busy, usage, personas, onChange, onAddPersona, onDeletePersona, onResetCount }) {
1255
1275
  const care = person.care
1256
1276
  const [cap, setCap] = useState(String(care.hourlyCap))
1257
1277
  const [chars, setChars] = useState(String(care.maxReplyChars))
1258
1278
  const [quietFrom, setQuietFrom] = useState(care.quietFrom)
1259
1279
  const [quietTo, setQuietTo] = useState(care.quietTo)
1280
+ const [delay, setDelay] = useState(String(care.replyDelaySeconds ?? 5))
1260
1281
  const [clockError, setClockError] = useState('')
1282
+ // The "+ 新人设" form: name + description, saved through the open interface.
1283
+ const [personaForm, setPersonaForm] = useState(false)
1284
+ const [draftName, setDraftName] = useState('')
1285
+ const [draftPrompt, setDraftPrompt] = useState('')
1261
1286
 
1262
1287
  const channelReady = channel !== undefined && channel.available === true && channel.enabled === true
1263
1288
  const commitNumber = (field, value, min, max, reset) => {
@@ -1317,6 +1342,78 @@ window.__ModuleLoader__.load({
1317
1342
  style: { fontSize: 11, color: C.label2, lineHeight: 1.6 },
1318
1343
  }, '注意:托管总开关现在是关的,这里打开也不会生效。到「设置」里打开总开关。') : null,
1319
1344
 
1345
+ (() => {
1346
+ const list = Array.isArray(personas) ? personas : []
1347
+ const currentId = care.persona ?? 'default'
1348
+ const current = list.find(entry => entry.id === currentId) ?? list[0]
1349
+ return h('div', { key: 'persona', style: { display: 'flex', flexDirection: 'column', gap: 6 } }, [
1350
+ h('div', { key: 'row', style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } }, [
1351
+ h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2 } }, '说话人设'),
1352
+ h('select', {
1353
+ key: 'sel',
1354
+ 'aria-label': '回复人设',
1355
+ // A persona that no longer exists must not leave the select blank.
1356
+ value: current === undefined ? 'default' : current.id,
1357
+ disabled: busy,
1358
+ onChange: (event) => onChange({ persona: event.target.value }),
1359
+ style: { ...inputStyle, width: 'auto', minWidth: 190, cursor: 'pointer' },
1360
+ }, list.map(entry => h('option', { key: entry.id, value: entry.id }, entry.name))),
1361
+ h(Btn, {
1362
+ key: 'new',
1363
+ kind: 'quiet',
1364
+ style: { padding: '2px 8px', fontSize: 11 },
1365
+ onClick: () => setPersonaForm(open => !open),
1366
+ }, personaForm ? '取消' : '+ 新人设'),
1367
+ current !== undefined && current.custom === true && typeof onDeletePersona === 'function' ? h(Btn, {
1368
+ key: 'del',
1369
+ kind: 'quiet',
1370
+ disabled: busy,
1371
+ style: { padding: '2px 8px', fontSize: 11, color: C.error },
1372
+ title: '删除这个人设;用到它的人会回到默认人设',
1373
+ onClick: () => onDeletePersona(current.id),
1374
+ }, '删除这个人设') : null,
1375
+ ]),
1376
+ current === undefined ? null : h('div', {
1377
+ key: 'about',
1378
+ style: { fontSize: 11, color: C.label2, lineHeight: 1.65 },
1379
+ }, current.summary ?? String(current.prompt ?? '').slice(0, 160)),
1380
+ personaForm ? h('div', {
1381
+ key: 'form',
1382
+ style: { display: 'flex', flexDirection: 'column', gap: 6, padding: '8px 10px', background: C.layer1, border: `1px solid ${C.border1}`, borderRadius: 8 },
1383
+ }, [
1384
+ h(Field, { key: 'n', label: '人设名(会出现在下拉里)' }, h('input', {
1385
+ value: draftName,
1386
+ placeholder: '例如:隔壁老王',
1387
+ onChange: (event) => setDraftName(event.target.value.slice(0, 40)),
1388
+ style: inputStyle,
1389
+ })),
1390
+ h(Field, { key: 'p', label: '这个人怎么说话(描述越具体越像)' }, h('textarea', {
1391
+ value: draftPrompt,
1392
+ rows: 4,
1393
+ placeholder: '例如:说话直白、爱用短句、习惯反问;对熟人会损两句,但分寸很稳。',
1394
+ onChange: (event) => setDraftPrompt(event.target.value.slice(0, 2000)),
1395
+ style: { ...inputStyle, resize: 'vertical', lineHeight: 1.6, fontFamily: 'inherit' },
1396
+ })),
1397
+ h('div', { key: 'b', style: { display: 'flex', gap: 8, alignItems: 'center' } }, [
1398
+ h(Btn, {
1399
+ key: 'save',
1400
+ kind: 'primary',
1401
+ disabled: busy || draftName.trim() === '' || draftPrompt.trim() === '',
1402
+ onClick: () => {
1403
+ if (typeof onAddPersona !== 'function') return
1404
+ onAddPersona({ name: draftName.trim(), prompt: draftPrompt.trim() })
1405
+ setDraftName('')
1406
+ setDraftPrompt('')
1407
+ setPersonaForm(false)
1408
+ },
1409
+ }, '保存人设'),
1410
+ h('span', { key: 'h', style: { fontSize: 10.5, color: C.label2, lineHeight: 1.5 } },
1411
+ '保存后会自动选中它。人设只影响措辞,不会改变好感度的判断口径。'),
1412
+ ]),
1413
+ ]) : null,
1414
+ ])
1415
+ })(),
1416
+
1320
1417
  h('div', { key: 'mode', style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } }, [
1321
1418
  h('span', { key: 'l', style: { fontSize: 11.5, color: C.label2 } }, '方式'),
1322
1419
  h(Btn, {
@@ -1339,7 +1436,7 @@ window.__ModuleLoader__.load({
1339
1436
  ]),
1340
1437
 
1341
1438
  h('div', { key: 'limits', style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: 8 } }, [
1342
- h(Field, { key: 'cap', label: '每小时最多几条' }, h('input', {
1439
+ h(Field, { key: 'cap', label: '每小时最多回几次' }, h('input', {
1343
1440
  value: cap,
1344
1441
  inputMode: 'numeric',
1345
1442
  onChange: (event) => setCap(event.target.value.replace(/\D/g, '').slice(0, 2)),
@@ -1353,8 +1450,20 @@ window.__ModuleLoader__.load({
1353
1450
  onBlur: () => commitNumber('maxReplyChars', chars, 10, 300, () => setChars(String(care.maxReplyChars))),
1354
1451
  style: inputStyle,
1355
1452
  })),
1453
+ h(Field, { key: 'delay', label: '等几秒再回(0 = 立刻回)' }, h('input', {
1454
+ value: delay,
1455
+ inputMode: 'numeric',
1456
+ onChange: (event) => setDelay(event.target.value.replace(/\D/g, '').slice(0, 3)),
1457
+ onBlur: () => commitNumber('replyDelaySeconds', delay, 0, 300, () => setDelay(String(care.replyDelaySeconds))),
1458
+ style: inputStyle,
1459
+ })),
1356
1460
  ]),
1357
1461
 
1462
+ h('div', {
1463
+ key: 'delay-note',
1464
+ style: { fontSize: 11, color: C.label2, lineHeight: 1.7 },
1465
+ }, `等 ${care.replyDelaySeconds ?? 5} 秒再回:这段时间里 TA 再发消息就重新计时,等安静下来才一次性回完上面所有内容。想直接回就把这里填 0。`),
1466
+
1358
1467
  h('div', { key: 'quiet', style: { display: 'flex', gap: 8, alignItems: 'flex-end', flexWrap: 'wrap' } }, [
1359
1468
  h(Field, { key: 'f', label: '免打扰开始(留空 = 不启用)' }, h('input', {
1360
1469
  value: quietFrom,
@@ -1398,7 +1507,39 @@ window.__ModuleLoader__.load({
1398
1507
  usage === undefined ? null : h('div', {
1399
1508
  key: 'usage',
1400
1509
  style: { fontSize: 11, color: C.label2 },
1401
- }, `最近一小时自动回复 ${usage.lastHour} 条,最后一条 ${fmtTime(usage.lastAt)}。`),
1510
+ }, `最近一小时自动回复 ${usage.lastHour} 次${usage.coveredMessages > usage.lastHour ? `(覆盖 TA 的 ${usage.coveredMessages} 条消息)` : ''},最后一条 ${fmtTime(usage.lastAt)}。`),
1511
+
1512
+ h('div', {
1513
+ key: 'cap-note',
1514
+ style: { fontSize: 11, color: C.label2, lineHeight: 1.7 },
1515
+ }, `到上限(每小时 ${care.hourlyCap} 次)之后,插件会先用一句得体的借口把这次聊天收尾(「我先去忙了」这类),然后这一小时内不再回复。同一小时只推辞一次,不会反复刷理由。`),
1516
+
1517
+ h('div', {
1518
+ key: 'cap-note-2',
1519
+ style: { fontSize: 11, color: C.label2, lineHeight: 1.7 },
1520
+ }, `「一次」= 一条自动回复。如果 TA 连着发好几条、被上面那几秒的等待攒成一批,那也只算一次。`),
1521
+
1522
+ typeof onResetCount === 'function' ? h('div', {
1523
+ key: 'reset',
1524
+ style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' },
1525
+ }, [
1526
+ h(Btn, {
1527
+ key: 'b',
1528
+ kind: 'outline',
1529
+ disabled: busy,
1530
+ title: '把这个人这一小时的回复计数清零,托管立刻恢复回复',
1531
+ onClick: () => {
1532
+ const spent = usage === undefined ? '' : `(这一小时已经回复 ${usage.lastHour} 条)`
1533
+ if (!window.confirm(`把「${person.names?.slice(-1)[0] ?? person.uin}」这一小时的自动回复计数清零?${spent}之后托管会立刻恢复回复。`)) return
1534
+ onResetCount()
1535
+ },
1536
+ style: { padding: '3px 9px', fontSize: 11.5 },
1537
+ }, '重置这一小时的计数'),
1538
+ h('span', {
1539
+ key: 'h',
1540
+ style: { fontSize: 10.5, color: C.label2, lineHeight: 1.5 },
1541
+ }, '推辞记录也会作废,所以重新超限时会再推辞一次。'),
1542
+ ]) : null,
1402
1543
  ])
1403
1544
  }
1404
1545
 
@@ -1730,6 +1871,15 @@ window.__ModuleLoader__.load({
1730
1871
  return () => window.clearInterval(timer)
1731
1872
  }, [careActive, draftCount, load, loadConversation, loadPersonOutbox])
1732
1873
 
1874
+ // A running task changes faster than the slow poll above: while any task is
1875
+ // in flight, refresh the snapshot every couple of seconds so the list moves.
1876
+ const hasRunningTask = (state?.tasks ?? []).some(task => task.state === 'running')
1877
+ useEffect(() => {
1878
+ if (hasRunningTask !== true) return undefined
1879
+ const timer = window.setInterval(() => { void load() }, 2000)
1880
+ return () => window.clearInterval(timer)
1881
+ }, [hasRunningTask, load])
1882
+
1733
1883
  // Handlers ----------------------------------------------------------
1734
1884
 
1735
1885
  const toggleConversation = async (row, enabled) => {
@@ -1892,6 +2042,61 @@ window.__ModuleLoader__.load({
1892
2042
  }
1893
2043
  }
1894
2044
 
2045
+ /** Analyse one group as a room: topics, mood, core members. */
2046
+ const analyzeGroupChat = async (conversationId, force = false) => {
2047
+ setBusy(`group:${conversationId}`)
2048
+ setPanelError(null)
2049
+ try {
2050
+ const result = await api('group', { method: 'POST', body: { conversationId, force } })
2051
+ if (!alive.current) return
2052
+ setState(result.state)
2053
+ if (result.group?.reused === true) notify('群里没有新消息,直接沿用了上次的分析(没有消耗模型调用)。')
2054
+ else if (result.group?.basedOn?.incremental === true) notify(`群聊分析已更新:只看了新增的 ${result.group.basedOn.deltaMessages} 条。`)
2055
+ else notify('群聊分析已完成。')
2056
+ } catch (failure) {
2057
+ if (!alive.current) return
2058
+ setPanelError({ where: `group:${conversationId}`, message: failure.message })
2059
+ } finally {
2060
+ if (alive.current) setBusy('')
2061
+ }
2062
+ }
2063
+
2064
+ /** Save a user-defined reply persona. */
2065
+ const addReplyPersona = async (draft) => {
2066
+ try {
2067
+ const result = await api('personas', { method: 'POST', body: { action: 'add', name: draft.name, prompt: draft.prompt } })
2068
+ if (!alive.current) return
2069
+ setState(result.state)
2070
+ notify(`人设「${result.persona.name}」已保存。`)
2071
+ } catch (failure) {
2072
+ if (alive.current) notify(failure.message)
2073
+ }
2074
+ }
2075
+
2076
+ /** Remove one custom reply persona; anyone using it falls back to default. */
2077
+ const deleteReplyPersona = async (id) => {
2078
+ try {
2079
+ const result = await api('personas', { method: 'POST', body: { action: 'delete', id } })
2080
+ if (!alive.current) return
2081
+ setState(result.state)
2082
+ notify('人设已删除,用到它的人回到默认人设。')
2083
+ } catch (failure) {
2084
+ if (alive.current) notify(failure.message)
2085
+ }
2086
+ }
2087
+
2088
+ /** Zero one person's hourly reply count, so托管 can answer again right away. */
2089
+ const resetCareCount = async (uin) => {
2090
+ try {
2091
+ const result = await api('care', { method: 'POST', body: { uin, action: 'reset-count' } })
2092
+ if (!alive.current) return
2093
+ setState(result.state)
2094
+ notify('这一小时的计数已清零,托管会立刻恢复回复。')
2095
+ } catch (failure) {
2096
+ if (alive.current) notify(failure.message)
2097
+ }
2098
+ }
2099
+
1895
2100
  const suggest = async (id) => {
1896
2101
  const result = await run(`suggest:${id}`, () => api('suggest', { method: 'POST', body: { conversationId: id } }))
1897
2102
  if (result === undefined) return
@@ -2167,6 +2372,7 @@ window.__ModuleLoader__.load({
2167
2372
  tabButton('conversations', '对话', conversations.length),
2168
2373
  tabButton('people', '档案', people.length),
2169
2374
  tabButton('self', '我', 0),
2375
+ tabButton('tasks', '任务', (state?.tasks ?? []).length),
2170
2376
  ]),
2171
2377
  tab === 'people' ? sortBar() : null,
2172
2378
  panelError !== null && typeof panelError.where === 'string' && panelError.where.startsWith('order:') ? h('div', {
@@ -2188,7 +2394,9 @@ window.__ModuleLoader__.load({
2188
2394
  h('div', { key: 'list', style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '4px 8px 12px' } },
2189
2395
  tab === 'conversations'
2190
2396
  ? conversationList()
2191
- : tab === 'people' ? peopleList() : selfRail()),
2397
+ : tab === 'people'
2398
+ ? peopleList()
2399
+ : tab === 'self' ? selfRail() : taskList()),
2192
2400
  h('div', {
2193
2401
  key: 'foot',
2194
2402
  style: {
@@ -2218,7 +2426,7 @@ window.__ModuleLoader__.load({
2218
2426
  ? (conversation === undefined ? emptyState() : conversationDetail(conversation))
2219
2427
  : tab === 'people'
2220
2428
  ? (person === undefined ? emptyState() : personDetail(person))
2221
- : selfDetail()),
2429
+ : tab === 'self' ? selfDetail() : tasksDetail()),
2222
2430
  ]),
2223
2431
 
2224
2432
  settingsOpen ? h(SettingsForm, {
@@ -2578,6 +2786,96 @@ window.__ModuleLoader__.load({
2578
2786
  ])
2579
2787
  }
2580
2788
 
2789
+ /** One task line, shared by the rail list and the detail pane. */
2790
+ function taskRow(task, { wide = false } = {}) {
2791
+ const color = task.state === 'running' ? C.brand : task.state === 'failed' ? C.error : C.success
2792
+ const progress = task.total > 0 ? ` ${Math.min(task.done, task.total)}/${task.total}` : ''
2793
+ const queued = task.queuedCount > 0 ? `(还有 ${task.queuedCount} 个)` : ''
2794
+ const elapsed = task.state === 'running'
2795
+ ? ` · ${formatElapsed(Date.now() - task.startedAt)}`
2796
+ : ''
2797
+ const title = task.queuedCount > 0 ? `排队中:${task.queued.join('、')}` : (task.error === '' ? task.label : task.error)
2798
+ const line = `${task.label}${task.detail === '' ? '' : ` · ${task.detail}`}${progress}${queued}`
2799
+ const percent = task.total > 0 ? Math.round(Math.min(100, (task.done / task.total) * 100)) : 0
2800
+ return h('div', {
2801
+ key: task.id,
2802
+ title,
2803
+ style: {
2804
+ display: 'flex',
2805
+ flexDirection: 'column',
2806
+ gap: 2,
2807
+ padding: wide ? '7px 0' : '0',
2808
+ borderBottom: wide ? `1px solid ${C.border1}` : 'none',
2809
+ minWidth: 0,
2810
+ },
2811
+ }, [
2812
+ h('div', { key: 'top', style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0 } }, [
2813
+ h('span', { key: 'dot', style: { width: 6, height: 6, borderRadius: 999, background: color, flex: '0 0 auto' } }),
2814
+ h('span', {
2815
+ key: 't',
2816
+ style: {
2817
+ flex: 1,
2818
+ minWidth: 0,
2819
+ overflow: 'hidden',
2820
+ textOverflow: 'ellipsis',
2821
+ whiteSpace: 'nowrap',
2822
+ fontSize: wide ? 12 : 11,
2823
+ lineHeight: 1.5,
2824
+ color: task.state === 'failed' ? C.error : C.label,
2825
+ },
2826
+ }, line + elapsed),
2827
+ ]),
2828
+ wide && task.total > 0 ? h('div', {
2829
+ key: 'bar',
2830
+ style: { height: 3, borderRadius: 999, background: C.layer2, overflow: 'hidden', marginLeft: 12 },
2831
+ }, h('div', { style: { width: `${percent}%`, height: '100%', background: color } })) : null,
2832
+ wide && task.error !== '' ? h('div', {
2833
+ key: 'err',
2834
+ style: { fontSize: 10.5, color: C.error, marginLeft: 12, lineHeight: 1.5, whiteSpace: 'pre-wrap' },
2835
+ }, task.error) : null,
2836
+ ])
2837
+ }
2838
+
2839
+ /** Rail list for the 任务 tab. */
2840
+ function taskList() {
2841
+ const rows = state?.tasks ?? []
2842
+ if (rows.length === 0) {
2843
+ return h('div', { style: { padding: '18px 10px', color: C.label2, fontSize: 12, lineHeight: 1.85 } }, [
2844
+ h('div', { key: 'a', style: { color: C.label, fontWeight: 600, marginBottom: 4 } }, '现在没有任务'),
2845
+ h('div', { key: 'b' }, '分析、批量更新、同步历史、托管回复开始运行时,会在这里排队出现。'),
2846
+ ])
2847
+ }
2848
+ return [...rows].reverse().map(task => h('div', {
2849
+ key: task.id,
2850
+ style: { padding: '6px 8px', marginBottom: 2, borderRadius: 6 },
2851
+ }, taskRow(task)))
2852
+ }
2853
+
2854
+ /** Main pane for the 任务 tab: the same queue, with progress and reasons. */
2855
+ function tasksDetail() {
2856
+ const rows = state?.tasks ?? []
2857
+ const running = rows.filter(task => task.state === 'running')
2858
+ const finished = rows.filter(task => task.state !== 'running')
2859
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12, maxWidth: 900 } }, [
2860
+ h(Section, {
2861
+ key: 'running',
2862
+ title: '正在进行',
2863
+ extra: h(Chip, { key: 'c', mono: true, color: running.length > 0 ? C.brand : C.idle }, `${running.length} 个`),
2864
+ }, running.length === 0
2865
+ ? h('div', { style: { fontSize: 12, color: C.label2, lineHeight: 1.8 } }, '空闲中。点「分析」「一键更新全部」「同步已载入的消息」或让别人发条消息(托管开着时),任务会出现在这里。')
2866
+ : h('div', { style: { display: 'flex', flexDirection: 'column' } }, running.map(task => taskRow(task, { wide: true })))),
2867
+ h(Section, {
2868
+ key: 'finished',
2869
+ title: '刚结束',
2870
+ extra: h(Chip, { key: 'c', mono: true }, `${finished.length} 个`),
2871
+ }, finished.length === 0
2872
+ ? h('div', { style: { fontSize: 12, color: C.label2, lineHeight: 1.8 } }, '还没有结束的任务。')
2873
+ : h('div', { style: { display: 'flex', flexDirection: 'column' } }, finished.map(task => taskRow(task, { wide: true })))),
2874
+ h('div', { key: 'hint', style: { fontSize: 11, color: C.label2, lineHeight: 1.75 } },
2875
+ '任务由插件后台登记,结束的任务会保留几秒再消失。批量更新会在这里显示进度和还在排队的名单,悬停可以看到具体是谁。'),
2876
+ ])
2877
+ }
2878
+
2581
2879
  /** The batch-refresh bar, above the add-conversation button. */
2582
2880
  function refreshBar() {
2583
2881
  const job = refreshJob
@@ -2809,6 +3107,12 @@ window.__ModuleLoader__.load({
2809
3107
  h(Btn, { key: 'del', kind: 'danger', onClick: () => void removeConversation(row.id) }, '删除数据'),
2810
3108
  ]) : null,
2811
3109
 
3110
+ row.enabled && row.kind === 'group' ? h(Section, {
3111
+ key: 'group-analysis',
3112
+ title: '群聊分析',
3113
+ extra: groupHeaderExtra(row),
3114
+ }, groupBody(row)) : null,
3115
+
2812
3116
  row.enabled && row.kind === 'group' ? h('div', {
2813
3117
  key: 'members',
2814
3118
  style: { fontSize: 11.5, color: C.label2, lineHeight: 1.8, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' },
@@ -3126,6 +3430,160 @@ window.__ModuleLoader__.load({
3126
3430
  return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12 } }, [errorBox, header])
3127
3431
  }
3128
3432
 
3433
+ /** Header chip for the group analysis section. */
3434
+ function groupHeaderExtra(row) {
3435
+ const group = row.groupProfile
3436
+ if (group === null || group === undefined) return h(Chip, { key: 'c', color: C.idle }, '未分析')
3437
+ return h('div', { key: 'c', style: { display: 'flex', gap: 6, alignItems: 'center' } }, [
3438
+ group.atmosphere?.label === undefined || group.atmosphere.label === ''
3439
+ ? null
3440
+ : h(Chip, { key: 'a', color: C.brand }, group.atmosphere.label),
3441
+ h(Chip, { key: 'b', mono: true }, `置信 ${Math.round((group.confidence ?? 0) * 100)}%`),
3442
+ ])
3443
+ }
3444
+
3445
+ /** One labelled bar, used for topic shares and member shares. */
3446
+ function shareBar(share, color) {
3447
+ return h('div', {
3448
+ 'aria-hidden': true,
3449
+ style: { height: 4, borderRadius: 999, background: C.layer2, overflow: 'hidden', flex: '0 0 64px' },
3450
+ }, h('div', { style: { width: `${Math.round(Math.min(1, share) * 100)}%`, height: '100%', background: color } }))
3451
+ }
3452
+
3453
+ /** The group analysis body: empty state or the full picture. */
3454
+ function groupBody(row) {
3455
+ const group = row.groupProfile
3456
+ const working = busy === `group:${row.id}`
3457
+ const button = (key, label, kind, onClick, title) => h(Btn, {
3458
+ key, kind, title, disabled: working, onClick,
3459
+ }, working ? '正在分析…' : label)
3460
+ if (group === null || group === undefined) {
3461
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } }, [
3462
+ h('div', { style: { fontSize: 12, color: C.label2, lineHeight: 1.85 } },
3463
+ '分析这个群主要在聊什么、气氛怎么样、谁在撑场子、怎么开口更容易被接住。需要至少 20 条记录。'),
3464
+ h('div', { key: 'b', style: { display: 'flex', gap: 8, alignItems: 'center' } }, [
3465
+ button('run', '分析这个群', 'primary', () => void analyzeGroupChat(row.id)),
3466
+ h('span', { key: 'n', style: { fontSize: 11, color: C.label2 } }, `${row.messageCount} 条记录`),
3467
+ ]),
3468
+ panelError !== null && panelError.where === `group:${row.id}` ? h('div', {
3469
+ key: 'err',
3470
+ style: { fontSize: 11.5, color: C.error, lineHeight: 1.7, whiteSpace: 'pre-wrap' },
3471
+ }, panelError.message) : null,
3472
+ ])
3473
+ }
3474
+ const stats = group.stats ?? {}
3475
+ const atmosphere = group.atmosphere ?? {}
3476
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 12 } }, [
3477
+ h('div', { key: 'sum', style: { fontSize: 13, lineHeight: 1.8, color: C.label } }, group.summary),
3478
+
3479
+ // Numbers the model cannot count, measured from the transcript.
3480
+ h('div', {
3481
+ key: 'stats',
3482
+ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: 8 },
3483
+ }, [
3484
+ h('div', { key: 's1', style: { fontSize: 11.5, color: C.label2 } }, [
3485
+ h('div', { key: 'v', style: { color: C.label, fontSize: 15, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, String(stats.activeSpeakers ?? '—')),
3486
+ h('div', { key: 'l' }, '常驻说话的人'),
3487
+ ]),
3488
+ h('div', { key: 's2', style: { fontSize: 11.5, color: C.label2 } }, [
3489
+ h('div', { key: 'v', style: { color: C.label, fontSize: 15, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, `${Math.round((stats.topThreeShare ?? 0) * 100)}%`),
3490
+ h('div', { key: 'l' }, '前三人占发言'),
3491
+ ]),
3492
+ h('div', { key: 's3', style: { fontSize: 11.5, color: C.label2 } }, [
3493
+ h('div', { key: 'v', style: { color: C.label, fontSize: 15, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, String(stats.messagesPerActiveDay ?? '—')),
3494
+ h('div', { key: 'l' }, '日均消息'),
3495
+ ]),
3496
+ h('div', { key: 's4', style: { fontSize: 11.5, color: C.label2 } }, [
3497
+ h('div', { key: 'v', style: { color: C.label, fontSize: 15, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, `${Math.round((stats.myShare ?? 0) * 100)}%`),
3498
+ h('div', { key: 'l' }, '我的发言占'),
3499
+ ]),
3500
+ h('div', { key: 's5', style: { fontSize: 11.5, color: C.label2 } }, [
3501
+ h('div', { key: 'v', style: { color: C.label, fontSize: 15, fontWeight: 600, fontVariantNumeric: 'tabular-nums' } }, String(stats.atMeMessages ?? 0)),
3502
+ h('div', { key: 'l' }, '被 @ 次数'),
3503
+ ]),
3504
+ h('div', { key: 's6', style: { fontSize: 11.5, color: C.label2 } }, [
3505
+ h('div', { key: 'v', style: { color: C.label, fontSize: 15, fontWeight: 600 } },
3506
+ (stats.peakHours ?? []).length === 0 ? '—' : (stats.peakHours ?? []).map(hour => `${hour}点`).join(' ')),
3507
+ h('div', { key: 'l' }, '最活跃时段'),
3508
+ ]),
3509
+ ]),
3510
+
3511
+ (group.topics ?? []).length === 0 ? null : h('div', { key: 'topics', style: { display: 'flex', flexDirection: 'column', gap: 6 } }, [
3512
+ h('div', { key: 'h', style: { fontSize: 12, color: C.label2, marginBottom: 2 } }, '主要在聊什么'),
3513
+ ...group.topics.map((topic, index) => h('div', {
3514
+ key: index,
3515
+ style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 12 },
3516
+ }, [
3517
+ h('span', { key: 'l', style: { flex: '0 0 auto', color: C.label, minWidth: 64 } }, topic.label),
3518
+ shareBar(topic.share, C.brand),
3519
+ h('span', { key: 's', style: { fontSize: 11, color: C.label2, fontVariantNumeric: 'tabular-nums' } }, `${Math.round(topic.share * 100)}%`),
3520
+ h('span', { key: 'e', style: { flex: 1, minWidth: 0, fontSize: 11, color: C.label2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: topic.evidence }, topic.evidence),
3521
+ ])),
3522
+ ]),
3523
+
3524
+ h('div', { key: 'mood', style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))', gap: 10 } }, [
3525
+ h(Meter, { key: 'e', label: '热闹程度', value: atmosphere.energy }),
3526
+ h(Meter, { key: 'w', label: '亲密度', value: atmosphere.warmth }),
3527
+ h(Meter, { key: 'o', label: '有序程度', value: atmosphere.order }),
3528
+ h(Meter, { key: 's', label: '正经事占比', value: atmosphere.seriousness }),
3529
+ ]),
3530
+ (atmosphere.evidence ?? []).length === 0 ? null : h('ul', {
3531
+ key: 'mood-ev',
3532
+ style: { margin: 0, paddingLeft: 18, fontSize: 11.5, color: C.label2, lineHeight: 1.8 },
3533
+ }, (atmosphere.evidence ?? []).map((line, index) => h('li', { key: index }, line))),
3534
+
3535
+ (group.coreMembers ?? []).length === 0 ? null : h('div', { key: 'core', style: { display: 'flex', flexDirection: 'column', gap: 5 } }, [
3536
+ h('div', { key: 'h', style: { fontSize: 12, color: C.label2 } }, '谁在撑这个群'),
3537
+ ...group.coreMembers.map((member, index) => {
3538
+ const known = (stats.speakers ?? []).find(speaker => speaker.uin === member.uin)
3539
+ return h('div', { key: index, style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 12 } }, [
3540
+ h('span', { key: 'n', style: { minWidth: 80, color: C.label } }, member.name === '' ? `QQ ${member.uin}` : member.name),
3541
+ h(Chip, { key: 'r', color: C.brand }, member.role === '' ? '活跃' : member.role),
3542
+ known === undefined ? null : shareBar(known.share, C.success),
3543
+ known === undefined ? null : h('span', { key: 's', style: { fontSize: 11, color: C.label2, fontVariantNumeric: 'tabular-nums' } }, `${Math.round(known.share * 100)}%`),
3544
+ h('span', { key: 'e', style: { flex: 1, minWidth: 0, fontSize: 11, color: C.label2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: member.evidence }, member.evidence),
3545
+ ])
3546
+ }),
3547
+ ]),
3548
+
3549
+ (group.norms ?? []).length === 0 && (group.cautions ?? []).length === 0 ? null : h('div', {
3550
+ key: 'rules',
3551
+ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 10 },
3552
+ }, [
3553
+ (group.norms ?? []).length === 0 ? null : h('div', { key: 'n', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.9 } }, [
3554
+ h('div', { key: 'h', style: { color: C.label, fontWeight: 600, marginBottom: 2 } }, '群里的默契'),
3555
+ ...(group.norms ?? []).map((line, index) => h('div', { key: index }, `· ${line}`)),
3556
+ ]),
3557
+ (group.cautions ?? []).length === 0 ? null : h('div', { key: 'c', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.9 } }, [
3558
+ h('div', { key: 'h', style: { color: C.label, fontWeight: 600, marginBottom: 2 } }, '说话要小心'),
3559
+ ...(group.cautions ?? []).map((line, index) => h('div', { key: index }, `· ${line}`)),
3560
+ ]),
3561
+ ]),
3562
+
3563
+ (group.howToJoin ?? []).length === 0 ? null : h('div', { key: 'join', style: { fontSize: 11.5, color: C.label2, lineHeight: 1.9 } }, [
3564
+ h('div', { key: 'h', style: { color: C.label, fontWeight: 600, marginBottom: 2 } }, '怎么开口更容易被接住'),
3565
+ ...(group.howToJoin ?? []).map((line, index) => h('div', { key: index }, `· ${line}`)),
3566
+ ]),
3567
+
3568
+ h('div', {
3569
+ key: 'meta',
3570
+ style: { fontSize: 10.5, color: C.label2, display: 'flex', gap: 14, flexWrap: 'wrap', alignItems: 'center' },
3571
+ }, [
3572
+ h('span', { key: 'a' }, `依据 ${group.basedOn?.totalMessages ?? 0} 条消息`),
3573
+ h('span', { key: 'b' }, `更新于 ${fmtTime(group.updatedAt)}`),
3574
+ h('span', { key: 'c' }, analysisMode(group)),
3575
+ h('span', { key: 'd' }, `本次 ${tokenCost(group.usage)} tokens`),
3576
+ h('div', { key: 'sp', style: { flex: 1 } }),
3577
+ button('again', '增量更新', 'outline', () => void analyzeGroupChat(row.id)),
3578
+ button('force', '完整重算', 'quiet', () => void analyzeGroupChat(row.id, true), '忽略上次结论,从头读完全部记录'),
3579
+ ]),
3580
+ panelError !== null && panelError.where === `group:${row.id}` ? h('div', {
3581
+ key: 'err',
3582
+ style: { fontSize: 11.5, color: C.error, lineHeight: 1.7, whiteSpace: 'pre-wrap' },
3583
+ }, panelError.message) : null,
3584
+ ])
3585
+ }
3586
+
3129
3587
  function personDetail(row) {
3130
3588
  const stored = row.score
3131
3589
  const persona = row.persona ?? null
@@ -3528,7 +3986,11 @@ window.__ModuleLoader__.load({
3528
3986
  careEnabled,
3529
3987
  busy: busy === `care:${row.uin}`,
3530
3988
  usage: state.careUsage?.[row.uin],
3989
+ personas: state.replyPersonas ?? [],
3531
3990
  onChange: (patch) => void setCare(row.uin, patch),
3991
+ onAddPersona: addReplyPersona,
3992
+ onDeletePersona: deleteReplyPersona,
3993
+ onResetCount: () => void resetCareCount(row.uin),
3532
3994
  })),
3533
3995
 
3534
3996
  h(Section, { key: 'care-log', title: '这个人的自动回复记录' }, h(OutboxList, {
package/index.js CHANGED
@@ -23,6 +23,7 @@ import { createCareEngine } from './lib/care.js'
23
23
  import { createNodeHandler } from './lib/inbound.js'
24
24
  import { bridgePort, startBridgeServer } from './lib/bridge-server.js'
25
25
  import { recoverLoaded } from './lib/recover.js'
26
+ import { createTaskRegistry } from './lib/tasks.js'
26
27
 
27
28
  export const name = 'qq-affinity'
28
29
 
@@ -52,10 +53,13 @@ export const inject = ['connection', 'timer']
52
53
  */
53
54
  export function apply(ctx) {
54
55
  const store = new Store(resolveDataDirectory())
55
- const engine = createCareEngine({ ctx, store })
56
+ // One registry shared by the routes and the care engine, so the panel shows
57
+ // every slow operation in the same list.
58
+ const tasks = createTaskRegistry()
59
+ const engine = createCareEngine({ ctx, store, tasks })
56
60
  // Shared mutable status: the listener settles asynchronously, the panel reads it on demand.
57
61
  const bridge = { listening: false, port: bridgePort(), url: '', error: 'starting' }
58
- const routes = createRoutes(ctx, store, engine, bridge, { version: VERSION })
62
+ const routes = createRoutes(ctx, store, engine, bridge, { version: VERSION, tasks })
59
63
 
60
64
  ctx.effect(() => {
61
65
  const disposers = routes.map(route => ctx.connection.fetch.register({