Skip to content

Commit 24edb82

Browse files
shakkernerdsteipete
authored andcommitted
refactor: split delivery target runtime seams
1 parent d6ad92c commit 24edb82

1 file changed

Lines changed: 13 additions & 25 deletions

File tree

src/cron/isolated-agent/delivery-target.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ async function loadTargetsRuntime() {
4141
return await targetsRuntimePromise;
4242
}
4343

44+
async function resolveOutboundTargetWithRuntime(
45+
params: Parameters<typeof tryResolveLoadedOutboundTarget>[0],
46+
) {
47+
const loaded = tryResolveLoadedOutboundTarget(params);
48+
if (loaded) {
49+
return loaded;
50+
}
51+
const { resolveOutboundTarget } = await loadTargetsRuntime();
52+
return resolveOutboundTarget(params);
53+
}
54+
4455
let channelSelectionRuntimePromise:
4556
| Promise<typeof import("../../infra/outbound/channel-selection.runtime.js")>
4657
| undefined;
@@ -49,7 +60,6 @@ async function loadChannelSelectionRuntime() {
4960
channelSelectionRuntimePromise ??= import("../../infra/outbound/channel-selection.runtime.js");
5061
return await channelSelectionRuntimePromise;
5162
}
52-
5363
export async function resolveDeliveryTarget(
5464
cfg: OpenClawConfig,
5565
agentId: string,
@@ -182,49 +192,27 @@ export async function resolveDeliveryTarget(
182192
const effectiveAllowFrom = mode === "implicit" ? allowFromOverride : undefined;
183193

184194
if (toCandidate && mode === "implicit" && allowFromOverride.length > 0) {
185-
let currentTargetResolution = tryResolveLoadedOutboundTarget({
195+
const currentTargetResolution = await resolveOutboundTargetWithRuntime({
186196
channel,
187197
to: toCandidate,
188198
cfg,
189199
accountId,
190200
mode,
191201
allowFrom: effectiveAllowFrom,
192202
});
193-
if (!currentTargetResolution) {
194-
const { resolveOutboundTarget } = await loadTargetsRuntime();
195-
currentTargetResolution = resolveOutboundTarget({
196-
channel,
197-
to: toCandidate,
198-
cfg,
199-
accountId,
200-
mode,
201-
allowFrom: effectiveAllowFrom,
202-
});
203-
}
204203
if (!currentTargetResolution.ok) {
205204
toCandidate = allowFromOverride[0];
206205
}
207206
}
208207

209-
let docked = tryResolveLoadedOutboundTarget({
208+
const docked = await resolveOutboundTargetWithRuntime({
210209
channel,
211210
to: toCandidate,
212211
cfg,
213212
accountId,
214213
mode,
215214
allowFrom: effectiveAllowFrom,
216215
});
217-
if (!docked) {
218-
const { resolveOutboundTarget } = await loadTargetsRuntime();
219-
docked = resolveOutboundTarget({
220-
channel,
221-
to: toCandidate,
222-
cfg,
223-
accountId,
224-
mode,
225-
allowFrom: effectiveAllowFrom,
226-
});
227-
}
228216
if (!docked.ok) {
229217
return {
230218
ok: false,

0 commit comments

Comments
 (0)