dsh-powertools 0.0.0-stage → 0.2.2
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/LICENSE +21 -0
- package/README.md +98 -2
- package/client.js +3213 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +9 -0
- package/index.js +90 -0
- package/lib/credentials.js +173 -0
- package/lib/enhance.js +159 -0
- package/lib/errors.js +11 -0
- package/lib/instructions.js +298 -0
- package/lib/mcp.js +124 -0
- package/lib/platform.js +70 -0
- package/lib/sessions.js +516 -0
- package/lib/skill-repositories.js +152 -0
- package/lib/skills.js +280 -0
- package/lib/tasks.js +244 -0
- package/licenses/lucide.txt +43 -0
- package/licenses/magi-code.txt +203 -0
- package/locale/en.json +1 -0
- package/locale/zh.json +1 -0
- package/node_modules/yaml/LICENSE +13 -0
- package/node_modules/yaml/README.md +172 -0
- package/node_modules/yaml/bin.mjs +11 -0
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/node_modules/yaml/browser/dist/errors.js +57 -0
- package/node_modules/yaml/browser/dist/index.js +17 -0
- package/node_modules/yaml/browser/dist/log.js +11 -0
- package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
- package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
- package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
- package/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/node_modules/yaml/browser/dist/util.js +11 -0
- package/node_modules/yaml/browser/dist/visit.js +233 -0
- package/node_modules/yaml/browser/index.js +5 -0
- package/node_modules/yaml/browser/package.json +3 -0
- package/node_modules/yaml/dist/cli.d.ts +8 -0
- package/node_modules/yaml/dist/cli.mjs +201 -0
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/node_modules/yaml/dist/compose/composer.js +224 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/node_modules/yaml/dist/doc/Document.js +337 -0
- package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/node_modules/yaml/dist/doc/directives.js +178 -0
- package/node_modules/yaml/dist/errors.d.ts +21 -0
- package/node_modules/yaml/dist/errors.js +62 -0
- package/node_modules/yaml/dist/index.d.ts +25 -0
- package/node_modules/yaml/dist/index.js +50 -0
- package/node_modules/yaml/dist/log.d.ts +3 -0
- package/node_modules/yaml/dist/log.js +19 -0
- package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/Alias.js +120 -0
- package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/node_modules/yaml/dist/options.d.ts +350 -0
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/node_modules/yaml/dist/parse/cst.js +112 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/node_modules/yaml/dist/parse/parser.js +980 -0
- package/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/node_modules/yaml/dist/public-api.js +107 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/node_modules/yaml/dist/schema/tags.js +99 -0
- package/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/node_modules/yaml/dist/test-events.js +134 -0
- package/node_modules/yaml/dist/util.d.ts +16 -0
- package/node_modules/yaml/dist/util.js +28 -0
- package/node_modules/yaml/dist/visit.d.ts +102 -0
- package/node_modules/yaml/dist/visit.js +236 -0
- package/node_modules/yaml/package.json +97 -0
- package/node_modules/yaml/util.js +2 -0
- package/package.json +74 -4
package/client.js
ADDED
|
@@ -0,0 +1,3213 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-powertools',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const { Button, IconChevronRightOutlineRegular, writeClipboard } = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
6
|
+
const { createElement: h, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } = React
|
|
7
|
+
const PANEL = 'dsh-powertools'
|
|
8
|
+
const SESSION_LOCALE = `${PANEL}.sessions`
|
|
9
|
+
const sessionLocales = {
|
|
10
|
+
en: {
|
|
11
|
+
defaultWorkspace: 'Default workspace', ungrouped: 'Ungrouped', untitled: 'Untitled session', sessionId: 'Session ID',
|
|
12
|
+
workspaceDeleted: 'Workspace deleted', workspaceMissing: 'No registered workspace matches the working directory.',
|
|
13
|
+
delete: 'Delete session', deleteTitle: 'Delete “{title}”?', confirm: 'Confirm deletion',
|
|
14
|
+
cancel: 'Cancel', close: 'Close', checking: 'Checking session status…', deleting: 'Deleting session…',
|
|
15
|
+
missing: 'This session is no longer available.', blocked: 'This session cannot be deleted.',
|
|
16
|
+
running: 'Stop the running session before deleting it.', childRunning: 'Stop the linked subagent before deleting this session.',
|
|
17
|
+
resident: 'DSH is holding this session open. Restart DSH to release it before deleting.',
|
|
18
|
+
childResident: 'DSH is holding a linked subagent session open. Restart DSH to release it before deleting.',
|
|
19
|
+
storage: 'The session or a linked subagent is stored in a format that cannot be moved to recovery.',
|
|
20
|
+
recovery: 'The session and its linked subagent sessions will move to the recovery folder. Workspace files are kept.',
|
|
21
|
+
subagents: 'Linked subagent sessions: {count}',
|
|
22
|
+
deleted: 'Session moved to the recovery folder.', copyRecovery: 'Copy recovery path',
|
|
23
|
+
copyFailed: 'Could not copy the recovery path.',
|
|
24
|
+
refreshFailed: 'Session moved to the recovery folder. Reopen the app to refresh the list.',
|
|
25
|
+
},
|
|
26
|
+
zh: {
|
|
27
|
+
defaultWorkspace: '默认工作区', ungrouped: '未分组', untitled: '未命名会话', sessionId: '会话 ID',
|
|
28
|
+
workspaceDeleted: '工作区已删除', workspaceMissing: '工作目录没有对应的已登记工作区。',
|
|
29
|
+
delete: '删除会话', deleteTitle: '删除「{title}」?', confirm: '确认删除会话',
|
|
30
|
+
cancel: '取消', close: '关闭', checking: '正在核对会话状态…', deleting: '正在删除会话…',
|
|
31
|
+
missing: '目标会话不存在或已被移除。', blocked: '当前会话无法删除。',
|
|
32
|
+
running: '会话正在运行中,请先停止后再删除。', childRunning: '关联子 Agent 正在运行中,请先停止后再删除。',
|
|
33
|
+
resident: '会话正由当前 DSH 进程打开持有,请重启 DSH 释放后再删除。',
|
|
34
|
+
childResident: '关联子 Agent 会话仍由 DSH 持有,请重启 DSH 释放后再删除。',
|
|
35
|
+
storage: '会话或关联子 Agent 的存储格式不支持移至恢复目录。',
|
|
36
|
+
recovery: '会话及其关联的子 Agent 会话将移至恢复目录,工作区文件会保留。',
|
|
37
|
+
subagents: '关联的子 Agent 会话:{count} 条',
|
|
38
|
+
deleted: '会话已移至恢复目录。', copyRecovery: '复制恢复目录',
|
|
39
|
+
copyFailed: '无法复制恢复目录。',
|
|
40
|
+
refreshFailed: '会话已移至恢复目录。重新打开应用可刷新列表。',
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Lucide 1.61.0 icon geometry from Magi Code (web/src/lib/icons.ts), license in licenses/lucide.txt.
|
|
45
|
+
const ICONS = {
|
|
46
|
+
'layout-grid': [
|
|
47
|
+
['rect', { width: 7, height: 7, x: 3, y: 3, rx: 1 }],
|
|
48
|
+
['rect', { width: 7, height: 7, x: 14, y: 3, rx: 1 }],
|
|
49
|
+
['rect', { width: 7, height: 7, x: 14, y: 14, rx: 1 }],
|
|
50
|
+
['rect', { width: 7, height: 7, x: 3, y: 14, rx: 1 }],
|
|
51
|
+
],
|
|
52
|
+
'message-square': [
|
|
53
|
+
['path', { d: 'M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z' }],
|
|
54
|
+
],
|
|
55
|
+
plug: [
|
|
56
|
+
['path', { d: 'M12 22v-5' }],
|
|
57
|
+
['path', { d: 'M15 8V2' }],
|
|
58
|
+
['path', { d: 'M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z' }],
|
|
59
|
+
['path', { d: 'M9 8V2' }],
|
|
60
|
+
],
|
|
61
|
+
'wand-sparkles': [
|
|
62
|
+
['path', { d: 'm21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.21 1.21 0 0 0 1.72 0L21.64 5.36a1.21 1.21 0 0 0 0-1.72' }],
|
|
63
|
+
['path', { d: 'm14 7 3 3' }],
|
|
64
|
+
['path', { d: 'M5 6v4' }],
|
|
65
|
+
['path', { d: 'M19 14v4' }],
|
|
66
|
+
['path', { d: 'M10 2v2' }],
|
|
67
|
+
['path', { d: 'M7 8H3' }],
|
|
68
|
+
['path', { d: 'M21 16h-4' }],
|
|
69
|
+
['path', { d: 'M11 3H9' }],
|
|
70
|
+
],
|
|
71
|
+
enhance: [
|
|
72
|
+
['path', { d: 'M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z' }],
|
|
73
|
+
['path', { d: 'M20 2v4' }],
|
|
74
|
+
['path', { d: 'M22 4h-4' }],
|
|
75
|
+
['circle', { cx: 4, cy: 20, r: 2 }],
|
|
76
|
+
],
|
|
77
|
+
loader: [
|
|
78
|
+
['path', { d: 'M21 12a9 9 0 1 1-6.219-8.56' }],
|
|
79
|
+
],
|
|
80
|
+
undo: [
|
|
81
|
+
['path', { d: 'M9 14 4 9l5-5' }],
|
|
82
|
+
['path', { d: 'M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11' }],
|
|
83
|
+
],
|
|
84
|
+
plus: [
|
|
85
|
+
['path', { d: 'M5 12h14' }],
|
|
86
|
+
['path', { d: 'M12 5v14' }],
|
|
87
|
+
],
|
|
88
|
+
'refresh-cw': [
|
|
89
|
+
['path', { d: 'M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8' }],
|
|
90
|
+
['path', { d: 'M21 3v5h-5' }],
|
|
91
|
+
['path', { d: 'M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16' }],
|
|
92
|
+
['path', { d: 'M8 16H3v5' }],
|
|
93
|
+
],
|
|
94
|
+
'rotate-cw': [
|
|
95
|
+
['path', { d: 'M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8' }],
|
|
96
|
+
['path', { d: 'M21 3v5h-5' }],
|
|
97
|
+
],
|
|
98
|
+
play: [
|
|
99
|
+
['path', { d: 'M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z' }],
|
|
100
|
+
],
|
|
101
|
+
'square-pen': [
|
|
102
|
+
['path', { d: 'M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7' }],
|
|
103
|
+
['path', { d: 'M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z' }],
|
|
104
|
+
],
|
|
105
|
+
trash: [
|
|
106
|
+
['path', { d: 'M10 11v6' }],
|
|
107
|
+
['path', { d: 'M14 11v6' }],
|
|
108
|
+
['path', { d: 'M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6' }],
|
|
109
|
+
['path', { d: 'M3 6h18' }],
|
|
110
|
+
['path', { d: 'M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2' }],
|
|
111
|
+
],
|
|
112
|
+
archive: [
|
|
113
|
+
['rect', { width: 20, height: 5, x: 2, y: 3, rx: 1 }],
|
|
114
|
+
['path', { d: 'M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8' }],
|
|
115
|
+
['path', { d: 'M10 12h4' }],
|
|
116
|
+
],
|
|
117
|
+
'archive-restore': [
|
|
118
|
+
['rect', { width: 20, height: 5, x: 2, y: 3, rx: 1 }],
|
|
119
|
+
['path', { d: 'M4 8v11a2 2 0 0 0 2 2h2' }],
|
|
120
|
+
['path', { d: 'M20 8v11a2 2 0 0 1-2 2h-2' }],
|
|
121
|
+
['path', { d: 'm9 15 3-3 3 3' }],
|
|
122
|
+
['path', { d: 'M12 12v9' }],
|
|
123
|
+
],
|
|
124
|
+
eye: [
|
|
125
|
+
['path', { d: 'M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0' }],
|
|
126
|
+
['circle', { cx: 12, cy: 12, r: 3 }],
|
|
127
|
+
],
|
|
128
|
+
'folder-plus': [
|
|
129
|
+
['path', { d: 'M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z' }],
|
|
130
|
+
['path', { d: 'M12 10v6' }],
|
|
131
|
+
['path', { d: 'M9 13h6' }],
|
|
132
|
+
],
|
|
133
|
+
folder: [
|
|
134
|
+
['path', { d: 'M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z' }],
|
|
135
|
+
],
|
|
136
|
+
'external-link': [
|
|
137
|
+
['path', { d: 'M15 3h6v6' }],
|
|
138
|
+
['path', { d: 'M10 14 21 3' }],
|
|
139
|
+
['path', { d: 'M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6' }],
|
|
140
|
+
],
|
|
141
|
+
copy: [
|
|
142
|
+
['rect', { width: 14, height: 14, x: 8, y: 8, rx: 2, ry: 2 }],
|
|
143
|
+
['path', { d: 'M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2' }],
|
|
144
|
+
],
|
|
145
|
+
check: [
|
|
146
|
+
['path', { d: 'M20 6 9 17l-5-5' }],
|
|
147
|
+
],
|
|
148
|
+
x: [
|
|
149
|
+
['path', { d: 'M18 6 6 18' }],
|
|
150
|
+
['path', { d: 'm6 6 12 12' }],
|
|
151
|
+
],
|
|
152
|
+
'git-branch': [
|
|
153
|
+
['line', { x1: 6, x2: 6, y1: 3, y2: 15 }],
|
|
154
|
+
['circle', { cx: 18, cy: 6, r: 3 }],
|
|
155
|
+
['circle', { cx: 6, cy: 18, r: 3 }],
|
|
156
|
+
['path', { d: 'M18 9a9 9 0 0 1-9 9' }],
|
|
157
|
+
],
|
|
158
|
+
download: [
|
|
159
|
+
['path', { d: 'M12 15V3' }],
|
|
160
|
+
['path', { d: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4' }],
|
|
161
|
+
['path', { d: 'm7 10 5 5 5-5' }],
|
|
162
|
+
],
|
|
163
|
+
'chevrons-down-up': [
|
|
164
|
+
['path', { d: 'm7 20 5-5 5 5' }],
|
|
165
|
+
['path', { d: 'm7 4 5 5 5-5' }],
|
|
166
|
+
],
|
|
167
|
+
'key-round': [
|
|
168
|
+
['path', { d: 'M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z' }],
|
|
169
|
+
['circle', { cx: 16.5, cy: 7.5, r: 0.5, fill: 'currentColor' }],
|
|
170
|
+
],
|
|
171
|
+
clock: [
|
|
172
|
+
['circle', { cx: 12, cy: 12, r: 10 }],
|
|
173
|
+
['polyline', { points: '12 6 12 12 16 14' }],
|
|
174
|
+
],
|
|
175
|
+
terminal: [
|
|
176
|
+
['polyline', { points: '4 17 10 11 4 5' }],
|
|
177
|
+
['line', { x1: 12, x2: 20, y1: 19, y2: 19 }],
|
|
178
|
+
],
|
|
179
|
+
'file-text': [
|
|
180
|
+
['path', { d: 'M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z' }],
|
|
181
|
+
['path', { d: 'M14 2v4a2 2 0 0 0 2 2h4' }],
|
|
182
|
+
['path', { d: 'M10 9H8' }],
|
|
183
|
+
['path', { d: 'M16 13H8' }],
|
|
184
|
+
['path', { d: 'M16 17H8' }],
|
|
185
|
+
],
|
|
186
|
+
pause: [
|
|
187
|
+
['rect', { x: 14, y: 4, width: 4, height: 16, rx: 1 }],
|
|
188
|
+
['rect', { x: 6, y: 4, width: 4, height: 16, rx: 1 }],
|
|
189
|
+
],
|
|
190
|
+
square: [
|
|
191
|
+
['rect', { width: 18, height: 18, x: 3, y: 3, rx: 2 }],
|
|
192
|
+
],
|
|
193
|
+
pin: [
|
|
194
|
+
['path', { d: 'M12 17v5' }],
|
|
195
|
+
['path', { d: 'M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z' }],
|
|
196
|
+
],
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function Icon({ name, size = 14, className = '' }) {
|
|
200
|
+
const shapes = ICONS[name]
|
|
201
|
+
if (!shapes) return null
|
|
202
|
+
return h('svg', {
|
|
203
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
|
|
204
|
+
stroke: 'currentColor', strokeWidth: 1.75, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
205
|
+
'aria-hidden': true, 'data-icon': name, className: `dpt-icon${className ? ` ${className}` : ''}`,
|
|
206
|
+
}, ...shapes.map(([tag, attrs], index) => h(tag, { key: index, ...attrs })))
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const css = `
|
|
210
|
+
.dpt {
|
|
211
|
+
--dpt-line: var(--dsw-alias-border-l2);
|
|
212
|
+
--dpt-module: var(--dsw-alias-bg-module-platform, var(--dsw-alias-bg-layer-2));
|
|
213
|
+
--dpt-entry: var(--dsw-alias-bg-base, var(--dsw-alias-bg-layer-1));
|
|
214
|
+
--dpt-muted: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
|
|
215
|
+
--dpt-accent: var(--dsw-alias-state-business-primary);
|
|
216
|
+
--dpt-danger: var(--dsw-alias-state-error-primary);
|
|
217
|
+
--dpt-ease: 140ms var(--ds-ease-in-out, cubic-bezier(.4, 0, .2, 1));
|
|
218
|
+
color: var(--dsw-alias-label-primary);
|
|
219
|
+
font-size: 13px;
|
|
220
|
+
line-height: 20px;
|
|
221
|
+
font-weight: 400;
|
|
222
|
+
min-width: 0;
|
|
223
|
+
container-type: inline-size;
|
|
224
|
+
}
|
|
225
|
+
.dpt *, .dpt *::before { box-sizing: border-box; }
|
|
226
|
+
.dpt-icon { display: block; flex: 0 0 auto; }
|
|
227
|
+
@keyframes dpt-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
228
|
+
.dpt-spin { animation: dpt-spin 900ms linear infinite; }
|
|
229
|
+
.dpt h1, .dpt h2, .dpt h3, .dpt p, .dpt ul, .dpt dl, .dpt dd { margin: 0; }
|
|
230
|
+
.dpt h1 { font-size: 20px; line-height: 28px; font-weight: 500; }
|
|
231
|
+
.dpt h2 { font-size: 16px; line-height: 24px; font-weight: 500; overflow-wrap: anywhere; }
|
|
232
|
+
.dpt h3 { font-size: 14px; line-height: 20px; font-weight: 500; }
|
|
233
|
+
.dpt a, .dpt button, .dpt input, .dpt select, .dpt textarea { font: inherit; }
|
|
234
|
+
.dpt-page {
|
|
235
|
+
width: 100%; height: 100%; min-height: 0; overflow-x: hidden; overflow-y: auto;
|
|
236
|
+
scrollbar-gutter: stable; background: var(--dsw-alias-bg-base);
|
|
237
|
+
--dsh-scrollbar-width: 9px; --dsh-scrollbar-thumb-border: 2px;
|
|
238
|
+
}
|
|
239
|
+
.dpt-page-inner { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 clamp(24px, 4vw, 48px) 48px; }
|
|
240
|
+
@media (max-width: 767px) { .dpt-page-inner { padding-inline: 20px; } }
|
|
241
|
+
.dpt-inline { width: 100%; padding: 0; }
|
|
242
|
+
.dpt-page-head { display: flex; align-items: center; gap: 12px; padding-top: 28px; margin-bottom: 14px; }
|
|
243
|
+
[data-platform='darwin'] .dpt-page .dpt-page-head { padding-top: calc(28px + var(--dsh-frame-top-clearance, 0px)); }
|
|
244
|
+
.dpt-page-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--dsw-radius-sm, 8px); background: var(--dpt-module); color: var(--dsw-alias-label-primary); }
|
|
245
|
+
.dpt-controls { display: grid; gap: 14px; }
|
|
246
|
+
.dpt-panel { display: grid; gap: 12px; min-width: 0; }
|
|
247
|
+
.dpt-bar, .dpt-actions, .dpt-nav, .dpt-form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
248
|
+
.dpt-nav { gap: 4px; border-bottom: .5px solid var(--dpt-line); }
|
|
249
|
+
.dpt-nav .dpt-tab {
|
|
250
|
+
position: relative; min-height: 34px; padding: 0 12px; border-radius: 6px 6px 0 0;
|
|
251
|
+
color: var(--dpt-muted); background: transparent;
|
|
252
|
+
}
|
|
253
|
+
.dpt-nav .dpt-tab[aria-pressed='true'] { color: var(--dsw-alias-label-primary); font-weight: 500; background: transparent; }
|
|
254
|
+
.dpt-nav .dpt-tab[aria-pressed='true']::after {
|
|
255
|
+
content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px;
|
|
256
|
+
border-radius: 2px; background: var(--dpt-accent);
|
|
257
|
+
}
|
|
258
|
+
/* Unified single-row sticky toolbar with clickable segmented pills */
|
|
259
|
+
.dpt-toolbar {
|
|
260
|
+
display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-width: 0;
|
|
261
|
+
}
|
|
262
|
+
@container (min-width: 561px) {
|
|
263
|
+
.dpt-page .dpt-toolbar {
|
|
264
|
+
position: sticky; top: 0; z-index: 10; padding-block: 6px; margin-block: -6px -2px;
|
|
265
|
+
background: var(--dsw-alias-bg-base);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
.dpt-toolbar-right {
|
|
269
|
+
display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; flex: 1 1 auto; min-width: 0;
|
|
270
|
+
}
|
|
271
|
+
.dpt-seg {
|
|
272
|
+
display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 2px;
|
|
273
|
+
border-radius: var(--dsw-radius-sm, 8px); background: var(--dpt-module); border: .5px solid var(--dpt-line);
|
|
274
|
+
}
|
|
275
|
+
.dpt-seg-btn {
|
|
276
|
+
display: inline-flex; align-items: center; gap: 5px; min-height: 26px; padding: 0 9px;
|
|
277
|
+
border: 0; border-radius: 6px; background: transparent; color: var(--dpt-muted);
|
|
278
|
+
font-size: 12.5px; line-height: 18px; cursor: pointer; white-space: nowrap;
|
|
279
|
+
transition: background var(--dpt-ease), color var(--dpt-ease);
|
|
280
|
+
}
|
|
281
|
+
.dpt-seg-btn[aria-pressed='true'] {
|
|
282
|
+
background: var(--dpt-entry); color: var(--dsw-alias-label-primary); font-weight: 500;
|
|
283
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 7%);
|
|
284
|
+
}
|
|
285
|
+
.dpt-seg-count { font-size: 11px; color: var(--dpt-muted); font-weight: 400; }
|
|
286
|
+
.dpt-seg-btn[aria-pressed='true'] .dpt-seg-count { color: var(--dsw-alias-label-secondary); }
|
|
287
|
+
.dpt-seg-btn[data-alert='true'] .dpt-seg-count { color: var(--dsw-alias-state-warn-primary); font-weight: 500; }
|
|
288
|
+
.dpt .dpt-button {
|
|
289
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 5px;
|
|
290
|
+
max-width: 100%; min-height: 30px; height: auto; padding: 0 10px; font-size: 13px; line-height: 20px;
|
|
291
|
+
white-space: nowrap;
|
|
292
|
+
transition: background var(--dpt-ease), box-shadow var(--dpt-ease), color var(--dpt-ease);
|
|
293
|
+
}
|
|
294
|
+
.dpt .dpt-icon-btn { width: 30px; min-width: 30px; min-height: 30px; padding: 0; color: var(--dsw-alias-label-secondary); }
|
|
295
|
+
.dpt .dpt-row-btn { min-height: 26px; padding: 0 8px; font-size: 12px; line-height: 18px; }
|
|
296
|
+
.dpt .dpt-row-icon-btn { width: 26px; min-width: 26px; min-height: 26px; padding: 0; color: var(--dsw-alias-label-secondary); }
|
|
297
|
+
.dpt .dpt-button:disabled { cursor: default; }
|
|
298
|
+
.dpt .dpt-primary { background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground); font-weight: 500; }
|
|
299
|
+
.dpt .dpt-danger { color: var(--dpt-danger); }
|
|
300
|
+
.dpt :is(button, input, select, textarea):focus-visible {
|
|
301
|
+
outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dpt-accent));
|
|
302
|
+
outline-offset: 1px;
|
|
303
|
+
}
|
|
304
|
+
.dpt :is(input:not([type='checkbox']), select, textarea) {
|
|
305
|
+
min-width: 0; max-width: 100%; height: 30px; padding: 0 10px; color: inherit;
|
|
306
|
+
border: .5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-sm, 8px);
|
|
307
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
308
|
+
}
|
|
309
|
+
.dpt .dpt-form :is(input:not([type='checkbox']), select) { height: 32px; }
|
|
310
|
+
.dpt .dpt-search { width: auto; flex: 1 1 130px; max-width: 220px; font-size: 12.5px; }
|
|
311
|
+
.dpt .dpt-toolbar-right select { font-size: 12.5px; padding-inline: 8px; }
|
|
312
|
+
.dpt :is(input, select, textarea):focus { border-color: var(--dpt-accent); }
|
|
313
|
+
.dpt textarea { height: auto; padding-block: 6px; }
|
|
314
|
+
.dpt textarea.dpt-fixed-editor { height: 180px; resize: none; overflow-y: auto; }
|
|
315
|
+
.dpt input.dpt-inline-filter { height: 28px; padding: 0 8px; font-size: 12px; width: 180px; max-width: 100%; }
|
|
316
|
+
@media (hover: hover) {
|
|
317
|
+
.dpt .dpt-button:hover:not(:disabled), .dpt .dpt-row-main:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
318
|
+
.dpt .dpt-seg-btn:hover:not([aria-pressed='true']) { color: var(--dsw-alias-label-primary); }
|
|
319
|
+
.dpt .dpt-nav .dpt-tab:hover:not(:disabled) { color: var(--dsw-alias-label-primary); }
|
|
320
|
+
.dpt .dpt-primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-fill); box-shadow: inset 0 0 0 1000px var(--dsw-alias-interactive-bg-hover); }
|
|
321
|
+
.dpt .dpt-danger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dpt-danger); }
|
|
322
|
+
.dpt .dpt-icon-btn:hover:not(:disabled), .dpt .dpt-row-icon-btn:hover:not(:disabled) { color: var(--dsw-alias-label-primary); }
|
|
323
|
+
}
|
|
324
|
+
.dpt-card {
|
|
325
|
+
min-width: 0; overflow: hidden; border: .5px solid var(--dsw-alias-settings-card-stroke, var(--dpt-line));
|
|
326
|
+
border-radius: var(--dsw-radius-md, 10px);
|
|
327
|
+
background: var(--dsw-alias-settings-card-fill, var(--dsw-alias-bg-layer-1));
|
|
328
|
+
}
|
|
329
|
+
.dpt ul.dpt-card { padding: 0; list-style: none; }
|
|
330
|
+
.dpt-row + .dpt-row { border-top: .5px solid var(--dpt-line); }
|
|
331
|
+
.dpt-sentinel { height: 1px; border: 0; padding: 0; margin: 0; pointer-events: none; }
|
|
332
|
+
.dpt-subhead {
|
|
333
|
+
padding: 5px 16px; background: color-mix(in srgb, var(--dpt-module) 55%, transparent);
|
|
334
|
+
color: var(--dpt-muted); font-size: 11.5px; line-height: 18px; font-weight: 500;
|
|
335
|
+
}
|
|
336
|
+
.dpt-subhead:not(:first-child) { border-top: .5px solid var(--dpt-line); }
|
|
337
|
+
.dpt-subhead + .dpt-row { border-top: .5px solid var(--dpt-line); }
|
|
338
|
+
.dpt-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 8px; }
|
|
339
|
+
.dpt-section-body { display: grid; gap: 8px; min-width: 0; }
|
|
340
|
+
/* High-density row with hover-swap checkbox and 1-click trailing actions */
|
|
341
|
+
.dpt-row-main {
|
|
342
|
+
display: flex; align-items: center; min-width: 0;
|
|
343
|
+
transition: background var(--dpt-ease);
|
|
344
|
+
}
|
|
345
|
+
.dpt-row[data-selected='true'] > .dpt-row-main {
|
|
346
|
+
background: color-mix(in srgb, var(--dpt-accent) 7%, transparent);
|
|
347
|
+
}
|
|
348
|
+
.dpt-lead-cell {
|
|
349
|
+
position: relative; display: grid; place-items: center; width: 36px; align-self: stretch;
|
|
350
|
+
flex: 0 0 36px; cursor: pointer; user-select: none;
|
|
351
|
+
}
|
|
352
|
+
.dpt-lead-cell .dpt-indicator { transition: opacity 120ms ease; }
|
|
353
|
+
.dpt-row-checkbox {
|
|
354
|
+
position: absolute; width: 15px; height: 15px; margin: 0; cursor: pointer;
|
|
355
|
+
accent-color: var(--dpt-accent); opacity: 0; transition: opacity 120ms ease;
|
|
356
|
+
}
|
|
357
|
+
@media (pointer: coarse) {
|
|
358
|
+
.dpt-lead-cell .dpt-indicator { opacity: 0; }
|
|
359
|
+
.dpt-row-checkbox { opacity: .65; }
|
|
360
|
+
}
|
|
361
|
+
.dpt-row-main:hover .dpt-lead-cell .dpt-indicator,
|
|
362
|
+
.dpt-lead-cell:focus-within .dpt-indicator,
|
|
363
|
+
.dpt-card[data-selecting='true'] .dpt-lead-cell .dpt-indicator { opacity: 0; }
|
|
364
|
+
.dpt-row-main:hover .dpt-row-checkbox,
|
|
365
|
+
.dpt-lead-cell:focus-within .dpt-row-checkbox,
|
|
366
|
+
.dpt-card[data-selecting='true'] .dpt-row-checkbox { opacity: 1; }
|
|
367
|
+
.dpt .dpt-disclosure {
|
|
368
|
+
display: flex; align-items: center; gap: 10px; text-align: start; cursor: pointer;
|
|
369
|
+
flex: 1; min-width: 0; padding: 9px 10px 9px 16px; border: 0; border-radius: 0; background: transparent; color: inherit;
|
|
370
|
+
}
|
|
371
|
+
.dpt-lead-cell + .dpt-disclosure { padding-inline-start: 0; }
|
|
372
|
+
.dpt .dpt-disclosure:focus-visible { outline-offset: -2px; }
|
|
373
|
+
.dpt-row-end {
|
|
374
|
+
display: flex; align-items: center; gap: 8px; padding-inline-end: 16px; flex: 0 0 auto;
|
|
375
|
+
}
|
|
376
|
+
.dpt-row-toggle-tail {
|
|
377
|
+
display: inline-flex; align-items: center; gap: 8px; cursor: pointer; align-self: stretch;
|
|
378
|
+
}
|
|
379
|
+
.dpt-quick-actions {
|
|
380
|
+
display: inline-flex; align-items: center; gap: 3px;
|
|
381
|
+
}
|
|
382
|
+
@media (hover: hover) {
|
|
383
|
+
.dpt-quick-actions--hover { opacity: 0; transition: opacity 120ms ease; }
|
|
384
|
+
.dpt-row-main:hover .dpt-quick-actions--hover,
|
|
385
|
+
.dpt-row-main:focus-within .dpt-quick-actions--hover,
|
|
386
|
+
.dpt-row[data-open='true'] .dpt-quick-actions--hover { opacity: 1; }
|
|
387
|
+
}
|
|
388
|
+
.dpt-switch {
|
|
389
|
+
width: 32px; height: 18px; padding: 2px; border: 0; border-radius: 999px;
|
|
390
|
+
background: var(--dsw-alias-border-l4, var(--dpt-line)); cursor: pointer;
|
|
391
|
+
display: inline-flex; align-items: center; flex: 0 0 32px;
|
|
392
|
+
transition: background var(--dpt-ease);
|
|
393
|
+
}
|
|
394
|
+
.dpt-switch[aria-checked='true'] { background: var(--dpt-accent); }
|
|
395
|
+
.dpt-switch:disabled { opacity: .45; cursor: default; }
|
|
396
|
+
.dpt-switch-thumb {
|
|
397
|
+
width: 14px; height: 14px; border-radius: 50%; background: #fff;
|
|
398
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 22%);
|
|
399
|
+
transition: transform var(--dpt-ease);
|
|
400
|
+
}
|
|
401
|
+
.dpt-switch[aria-checked='true'] .dpt-switch-thumb { transform: translateX(14px); }
|
|
402
|
+
.dpt-row-label { display: grid; gap: 1px; flex: 1; min-width: 0; }
|
|
403
|
+
.dpt-row-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 6px; min-width: 0; }
|
|
404
|
+
.dpt-row-meta .dpt-row-summary { flex: 1 1 10ch; }
|
|
405
|
+
.dpt-workspace-badges { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px; min-width: 0; max-inline-size: 100%; }
|
|
406
|
+
.dpt-workspace-badge {
|
|
407
|
+
display: inline-block; max-inline-size: 100%; min-inline-size: 0;
|
|
408
|
+
padding: 0 6px; border: 1px solid color-mix(in srgb, var(--dpt-workspace-color) 48%, transparent);
|
|
409
|
+
border-radius: 999px; background: color-mix(in srgb, var(--dpt-workspace-color) 19%, transparent);
|
|
410
|
+
color: var(--dsw-alias-label-primary); font-size: 11px; line-height: 15px;
|
|
411
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
412
|
+
}
|
|
413
|
+
.dpt-workspace-badge[data-workspace-missing] { color: var(--dpt-workspace-color); }
|
|
414
|
+
.dpt-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
415
|
+
.dpt-row-title strong { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
416
|
+
.dpt-row-tag { min-width: 0; color: var(--dpt-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
417
|
+
.dpt-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
418
|
+
.dpt-indicator { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; background: var(--dpt-tone, var(--dpt-muted)); }
|
|
419
|
+
.dpt[data-tone='ready'], .dpt [data-tone='ready'] { --dpt-tone: var(--dsw-alias-state-success-primary); }
|
|
420
|
+
.dpt[data-tone='attention'], .dpt [data-tone='attention'] { --dpt-tone: var(--dsw-alias-state-warn-primary); }
|
|
421
|
+
.dpt[data-tone='info'], .dpt [data-tone='info'] { --dpt-tone: var(--dpt-accent); }
|
|
422
|
+
.dpt-pill {
|
|
423
|
+
flex: 0 0 auto; padding: 1px 7px; border-radius: 999px; font-size: 11px; line-height: 17px;
|
|
424
|
+
color: var(--dsw-alias-label-secondary); background: var(--dpt-module); border: .5px solid transparent;
|
|
425
|
+
}
|
|
426
|
+
.dpt-pill:not([data-tone='idle']) {
|
|
427
|
+
color: var(--dpt-tone); background: color-mix(in srgb, var(--dpt-tone) 12%, transparent);
|
|
428
|
+
border-color: color-mix(in srgb, var(--dpt-tone) 24%, transparent);
|
|
429
|
+
}
|
|
430
|
+
.dpt-chevron {
|
|
431
|
+
display: grid; place-items: center; flex: 0 0 20px; width: 20px; height: 20px; color: var(--dpt-muted);
|
|
432
|
+
transition: transform var(--dpt-ease);
|
|
433
|
+
}
|
|
434
|
+
.dpt-row[data-open='true'] .dpt-chevron { transform: rotate(90deg); }
|
|
435
|
+
/* Flat full-bleed disclosure drawer: max 2 visual layers */
|
|
436
|
+
.dpt-drawer {
|
|
437
|
+
margin: 0; padding: 10px 16px 12px 36px; min-width: 0; display: grid; gap: 10px;
|
|
438
|
+
border-top: 1px dashed var(--dpt-line);
|
|
439
|
+
background: color-mix(in srgb, var(--dpt-module) 68%, var(--dsw-alias-bg-base));
|
|
440
|
+
}
|
|
441
|
+
.dpt-drawer[hidden] { display: none; }
|
|
442
|
+
.dpt-drawer-bar {
|
|
443
|
+
display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; min-width: 0;
|
|
444
|
+
}
|
|
445
|
+
.dpt-drawer-facts {
|
|
446
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 12px; color: var(--dpt-muted); min-width: 0;
|
|
447
|
+
}
|
|
448
|
+
.dpt-drawer-facts > span { display: inline-flex; align-items: baseline; gap: 5px; min-width: 0; }
|
|
449
|
+
.dpt-drawer-facts strong { font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
450
|
+
.dpt-drawer-split {
|
|
451
|
+
padding-top: 10px; border-top: .5px solid var(--dpt-line); min-width: 0; display: grid; gap: 8px;
|
|
452
|
+
}
|
|
453
|
+
/* Floating bottom multi-select action bar (zero layout shift) */
|
|
454
|
+
.dpt-floating-batch {
|
|
455
|
+
position: sticky; bottom: 14px; z-index: 25; justify-self: center;
|
|
456
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
|
|
457
|
+
max-width: 100%; padding: 6px 10px 6px 14px; border-radius: 999px;
|
|
458
|
+
border: .5px solid var(--dsw-alias-border-l3, var(--dpt-line));
|
|
459
|
+
background: color-mix(in srgb, var(--dsw-alias-bg-layer-1) 92%, var(--dpt-module));
|
|
460
|
+
backdrop-filter: blur(12px);
|
|
461
|
+
box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
|
|
462
|
+
}
|
|
463
|
+
.dpt-batch-sep { width: 1px; height: 16px; background: var(--dpt-line); flex: 0 0 1px; }
|
|
464
|
+
/* Non-shifting floating toast for transient feedback & recovery paths */
|
|
465
|
+
.dpt-toast {
|
|
466
|
+
position: fixed; right: 20px; bottom: 20px; z-index: 45;
|
|
467
|
+
width: max-content; max-width: min(440px, calc(100vw - 32px));
|
|
468
|
+
display: flex; align-items: start; gap: 10px; padding: 8px 10px 8px 14px;
|
|
469
|
+
border-radius: var(--dsw-radius-md, 10px);
|
|
470
|
+
border: .5px solid var(--dsw-alias-border-l3, var(--dpt-line));
|
|
471
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
472
|
+
box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
|
|
473
|
+
transition: bottom var(--dpt-ease);
|
|
474
|
+
}
|
|
475
|
+
.dpt-controls:has(.dpt-floating-batch) > .dpt-toast { bottom: 68px; }
|
|
476
|
+
.dpt-toast[data-error='true'] { border-color: color-mix(in srgb, var(--dpt-danger) 45%, var(--dpt-line)); }
|
|
477
|
+
.dpt-toast-body { flex: 1; min-width: 0; display: grid; gap: 4px; padding-block: 2px; font-size: 12.5px; line-height: 18px; }
|
|
478
|
+
.dpt-toast[data-error='true'] .dpt-toast-body { color: var(--dpt-danger); }
|
|
479
|
+
.dpt-field > span, .dpt-label { color: var(--dpt-muted); font-size: 12px; line-height: 18px; font-weight: 500; }
|
|
480
|
+
.dpt-message-text, .dpt-muted { min-width: 0; overflow-wrap: anywhere; }
|
|
481
|
+
.dpt-muted, .dpt-summary { color: var(--dpt-muted); font-size: 12px; line-height: 18px; }
|
|
482
|
+
.dpt, .dpt-modal { font-variant-numeric: tabular-nums; }
|
|
483
|
+
.dpt .dpt-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 18px; }
|
|
484
|
+
@media (pointer: coarse) { .dpt :is(input, select, textarea), .dpt :is(input, textarea).dpt-mono { font-size: 16px; } }
|
|
485
|
+
.dpt-empty { padding: 14px 16px; }
|
|
486
|
+
.dpt-empty-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
|
|
487
|
+
.dpt-scroll-box { max-height: 220px; overflow-y: auto; padding-inline-end: 4px; }
|
|
488
|
+
.dpt-repo-scroll { max-height: 420px; overflow-y: auto; padding-inline-end: 4px; }
|
|
489
|
+
.dpt-message {
|
|
490
|
+
display: flex; align-items: start; gap: 8px; padding: 5px 10px; min-width: 0;
|
|
491
|
+
border-radius: var(--dsw-radius-sm, 7px);
|
|
492
|
+
background: color-mix(in srgb, var(--dpt-entry) 70%, var(--dpt-module));
|
|
493
|
+
}
|
|
494
|
+
.dpt-message-text { flex: 1; padding-block: 2px; font-size: 12px; line-height: 18px; }
|
|
495
|
+
.dpt-message [role='alert'] { color: var(--dpt-danger); }
|
|
496
|
+
.dpt .dpt-close { width: 22px; min-height: 22px; padding: 0; flex: 0 0 auto; color: var(--dpt-muted); }
|
|
497
|
+
.dpt-actions { justify-content: flex-end; gap: 6px; }
|
|
498
|
+
.dpt-path { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 10px; }
|
|
499
|
+
.dpt-path code { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
|
|
500
|
+
.dpt .dpt-copy { width: 76px; min-width: 76px; min-height: 26px; font-size: 12px; }
|
|
501
|
+
.dpt .dpt-copy[data-copied] { color: var(--dsw-alias-state-success-primary); }
|
|
502
|
+
.dpt-form { display: grid; gap: 10px; }
|
|
503
|
+
.dpt-edit { display: grid; gap: 10px; min-width: 0; }
|
|
504
|
+
.dpt-field { display: grid; gap: 4px; min-width: 0; }
|
|
505
|
+
.dpt-field textarea { width: 100%; resize: vertical; }
|
|
506
|
+
.dpt-field textarea.dpt-fixed-editor { height: 180px; resize: none; overflow-y: auto; }
|
|
507
|
+
.dpt-form-row .dpt-field { flex: 1 1 180px; }
|
|
508
|
+
.dpt ul.dpt-repo-skills { list-style: none; display: grid; gap: 0; padding: 0; border-top: .5px solid var(--dpt-line); }
|
|
509
|
+
.dpt-repo-skill { padding: 10px 0; display: grid; gap: 6px; min-width: 0; }
|
|
510
|
+
.dpt-repo-skill + .dpt-repo-skill { border-top: .5px solid var(--dpt-line); }
|
|
511
|
+
.dpt-argument-row { display: flex; gap: 6px; min-width: 0; }
|
|
512
|
+
.dpt-argument-row input { flex: 1 1 0; }
|
|
513
|
+
.dpt-check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; }
|
|
514
|
+
.dpt-check input[type='checkbox'] { accent-color: var(--dpt-accent); cursor: pointer; }
|
|
515
|
+
.dpt-tool-list { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
516
|
+
.dpt-tool-chip {
|
|
517
|
+
padding: 1px 7px; border-radius: 5px; border: .5px solid var(--dpt-line);
|
|
518
|
+
background: var(--dpt-entry); color: var(--dsw-alias-label-primary);
|
|
519
|
+
}
|
|
520
|
+
.dpt-file-list { list-style: none; display: grid; gap: 4px; padding: 0; margin: 0; }
|
|
521
|
+
.dpt-file-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--dpt-muted); }
|
|
522
|
+
.dpt-modal {
|
|
523
|
+
width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
|
|
524
|
+
border: .5px solid var(--dpt-line); border-radius: var(--dsw-radius-lg, 14px);
|
|
525
|
+
color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1); padding: 20px;
|
|
526
|
+
}
|
|
527
|
+
.dpt-modal::backdrop { background: var(--dsw-alias-bg-mask-1, rgb(0 0 0 / 24%)); }
|
|
528
|
+
.dpt-review { width: min(700px, calc(100vw - 32px)); }
|
|
529
|
+
.dpt-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
|
|
530
|
+
.dpt-confirm-list { display: grid; gap: 8px; }
|
|
531
|
+
.dpt-confirm-list > section { padding: 8px 10px; border-radius: var(--dsw-radius-sm, 8px); background: var(--dpt-module); }
|
|
532
|
+
.dpt-confirm-list ul { padding-inline-start: 18px; }
|
|
533
|
+
.dpt pre { margin: 0; font: inherit; border: .5px solid var(--dpt-line); border-radius: var(--dsw-radius-sm, 8px); background: var(--dpt-entry); padding: 10px; max-height: 38dvh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
534
|
+
.dpt-composer { display: inline-flex; gap: 6px; align-items: center; container-type: normal; }
|
|
535
|
+
.dpt-composer-action--fallback {
|
|
536
|
+
display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0;
|
|
537
|
+
border: 0; border-radius: 50%; corner-shape: round;
|
|
538
|
+
cursor: pointer; transition: background-color 100ms ease;
|
|
539
|
+
}
|
|
540
|
+
.dpt .dpt-composer-action {
|
|
541
|
+
background: var(--dsw-specific-selector);
|
|
542
|
+
color: var(--dsw-alias-label-primary);
|
|
543
|
+
}
|
|
544
|
+
.dpt .dpt-composer-action:disabled { opacity: 1; cursor: default; }
|
|
545
|
+
.dpt-composer-action:disabled svg { opacity: .4; }
|
|
546
|
+
.dpt-composer-action.dpt-composer-undo {
|
|
547
|
+
background: var(--dsw-alias-button-tool-bar-fill);
|
|
548
|
+
color: var(--dsw-alias-label-secondary);
|
|
549
|
+
}
|
|
550
|
+
@media (hover: hover) {
|
|
551
|
+
.dpt .dpt-composer-action:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-solid); }
|
|
552
|
+
.dpt .dpt-composer-action.dpt-composer-undo:hover {
|
|
553
|
+
background: var(--dsw-alias-button-tool-bar-hover);
|
|
554
|
+
color: var(--dsw-alias-label-primary);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
.dpt-composer .dpt-message { font-size: 11px; max-width: 180px; padding: 2px 6px; }
|
|
558
|
+
@container (max-width: 560px) {
|
|
559
|
+
.dpt .dpt-search, .dpt-bar > input[type='search'] { flex: 1 1 100%; width: 100%; }
|
|
560
|
+
.dpt-toolbar-right { justify-content: flex-start; width: 100%; }
|
|
561
|
+
.dpt-quick-actions--hover { display: none; }
|
|
562
|
+
.dpt-summary { white-space: normal; overflow-wrap: anywhere; }
|
|
563
|
+
.dpt-row-summary { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
|
|
564
|
+
.dpt-actions { row-gap: 4px; }
|
|
565
|
+
.dpt-drawer { padding: 10px 12px 12px 12px; }
|
|
566
|
+
.dpt-floating-batch { border-radius: var(--dsw-radius-md, 10px); }
|
|
567
|
+
}
|
|
568
|
+
@media (prefers-reduced-motion: reduce) {
|
|
569
|
+
.dpt button, .dpt-chevron, .dpt-composer-action, .dpt-switch, .dpt-switch-thumb { transition: none; }
|
|
570
|
+
.dpt-spin { animation: none; }
|
|
571
|
+
}
|
|
572
|
+
`
|
|
573
|
+
|
|
574
|
+
async function request(feature, payload = {}, signal) {
|
|
575
|
+
const response = await fetch('api/dsh-powertools', {
|
|
576
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
577
|
+
body: JSON.stringify({ feature, ...payload }), signal,
|
|
578
|
+
})
|
|
579
|
+
const value = await response.json().catch(() => null)
|
|
580
|
+
if (!response.ok || !value) throw new Error(value?.error ?? '无法连接 DSH 工具箱。')
|
|
581
|
+
return value
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const button = (text, click, { className = '', icon, iconSize = 14, iconClass = '', ...props } = {}) => h(Button, {
|
|
585
|
+
size: 'sm', onClick: click, ...props, className: `dpt-button ${className}`,
|
|
586
|
+
}, icon && h(Icon, { name: icon, size: iconSize, className: iconClass }), text)
|
|
587
|
+
const primary = (text, click, props) => button(text, click, { variant: 'primary', className: 'dpt-primary', ...props })
|
|
588
|
+
const iconButton = (label, icon, click, { className = '', iconSize = 14, iconClass = '', ...props } = {}) => button('', click, {
|
|
589
|
+
icon, iconSize, iconClass, className: `dpt-icon-btn ${className}`, 'aria-label': label, title: props.title ?? label, ...props,
|
|
590
|
+
})
|
|
591
|
+
const option = (value, text) => h('option', { key: value, value }, text)
|
|
592
|
+
const field = (label, control) => h('label', { className: 'dpt-field' }, h('span', null, label), control)
|
|
593
|
+
const muted = (text, props) => h('p', { className: 'dpt-muted', ...props }, text)
|
|
594
|
+
const code = text => h('code', { className: 'dpt-mono', dir: 'ltr' }, text)
|
|
595
|
+
const filterInput = (label, value, set, className = 'dpt-search') => h('input', {
|
|
596
|
+
type: 'search', className, 'aria-label': label, placeholder: label, value,
|
|
597
|
+
onChange: e => set(e.target.value),
|
|
598
|
+
onKeyDown: e => { if (e.key === 'Escape' && value) { e.preventDefault(); set('') } },
|
|
599
|
+
})
|
|
600
|
+
const pick = (label, value, set, options) => h('select', { 'aria-label': label, value, onChange: e => set(e.target.value) }, options)
|
|
601
|
+
const feedback = (message, error, dismiss) => message && h('div', { className: 'dpt-message' },
|
|
602
|
+
h('div', { className: 'dpt-message-text', role: error ? 'alert' : 'status' }, message),
|
|
603
|
+
dismiss && button('', dismiss, { icon: 'x', iconSize: 13, className: 'dpt-close', 'aria-label': '关闭反馈' }))
|
|
604
|
+
const matches = (query, ...values) => values.some(value => value?.toLowerCase().includes(query.trim().toLowerCase()))
|
|
605
|
+
const formatBytes = bytes => {
|
|
606
|
+
if (!Number.isFinite(bytes)) return ''
|
|
607
|
+
if (bytes < 1024) return `${bytes} B`
|
|
608
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB`
|
|
609
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`
|
|
610
|
+
}
|
|
611
|
+
const formatShortTime = ts => {
|
|
612
|
+
if (!ts || !Number.isFinite(ts) || ts <= 0) return ''
|
|
613
|
+
const date = new Date(ts)
|
|
614
|
+
const now = new Date()
|
|
615
|
+
const sameDay = date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()
|
|
616
|
+
const hm = `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
|
617
|
+
if (sameDay) return `今天 ${hm}`
|
|
618
|
+
const md = `${date.getMonth() + 1}/${date.getDate()}`
|
|
619
|
+
return date.getFullYear() === now.getFullYear() ? `${md} ${hm}` : `${date.getFullYear()}/${md}`
|
|
620
|
+
}
|
|
621
|
+
const identity = value => value
|
|
622
|
+
const workspaceTitle = (workspace, t) => workspace.title === 'default-workspace'
|
|
623
|
+
? (t ? t('defaultWorkspace') : '默认工作区') : workspace.title
|
|
624
|
+
const workspaceBadgeColors = [
|
|
625
|
+
'var(--dsw-alias-state-business-primary)',
|
|
626
|
+
'var(--dsw-alias-state-warn-primary)',
|
|
627
|
+
'var(--dsw-static-violet-600)',
|
|
628
|
+
'var(--dsw-alias-state-success-primary)',
|
|
629
|
+
'color-mix(in oklch, var(--dsw-alias-state-business-primary), var(--dsw-alias-state-success-primary) 40%)',
|
|
630
|
+
'color-mix(in oklch, var(--dsw-alias-state-success-primary), var(--dsw-alias-state-warn-primary) 50%)',
|
|
631
|
+
]
|
|
632
|
+
|
|
633
|
+
function assignWorkspaceBadgeColors(workspaces) {
|
|
634
|
+
// The oldest workspace gets first choice regardless of sidebar order.
|
|
635
|
+
const ordered = [...workspaces].sort((a, b) =>
|
|
636
|
+
(a.createdAt ?? '').localeCompare(b.createdAt ?? '') || a.workspaceId.localeCompare(b.workspaceId))
|
|
637
|
+
const colors = new Map()
|
|
638
|
+
const used = new Set()
|
|
639
|
+
const count = workspaceBadgeColors.length
|
|
640
|
+
for (const workspace of ordered) {
|
|
641
|
+
if (used.size === count) used.clear()
|
|
642
|
+
let hash = 0
|
|
643
|
+
for (const char of workspace.workspaceId) hash = (Math.imul(hash, 31) + char.codePointAt(0)) >>> 0
|
|
644
|
+
let index = hash % count
|
|
645
|
+
while (used.has(index)) index = (index + 1) % count
|
|
646
|
+
used.add(index)
|
|
647
|
+
colors.set(workspace.workspaceId, workspaceBadgeColors[index])
|
|
648
|
+
}
|
|
649
|
+
return colors
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function WorkspaceBadge({ workspace, workspaceColors, orphanedCwd, t }) {
|
|
653
|
+
const label = workspace ? workspaceTitle(workspace, t) : t(orphanedCwd ? 'workspaceDeleted' : 'ungrouped')
|
|
654
|
+
let accent = 'var(--dsw-alias-label-tertiary)'
|
|
655
|
+
let title = label
|
|
656
|
+
if (workspace) {
|
|
657
|
+
accent = workspaceColors.get(workspace.workspaceId) ?? workspaceBadgeColors[0]
|
|
658
|
+
if (workspace.path) title = `${label}\n${workspace.path}`
|
|
659
|
+
} else if (orphanedCwd) {
|
|
660
|
+
accent = 'var(--dsw-alias-state-error-primary)'
|
|
661
|
+
title = `${t('workspaceMissing')}\n${orphanedCwd}`
|
|
662
|
+
}
|
|
663
|
+
return h('span', {
|
|
664
|
+
className: 'dpt-workspace-badge', title, dir: 'auto',
|
|
665
|
+
'data-workspace-badge': workspace?.workspaceId ?? '', 'data-workspace-missing': orphanedCwd ? true : undefined,
|
|
666
|
+
style: { '--dpt-workspace-color': accent },
|
|
667
|
+
}, label)
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function Segmented({ label, value, onChange, items }) {
|
|
671
|
+
return h('div', { className: 'dpt-seg', role: 'group', 'aria-label': label }, items.map(item =>
|
|
672
|
+
h('button', {
|
|
673
|
+
key: item.value, type: 'button', className: 'dpt-seg-btn',
|
|
674
|
+
'aria-pressed': value === item.value,
|
|
675
|
+
'data-alert': item.alert || undefined,
|
|
676
|
+
onClick: () => onChange(item.value),
|
|
677
|
+
},
|
|
678
|
+
h('span', null, item.label),
|
|
679
|
+
item.count !== undefined && item.count !== null && h('span', { className: 'dpt-seg-count' }, item.count))))
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function Switch({ checked, onChange, label, disabled }) {
|
|
683
|
+
return h('button', {
|
|
684
|
+
type: 'button', role: 'switch', className: 'dpt-switch',
|
|
685
|
+
'aria-checked': Boolean(checked), 'aria-label': label, title: label, disabled,
|
|
686
|
+
onClick: e => { e.stopPropagation(); onChange(!checked) },
|
|
687
|
+
}, h('span', { className: 'dpt-switch-thumb', 'aria-hidden': true }))
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function useToast() {
|
|
691
|
+
const [toast, setToast] = useState(null)
|
|
692
|
+
const [hovered, setHovered] = useState(false)
|
|
693
|
+
useEffect(() => {
|
|
694
|
+
if (!toast || toast.error || hovered) return
|
|
695
|
+
const duration = toast.sticky ? 8000 : 2600
|
|
696
|
+
const timer = setTimeout(() => setToast(null), duration)
|
|
697
|
+
return () => clearTimeout(timer)
|
|
698
|
+
}, [toast, hovered])
|
|
699
|
+
const show = (content, { error = false, sticky = false } = {}) => {
|
|
700
|
+
if (!content) { setToast(null); return }
|
|
701
|
+
setToast({ id: Date.now() + Math.random(), content, error, sticky })
|
|
702
|
+
}
|
|
703
|
+
const node = toast && h('div', {
|
|
704
|
+
className: 'dpt-toast', 'data-error': toast.error || undefined,
|
|
705
|
+
onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false),
|
|
706
|
+
},
|
|
707
|
+
h('div', { className: 'dpt-toast-body', role: toast.error ? 'alert' : 'status' }, toast.content),
|
|
708
|
+
button('', () => setToast(null), { icon: 'x', iconSize: 13, className: 'dpt-close', 'aria-label': '关闭提示' }))
|
|
709
|
+
return { show, dismiss: () => setToast(null), node }
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function useInfiniteScroll(total, resetKey, step = 50) {
|
|
713
|
+
const [state, setState] = useState({ key: resetKey, limit: step })
|
|
714
|
+
const sentinelRef = useRef(null)
|
|
715
|
+
const limit = state.key === resetKey ? state.limit : step
|
|
716
|
+
const hasMore = total > limit
|
|
717
|
+
useEffect(() => {
|
|
718
|
+
if (state.key !== resetKey) setState({ key: resetKey, limit: step })
|
|
719
|
+
}, [resetKey, step, state.key])
|
|
720
|
+
useEffect(() => {
|
|
721
|
+
const node = sentinelRef.current
|
|
722
|
+
if (!node || !hasMore || typeof IntersectionObserver === 'undefined') return
|
|
723
|
+
const observer = new IntersectionObserver(entries => {
|
|
724
|
+
if (entries.some(entry => entry.isIntersecting)) {
|
|
725
|
+
setState(previous => ({
|
|
726
|
+
key: resetKey,
|
|
727
|
+
limit: Math.min(total, (previous.key === resetKey ? previous.limit : step) + step),
|
|
728
|
+
}))
|
|
729
|
+
}
|
|
730
|
+
}, { rootMargin: '360px 0px' })
|
|
731
|
+
observer.observe(node)
|
|
732
|
+
return () => observer.disconnect()
|
|
733
|
+
}, [hasMore, limit, resetKey, step, total])
|
|
734
|
+
return {
|
|
735
|
+
limit,
|
|
736
|
+
hasMore,
|
|
737
|
+
sentinel: hasMore && h('li', { ref: sentinelRef, className: 'dpt-sentinel', 'aria-hidden': true }),
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function PanelSection({ title, summary, toolbar, children }) {
|
|
742
|
+
return h('section', { 'aria-label': title },
|
|
743
|
+
h('header', { className: 'dpt-heading' }, h('h3', null, title),
|
|
744
|
+
summary && h('p', { className: 'dpt-summary' }, summary)),
|
|
745
|
+
h('div', { className: 'dpt-section-body' }, toolbar, children))
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const empty = (message, onReset) => h('div', { className: `dpt-card dpt-empty${onReset ? ' dpt-empty-row' : ''}` },
|
|
749
|
+
muted(message, { role: 'status' }),
|
|
750
|
+
onReset && button('重置筛选', onReset, { icon: 'x', iconSize: 13 }))
|
|
751
|
+
const pill = (text, tone = 'idle', id) => h('span', { id, className: 'dpt-pill', 'data-tone': tone }, text)
|
|
752
|
+
|
|
753
|
+
function useHostStatus() {
|
|
754
|
+
const [state, setState] = useState({ loading: true })
|
|
755
|
+
const active = useRef(null)
|
|
756
|
+
async function check() {
|
|
757
|
+
active.current?.abort()
|
|
758
|
+
const controller = new AbortController()
|
|
759
|
+
active.current = controller
|
|
760
|
+
setState(previous => ({ ...previous, loading: true, error: '' }))
|
|
761
|
+
try {
|
|
762
|
+
const info = await request('capabilities', {}, controller.signal)
|
|
763
|
+
if (!controller.signal.aborted) setState({ info })
|
|
764
|
+
} catch (error) {
|
|
765
|
+
if (!controller.signal.aborted) setState(previous => ({ ...previous, loading: false, error: error.message, failed: true }))
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
useEffect(() => {
|
|
769
|
+
void check()
|
|
770
|
+
return () => active.current?.abort()
|
|
771
|
+
}, [])
|
|
772
|
+
return { ...state, check, dismiss: () => setState(previous => ({ ...previous, error: '' })) }
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function PathLine({ value, label = '路径' }) {
|
|
776
|
+
const [copied, setCopied] = useState(false)
|
|
777
|
+
const [error, setError] = useState('')
|
|
778
|
+
const timer = useRef(null)
|
|
779
|
+
useEffect(() => () => clearTimeout(timer.current), [])
|
|
780
|
+
async function copy() {
|
|
781
|
+
clearTimeout(timer.current)
|
|
782
|
+
setError('')
|
|
783
|
+
try {
|
|
784
|
+
if (!await writeClipboard(value)) throw new Error('clipboard unavailable')
|
|
785
|
+
setCopied(true)
|
|
786
|
+
timer.current = setTimeout(() => setCopied(false), 1800)
|
|
787
|
+
} catch {
|
|
788
|
+
setCopied(false)
|
|
789
|
+
setError('无法访问剪贴板。可以选择并复制路径。')
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return h(React.Fragment, null, h('div', { className: 'dpt-path' }, code(value),
|
|
793
|
+
button(copied ? '已复制' : '复制', copy, {
|
|
794
|
+
icon: copied ? 'check' : 'copy', iconSize: 12,
|
|
795
|
+
className: 'dpt-copy', 'data-copied': copied || undefined,
|
|
796
|
+
'aria-label': copied ? `已复制${label}` : `复制${label}`,
|
|
797
|
+
})),
|
|
798
|
+
feedback(error, true, () => setError('')))
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function DisclosureRow({
|
|
802
|
+
title, tag, chips, detail, workspaceBadges, badge, tone = 'idle', expanded, onToggle,
|
|
803
|
+
selectable, quickActions, alwaysActions, children, ...props
|
|
804
|
+
}) {
|
|
805
|
+
const id = React.useId()
|
|
806
|
+
const descriptions = [tag && `${id}-tag`, workspaceBadges && `${id}-workspaces`, detail && `${id}-detail`, badge && `${id}-status`].filter(Boolean).join(' ')
|
|
807
|
+
const summary = detail && h('span', { id: `${id}-detail`, className: 'dpt-muted dpt-ellipsis dpt-row-summary', dir: 'auto' }, detail)
|
|
808
|
+
return h('li', {
|
|
809
|
+
className: 'dpt-row', 'data-open': expanded || undefined,
|
|
810
|
+
'data-selected': selectable?.checked || undefined, ...props,
|
|
811
|
+
},
|
|
812
|
+
h('div', { className: 'dpt-row-main' },
|
|
813
|
+
selectable && h('label', {
|
|
814
|
+
className: 'dpt-lead-cell',
|
|
815
|
+
onClick: e => e.stopPropagation(),
|
|
816
|
+
},
|
|
817
|
+
h('span', { className: 'dpt-indicator', 'data-tone': tone, 'aria-hidden': true }),
|
|
818
|
+
h('input', {
|
|
819
|
+
type: 'checkbox', className: 'dpt-row-checkbox',
|
|
820
|
+
checked: selectable.checked, 'aria-label': selectable.label,
|
|
821
|
+
onChange: e => selectable.onChange(e.target.checked, Boolean(e.nativeEvent?.shiftKey)),
|
|
822
|
+
})),
|
|
823
|
+
h('button', {
|
|
824
|
+
type: 'button', className: 'dpt-disclosure', onClick: onToggle,
|
|
825
|
+
'aria-label': title, 'aria-expanded': expanded, 'aria-controls': id,
|
|
826
|
+
'aria-describedby': descriptions || undefined,
|
|
827
|
+
},
|
|
828
|
+
!selectable && h('span', { className: 'dpt-indicator', 'data-tone': tone, 'aria-hidden': true }),
|
|
829
|
+
h('span', { className: 'dpt-row-label' },
|
|
830
|
+
h('span', { className: 'dpt-row-title' },
|
|
831
|
+
h('strong', { className: 'dpt-ellipsis', dir: 'auto' }, title),
|
|
832
|
+
tag && h('span', { id: `${id}-tag`, className: 'dpt-row-tag dpt-mono', dir: 'ltr' }, tag),
|
|
833
|
+
chips),
|
|
834
|
+
workspaceBadges
|
|
835
|
+
? h('span', { className: 'dpt-row-meta' }, h('span', { id: `${id}-workspaces`, className: 'dpt-workspace-badges' }, workspaceBadges), summary)
|
|
836
|
+
: summary)),
|
|
837
|
+
h('div', { className: 'dpt-row-end' },
|
|
838
|
+
quickActions && h('div', { className: 'dpt-quick-actions dpt-quick-actions--hover' }, quickActions),
|
|
839
|
+
alwaysActions && h('div', { className: 'dpt-quick-actions' }, alwaysActions),
|
|
840
|
+
h('span', { className: 'dpt-row-toggle-tail', onClick: onToggle, 'aria-hidden': true },
|
|
841
|
+
badge && pill(badge, tone, `${id}-status`),
|
|
842
|
+
h('span', { className: 'dpt-chevron' }, h(IconChevronRightOutlineRegular, { size: 16 }))))),
|
|
843
|
+
h('div', { id, hidden: !expanded, className: 'dpt-drawer' }, expanded && children))
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function useDisclosure() {
|
|
847
|
+
const [choices, setChoices] = useState(() => new Map())
|
|
848
|
+
const bind = (key, initial = false) => {
|
|
849
|
+
const expanded = choices.get(key) ?? initial
|
|
850
|
+
return {
|
|
851
|
+
expanded,
|
|
852
|
+
open: () => setChoices(previous => new Map(previous).set(key, true)),
|
|
853
|
+
onToggle: () => setChoices(previous => new Map(previous).set(key, !expanded)),
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
bind.isOpen = (key, initial = false) => choices.get(key) ?? initial
|
|
857
|
+
bind.collapseAll = keys => setChoices(previous => {
|
|
858
|
+
const next = new Map(previous)
|
|
859
|
+
for (const key of keys) next.set(key, false)
|
|
860
|
+
return next
|
|
861
|
+
})
|
|
862
|
+
return bind
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
function Modal({ title, close, closeLabel = '关闭', busy = false, review = false, children }) {
|
|
866
|
+
const dialog = useRef(null)
|
|
867
|
+
const heading = React.useId()
|
|
868
|
+
useLayoutEffect(() => {
|
|
869
|
+
const node = dialog.current
|
|
870
|
+
node.showModal()
|
|
871
|
+
node.querySelector('[data-dpt-initial-focus]')?.focus()
|
|
872
|
+
return () => node.close()
|
|
873
|
+
}, [])
|
|
874
|
+
return h('dialog', {
|
|
875
|
+
ref: dialog, className: `dpt dpt-modal${review ? ' dpt-review' : ''}`, 'aria-labelledby': heading,
|
|
876
|
+
onCancel: e => { e.preventDefault(); if (!busy) close() },
|
|
877
|
+
},
|
|
878
|
+
h('style', null, css),
|
|
879
|
+
h('header', { className: 'dpt-modal-head' }, h('h2', { id: heading }, title), button(closeLabel, close, { icon: 'x', iconSize: 13, disabled: busy })), children)
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
function useAction() {
|
|
883
|
+
const [status, setStatus] = useState({ busy: false })
|
|
884
|
+
const active = useRef(false)
|
|
885
|
+
async function run(operation) {
|
|
886
|
+
if (active.current) return
|
|
887
|
+
active.current = true
|
|
888
|
+
setStatus({ busy: true })
|
|
889
|
+
try {
|
|
890
|
+
const message = await operation()
|
|
891
|
+
setStatus({ busy: false, message })
|
|
892
|
+
return message
|
|
893
|
+
} catch (error) {
|
|
894
|
+
setStatus({ busy: false, message: error.message || '操作未完成。', error: true })
|
|
895
|
+
return undefined
|
|
896
|
+
} finally { active.current = false }
|
|
897
|
+
}
|
|
898
|
+
const dismiss = () => setStatus(previous => ({ busy: previous.busy }))
|
|
899
|
+
return [status, run, dismiss]
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
function useHostSessions(sessionVersion, hostInfo) {
|
|
903
|
+
const [items, setItems] = useState(null)
|
|
904
|
+
const [error, setError] = useState('')
|
|
905
|
+
const [reloading, setReloading] = useState(false)
|
|
906
|
+
const generation = useRef(0)
|
|
907
|
+
async function reload(signal) {
|
|
908
|
+
const current = ++generation.current
|
|
909
|
+
setReloading(true)
|
|
910
|
+
try {
|
|
911
|
+
const { sessions } = await request('sessions', { action: 'list' }, signal)
|
|
912
|
+
if (current === generation.current && !signal?.aborted) { setItems(sessions); setError('') }
|
|
913
|
+
} catch (err) {
|
|
914
|
+
if (current === generation.current && !signal?.aborted) {
|
|
915
|
+
const staleHost = hostInfo && hostInfo.sessionDelete === false
|
|
916
|
+
setError(staleHost ? 'DSH 宿主仍在运行旧版插件代码,请完全退出并重启 DSH 后生效。' : err.message)
|
|
917
|
+
}
|
|
918
|
+
} finally {
|
|
919
|
+
if (current === generation.current) setReloading(false)
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
useEffect(() => {
|
|
923
|
+
const abort = new AbortController()
|
|
924
|
+
void reload(abort.signal)
|
|
925
|
+
return () => { abort.abort(); generation.current++ }
|
|
926
|
+
}, [sessionVersion, hostInfo?.sessionDelete])
|
|
927
|
+
return { items, error, reloading, reload, dismissError: () => setError('') }
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function subagentLabel(item) {
|
|
931
|
+
const parts = ['子 Agent']
|
|
932
|
+
if (item.agentPreset) parts.push(item.agentPreset)
|
|
933
|
+
if (item.delegationDepth) parts.push(`L${item.delegationDepth}`)
|
|
934
|
+
return parts.join(' · ')
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function safeFilename(title, fallback) {
|
|
938
|
+
const cleaned = (title || '').replace(/[\\/:*?"<>|\x00-\x1f]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 60)
|
|
939
|
+
return cleaned || fallback
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function triggerDownload(url, filename) {
|
|
943
|
+
const anchor = document.createElement('a')
|
|
944
|
+
anchor.href = url
|
|
945
|
+
anchor.download = filename
|
|
946
|
+
anchor.rel = 'noopener'
|
|
947
|
+
document.body.appendChild(anchor)
|
|
948
|
+
anchor.click()
|
|
949
|
+
anchor.remove()
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function SessionRow({
|
|
953
|
+
row, id, title, workspaces, isArchived, isPinned, matchSnippet, subagents, totalBytes, navigation,
|
|
954
|
+
onArchived, onPinned, onDeleted, notify, disclosure, selectable, workspaceColors, t,
|
|
955
|
+
}) {
|
|
956
|
+
const [status, run, dismiss] = useAction()
|
|
957
|
+
const [removal, setRemoval] = useState(false)
|
|
958
|
+
const [showAllSubagents, setShowAllSubagents] = useState(false)
|
|
959
|
+
async function archive() {
|
|
960
|
+
await run(async () => {
|
|
961
|
+
try {
|
|
962
|
+
if (isArchived) await navigation.unarchiveSession(id)
|
|
963
|
+
else await navigation.archiveSession(id, { stopActivity: false })
|
|
964
|
+
} catch (error) {
|
|
965
|
+
if (error.rpcError?.code === 'workspace/session-active') throw new Error('会话仍有运行中的工作。停止后可归档。')
|
|
966
|
+
throw error
|
|
967
|
+
}
|
|
968
|
+
onArchived(isArchived ? '会话已恢复' : '会话已归档')
|
|
969
|
+
})
|
|
970
|
+
}
|
|
971
|
+
async function togglePin() {
|
|
972
|
+
await run(async () => {
|
|
973
|
+
await request('sessions', { action: isPinned ? 'unpin' : 'pin', sessionId: id })
|
|
974
|
+
onPinned(isPinned ? '已取消置顶' : '会话已置顶')
|
|
975
|
+
})
|
|
976
|
+
}
|
|
977
|
+
async function exportMarkdown(mode) {
|
|
978
|
+
await run(async () => {
|
|
979
|
+
const response = await fetch(`api/session.markdown?sessionId=${encodeURIComponent(id)}`)
|
|
980
|
+
if (!response.ok) throw new Error('无法导出会话 Markdown,请确认会话已包含内容。')
|
|
981
|
+
const markdown = await response.text()
|
|
982
|
+
if (mode === 'copy') {
|
|
983
|
+
if (!await writeClipboard(markdown)) throw new Error('无法访问剪贴板,请改用下载 Markdown。')
|
|
984
|
+
notify('已复制会话 Markdown')
|
|
985
|
+
return
|
|
986
|
+
}
|
|
987
|
+
const blob = new Blob([markdown], { type: 'text/markdown;charset=utf-8' })
|
|
988
|
+
const objectUrl = URL.createObjectURL(blob)
|
|
989
|
+
try {
|
|
990
|
+
triggerDownload(objectUrl, `${safeFilename(title, id)}.md`)
|
|
991
|
+
} finally {
|
|
992
|
+
setTimeout(() => URL.revokeObjectURL(objectUrl), 4000)
|
|
993
|
+
}
|
|
994
|
+
notify('已开始下载会话 Markdown')
|
|
995
|
+
})
|
|
996
|
+
}
|
|
997
|
+
function exportZip() {
|
|
998
|
+
triggerDownload(`api/session.export?sessionId=${encodeURIComponent(id)}`, `${safeFilename(title, id)}.zip`)
|
|
999
|
+
notify('已开始下载会话 ZIP 归档')
|
|
1000
|
+
}
|
|
1001
|
+
const timeSummary = formatShortTime(row.updatedAt || row.createdAt)
|
|
1002
|
+
const sizeSummary = totalBytes !== null ? formatBytes(totalBytes) : ''
|
|
1003
|
+
const lineageSummary = row.isSubagent && (row.orphanSubagent ? '孤儿子会话(父会话已移除)' : `隶属 ${row.parentSessionId}`)
|
|
1004
|
+
const detailParts = matchSnippet
|
|
1005
|
+
? [row.orphanSubagent && lineageSummary, `命中:${matchSnippet}`]
|
|
1006
|
+
: [lineageSummary, sizeSummary, timeSummary]
|
|
1007
|
+
const badge = row.running ? '运行中' : row.isSubagent ? '子 Agent' : isArchived ? '已归档' : undefined
|
|
1008
|
+
const tone = row.running ? 'info' : row.isSubagent ? 'attention' : 'idle'
|
|
1009
|
+
const removedItems = [
|
|
1010
|
+
`${row.isSubagent ? '子 Agent 会话' : '会话'}「${title}」(${id})`,
|
|
1011
|
+
...(subagents.length > 0 ? [
|
|
1012
|
+
`关联的 ${subagents.length} 条子 Agent 会话记录:` + subagents.slice(0, 6).map(item => item.id).join('、') + (subagents.length > 6 ? ` 等共 ${subagents.length} 条` : ''),
|
|
1013
|
+
] : []),
|
|
1014
|
+
]
|
|
1015
|
+
const visibleSubagents = showAllSubagents ? subagents : subagents.slice(0, 6)
|
|
1016
|
+
const activeTime = row.updatedAt || row.createdAt
|
|
1017
|
+
const deleteHint = row.deletable
|
|
1018
|
+
? (subagents.length > 0 ? `关联删除(含 ${subagents.length} 条子会话)` : '删除会话')
|
|
1019
|
+
: (row.deleteReason || '当前不可删除')
|
|
1020
|
+
|
|
1021
|
+
const chips = (isPinned || subagents.length > 0) && h(React.Fragment, null,
|
|
1022
|
+
isPinned && pill('已置顶', 'info'),
|
|
1023
|
+
subagents.length > 0 && pill(`${subagents.length} 子会话`))
|
|
1024
|
+
|
|
1025
|
+
const quickActions = h(React.Fragment, null,
|
|
1026
|
+
!row.isSubagent && button('打开', () => run(() => navigation.openSession(id)), {
|
|
1027
|
+
icon: 'external-link', iconSize: 13, className: 'dpt-row-btn', disabled: status.busy,
|
|
1028
|
+
'aria-label': `打开 ${title}`,
|
|
1029
|
+
}),
|
|
1030
|
+
!row.isSubagent && !isArchived && iconButton(
|
|
1031
|
+
`${isPinned ? '取消置顶' : '置顶'} ${title}`,
|
|
1032
|
+
'pin',
|
|
1033
|
+
togglePin,
|
|
1034
|
+
{ className: 'dpt-row-icon-btn', iconSize: 13, title: isPinned ? '取消置顶' : '置顶会话', disabled: status.busy },
|
|
1035
|
+
),
|
|
1036
|
+
!row.isSubagent && iconButton(
|
|
1037
|
+
`${isArchived ? '恢复' : '归档'} ${title}`,
|
|
1038
|
+
isArchived ? 'archive-restore' : 'archive',
|
|
1039
|
+
archive,
|
|
1040
|
+
{ className: 'dpt-row-icon-btn', iconSize: 13, title: isArchived ? '恢复会话' : '归档会话', disabled: status.busy || (!isArchived && row.running) },
|
|
1041
|
+
),
|
|
1042
|
+
iconButton(
|
|
1043
|
+
`删除 ${title}`,
|
|
1044
|
+
'trash',
|
|
1045
|
+
() => setRemoval(true),
|
|
1046
|
+
{ className: 'dpt-row-icon-btn dpt-danger', iconSize: 13, title: deleteHint, disabled: status.busy || !row.deletable },
|
|
1047
|
+
))
|
|
1048
|
+
|
|
1049
|
+
return h(DisclosureRow, {
|
|
1050
|
+
'data-session-id': id, 'data-session-kind': row.isSubagent ? 'subagent' : 'session',
|
|
1051
|
+
title,
|
|
1052
|
+
tag: row.isSubagent ? (row.agentPreset || (row.delegationDepth ? `L${row.delegationDepth}` : undefined)) : undefined,
|
|
1053
|
+
chips,
|
|
1054
|
+
workspaceBadges: workspaces.length
|
|
1055
|
+
? workspaces.map(workspace => h(WorkspaceBadge, { key: workspace.workspaceId, workspace, workspaceColors, t }))
|
|
1056
|
+
: h(WorkspaceBadge, { orphanedCwd: row.orphanWorkspace ? row.cwd : undefined, t }),
|
|
1057
|
+
detail: detailParts.filter(Boolean).join(' · '),
|
|
1058
|
+
badge, tone, selectable, quickActions, ...disclosure,
|
|
1059
|
+
},
|
|
1060
|
+
matchSnippet && muted(`正文命中摘录:${matchSnippet}`),
|
|
1061
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1062
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
1063
|
+
h('span', null, '会话 ID', code(id)),
|
|
1064
|
+
row.isSubagent && row.parentSessionId && h('span', null, '父会话', code(row.parentSessionId)),
|
|
1065
|
+
activeTime > 0 && h('span', null, row.updatedAt > 0 ? '更新' : '创建', h('strong', null, new Date(activeTime).toLocaleString())),
|
|
1066
|
+
totalBytes !== null && h('span', null, '大小', h('strong', null,
|
|
1067
|
+
subagents.length > 0 && Number.isFinite(row.sizeBytes) && totalBytes > row.sizeBytes
|
|
1068
|
+
? `${formatBytes(totalBytes)}(主会话 ${formatBytes(row.sizeBytes)})`
|
|
1069
|
+
: formatBytes(totalBytes)))),
|
|
1070
|
+
h('div', { className: 'dpt-actions' },
|
|
1071
|
+
!row.isSubagent && button('打开', () => run(() => navigation.openSession(id)), { icon: 'external-link', disabled: status.busy }),
|
|
1072
|
+
!row.isSubagent && !isArchived && button(isPinned ? '取消置顶' : '置顶', togglePin, { icon: 'pin', disabled: status.busy }),
|
|
1073
|
+
!row.isSubagent && button(isArchived ? '恢复' : '归档', archive, { icon: isArchived ? 'archive-restore' : 'archive', disabled: status.busy || (!isArchived && row.running) }),
|
|
1074
|
+
button('复制 Markdown', () => exportMarkdown('copy'), { icon: 'copy', disabled: status.busy }),
|
|
1075
|
+
button('下载 .md', () => exportMarkdown('download'), { icon: 'download', disabled: status.busy }),
|
|
1076
|
+
button('ZIP', exportZip, { icon: 'download', disabled: status.busy, title: '下载 DSH 原始会话 ZIP 归档' }),
|
|
1077
|
+
button(subagents.length > 0 ? `关联删除(${subagents.length + 1})` : '删除', () => setRemoval(true), {
|
|
1078
|
+
icon: 'trash', className: 'dpt-danger', disabled: status.busy || !row.deletable, title: deleteHint,
|
|
1079
|
+
}))),
|
|
1080
|
+
row.orphanWorkspace && muted(t('workspaceMissing')),
|
|
1081
|
+
row.cwd && h(PathLine, { value: row.cwd }),
|
|
1082
|
+
subagents.length > 0 && h('div', { className: 'dpt-drawer-split' },
|
|
1083
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1084
|
+
h('span', { className: 'dpt-label' }, `关联子 Agent 会话(${subagents.length})· 删除主会话时自动一并清理`),
|
|
1085
|
+
subagents.length > 6 && button(showAllSubagents ? '收起列表' : `展开全部 ${subagents.length} 条`, () => setShowAllSubagents(!showAllSubagents))),
|
|
1086
|
+
h('ul', { className: `dpt-file-list${showAllSubagents && subagents.length > 8 ? ' dpt-scroll-box' : ''}` }, visibleSubagents.map(child =>
|
|
1087
|
+
h('li', { key: child.id, 'data-subagent-id': child.id },
|
|
1088
|
+
h('span', null, subagentLabel(child), ' ', code(child.id), child.orphanWorkspace && h(React.Fragment, null,
|
|
1089
|
+
' ', h(WorkspaceBadge, { orphanedCwd: child.cwd, t }))),
|
|
1090
|
+
h('span', null, [
|
|
1091
|
+
child.running ? '运行中' : child.resident ? '打开中' : '',
|
|
1092
|
+
Number.isFinite(child.sizeBytes) ? formatBytes(child.sizeBytes) : '',
|
|
1093
|
+
].filter(Boolean).join(' · ') || '已落盘'))))),
|
|
1094
|
+
!row.deletable && row.deleteReason && muted(row.deleteReason),
|
|
1095
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1096
|
+
removal && h(Confirm, {
|
|
1097
|
+
title: `删除 ${title}`,
|
|
1098
|
+
label: subagents.length > 0 ? `确认关联删除(${subagents.length + 1} 条)` : '确认删除会话',
|
|
1099
|
+
removed: removedItems,
|
|
1100
|
+
preserved: ['工作区目录及所有项目文件', '其他无关会话与独立分支会话', 'Profile 恢复目录中的会话备份(含 manifest.json)'],
|
|
1101
|
+
close: () => setRemoval(false),
|
|
1102
|
+
confirm: async () => {
|
|
1103
|
+
const result = await request('sessions', { action: 'delete', sessionId: id, confirm: id })
|
|
1104
|
+
setRemoval(false)
|
|
1105
|
+
await onDeleted(result)
|
|
1106
|
+
},
|
|
1107
|
+
}))
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
function SessionPanel({ sessionList, workspaceList, navigation, refresh, host, toast, t }) {
|
|
1111
|
+
const [query, search] = useState('')
|
|
1112
|
+
const [searchScope, setSearchScope] = useState('title')
|
|
1113
|
+
const [contentSearch, setContentSearch] = useState({ loading: false, query: '', hits: null, error: '' })
|
|
1114
|
+
const [workspace, selectWorkspace] = useState('all')
|
|
1115
|
+
const [viewMode, setViewMode] = useState('active')
|
|
1116
|
+
const [sortBy, setSortBy] = useState('recent')
|
|
1117
|
+
const [selectedIds, setSelectedIds] = useState(() => new Set())
|
|
1118
|
+
const [batchRemoval, setBatchRemoval] = useState(false)
|
|
1119
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
1120
|
+
const [status, run, dismiss] = useAction()
|
|
1121
|
+
const lastClickedIndex = useRef(-1)
|
|
1122
|
+
const disclosure = useDisclosure()
|
|
1123
|
+
const hostSessions = useHostSessions(`${sessionList.ids.length}:${workspaceList.archivedSessionIds.length}:${workspaceList.pinnedSessionIds?.length ?? 0}`, host.info)
|
|
1124
|
+
const archived = new Set(workspaceList.archivedSessionIds)
|
|
1125
|
+
const clientPinned = Array.isArray(workspaceList.pinnedSessionIds) ? workspaceList.pinnedSessionIds : []
|
|
1126
|
+
const clientPinnedOrder = new Map(clientPinned.map((id, index) => [id, index]))
|
|
1127
|
+
const groups = new Map()
|
|
1128
|
+
const workspacesByPath = new Map()
|
|
1129
|
+
const workspaceColors = React.useMemo(() => assignWorkspaceBadgeColors(workspaceList.items), [workspaceList.items])
|
|
1130
|
+
const workspacesReady = workspaceList.phase === 'ready'
|
|
1131
|
+
for (const item of workspaceList.items) {
|
|
1132
|
+
if (item.path) workspacesByPath.set(item.path, item)
|
|
1133
|
+
for (const id of item.sessionIds) groups.set(id, [...(groups.get(id) ?? []), item])
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
useEffect(() => {
|
|
1137
|
+
if (workspacesReady && !['all', 'none', 'orphan'].includes(workspace)
|
|
1138
|
+
&& !workspaceList.items.some(item => item.workspaceId === workspace)) selectWorkspace('all')
|
|
1139
|
+
}, [workspace, workspacesReady, workspaceList.items])
|
|
1140
|
+
|
|
1141
|
+
const trimmedQuery = query.trim()
|
|
1142
|
+
useEffect(() => {
|
|
1143
|
+
if (searchScope !== 'content' || !trimmedQuery) {
|
|
1144
|
+
setContentSearch({ loading: false, query: '', hits: null, error: '' })
|
|
1145
|
+
return
|
|
1146
|
+
}
|
|
1147
|
+
const abort = new AbortController()
|
|
1148
|
+
setContentSearch(previous => ({ ...previous, loading: true, error: '' }))
|
|
1149
|
+
const timer = setTimeout(async () => {
|
|
1150
|
+
try {
|
|
1151
|
+
const result = await request('sessions', { action: 'search', query: trimmedQuery, limit: 50 }, abort.signal)
|
|
1152
|
+
if (!abort.signal.aborted) {
|
|
1153
|
+
setContentSearch({ loading: false, query: trimmedQuery, hits: result.hits ?? [], error: '' })
|
|
1154
|
+
}
|
|
1155
|
+
} catch (err) {
|
|
1156
|
+
if (!abort.signal.aborted) {
|
|
1157
|
+
setContentSearch({ loading: false, query: trimmedQuery, hits: [], error: err.message })
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}, 220)
|
|
1161
|
+
return () => { clearTimeout(timer); abort.abort() }
|
|
1162
|
+
}, [searchScope, trimmedQuery])
|
|
1163
|
+
|
|
1164
|
+
const contentHitBySession = new Map()
|
|
1165
|
+
if (searchScope === 'content' && trimmedQuery && contentSearch.hits) {
|
|
1166
|
+
contentSearch.hits.forEach((hit, index) => {
|
|
1167
|
+
if (!contentHitBySession.has(hit.sessionId)) contentHitBySession.set(hit.sessionId, { ...hit, rank: index })
|
|
1168
|
+
})
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
const mergedById = new Map()
|
|
1172
|
+
for (const id of sessionList.ids) {
|
|
1173
|
+
const clientRow = sessionList.byId[id]
|
|
1174
|
+
mergedById.set(id, {
|
|
1175
|
+
id,
|
|
1176
|
+
title: clientRow.title || (clientRow.displayTitle !== id && clientRow.displayTitle) || '未命名会话',
|
|
1177
|
+
cwd: clientRow.cwd ?? '',
|
|
1178
|
+
updatedAt: clientRow.updatedAt ?? 0,
|
|
1179
|
+
createdAt: 0,
|
|
1180
|
+
running: Boolean(clientRow.running),
|
|
1181
|
+
pinned: clientPinnedOrder.has(id),
|
|
1182
|
+
pinnedRank: clientPinnedOrder.get(id) ?? -1,
|
|
1183
|
+
isSubagent: false,
|
|
1184
|
+
orphanSubagent: false,
|
|
1185
|
+
parentSessionId: null,
|
|
1186
|
+
descendantSubagentIds: [],
|
|
1187
|
+
sizeBytes: null,
|
|
1188
|
+
deletable: false,
|
|
1189
|
+
deleteReason: '正在核对会话持久化状态…',
|
|
1190
|
+
workspaces: [],
|
|
1191
|
+
})
|
|
1192
|
+
}
|
|
1193
|
+
for (const hRow of hostSessions.items ?? []) {
|
|
1194
|
+
const existing = mergedById.get(hRow.id)
|
|
1195
|
+
const fallbackTitle = hRow.isSubagent ? subagentLabel(hRow) : '未命名会话'
|
|
1196
|
+
const pinned = Boolean(hRow.pinned || clientPinnedOrder.has(hRow.id))
|
|
1197
|
+
const pinnedRank = hRow.pinnedRank >= 0 ? hRow.pinnedRank : (clientPinnedOrder.get(hRow.id) ?? -1)
|
|
1198
|
+
mergedById.set(hRow.id, {
|
|
1199
|
+
...(existing ?? {}),
|
|
1200
|
+
...hRow,
|
|
1201
|
+
title: existing?.title && existing.title !== '未命名会话' ? existing.title : fallbackTitle,
|
|
1202
|
+
cwd: existing?.cwd || hRow.cwd || '',
|
|
1203
|
+
updatedAt: existing?.updatedAt || hRow.createdAt || 0,
|
|
1204
|
+
running: Boolean(existing?.running || hRow.running),
|
|
1205
|
+
pinned,
|
|
1206
|
+
pinnedRank,
|
|
1207
|
+
})
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const allMerged = [...mergedById.values()]
|
|
1211
|
+
for (const row of allMerged) {
|
|
1212
|
+
const pathMatch = workspacesByPath.get(row.cwd)
|
|
1213
|
+
const inherited = !row.cwd ? groups.get(row.rootSessionId) : undefined
|
|
1214
|
+
// The live workspace projection supersedes the host session list's older memberships.
|
|
1215
|
+
row.workspaces = groups.get(row.id) ?? (pathMatch ? [pathMatch] : inherited)
|
|
1216
|
+
?? (workspacesReady ? [] : row.workspaces ?? [])
|
|
1217
|
+
row.orphanWorkspace = workspacesReady && Boolean(row.cwd) && row.workspaces.length === 0
|
|
1218
|
+
}
|
|
1219
|
+
const inSelectedWorkspace = row => {
|
|
1220
|
+
if (workspace === 'all') return true
|
|
1221
|
+
if (workspace === 'orphan') return row.orphanWorkspace
|
|
1222
|
+
if (workspace === 'none') return row.workspaces.length === 0 && !row.orphanWorkspace
|
|
1223
|
+
return row.workspaces.some(item => item.workspaceId === workspace)
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// Counts on the segmented tabs reflect workspace filter so numbers always match what you click into.
|
|
1227
|
+
const wsScoped = allMerged.filter(inSelectedWorkspace)
|
|
1228
|
+
const activeCount = wsScoped.filter(item => (!item.isSubagent || item.orphanSubagent) && !archived.has(item.id)).length
|
|
1229
|
+
const archivedCount = wsScoped.filter(item => !item.isSubagent && archived.has(item.id)).length
|
|
1230
|
+
const subagentCount = wsScoped.filter(item => item.isSubagent).length
|
|
1231
|
+
|
|
1232
|
+
const usingContentSearch = searchScope === 'content' && Boolean(trimmedQuery)
|
|
1233
|
+
const rows = wsScoped.flatMap(row => {
|
|
1234
|
+
const isArchived = archived.has(row.id)
|
|
1235
|
+
const isPinned = Boolean(row.pinned) && !isArchived
|
|
1236
|
+
if (viewMode === 'active') {
|
|
1237
|
+
if ((row.isSubagent && !row.orphanSubagent) || isArchived) return []
|
|
1238
|
+
} else if (viewMode === 'archived') {
|
|
1239
|
+
if (row.isSubagent || !isArchived) return []
|
|
1240
|
+
} else if (viewMode === 'subagent') {
|
|
1241
|
+
if (!row.isSubagent) return []
|
|
1242
|
+
}
|
|
1243
|
+
const subagents = (row.descendantSubagentIds ?? []).map(subId => mergedById.get(subId)).filter(Boolean)
|
|
1244
|
+
let matchSnippet = ''
|
|
1245
|
+
let matchRank = -1
|
|
1246
|
+
if (usingContentSearch) {
|
|
1247
|
+
const directHit = contentHitBySession.get(row.id)
|
|
1248
|
+
const subHit = !directHit && subagents.map(sub => contentHitBySession.get(sub.id)).find(Boolean)
|
|
1249
|
+
const hit = directHit || subHit
|
|
1250
|
+
if (!hit) return []
|
|
1251
|
+
matchSnippet = hit.snippet || ''
|
|
1252
|
+
matchRank = hit.rank
|
|
1253
|
+
} else {
|
|
1254
|
+
const subagentText = subagents.map(sub => `${sub.id} ${sub.agentPreset ?? ''}`).join(' ')
|
|
1255
|
+
if (!matches(query, row.title, row.id, row.agentPreset ?? '', subagentText)) return []
|
|
1256
|
+
}
|
|
1257
|
+
const ownBytes = Number.isFinite(row.sizeBytes) ? row.sizeBytes : 0
|
|
1258
|
+
const subBytes = subagents.reduce((sum, sub) => sum + (Number.isFinite(sub.sizeBytes) ? sub.sizeBytes : 0), 0)
|
|
1259
|
+
const totalBytes = Number.isFinite(row.sizeBytes) || subagents.some(sub => Number.isFinite(sub.sizeBytes))
|
|
1260
|
+
? ownBytes + subBytes : null
|
|
1261
|
+
return [{ row, id: row.id, title: row.title, workspaces: row.workspaces ?? [], isArchived, isPinned, matchSnippet, matchRank, subagents, totalBytes }]
|
|
1262
|
+
}).sort((a, b) => {
|
|
1263
|
+
if (usingContentSearch) return a.matchRank - b.matchRank
|
|
1264
|
+
const recentDiff = (b.row.updatedAt || b.row.createdAt) - (a.row.updatedAt || a.row.createdAt)
|
|
1265
|
+
if (sortBy === 'oldest') return ((a.row.createdAt || a.row.updatedAt) - (b.row.createdAt || b.row.updatedAt)) || -recentDiff
|
|
1266
|
+
if (sortBy === 'size') return ((b.totalBytes ?? -1) - (a.totalBytes ?? -1)) || recentDiff
|
|
1267
|
+
if (sortBy === 'subagents') return (b.subagents.length - a.subagents.length) || recentDiff
|
|
1268
|
+
if (a.isPinned !== b.isPinned) return a.isPinned ? -1 : 1
|
|
1269
|
+
if (a.isPinned && b.isPinned && a.row.pinnedRank !== b.row.pinnedRank) return a.row.pinnedRank - b.row.pinnedRank
|
|
1270
|
+
return recentDiff
|
|
1271
|
+
})
|
|
1272
|
+
|
|
1273
|
+
const hasActiveFilter = Boolean(trimmedQuery) || searchScope !== 'title' || workspace !== 'all' || sortBy !== 'recent'
|
|
1274
|
+
const resetFilters = () => { search(''); setSearchScope('title'); selectWorkspace('all'); setSortBy('recent') }
|
|
1275
|
+
const scroller = useInfiniteScroll(rows.length, `${viewMode}\n${searchScope}\n${query}\n${workspace}\n${sortBy}`, 50)
|
|
1276
|
+
const visibleRows = rows.slice(0, scroller.limit)
|
|
1277
|
+
const openKeys = visibleRows.filter(item => disclosure.isOpen(item.id)).map(item => item.id)
|
|
1278
|
+
|
|
1279
|
+
const selectedRows = rows.filter(item => selectedIds.has(item.id))
|
|
1280
|
+
const deletableRows = rows.filter(item => item.row.deletable)
|
|
1281
|
+
const deletableSelected = selectedRows.filter(item => item.row.deletable)
|
|
1282
|
+
const lockedSelectedCount = selectedRows.length - deletableSelected.length
|
|
1283
|
+
const archivableSelected = selectedRows.filter(item => !item.row.isSubagent && !item.isArchived && !item.row.running)
|
|
1284
|
+
const restorableSelected = selectedRows.filter(item => !item.row.isSubagent && item.isArchived)
|
|
1285
|
+
const allFilteredSelected = rows.length > 0 && selectedRows.length === rows.length
|
|
1286
|
+
|
|
1287
|
+
const cascadeTargetIds = new Set()
|
|
1288
|
+
const directDeleteSet = new Set(deletableSelected.map(item => item.id))
|
|
1289
|
+
for (const item of deletableSelected) {
|
|
1290
|
+
cascadeTargetIds.add(item.id)
|
|
1291
|
+
for (const sub of item.subagents) cascadeTargetIds.add(sub.id)
|
|
1292
|
+
}
|
|
1293
|
+
const cascadedExtraCount = [...cascadeTargetIds].filter(id => !directDeleteSet.has(id)).length
|
|
1294
|
+
|
|
1295
|
+
useEffect(() => {
|
|
1296
|
+
if (!selectedRows.length) return
|
|
1297
|
+
const onKey = e => {
|
|
1298
|
+
if (e.key === 'Escape' && !document.querySelector('dialog[open]')) {
|
|
1299
|
+
setSelectedIds(new Set())
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
window.addEventListener('keydown', onKey)
|
|
1303
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
1304
|
+
}, [selectedRows.length])
|
|
1305
|
+
|
|
1306
|
+
function toggleSelect(index, id, checked, shiftKey) {
|
|
1307
|
+
if (checked) toast.dismiss()
|
|
1308
|
+
setSelectedIds(previous => {
|
|
1309
|
+
const next = new Set(previous)
|
|
1310
|
+
if (shiftKey && lastClickedIndex.current >= 0 && lastClickedIndex.current < rows.length) {
|
|
1311
|
+
const [start, end] = [Math.min(lastClickedIndex.current, index), Math.max(lastClickedIndex.current, index)]
|
|
1312
|
+
for (let i = start; i <= end; i++) {
|
|
1313
|
+
if (checked) next.add(rows[i].id)
|
|
1314
|
+
else next.delete(rows[i].id)
|
|
1315
|
+
}
|
|
1316
|
+
} else if (checked) next.add(id)
|
|
1317
|
+
else next.delete(id)
|
|
1318
|
+
lastClickedIndex.current = index
|
|
1319
|
+
return next
|
|
1320
|
+
})
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
async function silentRefresh() {
|
|
1324
|
+
if (refreshing) return
|
|
1325
|
+
setRefreshing(true)
|
|
1326
|
+
try { await Promise.all([refresh(), hostSessions.reload()]) }
|
|
1327
|
+
finally { setRefreshing(false) }
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
async function handleDeleted(result) {
|
|
1331
|
+
await Promise.all([refresh(), hostSessions.reload()])
|
|
1332
|
+
setSelectedIds(previous => {
|
|
1333
|
+
const next = new Set(previous)
|
|
1334
|
+
for (const id of result.deletedIds ?? []) next.delete(id)
|
|
1335
|
+
return next
|
|
1336
|
+
})
|
|
1337
|
+
const total = result.deletedIds?.length ?? 1
|
|
1338
|
+
const sub = result.subagentCount ?? 0
|
|
1339
|
+
const isBatch = (result.requestedCount ?? 1) > 1
|
|
1340
|
+
toast.show(h(React.Fragment, null,
|
|
1341
|
+
h('p', null, isBatch
|
|
1342
|
+
? `已批量清理 ${total} 条会话${sub > 0 ? `(含 ${sub} 条子 Agent)` : ''}`
|
|
1343
|
+
: (sub > 0 ? `已关联删除 ${total} 条会话(含 ${sub} 条子 Agent)` : '会话已移至恢复目录')),
|
|
1344
|
+
h(PathLine, { value: result.recovery, label: '恢复目录' })), { sticky: true })
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
function batchArchive(restore) {
|
|
1348
|
+
const targets = restore ? restorableSelected : archivableSelected
|
|
1349
|
+
if (!targets.length) return
|
|
1350
|
+
return run(async () => {
|
|
1351
|
+
let completed = 0
|
|
1352
|
+
for (const item of targets) {
|
|
1353
|
+
try {
|
|
1354
|
+
if (restore) await navigation.unarchiveSession(item.id)
|
|
1355
|
+
else await navigation.archiveSession(item.id, { stopActivity: false })
|
|
1356
|
+
completed++
|
|
1357
|
+
} catch (error) {
|
|
1358
|
+
if (error.rpcError?.code !== 'workspace/session-active') throw error
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
setSelectedIds(previous => {
|
|
1362
|
+
const next = new Set(previous)
|
|
1363
|
+
for (const item of targets) next.delete(item.id)
|
|
1364
|
+
return next
|
|
1365
|
+
})
|
|
1366
|
+
await hostSessions.reload()
|
|
1367
|
+
toast.show(restore ? `已恢复 ${completed} 个会话` : `已归档 ${completed} 个会话`)
|
|
1368
|
+
})
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
return h('div', { className: 'dpt-panel' },
|
|
1372
|
+
feedback(host.error, true, host.dismiss),
|
|
1373
|
+
feedback(hostSessions.error, true, hostSessions.dismissError),
|
|
1374
|
+
feedback(contentSearch.error, true, () => setContentSearch(previous => ({ ...previous, error: '' }))),
|
|
1375
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1376
|
+
h('div', { className: 'dpt-toolbar' },
|
|
1377
|
+
h(Segmented, {
|
|
1378
|
+
label: '会话视图', value: viewMode,
|
|
1379
|
+
onChange: next => { setViewMode(next); setSelectedIds(new Set()); lastClickedIndex.current = -1 },
|
|
1380
|
+
items: [
|
|
1381
|
+
{ value: 'active', label: '未归档', count: sessionList.phase === 'ready' ? activeCount : null },
|
|
1382
|
+
{ value: 'archived', label: '已归档', count: sessionList.phase === 'ready' ? archivedCount : null },
|
|
1383
|
+
{ value: 'subagent', label: '子 Agent', count: hostSessions.items ? subagentCount : null },
|
|
1384
|
+
],
|
|
1385
|
+
}),
|
|
1386
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
1387
|
+
filterInput(searchScope === 'content' ? '搜索会话正文' : '搜索会话标题', query, search),
|
|
1388
|
+
host.info?.sessionSearch !== false && pick('搜索范围', searchScope, setSearchScope, [
|
|
1389
|
+
option('title', '搜标题'),
|
|
1390
|
+
option('content', '搜正文'),
|
|
1391
|
+
]),
|
|
1392
|
+
pick('工作区', workspace, selectWorkspace, [
|
|
1393
|
+
option('all', '全部工作区'),
|
|
1394
|
+
option('none', t('ungrouped')),
|
|
1395
|
+
option('orphan', t('workspaceDeleted')),
|
|
1396
|
+
...workspaceList.items.map(item => option(item.workspaceId, workspaceTitle(item, t))),
|
|
1397
|
+
]),
|
|
1398
|
+
pick('排序方式', sortBy, setSortBy, [
|
|
1399
|
+
option('recent', '最近活跃'),
|
|
1400
|
+
option('oldest', '最早创建'),
|
|
1401
|
+
option('size', '占用最大'),
|
|
1402
|
+
option('subagents', '子会话最多'),
|
|
1403
|
+
]),
|
|
1404
|
+
hasActiveFilter && rows.length > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
1405
|
+
openKeys.length >= 2 && button('收起全部', () => disclosure.collapseAll(openKeys), { icon: 'chevrons-down-up', iconSize: 13 }),
|
|
1406
|
+
iconButton('刷新会话', 'refresh-cw', silentRefresh, {
|
|
1407
|
+
iconClass: (refreshing || hostSessions.reloading || contentSearch.loading) ? 'dpt-spin' : '',
|
|
1408
|
+
disabled: refreshing, 'aria-busy': refreshing,
|
|
1409
|
+
}))),
|
|
1410
|
+
rows.length === 0
|
|
1411
|
+
? empty(usingContentSearch && contentSearch.loading
|
|
1412
|
+
? '正在检索会话正文…'
|
|
1413
|
+
: (sessionList.phase === 'ready' ? '没有符合条件的会话。' : '正在读取会话…'),
|
|
1414
|
+
sessionList.phase === 'ready' && hasActiveFilter ? resetFilters : undefined)
|
|
1415
|
+
: h('ul', { className: 'dpt-card', 'data-selecting': selectedRows.length > 0 || undefined },
|
|
1416
|
+
visibleRows.map((item, index) => h(SessionRow, {
|
|
1417
|
+
...item, key: item.id, navigation, notify: toast.show, workspaceColors, t,
|
|
1418
|
+
disclosure: disclosure(item.id),
|
|
1419
|
+
selectable: {
|
|
1420
|
+
checked: selectedIds.has(item.id),
|
|
1421
|
+
label: `选择会话 ${item.title}`,
|
|
1422
|
+
onChange: (checked, shiftKey) => toggleSelect(index, item.id, checked, shiftKey),
|
|
1423
|
+
},
|
|
1424
|
+
onArchived: message => { toast.show(message); void hostSessions.reload() },
|
|
1425
|
+
onPinned: message => { toast.show(message); void silentRefresh() },
|
|
1426
|
+
onDeleted: handleDeleted,
|
|
1427
|
+
})),
|
|
1428
|
+
scroller.sentinel),
|
|
1429
|
+
selectedRows.length > 0 && h('div', { className: 'dpt-floating-batch', role: 'region', 'aria-label': '会话批量操作' },
|
|
1430
|
+
h('span', { className: 'dpt-summary' }, `已选 ${selectedRows.length} 项${cascadedExtraCount > 0 ? `(+${cascadedExtraCount} 子会话)` : ''}`),
|
|
1431
|
+
button(allFilteredSelected ? '取消全选' : `全选 (${rows.length})`, () => {
|
|
1432
|
+
setSelectedIds(allFilteredSelected ? new Set() : new Set(rows.map(item => item.id)))
|
|
1433
|
+
}, { className: 'dpt-row-btn' }),
|
|
1434
|
+
deletableRows.length > 0 && deletableRows.length < rows.length && button(`仅选可删 (${deletableRows.length})`, () => {
|
|
1435
|
+
setSelectedIds(new Set(deletableRows.map(item => item.id)))
|
|
1436
|
+
}, { className: 'dpt-row-btn' }),
|
|
1437
|
+
h('span', { className: 'dpt-batch-sep', 'aria-hidden': true }),
|
|
1438
|
+
archivableSelected.length > 0 && button(`归档 (${archivableSelected.length})`, () => batchArchive(false), { icon: 'archive', iconSize: 13, className: 'dpt-row-btn', disabled: status.busy }),
|
|
1439
|
+
restorableSelected.length > 0 && button(`恢复 (${restorableSelected.length})`, () => batchArchive(true), { icon: 'archive-restore', iconSize: 13, className: 'dpt-row-btn', disabled: status.busy }),
|
|
1440
|
+
button(`删除 (${deletableSelected.length})`, () => setBatchRemoval(true), {
|
|
1441
|
+
icon: 'trash', iconSize: 13, className: 'dpt-row-btn dpt-danger',
|
|
1442
|
+
disabled: status.busy || deletableSelected.length === 0,
|
|
1443
|
+
title: deletableSelected.length === 0 ? '所选会话正在运行或由当前进程持有,暂不可删除' : undefined,
|
|
1444
|
+
}),
|
|
1445
|
+
iconButton('取消选择', 'x', () => setSelectedIds(new Set()), { className: 'dpt-row-icon-btn', iconSize: 13 })),
|
|
1446
|
+
batchRemoval && deletableSelected.length > 0 && h(Confirm, {
|
|
1447
|
+
title: `批量删除 ${deletableSelected.length} 条会话`,
|
|
1448
|
+
label: `确认批量删除(共 ${cascadeTargetIds.size} 条)`,
|
|
1449
|
+
removed: [
|
|
1450
|
+
...deletableSelected.slice(0, 6).map(item => `${item.row.isSubagent ? '子 Agent 会话' : '会话'}「${item.title}」(${item.id})`),
|
|
1451
|
+
...(deletableSelected.length > 6 ? [`其余 ${deletableSelected.length - 6} 条已选会话(合计 ${deletableSelected.length} 条)`] : []),
|
|
1452
|
+
...(cascadedExtraCount > 0 ? [`自动关联的 ${cascadedExtraCount} 条子 Agent 会话记录`] : []),
|
|
1453
|
+
],
|
|
1454
|
+
preserved: [
|
|
1455
|
+
...(lockedSelectedCount > 0 ? [`已自动跳过的 ${lockedSelectedCount} 条运行中或当前进程打开的会话`] : []),
|
|
1456
|
+
'工作区目录及所有项目文件',
|
|
1457
|
+
'其他未选中会话与独立分支会话',
|
|
1458
|
+
'Profile 恢复目录中的会话备份(含 manifest.json)',
|
|
1459
|
+
],
|
|
1460
|
+
close: () => setBatchRemoval(false),
|
|
1461
|
+
confirm: async () => {
|
|
1462
|
+
const result = await request('sessions', {
|
|
1463
|
+
action: 'batch-delete',
|
|
1464
|
+
sessionIds: deletableSelected.map(item => item.id),
|
|
1465
|
+
confirm: true,
|
|
1466
|
+
})
|
|
1467
|
+
setBatchRemoval(false)
|
|
1468
|
+
await handleDeleted(result)
|
|
1469
|
+
},
|
|
1470
|
+
}))
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
const mcpSources = { user: '用户配置', inherited: '继承配置', plugin: '插件注册', retired: '已移除' }
|
|
1474
|
+
const mcpSourceOrder = { user: 1, inherited: 2, plugin: 3, retired: 4 }
|
|
1475
|
+
const mcpStates = { disabled: '已停用', connected: '已连接', connecting: '连接中', reconnecting: '重连中', failed: '连接失败', closed: '已断开', 'waiting-credentials': '等待凭据', 'waiting-authorization': '等待授权' }
|
|
1476
|
+
const mcpIssues = {
|
|
1477
|
+
failed: '连接未建立。可以测试连接或重新连接。',
|
|
1478
|
+
'waiting-credentials': '请在 DSH 中检查此服务器引用的凭据。',
|
|
1479
|
+
'waiting-authorization': '请在 DSH 的连接账号界面完成授权。',
|
|
1480
|
+
closed: '服务器连接已关闭。可以尝试重新连接。',
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
const mcpFields = ['command', 'args', 'cwd', 'env', 'url', 'headers']
|
|
1484
|
+
const mcpObject = value => value && typeof value === 'object' && !Array.isArray(value)
|
|
1485
|
+
|
|
1486
|
+
function mcpDraft(text) {
|
|
1487
|
+
let data
|
|
1488
|
+
try { data = JSON.parse(text) } catch { throw new Error('JSON 格式无效,请检查括号和引号。') }
|
|
1489
|
+
if (!mcpObject(data)) throw new Error('请提供一个 MCP 服务器对象。')
|
|
1490
|
+
let name = data.name
|
|
1491
|
+
let config = data
|
|
1492
|
+
if (Object.hasOwn(data, 'mcpServers')) {
|
|
1493
|
+
if (!mcpObject(data.mcpServers) || Object.keys(data.mcpServers).length !== 1) {
|
|
1494
|
+
throw new Error('每次保存一个服务器。请在 mcpServers 中保留一项。')
|
|
1495
|
+
}
|
|
1496
|
+
const [entry] = Object.entries(data.mcpServers)
|
|
1497
|
+
name = entry[0]
|
|
1498
|
+
config = entry[1]
|
|
1499
|
+
}
|
|
1500
|
+
if (!mcpObject(config) || name !== undefined && typeof name !== 'string') throw new Error('服务器配置或名称无效。')
|
|
1501
|
+
const type = config.transport ?? config.type ?? (config.url !== undefined ? 'streamable-http' : 'stdio')
|
|
1502
|
+
const transport = type === 'http' ? 'streamable-http' : type
|
|
1503
|
+
if (!['stdio', 'streamable-http'].includes(transport)) throw new Error('传输方式须为 stdio 或 streamable-http。')
|
|
1504
|
+
const allowed = transport === 'stdio' ? ['command', 'args', 'cwd', 'env'] : ['url', 'headers']
|
|
1505
|
+
const values = {}
|
|
1506
|
+
for (const [key, value] of Object.entries(config)) {
|
|
1507
|
+
if (['name', 'type', 'transport'].includes(key)) continue
|
|
1508
|
+
if (!allowed.includes(key)) throw new Error('JSON 包含当前传输方式无法录入的字段。')
|
|
1509
|
+
if (key === 'args') {
|
|
1510
|
+
if (!Array.isArray(value) || value.some(arg => typeof arg !== 'string')) throw new Error('args 须为字符串数组。')
|
|
1511
|
+
} else if (['env', 'headers'].includes(key)) {
|
|
1512
|
+
if (!mcpObject(value) || Object.values(value).some(item => typeof item !== 'string')) throw new Error(`${key} 须为字符串映射。`)
|
|
1513
|
+
} else if (typeof value !== 'string') throw new Error(`${key} 须为字符串。`)
|
|
1514
|
+
values[key] = value
|
|
1515
|
+
}
|
|
1516
|
+
return { name: name?.trim() ?? '', transport, values }
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
function McpListFields({ fieldName, label, values, update, pairs, credentialNames = [], bearerHint = false }) {
|
|
1520
|
+
const rows = values ?? []
|
|
1521
|
+
function change(index, column, value) {
|
|
1522
|
+
update(rows.map((row, i) => i === index ? row.map((part, j) => j === column ? value : part) : row))
|
|
1523
|
+
}
|
|
1524
|
+
function addFromCredential(credName) {
|
|
1525
|
+
if (!credName) return
|
|
1526
|
+
const ref = bearerHint ? `Bearer \${credential:${credName}}` : `\${credential:${credName}}`
|
|
1527
|
+
const defaultKey = bearerHint ? 'Authorization' : credName
|
|
1528
|
+
update([...rows, [defaultKey, ref]])
|
|
1529
|
+
}
|
|
1530
|
+
return h('div', { className: 'dpt-edit' },
|
|
1531
|
+
h('span', { className: 'dpt-label' }, label),
|
|
1532
|
+
rows.map((row, index) => h('div', { key: index, className: 'dpt-argument-row' },
|
|
1533
|
+
row.map((part, column) => h('input', {
|
|
1534
|
+
key: column, className: 'dpt-mono', dir: 'ltr', spellCheck: false,
|
|
1535
|
+
'aria-label': pairs ? `${fieldName} ${index + 1} ${column ? '值' : '名称'}` : `参数 ${index + 1}`,
|
|
1536
|
+
placeholder: pairs ? column ? (bearerHint ? 'Bearer ${credential:MCP_TOKEN}' : '${credential:MCP_TOKEN}') : '名称' : '参数',
|
|
1537
|
+
value: part, onChange: e => change(index, column, e.target.value),
|
|
1538
|
+
})),
|
|
1539
|
+
button('', () => update(rows.filter((_, i) => i !== index)), { icon: 'x', iconSize: 13, className: 'dpt-danger', 'aria-label': `移除${fieldName} ${index + 1}` }))),
|
|
1540
|
+
h('div', { className: 'dpt-actions' },
|
|
1541
|
+
pairs && credentialNames.length > 0 && h('select', {
|
|
1542
|
+
'aria-label': `插入已有凭据到${fieldName}`,
|
|
1543
|
+
value: '',
|
|
1544
|
+
onChange: e => { addFromCredential(e.target.value); e.target.value = '' },
|
|
1545
|
+
},
|
|
1546
|
+
option('', '插入已有凭据…'),
|
|
1547
|
+
...credentialNames.map(cred => option(cred, cred))),
|
|
1548
|
+
button(`添加${fieldName}`, () => update([...rows, pairs ? ['', ''] : ['']]), { icon: 'plus', iconSize: 13 })))
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function McpEditor({ row, revision, credentialNames = [], close, saved }) {
|
|
1552
|
+
const [status, run, dismiss] = useAction()
|
|
1553
|
+
const [mode, setMode] = useState('form')
|
|
1554
|
+
const [name, setName] = useState(row?.name ?? '')
|
|
1555
|
+
const [transport, setTransport] = useState(row?.transport ?? 'stdio')
|
|
1556
|
+
const [values, setValues] = useState({})
|
|
1557
|
+
const [json, setJson] = useState('')
|
|
1558
|
+
const [modeError, setModeError] = useState('')
|
|
1559
|
+
const set = (key, value) => setValues(previous => ({ ...previous, [key]: value }))
|
|
1560
|
+
const switching = row && transport !== row.transport
|
|
1561
|
+
const existing = row && !switching
|
|
1562
|
+
|
|
1563
|
+
function input(key, label, placeholder, type = 'text') {
|
|
1564
|
+
return field(label, h('input', {
|
|
1565
|
+
type, dir: 'ltr', className: 'dpt-mono', spellCheck: false,
|
|
1566
|
+
value: values[key] ?? '', placeholder, onChange: e => set(key, e.target.value), autoComplete: 'off',
|
|
1567
|
+
}))
|
|
1568
|
+
}
|
|
1569
|
+
function formValues() {
|
|
1570
|
+
const result = {}
|
|
1571
|
+
const listFields = transport === 'stdio' ? ['command', 'args', 'cwd', 'env'] : ['url', 'headers']
|
|
1572
|
+
for (const key of listFields) {
|
|
1573
|
+
if (!Object.hasOwn(values, key)) continue
|
|
1574
|
+
const value = values[key]
|
|
1575
|
+
if (key === 'args') result.args = value.map(([argument]) => argument)
|
|
1576
|
+
else if (['env', 'headers'].includes(key)) {
|
|
1577
|
+
const seen = new Set()
|
|
1578
|
+
for (const [entryName, item] of value) {
|
|
1579
|
+
if (!entryName.trim() || !item.trim() || seen.has(entryName.trim())) throw new Error('请填写非空且唯一的环境变量或请求头。')
|
|
1580
|
+
seen.add(entryName.trim())
|
|
1581
|
+
}
|
|
1582
|
+
result[key] = Object.fromEntries(value.map(([entryName, item]) => [entryName.trim(), item]))
|
|
1583
|
+
} else result[key] = value
|
|
1584
|
+
}
|
|
1585
|
+
return result
|
|
1586
|
+
}
|
|
1587
|
+
function readJson() {
|
|
1588
|
+
const draft = mcpDraft(json)
|
|
1589
|
+
if (row && draft.name && row.name !== draft.name) throw new Error('编辑时请保留原服务器名称。')
|
|
1590
|
+
return { ...draft, name: row?.name ?? draft.name }
|
|
1591
|
+
}
|
|
1592
|
+
function changeMode(next) {
|
|
1593
|
+
if (mode === next) return
|
|
1594
|
+
try {
|
|
1595
|
+
if (next === 'json') {
|
|
1596
|
+
const config = { transport, ...formValues() }
|
|
1597
|
+
setJson(JSON.stringify(name.trim() ? { mcpServers: { [name.trim()]: config } } : { name: '', ...config }, null, 2))
|
|
1598
|
+
} else {
|
|
1599
|
+
const draft = readJson()
|
|
1600
|
+
setName(draft.name); setTransport(draft.transport)
|
|
1601
|
+
setValues(Object.fromEntries(mcpFields.filter(key => Object.hasOwn(draft.values, key)).map(key => {
|
|
1602
|
+
const value = draft.values[key]
|
|
1603
|
+
return [key, key === 'args' ? value.map(argument => [argument]) : ['env', 'headers'].includes(key) ? Object.entries(value) : value]
|
|
1604
|
+
})))
|
|
1605
|
+
}
|
|
1606
|
+
dismiss(); setModeError(''); setMode(next)
|
|
1607
|
+
} catch (error) { setModeError(error.message) }
|
|
1608
|
+
}
|
|
1609
|
+
async function save() {
|
|
1610
|
+
const draft = mode === 'json' ? readJson() : { name: name.trim(), transport, values: formValues() }
|
|
1611
|
+
await request('mcp', { action: row ? 'edit' : 'create', revision, name: draft.name, transport: draft.transport, ...draft.values })
|
|
1612
|
+
saved(row ? '服务器配置已更新' : '服务器已添加(默认停用,可先测试连接再启用)')
|
|
1613
|
+
}
|
|
1614
|
+
const modeNav = h('nav', { className: 'dpt-nav', 'aria-label': 'MCP 录入方式' },
|
|
1615
|
+
button('表单录入', () => changeMode('form'), { 'aria-pressed': mode === 'form', disabled: status.busy }),
|
|
1616
|
+
button('JSON 录入', () => changeMode('json'), { 'aria-pressed': mode === 'json', disabled: status.busy }))
|
|
1617
|
+
return h('div', { className: 'dpt-edit' },
|
|
1618
|
+
h('h3', null, row ? '编辑服务器' : '新增 MCP 服务器'), modeNav,
|
|
1619
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(save) } },
|
|
1620
|
+
mode === 'json' ? h(React.Fragment, null,
|
|
1621
|
+
field('MCP JSON', h('textarea', {
|
|
1622
|
+
rows: 10, value: json, spellCheck: false, dir: 'ltr', className: 'dpt-mono dpt-fixed-editor',
|
|
1623
|
+
onChange: e => { setJson(e.target.value); setModeError('') },
|
|
1624
|
+
})),
|
|
1625
|
+
muted(h(React.Fragment, null, '支持单个服务器对象或 ', code('mcpServers'), ' 中的单项。编辑时省略的字段沿用现有值。')))
|
|
1626
|
+
: h(React.Fragment, null,
|
|
1627
|
+
h('div', { className: 'dpt-form-row' },
|
|
1628
|
+
field('服务器名称', h('input', { value: name, onChange: e => setName(e.target.value), disabled: Boolean(row), required: true, dir: 'ltr', className: 'dpt-mono' })),
|
|
1629
|
+
field('传输方式', pick('传输方式', transport, value => { setTransport(value); setValues({}) }, [option('stdio', 'stdio'), option('streamable-http', 'streamable-http')]))),
|
|
1630
|
+
existing && muted('未填写的字段沿用现有值。要清空现有列表,可用 JSON 提交空数组或对象。'),
|
|
1631
|
+
switching && muted('切换传输方式会清空原传输配置。'),
|
|
1632
|
+
transport === 'stdio' ? h(React.Fragment, null,
|
|
1633
|
+
input('command', '可执行文件', 'node 或 node.exe'), input('cwd', '启动目录(绝对路径,可选)', ''),
|
|
1634
|
+
h(McpListFields, { fieldName: '参数', label: '进程参数', values: values.args, update: value => set('args', value) }),
|
|
1635
|
+
h(McpListFields, { fieldName: '环境变量', label: '环境变量 · DSH 凭据引用', values: values.env, pairs: true, credentialNames, update: value => set('env', value) }))
|
|
1636
|
+
: h(React.Fragment, null,
|
|
1637
|
+
input('url', 'MCP 地址', 'https://example.com/mcp', 'url'),
|
|
1638
|
+
h(McpListFields, { fieldName: '请求头', label: '请求头 · DSH 凭据引用', values: values.headers, pairs: true, bearerHint: true, credentialNames, update: value => set('headers', value) }))),
|
|
1639
|
+
feedback(modeError, true, () => setModeError('')), feedback(status.message, status.error, dismiss),
|
|
1640
|
+
h('div', { className: 'dpt-actions' },
|
|
1641
|
+
button('取消编辑', close, { disabled: status.busy }),
|
|
1642
|
+
primary('保存', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy }))))
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
function Confirm({ title, removed, preserved, label, close, confirm }) {
|
|
1646
|
+
const [status, run, dismiss] = useAction()
|
|
1647
|
+
return h(Modal, { title, close },
|
|
1648
|
+
h('div', { className: 'dpt-form' },
|
|
1649
|
+
h('div', { className: 'dpt-confirm-list' }, [['将移除', removed], ['将保留', preserved]].map(([heading, items]) =>
|
|
1650
|
+
h('section', { key: heading }, h('h3', null, heading), h('ul', null, items.map(item => h('li', { key: item }, item)))))),
|
|
1651
|
+
feedback(status.message, status.error, dismiss),
|
|
1652
|
+
h('div', { className: 'dpt-actions' }, button('取消', close, { autoFocus: true, disabled: status.busy }),
|
|
1653
|
+
button(label, () => run(confirm), { icon: 'trash', className: 'dpt-danger', disabled: status.busy, 'aria-busy': status.busy }))))
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
function useMcpList() {
|
|
1657
|
+
const [view, setView] = useState(null)
|
|
1658
|
+
const [error, setError] = useState('')
|
|
1659
|
+
const [reloading, setReloading] = useState(false)
|
|
1660
|
+
const generation = useRef(0)
|
|
1661
|
+
async function refresh(signal, manual = false) {
|
|
1662
|
+
const current = ++generation.current
|
|
1663
|
+
if (manual) setReloading(true)
|
|
1664
|
+
try {
|
|
1665
|
+
const next = await request('mcp', { action: 'list' }, signal)
|
|
1666
|
+
if (current === generation.current && !signal?.aborted) { setView(next); setError('') }
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
if (current === generation.current && !signal?.aborted) setError(error.message)
|
|
1669
|
+
} finally {
|
|
1670
|
+
if (manual && current === generation.current) setReloading(false)
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
useEffect(() => {
|
|
1674
|
+
const abort = new AbortController()
|
|
1675
|
+
void refresh(abort.signal)
|
|
1676
|
+
const timer = setInterval(() => refresh(abort.signal), 2500)
|
|
1677
|
+
return () => { clearInterval(timer); abort.abort(); generation.current++ }
|
|
1678
|
+
}, [])
|
|
1679
|
+
return { view, error, reloading, refresh: () => refresh(undefined, true), dismissError: () => setError('') }
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
const credentialSources = { file: '凭据文件', env: '环境变量', 'project-env': '项目 .env', 'user-env': '用户 .env' }
|
|
1683
|
+
|
|
1684
|
+
function CredentialRow({ row, disclosure, onUpdated, notify }) {
|
|
1685
|
+
const [editing, setEditing] = useState(false)
|
|
1686
|
+
const [value, setValue] = useState('')
|
|
1687
|
+
const [removal, setRemoval] = useState(false)
|
|
1688
|
+
const [status, run, dismiss] = useAction()
|
|
1689
|
+
|
|
1690
|
+
async function copyRef() {
|
|
1691
|
+
const ref = `\${credential:${row.name}}`
|
|
1692
|
+
try {
|
|
1693
|
+
if (!await writeClipboard(ref)) throw new Error('clipboard unavailable')
|
|
1694
|
+
notify(`已复制 ${ref}`)
|
|
1695
|
+
} catch {
|
|
1696
|
+
notify('无法访问剪贴板,请手动复制凭据引用。', { error: true })
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
const missing = !row.configured
|
|
1701
|
+
const detailParts = [
|
|
1702
|
+
row.source ? credentialSources[row.source] ?? row.source : '尚未配置值',
|
|
1703
|
+
row.referencedBy?.length > 0 ? `被 ${row.referencedBy.join('、')} 引用` : '',
|
|
1704
|
+
].filter(Boolean)
|
|
1705
|
+
|
|
1706
|
+
const quickActions = h(React.Fragment, null,
|
|
1707
|
+
iconButton(`复制 ${row.name} 引用`, 'copy', copyRef, {
|
|
1708
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: `复制 \${credential:${row.name}}`,
|
|
1709
|
+
}),
|
|
1710
|
+
row.writable && iconButton(`更新 ${row.name}`, 'square-pen', () => { setEditing(true); disclosure.open() }, {
|
|
1711
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: missing ? '设置凭据值' : '更新凭据值', disabled: status.busy,
|
|
1712
|
+
}))
|
|
1713
|
+
|
|
1714
|
+
return h(DisclosureRow, {
|
|
1715
|
+
'data-credential-name': row.name,
|
|
1716
|
+
title: row.name,
|
|
1717
|
+
tag: row.masked || (missing ? '未设置' : undefined),
|
|
1718
|
+
detail: detailParts.join(' · '),
|
|
1719
|
+
badge: missing ? '缺失' : '已配置',
|
|
1720
|
+
tone: missing ? 'attention' : 'ready',
|
|
1721
|
+
quickActions,
|
|
1722
|
+
...disclosure,
|
|
1723
|
+
},
|
|
1724
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1725
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
1726
|
+
h('span', null, '引用模板', code(`\${credential:${row.name}}`)),
|
|
1727
|
+
row.source && h('span', null, '当前来源', h('strong', null, credentialSources[row.source] ?? row.source)),
|
|
1728
|
+
row.masked && h('span', null, '脱敏预览', code(row.masked))),
|
|
1729
|
+
h('div', { className: 'dpt-actions' },
|
|
1730
|
+
button('复制引用', copyRef, { icon: 'copy', iconSize: 13 }),
|
|
1731
|
+
row.writable && !editing && button(missing ? '设置值' : '更新值', () => setEditing(true), { icon: 'square-pen', disabled: status.busy }),
|
|
1732
|
+
row.source === 'file' && row.writable && button('移除', () => setRemoval(true), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
1733
|
+
row.referencedBy?.length > 0 && muted(`引用的 MCP 服务器:${row.referencedBy.join('、')}`),
|
|
1734
|
+
editing && h('form', {
|
|
1735
|
+
className: 'dpt-form dpt-drawer-split',
|
|
1736
|
+
onSubmit: e => {
|
|
1737
|
+
e.preventDefault()
|
|
1738
|
+
void run(async () => {
|
|
1739
|
+
await request('credentials', { action: 'set', name: row.name, value })
|
|
1740
|
+
setValue(''); setEditing(false)
|
|
1741
|
+
notify(`凭据 ${row.name} 已更新`)
|
|
1742
|
+
await onUpdated()
|
|
1743
|
+
})
|
|
1744
|
+
},
|
|
1745
|
+
},
|
|
1746
|
+
field('新凭据值(仅写入 DSH 凭据文件,不回显原文)', h('input', {
|
|
1747
|
+
type: 'password', autoComplete: 'new-password', required: true, autoFocus: true,
|
|
1748
|
+
dir: 'ltr', className: 'dpt-mono', value, onChange: e => setValue(e.target.value),
|
|
1749
|
+
})),
|
|
1750
|
+
h('div', { className: 'dpt-actions' },
|
|
1751
|
+
button('取消', () => { setEditing(false); setValue(''); dismiss() }, { disabled: status.busy }),
|
|
1752
|
+
primary('保存凭据', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy }))),
|
|
1753
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1754
|
+
removal && h(Confirm, {
|
|
1755
|
+
title: `移除凭据 ${row.name}`,
|
|
1756
|
+
label: '确认移除凭据',
|
|
1757
|
+
removed: [`DSH 托管凭据文件中的 ${row.name}`],
|
|
1758
|
+
preserved: ['进程环境变量与 .env 文件中的同名项(若存在将自动回退生效)', '引用该凭据的 MCP 配置条目'],
|
|
1759
|
+
close: () => setRemoval(false),
|
|
1760
|
+
confirm: async () => {
|
|
1761
|
+
const result = await request('credentials', { action: 'unset', name: row.name, confirm: row.name })
|
|
1762
|
+
setRemoval(false)
|
|
1763
|
+
notify(result.credential?.configured
|
|
1764
|
+
? `已从凭据文件移除 ${row.name}(当前由${credentialSources[result.credential.source] ?? result.credential.source}继续提供)`
|
|
1765
|
+
: `已移除凭据 ${row.name}`)
|
|
1766
|
+
await onUpdated()
|
|
1767
|
+
},
|
|
1768
|
+
}))
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
function CredentialsPanel({ rows, error, onRefresh, onUpdated, notify }) {
|
|
1772
|
+
const [name, setName] = useState('')
|
|
1773
|
+
const [value, setValue] = useState('')
|
|
1774
|
+
const [lookupResult, setLookupResult] = useState(null)
|
|
1775
|
+
const [status, run, dismiss] = useAction()
|
|
1776
|
+
const disclosure = useDisclosure()
|
|
1777
|
+
const items = rows ?? []
|
|
1778
|
+
const missingCount = items.filter(item => !item.configured).length
|
|
1779
|
+
|
|
1780
|
+
async function saveNew() {
|
|
1781
|
+
const cleanName = name.trim()
|
|
1782
|
+
await request('credentials', { action: 'set', name: cleanName, value })
|
|
1783
|
+
setName(''); setValue(''); setLookupResult(null)
|
|
1784
|
+
notify(`凭据 ${cleanName} 已保存`)
|
|
1785
|
+
await onUpdated()
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
async function checkName() {
|
|
1789
|
+
const cleanName = name.trim()
|
|
1790
|
+
if (!cleanName) return
|
|
1791
|
+
await run(async () => {
|
|
1792
|
+
const result = await request('credentials', { action: 'describe', name: cleanName })
|
|
1793
|
+
setLookupResult(result.credential)
|
|
1794
|
+
})
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
return h(PanelSection, {
|
|
1798
|
+
title: 'DSH 凭据',
|
|
1799
|
+
summary: rows ? `${items.length} 项${missingCount > 0 ? ` · ${missingCount} 项缺失` : ''} · 仅写不读` : undefined,
|
|
1800
|
+
},
|
|
1801
|
+
h('div', { className: 'dpt-card dpt-empty dpt-edit' },
|
|
1802
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(saveNew) } },
|
|
1803
|
+
h('div', { className: 'dpt-form-row' },
|
|
1804
|
+
field('凭据名称(环境变量标识符)', h('input', {
|
|
1805
|
+
value: name, required: true, dir: 'ltr', className: 'dpt-mono', spellCheck: false, autoComplete: 'off',
|
|
1806
|
+
placeholder: '例如 MCP_GITHUB_TOKEN',
|
|
1807
|
+
onChange: e => { setName(e.target.value); setLookupResult(null) },
|
|
1808
|
+
})),
|
|
1809
|
+
field('凭据值(不回显原文)', h('input', {
|
|
1810
|
+
type: 'password', autoComplete: 'new-password', required: true, dir: 'ltr', className: 'dpt-mono',
|
|
1811
|
+
placeholder: '输入密钥或令牌', value, onChange: e => setValue(e.target.value),
|
|
1812
|
+
}))),
|
|
1813
|
+
h('div', { className: 'dpt-actions' },
|
|
1814
|
+
button('查询环境变量状态', checkName, { icon: 'eye', disabled: status.busy || !name.trim() }),
|
|
1815
|
+
primary('保存凭据', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy }))),
|
|
1816
|
+
lookupResult && muted(lookupResult.configured
|
|
1817
|
+
? `${lookupResult.name} 已配置(来源:${credentialSources[lookupResult.source] ?? lookupResult.source}${lookupResult.masked ? ` · ${lookupResult.masked}` : ''})`
|
|
1818
|
+
: `${lookupResult.name} 尚未配置,可直接填写上方凭据值保存。`),
|
|
1819
|
+
feedback(error, true, onRefresh),
|
|
1820
|
+
feedback(status.error ? status.message : '', true, dismiss)),
|
|
1821
|
+
items.length > 0
|
|
1822
|
+
? h('ul', { className: 'dpt-card' }, items.map(row => h(CredentialRow, {
|
|
1823
|
+
key: row.name, row, notify, onUpdated,
|
|
1824
|
+
disclosure: disclosure(row.name, !row.configured),
|
|
1825
|
+
})))
|
|
1826
|
+
: empty(rows ? '尚未在 DSH 凭据文件中保存凭据,也没有待配置的 MCP 凭据引用。' : error ? '凭据列表暂不可用。' : '正在读取凭据状态…'))
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
function McpRow({ row, revision, credentialNames, refresh, removed, disclosure, onProbed, notify }) {
|
|
1830
|
+
const [editing, setEditing] = useState(null)
|
|
1831
|
+
const [removal, setRemoval] = useState(null)
|
|
1832
|
+
const [probedTools, setProbedTools] = useState(null)
|
|
1833
|
+
const [toolQuery, setToolQuery] = useState('')
|
|
1834
|
+
const [showAllTools, setShowAllTools] = useState(false)
|
|
1835
|
+
const [optimisticEnabled, setOptimisticEnabled] = useState(null)
|
|
1836
|
+
const [status, run, dismiss] = useAction()
|
|
1837
|
+
useEffect(() => { setOptimisticEnabled(null) }, [row.enabled, row.status])
|
|
1838
|
+
const effectiveEnabled = optimisticEnabled ?? row.enabled
|
|
1839
|
+
const issue = row.enabled && mcpIssues[row.status]
|
|
1840
|
+
const tone = issue ? 'attention' : row.status === 'connected' ? 'ready' : effectiveEnabled ? 'info' : 'idle'
|
|
1841
|
+
|
|
1842
|
+
function operation(action, success, expandOnDone = false) {
|
|
1843
|
+
if (action === 'enable' || action === 'disable') setOptimisticEnabled(action === 'enable')
|
|
1844
|
+
return run(async () => {
|
|
1845
|
+
try {
|
|
1846
|
+
const result = await request('mcp', { action, name: row.name, revision })
|
|
1847
|
+
await refresh()
|
|
1848
|
+
if (action === 'probe') {
|
|
1849
|
+
if (!result.closed) throw new Error(`${row.name} 的探测进程未确认清理。`)
|
|
1850
|
+
if (!result.ok) throw new Error(`${row.name} ${result.stage === 'list' ? '工具列表读取失败' : '连接测试失败'}。`)
|
|
1851
|
+
const names = result.toolNames ?? []
|
|
1852
|
+
setProbedTools({ names, truncated: Boolean(result.truncated) })
|
|
1853
|
+
setToolQuery('')
|
|
1854
|
+
setShowAllTools(false)
|
|
1855
|
+
onProbed?.(row.name, names)
|
|
1856
|
+
if (expandOnDone && names.length > 0) disclosure.open()
|
|
1857
|
+
const msg = `${row.name} 测试通过 · ${result.toolCount}${result.truncated ? '+' : ''} 个工具 · ${result.durationMs} ms`
|
|
1858
|
+
notify(msg)
|
|
1859
|
+
return msg
|
|
1860
|
+
}
|
|
1861
|
+
if (success) notify(`${row.name} ${success}`)
|
|
1862
|
+
return `${row.name} ${success}`
|
|
1863
|
+
} catch (err) {
|
|
1864
|
+
setOptimisticEnabled(null)
|
|
1865
|
+
throw err
|
|
1866
|
+
}
|
|
1867
|
+
})
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
const allTools = probedTools?.names ?? []
|
|
1871
|
+
const filteredTools = toolQuery.trim() ? allTools.filter(tool => matches(toolQuery, tool)) : allTools
|
|
1872
|
+
const visibleTools = showAllTools ? filteredTools : filteredTools.slice(0, 24)
|
|
1873
|
+
|
|
1874
|
+
const quickActions = row.testable && iconButton(
|
|
1875
|
+
`测试 ${row.name}`, 'play', () => operation('probe', '', true),
|
|
1876
|
+
{ className: 'dpt-row-icon-btn', iconSize: 13, title: '测试连接', disabled: status.busy },
|
|
1877
|
+
)
|
|
1878
|
+
const alwaysActions = row.editable && h(Switch, {
|
|
1879
|
+
checked: effectiveEnabled,
|
|
1880
|
+
disabled: status.busy,
|
|
1881
|
+
label: `${effectiveEnabled ? '停用' : '启用'} ${row.name}`,
|
|
1882
|
+
onChange: next => operation(next ? 'enable' : 'disable', next ? '已启用' : '已停用'),
|
|
1883
|
+
})
|
|
1884
|
+
|
|
1885
|
+
return h(DisclosureRow, {
|
|
1886
|
+
title: row.name, tag: row.transport,
|
|
1887
|
+
detail: [
|
|
1888
|
+
mcpSources[row.source],
|
|
1889
|
+
row.transport === 'stdio' ? '本地进程' : row.transport === 'streamable-http' ? 'HTTP 服务' : '传输未公开',
|
|
1890
|
+
Number.isInteger(row.toolCount) ? `${row.toolCount} 个工具` : '',
|
|
1891
|
+
].filter(Boolean).join(' · '),
|
|
1892
|
+
badge: mcpStates[row.status] ?? '状态未知', tone,
|
|
1893
|
+
quickActions, alwaysActions, ...disclosure,
|
|
1894
|
+
},
|
|
1895
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1896
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
1897
|
+
h('span', null, '来源', h('strong', null, mcpSources[row.source])),
|
|
1898
|
+
h('span', null, '传输', row.transport ? code(row.transport) : h('strong', null, '未公开')),
|
|
1899
|
+
h('span', null, '配置', h('strong', null, row.enabled ? '启用' : '停用')),
|
|
1900
|
+
Number.isInteger(row.toolCount) && h('span', null, '工具', h('strong', null, row.toolCount))),
|
|
1901
|
+
h('div', { className: 'dpt-actions' },
|
|
1902
|
+
row.testable && button('测试连接', () => operation('probe'), { icon: 'play', disabled: status.busy, 'aria-busy': status.busy }),
|
|
1903
|
+
row.reconnectable && button('重连', () => operation('restart', '已请求重连'), { icon: 'rotate-cw', disabled: status.busy }),
|
|
1904
|
+
row.editable && button(row.enabled ? '停用' : '启用', () => operation(row.enabled ? 'disable' : 'enable', row.enabled ? '已停用' : '已启用'), { disabled: status.busy }),
|
|
1905
|
+
row.editable && !editing && button('编辑', () => setEditing({ revision }), { icon: 'square-pen', disabled: status.busy }),
|
|
1906
|
+
row.editable && button('移除', () => setRemoval({ revision }), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
1907
|
+
allTools.length > 0 && h('div', { className: 'dpt-edit' },
|
|
1908
|
+
allTools.length > 12 && h('div', { className: 'dpt-drawer-bar' },
|
|
1909
|
+
h('span', { className: 'dpt-label' }, `探测工具(${filteredTools.length}${filteredTools.length !== allTools.length ? ` / ${allTools.length}` : ''}${probedTools.truncated ? '+' : ''})`),
|
|
1910
|
+
h('div', { className: 'dpt-actions' },
|
|
1911
|
+
h('input', {
|
|
1912
|
+
type: 'search', className: 'dpt-inline-filter',
|
|
1913
|
+
'aria-label': `筛选 ${row.name} 工具`, placeholder: '筛选工具名…',
|
|
1914
|
+
value: toolQuery, onChange: e => setToolQuery(e.target.value),
|
|
1915
|
+
onKeyDown: e => { if (e.key === 'Escape' && toolQuery) { e.preventDefault(); setToolQuery('') } },
|
|
1916
|
+
}),
|
|
1917
|
+
filteredTools.length > 24 && button(showAllTools ? '收起列表' : `展开全部 ${filteredTools.length} 个`, () => setShowAllTools(!showAllTools)))),
|
|
1918
|
+
filteredTools.length > 0
|
|
1919
|
+
? h('div', { className: `dpt-tool-list${showAllTools && filteredTools.length > 24 ? ' dpt-scroll-box' : ''}`, 'aria-label': '探测到的工具' },
|
|
1920
|
+
visibleTools.map(tool => h('code', { key: tool, className: 'dpt-mono dpt-tool-chip', dir: 'ltr' }, tool)),
|
|
1921
|
+
(!showAllTools && filteredTools.length > 24)
|
|
1922
|
+
? h('span', { className: 'dpt-muted' }, `…其余 ${filteredTools.length - 24} 个`)
|
|
1923
|
+
: (probedTools.truncated && !toolQuery.trim() && h('span', { className: 'dpt-muted' }, '…')))
|
|
1924
|
+
: muted('没有匹配的探测工具。')),
|
|
1925
|
+
issue && muted(issue),
|
|
1926
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1927
|
+
editing && h('div', { className: 'dpt-drawer-split' }, h(McpEditor, {
|
|
1928
|
+
row, ...editing, credentialNames, close: () => setEditing(null), saved: message => {
|
|
1929
|
+
dismiss(); notify(message); setEditing(null); void refresh()
|
|
1930
|
+
},
|
|
1931
|
+
})),
|
|
1932
|
+
removal && h(Confirm, {
|
|
1933
|
+
title: `移除 ${row.name}`, label: '移除服务器',
|
|
1934
|
+
removed: [`服务器「${row.name}」的用户配置`, '此服务器的连接与会话中的工具注册'],
|
|
1935
|
+
preserved: ['本机可执行文件及资源', 'DSH 凭据和其他 MCP 服务器配置'],
|
|
1936
|
+
close: () => setRemoval(null), confirm: async () => {
|
|
1937
|
+
await request('mcp', { action: 'remove', name: row.name, revision: removal.revision })
|
|
1938
|
+
setRemoval(null); removed(row.name); await refresh()
|
|
1939
|
+
},
|
|
1940
|
+
}))
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
function McpPanel({ host, toast }) {
|
|
1944
|
+
const { view, error, reloading, refresh, dismissError } = useMcpList()
|
|
1945
|
+
const [query, search] = useState('')
|
|
1946
|
+
const [sourceFilter, setSourceFilter] = useState('all')
|
|
1947
|
+
const [statusFilter, setStatusFilter] = useState('all')
|
|
1948
|
+
const [probedByServer, setProbedByServer] = useState({})
|
|
1949
|
+
const [editor, setEditor] = useState(null)
|
|
1950
|
+
const [credentialsOpen, setCredentialsOpen] = useState(false)
|
|
1951
|
+
const [credentials, setCredentials] = useState(null)
|
|
1952
|
+
const [credentialsError, setCredentialsError] = useState('')
|
|
1953
|
+
const disclosure = useDisclosure()
|
|
1954
|
+
const rows = (view?.servers ?? []).filter(row => row.source !== 'retired')
|
|
1955
|
+
const connectedCount = rows.filter(row => row.status === 'connected').length
|
|
1956
|
+
const issueCount = rows.filter(row => row.enabled && mcpIssues[row.status]).length
|
|
1957
|
+
const disabledCount = rows.filter(row => !row.enabled).length
|
|
1958
|
+
|
|
1959
|
+
async function reloadCredentials(signal) {
|
|
1960
|
+
if (host.info?.credentials === false) return
|
|
1961
|
+
try {
|
|
1962
|
+
const result = await request('credentials', { action: 'list' }, signal)
|
|
1963
|
+
if (!signal?.aborted) { setCredentials(result.credentials); setCredentialsError('') }
|
|
1964
|
+
} catch (err) {
|
|
1965
|
+
if (!signal?.aborted) setCredentialsError(err.message)
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
useEffect(() => {
|
|
1970
|
+
if (host.info?.credentials === false) return
|
|
1971
|
+
const abort = new AbortController()
|
|
1972
|
+
void reloadCredentials(abort.signal)
|
|
1973
|
+
return () => abort.abort()
|
|
1974
|
+
}, [host.info?.credentials, view?.revision])
|
|
1975
|
+
|
|
1976
|
+
const credentialNames = (credentials ?? []).map(item => item.name)
|
|
1977
|
+
const missingCredentials = (credentials ?? []).filter(item => !item.configured).length
|
|
1978
|
+
|
|
1979
|
+
const filtered = rows.filter(row => {
|
|
1980
|
+
if (sourceFilter !== 'all' && row.source !== sourceFilter) return false
|
|
1981
|
+
if (statusFilter === 'connected' && row.status !== 'connected') return false
|
|
1982
|
+
if (statusFilter === 'issue' && !(row.enabled && mcpIssues[row.status])) return false
|
|
1983
|
+
if (statusFilter === 'disabled' && row.enabled) return false
|
|
1984
|
+
return matches(query, row.name, row.transport ?? '', mcpSources[row.source], ...(probedByServer[row.name] ?? []))
|
|
1985
|
+
}).sort((a, b) => (mcpSourceOrder[a.source] ?? 9) - (mcpSourceOrder[b.source] ?? 9))
|
|
1986
|
+
|
|
1987
|
+
const hasActiveFilter = Boolean(query.trim()) || sourceFilter !== 'all' || statusFilter !== 'all'
|
|
1988
|
+
const resetFilters = () => { search(''); setSourceFilter('all'); setStatusFilter('all') }
|
|
1989
|
+
const scroller = useInfiniteScroll(filtered.length, `${query}\n${sourceFilter}\n${statusFilter}`, 50)
|
|
1990
|
+
const visibleRows = filtered.slice(0, scroller.limit)
|
|
1991
|
+
const openKeys = visibleRows.filter(row => disclosure.isOpen(row.name, Boolean(row.enabled && mcpIssues[row.status]))).map(row => row.name)
|
|
1992
|
+
|
|
1993
|
+
return h('div', { className: 'dpt-panel' },
|
|
1994
|
+
feedback(host.error || (host.info?.mcp === false ? '当前 DSH 配置未加载 MCP 服务。' : ''), true, host.dismiss),
|
|
1995
|
+
feedback(error, true, dismissError),
|
|
1996
|
+
h('div', { className: 'dpt-toolbar' },
|
|
1997
|
+
h(Segmented, {
|
|
1998
|
+
label: 'MCP 状态筛选', value: statusFilter, onChange: setStatusFilter,
|
|
1999
|
+
items: [
|
|
2000
|
+
{ value: 'all', label: '全部', count: view ? rows.length : null },
|
|
2001
|
+
{ value: 'connected', label: '已连接', count: view ? connectedCount : null },
|
|
2002
|
+
{ value: 'issue', label: '异常', count: view ? issueCount : null, alert: issueCount > 0 },
|
|
2003
|
+
{ value: 'disabled', label: '已停用', count: view ? disabledCount : null },
|
|
2004
|
+
],
|
|
2005
|
+
}),
|
|
2006
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
2007
|
+
rows.length > 0 && filterInput('搜索 MCP 服务器', query, search),
|
|
2008
|
+
rows.length > 0 && pick('MCP 来源筛选', sourceFilter, setSourceFilter, [
|
|
2009
|
+
option('all', '全部来源'),
|
|
2010
|
+
option('user', '用户配置'),
|
|
2011
|
+
option('inherited', '继承配置'),
|
|
2012
|
+
option('plugin', '插件注册'),
|
|
2013
|
+
]),
|
|
2014
|
+
hasActiveFilter && filtered.length > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
2015
|
+
openKeys.length >= 2 && button('收起全部', () => disclosure.collapseAll(openKeys), { icon: 'chevrons-down-up', iconSize: 13 }),
|
|
2016
|
+
iconButton('刷新 MCP', 'refresh-cw', () => { void refresh(); void reloadCredentials() }, { iconClass: reloading ? 'dpt-spin' : '', disabled: reloading, 'aria-busy': reloading }),
|
|
2017
|
+
host.info?.credentials !== false && button(missingCredentials > 0 ? `凭据管理 (${missingCredentials})` : '凭据管理', () => setCredentialsOpen(!credentialsOpen), { icon: 'key-round', 'aria-expanded': credentialsOpen }),
|
|
2018
|
+
primary('新增服务器', () => setEditor({ revision: view.revision }), { icon: 'plus', disabled: !view?.writable || Boolean(editor) }))),
|
|
2019
|
+
credentialsOpen && h(CredentialsPanel, {
|
|
2020
|
+
rows: credentials, error: credentialsError, notify: toast.show,
|
|
2021
|
+
onRefresh: () => void reloadCredentials(),
|
|
2022
|
+
onUpdated: async () => { await Promise.all([reloadCredentials(), refresh()]) },
|
|
2023
|
+
}),
|
|
2024
|
+
editor && h('div', { className: 'dpt-card dpt-empty' }, h(McpEditor, {
|
|
2025
|
+
...editor, credentialNames, close: () => setEditor(null), saved: message => {
|
|
2026
|
+
toast.show(message); setEditor(null); void refresh(); void reloadCredentials()
|
|
2027
|
+
},
|
|
2028
|
+
})),
|
|
2029
|
+
filtered.length ? h('ul', { className: 'dpt-card' }, (() => {
|
|
2030
|
+
const groups = Object.entries(mcpSources).map(([source, title]) => [source, title, visibleRows.filter(row => row.source === source)]).filter(([, , items]) => items.length > 0)
|
|
2031
|
+
return groups.map(([source, title, group]) => h(React.Fragment, { key: source },
|
|
2032
|
+
groups.length > 1 && h('li', { className: 'dpt-subhead' }, title),
|
|
2033
|
+
group.map(row => h(McpRow, {
|
|
2034
|
+
key: row.name, row, revision: view.revision, credentialNames, refresh, notify: toast.show,
|
|
2035
|
+
disclosure: disclosure(row.name, Boolean(row.enabled && mcpIssues[row.status])),
|
|
2036
|
+
onProbed: (serverName, names) => setProbedByServer(previous => ({ ...previous, [serverName]: names })),
|
|
2037
|
+
removed: name => { toast.show(`已移除服务器 · ${name}`); void reloadCredentials() },
|
|
2038
|
+
}))))
|
|
2039
|
+
})(), scroller.sentinel)
|
|
2040
|
+
: empty(rows.length ? '没有符合条件的 MCP 服务器。' : view ? '暂无 MCP 服务器,点击右上角「新增服务器」添加。' : error ? '服务器列表暂不可用。' : '正在读取 MCP 服务器…', rows.length && hasActiveFilter ? resetFilters : undefined))
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
const skillSources = { 'project-dsh': '项目 · DSH', 'project-agents': '项目 · Agents', 'user-dsh': '个人 · DSH', 'user-agents': '个人 · Agents', bundled: '内置', runtime: '插件', custom: '自定义目录' }
|
|
2044
|
+
const skillSourceOrder = { 'project-dsh': 1, 'project-agents': 2, 'user-dsh': 3, 'user-agents': 4, custom: 5, runtime: 6, bundled: 7 }
|
|
2045
|
+
|
|
2046
|
+
function SkillPreview({ preview, initialEditing = false, close, update }) {
|
|
2047
|
+
const [editing, setEditing] = useState(initialEditing)
|
|
2048
|
+
const [showAllFiles, setShowAllFiles] = useState(false)
|
|
2049
|
+
const [description, setDescription] = useState(preview.description)
|
|
2050
|
+
const [body, setBody] = useState(preview.body)
|
|
2051
|
+
const [modelInvocable, model] = useState(preview.modelInvocable)
|
|
2052
|
+
const [userInvocable, user] = useState(preview.userInvocable)
|
|
2053
|
+
const [status, run, dismiss] = useAction()
|
|
2054
|
+
const files = preview.files ?? []
|
|
2055
|
+
const visibleFiles = showAllFiles ? files : files.slice(0, 8)
|
|
2056
|
+
return h('div', { className: 'dpt-edit' }, editing
|
|
2057
|
+
? h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(() => update({ description, body, modelInvocable, userInvocable })) } },
|
|
2058
|
+
field('描述', h('input', { required: true, value: description, onChange: e => setDescription(e.target.value) })),
|
|
2059
|
+
field('正文', h('textarea', { rows: 11, className: 'dpt-mono dpt-fixed-editor', value: body, onChange: e => setBody(e.target.value) })),
|
|
2060
|
+
h('div', { className: 'dpt-actions' },
|
|
2061
|
+
h('label', { className: 'dpt-check' }, h('input', { type: 'checkbox', checked: modelInvocable, onChange: e => model(e.target.checked) }), '允许模型调用'),
|
|
2062
|
+
h('label', { className: 'dpt-check' }, h('input', { type: 'checkbox', checked: userInvocable, onChange: e => user(e.target.checked) }), '允许用户手动调用')),
|
|
2063
|
+
feedback(status.message, status.error, dismiss),
|
|
2064
|
+
h('div', { className: 'dpt-actions' }, primary('保存 Skill', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy }),
|
|
2065
|
+
button('取消编辑', () => {
|
|
2066
|
+
setDescription(preview.description); setBody(preview.body); model(preview.modelInvocable); user(preview.userInvocable)
|
|
2067
|
+
dismiss()
|
|
2068
|
+
if (initialEditing) close()
|
|
2069
|
+
else setEditing(false)
|
|
2070
|
+
}, { disabled: status.busy })))
|
|
2071
|
+
: h(React.Fragment, null,
|
|
2072
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2073
|
+
muted(h(React.Fragment, null, preview.raw ? code('SKILL.md') : 'DSH 提供的 Skill 正文',
|
|
2074
|
+
preview.bytes ? ` · ${formatBytes(preview.bytes)}` : '')),
|
|
2075
|
+
h('div', { className: 'dpt-actions' },
|
|
2076
|
+
preview.editable && button('编辑内容与权限', () => setEditing(true), { icon: 'square-pen' }),
|
|
2077
|
+
button('关闭预览', close, { icon: 'x', iconSize: 13 }))),
|
|
2078
|
+
preview.meta?.length > 0 && h('div', { className: 'dpt-drawer-facts' },
|
|
2079
|
+
preview.meta.map(entry => h('span', { key: entry.key }, entry.key, code(entry.value)))),
|
|
2080
|
+
h('pre', { className: 'dpt-mono', dir: 'ltr' }, preview.markdown),
|
|
2081
|
+
files.length > 0 && h('div', { className: 'dpt-edit' },
|
|
2082
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2083
|
+
h('span', { className: 'dpt-label' }, `随附文件(${files.length})`),
|
|
2084
|
+
files.length > 8 && button(showAllFiles ? '收起文件列表' : `展开全部 ${files.length} 个文件`, () => setShowAllFiles(!showAllFiles))),
|
|
2085
|
+
h('ul', { className: `dpt-file-list${showAllFiles && files.length > 8 ? ' dpt-scroll-box' : ''}` }, visibleFiles.map(file =>
|
|
2086
|
+
h('li', { key: file.path }, code(file.path), h('span', null, formatBytes(file.size))))))))
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
function SkillImport({ workspace, navigation, close, save }) {
|
|
2090
|
+
const [directory, setDirectory] = useState('')
|
|
2091
|
+
const [destination, setDestination] = useState(workspace ? 'project' : 'personal')
|
|
2092
|
+
const [status, run, dismiss] = useAction()
|
|
2093
|
+
return h('div', { className: 'dpt-edit' }, h('h3', null, '导入本地 Skill'),
|
|
2094
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(() => save({ directory: directory.trim(), destination })) } },
|
|
2095
|
+
field('来源目录(包含 SKILL.md)', h('input', { required: true, autoFocus: true, value: directory, onChange: e => setDirectory(e.target.value), dir: 'ltr', className: 'dpt-mono' })),
|
|
2096
|
+
h('div', { className: 'dpt-actions' },
|
|
2097
|
+
button('选择本地目录', () => run(async () => { const dir = await navigation.pickDirectory(); if (dir) setDirectory(dir) }), { icon: 'folder', disabled: status.busy })),
|
|
2098
|
+
field('导入位置', pick('导入位置', destination, setDestination, [workspace && option('project', '当前项目'), option('personal', '个人 DSH')].filter(Boolean))),
|
|
2099
|
+
feedback(status.message, status.error, dismiss),
|
|
2100
|
+
h('div', { className: 'dpt-actions' }, button('取消', close, { disabled: status.busy }),
|
|
2101
|
+
primary('导入', undefined, { type: 'submit', icon: 'folder-plus', disabled: status.busy, 'aria-busy': status.busy }))))
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
function SkillRow({ row, scope, disclosure, refresh, removed, notify }) {
|
|
2105
|
+
const [preview, setPreview] = useState(null)
|
|
2106
|
+
const [startInEdit, setStartInEdit] = useState(false)
|
|
2107
|
+
const [removal, setRemoval] = useState(false)
|
|
2108
|
+
const [optimisticPerm, setOptimisticPerm] = useState(null)
|
|
2109
|
+
const [status, run, dismiss] = useAction()
|
|
2110
|
+
useEffect(() => { setOptimisticPerm(null) }, [row.modelInvocable, row.userInvocable])
|
|
2111
|
+
const modelChecked = optimisticPerm ? optimisticPerm.model : row.modelInvocable
|
|
2112
|
+
const userChecked = optimisticPerm ? optimisticPerm.user : row.userInvocable
|
|
2113
|
+
|
|
2114
|
+
async function load() {
|
|
2115
|
+
return request('skills', { ...scope, action: 'preview', name: row.name })
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
async function openMode(editMode) {
|
|
2119
|
+
await run(async () => {
|
|
2120
|
+
const current = await load()
|
|
2121
|
+
setStartInEdit(editMode)
|
|
2122
|
+
setPreview(current)
|
|
2123
|
+
disclosure.open()
|
|
2124
|
+
})
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
async function quickTogglePermission(nextModel, nextUser) {
|
|
2128
|
+
setOptimisticPerm({ model: nextModel, user: nextUser })
|
|
2129
|
+
await run(async () => {
|
|
2130
|
+
try {
|
|
2131
|
+
const current = await load()
|
|
2132
|
+
await request('skills', {
|
|
2133
|
+
...scope, action: 'edit', name: row.name, revision: current.revision,
|
|
2134
|
+
description: current.description, body: current.body,
|
|
2135
|
+
modelInvocable: nextModel, userInvocable: nextUser,
|
|
2136
|
+
})
|
|
2137
|
+
if (preview) setPreview(await load())
|
|
2138
|
+
notify(`${row.name} 调用权限已更新`)
|
|
2139
|
+
await refresh()
|
|
2140
|
+
} catch (err) {
|
|
2141
|
+
setOptimisticPerm(null)
|
|
2142
|
+
throw err
|
|
2143
|
+
}
|
|
2144
|
+
})
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
const restrictionChips = (!modelChecked || !userChecked) && h(React.Fragment, null,
|
|
2148
|
+
!modelChecked && pill('模型停用', 'attention'),
|
|
2149
|
+
!userChecked && pill('手动停用'))
|
|
2150
|
+
|
|
2151
|
+
const quickActions = h(React.Fragment, null,
|
|
2152
|
+
iconButton(`快速预览 ${row.name}`, 'eye', () => openMode(false), { className: 'dpt-row-icon-btn', iconSize: 13, title: '预览 SKILL.md', disabled: status.busy }),
|
|
2153
|
+
row.editable && iconButton(`快速编辑 ${row.name}`, 'square-pen', () => openMode(true), { className: 'dpt-row-icon-btn', iconSize: 13, title: '编辑内容与权限', disabled: status.busy }))
|
|
2154
|
+
|
|
2155
|
+
return h(DisclosureRow, {
|
|
2156
|
+
title: row.name, chips: restrictionChips, detail: row.description,
|
|
2157
|
+
badge: row.editable ? '可编辑' : '只读', tone: row.editable ? 'ready' : 'idle',
|
|
2158
|
+
quickActions, ...disclosure,
|
|
2159
|
+
},
|
|
2160
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2161
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
2162
|
+
h('span', null, '来源', h('strong', null, skillSources[row.source] ?? `插件 · ${row.source}`)),
|
|
2163
|
+
row.editable
|
|
2164
|
+
? h(React.Fragment, null,
|
|
2165
|
+
h('label', { className: 'dpt-check' },
|
|
2166
|
+
h('input', {
|
|
2167
|
+
type: 'checkbox', checked: modelChecked, disabled: status.busy,
|
|
2168
|
+
onChange: e => quickTogglePermission(e.target.checked, userChecked),
|
|
2169
|
+
}), '模型调用'),
|
|
2170
|
+
h('label', { className: 'dpt-check' },
|
|
2171
|
+
h('input', {
|
|
2172
|
+
type: 'checkbox', checked: userChecked, disabled: status.busy,
|
|
2173
|
+
onChange: e => quickTogglePermission(modelChecked, e.target.checked),
|
|
2174
|
+
}), '手动调用'))
|
|
2175
|
+
: h('span', null, '权限', h('strong', null, `模型${row.modelInvocable ? '可调用' : '停用'} · 手动${row.userInvocable ? '可调用' : '停用'}`))),
|
|
2176
|
+
h('div', { className: 'dpt-actions' },
|
|
2177
|
+
!preview && button('预览', () => openMode(false), { icon: 'eye', disabled: status.busy, 'aria-label': `预览 ${row.name}` }),
|
|
2178
|
+
!preview && row.editable && button('编辑', () => openMode(true), { icon: 'square-pen', disabled: status.busy }),
|
|
2179
|
+
row.editable && button('移除', () => run(async () => {
|
|
2180
|
+
const current = await load()
|
|
2181
|
+
setStartInEdit(false); setPreview(current); setRemoval(true)
|
|
2182
|
+
}), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
2183
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
2184
|
+
preview && h('div', { className: 'dpt-drawer-split' }, h(SkillPreview, {
|
|
2185
|
+
key: `${preview.revision ?? preview.name}:${startInEdit}`, preview, initialEditing: startInEdit,
|
|
2186
|
+
close: () => { setPreview(null); setStartInEdit(false) },
|
|
2187
|
+
update: async fields => {
|
|
2188
|
+
await request('skills', { ...scope, action: 'edit', ...fields, name: row.name, revision: preview.revision })
|
|
2189
|
+
setPreview(null); setStartInEdit(false); notify('Skill 已更新'); await refresh()
|
|
2190
|
+
},
|
|
2191
|
+
})),
|
|
2192
|
+
preview && removal && h(Confirm, {
|
|
2193
|
+
title: `移除 ${row.name}`, label: '移除 Skill',
|
|
2194
|
+
removed: [`DSH 扫描目录中的 ${row.name}`],
|
|
2195
|
+
preserved: ['恢复目录中的 SKILL.md 和随附文件', '导入来源中的原始文件以及其他 Skill'],
|
|
2196
|
+
close: () => setRemoval(false), confirm: async () => {
|
|
2197
|
+
const result = await request('skills', { ...scope, action: 'remove', name: row.name, revision: preview.revision, confirm: row.name })
|
|
2198
|
+
setRemoval(false); removed(result.recovery); await refresh()
|
|
2199
|
+
},
|
|
2200
|
+
}))
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
function RepositorySkill({ repository, skill, scope, destination, installed, onInstall }) {
|
|
2204
|
+
const [preview, setPreview] = useState('')
|
|
2205
|
+
const [status, run, dismiss] = useAction()
|
|
2206
|
+
const selection = { ...scope, repositoryId: repository.id, commit: repository.commit, skillId: skill.id }
|
|
2207
|
+
return h('li', { className: 'dpt-repo-skill' },
|
|
2208
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2209
|
+
h('div', { className: 'dpt-row-title' }, h('strong', { className: 'dpt-ellipsis' }, skill.name),
|
|
2210
|
+
installed && pill('已安装')),
|
|
2211
|
+
h('div', { className: 'dpt-actions' },
|
|
2212
|
+
button(preview ? '关闭预览' : '预览 Skill', () => preview ? setPreview('') : run(async () => {
|
|
2213
|
+
const result = await request('skills', { ...selection, action: 'repository-preview' })
|
|
2214
|
+
setPreview(result.markdown)
|
|
2215
|
+
}), { icon: preview ? 'x' : 'eye', disabled: status.busy, 'aria-label': preview ? '关闭预览' : `预览 Skill ${skill.name}` }),
|
|
2216
|
+
button('安装', () => run(async () => {
|
|
2217
|
+
const result = await request('skills', { ...selection, action: 'repository-install', destination })
|
|
2218
|
+
await onInstall(result.name)
|
|
2219
|
+
}), { icon: 'download', disabled: installed || status.busy, 'aria-busy': status.busy, 'aria-label': `安装 ${skill.name}` }))),
|
|
2220
|
+
muted(skill.description),
|
|
2221
|
+
preview && h('pre', { className: 'dpt-mono', dir: 'ltr' }, preview),
|
|
2222
|
+
feedback(status.error ? status.message : '', true, dismiss))
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
function RepositoryRow({ repository, scope, destination, installed, disclosure, query, installFilter = 'all', update, remove, onInstall, notify }) {
|
|
2226
|
+
const [removal, setRemoval] = useState(false)
|
|
2227
|
+
const [status, run, dismiss] = useAction()
|
|
2228
|
+
const skills = repository.skills.filter(skill => {
|
|
2229
|
+
const isInstalled = installed.has(skill.name)
|
|
2230
|
+
if (installFilter === 'available' && isInstalled) return false
|
|
2231
|
+
if (installFilter === 'installed' && !isInstalled) return false
|
|
2232
|
+
return matches(query, skill.name, skill.description)
|
|
2233
|
+
})
|
|
2234
|
+
const hasRepoFilter = Boolean(query.trim()) || installFilter !== 'all'
|
|
2235
|
+
const scroller = useInfiniteScroll(skills.length, `${query}\n${installFilter}`, 35)
|
|
2236
|
+
const visibleSkills = skills.slice(0, scroller.limit)
|
|
2237
|
+
return h(DisclosureRow, {
|
|
2238
|
+
title: repository.name,
|
|
2239
|
+
detail: hasRepoFilter
|
|
2240
|
+
? `匹配 ${skills.length} / ${repository.skills.length} 个 Skill`
|
|
2241
|
+
: `${repository.skills.length} 个可安装 Skill`,
|
|
2242
|
+
badge: '已同步', tone: 'ready', ...disclosure,
|
|
2243
|
+
},
|
|
2244
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2245
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
2246
|
+
h('span', null, '来源', h('a', { href: repository.url, target: '_blank', rel: 'noreferrer' }, 'GitHub ↗')),
|
|
2247
|
+
h('span', null, '同步时间', h('strong', null, new Date(repository.checkedAt).toLocaleString()))),
|
|
2248
|
+
h('div', { className: 'dpt-actions' },
|
|
2249
|
+
button('刷新仓库', () => run(async () => {
|
|
2250
|
+
const result = await request('skills', { action: 'repository-refresh', repositoryId: repository.id })
|
|
2251
|
+
update(result.repository)
|
|
2252
|
+
notify('仓库已同步更新')
|
|
2253
|
+
}), { icon: 'refresh-cw', disabled: status.busy, 'aria-busy': status.busy }),
|
|
2254
|
+
button('移除仓库', () => setRemoval(true), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
2255
|
+
h(PathLine, { value: repository.commit, label: '提交哈希' }),
|
|
2256
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
2257
|
+
skills.length ? h('ul', { className: `dpt-repo-skills${visibleSkills.length > 10 ? ' dpt-repo-scroll' : ''}`, 'aria-label': '仓库 Skill' },
|
|
2258
|
+
visibleSkills.map(skill => h(RepositorySkill, {
|
|
2259
|
+
key: `${repository.commit}:${skill.id}:${destination}`, repository,
|
|
2260
|
+
skill, scope, destination, installed: installed.has(skill.name), onInstall,
|
|
2261
|
+
})),
|
|
2262
|
+
scroller.sentinel) :
|
|
2263
|
+
muted(hasRepoFilter ? '仓库中没有符合筛选条件的 Skill。' : '仓库中未发现 Skill。'),
|
|
2264
|
+
removal && h(Confirm, {
|
|
2265
|
+
title: `移除仓库 ${repository.name}`, label: '确认移除仓库',
|
|
2266
|
+
removed: ['工具箱中的来源记录与下载缓存'], preserved: ['已安装的 Skill 和 GitHub 仓库'],
|
|
2267
|
+
close: () => setRemoval(false), confirm: async () => {
|
|
2268
|
+
await request('skills', { action: 'repository-remove', repositoryId: repository.id, confirm: repository.id })
|
|
2269
|
+
remove(repository.id)
|
|
2270
|
+
},
|
|
2271
|
+
}))
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
function SkillRepositoryPanel({ scope, installedRows, onInstall, onRemove, notify }) {
|
|
2275
|
+
const [repositories, setRepositories] = useState(null)
|
|
2276
|
+
const [url, setUrl] = useState('')
|
|
2277
|
+
const [query, search] = useState('')
|
|
2278
|
+
const [installFilter, setInstallFilter] = useState('all')
|
|
2279
|
+
const [destination, setDestination] = useState(scope.workspaceId ? 'project' : 'personal')
|
|
2280
|
+
const [status, run, dismiss] = useAction()
|
|
2281
|
+
const [failure, setFailure] = useState('')
|
|
2282
|
+
const [added, setAdded] = useState(null)
|
|
2283
|
+
const disclosure = useDisclosure()
|
|
2284
|
+
useEffect(() => {
|
|
2285
|
+
const abort = new AbortController()
|
|
2286
|
+
request('skills', { action: 'repository-list' }, abort.signal).then(
|
|
2287
|
+
value => { if (!abort.signal.aborted) setRepositories(value.repositories) },
|
|
2288
|
+
error => { if (!abort.signal.aborted) setFailure(error.message) },
|
|
2289
|
+
)
|
|
2290
|
+
return () => abort.abort()
|
|
2291
|
+
}, [])
|
|
2292
|
+
const installed = new Set(installedRows?.map(skill => skill.name))
|
|
2293
|
+
const hasRepoFilter = Boolean(query.trim()) || installFilter !== 'all'
|
|
2294
|
+
async function add() {
|
|
2295
|
+
const { repository } = await request('skills', { action: 'repository-add', url: url.trim() })
|
|
2296
|
+
setRepositories(previous => [...(previous ?? []), repository])
|
|
2297
|
+
setAdded(repository.id); setUrl(''); setFailure('')
|
|
2298
|
+
notify(`已添加仓库 ${repository.name}`)
|
|
2299
|
+
}
|
|
2300
|
+
return h(PanelSection, { title: 'Skill 仓库', summary: repositories && `${repositories.length} 个仓库` },
|
|
2301
|
+
h('div', { className: 'dpt-card dpt-empty dpt-edit' },
|
|
2302
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(add) } },
|
|
2303
|
+
field('GitHub 仓库地址', h('input', {
|
|
2304
|
+
type: 'url', value: url, dir: 'ltr', className: 'dpt-mono',
|
|
2305
|
+
placeholder: 'https://github.com/owner/repo', required: true, onChange: e => setUrl(e.target.value),
|
|
2306
|
+
})),
|
|
2307
|
+
h('div', { className: 'dpt-actions' },
|
|
2308
|
+
button('添加仓库', undefined, { type: 'submit', icon: 'plus', disabled: status.busy, 'aria-busy': status.busy }))),
|
|
2309
|
+
feedback(failure, true, () => setFailure('')), feedback(status.error ? status.message : '', true, dismiss)),
|
|
2310
|
+
repositories?.length > 0 && h(React.Fragment, null,
|
|
2311
|
+
h('div', { className: 'dpt-bar' }, filterInput('搜索仓库 Skill', query, search),
|
|
2312
|
+
pick('仓库安装状态', installFilter, setInstallFilter, [
|
|
2313
|
+
option('all', '全部状态'),
|
|
2314
|
+
option('available', '仅未安装'),
|
|
2315
|
+
option('installed', '已安装'),
|
|
2316
|
+
]),
|
|
2317
|
+
pick('仓库 Skill 安装位置', destination, setDestination, [scope.workspaceId && option('project', '当前项目'), option('personal', '个人 DSH')].filter(Boolean)),
|
|
2318
|
+
hasRepoFilter && button('重置筛选', () => { search(''); setInstallFilter('all') }, { icon: 'x', iconSize: 13 })),
|
|
2319
|
+
h('ul', { className: 'dpt-card' }, repositories.map(repository => h(RepositoryRow, {
|
|
2320
|
+
key: repository.id,
|
|
2321
|
+
repository, query, installFilter, scope, destination, installed, notify,
|
|
2322
|
+
disclosure: disclosure(repository.id, added === repository.id),
|
|
2323
|
+
update: refreshed => setRepositories(previous => previous.map(item => item.id === refreshed.id ? refreshed : item)),
|
|
2324
|
+
remove: id => {
|
|
2325
|
+
setRepositories(previous => previous.filter(item => item.id !== id))
|
|
2326
|
+
onRemove()
|
|
2327
|
+
},
|
|
2328
|
+
onInstall,
|
|
2329
|
+
})))),
|
|
2330
|
+
(!repositories || !repositories.length) && empty(repositories ? '尚未添加 Skill 仓库。' : failure ? '仓库列表暂不可用。' : '正在读取 Skill 仓库…'))
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
function InstructionRow({ row, workspaceId, disclosure, refresh, notify }) {
|
|
2334
|
+
const [preview, setPreview] = useState(null)
|
|
2335
|
+
const [editing, setEditing] = useState(false)
|
|
2336
|
+
const [content, setContent] = useState('')
|
|
2337
|
+
const [removal, setRemoval] = useState(false)
|
|
2338
|
+
const [status, run, dismiss] = useAction()
|
|
2339
|
+
|
|
2340
|
+
async function openMode(startEditing) {
|
|
2341
|
+
await run(async () => {
|
|
2342
|
+
const data = await request('instructions', { action: 'preview', workspaceId, id: row.id })
|
|
2343
|
+
setPreview(data)
|
|
2344
|
+
setContent(data.content ?? '')
|
|
2345
|
+
setEditing(startEditing)
|
|
2346
|
+
disclosure.open()
|
|
2347
|
+
})
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
const detailParts = [
|
|
2351
|
+
row.scopeLabel,
|
|
2352
|
+
row.exists ? formatBytes(row.bytes) : '尚未创建,可一键新建',
|
|
2353
|
+
row.exists && row.mtimeMs > 0 ? formatShortTime(row.mtimeMs) : '',
|
|
2354
|
+
].filter(Boolean)
|
|
2355
|
+
|
|
2356
|
+
const badge = !row.exists ? '未创建' : row.symlink ? '符号链接' : row.editable ? '已生效' : '只读'
|
|
2357
|
+
const tone = !row.exists ? 'idle' : row.editable ? 'ready' : 'idle'
|
|
2358
|
+
|
|
2359
|
+
const quickActions = h(React.Fragment, null,
|
|
2360
|
+
row.exists && !row.symlink && iconButton(`预览 ${row.displayPath}`, 'eye', () => openMode(false), {
|
|
2361
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: '预览内容', disabled: status.busy,
|
|
2362
|
+
}),
|
|
2363
|
+
row.editable && iconButton(`${row.exists ? '编辑' : '创建'} ${row.displayPath}`, row.exists ? 'square-pen' : 'plus', () => openMode(true), {
|
|
2364
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: row.exists ? '编辑指令文件' : '创建指令文件', disabled: status.busy,
|
|
2365
|
+
}))
|
|
2366
|
+
|
|
2367
|
+
return h(DisclosureRow, {
|
|
2368
|
+
'data-instruction-id': row.id,
|
|
2369
|
+
title: row.displayPath,
|
|
2370
|
+
tag: row.localOverlay ? '本地覆盖' : undefined,
|
|
2371
|
+
detail: detailParts.join(' · '),
|
|
2372
|
+
badge,
|
|
2373
|
+
tone,
|
|
2374
|
+
quickActions,
|
|
2375
|
+
...disclosure,
|
|
2376
|
+
},
|
|
2377
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2378
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
2379
|
+
h('span', null, '作用域', h('strong', null, row.scopeLabel)),
|
|
2380
|
+
row.exists && h('span', null, '大小', h('strong', null, formatBytes(row.bytes)))),
|
|
2381
|
+
h('div', { className: 'dpt-actions' },
|
|
2382
|
+
row.exists && !row.symlink && !preview && button('预览', () => openMode(false), { icon: 'eye', disabled: status.busy }),
|
|
2383
|
+
row.editable && !editing && button(row.exists ? '编辑' : '创建', () => openMode(true), { icon: row.exists ? 'square-pen' : 'plus', disabled: status.busy }),
|
|
2384
|
+
row.exists && row.editable && button('移除', () => run(async () => {
|
|
2385
|
+
const current = await request('instructions', { action: 'preview', workspaceId, id: row.id })
|
|
2386
|
+
setPreview(current); setEditing(false); setRemoval(true)
|
|
2387
|
+
}), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
2388
|
+
h(PathLine, { value: row.path, label: '文件路径' }),
|
|
2389
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
2390
|
+
preview && h('div', { className: 'dpt-drawer-split' }, editing
|
|
2391
|
+
? h('form', {
|
|
2392
|
+
className: 'dpt-form',
|
|
2393
|
+
onSubmit: e => {
|
|
2394
|
+
e.preventDefault()
|
|
2395
|
+
void run(async () => {
|
|
2396
|
+
await request('instructions', { action: 'save', workspaceId, id: row.id, revision: preview.revision, content })
|
|
2397
|
+
setPreview(null); setEditing(false)
|
|
2398
|
+
notify(`${row.displayPath} 已保存`)
|
|
2399
|
+
await refresh()
|
|
2400
|
+
})
|
|
2401
|
+
},
|
|
2402
|
+
},
|
|
2403
|
+
field(`${row.displayPath} 内容`, h('textarea', {
|
|
2404
|
+
rows: 11, className: 'dpt-mono dpt-fixed-editor', value: content,
|
|
2405
|
+
onChange: e => setContent(e.target.value),
|
|
2406
|
+
})),
|
|
2407
|
+
h('div', { className: 'dpt-actions' },
|
|
2408
|
+
button('取消', () => { setEditing(false); if (!row.exists) setPreview(null); dismiss() }, { disabled: status.busy }),
|
|
2409
|
+
primary(row.exists ? '保存修改' : '创建文件', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy })))
|
|
2410
|
+
: h(React.Fragment, null,
|
|
2411
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2412
|
+
muted(`${row.displayPath} · ${formatBytes(preview.bytes)}`),
|
|
2413
|
+
h('div', { className: 'dpt-actions' },
|
|
2414
|
+
row.editable && button('编辑', () => setEditing(true), { icon: 'square-pen' }),
|
|
2415
|
+
button('关闭预览', () => setPreview(null), { icon: 'x', iconSize: 13 }))),
|
|
2416
|
+
h('pre', { className: 'dpt-mono', dir: 'ltr' }, preview.content || '(空文件)'))),
|
|
2417
|
+
preview && removal && h(Confirm, {
|
|
2418
|
+
title: `移除 ${row.displayPath}`,
|
|
2419
|
+
label: '确认移除',
|
|
2420
|
+
removed: [`指令文件 ${row.displayPath}`],
|
|
2421
|
+
preserved: ['Profile 恢复目录中的原始文件备份', '其他工作区与全局指令文件'],
|
|
2422
|
+
close: () => setRemoval(false),
|
|
2423
|
+
confirm: async () => {
|
|
2424
|
+
const result = await request('instructions', { action: 'remove', workspaceId, id: row.id, revision: preview.revision, confirm: row.id })
|
|
2425
|
+
setRemoval(false); setPreview(null)
|
|
2426
|
+
notify(h(React.Fragment, null,
|
|
2427
|
+
h('p', null, `已移除 ${row.displayPath} 至恢复目录`),
|
|
2428
|
+
h(PathLine, { value: result.recovery, label: '恢复目录' })), { sticky: true })
|
|
2429
|
+
await refresh()
|
|
2430
|
+
},
|
|
2431
|
+
}))
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
function InstructionsPanel({ workspaceId, notify }) {
|
|
2435
|
+
const [rows, setRows] = useState(null)
|
|
2436
|
+
const [error, setError] = useState('')
|
|
2437
|
+
const disclosure = useDisclosure()
|
|
2438
|
+
const generation = useRef(0)
|
|
2439
|
+
|
|
2440
|
+
async function refresh(signal) {
|
|
2441
|
+
const current = ++generation.current
|
|
2442
|
+
try {
|
|
2443
|
+
const result = await request('instructions', { action: 'list', workspaceId }, signal)
|
|
2444
|
+
if (current === generation.current && !signal?.aborted) { setRows(result.instructions); setError('') }
|
|
2445
|
+
} catch (err) {
|
|
2446
|
+
if (current === generation.current && !signal?.aborted) setError(err.message)
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
useEffect(() => {
|
|
2451
|
+
const abort = new AbortController()
|
|
2452
|
+
setRows(null); setError('')
|
|
2453
|
+
void refresh(abort.signal)
|
|
2454
|
+
return () => { generation.current++; abort.abort() }
|
|
2455
|
+
}, [workspaceId])
|
|
2456
|
+
|
|
2457
|
+
const activeRows = (rows ?? []).filter(item => item.exists)
|
|
2458
|
+
const totalBytes = activeRows.reduce((sum, item) => sum + (item.bytes ?? 0), 0)
|
|
2459
|
+
|
|
2460
|
+
return h(PanelSection, {
|
|
2461
|
+
title: '指令文件',
|
|
2462
|
+
summary: rows ? `${activeRows.length} 个已生效${totalBytes > 0 ? ` · 共 ${formatBytes(totalBytes)}` : ''}` : undefined,
|
|
2463
|
+
},
|
|
2464
|
+
feedback(error, true, () => setError('')),
|
|
2465
|
+
rows?.length > 0
|
|
2466
|
+
? h('ul', { className: 'dpt-card' }, rows.map(row => h(InstructionRow, {
|
|
2467
|
+
key: `${workspaceId}:${row.id}`, row, workspaceId, notify,
|
|
2468
|
+
disclosure: disclosure(row.id),
|
|
2469
|
+
refresh: () => refresh(),
|
|
2470
|
+
})))
|
|
2471
|
+
: empty(rows ? '当前作用域没有可管理的指令文件。' : error ? '指令文件暂不可用。' : '正在扫描指令文件…'))
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
function SkillsPanel({ workspaceList, sessionList, navigation, host, toast }) {
|
|
2475
|
+
const main = Object.values(sessionList.byId).find(item => item.retainedBy?.mainView > 0)
|
|
2476
|
+
const current = workspaceList.items.find(item => item.sessionIds.includes(main?.id) || item.path === main?.cwd)
|
|
2477
|
+
const [override, setWorkspace] = useState(null)
|
|
2478
|
+
const workspace = override ?? current?.workspaceId ?? ''
|
|
2479
|
+
const [query, search] = useState('')
|
|
2480
|
+
const [sourceFilter, setSourceFilter] = useState('all')
|
|
2481
|
+
const [permFilter, setPermFilter] = useState('all')
|
|
2482
|
+
const [rows, setRows] = useState(null)
|
|
2483
|
+
const [error, setError] = useState('')
|
|
2484
|
+
const [reloading, setReloading] = useState(false)
|
|
2485
|
+
const [importing, setImporting] = useState(false)
|
|
2486
|
+
const [library, setLibrary] = useState(false)
|
|
2487
|
+
const [instructionsOpen, setInstructionsOpen] = useState(false)
|
|
2488
|
+
const disclosure = useDisclosure()
|
|
2489
|
+
const scope = { workspaceId: workspace, sessionId: main?.id }
|
|
2490
|
+
const generation = useRef(0)
|
|
2491
|
+
async function refresh(signal, manual = false) {
|
|
2492
|
+
const currentGen = ++generation.current
|
|
2493
|
+
if (manual) setReloading(true)
|
|
2494
|
+
try {
|
|
2495
|
+
const { skills } = await request('skills', { ...scope, action: 'list' }, signal)
|
|
2496
|
+
if (generation.current === currentGen && !signal?.aborted) { setRows(skills); setError('') }
|
|
2497
|
+
} catch (error) {
|
|
2498
|
+
if (generation.current === currentGen && !signal?.aborted) setError(error.message)
|
|
2499
|
+
} finally {
|
|
2500
|
+
if (manual && generation.current === currentGen) setReloading(false)
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
useEffect(() => {
|
|
2504
|
+
const abort = new AbortController()
|
|
2505
|
+
setRows(null)
|
|
2506
|
+
setImporting(false)
|
|
2507
|
+
setError('')
|
|
2508
|
+
void refresh(abort.signal)
|
|
2509
|
+
return () => { generation.current++; abort.abort() }
|
|
2510
|
+
}, [workspace, main?.id])
|
|
2511
|
+
|
|
2512
|
+
const allRows = rows ?? []
|
|
2513
|
+
const editableCount = allRows.filter(row => row.editable).length
|
|
2514
|
+
const projectCount = allRows.filter(row => row.source?.startsWith('project-')).length
|
|
2515
|
+
const personalCount = allRows.filter(row => row.source?.startsWith('user-')).length
|
|
2516
|
+
const builtinPluginCount = allRows.filter(row => row.source === 'bundled' || row.source === 'runtime' || row.source === 'custom').length
|
|
2517
|
+
|
|
2518
|
+
const shown = allRows.filter(row => {
|
|
2519
|
+
if (sourceFilter === 'editable' && !row.editable) return false
|
|
2520
|
+
if (sourceFilter === 'project' && !row.source?.startsWith('project-')) return false
|
|
2521
|
+
if (sourceFilter === 'personal' && !row.source?.startsWith('user-')) return false
|
|
2522
|
+
if (sourceFilter === 'readonly' && !(row.source === 'bundled' || row.source === 'runtime' || row.source === 'custom')) return false
|
|
2523
|
+
if (permFilter === 'model' && !row.modelInvocable) return false
|
|
2524
|
+
if (permFilter === 'user' && !row.userInvocable) return false
|
|
2525
|
+
if (permFilter === 'restricted' && row.modelInvocable && row.userInvocable) return false
|
|
2526
|
+
return matches(query, row.name, row.description, skillSources[row.source] ?? '')
|
|
2527
|
+
}).sort((a, b) => (skillSourceOrder[a.source] ?? 6) - (skillSourceOrder[b.source] ?? 6))
|
|
2528
|
+
|
|
2529
|
+
const hasActiveFilter = Boolean(query.trim()) || sourceFilter !== 'all' || permFilter !== 'all'
|
|
2530
|
+
const resetFilters = () => { search(''); setSourceFilter('all'); setPermFilter('all') }
|
|
2531
|
+
const scroller = useInfiniteScroll(shown.length, `${workspace}\n${query}\n${sourceFilter}\n${permFilter}`, 50)
|
|
2532
|
+
const visibleRows = shown.slice(0, scroller.limit)
|
|
2533
|
+
const openKeys = visibleRows.filter(row => disclosure.isOpen(row.name)).map(row => row.name)
|
|
2534
|
+
|
|
2535
|
+
const groups = new Map()
|
|
2536
|
+
for (const row of visibleRows) {
|
|
2537
|
+
const title = skillSources[row.source] ?? '插件'
|
|
2538
|
+
if (!groups.has(title)) groups.set(title, [])
|
|
2539
|
+
groups.get(title).push(row)
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
return h('div', { className: 'dpt-panel' },
|
|
2543
|
+
feedback(host.error || (host.info?.skills === false ? '当前 DSH 配置未加载 Skill 服务。' : ''), true, host.dismiss),
|
|
2544
|
+
feedback(error, true, () => setError('')),
|
|
2545
|
+
h('div', { className: 'dpt-toolbar' },
|
|
2546
|
+
h(Segmented, {
|
|
2547
|
+
label: 'Skill 来源筛选', value: sourceFilter, onChange: setSourceFilter,
|
|
2548
|
+
items: [
|
|
2549
|
+
{ value: 'all', label: '全部', count: rows ? allRows.length : null },
|
|
2550
|
+
{ value: 'editable', label: '可编辑', count: rows ? editableCount : null },
|
|
2551
|
+
...(projectCount > 0 ? [{ value: 'project', label: '项目', count: projectCount }] : []),
|
|
2552
|
+
...(personalCount > 0 ? [{ value: 'personal', label: '个人', count: personalCount }] : []),
|
|
2553
|
+
{ value: 'readonly', label: '只读', count: rows ? builtinPluginCount : null },
|
|
2554
|
+
],
|
|
2555
|
+
}),
|
|
2556
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
2557
|
+
filterInput('搜索 Skill', query, search),
|
|
2558
|
+
pick('调用权限', permFilter, setPermFilter, [
|
|
2559
|
+
option('all', '全部权限'),
|
|
2560
|
+
option('model', '模型可调用'),
|
|
2561
|
+
option('user', '手动可调用'),
|
|
2562
|
+
option('restricted', '含停用限制'),
|
|
2563
|
+
]),
|
|
2564
|
+
pick('Skill 工作区', workspace, setWorkspace, [
|
|
2565
|
+
option('', '个人与全局'),
|
|
2566
|
+
...workspaceList.items.map(item => option(item.workspaceId, workspaceTitle(item))),
|
|
2567
|
+
]),
|
|
2568
|
+
hasActiveFilter && shown.length > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
2569
|
+
openKeys.length >= 2 && button('收起全部', () => disclosure.collapseAll(openKeys), { icon: 'chevrons-down-up', iconSize: 13 }),
|
|
2570
|
+
iconButton('刷新 Skill', 'refresh-cw', () => refresh(undefined, true), { iconClass: reloading ? 'dpt-spin' : '', disabled: reloading, 'aria-busy': reloading }),
|
|
2571
|
+
host.info?.instructions !== false && button('指令文件', () => setInstructionsOpen(!instructionsOpen), { icon: 'file-text', 'aria-expanded': instructionsOpen }),
|
|
2572
|
+
button('仓库管理', () => setLibrary(!library), { icon: 'git-branch', 'aria-expanded': library }),
|
|
2573
|
+
primary('导入 Skill', () => setImporting(true), { icon: 'folder-plus', disabled: !rows || importing }))),
|
|
2574
|
+
instructionsOpen && h(InstructionsPanel, { key: workspace, workspaceId: workspace, notify: toast.show }),
|
|
2575
|
+
library && h(SkillRepositoryPanel, {
|
|
2576
|
+
key: workspace, scope, installedRows: rows, notify: toast.show,
|
|
2577
|
+
onInstall: async name => { toast.show(`已从仓库安装 ${name}`); await refresh() },
|
|
2578
|
+
onRemove: () => toast.show('仓库已移除,已安装的 Skill 已保留'),
|
|
2579
|
+
}),
|
|
2580
|
+
importing && h('div', { className: 'dpt-card dpt-empty' }, h(SkillImport, {
|
|
2581
|
+
workspace, navigation, close: () => setImporting(false), save: async payload => {
|
|
2582
|
+
const result = await request('skills', { ...scope, action: 'import', ...payload })
|
|
2583
|
+
setImporting(false); toast.show(`已导入 ${result.name}`); await refresh()
|
|
2584
|
+
},
|
|
2585
|
+
})),
|
|
2586
|
+
shown.length ? h('ul', { className: 'dpt-card' }, [...groups].map(([title, group]) =>
|
|
2587
|
+
h(React.Fragment, { key: title }, groups.size > 1 && h('li', { className: 'dpt-subhead' }, title),
|
|
2588
|
+
group.map(row => h(SkillRow, {
|
|
2589
|
+
key: `${workspace}:${main?.id}:${row.name}`, row, scope, notify: toast.show,
|
|
2590
|
+
refresh: () => refresh(),
|
|
2591
|
+
disclosure: disclosure(row.name),
|
|
2592
|
+
removed: value => toast.show(h(React.Fragment, null,
|
|
2593
|
+
h('p', null, `已移除 ${row.name} 至恢复目录`),
|
|
2594
|
+
h(PathLine, { value, label: '恢复目录' })), { sticky: true }),
|
|
2595
|
+
})))), scroller.sentinel)
|
|
2596
|
+
: empty(rows ? '没有符合条件的 Skill。' : error ? 'Skill 列表暂不可用。' : '正在发现 Skill…', rows && hasActiveFilter ? resetFilters : undefined))
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
const jobStates = { running: '运行中', stopping: '停止中', completed: '已完成', killed: '已停止', failed: '已失败' }
|
|
2600
|
+
const scheduleStates = { active: '活跃', paused: '已暂停', ended: '已结束' }
|
|
2601
|
+
const weekdayNames = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
|
2602
|
+
|
|
2603
|
+
function formatDurationSeconds(seconds) {
|
|
2604
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return ''
|
|
2605
|
+
if (seconds % 3600 === 0) return `${seconds / 3600} 小时`
|
|
2606
|
+
if (seconds % 60 === 0) return `${seconds / 60} 分钟`
|
|
2607
|
+
return `${seconds} 秒`
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
function scheduleRuleLabel(item) {
|
|
2611
|
+
if (item.kind === 'after') return item.afterSeconds ? `${formatDurationSeconds(item.afterSeconds)}后单次` : '延时单次'
|
|
2612
|
+
if (item.kind === 'at') return '定时单次'
|
|
2613
|
+
if (item.kind === 'every') return item.everySeconds ? `每 ${formatDurationSeconds(item.everySeconds)}` : '循环间隔'
|
|
2614
|
+
if (item.kind === 'daily') return `每天 ${item.time ?? ''}`.trim()
|
|
2615
|
+
if (item.kind === 'weekly') {
|
|
2616
|
+
const days = (item.weekdays ?? []).map(day => weekdayNames[day] ?? day).join('、')
|
|
2617
|
+
return `每周 ${days} ${item.time ?? ''}`.trim()
|
|
2618
|
+
}
|
|
2619
|
+
if (item.kind === 'cron') return `Cron ${item.expression ?? ''}`.trim()
|
|
2620
|
+
if (item.kind === 'rrule') return `RRule`
|
|
2621
|
+
return item.kind
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
function formatIsoShort(iso) {
|
|
2625
|
+
if (!iso) return ''
|
|
2626
|
+
const ts = Date.parse(iso)
|
|
2627
|
+
return Number.isFinite(ts) ? formatShortTime(ts) : iso
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
function useTasksData(host) {
|
|
2631
|
+
const [jobs, setJobs] = useState(null)
|
|
2632
|
+
const [schedules, setSchedules] = useState(null)
|
|
2633
|
+
const [error, setError] = useState('')
|
|
2634
|
+
const [reloading, setReloading] = useState(false)
|
|
2635
|
+
const generation = useRef(0)
|
|
2636
|
+
|
|
2637
|
+
async function refresh(signal, manual = false) {
|
|
2638
|
+
const current = ++generation.current
|
|
2639
|
+
if (manual) setReloading(true)
|
|
2640
|
+
const errs = []
|
|
2641
|
+
const jobsPromise = host.info?.jobs === false
|
|
2642
|
+
? Promise.resolve(null)
|
|
2643
|
+
: request('jobs', { action: 'list' }, signal).then(res => res.jobs, err => { if (!signal?.aborted) errs.push(err.message); return null })
|
|
2644
|
+
const schedulePromise = host.info?.schedule === false
|
|
2645
|
+
? Promise.resolve(null)
|
|
2646
|
+
: request('schedule', { action: 'list' }, signal).then(res => res.schedules, err => { if (!signal?.aborted) errs.push(err.message); return null })
|
|
2647
|
+
try {
|
|
2648
|
+
const [nextJobs, nextSchedules] = await Promise.all([jobsPromise, schedulePromise])
|
|
2649
|
+
if (current === generation.current && !signal?.aborted) {
|
|
2650
|
+
if (nextJobs !== null) setJobs(nextJobs)
|
|
2651
|
+
if (nextSchedules !== null) setSchedules(nextSchedules)
|
|
2652
|
+
setError(errs.join(';'))
|
|
2653
|
+
}
|
|
2654
|
+
} finally {
|
|
2655
|
+
if (manual && current === generation.current) setReloading(false)
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
useEffect(() => {
|
|
2660
|
+
const abort = new AbortController()
|
|
2661
|
+
void refresh(abort.signal)
|
|
2662
|
+
const timer = setInterval(() => refresh(abort.signal), 2500)
|
|
2663
|
+
return () => { clearInterval(timer); abort.abort(); generation.current++ }
|
|
2664
|
+
}, [host.info?.jobs, host.info?.schedule])
|
|
2665
|
+
|
|
2666
|
+
return { jobs, schedules, error, reloading, refresh: () => refresh(undefined, true), dismissError: () => setError('') }
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
function JobRow({ job, sessionTitle, navigation, disclosure, refresh, notify }) {
|
|
2670
|
+
const [output, setOutput] = useState(null)
|
|
2671
|
+
const [killing, setKilling] = useState(false)
|
|
2672
|
+
const [status, run, dismiss] = useAction()
|
|
2673
|
+
const live = job.status === 'running' || job.status === 'stopping'
|
|
2674
|
+
const tone = job.status === 'running' ? 'info' : job.status === 'completed' ? 'ready' : job.status === 'stopping' || job.status === 'failed' ? 'attention' : 'idle'
|
|
2675
|
+
|
|
2676
|
+
const detailParts = [
|
|
2677
|
+
job.owner ? `会话 ${sessionTitle || job.owner}` : '全局任务',
|
|
2678
|
+
job.progress || job.detail || '',
|
|
2679
|
+
job.output?.total > 0 ? `输出 ${formatBytes(job.output.total)}` : '',
|
|
2680
|
+
job.startedAt > 0 ? formatShortTime(job.startedAt) : '',
|
|
2681
|
+
].filter(Boolean)
|
|
2682
|
+
|
|
2683
|
+
async function loadOutput() {
|
|
2684
|
+
await run(async () => {
|
|
2685
|
+
const result = await request('jobs', { action: 'output', id: job.id })
|
|
2686
|
+
setOutput(result)
|
|
2687
|
+
disclosure.open()
|
|
2688
|
+
})
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
const quickActions = h(React.Fragment, null,
|
|
2692
|
+
job.owner && iconButton(`打开所属会话 ${job.label}`, 'external-link', () => run(() => navigation.openSession(job.owner)), {
|
|
2693
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: '打开所属会话', disabled: status.busy,
|
|
2694
|
+
}),
|
|
2695
|
+
live
|
|
2696
|
+
? iconButton(`停止任务 ${job.label}`, 'square', () => setKilling(true), {
|
|
2697
|
+
className: 'dpt-row-icon-btn dpt-danger', iconSize: 13, title: '停止后台任务', disabled: status.busy,
|
|
2698
|
+
})
|
|
2699
|
+
: iconButton(`清除记录 ${job.label}`, 'trash', () => run(async () => {
|
|
2700
|
+
await request('jobs', { action: 'remove', id: job.id })
|
|
2701
|
+
notify('已清除后台任务记录')
|
|
2702
|
+
await refresh()
|
|
2703
|
+
}), {
|
|
2704
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: '清除已结束记录', disabled: status.busy,
|
|
2705
|
+
}))
|
|
2706
|
+
|
|
2707
|
+
return h(DisclosureRow, {
|
|
2708
|
+
'data-job-id': job.id,
|
|
2709
|
+
title: job.label,
|
|
2710
|
+
tag: job.kind,
|
|
2711
|
+
detail: detailParts.join(' · '),
|
|
2712
|
+
badge: jobStates[job.status] ?? job.status,
|
|
2713
|
+
tone,
|
|
2714
|
+
quickActions,
|
|
2715
|
+
...disclosure,
|
|
2716
|
+
},
|
|
2717
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2718
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
2719
|
+
h('span', null, '任务 ID', code(job.id)),
|
|
2720
|
+
job.owner && h('span', null, '所属会话', code(job.owner)),
|
|
2721
|
+
job.startedAt > 0 && h('span', null, '启动', h('strong', null, new Date(job.startedAt).toLocaleString())),
|
|
2722
|
+
job.finishedAt > 0 && h('span', null, '结束', h('strong', null, new Date(job.finishedAt).toLocaleString())),
|
|
2723
|
+
Number.isInteger(job.exitCode) && h('span', null, '退出码', code(String(job.exitCode)))),
|
|
2724
|
+
h('div', { className: 'dpt-actions' },
|
|
2725
|
+
job.owner && button('打开会话', () => run(() => navigation.openSession(job.owner)), { icon: 'external-link', disabled: status.busy }),
|
|
2726
|
+
button(output ? '刷新输出' : '查看输出', loadOutput, { icon: 'terminal', disabled: status.busy }),
|
|
2727
|
+
live
|
|
2728
|
+
? button('停止任务', () => setKilling(true), { icon: 'square', className: 'dpt-danger', disabled: status.busy })
|
|
2729
|
+
: button('清除记录', () => run(async () => {
|
|
2730
|
+
await request('jobs', { action: 'remove', id: job.id })
|
|
2731
|
+
notify('已清除后台任务记录')
|
|
2732
|
+
await refresh()
|
|
2733
|
+
}), { icon: 'trash', disabled: status.busy }))),
|
|
2734
|
+
job.detail && muted(`详情:${job.detail}`),
|
|
2735
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
2736
|
+
output && h('div', { className: 'dpt-drawer-split' },
|
|
2737
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2738
|
+
muted(`最近输出${output.truncated ? '(仅展示末尾 16 KiB)' : ''} · 总计 ${formatBytes(output.total)}`),
|
|
2739
|
+
button('关闭输出', () => setOutput(null), { icon: 'x', iconSize: 13 })),
|
|
2740
|
+
h('pre', { className: 'dpt-mono', dir: 'ltr' }, output.text || '(暂无输出)')),
|
|
2741
|
+
killing && h(Confirm, {
|
|
2742
|
+
title: `停止任务 ${job.label}`,
|
|
2743
|
+
label: '确认停止任务',
|
|
2744
|
+
removed: [`正在运行的后台任务「${job.label}」(${job.id})`],
|
|
2745
|
+
preserved: ['所属会话的历史记录与工作区文件'],
|
|
2746
|
+
close: () => setKilling(false),
|
|
2747
|
+
confirm: async () => {
|
|
2748
|
+
const result = await request('jobs', { action: 'kill', id: job.id, confirm: job.id })
|
|
2749
|
+
setKilling(false)
|
|
2750
|
+
notify(result.outcome === 'already-finished' ? '任务已自行结束' : '已请求停止任务')
|
|
2751
|
+
await refresh()
|
|
2752
|
+
},
|
|
2753
|
+
}))
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
function ScheduleRow({ item, sessionTitle, navigation, disclosure, refresh, notify }) {
|
|
2757
|
+
const [history, setHistory] = useState(null)
|
|
2758
|
+
const [removal, setRemoval] = useState(false)
|
|
2759
|
+
const [optimisticActive, setOptimisticActive] = useState(null)
|
|
2760
|
+
const [status, run, dismiss] = useAction()
|
|
2761
|
+
useEffect(() => { setOptimisticActive(null) }, [item.status, item.updatedAt])
|
|
2762
|
+
|
|
2763
|
+
const isEnded = item.status === 'ended'
|
|
2764
|
+
const effectiveActive = optimisticActive ?? (item.status === 'active')
|
|
2765
|
+
const targetSessionId = item.target?.sessionId || item.lastDelivery?.targetSessionId || item.involvedSessionIds?.[0] || null
|
|
2766
|
+
const tone = item.executionActive ? 'info' : effectiveActive ? 'ready' : item.status === 'paused' ? 'attention' : 'idle'
|
|
2767
|
+
const badge = item.executionActive ? '执行中' : scheduleStates[effectiveActive ? 'active' : isEnded ? 'ended' : 'paused'] ?? item.status
|
|
2768
|
+
|
|
2769
|
+
const detailParts = [
|
|
2770
|
+
item.target?.kind === 'new' ? '每次新建会话' : item.target?.kind === 'new_once' ? '首次新建会话' : (targetSessionId ? `会话 ${sessionTitle || targetSessionId}` : '目标会话'),
|
|
2771
|
+
!isEnded && item.scheduledAt ? `下次 ${formatIsoShort(item.scheduledAt)}` : '',
|
|
2772
|
+
item.lastDelivery?.deliveredAt ? `上次 ${formatIsoShort(item.lastDelivery.deliveredAt)}` : '',
|
|
2773
|
+
].filter(Boolean)
|
|
2774
|
+
|
|
2775
|
+
function toggleActive(nextActive) {
|
|
2776
|
+
if (isEnded) return
|
|
2777
|
+
setOptimisticActive(nextActive)
|
|
2778
|
+
void run(async () => {
|
|
2779
|
+
try {
|
|
2780
|
+
await request('schedule', { action: 'toggle', id: item.id, active: nextActive, expectedUpdatedAt: item.updatedAt })
|
|
2781
|
+
notify(`${item.title} ${nextActive ? '已恢复调度' : '已暂停'}`)
|
|
2782
|
+
await refresh()
|
|
2783
|
+
} catch (err) {
|
|
2784
|
+
setOptimisticActive(null)
|
|
2785
|
+
throw err
|
|
2786
|
+
}
|
|
2787
|
+
})
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
async function runNow() {
|
|
2791
|
+
await run(async () => {
|
|
2792
|
+
await request('schedule', { action: 'run', id: item.id })
|
|
2793
|
+
notify(`已触发定时任务:${item.title}`)
|
|
2794
|
+
await refresh()
|
|
2795
|
+
})
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
async function loadHistory() {
|
|
2799
|
+
await run(async () => {
|
|
2800
|
+
const result = await request('schedule', { action: 'history', id: item.id })
|
|
2801
|
+
setHistory(result)
|
|
2802
|
+
disclosure.open()
|
|
2803
|
+
})
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
const quickActions = h(React.Fragment, null,
|
|
2807
|
+
!isEnded && iconButton(`立即运行 ${item.title}`, 'play', runNow, {
|
|
2808
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: '立即触发一次', disabled: status.busy || item.executionActive,
|
|
2809
|
+
}),
|
|
2810
|
+
targetSessionId && iconButton(`打开目标会话 ${item.title}`, 'external-link', () => run(() => navigation.openSession(targetSessionId)), {
|
|
2811
|
+
className: 'dpt-row-icon-btn', iconSize: 13, title: '打开目标会话', disabled: status.busy,
|
|
2812
|
+
}))
|
|
2813
|
+
|
|
2814
|
+
const alwaysActions = !isEnded && h(Switch, {
|
|
2815
|
+
checked: effectiveActive,
|
|
2816
|
+
disabled: status.busy,
|
|
2817
|
+
label: `${effectiveActive ? '暂停' : '恢复'} ${item.title}`,
|
|
2818
|
+
onChange: toggleActive,
|
|
2819
|
+
})
|
|
2820
|
+
|
|
2821
|
+
return h(DisclosureRow, {
|
|
2822
|
+
'data-schedule-id': item.id,
|
|
2823
|
+
title: item.title,
|
|
2824
|
+
tag: scheduleRuleLabel(item),
|
|
2825
|
+
detail: detailParts.join(' · '),
|
|
2826
|
+
badge,
|
|
2827
|
+
tone,
|
|
2828
|
+
quickActions,
|
|
2829
|
+
alwaysActions,
|
|
2830
|
+
...disclosure,
|
|
2831
|
+
},
|
|
2832
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2833
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
2834
|
+
h('span', null, '任务 ID', code(item.id)),
|
|
2835
|
+
item.scheduledAt && !isEnded && h('span', null, '下次触发', h('strong', null, new Date(item.scheduledAt).toLocaleString())),
|
|
2836
|
+
item.timeZone && h('span', null, '时区', code(item.timeZone)),
|
|
2837
|
+
targetSessionId && h('span', null, '目标会话', code(targetSessionId))),
|
|
2838
|
+
h('div', { className: 'dpt-actions' },
|
|
2839
|
+
!isEnded && button('立即运行', runNow, { icon: 'play', disabled: status.busy || item.executionActive }),
|
|
2840
|
+
!isEnded && button(effectiveActive ? '暂停' : '恢复', () => toggleActive(!effectiveActive), { icon: effectiveActive ? 'pause' : 'play', disabled: status.busy }),
|
|
2841
|
+
targetSessionId && button('打开会话', () => run(() => navigation.openSession(targetSessionId)), { icon: 'external-link', disabled: status.busy }),
|
|
2842
|
+
button(history ? '刷新历史' : '投递历史', loadHistory, { icon: 'clock', disabled: status.busy }),
|
|
2843
|
+
button('删除', () => setRemoval(true), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
2844
|
+
item.prompt && h('pre', { className: 'dpt-mono', dir: 'auto' }, item.prompt),
|
|
2845
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
2846
|
+
history && h('div', { className: 'dpt-drawer-split' },
|
|
2847
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
2848
|
+
h('span', { className: 'dpt-label' }, `最近投递记录(${history.records.length})${history.earlierRecordsPruned ? ' · 更早记录已按保留窗口清理' : ''}`),
|
|
2849
|
+
button('关闭历史', () => setHistory(null), { icon: 'x', iconSize: 13 })),
|
|
2850
|
+
history.records.length > 0
|
|
2851
|
+
? h('ul', { className: 'dpt-file-list dpt-scroll-box' }, history.records.map(rec => h('li', { key: rec.messageId || rec.deliveredAt },
|
|
2852
|
+
h('span', null, new Date(rec.deliveredAt).toLocaleString(), ' · ', code(rec.targetSessionId)),
|
|
2853
|
+
h('span', null, `计划 ${formatIsoShort(rec.scheduledAt)}`))))
|
|
2854
|
+
: muted('尚无投递记录。')),
|
|
2855
|
+
removal && h(Confirm, {
|
|
2856
|
+
title: `删除定时任务 ${item.title}`,
|
|
2857
|
+
label: '确认删除定时任务',
|
|
2858
|
+
removed: [`定时任务「${item.title}」(${item.id})及未执行的后续触发计划`],
|
|
2859
|
+
preserved: ['目标会话与历史已投递的消息记录'],
|
|
2860
|
+
close: () => setRemoval(false),
|
|
2861
|
+
confirm: async () => {
|
|
2862
|
+
await request('schedule', { action: 'delete', id: item.id, confirm: item.id, expectedUpdatedAt: item.updatedAt })
|
|
2863
|
+
setRemoval(false)
|
|
2864
|
+
notify(`已删除定时任务 ${item.title}`)
|
|
2865
|
+
await refresh()
|
|
2866
|
+
},
|
|
2867
|
+
}))
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
function TasksPanel({ sessionList, navigation, host, toast }) {
|
|
2871
|
+
const { jobs, schedules, error, reloading, refresh, dismissError } = useTasksData(host)
|
|
2872
|
+
const [kindFilter, setKindFilter] = useState('all')
|
|
2873
|
+
const [stateFilter, setStateFilter] = useState('all')
|
|
2874
|
+
const [query, search] = useState('')
|
|
2875
|
+
const [clearingEnded, setClearingEnded] = useState(false)
|
|
2876
|
+
const disclosure = useDisclosure()
|
|
2877
|
+
|
|
2878
|
+
const jobItems = jobs ?? []
|
|
2879
|
+
const scheduleItems = schedules ?? []
|
|
2880
|
+
const liveJobCount = jobItems.filter(item => item.status === 'running' || item.status === 'stopping').length
|
|
2881
|
+
const activeScheduleCount = scheduleItems.filter(item => item.status === 'active').length
|
|
2882
|
+
const endedScheduleCount = scheduleItems.filter(item => item.status === 'ended').length
|
|
2883
|
+
|
|
2884
|
+
const sessionTitleById = id => {
|
|
2885
|
+
if (!id) return ''
|
|
2886
|
+
const row = sessionList.byId?.[id]
|
|
2887
|
+
return row?.title || (row?.displayTitle !== id && row?.displayTitle) || ''
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
const filteredJobs = kindFilter === 'schedule' ? [] : jobItems.filter(job => {
|
|
2891
|
+
const live = job.status === 'running' || job.status === 'stopping'
|
|
2892
|
+
if (stateFilter === 'active' && !live) return false
|
|
2893
|
+
if (stateFilter === 'paused') return false
|
|
2894
|
+
if (stateFilter === 'ended' && live) return false
|
|
2895
|
+
return matches(query, job.label, job.id, job.kind, job.owner ?? '', sessionTitleById(job.owner), job.detail ?? '')
|
|
2896
|
+
})
|
|
2897
|
+
|
|
2898
|
+
const filteredSchedules = kindFilter === 'jobs' ? [] : scheduleItems.filter(item => {
|
|
2899
|
+
if (stateFilter === 'active' && item.status !== 'active') return false
|
|
2900
|
+
if (stateFilter === 'paused' && item.status !== 'paused') return false
|
|
2901
|
+
if (stateFilter === 'ended' && item.status !== 'ended') return false
|
|
2902
|
+
const targetId = item.target?.sessionId ?? ''
|
|
2903
|
+
return matches(query, item.title, item.id, item.prompt, scheduleRuleLabel(item), targetId, sessionTitleById(targetId))
|
|
2904
|
+
})
|
|
2905
|
+
|
|
2906
|
+
const totalShown = filteredJobs.length + filteredSchedules.length
|
|
2907
|
+
const hasActiveFilter = Boolean(query.trim()) || stateFilter !== 'all'
|
|
2908
|
+
const resetFilters = () => { search(''); setStateFilter('all') }
|
|
2909
|
+
const ready = jobs !== null || schedules !== null || (host.info?.jobs === false && host.info?.schedule === false)
|
|
2910
|
+
|
|
2911
|
+
return h('div', { className: 'dpt-panel' },
|
|
2912
|
+
feedback(host.error || (host.info?.jobs === false && host.info?.schedule === false ? '当前 DSH 配置未加载后台任务与定时调度服务。' : ''), true, host.dismiss),
|
|
2913
|
+
feedback(error, true, dismissError),
|
|
2914
|
+
h('div', { className: 'dpt-toolbar' },
|
|
2915
|
+
h(Segmented, {
|
|
2916
|
+
label: '任务类型筛选', value: kindFilter, onChange: setKindFilter,
|
|
2917
|
+
items: [
|
|
2918
|
+
{ value: 'all', label: '全部', count: ready ? jobItems.length + scheduleItems.length : null },
|
|
2919
|
+
{ value: 'jobs', label: '后台任务', count: jobs ? jobItems.length : null, alert: liveJobCount > 0 },
|
|
2920
|
+
{ value: 'schedule', label: '定时调度', count: schedules ? scheduleItems.length : null, alert: activeScheduleCount > 0 },
|
|
2921
|
+
],
|
|
2922
|
+
}),
|
|
2923
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
2924
|
+
filterInput('搜索任务或提示词', query, search),
|
|
2925
|
+
pick('任务状态筛选', stateFilter, setStateFilter, [
|
|
2926
|
+
option('all', '全部状态'),
|
|
2927
|
+
option('active', '运行中 / 活跃'),
|
|
2928
|
+
option('paused', '已暂停'),
|
|
2929
|
+
option('ended', '已结束'),
|
|
2930
|
+
]),
|
|
2931
|
+
hasActiveFilter && totalShown > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
2932
|
+
endedScheduleCount > 0 && kindFilter !== 'jobs' && button(`清理已结束 (${endedScheduleCount})`, () => setClearingEnded(true), { icon: 'trash', iconSize: 13 }),
|
|
2933
|
+
iconButton('刷新任务与调度', 'refresh-cw', refresh, { iconClass: reloading ? 'dpt-spin' : '', disabled: reloading, 'aria-busy': reloading }))),
|
|
2934
|
+
totalShown > 0
|
|
2935
|
+
? h('ul', { className: 'dpt-card' },
|
|
2936
|
+
filteredJobs.length > 0 && h(React.Fragment, null,
|
|
2937
|
+
kindFilter === 'all' && h('li', { className: 'dpt-subhead' }, `后台任务(${filteredJobs.length})`),
|
|
2938
|
+
filteredJobs.map(job => h(JobRow, {
|
|
2939
|
+
key: `job:${job.id}`, job, sessionTitle: sessionTitleById(job.owner),
|
|
2940
|
+
navigation, refresh, notify: toast.show,
|
|
2941
|
+
disclosure: disclosure(`job:${job.id}`),
|
|
2942
|
+
}))),
|
|
2943
|
+
filteredSchedules.length > 0 && h(React.Fragment, null,
|
|
2944
|
+
kindFilter === 'all' && h('li', { className: 'dpt-subhead' }, `定时调度(${filteredSchedules.length})`),
|
|
2945
|
+
filteredSchedules.map(item => h(ScheduleRow, {
|
|
2946
|
+
key: `schedule:${item.id}`, item, sessionTitle: sessionTitleById(item.target?.sessionId),
|
|
2947
|
+
navigation, refresh, notify: toast.show,
|
|
2948
|
+
disclosure: disclosure(`schedule:${item.id}`),
|
|
2949
|
+
}))))
|
|
2950
|
+
: empty(ready
|
|
2951
|
+
? (hasActiveFilter ? '没有符合条件的任务或定时调度。' : '当前没有后台任务或定时调度。')
|
|
2952
|
+
: '正在读取后台任务与定时调度…', ready && hasActiveFilter ? resetFilters : undefined),
|
|
2953
|
+
clearingEnded && h(Confirm, {
|
|
2954
|
+
title: `清理 ${endedScheduleCount} 条已结束的定时任务`,
|
|
2955
|
+
label: '确认清理',
|
|
2956
|
+
removed: [`${endedScheduleCount} 条状态为「已结束」的定时调度记录`],
|
|
2957
|
+
preserved: ['所有活跃与暂停中的定时调度', '历史已投递的会话消息'],
|
|
2958
|
+
close: () => setClearingEnded(false),
|
|
2959
|
+
confirm: async () => {
|
|
2960
|
+
const result = await request('schedule', { action: 'delete-inactive', confirm: true })
|
|
2961
|
+
setClearingEnded(false)
|
|
2962
|
+
toast.show(`已清理 ${result.deleted ?? endedScheduleCount} 条已结束的定时任务`)
|
|
2963
|
+
await refresh()
|
|
2964
|
+
},
|
|
2965
|
+
}))
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function PowerTools({ useSessions, useWorkspaces, navigation, refresh, t, embedded = false }) {
|
|
2969
|
+
const [tab, select] = useState('sessions')
|
|
2970
|
+
const sessionList = useSessions(identity)
|
|
2971
|
+
const workspaceList = useWorkspaces(identity)
|
|
2972
|
+
const host = useHostStatus()
|
|
2973
|
+
const toast = useToast()
|
|
2974
|
+
const controls = h('div', { className: 'dpt-controls' },
|
|
2975
|
+
h('nav', { className: 'dpt-nav', 'aria-label': '工具箱功能' },
|
|
2976
|
+
[['sessions', '会话', 'message-square'], ['mcp', 'MCP', 'plug'], ['skills', 'Skill', 'wand-sparkles'], ['tasks', '任务与调度', 'clock']].map(([id, label, icon]) =>
|
|
2977
|
+
button(label, () => select(id), { key: id, icon, className: 'dpt-tab', 'aria-pressed': tab === id }))),
|
|
2978
|
+
tab === 'sessions' ? h(SessionPanel, { sessionList, workspaceList, navigation, refresh, host, toast, t })
|
|
2979
|
+
: tab === 'mcp' ? h(McpPanel, { host, toast })
|
|
2980
|
+
: tab === 'skills' ? h(SkillsPanel, { sessionList, workspaceList, navigation, host, toast })
|
|
2981
|
+
: h(TasksPanel, { sessionList, navigation, host, toast }),
|
|
2982
|
+
toast.node)
|
|
2983
|
+
const stylesheet = h('style', null, css)
|
|
2984
|
+
if (embedded) return h('div', { className: 'dpt dpt-inline' }, stylesheet, controls)
|
|
2985
|
+
return h('main', { className: 'dpt dpt-page' }, stylesheet, h('div', { className: 'dpt-page-inner' },
|
|
2986
|
+
h('header', { className: 'dpt-page-head' },
|
|
2987
|
+
h('div', { className: 'dpt-page-icon' }, h(PowerToolsIcon, { size: 18 })), h('h1', null, '工具箱')),
|
|
2988
|
+
controls))
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
function PowerToolsConfig(props) {
|
|
2992
|
+
return props.view === 'page' ? h(PowerTools, { ...props, embedded: true }) : null
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
function Enhance({ useInput, inputActions, sessionId }) {
|
|
2996
|
+
const input = useInput(identity)
|
|
2997
|
+
const [requesting, setRequesting] = useState(false)
|
|
2998
|
+
const [undo, setUndo] = useState(null)
|
|
2999
|
+
const [error, setError] = useState('')
|
|
3000
|
+
const [sendClass, setSendClass] = useState('')
|
|
3001
|
+
const pending = useRef(null)
|
|
3002
|
+
const rootRef = useRef(null)
|
|
3003
|
+
const draft = input?.draft ?? ''
|
|
3004
|
+
const plain = input?.phase === 'plain' && !input?.occurrences?.length
|
|
3005
|
+
const allowed = plain && draft.trim() && !/^\s*\/\S/.test(draft) && typeof inputActions?.insertText === 'function'
|
|
3006
|
+
|
|
3007
|
+
useLayoutEffect(() => {
|
|
3008
|
+
const root = rootRef.current
|
|
3009
|
+
const card = root.closest('[data-composer-card]')
|
|
3010
|
+
// The host marks the primary action with aria-busy on both release lines.
|
|
3011
|
+
const primaryButton = ':scope > button[aria-busy]:not(.dpt-composer-action)'
|
|
3012
|
+
let toolbar = root.parentElement
|
|
3013
|
+
while (toolbar && toolbar !== card && !toolbar.querySelector(primaryButton)) toolbar = toolbar.parentElement
|
|
3014
|
+
if (!toolbar || toolbar === card) return
|
|
3015
|
+
const sync = () => setSendClass(toolbar.querySelector(primaryButton)?.className ?? '')
|
|
3016
|
+
const observer = new MutationObserver(sync)
|
|
3017
|
+
observer.observe(toolbar, { childList: true })
|
|
3018
|
+
sync()
|
|
3019
|
+
return () => observer.disconnect()
|
|
3020
|
+
}, [])
|
|
3021
|
+
|
|
3022
|
+
useEffect(() => () => { pending.current?.abort(); pending.current = null }, [sessionId])
|
|
3023
|
+
useEffect(() => { setError('') }, [input?.draftRev, sessionId])
|
|
3024
|
+
useEffect(() => {
|
|
3025
|
+
if (pending.current && (pending.current.revision !== input?.draftRev || !plain || pending.current.sessionId !== sessionId)) {
|
|
3026
|
+
pending.current.abort(); pending.current = null; setRequesting(false)
|
|
3027
|
+
}
|
|
3028
|
+
if (undo && (undo.revision !== input?.draftRev || !plain || undo.sessionId !== sessionId)) setUndo(null)
|
|
3029
|
+
}, [input?.draftRev, plain, sessionId, undo])
|
|
3030
|
+
|
|
3031
|
+
function focusComposer() {
|
|
3032
|
+
const card = rootRef.current?.closest('[data-composer-card]')
|
|
3033
|
+
const editor = card?.querySelector('[contenteditable="true"][role="textbox"]')
|
|
3034
|
+
if (editor instanceof HTMLElement) editor.focus()
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
async function enhance() {
|
|
3038
|
+
if (!allowed || pending.current) return
|
|
3039
|
+
const controller = new AbortController()
|
|
3040
|
+
const revision = inputActions.captureInsertion().draftRev
|
|
3041
|
+
if (revision !== input.draftRev) return
|
|
3042
|
+
const active = { revision, sessionId, abort: () => controller.abort() }
|
|
3043
|
+
pending.current = active
|
|
3044
|
+
setError(''); setRequesting(true)
|
|
3045
|
+
try {
|
|
3046
|
+
const result = await request('enhance', { draft, sessionId }, AbortSignal.any([controller.signal, AbortSignal.timeout(48_000)]))
|
|
3047
|
+
if (pending.current === active && inputActions.captureInsertion().draftRev === revision) {
|
|
3048
|
+
if (inputActions.insertText(result.text, { start: 0, end: draft.length, draftRev: revision })) {
|
|
3049
|
+
const nextRev = inputActions.captureInsertion().draftRev
|
|
3050
|
+
setUndo({
|
|
3051
|
+
sessionId, revision: nextRev, original: draft, enhanced: result.text,
|
|
3052
|
+
model: result.model, contextTurns: result.contextTurns ?? 0,
|
|
3053
|
+
})
|
|
3054
|
+
focusComposer()
|
|
3055
|
+
} else setError('草稿已变化,请重新增强。')
|
|
3056
|
+
}
|
|
3057
|
+
} catch (error) {
|
|
3058
|
+
if (pending.current === active && !controller.signal.aborted) setError(error.message)
|
|
3059
|
+
} finally {
|
|
3060
|
+
if (pending.current === active) { pending.current = null; setRequesting(false) }
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
function revert() {
|
|
3065
|
+
if (!undo || undo.sessionId !== sessionId) return
|
|
3066
|
+
if (plain && undo.revision === inputActions.captureInsertion().draftRev && draft === undo.enhanced) {
|
|
3067
|
+
inputActions.insertText(undo.original, { start: 0, end: undo.enhanced.length, draftRev: undo.revision })
|
|
3068
|
+
focusComposer()
|
|
3069
|
+
}
|
|
3070
|
+
setUndo(null)
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
const keepFocus = e => e.preventDefault()
|
|
3074
|
+
const actionClass = 'dpt-composer-action ' + (sendClass || 'dpt-composer-action--fallback')
|
|
3075
|
+
|
|
3076
|
+
return h('div', { ref: rootRef, className: 'dpt dpt-composer' }, h('style', null, css),
|
|
3077
|
+
feedback(error, true, () => setError('')),
|
|
3078
|
+
undo && h('button', {
|
|
3079
|
+
type: 'button', className: actionClass + ' dpt-composer-undo', 'aria-label': '撤销增强',
|
|
3080
|
+
title: undo.model
|
|
3081
|
+
? `撤销增强(已由 ${undo.model} 改写${undo.contextTurns > 0 ? `,参考最近 ${undo.contextTurns} 条上下文` : ''})`
|
|
3082
|
+
: '撤销增强',
|
|
3083
|
+
onMouseDown: keepFocus, onClick: revert,
|
|
3084
|
+
}, h(Icon, { name: 'undo', size: 16 })),
|
|
3085
|
+
requesting
|
|
3086
|
+
? h('button', {
|
|
3087
|
+
type: 'button', className: actionClass, 'aria-label': '取消增强', title: '取消增强',
|
|
3088
|
+
'aria-busy': true, onMouseDown: keepFocus,
|
|
3089
|
+
onClick: () => { pending.current?.abort(); pending.current = null; setRequesting(false) },
|
|
3090
|
+
}, h(Icon, { name: 'loader', size: 16, className: 'dpt-spin' }))
|
|
3091
|
+
: h('button', {
|
|
3092
|
+
type: 'button', className: actionClass, 'aria-label': '增强',
|
|
3093
|
+
title: '使用当前主对话模型结合近期上下文改写草稿', disabled: !allowed,
|
|
3094
|
+
onMouseDown: keepFocus, onClick: enhance,
|
|
3095
|
+
}, h(Icon, { name: 'enhance', size: 16 })))
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
function EnhanceSlot(props) {
|
|
3099
|
+
if (!props.useInput || !props.inputActions || !props.sessionId) return null
|
|
3100
|
+
return h(Enhance, { key: props.sessionId, ...props })
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
function SidebarSessionDelete({ target, close, refresh, notify, t }) {
|
|
3104
|
+
const { sessionId, displayTitle } = target
|
|
3105
|
+
const [preview, setPreview] = useState(null)
|
|
3106
|
+
const [status, run, dismiss] = useAction()
|
|
3107
|
+
useEffect(() => {
|
|
3108
|
+
const abort = new AbortController()
|
|
3109
|
+
request('sessions', { action: 'list' }, abort.signal).then(({ sessions }) => {
|
|
3110
|
+
if (!abort.signal.aborted) setPreview({ row: sessions.find(row => row.id === sessionId) })
|
|
3111
|
+
}).catch(error => {
|
|
3112
|
+
if (!abort.signal.aborted) setPreview({ error: error.message })
|
|
3113
|
+
})
|
|
3114
|
+
return () => abort.abort()
|
|
3115
|
+
}, [sessionId])
|
|
3116
|
+
|
|
3117
|
+
const row = preview?.row
|
|
3118
|
+
const subagents = row?.descendantSubagentIds.length ?? 0
|
|
3119
|
+
const error = preview?.error || (preview && !row ? t('missing') : '')
|
|
3120
|
+
|| (row && !row.deletable ? (row.deleteBlocker ? t(row.deleteBlocker) : row.deleteReason || t('blocked')) : '')
|
|
3121
|
+
function confirm() {
|
|
3122
|
+
return run(async () => {
|
|
3123
|
+
const result = await request('sessions', { action: 'delete', sessionId, confirm: sessionId })
|
|
3124
|
+
const copyRecovery = {
|
|
3125
|
+
label: t('copyRecovery'), failureLabel: t('copyFailed'),
|
|
3126
|
+
run: async () => { if (!await writeClipboard(result.recovery)) throw new Error(t('copyFailed')) },
|
|
3127
|
+
}
|
|
3128
|
+
try {
|
|
3129
|
+
await refresh()
|
|
3130
|
+
notify(t('deleted'), true, copyRecovery)
|
|
3131
|
+
} catch {
|
|
3132
|
+
notify(t('refreshFailed'), false, copyRecovery)
|
|
3133
|
+
}
|
|
3134
|
+
close()
|
|
3135
|
+
})
|
|
3136
|
+
}
|
|
3137
|
+
return h(Modal, { title: t('deleteTitle', { title: displayTitle || t('untitled') }), close, closeLabel: t('close'), busy: status.busy },
|
|
3138
|
+
h('div', { className: 'dpt-form' },
|
|
3139
|
+
h('div', { className: 'dpt-drawer-facts' }, h('span', null, t('sessionId'), code(sessionId))),
|
|
3140
|
+
!preview && h('p', { role: 'status' }, t('checking')),
|
|
3141
|
+
status.busy && h('p', { role: 'status' }, t('deleting')),
|
|
3142
|
+
error && feedback(error, true),
|
|
3143
|
+
row?.deletable && h('p', null, t('recovery')),
|
|
3144
|
+
subagents > 0 && h('p', null, t('subagents', { count: subagents })),
|
|
3145
|
+
feedback(status.message, status.error, dismiss),
|
|
3146
|
+
h('div', { className: 'dpt-actions' },
|
|
3147
|
+
button(t('cancel'), close, { 'data-dpt-initial-focus': true, disabled: status.busy }),
|
|
3148
|
+
button(t('confirm'), confirm, { icon: 'trash', className: 'dpt-danger', disabled: status.busy || !row?.deletable, 'aria-busy': status.busy }))))
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
function SessionOverlay({ deletion, refresh, notify, t }) {
|
|
3152
|
+
const target = useSyncExternalStore(deletion.subscribe, deletion.getSnapshot)
|
|
3153
|
+
return target && h(SidebarSessionDelete, { key: target.sessionId, target, close: () => deletion.set(null), refresh, notify, t })
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
function PowerToolsIcon({ size = 16 }) {
|
|
3157
|
+
return h(Icon, { name: 'layout-grid', size })
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
return {
|
|
3161
|
+
inject: ['slots', 'uiWorkspace', 'sessions', 'locale', 'contextMenus'],
|
|
3162
|
+
apply(ctx) {
|
|
3163
|
+
ctx.effect(() => ctx.locale.register(SESSION_LOCALE, sessionLocales), 'PowerTools session translations')
|
|
3164
|
+
const t = ctx.locale.bind(SESSION_LOCALE)
|
|
3165
|
+
const refresh = () => ctx.sessions.refresh()
|
|
3166
|
+
const panelProps = () => ({ navigation: ctx.uiWorkspace, refresh })
|
|
3167
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL, locale: SESSION_LOCALE, inject: panelProps }, PowerTools))
|
|
3168
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({ name: 'plugins.bundle.config', key: PANEL, locale: SESSION_LOCALE, inject: panelProps }, PowerToolsConfig))
|
|
3169
|
+
|
|
3170
|
+
let deleteTarget = null
|
|
3171
|
+
const listeners = new Set()
|
|
3172
|
+
const deletion = {
|
|
3173
|
+
getSnapshot: () => deleteTarget,
|
|
3174
|
+
subscribe(listener) {
|
|
3175
|
+
listeners.add(listener)
|
|
3176
|
+
return () => listeners.delete(listener)
|
|
3177
|
+
},
|
|
3178
|
+
set(target) {
|
|
3179
|
+
deleteTarget = target
|
|
3180
|
+
for (const listener of listeners) listener()
|
|
3181
|
+
},
|
|
3182
|
+
}
|
|
3183
|
+
const notify = (...args) => ctx.contextMenus.notify(...args)
|
|
3184
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
3185
|
+
name: 'shell.overlay', id: PANEL, locale: SESSION_LOCALE,
|
|
3186
|
+
inject: () => ({ deletion, refresh, notify }),
|
|
3187
|
+
}, SessionOverlay))
|
|
3188
|
+
const deleteIcon = `${PANEL}.delete-session`
|
|
3189
|
+
ctx.slots.inject('contextMenu.icon', () => ctx.slots.register({
|
|
3190
|
+
name: 'contextMenu.icon', key: deleteIcon,
|
|
3191
|
+
}, () => h(Icon, { name: 'trash' })))
|
|
3192
|
+
ctx.effect(() => ctx.contextMenus.register({
|
|
3193
|
+
id: deleteIcon, target: 'session', order: 700,
|
|
3194
|
+
observe: () => [ctx.locale],
|
|
3195
|
+
resolve(target) {
|
|
3196
|
+
const summary = ctx.sessions.list.getSnapshot().byId[target.sessionId]
|
|
3197
|
+
if (!summary || summary.blank) return []
|
|
3198
|
+
return [{
|
|
3199
|
+
id: 'delete', label: t('delete'), icon: { key: deleteIcon },
|
|
3200
|
+
danger: true, separatorBefore: true, afterContent: true,
|
|
3201
|
+
run: () => deletion.set(target),
|
|
3202
|
+
}]
|
|
3203
|
+
},
|
|
3204
|
+
}), 'PowerTools session deletion menu')
|
|
3205
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({ name: 'sidebar.panellist', id: PANEL, order: 20, label: '工具箱' }, PowerToolsIcon))
|
|
3206
|
+
ctx.slots.inject('conversation.input.activity', () => ctx.slots.register({
|
|
3207
|
+
name: 'conversation.input.activity', id: PANEL, order: 15,
|
|
3208
|
+
inject: sessionId => ({ sessionId }),
|
|
3209
|
+
}, EnhanceSlot))
|
|
3210
|
+
},
|
|
3211
|
+
}
|
|
3212
|
+
},
|
|
3213
|
+
})
|