Files
Agent-System/web/src/api/chatRetry.ts
T

46 lines
1.2 KiB
TypeScript

import type { ChatErrorInfo } from '../types/workbench';
/** 闲聊 SSE:幂等协议落地前禁止自动重放完整 POST */
export function shouldAutoRetryChat(
_info: Pick<ChatErrorInfo, 'class'>,
_attemptIndex: number,
): boolean {
return false;
}
/** 长任务 SSE:仍允许有限次瞬态自动重试 */
export function shouldAutoRetryTask(
info: Pick<ChatErrorInfo, 'class' | 'code'>,
attemptIndex: number,
): boolean {
if (
info.code === 'DOC_TASK_NOT_IN_ACTIVE_STAGE' ||
info.code === 'DOC_DUTY_FORBIDDEN' ||
info.code === 'ERR_FORBIDDEN'
) {
return false;
}
return info.class === 'transient' && attemptIndex < 2;
}
/** @deprecated 请使用 shouldAutoRetryChat / shouldAutoRetryTask */
export function shouldAutoRetry(
info: Pick<ChatErrorInfo, 'class' | 'code'>,
attemptIndex: number,
): boolean {
return shouldAutoRetryTask(info, attemptIndex);
}
export function autoRetryDelayMs(attemptIndex: number): number {
return attemptIndex === 0 ? 1000 : 2000;
}
export function fallbackErrorClass(criteria: {
network?: boolean;
workspaceId?: string;
}): ChatErrorInfo['class'] {
if (criteria.network) return 'transient';
if (criteria.workspaceId) return 'resumable';
return 'fatal';
}