@@ -5,12 +5,13 @@ import { useCallback, useEffect, useReducer, useRef, useState } from "react";
5
5
import { useSearchParams } from "react-router-dom" ;
6
6
7
7
import { SSE } from "sse.js" ;
8
- import useSWR from "swr" ;
8
+ import useSWR , { mutate } from "swr" ;
9
9
import { AIHelpLog } from "./rust-types" ;
10
10
import { useGleanClick } from "../../telemetry/glean-context" ;
11
11
import { AI_HELP } from "../../telemetry/constants" ;
12
12
import { useAIHelpSettings } from "./utils" ;
13
13
import { EVENT_TIMEOUT } from "./constants" ;
14
+ import { AI_HELP_QUOTA_PATH } from "../common/api" ;
14
15
15
16
const RETRY_INTERVAL = 10000 ;
16
17
const ERROR_TIMEOUT = 60000 ;
@@ -384,6 +385,7 @@ export function useAiChat({
384
385
eventSourceRef . current ?. close ( ) ;
385
386
eventSourceRef . current = undefined ;
386
387
setLoadingState ( "failed" ) ;
388
+ mutate ( AI_HELP_QUOTA_PATH ) ;
387
389
console . error ( err ) ;
388
390
} ,
389
391
[ gleanClick ]
@@ -694,18 +696,15 @@ export function useAiChat({
694
696
} , [ state , path , setMessages ] ) ;
695
697
696
698
function useRemoteQuota ( ) {
697
- const { data } = useSWR < Quota > (
698
- "/api/v1/plus/ai/help/quota" ,
699
- async ( url ) => {
700
- const response = await fetch ( url ) ;
701
- if ( ! response . ok ) {
702
- const text = await response . text ( ) ;
703
- throw new Error ( `${ response . status } on ${ url } : ${ text } ` ) ;
704
- }
705
- const data = await response . json ( ) ;
706
- return data . quota ;
699
+ const { data } = useSWR < Quota > ( AI_HELP_QUOTA_PATH , async ( url ) => {
700
+ const response = await fetch ( url ) ;
701
+ if ( ! response . ok ) {
702
+ const text = await response . text ( ) ;
703
+ throw new Error ( `${ response . status } on ${ url } : ${ text } ` ) ;
707
704
}
708
- ) ;
705
+ const data = await response . json ( ) ;
706
+ return data . quota ;
707
+ } ) ;
709
708
710
709
return data ;
711
710
}
0 commit comments