@hyprnos/dsh-remote-plugin 0.0.0-stage → 0.8.8
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.en.md +61 -0
- package/README.md +60 -2
- package/apk/dsh-remote.apk +0 -0
- package/approval-summary.mjs +115 -0
- package/client.js +197 -0
- package/cordis.patch.yml +5 -0
- package/doctor-skill.mjs +99 -0
- package/doctor-target.mjs +24 -0
- package/file-delivery.mjs +84 -0
- package/gateway-stats.cjs +501 -0
- package/gateway.cjs +8451 -0
- package/index.mjs +1784 -0
- package/insights.mjs +111 -0
- package/market.mjs +86 -0
- package/package.json +71 -4
- package/peak-reminders.mjs +50 -0
- package/plugin-center.mjs +777 -0
- package/plugin-transaction.mjs +300 -0
- package/public/activity.js +188 -0
- package/public/admin.html +820 -0
- package/public/admin.js +1167 -0
- package/public/announcement-forms.js +89 -0
- package/public/announcements.json +464 -0
- package/public/app.js +8826 -0
- package/public/approval-records.js +301 -0
- package/public/approval-summary.js +78 -0
- package/public/build.json +5 -0
- package/public/cache-upgrade.js +51 -0
- package/public/chat-copy.js +59 -0
- package/public/chat-files.js +87 -0
- package/public/desktop/desktop.css +816 -0
- package/public/desktop/desktop.html +871 -0
- package/public/desktop/desktop.js +4548 -0
- package/public/desktop/i18n.js +85 -0
- package/public/diagnostics.js +203 -0
- package/public/doctor-entry.js +94 -0
- package/public/doctor.css +205 -0
- package/public/doctor.js +769 -0
- package/public/donate.png +0 -0
- package/public/e2ee-transport.js +219 -0
- package/public/extensions.css +109 -0
- package/public/extensions.js +215 -0
- package/public/file-inbox.css +66 -0
- package/public/file-inbox.js +289 -0
- package/public/genui.css +8 -0
- package/public/genui.js +254 -0
- package/public/history.js +304 -0
- package/public/i18n.js +57 -0
- package/public/icon.svg +12 -0
- package/public/image-cache.js +141 -0
- package/public/image-preview.js +290 -0
- package/public/index.html +1548 -0
- package/public/insights.css +28 -0
- package/public/insights.js +290 -0
- package/public/jsqr.min.js +10104 -0
- package/public/lan-discovery.js +94 -0
- package/public/link-check.js +109 -0
- package/public/manifest.webmanifest +16 -0
- package/public/md.js +333 -0
- package/public/morphicons-init.js +41 -0
- package/public/motion.js +557 -0
- package/public/network.js +100 -0
- package/public/onboarding.css +36 -0
- package/public/onboarding.js +253 -0
- package/public/operations.js +141 -0
- package/public/permission-presets.js +159 -0
- package/public/plugin-center.css +120 -0
- package/public/plugin-center.js +666 -0
- package/public/plugin-icon.svg +5 -0
- package/public/plugin.html +68 -0
- package/public/plugin.js +211 -0
- package/public/qrcode.min.js +2297 -0
- package/public/relay-autopair.js +251 -0
- package/public/relay-devices.js +80 -0
- package/public/relay-settings.css +24 -0
- package/public/relay-settings.js +194 -0
- package/public/remote-state.js +27 -0
- package/public/remote-ui.css +148 -0
- package/public/remote-ui.js +243 -0
- package/public/session-deck.css +79 -0
- package/public/session-deck.js +180 -0
- package/public/session-presets.js +47 -0
- package/public/setup.css +18 -0
- package/public/setup.js +213 -0
- package/public/sha256.js +119 -0
- package/public/skills.css +81 -0
- package/public/skills.js +202 -0
- package/public/skins/blue-fish/DESIGN.md +24 -0
- package/public/skins/blue-fish/face.png +0 -0
- package/public/skins/blue-fish/icon-blush.png +0 -0
- package/public/skins/blue-fish/icon-sleep.png +0 -0
- package/public/skins/blue-fish/icon-smile.png +0 -0
- package/public/skins/blue-fish/icon-star.png +0 -0
- package/public/skins/blue-fish/icon-wink.png +0 -0
- package/public/skins/blue-fish/icon.png +0 -0
- package/public/skins/blue-fish/mascot.png +0 -0
- package/public/skins/blue-fish/pattern.png +0 -0
- package/public/skins/blue-fish/preview.html +12 -0
- package/public/skins/blue-fish/skin.css +122 -0
- package/public/skins/blue-fish/sparkles.svg +18 -0
- package/public/skins/bocchi/DESIGN.md +99 -0
- package/public/skins/bocchi/face.png +0 -0
- package/public/skins/bocchi/grain.png +0 -0
- package/public/skins/bocchi/icon-blush.png +0 -0
- package/public/skins/bocchi/icon-sleep.png +0 -0
- package/public/skins/bocchi/icon-smile.png +0 -0
- package/public/skins/bocchi/icon-star.png +0 -0
- package/public/skins/bocchi/icon-wink.png +0 -0
- package/public/skins/bocchi/icon.png +0 -0
- package/public/skins/bocchi/pattern-soft.png +0 -0
- package/public/skins/bocchi/pattern.png +0 -0
- package/public/skins/bocchi/preview.html +55 -0
- package/public/skins/bocchi/skin.css +233 -0
- package/public/skins/bocchi/stage-bg.png +0 -0
- package/public/skins/bocchi/stage-soft.png +0 -0
- package/public/skins/bocchi/stand.png +0 -0
- package/public/skins/bocchi/sticker-guitar.png +0 -0
- package/public/skins/kessoku/DESIGN.md +38 -0
- package/public/skins/kessoku/grain.png +0 -0
- package/public/skins/kessoku/skin.css +212 -0
- package/public/skins/kita/SOURCES.json +51 -0
- package/public/skins/kita/face.png +0 -0
- package/public/skins/kita/icon-live.png +0 -0
- package/public/skins/kita/icon-reddress.png +0 -0
- package/public/skins/kita/icon-seifuku.png +0 -0
- package/public/skins/kita/pattern.png +0 -0
- package/public/skins/kita/preview.html +56 -0
- package/public/skins/kita/skin.css +26 -0
- package/public/skins/kita/stand.png +0 -0
- package/public/skins/kita/sticker-live.png +0 -0
- package/public/skins/nijika/SOURCES.json +51 -0
- package/public/skins/nijika/face.png +0 -0
- package/public/skins/nijika/icon-live.png +0 -0
- package/public/skins/nijika/icon-reddress.png +0 -0
- package/public/skins/nijika/icon-seifuku.png +0 -0
- package/public/skins/nijika/pattern.png +0 -0
- package/public/skins/nijika/preview.html +56 -0
- package/public/skins/nijika/skin.css +25 -0
- package/public/skins/nijika/stand.png +0 -0
- package/public/skins/nijika/sticker-live.png +0 -0
- package/public/skins/penguin/DESIGN.md +33 -0
- package/public/skins/penguin/SOURCES.json +22 -0
- package/public/skins/penguin/aic-blueprint.svg +24 -0
- package/public/skins/penguin/endfield-triangles.svg +4 -0
- package/public/skins/penguin/face.png +0 -0
- package/public/skins/penguin/icon-blush.png +0 -0
- package/public/skins/penguin/icon-dizzy.png +0 -0
- package/public/skins/penguin/icon-laugh.png +0 -0
- package/public/skins/penguin/icon-sleep.png +0 -0
- package/public/skins/penguin/icon-smile.png +0 -0
- package/public/skins/penguin/icon-star.png +0 -0
- package/public/skins/penguin/icon-wink.png +0 -0
- package/public/skins/penguin/icon.png +0 -0
- package/public/skins/penguin/mascot.png +0 -0
- package/public/skins/penguin/pattern-night.png +0 -0
- package/public/skins/penguin/pattern.png +0 -0
- package/public/skins/penguin/preview.html +12 -0
- package/public/skins/penguin/skin.css +212 -0
- package/public/skins/ryo/SOURCES.json +51 -0
- package/public/skins/ryo/face.png +0 -0
- package/public/skins/ryo/icon-live.png +0 -0
- package/public/skins/ryo/icon-reddress.png +0 -0
- package/public/skins/ryo/icon-seifuku.png +0 -0
- package/public/skins/ryo/pattern.png +0 -0
- package/public/skins/ryo/preview.html +56 -0
- package/public/skins/ryo/skin.css +25 -0
- package/public/skins/ryo/stand.png +0 -0
- package/public/skins/ryo/sticker-live.png +0 -0
- package/public/sponsor-entry.js +21 -0
- package/public/styles.css +1494 -0
- package/public/subagents.css +61 -0
- package/public/subagents.js +275 -0
- package/public/task-board.js +109 -0
- package/public/teams.js +98 -0
- package/public/theme-picker.css +58 -0
- package/public/theme-vars.css +1044 -0
- package/public/theme.js +166 -0
- package/public/transcribe-core.js +74 -0
- package/public/turn-results.js +121 -0
- package/public/update.json +49 -0
- package/public/vendor/gsap/NOTICE.md +10 -0
- package/public/vendor/gsap/gsap.min.js +11 -0
- package/public/vendor/morphicons/LICENSE +21 -0
- package/public/vendor/morphicons/README.md +10 -0
- package/public/vendor/morphicons/controller-CXZuwJ_M.js +152 -0
- package/public/vendor/morphicons/dom.js +206 -0
- package/public/vendor/morphicons/element.js +261 -0
- package/public/vendor/morphicons/normalize-CYnN3Npw.js +540 -0
- package/public/vendor/morphicons/spring-CFHloqPP.js +623 -0
- package/public/version.json +3 -0
- package/public/voice-input.js +739 -0
- package/public/workflow.css +365 -0
- package/public/workflow.js +409 -0
- package/session-file.mjs +39 -0
- package/skills/dsh-remote-doctor/SKILL.md +186 -0
- package/skills/dsh-remote-doctor/references/wiki/README.md +40 -0
- package/skills/dsh-remote-doctor/references/wiki/ai-guide.md +61 -0
- package/skills/dsh-remote-doctor/references/wiki/connection.md +76 -0
- package/skills/dsh-remote-doctor/references/wiki/errors.md +26 -0
- package/skills/dsh-remote-doctor/references/wiki/evidence.md +44 -0
- package/skills/dsh-remote-doctor/references/wiki/files.md +31 -0
- package/skills/dsh-remote-doctor/references/wiki/maintenance.md +30 -0
- package/skills/dsh-remote-doctor/references/wiki/notifications.md +33 -0
- package/skills/dsh-remote-doctor/references/wiki/operations.md +32 -0
- package/skills/dsh-remote-doctor/references/wiki/plugins.md +90 -0
- package/skills/dsh-remote-doctor/references/wiki/sessions.md +45 -0
- package/skills/dsh-remote-doctor/references/wiki/sources.md +27 -0
- package/skills.mjs +53 -0
- package/task-board.mjs +57 -0
- package/teams.mjs +58 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
.subagent-page{position:fixed;inset:0;box-sizing:border-box;width:100%;height:100%;height:100dvh;max-width:none;max-height:none;margin:0;padding:0;border:0;border-radius:0;background:var(--dsr-bg);color:var(--dsr-text);overflow:hidden}
|
|
2
|
+
.subagent-page[open]{display:flex;flex-direction:column}.subagent-page::backdrop{background:var(--dsr-bg)}
|
|
3
|
+
.subagent-page-head{flex:none;display:flex;align-items:center;gap:22px;padding:max(16px,var(--dsr-safe-top,0px)) max(24px,env(safe-area-inset-right)) 16px max(24px,env(safe-area-inset-left));border-bottom:1px solid var(--dsr-line);background:var(--dsr-panel)}
|
|
4
|
+
.subagent-page-heading{min-width:0}.subagent-page-head h2{margin:5px 0 0;font-size:19px;font-weight:650;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
5
|
+
.subagent-page-back,.subtree button{font:inherit;cursor:pointer;color:inherit}
|
|
6
|
+
.subagent-page-back{flex:none;min-height:44px;border:1px solid var(--dsr-line);border-radius:10px;background:var(--dsr-bg-2);padding:8px 13px;font-size:13px}
|
|
7
|
+
.subagent-page-content{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:24px max(24px,env(safe-area-inset-right)) max(24px,var(--dsr-safe-b,0px)) max(24px,env(safe-area-inset-left))}
|
|
8
|
+
.subtree{max-width:1280px;margin-inline:auto;font-size:13px;line-height:1.5}
|
|
9
|
+
.subtree-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:12px}
|
|
10
|
+
.subtree-search{flex:1 1 240px;min-width:0;max-width:400px;box-sizing:border-box;min-height:44px;border:1px solid var(--dsr-line);border-radius:10px;padding:10px 13px;background:var(--dsr-panel);color:var(--dsr-text);font:inherit;font-size:14px}
|
|
11
|
+
.subtree-search::placeholder{color:var(--dsr-muted)}
|
|
12
|
+
.subtree-filters{display:flex;gap:3px;padding:3px;border:1px solid var(--dsr-line);border-radius:11px;background:var(--dsr-bg-2)}
|
|
13
|
+
.subtree-filters button{min-height:38px;border:0;border-radius:7px;background:transparent;padding:7px 12px;color:var(--dsr-muted);font-size:12px}
|
|
14
|
+
.subtree-filters button[aria-pressed=true]{background:var(--dsr-accent-soft);color:var(--dsr-accent-strong);box-shadow:inset 0 0 0 1px var(--dsr-accent-line)}
|
|
15
|
+
.subtree-toolbar-actions{display:flex;align-items:center;gap:8px;margin-inline-start:auto}
|
|
16
|
+
.subtree-quiet,.subtree-action{min-height:44px;padding:9px 12px;border:1px solid var(--dsr-line);border-radius:9px;background:var(--dsr-panel);font-size:12px!important}
|
|
17
|
+
.subtree button:disabled{opacity:.6;cursor:default}
|
|
18
|
+
.subtree-summary{display:flex;flex-wrap:wrap;gap:6px 18px;margin:15px 0;color:var(--dsr-muted);font-size:12px;font-variant-numeric:tabular-nums}
|
|
19
|
+
.subtree-layout{display:grid;grid-template-columns:minmax(0,1fr) 320px;align-items:start;gap:24px}
|
|
20
|
+
.subtree-outline{min-width:0;padding:20px 16px;background:var(--dsr-bg-2);border:1px solid var(--dsr-line);border-radius:16px}
|
|
21
|
+
.subtree-list{list-style:none;padding:0 0 0 22px;margin:0 0 0 21px;border-inline-start:1px solid var(--dsr-divider)}
|
|
22
|
+
.subtree-root-list{padding:0;margin:0;border:0}.subtree-list>li{position:relative;padding-block:6px}
|
|
23
|
+
.subtree-list:not(.subtree-root-list)>li::before{content:'';position:absolute;inset-inline-start:-22px;top:37px;width:22px;border-top:1px solid var(--dsr-divider)}
|
|
24
|
+
.subtree-row{display:flex;align-items:center;gap:4px;min-width:0}
|
|
25
|
+
.subtree-disclosure,.subtree-leaf{flex:none;display:flex;align-items:center;justify-content:center;width:36px;min-height:44px;border:0;border-radius:8px;background:transparent;font-size:22px!important;color:var(--dsr-muted)!important}
|
|
26
|
+
.subtree-node{display:block;flex:1;min-width:0;width:100%;text-align:start;border:1px solid var(--dsr-line);border-radius:11px;padding:11px 13px;background:var(--dsr-panel);transition:border-color .15s,background .15s}
|
|
27
|
+
.subtree-node:hover{border-color:var(--dsr-accent-line);background:var(--dsr-panel-2)}
|
|
28
|
+
.subtree-node[aria-pressed=true]{border-color:var(--dsr-accent);background:var(--dsr-accent-soft);box-shadow:0 0 0 1px var(--dsr-accent-line)}
|
|
29
|
+
.subtree-node-head{display:flex;align-items:center;justify-content:space-between;gap:10px;min-width:0}
|
|
30
|
+
.subtree-node-head strong{min-width:0;font-size:14px;font-weight:600;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
31
|
+
.subtree-node-meta{display:flex;flex-wrap:wrap;gap:3px 12px;margin-top:5px;font-size:11px;color:var(--dsr-muted)}
|
|
32
|
+
.subtree-badge{display:inline-flex;align-items:center;gap:5px;flex:none;white-space:nowrap;border-radius:6px;padding:3px 7px;background:var(--dsr-panel-2);color:var(--dsr-muted);font-size:11px;font-weight:500}
|
|
33
|
+
.subtree-badge::before{content:'·';font-size:18px;line-height:10px}.subtree-badge[data-activity=running]{color:var(--dsr-accent-strong);background:var(--dsr-accent-soft)}
|
|
34
|
+
.subtree-badge[data-activity=waiting],.subtree-badge[data-activity=diagnostic]{color:var(--dsr-warning);background:var(--dsr-warning-soft)}
|
|
35
|
+
.subtree-badge[data-activity=diagnostic]::before{content:'!';font-size:11px}
|
|
36
|
+
.subtree-detail{position:sticky;top:0;min-width:0;padding:21px;border:1px solid var(--dsr-line);border-radius:16px;background:var(--dsr-panel)}
|
|
37
|
+
.subtree-eyebrow{font-size:11px;color:var(--dsr-muted);letter-spacing:.06em}.subtree-detail h3{font-size:18px;line-height:1.4;margin:9px 0 12px;overflow-wrap:anywhere}
|
|
38
|
+
.subtree-detail-badges{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:20px}.subtree-kind{font-size:11px;color:var(--dsr-muted)}
|
|
39
|
+
.subtree-field-label{margin-top:16px;font-size:11px;color:var(--dsr-muted)}.subtree-path{font-size:12px;line-height:1.7;margin:5px 0 0;overflow-wrap:anywhere}
|
|
40
|
+
.subtree-id{display:block;font-size:11px;line-height:1.6;margin-top:6px;padding:8px;border-radius:7px;background:var(--dsr-code-bg);overflow-wrap:anywhere;user-select:text}
|
|
41
|
+
.subtree-parent{max-width:100%;min-width:44px;min-height:44px;text-align:start;overflow-wrap:anywhere;padding:4px 0;border:0;background:transparent;color:var(--dsr-accent-strong)!important;font-size:12px!important}
|
|
42
|
+
.subtree-detail-actions{display:flex;flex-direction:column;gap:9px;margin-top:22px}.subtree-action{text-align:center}
|
|
43
|
+
.subtree-primary{background:var(--dsr-accent)!important;color:var(--dsr-on-accent)!important;border-color:var(--dsr-accent)!important;font-weight:650!important}
|
|
44
|
+
.subtree-danger{color:var(--dsr-warning)!important;border-color:var(--dsr-warning-line)!important;background:var(--dsr-warning-soft)!important}
|
|
45
|
+
.subtree-note{font-size:11px;color:var(--dsr-muted);line-height:1.7;margin:13px 0 0;overflow-wrap:anywhere}
|
|
46
|
+
.subtree-notice{padding:12px;border:1px solid var(--dsr-warning-line);border-radius:9px;background:var(--dsr-warning-soft);color:var(--dsr-warning);font-size:12px;line-height:1.65}
|
|
47
|
+
.subtree-reason{font-size:11px;color:var(--dsr-muted);display:block;margin-bottom:16px;overflow-wrap:anywhere}
|
|
48
|
+
.subtree-feedback{list-style:none;padding:18px!important;margin:8px 0;border:1px dashed var(--dsr-divider);border-radius:10px;color:var(--dsr-muted);font-size:12px;overflow-wrap:anywhere}
|
|
49
|
+
.subtree-feedback strong{font-size:13px;color:var(--dsr-text);font-weight:500}.subtree-feedback p{margin:7px 0 10px}.subtree-warning{border-color:var(--dsr-warning-line);background:var(--dsr-warning-soft)}
|
|
50
|
+
.subtree-depth{color:var(--dsr-accent-strong)}.subtree :is(button,input):focus-visible,.subagent-page-back:focus-visible{outline:2px solid var(--dsr-accent);outline-offset:3px}.subtree-detail h3:focus{outline:none}
|
|
51
|
+
.subtree-back-to-tree{display:none}
|
|
52
|
+
.subagents-entry{flex:none;font:inherit;font-size:12px;color:var(--dsr-text);background:transparent;border:1px solid var(--dsr-line);border-radius:9px;min-height:44px;padding:6px 9px;cursor:pointer}
|
|
53
|
+
body.viewing-subagent .composer-wrap,body.viewing-subagent .ds-composer,body.viewing-subagent #btn-session-more,body.viewing-subagent #btn-rename-session,body.viewing-subagent #btn-archive-session,body.viewing-subagent #btn-cancel,body.viewing-subagent [data-goal],body.viewing-subagent #queue-dock{display:none!important}
|
|
54
|
+
@media(max-width:800px){.subtree-layout{grid-template-columns:minmax(0,1fr);gap:16px}.subtree-detail{position:static}.subtree-search{max-width:none}.subtree-outline{padding:12px 8px}.subtree-disclosure,.subtree-leaf{width:32px}.subtree-node{padding:10px}.subtree-node-head{align-items:start;flex-wrap:wrap;gap:5px}.subtree-node-head strong{flex:1 1 120px}.subtree-detail-actions{flex-direction:row;flex-wrap:wrap}.subtree-detail-actions>*{flex:1 1 160px}.subtree .subtree-filters button{min-height:44px}.subtree .subtree-disclosure{min-width:44px}.subtree-list .subtree-list .subtree-list .subtree-list{padding-inline-start:0;margin-inline-start:8px;border-color:transparent}.subtree-list .subtree-list .subtree-list .subtree-list>li::before{display:none}}
|
|
55
|
+
@media(max-width:480px){.subagent-page-head{gap:12px;padding:max(12px,var(--dsr-safe-top,0px)) 12px 12px}.subagent-page-head h2{font-size:16px}.subagent-page-content{padding:16px 12px max(16px,var(--dsr-safe-b,0px))}.subtree-toolbar{gap:10px}.subtree-search{flex-basis:100%}.subtree-toolbar-actions{gap:4px}.subtree-quiet{padding-inline:9px}.subtree-filters button{padding-inline:10px}.subtree-summary{gap:5px 12px}.subtree-list{padding-inline-start:12px;margin-inline-start:14px}.subtree-list:not(.subtree-root-list)>li::before{inset-inline-start:-12px;width:12px}.subtree-root-list{padding:0;margin:0}.subtree-node-head strong{flex-basis:100px}.subtree-detail{padding:18px}}
|
|
56
|
+
@media(prefers-reduced-motion:reduce){.subtree-node{transition:none}}
|
|
57
|
+
@media(max-width:800px){.subtree-back-to-tree{display:block;margin-bottom:8px}}
|
|
58
|
+
@media(max-width:800px){.subtree-leaf{min-width:44px}}
|
|
59
|
+
@media(max-width:800px){.subtree-search{font-size:16px}}
|
|
60
|
+
.subtree-list .subtree-list .subtree-list .subtree-list .subtree-list .subtree-list{padding-inline-start:0;margin-inline-start:10px;border-color:transparent}
|
|
61
|
+
.subtree-list .subtree-list .subtree-list .subtree-list .subtree-list .subtree-list>li::before{display:none}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/* Shared, dependency-free subagent browser. Only explicit disclosure reads a new level. */
|
|
2
|
+
(function (root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
let view = null, page = null, pageBody = null, pageTitle = null
|
|
5
|
+
const memories = new Map()
|
|
6
|
+
const text = (cn, en) => String(root.I18N?.lang || 'zh').startsWith('en') ? en : cn
|
|
7
|
+
function node(tag, label, cls) {
|
|
8
|
+
const el = document.createElement(tag)
|
|
9
|
+
if (label !== undefined) el.textContent = label
|
|
10
|
+
if (cls) el.className = cls
|
|
11
|
+
return el
|
|
12
|
+
}
|
|
13
|
+
function button(label, action, cls, key) {
|
|
14
|
+
const el = node('button', label, cls)
|
|
15
|
+
el.type = 'button'
|
|
16
|
+
if (key) el.dataset.subFocus = key
|
|
17
|
+
el.addEventListener('click', action)
|
|
18
|
+
return el
|
|
19
|
+
}
|
|
20
|
+
const valid = v => view === v && !v.paused && v.options.valid()
|
|
21
|
+
const modeLabel = mode => mode === 'one-shot' ? text('单次任务', 'One-shot task') : mode === 'continuable' ? text('可续接任务', 'Continuable task') : text('模式未知', 'Unknown mode')
|
|
22
|
+
const activityLabel = activity => activity === 'running' ? text('运行中', 'Running') : activity === 'waiting' ? text('等待中', 'Waiting') : activity === 'inactive' ? text('未运行', 'Inactive') : text('状态未知', 'Unknown status')
|
|
23
|
+
function reasonLabel(reason) {
|
|
24
|
+
if (reason === 'migration-required') return text('请先在 DSH 中打开原会话完成迁移,再刷新目录', 'Open the source session in DSH to complete migration, then refresh the catalog')
|
|
25
|
+
if (reason === 'external') return text('这是外部代理任务,请在 DSH 中查看', 'This is an external-agent task. View it in DSH')
|
|
26
|
+
return ({ unsupported: text('当前版本无法识别此任务类型', 'This task type is not supported by the current version'), unavailable: text('记录暂时无法读取,可刷新重试', 'Record unavailable. Refresh to try again'), corrupt: text('任务信息不一致,暂不能打开', 'Task information is inconsistent. This record cannot be opened'), cycle: text('目录关系重复或形成循环', 'The catalog contains a repeated or circular relationship') })[reason] || text('此目录项暂时不可用', 'This catalog entry is unavailable')
|
|
27
|
+
}
|
|
28
|
+
function status(entry, diagnostic) {
|
|
29
|
+
const value = diagnostic ? 'diagnostic' : ['running', 'waiting', 'inactive'].includes(entry.activity) ? entry.activity : 'unknown'
|
|
30
|
+
const el = node('span', diagnostic ? text('目录异常', 'Catalog issue') : activityLabel(value), 'subtree-badge')
|
|
31
|
+
el.dataset.activity = value
|
|
32
|
+
return el
|
|
33
|
+
}
|
|
34
|
+
function model(v) {
|
|
35
|
+
const rootItem = { key: 'root', id: v.id, label: v.options.title || v.id, parent: null, depth: 0, entry: { activity: v.options.activity }, children: [] }
|
|
36
|
+
const byKey = new Map([['root', rootItem]])
|
|
37
|
+
let count = 0, running = 0, issues = 0, limited = false
|
|
38
|
+
function visit(parent, ancestors) {
|
|
39
|
+
const cached = v.cache.get(parent.id)
|
|
40
|
+
for (const entry of cached?.value?.entries || []) {
|
|
41
|
+
if (byKey.size > 300) { limited = true; break }
|
|
42
|
+
const diagnostic = entry.kind === 'diagnostic' || !entry.id || ancestors.has(entry.id)
|
|
43
|
+
const item = { key: parent.key + '/' + (entry.id ? encodeURIComponent(entry.id) : 'unknown-' + parent.children.length), id: entry.id || '', label: entry.label || entry.id?.slice(0, 12) || text('异常条目', 'Catalog issue'), entry, parent, depth: parent.depth + 1, diagnostic, reason: ancestors.has(entry.id) ? 'cycle' : entry.reason, children: [] }
|
|
44
|
+
byKey.set(item.key, item); parent.children.push(item)
|
|
45
|
+
if (diagnostic) issues++
|
|
46
|
+
else {
|
|
47
|
+
count++; if (entry.activity === 'running') running++
|
|
48
|
+
if (item.depth < 16) visit(item, new Set([...ancestors, item.id]))
|
|
49
|
+
else if (entry.hasChildren !== false) limited = true
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
visit(rootItem, new Set([v.id]))
|
|
54
|
+
return { rootItem, byKey, count, running, issues, limited }
|
|
55
|
+
}
|
|
56
|
+
async function read(v, id, force = false) {
|
|
57
|
+
if (!valid(v)) return
|
|
58
|
+
const previous = v.cache.get(id)
|
|
59
|
+
if (previous?.loading || (!force && (previous?.value || previous?.error))) return
|
|
60
|
+
const item = { ...previous, loading: true, error: '' }
|
|
61
|
+
v.cache.set(id, item); paint(v)
|
|
62
|
+
try {
|
|
63
|
+
const value = await v.options.read(id)
|
|
64
|
+
if (!valid(v)) { v.cache.delete(id); return }
|
|
65
|
+
if (!Array.isArray(value?.entries)) throw new Error(text('未能读取子代理目录', 'Subagent catalog unavailable'))
|
|
66
|
+
item.value = value; item.updatedAt = Date.now()
|
|
67
|
+
const ancestors = new Set([v.id, id])
|
|
68
|
+
let parent = [...model(v).byKey.values()].find(item => !item.diagnostic && item.id === id)
|
|
69
|
+
for (; parent; parent = parent.parent) ancestors.add(parent.id)
|
|
70
|
+
for (const entry of value.entries) if (entry.kind !== 'diagnostic' && entry.id && !ancestors.has(entry.id)) v.options.remember(entry, id)
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (!valid(v)) { v.cache.delete(id); return }
|
|
73
|
+
item.error = String(error.message || error)
|
|
74
|
+
} finally { item.loading = false; if (valid(v)) paint(v) }
|
|
75
|
+
}
|
|
76
|
+
async function refresh(v) {
|
|
77
|
+
if (!valid(v) || v.refreshing) return
|
|
78
|
+
v.refreshing = true; paint(v)
|
|
79
|
+
const seen = new Set()
|
|
80
|
+
async function visit(id, depth) {
|
|
81
|
+
if (!valid(v) || seen.has(id) || seen.size >= 300 || depth > 16) return
|
|
82
|
+
seen.add(id); await read(v, id, true)
|
|
83
|
+
if (!valid(v) || !v.expanded.has(id)) return
|
|
84
|
+
for (const entry of v.cache.get(id)?.value?.entries || []) {
|
|
85
|
+
if (entry.kind !== 'diagnostic' && entry.id && v.expanded.has(entry.id)) await visit(entry.id, depth + 1)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try { await visit(v.id, 0) } finally { v.refreshing = false; if (valid(v)) paint(v) }
|
|
89
|
+
}
|
|
90
|
+
function shell(v) {
|
|
91
|
+
const el = v.el = node('section', undefined, 'subtree')
|
|
92
|
+
const toolbar = node('div', undefined, 'subtree-toolbar')
|
|
93
|
+
const search = v.search = node('input', undefined, 'subtree-search')
|
|
94
|
+
search.type = 'search'; search.placeholder = text('查找已读取的名称或 ID', 'Find a loaded name or ID')
|
|
95
|
+
search.setAttribute('aria-label', search.placeholder)
|
|
96
|
+
search.addEventListener('input', () => { v.query = search.value; paint(v) })
|
|
97
|
+
const filters = node('div', undefined, 'subtree-filters')
|
|
98
|
+
filters.setAttribute('aria-label', text('按状态筛选', 'Filter by status'))
|
|
99
|
+
v.filters = []
|
|
100
|
+
for (const [key, label] of [['all', text('全部', 'All')], ['running', text('运行中', 'Running')], ['diagnostic', text('异常', 'Issues')]]) {
|
|
101
|
+
const b = button(label, () => { v.filter = key; paint(v) }, '', 'filter:' + key)
|
|
102
|
+
filters.append(b); v.filters.push([key, b])
|
|
103
|
+
}
|
|
104
|
+
toolbar.append(search, filters)
|
|
105
|
+
const actions = node('div', undefined, 'subtree-toolbar-actions')
|
|
106
|
+
const collapse = button(text('收起分支', 'Collapse branches'), () => { v.expanded.clear(); v.expanded.add(v.id); paint(v) }, 'subtree-quiet', 'collapse')
|
|
107
|
+
v.collapseButton = collapse
|
|
108
|
+
const refreshButton = v.refreshButton = button(text('刷新', 'Refresh'), () => void refresh(v), 'subtree-quiet', 'refresh')
|
|
109
|
+
actions.append(collapse, refreshButton); toolbar.append(actions)
|
|
110
|
+
v.summary = node('div', undefined, 'subtree-summary'); v.summary.setAttribute('role', 'status')
|
|
111
|
+
const layout = node('div', undefined, 'subtree-layout')
|
|
112
|
+
v.tree = node('div', undefined, 'subtree-outline'); v.tree.setAttribute('aria-label', text('子代理层级', 'Subagent hierarchy'))
|
|
113
|
+
v.detail = node('aside', undefined, 'subtree-detail'); v.detail.setAttribute('aria-label', text('所选节点详情', 'Selected node details'))
|
|
114
|
+
layout.append(v.tree, v.detail); el.append(toolbar, v.summary, layout)
|
|
115
|
+
}
|
|
116
|
+
function select(v, item) {
|
|
117
|
+
v.selected = item.key; paint(v)
|
|
118
|
+
if (root.matchMedia?.('(max-width:800px)').matches) v.detail.scrollIntoView({ behavior: root.matchMedia('(prefers-reduced-motion:reduce)').matches ? 'auto' : 'smooth', block: 'start' })
|
|
119
|
+
v.detailTitle?.focus({ preventScroll: true })
|
|
120
|
+
}
|
|
121
|
+
function details(v, item, outsideFilter) {
|
|
122
|
+
const box = v.detail; box.replaceChildren()
|
|
123
|
+
box.append(button(text('↑ 返回层级', '↑ Back to hierarchy'), () => {
|
|
124
|
+
const card = v.cards.get(item.key) || v.cards.get('root')
|
|
125
|
+
card?.scrollIntoView({ block: 'center' }); card?.focus({ preventScroll: true })
|
|
126
|
+
}, 'subtree-parent subtree-back-to-tree', 'back-to-tree'))
|
|
127
|
+
box.append(node('div', text('节点详情', 'Node details'), 'subtree-eyebrow'))
|
|
128
|
+
const title = v.detailTitle = node('h3', item.label); title.tabIndex = -1; box.append(title)
|
|
129
|
+
if (outsideFilter) box.append(node('p', text('此选中节点不在当前筛选结果中。', 'This selected node is outside the current filter.'), 'subtree-note'))
|
|
130
|
+
const badges = node('div', undefined, 'subtree-detail-badges')
|
|
131
|
+
if (item.key === 'root') badges.append(node('span', text('当前会话', 'Current session'), 'subtree-kind'))
|
|
132
|
+
else badges.append(node('span', item.diagnostic ? text('不可打开', 'Unavailable') : modeLabel(item.entry.mode), 'subtree-kind'))
|
|
133
|
+
badges.append(status(item.entry, item.diagnostic)); box.append(badges)
|
|
134
|
+
const path = []; for (let p = item; p; p = p.parent) path.unshift(p.label)
|
|
135
|
+
box.append(node('div', text('所在分支', 'Branch'), 'subtree-field-label'), node('p', path.join(' › '), 'subtree-path'))
|
|
136
|
+
if (item.parent) {
|
|
137
|
+
box.append(node('div', text('直接父会话', 'Direct parent'), 'subtree-field-label'))
|
|
138
|
+
box.append(button(item.parent.label, () => select(v, item.parent), 'subtree-parent', 'parent:' + item.key))
|
|
139
|
+
}
|
|
140
|
+
box.append(node('div', text('会话 ID', 'Session ID'), 'subtree-field-label'), node('code', item.id || '—', 'subtree-id'))
|
|
141
|
+
if (item.diagnostic) {
|
|
142
|
+
box.append(node('p', reasonLabel(item.reason), 'subtree-notice'))
|
|
143
|
+
if (item.reason) box.append(node('code', item.reason, 'subtree-reason'))
|
|
144
|
+
box.append(button(text('刷新目录', 'Refresh catalog'), () => void read(v, item.parent.id, true), 'subtree-action', 'retry-detail')); return
|
|
145
|
+
}
|
|
146
|
+
const cached = v.cache.get(item.id)
|
|
147
|
+
if (cached?.value) box.append(node('p', text(`已读取 ${item.children.filter(c => !c.diagnostic).length} 个直接子代理`, `${item.children.filter(c => !c.diagnostic).length} direct subagents loaded`), 'subtree-note'))
|
|
148
|
+
else if (item.entry.hasChildren !== false && item.key !== 'root') box.append(node('p', text('展开节点前的箭头,读取下一层任务。', 'Expand the node arrow to load the next level.'), 'subtree-note'))
|
|
149
|
+
const actions = node('div', undefined, 'subtree-detail-actions')
|
|
150
|
+
actions.append(button(item.key === 'root' ? text('返回当前对话', 'Back to current chat') : text('打开只读记录 ↗', 'Open read-only record ↗'), () => {
|
|
151
|
+
if (!valid(v)) return
|
|
152
|
+
root.DshSubagents.close(); if (item.parent) void v.options.open(item.entry, item.parent.id)
|
|
153
|
+
}, 'subtree-action subtree-primary', 'open:' + item.key))
|
|
154
|
+
const parentCatalog = item.parent && v.cache.get(item.parent.id)?.value
|
|
155
|
+
if (item.entry.mode === 'continuable' && item.entry.activity === 'running' && parentCatalog?.parentAvailable !== false) {
|
|
156
|
+
actions.append(button(text('中断任务', 'Interrupt task'), () => { if (valid(v)) void v.options.interrupt(item.id, item.parent.id) }, 'subtree-action subtree-danger', 'interrupt:' + item.key))
|
|
157
|
+
}
|
|
158
|
+
box.append(actions, node('p', item.parent ? text('打开记录后,返回会进入它的直接父会话。', 'From a record, Back opens its direct parent session.') : text('选择树中的子代理,查看任务详情。', 'Select a subagent in the tree to inspect its details.'), 'subtree-note'))
|
|
159
|
+
}
|
|
160
|
+
function paint(v) {
|
|
161
|
+
if (!valid(v)) return
|
|
162
|
+
const focused = document.activeElement?.dataset?.subFocus
|
|
163
|
+
const m = model(v), query = v.query.trim().toLocaleLowerCase(), filtering = !!query || v.filter !== 'all'
|
|
164
|
+
const matches = new Set()
|
|
165
|
+
function match(item) {
|
|
166
|
+
const own = (!query || `${item.label} ${item.id}`.toLocaleLowerCase().includes(query)) && (v.filter === 'all' || (v.filter === 'diagnostic' ? item.diagnostic : !item.diagnostic && item.entry.activity === 'running'))
|
|
167
|
+
const descendant = item.children.map(match).some(Boolean)
|
|
168
|
+
if (own || descendant) matches.add(item.key)
|
|
169
|
+
return own || descendant
|
|
170
|
+
}
|
|
171
|
+
m.rootItem.children.forEach(match)
|
|
172
|
+
v.refreshButton.disabled = !!v.refreshing; v.refreshButton.textContent = v.refreshing ? text('刷新中…', 'Refreshing…') : text('刷新', 'Refresh')
|
|
173
|
+
v.collapseButton.disabled = filtering
|
|
174
|
+
v.collapseButton.title = filtering ? text('清除筛选后可收起分支', 'Clear filters to collapse branches') : ''
|
|
175
|
+
for (const [key, b] of v.filters) b.setAttribute('aria-pressed', String(key === v.filter))
|
|
176
|
+
const labels = [text(`已读取 ${m.count} 个子代理`, `${m.count} subagents loaded`), text(`${m.running} 个运行中`, `${m.running} running`), text(`${m.issues} 个目录异常`, `${m.issues} catalog issues`)]
|
|
177
|
+
if (v.summarySignature !== labels.join('|')) {
|
|
178
|
+
v.summarySignature = labels.join('|'); v.summary.replaceChildren()
|
|
179
|
+
for (const label of labels) v.summary.append(node('span', label))
|
|
180
|
+
}
|
|
181
|
+
v.tree.replaceChildren()
|
|
182
|
+
v.cards = new Map()
|
|
183
|
+
function feedback(parent, list) {
|
|
184
|
+
const cached = v.cache.get(parent.id)
|
|
185
|
+
if (cached?.error) {
|
|
186
|
+
const warning = node('li', undefined, 'subtree-feedback subtree-warning')
|
|
187
|
+
warning.append(node('strong', cached.value ? text('刷新失败,保留上次目录', 'Refresh failed. Showing the last catalog') : text('暂时无法读取目录', 'Catalog unavailable')), node('p', cached.error))
|
|
188
|
+
warning.append(button(text('重试', 'Retry'), () => void read(v, parent.id, true), 'subtree-action', 'retry:' + parent.key)); list.append(warning)
|
|
189
|
+
}
|
|
190
|
+
if (cached?.loading) list.append(node('li', text('正在读取这一层…', 'Loading this level…'), 'subtree-feedback'))
|
|
191
|
+
if (cached?.value && !cached.value.entries.length && !cached.error) {
|
|
192
|
+
const empty = node('li', undefined, 'subtree-feedback')
|
|
193
|
+
empty.append(node('strong', text('暂无子代理', 'No subagents')), node('p', text('此会话还没有子代理记录。产生新任务后可刷新查看。', 'This session has no subagent records yet. Refresh after new tasks are created.'))); list.append(empty)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function row(item) {
|
|
197
|
+
const li = node('li'), line = node('div', undefined, 'subtree-row')
|
|
198
|
+
const cached = v.cache.get(item.id), expanded = v.expanded.has(item.id)
|
|
199
|
+
const canExpand = !item.diagnostic && item.depth < 16 && (cached?.value ? cached.value.entries.length > 0 : item.key === 'root' || item.entry.hasChildren !== false)
|
|
200
|
+
if (canExpand) {
|
|
201
|
+
const toggle = button(expanded ? '⌄' : '›', () => {
|
|
202
|
+
if (expanded) v.expanded.delete(item.id)
|
|
203
|
+
else { v.expanded.add(item.id); void read(v, item.id) }
|
|
204
|
+
paint(v)
|
|
205
|
+
}, 'subtree-disclosure', 'toggle:' + item.key)
|
|
206
|
+
toggle.setAttribute('aria-expanded', String(expanded)); toggle.setAttribute('aria-label', (expanded ? text('收起 ', 'Collapse ') : text('展开 ', 'Expand ')) + item.label); line.append(toggle)
|
|
207
|
+
} else line.append(node('span', '·', 'subtree-leaf'))
|
|
208
|
+
const card = button(undefined, () => select(v, item), 'subtree-node', 'select:' + item.key)
|
|
209
|
+
v.cards.set(item.key, card)
|
|
210
|
+
card.setAttribute('aria-pressed', String(item.key === v.selected)); card.title = item.id
|
|
211
|
+
const head = node('span', undefined, 'subtree-node-head'); head.append(node('strong', item.label), status(item.entry, item.diagnostic))
|
|
212
|
+
const meta = node('span', undefined, 'subtree-node-meta')
|
|
213
|
+
meta.append(node('span', item.key === 'root' ? text('当前会话 · 树的起点', 'Current session · Tree root') : item.diagnostic ? reasonLabel(item.reason) : modeLabel(item.entry.mode)))
|
|
214
|
+
if (item.depth >= 4) meta.append(node('span', text(`第 ${item.depth} 层`, `Level ${item.depth}`), 'subtree-depth'))
|
|
215
|
+
if (!item.diagnostic && cached?.value && item.children.length) meta.append(node('span', text(`${item.children.length} 个下级条目`, `${item.children.length} child entries`)))
|
|
216
|
+
card.append(head, meta); line.append(card); li.append(line)
|
|
217
|
+
if (!item.diagnostic && (expanded || filtering)) {
|
|
218
|
+
const list = node('ul', undefined, 'subtree-list')
|
|
219
|
+
for (const child of item.children) if (!filtering || matches.has(child.key)) list.append(row(child))
|
|
220
|
+
if (!filtering || cached?.loading || cached?.error) feedback(item, list)
|
|
221
|
+
if (list.children.length) li.append(list)
|
|
222
|
+
}
|
|
223
|
+
return li
|
|
224
|
+
}
|
|
225
|
+
const treeList = node('ul', undefined, 'subtree-list subtree-root-list'); treeList.append(row(m.rootItem)); v.tree.append(treeList)
|
|
226
|
+
if (filtering && v.cache.get(v.id)?.value && !v.cache.get(v.id)?.loading && !m.rootItem.children.some(c => matches.has(c.key))) {
|
|
227
|
+
const empty = node('div', undefined, 'subtree-feedback')
|
|
228
|
+
empty.append(node('strong', text('已读取目录中没有匹配项', 'No matches in the loaded catalog')), node('p', text('筛选仅检查已读取的节点,不会自动加载其他分支。', 'Filters only inspect loaded nodes and do not load other branches.')))
|
|
229
|
+
empty.append(button(text('清除筛选', 'Clear filters'), () => { v.query = ''; v.search.value = ''; v.filter = 'all'; paint(v) }, 'subtree-action', 'clear')); v.tree.append(empty)
|
|
230
|
+
}
|
|
231
|
+
if (m.limited) v.tree.append(node('p', text('目录较大,打开子代理记录可继续查看更深层。', 'Open a child record to explore more of this large catalog.'), 'subtree-note'))
|
|
232
|
+
const selected = m.byKey.get(v.selected) || m.rootItem
|
|
233
|
+
v.selected = selected.key; details(v, selected, filtering && selected.key !== 'root' && !matches.has(selected.key))
|
|
234
|
+
if (focused) for (const el of v.el.querySelectorAll('[data-sub-focus]')) if (el.dataset.subFocus === focused) el.focus({ preventScroll: true })
|
|
235
|
+
}
|
|
236
|
+
root.DshSubagents = {
|
|
237
|
+
configure(entry, options) {
|
|
238
|
+
if (!entry) return
|
|
239
|
+
entry.onclick = () => { if (options.valid()) root.DshSubagents.show(options) }
|
|
240
|
+
if (page?.open) { if (view?.id === options.sessionId) root.DshSubagents.mount(pageBody, options); else root.DshSubagents.close() }
|
|
241
|
+
},
|
|
242
|
+
show(options) {
|
|
243
|
+
if (!options.valid()) return
|
|
244
|
+
if (!page) {
|
|
245
|
+
page = node('dialog', undefined, 'subagent-page'); page.id = 'subagent-page'; page.setAttribute('aria-labelledby', 'subagent-page-title')
|
|
246
|
+
const head = node('header', undefined, 'subagent-page-head')
|
|
247
|
+
const back = button(text('‹ 返回对话', '‹ Back to chat'), () => root.DshSubagents.close(), 'subagent-page-back')
|
|
248
|
+
const titleBlock = node('div', undefined, 'subagent-page-heading'); titleBlock.append(node('span', text('会话 / 子代理', 'Conversation / Subagents'), 'subtree-eyebrow'))
|
|
249
|
+
pageTitle = node('h2'); pageTitle.id = 'subagent-page-title'; titleBlock.append(pageTitle); head.append(back, titleBlock)
|
|
250
|
+
pageBody = node('div', undefined, 'subagent-page-content'); page.append(head, pageBody)
|
|
251
|
+
page.addEventListener('close', () => { if (view?.options.valid()) view.options.onClose?.(); root.DshSubagents.pause() }); document.body.append(page)
|
|
252
|
+
}
|
|
253
|
+
pageTitle.textContent = options.title || options.sessionId
|
|
254
|
+
if (!page.open) { page.showModal(); options.onShow?.() }
|
|
255
|
+
if (!view || view.id !== options.sessionId || !view.options.valid()) {
|
|
256
|
+
const expanded = memories.get(options.sessionId) || new Set(); expanded.add(options.sessionId); memories.set(options.sessionId, expanded)
|
|
257
|
+
}
|
|
258
|
+
pageBody.replaceChildren(); root.DshSubagents.mount(pageBody, options)
|
|
259
|
+
},
|
|
260
|
+
close() { if (page?.open) { page.close(); root.DshSubagents.pause() } },
|
|
261
|
+
mount(target, options) {
|
|
262
|
+
if (!target || !options.valid()) return
|
|
263
|
+
if (!view || view.id !== options.sessionId || !view.options.valid()) {
|
|
264
|
+
if (view) memories.set(view.id, view.expanded)
|
|
265
|
+
if (memories.size > 20) memories.delete(memories.keys().next().value)
|
|
266
|
+
view = { id: options.sessionId, options, expanded: memories.get(options.sessionId) || new Set([options.sessionId]), cache: new Map(), paused: false, query: '', filter: 'all', selected: 'root' }; shell(view)
|
|
267
|
+
}
|
|
268
|
+
view.options = options; view.paused = false; target.append(view.el); paint(view)
|
|
269
|
+
const cached = view.cache.get(view.id)
|
|
270
|
+
if (cached?.value && Date.now() - cached.updatedAt >= 10000) void refresh(view); else void read(view, view.id)
|
|
271
|
+
},
|
|
272
|
+
pause() { if (view) view.paused = true },
|
|
273
|
+
reset() { root.DshSubagents.close(); view = null; memories.clear() },
|
|
274
|
+
}
|
|
275
|
+
})(window)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* Task board: a bounded read-only view of the selected host workspace. */
|
|
2
|
+
;(function(root) {
|
|
3
|
+
'use strict'
|
|
4
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({ '&':'&', '<':'<', '>':'>', '"':'"', "'":''' }[c]))
|
|
5
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
6
|
+
const statuses = { backlog: ['待整理','Backlog'], todo: ['待执行','To do'], running: ['运行中','Running'], done: ['已完成','Done'], failed: ['失败','Failed'],
|
|
7
|
+
succeeded: ['执行成功','Run succeeded'], cancelled: ['已取消','Cancelled'], unknown: ['未知','Unknown'] }
|
|
8
|
+
const label = value => statuses[value] ? text(...statuses[value]) : text('未知','Unknown')
|
|
9
|
+
const date = (value, zone) => {
|
|
10
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) return '—'
|
|
11
|
+
try { return new Date(value).toLocaleString(root.I18N?.lang === 'en' ? 'en-GB' : 'zh-CN', { timeZone: zone || undefined }) }
|
|
12
|
+
catch { return text('时间或时区不可用','Time or timezone unavailable') }
|
|
13
|
+
}
|
|
14
|
+
function taskHtml(task, index, timeZone) {
|
|
15
|
+
const run = task.executions?.at(-1), verification = run?.verification
|
|
16
|
+
const accepted = verification?.stage === 'quality' && verification.passed === true && !verification.inFlight && !verification.failedReason
|
|
17
|
+
const verdict = !verification ? text('未提供验收记录','No verification record') : verification.inFlight ? text('验收中','Verification running')
|
|
18
|
+
: verification.applicability !== 'enforced' ? text('未启用独立验收','Independent verification not enforced') : accepted ? text('验收记录通过','Verification record passed')
|
|
19
|
+
: verification.stage === 'quality' && verification.passed === false ? text('验收未通过','Verification did not pass') : text('尚无有效验收通过记录','No valid passing verification record')
|
|
20
|
+
const schedule = task.schedule
|
|
21
|
+
const errors = [...new Set([run?.error,verification?.failedReason].filter(Boolean))]
|
|
22
|
+
const tone = task.status === 'running' ? 'active' : task.status === 'failed' ? 'attention' : 'neutral'
|
|
23
|
+
return `<article class="task-card" data-task-id="${esc(task.id)}"><header class="ext-panel-head"><h3>${esc(task.title || text('未命名任务','Untitled task'))}</h3><span class="ext-badge" data-tone="${tone}">${esc(label(task.status))}${task.archivedAt ? ' · ' + esc(text('已归档','Archived')) : ''}</span></header>
|
|
24
|
+
${task.description ? `<p class="ext-copy task-description">${esc(task.description)}</p>` : ''}<dl class="ext-facts task-outcomes"><div><dt>${esc(text('最近执行','Latest run'))}</dt><dd>${esc(run ? run.result ? label(run.result) : run.endedAt ? text('结果未知','Outcome unknown') : text('执行尚未结束','Run has not ended') : text('尚无执行记录','No execution record'))}${run?.external ? `<small>${esc(text('外部报告','Externally reported'))}</small>` : ''}</dd></div><div><dt>${esc(text('独立验收','Verification'))}</dt><dd>${esc(verdict)}</dd></div></dl>
|
|
25
|
+
${errors.length ? `<aside class="ext-alert"><strong>${esc(text('需要关注','Needs attention'))}</strong>${errors.map(error => `<p class="ext-copy">${esc(error)}</p>`).join('')}</aside>` : ''}
|
|
26
|
+
${schedule ? `<div class="task-schedule"><div class="task-schedule-head"><span>${esc(text('执行计划','Schedule'))}</span><span>${esc(schedule.enabled ? text('已启用','Enabled') : text('未启用','Disabled'))}</span></div><p class="task-schedule-rule">${esc(schedule.mode === 'once' ? text('单次执行','Run once') : schedule.mode === 'cron' ? schedule.cron : text('未知计划','Unknown schedule'))}</p>${schedule.enabled ? `<dl class="ext-facts"><div><dt>${esc(text('下次执行','Next run'))}</dt><dd>${esc(date(schedule.nextRunAt,schedule.timeZone || timeZone))}<small>${esc(schedule.timeZone || timeZone || text('时区未知','Timezone unknown'))}</small></dd></div></dl>` : ''}</div>` : ''}
|
|
27
|
+
${run?.summary ? `<details class="ext-disclosure" data-task-detail="${esc(task.id)}"><summary><span>${esc(text('最近执行摘要','Latest run summary'))}</span></summary><div class="ext-detail-body ext-copy">${esc(run.summary)}</div></details>` : ''}
|
|
28
|
+
${task.parentId ? `<dl class="ext-facts task-parent"><div><dt>${esc(text('父任务','Parent task'))}</dt><dd class="ext-identifier">${esc(task.parentId)}</dd></div></dl>` : ''}
|
|
29
|
+
<footer class="task-footer"><span>${esc(text('更新于','Updated'))}<time>${esc(date(task.updatedAt,timeZone))}</time></span>${run?.sessionId ? `<button class="ext-button" type="button" data-task-open="${index}">${esc(text('打开执行会话','Open execution session'))}<span aria-hidden="true">↗</span></button>` : ''}</footer></article>`
|
|
30
|
+
}
|
|
31
|
+
let current
|
|
32
|
+
function close() { if (current) { current.controller.abort(); clearInterval(current.timer); current = null } }
|
|
33
|
+
async function mount(config, target) {
|
|
34
|
+
close()
|
|
35
|
+
const workspaces = (config.getWorkspaces?.() || []).filter(row => row?.workspaceId)
|
|
36
|
+
const s = { config, target, controller: new AbortController(), request: 0, data: null, expanded: new Set() }
|
|
37
|
+
current = s
|
|
38
|
+
const valid = () => current === s && config.valid()
|
|
39
|
+
s.workspaceId = workspaces.find(row => row.workspaceId === config.getWorkspaceId?.())?.workspaceId || workspaces[0]?.workspaceId || ''
|
|
40
|
+
target.innerHTML = `<section class="task-board"><div class="ext-heading"><span class="ext-eyebrow">${esc(text('工作概览','WORK OVERVIEW'))}</span><h2>${esc(text('任务看板','Task board'))}</h2><p>${esc(text('跟进任务进度、执行结果与验收状态。','Track task progress, execution results and verification.'))}</p></div>
|
|
41
|
+
<div class="task-controls ext-toolbar"><label class="ext-field ext-workspace">${esc(text('工作区','Workspace'))}<select data-task-workspace>${workspaces.map(row => `<option value="${esc(row.workspaceId)}">${esc(row.title || row.workspaceId)}</option>`).join('')}</select></label>
|
|
42
|
+
<label class="ext-field">${esc(text('状态','Status'))}<select data-task-status><option value="">${esc(text('全部状态','All statuses'))}</option>${Object.keys(statuses).slice(0,5).map(value => `<option value="${value}">${esc(label(value))}</option>`).join('')}</select></label>
|
|
43
|
+
<label class="ext-field ext-search">${esc(text('搜索','Search'))}<input type="search" data-task-search placeholder="${esc(text('搜索任务','Search tasks'))}"></label><label class="ext-check"><input type="checkbox" data-task-archived> ${esc(text('显示归档任务','Show archived tasks'))}</label>
|
|
44
|
+
<button class="ext-button" type="button" data-task-refresh>${esc(text('刷新','Refresh'))}</button></div><p class="ext-note task-scope">${esc(text('只读查看当前工作区,未指定工作区的任务不在此列表。','Read-only view of this workspace; unassigned tasks are excluded.'))}</p><div class="task-summary"><p class="ext-note" data-task-count></p><p class="ext-note" role="status" aria-live="polite" data-task-note></p></div><div class="task-list" data-task-content></div></section>`
|
|
45
|
+
const selector = target.querySelector('[data-task-workspace]'), filter = target.querySelector('[data-task-status]'), search = target.querySelector('[data-task-search]')
|
|
46
|
+
const archived = target.querySelector('[data-task-archived]'), content = target.querySelector('[data-task-content]'), note = target.querySelector('[data-task-note]'), count = target.querySelector('[data-task-count]')
|
|
47
|
+
selector.value = s.workspaceId; filter.value = ''; search.value = ''; archived.checked = false
|
|
48
|
+
function render() {
|
|
49
|
+
if (!valid() || !s.data) return
|
|
50
|
+
const query = search.value.trim().toLowerCase(), renderKey = JSON.stringify([s.data.tasks,s.data.timeZone,query,filter.value,archived.checked])
|
|
51
|
+
if (renderKey === s.renderKey) return
|
|
52
|
+
s.renderKey = renderKey
|
|
53
|
+
const focusedTask = document.activeElement?.closest?.('[data-task-id]')?.dataset.taskId
|
|
54
|
+
for (const el of content.querySelectorAll('details')) { if (el.open) s.expanded.add(el.dataset.taskDetail); else s.expanded.delete(el.dataset.taskDetail) }
|
|
55
|
+
const rows = s.data.tasks.map((task, index) => ({ task, index })).filter(({ task }) => (!filter.value || task.status === filter.value) && (archived.checked || !task.archivedAt)
|
|
56
|
+
&& [task.title,task.description].join(' ').toLowerCase().includes(query))
|
|
57
|
+
count.textContent = `${text('显示','Showing')} ${rows.length}${rows.length !== s.data.tasks.length ? ' / ' + s.data.tasks.length : ''} ${text('个任务','tasks')}`
|
|
58
|
+
content.innerHTML = rows.length ? rows.map(({ task,index }) => taskHtml(task,index,s.data.timeZone)).join('') : `<p class="ext-empty">${esc(text('没有匹配的任务。','No matching tasks.'))}</p>`
|
|
59
|
+
for (const el of content.querySelectorAll('details')) el.open = s.expanded.has(el.dataset.taskDetail)
|
|
60
|
+
if (focusedTask) [...content.querySelectorAll('[data-task-open]')].find(el => s.data.tasks[Number(el.dataset.taskOpen)]?.id === focusedTask)?.focus({ preventScroll:true })
|
|
61
|
+
}
|
|
62
|
+
async function load(clear = false) {
|
|
63
|
+
if (!valid()) { if (current === s) close(); return }
|
|
64
|
+
if (s.loading && !clear) return
|
|
65
|
+
s.readController?.abort(); s.readController = new AbortController()
|
|
66
|
+
const request = ++s.request; s.loading = true
|
|
67
|
+
if (clear) { s.data = null; s.renderKey = ''; s.expanded.clear(); content.replaceChildren(); count.textContent = '' }
|
|
68
|
+
if (!s.workspaceId) { s.loading = false; note.textContent = text('请先登记一个 DSH 工作区。','Register a DSH workspace first.'); return }
|
|
69
|
+
note.textContent = text('正在读取任务…','Loading tasks…')
|
|
70
|
+
try {
|
|
71
|
+
const response = await fetch(config.url('/remote/api/task-board?workspaceId=' + encodeURIComponent(s.workspaceId)), { headers: config.headers,
|
|
72
|
+
signal: AbortSignal.any([s.controller.signal,s.readController.signal,AbortSignal.timeout(25000)]) })
|
|
73
|
+
const body = await response.text()
|
|
74
|
+
if (!valid() || request !== s.request) return
|
|
75
|
+
if (body.length > 2 * 1024 * 1024) throw Error('large')
|
|
76
|
+
const data = JSON.parse(body)
|
|
77
|
+
if (!response.ok || data.ok !== true) { root.DshExtensions?.reportAvailability?.(config,'tasks',{ code: response.status === 401 || response.status === 403 ? 'host-denied' : data.code || (response.status === 404 ? 'not-installed' : 'read-failed') }); throw Error('read') }
|
|
78
|
+
if (data.schema !== 1 || data.available !== false && (!Array.isArray(data.tasks) || data.source !== 'task-board' || data.workspaceId !== s.workspaceId)) throw Error('schema')
|
|
79
|
+
root.DshExtensions?.reportAvailability?.(config,'tasks',data)
|
|
80
|
+
if (data.available === false) { s.data = null; s.renderKey = ''; content.replaceChildren(); count.textContent = ''; note.textContent = text('主机未提供兼容的任务看板服务,请返回插件列表查看诊断。','No compatible task-board service. Check diagnostics in the plugin list.'); return }
|
|
81
|
+
s.data = data; render()
|
|
82
|
+
note.textContent = (data.truncated ? text('仅载入前 200 个任务 · ','Loaded the first 200 tasks · ') : text('已更新 · ','Updated · ')) + date(data.generatedAt, data.timeZone)
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (valid() && request === s.request) {
|
|
85
|
+
if (error.message !== 'read') root.DshExtensions?.reportAvailability?.(config,'tasks',{ code: error.message === 'schema' ? 'unsupported' : error.name === 'TimeoutError' ? 'timeout' : 'read-failed' })
|
|
86
|
+
note.textContent = s.data ? text('刷新失败,保留上次结果,可重试。','Refresh failed. Showing the previous result; retry available.') : text('读取失败,请重试或查看插件诊断。','Read failed. Retry or check plugin diagnostics.')
|
|
87
|
+
}
|
|
88
|
+
} finally { if (request === s.request) s.loading = false }
|
|
89
|
+
}
|
|
90
|
+
selector.addEventListener('change', () => { if (!valid()) return; s.workspaceId = selector.value; void load(true) })
|
|
91
|
+
filter.addEventListener('change', render); search.addEventListener('input', render); archived.addEventListener('change', render)
|
|
92
|
+
target.querySelector('[data-task-refresh]').addEventListener('click', () => void load())
|
|
93
|
+
content.addEventListener('click', async event => {
|
|
94
|
+
const button = event.target.closest?.('[data-task-open]')
|
|
95
|
+
if (!button || !valid() || !s.data) return
|
|
96
|
+
const task = s.data.tasks[Number(button.dataset.taskOpen)], sessionId = task?.executions?.at(-1)?.sessionId
|
|
97
|
+
if (!sessionId || !config.openTaskSession) return
|
|
98
|
+
button.disabled = true
|
|
99
|
+
try { await config.openTaskSession(sessionId,s.workspaceId) }
|
|
100
|
+
catch { if (valid()) note.textContent = text('执行会话暂不可用,请刷新后重试。','Execution session unavailable. Refresh and retry.') }
|
|
101
|
+
finally { if (valid()) button.disabled = false }
|
|
102
|
+
})
|
|
103
|
+
s.timer = setInterval(() => { if (valid() && !document.hidden) void load(); else if (!valid()) close() }, 15000)
|
|
104
|
+
await load()
|
|
105
|
+
}
|
|
106
|
+
const api = { mount, close, taskHtml }
|
|
107
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
108
|
+
else root.DshTasks = api
|
|
109
|
+
})(typeof window === 'undefined' ? globalThis : window)
|
package/public/teams.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* AgentTeams view: reads only; scheduling remains owned by the host plugin. */
|
|
2
|
+
'use strict';
|
|
3
|
+
;(function(root) {
|
|
4
|
+
const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))
|
|
5
|
+
const text = (zh, en) => root.I18N?.lang === 'en' ? en : zh
|
|
6
|
+
let current
|
|
7
|
+
function status(value) {
|
|
8
|
+
const names = { staged: ['待确认计划','Plan awaiting review'], running: ['运行中','Running'], working: ['工作中','Working'], idle: ['未运行','Idle'], unknown: ['未知','Unknown'],
|
|
9
|
+
open: ['待执行','Open'], blocked: ['受阻','Blocked'], completed: ['已完成','Completed'], failed: ['失败','Failed'], cancelled: ['已取消','Cancelled'], in_progress: ['执行中','In progress'], removed: ['已移除','Removed'],
|
|
10
|
+
pending: ['待审查','Pending review'], approved: ['已通过','Approved'], rejected: ['未通过','Rejected'], not_required: ['无需审查','Not required'],
|
|
11
|
+
awaiting_review: ['等待计划审查','Awaiting plan review'], awaiting_feedback: ['等待审查反馈','Awaiting review feedback'] }
|
|
12
|
+
return names[value] ? text(...names[value]) : value || text('未知','Unknown')
|
|
13
|
+
}
|
|
14
|
+
function teamHtml(team, index, archived) {
|
|
15
|
+
const button = (label, member = '') => `<button class="ext-button${member ? '' : ' ext-button-primary'}" type="button" data-team-open="${index}"${member ? ` data-team-member="${esc(member)}"` : ''}>${esc(label)}<span aria-hidden="true">↗</span></button>`
|
|
16
|
+
const badge = (value, title) => `<span class="ext-badge" data-tone="${['blocked','failed','rejected'].includes(value) ? 'attention' : ['working','running','in_progress'].includes(value) ? 'active' : 'neutral'}">${esc(title || status(value))}</span>`
|
|
17
|
+
const members = (team.members || []).map(member => {
|
|
18
|
+
const states = [...new Set([member.activity,member.status].filter(Boolean).map(status))]
|
|
19
|
+
return `<li class="team-member"><div class="ext-panel-head"><strong>${esc(member.name)}</strong><span class="team-member-state">${states.map(esc).join(' · ')}</span></div>${member.role ? `<p class="ext-copy team-role">${esc(member.role)}</p>` : ''}<dl class="ext-facts team-member-facts">${member.provider || member.model ? `<div><dt>${esc(text('模型','Model'))}</dt><dd class="ext-identifier">${esc([member.provider,member.model].filter(Boolean).join(' / '))}</dd></div>` : ''}${member.currentTask ? `<div><dt>${esc(text('当前任务','Current task'))}</dt><dd class="ext-copy">${esc(member.currentTask)}</dd></div>` : ''}</dl>${!archived && member.id ? `<footer class="team-member-action">${button(text('打开成员记录','Open member record'), member.id)}</footer>` : ''}</li>`
|
|
20
|
+
}).join('')
|
|
21
|
+
const tasks = (team.tasks || []).map(task => `<li class="team-task"><div class="ext-panel-head"><strong>${esc(task.subject || task.id)}</strong>${badge(task.state || task.status)}</div>${task.subject && task.id ? `<span class="ext-identifier team-task-id">${esc(task.id)}</span>` : ''}${task.description ? `<p class="ext-copy">${esc(task.description)}</p>` : ''}<dl class="ext-facts"><div><dt>${esc(text('负责人','Assignee'))}</dt><dd>${esc(task.assignee || '—')}</dd></div><div><dt>${esc(text('依赖','Depends on'))}</dt><dd class="ext-identifier">${esc((task.dependencies || []).join(', ') || '—')}</dd></div></dl>${task.verdictStale ? `<p class="ext-alert ext-copy">${esc(task.verdictStale)}</p>` : ''}</li>`).join('')
|
|
22
|
+
const delivery = team.deliverable === true && team.delivery?.ok === true ? text('插件报告可交付','Plugin reports deliverable') : text('交付尚未确认','Delivery not confirmed')
|
|
23
|
+
const count = (label, value) => `<span>${esc(label)}<b>${value}</b></span>`
|
|
24
|
+
const detail = (key, label, count, body, open = false) => `<details class="ext-disclosure"${open ? ' open' : ''} data-team-detail="${key}:${esc(team.teamId)}"><summary><span>${esc(label)}</span><span class="ext-count">${esc(count)}</span></summary><div class="ext-detail-body">${body}</div></details>`
|
|
25
|
+
const blockers = team.delivery?.blockers || [], warnings = team.delivery?.warnings || []
|
|
26
|
+
const attention = team.delivery?.ok === false || blockers.length || warnings.length
|
|
27
|
+
? `<aside class="ext-alert"><strong>${esc(team.delivery?.ok === false ? text('交付检查未通过','Delivery checks have not passed') : text('交付提醒','Delivery notes'))}</strong>${blockers.length ? `<ul aria-label="${esc(text('交付阻断','Delivery blockers'))}">${blockers.map(value => `<li class="ext-copy">${esc(value)}</li>`).join('')}</ul>` : ''}${warnings.length ? detail('warnings',text('交付警告','Delivery warnings'),warnings.length,`<ul>${warnings.map(value => `<li class="ext-copy">${esc(value)}</li>`).join('')}</ul>`) : ''}</aside>` : ''
|
|
28
|
+
return `<article class="teams-card" data-team-id="${esc(team.teamId)}"><header class="ext-panel-head"><h3>${esc(team.name)}</h3>${badge(archived ? 'archived' : team.halted ? 'blocked' : team.phase, archived ? text('已归档','Archived') : team.halted ? text('已暂停调度','Scheduling halted') : status(team.phase))}</header>${team.description ? `<p class="ext-copy team-description">${esc(team.description)}</p>` : ''}<div class="team-overview">${count(text('成员','Members'),(team.members || []).length + (team.membersTruncated ? '+' : ''))}${count(text('任务','Tasks'),(team.tasks || []).length + (team.tasksTruncated ? '+' : ''))}${count(text('受阻','Blocked'),(team.tasks || []).filter(task => (task.state || task.status) === 'blocked').length)}</div><dl class="ext-facts team-checks">${team.planReviewState ? `<div><dt>${esc(text('计划审查','Plan review'))}</dt><dd>${esc(status(team.planReviewState))}</dd></div>` : ''}<div><dt>${esc(text('交付状态','Delivery'))}</dt><dd>${esc(delivery)}</dd></div></dl>${attention}<div class="team-captain-action">${button(text('打开队长会话','Open captain session'))}</div>${detail('members',text('成员','Members'),(team.members || []).length + (team.membersTruncated ? '+' : ''),`<ul class="team-members">${members || `<li class="ext-empty">${esc(text('暂无成员','No members'))}</li>`}</ul>`,true)}${detail('tasks',text('任务与依赖','Tasks and dependencies'),(team.tasks || []).length + (team.tasksTruncated ? '+' : ''),`<ul class="team-tasks">${tasks || `<li class="ext-empty">${esc(text('暂无任务','No tasks'))}</li>`}</ul>`)}${detail('messages',text('队长未读消息预览','Unread captain messages'),team.messageCount ?? '—',`<ul class="team-messages">${(team.captainInbox || []).map(row => `<li><strong>${esc(row.from)}</strong><p class="ext-copy">${esc(row.content)}</p></li>`).join('') || `<li class="ext-empty">${esc(text('暂无预览消息','No message previews'))}</li>`}</ul>`)}</article>`
|
|
29
|
+
}
|
|
30
|
+
function close() { if (current) { current.controller.abort(); clearInterval(current.timer); current = null } }
|
|
31
|
+
async function mount(config, target) {
|
|
32
|
+
close()
|
|
33
|
+
const s = { config, target, controller: new AbortController(), request: 0, data: null, workspaceId: '', archived: false, expanded: new Map() }
|
|
34
|
+
current = s
|
|
35
|
+
const valid = () => current === s && config.valid()
|
|
36
|
+
const workspaces = (config.getWorkspaces?.() || []).filter(w => w?.workspaceId)
|
|
37
|
+
s.workspaceId = workspaces.some(w => w.workspaceId === config.getWorkspaceId?.()) ? config.getWorkspaceId() : workspaces[0]?.workspaceId || ''
|
|
38
|
+
target.innerHTML = `<section class="teams-page"><div class="ext-heading"><span class="ext-eyebrow">${esc(text('协作概览','COLLABORATION'))}</span><h2>${esc(text('智能体团队','Agent teams'))}</h2><p>${esc(text('掌握团队进展,查看成员分工与交付阻断。','Follow team progress, member assignments and delivery blockers.'))}</p></div><div class="teams-controls ext-toolbar"><label class="ext-field ext-workspace">${esc(text('工作区','Workspace'))}<select data-teams-workspace>${workspaces.map(w => `<option value="${esc(w.workspaceId)}">${esc(w.title || w.path || w.workspaceId)}</option>`).join('')}</select></label><label class="ext-check"><input type="checkbox" data-teams-archived> ${esc(text('查看归档团队','Archived teams'))}</label><button class="ext-button" type="button" data-teams-refresh>${esc(text('刷新','Refresh'))}</button></div><p class="ext-note" data-teams-status role="status" aria-live="polite"></p><div class="teams-list" data-teams-content></div></section>`
|
|
39
|
+
const selector = target.querySelector('[data-teams-workspace]'), content = target.querySelector('[data-teams-content]'), note = target.querySelector('[data-teams-status]')
|
|
40
|
+
selector.value = s.workspaceId
|
|
41
|
+
function render(data) {
|
|
42
|
+
const key = JSON.stringify([data.teams,s.archived])
|
|
43
|
+
if (key === s.renderKey) return
|
|
44
|
+
s.renderKey = key
|
|
45
|
+
const active = document.activeElement, focused = active?.closest?.('[data-team-open]')
|
|
46
|
+
const focusedTeam = focused?.closest?.('[data-team-id]')?.dataset.teamId, focusedMember = focused?.dataset.teamMember || ''
|
|
47
|
+
for (const detail of content.querySelectorAll('details[data-team-detail]')) s.expanded.set(detail.dataset.teamDetail, detail.open)
|
|
48
|
+
content.innerHTML = data.teams.length ? data.teams.map((team, index) => teamHtml(team, index, s.archived)).join('') : `<p class="ext-empty">${esc(text('此工作区暂无团队。','No teams in this workspace.'))}</p>`
|
|
49
|
+
for (const detail of content.querySelectorAll('details[data-team-detail]')) if (s.expanded.has(detail.dataset.teamDetail)) detail.open = s.expanded.get(detail.dataset.teamDetail)
|
|
50
|
+
if (focusedTeam) [...content.querySelectorAll('[data-team-open]')].find(el => data.teams[Number(el.dataset.teamOpen)]?.teamId === focusedTeam && (el.dataset.teamMember || '') === focusedMember)?.focus({ preventScroll:true })
|
|
51
|
+
}
|
|
52
|
+
async function load(clear = false) {
|
|
53
|
+
if (!valid()) { if (current === s) close(); return }
|
|
54
|
+
s.readController?.abort()
|
|
55
|
+
s.readController = new AbortController()
|
|
56
|
+
const request = ++s.request
|
|
57
|
+
if (clear) { s.data = null; s.renderKey = ''; s.expanded.clear(); content.replaceChildren() }
|
|
58
|
+
if (!s.workspaceId) { note.textContent = text('请先登记一个 DSH 工作区。','Register a DSH workspace first.'); return }
|
|
59
|
+
note.textContent = text('正在读取团队…','Loading teams…')
|
|
60
|
+
try {
|
|
61
|
+
const response = await fetch(config.url('/remote/api/teams?workspaceId=' + encodeURIComponent(s.workspaceId) + '&archived=' + (s.archived ? '1' : '0')), { headers: config.headers, signal: AbortSignal.any([s.controller.signal, s.readController.signal, AbortSignal.timeout(20000)]) })
|
|
62
|
+
const body = await response.text()
|
|
63
|
+
if (!valid() || request !== s.request) return
|
|
64
|
+
if (body.length > 2 * 1024 * 1024) throw Error('large')
|
|
65
|
+
const data = JSON.parse(body)
|
|
66
|
+
if (!response.ok || data.ok !== true) { root.DshExtensions?.reportAvailability?.(config, 'teams', { code: response.status === 401 || response.status === 403 ? 'host-denied' : data.code || (response.status === 404 ? 'endpoint-missing' : 'read-failed') }); throw Error('read') }
|
|
67
|
+
if (data.schema !== 1 || data.available !== false && (!Array.isArray(data.teams) || data.workspaceId !== s.workspaceId)) throw Error('schema')
|
|
68
|
+
root.DshExtensions?.reportAvailability?.(config, 'teams', data)
|
|
69
|
+
if (data.available === false) { s.data = null; s.renderKey = ''; content.replaceChildren(); note.textContent = data.code === 'endpoint-missing' ? text('主机团队接口尚未挂载。请核对插件是否启用,必要时重启 DSH 后刷新。','The host team endpoint is not mounted. Check that the plugin is enabled; restart DSH if needed, then refresh.') : text('主机未提供兼容的智能体团队接口。','No compatible AgentTeams endpoint on this host.'); return }
|
|
70
|
+
render(data); s.data = data
|
|
71
|
+
note.textContent = data.truncated ? text('团队较多,仅显示前 40 个。','Showing the first 40 teams.') : `${data.teams.length} ${text('个团队 · 已更新','teams · Updated')}`
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (valid() && request === s.request) {
|
|
74
|
+
if (error.message !== 'read') root.DshExtensions?.reportAvailability?.(config, 'teams', { code: error.message === 'schema' ? 'unsupported' : error.name === 'TimeoutError' ? 'timeout' : 'read-failed' })
|
|
75
|
+
note.textContent = s.data ? text('刷新失败,保留上次结果,可重试。','Refresh failed. Showing the previous result; retry is available.') : text('读取失败,请检查插件状态后重试。','Unable to load. Check plugin status and retry.')
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
selector.addEventListener('change', () => { s.workspaceId = selector.value; void load(true) })
|
|
80
|
+
target.querySelector('[data-teams-archived]').addEventListener('change', event => { s.archived = event.target.checked; void load(true) })
|
|
81
|
+
target.querySelector('[data-teams-refresh]').addEventListener('click', () => void load())
|
|
82
|
+
content.addEventListener('click', async event => {
|
|
83
|
+
const button = event.target.closest?.('[data-team-open]')
|
|
84
|
+
if (!button || !valid() || !s.data) return
|
|
85
|
+
const team = s.data.teams[Number(button.dataset.teamOpen)], member = button.dataset.teamMember
|
|
86
|
+
if (!team || !team.captainSessionId) return
|
|
87
|
+
button.disabled = true
|
|
88
|
+
try { if (member) await config.openTeamMember?.(member, team.captainSessionId); else await config.openTeamCaptain?.(team.captainSessionId) }
|
|
89
|
+
catch { if (valid()) note.textContent = text('会话暂不可读,请刷新后重试。','Session unavailable. Refresh and retry.') }
|
|
90
|
+
finally { if (valid()) button.disabled = false }
|
|
91
|
+
})
|
|
92
|
+
s.timer = setInterval(() => { if (!document.hidden) void load() }, 15000)
|
|
93
|
+
await load()
|
|
94
|
+
}
|
|
95
|
+
const api = { mount, close, teamHtml }
|
|
96
|
+
root.DshTeams = api
|
|
97
|
+
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
98
|
+
})(typeof window === 'undefined' ? globalThis : window)
|