@soulcraft/brainy 0.9.23 → 0.9.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/brainy.js +133 -26
- package/dist/brainy.min.js +1 -1
- package/dist/storage/fileSystemStorage.d.ts.map +1 -1
- package/dist/types/tensorflowTypes.d.ts +25 -5
- package/dist/types/tensorflowTypes.d.ts.map +1 -1
- package/dist/unified.js +133 -26
- package/dist/unified.min.js +1 -1
- package/dist/utils/embedding.d.ts +5 -0
- package/dist/utils/embedding.d.ts.map +1 -1
- package/dist/utils/tensorflowUtils.d.ts +18 -0
- package/dist/utils/tensorflowUtils.d.ts.map +1 -0
- package/dist/utils/version.d.ts +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
<br/><br/>
|
|
4
4
|
|
|
5
5
|
[](LICENSE)
|
|
6
|
-
[](https://nodejs.org/)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](CONTRIBUTING.md)
|
|
9
|
-
[](https://www.npmjs.com/package/@soulcraft/brainy)
|
|
10
10
|
|
|
11
11
|
[//]: # ([](https://github.com/sodal-project/cartographer))
|
|
12
12
|
|
package/dist/brainy.js
CHANGED
|
@@ -2900,6 +2900,19 @@ let UniversalSentenceEncoder$1 = class UniversalSentenceEncoder {
|
|
|
2900
2900
|
this.use = null;
|
|
2901
2901
|
this.backend = 'cpu'; // Default to CPU
|
|
2902
2902
|
}
|
|
2903
|
+
/**
|
|
2904
|
+
* Add polyfills and patches for TensorFlow.js compatibility
|
|
2905
|
+
* This addresses issues with TensorFlow.js in Node.js environments
|
|
2906
|
+
*/
|
|
2907
|
+
addNodeCompatibilityPolyfills() {
|
|
2908
|
+
// Only apply in Node.js environment
|
|
2909
|
+
if (typeof process === 'undefined' ||
|
|
2910
|
+
!process.versions ||
|
|
2911
|
+
!process.versions.node) {
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
// No compatibility patches needed - TensorFlow.js now works correctly with Node.js 24+
|
|
2915
|
+
}
|
|
2903
2916
|
/**
|
|
2904
2917
|
* Initialize the embedding model
|
|
2905
2918
|
*/
|
|
@@ -2916,6 +2929,8 @@ let UniversalSentenceEncoder$1 = class UniversalSentenceEncoder {
|
|
|
2916
2929
|
}
|
|
2917
2930
|
originalWarn(message, ...optionalParams);
|
|
2918
2931
|
};
|
|
2932
|
+
// Add polyfills for TensorFlow.js compatibility
|
|
2933
|
+
this.addNodeCompatibilityPolyfills();
|
|
2919
2934
|
// TensorFlow.js will use its default EPSILON value
|
|
2920
2935
|
// Dynamically import TensorFlow.js core module and backends
|
|
2921
2936
|
// Use type assertions to tell TypeScript these modules exist
|
|
@@ -9312,9 +9327,42 @@ class BrainyData {
|
|
|
9312
9327
|
}
|
|
9313
9328
|
}
|
|
9314
9329
|
|
|
9315
|
-
//
|
|
9330
|
+
// Import Node.js built-in modules
|
|
9331
|
+
// Using require for compatibility with Node.js
|
|
9316
9332
|
let fs;
|
|
9317
9333
|
let path;
|
|
9334
|
+
// Initialize these modules immediately if in Node.js environment
|
|
9335
|
+
if (typeof process !== 'undefined' &&
|
|
9336
|
+
process.versions &&
|
|
9337
|
+
process.versions.node) {
|
|
9338
|
+
try {
|
|
9339
|
+
// Use require for Node.js built-in modules
|
|
9340
|
+
fs = require('fs');
|
|
9341
|
+
path = require('path');
|
|
9342
|
+
// Verify that path has the required methods
|
|
9343
|
+
if (!path || typeof path.resolve !== 'function') {
|
|
9344
|
+
throw new Error('path module is missing required methods');
|
|
9345
|
+
}
|
|
9346
|
+
}
|
|
9347
|
+
catch (e) {
|
|
9348
|
+
console.warn('Failed to load Node.js modules with require:', e);
|
|
9349
|
+
// Try using dynamic import as a fallback
|
|
9350
|
+
try {
|
|
9351
|
+
// Use a synchronous approach to ensure modules are loaded before continuing
|
|
9352
|
+
const pathModule = require('node:path');
|
|
9353
|
+
const fsModule = require('node:fs');
|
|
9354
|
+
path = pathModule;
|
|
9355
|
+
fs = fsModule;
|
|
9356
|
+
// Verify that path has the required methods
|
|
9357
|
+
if (!path || typeof path.resolve !== 'function') {
|
|
9358
|
+
throw new Error('path module from node:path is missing required methods');
|
|
9359
|
+
}
|
|
9360
|
+
}
|
|
9361
|
+
catch (nodeImportError) {
|
|
9362
|
+
console.warn('Failed to load Node.js modules with node: prefix:', nodeImportError);
|
|
9363
|
+
}
|
|
9364
|
+
}
|
|
9365
|
+
}
|
|
9318
9366
|
// Constants for directory and file names
|
|
9319
9367
|
const ROOT_DIR = 'brainy-data';
|
|
9320
9368
|
const NOUNS_DIR = 'nouns';
|
|
@@ -9355,32 +9403,91 @@ class FileSystemStorage {
|
|
|
9355
9403
|
return;
|
|
9356
9404
|
}
|
|
9357
9405
|
try {
|
|
9358
|
-
//
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
const
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9406
|
+
// Check if fs and path modules are available and have required methods
|
|
9407
|
+
if (!fs || !path || typeof path.resolve !== 'function') {
|
|
9408
|
+
console.log('Node.js modules not properly loaded, attempting to load them now');
|
|
9409
|
+
// Try multiple approaches to load the modules
|
|
9410
|
+
const loadAttempts = [
|
|
9411
|
+
// Attempt 1: Use require
|
|
9412
|
+
async () => {
|
|
9413
|
+
console.log('Attempting to load Node.js modules with require()');
|
|
9414
|
+
const fsModule = require('fs');
|
|
9415
|
+
const pathModule = require('path');
|
|
9416
|
+
if (!pathModule || typeof pathModule.resolve !== 'function') {
|
|
9417
|
+
throw new Error('path.resolve is not a function after require()');
|
|
9418
|
+
}
|
|
9419
|
+
return { fs: fsModule, path: pathModule };
|
|
9420
|
+
},
|
|
9421
|
+
// Attempt 2: Use require with node: prefix
|
|
9422
|
+
async () => {
|
|
9423
|
+
console.log('Attempting to load Node.js modules with require("node:...")');
|
|
9424
|
+
const fsModule = require('node:fs');
|
|
9425
|
+
const pathModule = require('node:path');
|
|
9426
|
+
if (!pathModule || typeof pathModule.resolve !== 'function') {
|
|
9427
|
+
throw new Error('path.resolve is not a function after require("node:path")');
|
|
9428
|
+
}
|
|
9429
|
+
return { fs: fsModule, path: pathModule };
|
|
9430
|
+
},
|
|
9431
|
+
// Attempt 3: Use dynamic import
|
|
9432
|
+
async () => {
|
|
9433
|
+
console.log('Attempting to load Node.js modules with dynamic import');
|
|
9434
|
+
const fsModule = await Promise.resolve().then(function () { return _fsShim$1; });
|
|
9435
|
+
const pathModule = await Promise.resolve().then(function () { return _pathShim$1; });
|
|
9436
|
+
const fsResolved = fsModule.default || fsModule;
|
|
9437
|
+
const pathResolved = pathModule.default || pathModule;
|
|
9438
|
+
if (!pathResolved || typeof pathResolved.resolve !== 'function') {
|
|
9439
|
+
throw new Error('path.resolve is not a function after dynamic import');
|
|
9440
|
+
}
|
|
9441
|
+
return { fs: fsResolved, path: pathResolved };
|
|
9442
|
+
},
|
|
9443
|
+
// Attempt 4: Use dynamic import with node: prefix
|
|
9444
|
+
async () => {
|
|
9445
|
+
console.log('Attempting to load Node.js modules with dynamic import("node:...")');
|
|
9446
|
+
const fsModule = await import('node:fs');
|
|
9447
|
+
const pathModule = await import('node:path');
|
|
9448
|
+
const fsResolved = fsModule.default || fsModule;
|
|
9449
|
+
const pathResolved = pathModule.default || pathModule;
|
|
9450
|
+
if (!pathResolved || typeof pathResolved.resolve !== 'function') {
|
|
9451
|
+
throw new Error('path.resolve is not a function after dynamic import("node:path")');
|
|
9452
|
+
}
|
|
9453
|
+
return { fs: fsResolved, path: pathResolved };
|
|
9454
|
+
}
|
|
9455
|
+
];
|
|
9456
|
+
// Try each loading method until one succeeds
|
|
9457
|
+
let lastError = null;
|
|
9458
|
+
for (const loadAttempt of loadAttempts) {
|
|
9459
|
+
try {
|
|
9460
|
+
const modules = await loadAttempt();
|
|
9461
|
+
fs = modules.fs;
|
|
9462
|
+
path = modules.path;
|
|
9463
|
+
console.log('Successfully loaded Node.js modules');
|
|
9464
|
+
break;
|
|
9465
|
+
}
|
|
9466
|
+
catch (error) {
|
|
9467
|
+
lastError = error;
|
|
9468
|
+
console.warn(`Module loading attempt failed:`, error);
|
|
9469
|
+
// Continue to the next attempt
|
|
9470
|
+
}
|
|
9471
|
+
}
|
|
9472
|
+
// If all attempts failed, throw an error
|
|
9473
|
+
if (!fs || !path || typeof path.resolve !== 'function') {
|
|
9474
|
+
throw new Error(`Failed to import Node.js modules after multiple attempts: ${lastError}. This adapter requires a Node.js environment.`);
|
|
9475
|
+
}
|
|
9383
9476
|
}
|
|
9477
|
+
// Now set up the directory paths
|
|
9478
|
+
const rootDir = this.rootDir || process.cwd();
|
|
9479
|
+
this.rootDir = path.resolve(rootDir, ROOT_DIR);
|
|
9480
|
+
this.nounsDir = path.join(this.rootDir, NOUNS_DIR);
|
|
9481
|
+
this.verbsDir = path.join(this.rootDir, VERBS_DIR);
|
|
9482
|
+
this.metadataDir = path.join(this.rootDir, METADATA_DIR);
|
|
9483
|
+
// Set up noun type directory paths
|
|
9484
|
+
this.personDir = path.join(this.nounsDir, PERSON_DIR);
|
|
9485
|
+
this.placeDir = path.join(this.nounsDir, PLACE_DIR);
|
|
9486
|
+
this.thingDir = path.join(this.nounsDir, THING_DIR);
|
|
9487
|
+
this.eventDir = path.join(this.nounsDir, EVENT_DIR);
|
|
9488
|
+
this.conceptDir = path.join(this.nounsDir, CONCEPT_DIR);
|
|
9489
|
+
this.contentDir = path.join(this.nounsDir, CONTENT_DIR);
|
|
9490
|
+
this.defaultDir = path.join(this.nounsDir, DEFAULT_DIR);
|
|
9384
9491
|
// Create directories if they don't exist
|
|
9385
9492
|
await this.ensureDirectoryExists(this.rootDir);
|
|
9386
9493
|
await this.ensureDirectoryExists(this.nounsDir);
|