@soulcraft/brainy 0.62.3 → 0.63.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/bin/brainy.js +276 -6
- package/dist/augmentationPipeline.d.ts +60 -0
- package/dist/augmentationPipeline.js +94 -0
- package/dist/augmentations/neuralImport.d.ts +199 -0
- package/dist/augmentations/neuralImport.js +750 -0
- package/dist/brainyData.d.ts +90 -5
- package/dist/brainyData.js +110 -5
- package/dist/chat/BrainyChat.d.ts +113 -0
- package/dist/chat/BrainyChat.js +374 -0
- package/dist/chat/ChatCLI.d.ts +61 -0
- package/dist/chat/ChatCLI.js +351 -0
- package/dist/connectors/interfaces/IConnector.d.ts +3 -3
- package/dist/connectors/interfaces/IConnector.js +1 -1
- package/dist/cortex/cortex-legacy.d.ts +5 -0
- package/dist/cortex/cortex-legacy.js +75 -15
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/shared/default-augmentations.d.ts +3 -3
- package/dist/shared/default-augmentations.js +10 -10
- package/package.json +1 -1
package/dist/brainyData.d.ts
CHANGED
|
@@ -532,18 +532,34 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
532
532
|
*/
|
|
533
533
|
connectToRemoteServer(serverUrl: string, protocols?: string | string[]): Promise<WebSocketConnection>;
|
|
534
534
|
/**
|
|
535
|
-
* Add
|
|
536
|
-
*
|
|
535
|
+
* Add data to the database (literal storage by default)
|
|
536
|
+
*
|
|
537
|
+
* 🔒 Safe by default: Only stores your data literally without AI processing
|
|
538
|
+
* 🧠 AI processing: Set { process: true } or use addSmart() for Neural Import
|
|
539
|
+
*
|
|
537
540
|
* @param vectorOrData Vector or data to add
|
|
538
|
-
* @param metadata Optional metadata to associate with the
|
|
539
|
-
* @param options Additional options
|
|
540
|
-
* @returns The ID of the added
|
|
541
|
+
* @param metadata Optional metadata to associate with the data
|
|
542
|
+
* @param options Additional options - use { process: true } for AI analysis
|
|
543
|
+
* @returns The ID of the added data
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* // Literal storage (safe, no AI processing)
|
|
547
|
+
* await brainy.add("API_KEY=secret123")
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* // With AI processing (explicit opt-in)
|
|
551
|
+
* await brainy.add("John works at Acme Corp", null, { process: true })
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* // Smart processing (recommended for data analysis)
|
|
555
|
+
* await brainy.addSmart("Customer feedback: Great product!")
|
|
541
556
|
*/
|
|
542
557
|
add(vectorOrData: Vector | any, metadata?: T, options?: {
|
|
543
558
|
forceEmbed?: boolean;
|
|
544
559
|
addToRemote?: boolean;
|
|
545
560
|
id?: string;
|
|
546
561
|
service?: string;
|
|
562
|
+
process?: boolean;
|
|
547
563
|
}): Promise<string>;
|
|
548
564
|
/**
|
|
549
565
|
* Add a text item to the database with automatic embedding
|
|
@@ -929,6 +945,26 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
929
945
|
* @private
|
|
930
946
|
*/
|
|
931
947
|
private adaptCacheConfiguration;
|
|
948
|
+
/**
|
|
949
|
+
* Add data with AI processing enabled by default
|
|
950
|
+
*
|
|
951
|
+
* 🧠 This method automatically enables Neural Import and other AI augmentations
|
|
952
|
+
* for intelligent data understanding, entity detection, and relationship analysis.
|
|
953
|
+
*
|
|
954
|
+
* Use this when you want AI to understand and process your data.
|
|
955
|
+
* Use regular add() when you want literal storage only.
|
|
956
|
+
*
|
|
957
|
+
* @param vectorOrData The data to add (any format)
|
|
958
|
+
* @param metadata Optional metadata to associate with the data
|
|
959
|
+
* @param options Additional options (process defaults to true)
|
|
960
|
+
* @returns The ID of the added data
|
|
961
|
+
*/
|
|
962
|
+
addSmart(vectorOrData: Vector | any, metadata?: T, options?: {
|
|
963
|
+
forceEmbed?: boolean;
|
|
964
|
+
addToRemote?: boolean;
|
|
965
|
+
id?: string;
|
|
966
|
+
service?: string;
|
|
967
|
+
}): Promise<string>;
|
|
932
968
|
/**
|
|
933
969
|
* Get the number of nouns in the database (excluding verbs)
|
|
934
970
|
* This is used for statistics reporting to match the expected behavior in tests
|
|
@@ -1342,5 +1378,54 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
1342
1378
|
* Exposed for Cortex reindex command
|
|
1343
1379
|
*/
|
|
1344
1380
|
rebuildMetadataIndex(): Promise<void>;
|
|
1381
|
+
/**
|
|
1382
|
+
* Enable an augmentation by name
|
|
1383
|
+
* Universal control for built-in, community, and premium augmentations
|
|
1384
|
+
*
|
|
1385
|
+
* @param name The name of the augmentation to enable
|
|
1386
|
+
* @returns True if augmentation was found and enabled
|
|
1387
|
+
*/
|
|
1388
|
+
enableAugmentation(name: string): boolean;
|
|
1389
|
+
/**
|
|
1390
|
+
* Disable an augmentation by name
|
|
1391
|
+
* Universal control for built-in, community, and premium augmentations
|
|
1392
|
+
*
|
|
1393
|
+
* @param name The name of the augmentation to disable
|
|
1394
|
+
* @returns True if augmentation was found and disabled
|
|
1395
|
+
*/
|
|
1396
|
+
disableAugmentation(name: string): boolean;
|
|
1397
|
+
/**
|
|
1398
|
+
* Check if an augmentation is enabled
|
|
1399
|
+
*
|
|
1400
|
+
* @param name The name of the augmentation to check
|
|
1401
|
+
* @returns True if augmentation is found and enabled, false otherwise
|
|
1402
|
+
*/
|
|
1403
|
+
isAugmentationEnabled(name: string): boolean;
|
|
1404
|
+
/**
|
|
1405
|
+
* Get all augmentations with their enabled status
|
|
1406
|
+
* Shows built-in, community, and premium augmentations
|
|
1407
|
+
*
|
|
1408
|
+
* @returns Array of augmentations with name, type, and enabled status
|
|
1409
|
+
*/
|
|
1410
|
+
listAugmentations(): Array<{
|
|
1411
|
+
name: string;
|
|
1412
|
+
type: string;
|
|
1413
|
+
enabled: boolean;
|
|
1414
|
+
description: string;
|
|
1415
|
+
}>;
|
|
1416
|
+
/**
|
|
1417
|
+
* Enable all augmentations of a specific type
|
|
1418
|
+
*
|
|
1419
|
+
* @param type The type of augmentations to enable (sense, conduit, cognition, etc.)
|
|
1420
|
+
* @returns Number of augmentations enabled
|
|
1421
|
+
*/
|
|
1422
|
+
enableAugmentationType(type: 'sense' | 'conduit' | 'cognition' | 'memory' | 'perception' | 'dialog' | 'activation' | 'webSocket'): number;
|
|
1423
|
+
/**
|
|
1424
|
+
* Disable all augmentations of a specific type
|
|
1425
|
+
*
|
|
1426
|
+
* @param type The type of augmentations to disable (sense, conduit, cognition, etc.)
|
|
1427
|
+
* @returns Number of augmentations disabled
|
|
1428
|
+
*/
|
|
1429
|
+
disableAugmentationType(type: 'sense' | 'conduit' | 'cognition' | 'memory' | 'perception' | 'dialog' | 'activation' | 'webSocket'): number;
|
|
1345
1430
|
}
|
|
1346
1431
|
export { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance } from './utils/index.js';
|
package/dist/brainyData.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { v4 as uuidv4 } from './universal/uuid.js';
|
|
6
6
|
import { HNSWIndex } from './hnsw/hnswIndex.js';
|
|
7
|
+
import { ExecutionMode } from './augmentationPipeline.js';
|
|
7
8
|
import { HNSWIndexOptimized } from './hnsw/hnswIndexOptimized.js';
|
|
8
9
|
import { createStorage } from './storage/storageFactory.js';
|
|
9
10
|
import { cosineDistance, defaultEmbeddingFunction, cleanupWorkerPools, batchEmbed } from './utils/index.js';
|
|
@@ -983,12 +984,27 @@ export class BrainyData {
|
|
|
983
984
|
}
|
|
984
985
|
}
|
|
985
986
|
/**
|
|
986
|
-
* Add
|
|
987
|
-
*
|
|
987
|
+
* Add data to the database (literal storage by default)
|
|
988
|
+
*
|
|
989
|
+
* 🔒 Safe by default: Only stores your data literally without AI processing
|
|
990
|
+
* 🧠 AI processing: Set { process: true } or use addSmart() for Neural Import
|
|
991
|
+
*
|
|
988
992
|
* @param vectorOrData Vector or data to add
|
|
989
|
-
* @param metadata Optional metadata to associate with the
|
|
990
|
-
* @param options Additional options
|
|
991
|
-
* @returns The ID of the added
|
|
993
|
+
* @param metadata Optional metadata to associate with the data
|
|
994
|
+
* @param options Additional options - use { process: true } for AI analysis
|
|
995
|
+
* @returns The ID of the added data
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* // Literal storage (safe, no AI processing)
|
|
999
|
+
* await brainy.add("API_KEY=secret123")
|
|
1000
|
+
*
|
|
1001
|
+
* @example
|
|
1002
|
+
* // With AI processing (explicit opt-in)
|
|
1003
|
+
* await brainy.add("John works at Acme Corp", null, { process: true })
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
1006
|
+
* // Smart processing (recommended for data analysis)
|
|
1007
|
+
* await brainy.addSmart("Customer feedback: Great product!")
|
|
992
1008
|
*/
|
|
993
1009
|
async add(vectorOrData, metadata, options = {}) {
|
|
994
1010
|
await this.ensureInitialized();
|
|
@@ -1246,6 +1262,20 @@ export class BrainyData {
|
|
|
1246
1262
|
}
|
|
1247
1263
|
// Invalidate search cache since data has changed
|
|
1248
1264
|
this.searchCache.invalidateOnDataChange('add');
|
|
1265
|
+
// 🧠 AI Processing (Neural Import) - Only if explicitly requested
|
|
1266
|
+
if (options.process === true) {
|
|
1267
|
+
try {
|
|
1268
|
+
// Execute SENSE pipeline (includes Neural Import and other AI augmentations)
|
|
1269
|
+
await augmentationPipeline.executeSensePipeline('processRawData', [vectorOrData, typeof vectorOrData === 'string' ? 'text' : 'data'], { mode: ExecutionMode.SEQUENTIAL });
|
|
1270
|
+
if (this.loggingConfig?.verbose) {
|
|
1271
|
+
console.log(`🧠 AI processing completed for data: ${id}`);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
catch (processingError) {
|
|
1275
|
+
// Don't fail the add operation if processing fails
|
|
1276
|
+
console.warn(`🧠 AI processing failed for ${id}:`, processingError);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1249
1279
|
return id;
|
|
1250
1280
|
}
|
|
1251
1281
|
catch (error) {
|
|
@@ -3145,6 +3175,24 @@ export class BrainyData {
|
|
|
3145
3175
|
}
|
|
3146
3176
|
}
|
|
3147
3177
|
}
|
|
3178
|
+
/**
|
|
3179
|
+
* Add data with AI processing enabled by default
|
|
3180
|
+
*
|
|
3181
|
+
* 🧠 This method automatically enables Neural Import and other AI augmentations
|
|
3182
|
+
* for intelligent data understanding, entity detection, and relationship analysis.
|
|
3183
|
+
*
|
|
3184
|
+
* Use this when you want AI to understand and process your data.
|
|
3185
|
+
* Use regular add() when you want literal storage only.
|
|
3186
|
+
*
|
|
3187
|
+
* @param vectorOrData The data to add (any format)
|
|
3188
|
+
* @param metadata Optional metadata to associate with the data
|
|
3189
|
+
* @param options Additional options (process defaults to true)
|
|
3190
|
+
* @returns The ID of the added data
|
|
3191
|
+
*/
|
|
3192
|
+
async addSmart(vectorOrData, metadata, options = {}) {
|
|
3193
|
+
// Call add() with process=true by default
|
|
3194
|
+
return this.add(vectorOrData, metadata, { ...options, process: true });
|
|
3195
|
+
}
|
|
3148
3196
|
/**
|
|
3149
3197
|
* Get the number of nouns in the database (excluding verbs)
|
|
3150
3198
|
* This is used for statistics reporting to match the expected behavior in tests
|
|
@@ -4817,6 +4865,63 @@ export class BrainyData {
|
|
|
4817
4865
|
await this.metadataIndex.rebuild();
|
|
4818
4866
|
}
|
|
4819
4867
|
}
|
|
4868
|
+
// ===== Augmentation Control Methods =====
|
|
4869
|
+
/**
|
|
4870
|
+
* Enable an augmentation by name
|
|
4871
|
+
* Universal control for built-in, community, and premium augmentations
|
|
4872
|
+
*
|
|
4873
|
+
* @param name The name of the augmentation to enable
|
|
4874
|
+
* @returns True if augmentation was found and enabled
|
|
4875
|
+
*/
|
|
4876
|
+
enableAugmentation(name) {
|
|
4877
|
+
return augmentationPipeline.enableAugmentation(name);
|
|
4878
|
+
}
|
|
4879
|
+
/**
|
|
4880
|
+
* Disable an augmentation by name
|
|
4881
|
+
* Universal control for built-in, community, and premium augmentations
|
|
4882
|
+
*
|
|
4883
|
+
* @param name The name of the augmentation to disable
|
|
4884
|
+
* @returns True if augmentation was found and disabled
|
|
4885
|
+
*/
|
|
4886
|
+
disableAugmentation(name) {
|
|
4887
|
+
return augmentationPipeline.disableAugmentation(name);
|
|
4888
|
+
}
|
|
4889
|
+
/**
|
|
4890
|
+
* Check if an augmentation is enabled
|
|
4891
|
+
*
|
|
4892
|
+
* @param name The name of the augmentation to check
|
|
4893
|
+
* @returns True if augmentation is found and enabled, false otherwise
|
|
4894
|
+
*/
|
|
4895
|
+
isAugmentationEnabled(name) {
|
|
4896
|
+
return augmentationPipeline.isAugmentationEnabled(name);
|
|
4897
|
+
}
|
|
4898
|
+
/**
|
|
4899
|
+
* Get all augmentations with their enabled status
|
|
4900
|
+
* Shows built-in, community, and premium augmentations
|
|
4901
|
+
*
|
|
4902
|
+
* @returns Array of augmentations with name, type, and enabled status
|
|
4903
|
+
*/
|
|
4904
|
+
listAugmentations() {
|
|
4905
|
+
return augmentationPipeline.listAugmentationsWithStatus();
|
|
4906
|
+
}
|
|
4907
|
+
/**
|
|
4908
|
+
* Enable all augmentations of a specific type
|
|
4909
|
+
*
|
|
4910
|
+
* @param type The type of augmentations to enable (sense, conduit, cognition, etc.)
|
|
4911
|
+
* @returns Number of augmentations enabled
|
|
4912
|
+
*/
|
|
4913
|
+
enableAugmentationType(type) {
|
|
4914
|
+
return augmentationPipeline.enableAugmentationType(type);
|
|
4915
|
+
}
|
|
4916
|
+
/**
|
|
4917
|
+
* Disable all augmentations of a specific type
|
|
4918
|
+
*
|
|
4919
|
+
* @param type The type of augmentations to disable (sense, conduit, cognition, etc.)
|
|
4920
|
+
* @returns Number of augmentations disabled
|
|
4921
|
+
*/
|
|
4922
|
+
disableAugmentationType(type) {
|
|
4923
|
+
return augmentationPipeline.disableAugmentationType(type);
|
|
4924
|
+
}
|
|
4820
4925
|
}
|
|
4821
4926
|
// Export distance functions for convenience
|
|
4822
4927
|
export { euclideanDistance, cosineDistance, manhattanDistance, dotProductDistance } from './utils/index.js';
|
|
@@ -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
|
+
}
|