fix(auto-reply): acknowledge reset triggers
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import * as tauRpc from "../process/tau-rpc.js";
|
||||
@@ -75,6 +77,32 @@ describe("trigger handling", () => {
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("acknowledges a bare /new without treating it as empty", async () => {
|
||||
const commandSpy = vi.spyOn(commandReply, "runCommandReply");
|
||||
const res = await getReplyFromConfig(
|
||||
{
|
||||
Body: "/new",
|
||||
From: "+1003",
|
||||
To: "+2000",
|
||||
},
|
||||
{},
|
||||
{
|
||||
inbound: {
|
||||
reply: {
|
||||
mode: "command",
|
||||
command: ["echo", "{{Body}}"],
|
||||
session: {
|
||||
store: join(tmpdir(), `clawdis-session-test-${Date.now()}.json`),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toMatch(/fresh session/i);
|
||||
expect(commandSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores think directives that only appear in the context wrapper", async () => {
|
||||
const rpcMock = vi.spyOn(tauRpc, "runPiRpc").mockResolvedValue({
|
||||
stdout:
|
||||
|
||||
@@ -582,15 +582,24 @@ export async function getReplyFromConfig(
|
||||
? applyTemplate(reply.bodyPrefix ?? "", sessionCtx)
|
||||
: "";
|
||||
const baseBody = sessionCtx.BodyStripped ?? sessionCtx.Body ?? "";
|
||||
const baseBodyTrimmed = baseBody.trim();
|
||||
const rawBodyTrimmed = (ctx.Body ?? "").trim();
|
||||
const isBareSessionReset =
|
||||
isNewSession && baseBodyTrimmed.length === 0 && rawBodyTrimmed.length > 0;
|
||||
// Bail early if the cleaned body is empty to avoid sending blank prompts to the agent.
|
||||
// This can happen if an inbound platform delivers an empty text message or we strip everything out.
|
||||
if (!baseBody.trim()) {
|
||||
if (!baseBodyTrimmed) {
|
||||
await onReplyStart();
|
||||
if (isBareSessionReset) {
|
||||
cleanupTyping();
|
||||
return {
|
||||
text: "Started a fresh session. Send a new message to continue.",
|
||||
};
|
||||
}
|
||||
logVerbose("Inbound body empty after normalization; skipping agent run");
|
||||
cleanupTyping();
|
||||
return {
|
||||
text:
|
||||
"I didn't receive any text in your message. Please resend or add a caption.",
|
||||
text: "I didn't receive any text in your message. Please resend or add a caption.",
|
||||
};
|
||||
}
|
||||
const abortedHint =
|
||||
|
||||
Reference in New Issue
Block a user