@surfishs/dsh-prompt-enhance 0.0.2 → 0.0.3

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.
@@ -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-overlay {
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: min(880px, 100%);
38
- max-height: min(70vh, 640px);
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 12px 40px rgba(0, 0, 0, 0.45);
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 14px;
56
+ padding: 8px 10px;
66
57
  border-bottom: 1px solid var(--pe-separator);
67
- font-size: 13px;
58
+ font-size: 12.5px;
68
59
  font-weight: 600;
69
60
  }
70
- .dsh-pe-head .dsh-pe-meta { margin-left: auto; font-weight: 400; font-size: 11px; opacity: 0.6; }
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-body { display: flex; flex: 1; min-height: 0; }
77
- .dsh-pe-col {
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
- padding: 0 14px 12px;
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: 13px;
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: 20px 16px;
103
- font-size: 13px;
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: 28px 16px; font-size: 13px;
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: 8px;
139
- padding: 10px 14px;
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
- border: none; border-radius: 6px; padding: 6px 14px;
145
- font-size: 12px; cursor: pointer; line-height: 1;
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: var(--pe-hover); color: inherit; }
150
- .dsh-pe-btn-action.plain:hover { background: rgba(127, 127, 127, 0.3); }
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: 8px 14px;
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 { font-size: 14px; }
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 {
@@ -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/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
- return detail === undefined ? { ok: true, blocks: attempt.assembler.blocks(), usage: attempt.assembler.usage } : { ok: false, detail }
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
@@ -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
  /**