mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-20 08:01:46 +00:00
fix(usage): improve request record layout and error summaries
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import type { UsageListRecord } from '@/api'
|
||||
import { ZPopover, ZScrollbar } from '@codex-proxy/ui'
|
||||
import { CheckCheck, CircleHelp, Network, Server, Unplug } from '@lucide/vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { usageErrorCode, usageErrorOrigin, usageErrorTitle } from './shared/errors'
|
||||
import { usageErrorOrigin, usageErrorReason, usageErrorTitle } from './shared/errors'
|
||||
|
||||
const props = defineProps<{ record: UsageListRecord }>()
|
||||
|
||||
@@ -15,16 +16,23 @@ const originIcons = {
|
||||
}
|
||||
|
||||
const { t } = useI18n({ useScope: 'global' })
|
||||
const message = computed(() => props.record.errorMessage?.replace(/^OpenAI upstream failure: /, ''))
|
||||
const code = computed(() => usageErrorCode(props.record) || props.record.errorKind)
|
||||
const code = computed(() => props.record.errorCode || props.record.errorKind)
|
||||
const errorType = computed(() => props.record.errorKind || props.record.errorCode)
|
||||
const origin = computed(() => usageErrorOrigin(props.record))
|
||||
const outcome = computed(() => usageErrorTitle(props.record))
|
||||
const summary = computed(() => message.value || code.value || t('usage.error.noDetails'))
|
||||
const summary = computed(() => {
|
||||
const reason = usageErrorReason(code.value) || props.record.errorMessage || code.value
|
||||
if (reason)
|
||||
return reason
|
||||
return props.record.websocketCloseCode != null
|
||||
? `WS ${props.record.websocketCloseCode}`
|
||||
: t('usage.error.noDetails')
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-w-0 py-0.5">
|
||||
<div class="flex min-w-0 items-start gap-2">
|
||||
<div class="flex min-w-0 items-center gap-1.5 text-z-xs text-z-text-secondary">
|
||||
<span
|
||||
class="inline-flex size-5 shrink-0 items-center justify-center"
|
||||
:class="origin.className"
|
||||
@@ -34,20 +42,47 @@ const summary = computed(() => message.value || code.value || t('usage.error.noD
|
||||
>
|
||||
<component :is="originIcons[origin.kind]" class="size-3.5" aria-hidden="true" />
|
||||
</span>
|
||||
<span class="line-clamp-2 min-w-0 text-z-sm font-medium wrap-anywhere text-z-text" :title="summary" translate="no">{{ summary }}</span>
|
||||
</div>
|
||||
<div class="mt-1 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-z-xs text-z-text-secondary">
|
||||
<span>{{ outcome }}</span>
|
||||
<code v-if="message && code && code !== message" class="truncate font-mono" :title="code" translate="no">{{ code }}</code>
|
||||
<span v-if="record.upstreamStatusCode != null" class="shrink-0 font-mono text-z-xs text-z-text-secondary" :title="t('usage.error.upstreamStatusCode')">
|
||||
{{ t('usage.error.upstreamHttpStatus', { status: record.upstreamStatusCode }) }}
|
||||
</span>
|
||||
<span v-if="record.clientStatusCode != null && record.clientStatusCode !== record.upstreamStatusCode" class="shrink-0 font-mono text-z-xs text-z-text-secondary" :title="t('usage.error.clientStatusCode')">
|
||||
{{ t('usage.error.clientHttpStatus', { status: record.clientStatusCode }) }}
|
||||
<span class="truncate">
|
||||
<span class="font-emphasis">{{ outcome }}</span>
|
||||
<span v-if="record.upstreamStatusCode != null" class="ms-1.5 font-mono" :title="t('usage.error.upstreamStatusCode')">
|
||||
{{ t('usage.error.upstreamHttpStatus', { status: record.upstreamStatusCode }) }}
|
||||
</span>
|
||||
<span v-if="record.clientStatusCode != null && record.clientStatusCode !== record.upstreamStatusCode" class="ms-1.5 font-mono" :title="t('usage.error.clientStatusCode')">
|
||||
{{ t('usage.error.clientHttpStatus', { status: record.clientStatusCode }) }}
|
||||
</span>
|
||||
</span>
|
||||
<span v-if="record.recovered" class="inline-flex shrink-0 text-z-success-text" role="img" :aria-label="t('usage.error.recovered')" :title="t('usage.error.recovered')">
|
||||
<CheckCheck class="size-4" :stroke-width="2.25" aria-hidden="true" />
|
||||
</span>
|
||||
</div>
|
||||
<ZPopover class="mt-1 flex!" trigger="hover-click" placement="top-start" role="tooltip">
|
||||
<template #reference="{ id, open }">
|
||||
<button
|
||||
type="button"
|
||||
class="block min-w-0 cursor-pointer truncate rounded-z-sm border-0 bg-transparent p-0 text-left text-z-sm font-medium text-z-text focus-visible:ring-2 focus-visible:ring-z-control-outline"
|
||||
:aria-expanded="open"
|
||||
:aria-describedby="open ? id : undefined"
|
||||
translate="no"
|
||||
>
|
||||
<template v-if="errorType && errorType !== summary">
|
||||
<code class="font-mono text-z-xs text-z-text-secondary">{{ errorType }}</code>
|
||||
<span class="mx-1 text-z-text-secondary" aria-hidden="true">·</span>
|
||||
</template>
|
||||
<span>{{ summary }}</span>
|
||||
</button>
|
||||
</template>
|
||||
<ZScrollbar class="w-max max-w-[min(26rem,calc(100vw-2rem))]" max-height="min(18rem, 60dvh)">
|
||||
<div class="grid gap-1 px-3 py-2 text-z-sm leading-relaxed whitespace-pre-wrap select-text wrap-anywhere" translate="no">
|
||||
<code v-if="code" class="font-mono font-emphasis">{{ code }}</code>
|
||||
<span v-if="record.errorKind && record.errorKind !== code">
|
||||
{{ t('usage.error.failureClassification') }} · <code>{{ record.errorKind }}</code>
|
||||
</span>
|
||||
<span v-if="record.websocketCloseCode != null">
|
||||
{{ t('usage.error.websocketCloseCode') }} · <code>{{ record.websocketCloseCode }}</code>
|
||||
</span>
|
||||
<span>{{ record.errorMessage || t('usage.error.noDetails') }}</span>
|
||||
</div>
|
||||
</ZScrollbar>
|
||||
</ZPopover>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -56,8 +56,21 @@ export function usageSendStateText(state: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function usageErrorCode(record: UsageErrorFacts): string | null {
|
||||
return record.websocketCloseCode != null
|
||||
? `WS ${record.websocketCloseCode}`
|
||||
: record.errorCode
|
||||
export function usageErrorReason(code: string | null): string | undefined {
|
||||
switch (code) {
|
||||
case 'no_available_provider': return t('usage.error.noAvailableProvider')
|
||||
case 'rate_limited':
|
||||
case 'rate_limit_exceeded': return t('common.errors.rateLimited')
|
||||
case 'invalid_request': return t('common.errors.invalidParameters')
|
||||
case 'upstream_connection_closed': return t('usage.error.upstreamConnectionClosed')
|
||||
case 'upstream_timeout': return t('common.errors.upstreamTimeout')
|
||||
case 'timeout':
|
||||
case 'request_timeout': return t('common.errors.timeout')
|
||||
case 'concurrency_queue_timeout': return t('usage.error.queueTimeout')
|
||||
case 'concurrency_queue_full': return t('usage.error.queueFull')
|
||||
case 'message_too_big': return t('common.errors.payloadTooLarge')
|
||||
case 'cancelled':
|
||||
case 'request_cancelled': return t('common.errors.canceled')
|
||||
case 'internal_error': return t('common.errors.internal')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,6 +265,10 @@
|
||||
},
|
||||
"error": {
|
||||
"noDetails": "No detailed error message was recorded",
|
||||
"noAvailableProvider": "No upstream provider is available for this request.",
|
||||
"upstreamConnectionClosed": "Upstream connection closed",
|
||||
"queueTimeout": "Request queue wait timed out",
|
||||
"queueFull": "Request queue is full",
|
||||
"platform": "Provider",
|
||||
"requestModel": "Request model",
|
||||
"upstreamModel": "Upstream model",
|
||||
|
||||
@@ -265,6 +265,10 @@
|
||||
},
|
||||
"error": {
|
||||
"noDetails": "未记录具体错误消息",
|
||||
"noAvailableProvider": "此请求没有可用的上游服务",
|
||||
"upstreamConnectionClosed": "上游连接已关闭",
|
||||
"queueTimeout": "请求排队超时",
|
||||
"queueFull": "请求队列已满",
|
||||
"platform": "平台",
|
||||
"requestModel": "请求模型",
|
||||
"upstreamModel": "上游模型",
|
||||
|
||||
@@ -265,6 +265,10 @@
|
||||
},
|
||||
"error": {
|
||||
"noDetails": "未記錄具體錯誤消息",
|
||||
"noAvailableProvider": "此請求沒有可用的上游服務",
|
||||
"upstreamConnectionClosed": "上游連線已關閉",
|
||||
"queueTimeout": "請求排隊超時",
|
||||
"queueFull": "請求隊列已滿",
|
||||
"platform": "平臺",
|
||||
"requestModel": "請求模型",
|
||||
"upstreamModel": "上游模型",
|
||||
|
||||
@@ -8,6 +8,8 @@ import { t } from '@/i18n'
|
||||
|
||||
export function useUsageRecordColumns(status: Ref<UsageRecordStatus>, tableWidth: Readonly<Ref<number>>) {
|
||||
const columns = computed(() => usageRecordColumns.value.map((column) => {
|
||||
if (column.key === 'createdAtDisplay')
|
||||
return { ...column, width: 128 }
|
||||
if (column.key === 'accountEmail')
|
||||
return { ...column, width: 280, hideable: true }
|
||||
return ['clientApiKeyName', 'model', 'reasoningEffort'].includes(column.key)
|
||||
@@ -18,6 +20,7 @@ export function useUsageRecordColumns(status: Ref<UsageRecordStatus>, tableWidth
|
||||
const errors = useTableColumns(() => {
|
||||
const time = columns.value.find(column => column.key === 'createdAtDisplay')!
|
||||
const actionWidth = 72
|
||||
const errorWidth = 370
|
||||
return [
|
||||
{
|
||||
key: 'errorMessage',
|
||||
@@ -25,11 +28,11 @@ export function useUsageRecordColumns(status: Ref<UsageRecordStatus>, tableWidth
|
||||
kind: 'custom',
|
||||
fixed: 'left',
|
||||
minWidth: tableWidth.value
|
||||
? Math.min(310, Math.max(96, (tableWidth.value - actionWidth) / 2))
|
||||
: 310,
|
||||
? Math.min(errorWidth, Math.max(96, (tableWidth.value - actionWidth) / 2))
|
||||
: errorWidth,
|
||||
hideable: false,
|
||||
},
|
||||
{ ...time, width: 112 },
|
||||
time,
|
||||
...columns.value.filter(column => column.key !== time.key).map((column) => {
|
||||
if (column.key === 'transport')
|
||||
return { ...column, width: 112 }
|
||||
|
||||
@@ -91,7 +91,7 @@ watch(timeRange, () => {
|
||||
<div class="@container w-full">
|
||||
<ZPageHeader class="justify-end" :title="t('navigation.usage')" :description="t('usage.page.description')">
|
||||
<template #actions>
|
||||
<div class="flex w-[100cqw] max-w-[100cqw] flex-wrap items-center justify-end gap-2 @min-[21rem]:flex-nowrap @min-[28rem]:w-auto">
|
||||
<div class="flex w-[100cqw] max-w-[100cqw] flex-wrap items-center justify-end gap-2 @min-[21rem]:flex-nowrap @md:w-auto">
|
||||
<ZDatePicker
|
||||
v-model="timeRange"
|
||||
type="daterange"
|
||||
@@ -100,7 +100,7 @@ watch(timeRange, () => {
|
||||
:disabled-date="disabledDate"
|
||||
single-panel
|
||||
:aria-label="t('usage.page.dateRangeLabel')"
|
||||
class="min-w-0 flex-1 basis-full @min-[21rem]:basis-auto @min-[28rem]:w-60 @min-[28rem]:flex-none @max-[28rem]:[&>div]:gap-1.5 @max-[28rem]:[&>div]:px-2"
|
||||
class="min-w-0 flex-1 basis-full @min-[21rem]:basis-auto @md:w-60 @md:flex-none @max-md:[&>div]:gap-1.5 @max-md:[&>div]:px-2"
|
||||
/>
|
||||
<ProviderFilter
|
||||
v-model="providerQuery"
|
||||
@@ -140,7 +140,7 @@ watch(timeRange, () => {
|
||||
|
||||
<template #body>
|
||||
<div
|
||||
class="flex min-h-130 min-w-0 flex-1 flex-col gap-3"
|
||||
class="grid min-h-130 min-w-0 flex-1 grid-rows-[auto_minmax(0,1fr)] gap-3"
|
||||
>
|
||||
<UsageFilters
|
||||
v-model:field="filterField"
|
||||
@@ -167,7 +167,7 @@ watch(timeRange, () => {
|
||||
</template>
|
||||
</UsageFilters>
|
||||
|
||||
<div ref="tableArea" class="flex min-h-0 min-w-0 flex-1 flex-col">
|
||||
<div ref="tableArea" class="flex min-h-0 min-w-0 flex-col">
|
||||
<UsageRecordsTable
|
||||
class="min-h-0 flex-1"
|
||||
:columns="columns.visibleColumns.value"
|
||||
|
||||
Reference in New Issue
Block a user