Add assistant cost usage limits to Settings - #3843
Conversation
📊 Performance Test ResultsComparing 63dc83c vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
| sprintf( | ||
| __( '%1$s of monthly limit used (resets on %2$s)' ), | ||
| formatPercentage( |
There was a problem hiding this comment.
We could add a message for the translators.
/* translators: %1$s: percentage of monthly limit used (e.g. 7.5%). %2$s: date the limit resets (e.g. July 1, 2026). */
There was a problem hiding this comment.
I am wondering if it would make sense to change the design of the bar once the limit is hit e.g. make it red or something like this.
But it is not a strong preference, so we can also leave this as is.
There was a problem hiding this comment.
The idea is cool. I propose keeping it as is and maybe talking with Shaun Andrews later to improve the UI as a whole.
| isError: false, | ||
| isLoading: false, | ||
| refetch: vi.fn(), | ||
| } as unknown as ReturnType< typeof useGetStudioAssistantQuota > ); |
There was a problem hiding this comment.
We can avoid using the as unknown as ReturnType by using partial which would be a bit cleaner:
nfo.test.tsx
index 5a670b28e..abfc3190d 100644
--- a/apps/studio/src/modules/user-settings/components/tests/prompt-info.test.tsx
+++ b/apps/studio/src/modules/user-settings/components/tests/prompt-info.test.tsx
@@ -20,7 +20,7 @@ describe( 'PromptInfo', () => {
} );
it( 'shows Studio Code dollar usage and reset date', () => {
- vi.mocked( useGetStudioAssistantQuota ).mockReturnValue( {
+ vi.mocked( useGetStudioAssistantQuota, { partial: true } ).mockReturnValue( {
data: {
costUsage: 33392,
costCap: 20000000,
@@ -29,7 +29,7 @@ describe( 'PromptInfo', () => {
isError: false,
isLoading: false,
refetch: vi.fn(),
- } as unknown as ReturnType< typeof useGetStudioAssistantQuota > );
+ } );
render( <PromptInfo /> );
@@ -42,7 +42,7 @@ describe( 'PromptInfo', () => {
} );
it( 'shows unavailable message when cost cap is missing', () => {
- vi.mocked( useGetStudioAssistantQuota ).mockReturnValue( {
+ vi.mocked( useGetStudioAssistantQuota, { partial: true } ).mockReturnValue( {
data: {
costUsage: 0,
costCap: 0,
@@ -51,7 +51,7 @@ describe( 'PromptInfo', () => {
isError: false,
isLoading: false,
refetch: vi.fn(),
- } as unknown as ReturnType< typeof useGetStudioAssistantQuota > );
+ } );
render( <PromptInfo /> );
@@ -61,7 +61,7 @@ describe( 'PromptInfo', () => {
} );
it( 'caps over-limit usage at 100%', () => {
- vi.mocked( useGetStudioAssistantQuota ).mockReturnValue( {
+ vi.mocked( useGetStudioAssistantQuota, { partial: true } ).mockReturnValue( {
data: {
costUsage: 3403700000,
costCap: 20000000,
@@ -70,7 +70,7 @@ describe( 'PromptInfo', () => {
isError: false,
isLoading: false,
refetch: vi.fn(),
- } as unknown as ReturnType< typeof useGetStudioAssistantQuota > );
+ } );
render( <PromptInfo /> );
katinthehatsite
left a comment
There was a problem hiding this comment.
The changes look good but I added one comment regarding cleaning up the tests a bit


Related issues
How AI was used in this PR
AI helped with writing code, iterated, I reviewed carefully and adjusted.
Proposed Changes
We will display percentage of usage limits based on cost in Studio Settings.
Testing Instructions
'cost_usage' => 1500000,inclass-studio-app-ai-assistant.php'cost_usage' => 30000000,(bigger than the cap)