feat: add universal adapters for browser compatibility

- Create universal adapters for cross-platform support (browser/Node/serverless)
- Replace Node.js-specific imports with universal implementations
- Add OPFS support for browser persistent storage
- Maintain same BrainyData interface across all environments
- Enable real Brainy usage in browser console UI
- Keep package size optimized (no bloat)

Universal adapters in /src/universal/:
- uuid.ts: Cross-platform UUID generation
- crypto.ts: Browser/Node crypto operations
- fs.ts: OPFS/FileSystem/Memory storage adapter
- path.ts: Universal path operations
- events.ts: EventEmitter compatibility layer

This enables 'write once, run anywhere' for Brainy while maintaining
the exact same API. No breaking changes to existing code.
This commit is contained in:
David Snelling 2025-08-08 15:22:38 -07:00
parent 6e8869ecb7
commit 93804be354
31 changed files with 2120 additions and 2028 deletions

View file

@ -5,7 +5,7 @@ import {
AugmentationResponse,
WebSocketConnection
} from '../types/augmentations.js'
import { v4 as uuidv4 } from 'uuid'
import { v4 as uuidv4 } from '../universal/uuid.js'
/**
* Base class for conduit augmentations that provide data synchronization between Brainy instances

View file

@ -8,8 +8,8 @@
import { ISenseAugmentation, AugmentationResponse } from '../types/augmentations.js'
import { BrainyData } from '../brainyData.js'
import { NounType, VerbType } from '../types/graphTypes.js'
import * as fs from 'fs/promises'
import * as path from 'path'
import * as fs from '../universal/fs.js'
import * as path from '../universal/path.js'
// Cortex Analysis Types
export interface CortexAnalysisResult {

View file

@ -14,7 +14,7 @@ import {
WebSocketConnection
} from '../types/augmentations.js'
import { WebSocketConduitAugmentation } from './conduitAugmentations.js'
import { v4 as uuidv4 } from 'uuid'
import { v4 as uuidv4 } from '../universal/uuid.js'
import { BrainyDataInterface } from '../types/brainyDataInterface.js'
/**