fix: surface actionable channel message errors

This commit is contained in:
xmanrui 2026-08-25 14:54:50 +08:00
parent b42fc411c2
commit 7cbed3aefb
59 changed files with 2405 additions and 607 deletions

View file

@ -1,4 +1,5 @@
import { normalizeAgentPresetCatalog, normalizeAgentPresetId, SET_AGENT_PRESET_ENDPOINT } from '../../agent-preset.js';
import { normalizeLastMessageError } from '../../last-message-error.js';
export const WEIXIN_RPC_CHANNEL = '/weixin';
export const WEIXIN_ENDPOINTS = Object.freeze({
@ -48,15 +49,6 @@ function normalizeTestMessage(value) {
return { sent: false, code };
}
function normalizeMessageError(value) {
if (!isRecord(value)) return null;
const code = string(value.code).slice(0, 64);
const reason = string(value.reason).slice(0, 128);
const message = string(value.message).slice(0, 500);
const at = timestamp(value.at);
return code && reason && message && at !== null ? { code, reason, message, at } : null;
}
export function unwrapRpcResult(result) {
if (!isRecord(result) || typeof result.ok !== 'boolean') {
throw new Error('微信服务返回了无法识别的响应');
@ -141,7 +133,7 @@ function normalizeBot(value) {
messagesReceived: Math.max(0, Number(value.stats?.messagesReceived) || 0),
messagesReplied: Math.max(0, Number(value.stats?.messagesReplied) || 0),
},
lastMessageError: normalizeMessageError(value.lastMessageError),
lastMessageError: normalizeLastMessageError(value.lastMessageError),
error: isRecord(value.error)
? {
code: string(value.error.code, 'WEIXIN_ACCOUNT_ERROR'),