@surfishs/dsh-prompt-enhance 0.0.7 → 0.0.8
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 +3 -0
- package/README.md +3 -0
- package/cordis.patch.yml +1 -1
- package/lib/client.js +341 -383
- package/lib/index.js +67 -56
- package/lib/index.js.map +3 -3
- package/package.json +23 -15
- 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 +3 -13
- package/src/client/SparkleIcon.tsx +2 -12
- 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/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.8",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -50,29 +50,34 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"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.
|
|
53
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
54
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.3",
|
|
55
|
+
"@deepseek-ai/dsh-client-store": "^0.2.2-rc.3",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.2.2-rc.3",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-session": "^0.2.2-rc.3",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.3",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.3",
|
|
60
|
+
"@deepseek-ai/dsh-commands": "^0.2.2-rc.3",
|
|
61
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.3",
|
|
62
|
+
"@deepseek-ai/dsh-llm": "^0.2.2-rc.3",
|
|
63
|
+
"@deepseek-ai/dsh-session": "^0.2.2-rc.3",
|
|
64
|
+
"@deepseek-ai/dsh-settings": "^0.2.2-rc.3",
|
|
65
|
+
"@eslint/js": "^10.0.1",
|
|
65
66
|
"@testing-library/dom": "^10.4.1",
|
|
66
67
|
"@testing-library/react": "^16.3.3",
|
|
67
68
|
"@types/node": "^22.20.0",
|
|
68
69
|
"@types/react": "~18.3.1",
|
|
69
70
|
"@types/react-dom": "~18.3.1",
|
|
70
71
|
"esbuild": "~0.25.0",
|
|
72
|
+
"eslint": "^10.15.0",
|
|
73
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
71
74
|
"jsdom": "^29.1.1",
|
|
75
|
+
"prettier": "^3.10.1",
|
|
72
76
|
"react": "^18.3.1",
|
|
73
77
|
"react-dom": "^18.2.0",
|
|
74
78
|
"typescript": "~5.7.2",
|
|
75
|
-
"
|
|
79
|
+
"typescript-eslint": "^8.72.2",
|
|
80
|
+
"vitest": "^4.1.12"
|
|
76
81
|
},
|
|
77
82
|
"files": [
|
|
78
83
|
"lib/**/*.js",
|
|
@@ -80,7 +85,7 @@
|
|
|
80
85
|
"src",
|
|
81
86
|
"cordis.patch.yml",
|
|
82
87
|
"locale/*.json",
|
|
83
|
-
"docs",
|
|
88
|
+
"docs/images/**",
|
|
84
89
|
"README.md",
|
|
85
90
|
"README.en.md"
|
|
86
91
|
],
|
|
@@ -104,6 +109,9 @@
|
|
|
104
109
|
"build": "tsc -p . && node scripts/build.mjs",
|
|
105
110
|
"watch": "node scripts/build.mjs --watch",
|
|
106
111
|
"typecheck": "tsc -p . --pretty false",
|
|
112
|
+
"lint": "eslint .",
|
|
113
|
+
"format": "prettier --write .",
|
|
114
|
+
"format:check": "prettier --check .",
|
|
107
115
|
"test": "vitest run",
|
|
108
116
|
"test:watch": "vitest",
|
|
109
117
|
"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
|
)}
|
|
@@ -20,22 +20,12 @@ 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
|
|
|
20
20
|
export function SparkleFishIcon(props: { size?: number; spinning?: boolean }): ReactElement {
|
|
21
21
|
const size = props.size ?? 15
|
|
22
22
|
return (
|
|
23
|
-
<svg
|
|
24
|
-
width={size * 1.3}
|
|
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
|
-
>
|
|
23
|
+
<svg width={size * 1.3} height={size} viewBox="0 0 26 20" fill="none" aria-hidden="true" focusable="false" style={{ display: 'block', flexShrink: 0 }}>
|
|
32
24
|
<g transform="translate(5,3) scale(0.85)">
|
|
33
25
|
<path d={FISH_PATH} fill="currentColor" />
|
|
34
26
|
</g>
|
|
35
27
|
<path d={STAR_PATH} transform="translate(1.2,0.8) scale(0.55)" fill="currentColor" />
|
|
36
|
-
{props.spinning === true
|
|
37
|
-
? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" />
|
|
38
|
-
: null}
|
|
28
|
+
{props.spinning === true ? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" /> : null}
|
|
39
29
|
</svg>
|
|
40
30
|
)
|
|
41
|
-
}
|
|
31
|
+
}
|
|
@@ -12,22 +12,12 @@ import type { ReactElement } from 'react'
|
|
|
12
12
|
export function SparkleIcon(props: { size?: number; spinning?: boolean }): ReactElement {
|
|
13
13
|
const size = props.size ?? 15
|
|
14
14
|
return (
|
|
15
|
-
<svg
|
|
16
|
-
width={size}
|
|
17
|
-
height={size}
|
|
18
|
-
viewBox="0 0 16 16"
|
|
19
|
-
fill="none"
|
|
20
|
-
aria-hidden="true"
|
|
21
|
-
focusable="false"
|
|
22
|
-
style={{ display: 'block', flexShrink: 0 }}
|
|
23
|
-
>
|
|
15
|
+
<svg width={size} height={size} viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false" style={{ display: 'block', flexShrink: 0 }}>
|
|
24
16
|
<path
|
|
25
17
|
d="M5.02692 11.2125C5.22842 11.3544 5.46898 11.4303 5.71542 11.4297C5.96186 11.429 6.20204 11.352 6.40284 11.2091C6.60626 11.0605 6.76053 10.8547 6.8451 10.617L7.35593 9.0477C7.4867 8.65418 7.70731 8.29654 8.00029 8.00312C8.29327 7.7097 8.65056 7.48856 9.04383 7.35724L10.6335 6.8429C10.8685 6.7578 11.0709 6.60108 11.2121 6.39484C11.3534 6.1886 11.4264 5.94323 11.4208 5.6933C11.4153 5.44337 11.3315 5.20148 11.1812 5.00172C11.0309 4.80196 10.8217 4.65439 10.5832 4.57981L9.01183 4.06776C8.61813 3.9372 8.26027 3.71665 7.96668 3.4236C7.67308 3.13056 7.45184 2.77309 7.3205 2.37959L6.80396 0.793139C6.72078 0.559416 6.56684 0.357433 6.36355 0.215288C6.16025 0.0731435 5.91772 -0.0020932 5.66968 4.43152e-05C5.42164 0.00218183 5.18044 0.0815873 4.97962 0.227214C4.77881 0.372841 4.62837 0.577448 4.54923 0.81257L4.02697 2.41273C3.89617 2.79564 3.68006 3.1438 3.39497 3.43091C3.10989 3.71803 2.76329 3.93657 2.38135 4.07005L0.792873 4.58096C0.559281 4.66432 0.357437 4.81836 0.215361 5.02168C0.0732858 5.225 -0.00197096 5.46752 3.92466e-05 5.71557C0.00204945 5.96362 0.0812268 6.20489 0.226579 6.40588C0.371931 6.60687 0.576246 6.75762 0.811157 6.83719L2.38135 7.34581C2.77671 7.47731 3.13575 7.69966 3.42967 7.99502C3.72359 8.29038 3.94421 8.65052 4.07383 9.04656L4.59037 10.6364C4.67265 10.8696 4.82579 11.0708 5.02692 11.2125ZM12.0402 15.8324C12.1571 15.9146 12.2915 15.9685 12.4328 15.9897C12.5742 16.011 12.7185 15.9991 12.8544 15.955C12.9903 15.9109 13.1141 15.8357 13.2159 15.7355C13.3178 15.6352 13.395 15.5127 13.4413 15.3775L13.7247 14.5065C13.7857 14.3259 13.8874 14.1617 14.0218 14.0265C14.1567 13.8893 14.3212 13.7888 14.5018 13.7293L15.384 13.4413C15.5661 13.3784 15.7237 13.2597 15.8342 13.102C15.9448 12.9443 16.0028 12.7557 16.0099 12.5631C15.997 12.3705 15.9333 12.1838 15.818 12.0295C15.7027 11.8752 15.5416 11.7613 15.3578 11.704L14.4847 11.4182C14.3039 11.3581 14.1397 11.2569 14.0048 11.1224C13.8699 10.9879 13.7682 10.8239 13.7076 10.6433L13.4196 9.75977C13.3577 9.57805 13.2403 9.42041 13.0839 9.30918C12.9275 9.19795 12.74 9.13877 12.5481 9.14003C12.3562 9.1413 12.1695 9.20294 12.0146 9.31622C11.8596 9.42951 11.7443 9.58869 11.6848 9.7712L11.4026 10.6421C11.3444 10.8214 11.2455 10.9847 11.1136 11.1194C10.9818 11.254 10.8206 11.3563 10.6426 11.4182L9.75922 11.7063C9.57745 11.7679 9.41968 11.8851 9.30827 12.0414C9.19685 12.1977 9.13744 12.3851 9.13845 12.5771C9.13946 12.769 9.20085 12.9558 9.3139 13.1109C9.42696 13.266 9.58596 13.3816 9.76836 13.4413L10.6403 13.7236C10.8232 13.7853 10.9877 13.8871 11.1226 14.0219C11.2586 14.1579 11.3591 14.3225 11.4174 14.5043L11.7065 15.3889C11.7691 15.5678 11.8857 15.7227 12.0402 15.8324Z"
|
|
26
18
|
fill="currentColor"
|
|
27
19
|
/>
|
|
28
|
-
{props.spinning === true
|
|
29
|
-
? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" />
|
|
30
|
-
: null}
|
|
20
|
+
{props.spinning === true ? <animate attributeName="opacity" values="1;0.35;1" dur="1.1s" repeatCount="indefinite" /> : null}
|
|
31
21
|
</svg>
|
|
32
22
|
)
|
|
33
23
|
}
|
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
|
)
|