@surfishs/dsh-prompt-enhance 0.0.6 → 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 +454 -397
- 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 +20 -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 +166 -1109
- 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/styles.ts +52 -0
- 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
|
@@ -5,7 +5,16 @@
|
|
|
5
5
|
* @module dsh-prompt-enhance/client/enhance-client
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ENHANCE_ENDPOINT,
|
|
10
|
+
ENHANCE_STREAM_ENDPOINT,
|
|
11
|
+
type EnhanceError,
|
|
12
|
+
type EnhanceErrorCode,
|
|
13
|
+
type EnhanceRequestBody,
|
|
14
|
+
type EnhanceResult,
|
|
15
|
+
type EnhanceStreamEvent,
|
|
16
|
+
type EnhanceUsage,
|
|
17
|
+
} from '../shared/protocol'
|
|
9
18
|
|
|
10
19
|
/** Typed fetch failure carrying the wire error. */
|
|
11
20
|
export class EnhanceClientError extends Error {
|
|
@@ -29,32 +38,18 @@ function jsonBody(body: EnhanceRequestBody): Uint8Array {
|
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
/** The stable error codes the host may send; anything else normalizes to `internal`. */
|
|
32
|
-
const KNOWN_ERROR_CODES = new Set<EnhanceErrorCode>([
|
|
33
|
-
'rejected',
|
|
34
|
-
'rate-limit',
|
|
35
|
-
'concurrency-limit',
|
|
36
|
-
'cooldown',
|
|
37
|
-
'timeout',
|
|
38
|
-
'upstream',
|
|
39
|
-
'unconfigured',
|
|
40
|
-
'internal',
|
|
41
|
-
'effort-unsupported',
|
|
42
|
-
])
|
|
41
|
+
const KNOWN_ERROR_CODES = new Set<EnhanceErrorCode>(['rejected', 'rate-limit', 'concurrency-limit', 'cooldown', 'timeout', 'upstream', 'unconfigured', 'internal', 'effort-unsupported'])
|
|
43
42
|
|
|
44
43
|
/** Narrow one wire error, normalizing unknown codes. `message`/`params` are optional. */
|
|
45
44
|
function parseError(value: unknown): EnhanceError {
|
|
46
45
|
const record = value as Partial<EnhanceError> | null
|
|
47
46
|
if (record !== null && typeof record === 'object') {
|
|
48
|
-
const code: EnhanceErrorCode = typeof record.code === 'string' && KNOWN_ERROR_CODES.has(record.code as EnhanceErrorCode)
|
|
49
|
-
? record.code as EnhanceErrorCode
|
|
50
|
-
: 'internal'
|
|
47
|
+
const code: EnhanceErrorCode = typeof record.code === 'string' && KNOWN_ERROR_CODES.has(record.code as EnhanceErrorCode) ? (record.code as EnhanceErrorCode) : 'internal'
|
|
51
48
|
const message = typeof record.message === 'string' && record.message !== '' ? record.message : undefined
|
|
52
|
-
const params = record.params !== null && typeof record.params === 'object'
|
|
53
|
-
? record.params as Record<string, string | number>
|
|
54
|
-
: undefined
|
|
49
|
+
const params = record.params !== null && typeof record.params === 'object' ? (record.params as Record<string, string | number>) : undefined
|
|
55
50
|
return { code, ...(message !== undefined ? { message } : {}), ...(params !== undefined ? { params } : {}) }
|
|
56
51
|
}
|
|
57
|
-
return { code: 'internal',
|
|
52
|
+
return { code: 'internal', params: { reason: 'malformed' } }
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
/** One finite, non-negative token count, or undefined when absent/malformed. */
|
|
@@ -80,9 +75,9 @@ function parseUsage(value: unknown): EnhanceUsage | undefined {
|
|
|
80
75
|
return {
|
|
81
76
|
inputTokens,
|
|
82
77
|
outputTokens,
|
|
83
|
-
...totalTokens === undefined ? {} : { totalTokens },
|
|
84
|
-
...cacheReadTokens === undefined ? {} : { cacheReadTokens },
|
|
85
|
-
...cacheWriteTokens === undefined ? {} : { cacheWriteTokens },
|
|
78
|
+
...(totalTokens === undefined ? {} : { totalTokens }),
|
|
79
|
+
...(cacheReadTokens === undefined ? {} : { cacheReadTokens }),
|
|
80
|
+
...(cacheWriteTokens === undefined ? {} : { cacheWriteTokens }),
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
83
|
|
|
@@ -90,11 +85,16 @@ function parseUsage(value: unknown): EnhanceUsage | undefined {
|
|
|
90
85
|
function parseResult(value: unknown): EnhanceResult {
|
|
91
86
|
const record = value as Partial<EnhanceResult> | null
|
|
92
87
|
if (
|
|
93
|
-
record !== null &&
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
record !== null &&
|
|
89
|
+
typeof record === 'object' &&
|
|
90
|
+
typeof record.text === 'string' &&
|
|
91
|
+
record.text !== '' &&
|
|
92
|
+
typeof record.provider === 'string' &&
|
|
93
|
+
record.provider !== '' &&
|
|
94
|
+
typeof record.model === 'string' &&
|
|
95
|
+
record.model !== '' &&
|
|
96
|
+
typeof record.elapsedMs === 'number' &&
|
|
97
|
+
Number.isFinite(record.elapsedMs)
|
|
98
98
|
) {
|
|
99
99
|
const usage = parseUsage((record as { usage?: unknown }).usage)
|
|
100
100
|
return {
|
|
@@ -102,10 +102,10 @@ function parseResult(value: unknown): EnhanceResult {
|
|
|
102
102
|
provider: record.provider,
|
|
103
103
|
model: record.model,
|
|
104
104
|
elapsedMs: record.elapsedMs,
|
|
105
|
-
...usage === undefined ? {} : { usage },
|
|
105
|
+
...(usage === undefined ? {} : { usage }),
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
108
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'malformed' } })
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/** Read and validate the response envelope. */
|
|
@@ -114,7 +114,7 @@ async function readEnvelope(response: Response): Promise<EnhanceResult> {
|
|
|
114
114
|
try {
|
|
115
115
|
parsed = await response.json()
|
|
116
116
|
} catch {
|
|
117
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
117
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'malformed' } })
|
|
118
118
|
}
|
|
119
119
|
const envelope = parsed as { ok?: unknown; value?: EnhanceResult; error?: EnhanceError } | null
|
|
120
120
|
if (envelope !== null && typeof envelope === 'object' && envelope.ok === true) {
|
|
@@ -123,7 +123,7 @@ async function readEnvelope(response: Response): Promise<EnhanceResult> {
|
|
|
123
123
|
if (envelope !== null && typeof envelope === 'object' && envelope.error !== undefined) {
|
|
124
124
|
throw new EnhanceClientError(parseError(envelope.error))
|
|
125
125
|
}
|
|
126
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
126
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'malformed', status: response.status } })
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -140,14 +140,14 @@ async function readEnvelope(response: Response): Promise<EnhanceResult> {
|
|
|
140
140
|
*/
|
|
141
141
|
async function rejectionOf(response: Response): Promise<EnhanceClientError> {
|
|
142
142
|
try {
|
|
143
|
-
const parsed = await response.json() as { error?: unknown } | null
|
|
143
|
+
const parsed = (await response.json()) as { error?: unknown } | null
|
|
144
144
|
if (parsed !== null && typeof parsed === 'object' && parsed.error !== undefined) {
|
|
145
145
|
return new EnhanceClientError(parseError(parsed.error))
|
|
146
146
|
}
|
|
147
147
|
} catch {
|
|
148
148
|
// Not the JSON envelope (proxy error page, empty body): fall through.
|
|
149
149
|
}
|
|
150
|
-
return new EnhanceClientError({ code: 'internal',
|
|
150
|
+
return new EnhanceClientError({ code: 'internal', params: { reason: 'refused', status: response.status } })
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
/** One SSE frame: the event name line and the `data:` payload line. */
|
|
@@ -220,10 +220,10 @@ export async function requestEnhanceStream(body: EnhanceRequestBody, options: En
|
|
|
220
220
|
} as RequestInit)
|
|
221
221
|
} catch (error) {
|
|
222
222
|
if (options.signal?.aborted) {
|
|
223
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
223
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'cancelled' } })
|
|
224
224
|
}
|
|
225
225
|
void error
|
|
226
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
226
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'unreachable' } })
|
|
227
227
|
}
|
|
228
228
|
const contentType = String(response.headers.get('content-type') ?? '').toLowerCase()
|
|
229
229
|
// A refusal is the server answering, not a missing stream: report it as-is
|
|
@@ -235,7 +235,9 @@ export async function requestEnhanceStream(body: EnhanceRequestBody, options: En
|
|
|
235
235
|
// one-shot path instead.
|
|
236
236
|
// `cancel()` may return a promise in some runtimes and undefined in
|
|
237
237
|
// others, so wrap before catching rather than assuming a promise.
|
|
238
|
-
void Promise.resolve()
|
|
238
|
+
void Promise.resolve()
|
|
239
|
+
.then(() => stream?.cancel())
|
|
240
|
+
.catch(() => {})
|
|
239
241
|
return requestEnhance(body, options.signal)
|
|
240
242
|
}
|
|
241
243
|
const reader = stream.getReader()
|
|
@@ -257,9 +259,11 @@ export async function requestEnhanceStream(body: EnhanceRequestBody, options: En
|
|
|
257
259
|
}
|
|
258
260
|
}
|
|
259
261
|
} finally {
|
|
260
|
-
void Promise.resolve()
|
|
262
|
+
void Promise.resolve()
|
|
263
|
+
.then(() => reader.cancel())
|
|
264
|
+
.catch(() => {})
|
|
261
265
|
}
|
|
262
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
266
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'stream-closed' } })
|
|
263
267
|
}
|
|
264
268
|
|
|
265
269
|
/**
|
|
@@ -280,10 +284,10 @@ export async function requestEnhance(body: EnhanceRequestBody, signal?: AbortSig
|
|
|
280
284
|
} as RequestInit)
|
|
281
285
|
} catch (error) {
|
|
282
286
|
if (signal?.aborted) {
|
|
283
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
287
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'cancelled' } })
|
|
284
288
|
}
|
|
285
289
|
void error
|
|
286
|
-
throw new EnhanceClientError({ code: 'internal',
|
|
290
|
+
throw new EnhanceClientError({ code: 'internal', params: { reason: 'unreachable' } })
|
|
287
291
|
}
|
|
288
292
|
return readEnvelope(response)
|
|
289
293
|
}
|
package/src/client/index.tsx
CHANGED
|
@@ -129,10 +129,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
129
129
|
if (slots === undefined) return
|
|
130
130
|
return slots.inject('conversation.input.right', () => {
|
|
131
131
|
try {
|
|
132
|
-
return slots.register(
|
|
133
|
-
{ name: 'conversation.input.right', id: 'dsh-prompt-enhance', order: 60, locale: NS },
|
|
134
|
-
EnhanceButton as unknown as never,
|
|
135
|
-
)
|
|
132
|
+
return slots.register({ name: 'conversation.input.right', id: 'dsh-prompt-enhance', order: 60, locale: NS }, EnhanceButton as unknown as never)
|
|
136
133
|
} catch (error) {
|
|
137
134
|
return report('composer enhance button slot', error)
|
|
138
135
|
}
|
|
@@ -144,10 +141,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
144
141
|
if (slots === undefined) return
|
|
145
142
|
return slots.inject('conversation.input.dock', () => {
|
|
146
143
|
try {
|
|
147
|
-
return slots.register(
|
|
148
|
-
{ name: 'conversation.input.dock', id: 'dsh-prompt-enhance-result', order: 30, locale: NS },
|
|
149
|
-
ResultDock as unknown as never,
|
|
150
|
-
)
|
|
144
|
+
return slots.register({ name: 'conversation.input.dock', id: 'dsh-prompt-enhance-result', order: 30, locale: NS }, ResultDock as unknown as never)
|
|
151
145
|
} catch (error) {
|
|
152
146
|
return report('result dock slot', error)
|
|
153
147
|
}
|
|
@@ -159,10 +153,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
159
153
|
if (slots === undefined) return
|
|
160
154
|
return slots.inject('conversation.input.dock', () => {
|
|
161
155
|
try {
|
|
162
|
-
return slots.register(
|
|
163
|
-
{ name: 'conversation.input.dock', id: 'dsh-prompt-enhance-undo', order: 90, locale: NS },
|
|
164
|
-
UndoBar as unknown as never,
|
|
165
|
-
)
|
|
156
|
+
return slots.register({ name: 'conversation.input.dock', id: 'dsh-prompt-enhance-undo', order: 90, locale: NS }, UndoBar as unknown as never)
|
|
166
157
|
} catch (error) {
|
|
167
158
|
return report('undo bar slot', error)
|
|
168
159
|
}
|
|
@@ -46,28 +46,26 @@ function endpoint(path: string, params: Record<string, string> = {}): URL {
|
|
|
46
46
|
export async function fetchProviders(signal?: AbortSignal): Promise<ProviderCatalogEntry[] | undefined> {
|
|
47
47
|
const value = await getJson<ProviderCatalog>(endpoint(LLM_PROVIDERS_ENDPOINT), signal)
|
|
48
48
|
if (value === undefined || !Array.isArray(value.providers)) return undefined
|
|
49
|
-
return value.providers.filter(
|
|
50
|
-
entry
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
&& typeof entry.registered === 'boolean'
|
|
54
|
-
))
|
|
49
|
+
return value.providers.filter(
|
|
50
|
+
(entry): entry is ProviderCatalogEntry =>
|
|
51
|
+
entry !== null && typeof entry === 'object' && typeof entry.id === 'string' && entry.id !== '' && typeof entry.name === 'string' && entry.name !== '' && typeof entry.registered === 'boolean',
|
|
52
|
+
)
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
/** Models of one provider, or undefined when the read failed. */
|
|
58
56
|
export async function fetchModels(provider: string, signal?: AbortSignal): Promise<ModelCatalog | undefined> {
|
|
59
57
|
const value = await getJson<ModelCatalog>(endpoint(LLM_MODELS_ENDPOINT, { provider }), signal)
|
|
60
58
|
if (value === undefined || !Array.isArray(value.models)) return undefined
|
|
61
|
-
const models = value.models
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return { models, ...typeof value.reason === 'string' ? { reason: value.reason as ModelCatalog['reason'] } : {} }
|
|
59
|
+
const models = value.models
|
|
60
|
+
.filter(
|
|
61
|
+
(entry): entry is ModelCatalogEntry => entry !== null && typeof entry === 'object' && typeof entry.id === 'string' && entry.id !== '' && typeof entry.name === 'string' && entry.name !== '',
|
|
62
|
+
)
|
|
63
|
+
.map((entry) => ({
|
|
64
|
+
id: entry.id,
|
|
65
|
+
name: entry.name,
|
|
66
|
+
...(typeof entry.description === 'string' && entry.description !== '' ? { description: entry.description } : {}),
|
|
67
|
+
}))
|
|
68
|
+
return { models, ...(typeof value.reason === 'string' ? { reason: value.reason as ModelCatalog['reason'] } : {}) }
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
/** Whether one exact route resolves; undefined when the check itself failed. */
|
package/src/client/locales.ts
CHANGED
|
@@ -52,6 +52,11 @@ export const zh = {
|
|
|
52
52
|
'error.effortUnsupported': '该模型不支持所选推理档位「{effort}」,请改选其它档位,或改用「跟随提供方默认」。',
|
|
53
53
|
'error.upstream': '模型服务返回错误,请重试;原输入未改动。',
|
|
54
54
|
'error.internal': '增强失败,请重试;原输入未改动。',
|
|
55
|
+
'error.client.unreachable': '无法连接宿主服务,请确认 dsh web 正在运行后重试。',
|
|
56
|
+
'error.client.malformed': '宿主服务返回了无法解析的数据,请重试;原输入未改动。',
|
|
57
|
+
'error.client.refused': '宿主服务拒绝了请求(HTTP {status}),请稍后重试。',
|
|
58
|
+
'error.client.streamClosed': '宿主服务提前关闭了增强流,请重试;原输入未改动。',
|
|
59
|
+
'error.client.cancelled': '已取消增强;原输入未改动。',
|
|
55
60
|
'error.rateLimit': '请求过于频繁:每分钟最多 {limit} 次增强,请在 {retryAfterSeconds} 秒后再试。',
|
|
56
61
|
'error.concurrencyLimit': '已有 {max} 个增强正在进行,请等其中一个完成后再试。',
|
|
57
62
|
'error.cooldown': '连续 {failures} 次增强失败,已暂停调用以免持续冲击模型服务;请 {retryAfterSeconds} 秒后重试,或先检查设置里的模型配置。',
|
|
@@ -71,6 +76,7 @@ export const zh = {
|
|
|
71
76
|
'settings.saved': '已保存',
|
|
72
77
|
'settings.saveFailed': '本部署没有接受这些值,已保留供你修改。',
|
|
73
78
|
'settings.saveFailedShort': '保存失败',
|
|
79
|
+
'settings.advanced': '高级设置',
|
|
74
80
|
'settings.readOnly': '本部署的设置为只读。',
|
|
75
81
|
'settings.unavailable': '该插件当前未加载,暂时无法配置。',
|
|
76
82
|
'settings.reset': '恢复默认',
|
|
@@ -193,10 +199,16 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
193
199
|
'error.disabled': 'Prompt enhance is disabled in the plugin settings.',
|
|
194
200
|
'error.rejected': 'The enhance request was rejected.',
|
|
195
201
|
'error.timeout': 'The enhancement timed out ({seconds}s). Retry; your draft is untouched.',
|
|
196
|
-
'error.unconfigured':
|
|
202
|
+
'error.unconfigured':
|
|
203
|
+
'No model resolved for the enhancement: pair provider/model in the plugin settings, or send a message in the current session first (the enhancement will follow the session model).',
|
|
197
204
|
'error.effortUnsupported': 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "follow provider default".',
|
|
198
205
|
'error.upstream': 'The model provider returned an error. Retry; your draft is untouched.',
|
|
199
206
|
'error.internal': 'Enhancement failed. Retry; your draft is untouched.',
|
|
207
|
+
'error.client.unreachable': 'Cannot reach the host service — make sure dsh web is running, then retry.',
|
|
208
|
+
'error.client.malformed': 'The host returned data that could not be parsed. Retry; your draft is untouched.',
|
|
209
|
+
'error.client.refused': 'The host refused the request (HTTP {status}). Retry later.',
|
|
210
|
+
'error.client.streamClosed': 'The host closed the enhance stream early. Retry; your draft is untouched.',
|
|
211
|
+
'error.client.cancelled': 'The enhancement was cancelled; your draft is untouched.',
|
|
200
212
|
'error.rateLimit': 'Too many requests — at most {limit} enhancements per minute; retry in {retryAfterSeconds} seconds.',
|
|
201
213
|
'error.concurrencyLimit': '{max} enhancements are already running — wait for one to finish, then retry.',
|
|
202
214
|
'error.cooldown': '{failures} enhancements failed in a row; calls are paused to stop hammering the model service. Retry in {retryAfterSeconds}s, or check the model settings first.',
|
|
@@ -210,12 +222,14 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
210
222
|
'error.upstream.maxTokens': 'The rewrite hit the output cap (maxOutputTokens) — raise it in settings or shorten the draft.',
|
|
211
223
|
'settings.summary': 'Model, context, and resource limits',
|
|
212
224
|
'settings.title': 'Prompt enhance',
|
|
213
|
-
'settings.description':
|
|
225
|
+
'settings.description':
|
|
226
|
+
'Turns a composer draft into a structured prompt: role and goal, executable steps, output format, acceptance criteria, edge cases. The draft is preserved, failures never touch it, and saved values apply to the next call.',
|
|
214
227
|
'settings.save': 'Save',
|
|
215
228
|
'settings.saving': 'Saving…',
|
|
216
229
|
'settings.saved': 'Saved',
|
|
217
230
|
'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
|
|
218
231
|
'settings.saveFailedShort': 'Save failed',
|
|
232
|
+
'settings.advanced': 'Advanced',
|
|
219
233
|
'settings.readOnly': 'This deployment stores settings read-only.',
|
|
220
234
|
'settings.unavailable': 'This plugin is not loaded, so it cannot be configured right now.',
|
|
221
235
|
'settings.reset': 'Reset to default',
|
|
@@ -248,7 +262,8 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
248
262
|
'settings.routing.custom': 'Custom…',
|
|
249
263
|
'settings.routing.customPlaceholder': 'Type a model id',
|
|
250
264
|
'settings.routing.pairIncomplete': 'provider and model must be set together; with only one filled, the save follows the session instead.',
|
|
251
|
-
'settings.routing.routeUnavailable':
|
|
265
|
+
'settings.routing.routeUnavailable':
|
|
266
|
+
'This provider/model is currently unavailable; you can still save, but enhancement calls may fail. Check that model services are configured and the model id is correct.',
|
|
252
267
|
'settings.routing.retry': 'Retry',
|
|
253
268
|
'settings.row.temperature.label': 'Temperature',
|
|
254
269
|
'settings.row.temperature.hint': 'Sampling temperature (0–1, step 0.05); lower stays closer to the original. Default 0.3.',
|
|
@@ -261,7 +276,8 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
261
276
|
'settings.row.timeoutMs.label': 'Timeout (ms)',
|
|
262
277
|
'settings.row.timeoutMs.hint': 'End-to-end timeout of one enhancement call. Default 60000.',
|
|
263
278
|
'settings.row.strategyMode.label': 'Prompt composition',
|
|
264
|
-
'settings.row.strategyMode.hint':
|
|
279
|
+
'settings.row.strategyMode.hint':
|
|
280
|
+
'How a non-empty custom system prompt combines with the built-in strategy: replace it (the minimal output contract still applies), or append after it (the built-in rules still apply).',
|
|
265
281
|
'settings.row.systemPrompt.label': 'Custom system prompt',
|
|
266
282
|
'settings.row.systemPrompt.hint': 'Leave empty to use the built-in enhancement strategy.',
|
|
267
283
|
'settings.row.systemPrompt.placeholder': 'e.g. translate the user text from Chinese into English.',
|
|
@@ -19,7 +19,7 @@ function effortOf(value: unknown): ReasoningEffortInfo | undefined {
|
|
|
19
19
|
return {
|
|
20
20
|
id: record.id,
|
|
21
21
|
name: record.name,
|
|
22
|
-
...typeof record.description === 'string' && record.description !== '' ? { description: record.description } : {},
|
|
22
|
+
...(typeof record.description === 'string' && record.description !== '' ? { description: record.description } : {}),
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -27,19 +27,15 @@ function effortOf(value: unknown): ReasoningEffortInfo | undefined {
|
|
|
27
27
|
function capabilitiesOf(value: unknown): ReasoningCapabilities {
|
|
28
28
|
if (value === null || typeof value !== 'object') return { efforts: [], source: 'unavailable', reason: 'resolve-failed' }
|
|
29
29
|
const record = value as { efforts?: unknown; defaultEffort?: unknown; source?: unknown; reason?: unknown }
|
|
30
|
-
const source = record.source === 'resolved' || record.source === 'default' || record.source === 'unavailable'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const efforts = Array.isArray(record.efforts)
|
|
34
|
-
? record.efforts.map(effortOf).filter((effort): effort is ReasoningEffortInfo => effort !== undefined)
|
|
35
|
-
: []
|
|
36
|
-
const reason = typeof record.reason === 'string' ? record.reason as ReasoningCapabilities['reason'] : undefined
|
|
30
|
+
const source = record.source === 'resolved' || record.source === 'default' || record.source === 'unavailable' ? record.source : 'unavailable'
|
|
31
|
+
const efforts = Array.isArray(record.efforts) ? record.efforts.map(effortOf).filter((effort): effort is ReasoningEffortInfo => effort !== undefined) : []
|
|
32
|
+
const reason = typeof record.reason === 'string' ? (record.reason as ReasoningCapabilities['reason']) : undefined
|
|
37
33
|
if (source !== 'unavailable' && efforts.length === 0) return { efforts: [], source: 'unavailable', reason: 'no-efforts' }
|
|
38
34
|
return {
|
|
39
35
|
efforts,
|
|
40
36
|
source,
|
|
41
|
-
...typeof record.defaultEffort === 'string' && record.defaultEffort !== '' ? { defaultEffort: record.defaultEffort } : {},
|
|
42
|
-
...reason === undefined ? {} : { reason },
|
|
37
|
+
...(typeof record.defaultEffort === 'string' && record.defaultEffort !== '' ? { defaultEffort: record.defaultEffort } : {}),
|
|
38
|
+
...(reason === undefined ? {} : { reason }),
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
|
|
@@ -50,11 +46,7 @@ function capabilitiesOf(value: unknown): ReasoningCapabilities {
|
|
|
50
46
|
* @param options - `refresh` bypasses the host cache; `signal` cancels.
|
|
51
47
|
* @returns the validated answer; transport failures surface as `unavailable`.
|
|
52
48
|
*/
|
|
53
|
-
export async function fetchReasoningCapabilities(
|
|
54
|
-
provider: string | undefined,
|
|
55
|
-
model: string | undefined,
|
|
56
|
-
options: { refresh?: boolean; signal?: AbortSignal } = {},
|
|
57
|
-
): Promise<ReasoningCapabilities> {
|
|
49
|
+
export async function fetchReasoningCapabilities(provider: string | undefined, model: string | undefined, options: { refresh?: boolean; signal?: AbortSignal } = {}): Promise<ReasoningCapabilities> {
|
|
58
50
|
const url = new URL(REASONING_EFFORTS_ENDPOINT, globalThis.location?.origin ?? 'http://127.0.0.1')
|
|
59
51
|
if (provider !== undefined && model !== undefined) {
|
|
60
52
|
url.searchParams.set('provider', provider)
|