### Changes: - Added `rollup.unified.js` for building a unified bundle with environment detection (Node.js, Browser, Serverless). - Added `rollup_config.js` for browser-specific bundle configurations. - Created `tsconfig.browser.json` for browser builds and `tsconfig.unified.json` for unified builds. - Implemented custom Rollup plugins: - **`fixThisReferences`**: Resolves `this` reference issues in TensorFlow files. - **`nodeModuleShims`**: Provides empty shims for Node.js built-in modules in browser environments. - Updated dependencies in `package-lock.json` to include Rollup plugins and updated `buffer` dependency for polyfills. - Created `src/unified.ts` as the unified library entry point with dynamic environment detection. ### Purpose: - Introduced a unified and browser-compatible build pipeline to ensure `Brainy` can seamlessly operate across multiple environments (Node.js, Browser, Serverless). - Resolved compatibility issues with Node.js modules and specific library builds. - Enhanced flexibility and usability for developers working in diverse runtime environments.
263 lines
5.7 KiB
TypeScript
263 lines
5.7 KiB
TypeScript
/**
|
|
* OPFS BrainyData
|
|
* A vector database using HNSW indexing with Origin Private File System storage
|
|
*/
|
|
|
|
// Export main BrainyData class and related types
|
|
import { BrainyData, BrainyDataConfig } from './brainyData.js'
|
|
|
|
export { BrainyData }
|
|
export type { BrainyDataConfig }
|
|
|
|
// Export distance functions for convenience
|
|
import {
|
|
euclideanDistance,
|
|
cosineDistance,
|
|
manhattanDistance,
|
|
dotProductDistance
|
|
} from './utils/index.js'
|
|
|
|
export {
|
|
euclideanDistance,
|
|
cosineDistance,
|
|
manhattanDistance,
|
|
dotProductDistance
|
|
}
|
|
|
|
// Export embedding functionality
|
|
import {
|
|
UniversalSentenceEncoder,
|
|
createEmbeddingFunction,
|
|
createTensorFlowEmbeddingFunction,
|
|
defaultEmbeddingFunction
|
|
} from './utils/embedding.js'
|
|
|
|
export {
|
|
UniversalSentenceEncoder,
|
|
createEmbeddingFunction,
|
|
createTensorFlowEmbeddingFunction,
|
|
defaultEmbeddingFunction
|
|
}
|
|
|
|
// Export storage adapters
|
|
import {
|
|
OPFSStorage,
|
|
MemoryStorage,
|
|
createStorage
|
|
} from './storage/opfsStorage.js'
|
|
import { FileSystemStorage } from './storage/fileSystemStorage.js'
|
|
import { R2Storage, S3CompatibleStorage } from './storage/s3CompatibleStorage.js'
|
|
|
|
export {
|
|
OPFSStorage,
|
|
MemoryStorage,
|
|
FileSystemStorage,
|
|
R2Storage,
|
|
S3CompatibleStorage,
|
|
createStorage
|
|
}
|
|
|
|
// Export augmentation pipeline
|
|
import {
|
|
AugmentationPipeline,
|
|
augmentationPipeline,
|
|
ExecutionMode,
|
|
PipelineOptions
|
|
} from './augmentationPipeline.js'
|
|
|
|
// Export sequential pipeline
|
|
import {
|
|
SequentialPipeline,
|
|
sequentialPipeline,
|
|
PipelineResult,
|
|
SequentialPipelineOptions
|
|
} from './sequentialPipeline.js'
|
|
|
|
export {
|
|
AugmentationPipeline,
|
|
augmentationPipeline,
|
|
ExecutionMode,
|
|
SequentialPipeline,
|
|
sequentialPipeline
|
|
}
|
|
export type { PipelineOptions, PipelineResult, SequentialPipelineOptions }
|
|
|
|
// Export augmentation registry for build-time loading
|
|
import {
|
|
availableAugmentations,
|
|
registerAugmentation,
|
|
initializeAugmentationPipeline,
|
|
setAugmentationEnabled,
|
|
getAugmentationsByType
|
|
} from './augmentationRegistry.js'
|
|
|
|
export {
|
|
availableAugmentations,
|
|
registerAugmentation,
|
|
initializeAugmentationPipeline,
|
|
setAugmentationEnabled,
|
|
getAugmentationsByType
|
|
}
|
|
|
|
// Export augmentation registry loader for build tools
|
|
import {
|
|
loadAugmentationsFromModules,
|
|
createAugmentationRegistryPlugin,
|
|
createAugmentationRegistryRollupPlugin
|
|
} from './augmentationRegistryLoader.js'
|
|
import type {
|
|
AugmentationRegistryLoaderOptions,
|
|
AugmentationLoadResult
|
|
} from './augmentationRegistryLoader.js'
|
|
|
|
export {
|
|
loadAugmentationsFromModules,
|
|
createAugmentationRegistryPlugin,
|
|
createAugmentationRegistryRollupPlugin
|
|
}
|
|
export type {
|
|
AugmentationRegistryLoaderOptions,
|
|
AugmentationLoadResult
|
|
}
|
|
|
|
// Export augmentation implementations
|
|
import {
|
|
MemoryStorageAugmentation,
|
|
FileSystemStorageAugmentation,
|
|
OPFSStorageAugmentation,
|
|
createMemoryAugmentation
|
|
} from './augmentations/memoryAugmentations.js'
|
|
import {
|
|
WebSocketConduitAugmentation,
|
|
WebRTCConduitAugmentation,
|
|
createConduitAugmentation
|
|
} from './augmentations/conduitAugmentations.js'
|
|
import {
|
|
ServerSearchConduitAugmentation,
|
|
ServerSearchActivationAugmentation,
|
|
createServerSearchAugmentations
|
|
} from './augmentations/serverSearchAugmentations.js'
|
|
|
|
// Non-LLM exports
|
|
export {
|
|
MemoryStorageAugmentation,
|
|
FileSystemStorageAugmentation,
|
|
OPFSStorageAugmentation,
|
|
createMemoryAugmentation,
|
|
WebSocketConduitAugmentation,
|
|
WebRTCConduitAugmentation,
|
|
createConduitAugmentation,
|
|
ServerSearchConduitAugmentation,
|
|
ServerSearchActivationAugmentation,
|
|
createServerSearchAugmentations
|
|
}
|
|
|
|
// LLM augmentations are optional and not imported by default
|
|
// They can be imported directly from their module if needed:
|
|
// import { LLMCognitionAugmentation, LLMActivationAugmentation, createLLMAugmentations } from './augmentations/llmAugmentations.js'
|
|
|
|
|
|
// Export types
|
|
import type {
|
|
Vector,
|
|
VectorDocument,
|
|
SearchResult,
|
|
DistanceFunction,
|
|
EmbeddingFunction,
|
|
EmbeddingModel,
|
|
HNSWNoun,
|
|
GraphVerb,
|
|
HNSWConfig,
|
|
StorageAdapter
|
|
} from './coreTypes.js'
|
|
|
|
// Export HNSW index and optimized version
|
|
import { HNSWIndex } from './hnsw/hnswIndex.js'
|
|
import { HNSWIndexOptimized, HNSWOptimizedConfig } from './hnsw/hnswIndexOptimized.js'
|
|
|
|
export {
|
|
HNSWIndex,
|
|
HNSWIndexOptimized
|
|
}
|
|
|
|
export type {
|
|
Vector,
|
|
VectorDocument,
|
|
SearchResult,
|
|
DistanceFunction,
|
|
EmbeddingFunction,
|
|
EmbeddingModel,
|
|
HNSWNoun,
|
|
GraphVerb,
|
|
HNSWConfig,
|
|
HNSWOptimizedConfig,
|
|
StorageAdapter
|
|
}
|
|
|
|
// Export augmentation types
|
|
import type {
|
|
IAugmentation,
|
|
AugmentationResponse,
|
|
IWebSocketSupport,
|
|
ISenseAugmentation,
|
|
IConduitAugmentation,
|
|
ICognitionAugmentation,
|
|
IMemoryAugmentation,
|
|
IPerceptionAugmentation,
|
|
IDialogAugmentation,
|
|
IActivationAugmentation
|
|
} from './types/augmentations.js'
|
|
import { AugmentationType, BrainyAugmentations } from './types/augmentations.js'
|
|
|
|
export type {
|
|
IAugmentation,
|
|
AugmentationResponse,
|
|
IWebSocketSupport
|
|
}
|
|
export {
|
|
AugmentationType,
|
|
BrainyAugmentations,
|
|
ISenseAugmentation,
|
|
IConduitAugmentation,
|
|
ICognitionAugmentation,
|
|
IMemoryAugmentation,
|
|
IPerceptionAugmentation,
|
|
IDialogAugmentation,
|
|
IActivationAugmentation
|
|
}
|
|
|
|
// Export combined WebSocket augmentation interfaces
|
|
export type {
|
|
IWebSocketCognitionAugmentation,
|
|
IWebSocketSenseAugmentation,
|
|
IWebSocketPerceptionAugmentation,
|
|
IWebSocketActivationAugmentation,
|
|
IWebSocketDialogAugmentation,
|
|
IWebSocketConduitAugmentation,
|
|
IWebSocketMemoryAugmentation
|
|
} from './types/augmentations.js'
|
|
|
|
// Export graph types
|
|
import type {
|
|
GraphNoun,
|
|
EmbeddedGraphVerb,
|
|
Person,
|
|
Place,
|
|
Thing,
|
|
Event,
|
|
Concept,
|
|
Content
|
|
} from './types/graphTypes.js'
|
|
import { NounType, VerbType } from './types/graphTypes.js'
|
|
|
|
export type {
|
|
GraphNoun,
|
|
EmbeddedGraphVerb,
|
|
Person,
|
|
Place,
|
|
Thing,
|
|
Event,
|
|
Concept,
|
|
Content
|
|
}
|
|
export { NounType, VerbType }
|