fix: suppress heartbeat directive acks and add coverage
This commit is contained in:
@@ -85,4 +85,39 @@ describe("trigger handling", () => {
|
|||||||
expect(prompt).toContain("Give me the status");
|
expect(prompt).toContain("Give me the status");
|
||||||
expect(prompt).not.toContain("/thinking high");
|
expect(prompt).not.toContain("/thinking high");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not emit directive acks for heartbeats with /think", async () => {
|
||||||
|
const rpcMock = vi.spyOn(tauRpc, "runPiRpc").mockResolvedValue({
|
||||||
|
stdout:
|
||||||
|
'{"type":"message_end","message":{"role":"assistant","content":[{"type":"text","text":"ok"}]}}',
|
||||||
|
stderr: "",
|
||||||
|
code: 0,
|
||||||
|
signal: null,
|
||||||
|
killed: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await getReplyFromConfig(
|
||||||
|
{
|
||||||
|
Body: "HEARTBEAT /think:high",
|
||||||
|
From: "+1003",
|
||||||
|
To: "+1003",
|
||||||
|
},
|
||||||
|
{ isHeartbeat: true },
|
||||||
|
{
|
||||||
|
inbound: {
|
||||||
|
reply: {
|
||||||
|
mode: "command",
|
||||||
|
command: ["pi", "{{Body}}"],
|
||||||
|
agent: { kind: "pi" },
|
||||||
|
session: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||||
|
expect(text).toBe("ok");
|
||||||
|
expect(text).not.toMatch(/Thinking level set/i);
|
||||||
|
expect(rpcMock).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -329,6 +329,7 @@ export async function getReplyFromConfig(
|
|||||||
const isGroup =
|
const isGroup =
|
||||||
typeof ctx.From === "string" &&
|
typeof ctx.From === "string" &&
|
||||||
(ctx.From.includes("@g.us") || ctx.From.startsWith("group:"));
|
(ctx.From.includes("@g.us") || ctx.From.startsWith("group:"));
|
||||||
|
const isHeartbeat = opts?.isHeartbeat === true;
|
||||||
|
|
||||||
let resolvedThinkLevel =
|
let resolvedThinkLevel =
|
||||||
inlineThink ??
|
inlineThink ??
|
||||||
@@ -359,7 +360,7 @@ export async function getReplyFromConfig(
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// Directive-only message => persist session thinking level and return ack
|
// Directive-only message => persist session thinking level and return ack
|
||||||
if (directiveOnly || combinedDirectiveOnly) {
|
if (!isHeartbeat && (directiveOnly || combinedDirectiveOnly)) {
|
||||||
if (!inlineThink) {
|
if (!inlineThink) {
|
||||||
cleanupTyping();
|
cleanupTyping();
|
||||||
return {
|
return {
|
||||||
@@ -425,7 +426,7 @@ export async function getReplyFromConfig(
|
|||||||
return noMentions.length === 0;
|
return noMentions.length === 0;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if (verboseDirectiveOnly) {
|
if (!isHeartbeat && verboseDirectiveOnly) {
|
||||||
if (!inlineVerbose) {
|
if (!inlineVerbose) {
|
||||||
cleanupTyping();
|
cleanupTyping();
|
||||||
return {
|
return {
|
||||||
@@ -451,7 +452,7 @@ export async function getReplyFromConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If any directive (think/verbose) is present anywhere, acknowledge immediately and skip agent execution.
|
// If any directive (think/verbose) is present anywhere, acknowledge immediately and skip agent execution.
|
||||||
if (hasThinkDirective || hasVerboseDirective) {
|
if (!isHeartbeat && (hasThinkDirective || hasVerboseDirective)) {
|
||||||
if (sessionEntry && sessionStore && sessionKey) {
|
if (sessionEntry && sessionStore && sessionKey) {
|
||||||
if (hasThinkDirective && inlineThink) {
|
if (hasThinkDirective && inlineThink) {
|
||||||
if (inlineThink === "off") {
|
if (inlineThink === "off") {
|
||||||
@@ -694,8 +695,6 @@ export async function getReplyFromConfig(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isHeartbeat = opts?.isHeartbeat === true;
|
|
||||||
|
|
||||||
if (reply && reply.mode === "command") {
|
if (reply && reply.mode === "command") {
|
||||||
const heartbeatCommand = isHeartbeat
|
const heartbeatCommand = isHeartbeat
|
||||||
? (reply as { heartbeatCommand?: string[] }).heartbeatCommand
|
? (reply as { heartbeatCommand?: string[] }).heartbeatCommand
|
||||||
|
|||||||
Reference in New Issue
Block a user