openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
61 lines (60 loc) • 2.34 kB
JavaScript
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs";
import "./registry-BB86xKJa.mjs";
import { n as normalizeCommandBody } from "./commands-registry-normalize-dI3NYF5y.mjs";
import { a as stripMentions } from "./mentions-CACvAvae.mjs";
//#region src/auto-reply/reply/commands-context.ts
/** Selection and execution must bind to the same channel, including origin-routed turns. */
function resolveCommandChannel(e) {
return normalizeLowercaseStringOrEmpty(e.OriginatingChannel ?? e.Provider ?? e.Surface);
}
function buildPluginCommandContext(e) {
const { command: t, ctx: n } = e;
return {
senderId: t.senderId,
channel: t.channel,
channelId: t.channelId,
isAuthorizedSender: t.isAuthorizedSender,
senderIsOwner: t.senderIsOwner,
assertOwnerCurrent: t.assertOwnerCurrent,
gatewayClientScopes: n.GatewayClientScopes,
agentId: e.agentId,
sessionKey: e.sessionKey,
config: e.cfg,
from: t.from,
to: t.to,
originatingTo: normalizeOptionalString(n.OriginatingTo),
accountId: n.AccountId,
messageThreadId: n.MessageThreadId,
threadParentId: normalizeOptionalString(n.ThreadParentId)
};
}
function buildCommandContext(e, t) {
const { ctx: n, cfg: r, agentId: i, sessionKey: a, isGroup: o, triggerBodyNormalized: s } = e;
const c = normalizeLowercaseStringOrEmpty(n.Surface ?? n.Provider);
const l = resolveCommandChannel(n);
const u = t.from ?? normalizeOptionalString(n.SenderId);
const d = t.to ?? normalizeOptionalString(n.OriginatingTo);
const f = a ?? u ?? d;
const p = normalizeAnyChannelId(l) ?? (l ? l : void 0);
const m = s;
const h = normalizeCommandBody(o ? stripMentions(m, n, r, i) : m, { botUsername: n.BotUsername });
return {
surface: c,
channel: l,
channelId: p ?? t.providerId,
accountId: normalizeOptionalString(n.AccountId),
ownerList: t.ownerList,
senderIsOwner: t.senderIsOwner,
...t.assertOwnerCurrent ? { assertOwnerCurrent: t.assertOwnerCurrent } : {},
isAuthorizedSender: t.isAuthorizedSender,
senderId: t.senderId,
abortKey: f,
rawBodyNormalized: m,
commandBodyNormalized: h,
from: u,
to: d
};
}
//#endregion
export { buildPluginCommandContext as n, resolveCommandChannel as r, buildCommandContext as t };