kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat(web): fix example usage hydration error
rodzic
ddc8d499fc
commit
ea28dcde91
|
@ -1,16 +1,46 @@
|
|||
'use client'
|
||||
|
||||
import type React from 'react'
|
||||
import { QueryClientProvider } from '@tanstack/react-query'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||
|
||||
import { AgenticProvider } from '@/components/agentic-provider'
|
||||
import { PostHogProvider } from '@/components/posthog-provider'
|
||||
import { ThemeProvider } from '@/components/theme-provider'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { queryClient } from '@/lib/query-client'
|
||||
import { isServer } from '@/lib/config'
|
||||
|
||||
function createQueryClient() {
|
||||
return new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 60 * 1000
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let browserQueryClient: QueryClient | undefined
|
||||
|
||||
function getQueryClient(): QueryClient {
|
||||
if (isServer) {
|
||||
// Server: always make a new query client
|
||||
return createQueryClient()
|
||||
} else {
|
||||
// Browser: make a new query client if we don't already have one
|
||||
// This is very important, so we don't re-make a new client if React
|
||||
// suspends during the initial render. This may not be needed if we
|
||||
// have a suspense boundary BELOW the creation of the query client
|
||||
if (!browserQueryClient) {
|
||||
browserQueryClient = createQueryClient()
|
||||
}
|
||||
|
||||
return browserQueryClient
|
||||
}
|
||||
}
|
||||
|
||||
export default function Providers({ children }: { children: React.ReactNode }) {
|
||||
const queryClient = getQueryClient()
|
||||
|
||||
return (
|
||||
<PostHogProvider>
|
||||
<AgenticProvider>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use client'
|
||||
|
||||
import type { Project } from '@agentic/platform-types'
|
||||
import type { JSX } from 'react'
|
||||
import { type JSX, useEffect, useMemo, useState } from 'react'
|
||||
import { useLocalStorage } from 'react-use'
|
||||
|
||||
import { useAgentic } from '@/components/agentic-provider'
|
||||
|
@ -43,12 +43,22 @@ export function ExampleUsage({
|
|||
initialCodeBlock?: JSX.Element
|
||||
}) {
|
||||
const ctx = useAgentic()
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
|
||||
const [config, setConfig] = useLocalStorage<DeveloperConfig>(
|
||||
useEffect(() => {
|
||||
setIsMounted(true)
|
||||
}, [])
|
||||
|
||||
const [rawConfig, setConfig] = useLocalStorage<DeveloperConfig>(
|
||||
'developer-config',
|
||||
defaultConfig
|
||||
)
|
||||
|
||||
const config = useMemo(
|
||||
() => (isMounted && rawConfig ? rawConfig : defaultConfig),
|
||||
[rawConfig, isMounted]
|
||||
)
|
||||
|
||||
// TODO: make this configurable
|
||||
// TODO: allow to take the project and/or consumer in as props
|
||||
// TODO: need a way of fetching a project and target deployment; same as in `AgenticToolClient.fromIdentifier` (currently only supports latest)
|
||||
|
@ -151,7 +161,7 @@ function ExampleUsageContent({
|
|||
|
||||
return (
|
||||
<Tabs
|
||||
defaultValue={config.target}
|
||||
value={config.target}
|
||||
onValueChange={(value) =>
|
||||
setConfig({
|
||||
...defaultConfig,
|
||||
|
@ -176,7 +186,7 @@ function ExampleUsageContent({
|
|||
|
||||
<TabsContent value='mcp' className='w-full'>
|
||||
<Tabs
|
||||
defaultValue={config.mcpClientTarget}
|
||||
value={config.mcpClientTarget}
|
||||
onValueChange={(value) =>
|
||||
setConfig({
|
||||
...defaultConfig,
|
||||
|
@ -216,7 +226,7 @@ function ExampleUsageContent({
|
|||
|
||||
<TabsContent value='typescript' className='w-full'>
|
||||
<Tabs
|
||||
defaultValue={config.tsFrameworkTarget}
|
||||
value={config.tsFrameworkTarget}
|
||||
onValueChange={(value) =>
|
||||
setConfig({
|
||||
...defaultConfig,
|
||||
|
@ -252,7 +262,7 @@ function ExampleUsageContent({
|
|||
|
||||
<TabsContent value='python' className='w-full'>
|
||||
<Tabs
|
||||
defaultValue={config.pyFrameworkTarget}
|
||||
value={config.pyFrameworkTarget}
|
||||
onValueChange={(value) =>
|
||||
setConfig({
|
||||
...defaultConfig,
|
||||
|
@ -288,7 +298,7 @@ function ExampleUsageContent({
|
|||
|
||||
<TabsContent value='http' className='w-full'>
|
||||
<Tabs
|
||||
defaultValue={config.httpTarget}
|
||||
value={config.httpTarget}
|
||||
onValueChange={(value) =>
|
||||
setConfig({
|
||||
...defaultConfig,
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
import {
|
||||
type DefaultError,
|
||||
type InfiniteData,
|
||||
QueryClient,
|
||||
type QueryKey,
|
||||
useInfiniteQuery as useInfiniteQueryBase,
|
||||
useQuery as useQueryBase
|
||||
} from '@tanstack/react-query'
|
||||
import { HTTPError } from 'ky'
|
||||
|
||||
export const queryClient = new QueryClient()
|
||||
|
||||
const retryStatusCodes = new Set([408, 413, 429, 500, 502, 503, 504])
|
||||
|
||||
// Inspired by https://github.com/sindresorhus/ky#retry
|
||||
|
|
Ładowanie…
Reference in New Issue