Repository navigation
Expand file tree
/
Copy pathclient.js
More file actions
2207 lines (2137 loc) · 93.7 KB
/
Copy pathclient.js
File metadata and controls
2207 lines (2137 loc) · 93.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
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
319
320
321
322
323
324
325
326
327
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
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
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
514
515
516
517
518
519
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
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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Web / Desktop client for `dsh-qoder-bots` — Standalone Super-Agent / Bot OS Workspace
*
* Pure Standalone Architecture (Zero Workspace Session-List or Chat-Box Pollution):
* - Registers ONLY `sidebar.panellist` (`Bots`, order 15) + `main` (`'qoder-bots-studio'`).
* - NEVER creates items in the regular `工作区` / `默认工作区` session list.
* - NEVER injects a toggle switch into the regular `新会话` composer (`conversation.hero.options`).
* - NEVER mounts a tab onto regular workspace conversations (`sidebarRightTabs`).
*
* Design Philosophy:
* - **DeepSeek Super Agent**: Solves the human attention bottleneck via a persistent
* Chief-of-Staff Router + Multi-Worker sub-agent delegation (`Coordinator` + `Threads`),
* asynchronous background execution, and Proactive Attention Triage (`Needs Approval` + Inbox).
* - **Always-On Cloud Computer**: Each Bot lives in its own persistent Cloud Computer
* powered by **Qoder Cloud Agents** (`/api/v1/cloud`), with a live Cloud Chrome viewport,
* 1-click `🕹️ 人工接管`, persistent `Memory Store` + CoW `Dream`, and `7×24 Routines`.
*/
window.__ModuleLoader__.load({
id: '@qoder-ai/dsh-qoder-bots',
factory(require) {
const React = require('react')
const h = React.createElement
const NS = 'qoderBots'
const PANEL_ID = 'qoder-bots-studio'
const API_BASE = '/api/qoder-bots'
const zh = { navLabel: 'Bots' }
const en = { navLabel: 'Bots' }
async function apiGet(path, params) {
const qs = params ? '?' + new URLSearchParams(params).toString() : ''
const res = await fetch(API_BASE + path + qs, {
method: 'GET',
credentials: 'same-origin',
headers: { accept: 'application/json' },
})
const data = await res.json().catch(() => ({ ok: false, error: 'Invalid response (' + res.status + ')' }))
if (!res.ok || data.ok === false) {
throw new Error(data.error || ('HTTP ' + res.status))
}
return data
}
async function apiAction(action, payload) {
const res = await fetch(API_BASE + '/action', {
method: 'POST',
credentials: 'same-origin',
headers: { 'content-type': 'application/json', accept: 'application/json' },
body: JSON.stringify(Object.assign({ action }, payload || {})),
})
const data = await res.json().catch(() => ({ ok: false, error: 'Invalid response (' + res.status + ')' }))
if (!res.ok || data.ok === false) {
throw new Error(data.error || ('HTTP ' + res.status))
}
return data
}
function fileUrl(fileId, filename, inline) {
const q = new URLSearchParams({ id: fileId })
if (filename) q.set('name', filename)
if (inline) q.set('inline', '1')
return API_BASE + '/file?' + q.toString()
}
function isImgName(name, mime) {
if (mime && mime.indexOf('image/') === 0) return true
if (!name) return false
return /\.(png|jpe?g|webp|gif|svg)$/i.test(name)
}
function formatTimeAgo(iso) {
if (!iso) return ''
const ms = Date.now() - Date.parse(iso)
if (!Number.isFinite(ms)) return ''
const sec = Math.max(0, Math.floor(ms / 1000))
if (sec < 60) return sec <= 5 ? '刚刚' : (sec + ' 秒前')
const min = Math.floor(sec / 60)
if (min < 60) return min + ' 分钟前'
const hr = Math.floor(min / 60)
if (hr < 24) return hr + ' 小时前'
return Math.floor(hr / 24) + ' 天前'
}
// Normalize internal file reference tokens for clean UI display
function cleanDisplayText(str) {
if (!str || typeof str !== 'string') return ''
return str.replace(/file_[0-9a-zA-Z._-]+/g, '已就绪')
}
// Clean Robot Icon for Left Primary Navigation (`sidebar.panellist` -> `Bots`)
function BotsNavIcon(props) {
const size = (props && props.size) || 18
return h('svg', {
width: size,
height: size,
viewBox: '0 0 24 24',
fill: 'none',
stroke: 'currentColor',
strokeWidth: 1.8,
strokeLinecap: 'round',
strokeLinejoin: 'round',
'aria-hidden': 'true',
},
h('rect', { x: 3, y: 6, width: 18, height: 13, rx: 3.5 }),
h('path', { d: 'M12 2v4' }),
h('circle', { cx: 12, cy: 2, r: 1, fill: 'currentColor' }),
h('circle', { cx: 9, cy: 12.2, r: 1.3, fill: 'currentColor', stroke: 'none' }),
h('circle', { cx: 15, cy: 12.2, r: 1.3, fill: 'currentColor', stroke: 'none' }),
h('path', { d: 'M9.5 15.8h5' }))
}
const S = {
card: {
borderRadius: 14,
border: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.20))',
background: 'var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-layer-1, rgba(255,255,255,0.78)))',
padding: 16,
boxShadow: '0 2px 10px rgba(15, 23, 42, 0.03)',
},
pill: (tone) => {
const palettes = {
blue: { bg: 'rgba(65, 118, 230, 0.12)', fg: '#2b63d9', bd: 'rgba(65, 118, 230, 0.25)' },
green: { bg: 'rgba(16, 185, 129, 0.12)', fg: '#059669', bd: 'rgba(16, 185, 129, 0.28)' },
amber: { bg: 'rgba(245, 158, 11, 0.14)', fg: '#d97706', bd: 'rgba(245, 158, 11, 0.34)' },
purple: { bg: 'rgba(139, 92, 246, 0.12)', fg: '#7c3aed', bd: 'rgba(139, 92, 246, 0.28)' },
teal: { bg: 'rgba(13, 148, 136, 0.12)', fg: '#0f766e', bd: 'rgba(13, 148, 136, 0.26)' },
neutral: { bg: 'rgba(148, 163, 184, 0.13)', fg: 'var(--dsw-alias-label-secondary, #64748b)', bd: 'rgba(148, 163, 184, 0.22)' },
}
const p = palettes[tone] || palettes.neutral
return {
display: 'inline-flex',
alignItems: 'center',
gap: 4,
padding: '2px 8px',
borderRadius: 999,
fontSize: 11,
fontWeight: 500,
lineHeight: '16px',
background: p.bg,
color: p.fg,
border: '1px solid ' + p.bd,
whiteSpace: 'nowrap',
}
},
btnPrimary: (disabled) => ({
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
gap: 6,
padding: '7px 13px',
borderRadius: 9,
border: 'none',
background: disabled ? 'rgba(65,118,230,0.42)' : 'linear-gradient(135deg, #4176E6 0%, #315FD2 100%)',
color: '#ffffff',
fontSize: 12.5,
fontWeight: 600,
cursor: disabled ? 'not-allowed' : 'pointer',
boxShadow: disabled ? 'none' : '0 2px 8px rgba(65, 118, 230, 0.22)',
}),
btnSecondary: (active, disabled) => ({
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
gap: 5,
padding: '6px 11px',
borderRadius: 9,
border: '1px solid ' + (active ? 'rgba(65,118,230,0.45)' : 'var(--dsw-alias-line-primary, rgba(128,138,158,0.24))'),
background: active ? 'rgba(65,118,230,0.10)' : 'transparent',
color: active ? '#2b63d9' : 'var(--dsw-alias-label-primary, inherit)',
fontSize: 12,
fontWeight: active ? 600 : 500,
cursor: disabled ? 'not-allowed' : 'pointer',
}),
btnDanger: (disabled) => ({
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
gap: 5,
padding: '6px 11px',
borderRadius: 9,
border: '1px solid rgba(239, 68, 68, 0.32)',
background: 'rgba(239, 68, 68, 0.08)',
color: '#dc2626',
fontSize: 12,
fontWeight: 500,
cursor: disabled ? 'not-allowed' : 'pointer',
}),
input: {
width: '100%',
boxSizing: 'border-box',
padding: '8px 11px',
borderRadius: 9,
border: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.28))',
background: 'var(--dsw-alias-bg-base, transparent)',
color: 'var(--dsw-alias-label-primary, inherit)',
fontSize: 13,
outline: 'none',
},
}
// --- Human-in-the-Loop Approval Gate Card (`Needs Approval`) ---
function ApprovalCard({ item, onDecide, compact }) {
const [busy, setBusy] = React.useState(false)
const [denyReason, setDenyReason] = React.useState('')
const [showDenyInput, setShowDenyInput] = React.useState(false)
const decide = async (decision) => {
setBusy(true)
try {
await onDecide(item, decision, denyReason)
} finally {
setBusy(false)
}
}
return h('div', {
'data-testid': 'qoder-approval-card',
style: {
borderRadius: 12,
border: '1.5px solid rgba(245, 158, 11, 0.58)',
background: 'linear-gradient(180deg, rgba(245, 158, 11, 0.12) 0%, rgba(245, 158, 11, 0.04) 100%)',
padding: compact ? 12 : 15,
display: 'flex',
flexDirection: 'column',
gap: 9,
},
},
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 } },
h('div', { style: { display: 'flex', alignItems: 'center', gap: 7, fontWeight: 600, fontSize: compact ? 12.5 : 13.5, color: '#b45309' } },
h('span', null, '🛡️ Needs Approval · 人类决策门禁'),
h('span', { style: S.pill('amber') }, item.toolName),
),
h('span', { style: { fontSize: 11, opacity: 0.7 } }, formatTimeAgo(item.createdAt)),
),
h('div', { style: { fontSize: 12, opacity: 0.88 } },
'Bot ',
h('strong', null, item.botName),
' 在专属云电脑请求执行敏感操作:',
),
h('pre', {
style: {
margin: 0,
padding: '8px 10px',
borderRadius: 8,
background: 'rgba(15, 23, 42, 0.06)',
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
fontSize: 11.5,
whiteSpace: 'pre-wrap',
wordBreak: 'break-all',
maxHeight: 100,
overflowY: 'auto',
},
}, cleanDisplayText(item.inputSummary || JSON.stringify(item.rawInput, null, 2))),
showDenyInput && h('input', {
type: 'text',
value: denyReason,
onChange: e => setDenyReason(e.target.value),
placeholder: '输入拒绝原因或替代指令(将直接反馈给 Bot)…',
style: S.input,
}),
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
h('button', {
type: 'button',
'data-testid': 'qoder-approve-allow-btn',
disabled: busy,
onClick: () => decide('allow'),
style: {
padding: '6px 14px',
borderRadius: 8,
border: 'none',
background: '#059669',
color: '#fff',
fontWeight: 600,
fontSize: 12,
cursor: busy ? 'wait' : 'pointer',
},
}, busy ? '处理中…' : '✓ 批准并继续执行'),
!showDenyInput
? h('button', {
type: 'button',
disabled: busy,
onClick: () => setShowDenyInput(true),
style: S.btnDanger(busy),
}, '✕ 拒绝操作…')
: h('button', {
type: 'button',
'data-testid': 'qoder-approve-deny-btn',
disabled: busy,
onClick: () => decide('deny'),
style: S.btnDanger(busy),
}, '确认拒绝并反馈'),
))
}
// --- Step Pill inside Bot Message Stream (Tool / Browser / Sub-Worker Thread / Artifact) ---
function StepChain({ steps }) {
const [expanded, setExpanded] = React.useState(true)
if (!steps || steps.length === 0) return null
const iconOf = (k) => {
if (k === 'browser') return '🌐'
if (k === 'bash') return '💻'
if (k === 'file') return '📄'
if (k === 'thread') return '🧵'
if (k === 'artifact') return '📸'
if (k === 'approval') return '🛡️'
if (k === 'thinking') return '💭'
return '🔧'
}
return h('div', {
'data-testid': 'bot-message-steps',
style: {
borderRadius: 10,
border: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.18))',
background: 'rgba(148, 163, 184, 0.05)',
padding: '7px 10px',
display: 'flex',
flexDirection: 'column',
gap: 5,
},
},
h('div', {
onClick: () => setExpanded(!expanded),
style: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
cursor: 'pointer',
fontSize: 11.5,
fontWeight: 600,
color: 'var(--dsw-alias-label-secondary, #64748b)',
},
},
h('span', null, '⚡ 自主执行轨迹 · ' + steps.length + ' 步操作'),
h('span', { style: { fontSize: 11, opacity: 0.75 } }, expanded ? '收起 ▴' : '展开 ▾')),
expanded && h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, marginTop: 2 } },
steps.slice(-10).map(st => h('div', {
key: st.id,
style: {
display: 'flex',
alignItems: 'baseline',
gap: 6,
fontSize: 11.5,
lineHeight: '17px',
color: st.kind === 'thread'
? '#6d28d9'
: st.kind === 'approval'
? '#b45309'
: 'var(--dsw-alias-label-primary, inherit)',
},
},
h('span', { style: { flexShrink: 0 } }, iconOf(st.kind)),
h('span', { style: { fontWeight: 600, flexShrink: 0 } }, cleanDisplayText(st.title)),
st.detail && h('span', {
style: {
fontSize: 11,
opacity: 0.72,
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
minWidth: 0,
},
}, cleanDisplayText(st.detail)))),
))
}
// =========================================================================
// STANDALONE 3-PANE SUPER-AGENT / BOT OS WORKSPACE (`BotsStudioApp`)
// =========================================================================
function BotsStudioApp() {
const [dash, setDash] = React.useState(null)
const [loadingDash, setLoadingDash] = React.useState(true)
const [selectedBotId, setSelectedBotId] = React.useState('')
const [adoptedSessionId, setAdoptedSessionId] = React.useState(null)
const [centerTab, setCenterTab] = React.useState('workspace') // 'workspace' | 'inbox' | 'memory' | 'routines'
const [rightTab, setRightTab] = React.useState('desktop') // 'desktop' | 'workers' | 'artifacts'
const [compState, setCompState] = React.useState(null)
const [composerText, setComposerText] = React.useState('')
const [sending, setSending] = React.useState(false)
const [banner, setBanner] = React.useState(null)
// Modals
const [createModalOpen, setCreateModalOpen] = React.useState(false)
const [teamModalOpen, setTeamModalOpen] = React.useState(false)
const [editingBot, setEditingBot] = React.useState(null)
// Create Bot Form
const [tplId, setTplId] = React.useState('web-operator')
const [newBotName, setNewBotName] = React.useState('')
const [newBotDesc, setNewBotDesc] = React.useState('')
const [newApproval, setNewApproval] = React.useState('auto')
const [newBrowser, setNewBrowser] = React.useState(true)
const [newSkillIds, setNewSkillIds] = React.useState([])
const [newVaultIds, setNewVaultIds] = React.useState([])
const [creating, setCreating] = React.useState(false)
// Create Super-Agent Team Form
const [teamName, setTeamName] = React.useState('')
const [teamDesc, setTeamDesc] = React.useState('')
const [teamMembers, setTeamMembers] = React.useState(['code-reviewer', 'deep-researcher'])
const [creatingTeam, setCreatingTeam] = React.useState(false)
// Proactive Inbox State
const [expandedRunId, setExpandedRunId] = React.useState(null)
const [runReports, setRunReports] = React.useState({})
const [loadingRunId, setLoadingRunId] = React.useState(null)
// Memory & Dream State
const [memList, setMemList] = React.useState([])
const [memStore, setMemStore] = React.useState(null)
const [selectedMemPath, setSelectedMemPath] = React.useState('')
const [memContent, setMemContent] = React.useState('')
const [memBusy, setMemBusy] = React.useState(false)
const [newFileMode, setNewFileMode] = React.useState(false)
const [newFilePath, setNewFilePath] = React.useState('')
// Routine State
const [rtName, setRtName] = React.useState('')
const [rtPreset, setRtPreset] = React.useState('0 9 * * 1-5')
const [rtCustomCron, setRtCustomCron] = React.useState('0 9 * * 1-5')
const [rtPrompt, setRtPrompt] = React.useState('')
const [rtBusy, setRtBusy] = React.useState(false)
const streamEndRef = React.useRef(null)
const notify = (type, text) => {
setBanner({ type, text })
if (type === 'ok') {
setTimeout(() => {
setBanner(prev => (prev && prev.text === text ? null : prev))
}, 5000)
}
}
const loadDashboard = React.useCallback(async (silent) => {
if (!silent) setLoadingDash(true)
try {
const d = await apiGet('/dashboard')
setDash(d)
if (d.bots && d.bots.length > 0) {
setSelectedBotId((prev) => {
if (prev && d.bots.some(b => b.id === prev)) return prev
const active = d.activeSelection && d.activeSelection.botId
if (active && d.bots.some(b => b.id === active)) return active
// Prefer web-scout or team if present, else first bot
const preferred = d.bots.find(b => b.browserEnabled && !b.isTeam) || d.bots[0]
return preferred.id
})
}
} catch (err) {
if (!silent) notify('err', String(err.message || err))
} finally {
if (!silent) setLoadingDash(false)
}
}, [])
const pollWorkspace = React.useCallback(async () => {
if (!selectedBotId) return
try {
const params = { botId: selectedBotId }
if (adoptedSessionId) params.remoteSessionId = adoptedSessionId
const data = await apiGet('/computer', params)
setCompState(data)
} catch {
// Ignore transient poll errors
}
}, [selectedBotId, adoptedSessionId])
React.useEffect(() => {
void loadDashboard(false)
const t = setInterval(() => { void loadDashboard(true) }, 5000)
return () => clearInterval(t)
}, [loadDashboard])
React.useEffect(() => {
if (!selectedBotId) return
void pollWorkspace()
const t = setInterval(() => { void pollWorkspace() }, 1800)
return () => clearInterval(t)
}, [pollWorkspace, selectedBotId])
const loadMemoriesForBot = React.useCallback(async (targetBotId) => {
if (!targetBotId) return
setMemBusy(true)
try {
const res = await apiAction('inspectMemories', { botId: targetBotId })
const entries = res.entries || []
setMemList(entries)
setMemStore(res.store || null)
if (entries.length > 0) {
const pick = entries.find(e => e.path === selectedMemPath) || entries[0]
setSelectedMemPath(pick.path)
if (pick.content !== undefined) {
setMemContent(pick.content)
} else if (res.store && res.store.id) {
const full = await apiAction('readMemory', { memoryStoreId: res.store.id, memoryId: pick.id })
setMemContent((full.entry && full.entry.content) || '')
}
} else {
setSelectedMemPath('')
setMemContent('')
}
} catch (err) {
notify('err', '读取记忆失败:' + String(err.message || err))
} finally {
setMemBusy(false)
}
}, [selectedMemPath])
React.useEffect(() => {
if (centerTab === 'memory' && selectedBotId) {
void loadMemoriesForBot(selectedBotId)
}
}, [centerTab, selectedBotId])
const bots = (dash && dash.bots) || []
const templates = (dash && dash.templates) || []
const environments = (dash && dash.environments) || []
const routines = (dash && dash.routines) || []
const inboxRuns = (dash && dash.inboxRuns) || []
const allPendingApprovals = (dash && dash.pendingApprovals) || []
const liveComputers = (dash && dash.liveComputers) || []
const skills = (dash && dash.skills) || []
const vaults = (dash && dash.vaults) || []
const activeEnvId = dash && dash.activeSelection ? dash.activeSelection.environmentId : undefined
const activeBot = bots.find(b => b.id === selectedBotId) || (compState && compState.bot) || null
const comp = compState && compState.computer
const remoteSessionId = (compState && compState.remoteSessionId) || (activeBot && activeBot.primarySessionId) || null
const takeoverUrl = compState && compState.takeoverUrl
const messages = (compState && compState.messages) || []
const threads = (compState && compState.threads) || []
const botApprovals = (compState && compState.pendingApprovals) || []
const artifacts = (comp && comp.artifacts) || []
const activities = (comp && comp.activities) || []
const latestFrame = comp && comp.latestBrowserFrame
const status = (comp && comp.status) || (compState && compState.remoteSession && compState.remoteSession.status) || 'idle'
const isBotBusy = status === 'running' || sending
const selectBot = async (bot) => {
setSelectedBotId(bot.id)
setAdoptedSessionId(null)
setCenterTab('workspace')
apiAction('selectBot', { botId: bot.id }).catch(() => {})
}
const handleSendObjective = async (rawOverride) => {
if (!activeBot) return
const text = (typeof rawOverride === 'string' ? rawOverride : composerText).trim()
if (!text || sending) return
if (typeof rawOverride !== 'string') setComposerText('')
setSending(true)
try {
await apiAction('sendBotMessage', {
botId: activeBot.id,
text,
remoteSessionId: adoptedSessionId || undefined,
})
await pollWorkspace()
setTimeout(() => {
if (streamEndRef.current && streamEndRef.current.scrollIntoView) {
streamEndRef.current.scrollIntoView({ behavior: 'smooth', block: 'end' })
}
}, 80)
} catch (err) {
notify('err', '发送指令失败:' + String(err.message || err))
} finally {
setSending(false)
}
}
const handleInterrupt = async () => {
if (!remoteSessionId) return
try {
await apiAction('interruptBotTurn', { remoteSessionId })
notify('ok', '已暂停当前执行轮次,常驻云电脑保持在线。')
await pollWorkspace()
} catch (err) {
notify('err', String(err.message || err))
}
}
const handleDecideApproval = async (item, decision, denyMessage) => {
try {
await apiAction('decideApproval', {
toolUseId: item.toolUseId,
remoteSessionId: item.remoteSessionId,
decision,
denyMessage,
})
notify('ok', decision === 'allow' ? '✓ 已批准操作,Bot 继续在云电脑自主推进。' : '✕ 已拒绝该操作并向 Bot 反馈原因。')
await Promise.all([loadDashboard(true), pollWorkspace()])
} catch (err) {
notify('err', String(err.message || err))
}
}
const handleCreateBot = async (e) => {
e.preventDefault()
setCreating(true)
try {
const res = await apiAction('createBot', {
templateId: tplId,
name: newBotName.trim() || undefined,
description: newBotDesc.trim() || undefined,
defaultRuntime: 'cloud',
approvalMode: newApproval,
browserEnabled: newBrowser,
skillIds: newSkillIds,
vaultIds: newVaultIds,
})
setCreateModalOpen(false)
setNewBotName('')
setNewBotDesc('')
setSelectedBotId(res.bot.id)
setAdoptedSessionId(null)
setCenterTab('workspace')
notify('ok', '已创建专属 Bot ' + res.bot.avatar + ' ' + res.bot.name + '(已挂载 Qoder Cloud 常驻云电脑与持久记忆库)!')
await loadDashboard(true)
} catch (err) {
notify('err', '创建失败:' + String(err.message || err))
} finally {
setCreating(false)
}
}
const handleCreateTeam = async (e) => {
e.preventDefault()
if (!teamName.trim() || teamMembers.length === 0) return
setCreatingTeam(true)
try {
const res = await apiAction('createTeam', {
name: teamName.trim(),
description: teamDesc.trim() || undefined,
members: teamMembers,
})
setTeamModalOpen(false)
setTeamName('')
setTeamDesc('')
setSelectedBotId(res.team.id)
setAdoptedSessionId(null)
setCenterTab('workspace')
notify('ok', '已组建 Super Agent 协同组 👥 ' + res.team.name + '(Router 主控 + ' + res.members.length + ' 个专业子 Bot)!')
await loadDashboard(true)
} catch (err) {
notify('err', '组建失败:' + String(err.message || err))
} finally {
setCreatingTeam(false)
}
}
const attentionCount = allPendingApprovals.length + inboxRuns.length
// Starter quick-delegation prompts tailored to active Bot role
const starterPrompts = activeBot && activeBot.isTeam
? [
'作为主控 Router 并行调度子 Bot:审查认证模块并发安全,同时整理最新云沙箱架构简报',
'向各专业 Worker 分发代码健康度巡检任务,汇总高优先级风险并写入长期记忆',
]
: activeBot && activeBot.browserEnabled
? [
'打开 https://example.com 巡检页面标题与核心正文,截图同步到右侧云电脑屏幕并一句话汇报',
'访问目标站点验证可访问性,把关键观察记录写入长期记忆库 README.md',
]
: [
'检查当前云电脑工具链环境与挂载的长期记忆文件,并用一句话汇报就绪状态',
'为我创建一个工作日每天 09:00 自动执行的云端巡检定时任务',
]
return h('div', {
'data-testid': 'qoder-bots-studio-page',
style: {
width: '100%',
height: '100%',
display: 'flex',
overflow: 'hidden',
background: 'var(--dsw-alias-bg-base, #f8fafc)',
color: 'var(--dsw-alias-label-primary, #0f172a)',
boxSizing: 'border-box',
},
},
// =======================================================================
// PANE 1 (LEFT RAIL): Super-Agent Bot Roster & Proactive Attention Triage
// =======================================================================
h('aside', {
'data-testid': 'qoder-bots-left-roster',
style: {
width: 286,
flexShrink: 0,
height: '100%',
display: 'flex',
flexDirection: 'column',
borderRight: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.18))',
background: 'var(--dsw-alias-bg-layer-1, rgba(248, 250, 252, 0.75))',
boxSizing: 'border-box',
},
},
// Left Header
h('div', {
style: {
padding: '16px 14px 12px',
borderBottom: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.14))',
display: 'flex',
flexDirection: 'column',
gap: 10,
},
},
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 } },
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
h('span', {
style: {
width: 28,
height: 28,
borderRadius: 8,
background: 'linear-gradient(135deg, #4176E6 0%, #0D9488 100%)',
color: '#fff',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 15,
boxShadow: '0 3px 10px rgba(65,118,230,0.24)',
},
}, '🤖'),
h('div', { style: { minWidth: 0 } },
h('div', { style: { fontWeight: 700, fontSize: 15, letterSpacing: '-0.01em' } }, 'Bots'),
h('div', { style: { fontSize: 10, opacity: 0.65, whiteSpace: 'nowrap' } }, 'Super Agent · Qoder'),
),
),
h('div', { style: { display: 'flex', gap: 5, flexShrink: 0 } },
h('button', {
type: 'button',
'data-testid': 'qoder-open-team-modal-btn',
title: '组建 Router + Workers 多智能体协同组',
onClick: () => setTeamModalOpen(true),
style: Object.assign({}, S.btnSecondary(false, false), { padding: '5px 8px', fontSize: 11.5, whiteSpace: 'nowrap' }),
}, '👥 Team'),
h('button', {
type: 'button',
'data-testid': 'qoder-open-create-modal-btn',
title: '新建常驻云电脑 Bot',
onClick: () => setCreateModalOpen(true),
style: Object.assign({}, S.btnPrimary(false), { padding: '5px 10px', fontSize: 11.5, whiteSpace: 'nowrap' }),
}, '+ 新建'),
),
),
// Attention Triage Shortcut (DeepSeek Super Agent's Attention Bottleneck Solver!)
h('button', {
type: 'button',
'data-testid': 'qoder-triage-inbox-btn',
onClick: () => setCenterTab(centerTab === 'inbox' ? 'workspace' : 'inbox'),
style: {
width: '100%',
padding: '8px 10px',
borderRadius: 10,
border: allPendingApprovals.length > 0
? '1.5px solid rgba(245, 158, 11, 0.55)'
: (centerTab === 'inbox' ? '1px solid rgba(65,118,230,0.45)' : '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.20))'),
background: allPendingApprovals.length > 0
? 'rgba(245, 158, 11, 0.10)'
: (centerTab === 'inbox' ? 'rgba(65,118,230,0.10)' : 'var(--dsw-alias-bg-elevated, #ffffff)'),
color: 'inherit',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
fontSize: 12,
fontWeight: 600,
},
},
h('span', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
h('span', null, allPendingApprovals.length > 0 ? '🛡️' : '📬'),
h('span', null, allPendingApprovals.length > 0 ? '待你决策审批' : '主动汇报收件箱'),
),
attentionCount > 0
? h('span', { style: S.pill(allPendingApprovals.length > 0 ? 'amber' : 'blue') }, String(attentionCount))
: h('span', { style: { fontSize: 11, opacity: 0.5, fontWeight: 400 } }, '清零'))),
// Bot Roster List
h('div', {
style: {
flex: 1,
overflowY: 'auto',
padding: '10px 10px 14px',
display: 'flex',
flexDirection: 'column',
gap: 6,
},
},
h('div', { style: { fontSize: 11, fontWeight: 600, opacity: 0.55, padding: '2px 6px 4px', display: 'flex', justifyContent: 'space-between' } },
h('span', null, '常驻云电脑 BOTS (' + bots.length + ')'),
h('span', null, '独立运行'),
),
bots.length === 0 && !loadingDash && h('div', {
style: { padding: '24px 12px', textAlign: 'center', fontSize: 12, opacity: 0.68 },
}, '点击右上角「+ 新建」创建你的第一个常驻云电脑 Bot'),
bots.map((bot) => {
const selected = bot.id === (activeBot && activeBot.id) && centerTab !== 'inbox'
const live = liveComputers.find(c => c.botId === bot.id || (bot.primarySessionId && c.remoteSessionId === bot.primarySessionId))
const st = live ? live.status : (bot.primarySessionId ? 'online' : 'standby')
return h('div', {
key: bot.id,
'data-testid': 'qoder-bot-card-' + bot.name,
onClick: () => selectBot(bot),
style: {
padding: '10px 11px',
borderRadius: 11,
cursor: 'pointer',
border: selected
? '1.5px solid rgba(65, 118, 230, 0.55)'
: (st === 'needs_approval' ? '1.5px solid rgba(245, 158, 11, 0.55)' : '1px solid transparent'),
background: selected
? 'rgba(65, 118, 230, 0.10)'
: 'var(--dsw-alias-bg-elevated, rgba(255,255,255,0.65))',
display: 'flex',
flexDirection: 'column',
gap: 6,
transition: 'all 0.14s ease',
},
},
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 6 } },
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } },
h('span', {
style: {
width: 30,
height: 30,
borderRadius: 9,
background: bot.isTeam ? 'rgba(139,92,246,0.14)' : 'rgba(65,118,230,0.11)',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: 16,
flexShrink: 0,
},
}, bot.avatar || '🤖'),
h('div', { style: { minWidth: 0 } },
h('div', {
style: {
fontWeight: selected ? 700 : 600,
fontSize: 13,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
}, bot.name),
h('div', { style: { fontSize: 10.5, opacity: 0.62, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
bot.isTeam
? ('Router + ' + ((bot.teamMemberIds && bot.teamMemberIds.length) || 2) + ' Workers')
: (bot.browserEnabled ? '云电脑 · 实时 Chrome' : '云电脑 · 持久记忆'),
),
),
),
st === 'needs_approval'
? h('span', { style: S.pill('amber') }, '待审批')
: st === 'running'
? h('span', { style: S.pill('green') }, '⚡ 运行')
: h('span', {
style: {
width: 8,
height: 8,
borderRadius: '50%',
background: st === 'online' ? '#10b981' : '#94a3b8',
flexShrink: 0,
},
title: st === 'online' ? '常驻云电脑在线' : '按需唤醒',
}),
))
})),
// Environment / Cloud Computer Footer inside Left Rail
environments.length > 0 && h('div', {
style: {
padding: '10px 12px',
borderTop: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.14))',
display: 'flex',
flexDirection: 'column',
gap: 5,
},
},
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 6 } },
h('div', { style: { fontSize: 10.5, opacity: 0.65, fontWeight: 600 } }, '🖥️ QODER 云电脑底座'),
h('button', {
type: 'button',
'data-testid': 'qoder-provision-cloud-computer-btn',
title: '开通一台新的 Qoder Cloud 持久化云电脑 (runtime_mode=shared)',
onClick: async () => {
try {
const res = await apiAction('provisionCloudComputer', {
name: 'dsh-cloud-computer-' + Math.random().toString(36).slice(2, 6),
idleTimeoutSeconds: 3600,
})
notify('ok', '🖥️ 已开通持久化云电脑 ' + res.environment.name + ' (' + res.environment.id + ') · runtime_mode=shared!')
await Promise.all([loadDashboard(true), pollWorkspace()])
} catch (err) {
notify('err', '开通云电脑失败:' + String(err.message || err))
}
},
style: {
border: '1px solid rgba(65,118,230,0.32)',
background: 'rgba(65,118,230,0.08)',
color: '#2b63d9',
borderRadius: 6,
padding: '2px 7px',
fontSize: 10.5,
fontWeight: 600,
cursor: 'pointer',
},
}, '+ 云电脑'),
),
h('select', {
value: activeEnvId || (environments[0] && environments[0].id) || '',
onChange: async (e) => {
await apiAction('selectEnv', { environmentId: e.target.value }).catch(err => notify('err', err.message))
await Promise.all([loadDashboard(true), pollWorkspace()])
},
style: Object.assign({}, S.input, { padding: '5px 8px', fontSize: 11.5 }),
}, environments.map(env => {
const isShared = env && env.config && env.config.runtime_mode === 'shared'
return h('option', { key: env.id, value: env.id }, (isShared ? '🖥️ ' : '☁️ ') + env.name + (isShared ? ' · 持久云电脑' : ' · 会话沙箱'))
})))),
// =======================================================================
// PANE 2 (CENTER): Standalone Bot Objective Stream / Inbox / Memory / Cron
// =======================================================================
h('main', {
'data-testid': 'qoder-bots-center-stream',
style: {
flex: 1,
minWidth: 0,
height: '100%',
display: 'flex',
flexDirection: 'column',
background: 'var(--dsw-alias-bg-base, #ffffff)',
},
},
// Center Top Header Bar
h('header', {
style: {
padding: '12px 20px',
borderBottom: '1px solid var(--dsw-alias-line-primary, rgba(128,138,158,0.16))',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 12,
flexWrap: 'wrap',
},
},
activeBot
? h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, minWidth: 0 } },
h('span', { style: { fontSize: 22 } }, activeBot.avatar || '🤖'),
h('div', { style: { minWidth: 0 } },
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
h('span', { style: { fontWeight: 700, fontSize: 15.5 } }, activeBot.name),
activeBot.isTeam
? h('span', { style: S.pill('purple') }, '👥 Super Agent Router + Workers')
: h('span', { style: S.pill('blue') }, '🖥️ 独立常驻云电脑'),
activeBot.approvalMode === 'gated' && h('span', { style: S.pill('amber') }, '🛡️ 关键操作审批'),
adoptedSessionId && h('span', { style: S.pill('teal') }, '📬 巡检会话接续中'),
),
h('div', { style: { fontSize: 11.5, opacity: 0.66, marginTop: 2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
cleanDisplayText(activeBot.description) || '独立于普通聊天列表运行 · 后台自主推进任务、持久记忆沉淀并在关键节点请求人类决策',
),
),
)
: h('div', { style: { fontWeight: 600, fontSize: 15 } }, 'Bots · Super Agent 独立工作台'),
// Center Mode Sub-Tabs + Settings
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
[
{ id: 'workspace', label: '💬 目标委派 & 执行流' },
{ id: 'inbox', label: '📬 主动汇报' + (attentionCount > 0 ? ' (' + attentionCount + ')' : '') },
{ id: 'memory', label: '🧠 持久记忆 & Dream' },
{ id: 'routines', label: '⏰ 7×24 巡检' + (routines.length > 0 ? ' (' + routines.length + ')' : '') },
].map(tabItem => h('button', {
key: tabItem.id,
type: 'button',
'data-testid': 'qoder-studio-tab-' + tabItem.id,
onClick: () => setCenterTab(tabItem.id),
style: S.btnSecondary(centerTab === tabItem.id, false),
}, tabItem.label)),
activeBot && h('button', {
type: 'button',
'data-testid': 'qoder-config-bot-btn-' + activeBot.name,
title: '配置 Bot 权限门禁 / 重置云电脑实例',
onClick: () => setEditingBot(activeBot),
style: S.btnSecondary(false, false),
}, '⚙️')),
),
// Optional Status / Error Banner
dash && dash.configured === false && h('div', {
style: {
margin: '12px 20px 0',
padding: '12px 16px',
borderRadius: 10,
border: '1px solid rgba(245, 158, 11, 0.4)',
background: 'rgba(245, 158, 11, 0.08)',
fontSize: 12.5,