976bde37cc
与 REST/OpenAPI 并存,按实例权限自动 tools/list,免手填工具。 Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
968 B
TypeScript
27 lines
968 B
TypeScript
import { HttpException } from '@nestjs/common';
|
|
|
|
export function wecomPluginCaller(req: { headers: Record<string, unknown> }): 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;
|
|
}
|