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:
parent
7d2b695ea0
commit
203b669203
22 changed files with 1063 additions and 541 deletions
110
README.md
110
README.md
|
|
@ -577,88 +577,52 @@ This enum can be used by consumers of the library to identify the different type
|
|||
|
||||
Brainy provides an event pipeline that allows registering and executing multiple augmentations of each type. The pipeline supports different execution modes and provides a flexible way to manage augmentations.
|
||||
|
||||
#### Using External Augmentation Plugins
|
||||
### Installing Custom Augmentations
|
||||
|
||||
Brainy provides a plugin loader that makes it easy to load and configure augmentation plugins from external npm packages. This allows you to extend Brainy's capabilities with specialized augmentations developed by third parties or maintained in separate packages.
|
||||
Brainy provides a build-time registration system for installing custom augmentations in your application:
|
||||
|
||||
#### Build-Time Registration
|
||||
|
||||
For better performance and bundle optimization, you can register augmentations at build time:
|
||||
|
||||
```typescript
|
||||
import {
|
||||
BrainyData,
|
||||
configureAndStartPipeline,
|
||||
createSensePluginConfig,
|
||||
createConduitPluginConfig,
|
||||
AugmentationType
|
||||
} from '@soulcraft/brainy';
|
||||
// myCustomAugmentation.ts
|
||||
import { registerAugmentation, AugmentationType } from '@soulcraft/brainy';
|
||||
|
||||
// Create a new BrainyData instance
|
||||
const db = new BrainyData();
|
||||
await db.init();
|
||||
|
||||
// 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
|
||||
}),
|
||||
|
||||
// Conduit augmentations for two-way synchronization
|
||||
createConduitPluginConfig('@example/websocket-conduit', {
|
||||
url: 'wss://example.com/sync',
|
||||
reconnectInterval: 5000
|
||||
}),
|
||||
|
||||
// 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
|
||||
]
|
||||
});
|
||||
|
||||
// Get the pipeline instance
|
||||
const { pipeline } = result;
|
||||
|
||||
// Use the pipeline to execute augmentations
|
||||
const senseResults = await pipeline.executeSensePipeline(
|
||||
'processRawData',
|
||||
['This is some example text to process', 'text']
|
||||
);
|
||||
|
||||
// Process the results and insert data into BrainyData
|
||||
for (const resultPromise of senseResults) {
|
||||
const result = await resultPromise;
|
||||
if (result.success) {
|
||||
// Insert the extracted nouns and verbs into BrainyData according to graphTypes
|
||||
for (const noun of result.data.nouns) {
|
||||
await db.add(noun, { type: 'noun' });
|
||||
}
|
||||
}
|
||||
// Create your custom augmentation
|
||||
class MyCustomAugmentation {
|
||||
// Implement required methods...
|
||||
}
|
||||
|
||||
// Register it with the registry
|
||||
export const myAugmentation = registerAugmentation(new MyCustomAugmentation());
|
||||
```
|
||||
|
||||
The plugin loader provides several functions for working with external plugins:
|
||||
Then configure your build tool (webpack or rollup) to automatically discover and register these augmentations:
|
||||
|
||||
- `loadPlugins(plugins, options)`: Loads augmentation plugins from external npm packages
|
||||
- `configureAndStartPipeline(plugins, options)`: Configures and starts the augmentation pipeline with the specified plugins
|
||||
- `createSensePluginConfig(plugin, config)`: Creates a plugin configuration for a sense augmentation
|
||||
- `createConduitPluginConfig(plugin, config)`: Creates a plugin configuration for a conduit augmentation
|
||||
```javascript
|
||||
// webpack.config.js
|
||||
const { createAugmentationRegistryPlugin } = require('@soulcraft/brainy');
|
||||
|
||||
module.exports = {
|
||||
// ... other webpack config
|
||||
plugins: [
|
||||
createAugmentationRegistryPlugin({
|
||||
pattern: /augmentation\.(js|ts)$/,
|
||||
options: { autoInitialize: true }
|
||||
})
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
Benefits of build-time registration:
|
||||
- Better performance as augmentations are available immediately at startup
|
||||
- Improved tree-shaking and bundle optimization
|
||||
- Type safety and better IDE support
|
||||
- No need for dynamic imports or async loading
|
||||
|
||||
For detailed documentation on build-time augmentation registration, see [build-time-augmentations.md](docs/build-time-augmentations.md).
|
||||
|
||||
For more details, see the [externalPlugins.js](examples/externalPlugins.js) example.
|
||||
|
||||
#### Using the Pipeline Directly
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue