comfy-ts 2.21.0 → 2.23.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.
Files changed (104) hide show
  1. package/dist/{ServeApp-ByMobrWW.js → ServeApp-DolRCMHj.js} +183 -14
  2. package/dist/ServeApp-DolRCMHj.js.map +1 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-B5sMqNia.js → exampleAssets-Duneoq6r.js} +331 -42
  5. package/dist/exampleAssets-Duneoq6r.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-BNZgYIww.js → findDefinedWorkflow-DjoJA8y7.js} +2 -2
  7. package/dist/{findDefinedWorkflow-BNZgYIww.js.map → findDefinedWorkflow-DjoJA8y7.js.map} +1 -1
  8. package/dist/index.cjs +381 -34
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +201 -24
  11. package/dist/index.d.ts +201 -24
  12. package/dist/index.js +380 -35
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-CuBSygku.js → run-run-Cr0L9lCK.js} +5 -5
  15. package/dist/{run-run-CuBSygku.js.map → run-run-Cr0L9lCK.js.map} +1 -1
  16. package/dist/{run-serve-COk_G0Qz.js → run-serve---qA7o_m.js} +4 -4
  17. package/dist/{run-serve-COk_G0Qz.js.map → run-serve---qA7o_m.js.map} +1 -1
  18. package/dist/{run-tui-CB6i_x2y.js → run-tui-DxXiWo5J.js} +4 -4
  19. package/dist/{run-tui-CB6i_x2y.js.map → run-tui-DxXiWo5J.js.map} +1 -1
  20. package/dist/{schemaDrift-CHDVYlaj.js → schemaDrift-BTxdABHi.js} +36 -2
  21. package/dist/schemaDrift-BTxdABHi.js.map +1 -0
  22. package/dist/serve-web.js +207 -47
  23. package/dist/web.d.ts +201 -24
  24. package/dist/web.js +380 -35
  25. package/dist/web.js.map +1 -1
  26. package/examples/README.md +2 -0
  27. package/examples/comfy-cloud/sdk.d.ts +102 -1
  28. package/examples/depth-explorer/models.ts +722 -0
  29. package/examples/depth-explorer/serve.ts +140 -0
  30. package/examples/depth-explorer/thumbs/bae.webp +0 -0
  31. package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
  32. package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
  33. package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
  34. package/examples/depth-explorer/thumbs/dsine.webp +0 -0
  35. package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
  36. package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
  37. package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
  38. package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
  39. package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
  40. package/examples/depth-explorer/thumbs/leres.webp +0 -0
  41. package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
  42. package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
  43. package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
  44. package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
  45. package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
  46. package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
  47. package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
  48. package/examples/depth-explorer/thumbs/midas.webp +0 -0
  49. package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
  50. package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
  51. package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
  52. package/examples/depth-explorer/thumbs/zoe.webp +0 -0
  53. package/examples/depth-explorer/web/App.tsx +457 -0
  54. package/examples/depth-explorer/web/gl.ts +202 -0
  55. package/examples/depth-explorer/web/index.html +14 -0
  56. package/examples/depth-explorer/web/main.tsx +19 -0
  57. package/examples/depth-explorer/web/pixels.ts +86 -0
  58. package/examples/depth-explorer/web/state.ts +329 -0
  59. package/examples/depth-explorer/web/styles.css +366 -0
  60. package/examples/depth-explorer/web/tsconfig.json +16 -0
  61. package/examples/rvion/17-relight.cflow.ts +110 -0
  62. package/examples/rvion/18-world.cflow.ts +101 -0
  63. package/examples/world-explorer/serve.ts +171 -0
  64. package/examples/world-explorer/web/index.html +14 -0
  65. package/examples/world-explorer/web/main.tsx +200 -0
  66. package/examples/world-explorer/web/state.ts +212 -0
  67. package/examples/world-explorer/web/styles.css +131 -0
  68. package/examples/world-explorer/web/thumb.ts +21 -0
  69. package/examples/world-explorer/web/tsconfig.json +11 -0
  70. package/examples/world-explorer/world-state.ts +40 -0
  71. package/package.json +6 -7
  72. package/src/cli/serve/ServeApp.ts +106 -6
  73. package/src/cli/serve/describeVar.ts +12 -1
  74. package/src/cli/serve/resultHistory.ts +28 -5
  75. package/src/cli/serve/thumbs.ts +77 -0
  76. package/src/cli/serve/web/api.ts +9 -1
  77. package/src/cli/serve/web/components/Gallery.tsx +26 -1
  78. package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
  79. package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
  80. package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
  81. package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
  82. package/src/cli/serve/web/state/choiceButtons.ts +26 -2
  83. package/src/cli/serve/web/styles.ts +42 -0
  84. package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
  85. package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
  86. package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
  87. package/src/cli/serve/web/widgets/relightGl.ts +305 -0
  88. package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
  89. package/src/coreExports.ts +10 -0
  90. package/src/graph/ComfyNode.ts +12 -2
  91. package/src/host/ComfyHost.ts +153 -2
  92. package/src/host/ResilientWebsocket.ts +10 -0
  93. package/src/manager/script-update-manager.bun.ts +0 -7
  94. package/src/runner/ComfyExecution.ts +165 -20
  95. package/src/runner/ComfyWsApi.ts +2 -0
  96. package/src/runner/historyReplay.ts +53 -0
  97. package/src/runner/outputs3d.ts +18 -0
  98. package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
  99. package/src/vars/ComfyVars.ts +32 -2
  100. package/src/vars/DefinedWorkflow.ts +4 -0
  101. package/src/vars/outputWidgets.ts +47 -0
  102. package/dist/ServeApp-ByMobrWW.js.map +0 -1
  103. package/dist/exampleAssets-B5sMqNia.js.map +0 -1
  104. package/dist/schemaDrift-CHDVYlaj.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ html,
2
+ body,
3
+ #root {
4
+ height: 100%;
5
+ margin: 0;
6
+ background: #0d0e10;
7
+ color: #d8d9dc;
8
+ font:
9
+ 13px system-ui,
10
+ sans-serif;
11
+ overflow: hidden;
12
+ }
13
+
14
+ .app {
15
+ display: flex;
16
+ flex-direction: column;
17
+ height: 100%;
18
+ }
19
+
20
+ .bar {
21
+ display: flex;
22
+ align-items: center;
23
+ gap: 4px;
24
+ padding: 4px 6px;
25
+ flex: none;
26
+ }
27
+
28
+ .tab {
29
+ font: inherit;
30
+ color: #9a9ca3;
31
+ background: none;
32
+ border: 1px solid transparent;
33
+ border-radius: 6px;
34
+ padding: 2px 9px;
35
+ cursor: pointer;
36
+ }
37
+
38
+ .tab.on {
39
+ color: #e8e8ea;
40
+ border-color: #3a3d45;
41
+ background: #1d1f24;
42
+ }
43
+
44
+ .line {
45
+ margin-left: 6px;
46
+ color: #8a8c93;
47
+ white-space: nowrap;
48
+ overflow: hidden;
49
+ text-overflow: ellipsis;
50
+ }
51
+
52
+ .line b {
53
+ color: #d8d9dc;
54
+ font-weight: 500;
55
+ }
56
+
57
+ .stage {
58
+ position: relative;
59
+ flex: 1;
60
+ min-height: 0;
61
+ touch-action: none;
62
+ user-select: none;
63
+ cursor: grab;
64
+ outline: none;
65
+ }
66
+
67
+ .view {
68
+ position: absolute;
69
+ inset: 0;
70
+ outline: none;
71
+ }
72
+
73
+ .stage canvas,
74
+ .stage img {
75
+ position: absolute;
76
+ inset: 0;
77
+ width: 100%;
78
+ height: 100%;
79
+ }
80
+
81
+ .stage img {
82
+ object-fit: contain;
83
+ cursor: default;
84
+ }
85
+
86
+ .note {
87
+ position: absolute;
88
+ inset: 0;
89
+ display: grid;
90
+ place-items: center;
91
+ color: #8a8c93;
92
+ pointer-events: none;
93
+ text-align: center;
94
+ padding: 12px;
95
+ }
96
+
97
+ .worlds a {
98
+ display: block;
99
+ color: #d8d9dc;
100
+ padding: 2px 0;
101
+ pointer-events: auto;
102
+ }
103
+ .tools {
104
+ margin-left: auto;
105
+ display: flex;
106
+ gap: 4px;
107
+ flex: none;
108
+ }
109
+
110
+ /* the hub panorama's hint: a pill at the foot of the view */
111
+ .hint {
112
+ position: absolute;
113
+ left: 50%;
114
+ bottom: 10px;
115
+ transform: translateX(-50%);
116
+ max-width: calc(100% - 24px);
117
+ padding: 3px 12px;
118
+ border-radius: 999px;
119
+ background: color-mix(in srgb, #000 55%, transparent);
120
+ color: #d8d9dc;
121
+ font-size: 12px;
122
+ white-space: nowrap;
123
+ overflow: hidden;
124
+ text-overflow: ellipsis;
125
+ pointer-events: none;
126
+ }
127
+
128
+ .hint.notice {
129
+ bottom: 40px;
130
+ color: #ffb4b4;
131
+ }
@@ -0,0 +1,21 @@
1
+ // a world's thumbnail: what the view shows at its default camera, 640 px wide, sent to the server that keeps it as
2
+ // .comfy-ts/worlds/<name>/thumb.webp. A 3D view gives it by `View3d.snapshot`, the picture view by its <img>
3
+ export const THUMB_W = 640
4
+
5
+ export async function sendThumb(name: string, src: CanvasImageSource, w: number, h: number): Promise<void> {
6
+ if (w <= 0 || h <= 0) return
7
+ const c = document.createElement('canvas')
8
+ c.width = THUMB_W
9
+ c.height = Math.round((THUMB_W * h) / w)
10
+ const g = c.getContext('2d')
11
+ if (g == null) throw new Error('thumbnail: no 2d context')
12
+ g.drawImage(src, 0, 0, c.width, c.height)
13
+ const blob = await new Promise<Blob | null>((res) => c.toBlob(res, 'image/webp', 0.85))
14
+ if (blob == null) throw new Error('thumbnail: the browser made no webp')
15
+ await postThumb(name, blob)
16
+ }
17
+
18
+ export async function postThumb(name: string, blob: Blob): Promise<void> {
19
+ const r = await fetch(`api/thumb/${encodeURIComponent(name)}`, { method: 'POST', body: blob })
20
+ if (!r.ok) throw new Error(`thumbnail of ${name}: ${r.status} ${await r.text()}`)
21
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ // the world explorer page: dom-typed like examples/web, so it keeps its own config
3
+ "extends": "../../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
6
+ "tsBuildInfoFile": "../../../node_modules/.cache/tsbuildinfo-world-explorer-web.json"
7
+ },
8
+ // MUST override the root's exclude, which lists this directory
9
+ "exclude": [],
10
+ "include": ["."]
11
+ }
@@ -0,0 +1,40 @@
1
+ // the state of a `world:<name>` thread version, from the files its folder holds: `{ json: { name, files }, views, card? }`.
2
+ // `views` is one still per view with its legend (the page's `view` key, the word under it); the card (title, chips,
3
+ // sizes) is the hub's line under the stills, `--card` adds it
4
+ //
5
+ // usage: bun examples/world-explorer/world-state.ts <name> [--card] → prints the state file's path
6
+ // then: sk thread post world:<name> --title … --what … --after <path> --image .comfy-ts/worlds/<name>/thumb.webp
7
+ import { existsSync, readdirSync, statSync, writeFileSync } from 'node:fs'
8
+ import { join } from 'pathe'
9
+
10
+ /** the file each view draws, its id (the page's `view` key) and its legend under the still */
11
+ const VIEWS: [file: string, label: string, id: string][] = [
12
+ ['panorama.png', '360°', 'pano'],
13
+ ['world.glb', 'walk', 'world'],
14
+ ['splat.ply', 'splat', 'splat'],
15
+ ['source.png', 'picture', 'source'],
16
+ ]
17
+
18
+ const name = process.argv[2]
19
+ if (name == null || name.startsWith('-')) throw new Error('usage: world-state.ts <name> [--card]')
20
+ const dir = join(process.cwd(), '.comfy-ts/worlds', name)
21
+ if (!existsSync(dir)) throw new Error(`no world folder ${dir}`)
22
+ const present = new Set(readdirSync(dir))
23
+ const files = VIEWS.map(([f]) => f).filter((f) => present.has(f))
24
+ if (files.length === 0) throw new Error(`${dir} holds none of ${VIEWS.map(([f]) => f).join(', ')}`)
25
+
26
+ const mb = (f: string): string => `${(statSync(join(dir, f)).size / 1e6).toFixed(0)} MB`
27
+ const card = {
28
+ kind: 'world',
29
+ title: name,
30
+ chips: VIEWS.filter(([f]) => present.has(f)).map(([, v]) => v),
31
+ fields: [
32
+ ...(present.has('world.glb') ? [{ label: 'mesh', text: mb('world.glb') }] : []),
33
+ ...(present.has('splat.ply') ? [{ label: 'splat', text: mb('splat.ply') }] : []),
34
+ ],
35
+ }
36
+ const views = VIEWS.filter(([f]) => present.has(f)).map(([, label, id]) => ({ id, label }))
37
+ const state = { json: { name, files }, views, ...(process.argv.includes('--card') ? { card } : {}) }
38
+ const out = join(dir, 'state.json')
39
+ writeFileSync(out, JSON.stringify(state, null, 2))
40
+ console.log(out)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.21.0",
3
+ "version": "2.23.0",
4
4
  "description": "An efficient way to create, run, maintain and operate your ComfyUI workflows, for humans and agents. A TypeScript SDK typed from your own install, with a CLI, a terminal UI, a web panel and a guide for coding agents.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -73,19 +73,17 @@
73
73
  "test:raw": "bun test",
74
74
  "test:watch": "bun test --watch",
75
75
  "typecheck": "tsc -p tsconfig.lib.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
76
- "typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
76
+ "typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json && tsc -p examples/depth-explorer/web/tsconfig.json && tsc -p examples/world-explorer/web/tsconfig.json",
77
77
  "lint": "oxlint src examples scripts tests",
78
- "format": "oxfmt src examples scripts tests",
79
- "format:check": "oxfmt --check src examples scripts tests",
80
78
  "imports:check": "rvt imports --check",
81
79
  "imports:fix": "rvt imports --fix",
82
80
  "cycles": "rvt cycles 1",
83
81
  "rename": "rvt rename",
84
- "ci": "bun run typecheck && bun run lint && bun run format:check && bun run imports:check && bun run test",
82
+ "ci": "bun run typecheck && bun run lint && bun run imports:check && bun run test",
85
83
  "ci:local": "bun run ci && bun run typecheck:full",
86
84
  "gen:manager": "bun src/manager/script-update-manager.bun.ts",
87
85
  "gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
88
- "gen:sdk:cloud": "bun src/cli/comfy-ts-cli.ts gen --id comfy-cloud --host https://cloud.comfy.org --out examples/comfy-cloud/sdk.d.ts && oxfmt examples/comfy-cloud/sdk.d.ts",
86
+ "gen:sdk:cloud": "bun src/cli/comfy-ts-cli.ts gen --id comfy-cloud --host https://cloud.comfy.org --out examples/comfy-cloud/sdk.d.ts",
89
87
  "sdk:outline": "bun scripts/sdk-outline.ts",
90
88
  "loras": "bun src/cli/comfy-ts-cli.ts loras",
91
89
  "examples:images": "bun scripts/fetch-example-images.ts",
@@ -102,6 +100,8 @@
102
100
  "serve:0000": "bun src/cli/comfy-ts-cli.ts serve --host 0.0.0.0",
103
101
  "serve:0000:rvion": "bun src/cli/comfy-ts-cli.ts serve --host 0.0.0.0 examples/rvion",
104
102
  "serve:rvion": "bun --watch src/cli/comfy-ts-cli.ts serve examples/rvion",
103
+ "depth": "bun examples/depth-explorer/serve.ts",
104
+ "world": "bun --watch examples/world-explorer/serve.ts",
105
105
  "check:panel-scroll": "bun scripts/check-panel-scroll.ts"
106
106
  },
107
107
  "rvt": {
@@ -139,7 +139,6 @@
139
139
  "@types/react": "^19.2.17",
140
140
  "@types/react-dom": "^19.2.3",
141
141
  "@types/ws": "^8.18.1",
142
- "oxfmt": "^0.60.0",
143
142
  "oxlint": "^1.75.0",
144
143
  "oxlint-tsgolint": "^7.0.2001",
145
144
  "rvlib-shipkit": "^2.26.0",
@@ -13,8 +13,10 @@ import {
13
13
  statSync,
14
14
  writeFileSync,
15
15
  } from 'node:fs'
16
+ import { createHash } from 'node:crypto'
16
17
  import { nanoid } from 'nanoid'
17
- import { basename, dirname, extname, join, resolve } from 'pathe'
18
+ import { basename, dirname, extname, isAbsolute, join, resolve } from 'pathe'
19
+ import { isHttpUrl, ThumbStore, thumbUrl } from 'src/cli/serve/thumbs.ts'
18
20
  import { applyVarPayload } from 'src/cli/serve/applyVarPayload.ts'
19
21
  import { describeVar, type VarDescriptor } from 'src/cli/serve/describeVar.ts'
20
22
  import { deletePromptEnhancer, listPromptEnhancers, writePromptEnhancer } from 'src/promptEnhancers.ts'
@@ -74,7 +76,16 @@ import {
74
76
  import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
75
77
  import type { ComfyHost } from 'src/host/ComfyHost.ts'
76
78
  import { DEFAULT_MEDIA_EXTENSIONS, MEDIA_KINDS, type MediaKind } from 'src/runner/mediaKinds.ts'
77
- import type { ChoiceVar, LorasVar, MediaVar, OptionalChoiceVar, PromptVar, SeedVar } from 'src/vars/ComfyVars.ts'
79
+ import { MODEL_3D_MIMES } from 'src/runner/outputs3d.ts'
80
+ import type {
81
+ ChoiceOptionLook,
82
+ ChoiceVar,
83
+ LorasVar,
84
+ MediaVar,
85
+ OptionalChoiceVar,
86
+ PromptVar,
87
+ SeedVar,
88
+ } from 'src/vars/ComfyVars.ts'
78
89
  import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
79
90
  import { bang } from 'src/utils/bang.ts'
80
91
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
@@ -88,7 +99,7 @@ export type ServeExecution = {
88
99
  status: string
89
100
  /** buffer is the ONLY copy for an in-memory image (saving off); reading it on a
90
101
  * SAVED image would hit the disk, so it is only touched when absPath is null */
91
- images: { absPath: string | null; filename: string; buffer?: Uint8Array }[]
102
+ images: { absPath: string | null; filename: string; buffer?: Uint8Array; tags?: string[] }[]
92
103
  /** STRING outputs (PreviewAny, i.e. every llm graph). A text-only workflow has no images at
93
104
  * all, so without these its run reply is empty and the panel shows nothing */
94
105
  texts?: { nodeId: string; nodeKey: string | null; text: string }[]
@@ -96,6 +107,8 @@ export type ServeExecution = {
96
107
  audios?: { absPath: string | null; filename: string; mime: string; bytes: Uint8Array }[]
97
108
  /** video files (SaveVideo, SaveWEBM, VHS_VideoCombine), same shape as audios */
98
109
  videos?: { absPath: string | null; filename: string; mime: string; bytes: Uint8Array }[]
110
+ /** 3D files (SaveGLB, SaveGaussianSplat, SavePointCloud), the same shape plus `format` */
111
+ models3d?: { absPath: string | null; filename: string; mime: string; format: string; bytes: Uint8Array }[]
99
112
  data: { id: string; error?: unknown }
100
113
  /** live global progress (ComfyExecution has it; fakes may omit) — the /run/<module> poll reads it */
101
114
  progressGlobal?: { percent: number }
@@ -261,6 +274,7 @@ const CONTENT_TYPES: Record<string, string> = {
261
274
  '.m4a': 'audio/mp4',
262
275
  '.json': 'application/json',
263
276
  '.txt': 'text/plain',
277
+ ...Object.fromEntries(Object.entries(MODEL_3D_MIMES).map(([ext, mime]) => [`.${ext}`, mime])),
264
278
  }
265
279
 
266
280
  /** magic-byte sniff for the preview proxy — fetchLoraPreviewBytes already guarantees an image */
@@ -342,7 +356,7 @@ const USAGE = [
342
356
  'DELETE /drafts/<module>/<draft> — delete that draft file',
343
357
  'GET /run/<module> — live run status · /run/<module>/preview — latent preview bytes',
344
358
  'POST /upload with {"name","dataBase64"} — store a browser file for an image, audio or video var',
345
- 'GET /images|audio|video/<promptId>/<ix> — an output kept in memory (saving off)',
359
+ 'GET /images|audio|video|model3d/<promptId>/<ix> — an output kept in memory (saving off)',
346
360
  'GET /tags/<module>/<var>?q=<text>&limit=<n> — tag completion from the list a prompt var declares (`tags`)',
347
361
  'GET /hosts/<hostId>/drift[?full=1] — what changed on the host since the schema was loaded (model files; node types with full=1)',
348
362
  'GET /lora-info/<hostId>/<lora> — display name + trigger words (local mirror)',
@@ -485,6 +499,7 @@ export class ServeApp {
485
499
  if (segs[0] === 'tags' && segs.length === 3 && segs[1] != null && segs[2] != null)
486
500
  return await this.replyTags(segs[1], segs[2], req.url)
487
501
  if (segs[0] === 'settings' && segs.length === 1) return this.replySettings()
502
+ if (segs[0] === 'thumb' && segs.length === 1) return await this.replyThumb(req.url)
488
503
  if (segs[0] === 'tabs' && segs.length === 1) return this.replyTabs()
489
504
  if (segs[0] === 'hosts' && segs.length === 1) return this.replyHosts()
490
505
  if (segs[0] === 'hosts' && segs.length === 3 && segs[1] != null && segs[2] === 'logs')
@@ -499,6 +514,8 @@ export class ServeApp {
499
514
  return this.replyMemoryImage(`audio/${segs[1]}/${segs[2]}`)
500
515
  if (segs[0] === 'video' && segs.length === 3 && segs[1] != null && segs[2] != null)
501
516
  return this.replyMemoryImage(`video/${segs[1]}/${segs[2]}`)
517
+ if (segs[0] === 'model3d' && segs.length === 3 && segs[1] != null && segs[2] != null)
518
+ return this.replyMemoryImage(`model3d/${segs[1]}/${segs[2]}`)
502
519
  if (segs[0] === 'results' && segs.length === 1)
503
520
  return json(200, { runs: this.kept.list(), memory: this.kept.usage() })
504
521
  if (segs[0] === 'outputs') return this.replyOutput(segs.slice(1))
@@ -617,12 +634,64 @@ export class ServeApp {
617
634
  }
618
635
 
619
636
  // #region introspection ----------------------------------------------------
637
+ /** the pictures of a descriptor made concrete for the page: a local thumb or preset becomes a
638
+ * /thumb url the store allows, a local preset not on this machine is flagged missing, a url
639
+ * stays as it is. Relative paths are relative to the workflow file */
640
+ private decorateLooks(desc: VarDescriptor, mod: ServeModule): void {
641
+ const dir = dirname(mod.file)
642
+ this.thumbs.allowRoot(dir)
643
+ this.thumbs.allowRoot(this.outputRoot)
644
+ const local = (p: string): string => (isAbsolute(p) ? p : resolve(dir, p))
645
+ const options = desc.ui?.options
646
+ if (desc.ui != null && options != null) {
647
+ const looks: Record<string, ChoiceOptionLook> = {}
648
+ for (const [value, look] of Object.entries(options)) {
649
+ if (look.thumb == null || isHttpUrl(look.thumb)) {
650
+ looks[value] = look
651
+ continue
652
+ }
653
+ const abs = local(look.thumb)
654
+ this.thumbs.allow(abs)
655
+ looks[value] = { ...look, thumb: thumbUrl(abs, 128) }
656
+ }
657
+ // a copy: the var's own ui object must keep the authored paths
658
+ desc.ui = { ...desc.ui, options: looks }
659
+ }
660
+ if (desc.mediaPresets != null)
661
+ desc.mediaPresets = desc.mediaPresets.map((preset) => {
662
+ if (isHttpUrl(preset.value)) {
663
+ // once a run fetched it, the tile is a small local thumb, not the whole remote file
664
+ const cached = this.urlInputPath(preset.value, basename(new URL(preset.value).pathname))
665
+ return { ...preset, thumb: existsSync(cached) ? thumbUrl(cached, 160) : preset.value }
666
+ }
667
+ const abs = local(preset.value)
668
+ this.thumbs.allow(abs)
669
+ return existsSync(abs)
670
+ ? { ...preset, value: abs, thumb: thumbUrl(abs, 160) }
671
+ : { ...preset, value: abs, missing: true }
672
+ })
673
+ if (MEDIA_KINDS.includes(desc.kind as MediaKind) && typeof desc.default === 'string' && desc.default !== '')
674
+ if (!isHttpUrl(desc.default)) this.thumbs.allow(local(desc.default))
675
+ }
676
+
677
+ private async replyThumb(url: string): Promise<ServeReply> {
678
+ const q = new URLSearchParams(url.split('?')[1] ?? '')
679
+ const src = q.get('src')
680
+ if (src == null || src === '') return json(400, { error: 'thumb needs ?src=<local path>' })
681
+ const out = await this.thumbs.render(src, Number(q.get('w') ?? 160) || 160)
682
+ if (out === 'forbidden')
683
+ return json(403, { error: 'not a picture a served workflow declared, nor under its folder or the outputs' })
684
+ if (out === 'missing') return json(404, { error: 'not on this machine' })
685
+ return { status: 200, contentType: 'image/webp', body: out, headers: { 'cache-control': 'max-age=300' } }
686
+ }
687
+
620
688
  private describeModule(mod: ServeModule): Record<string, unknown> {
621
689
  refreshLoraInfoCacheIfChanged()
622
690
  const hostId = mod.dw.host.data.id
623
691
  const vars: Record<string, VarDescriptor> = {}
624
692
  for (const [name, varDef] of mod.dw.entries()) {
625
693
  const desc = describeVar(varDef)
694
+ this.decorateLooks(desc, mod)
626
695
  // the raw enum values stay the payload keys; the mirror's names are for humans
627
696
  if (desc.kind === 'loras' && desc.options != null) {
628
697
  const labels: Record<string, string> = {}
@@ -700,6 +769,8 @@ export class ServeApp {
700
769
 
701
770
  /** per module, read once from a dry build: the omnibox searches and shows them */
702
771
  private tagsByModule = new Map<string, string[]>()
772
+ /** the local images the page may preview (GET /thumb), filled by describeModule */
773
+ private thumbs = new ThumbStore()
703
774
 
704
775
  private async tagsFor(mod: ServeModule): Promise<string[]> {
705
776
  const known = this.tagsByModule.get(mod.key)
@@ -1631,6 +1702,8 @@ export class ServeApp {
1631
1702
  if (audios.length > 0) produced.push(`${audios.length} audio(s)`)
1632
1703
  const videos = execution.videos ?? []
1633
1704
  if (videos.length > 0) produced.push(`${videos.length} video(s)`)
1705
+ const models3d = execution.models3d ?? []
1706
+ if (models3d.length > 0) produced.push(`${models3d.length} 3d model(s)`)
1634
1707
  if ((execution.texts ?? []).length > 0) produced.push(`${(execution.texts ?? []).length} text(s)`)
1635
1708
  console.log(`[serve] 🟢 ${mod.key}/${draft} done in ${(durationMs / 1000).toFixed(1)}s · ${produced.join(' · ')}`)
1636
1709
 
@@ -1656,6 +1729,12 @@ export class ServeApp {
1656
1729
  blobs.push(this.memoryBlob(key, a.bytes, a.filename))
1657
1730
  return key
1658
1731
  })
1732
+ const model3dKeys = models3d.map((m, ix) => {
1733
+ if (m.absPath != null) return null
1734
+ const key = `model3d/${execution.data.id}/${ix}`
1735
+ blobs.push(this.memoryBlob(key, m.bytes, m.filename))
1736
+ return key
1737
+ })
1659
1738
  // the KEY is raw (`<promptId>/<ix>`); the url encodes each segment, and handle() decodes
1660
1739
  // per segment, so the lookup gets the raw key back
1661
1740
  const memoryUrl = (route: string, key: string): string =>
@@ -1680,6 +1759,7 @@ export class ServeApp {
1680
1759
  filename: img.filename,
1681
1760
  url: img.absPath != null ? this.outputUrl(img.absPath) : key != null ? memoryUrl('images', key) : null,
1682
1761
  absPath: img.absPath,
1762
+ ...(img.tags != null && img.tags.length > 0 ? { tags: [...img.tags] } : {}),
1683
1763
  }
1684
1764
  }),
1685
1765
  audios: audios.map((a, ix) => {
@@ -1700,8 +1780,20 @@ export class ServeApp {
1700
1780
  absPath: a.absPath,
1701
1781
  }
1702
1782
  }),
1783
+ models3d: models3d.map((m, ix) => {
1784
+ const key = model3dKeys[ix]
1785
+ return {
1786
+ filename: m.filename,
1787
+ mime: m.mime,
1788
+ format: m.format,
1789
+ size: m.bytes.byteLength,
1790
+ url: m.absPath != null ? this.outputUrl(m.absPath) : key != null ? memoryUrl('model3d', key) : null,
1791
+ absPath: m.absPath,
1792
+ }
1793
+ }),
1794
+ ...(mod.dw.spec.widgets != null && mod.dw.spec.widgets.length > 0 ? { widgets: mod.dw.spec.widgets } : {}),
1703
1795
  }
1704
- this.kept.add({ record, imageKeys, audioKeys, videoKeys, blobs })
1796
+ this.kept.add({ record, imageKeys, audioKeys, videoKeys, model3dKeys, blobs })
1705
1797
 
1706
1798
  // Accept: image/* → first image's bytes directly (curl -o, <img src>)
1707
1799
  const first = execution.images[0]
@@ -1872,8 +1964,16 @@ export class ServeApp {
1872
1964
  return next
1873
1965
  }
1874
1966
 
1967
+ /** one file per url: a preset or a pasted url downloads once per output root, not per run */
1968
+ private urlInputPath(url: string, name: string): string {
1969
+ const hash = createHash('sha1').update(url).digest('hex').slice(0, 16)
1970
+ return join(this.outputRoot, 'serve-inputs', `url-${hash}${extname(name)}`)
1971
+ }
1972
+
1875
1973
  /** payload image urls land as local files under outputs/serve-inputs/ */
1876
1974
  private async downloadInput(url: string): Promise<string> {
1975
+ const cached = this.urlInputPath(url, basename(new URL(url).pathname))
1976
+ if (existsSync(cached)) return cached
1877
1977
  // every failure below answers the SAME thing. Refused, DNS miss, 403 and 200-of-the-wrong
1878
1978
  // -type were four distinguishable replies, which is a port and host scanner for anything
1879
1979
  // this box can reach. The reason goes to the server log
@@ -1900,7 +2000,7 @@ export class ServeApp {
1900
2000
  if (declared > INPUT_DOWNLOAD_CAP) throw new Error(`download too large (${declared} bytes): ${url}`)
1901
2001
  const bytes = await readCapped(res, INPUT_DOWNLOAD_CAP, url)
1902
2002
  const name = basename(new URL(url).pathname) || 'input'
1903
- const abs = join(this.outputRoot, 'serve-inputs', `${nanoid(6)}-${name}`)
2003
+ const abs = this.urlInputPath(url, name)
1904
2004
  mkdirSync(dirname(abs), { recursive: true })
1905
2005
  writeFileSync(abs, bytes)
1906
2006
  return abs
@@ -70,8 +70,13 @@ export type VarDescriptor = {
70
70
  /** size: preset labels starred by default (quick buttons before the list) */
71
71
  starredPresets?: string[]
72
72
  extensions?: readonly string[]
73
+ /** image, audio, video: one-click starting files. `thumb` (a url the page can show) and
74
+ * `missing` (a local file not on this machine) are filled by ServeApp.describeModule */
75
+ mediaPresets?: MediaPresetDescriptor[]
73
76
  }
74
77
 
78
+ export type MediaPresetDescriptor = { label: string; value: string; thumb?: string; missing?: boolean }
79
+
75
80
  /** an empty list is absent from the json: every var without presets would otherwise carry `[]` */
76
81
  function presetsOrUndefined(presets: VarPreset[]): VarPreset[] | undefined {
77
82
  return presets.length === 0 ? undefined : presets
@@ -166,7 +171,13 @@ export function describeVar(varDef: AnyVar): VarDescriptor {
166
171
  case 'audio':
167
172
  case 'video': {
168
173
  const v = varDef as MediaVar
169
- return { ...base, payload: 'local file path or http(s) url', extensions: v.extensions }
174
+ const presets = v.presets
175
+ return {
176
+ ...base,
177
+ payload: 'local file path or http(s) url',
178
+ extensions: v.extensions,
179
+ ...(presets.length > 0 ? { mediaPresets: presets } : {}),
180
+ }
170
181
  }
171
182
  default: {
172
183
  // an unknown kind CAN reach here: a globally installed cli against a project on a
@@ -2,8 +2,13 @@
2
2
  // again. Unsaved outputs keep their bytes here, the ONLY copy, under one byte budget, FIFO.
3
3
  // Nothing is written to disk: a server restart forgets it all. PURE, headless-tested
4
4
 
5
- export type RunOutput = { filename: string; url: string | null; absPath: string | null }
5
+ import type { OutputWidget } from 'src/vars/outputWidgets.ts'
6
+
7
+ /** `tags`: the save node's metadata tags, which output widgets read (absent on older records) */
8
+ export type RunOutput = { filename: string; url: string | null; absPath: string | null; tags?: string[] }
6
9
  export type RunAudioOutput = RunOutput & { mime: string }
10
+ /** a mesh, point cloud or splat: `format` the lowercase extension, `size` in bytes */
11
+ export type RunModel3DOutput = RunAudioOutput & { format: string; size: number }
7
12
 
8
13
  /** the run reply `POST /generate` answers, and what `GET /results` lists */
9
14
  export type RunRecord = {
@@ -21,6 +26,10 @@ export type RunRecord = {
21
26
  audios: RunAudioOutput[]
22
27
  /** absent on a record from an older server */
23
28
  videos?: RunAudioOutput[]
29
+ /** absent on a record from an older server */
30
+ models3d?: RunModel3DOutput[]
31
+ /** the module's output widgets at run time, so a kept result draws them after a reload */
32
+ widgets?: OutputWidget[]
24
33
  }
25
34
 
26
35
  export type MemoryUsage = { usedBytes: number; budgetBytes: number; outputs: number; runs: number }
@@ -39,6 +48,7 @@ type Kept = {
39
48
  imageKeys: (string | null)[]
40
49
  audioKeys: (string | null)[]
41
50
  videoKeys: (string | null)[]
51
+ model3dKeys: (string | null)[]
42
52
  }
43
53
 
44
54
  export class ResultHistory {
@@ -55,6 +65,7 @@ export class ResultHistory {
55
65
  imageKeys: (string | null)[]
56
66
  audioKeys: (string | null)[]
57
67
  videoKeys?: (string | null)[]
68
+ model3dKeys?: (string | null)[]
58
69
  blobs: KeptBlob[]
59
70
  }): void {
60
71
  this.remove(p.record.promptId)
@@ -62,7 +73,13 @@ export class ResultHistory {
62
73
  this.blobs.set(b.key, { bytes: b.bytes, contentType: b.contentType })
63
74
  this.used += b.bytes.byteLength
64
75
  }
65
- const kept = { record: p.record, imageKeys: p.imageKeys, audioKeys: p.audioKeys, videoKeys: p.videoKeys ?? [] }
76
+ const kept = {
77
+ record: p.record,
78
+ imageKeys: p.imageKeys,
79
+ audioKeys: p.audioKeys,
80
+ videoKeys: p.videoKeys ?? [],
81
+ model3dKeys: p.model3dKeys ?? [],
82
+ }
66
83
  this.runs = [kept, ...this.runs]
67
84
  for (const dropped of this.runs.slice(KEPT_RUNS)) this.freeRun(dropped)
68
85
  this.runs = this.runs.slice(0, KEPT_RUNS)
@@ -80,6 +97,7 @@ export class ResultHistory {
80
97
  images: k.record.images.map((img, ix) => this.withLiveUrl(img, k.imageKeys[ix])),
81
98
  audios: k.record.audios.map((a, ix) => this.withLiveUrl(a, k.audioKeys[ix])),
82
99
  videos: (k.record.videos ?? []).map((a, ix) => this.withLiveUrl(a, k.videoKeys[ix])),
100
+ models3d: (k.record.models3d ?? []).map((a, ix) => this.withLiveUrl(a, k.model3dKeys[ix])),
83
101
  }))
84
102
  }
85
103
 
@@ -111,7 +129,7 @@ export class ResultHistory {
111
129
  }
112
130
 
113
131
  private freeRun(k: Kept): void {
114
- for (const key of [...k.imageKeys, ...k.audioKeys, ...k.videoKeys]) {
132
+ for (const key of [...k.imageKeys, ...k.audioKeys, ...k.videoKeys, ...k.model3dKeys]) {
115
133
  if (key == null) continue
116
134
  const b = this.blobs.get(key)
117
135
  if (b == null) continue
@@ -134,8 +152,13 @@ export class ResultHistory {
134
152
  const live = (keys: (string | null)[]): boolean => keys.some((key) => key == null || this.blobs.has(key))
135
153
  const hasText = k.record.texts.length > 0
136
154
  const hasNothing =
137
- k.record.images.length === 0 && k.record.audios.length === 0 && (k.record.videos ?? []).length === 0
138
- return hasText || hasNothing || live(k.imageKeys) || live(k.audioKeys) || live(k.videoKeys)
155
+ k.record.images.length === 0 &&
156
+ k.record.audios.length === 0 &&
157
+ (k.record.videos ?? []).length === 0 &&
158
+ (k.record.models3d ?? []).length === 0
159
+ return (
160
+ hasText || hasNothing || live(k.imageKeys) || live(k.audioKeys) || live(k.videoKeys) || live(k.model3dKeys)
161
+ )
139
162
  })
140
163
  }
141
164
  }