import type { ChannelId } from "../../channels/plugins/types.public.js"; import { resolveAgentMainSessionKey } from "../../config/sessions/main-session.js"; import { resolveStorePath } from "../../config/sessions/paths.js"; import { loadSessionStore } from "../../config/sessions/store-load.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; import { formatErrorMessage } from "../../infra/errors.js"; import { maybeResolveIdLikeTarget } from "../../infra/outbound/target-id-resolution.js"; import { tryResolveLoadedOutboundTarget } from "../../infra/outbound/targets-loaded.js"; import { resolveSessionDeliveryTarget } from "../../infra/outbound/targets-session.js"; import type { OutboundChannel } from "../../infra/outbound/targets.js"; import { normalizeAccountId } from "../../routing/session-key.js";
// Look up thread-specific session first (e.g. agent:main:main:thread:1234), // then fall back to the main session entry. const threadSessionKey = jobPayload.sessionKey?.trim(); const threadEntry = threadSessionKey ? store[threadSessionKey] : undefined; const main = threadEntry ?? store[mainSessionKey];
const channel = resolved.channel ?? fallbackChannel; const mode = resolved.mode as "explicit" | "implicit";
let toCandidate = resolved.to;
// Prefer an explicit accountId from the job's delivery config (set via // --account on cron add/edit). Fall back to the session's lastAccountId, // then to the agent's bound account from bindings config. const explicitAccountId = typeof jobPayload.accountId === "string" && jobPayload.accountId.trim()
? jobPayload.accountId.trim()
: undefined;
let accountId = explicitAccountId ?? resolved.accountId; if (!accountId && channel) { const { resolveFirstBoundAccountId } = await loadDeliveryTargetRuntime();
accountId = resolveFirstBoundAccountId({ cfg, channelId: channel, agentId });
}
// job.delivery.accountId takes highest precedence — explicitly set by the job author. if (jobPayload.accountId) {
accountId = jobPayload.accountId;
}
// Carry threadId when it was explicitly set (from :topic: parsing or config) // or when delivering to the same recipient as the session's last conversation. // Session-derived threadIds are dropped when the target differs to prevent // stale thread IDs from leaking to a different chat. const threadId =
resolved.threadId &&
(resolved.threadIdExplicit || (resolved.to && resolved.to === resolved.lastTo))
? resolved.threadId
: undefined;
if (!channel) { return {
ok: false,
channel: undefined,
to: undefined,
accountId,
threadId,
mode,
error:
channelResolutionError ?? new Error("Channel is required when delivery.channel=last has no previous channel."),
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.