




















@@ -11,12 +11,13 @@ import {
1111} from "./inbound-dedupe.js";
1212import { materializeDiscordInboundJob, type DiscordInboundJob } from "./inbound-job.js";
1313import type { RuntimeEnv } from "./message-handler.preflight.types.js";
14-import { processDiscordMessage } from "./message-handler.process.js";
15-import { deliverDiscordReply } from "./reply-delivery.js";
1614import type { DiscordMonitorStatusSink } from "./status.js";
1715import { resolveDiscordReplyDeliveryPlan } from "./threading.js";
1816import { normalizeDiscordInboundWorkerTimeoutMs, runDiscordTaskWithTimeout } from "./timeouts.js";
191718+type ProcessDiscordMessage = typeof import("./message-handler.process.js").processDiscordMessage;
19+type DeliverDiscordReply = typeof import("./reply-delivery.js").deliverDiscordReply;
20+2021type DiscordInboundWorkerParams = {
2122runtime: RuntimeEnv;
2223setStatus?: DiscordMonitorStatusSink;
@@ -32,10 +33,25 @@ export type DiscordInboundWorker = {
3233};
33343435export type DiscordInboundWorkerTestingHooks = {
35-processDiscordMessage?: typeof processDiscordMessage;
36-deliverDiscordReply?: typeof deliverDiscordReply;
36+processDiscordMessage?: ProcessDiscordMessage;
37+deliverDiscordReply?: DeliverDiscordReply;
3738};
383940+let messageProcessRuntimePromise:
41+| Promise<typeof import("./message-handler.process.js")>
42+| undefined;
43+let replyDeliveryRuntimePromise: Promise<typeof import("./reply-delivery.js")> | undefined;
44+45+async function loadMessageProcessRuntime() {
46+messageProcessRuntimePromise ??= import("./message-handler.process.js");
47+return await messageProcessRuntimePromise;
48+}
49+50+async function loadReplyDeliveryRuntime() {
51+replyDeliveryRuntimePromise ??= import("./reply-delivery.js");
52+return await replyDeliveryRuntimePromise;
53+}
54+3955function formatDiscordRunContextSuffix(job: DiscordInboundJob): string {
4056const channelId = job.payload.messageChannelId?.trim();
4157const messageId = job.payload.data?.message?.id?.trim();
@@ -62,7 +78,9 @@ async function processDiscordInboundJob(params: {
6278let finalReplyStarted = false;
6379let createdThreadId: string | undefined;
6480let sessionKey: string | undefined;
65-const processDiscordMessageImpl = params.testing?.processDiscordMessage ?? processDiscordMessage;
81+const processDiscordMessageImpl =
82+params.testing?.processDiscordMessage ??
83+(await loadMessageProcessRuntime()).processDiscordMessage;
6684try {
6785await runDiscordTaskWithTimeout({
6886run: async (abortSignal) => {
@@ -135,7 +153,7 @@ async function sendDiscordInboundWorkerTimeoutReply(params: {
135153contextSuffix: string;
136154createdThreadId?: string;
137155sessionKey?: string;
138-deliverDiscordReplyImpl?: typeof deliverDiscordReply;
156+deliverDiscordReplyImpl?: DeliverDiscordReply;
139157}) {
140158const messageChannelId = params.job.payload.messageChannelId?.trim();
141159const messageId = params.job.payload.message?.id?.trim();
@@ -158,7 +176,9 @@ async function sendDiscordInboundWorkerTimeoutReply(params: {
158176});
159177160178try {
161-await (params.deliverDiscordReplyImpl ?? deliverDiscordReply)({
179+const deliverDiscordReplyImpl =
180+params.deliverDiscordReplyImpl ?? (await loadReplyDeliveryRuntime()).deliverDiscordReply;
181+await deliverDiscordReplyImpl({
162182cfg: params.job.payload.cfg,
163183replies: [{ text: "Discord inbound worker timed out.", isError: true }],
164184target: deliveryPlan.deliverTarget,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。