@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.
@@ -1 +1 @@
1
- {"version":3,"file":"fileSystemStorage.d.ts","sourceRoot":"","sources":["../../src/storage/fileSystemStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAqBrE;;GAEG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACtD,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,aAAa,CAAQ;gBAEjB,aAAa,CAAC,EAAE,MAAM;IAelC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA2DlC;;OAEG;IACU,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BpD;;OAEG;IACU,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAoG1D;;;;OAIG;IACU,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IA2DtE;;OAEG;IACU,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAkC/C;;OAEG;YACW,gBAAgB;IAsB9B;;OAEG;IACU,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OA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
3
- embed(data: string[]): any;
4
- dispose(): void;
1
+ /**
2
+ * Type definitions for TensorFlow.js compatibility
3
+ * This file exports type definitions for TensorFlow.js utilities
4
+ */
5
+ export interface TensorFlowUtilObject {
6
+ isFloat32Array: (arr: unknown) => boolean;
7
+ isTypedArray: (arr: unknown) => boolean;
8
+ [key: string]: unknown;
9
+ }
10
+ export interface PlatformNodeObject {
11
+ isFloat32Array?: (arr: unknown) => boolean;
12
+ isTypedArray?: (arr: unknown) => boolean;
13
+ [key: string]: unknown;
14
+ }
15
+ export interface TensorFlowObject {
16
+ util?: TensorFlowUtilObject;
17
+ [key: string]: unknown;
18
+ }
19
+ declare global {
20
+ interface Window {
21
+ importTensorFlow?: () => Promise<any>;
22
+ }
23
+ interface WorkerGlobalScope {
24
+ importTensorFlow?: () => Promise<any>;
25
+ }
5
26
  }
6
- export declare const tensorflowModelsLoaded = true;
7
27
  //# sourceMappingURL=tensorflowTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tensorflowTypes.d.ts","sourceRoot":"","sources":["../../src/types/tensorflowTypes.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAC3B,OAAO,IAAI,IAAI,CAAC;CACjB;AAGD,eAAO,MAAM,sBAAsB,OAAO,CAAC"}
1
+ {"version":3,"file":"tensorflowTypes.d.ts","sourceRoot":"","sources":["../../src/types/tensorflowTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;IACzC,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;IACvC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAGD,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;IAC1C,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAGD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,oBAAoB,CAAA;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;KACtC;IAED,UAAU,iBAAiB;QACzB,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;KACtC;CACF"}
package/dist/unified.js CHANGED
@@ -2898,6 +2898,19 @@ let UniversalSentenceEncoder$1 = class UniversalSentenceEncoder {
2898
2898
  this.use = null;
2899
2899
  this.backend = 'cpu'; // Default to CPU
2900
2900
  }
2901
+ /**
2902
+ * Add polyfills and patches for TensorFlow.js compatibility
2903
+ * This addresses issues with TensorFlow.js in Node.js environments
2904
+ */
2905
+ addNodeCompatibilityPolyfills() {
2906
+ // Only apply in Node.js environment
2907
+ if (typeof process === 'undefined' ||
2908
+ !process.versions ||
2909
+ !process.versions.node) {
2910
+ return;
2911
+ }
2912
+ // No compatibility patches needed - TensorFlow.js now works correctly with Node.js 24+
2913
+ }
2901
2914
  /**
2902
2915
  * Initialize the embedding model
2903
2916
  */
@@ -2914,6 +2927,8 @@ let UniversalSentenceEncoder$1 = class UniversalSentenceEncoder {
2914
2927
  }
2915
2928
  originalWarn(message, ...optionalParams);
2916
2929
  };
2930
+ // Add polyfills for TensorFlow.js compatibility
2931
+ this.addNodeCompatibilityPolyfills();
2917
2932
  // TensorFlow.js will use its default EPSILON value
2918
2933
  // Dynamically import TensorFlow.js core module and backends
2919
2934
  // Use type assertions to tell TypeScript these modules exist
@@ -9310,9 +9325,42 @@ class BrainyData {
9310
9325
  }
9311
9326
  }
9312
9327
 
9313
- // We'll dynamically import Node.js built-in modules
9328
+ // Import Node.js built-in modules
9329
+ // Using require for compatibility with Node.js
9314
9330
  let fs;
9315
9331
  let path;
9332
+ // Initialize these modules immediately if in Node.js environment
9333
+ if (typeof process !== 'undefined' &&
9334
+ process.versions &&
9335
+ process.versions.node) {
9336
+ try {
9337
+ // Use require for Node.js built-in modules
9338
+ fs = require('fs');
9339
+ path = require('path');
9340
+ // Verify that path has the required methods
9341
+ if (!path || typeof path.resolve !== 'function') {
9342
+ throw new Error('path module is missing required methods');
9343
+ }
9344
+ }
9345
+ catch (e) {
9346
+ console.warn('Failed to load Node.js modules with require:', e);
9347
+ // Try using dynamic import as a fallback
9348
+ try {
9349
+ // Use a synchronous approach to ensure modules are loaded before continuing
9350
+ const pathModule = require('node:path');
9351
+ const fsModule = require('node:fs');
9352
+ path = pathModule;
9353
+ fs = fsModule;
9354
+ // Verify that path has the required methods
9355
+ if (!path || typeof path.resolve !== 'function') {
9356
+ throw new Error('path module from node:path is missing required methods');
9357
+ }
9358
+ }
9359
+ catch (nodeImportError) {
9360
+ console.warn('Failed to load Node.js modules with node: prefix:', nodeImportError);
9361
+ }
9362
+ }
9363
+ }
9316
9364
  // Constants for directory and file names
9317
9365
  const ROOT_DIR = 'brainy-data';
9318
9366
  const NOUNS_DIR = 'nouns';
@@ -9353,32 +9401,91 @@ class FileSystemStorage {
9353
9401
  return;
9354
9402
  }
9355
9403
  try {
9356
- // Dynamically import Node.js built-in modules
9357
- try {
9358
- // Import the modules
9359
- const fsModule = await Promise.resolve().then(function () { return _fsShim$1; });
9360
- const pathModule = await Promise.resolve().then(function () { return _pathShim$1; });
9361
- // Assign to our module-level variables
9362
- fs = fsModule.default || fsModule;
9363
- path = pathModule.default || pathModule;
9364
- // Now set up the directory paths
9365
- const rootDir = this.rootDir || process.cwd();
9366
- this.rootDir = path.resolve(rootDir, ROOT_DIR);
9367
- this.nounsDir = path.join(this.rootDir, NOUNS_DIR);
9368
- this.verbsDir = path.join(this.rootDir, VERBS_DIR);
9369
- this.metadataDir = path.join(this.rootDir, METADATA_DIR);
9370
- // Set up noun type directory paths
9371
- this.personDir = path.join(this.nounsDir, PERSON_DIR);
9372
- this.placeDir = path.join(this.nounsDir, PLACE_DIR);
9373
- this.thingDir = path.join(this.nounsDir, THING_DIR);
9374
- this.eventDir = path.join(this.nounsDir, EVENT_DIR);
9375
- this.conceptDir = path.join(this.nounsDir, CONCEPT_DIR);
9376
- this.contentDir = path.join(this.nounsDir, CONTENT_DIR);
9377
- this.defaultDir = path.join(this.nounsDir, DEFAULT_DIR);
9378
- }
9379
- catch (importError) {
9380
- throw new Error(`Failed to import Node.js modules: ${importError}. This adapter requires a Node.js environment.`);
9404
+ // Check if fs and path modules are available and have required methods
9405
+ if (!fs || !path || typeof path.resolve !== 'function') {
9406
+ console.log('Node.js modules not properly loaded, attempting to load them now');
9407
+ // Try multiple approaches to load the modules
9408
+ const loadAttempts = [
9409
+ // Attempt 1: Use require
9410
+ async () => {
9411
+ console.log('Attempting to load Node.js modules with require()');
9412
+ const fsModule = require('fs');
9413
+ const pathModule = require('path');
9414
+ if (!pathModule || typeof pathModule.resolve !== 'function') {
9415
+ throw new Error('path.resolve is not a function after require()');
9416
+ }
9417
+ return { fs: fsModule, path: pathModule };
9418
+ },
9419
+ // Attempt 2: Use require with node: prefix
9420
+ async () => {
9421
+ console.log('Attempting to load Node.js modules with require("node:...")');
9422
+ const fsModule = require('node:fs');
9423
+ const pathModule = require('node:path');
9424
+ if (!pathModule || typeof pathModule.resolve !== 'function') {
9425
+ throw new Error('path.resolve is not a function after require("node:path")');
9426
+ }
9427
+ return { fs: fsModule, path: pathModule };
9428
+ },
9429
+ // Attempt 3: Use dynamic import
9430
+ async () => {
9431
+ console.log('Attempting to load Node.js modules with dynamic import');
9432
+ const fsModule = await Promise.resolve().then(function () { return _fsShim$1; });
9433
+ const pathModule = await Promise.resolve().then(function () { return _pathShim$1; });
9434
+ const fsResolved = fsModule.default || fsModule;
9435
+ const pathResolved = pathModule.default || pathModule;
9436
+ if (!pathResolved || typeof pathResolved.resolve !== 'function') {
9437
+ throw new Error('path.resolve is not a function after dynamic import');
9438
+ }
9439
+ return { fs: fsResolved, path: pathResolved };
9440
+ },
9441
+ // Attempt 4: Use dynamic import with node: prefix
9442
+ async () => {
9443
+ console.log('Attempting to load Node.js modules with dynamic import("node:...")');
9444
+ const fsModule = await import('node:fs');
9445
+ const pathModule = await import('node:path');
9446
+ const fsResolved = fsModule.default || fsModule;
9447
+ const pathResolved = pathModule.default || pathModule;
9448
+ if (!pathResolved || typeof pathResolved.resolve !== 'function') {
9449
+ throw new Error('path.resolve is not a function after dynamic import("node:path")');
9450
+ }
9451
+ return { fs: fsResolved, path: pathResolved };
9452
+ }
9453
+ ];
9454
+ // Try each loading method until one succeeds
9455
+ let lastError = null;
9456
+ for (const loadAttempt of loadAttempts) {
9457
+ try {
9458
+ const modules = await loadAttempt();
9459
+ fs = modules.fs;
9460
+ path = modules.path;
9461
+ console.log('Successfully loaded Node.js modules');
9462
+ break;
9463
+ }
9464
+ catch (error) {
9465
+ lastError = error;
9466
+ console.warn(`Module loading attempt failed:`, error);
9467
+ // Continue to the next attempt
9468
+ }
9469
+ }
9470
+ // If all attempts failed, throw an error
9471
+ if (!fs || !path || typeof path.resolve !== 'function') {
9472
+ throw new Error(`Failed to import Node.js modules after multiple attempts: ${lastError}. This adapter requires a Node.js environment.`);
9473
+ }
9381
9474
  }
9475
+ // Now set up the directory paths
9476
+ const rootDir = this.rootDir || process.cwd();
9477
+ this.rootDir = path.resolve(rootDir, ROOT_DIR);
9478
+ this.nounsDir = path.join(this.rootDir, NOUNS_DIR);
9479
+ this.verbsDir = path.join(this.rootDir, VERBS_DIR);
9480
+ this.metadataDir = path.join(this.rootDir, METADATA_DIR);
9481
+ // Set up noun type directory paths
9482
+ this.personDir = path.join(this.nounsDir, PERSON_DIR);
9483
+ this.placeDir = path.join(this.nounsDir, PLACE_DIR);
9484
+ this.thingDir = path.join(this.nounsDir, THING_DIR);
9485
+ this.eventDir = path.join(this.nounsDir, EVENT_DIR);
9486
+ this.conceptDir = path.join(this.nounsDir, CONCEPT_DIR);
9487
+ this.contentDir = path.join(this.nounsDir, CONTENT_DIR);
9488
+ this.defaultDir = path.join(this.nounsDir, DEFAULT_DIR);
9382
9489
  // Create directories if they don't exist
9383
9490
  await this.ensureDirectoryExists(this.rootDir);
9384
9491
  await this.ensureDirectoryExists(this.nounsDir);