dsh-agent-floor 0.1.0 → 0.3.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/README.md +23 -40
- package/client.js +200 -672
- package/icon.svg +8 -9
- package/package.json +2 -4
- package/scripts/README.md +15 -61
- package/scripts/harness.js +30 -17
- package/scripts/raster.py +0 -218
- package/scripts/render.js +0 -226
package/client.js
CHANGED
|
@@ -5,386 +5,92 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
const h = React.createElement;
|
|
6
6
|
const { useState, useEffect, useRef } = React;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const
|
|
8
|
+
const inject = ['slots'];
|
|
9
|
+
const ROUTE = '/dsh-agent-floor/state';
|
|
10
10
|
const OPEN_KEY = 'dsh.agent-floor.open';
|
|
11
|
-
const
|
|
11
|
+
const POS_KEY = 'dsh.agent-floor.pos';
|
|
12
12
|
const CHILD_TTL = 10 * 60 * 1000;
|
|
13
|
+
const MAX_ROWS = 8;
|
|
13
14
|
|
|
14
15
|
const CSS = `
|
|
15
|
-
.fg-root{
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
.fg-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.fg-head{display:flex;align-items:center;gap:
|
|
24
|
-
|
|
25
|
-
.fg-
|
|
26
|
-
.fg-
|
|
27
|
-
.fg-
|
|
28
|
-
|
|
29
|
-
.fg-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
.fg-
|
|
33
|
-
.fg-
|
|
34
|
-
.fg-
|
|
35
|
-
.fg-
|
|
36
|
-
|
|
37
|
-
.fg-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.fg-
|
|
41
|
-
|
|
42
|
-
.fg-
|
|
43
|
-
.fg-
|
|
44
|
-
.fg-
|
|
45
|
-
.fg-
|
|
46
|
-
.fg-
|
|
47
|
-
.fg-
|
|
48
|
-
|
|
49
|
-
.fg-
|
|
50
|
-
.fg-bar i{display:block;height:100%;border-radius:3px;background:var(--dsw-alias-brand-primary,#5b8cff);transition:width .5s ease;}
|
|
51
|
-
.fg-row[data-run="1"] .fg-bar i{background:linear-gradient(90deg,#22c55e,#4ade80);background-size:200% 100%;animation:fg-flow 1.6s linear infinite;}
|
|
52
|
-
@keyframes fg-flow{from{background-position:0 0}to{background-position:-200% 0}}
|
|
53
|
-
.fg-meta{font-size:10px;opacity:.45;display:flex;gap:8px;font-variant-numeric:tabular-nums;}
|
|
54
|
-
.fg-empty{padding:22px 12px;text-align:center;font-size:11.5px;opacity:.5;}
|
|
55
|
-
.fg-full{position:fixed;inset:0;z-index:130;background:color-mix(in srgb,var(--dsw-alias-bg-base,#0f0f12) 82%,transparent);backdrop-filter:blur(16px);display:flex;flex-direction:column;pointer-events:auto;animation:fg-fade .18s ease;}
|
|
56
|
-
@keyframes fg-fade{from{opacity:0}to{opacity:1}}
|
|
57
|
-
.fg-full-head{display:flex;align-items:center;gap:10px;padding:18px 22px 10px;}
|
|
58
|
-
.fg-full-title{font-size:13px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;}
|
|
59
|
-
.fg-full-sub{font-size:11px;opacity:.55;}
|
|
60
|
-
.fg-grid{flex:1;overflow-y:auto;display:grid;grid-template-columns:repeat(auto-fill,minmax(238px,1fr));gap:14px;padding:8px 22px 26px;align-content:start;}
|
|
61
|
-
.fg-stage{flex:1;overflow:auto;padding:0 12px 18px;display:flex;align-items:flex-start;justify-content:center;}
|
|
62
|
-
.fg-iso-run{animation:fg-iso-bob 2.4s ease-in-out infinite;}
|
|
63
|
-
.fg-flow{animation:fg-dash 1.4s linear infinite;}
|
|
64
|
-
@keyframes fg-dash{to{stroke-dashoffset:-24}}
|
|
65
|
-
.fg-flow-g{opacity:.9;}
|
|
66
|
-
.fg-task{font-size:10px;opacity:.62;display:flex;gap:6px;align-items:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
|
|
67
|
-
.fg-task b{font-weight:650;opacity:.9;}
|
|
68
|
-
.fg-files{font-size:9.5px;opacity:.5;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
|
|
69
|
-
@keyframes fg-iso-bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-3px)}}
|
|
70
|
-
.fg-card{border-radius:16px;border:1px solid var(--dsw-alias-border-l1,rgba(255,255,255,.12));background:var(--dsw-alias-bg-layer-1,rgba(30,30,35,.9));padding:14px;display:flex;flex-direction:column;gap:9px;cursor:pointer;transition:transform .15s ease,border-color .15s ease,box-shadow .15s ease;}
|
|
71
|
-
.fg-card:hover{transform:translateY(-2px);border-color:var(--dsw-alias-brand-primary,#5b8cff);box-shadow:0 12px 30px rgba(0,0,0,.3);}
|
|
72
|
-
.fg-card[data-run="1"]{border-color:color-mix(in srgb,var(--dsw-alias-state-success-primary,#22c55e) 45%,transparent);}
|
|
73
|
-
.fg-card-top{display:flex;align-items:center;gap:10px;}
|
|
74
|
-
.fg-card-av{width:56px;height:56px;flex:none;display:grid;place-items:center;border-radius:12px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.06));}
|
|
75
|
-
.fg-card-name{font-size:13px;font-weight:650;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
|
|
76
|
-
.fg-card-role{font-size:10px;opacity:.55;letter-spacing:.05em;text-transform:uppercase;}
|
|
77
|
-
.fg-card-last{font-size:10.5px;opacity:.6;min-height:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
|
|
78
|
-
.fg-card-stats{display:flex;gap:12px;font-size:10.5px;font-variant-numeric:tabular-nums;opacity:.75;}
|
|
79
|
-
.fg-card-stats b{font-weight:700;opacity:.95;}
|
|
80
|
-
.fg-kids{display:flex;flex-wrap:wrap;gap:5px;border-top:1px dashed var(--dsw-alias-border-l1,rgba(255,255,255,.12));padding-top:8px;}
|
|
81
|
-
.fg-kid{display:inline-flex;align-items:center;gap:5px;font-size:10px;padding:2px 7px;border-radius:6px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.07));opacity:.85;}
|
|
16
|
+
.fg-root{position:fixed;inset:0;z-index:60;pointer-events:none;
|
|
17
|
+
font:12px/1.5 ui-sans-serif,-apple-system,"SF Pro Text","PingFang SC",system-ui,sans-serif;
|
|
18
|
+
color:var(--dsw-alias-label-primary,#1c1c1e);}
|
|
19
|
+
.fg-dock{position:absolute;min-width:196px;max-width:340px;border-radius:12px;overflow:hidden;
|
|
20
|
+
pointer-events:auto;
|
|
21
|
+
background:var(--dsw-alias-bg-overlay,#fff);
|
|
22
|
+
border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.09));
|
|
23
|
+
box-shadow:0 8px 28px rgba(0,0,0,.12);}
|
|
24
|
+
.fg-head{display:flex;align-items:center;gap:7px;padding:7px 10px;cursor:grab;
|
|
25
|
+
user-select:none;-webkit-user-select:none;touch-action:none;}
|
|
26
|
+
.fg-head.dragging{cursor:grabbing;}
|
|
27
|
+
.fg-head:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.03));}
|
|
28
|
+
.fg-pulse{width:7px;height:7px;border-radius:50%;flex:0 0 auto;
|
|
29
|
+
background:var(--dsw-alias-state-idle-primary,#9aa0a6);}
|
|
30
|
+
.fg-pulse.on{background:var(--dsw-alias-state-success-primary,#1a9b4e);
|
|
31
|
+
animation:fg-breathe 1.6s ease-in-out infinite;}
|
|
32
|
+
@keyframes fg-breathe{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.45;transform:scale(.82)}}
|
|
33
|
+
.fg-sum{font-weight:600;letter-spacing:.1px;white-space:nowrap;}
|
|
34
|
+
.fg-sum i{font-style:normal;font-weight:500;opacity:.55;}
|
|
35
|
+
.fg-caret{margin-left:auto;opacity:.45;font-size:11px;}
|
|
36
|
+
.fg-body{max-height:280px;overflow:auto;
|
|
37
|
+
border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.07));}
|
|
38
|
+
.fg-row{display:grid;grid-template-columns:9px 1fr auto;gap:2px 7px;
|
|
39
|
+
padding:6px 10px;cursor:pointer;align-items:center;}
|
|
40
|
+
.fg-row:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.035));}
|
|
41
|
+
.fg-dot{width:7px;height:7px;border-radius:50%;
|
|
42
|
+
background:var(--dsw-alias-state-idle-primary,#c2c6cc);}
|
|
43
|
+
.fg-dot.run{background:var(--dsw-alias-state-success-primary,#1a9b4e);}
|
|
44
|
+
.fg-dot.wait{background:var(--dsw-alias-state-warn-primary,#e0a72e);}
|
|
45
|
+
.fg-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;}
|
|
46
|
+
.fg-name em{font-style:normal;font-weight:500;opacity:.5;font-size:11px;margin-left:5px;}
|
|
47
|
+
.fg-num{font-variant-numeric:tabular-nums;opacity:.6;white-space:nowrap;font-size:11px;}
|
|
48
|
+
.fg-file{grid-column:2 / 4;font-size:11px;opacity:.5;overflow:hidden;
|
|
49
|
+
text-overflow:ellipsis;white-space:nowrap;}
|
|
50
|
+
.fg-more{grid-column:1 / 4;padding:5px 10px;font-size:11px;opacity:.5;}
|
|
82
51
|
`;
|
|
83
52
|
|
|
84
|
-
function
|
|
85
|
-
if (typeof document === 'undefined') return;
|
|
86
|
-
if (document.getElementById('
|
|
53
|
+
function ensureStyle() {
|
|
54
|
+
if (typeof document === 'undefined' || !document.head) return;
|
|
55
|
+
if (document.getElementById('fg-style')) return;
|
|
87
56
|
const el = document.createElement('style');
|
|
88
|
-
el.id = '
|
|
57
|
+
el.id = 'fg-style';
|
|
89
58
|
el.textContent = CSS;
|
|
90
59
|
document.head.appendChild(el);
|
|
91
60
|
}
|
|
92
61
|
|
|
93
|
-
function hash(s) {
|
|
94
|
-
let x = 0;
|
|
95
|
-
const str = String(s || '');
|
|
96
|
-
for (let i = 0; i < str.length; i += 1) x = (x * 31 + str.charCodeAt(i)) | 0;
|
|
97
|
-
return Math.abs(x);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
62
|
function num(n) {
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
if (
|
|
104
|
-
return
|
|
63
|
+
if (!n) return '0';
|
|
64
|
+
if (n < 1000) return String(n);
|
|
65
|
+
if (n < 1e6) return (n / 1000).toFixed(n < 1e4 ? 1 : 0) + 'k';
|
|
66
|
+
return (n / 1e6).toFixed(1) + 'M';
|
|
105
67
|
}
|
|
106
68
|
|
|
107
69
|
function ago(t) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (s <
|
|
111
|
-
return Math.round(s /
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
function statusOf(a) {
|
|
115
|
-
if (a.status === 'RUNNING') return { text: '干活中', cls: 'fg-chip-run' };
|
|
116
|
-
if (a.status === 'STANDBY') return { text: '待命', cls: 'fg-chip-wait' };
|
|
117
|
-
return { text: '收工', cls: 'fg-chip-idle' };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function progress(a) {
|
|
121
|
-
const tokens = Number(a.tokens) || 0;
|
|
122
|
-
return Math.max(3, Math.min(100, (tokens / 120000) * 100));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function spriteParts(seed) {
|
|
126
|
-
const hue = hash(seed) % 360;
|
|
127
|
-
const shirt = 'hsl(' + hue + ' 62% 52%)';
|
|
128
|
-
const shirt2 = 'hsl(' + hue + ' 62% 40%)';
|
|
129
|
-
const hair = 'hsl(' + ((hue + 35) % 360) + ' 32% 26%)';
|
|
130
|
-
const skin = '#f0c9a2';
|
|
131
|
-
return [
|
|
132
|
-
[2, 1, 4, 1, hair],
|
|
133
|
-
[1, 2, 6, 1, hair],
|
|
134
|
-
[2, 3, 4, 2, skin],
|
|
135
|
-
[2, 4, 1, 1, '#2b2b33'],
|
|
136
|
-
[5, 4, 1, 1, '#2b2b33'],
|
|
137
|
-
[1, 6, 6, 2, shirt],
|
|
138
|
-
[2, 7, 4, 1, shirt2],
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function Engine({ seed, size, running }) {
|
|
143
|
-
const cell = size / 8;
|
|
144
|
-
const parts = spriteParts(seed);
|
|
145
|
-
return h('svg', {
|
|
146
|
-
className: 'fg-eng' + (running ? ' fg-eng-run' : ''),
|
|
147
|
-
width: size, height: size, viewBox: '0 0 ' + size + ' ' + size, 'aria-hidden': 'true',
|
|
148
|
-
}, parts.map((q, i) => h('rect', {
|
|
149
|
-
key: i, x: q[0] * cell, y: q[1] * cell, width: q[2] * cell, height: q[3] * cell, fill: q[4], rx: cell * 0.2,
|
|
150
|
-
})).concat(running ? [h('rect', {
|
|
151
|
-
key: 'lamp', x: 6.4 * cell, y: 5.4 * cell, width: cell, height: cell, fill: '#7dd3fc', rx: cell * 0.3,
|
|
152
|
-
})] : []));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const ISO = { TW: 350, TH: 170, DESK: 18, SP: 4.6, COLS: 4 };
|
|
156
|
-
|
|
157
|
-
function isoDiamond(p, w, h) {
|
|
158
|
-
return [[p.x, p.y - h / 2], [p.x + w / 2, p.y], [p.x, p.y + h / 2], [p.x - w / 2, p.y]]
|
|
159
|
-
.map((q) => q[0].toFixed(1) + ',' + q[1].toFixed(1))
|
|
160
|
-
.join(' ');
|
|
70
|
+
if (!t) return '';
|
|
71
|
+
const s = Math.max(0, Math.round((Date.now() - t) / 1000));
|
|
72
|
+
if (s < 60) return s + '秒前';
|
|
73
|
+
if (s < 3600) return Math.round(s / 60) + '分钟前';
|
|
74
|
+
return Math.round(s / 3600) + '小时前';
|
|
161
75
|
}
|
|
162
76
|
|
|
163
|
-
function
|
|
164
|
-
const
|
|
165
|
-
const list = (seats || []).filter((s) => s && s.agent);
|
|
166
|
-
const rows = Math.max(1, Math.ceil(Math.max(1, list.length) / COLS));
|
|
167
|
-
const cols = Math.max(1, Math.min(COLS, Math.max(1, list.length)));
|
|
168
|
-
const W = Math.max(900, Math.round((cols + rows) * (TW / 2) + 240));
|
|
169
|
-
const H = Math.max(440, Math.round((cols + rows) * (TH / 2) + 300));
|
|
170
|
-
const cx = W / 2;
|
|
171
|
-
const cy = 180;
|
|
172
|
-
const at = (c, r) => ({ x: cx + (c - r) * (TW / 2), y: cy + (c + r) * (TH / 2) });
|
|
173
|
-
|
|
174
|
-
const bg1 = 'var(--dsw-alias-bg-layer-1,#ffffff)';
|
|
175
|
-
const bg2 = 'var(--dsw-alias-bg-layer-2,#f3f3f6)';
|
|
176
|
-
const ink = 'var(--dsw-alias-label-primary,#1c1c1e)';
|
|
177
|
-
const dim = 'color-mix(in srgb, var(--dsw-alias-label-primary,#1c1c1e) 58%, transparent)';
|
|
178
|
-
const hair = 'color-mix(in srgb, var(--dsw-alias-label-primary,#1c1c1e) 18%, transparent)';
|
|
179
|
-
const accent = 'var(--dsw-alias-brand-primary,#3b82f6)';
|
|
180
|
-
const okc = 'var(--dsw-alias-state-success-primary,#16a34a)';
|
|
181
|
-
const warnc = 'var(--dsw-alias-state-warn-primary,#f59e0b)';
|
|
182
|
-
const tone = (pct, base) => 'color-mix(in srgb, var(--dsw-alias-label-primary,#1c1c1e) ' + pct + '%, ' + (base || bg1) + ')';
|
|
183
|
-
|
|
184
|
-
const fixed = list.map((s) => ({ ...s, p: at(s.col, s.row) }));
|
|
185
|
-
const bySeat = new Map();
|
|
186
|
-
fixed.forEach((s) => bySeat.set(s.agent.id, s.p));
|
|
187
|
-
|
|
188
|
-
const scene = [];
|
|
189
|
-
const tags = [];
|
|
190
|
-
const couriers = [];
|
|
191
|
-
|
|
192
|
-
for (let r = 0; r < rows; r += 1) {
|
|
193
|
-
for (let c = 0; c < cols; c += 1) {
|
|
194
|
-
const cp = at(c, r);
|
|
195
|
-
const occupied = fixed.some((s2) => s2.col === c && s2.row === r);
|
|
196
|
-
scene.push(h('polygon', {
|
|
197
|
-
key: 'fl' + c + '-' + r,
|
|
198
|
-
points: isoDiamond(cp, TW, TH),
|
|
199
|
-
fill: tone(occupied ? 4.5 : 3),
|
|
200
|
-
stroke: hair,
|
|
201
|
-
strokeWidth: 0.7,
|
|
202
|
-
}));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
fixed.forEach((seat) => {
|
|
207
|
-
const a = seat.agent;
|
|
208
|
-
const p = seat.p;
|
|
209
|
-
const run = a.status === 'RUNNING';
|
|
210
|
-
const kid = !!a.parent;
|
|
211
|
-
const sp = kid ? SP * 0.88 : SP;
|
|
212
|
-
|
|
213
|
-
scene.push(h('polygon', {
|
|
214
|
-
key: 'mat' + a.id,
|
|
215
|
-
points: isoDiamond(p, TW * 0.86, TH * 0.86),
|
|
216
|
-
fill: tone(run ? 9 : 2),
|
|
217
|
-
stroke: run ? tone(30) : 'none',
|
|
218
|
-
strokeWidth: 1.2,
|
|
219
|
-
strokeDasharray: run ? '8 6' : 'none',
|
|
220
|
-
}));
|
|
221
|
-
|
|
222
|
-
const dw = TW * 0.34;
|
|
223
|
-
const dh = TH * 0.32;
|
|
224
|
-
const dy = p.y + 8;
|
|
225
|
-
const topFace = [
|
|
226
|
-
[p.x, dy - dh / 2 - DESK], [p.x + dw / 2, dy - DESK], [p.x, dy + dh / 2 - DESK], [p.x - dw / 2, dy - DESK],
|
|
227
|
-
].map((q) => q[0].toFixed(1) + ',' + q[1].toFixed(1)).join(' ');
|
|
228
|
-
const leftFace = [
|
|
229
|
-
[p.x - dw / 2, dy - DESK], [p.x, dy + dh / 2 - DESK], [p.x, dy + dh / 2], [p.x - dw / 2, dy],
|
|
230
|
-
].map((q) => q[0].toFixed(1) + ',' + q[1].toFixed(1)).join(' ');
|
|
231
|
-
const rightFace = [
|
|
232
|
-
[p.x, dy + dh / 2 - DESK], [p.x + dw / 2, dy - DESK], [p.x + dw / 2, dy], [p.x, dy + dh / 2],
|
|
233
|
-
].map((q) => q[0].toFixed(1) + ',' + q[1].toFixed(1)).join(' ');
|
|
234
|
-
scene.push(h('g', { key: 'dk' + a.id }, [
|
|
235
|
-
h('polygon', { key: 'l', points: leftFace, fill: tone(24, bg2), stroke: hair, strokeWidth: 0.8 }),
|
|
236
|
-
h('polygon', { key: 'r', points: rightFace, fill: tone(15, bg2), stroke: hair, strokeWidth: 0.8 }),
|
|
237
|
-
h('polygon', { key: 't', points: topFace, fill: tone(8, bg2), stroke: hair, strokeWidth: 1 }),
|
|
238
|
-
]));
|
|
239
|
-
|
|
240
|
-
const sprite = spriteParts(a.id || a.name);
|
|
241
|
-
const sx = p.x - 4 * sp;
|
|
242
|
-
const sy = p.y + 14 - 8 * sp;
|
|
243
|
-
scene.push(h('g', {
|
|
244
|
-
key: 'sp' + a.id,
|
|
245
|
-
className: run ? 'fg-iso-run' : undefined,
|
|
246
|
-
}, sprite.map((q, i) => h('rect', {
|
|
247
|
-
key: i,
|
|
248
|
-
x: sx + q[0] * sp,
|
|
249
|
-
y: sy + q[1] * sp,
|
|
250
|
-
width: q[2] * sp,
|
|
251
|
-
height: q[3] * sp,
|
|
252
|
-
rx: sp * 0.24,
|
|
253
|
-
fill: q[4],
|
|
254
|
-
})).concat(run ? [h('rect', {
|
|
255
|
-
key: 'led',
|
|
256
|
-
x: sx + 6.2 * sp,
|
|
257
|
-
y: sy + 5.4 * sp,
|
|
258
|
-
width: sp,
|
|
259
|
-
height: sp,
|
|
260
|
-
rx: sp * 0.3,
|
|
261
|
-
fill: '#38bdf8',
|
|
262
|
-
})] : [])));
|
|
263
|
-
|
|
264
|
-
const tw = 160;
|
|
265
|
-
const tx = Math.max(6, Math.min(W - tw - 6, p.x - tw / 2));
|
|
266
|
-
const ty = p.y - 96;
|
|
267
|
-
const status = run ? okc : a.status === 'STANDBY' ? warnc : dim;
|
|
268
|
-
const files = (a.files || []).slice(0, 2).map((f) => (f.write ? '改 ' : '') + f.name).join(' · ');
|
|
269
|
-
tags.push(h('g', {
|
|
270
|
-
key: 'tg' + a.id,
|
|
271
|
-
'data-tag': '1',
|
|
272
|
-
style: { cursor: 'pointer' },
|
|
273
|
-
onClick: () => onOpen && onOpen(a),
|
|
274
|
-
}, [
|
|
275
|
-
h('line', {
|
|
276
|
-
key: 'stem', x1: p.x, y1: ty + 40, x2: p.x, y2: p.y - 14,
|
|
277
|
-
stroke: hair, strokeWidth: 1, strokeDasharray: '3 3',
|
|
278
|
-
}),
|
|
279
|
-
h('rect', { key: 'bg', x: tx, y: ty, width: tw, height: 40, rx: 9, fill: bg1, stroke: hair, strokeWidth: 1 }),
|
|
280
|
-
h('circle', { key: 'd', cx: tx + 10, cy: ty + 12, r: 3.2, fill: status }),
|
|
281
|
-
h('text', {
|
|
282
|
-
key: 'n', x: tx + 18, y: ty + 16, fill: ink, fontSize: 10, fontWeight: 650,
|
|
283
|
-
}, (a.name || '未命名').slice(0, 16)),
|
|
284
|
-
h('rect', { key: 'tr', x: tx + 9, y: ty + 22, width: tw - 18, height: 3, rx: 2, fill: tone(12) }),
|
|
285
|
-
h('rect', {
|
|
286
|
-
key: 'fl', x: tx + 9, y: ty + 22, width: (tw - 18) * (progress(a) / 100), height: 3, rx: 2,
|
|
287
|
-
fill: run ? okc : tone(34),
|
|
288
|
-
}),
|
|
289
|
-
h('text', {
|
|
290
|
-
key: 'm', x: tx + 9, y: ty + 35, fill: dim, fontSize: 8.8,
|
|
291
|
-
}, (files || (kid ? '子工程师 · 第 ' : '主工程师 · 第 ') + (a.step || 0) + ' 步')),
|
|
292
|
-
]));
|
|
293
|
-
|
|
294
|
-
if (run && a.tool) {
|
|
295
|
-
const label = (a.tool.name || 'tool') + (a.tool.target ? ' · ' + a.tool.target : '');
|
|
296
|
-
const text = label.length > 26 ? label.slice(0, 25) + '…' : label;
|
|
297
|
-
const bw = Math.min(200, Math.max(78, 15 + text.length * 5.9));
|
|
298
|
-
const bx = Math.max(6, Math.min(W - bw - 6, p.x - bw / 2));
|
|
299
|
-
const by = p.y - 128;
|
|
300
|
-
tags.push(h('g', { key: 'bb' + a.id }, [
|
|
301
|
-
h('polygon', {
|
|
302
|
-
key: 'tail',
|
|
303
|
-
points: (bx + bw / 2 - 5).toFixed(1) + ',' + (by + 21) + ' ' + (bx + bw / 2 + 6).toFixed(1) + ',' + (by + 21) + ' ' + (bx + bw / 2).toFixed(1) + ',' + (by + 28),
|
|
304
|
-
fill: bg1, stroke: accent, strokeWidth: 1,
|
|
305
|
-
}),
|
|
306
|
-
h('rect', { key: 'b', x: bx, y: by, width: bw, height: 22, rx: 7, fill: bg1, stroke: accent, strokeWidth: 1 }),
|
|
307
|
-
h('text', {
|
|
308
|
-
key: 't', x: bx + 8, y: by + 15, fill: ink, fontSize: 9.8, fontWeight: 600,
|
|
309
|
-
}, text),
|
|
310
|
-
]));
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
fixed.forEach((seat) => {
|
|
315
|
-
const a = seat.agent;
|
|
316
|
-
if (!a.parent) return;
|
|
317
|
-
const from = bySeat.get(a.parent);
|
|
318
|
-
const to = seat.p;
|
|
319
|
-
if (!from) return;
|
|
320
|
-
const pid = 'fgwalk' + Math.abs(hash(String(a.id))).toString(36);
|
|
321
|
-
const lift = Math.min(from.y, to.y) - 66;
|
|
322
|
-
const d = 'M ' + from.x.toFixed(1) + ' ' + (from.y + 2).toFixed(1) + ' Q ' + ((from.x + to.x) / 2).toFixed(1) + ' ' + lift.toFixed(1) + ' ' + to.x.toFixed(1) + ' ' + (to.y + 2).toFixed(1);
|
|
323
|
-
const dur = a.status === 'RUNNING' ? '3.4s' : '7s';
|
|
324
|
-
couriers.push(h('path', {
|
|
325
|
-
key: 'p' + pid, id: pid, d, fill: 'none', stroke: tone(30), strokeWidth: 1.4,
|
|
326
|
-
strokeDasharray: '5 7', className: 'fg-flow', opacity: 0.8,
|
|
327
|
-
}));
|
|
328
|
-
const mini = spriteParts(a.id || a.name).slice(5);
|
|
329
|
-
couriers.push(h('g', { key: 'c' + pid, className: 'fg-flow-g' }, [
|
|
330
|
-
h('animateMotion', {
|
|
331
|
-
key: 'am', dur, repeatCount: 'indefinite', rotate: '0', xlinkHref: '#' + pid,
|
|
332
|
-
}),
|
|
333
|
-
...mini.map((q, i) => h('rect', {
|
|
334
|
-
key: i, x: q[0] * 1.8 - 6, y: q[1] * 1.8 - 6, width: q[2] * 1.8, height: q[3] * 1.8, fill: q[4], rx: 1,
|
|
335
|
-
})),
|
|
336
|
-
]));
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
const zoom = Math.min(2.2, Math.max(0.6, Number(scale) || 1));
|
|
340
|
-
const off = offset || { x: 0, y: 0 };
|
|
341
|
-
const ox = Number(off.x) || 0;
|
|
342
|
-
const oy = Number(off.y) || 0;
|
|
343
|
-
const vcx = W / 2;
|
|
344
|
-
const vcy = H / 2;
|
|
345
|
-
const view = 'translate(' + (vcx + ox).toFixed(2) + ' ' + (vcy + oy).toFixed(2) + ')'
|
|
346
|
-
+ ' scale(' + zoom.toFixed(4) + ')'
|
|
347
|
-
+ ' translate(' + (-vcx).toFixed(2) + ' ' + (-vcy).toFixed(2) + ')';
|
|
348
|
-
|
|
349
|
-
return h('svg', {
|
|
350
|
-
className: 'fg-iso',
|
|
351
|
-
viewBox: '0 0 ' + W + ' ' + H,
|
|
352
|
-
preserveAspectRatio: 'xMidYMin meet',
|
|
353
|
-
style: { width: '100%', height: '100%', display: 'block' },
|
|
354
|
-
}, h('g', { key: 'viewport', transform: view }, scene.concat(couriers, tags)));
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function useFloor(active) {
|
|
358
|
-
const [state, setState] = useState(null);
|
|
77
|
+
function useFloor(open, initial) {
|
|
78
|
+
const [data, setData] = useState(() => initial || null);
|
|
359
79
|
useEffect(() => {
|
|
360
80
|
let alive = true;
|
|
361
|
-
let timer =
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (alive) setState(null);
|
|
370
|
-
}
|
|
371
|
-
if (alive) timer = window.setTimeout(load, active ? 1800 : 7000);
|
|
81
|
+
let timer = null;
|
|
82
|
+
const tick = () => {
|
|
83
|
+
Promise.resolve()
|
|
84
|
+
.then(() => fetch(ROUTE, { headers: { accept: 'application/json' } }))
|
|
85
|
+
.then((r) => (r && r.ok ? r.json() : null))
|
|
86
|
+
.then((d) => { if (alive && d) setData(d); })
|
|
87
|
+
.catch(() => {})
|
|
88
|
+
.then(() => { if (alive) timer = setTimeout(tick, open ? 2000 : 6000); });
|
|
372
89
|
};
|
|
373
|
-
|
|
374
|
-
return () => { alive = false;
|
|
375
|
-
}, [
|
|
376
|
-
return
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function openSession(id) {
|
|
380
|
-
try {
|
|
381
|
-
const ctx = moduleCtx;
|
|
382
|
-
if (!ctx) return;
|
|
383
|
-
const ws = ctx.get ? ctx.get('uiWorkspace') : null;
|
|
384
|
-
if (ws && typeof ws.openSession === 'function') { ws.openSession(id); return; }
|
|
385
|
-
const sessions = ctx.get ? ctx.get('sessions') : null;
|
|
386
|
-
if (sessions && typeof sessions.scope === 'function') sessions.scope(id);
|
|
387
|
-
} catch (e) { /* read-only fallback */ }
|
|
90
|
+
tick();
|
|
91
|
+
return () => { alive = false; if (timer) clearTimeout(timer); };
|
|
92
|
+
}, [open]);
|
|
93
|
+
return data;
|
|
388
94
|
}
|
|
389
95
|
|
|
390
96
|
function deriveAgents(data) {
|
|
@@ -395,373 +101,195 @@ window.__ModuleLoader__.load({
|
|
|
395
101
|
id: s.id,
|
|
396
102
|
name: s.title || s.cwd || s.id,
|
|
397
103
|
parent: s.parent || null,
|
|
398
|
-
role: s.parent ? 'SUBAGENT' : 'LEAD',
|
|
399
104
|
status: s.running ? 'RUNNING' : (now - (s.updatedAt || 0) < 300000 ? 'STANDBY' : 'IDLE'),
|
|
400
105
|
step: s.step || 0,
|
|
401
106
|
turn: s.turn || 0,
|
|
402
107
|
tools: s.toolCalls || 0,
|
|
403
108
|
tokens: (s.tokensIn || 0) + (s.tokensOut || 0),
|
|
404
|
-
lastEvent: s.lastLabel || '',
|
|
405
109
|
tool: s.lastTool || null,
|
|
110
|
+
forked: !!(data.focus && s.id === data.focus),
|
|
406
111
|
files: (Array.isArray(s.diffFiles) && s.diffFiles.length)
|
|
407
112
|
? s.diffFiles.slice(0, 4).map((f) => ({ name: String(f).split('/').pop(), write: true }))
|
|
408
113
|
: (Array.isArray(s.files) ? s.files : []),
|
|
409
|
-
updatedAt: s.updatedAt,
|
|
410
|
-
|
|
411
|
-
})) : (Array.isArray(data.agents) ? data.agents : []);
|
|
114
|
+
updatedAt: s.updatedAt || 0,
|
|
115
|
+
})) : [];
|
|
412
116
|
|
|
413
117
|
const seen = new Map();
|
|
414
|
-
for (const a of list)
|
|
415
|
-
const key = (a.name || '').trim();
|
|
416
|
-
seen.set(key, (seen.get(key) || 0) + 1);
|
|
417
|
-
}
|
|
118
|
+
for (const a of list) seen.set((a.name || '').trim(), (seen.get((a.name || '').trim()) || 0) + 1);
|
|
418
119
|
for (const a of list) {
|
|
419
120
|
if (seen.get((a.name || '').trim()) > 1) {
|
|
420
|
-
a.name = a.name + ' · ' + String(a.id ||
|
|
121
|
+
a.name = a.name + ' · ' + String(a.id || '').slice(-4);
|
|
421
122
|
}
|
|
422
123
|
}
|
|
423
|
-
for (const a of list) {
|
|
424
|
-
if (a.parent && a.name && a.name.length > 18) a.name = a.name.slice(0, 18) + '…';
|
|
425
|
-
}
|
|
426
124
|
|
|
427
|
-
const
|
|
125
|
+
const live = list.filter((a) => {
|
|
428
126
|
if (!a.parent) return true;
|
|
429
|
-
|
|
127
|
+
if (a.status === 'RUNNING') return true;
|
|
128
|
+
return now - (a.updatedAt || 0) < CHILD_TTL;
|
|
430
129
|
});
|
|
431
130
|
|
|
432
|
-
const
|
|
433
|
-
const
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const bucket = children.get(pid) || [];
|
|
439
|
-
bucket.push(a);
|
|
440
|
-
children.set(pid, bucket);
|
|
441
|
-
} else {
|
|
442
|
-
leaders.push(a);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
const ordered = [];
|
|
131
|
+
const rank = (a) => (a.status === 'RUNNING' ? 0 : a.status === 'STANDBY' ? 1 : 2);
|
|
132
|
+
const byId = new Map(live.map((a) => [a.id, a]));
|
|
133
|
+
const leaders = live.filter((a) => !a.parent || !byId.has(a.parent));
|
|
134
|
+
leaders.sort((x, y) => rank(x) - rank(y) || (y.updatedAt || 0) - (x.updatedAt || 0));
|
|
135
|
+
|
|
136
|
+
const out = [];
|
|
446
137
|
for (const lead of leaders) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
138
|
+
const kids = live.filter((a) => a.parent === lead.id);
|
|
139
|
+
kids.sort((x, y) => rank(x) - rank(y) || (y.updatedAt || 0) - (x.updatedAt || 0));
|
|
140
|
+
out.push({ ...lead, depth: 0, kids: kids.length });
|
|
141
|
+
for (const k of kids) out.push({ ...k, depth: 1, kids: 0 });
|
|
450
142
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function fileLine(a) {
|
|
147
|
+
const files = (a.files || []).slice(0, 3).map((f) => (f.write ? '改 ' : '') + f.name);
|
|
148
|
+
if (files.length) return files.join(' · ');
|
|
149
|
+
if (a.tool && a.tool.name) {
|
|
150
|
+
const target = String(a.tool.target || '').split('/').pop();
|
|
151
|
+
return a.tool.name + (target ? ' · ' + target : '');
|
|
454
152
|
}
|
|
455
|
-
return
|
|
153
|
+
return '';
|
|
456
154
|
}
|
|
457
155
|
|
|
458
|
-
function
|
|
459
|
-
const
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
'
|
|
464
|
-
'
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
h('div', { className: 'fg-av', key: 'av' }, h(Engine, {
|
|
469
|
-
seed: a.id || a.name, size: depth ? 22 : 30, running: run,
|
|
470
|
-
})),
|
|
471
|
-
h('div', { className: 'fg-main', key: 'main' }, [
|
|
472
|
-
h('div', { className: 'fg-top', key: 'top' }, [
|
|
473
|
-
h('span', { className: 'fg-name', key: 'n' }, a.name || '未命名'),
|
|
474
|
-
h('span', { className: 'fg-chip ' + st.cls, key: 'c' }, st.text),
|
|
475
|
-
]),
|
|
476
|
-
h('div', { className: 'fg-sub', key: 'sub' }, [
|
|
477
|
-
h('span', { key: 'r' }, depth ? '子工程师' : (kidCount ? '组长 · 带队 ' + kidCount + ' 人' : '主工程师')),
|
|
478
|
-
h('span', { key: 's' }, '第 ' + (a.step || 0) + ' 步 · 第 ' + (a.turn || 0) + ' 轮'),
|
|
479
|
-
h('span', { key: 't' }, num(a.tools) + ' 次工具'),
|
|
480
|
-
]),
|
|
481
|
-
a.tool ? h('div', { className: 'fg-task', key: 'task' }, [
|
|
482
|
-
h('b', { key: 'k' }, a.tool.name || '工具'),
|
|
483
|
-
h('span', { key: 'v' }, a.tool.target || ''),
|
|
484
|
-
]) : null,
|
|
485
|
-
(a.files && a.files.length) ? h('div', { className: 'fg-files', key: 'files' },
|
|
486
|
-
a.files.slice(0, 3).map((f) => (f.write ? '改 ' : '') + f.name).join(' · ')) : null,
|
|
487
|
-
h('div', { className: 'fg-bar', key: 'bar' }, h('i', { style: { width: progress(a) + '%' } })),
|
|
488
|
-
h('div', { className: 'fg-meta', key: 'meta' }, [
|
|
489
|
-
h('span', { key: 'tok' }, num(a.tokens) + ' tok'),
|
|
490
|
-
h('span', { key: 'ago' }, ago(a.updatedAt)),
|
|
491
|
-
]),
|
|
156
|
+
function MonitorRow(props) {
|
|
157
|
+
const a = props.agent;
|
|
158
|
+
const cls = 'fg-dot ' + (a.status === 'RUNNING' ? 'run' : a.status === 'STANDBY' ? 'wait' : '');
|
|
159
|
+
const shot = fileLine(a);
|
|
160
|
+
return h('div', { className: 'fg-row', onClick: () => props.onOpen(a) }, [
|
|
161
|
+
h('span', { className: cls, key: 'dot' }),
|
|
162
|
+
h('span', { className: 'fg-name', key: 'name' }, [
|
|
163
|
+
a.depth ? '↳ ' : '',
|
|
164
|
+
a.name || '未命名',
|
|
165
|
+
a.depth ? null : (a.kids ? h('em', { key: 'k' }, '带队 ' + a.kids) : null),
|
|
492
166
|
]),
|
|
167
|
+
h('span', { className: 'fg-num', key: 'num' },
|
|
168
|
+
'第' + a.step + '步·第' + a.turn + '轮 · ' + num(a.tokens) + ' tok'),
|
|
169
|
+
shot ? h('span', { className: 'fg-file', key: 'file' }, shot) : null,
|
|
493
170
|
]);
|
|
494
171
|
}
|
|
495
172
|
|
|
496
|
-
function
|
|
173
|
+
function readPos() {
|
|
174
|
+
try {
|
|
175
|
+
const raw = localStorage.getItem(POS_KEY);
|
|
176
|
+
if (raw) {
|
|
177
|
+
const v = JSON.parse(raw);
|
|
178
|
+
if (v && Number.isFinite(v.x) && Number.isFinite(v.y)) return { x: v.x, y: v.y };
|
|
179
|
+
}
|
|
180
|
+
} catch {}
|
|
181
|
+
return { x: 14, y: 14 };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function MonitorBar(props) {
|
|
185
|
+
const ctx = (props && props.ctx) || null;
|
|
497
186
|
const [open, setOpen] = useState(() => {
|
|
498
|
-
try { return localStorage.getItem(OPEN_KEY) === '1'; } catch
|
|
499
|
-
});
|
|
500
|
-
const [full, setFull] = useState(false);
|
|
501
|
-
const [onlyActive, setOnlyActive] = useState(() => {
|
|
502
|
-
try { return localStorage.getItem(ACTIVE_KEY) === '1'; } catch (e) { return false; }
|
|
503
|
-
});
|
|
504
|
-
const [pos, setPos] = useState(() => {
|
|
505
|
-
try {
|
|
506
|
-
const raw = localStorage.getItem(POS_KEY);
|
|
507
|
-
return raw ? JSON.parse(raw) : null;
|
|
508
|
-
} catch (e) { return null; }
|
|
187
|
+
try { return localStorage.getItem(OPEN_KEY) === '1'; } catch { return false; }
|
|
509
188
|
});
|
|
189
|
+
const [pos, setPos] = useState(readPos);
|
|
510
190
|
const [dragging, setDragging] = useState(false);
|
|
511
|
-
const panelRef = useRef(null);
|
|
512
191
|
const dragRef = useRef(null);
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
const [viewOffset, setViewOffset] = useState({ x: 0, y: 0 });
|
|
517
|
-
const [viewDrag, setViewDrag] = useState(false);
|
|
518
|
-
const stageRef = useRef(null);
|
|
519
|
-
const panRef = useRef(null);
|
|
520
|
-
const suppressRef = useRef(false);
|
|
521
|
-
const data = useFloor(open || full);
|
|
522
|
-
const ordered = deriveAgents(data);
|
|
523
|
-
const agents = ordered.map((o) => o.agent);
|
|
192
|
+
const movedRef = useRef(false);
|
|
193
|
+
const data = useFloor(open, props && props.initialData);
|
|
194
|
+
const agents = deriveAgents(data);
|
|
524
195
|
const running = agents.filter((a) => a.status === 'RUNNING').length;
|
|
525
|
-
const
|
|
526
|
-
const
|
|
527
|
-
? ordered.filter((o) => o.agent.status === 'RUNNING').map((o) => ({ agent: o.agent, depth: 0 }))
|
|
528
|
-
: ordered;
|
|
529
|
-
|
|
530
|
-
useEffect(() => {
|
|
531
|
-
try { localStorage.setItem(OPEN_KEY, open ? '1' : '0'); } catch (e) { /* private mode */ }
|
|
532
|
-
}, [open]);
|
|
533
|
-
|
|
534
|
-
useEffect(() => {
|
|
535
|
-
try { localStorage.setItem(ACTIVE_KEY, onlyActive ? '1' : '0'); } catch (e) { /* private mode */ }
|
|
536
|
-
}, [onlyActive]);
|
|
537
|
-
|
|
538
|
-
const onDragStart = (e) => {
|
|
539
|
-
if (e.button !== 0) return;
|
|
540
|
-
const el = panelRef.current;
|
|
541
|
-
if (!el) return;
|
|
542
|
-
const rect = el.getBoundingClientRect();
|
|
543
|
-
dragRef.current = { dx: e.clientX - rect.left, dy: e.clientY - rect.top, w: rect.width, h: rect.height };
|
|
544
|
-
setDragging(true);
|
|
545
|
-
try { e.currentTarget.setPointerCapture(e.pointerId); } catch (err) { /* older engines */ }
|
|
546
|
-
};
|
|
547
|
-
const onDragMove = (e) => {
|
|
548
|
-
const d = dragRef.current;
|
|
549
|
-
if (!d) return;
|
|
550
|
-
const x = Math.min(Math.max(8, e.clientX - d.dx), Math.max(8, window.innerWidth - d.w - 8));
|
|
551
|
-
const y = Math.min(Math.max(8, e.clientY - d.dy), Math.max(8, window.innerHeight - d.h - 8));
|
|
552
|
-
setPos({ x, y });
|
|
553
|
-
};
|
|
554
|
-
const onDragEnd = () => {
|
|
555
|
-
if (!dragRef.current) { return; }
|
|
556
|
-
dragRef.current = null;
|
|
557
|
-
setDragging(false);
|
|
558
|
-
try {
|
|
559
|
-
const rect = panelRef.current ? panelRef.current.getBoundingClientRect() : null;
|
|
560
|
-
if (rect) localStorage.setItem(POS_KEY, JSON.stringify({ x: Math.round(rect.left), y: Math.round(rect.top) }));
|
|
561
|
-
} catch (e) { /* private mode */ }
|
|
562
|
-
};
|
|
196
|
+
const shown = agents.slice(0, MAX_ROWS);
|
|
197
|
+
const hidden = agents.length - shown.length;
|
|
563
198
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const vb = svg && svg.viewBox ? svg.viewBox.baseVal : null;
|
|
569
|
-
if (!svg || !vb || !vb.width || !vb.height) return null;
|
|
570
|
-
let rect = null;
|
|
571
|
-
try { rect = svg.getBoundingClientRect(); } catch (err) { return null; }
|
|
572
|
-
if (!rect || !rect.width || !rect.height) return null;
|
|
573
|
-
const k = Math.min(rect.width / vb.width, rect.height / vb.height);
|
|
574
|
-
if (!k || !isFinite(k)) return null;
|
|
575
|
-
return { k: k, w: vb.width, h: vb.height };
|
|
199
|
+
const toggle = () => {
|
|
200
|
+
const next = !open;
|
|
201
|
+
setOpen(next);
|
|
202
|
+
try { localStorage.setItem(OPEN_KEY, next ? '1' : '0'); } catch {}
|
|
576
203
|
};
|
|
577
204
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
// 滚轮缩放:原生监听,passive:false 才能 preventDefault 阻止页面/容器滚动
|
|
581
|
-
useEffect(() => {
|
|
582
|
-
const el = stageRef.current;
|
|
583
|
-
if (!el || typeof el.addEventListener !== 'function') return undefined;
|
|
584
|
-
const onWheel = (e) => {
|
|
585
|
-
if (!e.deltaY) return;
|
|
586
|
-
e.preventDefault();
|
|
587
|
-
const factor = e.deltaY < 0 ? 1.1 : 0.9;
|
|
588
|
-
setViewScale((prev) => clampScale(prev * factor));
|
|
589
|
-
};
|
|
590
|
-
el.addEventListener('wheel', onWheel, { passive: false });
|
|
591
|
-
return () => el.removeEventListener('wheel', onWheel);
|
|
592
|
-
}, [full]);
|
|
205
|
+
useEffect(() => { ensureStyle(); }, []);
|
|
593
206
|
|
|
594
|
-
// 拖拽平移:按下后在 window 上跟随,松手/取消结束
|
|
595
207
|
useEffect(() => {
|
|
596
|
-
if (!
|
|
597
|
-
const
|
|
598
|
-
const
|
|
599
|
-
if (!
|
|
600
|
-
const dx = e.clientX -
|
|
601
|
-
const dy = e.clientY -
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
setViewOffset({
|
|
609
|
-
x: Math.max(-limX, Math.min(limX, p.ox + dx / k)),
|
|
610
|
-
y: Math.max(-limY, Math.min(limY, p.oy + dy / k)),
|
|
208
|
+
if (!dragging) return undefined;
|
|
209
|
+
const move = (e) => {
|
|
210
|
+
const d = dragRef.current;
|
|
211
|
+
if (!d) return;
|
|
212
|
+
const dx = e.clientX - d.x0;
|
|
213
|
+
const dy = e.clientY - d.y0;
|
|
214
|
+
if (Math.abs(dx) + Math.abs(dy) > 3) movedRef.current = true;
|
|
215
|
+
const maxX = Math.max(8, (window.innerWidth || 1200) - 120);
|
|
216
|
+
const maxY = Math.max(8, (window.innerHeight || 800) - 60);
|
|
217
|
+
setPos({
|
|
218
|
+
x: Math.min(maxX, Math.max(8, d.px + dx)),
|
|
219
|
+
y: Math.min(maxY, Math.max(8, d.py - dy)),
|
|
611
220
|
});
|
|
612
221
|
};
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
setViewDrag(false);
|
|
222
|
+
const up = () => {
|
|
223
|
+
setDragging(false);
|
|
224
|
+
const p = readPos();
|
|
225
|
+
try { localStorage.setItem(POS_KEY, JSON.stringify(snapRef.current || p)); } catch {}
|
|
618
226
|
};
|
|
619
|
-
window.addEventListener('pointermove',
|
|
620
|
-
window.addEventListener('pointerup',
|
|
621
|
-
window.addEventListener('pointercancel',
|
|
227
|
+
window.addEventListener('pointermove', move);
|
|
228
|
+
window.addEventListener('pointerup', up);
|
|
229
|
+
window.addEventListener('pointercancel', up);
|
|
622
230
|
return () => {
|
|
623
|
-
window.removeEventListener('pointermove',
|
|
624
|
-
window.removeEventListener('pointerup',
|
|
625
|
-
window.removeEventListener('pointercancel',
|
|
231
|
+
window.removeEventListener('pointermove', move);
|
|
232
|
+
window.removeEventListener('pointerup', up);
|
|
233
|
+
window.removeEventListener('pointercancel', up);
|
|
626
234
|
};
|
|
627
|
-
}, [
|
|
235
|
+
}, [dragging]);
|
|
628
236
|
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
suppressRef.current = false;
|
|
632
|
-
panRef.current = { x: e.clientX, y: e.clientY, ox: viewOffset.x, oy: viewOffset.y, moved: false };
|
|
633
|
-
setViewDrag(true);
|
|
634
|
-
};
|
|
237
|
+
const snapRef = useRef(pos);
|
|
238
|
+
snapRef.current = pos;
|
|
635
239
|
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
240
|
+
const onHeadDown = (e) => {
|
|
241
|
+
if (e.button !== undefined && e.button !== 0) return;
|
|
242
|
+
dragRef.current = { x0: e.clientX, y0: e.clientY, px: pos.x, py: pos.y };
|
|
243
|
+
movedRef.current = false;
|
|
244
|
+
setDragging(true);
|
|
641
245
|
};
|
|
642
246
|
|
|
643
|
-
const
|
|
644
|
-
if (
|
|
645
|
-
|
|
247
|
+
const onHeadClick = () => {
|
|
248
|
+
if (movedRef.current) { movedRef.current = false; return; }
|
|
249
|
+
toggle();
|
|
646
250
|
};
|
|
647
251
|
|
|
648
|
-
|
|
649
|
-
const
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
if (
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
const leaders = ordered.filter((o) => o.depth === 0).map((o) => o.agent);
|
|
659
|
-
leaders.sort((p1, q1) => (q1.status === 'RUNNING' ? 1 : 0) - (p1.status === 'RUNNING' ? 1 : 0));
|
|
660
|
-
const COLS = 4;
|
|
661
|
-
const seats = [];
|
|
662
|
-
let cursor = { row: 0, col: 0 };
|
|
663
|
-
const place = (agent) => {
|
|
664
|
-
seats.push({ agent, row: cursor.row, col: cursor.col });
|
|
665
|
-
cursor.col += 1;
|
|
666
|
-
if (cursor.col >= COLS) { cursor.col = 0; cursor.row += 1; }
|
|
667
|
-
};
|
|
668
|
-
leaders.forEach(place);
|
|
669
|
-
if (cursor.col !== 0) { cursor.col = 0; cursor.row += 1; }
|
|
670
|
-
const orphans = [];
|
|
671
|
-
for (const [pid, kids] of kidsOf) {
|
|
672
|
-
if (!leaders.some((a) => (a.id || a.sessionId) === pid)) orphans.push.apply(orphans, kids);
|
|
673
|
-
}
|
|
674
|
-
const childSeats = [];
|
|
675
|
-
for (const lead of leaders) {
|
|
676
|
-
const kids = kidsOf.get(lead.id || lead.sessionId) || [];
|
|
677
|
-
for (const k of kids) childSeats.push(k);
|
|
678
|
-
}
|
|
679
|
-
childSeats.concat(orphans).forEach(place);
|
|
680
|
-
return h('div', { className: 'fg-root fg-full' }, [
|
|
681
|
-
h('div', { className: 'fg-full-head', key: 'head' }, [
|
|
682
|
-
h('span', { className: 'fg-full-title', key: 't' }, 'Agent Floor'),
|
|
683
|
-
h('span', { className: 'fg-full-sub', key: 's' }, leaderCount + ' 位组长 · ' + agents.length + ' 位工程师 · ' + running + ' 人在干活'),
|
|
684
|
-
h('span', {
|
|
685
|
-
className: 'fg-full-sub',
|
|
686
|
-
key: 'hint',
|
|
687
|
-
style: { opacity: 0.42, marginLeft: 6 },
|
|
688
|
-
title: '滚轮缩放 · 按住拖动平移 · 双击空白复位',
|
|
689
|
-
}, Math.round(viewScale * 100) + '%'),
|
|
690
|
-
h('button', { className: 'fg-icon', key: 'x', style: { marginLeft: 'auto' }, onClick: () => setFull(false), title: '关闭' }, '✕'),
|
|
691
|
-
]),
|
|
692
|
-
h('div', {
|
|
693
|
-
className: 'fg-stage',
|
|
694
|
-
key: 'stage',
|
|
695
|
-
ref: stageRef,
|
|
696
|
-
style: { cursor: viewDrag ? 'grabbing' : 'grab', userSelect: viewDrag ? 'none' : undefined },
|
|
697
|
-
onPointerDown: onStageDown,
|
|
698
|
-
onDoubleClick: onStageDoubleClick,
|
|
699
|
-
title: '滚轮缩放 · 按住拖动平移 · 双击空白复位',
|
|
700
|
-
}, seats.length
|
|
701
|
-
? h(IsoFloor, { seats, onOpen: onStageOpen, scale: viewScale, offset: viewOffset })
|
|
702
|
-
: h('div', { className: 'fg-empty' }, '还没有工程师上岗')),
|
|
703
|
-
]);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
if (!open) {
|
|
707
|
-
return h('div', { className: 'fg-root' },
|
|
708
|
-
h('button', { className: 'fg-pill', onClick: () => setOpen(true), title: '打开 Agent Floor' }, [
|
|
709
|
-
h('span', { className: 'fg-dot' + (running ? ' fg-dot-live' : ''), key: 'd' }),
|
|
710
|
-
h('span', { key: 't' }, '工位 ' + agents.length + ' 人'),
|
|
711
|
-
running ? h('span', { key: 'r' }, '· ' + running + ' 在干活') : null,
|
|
712
|
-
].filter(Boolean)));
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
const style = pos
|
|
716
|
-
? { left: pos.x + 'px', top: pos.y + 'px', bottom: 'auto', cursor: dragging ? 'grabbing' : undefined }
|
|
717
|
-
: undefined;
|
|
252
|
+
const openSession = (a) => {
|
|
253
|
+
const id = a && a.id;
|
|
254
|
+
if (!id) return;
|
|
255
|
+
try {
|
|
256
|
+
const ui = ctx && typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : null;
|
|
257
|
+
if (ui && typeof ui.openSession === 'function') { ui.openSession(id); return; }
|
|
258
|
+
const ses = ctx && typeof ctx.get === 'function' ? ctx.get('sessions') : null;
|
|
259
|
+
if (ses && typeof ses.scope === 'function') ses.scope(id);
|
|
260
|
+
} catch {}
|
|
261
|
+
};
|
|
718
262
|
|
|
719
|
-
return h('div', {
|
|
720
|
-
className: 'fg-
|
|
721
|
-
|
|
722
|
-
style,
|
|
263
|
+
return h('div', { className: 'fg-root' }, h('div', {
|
|
264
|
+
className: 'fg-dock',
|
|
265
|
+
style: { left: pos.x + 'px', bottom: pos.y + 'px' },
|
|
723
266
|
}, [
|
|
724
267
|
h('div', {
|
|
725
|
-
className: 'fg-head',
|
|
268
|
+
className: 'fg-head' + (dragging ? ' dragging' : ''),
|
|
726
269
|
key: 'head',
|
|
727
|
-
onPointerDown:
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
onPointerCancel: onDragEnd,
|
|
731
|
-
title: '拖动标题栏可移动',
|
|
270
|
+
onPointerDown: onHeadDown,
|
|
271
|
+
onClick: onHeadClick,
|
|
272
|
+
title: '拖动可移动位置 · 点击' + (open ? '收起' : '展开'),
|
|
732
273
|
}, [
|
|
733
|
-
h('span', { className: 'fg-
|
|
734
|
-
h('span', { className: 'fg-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
onClick: () => setOnlyActive((v) => !v),
|
|
740
|
-
title: onlyActive ? '显示全部工程师' : '只显示在干活的',
|
|
741
|
-
style: onlyActive ? { color: 'var(--dsw-alias-state-success-primary,#22c55e)', opacity: 1 } : undefined,
|
|
742
|
-
}, '●'),
|
|
743
|
-
h('button', { className: 'fg-icon', key: 'f', onClick: () => setFull(true), title: '上帝视角' }, '⛶'),
|
|
744
|
-
h('button', { className: 'fg-icon', key: 'x', onClick: () => setOpen(false), title: '收起' }, '⌄'),
|
|
274
|
+
h('span', { className: 'fg-pulse' + (running ? ' on' : ''), key: 'p' }),
|
|
275
|
+
h('span', { className: 'fg-sum', key: 's' }, [
|
|
276
|
+
running ? running + ' 在跑' : '全部空闲',
|
|
277
|
+
h('i', { key: 'i' }, ' / ' + agents.length + ' 在岗'),
|
|
278
|
+
]),
|
|
279
|
+
h('span', { className: 'fg-caret', key: 'c' }, open ? '⌄' : '⌃'),
|
|
745
280
|
]),
|
|
746
|
-
h('div', { className: 'fg-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}))
|
|
753
|
-
: h('div', { className: 'fg-empty' }, onlyActive ? '现在没人干活' : '还没有工程师上岗')),
|
|
754
|
-
]);
|
|
281
|
+
open ? h('div', { className: 'fg-body', key: 'body' }, [
|
|
282
|
+
...shown.map((a) => h(MonitorRow, { key: a.id || a.name, agent: a, onOpen: openSession })),
|
|
283
|
+
hidden > 0 ? h('div', { className: 'fg-more', key: 'more' }, '还有 ' + hidden + ' 个会话') : null,
|
|
284
|
+
agents.length === 0 ? h('div', { className: 'fg-more', key: 'empty' }, '暂无会话') : null,
|
|
285
|
+
]) : null,
|
|
286
|
+
]));
|
|
755
287
|
}
|
|
756
288
|
|
|
757
|
-
const inject = ['slots'];
|
|
758
|
-
|
|
759
289
|
function apply(ctx) {
|
|
760
|
-
|
|
761
|
-
installStyle();
|
|
762
|
-
const mount = (ready) => {
|
|
290
|
+
const bridge = (ready) => {
|
|
763
291
|
const target = ready && ready.slots ? ready : ctx;
|
|
764
|
-
const slots = target.slots;
|
|
292
|
+
const slots = target && target.slots;
|
|
765
293
|
if (!slots) return;
|
|
766
294
|
const render = () => {
|
|
767
295
|
slots.inject('shell.overlay', () => slots.register({
|
|
@@ -769,18 +297,18 @@ window.__ModuleLoader__.load({
|
|
|
769
297
|
id: 'dsh-agent-floor',
|
|
770
298
|
order: 940,
|
|
771
299
|
label: 'Agent Floor',
|
|
772
|
-
}, (
|
|
300
|
+
}, () => h(MonitorBar, { ctx })));
|
|
773
301
|
};
|
|
774
302
|
if (typeof target.effect === 'function') target.effect(render, 'dsh-agent-floor: mounts');
|
|
775
303
|
else render();
|
|
776
304
|
};
|
|
777
305
|
if (typeof ctx.inject === 'function') {
|
|
778
|
-
ctx.inject(['slots'],
|
|
306
|
+
ctx.inject(['slots'], bridge);
|
|
779
307
|
return;
|
|
780
308
|
}
|
|
781
|
-
if (ctx.slots)
|
|
309
|
+
if (ctx.slots) bridge(ctx);
|
|
782
310
|
}
|
|
783
311
|
|
|
784
|
-
return { inject, apply };
|
|
312
|
+
return { inject, apply, __dshTest: { deriveAgents, MonitorBar, MonitorRow } };
|
|
785
313
|
},
|
|
786
314
|
});
|