fix: sync delivery routing context

Co-authored-by: adam91holt <adam91holt@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-17 06:01:30 +00:00
parent e59d8c5436
commit 285ed8bac3
10 changed files with 208 additions and 51 deletions

View File

@@ -30,12 +30,14 @@ function resolveDeliveryAccountId(params: {
opts: AgentCommandOpts;
sessionEntry?: SessionEntry;
targetMode: ChannelOutboundTargetMode;
deliveryChannel?: string;
}) {
const sessionOrigin = deliveryContextFromSession(params.sessionEntry);
return (
normalizeAccountId(params.opts.accountId) ??
(params.targetMode === "implicit" ? normalizeAccountId(sessionOrigin?.accountId) : undefined)
);
const explicit = normalizeAccountId(params.opts.accountId);
if (explicit || params.targetMode !== "implicit") return explicit;
if (!params.deliveryChannel || isInternalMessageChannel(params.deliveryChannel)) return undefined;
if (sessionOrigin?.channel !== params.deliveryChannel) return undefined;
return normalizeAccountId(sessionOrigin?.accountId);
}
export async function deliverAgentCommandResult(params: {
@@ -61,7 +63,12 @@ export async function deliverAgentCommandResult(params: {
const targetMode: ChannelOutboundTargetMode =
opts.deliveryTargetMode ?? (opts.to ? "explicit" : "implicit");
const resolvedAccountId = resolveDeliveryAccountId({ opts, sessionEntry, targetMode });
const resolvedAccountId = resolveDeliveryAccountId({
opts,
sessionEntry,
targetMode,
deliveryChannel,
});
const resolvedTarget =
deliver && isDeliveryChannelKnown && deliveryChannel
? resolveOutboundTarget({