39 lines
1.0 KiB
TypeScript
39 lines
1.0 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'>,
|
|
attemptIndex: number,
|
|
): boolean {
|
|
return info.class === 'transient' && attemptIndex < 2;
|
|
}
|
|
|
|
/** @deprecated 请使用 shouldAutoRetryChat / shouldAutoRetryTask */
|
|
export function shouldAutoRetry(
|
|
info: Pick<ChatErrorInfo, 'class'>,
|
|
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';
|
|
}
|