dsh-powertools 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +90 -2
- package/client.js +2179 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +9 -0
- package/index.js +79 -0
- package/lib/enhance.js +159 -0
- package/lib/errors.js +11 -0
- package/lib/mcp.js +124 -0
- package/lib/platform.js +70 -0
- package/lib/sessions.js +377 -0
- package/lib/skill-repositories.js +152 -0
- package/lib/skills.js +280 -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 +73 -4
package/client.js
ADDED
|
@@ -0,0 +1,2179 @@
|
|
|
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 } = React
|
|
7
|
+
const PANEL = 'dsh-powertools'
|
|
8
|
+
|
|
9
|
+
// Lucide 1.61.0 icon geometry from Magi Code (web/src/lib/icons.ts), license in licenses/lucide.txt.
|
|
10
|
+
const ICONS = {
|
|
11
|
+
'layout-grid': [
|
|
12
|
+
['rect', { width: 7, height: 7, x: 3, y: 3, rx: 1 }],
|
|
13
|
+
['rect', { width: 7, height: 7, x: 14, y: 3, rx: 1 }],
|
|
14
|
+
['rect', { width: 7, height: 7, x: 14, y: 14, rx: 1 }],
|
|
15
|
+
['rect', { width: 7, height: 7, x: 3, y: 14, rx: 1 }],
|
|
16
|
+
],
|
|
17
|
+
'message-square': [
|
|
18
|
+
['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' }],
|
|
19
|
+
],
|
|
20
|
+
plug: [
|
|
21
|
+
['path', { d: 'M12 22v-5' }],
|
|
22
|
+
['path', { d: 'M15 8V2' }],
|
|
23
|
+
['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' }],
|
|
24
|
+
['path', { d: 'M9 8V2' }],
|
|
25
|
+
],
|
|
26
|
+
'wand-sparkles': [
|
|
27
|
+
['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' }],
|
|
28
|
+
['path', { d: 'm14 7 3 3' }],
|
|
29
|
+
['path', { d: 'M5 6v4' }],
|
|
30
|
+
['path', { d: 'M19 14v4' }],
|
|
31
|
+
['path', { d: 'M10 2v2' }],
|
|
32
|
+
['path', { d: 'M7 8H3' }],
|
|
33
|
+
['path', { d: 'M21 16h-4' }],
|
|
34
|
+
['path', { d: 'M11 3H9' }],
|
|
35
|
+
],
|
|
36
|
+
enhance: [
|
|
37
|
+
['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' }],
|
|
38
|
+
['path', { d: 'M20 2v4' }],
|
|
39
|
+
['path', { d: 'M22 4h-4' }],
|
|
40
|
+
['circle', { cx: 4, cy: 20, r: 2 }],
|
|
41
|
+
],
|
|
42
|
+
loader: [
|
|
43
|
+
['path', { d: 'M21 12a9 9 0 1 1-6.219-8.56' }],
|
|
44
|
+
],
|
|
45
|
+
undo: [
|
|
46
|
+
['path', { d: 'M9 14 4 9l5-5' }],
|
|
47
|
+
['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' }],
|
|
48
|
+
],
|
|
49
|
+
plus: [
|
|
50
|
+
['path', { d: 'M5 12h14' }],
|
|
51
|
+
['path', { d: 'M12 5v14' }],
|
|
52
|
+
],
|
|
53
|
+
'refresh-cw': [
|
|
54
|
+
['path', { d: 'M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8' }],
|
|
55
|
+
['path', { d: 'M21 3v5h-5' }],
|
|
56
|
+
['path', { d: 'M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16' }],
|
|
57
|
+
['path', { d: 'M8 16H3v5' }],
|
|
58
|
+
],
|
|
59
|
+
'rotate-cw': [
|
|
60
|
+
['path', { d: 'M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8' }],
|
|
61
|
+
['path', { d: 'M21 3v5h-5' }],
|
|
62
|
+
],
|
|
63
|
+
play: [
|
|
64
|
+
['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' }],
|
|
65
|
+
],
|
|
66
|
+
'square-pen': [
|
|
67
|
+
['path', { d: 'M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7' }],
|
|
68
|
+
['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' }],
|
|
69
|
+
],
|
|
70
|
+
trash: [
|
|
71
|
+
['path', { d: 'M10 11v6' }],
|
|
72
|
+
['path', { d: 'M14 11v6' }],
|
|
73
|
+
['path', { d: 'M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6' }],
|
|
74
|
+
['path', { d: 'M3 6h18' }],
|
|
75
|
+
['path', { d: 'M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2' }],
|
|
76
|
+
],
|
|
77
|
+
archive: [
|
|
78
|
+
['rect', { width: 20, height: 5, x: 2, y: 3, rx: 1 }],
|
|
79
|
+
['path', { d: 'M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8' }],
|
|
80
|
+
['path', { d: 'M10 12h4' }],
|
|
81
|
+
],
|
|
82
|
+
'archive-restore': [
|
|
83
|
+
['rect', { width: 20, height: 5, x: 2, y: 3, rx: 1 }],
|
|
84
|
+
['path', { d: 'M4 8v11a2 2 0 0 0 2 2h2' }],
|
|
85
|
+
['path', { d: 'M20 8v11a2 2 0 0 1-2 2h-2' }],
|
|
86
|
+
['path', { d: 'm9 15 3-3 3 3' }],
|
|
87
|
+
['path', { d: 'M12 12v9' }],
|
|
88
|
+
],
|
|
89
|
+
eye: [
|
|
90
|
+
['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' }],
|
|
91
|
+
['circle', { cx: 12, cy: 12, r: 3 }],
|
|
92
|
+
],
|
|
93
|
+
'folder-plus': [
|
|
94
|
+
['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' }],
|
|
95
|
+
['path', { d: 'M12 10v6' }],
|
|
96
|
+
['path', { d: 'M9 13h6' }],
|
|
97
|
+
],
|
|
98
|
+
folder: [
|
|
99
|
+
['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' }],
|
|
100
|
+
],
|
|
101
|
+
'external-link': [
|
|
102
|
+
['path', { d: 'M15 3h6v6' }],
|
|
103
|
+
['path', { d: 'M10 14 21 3' }],
|
|
104
|
+
['path', { d: 'M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6' }],
|
|
105
|
+
],
|
|
106
|
+
copy: [
|
|
107
|
+
['rect', { width: 14, height: 14, x: 8, y: 8, rx: 2, ry: 2 }],
|
|
108
|
+
['path', { d: 'M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2' }],
|
|
109
|
+
],
|
|
110
|
+
check: [
|
|
111
|
+
['path', { d: 'M20 6 9 17l-5-5' }],
|
|
112
|
+
],
|
|
113
|
+
x: [
|
|
114
|
+
['path', { d: 'M18 6 6 18' }],
|
|
115
|
+
['path', { d: 'm6 6 12 12' }],
|
|
116
|
+
],
|
|
117
|
+
'git-branch': [
|
|
118
|
+
['line', { x1: 6, x2: 6, y1: 3, y2: 15 }],
|
|
119
|
+
['circle', { cx: 18, cy: 6, r: 3 }],
|
|
120
|
+
['circle', { cx: 6, cy: 18, r: 3 }],
|
|
121
|
+
['path', { d: 'M18 9a9 9 0 0 1-9 9' }],
|
|
122
|
+
],
|
|
123
|
+
download: [
|
|
124
|
+
['path', { d: 'M12 15V3' }],
|
|
125
|
+
['path', { d: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4' }],
|
|
126
|
+
['path', { d: 'm7 10 5 5 5-5' }],
|
|
127
|
+
],
|
|
128
|
+
'chevrons-down-up': [
|
|
129
|
+
['path', { d: 'm7 20 5-5 5 5' }],
|
|
130
|
+
['path', { d: 'm7 4 5 5 5-5' }],
|
|
131
|
+
],
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function Icon({ name, size = 14, className = '' }) {
|
|
135
|
+
const shapes = ICONS[name]
|
|
136
|
+
if (!shapes) return null
|
|
137
|
+
return h('svg', {
|
|
138
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
|
|
139
|
+
stroke: 'currentColor', strokeWidth: 1.75, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
140
|
+
'aria-hidden': true, 'data-icon': name, className: `dpt-icon${className ? ` ${className}` : ''}`,
|
|
141
|
+
}, ...shapes.map(([tag, attrs], index) => h(tag, { key: index, ...attrs })))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const css = `
|
|
145
|
+
.dpt {
|
|
146
|
+
--dpt-line: var(--dsw-alias-border-l2);
|
|
147
|
+
--dpt-module: var(--dsw-alias-bg-module-platform, var(--dsw-alias-bg-layer-2));
|
|
148
|
+
--dpt-entry: var(--dsw-alias-bg-base, var(--dsw-alias-bg-layer-1));
|
|
149
|
+
--dpt-muted: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
|
|
150
|
+
--dpt-accent: var(--dsw-alias-state-business-primary);
|
|
151
|
+
--dpt-danger: var(--dsw-alias-state-error-primary);
|
|
152
|
+
--dpt-ease: 140ms var(--ds-ease-in-out, cubic-bezier(.4, 0, .2, 1));
|
|
153
|
+
color: var(--dsw-alias-label-primary);
|
|
154
|
+
font-size: 13px;
|
|
155
|
+
line-height: 20px;
|
|
156
|
+
font-weight: 400;
|
|
157
|
+
min-width: 0;
|
|
158
|
+
container-type: inline-size;
|
|
159
|
+
}
|
|
160
|
+
.dpt *, .dpt *::before { box-sizing: border-box; }
|
|
161
|
+
.dpt-icon { display: block; flex: 0 0 auto; }
|
|
162
|
+
@keyframes dpt-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
163
|
+
.dpt-spin { animation: dpt-spin 900ms linear infinite; }
|
|
164
|
+
.dpt h1, .dpt h2, .dpt h3, .dpt p, .dpt ul, .dpt dl, .dpt dd { margin: 0; }
|
|
165
|
+
.dpt h1 { font-size: 20px; line-height: 28px; font-weight: 500; }
|
|
166
|
+
.dpt h2 { font-size: 16px; line-height: 24px; font-weight: 500; overflow-wrap: anywhere; }
|
|
167
|
+
.dpt h3 { font-size: 14px; line-height: 20px; font-weight: 500; }
|
|
168
|
+
.dpt a, .dpt button, .dpt input, .dpt select, .dpt textarea { font: inherit; }
|
|
169
|
+
.dpt-page {
|
|
170
|
+
width: 100%; height: 100%; min-height: 0; overflow-x: hidden; overflow-y: auto;
|
|
171
|
+
scrollbar-gutter: stable; background: var(--dsw-alias-bg-base);
|
|
172
|
+
--dsh-scrollbar-width: 9px; --dsh-scrollbar-thumb-border: 2px;
|
|
173
|
+
}
|
|
174
|
+
.dpt-page-inner { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 clamp(24px, 4vw, 48px) 48px; }
|
|
175
|
+
@media (max-width: 767px) { .dpt-page-inner { padding-inline: 20px; } }
|
|
176
|
+
.dpt-inline { width: 100%; padding: 0; }
|
|
177
|
+
.dpt-page-head { display: flex; align-items: center; gap: 12px; padding-top: 28px; margin-bottom: 14px; }
|
|
178
|
+
[data-platform='darwin'] .dpt-page .dpt-page-head { padding-top: calc(28px + var(--dsh-frame-top-clearance, 0px)); }
|
|
179
|
+
.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); }
|
|
180
|
+
.dpt-controls { display: grid; gap: 14px; }
|
|
181
|
+
.dpt-panel { display: grid; gap: 12px; min-width: 0; }
|
|
182
|
+
.dpt-bar, .dpt-actions, .dpt-nav, .dpt-form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
183
|
+
.dpt-nav { gap: 4px; border-bottom: .5px solid var(--dpt-line); }
|
|
184
|
+
.dpt-nav .dpt-tab {
|
|
185
|
+
position: relative; min-height: 34px; padding: 0 12px; border-radius: 6px 6px 0 0;
|
|
186
|
+
color: var(--dpt-muted); background: transparent;
|
|
187
|
+
}
|
|
188
|
+
.dpt-nav .dpt-tab[aria-pressed='true'] { color: var(--dsw-alias-label-primary); font-weight: 500; background: transparent; }
|
|
189
|
+
.dpt-nav .dpt-tab[aria-pressed='true']::after {
|
|
190
|
+
content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px;
|
|
191
|
+
border-radius: 2px; background: var(--dpt-accent);
|
|
192
|
+
}
|
|
193
|
+
/* Unified single-row sticky toolbar with clickable segmented pills */
|
|
194
|
+
.dpt-toolbar {
|
|
195
|
+
display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-width: 0;
|
|
196
|
+
}
|
|
197
|
+
@container (min-width: 561px) {
|
|
198
|
+
.dpt-page .dpt-toolbar {
|
|
199
|
+
position: sticky; top: 0; z-index: 10; padding-block: 6px; margin-block: -6px -2px;
|
|
200
|
+
background: var(--dsw-alias-bg-base);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
.dpt-toolbar-right {
|
|
204
|
+
display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; flex: 1 1 auto; min-width: 0;
|
|
205
|
+
}
|
|
206
|
+
.dpt-seg {
|
|
207
|
+
display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 2px;
|
|
208
|
+
border-radius: var(--dsw-radius-sm, 8px); background: var(--dpt-module); border: .5px solid var(--dpt-line);
|
|
209
|
+
}
|
|
210
|
+
.dpt-seg-btn {
|
|
211
|
+
display: inline-flex; align-items: center; gap: 5px; min-height: 26px; padding: 0 9px;
|
|
212
|
+
border: 0; border-radius: 6px; background: transparent; color: var(--dpt-muted);
|
|
213
|
+
font-size: 12.5px; line-height: 18px; cursor: pointer; white-space: nowrap;
|
|
214
|
+
transition: background var(--dpt-ease), color var(--dpt-ease);
|
|
215
|
+
}
|
|
216
|
+
.dpt-seg-btn[aria-pressed='true'] {
|
|
217
|
+
background: var(--dpt-entry); color: var(--dsw-alias-label-primary); font-weight: 500;
|
|
218
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 7%);
|
|
219
|
+
}
|
|
220
|
+
.dpt-seg-count { font-size: 11px; color: var(--dpt-muted); font-weight: 400; }
|
|
221
|
+
.dpt-seg-btn[aria-pressed='true'] .dpt-seg-count { color: var(--dsw-alias-label-secondary); }
|
|
222
|
+
.dpt-seg-btn[data-alert='true'] .dpt-seg-count { color: var(--dsw-alias-state-warn-primary); font-weight: 500; }
|
|
223
|
+
.dpt .dpt-button {
|
|
224
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 5px;
|
|
225
|
+
max-width: 100%; min-height: 30px; height: auto; padding: 0 10px; font-size: 13px; line-height: 20px;
|
|
226
|
+
white-space: nowrap;
|
|
227
|
+
transition: background var(--dpt-ease), box-shadow var(--dpt-ease), color var(--dpt-ease);
|
|
228
|
+
}
|
|
229
|
+
.dpt .dpt-icon-btn { width: 30px; min-width: 30px; min-height: 30px; padding: 0; color: var(--dsw-alias-label-secondary); }
|
|
230
|
+
.dpt .dpt-row-btn { min-height: 26px; padding: 0 8px; font-size: 12px; line-height: 18px; }
|
|
231
|
+
.dpt .dpt-row-icon-btn { width: 26px; min-width: 26px; min-height: 26px; padding: 0; color: var(--dsw-alias-label-secondary); }
|
|
232
|
+
.dpt .dpt-button:disabled { cursor: default; }
|
|
233
|
+
.dpt .dpt-primary { background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground); font-weight: 500; }
|
|
234
|
+
.dpt .dpt-danger { color: var(--dpt-danger); }
|
|
235
|
+
.dpt :is(button, input, select, textarea):focus-visible {
|
|
236
|
+
outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dpt-accent));
|
|
237
|
+
outline-offset: 1px;
|
|
238
|
+
}
|
|
239
|
+
.dpt :is(input:not([type='checkbox']), select, textarea) {
|
|
240
|
+
min-width: 0; max-width: 100%; height: 30px; padding: 0 10px; color: inherit;
|
|
241
|
+
border: .5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-sm, 8px);
|
|
242
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
243
|
+
}
|
|
244
|
+
.dpt .dpt-form :is(input:not([type='checkbox']), select) { height: 32px; }
|
|
245
|
+
.dpt .dpt-search { width: auto; flex: 1 1 130px; max-width: 220px; font-size: 12.5px; }
|
|
246
|
+
.dpt .dpt-toolbar-right select { font-size: 12.5px; padding-inline: 8px; }
|
|
247
|
+
.dpt :is(input, select, textarea):focus { border-color: var(--dpt-accent); }
|
|
248
|
+
.dpt textarea { height: auto; padding-block: 6px; }
|
|
249
|
+
.dpt textarea.dpt-fixed-editor { height: 180px; resize: none; overflow-y: auto; }
|
|
250
|
+
.dpt input.dpt-inline-filter { height: 28px; padding: 0 8px; font-size: 12px; width: 180px; max-width: 100%; }
|
|
251
|
+
@media (hover: hover) {
|
|
252
|
+
.dpt .dpt-button:hover:not(:disabled), .dpt .dpt-row-main:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
253
|
+
.dpt .dpt-seg-btn:hover:not([aria-pressed='true']) { color: var(--dsw-alias-label-primary); }
|
|
254
|
+
.dpt .dpt-nav .dpt-tab:hover:not(:disabled) { color: var(--dsw-alias-label-primary); }
|
|
255
|
+
.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); }
|
|
256
|
+
.dpt .dpt-danger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-danger); color: var(--dpt-danger); }
|
|
257
|
+
.dpt .dpt-icon-btn:hover:not(:disabled), .dpt .dpt-row-icon-btn:hover:not(:disabled) { color: var(--dsw-alias-label-primary); }
|
|
258
|
+
}
|
|
259
|
+
.dpt-card {
|
|
260
|
+
min-width: 0; overflow: hidden; border: .5px solid var(--dsw-alias-settings-card-stroke, var(--dpt-line));
|
|
261
|
+
border-radius: var(--dsw-radius-md, 10px);
|
|
262
|
+
background: var(--dsw-alias-settings-card-fill, var(--dsw-alias-bg-layer-1));
|
|
263
|
+
}
|
|
264
|
+
.dpt ul.dpt-card { padding: 0; list-style: none; }
|
|
265
|
+
.dpt-row + .dpt-row { border-top: .5px solid var(--dpt-line); }
|
|
266
|
+
.dpt-sentinel { height: 1px; border: 0; padding: 0; margin: 0; pointer-events: none; }
|
|
267
|
+
.dpt-subhead {
|
|
268
|
+
padding: 5px 16px; background: color-mix(in srgb, var(--dpt-module) 55%, transparent);
|
|
269
|
+
color: var(--dpt-muted); font-size: 11.5px; line-height: 18px; font-weight: 500;
|
|
270
|
+
}
|
|
271
|
+
.dpt-subhead:not(:first-child) { border-top: .5px solid var(--dpt-line); }
|
|
272
|
+
.dpt-subhead + .dpt-row { border-top: .5px solid var(--dpt-line); }
|
|
273
|
+
.dpt-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 8px; }
|
|
274
|
+
.dpt-section-body { display: grid; gap: 8px; min-width: 0; }
|
|
275
|
+
/* High-density row with hover-swap checkbox and 1-click trailing actions */
|
|
276
|
+
.dpt-row-main {
|
|
277
|
+
display: flex; align-items: center; min-width: 0;
|
|
278
|
+
transition: background var(--dpt-ease);
|
|
279
|
+
}
|
|
280
|
+
.dpt-row[data-selected='true'] > .dpt-row-main {
|
|
281
|
+
background: color-mix(in srgb, var(--dpt-accent) 7%, transparent);
|
|
282
|
+
}
|
|
283
|
+
.dpt-lead-cell {
|
|
284
|
+
position: relative; display: grid; place-items: center; width: 36px; align-self: stretch;
|
|
285
|
+
flex: 0 0 36px; cursor: pointer; user-select: none;
|
|
286
|
+
}
|
|
287
|
+
.dpt-lead-cell .dpt-indicator { transition: opacity 120ms ease; }
|
|
288
|
+
.dpt-row-checkbox {
|
|
289
|
+
position: absolute; width: 15px; height: 15px; margin: 0; cursor: pointer;
|
|
290
|
+
accent-color: var(--dpt-accent); opacity: 0; transition: opacity 120ms ease;
|
|
291
|
+
}
|
|
292
|
+
@media (pointer: coarse) {
|
|
293
|
+
.dpt-lead-cell .dpt-indicator { opacity: 0; }
|
|
294
|
+
.dpt-row-checkbox { opacity: .65; }
|
|
295
|
+
}
|
|
296
|
+
.dpt-row-main:hover .dpt-lead-cell .dpt-indicator,
|
|
297
|
+
.dpt-lead-cell:focus-within .dpt-indicator,
|
|
298
|
+
.dpt-card[data-selecting='true'] .dpt-lead-cell .dpt-indicator { opacity: 0; }
|
|
299
|
+
.dpt-row-main:hover .dpt-row-checkbox,
|
|
300
|
+
.dpt-lead-cell:focus-within .dpt-row-checkbox,
|
|
301
|
+
.dpt-card[data-selecting='true'] .dpt-row-checkbox { opacity: 1; }
|
|
302
|
+
.dpt .dpt-disclosure {
|
|
303
|
+
display: flex; align-items: center; gap: 10px; text-align: start; cursor: pointer;
|
|
304
|
+
flex: 1; min-width: 0; padding: 9px 10px 9px 16px; border: 0; border-radius: 0; background: transparent; color: inherit;
|
|
305
|
+
}
|
|
306
|
+
.dpt-lead-cell + .dpt-disclosure { padding-inline-start: 0; }
|
|
307
|
+
.dpt .dpt-disclosure:focus-visible { outline-offset: -2px; }
|
|
308
|
+
.dpt-row-end {
|
|
309
|
+
display: flex; align-items: center; gap: 8px; padding-inline-end: 16px; flex: 0 0 auto;
|
|
310
|
+
}
|
|
311
|
+
.dpt-row-toggle-tail {
|
|
312
|
+
display: inline-flex; align-items: center; gap: 8px; cursor: pointer; align-self: stretch;
|
|
313
|
+
}
|
|
314
|
+
.dpt-quick-actions {
|
|
315
|
+
display: inline-flex; align-items: center; gap: 3px;
|
|
316
|
+
}
|
|
317
|
+
@media (hover: hover) {
|
|
318
|
+
.dpt-quick-actions--hover { opacity: 0; transition: opacity 120ms ease; }
|
|
319
|
+
.dpt-row-main:hover .dpt-quick-actions--hover,
|
|
320
|
+
.dpt-row-main:focus-within .dpt-quick-actions--hover,
|
|
321
|
+
.dpt-row[data-open='true'] .dpt-quick-actions--hover { opacity: 1; }
|
|
322
|
+
}
|
|
323
|
+
.dpt-switch {
|
|
324
|
+
width: 32px; height: 18px; padding: 2px; border: 0; border-radius: 999px;
|
|
325
|
+
background: var(--dsw-alias-border-l4, var(--dpt-line)); cursor: pointer;
|
|
326
|
+
display: inline-flex; align-items: center; flex: 0 0 32px;
|
|
327
|
+
transition: background var(--dpt-ease);
|
|
328
|
+
}
|
|
329
|
+
.dpt-switch[aria-checked='true'] { background: var(--dpt-accent); }
|
|
330
|
+
.dpt-switch:disabled { opacity: .45; cursor: default; }
|
|
331
|
+
.dpt-switch-thumb {
|
|
332
|
+
width: 14px; height: 14px; border-radius: 50%; background: #fff;
|
|
333
|
+
box-shadow: 0 1px 2px rgb(0 0 0 / 22%);
|
|
334
|
+
transition: transform var(--dpt-ease);
|
|
335
|
+
}
|
|
336
|
+
.dpt-switch[aria-checked='true'] .dpt-switch-thumb { transform: translateX(14px); }
|
|
337
|
+
.dpt-row-label { display: grid; gap: 1px; flex: 1; min-width: 0; }
|
|
338
|
+
.dpt-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
339
|
+
.dpt-row-title strong { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
340
|
+
.dpt-row-tag { min-width: 0; color: var(--dpt-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
341
|
+
.dpt-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
342
|
+
.dpt-indicator { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; background: var(--dpt-tone, var(--dpt-muted)); }
|
|
343
|
+
.dpt[data-tone='ready'], .dpt [data-tone='ready'] { --dpt-tone: var(--dsw-alias-state-success-primary); }
|
|
344
|
+
.dpt[data-tone='attention'], .dpt [data-tone='attention'] { --dpt-tone: var(--dsw-alias-state-warn-primary); }
|
|
345
|
+
.dpt[data-tone='info'], .dpt [data-tone='info'] { --dpt-tone: var(--dpt-accent); }
|
|
346
|
+
.dpt-pill {
|
|
347
|
+
flex: 0 0 auto; padding: 1px 7px; border-radius: 999px; font-size: 11px; line-height: 17px;
|
|
348
|
+
color: var(--dsw-alias-label-secondary); background: var(--dpt-module); border: .5px solid transparent;
|
|
349
|
+
}
|
|
350
|
+
.dpt-pill:not([data-tone='idle']) {
|
|
351
|
+
color: var(--dpt-tone); background: color-mix(in srgb, var(--dpt-tone) 12%, transparent);
|
|
352
|
+
border-color: color-mix(in srgb, var(--dpt-tone) 24%, transparent);
|
|
353
|
+
}
|
|
354
|
+
.dpt-chevron {
|
|
355
|
+
display: grid; place-items: center; flex: 0 0 20px; width: 20px; height: 20px; color: var(--dpt-muted);
|
|
356
|
+
transition: transform var(--dpt-ease);
|
|
357
|
+
}
|
|
358
|
+
.dpt-row[data-open='true'] .dpt-chevron { transform: rotate(90deg); }
|
|
359
|
+
/* Flat full-bleed disclosure drawer: max 2 visual layers */
|
|
360
|
+
.dpt-drawer {
|
|
361
|
+
margin: 0; padding: 10px 16px 12px 36px; min-width: 0; display: grid; gap: 10px;
|
|
362
|
+
border-top: 1px dashed var(--dpt-line);
|
|
363
|
+
background: color-mix(in srgb, var(--dpt-module) 68%, var(--dsw-alias-bg-base));
|
|
364
|
+
}
|
|
365
|
+
.dpt-drawer[hidden] { display: none; }
|
|
366
|
+
.dpt-drawer-bar {
|
|
367
|
+
display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; min-width: 0;
|
|
368
|
+
}
|
|
369
|
+
.dpt-drawer-facts {
|
|
370
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 12px; color: var(--dpt-muted); min-width: 0;
|
|
371
|
+
}
|
|
372
|
+
.dpt-drawer-facts > span { display: inline-flex; align-items: baseline; gap: 5px; min-width: 0; }
|
|
373
|
+
.dpt-drawer-facts strong { font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
374
|
+
.dpt-drawer-split {
|
|
375
|
+
padding-top: 10px; border-top: .5px solid var(--dpt-line); min-width: 0; display: grid; gap: 8px;
|
|
376
|
+
}
|
|
377
|
+
/* Floating bottom multi-select action bar (zero layout shift) */
|
|
378
|
+
.dpt-floating-batch {
|
|
379
|
+
position: sticky; bottom: 14px; z-index: 25; justify-self: center;
|
|
380
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
|
|
381
|
+
max-width: 100%; padding: 6px 10px 6px 14px; border-radius: 999px;
|
|
382
|
+
border: .5px solid var(--dsw-alias-border-l3, var(--dpt-line));
|
|
383
|
+
background: color-mix(in srgb, var(--dsw-alias-bg-layer-1) 92%, var(--dpt-module));
|
|
384
|
+
backdrop-filter: blur(12px);
|
|
385
|
+
box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
|
|
386
|
+
}
|
|
387
|
+
.dpt-batch-sep { width: 1px; height: 16px; background: var(--dpt-line); flex: 0 0 1px; }
|
|
388
|
+
/* Non-shifting floating toast for transient feedback & recovery paths */
|
|
389
|
+
.dpt-toast {
|
|
390
|
+
position: fixed; right: 20px; bottom: 20px; z-index: 45;
|
|
391
|
+
width: max-content; max-width: min(440px, calc(100vw - 32px));
|
|
392
|
+
display: flex; align-items: start; gap: 10px; padding: 8px 10px 8px 14px;
|
|
393
|
+
border-radius: var(--dsw-radius-md, 10px);
|
|
394
|
+
border: .5px solid var(--dsw-alias-border-l3, var(--dpt-line));
|
|
395
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
396
|
+
box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
|
|
397
|
+
transition: bottom var(--dpt-ease);
|
|
398
|
+
}
|
|
399
|
+
.dpt-controls:has(.dpt-floating-batch) > .dpt-toast { bottom: 68px; }
|
|
400
|
+
.dpt-toast[data-error='true'] { border-color: color-mix(in srgb, var(--dpt-danger) 45%, var(--dpt-line)); }
|
|
401
|
+
.dpt-toast-body { flex: 1; min-width: 0; display: grid; gap: 4px; padding-block: 2px; font-size: 12.5px; line-height: 18px; }
|
|
402
|
+
.dpt-toast[data-error='true'] .dpt-toast-body { color: var(--dpt-danger); }
|
|
403
|
+
.dpt-maintenance { background: transparent; border-style: dashed; }
|
|
404
|
+
.dpt-maintenance .dpt-disclosure { background: transparent; padding-block: 8px; }
|
|
405
|
+
.dpt-maintenance .dpt-row-title strong { font-size: 12.5px; color: var(--dpt-muted); font-weight: 500; }
|
|
406
|
+
.dpt-meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: baseline; gap: 4px 12px; }
|
|
407
|
+
.dpt-meta dt, .dpt-field > span, .dpt-label { color: var(--dpt-muted); font-size: 12px; line-height: 18px; font-weight: 500; }
|
|
408
|
+
.dpt-meta dd, .dpt-message-text, .dpt-muted { min-width: 0; overflow-wrap: anywhere; }
|
|
409
|
+
.dpt-muted, .dpt-summary { color: var(--dpt-muted); font-size: 12px; line-height: 18px; }
|
|
410
|
+
.dpt, .dpt-modal { font-variant-numeric: tabular-nums; }
|
|
411
|
+
.dpt .dpt-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 18px; }
|
|
412
|
+
@media (pointer: coarse) { .dpt :is(input, select, textarea), .dpt :is(input, textarea).dpt-mono { font-size: 16px; } }
|
|
413
|
+
.dpt-empty { padding: 14px 16px; }
|
|
414
|
+
.dpt-empty-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
|
|
415
|
+
.dpt-scroll-box { max-height: 220px; overflow-y: auto; padding-inline-end: 4px; }
|
|
416
|
+
.dpt-repo-scroll { max-height: 420px; overflow-y: auto; padding-inline-end: 4px; }
|
|
417
|
+
.dpt-message {
|
|
418
|
+
display: flex; align-items: start; gap: 8px; padding: 5px 10px; min-width: 0;
|
|
419
|
+
border-radius: var(--dsw-radius-sm, 7px);
|
|
420
|
+
background: color-mix(in srgb, var(--dpt-entry) 70%, var(--dpt-module));
|
|
421
|
+
}
|
|
422
|
+
.dpt-message-text { flex: 1; padding-block: 2px; font-size: 12px; line-height: 18px; }
|
|
423
|
+
.dpt-message [role='alert'] { color: var(--dpt-danger); }
|
|
424
|
+
.dpt .dpt-close { width: 22px; min-height: 22px; padding: 0; flex: 0 0 auto; color: var(--dpt-muted); }
|
|
425
|
+
.dpt-actions { justify-content: flex-end; gap: 6px; }
|
|
426
|
+
.dpt-path { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 10px; }
|
|
427
|
+
.dpt-path code { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
|
|
428
|
+
.dpt .dpt-copy { width: 76px; min-width: 76px; min-height: 26px; font-size: 12px; }
|
|
429
|
+
.dpt .dpt-copy[data-copied] { color: var(--dsw-alias-state-success-primary); }
|
|
430
|
+
.dpt-form { display: grid; gap: 10px; }
|
|
431
|
+
.dpt-edit { display: grid; gap: 10px; min-width: 0; }
|
|
432
|
+
.dpt-field { display: grid; gap: 4px; min-width: 0; }
|
|
433
|
+
.dpt-field textarea { width: 100%; resize: vertical; }
|
|
434
|
+
.dpt-field textarea.dpt-fixed-editor { height: 180px; resize: none; overflow-y: auto; }
|
|
435
|
+
.dpt-form-row .dpt-field { flex: 1 1 180px; }
|
|
436
|
+
.dpt ul.dpt-repo-skills { list-style: none; display: grid; gap: 0; padding: 0; border-top: .5px solid var(--dpt-line); }
|
|
437
|
+
.dpt-repo-skill { padding: 10px 0; display: grid; gap: 6px; min-width: 0; }
|
|
438
|
+
.dpt-repo-skill + .dpt-repo-skill { border-top: .5px solid var(--dpt-line); }
|
|
439
|
+
.dpt-argument-row { display: flex; gap: 6px; min-width: 0; }
|
|
440
|
+
.dpt-argument-row input { flex: 1 1 0; }
|
|
441
|
+
.dpt-check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; }
|
|
442
|
+
.dpt-check input[type='checkbox'] { accent-color: var(--dpt-accent); cursor: pointer; }
|
|
443
|
+
.dpt-tool-list { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
444
|
+
.dpt-tool-chip {
|
|
445
|
+
padding: 1px 7px; border-radius: 5px; border: .5px solid var(--dpt-line);
|
|
446
|
+
background: var(--dpt-entry); color: var(--dsw-alias-label-primary);
|
|
447
|
+
}
|
|
448
|
+
.dpt-file-list { list-style: none; display: grid; gap: 4px; padding: 0; margin: 0; }
|
|
449
|
+
.dpt-file-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--dpt-muted); }
|
|
450
|
+
.dpt-modal {
|
|
451
|
+
width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
|
|
452
|
+
border: .5px solid var(--dpt-line); border-radius: var(--dsw-radius-lg, 14px);
|
|
453
|
+
color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1); padding: 20px;
|
|
454
|
+
}
|
|
455
|
+
.dpt-modal::backdrop { background: var(--dsw-alias-bg-mask-1, rgb(0 0 0 / 24%)); }
|
|
456
|
+
.dpt-review { width: min(700px, calc(100vw - 32px)); }
|
|
457
|
+
.dpt-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
|
|
458
|
+
.dpt-confirm-list { display: grid; gap: 8px; }
|
|
459
|
+
.dpt-confirm-list > section { padding: 8px 10px; border-radius: var(--dsw-radius-sm, 8px); background: var(--dpt-module); }
|
|
460
|
+
.dpt-confirm-list ul { padding-inline-start: 18px; }
|
|
461
|
+
.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; }
|
|
462
|
+
.dpt-composer { display: inline-flex; gap: 6px; align-items: center; container-type: normal; }
|
|
463
|
+
.dpt-composer-action--fallback {
|
|
464
|
+
display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0;
|
|
465
|
+
border: 0; border-radius: 50%; corner-shape: round;
|
|
466
|
+
cursor: pointer; transition: background-color 100ms ease;
|
|
467
|
+
}
|
|
468
|
+
.dpt .dpt-composer-action {
|
|
469
|
+
background: var(--dsw-specific-selector);
|
|
470
|
+
color: var(--dsw-alias-label-primary);
|
|
471
|
+
}
|
|
472
|
+
.dpt .dpt-composer-action:disabled { opacity: 1; cursor: default; }
|
|
473
|
+
.dpt-composer-action:disabled svg { opacity: .4; }
|
|
474
|
+
.dpt-composer-action.dpt-composer-undo {
|
|
475
|
+
background: var(--dsw-alias-button-tool-bar-fill);
|
|
476
|
+
color: var(--dsw-alias-label-secondary);
|
|
477
|
+
}
|
|
478
|
+
@media (hover: hover) {
|
|
479
|
+
.dpt .dpt-composer-action:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-solid); }
|
|
480
|
+
.dpt .dpt-composer-action.dpt-composer-undo:hover {
|
|
481
|
+
background: var(--dsw-alias-button-tool-bar-hover);
|
|
482
|
+
color: var(--dsw-alias-label-primary);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
.dpt-composer .dpt-message { font-size: 11px; max-width: 180px; padding: 2px 6px; }
|
|
486
|
+
@container (max-width: 560px) {
|
|
487
|
+
.dpt .dpt-search, .dpt-bar > input[type='search'] { flex: 1 1 100%; width: 100%; }
|
|
488
|
+
.dpt-toolbar-right { justify-content: flex-start; width: 100%; }
|
|
489
|
+
.dpt-quick-actions--hover { display: none; }
|
|
490
|
+
.dpt-summary { white-space: normal; overflow-wrap: anywhere; }
|
|
491
|
+
.dpt-row-summary { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
|
|
492
|
+
.dpt-actions { row-gap: 4px; }
|
|
493
|
+
.dpt-drawer { padding: 10px 12px 12px 12px; }
|
|
494
|
+
.dpt-floating-batch { border-radius: var(--dsw-radius-md, 10px); }
|
|
495
|
+
}
|
|
496
|
+
@media (prefers-reduced-motion: reduce) {
|
|
497
|
+
.dpt button, .dpt-chevron, .dpt-composer-action, .dpt-switch, .dpt-switch-thumb { transition: none; }
|
|
498
|
+
.dpt-spin { animation: none; }
|
|
499
|
+
}
|
|
500
|
+
`
|
|
501
|
+
|
|
502
|
+
async function request(feature, payload = {}, signal) {
|
|
503
|
+
const response = await fetch('api/dsh-powertools', {
|
|
504
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
505
|
+
body: JSON.stringify({ feature, ...payload }), signal,
|
|
506
|
+
})
|
|
507
|
+
const value = await response.json().catch(() => null)
|
|
508
|
+
if (!response.ok || !value) throw new Error(value?.error ?? '无法连接 DSH 工具箱。')
|
|
509
|
+
return value
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const button = (text, click, { className = '', icon, iconSize = 14, iconClass = '', ...props } = {}) => h(Button, {
|
|
513
|
+
size: 'sm', onClick: click, ...props, className: `dpt-button ${className}`,
|
|
514
|
+
}, icon && h(Icon, { name: icon, size: iconSize, className: iconClass }), text)
|
|
515
|
+
const primary = (text, click, props) => button(text, click, { variant: 'primary', className: 'dpt-primary', ...props })
|
|
516
|
+
const iconButton = (label, icon, click, { className = '', iconSize = 14, iconClass = '', ...props } = {}) => button('', click, {
|
|
517
|
+
icon, iconSize, iconClass, className: `dpt-icon-btn ${className}`, 'aria-label': label, title: props.title ?? label, ...props,
|
|
518
|
+
})
|
|
519
|
+
const option = (value, text) => h('option', { key: value, value }, text)
|
|
520
|
+
const field = (label, control) => h('label', { className: 'dpt-field' }, h('span', null, label), control)
|
|
521
|
+
const muted = (text, props) => h('p', { className: 'dpt-muted', ...props }, text)
|
|
522
|
+
const code = text => h('code', { className: 'dpt-mono', dir: 'ltr' }, text)
|
|
523
|
+
const filterInput = (label, value, set, className = 'dpt-search') => h('input', {
|
|
524
|
+
type: 'search', className, 'aria-label': label, placeholder: label, value,
|
|
525
|
+
onChange: e => set(e.target.value),
|
|
526
|
+
onKeyDown: e => { if (e.key === 'Escape' && value) { e.preventDefault(); set('') } },
|
|
527
|
+
})
|
|
528
|
+
const pick = (label, value, set, options) => h('select', { 'aria-label': label, value, onChange: e => set(e.target.value) }, options)
|
|
529
|
+
const feedback = (message, error, dismiss) => message && h('div', { className: 'dpt-message' },
|
|
530
|
+
h('div', { className: 'dpt-message-text', role: error ? 'alert' : 'status' }, message),
|
|
531
|
+
dismiss && button('', dismiss, { icon: 'x', iconSize: 13, className: 'dpt-close', 'aria-label': '关闭反馈' }))
|
|
532
|
+
const matches = (query, ...values) => values.some(value => value?.toLowerCase().includes(query.trim().toLowerCase()))
|
|
533
|
+
const formatBytes = bytes => {
|
|
534
|
+
if (!Number.isFinite(bytes)) return ''
|
|
535
|
+
if (bytes < 1024) return `${bytes} B`
|
|
536
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB`
|
|
537
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`
|
|
538
|
+
}
|
|
539
|
+
const formatShortTime = ts => {
|
|
540
|
+
if (!ts || !Number.isFinite(ts) || ts <= 0) return ''
|
|
541
|
+
const date = new Date(ts)
|
|
542
|
+
const now = new Date()
|
|
543
|
+
const sameDay = date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()
|
|
544
|
+
const hm = `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
|
545
|
+
if (sameDay) return `今天 ${hm}`
|
|
546
|
+
const md = `${date.getMonth() + 1}/${date.getDate()}`
|
|
547
|
+
return date.getFullYear() === now.getFullYear() ? `${md} ${hm}` : `${date.getFullYear()}/${md}`
|
|
548
|
+
}
|
|
549
|
+
const identity = value => value
|
|
550
|
+
const workspaceTitle = workspace => workspace.title === 'default-workspace' ? '默认工作区' : workspace.title
|
|
551
|
+
|
|
552
|
+
function Segmented({ label, value, onChange, items }) {
|
|
553
|
+
return h('div', { className: 'dpt-seg', role: 'group', 'aria-label': label }, items.map(item =>
|
|
554
|
+
h('button', {
|
|
555
|
+
key: item.value, type: 'button', className: 'dpt-seg-btn',
|
|
556
|
+
'aria-pressed': value === item.value,
|
|
557
|
+
'data-alert': item.alert || undefined,
|
|
558
|
+
onClick: () => onChange(item.value),
|
|
559
|
+
},
|
|
560
|
+
h('span', null, item.label),
|
|
561
|
+
item.count !== undefined && item.count !== null && h('span', { className: 'dpt-seg-count' }, item.count))))
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function Switch({ checked, onChange, label, disabled }) {
|
|
565
|
+
return h('button', {
|
|
566
|
+
type: 'button', role: 'switch', className: 'dpt-switch',
|
|
567
|
+
'aria-checked': Boolean(checked), 'aria-label': label, title: label, disabled,
|
|
568
|
+
onClick: e => { e.stopPropagation(); onChange(!checked) },
|
|
569
|
+
}, h('span', { className: 'dpt-switch-thumb', 'aria-hidden': true }))
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function useToast() {
|
|
573
|
+
const [toast, setToast] = useState(null)
|
|
574
|
+
const [hovered, setHovered] = useState(false)
|
|
575
|
+
useEffect(() => {
|
|
576
|
+
if (!toast || toast.error || hovered) return
|
|
577
|
+
const duration = toast.sticky ? 8000 : 2600
|
|
578
|
+
const timer = setTimeout(() => setToast(null), duration)
|
|
579
|
+
return () => clearTimeout(timer)
|
|
580
|
+
}, [toast, hovered])
|
|
581
|
+
const show = (content, { error = false, sticky = false } = {}) => {
|
|
582
|
+
if (!content) { setToast(null); return }
|
|
583
|
+
setToast({ id: Date.now() + Math.random(), content, error, sticky })
|
|
584
|
+
}
|
|
585
|
+
const node = toast && h('div', {
|
|
586
|
+
className: 'dpt-toast', 'data-error': toast.error || undefined,
|
|
587
|
+
onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false),
|
|
588
|
+
},
|
|
589
|
+
h('div', { className: 'dpt-toast-body', role: toast.error ? 'alert' : 'status' }, toast.content),
|
|
590
|
+
button('', () => setToast(null), { icon: 'x', iconSize: 13, className: 'dpt-close', 'aria-label': '关闭提示' }))
|
|
591
|
+
return { show, dismiss: () => setToast(null), node }
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function useInfiniteScroll(total, resetKey, step = 50) {
|
|
595
|
+
const [state, setState] = useState({ key: resetKey, limit: step })
|
|
596
|
+
const sentinelRef = useRef(null)
|
|
597
|
+
const limit = state.key === resetKey ? state.limit : step
|
|
598
|
+
const hasMore = total > limit
|
|
599
|
+
useEffect(() => {
|
|
600
|
+
if (state.key !== resetKey) setState({ key: resetKey, limit: step })
|
|
601
|
+
}, [resetKey, step, state.key])
|
|
602
|
+
useEffect(() => {
|
|
603
|
+
const node = sentinelRef.current
|
|
604
|
+
if (!node || !hasMore || typeof IntersectionObserver === 'undefined') return
|
|
605
|
+
const observer = new IntersectionObserver(entries => {
|
|
606
|
+
if (entries.some(entry => entry.isIntersecting)) {
|
|
607
|
+
setState(previous => ({
|
|
608
|
+
key: resetKey,
|
|
609
|
+
limit: Math.min(total, (previous.key === resetKey ? previous.limit : step) + step),
|
|
610
|
+
}))
|
|
611
|
+
}
|
|
612
|
+
}, { rootMargin: '360px 0px' })
|
|
613
|
+
observer.observe(node)
|
|
614
|
+
return () => observer.disconnect()
|
|
615
|
+
}, [hasMore, limit, resetKey, step, total])
|
|
616
|
+
return {
|
|
617
|
+
limit,
|
|
618
|
+
hasMore,
|
|
619
|
+
sentinel: hasMore && h('li', { ref: sentinelRef, className: 'dpt-sentinel', 'aria-hidden': true }),
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function PanelSection({ title, summary, toolbar, children }) {
|
|
624
|
+
return h('section', { 'aria-label': title },
|
|
625
|
+
h('header', { className: 'dpt-heading' }, h('h3', null, title),
|
|
626
|
+
summary && h('p', { className: 'dpt-summary' }, summary)),
|
|
627
|
+
h('div', { className: 'dpt-section-body' }, toolbar, children))
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const empty = (message, onReset) => h('div', { className: `dpt-card dpt-empty${onReset ? ' dpt-empty-row' : ''}` },
|
|
631
|
+
muted(message, { role: 'status' }),
|
|
632
|
+
onReset && button('重置筛选', onReset, { icon: 'x', iconSize: 13 }))
|
|
633
|
+
const facts = entries => h('dl', { className: 'dpt-meta' }, entries.map(([label, value]) =>
|
|
634
|
+
h(React.Fragment, { key: label }, h('dt', null, label), h('dd', null, value))))
|
|
635
|
+
const pill = (text, tone = 'idle', id) => h('span', { id, className: 'dpt-pill', 'data-tone': tone }, text)
|
|
636
|
+
|
|
637
|
+
function useHostStatus() {
|
|
638
|
+
const [state, setState] = useState({ loading: true })
|
|
639
|
+
const active = useRef(null)
|
|
640
|
+
async function check() {
|
|
641
|
+
active.current?.abort()
|
|
642
|
+
const controller = new AbortController()
|
|
643
|
+
active.current = controller
|
|
644
|
+
setState(previous => ({ ...previous, loading: true, error: '' }))
|
|
645
|
+
try {
|
|
646
|
+
const info = await request('capabilities', {}, controller.signal)
|
|
647
|
+
if (!controller.signal.aborted) setState({ info })
|
|
648
|
+
} catch (error) {
|
|
649
|
+
if (!controller.signal.aborted) setState(previous => ({ ...previous, loading: false, error: error.message, failed: true }))
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
useEffect(() => {
|
|
653
|
+
void check()
|
|
654
|
+
return () => active.current?.abort()
|
|
655
|
+
}, [])
|
|
656
|
+
return { ...state, check, dismiss: () => setState(previous => ({ ...previous, error: '' })) }
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function PathLine({ value, label = '路径' }) {
|
|
660
|
+
const [copied, setCopied] = useState(false)
|
|
661
|
+
const [error, setError] = useState('')
|
|
662
|
+
const timer = useRef(null)
|
|
663
|
+
useEffect(() => () => clearTimeout(timer.current), [])
|
|
664
|
+
async function copy() {
|
|
665
|
+
clearTimeout(timer.current)
|
|
666
|
+
setError('')
|
|
667
|
+
try {
|
|
668
|
+
if (!await writeClipboard(value)) throw new Error('clipboard unavailable')
|
|
669
|
+
setCopied(true)
|
|
670
|
+
timer.current = setTimeout(() => setCopied(false), 1800)
|
|
671
|
+
} catch {
|
|
672
|
+
setCopied(false)
|
|
673
|
+
setError('无法访问剪贴板。可以选择并复制路径。')
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return h(React.Fragment, null, h('div', { className: 'dpt-path' }, code(value),
|
|
677
|
+
button(copied ? '已复制' : '复制', copy, {
|
|
678
|
+
icon: copied ? 'check' : 'copy', iconSize: 12,
|
|
679
|
+
className: 'dpt-copy', 'data-copied': copied || undefined,
|
|
680
|
+
'aria-label': copied ? `已复制${label}` : `复制${label}`,
|
|
681
|
+
})),
|
|
682
|
+
feedback(error, true, () => setError('')))
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function DisclosureRow({
|
|
686
|
+
title, tag, chips, detail, badge, tone = 'idle', expanded, onToggle,
|
|
687
|
+
selectable, quickActions, alwaysActions, children, ...props
|
|
688
|
+
}) {
|
|
689
|
+
const id = React.useId()
|
|
690
|
+
const descriptions = [tag && `${id}-tag`, detail && `${id}-detail`, badge && `${id}-status`].filter(Boolean).join(' ')
|
|
691
|
+
return h('li', {
|
|
692
|
+
className: 'dpt-row', 'data-open': expanded || undefined,
|
|
693
|
+
'data-selected': selectable?.checked || undefined, ...props,
|
|
694
|
+
},
|
|
695
|
+
h('div', { className: 'dpt-row-main' },
|
|
696
|
+
selectable && h('label', {
|
|
697
|
+
className: 'dpt-lead-cell',
|
|
698
|
+
onClick: e => e.stopPropagation(),
|
|
699
|
+
},
|
|
700
|
+
h('span', { className: 'dpt-indicator', 'data-tone': tone, 'aria-hidden': true }),
|
|
701
|
+
h('input', {
|
|
702
|
+
type: 'checkbox', className: 'dpt-row-checkbox',
|
|
703
|
+
checked: selectable.checked, 'aria-label': selectable.label,
|
|
704
|
+
onChange: e => selectable.onChange(e.target.checked, Boolean(e.nativeEvent?.shiftKey)),
|
|
705
|
+
})),
|
|
706
|
+
h('button', {
|
|
707
|
+
type: 'button', className: 'dpt-disclosure', onClick: onToggle,
|
|
708
|
+
'aria-label': title, 'aria-expanded': expanded, 'aria-controls': id,
|
|
709
|
+
'aria-describedby': descriptions || undefined,
|
|
710
|
+
},
|
|
711
|
+
!selectable && h('span', { className: 'dpt-indicator', 'data-tone': tone, 'aria-hidden': true }),
|
|
712
|
+
h('span', { className: 'dpt-row-label' },
|
|
713
|
+
h('span', { className: 'dpt-row-title' },
|
|
714
|
+
h('strong', { className: 'dpt-ellipsis', dir: 'auto' }, title),
|
|
715
|
+
tag && h('span', { id: `${id}-tag`, className: 'dpt-row-tag dpt-mono', dir: 'ltr' }, tag),
|
|
716
|
+
chips),
|
|
717
|
+
detail && h('span', { id: `${id}-detail`, className: 'dpt-muted dpt-ellipsis dpt-row-summary', dir: 'auto' }, detail))),
|
|
718
|
+
h('div', { className: 'dpt-row-end' },
|
|
719
|
+
quickActions && h('div', { className: 'dpt-quick-actions dpt-quick-actions--hover' }, quickActions),
|
|
720
|
+
alwaysActions && h('div', { className: 'dpt-quick-actions' }, alwaysActions),
|
|
721
|
+
h('span', { className: 'dpt-row-toggle-tail', onClick: onToggle, 'aria-hidden': true },
|
|
722
|
+
badge && pill(badge, tone, `${id}-status`),
|
|
723
|
+
h('span', { className: 'dpt-chevron' }, h(IconChevronRightOutlineRegular, { size: 16 }))))),
|
|
724
|
+
h('div', { id, hidden: !expanded, className: 'dpt-drawer' }, expanded && children))
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function useDisclosure() {
|
|
728
|
+
const [choices, setChoices] = useState(() => new Map())
|
|
729
|
+
const bind = (key, initial = false) => {
|
|
730
|
+
const expanded = choices.get(key) ?? initial
|
|
731
|
+
return {
|
|
732
|
+
expanded,
|
|
733
|
+
open: () => setChoices(previous => new Map(previous).set(key, true)),
|
|
734
|
+
onToggle: () => setChoices(previous => new Map(previous).set(key, !expanded)),
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
bind.isOpen = (key, initial = false) => choices.get(key) ?? initial
|
|
738
|
+
bind.collapseAll = keys => setChoices(previous => {
|
|
739
|
+
const next = new Map(previous)
|
|
740
|
+
for (const key of keys) next.set(key, false)
|
|
741
|
+
return next
|
|
742
|
+
})
|
|
743
|
+
return bind
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function Modal({ title, close, review = false, children }) {
|
|
747
|
+
const dialog = useRef(null)
|
|
748
|
+
const heading = React.useId()
|
|
749
|
+
useLayoutEffect(() => {
|
|
750
|
+
const node = dialog.current
|
|
751
|
+
node.showModal()
|
|
752
|
+
return () => node.close()
|
|
753
|
+
}, [])
|
|
754
|
+
return h('dialog', {
|
|
755
|
+
ref: dialog, className: `dpt dpt-modal${review ? ' dpt-review' : ''}`, 'aria-labelledby': heading,
|
|
756
|
+
onCancel: e => { e.preventDefault(); close() },
|
|
757
|
+
},
|
|
758
|
+
h('style', null, css),
|
|
759
|
+
h('header', { className: 'dpt-modal-head' }, h('h2', { id: heading }, title), button('关闭', close, { icon: 'x', iconSize: 13 })), children)
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function useAction() {
|
|
763
|
+
const [status, setStatus] = useState({ busy: false })
|
|
764
|
+
const active = useRef(false)
|
|
765
|
+
async function run(operation) {
|
|
766
|
+
if (active.current) return
|
|
767
|
+
active.current = true
|
|
768
|
+
setStatus({ busy: true })
|
|
769
|
+
try {
|
|
770
|
+
const message = await operation()
|
|
771
|
+
setStatus({ busy: false, message })
|
|
772
|
+
return message
|
|
773
|
+
} catch (error) {
|
|
774
|
+
setStatus({ busy: false, message: error.message || '操作未完成。', error: true })
|
|
775
|
+
return undefined
|
|
776
|
+
} finally { active.current = false }
|
|
777
|
+
}
|
|
778
|
+
const dismiss = () => setStatus(previous => ({ busy: previous.busy }))
|
|
779
|
+
return [status, run, dismiss]
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function useHostSessions(sessionVersion, hostInfo) {
|
|
783
|
+
const [items, setItems] = useState(null)
|
|
784
|
+
const [error, setError] = useState('')
|
|
785
|
+
const [reloading, setReloading] = useState(false)
|
|
786
|
+
const generation = useRef(0)
|
|
787
|
+
async function reload(signal) {
|
|
788
|
+
const current = ++generation.current
|
|
789
|
+
setReloading(true)
|
|
790
|
+
try {
|
|
791
|
+
const { sessions } = await request('sessions', { action: 'list' }, signal)
|
|
792
|
+
if (current === generation.current && !signal?.aborted) { setItems(sessions); setError('') }
|
|
793
|
+
} catch (err) {
|
|
794
|
+
if (current === generation.current && !signal?.aborted) {
|
|
795
|
+
const staleHost = hostInfo && hostInfo.sessionDelete === false
|
|
796
|
+
setError(staleHost ? 'DSH 宿主仍在运行旧版插件代码,请完全退出并重启 DSH 后生效。' : err.message)
|
|
797
|
+
}
|
|
798
|
+
} finally {
|
|
799
|
+
if (current === generation.current) setReloading(false)
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
useEffect(() => {
|
|
803
|
+
const abort = new AbortController()
|
|
804
|
+
void reload(abort.signal)
|
|
805
|
+
return () => { abort.abort(); generation.current++ }
|
|
806
|
+
}, [sessionVersion, hostInfo?.sessionDelete])
|
|
807
|
+
return { items, error, reloading, reload, dismissError: () => setError('') }
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
function subagentLabel(item) {
|
|
811
|
+
const parts = ['子 Agent']
|
|
812
|
+
if (item.agentPreset) parts.push(item.agentPreset)
|
|
813
|
+
if (item.delegationDepth) parts.push(`L${item.delegationDepth}`)
|
|
814
|
+
return parts.join(' · ')
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function SessionRow({
|
|
818
|
+
row, id, title, workspaces, isArchived, subagents, totalBytes, navigation, onArchived, onDeleted,
|
|
819
|
+
notify, disclosure, selectable,
|
|
820
|
+
}) {
|
|
821
|
+
const [status, run, dismiss] = useAction()
|
|
822
|
+
const [removal, setRemoval] = useState(false)
|
|
823
|
+
const [showAllSubagents, setShowAllSubagents] = useState(false)
|
|
824
|
+
async function archive() {
|
|
825
|
+
await run(async () => {
|
|
826
|
+
try {
|
|
827
|
+
if (isArchived) await navigation.unarchiveSession(id)
|
|
828
|
+
else await navigation.archiveSession(id, { stopActivity: false })
|
|
829
|
+
} catch (error) {
|
|
830
|
+
if (error.rpcError?.code === 'workspace/session-active') throw new Error('会话仍有运行中的工作。停止后可归档。')
|
|
831
|
+
throw error
|
|
832
|
+
}
|
|
833
|
+
onArchived(isArchived ? '会话已恢复' : '会话已归档')
|
|
834
|
+
})
|
|
835
|
+
}
|
|
836
|
+
const timeSummary = formatShortTime(row.updatedAt || row.createdAt)
|
|
837
|
+
const sizeSummary = totalBytes !== null ? formatBytes(totalBytes) : ''
|
|
838
|
+
const detailParts = [
|
|
839
|
+
row.isSubagent ? (row.orphanSubagent ? '孤儿子会话(父会话已移除)' : `隶属 ${row.parentSessionId}`) : (workspaces.map(workspaceTitle).join('、') || '未分组'),
|
|
840
|
+
sizeSummary,
|
|
841
|
+
timeSummary,
|
|
842
|
+
].filter(Boolean)
|
|
843
|
+
const badge = row.running ? '运行中' : row.isSubagent ? '子 Agent' : isArchived ? '已归档' : undefined
|
|
844
|
+
const tone = row.running ? 'info' : row.isSubagent ? 'attention' : 'idle'
|
|
845
|
+
const removedItems = [
|
|
846
|
+
`${row.isSubagent ? '子 Agent 会话' : '会话'}「${title}」(${id})`,
|
|
847
|
+
...(subagents.length > 0 ? [
|
|
848
|
+
`关联的 ${subagents.length} 条子 Agent 会话记录:` + subagents.slice(0, 6).map(item => item.id).join('、') + (subagents.length > 6 ? ` 等共 ${subagents.length} 条` : ''),
|
|
849
|
+
] : []),
|
|
850
|
+
]
|
|
851
|
+
const visibleSubagents = showAllSubagents ? subagents : subagents.slice(0, 6)
|
|
852
|
+
const activeTime = row.updatedAt || row.createdAt
|
|
853
|
+
const deleteHint = row.deletable
|
|
854
|
+
? (subagents.length > 0 ? `关联删除(含 ${subagents.length} 条子会话)` : '删除会话')
|
|
855
|
+
: (row.deleteReason || '当前不可删除')
|
|
856
|
+
|
|
857
|
+
const quickActions = h(React.Fragment, null,
|
|
858
|
+
!row.isSubagent && button('打开', () => run(() => navigation.openSession(id)), {
|
|
859
|
+
icon: 'external-link', iconSize: 13, className: 'dpt-row-btn', disabled: status.busy,
|
|
860
|
+
'aria-label': `打开 ${title}`,
|
|
861
|
+
}),
|
|
862
|
+
!row.isSubagent && iconButton(
|
|
863
|
+
`${isArchived ? '恢复' : '归档'} ${title}`,
|
|
864
|
+
isArchived ? 'archive-restore' : 'archive',
|
|
865
|
+
archive,
|
|
866
|
+
{ className: 'dpt-row-icon-btn', iconSize: 13, title: isArchived ? '恢复会话' : '归档会话', disabled: status.busy || (!isArchived && row.running) },
|
|
867
|
+
),
|
|
868
|
+
iconButton(
|
|
869
|
+
`删除 ${title}`,
|
|
870
|
+
'trash',
|
|
871
|
+
() => setRemoval(true),
|
|
872
|
+
{ className: 'dpt-row-icon-btn dpt-danger', iconSize: 13, title: deleteHint, disabled: status.busy || !row.deletable },
|
|
873
|
+
))
|
|
874
|
+
|
|
875
|
+
return h(DisclosureRow, {
|
|
876
|
+
'data-session-id': id, 'data-session-kind': row.isSubagent ? 'subagent' : 'session',
|
|
877
|
+
title,
|
|
878
|
+
tag: row.isSubagent ? (row.agentPreset || (row.delegationDepth ? `L${row.delegationDepth}` : undefined)) : undefined,
|
|
879
|
+
chips: subagents.length > 0 ? pill(`${subagents.length} 子会话`) : undefined,
|
|
880
|
+
detail: detailParts.join(' · '), badge, tone, selectable, quickActions, ...disclosure,
|
|
881
|
+
},
|
|
882
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
883
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
884
|
+
h('span', null, '会话 ID', code(id)),
|
|
885
|
+
row.isSubagent && row.parentSessionId && h('span', null, '父会话', code(row.parentSessionId)),
|
|
886
|
+
activeTime > 0 && h('span', null, row.updatedAt > 0 ? '更新' : '创建', h('strong', null, new Date(activeTime).toLocaleString())),
|
|
887
|
+
totalBytes !== null && h('span', null, '大小', h('strong', null,
|
|
888
|
+
subagents.length > 0 && Number.isFinite(row.sizeBytes) && totalBytes > row.sizeBytes
|
|
889
|
+
? `${formatBytes(totalBytes)}(主会话 ${formatBytes(row.sizeBytes)})`
|
|
890
|
+
: formatBytes(totalBytes)))),
|
|
891
|
+
h('div', { className: 'dpt-actions' },
|
|
892
|
+
!row.isSubagent && button('打开', () => run(() => navigation.openSession(id)), { icon: 'external-link', disabled: status.busy }),
|
|
893
|
+
!row.isSubagent && button(isArchived ? '恢复' : '归档', archive, { icon: isArchived ? 'archive-restore' : 'archive', disabled: status.busy || (!isArchived && row.running) }),
|
|
894
|
+
button(subagents.length > 0 ? `关联删除(${subagents.length + 1})` : '删除', () => setRemoval(true), {
|
|
895
|
+
icon: 'trash', className: 'dpt-danger', disabled: status.busy || !row.deletable, title: deleteHint,
|
|
896
|
+
}))),
|
|
897
|
+
row.cwd && h(PathLine, { value: row.cwd }),
|
|
898
|
+
subagents.length > 0 && h('div', { className: 'dpt-drawer-split' },
|
|
899
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
900
|
+
h('span', { className: 'dpt-label' }, `关联子 Agent 会话(${subagents.length})· 删除主会话时自动一并清理`),
|
|
901
|
+
subagents.length > 6 && button(showAllSubagents ? '收起列表' : `展开全部 ${subagents.length} 条`, () => setShowAllSubagents(!showAllSubagents))),
|
|
902
|
+
h('ul', { className: `dpt-file-list${showAllSubagents && subagents.length > 8 ? ' dpt-scroll-box' : ''}` }, visibleSubagents.map(child =>
|
|
903
|
+
h('li', { key: child.id, 'data-subagent-id': child.id },
|
|
904
|
+
h('span', null, subagentLabel(child), ' ', code(child.id)),
|
|
905
|
+
h('span', null, [
|
|
906
|
+
child.running ? '运行中' : child.resident ? '打开中' : '',
|
|
907
|
+
Number.isFinite(child.sizeBytes) ? formatBytes(child.sizeBytes) : '',
|
|
908
|
+
].filter(Boolean).join(' · ') || '已落盘'))))),
|
|
909
|
+
!row.deletable && row.deleteReason && muted(row.deleteReason),
|
|
910
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
911
|
+
removal && h(Confirm, {
|
|
912
|
+
title: `删除 ${title}`,
|
|
913
|
+
label: subagents.length > 0 ? `确认关联删除(${subagents.length + 1} 条)` : '确认删除会话',
|
|
914
|
+
removed: removedItems,
|
|
915
|
+
preserved: ['工作区目录及所有项目文件', '其他无关会话与独立分支会话', 'Profile 恢复目录中的会话备份(含 manifest.json)'],
|
|
916
|
+
close: () => setRemoval(false),
|
|
917
|
+
confirm: async () => {
|
|
918
|
+
const result = await request('sessions', { action: 'delete', sessionId: id, confirm: id })
|
|
919
|
+
setRemoval(false)
|
|
920
|
+
await onDeleted(result)
|
|
921
|
+
},
|
|
922
|
+
}))
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
function SessionPanel({ sessionList, workspaceList, navigation, refresh, host, toast }) {
|
|
926
|
+
const [query, search] = useState('')
|
|
927
|
+
const [workspace, selectWorkspace] = useState('all')
|
|
928
|
+
const [viewMode, setViewMode] = useState('active')
|
|
929
|
+
const [sortBy, setSortBy] = useState('recent')
|
|
930
|
+
const [selectedIds, setSelectedIds] = useState(() => new Set())
|
|
931
|
+
const [batchRemoval, setBatchRemoval] = useState(false)
|
|
932
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
933
|
+
const [status, run, dismiss] = useAction()
|
|
934
|
+
const lastClickedIndex = useRef(-1)
|
|
935
|
+
const disclosure = useDisclosure()
|
|
936
|
+
const hostSessions = useHostSessions(`${sessionList.ids.length}:${workspaceList.archivedSessionIds.length}`, host.info)
|
|
937
|
+
const archived = new Set(workspaceList.archivedSessionIds)
|
|
938
|
+
const groups = new Map()
|
|
939
|
+
for (const item of workspaceList.items) for (const id of item.sessionIds) {
|
|
940
|
+
groups.set(id, [...(groups.get(id) ?? []), item])
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
const mergedById = new Map()
|
|
944
|
+
for (const id of sessionList.ids) {
|
|
945
|
+
const clientRow = sessionList.byId[id]
|
|
946
|
+
mergedById.set(id, {
|
|
947
|
+
id,
|
|
948
|
+
title: clientRow.title || (clientRow.displayTitle !== id && clientRow.displayTitle) || '未命名会话',
|
|
949
|
+
cwd: clientRow.cwd ?? '',
|
|
950
|
+
updatedAt: clientRow.updatedAt ?? 0,
|
|
951
|
+
createdAt: 0,
|
|
952
|
+
running: Boolean(clientRow.running),
|
|
953
|
+
isSubagent: false,
|
|
954
|
+
orphanSubagent: false,
|
|
955
|
+
parentSessionId: null,
|
|
956
|
+
descendantSubagentIds: [],
|
|
957
|
+
sizeBytes: null,
|
|
958
|
+
deletable: false,
|
|
959
|
+
deleteReason: '正在核对会话持久化状态…',
|
|
960
|
+
workspaces: groups.get(id) ?? [],
|
|
961
|
+
})
|
|
962
|
+
}
|
|
963
|
+
for (const hRow of hostSessions.items ?? []) {
|
|
964
|
+
const existing = mergedById.get(hRow.id)
|
|
965
|
+
const byCwd = hRow.cwd ? workspaceList.items.filter(item => item.path && item.path === hRow.cwd) : []
|
|
966
|
+
const wsList = existing?.workspaces?.length
|
|
967
|
+
? existing.workspaces
|
|
968
|
+
: (hRow.workspaces?.length
|
|
969
|
+
? hRow.workspaces
|
|
970
|
+
: (groups.get(hRow.id) ?? (hRow.rootSessionId ? groups.get(hRow.rootSessionId) : undefined) ?? byCwd))
|
|
971
|
+
const fallbackTitle = hRow.isSubagent ? subagentLabel(hRow) : '未命名会话'
|
|
972
|
+
mergedById.set(hRow.id, {
|
|
973
|
+
...(existing ?? {}),
|
|
974
|
+
...hRow,
|
|
975
|
+
title: existing?.title && existing.title !== '未命名会话' ? existing.title : fallbackTitle,
|
|
976
|
+
cwd: existing?.cwd || hRow.cwd || '',
|
|
977
|
+
updatedAt: existing?.updatedAt || hRow.createdAt || 0,
|
|
978
|
+
running: Boolean(existing?.running || hRow.running),
|
|
979
|
+
workspaces: wsList,
|
|
980
|
+
})
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
const allMerged = [...mergedById.values()]
|
|
984
|
+
const inSelectedWorkspace = row => {
|
|
985
|
+
const ws = row.workspaces ?? []
|
|
986
|
+
return workspace === 'all' || (workspace === 'none' ? ws.length === 0 : ws.some(item => item.workspaceId === workspace))
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// Counts on the segmented tabs reflect workspace filter so numbers always match what you click into.
|
|
990
|
+
const wsScoped = allMerged.filter(inSelectedWorkspace)
|
|
991
|
+
const activeCount = wsScoped.filter(item => (!item.isSubagent || item.orphanSubagent) && !archived.has(item.id)).length
|
|
992
|
+
const archivedCount = wsScoped.filter(item => !item.isSubagent && archived.has(item.id)).length
|
|
993
|
+
const subagentCount = wsScoped.filter(item => item.isSubagent).length
|
|
994
|
+
|
|
995
|
+
const rows = wsScoped.flatMap(row => {
|
|
996
|
+
const isArchived = archived.has(row.id)
|
|
997
|
+
if (viewMode === 'active') {
|
|
998
|
+
if ((row.isSubagent && !row.orphanSubagent) || isArchived) return []
|
|
999
|
+
} else if (viewMode === 'archived') {
|
|
1000
|
+
if (row.isSubagent || !isArchived) return []
|
|
1001
|
+
} else if (viewMode === 'subagent') {
|
|
1002
|
+
if (!row.isSubagent) return []
|
|
1003
|
+
}
|
|
1004
|
+
const subagents = (row.descendantSubagentIds ?? []).map(subId => mergedById.get(subId)).filter(Boolean)
|
|
1005
|
+
const subagentText = subagents.map(sub => `${sub.id} ${sub.agentPreset ?? ''}`).join(' ')
|
|
1006
|
+
if (!matches(query, row.title, row.id, row.agentPreset ?? '', subagentText)) return []
|
|
1007
|
+
const ownBytes = Number.isFinite(row.sizeBytes) ? row.sizeBytes : 0
|
|
1008
|
+
const subBytes = subagents.reduce((sum, sub) => sum + (Number.isFinite(sub.sizeBytes) ? sub.sizeBytes : 0), 0)
|
|
1009
|
+
const totalBytes = Number.isFinite(row.sizeBytes) || subagents.some(sub => Number.isFinite(sub.sizeBytes))
|
|
1010
|
+
? ownBytes + subBytes : null
|
|
1011
|
+
return [{ row, id: row.id, title: row.title, workspaces: row.workspaces ?? [], isArchived, subagents, totalBytes }]
|
|
1012
|
+
}).sort((a, b) => {
|
|
1013
|
+
const recentDiff = (b.row.updatedAt || b.row.createdAt) - (a.row.updatedAt || a.row.createdAt)
|
|
1014
|
+
if (sortBy === 'oldest') return ((a.row.createdAt || a.row.updatedAt) - (b.row.createdAt || b.row.updatedAt)) || -recentDiff
|
|
1015
|
+
if (sortBy === 'size') return ((b.totalBytes ?? -1) - (a.totalBytes ?? -1)) || recentDiff
|
|
1016
|
+
if (sortBy === 'subagents') return (b.subagents.length - a.subagents.length) || recentDiff
|
|
1017
|
+
return recentDiff
|
|
1018
|
+
})
|
|
1019
|
+
|
|
1020
|
+
const hasActiveFilter = Boolean(query.trim()) || workspace !== 'all' || sortBy !== 'recent'
|
|
1021
|
+
const resetFilters = () => { search(''); selectWorkspace('all'); setSortBy('recent') }
|
|
1022
|
+
const scroller = useInfiniteScroll(rows.length, `${viewMode}\n${query}\n${workspace}\n${sortBy}`, 50)
|
|
1023
|
+
const visibleRows = rows.slice(0, scroller.limit)
|
|
1024
|
+
const openKeys = visibleRows.filter(item => disclosure.isOpen(item.id)).map(item => item.id)
|
|
1025
|
+
|
|
1026
|
+
const selectedRows = rows.filter(item => selectedIds.has(item.id))
|
|
1027
|
+
const deletableRows = rows.filter(item => item.row.deletable)
|
|
1028
|
+
const deletableSelected = selectedRows.filter(item => item.row.deletable)
|
|
1029
|
+
const lockedSelectedCount = selectedRows.length - deletableSelected.length
|
|
1030
|
+
const archivableSelected = selectedRows.filter(item => !item.row.isSubagent && !item.isArchived && !item.row.running)
|
|
1031
|
+
const restorableSelected = selectedRows.filter(item => !item.row.isSubagent && item.isArchived)
|
|
1032
|
+
const allFilteredSelected = rows.length > 0 && selectedRows.length === rows.length
|
|
1033
|
+
|
|
1034
|
+
const cascadeTargetIds = new Set()
|
|
1035
|
+
const directDeleteSet = new Set(deletableSelected.map(item => item.id))
|
|
1036
|
+
for (const item of deletableSelected) {
|
|
1037
|
+
cascadeTargetIds.add(item.id)
|
|
1038
|
+
for (const sub of item.subagents) cascadeTargetIds.add(sub.id)
|
|
1039
|
+
}
|
|
1040
|
+
const cascadedExtraCount = [...cascadeTargetIds].filter(id => !directDeleteSet.has(id)).length
|
|
1041
|
+
|
|
1042
|
+
useEffect(() => {
|
|
1043
|
+
if (!selectedRows.length) return
|
|
1044
|
+
const onKey = e => {
|
|
1045
|
+
if (e.key === 'Escape' && !document.querySelector('dialog[open]')) {
|
|
1046
|
+
setSelectedIds(new Set())
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
window.addEventListener('keydown', onKey)
|
|
1050
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
1051
|
+
}, [selectedRows.length])
|
|
1052
|
+
|
|
1053
|
+
function toggleSelect(index, id, checked, shiftKey) {
|
|
1054
|
+
if (checked) toast.dismiss()
|
|
1055
|
+
setSelectedIds(previous => {
|
|
1056
|
+
const next = new Set(previous)
|
|
1057
|
+
if (shiftKey && lastClickedIndex.current >= 0 && lastClickedIndex.current < rows.length) {
|
|
1058
|
+
const [start, end] = [Math.min(lastClickedIndex.current, index), Math.max(lastClickedIndex.current, index)]
|
|
1059
|
+
for (let i = start; i <= end; i++) {
|
|
1060
|
+
if (checked) next.add(rows[i].id)
|
|
1061
|
+
else next.delete(rows[i].id)
|
|
1062
|
+
}
|
|
1063
|
+
} else if (checked) next.add(id)
|
|
1064
|
+
else next.delete(id)
|
|
1065
|
+
lastClickedIndex.current = index
|
|
1066
|
+
return next
|
|
1067
|
+
})
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
async function silentRefresh() {
|
|
1071
|
+
if (refreshing) return
|
|
1072
|
+
setRefreshing(true)
|
|
1073
|
+
try { await Promise.all([refresh(), hostSessions.reload()]) }
|
|
1074
|
+
finally { setRefreshing(false) }
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
async function handleDeleted(result) {
|
|
1078
|
+
await Promise.all([refresh(), hostSessions.reload()])
|
|
1079
|
+
setSelectedIds(previous => {
|
|
1080
|
+
const next = new Set(previous)
|
|
1081
|
+
for (const id of result.deletedIds ?? []) next.delete(id)
|
|
1082
|
+
return next
|
|
1083
|
+
})
|
|
1084
|
+
const total = result.deletedIds?.length ?? 1
|
|
1085
|
+
const sub = result.subagentCount ?? 0
|
|
1086
|
+
const isBatch = (result.requestedCount ?? 1) > 1
|
|
1087
|
+
toast.show(h(React.Fragment, null,
|
|
1088
|
+
h('p', null, isBatch
|
|
1089
|
+
? `已批量清理 ${total} 条会话${sub > 0 ? `(含 ${sub} 条子 Agent)` : ''}`
|
|
1090
|
+
: (sub > 0 ? `已关联删除 ${total} 条会话(含 ${sub} 条子 Agent)` : '会话已移至恢复目录')),
|
|
1091
|
+
h(PathLine, { value: result.recovery, label: '恢复目录' })), { sticky: true })
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function batchArchive(restore) {
|
|
1095
|
+
const targets = restore ? restorableSelected : archivableSelected
|
|
1096
|
+
if (!targets.length) return
|
|
1097
|
+
return run(async () => {
|
|
1098
|
+
let completed = 0
|
|
1099
|
+
for (const item of targets) {
|
|
1100
|
+
try {
|
|
1101
|
+
if (restore) await navigation.unarchiveSession(item.id)
|
|
1102
|
+
else await navigation.archiveSession(item.id, { stopActivity: false })
|
|
1103
|
+
completed++
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
if (error.rpcError?.code !== 'workspace/session-active') throw error
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
setSelectedIds(previous => {
|
|
1109
|
+
const next = new Set(previous)
|
|
1110
|
+
for (const item of targets) next.delete(item.id)
|
|
1111
|
+
return next
|
|
1112
|
+
})
|
|
1113
|
+
await hostSessions.reload()
|
|
1114
|
+
toast.show(restore ? `已恢复 ${completed} 个会话` : `已归档 ${completed} 个会话`)
|
|
1115
|
+
})
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
return h('div', { className: 'dpt-panel' },
|
|
1119
|
+
feedback(host.error, true, host.dismiss),
|
|
1120
|
+
feedback(hostSessions.error, true, hostSessions.dismissError),
|
|
1121
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1122
|
+
h('div', { className: 'dpt-toolbar' },
|
|
1123
|
+
h(Segmented, {
|
|
1124
|
+
label: '会话视图', value: viewMode,
|
|
1125
|
+
onChange: next => { setViewMode(next); setSelectedIds(new Set()); lastClickedIndex.current = -1 },
|
|
1126
|
+
items: [
|
|
1127
|
+
{ value: 'active', label: '未归档', count: sessionList.phase === 'ready' ? activeCount : null },
|
|
1128
|
+
{ value: 'archived', label: '已归档', count: sessionList.phase === 'ready' ? archivedCount : null },
|
|
1129
|
+
{ value: 'subagent', label: '子 Agent', count: hostSessions.items ? subagentCount : null },
|
|
1130
|
+
],
|
|
1131
|
+
}),
|
|
1132
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
1133
|
+
filterInput('搜索会话标题', query, search),
|
|
1134
|
+
pick('工作区', workspace, selectWorkspace, [
|
|
1135
|
+
option('all', '全部工作区'),
|
|
1136
|
+
option('none', '未分组'),
|
|
1137
|
+
...workspaceList.items.map(item => option(item.workspaceId, workspaceTitle(item))),
|
|
1138
|
+
]),
|
|
1139
|
+
pick('排序方式', sortBy, setSortBy, [
|
|
1140
|
+
option('recent', '最近活跃'),
|
|
1141
|
+
option('oldest', '最早创建'),
|
|
1142
|
+
option('size', '占用最大'),
|
|
1143
|
+
option('subagents', '子会话最多'),
|
|
1144
|
+
]),
|
|
1145
|
+
hasActiveFilter && rows.length > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
1146
|
+
openKeys.length >= 2 && button('收起全部', () => disclosure.collapseAll(openKeys), { icon: 'chevrons-down-up', iconSize: 13 }),
|
|
1147
|
+
iconButton('刷新会话', 'refresh-cw', silentRefresh, {
|
|
1148
|
+
iconClass: (refreshing || hostSessions.reloading) ? 'dpt-spin' : '',
|
|
1149
|
+
disabled: refreshing, 'aria-busy': refreshing,
|
|
1150
|
+
}))),
|
|
1151
|
+
rows.length === 0
|
|
1152
|
+
? empty(sessionList.phase === 'ready' ? '没有符合条件的会话。' : '正在读取会话…', sessionList.phase === 'ready' && hasActiveFilter ? resetFilters : undefined)
|
|
1153
|
+
: h('ul', { className: 'dpt-card', 'data-selecting': selectedRows.length > 0 || undefined },
|
|
1154
|
+
visibleRows.map((item, index) => h(SessionRow, {
|
|
1155
|
+
...item, key: item.id, navigation, notify: toast.show,
|
|
1156
|
+
disclosure: disclosure(item.id),
|
|
1157
|
+
selectable: {
|
|
1158
|
+
checked: selectedIds.has(item.id),
|
|
1159
|
+
label: `选择会话 ${item.title}`,
|
|
1160
|
+
onChange: (checked, shiftKey) => toggleSelect(index, item.id, checked, shiftKey),
|
|
1161
|
+
},
|
|
1162
|
+
onArchived: message => { toast.show(message); void hostSessions.reload() },
|
|
1163
|
+
onDeleted: handleDeleted,
|
|
1164
|
+
})),
|
|
1165
|
+
scroller.sentinel),
|
|
1166
|
+
selectedRows.length > 0 && h('div', { className: 'dpt-floating-batch', role: 'region', 'aria-label': '会话批量操作' },
|
|
1167
|
+
h('span', { className: 'dpt-summary' }, `已选 ${selectedRows.length} 项${cascadedExtraCount > 0 ? `(+${cascadedExtraCount} 子会话)` : ''}`),
|
|
1168
|
+
button(allFilteredSelected ? '取消全选' : `全选 (${rows.length})`, () => {
|
|
1169
|
+
setSelectedIds(allFilteredSelected ? new Set() : new Set(rows.map(item => item.id)))
|
|
1170
|
+
}, { className: 'dpt-row-btn' }),
|
|
1171
|
+
deletableRows.length > 0 && deletableRows.length < rows.length && button(`仅选可删 (${deletableRows.length})`, () => {
|
|
1172
|
+
setSelectedIds(new Set(deletableRows.map(item => item.id)))
|
|
1173
|
+
}, { className: 'dpt-row-btn' }),
|
|
1174
|
+
h('span', { className: 'dpt-batch-sep', 'aria-hidden': true }),
|
|
1175
|
+
archivableSelected.length > 0 && button(`归档 (${archivableSelected.length})`, () => batchArchive(false), { icon: 'archive', iconSize: 13, className: 'dpt-row-btn', disabled: status.busy }),
|
|
1176
|
+
restorableSelected.length > 0 && button(`恢复 (${restorableSelected.length})`, () => batchArchive(true), { icon: 'archive-restore', iconSize: 13, className: 'dpt-row-btn', disabled: status.busy }),
|
|
1177
|
+
button(`删除 (${deletableSelected.length})`, () => setBatchRemoval(true), {
|
|
1178
|
+
icon: 'trash', iconSize: 13, className: 'dpt-row-btn dpt-danger',
|
|
1179
|
+
disabled: status.busy || deletableSelected.length === 0,
|
|
1180
|
+
title: deletableSelected.length === 0 ? '所选会话正在运行或由当前进程持有,暂不可删除' : undefined,
|
|
1181
|
+
}),
|
|
1182
|
+
iconButton('取消选择', 'x', () => setSelectedIds(new Set()), { className: 'dpt-row-icon-btn', iconSize: 13 })),
|
|
1183
|
+
batchRemoval && deletableSelected.length > 0 && h(Confirm, {
|
|
1184
|
+
title: `批量删除 ${deletableSelected.length} 条会话`,
|
|
1185
|
+
label: `确认批量删除(共 ${cascadeTargetIds.size} 条)`,
|
|
1186
|
+
removed: [
|
|
1187
|
+
...deletableSelected.slice(0, 6).map(item => `${item.row.isSubagent ? '子 Agent 会话' : '会话'}「${item.title}」(${item.id})`),
|
|
1188
|
+
...(deletableSelected.length > 6 ? [`其余 ${deletableSelected.length - 6} 条已选会话(合计 ${deletableSelected.length} 条)`] : []),
|
|
1189
|
+
...(cascadedExtraCount > 0 ? [`自动关联的 ${cascadedExtraCount} 条子 Agent 会话记录`] : []),
|
|
1190
|
+
],
|
|
1191
|
+
preserved: [
|
|
1192
|
+
...(lockedSelectedCount > 0 ? [`已自动跳过的 ${lockedSelectedCount} 条运行中或当前进程打开的会话`] : []),
|
|
1193
|
+
'工作区目录及所有项目文件',
|
|
1194
|
+
'其他未选中会话与独立分支会话',
|
|
1195
|
+
'Profile 恢复目录中的会话备份(含 manifest.json)',
|
|
1196
|
+
],
|
|
1197
|
+
close: () => setBatchRemoval(false),
|
|
1198
|
+
confirm: async () => {
|
|
1199
|
+
const result = await request('sessions', {
|
|
1200
|
+
action: 'batch-delete',
|
|
1201
|
+
sessionIds: deletableSelected.map(item => item.id),
|
|
1202
|
+
confirm: true,
|
|
1203
|
+
})
|
|
1204
|
+
setBatchRemoval(false)
|
|
1205
|
+
await handleDeleted(result)
|
|
1206
|
+
},
|
|
1207
|
+
}))
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const mcpSources = { user: '用户配置', inherited: '继承配置', plugin: '插件注册', retired: '已移除' }
|
|
1211
|
+
const mcpSourceOrder = { user: 1, inherited: 2, plugin: 3, retired: 4 }
|
|
1212
|
+
const mcpStates = { disabled: '已停用', connected: '已连接', connecting: '连接中', reconnecting: '重连中', failed: '连接失败', closed: '已断开', 'waiting-credentials': '等待凭据', 'waiting-authorization': '等待授权' }
|
|
1213
|
+
const mcpIssues = {
|
|
1214
|
+
failed: '连接未建立。可以测试连接或重新连接。',
|
|
1215
|
+
'waiting-credentials': '请在 DSH 中检查此服务器引用的凭据。',
|
|
1216
|
+
'waiting-authorization': '请在 DSH 的连接账号界面完成授权。',
|
|
1217
|
+
closed: '服务器连接已关闭。可以尝试重新连接。',
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
const mcpFields = ['command', 'args', 'cwd', 'env', 'url', 'headers']
|
|
1221
|
+
const mcpObject = value => value && typeof value === 'object' && !Array.isArray(value)
|
|
1222
|
+
|
|
1223
|
+
function mcpDraft(text) {
|
|
1224
|
+
let data
|
|
1225
|
+
try { data = JSON.parse(text) } catch { throw new Error('JSON 格式无效,请检查括号和引号。') }
|
|
1226
|
+
if (!mcpObject(data)) throw new Error('请提供一个 MCP 服务器对象。')
|
|
1227
|
+
let name = data.name
|
|
1228
|
+
let config = data
|
|
1229
|
+
if (Object.hasOwn(data, 'mcpServers')) {
|
|
1230
|
+
if (!mcpObject(data.mcpServers) || Object.keys(data.mcpServers).length !== 1) {
|
|
1231
|
+
throw new Error('每次保存一个服务器。请在 mcpServers 中保留一项。')
|
|
1232
|
+
}
|
|
1233
|
+
const [entry] = Object.entries(data.mcpServers)
|
|
1234
|
+
name = entry[0]
|
|
1235
|
+
config = entry[1]
|
|
1236
|
+
}
|
|
1237
|
+
if (!mcpObject(config) || name !== undefined && typeof name !== 'string') throw new Error('服务器配置或名称无效。')
|
|
1238
|
+
const type = config.transport ?? config.type ?? (config.url !== undefined ? 'streamable-http' : 'stdio')
|
|
1239
|
+
const transport = type === 'http' ? 'streamable-http' : type
|
|
1240
|
+
if (!['stdio', 'streamable-http'].includes(transport)) throw new Error('传输方式须为 stdio 或 streamable-http。')
|
|
1241
|
+
const allowed = transport === 'stdio' ? ['command', 'args', 'cwd', 'env'] : ['url', 'headers']
|
|
1242
|
+
const values = {}
|
|
1243
|
+
for (const [key, value] of Object.entries(config)) {
|
|
1244
|
+
if (['name', 'type', 'transport'].includes(key)) continue
|
|
1245
|
+
if (!allowed.includes(key)) throw new Error('JSON 包含当前传输方式无法录入的字段。')
|
|
1246
|
+
if (key === 'args') {
|
|
1247
|
+
if (!Array.isArray(value) || value.some(arg => typeof arg !== 'string')) throw new Error('args 须为字符串数组。')
|
|
1248
|
+
} else if (['env', 'headers'].includes(key)) {
|
|
1249
|
+
if (!mcpObject(value) || Object.values(value).some(item => typeof item !== 'string')) throw new Error(`${key} 须为字符串映射。`)
|
|
1250
|
+
} else if (typeof value !== 'string') throw new Error(`${key} 须为字符串。`)
|
|
1251
|
+
values[key] = value
|
|
1252
|
+
}
|
|
1253
|
+
return { name: name?.trim() ?? '', transport, values }
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function McpListFields({ fieldName, label, values, update, pairs }) {
|
|
1257
|
+
const rows = values ?? []
|
|
1258
|
+
function change(index, column, value) {
|
|
1259
|
+
update(rows.map((row, i) => i === index ? row.map((part, j) => j === column ? value : part) : row))
|
|
1260
|
+
}
|
|
1261
|
+
return h('div', { className: 'dpt-edit' },
|
|
1262
|
+
h('span', { className: 'dpt-label' }, label),
|
|
1263
|
+
rows.map((row, index) => h('div', { key: index, className: 'dpt-argument-row' },
|
|
1264
|
+
row.map((part, column) => h('input', {
|
|
1265
|
+
key: column, className: 'dpt-mono', dir: 'ltr', spellCheck: false,
|
|
1266
|
+
'aria-label': pairs ? `${fieldName} ${index + 1} ${column ? '值' : '名称'}` : `参数 ${index + 1}`,
|
|
1267
|
+
placeholder: pairs ? column ? 'Bearer ${credential:MCP_TOKEN}' : '名称' : '参数',
|
|
1268
|
+
value: part, onChange: e => change(index, column, e.target.value),
|
|
1269
|
+
})),
|
|
1270
|
+
button('', () => update(rows.filter((_, i) => i !== index)), { icon: 'x', iconSize: 13, className: 'dpt-danger', 'aria-label': `移除${fieldName} ${index + 1}` }))),
|
|
1271
|
+
h('div', { className: 'dpt-actions' }, button(`添加${fieldName}`, () => update([...rows, pairs ? ['', ''] : ['']]), { icon: 'plus', iconSize: 13 })))
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function McpEditor({ row, revision, close, saved }) {
|
|
1275
|
+
const [status, run, dismiss] = useAction()
|
|
1276
|
+
const [mode, setMode] = useState('form')
|
|
1277
|
+
const [name, setName] = useState(row?.name ?? '')
|
|
1278
|
+
const [transport, setTransport] = useState(row?.transport ?? 'stdio')
|
|
1279
|
+
const [values, setValues] = useState({})
|
|
1280
|
+
const [json, setJson] = useState('')
|
|
1281
|
+
const [modeError, setModeError] = useState('')
|
|
1282
|
+
const set = (key, value) => setValues(previous => ({ ...previous, [key]: value }))
|
|
1283
|
+
const switching = row && transport !== row.transport
|
|
1284
|
+
const existing = row && !switching
|
|
1285
|
+
|
|
1286
|
+
function input(key, label, placeholder, type = 'text') {
|
|
1287
|
+
return field(label, h('input', {
|
|
1288
|
+
type, dir: 'ltr', className: 'dpt-mono', spellCheck: false,
|
|
1289
|
+
value: values[key] ?? '', placeholder, onChange: e => set(key, e.target.value), autoComplete: 'off',
|
|
1290
|
+
}))
|
|
1291
|
+
}
|
|
1292
|
+
function formValues() {
|
|
1293
|
+
const result = {}
|
|
1294
|
+
const listFields = transport === 'stdio' ? ['command', 'args', 'cwd', 'env'] : ['url', 'headers']
|
|
1295
|
+
for (const key of listFields) {
|
|
1296
|
+
if (!Object.hasOwn(values, key)) continue
|
|
1297
|
+
const value = values[key]
|
|
1298
|
+
if (key === 'args') result.args = value.map(([argument]) => argument)
|
|
1299
|
+
else if (['env', 'headers'].includes(key)) {
|
|
1300
|
+
const seen = new Set()
|
|
1301
|
+
for (const [entryName, item] of value) {
|
|
1302
|
+
if (!entryName.trim() || !item.trim() || seen.has(entryName.trim())) throw new Error('请填写非空且唯一的环境变量或请求头。')
|
|
1303
|
+
seen.add(entryName.trim())
|
|
1304
|
+
}
|
|
1305
|
+
result[key] = Object.fromEntries(value.map(([entryName, item]) => [entryName.trim(), item]))
|
|
1306
|
+
} else result[key] = value
|
|
1307
|
+
}
|
|
1308
|
+
return result
|
|
1309
|
+
}
|
|
1310
|
+
function readJson() {
|
|
1311
|
+
const draft = mcpDraft(json)
|
|
1312
|
+
if (row && draft.name && row.name !== draft.name) throw new Error('编辑时请保留原服务器名称。')
|
|
1313
|
+
return { ...draft, name: row?.name ?? draft.name }
|
|
1314
|
+
}
|
|
1315
|
+
function changeMode(next) {
|
|
1316
|
+
if (mode === next) return
|
|
1317
|
+
try {
|
|
1318
|
+
if (next === 'json') {
|
|
1319
|
+
const config = { transport, ...formValues() }
|
|
1320
|
+
setJson(JSON.stringify(name.trim() ? { mcpServers: { [name.trim()]: config } } : { name: '', ...config }, null, 2))
|
|
1321
|
+
} else {
|
|
1322
|
+
const draft = readJson()
|
|
1323
|
+
setName(draft.name); setTransport(draft.transport)
|
|
1324
|
+
setValues(Object.fromEntries(mcpFields.filter(key => Object.hasOwn(draft.values, key)).map(key => {
|
|
1325
|
+
const value = draft.values[key]
|
|
1326
|
+
return [key, key === 'args' ? value.map(argument => [argument]) : ['env', 'headers'].includes(key) ? Object.entries(value) : value]
|
|
1327
|
+
})))
|
|
1328
|
+
}
|
|
1329
|
+
dismiss(); setModeError(''); setMode(next)
|
|
1330
|
+
} catch (error) { setModeError(error.message) }
|
|
1331
|
+
}
|
|
1332
|
+
async function save() {
|
|
1333
|
+
const draft = mode === 'json' ? readJson() : { name: name.trim(), transport, values: formValues() }
|
|
1334
|
+
await request('mcp', { action: row ? 'edit' : 'create', revision, name: draft.name, transport: draft.transport, ...draft.values })
|
|
1335
|
+
saved(row ? '服务器配置已更新' : '服务器已添加(默认停用,可先测试连接再启用)')
|
|
1336
|
+
}
|
|
1337
|
+
const modeNav = h('nav', { className: 'dpt-nav', 'aria-label': 'MCP 录入方式' },
|
|
1338
|
+
button('表单录入', () => changeMode('form'), { 'aria-pressed': mode === 'form', disabled: status.busy }),
|
|
1339
|
+
button('JSON 录入', () => changeMode('json'), { 'aria-pressed': mode === 'json', disabled: status.busy }))
|
|
1340
|
+
return h('div', { className: 'dpt-edit' },
|
|
1341
|
+
h('h3', null, row ? '编辑服务器' : '新增 MCP 服务器'), modeNav,
|
|
1342
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(save) } },
|
|
1343
|
+
mode === 'json' ? h(React.Fragment, null,
|
|
1344
|
+
field('MCP JSON', h('textarea', {
|
|
1345
|
+
rows: 10, value: json, spellCheck: false, dir: 'ltr', className: 'dpt-mono dpt-fixed-editor',
|
|
1346
|
+
onChange: e => { setJson(e.target.value); setModeError('') },
|
|
1347
|
+
})),
|
|
1348
|
+
muted(h(React.Fragment, null, '支持单个服务器对象或 ', code('mcpServers'), ' 中的单项。编辑时省略的字段沿用现有值。')))
|
|
1349
|
+
: h(React.Fragment, null,
|
|
1350
|
+
h('div', { className: 'dpt-form-row' },
|
|
1351
|
+
field('服务器名称', h('input', { value: name, onChange: e => setName(e.target.value), disabled: Boolean(row), required: true, dir: 'ltr', className: 'dpt-mono' })),
|
|
1352
|
+
field('传输方式', pick('传输方式', transport, value => { setTransport(value); setValues({}) }, [option('stdio', 'stdio'), option('streamable-http', 'streamable-http')]))),
|
|
1353
|
+
existing && muted('未填写的字段沿用现有值。要清空现有列表,可用 JSON 提交空数组或对象。'),
|
|
1354
|
+
switching && muted('切换传输方式会清空原传输配置。'),
|
|
1355
|
+
transport === 'stdio' ? h(React.Fragment, null,
|
|
1356
|
+
input('command', '可执行文件', 'node 或 node.exe'), input('cwd', '启动目录(绝对路径,可选)', ''),
|
|
1357
|
+
h(McpListFields, { fieldName: '参数', label: '进程参数', values: values.args, update: value => set('args', value) }),
|
|
1358
|
+
h(McpListFields, { fieldName: '环境变量', label: '环境变量 · DSH 凭据引用', values: values.env, pairs: true, update: value => set('env', value) }))
|
|
1359
|
+
: h(React.Fragment, null,
|
|
1360
|
+
input('url', 'MCP 地址', 'https://example.com/mcp', 'url'),
|
|
1361
|
+
h(McpListFields, { fieldName: '请求头', label: '请求头 · DSH 凭据引用', values: values.headers, pairs: true, update: value => set('headers', value) }))),
|
|
1362
|
+
feedback(modeError, true, () => setModeError('')), feedback(status.message, status.error, dismiss),
|
|
1363
|
+
h('div', { className: 'dpt-actions' },
|
|
1364
|
+
button('取消编辑', close, { disabled: status.busy }),
|
|
1365
|
+
primary('保存', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy }))))
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
function Confirm({ title, removed, preserved, label, close, confirm }) {
|
|
1369
|
+
const [status, run, dismiss] = useAction()
|
|
1370
|
+
return h(Modal, { title, close },
|
|
1371
|
+
h('div', { className: 'dpt-form' },
|
|
1372
|
+
h('div', { className: 'dpt-confirm-list' }, [['将移除', removed], ['将保留', preserved]].map(([heading, items]) =>
|
|
1373
|
+
h('section', { key: heading }, h('h3', null, heading), h('ul', null, items.map(item => h('li', { key: item }, item)))))),
|
|
1374
|
+
feedback(status.message, status.error, dismiss),
|
|
1375
|
+
h('div', { className: 'dpt-actions' }, button('取消', close, { autoFocus: true, disabled: status.busy }),
|
|
1376
|
+
button(label, () => run(confirm), { icon: 'trash', className: 'dpt-danger', disabled: status.busy, 'aria-busy': status.busy }))))
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
function useMcpList() {
|
|
1380
|
+
const [view, setView] = useState(null)
|
|
1381
|
+
const [error, setError] = useState('')
|
|
1382
|
+
const [reloading, setReloading] = useState(false)
|
|
1383
|
+
const generation = useRef(0)
|
|
1384
|
+
async function refresh(signal, manual = false) {
|
|
1385
|
+
const current = ++generation.current
|
|
1386
|
+
if (manual) setReloading(true)
|
|
1387
|
+
try {
|
|
1388
|
+
const next = await request('mcp', { action: 'list' }, signal)
|
|
1389
|
+
if (current === generation.current && !signal?.aborted) { setView(next); setError('') }
|
|
1390
|
+
} catch (error) {
|
|
1391
|
+
if (current === generation.current && !signal?.aborted) setError(error.message)
|
|
1392
|
+
} finally {
|
|
1393
|
+
if (manual && current === generation.current) setReloading(false)
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
useEffect(() => {
|
|
1397
|
+
const abort = new AbortController()
|
|
1398
|
+
void refresh(abort.signal)
|
|
1399
|
+
const timer = setInterval(() => refresh(abort.signal), 2500)
|
|
1400
|
+
return () => { clearInterval(timer); abort.abort(); generation.current++ }
|
|
1401
|
+
}, [])
|
|
1402
|
+
return { view, error, reloading, refresh: () => refresh(undefined, true), dismissError: () => setError('') }
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
function McpRow({ row, revision, refresh, removed, disclosure, onProbed, notify }) {
|
|
1406
|
+
const [editing, setEditing] = useState(null)
|
|
1407
|
+
const [removal, setRemoval] = useState(null)
|
|
1408
|
+
const [probedTools, setProbedTools] = useState(null)
|
|
1409
|
+
const [toolQuery, setToolQuery] = useState('')
|
|
1410
|
+
const [showAllTools, setShowAllTools] = useState(false)
|
|
1411
|
+
const [optimisticEnabled, setOptimisticEnabled] = useState(null)
|
|
1412
|
+
const [status, run, dismiss] = useAction()
|
|
1413
|
+
useEffect(() => { setOptimisticEnabled(null) }, [row.enabled, row.status])
|
|
1414
|
+
const effectiveEnabled = optimisticEnabled ?? row.enabled
|
|
1415
|
+
const issue = row.enabled && mcpIssues[row.status]
|
|
1416
|
+
const tone = issue ? 'attention' : row.status === 'connected' ? 'ready' : effectiveEnabled ? 'info' : 'idle'
|
|
1417
|
+
|
|
1418
|
+
function operation(action, success, expandOnDone = false) {
|
|
1419
|
+
if (action === 'enable' || action === 'disable') setOptimisticEnabled(action === 'enable')
|
|
1420
|
+
return run(async () => {
|
|
1421
|
+
try {
|
|
1422
|
+
const result = await request('mcp', { action, name: row.name, revision })
|
|
1423
|
+
await refresh()
|
|
1424
|
+
if (action === 'probe') {
|
|
1425
|
+
if (!result.closed) throw new Error(`${row.name} 的探测进程未确认清理。`)
|
|
1426
|
+
if (!result.ok) throw new Error(`${row.name} ${result.stage === 'list' ? '工具列表读取失败' : '连接测试失败'}。`)
|
|
1427
|
+
const names = result.toolNames ?? []
|
|
1428
|
+
setProbedTools({ names, truncated: Boolean(result.truncated) })
|
|
1429
|
+
setToolQuery('')
|
|
1430
|
+
setShowAllTools(false)
|
|
1431
|
+
onProbed?.(row.name, names)
|
|
1432
|
+
if (expandOnDone && names.length > 0) disclosure.open()
|
|
1433
|
+
const msg = `${row.name} 测试通过 · ${result.toolCount}${result.truncated ? '+' : ''} 个工具 · ${result.durationMs} ms`
|
|
1434
|
+
notify(msg)
|
|
1435
|
+
return msg
|
|
1436
|
+
}
|
|
1437
|
+
if (success) notify(`${row.name} ${success}`)
|
|
1438
|
+
return `${row.name} ${success}`
|
|
1439
|
+
} catch (err) {
|
|
1440
|
+
setOptimisticEnabled(null)
|
|
1441
|
+
throw err
|
|
1442
|
+
}
|
|
1443
|
+
})
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
const allTools = probedTools?.names ?? []
|
|
1447
|
+
const filteredTools = toolQuery.trim() ? allTools.filter(tool => matches(toolQuery, tool)) : allTools
|
|
1448
|
+
const visibleTools = showAllTools ? filteredTools : filteredTools.slice(0, 24)
|
|
1449
|
+
|
|
1450
|
+
const quickActions = row.testable && iconButton(
|
|
1451
|
+
`测试 ${row.name}`, 'play', () => operation('probe', '', true),
|
|
1452
|
+
{ className: 'dpt-row-icon-btn', iconSize: 13, title: '测试连接', disabled: status.busy },
|
|
1453
|
+
)
|
|
1454
|
+
const alwaysActions = row.editable && h(Switch, {
|
|
1455
|
+
checked: effectiveEnabled,
|
|
1456
|
+
disabled: status.busy,
|
|
1457
|
+
label: `${effectiveEnabled ? '停用' : '启用'} ${row.name}`,
|
|
1458
|
+
onChange: next => operation(next ? 'enable' : 'disable', next ? '已启用' : '已停用'),
|
|
1459
|
+
})
|
|
1460
|
+
|
|
1461
|
+
return h(DisclosureRow, {
|
|
1462
|
+
title: row.name, tag: row.transport,
|
|
1463
|
+
detail: [
|
|
1464
|
+
mcpSources[row.source],
|
|
1465
|
+
row.transport === 'stdio' ? '本地进程' : row.transport === 'streamable-http' ? 'HTTP 服务' : '传输未公开',
|
|
1466
|
+
Number.isInteger(row.toolCount) ? `${row.toolCount} 个工具` : '',
|
|
1467
|
+
].filter(Boolean).join(' · '),
|
|
1468
|
+
badge: mcpStates[row.status] ?? '状态未知', tone,
|
|
1469
|
+
quickActions, alwaysActions, ...disclosure,
|
|
1470
|
+
},
|
|
1471
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1472
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
1473
|
+
h('span', null, '来源', h('strong', null, mcpSources[row.source])),
|
|
1474
|
+
h('span', null, '传输', row.transport ? code(row.transport) : h('strong', null, '未公开')),
|
|
1475
|
+
h('span', null, '配置', h('strong', null, row.enabled ? '启用' : '停用')),
|
|
1476
|
+
Number.isInteger(row.toolCount) && h('span', null, '工具', h('strong', null, row.toolCount))),
|
|
1477
|
+
h('div', { className: 'dpt-actions' },
|
|
1478
|
+
row.testable && button('测试连接', () => operation('probe'), { icon: 'play', disabled: status.busy, 'aria-busy': status.busy }),
|
|
1479
|
+
row.reconnectable && button('重连', () => operation('restart', '已请求重连'), { icon: 'rotate-cw', disabled: status.busy }),
|
|
1480
|
+
row.editable && button(row.enabled ? '停用' : '启用', () => operation(row.enabled ? 'disable' : 'enable', row.enabled ? '已停用' : '已启用'), { disabled: status.busy }),
|
|
1481
|
+
row.editable && !editing && button('编辑', () => setEditing({ revision }), { icon: 'square-pen', disabled: status.busy }),
|
|
1482
|
+
row.editable && button('移除', () => setRemoval({ revision }), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
1483
|
+
allTools.length > 0 && h('div', { className: 'dpt-edit' },
|
|
1484
|
+
allTools.length > 12 && h('div', { className: 'dpt-drawer-bar' },
|
|
1485
|
+
h('span', { className: 'dpt-label' }, `探测工具(${filteredTools.length}${filteredTools.length !== allTools.length ? ` / ${allTools.length}` : ''}${probedTools.truncated ? '+' : ''})`),
|
|
1486
|
+
h('div', { className: 'dpt-actions' },
|
|
1487
|
+
h('input', {
|
|
1488
|
+
type: 'search', className: 'dpt-inline-filter',
|
|
1489
|
+
'aria-label': `筛选 ${row.name} 工具`, placeholder: '筛选工具名…',
|
|
1490
|
+
value: toolQuery, onChange: e => setToolQuery(e.target.value),
|
|
1491
|
+
onKeyDown: e => { if (e.key === 'Escape' && toolQuery) { e.preventDefault(); setToolQuery('') } },
|
|
1492
|
+
}),
|
|
1493
|
+
filteredTools.length > 24 && button(showAllTools ? '收起列表' : `展开全部 ${filteredTools.length} 个`, () => setShowAllTools(!showAllTools)))),
|
|
1494
|
+
filteredTools.length > 0
|
|
1495
|
+
? h('div', { className: `dpt-tool-list${showAllTools && filteredTools.length > 24 ? ' dpt-scroll-box' : ''}`, 'aria-label': '探测到的工具' },
|
|
1496
|
+
visibleTools.map(tool => h('code', { key: tool, className: 'dpt-mono dpt-tool-chip', dir: 'ltr' }, tool)),
|
|
1497
|
+
(!showAllTools && filteredTools.length > 24)
|
|
1498
|
+
? h('span', { className: 'dpt-muted' }, `…其余 ${filteredTools.length - 24} 个`)
|
|
1499
|
+
: (probedTools.truncated && !toolQuery.trim() && h('span', { className: 'dpt-muted' }, '…')))
|
|
1500
|
+
: muted('没有匹配的探测工具。')),
|
|
1501
|
+
issue && muted(issue),
|
|
1502
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1503
|
+
editing && h('div', { className: 'dpt-drawer-split' }, h(McpEditor, {
|
|
1504
|
+
row, ...editing, close: () => setEditing(null), saved: message => {
|
|
1505
|
+
dismiss(); notify(message); setEditing(null); void refresh()
|
|
1506
|
+
},
|
|
1507
|
+
})),
|
|
1508
|
+
removal && h(Confirm, {
|
|
1509
|
+
title: `移除 ${row.name}`, label: '移除服务器',
|
|
1510
|
+
removed: [`服务器「${row.name}」的用户配置`, '此服务器的连接与会话中的工具注册'],
|
|
1511
|
+
preserved: ['本机可执行文件及资源', 'DSH 凭据和其他 MCP 服务器配置'],
|
|
1512
|
+
close: () => setRemoval(null), confirm: async () => {
|
|
1513
|
+
await request('mcp', { action: 'remove', name: row.name, revision: removal.revision })
|
|
1514
|
+
setRemoval(null); removed(row.name); await refresh()
|
|
1515
|
+
},
|
|
1516
|
+
}))
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
function McpPanel({ host, toast }) {
|
|
1520
|
+
const { view, error, reloading, refresh, dismissError } = useMcpList()
|
|
1521
|
+
const [query, search] = useState('')
|
|
1522
|
+
const [sourceFilter, setSourceFilter] = useState('all')
|
|
1523
|
+
const [statusFilter, setStatusFilter] = useState('all')
|
|
1524
|
+
const [probedByServer, setProbedByServer] = useState({})
|
|
1525
|
+
const [editor, setEditor] = useState(null)
|
|
1526
|
+
const disclosure = useDisclosure()
|
|
1527
|
+
const rows = (view?.servers ?? []).filter(row => row.source !== 'retired')
|
|
1528
|
+
const connectedCount = rows.filter(row => row.status === 'connected').length
|
|
1529
|
+
const issueCount = rows.filter(row => row.enabled && mcpIssues[row.status]).length
|
|
1530
|
+
const disabledCount = rows.filter(row => !row.enabled).length
|
|
1531
|
+
|
|
1532
|
+
const filtered = rows.filter(row => {
|
|
1533
|
+
if (sourceFilter !== 'all' && row.source !== sourceFilter) return false
|
|
1534
|
+
if (statusFilter === 'connected' && row.status !== 'connected') return false
|
|
1535
|
+
if (statusFilter === 'issue' && !(row.enabled && mcpIssues[row.status])) return false
|
|
1536
|
+
if (statusFilter === 'disabled' && row.enabled) return false
|
|
1537
|
+
return matches(query, row.name, row.transport ?? '', mcpSources[row.source], ...(probedByServer[row.name] ?? []))
|
|
1538
|
+
}).sort((a, b) => (mcpSourceOrder[a.source] ?? 9) - (mcpSourceOrder[b.source] ?? 9))
|
|
1539
|
+
|
|
1540
|
+
const hasActiveFilter = Boolean(query.trim()) || sourceFilter !== 'all' || statusFilter !== 'all'
|
|
1541
|
+
const resetFilters = () => { search(''); setSourceFilter('all'); setStatusFilter('all') }
|
|
1542
|
+
const scroller = useInfiniteScroll(filtered.length, `${query}\n${sourceFilter}\n${statusFilter}`, 50)
|
|
1543
|
+
const visibleRows = filtered.slice(0, scroller.limit)
|
|
1544
|
+
const openKeys = visibleRows.filter(row => disclosure.isOpen(row.name, Boolean(row.enabled && mcpIssues[row.status]))).map(row => row.name)
|
|
1545
|
+
|
|
1546
|
+
return h('div', { className: 'dpt-panel' },
|
|
1547
|
+
feedback(host.error || (host.info?.mcp === false ? '当前 DSH 配置未加载 MCP 服务。' : ''), true, host.dismiss),
|
|
1548
|
+
feedback(error, true, dismissError),
|
|
1549
|
+
h('div', { className: 'dpt-toolbar' },
|
|
1550
|
+
h(Segmented, {
|
|
1551
|
+
label: 'MCP 状态筛选', value: statusFilter, onChange: setStatusFilter,
|
|
1552
|
+
items: [
|
|
1553
|
+
{ value: 'all', label: '全部', count: view ? rows.length : null },
|
|
1554
|
+
{ value: 'connected', label: '已连接', count: view ? connectedCount : null },
|
|
1555
|
+
{ value: 'issue', label: '异常', count: view ? issueCount : null, alert: issueCount > 0 },
|
|
1556
|
+
{ value: 'disabled', label: '已停用', count: view ? disabledCount : null },
|
|
1557
|
+
],
|
|
1558
|
+
}),
|
|
1559
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
1560
|
+
rows.length > 0 && filterInput('搜索 MCP 服务器', query, search),
|
|
1561
|
+
rows.length > 0 && pick('MCP 来源筛选', sourceFilter, setSourceFilter, [
|
|
1562
|
+
option('all', '全部来源'),
|
|
1563
|
+
option('user', '用户配置'),
|
|
1564
|
+
option('inherited', '继承配置'),
|
|
1565
|
+
option('plugin', '插件注册'),
|
|
1566
|
+
]),
|
|
1567
|
+
hasActiveFilter && filtered.length > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
1568
|
+
openKeys.length >= 2 && button('收起全部', () => disclosure.collapseAll(openKeys), { icon: 'chevrons-down-up', iconSize: 13 }),
|
|
1569
|
+
iconButton('刷新 MCP', 'refresh-cw', refresh, { iconClass: reloading ? 'dpt-spin' : '', disabled: reloading, 'aria-busy': reloading }),
|
|
1570
|
+
primary('新增服务器', () => setEditor({ revision: view.revision }), { icon: 'plus', disabled: !view?.writable || Boolean(editor) }))),
|
|
1571
|
+
editor && h('div', { className: 'dpt-card dpt-empty' }, h(McpEditor, {
|
|
1572
|
+
...editor, close: () => setEditor(null), saved: message => {
|
|
1573
|
+
toast.show(message); setEditor(null); void refresh()
|
|
1574
|
+
},
|
|
1575
|
+
})),
|
|
1576
|
+
filtered.length ? h('ul', { className: 'dpt-card' }, (() => {
|
|
1577
|
+
const groups = Object.entries(mcpSources).map(([source, title]) => [source, title, visibleRows.filter(row => row.source === source)]).filter(([, , items]) => items.length > 0)
|
|
1578
|
+
return groups.map(([source, title, group]) => h(React.Fragment, { key: source },
|
|
1579
|
+
groups.length > 1 && h('li', { className: 'dpt-subhead' }, title),
|
|
1580
|
+
group.map(row => h(McpRow, {
|
|
1581
|
+
key: row.name, row, revision: view.revision, refresh, notify: toast.show,
|
|
1582
|
+
disclosure: disclosure(row.name, Boolean(row.enabled && mcpIssues[row.status])),
|
|
1583
|
+
onProbed: (serverName, names) => setProbedByServer(previous => ({ ...previous, [serverName]: names })),
|
|
1584
|
+
removed: name => toast.show(`已移除服务器 · ${name}`),
|
|
1585
|
+
}))))
|
|
1586
|
+
})(), scroller.sentinel)
|
|
1587
|
+
: empty(rows.length ? '没有符合条件的 MCP 服务器。' : view ? '暂无 MCP 服务器,点击右上角「新增服务器」添加。' : error ? '服务器列表暂不可用。' : '正在读取 MCP 服务器…', rows.length && hasActiveFilter ? resetFilters : undefined))
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
const skillSources = { 'project-dsh': '项目 · DSH', 'project-agents': '项目 · Agents', 'user-dsh': '个人 · DSH', 'user-agents': '个人 · Agents', bundled: '内置', runtime: '插件', custom: '自定义目录' }
|
|
1591
|
+
const skillSourceOrder = { 'project-dsh': 1, 'project-agents': 2, 'user-dsh': 3, 'user-agents': 4, custom: 5, runtime: 6, bundled: 7 }
|
|
1592
|
+
|
|
1593
|
+
function SkillPreview({ preview, initialEditing = false, close, update }) {
|
|
1594
|
+
const [editing, setEditing] = useState(initialEditing)
|
|
1595
|
+
const [showAllFiles, setShowAllFiles] = useState(false)
|
|
1596
|
+
const [description, setDescription] = useState(preview.description)
|
|
1597
|
+
const [body, setBody] = useState(preview.body)
|
|
1598
|
+
const [modelInvocable, model] = useState(preview.modelInvocable)
|
|
1599
|
+
const [userInvocable, user] = useState(preview.userInvocable)
|
|
1600
|
+
const [status, run, dismiss] = useAction()
|
|
1601
|
+
const files = preview.files ?? []
|
|
1602
|
+
const visibleFiles = showAllFiles ? files : files.slice(0, 8)
|
|
1603
|
+
return h('div', { className: 'dpt-edit' }, editing
|
|
1604
|
+
? h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(() => update({ description, body, modelInvocable, userInvocable })) } },
|
|
1605
|
+
field('描述', h('input', { required: true, value: description, onChange: e => setDescription(e.target.value) })),
|
|
1606
|
+
field('正文', h('textarea', { rows: 11, className: 'dpt-mono dpt-fixed-editor', value: body, onChange: e => setBody(e.target.value) })),
|
|
1607
|
+
h('div', { className: 'dpt-actions' },
|
|
1608
|
+
h('label', { className: 'dpt-check' }, h('input', { type: 'checkbox', checked: modelInvocable, onChange: e => model(e.target.checked) }), '允许模型调用'),
|
|
1609
|
+
h('label', { className: 'dpt-check' }, h('input', { type: 'checkbox', checked: userInvocable, onChange: e => user(e.target.checked) }), '允许用户手动调用')),
|
|
1610
|
+
feedback(status.message, status.error, dismiss),
|
|
1611
|
+
h('div', { className: 'dpt-actions' }, primary('保存 Skill', undefined, { type: 'submit', icon: 'check', disabled: status.busy, 'aria-busy': status.busy }),
|
|
1612
|
+
button('取消编辑', () => {
|
|
1613
|
+
setDescription(preview.description); setBody(preview.body); model(preview.modelInvocable); user(preview.userInvocable)
|
|
1614
|
+
dismiss()
|
|
1615
|
+
if (initialEditing) close()
|
|
1616
|
+
else setEditing(false)
|
|
1617
|
+
}, { disabled: status.busy })))
|
|
1618
|
+
: h(React.Fragment, null,
|
|
1619
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1620
|
+
muted(h(React.Fragment, null, preview.raw ? code('SKILL.md') : 'DSH 提供的 Skill 正文',
|
|
1621
|
+
preview.bytes ? ` · ${formatBytes(preview.bytes)}` : '')),
|
|
1622
|
+
h('div', { className: 'dpt-actions' },
|
|
1623
|
+
preview.editable && button('编辑内容与权限', () => setEditing(true), { icon: 'square-pen' }),
|
|
1624
|
+
button('关闭预览', close, { icon: 'x', iconSize: 13 }))),
|
|
1625
|
+
preview.meta?.length > 0 && h('div', { className: 'dpt-drawer-facts' },
|
|
1626
|
+
preview.meta.map(entry => h('span', { key: entry.key }, entry.key, code(entry.value)))),
|
|
1627
|
+
h('pre', { className: 'dpt-mono', dir: 'ltr' }, preview.markdown),
|
|
1628
|
+
files.length > 0 && h('div', { className: 'dpt-edit' },
|
|
1629
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1630
|
+
h('span', { className: 'dpt-label' }, `随附文件(${files.length})`),
|
|
1631
|
+
files.length > 8 && button(showAllFiles ? '收起文件列表' : `展开全部 ${files.length} 个文件`, () => setShowAllFiles(!showAllFiles))),
|
|
1632
|
+
h('ul', { className: `dpt-file-list${showAllFiles && files.length > 8 ? ' dpt-scroll-box' : ''}` }, visibleFiles.map(file =>
|
|
1633
|
+
h('li', { key: file.path }, code(file.path), h('span', null, formatBytes(file.size))))))))
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
function SkillImport({ workspace, navigation, close, save }) {
|
|
1637
|
+
const [directory, setDirectory] = useState('')
|
|
1638
|
+
const [destination, setDestination] = useState(workspace ? 'project' : 'personal')
|
|
1639
|
+
const [status, run, dismiss] = useAction()
|
|
1640
|
+
return h('div', { className: 'dpt-edit' }, h('h3', null, '导入本地 Skill'),
|
|
1641
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(() => save({ directory: directory.trim(), destination })) } },
|
|
1642
|
+
field('来源目录(包含 SKILL.md)', h('input', { required: true, autoFocus: true, value: directory, onChange: e => setDirectory(e.target.value), dir: 'ltr', className: 'dpt-mono' })),
|
|
1643
|
+
h('div', { className: 'dpt-actions' },
|
|
1644
|
+
button('选择本地目录', () => run(async () => { const dir = await navigation.pickDirectory(); if (dir) setDirectory(dir) }), { icon: 'folder', disabled: status.busy })),
|
|
1645
|
+
field('导入位置', pick('导入位置', destination, setDestination, [workspace && option('project', '当前项目'), option('personal', '个人 DSH')].filter(Boolean))),
|
|
1646
|
+
feedback(status.message, status.error, dismiss),
|
|
1647
|
+
h('div', { className: 'dpt-actions' }, button('取消', close, { disabled: status.busy }),
|
|
1648
|
+
primary('导入', undefined, { type: 'submit', icon: 'folder-plus', disabled: status.busy, 'aria-busy': status.busy }))))
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
function SkillRow({ row, scope, disclosure, refresh, removed, notify }) {
|
|
1652
|
+
const [preview, setPreview] = useState(null)
|
|
1653
|
+
const [startInEdit, setStartInEdit] = useState(false)
|
|
1654
|
+
const [removal, setRemoval] = useState(false)
|
|
1655
|
+
const [optimisticPerm, setOptimisticPerm] = useState(null)
|
|
1656
|
+
const [status, run, dismiss] = useAction()
|
|
1657
|
+
useEffect(() => { setOptimisticPerm(null) }, [row.modelInvocable, row.userInvocable])
|
|
1658
|
+
const modelChecked = optimisticPerm ? optimisticPerm.model : row.modelInvocable
|
|
1659
|
+
const userChecked = optimisticPerm ? optimisticPerm.user : row.userInvocable
|
|
1660
|
+
|
|
1661
|
+
async function load() {
|
|
1662
|
+
return request('skills', { ...scope, action: 'preview', name: row.name })
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
async function openMode(editMode) {
|
|
1666
|
+
await run(async () => {
|
|
1667
|
+
const current = await load()
|
|
1668
|
+
setStartInEdit(editMode)
|
|
1669
|
+
setPreview(current)
|
|
1670
|
+
disclosure.open()
|
|
1671
|
+
})
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
async function quickTogglePermission(nextModel, nextUser) {
|
|
1675
|
+
setOptimisticPerm({ model: nextModel, user: nextUser })
|
|
1676
|
+
await run(async () => {
|
|
1677
|
+
try {
|
|
1678
|
+
const current = await load()
|
|
1679
|
+
await request('skills', {
|
|
1680
|
+
...scope, action: 'edit', name: row.name, revision: current.revision,
|
|
1681
|
+
description: current.description, body: current.body,
|
|
1682
|
+
modelInvocable: nextModel, userInvocable: nextUser,
|
|
1683
|
+
})
|
|
1684
|
+
if (preview) setPreview(await load())
|
|
1685
|
+
notify(`${row.name} 调用权限已更新`)
|
|
1686
|
+
await refresh()
|
|
1687
|
+
} catch (err) {
|
|
1688
|
+
setOptimisticPerm(null)
|
|
1689
|
+
throw err
|
|
1690
|
+
}
|
|
1691
|
+
})
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
const restrictionChips = (!modelChecked || !userChecked) && h(React.Fragment, null,
|
|
1695
|
+
!modelChecked && pill('模型停用', 'attention'),
|
|
1696
|
+
!userChecked && pill('手动停用'))
|
|
1697
|
+
|
|
1698
|
+
const quickActions = h(React.Fragment, null,
|
|
1699
|
+
iconButton(`快速预览 ${row.name}`, 'eye', () => openMode(false), { className: 'dpt-row-icon-btn', iconSize: 13, title: '预览 SKILL.md', disabled: status.busy }),
|
|
1700
|
+
row.editable && iconButton(`快速编辑 ${row.name}`, 'square-pen', () => openMode(true), { className: 'dpt-row-icon-btn', iconSize: 13, title: '编辑内容与权限', disabled: status.busy }))
|
|
1701
|
+
|
|
1702
|
+
return h(DisclosureRow, {
|
|
1703
|
+
title: row.name, chips: restrictionChips, detail: row.description,
|
|
1704
|
+
badge: row.editable ? '可编辑' : '只读', tone: row.editable ? 'ready' : 'idle',
|
|
1705
|
+
quickActions, ...disclosure,
|
|
1706
|
+
},
|
|
1707
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1708
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
1709
|
+
h('span', null, '来源', h('strong', null, skillSources[row.source] ?? `插件 · ${row.source}`)),
|
|
1710
|
+
row.editable
|
|
1711
|
+
? h(React.Fragment, null,
|
|
1712
|
+
h('label', { className: 'dpt-check' },
|
|
1713
|
+
h('input', {
|
|
1714
|
+
type: 'checkbox', checked: modelChecked, disabled: status.busy,
|
|
1715
|
+
onChange: e => quickTogglePermission(e.target.checked, userChecked),
|
|
1716
|
+
}), '模型调用'),
|
|
1717
|
+
h('label', { className: 'dpt-check' },
|
|
1718
|
+
h('input', {
|
|
1719
|
+
type: 'checkbox', checked: userChecked, disabled: status.busy,
|
|
1720
|
+
onChange: e => quickTogglePermission(modelChecked, e.target.checked),
|
|
1721
|
+
}), '手动调用'))
|
|
1722
|
+
: h('span', null, '权限', h('strong', null, `模型${row.modelInvocable ? '可调用' : '停用'} · 手动${row.userInvocable ? '可调用' : '停用'}`))),
|
|
1723
|
+
h('div', { className: 'dpt-actions' },
|
|
1724
|
+
!preview && button('预览', () => openMode(false), { icon: 'eye', disabled: status.busy, 'aria-label': `预览 ${row.name}` }),
|
|
1725
|
+
!preview && row.editable && button('编辑', () => openMode(true), { icon: 'square-pen', disabled: status.busy }),
|
|
1726
|
+
row.editable && button('移除', () => run(async () => {
|
|
1727
|
+
const current = await load()
|
|
1728
|
+
setStartInEdit(false); setPreview(current); setRemoval(true)
|
|
1729
|
+
}), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
1730
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1731
|
+
preview && h('div', { className: 'dpt-drawer-split' }, h(SkillPreview, {
|
|
1732
|
+
key: `${preview.revision ?? preview.name}:${startInEdit}`, preview, initialEditing: startInEdit,
|
|
1733
|
+
close: () => { setPreview(null); setStartInEdit(false) },
|
|
1734
|
+
update: async fields => {
|
|
1735
|
+
await request('skills', { ...scope, action: 'edit', ...fields, name: row.name, revision: preview.revision })
|
|
1736
|
+
setPreview(null); setStartInEdit(false); notify('Skill 已更新'); await refresh()
|
|
1737
|
+
},
|
|
1738
|
+
})),
|
|
1739
|
+
preview && removal && h(Confirm, {
|
|
1740
|
+
title: `移除 ${row.name}`, label: '移除 Skill',
|
|
1741
|
+
removed: [`DSH 扫描目录中的 ${row.name}`],
|
|
1742
|
+
preserved: ['恢复目录中的 SKILL.md 和随附文件', '导入来源中的原始文件以及其他 Skill'],
|
|
1743
|
+
close: () => setRemoval(false), confirm: async () => {
|
|
1744
|
+
const result = await request('skills', { ...scope, action: 'remove', name: row.name, revision: preview.revision, confirm: row.name })
|
|
1745
|
+
setRemoval(false); removed(result.recovery); await refresh()
|
|
1746
|
+
},
|
|
1747
|
+
}))
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
function RepositorySkill({ repository, skill, scope, destination, installed, onInstall }) {
|
|
1751
|
+
const [preview, setPreview] = useState('')
|
|
1752
|
+
const [status, run, dismiss] = useAction()
|
|
1753
|
+
const selection = { ...scope, repositoryId: repository.id, commit: repository.commit, skillId: skill.id }
|
|
1754
|
+
return h('li', { className: 'dpt-repo-skill' },
|
|
1755
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1756
|
+
h('div', { className: 'dpt-row-title' }, h('strong', { className: 'dpt-ellipsis' }, skill.name),
|
|
1757
|
+
installed && pill('已安装')),
|
|
1758
|
+
h('div', { className: 'dpt-actions' },
|
|
1759
|
+
button(preview ? '关闭预览' : '预览 Skill', () => preview ? setPreview('') : run(async () => {
|
|
1760
|
+
const result = await request('skills', { ...selection, action: 'repository-preview' })
|
|
1761
|
+
setPreview(result.markdown)
|
|
1762
|
+
}), { icon: preview ? 'x' : 'eye', disabled: status.busy, 'aria-label': preview ? '关闭预览' : `预览 Skill ${skill.name}` }),
|
|
1763
|
+
button('安装', () => run(async () => {
|
|
1764
|
+
const result = await request('skills', { ...selection, action: 'repository-install', destination })
|
|
1765
|
+
await onInstall(result.name)
|
|
1766
|
+
}), { icon: 'download', disabled: installed || status.busy, 'aria-busy': status.busy, 'aria-label': `安装 ${skill.name}` }))),
|
|
1767
|
+
muted(skill.description),
|
|
1768
|
+
preview && h('pre', { className: 'dpt-mono', dir: 'ltr' }, preview),
|
|
1769
|
+
feedback(status.error ? status.message : '', true, dismiss))
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
function RepositoryRow({ repository, scope, destination, installed, disclosure, query, installFilter = 'all', update, remove, onInstall, notify }) {
|
|
1773
|
+
const [removal, setRemoval] = useState(false)
|
|
1774
|
+
const [status, run, dismiss] = useAction()
|
|
1775
|
+
const skills = repository.skills.filter(skill => {
|
|
1776
|
+
const isInstalled = installed.has(skill.name)
|
|
1777
|
+
if (installFilter === 'available' && isInstalled) return false
|
|
1778
|
+
if (installFilter === 'installed' && !isInstalled) return false
|
|
1779
|
+
return matches(query, skill.name, skill.description)
|
|
1780
|
+
})
|
|
1781
|
+
const hasRepoFilter = Boolean(query.trim()) || installFilter !== 'all'
|
|
1782
|
+
const scroller = useInfiniteScroll(skills.length, `${query}\n${installFilter}`, 35)
|
|
1783
|
+
const visibleSkills = skills.slice(0, scroller.limit)
|
|
1784
|
+
return h(DisclosureRow, {
|
|
1785
|
+
title: repository.name,
|
|
1786
|
+
detail: hasRepoFilter
|
|
1787
|
+
? `匹配 ${skills.length} / ${repository.skills.length} 个 Skill`
|
|
1788
|
+
: `${repository.skills.length} 个可安装 Skill`,
|
|
1789
|
+
badge: '已同步', tone: 'ready', ...disclosure,
|
|
1790
|
+
},
|
|
1791
|
+
h('div', { className: 'dpt-drawer-bar' },
|
|
1792
|
+
h('div', { className: 'dpt-drawer-facts' },
|
|
1793
|
+
h('span', null, '来源', h('a', { href: repository.url, target: '_blank', rel: 'noreferrer' }, 'GitHub ↗')),
|
|
1794
|
+
h('span', null, '同步时间', h('strong', null, new Date(repository.checkedAt).toLocaleString()))),
|
|
1795
|
+
h('div', { className: 'dpt-actions' },
|
|
1796
|
+
button('刷新仓库', () => run(async () => {
|
|
1797
|
+
const result = await request('skills', { action: 'repository-refresh', repositoryId: repository.id })
|
|
1798
|
+
update(result.repository)
|
|
1799
|
+
notify('仓库已同步更新')
|
|
1800
|
+
}), { icon: 'refresh-cw', disabled: status.busy, 'aria-busy': status.busy }),
|
|
1801
|
+
button('移除仓库', () => setRemoval(true), { icon: 'trash', className: 'dpt-danger', disabled: status.busy }))),
|
|
1802
|
+
h(PathLine, { value: repository.commit, label: '提交哈希' }),
|
|
1803
|
+
feedback(status.error ? status.message : '', true, dismiss),
|
|
1804
|
+
skills.length ? h('ul', { className: `dpt-repo-skills${visibleSkills.length > 10 ? ' dpt-repo-scroll' : ''}`, 'aria-label': '仓库 Skill' },
|
|
1805
|
+
visibleSkills.map(skill => h(RepositorySkill, {
|
|
1806
|
+
key: `${repository.commit}:${skill.id}:${destination}`, repository,
|
|
1807
|
+
skill, scope, destination, installed: installed.has(skill.name), onInstall,
|
|
1808
|
+
})),
|
|
1809
|
+
scroller.sentinel) :
|
|
1810
|
+
muted(hasRepoFilter ? '仓库中没有符合筛选条件的 Skill。' : '仓库中未发现 Skill。'),
|
|
1811
|
+
removal && h(Confirm, {
|
|
1812
|
+
title: `移除仓库 ${repository.name}`, label: '确认移除仓库',
|
|
1813
|
+
removed: ['工具箱中的来源记录与下载缓存'], preserved: ['已安装的 Skill 和 GitHub 仓库'],
|
|
1814
|
+
close: () => setRemoval(false), confirm: async () => {
|
|
1815
|
+
await request('skills', { action: 'repository-remove', repositoryId: repository.id, confirm: repository.id })
|
|
1816
|
+
remove(repository.id)
|
|
1817
|
+
},
|
|
1818
|
+
}))
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
function SkillRepositoryPanel({ scope, installedRows, onInstall, onRemove, notify }) {
|
|
1822
|
+
const [repositories, setRepositories] = useState(null)
|
|
1823
|
+
const [url, setUrl] = useState('')
|
|
1824
|
+
const [query, search] = useState('')
|
|
1825
|
+
const [installFilter, setInstallFilter] = useState('all')
|
|
1826
|
+
const [destination, setDestination] = useState(scope.workspaceId ? 'project' : 'personal')
|
|
1827
|
+
const [status, run, dismiss] = useAction()
|
|
1828
|
+
const [failure, setFailure] = useState('')
|
|
1829
|
+
const [added, setAdded] = useState(null)
|
|
1830
|
+
const disclosure = useDisclosure()
|
|
1831
|
+
useEffect(() => {
|
|
1832
|
+
const abort = new AbortController()
|
|
1833
|
+
request('skills', { action: 'repository-list' }, abort.signal).then(
|
|
1834
|
+
value => { if (!abort.signal.aborted) setRepositories(value.repositories) },
|
|
1835
|
+
error => { if (!abort.signal.aborted) setFailure(error.message) },
|
|
1836
|
+
)
|
|
1837
|
+
return () => abort.abort()
|
|
1838
|
+
}, [])
|
|
1839
|
+
const installed = new Set(installedRows?.map(skill => skill.name))
|
|
1840
|
+
const hasRepoFilter = Boolean(query.trim()) || installFilter !== 'all'
|
|
1841
|
+
async function add() {
|
|
1842
|
+
const { repository } = await request('skills', { action: 'repository-add', url: url.trim() })
|
|
1843
|
+
setRepositories(previous => [...(previous ?? []), repository])
|
|
1844
|
+
setAdded(repository.id); setUrl(''); setFailure('')
|
|
1845
|
+
notify(`已添加仓库 ${repository.name}`)
|
|
1846
|
+
}
|
|
1847
|
+
return h(PanelSection, { title: 'Skill 仓库', summary: repositories && `${repositories.length} 个仓库` },
|
|
1848
|
+
h('div', { className: 'dpt-card dpt-empty dpt-edit' },
|
|
1849
|
+
h('form', { className: 'dpt-form', onSubmit: e => { e.preventDefault(); void run(add) } },
|
|
1850
|
+
field('GitHub 仓库地址', h('input', {
|
|
1851
|
+
type: 'url', value: url, dir: 'ltr', className: 'dpt-mono',
|
|
1852
|
+
placeholder: 'https://github.com/owner/repo', required: true, onChange: e => setUrl(e.target.value),
|
|
1853
|
+
})),
|
|
1854
|
+
h('div', { className: 'dpt-actions' },
|
|
1855
|
+
button('添加仓库', undefined, { type: 'submit', icon: 'plus', disabled: status.busy, 'aria-busy': status.busy }))),
|
|
1856
|
+
feedback(failure, true, () => setFailure('')), feedback(status.error ? status.message : '', true, dismiss)),
|
|
1857
|
+
repositories?.length > 0 && h(React.Fragment, null,
|
|
1858
|
+
h('div', { className: 'dpt-bar' }, filterInput('搜索仓库 Skill', query, search),
|
|
1859
|
+
pick('仓库安装状态', installFilter, setInstallFilter, [
|
|
1860
|
+
option('all', '全部状态'),
|
|
1861
|
+
option('available', '仅未安装'),
|
|
1862
|
+
option('installed', '已安装'),
|
|
1863
|
+
]),
|
|
1864
|
+
pick('仓库 Skill 安装位置', destination, setDestination, [scope.workspaceId && option('project', '当前项目'), option('personal', '个人 DSH')].filter(Boolean)),
|
|
1865
|
+
hasRepoFilter && button('重置筛选', () => { search(''); setInstallFilter('all') }, { icon: 'x', iconSize: 13 })),
|
|
1866
|
+
h('ul', { className: 'dpt-card' }, repositories.map(repository => h(RepositoryRow, {
|
|
1867
|
+
key: repository.id,
|
|
1868
|
+
repository, query, installFilter, scope, destination, installed, notify,
|
|
1869
|
+
disclosure: disclosure(repository.id, added === repository.id),
|
|
1870
|
+
update: refreshed => setRepositories(previous => previous.map(item => item.id === refreshed.id ? refreshed : item)),
|
|
1871
|
+
remove: id => {
|
|
1872
|
+
setRepositories(previous => previous.filter(item => item.id !== id))
|
|
1873
|
+
onRemove()
|
|
1874
|
+
},
|
|
1875
|
+
onInstall,
|
|
1876
|
+
})))),
|
|
1877
|
+
(!repositories || !repositories.length) && empty(repositories ? '尚未添加 Skill 仓库。' : failure ? '仓库列表暂不可用。' : '正在读取 Skill 仓库…'))
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
function SkillsPanel({ workspaceList, sessionList, navigation, host, toast }) {
|
|
1881
|
+
const main = Object.values(sessionList.byId).find(item => item.retainedBy?.mainView > 0)
|
|
1882
|
+
const current = workspaceList.items.find(item => item.sessionIds.includes(main?.id) || item.path === main?.cwd)
|
|
1883
|
+
const [override, setWorkspace] = useState(null)
|
|
1884
|
+
const workspace = override ?? current?.workspaceId ?? ''
|
|
1885
|
+
const [query, search] = useState('')
|
|
1886
|
+
const [sourceFilter, setSourceFilter] = useState('all')
|
|
1887
|
+
const [permFilter, setPermFilter] = useState('all')
|
|
1888
|
+
const [rows, setRows] = useState(null)
|
|
1889
|
+
const [error, setError] = useState('')
|
|
1890
|
+
const [reloading, setReloading] = useState(false)
|
|
1891
|
+
const [importing, setImporting] = useState(false)
|
|
1892
|
+
const [library, setLibrary] = useState(false)
|
|
1893
|
+
const disclosure = useDisclosure()
|
|
1894
|
+
const scope = { workspaceId: workspace, sessionId: main?.id }
|
|
1895
|
+
const generation = useRef(0)
|
|
1896
|
+
async function refresh(signal, manual = false) {
|
|
1897
|
+
const currentGen = ++generation.current
|
|
1898
|
+
if (manual) setReloading(true)
|
|
1899
|
+
try {
|
|
1900
|
+
const { skills } = await request('skills', { ...scope, action: 'list' }, signal)
|
|
1901
|
+
if (generation.current === currentGen && !signal?.aborted) { setRows(skills); setError('') }
|
|
1902
|
+
} catch (error) {
|
|
1903
|
+
if (generation.current === currentGen && !signal?.aborted) setError(error.message)
|
|
1904
|
+
} finally {
|
|
1905
|
+
if (manual && generation.current === currentGen) setReloading(false)
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
useEffect(() => {
|
|
1909
|
+
const abort = new AbortController()
|
|
1910
|
+
setRows(null)
|
|
1911
|
+
setImporting(false)
|
|
1912
|
+
setError('')
|
|
1913
|
+
void refresh(abort.signal)
|
|
1914
|
+
return () => { generation.current++; abort.abort() }
|
|
1915
|
+
}, [workspace, main?.id])
|
|
1916
|
+
|
|
1917
|
+
const allRows = rows ?? []
|
|
1918
|
+
const editableCount = allRows.filter(row => row.editable).length
|
|
1919
|
+
const projectCount = allRows.filter(row => row.source?.startsWith('project-')).length
|
|
1920
|
+
const personalCount = allRows.filter(row => row.source?.startsWith('user-')).length
|
|
1921
|
+
const builtinPluginCount = allRows.filter(row => row.source === 'bundled' || row.source === 'runtime' || row.source === 'custom').length
|
|
1922
|
+
|
|
1923
|
+
const shown = allRows.filter(row => {
|
|
1924
|
+
if (sourceFilter === 'editable' && !row.editable) return false
|
|
1925
|
+
if (sourceFilter === 'project' && !row.source?.startsWith('project-')) return false
|
|
1926
|
+
if (sourceFilter === 'personal' && !row.source?.startsWith('user-')) return false
|
|
1927
|
+
if (sourceFilter === 'readonly' && !(row.source === 'bundled' || row.source === 'runtime' || row.source === 'custom')) return false
|
|
1928
|
+
if (permFilter === 'model' && !row.modelInvocable) return false
|
|
1929
|
+
if (permFilter === 'user' && !row.userInvocable) return false
|
|
1930
|
+
if (permFilter === 'restricted' && row.modelInvocable && row.userInvocable) return false
|
|
1931
|
+
return matches(query, row.name, row.description, skillSources[row.source] ?? '')
|
|
1932
|
+
}).sort((a, b) => (skillSourceOrder[a.source] ?? 6) - (skillSourceOrder[b.source] ?? 6))
|
|
1933
|
+
|
|
1934
|
+
const hasActiveFilter = Boolean(query.trim()) || sourceFilter !== 'all' || permFilter !== 'all'
|
|
1935
|
+
const resetFilters = () => { search(''); setSourceFilter('all'); setPermFilter('all') }
|
|
1936
|
+
const scroller = useInfiniteScroll(shown.length, `${workspace}\n${query}\n${sourceFilter}\n${permFilter}`, 50)
|
|
1937
|
+
const visibleRows = shown.slice(0, scroller.limit)
|
|
1938
|
+
const openKeys = visibleRows.filter(row => disclosure.isOpen(row.name)).map(row => row.name)
|
|
1939
|
+
|
|
1940
|
+
const groups = new Map()
|
|
1941
|
+
for (const row of visibleRows) {
|
|
1942
|
+
const title = skillSources[row.source] ?? '插件'
|
|
1943
|
+
if (!groups.has(title)) groups.set(title, [])
|
|
1944
|
+
groups.get(title).push(row)
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
return h('div', { className: 'dpt-panel' },
|
|
1948
|
+
feedback(host.error || (host.info?.skills === false ? '当前 DSH 配置未加载 Skill 服务。' : ''), true, host.dismiss),
|
|
1949
|
+
feedback(error, true, () => setError('')),
|
|
1950
|
+
h('div', { className: 'dpt-toolbar' },
|
|
1951
|
+
h(Segmented, {
|
|
1952
|
+
label: 'Skill 来源筛选', value: sourceFilter, onChange: setSourceFilter,
|
|
1953
|
+
items: [
|
|
1954
|
+
{ value: 'all', label: '全部', count: rows ? allRows.length : null },
|
|
1955
|
+
{ value: 'editable', label: '可编辑', count: rows ? editableCount : null },
|
|
1956
|
+
...(projectCount > 0 ? [{ value: 'project', label: '项目', count: projectCount }] : []),
|
|
1957
|
+
...(personalCount > 0 ? [{ value: 'personal', label: '个人', count: personalCount }] : []),
|
|
1958
|
+
{ value: 'readonly', label: '只读', count: rows ? builtinPluginCount : null },
|
|
1959
|
+
],
|
|
1960
|
+
}),
|
|
1961
|
+
h('div', { className: 'dpt-toolbar-right' },
|
|
1962
|
+
filterInput('搜索 Skill', query, search),
|
|
1963
|
+
pick('调用权限', permFilter, setPermFilter, [
|
|
1964
|
+
option('all', '全部权限'),
|
|
1965
|
+
option('model', '模型可调用'),
|
|
1966
|
+
option('user', '手动可调用'),
|
|
1967
|
+
option('restricted', '含停用限制'),
|
|
1968
|
+
]),
|
|
1969
|
+
pick('Skill 工作区', workspace, setWorkspace, [
|
|
1970
|
+
option('', '个人与全局'),
|
|
1971
|
+
...workspaceList.items.map(item => option(item.workspaceId, workspaceTitle(item))),
|
|
1972
|
+
]),
|
|
1973
|
+
hasActiveFilter && shown.length > 0 && button('重置筛选', resetFilters, { icon: 'x', iconSize: 13 }),
|
|
1974
|
+
openKeys.length >= 2 && button('收起全部', () => disclosure.collapseAll(openKeys), { icon: 'chevrons-down-up', iconSize: 13 }),
|
|
1975
|
+
iconButton('刷新 Skill', 'refresh-cw', () => refresh(undefined, true), { iconClass: reloading ? 'dpt-spin' : '', disabled: reloading, 'aria-busy': reloading }),
|
|
1976
|
+
button('仓库管理', () => setLibrary(!library), { icon: 'git-branch', 'aria-expanded': library }),
|
|
1977
|
+
primary('导入 Skill', () => setImporting(true), { icon: 'folder-plus', disabled: !rows || importing }))),
|
|
1978
|
+
library && h(SkillRepositoryPanel, {
|
|
1979
|
+
key: workspace, scope, installedRows: rows, notify: toast.show,
|
|
1980
|
+
onInstall: async name => { toast.show(`已从仓库安装 ${name}`); await refresh() },
|
|
1981
|
+
onRemove: () => toast.show('仓库已移除,已安装的 Skill 已保留'),
|
|
1982
|
+
}),
|
|
1983
|
+
importing && h('div', { className: 'dpt-card dpt-empty' }, h(SkillImport, {
|
|
1984
|
+
workspace, navigation, close: () => setImporting(false), save: async payload => {
|
|
1985
|
+
const result = await request('skills', { ...scope, action: 'import', ...payload })
|
|
1986
|
+
setImporting(false); toast.show(`已导入 ${result.name}`); await refresh()
|
|
1987
|
+
},
|
|
1988
|
+
})),
|
|
1989
|
+
shown.length ? h('ul', { className: 'dpt-card' }, [...groups].map(([title, group]) =>
|
|
1990
|
+
h(React.Fragment, { key: title }, groups.size > 1 && h('li', { className: 'dpt-subhead' }, title),
|
|
1991
|
+
group.map(row => h(SkillRow, {
|
|
1992
|
+
key: `${workspace}:${main?.id}:${row.name}`, row, scope, notify: toast.show,
|
|
1993
|
+
refresh: () => refresh(),
|
|
1994
|
+
disclosure: disclosure(row.name),
|
|
1995
|
+
removed: value => toast.show(h(React.Fragment, null,
|
|
1996
|
+
h('p', null, `已移除 ${row.name} 至恢复目录`),
|
|
1997
|
+
h(PathLine, { value, label: '恢复目录' })), { sticky: true }),
|
|
1998
|
+
})))), scroller.sentinel)
|
|
1999
|
+
: empty(rows ? '没有符合条件的 Skill。' : error ? 'Skill 列表暂不可用。' : '正在发现 Skill…', rows && hasActiveFilter ? resetFilters : undefined))
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
function PowerToolsHelp({ host, tab, embedded }) {
|
|
2003
|
+
const disclosure = useDisclosure()
|
|
2004
|
+
const status = enabled => enabled === undefined ? '等待检查' : enabled ? '可用' : '不可用'
|
|
2005
|
+
const usage = {
|
|
2006
|
+
sessions: '悬停会话行可直接打开、归档或删除;行首勾选(支持 Shift 连选)呼出底部悬浮批量操作条。',
|
|
2007
|
+
mcp: '行尾开关可一键启停用户配置的服务器;点击行查看探测工具列表与连接详情。',
|
|
2008
|
+
skills: h(React.Fragment, null, '可编辑的项目与个人 Skill 置顶展示,展开行可直接切换模型/手动调用开关。'),
|
|
2009
|
+
}
|
|
2010
|
+
return h('ul', { className: 'dpt-card dpt-maintenance', 'aria-label': '使用与诊断' },
|
|
2011
|
+
h(DisclosureRow, {
|
|
2012
|
+
title: '使用与诊断',
|
|
2013
|
+
tag: host.info?.version ? `v${host.info.version}` : undefined,
|
|
2014
|
+
...disclosure('help'),
|
|
2015
|
+
},
|
|
2016
|
+
muted(usage[tab]),
|
|
2017
|
+
facts([['插件版本', host.info?.version ? code(host.info.version) : '—'],
|
|
2018
|
+
['MCP 管理', status(host.info?.mcp)], ['Skill 管理', status(host.info?.skills)],
|
|
2019
|
+
['提示词增强', status(host.info?.enhance)], ['会话清理', status(host.info?.sessionDelete)]]),
|
|
2020
|
+
host.info?.profilePath && h('div', { className: 'dpt-drawer-split' },
|
|
2021
|
+
h('h3', null, 'Profile 配置'), h(PathLine, { value: host.info.profilePath })),
|
|
2022
|
+
embedded && h('div', { className: 'dpt-drawer-split' },
|
|
2023
|
+
h('h3', null, '会话与工作区偏好'), muted('工具箱尚无已保存的覆盖规则。')),
|
|
2024
|
+
h('div', { className: 'dpt-actions' }, button('重新检查宿主', host.check, { icon: 'refresh-cw', disabled: host.loading, 'aria-busy': host.loading }))))
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
function PowerTools({ useSessions, useWorkspaces, navigation, refresh, embedded = false }) {
|
|
2028
|
+
const [tab, select] = useState('sessions')
|
|
2029
|
+
const sessionList = useSessions(identity)
|
|
2030
|
+
const workspaceList = useWorkspaces(identity)
|
|
2031
|
+
const host = useHostStatus()
|
|
2032
|
+
const toast = useToast()
|
|
2033
|
+
const controls = h('div', { className: 'dpt-controls' },
|
|
2034
|
+
h('nav', { className: 'dpt-nav', 'aria-label': '工具箱功能' },
|
|
2035
|
+
[['sessions', '会话', 'message-square'], ['mcp', 'MCP', 'plug'], ['skills', 'Skill', 'wand-sparkles']].map(([id, label, icon]) =>
|
|
2036
|
+
button(label, () => select(id), { key: id, icon, className: 'dpt-tab', 'aria-pressed': tab === id }))),
|
|
2037
|
+
tab === 'sessions' ? h(SessionPanel, { sessionList, workspaceList, navigation, refresh, host, toast })
|
|
2038
|
+
: tab === 'mcp' ? h(McpPanel, { host, toast }) : h(SkillsPanel, { sessionList, workspaceList, navigation, host, toast }),
|
|
2039
|
+
h(PowerToolsHelp, { host, tab, embedded }),
|
|
2040
|
+
toast.node)
|
|
2041
|
+
const stylesheet = h('style', null, css)
|
|
2042
|
+
if (embedded) return h('div', { className: 'dpt dpt-inline' }, stylesheet, controls)
|
|
2043
|
+
return h('main', { className: 'dpt dpt-page' }, stylesheet, h('div', { className: 'dpt-page-inner' },
|
|
2044
|
+
h('header', { className: 'dpt-page-head' },
|
|
2045
|
+
h('div', { className: 'dpt-page-icon' }, h(PowerToolsIcon, { size: 18 })), h('h1', null, '工具箱')),
|
|
2046
|
+
controls))
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
function PowerToolsConfig(props) {
|
|
2050
|
+
return props.view === 'page' ? h(PowerTools, { ...props, embedded: true }) : null
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
function Enhance({ useInput, inputActions, sessionId }) {
|
|
2054
|
+
const input = useInput(identity)
|
|
2055
|
+
const [requesting, setRequesting] = useState(false)
|
|
2056
|
+
const [undo, setUndo] = useState(null)
|
|
2057
|
+
const [error, setError] = useState('')
|
|
2058
|
+
const [sendClass, setSendClass] = useState('')
|
|
2059
|
+
const pending = useRef(null)
|
|
2060
|
+
const rootRef = useRef(null)
|
|
2061
|
+
const draft = input?.draft ?? ''
|
|
2062
|
+
const plain = input?.phase === 'plain' && !input?.occurrences?.length
|
|
2063
|
+
const allowed = plain && draft.trim() && !/^\s*\/\S/.test(draft) && typeof inputActions?.insertText === 'function'
|
|
2064
|
+
|
|
2065
|
+
useLayoutEffect(() => {
|
|
2066
|
+
const root = rootRef.current
|
|
2067
|
+
const card = root.closest('[data-composer-card]')
|
|
2068
|
+
// The host marks the primary action with aria-busy on both release lines.
|
|
2069
|
+
const primaryButton = ':scope > button[aria-busy]:not(.dpt-composer-action)'
|
|
2070
|
+
let toolbar = root.parentElement
|
|
2071
|
+
while (toolbar && toolbar !== card && !toolbar.querySelector(primaryButton)) toolbar = toolbar.parentElement
|
|
2072
|
+
if (!toolbar || toolbar === card) return
|
|
2073
|
+
const sync = () => setSendClass(toolbar.querySelector(primaryButton)?.className ?? '')
|
|
2074
|
+
const observer = new MutationObserver(sync)
|
|
2075
|
+
observer.observe(toolbar, { childList: true })
|
|
2076
|
+
sync()
|
|
2077
|
+
return () => observer.disconnect()
|
|
2078
|
+
}, [])
|
|
2079
|
+
|
|
2080
|
+
useEffect(() => () => { pending.current?.abort(); pending.current = null }, [sessionId])
|
|
2081
|
+
useEffect(() => { setError('') }, [input?.draftRev, sessionId])
|
|
2082
|
+
useEffect(() => {
|
|
2083
|
+
if (pending.current && (pending.current.revision !== input?.draftRev || !plain || pending.current.sessionId !== sessionId)) {
|
|
2084
|
+
pending.current.abort(); pending.current = null; setRequesting(false)
|
|
2085
|
+
}
|
|
2086
|
+
if (undo && (undo.revision !== input?.draftRev || !plain || undo.sessionId !== sessionId)) setUndo(null)
|
|
2087
|
+
}, [input?.draftRev, plain, sessionId, undo])
|
|
2088
|
+
|
|
2089
|
+
function focusComposer() {
|
|
2090
|
+
const card = rootRef.current?.closest('[data-composer-card]')
|
|
2091
|
+
const editor = card?.querySelector('[contenteditable="true"][role="textbox"]')
|
|
2092
|
+
if (editor instanceof HTMLElement) editor.focus()
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
async function enhance() {
|
|
2096
|
+
if (!allowed || pending.current) return
|
|
2097
|
+
const controller = new AbortController()
|
|
2098
|
+
const revision = inputActions.captureInsertion().draftRev
|
|
2099
|
+
if (revision !== input.draftRev) return
|
|
2100
|
+
const active = { revision, sessionId, abort: () => controller.abort() }
|
|
2101
|
+
pending.current = active
|
|
2102
|
+
setError(''); setRequesting(true)
|
|
2103
|
+
try {
|
|
2104
|
+
const result = await request('enhance', { draft, sessionId }, AbortSignal.any([controller.signal, AbortSignal.timeout(48_000)]))
|
|
2105
|
+
if (pending.current === active && inputActions.captureInsertion().draftRev === revision) {
|
|
2106
|
+
if (inputActions.insertText(result.text, { start: 0, end: draft.length, draftRev: revision })) {
|
|
2107
|
+
const nextRev = inputActions.captureInsertion().draftRev
|
|
2108
|
+
setUndo({
|
|
2109
|
+
sessionId, revision: nextRev, original: draft, enhanced: result.text,
|
|
2110
|
+
model: result.model, contextTurns: result.contextTurns ?? 0,
|
|
2111
|
+
})
|
|
2112
|
+
focusComposer()
|
|
2113
|
+
} else setError('草稿已变化,请重新增强。')
|
|
2114
|
+
}
|
|
2115
|
+
} catch (error) {
|
|
2116
|
+
if (pending.current === active && !controller.signal.aborted) setError(error.message)
|
|
2117
|
+
} finally {
|
|
2118
|
+
if (pending.current === active) { pending.current = null; setRequesting(false) }
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
function revert() {
|
|
2123
|
+
if (!undo || undo.sessionId !== sessionId) return
|
|
2124
|
+
if (plain && undo.revision === inputActions.captureInsertion().draftRev && draft === undo.enhanced) {
|
|
2125
|
+
inputActions.insertText(undo.original, { start: 0, end: undo.enhanced.length, draftRev: undo.revision })
|
|
2126
|
+
focusComposer()
|
|
2127
|
+
}
|
|
2128
|
+
setUndo(null)
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
const keepFocus = e => e.preventDefault()
|
|
2132
|
+
const actionClass = 'dpt-composer-action ' + (sendClass || 'dpt-composer-action--fallback')
|
|
2133
|
+
|
|
2134
|
+
return h('div', { ref: rootRef, className: 'dpt dpt-composer' }, h('style', null, css),
|
|
2135
|
+
feedback(error, true, () => setError('')),
|
|
2136
|
+
undo && h('button', {
|
|
2137
|
+
type: 'button', className: actionClass + ' dpt-composer-undo', 'aria-label': '撤销增强',
|
|
2138
|
+
title: undo.model
|
|
2139
|
+
? `撤销增强(已由 ${undo.model} 改写${undo.contextTurns > 0 ? `,参考最近 ${undo.contextTurns} 条上下文` : ''})`
|
|
2140
|
+
: '撤销增强',
|
|
2141
|
+
onMouseDown: keepFocus, onClick: revert,
|
|
2142
|
+
}, h(Icon, { name: 'undo', size: 16 })),
|
|
2143
|
+
requesting
|
|
2144
|
+
? h('button', {
|
|
2145
|
+
type: 'button', className: actionClass, 'aria-label': '取消增强', title: '取消增强',
|
|
2146
|
+
'aria-busy': true, onMouseDown: keepFocus,
|
|
2147
|
+
onClick: () => { pending.current?.abort(); pending.current = null; setRequesting(false) },
|
|
2148
|
+
}, h(Icon, { name: 'loader', size: 16, className: 'dpt-spin' }))
|
|
2149
|
+
: h('button', {
|
|
2150
|
+
type: 'button', className: actionClass, 'aria-label': '增强',
|
|
2151
|
+
title: '使用当前主对话模型结合近期上下文改写草稿', disabled: !allowed,
|
|
2152
|
+
onMouseDown: keepFocus, onClick: enhance,
|
|
2153
|
+
}, h(Icon, { name: 'enhance', size: 16 })))
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
function EnhanceSlot(props) {
|
|
2157
|
+
if (!props.useInput || !props.inputActions || !props.sessionId) return null
|
|
2158
|
+
return h(Enhance, { key: props.sessionId, ...props })
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
function PowerToolsIcon({ size = 16 }) {
|
|
2162
|
+
return h(Icon, { name: 'layout-grid', size })
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
return {
|
|
2166
|
+
inject: ['slots', 'uiWorkspace', 'sessions'],
|
|
2167
|
+
apply(ctx) {
|
|
2168
|
+
const panelProps = () => ({ navigation: ctx.uiWorkspace, refresh: () => ctx.sessions.refresh() })
|
|
2169
|
+
ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL, inject: panelProps }, PowerTools))
|
|
2170
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({ name: 'plugins.bundle.config', key: PANEL, inject: panelProps }, PowerToolsConfig))
|
|
2171
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({ name: 'sidebar.panellist', id: PANEL, order: 20, label: '工具箱' }, PowerToolsIcon))
|
|
2172
|
+
ctx.slots.inject('conversation.input.activity', () => ctx.slots.register({
|
|
2173
|
+
name: 'conversation.input.activity', id: PANEL, order: 15,
|
|
2174
|
+
inject: sessionId => ({ sessionId }),
|
|
2175
|
+
}, EnhanceSlot))
|
|
2176
|
+
},
|
|
2177
|
+
}
|
|
2178
|
+
},
|
|
2179
|
+
})
|