@y1x1n/dsh-prompt-optimizer 0.3.14 → 0.3.16

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Y1X1n
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md CHANGED
@@ -1,15 +1,38 @@
1
1
  # dsh-prompt-optimizer
2
2
 
3
- [中文](README.md) | **English**
3
+ [中文](README.md) | **English** | 🐣 [Beginner guide (中文)](README.simple.md)
4
4
 
5
5
  [![CI](https://github.com/Y1X1n/dsh-prompt-optimizer/actions/workflows/ci.yml/badge.svg)](https://github.com/Y1X1n/dsh-prompt-optimizer/actions/workflows/ci.yml)
6
6
  [![npm](https://img.shields.io/npm/v/@y1x1n/dsh-prompt-optimizer?label=npm&color=cb3837)](https://www.npmjs.com/package/@y1x1n/dsh-prompt-optimizer)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+ [![Release](https://img.shields.io/github/v/release/Y1X1n/dsh-prompt-optimizer?label=release)](https://github.com/Y1X1n/dsh-prompt-optimizer/releases/latest)
9
+ [![Stars](https://img.shields.io/github/stars/Y1X1n/dsh-prompt-optimizer?logo=github)](https://github.com/Y1X1n/dsh-prompt-optimizer/stargazers)
10
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
7
11
 
8
12
  A DeepSeek Harness plugin that adds an **Optimize** button (✨) next to the composer, one click analyzes and rewrites the prompt draft in your input box, with results **streamed section by section over SSE**. The optimization call reuses the current session's model route by default (read live on every click — switching models in the session takes effect immediately).
9
13
 
10
14
  - **Host side**: registers two routes, `POST /dsh-prompt-optimizer/optimize` (SSE streaming) and `POST /dsh-prompt-optimizer/test-model` (connectivity probe), and drives `ctx.llm` for the "analyze + rewrite" call.
11
15
  - **Client side**: injects the button into the `conversation.input.right` slot, the result panel into `conversation.input.dock` (a full-width row above the input card, same family as TodoDock — renders on the new-session screen too and never covers the input box), and a collapsible settings card into `settings.plugin.item`. UI copy follows the DSH interface language (中文 / English).
12
16
 
17
+ ## Contents
18
+
19
+ - [Features](#features)
20
+ - [Installation](#installation)
21
+ - [From a Release (recommended, no build)](#from-a-release-recommended-no-build)
22
+ - [From source (tarball)](#from-source-tarball)
23
+ - [From GitHub](#from-github)
24
+ - [Uninstall](#uninstall)
25
+ - [Compatibility](#compatibility)
26
+ - [FAQ](#faq)
27
+ - [Verification status](#verification-status)
28
+ - [How it works](#how-it-works)
29
+ - [Development](#development)
30
+ - [Security notes](#security-notes)
31
+ - [Contributors](#contributors)
32
+ - [License](#license)
33
+
34
+ > 🐣 **First time using dsh plugins?** See the [beginner guide](README.simple.md) (in Chinese): three steps to install, one click to use.
35
+
13
36
  ![The result panel: five-dimension diagnosis and the rewrite streamed live, with replace/undo/copy; the badge shows the actual route and duration](docs/screenshots/optimize-panel.png)
14
37
 
15
38
  | | |
@@ -80,7 +103,19 @@ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
80
103
 
81
104
  ## Compatibility
82
105
 
83
- - Development baseline: `@deepseek-ai/*` **0.1.0-rc.7** (matching the packages bundled with `npx @deepseek-ai/dsh@0.1.0-rc.7`); verified on the **0.1.0-rc.8** runtime (2026-08-20, Windows, real-profile install + Web routes / client bundle / session-history RPC / end-to-end LLM call), and re-verified on **0.1.1-rc.2** (2026-08-27, Windows: `--dump-config` composition layer, route registration, client bundle all healthy).
106
+ > **This version (v0.3.16) targets DeepSeek Harness**:
107
+ >
108
+ > | dsh version | Optimize route / model calls | Settings page (incl. GitHub link) | Composer button / result panel |
109
+ > |---|---|---|---|
110
+ > | **0.1.2-rc.1 / 0.1.2-alpha.5** | ✅ verified | ✅ verified | ✅ verified |
111
+ > | **0.1.1-rc.2 and below** (0.1.0-rc.7+) | ✅ verified | ✅ verified | ✅ verified |
112
+ >
113
+ > One build covers 0.1.0-rc.7 through 0.1.2; this annotation is maintained in every Release note from v0.3.15 onward, and earlier Release notes have been retroactively annotated.
114
+
115
+ - Development baseline: `@deepseek-ai/*` **0.1.0-rc.7**; verified on **0.1.0-rc.8** (2026-08-20, Windows, real-profile install + Web routes / client bundle / session-history RPC / end-to-end LLM call), re-verified on **0.1.1-rc.2** (2026-08-27), and adapted + verified on **0.1.2-rc.1 / 0.1.2-alpha.5** (2026-09-05/06, real-profile end-to-end smoke tests: composition layer, route SSE, client bundle, composer button and result panel, settings card).
116
+ - **dsh-settings API compatibility layer**: the 0.1.2 line rewrote the settings API (standalone `installSettingsSection` removed, replaced by the `installSection` method on the `ctx.settings` service instance). 0.3.16+ feature-detects at runtime: uses the new interface when present, otherwise an inline equivalent (register + watch + unload fallback); when the settings service is absent it falls back to the composition-layer config.
117
+ - **Client slot props dual form**: since 0.1.2 the composer slots are session-scoped — components read session/draft state via standard hooks (`useInput`/`useSession`), and registration uses the official two-layer shape (register inside an inject callback on the derived context, with an `inject(sessionId)` hook). Components dispatch on the props shape (hooks on 0.1.2, direct snapshots on older hosts), so both hosts share one build.
118
+ - **Client bundle registration id**: the loader id in `lib/client.js` must equal the plugin npm package name (the host's client-modules validates registration against it); the client inject list no longer names `dsh-client-runtime`, which 0.1.2 merged away.
84
119
  - Protocol contract: `/dsh-prompt-optimizer/optimize` returns 400/405/409/413 as plain JSON on pre-check failure and switches to an SSE stream on success (model errors arrive as `error` events); `/dsh-prompt-optimizer/test-model` **always returns HTTP 200** with an `ok` field in the body (a probe is application-level semantics, deliberately not mapped to transport status codes) — integrate against `ok`, not the status code.
85
120
  - The HTTP carrier service name has drifted between releases (`httpServer` in the npm 0.0.1-rc.x type packages, `webServer` in the 0.1.0-rc.x runtime): the plugin waits on both names via `ctx.inject` with no static hard dependency — if the name changes again, only this plugin's routes fail to register (with a log warning after 10s); the Harness startup is never dragged down.
86
121
  - Client and Host must be the same version (the SSE protocol is a private contract): after upgrading, restart `dsh web` and refresh the browser.
package/README.md CHANGED
@@ -1,15 +1,38 @@
1
1
  # dsh-prompt-optimizer
2
2
 
3
- **中文** | [English](README.en.md)
3
+ **中文** | [English](README.en.md) | [🐣 小白版](README.simple.md)
4
4
 
5
5
  [![CI](https://github.com/Y1X1n/dsh-prompt-optimizer/actions/workflows/ci.yml/badge.svg)](https://github.com/Y1X1n/dsh-prompt-optimizer/actions/workflows/ci.yml)
6
6
  [![npm](https://img.shields.io/npm/v/@y1x1n/dsh-prompt-optimizer?label=npm&color=cb3837)](https://www.npmjs.com/package/@y1x1n/dsh-prompt-optimizer)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+ [![Release](https://img.shields.io/github/v/release/Y1X1n/dsh-prompt-optimizer?label=release)](https://github.com/Y1X1n/dsh-prompt-optimizer/releases/latest)
9
+ [![Stars](https://img.shields.io/github/stars/Y1X1n/dsh-prompt-optimizer?logo=github)](https://github.com/Y1X1n/dsh-prompt-optimizer/stargazers)
10
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
7
11
 
8
12
  DeepSeek Harness 插件:在会话输入框(发送栏)旁提供一个「优化」按钮(✨ 图标),一键分析并优化当前输入的提示词草稿,**结果经 SSE 流式逐段上屏**。优化调用默认复用当前会话的模型路由(每次点击实时读取,会话里切换模型立即生效)。
9
13
 
10
14
  - **Host 半侧**:注册 `POST /dsh-prompt-optimizer/optimize`(SSE 流式)与 `POST /dsh-prompt-optimizer/test-model`(连通性探活)两条路由,调用 `ctx.llm` 完成「分析 + 改写」。
11
15
  - **Client 半侧**:向 `conversation.input.right` 槽位注入按钮,向 `conversation.input.dock` 注入结果面板(输入卡上方整行、与 TodoDock 同族,新会话界面也渲染,且不遮挡输入框),向 `settings.plugin.item` 注入可折叠的设置卡片(设置页自动获得配置界面,无需单独开发页面)。界面文案跟随 DSH 界面语言(中文 / English)。
12
16
 
17
+ ## 目录
18
+
19
+ - [功能](#功能)
20
+ - [安装](#安装)
21
+ - [从 Release 安装(推荐,免构建)](#从-release-安装推荐免构建)
22
+ - [本地源码安装(tarball)](#本地源码安装tarball)
23
+ - [从 GitHub 安装](#从-github-安装)
24
+ - [卸载](#卸载)
25
+ - [兼容性](#兼容性)
26
+ - [常见问题](#常见问题)
27
+ - [验证状态](#验证状态)
28
+ - [工作原理](#工作原理)
29
+ - [开发](#开发)
30
+ - [安全说明](#安全说明)
31
+ - [贡献者](#贡献者)
32
+ - [License](#license)
33
+
34
+ > 🐣 **第一次用 dsh 插件?** 直接看[小白版指南](README.simple.md):三步装好、点按钮就用,全程大白话。
35
+
13
36
  ![结果面板:五维诊断与优化稿流式上屏,可替换/撤回/复制;徽章显示实际路由与用时](docs/screenshots/optimize-panel.png)
14
37
 
15
38
  | | |
@@ -80,7 +103,19 @@ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
80
103
 
81
104
  ## 兼容性
82
105
 
83
- - 开发基线:`@deepseek-ai/*` **0.1.0-rc.7**(与 `npx @deepseek-ai/dsh@0.1.0-rc.7` 内置包一致);已在 **0.1.0-rc.8** 运行时实测通过(2026-08-20,Windows,真实 profile 安装 + Web 路由/客户端 bundle/会话历史 RPC/端到端 LLM 调用),并在 **0.1.1-rc.2** 上复测通过(2026-08-27,Windows:`--dump-config` 组合层、路由注册、client bundle 均正常)。
106
+ > **当前版本(v0.3.16)适配 DeepSeek Harness**:
107
+ >
108
+ > | dsh 版本 | 优化路由 / 模型调用 | 设置页(含 GitHub 入口) | 发送栏按钮 / 结果面板 |
109
+ > |---|---|---|---|
110
+ > | **0.1.2-rc.1 / 0.1.2-alpha.5** | ✅ 实测 | ✅ 实测 | ✅ 实测 |
111
+ > | **0.1.1-rc.2 及以下**(0.1.0-rc.7+) | ✅ 实测 | ✅ 实测 | ✅ 实测 |
112
+ >
113
+ > 同一份构建覆盖 0.1.0-rc.7 至 0.1.2 全线;此标注自 v0.3.15 起在每个 Release 说明中固定维护,更早 Release 的说明已回溯补注。
114
+
115
+ - 开发基线:`@deepseek-ai/*` **0.1.0-rc.7**;已实测通过 **0.1.0-rc.8**(2026-08-20,Windows,真实 profile 安装 + Web 路由/客户端 bundle/会话历史 RPC/端到端 LLM 调用)、复测通过 **0.1.1-rc.2**(2026-08-27)、适配并通过 **0.1.2-rc.1 与 0.1.2-alpha.5**(2026-09-05/06,真实 profile 端到端冒烟:组合层注入、路由 SSE、client bundle、发送栏按钮与结果面板、设置卡片)。
116
+ - **dsh-settings API 兼容层**:0.1.2 线重写了设置 API(独立函数 `installSettingsSection` 移除,改为 `ctx.settings` 服务的 `installSection` 方法)。0.3.16+ 运行时按能力探测自动分派:新 API 存在则走新接口,否则内联等价实现(register+watch+卸载回落),settings 服务整体缺席时回落组合层配置。
117
+ - **客户端槽位 props 双形态**:0.1.2 起 composer 槽位改为 session scope,组件经 standard hooks(`useInput`/`useSession`)读取会话与草稿状态,注册需采用「注入回调内 scope 化注册 + `inject(sessionId)` 钩子」的官方双层形态。组件按 props 形态自动分派(0.1.2 走 hooks,旧版读直传快照),两种宿主共用同一份构建。
118
+ - **client bundle 注册 id**:`lib/client.js` 的 loader id 必须等于插件 npm 包名(宿主 client-modules 按包名校验注册);client 注入列表已随 0.1.2 移除已合并的 `dsh-client-runtime`。
84
119
  - HTTP 载体服务名在发布版间漂移过(npm 0.0.1-rc.x 类型包叫 `httpServer`,0.1.0-rc.x 运行时叫 `webServer`):本插件用 `ctx.inject` 同时等待两个名字,且不做静态硬依赖——即使服务名再次变化,也只会使本插件的路由不注册(10 秒后日志告警),不会拖垮整个 Harness 启动。
85
120
  - **客户端协议口径**:`/dsh-prompt-optimizer/optimize` 预校验失败返回 400/405/409/413(普通 JSON),成功后进入 SSE 流,模型错误经 `error` 事件传达;`/dsh-prompt-optimizer/test-model` **无论成败一律 HTTP 200**,由 body 的 `ok` 字段区分(探活是应用层语义,刻意不走传输层状态码)——对接方请以 `ok` 为准。
86
121
  - 客户端与 Host 需同版本(SSE 协议是私有约定):升级插件后请重启 `dsh web` 并刷新浏览器页面。
@@ -0,0 +1,136 @@
1
+ # 🐣 小白版:三分钟用上「提示词优化」
2
+
3
+ [← 返回完整中文文档](README.md) | [English](README.en.md)
4
+
5
+ > 这页是写给第一次接触 dsh 插件的朋友的,全程大白话,不讲技术细节。
6
+ > 想看完整功能说明、兼容性、测试覆盖?请回[完整版 README](README.md)。
7
+
8
+ ## 目录
9
+
10
+ - [这是个啥?](#这是个啥)
11
+ - [开始前,你要有这三样东西](#开始前你要有这三样东西)
12
+ - [三步装好](#三步装好)
13
+ - [怎么用](#怎么用)
14
+ - [常见小问题](#常见小问题)
15
+ - [卸载](#卸载)
16
+
17
+ ---
18
+
19
+ ## 这是个啥?
20
+
21
+ 一句话:**帮你把发给 AI 的话写得更好。**
22
+
23
+ 你在 DeepSeek 对话框里打了一句"帮我写周报",总觉得太笼统、AI 回答不给力?
24
+ 装了这个插件,输入框旁边会多一个 ✨「优化」按钮。点一下,它自动把你的话改写成一份表达清晰、要求明确的提示词,像打字机一样一段段显示出来,满意就一键替换。
25
+
26
+ **它长这样:**
27
+
28
+ | 输入框旁的按钮 | 点完之后的效果 |
29
+ |---|---|
30
+ | ![发送栏空闲态](docs/screenshots/composer-idle.png) | ![结果面板](docs/screenshots/optimize-panel.png) |
31
+
32
+ ---
33
+
34
+ ## 开始前,你要有这三样东西
35
+
36
+ 1. **一台装了 Node.js 的电脑**(Node 18 或更新版本)
37
+ 2. **dsh 命令行** —— 就是能在终端跑 `npx @deepseek-ai/dsh web` 的环境
38
+ 3. **配好的模型** —— 在 dsh 网页版的 设置 → 模型 里,已经配好至少一个模型提供方(比如 DeepSeek 官方 API)
39
+
40
+ > 三样里缺哪样?先把 [dsh 本体](https://github.com/deepseek-ai)跑起来 —— 本插件是装在它上面的「小挂件」,本体没有它也无处安放。
41
+
42
+ ---
43
+
44
+ ## 三步装好
45
+
46
+ ### 第 1 步:下载插件包
47
+
48
+ 打开 [Releases 页面](https://github.com/Y1X1n/dsh-prompt-optimizer/releases/latest),下载 `y1x1n-dsh-prompt-optimizer.tgz`。
49
+
50
+ > Windows 用浏览器下载即可;习惯命令行的话:
51
+ >
52
+ > ```sh
53
+ > curl -LO https://github.com/Y1X1n/dsh-prompt-optimizer/releases/latest/download/y1x1n-dsh-prompt-optimizer.tgz
54
+ > ```
55
+
56
+ ### 第 2 步:安装
57
+
58
+ 打开终端,进到下载文件所在的目录,运行:
59
+
60
+ ```sh
61
+ dsh plugin --profile web add ./y1x1n-dsh-prompt-optimizer.tgz
62
+ ```
63
+
64
+ ### 第 3 步:重启
65
+
66
+ 关掉 `dsh web` 重新启动,打开网页版界面。
67
+
68
+ **装好了!** 输入框旁边是不是多了一个 ✨ 按钮?
69
+
70
+ > 也可以直接从 npm 装:`dsh plugin --profile web add @y1x1n/dsh-prompt-optimizer`(装完同样要重启)。
71
+
72
+ ---
73
+
74
+ ## 怎么用
75
+
76
+ 就三下:
77
+
78
+ 1. **打字**:在输入框里随便写一句话,比如"帮我写周报"
79
+ 2. **点按钮**:点 ✨「优化」
80
+ 3. **选结果**:等几秒,面板会出现两段内容 ——「分析诊断」和「优化结果」
81
+ - 觉得好 → 点 **「替换输入框」**,你的草稿就变成优化后的版本了
82
+ - 不满意 → 点 **「重新优化」**,再生成一版
83
+ - 点错了?→ 点 **「撤回」**,一键回到替换前
84
+
85
+ ### 几个实用小开关(可选)
86
+
87
+ 在 设置 → 插件配置 → 「提示词优化」里:
88
+
89
+ - **嫌等待久?** 把「优化模式」切到 **快速**,等待时间约减半
90
+ - **想固定用某个模型优化?** 「优化用模型」里选一个,不选就跟随当前会话
91
+ - **优化出来的结果想换英文?** 「输出语言」里切
92
+
93
+ ---
94
+
95
+ ## 常见小问题
96
+
97
+ <details>
98
+ <summary><b>点了 ✨ 没反应?</b></summary>
99
+
100
+ 多半是模型没配好。去 **设置 → 模型** 配好至少一个提供方,再试。
101
+ 还不行就按 F12 打开浏览器控制台,找 `[dsh-prompt-optimizer]` 开头的红色日志,拿去[提 issue](https://github.com/Y1X1n/dsh-prompt-optimizer/issues)。
102
+ </details>
103
+
104
+ <details>
105
+ <summary><b>装完找不到 ✨ 按钮?</b></summary>
106
+
107
+ 重启 `dsh web` 了吗?插件装完**必须重启**才生效,光刷新网页不够。
108
+ </details>
109
+
110
+ <details>
111
+ <summary><b>升级插件后要做什么?</b></summary>
112
+
113
+ 重启 `dsh web`,然后刷新浏览器页面(建议 Ctrl+F5 强刷)。
114
+ </details>
115
+
116
+ <details>
117
+ <summary><b>结果跑到一半断了/被截断?</b></summary>
118
+
119
+ 设置卡里把「最大输出 Token」调高一点(默认 8192,最长 32768)。
120
+ </details>
121
+
122
+ 更多问题看[完整版常见问题](README.md#常见问题)。
123
+
124
+ ---
125
+
126
+ ## 卸载
127
+
128
+ ```sh
129
+ dsh plugin --profile web remove @y1x1n/dsh-prompt-optimizer
130
+ ```
131
+
132
+ 然后重启 `dsh web`。
133
+
134
+ ---
135
+
136
+ 觉得好用?给[仓库](https://github.com/Y1X1n/dsh-prompt-optimizer)点个 ⭐ 就是最大的支持。有问题欢迎[提 issue](https://github.com/Y1X1n/dsh-prompt-optimizer/issues)。
package/lib/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  window.__ModuleLoader__.load({
2
- id: "dsh-prompt-optimizer",
2
+ id: "@y1x1n/dsh-prompt-optimizer",
3
3
  factory: (require) => {
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
@@ -268,7 +268,9 @@ function createOptimizeButton(controller) {
268
268
  return function OptimizeButton(props) {
269
269
  const state = (0, import_react2.useSyncExternalStore)(controller.subscribe, controller.getSnapshot);
270
270
  const t = useT();
271
- const draft = props.input.draft;
271
+ const p = props;
272
+ const input = p.useInput ? p.useInput((s) => s) : p.input;
273
+ const draft = input?.draft ?? "";
272
274
  const empty = !draft.trim();
273
275
  const loading = state.status === "loading";
274
276
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { display: "inline-flex" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
@@ -279,7 +281,7 @@ function createOptimizeButton(controller) {
279
281
  style: { ...buttonStyle, ...empty || loading ? { opacity: 0.45, cursor: "not-allowed" } : {} },
280
282
  disabled: empty || loading,
281
283
  title: empty ? t("button.titleEmpty") : t("button.title"),
282
- onClick: () => void controller.optimize(draft, props.sessionId),
284
+ onClick: () => void controller.optimize(draft, p.sessionId),
283
285
  children: [
284
286
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SparkleIcon, { spinning: loading }),
285
287
  loading ? t("button.optimizing") : t("button.optimize")
@@ -779,7 +781,11 @@ function createResultDock(controller) {
779
781
  const [copied, setCopied] = (0, import_react3.useState)(false);
780
782
  const [analysisOpen, setAnalysisOpen] = (0, import_react3.useState)(true);
781
783
  const [undoneFlash, setUndoneFlash] = (0, import_react3.useState)(false);
782
- const owns = state.open && state.last?.sessionId === props.sessionId;
784
+ const p = props;
785
+ const input = (p.useInput ? p.useInput((s) => s) : p.input) ?? {};
786
+ const session = (p.useSession ? p.useSession((s) => s) : p.session) ?? {};
787
+ const inputActions = p.inputActions;
788
+ const owns = state.open && state.last?.sessionId === p.sessionId;
783
789
  (0, import_react3.useEffect)(() => {
784
790
  if (!owns) return;
785
791
  const onKey = (event) => {
@@ -791,9 +797,9 @@ function createResultDock(controller) {
791
797
  return () => document.removeEventListener("keydown", onKey);
792
798
  }, [owns]);
793
799
  const applied = state.applied;
794
- const draft = props.input.draft;
795
- const running = Boolean(props.session?.running);
796
- const queued = props.session?.queue?.length ?? 0;
800
+ const draft = input.draft ?? "";
801
+ const running = Boolean(session.running);
802
+ const queued = session.queue?.length ?? 0;
797
803
  const prevRef = (0, import_react3.useRef)({ running, queued });
798
804
  (0, import_react3.useEffect)(() => {
799
805
  const prev = prevRef.current;
@@ -854,12 +860,12 @@ function createResultDock(controller) {
854
860
  const onReplace = () => {
855
861
  if (!result) return;
856
862
  const nextDraft = state.last?.prefix ? `${state.last.prefix} ${result.optimized}` : result.optimized;
857
- controller.markApplied({ backup: props.input.draft, text: nextDraft });
858
- props.inputActions.setDraft(nextDraft);
863
+ controller.markApplied({ backup: input.draft ?? "", text: nextDraft });
864
+ inputActions?.setDraft(nextDraft);
859
865
  };
860
866
  const onUndo = () => {
861
867
  if (!applied) return;
862
- props.inputActions.setDraft(applied.backup);
868
+ inputActions?.setDraft(applied.backup);
863
869
  controller.clearApplied();
864
870
  setUndoneFlash(true);
865
871
  };
@@ -1467,20 +1473,32 @@ function apply(ctx) {
1467
1473
  // R21:看门狗 = 设置超时秒数 + 5s 余量(正常时 Host 的超时错误先到达,文案更友好)。
1468
1474
  getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3
1469
1475
  });
1470
- ctx.slots.inject(
1471
- "conversation.input.right",
1472
- () => ctx.slots.register(
1473
- { name: "conversation.input.right", id: "prompt-optimizer", order: 30 },
1474
- createOptimizeButton(controller)
1475
- )
1476
- );
1477
- ctx.slots.inject(
1478
- "conversation.input.dock",
1479
- () => ctx.slots.register(
1480
- { name: "conversation.input.dock", id: "prompt-optimizer", order: 30 },
1481
- createResultDock(controller)
1482
- )
1483
- );
1476
+ ctx.inject(["slots", "connection", "remote", "settingsScope"], (scopeCtx) => {
1477
+ scopeCtx.slots.inject(
1478
+ "conversation.input.right",
1479
+ () => scopeCtx.slots.register(
1480
+ {
1481
+ name: "conversation.input.right",
1482
+ id: "prompt-optimizer",
1483
+ order: 30,
1484
+ inject: () => ({})
1485
+ },
1486
+ createOptimizeButton(controller)
1487
+ )
1488
+ );
1489
+ scopeCtx.slots.inject(
1490
+ "conversation.input.dock",
1491
+ () => scopeCtx.slots.register(
1492
+ {
1493
+ name: "conversation.input.dock",
1494
+ id: "prompt-optimizer",
1495
+ order: 30,
1496
+ inject: () => ({})
1497
+ },
1498
+ createResultDock(controller)
1499
+ )
1500
+ );
1501
+ });
1484
1502
  ctx.slots.inject(
1485
1503
  "settings.plugin.item",
1486
1504
  () => ctx.slots.register(
package/lib/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // src/index.ts
2
2
  import Schema from "@deepseek-ai/schemastery";
3
- import { installSettingsSection, settingsNamespace } from "@deepseek-ai/dsh-settings";
4
3
 
5
4
  // src/prompt.ts
6
5
  var MARKERS = {
@@ -241,7 +240,7 @@ var Config = Schema.object({
241
240
  autoMaxTokens: Schema.boolean().default(true),
242
241
  includeContext: Schema.boolean().default(true)
243
242
  });
244
- var NS = settingsNamespace("prompt-optimizer");
243
+ var NS = "prompt-optimizer";
245
244
  var ROUTE_PATH = "/dsh-prompt-optimizer/optimize";
246
245
  var TEST_ROUTE_PATH = "/dsh-prompt-optimizer/test-model";
247
246
  var MAX_BODY_BYTES = 256 * 1024;
@@ -413,12 +412,29 @@ function apply(ctx, config) {
413
412
  return effort;
414
413
  };
415
414
  let current = () => config;
416
- installSettingsSection(ctx, NS, Config, config, {
417
- setSource: (source) => {
418
- current = source;
419
- },
420
- onChange: () => {
415
+ ctx.inject(["settings"], (sctx) => {
416
+ const settings = sctx.settings;
417
+ if (!settings) return;
418
+ const hooks = {
419
+ setSource: (source) => {
420
+ current = source;
421
+ },
422
+ onChange: () => {
423
+ }
424
+ };
425
+ if (typeof settings.installSection === "function") {
426
+ settings.installSection(ctx, NS, Config, config, hooks);
427
+ return;
421
428
  }
429
+ const scope = settings.register(NS, Config, { base: config });
430
+ hooks.setSource(() => scope.get());
431
+ hooks.onChange();
432
+ const disposeWatch = scope.watch(() => hooks.onChange());
433
+ ctx.effect(() => () => {
434
+ disposeWatch();
435
+ hooks.setSource(() => config);
436
+ hooks.onChange();
437
+ });
422
438
  });
423
439
  warnUnknownEnumConfig(config);
424
440
  let mounted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y1x1n/dsh-prompt-optimizer",
3
- "version": "0.3.14",
3
+ "version": "0.3.16",
4
4
  "description": "DeepSeek Harness 插件:在发送栏旁一键分析并优化提示词(复用当前会话模型)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,7 +50,6 @@
50
50
  "platform": "web",
51
51
  "inject": [
52
52
  "@deepseek-ai/dsh-client-connection",
53
- "@deepseek-ai/dsh-client-runtime",
54
53
  "@deepseek-ai/dsh-client-ui-conversation",
55
54
  "@deepseek-ai/dsh-client-ui-settings",
56
55
  "@deepseek-ai/dsh-client-ui-settings-plugins"
@@ -58,13 +57,13 @@
58
57
  }
59
58
  },
60
59
  "dependencies": {
61
- "@deepseek-ai/dsh-settings": "^0.1.0-rc.7",
60
+ "@deepseek-ai/dsh-settings": "^0.1.2-rc.1",
62
61
  "@deepseek-ai/schemastery": "^3.18.1"
63
62
  },
64
63
  "devDependencies": {
65
- "@deepseek-ai/cordis": "^4.0.1",
66
- "@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.7",
67
- "@deepseek-ai/dsh-llm": "^0.1.0-rc.7",
64
+ "@deepseek-ai/cordis": "^4.0.2",
65
+ "@deepseek-ai/dsh-host-webserver": "^0.1.2-rc.1",
66
+ "@deepseek-ai/dsh-llm": "^0.1.2-rc.1",
68
67
  "@types/node": "^20.0.0",
69
68
  "@types/react": "^18.3.1",
70
69
  "esbuild": "^0.24.0",