@soulcraft/brainy 0.9.5
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/LICENSE +21 -0
- package/README.demo.md +59 -0
- package/README.md +1257 -0
- package/brainy.png +0 -0
- package/cli-wrapper.js +56 -0
- package/dist/augmentationFactory.d.ts +87 -0
- package/dist/augmentationPipeline.d.ts +205 -0
- package/dist/augmentationRegistry.d.ts +48 -0
- package/dist/augmentationRegistryLoader.d.ts +147 -0
- package/dist/augmentations/conduitAugmentations.d.ts +173 -0
- package/dist/augmentations/memoryAugmentations.d.ts +71 -0
- package/dist/augmentations/serverSearchAugmentations.d.ts +168 -0
- package/dist/brainy.js +116929 -0
- package/dist/brainy.min.js +16107 -0
- package/dist/brainyData.d.ts +507 -0
- package/dist/cli.d.ts +7 -0
- package/dist/coreTypes.d.ts +131 -0
- package/dist/examples/basicUsage.d.ts +5 -0
- package/dist/hnsw/hnswIndex.d.ts +96 -0
- package/dist/hnsw/hnswIndexOptimized.d.ts +167 -0
- package/dist/index.d.ts +49 -0
- package/dist/mcp/brainyMCPAdapter.d.ts +69 -0
- package/dist/mcp/brainyMCPService.d.ts +99 -0
- package/dist/mcp/index.d.ts +14 -0
- package/dist/mcp/mcpAugmentationToolset.d.ts +68 -0
- package/dist/pipeline.d.ts +281 -0
- package/dist/sequentialPipeline.d.ts +114 -0
- package/dist/storage/fileSystemStorage.d.ts +123 -0
- package/dist/storage/opfsStorage.d.ts +244 -0
- package/dist/storage/s3CompatibleStorage.d.ts +158 -0
- package/dist/types/augmentations.d.ts +324 -0
- package/dist/types/augmentations.d.ts.map +1 -0
- package/dist/types/brainyDataInterface.d.ts +51 -0
- package/dist/types/brainyDataInterface.d.ts.map +1 -0
- package/dist/types/fileSystemTypes.d.ts +6 -0
- package/dist/types/fileSystemTypes.d.ts.map +1 -0
- package/dist/types/graphTypes.d.ts +134 -0
- package/dist/types/graphTypes.d.ts.map +1 -0
- package/dist/types/mcpTypes.d.ts +140 -0
- package/dist/types/mcpTypes.d.ts.map +1 -0
- package/dist/types/pipelineTypes.d.ts +27 -0
- package/dist/types/pipelineTypes.d.ts.map +1 -0
- package/dist/types/tensorflowTypes.d.ts +7 -0
- package/dist/types/tensorflowTypes.d.ts.map +1 -0
- package/dist/unified.d.ts +12 -0
- package/dist/unified.js +117122 -0
- package/dist/unified.min.js +16107 -0
- package/dist/utils/distance.d.ts +32 -0
- package/dist/utils/embedding.d.ts +55 -0
- package/dist/utils/environment.d.ts +28 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/version.d.ts +6 -0
- package/dist/utils/workerUtils.d.ts +28 -0
- package/package.json +156 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HNSW (Hierarchical Navigable Small World) Index implementation
|
|
3
|
+
* Based on the paper: "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs"
|
|
4
|
+
*/
|
|
5
|
+
import { DistanceFunction, HNSWConfig, HNSWNoun, Vector, VectorDocument } from '../coreTypes.js';
|
|
6
|
+
export declare class HNSWIndex {
|
|
7
|
+
private nouns;
|
|
8
|
+
private entryPointId;
|
|
9
|
+
private maxLevel;
|
|
10
|
+
private config;
|
|
11
|
+
private distanceFunction;
|
|
12
|
+
private dimension;
|
|
13
|
+
private useParallelization;
|
|
14
|
+
constructor(config?: Partial<HNSWConfig>, distanceFunction?: DistanceFunction, options?: {
|
|
15
|
+
useParallelization?: boolean;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Set whether to use parallelization for performance-critical operations
|
|
19
|
+
*/
|
|
20
|
+
setUseParallelization(useParallelization: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get whether parallelization is enabled
|
|
23
|
+
*/
|
|
24
|
+
getUseParallelization(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Calculate distances between a query vector and multiple vectors in parallel
|
|
27
|
+
* This is used to optimize performance for search operations
|
|
28
|
+
* @param queryVector The query vector
|
|
29
|
+
* @param vectors Array of vectors to compare against
|
|
30
|
+
* @returns Array of distances
|
|
31
|
+
*/
|
|
32
|
+
private calculateDistancesInParallel;
|
|
33
|
+
/**
|
|
34
|
+
* Add a vector to the index
|
|
35
|
+
*/
|
|
36
|
+
addItem(item: VectorDocument): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Search for nearest neighbors
|
|
39
|
+
*/
|
|
40
|
+
search(queryVector: Vector, k?: number): Promise<Array<[string, number]>>;
|
|
41
|
+
/**
|
|
42
|
+
* Remove an item from the index
|
|
43
|
+
*/
|
|
44
|
+
removeItem(id: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get all nouns in the index
|
|
47
|
+
*/
|
|
48
|
+
getNouns(): Map<string, HNSWNoun>;
|
|
49
|
+
/**
|
|
50
|
+
* Clear the index
|
|
51
|
+
*/
|
|
52
|
+
clear(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Get the size of the index
|
|
55
|
+
*/
|
|
56
|
+
size(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Get the distance function used by the index
|
|
59
|
+
*/
|
|
60
|
+
getDistanceFunction(): DistanceFunction;
|
|
61
|
+
/**
|
|
62
|
+
* Get the entry point ID
|
|
63
|
+
*/
|
|
64
|
+
getEntryPointId(): string | null;
|
|
65
|
+
/**
|
|
66
|
+
* Get the maximum level
|
|
67
|
+
*/
|
|
68
|
+
getMaxLevel(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Get the dimension
|
|
71
|
+
*/
|
|
72
|
+
getDimension(): number | null;
|
|
73
|
+
/**
|
|
74
|
+
* Get the configuration
|
|
75
|
+
*/
|
|
76
|
+
getConfig(): HNSWConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Search within a specific layer
|
|
79
|
+
* Returns a map of noun IDs to distances, sorted by distance
|
|
80
|
+
*/
|
|
81
|
+
private searchLayer;
|
|
82
|
+
/**
|
|
83
|
+
* Select M nearest neighbors from the candidate set
|
|
84
|
+
*/
|
|
85
|
+
private selectNeighbors;
|
|
86
|
+
/**
|
|
87
|
+
* Ensure a noun doesn't have too many connections at a given level
|
|
88
|
+
*/
|
|
89
|
+
private pruneConnections;
|
|
90
|
+
/**
|
|
91
|
+
* Generate a random level for a new noun
|
|
92
|
+
* Uses the same distribution as in the original HNSW paper
|
|
93
|
+
*/
|
|
94
|
+
private getRandomLevel;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=hnswIndex.d.ts.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimized HNSW (Hierarchical Navigable Small World) Index implementation
|
|
3
|
+
* Extends the base HNSW implementation with support for large datasets
|
|
4
|
+
* Uses product quantization for dimensionality reduction and disk-based storage when needed
|
|
5
|
+
*/
|
|
6
|
+
import { DistanceFunction, HNSWConfig, Vector, VectorDocument } from '../coreTypes.js';
|
|
7
|
+
import { HNSWIndex } from './hnswIndex.js';
|
|
8
|
+
import { StorageAdapter } from '../coreTypes.js';
|
|
9
|
+
export interface HNSWOptimizedConfig extends HNSWConfig {
|
|
10
|
+
memoryThreshold?: number;
|
|
11
|
+
productQuantization?: {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
numSubvectors?: number;
|
|
14
|
+
numCentroids?: number;
|
|
15
|
+
};
|
|
16
|
+
useDiskBasedIndex?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Product Quantization implementation
|
|
20
|
+
* Reduces vector dimensionality by splitting vectors into subvectors
|
|
21
|
+
* and quantizing each subvector to the nearest centroid
|
|
22
|
+
*/
|
|
23
|
+
declare class ProductQuantizer {
|
|
24
|
+
private numSubvectors;
|
|
25
|
+
private numCentroids;
|
|
26
|
+
private centroids;
|
|
27
|
+
private subvectorSize;
|
|
28
|
+
private initialized;
|
|
29
|
+
private dimension;
|
|
30
|
+
constructor(numSubvectors?: number, numCentroids?: number);
|
|
31
|
+
/**
|
|
32
|
+
* Initialize the product quantizer with training data
|
|
33
|
+
* @param vectors Training vectors to use for learning centroids
|
|
34
|
+
*/
|
|
35
|
+
train(vectors: Vector[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* Quantize a vector using product quantization
|
|
38
|
+
* @param vector Vector to quantize
|
|
39
|
+
* @returns Array of centroid indices, one for each subvector
|
|
40
|
+
*/
|
|
41
|
+
quantize(vector: Vector): number[];
|
|
42
|
+
/**
|
|
43
|
+
* Reconstruct a vector from its quantized representation
|
|
44
|
+
* @param codes Array of centroid indices
|
|
45
|
+
* @returns Reconstructed vector
|
|
46
|
+
*/
|
|
47
|
+
reconstruct(codes: number[]): Vector;
|
|
48
|
+
/**
|
|
49
|
+
* Compute squared Euclidean distance between two vectors
|
|
50
|
+
* @param a First vector
|
|
51
|
+
* @param b Second vector
|
|
52
|
+
* @returns Squared Euclidean distance
|
|
53
|
+
*/
|
|
54
|
+
private euclideanDistanceSquared;
|
|
55
|
+
/**
|
|
56
|
+
* Implement k-means++ algorithm to initialize centroids
|
|
57
|
+
* @param vectors Vectors to cluster
|
|
58
|
+
* @param k Number of clusters
|
|
59
|
+
* @returns Array of centroids
|
|
60
|
+
*/
|
|
61
|
+
private kMeansPlusPlus;
|
|
62
|
+
/**
|
|
63
|
+
* Get the centroids for each subvector
|
|
64
|
+
* @returns Array of centroid arrays
|
|
65
|
+
*/
|
|
66
|
+
getCentroids(): Vector[][];
|
|
67
|
+
/**
|
|
68
|
+
* Set the centroids for each subvector
|
|
69
|
+
* @param centroids Array of centroid arrays
|
|
70
|
+
*/
|
|
71
|
+
setCentroids(centroids: Vector[][]): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get the dimension of the vectors
|
|
74
|
+
* @returns Dimension
|
|
75
|
+
*/
|
|
76
|
+
getDimension(): number;
|
|
77
|
+
/**
|
|
78
|
+
* Set the dimension of the vectors
|
|
79
|
+
* @param dimension Dimension
|
|
80
|
+
*/
|
|
81
|
+
setDimension(dimension: number): void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Optimized HNSW Index implementation
|
|
85
|
+
* Extends the base HNSW implementation with support for large datasets
|
|
86
|
+
* Uses product quantization for dimensionality reduction and disk-based storage when needed
|
|
87
|
+
*/
|
|
88
|
+
export declare class HNSWIndexOptimized extends HNSWIndex {
|
|
89
|
+
private optimizedConfig;
|
|
90
|
+
private productQuantizer;
|
|
91
|
+
private storage;
|
|
92
|
+
private useDiskBasedIndex;
|
|
93
|
+
private useProductQuantization;
|
|
94
|
+
private quantizedVectors;
|
|
95
|
+
private memoryUsage;
|
|
96
|
+
private vectorCount;
|
|
97
|
+
constructor(config: Partial<HNSWOptimizedConfig> | undefined, distanceFunction: DistanceFunction, storage?: StorageAdapter | null);
|
|
98
|
+
/**
|
|
99
|
+
* Add a vector to the index
|
|
100
|
+
* Uses product quantization if enabled and memory threshold is exceeded
|
|
101
|
+
*/
|
|
102
|
+
addItem(item: VectorDocument): Promise<string>;
|
|
103
|
+
/**
|
|
104
|
+
* Search for nearest neighbors
|
|
105
|
+
* Uses product quantization if enabled
|
|
106
|
+
*/
|
|
107
|
+
search(queryVector: Vector, k?: number): Promise<Array<[string, number]>>;
|
|
108
|
+
/**
|
|
109
|
+
* Remove an item from the index
|
|
110
|
+
*/
|
|
111
|
+
removeItem(id: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Clear the index
|
|
114
|
+
*/
|
|
115
|
+
clear(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Initialize product quantizer with existing vectors
|
|
118
|
+
*/
|
|
119
|
+
private initializeProductQuantizer;
|
|
120
|
+
/**
|
|
121
|
+
* Get the product quantizer
|
|
122
|
+
* @returns Product quantizer or null if not enabled
|
|
123
|
+
*/
|
|
124
|
+
getProductQuantizer(): ProductQuantizer | null;
|
|
125
|
+
/**
|
|
126
|
+
* Get the optimized configuration
|
|
127
|
+
* @returns Optimized configuration
|
|
128
|
+
*/
|
|
129
|
+
getOptimizedConfig(): HNSWOptimizedConfig;
|
|
130
|
+
/**
|
|
131
|
+
* Get the estimated memory usage
|
|
132
|
+
* @returns Estimated memory usage in bytes
|
|
133
|
+
*/
|
|
134
|
+
getMemoryUsage(): number;
|
|
135
|
+
/**
|
|
136
|
+
* Set the storage adapter
|
|
137
|
+
* @param storage Storage adapter
|
|
138
|
+
*/
|
|
139
|
+
setStorage(storage: StorageAdapter): void;
|
|
140
|
+
/**
|
|
141
|
+
* Get the storage adapter
|
|
142
|
+
* @returns Storage adapter or null if not set
|
|
143
|
+
*/
|
|
144
|
+
getStorage(): StorageAdapter | null;
|
|
145
|
+
/**
|
|
146
|
+
* Set whether to use disk-based index
|
|
147
|
+
* @param useDiskBasedIndex Whether to use disk-based index
|
|
148
|
+
*/
|
|
149
|
+
setUseDiskBasedIndex(useDiskBasedIndex: boolean): void;
|
|
150
|
+
/**
|
|
151
|
+
* Get whether disk-based index is used
|
|
152
|
+
* @returns Whether disk-based index is used
|
|
153
|
+
*/
|
|
154
|
+
getUseDiskBasedIndex(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Set whether to use product quantization
|
|
157
|
+
* @param useProductQuantization Whether to use product quantization
|
|
158
|
+
*/
|
|
159
|
+
setUseProductQuantization(useProductQuantization: boolean): void;
|
|
160
|
+
/**
|
|
161
|
+
* Get whether product quantization is used
|
|
162
|
+
* @returns Whether product quantization is used
|
|
163
|
+
*/
|
|
164
|
+
getUseProductQuantization(): boolean;
|
|
165
|
+
}
|
|
166
|
+
export {};
|
|
167
|
+
//# sourceMappingURL=hnswIndexOptimized.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPFS BrainyData
|
|
3
|
+
* A vector database using HNSW indexing with Origin Private File System storage
|
|
4
|
+
*/
|
|
5
|
+
import { BrainyData, BrainyDataConfig } from './brainyData.js';
|
|
6
|
+
export { BrainyData };
|
|
7
|
+
export type { BrainyDataConfig };
|
|
8
|
+
import { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance } from './utils/index.js';
|
|
9
|
+
export { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance };
|
|
10
|
+
import { UniversalSentenceEncoder, createEmbeddingFunction, createTensorFlowEmbeddingFunction, createThreadedEmbeddingFunction, defaultEmbeddingFunction } from './utils/embedding.js';
|
|
11
|
+
export { UniversalSentenceEncoder, createEmbeddingFunction, createTensorFlowEmbeddingFunction, createThreadedEmbeddingFunction, defaultEmbeddingFunction };
|
|
12
|
+
import { OPFSStorage, MemoryStorage, createStorage } from './storage/opfsStorage.js';
|
|
13
|
+
import { FileSystemStorage } from './storage/fileSystemStorage.js';
|
|
14
|
+
import { R2Storage, S3CompatibleStorage } from './storage/s3CompatibleStorage.js';
|
|
15
|
+
export { OPFSStorage, MemoryStorage, FileSystemStorage, R2Storage, S3CompatibleStorage, createStorage };
|
|
16
|
+
import { Pipeline, pipeline, augmentationPipeline, ExecutionMode, PipelineOptions, PipelineResult, executeStreamlined, executeByType, executeSingle, processStaticData, processStreamingData, createPipeline, createStreamingPipeline, StreamlinedExecutionMode, StreamlinedPipelineOptions, StreamlinedPipelineResult } from './pipeline.js';
|
|
17
|
+
import { SequentialPipeline, sequentialPipeline, SequentialPipelineOptions } from './sequentialPipeline.js';
|
|
18
|
+
import { createSenseAugmentation, addWebSocketSupport, executeAugmentation, loadAugmentationModule, AugmentationOptions } from './augmentationFactory.js';
|
|
19
|
+
export { Pipeline, pipeline, augmentationPipeline, ExecutionMode, SequentialPipeline, sequentialPipeline, executeStreamlined, executeByType, executeSingle, processStaticData, processStreamingData, createPipeline, createStreamingPipeline, StreamlinedExecutionMode, createSenseAugmentation, addWebSocketSupport, executeAugmentation, loadAugmentationModule };
|
|
20
|
+
export type { PipelineOptions, PipelineResult, SequentialPipelineOptions, StreamlinedPipelineOptions, StreamlinedPipelineResult, AugmentationOptions };
|
|
21
|
+
import { availableAugmentations, registerAugmentation, initializeAugmentationPipeline, setAugmentationEnabled, getAugmentationsByType } from './augmentationRegistry.js';
|
|
22
|
+
export { availableAugmentations, registerAugmentation, initializeAugmentationPipeline, setAugmentationEnabled, getAugmentationsByType };
|
|
23
|
+
import { loadAugmentationsFromModules, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin } from './augmentationRegistryLoader.js';
|
|
24
|
+
import type { AugmentationRegistryLoaderOptions, AugmentationLoadResult } from './augmentationRegistryLoader.js';
|
|
25
|
+
export { loadAugmentationsFromModules, createAugmentationRegistryPlugin, createAugmentationRegistryRollupPlugin };
|
|
26
|
+
export type { AugmentationRegistryLoaderOptions, AugmentationLoadResult };
|
|
27
|
+
import { MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentation, createMemoryAugmentation } from './augmentations/memoryAugmentations.js';
|
|
28
|
+
import { WebSocketConduitAugmentation, WebRTCConduitAugmentation, createConduitAugmentation } from './augmentations/conduitAugmentations.js';
|
|
29
|
+
import { ServerSearchConduitAugmentation, ServerSearchActivationAugmentation, createServerSearchAugmentations } from './augmentations/serverSearchAugmentations.js';
|
|
30
|
+
export { MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentation, createMemoryAugmentation, WebSocketConduitAugmentation, WebRTCConduitAugmentation, createConduitAugmentation, ServerSearchConduitAugmentation, ServerSearchActivationAugmentation, createServerSearchAugmentations };
|
|
31
|
+
import type { Vector, VectorDocument, SearchResult, DistanceFunction, EmbeddingFunction, EmbeddingModel, HNSWNoun, GraphVerb, HNSWConfig, StorageAdapter } from './coreTypes.js';
|
|
32
|
+
import { HNSWIndex } from './hnsw/hnswIndex.js';
|
|
33
|
+
import { HNSWIndexOptimized, HNSWOptimizedConfig } from './hnsw/hnswIndexOptimized.js';
|
|
34
|
+
export { HNSWIndex, HNSWIndexOptimized };
|
|
35
|
+
export type { Vector, VectorDocument, SearchResult, DistanceFunction, EmbeddingFunction, EmbeddingModel, HNSWNoun, GraphVerb, HNSWConfig, HNSWOptimizedConfig, StorageAdapter };
|
|
36
|
+
import type { IAugmentation, AugmentationResponse, IWebSocketSupport, ISenseAugmentation, IConduitAugmentation, ICognitionAugmentation, IMemoryAugmentation, IPerceptionAugmentation, IDialogAugmentation, IActivationAugmentation } from './types/augmentations.js';
|
|
37
|
+
import { AugmentationType, BrainyAugmentations } from './types/augmentations.js';
|
|
38
|
+
export type { IAugmentation, AugmentationResponse, IWebSocketSupport };
|
|
39
|
+
export { AugmentationType, BrainyAugmentations, ISenseAugmentation, IConduitAugmentation, ICognitionAugmentation, IMemoryAugmentation, IPerceptionAugmentation, IDialogAugmentation, IActivationAugmentation };
|
|
40
|
+
export type { IWebSocketCognitionAugmentation, IWebSocketSenseAugmentation, IWebSocketPerceptionAugmentation, IWebSocketActivationAugmentation, IWebSocketDialogAugmentation, IWebSocketConduitAugmentation, IWebSocketMemoryAugmentation } from './types/augmentations.js';
|
|
41
|
+
import type { GraphNoun, EmbeddedGraphVerb, Person, Place, Thing, Event, Concept, Content } from './types/graphTypes.js';
|
|
42
|
+
import { NounType, VerbType } from './types/graphTypes.js';
|
|
43
|
+
export type { GraphNoun, EmbeddedGraphVerb, Person, Place, Thing, Event, Concept, Content };
|
|
44
|
+
export { NounType, VerbType };
|
|
45
|
+
import { BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService } from './mcp/index.js';
|
|
46
|
+
import { MCPRequest, MCPResponse, MCPDataAccessRequest, MCPToolExecutionRequest, MCPSystemInfoRequest, MCPAuthenticationRequest, MCPRequestType, MCPServiceOptions, MCPTool, MCP_VERSION } from './types/mcpTypes.js';
|
|
47
|
+
export { BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService, MCPRequestType, MCP_VERSION };
|
|
48
|
+
export type { MCPRequest, MCPResponse, MCPDataAccessRequest, MCPToolExecutionRequest, MCPSystemInfoRequest, MCPAuthenticationRequest, MCPServiceOptions, MCPTool };
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { BrainyDataInterface } from '../types/brainyDataInterface.js';
|
|
9
|
+
import { MCPResponse, MCPDataAccessRequest } from '../types/mcpTypes.js';
|
|
10
|
+
export declare class BrainyMCPAdapter {
|
|
11
|
+
private brainyData;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new BrainyMCPAdapter
|
|
14
|
+
* @param brainyData The BrainyData instance to wrap
|
|
15
|
+
*/
|
|
16
|
+
constructor(brainyData: BrainyDataInterface);
|
|
17
|
+
/**
|
|
18
|
+
* Handles an MCP data access request
|
|
19
|
+
* @param request The MCP request
|
|
20
|
+
* @returns An MCP response
|
|
21
|
+
*/
|
|
22
|
+
handleRequest(request: MCPDataAccessRequest): Promise<MCPResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Handles a get request
|
|
25
|
+
* @param request The MCP request
|
|
26
|
+
* @returns An MCP response
|
|
27
|
+
*/
|
|
28
|
+
private handleGetRequest;
|
|
29
|
+
/**
|
|
30
|
+
* Handles a search request
|
|
31
|
+
* @param request The MCP request
|
|
32
|
+
* @returns An MCP response
|
|
33
|
+
*/
|
|
34
|
+
private handleSearchRequest;
|
|
35
|
+
/**
|
|
36
|
+
* Handles an add request
|
|
37
|
+
* @param request The MCP request
|
|
38
|
+
* @returns An MCP response
|
|
39
|
+
*/
|
|
40
|
+
private handleAddRequest;
|
|
41
|
+
/**
|
|
42
|
+
* Handles a getRelationships request
|
|
43
|
+
* @param request The MCP request
|
|
44
|
+
* @returns An MCP response
|
|
45
|
+
*/
|
|
46
|
+
private handleGetRelationshipsRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a success response
|
|
49
|
+
* @param requestId The request ID
|
|
50
|
+
* @param data The response data
|
|
51
|
+
* @returns An MCP response
|
|
52
|
+
*/
|
|
53
|
+
private createSuccessResponse;
|
|
54
|
+
/**
|
|
55
|
+
* Creates an error response
|
|
56
|
+
* @param requestId The request ID
|
|
57
|
+
* @param code The error code
|
|
58
|
+
* @param message The error message
|
|
59
|
+
* @param details Optional error details
|
|
60
|
+
* @returns An MCP response
|
|
61
|
+
*/
|
|
62
|
+
private createErrorResponse;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new request ID
|
|
65
|
+
* @returns A new UUID
|
|
66
|
+
*/
|
|
67
|
+
generateRequestId(): string;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=brainyMCPAdapter.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrainyMCPService
|
|
3
|
+
*
|
|
4
|
+
* This class provides a unified service for accessing Brainy 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 { BrainyDataInterface } from '../types/brainyDataInterface.js';
|
|
10
|
+
import { MCPRequest, MCPResponse, MCPServiceOptions } from '../types/mcpTypes.js';
|
|
11
|
+
export declare class BrainyMCPService {
|
|
12
|
+
private dataAdapter;
|
|
13
|
+
private toolset;
|
|
14
|
+
private options;
|
|
15
|
+
private authTokens;
|
|
16
|
+
private rateLimits;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new BrainyMCPService
|
|
19
|
+
* @param brainyData The BrainyData instance to wrap
|
|
20
|
+
* @param options Configuration options for the service
|
|
21
|
+
*/
|
|
22
|
+
constructor(brainyData: BrainyDataInterface, options?: MCPServiceOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Handles an MCP request
|
|
25
|
+
* @param request The MCP request
|
|
26
|
+
* @returns An MCP response
|
|
27
|
+
*/
|
|
28
|
+
handleRequest(request: MCPRequest): Promise<MCPResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Handles a system info request
|
|
31
|
+
* @param request The MCP request
|
|
32
|
+
* @returns An MCP response
|
|
33
|
+
*/
|
|
34
|
+
private handleSystemInfoRequest;
|
|
35
|
+
/**
|
|
36
|
+
* Handles an authentication request
|
|
37
|
+
* @param request The MCP request
|
|
38
|
+
* @returns An MCP response
|
|
39
|
+
*/
|
|
40
|
+
private handleAuthenticationRequest;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a request is valid
|
|
43
|
+
* @param request The request to check
|
|
44
|
+
* @returns Whether the request is valid
|
|
45
|
+
*/
|
|
46
|
+
private isValidRequest;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a request is authenticated
|
|
49
|
+
* @param request The request to check
|
|
50
|
+
* @returns Whether the request is authenticated
|
|
51
|
+
*/
|
|
52
|
+
private isAuthenticated;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a token is valid
|
|
55
|
+
* @param token The token to check
|
|
56
|
+
* @returns Whether the token is valid
|
|
57
|
+
*/
|
|
58
|
+
private isValidToken;
|
|
59
|
+
/**
|
|
60
|
+
* Generates an authentication token
|
|
61
|
+
* @param userId The user ID to associate with the token
|
|
62
|
+
* @returns The generated token
|
|
63
|
+
*/
|
|
64
|
+
private generateAuthToken;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a client has exceeded the rate limit
|
|
67
|
+
* @param clientId The client ID to check
|
|
68
|
+
* @returns Whether the client is within the rate limit
|
|
69
|
+
*/
|
|
70
|
+
private checkRateLimit;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a success response
|
|
73
|
+
* @param requestId The request ID
|
|
74
|
+
* @param data The response data
|
|
75
|
+
* @returns An MCP response
|
|
76
|
+
*/
|
|
77
|
+
private createSuccessResponse;
|
|
78
|
+
/**
|
|
79
|
+
* Creates an error response
|
|
80
|
+
* @param requestId The request ID
|
|
81
|
+
* @param code The error code
|
|
82
|
+
* @param message The error message
|
|
83
|
+
* @param details Optional error details
|
|
84
|
+
* @returns An MCP response
|
|
85
|
+
*/
|
|
86
|
+
private createErrorResponse;
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new request ID
|
|
89
|
+
* @returns A new UUID
|
|
90
|
+
*/
|
|
91
|
+
generateRequestId(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Handles an MCP request directly (for in-process models)
|
|
94
|
+
* @param request The MCP request
|
|
95
|
+
* @returns An MCP response
|
|
96
|
+
*/
|
|
97
|
+
handleMCPRequest(request: MCPRequest): Promise<MCPResponse>;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=brainyMCPService.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { BrainyMCPAdapter } from './brainyMCPAdapter.js';
|
|
8
|
+
import { MCPAugmentationToolset } from './mcpAugmentationToolset.js';
|
|
9
|
+
import { BrainyMCPService } from './brainyMCPService.js';
|
|
10
|
+
export { BrainyMCPAdapter };
|
|
11
|
+
export { MCPAugmentationToolset };
|
|
12
|
+
export { BrainyMCPService };
|
|
13
|
+
export * from '../types/mcpTypes.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCPAugmentationToolset
|
|
3
|
+
*
|
|
4
|
+
* This class exposes the Brainy augmentation pipeline as tools through the Model Control Protocol (MCP).
|
|
5
|
+
* It provides methods for getting available tools and executing tools.
|
|
6
|
+
*/
|
|
7
|
+
import { MCPResponse, MCPToolExecutionRequest, MCPTool } from '../types/mcpTypes.js';
|
|
8
|
+
export declare class MCPAugmentationToolset {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new MCPAugmentationToolset
|
|
11
|
+
*/
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Handles an MCP tool execution request
|
|
15
|
+
* @param request The MCP request
|
|
16
|
+
* @returns An MCP response
|
|
17
|
+
*/
|
|
18
|
+
handleRequest(request: MCPToolExecutionRequest): Promise<MCPResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* Gets all available tools
|
|
21
|
+
* @returns An array of MCP tools
|
|
22
|
+
*/
|
|
23
|
+
getAvailableTools(): Promise<MCPTool[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a tool definition
|
|
26
|
+
* @param type The augmentation type
|
|
27
|
+
* @param augmentationName The augmentation name
|
|
28
|
+
* @param method The method name
|
|
29
|
+
* @returns An MCP tool definition
|
|
30
|
+
*/
|
|
31
|
+
private createToolDefinition;
|
|
32
|
+
/**
|
|
33
|
+
* Executes the appropriate pipeline based on the augmentation type
|
|
34
|
+
* @param type The augmentation type
|
|
35
|
+
* @param method The method to execute
|
|
36
|
+
* @param parameters The parameters for the method
|
|
37
|
+
* @returns The result of the pipeline execution
|
|
38
|
+
*/
|
|
39
|
+
private executePipeline;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an augmentation type is valid
|
|
42
|
+
* @param type The augmentation type to check
|
|
43
|
+
* @returns Whether the augmentation type is valid
|
|
44
|
+
*/
|
|
45
|
+
private isValidAugmentationType;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a success response
|
|
48
|
+
* @param requestId The request ID
|
|
49
|
+
* @param data The response data
|
|
50
|
+
* @returns An MCP response
|
|
51
|
+
*/
|
|
52
|
+
private createSuccessResponse;
|
|
53
|
+
/**
|
|
54
|
+
* Creates an error response
|
|
55
|
+
* @param requestId The request ID
|
|
56
|
+
* @param code The error code
|
|
57
|
+
* @param message The error message
|
|
58
|
+
* @param details Optional error details
|
|
59
|
+
* @returns An MCP response
|
|
60
|
+
*/
|
|
61
|
+
private createErrorResponse;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new request ID
|
|
64
|
+
* @returns A new UUID
|
|
65
|
+
*/
|
|
66
|
+
generateRequestId(): string;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=mcpAugmentationToolset.d.ts.map
|