Skip to content

Commit 464d89a

Browse files
committed
v1.8.0-stream-behavior - added and default methods, and on agent class
1 parent 1eb8880 commit 464d89a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pompeii-labs/magma",
3-
"version": "1.7.7",
3+
"version": "1.8.0",
44
"description": "The Typescript framework to build AI agents quickly and easily",
55
"keywords": [
66
"Agents",

src/agent.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import OpenAI from 'openai';
3737
import Anthropic from '@anthropic-ai/sdk';
3838
import Groq from 'groq-sdk';
3939
import cron from 'node-cron';
40+
import { WebSocket } from 'ws';
4041
import { GoogleGenerativeAI } from '@google/generative-ai';
4142

4243
const kMiddlewareMaxRetries = 5;
@@ -45,11 +46,15 @@ type AgentProps = MagmaProviderConfig & {
4546
verbose?: boolean;
4647
messageContext?: number;
4748
stream?: boolean;
49+
sessionId?: string;
4850
};
4951

5052
export 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

Comments
 (0)