**feat: add browser-compatible build configuration and environment detection**
### 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.
This commit is contained in:
parent
6cedde94b0
commit
8eaf9f67cb
8 changed files with 1125 additions and 46 deletions
29
src/index.ts
29
src/index.ts
|
|
@ -26,20 +26,16 @@ export {
|
|||
|
||||
// Export embedding functionality
|
||||
import {
|
||||
SimpleEmbedding,
|
||||
UniversalSentenceEncoder,
|
||||
createEmbeddingFunction,
|
||||
createTensorFlowEmbeddingFunction,
|
||||
createSimpleEmbeddingFunction,
|
||||
defaultEmbeddingFunction
|
||||
} from './utils/embedding.js'
|
||||
|
||||
export {
|
||||
SimpleEmbedding,
|
||||
UniversalSentenceEncoder,
|
||||
createEmbeddingFunction,
|
||||
createTensorFlowEmbeddingFunction,
|
||||
createSimpleEmbeddingFunction,
|
||||
defaultEmbeddingFunction
|
||||
}
|
||||
|
||||
|
|
@ -141,12 +137,8 @@ import {
|
|||
ServerSearchActivationAugmentation,
|
||||
createServerSearchAugmentations
|
||||
} from './augmentations/serverSearchAugmentations.js'
|
||||
import {
|
||||
LLMCognitionAugmentation,
|
||||
LLMActivationAugmentation,
|
||||
createLLMAugmentations
|
||||
} from './augmentations/llmAugmentations.js'
|
||||
|
||||
// Non-LLM exports
|
||||
export {
|
||||
MemoryStorageAugmentation,
|
||||
FileSystemStorageAugmentation,
|
||||
|
|
@ -157,12 +149,13 @@ export {
|
|||
createConduitAugmentation,
|
||||
ServerSearchConduitAugmentation,
|
||||
ServerSearchActivationAugmentation,
|
||||
createServerSearchAugmentations,
|
||||
LLMCognitionAugmentation,
|
||||
LLMActivationAugmentation,
|
||||
createLLMAugmentations
|
||||
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 {
|
||||
|
|
@ -178,6 +171,15 @@ import type {
|
|||
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,
|
||||
|
|
@ -188,6 +190,7 @@ export type {
|
|||
HNSWNoun,
|
||||
GraphVerb,
|
||||
HNSWConfig,
|
||||
HNSWOptimizedConfig,
|
||||
StorageAdapter
|
||||
}
|
||||
|
||||
|
|
|
|||
21
src/unified.ts
Normal file
21
src/unified.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Unified entry point for Brainy
|
||||
* This file exports everything from index.ts and adds environment detection
|
||||
* to ensure the library works in any environment (Node.js, browser, serverless)
|
||||
*/
|
||||
|
||||
// Environment detection (will be replaced by the build process)
|
||||
const isBrowser = typeof window !== 'undefined'
|
||||
const isNode =
|
||||
typeof process !== 'undefined' && process.versions && process.versions.node
|
||||
const isServerless = !isBrowser && !isNode
|
||||
|
||||
// Export environment information
|
||||
export const environment = {
|
||||
isBrowser,
|
||||
isNode,
|
||||
isServerless
|
||||
}
|
||||
|
||||
// Re-export everything from index.ts
|
||||
export * from './index.js'
|
||||
Loading…
Add table
Add a link
Reference in a new issue