Extract message runtime handoff adapter

This commit is contained in:
ejclaw
2026-04-29 11:54:38 +09:00
parent d6e7476ce0
commit 118c255ad2
3 changed files with 129 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import {
claimServiceHandoff,
completeServiceHandoffAndAdvanceTargetCursor,
failServiceHandoff,
getPairedTaskById,
getPendingServiceHandoffs,
type ServiceHandoff,
} from './db.js';
@@ -45,6 +46,36 @@ export function enqueuePendingHandoffs(args: {
}
}
export function enqueueMessageRuntimePendingHandoffs(args: {
enqueueTask?:
| ((chatJid: string, taskId: string, task: () => Promise<void>) => void)
| undefined;
getRoomBindings: () => Record<string, RegisteredGroup>;
channels: Channel[];
executeTurn: ExecuteTurnFn;
getLastAgentTimestamps: () => Record<string, string>;
saveState: () => void;
enqueueMessageCheck: (chatJid: string) => void;
}): void {
enqueuePendingHandoffs({
enqueueTask: (chatJid, taskId, task) => {
args.enqueueTask?.(chatJid, taskId, task);
},
processClaimedHandoff: async (handoff) => {
await processClaimedHandoff({
handoff,
getRoomBindings: args.getRoomBindings,
channels: args.channels,
executeTurn: args.executeTurn,
lastAgentTimestamps: args.getLastAgentTimestamps(),
saveState: args.saveState,
getPairedTaskById,
enqueueMessageCheck: args.enqueueMessageCheck,
});
},
});
}
function requeueFailedClaimedPairedTurn(args: {
handoff: ServiceHandoff;
error: string;