dsbot-starboard 0.0.0-stage → 0.2.0

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/ui/index.js ADDED
@@ -0,0 +1,2866 @@
1
+ // Generated by .build-desktop.cjs. Do not edit directly.
2
+ let React
3
+
4
+ // 星轨蜂巢设计令牌。深浅两套 CSS 变量,统一挂在 .dsb-root 上。
5
+ // 颜色只在角色身份色与状态色上做区分,UI chrome 保持中性。
6
+
7
+ const HIVE_FONT = '"Segoe UI Variable Text", "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif'
8
+ const HIVE_MONO = '"Cascadia Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace'
9
+
10
+ const HIVE_VARS = {
11
+ dark: {
12
+ '--dsb-font': HIVE_FONT,
13
+ '--dsb-mono': HIVE_MONO,
14
+ '--dsb-stage-0': '#080a0f',
15
+ '--dsb-stage-1': '#0d1017',
16
+ '--dsb-stage-2': '#161b28',
17
+ '--dsb-panel': '#12151c',
18
+ '--dsb-card': 'rgba(255,255,255,.035)',
19
+ '--dsb-card-hi': 'rgba(255,255,255,.07)',
20
+ '--dsb-card-border': 'rgba(255,255,255,.09)',
21
+ '--dsb-hair': 'rgba(255,255,255,.075)',
22
+ '--dsb-text-1': '#f3f5f9',
23
+ '--dsb-text-2': 'rgba(243,245,249,.72)',
24
+ '--dsb-text-3': 'rgba(243,245,249,.48)',
25
+ '--dsb-accent': '#4d6bfe',
26
+ '--dsb-accent-2': '#8b9bff',
27
+ '--dsb-cyan': '#62d6ff',
28
+ '--dsb-wait': '#f2b84b',
29
+ '--dsb-fail': '#ff6b72',
30
+ '--dsb-ok': '#2bd98a',
31
+ '--dsb-pod-bg': 'radial-gradient(circle at 50% 28%, rgba(255,255,255,.16), rgba(255,255,255,.04) 66%, rgba(255,255,255,.012) 100%)',
32
+ '--dsb-pod-shadow': '0 12px 28px -10px rgba(0,0,0,.78), inset 0 1px 0 rgba(255,255,255,.16)',
33
+ '--dsb-pod-ring': 'rgba(255,255,255,.15)',
34
+ '--dsb-star': 'rgba(255,255,255,.55)',
35
+ '--dsb-orbit': 'rgba(255,255,255,.13)',
36
+ '--dsb-dock': 'rgba(18,21,28,.84)',
37
+ '--dsb-shadow-card': '0 20px 44px -22px rgba(0,0,0,.78)',
38
+ '--dsb-name-shadow': '0 1px 3px rgba(0,0,0,.55)',
39
+ '--dsb-scroll': 'rgba(255,255,255,.16)',
40
+ },
41
+ light: {
42
+ '--dsb-font': HIVE_FONT,
43
+ '--dsb-mono': HIVE_MONO,
44
+ '--dsb-stage-0': '#e6ebf4',
45
+ '--dsb-stage-1': '#f2f5fb',
46
+ '--dsb-stage-2': '#ffffff',
47
+ '--dsb-panel': '#ffffff',
48
+ '--dsb-card': 'rgba(255,255,255,.94)',
49
+ '--dsb-card-hi': '#ffffff',
50
+ '--dsb-card-border': 'rgba(24,32,60,.10)',
51
+ '--dsb-hair': 'rgba(24,32,60,.09)',
52
+ '--dsb-text-1': '#12151c',
53
+ '--dsb-text-2': 'rgba(18,21,28,.74)',
54
+ '--dsb-text-3': 'rgba(18,21,28,.52)',
55
+ '--dsb-accent': '#3a56e8',
56
+ '--dsb-accent-2': '#4d6bfe',
57
+ '--dsb-cyan': '#0b8fce',
58
+ '--dsb-wait': '#b26b00',
59
+ '--dsb-fail': '#d92d3d',
60
+ '--dsb-ok': '#008f52',
61
+ '--dsb-pod-bg': 'radial-gradient(circle at 50% 28%, #ffffff, #f2f5fb 66%, #e6ebf6 100%)',
62
+ '--dsb-pod-shadow': '0 12px 26px -12px rgba(24,36,80,.40), inset 0 1px 0 #ffffff',
63
+ '--dsb-pod-ring': 'rgba(24,32,60,.16)',
64
+ '--dsb-star': 'rgba(24,36,80,.28)',
65
+ '--dsb-orbit': 'rgba(24,36,80,.16)',
66
+ '--dsb-dock': 'rgba(255,255,255,.88)',
67
+ '--dsb-shadow-card': '0 18px 40px -24px rgba(24,36,80,.45)',
68
+ '--dsb-name-shadow': 'none',
69
+ '--dsb-scroll': 'rgba(24,32,60,.18)',
70
+ },
71
+ }
72
+
73
+ // 由 .extract-characters.cjs 从 ds-bot 0.4.3 的 client.js 抽取,勿手改。
74
+ const CHARACTERS = {"whale":{"label":"Whale","body":"M65.3 20.9l5.1 .1 4.8 .9 4.8 1.7 4.3 2.3 3.8 3.1 3 3.4 2.3 3.8 1.6 4.3 .9 4.3 0 4.8-.8 4.8-1.4 4.3-2.3 4.3-3.2 4.3-3.4 3.3-4.3 3.1-7.2 3.5-7.6 1.7-7.2 .1-9.6-1.6-3.3-1-2.9-1.7-8.8-8.9-6-4.7-3.3-.5-7.7 1.1-4.8-.1-4.7-1.2-1.9-1.2-1-1-.5-1.5 .4-1.4 1.1-1.3 1.9-1.3 4.7-1.5 7.7-.6 1.1-.5 .7-1 0-1.4-2.8-7.2-1.2-5.3-.1-4.3 .4-1.4 .9-1.2 1.9-.2 2 1 2.2 2.3 2.2 3.4 3.2 7.6 1.9 9.7 .5-.1 1.1-7.2 1.8-4.8 3.2-5.2 3.9-4.3 4.9-3.9 5.6-2.9 5.8-1.9z","eyes":[[72.5,48.4,9.3,23,-15.8],[85.6,43.4,7,22.9,-21.2]],"paints":[["M93.3 55.8l1-.3 .1 1.2-2.4 5.3-3.4 4.8-3.8 3.8-4.8 3.4-5.7 2.8-4.8 1.5-4.8 .4 20.1-17.4 5.2-3.7z","#fff",1]],"shade":"M88.6 29.5l2.4 2.9 1.9 2.8 2.4 6.3 .5 3.3 .1 5.3-1.5 6.6-1.9 4.3-2 3.3-4.8 5.4-5.7 4.3-7.2 3.3-6.2 1.5-6.7 .1-3.3-.2-9.6-1.8-3.3-1.5-2.4-1.9-8.6-8.9-5.3-3.9-3.3-.1-2.9 .2-3.3 .8-5.8 0-4.3-1-2.9-1.9 .6-.6 3.8-1.3 10.5-2.5 4.3 .9 1.4-.1 2.2-1.7 .5-1.4-.3-1.5-1.2-1.4-2.2-1.4-1.2-1.9-.6-12 .4-3.3 .5-.5 2.9 3.8 2.4 4.8 1.9 5.7 .7 5.8 .7 2.8 2.1 2.4 2.7 5.5 3.8 4.3 2.9 2.2 3.3 1 3.4-.4 6.2-3 7.1-4.5 7.3-5.6 6.6-5.9 5.9-6.5 3.7-5.3 1.7-4.2 .1-2.9z","light":"M55.6 22.8l1.9-.3 1.5 .3 .6 1 .1 .9-2 4.3-3.8 5.3-5.8 6.2-5.4 4.4-4.8 2.3-1.4 0-1.2-.5-.8-1.9 .5-3.3 2.5-4.8 3.3-4.3 2.4-2.4 5.3-3.9zM19.3 28.1l-1.4 2 .3-1.1zM21.7 49.1l.6 .5-.3 .5-.8 0zM35.8 52l1.2-.4 .9 .7 .7 1.6-.4 .9-1.2 .1-2.6-.5zM7.2 52.9l-2.9 2.9 1.2-1.6z"},"star":{"label":"Star","body":"M40.1 4.4l1.5-.4 1.9 .1 5.2 1.1 1.9 .9 13.2 14.9 17.1-.8 5.2 1.1 1.8 .9 1.7 1.6 .7 2.4-.4 1.9-9.7 23.6 5.6 23.7 .1 1.9-.6 1.4-2.1 1.8-2.3 .5-19.9-1.8-16.6 15.5-1.9 1-1.9 .3-7-1.5-2.6-2.1-.9-2.4-2.8-24.1-16-13.6-1.1-1.5-.5-1.9 .4-1.9 1.2-1.5 18.9-13.6 7.1-24.6 1-1.7z","eyes":[[53.9,53.4,7.2,18.8,-10],[65.1,49.2,7.2,18.8,-10]]},"moon":{"label":"Moon","body":"M44.4 4.3l8-.1 11.7 2.5 6.6 2.6 5.6 3.8 5.6 5.7 4.4 7.1 3.1 7.9 1.5 8.5 .1 9.4-1.6 9.4-3.2 8.9-4.9 8.4-5.9 6.8-7 5.4-7.5 3.6-8 1.7-7.5-.2-10.7-2.3-5.8-2.1-5-3-5.3-4.7-4.7-6.1-3.4-7.1-1.6-6.1 .3-4.2 .5-.9 .9-.4 7.5 1.7 6.1 5.3 1.5 0 2.8-1.1 2.5-1.8 2.3-2.3 2.2-3.1 2.7-6.3 .9-7-.9-6.6-1.3-3.1-1.6-2.5-1.8-1.9-1.3-.7-2.8 .9-6.1 3.1-1.9 .4-7-1.6-.7-1.2 .1-1.9 1.1-3.7 2.2-3.8 3.9-4.8 4.3-4.1 4.6-3.2 4.7-2.5 4.7-1.7z","eyes":[[61.3,54.8,6.9,18.1,-10],[72.4,50.7,6.9,18.1,-10]]},"cloud":{"label":"Cloud","body":"M43.6 11.6l6.7 .1 6.6 1.9 5.3 3.4 7.7 7.9 11.3 2.5 3.6 1.6 3.6 2.5 4.1 4.7 2.6 5.7 .9 6.6-1.1 6.5-1.5 3.6-1.9 2.9-4.9 5.3-17 11.4-6.8 3.5-8.9 2.8-9.5 1.3-13.1 2.5-6.5 .2-5.9-1.1-4.2-1.8-3.6-2.6-2.7-3-2.2-3.6-1.5-4.2-.7-4.1 .2-4.2 1-4.1 1.5-3.6 2.4-3.6 8.6-8.8 1.8-2.5 1.3-2.9 2.5-10.7 1.7-3.6 2.2-3.2 3.5-3.6 3.9-2.7 4.5-1.9z","eyes":[[55.7,62.2,8.5,20.1,-10.7],[74.4,55.5,6.8,20,-11.5]]},"spark":{"label":"Spark","body":"M32.9 4.3l2.9-.2 2.3 1 21.5 19.1 1.5-.7 2.4-2.3 1.9-1.1 2.3-.1 2.1 1.2 1.2 1.7 3.1 7.6 8.4 13.9 2.6 6.5 1.2 6.2-.2 7-1.6 7-3.1 6.4-4.4 5.8-5.3 4.8-6.3 3.9-6.4 2.4-7 1.4-7 .1-6.9-1.2-6.4-2.4-5.8-3.7-5-4.8-3.7-5.5-2.4-6.1-.9-4-.3-4.1 .3-4.6 .8-4.1 2.5-7 6-11 1.8-4.1 .9-3.4 3.4-21.5 1.2-2.5z","eyes":[[60.7,67.1,8.3,19.7,-11.2],[76.9,61,6.2,19.6,-12.1]]},"bear":{"label":"Bear","body":"M63.8 4.5l5.2-.4 4.9 1.4 3.9 2.8 2.9 4.4 1 3.2 .1 3.9-.5 2.7-1.7 4.4-.2 2.1 .9 2.2 3.8 4.4 2.6 3.8 1.9 3.9 1.3 3.8 1 4.4 .3 4.9-.3 4.9-1.1 4.9-2.8 7.1-4.3 6.7-5.7 5.9-6.9 4.7-7.6 3.3-7.7 1.8-8.2 .2-7.6-1.3-7.1-2.7-6.6-4.3-5.4-5.5-3.6-6.1-2.5-7.1-.8-7.1 .6-7.1 2.1-7.1-3.5-3.3-2.3-3.8-1.1-4.3 .5-5 1.3-3.2 2.5-3.3 2.9-2.2 3.8-1.5 4.4-.4 3.9 .8 3.8 2 3.2 3.3 7.1-2.9 8.2-2 1.1-.7 .9-1.3 1.3-6.1 2.2-4 3.3-3.1z","eyes":[[62.1,63.9,9,21.4,-11.5],[80.4,57,6.7,21.3,-13.3]]},"puppy":{"label":"Puppy","body":"M48.2 13.7l4.1 0 4.3 .5 7.7 2.3 3.8-2.2 3.9-.5 3.2 .8 2.8 1.7 2.2 2.7 15 26.4 .8 4.4-.3 2.2-.9 2.2-2.6 3.1-3.8 1.9-3.8 .2-3.9-1.3-3.8 6.5-4.9 5.5-5.5 4.2-6.6 3.2-4.4 1.3-4.3 .8-5 .2-4.3-.4-4.4-1-4.4-1.6-3.8-2-3.9-2.8-.4 .8-1.4 7.1-1.2 2.2-1.9 2-2.7 1.6-2.8 .6-2.7-.1-2.7-.9-2.3-1.5-1.8-2.2-1.2-2.8-.3-2.7 5.5-34.5 1.1-3.2 1.3-1.7 1.8-1.7 4.1-1.6 5.4-7.7 3.4-3.3 3.8-2.8 4.3-2.4 4.4-1.8 4.4-1.1z","eyes":[[58,51.9,8.8,20.6,-11.1],[74.8,45.6,6.3,20.5,-12.6]]},"kitty":{"label":null,"body":"M62.4 4.2l1.6-.1 1.5 1.2 7.4 21.3 3.7 6.4 6.2 7.4 3.1 5.9 1.5 4.8 .7 5.3-.2 5.4-1.1 5.3-3 7.4-4.4 6.4-5.3 5.4-6.9 4.6-7.5 3.1-8 1.7-8 .2-7.4-1.4-4.3-1.5-3.7-1.8-3.8-2.5-3.1-2.7-2.7-3-2.5-3.7-1.9-3.7-1.4-4.3-.9-5.3 .1-5.8 1.4-7 1.6-4.2 2-3.8 .8-3.2 .2-20.2 1.1-1.4 1.1-.3 1.1 .3 12.2 9.7 5.9-2.5 8-2.1 3.2-1.8 2.3-2.4 8.3-16z","eyes":[[59.6,65.1,9.4,22.6,-11.9],[77.5,58.4,7,22.5,-14]]},"bunny":{"label":null,"body":"M49.3 4.4l1.5-.4 2 1.2 1.6 2.7 1.2 3.4 1.6 8.9 .2 6-.2 6.4 .6 3 2.4 2.5 5.4 3 3.4 2.4 5.1 5.5 2.4 3.9 1.7 4 1.1 4.4 .4 4.5-.5 5.9-1.6 5.5-2.8 5.4-3.6 4.5-4.6 3.8-4.9 2.7-5.5 1.7-5.9 .7-6-.5-5.4-1.7-4.9-2.5-4.7-3.7-3.8-4.5-2.7-4.9-1.8-5.5-.7-5.9 .6-6.5 1.9-5.9 3.1-5.4 4.6-5.5-.4-2-3.4-8.4-1.8-6.9-.6-6.9 .3-3 .6-2 1.3-1.4 2-.1 2.5 1.5 2.1 2.5 4 6.9 2.1 5.5 1.7 5.9 1.5 2.1 1.8-1.6 .7-2-.4-12.4 1-8.9 1.6-4.9z","eyes":[[59.2,69.2,8.2,19.3,-12],[72.9,64,5.6,19.1,-15.4]]},"octopus":{"label":"Octopus","body":"M41.9 4.2l4.4-.2 4.5 .3 8 2 4 1.7 3.5 2.1 3.4 2.7 2.8 3 2.4 3.3 1.9 3.4 1.5 4 .8 4 .3 4-.3 4.5-.9 4-1.4 4 1.4 1.5 9.8 5.7 1.7 1.5 1.2 1.6 .9 2.3 .4 2.3-.2 2.3-.8 2.3-1.6 2.2-2.2 1.8-2.9 1.1-2.3 .1-2.2-.3-6.6-3.2 2.7 6.2 .2 4-.6 2.3-1.4 2.3-1.8 1.7-1.7 1-4 .8-4-.9-2.8-2-2.3-3.6-.3 .7 .2 5.7-1.6 3.8-1.7 1.8-2 1.3-2.6 .8-2.3 .1-3.4-.9-3-2.3-1.7-2.8-1.3-5.2-.3-.6-.6 .1-3.1 7.9-2 2.9-1.7 1.3-2.3 1-2.3 .4-2.3-.2-2.4-.8-2.4-1.7-1.7-2.3-.9-2.3-.3-2.3 .3-2.2 4.8-13.8 .4-3.4-1.2-3.4-6.9-7.9-3.4-6.4-1.2-4-.6-4 0-4 .5-4.5 1.6-5.2 2.5-5.1 3.2-4.6 4.3-4.3 5-3.7 5.3-2.7 5.7-1.9z","eyes":[[53.6,44.1,8.6,19.9,-10],[71.1,37.5,6.1,19.9,-10]]},"sprout":{"label":"Sprout","body":"M63.2 4.1l3 .2 1.2 .8 .7 1.1 .3 1.6-.2 2.1-1.6 4.2-3.6 5-4.7 4.4-4.8 3-5.4 1.7-.3 1.1 .4 2.6 .6 .5 4.7-.1 4.3 .5 6.3 1.7 6.3 3.2 5.7 4.9 4.4 6.1 2.6 6.8 .8 7.4-1.1 7.4-2.4 6.3-3.7 5.7-4.8 5-5.7 4-6.3 2.8-6.9 1.6-6.8 .2-6.8-1-4.8-1.6-4.7-2.5-4.1-3.2-3.5-3.7-2.7-4.2-2-4.7-1.1-4.7-.4-5.3 .6-4.7 1.2-4.8 2.1-4.7 2.8-4.2 3.4-3.9 4.2-3.5 4.8-2.9 5.4-2.3 0-1.6-.2-.4-3.1 1.6-3.7 .7-3.7-.2-3.7-.9-3.1-1.5-2.6-2.1-1.4-2.4 0-2.1 .9-1.6 1.5-1.2 2.6-1 2.7-.4 5.7 .5 6.3 2.6 .3-3.1 1.3-1.9 2.1-.7 2.6 .9 4-5.7 4.4-4.5 5.1-3.3z","eyes":[[59.4,69.3,8.7,20.6,-11.1],[75.5,63.2,6.3,20.6,-12.6]]},"bloom":{"label":"Blossom","body":"M45 4.1l3-.1 2.9 .4 2.9 .9 2.8 1.5 2.4 1.9 2.1 2.3 3 5.3 4-1.3 4.6-.4 4.6 .9 4 2 3.7 3.3 2.7 4 1.5 4.6 .4 4.6-.7 4.6-1.9 4.6-2.2 3.3-4.1 3.6-.5 1.1 3.1 4.1 1.6 2.8 1.2 3.5 .6 3.4-.1 4.1-.8 3.4-1.4 3.5-1.9 2.9-2.3 2.5-2.8 2-3 1.5-2.8 .9-3.5 .3-2.8-.2-6.4-2-2.8 4.9-4.1 3.9-5.1 2.5-5.8 .8-4-.6-4-1.7-3.5-2.6-2.5-3.1-2.3-4.6-.9-4.6 .3-5.1 1.4-4.6-6.3-2.6-2.7-2-2.2-2.3-1.8-2.9-1.2-2.9-.8-3.4-.2-3.5 .4-3.4 1.1-3.5 1.8-3.4 2.2-2.9 2.8-2.4 2.9-1.7 3.4-1.2 4.1-.5 .3-.5-.9-5.2 .3-4.6 1.3-4.6 2.4-4.1 2.6-2.8 3.1-2.3 3.5-1.5z","eyes":[[54.2,55.2,8,18.1,-10],[69.4,49.5,5.1,18.1,-10]]},"acorn":{"label":null,"body":"M47.6 4l2.1 .6 1.3 1.5 .4 1.5-.4 5.2 .3 .3 8.8-.1 7.7 1 7.3 2.1 5.7 2.9 3.6 2.9 2.6 3 1.8 3.4 .9 3.7 0 4.1-1 3.6-1.7 2.2-3.9 3 2.9 8.3 .9 8.3-.9 8.3-2.7 7.7-4.2 6.8-2.9 3.1-3.2 2.6-6.7 3.8-3.7 1.2-4.1 .8-7.2 0-7.3-1.7-7-3.6-5.9-5.1-4.8-6.3-3.3-7.3-1.8-7.7-.1-8.3-4.5-1.5-2.6-1.7-2.6-4.1-1.1-4.1 0-4.2 1.2-4.1 2.2-4.1 2.8-3.7 5.2-4.6 6.3-3.8 7.2-3.2 8.3-2.3 .9-8.3 1.2-1.4z","eyes":[[63.6,63.3,9.6,22.7,-11.9],[79.5,57.3,6.5,22.5,-15.5]]},"squircle":{"label":"Squircle","body":"M54.5 4.2l3.9-.2 3.7 .3 11.6 2.7 3.1 1.6 2.8 1.9 2.6 2.7 2.2 3.1 2.4 4.8 1.9 5.8 3.7 19.4 .8 11.1-.4 4.7-1 4.7-1.3 3.5-1.8 3.4-4.8 5.8-6.4 4.7-8 4-14.2 5.3-9.5 2.2-7.4 .1-10.5-2.2-5.3-2.5-4.3-3.7-3.3-4.8-2.7-6.3-2.4-9.5-2.8-17.9-.2-7.8 1.3-7.9 2.2-5.3 2.8-4.2 4.1-4.2 4.3-3.1 6.3-3.4 11.6-4.6 7.9-2.7z","eyes":[[52.6,52.4,8.4,22.1,-10],[67.3,46.9,8.4,22.1,-10]]},"gumdrop":{"label":null,"body":"M38.7 4.5l4.4-.5 4.6 .8 4.1 1.9 3.7 3.2 23.2 36.6 2.3 5 1.4 5.1 .7 6.4-.7 6.4-1.8 6.1-3.1 5.7-4.1 5.1-5.2 4.2-5.8 3.1-6 1.8-6.4 .6-6.4-.6-6-1.8-5.9-3.1-5.1-4.2-4.1-5.1-3-5.4-1.9-6.4-.7-6 .5-5.9 9-41.6 2-4.1 2.6-3.2 3.4-2.5z","eyes":[[52.1,40.3,9.7,22.9,-15.2],[64.8,35.6,6.3,23,-27]]},"peanut":{"label":null,"body":"M43.5 4l6.6 .7 5.8 2.2 5.4 3.8 4.1 4.7 2 3.8 1.4 4.3 1.3 11.9 1 4.3 1.6 3.8 5.8 10.5 1.4 3.8 .8 4.3 .1 6.2-1 5.7-2.1 5.5-3.2 4.9-4.1 4.3-4.8 3.4-5.6 2.4-5.7 1.3-6.1 .1-5.8-1.1-5.7-2.2-4.7-3.1-4.3-4.1-3.3-4.8-2.5-5.7-1.2-5.7-.1-6.7 1.7-9 .4-4.3-.5-4.7-2.5-9.6-.6-3.8 .2-5.2 1.2-5.2 1.5-3.4 2.2-3.3 2.5-2.9 2.8-2.3 3.4-2.1 3.4-1.4 3.8-.9z","eyes":[[50.9,31.5,8.7,20.5,-11.9],[64.2,26.5,5.7,20.3,-16.3]]},"saucer":{"label":null,"body":"M45 22.7l6.7 .1 6.7 1.9 4.3 2.5 3.5 3.1 2.8 3.5 2.5 4.5 6.8 .9 5.6 1.2 4.5 1.6 3.5 2.1 2.8 2.8 1.3 3.5-.5 3.5-2 3.5-2.6 2.8-3.5 2.8-4.5 2.8-5.1 2.6-12 4.4-13.6 3.1-13.6 1.5-12.6-.3-5.5-.7-5-1.2-4.1-1.6-3.5-2-2.8-3.1-1.1-3 .5-3.5 2-3.6 2.7-3 3.7-2.9 10.3-5.6 .7-5.1 1.5-4.5 2.6-4.5 3.1-3.5 3-2.4 3.5-2 3.5-1.4z","eyes":[[53.6,45,7.8,18.4,-14.5],[66.2,40.3,5,18.3,-25.1]]},"beacon":{"label":null,"body":"M40 4.1l2.7 0 2.5 .9 2 1.7 1.1 2.1 .5 2-.2 2.1-2.1 4.1-.4 1.6 1.5 7.7 9-3.1 4.1-.2 18.5 4 3.1 1.6 2.4 2.3 1.3 2.1 .9 2.6 5.8 33.4-.4 3.1-1.3 3.1-2 2.5-2.6 1.9-41.7 15.7-4.1 .7-19.6-4-3.5-1.9-2.5-2.5-1.2-2.1-.8-2.6-5.7-32.9 .4-3.1 1-2.7 1.7-2.5 2.4-1.9 28.4-10.9-1.5-9.3-.7-1-3.5-3.3-.9-1.9-.4-2 .5-2.6 1.1-2.1 1.7-1.5z","eyes":[[55.5,65.3,8.4,22.1,-10],[74.2,58.3,8.4,22.1,-10]]},"pebbles":{"label":null,"body":"M47.3 4.5l2.7-.4 2.7 .1 13.7 3 4.3 2.1 3.3 3.4 1.3 2.2 1 2.8 2 12-.5 4.3-3.1 7.7 .2 .5 8.4 1.9 2.7 1 3.3 2.1 2.7 2.8 2.4 4.3 1.4 6.5 .1 4.4-.8 3.8-1.3 2.7-2 2.8-2.4 2.2-2.7 1.6-45.5 17-3.3 .6-3.2-.2-19.2-4.2-4.9-2.8-3.4-3.8-1.9-4.4-1.3-7.7 .2-3.2 .8-2.8 1.3-2.7 2-2.7 3.2-2.8 7.9-3.8 2.5-2.2-.4-1.6-5.4-6.1-1.8-3.8-2.3-12.5 .2-3.3 .7-2.7 2.6-4.4 2.2-2 2.2-1.4z","eyes":[[51.2,34.1,6.9,18.1,-10],[66.4,28.4,6.9,18.1,-10]]},"plus":{"label":null,"body":"M44.6 4.3l3.3-.1 11.9 2.5 2.5 1.3 1.3 1.4 .7 1.6 2.1 11.4 4.1-1.2 2.1 0 12.3 2.6 2.8 1.6 1.2 1.5 .7 1.5 3.8 21.6-.5 3.1-1 1.5-1.3 1.3-17 6.6 3.4 20.4-.4 2.5-1.2 2.1-2.3 1.6-19 6.9-2-.2-11.9-2.5-2.5-1.3-1.3-1.4-.7-1.6-2.1-11.4-4.1 1.2-2.1 0-12.3-2.6-2.8-1.6-1.2-1.5-.7-1.5-3.8-21.6 .5-3.1 1-1.5 1.3-1.3 17-6.6-3.4-20.4 .2-2 1.1-2.2 2.6-2z","eyes":[[54.5,53.1,6.1,15.9,-10],[64.5,49.4,6.1,15.9,-10]]},"magnet":{"label":null,"body":"M71.9 4.2l1.2-.2 12.1 2.6 .5 .3 .6 1 6.2 35.6 .6 5.8-.1 5.7-.7 5.8-1.5 5.7-2.2 5.8-4.2 7.3-5.5 6.5-6.5 5-7.1 3.4-6.3 1.3-6.3 0-15.2-3.1-5.2-1.8-5.2-3-4.6-4.1-4-5.2-2.9-5.8-2.4-7.8-6.4-36.2 25-9.5 13.1 2.9 .5 .9 6.3 35.3 1.8-3.9 .5-4.7-6.3-36.1 .4-.6z","eyes":[[59.6,82.1,6.1,15.9,-10],[72,77.5,6.1,15.9,-10]]},"ring":{"label":null,"body":"M48.1 4.3l8-.1 7.8 1.8 7.3 3.5 6.7 5.4 5.2 6.7 4.1 8.3 2.3 8.9 .7 9-1 9.5-2.5 8.9-4.1 8.3-5.3 7.3-6.6 6.1-7.3 4.5-7.8 2.7-8.4 .9-7.2-.8-7.3-2.5-6.7-4.1-5.6-5.3-4.5-6.5-3.5-7.8-2-8.4-.6-8.4 .9-8.9 2.2-8.4 3.5-7.8 4.9-7.2 5.8-6.1 6.3-4.5 7.1-3.3zM50.5 33.8l2.3-.3 1.7 .4 1.6 1.1 2 2.2 1.3 2.8 .8 2.7 .4 3.4-.1 3.3-1.4 6.2-3 5.6-2.2 2.4-2.2 1.6-2.3 1-2.2 .3-1.7-.4-1.6-1.1-2.8-3.7-1.5-5.2-.1-5.5 1.2-5.6 2.4-5 3.6-4z","eyes":[[56.2,84.6,5.3,13.3,-6.8],[71.7,78.8,5.1,13.4,-6.5]]},"gem":{"label":null,"body":"M57 9.3l2.9-.4 14.9 3.5 19.6 14.1 1 1.4 .6 1.6-.5 2.6-27.1 56.5-1.6 1.8-2.1 .7-15.9-3.4-42.9-30.7-1.3-1.6-.6-1.6 .5-2.6 12-25.2 1.1-1.5 1.5-1z","eyes":[[51.4,42.9,6.7,17.7,-10],[66.1,37.4,6.7,17.7,-10]]}}
75
+ const GRADIENTS = {"aurora":[[0,"#A4FFB0"],[0.42,"#00F0E4"],[1,"#2E9EF7"]]}
76
+
77
+
78
+ const boardViewModule = (function () {
79
+ // Starboard 角色渲染与画布样式。由 .build-client.cjs 内联;不能有 import/export。
80
+
81
+ function characterMarkupOf(shapeId, size) {
82
+ const id = characterShapeId(shapeId)
83
+ const def = id ? CHARACTERS[id] : null
84
+ if (!def || !def.body) return null
85
+ const scale = size / 100
86
+ return { id, def, scale }
87
+ }
88
+
89
+ function characterShapeId(value) {
90
+ const raw = String(value || '')
91
+ const alias = {
92
+ zed: 'bear', wave: 'octopus', hex: 'bloom', cushion: 'squircle',
93
+ dolphin: 'whale', turtle: 'acorn', crab: 'octopus', puffer: 'cloud',
94
+ jelly: 'octopus', starfish: 'star', seahorse: 'whale',
95
+ }
96
+ const id = alias[raw] || raw
97
+ return Object.prototype.hasOwnProperty.call(CHARACTERS, id) ? id : null
98
+ }
99
+
100
+ // DS Bot 原生 Bot 色映射成角色渐变。UI chrome 不使用这些颜色,身份色只留在角色上。
101
+ const BOT_GRADIENTS = {
102
+ deepseek: [[0, '#7c8cf8'], [1, '#4d5df5']],
103
+ blue: [[0, '#63b3ff'], [1, '#2f80ed']],
104
+ violet: [[0, '#c08cff'], [1, '#7c4dff']],
105
+ orange: [[0, '#ffb36b'], [1, '#f2803c']],
106
+ green: [[0, '#6fe0a8'], [1, '#2fae74']],
107
+ magenta: [[0, '#ff8cc6'], [1, '#d4408f']],
108
+ cyan: [[0, '#6fd8e8'], [1, '#2b93a8']],
109
+ red: [[0, '#ff8f8f'], [1, '#d64545']],
110
+ yellow: [[0, '#ffd76b'], [1, '#d9a021']],
111
+ brown: [[0, '#c9a27a'], [1, '#8b6a45']],
112
+ gray: [[0, '#b6bfcc'], [1, '#7d8794']],
113
+ black: [[0, '#5a626e'], [1, '#2b3038']],
114
+ aurora: [[0, '#A4FFB0'], [0.42, '#00F0E4'], [1, '#2E9EF7']],
115
+ rose: [[0, '#ffa8c0'], [1, '#d95477']],
116
+ sky: [[0, '#9ccfff'], [1, '#4f9bd9']],
117
+ tangerine: [[0, '#ffc078'], [1, '#ef8a2b']],
118
+ cobalt: [[0, '#8fa8ff'], [1, '#3f5ed6']],
119
+ charcoal: [[0, '#767d88'], [1, '#3b4048']],
120
+ graphite: [[0, '#8a9099'], [1, '#4c525b']],
121
+ }
122
+
123
+ function gradientOf(color, seed) {
124
+ const key = String(color || '')
125
+ if (BOT_GRADIENTS[key]) return BOT_GRADIENTS[key]
126
+ if (GRADIENTS[key]) return GRADIENTS[key]
127
+ if (/^#[0-9a-f]{6}$/i.test(key)) return [[0, key], [1, shadeHex(key, -0.35)]]
128
+ let hash = 0
129
+ const text = String(seed || key || 'x')
130
+ for (let i = 0; i < text.length; i++) hash = (hash * 31 + text.charCodeAt(i)) >>> 0
131
+ const hue = hash % 360
132
+ return [[0, 'hsl(' + hue + ' 62% 62%)'], [1, 'hsl(' + ((hue + 28) % 360) + ' 58% 44%)']]
133
+ }
134
+
135
+ function shadeHex(hex, amount) {
136
+ const value = parseInt(String(hex).slice(1), 16)
137
+ const clampByte = (channel) => Math.max(0, Math.min(255, Math.round(channel)))
138
+ const red = clampByte(((value >> 16) & 255) * (1 + amount))
139
+ const green = clampByte(((value >> 8) & 255) * (1 + amount))
140
+ const blue = clampByte((value & 255) * (1 + amount))
141
+ return '#' + ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).slice(1)
142
+ }
143
+
144
+ // ── 与 ds-bot 宿主逐字一致的默认头像派生 ────────────────────────────────
145
+ // 宿主 lookOf(bot):bot 没配 avatar.shape / color 时,按 bot.id 做 FNV-1a 哈希派生角色与颜色。
146
+ // 看板以前自己按名字派生 + localStorage 注册表避让,导致同一个 bot 在宿主列表和看板里长成两只,
147
+ // 所以这里必须照抄宿主算法(常量与 ds-bot/client.js 的 DEFAULT_SHAPES / DEFAULT_COLORS 对齐)。
148
+ // DEFAULT_COLORS = CHARACTER_COLORS 去掉 black/gray/brown,再去掉 GRADIENTS 里有的 aurora。
149
+ const HOST_DEFAULT_SHAPES = ['star', 'moon', 'cloud', 'octopus', 'spark', 'bear', 'puppy', 'sprout', 'bloom', 'squircle', 'gumdrop', 'peanut', 'bunny', 'kitty', 'acorn']
150
+ const HOST_FALLBACK_SHAPE = 'gumdrop'
151
+ const HOST_DEFAULT_COLORS = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'violet', 'magenta']
152
+
153
+ function hostFnv1a(text) {
154
+ let value = 2166136261
155
+ for (let index = 0; index < text.length; index += 1) value = Math.imul(value ^ text.charCodeAt(index), 16777619)
156
+ return value >>> 0
157
+ }
158
+
159
+ function hostDefaultColor(id) {
160
+ const seed = hostFnv1a(id) + 1831565813 | 0
161
+ let mixed = Math.imul(seed ^ seed >>> 15, 1 | seed)
162
+ mixed = mixed + Math.imul(mixed ^ mixed >>> 7, 61 | mixed) ^ mixed
163
+ return HOST_DEFAULT_COLORS[Math.floor(((mixed ^ mixed >>> 14) >>> 0) / 4294967296 * HOST_DEFAULT_COLORS.length)]
164
+ }
165
+
166
+ function hostDefaultShape(id) {
167
+ let value = hostFnv1a(id) | 0
168
+ value = Math.imul(value ^ value >>> 16, 73244475)
169
+ value = Math.imul(value ^ value >>> 13, 3266489909)
170
+ return HOST_DEFAULT_SHAPES[((value ^ value >>> 16) >>> 0) % HOST_DEFAULT_SHAPES.length]
171
+ }
172
+
173
+ function hostIsColor(color) {
174
+ const key = String(color || '')
175
+ return /^#[0-9a-f]{6}$/i.test(key)
176
+ || Object.prototype.hasOwnProperty.call(BOT_GRADIENTS, key)
177
+ || Object.prototype.hasOwnProperty.call(GRADIENTS, key)
178
+ }
179
+
180
+ // 宿主 lookOf(bot) 的等价实现:shape / color / image 三件套,看板任何地方画 bot 都走它。
181
+ function hostLookOf(bot) {
182
+ const avatar = (bot && bot.avatar) || {}
183
+ const stored = characterShapeId(avatar.shape)
184
+ return {
185
+ shape: stored || (bot && bot.id ? hostDefaultShape(String(bot.id)) : HOST_FALLBACK_SHAPE),
186
+ image: typeof avatar.image === 'string' && avatar.image.length > 0 ? avatar.image : null,
187
+ color: hostIsColor(bot && bot.color) ? bot.color : (bot && bot.id ? hostDefaultColor(String(bot.id)) : 'black'),
188
+ }
189
+ }
190
+
191
+ function renderCharacter(h, opts) {
192
+ const { def, id, r, color, uid, status, reducedMotion, active, seed, blinkDelay, nodeKey, simple } = opts
193
+ const identity = String(nodeKey || seed || id).replace(/[^a-z0-9]/gi, '')
194
+ const gradId = uid + '-cg-' + id + '-' + identity
195
+ const maskId = uid + '-cm-' + id + '-' + identity
196
+ const stops = gradientOf(color, seed)
197
+ const scale = (r * 2) / 100
198
+ const canBlink = !reducedMotion
199
+ const group = {
200
+ 'aria-hidden': 'true',
201
+ // Starboard里角色放大到 29–57px,曲线要抗锯齿才干净(旧像素风的 crispEdges 会出锯齿)
202
+ shapeRendering: 'geometricPrecision',
203
+ transform: 'translate(' + (-r) + ' ' + (-r) + ') scale(' + scale + ')',
204
+ }
205
+ const eyes = def.eyes
206
+ ? h('g', { fill: '#0b1220' }, def.eyes.map(([cx, cy, width, height, tilt], index) => h('g', {
207
+ key: index,
208
+ transform: 'translate(' + cx + ' ' + cy + ') rotate(' + tilt + ')',
209
+ }, h('g', {
210
+ className: canBlink ? 'dsb-eye-blink' : undefined,
211
+ style: canBlink ? { animationDelay: (blinkDelay == null ? -index * 0.37 : blinkDelay) + 's' } : undefined,
212
+ }, h('rect', { x: -width / 2, y: -height / 2, width, height, rx: width / 2 })))))
213
+ : null
214
+
215
+ // 极简模式(待机坞 18px):纯色身体 + 眼睛,不建渐变与遮罩。
216
+ // 宿主里 url(#id) 引用偶发失效时,渐变身体会整块不画、只剩眼睛;小尺寸下纯色看不出差别。
217
+ if (simple) {
218
+ return h('g', group,
219
+ h('path', { d: def.body, fill: stops[0][1] }),
220
+ eyes)
221
+ }
222
+
223
+ return h('g', group,
224
+ h('defs', null,
225
+ h('linearGradient', {
226
+ id: gradId, gradientUnits: 'userSpaceOnUse', x1: 18, y1: 10, x2: 78, y2: 92,
227
+ }, stops.map(([offset, value], index) => h('stop', { key: index, offset, stopColor: value }))),
228
+ h('mask', {
229
+ id: maskId, maskUnits: 'userSpaceOnUse', x: 0, y: 0, width: 100, height: 100,
230
+ }, h('path', { d: def.body, fill: '#fff' }))),
231
+ h('g', { mask: 'url(#' + maskId + ')' },
232
+ h('path', { d: def.body, fill: 'url(#' + gradId + ')' }),
233
+ (def.paints || []).map((paint, index) => Array.isArray(paint)
234
+ ? h('path', {
235
+ key: 'p' + index, d: paint[0], fill: paint[1] || '#fff',
236
+ opacity: typeof paint[2] === 'number' ? paint[2] : 1,
237
+ })
238
+ : null),
239
+ def.shade ? h('path', { d: def.shade, fill: '#000', opacity: 0.14 }) : null,
240
+ def.light ? h('path', { d: def.light, fill: '#fff', opacity: 0.5 }) : null),
241
+ eyes)
242
+ }
243
+
244
+ // 角色眨眼动效的 CSS 由 board-view.js 的 hiveStyleText() 提供(.dsb-eye-blink)。
245
+
246
+ // Starboard · 星轨蜂巢视图。由 .build-client.cjs 内联;不能有 import/export。
247
+ // 宿主只提供 React.createElement,所以整份视图用 h() 手写,不依赖 JSX。
248
+ //
249
+ // 关系 edgesOf 最后一条真实消息的 @ = 派活;synthetic = 等待
250
+ // 布局 layoutHive 主控居中,其余绕椭圆星轨;环上放不下时自动缩小舱体
251
+ // layoutStrip 主控在左、团队在右一到两排(多任务同屏、纵向不够时)
252
+ // 布线 routeBeam 径向走直线;环上互连走外弧/内弧,避开舱体与名字
253
+ // 渲染 HiveStage / HiveCard / HiveCanvas / HiveHud / HiveTabs / HiveDock / HiveEmpty
254
+
255
+ const HIVE_STATUS_TEXT = { working: '工作中', thinking: '思考中', waiting: '等回执', failed: '失败', user: '你' }
256
+
257
+ // DS Bot 原生 Bot 色 → 身份辉光(rgb 分量,CSS 里用 rgba(var(--dsb-tint), a))
258
+ const HIVE_TINT = {
259
+ deepseek: '124,141,255', blue: '99,179,255', violet: '192,140,255', orange: '255,179,107',
260
+ green: '111,224,168', cyan: '111,216,232', magenta: '255,140,198', rose: '255,168,192',
261
+ tangerine: '255,192,120', sky: '156,207,255', cobalt: '143,168,255', yellow: '255,215,107',
262
+ red: '255,143,143', brown: '201,162,122', charcoal: '150,158,170', graphite: '138,144,153',
263
+ gray: '182,191,204', black: '120,130,145', aurora: '120,240,220',
264
+ }
265
+
266
+ // 三档密度:单任务大舱体、双任务、三个及以上任务同屏
267
+ // beam = 主控到卫星之间「光束」的基准长度。线优先于图标:舞台不够宽时先缩舱体,光束只缩到 BEAM_FLOOR 为止。
268
+ const HIVE_MODES = {
269
+ solo: { pod: 68, coord: 84, name: 38, padT: 18, padB: 22, padX: 40, beam: 72 },
270
+ duo: { pod: 50, coord: 60, name: 34, padT: 12, padB: 16, padX: 32, beam: 52 },
271
+ crowd: { pod: 42, coord: 50, name: 18, padT: 10, padB: 12, padX: 34, beam: 44 },
272
+ }
273
+ const BEAM_FLOOR = 34 // 再窄的面板也至少留这么长一截光束
274
+ const LABEL_MIN_READABLE = 46 // 名字块宽度低于这个值就只剩「DS…」这种残桩,不如整个收起(悬停可看)
275
+
276
+ // 一档密度的「最小舒适宽度」:主控 + 两颗卫星 + 两侧光束 + 左右留白。
277
+ // 舞台比它窄就整体等比收紧(舱体 / 名字块 / 留白一起缩),宽了保持标准尺寸——侧栏拖窄时自动变小。
278
+ function naturalWidthOf(modeKey) {
279
+ const M = HIVE_MODES[modeKey] || HIVE_MODES.duo
280
+ return M.coord + 2 * M.pod + 2 * M.beam + 2 * M.padX
281
+ }
282
+
283
+ function densityOf(modeKey, W) {
284
+ if (!W) return 1
285
+ return Math.max(0.55, Math.min(1, (W - 8) / naturalWidthOf(modeKey)))
286
+ }
287
+
288
+ // 面板宽度 → 外围 chrome(HUD / 页签 / 待机坞 / 卡片圆角)的密度系数,1 = 标准
289
+ function chromeDensityOf(width) {
290
+ if (!width) return 1
291
+ return Math.max(0.7, Math.min(1, width / 460))
292
+ }
293
+
294
+ const HIVE_HEAD_H = 28 // 任务卡头部高度,与 .dsb-task__head 的盒模型一致
295
+ const HIVE_GAP = 12 // 卡片间距
296
+ const HIVE_PAD_X = 12 // 画布左右内边距
297
+ const HIVE_PAD_Y = 16 // 画布上下内边距合计
298
+
299
+ function singleTaskFills(naturalTotal, canvasHeight) {
300
+ return naturalTotal <= canvasHeight - HIVE_PAD_Y + 1
301
+ }
302
+
303
+ function hiveStyleText() {
304
+ return [
305
+ '.dsb-root { position: relative; height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden;',
306
+ ' font-family: var(--dsb-font); color: var(--dsb-text-1); -webkit-font-smoothing: antialiased;',
307
+ ' background: radial-gradient(130% 80% at 50% -10%, var(--dsb-stage-2) 0%, var(--dsb-stage-1) 46%, var(--dsb-stage-0) 100%); }',
308
+ '.dsb-root *, .dsb-root *::before, .dsb-root *::after { box-sizing: border-box; }',
309
+ '.dsb-root::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;',
310
+ ' background-image: radial-gradient(var(--dsb-star) .8px, transparent 1.1px), radial-gradient(var(--dsb-star) .6px, transparent 1px);',
311
+ ' background-size: 58px 58px, 97px 97px; background-position: 0 0, 31px 47px;',
312
+ ' -webkit-mask-image: radial-gradient(120% 90% at 50% 30%, #000 0%, transparent 78%);',
313
+ ' mask-image: radial-gradient(120% 90% at 50% 30%, #000 0%, transparent 78%); }',
314
+
315
+ // ── HUD ──(--dsb-k = 面板密度:侧栏拖窄时外围 chrome 一起收紧)
316
+ '.dsb-hud { position: relative; z-index: 1; flex: 0 0 auto; padding: calc(12px * var(--dsb-k, 1)) calc(14px * var(--dsb-k, 1)) calc(10px * var(--dsb-k, 1)); display: grid;',
317
+ ' grid-template-columns: auto 1fr auto; column-gap: calc(10px * var(--dsb-k, 1)); row-gap: calc(9px * var(--dsb-k, 1)); align-items: center; }',
318
+ '.dsb-hud__brand { width: calc(34px * var(--dsb-k, 1)); height: calc(34px * var(--dsb-k, 1)); border-radius: calc(11px * var(--dsb-k, 1)); display: grid; place-items: center; color: #fff;',
319
+ ' background: linear-gradient(140deg, #6f80ff 0%, #4d6bfe 45%, #2f49d8 100%);',
320
+ ' box-shadow: 0 0 0 1px rgba(255,255,255,.14) inset, 0 8px 22px -8px rgba(77,107,254,.9); }',
321
+ '.dsb-hud__title { display: flex; align-items: center; gap: calc(8px * var(--dsb-k, 1)); font-size: max(12px, calc(15px * var(--dsb-k, 1))); font-weight: 700; letter-spacing: .01em; }',
322
+ '.dsb-hud__live { width: 7px; height: 7px; border-radius: 50%; background: var(--dsb-ok);',
323
+ ' box-shadow: 0 0 0 3px rgba(43,217,138,.18); animation: dsb-pulse 2.4s ease-in-out infinite; }',
324
+ '.dsb-hud__live[data-stale="true"] { background: var(--dsb-wait); box-shadow: 0 0 0 3px rgba(242,184,75,.18); animation: none; }',
325
+ '.dsb-hud__sub { margin-top: 2px; font-size: max(10px, calc(11.5px * var(--dsb-k, 1))); color: var(--dsb-text-3); display: flex; gap: 6px; align-items: center; white-space: nowrap; }',
326
+ '.dsb-hud__sub b { font-family: var(--dsb-mono); font-weight: 600; color: var(--dsb-text-2); }',
327
+ '.dsb-hud__sub .dsb-amber { color: var(--dsb-wait); }',
328
+ '.dsb-hud__actions { display: flex; gap: calc(6px * var(--dsb-k, 1)); }',
329
+ '.dsb-hud__btn { width: calc(30px * var(--dsb-k, 1)); height: calc(30px * var(--dsb-k, 1)); border-radius: calc(9px * var(--dsb-k, 1)); border: 1px solid var(--dsb-hair); padding: 0;',
330
+ ' background: var(--dsb-card); color: var(--dsb-text-2); display: grid; place-items: center; cursor: pointer;',
331
+ ' transition: background-color .15s ease, border-color .15s ease, color .15s ease; }',
332
+ '.dsb-hud__btn:hover { color: var(--dsb-text-1); border-color: var(--dsb-card-border); }',
333
+ '.dsb-hud__btn[data-active="true"] { color: var(--dsb-accent-2); border-color: rgba(124,141,255,.45); background: rgba(77,107,254,.14); }',
334
+ '.dsb-hud__btn:focus-visible, .dsb-tab:focus-visible, .dsb-retry:focus-visible, .dsb-dock__item:focus-visible { outline: 2px solid var(--dsb-accent-2); outline-offset: 2px; }',
335
+ '.dsb-hud__meter { grid-column: 1 / -1; height: 4px; border-radius: 99px; display: flex; gap: 3px; }',
336
+ '.dsb-hud__meter i { display: block; height: 100%; border-radius: 99px; }',
337
+ '.dsb-hud__meter .dsb-m-work { background: linear-gradient(90deg, var(--dsb-accent), var(--dsb-cyan)); box-shadow: 0 0 12px rgba(98,214,255,.45); }',
338
+ '.dsb-hud__meter .dsb-m-wait { background: var(--dsb-wait); }',
339
+ '.dsb-hud__meter .dsb-m-idle { background: var(--dsb-orbit); }',
340
+
341
+ // ── 任务页签 ──
342
+ '.dsb-tabs { position: relative; z-index: 1; flex: 0 0 auto; display: flex; gap: calc(6px * var(--dsb-k, 1)); padding: 0 calc(14px * var(--dsb-k, 1)) calc(10px * var(--dsb-k, 1)); overflow-x: auto; scrollbar-width: none; }',
343
+ '.dsb-tabs::-webkit-scrollbar { display: none; }',
344
+ '.dsb-tab { flex: 0 0 auto; height: calc(26px * var(--dsb-k, 1)); padding: 0 calc(11px * var(--dsb-k, 1)) 0 calc(9px * var(--dsb-k, 1)); border-radius: 99px; display: inline-flex; align-items: center; gap: calc(6px * var(--dsb-k, 1));',
345
+ ' font: inherit; font-size: max(10.5px, calc(11.5px * var(--dsb-k, 1))); font-weight: 600; color: var(--dsb-text-2); background: var(--dsb-card);',
346
+ ' border: 1px solid var(--dsb-hair); white-space: nowrap; cursor: pointer;',
347
+ ' transition: background-color .15s ease, border-color .15s ease, color .15s ease; }',
348
+ '.dsb-tab i { width: 6px; height: 6px; border-radius: 50%; background: rgb(var(--dsb-tint, 124,141,255)); box-shadow: 0 0 8px rgb(var(--dsb-tint, 124,141,255)); }',
349
+ '.dsb-tab:hover { color: var(--dsb-text-1); }',
350
+ '.dsb-tab[aria-pressed="true"] { color: var(--dsb-text-1); background: rgba(77,107,254,.16); border-color: rgba(124,141,255,.5); }',
351
+
352
+ // ── 画布与任务卡 ──
353
+ '.dsb-canvas { position: relative; z-index: 1; flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto;',
354
+ ' padding: 2px 12px 14px; display: grid; grid-template-columns: 1fr; grid-auto-rows: max-content; gap: 12px;',
355
+ ' align-content: start; align-items: stretch; scrollbar-width: thin; scrollbar-color: var(--dsb-scroll) transparent; }',
356
+ '.dsb-canvas[data-cols="2"] { grid-template-columns: 1fr 1fr; }',
357
+ '.dsb-canvas[data-empty="true"] { align-content: center; }',
358
+ '.dsb-canvas[data-center="true"] { align-content: center; }',
359
+ '.dsb-canvas[data-fill="true"] { grid-auto-rows: minmax(0, 1fr); }',
360
+ '.dsb-canvas::-webkit-scrollbar { width: 6px; }',
361
+ '.dsb-canvas::-webkit-scrollbar-thumb { background: var(--dsb-scroll); border-radius: 99px; }',
362
+ '.dsb-canvas::-webkit-scrollbar-track { background: transparent; }',
363
+ '.dsb-task { position: relative; display: flex; flex-direction: column; border-radius: calc(18px * var(--dsb-k, 1)); border: 1px solid var(--dsb-card-border);',
364
+ ' background: var(--dsb-card); box-shadow: var(--dsb-shadow-card), inset 0 1px 0 var(--dsb-card-hi); overflow: hidden; }',
365
+ '.dsb-task::before { content: ""; position: absolute; inset: 0; pointer-events: none;',
366
+ ' background: radial-gradient(120% 90% at 50% -20%, rgba(var(--dsb-card-tint, 124,141,255), .22), transparent 62%); }',
367
+ '.dsb-task__head { position: relative; display: flex; align-items: center; gap: calc(8px * var(--dsb-k, 1)); padding: calc(10px * var(--dsb-k, 1)) calc(12px * var(--dsb-k, 1)) 0; height: 28px; flex: 0 0 auto; }',
368
+ '.dsb-task__dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: rgb(var(--dsb-card-tint, 124,141,255));',
369
+ ' box-shadow: 0 0 10px rgb(var(--dsb-card-tint, 124,141,255)); }',
370
+ '.dsb-task__name { font-size: max(11px, calc(12.5px * var(--dsb-k, 1))); font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }',
371
+ '.dsb-task__stats { margin-left: auto; font-size: max(10px, calc(11px * var(--dsb-k, 1))); color: var(--dsb-text-3); display: flex; gap: 6px; align-items: center; white-space: nowrap; flex: 0 0 auto; }',
372
+ '.dsb-task__stats b { font-family: var(--dsb-mono); font-weight: 600; color: var(--dsb-text-2); }',
373
+ '.dsb-task__stats .dsb-amber { color: var(--dsb-wait); }',
374
+ '.dsb-stage { position: relative; flex: 1 1 auto; min-height: 0; }',
375
+ '.dsb-beams { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }',
376
+ '.dsb-orbit { fill: none; stroke: var(--dsb-orbit); stroke-width: 1; stroke-dasharray: 2 7; stroke-linecap: round; }',
377
+
378
+ // ── 角色舱(玻璃舱) ──
379
+ // .dsb-pod 的原点 = 舱体圆心;名字块绝对定位在圆心下方或上方,光束端点才能对准。
380
+ '.dsb-pod { position: absolute; width: 0; height: 0; margin: 0; padding: 0; border: 0; background: none;',
381
+ ' font: inherit; color: inherit; text-align: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }',
382
+ '.dsb-pod--static { cursor: default; }',
383
+ '.dsb-pod:focus { outline: none; }',
384
+ '.dsb-pod:focus-visible .dsb-pod__body { box-shadow: 0 0 0 2px var(--dsb-accent-2), var(--dsb-pod-shadow); }',
385
+ '.dsb-pod:hover .dsb-pod__body { filter: brightness(1.08); }',
386
+ '.dsb-pod__glow { position: absolute; top: calc(var(--dsb-pod) / -2 - 10px); left: calc(var(--dsb-pod) / -2 - 10px);',
387
+ ' width: calc(var(--dsb-pod) + 20px); height: calc(var(--dsb-pod) + 20px); border-radius: 50%; pointer-events: none;',
388
+ ' background: radial-gradient(circle, rgba(var(--dsb-tint), .34) 0%, rgba(var(--dsb-tint), .10) 44%, transparent 70%); }',
389
+ '.dsb-pod__body { position: absolute; top: calc(var(--dsb-pod) / -2); left: calc(var(--dsb-pod) / -2); width: var(--dsb-pod); height: var(--dsb-pod);',
390
+ ' border-radius: 50%; display: grid; place-items: center; background: var(--dsb-pod-bg); box-shadow: var(--dsb-pod-shadow);',
391
+ ' transition: filter .15s ease; }',
392
+ '.dsb-pod__body::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 1px solid var(--dsb-pod-ring); pointer-events: none; }',
393
+ '.dsb-pod__char { position: relative; display: grid; place-items: center; filter: drop-shadow(0 3px 6px rgba(0,0,0,.45));',
394
+ ' animation: dsb-ava-work 2.4s ease-in-out infinite; animation-delay: var(--dsb-ava-delay, 0s); }',
395
+ // 头像动效:按状态换动作,幅度都压得很小,别抢光束的戏
396
+ '.dsb-pod--thinking .dsb-pod__char { animation: dsb-ava-think 3.4s ease-in-out infinite; }',
397
+ '.dsb-pod--waiting .dsb-pod__char { animation: dsb-ava-breathe 2.2s ease-in-out infinite; }',
398
+ '.dsb-pod--failed .dsb-pod__char { animation: dsb-ava-shake 6s ease-in-out infinite; }',
399
+ '.dsb-pod--user .dsb-pod__char { animation: none; }',
400
+ '.dsb-pod__char img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }',
401
+ '.dsb-pod__user { display: grid; place-items: center; color: var(--dsb-text-2); }',
402
+ '.dsb-pod__letter { font-size: 12px; font-weight: 700; color: var(--dsb-text-2); }',
403
+ '.dsb-pod__ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); pointer-events: none; overflow: visible; }',
404
+ '.dsb-pod__ring circle { fill: none; stroke-width: 2; }',
405
+ '.dsb-pod__ring .dsb-halo, .dsb-pod__ring .dsb-tick { opacity: 0; }',
406
+ '.dsb-pod__ring .dsb-gold { stroke: #f2c96b; stroke-width: 1.3; opacity: .9; }',
407
+ '.dsb-pod--working .dsb-pod__ring .dsb-arc { stroke: var(--dsb-accent-2); stroke-linecap: round; stroke-dasharray: 34 96; transform-origin: 50% 50%; animation: dsb-spin 2.6s linear infinite; }',
408
+ '.dsb-pod--thinking .dsb-pod__ring .dsb-arc { stroke: var(--dsb-cyan); stroke-linecap: round; stroke-dasharray: 12 20; transform-origin: 50% 50%; animation: dsb-spin 3.4s linear infinite; }',
409
+ '.dsb-pod--waiting .dsb-pod__ring .dsb-arc { stroke: var(--dsb-wait); stroke-linecap: round; stroke-dasharray: 5 7; transform-origin: 50% 50%; animation: dsb-breathe 2.2s ease-in-out infinite; }',
410
+ '.dsb-pod--failed .dsb-pod__ring .dsb-arc { stroke: var(--dsb-fail); stroke-linecap: round; stroke-dasharray: 96 0; }',
411
+ '.dsb-pod--user .dsb-pod__ring .dsb-arc { stroke: var(--dsb-text-3); stroke-linecap: round; stroke-dasharray: 2 6; }',
412
+ '.dsb-pod__pulse { position: absolute; top: calc(var(--dsb-pod) / -2 - 5px); left: calc(var(--dsb-pod) / -2 - 5px);',
413
+ ' width: calc(var(--dsb-pod) + 10px); height: calc(var(--dsb-pod) + 10px); border-radius: 50%; border: 1.5px solid var(--dsb-wait);',
414
+ ' opacity: 0; animation: dsb-ripple 2.2s ease-out infinite; pointer-events: none; }',
415
+ // 标签宽度由布局算好(--dsb-label-w),不用 max-content:标签绝对定位在 0 宽的舱体里,
416
+ // 内在尺寸在宿主里会被算成随机宽度(出现过「Software En…」这种误截断)。
417
+ // 名字块字号固定 12px / 10.5px:窄面板里只缩舱体与留白,字号再小会截断且难读
418
+ '.dsb-pod__label { position: absolute; left: 0; top: calc(var(--dsb-pod) / 2 + 7px); transform: translateX(calc(-50% + var(--dsb-shift, 0px)));',
419
+ ' display: flex; flex-direction: column; align-items: center; pointer-events: none; width: var(--dsb-label-w, max-content); }',
420
+ '.dsb-pod--up .dsb-pod__label { top: auto; bottom: calc(var(--dsb-pod) / 2 + 7px); flex-direction: column-reverse; }',
421
+ '.dsb-pod__name { font-size: 12px; font-weight: 650; line-height: 1.15; text-align: center; max-width: var(--dsb-name-max, 112px); overflow: hidden;',
422
+ ' text-shadow: var(--dsb-name-shadow); white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 5px; width: 100%; }',
423
+ '.dsb-pod__name > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }',
424
+ '.dsb-pod--coord .dsb-pod__name { max-width: 156px; }',
425
+ '.dsb-pod__meta { margin-top: 2px; font-size: 10.5px; line-height: 1.1; color: var(--dsb-text-3); display: flex; align-items: center; gap: 4px; white-space: nowrap; }',
426
+ '.dsb-pod--up .dsb-pod__meta { margin-top: 0; margin-bottom: 2px; }',
427
+ '.dsb-pod__meta i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }',
428
+ '.dsb-pod--working .dsb-pod__meta { color: var(--dsb-accent-2); }',
429
+ '.dsb-pod--thinking .dsb-pod__meta { color: var(--dsb-cyan); }',
430
+ '.dsb-pod--waiting .dsb-pod__meta { color: var(--dsb-wait); }',
431
+ '.dsb-pod--failed .dsb-pod__meta { color: var(--dsb-fail); }',
432
+ '.dsb-pod__crown { flex: 0 0 auto; height: 13px; padding: 0 5px; border-radius: 99px;',
433
+ ' font-size: 9px; font-weight: 700; letter-spacing: .04em; display: inline-flex; align-items: center; color: #0b1020; white-space: nowrap;',
434
+ ' text-shadow: none; background: linear-gradient(180deg, #ffe9a8, #f2b84b); box-shadow: 0 3px 8px -4px rgba(242,184,75,.8); }',
435
+ '.dsb-pod--user .dsb-pod__name { color: var(--dsb-text-2); }',
436
+ '.dsb-pod--user .dsb-pod__body { background: radial-gradient(circle at 50% 28%, rgba(255,255,255,.12), rgba(255,255,255,.03) 70%); }',
437
+
438
+ // 紧凑模式(多任务同屏):只留名字,状态靠环与色
439
+ '.dsb-task[data-mode="crowd"] .dsb-pod__label { top: calc(var(--dsb-pod) / 2 + 5px); }',
440
+ '.dsb-task[data-mode="crowd"] .dsb-pod--up .dsb-pod__label { top: auto; bottom: calc(var(--dsb-pod) / 2 + 5px); }',
441
+ '.dsb-task[data-mode="crowd"] .dsb-pod__name { font-size: 11px; }',
442
+ '.dsb-task[data-mode="crowd"] .dsb-pod__meta { display: none; }',
443
+ '.dsb-task[data-mode="crowd"] .dsb-pod__crown { height: 12px; font-size: 8.5px; padding: 0 4px; }',
444
+
445
+ // 传送带模式(多任务同屏且纵向不够):只留名字,名字过长省略
446
+ '.dsb-task[data-mode="strip"] .dsb-pod__label { top: calc(var(--dsb-pod) / 2 + 5px); }',
447
+ '.dsb-task[data-mode="strip"] .dsb-pod--up .dsb-pod__label { top: auto; bottom: calc(var(--dsb-pod) / 2 + 5px); }',
448
+ '.dsb-task[data-mode="strip"] .dsb-pod__meta { display: none; }',
449
+ '.dsb-task[data-mode="strip"] .dsb-pod__name { font-size: 11px; }',
450
+ '.dsb-task[data-mode="strip"] .dsb-pod__name > span:last-child { display: inline-block; max-width: var(--dsb-name-max, 74px); overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }',
451
+ '.dsb-root .dsb-pod__name > span:last-child { max-width: var(--dsb-name-max, 112px); }',
452
+ '.dsb-task[data-mode="strip"] .dsb-pod__crown { height: 12px; font-size: 8.5px; padding: 0 4px; }',
453
+
454
+ // ── 待机坞 ──(格子与头像跟着面板密度缩,窄侧栏里不再是一排 30px 大圆)
455
+ '.dsb-dock { position: relative; z-index: 1; flex: 0 0 auto; margin: 0 calc(12px * var(--dsb-k, 1)) calc(12px * var(--dsb-k, 1)); padding: calc(8px * var(--dsb-k, 1)) calc(10px * var(--dsb-k, 1)) calc(9px * var(--dsb-k, 1)); border-radius: calc(14px * var(--dsb-k, 1));',
456
+ ' background: var(--dsb-dock); border: 1px solid var(--dsb-hair); backdrop-filter: blur(8px); box-shadow: inset 0 1px 0 var(--dsb-card-hi); }',
457
+ '.dsb-dock__head { display: flex; align-items: center; gap: 6px; font-size: max(9.5px, calc(10.5px * var(--dsb-k, 1))); font-weight: 650; color: var(--dsb-text-3); letter-spacing: .06em; }',
458
+ '.dsb-dock__head b { font-family: var(--dsb-mono); color: var(--dsb-text-2); }',
459
+ '.dsb-dock__row { margin-top: calc(7px * var(--dsb-k, 1)); display: flex; gap: calc(7px * var(--dsb-k, 1)); flex-wrap: wrap; }',
460
+ '.dsb-dock__item { position: relative; width: calc(30px * var(--dsb-k, 1)); height: calc(30px * var(--dsb-k, 1)); padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center;',
461
+ ' background: var(--dsb-pod-bg); box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 0 0 1px var(--dsb-pod-ring); opacity: .62; cursor: pointer;',
462
+ ' animation: dsb-float 5.6s ease-in-out infinite; transition: opacity .15s ease, transform .15s ease; }',
463
+ '.dsb-dock__item:nth-child(2n) { animation-delay: -1.7s; }',
464
+ '.dsb-dock__item:nth-child(3n) { animation-delay: -3.1s; }',
465
+ '.dsb-dock__item:hover { opacity: 1; }',
466
+ // 头像要显式给尺寸:宿主里有 button > svg 之类的全局规则会把只带 width/height 属性的 svg 压成几像素
467
+ '.dsb-dock__glyph { display: grid; place-items: center; width: calc(20px * var(--dsb-k, 1)); height: calc(20px * var(--dsb-k, 1)); flex: 0 0 auto;',
468
+ ' animation: dsb-ava-idle 4.2s ease-in-out infinite; }',
469
+ '.dsb-dock__glyph > svg { display: block; width: calc(18px * var(--dsb-k, 1)); height: calc(18px * var(--dsb-k, 1)); flex: 0 0 auto; }',
470
+ '.dsb-dock__item:nth-child(2n) .dsb-dock__glyph { animation-delay: -1.4s; }',
471
+ '.dsb-dock__item:nth-child(3n) .dsb-dock__glyph { animation-delay: -2.8s; }',
472
+ '.dsb-dock__item:nth-child(5n) .dsb-dock__glyph { animation-delay: -3.6s; }',
473
+ '.dsb-dock__letter { font-size: 11px; font-weight: 700; color: var(--dsb-text-2); }',
474
+
475
+ // ── 空状态 ──
476
+ '.dsb-empty { grid-column: 1 / -1; position: relative; display: grid; place-items: center; text-align: center; padding: 40px 20px; min-height: 260px; }',
477
+ '.dsb-empty__orbit { position: absolute; width: 220px; height: 220px; border-radius: 50%; border: 1px dashed var(--dsb-orbit); animation: dsb-spin 40s linear infinite; }',
478
+ '.dsb-empty__orbit::after { content: ""; position: absolute; top: -4px; left: 50%; width: 8px; height: 8px; border-radius: 50%;',
479
+ ' background: var(--dsb-accent-2); box-shadow: 0 0 12px var(--dsb-accent-2); }',
480
+ '.dsb-empty__core { position: relative; margin: 0 auto; width: 54px; height: 54px; border-radius: 50%; background: var(--dsb-pod-bg);',
481
+ ' box-shadow: var(--dsb-pod-shadow); display: grid; place-items: center; color: var(--dsb-text-3); }',
482
+ '.dsb-empty__title { position: relative; margin-top: 16px; font-size: 13.5px; font-weight: 650; color: var(--dsb-text-2); }',
483
+ '.dsb-empty__sub { position: relative; margin-top: 6px; font-size: 11.5px; color: var(--dsb-text-3); }',
484
+
485
+ // ── 局部提示 / 骨架 / 错误 ──
486
+ '.dsb-banner { position: relative; z-index: 1; flex: 0 0 auto; display: flex; align-items: center; gap: 6px; margin: 0 calc(12px * var(--dsb-k, 1)) calc(8px * var(--dsb-k, 1)); padding: 6px 10px;',
487
+ ' border-radius: 10px; border: 1px solid rgba(242,184,75,.28); background: rgba(242,184,75,.10); color: var(--dsb-wait); font-size: 11px; }',
488
+ '.dsb-skeleton { position: relative; z-index: 1; flex: 1 1 auto; min-height: 0; padding: 16px; display: flex; flex-direction: column; gap: 12px; }',
489
+ '.dsb-skeleton__row, .dsb-skeleton__dot { background: linear-gradient(100deg, var(--dsb-card) 20%, var(--dsb-card-hi) 45%, var(--dsb-card) 70%);',
490
+ ' background-size: 220% 100%; animation: dsb-skeleton-flow 1.4s ease-in-out infinite; border-radius: 10px; }',
491
+ '.dsb-skeleton__stage { position: relative; flex: 1 1 auto; min-height: 180px; }',
492
+ '.dsb-skeleton__dot { position: absolute; border-radius: 50%; }',
493
+ '.dsb-error { position: relative; z-index: 1; flex: 1 1 auto; min-height: 0; display: grid; place-items: center; padding: 24px; }',
494
+ '.dsb-error__box { max-width: 280px; text-align: center; }',
495
+ '.dsb-error__icon { display: flex; justify-content: center; color: var(--dsb-fail); margin-bottom: 12px; }',
496
+ '.dsb-error__title { font-size: 12.5px; font-weight: 650; margin-bottom: 4px; }',
497
+ '.dsb-error__msg { font-size: 11px; line-height: 1.7; color: var(--dsb-text-2); font-family: var(--dsb-mono); word-break: break-word; }',
498
+ '.dsb-retry { margin-top: 16px; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;',
499
+ ' border: 1px solid var(--dsb-card-border); background: var(--dsb-card); color: var(--dsb-text-1); font: inherit; font-size: 11px; cursor: pointer; }',
500
+ '.dsb-retry:hover { border-color: var(--dsb-accent-2); }',
501
+
502
+ '@keyframes dsb-pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }',
503
+ '@keyframes dsb-spin { to { transform: rotate(360deg) } }',
504
+ '@keyframes dsb-breathe { 0%,100% { opacity: 1 } 50% { opacity: .45 } }',
505
+ '@keyframes dsb-ripple { 0% { transform: scale(1); opacity: .55 } 100% { transform: scale(1.34); opacity: 0 } }',
506
+ '@keyframes dsb-float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-1.5px) } }',
507
+ '@keyframes dsb-skeleton-flow { from { background-position: 120% 0 } to { background-position: -120% 0 } }',
508
+ '@keyframes dsb-eye-blink { 0%,90%,100% { transform: scaleY(1) } 95% { transform: scaleY(.08) } }',
509
+ '.dsb-root .dsb-eye-blink { transform-box: fill-box; transform-origin: center; animation: dsb-eye-blink 4.6s ease-in-out infinite; }',
510
+ // 头像动效:干活=点头、思考=歪头晃、等待=呼吸、失败=偶尔抖一下、待命=慢呼吸
511
+ '@keyframes dsb-ava-work { 0%,100% { transform: translateY(0) rotate(0deg) } 30% { transform: translateY(-1.6px) rotate(-2.5deg) } 65% { transform: translateY(-.6px) rotate(2deg) } }',
512
+ '@keyframes dsb-ava-think { 0%,100% { transform: rotate(-5deg) translateY(0) } 50% { transform: rotate(5deg) translateY(-1px) } }',
513
+ '@keyframes dsb-ava-breathe { 0%,100% { transform: scale(1) } 50% { transform: scale(1.07) } }',
514
+ '@keyframes dsb-ava-shake { 0%,84%,100% { transform: translateX(0) } 88% { transform: translateX(-2px) } 92% { transform: translateX(2px) } 96% { transform: translateX(-1px) } }',
515
+ '@keyframes dsb-ava-idle { 0%,100% { transform: scale(1) } 50% { transform: scale(1.08) } }',
516
+
517
+ // 动效开关与系统 reduced-motion:CSS 动画全部停掉(SMIL 由组件按 motion 开关决定是否渲染)
518
+ '.dsb-motion-off .dsb-pod__ring .dsb-arc, .dsb-motion-off .dsb-pod__pulse, .dsb-motion-off .dsb-hud__live,',
519
+ '.dsb-motion-off .dsb-dock__item, .dsb-motion-off .dsb-empty__orbit, .dsb-motion-off .dsb-skeleton__row,',
520
+ '.dsb-motion-off .dsb-skeleton__dot, .dsb-motion-off .dsb-eye-blink,',
521
+ '.dsb-motion-off .dsb-pod__char, .dsb-motion-off .dsb-dock__glyph { animation: none !important; }',
522
+ '.dsb-motion-off .dsb-skeleton__row, .dsb-motion-off .dsb-skeleton__dot { background: var(--dsb-card); }',
523
+ '@media (prefers-reduced-motion: reduce) {',
524
+ ' .dsb-root .dsb-pod__ring .dsb-arc, .dsb-root .dsb-pod__pulse, .dsb-root .dsb-hud__live, .dsb-root .dsb-dock__item,',
525
+ ' .dsb-root .dsb-empty__orbit, .dsb-root .dsb-skeleton__row, .dsb-root .dsb-skeleton__dot, .dsb-root .dsb-eye-blink,',
526
+ ' .dsb-root .dsb-pod__char, .dsb-root .dsb-dock__glyph { animation: none !important; }',
527
+ ' .dsb-root .dsb-skeleton__row, .dsb-root .dsb-skeleton__dot { background: var(--dsb-card); }',
528
+ '}',
529
+ ].join('\n')
530
+ }
531
+
532
+ function createBoardView(React) {
533
+ const h = React.createElement
534
+ const Fragment = React.Fragment
535
+ const { useState, useLayoutEffect, useMemo, useRef, useEffect } = React
536
+
537
+ const tintOf = (color) => HIVE_TINT[color] || '124,141,255'
538
+
539
+ // ── 关系:最后一条真实消息的 @ = 派活;synthetic = 等待 ──
540
+ function edgesOf(group) {
541
+ const byName = {}
542
+ for (const node of group.nodes) byName[node.name] = node
543
+ const out = []
544
+ const seen = {}
545
+ const waits = group.messages.filter((m) => m.synthetic)
546
+ for (const m of waits) {
547
+ const target = byName[(m.to || [])[0]]
548
+ if (!target || !m.botId) continue
549
+ const key = m.botId + '>' + target.id
550
+ if (seen[key]) continue
551
+ seen[key] = 1
552
+ out.push({ from: m.botId, to: target.id, kind: 'wait' })
553
+ }
554
+ const real = group.messages.filter((m) => !m.synthetic)
555
+ const last = real[real.length - 1]
556
+ if (last) {
557
+ const fromId = last.botId || (last.who === 'User' ? '__user__' : '')
558
+ for (const name of last.to || []) {
559
+ const target = byName[name]
560
+ if (!target || !fromId || target.id === fromId) continue
561
+ const key = fromId + '>' + target.id
562
+ if (seen[key]) continue
563
+ seen[key] = 1
564
+ out.push({ from: fromId, to: target.id, kind: 'cur' })
565
+ }
566
+ }
567
+ return out
568
+ }
569
+
570
+ // ── 布局:主控居中,其余绕椭圆星轨 ──
571
+ // 环上角度:先给等角基准,再按椭圆弧长均匀重排(高瘦椭圆上等角会让上下挤、两侧空)
572
+ function anglesFor(n) {
573
+ if (n <= 0) return []
574
+ if (n === 1) return [0]
575
+ if (n === 2) return [180, 0]
576
+ const out = []
577
+ for (let i = 0; i < n; i++) out.push(-90 + (i * 360) / n)
578
+ return out
579
+ }
580
+
581
+ function evenAngles(rx, ry, n) {
582
+ if (n < 3) return anglesFor(n)
583
+ const STEPS = 360
584
+ const cum = [0]
585
+ let px = rx * Math.cos(-Math.PI / 2)
586
+ let py = ry * Math.sin(-Math.PI / 2)
587
+ for (let i = 1; i <= STEPS; i++) {
588
+ const a = -Math.PI / 2 + (i / STEPS) * 2 * Math.PI
589
+ const x = rx * Math.cos(a)
590
+ const y = ry * Math.sin(a)
591
+ cum.push(cum[i - 1] + Math.hypot(x - px, y - py))
592
+ px = x
593
+ py = y
594
+ }
595
+ const total = cum[STEPS]
596
+ const out = []
597
+ for (let k = 0; k < n; k++) {
598
+ const target = (k / n) * total
599
+ let i = 1
600
+ while (i < STEPS && cum[i] < target) i++
601
+ const span = Math.max(1e-6, cum[i] - cum[i - 1])
602
+ const t = (target - cum[i - 1]) / span
603
+ out.push((-90 + ((i - 1 + t) / STEPS) * 360))
604
+ }
605
+ return out
606
+ }
607
+
608
+ function minSpacing(rx, ry, angles) {
609
+ const n = angles.length
610
+ if (n < 2) return Infinity
611
+ let min = Infinity
612
+ for (let i = 0; i < n; i++) {
613
+ const a = (angles[i] * Math.PI) / 180
614
+ const b = (angles[(i + 1) % n] * Math.PI) / 180
615
+ min = Math.min(min, Math.hypot(rx * (Math.cos(b) - Math.cos(a)), ry * (Math.sin(b) - Math.sin(a))))
616
+ }
617
+ return min
618
+ }
619
+
620
+ // 名字块宽度估算(按 12px 字号算,d = 舞台密度:窄面板里字号一起缩)
621
+ function estimateLabelWidth(node, d) {
622
+ const k = d == null ? 1 : d
623
+ const name = String(node.name || '')
624
+ let w = 0
625
+ for (const ch of name) w += ch.charCodeAt(0) > 0x2e7f ? 12 : 6.7
626
+ if (node.coord) w += 33
627
+ return Math.min(node.coord ? 156 : 112, Math.max(26, w)) * k
628
+ }
629
+
630
+ // 标签避让:名字块不能压到别的舱体、别的名字块或舞台边界。
631
+ // 候选顺序 = 先原位、再向外侧平移、最后翻到舱体另一侧;取冲突最少的一个。
632
+ // lockUp = 传送带两排布局:顶排标签必须在上、底排必须在下,中间留给光束走廊。
633
+ function resolveLabels(pos, nodes, W, H, labelH, gap, center, lockUp, d) {
634
+ const items = []
635
+ for (const node of nodes) {
636
+ const p = pos[node.id]
637
+ if (!p) continue
638
+ items.push({ id: node.id, node, p, hw: Math.min(estimateLabelWidth(node, d), p.labelMax || 999) / 2 })
639
+ }
640
+ const circles = items.map((it) => ({ id: it.id, x: it.p.x, y: it.p.y, r: it.p.pod / 2 }))
641
+ const rectOf = (it, up, shift) => {
642
+ const cx = it.p.x + shift
643
+ const y0 = up ? it.p.y - it.p.pod / 2 - gap - labelH : it.p.y + it.p.pod / 2 + gap
644
+ return { x0: cx - it.hw, x1: cx + it.hw, y0, y1: y0 + labelH }
645
+ }
646
+ const countHits = (rect, selfId, placed) => {
647
+ let hits = 0
648
+ if (rect.x0 < 4 || rect.x1 > W - 4 || rect.y0 < 2 || rect.y1 > H - 2) hits += 2
649
+ for (const c of circles) {
650
+ if (c.id === selfId) continue
651
+ const nx = Math.max(rect.x0, Math.min(c.x, rect.x1))
652
+ const ny = Math.max(rect.y0, Math.min(c.y, rect.y1))
653
+ if (Math.hypot(nx - c.x, ny - c.y) < c.r + 5) hits += 1
654
+ }
655
+ for (const other of placed) {
656
+ if (other.id === selfId) continue
657
+ if (rect.x0 < other.rect.x1 + 2 && rect.x1 > other.rect.x0 - 2 &&
658
+ rect.y0 < other.rect.y1 + 1 && rect.y1 > other.rect.y0 - 1) hits += 1
659
+ }
660
+ return hits
661
+ }
662
+ const placed = []
663
+ let total = 0
664
+ items.sort((a, b) => (b.p.isCenter ? 1 : 0) - (a.p.isCenter ? 1 : 0))
665
+ for (const it of items) {
666
+ const out = it.p.x >= center.x ? 1 : -1
667
+ const shifts = [0]
668
+ for (let s = 6; s <= 78; s += 6) { shifts.push(out * s); shifts.push(-out * s) }
669
+ const ups = lockUp ? [!!it.p.labelUp] : (it.p.labelUp ? [true, false] : [false, true])
670
+ let best = null
671
+ for (const up of ups) {
672
+ for (const shift of shifts) {
673
+ // 平移后若越出舞台左右边界,就地夹回边界内(只改标签位置,不改舱体)
674
+ const lo = 4 + it.hw
675
+ const hi = W - 4 - it.hw
676
+ const cx = hi > lo ? Math.min(hi, Math.max(lo, it.p.x + shift)) : it.p.x
677
+ const real = cx - it.p.x
678
+ const rect = rectOf(it, up, real)
679
+ const hits = countHits(rect, it.id, placed)
680
+ if (!best || hits < best.hits) best = { up, shift: real, rect, hits }
681
+ if (hits === 0) break
682
+ }
683
+ if (best && best.hits === 0) break
684
+ }
685
+ it.p.labelUp = best.up
686
+ it.p.nameShift = best.shift
687
+ total += best.hits
688
+ placed.push({ id: it.id, rect: best.rect })
689
+ }
690
+ return total
691
+ }
692
+
693
+ function layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, dense, fill, cap, density, noLabels) {
694
+ const base0 = HIVE_MODES[modeKey] || HIVE_MODES.duo
695
+ // 舞台密度:窄面板里舱体 / 名字块 / 留白一起等比收紧(侧栏拖窄时自动变小)
696
+ const d = density == null ? 1 : density
697
+ const base = d === 1 ? base0 : {
698
+ ...base0,
699
+ pod: Math.round(base0.pod * d),
700
+ coord: Math.round(base0.coord * d),
701
+ name: Math.round(base0.name * d),
702
+ padT: Math.round(base0.padT * d),
703
+ padB: Math.round(base0.padB * d),
704
+ padX: Math.round(base0.padX * d),
705
+ }
706
+ const M = scale === 1
707
+ ? base
708
+ : { ...base, pod: Math.round(base.pod * scale), coord: Math.round(base.coord * scale) }
709
+ // 光束优先于图标:先给线留够长度(不低于 BEAM_FLOOR),舱体放不下就由 layoutHive 缩舱体让位
710
+ const beam = Math.max(BEAM_FLOOR, Math.round(base0.beam * d))
711
+ const seg = Math.round(beam * 0.6) // 纵向绕行时至少露出这么一截光束
712
+ // 紧凑标签:只留名字(11px),不给状态文字留位;环太挤时自动切换
713
+ // 名字块字号不跟密度缩(12px 已经是可读下限,再小会截断),只缩舱体与留白
714
+ const compact = dense || modeKey === 'crowd'
715
+ const nameH = compact ? 18 : base0.name
716
+ // noLabels:卫星名字块整个收起来(悬停仍可看),纵向不再给它留位——省下的空间全给光束
717
+ const satLabelH = noLabels ? 0 : nameH
718
+ const coord = nodes.find((n) => n.coord) || nodes[0]
719
+ const others = nodes.filter((n) => n !== coord)
720
+ const n = others.length
721
+ const rx = Math.max(M.coord / 2 + M.pod / 2 + beam, W / 2 - M.pod / 2 - M.padX)
722
+ // 纵向净空:按「标签框 / 舱体框是否真的相交」判断,而不是按 sin 一刀切
723
+ let ryNeed = 0
724
+ for (const deg of anglesFor(n)) {
725
+ const rad = (deg * Math.PI) / 180
726
+ const s = Math.sin(rad)
727
+ const dx = Math.abs(Math.cos(rad)) * rx
728
+ let need = 0
729
+ if (s < -0.3) {
730
+ // 名字在舱体上方:只需让开主控本体与一段可见光束
731
+ need = !noLabels && dx < M.coord / 2 + M.pod / 2 + Math.round(seg * 0.5) ? M.coord / 2 + M.pod / 2 + 8 * d + seg : 0
732
+ } else if (s > 0.02) {
733
+ // 下方:主控自己的名字块永远要留出(主控不收名字),卫星名字收起时只让开主控字块
734
+ if (dx - M.pod / 2 < Math.round(beam * 0.8)) need = M.coord / 2 + nameH + 8 * d + M.pod / 2 + (noLabels ? 6 : seg)
735
+ else if (dx < Math.round(beam * 1.5)) need = M.coord / 2 + nameH + 8 * d - M.pod / 2
736
+ }
737
+ if (need > 0) ryNeed = Math.max(ryNeed, need / Math.max(Math.abs(s), 0.2))
738
+ }
739
+ // 椭圆高度:先按周长需求拉高;标签还挤就吃满纵向预算(fill),再不行由 layoutHive 缩小舱体
740
+ const needLen = n * (M.pod + 14 * d)
741
+ const ryCap2 = needLen > 0 ? Math.sqrt(Math.max(0, 2 * Math.pow(needLen / (2 * Math.PI), 2) - rx * rx)) : 0
742
+ const ryFloor = 56 * d
743
+ const ryCap = Math.max(ryFloor, availH / 2 - M.pod / 2 - satLabelH - 8 * d - (M.padT + M.padB) / 2 - 1)
744
+ const ry = fill
745
+ ? Math.max(ryNeed, ryCap, ryFloor)
746
+ : Math.max(ryNeed, Math.min(ryCap, Math.max(rx * 0.84, ryCap2)), ryFloor)
747
+ const angles = evenAngles(rx, ry, n)
748
+ let top = M.coord / 2 + 20 * d // 顶部留一条绕行弧线的通道
749
+ let bottom = M.coord / 2 + nameH + 8 * d
750
+ for (const deg of angles) {
751
+ const s = Math.sin((deg * Math.PI) / 180)
752
+ const up = s < -0.3
753
+ top = Math.max(top, -s * ry + M.pod / 2 + (up ? satLabelH + 8 * d : 0) + 2)
754
+ bottom = Math.max(bottom, s * ry + M.pod / 2 + (up ? 0 : satLabelH + 8 * d))
755
+ }
756
+ let cy = M.padT + top
757
+ const height = Math.round(cy + bottom + M.padB)
758
+ if (viewH && height < viewH) cy += (viewH - height) / 2
759
+ const pos = {}
760
+ pos[coord.id] = { x: W / 2, y: cy, pod: M.coord, isCenter: true, angle: null, labelUp: false }
761
+ others.forEach((node, i) => {
762
+ const rad = (angles[i] * Math.PI) / 180
763
+ pos[node.id] = {
764
+ x: W / 2 + rx * Math.cos(rad),
765
+ y: cy + ry * Math.sin(rad),
766
+ pod: M.pod,
767
+ isCenter: false,
768
+ angle: angles[i],
769
+ labelUp: Math.sin(rad) < -0.3,
770
+ labelMax: cap || 0,
771
+ }
772
+ })
773
+ // 整簇水平居中(单侧节点时避免半边空)
774
+ let minX = Infinity
775
+ let maxX = -Infinity
776
+ for (const id of Object.keys(pos)) {
777
+ minX = Math.min(minX, pos[id].x - pos[id].pod / 2)
778
+ maxX = Math.max(maxX, pos[id].x + pos[id].pod / 2)
779
+ }
780
+ const shift = (W - (maxX - minX)) / 2 - minX
781
+ for (const id of Object.keys(pos)) pos[id].x += shift
782
+ const center = { x: W / 2 + shift, y: cy }
783
+ const labelHits = noLabels
784
+ ? 0
785
+ : resolveLabels(pos, nodes, W, Math.max(height, viewH || 0), compact ? 16 : 28, compact ? 5 : 7, center, false, 1)
786
+ return {
787
+ pos, center, rx, ry, height, angles, mode: M, coordId: coord.id, ringCount: n,
788
+ strip: false, hideMeta: compact, labelHits, density: d, hideLabels: !!noLabels,
789
+ }
790
+ }
791
+
792
+ // 依次尝试:纵向富余就先放大一档 → 原尺寸 → 紧凑标签(去掉状态文字)→ 椭圆吃满纵向 → 缩小舱体 → 名字截断
793
+ function layoutHive(nodes, W, availH, modeKey, viewH, density) {
794
+ const d = density == null ? 1 : density
795
+ // 宽度预算:放大后的簇宽不能超过舞台宽度——窄面板里纵向再富余也不许把舱体撑回原尺寸
796
+ const growCap = (W - 8) / (naturalWidthOf(modeKey) * d)
797
+ let scale = 1
798
+ let dense = false
799
+ let fill = false
800
+ let cap = 0
801
+ let L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, 1, false, false, 0, d)
802
+ // 单任务铺满一屏时星团容易缩在中间:纵向明显富余就把舱体放大一档(最多 1.35 倍)
803
+ const outOfBounds = (L) => Object.keys(L.pos).some((id) => {
804
+ const p = L.pos[id]
805
+ return p.x - p.pod / 2 < -0.5 || p.x + p.pod / 2 > W + 0.5
806
+ })
807
+ if (availH && L.ringCount >= 1 && L.height < availH * 0.6) {
808
+ const grow = Math.min(1.35, (availH * 0.6) / L.height, growCap)
809
+ if (grow > 1.06) {
810
+ const G = layoutHiveRaw(nodes, W, availH, modeKey, viewH, grow, false, false, 0, d)
811
+ if (!outOfBounds(G) && G.labelHits === 0 && (G.ringCount < 2 || minSpacing(G.rx, G.ry, G.angles) >= G.mode.pod + 8)) {
812
+ scale = grow
813
+ L = G
814
+ }
815
+ }
816
+ }
817
+ for (let i = 0; i < 12; i++) {
818
+ const have = L.ringCount >= 2 ? minSpacing(L.rx, L.ry, L.angles) : Infinity
819
+ const need = L.mode.pod + 8
820
+ if (have < need || outOfBounds(L)) {
821
+ // 环上放不下:按「实际弦长 / 需要的弦长」缩小舱体,单次最多缩 25%;横向出界则每次缩 6%
822
+ if (scale <= 0.42) break
823
+ const k = have < need ? Math.max(0.75, Math.min(0.98, have / need)) : 0.94
824
+ scale = Math.max(0.42, scale * k)
825
+ L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, dense, fill, cap, d)
826
+ continue
827
+ }
828
+ if (L.labelHits > 0) {
829
+ if (!dense) dense = true
830
+ else if (!fill) fill = true
831
+ else if (scale > 0.42) scale = Math.max(0.42, scale * 0.88)
832
+ else cap = Math.max(Math.round(40 * d), Math.round(have - 4)) // 实在放不下就把名字截断
833
+ L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, dense, fill, cap, d)
834
+ continue
835
+ }
836
+ break
837
+ }
838
+ // 收尾:名字块只能截成「DS…」这种残桩,或者循环跑完还在冲突——干脆把卫星名字整个收起来
839
+ // (悬停仍可看),省下的横向 / 纵向空间全部让给光束,环能撑得更大,舱体也不用再为躲字而缩。
840
+ const haveNow = L.ringCount >= 2 ? minSpacing(L.rx, L.ry, L.angles) : Infinity
841
+ const tight = L.labelHits > 0 ? Math.max(26, Math.round(haveNow - 4)) : (cap || 999)
842
+ if (L.labelHits > 0) L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, true, true, tight, d)
843
+ if (L.labelHits > 0 || tight < LABEL_MIN_READABLE) {
844
+ L = layoutHiveRaw(nodes, W, availH, modeKey, viewH, scale, true, true, 0, d, true)
845
+ }
846
+ return L
847
+ }
848
+
849
+ // ── 紧凑「传送带」布局:主控在左,其余在右侧一到两排 ──
850
+ function layoutStrip(nodes, W, viewH, modeKey, density) {
851
+ const d = density == null ? 1 : density
852
+ const base0 = HIVE_MODES[modeKey] || HIVE_MODES.duo
853
+ const M = d === 1 ? base0 : { ...base0, pod: Math.round(base0.pod * d), coord: Math.round(base0.coord * d) }
854
+ const coord = nodes.find((n) => n.coord) || nodes[0]
855
+ const others = nodes.filter((n) => n !== coord)
856
+ const n = others.length
857
+ let rows = n >= 2 ? 2 : 1
858
+ const padX = Math.round(16 * d)
859
+ const labelH = 18
860
+ const labelBlock = 6 + labelH
861
+ // 光束优先:主控与卫星之间的走廊、以及两排之间的走廊都按 beam 给,舱体放不下就缩舱体
862
+ const beamX = Math.max(BEAM_FLOOR, Math.round(base0.beam * 0.8 * d))
863
+ const corridor = Math.max(26, Math.round(base0.beam * 0.6 * d)) // 两排之间的光束走廊高度
864
+ const coordSize = M.coord
865
+ const xa = padX + coordSize / 2
866
+ // 横向放不下(舱体会互相压)才拆成三排,三排没有光束走廊
867
+ const rawPod = (r) => {
868
+ const per = Math.ceil(n / r)
869
+ if (per <= 1) return M.pod
870
+ const x0 = xa + coordSize / 2 + beamX + M.pod / 2
871
+ const xb = W - 22 * d - M.pod / 2
872
+ return Math.min(M.pod, Math.floor((xb - x0) / (per - 1)) - 8)
873
+ }
874
+ let pod = rawPod(rows)
875
+ if (rows < 3) {
876
+ const wide = rawPod(3)
877
+ if (pod < 22 && wide > pod + 6) { rows = 3; pod = wide }
878
+ }
879
+ pod = Math.max(18, pod)
880
+ const perRow = Math.ceil(n / rows)
881
+ const x0 = xa + coordSize / 2 + beamX + pod / 2
882
+ const xb = W - 22 * d - pod / 2
883
+ const rowH = pod + labelBlock
884
+ // 纵向:两排时顶排标签在上、底排标签在下,中间留一条光束走廊;单排/三排标签都在下方
885
+ const rowY = []
886
+ let height
887
+ if (rows === 2) {
888
+ const y0 = 10 + labelBlock + pod / 2
889
+ rowY.push(y0, y0 + pod + corridor)
890
+ height = Math.round(rowY[1] + pod / 2 + labelBlock + 10)
891
+ } else if (rows === 1) {
892
+ const y = 22 + pod / 2 // 上方留出绕行弧线的余量
893
+ rowY.push(y)
894
+ height = Math.round(y + pod / 2 + labelBlock + 10)
895
+ } else {
896
+ const y0 = 12 + pod / 2
897
+ for (let r = 0; r < rows; r++) rowY.push(y0 + r * (rowH + 10))
898
+ height = Math.round(rowY[rows - 1] + pod / 2 + labelBlock + 10)
899
+ }
900
+ const cy = rows === 2 ? (rowY[0] + rowY[1]) / 2 : rowY[Math.floor(rows / 2)]
901
+ const shiftY = viewH && viewH > height ? (viewH - height) / 2 : 0
902
+ // 名字宽度上限跟着舱体间距走,长名字用省略号收尾,避免相邻标签互相压
903
+ const spacing = perRow > 1 ? (xb - x0) / (perRow - 1) : xb - x0
904
+ const labelMax = Math.max(38, Math.min(74, Math.floor(spacing + 4)))
905
+ const pos = {}
906
+ pos[coord.id] = { x: xa, y: cy + shiftY, pod: coordSize, isCenter: true, angle: null, labelUp: false }
907
+ others.forEach((node, i) => {
908
+ const row = Math.floor(i / perRow)
909
+ const col = i % perRow
910
+ const cnt = Math.min(perRow, n - perRow * row)
911
+ // 单排只放一个舱体时(两个组员),错开一点,别叠成一条竖线
912
+ const t = cnt === 1 ? (rows === 2 ? (row === 0 ? 0.38 : 0.62) : 0.5) : col / (cnt - 1)
913
+ pos[node.id] = {
914
+ x: x0 + (xb - x0) * t,
915
+ y: rowY[Math.min(row, rowY.length - 1)] + shiftY,
916
+ pod,
917
+ isCenter: false,
918
+ angle: null,
919
+ labelUp: rows === 2 && row === 0,
920
+ labelMax,
921
+ }
922
+ })
923
+ const center = { x: xa, y: cy + shiftY }
924
+ resolveLabels(pos, nodes, W, Math.max(height, viewH || 0), 16, 5, center, rows === 2, 1)
925
+ return {
926
+ pos, center, rx: 0, ry: 0, height, mode: M, coordId: coord.id, ringCount: n,
927
+ strip: true, hideMeta: false, labelHits: 0, density: d,
928
+ corridor: rows === 2 ? cy + shiftY : null,
929
+ }
930
+ }
931
+
932
+ // ── 布线:径向走直线,环上互连走外弧/内弧,传送带走中间走廊;全部避开舱体与名字 ──
933
+ function curve(s, c, e) {
934
+ return {
935
+ d: 'M' + s.x.toFixed(1) + ' ' + s.y.toFixed(1) + ' Q' + c.x.toFixed(1) + ' ' + c.y.toFixed(1) + ' ' + e.x.toFixed(1) + ' ' + e.y.toFixed(1),
936
+ sx: s.x, sy: s.y, cx: c.x, cy: c.y, ex: e.x, ey: e.y,
937
+ }
938
+ }
939
+
940
+ function cubic(s, c1, c2, e) {
941
+ return {
942
+ d: 'M' + s.x.toFixed(1) + ' ' + s.y.toFixed(1) + ' C' + c1.x.toFixed(1) + ' ' + c1.y.toFixed(1) + ' ' + c2.x.toFixed(1) + ' ' + c2.y.toFixed(1) + ' ' + e.x.toFixed(1) + ' ' + e.y.toFixed(1),
943
+ sx: s.x, sy: s.y, c1x: c1.x, c1y: c1.y, c2x: c2.x, c2y: c2.y, ex: e.x, ey: e.y,
944
+ }
945
+ }
946
+
947
+ function pointAt(p, t) {
948
+ const u = 1 - t
949
+ if (p.c1x != null) {
950
+ return {
951
+ x: u * u * u * p.sx + 3 * u * u * t * p.c1x + 3 * u * t * t * p.c2x + t * t * t * p.ex,
952
+ y: u * u * u * p.sy + 3 * u * u * t * p.c1y + 3 * u * t * t * p.c2y + t * t * t * p.ey,
953
+ }
954
+ }
955
+ return {
956
+ x: u * u * p.sx + 2 * u * t * p.cx + t * t * p.ex,
957
+ y: u * u * p.sy + 2 * u * t * p.cy + t * t * p.ey,
958
+ }
959
+ }
960
+
961
+ function curveLength(p) {
962
+ let len = 0
963
+ let prev = pointAt(p, 0)
964
+ for (let i = 1; i <= 24; i++) {
965
+ const cur = pointAt(p, i / 24)
966
+ len += Math.hypot(cur.x - prev.x, cur.y - prev.y)
967
+ prev = cur
968
+ }
969
+ return len
970
+ }
971
+
972
+ function collides(p, pods, skipA, skipB, W, H) {
973
+ for (let i = 1; i <= 20; i++) {
974
+ const t = i / 20
975
+ const q = pointAt(p, t)
976
+ const x = q.x
977
+ const y = q.y
978
+ if (x < 3 || x > W - 3 || y < 3 || y > H - 3) return true
979
+ for (const pod of pods) {
980
+ const isA = pod.id === skipA
981
+ const isB = pod.id === skipB
982
+ if (isA || isB) {
983
+ // 起点 / 终点的舱体圆必须跳过(线就是从它们边缘出发的);
984
+ // 但两端自己的名字块要避开——终点整条路径都不许压字,起点只放行开头一小段。
985
+ if (!pod.rect) continue
986
+ if (isB || t > 0.25) {
987
+ const rc = pod.rect
988
+ if (x > rc.x0 && x < rc.x1 && y > rc.y0 && y < rc.y1) return true
989
+ }
990
+ continue
991
+ }
992
+ if (Math.hypot(x - pod.x, y - pod.y) < pod.pod / 2 + 10) return true
993
+ const rc = pod.rect
994
+ if (rc && x > rc.x0 && x < rc.x1 && y > rc.y0 && y < rc.y1) return true
995
+ }
996
+ }
997
+ return false
998
+ }
999
+
1000
+ function routeBeam(a, b, L, pods, W, H) {
1001
+ const ra = a.pod / 2
1002
+ const rb = b.pod / 2
1003
+ const dx = b.x - a.x
1004
+ const dy = b.y - a.y
1005
+ const len = Math.hypot(dx, dy) || 1
1006
+ const ux = dx / len
1007
+ const uy = dy / len
1008
+ const s = { x: a.x + ux * (ra + 8), y: a.y + uy * (ra + 8) }
1009
+ const e = { x: b.x - ux * (rb + 8), y: b.y - uy * (rb + 8) }
1010
+ const mid = { x: (s.x + e.x) / 2, y: (s.y + e.y) / 2 }
1011
+ const chord = Math.hypot(e.x - s.x, e.y - s.y)
1012
+ const nx = -uy
1013
+ const ny = ux
1014
+ const cands = []
1015
+ if (L.strip && L.corridor != null) {
1016
+ // 传送带:从舱体边缘进出,中间贴着两排之间的走廊走,像一条总线
1017
+ const cy = L.corridor
1018
+ const s2 = a.isCenter
1019
+ ? { x: a.x + (b.x >= a.x ? 1 : -1) * (ra + 8), y: a.y }
1020
+ : { x: a.x, y: a.y + (cy > a.y ? 1 : -1) * (ra + 8) }
1021
+ const e2 = b.isCenter
1022
+ ? { x: b.x - (b.x >= a.x ? 1 : -1) * (rb + 8), y: b.y }
1023
+ : { x: b.x, y: b.y + (cy > b.y ? 1 : -1) * (rb + 8) }
1024
+ const span = e2.x - s2.x
1025
+ for (const k of [0.16, 0.3, 0.46]) {
1026
+ cands.push(cubic(s2, { x: s2.x + span * k, y: cy }, { x: e2.x - span * k, y: cy }, e2))
1027
+ }
1028
+ }
1029
+ if (a.isCenter || b.isCenter) {
1030
+ if (L.strip) {
1031
+ // 传送带(无走廊时):优先走两排之间的空档,绕开近处舱体与名字
1032
+ const toMid = mid.y - L.center.y > 0 ? -1 : 1
1033
+ for (const k of [0.14, 0.28, 0.42, 0.6]) {
1034
+ cands.push({ x: mid.x, y: mid.y + toMid * chord * k })
1035
+ cands.push({ x: mid.x, y: mid.y - toMid * chord * k })
1036
+ }
1037
+ } else {
1038
+ cands.push({ x: mid.x + nx * chord * 0.1, y: mid.y + ny * chord * 0.1 })
1039
+ cands.push({ x: mid.x - nx * chord * 0.1, y: mid.y - ny * chord * 0.1 })
1040
+ }
1041
+ } else {
1042
+ let ox = mid.x - L.center.x
1043
+ let oy = mid.y - L.center.y
1044
+ let ol = Math.hypot(ox, oy)
1045
+ if (ol < 10) { ox = nx; oy = ny; ol = 1 }
1046
+ ox /= ol
1047
+ oy /= ol
1048
+ // 先小弧度,撞到舱体/名字再加大(对径两点的连线必须绕开主控;超宽弦需要的弧度很小)
1049
+ for (let k = 0.06; k <= 0.96; k += 0.03) {
1050
+ cands.push({ x: mid.x + ox * chord * k, y: mid.y + oy * chord * k })
1051
+ cands.push({ x: mid.x - ox * chord * k, y: mid.y - oy * chord * k })
1052
+ cands.push({ x: mid.x + nx * chord * k, y: mid.y + ny * chord * k })
1053
+ cands.push({ x: mid.x - nx * chord * k, y: mid.y - ny * chord * k })
1054
+ }
1055
+ }
1056
+ let picked = null
1057
+ // 箭头落在目标名字上时,改从侧面切入(±60° / ±92°),避免箭头压字
1058
+ const target = pods.find((p) => p.id === b.id)
1059
+ const ends = [e]
1060
+ if (target && target.rect && e.x > target.rect.x0 && e.x < target.rect.x1 && e.y > target.rect.y0 && e.y < target.rect.y1) {
1061
+ const base = Math.atan2(e.y - b.y, e.x - b.x)
1062
+ for (const d of [1.05, -1.05, 1.6, -1.6]) {
1063
+ ends.push({ x: b.x + Math.cos(base + d) * (rb + 8), y: b.y + Math.sin(base + d) * (rb + 8) })
1064
+ }
1065
+ }
1066
+ for (const cand of cands) {
1067
+ if (cand.d) {
1068
+ if (!collides(cand, pods, a.id, b.id, W, H)) { picked = cand; break }
1069
+ continue
1070
+ }
1071
+ for (const end of ends) {
1072
+ const p = curve(s, cand, end)
1073
+ if (!collides(p, pods, a.id, b.id, W, H)) { picked = p; break }
1074
+ }
1075
+ if (picked) break
1076
+ }
1077
+ if (!picked) picked = curve(s, mid, e)
1078
+ picked.len = curveLength(picked)
1079
+ const tx = picked.ex - (picked.c1x != null ? picked.c2x : picked.cx)
1080
+ const ty = picked.ey - (picked.c1y != null ? picked.c2y : picked.cy)
1081
+ const tl = Math.hypot(tx, ty) || 1
1082
+ picked.angle = (Math.atan2(ty / tl, tx / tl) * 180) / Math.PI
1083
+ return picked
1084
+ }
1085
+
1086
+ // ── 图标 ──
1087
+ function strokeProps() {
1088
+ return { fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }
1089
+ }
1090
+
1091
+ function HudIcon({ name, size = 16 }) {
1092
+ const common = strokeProps()
1093
+ let body = null
1094
+ if (name === 'sun') {
1095
+ body = h(Fragment, null,
1096
+ h('circle', { cx: 12, cy: 12, r: 4, ...common }),
1097
+ h('path', { d: 'M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4', ...common }))
1098
+ } else if (name === 'moon') {
1099
+ body = h('path', { d: 'M20.5 14.2A8.5 8.5 0 0 1 9.8 3.5 8.5 8.5 0 1 0 20.5 14.2Z', ...common })
1100
+ } else if (name === 'motion') {
1101
+ body = h('path', { d: 'M3 12h4l2.5-6 5 12 2.5-6h4', ...common })
1102
+ } else if (name === 'still') {
1103
+ body = h('path', { d: 'M8 5v14M16 5v14', ...common })
1104
+ } else if (name === 'refresh') {
1105
+ body = h(Fragment, null,
1106
+ h('path', { d: 'M20 7v5h-5M4 17v-5h5', ...common }),
1107
+ h('path', { d: 'M6.1 8a7 7 0 0 1 11.6-2L20 8M4 16l2.3 2A7 7 0 0 0 18 16', ...common }))
1108
+ } else if (name === 'alert') {
1109
+ body = h(Fragment, null,
1110
+ h('path', { d: 'M12 8v5M12 16h.01', ...common }),
1111
+ h('path', { d: 'M10.3 4.1 2.6 17.2A2 2 0 0 0 4.3 20h15.4a2 2 0 0 0 1.7-2.8L13.7 4.1a2 2 0 0 0-3.4 0Z', ...common }))
1112
+ }
1113
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', 'aria-hidden': 'true', focusable: 'false', style: { display: 'block' } }, body)
1114
+ }
1115
+
1116
+ function BrandGlyph({ size = 18, stroke = 1.9 }) {
1117
+ return h('svg', {
1118
+ viewBox: '0 0 24 24', width: size, height: size, fill: 'none', stroke: 'currentColor',
1119
+ strokeWidth: stroke, strokeLinecap: 'round', 'aria-hidden': 'true', focusable: 'false', style: { display: 'block' },
1120
+ },
1121
+ h('path', { d: 'M12 6.5v5M12 11.5l-5 4M12 11.5l5 4' }),
1122
+ h('circle', { cx: 12, cy: 5, r: 2.4, fill: 'currentColor', stroke: 'none' }),
1123
+ h('circle', { cx: 7, cy: 17.5, r: 2.1, fill: 'currentColor', stroke: 'none' }),
1124
+ h('circle', { cx: 17, cy: 17.5, r: 2.1, fill: 'currentColor', stroke: 'none' }))
1125
+ }
1126
+
1127
+ function UserGlyph({ size = 20 }) {
1128
+ return h('svg', {
1129
+ viewBox: '0 0 24 24', width: size, height: size, fill: 'none', stroke: 'currentColor',
1130
+ strokeWidth: 1.6, strokeLinecap: 'round', 'aria-hidden': 'true', focusable: 'false', style: { display: 'block' },
1131
+ },
1132
+ h('circle', { cx: 12, cy: 8.5, r: 3.6 }),
1133
+ h('path', { d: 'M4.6 20c1.2-3.6 4-5.4 7.4-5.4s6.2 1.8 7.4 5.4' }))
1134
+ }
1135
+
1136
+ // ── 元素:光束(彗尾三层 + 头点)与舱体 ──
1137
+ function beamElements(edge, p, id, motion, filterId) {
1138
+ const isWait = edge.kind === 'wait'
1139
+ const dur = isWait ? 3.4 : 2.1
1140
+ const color = isWait ? 'var(--dsb-wait)' : 'var(--dsb-cyan)'
1141
+ const gradId = 'dsb-bg-' + id
1142
+ const out = []
1143
+ out.push(h('defs', { key: 'defs' },
1144
+ h('linearGradient', {
1145
+ id: gradId, gradientUnits: 'userSpaceOnUse',
1146
+ x1: p.sx.toFixed(1), y1: p.sy.toFixed(1), x2: p.ex.toFixed(1), y2: p.ey.toFixed(1),
1147
+ },
1148
+ isWait
1149
+ ? [
1150
+ h('stop', { key: 0, offset: 0, stopColor: '#f2b84b', stopOpacity: 0.16 }),
1151
+ h('stop', { key: 1, offset: 1, stopColor: '#f2b84b', stopOpacity: 0.7 }),
1152
+ ]
1153
+ : [
1154
+ h('stop', { key: 0, offset: 0, stopColor: '#4d6bfe', stopOpacity: 0.3 }),
1155
+ h('stop', { key: 1, offset: 1, stopColor: '#62d6ff', stopOpacity: 0.95 }),
1156
+ ])))
1157
+ out.push(h('path', {
1158
+ key: 'base', d: p.d, fill: 'none', stroke: 'url(#' + gradId + ')',
1159
+ strokeWidth: isWait ? 2 : 2.6, strokeLinecap: 'round',
1160
+ strokeDasharray: isWait ? '2 6' : undefined,
1161
+ filter: 'url(#' + filterId + ')',
1162
+ }))
1163
+ if (motion) {
1164
+ for (const layer of [[42, 2.2, 0.26], [24, 3.2, 0.48], [10, 4.2, 0.85]]) {
1165
+ const dash = layer[0]
1166
+ out.push(h('path', {
1167
+ key: 'c' + dash, d: p.d, fill: 'none', stroke: color, strokeWidth: layer[1],
1168
+ strokeLinecap: 'round', opacity: layer[2],
1169
+ strokeDasharray: dash + ' 9999', strokeDashoffset: dash,
1170
+ },
1171
+ h('animate', {
1172
+ attributeName: 'stroke-dashoffset', from: dash, to: (dash - p.len).toFixed(1),
1173
+ dur: dur + 's', repeatCount: 'indefinite',
1174
+ })))
1175
+ }
1176
+ out.push(h('circle', {
1177
+ key: 'head', r: isWait ? 3 : 3.6, fill: isWait ? '#ffe2a6' : '#e8fbff',
1178
+ filter: 'url(#' + filterId + ')',
1179
+ },
1180
+ h('animateMotion', {
1181
+ dur: dur + 's', repeatCount: 'indefinite', path: p.d,
1182
+ calcMode: 'linear', keyPoints: '0;1', keyTimes: '0;1',
1183
+ })))
1184
+ }
1185
+ out.push(h('path', {
1186
+ key: 'arrow', d: 'M-5 -4 L1 0 L-5 4', fill: 'none', stroke: color, strokeWidth: 2,
1187
+ strokeLinecap: 'round', strokeLinejoin: 'round',
1188
+ transform: 'translate(' + p.ex.toFixed(1) + ' ' + p.ey.toFixed(1) + ') rotate(' + p.angle.toFixed(1) + ')',
1189
+ }))
1190
+ return out
1191
+ }
1192
+
1193
+ // 头像图片:加载失败时回退到形状/字母,避免宿主里出现破图占位
1194
+ function AvatarImg({ src, alt, style, fallback }) {
1195
+ const [bad, setBad] = useState(false)
1196
+ useEffect(() => { setBad(false) }, [src])
1197
+ if (!src || bad) return fallback || null
1198
+ return h('img', { src, alt: alt || '', style, onError: () => { setBad(true) } })
1199
+ }
1200
+
1201
+ function podElement(node, p, modeKey, ctx) {
1202
+ const status = node.isUser ? 'user' : (node.failed ? 'failed' : (node.activeStatus || 'working'))
1203
+ const statusText = HIVE_STATUS_TEXT[status] || '工作中'
1204
+ const size = Math.round(p.pod * 0.62)
1205
+ const mark = node.shape ? characterMarkupOf(node.shape, size) : null
1206
+ const glyph = mark
1207
+ ? h('svg', {
1208
+ width: size, height: size, viewBox: '-50 -50 100 100', 'aria-hidden': 'true', focusable: 'false',
1209
+ // 尺寸写进 style:宿主里的全局 svg 规则可能压掉 width/height 属性
1210
+ style: { width: size, height: size, display: 'block', flex: '0 0 auto' },
1211
+ },
1212
+ renderCharacter(h, {
1213
+ def: mark.def, id: mark.id, r: 50, color: node.color,
1214
+ uid: ctx.uid + '-' + node.id, status,
1215
+ reducedMotion: !ctx.motion, active: true, seed: node.name, nodeKey: node.id,
1216
+ }))
1217
+ : h('span', { className: 'dsb-pod__letter' }, String(node.name || '?').slice(0, 1))
1218
+ let inner
1219
+ if (node.isUser) {
1220
+ inner = h('span', { className: 'dsb-pod__user' }, h(UserGlyph, { size: Math.round(p.pod * 0.42) }))
1221
+ } else if (node.avatar && node.avatar.image) {
1222
+ const box = Math.round(p.pod * 0.74)
1223
+ inner = h('span', { className: 'dsb-pod__char', style: { width: box, height: box } },
1224
+ h(AvatarImg, { src: node.avatar.image, alt: '', fallback: glyph }))
1225
+ } else {
1226
+ inner = h('span', { className: 'dsb-pod__char' }, glyph)
1227
+ }
1228
+ const ring = h('svg', { className: 'dsb-pod__ring', viewBox: '0 0 100 100', 'aria-hidden': 'true', focusable: 'false' },
1229
+ h('circle', { className: 'dsb-halo', cx: 50, cy: 50, r: 47 }),
1230
+ h('circle', { className: 'dsb-tick', cx: 50, cy: 50, r: 47 }),
1231
+ node.coord ? h('circle', { className: 'dsb-gold', cx: 50, cy: 50, r: 52 }) : null,
1232
+ h('circle', { className: 'dsb-arc', cx: 50, cy: 50, r: 47 }))
1233
+ const label = ctx.hideLabels && !node.coord
1234
+ ? null
1235
+ : h('div', { className: 'dsb-pod__label' },
1236
+ h('div', { className: 'dsb-pod__name' },
1237
+ node.coord ? h('span', { className: 'dsb-pod__crown' }, '主控') : null,
1238
+ h('span', { title: node.name }, node.name)),
1239
+ modeKey === 'crowd' || modeKey === 'strip'
1240
+ ? null
1241
+ : h('div', { className: 'dsb-pod__meta' }, h('i'), statusText))
1242
+ const labelW = Math.min(estimateLabelWidth(node), p.labelMax || 999)
1243
+ // 名字文字的上限:主控要把「主控」冠标 + 间距让出来,否则传送带里会被压成 74px 截断
1244
+ const nameMax = node.coord ? Math.max(40, Math.round(labelW - 33)) : (p.labelMax || 0)
1245
+ // 头像动效错峰:按 id 散开,别让一整圈头像同步点头
1246
+ let avaSeed = 0
1247
+ const seedText = String(node.id || node.name || '')
1248
+ for (let i = 0; i < seedText.length; i++) avaSeed = (avaSeed * 31 + seedText.charCodeAt(i)) >>> 0
1249
+ const style = {
1250
+ left: p.x.toFixed(1) + 'px',
1251
+ top: p.y.toFixed(1) + 'px',
1252
+ '--dsb-pod': p.pod + 'px',
1253
+ '--dsb-tint': tintOf(node.color),
1254
+ '--dsb-shift': (p.nameShift || 0).toFixed(1) + 'px',
1255
+ '--dsb-name-max': nameMax ? nameMax + 'px' : undefined,
1256
+ '--dsb-label-w': labelW + 'px',
1257
+ '--dsb-ava-delay': (-((avaSeed % 30) / 10)).toFixed(1) + 's',
1258
+ }
1259
+ const cls = 'dsb-pod dsb-pod--' + status + (node.coord ? ' dsb-pod--coord' : '') + (p.labelUp ? ' dsb-pod--up' : '')
1260
+ const body = h('div', { className: 'dsb-pod__body' }, ring, inner)
1261
+ if (node.isUser) {
1262
+ return h('div', { key: node.id, className: cls + ' dsb-pod--static', style, 'aria-hidden': 'true' },
1263
+ h('div', { className: 'dsb-pod__glow' }), body, label)
1264
+ }
1265
+ return h('button', {
1266
+ key: node.id,
1267
+ type: 'button',
1268
+ className: cls,
1269
+ style,
1270
+ title: node.name + ' · ' + statusText,
1271
+ 'aria-label': '打开 ' + node.name + ' 的会话(' + statusText + ')',
1272
+ onClick: () => { if (ctx.onOpenSession) ctx.onOpenSession({ botId: node.id, key: node.key, name: node.name }) },
1273
+ },
1274
+ h('div', { className: 'dsb-pod__glow' }),
1275
+ status === 'waiting' ? h('div', { className: 'dsb-pod__pulse' }) : null,
1276
+ body,
1277
+ label)
1278
+ }
1279
+
1280
+ function stageElements(group, L, W, H, modeKey, ctx) {
1281
+ const effMode = L.strip ? 'strip' : (L.hideMeta ? 'crowd' : modeKey)
1282
+ const compact = effMode !== modeKey || modeKey === 'crowd'
1283
+ const d = L.density == null ? 1 : L.density
1284
+ const labelH = compact ? 16 : 28
1285
+ const gap = compact ? 5 : 7
1286
+ const pods = []
1287
+ for (const node of group.nodes) {
1288
+ const p = L.pos[node.id]
1289
+ if (!p) continue
1290
+ const sh = p.nameShift || 0
1291
+ const half = Math.min(estimateLabelWidth(node), p.labelMax || 999) / 2
1292
+ // 名字收起的卫星不占障碍物,光束不必再绕一块不存在的字;
1293
+ // 绕行时给文字留 5px 呼吸:光束带辉光,贴着字边走还是会被看成压字
1294
+ const pad = 5
1295
+ const rect = ctx.hideLabels && !node.coord
1296
+ ? null
1297
+ : (p.labelUp
1298
+ ? { x0: p.x - half - pad + sh, x1: p.x + half + pad + sh, y0: p.y - p.pod / 2 - gap - labelH - 2, y1: p.y - p.pod / 2 - 3 }
1299
+ : { x0: p.x - half - pad + sh, x1: p.x + half + pad + sh, y0: p.y + p.pod / 2 + 3, y1: p.y + p.pod / 2 + gap + labelH + 2 })
1300
+ pods.push({ id: node.id, x: p.x, y: p.y, pod: p.pod, rect })
1301
+ }
1302
+ const filterId = 'dsb-soft-' + ctx.uid
1303
+ const beams = []
1304
+ edgesOf(group).forEach((edge, i) => {
1305
+ const a = L.pos[edge.from]
1306
+ const b = L.pos[edge.to]
1307
+ if (!a || !b) return
1308
+ const route = routeBeam(
1309
+ { id: edge.from, x: a.x, y: a.y, pod: a.pod, isCenter: a.isCenter },
1310
+ { id: edge.to, x: b.x, y: b.y, pod: b.pod, isCenter: b.isCenter },
1311
+ L, pods, W, H,
1312
+ )
1313
+ beams.push(h(Fragment, { key: edge.from + '>' + edge.to + ':' + edge.kind + ':' + i },
1314
+ beamElements(edge, route, ctx.uid + '-' + i, ctx.motion, filterId)))
1315
+ })
1316
+ const orbit = !L.strip && (L.ringCount > 2 || (modeKey === 'solo' && L.ringCount > 0))
1317
+ ? h('ellipse', { key: 'orbit', className: 'dsb-orbit', cx: L.center.x.toFixed(1), cy: L.center.y.toFixed(1), rx: L.rx.toFixed(1), ry: L.ry.toFixed(1) })
1318
+ : null
1319
+ const svg = h('svg', {
1320
+ key: 'beams', className: 'dsb-beams', viewBox: '0 0 ' + W + ' ' + H,
1321
+ 'aria-hidden': 'true', focusable: 'false',
1322
+ },
1323
+ h('defs', null,
1324
+ h('filter', { id: filterId, x: '-40%', y: '-40%', width: '180%', height: '180%' },
1325
+ h('feGaussianBlur', { stdDeviation: 3.2, result: 'b' }),
1326
+ h('feMerge', null, h('feMergeNode', { in: 'b' }), h('feMergeNode', { in: 'SourceGraphic' })))),
1327
+ orbit,
1328
+ beams)
1329
+ return [svg].concat(group.nodes.map((node) => {
1330
+ const p = L.pos[node.id]
1331
+ return p ? podElement(node, p, effMode, ctx) : null
1332
+ }))
1333
+ }
1334
+
1335
+ // ── 组件:任务卡 ──
1336
+ function HiveCard({ group, index, stageW, availH, budget, fill, modeKey, density, motion, onOpenSession }) {
1337
+ const natural = useMemo(
1338
+ () => (stageW ? layoutHive(group.nodes, stageW, availH, modeKey, 0, density).height : 0),
1339
+ [group, stageW, availH, modeKey, density],
1340
+ )
1341
+ const strip = !fill && budget != null && budget < natural + HIVE_HEAD_H
1342
+ const probe = useMemo(
1343
+ () => (strip && stageW ? layoutStrip(group.nodes, stageW, 0, modeKey, density).height : natural),
1344
+ [strip, group, stageW, modeKey, natural, density],
1345
+ )
1346
+ const stageH = fill ? null : (strip ? Math.max(probe, budget - HIVE_HEAD_H) : natural)
1347
+ const [box, setBox] = useState(null)
1348
+ const ref = useRef(null)
1349
+ useLayoutEffect(() => {
1350
+ const el = ref.current
1351
+ if (!el) return
1352
+ const w = Math.round(el.clientWidth)
1353
+ const hgt = Math.round(el.clientHeight)
1354
+ if (hgt <= 0) return
1355
+ setBox((prev) => (prev && Math.abs(prev.w - w) <= 1 && Math.abs(prev.h - hgt) <= 1 ? prev : { w, h: hgt }))
1356
+ })
1357
+ const W = box ? box.w : stageW
1358
+ const H = box ? box.h : (stageH || availH)
1359
+ const L = useMemo(
1360
+ () => (W ? (strip ? layoutStrip(group.nodes, W, H, modeKey, density) : layoutHive(group.nodes, W, availH, modeKey, H, density)) : null),
1361
+ [group, W, H, availH, modeKey, strip, density],
1362
+ )
1363
+ if (!L) return null
1364
+ const coord = group.nodes.find((n) => n.coord) || group.nodes[0]
1365
+ const botCount = group.nodes.filter((n) => !n.isUser).length
1366
+ const waitCount = group.nodes.filter((n) => n.activeStatus === 'waiting').length
1367
+ return h('section', {
1368
+ className: 'dsb-task',
1369
+ 'data-mode': strip ? 'strip' : (L.hideMeta ? 'crowd' : modeKey),
1370
+ 'data-active-group': group.id,
1371
+ style: { '--dsb-card-tint': tintOf(coord && coord.color) },
1372
+ },
1373
+ h('div', { className: 'dsb-task__head' },
1374
+ h('span', { className: 'dsb-task__dot' }),
1375
+ h('span', { className: 'dsb-task__name', title: group.label }, group.label),
1376
+ h('span', { className: 'dsb-task__stats' },
1377
+ h('b', null, String(botCount)), 'Bot',
1378
+ waitCount ? h(Fragment, null, ' · ', h('b', { className: 'dsb-amber' }, String(waitCount)), '等待') : null)),
1379
+ h('div', {
1380
+ className: 'dsb-stage',
1381
+ ref,
1382
+ // 舞台密度:名字块字号 / 冠标 / 标签间距跟着舱体一起缩
1383
+ style: Object.assign({ '--dsb-pk': String(density) }, stageH != null ? { height: stageH } : null),
1384
+ },
1385
+ stageElements(group, L, W, H, strip ? 'strip' : modeKey, { motion, uid: 'dsb' + index, density, hideLabels: !!L.hideLabels, onOpenSession })))
1386
+ }
1387
+
1388
+ // ── 组件:画布(量宽高 → 算自然高度 → 放不下时按预算分给各卡) ──
1389
+ function HiveCanvas({ groups, modeKey, motion, onOpenSession }) {
1390
+ const ref = useRef(null)
1391
+ const [size, setSize] = useState({ w: 0, h: 0 })
1392
+ useLayoutEffect(() => {
1393
+ const el = ref.current
1394
+ if (!el) return undefined
1395
+ const measure = () => {
1396
+ const w = Math.round(el.clientWidth)
1397
+ const hgt = Math.round(el.clientHeight)
1398
+ setSize((prev) => (prev.w === w && prev.h === hgt ? prev : { w, h: hgt }))
1399
+ }
1400
+ measure()
1401
+ if (typeof ResizeObserver === 'undefined') return undefined
1402
+ const ro = new ResizeObserver(measure)
1403
+ ro.observe(el)
1404
+ return () => ro.disconnect()
1405
+ }, [])
1406
+ const cols = size.w >= 760 && groups.length > 1 ? 2 : 1
1407
+ const rows = Math.max(1, Math.ceil(groups.length / cols))
1408
+ const stageW = size.w ? Math.max(140, Math.floor((size.w - HIVE_PAD_X * 2 - HIVE_GAP * (cols - 1)) / cols) - 2) : 0
1409
+ const availH = size.h ? Math.max(120, Math.floor((size.h - HIVE_PAD_Y - HIVE_GAP * (rows - 1)) / rows) - HIVE_HEAD_H) : 0
1410
+ // 舞台密度:窄侧栏里舱体 / 名字块 / 留白整体等比收紧,宽面板保持标准尺寸
1411
+ const density = stageW ? densityOf(modeKey, stageW) : 1
1412
+ const naturals = useMemo(
1413
+ () => (stageW ? groups.map((g) => layoutHive(g.nodes, stageW, availH, modeKey, 0, density).height + HIVE_HEAD_H) : []),
1414
+ [groups, stageW, availH, modeKey, density],
1415
+ )
1416
+ // 单任务 + 窄面板 + 星团远小于舞台:卡片贴着星团、垂直居中,别让一整块玻璃舱里只飘着两三颗舱体。
1417
+ // (宽面板不启用:那里舱体还能按纵向富余放大一档,卡片铺满更气派。)
1418
+ const compact = groups.length === 1 && density < 0.999 && !!size.h && naturals.length === 1 && naturals[0] < (size.h - HIVE_PAD_Y) * 0.62
1419
+ const fill = groups.length === 1 && !compact && singleTaskFills(naturals[0], size.h)
1420
+ const cardAvailH = compact ? Math.max(120, naturals[0] - HIVE_HEAD_H) : availH
1421
+ const budget = useMemo(() => {
1422
+ if (fill || !size.h || groups.length < 2 || !naturals.length) return null
1423
+ const rowNeed = []
1424
+ for (let r = 0; r < rows; r++) {
1425
+ let m = 0
1426
+ for (let c = 0; c < cols; c++) {
1427
+ const i = r * cols + c
1428
+ if (i < groups.length) m = Math.max(m, naturals[i])
1429
+ }
1430
+ rowNeed.push(m)
1431
+ }
1432
+ const need = rowNeed.reduce((a, b) => a + b, 0) + (rows - 1) * HIVE_GAP
1433
+ if (need <= size.h - HIVE_PAD_Y + 1) return null
1434
+ const free = size.h - HIVE_PAD_Y - (rows - 1) * HIVE_GAP
1435
+ if (cols === 1) {
1436
+ const weights = groups.map((g) => Math.pow(g.nodes.length, 0.7))
1437
+ const total = weights.reduce((a, b) => a + b, 0)
1438
+ return weights.map((w) => Math.floor((free * w) / total))
1439
+ }
1440
+ return groups.map(() => Math.floor(free / rows))
1441
+ }, [fill, size.h, groups, naturals, rows, cols])
1442
+
1443
+ return h('div', {
1444
+ className: 'dsb-canvas',
1445
+ ref,
1446
+ 'data-cols': String(cols),
1447
+ 'data-fill': fill ? 'true' : 'false',
1448
+ 'data-center': compact ? 'true' : 'false',
1449
+ 'data-empty': groups.length ? 'false' : 'true',
1450
+ },
1451
+ groups.length
1452
+ ? groups.map((group, i) => h(HiveCard, {
1453
+ key: group.id,
1454
+ group,
1455
+ index: i,
1456
+ stageW,
1457
+ availH: cardAvailH,
1458
+ budget: budget ? budget[i] : null,
1459
+ fill,
1460
+ modeKey,
1461
+ density,
1462
+ motion,
1463
+ onOpenSession,
1464
+ }))
1465
+ : h(HiveEmpty))
1466
+ }
1467
+
1468
+ function HiveEmpty() {
1469
+ return h('div', { className: 'dsb-empty' },
1470
+ h('div', { className: 'dsb-empty__orbit' }),
1471
+ h('div', null,
1472
+ h('div', { className: 'dsb-empty__core' }, h(BrandGlyph, { size: 22, stroke: 1.6 })),
1473
+ h('div', { className: 'dsb-empty__title' }, '全员待命'),
1474
+ h('div', { className: 'dsb-empty__sub' }, '在会话里 @ 一个 Bot,星轨就会亮起来')))
1475
+ }
1476
+
1477
+ // ── 组件:HUD / 页签 / 待机坞 ──
1478
+ function HiveHud({ groups, botTotal, waiting, idleCount, stale, themeName, motionOn, onToggleTheme, onToggleMotion }) {
1479
+ const working = Math.max(0, botTotal - waiting)
1480
+ return h('div', { className: 'dsb-hud' },
1481
+ h('div', { className: 'dsb-hud__brand' }, h(BrandGlyph, { size: 18 })),
1482
+ h('div', null,
1483
+ h('div', { className: 'dsb-hud__title' },
1484
+ 'Starboard',
1485
+ h('span', {
1486
+ className: 'dsb-hud__live',
1487
+ 'data-stale': stale ? 'true' : 'false',
1488
+ title: stale ? '数据已陈旧,下一轮自动重试' : '数据已同步',
1489
+ })),
1490
+ h('div', { className: 'dsb-hud__sub', 'aria-live': 'polite', 'aria-atomic': 'true' },
1491
+ h('b', null, String(groups)), ' 个任务 · ',
1492
+ h('b', null, String(botTotal)), ' Bot 在岗',
1493
+ waiting ? h(Fragment, null, ' · ', h('b', { className: 'dsb-amber' }, String(waiting)), ' 等待') : null)),
1494
+ h('div', { className: 'dsb-hud__actions' },
1495
+ h('button', {
1496
+ type: 'button', className: 'dsb-hud__btn', onClick: onToggleTheme,
1497
+ title: themeName === 'dark' ? '切换浅色' : '切换深色',
1498
+ 'aria-label': themeName === 'dark' ? '切换浅色' : '切换深色',
1499
+ }, h(HudIcon, { name: themeName === 'dark' ? 'sun' : 'moon', size: 15 })),
1500
+ h('button', {
1501
+ type: 'button', className: 'dsb-hud__btn', onClick: onToggleMotion,
1502
+ title: motionOn ? '暂停动效' : '开启动效',
1503
+ 'aria-label': motionOn ? '暂停动效' : '开启动效',
1504
+ 'aria-pressed': motionOn ? 'true' : 'false',
1505
+ 'data-active': motionOn ? 'true' : 'false',
1506
+ }, h(HudIcon, { name: motionOn ? 'motion' : 'still', size: 15 }))),
1507
+ h('div', { className: 'dsb-hud__meter', 'aria-hidden': 'true' },
1508
+ working ? h('i', { className: 'dsb-m-work', style: { flex: working } }) : null,
1509
+ waiting ? h('i', { className: 'dsb-m-wait', style: { flex: waiting } }) : null,
1510
+ h('i', { className: 'dsb-m-idle', style: { flex: Math.max(1, idleCount) } })))
1511
+ }
1512
+
1513
+ function HiveTabs({ options, scope, onSelect }) {
1514
+ return h('div', { className: 'dsb-tabs', role: 'group', 'aria-label': '按活跃任务筛选' },
1515
+ h('button', {
1516
+ type: 'button', className: 'dsb-tab', onClick: () => onSelect('all'),
1517
+ 'aria-pressed': scope === 'all' ? 'true' : 'false',
1518
+ style: { '--dsb-tint': '124,141,255' },
1519
+ }, h('i'), '全部'),
1520
+ options.map((item) => h('button', {
1521
+ key: item.id, type: 'button', className: 'dsb-tab', onClick: () => onSelect(item.id),
1522
+ 'aria-pressed': scope === item.id ? 'true' : 'false',
1523
+ title: item.label,
1524
+ style: { '--dsb-tint': item.tint || '124,141,255' },
1525
+ }, h('i'), item.label)))
1526
+ }
1527
+
1528
+ function HiveDock({ bots, motion, density, onOpenSession }) {
1529
+ // 待机坞跟着面板密度缩:窄侧栏里头像与格子一起变小(默认 30px 格子 / 18px 头像)
1530
+ const d = density == null ? 1 : density
1531
+ const glyphSize = Math.round(18 * d)
1532
+ const boxSize = Math.round(20 * d)
1533
+ return h('div', { className: 'dsb-dock', 'data-dsbot-board-dock': '' },
1534
+ h('div', { className: 'dsb-dock__head' }, '待命 ', h('b', null, String(bots.length)), ' · 随时可派活'),
1535
+ h('div', { className: 'dsb-dock__row' }, bots.map((bot, i) => {
1536
+ const avatar = bot.avatar || {}
1537
+ const mark = avatar.shape ? characterMarkupOf(avatar.shape, glyphSize) : null
1538
+ const glyph = mark
1539
+ ? h('svg', {
1540
+ width: glyphSize, height: glyphSize, viewBox: '-50 -50 100 100', 'aria-hidden': 'true', focusable: 'false',
1541
+ // 尺寸写进 style:宿主里有 button > svg 之类的全局规则,只带 width/height 属性会被压成几像素
1542
+ style: { width: glyphSize, height: glyphSize, display: 'block', flex: '0 0 auto' },
1543
+ },
1544
+ renderCharacter(h, {
1545
+ def: mark.def, id: mark.id, r: 50, color: bot.color,
1546
+ uid: 'dsbdock' + i, status: 'idle', reducedMotion: !motion, active: false,
1547
+ blinkDelay: -((i * 0.73) % 3.1), seed: bot.name, nodeKey: bot.id,
1548
+ // 待机坞 18px 走极简:纯色身体,不建渐变/遮罩,宿主里 url(#id) 偶发失效时不会只剩眼睛
1549
+ simple: true,
1550
+ }))
1551
+ : h('span', { className: 'dsb-dock__letter' }, String(bot.name || '?').slice(0, 1))
1552
+ const inner = avatar.image
1553
+ ? h(AvatarImg, {
1554
+ src: avatar.image,
1555
+ alt: '',
1556
+ style: { width: boxSize, height: boxSize, borderRadius: '50%', objectFit: 'cover', display: 'block' },
1557
+ fallback: glyph,
1558
+ })
1559
+ : glyph
1560
+ return h('button', {
1561
+ key: bot.id,
1562
+ type: 'button',
1563
+ className: 'dsb-dock__item',
1564
+ title: bot.name,
1565
+ 'aria-label': '打开 ' + bot.name + ' 的会话',
1566
+ onClick: () => { if (onOpenSession) onOpenSession({ botId: bot.id, key: bot.id, name: bot.name }) },
1567
+ }, h('span', { className: 'dsb-dock__glyph' }, inner))
1568
+ })))
1569
+ }
1570
+
1571
+ function HiveSkeleton() {
1572
+ return h('div', { className: 'dsb-skeleton', 'data-dsbot-board-skeleton': '' },
1573
+ h('div', { className: 'dsb-skeleton__row', style: { width: '42%', height: 14 } }),
1574
+ h('div', { className: 'dsb-skeleton__row', style: { width: '100%', height: 1, opacity: 0.5 } }),
1575
+ h('div', { className: 'dsb-skeleton__stage' },
1576
+ h('div', { className: 'dsb-skeleton__dot', style: { left: '18%', top: '22%', width: 72, height: 72 } }),
1577
+ h('div', { className: 'dsb-skeleton__dot', style: { right: '16%', top: '48%', width: 88, height: 88 } }),
1578
+ h('div', { className: 'dsb-skeleton__dot', style: { left: '46%', top: '68%', width: 64, height: 64 } })),
1579
+ h('div', { className: 'dsb-skeleton__row', style: { width: '100%', height: 44 } }))
1580
+ }
1581
+
1582
+ function HiveError({ message, onRetry }) {
1583
+ return h('div', { className: 'dsb-error' },
1584
+ h('div', { className: 'dsb-error__box' },
1585
+ h('div', { className: 'dsb-error__icon' }, h(HudIcon, { name: 'alert', size: 24 })),
1586
+ h('div', { className: 'dsb-error__title' }, '数据通道没通'),
1587
+ h('div', { className: 'dsb-error__msg' }, message),
1588
+ h('button', { type: 'button', className: 'dsb-retry', onClick: onRetry },
1589
+ h(HudIcon, { name: 'refresh', size: 14 }), '重试')))
1590
+ }
1591
+
1592
+ // ── 根组件 ──
1593
+ function BoardView(props) {
1594
+ const {
1595
+ phase, message, board, bots, failed, lastChecked, lastUpdated,
1596
+ themeName, themeVars, onToggleTheme, motionOn, onToggleMotion,
1597
+ scope, onSelectScope, onRetry, onOpenSession,
1598
+ } = props
1599
+ const vars = Object.assign({}, HIVE_VARS[themeName] || HIVE_VARS.dark, themeVars || {})
1600
+ // 面板宽度 → 外围 chrome 密度:侧栏拖窄时 HUD / 页签 / 待机坞 / 卡片圆角一起收紧
1601
+ const rootRef = useRef(null)
1602
+ const [panelW, setPanelW] = useState(0)
1603
+ useLayoutEffect(() => {
1604
+ const el = rootRef.current
1605
+ if (!el) return undefined
1606
+ const measure = () => {
1607
+ const w = Math.round(el.clientWidth)
1608
+ setPanelW((prev) => (prev === w ? prev : w))
1609
+ }
1610
+ measure()
1611
+ if (typeof ResizeObserver === 'undefined') return undefined
1612
+ const ro = new ResizeObserver(measure)
1613
+ ro.observe(el)
1614
+ return () => ro.disconnect()
1615
+ }, [])
1616
+ const chromeK = chromeDensityOf(panelW)
1617
+ const reduced = useMemo(() => {
1618
+ try { return !!(window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) } catch (error) { return false }
1619
+ }, [])
1620
+ const motion = motionOn !== false && !reduced
1621
+ const groups = (board && board.groups) || []
1622
+ const visible = scope === 'all' ? groups : groups.filter((g) => g.id === scope)
1623
+ const modeKey = visible.length >= 3 ? 'crowd' : visible.length === 2 ? 'duo' : 'solo'
1624
+ const activeIds = useMemo(() => {
1625
+ const set = {}
1626
+ for (const g of groups) for (const n of g.nodes) if (!n.isUser) set[n.id] = 1
1627
+ return set
1628
+ }, [groups])
1629
+ const idle = useMemo(() => {
1630
+ const list = (bots || []).filter((b) => !activeIds[b.id])
1631
+ try {
1632
+ // 待机坞头像也走 hostLookOf:必须和宿主会话列表、和舱体里那只完全是同一个角色。
1633
+ return list.map((b) => {
1634
+ const look = hostLookOf(b)
1635
+ return { ...b, color: look.color, avatar: { ...(b.avatar || {}), shape: look.shape } }
1636
+ })
1637
+ } catch (error) {
1638
+ return list
1639
+ }
1640
+ }, [bots, activeIds])
1641
+ const botTotal = board ? board.activeCount : 0
1642
+ const waiting = board ? board.waitingCount : 0
1643
+ const stale = phase === 'ok' && (failed > 0 || Date.now() - (lastChecked || lastUpdated || 0) > 15000)
1644
+ const tabOptions = groups.map((g) => {
1645
+ const coord = g.nodes.find((n) => n.coord) || g.nodes[0]
1646
+ return { id: g.id, label: g.label, tint: tintOf(coord && coord.color) }
1647
+ })
1648
+
1649
+ let content
1650
+ if (phase === 'loading') {
1651
+ content = h(HiveSkeleton)
1652
+ } else if (phase === 'error') {
1653
+ content = h(HiveError, { message, onRetry })
1654
+ } else {
1655
+ content = h(HiveCanvas, { groups: visible, modeKey, motion, onOpenSession })
1656
+ }
1657
+
1658
+ return h('div', {
1659
+ className: 'dsb-root' + (motion ? '' : ' dsb-motion-off'),
1660
+ ref: rootRef,
1661
+ style: Object.assign({}, vars, { '--dsb-k': String(chromeK) }),
1662
+ 'data-dsbot-board-shell': '',
1663
+ },
1664
+ phase === 'ok'
1665
+ ? h(HiveHud, {
1666
+ groups: groups.length,
1667
+ botTotal,
1668
+ waiting,
1669
+ idleCount: idle.length,
1670
+ stale,
1671
+ themeName,
1672
+ motionOn: motionOn !== false,
1673
+ onToggleTheme,
1674
+ onToggleMotion,
1675
+ })
1676
+ : null,
1677
+ phase === 'ok' && groups.length > 1
1678
+ ? h(HiveTabs, { options: tabOptions, scope, onSelect: onSelectScope })
1679
+ : null,
1680
+ phase === 'ok' && failed
1681
+ ? h('div', { className: 'dsb-banner', role: 'status' },
1682
+ h(HudIcon, { name: 'alert', size: 13 }), '部分空间读取失败,正在自动重试')
1683
+ : null,
1684
+ content,
1685
+ phase === 'ok' && idle.length ? h(HiveDock, { bots: idle, motion, density: chromeK, onOpenSession }) : null)
1686
+ }
1687
+
1688
+ // 供回归测试直接驱动纯布局/布线函数(不依赖 DOM)
1689
+ BoardView.__hive = {
1690
+ HIVE_MODES, naturalWidthOf, densityOf, chromeDensityOf,
1691
+ edgesOf, anglesFor, evenAngles, minSpacing, estimateLabelWidth,
1692
+ resolveLabels, layoutHive, layoutStrip, routeBeam, curveLength, pointAt, collides, singleTaskFills,
1693
+ }
1694
+ return BoardView
1695
+ }
1696
+
1697
+ return { createBoardView, hiveStyleText, hostLookOf }
1698
+ })()
1699
+ const { createBoardView, hiveStyleText, hostLookOf } = boardViewModule
1700
+
1701
+ const listOf = (v) => (Array.isArray(v) ? v : v && typeof v === 'object' ? Object.values(v) : [])
1702
+ const pick = (obj, keys, fallback) => {
1703
+ for (const key of keys) {
1704
+ const value = obj ? obj[key] : undefined
1705
+ if (value !== undefined && value !== null && value !== '') return value
1706
+ }
1707
+ return fallback
1708
+ }
1709
+
1710
+ // 全局聚合:把「所有群」+「所有 Bot 私聊」的协作拼成一条统一事件流。
1711
+ // 由 .build-client.cjs 内联;不能有 import/export。
1712
+
1713
+ // 一个会话的一条消息 → 统一事件。
1714
+ // source 字段来自 room-chat / chat 的行:{ id, kind, botId, name, text, time, sessionId, turn, messageId }
1715
+ function toBoardEvent(row, ctx) {
1716
+ const kind = String(pick(row, ['kind'], 'message'))
1717
+ const text = String(pick(row, ['text', 'body'], ''))
1718
+ const botId = String(pick(row, ['botId', 'bot', 'fromId'], '') || '')
1719
+ const name = pick(row, ['name', 'who'], '') || ''
1720
+ const seq = pick(row, ['seq'], null)
1721
+ const mid = pick(row, ['messageId', 'id'], null)
1722
+ const isUser = kind === 'user' || (!botId && /^user$/i.test(name))
1723
+ return {
1724
+ key: ctx.scope + '|' + (mid == null ? ctx.i : mid),
1725
+ scope: ctx.scope, // 'room:<id>' 或 'bot:<id>'
1726
+ scopeLabel: ctx.scopeLabel,
1727
+ kind,
1728
+ botId,
1729
+ name: isUser ? 'User' : name,
1730
+ isUser,
1731
+ text,
1732
+ time: pick(row, ['time', 'at'], null),
1733
+ turn: pick(row, ['turn'], null),
1734
+ messageId: mid,
1735
+ seq: seq == null ? ctx.i : seq,
1736
+ order: ctx.order + ctx.i, // 跨会话的稳定排序:先群后私聊,各自按行序
1737
+ }
1738
+ }
1739
+
1740
+ // @ 提及:从文本里解析出被叫到的名字,供画边使用。
1741
+ // 关键:名字允许含空格(Lead Bot、Software Engineer),所以不能按空白切词。
1742
+ // 做法是「长名字优先」在原文里直接找 @名字,找到多长的就吃多长,剩下才按短名匹配。
1743
+ function mentionsOf(text, names) {
1744
+ const out = []
1745
+ const source = String(text || '')
1746
+ const list = (names || []).filter(Boolean)
1747
+ if (!list.length) return out
1748
+ // 长的排前面:@Software Engineer 必须先于 @Software 被吃掉。
1749
+ const ordered = list.slice().sort((a, b) => b.length - a.length)
1750
+ let rest = source
1751
+ for (const name of ordered) {
1752
+ const token = '@' + name
1753
+ if (!rest.includes(token)) continue
1754
+ // 还要求后面不是紧跟一个会把它变成更长名字的字符。
1755
+ let idx = rest.indexOf(token)
1756
+ let taken = 0
1757
+ while (idx >= 0) {
1758
+ const after = rest.charAt(idx + token.length)
1759
+ const isBoundary = !after || /[\s@,,。::;;!!??、.]/.test(after)
1760
+ if (isBoundary) {
1761
+ out.push(name)
1762
+ taken++
1763
+ rest = rest.slice(0, idx) + rest.slice(idx + token.length)
1764
+ }
1765
+ idx = rest.indexOf(token, idx + 1)
1766
+ if (idx < 0) break
1767
+ }
1768
+ if (taken) continue
1769
+ }
1770
+ return out
1771
+ }
1772
+
1773
+ // 头像派生统一走 characters-view.js 的 hostLookOf()(与宿主 ds-bot 的 lookOf() 同一套 id 哈希),
1774
+ // 以前那套"按名字派生 + localStorage 注册表避让"会让同一个 bot 在看板和宿主列表里长成两只,已整体废弃。
1775
+
1776
+ // 全局快照 → 组件输入(nodes + messages)。
1777
+ // snapshot: { bots, rooms, roomItems: {roomId: rows}, botItems: {botId: rows} }
1778
+ function buildGlobalBoard(snapshot, opts) {
1779
+ const options = opts || {}
1780
+ const includePrivate = options.includePrivate !== false
1781
+ const bots = listOf(snapshot.bots)
1782
+ const rooms = listOf(snapshot.rooms)
1783
+ const roomItems = snapshot.roomItems || {}
1784
+ const botItems = snapshot.botItems || {}
1785
+
1786
+ const botById = new Map(bots.map((b) => [b.id, b]))
1787
+ const events = []
1788
+ let order = 0
1789
+
1790
+ for (const room of rooms) {
1791
+ const rows = listOf(roomItems[room.id])
1792
+ const label = room.name || room.id
1793
+ rows.forEach((row, i) => {
1794
+ events.push(toBoardEvent(row, { scope: 'room:' + room.id, scopeLabel: label, order, i }))
1795
+ })
1796
+ order += rows.length
1797
+ }
1798
+ if (includePrivate) {
1799
+ for (const bot of bots) {
1800
+ const rows = listOf(botItems[bot.id])
1801
+ if (!rows.length) continue
1802
+ const label = (bot.name || bot.id) + ' · 私聊'
1803
+ rows.forEach((row, i) => {
1804
+ events.push(toBoardEvent(row, { scope: 'bot:' + bot.id, scopeLabel: label, order, i }))
1805
+ })
1806
+ order += rows.length
1807
+ }
1808
+ }
1809
+ // 排序必须按消息时间,不能按「先群后私聊」的遍历顺序:
1810
+ // 否则一条更旧的私聊会拿到更大的下标,被当成当前消息,回放和状态全错。
1811
+ // 没有时间戳的(或时间相同)才用遍历顺序兜底。
1812
+ const timeOf = (e) => {
1813
+ const t = e.time
1814
+ if (typeof t === 'number' && Number.isFinite(t)) return t
1815
+ if (typeof t === 'string') {
1816
+ const parsed = Date.parse(t)
1817
+ if (Number.isFinite(parsed)) return parsed
1818
+ }
1819
+ return null
1820
+ }
1821
+ events.sort((a, b) => {
1822
+ const ta = timeOf(a), tb = timeOf(b)
1823
+ if (ta != null && tb != null && ta !== tb) return ta - tb
1824
+ // 一方没有时间:保持遍历顺序(不能把未知时间当成最早)。
1825
+ if (ta == null && tb != null) return a.order - b.order
1826
+ if (tb == null && ta != null) return a.order - b.order
1827
+ return a.order - b.order
1828
+ })
1829
+
1830
+ // 节点:所有发过言或只被提及的 Bot + User。空会话且未被提及的 Bot 不占版面。
1831
+ const seen = new Set()
1832
+ for (const event of events) if (event.botId) seen.add(event.botId)
1833
+ const hasUser = events.some((event) => event.isUser)
1834
+ // 提及候选必须包含 User:Bot 回 @User 也是一条协作边,漏了它这条边就消失了。
1835
+ const names = bots.map((bot) => bot.name).filter(Boolean)
1836
+ if (hasUser) names.push('User')
1837
+ const mentionedNames = new Set()
1838
+ for (const event of events) {
1839
+ for (const target of mentionsOf(event.text, names)) mentionedNames.add(target)
1840
+ }
1841
+ for (const bot of bots) {
1842
+ if (bot.name && mentionedNames.has(bot.name)) seen.add(bot.id)
1843
+ }
1844
+
1845
+ const nodes = []
1846
+ for (const id of seen) {
1847
+ const bot = botById.get(id)
1848
+ if (!bot) continue
1849
+ // 头像三件套一律走 hostLookOf:跟宿主 ds-bot 的 lookOf() 同一套派生。
1850
+ const look = hostLookOf(bot)
1851
+ const botName = bot.name || String(id).slice(0, 8)
1852
+ nodes.push({
1853
+ id, key: id,
1854
+ name: botName,
1855
+ color: look.color,
1856
+ shape: look.shape,
1857
+ failed: bot.blocked !== undefined || bot.failed === true,
1858
+ ...(look.image ? { avatar: { image: look.image } } : {}),
1859
+ coord: false,
1860
+ })
1861
+ }
1862
+ if (hasUser) nodes.push({ id: '__user__', key: '__user__', name: 'User', isUser: true })
1863
+
1864
+ // 主控:发出最多跨 Bot 指令的那个,标 coord。
1865
+ const askCount = new Map()
1866
+ for (const e of events) {
1867
+ if (!e.botId) continue
1868
+ const targets = mentionsOf(e.text, names)
1869
+ if (targets.length) askCount.set(e.botId, (askCount.get(e.botId) || 0) + targets.length)
1870
+ }
1871
+ let topId = null, topCount = 0
1872
+ for (const [id, count] of askCount) if (count > topCount) { topId = id; topCount = count }
1873
+ for (const node of nodes) node.coord = node.id === topId
1874
+
1875
+ // 消息:seq 必须是全局顺序,不能沿用会话内序号——否则新私聊的 seq=0 会排到老群 seq=100 前面,
1876
+ // 回放和当前边都会错。原始序号另存 sourceSeq。
1877
+ const messages = events.map((e, i) => ({
1878
+ seq: i,
1879
+ sourceSeq: e.seq,
1880
+ who: e.name,
1881
+ botId: e.botId,
1882
+ text: e.text,
1883
+ // @ 解析对所有人一视同仁:User 也在候选里,Bot 回 @User 才不会丢边。
1884
+ to: mentionsOf(e.text, names),
1885
+ scope: e.scope,
1886
+ scopeLabel: e.scopeLabel,
1887
+ time: e.time,
1888
+ }))
1889
+
1890
+ const scopeOptions = []
1891
+ const scopeIds = new Set()
1892
+ for (const event of events) {
1893
+ if (scopeIds.has(event.scope)) continue
1894
+ scopeIds.add(event.scope)
1895
+ scopeOptions.push({ id: event.scope, label: event.scopeLabel })
1896
+ }
1897
+
1898
+ return {
1899
+ nodes,
1900
+ messages,
1901
+ scopes: [...new Set(events.map((event) => event.scopeLabel))],
1902
+ scopeOptions,
1903
+ }
1904
+ }
1905
+
1906
+ // 活跃任务聚合:只把正在工作或等待协作的 Bot 放进看板,并按任务连成独立图簇。
1907
+ // 数据来自 state.work / state.activity;聊天记录只取活跃空间最近的上下文。
1908
+
1909
+ function activeBoardTime(value) {
1910
+ if (typeof value === 'number' && Number.isFinite(value)) return value
1911
+ if (typeof value === 'string') {
1912
+ const parsed = Date.parse(value)
1913
+ if (Number.isFinite(parsed)) return parsed
1914
+ }
1915
+ return null
1916
+ }
1917
+
1918
+ function activeRoomIdsOf(work) {
1919
+ const ids = new Set(Object.keys(work.rooms || {}))
1920
+ for (const info of Object.values(work.bots || {})) if (info.roomId) ids.add(info.roomId)
1921
+ for (const roomId of listOf(work.activeRooms)) ids.add(roomId)
1922
+ for (const info of Object.values(work.waiting || {})) {
1923
+ for (const item of listOf(info.waits)) if (item.room) ids.add(item.room)
1924
+ }
1925
+ return [...ids]
1926
+ }
1927
+
1928
+ function activeBotIdsOf(work, activity) {
1929
+ const ids = new Set(Object.keys(work.bots || {}))
1930
+ for (const items of Object.values(work.rooms || {})) {
1931
+ for (const item of listOf(items)) if (item.botId) ids.add(item.botId)
1932
+ }
1933
+ for (const [botId, status] of Object.entries(activity || {})) {
1934
+ if (status === 'working' || status === 'thinking' || status === 'waiting' || status === 'alert') ids.add(botId)
1935
+ }
1936
+ for (const [ownerId, info] of Object.entries(work.waiting || {})) {
1937
+ ids.add(ownerId)
1938
+ for (const targetId of listOf(info.bots)) ids.add(targetId)
1939
+ for (const callerId of listOf(info.for)) ids.add(callerId)
1940
+ }
1941
+ return [...ids]
1942
+ }
1943
+
1944
+ function boardBotIdAliases(bots) {
1945
+ const aliases = new Map()
1946
+ for (const bot of listOf(bots)) {
1947
+ const id = String(bot.id || '')
1948
+ if (!id) continue
1949
+ aliases.set(id, id)
1950
+ aliases.set(id.replace(/^session-/, ''), id)
1951
+ }
1952
+ return aliases
1953
+ }
1954
+
1955
+ function resolveBoardBotId(id, aliases) {
1956
+ if (id == null) return null
1957
+ return aliases.get(String(id)) || null
1958
+ }
1959
+
1960
+ // `state` 的 unchanged 回答只带实时 work/activity,不再重复 bots/rooms。
1961
+ // 看板必须沿用上一次完整回答的清单,否则活跃 ID 会被误判为未知 Bot。
1962
+ function boardBaseFromState(state, cached) {
1963
+ if (state && state.unchanged === true && cached) return cached
1964
+ return { bots: listOf(state && state.bots), rooms: listOf(state && state.rooms) }
1965
+ }
1966
+
1967
+ function buildActiveBoard(snapshot, opts) {
1968
+ const options = opts || {}
1969
+ const bots = listOf(snapshot.bots)
1970
+ const rooms = listOf(snapshot.rooms)
1971
+ const roomItems = snapshot.roomItems || {}
1972
+ const botItems = snapshot.botItems || {}
1973
+ const work = snapshot.work || {}
1974
+ const activity = snapshot.activity || {}
1975
+ const waiting = work.waiting || {}
1976
+ const botById = new Map(bots.map((bot) => [bot.id, bot]))
1977
+ const botAliases = boardBotIdAliases(bots)
1978
+ const roomById = new Map(rooms.map((room) => [room.id, room]))
1979
+ const active = new Map()
1980
+
1981
+ function markActive(botId, info, preserveStatus = false, authoritative = false) {
1982
+ const canonicalId = resolveBoardBotId(botId, botAliases)
1983
+ if (!canonicalId || !botById.has(canonicalId)) return
1984
+ const previous = active.get(canonicalId)
1985
+ const previousAuthoritative = previous && previous.authoritative === true
1986
+ const next = { ...(previous || {}) }
1987
+ for (const [key, value] of Object.entries(info)) {
1988
+ if (value !== undefined) next[key] = value
1989
+ }
1990
+ if (preserveStatus && previousAuthoritative) next.status = previous.status
1991
+ else if (info.status !== undefined) next.status = info.status
1992
+ else if (!next.status) next.status = 'working'
1993
+ next.authoritative = authoritative || previousAuthoritative
1994
+ active.set(canonicalId, next)
1995
+ }
1996
+
1997
+ for (const [botId, info] of Object.entries(work.bots || {})) {
1998
+ markActive(botId, {
1999
+ status: 'working',
2000
+ roomId: info.roomId,
2001
+ since: info.since,
2002
+ tool: info.tool,
2003
+ note: info.note,
2004
+ })
2005
+ }
2006
+ for (const [roomId, items] of Object.entries(work.rooms || {})) {
2007
+ for (const item of listOf(items)) {
2008
+ markActive(item.botId, {
2009
+ status: 'working',
2010
+ roomId,
2011
+ since: item.since,
2012
+ tool: item.tool,
2013
+ note: item.note,
2014
+ })
2015
+ }
2016
+ }
2017
+ for (const [botId, status] of Object.entries(activity)) {
2018
+ if (status !== 'working' && status !== 'thinking' && status !== 'waiting' && status !== 'alert') continue
2019
+ markActive(botId, { status: status === 'alert' ? 'failed' : status }, false, true)
2020
+ }
2021
+ for (const [ownerId, info] of Object.entries(waiting)) {
2022
+ markActive(ownerId, { status: 'waiting' }, false, true)
2023
+ for (const targetId of listOf(info.bots)) markActive(targetId, { status: 'working' }, true)
2024
+ for (const callerId of listOf(info.for)) markActive(callerId, { status: 'working' }, true)
2025
+ }
2026
+
2027
+ if (active.size === 0) {
2028
+ return {
2029
+ groups: [], nodes: [], messages: [], scopeOptions: [], activeCount: 0, waitingCount: 0,
2030
+ }
2031
+ }
2032
+
2033
+ const parent = new Map([...active.keys()].map((id) => [id, id]))
2034
+ function find(id) {
2035
+ let current = id
2036
+ while (parent.get(current) !== current) current = parent.get(current)
2037
+ return current
2038
+ }
2039
+ function union(a, b) {
2040
+ if (!active.has(a) || !active.has(b) || a === b) return
2041
+ const rootA = find(a)
2042
+ const rootB = find(b)
2043
+ if (rootA !== rootB) parent.set(rootB, rootA)
2044
+ }
2045
+
2046
+ const roomGroups = new Map()
2047
+ for (const [roomId, items] of Object.entries(work.rooms || {})) {
2048
+ const ids = listOf(items)
2049
+ .map((item) => resolveBoardBotId(item.botId, botAliases))
2050
+ .filter((id) => id && active.has(id))
2051
+ if (!ids.length) continue
2052
+ roomGroups.set(roomId, ids)
2053
+ for (const id of ids) union(ids[0], id)
2054
+ }
2055
+ for (const [botId, info] of active) {
2056
+ if (!info.roomId) continue
2057
+ const ids = roomGroups.get(info.roomId) || []
2058
+ if (!ids.includes(botId)) ids.push(botId)
2059
+ roomGroups.set(info.roomId, ids)
2060
+ for (const id of ids) union(ids[0], id)
2061
+ }
2062
+
2063
+ const waitLinks = []
2064
+ for (const [rawOwnerId, info] of Object.entries(waiting)) {
2065
+ const ownerId = resolveBoardBotId(rawOwnerId, botAliases)
2066
+ if (!ownerId) continue
2067
+ for (const rawTargetId of listOf(info.bots)) {
2068
+ const targetId = resolveBoardBotId(rawTargetId, botAliases)
2069
+ if (!targetId || !active.has(targetId)) continue
2070
+ union(ownerId, targetId)
2071
+ waitLinks.push({ from: ownerId, to: targetId, scope: active.get(ownerId).roomId || 'bot:' + ownerId })
2072
+ }
2073
+ for (const rawCallerId of listOf(info.for)) {
2074
+ const callerId = resolveBoardBotId(rawCallerId, botAliases)
2075
+ if (!callerId || !active.has(callerId)) continue
2076
+ union(callerId, ownerId)
2077
+ waitLinks.push({ from: callerId, to: ownerId, scope: active.get(ownerId).roomId || 'bot:' + ownerId })
2078
+ }
2079
+ for (const item of listOf(info.waits)) {
2080
+ if (!item.room) continue
2081
+ for (const targetId of roomGroups.get(item.room) || []) {
2082
+ union(ownerId, targetId)
2083
+ waitLinks.push({ from: ownerId, to: targetId, scope: 'room:' + item.room })
2084
+ }
2085
+ }
2086
+ }
2087
+
2088
+ const events = []
2089
+ const activeRoomIds = new Set([...roomGroups.keys(), ...listOf(work.activeRooms)])
2090
+ for (const roomId of activeRoomIds) {
2091
+ const label = roomById.get(roomId)?.name || roomId
2092
+ listOf(roomItems[roomId]).slice(-60).forEach((row, index) => {
2093
+ events.push(toBoardEvent(row, { scope: 'room:' + roomId, scopeLabel: label, order: events.length, i: index }))
2094
+ })
2095
+ }
2096
+ for (const botId of active.keys()) {
2097
+ if (active.get(botId).roomId) continue
2098
+ const bot = botById.get(botId)
2099
+ const label = (bot?.name || botId) + ' · 私聊'
2100
+ listOf(botItems[botId]).slice(-60).forEach((row, index) => {
2101
+ events.push(toBoardEvent(row, { scope: 'bot:' + botId, scopeLabel: label, order: events.length, i: index }))
2102
+ })
2103
+ }
2104
+
2105
+ for (const event of events) {
2106
+ if (event.botId) event.botId = resolveBoardBotId(event.botId, botAliases) || event.botId
2107
+ }
2108
+
2109
+ const botNames = bots.map((bot) => bot.name).filter(Boolean)
2110
+ const activeNameToId = new Map()
2111
+ for (const botId of active.keys()) {
2112
+ const name = botById.get(botId)?.name
2113
+ if (name) activeNameToId.set(name, botId)
2114
+ }
2115
+
2116
+ function eventBelongsToCurrentWork(event) {
2117
+ const time = activeBoardTime(event.time)
2118
+ if (time == null) return true
2119
+ const senderStart = event.botId ? activeBoardTime(active.get(event.botId)?.since) : null
2120
+ if (senderStart != null) return time >= senderStart
2121
+ const participantIds = [event.botId]
2122
+ for (const name of mentionsOf(event.text, botNames)) {
2123
+ const botId = activeNameToId.get(name)
2124
+ if (botId) participantIds.push(botId)
2125
+ }
2126
+ const startTimes = participantIds
2127
+ .map((botId) => activeBoardTime(active.get(botId)?.since))
2128
+ .filter((value) => value != null)
2129
+ if (!startTimes.length) return true
2130
+ return startTimes.some((start) => time >= start)
2131
+ }
2132
+
2133
+ const relevantEvents = events.filter((event) => {
2134
+ if (!eventBelongsToCurrentWork(event)) return false
2135
+ if (event.isUser) return true
2136
+ if (active.has(event.botId)) return true
2137
+ return mentionsOf(event.text, botNames).some((name) => activeNameToId.has(name))
2138
+ })
2139
+ for (const event of relevantEvents) {
2140
+ if (!active.has(event.botId)) continue
2141
+ for (const name of mentionsOf(event.text, botNames)) {
2142
+ const targetId = activeNameToId.get(name)
2143
+ if (targetId) union(event.botId, targetId)
2144
+ }
2145
+ }
2146
+
2147
+ const components = new Map()
2148
+ for (const botId of active.keys()) {
2149
+ const root = find(botId)
2150
+ if (!components.has(root)) components.set(root, [])
2151
+ components.get(root).push(botId)
2152
+ }
2153
+
2154
+ function makeNode(botId) {
2155
+ const bot = botById.get(botId)
2156
+ // 头像三件套一律走 hostLookOf:跟宿主 ds-bot 的 lookOf() 同一套派生,看板和宿主列表必须是同一只。
2157
+ const look = hostLookOf(bot)
2158
+ const name = bot?.name || botId
2159
+ return {
2160
+ id: botId,
2161
+ key: botId,
2162
+ name,
2163
+ color: look.color,
2164
+ shape: look.shape,
2165
+ failed: bot?.blocked !== undefined || bot?.failed === true || active.get(botId).status === 'failed',
2166
+ activeStatus: active.get(botId).status,
2167
+ ...(look.image ? { avatar: { image: look.image } } : {}),
2168
+ coord: false,
2169
+ }
2170
+ }
2171
+
2172
+ const groups = []
2173
+ for (const component of components.values()) {
2174
+ const memberIds = new Set(component)
2175
+ const memberNames = new Set(component.map((id) => botById.get(id)?.name).filter(Boolean))
2176
+ const roomIds = [...roomGroups.entries()]
2177
+ .filter(([, ids]) => ids.some((id) => memberIds.has(id)))
2178
+ .map(([roomId]) => roomId)
2179
+ let label = ''
2180
+ if (roomIds.length === 1) label = roomById.get(roomIds[0])?.name || roomIds[0]
2181
+ else if (roomIds.length > 1) label = (roomById.get(roomIds[0])?.name || roomIds[0]) + ' +' + (roomIds.length - 1)
2182
+ else {
2183
+ const primary = component.map((id) => botById.get(id)).filter(Boolean)
2184
+ .sort((a, b) => a.name.localeCompare(b.name))[0]
2185
+ label = (primary?.name || component[0]) + ' · 协作'
2186
+ }
2187
+ const groupId = roomIds.length === 1 ? 'room:' + roomIds[0] : 'task:' + component.slice().sort()[0]
2188
+
2189
+ const groupEvents = relevantEvents.filter((event) => {
2190
+ if (event.isUser) return mentionsOf(event.text, [...memberNames]).some((name) => memberNames.has(name))
2191
+ if (memberIds.has(event.botId)) return true
2192
+ return mentionsOf(event.text, [...memberNames]).some((name) => memberNames.has(name))
2193
+ })
2194
+ const syntheticWaits = waitLinks
2195
+ .filter((link) => memberIds.has(link.from) && memberIds.has(link.to))
2196
+ .map((link, index) => ({
2197
+ seq: index,
2198
+ who: botById.get(link.from)?.name || link.from,
2199
+ botId: link.from,
2200
+ text: '',
2201
+ to: [botById.get(link.to)?.name || link.to],
2202
+ scope: groupId,
2203
+ scopeLabel: label,
2204
+ time: Date.now(),
2205
+ synthetic: true,
2206
+ }))
2207
+ const allEvents = groupEvents.concat(syntheticWaits).sort((a, b) => {
2208
+ const timeA = activeBoardTime(a.time)
2209
+ const timeB = activeBoardTime(b.time)
2210
+ if (timeA != null && timeB != null && timeA !== timeB) return timeA - timeB
2211
+ return a.seq - b.seq
2212
+ })
2213
+
2214
+ const nodes = component.map(makeNode)
2215
+ if (groupEvents.some((event) => event.isUser)) {
2216
+ nodes.push({ id: '__user__', key: '__user__', name: 'User', isUser: true, activeStatus: 'user' })
2217
+ }
2218
+ const rawAdminId = roomIds.length === 1 ? roomById.get(roomIds[0])?.admin : null
2219
+ const roomAdminId = resolveBoardBotId(rawAdminId, botAliases)
2220
+ const coordId = roomAdminId && memberIds.has(roomAdminId)
2221
+ ? roomAdminId
2222
+ : component.find((id) => waitLinks.some((link) => link.from === id)) || component[0]
2223
+ for (const node of nodes) node.coord = node.id === coordId
2224
+
2225
+ const messages = allEvents.map((event, index) => ({
2226
+ seq: index,
2227
+ sourceSeq: event.seq,
2228
+ who: event.name,
2229
+ botId: event.botId,
2230
+ text: event.text,
2231
+ to: event.synthetic ? event.to : mentionsOf(event.text, [...memberNames, 'User']),
2232
+ scope: groupId,
2233
+ scopeLabel: label,
2234
+ time: event.time,
2235
+ synthetic: event.synthetic === true,
2236
+ }))
2237
+ groups.push({ id: groupId, label, nodes, messages, coordId })
2238
+ }
2239
+
2240
+ groups.sort((a, b) => a.label.localeCompare(b.label))
2241
+ const scopeOptions = groups.map((group) => ({ id: group.id, label: group.label }))
2242
+ const nodes = groups.flatMap((group) => group.nodes)
2243
+ const messages = groups.flatMap((group) => group.messages)
2244
+ const waitingCount = nodes.filter((node) => node.activeStatus === 'waiting').length
2245
+ return {
2246
+ groups, nodes, messages, scopeOptions, activeCount: active.size, waitingCount,
2247
+ }
2248
+ }
2249
+
2250
+ // Starboard 外壳与数据接线。由 .build-client.cjs 内联进宿主模块工厂。
2251
+ // 这里不能用 import/export:整段会原样内联。
2252
+
2253
+ const mark = (text) => {
2254
+ try { window.localStorage.setItem('__dsbotBoardProbe', String(text)) } catch {}
2255
+ }
2256
+
2257
+ const REQUEST_TIMEOUT_MS = 8000
2258
+
2259
+ async function askApi(endpoint, payload) {
2260
+ const controller = new AbortController()
2261
+ const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
2262
+ try {
2263
+ const res = await fetch('/api/bot', {
2264
+ method: 'POST',
2265
+ credentials: 'same-origin',
2266
+ headers: { 'content-type': 'application/json' },
2267
+ body: JSON.stringify({ endpoint, payload: payload || {} }),
2268
+ signal: controller.signal,
2269
+ })
2270
+ const body = await res.json()
2271
+ if (!body || body.ok !== true) {
2272
+ const err = body && body.error ? body.error.code + ': ' + body.error.message : 'HTTP ' + res.status
2273
+ throw new Error(err)
2274
+ }
2275
+ return body.value || {}
2276
+ } catch (error) {
2277
+ if (error && error.name === 'AbortError') throw new Error('请求超时(' + REQUEST_TIMEOUT_MS / 1000 + 's)')
2278
+ throw error
2279
+ } finally {
2280
+ clearTimeout(timer)
2281
+ }
2282
+ }
2283
+
2284
+ let BoardView = null
2285
+ function ensureBoardView() {
2286
+ if (!BoardView) BoardView = createBoardView(React)
2287
+ return BoardView
2288
+ }
2289
+
2290
+ function BrandMark({ size = 18 }) {
2291
+ return React.createElement('svg', {
2292
+ viewBox: '0 0 64 64', width: size, height: size,
2293
+ 'aria-hidden': 'true', focusable: 'false', fill: 'none',
2294
+ stroke: 'currentColor', strokeWidth: 5.5, strokeLinecap: 'round',
2295
+ style: { display: 'block' },
2296
+ },
2297
+ React.createElement('path', { d: 'M32 17v13M32 30l-13 10M32 30l13 10' }),
2298
+ React.createElement('circle', { cx: 32, cy: 13, r: 7, fill: 'currentColor', stroke: 'none' }),
2299
+ React.createElement('circle', { cx: 18, cy: 50, r: 6, fill: 'currentColor', stroke: 'none' }),
2300
+ React.createElement('circle', { cx: 46, cy: 50, r: 6, fill: 'currentColor', stroke: 'none' }))
2301
+ }
2302
+
2303
+ // 入口按钮与页签标题跟随宿主变量;面板样式全部来自 board-view.js 的 hiveStyleText()。
2304
+ function ensureBoardChromeStyle() {
2305
+ if (typeof document === 'undefined' || document.getElementById('dsbot-board-chrome-style')) return
2306
+ const style = document.createElement('style')
2307
+ style.id = 'dsbot-board-chrome-style'
2308
+ style.textContent = [
2309
+ hiveStyleText(),
2310
+ '.dsb-entry { background: transparent; color: var(--dsw-alias-text-secondary, rgba(20,20,20,.70)); transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .15s ease; }',
2311
+ '.dsb-entry:hover { background: var(--dsw-alias-surface-hover, rgba(119,119,119,.09)); color: var(--dsw-alias-text-primary, #141414); }',
2312
+ '.dsb-entry:active { transform: translateY(1px); }',
2313
+ '.dsb-entry:focus-visible { outline: 2px solid #4d6bfe; outline-offset: 2px; }',
2314
+ 'html.dsbot-board-motion-off .dsb-entry { transition: none !important; }',
2315
+ '@media (prefers-reduced-motion: reduce) { .dsb-entry { transition: none !important; } }',
2316
+ ].join('\n')
2317
+ document.head.appendChild(style)
2318
+ }
2319
+
2320
+ async function askState(args) {
2321
+ try {
2322
+ return await askApi('state', args)
2323
+ } catch (error) {
2324
+ if (args && args.since != null) {
2325
+ mark('state since fallback')
2326
+ return askApi('state', {})
2327
+ }
2328
+ throw error
2329
+ }
2330
+ }
2331
+
2332
+ async function fetchActiveContext(activeRoomIds, privateBotIds, failed) {
2333
+ const pendingRooms = new Map()
2334
+ const pendingBots = new Map()
2335
+ const jobs = []
2336
+
2337
+ for (const roomId of activeRoomIds) {
2338
+ jobs.push(askApi('room-chat', { roomId }).then(
2339
+ (value) => { pendingRooms.set(roomId, listOf(value.items)) },
2340
+ () => { failed.add('room:' + roomId); mark('room-chat fail ' + roomId) },
2341
+ ))
2342
+ }
2343
+ for (const botId of privateBotIds) {
2344
+ jobs.push(askApi('chat', { botId }).then(
2345
+ (value) => { pendingBots.set(botId, listOf(value.items)) },
2346
+ () => { failed.add('bot:' + botId); mark('chat fail ' + botId) },
2347
+ ))
2348
+ }
2349
+
2350
+ await Promise.all(jobs)
2351
+ return { pendingRooms, pendingBots }
2352
+ }
2353
+
2354
+ // 活跃取数:state 轻查询带 work/activity;只有活跃空间才拉 room-chat / chat。
2355
+ function useGlobalBoard(active) {
2356
+ const [snap, setSnap] = React.useState({ phase: 'loading' })
2357
+ const revRef = React.useRef(null)
2358
+ const roomCache = React.useRef(new Map())
2359
+ const botCache = React.useRef(new Map())
2360
+ const baseCache = React.useRef({ bots: [], rooms: [] })
2361
+ const [tick, setTick] = React.useState(0)
2362
+
2363
+ React.useEffect(() => {
2364
+ if (!active) return undefined
2365
+ let alive = true
2366
+ let inFlight = false
2367
+ let seq = 0
2368
+
2369
+ const pull = async () => {
2370
+ if (inFlight) return
2371
+ inFlight = true
2372
+ const mySeq = ++seq
2373
+ const failed = new Set()
2374
+
2375
+ try {
2376
+ const args = {}
2377
+ if (revRef.current != null) args.since = revRef.current
2378
+ const state = await askState(args)
2379
+ if (!alive || mySeq !== seq) return
2380
+
2381
+ const base = boardBaseFromState(state, baseCache.current)
2382
+ const rooms = base.rooms
2383
+ const bots = base.bots
2384
+ const work = state.work || {}
2385
+ const activity = state.activity || {}
2386
+ const revision = state.revision
2387
+ if (state.unchanged !== true) baseCache.current = base
2388
+ const changed = state.unchanged !== true || revRef.current == null
2389
+ const activeRoomIds = activeRoomIdsOf(work)
2390
+ const botAliases = boardBotIdAliases(bots)
2391
+ const activeBotIds = activeBotIdsOf(work, activity)
2392
+ .map((botId) => resolveBoardBotId(botId, botAliases))
2393
+ .filter(Boolean)
2394
+ const privateBotIds = activeBotIds.filter((botId) => {
2395
+ const shortId = botId.replace(/^session-/, '')
2396
+ const info = (work.bots && work.bots[botId]) || (work.bots && work.bots[shortId])
2397
+ return !(info && info.roomId)
2398
+ })
2399
+
2400
+ if (!changed) {
2401
+ const missingRoomIds = activeRoomIds.filter((roomId) => !roomCache.current.has(roomId))
2402
+ const missingBotIds = privateBotIds.filter((botId) => !botCache.current.has(botId))
2403
+ if (missingRoomIds.length > 0 || missingBotIds.length > 0) {
2404
+ const loaded = await fetchActiveContext(
2405
+ missingRoomIds,
2406
+ missingBotIds,
2407
+ failed,
2408
+ )
2409
+ if (!alive || mySeq !== seq) return
2410
+ for (const [id, rows] of loaded.pendingRooms) roomCache.current.set(id, rows)
2411
+ for (const [id, rows] of loaded.pendingBots) botCache.current.set(id, rows)
2412
+ }
2413
+
2414
+ const roomItems = Object.fromEntries(roomCache.current)
2415
+ const botItems = Object.fromEntries(botCache.current)
2416
+ const board = buildActiveBoard({ bots, rooms, roomItems, botItems, work, activity })
2417
+ setSnap((prev) => (prev.phase === 'ok'
2418
+ ? { ...prev, board, work, activity, lastChecked: Date.now(), failed: failed.size, error: failed.size > 0 ? prev.error : undefined }
2419
+ : prev))
2420
+ mark('active unchanged rev=' + revision + ' groups=' + board.groups.length + ' nodes=' + board.nodes.length + ' failed=' + failed.size)
2421
+ return
2422
+ }
2423
+
2424
+ const loaded = await fetchActiveContext(
2425
+ activeRoomIds,
2426
+ privateBotIds,
2427
+ failed,
2428
+ )
2429
+ if (!alive || mySeq !== seq) return
2430
+
2431
+ for (const [id, rows] of loaded.pendingRooms) roomCache.current.set(id, rows)
2432
+ for (const [id, rows] of loaded.pendingBots) botCache.current.set(id, rows)
2433
+
2434
+ const roomItems = Object.fromEntries(roomCache.current)
2435
+ const botItems = Object.fromEntries(botCache.current)
2436
+ const board = buildActiveBoard({ bots, rooms, roomItems, botItems, work, activity })
2437
+
2438
+ setSnap({
2439
+ phase: 'ok',
2440
+ rooms,
2441
+ bots,
2442
+ revision,
2443
+ board,
2444
+ work,
2445
+ activity,
2446
+ failed: failed.size,
2447
+ lastUpdated: Date.now(),
2448
+ })
2449
+ if (failed.size === 0) revRef.current = revision
2450
+ mark('active ok rooms=' + activeRoomIds.length + ' bots=' + activeBotIds.length +
2451
+ ' groups=' + board.groups.length + ' nodes=' + board.nodes.length +
2452
+ ' rev=' + revision + ' failed=' + failed.size)
2453
+ } catch (error) {
2454
+ if (!alive || mySeq !== seq) return
2455
+ const message = String(error && error.message ? error.message : error)
2456
+ setSnap((prev) => {
2457
+ if (prev.phase === 'ok') return { ...prev, failed: (prev.failed || 0) + 1, error: message }
2458
+ return { phase: 'error', message }
2459
+ })
2460
+ mark('active error ' + message)
2461
+ } finally {
2462
+ if (mySeq === seq) inFlight = false
2463
+ }
2464
+ }
2465
+
2466
+ pull()
2467
+ const timer = setInterval(pull, 6000)
2468
+ return () => { alive = false; clearInterval(timer) }
2469
+ }, [active, tick])
2470
+
2471
+ return [snap, () => setTick((value) => value + 1)]
2472
+ }
2473
+
2474
+ const KIND = 'dsbot-starboard:main'
2475
+ const THEME_KEY = '__dsbotBoardTheme'
2476
+ const MOTION_KEY = '__dsbotBoardMotion'
2477
+ const SCOPE_KEY = '__dsbotBoardScope'
2478
+
2479
+ const themeUi = { name: 'dark', manual: false }
2480
+ const themeListeners = new Set()
2481
+
2482
+ function hostTheme() {
2483
+ try {
2484
+ const root = document.documentElement
2485
+ const attr = (root.getAttribute('data-theme') || root.getAttribute('data-dsw-theme') || '').toLowerCase()
2486
+ if (attr === 'light' || attr === 'dark') return attr
2487
+ if (root.classList.contains('dark') || root.classList.contains('dsw-dark')) return 'dark'
2488
+ if (root.classList.contains('light') || root.classList.contains('dsw-light')) return 'light'
2489
+ if (document.body && document.body.hasAttribute('data-ds-dark-theme')) return 'dark'
2490
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) return 'light'
2491
+ } catch (error) { /* 读不到就按深色 */ }
2492
+ return 'dark'
2493
+ }
2494
+
2495
+ function readTheme() {
2496
+ try {
2497
+ const saved = window.localStorage.getItem(THEME_KEY)
2498
+ if (saved === 'light' || saved === 'dark') return { name: saved, manual: true }
2499
+ } catch (error) { /* 忽略存储失败 */ }
2500
+ return { name: hostTheme(), manual: false }
2501
+ }
2502
+
2503
+ function setBoardTheme(next, persist = true) {
2504
+ themeUi.name = next
2505
+ themeUi.manual = persist
2506
+ if (persist) {
2507
+ try { window.localStorage.setItem(THEME_KEY, next) } catch (error) { /* 忽略存储失败 */ }
2508
+ }
2509
+ for (const listener of themeListeners) {
2510
+ try { listener(next) } catch (error) { /* 忽略单个订阅者 */ }
2511
+ }
2512
+ }
2513
+
2514
+ const initialTheme = readTheme()
2515
+ themeUi.name = initialTheme.name
2516
+ themeUi.manual = initialTheme.manual
2517
+
2518
+ function useBoardTheme() {
2519
+ const [themeName, setThemeName] = React.useState(themeUi.name)
2520
+ React.useEffect(() => {
2521
+ const listener = (value) => setThemeName(value)
2522
+ themeListeners.add(listener)
2523
+ setThemeName(themeUi.name)
2524
+
2525
+ const media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null
2526
+ const followHost = () => {
2527
+ let saved = null
2528
+ try { saved = window.localStorage.getItem(THEME_KEY) } catch (error) { /* 忽略 */ }
2529
+ if (saved === 'light' || saved === 'dark') return
2530
+ setBoardTheme(hostTheme(), false)
2531
+ }
2532
+ const observer = typeof MutationObserver !== 'undefined'
2533
+ ? new MutationObserver(followHost)
2534
+ : null
2535
+ if (observer) {
2536
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'data-theme', 'data-dsw-theme'] })
2537
+ if (document.body) observer.observe(document.body, { attributes: true, attributeFilter: ['class', 'data-theme', 'data-ds-dark-theme'] })
2538
+ }
2539
+ if (media && media.addEventListener) media.addEventListener('change', followHost)
2540
+
2541
+ return () => {
2542
+ themeListeners.delete(listener)
2543
+ if (observer) observer.disconnect()
2544
+ if (media && media.removeEventListener) media.removeEventListener('change', followHost)
2545
+ }
2546
+ }, [])
2547
+ const toggle = React.useCallback(() => {
2548
+ setBoardTheme(themeUi.name === 'dark' ? 'light' : 'dark')
2549
+ }, [])
2550
+ return [themeName, toggle, themeUi.manual]
2551
+ }
2552
+
2553
+ function useBoardMotion() {
2554
+ const [motionOn, setMotionOn] = React.useState(() => {
2555
+ try { return window.localStorage.getItem(MOTION_KEY) !== 'off' } catch (error) { return true }
2556
+ })
2557
+ const toggle = React.useCallback(() => {
2558
+ setMotionOn((prev) => {
2559
+ const next = !prev
2560
+ try { window.localStorage.setItem(MOTION_KEY, next ? 'on' : 'off') } catch (error) { /* 忽略 */ }
2561
+ return next
2562
+ })
2563
+ }, [])
2564
+ return [motionOn, toggle]
2565
+ }
2566
+
2567
+ function readScope() {
2568
+ try { return window.localStorage.getItem(SCOPE_KEY) || 'all' } catch (error) { return 'all' }
2569
+ }
2570
+
2571
+ // 薄壳:只负责取数、主题/动效/筛选状态与宿主接线,视觉全部交给 BoardView。
2572
+ function BoardBody({ active, themeName, onToggleTheme, themeVars, onOpenSession }) {
2573
+ const [snap, refresh] = useGlobalBoard(active)
2574
+ const [motionOn, toggleMotion] = useBoardMotion()
2575
+ const [scope, setScope] = React.useState(readScope)
2576
+
2577
+ React.useEffect(() => {
2578
+ document.documentElement.classList.toggle('dsbot-board-motion-off', !motionOn)
2579
+ return () => { document.documentElement.classList.remove('dsbot-board-motion-off') }
2580
+ }, [motionOn])
2581
+
2582
+ React.useEffect(() => {
2583
+ if (scope === 'all') return
2584
+ if (snap.phase === 'ok' && !snap.board.scopeOptions.some((item) => item.id === scope)) {
2585
+ setScope('all')
2586
+ try { window.localStorage.setItem(SCOPE_KEY, 'all') } catch (error) { /* 忽略 */ }
2587
+ }
2588
+ }, [scope, snap])
2589
+
2590
+ const selectScope = (next) => {
2591
+ setScope(next)
2592
+ try { window.localStorage.setItem(SCOPE_KEY, next) } catch (error) { /* 忽略 */ }
2593
+ }
2594
+
2595
+ return React.createElement(BoardView, {
2596
+ phase: snap.phase,
2597
+ message: snap.message,
2598
+ board: snap.board,
2599
+ bots: snap.bots,
2600
+ failed: snap.failed || 0,
2601
+ lastChecked: snap.lastChecked,
2602
+ lastUpdated: snap.lastUpdated,
2603
+ themeName,
2604
+ themeVars,
2605
+ onToggleTheme,
2606
+ motionOn,
2607
+ onToggleMotion: toggleMotion,
2608
+ scope,
2609
+ onSelectScope: selectScope,
2610
+ onRetry: refresh,
2611
+ onOpenSession: onOpenSession || openBotSession,
2612
+ })
2613
+ }
2614
+
2615
+ function NativeTabBody(props) {
2616
+ const [themeName, toggleTheme] = useBoardTheme()
2617
+ const visible = props && typeof props.visible === 'boolean' ? props.visible : true
2618
+ return React.createElement(BoardBody, { active: visible, themeName, onToggleTheme: toggleTheme })
2619
+ }
2620
+
2621
+ function NativeTabTitle(props) {
2622
+ const visible = props && typeof props.visible === 'boolean' ? props.visible : true
2623
+ return React.createElement('div', {
2624
+ 'data-dsbot-board-title': '',
2625
+ style: {
2626
+ display: 'flex', alignItems: 'center', gap: 6, height: '100%',
2627
+ padding: '0 4px', fontSize: 11,
2628
+ color: 'var(--dsw-alias-text-primary, #141414)', opacity: visible ? 1 : 0.6,
2629
+ },
2630
+ },
2631
+ React.createElement('span', { style: { display: 'inline-flex', color: 'var(--dsw-alias-text-secondary, rgba(20,20,20,.70))' } },
2632
+ React.createElement(BrandMark, { size: 13 })),
2633
+ React.createElement('span', { style: { fontWeight: 600 } }, 'Starboard'))
2634
+ }
2635
+
2636
+ function makeEntry() {
2637
+ return function BoardEntry() {
2638
+ return React.createElement('button', {
2639
+ type: 'button',
2640
+ title: '打开Starboard',
2641
+ 'aria-label': 'Starboard',
2642
+ 'data-dsbot-board-entry': '1',
2643
+ onClick: () => {
2644
+ try {
2645
+ const service = window.__dsbotBoard__ || null
2646
+ if (service && typeof service.open === 'function') {
2647
+ service.open()
2648
+ mark('entry:clicked')
2649
+ } else {
2650
+ mark('entry:no-service')
2651
+ }
2652
+ } catch (error) {
2653
+ mark('entry:fail ' + String(error && error.message ? error.message : error))
2654
+ }
2655
+ },
2656
+ className: 'dsb-entry',
2657
+ style: {
2658
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
2659
+ width: 28, height: 28, padding: 0, borderRadius: 9,
2660
+ border: '1px solid transparent', cursor: 'pointer', flex: '0 0 auto',
2661
+ },
2662
+ }, React.createElement(BrandMark, { size: 16 }))
2663
+ }
2664
+ }
2665
+
2666
+ function makeOpener() {
2667
+ return {
2668
+ open() {
2669
+ const right = opener.right
2670
+ if (!right) { mark('open:no-right'); return false }
2671
+ try {
2672
+ if (typeof right.openTab === 'function') { right.openTab(KIND); return true }
2673
+ } catch (error) {
2674
+ mark('open:openTab-fail ' + String(error && error.message ? error.message : error))
2675
+ }
2676
+ try {
2677
+ if (typeof right.focus === 'function') { right.focus(KIND); return true }
2678
+ } catch (error) {
2679
+ mark('open:focus-fail ' + String(error && error.message ? error.message : error))
2680
+ }
2681
+ return false
2682
+ },
2683
+ }
2684
+ }
2685
+
2686
+ const opener = makeOpener()
2687
+ const BoardEntry = makeEntry()
2688
+ let openBotSession = (detail) => { mark('open-session pending ' + JSON.stringify(detail || {})) }
2689
+
2690
+ const boardPlugin = {
2691
+ inject: ['slots'],
2692
+ apply(ctx) {
2693
+ mark('apply')
2694
+ ensureBoardChromeStyle()
2695
+ ensureBoardView()
2696
+
2697
+ const workspace = (() => {
2698
+ try { return ctx.get('uiWorkspace') } catch (error) { return undefined }
2699
+ })()
2700
+ openBotSession = (detail) => {
2701
+ const info = detail || {}
2702
+ const botId = info.botId || info.key || ''
2703
+ try {
2704
+ if (workspace && typeof workspace.openSession === 'function') {
2705
+ workspace.openSession(botId)
2706
+ mark('open-session ok ' + botId)
2707
+ return
2708
+ }
2709
+ } catch (error) {
2710
+ mark('open-session fail ' + String(error && error.message ? error.message : error))
2711
+ }
2712
+ mark('open-session unavailable ' + botId)
2713
+ }
2714
+
2715
+ for (const slot of ['conversation.session.header.utilities', 'conversation.input.right']) {
2716
+ try {
2717
+ ctx.slots.inject(slot, () => ctx.slots.register({
2718
+ name: slot, id: 'dsbot-board:entry', order: 30,
2719
+ registrant: 'dsbot-starboard', inject: () => ({}),
2720
+ }, BoardEntry))
2721
+ } catch (error) {
2722
+ mark('apply:entry-fail ' + slot + ' ' + String(error && error.message ? error.message : error))
2723
+ }
2724
+ }
2725
+ mark('apply:entry')
2726
+
2727
+ try {
2728
+ ctx.inject(['sidebarRightTabs', 'sidebarRight'], (injected) => {
2729
+ const tabs = injected.get('sidebarRightTabs')
2730
+ const right = injected.get('sidebarRight')
2731
+ opener.right = right
2732
+ window.__dsbotBoard__ = opener
2733
+ if (!tabs || typeof tabs.register !== 'function') {
2734
+ mark('apply:tabs-unavailable')
2735
+ return
2736
+ }
2737
+
2738
+ const disposers = []
2739
+ try {
2740
+ disposers.push(tabs.register({
2741
+ id: KIND,
2742
+ kind: KIND,
2743
+ keepMounted: true,
2744
+ priority: 'extension',
2745
+ title: () => 'Starboard',
2746
+ guide: [{
2747
+ id: KIND,
2748
+ order: 45,
2749
+ title: () => 'Starboard',
2750
+ description: () => '全局查看谁派活给谁、谁在等回执,以及当前消息走到哪',
2751
+ icon: (props) => BrandMark({ size: props && props.size ? props.size : 16 }),
2752
+ }],
2753
+ }))
2754
+ disposers.push(ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
2755
+ name: 'sidebar.right.pane.tab', key: KIND, inject: (sessionId) => ({ sessionId }),
2756
+ }, NativeTabBody)))
2757
+ disposers.push(ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({
2758
+ name: 'sidebar.right.pane.tab.title', key: KIND, inject: (sessionId) => ({ sessionId }),
2759
+ }, NativeTabTitle)))
2760
+ mark('apply:native-tab-ok')
2761
+ } catch (error) {
2762
+ mark('apply:native-tab-fail ' + String(error && error.message ? error.message : error))
2763
+ for (const dispose of disposers) { try { dispose() } catch (e) { /* 忽略清理失败 */ } }
2764
+ return
2765
+ }
2766
+
2767
+ try {
2768
+ if (window.localStorage.getItem('__dsbotBoardNativeOpened:v4') !== '1') {
2769
+ window.localStorage.setItem('__dsbotBoardNativeOpened:v4', '1')
2770
+ opener.open()
2771
+ mark('apply:native-open-ok')
2772
+ }
2773
+ } catch (error) {
2774
+ mark('apply:native-open-fail ' + String(error && error.message ? error.message : error))
2775
+ }
2776
+
2777
+ return () => {
2778
+ opener.right = null
2779
+ for (const dispose of disposers) { try { dispose() } catch (e) { /* 忽略清理失败 */ } }
2780
+ }
2781
+ })
2782
+ } catch (error) {
2783
+ mark('apply:native-inject-fail ' + String(error && error.message ? error.message : error))
2784
+ }
2785
+ },
2786
+ }
2787
+
2788
+ // DS Bot Desktop App 适配层:复用 Starboard 数据与视图,只替换宿主 UI 接线。
2789
+ function desktopThemeVars(themeName, manualTheme = false) {
2790
+ const dark = themeName !== 'light'
2791
+ if (manualTheme) return { ...(HIVE_VARS[themeName] || HIVE_VARS.dark) }
2792
+ return {
2793
+ '--dsb-font': 'var(--bt-font, ' + (dark ? '"Segoe UI Variable Text", "Segoe UI", sans-serif' : '"Segoe UI Variable Text", "Segoe UI", sans-serif') + ')',
2794
+ '--dsb-mono': 'var(--bt-mono, "Cascadia Mono", Consolas, monospace)',
2795
+ '--dsb-stage-0': 'var(--bt-main, ' + (dark ? '#141414' : '#fcfcfc') + ')',
2796
+ '--dsb-stage-1': 'var(--bt-main, ' + (dark ? '#141414' : '#fcfcfc') + ')',
2797
+ '--dsb-stage-2': 'var(--bt-card, ' + (dark ? '#1f1f1f' : '#ffffff') + ')',
2798
+ '--dsb-panel': 'var(--bt-sidebar, ' + (dark ? '#141414' : '#fcfcfc') + ')',
2799
+ '--dsb-card': 'var(--bt-card, ' + (dark ? '#1f1f1f' : '#ffffff') + ')',
2800
+ '--dsb-card-hi': 'var(--bt-card, ' + (dark ? '#1f1f1f' : '#ffffff') + ')',
2801
+ '--dsb-card-border': 'var(--bt-line, rgba(20,20,20,.10))',
2802
+ '--dsb-hair': 'var(--bt-line, rgba(20,20,20,.08))',
2803
+ '--dsb-text-1': 'var(--bt-ink, ' + (dark ? '#f2f2f2' : '#141414') + ')',
2804
+ '--dsb-text-2': 'var(--bt-ink-2, ' + (dark ? 'rgba(242,242,242,.66)' : 'rgba(20,20,20,.70)') + ')',
2805
+ '--dsb-text-3': 'var(--bt-ink-3, ' + (dark ? 'rgba(242,242,242,.52)' : 'rgba(20,20,20,.60)') + ')',
2806
+ '--dsb-accent': 'var(--bt-accent, #4d6bfe)',
2807
+ '--dsb-accent-2': 'var(--bt-accent, #4d6bfe)',
2808
+ '--dsb-cyan': 'var(--bt-accent, #4d6bfe)',
2809
+ '--dsb-wait': 'var(--bt-star, #ff9800)',
2810
+ '--dsb-fail': 'var(--bt-danger, #e02135)',
2811
+ '--dsb-ok': 'var(--bt-green, #00c972)',
2812
+ '--dsb-pod-bg': 'var(--bt-card, ' + (dark ? '#1f1f1f' : '#ffffff') + ')',
2813
+ '--dsb-pod-shadow': '0 12px 28px -10px rgba(0,0,0,.45), inset 0 1px 0 var(--bt-line-2, rgba(255,255,255,.12))',
2814
+ '--dsb-pod-ring': 'var(--bt-line-2, rgba(20,20,20,.15))',
2815
+ '--dsb-star': 'var(--bt-ink-3, rgba(20,20,20,.52))',
2816
+ '--dsb-orbit': 'var(--bt-line, rgba(20,20,20,.10))',
2817
+ '--dsb-dock': 'var(--bt-card, ' + (dark ? '#1f1f1f' : '#ffffff') + ')',
2818
+ '--dsb-shadow-card': '0 20px 44px -22px rgba(0,0,0,.45)',
2819
+ '--dsb-name-shadow': 'none',
2820
+ '--dsb-scroll': 'var(--bt-line-2, rgba(20,20,20,.15))',
2821
+ }
2822
+ }
2823
+
2824
+ function installDesktopPlugin(ctx) {
2825
+ const providedReact = ctx.get('react')
2826
+ React = Object.assign({}, providedReact, {
2827
+ useLayoutEffect: providedReact.useLayoutEffect || providedReact.useEffect,
2828
+ })
2829
+ ensureBoardView()
2830
+ ctx.style(hiveStyleText())
2831
+
2832
+ function DesktopTabBody(props) {
2833
+ const [themeName, toggleTheme, manualTheme] = useBoardTheme()
2834
+ const actions = props && props.actions
2835
+ return React.createElement(BoardBody, {
2836
+ active: true,
2837
+ themeName,
2838
+ themeVars: desktopThemeVars(themeName, manualTheme),
2839
+ onToggleTheme: toggleTheme,
2840
+ onOpenSession: (detail) => {
2841
+ const info = detail || {}
2842
+ const botId = info.botId || info.key || ''
2843
+ try {
2844
+ if (actions && typeof actions.openSession === 'function') {
2845
+ actions.openSession(botId)
2846
+ mark('desktop-open-session ok ' + botId)
2847
+ return
2848
+ }
2849
+ } catch (error) {
2850
+ mark('desktop-open-session fail ' + String(error && error.message ? error.message : error))
2851
+ }
2852
+ mark('desktop-open-session unavailable ' + botId)
2853
+ },
2854
+ })
2855
+ }
2856
+
2857
+ ctx.slot({
2858
+ name: 'sidebar.right.pane.tab',
2859
+ id: 'dsbot-starboard',
2860
+ meta: { label: 'Starboard', icon: BrandMark },
2861
+ }, DesktopTabBody)
2862
+ mark('desktop-apply-ok')
2863
+ }
2864
+
2865
+
2866
+ export { installDesktopPlugin as apply }