**feat(cli, workers): introduce text encoding patches and worker improvements**
- Added `cli-package/brainy-wrapper.js` to patch global `TextEncoder` and `TextDecoder` for Node.js environments, ensuring compatibility with TensorFlow.js. - Implemented unified text encoding utilities in `cli-package/src/utils/textEncoding.ts` for cross-environment consistency. - Enhanced `src/worker.js` and introduced `src/worker.ts` to improve worker execution with better function serialization and error handling. - Updated `package.json`: - Modified the `build` script to include a patch for `TextEncoder`. - Added `test-all` script for multi-environment testing. - Introduced the Puppeteer dependency for browser testing. - Created a favicon generation script `scripts/create-favicon.js` using a base64-encoded icon. - Added `scripts/test-all-environments.js` to run automated tests across Node.js, browser, and CLI environments. - Enhanced `src/utils/workerUtils.ts` to support improved fallback mechanisms and robust worker pooling. This update improves the project's compatibility across environments, refines worker functionalities, and adds comprehensive testing support for reliability.
This commit is contained in:
parent
9293328e72
commit
da760a34ed
23 changed files with 2319 additions and 229 deletions
29
src/index.ts
29
src/index.ts
|
|
@ -3,6 +3,11 @@
|
|||
* A vector database using HNSW indexing with Origin Private File System storage
|
||||
*/
|
||||
|
||||
// Import unified text encoding utilities first to ensure they're available
|
||||
import { applyTensorFlowPatch } from './utils/textEncoding.js'
|
||||
// Apply the TensorFlow.js platform patch if needed
|
||||
applyTensorFlowPatch()
|
||||
|
||||
// Export main BrainyData class and related types
|
||||
import { BrainyData, BrainyDataConfig } from './brainyData.js'
|
||||
|
||||
|
|
@ -39,6 +44,18 @@ import {
|
|||
cleanupWorkerPools
|
||||
} from './utils/workerUtils.js'
|
||||
|
||||
// Export environment utilities
|
||||
import {
|
||||
isBrowser,
|
||||
isNode,
|
||||
isWebWorker,
|
||||
areWebWorkersAvailable,
|
||||
areWorkerThreadsAvailable,
|
||||
areWorkerThreadsAvailableSync,
|
||||
isThreadingAvailable,
|
||||
isThreadingAvailableAsync
|
||||
} from './utils/environment.js'
|
||||
|
||||
export {
|
||||
UniversalSentenceEncoder,
|
||||
createEmbeddingFunction,
|
||||
|
|
@ -48,7 +65,17 @@ export {
|
|||
|
||||
// Worker utilities
|
||||
executeInThread,
|
||||
cleanupWorkerPools
|
||||
cleanupWorkerPools,
|
||||
|
||||
// Environment utilities
|
||||
isBrowser,
|
||||
isNode,
|
||||
isWebWorker,
|
||||
areWebWorkersAvailable,
|
||||
areWorkerThreadsAvailable,
|
||||
areWorkerThreadsAvailableSync,
|
||||
isThreadingAvailable,
|
||||
isThreadingAvailableAsync
|
||||
}
|
||||
|
||||
// Export storage adapters
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue