dsh-sendcomfy 0.5.1 → 0.5.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/CONTRACT.md +7 -7
- package/README.md +13 -1
- package/client.js +2 -2
- package/index.js +43 -2
- package/lib/http.mjs +65 -2
- package/package.json +3 -2
package/CONTRACT.md
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
> 目标:DSH(DeepSeek Harness)持久插件。侧边栏一个 ComfyUI 面板(配置 Comfy IP、看模型、导入/管理/运行工作流、填提示词、调参数),
|
|
4
4
|
> 同时 Host 注册 `comfy_*` 工具,让会话里的文本模型直接调用 ComfyUI。
|
|
5
|
-
>
|
|
5
|
+
> 包目录:`/run/user/1000/doc/84a6cc0b/dsh-agent/dsh-sendcomfy`
|
|
6
6
|
> 包名:`dsh-sendcomfy`;**本文件是各文件之间的唯一契约,改接口先改这里并通知 Lead。**
|
|
7
7
|
|
|
8
8
|
## 0. 运行环境与硬约束
|
|
9
9
|
|
|
10
|
-
- Node
|
|
10
|
+
- Node:`/snap/node/current/bin/node`(v24.22.3)。shell 里直接 `node` 会因 snap 封装 + 无 DBus 失败,**一律用绝对路径**。
|
|
11
11
|
- 全部 ESM(`type: module`),**零第三方依赖**(只用 Node 内建 + 全局 fetch/FormData/Blob),不 import `@deepseek-ai/*`。
|
|
12
12
|
- 不用 TypeScript、不用打包;`client.js` 是浏览器自注册脚本(见 §6)。
|
|
13
13
|
- 工作流/配置持久化在 `$DSH_HOME/sendcomfy/state.json`(默认 `~/.dsh/sendcomfy/state.json`),**不改 profile 的 patch/package**。
|
|
14
14
|
- 本包不导出 Schemastery `Config`(避免 schema 校验失败导致整条插件不激活)。
|
|
15
15
|
- 文案:Host 侧错误信息可用中文;客户端 UI 文案走 locale(§7)。
|
|
16
|
-
-
|
|
16
|
+
- 测试命令:`/snap/node/current/bin/node --test test/xxx.test.mjs`
|
|
17
17
|
|
|
18
18
|
## 1. 文件归属(写作用域,互不重叠)
|
|
19
19
|
|
|
@@ -369,16 +369,16 @@ window.__ModuleLoader__.load({
|
|
|
369
369
|
工具描述按 agent-experience 规范:先说用途与前提,参数规则写在参数里,不写实现细节。图片输出落盘到「当前会话工作目录/comfy-output/<promptId 前 8 位>/」。
|
|
370
370
|
|
|
371
371
|
## 9. 安装与验证(只有 Lead 做)
|
|
372
|
-
- 安装:`plugin_manager { action:'install_bundle', target:'
|
|
372
|
+
- 安装:`plugin_manager { action:'install_bundle', target:'/run/user/1000/doc/84a6cc0b/dsh-agent/dsh-sendcomfy' }`
|
|
373
373
|
- 验证:`cordis_inspect_query` Client `Slots.listSubTree`(root=`sidebar.panellist`/`main`)确认注册;Host `Tool.listTools` 确认工具;页面视觉由用户确认(本会话无浏览器控制)。
|
|
374
374
|
- 安装前 Lead 会:`node --check` 全部 js、`node --test test/`、locale JSON 校验、manifest 校验。
|
|
375
375
|
|
|
376
376
|
## 10. 环境坑(2026-11-16 实测,所有人必读)
|
|
377
377
|
|
|
378
|
-
1. shell 里直接 `node` 坏(snap 封装 + 无 DBus
|
|
378
|
+
1. shell 里直接 `node` 坏(snap 封装 + 无 DBus)。必须用绝对路径:`/snap/node/current/bin/node`。
|
|
379
379
|
2. **node 进程不能在 workspace 目录作为 cwd 启动**(`process.cwd` 报 ENOENT,bootstrap 就崩)。所有 node 命令都必须 `workdir: "/tmp"`(bash 工具参数),再用**绝对路径**引用包内文件,例如:
|
|
380
|
-
`bash { workdir: "/tmp", command: "node --check
|
|
381
|
-
`bash { workdir: "/tmp", command: "node --test
|
|
380
|
+
`bash { workdir: "/tmp", command: "/snap/node/current/bin/node --check /run/user/1000/doc/84a6cc0b/dsh-agent/dsh-sendcomfy/lib/comfy.mjs" }`
|
|
381
|
+
`bash { workdir: "/tmp", command: "/snap/node/current/bin/node --test /run/user/1000/doc/84a6cc0b/dsh-agent/dsh-sendcomfy/test/comfy.test.mjs" }`
|
|
382
382
|
3. 从 /tmp cwd 的 node 进程看,**workspace 是只读的(EROFS)**:测试里要写临时文件/状态目录,用 `node:os.tmpdir()` + `mkdtemp`,**不要写包目录 / workspace**。要落盘新文件就用 write/edit 工具或 bash(bash 默认 workdir=workspace 时可写)。
|
|
383
383
|
4. bash 沙箱偶发 bwrap 报错("sandbox backend unusable")或偶发 EROFS,重试即可。
|
|
384
384
|
5. 测试读 fixture 用 `new URL('./fixtures/x.json', import.meta.url)` 或 `fileURLToPath(import.meta.url)` 推导,不要用 process.cwd()。
|
package/README.md
CHANGED
|
@@ -113,10 +113,22 @@ AI 会自己 `comfy_choose_workflow` → `comfy_workflow` → `comfy_run`,并
|
|
|
113
113
|
|
|
114
114
|
---
|
|
115
115
|
|
|
116
|
+
## 访问控制
|
|
117
|
+
|
|
118
|
+
`/api/sendcomfy/*` 能改配置、触发跑图、上传图片,所以每条请求先过准入检查再分发:
|
|
119
|
+
|
|
120
|
+
- 有 `connection` 服务时走 `connection.requestRejection({ headers })`:Host/Origin 栅栏(挡 DNS rebinding 与跨站调用)+ 浏览器登录态,与官方插件同一口径;
|
|
121
|
+
- 取不到 `connection` 时退回本机回环栅栏:`Host` 必须回环、`Origin` 必须同源、`Origin: null` 拒绝;
|
|
122
|
+
- 拒绝返回 401/403,请求体不解析、不触达业务层。
|
|
123
|
+
|
|
124
|
+
`engines.dsh` 声明为 `>=0.2.2-rc.5`(`requestRejection` 从该版本可用)。
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
116
128
|
## 开发
|
|
117
129
|
|
|
118
130
|
```bash
|
|
119
|
-
npm test # node:test,
|
|
131
|
+
npm test # node:test,166 个用例
|
|
120
132
|
```
|
|
121
133
|
|
|
122
134
|
纯 ESM、零运行时依赖,只用 Node 内建 + 全局 `fetch`/`FormData`/`Blob`。
|
package/client.js
CHANGED
|
@@ -74,7 +74,7 @@ window.__ModuleLoader__.load({
|
|
|
74
74
|
'wf.importFileTooBig': '文件过大(上限 4MB)',
|
|
75
75
|
'wf.importing': '导入中…',
|
|
76
76
|
'wf.importedAs': '已导入:{name}',
|
|
77
|
-
'panel.version': 'v0.5.
|
|
77
|
+
'panel.version': 'v0.5.3',
|
|
78
78
|
'tab.workflows': '工作流',
|
|
79
79
|
'conn.configureCta': '去配置连接',
|
|
80
80
|
'tab.models': '模型',
|
|
@@ -228,7 +228,7 @@ window.__ModuleLoader__.load({
|
|
|
228
228
|
'wf.importFileTooBig': 'File is too large (4MB limit)',
|
|
229
229
|
'wf.importing': 'Importing…',
|
|
230
230
|
'wf.importedAs': 'Imported: {name}',
|
|
231
|
-
'panel.version': 'v0.5.
|
|
231
|
+
'panel.version': 'v0.5.3',
|
|
232
232
|
'tab.workflows': 'Workflows',
|
|
233
233
|
'conn.configureCta': 'Configure connection',
|
|
234
234
|
'tab.models': 'Models',
|
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { readFile, stat } from 'node:fs/promises'
|
|
|
12
12
|
import { isAbsolute, join, resolve } from 'node:path'
|
|
13
13
|
|
|
14
14
|
import { createActions, humanizeError } from './lib/actions.mjs'
|
|
15
|
-
import { createApiHandler } from './lib/http.mjs'
|
|
15
|
+
import { createApiHandler, loopbackAdmission } from './lib/http.mjs'
|
|
16
16
|
import { createStateStore } from './lib/state.mjs'
|
|
17
17
|
|
|
18
18
|
export const name = 'dsh-sendcomfy'
|
|
@@ -66,7 +66,48 @@ export function apply(ctx) {
|
|
|
66
66
|
const actions = createActions({ store, logger })
|
|
67
67
|
|
|
68
68
|
/* ── 1. 浏览器面板 API ─────────────────────────────────────── */
|
|
69
|
-
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 取 DSH 的 `connection` 服务(浏览器登录态 + Host/Origin 栅栏的持有者)。
|
|
72
|
+
* 懒取:它可能在本插件激活之后才装好;拿不到就退回本机回环栅栏。
|
|
73
|
+
*/
|
|
74
|
+
function connectionService() {
|
|
75
|
+
const usable = (value) => (value && typeof value.requestRejection === 'function' ? value : undefined)
|
|
76
|
+
try {
|
|
77
|
+
const direct = usable(ctx.connection)
|
|
78
|
+
if (direct) return direct
|
|
79
|
+
} catch {
|
|
80
|
+
/* 服务未定义 */
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
if (typeof ctx.get === 'function') return usable(ctx.get('connection'))
|
|
84
|
+
} catch {
|
|
85
|
+
/* 服务未注册 */
|
|
86
|
+
}
|
|
87
|
+
return undefined
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 准入检查:每条 /api/sendcomfy/* 请求在处理前先过这一关。
|
|
92
|
+
* 有 `connection` 时用它的 `requestRejection`(Host/Origin 栅栏 + 浏览器登录态,
|
|
93
|
+
* 与官方插件同一套口径);没有时退回 `loopbackAdmission`(只放行回环 Host、
|
|
94
|
+
* 同源 Origin)。宁可误拒也不放行未鉴权调用 —— 这些路由能改配置、触发跑图。
|
|
95
|
+
*/
|
|
96
|
+
function admit(req) {
|
|
97
|
+
const connection = connectionService()
|
|
98
|
+
if (connection) {
|
|
99
|
+
try {
|
|
100
|
+
const rejection = connection.requestRejection({ headers: (req && req.headers) || {} })
|
|
101
|
+
return rejection === 401 || rejection === 403 ? rejection : undefined
|
|
102
|
+
} catch (error) {
|
|
103
|
+
logger('准入检查抛错,按拒绝处理:', error?.message || error)
|
|
104
|
+
return 403
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return loopbackAdmission(req)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const handler = createApiHandler(actions, { prefix: ROUTE_PREFIX, admit })
|
|
70
111
|
ctx.effect(
|
|
71
112
|
() => ctx.webServer.register({
|
|
72
113
|
kind: 'prefix',
|
package/lib/http.mjs
CHANGED
|
@@ -114,12 +114,58 @@ function truthyQuery(value) {
|
|
|
114
114
|
return ['1', 'true', 'yes', 'on'].includes(String(value || '').toLowerCase())
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/** 回环主机名(Host 头去掉端口后的小写形式)。 */
|
|
118
|
+
const LOOPBACK_HOSTNAMES = new Set(['127.0.0.1', 'localhost', '[::1]', '::1', '[::ffff:127.0.0.1]'])
|
|
119
|
+
|
|
120
|
+
function hostnameOf(authority) {
|
|
121
|
+
const text = String(authority || '').trim().toLowerCase()
|
|
122
|
+
if (text.startsWith('[')) return text.slice(0, text.indexOf(']') + 1)
|
|
123
|
+
return text.replace(/:\d+$/, '')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function isLoopbackHostname(hostname) {
|
|
127
|
+
return LOOPBACK_HOSTNAMES.has(hostname) || /^127\.\d+\.\d+\.\d+$/.test(hostname)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 本机回环栅栏 —— 在没有 DSH `connection` 服务可用时的兜底准入检查。
|
|
132
|
+
*
|
|
133
|
+
* 规则(比 connection 的弱,但挡住主要的两种攻击):
|
|
134
|
+
* 1. `Host` 必须是回环地址,挡住 DNS rebinding(把 evil.com 解析到 127.0.0.1);
|
|
135
|
+
* 2. 若带 `Origin`,必须与 `Host` 同源,挡住别的网页对我们发起跨站请求;
|
|
136
|
+
* `Origin: null`(sandbox iframe / file://)一律拒绝。
|
|
137
|
+
*
|
|
138
|
+
* 拿到 `connection` 服务时不会走到这里 —— 那条路径额外带浏览器登录态校验。
|
|
139
|
+
*
|
|
140
|
+
* @param {import('node:http').IncomingMessage} req
|
|
141
|
+
* @returns {403 | undefined} 拒绝状态码,或 undefined 表示放行
|
|
142
|
+
*/
|
|
143
|
+
export function loopbackAdmission(req) {
|
|
144
|
+
const headers = (req && req.headers) || {}
|
|
145
|
+
const host = String(headers.host || '')
|
|
146
|
+
if (!isLoopbackHostname(hostnameOf(host))) return 403
|
|
147
|
+
const origin = headers.origin
|
|
148
|
+
if (origin === undefined || origin === '') return undefined
|
|
149
|
+
if (String(origin).toLowerCase() === 'null') return 403
|
|
150
|
+
try {
|
|
151
|
+
const originAuthority = new URL(String(origin)).host
|
|
152
|
+
return originAuthority.toLowerCase() === host.toLowerCase() ? undefined : 403
|
|
153
|
+
} catch {
|
|
154
|
+
return 403
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
117
158
|
/**
|
|
118
159
|
* @param {ReturnType<import('./actions.mjs').createActions>} actions
|
|
119
|
-
* @param {{
|
|
160
|
+
* @param {{
|
|
161
|
+
* prefix?: string,
|
|
162
|
+
* admit?: (req: import('node:http').IncomingMessage) => (401 | 403 | undefined),
|
|
163
|
+
* }} [options]
|
|
164
|
+
* `admit` 是准入检查:返回 401/403 表示拒绝,返回 undefined 表示放行。
|
|
165
|
+
* 不给时不做检查(仅供测试与无宿主场景),Host 插件总会传一个。
|
|
120
166
|
* @returns {(req: import('node:http').IncomingMessage, res: import('node:http').ServerResponse) => Promise<void>}
|
|
121
167
|
*/
|
|
122
|
-
export function createApiHandler(actions, { prefix = DEFAULT_PREFIX } = {}) {
|
|
168
|
+
export function createApiHandler(actions, { prefix = DEFAULT_PREFIX, admit } = {}) {
|
|
123
169
|
return async function handle(req, res) {
|
|
124
170
|
if (!req || !res) return
|
|
125
171
|
const startedAt = Date.now()
|
|
@@ -150,6 +196,23 @@ export function createApiHandler(actions, { prefix = DEFAULT_PREFIX } = {}) {
|
|
|
150
196
|
} catch {
|
|
151
197
|
/* 诊断失败不影响请求 */
|
|
152
198
|
}
|
|
199
|
+
// 准入检查必须在任何路由分发之前:所有 /api/sendcomfy/* 都能读到配置、
|
|
200
|
+
// 触发 ComfyUI 生成、上传图片,未鉴权的请求一条也不该被处理。
|
|
201
|
+
if (typeof admit === 'function') {
|
|
202
|
+
let rejection
|
|
203
|
+
try {
|
|
204
|
+
rejection = admit(req)
|
|
205
|
+
} catch {
|
|
206
|
+
rejection = 403
|
|
207
|
+
}
|
|
208
|
+
if (rejection === 401 || rejection === 403) {
|
|
209
|
+
sendJson(res, rejection, {
|
|
210
|
+
ok: false,
|
|
211
|
+
error: '请求未通过 DSH 准入检查(Host/Origin 栅栏或浏览器登录态)',
|
|
212
|
+
})
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
}
|
|
153
216
|
let url
|
|
154
217
|
try {
|
|
155
218
|
url = new URL(req.url || '/', 'http://127.0.0.1')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sendcomfy",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ComfyUI bridge plugin for DeepSeek Harness (DSH): browse ComfyUI server workflows and models from the sidebar, and let the session model pick, parametrize, and run workflows on demand — no import step.",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"LICENSE"
|
|
28
28
|
],
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=22"
|
|
30
|
+
"node": ">=22",
|
|
31
|
+
"dsh": ">=0.2.2-rc.5"
|
|
31
32
|
},
|
|
32
33
|
"dsh": {
|
|
33
34
|
"bundle": {
|