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
105 changes: 95 additions & 10 deletions apps/web/src/features/monitoring/ModelPricesPage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@
min-width: 0;
}

.tierClearNotice {
grid-column: 1 / -1;
padding: 7px 9px;
border: 1px solid color-mix(in srgb, var(--warning-color) 35%, var(--pricing-line));
border-radius: 10px;
background: color-mix(in srgb, var(--warning-color) 8%, var(--pricing-surface));
color: var(--pricing-muted);
font-size: 11px;
}

.titleGroup {
flex-wrap: nowrap;
}
Expand Down Expand Up @@ -255,6 +245,96 @@
padding-bottom: 1px;
}

.pricingRulesEditor {
display: grid;
grid-column: 1 / -1;
gap: 8px;
min-width: 0;
}

.ruleSection {
display: grid;
gap: 8px;
min-width: 0;
padding: 8px;
border: 1px solid var(--pricing-line);
border-radius: 10px;
background: color-mix(in srgb, var(--pricing-surface) 72%, var(--pricing-surface-muted));
}

.ruleSectionHeader {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}

.ruleSectionHeader > div {
display: grid;
gap: 2px;
}

.ruleSectionHeader strong {
font-size: 12px;
}

.ruleSectionHeader span,
.ruleEmpty {
color: var(--pricing-muted);
font-size: 11px;
}

.ruleSectionHeader :global(.btn > span) {
display: inline-flex;
align-items: center;
gap: 5px;
}

.ruleList {
display: grid;
gap: 7px;
min-width: 0;
overflow-x: auto;
}

.contextRuleRow,
.serviceRuleRow {
display: grid;
align-items: end;
gap: 7px;
min-width: 920px;
padding-top: 7px;
border-top: 1px solid color-mix(in srgb, var(--pricing-line) 70%, transparent);
}

.contextRuleRow {
grid-template-columns: minmax(120px, 1.1fr) repeat(5, minmax(105px, 1fr)) auto;
}

.serviceRuleRow {
grid-template-columns: repeat(2, minmax(110px, 1.1fr)) repeat(5, minmax(105px, 1fr)) auto;
min-width: 1060px;
}

.ruleDeleteButton {
display: inline-flex;
align-items: center;
justify-content: center;
width: 30px;
height: 32px;
padding: 0;
border: 1px solid var(--pricing-line);
border-radius: 9px;
background: var(--pricing-surface);
color: var(--pricing-muted);
cursor: pointer;
}

.ruleDeleteButton:hover {
border-color: color-mix(in srgb, var(--pricing-red) 35%, var(--pricing-line));
color: var(--pricing-red);
}

.tableWrap {
overflow-x: auto;
border: 1px solid var(--pricing-line);
Expand Down Expand Up @@ -475,4 +555,9 @@
.candidateControl {
grid-template-columns: 1fr;
}

.ruleSectionHeader {
align-items: flex-start;
flex-direction: column;
}
}
98 changes: 95 additions & 3 deletions apps/web/src/features/monitoring/ModelPricesPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ describe('ModelPricesPage Attention UI', () => {
acknowledgeSnapshot: vi.fn().mockResolvedValue(undefined),
};

vi.spyOn(attentionHook, 'useModelPriceAttention').mockImplementation(
() => mockAttentionState
);
vi.spyOn(attentionHook, 'useModelPriceAttention').mockImplementation(() => mockAttentionState);
});

it('renders pending count badge on Sync Prices button when pendingCount > 0', async () => {
Expand Down Expand Up @@ -339,4 +337,98 @@ describe('ModelPricesPage Attention UI', () => {

expect(mockAttentionState.check).toHaveBeenCalledWith({ force: true });
});

it('preserves special pricing rules and refreshes attention after editing an existing price', async () => {
const setModelPrices = vi.fn().mockResolvedValue(undefined);
vi.mocked(usageDataHook.useUsageData).mockReturnValue({
loading: false,
modelPrices: {
'tiered-model': {
prompt: 5,
completion: 25,
cache: 0.5,
contextTiers: [
{
thresholdTokens: 128_000,
prompt: 10,
completion: 0,
cache: 0,
promptConfigured: true,
completionConfigured: false,
cacheConfigured: false,
},
],
serviceTiers: [
{
mode: 'fast',
serviceTier: 'priority',
prompt: 0,
completion: 50,
cache: 0,
promptConfigured: true,
completionConfigured: true,
cacheConfigured: false,
},
],
},
},
setModelPrices,
syncModelPrices: mockSyncModelPrices,
usageServiceAvailable: true,
} as unknown as ReturnType<typeof usageDataHook.useUsageData>);

let renderer: ReactTestRenderer;
await act(async () => {
renderer = create(
<MemoryRouter initialEntries={['/model-prices']}>
<ModelPricesPage />
</MemoryRouter>
);
});

const root = renderer!.root;
const editButton = root
.findAllByType('button')
.find((button) => button.props['aria-label'] === 'common.edit');
if (!editButton) throw new Error('edit button not found');

await act(async () => {
editButton.props.onClick();
});
const inputPrice = root.findByProps({ 'data-testid': 'draft-input-price' });
await act(async () => {
inputPrice.props.onChange({ target: { value: '6' } });
});

const saveButton = root.findByProps({ 'data-testid': 'save-draft-button' });
await act(async () => {
saveButton.props.onClick();
});

expect(setModelPrices).toHaveBeenCalledWith({
'tiered-model': expect.objectContaining({
prompt: 6,
source: 'manual',
contextTiers: [
expect.objectContaining({
thresholdTokens: 128_000,
prompt: 10,
promptConfigured: true,
completionConfigured: false,
}),
],
serviceTiers: [
expect.objectContaining({
mode: 'fast',
serviceTier: 'priority',
prompt: 0,
completion: 50,
promptConfigured: true,
completionConfigured: true,
}),
],
}),
});
expect(mockAttentionState.check).toHaveBeenCalledWith({ force: true });
});
});
Loading
Loading