@surfishs/dsh-prompt-enhance 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +41 -10
- package/README.md +40 -9
- package/docs/images/panel-en-915.png +0 -0
- package/docs/images/panel.png +0 -0
- package/lib/client.js +433 -163
- package/package.json +1 -1
- package/src/client/ResultDock.tsx +3 -93
- package/src/client/ResultPanel.tsx +27 -25
- package/src/client/UndoBar.tsx +14 -7
- package/src/client/locales.ts +10 -6
- package/src/client/settings-page.tsx +212 -14
- package/src/client/styles.ts +94 -10
- package/src/client/useDockAlignment.ts +103 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surfishs/dsh-prompt-enhance",
|
|
3
3
|
"description": "Prompt enhancement for the dsh web GUI: rewrite the composer draft into a well-structured prompt through the harness LLM service, preview the before/after, then fill back, copy, or undo. Original draft is always preserved.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -13,6 +13,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
|
13
13
|
import { ResultPanel } from './ResultPanel'
|
|
14
14
|
import * as ui from './ui-state'
|
|
15
15
|
import { useSessionKey } from './session-key'
|
|
16
|
+
import { useDockAlignment } from './useDockAlignment'
|
|
16
17
|
|
|
17
18
|
/** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
|
|
18
19
|
export type ResultDockProps = PropsRuntime<'conversation.input.dock'> & PropsLocale<'dsh-prompt-enhance'>
|
|
@@ -23,12 +24,12 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
23
24
|
// 0.1.1-rc.2 carries sessionId on the props; 0.1.2-rc.1 dropped it. Use the
|
|
24
25
|
// host id for UI keying when present, else a stable per-mount fallback.
|
|
25
26
|
const uiKey = useSessionKey(sessionId, inputActions)
|
|
26
|
-
const
|
|
27
|
+
const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
|
|
28
|
+
const rootRef = useDockAlignment(panel !== undefined && panel.sessionId === uiKey)
|
|
27
29
|
const [undone, setUndone] = useState(false)
|
|
28
30
|
const [regenerated, setRegenerated] = useState(false)
|
|
29
31
|
const [pendingRegenerate, setPendingRegenerate] = useState(false)
|
|
30
32
|
const previousResultRef = useRef<unknown>(undefined)
|
|
31
|
-
const panel = useSyncExternalStore(ui.subscribe, ui.getPanel)
|
|
32
33
|
const draft = useInput((state) => {
|
|
33
34
|
const value = (state as { draft?: unknown }).draft
|
|
34
35
|
return typeof value === 'string' ? value : ''
|
|
@@ -121,97 +122,6 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
121
122
|
return () => clearTimeout(timer)
|
|
122
123
|
}, [pendingRegenerate])
|
|
123
124
|
|
|
124
|
-
// The dock row is wider than the composer card in some host layouts (the
|
|
125
|
-
// conversation column spans the pane while the card is centered). Align the
|
|
126
|
-
// card to the composer by measuring the composer's rounded card: find the
|
|
127
|
-
// nearest editor below the dock, walk up to the rounded surface, and reuse
|
|
128
|
-
// its width and left offset. The measurement is re-run on resize; when no
|
|
129
|
-
// editor exists the dock keeps the host's full width.
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
if (panel === undefined || panel.sessionId !== uiKey) return
|
|
132
|
-
const root = rootRef.current
|
|
133
|
-
if (root === null) return
|
|
134
|
-
let frame = 0
|
|
135
|
-
const align = (): void => {
|
|
136
|
-
const parent = root.parentElement
|
|
137
|
-
if (parent === null) return
|
|
138
|
-
// A transform-only offset is applied to the wrong base when the host
|
|
139
|
-
// already centers this entry, and a translated box can be clipped by its
|
|
140
|
-
// parent; use a layout margin instead. The previous margin is subtracted
|
|
141
|
-
// from the measured left so repeated runs do not accumulate drift.
|
|
142
|
-
root.style.transform = ''
|
|
143
|
-
const previousMargin = parseFloat(root.style.marginLeft) || 0
|
|
144
|
-
const rootRect = root.getBoundingClientRect()
|
|
145
|
-
const baseLeft = rootRect.left - previousMargin
|
|
146
|
-
const editors = Array.from(document.querySelectorAll<HTMLElement>('textarea, [contenteditable="true"], [role="textbox"]'))
|
|
147
|
-
const editor = editors.find((node) => {
|
|
148
|
-
const rect = node.getBoundingClientRect()
|
|
149
|
-
return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4
|
|
150
|
-
})
|
|
151
|
-
if (editor === undefined) {
|
|
152
|
-
root.style.width = ''
|
|
153
|
-
root.style.marginLeft = ''
|
|
154
|
-
root.style.transform = ''
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
const editorRect = editor.getBoundingClientRect()
|
|
158
|
-
// Collect every rounded, opaque ancestor of the editor, then take the
|
|
159
|
-
// widest one that is still plausibly the composer card. The first match
|
|
160
|
-
// is often an inner wrapper a few pixels narrower than the card; the
|
|
161
|
-
// conversation pane above it is too wide. Center proximity rejects the
|
|
162
|
-
// pane when the composer is off-center, and the width cap rejects it
|
|
163
|
-
// when both are centered.
|
|
164
|
-
const candidates: { node: HTMLElement; rect: DOMRect }[] = []
|
|
165
|
-
let node: HTMLElement | null = editor
|
|
166
|
-
for (let depth = 0; depth < 12 && node !== null; depth++) {
|
|
167
|
-
const rect = node.getBoundingClientRect()
|
|
168
|
-
const style = getComputedStyle(node)
|
|
169
|
-
if (
|
|
170
|
-
rect.width >= editorRect.width
|
|
171
|
-
&& rect.width > 360
|
|
172
|
-
&& rect.height > 48
|
|
173
|
-
&& (parseFloat(style.borderTopLeftRadius) || 0) >= 4
|
|
174
|
-
&& style.backgroundColor !== 'rgba(0, 0, 0, 0)'
|
|
175
|
-
) {
|
|
176
|
-
candidates.push({ node, rect })
|
|
177
|
-
}
|
|
178
|
-
node = node.parentElement
|
|
179
|
-
}
|
|
180
|
-
const editorCenter = editorRect.left + editorRect.width / 2
|
|
181
|
-
const cardEntry = candidates
|
|
182
|
-
.filter((candidate) => (
|
|
183
|
-
candidate.rect.width <= window.innerWidth * 0.8
|
|
184
|
-
&& Math.abs(candidate.rect.left + candidate.rect.width / 2 - editorCenter) < 40
|
|
185
|
-
))
|
|
186
|
-
.sort((a, b) => b.rect.width - a.rect.width)[0]
|
|
187
|
-
?? candidates.sort((a, b) => b.rect.width - a.rect.width)[0]
|
|
188
|
-
if (cardEntry === undefined) return
|
|
189
|
-
const cardRect = cardEntry.rect
|
|
190
|
-
const width = `${cardRect.width}px`
|
|
191
|
-
if (root.style.width !== width) root.style.width = width
|
|
192
|
-
// Width can shift a centered entry; measure again before deriving the
|
|
193
|
-
// margin so the final left edge matches the composer card.
|
|
194
|
-
const afterWidth = root.getBoundingClientRect()
|
|
195
|
-
const currentMargin = parseFloat(root.style.marginLeft) || 0
|
|
196
|
-
const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`
|
|
197
|
-
if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft
|
|
198
|
-
}
|
|
199
|
-
const schedule = (): void => {
|
|
200
|
-
cancelAnimationFrame(frame)
|
|
201
|
-
frame = requestAnimationFrame(align)
|
|
202
|
-
}
|
|
203
|
-
schedule()
|
|
204
|
-
schedule()
|
|
205
|
-
window.addEventListener('resize', schedule)
|
|
206
|
-
const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule)
|
|
207
|
-
observer?.observe(document.documentElement)
|
|
208
|
-
return () => {
|
|
209
|
-
cancelAnimationFrame(frame)
|
|
210
|
-
window.removeEventListener('resize', schedule)
|
|
211
|
-
observer?.disconnect()
|
|
212
|
-
}
|
|
213
|
-
}, [panel, uiKey])
|
|
214
|
-
|
|
215
125
|
if (panel === undefined || panel.sessionId !== uiKey) return null
|
|
216
126
|
|
|
217
127
|
const apply = (): void => {
|
|
@@ -180,31 +180,33 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
180
180
|
<SparkleFishIcon size={15} />
|
|
181
181
|
{t('panel.title')}
|
|
182
182
|
</span>
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
183
|
+
<div className="dsh-pe-head-actions">
|
|
184
|
+
{state.phase === 'result' && state.result !== undefined && (
|
|
185
|
+
<span className="dsh-pe-badge">
|
|
186
|
+
{t('panel.model', { provider: state.result.provider, model: state.result.model })} · {t('panel.elapsed', { ms: formatMs(state.result.elapsedMs) })}
|
|
187
|
+
{state.result.usage === undefined
|
|
188
|
+
? null
|
|
189
|
+
: (
|
|
190
|
+
<>
|
|
191
|
+
{' · '}
|
|
192
|
+
<span title={tokenDetail(state.result.usage)}>
|
|
193
|
+
{t('panel.tokens', { total: formatTokens(totalTokensOf(state.result.usage)) })}
|
|
194
|
+
</span>
|
|
195
|
+
</>
|
|
196
|
+
)}
|
|
197
|
+
</span>
|
|
198
|
+
)}
|
|
199
|
+
{copied === 'ok'
|
|
200
|
+
? <span className="dsh-pe-applied">{t('panel.copiedShort')}</span>
|
|
201
|
+
: regenerated
|
|
202
|
+
? <span className="dsh-pe-applied">{t('panel.regeneratedShort')}</span>
|
|
203
|
+
: applied
|
|
204
|
+
? <span className="dsh-pe-applied">{t('panel.appliedShort')}</span>
|
|
205
|
+
: undone
|
|
206
|
+
? <span className="dsh-pe-applied">{t('panel.undoneShort')}</span>
|
|
207
|
+
: null}
|
|
208
|
+
<button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>✕</button>
|
|
209
|
+
</div>
|
|
208
210
|
</header>
|
|
209
211
|
|
|
210
212
|
{state.phase === 'loading' && (
|
package/src/client/UndoBar.tsx
CHANGED
|
@@ -12,6 +12,8 @@ import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots
|
|
|
12
12
|
import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
|
|
13
13
|
import * as ui from './ui-state'
|
|
14
14
|
import { useSessionKey } from './session-key'
|
|
15
|
+
import { UndoIcon } from './ActionIcons'
|
|
16
|
+
import { useDockAlignment } from './useDockAlignment'
|
|
15
17
|
|
|
16
18
|
/** Props of the input.dock entry: the InputZone owner share + session kit + locale seat. */
|
|
17
19
|
export type UndoBarProps = PropsRuntime<'conversation.input.dock'> & PropsLocale<'dsh-prompt-enhance'>
|
|
@@ -40,8 +42,11 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
40
42
|
// The result card owns the undo affordance while it is open; the standalone
|
|
41
43
|
// row takes over only after the card is closed.
|
|
42
44
|
const panel = ui.getPanel()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const visible = (panel === undefined || panel.sessionId !== uiKey)
|
|
46
|
+
&& entry !== undefined
|
|
47
|
+
&& entry.applied === draft
|
|
48
|
+
const rootRef = useDockAlignment(visible)
|
|
49
|
+
if (!visible) return null
|
|
45
50
|
|
|
46
51
|
const undo = (): void => {
|
|
47
52
|
inputActions.setDraft(entry.original)
|
|
@@ -52,11 +57,13 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
return (
|
|
55
|
-
<div className="dsh-pe-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
<div ref={rootRef} className="dsh-pe-dock">
|
|
61
|
+
<div className="dsh-pe-undo">
|
|
62
|
+
<span className="dsh-pe-undo-check" aria-hidden>✓</span>
|
|
63
|
+
<span>{t('undo.applied')}</span>
|
|
64
|
+
<button type="button" className="dsh-pe-undo-link" onClick={undo}><UndoIcon />{t('undo.undo')}</button>
|
|
65
|
+
<button type="button" className="dsh-pe-undo-x" aria-label={t('undo.dismiss')} onClick={dismiss}>✕</button>
|
|
66
|
+
</div>
|
|
60
67
|
</div>
|
|
61
68
|
)
|
|
62
69
|
}
|
package/src/client/locales.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const zh = {
|
|
|
37
37
|
'panel.tokens.output': '输出 {count}',
|
|
38
38
|
'panel.tokens.cacheRead': '缓存读取 {count}',
|
|
39
39
|
'panel.tokens.cacheWrite': '缓存写入 {count}',
|
|
40
|
-
'undo.applied': '
|
|
40
|
+
'undo.applied': '已替换原提示词',
|
|
41
41
|
'undo.undo': '撤销',
|
|
42
42
|
'undo.dismiss': '关闭提示',
|
|
43
43
|
'error.empty': '输入框为空,请先输入要增强的提示词。',
|
|
@@ -68,7 +68,9 @@ export const zh = {
|
|
|
68
68
|
'settings.description': '把输入框草稿改写为结构化提示词:角色与目标、可执行步骤、输出格式、验收标准、边界条件。原文保留,失败不改草稿;保存后下一次调用即生效。',
|
|
69
69
|
'settings.save': '保存',
|
|
70
70
|
'settings.saving': '保存中…',
|
|
71
|
+
'settings.saved': '已保存',
|
|
71
72
|
'settings.saveFailed': '本部署没有接受这些值,已保留供你修改。',
|
|
73
|
+
'settings.saveFailedShort': '保存失败',
|
|
72
74
|
'settings.readOnly': '本部署的设置为只读。',
|
|
73
75
|
'settings.unavailable': '该插件当前未加载,暂时无法配置。',
|
|
74
76
|
'settings.reset': '恢复默认',
|
|
@@ -106,7 +108,7 @@ export const zh = {
|
|
|
106
108
|
'settings.row.temperature.label': '温度',
|
|
107
109
|
'settings.row.temperature.hint': '采样温度(0~1,步进 0.05),越低越忠实原文;默认 0.3。',
|
|
108
110
|
'settings.row.reasoningEffort.label': '推理预算',
|
|
109
|
-
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model
|
|
111
|
+
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。提供方默认表示不传该字段。',
|
|
110
112
|
'settings.row.maxOutputTokens.label': '输出 token 上限',
|
|
111
113
|
'settings.row.maxOutputTokens.hint': '单次增强的输出预算;默认 8192。',
|
|
112
114
|
'settings.row.maxInputChars.label': '输入字符上限',
|
|
@@ -117,7 +119,7 @@ export const zh = {
|
|
|
117
119
|
'settings.row.strategyMode.hint': '自定义系统提示词非空时:整体替换内置策略(仍保留最小输出契约),或追加在内置策略之后(内置规则继续生效)。',
|
|
118
120
|
'settings.row.systemPrompt.label': '自定义系统提示词',
|
|
119
121
|
'settings.row.systemPrompt.hint': '留空使用内置增强策略。',
|
|
120
|
-
'settings.row.systemPrompt.placeholder': '
|
|
122
|
+
'settings.row.systemPrompt.placeholder': '例:把用户的中文输入翻译成英文。',
|
|
121
123
|
'settings.row.contextMaxMessages.label': '上下文消息条数',
|
|
122
124
|
'settings.row.contextMaxMessages.hint': '最多参考最近多少轮对话;0 表示不参考;默认 8。',
|
|
123
125
|
'settings.row.contextMaxChars.label': '上下文字符上限',
|
|
@@ -131,7 +133,7 @@ export const zh = {
|
|
|
131
133
|
'settings.row.shortcut.placeholder': '例:ctrl+alt+shift+e',
|
|
132
134
|
'settings.strategy.replace': '替换内置策略',
|
|
133
135
|
'settings.strategy.extend': '追加在内置策略后',
|
|
134
|
-
'settings.reasoning.inherit': '
|
|
136
|
+
'settings.reasoning.inherit': '提供方默认',
|
|
135
137
|
'settings.reasoning.loading': '正在读取该模型的档位…',
|
|
136
138
|
'settings.reasoning.unavailable': '无法读取该模型的档位,仅可跟随提供方默认。',
|
|
137
139
|
'settings.reasoning.noTiers': '该模型未声明推理档位,调用时将跟随提供方默认。',
|
|
@@ -180,7 +182,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
180
182
|
'panel.tokens.output': 'Output {count}',
|
|
181
183
|
'panel.tokens.cacheRead': 'Cache read {count}',
|
|
182
184
|
'panel.tokens.cacheWrite': 'Cache write {count}',
|
|
183
|
-
'undo.applied': 'Original
|
|
185
|
+
'undo.applied': 'Original draft replaced',
|
|
184
186
|
'undo.undo': 'Undo',
|
|
185
187
|
'undo.dismiss': 'Dismiss',
|
|
186
188
|
'error.empty': 'The input box is empty — type a prompt to enhance first.',
|
|
@@ -211,7 +213,9 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
211
213
|
'settings.description': 'Turns a composer draft into a structured prompt: role and goal, executable steps, output format, acceptance criteria, edge cases. The draft is preserved, failures never touch it, and saved values apply to the next call.',
|
|
212
214
|
'settings.save': 'Save',
|
|
213
215
|
'settings.saving': 'Saving…',
|
|
216
|
+
'settings.saved': 'Saved',
|
|
214
217
|
'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
|
|
218
|
+
'settings.saveFailedShort': 'Save failed',
|
|
215
219
|
'settings.readOnly': 'This deployment stores settings read-only.',
|
|
216
220
|
'settings.unavailable': 'This plugin is not loaded, so it cannot be configured right now.',
|
|
217
221
|
'settings.reset': 'Reset to default',
|
|
@@ -249,7 +253,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
249
253
|
'settings.row.temperature.label': 'Temperature',
|
|
250
254
|
'settings.row.temperature.hint': 'Sampling temperature (0–1, step 0.05); lower stays closer to the original. Default 0.3.',
|
|
251
255
|
'settings.row.reasoningEffort.label': 'Reasoning effort',
|
|
252
|
-
'settings.row.reasoningEffort.hint': 'Tier choices come from what the configured provider/model declares; custom models are read on demand.
|
|
256
|
+
'settings.row.reasoningEffort.hint': 'Tier choices come from what the configured provider/model declares; custom models are read on demand. Provider default omits the field.',
|
|
253
257
|
'settings.row.maxOutputTokens.label': 'Output token budget',
|
|
254
258
|
'settings.row.maxOutputTokens.hint': 'Output budget for one enhancement call. Default 8192.',
|
|
255
259
|
'settings.row.maxInputChars.label': 'Input character cap',
|