11import { Metadata } from 'next'
2- import { unstable_cache } from 'next/cache '
2+ import { Suspense } from 'react '
33import AgentStoreClient from './store-client'
4+ import { getAgentsData } from './agents-data'
45
56// Types
67interface AgentData {
@@ -42,35 +43,6 @@ interface PublisherProfileResponse {
4243 avatar_url ?: string | null
4344}
4445
45- // Cache the agents data with 60 second revalidation
46- const getCachedAgentsData = unstable_cache (
47- async ( ) : Promise < AgentData [ ] > => {
48- const baseUrl =
49- process . env . NEXT_PUBLIC_CODEBUFF_APP_URL || 'http://localhost:3000'
50- const response = await fetch ( `${ baseUrl } /api/agents` , {
51- headers : {
52- 'User-Agent' : 'Codebuff-Store-Static' ,
53- } ,
54- } )
55-
56- if ( ! response . ok ) {
57- console . error (
58- 'Failed to fetch agents:' ,
59- response . status ,
60- response . statusText
61- )
62- return [ ]
63- }
64-
65- return await response . json ( )
66- } ,
67- [ 'store-agents-data' ] ,
68- {
69- revalidate : 60 , // Revalidate every 60 seconds
70- tags : [ 'agents' , 'store' ] ,
71- }
72- )
73-
7446export const metadata : Metadata = {
7547 title : 'Agent Store | Codebuff' ,
7648 description : 'Browse all published AI agents. Run, compose, or fork them.' ,
@@ -81,18 +53,22 @@ export const metadata: Metadata = {
8153 } ,
8254}
8355
84- // Enable static site generation with ISR
85- export const revalidate = 60 * 10 // Revalidate every 10 minutes
56+ // ISR Configuration - revalidate every 10 minutes
57+ export const revalidate = 600
8658export const dynamic = 'force-static'
87- export const fetchCache = 'force-cache'
8859
8960interface StorePageProps {
9061 searchParams : { [ key : string ] : string | string [ ] | undefined }
9162}
9263
93- export default async function StorePage ( { searchParams } : StorePageProps ) {
94- // Fetch agents data at build time
95- const agentsData = await getCachedAgentsData ( )
64+ // Server Component for fetching and rendering agents data
65+ async function AgentsDataProvider ( {
66+ searchParams,
67+ } : {
68+ searchParams : StorePageProps [ 'searchParams' ]
69+ } ) {
70+ // Fetch agents data with ISR
71+ const agentsData = await getAgentsData ( )
9672
9773 // For static generation, we don't pass session data
9874 // The client will handle authentication state
@@ -107,3 +83,36 @@ export default async function StorePage({ searchParams }: StorePageProps) {
10783 />
10884 )
10985}
86+
87+ // Loading component for better UX
88+ function AgentsLoading ( ) {
89+ return (
90+ < div className = "container mx-auto py-8 px-4" >
91+ < div className = "max-w-7xl mx-auto" >
92+ < div className = "mb-12" >
93+ < h1 className = "text-4xl font-bold text-white mb-2" > Agent Store</ h1 >
94+ < p className = "text-xl text-muted-foreground" >
95+ Browse all published AI agents. Run, compose, or fork them.
96+ </ p >
97+ </ div >
98+
99+ < div className = "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6" >
100+ { Array . from ( { length : 6 } ) . map ( ( _ , i ) => (
101+ < div
102+ key = { i }
103+ className = "h-[220px] bg-card/50 border rounded-lg animate-pulse"
104+ />
105+ ) ) }
106+ </ div >
107+ </ div >
108+ </ div >
109+ )
110+ }
111+
112+ export default async function StorePage ( { searchParams } : StorePageProps ) {
113+ return (
114+ < Suspense fallback = { < AgentsLoading /> } >
115+ < AgentsDataProvider searchParams = { searchParams } />
116+ </ Suspense >
117+ )
118+ }
0 commit comments