Skip to content

Commit

Permalink
Fix channels
Browse files Browse the repository at this point in the history
  • Loading branch information
parzival418 committed Nov 27, 2024
1 parent e6409c8 commit 82f4d86
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/server/agents/src/lib/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,39 +217,41 @@ export class Agent

// Set up global event routing to channels with debug logging
this.on('messageReceived', (data: ActionPayload) => {
console.log('Agent received messageReceived event:', data)
const channelId = (data as any)?.channel
const channelId = data?.event?.channel
if (channelId && this.channels.has(channelId)) {
console.log(`Forwarding messageReceived to channel ${channelId}`)
this.channels.get(channelId)!.emit('messageReceived', data)
} else {
console.log('No channel found for messageReceived:', {
channelId,
data,
})
}
})

this.on('message', (data: EventPayload) => {
console.log('Agent received message event:', data)
const channelId = (data as any)?.channel
const channelId = data.channel
if (channelId && this.channels.has(channelId)) {
console.log(`Forwarding message to channel ${channelId}`)
this.channels.get(channelId)!.emit('message', data)
}
})

this.on('messageStream', (data: ActionPayload) => {
const channelId = (data as any)?.channel
const channelId = data.event.channel
if (channelId && this.channels.has(channelId)) {
this.channels.get(channelId)!.emit('messageStream', data)
}
})

this.on('eventComplete', (data: EventPayload | null) => {
const channelId = (data as any)?.channel
const channelId = data?.channel
if (channelId && this.channels.has(channelId)) {
this.channels.get(channelId)!.emit('eventComplete', data)
}
})

this.on('error', (data: ActionPayload) => {
const channelId = (data as any)?.channel
const channelId = data.event.channel
if (channelId && this.channels.has(channelId)) {
this.channels.get(channelId)!.emit('error', data)
}
Expand Down

0 comments on commit 82f4d86

Please sign in to comment.