diff --git a/src/components/usage/RequestEventsDetailsCard.tsx b/src/components/usage/RequestEventsDetailsCard.tsx index d541750..5dcfb35 100644 --- a/src/components/usage/RequestEventsDetailsCard.tsx +++ b/src/components/usage/RequestEventsDetailsCard.tsx @@ -8,7 +8,7 @@ import { authFilesApi } from '@/services/api/authFiles'; import type { GeminiKeyConfig, ProviderKeyConfig, OpenAIProviderConfig } from '@/types'; import type { AuthFileItem } from '@/types/authFile'; import type { CredentialInfo } from '@/types/sourceInfo'; -import { buildSourceInfoMap } from '@/utils/sourceResolver'; +import { buildSourceInfoMap, resolveSourceDisplay } from '@/utils/sourceResolver'; import { collectUsageDetails, extractTotalTokens, @@ -128,13 +128,9 @@ export function RequestEventsDetailsCard({ authIndexRaw === null || authIndexRaw === undefined || authIndexRaw === '' ? '-' : String(authIndexRaw); - const normalizedAuthIndex = normalizeAuthIndex(authIndexRaw); - const sourceInfo = sourceInfoMap.get(sourceRaw); - const authInfo = normalizedAuthIndex ? authFileMap.get(normalizedAuthIndex) : undefined; - const source = sourceInfo?.displayName - || authInfo?.name - || (sourceRaw.startsWith('t:') ? sourceRaw.slice(2) : sourceRaw || '-'); - const sourceType = sourceInfo?.type || authInfo?.type || ''; + const sourceInfo = resolveSourceDisplay(sourceRaw, authIndexRaw, sourceInfoMap, authFileMap); + const source = sourceInfo.displayName; + const sourceType = sourceInfo.type; const model = String(detail.__modelName ?? '').trim() || '-'; const inputTokens = Math.max(toNumber(detail.tokens?.input_tokens), 0); const outputTokens = Math.max(toNumber(detail.tokens?.output_tokens), 0); diff --git a/src/pages/LogsPage.tsx b/src/pages/LogsPage.tsx index 0ea004d..d19f930 100644 --- a/src/pages/LogsPage.tsx +++ b/src/pages/LogsPage.tsx @@ -28,7 +28,7 @@ import { copyToClipboard } from '@/utils/clipboard'; import { downloadBlob } from '@/utils/download'; import { MANAGEMENT_API_PREFIX } from '@/utils/constants'; import { formatUnixTimestamp } from '@/utils/format'; -import { buildSourceInfoMap } from '@/utils/sourceResolver'; +import { buildSourceInfoMap, resolveSourceDisplay } from '@/utils/sourceResolver'; import { collectUsageDetailsWithEndpoint, normalizeAuthIndex, @@ -860,29 +860,8 @@ export function LogsPage() { return scored.slice(0, 8); }, [traceLogLine, traceUsageDetails]); const resolveTraceSourceInfo = useCallback( - (sourceRaw: string, authIndex: unknown): SourceInfo => { - const source = sourceRaw.trim(); - const matchedSource = traceSourceInfoMap.get(source); - if (matchedSource) { - return matchedSource; - } - - const authIndexKey = normalizeAuthIndex(authIndex); - if (authIndexKey) { - const authInfo = traceAuthFileMap.get(authIndexKey); - if (authInfo) { - return { - displayName: authInfo.name || authIndexKey, - type: authInfo.type - }; - } - } - - return { - displayName: source.startsWith('t:') ? source.slice(2) : source || '-', - type: '' - }; - }, + (sourceRaw: string, authIndex: unknown): SourceInfo => + resolveSourceDisplay(sourceRaw, authIndex, traceSourceInfoMap, traceAuthFileMap), [traceAuthFileMap, traceSourceInfoMap] ); diff --git a/src/utils/sourceResolver.ts b/src/utils/sourceResolver.ts index e593815..040b70c 100644 --- a/src/utils/sourceResolver.ts +++ b/src/utils/sourceResolver.ts @@ -1,6 +1,6 @@ import type { GeminiKeyConfig, OpenAIProviderConfig, ProviderKeyConfig } from '@/types'; -import type { SourceInfo } from '@/types/sourceInfo'; -import { buildCandidateUsageSourceIds } from '@/utils/usage'; +import type { CredentialInfo, SourceInfo } from '@/types/sourceInfo'; +import { buildCandidateUsageSourceIds, normalizeAuthIndex } from '@/utils/usage'; export interface SourceInfoMapInput { geminiApiKeys?: GeminiKeyConfig[]; @@ -57,3 +57,27 @@ export function buildSourceInfoMap(input: SourceInfoMapInput): Map, + authFileMap: Map +): SourceInfo { + const source = sourceRaw.trim(); + const matched = sourceInfoMap.get(source); + if (matched) return matched; + + const authIndexKey = normalizeAuthIndex(authIndex); + if (authIndexKey) { + const authInfo = authFileMap.get(authIndexKey); + if (authInfo) { + return { displayName: authInfo.name || authIndexKey, type: authInfo.type }; + } + } + + return { + displayName: source.startsWith('t:') ? source.slice(2) : source || '-', + type: '', + }; +}