@surfishs/dsh-prompt-enhance 0.0.7 → 0.0.9
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 +24 -18
- package/README.md +24 -18
- package/cordis.patch.yml +1 -1
- package/icon.svg +14 -0
- package/lib/client.js +343 -383
- package/lib/index.js +67 -56
- package/lib/index.js.map +3 -3
- package/package.json +26 -16
- package/src/client/ActionIcons.tsx +4 -17
- package/src/client/EnhanceButton.tsx +52 -48
- package/src/client/ResultDock.tsx +22 -9
- package/src/client/ResultPanel.tsx +83 -52
- package/src/client/SparkleFishIcon.tsx +25 -20
- package/src/client/UndoBar.tsx +11 -6
- package/src/client/enhance-client.ts +44 -40
- package/src/client/index.tsx +3 -12
- package/src/client/llm-catalog.ts +14 -16
- package/src/client/locales.ts +18 -4
- package/src/client/reasoning-options.ts +7 -15
- package/src/client/settings-page-controls.tsx +449 -0
- package/src/client/settings-page-copy.ts +112 -0
- package/src/client/settings-page-spec.ts +330 -0
- package/src/client/settings-page-styles.ts +161 -0
- package/src/client/settings-page.tsx +113 -1110
- package/src/client/settings-source.ts +41 -31
- package/src/client/settings.ts +17 -12
- package/src/client/shortcut.ts +7 -6
- package/src/client/useDockAlignment.ts +5 -15
- package/src/config.ts +84 -27
- package/src/context.ts +1 -5
- package/src/enhance-routes.ts +8 -8
- package/src/enhancer.ts +43 -34
- package/src/orchestrate.ts +19 -23
- package/src/prompts.ts +4 -4
- package/src/provider-catalog.ts +1 -1
- package/src/reasoning-cache.ts +4 -4
- package/src/reasoning-efforts.ts +4 -9
- package/src/settings-source.ts +37 -23
- package/src/shared/limits.ts +38 -0
- package/src/shared/normalize.ts +4 -1
- package/src/shared/protocol.ts +27 -23
- package/src/shared/reasoning.ts +1 -7
- package/src/shared/stream-text.ts +0 -6
- package/src/shared/validate.ts +3 -9
- package/docs/code-review-2026-09.md +0 -211
- package/docs/handoff-settings-page.md +0 -195
- package/docs/release-0.2.3.md +0 -47
- package/docs/release-0.2.4.md +0 -20
- package/docs/release-0.2.5.md +0 -28
- package/docs/release-0.2.6.md +0 -33
- package/docs/release-0.2.7.md +0 -22
- package/docs/release-0.3.0.md +0 -36
- package/docs/release-0.3.1.md +0 -50
- package/docs/release-0.3.2.md +0 -41
- package/docs/release-0.3.3.md +0 -53
- package/docs/release-0.3.4.md +0 -43
- package/src/client/SparkleIcon.tsx +0 -33
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.9",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"./package.json": "./package.json",
|
|
21
21
|
"./locale/en.json": "./locale/en.json",
|
|
22
22
|
"./locale/zh.json": "./locale/zh.json",
|
|
23
|
-
"./locale/*.json": "./locale/*.json"
|
|
23
|
+
"./locale/*.json": "./locale/*.json",
|
|
24
|
+
"./icon": "./icon.svg"
|
|
24
25
|
},
|
|
25
26
|
"dsh": {
|
|
26
27
|
"engines": {
|
|
@@ -50,29 +51,34 @@
|
|
|
50
51
|
}
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@deepseek-ai/cordis": "
|
|
54
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
55
|
-
"@deepseek-ai/dsh-client-store": "^0.2.
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.
|
|
57
|
-
"@deepseek-ai/dsh-client-ui-session": "^0.2.
|
|
58
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.
|
|
59
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
60
|
-
"@deepseek-ai/dsh-commands": "^0.2.
|
|
61
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.
|
|
62
|
-
"@deepseek-ai/dsh-llm": "^0.2.
|
|
63
|
-
"@deepseek-ai/dsh-session": "^0.2.
|
|
64
|
-
"@deepseek-ai/dsh-settings": "^0.2.
|
|
54
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
55
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.3",
|
|
56
|
+
"@deepseek-ai/dsh-client-store": "^0.2.2-rc.3",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.2-rc.3",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-session": "^0.2.2-rc.3",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.3",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.3",
|
|
61
|
+
"@deepseek-ai/dsh-commands": "^0.2.2-rc.3",
|
|
62
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.3",
|
|
63
|
+
"@deepseek-ai/dsh-llm": "^0.2.2-rc.3",
|
|
64
|
+
"@deepseek-ai/dsh-session": "^0.2.2-rc.3",
|
|
65
|
+
"@deepseek-ai/dsh-settings": "^0.2.2-rc.3",
|
|
66
|
+
"@eslint/js": "^10.0.1",
|
|
65
67
|
"@testing-library/dom": "^10.4.1",
|
|
66
68
|
"@testing-library/react": "^16.3.3",
|
|
67
69
|
"@types/node": "^22.20.0",
|
|
68
70
|
"@types/react": "~18.3.1",
|
|
69
71
|
"@types/react-dom": "~18.3.1",
|
|
70
72
|
"esbuild": "~0.25.0",
|
|
73
|
+
"eslint": "^10.15.0",
|
|
74
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
71
75
|
"jsdom": "^29.1.1",
|
|
76
|
+
"prettier": "^3.10.1",
|
|
72
77
|
"react": "^18.3.1",
|
|
73
78
|
"react-dom": "^18.2.0",
|
|
74
79
|
"typescript": "~5.7.2",
|
|
75
|
-
"
|
|
80
|
+
"typescript-eslint": "^8.72.2",
|
|
81
|
+
"vitest": "^4.1.12"
|
|
76
82
|
},
|
|
77
83
|
"files": [
|
|
78
84
|
"lib/**/*.js",
|
|
@@ -80,7 +86,8 @@
|
|
|
80
86
|
"src",
|
|
81
87
|
"cordis.patch.yml",
|
|
82
88
|
"locale/*.json",
|
|
83
|
-
"
|
|
89
|
+
"icon.svg",
|
|
90
|
+
"docs/images/**",
|
|
84
91
|
"README.md",
|
|
85
92
|
"README.en.md"
|
|
86
93
|
],
|
|
@@ -104,6 +111,9 @@
|
|
|
104
111
|
"build": "tsc -p . && node scripts/build.mjs",
|
|
105
112
|
"watch": "node scripts/build.mjs --watch",
|
|
106
113
|
"typecheck": "tsc -p . --pretty false",
|
|
114
|
+
"lint": "eslint .",
|
|
115
|
+
"format": "prettier --write .",
|
|
116
|
+
"format:check": "prettier --check .",
|
|
107
117
|
"test": "vitest run",
|
|
108
118
|
"test:watch": "vitest",
|
|
109
119
|
"prepublishOnly": "npm run build && npm test"
|
|
@@ -29,33 +29,20 @@ function icon(paths: ReactElement[]): ReactElement {
|
|
|
29
29
|
|
|
30
30
|
/** Circular arrow: run the same prompt again. */
|
|
31
31
|
export function RegenerateIcon(): ReactElement {
|
|
32
|
-
return icon([
|
|
33
|
-
<path key="arc" d="M21 12a9 9 0 1 1-3-6.7L21 8" />,
|
|
34
|
-
<path key="head" d="M21 3v5h-5" />,
|
|
35
|
-
])
|
|
32
|
+
return icon([<path key="arc" d="M21 12a9 9 0 1 1-3-6.7L21 8" />, <path key="head" d="M21 3v5h-5" />])
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
/** Two overlapping sheets: copy the result. */
|
|
39
36
|
export function CopyIcon(): ReactElement {
|
|
40
|
-
return icon([
|
|
41
|
-
<rect key="front" x="9" y="9" width="13" height="13" rx="2" />,
|
|
42
|
-
<path key="back" d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />,
|
|
43
|
-
])
|
|
37
|
+
return icon([<rect key="front" x="9" y="9" width="13" height="13" rx="2" />, <path key="back" d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />])
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
/** Arrow falling into a tray: fill the result into the composer. */
|
|
47
41
|
export function FillIcon(): ReactElement {
|
|
48
|
-
return icon([
|
|
49
|
-
<path key="stem" d="M12 3v12" />,
|
|
50
|
-
<path key="head" d="m7 10 5 5 5-5" />,
|
|
51
|
-
<path key="tray" d="M5 21h14" />,
|
|
52
|
-
])
|
|
42
|
+
return icon([<path key="stem" d="M12 3v12" />, <path key="head" d="m7 10 5 5 5-5" />, <path key="tray" d="M5 21h14" />])
|
|
53
43
|
}
|
|
54
44
|
|
|
55
45
|
/** Left arrow over a return curve: restore the pre-apply draft. */
|
|
56
46
|
export function UndoIcon(): ReactElement {
|
|
57
|
-
return icon([
|
|
58
|
-
<path key="head" d="M9 14 4 9l5-5" />,
|
|
59
|
-
<path key="curve" d="M4 9h10.5a5.5 5.5 0 0 1 0 11H8" />,
|
|
60
|
-
])
|
|
47
|
+
return icon([<path key="head" d="M9 14 4 9l5-5" />, <path key="curve" d="M4 9h10.5a5.5 5.5 0 0 1 0 11H8" />])
|
|
61
48
|
}
|
|
@@ -85,53 +85,55 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
|
|
|
85
85
|
const empty = draft.trim() === ''
|
|
86
86
|
|
|
87
87
|
/** Guard chain + fetch + panel transition for this session. */
|
|
88
|
-
const start = useCallback(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
? t('error.empty')
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
88
|
+
const start = useCallback(
|
|
89
|
+
(overrideText?: string): void => {
|
|
90
|
+
const source = overrideText ?? draft
|
|
91
|
+
if (anyBusy || source.trim() === '') return
|
|
92
|
+
if (!settings.enabled) {
|
|
93
|
+
const disabled = t('error.disabled')
|
|
94
|
+
ui.openError(uiKey, draft, { code: 'rejected', localized: disabled })
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
const check = checkInputText(source, settings.maxInputChars)
|
|
98
|
+
if (!check.ok) {
|
|
99
|
+
const message = check.code === 'empty' ? t('error.empty') : t('error.tooLong', { count: check.count, max: check.max })
|
|
100
|
+
ui.openError(uiKey, source, { code: 'rejected', localized: message })
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
if (occurrenceCount > 0) {
|
|
104
|
+
const occurrences = t('error.occurrences')
|
|
105
|
+
ui.openError(uiKey, source, { code: 'rejected', localized: occurrences })
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
if (phase !== 'plain') {
|
|
109
|
+
const busyPhase = t('error.phase')
|
|
110
|
+
ui.openError(uiKey, source, { code: 'rejected', localized: busyPhase })
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
const controller = new AbortController()
|
|
114
|
+
ui.openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort() })
|
|
115
|
+
const settle = (result: Parameters<typeof ui.settleResult>[1]): void => ui.settleResult(uiKey, result)
|
|
116
|
+
const fail = (error: unknown): void => {
|
|
117
|
+
const detail: EnhanceError = error instanceof EnhanceClientError ? error.detail : { code: 'internal', message: error instanceof Error ? error.message : String(error) }
|
|
118
|
+
ui.settleError(uiKey, detail)
|
|
119
|
+
}
|
|
120
|
+
// Progressive display when enabled: the panel fills in as the model
|
|
121
|
+
// writes, and degrades to the one-shot call on its own when the host or
|
|
122
|
+
// the transport cannot stream.
|
|
123
|
+
if (settings.streaming) {
|
|
124
|
+
requestEnhanceStream(
|
|
125
|
+
{ sessionId: wireId, text: source },
|
|
126
|
+
{
|
|
127
|
+
signal: controller.signal,
|
|
128
|
+
onDelta: (delta: string): void => ui.appendDelta(uiKey, delta),
|
|
129
|
+
},
|
|
130
|
+
).then(settle, fail)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
requestEnhance({ sessionId: wireId, text: source }, controller.signal).then(settle, fail)
|
|
134
|
+
},
|
|
135
|
+
[anyBusy, draft, occurrenceCount, phase, settings, uiKey, wireId, t],
|
|
136
|
+
)
|
|
135
137
|
|
|
136
138
|
// The session registry holds a stable identity; run always dispatches to
|
|
137
139
|
// the latest start callback. The refresh rides an effect (never the render
|
|
@@ -175,7 +177,9 @@ export function EnhanceButton(props: EnhanceButtonProps): ReactNode {
|
|
|
175
177
|
aria-disabled={empty || otherBusy || undefined}
|
|
176
178
|
onClick={() => start()}
|
|
177
179
|
>
|
|
178
|
-
<span className="dsh-pe-btn-icon" aria-hidden
|
|
180
|
+
<span className="dsh-pe-btn-icon" aria-hidden>
|
|
181
|
+
<SparkleFishIcon size={15} spinning={busy} />
|
|
182
|
+
</span>
|
|
179
183
|
</button>
|
|
180
184
|
</>
|
|
181
185
|
)
|
|
@@ -40,15 +40,28 @@ export function ResultDock(props: ResultDockProps): ReactNode {
|
|
|
40
40
|
})
|
|
41
41
|
// The host exposes the session store as a standard hook; older hosts may
|
|
42
42
|
// omit it, in which case the input phase is the only send signal.
|
|
43
|
-
const useSession = (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const useSession = (
|
|
44
|
+
props as ResultDockProps & {
|
|
45
|
+
useSession?: (selector: (s: unknown) => unknown) => unknown
|
|
46
|
+
}
|
|
47
|
+
).useSession
|
|
48
|
+
// Whether the host supplies `useSession` is a property of the HOST VERSION,
|
|
49
|
+
// not of session state, so the hook count below is constant for the whole
|
|
50
|
+
// lifetime of a mount — the reason this conditional call is safe here. It is
|
|
51
|
+
// still invisible to the linter, which cannot know that. Replacing it with an
|
|
52
|
+
// unconditional call would mean fabricating a hook on hosts that ship none,
|
|
53
|
+
// and that trade is worse than the documented suppression; a real refactor
|
|
54
|
+
// needs a live host to validate against.
|
|
55
|
+
const sessionRunning =
|
|
56
|
+
useSession === undefined
|
|
57
|
+
? false
|
|
58
|
+
: // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
59
|
+
Boolean(useSession((state) => (state as { running?: unknown }).running))
|
|
60
|
+
const sessionQueued =
|
|
61
|
+
useSession === undefined
|
|
62
|
+
? 0
|
|
63
|
+
: // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
64
|
+
Number(useSession((state) => (state as { queue?: unknown[] }).queue?.length ?? 0))
|
|
52
65
|
|
|
53
66
|
// The applied chip is derived from the undo stack: it is true exactly while
|
|
54
67
|
// the composer still holds the applied text, and drops itself when the user
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { useCallback, useState, type ReactNode } from 'react'
|
|
10
10
|
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
|
|
11
|
-
import type { EnhanceError, EnhanceUsage } from '../shared/protocol'
|
|
11
|
+
import type { EnhanceError, EnhanceUsage, ClientFailureReason } from '../shared/protocol'
|
|
12
12
|
import type { PromptEnhanceKey } from './locales'
|
|
13
13
|
import type { PanelState } from './ui-state'
|
|
14
14
|
import { CopyIcon, FillIcon, RegenerateIcon, UndoIcon } from './ActionIcons'
|
|
@@ -64,6 +64,28 @@ export const UPSTREAM_ERROR_KEYS: Record<string, PromptEnhanceKey> = {
|
|
|
64
64
|
'max-tokens': 'error.upstream.maxTokens',
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Why the BROWSER half failed → the dictionary key that carries its fix hint.
|
|
69
|
+
*
|
|
70
|
+
* Same reasoning as {@link UPSTREAM_ERROR_KEYS}: the wire reasons are kebab-case
|
|
71
|
+
* and the dictionary keys are camelCase, so an interpolated key would silently
|
|
72
|
+
* miss `stream-closed` and fall back to the generic line. A `Record` over the
|
|
73
|
+
* union (not a lookup with a fallback) also makes the type checker demand copy
|
|
74
|
+
* for every reason the protocol can carry.
|
|
75
|
+
*/
|
|
76
|
+
export const CLIENT_ERROR_KEYS: Record<ClientFailureReason, PromptEnhanceKey> = {
|
|
77
|
+
unreachable: 'error.client.unreachable',
|
|
78
|
+
malformed: 'error.client.malformed',
|
|
79
|
+
refused: 'error.client.refused',
|
|
80
|
+
'stream-closed': 'error.client.streamClosed',
|
|
81
|
+
cancelled: 'error.client.cancelled',
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Whether a params value names one of the browser half's own failure reasons. */
|
|
85
|
+
function isClientFailureReason(value: unknown): value is ClientFailureReason {
|
|
86
|
+
return typeof value === 'string' && Object.hasOwn(CLIENT_ERROR_KEYS, value)
|
|
87
|
+
}
|
|
88
|
+
|
|
67
89
|
/**
|
|
68
90
|
* Primary line for a server-side error, localized by the stable code and its
|
|
69
91
|
* structured params: an upstream `reason` picks a specific fix hint when one
|
|
@@ -71,11 +93,7 @@ export const UPSTREAM_ERROR_KEYS: Record<string, PromptEnhanceKey> = {
|
|
|
71
93
|
* client-side guard shows. The server's `message` (provider raw text, config
|
|
72
94
|
* errors) renders beneath as the diagnostic detail line.
|
|
73
95
|
*/
|
|
74
|
-
function localizedErrorMessage(
|
|
75
|
-
t: ResultPanelProps['t'],
|
|
76
|
-
code: EnhanceError['code'],
|
|
77
|
-
params: EnhanceError['params'],
|
|
78
|
-
): string {
|
|
96
|
+
function localizedErrorMessage(t: ResultPanelProps['t'], code: EnhanceError['code'], params: EnhanceError['params']): string {
|
|
79
97
|
if (code === 'rejected' && typeof params?.count === 'number' && typeof params?.max === 'number') {
|
|
80
98
|
return t('error.tooLong', { count: params.count, max: params.max })
|
|
81
99
|
}
|
|
@@ -83,16 +101,30 @@ function localizedErrorMessage(
|
|
|
83
101
|
const specific = UPSTREAM_ERROR_KEYS[params.reason]
|
|
84
102
|
if (specific !== undefined) return t(specific)
|
|
85
103
|
}
|
|
104
|
+
// A transport failure in this process carries a stable reason; its copy is
|
|
105
|
+
// localized here instead of being a hardcoded Chinese `message`.
|
|
106
|
+
if (code === 'internal' && isClientFailureReason(params?.reason)) {
|
|
107
|
+
return t(CLIENT_ERROR_KEYS[params.reason], params)
|
|
108
|
+
}
|
|
86
109
|
switch (code) {
|
|
87
|
-
case 'rejected':
|
|
88
|
-
|
|
89
|
-
case '
|
|
90
|
-
|
|
91
|
-
case '
|
|
92
|
-
|
|
93
|
-
case '
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
case 'rejected':
|
|
111
|
+
return t('error.rejected')
|
|
112
|
+
case 'rate-limit':
|
|
113
|
+
return t('error.rateLimit', params)
|
|
114
|
+
case 'concurrency-limit':
|
|
115
|
+
return t('error.concurrencyLimit', params)
|
|
116
|
+
case 'cooldown':
|
|
117
|
+
return t('error.cooldown', params)
|
|
118
|
+
case 'timeout':
|
|
119
|
+
return t('error.timeout', params)
|
|
120
|
+
case 'unconfigured':
|
|
121
|
+
return t('error.unconfigured')
|
|
122
|
+
case 'effort-unsupported':
|
|
123
|
+
return t('error.effortUnsupported', params)
|
|
124
|
+
case 'upstream':
|
|
125
|
+
return t('error.upstream')
|
|
126
|
+
default:
|
|
127
|
+
return t('error.internal')
|
|
96
128
|
}
|
|
97
129
|
}
|
|
98
130
|
|
|
@@ -146,7 +178,10 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
146
178
|
// navigator.clipboard only exists in secure contexts (https / localhost);
|
|
147
179
|
// guard the dereference and fall back for plain-http LAN access.
|
|
148
180
|
if (navigator.clipboard !== undefined) {
|
|
149
|
-
navigator.clipboard.writeText(text).then(
|
|
181
|
+
navigator.clipboard.writeText(text).then(
|
|
182
|
+
() => done(true),
|
|
183
|
+
() => done(fallbackCopy(text)),
|
|
184
|
+
)
|
|
150
185
|
return
|
|
151
186
|
}
|
|
152
187
|
done(fallbackCopy(text))
|
|
@@ -160,10 +195,7 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
160
195
|
* without explicit cache writes does not print a meaningless 0.
|
|
161
196
|
*/
|
|
162
197
|
const tokenDetail = (usage: EnhanceUsage): string => {
|
|
163
|
-
const parts = [
|
|
164
|
-
t('panel.tokens.input', { count: formatTokens(usage.inputTokens) }),
|
|
165
|
-
t('panel.tokens.output', { count: formatTokens(usage.outputTokens) }),
|
|
166
|
-
]
|
|
198
|
+
const parts = [t('panel.tokens.input', { count: formatTokens(usage.inputTokens) }), t('panel.tokens.output', { count: formatTokens(usage.outputTokens) })]
|
|
167
199
|
if ((usage.cacheReadTokens ?? 0) > 0) {
|
|
168
200
|
parts.push(t('panel.tokens.cacheRead', { count: formatTokens(usage.cacheReadTokens ?? 0) }))
|
|
169
201
|
}
|
|
@@ -184,28 +216,26 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
184
216
|
{state.phase === 'result' && state.result !== undefined && (
|
|
185
217
|
<span className="dsh-pe-badge">
|
|
186
218
|
{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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
{t('panel.tokens', { total: formatTokens(totalTokensOf(state.result.usage)) })}
|
|
194
|
-
</span>
|
|
195
|
-
</>
|
|
196
|
-
)}
|
|
219
|
+
{state.result.usage === undefined ? null : (
|
|
220
|
+
<>
|
|
221
|
+
{' · '}
|
|
222
|
+
<span title={tokenDetail(state.result.usage)}>{t('panel.tokens', { total: formatTokens(totalTokensOf(state.result.usage)) })}</span>
|
|
223
|
+
</>
|
|
224
|
+
)}
|
|
197
225
|
</span>
|
|
198
226
|
)}
|
|
199
|
-
{copied === 'ok'
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
<button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}
|
|
227
|
+
{copied === 'ok' ? (
|
|
228
|
+
<span className="dsh-pe-applied">{t('panel.copiedShort')}</span>
|
|
229
|
+
) : regenerated ? (
|
|
230
|
+
<span className="dsh-pe-applied">{t('panel.regeneratedShort')}</span>
|
|
231
|
+
) : applied ? (
|
|
232
|
+
<span className="dsh-pe-applied">{t('panel.appliedShort')}</span>
|
|
233
|
+
) : undone ? (
|
|
234
|
+
<span className="dsh-pe-applied">{t('panel.undoneShort')}</span>
|
|
235
|
+
) : null}
|
|
236
|
+
<button type="button" className="dsh-pe-close" aria-label={t('panel.close')} onClick={onCancel}>
|
|
237
|
+
✕
|
|
238
|
+
</button>
|
|
209
239
|
</div>
|
|
210
240
|
</header>
|
|
211
241
|
|
|
@@ -236,9 +266,7 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
236
266
|
) : (
|
|
237
267
|
<>
|
|
238
268
|
<div>{localizedErrorMessage(t, state.error.code, state.error.params)}</div>
|
|
239
|
-
{state.error.message !== undefined && state.error.message !== '' &&
|
|
240
|
-
<div className="dsh-pe-error-detail">{state.error.message}</div>
|
|
241
|
-
)}
|
|
269
|
+
{state.error.message !== undefined && state.error.message !== '' && <div className="dsh-pe-error-detail">{state.error.message}</div>}
|
|
242
270
|
</>
|
|
243
271
|
)}
|
|
244
272
|
</div>
|
|
@@ -250,13 +278,9 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
250
278
|
</div>
|
|
251
279
|
)}
|
|
252
280
|
|
|
253
|
-
{state.phase === 'result' && state.result?.truncated === true && (
|
|
254
|
-
<div className="dsh-pe-stale">⚠ {t('panel.truncated')}</div>
|
|
255
|
-
)}
|
|
281
|
+
{state.phase === 'result' && state.result?.truncated === true && <div className="dsh-pe-stale">⚠ {t('panel.truncated')}</div>}
|
|
256
282
|
|
|
257
|
-
{state.phase === 'result' && state.stale && (
|
|
258
|
-
<div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>
|
|
259
|
-
)}
|
|
283
|
+
{state.phase === 'result' && state.stale && <div className="dsh-pe-stale">⚠ {t('panel.stale.warn')}</div>}
|
|
260
284
|
|
|
261
285
|
<footer className="dsh-pe-foot">
|
|
262
286
|
<span className="dsh-pe-grow" />
|
|
@@ -269,12 +293,16 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
269
293
|
{state.phase === 'error' && (
|
|
270
294
|
<>
|
|
271
295
|
{retryable(state.error?.code) && onRetry !== undefined && (
|
|
272
|
-
<button type="button" className="dsh-pe-btn-action plain" onClick={onRetry}>
|
|
296
|
+
<button type="button" className="dsh-pe-btn-action plain" onClick={onRetry}>
|
|
297
|
+
{t('panel.retry')}
|
|
298
|
+
</button>
|
|
273
299
|
)}
|
|
274
300
|
</>
|
|
275
301
|
)}
|
|
276
302
|
{state.phase === 'loading' && (
|
|
277
|
-
<button type="button" className="dsh-pe-btn-action plain" onClick={onCancel}>
|
|
303
|
+
<button type="button" className="dsh-pe-btn-action plain" onClick={onCancel}>
|
|
304
|
+
{t('panel.cancel')}
|
|
305
|
+
</button>
|
|
278
306
|
)}
|
|
279
307
|
{state.phase === 'result' && (
|
|
280
308
|
<>
|
|
@@ -288,7 +316,10 @@ export function ResultPanel(props: ResultPanelProps): ReactNode {
|
|
|
288
316
|
{t('undo.undo')}
|
|
289
317
|
</button>
|
|
290
318
|
) : (
|
|
291
|
-
<button type="button" className="dsh-pe-btn-action primary" onClick={onApply}
|
|
319
|
+
<button type="button" className="dsh-pe-btn-action primary" onClick={onApply}>
|
|
320
|
+
<FillIcon />
|
|
321
|
+
{t('panel.apply')}
|
|
322
|
+
</button>
|
|
292
323
|
)}
|
|
293
324
|
</>
|
|
294
325
|
)}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The composer mark: the DeepSeek fish with
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* The composer mark: the DeepSeek fish with a four-point sparkle at its
|
|
3
|
+
* upper-left corner. The fish is the brand path used by the Harness bundles; the
|
|
4
|
+
* star is the NovelAI-style enhance mark. Both are painted with currentColor so
|
|
5
|
+
* the icon follows the button's label color, and the busy state pulses the whole
|
|
6
|
+
* mark instead of swapping glyphs.
|
|
7
|
+
*
|
|
8
|
+
* The arrangement is the one approved for the plugin icon: the star is larger and
|
|
9
|
+
* sits further outside the whale, so the two shapes stop crowding each other.
|
|
10
|
+
* `icon.svg` draws the same arrangement at 1.2027, bounding-box centred, so its
|
|
11
|
+
* ink fills 94% of that 36-unit canvas; here the pair is scaled to 0.835 and
|
|
12
|
+
* shifted so the glyph keeps the 26x20 footprint and margins it had before,
|
|
13
|
+
* which is what keeps the button the same size. Change one, change the other.
|
|
7
14
|
* @module dsh-prompt-enhance/client/SparkleFishIcon
|
|
8
15
|
*/
|
|
9
16
|
|
|
@@ -16,26 +23,24 @@ const FISH_PATH =
|
|
|
16
23
|
/** A four-point star, used at the fish's upper-left corner. */
|
|
17
24
|
const STAR_PATH = 'M5.715 0 L7.2 4.2 L11.43 5.715 L7.2 7.2 L5.715 11.43 L4.2 7.2 L0 5.715 L4.2 4.2 Z'
|
|
18
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Placement of the two paths inside the 26x20 glyph box, derived from the
|
|
28
|
+
* approved A+C arrangement by a single 0.834684 scale plus the offset that keeps
|
|
29
|
+
* the ink box at its previous 1.20..24.68 x 0.81..17.74 position.
|
|
30
|
+
*/
|
|
31
|
+
const FISH_TRANSFORM = 'translate(6.4976 4.3528) scale(0.78502)'
|
|
32
|
+
const STAR_TRANSFORM = 'translate(1.1944 0.7969) scale(0.60097)'
|
|
33
|
+
|
|
19
34
|
/** A fish-plus-sparkle mark sized to its container. */
|
|
20
35
|
export function SparkleFishIcon(props: { size?: number; spinning?: boolean }): ReactElement {
|
|
21
36
|
const size = props.size ?? 15
|
|
22
37
|
return (
|
|
23
|
-
<svg
|
|
24
|
-
|
|
25
|
-
height={size}
|
|
26
|
-
viewBox="0 0 26 20"
|
|
27
|
-
fill="none"
|
|
28
|
-
aria-hidden="true"
|
|
29
|
-
focusable="false"
|
|
30
|
-
style={{ display: 'block', flexShrink: 0 }}
|
|
31
|
-
>
|
|
32
|
-
<g transform="translate(5,3) scale(0.85)">
|
|
38
|
+
<svg width={size * 1.3} height={size} viewBox="0 0 26 20" fill="none" aria-hidden="true" focusable="false" style={{ display: 'block', flexShrink: 0 }}>
|
|
39
|
+
<g transform={FISH_TRANSFORM}>
|
|
33
40
|
<path d={FISH_PATH} fill="currentColor" />
|
|
34
41
|
</g>
|
|
35
|
-
<path d={STAR_PATH} transform=
|
|
36
|
-
{props.spinning === true
|
|
37
|
-
? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" />
|
|
38
|
-
: null}
|
|
42
|
+
<path d={STAR_PATH} transform={STAR_TRANSFORM} fill="currentColor" />
|
|
43
|
+
{props.spinning === true ? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" /> : null}
|
|
39
44
|
</svg>
|
|
40
45
|
)
|
|
41
|
-
}
|
|
46
|
+
}
|
package/src/client/UndoBar.tsx
CHANGED
|
@@ -42,9 +42,7 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
42
42
|
// The result card owns the undo affordance while it is open; the standalone
|
|
43
43
|
// row takes over only after the card is closed.
|
|
44
44
|
const panel = ui.getPanel()
|
|
45
|
-
const visible = (panel === undefined || panel.sessionId !== uiKey)
|
|
46
|
-
&& entry !== undefined
|
|
47
|
-
&& entry.applied === draft
|
|
45
|
+
const visible = (panel === undefined || panel.sessionId !== uiKey) && entry !== undefined && entry.applied === draft
|
|
48
46
|
const rootRef = useDockAlignment(visible)
|
|
49
47
|
if (!visible) return null
|
|
50
48
|
|
|
@@ -59,10 +57,17 @@ export function UndoBar(props: UndoBarProps): ReactNode {
|
|
|
59
57
|
return (
|
|
60
58
|
<div ref={rootRef} className="dsh-pe-dock">
|
|
61
59
|
<div className="dsh-pe-undo">
|
|
62
|
-
<span className="dsh-pe-undo-check" aria-hidden
|
|
60
|
+
<span className="dsh-pe-undo-check" aria-hidden>
|
|
61
|
+
✓
|
|
62
|
+
</span>
|
|
63
63
|
<span>{t('undo.applied')}</span>
|
|
64
|
-
<button type="button" className="dsh-pe-undo-link" onClick={undo}
|
|
65
|
-
|
|
64
|
+
<button type="button" className="dsh-pe-undo-link" onClick={undo}>
|
|
65
|
+
<UndoIcon />
|
|
66
|
+
{t('undo.undo')}
|
|
67
|
+
</button>
|
|
68
|
+
<button type="button" className="dsh-pe-undo-x" aria-label={t('undo.dismiss')} onClick={dismiss}>
|
|
69
|
+
✕
|
|
70
|
+
</button>
|
|
66
71
|
</div>
|
|
67
72
|
</div>
|
|
68
73
|
)
|