{"_id":"@buddhacognitivelab/state-manager","_rev":"2-ffaea77fae06924296f6223ab152dbfa","name":"@buddhacognitivelab/state-manager","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@buddhacognitivelab/state-manager","version":"1.0.0","keywords":["state-management","zustand","react","typescript"],"author":{"name":"Fluid Buddha Team"},"license":"MIT","_id":"@buddhacognitivelab/state-manager@1.0.0","maintainers":[{"name":"buddhacognitivelab","email":"rahul@buddhalab.in"}],"homepage":"https://github.com/your-org/fluid-buddha-design-system#readme","bugs":{"url":"https://github.com/your-org/fluid-buddha-design-system/issues"},"dist":{"shasum":"75a7c0e5e1460f6418aa017b8b70e90c7a8832d0","tarball":"https://registry.npmjs.org/@buddhacognitivelab/state-manager/-/state-manager-1.0.0.tgz","fileCount":7,"integrity":"sha512-AypXNaT4dveqPx3rqTLUaAZh5LITvccbvihDQC615Y5JQsRDeFgYgKfylOMishW4Upr2XjOsIycDHMpfUMbOyA==","signatures":[{"sig":"MEYCIQCpNEcdsoN+K9wmYu0xxNiYSGQ1P3Ei1oWlUqwRa/qgoQIhAOWqpQgCoYZaN5kj2ywKRZMsDXxVSpw6xGHyHhAOYncL","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24778},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.esm.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.js","require":"./dist/index.js"}},"gitHead":"86476da4d171e8c96529d2771fe9dc1571bffdf3","scripts":{"dev":"rollup -c -w","lint":"eslint src --ext .ts,.tsx","test":"jest","build":"rollup -c","clean":"rimraf dist","test:watch":"jest --watch","type-check":"tsc --noEmit"},"_npmUser":{"name":"buddhacognitivelab","actor":{"name":"buddhacognitivelab","type":"user","email":"rahul@buddhalab.in"},"email":"rahul@buddhalab.in"},"repository":{"url":"git+https://github.com/your-org/fluid-buddha-design-system.git","type":"git","directory":"packages/state-manager"},"_npmVersion":"10.9.2","description":"Central state management package for Fluid Buddha Design System","directories":{},"_nodeVersion":"23.7.0","dependencies":{"immer":"^10.0.0","tslib":"^2.8.1","zustand":"^4.5.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.0.0","react":"^19.1.0","rimraf":"^5.0.0","rollup":"^4.0.0","ts-jest":"^29.0.0","react-dom":"^19.1.0","typescript":"^5.0.0","@types/jest":"^29.0.0","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","rollup-plugin-dts":"^6.0.0","jest-environment-jsdom":"^30.0.2","@rollup/plugin-typescript":"^11.0.0","@rollup/plugin-node-resolve":"^15.0.0"},"peerDependencies":{"react":">=18.0.0"},"_npmOperationalInternal":{"tmp":"tmp/state-manager_1.0.0_1751401678059_0.6180948593018283","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@buddhacognitivelab/state-manager","version":"1.0.1","description":"Central state management package for Fluid Buddha Design System","main":"dist/index.js","module":"dist/index.esm.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.esm.js","require":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"rollup -c","dev":"rollup -c -w","test":"jest","test:watch":"jest --watch","lint":"eslint src --ext .ts,.tsx","type-check":"tsc --noEmit","clean":"rimraf dist"},"dependencies":{"immer":"^10.0.0","tslib":"^2.8.1","zustand":"^4.5.0"},"devDependencies":{"@rollup/plugin-node-resolve":"^15.0.0","@rollup/plugin-typescript":"^11.0.0","@types/jest":"^29.0.0","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","jest":"^29.0.0","jest-environment-jsdom":"^30.0.2","react":"^19.1.0","react-dom":"^19.1.0","rimraf":"^5.0.0","rollup":"^4.0.0","rollup-plugin-dts":"^6.0.0","ts-jest":"^29.0.0","typescript":"^5.0.0"},"peerDependencies":{"react":">=18.0.0"},"keywords":["state-management","zustand","react","typescript"],"author":{"name":"Fluid Buddha Team"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/your-org/fluid-buddha-design-system.git","directory":"packages/state-manager"},"_id":"@buddhacognitivelab/state-manager@1.0.1","gitHead":"86476da4d171e8c96529d2771fe9dc1571bffdf3","bugs":{"url":"https://github.com/your-org/fluid-buddha-design-system/issues"},"homepage":"https://github.com/your-org/fluid-buddha-design-system#readme","_nodeVersion":"23.7.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-3oP4m1emDC/amlyJ2WrbldNBhx9R0g8+rk3IrOx7r1BFedZM0FVLsVuSatwmmejpr79iPTdsGxi9Vn7R7pILmQ==","shasum":"d1c2f9a4819dc33af430a74f2d9a78e3ca6adfd5","tarball":"https://registry.npmjs.org/@buddhacognitivelab/state-manager/-/state-manager-1.0.1.tgz","fileCount":7,"unpackedSize":24778,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIB2w2U+yzpE6a7zRjUwfXKH77tvr+9dGjiA9YXe3QWW7AiAe0BNOeGmsYUTglHWPINUhErupB6faFdatpsC6F/86TQ=="}]},"_npmUser":{"name":"buddhacognitivelab","email":"rahul@buddhalab.in","actor":{"name":"buddhacognitivelab","email":"rahul@buddhalab.in","type":"user"}},"directories":{},"maintainers":[{"name":"buddhacognitivelab","email":"rahul@buddhalab.in"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/state-manager_1.0.1_1751436677302_0.6836834458490912"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-01T20:27:57.917Z","modified":"2025-07-02T06:11:17.607Z","1.0.0":"2025-07-01T20:27:58.225Z","1.0.1":"2025-07-02T06:11:17.468Z"},"bugs":{"url":"https://github.com/your-org/fluid-buddha-design-system/issues"},"author":{"name":"Fluid Buddha Team"},"license":"MIT","homepage":"https://github.com/your-org/fluid-buddha-design-system#readme","keywords":["state-management","zustand","react","typescript"],"repository":{"type":"git","url":"git+https://github.com/your-org/fluid-buddha-design-system.git","directory":"packages/state-manager"},"description":"Central state management package for Fluid Buddha Design System","maintainers":[{"name":"buddhacognitivelab","email":"rahul@buddhalab.in"}],"readme":"# @fluid-buddha/state-manager\n\nCentral state management package for the Fluid Buddha Design System. Provides a type-safe, performant, and predictable state management solution using Zustand with Immer for immutable updates.\n\n## Features\n\n- 🏪 **Centralized Store**: Single source of truth for application state\n- 🔄 **Immutable Updates**: Built-in Immer integration for safe state mutations\n- 🎯 **Type Safety**: Full TypeScript support with strict typing\n- 🎨 **Theme Management**: Dynamic theme and skin switching\n- 🌌 **Spatial Layout**: 3D zone management and camera controls\n- 🎤 **Voice Engine**: Voice recognition and synthesis state\n- 🤖 **AI Integration**: AI processing and conversation management\n- 🔧 **DevTools**: Redux DevTools integration for debugging\n- ⚡ **Performance**: Selective subscriptions to prevent unnecessary re-renders\n\n## Installation\n\n```bash\nnpm install @fluid-buddha/state-manager\n# or\nyarn add @fluid-buddha/state-manager\n```\n\n## Quick Start\n\n### Basic Usage\n\n```typescript\nimport { useFluidBuddhaStore } from '@fluid-buddha/state-manager';\n\nfunction MyComponent() {\n  // Subscribe to specific state (prevents unnecessary re-renders)\n  const activeTheme = useFluidBuddhaStore(state => state.activeTheme);\n  const setTheme = useFluidBuddhaStore(state => state.theme.setTheme);\n  \n  return (\n    <div>\n      <p>Current theme: {activeTheme?.name}</p>\n      <button onClick={() => setTheme(newTheme)}>\n        Change Theme\n      </button>\n    </div>\n  );\n}\n```\n\n### Multiple State Subscriptions\n\n```typescript\nfunction VoiceStatus() {\n  const { engineStatus, isListening, isMuted } = useFluidBuddhaStore(state => ({\n    engineStatus: state.engineStatus,\n    isListening: state.isListening,\n    isMuted: state.isMuted\n  }));\n  \n  return (\n    <div>\n      <p>Status: {engineStatus}</p>\n      <p>Listening: {isListening ? 'Yes' : 'No'}</p>\n      <p>Muted: {isMuted ? 'Yes' : 'No'}</p>\n    </div>\n  );\n}\n```\n\n### Actions Only (No Re-renders)\n\n```typescript\nfunction ActionButtons() {\n  // Get actions without subscribing to state changes\n  const actions = useFluidBuddhaStoreActions();\n  \n  return (\n    <div>\n      <button onClick={() => actions.theme.clearTheme()}>\n        Clear Theme\n      </button>\n      <button onClick={() => actions.voice.startListening()}>\n        Start Listening\n      </button>\n    </div>\n  );\n}\n```\n\n## State Structure\n\nThe store is organized into four main slices:\n\n### Theme State\n\n```typescript\ninterface ThemeState {\n  activeTheme: Theme | null;\n  activeSkin: Skin | null;\n}\n\ninterface ThemeActions {\n  setTheme: (theme: Theme) => void;\n  setSkin: (skin: Skin) => void;\n  clearTheme: () => void;\n}\n```\n\n### Spatial State\n\n```typescript\ninterface SpatialState {\n  layout: { zones: ZoneConfig[] } | null;\n  activeZoneId: string | null;\n  camera: {\n    position: [number, number, number];\n    target: [number, number, number];\n  };\n}\n\ninterface SpatialActions {\n  setLayout: (layout: { zones: ZoneConfig[] }) => void;\n  setActiveZone: (zoneId: string) => void;\n  updateCamera: (position: [number, number, number], target: [number, number, number]) => void;\n  createZone: (zone: Omit<ZoneConfig, 'id'>) => string;\n  updateZone: (zoneId: string, updates: Partial<Omit<ZoneConfig, 'id'>>) => void;\n  deleteZone: (zoneId: string) => void;\n  // ... more actions\n}\n```\n\n### Voice State\n\n```typescript\ninterface VoiceState {\n  engineStatus: 'IDLE' | 'INITIALIZING' | 'LISTENING' | 'PROCESSING' | 'SYNTHESIZING' | 'ERROR';\n  isInitialized: boolean;\n  isMuted: boolean;\n  isListening: boolean;\n  vad: VoiceActivityDetection;\n  currentTranscript: {\n    text: string;\n    confidence: number;\n    isFinal: boolean;\n    timestamp: number;\n  };\n  // ... more properties\n}\n\ninterface VoiceActions {\n  initializeEngine: (config?: Partial<VoiceEngineConfig>) => Promise<boolean>;\n  startListening: () => void;\n  stopListening: () => void;\n  toggleMute: () => void;\n  updateTranscript: (text: string, confidence: number, isFinal: boolean) => void;\n  // ... more actions\n}\n```\n\n### AI State\n\n```typescript\ninterface AIState {\n  isProcessing: boolean;\n  lastResponse: string | null;\n  conversationHistory: Array<{\n    id: string;\n    role: 'user' | 'assistant';\n    content: string;\n    timestamp: number;\n  }>;\n  error: string | null;\n}\n\ninterface AIActions {\n  setProcessing: (processing: boolean) => void;\n  setLastResponse: (response: string) => void;\n  addToHistory: (role: 'user' | 'assistant', content: string) => void;\n  clearHistory: () => void;\n  setError: (error: string | null) => void;\n}\n```\n\n## Advanced Usage\n\n### Custom Store Instance\n\n```typescript\nimport { createFluidBuddhaStore } from '@fluid-buddha/state-manager';\n\n// Create a custom store instance\nconst customStore = createFluidBuddhaStore();\n\n// Use with custom hook\nfunction useCustomStore<T>(selector: (state: FluidBuddhaStore) => T): T {\n  return useStore(customStore, selector);\n}\n```\n\n### Direct Store Access (Non-React)\n\n```typescript\nimport { store } from '@fluid-buddha/state-manager';\n\n// Get current state\nconst currentState = store.getState();\n\n// Subscribe to changes\nconst unsubscribe = store.subscribe((state) => {\n  console.log('State changed:', state);\n});\n\n// Update state\nstore.getState().theme.setTheme(newTheme);\n\n// Cleanup\nunsubscribe();\n```\n\n### Immer Utilities\n\n```typescript\nimport { withImmer, createImmerUpdater } from '@fluid-buddha/state-manager';\n\n// Use Immer utilities for complex state updates\nconst updateComplexState = createImmerUpdater((draft, payload) => {\n  draft.someNestedProperty.value = payload.newValue;\n  draft.anotherProperty.push(payload.newItem);\n});\n```\n\n## Performance Considerations\n\n### Selective Subscriptions\n\n```typescript\n// ✅ Good - Only re-renders when activeTheme changes\nconst activeTheme = useFluidBuddhaStore(state => state.activeTheme);\n\n// ❌ Bad - Re-renders on any state change\nconst state = useFluidBuddhaStoreState();\nconst activeTheme = state.activeTheme;\n```\n\n### Memoized Selectors\n\n```typescript\nimport { useMemo } from 'react';\n\nfunction ExpensiveComponent() {\n  const expensiveValue = useFluidBuddhaStore(\n    useMemo(\n      () => (state) => {\n        // Expensive computation\n        return state.zones.filter(zone => zone.isActive).length;\n      },\n      []\n    )\n  );\n  \n  return <div>Active zones: {expensiveValue}</div>;\n}\n```\n\n## Development\n\n### Building\n\n```bash\nnpm run build\n```\n\n### Testing\n\n```bash\nnpm test\nnpm run test:watch\n```\n\n### Type Checking\n\n```bash\nnpm run type-check\n```\n\n### Linting\n\n```bash\nnpm run lint\n```\n\n## Architecture\n\nThe state manager follows a slice-based architecture where each domain (theme, spatial, voice, AI) is managed in its own slice. All slices are combined into a single store with middleware for development tools and immutable updates.\n\n```\n@fluid-buddha/state-manager/\n├── src/\n│   ├── store/\n│   │   ├── createStore.ts    # Main store creation\n│   │   └── types.ts          # Type definitions\n│   ├── slices/\n│   │   ├── themeSlice.ts     # Theme state management\n│   │   ├── spatialSlice.ts   # Spatial layout management\n│   │   ├── voiceSlice.ts     # Voice engine management\n│   │   └── aiSlice.ts        # AI processing management\n│   ├── hooks/\n│   │   └── useFluidBuddhaStore.ts  # React hooks\n│   ├── utils/\n│   │   └── immerUtils.ts     # Immer utilities\n│   └── constants.ts          # Default values\n```\n\n## Dependencies\n\n- **zustand**: Core state management library\n- **immer**: Immutable state updates\n- **react**: Peer dependency for hooks\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\nSee the main project README for contribution guidelines.","readmeFilename":"README.md"}