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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Show the exact Video Gen prompt under the prompt box before Generate
Claude7435d98f7963
diff --git a/client/src/components/imageGen/ImageGenFormEditor.jsx b/client/src/components/imageGen/ImageGenFormEditor.jsxindex eb26f5b12b..24e7f94575 100644--- a/client/src/components/imageGen/ImageGenFormEditor.jsx+++ b/client/src/components/imageGen/ImageGenFormEditor.jsx@@ -8,7 +8,7 @@ import MusicVideoFilingSelect from '../media/MusicVideoFilingSelect';import { FormField } from '../ui/FormField';import Banner from '../ui/Banner';import AutoSizeTextarea from '../ui/AutoSizeTextarea';-import SentPromptPanel from '../media/SentPromptPanel';+import ModelInputPreview from '../media/ModelInputPreview';import HfTokenBanner from './HfTokenBanner';import ImageGenControls from './ImageGenControls';import InitImagePicker from './InitImagePicker';@@ -25,25 +25,6 @@ const ERROR_HEADINGS = {repo_not_found: 'Model repo not found',};-// What Generate will send (#11317): the server's preview, built by the same-// code as the render. The box above keeps only the user's words.-function ModelInputPreview({ preview, prompt }) {- if (preview?.error) return <p role="alert" className="text-xs text-port-warning">{preview.error}</p>;- const sent = preview?.preview;- if (!sent) return null;- return (- <div className="text-xs">- <SentPromptPanel- prompt={prompt}- sentPrompt={sent.sentPrompt}- sentNegativePrompt={sent.sentNegativePrompt}- additions={sent.promptAdditions || []}- asWrittenText="Sent to the model as written."- />- </div>- );-}-export default function ImageGenFormEditor({ form, backend, generation }) {const {fields,diff --git a/client/src/components/media/ModelInputPreview.jsx b/client/src/components/media/ModelInputPreview.jsxnew file mode 100644index 0000000000..dcbed7bfcb--- /dev/null+++ b/client/src/components/media/ModelInputPreview.jsx@@ -0,0 +1,23 @@+import SentPromptPanel from './SentPromptPanel';++/**+ * What Generate will send (#11317): the server's preview, built by the same+ * code as the render, shown under a form's prompt box. The box above keeps only+ * the user's words; a refusal the render would give shows here instead.+ */+export default function ModelInputPreview({ preview, prompt }) {+ if (preview?.error) return <p role="alert" className="text-xs text-port-warning">{preview.error}</p>;+ const sent = preview?.preview;+ if (!sent) return null;+ return (+ <div className="text-xs">+ <SentPromptPanel+ prompt={prompt}+ sentPrompt={sent.sentPrompt}+ sentNegativePrompt={sent.sentNegativePrompt}+ additions={sent.promptAdditions || []}+ asWrittenText="Sent to the model as written."+ />+ </div>+ );+}diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex d96b383c04..94e27406ff 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -82,9 +82,11 @@ import usePreviewRoute from '../hooks/usePreviewRoute';import useMediaPreviewActions from '../hooks/useMediaPreviewActions';import { useVideoGenForm } from '../hooks/useVideoGenForm.js';import { useFederatedMediaTarget } from '../hooks/useFederatedMediaTarget';+import { useModelInputPreview } from '../hooks/useModelInputPreview';+import ModelInputPreview from '../components/media/ModelInputPreview';import RemoteMediaTargetPicker from '../components/federatedMedia/RemoteMediaTargetPicker';import {- getVideoGenStatus, getVideoGenModelContext, generateVideo, cancelVideoGen,+ getVideoGenStatus, getVideoGenModelContext, generateVideo, cancelVideoGen, previewVideoPrompt,listVideoHistory, deleteVideoHistoryItem, setVideoHidden,patchSettingsSlice,getActiveVideoJob,@@ -880,6 +882,15 @@ export default function VideoGen() {// The form's request plus the music video it is filed under, if one is picked.const generatePayload = () => ({ ...buildGeneratePayload(), ...musicVideoFilingFields(searchParams) });+ // The same request as Generate, each upload named instead of attached (#11317).+ const previewBody = (() => {+ const payload = generatePayload();+ const previewUploads = Object.keys(payload).filter((key) => payload[key] instanceof Blob);+ const fields = Object.fromEntries(Object.entries(payload).filter(([, value]) => !(value instanceof Blob)));+ return previewUploads.length ? { ...fields, previewUploads } : fields;+ })();+ const modelInputPreview = useModelInputPreview(previewVideoPrompt, previewBody, { enabled: prompt.trim().length > 0 });+const handleGenerate = async (e) => {e?.preventDefault?.();if (generating) {@@ -1271,6 +1282,9 @@ export default function VideoGen() {Reactor will reject this — shorten the prompt. Style presets count toward the limit.</p>)}+ <div className="mt-2">+ <ModelInputPreview preview={modelInputPreview} prompt={prompt} />+ </div>{!negativePromptSupported && !isFal && !isReactor && (<p className="mt-1 text-[11px] text-gray-500 leading-snug">This model does not use a negative prompt.diff --git a/client/src/pages/VideoGen.promptPreview.test.jsx b/client/src/pages/VideoGen.promptPreview.test.jsxnew file mode 100644index 0000000000..d1e2c6d8b4--- /dev/null+++ b/client/src/pages/VideoGen.promptPreview.test.jsx@@ -0,0 +1,47 @@+import { beforeEach, describe, expect, it } from 'vitest';+import { fireEvent, screen, waitFor } from '@testing-library/react';+import {+ loadVideoGenPage, renderVideoGenPage, resetVideoGenMockState,+ state, videoGenModel, videoGenModelContext, videoGenStatus,+} from '../test/videoGenPageMocks.jsx';++const MODEL = videoGenModel('local-model');+await loadVideoGenPage();++// #11317: the form shows what Generate will send, from the server's preview of+// the same request, and the refusal the render would give before the click.+describe('VideoGen prompt preview', () => {+ beforeEach(() => {+ localStorage.clear();+ resetVideoGenMockState();+ state.getVideoGenModelContext.mockResolvedValue(videoGenModelContext([MODEL]));+ state.getVideoGenStatus.mockResolvedValue(videoGenStatus([MODEL], { falEnabled: true }));+ state.modelStatuses = { [MODEL.id]: { id: MODEL.id, repo: MODEL.repo, cached: true, sizeBytes: 100 } };+ });++ it('previews the Generate request and shows what the backend adds as chips', async () => {+ state.previewVideoPrompt.mockResolvedValue({+ backend: 'fal',+ sentPrompt: 'a fox watches the rain\nAvoid: blur',+ promptAdditions: [{ id: 'avoid', label: 'Negative prompt, sent as "Avoid:"', text: 'blur' }],+ });+ await renderVideoGenPage();+ fireEvent.click(await screen.findByRole('button', { name: 'fal.ai' }));+ fireEvent.change(screen.getByLabelText('Prompt'), { target: { value: 'a fox watches the rain' } });++ await waitFor(() => expect(state.previewVideoPrompt).toHaveBeenCalledWith(+ expect.objectContaining({ backend: 'fal', prompt: 'a fox watches the rain' }),+ { silent: true },+ ), { timeout: 2000 });+ expect(await screen.findByRole('button', { name: '+ Negative prompt, sent as "Avoid:"' })).toBeTruthy();+ expect(screen.getByLabelText('Prompt')).toHaveValue('a fox watches the rain');+ });++ it('shows the refusal Generate would get', async () => {+ state.previewVideoPrompt.mockRejectedValue(new Error('The prompt is 2,001 characters; MiniMax Hailuo-02 Standard (text) takes 2,000. Shorten it to render.'));+ await renderVideoGenPage();+ fireEvent.click(await screen.findByRole('button', { name: 'fal.ai' }));+ fireEvent.change(screen.getByLabelText('Prompt'), { target: { value: 'x'.repeat(2001) } });+ expect(await screen.findByRole('alert', {}, { timeout: 2000 })).toHaveTextContent('2,001 characters');+ });+});diff --git a/client/src/services/apiImageVideo.js b/client/src/services/apiImageVideo.jsindex 5c0ed18ed6..c56f2873a8 100644--- a/client/src/services/apiImageVideo.js+++ b/client/src/services/apiImageVideo.js@@ -364,6 +364,14 @@ export async function generateVideo(fields) {return res.json();}+// The Video Gen form's preview of what Generate would send (#11317): the same+// multipart fields, each upload the form holds named in `previewUploads`.+export const previewVideoPrompt = (fields, options = {}) => request('/video-gen/prompt-preview', {+ method: 'POST',+ body: buildFormData(fields),+ ...options,+});+// Video timeline projects (non-linear editor)export const listTimelineProjects = () => request('/video-timeline/projects');export const getTimelineProject = (id, options) => request(`/video-timeline/projects/${encodeURIComponent(id)}`, options);diff --git a/client/src/test/videoGenPageMocks.jsx b/client/src/test/videoGenPageMocks.jsxindex 1ac7afd1ad..270b56830f 100644--- a/client/src/test/videoGenPageMocks.jsx+++ b/client/src/test/videoGenPageMocks.jsx@@ -49,6 +49,8 @@ export const state = {*/getVideoGenModelContext: vi.fn(),generateVideo: vi.fn(),+ /** The form's prompt preview (#11317); resolves null (no panel) unless a test sets one. */+ previewVideoPrompt: vi.fn(),activeJob: null,/** Cache-status entries keyed by download id, read by the default `getModelStatus`. */modelStatuses: {},@@ -94,7 +96,7 @@ export const state = {runtimeStatus: { installed: true, ready: true, current: true },};-const SPIES = ['getVideoGenStatus', 'getVideoGenModelContext', 'generateVideo', 'start', 'startWhenIdle', 'repair', 'cancel', 'refresh', 'listVideoHistory', 'listLorasFull'];+const SPIES = ['getVideoGenStatus', 'getVideoGenModelContext', 'generateVideo', 'previewVideoPrompt', 'start', 'startWhenIdle', 'repair', 'cancel', 'refresh', 'listVideoHistory', 'listLorasFull'];/** Restore every documented default, including fresh spies. Call it first in `beforeEach`. */export function resetVideoGenMockState() {@@ -121,6 +123,7 @@ export function resetVideoGenMockState() {state.runtimeStatus = { installed: true, ready: true, current: true };for (const key of SPIES) state[key].mockReset();state.listVideoHistory.mockResolvedValue([]);+ state.previewVideoPrompt.mockResolvedValue(null);state.listLorasFull.mockImplementation(async () => state.availableLoras);}@@ -185,6 +188,7 @@ vi.mock('../services/api', () => ({getVideoGenStatus: (...args) => state.getVideoGenStatus(...args),getVideoGenModelContext: (...args) => state.getVideoGenModelContext(...args),generateVideo: (...args) => state.generateVideo(...args),+ previewVideoPrompt: (...args) => state.previewVideoPrompt(...args),cancelVideoGen: vi.fn(async () => ({})),listVideoHistory: (...args) => state.listVideoHistory(...args),deleteVideoHistoryItem: vi.fn(async () => ({})),diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex 310ca6ef5f..1001e35ab5 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -58,6 +58,7 @@ import { enqueueLtxUpscale } from '../services/videoGen/upscaleJob.js';import { trimHistoryItemStart } from '../services/videoGen/trimStart.js';import { cleanupMultipartTemp } from '../services/videoGen/prepareParams.js';import { submitVideoGenJob } from '../services/videoGen/submitJob.js';+import { PREVIEW_UPLOAD_FIELDS, previewVideoPrompt } from '../services/videoGen/promptPreview.js';import { resolveReactorApiKey, mintReactorToken } from '../services/videoGen/reactor.js';import { isVideoModeUsable, VIDEO_GEN_MODE } from '../services/videoGen/modes.js';import { MAX_VIDEO_BATCH_SIZE } from '../services/videoGen/batch.js';@@ -525,6 +526,12 @@ const generateBodySchema = z.object({mediaProviderEngine: z.string().trim().min(1).max(80).optional(),});+// The Video Gen form's preview (#11317): the generate body as the form would+// post it, with each upload it holds named instead of attached.+const promptPreviewBodySchema = generateBodySchema.safeExtend({+ previewUploads: z.preprocess((v) => (typeof v === 'string' ? [v] : v), z.array(z.enum(PREVIEW_UPLOAD_FIELDS)).max(PREVIEW_UPLOAD_FIELDS.length)).optional(),+});+// Probes required-package imports on each call so a half-installed Python// can't masquerade as connected. /status isn't polled (mount + manual// refresh only), so the ~1-2s subprocess cost is acceptable.@@ -940,6 +947,11 @@ router.get('/text-encoder/download', asyncHandler(async (req, res) => {await startHfDownloadStream({ req, res, repo, force: req.query.force === '1' });}));+// What Generate would send to the model, built by the render's own code (#11317).+router.post('/prompt-preview', uploadFields([]), asyncHandler(async (req, res) => {+ res.json(await previewVideoPrompt(validateRequest(promptPreviewBodySchema, req.body ?? {})));+}));+router.post('/', frameImageUpload, asyncHandler(async (req, res) => {// The route owns cleanup before validation succeeds; the submit service owns// every failure after it receives parsed data.diff --git a/server/routes/videoGen.test.js b/server/routes/videoGen.test.jsindex 94786cdf21..db11e7b5e9 100644--- a/server/routes/videoGen.test.js+++ b/server/routes/videoGen.test.js@@ -1133,6 +1133,45 @@ describe('videoGen routes', () => {});});+ describe('POST /prompt-preview (#11317)', () => {+ const settings = {+ imageGen: { grok: { enabled: true, grokPath: '/example/grok', aspectRatio: '16:9' } },+ videoGen: { fal: { apiKey: 'example-fal-key' } },+ };+ const style = { id: 'style-preset', label: 'Style preset', text: 'film grain' };++ it('shows the grok agent prompt, its instructions chip and the form\'s chips without queueing', async () => {+ const { getSettings } = await import('../services/settings.js');+ getSettings.mockResolvedValueOnce(settings);+ const r = await request(app).post('/api/video-gen/prompt-preview').send({+ backend: 'grok', prompt: 'a fox running, film grain', grokDuration: '10', promptAdditions: [style],+ });+ expect(r.status).toBe(200);+ expect(r.body.sentPrompt).toContain('a fox running, film grain');+ expect(r.body.sentPrompt).toContain('for 10 seconds');+ expect(r.body.promptAdditions).toEqual([style, expect.objectContaining({ label: 'Grok video tool instructions' })]);+ expect(r.body.promptAdditions[1].text).toContain('[prompt]');+ expect(r.body.promptAdditions[1].text).not.toContain('a fox running');+ expect(mediaJobQueue.enqueueJob).not.toHaveBeenCalled();+ });++ it('refuses a fal prompt over the model cap with the same count the render gives', async () => {+ const { getSettings } = await import('../services/settings.js');+ getSettings.mockResolvedValueOnce(settings);+ const r = await request(app).post('/api/video-gen/prompt-preview').send({ backend: 'fal', prompt: 'x'.repeat(2001) });+ expect(r.status).toBe(400);+ expect(r.body.error).toMatch(/2,001 characters/);+ });++ it('refuses a backend that is switched off, as Generate does', async () => {+ const { getSettings } = await import('../services/settings.js');+ getSettings.mockResolvedValueOnce({ imageGen: { grok: { enabled: false } } });+ const r = await request(app).post('/api/video-gen/prompt-preview').send({ backend: 'grok', prompt: 'a fox' });+ expect(r.status).toBe(400);+ expect(r.body.error).toMatch(/disabled/i);+ });+ });+describe('POST / — video pin ladder (#3231 Phase 4)', () => {const grokReady = { grok: { enabled: true, grokPath: '/opt/grok' } };diff --git a/server/services/videoGen/fal.js b/server/services/videoGen/fal.jsindex a13c0a6af2..de9b3b0533 100644--- a/server/services/videoGen/fal.js+++ b/server/services/videoGen/fal.js@@ -141,6 +141,42 @@ function buildRequestBody({ prompt, negativePrompt, duration, aspectRatio, imagereturn body;}+/**+ * Dry-run the curated request body with placeholder media before anything is+ * read or paid for: a missing required input or an over-cap prompt refuses here+ * as a 400, and the plan carries the coerced length, resolution and estimate the+ * history records. Returns the plan with the record of the text fal receives+ * (#11317); the Video Gen form's preview calls it with the same inputs.+ */+export function falVideoSentPrompt({ hasImage = false, hasEndImage = false, hasAudio = false, promptAdditions = [], ...spec }) {+ const modelId = spec.modelId || (hasImage ? FAL_DEFAULT_IMAGE_MODEL : FAL_DEFAULT_TEXT_MODEL);+ const { prompt = '', negativePrompt } = spec;+ let planned = null;+ try {+ planned = buildFalVideoRequest({+ ...spec, modelId,+ imageUrl: hasImage ? 'pending:image' : null,+ endImageUrl: hasEndImage ? 'pending:end-image' : null,+ audioUrl: hasAudio ? 'pending:audio' : null,+ });+ } catch (err) {+ if (err?.code !== 'FAL_MODEL_INPUT') throw err;+ throw new ServerError(err.message, { status: 400, code: 'VALIDATION_ERROR' });+ }+ if (hasEndImage && !planned) {+ throw new ServerError('End frames require a fal.ai model with catalogued end-frame support', { status: 400, code: 'VALIDATION_ERROR' });+ }+ // The text fal receives: a negative prompt the model has no field for rides folded in as "Avoid:".+ const record = sentPromptRecord({+ sentPrompt: planned ? (planned.body.prompt ?? '') : buildRequestBody({ prompt, negativePrompt }).prompt,+ sentNegativePrompt: planned?.body.negative_prompt ?? null,+ carried: carriedPromptAdditions({ promptAdditions }),+ added: [(!planned || planned.model.negativePrompt === 'fold') && planned?.model.prompt !== 'none'+ ? promptAddition('avoid', 'Negative prompt, sent as "Avoid:"', negativePrompt) : null],+ });+ return { planned, record };+}+export async function generateVideo({apiKey: providedApiKey, settings, modelId: requestedModelId,prompt = '', negativePrompt, duration, aspectRatio, width, height,@@ -195,25 +231,10 @@ export async function generateVideo({modelId, prompt, negativePrompt, seconds: duration, audioSec, aspectRatio, width, height, resolution,generateAudio: generateAudio === true, enableTranscription: lipSync?.enableTranscription === true,};- // Dry-run the curated body with placeholder media before anything is read or- // paid for: a missing required input refuses here as a 400, and the result- // carries the coerced length, resolution and estimate the history records.- let planned = null;- try {- planned = buildFalVideoRequest({- ...requestSpec,- imageUrl: sourceImagePath ? 'pending:image' : null,- endImageUrl: lastImagePath ? 'pending:end-image' : null,- audioUrl: audioFilePath ? 'pending:audio' : null,- });- } catch (err) {- if (err?.code !== 'FAL_MODEL_INPUT') throw err;- throw new ServerError(err.message, { status: 400, code: 'VALIDATION_ERROR' });- }-- if (lastImagePath && !planned) {- throw new ServerError('End frames require a fal.ai model with catalogued end-frame support', { status: 400, code: 'VALIDATION_ERROR' });- }+ const { planned, record: sentRecord } = falVideoSentPrompt({+ ...requestSpec, promptAdditions,+ hasImage: !!sourceImagePath, hasEndImage: !!lastImagePath, hasAudio: !!audioFilePath,+ });const meta = {id: jobId,@@ -234,14 +255,7 @@ export async function generateVideo({// What PortOS expected this render to cost at fal's list price, or null for// an uncurated model — recorded so spend can be audited per clip.estimatedCostUsd: planned?.estimatedCostUsd ?? null,- // The text fal receives: a negative prompt the model has no field for rides folded in as "Avoid:".- ...sentPromptRecord({- sentPrompt: planned ? (planned.body.prompt ?? '') : buildRequestBody({ prompt, negativePrompt }).prompt,- sentNegativePrompt: planned?.body.negative_prompt ?? null,- carried: carriedPromptAdditions({ promptAdditions }),- added: [(!planned || planned.model.negativePrompt === 'fold') && planned?.model.prompt !== 'none'- ? promptAddition('avoid', 'Negative prompt, sent as "Avoid:"', negativePrompt) : null],- }),+ ...sentRecord,filename,createdAt: new Date().toISOString(),mode: sourceImagePath ? 'image' : 'text',diff --git a/server/services/videoGen/generateVideo.js b/server/services/videoGen/generateVideo.jsindex 8a36f50ad8..4472891307 100644--- a/server/services/videoGen/generateVideo.js+++ b/server/services/videoGen/generateVideo.js@@ -154,6 +154,24 @@ export const listVideoModels = () => getVideoModels().map(decorateVideoModel);export const defaultVideoModelId = (capabilities, preferredId) => getDefaultVideoModelId(capabilities, preferredId);+/**+ * The prompt a local video render sends, with each selected LoRA's trigger word+ * woven in, and its record (#11317). Shared by the render and the Video Gen+ * form's preview.+ */+export async function localVideoSentPrompt({ prompt = '', negativePrompt, loraFilenames = [], promptAdditions = [] }) {+ const triggerWordsByLora = await readTriggerWordsByFilename(loraFilenames);+ const { prompt: renderPrompt, added: addedTriggerWords } = weaveLoraTriggers(+ prompt,+ loraFilenames.map((filename) => triggerWordsByLora[filename]),+ );+ return {+ renderPrompt, addedTriggerWords,+ record: sentPromptRecord({ sentPrompt: renderPrompt, sentNegativePrompt: negativePrompt, carried: carriedPromptAdditions({ promptAdditions }),+ added: [promptAddition('lora-triggers', 'LoRA trigger words', addedTriggerWords.join(', '))] }),+ };+}+export async function generateVideo({ pythonPath, prompt, negativePrompt = '', modelId, width = null, height = null, numFrames = null, fps = 24, steps, guidanceScale, seed, batchSize = 1, tiling = 'auto', disableAudio = false, sourceImagePath = null, uploadedTempPath = null, uploadedTempPaths = [], lastImagePath = null, keyframes = null, extendFromVideoPath = null, audioFilePath = null, audioStartSec = null, audioConditioning = null, mode = null, imageStrength = null, i2vReferenceMode = null, loras = null, icReferencePaths = null, icStrength = null, icAttentionStrength = null, icSkipStage2 = false, textEncoderId = null, speedProfileId = null, draftDecode = null, streamingMode = null, visualConditioning = null, hidden = false, keepExtendSource = false, displaySleep = null, jobId: providedJobId = null, promptAdditions = [] }) {const sourceAudioProvenance = audioConditioning == null ? null : federatedSourceAudioSchema.parse(audioConditioning);uploadedTempPaths = Array.isArray(uploadedTempPaths) ? uploadedTempPaths : [];@@ -360,12 +378,10 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m// prompt is never duplicated. Done here rather than in the route so the chain// orchestrator's per-chunk beats (`chunkPrompts`) get the tokens too — each// chunk re-enters through this function with its own prompt.- const triggerWordsByLora = await readTriggerWordsByFilename(resolvedLoras.map((l) => l.filename));const loraLicenses = await readLoraLicensesByFilename(resolvedLoras.map((l) => l.filename));- const { prompt: renderPrompt, added: addedTriggerWords } = weaveLoraTriggers(- prompt,- resolvedLoras.map((l) => triggerWordsByLora[l.filename]),- );+ const { renderPrompt, addedTriggerWords, record: sentRecord } = await localVideoSentPrompt({+ prompt, negativePrompt, loraFilenames: resolvedLoras.map((l) => l.filename), promptAdditions,+ });if (addedTriggerWords.length) {console.log(`🔤 Video LoRA trigger words woven [${jobId.slice(0, 8)}]: ${addedTriggerWords.join(', ')}`);}@@ -623,8 +639,7 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m// was actually rendered. Present only when something was woven, so every// other history row stays byte-identical to pre-feature renders....(addedTriggerWords.length ? { renderPrompt, addedTriggerWords } : {}),- ...sentPromptRecord({ sentPrompt: renderPrompt, sentNegativePrompt: negativePrompt, carried: carriedPromptAdditions({ promptAdditions }),- added: [promptAddition('lora-triggers', 'LoRA trigger words', addedTriggerWords.join(', '))] }),+ ...sentRecord,...(hidden ? { hidden: true } : {}),};// Each render gets one private preview directory. Runners overwrite thediff --git a/server/services/videoGen/grok.js b/server/services/videoGen/grok.jsindex 8aa9593f30..a5914eca46 100644--- a/server/services/videoGen/grok.js+++ b/server/services/videoGen/grok.js@@ -119,6 +119,28 @@ export function buildGrokVideoPrompt({ prompt, negativePrompt, aspectRatio, durareturn `${steps}\nSave the resulting video as an MP4 file at exactly this path: ${stagingPath}\nDo not create any other files, do not modify any code, and do not run any other tools beyond what is needed to generate the image/video and write the MP4 to that path. When the file is written, you are done.`;}+/**+ * The agent prompt a grok video render sends and its record (#11317): shared by+ * the render and the Video Gen form's preview so both show the same text.+ */+export function grokVideoSentPrompt({+ prompt = '', negativePrompt, aspectRatio, width, height, duration, sourceImagePath = null, scratchDir, promptAdditions = [],+}) {+ const effectiveDuration = resolveGrokDuration(duration);+ const configured = GROK_ASPECT_RATIOS.includes(aspectRatio) ? aspectRatio : null;+ const effectiveRatio = deriveAspectRatio(width, height) || configured;+ const buildWith = (text) => buildGrokVideoPrompt({+ prompt: text, negativePrompt, aspectRatio: effectiveRatio, duration: effectiveDuration,+ stagingPath: join(scratchDir, 'output.mp4'), sourceImagePath, scratchDir,+ });+ const fullPrompt = buildWith(prompt);+ return {+ fullPrompt, effectiveRatio, effectiveDuration,+ record: sentPromptRecord({ sentPrompt: fullPrompt, carried: carriedPromptAdditions({ promptAdditions }),+ added: [agentInstructionsAddition('Grok video tool instructions', buildWith)] }),+ };+}+export async function generateVideo({grokPath, aspectRatio, prompt = '', negativePrompt, width, height,sourceImagePath = null, duration,@@ -139,8 +161,6 @@ export async function generateVideo({throw new ServerError('Prompt is required', { status: 400, code: 'VALIDATION_ERROR' });}- const effectiveDuration = resolveGrokDuration(duration);-const jobId = providedJobId || randomUUID();const filename = `${jobId}.mp4`;const outputPath = join(PATHS.videos, filename);@@ -151,15 +171,9 @@ export async function generateVideo({const stagingPath = join(scratchDir, 'output.mp4');await mkdir(scratchDir, { recursive: true });- const derived = deriveAspectRatio(width, height);- const configured = GROK_ASPECT_RATIOS.includes(aspectRatio) ? aspectRatio : null;- const effectiveRatio = derived || configured;-- const buildWith = (text) => buildGrokVideoPrompt({- prompt: text, negativePrompt, aspectRatio: effectiveRatio, duration: effectiveDuration,- stagingPath, sourceImagePath, scratchDir,+ const { fullPrompt, effectiveRatio, effectiveDuration, record: sentRecord } = grokVideoSentPrompt({+ prompt, negativePrompt, aspectRatio, width, height, duration, sourceImagePath, scratchDir, promptAdditions,});- const fullPrompt = buildWith(prompt);const bin = grokPath || DEFAULT_BIN;const baseArgs = ensureGrokHeadlessArgs([], null);@@ -180,8 +194,7 @@ export async function generateVideo({filename,createdAt: new Date().toISOString(),mode: sourceImagePath ? 'image' : 'text',- ...sentPromptRecord({ sentPrompt: fullPrompt, carried: carriedPromptAdditions({ promptAdditions }),- added: [agentInstructionsAddition('Grok video tool instructions', buildWith)] }),+ ...sentRecord,};const job = { ...meta, clients: [], status: 'running', renderStartedAtMs };jobs.set(jobId, job);diff --git a/server/services/videoGen/prepareParams.js b/server/services/videoGen/prepareParams.jsindex 84df3cedb6..2ce844ff17 100644--- a/server/services/videoGen/prepareParams.js+++ b/server/services/videoGen/prepareParams.js@@ -229,26 +229,11 @@ export const withStagedRollback = async (cleanupStaged, fn) => {};/**- * @param {object} opts- * @param {object} opts.body - validated + coerced body from Zod (mutated in place)- * @param {object} opts.uploads - `req.files` from multer (may be empty)- * @param {string[]} opts.localOnlyParamKeys - field names only the local runtimes- * consume; a request carrying any of them is not grok-deliverable. Passed in- * from the route (which owns their Zod schemas) so this module never has to- * import back into `routes/`.- * @returns {Promise<object>} On the grok lane:- * `{ backend, grok, effectiveModel, sourceImagePath, uploadedTempPath,- * discardSourceImage, cleanupStaged }`.- * On the local lane, additionally `{ pythonPath, effectiveModelId, mode,- * lastImagePath, audioFilePath, icReferencePaths, resolvedKeyframes,- * extendFromVideoPath, uploadedTempPaths, loras, effectiveChunks,- * effectiveChunkPrompts }`.- * `cleanupStaged` is the caller's rollback hook for anything that can still- * throw after this resolves (today: `enqueueJob`) — pass it to- * `withStagedRollback`.+ * The backend a video request renders on: an explicit `body.backend`, else the+ * pin ladder (below). Shared by the submit path and the Video Gen form's+ * prompt preview, which passes the uploads the form holds as present fields.*/-export async function prepareVideoGenParams({ body, uploads, localOnlyParamKeys }) {- const settings = await getSettings();+export function resolveRequestedVideoBackend({ body, uploads, settings, localOnlyParamKeys }) {// #3231 Phase 4 — the video pin ladder. An explicit `body.backend` always// wins (the VideoGen page and the MV director board both send one); when// absent, consult the music-video target pin (for director-board renders)@@ -273,10 +258,34 @@ export async function prepareVideoGenParams({ body, uploads, localOnlyParamKeys&& !body.keyframes?.length&& !body.loraFilenames?.length&& !(body.chunks != null && Number(body.chunks) > 1);- const backend = body.backend+ return body.backend|| (grokDeliverable? resolveVideoMode(null, settings, { target: body.musicVideo ? RENDER_TARGET.MUSIC_VIDEO : null }): VIDEO_GEN_MODE.LOCAL);+}++/**+ * @param {object} opts+ * @param {object} opts.body - validated + coerced body from Zod (mutated in place)+ * @param {object} opts.uploads - `req.files` from multer (may be empty)+ * @param {string[]} opts.localOnlyParamKeys - field names only the local runtimes+ * consume; a request carrying any of them is not grok-deliverable. Passed in+ * from the route (which owns their Zod schemas) so this module never has to+ * import back into `routes/`.+ * @returns {Promise<object>} On the grok lane:+ * `{ backend, grok, effectiveModel, sourceImagePath, uploadedTempPath,+ * discardSourceImage, cleanupStaged }`.+ * On the local lane, additionally `{ pythonPath, effectiveModelId, mode,+ * lastImagePath, audioFilePath, icReferencePaths, resolvedKeyframes,+ * extendFromVideoPath, uploadedTempPaths, loras, effectiveChunks,+ * effectiveChunkPrompts }`.+ * `cleanupStaged` is the caller's rollback hook for anything that can still+ * throw after this resolves (today: `enqueueJob`) — pass it to+ * `withStagedRollback`.+ */+export async function prepareVideoGenParams({ body, uploads, localOnlyParamKeys }) {+ const settings = await getSettings();+ const backend = resolveRequestedVideoBackend({ body, uploads, settings, localOnlyParamKeys });// A loose reference (#4874) is a LOCAL-runtime capability. The model gate// further down asks whether the chosen model's runtime can honor it — but an// explicit `backend: 'grok'` never reaches that runtime at all: grok'sdiff --git a/server/services/videoGen/promptPreview.js b/server/services/videoGen/promptPreview.jsnew file mode 100644index 0000000000..6f76e987c0--- /dev/null+++ b/server/services/videoGen/promptPreview.js@@ -0,0 +1,77 @@+/**+ * Compose-time preview of what a Video Gen render sends to its model (#11317):+ * the same backend resolution and the same per-backend prompt builders the+ * render runs, without staging uploads or queueing anything. An upload the form+ * holds is named in place of its staged path, and the grok scratch folder names+ * the job folder it will get.+ */+import { join } from 'node:path';+import { tmpdir } from 'node:os';+import { ServerError } from '../../lib/errorHandler.js';+import { resolveGalleryImage } from '../../lib/fileUtils.js';+import { carriedPromptAdditions, sentPromptRecord } from '../../lib/modelInput.js';+import { getSettings } from '../settings.js';+import { VIDEO_GEN_MODE } from './modes.js';+import { HOSTED_VIDEO_SUBMISSIONS } from './hostedSubmission.js';+import { resolveRequestedVideoBackend } from './prepareParams.js';+import { VIDEO_GEN_LOCAL_ONLY_FIELD_NAMES } from './requestFields.js';+import { grokVideoSentPrompt } from './grok.js';+import { falVideoSentPrompt } from './fal.js';+import { localVideoSentPrompt } from './generateVideo.js';++export const PREVIEW_UPLOAD_FIELDS = ['sourceImage', 'lastImage', 'audioFile', 'icReference'];+const UPLOADED_SOURCE_IMAGE = '(uploaded image)';++const asWritten = (body, extra = {}) => ({+ ...extra,+ ...sentPromptRecord({+ sentPrompt: body.prompt || '', sentNegativePrompt: body.negativePrompt || null,+ carried: carriedPromptAdditions(body),+ }),+});++export async function previewVideoPrompt({ previewUploads = [], ...body }) {+ // A shot card and a FableLoom scene rebuild the prompt from their project on+ // submit; their own previews belong to those surfaces, not this form's.+ if (body.musicVideo || body.fableLoom) {+ throw new ServerError('Preview a music video shot or FableLoom scene from its own card', { status: 400, code: 'VALIDATION_ERROR' });+ }+ const uploads = Object.fromEntries(previewUploads.map((field) => [field, {}]));+ const settings = await getSettings();+ const backend = resolveRequestedVideoBackend({ body, uploads, settings, localOnlyParamKeys: VIDEO_GEN_LOCAL_ONLY_FIELD_NAMES });+ // A federated provider receives the prompt as written; its own backend may add lines there.+ if (body.mediaProviderPeerId) return asWritten(body, { backend: 'remote', remote: true });++ const hosted = HOSTED_VIDEO_SUBMISSIONS[backend];+ // The same refusal POST /video-gen gives a backend that is off or has no key.+ if (hosted && !hosted.prepare(settings).usable) {+ throw new ServerError(hosted.errorMessage, { status: 400, code: hosted.errorCode });+ }+ const hasSourceImage = !!uploads.sourceImage || !!body.sourceImageFile;+ const sourceImagePath = uploads.sourceImage ? UPLOADED_SOURCE_IMAGE+ : body.sourceImageFile ? resolveGalleryImage(body.sourceImageFile) : null;+ const promptAdditions = carriedPromptAdditions(body);++ if (backend === VIDEO_GEN_MODE.GROK) {+ return { backend, ...grokVideoSentPrompt({+ prompt: body.prompt, negativePrompt: body.negativePrompt,+ aspectRatio: settings.imageGen?.grok?.aspectRatio, width: body.width, height: body.height,+ duration: body.grokDuration, sourceImagePath, scratchDir: join(tmpdir(), 'portos-grok-video-<job>'), promptAdditions,+ }).record };+ }+ if (backend === VIDEO_GEN_MODE.FAL) {+ return { backend, ...falVideoSentPrompt({+ modelId: body.falModelId, prompt: body.prompt, negativePrompt: body.negativePrompt,+ seconds: body.falDuration, width: body.width, height: body.height, resolution: body.falResolution,+ generateAudio: body.falGenerateAudio === true, promptAdditions,+ hasImage: hasSourceImage, hasEndImage: !!uploads.lastImage || !!body.lastImageFile, hasAudio: !!uploads.audioFile,+ }).record };+ }+ if (backend === VIDEO_GEN_MODE.LOCAL) {+ return { backend, ...(await localVideoSentPrompt({+ prompt: body.prompt, negativePrompt: body.negativePrompt, loraFilenames: body.loraFilenames || [], promptAdditions,+ })).record };+ }+ // reactor.inc receives the trimmed prompt with nothing added.+ return asWritten(body, { backend });+}