Skip to content

Commit 2b24e85

Browse files
committed
refactor: implement unified messaging API with elizaOS support
1 parent 0c2b7c9 commit 2b24e85

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/messageManager.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,22 @@ export class MessageManager {
692692
}
693693
};
694694

695-
// Call the message handler directly instead of emitting events
696-
// This provides a clearer, more traceable flow for message processing
697-
if (!this.runtime.messageService) {
695+
// Use elizaOS.handleMessage if available (unified messaging API with streaming support)
696+
// Falls back to direct messageService call for backward compatibility
697+
if (this.runtime.hasElizaOS()) {
698+
await this.runtime.elizaOS.handleMessage(this.runtime.agentId, memory, {
699+
onResponse: async (content) => {
700+
await callback(content);
701+
},
702+
});
703+
} else if (this.runtime.messageService) {
704+
await this.runtime.messageService.handleMessage(this.runtime, memory, callback);
705+
} else {
698706
logger.error('Message service is not available');
699707
throw new Error(
700708
'Message service is not initialized. Ensure the message service is properly configured.'
701709
);
702710
}
703-
await this.runtime.messageService.handleMessage(this.runtime, memory, callback);
704711
} catch (error) {
705712
logger.error(
706713
{

0 commit comments

Comments
 (0)