-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathagents-data.ts
More file actions
71 lines (65 loc) · 1.65 KB
/
agents-data.ts
File metadata and controls
71 lines (65 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { unstable_cache } from 'next/cache'
// Types
interface AgentData {
id: string
name: string
description?: string
publisher: {
id: string
name: string
verified: boolean
avatar_url?: string | null
}
version: string
created_at: string
usage_count?: number
weekly_spent?: number
total_spent?: number
avg_cost_per_invocation?: number
unique_users?: number
last_used?: string
version_stats?: Record<string, any>
tags?: string[]
}
// Server-side data fetching function with ISR
export const getAgentsData = unstable_cache(
async (): Promise<AgentData[]> => {
const baseUrl =
process.env.NEXT_PUBLIC_CODEBUFF_APP_URL || 'http://localhost:3000'
try {
const response = await fetch(`${baseUrl}/api/agents`, {
headers: {
'User-Agent': 'Codebuff-Store-Static',
},
// Configure fetch-level caching
next: {
revalidate: 600, // 10 minutes
tags: ['agents', 'store'],
},
})
if (!response.ok) {
console.error(
'Failed to fetch agents:',
response.status,
response.statusText
)
return []
}
return await response.json()
} catch (error) {
console.error('Error fetching agents data:', error)
return []
}
},
['store-agents-data'],
{
revalidate: 600, // Cache for 10 minutes
tags: ['agents', 'store'],
}
)
// Helper function for on-demand revalidation (can be used in webhooks/admin actions)
export async function revalidateAgentsData() {
const { revalidateTag } = await import('next/cache')
revalidateTag('agents')
revalidateTag('store')
}