@soulcraft/brainy 3.18.0 → 3.19.1

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 (39) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +52 -3
  3. package/bin/brainy.js +9 -2335
  4. package/dist/api/DataAPI.d.ts +1 -1
  5. package/dist/augmentations/cacheAugmentation.d.ts +1 -1
  6. package/dist/augmentations/metricsAugmentation.d.ts +20 -20
  7. package/dist/brainy.d.ts +19 -1
  8. package/dist/brainy.js +24 -0
  9. package/dist/brainyData.js +1 -2
  10. package/dist/cli/catalog.js +8 -12
  11. package/dist/cli/commands/conversation.d.ts +22 -0
  12. package/dist/cli/commands/conversation.js +528 -0
  13. package/dist/cli/commands/core.js +61 -17
  14. package/dist/cli/commands/neural.js +4 -5
  15. package/dist/cli/commands/types.d.ts +30 -0
  16. package/dist/cli/commands/types.js +194 -0
  17. package/dist/cli/commands/utility.js +2 -3
  18. package/dist/cli/index.js +44 -2
  19. package/dist/cli/interactive.d.ts +3 -3
  20. package/dist/cli/interactive.js +5 -5
  21. package/dist/conversation/conversationManager.d.ts +176 -0
  22. package/dist/conversation/conversationManager.js +666 -0
  23. package/dist/conversation/index.d.ts +8 -0
  24. package/dist/conversation/index.js +8 -0
  25. package/dist/conversation/types.d.ts +231 -0
  26. package/dist/conversation/types.js +8 -0
  27. package/dist/hnsw/hnswIndexOptimized.d.ts +1 -1
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.js +3 -0
  30. package/dist/mcp/brainyMCPBroadcast.d.ts +2 -2
  31. package/dist/mcp/brainyMCPBroadcast.js +1 -1
  32. package/dist/mcp/brainyMCPClient.js +8 -4
  33. package/dist/mcp/conversationTools.d.ts +88 -0
  34. package/dist/mcp/conversationTools.js +470 -0
  35. package/dist/neural/types.d.ts +2 -2
  36. package/dist/streaming/pipeline.d.ts +1 -1
  37. package/dist/types/mcpTypes.d.ts +7 -1
  38. package/dist/universal/fs.d.ts +24 -66
  39. package/package.json +2 -2
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Conversation Types for Infinite Agent Memory
3
+ *
4
+ * Production-ready type definitions for storing and retrieving
5
+ * conversation history with semantic search and context management.
6
+ */
7
+ /**
8
+ * Role of the message sender
9
+ */
10
+ export type MessageRole = 'user' | 'assistant' | 'system' | 'tool';
11
+ /**
12
+ * Problem-solving phase for tracking agent's progress
13
+ */
14
+ export type ProblemSolvingPhase = 'understanding' | 'analysis' | 'planning' | 'implementation' | 'testing' | 'debugging' | 'refinement' | 'completed';
15
+ /**
16
+ * Metadata for a conversation message
17
+ */
18
+ export interface ConversationMessageMetadata {
19
+ role: MessageRole;
20
+ conversationId: string;
21
+ sessionId?: string;
22
+ timestamp: number;
23
+ problemSolvingPhase?: ProblemSolvingPhase;
24
+ confidence?: number;
25
+ tokensUsed?: number;
26
+ tokensTotal?: number;
27
+ artifacts?: string[];
28
+ toolsUsed?: string[];
29
+ references?: string[];
30
+ tags?: string[];
31
+ priority?: number;
32
+ archived?: boolean;
33
+ [key: string]: any;
34
+ }
35
+ /**
36
+ * A conversation message with all metadata
37
+ */
38
+ export interface ConversationMessage {
39
+ id: string;
40
+ content: string;
41
+ role: MessageRole;
42
+ metadata: ConversationMessageMetadata;
43
+ embedding?: number[];
44
+ createdAt: number;
45
+ updatedAt: number;
46
+ }
47
+ /**
48
+ * Conversation thread metadata
49
+ */
50
+ export interface ConversationThreadMetadata {
51
+ conversationId: string;
52
+ sessionId?: string;
53
+ title?: string;
54
+ summary?: string;
55
+ startTime: number;
56
+ endTime?: number;
57
+ messageCount: number;
58
+ totalTokens: number;
59
+ participants: string[];
60
+ tags?: string[];
61
+ archived?: boolean;
62
+ [key: string]: any;
63
+ }
64
+ /**
65
+ * A conversation thread (collection of messages)
66
+ */
67
+ export interface ConversationThread {
68
+ id: string;
69
+ metadata: ConversationThreadMetadata;
70
+ messages: ConversationMessage[];
71
+ artifacts?: string[];
72
+ }
73
+ /**
74
+ * Options for retrieving relevant context
75
+ */
76
+ export interface ContextRetrievalOptions {
77
+ query?: string;
78
+ conversationId?: string;
79
+ sessionId?: string;
80
+ role?: MessageRole | MessageRole[];
81
+ phase?: ProblemSolvingPhase | ProblemSolvingPhase[];
82
+ tags?: string[];
83
+ minConfidence?: number;
84
+ timeRange?: {
85
+ start?: number;
86
+ end?: number;
87
+ };
88
+ limit?: number;
89
+ maxTokens?: number;
90
+ relevanceThreshold?: number;
91
+ weights?: {
92
+ semantic?: number;
93
+ temporal?: number;
94
+ graph?: number;
95
+ };
96
+ includeArtifacts?: boolean;
97
+ includeSimilarConversations?: boolean;
98
+ deduplicateClusters?: boolean;
99
+ }
100
+ /**
101
+ * Ranked context message with relevance score
102
+ */
103
+ export interface RankedMessage extends ConversationMessage {
104
+ relevanceScore: number;
105
+ semanticScore?: number;
106
+ temporalScore?: number;
107
+ graphScore?: number;
108
+ explanation?: string;
109
+ }
110
+ /**
111
+ * Retrieved context result
112
+ */
113
+ export interface ConversationContext {
114
+ messages: RankedMessage[];
115
+ artifacts?: Array<{
116
+ path: string;
117
+ id: string;
118
+ content?: string;
119
+ summary?: string;
120
+ }>;
121
+ similarConversations?: Array<{
122
+ id: string;
123
+ title?: string;
124
+ summary?: string;
125
+ relevance: number;
126
+ messageCount: number;
127
+ }>;
128
+ totalTokens: number;
129
+ metadata: {
130
+ queryTime: number;
131
+ messagesConsidered: number;
132
+ conversationsSearched: number;
133
+ };
134
+ }
135
+ /**
136
+ * Options for saving messages
137
+ */
138
+ export interface SaveMessageOptions {
139
+ conversationId?: string;
140
+ sessionId?: string;
141
+ phase?: ProblemSolvingPhase;
142
+ confidence?: number;
143
+ artifacts?: string[];
144
+ toolsUsed?: string[];
145
+ tags?: string[];
146
+ linkToPrevious?: string;
147
+ metadata?: Record<string, any>;
148
+ }
149
+ /**
150
+ * Options for conversation search
151
+ */
152
+ export interface ConversationSearchOptions {
153
+ query: string;
154
+ limit?: number;
155
+ role?: MessageRole | MessageRole[];
156
+ conversationId?: string;
157
+ sessionId?: string;
158
+ timeRange?: {
159
+ start?: number;
160
+ end?: number;
161
+ };
162
+ includeMetadata?: boolean;
163
+ includeContent?: boolean;
164
+ }
165
+ /**
166
+ * Search result for conversations
167
+ */
168
+ export interface ConversationSearchResult {
169
+ message: ConversationMessage;
170
+ score: number;
171
+ conversationId: string;
172
+ snippet?: string;
173
+ }
174
+ /**
175
+ * Theme discovered via clustering
176
+ */
177
+ export interface ConversationTheme {
178
+ id: string;
179
+ label: string;
180
+ messages: string[];
181
+ centroid: number[];
182
+ coherence: number;
183
+ keywords?: string[];
184
+ }
185
+ /**
186
+ * Options for artifact storage
187
+ */
188
+ export interface ArtifactOptions {
189
+ conversationId: string;
190
+ messageId?: string;
191
+ type?: 'code' | 'config' | 'data' | 'document' | 'other';
192
+ language?: string;
193
+ description?: string;
194
+ metadata?: Record<string, any>;
195
+ }
196
+ /**
197
+ * Statistics about conversations
198
+ */
199
+ export interface ConversationStats {
200
+ totalConversations: number;
201
+ totalMessages: number;
202
+ totalTokens: number;
203
+ averageMessagesPerConversation: number;
204
+ averageTokensPerMessage: number;
205
+ oldestMessage: number;
206
+ newestMessage: number;
207
+ phases: Record<ProblemSolvingPhase, number>;
208
+ roles: Record<MessageRole, number>;
209
+ }
210
+ /**
211
+ * Compaction strategy options
212
+ */
213
+ export interface CompactionOptions {
214
+ conversationId: string;
215
+ strategy?: 'cluster-based' | 'importance-based' | 'hybrid';
216
+ keepRatio?: number;
217
+ minImportance?: number;
218
+ preservePhases?: ProblemSolvingPhase[];
219
+ preserveRecent?: number;
220
+ }
221
+ /**
222
+ * Result of compaction operation
223
+ */
224
+ export interface CompactionResult {
225
+ originalCount: number;
226
+ compactedCount: number;
227
+ removedCount: number;
228
+ tokensFreed: number;
229
+ preservedMessageIds: string[];
230
+ summaryMessageId?: string;
231
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Conversation Types for Infinite Agent Memory
3
+ *
4
+ * Production-ready type definitions for storing and retrieving
5
+ * conversation history with semantic search and context management.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -96,7 +96,7 @@ export declare class HNSWIndexOptimized extends HNSWIndex {
96
96
  private vectorCount;
97
97
  private memoryUpdateLock;
98
98
  private unifiedCache;
99
- constructor(config: Partial<HNSWOptimizedConfig> | undefined, distanceFunction: DistanceFunction, storage?: StorageAdapter | null);
99
+ constructor(config: Partial<HNSWOptimizedConfig>, distanceFunction: DistanceFunction, storage?: StorageAdapter | null);
100
100
  /**
101
101
  * Thread-safe method to update memory usage
102
102
  * @param memoryDelta Change in memory usage (can be negative)
package/dist/index.d.ts CHANGED
@@ -56,3 +56,6 @@ import { BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService } from './mc
56
56
  import { MCPRequest, MCPResponse, MCPDataAccessRequest, MCPToolExecutionRequest, MCPSystemInfoRequest, MCPAuthenticationRequest, MCPRequestType, MCPServiceOptions, MCPTool, MCP_VERSION } from './types/mcpTypes.js';
57
57
  export { BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService, MCPRequestType, MCP_VERSION };
58
58
  export type { MCPRequest, MCPResponse, MCPDataAccessRequest, MCPToolExecutionRequest, MCPSystemInfoRequest, MCPAuthenticationRequest, MCPServiceOptions, MCPTool };
59
+ export { ConversationManager, createConversationManager } from './conversation/index.js';
60
+ export { MCPConversationToolset, createConversationToolset } from './mcp/conversationTools.js';
61
+ export type { MessageRole, ProblemSolvingPhase, ConversationMessage, ConversationMessageMetadata, ConversationThread, ConversationThreadMetadata, ConversationContext, RankedMessage, SaveMessageOptions, ContextRetrievalOptions, ConversationSearchOptions, ConversationSearchResult, ConversationTheme, ArtifactOptions, ConversationStats, CompactionOptions, CompactionResult } from './conversation/types.js';
package/dist/index.js CHANGED
@@ -118,4 +118,7 @@ export {
118
118
  BrainyMCPAdapter, MCPAugmentationToolset, BrainyMCPService,
119
119
  // MCP types
120
120
  MCPRequestType, MCP_VERSION };
121
+ // Export Conversation API (Infinite Agent Memory)
122
+ export { ConversationManager, createConversationManager } from './conversation/index.js';
123
+ export { MCPConversationToolset, createConversationToolset } from './mcp/conversationTools.js';
121
124
  //# sourceMappingURL=index.js.map
@@ -11,7 +11,7 @@
11
11
  * - Works both locally and with cloud deployment
12
12
  */
13
13
  import { BrainyMCPService } from './brainyMCPService.js';
14
- import { BrainyDataInterface } from '../types/brainyDataInterface.js';
14
+ import { BrainyInterface } from '../types/brainyDataInterface.js';
15
15
  import { MCPServiceOptions } from '../types/mcpTypes.js';
16
16
  interface BroadcastMessage {
17
17
  id: string;
@@ -28,7 +28,7 @@ export declare class BrainyMCPBroadcast extends BrainyMCPService {
28
28
  private agents;
29
29
  private messageHistory;
30
30
  private maxHistorySize;
31
- constructor(brainyData: BrainyDataInterface, options?: MCPServiceOptions & {
31
+ constructor(brainyData: BrainyInterface, options?: MCPServiceOptions & {
32
32
  broadcastPort?: number;
33
33
  cloudUrl?: string;
34
34
  });
@@ -11,7 +11,7 @@
11
11
  * - Works both locally and with cloud deployment
12
12
  */
13
13
  import { WebSocketServer, WebSocket } from 'ws';
14
- import { createServer } from 'http';
14
+ import { createServer } from 'node:http';
15
15
  import { BrainyMCPService } from './brainyMCPService.js';
16
16
  import { v4 as uuidv4 } from '../universal/uuid.js';
17
17
  export class BrainyMCPBroadcast extends BrainyMCPService {
@@ -5,7 +5,7 @@
5
5
  * Utilizes Brainy for persistent memory and vector search capabilities
6
6
  */
7
7
  import WebSocket from 'ws';
8
- import { BrainyData } from '../brainyData.js';
8
+ import { Brainy } from '../brainy.js';
9
9
  import { v4 as uuidv4 } from '../universal/uuid.js';
10
10
  export class BrainyMCPClient {
11
11
  constructor(options) {
@@ -23,7 +23,7 @@ export class BrainyMCPClient {
23
23
  */
24
24
  async initBrainy() {
25
25
  if (this.options.useBrainyMemory && !this.brainy) {
26
- this.brainy = new BrainyData({
26
+ this.brainy = new Brainy({
27
27
  storage: {
28
28
  requestPersistentStorage: true
29
29
  }
@@ -95,7 +95,8 @@ export class BrainyMCPClient {
95
95
  to: message.to,
96
96
  timestamp: message.timestamp,
97
97
  type: message.type,
98
- event: message.event
98
+ event: message.event,
99
+ category: 'Message'
99
100
  }
100
101
  });
101
102
  }
@@ -111,7 +112,10 @@ export class BrainyMCPClient {
111
112
  for (const histMsg of message.data.history) {
112
113
  await this.brainy.add({
113
114
  text: `${histMsg.from}: ${JSON.stringify(histMsg.data)}`,
114
- metadata: histMsg
115
+ metadata: {
116
+ ...histMsg,
117
+ category: 'Message'
118
+ }
115
119
  });
116
120
  }
117
121
  }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * MCP Conversation Tools
3
+ *
4
+ * Exposes ConversationManager functionality through MCP for Claude Code integration.
5
+ * Provides 6 tools for infinite agent memory.
6
+ *
7
+ * REAL IMPLEMENTATION - Uses ConversationManager which uses real Brainy APIs
8
+ */
9
+ import { MCPResponse, MCPToolExecutionRequest, MCPTool } from '../types/mcpTypes.js';
10
+ import { Brainy } from '../brainy.js';
11
+ /**
12
+ * MCP Conversation Toolset
13
+ *
14
+ * Provides conversation and context management tools for AI agents
15
+ */
16
+ export declare class MCPConversationToolset {
17
+ private brain;
18
+ private conversationManager;
19
+ private initialized;
20
+ /**
21
+ * Create MCP Conversation Toolset
22
+ * @param brain Brainy instance
23
+ */
24
+ constructor(brain: Brainy);
25
+ /**
26
+ * Initialize the toolset
27
+ */
28
+ init(): Promise<void>;
29
+ /**
30
+ * Handle MCP tool execution request
31
+ * @param request MCP tool execution request
32
+ * @returns MCP response
33
+ */
34
+ handleRequest(request: MCPToolExecutionRequest): Promise<MCPResponse>;
35
+ /**
36
+ * Get available conversation tools
37
+ * @returns Array of MCP tool definitions
38
+ */
39
+ getAvailableTools(): Promise<MCPTool[]>;
40
+ /**
41
+ * Handle save_message tool
42
+ * REAL: Uses ConversationManager.saveMessage()
43
+ */
44
+ private handleSaveMessage;
45
+ /**
46
+ * Handle get_context tool
47
+ * REAL: Uses ConversationManager.getRelevantContext()
48
+ */
49
+ private handleGetContext;
50
+ /**
51
+ * Handle search tool
52
+ * REAL: Uses ConversationManager.searchMessages()
53
+ */
54
+ private handleSearch;
55
+ /**
56
+ * Handle get_thread tool
57
+ * REAL: Uses ConversationManager.getConversationThread()
58
+ */
59
+ private handleGetThread;
60
+ /**
61
+ * Handle save_artifact tool
62
+ * REAL: Uses ConversationManager.saveArtifact()
63
+ */
64
+ private handleSaveArtifact;
65
+ /**
66
+ * Handle find_similar tool
67
+ * REAL: Uses ConversationManager.findSimilarConversations()
68
+ */
69
+ private handleFindSimilar;
70
+ /**
71
+ * Create success response
72
+ */
73
+ private createSuccessResponse;
74
+ /**
75
+ * Create error response
76
+ */
77
+ private createErrorResponse;
78
+ /**
79
+ * Generate request ID
80
+ */
81
+ generateRequestId(): string;
82
+ }
83
+ /**
84
+ * Create MCP conversation toolset
85
+ * @param brain Brainy instance
86
+ * @returns MCPConversationToolset instance
87
+ */
88
+ export declare function createConversationToolset(brain: Brainy): MCPConversationToolset;