Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
476 changes: 463 additions & 13 deletions apps/web/src/features/demo/demoFixtures.ts

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions apps/web/src/features/monitoring/accountOverviewState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ describe('accountOverviewState', () => {
});
});

it('does not show a bare provider name under its multi-key disambiguated primary label', () => {
const row = createAccountRow({
account: 'kuaileshifu',
displayAccount: 'kuaileshifu #1',
accountMasked: 'kuaileshifu',
authLabels: ['kuaileshifu'],
channels: ['kuaileshifu'],
});

expect(resolveAccountDisplayText(row, 'masked')).toMatchObject({
primary: 'kuaileshifu #1',
secondary: '',
});
expect(resolveAccountDisplayText(row, 'full')).toMatchObject({
primary: 'kuaileshifu #1',
secondary: '',
});
});

it('keeps the existing default account sort contract', () => {
expect(DEFAULT_ACCOUNT_SORT).toEqual({ key: 'lastSeenAt', direction: 'desc' });
expect(normalizeAccountSortState(undefined)).toEqual(DEFAULT_ACCOUNT_SORT);
Expand Down
22 changes: 21 additions & 1 deletion apps/web/src/features/monitoring/accountOverviewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@ const hasReadableAccountValue = (value: string | null | undefined) => {
const firstReadableAccountValue = (...values: Array<string | null | undefined>) =>
values.find(hasReadableAccountValue)?.trim() || '';

const isRedundantAccountLabel = (
candidate: string | null | undefined,
primary: string | null | undefined
) => {
const candidateValue = String(candidate || '').trim();
const primaryValue = String(primary || '').trim();
if (!candidateValue || !primaryValue) return false;
if (candidateValue === primaryValue) return true;
const lowerCandidate = candidateValue.toLowerCase();
const lowerPrimary = primaryValue.toLowerCase();
return (
lowerPrimary.startsWith(`${lowerCandidate} #`) || lowerCandidate.startsWith(`${lowerPrimary} #`)
);
};

export const resolveAccountDisplayText = (
row: Pick<
MonitoringAccountRow,
Expand Down Expand Up @@ -236,7 +251,12 @@ export const resolveAccountDisplayText = (
]
: [maskedAccount, fullAccount];
const secondary =
secondaryCandidates.find((value) => hasReadableAccountValue(value) && value !== primary) || '';
secondaryCandidates.find(
(value) =>
hasReadableAccountValue(value) &&
value !== primary &&
!isRedundantAccountLabel(value, primary)
) || '';
const titleParts = Array.from(
new Set([primary, fullAccount, maskedAccount, secondary].filter(hasReadableAccountValue))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,29 @@ export const getCodexPlanLabel = (
return planType || normalized;
};

const isRedundantAccountSecondaryLabel = (candidate: string, primaryText: string) => {
if (!candidate || !primaryText || candidate === primaryText) return true;
const lowerCandidate = candidate.toLowerCase();
const lowerPrimary = primaryText.toLowerCase();
return (
lowerPrimary.startsWith(`${lowerCandidate} #`) || lowerCandidate.startsWith(`${lowerPrimary} #`)
);
};

export const buildAccountSecondaryText = (row: MonitoringAccountRow) => {
const primaryText = row.displayAccount || row.account;
if (row.account && row.account !== primaryText) {
if (row.account && !isRedundantAccountSecondaryLabel(row.account, primaryText)) {
return row.account;
}

const extraAuthLabels = row.authLabels.filter((label) => label && label !== primaryText);
const extraAuthLabels = row.authLabels.filter(
(label) => label && !isRedundantAccountSecondaryLabel(label, primaryText)
);
if (extraAuthLabels.length > 0) {
return joinShort(extraAuthLabels, 2);
}
const extraChannels = row.channels.filter(
(label) => label && label !== '-' && label !== primaryText
(label) => label && label !== '-' && !isRedundantAccountSecondaryLabel(label, primaryText)
);
if (extraChannels.length > 0) {
return joinShort(extraChannels, 2);
Expand Down
91 changes: 91 additions & 0 deletions apps/web/src/features/monitoring/model/eventRows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,95 @@ describe('buildEventRows', () => {
expect(row.provider).toBe('codex');
expect(display.primary).toBe('Shared Relay');
});

it('prefers multi-key OpenAI-compatible disambiguation in realtime source cells', () => {
const sourceInfoMap = buildSourceInfoMap({
openaiCompatibility: [
{
name: 'kuaileshifu',
baseUrl: 'https://api.kuaileshifu.example/v1',
apiKeyEntries: [
{ apiKey: 'sk-openai111111aaaa', authIndex: 'kuai-auth-1' },
{ apiKey: 'sk-openai222222bbbb', authIndex: 'kuai-auth-2' },
],
},
],
});
const authMetaMap = new Map([
[
'kuai-auth-1',
{
authIndex: 'kuai-auth-1',
label: 'kuaileshifu',
account: 'kuaileshifu',
provider: 'openai',
status: 'active',
disabled: false,
unavailable: false,
runtimeOnly: false,
planType: '-',
updatedAt: '',
},
],
]);
const channelByAuthIndex = new Map([
[
'kuai-auth-1',
{
key: 'openai:0',
name: 'kuaileshifu',
baseUrl: 'https://api.kuaileshifu.example/v1',
host: 'api.kuaileshifu.example',
disabled: false,
authIndices: ['kuai-auth-1', 'kuai-auth-2'],
modelNames: [],
},
],
]);

const [row] = buildEventRows(
[
{
timestamp: '2026-05-19T10:00:00Z',
source: 'm:sk-o...aaaa',
auth_index: 'kuai-auth-1',
account_snapshot: 'kuaileshifu',
auth_label_snapshot: 'kuaileshifu',
auth_provider_snapshot: 'openai',
latency_ms: 1500,
tokens: {
input_tokens: 10,
output_tokens: 20,
total_tokens: 30,
},
failed: false,
__modelName: 'gpt-4.1-mini',
__endpoint: 'POST /v1/chat/completions',
__endpointMethod: 'POST',
__endpointPath: '/v1/chat/completions',
__timestampMs: Date.parse('2026-05-19T10:00:00Z'),
},
],
authMetaMap,
new Map(),
sourceInfoMap,
channelByAuthIndex,
{},
new Map()
);

const t = ((key: string) => {
if (key === 'monitoring.filter_provider') return 'Provider';
if (key === 'monitoring.column_host') return 'Host';
if (key === 'monitoring.source') return 'Source';
return key;
}) as Parameters<typeof buildRealtimeSourceDisplay>[1];
const display = buildRealtimeSourceDisplay(row, t);

expect(row.source).toBe('kuaileshifu #1');
expect(row.sourceMasked).toBe('kuaileshifu #1');
expect(row.channel).toBe('kuaileshifu');
expect(display.primary).toBe('kuaileshifu #1');
expect(display.meta).toBe('Provider: openai');
});
});
29 changes: 23 additions & 6 deletions apps/web/src/features/monitoring/model/eventRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { formatApiKeyHashLabel } from './base';
import { buildSearchText, maskAuthIndex, maskEmailLike, readString } from './base';
import { sanitizeApiKeyDisplayText, type ApiKeyDisplayInfo } from './apiKeys';
import { isKeyDisambiguatedLabel } from './sourceDisplay';
import { buildHourLabel, buildLocalDayKey } from './range';
import type { MonitoringAuthMeta, MonitoringChannelMeta, MonitoringEventRow } from './types';

Expand Down Expand Up @@ -64,7 +65,28 @@ export const buildEventRows = (
detail.auth_provider_snapshot ?? detail.authProviderSnapshot
);
const snapshotDisplay = snapshotAccount || snapshotLabel;
const sourceLabel = authMeta?.label || snapshotDisplay || sourceMeta.displayName || authIndex;
const channelMeta =
channelByAuthIndex.get(authIndex) ||
(authMeta?.authIndex ? channelByAuthIndex.get(authMeta.authIndex) : undefined);
const channelLabel =
channelMeta?.name || authMeta?.provider || snapshotProvider || sourceMeta.type || '-';
const resolvedSourceName = readString(sourceMeta.displayName);
const labelCandidates = authMeta?.label || snapshotLabel || snapshotDisplay;
// Prefer multi-key OpenAI-compatible disambiguation (e.g. "kuaileshifu #1") over the
// bare provider/auth label so realtime cells match account overview identity.
const sourceLabel =
(resolvedSourceName &&
(isKeyDisambiguatedLabel(resolvedSourceName, channelMeta?.name) ||
isKeyDisambiguatedLabel(resolvedSourceName, channelMeta?.host) ||
isKeyDisambiguatedLabel(resolvedSourceName, labelCandidates) ||
isKeyDisambiguatedLabel(resolvedSourceName, authMeta?.account) ||
isKeyDisambiguatedLabel(resolvedSourceName, snapshotAccount))
? resolvedSourceName
: '') ||
authMeta?.label ||
snapshotDisplay ||
resolvedSourceName ||
authIndex;
const sourceMasked = maskEmailLike(sourceLabel);
const account = authMeta?.account || snapshotAccount || sourceLabel;
const accountMasked = maskEmailLike(account);
Expand All @@ -78,11 +100,6 @@ export const buildEventRows = (
apiKeyDisplay?.masked || apiKeyLabel,
apiKeyLabel
);
const channelMeta =
channelByAuthIndex.get(authIndex) ||
(authMeta?.authIndex ? channelByAuthIndex.get(authMeta.authIndex) : undefined);
const channelLabel =
channelMeta?.name || authMeta?.provider || snapshotProvider || sourceMeta.type || '-';
const endpoint = readString(detail.__endpoint) || '-';
const endpointMethod = readString(detail.__endpointMethod) || '-';
const endpointPath = readString(detail.__endpointPath) || endpoint;
Expand Down
Loading
Loading