import { Application } from 'express'; import { SynthOSConfig } from '../init'; import { ContextSection } from '../builders/types'; import { StorageProvider, FsStorageProvider } from '../storage'; export type RouteInstaller = (config: SynthOSConfig, app: Application) => void; export class Customizer { protected disabled: Set = new Set(); protected extraRoutes: RouteInstaller[] = []; /** Route hints for the LLM prompt (fork developers can add custom hints). */ protected routeHintEntries: { hints: string }[] = []; /** Custom instructions appended to transformPage's instruction block. */ protected customTransformInstructions: string[] = []; /** Custom context sections appended to the builder's additional sections. */ protected customContextSections: ContextSection[] = []; private _storageProvider?: StorageProvider; /** Storage provider for user-mutable data (pages, settings, themes, uploads). * Override in a derived class to swap the storage backend (e.g. Azure Blob). */ get storageProvider(): StorageProvider { if (!this._storageProvider) { this._storageProvider = new FsStorageProvider(); } return this._storageProvider; } // --- Local data folder --- // Override in a derived class to change the local project folder name. /** Name of the local data folder created in the user's project directory. */ get localFolder(): string { return '.synthos'; } // --- Content folder paths --- // Override these in a derived class to point to your fork's folders. // Each getter returns `string[]`. The sentinel value `'default'` is // resolved by `createConfig()` to the built-in SynthOS folder for that // getter. Forks can return additional paths alongside (or instead of) // `'default'` to layer custom folders. /** Folders containing built-in system pages (builder, settings, etc.) */ get requiredPagesFolders(): string[] { return ['default']; } /** Folders containing starter page templates copied on init */ get defaultPagesFolders(): string[] { return ['default']; } /** Folders containing theme CSS/JSON files */ get defaultThemesFolders(): string[] { return ['default']; } /** Folders containing versioned static files (page-v2.js, helpers-v2.js, etc.) */ get staticFilesFolders(): string[] { return ['default']; } /** Folders containing connector JSON definitions */ get serviceConnectorsFolders(): string[] { return ['default']; } /** Folders containing default scripts copied on init */ get defaultScriptsFolders(): string[] { return ['default']; } /** Route path for the "browse all pages/tabs" listing page. * Override in a derived class to change the redirect target for outdated pages. */ get tabsListRoute(): string { return '/pages'; } /** Product name used in LLM prompts and branding strings. * Override in a derived class for white-labeling. */ get productName(): string { return 'SynthOS'; } // --- Feature group control --- // Built-in groups: 'pages', 'api', 'connectors', 'agents', // 'data', 'brainstorm', 'search', 'scripts' disable(...groups: string[]): this { for (const g of groups) this.disabled.add(g); return this; } enable(...groups: string[]): this { for (const g of groups) this.disabled.delete(g); return this; } isEnabled(group: string): boolean { return !this.disabled.has(group); } // --- Custom routes --- addRoutes(...installers: (RouteInstaller | { installer: RouteInstaller; hints: string })[]): this { for (const entry of installers) { if (typeof entry === 'function') { this.extraRoutes.push(entry); } else { this.extraRoutes.push(entry.installer); this.routeHintEntries.push({ hints: entry.hints }); } } return this; } getExtraRoutes(): RouteInstaller[] { return this.extraRoutes; } // --- Route hints --- /** Add route hints that will be shown to the LLM in transformPage. */ addRouteHints(...hints: string[]): this { for (const h of hints) this.routeHintEntries.push({ hints: h }); return this; } /** Get all custom route hints. */ getRouteHints(): string[] { return this.routeHintEntries.map(e => e.hints); } // --- Custom transform instructions --- /** Add custom instructions for the transformPage LLM prompt. */ addTransformInstructions(...instructions: string[]): this { this.customTransformInstructions.push(...instructions); return this; } /** Get custom transform instructions. */ getTransformInstructions(): string[] { return this.customTransformInstructions; } // --- Custom context sections --- /** Add custom context sections for the builder. */ addContextSections(...sections: ContextSection[]): this { this.customContextSections.push(...sections); return this; } /** Get custom context sections. */ getContextSections(): ContextSection[] { return this.customContextSections; } }