@surfishs/dsh-prompt-enhance 0.1.5 → 0.1.7
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 +7 -3
- package/README.md +10 -4
- package/lib/client.js +16 -8
- package/lib/index.js +1 -1
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
- package/src/client/UndoBar.tsx +14 -1
- package/src/client/locales.ts +2 -2
- package/src/client/shortcut.ts +26 -10
- package/src/config.ts +1 -1
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.1.
|
|
4
|
+
"version": "0.1.7",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
package/src/client/UndoBar.tsx
CHANGED
|
@@ -39,10 +39,23 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
39
39
|
if (entry !== undefined && entry.applied !== draft) ui.popUndo(uiKey)
|
|
40
40
|
}, [draft, entry, uiKey])
|
|
41
41
|
|
|
42
|
+
// The composer's own phase decides whether an undo makes sense. While it is
|
|
43
|
+
// mid-submit (sending / submitting / adjudicating) the draft is about to be
|
|
44
|
+
// consumed, so restoring the pre-apply text is not what the user asked for —
|
|
45
|
+
// and the single commit between "card closed" and "draft cleared" used to
|
|
46
|
+
// flash the bar for exactly that moment. A host that publishes no phase reads
|
|
47
|
+
// as idle here, keeping the shipped behaviour on those versions.
|
|
48
|
+
const phase = useInput((state) => {
|
|
49
|
+
const value = (state as { phase?: unknown }).phase
|
|
50
|
+
return typeof value === 'string' ? value : ''
|
|
51
|
+
})
|
|
52
|
+
const composerIdle = phase === '' || phase === 'plain'
|
|
53
|
+
|
|
42
54
|
// The result card owns the undo affordance while it is open; the standalone
|
|
43
55
|
// row takes over only after the card is closed.
|
|
44
56
|
const panel = ui.getPanel()
|
|
45
|
-
const
|
|
57
|
+
const cardGone = panel === undefined || panel.sessionId !== uiKey
|
|
58
|
+
const visible = cardGone && composerIdle && entry !== undefined && entry.applied === draft
|
|
46
59
|
const rootRef = useDockAlignment(visible, uiKey)
|
|
47
60
|
if (!visible) return null
|
|
48
61
|
|
package/src/client/locales.ts
CHANGED
|
@@ -171,7 +171,7 @@ export const zh = {
|
|
|
171
171
|
'settings.row.rateLimitPerMinute.label': '每分钟调用上限',
|
|
172
172
|
'settings.row.rateLimitPerMinute.hint': '每分钟增强次数上限(滑动窗口);超限时提示稍后再试。默认 10。',
|
|
173
173
|
'settings.row.shortcut.label': '快捷键',
|
|
174
|
-
'settings.row.shortcut.hint': '默认留空(禁用);填写后生效,例:ctrl+alt+shift+e(须包含 ctrl/alt/meta
|
|
174
|
+
'settings.row.shortcut.hint': '默认留空(禁用);填写后生效,例:ctrl+alt+shift+e(须包含 ctrl/alt/meta 中至少一个修饰键;F13–F24 可单独使用)。',
|
|
175
175
|
'settings.row.shortcut.placeholder': '例:ctrl+alt+shift+e',
|
|
176
176
|
'settings.strategy.replace': '替换内置策略',
|
|
177
177
|
'settings.strategy.extend': '追加在内置策略后',
|
|
@@ -363,7 +363,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
363
363
|
'settings.row.rateLimitPerMinute.label': 'Calls per minute',
|
|
364
364
|
'settings.row.rateLimitPerMinute.hint': 'Successful enhancements per minute (sliding window); past the limit the request is told to retry later. Default 10.',
|
|
365
365
|
'settings.row.shortcut.label': 'Shortcut',
|
|
366
|
-
'settings.row.shortcut.hint': 'Empty by default (disabled); set it to enable, e.g. ctrl+alt+shift+e (needs at least one of ctrl/alt/meta).',
|
|
366
|
+
'settings.row.shortcut.hint': 'Empty by default (disabled); set it to enable, e.g. ctrl+alt+shift+e (needs at least one of ctrl/alt/meta; F13–F24 may be used alone).',
|
|
367
367
|
'settings.row.shortcut.placeholder': 'e.g. ctrl+alt+shift+e',
|
|
368
368
|
'settings.strategy.replace': 'Replace the built-in strategy',
|
|
369
369
|
'settings.strategy.extend': 'Append after the built-in strategy',
|
package/src/client/shortcut.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface ShortcutCombo {
|
|
|
16
16
|
readonly alt: boolean
|
|
17
17
|
readonly shift: boolean
|
|
18
18
|
readonly meta: boolean
|
|
19
|
-
/** Final key: a single letter a-z, digit 0-9, or f1-
|
|
19
|
+
/** Final key: a single letter a-z, digit 0-9, or f1-f24. */
|
|
20
20
|
readonly key: string
|
|
21
21
|
/** Layout-independent DOM code for the key (`KeyA`, `Digit1`, `F9`). */
|
|
22
22
|
readonly code: string
|
|
@@ -36,8 +36,20 @@ const MODIFIER_ALIASES: ReadonlyMap<string, keyof Omit<ShortcutCombo, 'key' | 'c
|
|
|
36
36
|
['super', 'meta'],
|
|
37
37
|
])
|
|
38
38
|
|
|
39
|
-
/** Function
|
|
40
|
-
const
|
|
39
|
+
/** Function keys f1-f24; everything else must be one alphanumeric character. */
|
|
40
|
+
const FUNCTION_KEY_TOKEN = /^f([1-9]|1[0-9]|2[0-4])$/
|
|
41
|
+
const isKeyToken = (token: string): boolean => /^[a-z0-9]$/.test(token) || FUNCTION_KEY_TOKEN.test(token)
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Function keys that may be bound without ctrl/alt/meta: f13-f24.
|
|
45
|
+
*
|
|
46
|
+
* A bare letter or digit would swallow ordinary typing, and f1-f12 carry
|
|
47
|
+
* browser/OS defaults (refresh, fullscreen, devtools), so both still require a
|
|
48
|
+
* modifier. f13-f24 have no default action and no physical key on an ordinary
|
|
49
|
+
* keyboard — they reach the page from macro pads and remappers — so requiring a
|
|
50
|
+
* modifier there would only make the natural binding impossible.
|
|
51
|
+
*/
|
|
52
|
+
const isBareFunctionKey = (token: string): boolean => /^f(1[3-9]|2[0-4])$/.test(token)
|
|
41
53
|
|
|
42
54
|
/** The DOM `event.code` for a key token (physical, layout-independent). */
|
|
43
55
|
function codeFor(token: string): string {
|
|
@@ -53,8 +65,9 @@ type ModifierFlags = Record<'ctrl' | 'alt' | 'shift' | 'meta', boolean>
|
|
|
53
65
|
* Parse a user-configured shortcut spec. Whitespace and case are free; the
|
|
54
66
|
* key token must come last. At least one of ctrl / alt / meta is REQUIRED —
|
|
55
67
|
* a shift-only combo fires while the user is simply typing a capital
|
|
56
|
-
* letter, and a bare key would swallow that character everywhere.
|
|
57
|
-
*
|
|
68
|
+
* letter, and a bare key would swallow that character everywhere. f13-f24
|
|
69
|
+
* are the exception: they may stand alone (see {@link isBareFunctionKey}).
|
|
70
|
+
* Empty spec parses to null (shortcut disabled).
|
|
58
71
|
* @param spec - the raw settings string.
|
|
59
72
|
* @returns the normalized combo, or null when the spec is unusable.
|
|
60
73
|
*/
|
|
@@ -75,7 +88,7 @@ export function parseShortcut(spec: string | undefined): ShortcutCombo | null {
|
|
|
75
88
|
if (modifier === undefined) return null
|
|
76
89
|
modifiers[modifier] = true
|
|
77
90
|
}
|
|
78
|
-
if (!modifiers.ctrl && !modifiers.alt && !modifiers.meta) return null
|
|
91
|
+
if (!modifiers.ctrl && !modifiers.alt && !modifiers.meta && !isBareFunctionKey(last)) return null
|
|
79
92
|
return { ...modifiers, key: last, code: codeFor(last) }
|
|
80
93
|
}
|
|
81
94
|
|
|
@@ -111,7 +124,7 @@ function keyTokenOf(event: ShortcutKeyEvent): string | null {
|
|
|
111
124
|
if (letter !== undefined) return letter.toLowerCase()
|
|
112
125
|
const digit = /^Digit([0-9])$/.exec(event.code)?.[1]
|
|
113
126
|
if (digit !== undefined) return digit
|
|
114
|
-
const fn = /^F([1-9]|1[0-2])$/.exec(event.code)?.[1]
|
|
127
|
+
const fn = /^F([1-9]|1[0-9]|2[0-4])$/.exec(event.code)?.[1]
|
|
115
128
|
if (fn !== undefined) return `f${fn}`
|
|
116
129
|
const byKey = event.key.toLowerCase()
|
|
117
130
|
return isKeyToken(byKey) ? byKey : null
|
|
@@ -122,15 +135,18 @@ function keyTokenOf(event: ShortcutKeyEvent): string | null {
|
|
|
122
135
|
*
|
|
123
136
|
* Returns null — meaning "this press cannot be a shortcut" — when neither
|
|
124
137
|
* ctrl / alt / meta is held (a bare key or shift+letter would swallow ordinary
|
|
125
|
-
* typing
|
|
126
|
-
*
|
|
138
|
+
* typing; f13-f24 are the exception, see {@link isBareFunctionKey}), or when
|
|
139
|
+
* the key falls outside the a-z / 0-9 / f1-f24 whitelist the parser accepts
|
|
140
|
+
* (Space, Tab, arrows …).
|
|
127
141
|
* @param event - the recorded key press.
|
|
128
142
|
* @returns the spec string, or null.
|
|
129
143
|
*/
|
|
130
144
|
export function shortcutSpecOf(event: ShortcutKeyEvent): string | null {
|
|
131
|
-
if (!event.ctrlKey && !event.altKey && !event.metaKey) return null
|
|
132
145
|
const token = keyTokenOf(event)
|
|
133
146
|
if (token === null) return null
|
|
147
|
+
// A bare f13-f24 is allowed; every other key needs ctrl / alt / meta so
|
|
148
|
+
// ordinary typing and the browser's own function-key actions stay untouched.
|
|
149
|
+
if (!event.ctrlKey && !event.altKey && !event.metaKey && !isBareFunctionKey(token)) return null
|
|
134
150
|
const parts: string[] = []
|
|
135
151
|
if (event.ctrlKey) parts.push('ctrl')
|
|
136
152
|
if (event.altKey) parts.push('alt')
|
package/src/config.ts
CHANGED
|
@@ -170,7 +170,7 @@ export const Config = z.object({
|
|
|
170
170
|
shortcut: z
|
|
171
171
|
.string()
|
|
172
172
|
.default(DEFAULT_CONFIG.shortcut)
|
|
173
|
-
.description('触发快捷键,默认留空即禁用;如需启用,填如 ctrl+alt+e(须包含 ctrl/alt/meta 中至少一个修饰键,shift 仅可作附加,纯字母/数字或 shift
|
|
173
|
+
.description('触发快捷键,默认留空即禁用;如需启用,填如 ctrl+alt+e(须包含 ctrl/alt/meta 中至少一个修饰键,shift 仅可作附加,纯字母/数字或 shift+字母会被忽略;F13–F24 可单独使用)')
|
|
174
174
|
.volatile(),
|
|
175
175
|
maxConcurrent: z
|
|
176
176
|
.number()
|