/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { useState, useEffect, useRef, type ReactNode } from 'react' import { cn } from '@/lib/utils' type AccentTone = 'emerald' | 'amber' | 'blue' | 'violet' interface ApiDemoConfig { id: string label: string method: 'POST' | 'GET' endpoint: string headers: string[] request: string[] response: string[] responseHighlights: string[] tokens: number latency: number accent: AccentTone } const ACCENT_CLASSES: Record< AccentTone, { activeText: string activeBorder: string badge: string } > = { emerald: { activeText: 'text-emerald-600 dark:text-emerald-400', activeBorder: 'border-emerald-500 dark:border-emerald-400', badge: 'bg-emerald-500/10 text-emerald-600 dark:bg-emerald-400/10 dark:text-emerald-400', }, amber: { activeText: 'text-amber-600 dark:text-amber-400', activeBorder: 'border-amber-500 dark:border-amber-400', badge: 'bg-amber-500/10 text-amber-600 dark:bg-amber-400/10 dark:text-amber-400', }, blue: { activeText: 'text-blue-600 dark:text-blue-400', activeBorder: 'border-blue-500 dark:border-blue-400', badge: 'bg-blue-500/10 text-blue-600 dark:bg-blue-400/10 dark:text-blue-400', }, violet: { activeText: 'text-violet-600 dark:text-violet-400', activeBorder: 'border-violet-500 dark:border-violet-400', badge: 'bg-violet-500/10 text-violet-600 dark:bg-violet-400/10 dark:text-violet-400', }, } const API_DEMOS: ApiDemoConfig[] = [ { id: 'gpt-chat', label: 'Chat', method: 'POST', endpoint: '/v1/chat/completions', headers: ['"Authorization: Bearer sk-••••"'], request: [ '"model": "your-model",', '"messages": [', ' { "role": "user", "content": "..." }', ']', ], response: [ '{', ' "choices": [{ "message": { "content": } }],', ' "usage": { "total_tokens": }', '}', ], responseHighlights: ['', ''], tokens: 27, latency: 142, accent: 'emerald', }, { id: 'responses', label: 'Responses', method: 'POST', endpoint: '/v1/responses', headers: ['"Authorization: Bearer sk-••••"'], request: ['"model": "your-model",', '"input": "..."'], response: [ '{', ' "output": [{ "type": "output_text", "text": }],', ' "usage": { "total_tokens": }', '}', ], responseHighlights: ['', ''], tokens: 31, latency: 168, accent: 'amber', }, { id: 'claude', label: 'Claude', method: 'POST', endpoint: '/v1/messages', headers: ['"x-api-key: sk-••••"', '"anthropic-version: 2023-06-01"'], request: [ '"model": "your-model",', '"max_tokens": 1024,', '"messages": [', ' { "role": "user", "content": "..." }', ']', ], response: [ '{', ' "content": [{ "type": "text", "text": }],', ' "usage": { "input_tokens": , "output_tokens": }', '}', ], responseHighlights: ['', '', ''], tokens: 29, latency: 156, accent: 'blue', }, { id: 'gemini', label: 'Gemini', method: 'POST', endpoint: '/v1beta/models/{model}:generateContent', headers: ['"x-goog-api-key: sk-••••"'], request: [ '"contents": [', ' { "role": "user",', ' "parts": [{ "text": "..." }] }', ']', ], response: [ '{', ' "candidates": [{ "content": { "parts": [{ "text": }] } }],', ' "usageMetadata": { "totalTokenCount": }', '}', ], responseHighlights: ['', ''], tokens: 25, latency: 93, accent: 'violet', }, ] const CYCLE_INTERVAL = 4500 const TRANSITION_MS = 220 export function HeroTerminalDemo() { const [activeIndex, setActiveIndex] = useState(0) const [transitioning, setTransitioning] = useState(false) const intervalRef = useRef>(undefined) const timeoutRef = useRef>(undefined) useEffect(() => { const mq = window.matchMedia('(prefers-reduced-motion: reduce)') if (mq.matches) return intervalRef.current = setInterval(() => { setTransitioning(true) timeoutRef.current = setTimeout(() => { setActiveIndex((prev) => (prev + 1) % API_DEMOS.length) setTransitioning(false) }, TRANSITION_MS) }, CYCLE_INTERVAL) return () => { if (intervalRef.current) clearInterval(intervalRef.current) if (timeoutRef.current) clearTimeout(timeoutRef.current) } }, []) const handleSelect = (index: number) => { if (index === activeIndex) return if (intervalRef.current) clearInterval(intervalRef.current) if (timeoutRef.current) clearTimeout(timeoutRef.current) setTransitioning(true) timeoutRef.current = setTimeout(() => { setActiveIndex(index) setTransitioning(false) }, TRANSITION_MS) } const demo = API_DEMOS[activeIndex] const accent = ACCENT_CLASSES[demo.accent] return (
{/* Tab strip */}
{API_DEMOS.map((item, index) => { const tone = ACCENT_CLASSES[item.accent] const isActive = index === activeIndex return ( ) })}
200 ok
{/* Endpoint row */}
{demo.method} {demo.endpoint}
{/* Body — fixed rows so neither block shifts when switching demos */}
{/* Request */} {/* Response */}
{/* Footer metrics */}
{demo.latency} ms {demo.tokens} tokens cost ${(demo.tokens * 0.00003).toFixed(5)}
stream · sse
) } function RequestBlock(props: { demo: ApiDemoConfig; transitioning: boolean }) { const { demo, transitioning } = props return (
Request
curl -X POST{' '} "{demo.endpoint}"{' '} {'\\'} {demo.headers.map((header) => ( -H {header}{' '} {'\\'} ))} -d '{'{'} {demo.request.map((line, i) => ( {renderJsonLine(line)} ))} {'}'}'
) } function ResponseBlock(props: { demo: ApiDemoConfig; transitioning: boolean }) { const { demo, transitioning } = props return (
Response
{demo.response.map((line, i) => ( {renderResponseLine(line, demo)} ))}
) } function SectionLabel(props: { children: ReactNode }) { return ( {props.children} ) } const STRING_RE = /"[^"]*"/g const PLACEHOLDER_RE = /<[a-z]+>/gi function renderJsonLine(line: string): ReactNode { if (!line.trim()) return return tokenize(line) } function renderResponseLine(line: string, demo: ApiDemoConfig): ReactNode { if (!line.trim()) return const segments: ReactNode[] = [] let cursor = 0 const matches = [...line.matchAll(PLACEHOLDER_RE)] if (matches.length === 0) return tokenize(line) matches.forEach((match, idx) => { const start = match.index ?? 0 if (start > cursor) { segments.push( {tokenize(line.slice(cursor, start))} ) } const placeholder = match[0] if (placeholder === '') { segments.push( {`"${truncateResponse(demo)}"`} ) } else if (placeholder === '') { segments.push({demo.tokens}) } else if (placeholder === '') { segments.push( {Math.floor(demo.tokens * 0.4)} ) } else if (placeholder === '') { segments.push( {Math.ceil(demo.tokens * 0.6)} ) } else { segments.push({placeholder}) } cursor = start + placeholder.length }) if (cursor < line.length) { segments.push({tokenize(line.slice(cursor))}) } return segments } function truncateResponse(demo: ApiDemoConfig): string { const map: Record = { 'gpt-chat': 'Chat request routed.', responses: 'Response workflow ready.', claude: 'Claude message routed.', gemini: 'Gemini request served.', } return map[demo.id] ?? '...' } function tokenize(input: string): ReactNode { // Split string into "..." string runs and the rest, then color keys/punct. const segments: ReactNode[] = [] let cursor = 0 const matches = [...input.matchAll(STRING_RE)] matches.forEach((match, idx) => { const start = match.index ?? 0 if (start > cursor) { segments.push( {input.slice(cursor, start)} ) } const text = match[0] const after = input.slice(start + text.length).trimStart() const isKey = after.startsWith(':') if (isKey) { segments.push({text}) } else { segments.push({text}) } cursor = start + text.length }) if (cursor < input.length) { segments.push({input.slice(cursor)}) } return segments } function CodeLine(props: { children: ReactNode; indent?: number }) { return (
{props.indent ? ( ) : null} {props.children}
) } function Command(props: { children: ReactNode }) { return ( {props.children} ) } function Flag(props: { children: ReactNode }) { return ( {props.children} ) } function Key(props: { children: ReactNode }) { return ( {props.children} ) } function StringText(props: { children: ReactNode }) { return ( {props.children} ) } function NumberText(props: { children: ReactNode }) { return ( {props.children} ) } function Muted(props: { children: ReactNode }) { return {props.children} } function Accent(props: { children: ReactNode; accent: AccentTone }) { const tone = ACCENT_CLASSES[props.accent] return ( {props.children} ) }