import type { ClawdbotConfig } from "openclaw/plugin-sdk"; import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk"; import type { PopoConfig, ResolvedPopoAccount } from "./types.js"; export function resolvePopoCredentials(cfg?: PopoConfig): { appKey: string; appSecret: string; token?: string; aesKey?: string; server: string; } | null { const appKey = cfg?.appKey?.trim(); const appSecret = cfg?.appSecret?.trim(); if (!appKey || !appSecret) return null; return { appKey, appSecret, token: cfg?.token?.trim() || undefined, aesKey: cfg?.aesKey?.trim() || undefined, server: cfg?.server ?? "https://open.popo.netease.com/open-apis/robots/v1", }; } export function resolvePopoAccount(params: { cfg: ClawdbotConfig; accountId?: string | null; }): ResolvedPopoAccount { const popoCfg = params.cfg.channels?.popo as PopoConfig | undefined; const enabled = popoCfg?.enabled !== false; const creds = resolvePopoCredentials(popoCfg); return { accountId: params.accountId?.trim() || DEFAULT_ACCOUNT_ID, enabled, configured: Boolean(creds), appKey: creds?.appKey, }; } export function listPopoAccountIds(_cfg: ClawdbotConfig): string[] { return [DEFAULT_ACCOUNT_ID]; } export function resolveDefaultPopoAccountId(_cfg: ClawdbotConfig): string { return DEFAULT_ACCOUNT_ID; } export function listEnabledPopoAccounts(cfg: ClawdbotConfig): ResolvedPopoAccount[] { return listPopoAccountIds(cfg) .map((accountId) => resolvePopoAccount({ cfg, accountId })) .filter((account) => account.enabled && account.configured); }