chore: remove examples/externalPlugins.js and pluginLoader.ts, update imports to .js

Deleted `examples/externalPlugins.js` and `pluginLoader.ts` as they are no longer used. Updated all `.ts` imports to `.js` across the codebase. Added `MemberOf` to `VerbType` and filtered disabled augmentations in `executeAugmentationPipeline`. Updated documentation to reflect new augmentation registration process. Removed deprecated `allowImportingTsExtensions` from `tsconfig.json`.
This commit is contained in:
David Snelling 2025-05-29 09:52:30 -07:00
parent 7d2b695ea0
commit 203b669203
22 changed files with 1063 additions and 541 deletions

View file

@ -0,0 +1,184 @@
/**
* Example: Registering Augmentations at Build Time
*
* This example demonstrates how to register custom augmentations at build time
* using the Brainy library's augmentation registry system.
*/
// Import the augmentation registry and types from Brainy
import {
registerAugmentation,
AugmentationType,
BrainyAugmentations
} from '../dist/index.js';
// Define a custom sense augmentation
class CustomTextSenseAugmentation {
constructor() {
this.name = 'CustomTextSenseAugmentation';
this.enabled = true;
this.type = AugmentationType.SENSE;
}
// Required IAugmentation methods
async initialize() {
console.log('Initializing CustomTextSenseAugmentation');
return true;
}
async shutDown() {
console.log('Shutting down CustomTextSenseAugmentation');
return true;
}
getStatus() {
return {
name: this.name,
enabled: this.enabled,
type: this.type,
status: 'ready'
};
}
// ISenseAugmentation methods
async processRawData(rawData, dataType) {
console.log(`Processing ${dataType} data: ${rawData.substring(0, 50)}...`);
// Simple implementation to extract nouns and verbs
const words = rawData.split(' ');
const nouns = words.filter(word => word.length > 4);
const verbs = words.filter(word => word.endsWith('ing'));
return {
success: true,
data: { nouns, verbs }
};
}
async listenToFeed(feedUrl, callback) {
console.log(`Listening to feed at ${feedUrl}`);
// In a real implementation, this would set up a listener
// For this example, we'll just call the callback once
setTimeout(() => {
callback({
success: true,
data: { message: 'Feed update received' }
});
}, 1000);
return {
success: true,
data: { feedId: 'example-feed-1' }
};
}
}
// Define a custom memory augmentation
class CustomMemoryAugmentation {
constructor() {
this.name = 'CustomMemoryAugmentation';
this.enabled = true;
this.type = AugmentationType.MEMORY;
this.storage = new Map();
}
// Required IAugmentation methods
async initialize() {
console.log('Initializing CustomMemoryAugmentation');
return true;
}
async shutDown() {
console.log('Shutting down CustomMemoryAugmentation');
this.storage.clear();
return true;
}
getStatus() {
return {
name: this.name,
enabled: this.enabled,
type: this.type,
status: 'ready',
itemCount: this.storage.size
};
}
// IMemoryAugmentation methods
async storeData(key, data, options = {}) {
console.log(`Storing data with key: ${key}`);
this.storage.set(key, data);
return {
success: true,
data: { key }
};
}
async retrieveData(key, options = {}) {
console.log(`Retrieving data with key: ${key}`);
const data = this.storage.get(key);
return {
success: !!data,
data: data || null,
error: !data ? 'Key not found' : undefined
};
}
async updateData(key, data, options = {}) {
console.log(`Updating data with key: ${key}`);
if (!this.storage.has(key)) {
return {
success: false,
data: null,
error: 'Key not found'
};
}
this.storage.set(key, data);
return {
success: true,
data: { key }
};
}
async deleteData(key, options = {}) {
console.log(`Deleting data with key: ${key}`);
const existed = this.storage.has(key);
this.storage.delete(key);
return {
success: existed,
data: { deleted: existed },
error: !existed ? 'Key not found' : undefined
};
}
async listDataKeys(pattern = '*', options = {}) {
console.log(`Listing data keys with pattern: ${pattern}`);
// Simple implementation that returns all keys
// A real implementation would filter by pattern
const keys = Array.from(this.storage.keys());
return {
success: true,
data: { keys }
};
}
}
// Register the augmentations with the registry
// This will make them available to the Brainy library at runtime
const textSenseAugmentation = registerAugmentation(new CustomTextSenseAugmentation());
const memoryAugmentation = registerAugmentation(new CustomMemoryAugmentation());
console.log('Custom augmentations registered successfully');
// Export the registered augmentations for use in the application
export { textSenseAugmentation, memoryAugmentation };

View file

@ -1,158 +0,0 @@
/**
* Example: Using External Augmentation Plugins with Brainy
*
* This example demonstrates how to load and configure external augmentation plugins
* with the Brainy library. It shows how to use the plugin loader to integrate
* externally installed augmentation plugins into the Brainy system.
*/
import {
BrainyData,
configureAndStartPipeline,
createSensePluginConfig,
createConduitPluginConfig,
AugmentationType
} from '../dist/index.js';
// Create a new BrainyData instance
const db = new BrainyData();
await db.init();
console.log('BrainyData initialized successfully');
// Configure and start the augmentation pipeline with external plugins
// Note: These are example plugin names. You would need to install these packages via npm first.
const result = await configureAndStartPipeline([
// Sense augmentations (will be loaded first)
createSensePluginConfig('@example/text-sense-augmentation', {
language: 'english',
enableNER: true
}),
createSensePluginConfig('@example/image-sense-augmentation', {
modelSize: 'medium',
detectObjects: true
}),
// Conduit augmentations for two-way synchronization
createConduitPluginConfig('@example/websocket-conduit', {
url: 'wss://example.com/sync',
reconnectInterval: 5000
}),
createConduitPluginConfig('@example/webrtc-conduit', {
iceServers: [{ urls: 'stun:stun.example.com:19302' }],
peerConfig: { reliable: true }
}),
// Other augmentation types
{
plugin: '@example/memory-augmentation',
config: { storageType: 'persistent' },
type: AugmentationType.MEMORY
}
], {
// Optional: Customize the loading options
useDefaultPipeline: true, // Use the default pipeline instance
initializeAfterLoading: true, // Initialize augmentations after loading
augmentationOrder: [ // Custom order (Sense first, as recommended)
AugmentationType.SENSE,
AugmentationType.CONDUIT,
AugmentationType.MEMORY,
AugmentationType.COGNITION,
AugmentationType.PERCEPTION,
AugmentationType.DIALOG,
AugmentationType.ACTIVATION
]
});
// Check for any errors during loading
if (result.errors.length > 0) {
console.error('Errors occurred while loading plugins:');
result.errors.forEach(error => console.error(` - ${error.message}`));
} else {
console.log('All plugins loaded successfully');
}
// Get the pipeline instance
const { pipeline } = result;
// Get all loaded augmentations by type
console.log('Loaded augmentations:');
for (const [type, augmentations] of result.augmentations.entries()) {
if (augmentations.length > 0) {
console.log(`${type}: ${augmentations.map(a => a.name).join(', ')}`);
}
}
// Example: Using a sense augmentation to process raw data
try {
const senseResults = await pipeline.executeSensePipeline(
'processRawData',
['This is some example text to process', 'text']
);
// Process the results
for (const resultPromise of senseResults) {
const result = await resultPromise;
if (result.success) {
console.log('Processed data:', result.data);
// Insert the extracted nouns and verbs into BrainyData according to graphTypes
for (const noun of result.data.nouns) {
await db.add(noun, { type: 'noun' });
}
for (const verb of result.data.verbs) {
await db.add(verb, { type: 'verb' });
}
} else {
console.error('Error processing data:', result.error);
}
}
} catch (error) {
console.error('Error executing sense pipeline:', error);
}
// Example: Using a conduit augmentation for two-way synchronization
try {
// Establish a connection
const connectionResults = await pipeline.executeConduitPipeline(
'establishConnection',
['external-system', { apiKey: 'your-api-key' }]
);
// Process the results
for (const resultPromise of connectionResults) {
const result = await resultPromise;
if (result.success) {
console.log('Connection established:', result.data);
// Read data from the external system
const readResults = await pipeline.executeConduitPipeline(
'readData',
[{ query: 'get-latest-data' }]
);
// Process the read results
for (const readResultPromise of readResults) {
const readResult = await readResultPromise;
if (readResult.success) {
console.log('Data read from external system:', readResult.data);
// Write data to the external system
await pipeline.executeConduitPipeline(
'writeData',
[{ updatedData: 'example' }]
);
}
}
} else {
console.error('Error establishing connection:', result.error);
}
}
} catch (error) {
console.error('Error executing conduit pipeline:', error);
}
// Shut down the pipeline when done
await pipeline.shutDown();
console.log('Pipeline shut down successfully');

58
examples/rollup.config.js Normal file
View file

@ -0,0 +1,58 @@
/**
* Example rollup configuration for using the Brainy augmentation registry
*
* This example shows how to configure rollup to automatically discover and register
* augmentations at build time.
*/
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import { createAugmentationRegistryRollupPlugin } from '../dist/index.js';
export default {
// Entry point for the application
input: 'src/index.js',
// Output configuration
output: {
file: 'dist/bundle.js',
format: 'esm',
sourcemap: true
},
// Plugins
plugins: [
// Resolve node modules
resolve(),
// Convert CommonJS modules to ES6
commonjs(),
// Process TypeScript files
typescript(),
// Augmentation Registry Plugin
// This plugin will automatically discover and register augmentations
// from files that match the specified pattern
createAugmentationRegistryRollupPlugin({
// Pattern to match files containing augmentations
// This will match any file ending with 'augmentation.js' or 'augmentation.ts'
pattern: /augmentation\.(js|ts)$/,
// Options for the loader
options: {
// Automatically initialize augmentations after loading
autoInitialize: true,
// Log debug information during loading
debug: true
}
})
],
// External dependencies that should not be bundled
external: [
'brainy'
]
};

View file

@ -0,0 +1,81 @@
/**
* Example webpack configuration for using the Brainy augmentation registry
*
* This example shows how to configure webpack to automatically discover and register
* augmentations at build time.
*/
const path = require('path');
const { createAugmentationRegistryPlugin } = require('../dist/index.js');
module.exports = {
// Entry point for the application
entry: './src/index.js',
// Output configuration
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
// Module rules for processing different file types
module: {
rules: [
// Process JavaScript files with babel
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
// Process TypeScript files
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader'
}
}
]
},
// Resolve file extensions
resolve: {
extensions: ['.js', '.ts']
},
// Plugins
plugins: [
// Augmentation Registry Plugin
// This plugin will automatically discover and register augmentations
// from files that match the specified pattern
createAugmentationRegistryPlugin({
// Pattern to match files containing augmentations
// This will match any file ending with 'augmentation.js' or 'augmentation.ts'
pattern: /augmentation\.(js|ts)$/,
// Options for the loader
options: {
// Automatically initialize augmentations after loading
autoInitialize: true,
// Log debug information during loading
debug: true
}
})
],
// Development server configuration
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 9000,
}
};