dsh-agent-floor 0.1.0 → 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/README.md +21 -40
- package/client.js +145 -689
- 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,89 @@ 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 ACTIVE_KEY = 'dsh.agent-floor.active';
|
|
12
11
|
const CHILD_TTL = 10 * 60 * 1000;
|
|
12
|
+
const MAX_ROWS = 8;
|
|
13
13
|
|
|
14
14
|
const CSS = `
|
|
15
|
-
.fg-root{
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
.fg-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.fg-
|
|
23
|
-
|
|
24
|
-
.fg-head:
|
|
25
|
-
.fg-
|
|
26
|
-
|
|
27
|
-
.fg-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.fg-
|
|
31
|
-
.fg-
|
|
32
|
-
.fg-
|
|
33
|
-
.fg-
|
|
34
|
-
|
|
35
|
-
.fg-
|
|
36
|
-
|
|
37
|
-
.fg-
|
|
38
|
-
.fg-
|
|
39
|
-
|
|
40
|
-
.fg-
|
|
41
|
-
.fg-
|
|
42
|
-
.fg-name{
|
|
43
|
-
.fg-
|
|
44
|
-
.fg-
|
|
45
|
-
.fg-
|
|
46
|
-
|
|
47
|
-
.fg-
|
|
48
|
-
.fg-sub{font-size:10.5px;opacity:.6;display:flex;gap:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
|
|
49
|
-
.fg-bar{height:4px;border-radius:3px;background:var(--dsw-alias-bg-layer-2,rgba(255,255,255,.1));overflow:hidden;}
|
|
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;}
|
|
15
|
+
.fg-root{position:fixed;left:14px;bottom:14px;z-index:60;pointer-events:auto;
|
|
16
|
+
font:12px/1.5 ui-sans-serif,-apple-system,"SF Pro Text","PingFang SC",system-ui,sans-serif;
|
|
17
|
+
color:var(--dsw-alias-label-primary,#1c1c1e);}
|
|
18
|
+
.fg-dock{min-width:196px;max-width:340px;border-radius:12px;overflow:hidden;
|
|
19
|
+
background:var(--dsw-alias-bg-overlay,#fff);
|
|
20
|
+
border:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.09));
|
|
21
|
+
box-shadow:0 8px 28px rgba(0,0,0,.12);}
|
|
22
|
+
.fg-head{display:flex;align-items:center;gap:7px;padding:7px 10px;cursor:pointer;
|
|
23
|
+
user-select:none;-webkit-user-select:none;}
|
|
24
|
+
.fg-head:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.03));}
|
|
25
|
+
.fg-pulse{width:7px;height:7px;border-radius:50%;flex:0 0 auto;
|
|
26
|
+
background:var(--dsw-alias-state-idle-primary,#9aa0a6);}
|
|
27
|
+
.fg-pulse.on{background:var(--dsw-alias-state-success-primary,#1a9b4e);
|
|
28
|
+
animation:fg-breathe 1.6s ease-in-out infinite;}
|
|
29
|
+
@keyframes fg-breathe{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.45;transform:scale(.82)}}
|
|
30
|
+
.fg-sum{font-weight:600;letter-spacing:.1px;white-space:nowrap;}
|
|
31
|
+
.fg-sum i{font-style:normal;font-weight:500;opacity:.55;}
|
|
32
|
+
.fg-caret{margin-left:auto;opacity:.45;font-size:11px;}
|
|
33
|
+
.fg-body{max-height:280px;overflow:auto;
|
|
34
|
+
border-top:1px solid var(--dsw-alias-border-l1,rgba(0,0,0,.07));}
|
|
35
|
+
.fg-row{display:grid;grid-template-columns:9px 1fr auto;gap:2px 7px;
|
|
36
|
+
padding:6px 10px;cursor:pointer;align-items:center;}
|
|
37
|
+
.fg-row:hover{background:var(--dsw-alias-bg-layer-2,rgba(0,0,0,.035));}
|
|
38
|
+
.fg-dot{width:7px;height:7px;border-radius:50%;
|
|
39
|
+
background:var(--dsw-alias-state-idle-primary,#c2c6cc);}
|
|
40
|
+
.fg-dot.run{background:var(--dsw-alias-state-success-primary,#1a9b4e);}
|
|
41
|
+
.fg-dot.wait{background:var(--dsw-alias-state-warn-primary,#e0a72e);}
|
|
42
|
+
.fg-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;}
|
|
43
|
+
.fg-name em{font-style:normal;font-weight:500;opacity:.5;font-size:11px;margin-left:5px;}
|
|
44
|
+
.fg-num{font-variant-numeric:tabular-nums;opacity:.6;white-space:nowrap;font-size:11px;}
|
|
45
|
+
.fg-file{grid-column:2 / 4;font-size:11px;opacity:.5;overflow:hidden;
|
|
46
|
+
text-overflow:ellipsis;white-space:nowrap;}
|
|
47
|
+
.fg-more{grid-column:1 / 4;padding:5px 10px;font-size:11px;opacity:.5;}
|
|
82
48
|
`;
|
|
83
49
|
|
|
84
|
-
function
|
|
85
|
-
if (typeof document === 'undefined') return;
|
|
86
|
-
if (document.getElementById('
|
|
50
|
+
function ensureStyle() {
|
|
51
|
+
if (typeof document === 'undefined' || !document.head) return;
|
|
52
|
+
if (document.getElementById('fg-style')) return;
|
|
87
53
|
const el = document.createElement('style');
|
|
88
|
-
el.id = '
|
|
54
|
+
el.id = 'fg-style';
|
|
89
55
|
el.textContent = CSS;
|
|
90
56
|
document.head.appendChild(el);
|
|
91
57
|
}
|
|
92
58
|
|
|
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
59
|
function num(n) {
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
if (
|
|
104
|
-
return
|
|
60
|
+
if (!n) return '0';
|
|
61
|
+
if (n < 1000) return String(n);
|
|
62
|
+
if (n < 1e6) return (n / 1000).toFixed(n < 1e4 ? 1 : 0) + 'k';
|
|
63
|
+
return (n / 1e6).toFixed(1) + 'M';
|
|
105
64
|
}
|
|
106
65
|
|
|
107
66
|
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(' ');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function IsoFloor({ seats, onOpen, scale, offset }) {
|
|
164
|
-
const { TW, TH, DESK, SP, COLS } = ISO;
|
|
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)));
|
|
67
|
+
if (!t) return '';
|
|
68
|
+
const s = Math.max(0, Math.round((Date.now() - t) / 1000));
|
|
69
|
+
if (s < 60) return s + '秒前';
|
|
70
|
+
if (s < 3600) return Math.round(s / 60) + '分钟前';
|
|
71
|
+
return Math.round(s / 3600) + '小时前';
|
|
355
72
|
}
|
|
356
73
|
|
|
357
|
-
function useFloor(
|
|
358
|
-
const [
|
|
74
|
+
function useFloor(open, initial) {
|
|
75
|
+
const [data, setData] = useState(() => initial || null);
|
|
359
76
|
useEffect(() => {
|
|
360
77
|
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);
|
|
78
|
+
let timer = null;
|
|
79
|
+
const tick = () => {
|
|
80
|
+
Promise.resolve()
|
|
81
|
+
.then(() => fetch(ROUTE, { headers: { accept: 'application/json' } }))
|
|
82
|
+
.then((r) => (r && r.ok ? r.json() : null))
|
|
83
|
+
.then((d) => { if (alive && d) setData(d); })
|
|
84
|
+
.catch(() => {})
|
|
85
|
+
.then(() => { if (alive) timer = setTimeout(tick, open ? 2000 : 6000); });
|
|
372
86
|
};
|
|
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 */ }
|
|
87
|
+
tick();
|
|
88
|
+
return () => { alive = false; if (timer) clearTimeout(timer); };
|
|
89
|
+
}, [open]);
|
|
90
|
+
return data;
|
|
388
91
|
}
|
|
389
92
|
|
|
390
93
|
function deriveAgents(data) {
|
|
@@ -395,373 +98,126 @@ window.__ModuleLoader__.load({
|
|
|
395
98
|
id: s.id,
|
|
396
99
|
name: s.title || s.cwd || s.id,
|
|
397
100
|
parent: s.parent || null,
|
|
398
|
-
role: s.parent ? 'SUBAGENT' : 'LEAD',
|
|
399
101
|
status: s.running ? 'RUNNING' : (now - (s.updatedAt || 0) < 300000 ? 'STANDBY' : 'IDLE'),
|
|
400
102
|
step: s.step || 0,
|
|
401
103
|
turn: s.turn || 0,
|
|
402
104
|
tools: s.toolCalls || 0,
|
|
403
105
|
tokens: (s.tokensIn || 0) + (s.tokensOut || 0),
|
|
404
|
-
lastEvent: s.lastLabel || '',
|
|
405
106
|
tool: s.lastTool || null,
|
|
107
|
+
forked: !!(data.focus && s.id === data.focus),
|
|
406
108
|
files: (Array.isArray(s.diffFiles) && s.diffFiles.length)
|
|
407
109
|
? s.diffFiles.slice(0, 4).map((f) => ({ name: String(f).split('/').pop(), write: true }))
|
|
408
110
|
: (Array.isArray(s.files) ? s.files : []),
|
|
409
|
-
updatedAt: s.updatedAt,
|
|
410
|
-
|
|
411
|
-
})) : (Array.isArray(data.agents) ? data.agents : []);
|
|
111
|
+
updatedAt: s.updatedAt || 0,
|
|
112
|
+
})) : [];
|
|
412
113
|
|
|
413
114
|
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
|
-
}
|
|
115
|
+
for (const a of list) seen.set((a.name || '').trim(), (seen.get((a.name || '').trim()) || 0) + 1);
|
|
418
116
|
for (const a of list) {
|
|
419
117
|
if (seen.get((a.name || '').trim()) > 1) {
|
|
420
|
-
a.name = a.name + ' · ' + String(a.id ||
|
|
118
|
+
a.name = a.name + ' · ' + String(a.id || '').slice(-4);
|
|
421
119
|
}
|
|
422
120
|
}
|
|
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
121
|
|
|
427
|
-
const
|
|
122
|
+
const live = list.filter((a) => {
|
|
428
123
|
if (!a.parent) return true;
|
|
429
|
-
|
|
124
|
+
if (a.status === 'RUNNING') return true;
|
|
125
|
+
return now - (a.updatedAt || 0) < CHILD_TTL;
|
|
430
126
|
});
|
|
431
127
|
|
|
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 = [];
|
|
128
|
+
const rank = (a) => (a.status === 'RUNNING' ? 0 : a.status === 'STANDBY' ? 1 : 2);
|
|
129
|
+
const byId = new Map(live.map((a) => [a.id, a]));
|
|
130
|
+
const leaders = live.filter((a) => !a.parent || !byId.has(a.parent));
|
|
131
|
+
leaders.sort((x, y) => rank(x) - rank(y) || (y.updatedAt || 0) - (x.updatedAt || 0));
|
|
132
|
+
|
|
133
|
+
const out = [];
|
|
446
134
|
for (const lead of leaders) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
135
|
+
const kids = live.filter((a) => a.parent === lead.id);
|
|
136
|
+
kids.sort((x, y) => rank(x) - rank(y) || (y.updatedAt || 0) - (x.updatedAt || 0));
|
|
137
|
+
out.push({ ...lead, depth: 0, kids: kids.length });
|
|
138
|
+
for (const k of kids) out.push({ ...k, depth: 1, kids: 0 });
|
|
450
139
|
}
|
|
451
|
-
|
|
452
|
-
if (byId.has(pid)) continue;
|
|
453
|
-
for (const kid of kids) ordered.push({ agent: kid, depth: 1 });
|
|
454
|
-
}
|
|
455
|
-
return ordered;
|
|
140
|
+
return out;
|
|
456
141
|
}
|
|
457
142
|
|
|
458
|
-
function
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
]),
|
|
143
|
+
function fileLine(a) {
|
|
144
|
+
const files = (a.files || []).slice(0, 3).map((f) => (f.write ? '改 ' : '') + f.name);
|
|
145
|
+
if (files.length) return files.join(' · ');
|
|
146
|
+
if (a.tool && a.tool.name) {
|
|
147
|
+
const target = String(a.tool.target || '').split('/').pop();
|
|
148
|
+
return a.tool.name + (target ? ' · ' + target : '');
|
|
149
|
+
}
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function MonitorRow(props) {
|
|
154
|
+
const a = props.agent;
|
|
155
|
+
const cls = 'fg-dot ' + (a.status === 'RUNNING' ? 'run' : a.status === 'STANDBY' ? 'wait' : '');
|
|
156
|
+
const shot = fileLine(a);
|
|
157
|
+
return h('div', { className: 'fg-row', onClick: () => props.onOpen(a) }, [
|
|
158
|
+
h('span', { className: cls, key: 'dot' }),
|
|
159
|
+
h('span', { className: 'fg-name', key: 'name' }, [
|
|
160
|
+
a.depth ? '↳ ' : '',
|
|
161
|
+
a.name || '未命名',
|
|
162
|
+
a.depth ? null : (a.kids ? h('em', { key: 'k' }, '带队 ' + a.kids) : null),
|
|
492
163
|
]),
|
|
164
|
+
h('span', { className: 'fg-num', key: 'num' },
|
|
165
|
+
'第' + a.step + '步·第' + a.turn + '轮 · ' + num(a.tokens) + ' tok'),
|
|
166
|
+
shot ? h('span', { className: 'fg-file', key: 'file' }, shot) : null,
|
|
493
167
|
]);
|
|
494
168
|
}
|
|
495
169
|
|
|
496
|
-
function
|
|
170
|
+
function MonitorBar(props) {
|
|
171
|
+
const ctx = (props && props.ctx) || null;
|
|
497
172
|
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; }
|
|
173
|
+
try { return localStorage.getItem(OPEN_KEY) === '1'; } catch { return false; }
|
|
503
174
|
});
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
const raw = localStorage.getItem(POS_KEY);
|
|
507
|
-
return raw ? JSON.parse(raw) : null;
|
|
508
|
-
} catch (e) { return null; }
|
|
509
|
-
});
|
|
510
|
-
const [dragging, setDragging] = useState(false);
|
|
511
|
-
const panelRef = useRef(null);
|
|
512
|
-
const dragRef = useRef(null);
|
|
513
|
-
|
|
514
|
-
// 工位视图:缩放 / 平移 / 复位
|
|
515
|
-
const [viewScale, setViewScale] = useState(1);
|
|
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);
|
|
175
|
+
const data = useFloor(open, props && props.initialData);
|
|
176
|
+
const agents = deriveAgents(data);
|
|
524
177
|
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
|
-
};
|
|
563
|
-
|
|
564
|
-
// 视图尺度:像素 delta 换算成 viewBox 单位(preserveAspectRatio=xMidYMin meet)
|
|
565
|
-
const stageMetrics = () => {
|
|
566
|
-
const stage = stageRef.current;
|
|
567
|
-
const svg = stage && stage.querySelector ? stage.querySelector('svg') : null;
|
|
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 };
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
const clampScale = (v) => Math.min(2.2, Math.max(0.6, v));
|
|
178
|
+
const shown = agents.slice(0, MAX_ROWS);
|
|
179
|
+
const hidden = agents.length - shown.length;
|
|
579
180
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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]);
|
|
593
|
-
|
|
594
|
-
// 拖拽平移:按下后在 window 上跟随,松手/取消结束
|
|
595
|
-
useEffect(() => {
|
|
596
|
-
if (!viewDrag) return undefined;
|
|
597
|
-
const onMove = (e) => {
|
|
598
|
-
const p = panRef.current;
|
|
599
|
-
if (!p) return;
|
|
600
|
-
const dx = e.clientX - p.x;
|
|
601
|
-
const dy = e.clientY - p.y;
|
|
602
|
-
if (!p.moved && (Math.abs(dx) > 4 || Math.abs(dy) > 4)) p.moved = true;
|
|
603
|
-
if (!p.moved) return;
|
|
604
|
-
const m = stageMetrics();
|
|
605
|
-
const k = m ? m.k : 1;
|
|
606
|
-
const limX = m ? m.w * 0.9 : 3000;
|
|
607
|
-
const limY = m ? m.h * 0.9 : 3000;
|
|
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)),
|
|
611
|
-
});
|
|
612
|
-
};
|
|
613
|
-
const onUp = () => {
|
|
614
|
-
const p = panRef.current;
|
|
615
|
-
if (p && p.moved) suppressRef.current = true;
|
|
616
|
-
panRef.current = null;
|
|
617
|
-
setViewDrag(false);
|
|
618
|
-
};
|
|
619
|
-
window.addEventListener('pointermove', onMove);
|
|
620
|
-
window.addEventListener('pointerup', onUp);
|
|
621
|
-
window.addEventListener('pointercancel', onUp);
|
|
622
|
-
return () => {
|
|
623
|
-
window.removeEventListener('pointermove', onMove);
|
|
624
|
-
window.removeEventListener('pointerup', onUp);
|
|
625
|
-
window.removeEventListener('pointercancel', onUp);
|
|
626
|
-
};
|
|
627
|
-
}, [viewDrag]);
|
|
628
|
-
|
|
629
|
-
const onStageDown = (e) => {
|
|
630
|
-
if (e && e.button !== 0) return;
|
|
631
|
-
suppressRef.current = false;
|
|
632
|
-
panRef.current = { x: e.clientX, y: e.clientY, ox: viewOffset.x, oy: viewOffset.y, moved: false };
|
|
633
|
-
setViewDrag(true);
|
|
181
|
+
const toggle = () => {
|
|
182
|
+
const next = !open;
|
|
183
|
+
setOpen(next);
|
|
184
|
+
try { localStorage.setItem(OPEN_KEY, next ? '1' : '0'); } catch {}
|
|
634
185
|
};
|
|
635
186
|
|
|
636
|
-
|
|
637
|
-
const t = e ? e.target : null;
|
|
638
|
-
if (t && typeof t.closest === 'function' && t.closest('[data-tag="1"]')) return;
|
|
639
|
-
setViewScale(1);
|
|
640
|
-
setViewOffset({ x: 0, y: 0 });
|
|
641
|
-
};
|
|
187
|
+
useEffect(() => { ensureStyle(); }, []);
|
|
642
188
|
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
if (
|
|
189
|
+
const openSession = (a) => {
|
|
190
|
+
const id = a && a.id;
|
|
191
|
+
if (!id) return;
|
|
192
|
+
try {
|
|
193
|
+
const ui = ctx && typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : null;
|
|
194
|
+
if (ui && typeof ui.openSession === 'function') { ui.openSession(id); return; }
|
|
195
|
+
const ses = ctx && typeof ctx.get === 'function' ? ctx.get('sessions') : null;
|
|
196
|
+
if (ses && typeof ses.scope === 'function') ses.scope(id);
|
|
197
|
+
} catch {}
|
|
646
198
|
};
|
|
647
199
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
const bucket = kidsOf.get(pid) || [];
|
|
655
|
-
bucket.push(o.agent);
|
|
656
|
-
kidsOf.set(pid, bucket);
|
|
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: '关闭' }, '✕'),
|
|
200
|
+
return h('div', { className: 'fg-root' }, h('div', { className: 'fg-dock' }, [
|
|
201
|
+
h('div', { className: 'fg-head', key: 'head', onClick: toggle, title: open ? '收起监控条' : '展开监控条' }, [
|
|
202
|
+
h('span', { className: 'fg-pulse' + (running ? ' on' : ''), key: 'p' }),
|
|
203
|
+
h('span', { className: 'fg-sum', key: 's' }, [
|
|
204
|
+
running ? running + ' 在跑' : '全部空闲',
|
|
205
|
+
h('i', { key: 'i' }, ' / ' + agents.length + ' 在岗'),
|
|
691
206
|
]),
|
|
692
|
-
h('
|
|
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;
|
|
718
|
-
|
|
719
|
-
return h('div', {
|
|
720
|
-
className: 'fg-root fg-panel' + (dragging ? ' fg-dragging' : ''),
|
|
721
|
-
ref: panelRef,
|
|
722
|
-
style,
|
|
723
|
-
}, [
|
|
724
|
-
h('div', {
|
|
725
|
-
className: 'fg-head',
|
|
726
|
-
key: 'head',
|
|
727
|
-
onPointerDown: onDragStart,
|
|
728
|
-
onPointerMove: onDragMove,
|
|
729
|
-
onPointerUp: onDragEnd,
|
|
730
|
-
onPointerCancel: onDragEnd,
|
|
731
|
-
title: '拖动标题栏可移动',
|
|
732
|
-
}, [
|
|
733
|
-
h('span', { className: 'fg-dot' + (running ? ' fg-dot-live' : ''), key: 'd' }),
|
|
734
|
-
h('span', { className: 'fg-title', key: 't' }, 'Agent Floor'),
|
|
735
|
-
h('span', { className: 'fg-count', key: 'c' }, running + ' 在干活 / ' + agents.length + ' 在岗'),
|
|
736
|
-
h('button', {
|
|
737
|
-
className: 'fg-icon',
|
|
738
|
-
key: 'a',
|
|
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: '收起' }, '⌄'),
|
|
207
|
+
h('span', { className: 'fg-caret', key: 'c' }, open ? '⌄' : '⌃'),
|
|
745
208
|
]),
|
|
746
|
-
h('div', { className: 'fg-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}))
|
|
753
|
-
: h('div', { className: 'fg-empty' }, onlyActive ? '现在没人干活' : '还没有工程师上岗')),
|
|
754
|
-
]);
|
|
209
|
+
open ? h('div', { className: 'fg-body', key: 'body' }, [
|
|
210
|
+
...shown.map((a) => h(MonitorRow, { key: a.id || a.name, agent: a, onOpen: openSession })),
|
|
211
|
+
hidden > 0 ? h('div', { className: 'fg-more', key: 'more' }, '还有 ' + hidden + ' 个会话') : null,
|
|
212
|
+
agents.length === 0 ? h('div', { className: 'fg-more', key: 'empty' }, '暂无会话') : null,
|
|
213
|
+
]) : null,
|
|
214
|
+
]));
|
|
755
215
|
}
|
|
756
216
|
|
|
757
|
-
const inject = ['slots'];
|
|
758
|
-
|
|
759
217
|
function apply(ctx) {
|
|
760
|
-
|
|
761
|
-
installStyle();
|
|
762
|
-
const mount = (ready) => {
|
|
218
|
+
const bridge = (ready) => {
|
|
763
219
|
const target = ready && ready.slots ? ready : ctx;
|
|
764
|
-
const slots = target.slots;
|
|
220
|
+
const slots = target && target.slots;
|
|
765
221
|
if (!slots) return;
|
|
766
222
|
const render = () => {
|
|
767
223
|
slots.inject('shell.overlay', () => slots.register({
|
|
@@ -769,18 +225,18 @@ window.__ModuleLoader__.load({
|
|
|
769
225
|
id: 'dsh-agent-floor',
|
|
770
226
|
order: 940,
|
|
771
227
|
label: 'Agent Floor',
|
|
772
|
-
}, (
|
|
228
|
+
}, () => h(MonitorBar, { ctx })));
|
|
773
229
|
};
|
|
774
230
|
if (typeof target.effect === 'function') target.effect(render, 'dsh-agent-floor: mounts');
|
|
775
231
|
else render();
|
|
776
232
|
};
|
|
777
233
|
if (typeof ctx.inject === 'function') {
|
|
778
|
-
ctx.inject(['slots'],
|
|
234
|
+
ctx.inject(['slots'], bridge);
|
|
779
235
|
return;
|
|
780
236
|
}
|
|
781
|
-
if (ctx.slots)
|
|
237
|
+
if (ctx.slots) bridge(ctx);
|
|
782
238
|
}
|
|
783
239
|
|
|
784
|
-
return { inject, apply };
|
|
240
|
+
return { inject, apply, __dshTest: { deriveAgents, MonitorBar, MonitorRow } };
|
|
785
241
|
},
|
|
786
242
|
});
|