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'
|
'use client'
|
||||||
|
|
||||||
import type React from 'react'
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||||
import { QueryClientProvider } from '@tanstack/react-query'
|
|
||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||||
|
|
||||||
import { AgenticProvider } from '@/components/agentic-provider'
|
import { AgenticProvider } from '@/components/agentic-provider'
|
||||||
import { PostHogProvider } from '@/components/posthog-provider'
|
import { PostHogProvider } from '@/components/posthog-provider'
|
||||||
import { ThemeProvider } from '@/components/theme-provider'
|
import { ThemeProvider } from '@/components/theme-provider'
|
||||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
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 }) {
|
export default function Providers({ children }: { children: React.ReactNode }) {
|
||||||
|
const queryClient = getQueryClient()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PostHogProvider>
|
<PostHogProvider>
|
||||||
<AgenticProvider>
|
<AgenticProvider>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import type { Project } from '@agentic/platform-types'
|
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 { useLocalStorage } from 'react-use'
|
||||||
|
|
||||||
import { useAgentic } from '@/components/agentic-provider'
|
import { useAgentic } from '@/components/agentic-provider'
|
||||||
|
@ -43,12 +43,22 @@ export function ExampleUsage({
|
||||||
initialCodeBlock?: JSX.Element
|
initialCodeBlock?: JSX.Element
|
||||||
}) {
|
}) {
|
||||||
const ctx = useAgentic()
|
const ctx = useAgentic()
|
||||||
|
const [isMounted, setIsMounted] = useState(false)
|
||||||
|
|
||||||
const [config, setConfig] = useLocalStorage<DeveloperConfig>(
|
useEffect(() => {
|
||||||
|
setIsMounted(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const [rawConfig, setConfig] = useLocalStorage<DeveloperConfig>(
|
||||||
'developer-config',
|
'developer-config',
|
||||||
defaultConfig
|
defaultConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const config = useMemo(
|
||||||
|
() => (isMounted && rawConfig ? rawConfig : defaultConfig),
|
||||||
|
[rawConfig, isMounted]
|
||||||
|
)
|
||||||
|
|
||||||
// TODO: make this configurable
|
// TODO: make this configurable
|
||||||
// TODO: allow to take the project and/or consumer in as props
|
// 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)
|
// 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 (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
defaultValue={config.target}
|
value={config.target}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setConfig({
|
setConfig({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
|
@ -176,7 +186,7 @@ function ExampleUsageContent({
|
||||||
|
|
||||||
<TabsContent value='mcp' className='w-full'>
|
<TabsContent value='mcp' className='w-full'>
|
||||||
<Tabs
|
<Tabs
|
||||||
defaultValue={config.mcpClientTarget}
|
value={config.mcpClientTarget}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setConfig({
|
setConfig({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
|
@ -216,7 +226,7 @@ function ExampleUsageContent({
|
||||||
|
|
||||||
<TabsContent value='typescript' className='w-full'>
|
<TabsContent value='typescript' className='w-full'>
|
||||||
<Tabs
|
<Tabs
|
||||||
defaultValue={config.tsFrameworkTarget}
|
value={config.tsFrameworkTarget}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setConfig({
|
setConfig({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
|
@ -252,7 +262,7 @@ function ExampleUsageContent({
|
||||||
|
|
||||||
<TabsContent value='python' className='w-full'>
|
<TabsContent value='python' className='w-full'>
|
||||||
<Tabs
|
<Tabs
|
||||||
defaultValue={config.pyFrameworkTarget}
|
value={config.pyFrameworkTarget}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setConfig({
|
setConfig({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
|
@ -288,7 +298,7 @@ function ExampleUsageContent({
|
||||||
|
|
||||||
<TabsContent value='http' className='w-full'>
|
<TabsContent value='http' className='w-full'>
|
||||||
<Tabs
|
<Tabs
|
||||||
defaultValue={config.httpTarget}
|
value={config.httpTarget}
|
||||||
onValueChange={(value) =>
|
onValueChange={(value) =>
|
||||||
setConfig({
|
setConfig({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
import {
|
import {
|
||||||
type DefaultError,
|
type DefaultError,
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
QueryClient,
|
|
||||||
type QueryKey,
|
type QueryKey,
|
||||||
useInfiniteQuery as useInfiniteQueryBase,
|
useInfiniteQuery as useInfiniteQueryBase,
|
||||||
useQuery as useQueryBase
|
useQuery as useQueryBase
|
||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
import { HTTPError } from 'ky'
|
import { HTTPError } from 'ky'
|
||||||
|
|
||||||
export const queryClient = new QueryClient()
|
|
||||||
|
|
||||||
const retryStatusCodes = new Set([408, 413, 429, 500, 502, 503, 504])
|
const retryStatusCodes = new Set([408, 413, 429, 500, 502, 503, 504])
|
||||||
|
|
||||||
// Inspired by https://github.com/sindresorhus/ky#retry
|
// Inspired by https://github.com/sindresorhus/ky#retry
|
||||||
|
|
Ładowanie…
Reference in New Issue