From 398c120757d3fa121bf9b0fc482f57fc8023c150 Mon Sep 17 00:00:00 2001 From: dpsifr Date: Fri, 18 Jul 2025 15:38:42 -0700 Subject: [PATCH] feat(docs): add WebSocket augmentation examples in README - Documented various WebSocket augmentation types (`IWebSocketSupport`, `IWebSocketSenseAugmentation`, etc.) to guide developers in extending augmentations with WebSocket capabilities. - Added code example showcasing the creation of a WebSocket-enabled sense augmentation (`mySenseAug`) using `addWebSocketSupport`. - Explained the purpose of combining base augmentation interfaces with `IWebSocketSupport` for type safety and autocompletion. Purpose: Enhance developer documentation by providing clear guidance and examples for integrating WebSocket capabilities into augmentations. --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/README.md b/README.md index 1ee8e83e..c2c5b85d 100644 --- a/README.md +++ b/README.md @@ -906,6 +906,71 @@ The simplified augmentation system provides: 4. **Dynamic Loading** - Load augmentations at runtime when needed 5. **Static & Streaming Data** - Handle both static and streaming data with the same API +#### WebSocket Augmentation Types + +Brainy exports several WebSocket augmentation types that can be used by augmentation creators to add WebSocket capabilities to their augmentations: + +```typescript +import { + // Base WebSocket support interface + IWebSocketSupport, + + // Combined WebSocket augmentation types + IWebSocketSenseAugmentation, + IWebSocketConduitAugmentation, + IWebSocketCognitionAugmentation, + IWebSocketMemoryAugmentation, + IWebSocketPerceptionAugmentation, + IWebSocketDialogAugmentation, + IWebSocketActivationAugmentation, + + // Function to add WebSocket support to any augmentation + addWebSocketSupport +} from '@soulcraft/brainy' + +// Example: Creating a typed WebSocket-enabled sense augmentation +const mySenseAug = createSenseAugmentation({ + name: 'my-sense', + processRawData: async (data, dataType) => { + // Implementation + return { + success: true, + data: { nouns: [], verbs: [] } + } + } +}) as IWebSocketSenseAugmentation + +// Add WebSocket support +addWebSocketSupport(mySenseAug, { + connectWebSocket: async (url) => { + // WebSocket implementation + return { + connectionId: 'ws-1', + url, + status: 'connected' + } + }, + sendWebSocketMessage: async (connectionId, data) => { + // Send message implementation + }, + onWebSocketMessage: async (connectionId, callback) => { + // Register callback implementation + }, + offWebSocketMessage: async (connectionId, callback) => { + // Remove callback implementation + }, + closeWebSocket: async (connectionId, code, reason) => { + // Close connection implementation + } +}) + +// Now mySenseAug has both sense augmentation methods and WebSocket methods +await mySenseAug.processRawData('data', 'text') +await mySenseAug.connectWebSocket('wss://example.com') +``` + +These WebSocket augmentation types combine the base augmentation interfaces with the `IWebSocketSupport` interface, providing type safety and autocompletion for augmentations with WebSocket capabilities. + ### Model Control Protocol (MCP) Brainy includes a Model Control Protocol (MCP) implementation that allows external models to access Brainy data and use