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 with null, boolean or single-string field answers

[._.]/ Adam Eivy4700868a3c28
diff --git a/server/services/musicVideo/castAndSetsDirection.js b/server/services/musicVideo/castAndSetsDirection.js
index d84291c784..e8bbde86e9 100644
--- a/server/services/musicVideo/castAndSetsDirection.js
+++ b/server/services/musicVideo/castAndSetsDirection.js
@@ -284,12 +284,16 @@ 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);
+// list of hexes), as null when it has nothing to say, or as a bare boolean. Flatten those to
+// text rather than letting one sub-field reject the whole protagonist or world, which reads
+// as "missing" and fails the stage. Empty and null parts are dropped from the flattened text.
+const flatten = (v) => (v == null ? ''
+ : Array.isArray(v) ? v.map(flatten).filter(Boolean).join(', ')
+ : typeof v === 'object' ? Object.entries(v).map(([k, x]) => [k, flatten(x)]).filter(([, x]) => x).map(([k, x]) => `${k}: ${x}`).join(', ')
+ : typeof v === 'number' || typeof v === 'boolean' ? String(v) : v);
const prose = (max) => z.preprocess(flatten, text(max));
+// A list field answered as one string (or null) instead of an array of strings.
+const proseList = (max) => z.preprocess((v) => (v == null ? [] : Array.isArray(v) ? v : [v]), z.array(prose(max)).transform((items) => items.filter(Boolean)));
const protagonistSchema = z.object({
name: prose(SHORT).optional(),
@@ -298,14 +302,14 @@ const protagonistSchema = z.object({
hair: prose(TEXT).optional(),
signature: prose(TEXT).optional(),
gesture: prose(TEXT).optional(),
- rules: z.array(text(300)).optional(),
+ rules: proseList(300).optional(),
// Procedural medium: how the character is built and moves in code.
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(),
+ expressions: proseList(300).optional(),
}).passthrough();
const worldSchema = z.object({
layout: prose(TEXT).optional(),
diff --git a/server/services/musicVideo/castAndSetsDirection.test.js b/server/services/musicVideo/castAndSetsDirection.test.js
index 0fcf555e25..aeaf591d6a 100644
--- a/server/services/musicVideo/castAndSetsDirection.test.js
+++ b/server/services/musicVideo/castAndSetsDirection.test.js
@@ -85,6 +85,18 @@ describe('Cast & Sets direction', () => {
expect(mergeCastAndSetsDirection(null, parsed, { sections, medium: 'procedural' }).missing).not.toContain('protagonist');
});
+ it('keeps a protagonist with null, boolean or single-string answers in its fields', () => {
+ const parsed = parseCastAndSetsResponse(JSON.stringify({
+ logline: 'x',
+ protagonist: { name: 'A', description: 'b', gesture: null, signature: true, palette: { primary: '#fff', accent: null },
+ rules: 'Never lands', expressions: null },
+ world: { camera: null },
+ }));
+ expect(parsed.protagonist).toMatchObject({ name: 'A', gesture: '', signature: 'true', palette: 'primary: #fff', rules: ['Never lands'], expressions: [] });
+ expect(parsed.world.camera).toBe('');
+ 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({