From 8bc069f76f621d59a00bdd1999d2d36ffa797d0a Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Thu, 25 Jun 2026 08:33:41 -0700 Subject: [PATCH] fix(outbound): preserve narrowed delivery target type --- src/infra/outbound/agent-delivery.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/infra/outbound/agent-delivery.ts b/src/infra/outbound/agent-delivery.ts index 034f679eef20..cf0bd6fe8e2d 100644 --- a/src/infra/outbound/agent-delivery.ts +++ b/src/infra/outbound/agent-delivery.ts @@ -146,20 +146,21 @@ export async function resolveAgentDeliveryPlanWithSessionRoute( }, ): Promise { const plan = resolveAgentDeliveryPlan(params); - const plugin = - params.wantsDelivery && plan.resolvedTo && isDeliverableMessageChannel(plan.resolvedChannel) - ? resolveOutboundChannelPlugin({ - channel: plan.resolvedChannel, - cfg: params.cfg, - allowBootstrap: true, - }) - : undefined; + const { resolvedChannel, resolvedTo } = plan; + if (!params.wantsDelivery || !resolvedTo || !isDeliverableMessageChannel(resolvedChannel)) { + return plan; + } + const plugin = resolveOutboundChannelPlugin({ + channel: resolvedChannel, + cfg: params.cfg, + allowBootstrap: true, + }); if (!plugin?.messaging?.resolveOutboundSessionRoute) { return plan; } const normalizedTarget = resolveOutboundTarget({ - channel: plan.resolvedChannel, - to: plan.resolvedTo, + channel: resolvedChannel, + to: resolvedTo, cfg: params.cfg, accountId: plan.resolvedAccountId, mode: plan.deliveryTargetMode ?? "explicit", @@ -174,8 +175,8 @@ export async function resolveAgentDeliveryPlanWithSessionRoute( } const resolvedTarget = await resolveChannelTarget({ cfg: params.cfg, - channel: plan.resolvedChannel as ChannelId, - input: plan.resolvedTo, + channel: resolvedChannel as ChannelId, + input: resolvedTo, accountId: plan.resolvedAccountId, unknownTargetMode: "normalized", plugin, @@ -194,7 +195,7 @@ export async function resolveAgentDeliveryPlanWithSessionRoute( try { return await resolveOutboundSessionRoute({ cfg: params.cfg, - channel: plan.resolvedChannel as ChannelId, + channel: resolvedChannel as ChannelId, agentId: params.agentId, accountId: plan.resolvedAccountId, target: sessionRouteTarget,