dsh-comfyui 0.3.0-beta.0 → 0.3.0-beta.2

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 ADDED
@@ -0,0 +1,205 @@
1
+ # dsh-comfyui
2
+
3
+ **English** | [中文](README.md)
4
+
5
+ <p align="center">
6
+ <img src="logo.png" width="480" alt="dsh-comfyui logo" />
7
+ </p>
8
+
9
+ <h1 align="center">dsh-comfyui</h1>
10
+
11
+ <p align="center">Let the DeepSeek Harness agent drive your ComfyUI server directly to generate and process images and videos.</p>
12
+
13
+ <p align="center">
14
+ <a href="https://www.npmjs.com/package/dsh-comfyui"><img src="https://img.shields.io/npm/v/dsh-comfyui" alt="npm version" /></a>
15
+ <a href="https://www.npmjs.com/package/dsh-comfyui"><img src="https://img.shields.io/npm/dm/dsh-comfyui" alt="npm downloads" /></a>
16
+ <img src="https://img.shields.io/npm/l/dsh-comfyui" alt="license" />
17
+ </p>
18
+
19
+ ## Features
20
+
21
+ ### Agent tools
22
+
23
+ - `comfyui_run` — submit a ComfyUI API-format workflow, or pick a built-in template, and get the generated media back. Two modes: `sync` (wait and return media) and `async` (start a background job, collect with `job_output` — ideal for video).
24
+ - `comfyui_object_info` — list the node definitions of your ComfyUI server so the agent can build valid workflows on the fly.
25
+ - `comfyui_workflow` — list and run runnable workflows from the plugin library. `action: list` also reports graph workflows you saved on the ComfyUI server and whether each has been **extracted** into runnable workflows; unextracted graphs are flagged so the agent tells you to extract them in the panel first.
26
+
27
+ ### UI panel
28
+
29
+ Right-docked; open from the sidebar rail — three tabs:
30
+
31
+ - **Workflows** — the plugin library of runnable (API) workflows: create / edit / run / delete, plus "Import file" to load an API-format `.json` directly. The **ComfyUI-saved graphs** section auto-detects graph workflows you saved in ComfyUI, shows which runnable workflows were extracted from each, and offers **extract** with per-graph analysis: a canvas often holds several independent flows, so you choose extract all / extract per component / extract main flow only. Workflows can be classified with **tags** (see below).
32
+ - **Assets** — everything the plugin generated, newest first, with a detail view and download links.
33
+ - **Queue** — a task center over ComfyUI's unified jobs API (`/api/jobs`): every task across the live queue **and** history in five states (pending / in progress / completed / failed / cancelled), filterable by state, with per-task progress bars (plugin-submitted jobs), preview thumbnails, failure messages and duration, plus actions — delete, interrupt, rerun, clear queue/history, free memory. Tasks the plugin queued are marked with their workflow name.
34
+
35
+ <p align="center"><img src="images/panel.png" width="70%" alt="Main panel: workflows / assets / queue" title="Main panel: workflows / assets / queue" /></p>
36
+
37
+ ### Load area
38
+
39
+ An image loader in the style of ComfyUI's LoadImage node, sitting at the top of the Workflows tab:
40
+
41
+ - Shows the **current source image** as a large preview; clicking opens a picker window with a nav bar (All / Imported / Generated), a type filter, a paste/upload drop zone on the right, and a masonry grid of every image in the ComfyUI `input` directory plus everything the plugin generated. Picking an image closes the window and makes it the current source.
42
+ - The current source image is the **default input image**: any workflow run that has an unset image-type parameter uses it automatically — the agent does not need to name a file.
43
+ - **Resolution auto-match**: uploads record their pixel size; when a run leaves `width`/`height` unset, they default to the source image's actual size.
44
+ - **Hash naming + dedup**: uploads are renamed to `original_shorthash.ext` (SHA-256 first 10 hex); re-uploading an identical file reuses the existing name instead of storing a duplicate. The picker refreshes live after uploads.
45
+ - Selecting a **generated** image copies it from the output directory into `input` on the fly, so image-loading nodes can use it.
46
+
47
+ <p align="center"><img src="images/loadarea.png" width="70%" alt="Load area: image picking and upload" title="Load area: image picking and upload" /></p>
48
+
49
+ ### Workflow tags
50
+
51
+ Classify runnable workflows with preset categories (image-to-image / text-to-image / text-to-video / image-to-video / reference-to-video / text-to-audio / reference-to-audio) plus any custom tags. Tags are edited in the workflow editor, shown on the top-right of each card, and the library list has a filter bar with per-tag counts.
52
+
53
+ ### Built-in templates
54
+
55
+ `txt2img` (SDXL text-to-image), `img2img` (SDXL image-to-image), `video` (Wan 2.1 text-to-video via ComfyUI-WanVideoWrapper). Template node ids are documented in the tool description so the agent overrides the right inputs.
56
+
57
+ ### Media proxy
58
+
59
+ Generated files stream through a same-origin route (`/comfyui/media`), so the browser never talks to ComfyUI directly: no CORS, no mixed-content, no API key in the page, and remote ComfyUI installs work unchanged.
60
+
61
+ ### Tool card
62
+
63
+ Results render as a media wall (images/videos with download links) right in the chat, including background-job status.
64
+
65
+ ### Settings page
66
+
67
+ A ComfyUI section in the DH settings where you can edit the server URL, API-key env var, data directory, and asset cap, test the connection, and switch the plugin UI language (Chinese / English — stored in the browser, applies to the whole plugin UI), all without touching `cordis.yml`.
68
+
69
+ <p align="center"><img src="images/settings.png" width="70%" alt="ComfyUI settings page (with UI language switch)" title="ComfyUI settings page (with UI language switch)" /></p>
70
+
71
+ ### Companion skill
72
+
73
+ A runtime skill (`dsh-comfyui-workflows`) registered through `ctx.skills.register`: the agent learns the graph-vs-runnable model, canvas analysis rules (connected components, bypassed groups, dangling nodes), when to ask you about extract mode, and the extraction tech rules.
74
+
75
+ ### Graph workflows vs runnable workflows
76
+
77
+ ComfyUI works in two layers:
78
+
79
+ - **Graph workflow** — the UI graph you save in ComfyUI (nodes/links/widgets). It is a source, not directly runnable, and a single canvas is often a **test bench holding several independent flows at once**. Visual `groups` are just rectangles — the real executable unit is a **connected component** over the links, with bypassed (`mode 4`) and dangling nodes excluded.
80
+ - **Runnable workflow** — an API-format prompt, the actual execution unit. You get one by **extracting** it from a graph (1 graph → N runnable workflows) or by pasting/importing an API `.json` directly.
81
+
82
+ The **extract** flow analyzes the canvas first (components with their node counts and group membership, bypassed/dangling counts) and lets you pick:
83
+
84
+ - **Extract all** — merge every component into one runnable workflow (everything executes together).
85
+ - **Extract per component** (recommended) — one runnable workflow per independent flow.
86
+ - **Extract main flow only** — the largest component only (usually the flow under test).
87
+
88
+ Extraction follows the live `/object_info`: rewires Reroute/bypass pass-throughs, maps widget values (including dynamic sub-widgets and `control_after_generate`), inlines primitives, drops stale slot references with a warning, skips components with no output node, and fails loudly when a required input was never wired — every extracted workflow is validated by `POST /prompt` (zero `node_errors`) before it is stored.
89
+
90
+ ### Adjustable parameters
91
+
92
+ Every runnable workflow carries an adjustable **parameter set** (`parameters`) so one workflow can produce different results per run:
93
+
94
+ - **Auto-detected (conservative)**: prompt text inputs, resolution (`EmptyLatentImage` width/height), sampler steps (`KSampler.steps`), and seed (`KSampler.seed`, randomized per run by default). Sampling-related inputs (cfg/denoise) and model selections stay as authored.
95
+ - **Advanced parameters**: the panel's workflow editor can expose any node input as a custom parameter (pick node → pick input → name it), and edit each parameter's name, label, default, and random toggle.
96
+ - **Agent-facing**: the parameter list is written into the workflow's input notes (`inputs` field) and shown by `comfyui_workflow` `action: list`; `action: run` accepts `parameters: {"prompt": "...", "seed": 42}` overrides — explicit values win over random/default, omitted parameters use their defaults.
97
+ - **Load-area integration**: an unset image-type parameter is filled with the load-area's current source image, and unset `width`/`height` are auto-matched to that image's recorded pixel size. Explicit values always win, so the agent can still override both.
98
+
99
+ ## Requirements
100
+
101
+ - DeepSeek Harness (web profile) — the plugin targets the `web` profile (`@deepseek-ai/dsh-web-app` ≥ 0.1.0-rc.6).
102
+ - A running [ComfyUI](https://github.com/comfystack/ComfyUI) server (default `http://127.0.0.1:8188`).
103
+ - For the `video` template: the [ComfyUI-WanVideoWrapper](https://github.com/kijai/ComfyUI-WanVideoWrapper) custom nodes and Wan 2.1 model files.
104
+
105
+ ## Installation
106
+
107
+ ```sh
108
+ dsh plugin --profile web add dsh-comfyui
109
+ ```
110
+
111
+ Then restart the web server (host-side rows mount at boot). The panel trigger appears in the sidebar rail, the settings section "ComfyUI" appears in the settings page, and the agent gains `comfyui_run`, `comfyui_object_info`, `comfyui_workflow`, and the `dsh-comfyui-workflows` skill immediately.
112
+
113
+ ### API key (remote servers)
114
+
115
+ For a remote ComfyUI behind an authenticating proxy, provide the key through the credentials store or an environment variable named by `apiKeyEnv` (default `COMFYUI_API_KEY`). The key is resolved per request on the host and never sent to the browser.
116
+
117
+ ## Usage
118
+
119
+ Ask the agent, e.g.:
120
+
121
+ - "Generate a red cat image with ComfyUI"
122
+ - "Turn this image into cyberpunk style" (img2img with an input image filename)
123
+ - "Turn the anime girl in the load area into a realistic photo, matching the original resolution" (load-area source image + resolution auto-match)
124
+ - "Generate a 5-second clip of a city at sunset" (video; needs the Wan wrapper)
125
+ - "Run my Krea-Afterlight workflow saved in ComfyUI" — the agent lists server-side graphs; if yours is not extracted yet it will tell you to click **extract** in the panel first (a canvas may contain several independent flows, so you can extract all as one, per component, or the main flow only).
126
+
127
+ The agent picks a template, inspects your server with `comfyui_object_info`, or runs a library workflow with `comfyui_workflow`.
128
+
129
+ ### Configuration
130
+
131
+ The plugin reads a `comfyui` section from `cordis.yml` (or the settings page):
132
+
133
+ ```yaml
134
+ # cordis.yml
135
+ - id: comfyui
136
+ name: dsh-comfyui
137
+ config:
138
+ baseUrl: http://127.0.0.1:8188
139
+ apiKeyEnv: COMFYUI_API_KEY
140
+ timeoutMs: 180000
141
+ maxMediaItems: 12
142
+ dataDir: ''
143
+ maxAssets: 200
144
+ ```
145
+
146
+ | Key | Default | Description |
147
+ | --- | --- | --- |
148
+ | `baseUrl` | `http://127.0.0.1:8188` | ComfyUI HTTP server base URL |
149
+ | `apiKeyEnv` | `COMFYUI_API_KEY` | Env-variable / credential name for the optional API key |
150
+ | `connectTimeoutMs` | `10000` | Per-request connect/read timeout |
151
+ | `timeoutMs` | `180000` | Sync generation wait budget (raise for video) |
152
+ | `pollIntervalMs` | `1000` | History polling interval while waiting |
153
+ | `maxMediaItems` | `12` | Max media items returned per workflow |
154
+ | `maxMediaBytes` | `67108864` | Max bytes the media proxy streams per file |
155
+ | `dataDir` | *(DSH data dir)* | Where the workflow library and asset index live (`$DSH_HOME/data/dsh-comfyui` by default) |
156
+ | `maxAssets` | `200` | Max entries kept in the asset index |
157
+
158
+ ## Roadmap & design boundaries (v0.2)
159
+
160
+ Confirmed scope decisions for this phase:
161
+
162
+ - **Image-to-video / reference-to-video / audio variants** are not plugin-side features: they share the same upload node as image-to-image, so any such workflow (extracted or imported) works as-is. Add the workflow, not plugin code.
163
+ - **No front-end parameter presets/favorites.** Advanced customization happens in the workflow editor (edit parameter defaults, or add an advanced parameter for any node input). This keeps one source of truth.
164
+ - **Model-strength knobs** (e.g. `ref_boost`) are handled through the advanced-parameter mechanism: expose the node input, label its effect, and the agent can tune it per run.
165
+ - **Planned**: auto-commit of run parameters — after a successful run, save the used parameter values as that workflow's new defaults, so the next run opens with the previous session's values instead of the authored ones.
166
+
167
+ ## Security
168
+
169
+ - The tools only ever connect to the **configured** `baseUrl` — the agent cannot name arbitrary targets (SSRF containment).
170
+ - The API key lives on the host (credentials store / environment), resolved per request; `/comfyui/config` reports only `hasApiKey`.
171
+ - Media is capped by size; config writes require same-origin requests.
172
+ - Workflows extracted from ComfyUI are validated (non-empty `class_type`, object inputs, zero `node_errors` on the server) before they are stored.
173
+ - Headless profiles without a web server keep the tools and skip the routes silently.
174
+
175
+ ## Architecture
176
+
177
+ A single npm package with two halves, following the DH plugin conventions:
178
+
179
+ - `src/index.ts` — host entry: `inject: ['tools']`; registers the tools and the companion skill (`ctx.skills.register`, optional service), and mounts routes + media proxy on a `webServer` sub-fiber (`ctx.inject`) so concurrent entry settling can never skip the mounts.
180
+ - `src/comfyui.ts` — minimal ComfyUI HTTP client (queue prompt, poll history, object_info, system_stats, interrupt, view download, userdata list/read).
181
+ - `src/analyze.ts` — canvas analysis: connected components over active nodes, group membership, dangling/isolated nodes, bypassed counts.
182
+ - `src/convert.ts` — graph → API extraction: rewires links (Reroute / bypass pass-through), derives widget order from the graph's own input array plus object_info (including `control_after_generate` and dynamic sub-widgets), inlines primitive values, drops stale slot references with a warning, and fails loudly when a required input was never wired.
183
+ - `src/skill.ts` — the `dsh-comfyui-workflows` companion skill body.
184
+ - `src/params.ts` — parameter application: fills an unset image parameter with the load-area source image, auto-matches `width`/`height` to the source's recorded size, and re-syncs DynamicCombo parent/child pairs.
185
+ - `src/store.ts` — the workflow library and asset index on disk (`workflows.json` + `assets.json`), plus the load-area records (`current-image.json`, `media-sizes.json`, `media-hashes.json`).
186
+ - `src/queue.ts` — tracks prompts the plugin queued and moves completed ones into the asset index (sweep-on-read, no timers).
187
+ - `src/tools.ts` — `ToolDefinition`s registered through `ctx.tools.register`; results carry `presentationMeta` so the client card renders from the session log.
188
+ - `src/routes.ts` — same-origin HTTP routes for the panel (config, workflows, ComfyUI-side graphs + analyze/extract, assets, queue, run, load area, upload with hash dedup + size recording).
189
+ - `src/client/` — browser half: the `shell.overlay` right-docked panel + `sidebar.footer.action` trigger, the `tool.call.toolview` card (key `comfyui_run`), and the `settings.section` page (id `comfyui`).
190
+ - `cordis.patch.yml` — the `dsh.bundle.patch` layer that inserts the `comfyui` row into a profile.
191
+
192
+ ## Development
193
+
194
+ ```sh
195
+ pnpm install
196
+ npm run typecheck # host + client
197
+ npm run build # tsc (host lib/) + tsdown (client bundle)
198
+ npm pack --dry-run # inspect the publish contents
199
+ ```
200
+
201
+ To test against a local profile: `dsh plugin --profile web add <path-to-this-repo>` (pnpm links the directory), restart the web server, and rebuild with `npm run build` after changes.
202
+
203
+ ## License
204
+
205
+ MIT
package/README.md CHANGED
@@ -1,89 +1,134 @@
1
1
  # dsh-comfyui
2
2
 
3
- > Version 0.2.0 — see [Roadmap & design boundaries](#roadmap--design-boundaries-v02) for this phase's confirmed scope.
3
+ [English](README.en.md) | **中文**
4
4
 
5
- ComfyUI integration for DeepSeek Harness (DH): let an agent generate and process images and videos directly against your ComfyUI server — submit workflows, run built-in templates, watch results render in the chat, and manage everything from a right-docked UI panel.
5
+ <p align="center">
6
+ <img src="logo.png" width="480" alt="dsh-comfyui logo" />
7
+ </p>
6
8
 
7
- ## Features
9
+ <h1 align="center">dsh-comfyui</h1>
8
10
 
9
- - **Agent tools**
10
- - `comfyui_run` — submit a ComfyUI API-format workflow, or pick a built-in template, and get the generated media back. Two modes: `sync` (wait and return media) and `async` (start a background job, collect with `job_output` — ideal for video).
11
- - `comfyui_object_info` — list the node definitions of your ComfyUI server so the agent can build valid workflows on the fly.
12
- - `comfyui_workflow` — list and run runnable workflows from the plugin library. `action: list` also reports graph workflows you saved on the ComfyUI server and whether each has been **extracted** into runnable workflows; unextracted graphs are flagged so the agent tells you to extract them in the panel first.
13
- - **UI panel** (right-docked; open from the sidebar rail) — three tabs:
14
- - **Workflows** — the plugin library of runnable (API) workflows: create / edit / run / delete, plus "Import file" to load an API-format `.json` directly. The **ComfyUI 端保存** section auto-detects graph workflows you saved in ComfyUI, shows which runnable workflows were extracted from each, and offers **提取** with per-graph analysis: a canvas often holds several independent flows, so you choose 整体提取 / 按分量提取 / 只提取主流程. Workflows can be classified with **tags** (see below).
15
- - **Assets** — everything the plugin generated, newest first, with a detail view and download links.
16
- - **Queue** — a task center over ComfyUI's unified jobs API (`/api/jobs`): every task across the live queue **and** history in five states (pending / in progress / completed / failed / cancelled), filterable by state, with per-task progress bars (plugin-submitted jobs), preview thumbnails, failure messages and duration, plus actions — delete, interrupt, rerun, clear queue/history, free memory. Tasks the plugin queued are marked with their workflow name.
17
- - **Load area(加载区)** — an image loader in the style of ComfyUI's LoadImage node, sitting at the top of the Workflows tab:
18
- - Shows the **current source image** as a large preview; clicking opens a picker window with a nav bar (全部 / 已导入 / 已生成), a type filter, a paste/upload drop zone on the right, and a masonry grid of every image in the ComfyUI `input` directory plus everything the plugin generated. Picking an image closes the window and makes it the current source.
19
- - The current source image is the **default input image**: any workflow run that has an unset image-type parameter uses it automatically — the agent does not need to name a file.
20
- - **Resolution auto-match**: uploads record their pixel size; when a run leaves `width`/`height` unset, they default to the source image's actual size.
21
- - **Hash naming + dedup**: uploads are renamed to `原名_短哈希.ext` (SHA-256 first 10 hex); re-uploading an identical file reuses the existing name instead of storing a duplicate. The picker refreshes live after uploads.
22
- - Selecting a **generated** image copies it from the output directory into `input` on the fly, so image-loading nodes can use it.
23
- - **Workflow tags** — classify runnable workflows with preset categories (图生图 / 文生图 / 文生视频 / 图生视频 / 参考生视频 / 文生音频 / 参考生音频) plus any custom tags. Tags are edited in the workflow editor, shown on the top-right of each card, and the library list has a filter bar with per-tag counts.
24
- - **Built-in templates** — `txt2img` (SDXL text-to-image), `img2img` (SDXL image-to-image), `video` (Wan 2.1 text-to-video via ComfyUI-WanVideoWrapper). Template node ids are documented in the tool description so the agent overrides the right inputs.
25
- - **Media proxy** — generated files stream through a same-origin route (`/comfyui/media`), so the browser never talks to ComfyUI directly: no CORS, no mixed-content, no API key in the page, and remote ComfyUI installs work unchanged.
26
- - **Tool card** — results render as a media wall (images/videos with download links) right in the chat, including background-job status.
27
- - **Settings page** — a ComfyUI section in the DH settings where you can edit the server URL, API-key env var, data directory, and asset cap, test the connection, and switch the plugin UI language (中文 / English — stored in the browser, applies to the whole plugin UI), all without touching `cordis.yml`.
28
- - **Companion skill** — a runtime skill (`dsh-comfyui-workflows`) registered through `ctx.skills.register`: the agent learns the graph-vs-runnable model, canvas analysis rules (connected components, bypassed groups, dangling nodes), when to ask you about extract mode, and the extraction tech rules.
11
+ <p align="center">让 DeepSeek Harness 的 Agent 直接驱动 ComfyUI 生成与处理图像、视频。</p>
29
12
 
30
- ### Graph workflows vs runnable workflows (提取执行流)
13
+ <p align="center">
14
+ <a href="https://www.npmjs.com/package/dsh-comfyui"><img src="https://img.shields.io/npm/v/dsh-comfyui" alt="npm version" /></a>
15
+ <a href="https://www.npmjs.com/package/dsh-comfyui"><img src="https://img.shields.io/npm/dm/dsh-comfyui" alt="npm downloads" /></a>
16
+ <img src="https://img.shields.io/npm/l/dsh-comfyui" alt="license" />
17
+ </p>
31
18
 
32
- ComfyUI works in two layers:
19
+ ## 功能
33
20
 
34
- - **Graph workflow(衍生主题)** — the UI graph you save in ComfyUI (nodes/links/widgets). It is a source, not directly runnable, and a single canvas is often a **test bench holding several independent flows at once**. Visual `groups` are just rectangles — the real executable unit is a **connected component** over the links, with bypassed (`mode 4`) and dangling nodes excluded.
35
- - **Runnable workflow(运行主题)** — an API-format prompt, the actual execution unit. You get one by **extracting** it from a graph (1 graph → N runnable workflows) or by pasting/importing an API `.json` directly.
21
+ ### Agent 工具
36
22
 
37
- The **提取** flow analyzes the canvas first (components with their node counts and group membership, bypassed/dangling counts) and lets you pick:
23
+ - `comfyui_run` —— 提交 ComfyUI API 格式的工作流,或选用内置模板,返回生成的媒体。两种模式:`sync`(等待并返回媒体)与 `async`(后台任务,用 `job_output` 收集结果——视频生成强烈建议)。
24
+ - `comfyui_object_info` —— 列出你的 ComfyUI 服务器支持的节点定义,让 Agent 能当场构造合法的工作流。
25
+ - `comfyui_workflow` —— 列出并运行插件库中的可运行工作流。`action: list` 还会报告你在 ComfyUI 端保存的图工作流以及每个是否已**提取**出可运行执行流;未提取的会明确标注,Agent 会先转告你在面板里点"提取"。
38
26
 
39
- - **整体提取** — merge every component into one runnable workflow (everything executes together).
40
- - **按分量提取** (recommended) — one runnable workflow per independent flow.
41
- - **只提取主流程** — the largest component only (usually the flow under test).
27
+ ### UI 面板
42
28
 
43
- Extraction follows the live `/object_info`: rewires Reroute/bypass pass-throughs, maps widget values (including dynamic sub-widgets and `control_after_generate`), inlines primitives, drops stale slot references with a warning, skips components with no output node, and fails loudly when a required input was never wired — every extracted workflow is validated by `POST /prompt` (zero `node_errors`) before it is stored.
29
+ 右侧停靠;从侧边栏轨道打开——三个页签:
44
30
 
45
- ### Adjustable parameters
31
+ - **工作流** —— 插件库(可运行的 API 工作流):新建 / 编辑 / 运行 / 删除,支持"导入文件"直接加载 API 格式 `.json`。"ComfyUI 端保存"分区自动检测你在 ComfyUI 里保存的图工作流,显示每个已提取出的执行流,并提供**提取**:画布上往往躺着多个独立流程,可整体提取 / 按分量提取 / 只提取主流程。工作流可用**标签**分类(见下)。
32
+ - **资产** —— 插件生成的所有结果,最新在前,带详情视图和下载链接。
33
+ - **队列** —— 基于 ComfyUI 统一任务 API(`/api/jobs`)的任务中心:实时队列**和**历史里所有任务按五态展示(待生成 / 生成中 / 已完成 / 失败 / 已取消),可按状态筛选;插件提交的任务带进度条(进度来自 ComfyUI WS 的 progress 事件),终态任务带预览缩略图、失败原因与耗时;支持操作:删除、中断、重跑、清空队列/历史、释放内存。插件提交的任务标注工作流名。
46
34
 
47
- Every runnable workflow carries an adjustable **parameter set** (`parameters`) so one workflow can produce different results per run:
35
+ <p align="center"><img src="images/panel.png" width="70%" alt="插件主面板:工作流 / 资产 / 队列" title="插件主面板:工作流 / 资产 / 队列" /></p>
48
36
 
49
- - **Auto-detected (conservative)**: prompt text inputs, resolution (`EmptyLatentImage` width/height), sampler steps (`KSampler.steps`), and seed (`KSampler.seed`, randomized per run by default). Sampling-related inputs (cfg/denoise) and model selections stay as authored.
50
- - **Advanced parameters**: the panel's workflow editor can expose any node input as a custom parameter (pick node → pick input → name it), and edit each parameter's name, label, default, and random toggle.
51
- - **Agent-facing**: the parameter list is written into the workflow's input notes (`inputs` field) and shown by `comfyui_workflow` `action: list`; `action: run` accepts `parameters: {"prompt": "...", "seed": 42}` overrides — explicit values win over random/default, omitted parameters use their defaults.
52
- - **Load-area integration**: an unset image-type parameter is filled with the load-area's current source image, and unset `width`/`height` are auto-matched to that image's recorded pixel size. Explicit values always win, so the agent can still override both.
37
+ ### 加载区
53
38
 
54
- ## Requirements
39
+ 仿 ComfyUI LoadImage 节点的图像加载器,位于工作流页顶部:
55
40
 
56
- - DeepSeek Harness (web profile) the plugin targets the `web` profile (`@deepseek-ai/dsh-web-app` ≥ 0.1.0-rc.6).
57
- - A running [ComfyUI](https://github.com/comfystack/ComfyUI) server (default `http://127.0.0.1:8188`).
58
- - For the `video` template: the [ComfyUI-WanVideoWrapper](https://github.com/kijai/ComfyUI-WanVideoWrapper) custom nodes and Wan 2.1 model files.
41
+ - 当前源图以大图展示;点击打开加载窗口:上方导航条(全部 / 已导入 / 已生成)、类型筛选、右侧粘贴/上传区、下方瀑布流网格展示 ComfyUI `input` 目录全部图片 + 插件生成的全部结果。点击图像即选定并关闭窗口,成为当前源图。
42
+ - 当前源图即**默认输入图**:任何含图片类参数(未显式指定)的工作流运行都会自动使用它——无需指定文件名。
43
+ - **分辨率自动匹配**:上传时记录像素尺寸;运行时不传 `width`/`height` 则自动用源图实际分辨率。
44
+ - **哈希命名 + 去重**:上传重命名为 `原名_短哈希.ext`(SHA-256 前 10 位十六进制);重复上传相同文件直接复用已有文件名,不产生重复存储。上传后列表实时刷新。
45
+ - 选中**已生成**的图时会自动从输出目录复制到 `input`,图像加载节点即可使用。
59
46
 
60
- ## Installation
47
+ <p align="center"><img src="images/loadarea.png" width="70%" alt="加载区:图像选择与上传" title="加载区:图像选择与上传" /></p>
48
+
49
+ ### 工作流标签
50
+
51
+ 用预设分类(图生图 / 文生图 / 文生视频 / 图生视频 / 参考生视频 / 文生音频 / 参考生音频)+ 自定义标签给可运行工作流分类。标签在编辑工作流时勾选/添加,显示在卡片右上角,列表顶部有带计数的标签筛选条。
52
+
53
+ ### 内置模板
54
+
55
+ `txt2img`(SDXL 文生图)、`img2img`(SDXL 图生图)、`video`(Wan 2.1 文生视频,需要 ComfyUI-WanVideoWrapper)。模板节点 id 写在工具描述里,Agent 会覆盖正确的输入。
56
+
57
+ ### 媒体代理
58
+
59
+ 生成文件经同源路由(`/comfyui/media`)转发,浏览器不直接接触 ComfyUI:没有 CORS、没有混合内容、页面里不出现 API Key,远程 ComfyUI 部署也可直接使用。
60
+
61
+ ### 工具卡片
62
+
63
+ 结果在对话里渲染成媒体墙(图片/视频带下载链接),后台任务也有状态提示。
64
+
65
+ ### 设置页
66
+
67
+ DH 设置里新增 "ComfyUI" 分区:改服务器地址、API Key 环境变量名、数据目录、资产上限、测试连接,并可切换插件界面语言(中文 / English——存于浏览器,作用于整个插件 UI),无需改动 `cordis.yml`。
68
+
69
+ <p align="center"><img src="images/settings.png" width="70%" alt="ComfyUI 设置页(含界面语言切换)" title="ComfyUI 设置页(含界面语言切换)" /></p>
70
+
71
+ ### 配套 skill
72
+
73
+ 通过 `ctx.skills.register` 注册的运行时 skill(`dsh-comfyui-workflows`):让 Agent 掌握图工作流 vs 执行流的概念、画布分析规则(连通分量、绕过组、悬空节点)、何时该询问你提取方式,以及图→API 提取的技术规则。
74
+
75
+ ### 图工作流 vs 可运行工作流(提取执行流)
76
+
77
+ ComfyUI 分两层:
78
+
79
+ - **图工作流(衍生主题)** —— 你在 ComfyUI 里保存的 UI 图(nodes/links/widgets),是"源",不能直接运行。一个画布常常是**同时测试多个独立流程的试验台**;视觉 `groups` 只是矩形,真正可执行单元是**连通分量**(按连线连通,排除绕过与悬空节点)。
80
+ - **可运行工作流(运行主题)** —— API 格式的 prompt,真正的执行单元。从图里**提取**出来(1 图 → N 个执行流),或直接粘贴/导入 API `.json`。
81
+
82
+ **提取**流程会先分析画布(各分量的节点数与所在组、绕过/悬空计数),然后让你选择:
83
+
84
+ - **整体提取** —— 所有分量合成一个执行流(运行时全部执行)。
85
+ - **按分量提取**(推荐)—— 每个独立流程一个执行流。
86
+ - **只提取主流程** —— 只取最大分量(通常是当前测试区块)。
87
+
88
+ 提取严格对照实时 `/object_info`:重排 Reroute/bypass 直通、映射 widget 值(含动态子 widget 与 `control_after_generate`)、内联 Primitive、丢弃失效的输出槽位引用并警告、跳过无输出节点的分量、必需输入缺失时明确报错——每个提取出的执行流都会先经 `POST /prompt` 校验(`node_errors` 为空)才入库。
89
+
90
+ ### 可调参数
91
+
92
+ 每个可运行工作流带一组**可调参数**(`parameters`),让同一流程按需生成不同结果:
93
+
94
+ - **自动识别(保守集)**:提取时自动提取 提示词(文本输入节点)、分辨率(`EmptyLatentImage` 宽高)、采样步数(`KSampler.steps`)、种子(`KSampler.seed`,默认**每次运行随机**)。采样相关(cfg/denoise)与模型选择不暴露,保持工作流原样。
95
+ - **高级参数**:面板"编辑工作流"里可手动暴露任意节点的任意输入为参数(选节点 → 选输入 → 命名),并调整每个参数的名称、显示名、默认值、是否随机。
96
+ - **Agent 感知**:参数清单自动写入工作流的"参数说明"(`inputs` 字段),`comfyui_workflow` 工具的 `action: list` 会展示;`action: run` 接受 `parameters: {"prompt": "...", "seed": 42}` 覆盖——显式传值优先于随机/默认,未传参数用默认值。
97
+ - **加载区联动**:未显式指定的图片类参数自动填入加载区当前源图;未传的 `width`/`height` 自动匹配该图记录的像素尺寸。显式传值始终优先,Agent 仍可覆盖两者。
98
+
99
+ ## 环境要求
100
+
101
+ - DeepSeek Harness(web profile)—— 本插件面向 `web` profile(`@deepseek-ai/dsh-web-app` ≥ 0.1.0-rc.6)。
102
+ - 一个运行中的 [ComfyUI](https://github.com/comfystack/ComfyUI) 服务器(默认 `http://127.0.0.1:8188`)。
103
+ - 使用 `video` 模板需要 [ComfyUI-WanVideoWrapper](https://github.com/kijai/ComfyUI-WanVideoWrapper) 自定义节点和 Wan 2.1 模型文件。
104
+
105
+ ## 安装
61
106
 
62
107
  ```sh
63
108
  dsh plugin --profile web add dsh-comfyui
64
109
  ```
65
110
 
66
- Then restart the web server (host-side rows mount at boot). The panel trigger appears in the sidebar rail, the settings section "ComfyUI" appears in the settings page, and the agent gains `comfyui_run`, `comfyui_object_info`, `comfyui_workflow`, and the `dsh-comfyui-workflows` skill immediately.
111
+ 然后重启 Web 服务(Host 端行在启动时挂载)。侧边栏轨道出现面板入口,设置页出现 "ComfyUI" 分区,Agent 立即获得 `comfyui_run`、`comfyui_object_info`、`comfyui_workflow` `dsh-comfyui-workflows` skill
67
112
 
68
- ### API key (remote servers)
113
+ ### API Key(远程服务器)
69
114
 
70
- For a remote ComfyUI behind an authenticating proxy, provide the key through the credentials store or an environment variable named by `apiKeyEnv` (default `COMFYUI_API_KEY`). The key is resolved per request on the host and never sent to the browser.
115
+ 远程 ComfyUI 若位于需要鉴权的代理之后,通过凭据存储或 `apiKeyEnv` 指定的环境变量(默认 `COMFYUI_API_KEY`)提供密钥。密钥在 Host 端按请求解析,绝不发给浏览器。
71
116
 
72
- ## Usage
117
+ ## 使用
73
118
 
74
- Ask the agent, e.g.:
119
+ 直接告诉 Agent,例如:
75
120
 
76
- - "用 ComfyUI 画一张红猫的图" / "Generate a red cat image with ComfyUI"
77
- - "把这幅图转成赛博朋克风格" (img2img with an input image filename)
78
- - "把加载区这张动漫图转成真人照片,分辨率跟原图一致" (load-area source image + resolution auto-match)
79
- - "生成一段 5 秒的短视频:日落下的城市" (video; needs the Wan wrapper)
80
- - "用我之前在 ComfyUI 里保存的 Krea-Afterlight 跑一下" the agent lists server-side graphs; if yours is not extracted yet it will tell you to click **提取** in the panel first (a canvas may contain several independent flows, so you can extract all as one, per component, or the main flow only).
121
+ - "用 ComfyUI 画一张红猫的图"
122
+ - "把这幅图转成赛博朋克风格"img2img,需要输入图片文件名)
123
+ - "把加载区这张动漫图转成真人照片,分辨率跟原图一致"(加载区源图 + 分辨率自动匹配)
124
+ - "生成一段 5 秒的短视频:日落下的城市"video,需要 Wan 插件)
125
+ - "用我之前在 ComfyUI 里保存的 Krea-Afterlight 跑一下" —— Agent 会列出服务器端的图工作流;如果你指的那个还没提取,它会先转告你去面板里点**提取**(画布可能含多个独立流程,可选整体/按分量/主流程)。
81
126
 
82
- The agent picks a template, inspects your server with `comfyui_object_info`, or runs a library workflow with `comfyui_workflow`.
127
+ Agent 会选用模板,或用 `comfyui_object_info` 探查你的服务器,或用 `comfyui_workflow` 运行插件库里已保存的执行流。
83
128
 
84
- ### Configuration
129
+ ### 配置
85
130
 
86
- The plugin reads a `comfyui` section from `cordis.yml` (or the settings page):
131
+ 插件读取 `cordis.yml` 中的 `comfyui` 段(或通过设置页修改):
87
132
 
88
133
  ```yaml
89
134
  # cordis.yml
@@ -98,62 +143,62 @@ The plugin reads a `comfyui` section from `cordis.yml` (or the settings page):
98
143
  maxAssets: 200
99
144
  ```
100
145
 
101
- | Key | Default | Description |
146
+ | | 默认值 | 说明 |
102
147
  | --- | --- | --- |
103
- | `baseUrl` | `http://127.0.0.1:8188` | ComfyUI HTTP server base URL |
104
- | `apiKeyEnv` | `COMFYUI_API_KEY` | Env-variable / credential name for the optional API key |
105
- | `connectTimeoutMs` | `10000` | Per-request connect/read timeout |
106
- | `timeoutMs` | `180000` | Sync generation wait budget (raise for video) |
107
- | `pollIntervalMs` | `1000` | History polling interval while waiting |
108
- | `maxMediaItems` | `12` | Max media items returned per workflow |
109
- | `maxMediaBytes` | `67108864` | Max bytes the media proxy streams per file |
110
- | `dataDir` | *(DSH data dir)* | Where the workflow library and asset index live (`$DSH_HOME/data/dsh-comfyui` by default) |
111
- | `maxAssets` | `200` | Max entries kept in the asset index |
112
-
113
- ## Roadmap & design boundaries (v0.2)
114
-
115
- Confirmed scope decisions for this phase:
116
-
117
- - **Image-to-video / reference-to-video / audio variants** are not plugin-side features: they share the same upload node as image-to-image, so any such workflow (extracted or imported) works as-is. Add the workflow, not plugin code.
118
- - **No front-end parameter presets/favorites.** Advanced customization happens in the workflow editor (edit parameter defaults, or add an advanced parameter for any node input). This keeps one source of truth.
119
- - **Model-strength knobs** (e.g. `ref_boost`) are handled through the advanced-parameter mechanism: expose the node input, label its effect, and the agent can tune it per run.
120
- - **Planned**: auto-commit of run parameters — after a successful run, save the used parameter values as that workflow's new defaults, so the next run opens with the previous session's values instead of the authored ones.
121
-
122
- ## Security
123
-
124
- - The tools only ever connect to the **configured** `baseUrl` the agent cannot name arbitrary targets (SSRF containment).
125
- - The API key lives on the host (credentials store / environment), resolved per request; `/comfyui/config` reports only `hasApiKey`.
126
- - Media is capped by size; config writes require same-origin requests.
127
- - Workflows extracted from ComfyUI are validated (non-empty `class_type`, object inputs, zero `node_errors` on the server) before they are stored.
128
- - Headless profiles without a web server keep the tools and skip the routes silently.
129
-
130
- ## Architecture
131
-
132
- A single npm package with two halves, following the DH plugin conventions:
133
-
134
- - `src/index.ts` host entry: `inject: ['tools']`; registers the tools and the companion skill (`ctx.skills.register`, optional service), and mounts routes + media proxy on a `webServer` sub-fiber (`ctx.inject`) so concurrent entry settling can never skip the mounts.
135
- - `src/comfyui.ts` minimal ComfyUI HTTP client (queue prompt, poll history, object_info, system_stats, interrupt, view download, userdata list/read).
136
- - `src/analyze.ts` canvas analysis: connected components over active nodes, group membership, dangling/isolated nodes, bypassed counts.
137
- - `src/convert.ts` graph → API extraction: rewires links (Reroute / bypass pass-through), derives widget order from the graph's own input array plus object_info (including `control_after_generate` and dynamic sub-widgets), inlines primitive values, drops stale slot references with a warning, and fails loudly when a required input was never wired.
138
- - `src/skill.ts` the `dsh-comfyui-workflows` companion skill body.
139
- - `src/params.ts` parameter application: fills an unset image parameter with the load-area source image, auto-matches `width`/`height` to the source's recorded size, and re-syncs DynamicCombo parent/child pairs.
140
- - `src/store.ts` the workflow library and asset index on disk (`workflows.json` + `assets.json`), plus the load-area records (`current-image.json`, `media-sizes.json`, `media-hashes.json`).
141
- - `src/queue.ts` tracks prompts the plugin queued and moves completed ones into the asset index (sweep-on-read, no timers).
142
- - `src/tools.ts` `ToolDefinition`s registered through `ctx.tools.register`; results carry `presentationMeta` so the client card renders from the session log.
143
- - `src/routes.ts` same-origin HTTP routes for the panel (config, workflows, ComfyUI-side graphs + analyze/extract, assets, queue, run, load area, upload with hash dedup + size recording).
144
- - `src/client/` browser half: the `shell.overlay` right-docked panel + `sidebar.footer.action` trigger, the `tool.call.toolview` card (key `comfyui_run`), and the `settings.section` page (id `comfyui`).
145
- - `cordis.patch.yml` the `dsh.bundle.patch` layer that inserts the `comfyui` row into a profile.
146
-
147
- ## Development
148
+ | `baseUrl` | `http://127.0.0.1:8188` | ComfyUI HTTP 服务器地址 |
149
+ | `apiKeyEnv` | `COMFYUI_API_KEY` | 可选 API Key 的环境变量/凭据名 |
150
+ | `connectTimeoutMs` | `10000` | 单次请求连接/读取超时 |
151
+ | `timeoutMs` | `180000` | 同步生成的等待预算(视频请调大) |
152
+ | `pollIntervalMs` | `1000` | 等待完成时的历史轮询间隔 |
153
+ | `maxMediaItems` | `12` | 每个工作流最多返回的媒体条数 |
154
+ | `maxMediaBytes` | `67108864` | 媒体代理单文件流式传输上限(字节) |
155
+ | `dataDir` | *(DSH 数据目录)* | 工作流库与资产索引存放位置(默认 `$DSH_HOME/data/dsh-comfyui`) |
156
+ | `maxAssets` | `200` | 资产索引最多保留的条数 |
157
+
158
+ ## Roadmap 与设计边界(v0.2
159
+
160
+ 本阶段确认的范围决策:
161
+
162
+ - **图生视频 / 参考生视频 / 音视频变体**不是插件侧功能:它们与图生图共用同一个上传节点,任何这类工作流(提取或导入)开箱即用。缺的是工作流本身,不是插件代码。
163
+ - **不做前端参数预设/收藏**。高级定制在工作流编辑里完成(修改参数默认值,或把任意节点输入添加为高级参数)。保持唯一事实来源。
164
+ - **模型强度类参数**(如 `ref_boost`)走高级参数机制:暴露节点输入、标注作用,Agent 即可按次调节。
165
+ - **规划中**:运行参数自动回写——运行成功后把本次使用的参数值保存为该工作流的新默认值,下次打开就是上一次会话用的值,而不是作者初始值。
166
+
167
+ ## 安全
168
+
169
+ - 工具只会连接**配置好的** `baseUrl` —— Agent 无法指定任意目标(SSRF 遏制)。
170
+ - API Key 只存在于 Host(凭据存储/环境变量),按请求解析;`/comfyui/config` 只回传 `hasApiKey`。
171
+ - 媒体有大小上限;配置写入要求同源请求。
172
+ - ComfyUI 提取的执行流会先校验(非空 `class_type`、对象型 inputs、服务器 `node_errors` 为空)再入库。
173
+ - Web 服务器的 headless profile 只保留工具,路由静默跳过。
174
+
175
+ ## 架构
176
+
177
+ 一个 npm 包、双端实现,遵循 DH 插件约定:
178
+
179
+ - `src/index.ts` —— Host 入口:`inject: ['tools']`;注册工具与配套 skill(`ctx.skills.register`,可选服务),并把路由与媒体代理挂到 `webServer` fiber(`ctx.inject`)上,避免并发 settle 导致挂载被静默跳过。
180
+ - `src/comfyui.ts` —— 精简的 ComfyUI HTTP 客户端(排队、轮询历史、object_infosystem_statsinterruptview 下载、userdata 列表/读取)。
181
+ - `src/analyze.ts` —— 画布分析:激活节点的连通分量、组归属、悬空/孤立节点、绕过计数。
182
+ - `src/convert.ts` —— → API 提取:重排连线(Reroute / bypass 直通)、按图自身输入顺序 + object_info 推导 widget 顺序(含 `control_after_generate` 与动态子 widget)、内联 Primitive 值、丢弃失效的输出槽位引用并警告、必需输入缺失时明确报错。
183
+ - `src/skill.ts` —— `dsh-comfyui-workflows` 配套 skill 正文。
184
+ - `src/params.ts` —— 参数应用:未指定的图片参数填入加载区源图、`width`/`height` 自动匹配源图记录尺寸、DynamicCombo 父子联动同步。
185
+ - `src/store.ts` —— 工作流库与资产索引落盘(`workflows.json` + `assets.json`),以及加载区记录(`current-image.json`、`media-sizes.json`、`media-hashes.json`)。
186
+ - `src/queue.ts` —— 追踪插件提交的 prompt,完成后移入资产索引(读时清扫,无定时器)。
187
+ - `src/tools.ts` —— 通过 `ctx.tools.register` 注册的 `ToolDefinition`;结果携带 `presentationMeta`,客户端卡片从会话日志渲染。
188
+ - `src/routes.ts` —— 面板用的同源 HTTP 路由(配置、工作流、ComfyUI 端图 + 分析/提取、资产、队列、运行、加载区、带哈希去重与尺寸记录的上传)。
189
+ - `src/client/` —— 浏览器端:`shell.overlay` 右侧停靠面板 + `sidebar.footer.action` 触发器、`tool.call.toolview` 卡片(key `comfyui_run`)、`settings.section` 设置页(id `comfyui`)。
190
+ - `cordis.patch.yml` —— `dsh.bundle.patch` 补丁层,把 `comfyui` 行插入 profile
191
+
192
+ ## 开发
148
193
 
149
194
  ```sh
150
195
  pnpm install
151
196
  npm run typecheck # host + client
152
- npm run build # tsc (host lib/) + tsdown (client bundle)
153
- npm pack --dry-run # inspect the publish contents
197
+ npm run build # tschost lib/)+ tsdownclient bundle
198
+ npm pack --dry-run # 检查发布内容
154
199
  ```
155
200
 
156
- To test against a local profile: `dsh plugin --profile web add <path-to-this-repo>` (pnpm links the directory), restart the web server, and rebuild with `npm run build` after changes.
201
+ 本地测试:`dsh plugin --profile web add <本仓库路径>`(pnpm 链接目录),重启 Web 服务,改动后 `npm run build` 重新构建。
157
202
 
158
203
  ## License
159
204
 
File without changes
Binary file
Binary file
Binary file
package/logo.png ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-comfyui",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.3.0-beta.2",
4
4
  "description": "Drive ComfyUI from DeepSeek Harness: generate and process images and videos through agent tools, with a workflow/asset/queue panel, in-chat results and a settings page. / 让 DeepSeek Harness 的 Agent 直接驱动 ComfyUI 生成与处理图像、视频,带工作流/资产/队列面板。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -19,7 +19,9 @@
19
19
  "client",
20
20
  "cordis.patch.yml",
21
21
  "README.md",
22
- "README.zh.md",
22
+ "README.en.md",
23
+ "logo.png",
24
+ "images",
23
25
  "LICENSE"
24
26
  ],
25
27
  "scripts": {
package/README.zh.md DELETED
@@ -1,160 +0,0 @@
1
- # dsh-comfyui
2
-
3
- > 版本 0.2.0 —— 本阶段确认的功能范围见 [Roadmap 与设计边界](#roadmap-与设计边界v02)。
4
-
5
- DeepSeek Harness (DH) 的 ComfyUI 集成插件:让 Agent 直接调用你的 ComfyUI 服务器生成和处理图像、视频——提交工作流、使用内置模板、在对话里直接看到生成结果,并通过右侧停靠的 UI 面板管理一切。
6
-
7
- ## 功能
8
-
9
- - **Agent 工具**
10
- - `comfyui_run` —— 提交 ComfyUI API 格式的工作流,或选用内置模板,返回生成的媒体。两种模式:`sync`(等待并返回媒体)与 `async`(后台任务,用 `job_output` 收集结果——视频生成强烈建议)。
11
- - `comfyui_object_info` —— 列出你的 ComfyUI 服务器支持的节点定义,让 Agent 能当场构造合法的工作流。
12
- - `comfyui_workflow` —— 列出并运行插件库中的可运行工作流。`action: list` 还会报告你在 ComfyUI 端保存的图工作流以及每个是否已**提取**出可运行执行流;未提取的会明确标注,Agent 会先转告你在面板里点"提取"。
13
- - **UI 面板**(右侧停靠;从侧边栏轨道打开)——三个页签:
14
- - **工作流** —— 插件库(可运行的 API 工作流):新建 / 编辑 / 运行 / 删除,支持"导入文件"直接加载 API 格式 `.json`。"ComfyUI 端保存"分区自动检测你在 ComfyUI 里保存的图工作流,显示每个已提取出的执行流,并提供**提取**:画布上往往躺着多个独立流程,可整体提取 / 按分量提取 / 只提取主流程。工作流可用**标签**分类(见下)。
15
- - **资产** —— 插件生成的所有结果,最新在前,带详情视图和下载链接。
16
- - **队列** —— 基于 ComfyUI 统一任务 API(`/api/jobs`)的任务中心:实时队列**和**历史里所有任务按五态展示(待生成 / 生成中 / 已完成 / 失败 / 已取消),可按状态筛选;插件提交的任务带进度条(进度来自 ComfyUI WS 的 progress 事件),终态任务带预览缩略图、失败原因与耗时;支持操作:删除、中断、重跑、清空队列/历史、释放内存。插件提交的任务标注工作流名。
17
- - **加载区** —— 仿 ComfyUI LoadImage 节点的图像加载器,位于工作流页顶部:
18
- - 当前源图以大图展示;点击打开加载窗口:上方导航条(全部 / 已导入 / 已生成)、类型筛选、右侧粘贴/上传区、下方瀑布流网格展示 ComfyUI `input` 目录全部图片 + 插件生成的全部结果。点击图像即选定并关闭窗口,成为当前源图。
19
- - 当前源图即**默认输入图**:任何含图片类参数(未显式指定)的工作流运行都会自动使用它——无需指定文件名。
20
- - **分辨率自动匹配**:上传时记录像素尺寸;运行时不传 `width`/`height` 则自动用源图实际分辨率。
21
- - **哈希命名 + 去重**:上传重命名为 `原名_短哈希.ext`(SHA-256 前 10 位十六进制);重复上传相同文件直接复用已有文件名,不产生重复存储。上传后列表实时刷新。
22
- - 选中**已生成**的图时会自动从输出目录复制到 `input`,图像加载节点即可使用。
23
- - **工作流标签** —— 用预设分类(图生图 / 文生图 / 文生视频 / 图生视频 / 参考生视频 / 文生音频 / 参考生音频)+ 自定义标签给可运行工作流分类。标签在编辑工作流时勾选/添加,显示在卡片右上角,列表顶部有带计数的标签筛选条。
24
- - **内置模板** —— `txt2img`(SDXL 文生图)、`img2img`(SDXL 图生图)、`video`(Wan 2.1 文生视频,需要 ComfyUI-WanVideoWrapper)。模板节点 id 写在工具描述里,Agent 会覆盖正确的输入。
25
- - **媒体代理** —— 生成文件经同源路由(`/comfyui/media`)转发,浏览器不直接接触 ComfyUI:没有 CORS、没有混合内容、页面里不出现 API Key,远程 ComfyUI 部署也可直接使用。
26
- - **工具卡片** —— 结果在对话里渲染成媒体墙(图片/视频带下载链接),后台任务也有状态提示。
27
- - **设置页** —— DH 设置里新增 "ComfyUI" 分区:改服务器地址、API Key 环境变量名、数据目录、资产上限、测试连接,并可切换插件界面语言(中文 / English——存于浏览器,作用于整个插件 UI),无需改动 `cordis.yml`。
28
- - **配套 skill** —— 通过 `ctx.skills.register` 注册的运行时 skill(`dsh-comfyui-workflows`):让 Agent 掌握图工作流 vs 执行流的概念、画布分析规则(连通分量、绕过组、悬空节点)、何时该询问你提取方式,以及图→API 提取的技术规则。
29
-
30
- ### 图工作流 vs 可运行工作流(提取执行流)
31
-
32
- ComfyUI 分两层:
33
-
34
- - **图工作流(衍生主题)** —— 你在 ComfyUI 里保存的 UI 图(nodes/links/widgets),是"源",不能直接运行。一个画布常常是**同时测试多个独立流程的试验台**;视觉 `groups` 只是矩形,真正可执行单元是**连通分量**(按连线连通,排除绕过与悬空节点)。
35
- - **可运行工作流(运行主题)** —— API 格式的 prompt,真正的执行单元。从图里**提取**出来(1 图 → N 个执行流),或直接粘贴/导入 API `.json`。
36
-
37
- **提取**流程会先分析画布(各分量的节点数与所在组、绕过/悬空计数),然后让你选择:
38
-
39
- - **整体提取** —— 所有分量合成一个执行流(运行时全部执行)。
40
- - **按分量提取**(推荐)—— 每个独立流程一个执行流。
41
- - **只提取主流程** —— 只取最大分量(通常是当前测试区块)。
42
-
43
- 提取严格对照实时 `/object_info`:重排 Reroute/bypass 直通、映射 widget 值(含动态子 widget 与 `control_after_generate`)、内联 Primitive、丢弃失效的输出槽位引用并警告、跳过无输出节点的分量、必需输入缺失时明确报错——每个提取出的执行流都会先经 `POST /prompt` 校验(`node_errors` 为空)才入库。
44
-
45
- ### 可调参数
46
-
47
- 每个可运行工作流带一组**可调参数**(`parameters`),让同一流程按需生成不同结果:
48
-
49
- - **自动识别(保守集)**:提取时自动提取 提示词(文本输入节点)、分辨率(`EmptyLatentImage` 宽高)、采样步数(`KSampler.steps`)、种子(`KSampler.seed`,默认**每次运行随机**)。采样相关(cfg/denoise)与模型选择不暴露,保持工作流原样。
50
- - **高级参数**:面板"编辑工作流"里可手动暴露任意节点的任意输入为参数(选节点 → 选输入 → 命名),并调整每个参数的名称、显示名、默认值、是否随机。
51
- - **Agent 感知**:参数清单自动写入工作流的"参数说明"(`inputs` 字段),`comfyui_workflow` 工具的 `action: list` 会展示;`action: run` 接受 `parameters: {"prompt": "...", "seed": 42}` 覆盖——显式传值优先于随机/默认,未传参数用默认值。
52
- - **加载区联动**:未显式指定的图片类参数自动填入加载区当前源图;未传的 `width`/`height` 自动匹配该图记录的像素尺寸。显式传值始终优先,Agent 仍可覆盖两者。
53
-
54
- ## 环境要求
55
-
56
- - DeepSeek Harness(web profile)—— 本插件面向 `web` profile(`@deepseek-ai/dsh-web-app` ≥ 0.1.0-rc.6)。
57
- - 一个运行中的 [ComfyUI](https://github.com/comfystack/ComfyUI) 服务器(默认 `http://127.0.0.1:8188`)。
58
- - 使用 `video` 模板需要 [ComfyUI-WanVideoWrapper](https://github.com/kijai/ComfyUI-WanVideoWrapper) 自定义节点和 Wan 2.1 模型文件。
59
-
60
- ## 安装
61
-
62
- ```sh
63
- dsh plugin --profile web add dsh-comfyui
64
- ```
65
-
66
- 然后重启 Web 服务(Host 端行在启动时挂载)。侧边栏轨道出现面板入口,设置页出现 "ComfyUI" 分区,Agent 立即获得 `comfyui_run`、`comfyui_object_info`、`comfyui_workflow` 与 `dsh-comfyui-workflows` skill。
67
-
68
- ### API Key(远程服务器)
69
-
70
- 远程 ComfyUI 若位于需要鉴权的代理之后,通过凭据存储或 `apiKeyEnv` 指定的环境变量(默认 `COMFYUI_API_KEY`)提供密钥。密钥在 Host 端按请求解析,绝不发给浏览器。
71
-
72
- ## 使用
73
-
74
- 直接告诉 Agent,例如:
75
-
76
- - "用 ComfyUI 画一张红猫的图"
77
- - "把这幅图转成赛博朋克风格"(img2img,需要输入图片文件名)
78
- - "把加载区这张动漫图转成真人照片,分辨率跟原图一致"(加载区源图 + 分辨率自动匹配)
79
- - "生成一段 5 秒的短视频:日落下的城市"(video,需要 Wan 插件)
80
- - "用我之前在 ComfyUI 里保存的 Krea-Afterlight 跑一下" —— Agent 会列出服务器端的图工作流;如果你指的那个还没提取,它会先转告你去面板里点**提取**(画布可能含多个独立流程,可选整体/按分量/主流程)。
81
-
82
- Agent 会选用模板,或用 `comfyui_object_info` 探查你的服务器,或用 `comfyui_workflow` 运行插件库里已保存的执行流。
83
-
84
- ### 配置
85
-
86
- 插件读取 `cordis.yml` 中的 `comfyui` 段(或通过设置页修改):
87
-
88
- ```yaml
89
- # cordis.yml
90
- - id: comfyui
91
- name: dsh-comfyui
92
- config:
93
- baseUrl: http://127.0.0.1:8188
94
- apiKeyEnv: COMFYUI_API_KEY
95
- timeoutMs: 180000
96
- maxMediaItems: 12
97
- dataDir: ''
98
- maxAssets: 200
99
- ```
100
-
101
- | 键 | 默认值 | 说明 |
102
- | --- | --- | --- |
103
- | `baseUrl` | `http://127.0.0.1:8188` | ComfyUI HTTP 服务器地址 |
104
- | `apiKeyEnv` | `COMFYUI_API_KEY` | 可选 API Key 的环境变量/凭据名 |
105
- | `connectTimeoutMs` | `10000` | 单次请求连接/读取超时 |
106
- | `timeoutMs` | `180000` | 同步生成的等待预算(视频请调大) |
107
- | `pollIntervalMs` | `1000` | 等待完成时的历史轮询间隔 |
108
- | `maxMediaItems` | `12` | 每个工作流最多返回的媒体条数 |
109
- | `maxMediaBytes` | `67108864` | 媒体代理单文件流式传输上限(字节) |
110
- | `dataDir` | *(DSH 数据目录)* | 工作流库与资产索引存放位置(默认 `$DSH_HOME/data/dsh-comfyui`) |
111
- | `maxAssets` | `200` | 资产索引最多保留的条数 |
112
-
113
- ## Roadmap 与设计边界(v0.2)
114
-
115
- 本阶段确认的范围决策:
116
-
117
- - **图生视频 / 参考生视频 / 音视频变体**不是插件侧功能:它们与图生图共用同一个上传节点,任何这类工作流(提取或导入)开箱即用。缺的是工作流本身,不是插件代码。
118
- - **不做前端参数预设/收藏**。高级定制在工作流编辑里完成(修改参数默认值,或把任意节点输入添加为高级参数)。保持唯一事实来源。
119
- - **模型强度类参数**(如 `ref_boost`)走高级参数机制:暴露节点输入、标注作用,Agent 即可按次调节。
120
- - **规划中**:运行参数自动回写——运行成功后把本次使用的参数值保存为该工作流的新默认值,下次打开就是上一次会话用的值,而不是作者初始值。
121
-
122
- ## 安全
123
-
124
- - 工具只会连接**配置好的** `baseUrl` —— Agent 无法指定任意目标(SSRF 遏制)。
125
- - API Key 只存在于 Host(凭据存储/环境变量),按请求解析;`/comfyui/config` 只回传 `hasApiKey`。
126
- - 媒体有大小上限;配置写入要求同源请求。
127
- - 从 ComfyUI 提取的执行流会先校验(非空 `class_type`、对象型 inputs、服务器 `node_errors` 为空)再入库。
128
- - 无 Web 服务器的 headless profile 只保留工具,路由静默跳过。
129
-
130
- ## 架构
131
-
132
- 一个 npm 包、双端实现,遵循 DH 插件约定:
133
-
134
- - `src/index.ts` —— Host 入口:`inject: ['tools']`;注册工具与配套 skill(`ctx.skills.register`,可选服务),并把路由与媒体代理挂到 `webServer` 子 fiber(`ctx.inject`)上,避免并发 settle 导致挂载被静默跳过。
135
- - `src/comfyui.ts` —— 精简的 ComfyUI HTTP 客户端(排队、轮询历史、object_info、system_stats、interrupt、view 下载、userdata 列表/读取)。
136
- - `src/analyze.ts` —— 画布分析:激活节点的连通分量、组归属、悬空/孤立节点、绕过计数。
137
- - `src/convert.ts` —— 图 → API 提取:重排连线(Reroute / bypass 直通)、按图自身输入顺序 + object_info 推导 widget 顺序(含 `control_after_generate` 与动态子 widget)、内联 Primitive 值、丢弃失效的输出槽位引用并警告、必需输入缺失时明确报错。
138
- - `src/skill.ts` —— `dsh-comfyui-workflows` 配套 skill 正文。
139
- - `src/params.ts` —— 参数应用:未指定的图片参数填入加载区源图、`width`/`height` 自动匹配源图记录尺寸、DynamicCombo 父子联动同步。
140
- - `src/store.ts` —— 工作流库与资产索引落盘(`workflows.json` + `assets.json`),以及加载区记录(`current-image.json`、`media-sizes.json`、`media-hashes.json`)。
141
- - `src/queue.ts` —— 追踪插件提交的 prompt,完成后移入资产索引(读时清扫,无定时器)。
142
- - `src/tools.ts` —— 通过 `ctx.tools.register` 注册的 `ToolDefinition`;结果携带 `presentationMeta`,客户端卡片从会话日志渲染。
143
- - `src/routes.ts` —— 面板用的同源 HTTP 路由(配置、工作流、ComfyUI 端图 + 分析/提取、资产、队列、运行、加载区、带哈希去重与尺寸记录的上传)。
144
- - `src/client/` —— 浏览器端:`shell.overlay` 右侧停靠面板 + `sidebar.footer.action` 触发器、`tool.call.toolview` 卡片(key `comfyui_run`)、`settings.section` 设置页(id `comfyui`)。
145
- - `cordis.patch.yml` —— `dsh.bundle.patch` 补丁层,把 `comfyui` 行插入 profile。
146
-
147
- ## 开发
148
-
149
- ```sh
150
- pnpm install
151
- npm run typecheck # host + client
152
- npm run build # tsc(host lib/)+ tsdown(client bundle)
153
- npm pack --dry-run # 检查发布内容
154
- ```
155
-
156
- 本地测试:`dsh plugin --profile web add <本仓库路径>`(pnpm 链接目录),重启 Web 服务,改动后 `npm run build` 重新构建。
157
-
158
- ## License
159
-
160
- MIT