import { HealthCard } from '@/components/health-card'; import { ManifestViewer } from '@/components/manifest-viewer'; import { SnippetCard } from '@/components/snippet-card'; import { EntrypointCard, type EntrypointCardData, } from '@/components/entrypoint-card'; import { WalletSummary } from '@/components/wallet-summary'; import type { DashboardData } from '@/lib/dashboard-types'; import type { AgentPayments } from '@/lib/api'; import type { AgentHealth } from '@/lib/api'; import { getNetworkInfo } from '@/lib/network'; const DEFAULT_PAYLOAD = JSON.stringify({ input: {} }, null, 2); const MANIFEST_PATH = '/.well-known/agent-card.json'; const indentPayload = (payload: string) => payload .split('\n') .map((line, index) => (index === 0 ? line : ` ${line}`)) .join('\n'); const derivePriceLabel = ( entrypoint: DashboardData['entrypoints'][number], payments?: AgentPayments | null ) => { const price = entrypoint.price; const defaultPrice = payments?.defaultPrice ?? undefined; const normalize = (value?: string | null) => typeof value === 'string' && value.length > 0 ? value : undefined; const invokePrice = typeof price === 'string' ? price : (normalize(price?.invoke) ?? defaultPrice); const streamPrice = entrypoint.streaming ? typeof price === 'string' ? price : (normalize(price?.stream) ?? defaultPrice) : undefined; if (!invokePrice && !streamPrice) return 'Free'; if (invokePrice && streamPrice && invokePrice !== streamPrice) { return `Invoke: ${invokePrice} ยท Stream: ${streamPrice}`; } if (invokePrice && !streamPrice) { return `Invoke: ${invokePrice}`; } if (streamPrice && !invokePrice) { return `Stream: ${streamPrice}`; } return `Invoke ยท Stream: ${invokePrice ?? streamPrice}`; }; const buildEntrypointCards = ( origin: string, entrypoints: DashboardData['entrypoints'], payments?: AgentPayments | null ): EntrypointCardData[] => { const payloadIndented = indentPayload(DEFAULT_PAYLOAD); return entrypoints.map(entrypoint => { const invokePath = `/api/agent/entrypoints/${entrypoint.key}/invoke`; const streamPath = entrypoint.streaming ? `/api/agent/entrypoints/${entrypoint.key}/stream` : undefined; const streaming = Boolean(entrypoint.streaming); const priceLabel = derivePriceLabel(entrypoint, payments); const invokeCurl = [ 'curl -s -X POST \\', ` '${origin}${invokePath}' \\`, " -H 'Content-Type: application/json' \\", " -d '", payloadIndented, " '", ].join('\n'); const streamCurl = streamPath ? [ 'curl -sN -X POST \\', ` '${origin}${streamPath}' \\`, " -H 'Content-Type: application/json' \\", " -H 'Accept: text/event-stream' \\", " -d '", payloadIndented, " '", ].join('\n') : undefined; return { key: String(entrypoint.key), description: entrypoint.description ?? 'No description provided.', streaming, priceLabel, networkId: entrypoint.network ?? payments?.network ?? null, invokePath, streamPath, invokeCurl, streamCurl, requiresPayment: priceLabel !== 'Free', inputSchema: entrypoint.inputSchema, outputSchema: entrypoint.outputSchema, defaultPayload: DEFAULT_PAYLOAD, }; }); }; const appKitSnippet = [ 'import { useWalletClient } from "wagmi";', 'import { wrapFetchWithPayment } from "x402-fetch";', '', 'const { data: walletClient } = useWalletClient();', '', 'if (walletClient) {', ' const fetchWithPayment = wrapFetchWithPayment(fetch, walletClient);', ' // await fetchWithPayment(...)', '}', '', '// Ensure WALLET_CONNECT_PROJECT_ID is configured to use WalletConnect.', ].join('\n'); export default function Dashboard({ initialData, origin, manifestText, initialHealth, }: { initialData: DashboardData; origin: string; manifestText: string; initialHealth: AgentHealth | null; }) { const cards = buildEntrypointCards( origin, initialData.entrypoints, initialData.payments ?? undefined ); const entrypointCount = cards.length; const entrypointLabel = entrypointCount === 1 ? 'Entrypoint' : 'Entrypoints'; const networkInfo = getNetworkInfo( initialData.payments?.network ?? undefined ); return (
v{initialData.meta?.version ?? '0.0.0'}
{initialData.meta?.description ?? 'Monitor agent health, review entrypoints, and interact with invoke and streaming flows.'}
Configure payloads and test your agent endpoints
Integration snippets for your applications