import { HttpException } from '@nestjs/common'; export function wecomPluginCaller(req: { headers: Record }): string { const raw = req.headers['x-wecom-userid'] ?? req.headers['userid']; const v = Array.isArray(raw) ? raw[0] : raw; return String(v || 'plugin').trim() || 'plugin'; } export function wecomPluginMcpErrorText(e: unknown): string { if (e instanceof HttpException) { const res = e.getResponse(); if (typeof res === 'string') return res; if (res && typeof res === 'object' && 'message' in res) { const message = (res as { message?: string | string[] }).message; return Array.isArray(message) ? message.join(', ') : String(message ?? e.message); } return e.message; } return e instanceof Error ? e.message : String(e); } export function wecomPluginQueryArg(v?: string | number): string | undefined { if (v == null) return undefined; const s = String(v).trim(); return s ? s : undefined; }