openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
55 lines (54 loc) • 2.56 kB
JavaScript
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as isBlockedObjectKey } from "./prototype-keys-CLGi5xDj.mjs";
import { n as normalizeAccountId, r as normalizeOptionalAccountId } from "./account-id-BqKT3GuY.mjs";
import { r as snapshotReaderSlot } from "./plugin-metadata-snapshot-readers-J64uR9fG.mjs";
//#region src/routing/account-lookup.ts
function resolveChannelAccountKey(e, t, n, r, i, a) {
return resolveAccountKey(e, t, r, i, {
...a,
channelId: n
});
}
function resolveChannelAccountEntry(e, t, n, r, i) {
const a = resolveChannelAccountKey(e, t, n, r, i);
return a === void 0 ? void 0 : e?.[a];
}
function resolveAccountEntry(e, t) {
const n = resolveAccountKey(e, t);
return n === void 0 ? void 0 : e?.[n];
}
function resolveNormalizedAccountEntry(e, t, n, r) {
const i = resolveAccountKey(e, t, n, r);
return i === void 0 ? void 0 : e?.[i];
}
/** Select the stored spelling once for account readers and writers; exact keys win. */
function resolveAccountKey(e, t, n, r, i) {
const a = r ?? (i?.channelId ? snapshotReaderSlot.getCurrentPluginMetadataSnapshot?.({
allowScopedSnapshot: true,
allowWorkspaceScopedSnapshot: true
})?.owners.channelAccountKeyPolicies?.get(i.channelId) : void 0);
const o = a ? normalizeAccountId : n;
const s = o ?? normalizeLowercaseStringOrEmpty;
if (i?.allowMissing && (isBlockedObjectKey(normalizeLowercaseStringOrEmpty(t)) || isBlockedObjectKey(s(t)))) throw new Error(`Account id "${t}" is reserved. Choose a different account id.`);
const c = a ? s(t) : t;
const l = i?.allowMissing ? c : void 0;
if (!e || typeof e !== "object") return l;
if (Object.hasOwn(e, c) && (!o || !isBlockedObjectKey(c))) return c;
const u = s(c);
const d = normalizeLowercaseStringOrEmpty(c);
let f;
for (const t of Object.keys(e)) {
if (o && isBlockedObjectKey(t)) continue;
if (a && normalizeLowercaseStringOrEmpty(t) === d) return t;
const n = s(t);
if ((!o || Boolean(normalizeOptionalAccountId(t)) && !isBlockedObjectKey(n)) && n === u) {
if (!a) return t;
const n = asOptionalRecord(e[t]);
if (f === void 0 && n && Object.hasOwn(n, a.canonicalAliasesRequireOwnField) && normalizeOptionalString(n[a.canonicalAliasesRequireOwnField])) f = t;
}
}
return f ?? l;
}
//#endregion
export { resolveNormalizedAccountEntry as a, resolveChannelAccountKey as i, resolveAccountKey as n, resolveChannelAccountEntry as r, resolveAccountEntry as t };