Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: unify image/video resolution UX into shared ResolutionField (#2436)

Adam Eivybc7ada7ce400
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 85fadf1c79..874bd1ba28 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -8,6 +8,8 @@
- **Shell page quick-command buttons trimmed to the interactive tools.** Dropped the four shell one-liner shortcuts (`git status`, `git pull`, `npm test`, `npm run dev`) that duplicated things you'd just type, renamed the `antigravity` button to its actual command `agy`, and added a `grok` button alongside the other coding-agent launchers.
+- **Image and video generators now share one resolution control (#2436).** The image (`ImageGenControls`) and video (`VideoGen`) size pickers had diverged into two separate "preset dropdown + custom W×H" implementations over the same helper tables — and VideoGen rendered its Width/Height inputs twice. Both now consume a single `components/media/ResolutionField.jsx` (preset `<select>` + a "Custom…" sentinel that reveals gated Width/Height inputs with a blur-snap), and `clampImageEdge` in `imageGenResolutions.js` is generalized to accept `{ min, max, step }` so video (64–2048, multiples of 64) reuses it instead of its own ad-hoc handler. Behavior-preserving cleanup deferred from the custom-image-dimensions slice.
+
## Fixes
- **The CoS agent briefing no longer prints a redundant "Target Application" heading for the PortOS default app on the api-prompt path (#2430).** The light/fallback prompt path already suppressed the target-app line for `portos-default` (the agent runs in the PortOS directory, so it adds nothing), but the editable `cos-agent-briefing` stage template still rendered the heading for any task carrying an app id. The template now gates the stock heading on a precomputed `targetAppLabel` (empty for the default app, the app id for managed apps) that `agentPromptBuilder.js` threads into the render context — mirroring `buildTaskBlock`'s predicate — while leaving `task.metadata.app` in the context untouched for any custom template references. Ships as stage-prompt migration 187 (hash-matched, cross-synced with 010's accepted-hash chain) so unmodified installs auto-upgrade and customized copies are left alone.
diff --git a/client/src/components/imageGen/ImageGenControls.jsx b/client/src/components/imageGen/ImageGenControls.jsx
index acc6cb67e0..0db3a82be0 100644
--- a/client/src/components/imageGen/ImageGenControls.jsx
+++ b/client/src/components/imageGen/ImageGenControls.jsx
@@ -8,16 +8,13 @@
// reshaping. `mode` drives which knobs are visible: codex hides everything except
// resolution; external swaps guidance for cfgScale; local shows guidance + quantize.
-import { useState, useEffect } from 'react';
import { Dice5 } from 'lucide-react';
-import {
- filterResolutions, resolveResolutionLabel, clampImageEdge,
- CUSTOM_RESOLUTION_VALUE, MAX_IMAGE_EDGE, MAX_IMAGE_PIXELS,
-} from '../../lib/imageGenResolutions';
+import { filterResolutions, MAX_IMAGE_EDGE, MAX_IMAGE_PIXELS } from '../../lib/imageGenResolutions';
import { randomSeed } from '../../lib/genUtils';
import { RUNNER_FAMILIES } from '../../lib/runnerFamilies';
import { IMAGE_GEN_MODE } from '../../lib/imageGenBackends';
import ModelDownloadBadge, { deriveSizeEstimate } from '../media/ModelDownloadBadge';
+import ResolutionField from '../media/ResolutionField';
import { FormField } from '../ui/FormField';
const QUANTIZE_OPTIONS = [
@@ -61,46 +58,9 @@ export default function ImageGenControls({
const isFlux2 = currentModel?.runner === RUNNER_FAMILIES.FLUX2;
// Filter by backend; a stale w/h (e.g. Flux 2 → Flux 1 with 1536 still set)
- // falls through to the custom inputs below so the value stays visible and
- // editable until the user picks a supported preset.
+ // falls through to the custom inputs (rendered by ResolutionField) so the
+ // value stays visible and editable until the user picks a supported preset.
const availableResolutions = filterResolutions(mode, currentModel?.runner);
- const { matched } = resolveResolutionLabel(availableResolutions, width, height);
- // Custom mode is sticky once opened (so a preset-matching size the user is
- // mid-edit doesn't snap the dropdown back to a preset) but also auto-engages
- // whenever the current dimensions match no preset (remix, uploaded photo, a
- // stale off-backend size) so the inputs appear without an extra click.
- const [customOpen, setCustomOpen] = useState(false);
- const isCustom = customOpen || (!matched && !!width && !!height);
- const selectValue = isCustom ? CUSTOM_RESOLUTION_VALUE : (matched?.label ?? '');
- // Latch custom mode stickily once a non-preset size appears (remix, uploaded
- // photo, stale off-backend size). Without this, clearing a Width/Height field
- // to a transient 0 mid-edit would flip `!matched && width && height` false and
- // unmount the inputs the user is typing into — which also skips the blur-snap.
- // `handleResolution` still clears the latch when a preset is explicitly picked.
- useEffect(() => {
- if (!matched && width && height) setCustomOpen(true);
- }, [matched, width, height]);
- const handleResolution = (e) => {
- if (e.target.value === CUSTOM_RESOLUTION_VALUE) { setCustomOpen(true); return; }
- const r = availableResolutions.find((opt) => opt.label === e.target.value);
- if (r) { setCustomOpen(false); onResolutionChange?.(r.w, r.h); }
- };
- // Live edits pass through raw so typing feels natural (0 = mid-edit/empty);
- // the blur handler clamps to the server's [64, MAX_IMAGE_EDGE] per-edge bounds.
- const handleCustomDim = (axis, raw) => {
- const n = Math.floor(Number(raw));
- // n > 0 already excludes NaN; Infinity can't come from a number input and
- // would clamp to MAX_IMAGE_EDGE anyway. 0 = mid-edit/empty.
- const v = n > 0 ? Math.min(MAX_IMAGE_EDGE, n) : 0;
- if (axis === 'w') onResolutionChange?.(v, height || 0);
- else onResolutionChange?.(width || 0, v);
- };
- const snapCustomDim = (axis) => {
- if (axis === 'w') onResolutionChange?.(clampImageEdge(width), height || 0);
- else onResolutionChange?.(width || 0, clampImageEdge(height));
- };
- const pixelCount = (width || 0) * (height || 0);
- const overPixelCap = pixelCount > MAX_IMAGE_PIXELS;
const inputCls = 'w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50';
@@ -127,51 +87,23 @@ export default function ImageGenControls({
</FormField>
)}
- <FormField label="Resolution" labelClassName="block text-xs font-medium text-gray-400 mb-1">
- <select
- value={selectValue}
- onChange={handleResolution}
- disabled={disabled}
- className={inputCls}
- >
- {availableResolutions.map((r) => <option key={r.label} value={r.label}>{r.label}</option>)}
- <option value={CUSTOM_RESOLUTION_VALUE}>Custom…</option>
- </select>
- </FormField>
-
- {/* Arbitrary width/height. The server accepts any edge in [64, 3840] with
- total pixels ≤ 8.29M (imageEdgeSchema + refineImagePixelCap), so custom
- sizes like 704×1280 (9:16 portrait) work without a new preset. Step 8
- keeps values latent-friendly for the local diffusion runners. */}
- {isCustom && (
- <>
- <FormField label="Width" labelClassName="block text-xs font-medium text-gray-400 mb-1">
- <input
- type="number" min={64} max={MAX_IMAGE_EDGE} step={8}
- value={width || ''}
- onChange={(e) => handleCustomDim('w', e.target.value)}
- onBlur={() => snapCustomDim('w')}
- disabled={disabled}
- className={inputCls}
- />
- </FormField>
- <FormField label="Height" labelClassName="block text-xs font-medium text-gray-400 mb-1">
- <input
- type="number" min={64} max={MAX_IMAGE_EDGE} step={8}
- value={height || ''}
- onChange={(e) => handleCustomDim('h', e.target.value)}
- onBlur={() => snapCustomDim('h')}
- disabled={disabled}
- className={inputCls}
- />
- </FormField>
- <p className={`col-span-full text-[10px] -mt-1 ${overPixelCap ? 'text-port-error' : 'text-gray-500'}`}>
- {overPixelCap
- ? `Too large — ${pixelCount.toLocaleString()} px exceeds the ${MAX_IMAGE_PIXELS.toLocaleString()} px cap. Reduce width or height.`
- : `Each edge 64–${MAX_IMAGE_EDGE}px, total ≤ ${MAX_IMAGE_PIXELS.toLocaleString()} px. Multiples of 8 render best on local models.`}
- </p>
- </>
- )}
+ {/* Preset dropdown + arbitrary width/height. The server accepts any edge
+ in [64, 3840] with total pixels ≤ 8.29M (imageEdgeSchema +
+ refineImagePixelCap), so custom sizes like 704×1280 (9:16 portrait)
+ work without a new preset. Step 8 keeps values latent-friendly for
+ the local diffusion runners. */}
+ <ResolutionField
+ presets={availableResolutions}
+ width={width}
+ height={height}
+ onChange={onResolutionChange}
+ min={64}
+ max={MAX_IMAGE_EDGE}
+ step={8}
+ maxPixels={MAX_IMAGE_PIXELS}
+ disabled={disabled}
+ inputClassName={inputCls}
+ />
{/* Codex's image_gen tool ignores seed/steps/guidance — only resolution
is honored, so the rest of the knobs are hidden in that mode. */}
diff --git a/client/src/components/media/ResolutionField.jsx b/client/src/components/media/ResolutionField.jsx
new file mode 100644
index 0000000000..9f24741b80
--- /dev/null
+++ b/client/src/components/media/ResolutionField.jsx
@@ -0,0 +1,123 @@
+// Shared "preset dropdown + custom W×H" resolution control for the image and
+// video generators. Both pages drive the same UX off their own preset tables
+// (RESOLUTIONS / VIDEO_RESOLUTIONS): a <select> of presets plus a "Custom…"
+// sentinel option that reveals gated Width/Height inputs, with a blur-snap that
+// clamps each edge to the runner's [min, max] bounds and (when step > 1) snaps
+// it down to the nearest multiple of `step`.
+//
+// Renders as a fragment of sibling FormFields (Resolution, then optionally
+// Width + Height + a note) so it slots directly into the caller's field grid —
+// the parent supplies the grid; this owns only the resolution cells.
+//
+// Consumers:
+// - client/src/components/imageGen/ImageGenControls.jsx (image)
+// - client/src/pages/VideoGen.jsx (video)
+
+import { useState, useEffect } from 'react';
+import { FormField } from '../ui/FormField';
+import {
+ resolveResolutionLabel, clampImageEdge, CUSTOM_RESOLUTION_VALUE, MAX_IMAGE_EDGE,
+} from '../../lib/imageGenResolutions';
+
+const DEFAULT_INPUT_CLS = 'w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50';
+
+export default function ResolutionField({
+ presets = [],
+ width, height, onChange,
+ // Per-edge bounds mirroring the server: image = [64, 3840] step 8, video =
+ // [64, 2048] step 64. `step` drives both the number-input spinner and the
+ // blur-snap.
+ min = 64, max = MAX_IMAGE_EDGE, step = 8,
+ // When set, shows a total-pixel-cap warning + note (image only). Omit for
+ // video, whose per-tier budget is enforced elsewhere.
+ maxPixels = null,
+ disabled = false,
+ inputClassName = DEFAULT_INPUT_CLS,
+ labelClassName = 'block text-xs font-medium text-gray-400 mb-1',
+ // Override the (non-error) helper note; defaults to a bounds-derived string.
+ note,
+}) {
+ const { matched } = resolveResolutionLabel(presets, width, height);
+ // Custom mode is sticky once opened (so a preset-matching size the user is
+ // mid-edit doesn't snap the dropdown back to a preset) and also auto-engages
+ // whenever the current dimensions match no preset (remix, uploaded photo, a
+ // stale off-backend size) so the inputs appear without an extra click.
+ const [customOpen, setCustomOpen] = useState(false);
+ const isCustom = customOpen || (!matched && !!width && !!height);
+ const selectValue = isCustom ? CUSTOM_RESOLUTION_VALUE : (matched?.label ?? '');
+ // Latch custom mode stickily once a non-preset size appears. Without this,
+ // clearing a Width/Height field to a transient 0 mid-edit would flip
+ // `!matched && width && height` false and unmount the inputs the user is
+ // typing into — which also skips the blur-snap.
+ useEffect(() => {
+ if (!matched && width && height) setCustomOpen(true);
+ }, [matched, width, height]);
+
+ const bounds = { min, max, step };
+ const handleResolution = (e) => {
+ if (e.target.value === CUSTOM_RESOLUTION_VALUE) { setCustomOpen(true); return; }
+ const r = presets.find((opt) => opt.label === e.target.value);
+ if (r) { setCustomOpen(false); onChange?.(r.w, r.h); }
+ };
+ // Live edits pass through raw so typing feels natural (0 = mid-edit/empty);
+ // the blur handler clamps + snaps to the runner's bounds.
+ const handleCustomDim = (axis, raw) => {
+ const n = Math.floor(Number(raw));
+ const v = n > 0 ? Math.min(max, n) : 0;
+ if (axis === 'w') onChange?.(v, height || 0);
+ else onChange?.(width || 0, v);
+ };
+ const snapCustomDim = (axis) => {
+ if (axis === 'w') onChange?.(clampImageEdge(width, bounds), height || 0);
+ else onChange?.(width || 0, clampImageEdge(height, bounds));
+ };
+ const pixelCount = (width || 0) * (height || 0);
+ const overPixelCap = maxPixels != null && pixelCount > maxPixels;
+ const defaultNote = `Each edge ${min}–${max}px${maxPixels != null ? `, total ≤ ${maxPixels.toLocaleString()} px` : ''}. Multiples of ${step} render best on local models.`;
+
+ return (
+ <>
+ <FormField label="Resolution" labelClassName={labelClassName}>
+ <select
+ value={selectValue}
+ onChange={handleResolution}
+ disabled={disabled}
+ className={inputClassName}
+ >
+ {presets.map((r) => <option key={r.label} value={r.label}>{r.label}</option>)}
+ <option value={CUSTOM_RESOLUTION_VALUE}>Custom…</option>
+ </select>
+ </FormField>
+
+ {isCustom && (
+ <>
+ <FormField label="Width" labelClassName={labelClassName}>
+ <input
+ type="number" min={min} max={max} step={step}
+ value={width || ''}
+ onChange={(e) => handleCustomDim('w', e.target.value)}
+ onBlur={() => snapCustomDim('w')}
+ disabled={disabled}
+ className={inputClassName}
+ />
+ </FormField>
+ <FormField label="Height" labelClassName={labelClassName}>
+ <input
+ type="number" min={min} max={max} step={step}
+ value={height || ''}
+ onChange={(e) => handleCustomDim('h', e.target.value)}
+ onBlur={() => snapCustomDim('h')}
+ disabled={disabled}
+ className={inputClassName}
+ />
+ </FormField>
+ <p className={`col-span-full text-[10px] -mt-1 ${overPixelCap ? 'text-port-error' : 'text-gray-500'}`}>
+ {overPixelCap
+ ? `Too large — ${pixelCount.toLocaleString()} px exceeds the ${maxPixels.toLocaleString()} px cap. Reduce width or height.`
+ : (note || defaultNote)}
+ </p>
+ </>
+ )}
+ </>
+ );
+}
diff --git a/client/src/components/media/ResolutionField.test.jsx b/client/src/components/media/ResolutionField.test.jsx
new file mode 100644
index 0000000000..314e72309d
--- /dev/null
+++ b/client/src/components/media/ResolutionField.test.jsx
@@ -0,0 +1,111 @@
+import { useState } from 'react';
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen, fireEvent } from '@testing-library/react';
+import ResolutionField from './ResolutionField';
+
+const IMAGE_PRESETS = [
+ { label: '1024×1024', w: 1024, h: 1024 },
+ { label: '832×1216 (Flux portrait)', w: 832, h: 1216 },
+];
+const VIDEO_PRESETS = [
+ { label: '768×512 (3:2 default)', w: 768, h: 512 },
+ { label: '1024×576 (16:9)', w: 1024, h: 576 },
+];
+
+const imageBounds = { min: 64, max: 3840, step: 8, maxPixels: 8_294_400 };
+const videoBounds = { min: 64, max: 2048, step: 64 };
+
+describe('ResolutionField — preset dropdown', () => {
+ it('renders every preset plus a Custom… sentinel option', () => {
+ render(<ResolutionField presets={IMAGE_PRESETS} width={1024} height={1024} onChange={vi.fn()} {...imageBounds} />);
+ expect(screen.getByRole('option', { name: 'Custom…' })).toBeTruthy();
+ expect(screen.getByRole('option', { name: '1024×1024' })).toBeTruthy();
+ });
+
+ it('emits w/h when a preset is chosen', () => {
+ const onChange = vi.fn();
+ render(<ResolutionField presets={IMAGE_PRESETS} width={1024} height={1024} onChange={onChange} {...imageBounds} />);
+ fireEvent.change(screen.getByLabelText('Resolution'), { target: { value: '832×1216 (Flux portrait)' } });
+ expect(onChange).toHaveBeenCalledWith(832, 1216);
+ });
+});
+
+describe('ResolutionField — custom W×H', () => {
+ it('hides the inputs when the size matches a preset', () => {
+ render(<ResolutionField presets={IMAGE_PRESETS} width={1024} height={1024} onChange={vi.fn()} {...imageBounds} />);
+ expect(screen.queryByLabelText('Width')).toBeNull();
+ expect(screen.queryByLabelText('Height')).toBeNull();
+ });
+
+ it('reveals the inputs when Custom… is selected', () => {
+ render(<ResolutionField presets={IMAGE_PRESETS} width={1024} height={1024} onChange={vi.fn()} {...imageBounds} />);
+ fireEvent.change(screen.getByLabelText('Resolution'), { target: { value: '__custom__' } });
+ expect(screen.getByLabelText('Width')).toBeTruthy();
+ expect(screen.getByLabelText('Height')).toBeTruthy();
+ });
+
+ it('auto-shows the inputs for an off-preset size', () => {
+ render(<ResolutionField presets={IMAGE_PRESETS} width={704} height={1280} onChange={vi.fn()} {...imageBounds} />);
+ expect(screen.getByLabelText('Width').value).toBe('704');
+ expect(screen.getByLabelText('Height').value).toBe('1280');
+ });
+
+ it('emits the new width while preserving height', () => {
+ const onChange = vi.fn();
+ render(<ResolutionField presets={IMAGE_PRESETS} width={704} height={1280} onChange={onChange} {...imageBounds} />);
+ fireEvent.change(screen.getByLabelText('Width'), { target: { value: '832' } });
+ expect(onChange).toHaveBeenLastCalledWith(832, 1280);
+ });
+
+ it('clamps a below-minimum edge up to min on blur', () => {
+ const onChange = vi.fn();
+ render(<ResolutionField presets={IMAGE_PRESETS} width={10} height={1280} onChange={onChange} {...imageBounds} />);
+ fireEvent.blur(screen.getByLabelText('Width'));
+ expect(onChange).toHaveBeenLastCalledWith(64, 1280);
+ });
+
+ it('snaps a video edge down to the step multiple on blur', () => {
+ const onChange = vi.fn();
+ render(<ResolutionField presets={VIDEO_PRESETS} width={700} height={512} onChange={onChange} {...videoBounds} />);
+ fireEvent.blur(screen.getByLabelText('Width'));
+ // 700 → floor to nearest multiple of 64 → 640
+ expect(onChange).toHaveBeenLastCalledWith(640, 512);
+ });
+
+ it('warns when total pixels exceed the cap (image only)', () => {
+ render(<ResolutionField presets={IMAGE_PRESETS} width={3840} height={3840} onChange={vi.fn()} {...imageBounds} />);
+ expect(screen.getByText(/exceeds the .* px cap/i)).toBeTruthy();
+ });
+
+ it('shows no pixel-cap note when maxPixels is omitted (video)', () => {
+ render(<ResolutionField presets={VIDEO_PRESETS} width={700} height={512} onChange={vi.fn()} {...videoBounds} />);
+ expect(screen.queryByText(/px cap/i)).toBeNull();
+ // Default bounds-derived note, no total-pixel clause.
+ expect(screen.getByText(/Each edge 64–2048px\. Multiples of 64/i)).toBeTruthy();
+ });
+
+ it('renders a custom note override when provided', () => {
+ render(<ResolutionField presets={VIDEO_PRESETS} width={700} height={512} onChange={vi.fn()} note="rounds down to 64" {...videoBounds} />);
+ expect(screen.getByText('rounds down to 64')).toBeTruthy();
+ });
+
+ it('keeps the inputs mounted when a dimension is cleared mid-edit', () => {
+ function Harness() {
+ const [dims, setDims] = useState({ width: 704, height: 1280 });
+ return (
+ <ResolutionField
+ presets={IMAGE_PRESETS}
+ width={dims.width}
+ height={dims.height}
+ onChange={(w, h) => setDims({ width: w, height: h })}
+ {...imageBounds}
+ />
+ );
+ }
+ render(<Harness />);
+ expect(screen.getByLabelText('Height')).toBeTruthy();
+ fireEvent.change(screen.getByLabelText('Height'), { target: { value: '' } });
+ expect(screen.getByLabelText('Width')).toBeTruthy();
+ expect(screen.getByLabelText('Height')).toBeTruthy();
+ });
+});
diff --git a/client/src/lib/imageGenResolutions.js b/client/src/lib/imageGenResolutions.js
index 5f5273ed0d..19fd54347b 100644
--- a/client/src/lib/imageGenResolutions.js
+++ b/client/src/lib/imageGenResolutions.js
@@ -70,14 +70,23 @@ export function clampImageDimensions(width, height) {
return { width: snap(w), height: snap(h) };
}
-// Clamp a single hand-typed edge (width or height) to the server's per-edge
-// bounds [64, MAX_IMAGE_EDGE] — mirrors imageEdgeSchema so the custom-dimension
-// inputs can't submit a value that 400s. Non-finite / ≤0 input snaps to the 64
-// floor. Fractional input floors (diffusion runners want integer pixels).
-export function clampImageEdge(value) {
- const n = Math.floor(Number(value));
- if (!Number.isFinite(n) || n < 64) return 64;
- return Math.min(MAX_IMAGE_EDGE, n);
+// Clamp a single hand-typed edge (width or height) to a runner's per-edge
+// bounds — mirrors the server so the custom-dimension inputs can't submit a
+// value that 400s. Non-finite / ≤0 / below-min input snaps to the `min` floor;
+// oversized caps at `max`; fractional input floors (runners want integer
+// pixels). When `step > 1`, the result is snapped DOWN to the nearest multiple
+// of `step` (still ≥ min) so the displayed value reflects what the runner will
+// actually render (image: multiples of 8; video: the server floors to 64).
+//
+// Defaults to the image-gen ceiling ([64, MAX_IMAGE_EDGE], step 1) so existing
+// image callers keep working with no `bounds` argument; video passes
+// `{ min: 64, max: 2048, step: 64 }`.
+export function clampImageEdge(value, { min = 64, max = MAX_IMAGE_EDGE, step = 1 } = {}) {
+ let n = Math.floor(Number(value));
+ if (!Number.isFinite(n) || n < min) return min;
+ n = Math.min(max, n);
+ if (step > 1) n = Math.max(min, Math.floor(n / step) * step);
+ return n;
}
// Sentinel dropdown value for "enter arbitrary width/height" — distinct from
diff --git a/client/src/lib/imageGenResolutions.test.js b/client/src/lib/imageGenResolutions.test.js
index 104b7b7e3c..77c06a30ff 100644
--- a/client/src/lib/imageGenResolutions.test.js
+++ b/client/src/lib/imageGenResolutions.test.js
@@ -27,6 +27,24 @@ describe('clampImageEdge', () => {
expect(clampImageEdge(704.9)).toBe(704);
expect(clampImageEdge('1280px'.replace('px', ''))).toBe(1280);
});
+
+ it('honors custom { min, max } bounds (e.g. video 64..2048)', () => {
+ const v = { min: 64, max: 2048 };
+ expect(clampImageEdge(1024, v)).toBe(1024);
+ expect(clampImageEdge(9999, v)).toBe(2048);
+ expect(clampImageEdge(0, v)).toBe(64);
+ });
+
+ it('snaps DOWN to the nearest multiple of step when step > 1', () => {
+ expect(clampImageEdge(700, { min: 64, max: 2048, step: 64 })).toBe(640);
+ expect(clampImageEdge(768, { min: 64, max: 2048, step: 64 })).toBe(768);
+ expect(clampImageEdge(705, { min: 64, max: 3840, step: 8 })).toBe(704);
+ });
+
+ it('never snaps below min after stepping', () => {
+ // 100 floored to a multiple of 64 is 64, still ≥ min.
+ expect(clampImageEdge(100, { min: 64, max: 2048, step: 64 })).toBe(64);
+ });
});
describe('clampImageDimensions', () => {
diff --git a/client/src/lib/videoGenResolutions.js b/client/src/lib/videoGenResolutions.js
index 96dfa54a40..0ddc07010d 100644
--- a/client/src/lib/videoGenResolutions.js
+++ b/client/src/lib/videoGenResolutions.js
@@ -1,6 +1,7 @@
// Shared resolution presets for video generation. Companion to
-// `imageGenResolutions.js` — both pages drive a "preset dropdown + custom
-// fallback" pattern off these tables so the size dropdown stays consistent.
+// `imageGenResolutions.js` — both the image and video generators feed their
+// preset table into the shared `components/media/ResolutionField.jsx` control
+// (preset dropdown + "Custom…" W×H), so the size UX stays consistent across both.
//
// Video sizes follow LTX-2's preferred latent boundaries (multiples of 64 on
// each edge); the aspect-ratio hints in the labels surface common shapes the
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index 6b5797befe..b975b27063 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -69,8 +69,8 @@ import LoraPicker from '../components/imageGen/LoraPicker';
import { videoLoraFamily, VIDEO_LORA_FAMILIES } from '../lib/runnerFamilies';
import { randomSeed } from '../lib/genUtils';
import { VIDEO_RESOLUTIONS, snapAspectToImage } from '../lib/videoGenResolutions';
+import ResolutionField from '../components/media/ResolutionField';
import { VIDEO_TILING_OPTIONS, VIDEO_TILING_ENUM_SET } from '../lib/videoTilingOptions';
-import { resolveResolutionLabel } from '../lib/imageGenResolutions';
// Values follow LTX-2's 8k+1 latent boundary so the model doesn't silently
// snap. 241 = 10s @ 24fps is the comfortable single-pass ceiling on 48 GB
@@ -900,7 +900,6 @@ export default function VideoGen() {
const [dismissedEncoderIntegrityKey, setDismissedEncoderIntegrityKey] = useState(null);
const showEncoderIntegrityBanner = encoderIntegrityBad && dismissedEncoderIntegrityKey !== encoderIntegrityKey && !modelDownload.downloading;
- const { matched: matchedResolution, label: resolutionLabel } = resolveResolutionLabel(VIDEO_RESOLUTIONS, width, height);
const progressPct = progress?.progress != null ? Math.round(progress.progress * 100) : null;
// Explicit px sizing — maxWidth + maxHeight + aspectRatio together resolves
@@ -910,21 +909,14 @@ export default function VideoGen() {
const previewWidth = previewRatio >= 1 ? previewBudget : Math.round(previewBudget * previewRatio);
const previewHeight = previewRatio >= 1 ? Math.round(previewBudget / previewRatio) : previewBudget;
- const handleResolutionChange = (e) => {
- const r = VIDEO_RESOLUTIONS.find((r) => r.label === e.target.value);
- if (r) { setWidth(r.w); setHeight(r.h); sizeManuallySetRef.current = true; }
- };
- // Free-form custom W×H entry for power users who want an exact I2V size the
- // preset list doesn't cover. Marks the size as manually set so aspect-snap on
- // image upload stops overriding it (same flag the preset/remix paths set).
- // Empty/invalid input is left untouched — width/height are numeric state the
- // preview + FFLF-budget math read, so we never let them go 0/NaN. The server
- // validates 64..2048 (videoGen route) and floors both dims to a multiple of
- // 64 (generateVideo in local.js) before enforcing the per-tier pixel budget,
- // so free entry stays safe; the inputs mirror that 64..2048 bound below.
- const handleDimensionChange = (setter) => (e) => {
- const v = Number(e.target.value);
- if (Number.isFinite(v) && v > 0) { setter(v); sizeManuallySetRef.current = true; }
+ // Preset pick or custom W×H edit — mark the size as manually set so aspect-snap
+ // on image upload stops overriding it (same flag the remix/deep-link paths set).
+ // ResolutionField passes a transient 0 mid-edit and blur-snaps each edge to the
+ // 64..2048 bound; the preview + FFLF-budget math guard against a transient 0,
+ // and the server floors both dims to a multiple of 64 (generateVideo in
+ // local.js) before enforcing the per-tier pixel budget.
+ const handleResolutionChange = (w, h) => {
+ setWidth(w); setHeight(h); sizeManuallySetRef.current = true;
};
const handleRandomSeed = () => setSeed(randomSeed());
@@ -1714,78 +1706,20 @@ export default function VideoGen() {
</div>
)}
- <FormField label="Resolution" labelClassName="block text-xs font-medium text-gray-400 mb-1">
- <select
- value={resolutionLabel}
- onChange={handleResolutionChange}
- className="w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50"
- >
- {!matchedResolution && (
- <option value={resolutionLabel}>{`${width}×${height} (custom)`}</option>
- )}
- {VIDEO_RESOLUTIONS.map((r) => <option key={r.label} value={r.label}>{r.label}</option>)}
- </select>
- <div className="flex items-center gap-1 mt-1">
- <input
- type="number"
- min={64}
- max={2048}
- step={64}
- value={width}
- onChange={(e) => {
- const v = Number(e.target.value);
- if (Number.isFinite(v) && v > 0) {
- setWidth(v);
- sizeManuallySetRef.current = true;
- }
- }}
- className="flex-1 min-w-0 bg-port-bg border border-port-border rounded-lg px-2 py-1.5 text-xs text-white focus:outline-none focus:border-port-accent disabled:opacity-50"
- title="Width in pixels (will be floored to a multiple of 64)"
- />
- <span className="text-gray-500 text-xs">x</span>
- <input
- type="number"
- min={64}
- max={2048}
- step={64}
- value={height}
- onChange={(e) => {
- const v = Number(e.target.value);
- if (Number.isFinite(v) && v > 0) {
- setHeight(v);
- sizeManuallySetRef.current = true;
- }
- }}
- className="flex-1 min-w-0 bg-port-bg border border-port-border rounded-lg px-2 py-1.5 text-xs text-white focus:outline-none focus:border-port-accent disabled:opacity-50"
- title="Height in pixels (will be floored to a multiple of 64)"
- />
- </div>
- </FormField>
-
- {/* Free-form W×H for exact I2V sizing beyond the preset list. Drives
- the same width/height state as the preset select; the "(custom)"
- option above reflects any off-preset value. The server accepts
- 64..2048 and rounds each dim DOWN to the 64-grid, so an off-grid
- size here renders at the next-lower multiple of 64. */}
- <FormField label="Width" labelClassName="block text-xs font-medium text-gray-400 mb-1">
- <input
- type="number" min={64} max={2048} step={64}
- value={width}
- onChange={handleDimensionChange(setWidth)}
- title="Custom width in px (64–2048) — the server rounds down to the nearest multiple of 64."
- className="w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50"
- />
- </FormField>
-
- <FormField label="Height" labelClassName="block text-xs font-medium text-gray-400 mb-1">
- <input
- type="number" min={64} max={2048} step={64}
- value={height}
- onChange={handleDimensionChange(setHeight)}
- title="Custom height in px (64–2048) — the server rounds down to the nearest multiple of 64."
- className="w-full bg-port-bg border border-port-border rounded-lg px-2 py-2 text-sm text-white focus:outline-none focus:border-port-accent disabled:opacity-50"
- />
- </FormField>
+ {/* Preset dropdown + free-form custom W×H for exact I2V sizing beyond
+ the preset list. The server accepts 64..2048 and rounds each dim
+ DOWN to the 64-grid, so an off-grid size renders at the next-lower
+ multiple of 64 — ResolutionField's blur-snap reflects that. */}
+ <ResolutionField
+ presets={VIDEO_RESOLUTIONS}
+ width={width}
+ height={height}
+ onChange={handleResolutionChange}
+ min={64}
+ max={2048}
+ step={64}
+ note="Each edge 64–2048px; the server rounds each down to the nearest multiple of 64."
+ />
<FormField label="Frames" labelClassName="block text-xs font-medium text-gray-400 mb-1">
<select