@@ -37,6 +37,7 @@ import OpenAI from 'openai';
3737import Anthropic from '@anthropic-ai/sdk' ;
3838import Groq from 'groq-sdk' ;
3939import cron from 'node-cron' ;
40+ import { WebSocket } from 'ws' ;
4041import { GoogleGenerativeAI } from '@google/generative-ai' ;
4142
4243const kMiddlewareMaxRetries = 5 ;
@@ -45,11 +46,15 @@ type AgentProps = MagmaProviderConfig & {
4546 verbose ?: boolean ;
4647 messageContext ?: number ;
4748 stream ?: boolean ;
49+ sessionId ?: string ;
4850} ;
4951
5052export class MagmaAgent {
5153 verbose ?: boolean ;
5254 stream : boolean = false ;
55+ public ws : WebSocket | null = null ;
56+ public sessionId : string ;
57+
5358 private providerConfig : MagmaProviderConfig = {
5459 provider : 'openai' ,
5560 model : 'gpt-4.1' ,
@@ -65,6 +70,7 @@ export class MagmaAgent {
6570 this . messageContext = args ?. messageContext ?? 20 ;
6671 this . verbose = args ?. verbose ?? false ;
6772 this . stream = args ?. stream ?? false ;
73+ this . sessionId = args ?. sessionId ?? '' ;
6874
6975 args ??= {
7076 provider : 'anthropic' ,
@@ -101,7 +107,15 @@ export class MagmaAgent {
101107 * Optional method to receive input from the user
102108 * @param message message object received from the user - type to be defined by extending class
103109 */
104- public async receive ?( message : any ) : Promise < void > { }
110+ public async receive ?( message : any ) : Promise < void > { }
111+
112+ /**
113+ * Sends data to the connected client depending on the medium (ws, SSE, etc)
114+ * @param message any data object to be sent to the client
115+ */
116+ public async send ( message : Record < string , any > ) : Promise < void > { }
117+
118+ public async onWsClose ( code : number , reason ?: string ) : Promise < void > { }
105119
106120 public async cleanup ( ) : Promise < void > {
107121 try {
0 commit comments