



















@@ -1,4 +1,3 @@
1-import { parseExplicitTargetForLoadedChannel } from "../../channels/plugins/target-parsing-loaded.js";
21import type { ChannelId } from "../../channels/plugins/types.public.js";
32import { resolveAgentMainSessionKey } from "../../config/sessions/main-session.js";
43import { resolveStorePath } from "../../config/sessions/paths.js";
@@ -9,7 +8,10 @@ import { formatErrorMessage } from "../../infra/errors.js";
98import { maybeResolveIdLikeTarget } from "../../infra/outbound/target-id-resolution.js";
109import { normalizeTargetForProvider } from "../../infra/outbound/target-normalization.js";
1110import { tryResolveLoadedOutboundTarget } from "../../infra/outbound/targets-loaded.js";
12-import { resolveSessionDeliveryTarget } from "../../infra/outbound/targets-session.js";
11+import {
12+resolveSessionDeliveryTarget,
13+type ExplicitTargetParser,
14+} from "../../infra/outbound/targets-session.js";
1315import type { OutboundChannel } from "../../infra/outbound/targets.js";
1416import { normalizeAccountId } from "../../routing/session-key.js";
1517import { createLazyImportLoader } from "../../shared/lazy-promise.js";
@@ -64,6 +66,7 @@ async function resolveOutboundTargetWithRuntime(
6466function normalizeTargetForThreadCarry(
6567channel: Exclude<OutboundChannel, "none"> | undefined,
6668to: string | undefined,
69+parseExplicitTarget: ExplicitTargetParser,
6770): string | undefined {
6871if (!channel || !to) {
6972return undefined;
@@ -74,7 +77,7 @@ function normalizeTargetForThreadCarry(
7477if (!comparable) {
7578return undefined;
7679}
77-const parsed = parseExplicitTargetForLoadedChannel(channel, comparable);
80+const parsed = parseExplicitTarget(channel, comparable);
7881const base = parsed?.to ?? comparable;
7982return normalizeTargetForProvider(channel, base) ?? base;
8083} catch {
@@ -86,15 +89,24 @@ function deliveryTargetsShareThreadRoute(params: {
8689channel: Exclude<OutboundChannel, "none"> | undefined;
8790to: string | undefined;
8891lastTo: string | undefined;
92+parseExplicitTarget: ExplicitTargetParser;
8993}): boolean {
9094if (!params.to || !params.lastTo) {
9195return false;
9296}
9397if (params.to === params.lastTo) {
9498return true;
9599}
96-const normalizedTo = normalizeTargetForThreadCarry(params.channel, params.to);
97-const normalizedLastTo = normalizeTargetForThreadCarry(params.channel, params.lastTo);
100+const normalizedTo = normalizeTargetForThreadCarry(
101+params.channel,
102+params.to,
103+params.parseExplicitTarget,
104+);
105+const normalizedLastTo = normalizeTargetForThreadCarry(
106+params.channel,
107+params.lastTo,
108+params.parseExplicitTarget,
109+);
98110return Boolean(normalizedTo && normalizedLastTo && normalizedTo === normalizedLastTo);
99111}
100112@@ -128,6 +140,13 @@ export async function resolveDeliveryTarget(
128140const requestedChannel = typeof jobPayload.channel === "string" ? jobPayload.channel : "last";
129141const explicitTo = typeof jobPayload.to === "string" ? jobPayload.to : undefined;
130142const allowMismatchedLastTo = requestedChannel === "last";
143+const deliveryTargetRuntime = await loadDeliveryTargetRuntime();
144+const parseExplicitTarget: ExplicitTargetParser = (channel, rawTarget) =>
145+deliveryTargetRuntime.parseExplicitTargetForDelivery({
146+ cfg,
147+ channel,
148+ rawTarget,
149+});
131150132151const sessionCfg = cfg.session;
133152const mainSessionKey = resolveAgentMainSessionKey({ cfg, agentId });
@@ -167,6 +186,7 @@ export async function resolveDeliveryTarget(
167186 explicitTo,
168187explicitThreadId: jobPayload.threadId,
169188 allowMismatchedLastTo,
189+ parseExplicitTarget,
170190});
171191172192let fallbackChannel: Exclude<OutboundChannel, "none"> | undefined;
@@ -197,6 +217,7 @@ export async function resolveDeliveryTarget(
197217 fallbackChannel,
198218 allowMismatchedLastTo,
199219mode: preliminary.mode,
220+ parseExplicitTarget,
200221})
201222 : preliminary;
202223@@ -213,8 +234,11 @@ export async function resolveDeliveryTarget(
213234 : undefined;
214235let accountId = explicitAccountId ?? resolved.accountId;
215236if (!accountId && channel) {
216-const { resolveFirstBoundAccountId } = await loadDeliveryTargetRuntime();
217-accountId = resolveFirstBoundAccountId({ cfg, channelId: channel, agentId });
237+accountId = deliveryTargetRuntime.resolveFirstBoundAccountId({
238+ cfg,
239+channelId: channel,
240+ agentId,
241+});
218242}
219243220244// job.delivery.accountId takes highest precedence — explicitly set by the job author.
@@ -233,20 +257,11 @@ export async function resolveDeliveryTarget(
233257 channel,
234258to: resolved.to,
235259lastTo: resolved.lastTo,
260+ parseExplicitTarget,
236261}))
237262 ? resolved.threadId
238263 : undefined;
239264240-if (channel === "telegram" && typeof toCandidate === "string") {
241-const topicMatch = toCandidate.match(/:topic:(\d+)$/i);
242-if (topicMatch) {
243-if (jobPayload.threadId == null || jobPayload.threadId === "") {
244-threadId = Number(topicMatch[1]);
245-}
246-toCandidate = toCandidate.replace(/:topic:\d+$/i, "");
247-}
248-}
249-250265if (!channel) {
251266return {
252267ok: false,
@@ -263,8 +278,7 @@ export async function resolveDeliveryTarget(
263278264279let effectiveAllowFrom: string[] | undefined;
265280if (mode === "implicit") {
266-const { getLoadedChannelPluginForRead, mapAllowFromEntries } =
267-await loadDeliveryTargetRuntime();
281+const { getLoadedChannelPluginForRead, mapAllowFromEntries } = deliveryTargetRuntime;
268282const channelPlugin = getLoadedChannelPluginForRead(channel);
269283const resolvedAccountId = normalizeAccountId(accountId);
270284const configuredAllowFromRaw = channelPlugin?.config.resolveAllowFrom?.({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。