UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

57 lines (56 loc) • 2.43 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { r as defaultRuntime } from "./runtime-B-SLYP-m.mjs"; import { o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs"; import "./session-key-CqAyZeVk.mjs"; import { t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs"; import { r as resolveChannelAccount } from "./account-resolution-D7u1J1M0.mjs"; //#region src/gateway/server-methods/channels-account.ts function resolveRuntimeAccountSnapshot(e) { const t = e.runtime.channelAccounts[e.channelId]?.[e.accountId]; if (t) return t; const n = e.runtime.channels[e.channelId]; return n?.accountId === e.accountId ? n : void 0; } function resolveChannelGatewayAccountId(e, t) { const n = normalizeOptionalString(e.accountId); if (n) return n; const r = e.plugin.id; const i = t?.(); if (i?.reloadingChannels?.has(r)) return i.reloadingChannels.get(r) || Object.keys(i.channelAccounts[r] ?? {})[0] || "default"; return e.plugin.config.defaultAccountId?.(e.cfg) || e.plugin.config.listAccountIds(e.cfg)[0] || "default"; } async function logoutChannelAccount(e) { const isRuntimeCurrent = () => e.context.getGatewayMethodRegistry?.() === e.methodRegistry && (!e.methodRegistry || getPluginRuntimeGatewayRequestScope()?.pluginRegistry === e.methodRegistry.pluginRegistry) && e.context.getRuntimeConfig() === e.cfg && e.context.isConfigReloadSettled(); const assertCurrent = () => { e.assertRequestCurrent(); if (!isRuntimeCurrent()) throw new Error(`Channel ${e.channelId} changed during logout; retry the request.`); }; assertCurrent(); const t = resolveChannelGatewayAccountId(e); const n = await resolveChannelAccount({ plugin: e.plugin, cfg: e.cfg, accountId: t }); assertCurrent(); await e.context.stopChannel(e.channelId, t); assertCurrent(); const r = await e.plugin.gateway?.logoutAccount?.({ cfg: e.cfg, accountId: t, account: n, runtime: defaultRuntime }); e.assertRequestCurrent(); if (!r) throw new Error(`Channel ${e.channelId} does not support logout`); const i = r.cleared; if ((typeof r.loggedOut === "boolean" ? r.loggedOut : i) && isRuntimeCurrent()) e.context.markChannelLoggedOut(e.channelId, true, t); return { channel: e.channelId, accountId: t, ...r, cleared: i }; } //#endregion export { resolveChannelGatewayAccountId as n, resolveRuntimeAccountSnapshot as r, logoutChannelAccount as t };