Files
makelore/shared/opencode-error-kind.ts
brother7 d092132d86 fix: 修复额度耗尽错误展示
问题:Token balance exhausted 被作为原始助手气泡展示,且额度确认可能跨会话复用。

修复:区分绝对余额与滚动额度,绑定当前会话失败 key,并补充真实消息结构与双会话回归测试。
2026-08-08 19:34:31 +08:00

31 lines
1.2 KiB
TypeScript

export type OpencodeErrorKind = 'quota_exhausted' | 'authentication_invalid';
export function isOpencodeTokenBalanceExhausted(message: string | null | undefined): boolean {
const normalized = message?.trim().toLowerCase() ?? '';
return normalized.includes('token_balance_exhausted')
|| normalized.includes('token balance exhausted')
|| normalized.includes('balance exhausted');
}
export function getOpencodeErrorKind(message: string | null | undefined): OpencodeErrorKind | null {
const normalized = message?.trim().toLowerCase() ?? '';
if (!normalized) return null;
if (
isOpencodeTokenBalanceExhausted(normalized)
|| normalized.includes('user quota is not enough')
|| normalized.includes('quota is not enough')
|| normalized.includes('quota not enough')
|| normalized.includes('insufficient quota')
|| normalized.includes('quota exhausted')
|| normalized.includes('quota exceeded')
|| normalized.includes('rolling 5-hour window')
|| normalized.includes('额度不足')
) {
return 'quota_exhausted';
}
if (normalized.includes('works_square_gateway_authorize_failed')) {
return 'authentication_invalid';
}
return null;
}