fix: finalize inbound contexts

This commit is contained in:
Peter Steinberger
2026-01-17 05:04:29 +00:00
parent 4b085f23e0
commit bc49c20434
27 changed files with 645 additions and 83 deletions

View File

@@ -17,6 +17,7 @@ import {
resolveInboundDebounceMs,
} from "../../auto-reply/inbound-debounce.js";
import { dispatchReplyFromConfig } from "../../auto-reply/reply/dispatch-from-config.js";
import { finalizeInboundContext } from "../../auto-reply/reply/inbound-context.js";
import {
buildPendingHistoryContextFromMap,
clearHistoryEntries,
@@ -26,6 +27,7 @@ import {
} from "../../auto-reply/reply/history.js";
import { buildMentionRegexes, matchesMentionPatterns } from "../../auto-reply/reply/mentions.js";
import { createReplyDispatcher } from "../../auto-reply/reply/reply-dispatcher.js";
import { formatInboundBodyWithSenderMeta } from "../../auto-reply/reply/inbound-sender-meta.js";
import { loadConfig } from "../../config/config.js";
import {
resolveChannelGroupPolicy,
@@ -387,12 +389,10 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
}
const imessageTo = (isGroup ? chatTarget : undefined) || `imessage:${sender}`;
const ctxPayload = {
const ctxPayload = finalizeInboundContext({
Body: combinedBody,
BodyForAgent: combinedBody,
RawBody: bodyText,
CommandBody: bodyText,
BodyForCommands: bodyText,
From: isGroup ? `group:${chatId}` : `imessage:${sender}`,
To: imessageTo,
SessionKey: route.sessionKey,
@@ -416,7 +416,8 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
// Originating channel for reply routing.
OriginatingChannel: "imessage" as const,
OriginatingTo: imessageTo,
};
});
ctxPayload.Body = formatInboundBodyWithSenderMeta({ ctx: ctxPayload, body: ctxPayload.Body });
if (!isGroup) {
const sessionCfg = cfg.session;