hivedesk 1.0.0 → 1.0.1
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/CHANGELOG.md +122 -111
- package/desktop/controller.js +85 -7
- package/desktop/native.js +4 -1
- package/desktop/release-notes/1.0.1.json +12 -0
- package/desktop/scripts/package.mjs +134 -123
- package/desktop/shell.html +5 -2
- package/desktop/workarea.js +440 -0
- package/i18n/de.json +247 -4
- package/i18n/en.json +247 -4
- package/i18n/es.json +247 -4
- package/i18n/fr.json +247 -4
- package/i18n/it.json +247 -4
- package/i18n/ja.json +247 -4
- package/i18n/ko.json +247 -4
- package/i18n/parts/downloads.de.json +29 -0
- package/i18n/parts/downloads.en.json +29 -0
- package/i18n/parts/downloads.es.json +29 -0
- package/i18n/parts/downloads.fr.json +29 -0
- package/i18n/parts/downloads.it.json +29 -0
- package/i18n/parts/downloads.ja.json +29 -0
- package/i18n/parts/downloads.ko.json +29 -0
- package/i18n/parts/downloads.pt-BR.json +29 -0
- package/i18n/parts/downloads.ru.json +29 -0
- package/i18n/parts/downloads.zh-CN.json +29 -0
- package/i18n/parts/office.de.json +184 -0
- package/i18n/parts/office.en.json +184 -0
- package/i18n/parts/office.es.json +184 -0
- package/i18n/parts/office.fr.json +184 -0
- package/i18n/parts/office.it.json +184 -0
- package/i18n/parts/office.ja.json +184 -0
- package/i18n/parts/office.ko.json +184 -0
- package/i18n/parts/office.pt-BR.json +184 -0
- package/i18n/parts/office.ru.json +184 -0
- package/i18n/parts/office.zh-CN.json +184 -0
- package/i18n/pt-BR.json +247 -4
- package/i18n/ru.json +247 -4
- package/i18n/zh-CN.json +247 -4
- package/package.json +3 -2
- package/src/brain/manager.js +23 -7
- package/src/brain/models.js +146 -30
- package/src/brain/runtime.js +61 -13
- package/src/crew/domains/flow.js +2 -1
- package/src/crew/engine.js +172 -22
- package/src/crew/legacy.js +72 -0
- package/src/crew/planner.js +14 -1
- package/src/crew/talk.js +110 -3
- package/src/crew/taskgraph.js +12 -2
- package/src/crew/worker.js +60 -2
- package/src/index.js +4 -1
- package/src/phone/hub.js +15 -3
- package/src/phone/port.js +1 -1
- package/src/replay/reduce.js +1 -0
- package/src/tools/check.js +2 -0
- package/src/voice/index.js +1 -1
- package/src/voice/piper.js +10 -4
- package/src/voice/store.js +2 -1
- package/src/voice/whisper.js +63 -25
- package/ui/city/activity.js +4 -1
- package/ui/city/city.js +5 -5
- package/ui/city/scene.js +2 -1
- package/ui/css/hive.css +20 -0
- package/ui/js/dock.js +2 -2
- package/ui/js/dom.js +23 -18
- package/ui/js/i18n.js +12 -0
- package/ui/js/main.js +43 -3
- package/ui/js/md.js +130 -0
- package/ui/js/net.js +6 -0
- package/ui/js/palette.js +2 -2
- package/ui/js/store.js +20 -2
- package/ui/js/topbar.js +2 -2
- package/ui/js/voice/index.js +3 -2
- package/ui/js/widgets/brief.js +28 -10
- package/ui/js/widgets/chat.js +16 -4
- package/ui/js/widgets/files.js +3 -3
- package/ui/js/widgets/memory.js +3 -3
- package/ui/js/widgets/replay.js +3 -3
- package/ui/js/widgets/settings.js +2 -2
- package/ui/js/widgets/timeline.js +2 -2
- package/ui/js/widgets/worker.js +17 -6
- package/ui/models/index.js +3 -2
- package/ui/models/window.js +2 -2
- package/ui/office/office.js +662 -623
- package/ui/office/popout.js +4 -3
- package/ui/office/scene.js +47 -28
- package/ui/phone/core/client.js +11 -5
- package/ui/phone/desktop.js +2 -1
- package/ui/widget.html +8 -8
- package/ui/widget.js +35 -20
- package/ui/workbench/searchview.js +3 -3
package/ui/office/office.js
CHANGED
|
@@ -1,623 +1,662 @@
|
|
|
1
|
-
// Office mode: the crew at work on a refined isometric floor (docs/1.0/DESIGN.md, section 6).
|
|
2
|
-
// A full scene that replaces the window desktop (toggle in the top bar), driven by the
|
|
3
|
-
// same engine events as every widget. Click a bee to chat, right click for its menu,
|
|
4
|
-
// drag a sticky note from Mel's board onto a bee to hand the task over.
|
|
5
|
-
|
|
6
|
-
import { h, icon, clear, reducedMotion } from '/js/dom.js';
|
|
7
|
-
import { S, rev, ui, worker, onEvent, currentJob, jobTasks } from '/js/store.js';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import * as
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
let
|
|
31
|
-
let
|
|
32
|
-
let
|
|
33
|
-
let
|
|
34
|
-
let
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
let
|
|
38
|
-
let
|
|
39
|
-
let
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
layer
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
hud.
|
|
226
|
-
hud.
|
|
227
|
-
hud.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
hud.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
hud.
|
|
244
|
-
hud.
|
|
245
|
-
hud.
|
|
246
|
-
hud.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
if (
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
|
|
1
|
+
// Office mode: the crew at work on a refined isometric floor (docs/1.0/DESIGN.md, section 6).
|
|
2
|
+
// A full scene that replaces the window desktop (toggle in the top bar), driven by the
|
|
3
|
+
// same engine events as every widget. Click a bee to chat, right click for its menu,
|
|
4
|
+
// drag a sticky note from Mel's board onto a bee to hand the task over.
|
|
5
|
+
|
|
6
|
+
import { h, icon, clear, reducedMotion, append } from '/js/dom.js';
|
|
7
|
+
import { S, rev, ui, worker, onEvent, currentJob, jobTasks, roleName } from '/js/store.js';
|
|
8
|
+
import { t, onLocale } from '/js/i18n.js';
|
|
9
|
+
import { mdLine } from '/js/md.js';
|
|
10
|
+
import { setTip } from '/js/tooltip.js';
|
|
11
|
+
import * as net from '/js/net.js';
|
|
12
|
+
import * as wm from '/js/wm.js';
|
|
13
|
+
import * as menu from '/js/menu.js';
|
|
14
|
+
import * as act from '/js/actions.js';
|
|
15
|
+
import { beeAvatar } from '/js/bees.js';
|
|
16
|
+
import { track, STATUS_LABEL, TASK_LABEL } from '/js/widgets/util.js';
|
|
17
|
+
import { OfficeScene, levelOf, doneCount, dayPhase } from './scene.js';
|
|
18
|
+
import * as audio from './audio.js';
|
|
19
|
+
import { openWidget, openPip, pipSupported } from './popout.js';
|
|
20
|
+
|
|
21
|
+
const VIEW_KEY = 'hivedesk.view.v2'; // v2: City became the default home in 0.2.0
|
|
22
|
+
// What a bee is doing in the scene, read in the current language when shown (office.mode.*).
|
|
23
|
+
export const MODES = ['idle', 'sleep', 'type', 'plan', 'wait', 'stuck', 'test', 'read', 'error', 'celebrate', 'paused', 'fly'];
|
|
24
|
+
const modeLabel = (m) => (MODES.includes(m) ? t(`office.mode.${m}`) : '');
|
|
25
|
+
export const JOB_STATES = ['refining', 'awaiting_brief', 'planning', 'running', 'done', 'failed', 'cancelled'];
|
|
26
|
+
const roleOf = (w) => roleName(w) || t('office.worker');
|
|
27
|
+
const statusOf = (w, m, st) => (w.paused ? t('office.mode.paused') : modeLabel(m) || STATUS_LABEL[st.status] || st.status);
|
|
28
|
+
|
|
29
|
+
let layer;
|
|
30
|
+
let scene;
|
|
31
|
+
let canvas;
|
|
32
|
+
let hud = {};
|
|
33
|
+
let hitLayer;
|
|
34
|
+
let tip;
|
|
35
|
+
let bees = new Map();
|
|
36
|
+
let notes = new Map();
|
|
37
|
+
let mode = 'desktop';
|
|
38
|
+
let hiddenWins = [];
|
|
39
|
+
let deskEl;
|
|
40
|
+
let seg;
|
|
41
|
+
let hourOverride = null;
|
|
42
|
+
let shownHoney = null;
|
|
43
|
+
let honeyTimer = null;
|
|
44
|
+
let drag = null;
|
|
45
|
+
|
|
46
|
+
function linkCss() {
|
|
47
|
+
if (document.querySelector('link[data-office]')) return;
|
|
48
|
+
document.head.append(h('link', { rel: 'stylesheet', href: '/office/office.css', 'data-office': '' }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function readHourOverride() {
|
|
52
|
+
const q = new URLSearchParams(location.search).get('hour');
|
|
53
|
+
if (q != null && q !== '' && !Number.isNaN(Number(q))) hourOverride = Math.max(0, Math.min(23.99, Number(q)));
|
|
54
|
+
}
|
|
55
|
+
const hourNow = () => {
|
|
56
|
+
if (hourOverride != null) return hourOverride;
|
|
57
|
+
const d = new Date();
|
|
58
|
+
return d.getHours() + d.getMinutes() / 60;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Mounts the Office. Hooks: a segmented toggle in the top bar and a dock entry for the
|
|
63
|
+
* mini widget.
|
|
64
|
+
* @param {{ desk: HTMLElement, barRight: HTMLElement|null, addDockItem?: Function }} opts
|
|
65
|
+
*/
|
|
66
|
+
export function initOffice({ desk, barRight, addDockItem }) {
|
|
67
|
+
linkCss();
|
|
68
|
+
readHourOverride();
|
|
69
|
+
deskEl = desk;
|
|
70
|
+
layer = h('section', { class: 'of-layer', hidden: true, ta: 'office.view.aria' });
|
|
71
|
+
canvas = h('canvas', { class: 'of-canvas', 'aria-hidden': 'true' });
|
|
72
|
+
hitLayer = h('div', { class: 'of-hits' });
|
|
73
|
+
tip = h('div', { class: 'of-tip', role: 'tooltip', id: 'of-tip' });
|
|
74
|
+
layer.append(canvas, hitLayer, buildHud(), tip);
|
|
75
|
+
desk.append(layer);
|
|
76
|
+
|
|
77
|
+
scene = new OfficeScene(canvas, {
|
|
78
|
+
getState: S,
|
|
79
|
+
reduced: reducedMotion,
|
|
80
|
+
hour: hourNow,
|
|
81
|
+
onSound: (n) => audio.fx(n),
|
|
82
|
+
honeyTarget: () => {
|
|
83
|
+
const r = hud.honey?.getBoundingClientRect();
|
|
84
|
+
const lr = layer.getBoundingClientRect();
|
|
85
|
+
return r ? { x: r.left - lr.left + 18, y: r.top - lr.top + r.height / 2 } : null;
|
|
86
|
+
},
|
|
87
|
+
onHoney: () => bumpHoney(),
|
|
88
|
+
onFrame: (sc) => { syncHits(sc); audio.setLevels(sc.typingCount || 0, sc.flyingCount || 0); },
|
|
89
|
+
});
|
|
90
|
+
new ResizeObserver(() => { if (mode === 'office') scene.resize(layer.clientWidth, layer.clientHeight); }).observe(layer);
|
|
91
|
+
|
|
92
|
+
// the toggle in the top bar
|
|
93
|
+
const segOffice = h('button', { type: 'button', dataset: { v: 'office' }, on: { click: () => setMode('office') } }, officeGlyph(), h('span', { tx: 'office.seg.office' }));
|
|
94
|
+
const segDesk = h('button', { type: 'button', dataset: { v: 'desktop' }, on: { click: () => setMode('desktop') } }, icon('hive', 'ico-sm'), h('span', { tx: 'office.seg.desktop' }));
|
|
95
|
+
seg = h('div', { class: 'of-seg', role: 'group', ta: 'office.seg.aria' }, segOffice, segDesk);
|
|
96
|
+
barRight?.prepend(seg);
|
|
97
|
+
|
|
98
|
+
const dockBtn = addDockItem?.({
|
|
99
|
+
id: 'widget', label: t('office.dock.label'), sub: () => t('office.dock.sub'),
|
|
100
|
+
content: h('span', { class: 'dk-hex' }, miniGlyph()),
|
|
101
|
+
onClick: () => openWidget(),
|
|
102
|
+
menu: () => [
|
|
103
|
+
{ header: t('office.dock.label') },
|
|
104
|
+
{ label: t('office.dock.popOut'), icon: 'preview', action: () => openWidget() },
|
|
105
|
+
{ label: t('office.dock.pip'), icon: 'preview', disabled: !pipSupported(), action: () => openPip() },
|
|
106
|
+
{ sep: true },
|
|
107
|
+
{ label: mode === 'office' ? t('office.dock.toDesktop') : t('office.dock.toOffice'), icon: 'hive', action: () => setMode(mode === 'office' ? 'desktop' : 'office') },
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
// the dock keeps the label it got: keep it in the current language
|
|
111
|
+
const dockTip = () => { if (!dockBtn?.setAttribute) return; dockBtn.setAttribute('aria-label', t('office.dock.label')); setTip(dockBtn, { title: t('office.dock.label'), help: t('office.dock.sub') }); };
|
|
112
|
+
dockBtn?.addEventListener?.('pointerenter', dockTip);
|
|
113
|
+
dockBtn?.addEventListener?.('focus', dockTip);
|
|
114
|
+
const paintStatic = () => {
|
|
115
|
+
segOffice.title = t('office.seg.officeTitle');
|
|
116
|
+
segDesk.title = t('office.seg.desktopTitle');
|
|
117
|
+
dockTip();
|
|
118
|
+
};
|
|
119
|
+
paintStatic();
|
|
120
|
+
onLocale(() => { paintStatic(); paintSound(); if (hud.segs) hud.segs._key = null; paintHud(); });
|
|
121
|
+
|
|
122
|
+
// engine wiring
|
|
123
|
+
net.on('hello', () => { scene.reset(); shownHoney = null; paintHud(); });
|
|
124
|
+
onEvent((ev) => {
|
|
125
|
+
scene.handle(ev);
|
|
126
|
+
feed(ev);
|
|
127
|
+
if (ev.type === 'job.done' && mode === 'office') banner(ev);
|
|
128
|
+
if (/^(brief|job)\./.test(ev.type)) paintHud();
|
|
129
|
+
});
|
|
130
|
+
track(() => [rev.jobs, rev.tasks, rev.queue, rev.crew, rev.workers, rev.chat, rev.approvals, ui.replay, ui.demo], () => paintHud());
|
|
131
|
+
track(() => [rev.crew], () => scene.syncCrew(true));
|
|
132
|
+
|
|
133
|
+
document.addEventListener('visibilitychange', () => {
|
|
134
|
+
if (mode !== 'office') return;
|
|
135
|
+
if (document.hidden) scene.stop(); else scene.start();
|
|
136
|
+
});
|
|
137
|
+
document.addEventListener('keydown', (e) => {
|
|
138
|
+
if (e.key === 'Escape' && drag) cancelDrag();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// City is the default home when it is registered (ui/city/); Office and Desktop stay one click away.
|
|
142
|
+
let start = 'city';
|
|
143
|
+
try { start = localStorage.getItem(VIEW_KEY) || 'city'; } catch { /* ignore */ }
|
|
144
|
+
const q = new URLSearchParams(location.search).get('view');
|
|
145
|
+
if (q) start = q;
|
|
146
|
+
// wait for the first layout of the windows before hiding them
|
|
147
|
+
net.on('hello', once(() => requestAnimationFrame(() => {
|
|
148
|
+
if (start === 'office' || views.has(start)) setMode(start, { quiet: true });
|
|
149
|
+
})));
|
|
150
|
+
paintSeg();
|
|
151
|
+
setInterval(() => { if (mode === 'office') paintClock(); }, 20000);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function once(fn) { let done = false; return (...a) => { if (!done) { done = true; fn(...a); } }; }
|
|
155
|
+
|
|
156
|
+
export function getMode() { return mode; }
|
|
157
|
+
|
|
158
|
+
/* Other full screen views next to Office and Desktop (the City registers here). */
|
|
159
|
+
const views = new Map();
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adds a view to the toggle. `enter({ quiet })` shows it; `leave({ quiet, done })` hides it and
|
|
163
|
+
* calls done when it is gone. `first` puts it at the start of the toggle.
|
|
164
|
+
* @param {{ id: string, labelKey: string, titleKey?: string, glyph: () => Node, enter: Function, leave: Function, first?: boolean }} v
|
|
165
|
+
*/
|
|
166
|
+
export function addView(v) {
|
|
167
|
+
views.set(v.id, v);
|
|
168
|
+
const b = h('button', { type: 'button', dataset: { v: v.id }, tip: v.titleKey, on: { click: () => setMode(v.id) } }, v.glyph(), h('span', { tx: v.labelKey }));
|
|
169
|
+
if (v.first) seg.prepend(b); else seg.append(b);
|
|
170
|
+
seg.dataset.tour = 'office';
|
|
171
|
+
paintSeg();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const isScene = (m) => m === 'office' || views.has(m);
|
|
175
|
+
|
|
176
|
+
export function setMode(next, { quiet = false } = {}) {
|
|
177
|
+
if (next === mode || !(next === 'desktop' || isScene(next))) return;
|
|
178
|
+
const prev = mode;
|
|
179
|
+
mode = next;
|
|
180
|
+
try { localStorage.setItem(VIEW_KEY, mode); } catch { /* ignore */ }
|
|
181
|
+
paintSeg();
|
|
182
|
+
if (isScene(next) && !isScene(prev)) {
|
|
183
|
+
// tuck the open windows into the dock, and bring them back on the desktop
|
|
184
|
+
hiddenWins = wm.list().filter((w) => !w.min).map((w) => w.id);
|
|
185
|
+
for (const id of hiddenWins) wm.minimize(id);
|
|
186
|
+
deskEl.classList.add('of-on');
|
|
187
|
+
}
|
|
188
|
+
const toDesk = () => {
|
|
189
|
+
if (mode !== 'desktop') return;
|
|
190
|
+
deskEl.classList.remove('of-on');
|
|
191
|
+
for (const id of hiddenWins) if (wm.get(id)?.min) wm.restore(id);
|
|
192
|
+
hiddenWins = [];
|
|
193
|
+
};
|
|
194
|
+
if (views.has(prev)) views.get(prev).leave({ quiet: quiet || isScene(next), done: toDesk });
|
|
195
|
+
if (views.has(next)) { if (prev === 'office') leaveOffice(true, () => {}); views.get(next).enter({ quiet }); return; }
|
|
196
|
+
if (mode === 'office') {
|
|
197
|
+
layer.hidden = false;
|
|
198
|
+
scene.resize(layer.clientWidth, layer.clientHeight);
|
|
199
|
+
scene.reset();
|
|
200
|
+
scene.start();
|
|
201
|
+
audio.setActive(true);
|
|
202
|
+
paintHud();
|
|
203
|
+
if (!quiet && !reducedMotion()) layer.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 200, easing: 'cubic-bezier(.2,0,0,1)' });
|
|
204
|
+
} else if (prev === 'office') leaveOffice(quiet, toDesk);
|
|
205
|
+
else toDesk();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function leaveOffice(quiet, after) {
|
|
209
|
+
scene.stop();
|
|
210
|
+
audio.setActive(false);
|
|
211
|
+
hideTip();
|
|
212
|
+
const done = () => { layer.hidden = true; after(); };
|
|
213
|
+
if (reducedMotion() || quiet) done();
|
|
214
|
+
else layer.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, easing: 'cubic-bezier(.4,0,1,1)' }).onfinish = done;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function paintSeg() {
|
|
218
|
+
if (!seg) return;
|
|
219
|
+
for (const b of seg.querySelectorAll('button')) b.setAttribute('aria-pressed', String(b.dataset.v === mode));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* ---------- HUD ---------- */
|
|
223
|
+
function buildHud() {
|
|
224
|
+
const xpFill = h('i');
|
|
225
|
+
hud.req = h('div', { class: 'of-req' });
|
|
226
|
+
hud.xpText = h('span', { class: 'of-xp-t' });
|
|
227
|
+
hud.xpLv = h('span', { class: 'of-xp-lv' });
|
|
228
|
+
// progress is a segmented timeline: one segment per task, colored by its state
|
|
229
|
+
hud.segs = h('span', { class: 'of-tl', 'aria-hidden': 'true' });
|
|
230
|
+
hud.xp = h('div', { class: 'of-xp', role: 'progressbar', ta: 'office.hud.progress', 'aria-valuemin': '0', 'aria-valuemax': '100' }, xpFill, hud.segs);
|
|
231
|
+
hud.xpFill = xpFill;
|
|
232
|
+
hud.state = h('span', { class: 'of-chip' });
|
|
233
|
+
// waiting for the user's OK on Mel's brief: one clear way to it
|
|
234
|
+
hud.openBrief = h('button', { type: 'button', class: 'btn btn-xs btn-primary of-brief-btn', style: 'justify-self:start', hidden: true, tx: 'office.hud.openBrief', on: { click: () => { setMode('desktop'); wm.open('brief'); } } });
|
|
235
|
+
const job = h('div', { class: 'of-card of-job' },
|
|
236
|
+
h('div', { class: 'of-row' }, h('span', { class: 'of-k', tx: 'office.hud.currentJob' }), hud.state),
|
|
237
|
+
hud.req,
|
|
238
|
+
h('div', { class: 'of-row', style: 'gap:10px' }, hud.xpLv, hud.xp),
|
|
239
|
+
hud.xpText,
|
|
240
|
+
hud.openBrief);
|
|
241
|
+
|
|
242
|
+
const doneMark = h('span', { class: 'of-jar', html: CHECK_SVG, 'aria-hidden': 'true' });
|
|
243
|
+
hud.honeyN = h('b', { text: '0' });
|
|
244
|
+
hud.honeyT = h('span', { class: 'of-faint' });
|
|
245
|
+
hud.honey = h('div', { class: 'of-pill of-honey' }, doneMark, hud.honeyN, hud.honeyT);
|
|
246
|
+
hud.clock = h('div', { class: 'of-pill of-clock' });
|
|
247
|
+
hud.sound = h('button', { type: 'button', class: 'of-ib', on: { click: () => { audio.setAmbient(!audio.ambientOn()); paintSound(); } } });
|
|
248
|
+
hud.pop = h('button', { type: 'button', class: 'of-ib', ta: 'office.hud.popOut', on: { click: () => openWidget() } }, miniGlyph());
|
|
249
|
+
hud.pip = h('button', { type: 'button', class: 'of-ib', ta: 'office.hud.pipAria', hidden: !pipSupported(), on: { click: () => openPip() } }, pipGlyph());
|
|
250
|
+
const stats = h('div', { class: 'of-stats' }, hud.honey, hud.clock, h('div', { class: 'of-pill of-tools' }, hud.sound, hud.pop, hud.pip));
|
|
251
|
+
|
|
252
|
+
hud.queue = h('div', { class: 'of-card of-queue' });
|
|
253
|
+
hud.feed = h('ol', { class: 'of-card of-feed', ta: 'office.hud.feed', 'aria-live': 'polite' });
|
|
254
|
+
hud.banner = h('div', { class: 'of-banner', role: 'status', hidden: true });
|
|
255
|
+
hud.empty = h('div', { class: 'of-empty', hidden: true });
|
|
256
|
+
paintSound();
|
|
257
|
+
return h('div', { class: 'of-hud' }, job, stats, hud.queue, hud.feed, hud.banner, hud.empty);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function paintSound() {
|
|
261
|
+
const on = audio.ambientOn();
|
|
262
|
+
hud.sound.setAttribute('aria-pressed', String(on));
|
|
263
|
+
hud.sound.setAttribute('aria-label', on ? t('office.hud.soundOn') : t('office.hud.soundOff'));
|
|
264
|
+
hud.sound.title = on ? t('office.hud.soundOnTitle') : t('office.hud.soundOff');
|
|
265
|
+
// the other fixed titles of the HUD, in the current language
|
|
266
|
+
hud.honey.title = t('office.hud.honeyTitle');
|
|
267
|
+
hud.pop.title = t('office.hud.popOut');
|
|
268
|
+
hud.pip.title = t('office.hud.pip');
|
|
269
|
+
hud.sound.innerHTML = on
|
|
270
|
+
? '<svg class="ico" viewBox="0 0 24 24"><path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M15.5 9a4.2 4.2 0 0 1 0 6M18 6.5a8 8 0 0 1 0 11"/></svg>'
|
|
271
|
+
: '<svg class="ico" viewBox="0 0 24 24"><path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M16 9.5l5 5M21 9.5l-5 5"/></svg>';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function paintHud() {
|
|
275
|
+
if (!hud.req) return;
|
|
276
|
+
const s = S();
|
|
277
|
+
let j = [...(s.jobs || [])].reverse().find((x) => ['refining', 'awaiting_brief', 'planning', 'running'].includes(x.status)) || currentJob(s);
|
|
278
|
+
if (j && scene?.briefWait && ['planning', 'refining'].includes(j.status)) j = { ...j, status: 'awaiting_brief' };
|
|
279
|
+
else if (j && scene?.briefWrite && j.status === 'planning') j = { ...j, status: 'refining' };
|
|
280
|
+
// job and XP
|
|
281
|
+
if (j) {
|
|
282
|
+
const tasks = jobTasks(s, j);
|
|
283
|
+
// progress is completed tasks of all tasks, nothing weighted; the running task is told in words
|
|
284
|
+
const done = tasks.filter((t) => t.status === 'done' || t.status === 'skipped').length;
|
|
285
|
+
const runningTasks = tasks.filter((t) => t.status === 'running' || t.status === 'review');
|
|
286
|
+
const running = runningTasks.length;
|
|
287
|
+
const total = tasks.length;
|
|
288
|
+
const pct = j.status === 'done' ? 100 : total ? Math.round((done / total) * 100) : 0;
|
|
289
|
+
hud.req.textContent = j.request;
|
|
290
|
+
hud.req.title = j.request;
|
|
291
|
+
hud.xpFill.style.width = `${pct}%`;
|
|
292
|
+
hud.xp.setAttribute('aria-valuenow', String(pct));
|
|
293
|
+
hud.xpLv.textContent = `${pct}%`;
|
|
294
|
+
paintTimeline(tasks);
|
|
295
|
+
if (['refining', 'awaiting_brief', 'planning'].includes(j.status)) hud.xpText.textContent = t(`office.hud.line.${j.status}`);
|
|
296
|
+
else {
|
|
297
|
+
const progress = t('office.hud.done', { done, total });
|
|
298
|
+
let what = running ? nowLine(s, runningTasks[0]) : '';
|
|
299
|
+
if (running > 1) what = t('office.hud.more', { what, count: running - 1 });
|
|
300
|
+
hud.xpText.textContent = running ? t('office.hud.doneNow', { progress, what }) : progress;
|
|
301
|
+
}
|
|
302
|
+
hud.state.textContent = JOB_STATES.includes(j.status) ? t(`office.state.${j.status}`) : j.status;
|
|
303
|
+
hud.state.dataset.s = j.status;
|
|
304
|
+
hud.openBrief.hidden = j.status !== 'awaiting_brief';
|
|
305
|
+
} else {
|
|
306
|
+
hud.req.textContent = t('office.hud.noJob');
|
|
307
|
+
hud.req.title = '';
|
|
308
|
+
hud.xpFill.style.width = '0%';
|
|
309
|
+
hud.xpLv.textContent = '0%';
|
|
310
|
+
hud.xpText.textContent = t('office.hud.noJobHint');
|
|
311
|
+
paintTimeline([]);
|
|
312
|
+
hud.state.textContent = t('office.state.idle');
|
|
313
|
+
hud.state.dataset.s = 'idle';
|
|
314
|
+
hud.openBrief.hidden = true;
|
|
315
|
+
}
|
|
316
|
+
// honey
|
|
317
|
+
const honey = doneCount(s);
|
|
318
|
+
if (shownHoney == null || honey < shownHoney || reducedMotion() || mode !== 'office') shownHoney = honey;
|
|
319
|
+
else if (honey > shownHoney) { clearTimeout(honeyTimer); honeyTimer = setTimeout(() => { shownHoney = doneCount(S()); paintHoney(); }, 1800); }
|
|
320
|
+
paintHoney();
|
|
321
|
+
paintClock();
|
|
322
|
+
// queue, the honest part: one model, workers take turns
|
|
323
|
+
clear(hud.queue);
|
|
324
|
+
const running = s.queue.running || [];
|
|
325
|
+
const waiting = s.queue.waiting || [];
|
|
326
|
+
hud.queue.append(h('div', { class: 'of-k', text: t('office.queue.title') }));
|
|
327
|
+
const row = h('div', { class: 'of-qrow' });
|
|
328
|
+
if (running.length) {
|
|
329
|
+
for (const q of running) row.append(h('span', { class: 'of-q of-q-on', title: t('office.queue.hasModel', { name: worker(q.workerId).name }) }, beeAvatar(worker(q.workerId), 26, { ring: true, status: 'thinking' })));
|
|
330
|
+
if (running.length === 1) row.append(h('span', { class: 'of-qname' }, h('b', { text: worker(running[0].workerId).name }), h('span', { class: 'of-faint', text: mdLine(s.tasks[running[0].taskId]?.title || '', 80) || t('office.queue.thinking') })));
|
|
331
|
+
}
|
|
332
|
+
else row.append(h('span', { class: 'of-faint small', text: t('office.queue.free') }));
|
|
333
|
+
if (waiting.length) {
|
|
334
|
+
row.append(h('span', { class: 'of-qsep', html: '<svg viewBox="0 0 16 16" class="ico ico-sm"><circle cx="8" cy="8" r="6.2"/><path d="M8 4.6V8l2.4 1.6"/></svg>' }));
|
|
335
|
+
for (const q of waiting.slice(0, 6)) row.append(h('span', { class: 'of-q', title: t('office.queue.inQueue', { name: worker(q.workerId).name }) }, beeAvatar(worker(q.workerId), 22, { ring: true })));
|
|
336
|
+
if (waiting.length > 6) row.append(h('span', { class: 'of-faint small', text: `+${waiting.length - 6}` }));
|
|
337
|
+
}
|
|
338
|
+
hud.queue.append(row, h('div', { class: 'of-faint tiny', text: (s.brains || []).length > 1 ? t('office.queue.brains', { count: s.brains.length }) : t('office.queue.oneModel') }));
|
|
339
|
+
// nothing hired yet / no state yet
|
|
340
|
+
hud.empty.hidden = !!(s.crew || []).length;
|
|
341
|
+
hud.empty.textContent = ui.hello ? t('office.empty') : t('office.opening');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** The running task in words: who does what right now, from the worker's real status. */
|
|
345
|
+
function nowLine(s, task) {
|
|
346
|
+
if (!task) return '';
|
|
347
|
+
const w = worker(task.assignee);
|
|
348
|
+
const st = s.workers?.[task.assignee] || {};
|
|
349
|
+
const what = NOW_KEYS.includes(st.status) ? st.status : task.status === 'review' ? 'review' : 'works';
|
|
350
|
+
return t(`office.now.${what}`, { name: w.name, title: mdLine(task.title, 80) });
|
|
351
|
+
}
|
|
352
|
+
const NOW_KEYS = ['thinking', 'tool', 'queued', 'waiting_approval'];
|
|
353
|
+
|
|
354
|
+
function paintClock() {
|
|
355
|
+
const hr = hourNow();
|
|
356
|
+
const hh = Math.floor(hr); const mm = Math.floor((hr % 1) * 60);
|
|
357
|
+
hud.clock.textContent = `${dayPhase(hr)} · ${String(hh).padStart(2, '0')}:${String(mm).padStart(2, '0')}`;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function paintHoney() {
|
|
361
|
+
if (hud.honeyN) hud.honeyN.textContent = String(shownHoney ?? 0);
|
|
362
|
+
if (hud.honeyT) hud.honeyT.textContent = t('office.hud.tasksDone', { count: shownHoney ?? 0 });
|
|
363
|
+
}
|
|
364
|
+
function bumpHoney() {
|
|
365
|
+
const real = doneCount(S());
|
|
366
|
+
shownHoney = Math.min(real, (shownHoney ?? 0) + 1);
|
|
367
|
+
paintHoney();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** The segmented timeline: one segment per task of the job, in order, colored by its state. */
|
|
371
|
+
function paintTimeline(tasks) {
|
|
372
|
+
if (!hud.segs) return;
|
|
373
|
+
const key = tasks.map((x) => `${x.id}:${x.status}`).join('|');
|
|
374
|
+
if (hud.segs._key === key) return;
|
|
375
|
+
hud.segs._key = key;
|
|
376
|
+
clear(hud.segs);
|
|
377
|
+
for (const x of tasks) hud.segs.append(h('i', { dataset: { s: x.status }, title: `${mdLine(x.title, 120)}: ${TASK_LABEL[x.status] || x.status}` }));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/* activity feed: short, human lines from real events (tx keys, so a language switch rewrites them) */
|
|
381
|
+
function feed(ev) {
|
|
382
|
+
if (!hud.feed) return;
|
|
383
|
+
const d = ev.data || {};
|
|
384
|
+
const s = S();
|
|
385
|
+
const name = (id) => worker(id).name;
|
|
386
|
+
const title = (task) => mdLine(task.title, 80);
|
|
387
|
+
let line = null; let tone = '';
|
|
388
|
+
switch (ev.type) {
|
|
389
|
+
case 'job.created': line = ['office.feed.jobCreated']; tone = 'honey'; break;
|
|
390
|
+
case 'job.planned': line = ['office.feed.jobPlanned', { count: d.tasks?.length || 0 }]; break;
|
|
391
|
+
case 'brief.proposed': line = ['office.feed.briefProposed']; tone = 'warn'; break;
|
|
392
|
+
case 'brief.approved': line = [d.source === 'original' ? 'office.feed.briefOriginal' : 'office.feed.briefApproved']; break;
|
|
393
|
+
case 'task.status': {
|
|
394
|
+
const task = s.tasks[d.taskId];
|
|
395
|
+
if (!task) break;
|
|
396
|
+
if (d.status === 'running') line = ['office.feed.started', { name: name(task.assignee), title: title(task) }];
|
|
397
|
+
else if (d.status === 'done') { line = ['office.feed.finished', { name: name(task.assignee), title: title(task) }]; tone = 'ok'; }
|
|
398
|
+
else if (d.status === 'failed') { line = ['office.feed.stuck', { name: name(task.assignee), title: title(task) }]; tone = 'bad'; }
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case 'file.changed': line = [d.op === 'create' ? 'office.feed.fileCreate' : d.op === 'delete' ? 'office.feed.fileDelete' : 'office.feed.fileEdit', { name: name(d.workerId), path: String(d.path || '') }]; break;
|
|
402
|
+
case 'approval.requested': line = ['office.feed.approval', { name: name(d.approval?.workerId) }]; tone = 'warn'; break;
|
|
403
|
+
case 'qa.report': line = d.passed ? ['office.feed.qaPassed'] : ['office.feed.qaIssues', { count: d.issues?.length || 0 }]; tone = d.passed ? 'ok' : 'bad'; break;
|
|
404
|
+
case 'task.updated': if (d.task?.assignee) line = ['office.feed.handed', { name: name(d.task.assignee) }]; break;
|
|
405
|
+
case 'crew.hired': if (ui.hello && !d.worker?.builtin) { line = ['office.feed.joined', { name: d.worker?.name || '' }]; tone = 'honey'; } break;
|
|
406
|
+
case 'job.done': line = ['office.feed.jobDone']; tone = 'ok'; break;
|
|
407
|
+
default: break;
|
|
408
|
+
}
|
|
409
|
+
if (!line) return;
|
|
410
|
+
const li = h('li', { dataset: { tone } }, h('span', { class: 'of-dot' }), h('span', { tx: line[0], txArgs: line[1] }));
|
|
411
|
+
// the brief waits for the user's OK: the line opens it
|
|
412
|
+
if (ev.type === 'brief.proposed') li.append(h('button', { type: 'button', class: 'btn btn-xs btn-quiet', style: 'margin-left:6px', tx: 'office.hud.openBrief', on: { click: () => { setMode('desktop'); wm.open('brief'); } } }));
|
|
413
|
+
hud.feed.prepend(li);
|
|
414
|
+
while (hud.feed.children.length > 5) hud.feed.lastChild.remove();
|
|
415
|
+
if (!reducedMotion() && mode === 'office') li.animate([{ opacity: 0, transform: 'translateY(-4px)' }, { opacity: 1, transform: 'none' }], { duration: 200, easing: 'cubic-bezier(.2,0,0,1)' });
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function banner(ev) {
|
|
419
|
+
const b = hud.banner;
|
|
420
|
+
clear(b);
|
|
421
|
+
// a calm activity toast: a check, the summary and one action
|
|
422
|
+
b.append(h('span', { class: 'of-jar of-jar-big', html: CHECK_SVG, 'aria-hidden': 'true' }),
|
|
423
|
+
h('div', {}, h('strong', { tx: 'office.banner.title' }), h('div', { class: 'of-faint', text: mdLine(ev.data?.summary || '', 140) || t('office.banner.fallback') })),
|
|
424
|
+
h('button', { type: 'button', class: 'btn btn-xs btn-quiet', tx: 'office.banner.preview', on: { click: () => { setMode('desktop'); wm.open('preview'); } } }));
|
|
425
|
+
b.hidden = false;
|
|
426
|
+
if (!reducedMotion()) b.animate([{ opacity: 0, transform: 'translate(-50%, 6px)' }, { opacity: 1, transform: 'translate(-50%, 0)' }], { duration: 200, easing: 'cubic-bezier(.2,0,0,1)' });
|
|
427
|
+
clearTimeout(b._t);
|
|
428
|
+
b._t = setTimeout(() => { b.hidden = true; }, 7000);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/* ---------- the DOM layer over the canvas: focus, hover, click, menus, drag ---------- */
|
|
432
|
+
function syncHits(sc) {
|
|
433
|
+
const s = S();
|
|
434
|
+
// bees
|
|
435
|
+
const seen = new Set();
|
|
436
|
+
for (const hit of sc.hits) {
|
|
437
|
+
seen.add(hit.id);
|
|
438
|
+
let b = bees.get(hit.id);
|
|
439
|
+
if (!b) b = makeBee(hit.id);
|
|
440
|
+
const tx = Math.round(hit.x); const ty = Math.round(hit.y);
|
|
441
|
+
if (b._x !== tx || b._y !== ty || b._w !== Math.round(hit.w)) {
|
|
442
|
+
b._x = tx; b._y = ty; b._w = Math.round(hit.w);
|
|
443
|
+
b.style.transform = `translate(${tx}px, ${ty}px)`;
|
|
444
|
+
b.style.width = `${Math.round(hit.w)}px`;
|
|
445
|
+
b.style.height = `${Math.round(hit.h)}px`;
|
|
446
|
+
}
|
|
447
|
+
const a = sc.actors.get(hit.id);
|
|
448
|
+
const label = beeLabel(hit.id, a, s);
|
|
449
|
+
if (b._label !== label) { b._label = label; b.setAttribute('aria-label', label); if (tip.dataset.for === `bee:${hit.id}`) showTip(b, hit.id); }
|
|
450
|
+
}
|
|
451
|
+
for (const [id, b] of bees) if (!seen.has(id)) { b.remove(); bees.delete(id); }
|
|
452
|
+
// notes
|
|
453
|
+
const nseen = new Set();
|
|
454
|
+
for (const hit of sc.noteHits) {
|
|
455
|
+
nseen.add(hit.id);
|
|
456
|
+
let n = notes.get(hit.id);
|
|
457
|
+
if (!n) n = makeNote(hit.id);
|
|
458
|
+
const tx = Math.round(hit.x); const ty = Math.round(hit.y);
|
|
459
|
+
if (n._x !== tx || n._y !== ty) {
|
|
460
|
+
n._x = tx; n._y = ty;
|
|
461
|
+
n.style.transform = `translate(${tx}px, ${ty}px)`;
|
|
462
|
+
n.style.width = `${Math.round(hit.w)}px`;
|
|
463
|
+
n.style.height = `${Math.round(hit.h)}px`;
|
|
464
|
+
}
|
|
465
|
+
const task = s.tasks[hit.id];
|
|
466
|
+
const label = task ? t('office.note.aria', { title: mdLine(task.title, 120), status: TASK_LABEL[task.status] || task.status, name: worker(task.assignee).name }) : t('office.note.task');
|
|
467
|
+
if (n._label !== label) { n._label = label; n.setAttribute('aria-label', label); }
|
|
468
|
+
}
|
|
469
|
+
for (const [id, n] of notes) if (!nseen.has(id) && !(drag && drag.taskId === id)) { n.remove(); notes.delete(id); }
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function beeLabel(id, a, s) {
|
|
473
|
+
const w = worker(id);
|
|
474
|
+
const st = s.workers[id] || { status: 'idle' };
|
|
475
|
+
const task = st.taskId && s.tasks[st.taskId];
|
|
476
|
+
const m = a ? (a.seg ? 'fly' : a.mode) : 'idle';
|
|
477
|
+
const lv = levelOf(s, id);
|
|
478
|
+
const who = lv != null ? t('office.bee.whoLevel', { name: w.name, role: roleOf(w), level: lv }) : t('office.bee.who', { name: w.name, role: roleOf(w) });
|
|
479
|
+
const status = statusOf(w, m, st);
|
|
480
|
+
return task ? t('office.bee.ariaTask', { who, status, title: mdLine(task.title, 120) }) : t('office.bee.aria', { who, status });
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function makeBee(id) {
|
|
484
|
+
const b = h('button', { type: 'button', class: 'of-bee', 'aria-describedby': 'of-tip', dataset: { id } });
|
|
485
|
+
b.addEventListener('click', () => { if (!drag) wm.open('worker', id); });
|
|
486
|
+
b.addEventListener('pointerenter', () => { scene.highlight = id; showTip(b, id); });
|
|
487
|
+
b.addEventListener('pointerleave', () => { if (scene.highlight === id) scene.highlight = null; hideTip(); });
|
|
488
|
+
b.addEventListener('focus', () => { scene.highlight = id; showTip(b, id); });
|
|
489
|
+
b.addEventListener('blur', () => { if (scene.highlight === id) scene.highlight = null; hideTip(); });
|
|
490
|
+
menu.provide(b, () => beeMenu(id));
|
|
491
|
+
hitLayer.append(b);
|
|
492
|
+
bees.set(id, b);
|
|
493
|
+
return b;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function beeMenu(id) {
|
|
497
|
+
const w = worker(id);
|
|
498
|
+
const s = S();
|
|
499
|
+
const st = s.workers[id] || {};
|
|
500
|
+
const mine = Object.values(s.tasks).filter((x) => x.assignee === id);
|
|
501
|
+
const retryable = mine.filter((x) => ['failed', 'blocked'].includes(x.status)).pop() || (st.taskId && s.tasks[st.taskId]);
|
|
502
|
+
const lv = levelOf(s, id);
|
|
503
|
+
return [
|
|
504
|
+
{ header: lv != null ? t('office.menu.headerLevel', { name: w.name, role: roleOf(w), level: lv }) : t('office.menu.header', { name: w.name, role: roleOf(w) }) },
|
|
505
|
+
{ label: t('office.menu.chat', { name: w.name }), icon: 'chat', action: () => wm.open('worker', id) },
|
|
506
|
+
{ label: w.paused ? t('office.menu.resume') : t('office.menu.pause'), icon: w.paused ? 'arrow' : 'stop', disabled: !!ui.replay, action: () => act.pauseWorker(id, !w.paused) },
|
|
507
|
+
{ label: retryable ? t('office.menu.retryTask', { title: mdLine(retryable.title, 60) }) : t('office.menu.retryNone'), icon: 'replay', disabled: !retryable || !!ui.replay, action: () => act.retryTask(retryable.id) },
|
|
508
|
+
{ label: t('office.menu.files'), icon: 'folder', action: () => { setMode('desktop'); wm.open('files'); } },
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function makeNote(id) {
|
|
513
|
+
const n = h('button', { type: 'button', class: 'of-note', 'aria-describedby': 'of-tip', dataset: { id } });
|
|
514
|
+
n.addEventListener('pointerenter', () => { scene.highlight = id; showNoteTip(n, id); });
|
|
515
|
+
n.addEventListener('pointerleave', () => { if (scene.highlight === id) scene.highlight = null; hideTip(); });
|
|
516
|
+
n.addEventListener('focus', () => { scene.highlight = id; showNoteTip(n, id); });
|
|
517
|
+
n.addEventListener('blur', () => { if (scene.highlight === id) scene.highlight = null; hideTip(); });
|
|
518
|
+
n.addEventListener('click', (e) => {
|
|
519
|
+
if (n._dragged) { n._dragged = false; return; }
|
|
520
|
+
const r = n.getBoundingClientRect();
|
|
521
|
+
menu.open({ x: e.clientX || r.left + 10, y: e.clientY || r.bottom, items: noteMenu(id) });
|
|
522
|
+
});
|
|
523
|
+
n.addEventListener('pointerdown', (e) => startDrag(e, n, id));
|
|
524
|
+
menu.provide(n, () => noteMenu(id));
|
|
525
|
+
hitLayer.append(n);
|
|
526
|
+
notes.set(id, n);
|
|
527
|
+
return n;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function noteMenu(id) {
|
|
531
|
+
const s = S();
|
|
532
|
+
const task = s.tasks[id];
|
|
533
|
+
if (!task) return null;
|
|
534
|
+
const off = !!ui.replay || task.status === 'done';
|
|
535
|
+
return [
|
|
536
|
+
{ header: mdLine(task.title, 60) },
|
|
537
|
+
{ label: t('office.menu.handTo'), icon: 'hire', disabled: off, items: s.crew.filter((w) => w.id !== task.assignee).map((w) => ({ label: t('office.menu.handToWho', { name: w.name, role: roleOf(w) }), iconEl: beeAvatar(w, 18, { ring: false }), action: () => reassign(id, w.id) })) },
|
|
538
|
+
{ label: t('office.menu.retry'), icon: 'replay', disabled: !!ui.replay || !['failed', 'blocked', 'done', 'skipped'].includes(task.status), action: () => act.retryTask(id) },
|
|
539
|
+
{ label: t('office.menu.cancel'), icon: 'x', danger: true, disabled: !!ui.replay || ['done', 'skipped'].includes(task.status), action: () => act.cancelTask(id) },
|
|
540
|
+
];
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function reassign(taskId, workerId) {
|
|
544
|
+
const task = S().tasks[taskId];
|
|
545
|
+
if (!task || task.assignee === workerId) return;
|
|
546
|
+
act.reassignTask(taskId, workerId);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function startDrag(e, el, id) {
|
|
550
|
+
if (e.button !== 0 || ui.replay) return;
|
|
551
|
+
const task = S().tasks[id];
|
|
552
|
+
if (!task || task.status === 'done') return;
|
|
553
|
+
const x0 = e.clientX; const y0 = e.clientY;
|
|
554
|
+
let ghost = null;
|
|
555
|
+
const move = (ev) => {
|
|
556
|
+
if (!drag && Math.hypot(ev.clientX - x0, ev.clientY - y0) < 6) return;
|
|
557
|
+
if (!drag) {
|
|
558
|
+
drag = { taskId: id, el };
|
|
559
|
+
scene.dragTask = id;
|
|
560
|
+
ghost = h('div', { class: 'of-drag', 'aria-hidden': 'true' }, h('i', { style: `background:${worker(task.assignee).color}` }), h('span', { text: mdLine(task.title, 60) }));
|
|
561
|
+
layer.append(ghost);
|
|
562
|
+
layer.classList.add('of-dragging');
|
|
563
|
+
hideTip();
|
|
564
|
+
}
|
|
565
|
+
const lr = layer.getBoundingClientRect();
|
|
566
|
+
ghost.style.transform = `translate(${ev.clientX - lr.left + 8}px, ${ev.clientY - lr.top + 8}px) rotate(-4deg)`;
|
|
567
|
+
const over = beeAt(ev.clientX, ev.clientY);
|
|
568
|
+
scene.highlight = over || null;
|
|
569
|
+
drag.over = over;
|
|
570
|
+
};
|
|
571
|
+
const up = () => {
|
|
572
|
+
removeEventListener('pointermove', move);
|
|
573
|
+
removeEventListener('pointerup', up);
|
|
574
|
+
removeEventListener('pointercancel', up);
|
|
575
|
+
if (!drag) return;
|
|
576
|
+
el._dragged = true;
|
|
577
|
+
const target = drag.over;
|
|
578
|
+
ghost?.remove();
|
|
579
|
+
layer.classList.remove('of-dragging');
|
|
580
|
+
scene.dragTask = null;
|
|
581
|
+
scene.highlight = null;
|
|
582
|
+
drag = null;
|
|
583
|
+
if (target) reassign(id, target);
|
|
584
|
+
};
|
|
585
|
+
addEventListener('pointermove', move);
|
|
586
|
+
addEventListener('pointerup', up);
|
|
587
|
+
addEventListener('pointercancel', up);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function cancelDrag() {
|
|
591
|
+
layer.querySelector('.of-drag')?.remove();
|
|
592
|
+
layer.classList.remove('of-dragging');
|
|
593
|
+
scene.dragTask = null;
|
|
594
|
+
scene.highlight = null;
|
|
595
|
+
drag = null;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function beeAt(x, y) {
|
|
599
|
+
for (const [id, b] of bees) {
|
|
600
|
+
const r = b.getBoundingClientRect();
|
|
601
|
+
if (x >= r.left - 6 && x <= r.right + 6 && y >= r.top - 6 && y <= r.bottom + 6) return id;
|
|
602
|
+
}
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function showTip(el, id) {
|
|
607
|
+
const s = S();
|
|
608
|
+
const w = worker(id);
|
|
609
|
+
const a = scene.actors.get(id);
|
|
610
|
+
const st = s.workers[id] || { status: 'idle' };
|
|
611
|
+
const task = st.taskId && s.tasks[st.taskId];
|
|
612
|
+
const m = a ? (a.seg ? 'fly' : a.mode) : 'idle';
|
|
613
|
+
const lastTask = task || Object.values(s.tasks).filter((x) => x.assignee === id && x.status === 'running').pop();
|
|
614
|
+
const done = Object.values(s.tasks).filter((x) => x.assignee === id && x.status === 'done').length;
|
|
615
|
+
const lv = levelOf(s, id);
|
|
616
|
+
clear(tip);
|
|
617
|
+
tip.append(
|
|
618
|
+
h('div', { class: 'of-tip-h' }, beeAvatar(w, 30, { ring: true }), h('div', {}, h('strong', { text: w.name }), h('div', { class: 'of-faint', text: roleOf(w) })), lv != null ? h('span', { class: 'of-lv', text: t('office.level', { level: lv }) }) : null),
|
|
619
|
+
h('div', { class: 'of-tip-r' }, h('span', { class: 'of-faint', tx: 'office.tip.status' }), h('span', { text: statusOf(w, m, st) })),
|
|
620
|
+
h('div', { class: 'of-tip-r' }, h('span', { class: 'of-faint', tx: 'office.tip.task' }), h('span', { text: lastTask ? mdLine(lastTask.title, 80) : t('office.tip.none') })),
|
|
621
|
+
h('div', { class: 'of-tip-r' }, h('span', { class: 'of-faint', tx: 'office.tip.done' }), h('span', { text: t('office.tip.doneCount', { count: done }) })),
|
|
622
|
+
h('div', { class: 'of-tip-f', tx: 'office.tip.foot' }));
|
|
623
|
+
tip.dataset.for = `bee:${id}`;
|
|
624
|
+
place(el);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function showNoteTip(el, id) {
|
|
628
|
+
const s = S();
|
|
629
|
+
const task = s.tasks[id];
|
|
630
|
+
if (!task) return;
|
|
631
|
+
clear(tip);
|
|
632
|
+
append(tip, [h('div', { class: 'of-tip-h' }, h('div', {}, h('strong', { text: mdLine(task.title, 120) }), h('div', { class: 'of-faint', text: t('office.tip.noteMeta', { status: TASK_LABEL[task.status] || task.status, name: worker(task.assignee).name }) }))),
|
|
633
|
+
task.detail ? h('div', { class: 'of-tip-d', text: mdLine(task.detail, 180) }) : null,
|
|
634
|
+
h('div', { class: 'of-tip-f', tx: task.status === 'done' ? 'office.tip.noteDone' : 'office.tip.noteFoot' })]);
|
|
635
|
+
tip.dataset.for = `note:${id}`;
|
|
636
|
+
place(el);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function place(el) {
|
|
640
|
+
const r = el.getBoundingClientRect();
|
|
641
|
+
const lr = layer.getBoundingClientRect();
|
|
642
|
+
tip.classList.add('on');
|
|
643
|
+
const tr = tip.getBoundingClientRect();
|
|
644
|
+
let x = r.left - lr.left + r.width / 2 - tr.width / 2;
|
|
645
|
+
let y = r.top - lr.top - tr.height - 10;
|
|
646
|
+
if (y < 8) y = r.bottom - lr.top + 10;
|
|
647
|
+
x = Math.max(8, Math.min(lr.width - tr.width - 8, x));
|
|
648
|
+
tip.style.transform = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
|
|
649
|
+
}
|
|
650
|
+
function hideTip() { tip?.classList.remove('on'); if (tip) tip.dataset.for = ''; }
|
|
651
|
+
|
|
652
|
+
/* ---------- glyphs ---------- */
|
|
653
|
+
function officeGlyph() {
|
|
654
|
+
return h('span', { class: 'of-gl', html: '<svg viewBox="0 0 24 24" class="ico ico-sm"><path d="M12 3 21 8v8l-9 5-9-5V8z"/><path d="M3 8l9 5 9-5M12 13v8"/></svg>' });
|
|
655
|
+
}
|
|
656
|
+
function miniGlyph() {
|
|
657
|
+
return h('span', { class: 'of-gl', html: '<svg viewBox="0 0 24 24" class="ico"><rect x="3.5" y="4.5" width="17" height="15" rx="2.5"/><rect x="11.5" y="11.5" width="7" height="6" rx="1.2"/></svg>' });
|
|
658
|
+
}
|
|
659
|
+
function pipGlyph() {
|
|
660
|
+
return h('span', { class: 'of-gl', html: '<svg viewBox="0 0 24 24" class="ico"><rect x="3.5" y="5" width="17" height="14" rx="2.5"/><path d="M13 12.5h5.5v4.5H13z"/><path d="M7 9l3 3M7 9h2.6M7 9v2.6"/></svg>' });
|
|
661
|
+
}
|
|
662
|
+
const CHECK_SVG = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8.5"/><path d="M8.2 12.2l2.6 2.6 5-5.2"/></svg>';
|