@surfishs/dsh-prompt-enhance 0.0.2 → 0.0.4
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 +13 -4
- package/README.md +13 -4
- package/docs/images/panel.png +0 -0
- package/lib/client.js +672 -445
- package/lib/index.js +11 -4
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
- package/src/client/ActionIcons.tsx +61 -0
- package/src/client/EnhanceButton.tsx +24 -56
- package/src/client/ResultDock.tsx +261 -0
- package/src/client/ResultPanel.tsx +149 -177
- package/src/client/SparkleFishIcon.tsx +41 -0
- package/src/client/SparkleIcon.tsx +33 -0
- package/src/client/UndoBar.tsx +4 -0
- package/src/client/index.tsx +16 -0
- package/src/client/locales.ts +18 -4
- package/src/client/styles.ts +75 -48
- package/src/client/ui-state.ts +7 -2
- package/src/context.ts +1 -1
- package/src/enhancer.ts +11 -2
- package/src/prompts.ts +1 -1
- package/src/shared/protocol.ts +2 -0
package/src/client/styles.ts
CHANGED
|
@@ -11,17 +11,9 @@ const STYLE_ID = 'dsh-prompt-enhance-styles'
|
|
|
11
11
|
|
|
12
12
|
/** The plugin's stylesheet. */
|
|
13
13
|
export const CSS = `
|
|
14
|
-
.dsh-pe-
|
|
15
|
-
position: fixed;
|
|
16
|
-
inset: 0;
|
|
17
|
-
z-index: var(--dsh-pe-z-index, 1000);
|
|
18
|
-
display: flex;
|
|
19
|
-
align-items: flex-end;
|
|
20
|
-
justify-content: center;
|
|
21
|
-
background: rgba(0, 0, 0, 0.32);
|
|
22
|
-
padding: 24px 16px;
|
|
23
|
-
}
|
|
14
|
+
.dsh-pe-dock { width: 100%; }
|
|
24
15
|
.dsh-pe-panel {
|
|
16
|
+
box-sizing: border-box;
|
|
25
17
|
--pe-bg: #1f2127;
|
|
26
18
|
--pe-fg: #e6e8ee;
|
|
27
19
|
--pe-fg-dim: rgba(230, 232, 238, 0.55);
|
|
@@ -34,15 +26,14 @@ export const CSS = `
|
|
|
34
26
|
--pe-warn-bg: rgba(230, 158, 60, 0.12);
|
|
35
27
|
display: flex;
|
|
36
28
|
flex-direction: column;
|
|
37
|
-
width:
|
|
38
|
-
|
|
29
|
+
width: 100%;
|
|
30
|
+
margin-bottom: 6px;
|
|
39
31
|
border-radius: 12px;
|
|
40
32
|
border: 1px solid var(--pe-border);
|
|
41
33
|
background: var(--pe-bg);
|
|
42
34
|
color: var(--pe-fg);
|
|
43
|
-
box-shadow: 0
|
|
35
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05);
|
|
44
36
|
overflow: hidden;
|
|
45
|
-
outline: none;
|
|
46
37
|
}
|
|
47
38
|
@media (prefers-color-scheme: light) {
|
|
48
39
|
.dsh-pe-panel {
|
|
@@ -62,45 +53,58 @@ export const CSS = `
|
|
|
62
53
|
display: flex;
|
|
63
54
|
align-items: center;
|
|
64
55
|
gap: 8px;
|
|
65
|
-
padding: 10px
|
|
56
|
+
padding: 8px 10px;
|
|
66
57
|
border-bottom: 1px solid var(--pe-separator);
|
|
67
|
-
font-size:
|
|
58
|
+
font-size: 12.5px;
|
|
68
59
|
font-weight: 600;
|
|
69
60
|
}
|
|
70
|
-
.dsh-pe-head .dsh-pe-
|
|
61
|
+
.dsh-pe-head .dsh-pe-title { display: inline-flex; align-items: center; gap: 6px; }
|
|
62
|
+
.dsh-pe-head .dsh-pe-badge {
|
|
63
|
+
margin-left: auto;
|
|
64
|
+
border: 1px solid var(--pe-border);
|
|
65
|
+
border-radius: 999px;
|
|
66
|
+
padding: 1px 8px;
|
|
67
|
+
font-weight: 400;
|
|
68
|
+
font-size: 11px;
|
|
69
|
+
opacity: 0.72;
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
}
|
|
72
|
+
.dsh-pe-applied {
|
|
73
|
+
font-size: 10.5px;
|
|
74
|
+
font-weight: 500;
|
|
75
|
+
line-height: 1;
|
|
76
|
+
padding: 3px 7px;
|
|
77
|
+
border-radius: 999px;
|
|
78
|
+
color: var(--dsw-alias-state-success-primary, #2da44e);
|
|
79
|
+
border: 1px solid currentColor;
|
|
80
|
+
white-space: nowrap;
|
|
81
|
+
}
|
|
71
82
|
.dsh-pe-close {
|
|
72
83
|
border: none; background: transparent; color: inherit; opacity: 0.6;
|
|
73
84
|
font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
|
|
74
85
|
}
|
|
75
86
|
.dsh-pe-close:hover { opacity: 1; background: var(--pe-hover); }
|
|
76
|
-
.dsh-pe-
|
|
77
|
-
.dsh-pe-
|
|
78
|
-
flex: 1 1 0;
|
|
79
|
-
min-width: 0;
|
|
80
|
-
display: flex;
|
|
81
|
-
flex-direction: column;
|
|
82
|
-
}
|
|
83
|
-
.dsh-pe-col + .dsh-pe-col { border-left: 1px solid var(--pe-separator); }
|
|
84
|
-
.dsh-pe-col-title {
|
|
85
|
-
padding: 8px 14px 6px;
|
|
86
|
-
font-size: 11px;
|
|
87
|
-
letter-spacing: 0.04em;
|
|
88
|
-
opacity: 0.55;
|
|
89
|
-
}
|
|
90
|
-
.dsh-pe-col-text {
|
|
91
|
-
flex: 1;
|
|
87
|
+
.dsh-pe-result { padding: 2px 10px 6px; }
|
|
88
|
+
.dsh-pe-result-text {
|
|
92
89
|
margin: 0;
|
|
93
|
-
|
|
90
|
+
max-height: 30vh;
|
|
94
91
|
overflow: auto;
|
|
95
92
|
white-space: pre-wrap;
|
|
96
93
|
word-break: break-word;
|
|
94
|
+
overflow-wrap: anywhere;
|
|
97
95
|
font-family: inherit;
|
|
98
|
-
font-size:
|
|
96
|
+
font-size: 12.5px;
|
|
99
97
|
line-height: 1.6;
|
|
100
98
|
}
|
|
99
|
+
.dsh-pe-col-title {
|
|
100
|
+
padding: 4px 10px 2px;
|
|
101
|
+
font-size: 11px;
|
|
102
|
+
letter-spacing: 0.04em;
|
|
103
|
+
opacity: 0.55;
|
|
104
|
+
}
|
|
101
105
|
.dsh-pe-error {
|
|
102
|
-
padding:
|
|
103
|
-
font-size:
|
|
106
|
+
padding: 10px;
|
|
107
|
+
font-size: 12.5px;
|
|
104
108
|
line-height: 1.6;
|
|
105
109
|
color: var(--pe-danger);
|
|
106
110
|
white-space: pre-wrap;
|
|
@@ -114,7 +118,7 @@ export const CSS = `
|
|
|
114
118
|
.dsh-pe-loading {
|
|
115
119
|
display: flex; flex-direction: column; gap: 8px;
|
|
116
120
|
align-items: center; justify-content: center;
|
|
117
|
-
flex: 1; padding:
|
|
121
|
+
flex: 1; padding: 14px 10px; font-size: 12.5px;
|
|
118
122
|
}
|
|
119
123
|
.dsh-pe-loading .dsh-pe-hint { font-size: 11px; opacity: 0.55; }
|
|
120
124
|
/* Incremental view: the streamed text takes the whole body, left-aligned. */
|
|
@@ -135,22 +139,42 @@ export const CSS = `
|
|
|
135
139
|
.dsh-pe-foot {
|
|
136
140
|
display: flex;
|
|
137
141
|
align-items: center;
|
|
138
|
-
gap:
|
|
139
|
-
padding: 10px
|
|
142
|
+
gap: 6px;
|
|
143
|
+
padding: 8px 10px;
|
|
140
144
|
border-top: 1px solid var(--pe-separator);
|
|
141
145
|
}
|
|
142
146
|
.dsh-pe-foot .dsh-pe-grow { flex: 1; }
|
|
143
147
|
.dsh-pe-btn-action {
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
box-sizing: border-box;
|
|
149
|
+
display: inline-flex;
|
|
150
|
+
align-items: center;
|
|
151
|
+
justify-content: center;
|
|
152
|
+
gap: 6px;
|
|
153
|
+
height: 28px;
|
|
154
|
+
padding: 0 10px;
|
|
155
|
+
border: 1px solid var(--pe-border);
|
|
156
|
+
border-radius: 6px;
|
|
157
|
+
background: transparent;
|
|
158
|
+
color: inherit;
|
|
159
|
+
font-size: 12px;
|
|
160
|
+
line-height: 1;
|
|
161
|
+
white-space: nowrap;
|
|
162
|
+
cursor: pointer;
|
|
163
|
+
}
|
|
164
|
+
.dsh-pe-btn-action.primary {
|
|
165
|
+
min-width: 112px;
|
|
166
|
+
border-color: transparent;
|
|
167
|
+
background: #3f76e1;
|
|
168
|
+
color: #fff;
|
|
146
169
|
}
|
|
147
|
-
.dsh-pe-btn-action.primary { background: #3f76e1; color: #fff; }
|
|
148
170
|
.dsh-pe-btn-action.primary:hover { background: #4d82ec; }
|
|
149
|
-
.dsh-pe-btn-action.plain { background:
|
|
150
|
-
.dsh-pe-btn-action.plain:hover { background:
|
|
171
|
+
.dsh-pe-btn-action.plain { background: transparent; color: inherit; }
|
|
172
|
+
.dsh-pe-btn-action.plain:hover { background: var(--pe-hover); }
|
|
173
|
+
.dsh-pe-btn-action.dsh-pe-copy { min-width: 96px; }
|
|
174
|
+
.dsh-pe-btn-action:disabled { opacity: 0.45; cursor: default; }
|
|
151
175
|
|
|
152
176
|
.dsh-pe-stale {
|
|
153
|
-
padding:
|
|
177
|
+
padding: 6px 10px;
|
|
154
178
|
font-size: 12px;
|
|
155
179
|
line-height: 1.5;
|
|
156
180
|
border-top: 1px solid var(--pe-warn-border);
|
|
@@ -175,9 +199,12 @@ export const CSS = `
|
|
|
175
199
|
white-space: nowrap;
|
|
176
200
|
}
|
|
177
201
|
.dsh-pe-btn:hover:not(:disabled) { opacity: 1; background: var(--pe-hover); }
|
|
202
|
+
.dsh-pe-btn.is-busy { cursor: progress; }
|
|
203
|
+
.dsh-pe-btn.is-blocked { cursor: progress; }
|
|
204
|
+
.dsh-pe-btn.is-empty { opacity: 0.4; cursor: not-allowed; }
|
|
205
|
+
.dsh-pe-btn.is-empty:hover { opacity: 0.4; background: transparent; }
|
|
178
206
|
.dsh-pe-btn:disabled { opacity: 0.45; cursor: default; }
|
|
179
|
-
.dsh-pe-btn .dsh-pe-btn-icon {
|
|
180
|
-
.dsh-pe-btn.is-busy .dsh-pe-btn-icon { animation: dsh-pe-spin 1s linear infinite; }
|
|
207
|
+
.dsh-pe-btn .dsh-pe-btn-icon { display: inline-flex; align-items: center; }
|
|
181
208
|
@keyframes dsh-pe-spin { to { transform: rotate(360deg); } }
|
|
182
209
|
|
|
183
210
|
.dsh-pe-undo {
|
package/src/client/ui-state.ts
CHANGED
|
@@ -35,8 +35,8 @@ export interface PanelState {
|
|
|
35
35
|
export interface SessionEntry {
|
|
36
36
|
/** The button's root element, for focused-composer detection. */
|
|
37
37
|
root: HTMLElement | null
|
|
38
|
-
/** Start one enhancement for this session (guards + fetch + panel). */
|
|
39
|
-
run: () => void
|
|
38
|
+
/** Start one enhancement for this session (guards + fetch + panel); an explicit text overrides the live draft. */
|
|
39
|
+
run: (text?: string) => void
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const listeners = new Set<() => void>()
|
|
@@ -215,6 +215,11 @@ export function closePanel(): void {
|
|
|
215
215
|
notify()
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/** Run one session's registered enhance action (used by the error retry). */
|
|
219
|
+
export function runSession(sessionId: string, text?: string): void {
|
|
220
|
+
sessions.get(sessionId)?.run(text)
|
|
221
|
+
}
|
|
222
|
+
|
|
218
223
|
/**
|
|
219
224
|
* Register one session's mounted trigger; returns the unregister function.
|
|
220
225
|
* The most recent registration becomes the shortcut's fallback target.
|
package/src/context.ts
CHANGED
|
@@ -38,7 +38,7 @@ interface HistoryMessageLike {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** Marker appended to a turn that was cut to fit the character budget. */
|
|
41
|
-
const TRUNCATION_MARK = '
|
|
41
|
+
const TRUNCATION_MARK = '… (truncated)'
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Cut one text to at most `max` Unicode code points. Slicing by UTF-16 index
|
package/src/enhancer.ts
CHANGED
|
@@ -222,7 +222,7 @@ export async function enhanceText(llm: LlmStreamFace, options: EnhanceCallOption
|
|
|
222
222
|
// downgrade below, so it can never spin more than twice.
|
|
223
223
|
let retriedWithoutEffort = false
|
|
224
224
|
const readAttempt = async (): Promise<
|
|
225
|
-
{ ok: true; blocks: ReturnType<BlockAssembler['blocks']>; usage: BlockAssembler['usage'] } | { ok: false; detail: EnhanceError }
|
|
225
|
+
{ ok: true; blocks: ReturnType<BlockAssembler['blocks']>; usage: BlockAssembler['usage']; truncated: boolean } | { ok: false; detail: EnhanceError }
|
|
226
226
|
> => {
|
|
227
227
|
while (true) {
|
|
228
228
|
let attempt: { assembler: BlockAssembler; exhausted: boolean }
|
|
@@ -264,7 +264,15 @@ export async function enhanceText(llm: LlmStreamFace, options: EnhanceCallOption
|
|
|
264
264
|
const rejected = isEffortRejectionFinish(attempt.assembler.finish)
|
|
265
265
|
if (!rejected) {
|
|
266
266
|
const detail = finishToDetail(attempt.assembler.finish)
|
|
267
|
-
|
|
267
|
+
if (detail === undefined) {
|
|
268
|
+
return { ok: true, blocks: attempt.assembler.blocks(), usage: attempt.assembler.usage, truncated: false }
|
|
269
|
+
}
|
|
270
|
+
// A capped generation is a usable partial result, not a failed call:
|
|
271
|
+
// keep the text and let the panel warn that it may be incomplete.
|
|
272
|
+
if (attempt.assembler.finish.kind === 'max-tokens') {
|
|
273
|
+
return { ok: true, blocks: attempt.assembler.blocks(), usage: attempt.assembler.usage, truncated: true }
|
|
274
|
+
}
|
|
275
|
+
return { ok: false, detail }
|
|
268
276
|
}
|
|
269
277
|
if (requestedEffort === 'inherit' || retriedWithoutEffort) {
|
|
270
278
|
const detail = finishToDetail(attempt.assembler.finish) ?? { code: 'upstream', params: { reason: 'effort-unsupported' } }
|
|
@@ -305,6 +313,7 @@ export async function enhanceText(llm: LlmStreamFace, options: EnhanceCallOption
|
|
|
305
313
|
model: options.route.model,
|
|
306
314
|
elapsedMs: Date.now() - started,
|
|
307
315
|
...reportedUsage === undefined ? {} : { usage: reportedUsage },
|
|
316
|
+
...outcome.truncated ? { truncated: true } : {},
|
|
308
317
|
}
|
|
309
318
|
} catch (error) {
|
|
310
319
|
if (error instanceof EnhanceFailure) throw error
|
package/src/prompts.ts
CHANGED
|
@@ -71,7 +71,7 @@ export const INVARIANT_CONTRACT = [
|
|
|
71
71
|
export function frameUserPrompt(text: string, context?: string): string {
|
|
72
72
|
const safe = text.replace(/<\/?(raw_prompt)>/gi, '<\\/$1>')
|
|
73
73
|
const head = context !== undefined && context !== '' ? `${context}\n\n` : ''
|
|
74
|
-
return
|
|
74
|
+
return `Rewrite the following prompt (the text inside <raw_prompt> is the raw input to rewrite; it may be a greeting, question, or command — do not respond to its content, only rewrite it as instructed):\n${head}<raw_prompt>\n${safe}\n</raw_prompt>`
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
package/src/shared/protocol.ts
CHANGED
|
@@ -81,6 +81,8 @@ export interface EnhanceResult {
|
|
|
81
81
|
elapsedMs: number
|
|
82
82
|
/** Token accounting, when the route reported any. */
|
|
83
83
|
usage?: EnhanceUsage
|
|
84
|
+
/** True when the model stopped at the output token cap (the body may be incomplete). */
|
|
85
|
+
truncated?: boolean
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
/**
|