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
treat a null Cast & Sets field as no change so a revision keeps the current value
[._.]/ Adam Eivy9166f75602cc
diff --git a/server/services/musicVideo/castAndSetsDirection.js b/server/services/musicVideo/castAndSetsDirection.jsindex e8bbde86e9..d102d7c6b2 100644--- a/server/services/musicVideo/castAndSetsDirection.js+++ b/server/services/musicVideo/castAndSetsDirection.js@@ -292,10 +292,13 @@ const flatten = (v) => (v == null ? '': 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.+// A list field answered as one string 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)));+// A null field means "nothing to change" (models write it when told to keep the rest), so it+// reads as absent and a revision keeps the current value; an empty string or list clears.+const withoutNulls = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).filter(([, x]) => x != null)) : v);-const protagonistSchema = z.object({+const protagonistSchema = z.preprocess(withoutNulls, z.object({name: prose(SHORT).optional(),description: prose(TEXT).optional(),face: prose(TEXT).optional(),@@ -310,14 +313,14 @@ const protagonistSchema = z.object({palette: prose(300).optional(),movement: prose(TEXT).optional(),expressions: proseList(300).optional(),-}).passthrough();-const worldSchema = z.object({+}).passthrough());+const worldSchema = z.preprocess(withoutNulls, z.object({layout: prose(TEXT).optional(),depth: prose(500).optional(),lighting: prose(500).optional(),camera: prose(500).optional(),transitions: prose(500).optional(),-}).passthrough();+}).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.const definitionsSchema = z.unknown().transform((value, ctx) => {diff --git a/server/services/musicVideo/castAndSetsDirection.test.js b/server/services/musicVideo/castAndSetsDirection.test.jsindex aeaf591d6a..3b9a915587 100644--- a/server/services/musicVideo/castAndSetsDirection.test.js+++ b/server/services/musicVideo/castAndSetsDirection.test.js@@ -92,11 +92,22 @@ describe('Cast & Sets direction', () => {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(parsed.protagonist).toMatchObject({ name: 'A', signature: 'true', palette: 'primary: #fff', rules: ['Never lands'] });+ expect(parsed.protagonist).not.toHaveProperty('gesture');+ expect(parsed.protagonist).not.toHaveProperty('expressions');+ expect(parsed.world).not.toHaveProperty('camera');expect(mergeCastAndSetsDirection(null, parsed, { sections, medium: 'procedural' }).missing).not.toContain('protagonist');});+ it('treats a null field in a revision as no change, and an empty one as a clear', () => {+ const { direction: previous } = mergeCastAndSetsDirection(null, parseCastAndSetsResponse(JSON.stringify({ ...ANSWER,+ protagonist: { ...ANSWER.protagonist, gesture: 'wave', rules: ['r1'] }, world: { camera: 'slow dolly' } })), { sections, moodImageCount: 4, medium: 'procedural' });+ const revision = parseCastAndSetsResponse(JSON.stringify({ protagonist: { hair: 'red', gesture: null, rules: null }, world: { camera: null, layout: '' } }));+ const { direction } = mergeCastAndSetsDirection(previous, revision, { sections, moodImageCount: 4, medium: 'procedural' });+ expect(direction.protagonist).toMatchObject({ hair: 'red', gesture: 'wave', rules: ['r1'] });+ expect(direction.world).toMatchObject({ camera: 'slow dolly', layout: '' });+ });+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({