refactor: prepare augmentation system for 2.0 clean architecture
- Removed factory function exports from index.ts - Removed unused augmentationFactory imports - Added deprecated type definitions temporarily to maintain compilation - Created REFACTOR-2.0-AUGMENTATIONS.md documenting cleanup plan - All old types marked as @deprecated for removal before final 2.0 This is an intermediate state - full refactor documented in REFACTOR-2.0-AUGMENTATIONS.md
This commit is contained in:
parent
a0dca5651f
commit
31720de34e
4 changed files with 93 additions and 114 deletions
67
REFACTOR-2.0-AUGMENTATIONS.md
Normal file
67
REFACTOR-2.0-AUGMENTATIONS.md
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
# Brainy 2.0 Augmentation System Refactoring TODO
|
||||||
|
|
||||||
|
## Current State
|
||||||
|
For the 2.0 release, we've marked the old augmentation type system as deprecated but kept it for now to maintain compilation. This document outlines what needs to be refactored for a truly clean 2.0 architecture.
|
||||||
|
|
||||||
|
## Files Requiring Major Refactoring
|
||||||
|
|
||||||
|
### 1. augmentationFactory.ts
|
||||||
|
- **Status**: Heavily dependent on old type system
|
||||||
|
- **Usage**: Only exports used in index.ts, not actually used in codebase
|
||||||
|
- **Action**: Can be completely removed after migrating any useful patterns to new system
|
||||||
|
|
||||||
|
### 2. augmentationPipeline.ts
|
||||||
|
- **Status**: Uses old ISenseAugmentation, IConduitAugmentation, etc. types
|
||||||
|
- **Usage**: Used by brainyData.ts for executing augmentation pipelines
|
||||||
|
- **Action**: Needs complete rewrite to use unified BrainyAugmentation interface
|
||||||
|
|
||||||
|
### 3. augmentationManager.ts
|
||||||
|
- **Status**: References AugmentationType enum
|
||||||
|
- **Usage**: Used for managing augmentations
|
||||||
|
- **Action**: Update to use string-based type identification
|
||||||
|
|
||||||
|
### 4. augmentationRegistry.ts
|
||||||
|
- **Status**: Uses old IAugmentation and AugmentationType
|
||||||
|
- **Usage**: Central registry for augmentations
|
||||||
|
- **Action**: Update to use BrainyAugmentation interface
|
||||||
|
|
||||||
|
### 5. cortex.ts
|
||||||
|
- **Status**: Imports old augmentation types
|
||||||
|
- **Usage**: Advanced augmentation orchestration
|
||||||
|
- **Action**: Update imports and type references
|
||||||
|
|
||||||
|
## Deprecated Types to Remove
|
||||||
|
|
||||||
|
All in `src/types/augmentations.ts`:
|
||||||
|
- `IAugmentation` - Replace with `BrainyAugmentation`
|
||||||
|
- `AugmentationType` enum - Replace with string literals
|
||||||
|
- `BrainyAugmentations` namespace - Remove entirely
|
||||||
|
- Individual type exports (ISenseAugmentation, etc.) - Remove
|
||||||
|
- `IWebSocketSupport` - Integrate into BrainyAugmentation if needed
|
||||||
|
|
||||||
|
## Clean Architecture Goals
|
||||||
|
|
||||||
|
1. **Single Interface**: All augmentations implement `BrainyAugmentation`
|
||||||
|
2. **No Type Enums**: Use string names for augmentation identification
|
||||||
|
3. **Simplified Factory**: Direct class instantiation instead of factory functions
|
||||||
|
4. **Unified Pipeline**: Single pipeline system for all augmentations
|
||||||
|
|
||||||
|
## Migration Strategy
|
||||||
|
|
||||||
|
1. **Phase 1**: (Current) Mark old types as deprecated, maintain compilation
|
||||||
|
2. **Phase 2**: Rewrite augmentationPipeline.ts to use unified interface
|
||||||
|
3. **Phase 3**: Update brainyData.ts to use new pipeline
|
||||||
|
4. **Phase 4**: Remove augmentationFactory.ts entirely
|
||||||
|
5. **Phase 5**: Remove all deprecated type definitions
|
||||||
|
|
||||||
|
## Benefits of Clean Architecture
|
||||||
|
|
||||||
|
- Simpler API surface
|
||||||
|
- Easier to understand and extend
|
||||||
|
- Better TypeScript type safety
|
||||||
|
- Reduced bundle size
|
||||||
|
- Cleaner documentation
|
||||||
|
|
||||||
|
## Timeline
|
||||||
|
|
||||||
|
This refactoring should be completed before the final 2.0 release to ensure a truly clean architecture.
|
||||||
|
|
@ -46,31 +46,6 @@ abstract class BaseConduitAugmentation extends BaseAugmentation {
|
||||||
): Promise<WebSocketConnection | null>
|
): Promise<WebSocketConnection | null>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* WebRTC Conduit Augmentation (placeholder for backwards compatibility)
|
|
||||||
* @deprecated Use WebSocketConduitAugmentation instead
|
|
||||||
*/
|
|
||||||
export class WebRTCConduitAugmentation extends BaseConduitAugmentation {
|
|
||||||
readonly name = 'webrtc-conduit'
|
|
||||||
|
|
||||||
async execute<T = any>(
|
|
||||||
operation: string,
|
|
||||||
params: any,
|
|
||||||
context?: AugmentationContext
|
|
||||||
): Promise<T | void> {
|
|
||||||
// Placeholder - WebRTC not yet implemented
|
|
||||||
this.log('WebRTC conduit not yet implemented, use WebSocket instead', 'warn')
|
|
||||||
}
|
|
||||||
|
|
||||||
async establishConnection(
|
|
||||||
targetSystemId: string,
|
|
||||||
config?: Record<string, unknown>
|
|
||||||
): Promise<WebSocketConnection | null> {
|
|
||||||
this.log('WebRTC conduit not yet implemented, use WebSocket instead', 'warn')
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocket Conduit Augmentation
|
* WebSocket Conduit Augmentation
|
||||||
* Syncs data between Brainy instances using WebSockets
|
* Syncs data between Brainy instances using WebSockets
|
||||||
|
|
|
||||||
74
src/index.ts
74
src/index.ts
|
|
@ -180,35 +180,7 @@ import {
|
||||||
|
|
||||||
// Sequential pipeline removed - use unified pipeline instead
|
// Sequential pipeline removed - use unified pipeline instead
|
||||||
|
|
||||||
// Export augmentation factory
|
// REMOVED: Old augmentation factory for 2.0 clean architecture
|
||||||
import {
|
|
||||||
createSenseAugmentation,
|
|
||||||
addWebSocketSupport,
|
|
||||||
executeAugmentation,
|
|
||||||
loadAugmentationModule,
|
|
||||||
AugmentationOptions
|
|
||||||
} from './augmentationFactory.js'
|
|
||||||
|
|
||||||
// Export factory functions for creating augmentations
|
|
||||||
import {
|
|
||||||
createSenseAugmentation,
|
|
||||||
createConduitAugmentation,
|
|
||||||
createCognitionAugmentation,
|
|
||||||
createMemoryAugmentation,
|
|
||||||
createPerceptionAugmentation,
|
|
||||||
createDialogAugmentation,
|
|
||||||
createActivationAugmentation
|
|
||||||
} from './augmentationFactory.js'
|
|
||||||
|
|
||||||
export {
|
|
||||||
createSenseAugmentation,
|
|
||||||
createConduitAugmentation,
|
|
||||||
createCognitionAugmentation,
|
|
||||||
createMemoryAugmentation,
|
|
||||||
createPerceptionAugmentation,
|
|
||||||
createDialogAugmentation,
|
|
||||||
createActivationAugmentation
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
// Unified pipeline exports
|
// Unified pipeline exports
|
||||||
|
|
@ -288,8 +260,7 @@ import {
|
||||||
createAutoStorageAugmentation
|
createAutoStorageAugmentation
|
||||||
} from './augmentations/storageAugmentations.js'
|
} from './augmentations/storageAugmentations.js'
|
||||||
import {
|
import {
|
||||||
WebSocketConduitAugmentation,
|
WebSocketConduitAugmentation
|
||||||
WebRTCConduitAugmentation
|
|
||||||
} from './augmentations/conduitAugmentations.js'
|
} from './augmentations/conduitAugmentations.js'
|
||||||
import {
|
import {
|
||||||
ServerSearchConduitAugmentation,
|
ServerSearchConduitAugmentation,
|
||||||
|
|
@ -365,45 +336,22 @@ export type {
|
||||||
|
|
||||||
// Export augmentation types
|
// Export augmentation types
|
||||||
import type {
|
import type {
|
||||||
IAugmentation,
|
|
||||||
AugmentationResponse,
|
AugmentationResponse,
|
||||||
IWebSocketSupport,
|
BrainyAugmentation,
|
||||||
ISenseAugmentation,
|
BaseAugmentation,
|
||||||
IConduitAugmentation,
|
AugmentationContext
|
||||||
ICognitionAugmentation,
|
|
||||||
IMemoryAugmentation,
|
|
||||||
IPerceptionAugmentation,
|
|
||||||
IDialogAugmentation,
|
|
||||||
IActivationAugmentation
|
|
||||||
} from './types/augmentations.js'
|
} from './types/augmentations.js'
|
||||||
import { AugmentationType, BrainyAugmentations } from './types/augmentations.js'
|
|
||||||
|
|
||||||
// Export augmentation manager for type-safe augmentation management
|
// Export augmentation manager for type-safe augmentation management
|
||||||
export { AugmentationManager, type AugmentationInfo } from './augmentationManager.js'
|
export { AugmentationManager, type AugmentationInfo } from './augmentationManager.js'
|
||||||
|
|
||||||
export type { IAugmentation, AugmentationResponse, IWebSocketSupport }
|
// Export only the clean augmentation types for 2.0
|
||||||
export {
|
|
||||||
AugmentationType,
|
|
||||||
BrainyAugmentations,
|
|
||||||
ISenseAugmentation,
|
|
||||||
IConduitAugmentation,
|
|
||||||
ICognitionAugmentation,
|
|
||||||
IMemoryAugmentation,
|
|
||||||
IPerceptionAugmentation,
|
|
||||||
IDialogAugmentation,
|
|
||||||
IActivationAugmentation
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export combined WebSocket augmentation interfaces
|
|
||||||
export type {
|
export type {
|
||||||
IWebSocketCognitionAugmentation,
|
AugmentationResponse,
|
||||||
IWebSocketSenseAugmentation,
|
BrainyAugmentation,
|
||||||
IWebSocketPerceptionAugmentation,
|
BaseAugmentation,
|
||||||
IWebSocketActivationAugmentation,
|
AugmentationContext
|
||||||
IWebSocketDialogAugmentation,
|
}
|
||||||
IWebSocketConduitAugmentation,
|
|
||||||
IWebSocketMemoryAugmentation
|
|
||||||
} from './types/augmentations.js'
|
|
||||||
|
|
||||||
// Export graph types
|
// Export graph types
|
||||||
import type {
|
import type {
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,12 @@ export type BaseAugmentation = BaseA
|
||||||
export type AugmentationContext = AC
|
export type AugmentationContext = AC
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Legacy compatibility - these are deprecated and should not be used in new code
|
* @deprecated - Being removed in 2.0 final. Use BrainyAugmentation directly
|
||||||
* @deprecated Use BrainyAugmentation instead
|
|
||||||
*/
|
*/
|
||||||
export type IAugmentation = BrainyAugmentation
|
export type IAugmentation = BrainyAugmentation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated AugmentationType enum is no longer used - augmentations are identified by name
|
* @deprecated - Being removed in 2.0 final
|
||||||
*/
|
*/
|
||||||
export enum AugmentationType {
|
export enum AugmentationType {
|
||||||
SENSE = 'sense',
|
SENSE = 'sense',
|
||||||
|
|
@ -67,20 +66,20 @@ export enum AugmentationType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use specific augmentation classes instead
|
* @deprecated - Being removed in 2.0 final. These are just aliases now
|
||||||
*/
|
*/
|
||||||
export namespace BrainyAugmentations {
|
export namespace BrainyAugmentations {
|
||||||
export interface ISenseAugmentation extends BrainyAugmentation {}
|
export type ISenseAugmentation = BrainyAugmentation
|
||||||
export interface IConduitAugmentation extends BrainyAugmentation {}
|
export type IConduitAugmentation = BrainyAugmentation
|
||||||
export interface ICognitionAugmentation extends BrainyAugmentation {}
|
export type ICognitionAugmentation = BrainyAugmentation
|
||||||
export interface IMemoryAugmentation extends BrainyAugmentation {}
|
export type IMemoryAugmentation = BrainyAugmentation
|
||||||
export interface IPerceptionAugmentation extends BrainyAugmentation {}
|
export type IPerceptionAugmentation = BrainyAugmentation
|
||||||
export interface IDialogAugmentation extends BrainyAugmentation {}
|
export type IDialogAugmentation = BrainyAugmentation
|
||||||
export interface IActivationAugmentation extends BrainyAugmentation {}
|
export type IActivationAugmentation = BrainyAugmentation
|
||||||
export interface ISynapseAugmentation extends BrainyAugmentation {}
|
export type ISynapseAugmentation = BrainyAugmentation
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export deprecated interfaces directly for compatibility
|
// Export as individual types for compatibility
|
||||||
export type ISenseAugmentation = BrainyAugmentations.ISenseAugmentation
|
export type ISenseAugmentation = BrainyAugmentations.ISenseAugmentation
|
||||||
export type IConduitAugmentation = BrainyAugmentations.IConduitAugmentation
|
export type IConduitAugmentation = BrainyAugmentations.IConduitAugmentation
|
||||||
export type ICognitionAugmentation = BrainyAugmentations.ICognitionAugmentation
|
export type ICognitionAugmentation = BrainyAugmentations.ICognitionAugmentation
|
||||||
|
|
@ -88,21 +87,11 @@ export type IMemoryAugmentation = BrainyAugmentations.IMemoryAugmentation
|
||||||
export type IPerceptionAugmentation = BrainyAugmentations.IPerceptionAugmentation
|
export type IPerceptionAugmentation = BrainyAugmentations.IPerceptionAugmentation
|
||||||
export type IDialogAugmentation = BrainyAugmentations.IDialogAugmentation
|
export type IDialogAugmentation = BrainyAugmentations.IDialogAugmentation
|
||||||
export type IActivationAugmentation = BrainyAugmentations.IActivationAugmentation
|
export type IActivationAugmentation = BrainyAugmentations.IActivationAugmentation
|
||||||
export type ISynapseAugmentation = BrainyAugmentations.ISynapseAugmentation
|
|
||||||
|
|
||||||
// WebSocket types for compatibility
|
|
||||||
export type IWebSocketCognitionAugmentation = ICognitionAugmentation & IWebSocketSupport
|
|
||||||
export type IWebSocketSenseAugmentation = ISenseAugmentation & IWebSocketSupport
|
|
||||||
export type IWebSocketPerceptionAugmentation = IPerceptionAugmentation & IWebSocketSupport
|
|
||||||
export type IWebSocketActivationAugmentation = IActivationAugmentation & IWebSocketSupport
|
|
||||||
export type IWebSocketDialogAugmentation = IDialogAugmentation & IWebSocketSupport
|
|
||||||
export type IWebSocketConduitAugmentation = IConduitAugmentation & IWebSocketSupport
|
|
||||||
export type IWebSocketMemoryAugmentation = IMemoryAugmentation & IWebSocketSupport
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use BrainyAugmentation instead
|
* @deprecated - Being removed in 2.0 final
|
||||||
*/
|
*/
|
||||||
export interface IWebSocketSupport extends BrainyAugmentation {
|
export interface IWebSocketSupport {
|
||||||
connectWebSocket?(url: string, protocols?: string | string[]): Promise<WebSocketConnection>
|
connectWebSocket?(url: string, protocols?: string | string[]): Promise<WebSocketConnection>
|
||||||
sendWebSocketMessage?(connectionId: string, data: unknown): Promise<void>
|
sendWebSocketMessage?(connectionId: string, data: unknown): Promise<void>
|
||||||
onWebSocketMessage?(connectionId: string, callback: DataCallback<unknown>): Promise<void>
|
onWebSocketMessage?(connectionId: string, callback: DataCallback<unknown>): Promise<void>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue