@soulcraft/brainy 3.9.1 → 3.10.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.
- package/README.md +64 -6
- package/dist/augmentations/KnowledgeAugmentation.d.ts +40 -0
- package/dist/augmentations/KnowledgeAugmentation.js +251 -0
- package/dist/augmentations/defaultAugmentations.d.ts +1 -0
- package/dist/augmentations/defaultAugmentations.js +5 -0
- package/dist/brainy.d.ts +11 -0
- package/dist/brainy.js +87 -1
- package/dist/embeddings/EmbeddingManager.js +14 -2
- package/dist/utils/mutex.d.ts +2 -0
- package/dist/utils/mutex.js +14 -3
- package/dist/vfs/ConceptSystem.d.ts +203 -0
- package/dist/vfs/ConceptSystem.js +545 -0
- package/dist/vfs/EntityManager.d.ts +75 -0
- package/dist/vfs/EntityManager.js +216 -0
- package/dist/vfs/EventRecorder.d.ts +84 -0
- package/dist/vfs/EventRecorder.js +269 -0
- package/dist/vfs/FSCompat.d.ts +85 -0
- package/dist/vfs/FSCompat.js +257 -0
- package/dist/vfs/GitBridge.d.ts +167 -0
- package/dist/vfs/GitBridge.js +537 -0
- package/dist/vfs/KnowledgeAugmentation.d.ts +104 -0
- package/dist/vfs/KnowledgeAugmentation.js +146 -0
- package/dist/vfs/KnowledgeLayer.d.ts +35 -0
- package/dist/vfs/KnowledgeLayer.js +443 -0
- package/dist/vfs/PathResolver.d.ts +96 -0
- package/dist/vfs/PathResolver.js +362 -0
- package/dist/vfs/PersistentEntitySystem.d.ts +165 -0
- package/dist/vfs/PersistentEntitySystem.js +503 -0
- package/dist/vfs/SemanticVersioning.d.ts +105 -0
- package/dist/vfs/SemanticVersioning.js +309 -0
- package/dist/vfs/VirtualFileSystem.d.ts +246 -0
- package/dist/vfs/VirtualFileSystem.js +1928 -0
- package/dist/vfs/importers/DirectoryImporter.d.ts +86 -0
- package/dist/vfs/importers/DirectoryImporter.js +298 -0
- package/dist/vfs/index.d.ts +19 -0
- package/dist/vfs/index.js +26 -0
- package/dist/vfs/streams/VFSReadStream.d.ts +19 -0
- package/dist/vfs/streams/VFSReadStream.js +54 -0
- package/dist/vfs/streams/VFSWriteStream.d.ts +21 -0
- package/dist/vfs/streams/VFSWriteStream.js +70 -0
- package/dist/vfs/types.d.ts +330 -0
- package/dist/vfs/types.js +46 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://www.typescriptlang.org/)
|
|
11
11
|
|
|
12
|
-
**🧠 Brainy -
|
|
12
|
+
**🧠 Brainy - The Knowledge Operating System**
|
|
13
13
|
|
|
14
|
-
**
|
|
14
|
+
**The world's first Knowledge Operating System** where every piece of knowledge - files, concepts, entities, ideas - exists as living information that understands itself, evolves over time, and connects to everything related. Built on revolutionary Triple Intelligence™ that unifies vector similarity, graph relationships, and document filtering in one magical API.
|
|
15
15
|
|
|
16
|
-
**Why Brainy
|
|
16
|
+
**Why Brainy Changes Everything**: Traditional systems trap knowledge in files or database rows. Brainy liberates it. Your characters exist across stories. Your concepts span projects. Your APIs remember their evolution. Every piece of knowledge - whether it's code, prose, or pure ideas - lives, breathes, and connects in a unified intelligence layer where everything understands its meaning, remembers its history, and relates to everything else.
|
|
17
17
|
|
|
18
18
|
**Framework-first design.** Built for modern web development with zero configuration and automatic framework compatibility. O(log n) performance, <10ms search latency, production-ready.
|
|
19
19
|
|
|
@@ -182,7 +182,7 @@ If using nvm: `nvm use` (we provide a `.nvmrc` file)
|
|
|
182
182
|
|
|
183
183
|
### World's First Triple Intelligence™ Engine
|
|
184
184
|
|
|
185
|
-
**The breakthrough that enables
|
|
185
|
+
**The breakthrough that enables The Knowledge Operating System:**
|
|
186
186
|
|
|
187
187
|
- **Vector Search**: Semantic similarity with HNSW indexing
|
|
188
188
|
- **Graph Relationships**: Navigate connected knowledge like Neo4j
|
|
@@ -190,7 +190,7 @@ If using nvm: `nvm use` (we provide a `.nvmrc` file)
|
|
|
190
190
|
- **Unified in ONE API**: No separate queries, no complex joins
|
|
191
191
|
- **First to solve this**: Others do vector OR graph OR document—we do ALL
|
|
192
192
|
|
|
193
|
-
###
|
|
193
|
+
### The Knowledge Operating System with Infinite Expressiveness
|
|
194
194
|
|
|
195
195
|
**Enabled by Triple Intelligence, standardized for everyone:**
|
|
196
196
|
|
|
@@ -209,6 +209,56 @@ await brain.find("Popular JavaScript libraries similar to Vue")
|
|
|
209
209
|
await brain.find("Documentation about authentication from last month")
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
+
### 🧠🌐 **Knowledge Graph + Virtual Filesystem - Where Ideas Come Alive**
|
|
213
|
+
|
|
214
|
+
**Store ANY knowledge. Connect EVERYTHING. Files are optional.**
|
|
215
|
+
|
|
216
|
+
- **Living Knowledge**: Characters, concepts, and systems that exist independently of files
|
|
217
|
+
- **Universal Connections**: Link files to entities, entities to concepts, anything to anything
|
|
218
|
+
- **Semantic Intelligence**: Find knowledge by meaning, not by where it's stored
|
|
219
|
+
- **Optional Files**: Use filesystem operations when helpful, pure knowledge when not
|
|
220
|
+
- **Perfect Memory**: Every piece of knowledge remembers its entire history
|
|
221
|
+
- **Knowledge Evolution**: Watch ideas grow and connect across time and projects
|
|
222
|
+
|
|
223
|
+
```javascript
|
|
224
|
+
import { Brainy } from '@soulcraft/brainy'
|
|
225
|
+
|
|
226
|
+
const brain = new Brainy({ storage: { type: 'memory' } })
|
|
227
|
+
await brain.init()
|
|
228
|
+
const vfs = brain.vfs()
|
|
229
|
+
await vfs.init()
|
|
230
|
+
|
|
231
|
+
// Start with familiar files if you want
|
|
232
|
+
await vfs.writeFile('/story.txt', 'A tale of adventure...')
|
|
233
|
+
|
|
234
|
+
// But knowledge doesn't need files!
|
|
235
|
+
const alice = await vfs.createEntity({
|
|
236
|
+
name: 'Alice',
|
|
237
|
+
type: 'character',
|
|
238
|
+
description: 'Brave explorer discovering quantum worlds'
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const quantumPhysics = await vfs.createConcept({
|
|
242
|
+
name: 'Quantum Entanglement',
|
|
243
|
+
domain: 'physics',
|
|
244
|
+
keywords: ['superposition', 'measurement', 'correlation']
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
// Connect EVERYTHING - files, entities, concepts
|
|
248
|
+
await vfs.linkEntities(alice, quantumPhysics, 'studies')
|
|
249
|
+
await vfs.addRelationship('/story.txt', alice.id, 'features')
|
|
250
|
+
|
|
251
|
+
// Find knowledge by meaning, not location
|
|
252
|
+
const physics = await vfs.search('quantum mechanics')
|
|
253
|
+
// Returns: files, entities, concepts, relationships - ALL knowledge
|
|
254
|
+
|
|
255
|
+
// Knowledge transcends boundaries
|
|
256
|
+
const aliceKnowledge = await vfs.getEntityGraph(alice)
|
|
257
|
+
// Her relationships, appearances, evolution - her entire existence
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Your knowledge isn't trapped anymore.** Characters live beyond stories. APIs exist beyond code files. Concepts connect across domains. This is knowledge that happens to support files, not a filesystem that happens to store knowledge.
|
|
261
|
+
|
|
212
262
|
### 🎯 Zero Configuration Philosophy
|
|
213
263
|
|
|
214
264
|
Brainy automatically configures **everything**:
|
|
@@ -661,7 +711,7 @@ Key changes in the latest version:
|
|
|
661
711
|
|
|
662
712
|
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
663
713
|
|
|
664
|
-
## 🧠 The
|
|
714
|
+
## 🧠 The Knowledge Operating System Explained
|
|
665
715
|
|
|
666
716
|
### How We Achieved The Impossible
|
|
667
717
|
|
|
@@ -706,6 +756,14 @@ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
|
706
756
|
- [Next.js Integration](docs/guides/nextjs-integration.md) - **NEW!** React and Next.js examples
|
|
707
757
|
- [Vue.js Integration](docs/guides/vue-integration.md) - **NEW!** Vue and Nuxt examples
|
|
708
758
|
|
|
759
|
+
### Virtual Filesystem & Knowledge Layer 🧠📁
|
|
760
|
+
- [VFS Core Documentation](docs/vfs/VFS_CORE.md) - **NEW!** Complete filesystem architecture and API
|
|
761
|
+
- [VFS + Knowledge Layer](docs/vfs/VFS_KNOWLEDGE_LAYER.md) - **NEW!** Intelligent knowledge management features
|
|
762
|
+
- [Examples & Scenarios](docs/vfs/VFS_EXAMPLES_SCENARIOS.md) - **NEW!** Real-world use cases and code
|
|
763
|
+
- [VFS API Guide](docs/vfs/VFS_API_GUIDE.md) - Complete API reference
|
|
764
|
+
- [Knowledge Layer API](docs/vfs/KNOWLEDGE_LAYER_API.md) - Advanced knowledge features
|
|
765
|
+
- [Knowledge Layer Overview](docs/KNOWLEDGE_LAYER_OVERVIEW.md) - Non-technical guide
|
|
766
|
+
|
|
709
767
|
### Core Documentation
|
|
710
768
|
- [Getting Started Guide](docs/guides/getting-started.md)
|
|
711
769
|
- [API Reference](docs/api/README.md)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Layer Augmentation for VFS
|
|
3
|
+
*
|
|
4
|
+
* Adds intelligent features to VFS without modifying core functionality:
|
|
5
|
+
* - Event recording for all operations
|
|
6
|
+
* - Semantic versioning based on content changes
|
|
7
|
+
* - Entity and concept extraction
|
|
8
|
+
* - Git bridge for import/export
|
|
9
|
+
*
|
|
10
|
+
* This is a TRUE augmentation - VFS works perfectly without it
|
|
11
|
+
*/
|
|
12
|
+
import { Brainy } from '../brainy.js';
|
|
13
|
+
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
14
|
+
export declare class KnowledgeAugmentation extends BaseAugmentation {
|
|
15
|
+
name: string;
|
|
16
|
+
timing: 'after';
|
|
17
|
+
metadata: 'none';
|
|
18
|
+
operations: any;
|
|
19
|
+
priority: number;
|
|
20
|
+
constructor(config?: any);
|
|
21
|
+
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
22
|
+
private eventRecorder?;
|
|
23
|
+
private semanticVersioning?;
|
|
24
|
+
private entitySystem?;
|
|
25
|
+
private conceptSystem?;
|
|
26
|
+
private gitBridge?;
|
|
27
|
+
private originalMethods;
|
|
28
|
+
initialize(context: any): Promise<void>;
|
|
29
|
+
augment(brain: Brainy): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Wrap a VFS method to add Knowledge Layer functionality
|
|
32
|
+
*/
|
|
33
|
+
private wrapMethod;
|
|
34
|
+
/**
|
|
35
|
+
* Add Knowledge Layer methods to VFS
|
|
36
|
+
*/
|
|
37
|
+
private addKnowledgeMethods;
|
|
38
|
+
private isSemanticChange;
|
|
39
|
+
cleanup(brain: Brainy): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Layer Augmentation for VFS
|
|
3
|
+
*
|
|
4
|
+
* Adds intelligent features to VFS without modifying core functionality:
|
|
5
|
+
* - Event recording for all operations
|
|
6
|
+
* - Semantic versioning based on content changes
|
|
7
|
+
* - Entity and concept extraction
|
|
8
|
+
* - Git bridge for import/export
|
|
9
|
+
*
|
|
10
|
+
* This is a TRUE augmentation - VFS works perfectly without it
|
|
11
|
+
*/
|
|
12
|
+
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
13
|
+
import { EventRecorder } from '../vfs/EventRecorder.js';
|
|
14
|
+
import { SemanticVersioning } from '../vfs/SemanticVersioning.js';
|
|
15
|
+
import { PersistentEntitySystem } from '../vfs/PersistentEntitySystem.js';
|
|
16
|
+
import { ConceptSystem } from '../vfs/ConceptSystem.js';
|
|
17
|
+
import { GitBridge } from '../vfs/GitBridge.js';
|
|
18
|
+
export class KnowledgeAugmentation extends BaseAugmentation {
|
|
19
|
+
constructor(config = {}) {
|
|
20
|
+
super(config);
|
|
21
|
+
this.name = 'knowledge';
|
|
22
|
+
this.timing = 'after'; // Process after VFS operations
|
|
23
|
+
this.metadata = 'none'; // No metadata access needed
|
|
24
|
+
this.operations = []; // VFS-specific augmentation, no operation interception
|
|
25
|
+
this.priority = 100; // Run last
|
|
26
|
+
this.originalMethods = new Map();
|
|
27
|
+
}
|
|
28
|
+
async execute(operation, params, next) {
|
|
29
|
+
// Pass through - this augmentation works at VFS level, not operation level
|
|
30
|
+
return await next();
|
|
31
|
+
}
|
|
32
|
+
async initialize(context) {
|
|
33
|
+
await this.augment(context.brain);
|
|
34
|
+
}
|
|
35
|
+
async augment(brain) {
|
|
36
|
+
// Only augment if VFS exists
|
|
37
|
+
const vfs = brain.vfs?.();
|
|
38
|
+
if (!vfs) {
|
|
39
|
+
console.warn('KnowledgeAugmentation: VFS not found, skipping');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Initialize Knowledge Layer components
|
|
43
|
+
this.eventRecorder = new EventRecorder(brain);
|
|
44
|
+
this.semanticVersioning = new SemanticVersioning(brain);
|
|
45
|
+
this.entitySystem = new PersistentEntitySystem(brain);
|
|
46
|
+
this.conceptSystem = new ConceptSystem(brain);
|
|
47
|
+
this.gitBridge = new GitBridge(vfs, brain);
|
|
48
|
+
// Wrap VFS methods to add intelligence WITHOUT slowing them down
|
|
49
|
+
this.wrapMethod(vfs, 'writeFile', async (original, path, data, options) => {
|
|
50
|
+
// Call original first (stays fast)
|
|
51
|
+
const result = await original.call(vfs, path, data, options);
|
|
52
|
+
// Knowledge processing in background (non-blocking)
|
|
53
|
+
setImmediate(async () => {
|
|
54
|
+
try {
|
|
55
|
+
// Record event
|
|
56
|
+
if (this.eventRecorder) {
|
|
57
|
+
await this.eventRecorder.recordEvent({
|
|
58
|
+
type: 'write',
|
|
59
|
+
path,
|
|
60
|
+
content: data,
|
|
61
|
+
size: data.length,
|
|
62
|
+
author: options?.author || 'system'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Check for semantic versioning
|
|
66
|
+
if (this.semanticVersioning) {
|
|
67
|
+
const existingContent = await vfs.readFile(path).catch(() => null);
|
|
68
|
+
const shouldVersion = existingContent && this.isSemanticChange(existingContent, data);
|
|
69
|
+
if (shouldVersion) {
|
|
70
|
+
await this.semanticVersioning.createVersion(path, data, {
|
|
71
|
+
message: 'Automatic semantic version'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Extract concepts
|
|
76
|
+
if (this.conceptSystem && options?.extractConcepts !== false) {
|
|
77
|
+
await this.conceptSystem.extractAndLinkConcepts(path, data);
|
|
78
|
+
}
|
|
79
|
+
// Extract entities
|
|
80
|
+
if (this.entitySystem && options?.extractEntities !== false) {
|
|
81
|
+
await this.entitySystem.extractEntities(data.toString('utf8'), data);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Knowledge Layer errors should not affect VFS operations
|
|
86
|
+
console.debug('KnowledgeLayer background processing error:', error);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return result;
|
|
90
|
+
});
|
|
91
|
+
this.wrapMethod(vfs, 'unlink', async (original, path) => {
|
|
92
|
+
const result = await original.call(vfs, path);
|
|
93
|
+
// Record deletion event
|
|
94
|
+
setImmediate(async () => {
|
|
95
|
+
if (this.eventRecorder) {
|
|
96
|
+
await this.eventRecorder.recordEvent({
|
|
97
|
+
type: 'delete',
|
|
98
|
+
path,
|
|
99
|
+
author: 'system'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
this.wrapMethod(vfs, 'rename', async (original, oldPath, newPath) => {
|
|
106
|
+
const result = await original.call(vfs, oldPath, newPath);
|
|
107
|
+
// Record rename event
|
|
108
|
+
setImmediate(async () => {
|
|
109
|
+
if (this.eventRecorder) {
|
|
110
|
+
await this.eventRecorder.recordEvent({
|
|
111
|
+
type: 'rename',
|
|
112
|
+
path: oldPath,
|
|
113
|
+
metadata: { newPath },
|
|
114
|
+
author: 'system'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return result;
|
|
119
|
+
});
|
|
120
|
+
// Add Knowledge Layer methods to VFS
|
|
121
|
+
this.addKnowledgeMethods(vfs);
|
|
122
|
+
console.log('✨ Knowledge Layer augmentation enabled');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Wrap a VFS method to add Knowledge Layer functionality
|
|
126
|
+
*/
|
|
127
|
+
wrapMethod(vfs, methodName, wrapper) {
|
|
128
|
+
const original = vfs[methodName];
|
|
129
|
+
if (!original)
|
|
130
|
+
return;
|
|
131
|
+
// Store original for cleanup
|
|
132
|
+
this.originalMethods.set(methodName, original);
|
|
133
|
+
// Replace with wrapped version
|
|
134
|
+
vfs[methodName] = async (...args) => {
|
|
135
|
+
return await wrapper(original, ...args);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Add Knowledge Layer methods to VFS
|
|
140
|
+
*/
|
|
141
|
+
addKnowledgeMethods(vfs) {
|
|
142
|
+
// Event history
|
|
143
|
+
vfs.getHistory = async (path, options) => {
|
|
144
|
+
if (!this.eventRecorder)
|
|
145
|
+
throw new Error('Knowledge Layer not initialized');
|
|
146
|
+
return await this.eventRecorder.getHistory(path, options);
|
|
147
|
+
};
|
|
148
|
+
vfs.reconstructAtTime = async (path, timestamp) => {
|
|
149
|
+
if (!this.eventRecorder)
|
|
150
|
+
throw new Error('Knowledge Layer not initialized');
|
|
151
|
+
return await this.eventRecorder.reconstructFileAtTime(path, timestamp);
|
|
152
|
+
};
|
|
153
|
+
// Semantic versioning
|
|
154
|
+
vfs.getVersions = async (path) => {
|
|
155
|
+
if (!this.semanticVersioning)
|
|
156
|
+
throw new Error('Knowledge Layer not initialized');
|
|
157
|
+
return await this.semanticVersioning.getVersions(path);
|
|
158
|
+
};
|
|
159
|
+
vfs.restoreVersion = async (path, versionId) => {
|
|
160
|
+
if (!this.semanticVersioning)
|
|
161
|
+
throw new Error('Knowledge Layer not initialized');
|
|
162
|
+
const version = await this.semanticVersioning.getVersion(path, versionId);
|
|
163
|
+
if (version) {
|
|
164
|
+
await vfs.writeFile(path, version);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
// Entities
|
|
168
|
+
vfs.findEntity = async (query) => {
|
|
169
|
+
if (!this.entitySystem)
|
|
170
|
+
throw new Error('Knowledge Layer not initialized');
|
|
171
|
+
return await this.entitySystem.findEntity(query);
|
|
172
|
+
};
|
|
173
|
+
vfs.getEntityAppearances = async (entityId) => {
|
|
174
|
+
if (!this.entitySystem)
|
|
175
|
+
throw new Error('Knowledge Layer not initialized');
|
|
176
|
+
return await this.entitySystem.getEvolution(entityId);
|
|
177
|
+
};
|
|
178
|
+
// Concepts
|
|
179
|
+
vfs.getConcepts = async (path) => {
|
|
180
|
+
if (!this.conceptSystem)
|
|
181
|
+
throw new Error('Knowledge Layer not initialized');
|
|
182
|
+
const concepts = await this.conceptSystem.findConcepts({ manifestedIn: path });
|
|
183
|
+
return concepts;
|
|
184
|
+
};
|
|
185
|
+
vfs.getConceptGraph = async (options) => {
|
|
186
|
+
if (!this.conceptSystem)
|
|
187
|
+
throw new Error('Knowledge Layer not initialized');
|
|
188
|
+
return await this.conceptSystem.getConceptGraph(options);
|
|
189
|
+
};
|
|
190
|
+
// Git bridge
|
|
191
|
+
vfs.exportToGit = async (vfsPath, gitPath) => {
|
|
192
|
+
if (!this.gitBridge)
|
|
193
|
+
throw new Error('Knowledge Layer not initialized');
|
|
194
|
+
return await this.gitBridge.exportToGit(vfsPath, gitPath);
|
|
195
|
+
};
|
|
196
|
+
vfs.importFromGit = async (gitPath, vfsPath) => {
|
|
197
|
+
if (!this.gitBridge)
|
|
198
|
+
throw new Error('Knowledge Layer not initialized');
|
|
199
|
+
return await this.gitBridge.importFromGit(gitPath, vfsPath);
|
|
200
|
+
};
|
|
201
|
+
// Temporal coupling
|
|
202
|
+
vfs.findTemporalCoupling = async (path, windowMs) => {
|
|
203
|
+
if (!this.eventRecorder)
|
|
204
|
+
throw new Error('Knowledge Layer not initialized');
|
|
205
|
+
return await this.eventRecorder.findTemporalCoupling(path, windowMs);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
isSemanticChange(oldContent, newContent) {
|
|
209
|
+
// Simple heuristic - significant size change or different content
|
|
210
|
+
const oldStr = oldContent.toString('utf8');
|
|
211
|
+
const newStr = newContent.toString('utf8');
|
|
212
|
+
// Check for significant size change (>10%)
|
|
213
|
+
const sizeDiff = Math.abs(oldStr.length - newStr.length) / oldStr.length;
|
|
214
|
+
if (sizeDiff > 0.1)
|
|
215
|
+
return true;
|
|
216
|
+
// Check for structural changes (simplified)
|
|
217
|
+
const oldLines = oldStr.split('\n').filter(l => l.trim());
|
|
218
|
+
const newLines = newStr.split('\n').filter(l => l.trim());
|
|
219
|
+
// Different number of non-empty lines
|
|
220
|
+
return Math.abs(oldLines.length - newLines.length) > 5;
|
|
221
|
+
}
|
|
222
|
+
async cleanup(brain) {
|
|
223
|
+
const vfs = brain.vfs?.();
|
|
224
|
+
if (!vfs)
|
|
225
|
+
return;
|
|
226
|
+
// Restore original methods
|
|
227
|
+
for (const [methodName, original] of this.originalMethods) {
|
|
228
|
+
vfs[methodName] = original;
|
|
229
|
+
}
|
|
230
|
+
// Remove added methods
|
|
231
|
+
delete vfs.getHistory;
|
|
232
|
+
delete vfs.reconstructAtTime;
|
|
233
|
+
delete vfs.getVersions;
|
|
234
|
+
delete vfs.restoreVersion;
|
|
235
|
+
delete vfs.findEntity;
|
|
236
|
+
delete vfs.getEntityAppearances;
|
|
237
|
+
delete vfs.getConcepts;
|
|
238
|
+
delete vfs.getConceptGraph;
|
|
239
|
+
delete vfs.exportToGit;
|
|
240
|
+
delete vfs.importFromGit;
|
|
241
|
+
delete vfs.findTemporalCoupling;
|
|
242
|
+
// Clean up components
|
|
243
|
+
this.eventRecorder = undefined;
|
|
244
|
+
this.semanticVersioning = undefined;
|
|
245
|
+
this.entitySystem = undefined;
|
|
246
|
+
this.conceptSystem = undefined;
|
|
247
|
+
this.gitBridge = undefined;
|
|
248
|
+
console.log('Knowledge Layer augmentation removed');
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=KnowledgeAugmentation.js.map
|
|
@@ -25,6 +25,7 @@ export declare function createDefaultAugmentations(config?: {
|
|
|
25
25
|
metrics?: boolean | Record<string, any>;
|
|
26
26
|
monitoring?: boolean | Record<string, any>;
|
|
27
27
|
display?: boolean | Record<string, any>;
|
|
28
|
+
knowledge?: boolean | Record<string, any>;
|
|
28
29
|
}): BaseAugmentation[];
|
|
29
30
|
/**
|
|
30
31
|
* Get augmentation by name with type safety
|
|
@@ -11,6 +11,7 @@ import { CacheAugmentation } from './cacheAugmentation.js';
|
|
|
11
11
|
import { MetricsAugmentation } from './metricsAugmentation.js';
|
|
12
12
|
import { MonitoringAugmentation } from './monitoringAugmentation.js';
|
|
13
13
|
import { UniversalDisplayAugmentation } from './universalDisplayAugmentation.js';
|
|
14
|
+
import { KnowledgeAugmentation } from './KnowledgeAugmentation.js';
|
|
14
15
|
/**
|
|
15
16
|
* Create default augmentations for zero-config operation
|
|
16
17
|
* Returns an array of augmentations to be registered
|
|
@@ -44,6 +45,10 @@ export function createDefaultAugmentations(config = {}) {
|
|
|
44
45
|
const monitoringConfig = typeof config.monitoring === 'object' ? config.monitoring : {};
|
|
45
46
|
augmentations.push(new MonitoringAugmentation(monitoringConfig));
|
|
46
47
|
}
|
|
48
|
+
// Knowledge Layer augmentation for VFS intelligence
|
|
49
|
+
if (config.knowledge !== false) {
|
|
50
|
+
augmentations.push(new KnowledgeAugmentation());
|
|
51
|
+
}
|
|
47
52
|
return augmentations;
|
|
48
53
|
}
|
|
49
54
|
/**
|
package/dist/brainy.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { Vector } from './coreTypes.js';
|
|
|
8
8
|
import { ImprovedNeuralAPI } from './neural/improvedNeuralAPI.js';
|
|
9
9
|
import { NaturalLanguageProcessor } from './neural/naturalLanguageProcessor.js';
|
|
10
10
|
import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
|
|
11
|
+
import { VirtualFileSystem } from './vfs/VirtualFileSystem.js';
|
|
11
12
|
import { Entity, Relation, Result, AddParams, UpdateParams, RelateParams, FindParams, SimilarParams, GetRelationsParams, AddManyParams, DeleteManyParams, RelateManyParams, BatchResult, BrainyConfig } from './types/brainy.types.js';
|
|
12
13
|
import { NounType } from './types/graphTypes.js';
|
|
13
14
|
import { BrainyInterface } from './types/brainyDataInterface.js';
|
|
@@ -34,6 +35,7 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
|
|
|
34
35
|
private _neural?;
|
|
35
36
|
private _nlp?;
|
|
36
37
|
private _tripleIntelligence?;
|
|
38
|
+
private _vfs?;
|
|
37
39
|
private initialized;
|
|
38
40
|
private dimensions?;
|
|
39
41
|
constructor(config?: BrainyConfig);
|
|
@@ -48,6 +50,10 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
|
|
|
48
50
|
* Ensure Brainy is initialized
|
|
49
51
|
*/
|
|
50
52
|
private ensureInitialized;
|
|
53
|
+
/**
|
|
54
|
+
* Check if Brainy is initialized
|
|
55
|
+
*/
|
|
56
|
+
get isInitialized(): boolean;
|
|
51
57
|
/**
|
|
52
58
|
* Add an entity to the database
|
|
53
59
|
*/
|
|
@@ -133,6 +139,10 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
|
|
|
133
139
|
* Natural Language Processing API
|
|
134
140
|
*/
|
|
135
141
|
nlp(): NaturalLanguageProcessor;
|
|
142
|
+
/**
|
|
143
|
+
* Virtual File System API - Knowledge Operating System
|
|
144
|
+
*/
|
|
145
|
+
vfs(): VirtualFileSystem;
|
|
136
146
|
/**
|
|
137
147
|
* Data Management API - backup, restore, import, export
|
|
138
148
|
*/
|
|
@@ -333,6 +343,7 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
|
|
|
333
343
|
private verbsToRelations;
|
|
334
344
|
/**
|
|
335
345
|
* Embed data into vector
|
|
346
|
+
* Handles any data type by converting to string representation
|
|
336
347
|
*/
|
|
337
348
|
embed(data: any): Promise<Vector>;
|
|
338
349
|
/**
|
package/dist/brainy.js
CHANGED
|
@@ -14,6 +14,7 @@ import { createDefaultAugmentations } from './augmentations/defaultAugmentations
|
|
|
14
14
|
import { ImprovedNeuralAPI } from './neural/improvedNeuralAPI.js';
|
|
15
15
|
import { NaturalLanguageProcessor } from './neural/naturalLanguageProcessor.js';
|
|
16
16
|
import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
|
|
17
|
+
import { VirtualFileSystem } from './vfs/VirtualFileSystem.js';
|
|
17
18
|
import { MetadataIndexManager } from './utils/metadataIndex.js';
|
|
18
19
|
import { GraphAdjacencyIndex } from './graph/graphAdjacencyIndex.js';
|
|
19
20
|
import { createPipeline } from './streaming/pipeline.js';
|
|
@@ -138,6 +139,12 @@ export class Brainy {
|
|
|
138
139
|
throw new Error('Brainy not initialized. Call init() first.');
|
|
139
140
|
}
|
|
140
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if Brainy is initialized
|
|
144
|
+
*/
|
|
145
|
+
get isInitialized() {
|
|
146
|
+
return this.initialized;
|
|
147
|
+
}
|
|
141
148
|
// ============= CORE CRUD OPERATIONS =============
|
|
142
149
|
/**
|
|
143
150
|
* Add an entity to the database
|
|
@@ -895,6 +902,15 @@ export class Brainy {
|
|
|
895
902
|
}
|
|
896
903
|
return this._nlp;
|
|
897
904
|
}
|
|
905
|
+
/**
|
|
906
|
+
* Virtual File System API - Knowledge Operating System
|
|
907
|
+
*/
|
|
908
|
+
vfs() {
|
|
909
|
+
if (!this._vfs) {
|
|
910
|
+
this._vfs = new VirtualFileSystem(this);
|
|
911
|
+
}
|
|
912
|
+
return this._vfs;
|
|
913
|
+
}
|
|
898
914
|
/**
|
|
899
915
|
* Data Management API - backup, restore, import, export
|
|
900
916
|
*/
|
|
@@ -1448,9 +1464,79 @@ export class Brainy {
|
|
|
1448
1464
|
}
|
|
1449
1465
|
/**
|
|
1450
1466
|
* Embed data into vector
|
|
1467
|
+
* Handles any data type by converting to string representation
|
|
1451
1468
|
*/
|
|
1452
1469
|
async embed(data) {
|
|
1453
|
-
|
|
1470
|
+
// Handle different data types intelligently
|
|
1471
|
+
let textToEmbed;
|
|
1472
|
+
if (typeof data === 'string') {
|
|
1473
|
+
textToEmbed = data;
|
|
1474
|
+
}
|
|
1475
|
+
else if (Array.isArray(data)) {
|
|
1476
|
+
// Array of items - convert each to string
|
|
1477
|
+
textToEmbed = data.map(item => {
|
|
1478
|
+
if (typeof item === 'string')
|
|
1479
|
+
return item;
|
|
1480
|
+
if (typeof item === 'number' || typeof item === 'boolean')
|
|
1481
|
+
return String(item);
|
|
1482
|
+
if (item && typeof item === 'object') {
|
|
1483
|
+
// For objects, try to extract meaningful text
|
|
1484
|
+
if (item.data)
|
|
1485
|
+
return String(item.data);
|
|
1486
|
+
if (item.content)
|
|
1487
|
+
return String(item.content);
|
|
1488
|
+
if (item.text)
|
|
1489
|
+
return String(item.text);
|
|
1490
|
+
if (item.name)
|
|
1491
|
+
return String(item.name);
|
|
1492
|
+
if (item.title)
|
|
1493
|
+
return String(item.title);
|
|
1494
|
+
if (item.description)
|
|
1495
|
+
return String(item.description);
|
|
1496
|
+
// Fallback to JSON for complex objects
|
|
1497
|
+
try {
|
|
1498
|
+
return JSON.stringify(item);
|
|
1499
|
+
}
|
|
1500
|
+
catch {
|
|
1501
|
+
return String(item);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
return String(item);
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
else if (data && typeof data === 'object') {
|
|
1508
|
+
// Single object - extract meaningful text
|
|
1509
|
+
if (data.data)
|
|
1510
|
+
textToEmbed = String(data.data);
|
|
1511
|
+
else if (data.content)
|
|
1512
|
+
textToEmbed = String(data.content);
|
|
1513
|
+
else if (data.text)
|
|
1514
|
+
textToEmbed = String(data.text);
|
|
1515
|
+
else if (data.name)
|
|
1516
|
+
textToEmbed = String(data.name);
|
|
1517
|
+
else if (data.title)
|
|
1518
|
+
textToEmbed = String(data.title);
|
|
1519
|
+
else if (data.description)
|
|
1520
|
+
textToEmbed = String(data.description);
|
|
1521
|
+
else {
|
|
1522
|
+
// For complex objects, create a descriptive string
|
|
1523
|
+
try {
|
|
1524
|
+
textToEmbed = JSON.stringify(data);
|
|
1525
|
+
}
|
|
1526
|
+
catch {
|
|
1527
|
+
textToEmbed = String(data);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
else if (data === null || data === undefined) {
|
|
1532
|
+
// Handle null/undefined gracefully
|
|
1533
|
+
textToEmbed = '';
|
|
1534
|
+
}
|
|
1535
|
+
else {
|
|
1536
|
+
// Numbers, booleans, etc - convert to string
|
|
1537
|
+
textToEmbed = String(data);
|
|
1538
|
+
}
|
|
1539
|
+
return this.embedder(textToEmbed);
|
|
1454
1540
|
}
|
|
1455
1541
|
/**
|
|
1456
1542
|
* Warm up the system
|
|
@@ -165,8 +165,20 @@ export class EmbeddingManager {
|
|
|
165
165
|
if (!this.model) {
|
|
166
166
|
throw new Error('Model not initialized');
|
|
167
167
|
}
|
|
168
|
-
//
|
|
169
|
-
|
|
168
|
+
// CRITICAL FIX: Ensure input is always a string
|
|
169
|
+
let input;
|
|
170
|
+
if (Array.isArray(text)) {
|
|
171
|
+
// Join array elements, converting each to string first
|
|
172
|
+
input = text.map(t => typeof t === 'string' ? t : String(t)).join(' ');
|
|
173
|
+
}
|
|
174
|
+
else if (typeof text === 'string') {
|
|
175
|
+
input = text;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// This shouldn't happen but let's be defensive
|
|
179
|
+
console.warn('EmbeddingManager.embed received non-string input:', typeof text);
|
|
180
|
+
input = String(text);
|
|
181
|
+
}
|
|
170
182
|
// Generate embedding
|
|
171
183
|
const output = await this.model(input, {
|
|
172
184
|
pooling: 'mean',
|
package/dist/utils/mutex.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ export declare class FileMutex implements MutexInterface {
|
|
|
29
29
|
private lockDir;
|
|
30
30
|
private processLocks;
|
|
31
31
|
private lockTimers;
|
|
32
|
+
private modulesLoaded;
|
|
32
33
|
constructor(lockDir: string);
|
|
34
|
+
private loadNodeModules;
|
|
33
35
|
acquire(key: string, timeout?: number): Promise<() => void>;
|
|
34
36
|
private release;
|
|
35
37
|
runExclusive<T>(key: string, fn: () => Promise<T>, timeout?: number): Promise<T>;
|
package/dist/utils/mutex.js
CHANGED
|
@@ -74,14 +74,25 @@ export class FileMutex {
|
|
|
74
74
|
constructor(lockDir) {
|
|
75
75
|
this.processLocks = new Map();
|
|
76
76
|
this.lockTimers = new Map();
|
|
77
|
+
this.modulesLoaded = false;
|
|
77
78
|
this.lockDir = lockDir;
|
|
78
|
-
|
|
79
|
+
}
|
|
80
|
+
async loadNodeModules() {
|
|
81
|
+
if (this.modulesLoaded)
|
|
82
|
+
return;
|
|
79
83
|
if (typeof window === 'undefined') {
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
// Modern ESM-compatible dynamic imports
|
|
85
|
+
const [fs, path] = await Promise.all([
|
|
86
|
+
import('fs'),
|
|
87
|
+
import('path')
|
|
88
|
+
]);
|
|
89
|
+
this.fs = fs;
|
|
90
|
+
this.path = path;
|
|
91
|
+
this.modulesLoaded = true;
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
async acquire(key, timeout = 30000) {
|
|
95
|
+
await this.loadNodeModules();
|
|
85
96
|
if (!this.fs || !this.path) {
|
|
86
97
|
throw new Error('FileMutex is only available in Node.js environments');
|
|
87
98
|
}
|