1
1
import { Metadata } from 'next'
2
- import { unstable_cache } from 'next/cache '
2
+ import { Suspense } from 'react '
3
3
import AgentStoreClient from './store-client'
4
+ import { getAgentsData } from './agents-data'
4
5
5
6
// Types
6
7
interface AgentData {
@@ -42,35 +43,6 @@ interface PublisherProfileResponse {
42
43
avatar_url ?: string | null
43
44
}
44
45
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
-
74
46
export const metadata : Metadata = {
75
47
title : 'Agent Store | Codebuff' ,
76
48
description : 'Browse all published AI agents. Run, compose, or fork them.' ,
@@ -81,18 +53,22 @@ export const metadata: Metadata = {
81
53
} ,
82
54
}
83
55
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
86
58
export const dynamic = 'force-static'
87
- export const fetchCache = 'force-cache'
88
59
89
60
interface StorePageProps {
90
61
searchParams : { [ key : string ] : string | string [ ] | undefined }
91
62
}
92
63
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 ( )
96
72
97
73
// For static generation, we don't pass session data
98
74
// The client will handle authentication state
@@ -107,3 +83,36 @@ export default async function StorePage({ searchParams }: StorePageProps) {
107
83
/>
108
84
)
109
85
}
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