dsh-qq-affinity 1.6.1 → 1.7.5

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 = '1.6.0'
23
+ const VERSION = '1.7.4'
24
24
 
25
25
  // ---------------------------------------------------------------- palette
26
26
 
@@ -82,8 +82,7 @@ window.__ModuleLoader__.load({
82
82
  : C.layer1)
83
83
 
84
84
  /** Distinct accent per list position, so neighbouring traits never match. */
85
- const TRAIT_COLORS = [
86
- () => C.brand,
85
+ const TRAIT_COLORS = [ () => C.brand,
87
86
  () => mix(C.brand, C.success, 45),
88
87
  () => C.success,
89
88
  () => mix(C.success, C.warn, 50),
@@ -92,6 +91,13 @@ window.__ModuleLoader__.load({
92
91
  ]
93
92
  const traitColor = (index) => (supportsColorMix ? TRAIT_COLORS[index % TRAIT_COLORS.length]() : C.brand)
94
93
 
94
+ /**
95
+ * The contribution chart reuses the score palette on purpose: green for the
96
+ * people who carry the room, warm colours for the quiet end. Same bands as
97
+ * the favour meters, so the two charts read as one visual language.
98
+ */
99
+ const contributionColor = (position) => tone(Math.round(Math.min(1, Math.max(0, position)) * 100))
100
+
95
101
  /** "正在分析" 已经跑了多久: 12 秒 / 3 分 5 秒 / 1 小时 2 分. */
96
102
  function formatElapsed(ms) {
97
103
  const total = Math.max(0, Math.round(Number(ms) / 1000))
@@ -3533,6 +3539,8 @@ window.__ModuleLoader__.load({
3533
3539
  style: { margin: 0, paddingLeft: 18, fontSize: 11.5, color: C.label2, lineHeight: 1.8 },
3534
3540
  }, (atmosphere.evidence ?? []).map((line, index) => h('li', { key: index }, line))),
3535
3541
 
3542
+ contributionChart(group),
3543
+
3536
3544
  (group.coreMembers ?? []).length === 0 ? null : h('div', { key: 'core', style: { display: 'flex', flexDirection: 'column', gap: 5 } }, [
3537
3545
  h('div', { key: 'h', style: { fontSize: 12, color: C.label2 } }, '谁在撑这个群'),
3538
3546
  ...group.coreMembers.map((member, index) => {
@@ -3585,6 +3593,174 @@ window.__ModuleLoader__.load({
3585
3593
  ])
3586
3594
  }
3587
3595
 
3596
+ /**
3597
+ * Group contribution: the people who carry the room, with their avatar, and
3598
+ * a column chart underneath.
3599
+ *
3600
+ * The numbers come from the measured speakers, not from the model, so the
3601
+ * chart is exact. Avatars are QQ's public CDN by QQ number; when that image
3602
+ * cannot load (offline, or blocked), the circle falls back to an initial so
3603
+ * the row never collapses.
3604
+ */
3605
+ function contributionChart(group) {
3606
+ const stats = group.stats ?? {}
3607
+ const speakers = (stats.speakers ?? []).filter(speaker => speaker.uin !== 'unknown')
3608
+ if (speakers.length === 0) return null
3609
+ const top = speakers.slice(0, 6)
3610
+ // Bar height ranks against the leader; colour spreads across the visible
3611
+ // range, so six near-equal shares still read as six different shades.
3612
+ const maxShare = Math.max(...top.map(speaker => speaker.share), 0.01)
3613
+ const minShare = Math.min(...top.map(speaker => speaker.share))
3614
+ const shareSpan = maxShare - minShare
3615
+ const positionOf = (speaker) => (shareSpan > 0.0001
3616
+ ? (speaker.share - minShare) / shareSpan
3617
+ // Everyone identical: show them all at the strong end rather than
3618
+ // inventing differences that the numbers do not support.
3619
+ : 1)
3620
+ const selfUin = state.settings?.selfUin ?? ''
3621
+ const label = (speaker) => (speaker.name === '' ? `QQ ${speaker.uin}` : speaker.name)
3622
+ return h('div', { key: 'contribution', style: { display: 'flex', flexDirection: 'column', gap: 6 } }, [
3623
+ h('div', {
3624
+ key: 'h',
3625
+ style: { display: 'flex', alignItems: 'baseline', gap: 8, fontSize: 12, color: C.label2 },
3626
+ }, [
3627
+ h('span', { key: 't', style: { color: C.label, fontWeight: 600 } }, '群贡献'),
3628
+ h('span', { key: 's' }, `发言最多的 ${top.length} 人 · 柱高 = 发言占比`),
3629
+ ]),
3630
+ // Legend: the colour is the ranking, not decoration.
3631
+ h('div', {
3632
+ key: 'legend',
3633
+ style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: 10.5, color: C.label2 },
3634
+ }, [
3635
+ h('span', { key: 'l' }, '贡献低'),
3636
+ h('div', {
3637
+ key: 'g',
3638
+ 'aria-hidden': true,
3639
+ style: {
3640
+ flex: '0 0 92px',
3641
+ height: 5,
3642
+ borderRadius: 999,
3643
+ overflow: 'hidden',
3644
+ display: 'flex',
3645
+ },
3646
+ // Same band gradient the score legend uses, low → high.
3647
+ }, [...BANDS].reverse().map(([, color], index) => h('div', {
3648
+ key: index,
3649
+ style: { flex: 1, background: color() },
3650
+ }))),
3651
+ h('span', { key: 'r' }, '贡献高'),
3652
+ ]),
3653
+ h('div', {
3654
+ key: 'chart',
3655
+ style: {
3656
+ display: 'grid',
3657
+ gridTemplateColumns: `repeat(${top.length}, minmax(0, 1fr))`,
3658
+ gap: 8,
3659
+ alignItems: 'end',
3660
+ padding: '10px 4px 2px',
3661
+ background: C.bg,
3662
+ border: `1px solid ${C.border1}`,
3663
+ borderRadius: 10,
3664
+ },
3665
+ }, top.map((speaker, index) => {
3666
+ const isMe = selfUin !== '' && speaker.uin === selfUin
3667
+ const height = Math.max(6, Math.round((speaker.share / maxShare) * 100))
3668
+ // Colour follows the score palette: the loudest of the six lands in the
3669
+ // green band, the quietest in the warm end.
3670
+ const position = positionOf(speaker)
3671
+ const color = contributionColor(position)
3672
+ const initial = (label(speaker).trim()[0] ?? '?').toUpperCase()
3673
+ return h('div', {
3674
+ key: speaker.uin,
3675
+ title: `${label(speaker)}:${speaker.messages} 条,占 ${Math.round(speaker.share * 100)}%,平均 ${speaker.avgChars} 字(色阶位置 ${Math.round(position * 100)}%)`,
3676
+ style: { display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 3, minWidth: 0 },
3677
+ }, [
3678
+ // Avatar, with a lettered circle behind it for when the CDN is unreachable.
3679
+ h('div', {
3680
+ key: 'av',
3681
+ style: {
3682
+ position: 'relative',
3683
+ width: 34,
3684
+ height: 34,
3685
+ borderRadius: 999,
3686
+ overflow: 'hidden',
3687
+ flex: '0 0 auto',
3688
+ background: tint(color, 18),
3689
+ border: `1px solid ${isMe ? C.warn : C.border1}`,
3690
+ display: 'flex',
3691
+ alignItems: 'center',
3692
+ justifyContent: 'center',
3693
+ fontSize: 13,
3694
+ fontWeight: 600,
3695
+ color,
3696
+ },
3697
+ }, [
3698
+ h('span', { key: 'i', style: { position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center' } }, initial),
3699
+ h('img', {
3700
+ key: 'img',
3701
+ src: `https://q1.qlogo.cn/g?b=qq&nk=${encodeURIComponent(speaker.uin)}&s=100`,
3702
+ alt: '',
3703
+ loading: 'lazy',
3704
+ referrerPolicy: 'no-referrer',
3705
+ onError: (event) => { event.currentTarget.style.display = 'none' },
3706
+ onLoad: (event) => { event.currentTarget.style.position = 'absolute' },
3707
+ style: {
3708
+ width: '100%',
3709
+ height: '100%',
3710
+ objectFit: 'cover',
3711
+ display: 'block',
3712
+ },
3713
+ }),
3714
+ ]),
3715
+ h('div', {
3716
+ key: 'n',
3717
+ style: {
3718
+ fontSize: 10.5,
3719
+ color: isMe ? C.warn : C.label2,
3720
+ maxWidth: '100%',
3721
+ overflow: 'hidden',
3722
+ textOverflow: 'ellipsis',
3723
+ whiteSpace: 'nowrap',
3724
+ },
3725
+ }, isMe ? '我' : label(speaker)),
3726
+ // The column itself: height is proportional to the share of speech.
3727
+ h('div', {
3728
+ key: 'bar',
3729
+ 'aria-hidden': true,
3730
+ style: {
3731
+ width: '100%',
3732
+ height: 78,
3733
+ display: 'flex',
3734
+ alignItems: 'flex-end',
3735
+ justifyContent: 'center',
3736
+ },
3737
+ }, h('div', {
3738
+ style: {
3739
+ width: '62%',
3740
+ height: `${height}%`,
3741
+ minHeight: 4,
3742
+ background: color,
3743
+ borderRadius: '3px 3px 0 0',
3744
+ transition: 'height 240ms cubic-bezier(.2,.8,.2,1)',
3745
+ },
3746
+ })),
3747
+ h('div', {
3748
+ key: 'v',
3749
+ style: { fontSize: 10.5, color: C.label, fontVariantNumeric: 'tabular-nums' },
3750
+ }, `${Math.round(speaker.share * 100)}%`),
3751
+ h('div', {
3752
+ key: 'c',
3753
+ style: { fontSize: 10, color: C.label2, fontVariantNumeric: 'tabular-nums' },
3754
+ }, `${speaker.messages} 条`),
3755
+ ])
3756
+ })),
3757
+ selfUin === '' || top.some(speaker => speaker.uin === selfUin)
3758
+ ? null
3759
+ : h('div', { key: 'me', style: { fontSize: 10.5, color: C.label2 } },
3760
+ `我不在前 ${top.length} 名里,我的发言占 ${Math.round((stats.myShare ?? 0) * 100)}%。`),
3761
+ ])
3762
+ }
3763
+
3588
3764
  function personDetail(row) {
3589
3765
  const stored = row.score
3590
3766
  const persona = row.persona ?? null
package/lib/analyze.js CHANGED
@@ -396,7 +396,7 @@ export async function writeAutoReply(ctx, store, request) {
396
396
  '5. 不要问超过一个问题,不要连着寒暄,不要用「哈哈」「亲」这类套话开头。',
397
397
  '6. 如果对方说的是坏消息、求助或情绪问题,先接住情绪,不要急着给建议。',
398
398
  '7. 不要承诺时间、地点、金额这类具体事项 —— 这些需要我自己确认。',
399
- '8. 只聊日常。如果对方要你解题、写代码、写论文、翻译长文、做表格这类正经活儿,不要真的去做,也不要说「我看看」——用一句日常的话推掉,例如「这个我可算不明白 你找找会的」「我脑子不够用 换个人问吧」。',
399
+ '8. 只聊日常。如果对方要你解题、写代码、写论文、做表格这类正经活儿,不要真的去做,也不要说「我看看」——用一句日常的话推掉,例如「这个我可算不明白 你找找会的」「我脑子不够用 换个人问吧」。翻译和总结照常帮忙,那属于日常聊天。',
400
400
  inCharacter ? '9. 保持人设,但不要写动作描写、不要用括号、不要说「(微笑)」这类旁白。' : '',
401
401
  ].filter(line => line !== '').join('\n')
402
402
 
package/lib/guard.js CHANGED
@@ -26,7 +26,6 @@ const CODE_FENCE = /```|~~~/
26
26
  const CODE_REQUEST = /(帮我|给我|替我|麻烦|帮忙|能否|能不能|可不可以|你).{0,8}(写|改|修|调|优化|检查|看).{0,12}(代码|程序|脚本|函数|正则|报错|bug|BUG|sql|SQL|接口|爬虫|算法|leetcode|LeetCode)|^(写|改|修|实现|优化).{0,12}(代码|程序|脚本|函数|爬虫|算法)/
27
27
  const HOMEWORK = /(作业|考卷|考试题|习题|卷子|复习题|练习题)/
28
28
  const HOMEWORK_ASK = /(怎么做|怎么解|答案是|答案|帮我做|解一下|算一下|写一下)/
29
- const LONG_TEXT_TASK = /(翻译|总结|概括|润色|改写|缩写).{0,14}(这|下面|以下|一下|整篇|全文|文章|内容|这段)/
30
29
 
31
30
  /**
32
31
  * Whether one inbound message is asking for non-conversational work.
@@ -48,9 +47,8 @@ export function isNonChatRequest(text) {
48
47
  if (HOMEWORK.test(trimmed) && (mathy || HOMEWORK_ASK.test(trimmed))) {
49
48
  return { blocked: true, why: 'homework' }
50
49
  }
51
- if (LONG_TEXT_TASK.test(trimmed) && trimmed.length > 200) {
52
- return { blocked: true, why: 'long-text' }
53
- }
50
+ // Translation and summarising are deliberately NOT refused: the user asked for
51
+ // them to go through, and the prompt cap keeps the cost bounded.
54
52
  return { blocked: false, why: '' }
55
53
  }
56
54
 
@@ -60,7 +58,6 @@ export function nonChatReason(why) {
60
58
  code: '写代码/改代码',
61
59
  math: '数学题/计算',
62
60
  homework: '作业题',
63
- 'long-text': '长文翻译或总结',
64
61
  }[why] ?? '非日常任务'
65
62
  return `对方在要我做${label},托管不接这类请求(不是闲聊)。`
66
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-qq-affinity",
3
- "version": "1.6.1",
3
+ "version": "1.7.5",
4
4
  "description": "QQ 聊天记录好感度档案:本地建档、三项亲密度评分、智能回复提示、按人开启的智能托管、人格画像、可迁移的本地数据位置、从实时通道自动补齐历史。",
5
5
  "type": "module",
6
6
  "exports": {
@@ -120,6 +120,15 @@ check('the prompt names the group', prompts[0].includes('折腾群'), prompts[0]
120
120
  check('the prompt carries the speaker table', prompts[0].includes('说话人分布'), prompts[0].slice(0, 200))
121
121
  check('token usage is recorded', first.usage.inputTokens === 2400, JSON.stringify(first.usage))
122
122
  check('the measured stats ride along', first.stats.activeSpeakers === 4 && first.stats.atMeMessages === 5, JSON.stringify(first.stats).slice(0, 120))
123
+ // The contribution chart draws straight from these fields: it needs a QQ number
124
+ // for the avatar, a name to label it, and the share to size the column.
125
+ const chartRow = first.stats.speakers[0]
126
+ check('speakers carry a uin for the avatar', typeof chartRow.uin === 'string' && /^\d+$/.test(chartRow.uin), chartRow.uin)
127
+ check('speakers carry a name', chartRow.name === '小明', chartRow.name)
128
+ check('speakers carry a message count', chartRow.messages === 9, `${chartRow.messages}`)
129
+ check('speakers carry a share between 0 and 1', chartRow.share > 0 && chartRow.share <= 1, `${chartRow.share}`)
130
+ check('speakers carry an average length', chartRow.avgChars > 0, `${chartRow.avgChars}`)
131
+ check('the list is longest-speaker first', first.stats.speakers.every((speaker, index, list) => index === 0 || list[index - 1].messages >= speaker.messages))
123
132
  check('the verdict is stored on the conversation', store.groupProfile(conversation.id)?.summary === first.summary, 'ok')
124
133
  check('the evidence is fingerprinted', typeof first.basedOn.fingerprint === 'string' && first.basedOn.fingerprint !== '', first.basedOn.fingerprint)
125
134
 
@@ -36,6 +36,9 @@ const allowed = [
36
36
  '这道菜怎么做',
37
37
  '周末去看展吗',
38
38
  '帮我翻译一下这段',
39
+ // Translation and summarising are allowed on purpose now, however long they are.
40
+ `帮我翻译一下这段好吗:${'这是一段需要翻译的英文文本。'.repeat(40)}`,
41
+ `总结一下这文章:${'内容内容内容内容内容。'.repeat(40)}`,
39
42
  '```js\nconsole.log(1)\n```',
40
43
  '',
41
44
  '在吗',
@@ -49,7 +52,6 @@ console.log('\n== the recorded reason reads like a sentence ==')
49
52
  check('math', nonChatReason('math').includes('数学题'), nonChatReason('math'))
50
53
  check('code', nonChatReason('code').includes('代码'), nonChatReason('code'))
51
54
  check('homework', nonChatReason('homework').includes('作业'), nonChatReason('homework'))
52
- check('long text', nonChatReason('long-text').includes('长文'), nonChatReason('long-text'))
53
55
  check('an unknown kind still reads fine', nonChatReason('mystery').includes('非日常'), nonChatReason('mystery'))
54
56
 
55
57
  console.log(failures === 0 ? '\nALL PASS' : `\n${failures} FAILURE(S)`)