























@@ -287,6 +287,18 @@ export async function dispatchReplyFromConfig(
287287"",
288288) ?? "off",
289289});
290+const isSystemEventTurn =
291+ctx.Provider === "heartbeat" || ctx.Provider === "cron-event" || ctx.Provider === "exec-event";
292+const persistedDeliveryContext = sessionStoreEntry.entry?.deliveryContext;
293+const fallbackOriginatingChannel = isSystemEventTurn
294+ ? (persistedDeliveryContext?.channel ?? sessionStoreEntry.entry?.lastChannel)
295+ : undefined;
296+const fallbackOriginatingTo = isSystemEventTurn
297+ ? (persistedDeliveryContext?.to ?? sessionStoreEntry.entry?.lastTo)
298+ : undefined;
299+const fallbackOriginatingAccountId = isSystemEventTurn
300+ ? (persistedDeliveryContext?.accountId ?? sessionStoreEntry.entry?.lastAccountId)
301+ : undefined;
290302// Restore route thread context only from the active turn or the thread-scoped session key.
291303// Do not read thread ids from the normalised session store here: `origin.threadId` can be
292304// folded back into lastThreadId/deliveryContext during store normalisation and resurrect a
@@ -319,7 +331,10 @@ export async function dispatchReplyFromConfig(
319331//
320332// Debug: `pnpm test src/auto-reply/reply/dispatch-from-config.test.ts`
321333const suppressAcpChildUserDelivery = isParentOwnedBackgroundAcpSession(sessionStoreEntry.entry);
322-const normalizedOriginatingChannel = normalizeMessageChannel(ctx.OriginatingChannel);
334+const effectiveOriginatingChannel = ctx.OriginatingChannel ?? fallbackOriginatingChannel;
335+const effectiveOriginatingTo = ctx.OriginatingTo ?? fallbackOriginatingTo;
336+const routeAccountId = ctx.AccountId ?? fallbackOriginatingAccountId;
337+const normalizedOriginatingChannel = normalizeMessageChannel(effectiveOriginatingChannel);
323338const normalizedProviderChannel = normalizeMessageChannel(ctx.Provider);
324339const normalizedSurfaceChannel = normalizeMessageChannel(ctx.Surface);
325340const normalizedCurrentSurface = normalizedProviderChannel ?? normalizedSurfaceChannel;
@@ -331,7 +346,7 @@ export async function dispatchReplyFromConfig(
331346!suppressAcpChildUserDelivery &&
332347!isInternalWebchatTurn &&
333348normalizedOriginatingChannel &&
334-ctx.OriginatingTo &&
349+effectiveOriginatingTo &&
335350normalizedOriginatingChannel !== normalizedCurrentSurface,
336351);
337352const routeReplyRuntime = hasRouteReplyCandidate ? await loadRouteReplyRuntime() : undefined;
@@ -340,20 +355,20 @@ export async function dispatchReplyFromConfig(
340355provider: ctx.Provider,
341356surface: ctx.Surface,
342357explicitDeliverRoute: ctx.ExplicitDeliverRoute,
343-originatingChannel: ctx.OriginatingChannel,
344-originatingTo: ctx.OriginatingTo,
358+originatingChannel: effectiveOriginatingChannel,
359+originatingTo: effectiveOriginatingTo,
345360suppressDirectUserDelivery: suppressAcpChildUserDelivery,
346361isRoutableChannel: routeReplyRuntime?.isRoutableChannel ?? (() => false),
347362});
348-const originatingTo = ctx.OriginatingTo;
363+const originatingTo = effectiveOriginatingTo;
349364const ttsChannel = shouldRouteToOriginating ? originatingChannel : currentSurface;
350365const { createReplyMediaPathNormalizer } = await loadReplyMediaPathsRuntime();
351366const normalizeReplyMediaPaths = createReplyMediaPathNormalizer({
352367 cfg,
353368sessionKey: acpDispatchSessionKey,
354369workspaceDir: resolveAgentWorkspaceDir(cfg, sessionAgentId),
355370messageProvider: ttsChannel,
356-accountId: ctx.AccountId,
371+accountId: routeAccountId,
357372 groupId,
358373groupChannel: ctx.GroupChannel,
359374groupSpace: ctx.GroupSpace,
@@ -385,7 +400,7 @@ export async function dispatchReplyFromConfig(
385400ctx.CommandSource === "native"
386401 ? (ctx.CommandTargetSessionKey ?? ctx.SessionKey)
387402 : ctx.SessionKey,
388-accountId: ctx.AccountId,
403+accountId: routeAccountId,
389404requesterSenderId: ctx.SenderId,
390405requesterSenderName: ctx.SenderName,
391406requesterSenderUsername: ctx.SenderUsername,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。