comfy-ts 2.22.0 → 2.24.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 (99) hide show
  1. package/dist/{ServeApp-DuxYdaZZ.js → ServeApp-fsHtW5zG.js} +51 -17
  2. package/dist/ServeApp-fsHtW5zG.js.map +1 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-1NHndnNB.js → exampleAssets-DZynSkZm.js} +405 -39
  5. package/dist/exampleAssets-DZynSkZm.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-CRsBTTJK.js → findDefinedWorkflow-qyqFea7q.js} +2 -2
  7. package/dist/{findDefinedWorkflow-CRsBTTJK.js.map → findDefinedWorkflow-qyqFea7q.js.map} +1 -1
  8. package/dist/index.cjs +428 -46
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +147 -1
  11. package/dist/index.d.ts +147 -1
  12. package/dist/index.js +428 -47
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-Y5ZI48vV.js → run-run-Cn2JzKlE.js} +5 -5
  15. package/dist/{run-run-Y5ZI48vV.js.map → run-run-Cn2JzKlE.js.map} +1 -1
  16. package/dist/{run-serve-CICU_wTL.js → run-serve-BhGegaCI.js} +4 -4
  17. package/dist/{run-serve-CICU_wTL.js.map → run-serve-BhGegaCI.js.map} +1 -1
  18. package/dist/{run-tui-CViJXsHL.js → run-tui-CrM4ijkH.js} +4 -4
  19. package/dist/{run-tui-CViJXsHL.js.map → run-tui-CrM4ijkH.js.map} +1 -1
  20. package/dist/{schemaDrift-CzjaIwZX.js → schemaDrift-BGYJZGMD.js} +18 -3
  21. package/dist/{schemaDrift-CzjaIwZX.js.map → schemaDrift-BGYJZGMD.js.map} +1 -1
  22. package/dist/serve-web.js +46 -43
  23. package/dist/web.d.ts +147 -1
  24. package/dist/web.js +428 -47
  25. package/dist/web.js.map +1 -1
  26. package/examples/README.md +1 -0
  27. package/examples/comfy-cloud/sdk.d.ts +102 -1
  28. package/examples/depth-explorer/models.ts +6 -56
  29. package/examples/depth-explorer/serve.ts +12 -133
  30. package/examples/depth-explorer/web/App.tsx +20 -91
  31. package/examples/depth-explorer/web/index.html +1 -0
  32. package/examples/depth-explorer/web/state.ts +26 -109
  33. package/examples/depth-explorer/web/styles.css +1 -286
  34. package/examples/explorer-kit/catalog.ts +80 -0
  35. package/examples/explorer-kit/server.ts +167 -0
  36. package/examples/explorer-kit/web/base.css +289 -0
  37. package/examples/explorer-kit/web/runs.ts +160 -0
  38. package/examples/explorer-kit/web/ui.tsx +125 -0
  39. package/examples/rvion/17-relight.cflow.ts +2 -1
  40. package/examples/rvion/18-world.cflow.ts +101 -0
  41. package/examples/rvion/19-flythrough.cflow.ts +312 -0
  42. package/examples/rvion/20-grow-splat.cflow.ts +88 -0
  43. package/examples/rvion/21-photo-to-model.cflow.ts +191 -0
  44. package/examples/rvion/flythroughChain.ts +171 -0
  45. package/examples/rvion/flythroughColmap.ts +157 -0
  46. package/examples/rvion/flythroughFuse.ts +199 -0
  47. package/examples/rvion/flythroughGuide.ts +300 -0
  48. package/examples/rvion/flythroughPalette.ts +310 -0
  49. package/examples/rvion/flythroughPath.ts +177 -0
  50. package/examples/rvion/flythroughSplat.ts +73 -0
  51. package/examples/rvion/grow-splat/align.ts +114 -0
  52. package/examples/rvion/grow-splat/grow.ts +198 -0
  53. package/examples/rvion/grow-splat/ply.ts +166 -0
  54. package/examples/rvion/grow-splat/raster.ts +207 -0
  55. package/examples/rvion/grow-splat/sharp.ts +45 -0
  56. package/examples/rvion/splatDataset.ts +80 -0
  57. package/examples/rvion/splatEval.ts +380 -0
  58. package/examples/upscale-explorer/models.ts +341 -0
  59. package/examples/upscale-explorer/serve.ts +19 -0
  60. package/examples/upscale-explorer/web/App.tsx +250 -0
  61. package/examples/upscale-explorer/web/compare.tsx +285 -0
  62. package/examples/upscale-explorer/web/index.html +15 -0
  63. package/examples/upscale-explorer/web/main.tsx +12 -0
  64. package/examples/upscale-explorer/web/state.ts +279 -0
  65. package/examples/upscale-explorer/web/styles.css +241 -0
  66. package/examples/upscale-explorer/web/tsconfig.json +16 -0
  67. package/examples/upscale-explorer/web/viewport.tsx +130 -0
  68. package/examples/world-explorer/serve.ts +171 -0
  69. package/examples/world-explorer/web/index.html +14 -0
  70. package/examples/world-explorer/web/main.tsx +200 -0
  71. package/examples/world-explorer/web/state.ts +212 -0
  72. package/examples/world-explorer/web/styles.css +131 -0
  73. package/examples/world-explorer/web/thumb.ts +21 -0
  74. package/examples/world-explorer/web/tsconfig.json +11 -0
  75. package/examples/world-explorer/world-state.ts +40 -0
  76. package/package.json +7 -8
  77. package/src/cli/serve/ServeApp.ts +27 -2
  78. package/src/cli/serve/resultHistory.ts +22 -4
  79. package/src/cli/serve/thumbs.ts +19 -8
  80. package/src/cli/serve/web/api.ts +4 -0
  81. package/src/cli/serve/web/components/Gallery.tsx +24 -1
  82. package/src/cli/serve/web/styles.ts +3 -0
  83. package/src/coreExports.ts +6 -0
  84. package/src/graph/ComfyNode.ts +12 -2
  85. package/src/host/ComfyHost.ts +159 -2
  86. package/src/host/ResilientWebsocket.ts +10 -0
  87. package/src/manager/script-update-manager.bun.ts +0 -7
  88. package/src/runner/ComfyExecution.ts +185 -23
  89. package/src/runner/ComfyWorkflow.ts +22 -0
  90. package/src/runner/ComfyWsApi.ts +3 -1
  91. package/src/runner/comfyOrgApiKey.ts +44 -0
  92. package/src/runner/historyReplay.ts +53 -0
  93. package/src/runner/outputs3d.ts +18 -0
  94. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +2 -0
  95. package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
  96. package/src/state.ts +2 -0
  97. package/src/vars/DefinedWorkflow.ts +1 -0
  98. package/dist/ServeApp-DuxYdaZZ.js.map +0 -1
  99. package/dist/exampleAssets-1NHndnNB.js.map +0 -1
@@ -5,6 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>depth explorer</title>
7
7
  <meta name="shot-ready" content="wait" />
8
+ <link rel="stylesheet" href="../../explorer-kit/web/base.css" />
8
9
  <link rel="stylesheet" href="./styles.css" />
9
10
  </head>
10
11
  <body>
@@ -1,36 +1,20 @@
1
1
  // the one state tree of the page: the catalog from the server, the source image, one result per
2
- // (image, detail, model), the view settings. A sequential run queue: one prompt at a time on the GPU.
2
+ // (image, detail, model), the view settings. The run queue is the explorer kit's.
3
3
  import { makeAutoObservable, runInAction } from 'mobx'
4
-
5
- export type WeightFile = { node: string; input: string; file: string; folder: string; url: string }
6
- export type ModelInfo = {
7
- id: string
8
- label: string
9
- family: string
10
- year: number
11
- kind: 'depth' | 'normal' | 'material'
12
- tier: 'modern' | 'classic'
13
- blurb: string
14
- autoDownload: boolean
15
- ok: boolean
16
- missingNodes: string[]
17
- missingFiles: WeightFile[]
18
- }
19
- export type Source = { key: string; url: string; name: string; width: number; height: number }
4
+ import {
5
+ fetchCatalog,
6
+ RunQueue,
7
+ sampleBlob,
8
+ uploadSource,
9
+ type CardInfo,
10
+ type RunSt,
11
+ type Source,
12
+ } from '../../explorer-kit/web/runs.ts'
13
+
14
+ export type ModelInfo = CardInfo & { kind: 'depth' | 'normal' | 'material'; tier: 'modern' | 'classic' }
20
15
  export type Colormap = 'gray' | 'turbo'
21
16
  export type FocusView = 'wipe' | '3d' | 'light'
22
17
 
23
- export class ResultSt {
24
- status: 'queued' | 'running' | 'done' | 'error' = 'queued'
25
- url: string | null = null
26
- ms: number | null = null
27
- error: string | null = null
28
- startedAt = 0
29
- constructor() {
30
- makeAutoObservable(this)
31
- }
32
- }
33
-
34
18
  export class AppSt {
35
19
  host = ''
36
20
  models: ModelInfo[] = []
@@ -50,25 +34,19 @@ export class AppSt {
50
34
  wipeX = 50
51
35
  /** the 3D relief camera and surface */
52
36
  relief = { yaw: 0.35, pitch: 0.2, zoom: 1, depthScale: 0.3, shade: 0.6 }
53
- results = new Map<string, ResultSt>()
54
- private queue: { key: string; model: string; image: string; detail: number }[] = []
55
- private draining = false
56
- /** ticks every 200 ms while something runs, for the elapsed timers */
57
- now = Date.now()
37
+ runs = new RunQueue()
58
38
 
59
39
  constructor() {
60
- makeAutoObservable(this, { results: true })
61
- setInterval(() => runInAction(() => (this.now = Date.now())), 200)
40
+ makeAutoObservable(this)
62
41
  }
63
42
 
64
43
  async boot(): Promise<void> {
65
44
  try {
66
- const [m, s] = await Promise.all([fetch('/api/models'), fetch('/api/samples')])
67
- const mj = (await m.json()) as { host: string; models: ModelInfo[] }
68
- const sj = (await s.json()) as string[]
45
+ const c = await fetchCatalog<ModelInfo>()
46
+ const sj = c.samples
69
47
  runInAction(() => {
70
- this.host = mj.host
71
- this.models = mj.models
48
+ this.host = c.host
49
+ this.models = c.models
72
50
  this.samples = sj
73
51
  })
74
52
  // deep link: ?image=<sample>&run=all|<id,id>&focus=<id>&view=wipe|3d|light
@@ -197,7 +175,7 @@ export class AppSt {
197
175
  return this.visibleModels.filter((m) => m.ok)
198
176
  }
199
177
  get busy(): boolean {
200
- return this.queue.length > 0 || this.draining
178
+ return this.runs.busy
201
179
  }
202
180
 
203
181
  model(id: string): ModelInfo | undefined {
@@ -206,29 +184,21 @@ export class AppSt {
206
184
  resultKey(model: string): string {
207
185
  return `${this.source?.key ?? '-'}:${this.detail}:${model}`
208
186
  }
209
- result(model: string): ResultSt | undefined {
210
- return this.results.get(this.resultKey(model))
187
+ result(model: string): RunSt | undefined {
188
+ return this.runs.get(this.resultKey(model))
211
189
  }
212
190
  get doneModels(): ModelInfo[] {
213
191
  return this.models.filter((m) => this.result(m.id)?.status === 'done')
214
192
  }
215
193
 
216
194
  async loadSample(name: string): Promise<void> {
217
- const blob = await (await fetch(`/api/samples/${encodeURIComponent(name)}`)).blob()
218
- await this.setSource(blob, name)
195
+ await this.setSource(await sampleBlob(name), name)
219
196
  }
220
197
 
221
198
  async setSource(blob: Blob, name: string): Promise<void> {
222
- const url = URL.createObjectURL(blob)
223
- const img = new Image()
224
- img.src = url
225
- await img.decode()
226
- const res = await fetch('/api/image', { method: 'POST', body: blob })
227
- const j = (await res.json()) as { key?: string; error?: string }
228
- if (j.key == null) throw new Error(j.error ?? 'upload failed')
229
- const key = j.key
199
+ const source = await uploadSource(blob, name)
230
200
  runInAction(() => {
231
- this.source = { key, url, name, width: img.naturalWidth, height: img.naturalHeight }
201
+ this.source = source
232
202
  this.focus = null
233
203
  })
234
204
  }
@@ -236,12 +206,7 @@ export class AppSt {
236
206
  enqueue(model: string): void {
237
207
  const src = this.source
238
208
  if (src == null) return
239
- const key = this.resultKey(model)
240
- const prev = this.results.get(key)
241
- if (prev != null && (prev.status === 'queued' || prev.status === 'running')) return
242
- this.results.set(key, new ResultSt())
243
- this.queue.push({ key, model, image: src.key, detail: this.detail })
244
- void this.drain()
209
+ this.runs.enqueue(this.resultKey(model), { image: src.key, model, detail: this.detail })
245
210
  }
246
211
 
247
212
  runAll(): void {
@@ -250,55 +215,7 @@ export class AppSt {
250
215
 
251
216
  /** resolves once the run queue is empty */
252
217
  settled(): Promise<void> {
253
- return new Promise((resolve) => {
254
- const tick = (): void => {
255
- if (this.busy) setTimeout(tick, 100)
256
- else resolve()
257
- }
258
- tick()
259
- })
260
- }
261
-
262
- private async drain(): Promise<void> {
263
- if (this.draining) return
264
- this.draining = true
265
- try {
266
- for (;;) {
267
- const job = this.queue.shift()
268
- if (job == null) break
269
- const r = this.results.get(job.key)
270
- if (r == null) continue
271
- runInAction(() => {
272
- r.status = 'running'
273
- r.startedAt = Date.now()
274
- })
275
- try {
276
- const res = await fetch('/api/run', {
277
- method: 'POST',
278
- headers: { 'content-type': 'application/json' },
279
- body: JSON.stringify({ image: job.image, model: job.model, detail: job.detail }),
280
- })
281
- if (!res.ok) {
282
- const j = (await res.json()) as { error?: string }
283
- throw new Error(j.error ?? `http ${res.status}`)
284
- }
285
- const url = URL.createObjectURL(await res.blob())
286
- const ms = Number(res.headers.get('x-ms'))
287
- runInAction(() => {
288
- r.url = url
289
- r.ms = ms
290
- r.status = 'done'
291
- })
292
- } catch (e) {
293
- runInAction(() => {
294
- r.error = e instanceof Error ? e.message : String(e)
295
- r.status = 'error'
296
- })
297
- }
298
- }
299
- } finally {
300
- runInAction(() => (this.draining = false))
301
- }
218
+ return this.runs.settled()
302
219
  }
303
220
 
304
221
  openFocus(model: string): void {
@@ -1,12 +1,5 @@
1
+ /* the depth explorer over the shared explorer look (examples/explorer-kit/web/base.css) */
1
2
  :root {
2
- --bg: #111316;
3
- --panel: #181b20;
4
- --card: #1d2127;
5
- --line: #2a2f37;
6
- --text: #e6e8eb;
7
- --dim: #8a929c;
8
- --accent: #6aa8ff;
9
- --err: #ff7a7a;
10
3
  /* the panel's tokens, which the shared widget rules read */
11
4
  --panel-2: var(--card);
12
5
  --border: var(--line);
@@ -15,7 +8,6 @@
15
8
  --sel-border: var(--accent);
16
9
  --sel-text: #c3d3fb;
17
10
  --amber: #e0af68;
18
- color-scheme: dark;
19
11
  }
20
12
  .relightWrap {
21
13
  padding: 10px;
@@ -23,283 +15,6 @@
23
15
  flex-direction: column;
24
16
  gap: 8px;
25
17
  }
26
- * {
27
- box-sizing: border-box;
28
- }
29
- body {
30
- margin: 0;
31
- background: var(--bg);
32
- color: var(--text);
33
- font:
34
- 13px/1.4 ui-sans-serif,
35
- system-ui,
36
- -apple-system,
37
- sans-serif;
38
- }
39
- button,
40
- select,
41
- a.ghost {
42
- font: inherit;
43
- color: var(--text);
44
- background: var(--card);
45
- border: 1px solid var(--line);
46
- border-radius: 6px;
47
- padding: 5px 10px;
48
- cursor: pointer;
49
- text-decoration: none;
50
- }
51
- button:disabled {
52
- opacity: 0.45;
53
- cursor: default;
54
- }
55
- button.primary {
56
- background: var(--accent);
57
- border-color: var(--accent);
58
- color: #0b1220;
59
- font-weight: 600;
60
- width: 100%;
61
- padding: 8px;
62
- margin-top: 14px;
63
- }
64
- .ghost {
65
- background: transparent;
66
- }
67
- .dim {
68
- color: var(--dim);
69
- }
70
- .small {
71
- font-size: 12px;
72
- margin-top: 6px;
73
- }
74
- .err {
75
- color: var(--err);
76
- display: flex;
77
- flex-direction: column;
78
- gap: 6px;
79
- padding: 10px;
80
- font-size: 12px;
81
- overflow: auto;
82
- }
83
- .app {
84
- min-height: 100vh;
85
- display: flex;
86
- flex-direction: column;
87
- }
88
- header {
89
- display: flex;
90
- align-items: baseline;
91
- gap: 14px;
92
- padding: 12px 20px;
93
- border-bottom: 1px solid var(--line);
94
- }
95
- h1 {
96
- font-size: 16px;
97
- margin: 0;
98
- }
99
- h2 {
100
- font-size: 12px;
101
- text-transform: uppercase;
102
- letter-spacing: 0.08em;
103
- color: var(--dim);
104
- margin: 4px 0 10px;
105
- }
106
- .body {
107
- display: flex;
108
- flex: 1;
109
- min-height: 0;
110
- }
111
- aside {
112
- width: 280px;
113
- flex-shrink: 0;
114
- padding: 16px;
115
- border-right: 1px solid var(--line);
116
- background: var(--panel);
117
- }
118
- aside label {
119
- display: block;
120
- color: var(--dim);
121
- margin: 14px 0 6px;
122
- }
123
- label.check {
124
- display: flex;
125
- gap: 8px;
126
- align-items: center;
127
- color: var(--text);
128
- margin: 10px 0 0;
129
- cursor: pointer;
130
- }
131
- .drop {
132
- border: 1px dashed var(--line);
133
- border-radius: 8px;
134
- min-height: 140px;
135
- display: grid;
136
- place-items: center;
137
- cursor: pointer;
138
- overflow: hidden;
139
- }
140
- .drop.over {
141
- border-color: var(--accent);
142
- }
143
- .drop img {
144
- display: block;
145
- width: 100%;
146
- }
147
- .samples {
148
- display: flex;
149
- gap: 6px;
150
- flex-wrap: wrap;
151
- margin-top: 10px;
152
- }
153
- .samples img {
154
- width: 40px;
155
- height: 40px;
156
- object-fit: cover;
157
- border-radius: 4px;
158
- cursor: pointer;
159
- opacity: 0.8;
160
- }
161
- .samples img:hover {
162
- opacity: 1;
163
- }
164
- .seg {
165
- display: flex;
166
- }
167
- .seg button {
168
- flex: 1;
169
- border-radius: 0;
170
- }
171
- .seg button:first-child {
172
- border-radius: 6px 0 0 6px;
173
- }
174
- .seg button:last-child {
175
- border-radius: 0 6px 6px 0;
176
- }
177
- .seg button.on {
178
- background: #2c3542;
179
- border-color: var(--accent);
180
- }
181
- main {
182
- flex: 1;
183
- padding: 16px 20px 40px;
184
- overflow: auto;
185
- }
186
- section + section {
187
- margin-top: 24px;
188
- }
189
- .grid {
190
- display: grid;
191
- grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
192
- gap: 14px;
193
- }
194
- .card {
195
- background: var(--card);
196
- border: 1px solid var(--line);
197
- border-radius: 8px;
198
- overflow: hidden;
199
- }
200
- .card.off {
201
- opacity: 0.6;
202
- }
203
- .cardHead {
204
- display: flex;
205
- justify-content: space-between;
206
- gap: 8px;
207
- padding: 8px 10px;
208
- }
209
- .name {
210
- font-weight: 600;
211
- }
212
- .fam {
213
- font-weight: 400;
214
- color: var(--dim);
215
- }
216
- .meta {
217
- color: var(--dim);
218
- white-space: nowrap;
219
- }
220
- .frame {
221
- background: #0c0d0f;
222
- display: grid;
223
- place-items: center;
224
- position: relative;
225
- overflow: hidden;
226
- }
227
- .card.done .frame {
228
- cursor: zoom-in;
229
- }
230
- .frame > img,
231
- .frame > canvas {
232
- width: 100%;
233
- height: 100%;
234
- object-fit: contain;
235
- display: block;
236
- }
237
- .frame .dim {
238
- display: flex;
239
- flex-direction: column;
240
- align-items: center;
241
- gap: 4px;
242
- }
243
- .blurb {
244
- padding: 8px 10px;
245
- color: var(--dim);
246
- font-size: 12px;
247
- }
248
- .missing {
249
- display: flex;
250
- flex-direction: column;
251
- gap: 4px;
252
- padding: 10px;
253
- font-size: 11px;
254
- word-break: break-all;
255
- }
256
- .missing a {
257
- color: var(--accent);
258
- }
259
- .spin {
260
- display: inline-block;
261
- width: 12px;
262
- height: 12px;
263
- border: 2px solid var(--line);
264
- border-top-color: var(--accent);
265
- border-radius: 50%;
266
- animation: spin 0.8s linear infinite;
267
- vertical-align: -2px;
268
- }
269
- @keyframes spin {
270
- to {
271
- transform: rotate(360deg);
272
- }
273
- }
274
- .focus {
275
- position: fixed;
276
- inset: 0;
277
- background: rgba(0, 0, 0, 0.75);
278
- display: grid;
279
- place-items: center;
280
- padding: 24px;
281
- z-index: 10;
282
- }
283
- .focusBox {
284
- background: var(--panel);
285
- border: 1px solid var(--line);
286
- border-radius: 10px;
287
- width: min(1200px, 100%);
288
- max-height: 100%;
289
- display: flex;
290
- flex-direction: column;
291
- overflow: hidden;
292
- }
293
- .focusBar {
294
- display: flex;
295
- align-items: center;
296
- gap: 10px;
297
- padding: 10px 14px;
298
- border-bottom: 1px solid var(--line);
299
- }
300
- .focusBar b {
301
- margin-right: auto;
302
- }
303
18
  .wipe {
304
19
  position: relative;
305
20
  flex-shrink: 0;
@@ -0,0 +1,80 @@
1
+ // what every explorer catalog shares: an entry's card facts, the weight files it needs, and its
2
+ // availability read from the LIVE host schema (a node or a weight file missing → the card shows
3
+ // the files and their urls instead of a run button).
4
+ import type { BaseNodeFactory, ComfyWorkflow } from 'comfy-ts'
5
+
6
+ /** a weight file the graph names, and where to get it when the host lacks it */
7
+ export type WeightFile = { node: string; input: string; file: string; folder: string; url: string }
8
+
9
+ /** the facts a card shows, and what the host must have to run the entry */
10
+ export type CatalogEntry = {
11
+ id: string
12
+ label: string
13
+ family: string
14
+ year: number
15
+ /** when it came out, as precise as known: `2025-11` */
16
+ date: string
17
+ /** its weights on disk */
18
+ size: string
19
+ /** 1 (rough) to 5 (the best of its kind), judged on the explorer's samples */
20
+ quality: number
21
+ /** one run on an RTX class GPU, weights loaded */
22
+ speed: string
23
+ blurb: string
24
+ nodes: string[]
25
+ /** weights the host must list; a node pack that downloads its own on the first run lists none */
26
+ files: WeightFile[]
27
+ /** the node pack downloads its weights on the first run (slow once) */
28
+ autoDownload?: boolean
29
+ }
30
+
31
+ /** a factory of the base (untyped) builder, or a loud error naming the node. For graphs that name
32
+ * weight files the generated host sdk does not know until they are downloaded */
33
+ export function base<ID extends string>(wf: ComfyWorkflow<ID>, name: string): BaseNodeFactory {
34
+ const f = wf.builderBase[name]
35
+ if (f == null) throw new Error(`this host has no ${name} node`)
36
+ return f
37
+ }
38
+
39
+ /** raw object_info, as the host schema keeps it */
40
+ export type ObjectInfo = Record<
41
+ string,
42
+ { input?: { required?: Record<string, unknown>; optional?: Record<string, unknown> } }
43
+ >
44
+
45
+ /** the options of a COMBO input in both object_info spellings: [[...]] and ['COMBO', { options }] */
46
+ function comboOptions(info: ObjectInfo, node: string, input: string): string[] {
47
+ const def = info[node]?.input
48
+ const slot = def?.required?.[input] ?? def?.optional?.[input]
49
+ if (!Array.isArray(slot)) return []
50
+ const head: unknown = slot[0]
51
+ if (Array.isArray(head)) return head.filter((x): x is string => typeof x === 'string')
52
+ const meta: unknown = slot[1]
53
+ const opts: unknown = typeof meta === 'object' && meta != null && 'options' in meta ? meta.options : null
54
+ return Array.isArray(opts) ? opts.filter((x): x is string => typeof x === 'string') : []
55
+ }
56
+
57
+ export type Availability = { ok: boolean; missingNodes: string[]; missingFiles: WeightFile[] }
58
+
59
+ export function availability(info: ObjectInfo, m: CatalogEntry): Availability {
60
+ const missingNodes = m.nodes.filter((n) => info[n] == null)
61
+ const missingFiles = m.files.filter((f) => !comboOptions(info, f.node, f.input).includes(f.file))
62
+ return { ok: missingNodes.length === 0 && missingFiles.length === 0, missingNodes, missingFiles }
63
+ }
64
+
65
+ /** an entry as the page gets it: its card facts and its availability, never its graph */
66
+ export function entryPayload(info: ObjectInfo, m: CatalogEntry): Record<string, unknown> {
67
+ return {
68
+ id: m.id,
69
+ label: m.label,
70
+ family: m.family,
71
+ year: m.year,
72
+ blurb: m.blurb,
73
+ date: m.date,
74
+ size: m.size,
75
+ quality: m.quality,
76
+ speed: m.speed,
77
+ autoDownload: m.autoDownload === true,
78
+ ...availability(info, m),
79
+ }
80
+ }