import { initializeAllContainers, registerContainers } from '@bytelyst/cosmos'; import type { ContainerConfig } from '@bytelyst/cosmos'; import { config } from './config.js'; const CONTAINER_DEFS: Record = { notes: { partitionKeyPath: '/workspaceId' }, workspaces: { partitionKeyPath: '/userId' }, note_relationships: { partitionKeyPath: '/workspaceId' }, note_tasks: { partitionKeyPath: '/workspaceId' }, note_artifacts: { partitionKeyPath: '/workspaceId' }, note_agent_actions: { partitionKeyPath: '/workspaceId' }, saved_views: { partitionKeyPath: '/userId' }, note_prompts: { partitionKeyPath: '/userId' }, note_prompt_schedules: { partitionKeyPath: '/userId' }, note_prompt_webhooks: { partitionKeyPath: '/userId' }, }; export async function initCosmosIfNeeded(): Promise { registerContainers(CONTAINER_DEFS); const shouldInit = config.NODE_ENV !== 'production' || process.env.COSMOS_AUTO_INIT === 'true'; if (!shouldInit || config.DB_PROVIDER === 'memory') { return; } try { await initializeAllContainers(); process.stdout.write('[notelett-backend] Cosmos containers ensured\n'); } catch (err) { const msg = err instanceof Error ? err.message : String(err); process.stderr.write(`[notelett-backend] Cosmos init failed: ${msg}\n`); } }