Files
makelore/electron/coding-runtime/pi/provider-failure.ts

27 lines
1.0 KiB
TypeScript

import type { CodingRuntimePublicError } from '../contracts';
import { isAIGatewayUserContextMissing } from '../../../shared/ai-gateway-error-details';
import { getAIGatewayErrorKind } from '../../../shared/ai-gateway-error-kind';
export function projectPiProviderFailure(message: unknown): CodingRuntimePublicError {
if (typeof message === 'string' && (isAIGatewayUserContextMissing(message)
|| message.toLowerCase().includes('works square login session is missing or expired'))) {
return {
code: 'CODING_PROVIDER_AUTH_REQUIRED',
message: '登录已失效,请重新登录后继续。',
recoverable: true,
};
}
if (typeof message === 'string' && getAIGatewayErrorKind(message) === 'quota_exhausted') {
return {
code: 'CODING_PROVIDER_QUOTA_EXHAUSTED',
message: '词元点数余额不足,请充值后重试。',
recoverable: false,
};
}
return {
code: 'CODING_RUNTIME_START_FAILED',
message: '模型服务请求失败,请稍后重试。',
recoverable: true,
};
}