mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
* improvement(usage-limit): update usage in real time, fix token output object * updated tokenBreakdown to tokens, standardized input/output/total token object type across providers * update remaining references * ack PR comment * remove singleton query client instance from hooks, leave only in zustand
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
|
|
/**
|
|
* Singleton QueryClient instance for client-side use.
|
|
* Can be imported directly for cache operations outside React components.
|
|
*/
|
|
function makeQueryClient() {
|
|
return new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: 30 * 1000,
|
|
gcTime: 5 * 60 * 1000,
|
|
refetchOnWindowFocus: false,
|
|
retry: 1,
|
|
retryOnMount: false,
|
|
},
|
|
mutations: {
|
|
retry: 1,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
let browserQueryClient: QueryClient | undefined
|
|
|
|
export function getQueryClient() {
|
|
if (typeof window === 'undefined') {
|
|
return makeQueryClient()
|
|
}
|
|
if (!browserQueryClient) {
|
|
browserQueryClient = makeQueryClient()
|
|
}
|
|
return browserQueryClient
|
|
}
|
|
|
|
export function QueryProvider({ children }: { children: ReactNode }) {
|
|
const queryClient = getQueryClient()
|
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
}
|