fix: remove top-level node:path imports to fix browser bundler compatibility
- Convert static imports to dynamic imports with environment checks - Prevents 'Module externalized for browser compatibility' errors - Maintains Node.js functionality while enabling browser usage
This commit is contained in:
parent
0cde950c03
commit
340123b3b6
3 changed files with 18 additions and 13 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@soulcraft/brainy",
|
"name": "@soulcraft/brainy",
|
||||||
"version": "3.8.1",
|
"version": "3.8.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@soulcraft/brainy",
|
"name": "@soulcraft/brainy",
|
||||||
"version": "3.8.1",
|
"version": "3.8.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.540.0",
|
"@aws-sdk/client-s3": "^3.540.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@soulcraft/brainy",
|
"name": "@soulcraft/brainy",
|
||||||
"version": "3.8.1",
|
"version": "3.8.2",
|
||||||
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
|
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@
|
||||||
import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js'
|
import { EmbeddingFunction, EmbeddingModel, Vector } from '../coreTypes.js'
|
||||||
import { executeInThread } from './workerUtils.js'
|
import { executeInThread } from './workerUtils.js'
|
||||||
import { isBrowser } from './environment.js'
|
import { isBrowser } from './environment.js'
|
||||||
import { join } from 'node:path'
|
|
||||||
import { existsSync } from 'node:fs'
|
|
||||||
// @ts-ignore - Transformers.js is now the primary embedding library
|
// @ts-ignore - Transformers.js is now the primary embedding library
|
||||||
import { pipeline, env } from '@huggingface/transformers'
|
import { pipeline, env } from '@huggingface/transformers'
|
||||||
|
|
||||||
|
|
@ -338,8 +336,11 @@ export class TransformerEmbedding implements EmbeddingModel {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// For Q8 models, we need to explicitly specify the model file
|
// For Q8 models, we need to explicitly specify the model file
|
||||||
if (actualType === 'q8') {
|
if (actualType === 'q8' && !isBrowser()) {
|
||||||
// Check if quantized model exists
|
try {
|
||||||
|
// Check if quantized model exists (Node.js only)
|
||||||
|
const { join } = await import('node:path')
|
||||||
|
const { existsSync } = await import('node:fs')
|
||||||
const modelPath = join(cacheDir, this.options.model, 'onnx', 'model_quantized.onnx')
|
const modelPath = join(cacheDir, this.options.model, 'onnx', 'model_quantized.onnx')
|
||||||
if (existsSync(modelPath)) {
|
if (existsSync(modelPath)) {
|
||||||
this.logger('log', '✅ Q8 model found locally')
|
this.logger('log', '✅ Q8 model found locally')
|
||||||
|
|
@ -347,6 +348,10 @@ export class TransformerEmbedding implements EmbeddingModel {
|
||||||
this.logger('warn', '⚠️ Q8 model not found')
|
this.logger('warn', '⚠️ Q8 model not found')
|
||||||
actualType = 'q8' // Always Q8
|
actualType = 'q8' // Always Q8
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Skip model path check in browser or if imports fail
|
||||||
|
this.logger('log', '🌐 Skipping local model check in browser environment')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.extractor = await pipeline('feature-extraction', this.options.model, pipelineOptions)
|
this.extractor = await pipeline('feature-extraction', this.options.model, pipelineOptions)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue