@soulcraft/brainy 0.19.0 → 0.21.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/README.md +8 -3
- package/dist/augmentations/conduitAugmentations.js +1158 -0
- package/dist/augmentations/conduitAugmentations.js.map +1 -0
- package/dist/augmentations/memoryAugmentations.js +255 -0
- package/dist/augmentations/memoryAugmentations.js.map +1 -0
- package/dist/augmentations/serverSearchAugmentations.js +531 -0
- package/dist/augmentations/serverSearchAugmentations.js.map +1 -0
- package/dist/brainy.js +508 -42
- package/dist/brainy.min.js +750 -750
- package/dist/brainyData.d.ts +58 -4
- package/dist/coreTypes.d.ts +54 -0
- package/dist/examples/basicUsage.js +128 -0
- package/dist/examples/basicUsage.js.map +1 -0
- package/dist/hnsw/hnswIndex.js +550 -0
- package/dist/hnsw/hnswIndex.js.map +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +441 -0
- package/dist/hnsw/hnswIndexOptimized.js.map +1 -0
- package/dist/mcp/brainyMCPAdapter.js +142 -0
- package/dist/mcp/brainyMCPAdapter.js.map +1 -0
- package/dist/mcp/brainyMCPService.js +248 -0
- package/dist/mcp/brainyMCPService.js.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcpAugmentationToolset.js +180 -0
- package/dist/mcp/mcpAugmentationToolset.js.map +1 -0
- package/dist/storage/adapters/baseStorageAdapter.d.ts +82 -0
- package/dist/storage/adapters/baseStorageAdapter.d.ts.map +1 -0
- package/dist/storage/adapters/baseStorageAdapter.js +233 -0
- package/dist/storage/adapters/baseStorageAdapter.js.map +1 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +11 -1
- package/dist/storage/adapters/fileSystemStorage.d.ts.map +1 -1
- package/dist/storage/adapters/fileSystemStorage.js +568 -0
- package/dist/storage/adapters/fileSystemStorage.js.map +1 -0
- package/dist/storage/adapters/memoryStorage.d.ts +12 -1
- package/dist/storage/adapters/memoryStorage.d.ts.map +1 -1
- package/dist/storage/adapters/memoryStorage.js +300 -0
- package/dist/storage/adapters/memoryStorage.js.map +1 -0
- package/dist/storage/adapters/opfsStorage.d.ts +28 -1
- package/dist/storage/adapters/opfsStorage.d.ts.map +1 -1
- package/dist/storage/adapters/opfsStorage.js +778 -0
- package/dist/storage/adapters/opfsStorage.js.map +1 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +47 -1
- package/dist/storage/adapters/s3CompatibleStorage.d.ts.map +1 -1
- package/dist/storage/adapters/s3CompatibleStorage.js +1021 -0
- package/dist/storage/adapters/s3CompatibleStorage.js.map +1 -0
- package/dist/storage/baseStorage.d.ts +16 -2
- package/dist/storage/baseStorage.d.ts.map +1 -1
- package/dist/storage/baseStorage.js +126 -0
- package/dist/storage/baseStorage.js.map +1 -0
- package/dist/storage/fileSystemStorage.d.ts +15 -2
- package/dist/storage/fileSystemStorage.d.ts.map +1 -1
- package/dist/storage/opfsStorage.d.ts +66 -3
- package/dist/storage/opfsStorage.d.ts.map +1 -1
- package/dist/storage/s3CompatibleStorage.d.ts +14 -2
- package/dist/storage/s3CompatibleStorage.d.ts.map +1 -1
- package/dist/storage/storageFactory.js +183 -0
- package/dist/storage/storageFactory.js.map +1 -0
- package/dist/types/augmentations.js +16 -0
- package/dist/types/augmentations.js.map +1 -0
- package/dist/types/brainyDataInterface.js +8 -0
- package/dist/types/brainyDataInterface.js.map +1 -0
- package/dist/types/fileSystemTypes.js +8 -0
- package/dist/types/fileSystemTypes.js.map +1 -0
- package/dist/types/graphTypes.js +36 -0
- package/dist/types/graphTypes.js.map +1 -0
- package/dist/types/mcpTypes.js +22 -0
- package/dist/types/mcpTypes.js.map +1 -0
- package/dist/types/pipelineTypes.js +7 -0
- package/dist/types/pipelineTypes.js.map +1 -0
- package/dist/types/tensorflowTypes.js +6 -0
- package/dist/types/tensorflowTypes.js.map +1 -0
- package/dist/unified.js +1554 -550
- package/dist/unified.min.js +747 -747
- package/dist/utils/distance.js +239 -0
- package/dist/utils/distance.js.map +1 -0
- package/dist/utils/embedding.js +622 -0
- package/dist/utils/embedding.js.map +1 -0
- package/dist/utils/environment.js +75 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/statistics.d.ts +11 -1
- package/dist/utils/statistics.d.ts.map +1 -1
- package/dist/utils/statistics.js +25 -0
- package/dist/utils/statistics.js.map +1 -0
- package/dist/utils/tensorflowUtils.js +25 -0
- package/dist/utils/tensorflowUtils.js.map +1 -0
- package/dist/utils/textEncoding.js +281 -0
- package/dist/utils/textEncoding.js.map +1 -0
- package/dist/utils/workerUtils.js +458 -0
- package/dist/utils/workerUtils.js.map +1 -0
- package/package.json +4 -3
- package/README.demo.md +0 -65
package/dist/brainyData.d.ts
CHANGED
|
@@ -138,6 +138,12 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
138
138
|
* @throws Error if the database is in read-only mode
|
|
139
139
|
*/
|
|
140
140
|
private checkReadOnly;
|
|
141
|
+
/**
|
|
142
|
+
* Get the current augmentation name if available
|
|
143
|
+
* This is used to auto-detect the service performing data operations
|
|
144
|
+
* @returns The name of the current augmentation or 'default' if none is detected
|
|
145
|
+
*/
|
|
146
|
+
private getCurrentAugmentation;
|
|
141
147
|
/**
|
|
142
148
|
* Initialize the database
|
|
143
149
|
* Loads existing data from storage if available
|
|
@@ -162,6 +168,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
162
168
|
forceEmbed?: boolean;
|
|
163
169
|
addToRemote?: boolean;
|
|
164
170
|
id?: string;
|
|
171
|
+
service?: string;
|
|
165
172
|
}): Promise<string>;
|
|
166
173
|
/**
|
|
167
174
|
* Add a text item to the database with automatic embedding
|
|
@@ -222,6 +229,14 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
222
229
|
forceEmbed?: boolean;
|
|
223
230
|
concurrency?: number;
|
|
224
231
|
}): Promise<string[]>;
|
|
232
|
+
/**
|
|
233
|
+
* Filter search results by service
|
|
234
|
+
* @param results Search results to filter
|
|
235
|
+
* @param service Service to filter by
|
|
236
|
+
* @returns Filtered search results
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
private filterResultsByService;
|
|
225
240
|
/**
|
|
226
241
|
* Search for similar vectors within specific noun types
|
|
227
242
|
* @param queryVectorOrData Query vector or data to search for
|
|
@@ -232,6 +247,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
232
247
|
*/
|
|
233
248
|
searchByNounTypes(queryVectorOrData: Vector | any, k?: number, nounTypes?: string[] | null, options?: {
|
|
234
249
|
forceEmbed?: boolean;
|
|
250
|
+
service?: string;
|
|
235
251
|
}): Promise<SearchResult<T>[]>;
|
|
236
252
|
/**
|
|
237
253
|
* Search for similar vectors
|
|
@@ -249,6 +265,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
249
265
|
verbTypes?: string[];
|
|
250
266
|
searchConnectedNouns?: boolean;
|
|
251
267
|
verbDirection?: 'outgoing' | 'incoming' | 'both';
|
|
268
|
+
service?: string;
|
|
252
269
|
}): Promise<SearchResult<T>[]>;
|
|
253
270
|
/**
|
|
254
271
|
* Search the local database for similar vectors
|
|
@@ -261,6 +278,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
261
278
|
forceEmbed?: boolean;
|
|
262
279
|
nounTypes?: string[];
|
|
263
280
|
includeVerbs?: boolean;
|
|
281
|
+
service?: string;
|
|
264
282
|
}): Promise<SearchResult<T>[]>;
|
|
265
283
|
/**
|
|
266
284
|
* Find entities similar to a given entity ID
|
|
@@ -285,12 +303,23 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
285
303
|
getAllNouns(): Promise<VectorDocument<T>[]>;
|
|
286
304
|
/**
|
|
287
305
|
* Delete a vector by ID
|
|
306
|
+
* @param id The ID of the vector to delete
|
|
307
|
+
* @param options Additional options
|
|
308
|
+
* @returns Promise that resolves to true if the vector was deleted, false otherwise
|
|
288
309
|
*/
|
|
289
|
-
delete(id: string
|
|
310
|
+
delete(id: string, options?: {
|
|
311
|
+
service?: string;
|
|
312
|
+
}): Promise<boolean>;
|
|
290
313
|
/**
|
|
291
314
|
* Update metadata for a vector
|
|
315
|
+
* @param id The ID of the vector to update metadata for
|
|
316
|
+
* @param metadata The new metadata
|
|
317
|
+
* @param options Additional options
|
|
318
|
+
* @returns Promise that resolves to true if the metadata was updated, false otherwise
|
|
292
319
|
*/
|
|
293
|
-
updateMetadata(id: string, metadata: T
|
|
320
|
+
updateMetadata(id: string, metadata: T, options?: {
|
|
321
|
+
service?: string;
|
|
322
|
+
}): Promise<boolean>;
|
|
294
323
|
/**
|
|
295
324
|
* Create a relationship between two entities
|
|
296
325
|
* This is a convenience wrapper around addVerb
|
|
@@ -329,6 +358,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
329
358
|
id?: string;
|
|
330
359
|
autoCreateMissingNouns?: boolean;
|
|
331
360
|
missingNounMetadata?: any;
|
|
361
|
+
service?: string;
|
|
332
362
|
}): Promise<string>;
|
|
333
363
|
/**
|
|
334
364
|
* Get a verb by ID
|
|
@@ -352,8 +382,13 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
352
382
|
getVerbsByType(type: string): Promise<GraphVerb[]>;
|
|
353
383
|
/**
|
|
354
384
|
* Delete a verb
|
|
385
|
+
* @param id The ID of the verb to delete
|
|
386
|
+
* @param options Additional options
|
|
387
|
+
* @returns Promise that resolves to true if the verb was deleted, false otherwise
|
|
355
388
|
*/
|
|
356
|
-
deleteVerb(id: string
|
|
389
|
+
deleteVerb(id: string, options?: {
|
|
390
|
+
service?: string;
|
|
391
|
+
}): Promise<boolean>;
|
|
357
392
|
/**
|
|
358
393
|
* Clear the database
|
|
359
394
|
*/
|
|
@@ -362,15 +397,31 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
362
397
|
* Get the number of vectors in the database
|
|
363
398
|
*/
|
|
364
399
|
size(): number;
|
|
400
|
+
/**
|
|
401
|
+
* Get the number of nouns in the database (excluding verbs)
|
|
402
|
+
* This is used for statistics reporting to match the expected behavior in tests
|
|
403
|
+
* @private
|
|
404
|
+
*/
|
|
405
|
+
private getNounCount;
|
|
365
406
|
/**
|
|
366
407
|
* Get statistics about the current state of the database
|
|
408
|
+
* @param options Additional options for retrieving statistics
|
|
367
409
|
* @returns Object containing counts of nouns, verbs, metadata entries, and HNSW index size
|
|
368
410
|
*/
|
|
369
|
-
getStatistics(
|
|
411
|
+
getStatistics(options?: {
|
|
412
|
+
service?: string | string[];
|
|
413
|
+
}): Promise<{
|
|
370
414
|
nounCount: number;
|
|
371
415
|
verbCount: number;
|
|
372
416
|
metadataCount: number;
|
|
373
417
|
hnswIndexSize: number;
|
|
418
|
+
serviceBreakdown?: {
|
|
419
|
+
[service: string]: {
|
|
420
|
+
nounCount: number;
|
|
421
|
+
verbCount: number;
|
|
422
|
+
metadataCount: number;
|
|
423
|
+
};
|
|
424
|
+
};
|
|
374
425
|
}>;
|
|
375
426
|
/**
|
|
376
427
|
* Check if the database is in read-only mode
|
|
@@ -400,6 +451,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
400
451
|
searchVerbs(queryVectorOrData: Vector | any, k?: number, options?: {
|
|
401
452
|
forceEmbed?: boolean;
|
|
402
453
|
verbTypes?: string[];
|
|
454
|
+
service?: string;
|
|
403
455
|
}): Promise<Array<GraphVerb & {
|
|
404
456
|
similarity: number;
|
|
405
457
|
}>>;
|
|
@@ -441,6 +493,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
441
493
|
nounTypes?: string[];
|
|
442
494
|
includeVerbs?: boolean;
|
|
443
495
|
storeResults?: boolean;
|
|
496
|
+
service?: string;
|
|
444
497
|
}): Promise<SearchResult<T>[]>;
|
|
445
498
|
/**
|
|
446
499
|
* Search both local and remote Brainy instances, combining the results
|
|
@@ -454,6 +507,7 @@ export declare class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|
|
454
507
|
nounTypes?: string[];
|
|
455
508
|
includeVerbs?: boolean;
|
|
456
509
|
localFirst?: boolean;
|
|
510
|
+
service?: string;
|
|
457
511
|
}): Promise<SearchResult<T>[]>;
|
|
458
512
|
/**
|
|
459
513
|
* Check if the instance is connected to a remote server
|
package/dist/coreTypes.d.ts
CHANGED
|
@@ -83,6 +83,31 @@ export interface HNSWConfig {
|
|
|
83
83
|
/**
|
|
84
84
|
* Storage interface for persistence
|
|
85
85
|
*/
|
|
86
|
+
/**
|
|
87
|
+
* Statistics data structure for tracking counts by service
|
|
88
|
+
*/
|
|
89
|
+
export interface StatisticsData {
|
|
90
|
+
/**
|
|
91
|
+
* Count of nouns by service
|
|
92
|
+
*/
|
|
93
|
+
nounCount: Record<string, number>;
|
|
94
|
+
/**
|
|
95
|
+
* Count of verbs by service
|
|
96
|
+
*/
|
|
97
|
+
verbCount: Record<string, number>;
|
|
98
|
+
/**
|
|
99
|
+
* Count of metadata entries by service
|
|
100
|
+
*/
|
|
101
|
+
metadataCount: Record<string, number>;
|
|
102
|
+
/**
|
|
103
|
+
* Size of the HNSW index
|
|
104
|
+
*/
|
|
105
|
+
hnswIndexSize: number;
|
|
106
|
+
/**
|
|
107
|
+
* Last updated timestamp
|
|
108
|
+
*/
|
|
109
|
+
lastUpdated: string;
|
|
110
|
+
}
|
|
86
111
|
export interface StorageAdapter {
|
|
87
112
|
init(): Promise<void>;
|
|
88
113
|
saveNoun(noun: HNSWNoun): Promise<void>;
|
|
@@ -127,4 +152,33 @@ export interface StorageAdapter {
|
|
|
127
152
|
*/
|
|
128
153
|
details?: Record<string, any>;
|
|
129
154
|
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Save statistics data
|
|
157
|
+
* @param statistics The statistics data to save
|
|
158
|
+
*/
|
|
159
|
+
saveStatistics(statistics: StatisticsData): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Get statistics data
|
|
162
|
+
* @returns Promise that resolves to the statistics data
|
|
163
|
+
*/
|
|
164
|
+
getStatistics(): Promise<StatisticsData | null>;
|
|
165
|
+
/**
|
|
166
|
+
* Increment a statistic counter
|
|
167
|
+
* @param type The type of statistic to increment ('noun', 'verb', 'metadata')
|
|
168
|
+
* @param service The service that inserted the data
|
|
169
|
+
* @param amount The amount to increment by (default: 1)
|
|
170
|
+
*/
|
|
171
|
+
incrementStatistic(type: 'noun' | 'verb' | 'metadata', service: string, amount?: number): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Decrement a statistic counter
|
|
174
|
+
* @param type The type of statistic to decrement ('noun', 'verb', 'metadata')
|
|
175
|
+
* @param service The service that inserted the data
|
|
176
|
+
* @param amount The amount to decrement by (default: 1)
|
|
177
|
+
*/
|
|
178
|
+
decrementStatistic(type: 'noun' | 'verb' | 'metadata', service: string, amount?: number): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Update the HNSW index size statistic
|
|
181
|
+
* @param size The new size of the HNSW index
|
|
182
|
+
*/
|
|
183
|
+
updateHnswIndexSize(size: number): Promise<void>;
|
|
130
184
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic usage example for the Soulcraft Brainy database
|
|
3
|
+
*/
|
|
4
|
+
import { BrainyData } from '../brainyData.js';
|
|
5
|
+
// Example data - word embeddings
|
|
6
|
+
const wordEmbeddings = {
|
|
7
|
+
cat: [0.2, 0.3, 0.4, 0.1],
|
|
8
|
+
dog: [0.3, 0.2, 0.4, 0.2],
|
|
9
|
+
fish: [0.1, 0.1, 0.8, 0.2],
|
|
10
|
+
bird: [0.1, 0.4, 0.2, 0.5],
|
|
11
|
+
tiger: [0.3, 0.4, 0.3, 0.1],
|
|
12
|
+
lion: [0.4, 0.3, 0.2, 0.1],
|
|
13
|
+
shark: [0.2, 0.1, 0.7, 0.3],
|
|
14
|
+
eagle: [0.2, 0.5, 0.1, 0.4]
|
|
15
|
+
};
|
|
16
|
+
// Example metadata
|
|
17
|
+
const metadata = {
|
|
18
|
+
cat: { type: 'mammal', domesticated: true },
|
|
19
|
+
dog: { type: 'mammal', domesticated: true },
|
|
20
|
+
fish: { type: 'fish', domesticated: false },
|
|
21
|
+
bird: { type: 'bird', domesticated: false },
|
|
22
|
+
tiger: { type: 'mammal', domesticated: false },
|
|
23
|
+
lion: { type: 'mammal', domesticated: false },
|
|
24
|
+
shark: { type: 'fish', domesticated: false },
|
|
25
|
+
eagle: { type: 'bird', domesticated: false }
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Run the example
|
|
29
|
+
*/
|
|
30
|
+
async function runExample() {
|
|
31
|
+
console.log('Initializing vector database...');
|
|
32
|
+
// Create a new vector database
|
|
33
|
+
const db = new BrainyData();
|
|
34
|
+
await db.init();
|
|
35
|
+
console.log('Adding vectors to the database...');
|
|
36
|
+
// Add vectors to the database
|
|
37
|
+
const ids = {};
|
|
38
|
+
const metadata = {
|
|
39
|
+
cat: { type: 'mammal', domesticated: true },
|
|
40
|
+
dog: { type: 'mammal', domesticated: true },
|
|
41
|
+
fish: { type: 'fish', domesticated: false },
|
|
42
|
+
bird: { type: 'bird', domesticated: false },
|
|
43
|
+
tiger: { type: 'mammal', domesticated: false },
|
|
44
|
+
lion: { type: 'mammal', domesticated: false },
|
|
45
|
+
shark: { type: 'fish', domesticated: false },
|
|
46
|
+
eagle: { type: 'bird', domesticated: false }
|
|
47
|
+
};
|
|
48
|
+
for (const [word, vector] of Object.entries(wordEmbeddings)) {
|
|
49
|
+
ids[word] = await db.add(vector, metadata[word]);
|
|
50
|
+
console.log(`Added "${word}" with ID: ${ids[word]}`);
|
|
51
|
+
}
|
|
52
|
+
console.log('\nDatabase size:', db.size());
|
|
53
|
+
// Search for similar vectors
|
|
54
|
+
console.log('\nSearching for vectors similar to "cat"...');
|
|
55
|
+
const catResults = await db.search(wordEmbeddings['cat'], 3);
|
|
56
|
+
console.log('Results:');
|
|
57
|
+
for (const result of catResults) {
|
|
58
|
+
const word = Object.entries(ids).find(([_, id]) => id === result.id)?.[0] || 'unknown';
|
|
59
|
+
console.log(`- ${word} (score: ${result.score.toFixed(4)}, metadata:`, result.metadata, ')');
|
|
60
|
+
}
|
|
61
|
+
// Search for similar vectors
|
|
62
|
+
console.log('\nSearching for vectors similar to "fish"...');
|
|
63
|
+
const fishResults = await db.search(wordEmbeddings['fish'], 3);
|
|
64
|
+
console.log('Results:');
|
|
65
|
+
for (const result of fishResults) {
|
|
66
|
+
const word = Object.entries(ids).find(([_, id]) => id === result.id)?.[0] || 'unknown';
|
|
67
|
+
console.log(`- ${word} (score: ${result.score.toFixed(4)}, metadata:`, result.metadata, ')');
|
|
68
|
+
}
|
|
69
|
+
// Update metadata
|
|
70
|
+
console.log('\nUpdating metadata for "bird"...');
|
|
71
|
+
await db.updateMetadata(ids['bird'], {
|
|
72
|
+
...metadata['bird'],
|
|
73
|
+
notes: 'Can fly'
|
|
74
|
+
});
|
|
75
|
+
// Get the updated document
|
|
76
|
+
const birdDoc = await db.get(ids['bird']);
|
|
77
|
+
console.log('Updated bird document:', birdDoc);
|
|
78
|
+
// Delete a vector
|
|
79
|
+
console.log('\nDeleting "shark"...');
|
|
80
|
+
await db.delete(ids['shark']);
|
|
81
|
+
console.log('Database size after deletion:', db.size());
|
|
82
|
+
// Search again to verify shark is gone
|
|
83
|
+
console.log('\nSearching for vectors similar to "fish" after deletion...');
|
|
84
|
+
const fishResultsAfterDeletion = await db.search(wordEmbeddings['fish'], 3);
|
|
85
|
+
console.log('Results:');
|
|
86
|
+
for (const result of fishResultsAfterDeletion) {
|
|
87
|
+
const word = Object.entries(ids).find(([_, id]) => id === result.id)?.[0] || 'unknown';
|
|
88
|
+
console.log(`- ${word} (score: ${result.score.toFixed(4)}, metadata:`, result.metadata, ')');
|
|
89
|
+
}
|
|
90
|
+
console.log('\nExample completed successfully!');
|
|
91
|
+
}
|
|
92
|
+
// Check if we're in a browser or Node.js environment
|
|
93
|
+
if (typeof window !== 'undefined') {
|
|
94
|
+
// Browser environment
|
|
95
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
96
|
+
const button = document.createElement('button');
|
|
97
|
+
button.textContent = 'Run BrainyData Example';
|
|
98
|
+
button.addEventListener('click', async () => {
|
|
99
|
+
const output = document.createElement('pre');
|
|
100
|
+
document.body.appendChild(output);
|
|
101
|
+
// Redirect console.log to the output element
|
|
102
|
+
const originalLog = console.log;
|
|
103
|
+
console.log = (...args) => {
|
|
104
|
+
originalLog(...args);
|
|
105
|
+
output.textContent +=
|
|
106
|
+
args
|
|
107
|
+
.map((arg) => typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg)
|
|
108
|
+
.join(' ') + '\n';
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
await runExample();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error('Error running example:', error);
|
|
115
|
+
}
|
|
116
|
+
// Restore console.log
|
|
117
|
+
console.log = originalLog;
|
|
118
|
+
});
|
|
119
|
+
document.body.appendChild(button);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Node.js environment
|
|
124
|
+
runExample().catch((error) => {
|
|
125
|
+
console.error('Error running example:', error);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=basicUsage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basicUsage.js","sourceRoot":"","sources":["../../src/examples/basicUsage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,iCAAiC;AACjC,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACzB,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC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