@surfishs/dsh-prompt-enhance 0.0.5 → 0.0.6
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 +17 -8
- package/README.md +16 -7
- package/docs/images/panel-en-915.png +0 -0
- package/docs/images/panel.png +0 -0
- package/lib/client.js +255 -34
- package/package.json +1 -1
- package/src/client/locales.ts +8 -4
- package/src/client/settings-page.tsx +212 -14
- package/src/client/styles.ts +47 -0
package/README.en.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[简体中文](./README.md) | English
|
|
10
10
|
|
|
11
|
-

|
|
11
|
+

|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -119,15 +119,20 @@ An empty or attachment-only draft dims the button and starts no request; raise `
|
|
|
119
119
|
|
|
120
120
|
## Security
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
- **Local access only**: the enhance route is served by the local DSH host and accepts only loopback addresses and local `Host` / `Origin` values, not external origins.
|
|
123
|
+
- **No model keys stored**: the plugin does not read or store model API keys; calls use the host's existing LLM configuration.
|
|
124
|
+
- **Context sent only when enabled**: with `contextAware` on, the most recent user/assistant text and the current draft are sent to the configured model provider (default: up to 8 messages and 4,000 characters); system messages, reasoning, tool results and attachments are excluded. With it off, only the draft is sent.
|
|
125
|
+
- **Sensitive conversations**: if the content must not leave the machine, turn off `contextAware` or use a local/private model route you trust.
|
|
123
126
|
|
|
124
127
|
## Troubleshooting
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
| Symptom | Check / fix |
|
|
130
|
+
|---|---|
|
|
131
|
+
| No enhance button in the toolbar | Confirm `enabled` is `true`; restart DSH (desktop app or `dsh web`) after installing; confirm the active profile. |
|
|
132
|
+
| Button is greyed out | The composer is empty or has attachments only; type text to enable it. |
|
|
133
|
+
| Truncated result | Check the truncation warning and raise `maxOutputTokens` in settings. |
|
|
134
|
+
| "No model resolved for enhancement" | Set both `provider` and `model` in settings, or send a message in the current session so the plugin can follow the session route. |
|
|
135
|
+
| Authentication failure | Check the provider credentials/API key configured in DSH. |
|
|
131
136
|
|
|
132
137
|
## Development
|
|
133
138
|
|
|
@@ -142,4 +147,8 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
|
142
147
|
|
|
143
148
|
## License
|
|
144
149
|
|
|
145
|
-
Apache-2.0
|
|
150
|
+
Licensed under Apache-2.0; see [LICENSE](./LICENSE).
|
|
151
|
+
|
|
152
|
+
## Credits
|
|
153
|
+
|
|
154
|
+
Thanks to [rongxingda/dsh-prompt-enhance](https://github.com/rongxingda/dsh-prompt-enhance): this project's code and design build on that project (Apache-2.0).
|
package/README.md
CHANGED
|
@@ -119,15 +119,20 @@ dsh plugin --profile <profile> remove @surfishs/dsh-prompt-enhance
|
|
|
119
119
|
|
|
120
120
|
## 安全
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
- **仅本机可访问**:增强路由由本机 DSH 宿主提供,只接受回环地址和本地 `Host` / `Origin`,不接受外部来源。
|
|
123
|
+
- **不保存模型密钥**:插件不读取或存储模型 API key,调用走宿主已有的 LLM 配置。
|
|
124
|
+
- **上下文按需发送**:`contextAware` 开启时,最近几轮 user/assistant 文本和当前草稿会发给当前配置的模型服务商(默认最多 8 条消息、4000 字符);system、reasoning、工具结果和附件不会进入上下文。关闭后只发送草稿。
|
|
125
|
+
- **敏感会话**:如果内容不能外发,请关闭 `contextAware`,或改用你信任的本地/私有模型服务。
|
|
123
126
|
|
|
124
127
|
## 故障排查
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
| 现象 | 检查与处理 |
|
|
130
|
+
|---|---|
|
|
131
|
+
| 工具栏没有增强按钮 | 确认 `enabled` 为 `true`;安装后重启 DSH(桌面版或 `dsh web`);确认当前 profile 正确。 |
|
|
132
|
+
| 按钮是灰的 | 输入框为空或只有附件;输入文字后恢复。 |
|
|
133
|
+
| 结果不完整 | 查看截断提示,并在设置中调高 `maxOutputTokens`。 |
|
|
134
|
+
| 提示「尚未确定增强用的模型」 | 在设置中成对填写 `provider` / `model`;或先在当前会话发一条消息,让插件跟随会话模型。 |
|
|
135
|
+
| 鉴权失败 | 检查对应 provider 在 DSH 中的凭据/API Key 是否有效。 |
|
|
131
136
|
|
|
132
137
|
## 开发
|
|
133
138
|
|
|
@@ -142,4 +147,8 @@ npm run build
|
|
|
142
147
|
|
|
143
148
|
## 许可证
|
|
144
149
|
|
|
145
|
-
Apache-2.0
|
|
150
|
+
本项目采用 Apache-2.0,见 [LICENSE](./LICENSE)。
|
|
151
|
+
|
|
152
|
+
## 致敬
|
|
153
|
+
|
|
154
|
+
感谢 [rongxingda/dsh-prompt-enhance](https://github.com/rongxingda/dsh-prompt-enhance):本项目的代码与设计建立在该项目(Apache-2.0)的基础之上。
|
|
Binary file
|
package/docs/images/panel.png
CHANGED
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -1103,7 +1103,9 @@ var zh = {
|
|
|
1103
1103
|
"settings.description": "\u628A\u8F93\u5165\u6846\u8349\u7A3F\u6539\u5199\u4E3A\u7ED3\u6784\u5316\u63D0\u793A\u8BCD\uFF1A\u89D2\u8272\u4E0E\u76EE\u6807\u3001\u53EF\u6267\u884C\u6B65\u9AA4\u3001\u8F93\u51FA\u683C\u5F0F\u3001\u9A8C\u6536\u6807\u51C6\u3001\u8FB9\u754C\u6761\u4EF6\u3002\u539F\u6587\u4FDD\u7559\uFF0C\u5931\u8D25\u4E0D\u6539\u8349\u7A3F\uFF1B\u4FDD\u5B58\u540E\u4E0B\u4E00\u6B21\u8C03\u7528\u5373\u751F\u6548\u3002",
|
|
1104
1104
|
"settings.save": "\u4FDD\u5B58",
|
|
1105
1105
|
"settings.saving": "\u4FDD\u5B58\u4E2D\u2026",
|
|
1106
|
+
"settings.saved": "\u5DF2\u4FDD\u5B58",
|
|
1106
1107
|
"settings.saveFailed": "\u672C\u90E8\u7F72\u6CA1\u6709\u63A5\u53D7\u8FD9\u4E9B\u503C\uFF0C\u5DF2\u4FDD\u7559\u4F9B\u4F60\u4FEE\u6539\u3002",
|
|
1108
|
+
"settings.saveFailedShort": "\u4FDD\u5B58\u5931\u8D25",
|
|
1107
1109
|
"settings.readOnly": "\u672C\u90E8\u7F72\u7684\u8BBE\u7F6E\u4E3A\u53EA\u8BFB\u3002",
|
|
1108
1110
|
"settings.unavailable": "\u8BE5\u63D2\u4EF6\u5F53\u524D\u672A\u52A0\u8F7D\uFF0C\u6682\u65F6\u65E0\u6CD5\u914D\u7F6E\u3002",
|
|
1109
1111
|
"settings.reset": "\u6062\u590D\u9ED8\u8BA4",
|
|
@@ -1141,7 +1143,7 @@ var zh = {
|
|
|
1141
1143
|
"settings.row.temperature.label": "\u6E29\u5EA6",
|
|
1142
1144
|
"settings.row.temperature.hint": "\u91C7\u6837\u6E29\u5EA6\uFF080~1\uFF0C\u6B65\u8FDB 0.05\uFF09\uFF0C\u8D8A\u4F4E\u8D8A\u5FE0\u5B9E\u539F\u6587\uFF1B\u9ED8\u8BA4 0.3\u3002",
|
|
1143
1145
|
"settings.row.reasoningEffort.label": "\u63A8\u7406\u9884\u7B97",
|
|
1144
|
-
"settings.row.reasoningEffort.hint": "\u6863\u4F4D\u9009\u9879\u6765\u81EA\u5F53\u524D provider/model \u7684\u58F0\u660E\uFF1B\u81EA\u5B9A\u4E49\u6A21\u578B\u65F6\u6309\u9700\u8BFB\u53D6\u3002\
|
|
1146
|
+
"settings.row.reasoningEffort.hint": "\u6863\u4F4D\u9009\u9879\u6765\u81EA\u5F53\u524D provider/model \u7684\u58F0\u660E\uFF1B\u81EA\u5B9A\u4E49\u6A21\u578B\u65F6\u6309\u9700\u8BFB\u53D6\u3002\u63D0\u4F9B\u65B9\u9ED8\u8BA4\u8868\u793A\u4E0D\u4F20\u8BE5\u5B57\u6BB5\u3002",
|
|
1145
1147
|
"settings.row.maxOutputTokens.label": "\u8F93\u51FA token \u4E0A\u9650",
|
|
1146
1148
|
"settings.row.maxOutputTokens.hint": "\u5355\u6B21\u589E\u5F3A\u7684\u8F93\u51FA\u9884\u7B97\uFF1B\u9ED8\u8BA4 8192\u3002",
|
|
1147
1149
|
"settings.row.maxInputChars.label": "\u8F93\u5165\u5B57\u7B26\u4E0A\u9650",
|
|
@@ -1152,7 +1154,7 @@ var zh = {
|
|
|
1152
1154
|
"settings.row.strategyMode.hint": "\u81EA\u5B9A\u4E49\u7CFB\u7EDF\u63D0\u793A\u8BCD\u975E\u7A7A\u65F6\uFF1A\u6574\u4F53\u66FF\u6362\u5185\u7F6E\u7B56\u7565\uFF08\u4ECD\u4FDD\u7559\u6700\u5C0F\u8F93\u51FA\u5951\u7EA6\uFF09\uFF0C\u6216\u8FFD\u52A0\u5728\u5185\u7F6E\u7B56\u7565\u4E4B\u540E\uFF08\u5185\u7F6E\u89C4\u5219\u7EE7\u7EED\u751F\u6548\uFF09\u3002",
|
|
1153
1155
|
"settings.row.systemPrompt.label": "\u81EA\u5B9A\u4E49\u7CFB\u7EDF\u63D0\u793A\u8BCD",
|
|
1154
1156
|
"settings.row.systemPrompt.hint": "\u7559\u7A7A\u4F7F\u7528\u5185\u7F6E\u589E\u5F3A\u7B56\u7565\u3002",
|
|
1155
|
-
"settings.row.systemPrompt.placeholder": "\u4F8B\uFF1A\u628A\u7528\u6237\u7684\u4E2D\u6587\
|
|
1157
|
+
"settings.row.systemPrompt.placeholder": "\u4F8B\uFF1A\u628A\u7528\u6237\u7684\u4E2D\u6587\u8F93\u5165\u7FFB\u8BD1\u6210\u82F1\u6587\u3002",
|
|
1156
1158
|
"settings.row.contextMaxMessages.label": "\u4E0A\u4E0B\u6587\u6D88\u606F\u6761\u6570",
|
|
1157
1159
|
"settings.row.contextMaxMessages.hint": "\u6700\u591A\u53C2\u8003\u6700\u8FD1\u591A\u5C11\u8F6E\u5BF9\u8BDD\uFF1B0 \u8868\u793A\u4E0D\u53C2\u8003\uFF1B\u9ED8\u8BA4 8\u3002",
|
|
1158
1160
|
"settings.row.contextMaxChars.label": "\u4E0A\u4E0B\u6587\u5B57\u7B26\u4E0A\u9650",
|
|
@@ -1166,7 +1168,7 @@ var zh = {
|
|
|
1166
1168
|
"settings.row.shortcut.placeholder": "\u4F8B\uFF1Actrl+alt+shift+e",
|
|
1167
1169
|
"settings.strategy.replace": "\u66FF\u6362\u5185\u7F6E\u7B56\u7565",
|
|
1168
1170
|
"settings.strategy.extend": "\u8FFD\u52A0\u5728\u5185\u7F6E\u7B56\u7565\u540E",
|
|
1169
|
-
"settings.reasoning.inherit": "\
|
|
1171
|
+
"settings.reasoning.inherit": "\u63D0\u4F9B\u65B9\u9ED8\u8BA4",
|
|
1170
1172
|
"settings.reasoning.loading": "\u6B63\u5728\u8BFB\u53D6\u8BE5\u6A21\u578B\u7684\u6863\u4F4D\u2026",
|
|
1171
1173
|
"settings.reasoning.unavailable": "\u65E0\u6CD5\u8BFB\u53D6\u8BE5\u6A21\u578B\u7684\u6863\u4F4D\uFF0C\u4EC5\u53EF\u8DDF\u968F\u63D0\u4F9B\u65B9\u9ED8\u8BA4\u3002",
|
|
1172
1174
|
"settings.reasoning.noTiers": "\u8BE5\u6A21\u578B\u672A\u58F0\u660E\u63A8\u7406\u6863\u4F4D\uFF0C\u8C03\u7528\u65F6\u5C06\u8DDF\u968F\u63D0\u4F9B\u65B9\u9ED8\u8BA4\u3002",
|
|
@@ -1241,7 +1243,9 @@ var en = {
|
|
|
1241
1243
|
"settings.description": "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.",
|
|
1242
1244
|
"settings.save": "Save",
|
|
1243
1245
|
"settings.saving": "Saving\u2026",
|
|
1246
|
+
"settings.saved": "Saved",
|
|
1244
1247
|
"settings.saveFailed": "The deployment did not accept these values; they were left for you to correct.",
|
|
1248
|
+
"settings.saveFailedShort": "Save failed",
|
|
1245
1249
|
"settings.readOnly": "This deployment stores settings read-only.",
|
|
1246
1250
|
"settings.unavailable": "This plugin is not loaded, so it cannot be configured right now.",
|
|
1247
1251
|
"settings.reset": "Reset to default",
|
|
@@ -1279,7 +1283,7 @@ var en = {
|
|
|
1279
1283
|
"settings.row.temperature.label": "Temperature",
|
|
1280
1284
|
"settings.row.temperature.hint": "Sampling temperature (0\u20131, step 0.05); lower stays closer to the original. Default 0.3.",
|
|
1281
1285
|
"settings.row.reasoningEffort.label": "Reasoning effort",
|
|
1282
|
-
"settings.row.reasoningEffort.hint": "Tier choices come from what the configured provider/model declares; custom models are read on demand.
|
|
1286
|
+
"settings.row.reasoningEffort.hint": "Tier choices come from what the configured provider/model declares; custom models are read on demand. Provider default omits the field.",
|
|
1283
1287
|
"settings.row.maxOutputTokens.label": "Output token budget",
|
|
1284
1288
|
"settings.row.maxOutputTokens.hint": "Output budget for one enhancement call. Default 8192.",
|
|
1285
1289
|
"settings.row.maxInputChars.label": "Input character cap",
|
|
@@ -1575,6 +1579,53 @@ var CSS = `
|
|
|
1575
1579
|
font-size: 12px;
|
|
1576
1580
|
}
|
|
1577
1581
|
.dsh-pe-undo-x:hover { opacity: 1; background: var(--dsw-alias-bg-layer-2, rgba(128, 128, 128, 0.12)); }
|
|
1582
|
+
.dsh-pe-segmented-labels [role="tab"] {
|
|
1583
|
+
min-width: 0;
|
|
1584
|
+
overflow: hidden;
|
|
1585
|
+
text-overflow: ellipsis;
|
|
1586
|
+
text-align: center;
|
|
1587
|
+
white-space: nowrap;
|
|
1588
|
+
}
|
|
1589
|
+
.dsh-pe-form-footer {
|
|
1590
|
+
display: flex;
|
|
1591
|
+
justify-content: flex-end;
|
|
1592
|
+
margin-top: 12px;
|
|
1593
|
+
padding-top: 10px;
|
|
1594
|
+
border-top: 1px solid var(--dsw-alias-border-l3, rgba(128, 128, 128, 0.22));
|
|
1595
|
+
}
|
|
1596
|
+
.dsh-pe-save-group {
|
|
1597
|
+
display: flex;
|
|
1598
|
+
align-items: center;
|
|
1599
|
+
justify-content: flex-end;
|
|
1600
|
+
flex-wrap: wrap;
|
|
1601
|
+
gap: 8px;
|
|
1602
|
+
min-width: 0;
|
|
1603
|
+
max-width: 100%;
|
|
1604
|
+
margin-left: auto;
|
|
1605
|
+
}
|
|
1606
|
+
.dsh-pe-save-status {
|
|
1607
|
+
min-width: 0;
|
|
1608
|
+
max-width: 100%;
|
|
1609
|
+
font-size: 12px;
|
|
1610
|
+
color: var(--dsw-alias-label-secondary, inherit);
|
|
1611
|
+
text-align: right;
|
|
1612
|
+
overflow-wrap: anywhere;
|
|
1613
|
+
}
|
|
1614
|
+
.dsh-pe-save-button {
|
|
1615
|
+
flex: none;
|
|
1616
|
+
margin-left: 0;
|
|
1617
|
+
height: 28px;
|
|
1618
|
+
padding: 0 14px;
|
|
1619
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
|
|
1620
|
+
border-radius: 8px;
|
|
1621
|
+
background: var(--dsw-alias-bg-layer-1, transparent);
|
|
1622
|
+
color: inherit;
|
|
1623
|
+
font: inherit;
|
|
1624
|
+
font-size: 12px;
|
|
1625
|
+
cursor: pointer;
|
|
1626
|
+
}
|
|
1627
|
+
.dsh-pe-save-button:hover:not(:disabled) { background: rgba(127, 127, 127, 0.12); }
|
|
1628
|
+
.dsh-pe-save-button:disabled { opacity: 0.5; cursor: default; }
|
|
1578
1629
|
`;
|
|
1579
1630
|
function ensureStyles() {
|
|
1580
1631
|
if (document.getElementById(STYLE_ID) !== null) return false;
|
|
@@ -2026,8 +2077,8 @@ var ROWS = [
|
|
|
2026
2077
|
{ key: "streaming", kind: "boolean", label: "settings.row.streaming.label", hint: "settings.row.streaming.hint" },
|
|
2027
2078
|
{ key: "provider", kind: "provider", label: "settings.row.provider.label", hint: "settings.row.provider.hint" },
|
|
2028
2079
|
{ key: "model", kind: "model", label: "settings.row.model.label", hint: "settings.row.model.hint" },
|
|
2029
|
-
{ key: "temperature", kind: "number", label: "settings.row.temperature.label", hint: "settings.row.temperature.hint" },
|
|
2030
2080
|
{ key: "reasoningEffort", kind: "reasoning", label: "settings.row.reasoningEffort.label", hint: "settings.row.reasoningEffort.hint" },
|
|
2081
|
+
{ key: "temperature", kind: "number", label: "settings.row.temperature.label", hint: "settings.row.temperature.hint" },
|
|
2031
2082
|
{ key: "maxOutputTokens", kind: "number", label: "settings.row.maxOutputTokens.label", hint: "settings.row.maxOutputTokens.hint" },
|
|
2032
2083
|
{ key: "maxInputChars", kind: "number", label: "settings.row.maxInputChars.label", hint: "settings.row.maxInputChars.hint" },
|
|
2033
2084
|
{ key: "timeoutMs", kind: "number", label: "settings.row.timeoutMs.label", hint: "settings.row.timeoutMs.hint" },
|
|
@@ -2074,8 +2125,10 @@ function sectionCopy(t, chinese) {
|
|
|
2074
2125
|
unavailable: t("settings.unavailable"),
|
|
2075
2126
|
readOnly: t("settings.readOnly"),
|
|
2076
2127
|
saveFailed: t("settings.saveFailed"),
|
|
2128
|
+
saveFailedShort: t("settings.saveFailedShort"),
|
|
2077
2129
|
save: t("settings.save"),
|
|
2078
2130
|
saving: t("settings.saving"),
|
|
2131
|
+
saved: t("settings.saved"),
|
|
2079
2132
|
reset: t("settings.reset"),
|
|
2080
2133
|
invalidNumber: t("settings.invalidNumber")
|
|
2081
2134
|
},
|
|
@@ -2092,8 +2145,10 @@ function pageCopy(t) {
|
|
|
2092
2145
|
unavailable: t("settings.unavailable"),
|
|
2093
2146
|
readOnly: t("settings.readOnly"),
|
|
2094
2147
|
saveFailed: t("settings.saveFailed"),
|
|
2148
|
+
saveFailedShort: t("settings.saveFailedShort"),
|
|
2095
2149
|
save: t("settings.save"),
|
|
2096
2150
|
saving: t("settings.saving"),
|
|
2151
|
+
saved: t("settings.saved"),
|
|
2097
2152
|
reset: t("settings.reset"),
|
|
2098
2153
|
invalidNumber: t("settings.invalidNumber")
|
|
2099
2154
|
},
|
|
@@ -2182,7 +2237,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
|
|
|
2182
2237
|
var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
|
|
2183
2238
|
var GITHUB_MARK = "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 2-.27c.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z";
|
|
2184
2239
|
var NPM_MARK = "M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z";
|
|
2185
|
-
var PLUGIN_VERSION = true ? "0.0.
|
|
2240
|
+
var PLUGIN_VERSION = true ? "0.0.6" : "0.0.0";
|
|
2186
2241
|
var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
|
|
2187
2242
|
var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
|
|
2188
2243
|
var HEADER_TITLE_STYLE = {
|
|
@@ -2307,8 +2362,9 @@ function ChoiceRow(props) {
|
|
|
2307
2362
|
import_dsh_client_ui_primitives.SegmentedControl,
|
|
2308
2363
|
{
|
|
2309
2364
|
id: props.id,
|
|
2365
|
+
className: "dsh-pe-segmented-labels",
|
|
2310
2366
|
value: props.view.text,
|
|
2311
|
-
options: props.options,
|
|
2367
|
+
options: props.options.map((option) => ({ ...option, title: option.title ?? option.label })),
|
|
2312
2368
|
disabled: props.disabled,
|
|
2313
2369
|
label: props.label,
|
|
2314
2370
|
onChange: (next) => props.onEdit(next)
|
|
@@ -2383,11 +2439,15 @@ function ReasoningRow(props) {
|
|
|
2383
2439
|
options.push({
|
|
2384
2440
|
value: effort.id,
|
|
2385
2441
|
label: effort.name,
|
|
2386
|
-
|
|
2442
|
+
title: effort.description === void 0 ? effort.name : `${effort.name} \u2014 ${effort.description}`
|
|
2387
2443
|
});
|
|
2388
2444
|
}
|
|
2389
2445
|
}
|
|
2390
|
-
options.push({
|
|
2446
|
+
options.push({
|
|
2447
|
+
value: "inherit",
|
|
2448
|
+
label: props.copy.choice("settings.reasoning.inherit"),
|
|
2449
|
+
title: props.copy.choice("settings.reasoning.inherit")
|
|
2450
|
+
});
|
|
2391
2451
|
const unsupported = !noTiers && phase === "ready" && capabilities?.source !== "unavailable" && current2 !== "" && current2 !== "inherit" && !realTierKnown;
|
|
2392
2452
|
const refreshing = feedback === "refreshing";
|
|
2393
2453
|
const refresh = () => {
|
|
@@ -2413,6 +2473,7 @@ function ReasoningRow(props) {
|
|
|
2413
2473
|
import_dsh_client_ui_primitives.SegmentedControl,
|
|
2414
2474
|
{
|
|
2415
2475
|
id: props.id,
|
|
2476
|
+
className: "dsh-pe-segmented-labels",
|
|
2416
2477
|
value: noTiers ? "inherit" : props.view.text,
|
|
2417
2478
|
options,
|
|
2418
2479
|
disabled: props.disabled,
|
|
@@ -2524,14 +2585,19 @@ function ModelRow(props) {
|
|
|
2524
2585
|
}
|
|
2525
2586
|
function TextControl(props) {
|
|
2526
2587
|
const [focused, setFocused] = (0, import_react8.useState)(false);
|
|
2527
|
-
const
|
|
2588
|
+
const [revealedInvalid, setRevealedInvalid] = (0, import_react8.useState)(false);
|
|
2589
|
+
(0, import_react8.useEffect)(() => {
|
|
2590
|
+
if (props.invalid !== true) setRevealedInvalid(false);
|
|
2591
|
+
}, [props.invalid]);
|
|
2592
|
+
const showInvalid = props.invalid === true && revealedInvalid;
|
|
2593
|
+
const borderColor = showInvalid ? "var(--dsw-alias-state-error-primary, #f85149)" : focused ? "var(--dsw-alias-state-business-primary, #4f8cff)" : void 0;
|
|
2528
2594
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2529
2595
|
"input",
|
|
2530
2596
|
{
|
|
2531
2597
|
id: props.id,
|
|
2532
2598
|
type: "text",
|
|
2533
2599
|
inputMode: props.numeric === true ? "numeric" : void 0,
|
|
2534
|
-
"aria-invalid":
|
|
2600
|
+
"aria-invalid": showInvalid || void 0,
|
|
2535
2601
|
disabled: props.disabled,
|
|
2536
2602
|
placeholder: props.placeholder,
|
|
2537
2603
|
value: props.value,
|
|
@@ -2541,7 +2607,17 @@ function TextControl(props) {
|
|
|
2541
2607
|
...borderColor === void 0 ? {} : { borderColor }
|
|
2542
2608
|
},
|
|
2543
2609
|
onFocus: () => setFocused(true),
|
|
2544
|
-
onBlur: () =>
|
|
2610
|
+
onBlur: () => {
|
|
2611
|
+
setFocused(false);
|
|
2612
|
+
if (props.invalid === true) setRevealedInvalid(true);
|
|
2613
|
+
props.onCommit?.();
|
|
2614
|
+
},
|
|
2615
|
+
onKeyDown: (event) => {
|
|
2616
|
+
if (event.key !== "Enter") return;
|
|
2617
|
+
event.preventDefault();
|
|
2618
|
+
if (props.invalid === true) setRevealedInvalid(true);
|
|
2619
|
+
props.onCommit?.();
|
|
2620
|
+
},
|
|
2545
2621
|
onChange: (event) => props.onChange(event.target.value)
|
|
2546
2622
|
}
|
|
2547
2623
|
);
|
|
@@ -2562,7 +2638,8 @@ function ValueRow(props) {
|
|
|
2562
2638
|
numeric: props.numeric,
|
|
2563
2639
|
invalid,
|
|
2564
2640
|
disabled: props.disabled,
|
|
2565
|
-
onChange: props.onEdit
|
|
2641
|
+
onChange: props.onEdit,
|
|
2642
|
+
onCommit: props.onCommit
|
|
2566
2643
|
}
|
|
2567
2644
|
),
|
|
2568
2645
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
|
|
@@ -2578,7 +2655,8 @@ function SettingsRow(props) {
|
|
|
2578
2655
|
view: props.view,
|
|
2579
2656
|
disabled: props.disabled,
|
|
2580
2657
|
onEdit: props.onEdit,
|
|
2581
|
-
onReset: props.onReset
|
|
2658
|
+
onReset: props.onReset,
|
|
2659
|
+
onCommit: props.onCommit
|
|
2582
2660
|
};
|
|
2583
2661
|
switch (props.row.kind) {
|
|
2584
2662
|
case "boolean":
|
|
@@ -2599,24 +2677,140 @@ function SettingsRows(props) {
|
|
|
2599
2677
|
const provider = viewOf(props.state, "provider").text.trim();
|
|
2600
2678
|
const model = viewOf(props.state, "model").text.trim();
|
|
2601
2679
|
const routing = useLlmRouting(provider, model);
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
disabled: !props.state.writable,
|
|
2612
|
-
reasoningPair: { provider, model },
|
|
2613
|
-
routing,
|
|
2614
|
-
providerValue: provider,
|
|
2615
|
-
onEdit: (text) => props.edit(row.key, text),
|
|
2616
|
-
onReset: () => props.resetField(row.key)
|
|
2680
|
+
const [saveState, setSaveState] = (0, import_react8.useState)("idle");
|
|
2681
|
+
const timers = (0, import_react8.useRef)(/* @__PURE__ */ new Map());
|
|
2682
|
+
const savedTimer = (0, import_react8.useRef)(void 0);
|
|
2683
|
+
const savedValues = (0, import_react8.useRef)(/* @__PURE__ */ new Map());
|
|
2684
|
+
const sequence = (0, import_react8.useRef)(0);
|
|
2685
|
+
(0, import_react8.useEffect)(() => {
|
|
2686
|
+
for (const row of ROWS) {
|
|
2687
|
+
if (!savedValues.current.has(row.key)) {
|
|
2688
|
+
savedValues.current.set(row.key, viewOf(props.state, row.key).text);
|
|
2617
2689
|
}
|
|
2618
|
-
|
|
2619
|
-
}
|
|
2690
|
+
}
|
|
2691
|
+
}, [props.state]);
|
|
2692
|
+
const runSave = async (key, text) => {
|
|
2693
|
+
if (props.writeField === void 0) return;
|
|
2694
|
+
if (savedValues.current.get(key) === text) return;
|
|
2695
|
+
const ticket = ++sequence.current;
|
|
2696
|
+
setSaveState("saving");
|
|
2697
|
+
const result = await props.writeField(key, text);
|
|
2698
|
+
if (ticket !== sequence.current) return;
|
|
2699
|
+
if (result === "invalid") {
|
|
2700
|
+
setSaveState("idle");
|
|
2701
|
+
return;
|
|
2702
|
+
}
|
|
2703
|
+
if (result === "failed") {
|
|
2704
|
+
setSaveState("failed");
|
|
2705
|
+
return;
|
|
2706
|
+
}
|
|
2707
|
+
savedValues.current.set(key, text);
|
|
2708
|
+
markSaved();
|
|
2709
|
+
};
|
|
2710
|
+
const markSaved = () => {
|
|
2711
|
+
setSaveState("saved");
|
|
2712
|
+
if (savedTimer.current !== void 0) clearTimeout(savedTimer.current);
|
|
2713
|
+
savedTimer.current = setTimeout(() => {
|
|
2714
|
+
setSaveState("idle");
|
|
2715
|
+
savedTimer.current = void 0;
|
|
2716
|
+
}, 2e3);
|
|
2717
|
+
};
|
|
2718
|
+
const manualSave = async () => {
|
|
2719
|
+
if (props.writeField === void 0) {
|
|
2720
|
+
props.save?.();
|
|
2721
|
+
markSaved();
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
const changed = ROWS.map((row) => ({ key: row.key, text: viewOf(props.state, row.key).text })).filter((item) => savedValues.current.get(item.key) !== item.text);
|
|
2725
|
+
if (changed.length === 0) {
|
|
2726
|
+
markSaved();
|
|
2727
|
+
return;
|
|
2728
|
+
}
|
|
2729
|
+
const ticket = ++sequence.current;
|
|
2730
|
+
setSaveState("saving");
|
|
2731
|
+
let failed = false;
|
|
2732
|
+
let invalid = false;
|
|
2733
|
+
for (const item of changed) {
|
|
2734
|
+
const result = await props.writeField(item.key, item.text);
|
|
2735
|
+
if (result === "saved") savedValues.current.set(item.key, item.text);
|
|
2736
|
+
else if (result === "failed") failed = true;
|
|
2737
|
+
else invalid = true;
|
|
2738
|
+
}
|
|
2739
|
+
if (ticket !== sequence.current) return;
|
|
2740
|
+
if (failed) setSaveState("failed");
|
|
2741
|
+
else if (invalid && changed.every((item) => savedValues.current.get(item.key) !== item.text)) setSaveState("idle");
|
|
2742
|
+
else markSaved();
|
|
2743
|
+
};
|
|
2744
|
+
const scheduleSave = (key, text, immediate) => {
|
|
2745
|
+
const pending = timers.current.get(key);
|
|
2746
|
+
if (pending !== void 0) clearTimeout(pending);
|
|
2747
|
+
if (immediate) {
|
|
2748
|
+
timers.current.delete(key);
|
|
2749
|
+
void runSave(key, text);
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
const timer = setTimeout(() => {
|
|
2753
|
+
timers.current.delete(key);
|
|
2754
|
+
void runSave(key, text);
|
|
2755
|
+
}, 800);
|
|
2756
|
+
timers.current.set(key, timer);
|
|
2757
|
+
};
|
|
2758
|
+
const onEdit = (key, text) => {
|
|
2759
|
+
props.edit(key, text);
|
|
2760
|
+
const row = ROWS.find((item) => item.key === key);
|
|
2761
|
+
const debounced = row !== void 0 && (row.kind === "text" || row.kind === "number");
|
|
2762
|
+
scheduleSave(key, text, !debounced);
|
|
2763
|
+
};
|
|
2764
|
+
const flushField = (key, text) => {
|
|
2765
|
+
const pending = timers.current.get(key);
|
|
2766
|
+
if (pending !== void 0) {
|
|
2767
|
+
clearTimeout(pending);
|
|
2768
|
+
timers.current.delete(key);
|
|
2769
|
+
}
|
|
2770
|
+
void runSave(key, text ?? viewOf(props.state, key).text);
|
|
2771
|
+
};
|
|
2772
|
+
(0, import_react8.useEffect)(() => () => {
|
|
2773
|
+
for (const timer of timers.current.values()) clearTimeout(timer);
|
|
2774
|
+
timers.current.clear();
|
|
2775
|
+
if (savedTimer.current !== void 0) clearTimeout(savedTimer.current);
|
|
2776
|
+
}, []);
|
|
2777
|
+
const statusText = props.state.writable === false ? props.copy.labels.readOnly : saveState === "saving" ? props.copy.labels.saving : saveState === "saved" ? props.copy.labels.saved : saveState === "failed" ? props.copy.labels.saveFailedShort : "";
|
|
2778
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsh-pe-form", children: [
|
|
2779
|
+
ROWS.map((row, index) => {
|
|
2780
|
+
const raw = viewOf(props.state, row.key);
|
|
2781
|
+
const view = raw.overridden && atDefaultValue(row.key, raw.text) ? { ...raw, overridden: false } : raw;
|
|
2782
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: index === 0 ? void 0 : SEPARATOR_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2783
|
+
SettingsRow,
|
|
2784
|
+
{
|
|
2785
|
+
row,
|
|
2786
|
+
copy: props.copy,
|
|
2787
|
+
view,
|
|
2788
|
+
disabled: !props.state.writable,
|
|
2789
|
+
reasoningPair: { provider, model },
|
|
2790
|
+
routing,
|
|
2791
|
+
providerValue: provider,
|
|
2792
|
+
onEdit: (text) => onEdit(row.key, text),
|
|
2793
|
+
onReset: () => props.resetField(row.key),
|
|
2794
|
+
onCommit: () => flushField(row.key, viewOf(props.state, row.key).text)
|
|
2795
|
+
}
|
|
2796
|
+
) }, row.key);
|
|
2797
|
+
}),
|
|
2798
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "dsh-pe-form-footer", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsh-pe-save-group", children: [
|
|
2799
|
+
statusText === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dsh-pe-save-status", role: "status", "aria-live": "polite", children: statusText }),
|
|
2800
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2801
|
+
"button",
|
|
2802
|
+
{
|
|
2803
|
+
type: "button",
|
|
2804
|
+
className: "dsh-pe-save-button",
|
|
2805
|
+
disabled: props.save === void 0 || props.state.writable === false,
|
|
2806
|
+
onClick: () => {
|
|
2807
|
+
void manualSave();
|
|
2808
|
+
},
|
|
2809
|
+
children: props.copy.labels.save
|
|
2810
|
+
}
|
|
2811
|
+
)
|
|
2812
|
+
] }) })
|
|
2813
|
+
] });
|
|
2620
2814
|
}
|
|
2621
2815
|
function SettingsSection(props) {
|
|
2622
2816
|
const read = props.usePromptEnhance;
|
|
@@ -2642,7 +2836,8 @@ function SettingsSection(props) {
|
|
|
2642
2836
|
edit,
|
|
2643
2837
|
resetField,
|
|
2644
2838
|
save: props.save,
|
|
2645
|
-
discard: props.discard
|
|
2839
|
+
discard: props.discard,
|
|
2840
|
+
writeField: props.writeField
|
|
2646
2841
|
}
|
|
2647
2842
|
)
|
|
2648
2843
|
] });
|
|
@@ -2667,7 +2862,8 @@ function SettingsPage(props) {
|
|
|
2667
2862
|
edit,
|
|
2668
2863
|
resetField,
|
|
2669
2864
|
save: props.save,
|
|
2670
|
-
discard: props.discard
|
|
2865
|
+
discard: props.discard,
|
|
2866
|
+
writeField: props.writeField
|
|
2671
2867
|
}
|
|
2672
2868
|
);
|
|
2673
2869
|
}
|
|
@@ -2678,9 +2874,11 @@ var SettingsPageController = class {
|
|
|
2678
2874
|
*/
|
|
2679
2875
|
constructor(scope, getLocale) {
|
|
2680
2876
|
__publicField(this, "form");
|
|
2877
|
+
__publicField(this, "scope");
|
|
2681
2878
|
__publicField(this, "store");
|
|
2682
2879
|
__publicField(this, "getLocale");
|
|
2683
2880
|
this.getLocale = getLocale;
|
|
2881
|
+
this.scope = scope;
|
|
2684
2882
|
this.form = createSettingsForm(scope);
|
|
2685
2883
|
this.store = this.form.bind(() => {
|
|
2686
2884
|
const out = this.form.shell();
|
|
@@ -2696,7 +2894,11 @@ var SettingsPageController = class {
|
|
|
2696
2894
|
/** The props the slots hand their pages. */
|
|
2697
2895
|
inject() {
|
|
2698
2896
|
const face = this.getLocale?.();
|
|
2699
|
-
const props = {
|
|
2897
|
+
const props = {
|
|
2898
|
+
hooks: { promptEnhance: this.store },
|
|
2899
|
+
...this.form.actions(),
|
|
2900
|
+
writeField: (key, text) => this.writeField(key, text)
|
|
2901
|
+
};
|
|
2700
2902
|
if (face !== void 0) {
|
|
2701
2903
|
;
|
|
2702
2904
|
props.hooks.promptEnhanceLocale = {
|
|
@@ -2707,6 +2909,25 @@ var SettingsPageController = class {
|
|
|
2707
2909
|
}
|
|
2708
2910
|
return props;
|
|
2709
2911
|
}
|
|
2912
|
+
/** Write one field through the host's per-field mutation API. */
|
|
2913
|
+
async writeField(key, text) {
|
|
2914
|
+
const descriptor = FIELD_SPECS.find((item) => item.field === key);
|
|
2915
|
+
if (descriptor === void 0) return "failed";
|
|
2916
|
+
const parsed = descriptor.parse(text);
|
|
2917
|
+
if (parsed === void 0) return "invalid";
|
|
2918
|
+
if (this.scope.set === void 0) return "failed";
|
|
2919
|
+
try {
|
|
2920
|
+
if (parsed.kind === "clear") {
|
|
2921
|
+
if (this.scope.unset === void 0) return "failed";
|
|
2922
|
+
if (!await this.scope.unset(key)) return "failed";
|
|
2923
|
+
} else {
|
|
2924
|
+
if (!await this.scope.set(key, parsed.value)) return "failed";
|
|
2925
|
+
}
|
|
2926
|
+
return "saved";
|
|
2927
|
+
} catch {
|
|
2928
|
+
return "failed";
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2710
2931
|
/** Release the form's subscriptions. */
|
|
2711
2932
|
dispose() {
|
|
2712
2933
|
try {
|
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.6",
|
|
5
5
|
"author": "surfishs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
package/src/client/locales.ts
CHANGED
|
@@ -68,7 +68,9 @@ export const zh = {
|
|
|
68
68
|
'settings.description': '把输入框草稿改写为结构化提示词:角色与目标、可执行步骤、输出格式、验收标准、边界条件。原文保留,失败不改草稿;保存后下一次调用即生效。',
|
|
69
69
|
'settings.save': '保存',
|
|
70
70
|
'settings.saving': '保存中…',
|
|
71
|
+
'settings.saved': '已保存',
|
|
71
72
|
'settings.saveFailed': '本部署没有接受这些值,已保留供你修改。',
|
|
73
|
+
'settings.saveFailedShort': '保存失败',
|
|
72
74
|
'settings.readOnly': '本部署的设置为只读。',
|
|
73
75
|
'settings.unavailable': '该插件当前未加载,暂时无法配置。',
|
|
74
76
|
'settings.reset': '恢复默认',
|
|
@@ -106,7 +108,7 @@ export const zh = {
|
|
|
106
108
|
'settings.row.temperature.label': '温度',
|
|
107
109
|
'settings.row.temperature.hint': '采样温度(0~1,步进 0.05),越低越忠实原文;默认 0.3。',
|
|
108
110
|
'settings.row.reasoningEffort.label': '推理预算',
|
|
109
|
-
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model
|
|
111
|
+
'settings.row.reasoningEffort.hint': '档位选项来自当前 provider/model 的声明;自定义模型时按需读取。提供方默认表示不传该字段。',
|
|
110
112
|
'settings.row.maxOutputTokens.label': '输出 token 上限',
|
|
111
113
|
'settings.row.maxOutputTokens.hint': '单次增强的输出预算;默认 8192。',
|
|
112
114
|
'settings.row.maxInputChars.label': '输入字符上限',
|
|
@@ -117,7 +119,7 @@ export const zh = {
|
|
|
117
119
|
'settings.row.strategyMode.hint': '自定义系统提示词非空时:整体替换内置策略(仍保留最小输出契约),或追加在内置策略之后(内置规则继续生效)。',
|
|
118
120
|
'settings.row.systemPrompt.label': '自定义系统提示词',
|
|
119
121
|
'settings.row.systemPrompt.hint': '留空使用内置增强策略。',
|
|
120
|
-
'settings.row.systemPrompt.placeholder': '
|
|
122
|
+
'settings.row.systemPrompt.placeholder': '例:把用户的中文输入翻译成英文。',
|
|
121
123
|
'settings.row.contextMaxMessages.label': '上下文消息条数',
|
|
122
124
|
'settings.row.contextMaxMessages.hint': '最多参考最近多少轮对话;0 表示不参考;默认 8。',
|
|
123
125
|
'settings.row.contextMaxChars.label': '上下文字符上限',
|
|
@@ -131,7 +133,7 @@ export const zh = {
|
|
|
131
133
|
'settings.row.shortcut.placeholder': '例:ctrl+alt+shift+e',
|
|
132
134
|
'settings.strategy.replace': '替换内置策略',
|
|
133
135
|
'settings.strategy.extend': '追加在内置策略后',
|
|
134
|
-
'settings.reasoning.inherit': '
|
|
136
|
+
'settings.reasoning.inherit': '提供方默认',
|
|
135
137
|
'settings.reasoning.loading': '正在读取该模型的档位…',
|
|
136
138
|
'settings.reasoning.unavailable': '无法读取该模型的档位,仅可跟随提供方默认。',
|
|
137
139
|
'settings.reasoning.noTiers': '该模型未声明推理档位,调用时将跟随提供方默认。',
|
|
@@ -211,7 +213,9 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
211
213
|
'settings.description': '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.',
|
|
212
214
|
'settings.save': 'Save',
|
|
213
215
|
'settings.saving': 'Saving…',
|
|
216
|
+
'settings.saved': 'Saved',
|
|
214
217
|
'settings.saveFailed': 'The deployment did not accept these values; they were left for you to correct.',
|
|
218
|
+
'settings.saveFailedShort': 'Save failed',
|
|
215
219
|
'settings.readOnly': 'This deployment stores settings read-only.',
|
|
216
220
|
'settings.unavailable': 'This plugin is not loaded, so it cannot be configured right now.',
|
|
217
221
|
'settings.reset': 'Reset to default',
|
|
@@ -249,7 +253,7 @@ export const en: Record<PromptEnhanceKey, string> = {
|
|
|
249
253
|
'settings.row.temperature.label': 'Temperature',
|
|
250
254
|
'settings.row.temperature.hint': 'Sampling temperature (0–1, step 0.05); lower stays closer to the original. Default 0.3.',
|
|
251
255
|
'settings.row.reasoningEffort.label': 'Reasoning effort',
|
|
252
|
-
'settings.row.reasoningEffort.hint': 'Tier choices come from what the configured provider/model declares; custom models are read on demand.
|
|
256
|
+
'settings.row.reasoningEffort.hint': 'Tier choices come from what the configured provider/model declares; custom models are read on demand. Provider default omits the field.',
|
|
253
257
|
'settings.row.maxOutputTokens.label': 'Output token budget',
|
|
254
258
|
'settings.row.maxOutputTokens.hint': 'Output budget for one enhancement call. Default 8192.',
|
|
255
259
|
'settings.row.maxInputChars.label': 'Input character cap',
|
|
@@ -31,7 +31,6 @@ import { fetchReasoningCapabilities } from './reasoning-options'
|
|
|
31
31
|
import { useLlmRouting, type LlmRoutingState } from './llm-catalog'
|
|
32
32
|
import {
|
|
33
33
|
SegmentedControl,
|
|
34
|
-
SettingsForm,
|
|
35
34
|
SettingsFormModel,
|
|
36
35
|
Switch,
|
|
37
36
|
settingsNumberField,
|
|
@@ -169,8 +168,8 @@ const ROWS: readonly Row[] = [
|
|
|
169
168
|
{ key: 'streaming', kind: 'boolean', label: 'settings.row.streaming.label', hint: 'settings.row.streaming.hint' },
|
|
170
169
|
{ key: 'provider', kind: 'provider', label: 'settings.row.provider.label', hint: 'settings.row.provider.hint' },
|
|
171
170
|
{ key: 'model', kind: 'model', label: 'settings.row.model.label', hint: 'settings.row.model.hint' },
|
|
172
|
-
{ key: 'temperature', kind: 'number', label: 'settings.row.temperature.label', hint: 'settings.row.temperature.hint' },
|
|
173
171
|
{ key: 'reasoningEffort', kind: 'reasoning', label: 'settings.row.reasoningEffort.label', hint: 'settings.row.reasoningEffort.hint' },
|
|
172
|
+
{ key: 'temperature', kind: 'number', label: 'settings.row.temperature.label', hint: 'settings.row.temperature.hint' },
|
|
174
173
|
{ key: 'maxOutputTokens', kind: 'number', label: 'settings.row.maxOutputTokens.label', hint: 'settings.row.maxOutputTokens.hint' },
|
|
175
174
|
{ key: 'maxInputChars', kind: 'number', label: 'settings.row.maxInputChars.label', hint: 'settings.row.maxInputChars.hint' },
|
|
176
175
|
{ key: 'timeoutMs', kind: 'number', label: 'settings.row.timeoutMs.label', hint: 'settings.row.timeoutMs.hint' },
|
|
@@ -280,8 +279,10 @@ function sectionCopy(t: Translate, chinese: boolean): RowCopy {
|
|
|
280
279
|
unavailable: t('settings.unavailable'),
|
|
281
280
|
readOnly: t('settings.readOnly'),
|
|
282
281
|
saveFailed: t('settings.saveFailed'),
|
|
282
|
+
saveFailedShort: t('settings.saveFailedShort'),
|
|
283
283
|
save: t('settings.save'),
|
|
284
284
|
saving: t('settings.saving'),
|
|
285
|
+
saved: t('settings.saved'),
|
|
285
286
|
reset: t('settings.reset'),
|
|
286
287
|
invalidNumber: t('settings.invalidNumber'),
|
|
287
288
|
},
|
|
@@ -305,8 +306,10 @@ function pageCopy(t: Translate): RowCopy {
|
|
|
305
306
|
unavailable: t('settings.unavailable'),
|
|
306
307
|
readOnly: t('settings.readOnly'),
|
|
307
308
|
saveFailed: t('settings.saveFailed'),
|
|
309
|
+
saveFailedShort: t('settings.saveFailedShort'),
|
|
308
310
|
save: t('settings.save'),
|
|
309
311
|
saving: t('settings.saving'),
|
|
312
|
+
saved: t('settings.saved'),
|
|
310
313
|
reset: t('settings.reset'),
|
|
311
314
|
invalidNumber: t('settings.invalidNumber'),
|
|
312
315
|
},
|
|
@@ -526,6 +529,7 @@ interface FormProps {
|
|
|
526
529
|
resetField?: (key: string) => void
|
|
527
530
|
save?: () => void
|
|
528
531
|
discard?: () => void
|
|
532
|
+
writeField?: (key: string, text: string) => Promise<'saved' | 'invalid' | 'failed'>
|
|
529
533
|
}
|
|
530
534
|
|
|
531
535
|
/** One locale snapshot, as the client locale service exposes it. */
|
|
@@ -577,6 +581,8 @@ interface RowProps {
|
|
|
577
581
|
onEdit: (text: string) => void
|
|
578
582
|
/** Clear the stored value so the row re-inherits the composition default. */
|
|
579
583
|
onReset: () => void
|
|
584
|
+
/** Commit the current text now, e.g. on blur or Enter. */
|
|
585
|
+
onCommit?: () => void
|
|
580
586
|
}
|
|
581
587
|
|
|
582
588
|
/**
|
|
@@ -669,7 +675,7 @@ function BooleanRow(props: RowProps): ReactElement {
|
|
|
669
675
|
* @param props - the row, its choices, its state, and its actions.
|
|
670
676
|
* @returns the row element.
|
|
671
677
|
*/
|
|
672
|
-
function ChoiceRow(props: RowProps & { options: readonly { value: string; label: string }[] }): ReactElement {
|
|
678
|
+
function ChoiceRow(props: RowProps & { options: readonly { value: string; label: string; title?: string }[] }): ReactElement {
|
|
673
679
|
return (
|
|
674
680
|
<div style={ROW_STYLE}>
|
|
675
681
|
<div style={HEAD_STYLE}>
|
|
@@ -678,8 +684,9 @@ function ChoiceRow(props: RowProps & { options: readonly { value: string; label:
|
|
|
678
684
|
</div>
|
|
679
685
|
<SegmentedControl
|
|
680
686
|
id={props.id}
|
|
687
|
+
className="dsh-pe-segmented-labels"
|
|
681
688
|
value={props.view.text}
|
|
682
|
-
options={props.options}
|
|
689
|
+
options={props.options.map((option) => ({ ...option, title: option.title ?? option.label }))}
|
|
683
690
|
disabled={props.disabled}
|
|
684
691
|
label={props.label}
|
|
685
692
|
onChange={(next: string) => props.onEdit(next)}
|
|
@@ -783,11 +790,15 @@ function ReasoningRow(props: RowProps & { provider: string; model: string }): Re
|
|
|
783
790
|
options.push({
|
|
784
791
|
value: effort.id,
|
|
785
792
|
label: effort.name,
|
|
786
|
-
|
|
793
|
+
title: effort.description === undefined ? effort.name : `${effort.name} — ${effort.description}`,
|
|
787
794
|
})
|
|
788
795
|
}
|
|
789
796
|
}
|
|
790
|
-
options.push({
|
|
797
|
+
options.push({
|
|
798
|
+
value: 'inherit',
|
|
799
|
+
label: props.copy.choice('settings.reasoning.inherit'),
|
|
800
|
+
title: props.copy.choice('settings.reasoning.inherit'),
|
|
801
|
+
})
|
|
791
802
|
const unsupported = !noTiers && phase === 'ready' && capabilities?.source !== 'unavailable'
|
|
792
803
|
&& current !== '' && current !== 'inherit' && !realTierKnown
|
|
793
804
|
const refreshing = feedback === 'refreshing'
|
|
@@ -815,6 +826,7 @@ function ReasoningRow(props: RowProps & { provider: string; model: string }): Re
|
|
|
815
826
|
</div>
|
|
816
827
|
<SegmentedControl
|
|
817
828
|
id={props.id}
|
|
829
|
+
className="dsh-pe-segmented-labels"
|
|
818
830
|
// A route that declares no tiers is presented as "follow provider
|
|
819
831
|
// default"; the stored tier stays in the config and the host omits it
|
|
820
832
|
// on the call, so the displayed state matches what actually happens.
|
|
@@ -995,9 +1007,15 @@ function TextControl(props: {
|
|
|
995
1007
|
invalid?: boolean
|
|
996
1008
|
disabled?: boolean
|
|
997
1009
|
onChange: (value: string) => void
|
|
1010
|
+
onCommit?: () => void
|
|
998
1011
|
}): ReactElement {
|
|
999
1012
|
const [focused, setFocused] = useState(false)
|
|
1000
|
-
const
|
|
1013
|
+
const [revealedInvalid, setRevealedInvalid] = useState(false)
|
|
1014
|
+
useEffect(() => {
|
|
1015
|
+
if (props.invalid !== true) setRevealedInvalid(false)
|
|
1016
|
+
}, [props.invalid])
|
|
1017
|
+
const showInvalid = props.invalid === true && revealedInvalid
|
|
1018
|
+
const borderColor = showInvalid
|
|
1001
1019
|
? 'var(--dsw-alias-state-error-primary, #f85149)'
|
|
1002
1020
|
: focused ? 'var(--dsw-alias-state-business-primary, #4f8cff)' : undefined
|
|
1003
1021
|
return (
|
|
@@ -1005,7 +1023,7 @@ function TextControl(props: {
|
|
|
1005
1023
|
id={props.id}
|
|
1006
1024
|
type="text"
|
|
1007
1025
|
inputMode={props.numeric === true ? 'numeric' : undefined}
|
|
1008
|
-
aria-invalid={
|
|
1026
|
+
aria-invalid={showInvalid || undefined}
|
|
1009
1027
|
disabled={props.disabled}
|
|
1010
1028
|
placeholder={props.placeholder}
|
|
1011
1029
|
value={props.value}
|
|
@@ -1015,7 +1033,17 @@ function TextControl(props: {
|
|
|
1015
1033
|
...borderColor === undefined ? {} : { borderColor },
|
|
1016
1034
|
}}
|
|
1017
1035
|
onFocus={() => setFocused(true)}
|
|
1018
|
-
onBlur={() =>
|
|
1036
|
+
onBlur={() => {
|
|
1037
|
+
setFocused(false)
|
|
1038
|
+
if (props.invalid === true) setRevealedInvalid(true)
|
|
1039
|
+
props.onCommit?.()
|
|
1040
|
+
}}
|
|
1041
|
+
onKeyDown={(event) => {
|
|
1042
|
+
if (event.key !== 'Enter') return
|
|
1043
|
+
event.preventDefault()
|
|
1044
|
+
if (props.invalid === true) setRevealedInvalid(true)
|
|
1045
|
+
props.onCommit?.()
|
|
1046
|
+
}}
|
|
1019
1047
|
onChange={(event) => props.onChange(event.target.value)}
|
|
1020
1048
|
/>
|
|
1021
1049
|
)
|
|
@@ -1037,6 +1065,7 @@ function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string }):
|
|
|
1037
1065
|
invalid={invalid}
|
|
1038
1066
|
disabled={props.disabled}
|
|
1039
1067
|
onChange={props.onEdit}
|
|
1068
|
+
onCommit={props.onCommit}
|
|
1040
1069
|
/>
|
|
1041
1070
|
<p style={HINT_STYLE}>{props.hint}</p>
|
|
1042
1071
|
{invalid ? <p style={INVALID_STYLE}>{props.copy.labels.invalidNumber}</p> : null}
|
|
@@ -1049,7 +1078,7 @@ function ValueRow(props: RowProps & { numeric: boolean; placeholder?: string }):
|
|
|
1049
1078
|
* @param props - the row, its copy, its state, its actions, and the pinned pair.
|
|
1050
1079
|
* @returns the row element.
|
|
1051
1080
|
*/
|
|
1052
|
-
function SettingsRow(props: { row: Row; copy: RowCopy; view: FieldView; disabled: boolean; reasoningPair: { provider: string; model: string }; routing: LlmRoutingState; providerValue: string; onEdit: (text: string) => void; onReset: () => void }): ReactElement {
|
|
1081
|
+
function SettingsRow(props: { row: Row; copy: RowCopy; view: FieldView; disabled: boolean; reasoningPair: { provider: string; model: string }; routing: LlmRoutingState; providerValue: string; onEdit: (text: string) => void; onReset: () => void; onCommit?: () => void }): ReactElement {
|
|
1053
1082
|
const shared = {
|
|
1054
1083
|
id: `dsh-prompt-enhance-${props.row.key}`,
|
|
1055
1084
|
label: props.copy.title(props.row),
|
|
@@ -1059,6 +1088,7 @@ function SettingsRow(props: { row: Row; copy: RowCopy; view: FieldView; disabled
|
|
|
1059
1088
|
disabled: props.disabled,
|
|
1060
1089
|
onEdit: props.onEdit,
|
|
1061
1090
|
onReset: props.onReset,
|
|
1091
|
+
onCommit: props.onCommit,
|
|
1062
1092
|
}
|
|
1063
1093
|
switch (props.row.kind) {
|
|
1064
1094
|
case 'boolean':
|
|
@@ -1088,14 +1118,136 @@ function SettingsRows(props: {
|
|
|
1088
1118
|
resetField: (key: string) => void
|
|
1089
1119
|
save?: () => void
|
|
1090
1120
|
discard?: () => void
|
|
1121
|
+
writeField?: (key: string, text: string) => Promise<'saved' | 'invalid' | 'failed'>
|
|
1091
1122
|
}): ReactElement {
|
|
1092
1123
|
// The reasoning row reads the staged pair so options follow the fields before
|
|
1093
1124
|
// they are saved (typing a custom model refreshes them on its own).
|
|
1094
1125
|
const provider = viewOf(props.state, 'provider').text.trim()
|
|
1095
1126
|
const model = viewOf(props.state, 'model').text.trim()
|
|
1096
1127
|
const routing = useLlmRouting(provider, model)
|
|
1128
|
+
const [saveState, setSaveState] = useState<'idle' | 'saving' | 'saved' | 'failed'>('idle')
|
|
1129
|
+
const timers = useRef(new Map<string, ReturnType<typeof setTimeout>>())
|
|
1130
|
+
const savedTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
1131
|
+
const savedValues = useRef(new Map<string, string>())
|
|
1132
|
+
const sequence = useRef(0)
|
|
1133
|
+
|
|
1134
|
+
useEffect(() => {
|
|
1135
|
+
for (const row of ROWS) {
|
|
1136
|
+
if (!savedValues.current.has(row.key)) {
|
|
1137
|
+
savedValues.current.set(row.key, viewOf(props.state, row.key).text)
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}, [props.state])
|
|
1141
|
+
|
|
1142
|
+
const runSave = async (key: string, text: string): Promise<void> => {
|
|
1143
|
+
if (props.writeField === undefined) return
|
|
1144
|
+
// A focus/blur with no edit, or an edit reverted to the stored value, is
|
|
1145
|
+
// not a write: skip it without touching the footer status.
|
|
1146
|
+
if (savedValues.current.get(key) === text) return
|
|
1147
|
+
const ticket = ++sequence.current
|
|
1148
|
+
setSaveState('saving')
|
|
1149
|
+
const result = await props.writeField(key, text)
|
|
1150
|
+
if (ticket !== sequence.current) return
|
|
1151
|
+
if (result === 'invalid') {
|
|
1152
|
+
setSaveState('idle')
|
|
1153
|
+
return
|
|
1154
|
+
}
|
|
1155
|
+
if (result === 'failed') {
|
|
1156
|
+
setSaveState('failed')
|
|
1157
|
+
return
|
|
1158
|
+
}
|
|
1159
|
+
savedValues.current.set(key, text)
|
|
1160
|
+
markSaved()
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
const markSaved = (): void => {
|
|
1164
|
+
setSaveState('saved')
|
|
1165
|
+
if (savedTimer.current !== undefined) clearTimeout(savedTimer.current)
|
|
1166
|
+
savedTimer.current = setTimeout(() => {
|
|
1167
|
+
setSaveState('idle')
|
|
1168
|
+
savedTimer.current = undefined
|
|
1169
|
+
}, 2000)
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
const manualSave = async (): Promise<void> => {
|
|
1173
|
+
if (props.writeField === undefined) {
|
|
1174
|
+
// Hosts without per-field writes keep the original whole-form action.
|
|
1175
|
+
props.save?.()
|
|
1176
|
+
markSaved()
|
|
1177
|
+
return
|
|
1178
|
+
}
|
|
1179
|
+
const changed = ROWS
|
|
1180
|
+
.map((row) => ({ key: row.key, text: viewOf(props.state, row.key).text }))
|
|
1181
|
+
.filter((item) => savedValues.current.get(item.key) !== item.text)
|
|
1182
|
+
if (changed.length === 0) {
|
|
1183
|
+
markSaved()
|
|
1184
|
+
return
|
|
1185
|
+
}
|
|
1186
|
+
const ticket = ++sequence.current
|
|
1187
|
+
setSaveState('saving')
|
|
1188
|
+
let failed = false
|
|
1189
|
+
let invalid = false
|
|
1190
|
+
for (const item of changed) {
|
|
1191
|
+
const result = await props.writeField(item.key, item.text)
|
|
1192
|
+
if (result === 'saved') savedValues.current.set(item.key, item.text)
|
|
1193
|
+
else if (result === 'failed') failed = true
|
|
1194
|
+
else invalid = true
|
|
1195
|
+
}
|
|
1196
|
+
if (ticket !== sequence.current) return
|
|
1197
|
+
if (failed) setSaveState('failed')
|
|
1198
|
+
else if (invalid && changed.every((item) => savedValues.current.get(item.key) !== item.text)) setSaveState('idle')
|
|
1199
|
+
else markSaved()
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const scheduleSave = (key: string, text: string, immediate: boolean): void => {
|
|
1203
|
+
const pending = timers.current.get(key)
|
|
1204
|
+
if (pending !== undefined) clearTimeout(pending)
|
|
1205
|
+
if (immediate) {
|
|
1206
|
+
timers.current.delete(key)
|
|
1207
|
+
void runSave(key, text)
|
|
1208
|
+
return
|
|
1209
|
+
}
|
|
1210
|
+
const timer = setTimeout(() => {
|
|
1211
|
+
timers.current.delete(key)
|
|
1212
|
+
void runSave(key, text)
|
|
1213
|
+
}, 800)
|
|
1214
|
+
timers.current.set(key, timer)
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
const onEdit = (key: string, text: string): void => {
|
|
1218
|
+
props.edit(key, text)
|
|
1219
|
+
const row = ROWS.find((item) => item.key === key)
|
|
1220
|
+
const debounced = row !== undefined && (row.kind === 'text' || row.kind === 'number')
|
|
1221
|
+
scheduleSave(key, text, !debounced)
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
const flushField = (key: string, text?: string): void => {
|
|
1225
|
+
const pending = timers.current.get(key)
|
|
1226
|
+
if (pending !== undefined) {
|
|
1227
|
+
clearTimeout(pending)
|
|
1228
|
+
timers.current.delete(key)
|
|
1229
|
+
}
|
|
1230
|
+
void runSave(key, text ?? viewOf(props.state, key).text)
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
useEffect(() => () => {
|
|
1234
|
+
for (const timer of timers.current.values()) clearTimeout(timer)
|
|
1235
|
+
timers.current.clear()
|
|
1236
|
+
if (savedTimer.current !== undefined) clearTimeout(savedTimer.current)
|
|
1237
|
+
}, [])
|
|
1238
|
+
|
|
1239
|
+
const statusText = props.state.writable === false
|
|
1240
|
+
? props.copy.labels.readOnly
|
|
1241
|
+
: saveState === 'saving'
|
|
1242
|
+
? props.copy.labels.saving
|
|
1243
|
+
: saveState === 'saved'
|
|
1244
|
+
? props.copy.labels.saved
|
|
1245
|
+
: saveState === 'failed'
|
|
1246
|
+
? props.copy.labels.saveFailedShort
|
|
1247
|
+
: ''
|
|
1248
|
+
|
|
1097
1249
|
return (
|
|
1098
|
-
<
|
|
1250
|
+
<div className="dsh-pe-form">
|
|
1099
1251
|
{ROWS.map((row, index) => {
|
|
1100
1252
|
const raw = viewOf(props.state, row.key)
|
|
1101
1253
|
// Hide the override badge once the value is back at its default; the
|
|
@@ -1111,13 +1263,29 @@ function SettingsRows(props: {
|
|
|
1111
1263
|
reasoningPair={{ provider, model }}
|
|
1112
1264
|
routing={routing}
|
|
1113
1265
|
providerValue={provider}
|
|
1114
|
-
onEdit={(text: string) =>
|
|
1266
|
+
onEdit={(text: string) => onEdit(row.key, text)}
|
|
1115
1267
|
onReset={() => props.resetField(row.key)}
|
|
1268
|
+
onCommit={() => flushField(row.key, viewOf(props.state, row.key).text)}
|
|
1116
1269
|
/>
|
|
1117
1270
|
</div>
|
|
1118
1271
|
)
|
|
1119
1272
|
})}
|
|
1120
|
-
|
|
1273
|
+
<div className="dsh-pe-form-footer">
|
|
1274
|
+
<div className="dsh-pe-save-group">
|
|
1275
|
+
{statusText === ''
|
|
1276
|
+
? null
|
|
1277
|
+
: <span className="dsh-pe-save-status" role="status" aria-live="polite">{statusText}</span>}
|
|
1278
|
+
<button
|
|
1279
|
+
type="button"
|
|
1280
|
+
className="dsh-pe-save-button"
|
|
1281
|
+
disabled={props.save === undefined || props.state.writable === false}
|
|
1282
|
+
onClick={() => { void manualSave() }}
|
|
1283
|
+
>
|
|
1284
|
+
{props.copy.labels.save}
|
|
1285
|
+
</button>
|
|
1286
|
+
</div>
|
|
1287
|
+
</div>
|
|
1288
|
+
</div>
|
|
1121
1289
|
)
|
|
1122
1290
|
}
|
|
1123
1291
|
|
|
@@ -1153,6 +1321,7 @@ export function SettingsSection(props: SectionProps): unknown {
|
|
|
1153
1321
|
resetField={resetField}
|
|
1154
1322
|
save={props.save}
|
|
1155
1323
|
discard={props.discard}
|
|
1324
|
+
writeField={props.writeField}
|
|
1156
1325
|
/>
|
|
1157
1326
|
</div>
|
|
1158
1327
|
)
|
|
@@ -1185,6 +1354,7 @@ export function SettingsPage(props: PageProps): unknown {
|
|
|
1185
1354
|
resetField={resetField}
|
|
1186
1355
|
save={props.save}
|
|
1187
1356
|
discard={props.discard}
|
|
1357
|
+
writeField={props.writeField}
|
|
1188
1358
|
/>
|
|
1189
1359
|
)
|
|
1190
1360
|
}
|
|
@@ -1193,6 +1363,8 @@ export function SettingsPage(props: PageProps): unknown {
|
|
|
1193
1363
|
interface ConfigScopeLike {
|
|
1194
1364
|
getSnapshot?: () => unknown
|
|
1195
1365
|
subscribe?: (listener: () => void) => () => void
|
|
1366
|
+
set?: (field: string, value: unknown) => Promise<boolean>
|
|
1367
|
+
unset?: (field: string) => Promise<boolean>
|
|
1196
1368
|
}
|
|
1197
1369
|
|
|
1198
1370
|
/** Structural face of the host's config-forms provider. */
|
|
@@ -1210,6 +1382,7 @@ interface SlotsFace {
|
|
|
1210
1382
|
/** Bridges one settings scope onto both pages' staged form. */
|
|
1211
1383
|
class SettingsPageController {
|
|
1212
1384
|
private readonly form: SettingsFormModel
|
|
1385
|
+
private readonly scope: ConfigScopeLike
|
|
1213
1386
|
private readonly store: unknown
|
|
1214
1387
|
private readonly getLocale: (() => LocaleFaceLike | undefined) | undefined
|
|
1215
1388
|
|
|
@@ -1219,6 +1392,7 @@ class SettingsPageController {
|
|
|
1219
1392
|
*/
|
|
1220
1393
|
constructor(scope: ConfigScopeLike, getLocale?: () => LocaleFaceLike | undefined) {
|
|
1221
1394
|
this.getLocale = getLocale
|
|
1395
|
+
this.scope = scope
|
|
1222
1396
|
this.form = createSettingsForm(scope)
|
|
1223
1397
|
this.store = this.form.bind(() => {
|
|
1224
1398
|
const out = this.form.shell()
|
|
@@ -1236,7 +1410,11 @@ class SettingsPageController {
|
|
|
1236
1410
|
/** The props the slots hand their pages. */
|
|
1237
1411
|
inject(): Record<string, unknown> {
|
|
1238
1412
|
const face = this.getLocale?.()
|
|
1239
|
-
const props: Record<string, unknown> = {
|
|
1413
|
+
const props: Record<string, unknown> = {
|
|
1414
|
+
hooks: { promptEnhance: this.store },
|
|
1415
|
+
...this.form.actions(),
|
|
1416
|
+
writeField: (key: string, text: string) => this.writeField(key, text),
|
|
1417
|
+
}
|
|
1240
1418
|
if (face !== undefined) {
|
|
1241
1419
|
// A small observable the slot turns into `usePromptEnhanceLocale`; the
|
|
1242
1420
|
// page reads the active language from it and re-renders on a switch.
|
|
@@ -1249,6 +1427,26 @@ class SettingsPageController {
|
|
|
1249
1427
|
return props
|
|
1250
1428
|
}
|
|
1251
1429
|
|
|
1430
|
+
/** Write one field through the host's per-field mutation API. */
|
|
1431
|
+
private async writeField(key: string, text: string): Promise<'saved' | 'invalid' | 'failed'> {
|
|
1432
|
+
const descriptor = FIELD_SPECS.find((item) => item.field === key)
|
|
1433
|
+
if (descriptor === undefined) return 'failed'
|
|
1434
|
+
const parsed = descriptor.parse(text)
|
|
1435
|
+
if (parsed === undefined) return 'invalid'
|
|
1436
|
+
if (this.scope.set === undefined) return 'failed'
|
|
1437
|
+
try {
|
|
1438
|
+
if (parsed.kind === 'clear') {
|
|
1439
|
+
if (this.scope.unset === undefined) return 'failed'
|
|
1440
|
+
if (!(await this.scope.unset(key))) return 'failed'
|
|
1441
|
+
} else {
|
|
1442
|
+
if (!(await this.scope.set(key, parsed.value))) return 'failed'
|
|
1443
|
+
}
|
|
1444
|
+
return 'saved'
|
|
1445
|
+
} catch {
|
|
1446
|
+
return 'failed'
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1252
1450
|
/** Release the form's subscriptions. */
|
|
1253
1451
|
dispose(): void {
|
|
1254
1452
|
try {
|
package/src/client/styles.ts
CHANGED
|
@@ -264,6 +264,53 @@ export const CSS = `
|
|
|
264
264
|
font-size: 12px;
|
|
265
265
|
}
|
|
266
266
|
.dsh-pe-undo-x:hover { opacity: 1; background: var(--dsw-alias-bg-layer-2, rgba(128, 128, 128, 0.12)); }
|
|
267
|
+
.dsh-pe-segmented-labels [role="tab"] {
|
|
268
|
+
min-width: 0;
|
|
269
|
+
overflow: hidden;
|
|
270
|
+
text-overflow: ellipsis;
|
|
271
|
+
text-align: center;
|
|
272
|
+
white-space: nowrap;
|
|
273
|
+
}
|
|
274
|
+
.dsh-pe-form-footer {
|
|
275
|
+
display: flex;
|
|
276
|
+
justify-content: flex-end;
|
|
277
|
+
margin-top: 12px;
|
|
278
|
+
padding-top: 10px;
|
|
279
|
+
border-top: 1px solid var(--dsw-alias-border-l3, rgba(128, 128, 128, 0.22));
|
|
280
|
+
}
|
|
281
|
+
.dsh-pe-save-group {
|
|
282
|
+
display: flex;
|
|
283
|
+
align-items: center;
|
|
284
|
+
justify-content: flex-end;
|
|
285
|
+
flex-wrap: wrap;
|
|
286
|
+
gap: 8px;
|
|
287
|
+
min-width: 0;
|
|
288
|
+
max-width: 100%;
|
|
289
|
+
margin-left: auto;
|
|
290
|
+
}
|
|
291
|
+
.dsh-pe-save-status {
|
|
292
|
+
min-width: 0;
|
|
293
|
+
max-width: 100%;
|
|
294
|
+
font-size: 12px;
|
|
295
|
+
color: var(--dsw-alias-label-secondary, inherit);
|
|
296
|
+
text-align: right;
|
|
297
|
+
overflow-wrap: anywhere;
|
|
298
|
+
}
|
|
299
|
+
.dsh-pe-save-button {
|
|
300
|
+
flex: none;
|
|
301
|
+
margin-left: 0;
|
|
302
|
+
height: 28px;
|
|
303
|
+
padding: 0 14px;
|
|
304
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.32));
|
|
305
|
+
border-radius: 8px;
|
|
306
|
+
background: var(--dsw-alias-bg-layer-1, transparent);
|
|
307
|
+
color: inherit;
|
|
308
|
+
font: inherit;
|
|
309
|
+
font-size: 12px;
|
|
310
|
+
cursor: pointer;
|
|
311
|
+
}
|
|
312
|
+
.dsh-pe-save-button:hover:not(:disabled) { background: rgba(127, 127, 127, 0.12); }
|
|
313
|
+
.dsh-pe-save-button:disabled { opacity: 0.5; cursor: default; }
|
|
267
314
|
`
|
|
268
315
|
|
|
269
316
|
/**
|