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

Link music videos to the catalog cast, sets and props they use (#11915)

[._.]/fe8a964d09fa
diff --git a/client/src/components/musicVideo/CreativeSetupPanel.jsx b/client/src/components/musicVideo/CreativeSetupPanel.jsx
index 9926e71605..57f62c2b86 100644
--- a/client/src/components/musicVideo/CreativeSetupPanel.jsx
+++ b/client/src/components/musicVideo/CreativeSetupPanel.jsx
@@ -6,11 +6,25 @@ import { listUniverseNames, getUniverse } from '../../services/apiUniverseBuilde
import { uuidv4 } from '../../lib/uuid.js';
import { pullUniverseCanonReferences } from '../../lib/musicVideoUniverseRefs.js';
import CharacterStylePicker from './CharacterStylePicker.jsx';
+import IngredientPicker from '../IngredientPicker.jsx';
const inputClass = 'w-full min-w-0 bg-port-bg border border-port-border rounded px-2 py-1.5 text-sm';
const kinds = [['character', 'Cast'], ['place', 'Places'], ['object', 'Objects']];
const fields = { character: 'characters', place: 'places', object: 'objects' };
+// A catalog record as a canon-shaped entry, so its image joins the look
+// references the same way a universe entry's does. Attached catalog media wins.
+// No canonId: that names an entry in this video's own universe.
+const catalogEntry = (ingredient) => {
+ const payload = ingredient.payload || {};
+ return {
+ ingredientId: ingredient.id,
+ name: ingredient.name,
+ primaryImageRef: ingredient.thumbnailKey || payload.primaryImageRef || null,
+ imageRefs: Array.isArray(payload.imageRefs) ? payload.imageRefs : [],
+ };
+};
+
/** Project-owned snapshots: changing source canon never silently recasts a video. */
export default function CreativeSetupPanel({ project, onSave, onPendingChange }) {
const [editing, setEditing] = useState(false);
@@ -25,6 +39,7 @@ export default function CreativeSetupPanel({ project, onSave, onPendingChange })
const [newName, setNewName] = useState('');
const [newDescription, setNewDescription] = useState('');
const [selectedCanon, setSelectedCanon] = useState([]);
+ const [catalogKind, setCatalogKind] = useState(null);
const universeId = draft?.universeId ?? project.concept?.universeId ?? '';
const universeReady = !universeId || (!loading && universe?.id === universeId);
const subjects = editing ? (draft?.subjects || []) : (project.concept?.subjects || []);
@@ -69,7 +84,7 @@ export default function CreativeSetupPanel({ project, onSave, onPendingChange })
};
const add = (kind, name, description, canon) => {
if (!name.trim() || subjects.length >= 24) return;
- const subject = { id: `mvc-${uuidv4()}`, kind, name: name.trim().slice(0, 120), description: (description || '').slice(0, 1000), ...(kind === 'character' ? { role: subjects.some((s) => s.kind === 'character') ? 'supporting' : 'protagonist' } : {}), ...(canon?.id ? { canonId: canon.id } : {}) };
+ const subject = { id: `mvc-${uuidv4()}`, kind, name: name.trim().slice(0, 120), description: (description || '').slice(0, 1000), ...(kind === 'character' ? { role: subjects.some((s) => s.kind === 'character') ? 'supporting' : 'protagonist' } : {}), ...(canon?.id ? { canonId: canon.id } : {}), ...(canon?.ingredientId ? { ingredientId: canon.ingredientId } : {}) };
setDraft((d) => ({ ...d, subjects: [...d.subjects, subject] }));
if (canon) setSelectedCanon((items) => [...items, { subjectId: subject.id, kind, entry: canon }]);
};
@@ -125,8 +140,25 @@ export default function CreativeSetupPanel({ project, onSave, onPendingChange })
<select id={idFor(`pick-${kind}`)} value="" className={inputClass} disabled={subjects.length >= 24} onChange={(e) => {
const entry = (universe[fields[kind]] || []).find((item) => item.id === e.target.value);
if (entry) add(kind, entry.name, entry.physicalDescription || entry.description, entry);
- }}><option value="">Add from universe…</option>{(universe[fields[kind]] || []).filter((entry) => !subjects.some((s) => s.canonId === entry.id && s.kind === kind)).map((entry) => <option key={entry.id} value={entry.id}>{entry.name}</option>)}</select>
+ }}><option value="">Add from universe…</option>{(universe[fields[kind]] || []).filter((entry) => !subjects.some((s) => s.kind === kind && (s.canonId === entry.id || (entry.ingredientId && s.ingredientId === entry.ingredientId)))).map((entry) => <option key={entry.id} value={entry.id}>{entry.name}</option>)}</select>
</div>)}</div>}
+ <div className="flex flex-wrap items-center gap-x-3" role="group" aria-label="Add from catalog">
+ <span className="text-xs text-port-text-muted">From the catalog:</span>
+ {kinds.map(([kind, label]) => <button key={kind} type="button" disabled={subjects.length >= 24} onClick={() => setCatalogKind(kind)} className="text-sm text-port-accent min-h-[44px] disabled:opacity-50">Add {label.toLowerCase()}</button>)}
+ </div>
+ <IngredientPicker
+ open={!!catalogKind}
+ type={catalogKind || undefined}
+ excludeIds={subjects.map((s) => s.ingredientId).filter(Boolean)}
+ onClose={() => setCatalogKind(null)}
+ onSelect={(ingredient) => {
+ const kind = catalogKind;
+ setCatalogKind(null);
+ if (!ingredient || !kind) return;
+ const payload = ingredient.payload || {};
+ add(kind, ingredient.name || '', payload.physicalDescription || payload.description || '', catalogEntry(ingredient));
+ }}
+ />
<p className="text-xs text-port-text-muted">Up to 24 subjects. Selected canon images are added as look references when space is available; enable “Condition frames” in Look references to use their pixels.</p>
<ul className="space-y-2">{subjects.map((subject) => <li key={subject.id} className="border border-port-border rounded p-2 space-y-1">
<div className="flex flex-wrap items-center gap-2"><span className="text-sm min-w-0 flex-1 break-words">{subject.name} · {subject.kind}</span>
diff --git a/client/src/components/musicVideo/CreativeSetupPanel.test.jsx b/client/src/components/musicVideo/CreativeSetupPanel.test.jsx
index 033cf6d0a8..5f853d5f35 100644
--- a/client/src/components/musicVideo/CreativeSetupPanel.test.jsx
+++ b/client/src/components/musicVideo/CreativeSetupPanel.test.jsx
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
+import { render, screen, fireEvent, waitFor, act, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import CreativeSetupPanel from './CreativeSetupPanel.jsx';
import { getUniverse } from '../../services/apiUniverseBuilder.js';
@@ -12,6 +12,13 @@ vi.mock('../../services/apiMusicVideo.js', () => ({
listMusicVideoCharacterStyles: vi.fn(async () => [CLAUDIA]),
setMusicVideoCharacterStyleReference: vi.fn(async (_id, imageId) => ({ ...CLAUDIA, referenceImageId: imageId })),
}));
+vi.mock('../IngredientPicker.jsx', () => ({
+ default: ({ open: isOpen, type, excludeIds, onSelect }) => (isOpen ? (
+ <div role="dialog" aria-label={`Pick ${type}`} data-exclude={excludeIds.join(',')}>
+ <button type="button" onClick={() => onSelect({ id: 'cat-plc-7', type: 'place', name: 'Night diner', thumbnailKey: 'diner.png', payload: { description: 'Chrome booths' } })}>Night diner</button>
+ </div>
+ ) : null),
+}));
const project = { id: 'mv1', concept: {}, visualSpec: {} };
const open = (onSave = vi.fn(async () => {})) => {
render(<MemoryRouter><CreativeSetupPanel project={project} onSave={onSave} onPendingChange={vi.fn()} /></MemoryRouter>);
@@ -44,6 +51,29 @@ describe('creative setup', () => {
});
expect(onSave.mock.calls[0][0]).not.toHaveProperty('visualSpec');
});
+ it('casts from the catalog and from universe canon with the catalog link, adding the catalog image as a look reference', async () => {
+ getUniverse.mockResolvedValue({ id: 'u1', name: 'Example universe', characters: [{ id: 'c1', ingredientId: 'cat-chr-1', name: 'Example singer', physicalDescription: 'Silver coat' }], places: [], objects: [] });
+ const onSave = open();
+ await screen.findByText('Example universe');
+ fireEvent.change(screen.getByLabelText('Universe'), { target: { value: 'u1' } });
+ await screen.findByText('Example singer');
+ fireEvent.change(screen.getByLabelText('Select cast'), { target: { value: 'c1' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Add places' }));
+ fireEvent.click(within(screen.getByRole('dialog', { name: 'Pick place' })).getByText('Night diner'));
+ expect(screen.queryByRole('dialog')).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'Add places' }));
+ expect(screen.getByRole('dialog', { name: 'Pick place' })).toHaveAttribute('data-exclude', 'cat-chr-1,cat-plc-7');
+ fireEvent.click(screen.getByText('Save creative setup'));
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
+ const saved = onSave.mock.calls[0][0];
+ expect(saved.concept.subjects).toMatchObject([
+ { kind: 'character', name: 'Example singer', canonId: 'c1', ingredientId: 'cat-chr-1' },
+ { kind: 'place', name: 'Night diner', description: 'Chrome booths', ingredientId: 'cat-plc-7' },
+ ]);
+ expect(saved.concept.subjects[1]).not.toHaveProperty('canonId');
+ expect(saved.visualSpec.references).toEqual([expect.objectContaining({ imageId: 'diner.png', role: 'set', label: 'Night diner', condition: false })]);
+ });
+
it('discards an unsaved cast when the director cancels setup', async () => {
const onSave = open();
fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Unsaved singer' } });
diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.js
index 28a73cc9bd..85b2a98ad3 100644
--- a/server/lib/catalogValidation.js
+++ b/server/lib/catalogValidation.js
@@ -55,6 +55,7 @@ export const REF_KINDS = Object.freeze([
'issue',
'work',
'creative-director',
+ 'music-video',
]);
// Relation kinds derived from the shared registry (`catalogTypes.js`) — adding
diff --git a/server/lib/catalogValidation.test.js b/server/lib/catalogValidation.test.js
index af64eb8af0..f22119cdca 100644
--- a/server/lib/catalogValidation.test.js
+++ b/server/lib/catalogValidation.test.js
@@ -41,8 +41,8 @@ describe('catalogValidation — ingredient types & ref kinds', () => {
expect(Object.isFrozen(INGREDIENT_TYPES)).toBe(true);
});
- it('exposes the documented ref kinds (universe/series/issue/work/creative-director)', () => {
- expect(REF_KINDS).toEqual(['universe', 'series', 'issue', 'work', 'creative-director']);
+ it('exposes the documented ref kinds (universe/series/issue/work/creative-director/music-video)', () => {
+ expect(REF_KINDS).toEqual(['universe', 'series', 'issue', 'work', 'creative-director', 'music-video']);
expect(Object.isFrozen(REF_KINDS)).toBe(true);
});
});
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.js
index 9884613c12..47d2490761 100644
--- a/server/lib/musicVideoValidation.js
+++ b/server/lib/musicVideoValidation.js
@@ -121,6 +121,9 @@ export const musicVideoConceptSchema = z.object({
description: z.string().max(1000).optional(),
role: z.enum(['protagonist', 'band', 'supporting']).optional(),
canonId: z.string().max(64).optional(),
+ // The catalog record this subject was cast from (Casting / Environments /
+ // Objects). The project keeps its own name and description snapshot.
+ ingredientId: z.string().max(128).optional(),
}).strict()).max(24).optional(),
}).strict();
diff --git a/server/lib/threadRefKinds.js b/server/lib/threadRefKinds.js
index 84556da7b6..ee759909d5 100644
--- a/server/lib/threadRefKinds.js
+++ b/server/lib/threadRefKinds.js
@@ -62,7 +62,7 @@ export const THREAD_REF_KINDS = Object.freeze({
},
// ─── App-native creative records ─────────────────────────────────────────
- // These five are the vocabulary `catalog_ingredient_refs` already stores
+ // These are the vocabulary `catalog_ingredient_refs` already stores
// (server/services/catalogRefResolver.js REF_TARGET_TABLES). Their routes
// moved here from the hard-coded switch in client/src/pages/CatalogIngredient.jsx
// so there is exactly one kind→route table in the repo.
@@ -70,6 +70,7 @@ export const THREAD_REF_KINDS = Object.freeze({
series: { label: 'Series', external: false, navPath: '/pipeline', basePath: '/pipeline/series', segment: true },
issue: { label: 'Issues', external: false, navPath: '/pipeline', basePath: '/pipeline/issues', segment: true, suffix: '/concept' },
'creative-director': { label: 'Creative Director', external: false, navPath: '/creative-director', segment: true, suffix: '/overview' },
+ 'music-video': { label: 'Music Videos', external: false, navPath: '/music-video', segment: true },
'writers-room': { label: "Writers' Room", external: false, navPath: '/writers-room' },
// ─── Other PortOS records ────────────────────────────────────────────────
diff --git a/server/services/catalogDB/refs.js b/server/services/catalogDB/refs.js
index a9340a311e..adf0a69615 100644
--- a/server/services/catalogDB/refs.js
+++ b/server/services/catalogDB/refs.js
@@ -142,6 +142,15 @@ const UNIVERSE_REF_ROLE_BY_TYPE = Object.freeze({
});
export const universeRefRoleForType = (type) => UNIVERSE_REF_ROLE_BY_TYPE[type] || 'reference';
+// Music video subject kind → ref role. A music video casts characters and
+// films in sets with props; the subject kind is the catalog type.
+const MUSIC_VIDEO_REF_ROLE_BY_TYPE = Object.freeze({
+ character: 'cast',
+ place: 'set',
+ object: 'prop',
+});
+export const musicVideoRefRoleForType = (type) => MUSIC_VIDEO_REF_ROLE_BY_TYPE[type] || 'reference';
+
// Link a batch of already-resolved catalog ingredients to a Creative Director
// project via catalog_ingredient_refs with ref_kind='creative-director' (#1808)
diff --git a/server/services/catalogRefResolver.js b/server/services/catalogRefResolver.js
index e4bda9744b..2e0a8497ef 100644
--- a/server/services/catalogRefResolver.js
+++ b/server/services/catalogRefResolver.js
@@ -2,14 +2,15 @@
* Catalog ref resolver + dangling-ref integrity (#1018).
*
* `catalog_ingredient_refs` records which app-native record (universe / series /
- * issue / work / creative-director) consumes a catalog ingredient, by a
+ * issue / work / creative-director / music-video) consumes a catalog ingredient, by a
* `(ref_kind, ref_id)` STRING tuple with NO database foreign key — deliberately
* (design #999, decision D3): a ref can federate to a peer BEFORE its target
* arrives, and a hard FK would make catalog sync FAIL on out-of-order apply.
*
- * Now that all five target kinds are DB-native (universes #1014, pipeline
+ * Now that every target kind is DB-native (universes #1014, pipeline
* series/issues #1015, writers_room_works #1017, creative_director_projects
- * #997), this module delivers the integrity #999 asked for WITHOUT a constraint:
+ * #997, music_video_projects), this module delivers the integrity #999 asked
+ * for WITHOUT a constraint:
*
* - resolveRefs(tuples) → which tuples point at a LIVE target
* - listDanglingRefs() → live refs whose target no longer resolves
@@ -23,7 +24,7 @@
import { query } from '../lib/db.js';
// ref_kind → the DB table its ref_id points at, plus the predicate that makes a
-// row a LIVE target. All five target kinds soft-delete (a `deleted` column;
+// row a LIVE target. Every target kind soft-deletes (a `deleted` column;
// creative_director_projects gained one in #1564 so its deletion federates), so
// a live target is `deleted = FALSE` in every case. This map is the single
// source of truth for the resolver — adding a new referenceable record kind
@@ -34,6 +35,7 @@ export const REF_TARGET_TABLES = Object.freeze({
issue: { table: 'pipeline_issues', liveClause: 'deleted = FALSE' },
work: { table: 'writers_room_works', liveClause: 'deleted = FALSE' },
'creative-director': { table: 'creative_director_projects', liveClause: 'deleted = FALSE' },
+ 'music-video': { table: 'music_video_projects', liveClause: 'deleted = FALSE' },
});
/** The ref kinds this resolver can resolve (those with a known target table). */
diff --git a/server/services/musicVideo/catalogLinks.js b/server/services/musicVideo/catalogLinks.js
new file mode 100644
index 0000000000..a0f2d7ae63
--- /dev/null
+++ b/server/services/musicVideo/catalogLinks.js
@@ -0,0 +1,72 @@
+// Keeps a music video's catalog links (catalog_ingredient_refs, ref_kind
+// 'music-video') in step with the subjects it cast from Casting, Environments
+// and Objects, so a catalog record shows which videos use it. The subjects keep
+// their own name/description snapshot; only the link lives in the catalog.
+
+import { isFileBackend } from '../../lib/pgFileFacade.js';
+
+const REF_KIND = 'music-video';
+
+// `ingredientId → role` for the project's catalog-linked subjects.
+function desiredCatalogLinks(project, roleForType) {
+ const subjects = project && !project.deleted && Array.isArray(project.concept?.subjects) ? project.concept.subjects : [];
+ const links = new Map();
+ for (const subject of subjects) {
+ if (typeof subject?.ingredientId === 'string' && subject.ingredientId) {
+ links.set(subject.ingredientId, roleForType(subject.kind));
+ }
+ }
+ return links;
+}
+
+// One sync per project at a time; a save landing mid-sync re-syncs after.
+const syncing = new Map();
+
+/**
+ * Link every catalog-cast subject and unlink records the project no longer
+ * casts. A deleted (or missing) project unlinks everything. Fire-and-forget
+ * from the project write paths: the save already succeeded.
+ */
+function syncProjectCatalogLinks(projectId) {
+ if (!projectId || isFileBackend()) return Promise.resolve(null);
+ const running = syncing.get(projectId);
+ if (running) {
+ running.again = true;
+ return running.promise;
+ }
+ const state = { again: false, promise: null };
+ state.promise = (async () => {
+ const [catalogDB, { getProject }] = await Promise.all([import('../catalogDB.js'), import('./projects.js')]);
+ let stats = null;
+ do {
+ state.again = false;
+ const project = await getProject(projectId);
+ const desired = desiredCatalogLinks(project, catalogDB.musicVideoRefRoleForType);
+ const current = await catalogDB.listIngredientsForRef(REF_KIND, projectId);
+ stats = { linked: 0, unlinked: 0 };
+ for (const { ingredient, role } of current) {
+ if (desired.get(ingredient.id) === role) continue;
+ await catalogDB.unlinkIngredientFromRef(ingredient.id, REF_KIND, projectId, role);
+ stats.unlinked++;
+ }
+ const have = new Set(current.map(({ ingredient, role }) => `${ingredient.id}\n${role}`));
+ for (const [ingredientId, role] of desired) {
+ if (have.has(`${ingredientId}\n${role}`)) continue;
+ await catalogDB.linkIngredientToRef(ingredientId, REF_KIND, projectId, role);
+ stats.linked++;
+ }
+ } while (state.again);
+ return stats;
+ })().finally(() => syncing.delete(projectId));
+ syncing.set(projectId, state);
+ return state.promise;
+}
+
+// Fire-and-forget from the project write paths; resolves to the sync's
+// { linked, unlinked } (null on failure or the file backend).
+export function queueProjectCatalogLinkSync(projectId) {
+ return syncProjectCatalogLinks(projectId).catch((err) => {
+ console.error(`❌ Music Video ${String(projectId).slice(0, 8)}: catalog link sync failed: ${err.message}`);
+ return null;
+ });
+}
diff --git a/server/services/musicVideo/catalogLinks.test.js b/server/services/musicVideo/catalogLinks.test.js
new file mode 100644
index 0000000000..55710a21b7
--- /dev/null
+++ b/server/services/musicVideo/catalogLinks.test.js
@@ -0,0 +1,76 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+vi.mock('../../lib/pgFileFacade.js', () => ({ isFileBackend: () => false }));
+const catalogDB = vi.hoisted(() => ({
+ listIngredientsForRef: vi.fn(),
+ linkIngredientToRef: vi.fn(),
+ unlinkIngredientFromRef: vi.fn(),
+ musicVideoRefRoleForType: (type) => ({ character: 'cast', place: 'set', object: 'prop' })[type] || 'mentioned',
+}));
+vi.mock('../catalogDB.js', () => catalogDB);
+const getProject = vi.hoisted(() => vi.fn());
+vi.mock('./projects.js', () => ({ getProject }));
+
+const { queueProjectCatalogLinkSync: syncProjectCatalogLinks } = await import('./catalogLinks.js');
+
+const subject = (id, kind, ingredientId) => ({ id, kind, name: id, ...(ingredientId ? { ingredientId } : {}) });
+
+describe('syncProjectCatalogLinks', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ catalogDB.linkIngredientToRef.mockResolvedValue();
+ catalogDB.unlinkIngredientFromRef.mockResolvedValue();
+ });
+
+ it('links newly cast catalog records, keeps existing links, and unlinks dropped or re-typed ones', async () => {
+ getProject.mockResolvedValue({ id: 'mv-1', concept: { subjects: [
+ subject('s1', 'character', 'cat-chr-1'),
+ subject('s2', 'place', 'cat-plc-1'),
+ subject('s3', 'object'),
+ subject('s4', 'object', 'cat-obj-1'),
+ ] } });
+ catalogDB.listIngredientsForRef.mockResolvedValue([
+ { ingredient: { id: 'cat-chr-1' }, role: 'cast' },
+ { ingredient: { id: 'cat-chr-9' }, role: 'cast' },
+ { ingredient: { id: 'cat-obj-1' }, role: 'set' },
+ ]);
+
+ const stats = await syncProjectCatalogLinks('mv-1');
+
+ expect(catalogDB.listIngredientsForRef).toHaveBeenCalledWith('music-video', 'mv-1');
+ expect(catalogDB.unlinkIngredientFromRef.mock.calls).toEqual([
+ ['cat-chr-9', 'music-video', 'mv-1', 'cast'],
+ ['cat-obj-1', 'music-video', 'mv-1', 'set'],
+ ]);
+ expect(catalogDB.linkIngredientToRef.mock.calls).toEqual([
+ ['cat-plc-1', 'music-video', 'mv-1', 'set'],
+ ['cat-obj-1', 'music-video', 'mv-1', 'prop'],
+ ]);
+ expect(stats).toEqual({ linked: 2, unlinked: 2 });
+ });
+
+ it('unlinks everything for a deleted project', async () => {
+ getProject.mockResolvedValue(null);
+ catalogDB.listIngredientsForRef.mockResolvedValue([{ ingredient: { id: 'cat-chr-1' }, role: 'cast' }]);
+ await syncProjectCatalogLinks('mv-2');
+ expect(catalogDB.unlinkIngredientFromRef).toHaveBeenCalledWith('cat-chr-1', 'music-video', 'mv-2', 'cast');
+ expect(catalogDB.linkIngredientToRef).not.toHaveBeenCalled();
+ });
+
+ it('re-syncs once when a save lands mid-sync instead of running two syncs at once', async () => {
+ let release;
+ getProject
+ .mockImplementationOnce(() => new Promise((r) => { release = () => r({ concept: { subjects: [] } }); }))
+ .mockResolvedValue({ concept: { subjects: [subject('s1', 'character', 'cat-chr-1')] } });
+ catalogDB.listIngredientsForRef.mockResolvedValue([]);
+
+ const first = syncProjectCatalogLinks('mv-3');
+ await vi.waitFor(() => expect(release).toBeTypeOf('function'));
+ const second = syncProjectCatalogLinks('mv-3');
+ release();
+ await Promise.all([first, second]);
+
+ expect(getProject).toHaveBeenCalledTimes(2);
+ expect(catalogDB.linkIngredientToRef).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/server/services/musicVideo/projects.js b/server/services/musicVideo/projects.js
index 76b3d0e5fa..3848a099fe 100644
--- a/server/services/musicVideo/projects.js
+++ b/server/services/musicVideo/projects.js
@@ -31,6 +31,7 @@ import { RENDER_TARGET } from '../../lib/renderTargets.js';
import { VIDEO_GEN_MODE, resolveVideoMode } from '../videoGen/modes.js';
import { getSettings } from '../settings.js';
import { withStyleSnapshots } from './styleSnapshots.js';
+import { queueProjectCatalogLinkSync } from './catalogLinks.js';
// Shared dispatcher (#2899). ensureSchema() runs inside the selector (mirroring
// memoryBackend.js) so the backend is self-sufficient regardless of boot ordering.
@@ -182,12 +183,14 @@ export async function createProject(input) {
const snapshotted = await withStyleSnapshots(seeded);
const project = await (await selectBackend()).createProject(snapshotted);
announceNewProject(project.id);
+ queueProjectCatalogLinkSync(project.id);
return project;
}
export async function cloneProject(id, options = {}) {
const project = await (await selectBackend()).cloneProject(id, options);
announceNewProject(project.id);
+ queueProjectCatalogLinkSync(project.id);
return project;
}
@@ -197,13 +200,16 @@ export async function updateProject(id, patch) {
const needsSnapshot = seeded?.concept?.universeId !== undefined || seeded?.concept?.characterStyleId !== undefined
|| seeded?.visualSpec?.moodBoardId !== undefined;
const resolved = needsSnapshot ? await withStyleSnapshots(seeded, await backend.getProject(id)) : seeded;
+ const castChanged = resolved?.concept?.subjects !== undefined;
if (!Array.isArray(resolved.scenes)) {
const next = await backend.updateProject(id, resolved);
emitRecordUpdated('musicVideoProject', id);
+ if (castChanged) queueProjectCatalogLinkSync(id);
return next;
}
const { applyProjectPatch } = await import('./projectsLogic.js');
const { project } = await mutateProjectRecord(id, current => ({ project: applyProjectPatch(current, resolved) }));
+ if (castChanged) queueProjectCatalogLinkSync(id);
return project;
}
@@ -226,6 +232,7 @@ export async function deleteProject(id) {
const result = await (await selectBackend()).deleteProject(id);
// Soft-delete tombstone — push the deletion to subscribed peers immediately.
emitRecordDeleted('musicVideoProject', id);
+ queueProjectCatalogLinkSync(id);
// Its cached shot segments are regenerable, and only this machine's.
await import('./shotSegments.js').then(({ removeProjectSegments }) => removeProjectSegments(id)).catch((err) => {
console.warn(`⚠️ Music Video ${id.slice(0, 8)}: could not remove its cached shot segments: ${err.message}`);
diff --git a/server/services/threadRefs.js b/server/services/threadRefs.js
index 58505022dc..e21f2a1e04 100644
--- a/server/services/threadRefs.js
+++ b/server/services/threadRefs.js
@@ -62,6 +62,7 @@ const DB_REF_TABLES = Object.freeze({
issue: { table: 'pipeline_issues', titleExpr: "COALESCE(NULLIF(data->>'title', ''), 'Issue ' || COALESCE(number::text, id))", liveClause: 'deleted = FALSE' },
'writers-room': { table: 'writers_room_works', titleExpr: 'title', liveClause: 'deleted = FALSE' },
'creative-director': { table: 'creative_director_projects', titleExpr: "NULLIF(data->>'title', '')", liveClause: 'deleted = FALSE' },
+ 'music-video': { table: 'music_video_projects', titleExpr: "NULLIF(data->>'name', '')", liveClause: 'deleted = FALSE' },
'catalog.ingredient': { table: 'catalog_ingredients', titleExpr: 'name', liveClause: 'deleted = FALSE', contextExpr: 'type' },
'catalog.scrap': { table: 'catalog_scraps', titleExpr: "NULLIF(title, '')", liveClause: 'deleted = FALSE' },
});