@soulcraft/brainy 0.62.3 → 1.0.0-rc.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 (36) hide show
  1. package/README.md +3 -3
  2. package/bin/brainy.js +903 -1153
  3. package/dist/augmentationPipeline.d.ts +60 -0
  4. package/dist/augmentationPipeline.js +94 -0
  5. package/dist/augmentations/{cortexSense.d.ts → neuralImport.d.ts} +14 -11
  6. package/dist/augmentations/{cortexSense.js → neuralImport.js} +14 -11
  7. package/dist/brainyData.d.ts +199 -18
  8. package/dist/brainyData.js +601 -18
  9. package/dist/chat/BrainyChat.d.ts +113 -0
  10. package/dist/chat/BrainyChat.js +368 -0
  11. package/dist/chat/ChatCLI.d.ts +61 -0
  12. package/dist/chat/ChatCLI.js +351 -0
  13. package/dist/connectors/interfaces/IConnector.d.ts +3 -3
  14. package/dist/connectors/interfaces/IConnector.js +1 -1
  15. package/dist/cortex/neuralImport.js +1 -3
  16. package/dist/index.d.ts +4 -6
  17. package/dist/index.js +6 -7
  18. package/dist/pipeline.d.ts +15 -271
  19. package/dist/pipeline.js +25 -586
  20. package/dist/shared/default-augmentations.d.ts +3 -3
  21. package/dist/shared/default-augmentations.js +10 -10
  22. package/package.json +3 -1
  23. package/dist/chat/brainyChat.d.ts +0 -42
  24. package/dist/chat/brainyChat.js +0 -340
  25. package/dist/cortex/cliWrapper.d.ts +0 -32
  26. package/dist/cortex/cliWrapper.js +0 -209
  27. package/dist/cortex/cortex-legacy.d.ts +0 -264
  28. package/dist/cortex/cortex-legacy.js +0 -2463
  29. package/dist/cortex/cortex.d.ts +0 -264
  30. package/dist/cortex/cortex.js +0 -2463
  31. package/dist/cortex/serviceIntegration.d.ts +0 -156
  32. package/dist/cortex/serviceIntegration.js +0 -384
  33. package/dist/sequentialPipeline.d.ts +0 -113
  34. package/dist/sequentialPipeline.js +0 -417
  35. package/dist/utils/modelLoader.d.ts +0 -12
  36. package/dist/utils/modelLoader.js +0 -88
@@ -0,0 +1,113 @@
1
+ /**
2
+ * BrainyChat - Magical Chat Command Center
3
+ *
4
+ * A smart chat system that leverages Brainy's standard noun/verb types
5
+ * to create intelligent, persistent conversations with automatic context loading.
6
+ *
7
+ * Key Features:
8
+ * - Uses standard NounType.Message for all chat messages
9
+ * - Employs VerbType.Communicates and VerbType.Precedes for conversation flow
10
+ * - Auto-discovery of previous sessions using Brainy's search capabilities
11
+ * - Hybrid architecture: basic chat (open source) + premium memory sync
12
+ */
13
+ import { BrainyData } from '../brainyData.js';
14
+ export interface ChatMessage {
15
+ id: string;
16
+ content: string;
17
+ speaker: 'user' | 'assistant' | string;
18
+ sessionId: string;
19
+ timestamp: Date;
20
+ metadata?: {
21
+ model?: string;
22
+ usage?: {
23
+ prompt_tokens?: number;
24
+ completion_tokens?: number;
25
+ };
26
+ context?: Record<string, any>;
27
+ };
28
+ }
29
+ export interface ChatSession {
30
+ id: string;
31
+ title?: string;
32
+ createdAt: Date;
33
+ lastMessageAt: Date;
34
+ messageCount: number;
35
+ participants: string[];
36
+ metadata?: {
37
+ tags?: string[];
38
+ summary?: string;
39
+ archived?: boolean;
40
+ premium?: boolean;
41
+ };
42
+ }
43
+ /**
44
+ * Enhanced BrainyChat with automatic context loading and intelligent memory
45
+ *
46
+ * This extends basic chat functionality with premium features when available
47
+ */
48
+ export declare class BrainyChat {
49
+ private brainy;
50
+ private currentSessionId;
51
+ private sessionCache;
52
+ constructor(brainy: BrainyData);
53
+ /**
54
+ * Initialize chat system and auto-discover last session
55
+ * Uses Brainy's advanced search to find the most recent conversation
56
+ */
57
+ initialize(): Promise<ChatSession | null>;
58
+ /**
59
+ * Start a new chat session
60
+ * Automatically generates a session ID and stores session metadata
61
+ */
62
+ startNewSession(title?: string, participants?: string[]): Promise<ChatSession>;
63
+ /**
64
+ * Add a message to the current session
65
+ * Stores using standard NounType.Message and creates conversation flow relationships
66
+ */
67
+ addMessage(content: string, speaker?: string, metadata?: ChatMessage['metadata']): Promise<ChatMessage>;
68
+ /**
69
+ * Get conversation history for current session
70
+ * Uses Brainy's graph traversal to get messages in chronological order
71
+ */
72
+ getHistory(limit?: number): Promise<ChatMessage[]>;
73
+ /**
74
+ * Search across all chat sessions and messages
75
+ * Leverages Brainy's powerful vector and semantic search
76
+ */
77
+ searchMessages(query: string, options?: {
78
+ sessionId?: string;
79
+ speaker?: string;
80
+ limit?: number;
81
+ semanticSearch?: boolean;
82
+ }): Promise<ChatMessage[]>;
83
+ /**
84
+ * Get all chat sessions
85
+ * Uses Brainy's search to find all conversation sessions
86
+ */
87
+ getSessions(limit?: number): Promise<ChatSession[]>;
88
+ /**
89
+ * Switch to a different session
90
+ * Automatically loads context and history
91
+ */
92
+ switchToSession(sessionId: string): Promise<ChatSession | null>;
93
+ /**
94
+ * Archive a session (premium feature)
95
+ * Maintains full searchability while organizing conversations
96
+ */
97
+ archiveSession(sessionId: string): Promise<boolean>;
98
+ /**
99
+ * Generate session summary using AI (premium feature)
100
+ * Intelligently summarizes long conversations
101
+ */
102
+ generateSessionSummary(sessionId: string): Promise<string | null>;
103
+ private createMessageRelationships;
104
+ private loadSession;
105
+ private getHistoryForSession;
106
+ private updateSessionMetadata;
107
+ private nounToChatMessage;
108
+ private nounToChatSession;
109
+ private toTimestamp;
110
+ private isPremiumEnabled;
111
+ getCurrentSessionId(): string | null;
112
+ getCurrentSession(): ChatSession | null;
113
+ }
@@ -0,0 +1,368 @@
1
+ /**
2
+ * BrainyChat - Magical Chat Command Center
3
+ *
4
+ * A smart chat system that leverages Brainy's standard noun/verb types
5
+ * to create intelligent, persistent conversations with automatic context loading.
6
+ *
7
+ * Key Features:
8
+ * - Uses standard NounType.Message for all chat messages
9
+ * - Employs VerbType.Communicates and VerbType.Precedes for conversation flow
10
+ * - Auto-discovery of previous sessions using Brainy's search capabilities
11
+ * - Hybrid architecture: basic chat (open source) + premium memory sync
12
+ */
13
+ import { NounType, VerbType } from '../types/graphTypes.js';
14
+ /**
15
+ * Enhanced BrainyChat with automatic context loading and intelligent memory
16
+ *
17
+ * This extends basic chat functionality with premium features when available
18
+ */
19
+ export class BrainyChat {
20
+ constructor(brainy) {
21
+ this.currentSessionId = null;
22
+ this.sessionCache = new Map();
23
+ this.brainy = brainy;
24
+ }
25
+ /**
26
+ * Initialize chat system and auto-discover last session
27
+ * Uses Brainy's advanced search to find the most recent conversation
28
+ */
29
+ async initialize() {
30
+ try {
31
+ // Search for the most recent chat message using Brainy's search
32
+ const recentMessages = await this.brainy.search('recent chat conversation', 1, {
33
+ nounTypes: [NounType.Message],
34
+ metadata: {
35
+ messageType: 'chat'
36
+ }
37
+ });
38
+ if (recentMessages.length > 0) {
39
+ const lastMessage = recentMessages[0];
40
+ const sessionId = lastMessage.metadata?.sessionId;
41
+ if (sessionId) {
42
+ this.currentSessionId = sessionId;
43
+ return await this.loadSession(sessionId);
44
+ }
45
+ }
46
+ }
47
+ catch (error) {
48
+ console.debug('No previous session found, starting fresh:', error?.message);
49
+ }
50
+ return null;
51
+ }
52
+ /**
53
+ * Start a new chat session
54
+ * Automatically generates a session ID and stores session metadata
55
+ */
56
+ async startNewSession(title, participants = ['user', 'assistant']) {
57
+ const sessionId = `chat-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
58
+ const session = {
59
+ id: sessionId,
60
+ title,
61
+ createdAt: new Date(),
62
+ lastMessageAt: new Date(),
63
+ messageCount: 0,
64
+ participants,
65
+ metadata: {
66
+ tags: ['active'],
67
+ premium: await this.isPremiumEnabled()
68
+ }
69
+ };
70
+ // Store session using BrainyData add() method
71
+ await this.brainy.add({
72
+ sessionType: 'chat',
73
+ title: title || `Chat Session ${new Date().toLocaleDateString()}`,
74
+ createdAt: session.createdAt.toISOString(),
75
+ lastMessageAt: session.lastMessageAt.toISOString(),
76
+ messageCount: session.messageCount,
77
+ participants: session.participants
78
+ }, {
79
+ id: sessionId,
80
+ nounType: NounType.Concept,
81
+ sessionType: 'chat'
82
+ });
83
+ this.currentSessionId = sessionId;
84
+ this.sessionCache.set(sessionId, session);
85
+ return session;
86
+ }
87
+ /**
88
+ * Add a message to the current session
89
+ * Stores using standard NounType.Message and creates conversation flow relationships
90
+ */
91
+ async addMessage(content, speaker = 'user', metadata) {
92
+ if (!this.currentSessionId) {
93
+ await this.startNewSession();
94
+ }
95
+ const messageId = `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
96
+ const timestamp = new Date();
97
+ const message = {
98
+ id: messageId,
99
+ content,
100
+ speaker,
101
+ sessionId: this.currentSessionId,
102
+ timestamp,
103
+ metadata
104
+ };
105
+ // Store message using BrainyData add() method
106
+ await this.brainy.add({
107
+ messageType: 'chat',
108
+ content,
109
+ speaker,
110
+ sessionId: this.currentSessionId,
111
+ timestamp: timestamp.toISOString(),
112
+ ...metadata
113
+ }, {
114
+ id: messageId,
115
+ nounType: NounType.Message,
116
+ messageType: 'chat',
117
+ sessionId: this.currentSessionId,
118
+ speaker
119
+ });
120
+ // Create relationships using standard verb types
121
+ await this.createMessageRelationships(messageId);
122
+ // Update session metadata
123
+ await this.updateSessionMetadata();
124
+ return message;
125
+ }
126
+ /**
127
+ * Get conversation history for current session
128
+ * Uses Brainy's graph traversal to get messages in chronological order
129
+ */
130
+ async getHistory(limit = 50) {
131
+ if (!this.currentSessionId)
132
+ return [];
133
+ try {
134
+ // Search for messages in this session using Brainy's search
135
+ const messageNouns = await this.brainy.search('', // Empty query to get all messages
136
+ limit, {
137
+ nounTypes: [NounType.Message],
138
+ metadata: {
139
+ sessionId: this.currentSessionId,
140
+ messageType: 'chat'
141
+ }
142
+ });
143
+ return messageNouns.map((noun) => this.nounToChatMessage(noun));
144
+ }
145
+ catch (error) {
146
+ console.error('Error retrieving chat history:', error);
147
+ return [];
148
+ }
149
+ }
150
+ /**
151
+ * Search across all chat sessions and messages
152
+ * Leverages Brainy's powerful vector and semantic search
153
+ */
154
+ async searchMessages(query, options) {
155
+ const metadata = {
156
+ messageType: 'chat'
157
+ };
158
+ if (options?.sessionId) {
159
+ metadata.sessionId = options.sessionId;
160
+ }
161
+ if (options?.speaker) {
162
+ metadata.speaker = options.speaker;
163
+ }
164
+ try {
165
+ const results = await this.brainy.search(options?.semanticSearch !== false ? query : '', options?.limit || 20, {
166
+ nounTypes: [NounType.Message],
167
+ metadata
168
+ });
169
+ return results.map((noun) => this.nounToChatMessage(noun));
170
+ }
171
+ catch (error) {
172
+ console.error('Error searching messages:', error);
173
+ return [];
174
+ }
175
+ }
176
+ /**
177
+ * Get all chat sessions
178
+ * Uses Brainy's search to find all conversation sessions
179
+ */
180
+ async getSessions(limit = 20) {
181
+ try {
182
+ const sessionNouns = await this.brainy.search('', limit, {
183
+ nounTypes: [NounType.Concept],
184
+ metadata: {
185
+ sessionType: 'chat'
186
+ }
187
+ });
188
+ return sessionNouns.map((noun) => this.nounToChatSession(noun));
189
+ }
190
+ catch (error) {
191
+ console.error('Error retrieving sessions:', error);
192
+ return [];
193
+ }
194
+ }
195
+ /**
196
+ * Switch to a different session
197
+ * Automatically loads context and history
198
+ */
199
+ async switchToSession(sessionId) {
200
+ try {
201
+ const session = await this.loadSession(sessionId);
202
+ if (session) {
203
+ this.currentSessionId = sessionId;
204
+ this.sessionCache.set(sessionId, session);
205
+ }
206
+ return session;
207
+ }
208
+ catch (error) {
209
+ console.error('Error switching to session:', error);
210
+ return null;
211
+ }
212
+ }
213
+ /**
214
+ * Archive a session (premium feature)
215
+ * Maintains full searchability while organizing conversations
216
+ */
217
+ async archiveSession(sessionId) {
218
+ if (!await this.isPremiumEnabled()) {
219
+ throw new Error('Session archiving requires premium Brain Cloud subscription');
220
+ }
221
+ try {
222
+ // Since BrainyData doesn't have update, add an archive marker
223
+ await this.brainy.add({
224
+ archivedSessionId: sessionId,
225
+ archivedAt: new Date().toISOString(),
226
+ action: 'archive'
227
+ }, {
228
+ nounType: NounType.State,
229
+ sessionId,
230
+ archived: true
231
+ });
232
+ return true;
233
+ }
234
+ catch (error) {
235
+ console.error('Error archiving session:', error);
236
+ }
237
+ return false;
238
+ }
239
+ /**
240
+ * Generate session summary using AI (premium feature)
241
+ * Intelligently summarizes long conversations
242
+ */
243
+ async generateSessionSummary(sessionId) {
244
+ if (!await this.isPremiumEnabled()) {
245
+ throw new Error('AI session summaries require premium Brain Cloud subscription');
246
+ }
247
+ try {
248
+ const messages = await this.getHistoryForSession(sessionId, 100);
249
+ const content = messages
250
+ .map(msg => `${msg.speaker}: ${msg.content}`)
251
+ .join('\n');
252
+ // Use Brainy's AI to generate summary (placeholder - would need actual AI integration)
253
+ const summaryResponse = `Summary of ${messages.length} messages discussing various topics in ${sessionId}`;
254
+ return summaryResponse || null;
255
+ }
256
+ catch (error) {
257
+ console.error('Error generating session summary:', error);
258
+ return null;
259
+ }
260
+ }
261
+ // Private helper methods
262
+ async createMessageRelationships(messageId) {
263
+ // Link message to session using unified addVerb API
264
+ await this.brainy.addVerb(messageId, this.currentSessionId, VerbType.PartOf, {
265
+ relationship: 'message-in-session'
266
+ });
267
+ // Find previous message to create conversation flow using VerbType.Precedes
268
+ const previousMessages = await this.brainy.search('', 1, {
269
+ nounTypes: [NounType.Message],
270
+ metadata: {
271
+ sessionId: this.currentSessionId,
272
+ messageType: 'chat'
273
+ }
274
+ });
275
+ if (previousMessages.length > 0 && previousMessages[0].id !== messageId) {
276
+ await this.brainy.addVerb(previousMessages[0].id, messageId, VerbType.Precedes, {
277
+ relationship: 'message-sequence'
278
+ });
279
+ }
280
+ }
281
+ async loadSession(sessionId) {
282
+ try {
283
+ const sessionNouns = await this.brainy.search('', 1, {
284
+ nounTypes: [NounType.Concept],
285
+ metadata: {
286
+ sessionType: 'chat'
287
+ }
288
+ });
289
+ // Filter by session ID manually since BrainyData search may not support ID filtering
290
+ const matchingSession = sessionNouns.find(noun => noun.id === sessionId);
291
+ if (matchingSession) {
292
+ return this.nounToChatSession(matchingSession);
293
+ }
294
+ }
295
+ catch (error) {
296
+ console.error('Error loading session:', error);
297
+ }
298
+ return null;
299
+ }
300
+ async getHistoryForSession(sessionId, limit = 50) {
301
+ try {
302
+ const messageNouns = await this.brainy.search('', limit, {
303
+ nounTypes: [NounType.Message],
304
+ metadata: {
305
+ sessionId: sessionId,
306
+ messageType: 'chat'
307
+ }
308
+ });
309
+ return messageNouns.map((noun) => this.nounToChatMessage(noun));
310
+ }
311
+ catch (error) {
312
+ console.error('Error retrieving session history:', error);
313
+ return [];
314
+ }
315
+ }
316
+ async updateSessionMetadata() {
317
+ if (!this.currentSessionId)
318
+ return;
319
+ // Since BrainyData doesn't have update functionality, we'll skip this
320
+ // In a real implementation, you'd need update capabilities
321
+ console.debug('Session metadata update skipped - BrainyData lacks update API');
322
+ }
323
+ nounToChatMessage(noun) {
324
+ return {
325
+ id: noun.id,
326
+ content: noun.metadata?.content || noun.data?.content || '',
327
+ speaker: noun.metadata?.speaker || noun.data?.speaker || 'unknown',
328
+ sessionId: noun.metadata?.sessionId || noun.data?.sessionId || '',
329
+ timestamp: new Date(noun.metadata?.timestamp || noun.data?.timestamp || Date.now()),
330
+ metadata: noun.metadata
331
+ };
332
+ }
333
+ nounToChatSession(noun) {
334
+ return {
335
+ id: noun.id,
336
+ title: noun.metadata?.title || noun.data?.title || 'Untitled Session',
337
+ createdAt: new Date(noun.metadata?.createdAt || noun.data?.createdAt || Date.now()),
338
+ lastMessageAt: new Date(noun.metadata?.lastMessageAt || noun.data?.lastMessageAt || Date.now()),
339
+ messageCount: noun.metadata?.messageCount || noun.data?.messageCount || 0,
340
+ participants: noun.metadata?.participants || noun.data?.participants || ['user', 'assistant'],
341
+ metadata: noun.metadata
342
+ };
343
+ }
344
+ toTimestamp(date) {
345
+ const seconds = Math.floor(date.getTime() / 1000);
346
+ const nanoseconds = (date.getTime() % 1000) * 1000000;
347
+ return { seconds, nanoseconds };
348
+ }
349
+ async isPremiumEnabled() {
350
+ // Check if premium augmentations are available
351
+ // This would integrate with the license validation system
352
+ try {
353
+ const augmentations = await this.brainy.listAugmentations();
354
+ return augmentations.some((aug) => aug.premium === true && aug.enabled === true);
355
+ }
356
+ catch {
357
+ return false;
358
+ }
359
+ }
360
+ // Public API methods for CLI integration
361
+ getCurrentSessionId() {
362
+ return this.currentSessionId;
363
+ }
364
+ getCurrentSession() {
365
+ return this.currentSessionId ? this.sessionCache.get(this.currentSessionId) || null : null;
366
+ }
367
+ }
368
+ //# sourceMappingURL=BrainyChat.js.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * ChatCLI - Command Line Interface for BrainyChat
3
+ *
4
+ * Provides a magical chat experience through the Brainy CLI with:
5
+ * - Auto-discovery of previous sessions
6
+ * - Intelligent context loading
7
+ * - Multi-agent coordination support
8
+ * - Premium memory sync integration
9
+ */
10
+ import { type ChatMessage } from './BrainyChat.js';
11
+ import { BrainyData } from '../brainyData.js';
12
+ export declare class ChatCLI {
13
+ private brainyChat;
14
+ private brainy;
15
+ constructor(brainy: BrainyData);
16
+ /**
17
+ * Start an interactive chat session
18
+ * Automatically discovers and loads previous context
19
+ */
20
+ startInteractiveChat(options?: {
21
+ sessionId?: string;
22
+ speaker?: string;
23
+ memory?: boolean;
24
+ newSession?: boolean;
25
+ }): Promise<void>;
26
+ /**
27
+ * Send a single message and get response
28
+ */
29
+ sendMessage(message: string, options?: {
30
+ sessionId?: string;
31
+ speaker?: string;
32
+ noResponse?: boolean;
33
+ }): Promise<ChatMessage[]>;
34
+ /**
35
+ * Show conversation history
36
+ */
37
+ showHistory(limit?: number): Promise<void>;
38
+ /**
39
+ * Search across all conversations
40
+ */
41
+ searchConversations(query: string, options?: {
42
+ limit?: number;
43
+ sessionId?: string;
44
+ semantic?: boolean;
45
+ }): Promise<void>;
46
+ /**
47
+ * List all chat sessions
48
+ */
49
+ listSessions(): Promise<void>;
50
+ /**
51
+ * Switch to a different session
52
+ */
53
+ switchSession(sessionId: string): Promise<void>;
54
+ /**
55
+ * Show help for chat commands
56
+ */
57
+ showHelp(): void;
58
+ private interactiveLoop;
59
+ private showRecentContext;
60
+ private generateResponse;
61
+ }