comfy-ts 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +4 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-CVu39RNd.js → run-serve-D1Tsuru9.js} +172 -12
- package/dist/run-serve-D1Tsuru9.js.map +1 -0
- package/dist/{run-tui-idFhdO4f.js → run-tui-JxlEbb_f.js} +3 -3
- package/dist/{run-tui-idFhdO4f.js.map → run-tui-JxlEbb_f.js.map} +1 -1
- package/dist/serve-web.js +15 -22
- package/dist/{state-C90kdjtB.js → state-CaHeDL-0.js} +6 -2
- package/dist/{state-C90kdjtB.js.map → state-CaHeDL-0.js.map} +1 -1
- package/dist/web.d.ts +3 -0
- package/dist/web.js +5 -1
- package/dist/web.js.map +1 -1
- package/examples/web/tsconfig.json +4 -1
- package/package.json +1 -1
- package/src/cli/comfy-ts-cli.ts +1 -1
- package/src/cli/serve/ServeApp.ts +76 -8
- package/src/cli/serve/promptEnhancers.ts +69 -0
- package/src/cli/serve/run-serve.ts +38 -6
- package/src/cli/serve/safeName.ts +12 -0
- package/src/cli/serve/web/api.ts +23 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +76 -32
- package/src/cli/serve/web/components/VarsForm.tsx +11 -0
- package/src/cli/serve/web/llm.ts +254 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +268 -157
- package/src/cli/serve/web/state/FormSt.ts +4 -1
- package/src/cli/serve/web/state/WebSt.ts +26 -1
- package/src/cli/serve/web/styles.ts +2 -0
- package/src/state.ts +6 -0
- package/dist/run-serve-CVu39RNd.js.map +0 -1
- package/src/cli/serve/web/openrouter.ts +0 -142
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
"src/*": ["../../src/*"],
|
|
10
10
|
"comfy-ts": ["../../src/index.ts"],
|
|
11
11
|
"comfy-ts/web": ["../../src/web.ts"]
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
// its own incremental cache: a shared one across configs with different include
|
|
14
|
+
// sets makes a typecheck fail on a symbol that exists (tests/tsconfig-buildinfo)
|
|
15
|
+
"tsBuildInfoFile": "../../node_modules/.cache/tsbuildinfo-examples-web.json"
|
|
13
16
|
},
|
|
14
17
|
"include": [".", "../../src"]
|
|
15
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"comfyui",
|
package/src/cli/comfy-ts-cli.ts
CHANGED
|
@@ -31,7 +31,7 @@ Usage:
|
|
|
31
31
|
host.defineWorkflow(...)); no arg scans cwd + the examples bundled
|
|
32
32
|
with comfy-ts, an explicit dir/file limits to it (file preselected)
|
|
33
33
|
|
|
34
|
-
comfy-ts serve [dir | workflow-module.ts] [--port 8288] [--
|
|
34
|
+
comfy-ts serve [dir | workflow-module.ts] [--port 8288] [--host 127.0.0.1]
|
|
35
35
|
drafts as a local HTTP generation API: POST /generate/<module>/<draft>
|
|
36
36
|
with { ...vars } overriding the draft's values (blocking; raw image
|
|
37
37
|
bytes under Accept: image/*), GET /drafts self-describes every var,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// `comfy-ts serve` request handling, transport-free: run-serve owns node:http,
|
|
2
2
|
// tests call handle() directly with an injected starter. Full contract:
|
|
3
3
|
// agent/architecture.md item 12.
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
5
5
|
import { nanoid } from 'nanoid'
|
|
6
6
|
import { basename, dirname, extname, join, resolve } from 'pathe'
|
|
7
7
|
import { applyVarPayload } from 'src/cli/serve/applyVarPayload.ts'
|
|
8
8
|
import { describeVar, type VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
9
|
+
import { deletePromptEnhancer, listPromptEnhancers, writePromptEnhancer } from 'src/cli/serve/promptEnhancers.ts'
|
|
10
|
+
import { validStoreName } from 'src/cli/serve/safeName.ts'
|
|
9
11
|
import { draftsDirForFile, listDraftsForFile } from 'src/cli/tui/state/DraftsSt.ts'
|
|
10
12
|
import {
|
|
11
13
|
getLoraDisplayName,
|
|
@@ -79,10 +81,13 @@ const USAGE = [
|
|
|
79
81
|
'POST /generate/<module>/<draft> with { ...vars } — run, blocking',
|
|
80
82
|
'POST /generate/<draft> — unqualified, when unambiguous',
|
|
81
83
|
'PUT /drafts/<module>/<draft> with { ...vars } — save (or duplicate to a new name) a draft',
|
|
84
|
+
'DELETE /drafts/<module>/<draft> — delete that draft file',
|
|
82
85
|
'GET /run/<module> — live run status · /run/<module>/preview — latent preview bytes',
|
|
83
86
|
'POST /upload with {"name","dataBase64"} — store a browser file for an image var',
|
|
84
87
|
'GET /lora-info/<hostId>/<lora> — display name + trigger words (local mirror)',
|
|
85
88
|
'GET /lora-preview/<hostId>/<lora> — preview image bytes',
|
|
89
|
+
'GET /prompt-enhancers — the web ui master prompts (.comfy-ts/prompt-enhancers/*.md)',
|
|
90
|
+
'PUT /prompt-enhancers/<name> with {"text"} — write one · DELETE /prompt-enhancers/<name> — remove it',
|
|
86
91
|
'GET /outputs/<path> — generated files',
|
|
87
92
|
]
|
|
88
93
|
|
|
@@ -164,6 +169,7 @@ export class ServeApp {
|
|
|
164
169
|
return this.replyLoraInfo(segs[1], segs[2])
|
|
165
170
|
if (segs[0] === 'lora-preview' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
166
171
|
return await this.replyLoraPreview(segs[1], segs[2])
|
|
172
|
+
if (segs[0] === 'prompt-enhancers' && segs.length === 1) return this.replyPromptEnhancers()
|
|
167
173
|
if (segs[0] === 'outputs') return this.replyOutput(segs.slice(1))
|
|
168
174
|
return json(404, { error: `no route: GET ${path}`, usage: USAGE })
|
|
169
175
|
}
|
|
@@ -175,6 +181,12 @@ export class ServeApp {
|
|
|
175
181
|
if (req.method === 'POST' && segs[0] === 'upload' && segs.length === 1) return this.replyUpload(req)
|
|
176
182
|
if (req.method === 'PUT' && segs[0] === 'drafts' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
177
183
|
return await this.replySaveDraft(segs[1], segs[2], req)
|
|
184
|
+
if (req.method === 'DELETE' && segs[0] === 'drafts' && segs.length === 3 && segs[1] != null && segs[2] != null)
|
|
185
|
+
return await this.replyDeleteDraft(segs[1], segs[2])
|
|
186
|
+
if (req.method === 'PUT' && segs[0] === 'prompt-enhancers' && segs.length === 2 && segs[1] != null)
|
|
187
|
+
return this.replySavePromptEnhancer(segs[1], req)
|
|
188
|
+
if (req.method === 'DELETE' && segs[0] === 'prompt-enhancers' && segs.length === 2 && segs[1] != null)
|
|
189
|
+
return this.replyDeletePromptEnhancer(segs[1])
|
|
178
190
|
return json(404, { error: `no route: ${req.method} ${path}`, usage: USAGE })
|
|
179
191
|
} catch (e) {
|
|
180
192
|
console.error('[serve] request crashed:', e)
|
|
@@ -192,14 +204,10 @@ export class ServeApp {
|
|
|
192
204
|
return ['default', ...onDisk.filter((n) => n !== 'default')]
|
|
193
205
|
}
|
|
194
206
|
|
|
195
|
-
/** THE draft-name gate, shared by every route that turns a url segment into a path
|
|
196
|
-
*
|
|
197
|
-
* count still looks right — an unguarded reader would read (and RUN) any json on disk */
|
|
207
|
+
/** THE draft-name gate, shared by every route that turns a url segment into a path
|
|
208
|
+
* (safeName.ts owns the rule — the prompt-enhancer routes call the same function) */
|
|
198
209
|
private validDraftName(raw: string): string | null {
|
|
199
|
-
|
|
200
|
-
// length cap: past it the fs answers ENAMETOOLONG as a raw 500
|
|
201
|
-
if (name.length > 100) return null
|
|
202
|
-
return /^[\w][\w .-]*$/.test(name) ? name : null
|
|
210
|
+
return validStoreName(raw)
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
/** absolute path of a draft file, or null when the name is not one we accept */
|
|
@@ -383,6 +391,66 @@ export class ServeApp {
|
|
|
383
391
|
return json(200, { ok: true, module: mod.key, draft, drafts: this.draftsFor(mod) })
|
|
384
392
|
}
|
|
385
393
|
|
|
394
|
+
/** delete the draft FILE. `default` is deletable like any other: the implicit `default`
|
|
395
|
+
* draft (spec values, no file) survives it, which is exactly the reset. Missing file is
|
|
396
|
+
* still a 200 — the caller asked for it to be gone, and it is */
|
|
397
|
+
private async replyDeleteDraft(modKey: string, rawDraft: string): Promise<ServeReply> {
|
|
398
|
+
const mod = this.moduleByKey(modKey)
|
|
399
|
+
if (mod == null) return json(404, { error: `unknown module '${modKey}'` })
|
|
400
|
+
const path = this.draftPath(mod, rawDraft)
|
|
401
|
+
if (path == null) return json(400, { error: `invalid draft name '${rawDraft}'` })
|
|
402
|
+
await this.exclusive(mod.key, () => {
|
|
403
|
+
if (existsSync(path)) rmSync(path)
|
|
404
|
+
return Promise.resolve()
|
|
405
|
+
})
|
|
406
|
+
console.log(`[serve] draft deleted: ${mod.key}/${rawDraft.trim()}`)
|
|
407
|
+
return json(200, { ok: true, module: mod.key, draft: rawDraft.trim(), drafts: this.draftsFor(mod) })
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// #region prompt enhancers (the web ui's master prompts, as .md files) ------
|
|
411
|
+
/** the folder is seeded on the first read, so `refine-krea2-prompt.md` exists to be edited */
|
|
412
|
+
private replyPromptEnhancers(): ServeReply {
|
|
413
|
+
try {
|
|
414
|
+
return json(200, { enhancers: listPromptEnhancers() })
|
|
415
|
+
} catch (e) {
|
|
416
|
+
return json(500, { error: `prompt-enhancers folder unreadable: ${extractErrorMessage(e)}` })
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private replySavePromptEnhancer(rawName: string, req: ServeRequest): ServeReply {
|
|
421
|
+
const name = validStoreName(rawName)
|
|
422
|
+
if (name == null)
|
|
423
|
+
return json(400, { error: `invalid enhancer name '${rawName}' — letters/digits then letters, digits, ". -_"` })
|
|
424
|
+
let parsed: unknown
|
|
425
|
+
try {
|
|
426
|
+
parsed = JSON.parse(req.body ?? '')
|
|
427
|
+
} catch (e) {
|
|
428
|
+
return json(400, { error: `body is not valid json: ${extractErrorMessage(e)}` })
|
|
429
|
+
}
|
|
430
|
+
if (parsed == null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
431
|
+
return json(400, { error: 'body must be { "text": "<master prompt>" }' })
|
|
432
|
+
const text = (parsed as Record<string, unknown>).text
|
|
433
|
+
if (typeof text !== 'string') return json(400, { error: 'body must be { "text": "<master prompt>" }' })
|
|
434
|
+
try {
|
|
435
|
+
writePromptEnhancer(name, text)
|
|
436
|
+
} catch (e) {
|
|
437
|
+
return json(500, { error: `could not write enhancer '${name}': ${extractErrorMessage(e)}` })
|
|
438
|
+
}
|
|
439
|
+
return json(200, { ok: true, name, enhancers: listPromptEnhancers() })
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
private replyDeletePromptEnhancer(rawName: string): ServeReply {
|
|
443
|
+
const name = validStoreName(rawName)
|
|
444
|
+
if (name == null) return json(400, { error: `invalid enhancer name '${rawName}'` })
|
|
445
|
+
try {
|
|
446
|
+
deletePromptEnhancer(name)
|
|
447
|
+
} catch (e) {
|
|
448
|
+
return json(500, { error: `could not delete enhancer '${name}': ${extractErrorMessage(e)}` })
|
|
449
|
+
}
|
|
450
|
+
console.log(`[serve] prompt enhancer deleted: ${name}`)
|
|
451
|
+
return json(200, { ok: true, name, enhancers: listPromptEnhancers() })
|
|
452
|
+
}
|
|
453
|
+
|
|
386
454
|
// #region live run state (web ui polling: progress + latent preview) --------
|
|
387
455
|
private liveRuns = new Map<string, ServeExecution>()
|
|
388
456
|
/** seq counts frames so the poller refetches only on a NEW one, not every tick */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// the master prompts of the web ui's prompt enhancer, as FILES:
|
|
2
|
+
// `.comfy-ts/prompt-enhancers/<name>.md`, the drafts model applied to prose.
|
|
3
|
+
// Markdown, not json: these are hand-edited paragraphs, and a json string field
|
|
4
|
+
// would be one escaped line. The FILENAME is the identity (a rename is a write
|
|
5
|
+
// plus a delete); validStoreName is the same gate the draft routes use.
|
|
6
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
7
|
+
import { join } from 'pathe'
|
|
8
|
+
import { validStoreName } from 'src/cli/serve/safeName.ts'
|
|
9
|
+
|
|
10
|
+
const EXT = '.md'
|
|
11
|
+
|
|
12
|
+
export type PromptEnhancer = { name: string; text: string }
|
|
13
|
+
|
|
14
|
+
export function promptEnhancersDir(): string {
|
|
15
|
+
return comfyts.resolveFromPromptEnhancers('')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function promptEnhancerPath(name: string): string | null {
|
|
19
|
+
const safe = validStoreName(name)
|
|
20
|
+
return safe == null ? null : join(promptEnhancersDir(), `${safe}${EXT}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** the shipped starting point. It is a FILE from the first read on, so it can be edited
|
|
24
|
+
* on disk like everything else — the browser ships no copy of this text */
|
|
25
|
+
const SEED: PromptEnhancer = {
|
|
26
|
+
name: 'refine-krea2-prompt',
|
|
27
|
+
text: `You rewrite image prompts for krea2 turbo, a distilled 8 step text to image model whose text encoder reads flowing natural language, not tag soup, and which is steered by adjectives rather than by negatives.
|
|
28
|
+
|
|
29
|
+
Rewrite the user's prompt into ONE dense paragraph someone could picture with their eyes closed:
|
|
30
|
+
- keep every noun and every named subject the user wrote, they are the point
|
|
31
|
+
- add what is missing to make it fun to look at: lighting, palette, material, texture, camera angle, composition, mood
|
|
32
|
+
- prefer concrete visual nouns over praise, never write "masterpiece", "8k", "highly detailed", "award winning"
|
|
33
|
+
- stay under about 80 words, no lists, no headings, no quotes around the result
|
|
34
|
+
- keep any "// " comment line and any "- " negative line from the input verbatim, each on its own line
|
|
35
|
+
|
|
36
|
+
Answer with the rewritten prompt and nothing else: no preamble, no explanation.
|
|
37
|
+
`,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** seeds ONCE, on an absent folder. A folder he emptied on purpose stays empty */
|
|
41
|
+
export function listPromptEnhancers(): PromptEnhancer[] {
|
|
42
|
+
const dir = promptEnhancersDir()
|
|
43
|
+
if (!existsSync(dir)) writePromptEnhancer(SEED.name, SEED.text)
|
|
44
|
+
if (!existsSync(dir)) return []
|
|
45
|
+
const out: PromptEnhancer[] = []
|
|
46
|
+
for (const file of readdirSync(dir).sort()) {
|
|
47
|
+
if (!file.endsWith(EXT)) continue
|
|
48
|
+
const name = file.slice(0, -EXT.length)
|
|
49
|
+
if (validStoreName(name) == null) continue
|
|
50
|
+
out.push({ name, text: readFileSync(join(dir, file), 'utf8') })
|
|
51
|
+
}
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function writePromptEnhancer(name: string, text: string): string | null {
|
|
56
|
+
const path = promptEnhancerPath(name)
|
|
57
|
+
if (path == null) return null
|
|
58
|
+
mkdirSync(promptEnhancersDir(), { recursive: true })
|
|
59
|
+
writeFileSync(path, text)
|
|
60
|
+
return path
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** a missing file is still a success: the caller asked for it to be gone, and it is */
|
|
64
|
+
export function deletePromptEnhancer(name: string): boolean {
|
|
65
|
+
const path = promptEnhancerPath(name)
|
|
66
|
+
if (path == null) return false
|
|
67
|
+
if (existsSync(path)) rmSync(path)
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// `comfy-ts serve [dir | module.cflow.ts] [--port N] [--
|
|
1
|
+
// `comfy-ts serve [dir | module.cflow.ts] [--port N] [--host ADDR]`
|
|
2
2
|
// drafts as a local HTTP generation API — agent/architecture.md item 12
|
|
3
3
|
import { statSync } from 'node:fs'
|
|
4
4
|
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
|
|
5
|
+
import { networkInterfaces } from 'node:os'
|
|
5
6
|
import { pathToFileURL } from 'node:url'
|
|
6
7
|
import { resolve } from 'pathe'
|
|
7
8
|
import { scanCflowFiles } from 'src/cli/tui/discoverWorkflows.ts'
|
|
@@ -15,7 +16,7 @@ import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
|
15
16
|
const DEFAULT_PORT = 8288
|
|
16
17
|
const BODY_CAP = 10_000_000
|
|
17
18
|
|
|
18
|
-
function parseArgs(args: string[]): { target?: string; port: number; bind: string } | { error: string } {
|
|
19
|
+
export function parseArgs(args: string[]): { target?: string; port: number; bind: string } | { error: string } {
|
|
19
20
|
let target: string | undefined
|
|
20
21
|
let port = DEFAULT_PORT
|
|
21
22
|
let bind = '127.0.0.1'
|
|
@@ -25,9 +26,10 @@ function parseArgs(args: string[]): { target?: string; port: number; bind: strin
|
|
|
25
26
|
const n = Number(args[++i])
|
|
26
27
|
if (!Number.isInteger(n) || n <= 0 || n > 65535) return { error: `--port expects 1..65535, got '${args[i]}'` }
|
|
27
28
|
port = n
|
|
28
|
-
} else if (a === '--bind') {
|
|
29
|
+
} else if (a === '--host' || a === '--bind') {
|
|
30
|
+
// --host is the spelling; --bind stays an alias so an old command line keeps working
|
|
29
31
|
const b = args[++i]
|
|
30
|
-
if (b == null) return { error:
|
|
32
|
+
if (b == null) return { error: `${a} expects an address (0.0.0.0 to reach it from another machine)` }
|
|
31
33
|
bind = b
|
|
32
34
|
} else if (a != null && a.startsWith('--')) return { error: `unknown flag '${a}'` }
|
|
33
35
|
else if (a != null) {
|
|
@@ -44,7 +46,7 @@ export function makeRequestListener(app: ServeApp): (req: IncomingMessage, res:
|
|
|
44
46
|
// local bridge, no auth by design: open CORS so browser frontends can call it
|
|
45
47
|
const cors = {
|
|
46
48
|
'access-control-allow-origin': '*',
|
|
47
|
-
'access-control-allow-methods': 'GET, POST, PUT, OPTIONS',
|
|
49
|
+
'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
|
48
50
|
'access-control-allow-headers': 'content-type, accept',
|
|
49
51
|
}
|
|
50
52
|
const chunks: Buffer[] = []
|
|
@@ -148,11 +150,41 @@ export async function runServe(args: string[]): Promise<number> {
|
|
|
148
150
|
})
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
export type Nic = { address: string; family: string | number; internal: boolean }
|
|
154
|
+
|
|
155
|
+
/** the addresses this bind actually answers on. `0.0.0.0` means every interface, so printing
|
|
156
|
+
* only that back is useless: the LAN ip and the tailnet 100.x are the urls a phone can open */
|
|
157
|
+
export function reachableAddresses(bind: string, nics: Record<string, Nic[] | undefined>): string[] {
|
|
158
|
+
if (bind !== '0.0.0.0' && bind !== '::') return [bind]
|
|
159
|
+
const found: string[] = []
|
|
160
|
+
for (const list of Object.values(nics)) {
|
|
161
|
+
for (const nic of list ?? []) {
|
|
162
|
+
// node reports family as 'IPv4' or 4 depending on the version
|
|
163
|
+
if (nic.internal || (nic.family !== 'IPv4' && nic.family !== 4)) continue
|
|
164
|
+
found.push(nic.address)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return ['127.0.0.1', ...found]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** 100.64.0.0/10 is the CGNAT range tailscale hands out — worth naming, it is the one he wants */
|
|
171
|
+
function addressNote(addr: string): string {
|
|
172
|
+
const octets = addr.split('.').map(Number)
|
|
173
|
+
const second = octets[1] ?? 0
|
|
174
|
+
return octets[0] === 100 && second >= 64 && second <= 127 ? ' (tailnet)' : ''
|
|
175
|
+
}
|
|
176
|
+
|
|
151
177
|
function printStartup(app: ServeApp, bind: string, port: number): void {
|
|
152
178
|
const base = `http://${bind}:${port}`
|
|
153
179
|
console.log(`comfy-ts serve · ${app.modules.length} workflow(s) · ${base}/`)
|
|
154
|
-
if (bind !== '127.0.0.1' && bind !== 'localhost')
|
|
180
|
+
if (bind !== '127.0.0.1' && bind !== 'localhost') {
|
|
155
181
|
console.log(`⚠️ bound to ${bind} — this API has NO AUTH and runs workflows on your ComfyUI host`)
|
|
182
|
+
const urls = reachableAddresses(bind, networkInterfaces())
|
|
183
|
+
if (urls.length > 1) {
|
|
184
|
+
console.log('reachable at:')
|
|
185
|
+
for (const addr of urls) console.log(` http://${addr}:${port}/${addressNote(addr)}`)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
156
188
|
for (const mod of app.modules) {
|
|
157
189
|
console.log(`\n${mod.key} (host: ${mod.dw.host.data.id})`)
|
|
158
190
|
for (const draft of app.draftsFor(mod))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// THE name gate for every serve route that turns a url segment into a file path.
|
|
2
|
+
// SECURITY-CRITICAL and deliberately shared: handle() decodes per segment, so
|
|
3
|
+
// `%2F` arrives as a real `/` while the segment count still looks right. One
|
|
4
|
+
// function, because a second regex somewhere else is a second traversal hole.
|
|
5
|
+
|
|
6
|
+
/** the accepted name, or null. Rejects traversal, absolute paths, leading dots and empties */
|
|
7
|
+
export function validStoreName(raw: string): string | null {
|
|
8
|
+
const name = raw.trim()
|
|
9
|
+
// length cap: past it the fs answers ENAMETOOLONG as a raw 500
|
|
10
|
+
if (name.length > 100) return null
|
|
11
|
+
return /^[\w][\w .-]*$/.test(name) ? name : null
|
|
12
|
+
}
|
package/src/cli/serve/web/api.ts
CHANGED
|
@@ -66,6 +66,10 @@ export function saveDraft(
|
|
|
66
66
|
})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
export function deleteDraft(p: { module: string; draft: string }): Promise<{ ok: true; drafts: string[] }> {
|
|
70
|
+
return jsonFetch(`/drafts/${encodeURIComponent(p.module)}/${encodeURIComponent(p.draft)}`, { method: 'DELETE' })
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
export type RunStatus = {
|
|
70
74
|
running: boolean
|
|
71
75
|
status: string
|
|
@@ -93,6 +97,25 @@ export function loraPreviewSrc(p: { host: string; name: string }): string {
|
|
|
93
97
|
return `/lora-preview/${encodeURIComponent(p.host)}/${encodeURIComponent(p.name)}`
|
|
94
98
|
}
|
|
95
99
|
|
|
100
|
+
/** master prompts of the enhancer, files under `.comfy-ts/prompt-enhancers/` (server-owned) */
|
|
101
|
+
export type PromptEnhancer = { name: string; text: string }
|
|
102
|
+
|
|
103
|
+
export function fetchPromptEnhancers(): Promise<{ enhancers: PromptEnhancer[] }> {
|
|
104
|
+
return jsonFetch('/prompt-enhancers')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function savePromptEnhancer(p: PromptEnhancer): Promise<{ ok: true; enhancers: PromptEnhancer[] }> {
|
|
108
|
+
return jsonFetch(`/prompt-enhancers/${encodeURIComponent(p.name)}`, {
|
|
109
|
+
method: 'PUT',
|
|
110
|
+
headers: { 'content-type': 'application/json' },
|
|
111
|
+
body: JSON.stringify({ text: p.text }),
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function deletePromptEnhancer(p: { name: string }): Promise<{ ok: true; enhancers: PromptEnhancer[] }> {
|
|
116
|
+
return jsonFetch(`/prompt-enhancers/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
|
|
117
|
+
}
|
|
118
|
+
|
|
96
119
|
export async function uploadFile(p: { file: File }): Promise<{ path: string; url: string | null }> {
|
|
97
120
|
const bytes = new Uint8Array(await p.file.arrayBuffer())
|
|
98
121
|
let bin = ''
|
|
@@ -2,25 +2,47 @@
|
|
|
2
2
|
// a library of named master prompts. Nothing touches the var until APPLY.
|
|
3
3
|
import { observer } from 'mobx-react-lite'
|
|
4
4
|
import { useEffect } from 'react'
|
|
5
|
-
import type { ReasoningEffort } from 'src/cli/serve/web/
|
|
6
|
-
import type
|
|
5
|
+
import type { ProviderId, ReasoningEffort } from 'src/cli/serve/web/llm.ts'
|
|
6
|
+
import { PROVIDERS, type EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
|
|
7
7
|
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
8
8
|
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
9
9
|
|
|
10
10
|
const EFFORTS: ReasoningEffort[] = ['off', 'low', 'medium', 'high']
|
|
11
11
|
|
|
12
|
+
const PROVIDER_LABEL: Record<ProviderId, string> = {
|
|
13
|
+
openrouter: 'openrouter (cloud)',
|
|
14
|
+
openwebui: 'open webui (local)',
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
const Settings = observer(function Settings(p: { e: EnhancerSt }) {
|
|
13
18
|
const models = p.e.visibleModels
|
|
19
|
+
const local = p.e.provider === 'openwebui'
|
|
14
20
|
return (
|
|
15
21
|
<div>
|
|
16
|
-
<div className="section-title">
|
|
22
|
+
<div className="section-title">provider · keys stay in this browser</div>
|
|
17
23
|
<div className="enh-row">
|
|
24
|
+
<select value={p.e.provider} onChange={(ev) => p.e.setProvider(ev.target.value)}>
|
|
25
|
+
{PROVIDERS.map((id) => (
|
|
26
|
+
<option key={id} value={id}>
|
|
27
|
+
{PROVIDER_LABEL[id]}
|
|
28
|
+
</option>
|
|
29
|
+
))}
|
|
30
|
+
</select>
|
|
31
|
+
{local ? (
|
|
32
|
+
<input
|
|
33
|
+
type="text"
|
|
34
|
+
placeholder="http://localhost:3000"
|
|
35
|
+
value={p.e.baseUrl}
|
|
36
|
+
onChange={(ev) => p.e.setBaseUrl(ev.target.value)}
|
|
37
|
+
style={{ flex: 1, minWidth: 180 }}
|
|
38
|
+
/>
|
|
39
|
+
) : null}
|
|
18
40
|
<input
|
|
19
41
|
type="password"
|
|
20
|
-
placeholder=
|
|
42
|
+
placeholder={local ? 'open webui api key (blank if none)' : 'sk-or-v1-… (localStorage only)'}
|
|
21
43
|
value={p.e.apiKey}
|
|
22
44
|
onChange={(ev) => p.e.setApiKey(ev.target.value)}
|
|
23
|
-
style={{ flex: 1, minWidth:
|
|
45
|
+
style={{ flex: 1, minWidth: 160 }}
|
|
24
46
|
/>
|
|
25
47
|
<button type="button" onClick={() => void p.e.loadModels()} disabled={p.e.modelsState === 'loading'}>
|
|
26
48
|
{p.e.modelsState === 'loading' ? 'loading…' : 'load models'}
|
|
@@ -42,27 +64,34 @@ const Settings = observer(function Settings(p: { e: EnhancerSt }) {
|
|
|
42
64
|
) : (
|
|
43
65
|
<input
|
|
44
66
|
type="text"
|
|
45
|
-
placeholder=
|
|
67
|
+
placeholder={local ? 'model id, e.g. qwen3:8b' : 'model id, e.g. anthropic/claude-sonnet-5'}
|
|
46
68
|
value={p.e.model}
|
|
47
69
|
onChange={(ev) => p.e.setModel(ev.target.value)}
|
|
48
70
|
style={{ flex: 1 }}
|
|
49
71
|
/>
|
|
50
72
|
)}
|
|
51
|
-
<label className="row-inline" title="
|
|
73
|
+
<label className="row-inline" title="hide models that report no reasoning support">
|
|
52
74
|
<input type="checkbox" checked={p.e.thinkingOnly} onChange={() => p.e.toggleThinkingOnly()} />
|
|
53
75
|
<span className="hint">thinking only</span>
|
|
54
76
|
</label>
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
{x}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
{local ? null : (
|
|
78
|
+
<label className="row-inline" title="reasoning effort sent to the model">
|
|
79
|
+
<span className="hint">effort</span>
|
|
80
|
+
<select value={p.e.effort} onChange={(ev) => p.e.setEffort(ev.target.value)}>
|
|
81
|
+
{EFFORTS.map((x) => (
|
|
82
|
+
<option key={x} value={x}>
|
|
83
|
+
{x}
|
|
84
|
+
</option>
|
|
85
|
+
))}
|
|
86
|
+
</select>
|
|
87
|
+
</label>
|
|
88
|
+
)}
|
|
65
89
|
</div>
|
|
90
|
+
{local ? (
|
|
91
|
+
<div className="hint">
|
|
92
|
+
a local model's <think> block is routed to the thinking pane, never into your prompt
|
|
93
|
+
</div>
|
|
94
|
+
) : null}
|
|
66
95
|
{p.e.modelsError !== '' ? <div className="error">🔴 {p.e.modelsError}</div> : null}
|
|
67
96
|
</div>
|
|
68
97
|
)
|
|
@@ -70,22 +99,40 @@ const Settings = observer(function Settings(p: { e: EnhancerSt }) {
|
|
|
70
99
|
|
|
71
100
|
const MasterPrompt = observer(function MasterPrompt(p: { e: EnhancerSt }) {
|
|
72
101
|
const preset = p.e.preset
|
|
73
|
-
if (preset == null)
|
|
102
|
+
if (preset == null) {
|
|
103
|
+
return (
|
|
104
|
+
<div>
|
|
105
|
+
<div className="section-title">master prompt</div>
|
|
106
|
+
<div className="hint">
|
|
107
|
+
{p.e.presetsState === 'loading' ? 'loading .comfy-ts/prompt-enhancers/…' : 'no master prompt yet'}
|
|
108
|
+
</div>
|
|
109
|
+
{p.e.presetsError !== '' ? <div className="error">🔴 {p.e.presetsError}</div> : null}
|
|
110
|
+
<button type="button" onClick={() => p.e.addPreset('refine-prompt')}>
|
|
111
|
+
create one
|
|
112
|
+
</button>
|
|
113
|
+
</div>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
74
116
|
const rename = (): void => {
|
|
75
|
-
const name = window.prompt('rename this master prompt', preset.name)
|
|
76
|
-
if (name != null) p.e.renamePreset(name)
|
|
117
|
+
const name = window.prompt('rename this master prompt (renames the file)', preset.name)
|
|
118
|
+
if (name != null) void p.e.renamePreset(name)
|
|
77
119
|
}
|
|
78
120
|
const create = (): void => {
|
|
79
121
|
const name = window.prompt('name the new master prompt', 'refine-<model>-prompt')
|
|
80
122
|
if (name != null) p.e.addPreset(name)
|
|
81
123
|
}
|
|
124
|
+
const remove = (): void => {
|
|
125
|
+
if (window.confirm(`delete master prompt '${preset.name}'? the .md file is removed.`)) void p.e.deletePreset()
|
|
126
|
+
}
|
|
82
127
|
return (
|
|
83
128
|
<div>
|
|
84
|
-
<div className="section-title">
|
|
129
|
+
<div className="section-title">
|
|
130
|
+
master prompt · one per image model · .comfy-ts/prompt-enhancers/{preset.name}.md
|
|
131
|
+
</div>
|
|
85
132
|
<div className="enh-row">
|
|
86
|
-
<select value={preset.
|
|
133
|
+
<select value={preset.name} onChange={(ev) => p.e.selectPreset(ev.target.value)} style={{ flex: 1 }}>
|
|
87
134
|
{p.e.presets.map((m) => (
|
|
88
|
-
<option key={m.
|
|
135
|
+
<option key={m.name} value={m.name}>
|
|
89
136
|
{m.name}
|
|
90
137
|
</option>
|
|
91
138
|
))}
|
|
@@ -99,17 +146,14 @@ const MasterPrompt = observer(function MasterPrompt(p: { e: EnhancerSt }) {
|
|
|
99
146
|
<button type="button" onClick={rename}>
|
|
100
147
|
rename
|
|
101
148
|
</button>
|
|
102
|
-
<button type="button" onClick={
|
|
149
|
+
<button type="button" onClick={remove} title="delete this master prompt file">
|
|
103
150
|
✕
|
|
104
151
|
</button>
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
>
|
|
111
|
-
restore defaults
|
|
112
|
-
</button>
|
|
152
|
+
<span className="hint">
|
|
153
|
+
{p.e.saveState === 'saving' ? 'saving…' : null}
|
|
154
|
+
{p.e.saveState === 'saved' ? 'autosaved to disk' : null}
|
|
155
|
+
{p.e.saveState === 'error' ? `🔴 save failed: ${p.e.saveError}` : null}
|
|
156
|
+
</span>
|
|
113
157
|
</div>
|
|
114
158
|
<textarea rows={8} value={preset.text} onChange={(ev) => p.e.setPresetText(ev.target.value)} />
|
|
115
159
|
</div>
|
|
@@ -136,6 +136,17 @@ export const VarsForm = observer(function VarsForm(p: { st: WebSt }) {
|
|
|
136
136
|
<button type="button" className="link" title="save these values as a new draft" onClick={duplicate}>
|
|
137
137
|
duplicate…
|
|
138
138
|
</button>
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
className="link danger"
|
|
142
|
+
title="delete this draft's file (default resets to the workflow's own values)"
|
|
143
|
+
onClick={() => {
|
|
144
|
+
if (window.confirm(`delete draft '${form.draft}' of ${form.moduleKey}? the file is removed.`))
|
|
145
|
+
void p.st.deleteDraft({ module: form.moduleKey, draft: form.draft })
|
|
146
|
+
}}
|
|
147
|
+
>
|
|
148
|
+
delete
|
|
149
|
+
</button>
|
|
139
150
|
</div>
|
|
140
151
|
{form.vars.map((v) => (
|
|
141
152
|
// keyed by DRAFT too: a draft switch must reset per-row ui state (lora filter,
|