dsh-efm-integration 0.4.1 → 0.4.5

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/client.js CHANGED
@@ -1,356 +1,525 @@
1
- window.__ModuleLoader__.load({
2
- id: 'dsh-efm-integration',
3
- factory: (require) => {
4
- const module = { exports: {} }
5
- const exports = module.exports
6
- const React = require('react')
7
- const { useEffect, useState } = React
8
- const ARCHIVE_PANEL_ID = 'dsh-efm-integration-archive-cleaner'
9
- const ARCHIVE_ENDPOINT = '/plugins/dsh-efm-integration/archived-sessions'
10
- const LSP_PANEL_ID = 'dsh-efm-integration-lsp-servers'
11
- const LSP_ENDPOINT = '/plugins/dsh-efm-integration/lsp-servers'
12
- const LSP_CONFIRM_VALUE = 'LSP_SERVER_CHANGE'
13
-
14
- // The host renders `main` panels inside a flex column with `overflow: hidden`
15
- // (ui-layout AppFrame: .centerCol / .mainPanel), so a page must fill the
16
- // panel and scroll itself; viewport units and host-level scrolling do not
17
- // exist here.
18
- const pageStyle = {
19
- flex: 1,
20
- minHeight: 0,
21
- width: '100%',
22
- overflowY: 'auto',
23
- display: 'flex',
24
- justifyContent: 'center',
25
- alignItems: 'flex-start',
26
- padding: '32px 24px 56px',
27
- boxSizing: 'border-box',
28
- background: 'var(--dsh-color-bg, #111)',
29
- color: 'var(--dsh-color-text, #eee)',
30
- }
31
- const cardStyle = {
32
- width: '100%',
33
- maxWidth: '820px',
34
- border: '1px solid #5554',
35
- borderRadius: '16px',
36
- padding: '28px',
37
- boxSizing: 'border-box',
38
- }
39
- const noticeStyle = {
40
- background: '#7a3d0033', border: '1px solid #e39b4c66', borderRadius: '10px', padding: '12px', marginBottom: '16px',
41
- }
42
-
43
- async function lspPost(body) {
44
- const response = await fetch(LSP_ENDPOINT, {
45
- method: 'POST',
46
- headers: {
47
- accept: 'application/json',
48
- 'content-type': 'application/json',
49
- 'x-dsh-efm-integration-confirm': LSP_CONFIRM_VALUE,
50
- },
51
- body: JSON.stringify(body),
52
- })
53
- const payload = await response.json()
54
- if (!response.ok) throw new Error(payload.error || '语言服务器操作失败')
55
- return payload
56
- }
57
-
58
- function ArchiveCleanerPage() {
59
- const [state, setState] = useState({ loading: true, count: 0, archivedCount: 0, blocked: [], error: '' })
60
- const [busy, setBusy] = useState(false)
61
-
62
- useEffect(() => {
63
- const controller = new AbortController()
64
- fetch(ARCHIVE_ENDPOINT, { signal: controller.signal, headers: { accept: 'application/json' } })
65
- .then(async response => {
66
- const body = await response.json()
67
- if (!response.ok) throw new Error(body.error || '无法读取存档会话')
68
- setState({ loading: false, count: body.count, archivedCount: body.archivedCount, blocked: body.blocked || [], error: '' })
69
- })
70
- .catch(error => {
71
- if (controller.signal.aborted) return
72
- setState(current => ({ ...current, loading: false, error: String(error.message || error) }))
73
- })
74
- return () => controller.abort()
75
- }, [])
76
-
77
- const clear = async () => {
78
- if (state.count === 0) return
79
- const confirmed = window.confirm(
80
- `将永久删除 ${state.count} 个存档会话(含子会话),删除后无法恢复。\n\n共享附件和工作区文件会保留。确定继续吗?`,
81
- )
82
- if (!confirmed) return
83
- setBusy(true)
84
- setState(current => ({ ...current, error: '' }))
85
- try {
86
- const response = await fetch(ARCHIVE_ENDPOINT, {
87
- method: 'POST',
88
- headers: {
89
- accept: 'application/json',
90
- 'content-type': 'application/json',
91
- 'x-dsh-efm-integration-confirm': 'DELETE_ALL_ARCHIVED',
92
- },
93
- body: '{}',
94
- })
95
- const body = await response.json()
96
- if (!response.ok || (body.failures && body.failures.length > 0)) {
97
- throw new Error(
98
- body.error
99
- || body.blocked?.map(reason => `暂不能删除:${reason}`).join('\n')
100
- || body.failures?.map(failure => `${failure.sessionId}: ${failure.message}`).join('\n')
101
- || '删除失败',
102
- )
103
- }
104
- window.location.reload()
105
- } catch (error) {
106
- setBusy(false)
107
- setState(current => ({ ...current, error: String(error.message || error) }))
108
- }
109
- }
110
-
111
- return React.createElement('main', { style: pageStyle }, React.createElement('section', {
112
- style: { ...cardStyle, maxWidth: '640px' },
113
- },
114
- React.createElement('h1', { style: { margin: '0 0 12px', fontSize: '24px' } }, '清空全部存档会话'),
115
- React.createElement('p', { style: { color: '#aaa', lineHeight: 1.7 } },
116
- '永久删除所有归档会话及其子 Agent 日志。共享附件和工作区文件不会被删除,操作无法撤销。'),
117
- React.createElement('p', { style: { fontSize: '18px', fontWeight: 600 } },
118
- state.loading ? '正在统计…' : `当前共有 ${state.count} 个会话(${state.archivedCount} 个归档根会话)`),
119
- state.blocked.length > 0 && React.createElement('div', { style: noticeStyle },
120
- '暂不能删除:', React.createElement('ul', null, state.blocked.map((item, index) => React.createElement('li', { key: index }, item)))),
121
- state.error && React.createElement('pre', {
122
- style: { color: '#ff8989', whiteSpace: 'pre-wrap', background: '#f003', padding: '12px', borderRadius: '10px' },
123
- }, state.error),
124
- React.createElement('button', {
125
- type: 'button',
126
- disabled: busy || state.loading || state.count === 0 || state.blocked.length > 0,
127
- onClick: clear,
128
- style: {
129
- appearance: 'none', border: 0, borderRadius: '10px', background: '#d94747', color: 'white',
130
- cursor: 'pointer', fontSize: '15px', fontWeight: 600, opacity: busy || state.count === 0 ? 0.45 : 1,
131
- padding: '12px 18px', marginTop: '10px',
132
- },
133
- }, busy ? '正在永久删除…' : '永久删除全部存档会话'),
134
- ))
135
- }
136
-
137
- function LspServersPage() {
138
- const empty = { loading: true, error: '', presets: [], servers: [], allowCustomServers: false, toolMount: 'lazy', toolMounted: false, restartHint: '' }
139
- const [state, setState] = useState(empty)
140
- const [draft, setDraft] = useState({ name: '', command: '', args: '', extensions: '' })
141
- const [busy, setBusy] = useState(false)
142
-
143
- const apply = (payload) => setState({
144
- loading: false,
145
- error: '',
146
- presets: payload.presets || [],
147
- servers: payload.servers || [],
148
- allowCustomServers: payload.allowCustomServers === true,
149
- toolMount: payload.toolMount || 'lazy',
150
- toolMounted: payload.toolMounted === true,
151
- restartHint: payload.restartHint || '',
152
- })
153
-
154
- useEffect(() => {
155
- const controller = new AbortController()
156
- fetch(LSP_ENDPOINT, { signal: controller.signal, headers: { accept: 'application/json' } })
157
- .then(async response => {
158
- const body = await response.json()
159
- if (!response.ok) throw new Error(body.error || '无法读取语言服务器配置')
160
- apply(body)
161
- })
162
- .catch(error => {
163
- if (controller.signal.aborted) return
164
- setState(current => ({ ...current, loading: false, error: String(error.message || error) }))
165
- })
166
- return () => controller.abort()
167
- }, [])
168
-
169
- const run = async (body, confirmText) => {
170
- if (confirmText && !window.confirm(confirmText)) return
171
- setBusy(true)
172
- setState(current => ({ ...current, error: '' }))
173
- try {
174
- apply(await lspPost(body))
175
- } catch (error) {
176
- setState(current => ({ ...current, error: String(error.message || error) }))
177
- }
178
- setBusy(false)
179
- }
180
-
181
- const addCustom = async () => {
182
- const extensions = {}
183
- draft.extensions.split(',').map(item => item.trim()).filter(Boolean).forEach((pair) => {
184
- const [ext, language] = pair.split('=').map(part => (part || '').trim())
185
- if (ext && language) extensions[ext] = language
186
- })
187
- await run({
188
- action: 'add',
189
- server: {
190
- name: draft.name.trim(),
191
- command: draft.command.trim(),
192
- args: draft.args.split(/\s+/).filter(Boolean),
193
- extensions,
194
- },
195
- })
196
- }
197
-
198
- const statusLabel = (status) => status === 'active' ? '已启用' : status === 'disabled' ? '已停用' : '启动失败'
199
-
200
- return React.createElement('main', { style: pageStyle }, React.createElement('section', { style: cardStyle },
201
- React.createElement('h1', { style: { margin: '0 0 12px', fontSize: '24px' } }, '语言服务器'),
202
- React.createElement('p', { style: { color: '#aaa', lineHeight: 1.7 } },
203
- '为 DSH 的 lsp 工具注册语义导航(定义、引用、实现、悬停)。启用或停用立即生效,无需重启;',
204
- '语言服务器进程要彻底回收,需要重启 DSH。'),
205
- state.loading && React.createElement('p', null, '正在读取配置…'),
206
- React.createElement('p', { style: { fontSize: '15px' } },
207
- `lsp 工具:${state.toolMounted ? '已挂载' : '未挂载'}(模式:${state.toolMount === 'always' ? '常驻' : '按需'})`),
208
- state.restartHint && React.createElement('div', { style: noticeStyle }, state.restartHint),
209
- state.error && React.createElement('pre', {
210
- style: { color: '#ff8989', whiteSpace: 'pre-wrap', background: '#f003', padding: '12px', borderRadius: '10px' },
211
- }, state.error),
212
-
213
- React.createElement('h2', { style: { fontSize: '18px', margin: '20px 0 8px' } }, '内置语言服务器'),
214
- React.createElement('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } },
215
- state.presets.map((preset) => React.createElement('li', {
216
- key: preset.id,
217
- style: { borderBottom: '1px solid #5553', padding: '12px 0', display: 'flex', gap: '12px', alignItems: 'center' },
218
- },
219
- React.createElement('div', { style: { flex: 1 } },
220
- React.createElement('strong', null, preset.label),
221
- React.createElement('div', { style: { color: '#999', fontSize: '13px' } },
222
- Object.keys(preset.extensions || {}).join(' ')),
223
- React.createElement('div', { style: { fontSize: '13px', color: preset.installed ? '#7fd08a' : '#e0a06b' } },
224
- preset.installed ? `已找到:${preset.source || preset.command}` : `未安装 · ${preset.installHint}`)),
225
- React.createElement('button', {
226
- type: 'button',
227
- disabled: busy,
228
- onClick: () => run(preset.enabled
229
- ? { action: 'disable', preset: preset.id, name: preset.name }
230
- : { action: 'enable', preset: preset.id, name: preset.name }),
231
- style: {
232
- appearance: 'none', border: 0, borderRadius: '8px', padding: '8px 14px', cursor: 'pointer',
233
- background: preset.enabled ? '#5a2626' : '#1f6f43', color: 'white',
234
- },
235
- }, preset.enabled ? '停用' : '启用'),
236
- )),
237
- ),
238
-
239
- React.createElement('h2', { style: { fontSize: '18px', margin: '20px 0 8px' } }, '已配置条目'),
240
- state.servers.length === 0
241
- ? React.createElement('p', { style: { color: '#888' } }, '暂无条目。')
242
- : React.createElement('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } },
243
- state.servers.map((server) => React.createElement('li', {
244
- key: server.name,
245
- style: { borderBottom: '1px solid #5553', padding: '10px 0', display: 'flex', gap: '12px', alignItems: 'center' },
246
- },
247
- React.createElement('div', { style: { flex: 1 } },
248
- React.createElement('strong', null, server.name),
249
- React.createElement('span', { style: { marginLeft: '8px', fontSize: '13px', color: '#999' } },
250
- statusLabel(server.status)),
251
- server.error && React.createElement('div', { style: { fontSize: '13px', color: '#e0a06b' } }, server.error)),
252
- server.preset === undefined && React.createElement('button', {
253
- type: 'button',
254
- disabled: busy,
255
- onClick: () => run({ action: 'remove', name: server.name }, `删除自定义语言服务器 ${server.name}?`),
256
- style: {
257
- appearance: 'none', border: 0, borderRadius: '8px', padding: '8px 14px', cursor: 'pointer',
258
- background: '#5a2626', color: 'white',
259
- },
260
- }, '删除'),
261
- )),
262
- ),
263
-
264
- state.allowCustomServers && React.createElement('div', { style: { marginTop: '20px' } },
265
- React.createElement('h2', { style: { fontSize: '18px', margin: '0 0 8px' } }, '添加自定义语言服务器'),
266
- React.createElement('p', { style: { color: '#aaa', fontSize: '13px' } },
267
- '自定义命令会直接启动本机可执行文件,请只添加你信任的程序。'),
268
- ['name', 'command', 'args', 'extensions'].map((field) => React.createElement('label', {
269
- key: field, style: { display: 'block', marginBottom: '8px' },
270
- },
271
- React.createElement('span', { style: { fontSize: '13px', color: '#999' } }, {
272
- name: '名称(小写字母、数字、连字符)',
273
- command: '可执行文件(绝对路径或 PATH 名称)',
274
- args: '参数(空格分隔)',
275
- extensions: '扩展名映射(例:.ts=typescript,.tsx=typescriptreact)',
276
- }[field]),
277
- React.createElement('input', {
278
- value: draft[field],
279
- onChange: event => setDraft(current => ({ ...current, [field]: event.target.value })),
280
- style: { width: '100%', boxSizing: 'border-box', padding: '8px', borderRadius: '8px', border: '1px solid #555' },
281
- }),
282
- )),
283
- React.createElement('button', {
284
- type: 'button',
285
- disabled: busy || !draft.name.trim() || !draft.command.trim(),
286
- onClick: addCustom,
287
- style: {
288
- appearance: 'none', border: 0, borderRadius: '8px', padding: '10px 16px', cursor: 'pointer',
289
- background: '#1f6f43', color: 'white',
290
- },
291
- }, '添加并启用'))
292
- , !state.allowCustomServers && React.createElement('p', {
293
- style: { color: '#888', fontSize: '13px', marginTop: '16px' },
294
- }, '自定义命令未启用:如需添加,请在 cordis.patch.yml 的 dsh-efm-integration-lsp-servers 行设置 allowCustomServers: true 并重启 DSH。'),
295
-
296
- React.createElement('button', {
297
- type: 'button',
298
- disabled: busy,
299
- onClick: () => run({ action: 'restart' }),
300
- style: {
301
- appearance: 'none', border: '1px solid #5557', borderRadius: '8px', padding: '10px 16px',
302
- cursor: 'pointer', background: 'transparent', color: 'inherit', marginTop: '18px',
303
- },
304
- }, '查看重启提示'),
305
- ))
306
- }
307
-
308
- function TrashIcon({ size = 16 }) {
309
- return React.createElement('svg', {
310
- width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
311
- stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
312
- 'aria-hidden': 'true',
313
- },
314
- React.createElement('path', { d: 'M4 7h16M9 7V4h6v3M7 7l1 13h8l1-13M10 11v5M14 11v5' }))
315
- }
316
-
317
- function CodeIcon({ size = 16 }) {
318
- return React.createElement('svg', {
319
- width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
320
- stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
321
- 'aria-hidden': 'true',
322
- },
323
- React.createElement('path', { d: 'M9 7l-5 5 5 5M15 7l5 5-5 5' }))
324
- }
325
-
326
- function apply(ctx) {
327
- ctx.slots.inject('main', () => ctx.slots.register({
328
- name: 'main',
329
- key: ARCHIVE_PANEL_ID,
330
- }, ArchiveCleanerPage))
331
- ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
332
- name: 'sidebar.panellist',
333
- id: ARCHIVE_PANEL_ID,
334
- order: 20,
335
- label: '清空全部存档会话',
336
- }, TrashIcon))
337
- ctx.slots.inject('main', () => ctx.slots.register({
338
- name: 'main',
339
- key: LSP_PANEL_ID,
340
- }, LspServersPage))
341
- ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
342
- name: 'sidebar.panellist',
343
- id: LSP_PANEL_ID,
344
- order: 21,
345
- label: '语言服务器',
346
- }, CodeIcon))
347
- }
348
-
349
- module.exports = {
350
- name: 'dsh-efm-integration-archive-cleaner',
351
- inject: ['slots'],
352
- apply,
353
- }
354
- return module.exports
355
- },
356
- })
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-efm-integration',
3
+ factory: (require) => {
4
+ const module = { exports: {} }
5
+ const exports = module.exports
6
+ const React = require('react')
7
+ const { useEffect, useState } = React
8
+ const ARCHIVE_PANEL_ID = 'dsh-efm-integration-archive-cleaner'
9
+ const ARCHIVE_ENDPOINT = '/plugins/dsh-efm-integration/archived-sessions'
10
+ const LSP_PANEL_ID = 'dsh-efm-integration-lsp-servers'
11
+ const LSP_ENDPOINT = '/plugins/dsh-efm-integration/lsp-servers'
12
+ const LSP_CONFIRM_VALUE = 'LSP_SERVER_CHANGE'
13
+ const SYSTEM_PROMPT_PANEL_ID = 'dsh-efm-integration-system-prompt'
14
+ const SYSTEM_PROMPT_ENDPOINT = '/plugins/dsh-efm-integration/system-prompt'
15
+ const SYSTEM_PROMPT_CONFIRM_VALUE = 'SYSTEM_PROMPT_CHANGE'
16
+
17
+ // The host renders `main` panels inside a flex column with `overflow: hidden`
18
+ // (ui-layout AppFrame: .centerCol / .mainPanel), so a page must fill the
19
+ // panel and scroll itself; viewport units and host-level scrolling do not
20
+ // exist here.
21
+ const pageStyle = {
22
+ flex: 1,
23
+ minHeight: 0,
24
+ width: '100%',
25
+ overflowY: 'auto',
26
+ display: 'flex',
27
+ justifyContent: 'center',
28
+ alignItems: 'flex-start',
29
+ padding: '32px 24px 56px',
30
+ boxSizing: 'border-box',
31
+ background: 'var(--dsh-color-bg, #111)',
32
+ color: 'var(--dsh-color-text, #eee)',
33
+ }
34
+ const cardStyle = {
35
+ width: '100%',
36
+ maxWidth: '820px',
37
+ border: '1px solid #5554',
38
+ borderRadius: '16px',
39
+ padding: '28px',
40
+ boxSizing: 'border-box',
41
+ }
42
+ const noticeStyle = {
43
+ background: '#7a3d0033', border: '1px solid #e39b4c66', borderRadius: '10px', padding: '12px', marginBottom: '16px',
44
+ }
45
+
46
+ async function lspPost(body) {
47
+ const response = await fetch(LSP_ENDPOINT, {
48
+ method: 'POST',
49
+ headers: {
50
+ accept: 'application/json',
51
+ 'content-type': 'application/json',
52
+ 'x-dsh-efm-integration-confirm': LSP_CONFIRM_VALUE,
53
+ },
54
+ body: JSON.stringify(body),
55
+ })
56
+ const payload = await response.json()
57
+ if (!response.ok) throw new Error(payload.error || '语言服务器操作失败')
58
+ return payload
59
+ }
60
+
61
+ function ArchiveCleanerPage() {
62
+ const [state, setState] = useState({ loading: true, count: 0, archivedCount: 0, blocked: [], error: '' })
63
+ const [busy, setBusy] = useState(false)
64
+
65
+ useEffect(() => {
66
+ const controller = new AbortController()
67
+ fetch(ARCHIVE_ENDPOINT, { signal: controller.signal, headers: { accept: 'application/json' } })
68
+ .then(async response => {
69
+ const body = await response.json()
70
+ if (!response.ok) throw new Error(body.error || '无法读取存档会话')
71
+ setState({ loading: false, count: body.count, archivedCount: body.archivedCount, blocked: body.blocked || [], error: '' })
72
+ })
73
+ .catch(error => {
74
+ if (controller.signal.aborted) return
75
+ setState(current => ({ ...current, loading: false, error: String(error.message || error) }))
76
+ })
77
+ return () => controller.abort()
78
+ }, [])
79
+
80
+ const clear = async () => {
81
+ if (state.count === 0) return
82
+ const confirmed = window.confirm(
83
+ `将永久删除 ${state.count} 个存档会话(含子会话),删除后无法恢复。\n\n共享附件和工作区文件会保留。确定继续吗?`,
84
+ )
85
+ if (!confirmed) return
86
+ setBusy(true)
87
+ setState(current => ({ ...current, error: '' }))
88
+ try {
89
+ const response = await fetch(ARCHIVE_ENDPOINT, {
90
+ method: 'POST',
91
+ headers: {
92
+ accept: 'application/json',
93
+ 'content-type': 'application/json',
94
+ 'x-dsh-efm-integration-confirm': 'DELETE_ALL_ARCHIVED',
95
+ },
96
+ body: '{}',
97
+ })
98
+ const body = await response.json()
99
+ if (!response.ok || (body.failures && body.failures.length > 0)) {
100
+ throw new Error(
101
+ body.error
102
+ || body.blocked?.map(reason => `暂不能删除:${reason}`).join('\n')
103
+ || body.failures?.map(failure => `${failure.sessionId}: ${failure.message}`).join('\n')
104
+ || '删除失败',
105
+ )
106
+ }
107
+ window.location.reload()
108
+ } catch (error) {
109
+ setBusy(false)
110
+ setState(current => ({ ...current, error: String(error.message || error) }))
111
+ }
112
+ }
113
+
114
+ return React.createElement('main', { style: pageStyle }, React.createElement('section', {
115
+ style: { ...cardStyle, maxWidth: '640px' },
116
+ },
117
+ React.createElement('h1', { style: { margin: '0 0 12px', fontSize: '24px' } }, '清空全部存档会话'),
118
+ React.createElement('p', { style: { color: '#aaa', lineHeight: 1.7 } },
119
+ '永久删除所有归档会话及其子 Agent 日志。共享附件和工作区文件不会被删除,操作无法撤销。'),
120
+ React.createElement('p', { style: { fontSize: '18px', fontWeight: 600 } },
121
+ state.loading ? '正在统计…' : `当前共有 ${state.count} 个会话(${state.archivedCount} 个归档根会话)`),
122
+ state.blocked.length > 0 && React.createElement('div', { style: noticeStyle },
123
+ '暂不能删除:', React.createElement('ul', null, state.blocked.map((item, index) => React.createElement('li', { key: index }, item)))),
124
+ state.error && React.createElement('pre', {
125
+ style: { color: '#ff8989', whiteSpace: 'pre-wrap', background: '#f003', padding: '12px', borderRadius: '10px' },
126
+ }, state.error),
127
+ React.createElement('button', {
128
+ type: 'button',
129
+ disabled: busy || state.loading || state.count === 0 || state.blocked.length > 0,
130
+ onClick: clear,
131
+ style: {
132
+ appearance: 'none', border: 0, borderRadius: '10px', background: '#d94747', color: 'white',
133
+ cursor: 'pointer', fontSize: '15px', fontWeight: 600, opacity: busy || state.count === 0 ? 0.45 : 1,
134
+ padding: '12px 18px', marginTop: '10px',
135
+ },
136
+ }, busy ? '正在永久删除…' : '永久删除全部存档会话'),
137
+ ))
138
+ }
139
+
140
+ function LspServersPage() {
141
+ const empty = { loading: true, error: '', presets: [], servers: [], allowCustomServers: false, toolMount: 'lazy', toolMounted: false, restartHint: '' }
142
+ const [state, setState] = useState(empty)
143
+ const [draft, setDraft] = useState({ name: '', command: '', args: '', extensions: '' })
144
+ const [busy, setBusy] = useState(false)
145
+
146
+ const apply = (payload) => setState({
147
+ loading: false,
148
+ error: '',
149
+ presets: payload.presets || [],
150
+ servers: payload.servers || [],
151
+ allowCustomServers: payload.allowCustomServers === true,
152
+ toolMount: payload.toolMount || 'lazy',
153
+ toolMounted: payload.toolMounted === true,
154
+ restartHint: payload.restartHint || '',
155
+ })
156
+
157
+ useEffect(() => {
158
+ const controller = new AbortController()
159
+ fetch(LSP_ENDPOINT, { signal: controller.signal, headers: { accept: 'application/json' } })
160
+ .then(async response => {
161
+ const body = await response.json()
162
+ if (!response.ok) throw new Error(body.error || '无法读取语言服务器配置')
163
+ apply(body)
164
+ })
165
+ .catch(error => {
166
+ if (controller.signal.aborted) return
167
+ setState(current => ({ ...current, loading: false, error: String(error.message || error) }))
168
+ })
169
+ return () => controller.abort()
170
+ }, [])
171
+
172
+ const run = async (body, confirmText) => {
173
+ if (confirmText && !window.confirm(confirmText)) return
174
+ setBusy(true)
175
+ setState(current => ({ ...current, error: '' }))
176
+ try {
177
+ apply(await lspPost(body))
178
+ } catch (error) {
179
+ setState(current => ({ ...current, error: String(error.message || error) }))
180
+ }
181
+ setBusy(false)
182
+ }
183
+
184
+ const addCustom = async () => {
185
+ const extensions = {}
186
+ draft.extensions.split(',').map(item => item.trim()).filter(Boolean).forEach((pair) => {
187
+ const [ext, language] = pair.split('=').map(part => (part || '').trim())
188
+ if (ext && language) extensions[ext] = language
189
+ })
190
+ await run({
191
+ action: 'add',
192
+ server: {
193
+ name: draft.name.trim(),
194
+ command: draft.command.trim(),
195
+ args: draft.args.split(/\s+/).filter(Boolean),
196
+ extensions,
197
+ },
198
+ })
199
+ }
200
+
201
+ const statusLabel = (status) => status === 'active' ? '已启用' : status === 'disabled' ? '已停用' : '启动失败'
202
+
203
+ return React.createElement('main', { style: pageStyle }, React.createElement('section', { style: cardStyle },
204
+ React.createElement('h1', { style: { margin: '0 0 12px', fontSize: '24px' } }, '语言服务器'),
205
+ React.createElement('p', { style: { color: '#aaa', lineHeight: 1.7 } },
206
+ '为 DSH 的 lsp 工具注册语义导航(定义、引用、实现、悬停)。启用或停用立即生效,无需重启;',
207
+ '语言服务器进程要彻底回收,需要重启 DSH。'),
208
+ state.loading && React.createElement('p', null, '正在读取配置…'),
209
+ React.createElement('p', { style: { fontSize: '15px' } },
210
+ `lsp 工具:${state.toolMounted ? '已挂载' : '未挂载'}(模式:${state.toolMount === 'always' ? '常驻' : '按需'})`),
211
+ state.restartHint && React.createElement('div', { style: noticeStyle }, state.restartHint),
212
+ state.error && React.createElement('pre', {
213
+ style: { color: '#ff8989', whiteSpace: 'pre-wrap', background: '#f003', padding: '12px', borderRadius: '10px' },
214
+ }, state.error),
215
+
216
+ React.createElement('h2', { style: { fontSize: '18px', margin: '20px 0 8px' } }, '内置语言服务器'),
217
+ React.createElement('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } },
218
+ state.presets.map((preset) => React.createElement('li', {
219
+ key: preset.id,
220
+ style: { borderBottom: '1px solid #5553', padding: '12px 0', display: 'flex', gap: '12px', alignItems: 'center' },
221
+ },
222
+ React.createElement('div', { style: { flex: 1 } },
223
+ React.createElement('strong', null, preset.label),
224
+ React.createElement('div', { style: { color: '#999', fontSize: '13px' } },
225
+ Object.keys(preset.extensions || {}).join(' ')),
226
+ React.createElement('div', { style: { fontSize: '13px', color: preset.installed ? '#7fd08a' : '#e0a06b' } },
227
+ preset.installed ? `已找到:${preset.source || preset.command}` : `未安装 · ${preset.installHint}`)),
228
+ React.createElement('button', {
229
+ type: 'button',
230
+ disabled: busy,
231
+ onClick: () => run(preset.enabled
232
+ ? { action: 'disable', preset: preset.id, name: preset.name }
233
+ : { action: 'enable', preset: preset.id, name: preset.name }),
234
+ style: {
235
+ appearance: 'none', border: 0, borderRadius: '8px', padding: '8px 14px', cursor: 'pointer',
236
+ background: preset.enabled ? '#5a2626' : '#1f6f43', color: 'white',
237
+ },
238
+ }, preset.enabled ? '停用' : '启用'),
239
+ )),
240
+ ),
241
+
242
+ React.createElement('h2', { style: { fontSize: '18px', margin: '20px 0 8px' } }, '已配置条目'),
243
+ state.servers.length === 0
244
+ ? React.createElement('p', { style: { color: '#888' } }, '暂无条目。')
245
+ : React.createElement('ul', { style: { listStyle: 'none', padding: 0, margin: 0 } },
246
+ state.servers.map((server) => React.createElement('li', {
247
+ key: server.name,
248
+ style: { borderBottom: '1px solid #5553', padding: '10px 0', display: 'flex', gap: '12px', alignItems: 'center' },
249
+ },
250
+ React.createElement('div', { style: { flex: 1 } },
251
+ React.createElement('strong', null, server.name),
252
+ React.createElement('span', { style: { marginLeft: '8px', fontSize: '13px', color: '#999' } },
253
+ statusLabel(server.status)),
254
+ server.error && React.createElement('div', { style: { fontSize: '13px', color: '#e0a06b' } }, server.error)),
255
+ server.preset === undefined && React.createElement('button', {
256
+ type: 'button',
257
+ disabled: busy,
258
+ onClick: () => run({ action: 'remove', name: server.name }, `删除自定义语言服务器 ${server.name}?`),
259
+ style: {
260
+ appearance: 'none', border: 0, borderRadius: '8px', padding: '8px 14px', cursor: 'pointer',
261
+ background: '#5a2626', color: 'white',
262
+ },
263
+ }, '删除'),
264
+ )),
265
+ ),
266
+
267
+ state.allowCustomServers && React.createElement('div', { style: { marginTop: '20px' } },
268
+ React.createElement('h2', { style: { fontSize: '18px', margin: '0 0 8px' } }, '添加自定义语言服务器'),
269
+ React.createElement('p', { style: { color: '#aaa', fontSize: '13px' } },
270
+ '自定义命令会直接启动本机可执行文件,请只添加你信任的程序。'),
271
+ ['name', 'command', 'args', 'extensions'].map((field) => React.createElement('label', {
272
+ key: field, style: { display: 'block', marginBottom: '8px' },
273
+ },
274
+ React.createElement('span', { style: { fontSize: '13px', color: '#999' } }, {
275
+ name: '名称(小写字母、数字、连字符)',
276
+ command: '可执行文件(绝对路径或 PATH 名称)',
277
+ args: '参数(空格分隔)',
278
+ extensions: '扩展名映射(例:.ts=typescript,.tsx=typescriptreact)',
279
+ }[field]),
280
+ React.createElement('input', {
281
+ value: draft[field],
282
+ onChange: event => setDraft(current => ({ ...current, [field]: event.target.value })),
283
+ style: { width: '100%', boxSizing: 'border-box', padding: '8px', borderRadius: '8px', border: '1px solid #555' },
284
+ }),
285
+ )),
286
+ React.createElement('button', {
287
+ type: 'button',
288
+ disabled: busy || !draft.name.trim() || !draft.command.trim(),
289
+ onClick: addCustom,
290
+ style: {
291
+ appearance: 'none', border: 0, borderRadius: '8px', padding: '10px 16px', cursor: 'pointer',
292
+ background: '#1f6f43', color: 'white',
293
+ },
294
+ }, '添加并启用'))
295
+ , !state.allowCustomServers && React.createElement('p', {
296
+ style: { color: '#888', fontSize: '13px', marginTop: '16px' },
297
+ }, '自定义命令未启用:如需添加,请在 cordis.patch.yml 的 dsh-efm-integration-lsp-servers 行设置 allowCustomServers: true 并重启 DSH。'),
298
+
299
+ React.createElement('button', {
300
+ type: 'button',
301
+ disabled: busy,
302
+ onClick: () => run({ action: 'restart' }),
303
+ style: {
304
+ appearance: 'none', border: '1px solid #5557', borderRadius: '8px', padding: '10px 16px',
305
+ cursor: 'pointer', background: 'transparent', color: 'inherit', marginTop: '18px',
306
+ },
307
+ }, '查看重启提示'),
308
+ ))
309
+ }
310
+
311
+ function SystemPromptPage() {
312
+ const initial = {
313
+ loading: true, source: 'default', text: '', length: 0, pureMode: false,
314
+ lockedByConfig: false, maxPromptBytes: 0, error: '',
315
+ presets: [], targetPreset: null, defaultPresetId: '', targetPresetAvailable: true,
316
+ }
317
+ const [state, setState] = useState(initial)
318
+ const [draft, setDraft] = useState('')
319
+ const [draftTarget, setDraftTarget] = useState('all')
320
+ const [busy, setBusy] = useState(false)
321
+
322
+ const apply = (payload) => {
323
+ const target = !payload.targetPreset || payload.targetPreset === 'all' ? 'all' : payload.targetPreset
324
+ setState({
325
+ loading: false,
326
+ source: payload.source || 'default',
327
+ text: payload.text || '',
328
+ length: payload.length || 0,
329
+ pureMode: payload.pureMode === true,
330
+ lockedByConfig: payload.lockedByConfig === true,
331
+ maxPromptBytes: payload.maxPromptBytes || 0,
332
+ error: '',
333
+ presets: Array.isArray(payload.presets) ? payload.presets : [],
334
+ targetPreset: target === 'all' ? null : target,
335
+ defaultPresetId: payload.defaultPresetId || '',
336
+ targetPresetAvailable: payload.targetPresetAvailable !== false,
337
+ })
338
+ if (payload.source !== 'default') setDraft(payload.text || '')
339
+ setDraftTarget(target)
340
+ }
341
+
342
+ useEffect(() => {
343
+ const controller = new AbortController()
344
+ fetch(SYSTEM_PROMPT_ENDPOINT, { signal: controller.signal, headers: { accept: 'application/json' } })
345
+ .then(async response => {
346
+ const body = await response.json()
347
+ if (!response.ok) throw new Error(body.error || '无法读取系统提示词')
348
+ apply(body)
349
+ })
350
+ .catch(error => {
351
+ if (controller.signal.aborted) return
352
+ setState(current => ({ ...current, loading: false, error: String(error.message || error) }))
353
+ })
354
+ return () => controller.abort()
355
+ }, [])
356
+
357
+ const post = async (body, confirmText) => {
358
+ if (confirmText && !window.confirm(confirmText)) return
359
+ setBusy(true)
360
+ setState(current => ({ ...current, error: '' }))
361
+ try {
362
+ const response = await fetch(SYSTEM_PROMPT_ENDPOINT, {
363
+ method: 'POST',
364
+ headers: {
365
+ accept: 'application/json',
366
+ 'content-type': 'application/json',
367
+ 'x-dsh-efm-integration-confirm': SYSTEM_PROMPT_CONFIRM_VALUE,
368
+ },
369
+ body: JSON.stringify(body),
370
+ })
371
+ const payload = await response.json()
372
+ if (!response.ok) throw new Error(payload.error || '系统提示词操作失败')
373
+ apply(payload)
374
+ } catch (error) {
375
+ setState(current => ({ ...current, error: String(error.message || error) }))
376
+ }
377
+ setBusy(false)
378
+ }
379
+
380
+ const sourceLabel = { config: '由 cordis.patch.yml 配置', custom: '自定义(纯净模式)', default: '默认执行契约' }[state.source] || state.source
381
+ const presetOptions = [{ value: 'all', label: '全部预设(保持原有全局行为)' }].concat(
382
+ state.presets.map(preset => ({
383
+ value: preset.id,
384
+ label: `${preset.name || preset.id}${preset.isDefault ? '(默认)' : ''}`,
385
+ })),
386
+ )
387
+ if (state.targetPreset && !state.presets.some(preset => preset.id === state.targetPreset)) {
388
+ presetOptions.push({ value: state.targetPreset, label: `${state.targetPreset}(已失效)` })
389
+ }
390
+ const targetLabel = state.targetPreset === null
391
+ ? '全部预设'
392
+ : state.presets.find(preset => preset.id === state.targetPreset)?.name || state.targetPreset
393
+
394
+ return React.createElement('main', { style: pageStyle }, React.createElement('section', { style: cardStyle },
395
+ React.createElement('h1', { style: { margin: '0 0 12px', fontSize: '24px' } }, '系统提示词'),
396
+ React.createElement('p', { style: { color: '#aaa', lineHeight: 1.7 } },
397
+ '填入一段提示词并保存后,模型只会收到这段文字:技能路由、MCP/工具说明、运行时上下文快照都会被去掉,工具调用也会被关闭。可选择只对某个 agent preset 生效,其他预设不受影响;“全部预设”保持原有全局行为。点击“恢复默认”可回到当前执行契约。'),
398
+ state.loading && React.createElement('p', null, '正在读取配置…'),
399
+ !state.loading && React.createElement('p', { style: { fontSize: '15px' } }, `当前来源:${sourceLabel};长度:${state.length} 字节;纯净模式:${state.pureMode ? '开启' : '关闭'};目标预设:${targetLabel}`),
400
+ state.source === 'custom' && !state.targetPresetAvailable && React.createElement('div', { style: noticeStyle },
401
+ '当前目标预设已不在可用列表中,替换暂时不会生效。请重新选择预设,或恢复默认。'),
402
+ React.createElement('label', { style: { display: 'block', marginTop: '12px' } },
403
+ React.createElement('span', { style: { fontSize: '13px', color: '#999' } }, '替换范围(agent preset)'),
404
+ React.createElement('select', {
405
+ value: draftTarget,
406
+ onChange: event => setDraftTarget(event.target.value),
407
+ disabled: busy || state.lockedByConfig,
408
+ style: {
409
+ display: 'block', width: '100%', boxSizing: 'border-box', marginTop: '8px', padding: '10px',
410
+ borderRadius: '10px', border: '1px solid #555', background: '#0003', color: 'inherit',
411
+ },
412
+ }, presetOptions.map(option => React.createElement('option', {
413
+ key: option.value, value: option.value,
414
+ }, option.label)))),
415
+ state.lockedByConfig && React.createElement('div', { style: noticeStyle },
416
+ 'cordis.patch.yml 已配置 prompt/promptFile,配置优先;此页面只读。'),
417
+ state.error && React.createElement('pre', {
418
+ style: { color: '#ff8989', whiteSpace: 'pre-wrap', background: '#f003', padding: '12px', borderRadius: '10px' },
419
+ }, state.error),
420
+ React.createElement('label', { style: { display: 'block', marginTop: '16px' } },
421
+ React.createElement('span', { style: { fontSize: '13px', color: '#999' } },
422
+ `自定义提示词(UTF-8,最多 ${state.maxPromptBytes || '—'} 字节,请勿写入密钥)`),
423
+ React.createElement('textarea', {
424
+ value: draft,
425
+ onChange: event => setDraft(event.target.value),
426
+ disabled: busy || state.lockedByConfig,
427
+ rows: 16,
428
+ spellCheck: false,
429
+ style: {
430
+ width: '100%', boxSizing: 'border-box', marginTop: '8px', padding: '12px',
431
+ borderRadius: '10px', border: '1px solid #555', background: '#0003',
432
+ color: 'inherit', fontFamily: 'monospace', fontSize: '13px', lineHeight: 1.5,
433
+ resize: 'vertical',
434
+ },
435
+ })),
436
+ React.createElement('div', { style: { display: 'flex', gap: '12px', marginTop: '16px', flexWrap: 'wrap' } },
437
+ React.createElement('button', {
438
+ type: 'button',
439
+ disabled: busy || state.lockedByConfig || draft.trim().length === 0,
440
+ onClick: () => post({ action: 'save', text: draft, targetPreset: draftTarget }),
441
+ style: {
442
+ appearance: 'none', border: 0, borderRadius: '8px', padding: '10px 16px', cursor: 'pointer',
443
+ background: '#1f6f43', color: 'white', fontWeight: 600,
444
+ },
445
+ }, busy ? '正在保存…' : '保存并启用纯净模式'),
446
+ React.createElement('button', {
447
+ type: 'button',
448
+ disabled: busy || state.lockedByConfig || state.source === 'default',
449
+ onClick: () => post({ action: 'clear' }, '恢复默认执行契约并重新启用工具?'),
450
+ style: {
451
+ appearance: 'none', border: '1px solid #5557', borderRadius: '8px', padding: '10px 16px',
452
+ cursor: 'pointer', background: 'transparent', color: 'inherit',
453
+ },
454
+ }, '恢复默认')),
455
+ ))
456
+ }
457
+
458
+ function TrashIcon({ size = 16 }) {
459
+ return React.createElement('svg', {
460
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
461
+ stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
462
+ 'aria-hidden': 'true',
463
+ },
464
+ React.createElement('path', { d: 'M4 7h16M9 7V4h6v3M7 7l1 13h8l1-13M10 11v5M14 11v5' }))
465
+ }
466
+
467
+ function CodeIcon({ size = 16 }) {
468
+ return React.createElement('svg', {
469
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
470
+ stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
471
+ 'aria-hidden': 'true',
472
+ },
473
+ React.createElement('path', { d: 'M9 7l-5 5 5 5M15 7l5 5-5 5' }))
474
+ }
475
+
476
+ function DocumentIcon({ size = 16 }) {
477
+ return React.createElement('svg', {
478
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
479
+ stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round',
480
+ 'aria-hidden': 'true',
481
+ },
482
+ React.createElement('path', { d: 'M7 3h7l5 5v13H7zM14 3v5h5M10 12h6M10 16h6' }))
483
+ }
484
+
485
+ function apply(ctx) {
486
+ ctx.slots.inject('main', () => ctx.slots.register({
487
+ name: 'main',
488
+ key: ARCHIVE_PANEL_ID,
489
+ }, ArchiveCleanerPage))
490
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
491
+ name: 'sidebar.panellist',
492
+ id: ARCHIVE_PANEL_ID,
493
+ order: 20,
494
+ label: '清空全部存档会话',
495
+ }, TrashIcon))
496
+ ctx.slots.inject('main', () => ctx.slots.register({
497
+ name: 'main',
498
+ key: LSP_PANEL_ID,
499
+ }, LspServersPage))
500
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
501
+ name: 'sidebar.panellist',
502
+ id: LSP_PANEL_ID,
503
+ order: 21,
504
+ label: '语言服务器',
505
+ }, CodeIcon))
506
+ ctx.slots.inject('main', () => ctx.slots.register({
507
+ name: 'main',
508
+ key: SYSTEM_PROMPT_PANEL_ID,
509
+ }, SystemPromptPage))
510
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
511
+ name: 'sidebar.panellist',
512
+ id: SYSTEM_PROMPT_PANEL_ID,
513
+ order: 22,
514
+ label: '系统提示词',
515
+ }, DocumentIcon))
516
+ }
517
+
518
+ module.exports = {
519
+ name: 'dsh-efm-integration-archive-cleaner',
520
+ inject: ['slots'],
521
+ apply,
522
+ }
523
+ return module.exports
524
+ },
525
+ })