openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
112 lines (111 loc) • 5.12 kB
JavaScript
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty, p as normalizeStringifiedOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { y as isAcpSessionKey } from "./session-key-CqAyZeVk.mjs";
import { t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { i as getLoadedChannelPluginForRead } from "./registry-loaded-NYWUyLLC.mjs";
import { n as listAcpBindings } from "./bindings-C2C-UuI7.mjs";
import { A as resolveCommandConversationResolution, t as getSessionBindingService } from "./session-binding-service-Bn-zGfS9.mjs";
import { n as normalizeBindingConfig, t as buildConfiguredAcpSessionKey } from "./persistent-bindings.types-CertbPM0.mjs";
import { n as resolveConfiguredBindingRecord } from "./configured-binding-registry-BU004wHy.mjs";
//#region src/auto-reply/reply/conversation-binding-input.ts
function resolveConversationBindingChannelFromMessage(e, t) {
const n = e.OriginatingChannel ?? t ?? e.Surface ?? e.Provider;
return normalizeStringifiedOptionalString(n)?.toLowerCase() ?? "";
}
function resolveConversationBindingAccountIdFromMessage(e) {
const t = resolveConversationBindingChannelFromMessage(e.ctx, e.commandChannel);
const n = getLoadedChannelPluginForRead(t);
return normalizeStringifiedOptionalString(e.ctx.AccountId) ?? normalizeStringifiedOptionalString(n?.config.defaultAccountId?.(e.cfg)) ?? "default";
}
function resolveConversationBindingContextFromMessage(e) {
return resolveCommandConversationResolution({
cfg: e.cfg,
channel: resolveConversationBindingChannelFromMessage(e.ctx),
accountId: e.ctx.AccountId,
chatType: e.ctx.ChatType,
threadId: e.ctx.MessageThreadId,
threadParentId: e.ctx.ThreadParentId,
senderId: e.senderId ?? e.ctx.SenderId,
sessionKey: e.sessionKey ?? e.ctx.SessionKey,
parentSessionKey: e.parentSessionKey ?? e.ctx.ParentSessionKey,
from: e.ctx.From,
originatingTo: e.ctx.OriginatingTo,
commandTo: e.commandTo,
fallbackTo: e.ctx.To,
nativeChannelId: e.ctx.NativeChannelId
});
}
function resolveConversationBindingContextFromAcpCommand(e) {
return resolveConversationBindingContextFromMessage({
cfg: e.cfg,
ctx: e.ctx,
senderId: e.command.senderId,
sessionKey: e.sessionKey,
parentSessionKey: e.ctx.ParentSessionKey,
commandTo: e.command.to
});
}
//#endregion
//#region src/auto-reply/reply/acp-reset-target.ts
function resolveRawConfiguredAcpSessionKey(e) {
for (const t of listAcpBindings(e.cfg)) {
const n = normalizeLowercaseStringOrEmpty(t.match.channel);
if (!n || n !== e.channel) continue;
const r = normalizeOptionalString(t.match.accountId) ?? "";
if (r && r !== "*" && r !== e.accountId) continue;
const i = normalizeOptionalString(t.match.peer?.id) ?? "";
const a = i === e.conversationId ? e.conversationId : i && i === e.parentConversationId ? e.parentConversationId : void 0;
if (!a) continue;
const o = normalizeBindingConfig(t.acp);
return buildConfiguredAcpSessionKey({
channel: e.channel,
accountId: r && r !== "*" ? r : e.accountId,
conversationId: a,
...e.parentConversationId ? { parentConversationId: e.parentConversationId } : {},
agentId: t.agentId,
mode: o.mode === "oneshot" ? "oneshot" : "persistent",
...o.cwd ? { cwd: o.cwd } : {},
...o.backend ? { backend: o.backend } : {},
...o.label ? { label: o.label } : {}
});
}
}
async function resolveEffectiveResetTargetSessionKey(e) {
const allowedTarget = (t) => e.allowNonAcpBindingSessionKey || isAcpSessionKey(t) ? t : void 0;
const t = normalizeOptionalString(e.commandTargetSessionKey);
if (t) return allowedTarget(t);
const n = normalizeOptionalString(e.activeSessionKey);
const r = n && isAcpSessionKey(n) ? n : void 0;
const i = Boolean(n) && !r;
const a = normalizeLowercaseStringOrEmpty(e.channel);
const o = normalizeOptionalString(e.conversationId) ?? "";
if (!a || !o) return r;
const s = normalizeOptionalString(e.accountId) ?? normalizeOptionalString(e.cfg.channels?.[a]?.defaultAccount) ?? "default";
const c = normalizeOptionalString(e.parentConversationId);
const l = {
channel: a,
accountId: s,
conversationId: o,
parentConversationId: c
};
const u = await getSessionBindingService().resolveByConversationAsync(l);
const d = u?.targetKind === "session" ? u.targetSessionKey.trim() : "";
if (d) return allowedTarget(d);
if (i && e.skipConfiguredFallbackWhenActiveSessionNonAcp) return;
const f = resolveConfiguredBindingRecord({
cfg: e.cfg,
...l
});
const p = f?.record.targetKind === "session" ? f.record.targetSessionKey.trim() : "";
if (p) return allowedTarget(p);
const m = resolveRawConfiguredAcpSessionKey({
cfg: e.cfg,
channel: a,
accountId: s,
conversationId: o,
...c ? { parentConversationId: c } : {}
});
if (m) return m;
return e.fallbackToActiveAcpWhenUnbound === false ? void 0 : r;
}
//#endregion
export { resolveConversationBindingContextFromMessage as a, resolveConversationBindingContextFromAcpCommand as i, resolveConversationBindingAccountIdFromMessage as n, resolveConversationBindingChannelFromMessage as r, resolveEffectiveResetTargetSessionKey as t };