mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-18 16:06:47 +00:00
Use regular Ultrafast rates for Astra and Sol. Show a double bolt for Ultrafast requests and remove backgrounds from error origin icons. Co-authored-by: Codex <noreply@openai.com>
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import type { UsageErrorFacts } from '@/api/modules/usage'
|
|
import { t } from '@/i18n'
|
|
|
|
export type UsageErrorRecord = UsageErrorFacts & {
|
|
provider: string | null
|
|
logicalOutcome: string
|
|
}
|
|
|
|
export function usageDisplayOutcome(outcome: string, errorCode: string | null, errorKind: string | null): string {
|
|
// 已开始交付的请求仍可能明确失败,展示不改变原始终态
|
|
// 进程中断和缺少明确错误的断流保留未完成,不从 HTTP 状态或文案推断
|
|
if (outcome === 'incomplete' && errorKind !== 'process_interrupted' && (errorCode || errorKind === 'timeout'))
|
|
return 'failed'
|
|
return outcome
|
|
}
|
|
|
|
export function usageErrorTitle(record: Pick<UsageErrorRecord, 'logicalOutcome' | 'errorCode' | 'errorKind'>): string {
|
|
return usageDisplayOutcome(record.logicalOutcome, record.errorCode, record.errorKind) === 'incomplete'
|
|
? t('usage.error.responseIsNotComplete')
|
|
: t('usage.error.requestFailed')
|
|
}
|
|
|
|
export function usageErrorOrigin(record: Pick<UsageErrorFacts, 'errorOrigin'>) {
|
|
const origins = {
|
|
proxy: {
|
|
label: t('usage.error.origin.proxy'),
|
|
className: 'text-z-blue-text',
|
|
hint: null,
|
|
},
|
|
upstream: {
|
|
label: t('usage.error.origin.upstream'),
|
|
className: 'text-z-error-text',
|
|
hint: null,
|
|
},
|
|
connection: {
|
|
label: t('usage.error.origin.connection'),
|
|
className: 'text-z-warning-text',
|
|
hint: t('usage.error.origin.connectionHint'),
|
|
},
|
|
unknown: {
|
|
label: t('usage.error.origin.unknown'),
|
|
className: 'text-z-text-secondary',
|
|
hint: t('usage.error.origin.unknownHint'),
|
|
},
|
|
}
|
|
return { kind: record.errorOrigin, ...origins[record.errorOrigin] }
|
|
}
|
|
|
|
export function usageSendStateText(state: string) {
|
|
switch (state) {
|
|
case 'not_sent': return t('usage.error.sendState.notSent')
|
|
case 'sent': return t('usage.error.sendState.sent')
|
|
case 'ambiguous': return t('usage.error.sendState.ambiguous')
|
|
case 'unknown': return t('usage.error.responseNotRecorded')
|
|
default: return state
|
|
}
|
|
}
|
|
|
|
export function usageErrorCode(record: UsageErrorFacts): string | null {
|
|
return record.websocketCloseCode != null
|
|
? `WS ${record.websocketCloseCode}`
|
|
: record.errorCode
|
|
}
|