fix: allow inline directives to continue and add mixed-message test
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { extractVerboseDirective, extractThinkDirective } from "./reply.js";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import * as tauRpc from "../process/tau-rpc.js";
|
||||
import { getReplyFromConfig, extractVerboseDirective, extractThinkDirective } from "./reply.js";
|
||||
|
||||
describe("directive parsing", () => {
|
||||
it("ignores verbose directive inside URL", () => {
|
||||
@@ -26,4 +27,38 @@ describe("directive parsing", () => {
|
||||
expect(res.hasDirective).toBe(true);
|
||||
expect(res.thinkLevel).toBe("high");
|
||||
});
|
||||
|
||||
it("applies inline think and still runs agent content", async () => {
|
||||
const rpcMock = vi.spyOn(tauRpc, "runPiRpc").mockResolvedValue({
|
||||
stdout:
|
||||
'{"type":"message_end","message":{"role":"assistant","content":[{"type":"text","text":"done"}]}}',
|
||||
stderr: "",
|
||||
code: 0,
|
||||
signal: null,
|
||||
killed: false,
|
||||
});
|
||||
|
||||
const res = await getReplyFromConfig(
|
||||
{
|
||||
Body: "please sync /think:high now",
|
||||
From: "+1004",
|
||||
To: "+2000",
|
||||
},
|
||||
{},
|
||||
{
|
||||
inbound: {
|
||||
reply: {
|
||||
mode: "command",
|
||||
command: ["pi", "{{Body}}"],
|
||||
agent: { kind: "pi" },
|
||||
session: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toBe("done");
|
||||
expect(rpcMock).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -451,8 +451,8 @@ export async function getReplyFromConfig(
|
||||
return { text: ack };
|
||||
}
|
||||
|
||||
// If any directive (think/verbose) is present anywhere, acknowledge immediately and skip agent execution.
|
||||
if (!isHeartbeat && (hasThinkDirective || hasVerboseDirective)) {
|
||||
// If directives are inline with other text: persist levels, then continue to agent (no early ack).
|
||||
if (hasThinkDirective || hasVerboseDirective) {
|
||||
if (sessionEntry && sessionStore && sessionKey) {
|
||||
if (hasThinkDirective && inlineThink) {
|
||||
if (inlineThink === "off") {
|
||||
@@ -475,36 +475,6 @@ export async function getReplyFromConfig(
|
||||
await saveSessionStore(storePath, sessionStore);
|
||||
}
|
||||
}
|
||||
const parts: string[] = [];
|
||||
if (hasThinkDirective) {
|
||||
if (!inlineThink) {
|
||||
parts.push(
|
||||
`⚙️ Unrecognized thinking level "${rawThinkLevel ?? ""}". Valid levels: off, minimal, low, medium, high.`,
|
||||
);
|
||||
} else {
|
||||
parts.push(
|
||||
inlineThink === "off"
|
||||
? "⚙️ Thinking disabled."
|
||||
: `⚙️ Thinking level set to ${inlineThink}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (hasVerboseDirective) {
|
||||
if (!inlineVerbose) {
|
||||
parts.push(
|
||||
`⚙️ Unrecognized verbose level "${rawVerboseLevel ?? ""}". Valid levels: off, on.`,
|
||||
);
|
||||
} else {
|
||||
parts.push(
|
||||
inlineVerbose === "off"
|
||||
? "⚙️ Verbose logging disabled."
|
||||
: "⚙️ Verbose logging enabled.",
|
||||
);
|
||||
}
|
||||
}
|
||||
const ack = parts.join(" ");
|
||||
cleanupTyping();
|
||||
return { text: ack };
|
||||
}
|
||||
|
||||
// Optional allowlist by origin number (E.164 without whatsapp: prefix)
|
||||
|
||||
Reference in New Issue
Block a user