comfy-ts 2.6.0 → 2.8.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 +22 -13
- package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
- package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
- package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
- package/dist/LogsSt-DFxzQfDc.js.map +1 -0
- package/dist/cli.js +8 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +288 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -7
- package/dist/index.d.ts +128 -7
- package/dist/index.js +286 -37
- package/dist/index.js.map +1 -1
- package/dist/run-serve-_nrvJYyt.js +1948 -0
- package/dist/run-serve-_nrvJYyt.js.map +1 -0
- package/dist/{run-tui-idFhdO4f.js → run-tui-BPw-SZYW.js} +107 -158
- package/dist/run-tui-BPw-SZYW.js.map +1 -0
- package/dist/serve-web.js +434 -81
- package/dist/{state-C90kdjtB.js → state-B-boDz-Z.js} +184 -45
- package/dist/state-B-boDz-Z.js.map +1 -0
- package/dist/web.d.ts +112 -7
- package/dist/web.js +239 -36
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/comfy-cloud/sdk.d.ts +4066 -321
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
- package/examples/web/tsconfig.json +7 -1
- package/extra/README.md +32 -0
- package/extra/comfyui-textgen-stream/README.md +35 -0
- package/extra/comfyui-textgen-stream/__init__.py +166 -0
- package/extra/scripts/fetch_text_encoder.py +137 -0
- package/package.json +6 -3
- package/src/cli/comfy-ts-cli.ts +4 -2
- package/src/cli/serve/ServeApp.ts +825 -43
- package/src/cli/serve/applyVarPayload.ts +10 -3
- package/src/cli/serve/describeVar.ts +47 -7
- package/src/cli/serve/managerOnlyLoras.ts +27 -0
- package/src/cli/serve/run-serve.ts +58 -29
- package/src/cli/serve/serveSettings.ts +86 -0
- package/src/cli/serve/startupPrint.ts +111 -0
- package/src/cli/serve/web/api.ts +120 -1
- package/src/cli/serve/web/components/App.tsx +61 -22
- package/src/cli/serve/web/components/Gallery.tsx +243 -30
- package/src/cli/serve/web/components/Icon.tsx +160 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +85 -38
- package/src/cli/serve/web/components/Sidebar.tsx +43 -19
- package/src/cli/serve/web/components/VarsForm.tsx +440 -80
- package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
- package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
- package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
- package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
- package/src/cli/serve/web/llm.ts +254 -0
- package/src/cli/serve/web/logWeb.ts +6 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +261 -157
- package/src/cli/serve/web/state/FormSt.ts +70 -18
- package/src/cli/serve/web/state/RunSt.ts +22 -1
- package/src/cli/serve/web/state/WebSt.ts +542 -13
- package/src/cli/serve/web/state/lightbox.ts +44 -0
- package/src/cli/serve/web/state/moduleTree.ts +52 -0
- package/src/cli/serve/web/state/payload.ts +44 -2
- package/src/cli/serve/web/state/urlSelection.ts +53 -0
- package/src/cli/serve/web/styles.ts +415 -57
- package/src/cli/serve/web/tsconfig.json +4 -0
- package/src/cli/tui/components/PickerOverlays.tsx +37 -0
- package/src/cli/tui/components/StatusBar.tsx +14 -1
- package/src/cli/tui/components/TuiApp.tsx +5 -2
- package/src/cli/tui/state/HostSt.ts +3 -2
- package/src/cli/tui/state/PickerSt.ts +48 -2
- package/src/cli/tui/state/TreeSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +2 -1
- package/src/coreExports.ts +8 -1
- package/src/graph/ComfyNode.ts +58 -1
- package/src/host/ComfyHost.ts +13 -2
- package/src/host/ComfyManager.ts +31 -13
- package/src/host/loraInfoCache.ts +35 -1
- package/src/host/loraManagerApi.ts +94 -0
- package/src/index.ts +2 -0
- package/src/promptEnhancers.ts +102 -0
- package/src/runner/ComfyExecution.ts +61 -6
- package/src/runner/ComfyWorkflow.ts +18 -4
- package/src/runner/ComfyWsApi.ts +3 -0
- package/src/runner/describePromptRejection.ts +34 -0
- package/src/sdk-generator/ComfySchema.ts +17 -4
- package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
- package/src/state.ts +6 -0
- package/src/utils/ansi.ts +13 -0
- package/src/utils/matchesRegex.ts +13 -0
- package/src/utils/safeName.ts +29 -0
- package/src/utils/stringMap.ts +9 -0
- package/src/vars/ComfyVars.ts +61 -10
- package/src/vars/presets.ts +17 -0
- package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
- package/dist/DraftsSt-dizp3VcC.js.map +0 -1
- package/dist/run-serve-CVu39RNd.js +0 -1002
- package/dist/run-serve-CVu39RNd.js.map +0 -1
- package/dist/run-tui-idFhdO4f.js.map +0 -1
- package/dist/state-C90kdjtB.js.map +0 -1
- package/src/cli/serve/web/openrouter.ts +0 -142
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// browser → openrouter. The second http module after api.ts, and the ONLY one
|
|
2
|
-
// that leaves this machine. The key is a parameter on every call: it lives in
|
|
3
|
-
// localStorage (EnhancerSt) and never reaches the serve process or the disk.
|
|
4
|
-
// Parsing is pure and DOM-free so tests/serve-web-enhancer.test.ts covers it.
|
|
5
|
-
|
|
6
|
-
const BASE = 'https://openrouter.ai/api/v1'
|
|
7
|
-
|
|
8
|
-
export type OpenRouterModel = { id: string; name: string; reasoning: boolean }
|
|
9
|
-
|
|
10
|
-
export type ReasoningEffort = 'off' | 'low' | 'medium' | 'high'
|
|
11
|
-
|
|
12
|
-
/** an external api drifts: every field is shape-checked before it is kept (coding.md cast family 10) */
|
|
13
|
-
function obj(raw: unknown): Record<string, unknown> {
|
|
14
|
-
return typeof raw === 'object' && raw !== null && !Array.isArray(raw) ? (raw as Record<string, unknown>) : {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function str(raw: unknown): string {
|
|
18
|
-
return typeof raw === 'string' ? raw : ''
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** `supported_parameters` carrying "reasoning" is what makes a model a THINKING model here */
|
|
22
|
-
export function parseModelsReply(raw: unknown): OpenRouterModel[] {
|
|
23
|
-
const data = obj(raw).data
|
|
24
|
-
if (!Array.isArray(data)) return []
|
|
25
|
-
const out: OpenRouterModel[] = []
|
|
26
|
-
for (const entry of data) {
|
|
27
|
-
const m = obj(entry)
|
|
28
|
-
const id = str(m.id)
|
|
29
|
-
if (id === '') continue
|
|
30
|
-
const params = Array.isArray(m.supported_parameters) ? m.supported_parameters : []
|
|
31
|
-
out.push({ id, name: str(m.name) === '' ? id : str(m.name), reasoning: params.includes('reasoning') })
|
|
32
|
-
}
|
|
33
|
-
out.sort((a, b) => a.id.localeCompare(b.id))
|
|
34
|
-
return out
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function failure(res: Response, what: string): Promise<Error> {
|
|
38
|
-
// never fail silently, and never let a gateway's html body masquerade as json
|
|
39
|
-
const body = await res.text().catch(() => '')
|
|
40
|
-
return new Error(`openrouter ${what} failed: http ${res.status} ${body.slice(0, 300)}`)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function fetchModels(p: { key: string }): Promise<OpenRouterModel[]> {
|
|
44
|
-
if (p.key.trim() === '') throw new Error('no openrouter api key — paste one in the enhancer settings')
|
|
45
|
-
const res = await fetch(`${BASE}/models`, { headers: { Authorization: `Bearer ${p.key.trim()}` } })
|
|
46
|
-
if (!res.ok) throw await failure(res, 'model list')
|
|
47
|
-
return parseModelsReply(await res.json())
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type RefineRequest = {
|
|
51
|
-
model: string
|
|
52
|
-
system: string
|
|
53
|
-
user: string
|
|
54
|
-
effort: ReasoningEffort
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** the chat body. `reasoning` is OMITTED at effort 'off': a model without thinking support rejects it */
|
|
58
|
-
export function buildRefineBody(p: RefineRequest): Record<string, unknown> {
|
|
59
|
-
return {
|
|
60
|
-
model: p.model,
|
|
61
|
-
stream: true,
|
|
62
|
-
messages: [
|
|
63
|
-
{ role: 'system', content: p.system },
|
|
64
|
-
{ role: 'user', content: p.user },
|
|
65
|
-
],
|
|
66
|
-
...(p.effort === 'off' ? {} : { reasoning: { effort: p.effort } }),
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** SSE framing: complete lines come out, the trailing partial stays in `rest` for the next chunk */
|
|
71
|
-
export function splitSseBuffer(buffer: string): { events: string[]; rest: string } {
|
|
72
|
-
const lines = buffer.split('\n')
|
|
73
|
-
const rest = lines.pop() ?? ''
|
|
74
|
-
const events: string[] = []
|
|
75
|
-
for (const line of lines) {
|
|
76
|
-
const trimmed = line.trim()
|
|
77
|
-
// ": OPENROUTER PROCESSING" keep-alive comments are not events
|
|
78
|
-
if (trimmed === '' || trimmed.startsWith(':')) continue
|
|
79
|
-
if (trimmed.startsWith('data:')) events.push(trimmed.slice(5).trim())
|
|
80
|
-
}
|
|
81
|
-
return { events, rest }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type StreamDelta = { content: string; reasoning: string }
|
|
85
|
-
|
|
86
|
-
/** one `data:` payload → what it adds. Thinking models put the visible answer in `content`
|
|
87
|
-
* and their work in `reasoning`; both are streamed, only content is the prompt */
|
|
88
|
-
export function readStreamDelta(payload: string): StreamDelta | null {
|
|
89
|
-
if (payload === '' || payload === '[DONE]') return null
|
|
90
|
-
let parsed: unknown
|
|
91
|
-
try {
|
|
92
|
-
parsed = JSON.parse(payload)
|
|
93
|
-
} catch {
|
|
94
|
-
return null
|
|
95
|
-
}
|
|
96
|
-
const root = obj(parsed)
|
|
97
|
-
const err = obj(root.error)
|
|
98
|
-
if (str(err.message) !== '') throw new Error(`openrouter stream error: ${str(err.message)}`)
|
|
99
|
-
const choices = root.choices
|
|
100
|
-
if (!Array.isArray(choices)) return null
|
|
101
|
-
const delta = obj(obj(choices[0]).delta)
|
|
102
|
-
const content = str(delta.content)
|
|
103
|
-
const reasoning = str(delta.reasoning)
|
|
104
|
-
if (content === '' && reasoning === '') return null
|
|
105
|
-
return { content, reasoning }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** streamed refine. onDelta fires per chunk so a slow thinking model shows work, not a spinner */
|
|
109
|
-
export async function streamRefine(
|
|
110
|
-
p: RefineRequest & { key: string; signal: AbortSignal; onDelta: (d: StreamDelta) => void },
|
|
111
|
-
): Promise<StreamDelta> {
|
|
112
|
-
if (p.key.trim() === '') throw new Error('no openrouter api key — paste one in the enhancer settings')
|
|
113
|
-
if (p.model.trim() === '') throw new Error('no model selected')
|
|
114
|
-
const res = await fetch(`${BASE}/chat/completions`, {
|
|
115
|
-
method: 'POST',
|
|
116
|
-
headers: { Authorization: `Bearer ${p.key.trim()}`, 'content-type': 'application/json' },
|
|
117
|
-
body: JSON.stringify(buildRefineBody(p)),
|
|
118
|
-
signal: p.signal,
|
|
119
|
-
})
|
|
120
|
-
if (!res.ok) throw await failure(res, 'refine')
|
|
121
|
-
const reader = res.body?.getReader()
|
|
122
|
-
if (reader == null) throw new Error('openrouter refine failed: the response carried no stream')
|
|
123
|
-
const decoder = new TextDecoder()
|
|
124
|
-
const total: StreamDelta = { content: '', reasoning: '' }
|
|
125
|
-
let buffer = ''
|
|
126
|
-
for (;;) {
|
|
127
|
-
const chunk = await reader.read()
|
|
128
|
-
if (chunk.done) break
|
|
129
|
-
buffer += decoder.decode(chunk.value, { stream: true })
|
|
130
|
-
const split = splitSseBuffer(buffer)
|
|
131
|
-
buffer = split.rest
|
|
132
|
-
for (const event of split.events) {
|
|
133
|
-
const delta = readStreamDelta(event)
|
|
134
|
-
if (delta == null) continue
|
|
135
|
-
total.content += delta.content
|
|
136
|
-
total.reasoning += delta.reasoning
|
|
137
|
-
p.onDelta(delta)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (total.content.trim() === '') throw new Error('openrouter refine returned no text — try another model')
|
|
141
|
-
return total
|
|
142
|
-
}
|