@melite/models-h3 0.2.2-alpha → 0.2.3-rc.4

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/lib/chainEdit.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { LANE_FILES, h3LoraStackOf, h3ShiftVideoOf } from './actions.js';
2
+ import { mountRefModBake } from './refmodBake.js';
3
+ import { wireList } from './schema.js';
4
+ import { REF_CAPS } from './timelineContract.js';
2
5
 
3
6
 
4
7
 
@@ -20,6 +23,42 @@ export const loadVideo = (g, path, frameLoadCap = 0, skipFirstFrames = 0) => {
20
23
  return [n.out(0), n.out(2)];
21
24
  };
22
25
 
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+ export const contexMaskedTarget = (g, plane, source) => {
49
+ const edit = g.node('MiniMaxH3FantasticVideoEditLatent', {
50
+ grow: 0, keep_audio: source.keepAudio, megapixels: 0,
51
+ vae: plane.vaeVideo, images: source.frames, mask: source.mask,
52
+ audio_vae: plane.vaeAudio, audio: source.audio,
53
+ }).out(0);
54
+ return g.node('MiniMaxH3ContexMaskedTarget', {
55
+ mask_meaning: 'white = generate',
56
+ audio_mode: source.keepAudio ? 'preserve source audio' : 'generate all audio',
57
+ mask_conversion: 'H3 exact (causal/token max)',
58
+ target_latent: edit, mask: source.mask,
59
+ }).out(0);
60
+ };
61
+
23
62
  // Two resolution regimes live in one family: the FILM path renders
24
63
  // at the doc's own width/height (schema defaults 1344×768), the mod
25
64
  // bags (replace/repair/extend) render at a plan TIER — a short-edge
@@ -53,6 +92,43 @@ export const planTierShape = (width, height, shortEdge) => {
53
92
  height: Math.max(32, Math.round(height * scale / 32) * 32),
54
93
  };
55
94
  };
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+ export const planTierPinOf = (filmWidth, filmHeight) => {
107
+ const filmShort = Math.min(filmWidth, filmHeight);
108
+ const exact = Object.entries(RESOLUTION_SHORT_EDGE).find(([, e]) => e === filmShort)?.[0];
109
+ if (exact !== undefined)
110
+ return exact;
111
+ return Object.keys(RESOLUTION_SHORT_EDGE).reduce((best, k) => {
112
+ const d = Math.abs(RESOLUTION_SHORT_EDGE[k] - filmShort);
113
+ const bd = Math.abs(RESOLUTION_SHORT_EDGE[best] - filmShort);
114
+ return d < bd || (d === bd && RESOLUTION_SHORT_EDGE[k] < RESOLUTION_SHORT_EDGE[best]) ? k : best;
115
+ }, '736p');
116
+ };
117
+ /** P0-3 — the entry's stated tier VERBATIM, else the film's own
118
+ * pin: 'auto' (the form's derived default) and absence both derive.
119
+ * The agent never states a tier unless they mean to override the
120
+ * film's own geometry.
121
+ * @param entry the cell's bound entry (resolution seat)
122
+ * @param p the walked doc params (the film regime's width/height)
123
+ * @returns the tier label the plan node takes */
124
+ export const resolvePlanTier = (entry, p) => {
125
+ const stated = typeof entry['resolution'] === 'string' ? entry['resolution'] : '';
126
+ if (stated !== '' && stated !== 'auto')
127
+ return stated;
128
+ const w = typeof p['width'] === 'number' ? p['width'] : 1344;
129
+ const h = typeof p['height'] === 'number' ? p['height'] : 768;
130
+ return planTierPinOf(w, h);
131
+ };
56
132
  /** THE CROSS-REGIME JOIN ADMISSION: given the film regime's shape
57
133
  * (the doc's width/height — the shape this estate's film arm
58
134
  * renders and the join appends onto) and the mod bag's tier, answer
@@ -149,6 +225,20 @@ export const h3MaskedEditPlane = (g, p, facts, clipSeconds) => {
149
225
  const samplerSel = g.node('KSamplerSelect', { sampler_name: 'euler' }).out();
150
226
  return { sigmaModel, samplerSel, clip, vaeVideo, vaeAudio };
151
227
  };
228
+ /** Wire the sheet handles into an r2v creator's image slots at the
229
+ * cell's first free index (each cell owns its anchor count; the
230
+ * spine owns the load + the cap). A symmetric input slot to the
231
+ * agent, machinery to the graph.
232
+ * @param refImages the declared sheet handles (possibly empty).
233
+ * @param base the cell's first free ref_images index.
234
+ * @returns dotted-slot inputs for the creator node. */
235
+ export function sheetRefSlots(refImages, base) {
236
+ const out = {};
237
+ refImages.forEach((h, i) => {
238
+ out[`ref_images.ref_image_${base + i}`] = h;
239
+ });
240
+ return out;
241
+ }
152
242
 
153
243
 
154
244
 
@@ -164,6 +254,43 @@ export const h3MaskedEditPlane = (g, p, facts, clipSeconds) => {
164
254
  * engine-side band move can never silently outdate the clamp. */
165
255
  export const PLAN_CLIP_BAND = { min: 2.5, max: 15.0 };
166
256
  const planClipFeed = (seconds) => Math.min(PLAN_CLIP_BAND.max, Math.max(PLAN_CLIP_BAND.min, seconds));
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+ export const PLAN_OVERLAP_CHOICES = [22, 39, 56];
273
+ /** THE PLAN-HEAD OVERLAP FEED (the bench-burn cure): the widget
274
+ * always rides a legal choice, and the ONLY join a source-slicing
275
+ * plan head serves is the AV-legal 39 — the one value both
276
+ * vocabularies share. Authored-shot seats (planFromSource false:
277
+ * the literal plan_json rules, the plan node's output is unread)
278
+ * ride the node's own default 39 on the inert widget; a join ≠ 39
279
+ * there is served where it lives, on the shots' context_length. A
280
+ * source-slicing seat (planFromSource true) that resolves a join ≠ 39
281
+ * REFUSES HERE, at the compose door, naming the cure — the run dies
282
+ * at zero GPU, never eight nodes deep at submit.
283
+ * @param overlapFrames the resolver's join (resolveCarryOverlap)
284
+ * @param literalShotsRules whether authored shots rule this run
285
+ * @returns the widget value: always a legal choice */
286
+ const planOverlapFeed = (overlapFrames, literalShotsRules) => {
287
+ if (literalShotsRules)
288
+ return 39;
289
+ if (overlapFrames !== 39) {
290
+ throw new Error(`h3-timeline edit chain: the join ${overlapFrames} cannot ride the source-slicing plan head — H3OneClickSwapPlan.overlap_frames carries the live engine's [${PLAN_OVERLAP_CHOICES.join(', ')}] and the AV-legal join a masked edit serves is 39; a CUT (0) serves AUTHORED windows only (the shot's own context_length 0 — split the film on the timeline first, then state carry: false), and the wider AV boundaries (90/141/192/243) belong to authored seams, never the plan head's own slicing. Leave carry unstated (or carry: true) and the join derives 39`);
291
+ }
292
+ return 39;
293
+ };
167
294
  /** Emit the shared masked-edit chain for one seat. The node
168
295
  * parameters are the three seats' historical spellings, verbatim;
169
296
  * the seat's deltas arrive through the seat interface. The emission
@@ -194,7 +321,7 @@ export function renderMaskedEditChain(g, seat) {
194
321
  // rides default_duration_seconds below, never this seat ──
195
322
  const plan = g.node('H3OneClickSwapPlan', {
196
323
  clip_seconds: planClipFeed(seat.clipSeconds),
197
- overlap_frames: seat.overlapFrames,
324
+ overlap_frames: planOverlapFeed(seat.overlapFrames, !seat.planFromSource),
198
325
  resolution: seat.resolution,
199
326
  steps: seat.steps,
200
327
  seed: seat.seed,
@@ -258,27 +385,71 @@ export function renderMaskedEditChain(g, seat) {
258
385
  const mutedChainAudio = g.node('AudioAdjustVolume', {
259
386
  volume: -100, audio: cur.out(12),
260
387
  }).out(0);
388
+ // ── THE SHEET (P0-1's second half): ref_images stated once at
389
+ // the doc level, loaded once here, wired by the cell at its first
390
+ // free slot. The cap is the one the gen door states (the bag's
391
+ // own max_stack, REF_CAPS.images): one number for both doors, the
392
+ // slot INDEX merely shifts under a cell's own anchor. A longer
393
+ // sheet refuses LOUD (the gen bus law — never a silent clobber
394
+ // onto the video lane). ──
395
+ const sheetRefs = wireList(seat.p.ref_images);
396
+ if (sheetRefs.length > REF_CAPS.images) {
397
+ throw new Error(`[h3-timeline] ref_images exceeds the reference-image cap (saw ${String(sheetRefs.length)}, max ${String(REF_CAPS.images)})`);
398
+ }
399
+ const refImages = sheetRefs.map((src) => g.node('LoadImage', { image: src, upload: 'image' }).out(0));
261
400
  // ── the seat's masked-edit body (anchors + slice + edit latent +
262
401
  // masked target — the seat's true deltas) ──
263
- const { conditioning, targetLatent } = seat.body({
402
+ const { conditioning: bodyCond, targetLatent } = seat.body({
264
403
  cur, clip, vaeVideo, vaeAudio, mutedChainAudio,
265
- srcFrames: seat.srcFrames, sliceAudio,
404
+ srcFrames: seat.srcFrames, sliceAudio, refImages,
266
405
  });
406
+ // ── THE REFMOD BAKE (P0-1's first half): the identical bake the
407
+ // film path mounts, appended onto the edit conditioning — the
408
+ // chain applies it to every window (the loop's own conditioning
409
+ // seat), so the bake is per-window through the chain's own law.
410
+ // An empty seat returns the handle untouched (byte-stable). ──
411
+ const conditioning = mountRefModBake(g, { p: seat.p, cond: bodyCond, vaeVideo, vaeAudio });
267
412
  const ctx = g.node('MiniMaxH3ChainContext', {
268
413
  state: cur.out(0), conditioning,
269
414
  vae: vaeVideo, latent: targetLatent, audio_vae: vaeAudio,
270
415
  });
271
416
  // ── the sampler tail (the denoise pole is the seat's one knob:
272
- // full 1 fresh — swap/extend; partial refine — the repair's law) ──
273
- const sample = g.node('SamplerCustomAdvanced', {
274
- noise: g.node('RandomNoise', { noise_seed: cur.out(5) }).out(0),
275
- guider: g.node('BasicGuider', { model: sigmaModel, conditioning: ctx.out(0) }).out(0),
276
- sampler: samplerSel,
277
- sigmas: g.node('BasicScheduler', {
278
- scheduler: 'simple', steps: cur.out(7), denoise: seat.denoise, model: sigmaModel,
279
- }).out(0),
280
- latent_image: ctx.out(3),
281
- }).out(0);
417
+ // full 1 fresh — swap/extend; partial refine — the repair's law).
418
+ // THE UPSCALE DIAL (the fourth dial): refine on swaps the tail
419
+ // for the learned RefineHandoff — the SAME latent (ctx.out(3)),
420
+ // the SAME conditioning (ctx.out(0)), the same noise/sampler/
421
+ // sigmas; the node upscales the joint-AV latent and runs the
422
+ // low-sigma pass internally (refine.ts's own wiring, riding the
423
+ // chain's LIVE latents). Downstream seats consume the same
424
+ // sampled-latent seam — segments still checkpoint (the chain
425
+ // store that writes the revisions a deferred upscale reads). ──
426
+ const sample = seat.upscale === undefined
427
+ ? g.node('SamplerCustomAdvanced', {
428
+ noise: g.node('RandomNoise', { noise_seed: cur.out(5) }).out(0),
429
+ guider: g.node('BasicGuider', { model: sigmaModel, conditioning: ctx.out(0) }).out(0),
430
+ sampler: samplerSel,
431
+ sigmas: g.node('BasicScheduler', {
432
+ scheduler: 'simple', steps: cur.out(7), denoise: seat.denoise, model: sigmaModel,
433
+ }).out(0),
434
+ latent_image: ctx.out(3),
435
+ }).out(0)
436
+ : g.node('MinimaxH3LatentUpscaler3DRefineHandoff', {
437
+ latent: ctx.out(3),
438
+ noise: g.node('RandomNoise', { noise_seed: cur.out(5) }).out(0),
439
+ sampler: samplerSel,
440
+ sigmas: g.node('BasicScheduler', {
441
+ scheduler: 'simple', steps: cur.out(7), denoise: seat.denoise, model: sigmaModel,
442
+ }).out(0),
443
+ model: sigmaModel,
444
+ positive: ctx.out(0),
445
+ model_name: seat.upscale.modelName,
446
+ mode: seat.upscale.mode,
447
+ scale: seat.upscale.scale,
448
+ width: 1280, height: 704, megapixels: 1,
449
+ keep_proportion: true, align: 32,
450
+ lock_audio: true, cfg: 1.0, device: 'cuda', precision: 'bf16',
451
+ offload_after_upscale: false,
452
+ }).out(0);
282
453
  const decoded = g.node('VAEDecode', { samples: sample, vae: vaeVideo }).out(0);
283
454
  const decodedAudio = g.node('VAEDecodeAudio', { samples: sample, vae: vaeAudio }).out(0);
284
455
  const trimmed = g.node('MiniMaxH3LoopTrim', {
@@ -1,5 +1,6 @@
1
1
  import { h3MaskedEditPlane } from './chainEdit.js';
2
2
  import { REFINE_UPSCALE_MODEL } from './refine.js';
3
+ import { FULL_NOISE_REASON, fullNoiseClause } from './secondPass.js';
3
4
  /** The upscale entry's required seats (the reshoot idiom: an armed
4
5
  * doc with an empty seat refuses loud naming the seat). */
5
6
  const REQUIRED_SEATS = [
@@ -39,8 +40,10 @@ export function renderH3ChainUpscale(entry, p, facts, g, runId) {
39
40
  }
40
41
  }
41
42
  const denoise = num(entry, 'denoise', 0.24);
43
+ // THE SHARED FULL-NOISE LAW (secondPass.ts): the clause and the
44
+ // reason are the seat's own — this door names its window.
42
45
  if (denoise >= 1) {
43
- throw new Error(`h3-timeline upscale: denoise ${denoise} >= 1 — a second pass is an upscale, never a re-render (the recipe's pass-2 window is 0.24; a full-noise sigma discards the learned upscaled latent — that is a reshoot, and the reshoot door exists)`);
46
+ throw new Error(`h3-timeline upscale: denoise ${denoise} >= 1 — ${fullNoiseClause('upscale')} (the recipe's pass-2 window is 0.24; ${FULL_NOISE_REASON} — that is a reshoot, and the reshoot door exists)`);
44
47
  }
45
48
  const steps = num(entry, 'steps', 20);
46
49
  const segmentCrf = num(entry, 'segment_crf', 18);
package/lib/edit.d.ts ADDED
@@ -0,0 +1,103 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ import type { GraphBuilder } from '@melite/comfyui-card-kit/graph';
31
+ import type { H3Facts } from './actions.js';
32
+ /** The near-full-denoise floor of the identity-safety refusal. */
33
+ export declare const EDIT_IDENTITY_BOIL_FLOOR = 0.8;
34
+ /** THE MASK DIAL — where the edit happens.
35
+ * `static-png`: ONE staged PNG (the track run's pixel-max union is
36
+ * the recommended bridge — per-frame motion is the region dial's
37
+ * own door, N7). `region`: the free-text SAM3 per-frame track
38
+ * (repair's own chain, tuning seats exposed — N8). `video`: the
39
+ * operator's OWN per-frame mask staged as a video (the track card's
40
+ * mask export or any greyscale ride) — decoded red-channel per
41
+ * frame, geometry-cured in-graph, then THE LENGTH-MATCH CHECK: the
42
+ * mask's frames must equal the clip's as loaded, refused loud
43
+ * engine-side naming both counts (a staged file's frame count is
44
+ * engine knowledge, never compose knowledge). `whole-frame`: the
45
+ * all-white SolidMask (extend's spelling — nothing held). */
46
+ export type EditMaskDial = {
47
+ readonly source: 'static-png';
48
+ readonly image: string;
49
+ } | {
50
+ readonly source: 'region';
51
+ readonly prompt: string;
52
+ readonly grow: number;
53
+ readonly blur: number;
54
+ readonly detectionThreshold: number;
55
+ } | {
56
+ readonly source: 'video';
57
+ readonly video: string;
58
+ readonly grow: number;
59
+ readonly blur: number;
60
+ } | {
61
+ readonly source: 'whole-frame';
62
+ };
63
+ /** THE REFERENCE DIAL — the identity anchors the r2v rides.
64
+ * `still+mannequin`: swap's pair (the still anchors appearance, the
65
+ * mannequin carries motion). `self`: repair's posture (the source
66
+ * clip on its own ref_video seat — the identity anchor of a repair
67
+ * is the person already in the frame). The continuation pole is
68
+ * a free cell since slice 2: the continuation dial delegates to
69
+ * renderH3Extend's own law set (the composition solver + the
70
+ * forced AddGuide seam) under the blank mask, self anchors, and
71
+ * full denoise. The no-reference second pass
72
+ * IS a free cell since the fourth dial landed: the refine posture
73
+ * composes as whole-frame × self × partial denoise × refine on —
74
+ * the learned handoff riding THIS chain's own latents. */
75
+ export type EditReferenceDial = {
76
+ readonly mode: 'still+mannequin';
77
+ readonly still: string;
78
+ readonly mannequin: string;
79
+ } | {
80
+ readonly mode: 'self';
81
+ };
82
+ /** THE VIDEO-EDIT MATRIX RENDERER: composes one free cell of the
83
+ * mask × reference × denoise matrix on the family's one chain
84
+ * spine. Validates the safety law, derives the dial's own mask and
85
+ * anchors, and hands a body that rides contexMaskedTarget — the
86
+ * stage-1 seam, never a hand-rolled pair.
87
+ * @param entry the edit entry's own seats (edit_prompt, denoise,
88
+ * keep_audio, seed, steps, clip_seconds, overlap_frames,
89
+ * resolution, window_start, window_length, mask_grow, mask_blur,
90
+ * detection_threshold — the card's one bag)
91
+ * @param mask the mask dial's resolved value
92
+ * @param reference the reference dial's resolved value
93
+ * @param p the walked doc params (the lora mod bag + SLA/shift
94
+ * knobs — the family plane this edit renders under)
95
+ * @param facts the family's lane facts (unet off the DECL row)
96
+ * @param g the run's graph builder
97
+ * @param runId the run tree's id (the assemble filename rides it)
98
+ * @throws refuses the identity boil (whole-frame × self × denoise
99
+ * >= 0.8), the incoherent audio drop (partial denoise ×
100
+ * keep_audio false), the off-grid stated window, and the negative
101
+ * window seats — each loud, each naming the dial to state */
102
+ export declare function renderH3Edit(entry: Record<string, unknown>, mask: EditMaskDial, reference: EditReferenceDial, p: Record<string, unknown>, facts: H3Facts, g: GraphBuilder, runId: string): void;
103
+ //# sourceMappingURL=edit.d.ts.map