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

keep a Cast & Sets protagonist whose palette came back as an object instead of failing the stage

[._.]/ Adam Eivyb43db6608da1
diff --git a/server/services/musicVideo/castAndSetsDirection.js b/server/services/musicVideo/castAndSetsDirection.js
index 814c09488d..d84291c784 100644
--- a/server/services/musicVideo/castAndSetsDirection.js
+++ b/server/services/musicVideo/castAndSetsDirection.js
@@ -283,29 +283,36 @@ export function buildCastAndSetsPrompt(project, { moodImages = [], board = null,
const isPlaceholder = (s) => typeof s === 'string' && /^\s*<.+>\s*$/.test(s);
const text = (max) => z.string().transform((s) => (isPlaceholder(s) ? '' : s.trim().slice(0, max)));
const slug = (s) => String(s || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40);
+// Prose fields a model sometimes answers in structure (a palette as {"primary":"#fff"} or a
+// list of hexes). Flatten those to text rather than letting one sub-field reject the whole
+// protagonist or world, which reads as "missing" and fails the stage.
+const flatten = (v) => (Array.isArray(v) ? v.map(flatten).filter(Boolean).join(', ')
+ : v && typeof v === 'object' ? Object.entries(v).map(([k, x]) => `${k}: ${flatten(x)}`).join(', ')
+ : typeof v === 'number' ? String(v) : v);
+const prose = (max) => z.preprocess(flatten, text(max));
const protagonistSchema = z.object({
- name: text(SHORT).optional(),
- description: text(TEXT).optional(),
- face: text(TEXT).optional(),
- hair: text(TEXT).optional(),
- signature: text(TEXT).optional(),
- gesture: text(TEXT).optional(),
+ name: prose(SHORT).optional(),
+ description: prose(TEXT).optional(),
+ face: prose(TEXT).optional(),
+ hair: prose(TEXT).optional(),
+ signature: prose(TEXT).optional(),
+ gesture: prose(TEXT).optional(),
rules: z.array(text(300)).optional(),
// Procedural medium: how the character is built and moves in code.
- construction: text(TEXT).optional(),
- shapeLanguage: text(500).optional(),
- materials: text(500).optional(),
- palette: text(300).optional(),
- movement: text(TEXT).optional(),
+ construction: prose(TEXT).optional(),
+ shapeLanguage: prose(500).optional(),
+ materials: prose(500).optional(),
+ palette: prose(300).optional(),
+ movement: prose(TEXT).optional(),
expressions: z.array(text(300)).optional(),
}).passthrough();
const worldSchema = z.object({
- layout: text(TEXT).optional(),
- depth: text(500).optional(),
- lighting: text(500).optional(),
- camera: text(500).optional(),
- transitions: text(500).optional(),
+ layout: prose(TEXT).optional(),
+ depth: prose(500).optional(),
+ lighting: prose(500).optional(),
+ camera: prose(500).optional(),
+ transitions: prose(500).optional(),
}).passthrough();
// Unusable definitions (not an object, or no character survives validation) count as
// absent so the merge keeps the current ones; `{ characters: [] }` is a deliberate clear.
diff --git a/server/services/musicVideo/castAndSetsDirection.test.js b/server/services/musicVideo/castAndSetsDirection.test.js
index b375accdd0..0fcf555e25 100644
--- a/server/services/musicVideo/castAndSetsDirection.test.js
+++ b/server/services/musicVideo/castAndSetsDirection.test.js
@@ -74,6 +74,17 @@ describe('Cast & Sets direction', () => {
expect(parseCastAndSetsResponse('no json here')).toBeNull();
});
+ it('keeps a protagonist whose prose fields came back as structure, flattening them to text', () => {
+ const parsed = parseCastAndSetsResponse(JSON.stringify({
+ logline: 'x',
+ protagonist: { name: 'The Vector', description: 'a paper airplane', palette: { primary: '#FFFFFF', accent: '#00F0FF' }, materials: ['paper', 'glow'] },
+ world: { lighting: { key: 'neon', fill: 0 } },
+ }));
+ expect(parsed.protagonist).toMatchObject({ name: 'The Vector', palette: 'primary: #FFFFFF, accent: #00F0FF', materials: 'paper, glow' });
+ expect(parsed.world.lighting).toBe('key: neon, fill: 0');
+ expect(mergeCastAndSetsDirection(null, parsed, { sections, medium: 'procedural' }).missing).not.toContain('protagonist');
+ });
+
it('on a revision keeps absent keys, applies present ones, and treats an empty value as a clear', () => {
const { direction: previous } = mergeCastAndSetsDirection(null, parseCastAndSetsResponse(JSON.stringify({ ...ANSWER, questions: ['Is she right?'], interpretation: 'agents' })), { sections, moodImageCount: 4 });
const revision = parseCastAndSetsResponse(JSON.stringify({