openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
100 lines (99 loc) • 4.07 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { t as asBoolean } from "./boolean-2vRuVafy.mjs";
import { l as isRecord, r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs";
import "./utils-C8YECn2Q.mjs";
import { n as describeChannelAccount } from "./account-resolution-D7u1J1M0.mjs";
import { o as projectSafeChannelAccountSnapshotFields, s as redactChannelStatusSummaryBaseUrl } from "./account-snapshot-fields-B0Zypjh2.mjs";
import { i as resolveChannelAccountState, t as applyChannelAccountState } from "./account-state-CG07Qq4V.mjs";
import { a as buildRuntimeAccountStatusSnapshot } from "./status-helpers-DArJIcrA.mjs";
//#region src/channels/account-summary.ts
/** Projects an admitted lifetime without resolving its potentially stale account configuration. */
function buildChannelAccountSnapshotFromRuntime(e) {
return {
...buildRuntimeAccountStatusSnapshot({ runtime: e }),
...projectSafeChannelAccountSnapshotFields(e),
accountId: e.accountId,
enabled: e.enabled,
configured: e.configured,
stateReason: e.stateReason
};
}
/** Projects diagnostic inspection metadata without treating it as a runtime account. */
function buildChannelAccountSnapshotFromInspection(e) {
const t = asNullableRecord(e.account);
const n = asBoolean(t?.enabled) ?? e.runtime?.enabled ?? true;
const r = asBoolean(t?.configured) ?? e.runtime?.configured;
const i = {
...buildRuntimeAccountStatusSnapshot(e),
lastInboundAt: e.runtime?.lastInboundAt ?? null,
lastOutboundAt: e.runtime?.lastOutboundAt ?? null,
...projectSafeChannelAccountSnapshotFields(e.account),
...e.runtime,
...e.probe !== void 0 ? { probe: e.probe } : {},
accountId: normalizeOptionalString(t?.accountId) ?? e.accountId,
enabled: n,
configured: r
};
if (r === void 0) {
i.stateReason = n ? "configuration status unavailable" : "disabled";
if (!n) i.running = false;
return redactChannelStatusSummaryBaseUrl(i);
}
const a = normalizeOptionalString(t?.stateReason);
applyChannelAccountState(i, resolveChannelAccountState({
enabled: n,
configured: r,
linked: i.linked,
runtime: i,
disabledReason: a,
unconfiguredReason: a
}));
return redactChannelStatusSummaryBaseUrl(i);
}
async function buildChannelAccountSummary(e) {
const t = await describeChannelAccount(e);
return redactChannelStatusSummaryBaseUrl({
enabled: e.enabled,
configured: e.configured,
...projectSafeChannelAccountSnapshotFields(e.account),
...t,
accountId: e.accountId
});
}
function formatChannelAllowFrom(e) {
if (e.plugin.config.formatAllowFrom) return e.plugin.config.formatAllowFrom({
cfg: e.cfg,
accountId: e.accountId,
allowFrom: e.allowFrom
});
return normalizeStringEntries(e.allowFrom);
}
function buildChannelAccountNotes(e, t) {
const n = [
["token", e.tokenSource],
["bot", e.botTokenSource],
["app", e.appTokenSource],
["signing", e.signingSecretSource]
].flatMap(([e, t]) => t && t !== "none" ? [`${e}:${t}`] : []);
return [
e.enabled === false ? "disabled" : void 0,
e.dmPolicy ? `dm:${e.dmPolicy}` : void 0,
...n,
t,
e.baseUrl,
e.port != null ? `port:${e.port}` : void 0,
e.cliPath ? `cli:${e.cliPath}` : void 0,
e.dbPath ? `db:${e.dbPath}` : void 0
].filter((e) => Boolean(e));
}
function resolveChannelAccountEnabled(e) {
if (e.plugin.config.isEnabled) return e.plugin.config.isEnabled(e.account, e.cfg);
return (isRecord(e.account) ? e.account.enabled : void 0) !== false;
}
async function resolveChannelAccountConfigured(e) {
if (e.plugin.config.isConfigured) return await e.plugin.config.isConfigured(e.account, e.cfg);
return (isRecord(e.account) ? e.account.configured : void 0) !== false;
}
//#endregion
export { formatChannelAllowFrom as a, buildChannelAccountSummary as i, buildChannelAccountSnapshotFromInspection as n, resolveChannelAccountConfigured as o, buildChannelAccountSnapshotFromRuntime as r, resolveChannelAccountEnabled as s, buildChannelAccountNotes as t };