mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:50:43 +00:00
fix(auto-reply): avoid duplicate reset hook acknowledgements
This commit is contained in:
@@ -251,7 +251,7 @@ describe("handleCommands reset hooks", () => {
|
||||
},
|
||||
);
|
||||
|
||||
await maybeHandleResetCommand(params);
|
||||
const result = await maybeHandleResetCommand(params);
|
||||
|
||||
expect(routeReplyMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -262,6 +262,7 @@ describe("handleCommands reset hooks", () => {
|
||||
threadId: "thread-1",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({ shouldContinue: false });
|
||||
});
|
||||
|
||||
it("prefers the target session entry when emitting reset hooks", async () => {
|
||||
|
||||
@@ -104,7 +104,7 @@ export async function emitResetCommandHooks(params: {
|
||||
sessionEntry?: HandleCommandsParams["sessionEntry"];
|
||||
previousSessionEntry?: HandleCommandsParams["previousSessionEntry"];
|
||||
workspaceDir: string;
|
||||
}): Promise<void> {
|
||||
}): Promise<{ routedReply: boolean }> {
|
||||
const hookEvent = createInternalHookEvent("command", params.action, params.sessionKey ?? "", {
|
||||
sessionEntry: params.sessionEntry,
|
||||
previousSessionEntry: params.previousSessionEntry,
|
||||
@@ -116,6 +116,7 @@ export async function emitResetCommandHooks(params: {
|
||||
await triggerInternalHook(hookEvent);
|
||||
params.command.resetHookTriggered = true;
|
||||
|
||||
let routedReply = false;
|
||||
if (hookEvent.messages.length > 0) {
|
||||
const channel = params.ctx.OriginatingChannel || params.command.channel;
|
||||
const to = params.ctx.OriginatingTo || params.command.from || params.command.to;
|
||||
@@ -134,6 +135,7 @@ export async function emitResetCommandHooks(params: {
|
||||
threadId: params.ctx.MessageThreadId,
|
||||
cfg: params.cfg,
|
||||
});
|
||||
routedReply = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,4 +162,5 @@ export async function emitResetCommandHooks(params: {
|
||||
}
|
||||
})();
|
||||
}
|
||||
return { routedReply };
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ export async function maybeHandleResetCommand(
|
||||
|
||||
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
|
||||
|
||||
await emitResetCommandHooks({
|
||||
const hookResult = await emitResetCommandHooks({
|
||||
action: commandAction,
|
||||
ctx: params.ctx,
|
||||
cfg: params.cfg,
|
||||
@@ -169,9 +169,13 @@ export async function maybeHandleResetCommand(
|
||||
if (!resetTail) {
|
||||
return {
|
||||
shouldContinue: false,
|
||||
reply: {
|
||||
text: commandAction === "reset" ? "✅ Session reset." : "✅ New session started.",
|
||||
},
|
||||
...(hookResult.routedReply
|
||||
? {}
|
||||
: {
|
||||
reply: {
|
||||
text: commandAction === "reset" ? "✅ Session reset." : "✅ New session started.",
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user