From a4a7958678d77682fb4a6ed1981d0b8ae6ccd145 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 22:01:52 +0000 Subject: [PATCH] refactor: share outbound base session setup --- src/infra/outbound/outbound-session.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/infra/outbound/outbound-session.ts b/src/infra/outbound/outbound-session.ts index d4a8a3466c6..afd3b1966c3 100644 --- a/src/infra/outbound/outbound-session.ts +++ b/src/infra/outbound/outbound-session.ts @@ -532,6 +532,21 @@ function resolveMatrixSession( }; } +function buildSimpleBaseSession(params: { + route: ResolveOutboundSessionRouteParams; + channel: string; + peer: RoutePeer; +}) { + const baseSessionKey = buildBaseSessionKey({ + cfg: params.route.cfg, + agentId: params.route.agentId, + channel: params.channel, + accountId: params.route.accountId, + peer: params.peer, + }); + return { baseSessionKey, peer: params.peer }; +} + function resolveMSTeamsSession( params: ResolveOutboundSessionRouteParams, ): OutboundSessionRoute | null { @@ -596,13 +611,10 @@ function resolveMattermostSession( if (!rawId) { return null; } - const peer: RoutePeer = { kind: isUser ? "direct" : "channel", id: rawId }; - const baseSessionKey = buildBaseSessionKey({ - cfg: params.cfg, - agentId: params.agentId, + const { baseSessionKey, peer } = buildSimpleBaseSession({ + route: params, channel: "mattermost", - accountId: params.accountId, - peer, + peer: { kind: isUser ? "direct" : "channel", id: rawId }, }); const threadId = normalizeThreadId(params.replyToId ?? params.threadId); const threadKeys = resolveThreadSessionKeys({