openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.18 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{r as defaultRuntime}from"./runtime-DIcLIHcp.mjs";import{o as getPluginRuntimeGatewayRequestScope}from"./gateway-request-scope-7deHmsb_.mjs";import"./session-key-BPgKfU2m.mjs";import{t as DEFAULT_ACCOUNT_ID}from"./account-id-3yqrEsRn.mjs";import{r as resolveChannelAccount}from"./account-resolution-BMEKSThh.mjs";
//!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}}export{resolveChannelGatewayAccountId as n,resolveRuntimeAccountSnapshot as r,logoutChannelAccount as t};