dsh-image-gen 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.zh-CN.md CHANGED
@@ -1,172 +1,172 @@
1
- <div align="center">
2
-
3
- <img src="docs/assets/hero-poster.webp" alt="dsh-image-gen 宣传海报" width="100%" style="max-width: 860px; border-radius: 12px;" />
4
-
5
- <br /><br />
6
-
7
- # 🎨 dsh-image-gen
8
-
9
- **为 DeepSeek Harness 提供完整的对话图像能力:文生图、图生图、多图参考、连续编辑、本地 ComfyUI 与画廊管理。**
10
-
11
- [![npm version](https://img.shields.io/npm/v/dsh-image-gen.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/dsh-image-gen)
12
- [![DSH Plugin](https://img.shields.io/badge/Plugin%20For-DeepSeek%20Harness-6366f1?style=flat-square)](https://github.com/deepseek-ai)
13
- [![npm downloads](https://img.shields.io/npm/dm/dsh-image-gen.svg?style=flat-square&color=emerald)](https://www.npmjs.com/package/dsh-image-gen)
14
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
15
-
16
- [English](README.en.md) | **简体中文**
17
-
18
- <br />
19
-
20
- <p align="center">💬 <b>直接对你的 DeepSeek Harness Agent 发送以下提示词:</b></p>
21
-
22
- ```text
23
- 帮我安装生图插件,执行命令:pnpm dsh plugin --profile web add dsh-image-gen@latest
24
- ```
25
-
26
- <p align="center"><sub>(也可以手动在终端执行:<code>pnpm dsh plugin --profile web add dsh-image-gen@latest</code>)</sub></p>
27
-
28
- <br />
29
-
30
- <p align="center">安装完成后,在 DSH 设置中填入自己的 API Key 或配置本地 ComfyUI,就可以直接对 Agent 说:</p>
31
-
32
- ```text
33
- 帮我画一张雨夜霓虹街头的赛博朋克猫咪。
34
- ```
35
-
36
- <p align="center">Agent 会自动调用 <code>generate_image</code>,生成图片并直接显示在当前对话中。</p>
37
-
38
- <br />
39
-
40
- <img src="docs/assets/chat-preview.png" alt="对话生图效果预览" width="820" />
41
-
42
- </div>
43
-
44
- ---
45
-
46
- ## 💡 它解决什么问题?
47
-
48
- **`dsh-image-gen` 是专为 DeepSeek Harness (DSH) 打造的开源图像生成插件。**
49
-
50
- DeepSeek Harness 已经可以让 Agent 调用不同工具完成任务,本项目为它补上了原生的**多模态生图能力**:
51
-
52
- ```mermaid
53
- graph LR
54
- A[用户 Prompt] --> B[DeepSeek Harness Agent]
55
- B --> C[generate_image 工具]
56
- C --> D[Gemini / OpenAI / Seedream / DashScope / ComfyUI]
57
- D --> E[图片数据]
58
- E --> F[当前 Conversation 对话流]
59
- ```
60
-
61
- ---
62
-
63
- ## 🚀 快速安装与使用
64
-
65
- ### 1. 安装插件
66
-
67
- 在你的 DeepSeek Harness 项目根目录下运行:
68
-
69
- ```bash
70
- # 推荐方式:安装或升级到最新版本
71
- pnpm dsh plugin --profile web add dsh-image-gen@latest
72
-
73
- # 若已将 dsh 安装为系统全局命令:
74
- dsh plugin --profile web add dsh-image-gen@latest
75
- ```
76
-
77
- <details>
78
- <summary><b>🛠️ 其他安装方式(Git 仓库直装 / 本地调试)</b></summary>
79
-
80
- ```bash
81
- # 方式 B:从 GitHub 仓库直接安装最新代码
82
- pnpm dsh plugin --profile web add git+https://github.com/shanliuling/dsh-image-gen.git
83
-
84
- # 方式 C:本地克隆源码开发安装
85
- git clone https://github.com/shanliuling/dsh-image-gen.git
86
- pnpm dsh plugin --profile web add ./dsh-image-gen
87
- ```
88
-
89
- </details>
90
-
91
- ### 2. 配置 Provider 与工作区设置
92
-
93
- 打开 DSH Web 页面(默认 `http://localhost:3080`):
94
-
95
- 1. 进入 **Settings → Plugins → Image generation**。
96
- 2. 选择 Provider;云端 Provider 填写 API Key,本地 ComfyUI 填写地址并导入 API Format Workflow JSON(提示词位置使用 `{{prompt}}`,种子可选用 `{{seed}}`)。
97
- 3. 可按需开启 **保存到工作区**(默认开启)并自定义子目录,点击 **保存** 即可。
98
-
99
- <div align="center">
100
- <img src="docs/assets/settings-preview.png?v=0.1.7" alt="设置面板预览" width="720" />
101
- </div>
102
-
103
- ### 3. 开始对话生图
104
-
105
- 现在直接在聊天框输入:
106
-
107
- ```text
108
- 生成一张极简主义的现代建筑客厅插画。
109
- ```
110
-
111
- 当前 Agent 就会自动调用 `generate_image` 工具并在对话流中返回图片。
112
-
113
- ### 4. 查看原生生图画廊
114
-
115
- 点击会话顶栏的 **`[画廊]`** Tab,即可集中查看和搜索所有对话生成的历史图片:
116
-
117
- <div align="center">
118
- <img src="docs/assets/gallery-preview.png" alt="原生生图画廊预览" width="820" />
119
- </div>
120
-
121
- ---
122
-
123
- ## ✨ 主要能力
124
-
125
- - 💬 **对话中直接生图**:不需要切换到其他网站,也不需要手动复制 Prompt,直接告诉 Agent 你想画什么即可。
126
- - 🖼️ **历史生图画廊**:顶栏自带「画廊」Tab,自动汇总所有历史生成的图片,支持关键词搜索、厂商筛选、单张删除(带防误触确认与持久化墓碑)与一键复制/下载。
127
- - 🔍 **交互式图片工具**:支持点击全屏大图预览、一键复制图片到剪贴板、本地下载与新标签页打开。
128
- - 🎨 **多 Provider 支持**:支持 Google Gemini、OpenAI Images、OpenAI Compatible API、ByteDance Seedream / 火山方舟、阿里云 DashScope(通义万相 / Qwen-Image)以及用户本地的 ComfyUI 工作流。
129
- - 🔑 **BYOK (自带 Key)**:插件使用你自己的 API Key。API Key 通过 DeepSeek Harness 的 `credentials` 服务管理,采用写保护隔离,不需要写进项目源码或配置文件,前端不存明文。
130
- - 🖼️ **图片跟随会话保存**:生成结果会接入 DeepSeek Harness 的 Attachment / Conversation 体系,重新打开历史会话后,仍然可以看到之前生成的图片。
131
- - 💾 **生成图片自动落盘到工作区**:默认在每次生成后把图片文件保存到当前会话工作区,工具结果会返回文件的绝对路径;可在设置中关闭或修改保存目录。
132
- - ⚙️ **原生设置界面**:Provider、API Key、模型和 Endpoint 都可以直接在 DSH Web 设置中修改,不需要手动编辑配置文件。
133
-
134
- ---
135
-
136
- ## 📦 支持的 Provider
137
-
138
- | Provider | 默认模型 | 默认 Endpoint / Base URL |
139
- | :--- | :--- | :--- |
140
- | **Google Gemini** | `gemini-3.1-flash-image` | `https://generativelanguage.googleapis.com/v1beta/interactions` |
141
- | **OpenAI Images** | `gpt-image-2` | `https://api.openai.com/v1` |
142
- | **OpenAI Compatible** | 自定义 | 自定义 Base URL |
143
- | **ByteDance Seedream / 火山方舟** | `doubao-seedream-5-0-260128` | `https://ark.cn-beijing.volces.com/api/v3` |
144
- | **Aliyun DashScope / 通义万相** | `wanx2.1-t2i-turbo` | `https://dashscope.aliyuncs.com/api/v1` |
145
- | **Local ComfyUI(仅文生图)** | 用户导入的 API Format Workflow | `http://127.0.0.1:8188` |
146
-
147
- ---
148
-
149
- ## 🛠️ 本地开发 (Development)
150
-
151
- ```bash
152
- # 克隆仓库
153
- git clone https://github.com/shanliuling/dsh-image-gen.git
154
- cd dsh-image-gen
155
-
156
- # 安装依赖与构建
157
- pnpm install
158
- pnpm run typecheck
159
- pnpm run test
160
- pnpm run build
161
-
162
- # 检查 npm 打包内容
163
- pnpm run pack:check
164
- ```
165
-
166
- ---
167
-
168
- ## 📄 开源协议 (License)
169
-
170
- 本项目基于 [MIT License](LICENSE) 开源。
171
-
172
- 如果这个插件对你有用,欢迎点一个 ⭐️ **Star** 支持!
1
+ <div align="center">
2
+
3
+ <img src="docs/assets/hero-poster.webp" alt="dsh-image-gen 宣传海报" width="100%" style="max-width: 860px; border-radius: 12px;" />
4
+
5
+ <br /><br />
6
+
7
+ # 🎨 dsh-image-gen
8
+
9
+ **为 DeepSeek Harness 提供完整的对话图像能力:文生图、图生图、多图参考、连续编辑、本地 ComfyUI 与画廊管理。**
10
+
11
+ [![npm version](https://img.shields.io/npm/v/dsh-image-gen.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/dsh-image-gen)
12
+ [![DSH Plugin](https://img.shields.io/badge/Plugin%20For-DeepSeek%20Harness-6366f1?style=flat-square)](https://github.com/deepseek-ai)
13
+ [![npm downloads](https://img.shields.io/npm/dm/dsh-image-gen.svg?style=flat-square&color=emerald)](https://www.npmjs.com/package/dsh-image-gen)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
15
+
16
+ [English](README.en.md) | **简体中文**
17
+
18
+ <br />
19
+
20
+ <p align="center">💬 <b>直接对你的 DeepSeek Harness Agent 发送以下提示词:</b></p>
21
+
22
+ ```text
23
+ 帮我安装生图插件,执行命令:pnpm dsh plugin --profile web add dsh-image-gen@latest
24
+ ```
25
+
26
+ <p align="center"><sub>(也可以手动在终端执行:<code>pnpm dsh plugin --profile web add dsh-image-gen@latest</code>)</sub></p>
27
+
28
+ <br />
29
+
30
+ <p align="center">安装完成后,在 DSH 设置中填入自己的 API Key 或配置本地 ComfyUI,就可以直接对 Agent 说:</p>
31
+
32
+ ```text
33
+ 帮我画一张雨夜霓虹街头的赛博朋克猫咪。
34
+ ```
35
+
36
+ <p align="center">Agent 会自动调用 <code>generate_image</code>,生成图片并直接显示在当前对话中。</p>
37
+
38
+ <br />
39
+
40
+ <img src="docs/assets/chat-preview.png" alt="对话生图效果预览" width="820" />
41
+
42
+ </div>
43
+
44
+ ---
45
+
46
+ ## 💡 它解决什么问题?
47
+
48
+ **`dsh-image-gen` 是专为 DeepSeek Harness (DSH) 打造的开源图像生成插件。**
49
+
50
+ DeepSeek Harness 已经可以让 Agent 调用不同工具完成任务,本项目为它补上了原生的**多模态生图能力**:
51
+
52
+ ```mermaid
53
+ graph LR
54
+ A[用户 Prompt] --> B[DeepSeek Harness Agent]
55
+ B --> C[generate_image 工具]
56
+ C --> D[Gemini / OpenAI / Seedream / DashScope / ComfyUI]
57
+ D --> E[图片数据]
58
+ E --> F[当前 Conversation 对话流]
59
+ ```
60
+
61
+ ---
62
+
63
+ ## 🚀 快速安装与使用
64
+
65
+ ### 1. 安装插件
66
+
67
+ 在你的 DeepSeek Harness 项目根目录下运行:
68
+
69
+ ```bash
70
+ # 推荐方式:安装或升级到最新版本
71
+ pnpm dsh plugin --profile web add dsh-image-gen@latest
72
+
73
+ # 若已将 dsh 安装为系统全局命令:
74
+ dsh plugin --profile web add dsh-image-gen@latest
75
+ ```
76
+
77
+ <details>
78
+ <summary><b>🛠️ 其他安装方式(Git 仓库直装 / 本地调试)</b></summary>
79
+
80
+ ```bash
81
+ # 方式 B:从 GitHub 仓库直接安装最新代码
82
+ pnpm dsh plugin --profile web add git+https://github.com/shanliuling/dsh-image-gen.git
83
+
84
+ # 方式 C:本地克隆源码开发安装
85
+ git clone https://github.com/shanliuling/dsh-image-gen.git
86
+ pnpm dsh plugin --profile web add ./dsh-image-gen
87
+ ```
88
+
89
+ </details>
90
+
91
+ ### 2. 配置 Provider 与工作区设置
92
+
93
+ 打开 DSH Web 页面(默认 `http://localhost:3080`):
94
+
95
+ 1. 进入 **Settings → Plugins → Image generation**。
96
+ 2. 选择 Provider;云端 Provider 填写 API Key,本地 ComfyUI 填写地址并导入 API Format Workflow JSON(提示词位置使用 `{{prompt}}`,种子可选用 `{{seed}}`)。
97
+ 3. 可按需开启 **保存到工作区**(默认开启)并自定义子目录,点击 **保存** 即可。
98
+
99
+ <div align="center">
100
+ <img src="docs/assets/settings-preview.png?v=0.1.7" alt="设置面板预览" width="720" />
101
+ </div>
102
+
103
+ ### 3. 开始对话生图
104
+
105
+ 现在直接在聊天框输入:
106
+
107
+ ```text
108
+ 生成一张极简主义的现代建筑客厅插画。
109
+ ```
110
+
111
+ 当前 Agent 就会自动调用 `generate_image` 工具并在对话流中返回图片。
112
+
113
+ ### 4. 查看原生生图画廊
114
+
115
+ 点击会话顶栏的 **`[画廊]`** Tab,即可集中查看和搜索所有对话生成的历史图片:
116
+
117
+ <div align="center">
118
+ <img src="docs/assets/gallery-preview.png" alt="原生生图画廊预览" width="820" />
119
+ </div>
120
+
121
+ ---
122
+
123
+ ## ✨ 主要能力
124
+
125
+ - 💬 **对话中直接生图**:不需要切换到其他网站,也不需要手动复制 Prompt,直接告诉 Agent 你想画什么即可。
126
+ - 🖼️ **历史生图画廊**:顶栏自带「画廊」Tab,自动汇总所有历史生成的图片,支持关键词搜索、厂商筛选、单张删除(带防误触确认与持久化墓碑)与一键复制/下载。
127
+ - 🔍 **交互式图片工具**:支持点击全屏大图预览、一键复制图片到剪贴板、本地下载与新标签页打开。
128
+ - 🎨 **多 Provider 支持**:支持 Google Gemini、OpenAI Images、OpenAI Compatible API、ByteDance Seedream / 火山方舟、阿里云 DashScope(通义万相 / Qwen-Image)以及用户本地的 ComfyUI 工作流。
129
+ - 🔑 **BYOK (自带 Key)**:插件使用你自己的 API Key。API Key 通过 DeepSeek Harness 的 `credentials` 服务管理,采用写保护隔离,不需要写进项目源码或配置文件,前端不存明文。
130
+ - 🖼️ **图片跟随会话保存**:生成结果会接入 DeepSeek Harness 的 Attachment / Conversation 体系,重新打开历史会话后,仍然可以看到之前生成的图片。
131
+ - 💾 **生成图片自动落盘到工作区**:默认在每次生成后把图片文件保存到当前会话工作区,工具结果会返回文件的绝对路径;可在设置中关闭或修改保存目录。
132
+ - ⚙️ **原生设置界面**:Provider、API Key、模型和 Endpoint 都可以直接在 DSH Web 设置中修改,不需要手动编辑配置文件。
133
+
134
+ ---
135
+
136
+ ## 📦 支持的 Provider
137
+
138
+ | Provider | 默认模型 | 默认 Endpoint / Base URL |
139
+ | :--- | :--- | :--- |
140
+ | **Google Gemini** | `gemini-3.1-flash-image` | `https://generativelanguage.googleapis.com/v1beta/interactions` |
141
+ | **OpenAI Images** | `gpt-image-2` | `https://api.openai.com/v1` |
142
+ | **OpenAI Compatible** | 自定义 | 自定义 Base URL |
143
+ | **ByteDance Seedream / 火山方舟** | `doubao-seedream-5-0-260128` | `https://ark.cn-beijing.volces.com/api/v3` |
144
+ | **Aliyun DashScope / 通义万相** | `wanx2.1-t2i-turbo` | `https://dashscope.aliyuncs.com/api/v1` |
145
+ | **Local ComfyUI(仅文生图)** | 用户导入的 API Format Workflow | `http://127.0.0.1:8188` |
146
+
147
+ ---
148
+
149
+ ## 🛠️ 本地开发 (Development)
150
+
151
+ ```bash
152
+ # 克隆仓库
153
+ git clone https://github.com/shanliuling/dsh-image-gen.git
154
+ cd dsh-image-gen
155
+
156
+ # 安装依赖与构建
157
+ pnpm install
158
+ pnpm run typecheck
159
+ pnpm run test
160
+ pnpm run build
161
+
162
+ # 检查 npm 打包内容
163
+ pnpm run pack:check
164
+ ```
165
+
166
+ ---
167
+
168
+ ## 📄 开源协议 (License)
169
+
170
+ 本项目基于 [MIT License](LICENSE) 开源。
171
+
172
+ 如果这个插件对你有用,欢迎点一个 ⭐️ **Star** 支持!
package/lib/client.js CHANGED
@@ -928,8 +928,20 @@ window.__ModuleLoader__.load({
928
928
  }
929
929
  }
930
930
  //#endregion
931
+ //#region lib/types/client/image-ref.js
932
+ /**
933
+ * Extract the verified durable image attachment from a completed tool result block.
934
+ * Supports legacy rc.2 `resultView.content` and modern DSH `block.content`.
935
+ */
936
+ function imageRef(block) {
937
+ if (!("kind" in block)) return void 0;
938
+ const fromResultView = block.resultView?.card === "generic" ? block.resultView.content?.find((item) => item.type === "image") : void 0;
939
+ if (fromResultView?.type === "image") return fromResultView.attachment;
940
+ const fromBlockContent = Array.isArray(block.content) ? block.content.find((item) => item.type === "image") : void 0;
941
+ if (fromBlockContent?.type === "image") return fromBlockContent.attachment;
942
+ }
943
+ //#endregion
931
944
  //#region lib/types/client/index.js
932
- /** Web settings and generated-image cards contributed by the Bundle. */
933
945
  const KEY_REF = {
934
946
  google: "GEMINI_API_KEY",
935
947
  openai: "OPENAI_API_KEY",
@@ -1145,8 +1157,8 @@ window.__ModuleLoader__.load({
1145
1157
  /** Required browser services. */
1146
1158
  const inject = [
1147
1159
  "slots",
1160
+ "connection",
1148
1161
  "remote",
1149
- "remote.credentials",
1150
1162
  "settingsScope",
1151
1163
  "locale"
1152
1164
  ];
@@ -1154,7 +1166,6 @@ window.__ModuleLoader__.load({
1154
1166
  function apply(ctx) {
1155
1167
  const scope = ctx.settingsScope.bind({ namespace: IMAGE_GENERATION_NAMESPACE });
1156
1168
  const locale = ctx.get("locale");
1157
- const credentials = ctx.remote.credentials;
1158
1169
  ctx.effect(() => {
1159
1170
  const style = document.createElement("style");
1160
1171
  style.dataset.plugin = "dsh-image-gen";
@@ -1165,15 +1176,27 @@ window.__ModuleLoader__.load({
1165
1176
  };
1166
1177
  }, "dsh-image-gen: styles");
1167
1178
  const register = ctx.slots.register.bind(ctx.slots);
1168
- ctx.slots.inject("settings.plugin.item", () => register({
1169
- name: "settings.plugin.item",
1170
- key: IMAGE_GENERATION_NAMESPACE,
1171
- inject: () => ({
1172
- scope,
1173
- credentials,
1174
- locale
1175
- })
1176
- }, ImageGenerationSettingsCard));
1179
+ const injectSettingsItem = (owner, credentials) => {
1180
+ const ownerRegister = owner.slots.register.bind(owner.slots);
1181
+ owner.slots.inject("settings.plugin.item", () => ownerRegister({
1182
+ name: "settings.plugin.item",
1183
+ key: IMAGE_GENERATION_NAMESPACE,
1184
+ inject: () => ({
1185
+ scope,
1186
+ credentials,
1187
+ locale
1188
+ })
1189
+ }, ImageGenerationSettingsCard));
1190
+ };
1191
+ const remoteCredentials = asCredentialsRemote(ctx.get("remote.credentials"));
1192
+ const legacyCredentials = credentialsFromLegacyConnection(ctx.get("connection"));
1193
+ if (remoteCredentials !== void 0) injectSettingsItem(ctx, remoteCredentials);
1194
+ else if (legacyCredentials !== void 0) injectSettingsItem(ctx, legacyCredentials);
1195
+ else ctx.inject(["remote.credentials"], (remoteCtx) => {
1196
+ const credentials = asCredentialsRemote(remoteCtx.get("remote.credentials"));
1197
+ if (credentials === void 0) throw new Error("dsh-image-gen: remote.credentials has an incompatible interface");
1198
+ injectSettingsItem(remoteCtx, credentials);
1199
+ });
1177
1200
  ctx.slots.inject("tool.call.toolview", () => register({
1178
1201
  name: "tool.call.toolview",
1179
1202
  key: "generate_image",
@@ -1194,6 +1217,36 @@ window.__ModuleLoader__.load({
1194
1217
  inject: () => ({ locale })
1195
1218
  }, GalleryViewTab));
1196
1219
  }
1220
+ function asCredentialsRemote(value) {
1221
+ if (value === null || typeof value !== "object") return void 0;
1222
+ const candidate = value;
1223
+ return typeof candidate.describe === "function" && typeof candidate.set === "function" ? candidate : void 0;
1224
+ }
1225
+ function credentialsFromLegacyConnection(value) {
1226
+ if (value === null || typeof value !== "object") return void 0;
1227
+ const credentials = value.api?.credentials;
1228
+ if (credentials === void 0 || typeof credentials.describe !== "function" || typeof credentials.set !== "function") return void 0;
1229
+ const legacy = credentials;
1230
+ return {
1231
+ async describe(refs) {
1232
+ const response = await legacy.describe({ refs });
1233
+ return response.result.ok ? {
1234
+ ok: true,
1235
+ value: response.result.value.credentials
1236
+ } : { ok: false };
1237
+ },
1238
+ async set(ref, credentialValue) {
1239
+ const response = await legacy.set({
1240
+ ref,
1241
+ value: credentialValue
1242
+ });
1243
+ return response.result.ok ? { ok: true } : {
1244
+ ok: false,
1245
+ error: response.result.error
1246
+ };
1247
+ }
1248
+ };
1249
+ }
1197
1250
  /** Edit provider settings and its write-only API credential. */
1198
1251
  function ImageGenerationSettingsCard(props) {
1199
1252
  const [open, setOpen] = (0, react.useState)(false);
@@ -1824,11 +1877,6 @@ window.__ModuleLoader__.load({
1824
1877
  const stored = provider === "google" ? value?.googleEndpoint : provider === "openai" ? value?.openaiBaseURL : provider === "seedream" ? value?.seedreamBaseURL : provider === "dashscope" ? value?.dashscopeEndpoint : value?.comfyuiBaseURL;
1825
1878
  return typeof stored === "string" && stored.length > 0 ? stored : DEFAULT_BASE_URLS[provider];
1826
1879
  }
1827
- function imageRef(block) {
1828
- if (!("kind" in block) || block.resultView?.card !== "generic") return void 0;
1829
- const image = block.resultView.content?.find((item) => item.type === "image");
1830
- return image?.type === "image" ? image.attachment : void 0;
1831
- }
1832
1880
  /** The workspace file path a completed image call saved, when the result meta carries one. */
1833
1881
  function imageSavedTo(block) {
1834
1882
  if (!("kind" in block)) return void 0;