@soulcraft/brainy 3.20.2 → 3.20.4

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/bin/brainy-interactive.js +2 -2
  3. package/dist/brainy.d.ts +1 -1
  4. package/dist/mcp/brainyMCPAdapter.d.ts +1 -1
  5. package/dist/mcp/brainyMCPService.d.ts +1 -1
  6. package/dist/neural/embeddedPatterns.d.ts +1 -1
  7. package/dist/neural/embeddedPatterns.js +1 -1
  8. package/dist/shared/default-augmentations.d.ts +1 -1
  9. package/dist/storage/adapters/fileSystemStorage.js +30 -17
  10. package/dist/types/{brainyDataInterface.js → brainyInterface.js} +1 -1
  11. package/package.json +1 -1
  12. package/dist/augmentationFactory.d.ts +0 -86
  13. package/dist/augmentationFactory.js +0 -342
  14. package/dist/augmentationRegistry.d.ts +0 -38
  15. package/dist/augmentationRegistry.js +0 -54
  16. package/dist/augmentationRegistryLoader.d.ts +0 -146
  17. package/dist/augmentationRegistryLoader.js +0 -213
  18. package/dist/augmentations/KnowledgeAugmentation.d.ts +0 -40
  19. package/dist/augmentations/KnowledgeAugmentation.js +0 -251
  20. package/dist/augmentations/intelligentVerbScoring.d.ts +0 -158
  21. package/dist/augmentations/intelligentVerbScoring.js +0 -377
  22. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +0 -168
  23. package/dist/augmentations/marketplace/AugmentationMarketplace.js +0 -329
  24. package/dist/augmentations/marketplace/cli.d.ts +0 -47
  25. package/dist/augmentations/marketplace/cli.js +0 -265
  26. package/dist/augmentations/memoryAugmentations.d.ts +0 -72
  27. package/dist/augmentations/memoryAugmentations.js +0 -280
  28. package/dist/augmentations/serverSearchAugmentations.d.ts +0 -190
  29. package/dist/augmentations/serverSearchAugmentations.js +0 -586
  30. package/dist/brainy-unified.d.ts +0 -106
  31. package/dist/brainy-unified.js +0 -327
  32. package/dist/brainyData.d.ts +0 -1832
  33. package/dist/brainyData.js +0 -6443
  34. package/dist/brainyDataV3.d.ts +0 -186
  35. package/dist/brainyDataV3.js +0 -337
  36. package/dist/config/distributedPresets-new.d.ts +0 -118
  37. package/dist/config/distributedPresets-new.js +0 -318
  38. package/dist/config/modelPrecisionManager.d.ts +0 -42
  39. package/dist/config/modelPrecisionManager.js +0 -98
  40. package/dist/connectors/interfaces/IConnector.d.ts +0 -143
  41. package/dist/connectors/interfaces/IConnector.js +0 -8
  42. package/dist/demo.d.ts +0 -106
  43. package/dist/demo.js +0 -201
  44. package/dist/embeddings/SingletonModelManager.d.ts +0 -95
  45. package/dist/embeddings/SingletonModelManager.js +0 -220
  46. package/dist/embeddings/lightweight-embedder.d.ts +0 -22
  47. package/dist/embeddings/lightweight-embedder.js +0 -128
  48. package/dist/embeddings/model-manager.d.ts +0 -39
  49. package/dist/embeddings/model-manager.js +0 -245
  50. package/dist/embeddings/universal-memory-manager.d.ts +0 -38
  51. package/dist/embeddings/universal-memory-manager.js +0 -166
  52. package/dist/embeddings/worker-embedding.d.ts +0 -7
  53. package/dist/embeddings/worker-embedding.js +0 -73
  54. package/dist/embeddings/worker-manager.d.ts +0 -28
  55. package/dist/embeddings/worker-manager.js +0 -162
  56. package/dist/examples/basicUsage.d.ts +0 -4
  57. package/dist/examples/basicUsage.js +0 -121
  58. package/dist/indices/fieldIndex.d.ts +0 -76
  59. package/dist/indices/fieldIndex.js +0 -357
  60. package/dist/mcp/brainyMCPBroadcast.d.ts +0 -82
  61. package/dist/mcp/brainyMCPBroadcast.js +0 -303
  62. package/dist/mcp/brainyMCPClient.d.ts +0 -92
  63. package/dist/mcp/brainyMCPClient.js +0 -258
  64. package/dist/scripts/precomputePatternEmbeddings.d.ts +0 -19
  65. package/dist/scripts/precomputePatternEmbeddings.js +0 -100
  66. package/dist/utils/cacheAutoConfig.d.ts +0 -63
  67. package/dist/utils/cacheAutoConfig.js +0 -261
  68. package/dist/utils/hybridModelManager.d.ts +0 -64
  69. package/dist/utils/hybridModelManager.js +0 -95
  70. package/dist/utils/statistics.d.ts +0 -28
  71. package/dist/utils/statistics.js +0 -25
  72. package/dist/vfs/ConceptSystem.d.ts +0 -203
  73. package/dist/vfs/ConceptSystem.js +0 -545
  74. package/dist/vfs/EntityManager.d.ts +0 -75
  75. package/dist/vfs/EntityManager.js +0 -216
  76. package/dist/vfs/EventRecorder.d.ts +0 -84
  77. package/dist/vfs/EventRecorder.js +0 -269
  78. package/dist/vfs/GitBridge.d.ts +0 -167
  79. package/dist/vfs/GitBridge.js +0 -537
  80. package/dist/vfs/KnowledgeAugmentation.d.ts +0 -104
  81. package/dist/vfs/KnowledgeAugmentation.js +0 -146
  82. package/dist/vfs/KnowledgeLayer.d.ts +0 -35
  83. package/dist/vfs/KnowledgeLayer.js +0 -443
  84. package/dist/vfs/PersistentEntitySystem.d.ts +0 -165
  85. package/dist/vfs/PersistentEntitySystem.js +0 -503
  86. package/dist/vfs/SemanticVersioning.d.ts +0 -105
  87. package/dist/vfs/SemanticVersioning.js +0 -309
  88. package/dist/vfs/VFSHealthCheck.d.ts +0 -78
  89. package/dist/vfs/VFSHealthCheck.js +0 -299
  90. /package/dist/types/{brainyDataInterface.d.ts → brainyInterface.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -12,6 +12,15 @@ All notable changes to this project will be documented in this file. See [standa
12
12
  - Adds mutex-based concurrency control for mkdir operations
13
13
  - Adds explicit compression tracking for file reads
14
14
 
15
+ ### BREAKING CHANGES (Deprecated API Removal)
16
+
17
+ * **removed BrainyData**: The deprecated `BrainyData` class has been completely removed
18
+ - `BrainyData` was never part of the official Brainy 3.0 API
19
+ - All users should migrate to the `Brainy` class
20
+ - Migration is simple: Replace `new BrainyData()` with `new Brainy()` and add `await brain.init()`
21
+ - See `.strategy/NEURAL_API_RESPONSE.md` for complete migration guide
22
+ - Renamed `brainyDataInterface.ts` to `brainyInterface.ts` for clarity
23
+
15
24
  ### [3.19.1](https://github.com/soulcraftlabs/brainy/compare/v3.19.0...v3.19.1) (2025-09-29)
16
25
 
17
26
  ## [3.19.0](https://github.com/soulcraftlabs/brainy/compare/v3.18.0...v3.19.0) (2025-09-29)
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { program } from 'commander'
10
- import { BrainyData } from '../dist/brainyData.js'
10
+ import { Brainy } from '../dist/index.js'
11
11
  import chalk from 'chalk'
12
12
  import inquirer from 'inquirer'
13
13
  import ora from 'ora'
@@ -61,7 +61,7 @@ async function getBrainy() {
61
61
  if (!brainyInstance) {
62
62
  const spinner = ora('Initializing Brainy...').start()
63
63
  try {
64
- brainyInstance = new BrainyData()
64
+ brainyInstance = new Brainy()
65
65
  await brainyInstance.init()
66
66
  spinner.succeed('Brainy initialized')
67
67
  } catch (error) {
package/dist/brainy.d.ts CHANGED
@@ -12,7 +12,7 @@ import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
12
12
  import { VirtualFileSystem } from './vfs/VirtualFileSystem.js';
13
13
  import { Entity, Relation, Result, AddParams, UpdateParams, RelateParams, FindParams, SimilarParams, GetRelationsParams, AddManyParams, DeleteManyParams, RelateManyParams, BatchResult, BrainyConfig } from './types/brainy.types.js';
14
14
  import { NounType } from './types/graphTypes.js';
15
- import { BrainyInterface } from './types/brainyDataInterface.js';
15
+ import { BrainyInterface } from './types/brainyInterface.js';
16
16
  /**
17
17
  * The main Brainy class - Clean, Beautiful, Powerful
18
18
  * REAL IMPLEMENTATION - No stubs, no mocks
@@ -5,7 +5,7 @@
5
5
  * It wraps a Brainy instance and exposes methods for getting vectors, searching similar items,
6
6
  * and getting relationships.
7
7
  */
8
- import { BrainyInterface } from '../types/brainyDataInterface.js';
8
+ import { BrainyInterface } from '../types/brainyInterface.js';
9
9
  import { MCPResponse, MCPDataAccessRequest } from '../types/mcpTypes.js';
10
10
  export declare class BrainyMCPAdapter {
11
11
  private brainyData;
@@ -6,7 +6,7 @@
6
6
  * MCPAugmentationToolset classes and provides WebSocket and REST server implementations
7
7
  * for external model access.
8
8
  */
9
- import { BrainyInterface } from '../types/brainyDataInterface.js';
9
+ import { BrainyInterface } from '../types/brainyInterface.js';
10
10
  import { MCPRequest, MCPResponse, MCPServiceOptions } from '../types/mcpTypes.js';
11
11
  export declare class BrainyMCPService {
12
12
  private dataAdapter;
@@ -2,7 +2,7 @@
2
2
  * 🧠 BRAINY EMBEDDED PATTERNS
3
3
  *
4
4
  * AUTO-GENERATED - DO NOT EDIT
5
- * Generated: 2025-09-29T17:05:30.153Z
5
+ * Generated: 2025-09-30T23:01:33.167Z
6
6
  * Patterns: 220
7
7
  * Coverage: 94-98% of all queries
8
8
  *
@@ -2,7 +2,7 @@
2
2
  * 🧠 BRAINY EMBEDDED PATTERNS
3
3
  *
4
4
  * AUTO-GENERATED - DO NOT EDIT
5
- * Generated: 2025-09-29T17:05:30.153Z
5
+ * Generated: 2025-09-30T23:01:33.167Z
6
6
  * Patterns: 220
7
7
  * Coverage: 94-98% of all queries
8
8
  *
@@ -4,7 +4,7 @@
4
4
  * 🧠⚛️ Pre-installed augmentations that come with every Brainy installation
5
5
  * These are the core "sensory organs" of the atomic age brain-in-jar system
6
6
  */
7
- import { BrainyInterface } from '../types/brainyDataInterface.js';
7
+ import { BrainyInterface } from '../types/brainyInterface.js';
8
8
  /**
9
9
  * Default augmentations that ship with Brainy
10
10
  * These are automatically registered on startup
@@ -897,26 +897,32 @@ export class FileSystemStorage extends BaseStorage {
897
897
  const limit = options.limit || 100;
898
898
  const startIndex = options.cursor ? parseInt(options.cursor, 10) : 0;
899
899
  try {
900
- // Production-scale optimization: Use persisted count for total instead of scanning
901
- const totalCount = this.totalVerbCount || 0;
900
+ // Get actual verb files first (critical for accuracy)
901
+ const verbFiles = await this.getAllShardedFiles(this.verbsDir);
902
+ verbFiles.sort(); // Consistent ordering for pagination
903
+ // Use actual file count - don't trust cached totalVerbCount
904
+ // This prevents accessing undefined array elements
905
+ const actualFileCount = verbFiles.length;
902
906
  // For large datasets, warn about performance
903
- if (totalCount > 1000000) {
904
- console.warn(`Very large verb dataset detected (${totalCount} verbs). Performance may be degraded. Consider database storage for optimal performance.`);
907
+ if (actualFileCount > 1000000) {
908
+ console.warn(`Very large verb dataset detected (${actualFileCount} verbs). Performance may be degraded. Consider database storage for optimal performance.`);
905
909
  }
906
- // Calculate pagination bounds
907
- const endIndex = Math.min(startIndex + limit, totalCount);
908
- const hasMore = endIndex < totalCount;
909
910
  // For production-scale datasets, use streaming approach
910
- if (totalCount > 50000) {
911
+ if (actualFileCount > 50000) {
911
912
  return await this.getVerbsWithPaginationStreaming(options, startIndex, limit);
912
913
  }
913
- // For smaller datasets, use the current approach (with optimizations)
914
- const verbFiles = await this.getAllShardedFiles(this.verbsDir);
915
- verbFiles.sort(); // This is still acceptable for <50k files
914
+ // Calculate pagination bounds using ACTUAL file count
915
+ const endIndex = Math.min(startIndex + limit, actualFileCount);
916
916
  // Load the requested page of verbs
917
917
  const verbs = [];
918
+ let successfullyLoaded = 0;
918
919
  for (let i = startIndex; i < endIndex; i++) {
919
920
  const file = verbFiles[i];
921
+ // CRITICAL: Null-safety check for undefined array elements
922
+ if (!file) {
923
+ console.warn(`Unexpected undefined file at index ${i}, skipping`);
924
+ continue;
925
+ }
920
926
  const id = file.replace('.json', '');
921
927
  try {
922
928
  // Read the verb data (HNSWVerb stored as edge) - use sharded path
@@ -1003,14 +1009,18 @@ export class FileSystemStorage extends BaseStorage {
1003
1009
  }
1004
1010
  }
1005
1011
  verbs.push(verb);
1012
+ successfullyLoaded++;
1006
1013
  }
1007
1014
  catch (error) {
1008
1015
  console.warn(`Failed to read verb ${id}:`, error);
1009
1016
  }
1010
1017
  }
1018
+ // CRITICAL FIX: hasMore based on actual file count, not cached totalVerbCount
1019
+ // Also verify we successfully loaded items (prevents infinite loops on corrupted storage)
1020
+ const hasMore = (endIndex < actualFileCount) && (successfullyLoaded > 0 || startIndex === 0);
1011
1021
  return {
1012
1022
  items: verbs,
1013
- totalCount,
1023
+ totalCount: actualFileCount, // Return actual count, not cached value
1014
1024
  hasMore,
1015
1025
  nextCursor: hasMore ? String(endIndex) : undefined
1016
1026
  };
@@ -1587,14 +1597,14 @@ export class FileSystemStorage extends BaseStorage {
1587
1597
  */
1588
1598
  async getVerbsWithPaginationStreaming(options, startIndex, limit) {
1589
1599
  const verbs = [];
1590
- const totalCount = this.totalVerbCount || 0;
1591
1600
  let processedCount = 0;
1592
1601
  let skippedCount = 0;
1593
1602
  let resultCount = 0;
1594
1603
  const depth = this.cachedShardingDepth ?? this.getOptimalShardingDepth();
1595
1604
  try {
1596
1605
  // Stream through sharded directories efficiently
1597
- const hasMore = await this.streamShardedFiles(this.verbsDir, depth, async (filename, filePath) => {
1606
+ // hasMore=false means we reached the end of files, hasMore=true means streaming stopped early
1607
+ const streamingHasMore = await this.streamShardedFiles(this.verbsDir, depth, async (filename, filePath) => {
1598
1608
  // Skip files until we reach start index
1599
1609
  if (skippedCount < startIndex) {
1600
1610
  skippedCount++;
@@ -1602,7 +1612,7 @@ export class FileSystemStorage extends BaseStorage {
1602
1612
  }
1603
1613
  // Stop if we have enough results
1604
1614
  if (resultCount >= limit) {
1605
- return false; // stop streaming
1615
+ return false; // stop streaming - more files exist
1606
1616
  }
1607
1617
  try {
1608
1618
  const id = filename.replace('.json', '');
@@ -1666,10 +1676,13 @@ export class FileSystemStorage extends BaseStorage {
1666
1676
  return true; // continue
1667
1677
  }
1668
1678
  });
1669
- const finalHasMore = (startIndex + resultCount) < totalCount;
1679
+ // CRITICAL FIX: Use streaming result for hasMore, not cached totalVerbCount
1680
+ // streamingHasMore=false means we exhausted all files
1681
+ // Also verify we loaded items to prevent infinite loops
1682
+ const finalHasMore = streamingHasMore && (resultCount > 0 || startIndex === 0);
1670
1683
  return {
1671
1684
  items: verbs,
1672
- totalCount,
1685
+ totalCount: this.totalVerbCount || undefined, // Return cached count as hint only
1673
1686
  hasMore: finalHasMore,
1674
1687
  nextCursor: finalHasMore ? String(startIndex + resultCount) : undefined
1675
1688
  };
@@ -7,4 +7,4 @@
7
7
  * NO DEPRECATED METHODS - Only clean, modern API patterns.
8
8
  */
9
9
  export {};
10
- //# sourceMappingURL=brainyDataInterface.js.map
10
+ //# sourceMappingURL=brainyInterface.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "3.20.2",
3
+ "version": "3.20.4",
4
4
  "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.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -1,86 +0,0 @@
1
- /**
2
- * Augmentation Factory
3
- *
4
- * This module provides a simplified factory for creating augmentations with minimal boilerplate.
5
- * It reduces the complexity of creating and using augmentations by providing a fluent API
6
- * and handling common patterns automatically.
7
- */
8
- import { IAugmentation, AugmentationResponse, ISenseAugmentation, IConduitAugmentation, IMemoryAugmentation, IWebSocketSupport, WebSocketConnection } from './types/augmentations.js';
9
- /**
10
- * Options for creating an augmentation
11
- */
12
- export interface AugmentationOptions {
13
- name: string;
14
- description?: string;
15
- enabled?: boolean;
16
- autoRegister?: boolean;
17
- autoInitialize?: boolean;
18
- }
19
- /**
20
- * Factory for creating sense augmentations
21
- */
22
- export declare function createSenseAugmentation(options: AugmentationOptions & {
23
- processRawData?: (rawData: Buffer | string, dataType: string) => Promise<AugmentationResponse<{
24
- nouns: string[];
25
- verbs: string[];
26
- }>> | AugmentationResponse<{
27
- nouns: string[];
28
- verbs: string[];
29
- }>;
30
- listenToFeed?: (feedUrl: string, callback: (data: {
31
- nouns: string[];
32
- verbs: string[];
33
- }) => void) => Promise<void>;
34
- }): ISenseAugmentation;
35
- /**
36
- * Factory for creating conduit augmentations
37
- */
38
- export declare function createConduitAugmentation(options: AugmentationOptions & {
39
- establishConnection?: (targetSystemId: string, config: Record<string, unknown>) => Promise<AugmentationResponse<WebSocketConnection>> | AugmentationResponse<WebSocketConnection>;
40
- readData?: (query: Record<string, unknown>, options?: Record<string, unknown>) => Promise<AugmentationResponse<unknown>> | AugmentationResponse<unknown>;
41
- writeData?: (data: Record<string, unknown>, options?: Record<string, unknown>) => Promise<AugmentationResponse<unknown>> | AugmentationResponse<unknown>;
42
- monitorStream?: (streamId: string, callback: (data: unknown) => void) => Promise<void>;
43
- }): IConduitAugmentation;
44
- /**
45
- * Factory for creating memory augmentations
46
- */
47
- export declare function createMemoryAugmentation(options: AugmentationOptions & {
48
- storeData?: (key: string, data: unknown, options?: Record<string, unknown>) => Promise<AugmentationResponse<boolean>> | AugmentationResponse<boolean>;
49
- retrieveData?: (key: string, options?: Record<string, unknown>) => Promise<AugmentationResponse<unknown>> | AugmentationResponse<unknown>;
50
- updateData?: (key: string, data: unknown, options?: Record<string, unknown>) => Promise<AugmentationResponse<boolean>> | AugmentationResponse<boolean>;
51
- deleteData?: (key: string, options?: Record<string, unknown>) => Promise<AugmentationResponse<boolean>> | AugmentationResponse<boolean>;
52
- listDataKeys?: (pattern?: string, options?: Record<string, unknown>) => Promise<AugmentationResponse<string[]>> | AugmentationResponse<string[]>;
53
- search?: (query: unknown, k?: number, options?: Record<string, unknown>) => Promise<AugmentationResponse<Array<{
54
- id: string;
55
- score: number;
56
- data: unknown;
57
- }>>> | AugmentationResponse<Array<{
58
- id: string;
59
- score: number;
60
- data: unknown;
61
- }>>;
62
- }): IMemoryAugmentation;
63
- /**
64
- * Factory for creating WebSocket-enabled augmentations
65
- * This can be combined with other augmentation factories to create WebSocket-enabled versions
66
- */
67
- export declare function addWebSocketSupport<T extends IAugmentation>(augmentation: T, options: {
68
- connectWebSocket?: (url: string, protocols?: string | string[]) => Promise<WebSocketConnection>;
69
- sendWebSocketMessage?: (connectionId: string, data: unknown) => Promise<void>;
70
- onWebSocketMessage?: (connectionId: string, callback: (data: unknown) => void) => Promise<void>;
71
- offWebSocketMessage?: (connectionId: string, callback: (data: unknown) => void) => Promise<void>;
72
- closeWebSocket?: (connectionId: string, code?: number, reason?: string) => Promise<void>;
73
- }): T & IWebSocketSupport;
74
- /**
75
- * Simplified function to execute an augmentation method with automatic error handling
76
- * This provides a more concise way to execute augmentation methods compared to the full pipeline
77
- */
78
- export declare function executeAugmentation<T, R>(augmentation: IAugmentation, method: string, ...args: any[]): Promise<AugmentationResponse<R>>;
79
- /**
80
- * Dynamically load augmentations from a module at runtime
81
- * This allows for lazy-loading augmentations when needed instead of at build time
82
- */
83
- export declare function loadAugmentationModule(modulePromise: Promise<any>, options?: {
84
- autoRegister?: boolean;
85
- autoInitialize?: boolean;
86
- }): Promise<IAugmentation[]>;
@@ -1,342 +0,0 @@
1
- /**
2
- * Augmentation Factory
3
- *
4
- * This module provides a simplified factory for creating augmentations with minimal boilerplate.
5
- * It reduces the complexity of creating and using augmentations by providing a fluent API
6
- * and handling common patterns automatically.
7
- */
8
- import { registerAugmentation } from './augmentationRegistry.js';
9
- /**
10
- * Base class for all augmentations created with the factory
11
- * Handles common functionality like initialization, shutdown, and status
12
- */
13
- class BaseAugmentation {
14
- constructor(options) {
15
- this.enabled = true;
16
- this.isInitialized = false;
17
- this.name = options.name;
18
- this.description = options.description || `${options.name} augmentation`;
19
- this.enabled = options.enabled !== false;
20
- }
21
- async initialize() {
22
- if (this.isInitialized)
23
- return;
24
- this.isInitialized = true;
25
- }
26
- async shutDown() {
27
- this.isInitialized = false;
28
- }
29
- async getStatus() {
30
- return this.isInitialized ? 'active' : 'inactive';
31
- }
32
- async ensureInitialized() {
33
- if (!this.isInitialized) {
34
- await this.initialize();
35
- }
36
- }
37
- }
38
- /**
39
- * Factory for creating sense augmentations
40
- */
41
- export function createSenseAugmentation(options) {
42
- const augmentation = new BaseAugmentation(options);
43
- // Implement the sense augmentation methods
44
- augmentation.processRawData = async (rawData, dataType) => {
45
- await augmentation.ensureInitialized();
46
- if (options.processRawData) {
47
- const result = options.processRawData(rawData, dataType);
48
- return result instanceof Promise ? await result : result;
49
- }
50
- return {
51
- success: false,
52
- data: { nouns: [], verbs: [] },
53
- error: 'processRawData not implemented'
54
- };
55
- };
56
- augmentation.listenToFeed = async (feedUrl, callback) => {
57
- await augmentation.ensureInitialized();
58
- if (options.listenToFeed) {
59
- return options.listenToFeed(feedUrl, callback);
60
- }
61
- throw new Error('listenToFeed not implemented');
62
- };
63
- // Auto-register if requested
64
- if (options.autoRegister) {
65
- registerAugmentation(augmentation);
66
- // Auto-initialize if requested
67
- if (options.autoInitialize) {
68
- augmentation.initialize().catch((error) => {
69
- console.error(`Failed to initialize augmentation ${augmentation.name}:`, error);
70
- });
71
- }
72
- }
73
- return augmentation;
74
- }
75
- /**
76
- * Factory for creating conduit augmentations
77
- */
78
- export function createConduitAugmentation(options) {
79
- const augmentation = new BaseAugmentation(options);
80
- // Implement the conduit augmentation methods
81
- augmentation.establishConnection = async (targetSystemId, config) => {
82
- await augmentation.ensureInitialized();
83
- if (options.establishConnection) {
84
- const result = options.establishConnection(targetSystemId, config);
85
- return result instanceof Promise ? await result : result;
86
- }
87
- return {
88
- success: false,
89
- data: null,
90
- error: 'establishConnection not implemented'
91
- };
92
- };
93
- augmentation.readData = async (query, opts) => {
94
- await augmentation.ensureInitialized();
95
- if (options.readData) {
96
- const result = options.readData(query, opts);
97
- return result instanceof Promise ? await result : result;
98
- }
99
- return {
100
- success: false,
101
- data: null,
102
- error: 'readData not implemented'
103
- };
104
- };
105
- augmentation.writeData = async (data, opts) => {
106
- await augmentation.ensureInitialized();
107
- if (options.writeData) {
108
- const result = options.writeData(data, opts);
109
- return result instanceof Promise ? await result : result;
110
- }
111
- return {
112
- success: false,
113
- data: null,
114
- error: 'writeData not implemented'
115
- };
116
- };
117
- augmentation.monitorStream = async (streamId, callback) => {
118
- await augmentation.ensureInitialized();
119
- if (options.monitorStream) {
120
- return options.monitorStream(streamId, callback);
121
- }
122
- throw new Error('monitorStream not implemented');
123
- };
124
- // Auto-register if requested
125
- if (options.autoRegister) {
126
- registerAugmentation(augmentation);
127
- // Auto-initialize if requested
128
- if (options.autoInitialize) {
129
- augmentation.initialize().catch((error) => {
130
- console.error(`Failed to initialize augmentation ${augmentation.name}:`, error);
131
- });
132
- }
133
- }
134
- return augmentation;
135
- }
136
- /**
137
- * Factory for creating memory augmentations
138
- */
139
- export function createMemoryAugmentation(options) {
140
- const augmentation = new BaseAugmentation(options);
141
- // Implement the memory augmentation methods
142
- augmentation.storeData = async (key, data, opts) => {
143
- await augmentation.ensureInitialized();
144
- if (options.storeData) {
145
- const result = options.storeData(key, data, opts);
146
- return result instanceof Promise ? await result : result;
147
- }
148
- return {
149
- success: false,
150
- data: false,
151
- error: 'storeData not implemented'
152
- };
153
- };
154
- augmentation.retrieveData = async (key, opts) => {
155
- await augmentation.ensureInitialized();
156
- if (options.retrieveData) {
157
- const result = options.retrieveData(key, opts);
158
- return result instanceof Promise ? await result : result;
159
- }
160
- return {
161
- success: false,
162
- data: null,
163
- error: 'retrieveData not implemented'
164
- };
165
- };
166
- augmentation.updateData = async (key, data, opts) => {
167
- await augmentation.ensureInitialized();
168
- if (options.updateData) {
169
- const result = options.updateData(key, data, opts);
170
- return result instanceof Promise ? await result : result;
171
- }
172
- return {
173
- success: false,
174
- data: false,
175
- error: 'updateData not implemented'
176
- };
177
- };
178
- augmentation.deleteData = async (key, opts) => {
179
- await augmentation.ensureInitialized();
180
- if (options.deleteData) {
181
- const result = options.deleteData(key, opts);
182
- return result instanceof Promise ? await result : result;
183
- }
184
- return {
185
- success: false,
186
- data: false,
187
- error: 'deleteData not implemented'
188
- };
189
- };
190
- augmentation.listDataKeys = async (pattern, opts) => {
191
- await augmentation.ensureInitialized();
192
- if (options.listDataKeys) {
193
- const result = options.listDataKeys(pattern, opts);
194
- return result instanceof Promise ? await result : result;
195
- }
196
- return {
197
- success: false,
198
- data: [],
199
- error: 'listDataKeys not implemented'
200
- };
201
- };
202
- augmentation.search = async (query, k, opts) => {
203
- await augmentation.ensureInitialized();
204
- if (options.search) {
205
- const result = options.search(query, k, opts);
206
- return result instanceof Promise ? await result : result;
207
- }
208
- return {
209
- success: false,
210
- data: [],
211
- error: 'search not implemented'
212
- };
213
- };
214
- // Auto-register if requested
215
- if (options.autoRegister) {
216
- registerAugmentation(augmentation);
217
- // Auto-initialize if requested
218
- if (options.autoInitialize) {
219
- augmentation.initialize().catch((error) => {
220
- console.error(`Failed to initialize augmentation ${augmentation.name}:`, error);
221
- });
222
- }
223
- }
224
- return augmentation;
225
- }
226
- /**
227
- * Factory for creating WebSocket-enabled augmentations
228
- * This can be combined with other augmentation factories to create WebSocket-enabled versions
229
- */
230
- export function addWebSocketSupport(augmentation, options) {
231
- const wsAugmentation = augmentation;
232
- // Add WebSocket methods
233
- wsAugmentation.connectWebSocket = async (url, protocols) => {
234
- await augmentation.ensureInitialized?.();
235
- if (options.connectWebSocket) {
236
- return options.connectWebSocket(url, protocols);
237
- }
238
- throw new Error('connectWebSocket not implemented');
239
- };
240
- wsAugmentation.sendWebSocketMessage = async (connectionId, data) => {
241
- await augmentation.ensureInitialized?.();
242
- if (options.sendWebSocketMessage) {
243
- return options.sendWebSocketMessage(connectionId, data);
244
- }
245
- throw new Error('sendWebSocketMessage not implemented');
246
- };
247
- wsAugmentation.onWebSocketMessage = async (connectionId, callback) => {
248
- await augmentation.ensureInitialized?.();
249
- if (options.onWebSocketMessage) {
250
- return options.onWebSocketMessage(connectionId, callback);
251
- }
252
- throw new Error('onWebSocketMessage not implemented');
253
- };
254
- wsAugmentation.offWebSocketMessage = async (connectionId, callback) => {
255
- await augmentation.ensureInitialized?.();
256
- if (options.offWebSocketMessage) {
257
- return options.offWebSocketMessage(connectionId, callback);
258
- }
259
- throw new Error('offWebSocketMessage not implemented');
260
- };
261
- wsAugmentation.closeWebSocket = async (connectionId, code, reason) => {
262
- await augmentation.ensureInitialized?.();
263
- if (options.closeWebSocket) {
264
- return options.closeWebSocket(connectionId, code, reason);
265
- }
266
- throw new Error('closeWebSocket not implemented');
267
- };
268
- return wsAugmentation;
269
- }
270
- /**
271
- * Simplified function to execute an augmentation method with automatic error handling
272
- * This provides a more concise way to execute augmentation methods compared to the full pipeline
273
- */
274
- export async function executeAugmentation(augmentation, method, ...args) {
275
- try {
276
- if (!augmentation.enabled) {
277
- return {
278
- success: false,
279
- data: null,
280
- error: `Augmentation ${augmentation.name} is disabled`
281
- };
282
- }
283
- if (typeof augmentation[method] !== 'function') {
284
- return {
285
- success: false,
286
- data: null,
287
- error: `Method ${method} not found on augmentation ${augmentation.name}`
288
- };
289
- }
290
- const result = await augmentation[method](...args);
291
- return result;
292
- }
293
- catch (error) {
294
- console.error(`Error executing ${method} on ${augmentation.name}:`, error);
295
- return {
296
- success: false,
297
- data: null,
298
- error: error instanceof Error ? error.message : String(error)
299
- };
300
- }
301
- }
302
- /**
303
- * Dynamically load augmentations from a module at runtime
304
- * This allows for lazy-loading augmentations when needed instead of at build time
305
- */
306
- export async function loadAugmentationModule(modulePromise, options = {}) {
307
- try {
308
- const module = await modulePromise;
309
- const augmentations = [];
310
- // Extract augmentations from the module
311
- for (const key in module) {
312
- const exported = module[key];
313
- // Skip non-objects and null
314
- if (!exported || typeof exported !== 'object') {
315
- continue;
316
- }
317
- // Check if it's an augmentation
318
- if (typeof exported.name === 'string' &&
319
- typeof exported.initialize === 'function' &&
320
- typeof exported.shutDown === 'function' &&
321
- typeof exported.getStatus === 'function') {
322
- augmentations.push(exported);
323
- // Auto-register if requested
324
- if (options.autoRegister) {
325
- registerAugmentation(exported);
326
- // Auto-initialize if requested
327
- if (options.autoInitialize) {
328
- exported.initialize().catch((error) => {
329
- console.error(`Failed to initialize augmentation ${exported.name}:`, error);
330
- });
331
- }
332
- }
333
- }
334
- }
335
- return augmentations;
336
- }
337
- catch (error) {
338
- console.error('Error loading augmentation module:', error);
339
- return [];
340
- }
341
- }
342
- //# sourceMappingURL=augmentationFactory.js.map