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
refactor(pipeline): share zod bible schemas with writers-room
Adam Eivy3183f0a11e3b
diff --git a/server/lib/validation.js b/server/lib/validation.jsindex 8afaafea1d..986b3bf1ef 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -625,7 +625,9 @@ export const writersRoomCharacterUpdateSchema = z.object({}).strict();const wrSettingTextField = z.string().max(2000);-export const writersRoomSettingCreateSchema = z.object({+// Inner ZodObject (without refine) — exposed so the Pipeline can `.extend()`+// it; `.refine()` returns a ZodEffects which has no `.extend()`.+const writersRoomSettingCreateObject = z.object({name: z.string().trim().max(200).optional(),slugline: z.string().trim().max(200).optional(),description: wrSettingTextField.optional(),@@ -634,9 +636,13 @@ export const writersRoomSettingCreateSchema = z.object({weather: wrSettingTextField.optional(),recurringDetails: wrSettingTextField.optional(),notes: wrSettingTextField.optional(),-}).strict().refine((v) => (v.name && v.name.trim()) || (v.slugline && v.slugline.trim()), {- message: 'Setting requires either a slugline or a name',-});+}).strict();+const settingHasIdentifier = (v) =>+ (v.name && v.name.trim()) || (v.slugline && v.slugline.trim());+export const writersRoomSettingCreateSchema = writersRoomSettingCreateObject.refine(+ settingHasIdentifier,+ { message: 'Setting requires either a slugline or a name' },+);export const writersRoomSettingUpdateSchema = z.object({name: z.string().trim().max(200).optional(),slugline: z.string().trim().max(200).optional(),@@ -664,6 +670,26 @@ export const writersRoomObjectUpdateSchema = z.object({notes: wrObjectTextField.optional(),}).strict();+// Generic bible-entry schemas — re-exports of the writers-room schemas under+// kind-neutral names so the Pipeline routes can share the same validation+// surface. The Pipeline extends these with its own back-compat fields+// (`description` legacy alias on character, `imageRefs`, `id`) in+// `server/routes/pipeline.js`; both surfaces ultimately funnel through the+// canonical sanitizer in `server/lib/storyBible.js`.+//+// NOTE: `settingBibleCreateSchema` is the un-refined ZodObject (not the+// refined ZodEffects export `writersRoomSettingCreateSchema`) so callers+// can `.extend()` it. The "needs name or slugline" refine is exported as+// `settingBibleRefine` so extenders can re-apply it after extending.+export const characterBibleCreateSchema = writersRoomCharacterCreateSchema;+export const characterBibleUpdateSchema = writersRoomCharacterUpdateSchema;+export const settingBibleCreateSchema = writersRoomSettingCreateObject;+export const settingBibleRefine = settingHasIdentifier;+export const settingBibleRefineMessage = 'Setting requires either a slugline or a name';+export const settingBibleUpdateSchema = writersRoomSettingUpdateSchema;+export const objectBibleCreateSchema = writersRoomObjectCreateSchema;+export const objectBibleUpdateSchema = writersRoomObjectUpdateSchema;+// =============================================================================// FEATURE AGENT SCHEMAS// =============================================================================diff --git a/server/routes/pipeline.js b/server/routes/pipeline.jsindex b92d66b8f9..dca8864089 100644--- a/server/routes/pipeline.js+++ b/server/routes/pipeline.js@@ -25,7 +25,12 @@import { Router } from 'express';import { z } from 'zod';import { asyncHandler, ServerError } from '../lib/errorHandler.js';-import { validateRequest } from '../lib/validation.js';+import {+ validateRequest,+ characterBibleCreateSchema,+ settingBibleCreateSchema,+ objectBibleCreateSchema,+} from '../lib/validation.js';import * as seriesSvc from '../services/pipeline/series.js';import * as issuesSvc from '../services/pipeline/issues.js';import { generateStage } from '../services/pipeline/textStages.js';@@ -54,26 +59,33 @@ const mapServiceError = (err) => {// ---- Series schemas -----// Bible entries are sanitized server-side via the canonical shape in-// `server/lib/storyBible.js`; the route schema is intentionally permissive-// (max length only) so additive fields don't require a schema migration.-const bibleEntrySchema = z.record(z.string(), z.any());--const characterSchema = z.object({+// Bible entry shape is owned by the canonical schemas in `server/lib/validation.js`+// (re-exports of the Writers Room character/setting/object create-schemas). The+// Pipeline extends them here with its own back-compat fields and uses+// `.passthrough()` so canonical sanitizer-emitted fields (`evidence`,+// `firstAppearance`, `source`, `createdAt`, `updatedAt`, `missingFromProse`)+// round-trip cleanly when the client re-saves an existing series. Final+// enforcement lives in the sanitizer in `server/lib/storyBible.js`.+const characterSchema = characterBibleCreateSchema.extend({id: z.string().trim().max(80).optional(),- name: z.string().trim().min(1).max(seriesSvc.CHARACTER_NAME_MAX),// Back-compat: pre-DRY shape used `description`. Both fields are accepted// and the canonical sanitizer normalizes them to `physicalDescription`.description: z.string().trim().max(seriesSvc.CHARACTER_DESCRIPTION_MAX).optional(),- physicalDescription: z.string().trim().max(seriesSvc.CHARACTER_DESCRIPTION_MAX).optional(),- aliases: z.array(z.string().trim().min(1).max(100)).max(12).optional(),- role: z.string().trim().max(200).optional(),- personality: z.string().trim().max(2000).optional(),- background: z.string().trim().max(2000).optional(),- notes: z.string().trim().max(4000).optional(),+ // Pipeline-only image refs (not present on the writers-room shape).imageRefs: z.array(z.string().trim().min(1).max(seriesSvc.IMAGE_REF_MAX)).max(seriesSvc.IMAGE_REFS_PER_CHARACTER_MAX).optional(),-});+ // Pipeline preserves a looser `notes` cap (4000) than the writers-room+ // base (2000) — overriding here so user-facing limits don't tighten.+ notes: z.string().trim().max(4000).optional(),+}).passthrough();++const settingSchema = settingBibleCreateSchema.extend({+ id: z.string().trim().max(80).optional(),+}).passthrough();++const objectSchema = objectBibleCreateSchema.extend({+ id: z.string().trim().max(80).optional(),+}).passthrough();const seriesCreateSchema = z.object({name: z.string().trim().min(1).max(seriesSvc.NAME_MAX),@@ -82,8 +94,8 @@ const seriesCreateSchema = z.object({worldId: z.string().trim().max(seriesSvc.WORLD_ID_MAX).nullable().optional(),writersRoomWorkId: z.string().trim().max(seriesSvc.WRITERS_ROOM_WORK_ID_MAX).nullable().optional(),characters: z.array(characterSchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),- settings: z.array(bibleEntrySchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),- objects: z.array(bibleEntrySchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),+ settings: z.array(settingSchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),+ objects: z.array(objectSchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),styleNotes: z.string().trim().max(seriesSvc.STYLE_NOTES_MAX).optional().default(''),targetFormat: z.enum(seriesSvc.TARGET_FORMATS).optional(),issueCountTarget: z.number().int().min(0).max(seriesSvc.ISSUE_COUNT_TARGET_MAX).optional(),@@ -96,8 +108,8 @@ const seriesPatchSchema = z.object({worldId: z.string().trim().max(seriesSvc.WORLD_ID_MAX).nullable().optional(),writersRoomWorkId: z.string().trim().max(seriesSvc.WRITERS_ROOM_WORK_ID_MAX).nullable().optional(),characters: z.array(characterSchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),- settings: z.array(bibleEntrySchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),- objects: z.array(bibleEntrySchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),+ settings: z.array(settingSchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),+ objects: z.array(objectSchema).max(seriesSvc.BIBLE_ENTRIES_PER_SERIES_MAX).optional(),styleNotes: z.string().trim().max(seriesSvc.STYLE_NOTES_MAX).optional(),targetFormat: z.enum(seriesSvc.TARGET_FORMATS).optional(),issueCountTarget: z.number().int().min(0).max(seriesSvc.ISSUE_COUNT_TARGET_MAX).optional(),