refactor: normalize delivery context

Co-authored-by: adam91holt <adam91holt@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-17 04:24:42 +00:00
parent 8ebfa2950d
commit 4f37f66264
4 changed files with 47 additions and 21 deletions

View File

@@ -20,6 +20,7 @@ import {
resolveGatewayMessageChannel,
} from "../../utils/message-channel.js";
import { normalizeAccountId } from "../../utils/account-id.js";
import { deliveryContextFromSession } from "../../utils/delivery-context.js";
import type { AgentCommandOpts } from "./types.js";
type RunResult = Awaited<
@@ -31,10 +32,11 @@ function resolveDeliveryAccountId(params: {
sessionEntry?: SessionEntry;
targetMode: ChannelOutboundTargetMode;
}) {
const sessionOrigin = deliveryContextFromSession(params.sessionEntry);
return (
normalizeAccountId(params.opts.accountId) ??
(params.targetMode === "implicit"
? normalizeAccountId(params.sessionEntry?.lastAccountId)
? normalizeAccountId(sessionOrigin?.accountId)
: undefined)
);
}