@qjysqjy/dsh-prompt-optimizer 0.1.0 → 0.2.0
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.md +23 -64
- package/lib/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,33 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
在 DSH Web UI 输入框的工具行里加一个**优化**控件:把当前草稿就地改写为结构化提示词,回填输入框,并且可以一键还原原文。
|
|
4
4
|
|
|
5
|
-
## 做什么,不做什么
|
|
6
|
-
|
|
7
5
|
- 改写是**纯文本操作**:不执行工具、不发消息、不产生会话轮次。
|
|
8
|
-
-
|
|
9
|
-
- 只动**草稿**。附件与 `@`
|
|
6
|
+
- 复用**当前会话自己的模型路由**,不需要额外配置 API Key 或供应商账号。
|
|
7
|
+
- 只动**草稿**。附件与 `@` 引用芯片保持原样;草稿以斜杠命令开头时控件不生效。
|
|
10
8
|
|
|
11
9
|
## 样子
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| 草稿已填、待优化 | 优化进行中(再点即取消) | 改写完成(点一下还原) |
|
|
11
|
+
| 草稿已填 | 优化进行中(再点即取消) | 改写完成(点一下还原) |
|
|
16
12
|
|---|---|---|
|
|
17
13
|
|  |  |  |
|
|
18
14
|
|
|
19
|
-
插件页里的条目(标题、描述与图标都来自包内资源,未激活时也能读到):
|
|
20
|
-
|
|
21
15
|

|
|
22
16
|
|
|
23
17
|
## 安装
|
|
24
18
|
|
|
25
|
-
先在仓库根 `pnpm install`,再:
|
|
26
|
-
|
|
27
19
|
```text
|
|
28
|
-
plugin_manager install_bundle
|
|
20
|
+
plugin_manager install_bundle @qjysqjy/dsh-prompt-optimizer
|
|
29
21
|
```
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
也可以在 **侧边栏 → 插件 → 添加插件** 里输入同一个包名。想跟最新提交就改用 `github:adonis797/dsh-qjysqjy#path:/packages/prompt-optimizer`;改代码则从本地克隆装,先在仓库根 `pnpm install`。
|
|
24
|
+
|
|
25
|
+
装好刷新页面即可,控件出现在输入框工具行、模型选择器左侧。
|
|
32
26
|
|
|
33
27
|
## 配置
|
|
34
28
|
|
|
@@ -37,10 +31,8 @@ plugin_manager install_bundle <仓库根>/packages/prompt-optimizer
|
|
|
37
31
|
```yaml
|
|
38
32
|
- id: qjysqjy-prompt-optimizer
|
|
39
33
|
config:
|
|
40
|
-
useContext:
|
|
41
|
-
|
|
42
|
-
You rewrite drafts into terse, concrete task prompts.
|
|
43
|
-
Reply in the draft's own language and return only the prompt.
|
|
34
|
+
useContext: false
|
|
35
|
+
maxOutputTokens: 2048
|
|
44
36
|
```
|
|
45
37
|
|
|
46
38
|
| 字段 | 默认 | 含义 |
|
|
@@ -49,77 +41,44 @@ plugin_manager install_bundle <仓库根>/packages/prompt-optimizer
|
|
|
49
41
|
| `userTemplate` | 内置 | 首次改写的用户提示词,占位符 `{draft}`。 |
|
|
50
42
|
| `revisionTemplate` | 内置 | 增量修订的用户提示词,占位符 `{draft}`、`{previous}`。 |
|
|
51
43
|
| `contextTemplate` | 内置 | 携带上下文时追加的段落,占位符 `{context}`。 |
|
|
52
|
-
| `useContext` | `
|
|
44
|
+
| `useContext` | `true` | 是否把会话近期消息作为背景发给模型。关掉可省 token,也让改写只依据草稿。 |
|
|
53
45
|
| `maxContextChars` | `2000` | 开启上下文时保留的字符数上限。 |
|
|
54
46
|
| `maxDraftChars` | `12000` | 接受的最大草稿长度,超过直接拒绝且不调模型。 |
|
|
55
47
|
| `maxOutputTokens` | `4096` | 单次改写的输出上限。 |
|
|
56
48
|
| `provider` / `model` | 未设 | 可选的固定路由,两者同时设置才生效,用于停止跟随会话。 |
|
|
57
49
|
|
|
58
|
-
##
|
|
59
|
-
|
|
60
|
-
```text
|
|
61
|
-
POST /__qjysqjy-prompt-optimizer/optimize
|
|
62
|
-
请求:{ text: string, sessionId: string, previousResult?: string }
|
|
63
|
-
响应:{ enhanced: string, language: string, provider: string, model: string }
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
- 空草稿、纯空白、超长、缺 `sessionId` 一律 4xx,**不调用模型**。
|
|
67
|
-
- `content-type` 必须是 JSON;带 `Origin` 时校验同源;请求体上限 96 KiB。
|
|
68
|
-
- 没有可用路由时返回 409,模型调用失败返回 502。
|
|
69
|
-
|
|
70
|
-
## 行为契约
|
|
50
|
+
## 行为
|
|
71
51
|
|
|
72
52
|
| 状态 | 触发 | 控件 | 点击后 |
|
|
73
53
|
|---|---|---|---|
|
|
74
54
|
| idle | 首次渲染、还原之后 | ✨ | 发起优化 |
|
|
75
55
|
| optimizing | ✨ 被按下 | 转圈 | **取消**——`fetch` 被 abort,Host 侧连带中断模型调用 |
|
|
76
56
|
| done | 改写已回填 | ↩️ | 还原为捕获的原文 |
|
|
77
|
-
| dirty | 回填后用户又编辑 | ↩️
|
|
57
|
+
| dirty | 回填后用户又编辑 | ↩️ 禁用,并多出一个 ✨ | 还原被拒绝;新 ✨ 基于当前编辑做增量修订 |
|
|
78
58
|
|
|
79
|
-
|
|
59
|
+
几条钉住的规则:空草稿不发请求;请求期间用户继续输入,结果**被丢弃**而不是覆盖;还原绝不覆盖改写之后用户自己写的字;语言锁定,中文进中文出、英文进英文出。
|
|
80
60
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
|
|
61
|
+
## HTTP 端点
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
POST /__qjysqjy-prompt-optimizer/optimize
|
|
65
|
+
请求:{ text: string, sessionId: string, previousResult?: string }
|
|
66
|
+
响应:{ enhanced: string, language: string, provider: string, model: string }
|
|
67
|
+
```
|
|
87
68
|
|
|
88
|
-
|
|
69
|
+
空草稿、超长、缺 `sessionId` 一律 4xx 且不调模型;请求体上限 96 KiB;无可用路由返回 409,模型失败返回 502。
|
|
70
|
+
|
|
71
|
+
## 开发
|
|
89
72
|
|
|
90
73
|
```text
|
|
91
74
|
lib/index.js Host 半:路由、路由解析、模型调用
|
|
92
75
|
lib/optimize.js 引擎:流收集、失败映射
|
|
93
76
|
lib/prompt.js 纯函数:模板、清洗、语言判定
|
|
94
77
|
lib/client.js Client 半:槽位注册、状态机、样式
|
|
95
|
-
test/ unit.test.js(纯函数与引擎)、client.test.mjs(状态机)
|
|
96
78
|
```
|
|
97
79
|
|
|
98
|
-
## 测试
|
|
99
|
-
|
|
100
80
|
```text
|
|
101
81
|
node --test test/unit.test.js test/client.test.mjs
|
|
102
82
|
```
|
|
103
83
|
|
|
104
84
|
Client 套件加载**真实的** `lib/client.js`,用最小 React 替身驱动,因此测的是发布出去的那份代码。
|
|
105
|
-
|
|
106
|
-
## 已实测(DSH 0.2.2-rc.1,Web UI)
|
|
107
|
-
|
|
108
|
-
用 CDP 驱动真实页面逐条走过:
|
|
109
|
-
|
|
110
|
-
| 场景 | 结果 |
|
|
111
|
-
|---|---|
|
|
112
|
-
| 空草稿 | 按钮 `disabled`,`title` 为“草稿为空,无需优化”,无 network 请求 |
|
|
113
|
-
| 正常改写 | 200 回填,按钮变↩️,`data-done` 置位 |
|
|
114
|
-
| 请求中取消 | `fetch` 收到 `AbortError`,`signal.aborted === true`,草稿不变,提示“已取消优化” |
|
|
115
|
-
| 请求中继续输入 | 请求照常返回 200,结果被丢弃,页面提示“草稿在优化期间被修改,结果已丢弃”,用户新写的字保留 |
|
|
116
|
-
| 改写后再编辑 | ↩️ 置 `disabled` 且 `data-stale`,强行触发点击也不覆盖;旁边出现增量优化 ✨ |
|
|
117
|
-
| 还原 | 草稿精确回到原文,按钮回 idle |
|
|
118
|
-
| 中文进 / 英文进 | `language` 分别为 `zh` / `en`,输出语言一致 |
|
|
119
|
-
|
|
120
|
-
## 已知限制
|
|
121
|
-
|
|
122
|
-
- 只在 **DSH Web UI** 形态可用(`dsh.client.platform: "web"`)。CLI/TUI 与 ACP 形态不注入任何槽位,未做任何验证。
|
|
123
|
-
- `conversation.composer` 是可被接管的 chain;若被其他插件临时接管,本控件随整条工具行一起不渲染。该形态未构造验证。
|
|
124
|
-
- 移动端窄视口未在真机验证:控件尺寸按桌面工具行设计(28×28),触摸命中区域未测。
|
|
125
|
-
- 深浅色主题只在实际使用的那套皮肤下截图确认过;控件只用 `--dsw-alias-*` 令牌,换肤应当跟随,但未逐皮肤验证。
|
package/lib/index.js
CHANGED
|
@@ -54,8 +54,8 @@ export const Config = z.object({
|
|
|
54
54
|
contextTemplate: z.string().description(
|
|
55
55
|
'Section appended when context is supplied. Supports {context}. Empty uses the built-in one.',
|
|
56
56
|
),
|
|
57
|
-
useContext: z.boolean().default(
|
|
58
|
-
'Send recent Session messages as background to the model.
|
|
57
|
+
useContext: z.boolean().default(true).description(
|
|
58
|
+
'Send recent Session messages as background to the model. On by default; turn it off to spend fewer tokens or to keep the rewrite strictly draft-local.',
|
|
59
59
|
),
|
|
60
60
|
maxContextChars: z.number().step(1).min(0).max(20000).default(MAX_CONTEXT_CHARS)
|
|
61
61
|
.description('Characters of Session context retained when context is enabled.'),
|
|
@@ -82,7 +82,7 @@ export function apply(ctx, config) {
|
|
|
82
82
|
userTemplate: config.userTemplate ?? '',
|
|
83
83
|
revisionTemplate: config.revisionTemplate ?? '',
|
|
84
84
|
contextTemplate: config.contextTemplate ?? '',
|
|
85
|
-
useContext: config.useContext
|
|
85
|
+
useContext: config.useContext !== false,
|
|
86
86
|
maxContextChars: config.maxContextChars ?? MAX_CONTEXT_CHARS,
|
|
87
87
|
maxDraftChars: config.maxDraftChars ?? MAX_DRAFT_CHARS,
|
|
88
88
|
maxOutputTokens: config.maxOutputTokens ?? 4096,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qjysqjy/dsh-prompt-optimizer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Rewrites the composer draft into a structured prompt in place, with one-click undo and true cancellation. 把输入框草稿就地改写为结构化提示词,支持一键还原与真实取消。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|