@soulcraft/brainy 0.41.0 → 0.43.0
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 +605 -194
- package/dist/augmentations/conduitAugmentations.js +1158 -0
- package/dist/augmentations/conduitAugmentations.js.map +1 -0
- package/dist/augmentations/memoryAugmentations.d.ts +2 -0
- package/dist/augmentations/memoryAugmentations.d.ts.map +1 -1
- package/dist/augmentations/memoryAugmentations.js +270 -0
- package/dist/augmentations/memoryAugmentations.js.map +1 -0
- package/dist/augmentations/serverSearchAugmentations.js +531 -0
- package/dist/augmentations/serverSearchAugmentations.js.map +1 -0
- package/dist/browserFramework.d.ts +15 -0
- package/dist/demo.d.ts +106 -0
- package/dist/examples/basicUsage.js +118 -0
- package/dist/examples/basicUsage.js.map +1 -0
- package/dist/hnsw/distributedSearch.js +452 -0
- package/dist/hnsw/distributedSearch.js.map +1 -0
- package/dist/hnsw/hnswIndex.js +602 -0
- package/dist/hnsw/hnswIndex.js.map +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +471 -0
- package/dist/hnsw/hnswIndexOptimized.js.map +1 -0
- package/dist/hnsw/optimizedHNSWIndex.js +313 -0
- package/dist/hnsw/optimizedHNSWIndex.js.map +1 -0
- package/dist/hnsw/partitionedHNSWIndex.js +304 -0
- package/dist/hnsw/partitionedHNSWIndex.js.map +1 -0
- package/dist/hnsw/scaledHNSWSystem.js +559 -0
- package/dist/hnsw/scaledHNSWSystem.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +81 -0
- package/dist/mcp/brainyMCPAdapter.js +142 -0
- package/dist/mcp/brainyMCPAdapter.js.map +1 -0
- package/dist/mcp/brainyMCPService.js +248 -0
- package/dist/mcp/brainyMCPService.js.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcpAugmentationToolset.js +180 -0
- package/dist/mcp/mcpAugmentationToolset.js.map +1 -0
- package/dist/storage/adapters/baseStorageAdapter.js +349 -0
- package/dist/storage/adapters/baseStorageAdapter.js.map +1 -0
- package/dist/storage/adapters/batchS3Operations.js +287 -0
- package/dist/storage/adapters/batchS3Operations.js.map +1 -0
- package/dist/storage/adapters/fileSystemStorage.js +846 -0
- package/dist/storage/adapters/fileSystemStorage.js.map +1 -0
- package/dist/storage/adapters/memoryStorage.js +532 -0
- package/dist/storage/adapters/memoryStorage.js.map +1 -0
- package/dist/storage/adapters/opfsStorage.d.ts.map +1 -1
- package/dist/storage/adapters/opfsStorage.js +1118 -0
- package/dist/storage/adapters/opfsStorage.js.map +1 -0
- package/dist/storage/adapters/optimizedS3Search.js +248 -0
- package/dist/storage/adapters/optimizedS3Search.js.map +1 -0
- package/dist/storage/adapters/s3CompatibleStorage.js +2026 -0
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -0
- package/dist/storage/baseStorage.js +603 -0
- package/dist/storage/baseStorage.js.map +1 -0
- package/dist/storage/cacheManager.js +1306 -0
- package/dist/storage/cacheManager.js.map +1 -0
- package/dist/storage/enhancedCacheManager.js +520 -0
- package/dist/storage/enhancedCacheManager.js.map +1 -0
- package/dist/storage/readOnlyOptimizations.js +425 -0
- package/dist/storage/readOnlyOptimizations.js.map +1 -0
- package/dist/storage/storageFactory.d.ts +0 -1
- package/dist/storage/storageFactory.d.ts.map +1 -1
- package/dist/storage/storageFactory.js +227 -0
- package/dist/storage/storageFactory.js.map +1 -0
- package/dist/types/augmentations.js +16 -0
- package/dist/types/augmentations.js.map +1 -0
- package/dist/types/brainyDataInterface.js +8 -0
- package/dist/types/brainyDataInterface.js.map +1 -0
- package/dist/types/distributedTypes.js +6 -0
- package/dist/types/distributedTypes.js.map +1 -0
- package/dist/types/fileSystemTypes.js +8 -0
- package/dist/types/fileSystemTypes.js.map +1 -0
- package/dist/types/graphTypes.js +247 -0
- package/dist/types/graphTypes.js.map +1 -0
- package/dist/types/mcpTypes.js +22 -0
- package/dist/types/mcpTypes.js.map +1 -0
- package/dist/types/paginationTypes.js +5 -0
- package/dist/types/paginationTypes.js.map +1 -0
- package/dist/types/pipelineTypes.js +7 -0
- package/dist/types/pipelineTypes.js.map +1 -0
- package/dist/types/tensorflowTypes.js +6 -0
- package/dist/types/tensorflowTypes.js.map +1 -0
- package/dist/unified.js +52 -128251
- package/dist/utils/autoConfiguration.js +341 -0
- package/dist/utils/autoConfiguration.js.map +1 -0
- package/dist/utils/cacheAutoConfig.js +261 -0
- package/dist/utils/cacheAutoConfig.js.map +1 -0
- package/dist/utils/crypto.js +45 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/distance.js +239 -0
- package/dist/utils/distance.js.map +1 -0
- package/dist/utils/embedding.d.ts.map +1 -1
- package/dist/utils/embedding.js +702 -0
- package/dist/utils/embedding.js.map +1 -0
- package/dist/utils/environment.js +75 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/fieldNameTracking.js +90 -0
- package/dist/utils/fieldNameTracking.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/jsonProcessing.js +179 -0
- package/dist/utils/jsonProcessing.js.map +1 -0
- package/dist/utils/logger.js +129 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/operationUtils.js +126 -0
- package/dist/utils/operationUtils.js.map +1 -0
- package/dist/utils/robustModelLoader.d.ts +14 -0
- package/dist/utils/robustModelLoader.d.ts.map +1 -1
- package/dist/utils/robustModelLoader.js +537 -0
- package/dist/utils/robustModelLoader.js.map +1 -0
- package/dist/utils/searchCache.js +248 -0
- package/dist/utils/searchCache.js.map +1 -0
- package/dist/utils/statistics.js +25 -0
- package/dist/utils/statistics.js.map +1 -0
- package/dist/utils/statisticsCollector.js +224 -0
- package/dist/utils/statisticsCollector.js.map +1 -0
- package/dist/utils/textEncoding.js +309 -0
- package/dist/utils/textEncoding.js.map +1 -0
- package/dist/utils/typeUtils.js +40 -0
- package/dist/utils/typeUtils.js.map +1 -0
- package/dist/utils/version.d.ts +15 -3
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +24 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/utils/workerUtils.js +458 -0
- package/dist/utils/workerUtils.js.map +1 -0
- package/package.json +23 -18
- package/dist/brainy.js +0 -90220
- package/dist/brainy.min.js +0 -12511
- package/dist/patched-platform-node.d.ts +0 -17
- package/dist/statistics/statisticsManager.d.ts +0 -121
- package/dist/storage/fileSystemStorage.d.ts +0 -73
- package/dist/storage/fileSystemStorage.d.ts.map +0 -1
- package/dist/storage/opfsStorage.d.ts +0 -236
- package/dist/storage/opfsStorage.d.ts.map +0 -1
- package/dist/storage/s3CompatibleStorage.d.ts +0 -157
- package/dist/storage/s3CompatibleStorage.d.ts.map +0 -1
- package/dist/testing/prettyReporter.d.ts +0 -23
- package/dist/testing/prettySummaryReporter.d.ts +0 -22
- package/dist/unified.min.js +0 -16153
- package/dist/utils/environmentDetection.d.ts +0 -47
- package/dist/utils/environmentDetection.d.ts.map +0 -1
- package/dist/utils/tensorflowUtils.d.ts +0 -17
- package/dist/utils/tensorflowUtils.d.ts.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brainy
|
|
3
|
+
* A vector and graph database using HNSW
|
|
4
|
+
*/
|
|
5
|
+
// CRITICAL: The TensorFlow.js environment patch is now centralized in setup.ts
|
|
6
|
+
// We import setup.js below which applies the necessary patches through textEncoding.js
|
|
7
|
+
// This ensures a consistent patching approach and avoids conflicts
|
|
8
|
+
// Import the setup file for its side-effects.
|
|
9
|
+
// This MUST be the very first import to ensure patches are applied
|
|
10
|
+
// before any other module (like TensorFlow.js) is loaded.
|
|
11
|
+
import './setup.js';
|
|
12
|
+
// Export main BrainyData class and related types
|
|
13
|
+
import { BrainyData } from './brainyData.js';
|
|
14
|
+
export { BrainyData };
|
|
15
|
+
// Export distance functions for convenience
|
|
16
|
+
import { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance, getStatistics } from './utils/index.js';
|
|
17
|
+
export { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance, getStatistics };
|
|
18
|
+
// Export embedding functionality
|
|
19
|
+
import { UniversalSentenceEncoder, createEmbeddingFunction, createTensorFlowEmbeddingFunction, createThreadedEmbeddingFunction, defaultEmbeddingFunction } from './utils/embedding.js';
|
|
20
|
+
// Export worker utilities
|
|
21
|
+
import { executeInThread, cleanupWorkerPools } from './utils/workerUtils.js';
|
|
22
|
+
// Export logging utilities
|
|
23
|
+
import { logger, LogLevel, configureLogger, createModuleLogger } from './utils/logger.js';
|
|
24
|
+
// Export environment utilities
|
|
25
|
+
import { isBrowser, isNode, isWebWorker, areWebWorkersAvailable, areWorkerThreadsAvailable, areWorkerThreadsAvailableSync, isThreadingAvailable, isThreadingAvailableAsync } from './utils/environment.js';
|
|
26
|
+
export { UniversalSentenceEncoder, createEmbeddingFunction, createTensorFlowEmbeddingFunction, createThreadedEmbeddingFunction, defaultEmbeddingFunction,
|
|
27
|
+
// Worker utilities
|
|
28
|
+
executeInThread, cleanupWorkerPools,
|
|
29
|
+
// Environment utilities
|
|
30
|
+
isBrowser, isNode, isWebWorker, areWebWorkersAvailable, areWorkerThreadsAvailable, areWorkerThreadsAvailableSync, isThreadingAvailable, isThreadingAvailableAsync,
|
|
31
|
+
// Logging utilities
|
|
32
|
+
logger, LogLevel, configureLogger, createModuleLogger };
|
|
33
|
+
// Export storage adapters
|
|
34
|
+
import { OPFSStorage, MemoryStorage, R2Storage, S3CompatibleStorage, createStorage } from './storage/storageFactory.js';
|
|
35
|
+
export { OPFSStorage, MemoryStorage, R2Storage, S3CompatibleStorage, createStorage };
|
|
36
|
+
// FileSystemStorage is exported separately to avoid browser build issues
|
|
37
|
+
export { FileSystemStorage } from './storage/adapters/fileSystemStorage.js';
|
|
38
|
+
// Export unified pipeline
|
|
39
|
+
import { Pipeline, pipeline, augmentationPipeline, ExecutionMode, executeStreamlined, executeByType, executeSingle, processStaticData, processStreamingData, createPipeline, createStreamingPipeline, StreamlinedExecutionMode } from './pipeline.js';
|
|
40
|
+
// Export sequential pipeline (for backward compatibility)
|
|
41
|
+
import { SequentialPipeline, sequentialPipeline } from './sequentialPipeline.js';
|
|
42
|
+
// Export augmentation factory
|
|
43
|
+
import { createSenseAugmentation, addWebSocketSupport, executeAugmentation, loadAugmentationModule } from './augmentationFactory.js';
|
|
44
|
+
export {
|
|
45
|
+
// Unified pipeline exports
|
|
46
|
+
Pipeline, pipeline, augmentationPipeline, ExecutionMode, SequentialPipeline, sequentialPipeline,
|
|
47
|
+
// Streamlined pipeline exports (now part of unified pipeline)
|
|
48
|
+
executeStreamlined, executeByType, executeSingle, processStaticData, processStreamingData, createPipeline, createStreamingPipeline, StreamlinedExecutionMode,
|
|
49
|
+
// Augmentation factory exports
|
|
50
|
+
createSenseAugmentation, addWebSocketSupport, executeAugmentation, loadAugmentationModule };
|
|
51
|
+
// Export augmentation registry for build-time loading
|
|
52
|
+
import { availableAugmentations, registerAugmentation, initializeAugmentationPipeline, setAugmentationEnabled, getAugmentationsByType } from './augmentationRegistry.js';
|
|
53
|
+
export { availableAugmentations, registerAugmentation, initializeAugmentationPipeline, setAugmentationEnabled, getAugmentationsByType };
|
|
54
|
+
// Export augmentation registry loader for build tools
|
|
55
|
+
import { loadAugmentationsFromModules, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin } from './augmentationRegistryLoader.js';
|
|
56
|
+
export { loadAugmentationsFromModules, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin };
|
|
57
|
+
// Export augmentation implementations
|
|
58
|
+
import { MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentation, createMemoryAugmentation } from './augmentations/memoryAugmentations.js';
|
|
59
|
+
import { WebSocketConduitAugmentation, WebRTCConduitAugmentation, createConduitAugmentation } from './augmentations/conduitAugmentations.js';
|
|
60
|
+
import { ServerSearchConduitAugmentation, ServerSearchActivationAugmentation, createServerSearchAugmentations } from './augmentations/serverSearchAugmentations.js';
|
|
61
|
+
// Non-LLM exports
|
|
62
|
+
export { MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentation, createMemoryAugmentation, WebSocketConduitAugmentation, WebRTCConduitAugmentation, createConduitAugmentation, ServerSearchConduitAugmentation, ServerSearchActivationAugmentation, createServerSearchAugmentations };
|
|
63
|
+
// Export HNSW index and optimized version
|
|
64
|
+
import { HNSWIndex } from './hnsw/hnswIndex.js';
|
|
65
|
+
import { HNSWIndexOptimized } from './hnsw/hnswIndexOptimized.js';
|
|
66
|
+
export { HNSWIndex, HNSWIndexOptimized };
|
|
67
|
+
import { AugmentationType } from './types/augmentations.js';
|
|
68
|
+
export { AugmentationType };
|
|
69
|
+
import { NounType, VerbType } from './types/graphTypes.js';
|
|
70
|
+
// Export type utility functions
|
|
71
|
+
import { getNounTypes, getVerbTypes, getNounTypeMap, getVerbTypeMap } from './utils/typeUtils.js';
|
|
72
|
+
export { NounType, VerbType, getNounTypes, getVerbTypes, getNounTypeMap, getVerbTypeMap };
|
|
73
|
+
// Export MCP (Model Control Protocol) components
|
|
74
|
+
import { BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService } from './mcp/index.js'; // Import from mcp/index.js
|
|
75
|
+
import { MCPRequestType, MCP_VERSION } from './types/mcpTypes.js';
|
|
76
|
+
export {
|
|
77
|
+
// MCP classes
|
|
78
|
+
BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService,
|
|
79
|
+
// MCP types
|
|
80
|
+
MCPRequestType, MCP_VERSION };
|
|
81
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrainyMCPAdapter
|
|
3
|
+
*
|
|
4
|
+
* This class provides an adapter for accessing Brainy data through the Model Control Protocol (MCP).
|
|
5
|
+
* It wraps a BrainyData instance and exposes methods for getting vectors, searching similar items,
|
|
6
|
+
* and getting relationships.
|
|
7
|
+
*/
|
|
8
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
import { MCP_VERSION } from '../types/mcpTypes.js';
|
|
10
|
+
export class BrainyMCPAdapter {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new BrainyMCPAdapter
|
|
13
|
+
* @param brainyData The BrainyData instance to wrap
|
|
14
|
+
*/
|
|
15
|
+
constructor(brainyData) {
|
|
16
|
+
this.brainyData = brainyData;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handles an MCP data access request
|
|
20
|
+
* @param request The MCP request
|
|
21
|
+
* @returns An MCP response
|
|
22
|
+
*/
|
|
23
|
+
async handleRequest(request) {
|
|
24
|
+
try {
|
|
25
|
+
switch (request.operation) {
|
|
26
|
+
case 'get':
|
|
27
|
+
return await this.handleGetRequest(request);
|
|
28
|
+
case 'search':
|
|
29
|
+
return await this.handleSearchRequest(request);
|
|
30
|
+
case 'add':
|
|
31
|
+
return await this.handleAddRequest(request);
|
|
32
|
+
case 'getRelationships':
|
|
33
|
+
return await this.handleGetRelationshipsRequest(request);
|
|
34
|
+
default:
|
|
35
|
+
return this.createErrorResponse(request.requestId, 'UNSUPPORTED_OPERATION', `Operation ${request.operation} is not supported`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return this.createErrorResponse(request.requestId, 'INTERNAL_ERROR', error instanceof Error ? error.message : String(error));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Handles a get request
|
|
44
|
+
* @param request The MCP request
|
|
45
|
+
* @returns An MCP response
|
|
46
|
+
*/
|
|
47
|
+
async handleGetRequest(request) {
|
|
48
|
+
const { id } = request.parameters;
|
|
49
|
+
if (!id) {
|
|
50
|
+
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "id" is required');
|
|
51
|
+
}
|
|
52
|
+
const noun = await this.brainyData.get(id);
|
|
53
|
+
if (!noun) {
|
|
54
|
+
return this.createErrorResponse(request.requestId, 'NOT_FOUND', `No noun found with id ${id}`);
|
|
55
|
+
}
|
|
56
|
+
return this.createSuccessResponse(request.requestId, noun);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Handles a search request
|
|
60
|
+
* @param request The MCP request
|
|
61
|
+
* @returns An MCP response
|
|
62
|
+
*/
|
|
63
|
+
async handleSearchRequest(request) {
|
|
64
|
+
const { query, k = 10 } = request.parameters;
|
|
65
|
+
if (!query) {
|
|
66
|
+
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "query" is required');
|
|
67
|
+
}
|
|
68
|
+
const results = await this.brainyData.searchText(query, k);
|
|
69
|
+
return this.createSuccessResponse(request.requestId, results);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Handles an add request
|
|
73
|
+
* @param request The MCP request
|
|
74
|
+
* @returns An MCP response
|
|
75
|
+
*/
|
|
76
|
+
async handleAddRequest(request) {
|
|
77
|
+
const { text, metadata } = request.parameters;
|
|
78
|
+
if (!text) {
|
|
79
|
+
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "text" is required');
|
|
80
|
+
}
|
|
81
|
+
const id = await this.brainyData.add(text, metadata);
|
|
82
|
+
return this.createSuccessResponse(request.requestId, { id });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Handles a getRelationships request
|
|
86
|
+
* @param request The MCP request
|
|
87
|
+
* @returns An MCP response
|
|
88
|
+
*/
|
|
89
|
+
async handleGetRelationshipsRequest(request) {
|
|
90
|
+
const { id } = request.parameters;
|
|
91
|
+
if (!id) {
|
|
92
|
+
return this.createErrorResponse(request.requestId, 'MISSING_PARAMETER', 'Parameter "id" is required');
|
|
93
|
+
}
|
|
94
|
+
// This is a simplified implementation - in a real implementation, we would
|
|
95
|
+
// need to check if these methods exist on the BrainyDataInterface
|
|
96
|
+
const outgoing = await this.brainyData.getVerbsBySource?.(id) || [];
|
|
97
|
+
const incoming = await this.brainyData.getVerbsByTarget?.(id) || [];
|
|
98
|
+
return this.createSuccessResponse(request.requestId, { outgoing, incoming });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a success response
|
|
102
|
+
* @param requestId The request ID
|
|
103
|
+
* @param data The response data
|
|
104
|
+
* @returns An MCP response
|
|
105
|
+
*/
|
|
106
|
+
createSuccessResponse(requestId, data) {
|
|
107
|
+
return {
|
|
108
|
+
success: true,
|
|
109
|
+
requestId,
|
|
110
|
+
version: MCP_VERSION,
|
|
111
|
+
data
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Creates an error response
|
|
116
|
+
* @param requestId The request ID
|
|
117
|
+
* @param code The error code
|
|
118
|
+
* @param message The error message
|
|
119
|
+
* @param details Optional error details
|
|
120
|
+
* @returns An MCP response
|
|
121
|
+
*/
|
|
122
|
+
createErrorResponse(requestId, code, message, details) {
|
|
123
|
+
return {
|
|
124
|
+
success: false,
|
|
125
|
+
requestId,
|
|
126
|
+
version: MCP_VERSION,
|
|
127
|
+
error: {
|
|
128
|
+
code,
|
|
129
|
+
message,
|
|
130
|
+
details
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates a new request ID
|
|
136
|
+
* @returns A new UUID
|
|
137
|
+
*/
|
|
138
|
+
generateRequestId() {
|
|
139
|
+
return uuidv4();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=brainyMCPAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brainyMCPAdapter.js","sourceRoot":"","sources":["../../src/mcp/brainyMCPAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAKL,WAAW,EACZ,MAAM,sBAAsB,CAAA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y data and augmentations
|
|
5
|
+
* through the Model Control Protocol (MCP). It integrates the BrainyMCPAdapter and
|
|
6
|
+
* MCPAugmentationToolset classes and provides WebSocket and REST server implementations
|
|
7
|
+
* for external model access.
|
|
8
|
+
*/
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
10
|
+
import { MCPRequestType, MCP_VERSION } from '../types/mcpTypes.js';
|
|
11
|
+
import { BrainyMCPAdapter } from './brainyMCPAdapter.js';
|
|
12
|
+
import { MCPAugmentationToolset } from './mcpAugmentationToolset.js';
|
|
13
|
+
import { isBrowser, isNode } from '../utils/environment.js';
|
|
14
|
+
export class BrainyMCPService {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new BrainyMCPService
|
|
17
|
+
* @param brainyData The BrainyData instance to wrap
|
|
18
|
+
* @param options Configuration options for the service
|
|
19
|
+
*/
|
|
20
|
+
constructor(brainyData, options = {}) {
|
|
21
|
+
this.dataAdapter = new BrainyMCPAdapter(brainyData);
|
|
22
|
+
this.toolset = new MCPAugmentationToolset();
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.authTokens = new Map();
|
|
25
|
+
this.rateLimits = new Map();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Handles an MCP request
|
|
29
|
+
* @param request The MCP request
|
|
30
|
+
* @returns An MCP response
|
|
31
|
+
*/
|
|
32
|
+
async handleRequest(request) {
|
|
33
|
+
try {
|
|
34
|
+
switch (request.type) {
|
|
35
|
+
case MCPRequestType.DATA_ACCESS:
|
|
36
|
+
return await this.dataAdapter.handleRequest(request);
|
|
37
|
+
case MCPRequestType.TOOL_EXECUTION:
|
|
38
|
+
return await this.toolset.handleRequest(request);
|
|
39
|
+
case MCPRequestType.SYSTEM_INFO:
|
|
40
|
+
return await this.handleSystemInfoRequest(request);
|
|
41
|
+
case MCPRequestType.AUTHENTICATION:
|
|
42
|
+
return await this.handleAuthenticationRequest(request);
|
|
43
|
+
default:
|
|
44
|
+
return this.createErrorResponse(request.requestId, 'UNSUPPORTED_REQUEST_TYPE', `Request type ${request.type} is not supported`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return this.createErrorResponse(request.requestId, 'INTERNAL_ERROR', error instanceof Error ? error.message : String(error));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Handles a system info request
|
|
53
|
+
* @param request The MCP request
|
|
54
|
+
* @returns An MCP response
|
|
55
|
+
*/
|
|
56
|
+
async handleSystemInfoRequest(request) {
|
|
57
|
+
try {
|
|
58
|
+
switch (request.infoType) {
|
|
59
|
+
case 'status':
|
|
60
|
+
return this.createSuccessResponse(request.requestId, {
|
|
61
|
+
status: 'active',
|
|
62
|
+
version: MCP_VERSION,
|
|
63
|
+
environment: isBrowser() ? 'browser' : isNode() ? 'node' : 'unknown'
|
|
64
|
+
});
|
|
65
|
+
case 'availableTools':
|
|
66
|
+
const tools = await this.toolset.getAvailableTools();
|
|
67
|
+
return this.createSuccessResponse(request.requestId, tools);
|
|
68
|
+
case 'version':
|
|
69
|
+
return this.createSuccessResponse(request.requestId, {
|
|
70
|
+
version: MCP_VERSION
|
|
71
|
+
});
|
|
72
|
+
default:
|
|
73
|
+
return this.createErrorResponse(request.requestId, 'UNSUPPORTED_INFO_TYPE', `Info type ${request.infoType} is not supported`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return this.createErrorResponse(request.requestId, 'INTERNAL_ERROR', error instanceof Error ? error.message : String(error));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Handles an authentication request
|
|
82
|
+
* @param request The MCP request
|
|
83
|
+
* @returns An MCP response
|
|
84
|
+
*/
|
|
85
|
+
async handleAuthenticationRequest(request) {
|
|
86
|
+
try {
|
|
87
|
+
if (!this.options.enableAuth) {
|
|
88
|
+
return this.createSuccessResponse(request.requestId, {
|
|
89
|
+
authenticated: true,
|
|
90
|
+
message: 'Authentication is not enabled'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const { credentials } = request;
|
|
94
|
+
// Check API key authentication
|
|
95
|
+
if (credentials.apiKey &&
|
|
96
|
+
this.options.apiKeys?.includes(credentials.apiKey)) {
|
|
97
|
+
const token = this.generateAuthToken('api-user');
|
|
98
|
+
return this.createSuccessResponse(request.requestId, {
|
|
99
|
+
authenticated: true,
|
|
100
|
+
token
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Check username/password authentication
|
|
104
|
+
// This is a placeholder - in a real implementation, you would check against a database
|
|
105
|
+
if (credentials.username === 'admin' &&
|
|
106
|
+
credentials.password === 'password') {
|
|
107
|
+
const token = this.generateAuthToken(credentials.username);
|
|
108
|
+
return this.createSuccessResponse(request.requestId, {
|
|
109
|
+
authenticated: true,
|
|
110
|
+
token
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return this.createErrorResponse(request.requestId, 'INVALID_CREDENTIALS', 'Invalid credentials');
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return this.createErrorResponse(request.requestId, 'INTERNAL_ERROR', error instanceof Error ? error.message : String(error));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a request is valid
|
|
121
|
+
* @param request The request to check
|
|
122
|
+
* @returns Whether the request is valid
|
|
123
|
+
*/
|
|
124
|
+
isValidRequest(request) {
|
|
125
|
+
return (request &&
|
|
126
|
+
typeof request === 'object' &&
|
|
127
|
+
request.type &&
|
|
128
|
+
request.requestId &&
|
|
129
|
+
request.version);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Checks if a request is authenticated
|
|
133
|
+
* @param request The request to check
|
|
134
|
+
* @returns Whether the request is authenticated
|
|
135
|
+
*/
|
|
136
|
+
isAuthenticated(request) {
|
|
137
|
+
if (!this.options.enableAuth) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return request.authToken ? this.isValidToken(request.authToken) : false;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Checks if a token is valid
|
|
144
|
+
* @param token The token to check
|
|
145
|
+
* @returns Whether the token is valid
|
|
146
|
+
*/
|
|
147
|
+
isValidToken(token) {
|
|
148
|
+
const tokenInfo = this.authTokens.get(token);
|
|
149
|
+
if (!tokenInfo) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (tokenInfo.expires < Date.now()) {
|
|
153
|
+
this.authTokens.delete(token);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Generates an authentication token
|
|
160
|
+
* @param userId The user ID to associate with the token
|
|
161
|
+
* @returns The generated token
|
|
162
|
+
*/
|
|
163
|
+
generateAuthToken(userId) {
|
|
164
|
+
const token = uuidv4();
|
|
165
|
+
const expires = Date.now() + 24 * 60 * 60 * 1000; // 24 hours
|
|
166
|
+
this.authTokens.set(token, { userId, expires });
|
|
167
|
+
return token;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Checks if a client has exceeded the rate limit
|
|
171
|
+
* @param clientId The client ID to check
|
|
172
|
+
* @returns Whether the client is within the rate limit
|
|
173
|
+
*/
|
|
174
|
+
checkRateLimit(clientId) {
|
|
175
|
+
if (!this.options.rateLimit) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
const now = Date.now();
|
|
179
|
+
const limit = this.rateLimits.get(clientId);
|
|
180
|
+
if (!limit) {
|
|
181
|
+
this.rateLimits.set(clientId, {
|
|
182
|
+
count: 1,
|
|
183
|
+
resetTime: now + this.options.rateLimit.windowMs
|
|
184
|
+
});
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
if (limit.resetTime < now) {
|
|
188
|
+
limit.count = 1;
|
|
189
|
+
limit.resetTime = now + this.options.rateLimit.windowMs;
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
if (limit.count >= this.options.rateLimit.maxRequests) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
limit.count++;
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates a success response
|
|
200
|
+
* @param requestId The request ID
|
|
201
|
+
* @param data The response data
|
|
202
|
+
* @returns An MCP response
|
|
203
|
+
*/
|
|
204
|
+
createSuccessResponse(requestId, data) {
|
|
205
|
+
return {
|
|
206
|
+
success: true,
|
|
207
|
+
requestId,
|
|
208
|
+
version: MCP_VERSION,
|
|
209
|
+
data
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Creates an error response
|
|
214
|
+
* @param requestId The request ID
|
|
215
|
+
* @param code The error code
|
|
216
|
+
* @param message The error message
|
|
217
|
+
* @param details Optional error details
|
|
218
|
+
* @returns An MCP response
|
|
219
|
+
*/
|
|
220
|
+
createErrorResponse(requestId, code, message, details) {
|
|
221
|
+
return {
|
|
222
|
+
success: false,
|
|
223
|
+
requestId,
|
|
224
|
+
version: MCP_VERSION,
|
|
225
|
+
error: {
|
|
226
|
+
code,
|
|
227
|
+
message,
|
|
228
|
+
details
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Creates a new request ID
|
|
234
|
+
* @returns A new UUID
|
|
235
|
+
*/
|
|
236
|
+
generateRequestId() {
|
|
237
|
+
return uuidv4();
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Handles an MCP request directly (for in-process models)
|
|
241
|
+
* @param request The MCP request
|
|
242
|
+
* @returns An MCP response
|
|
243
|
+
*/
|
|
244
|
+
async handleMCPRequest(request) {
|
|
245
|
+
return await this.handleRequest(request);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=brainyMCPService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brainyMCPService.js","sourceRoot":"","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ACb,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACK,qBAAqB,CAAC,SAAiB,EAAE,IAAS;QACxD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,SAAS;YACT,OAAO,EAAE,WAAW;YACpB,IAAI;SACL,CAAA;IACH,CAAC;IAED;;;;;;;OAOG;IACK,mBAAmB,CACzB,SAAiB,EACjB,IAAY,EACZ,OAAe,EACf,OAAa;QAEb,OAAO;YACL,OAAO,EAAE,KAAK;YACd,SAAS;YACT,OAAO,EAAE,WAAW;YACpB,KAAK,EAAE;gBACL,IAAI;gBACJ,OAAO;gBACP,OAAO;aACR;SACF,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,iBAAiB;QACf,OAAO,MAAM,EAAE,CAAA;IACjB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,gBAAgB,CAAC,OAAmB;QACxC,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Control Protocol (MCP) for Brainy
|
|
3
|
+
*
|
|
4
|
+
* This module provides a Model Control Protocol (MCP) implementation for Brainy,
|
|
5
|
+
* allowing external models to access Brainy data and use the augmentation pipeline as tools.
|
|
6
|
+
*/
|
|
7
|
+
// Import and re-export the MCP components
|
|
8
|
+
import { BrainyMCPAdapter } from './brainyMCPAdapter.js';
|
|
9
|
+
import { MCPAugmentationToolset } from './mcpAugmentationToolset.js';
|
|
10
|
+
import { BrainyMCPService } from './brainyMCPService.js';
|
|
11
|
+
// Export the MCP components
|
|
12
|
+
export { BrainyMCPAdapter };
|
|
13
|
+
export { MCPAugmentationToolset };
|
|
14
|
+
export { BrainyMCPService };
|
|
15
|
+
// Export the MCP types
|
|
16
|
+
export * from '../types/mcpTypes.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0CAA0C;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,4BAA4B;AAC5B,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC3B,OAAO,EAAE,sBAAsB,EAAE,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAE3B,uBAAuB;AACvB,cAAc,sBAAsB,CAAA"}
|