fix: imessage dm replies and error details (#935)

This commit is contained in:
Peter Steinberger
2026-01-15 07:58:44 +00:00
parent 9c04a79c0a
commit a5a9788b20
7 changed files with 88 additions and 6 deletions

View File

@@ -53,4 +53,38 @@ describe("buildThreadingToolContext", () => {
expect(result.currentChannelId).toBe("chat:99");
});
it("uses the sender handle for iMessage direct chats", () => {
const sessionCtx = {
Provider: "imessage",
ChatType: "direct",
From: "imessage:+15550001",
To: "chat_id:12",
} as TemplateContext;
const result = buildThreadingToolContext({
sessionCtx,
config: cfg,
hasRepliedRef: undefined,
});
expect(result.currentChannelId).toBe("imessage:+15550001");
});
it("uses chat_id for iMessage groups", () => {
const sessionCtx = {
Provider: "imessage",
ChatType: "group",
From: "group:7",
To: "chat_id:7",
} as TemplateContext;
const result = buildThreadingToolContext({
sessionCtx,
config: cfg,
hasRepliedRef: undefined,
});
expect(result.currentChannelId).toBe("chat_id:7");
});
});

View File

@@ -26,7 +26,12 @@ export function buildThreadingToolContext(params: {
const dock = getChannelDock(provider);
if (!dock?.threading?.buildToolContext) return {};
// WhatsApp context isolation keys off conversation id, not the bot's own number.
const threadingTo = provider === "whatsapp" ? (sessionCtx.From ?? sessionCtx.To) : sessionCtx.To;
const threadingTo =
provider === "whatsapp"
? (sessionCtx.From ?? sessionCtx.To)
: provider === "imessage" && sessionCtx.ChatType === "direct"
? (sessionCtx.From ?? sessionCtx.To)
: sessionCtx.To;
return (
dock.threading.buildToolContext({
cfg: config,