refactor: clean augmentation system for 2.0 architecture
- Fixed ServerSearchActivationAugmentation to extend BaseAugmentation - Fixed SynapseAugmentation to extend BaseAugmentation - Cleaned up old type system (kept minimal exports for compilation) - Created comprehensive augmentations reference doc (27 total) - 21 augmentations already using clean system (78%) - Fixed the 2 high-priority ones needing migration - Added complete documentation for all working augmentations Key stats: - 8 Storage augmentations (all clean) - 7 Performance augmentations (all clean) - 3 Data Integrity augmentations (all clean) - 2 Intelligence augmentations (all clean) - 4 Communication augmentations (now all clean) - 2 External Integration augmentations (now all clean)
This commit is contained in:
parent
63b6f9052d
commit
d2afc747d4
4 changed files with 475 additions and 100 deletions
|
|
@ -6,13 +6,10 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
AugmentationType,
|
||||
IConduitAugmentation,
|
||||
IActivationAugmentation,
|
||||
IWebSocketSupport,
|
||||
AugmentationResponse,
|
||||
WebSocketConnection
|
||||
} from '../types/augmentations.js'
|
||||
import { BaseAugmentation, AugmentationContext } from '../augmentations/brainyAugmentation.js'
|
||||
import { WebSocketConduitAugmentation } from './conduitAugmentations.js'
|
||||
import { v4 as uuidv4 } from '../universal/uuid.js'
|
||||
import { BrainyDataInterface } from '../types/brainyDataInterface.js'
|
||||
|
|
@ -316,48 +313,45 @@ export class ServerSearchConduitAugmentation extends WebSocketConduitAugmentatio
|
|||
*
|
||||
* An activation augmentation that provides actions for server search functionality.
|
||||
*/
|
||||
export class ServerSearchActivationAugmentation
|
||||
implements IActivationAugmentation
|
||||
{
|
||||
readonly name: string
|
||||
readonly description: string
|
||||
enabled: boolean = true
|
||||
private isInitialized = false
|
||||
export class ServerSearchActivationAugmentation extends BaseAugmentation {
|
||||
readonly timing = 'after' as const
|
||||
readonly operations = ['search', 'addNoun'] as const
|
||||
readonly priority = 20
|
||||
|
||||
private conduitAugmentation: ServerSearchConduitAugmentation | null = null
|
||||
private connections: Map<string, WebSocketConnection> = new Map()
|
||||
|
||||
constructor(name: string = 'server-search-activation') {
|
||||
this.name = name
|
||||
super(name)
|
||||
this.description = 'Activation augmentation for server-hosted Brainy search'
|
||||
}
|
||||
|
||||
getType(): AugmentationType {
|
||||
return AugmentationType.ACTIVATION
|
||||
protected async onInit(): Promise<void> {
|
||||
// Initialization logic if needed
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the augmentation
|
||||
*/
|
||||
async initialize(): Promise<void> {
|
||||
if (this.isInitialized) {
|
||||
return
|
||||
protected async onShutdown(): Promise<void> {
|
||||
// Cleanup connections
|
||||
this.connections.clear()
|
||||
}
|
||||
|
||||
async execute<T = any>(
|
||||
operation: string,
|
||||
params: any,
|
||||
context?: AugmentationContext
|
||||
): Promise<T | void> {
|
||||
// Handle server search operations
|
||||
if (operation === 'search' && this.conduitAugmentation) {
|
||||
// Trigger server search when local search happens
|
||||
const connectionId = this.connections.keys().next().value
|
||||
if (connectionId && params.query) {
|
||||
await this.conduitAugmentation.searchServer(
|
||||
connectionId,
|
||||
params.query,
|
||||
params.limit || 10
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
this.isInitialized = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down the augmentation
|
||||
*/
|
||||
async shutDown(): Promise<void> {
|
||||
this.isInitialized = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of the augmentation
|
||||
*/
|
||||
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
|
||||
return this.isInitialized ? 'active' : 'inactive'
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,31 +18,26 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
ISynapseAugmentation,
|
||||
AugmentationResponse
|
||||
} from '../types/augmentations.js'
|
||||
import { BrainyAugmentation, AugmentationContext } from './brainyAugmentation.js'
|
||||
import { BaseAugmentation, BrainyAugmentation, AugmentationContext } from './brainyAugmentation.js'
|
||||
import { NeuralImportAugmentation } from './neuralImport.js'
|
||||
|
||||
/**
|
||||
* Base class for all synapse augmentations
|
||||
* Provides common functionality for external data synchronization
|
||||
*/
|
||||
export abstract class SynapseAugmentation implements ISynapseAugmentation, BrainyAugmentation {
|
||||
export abstract class SynapseAugmentation extends BaseAugmentation {
|
||||
// BrainyAugmentation properties
|
||||
abstract readonly name: string
|
||||
abstract readonly description: string
|
||||
readonly timing = 'after' as const
|
||||
readonly operations = ['all'] as ('all')[]
|
||||
readonly priority = 10
|
||||
|
||||
// ISynapseAugmentation properties
|
||||
// Synapse-specific properties
|
||||
abstract readonly synapseId: string
|
||||
abstract readonly supportedTypes: string[]
|
||||
|
||||
// State management
|
||||
enabled = true
|
||||
protected context?: AugmentationContext
|
||||
protected syncInProgress = false
|
||||
protected lastSyncId?: string
|
||||
protected syncStats = {
|
||||
|
|
@ -55,17 +50,13 @@ export abstract class SynapseAugmentation implements ISynapseAugmentation, Brain
|
|||
protected neuralImport?: NeuralImportAugmentation
|
||||
protected useNeuralImport = true // Enable by default
|
||||
|
||||
/**
|
||||
* Initialize the synapse with BrainyData context
|
||||
*/
|
||||
async initialize(context: AugmentationContext): Promise<void> {
|
||||
this.context = context
|
||||
protected async onInit(): Promise<void> {
|
||||
|
||||
// Initialize Neural Import if available
|
||||
if (this.useNeuralImport && context.brain) {
|
||||
if (this.useNeuralImport && this.context?.brain) {
|
||||
try {
|
||||
// Check if neural import is already loaded
|
||||
const existingNeuralImport = context.brain.augmentations?.get('neural-import')
|
||||
const existingNeuralImport = this.context.brain.augmentations?.get('neural-import')
|
||||
if (existingNeuralImport) {
|
||||
this.neuralImport = existingNeuralImport as NeuralImportAugmentation
|
||||
} else {
|
||||
|
|
@ -133,21 +124,18 @@ export abstract class SynapseAugmentation implements ISynapseAugmentation, Brain
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IAugmentation required methods
|
||||
*/
|
||||
async shutDown(): Promise<void> {
|
||||
protected async onShutdown(): Promise<void> {
|
||||
if (this.syncInProgress) {
|
||||
await this.stopSync()
|
||||
}
|
||||
await this.onShutdown()
|
||||
await this.onSynapseShutdown()
|
||||
}
|
||||
|
||||
protected async onShutdown(): Promise<void> {
|
||||
protected async onSynapseShutdown(): Promise<void> {
|
||||
// Override in implementations for cleanup
|
||||
}
|
||||
|
||||
async getStatus(): Promise<'active' | 'inactive' | 'error'> {
|
||||
async getSynapseStatus(): Promise<'active' | 'inactive' | 'error'> {
|
||||
try {
|
||||
const result = await this.testConnection()
|
||||
return result.success ? 'active' : 'error'
|
||||
|
|
|
|||
|
|
@ -45,29 +45,12 @@ export type BrainyAugmentation = BA
|
|||
export type BaseAugmentation = BaseA
|
||||
export type AugmentationContext = AC
|
||||
|
||||
/**
|
||||
* @deprecated - Being removed in 2.0 final. Use BrainyAugmentation directly
|
||||
*/
|
||||
// REMOVED: Old augmentation type system for 2.0 clean architecture
|
||||
// All augmentations now use the unified BrainyAugmentation interface from brainyAugmentation.ts
|
||||
|
||||
// Temporary exports for compilation - TO BE REMOVED
|
||||
export type IAugmentation = BrainyAugmentation
|
||||
|
||||
/**
|
||||
* @deprecated - Being removed in 2.0 final
|
||||
*/
|
||||
export enum AugmentationType {
|
||||
SENSE = 'sense',
|
||||
CONDUIT = 'conduit',
|
||||
COGNITION = 'cognition',
|
||||
MEMORY = 'memory',
|
||||
PERCEPTION = 'perception',
|
||||
DIALOG = 'dialog',
|
||||
ACTIVATION = 'activation',
|
||||
WEBSOCKET = 'webSocket',
|
||||
SYNAPSE = 'synapse'
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - Being removed in 2.0 final. These are just aliases now
|
||||
*/
|
||||
export enum AugmentationType { SENSE = 'sense', CONDUIT = 'conduit', COGNITION = 'cognition', MEMORY = 'memory', PERCEPTION = 'perception', DIALOG = 'dialog', ACTIVATION = 'activation', WEBSOCKET = 'webSocket', SYNAPSE = 'synapse' }
|
||||
export namespace BrainyAugmentations {
|
||||
export type ISenseAugmentation = BrainyAugmentation
|
||||
export type IConduitAugmentation = BrainyAugmentation
|
||||
|
|
@ -78,23 +61,12 @@ export namespace BrainyAugmentations {
|
|||
export type IActivationAugmentation = BrainyAugmentation
|
||||
export type ISynapseAugmentation = BrainyAugmentation
|
||||
}
|
||||
|
||||
// Export as individual types for compatibility
|
||||
export type ISenseAugmentation = BrainyAugmentations.ISenseAugmentation
|
||||
export type IConduitAugmentation = BrainyAugmentations.IConduitAugmentation
|
||||
export type ICognitionAugmentation = BrainyAugmentations.ICognitionAugmentation
|
||||
export type IMemoryAugmentation = BrainyAugmentations.IMemoryAugmentation
|
||||
export type IPerceptionAugmentation = BrainyAugmentations.IPerceptionAugmentation
|
||||
export type IDialogAugmentation = BrainyAugmentations.IDialogAugmentation
|
||||
export type IActivationAugmentation = BrainyAugmentations.IActivationAugmentation
|
||||
|
||||
/**
|
||||
* @deprecated - Being removed in 2.0 final
|
||||
*/
|
||||
export interface IWebSocketSupport {
|
||||
connectWebSocket?(url: string, protocols?: string | string[]): Promise<WebSocketConnection>
|
||||
sendWebSocketMessage?(connectionId: string, data: unknown): Promise<void>
|
||||
onWebSocketMessage?(connectionId: string, callback: DataCallback<unknown>): Promise<void>
|
||||
offWebSocketMessage?(connectionId: string, callback: DataCallback<unknown>): Promise<void>
|
||||
closeWebSocket?(connectionId: string, code?: number, reason?: string): Promise<void>
|
||||
}
|
||||
export type ISenseAugmentation = BrainyAugmentation
|
||||
export type IConduitAugmentation = BrainyAugmentation
|
||||
export type ICognitionAugmentation = BrainyAugmentation
|
||||
export type IMemoryAugmentation = BrainyAugmentation
|
||||
export type IPerceptionAugmentation = BrainyAugmentation
|
||||
export type IDialogAugmentation = BrainyAugmentation
|
||||
export type IActivationAugmentation = BrainyAugmentation
|
||||
export type ISynapseAugmentation = BrainyAugmentation
|
||||
export interface IWebSocketSupport {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue