refactor: unify outbound session context wiring

This commit is contained in:
Peter Steinberger
2026-02-26 21:03:23 +01:00
parent 8483e01a68
commit a1628d89ec
14 changed files with 344 additions and 36 deletions

View File

@@ -11,6 +11,7 @@ import { resolveSessionAgentId } from "../../agents/agent-scope.js";
import { resolveEffectiveMessagesConfig } from "../../agents/identity.js";
import { normalizeChannelId } from "../../channels/plugins/index.js";
import type { OpenClawConfig } from "../../config/config.js";
import { buildOutboundSessionContext } from "../../infra/outbound/session-context.js";
import { INTERNAL_MESSAGE_CHANNEL, normalizeMessageChannel } from "../../utils/message-channel.js";
import type { OriginatingChannelType } from "../templating.js";
import type { ReplyPayload } from "../types.js";
@@ -122,6 +123,11 @@ export async function routeReply(params: RouteReplyParams): Promise<RouteReplyRe
// Provider docking: this is an execution boundary (we're about to send).
// Keep the module cheap to import by loading outbound plumbing lazily.
const { deliverOutboundPayloads } = await import("../../infra/outbound/deliver.js");
const outboundSession = buildOutboundSessionContext({
cfg,
agentId: resolvedAgentId,
sessionKey: params.sessionKey,
});
const results = await deliverOutboundPayloads({
cfg,
channel: channelId,
@@ -130,7 +136,7 @@ export async function routeReply(params: RouteReplyParams): Promise<RouteReplyRe
payloads: [normalized],
replyToId: resolvedReplyToId ?? null,
threadId: resolvedThreadId,
agentId: resolvedAgentId,
session: outboundSession,
abortSignal,
mirror:
params.mirror !== false && params.sessionKey