feat(FN-1065): add immediate message response mode for heartbeats
- Add MessageResponseMode and messageResponseMode runtime config to core agent heartbeat types and exports - Extend MessageStore with an onMessageToAgent hook plus runtime hook updates for agent-directed messages - Wire HeartbeatMonitor to wake agents on incoming messages when messageResponseMode is immediate and state is eligible - Update AgentDetailView with a Message Response Mode setting, validation, and runtimeConfig persistence - Expand core and engine tests to cover hook behavior, wake-on-message triggering, and start/stop hook lifecycle
This commit is contained in:
@@ -39,6 +39,8 @@ export interface MessageStoreEvents {
|
||||
export interface MessageStoreOptions {
|
||||
/** Root directory for kb data (default: .fusion) */
|
||||
rootDir?: string;
|
||||
/** Optional hook invoked when a message is addressed to an agent */
|
||||
onMessageToAgent?: (message: Message) => void;
|
||||
}
|
||||
|
||||
/** Index structure for mailbox lookups */
|
||||
@@ -55,12 +57,14 @@ export class MessageStore extends EventEmitter {
|
||||
private rootDir: string;
|
||||
private messagesDir: string;
|
||||
private indexPath: string;
|
||||
private onMessageToAgent?: (message: Message) => void;
|
||||
|
||||
constructor(options: MessageStoreOptions = {}) {
|
||||
super();
|
||||
this.rootDir = options.rootDir ?? ".fusion";
|
||||
this.messagesDir = join(this.rootDir, "messages");
|
||||
this.indexPath = join(this.messagesDir, "index.json");
|
||||
this.onMessageToAgent = options.onMessageToAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,6 +113,10 @@ export class MessageStore extends EventEmitter {
|
||||
this.emit("message:sent", message);
|
||||
this.emit("message:received", message);
|
||||
|
||||
if (message.toType === "agent" && this.onMessageToAgent) {
|
||||
this.onMessageToAgent(message);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -291,6 +299,13 @@ export class MessageStore extends EventEmitter {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or update the hook used when messages are sent to agents.
|
||||
*/
|
||||
setMessageToAgentHook(hook: (message: Message) => void): void {
|
||||
this.onMessageToAgent = hook;
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
// Private helpers
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user