|
| 1 | +import { SourcesList } from "@/app/components/chat/sources-list" |
| 2 | +import type { Tables } from "@/app/types/database.types" |
| 3 | +import { Message, MessageContent } from "@/components/prompt-kit/message" |
| 4 | +import { Button } from "@/components/ui/button" |
| 5 | +import { cn } from "@/lib/utils" |
| 6 | +import type { Message as MessageAISDK } from "@ai-sdk/react" |
| 7 | +import { ArrowUpRight } from "@phosphor-icons/react/dist/ssr" |
| 8 | +import Link from "next/link" |
| 9 | +import { Header } from "./header" |
| 10 | + |
| 11 | +type MessageType = Tables<"messages"> |
| 12 | + |
| 13 | +type ArticleProps = { |
| 14 | + date: string |
| 15 | + category: string |
| 16 | + title: string |
| 17 | + subtitle: string |
| 18 | + cta: { |
| 19 | + text: string |
| 20 | + href: string |
| 21 | + } |
| 22 | + messages: MessageType[] |
| 23 | +} |
| 24 | + |
| 25 | +export default function Article({ |
| 26 | + date, |
| 27 | + category, |
| 28 | + title, |
| 29 | + subtitle, |
| 30 | + cta, |
| 31 | + messages, |
| 32 | +}: ArticleProps) { |
| 33 | + return ( |
| 34 | + <> |
| 35 | + <Header /> |
| 36 | + <div className="mx-auto max-w-3xl px-4 py-12 md:py-24"> |
| 37 | + <div className="mb-8 flex items-center justify-center gap-2 text-sm font-medium"> |
| 38 | + <time |
| 39 | + dateTime={new Date(date).toISOString().split("T")[0]} |
| 40 | + className="text-foreground" |
| 41 | + > |
| 42 | + {new Date(date).toLocaleDateString("en-US", { |
| 43 | + year: "numeric", |
| 44 | + month: "long", |
| 45 | + day: "numeric", |
| 46 | + })} |
| 47 | + </time> |
| 48 | + <span className="mx-2">·</span> |
| 49 | + <span className="text-muted-foreground hover:text-foreground transition-colors"> |
| 50 | + <Link href={`/agents/${category}`}>{category}</Link> |
| 51 | + </span> |
| 52 | + </div> |
| 53 | + |
| 54 | + <h1 className="mb-4 text-center text-4xl font-medium tracking-tight md:text-5xl"> |
| 55 | + {title} |
| 56 | + </h1> |
| 57 | + |
| 58 | + <p className="text-foreground mb-8 text-center text-lg">{subtitle}</p> |
| 59 | + |
| 60 | + <div className="fixed bottom-6 left-0 z-50 flex w-full justify-center"> |
| 61 | + <Link href="/agents"> |
| 62 | + <Button |
| 63 | + variant="outline" |
| 64 | + className="text-muted-foreground group flex h-12 w-full max-w-36 items-center justify-between rounded-full py-2 pr-2 pl-4 shadow-sm transition-all hover:scale-[1.02] active:scale-[0.98]" |
| 65 | + > |
| 66 | + Ask Zola{" "} |
| 67 | + <div className="rounded-full bg-black/20 p-2 backdrop-blur-sm transition-colors group-hover:bg-black/30"> |
| 68 | + <ArrowUpRight className="h-4 w-4 text-white" /> |
| 69 | + </div> |
| 70 | + </Button> |
| 71 | + </Link> |
| 72 | + </div> |
| 73 | + <div className="mt-20 w-full"> |
| 74 | + {messages.map((message) => { |
| 75 | + const parts = message?.parts as MessageAISDK["parts"] |
| 76 | + const sources = parts |
| 77 | + ?.filter((part) => part?.type === "source") |
| 78 | + .map((part) => part?.source) |
| 79 | + |
| 80 | + return ( |
| 81 | + <div key={message.id}> |
| 82 | + <Message |
| 83 | + key={message.id} |
| 84 | + className={cn( |
| 85 | + "mb-4 flex flex-col gap-0", |
| 86 | + message.role === "assistant" && "w-full items-start", |
| 87 | + message.role === "user" && "w-full items-end" |
| 88 | + )} |
| 89 | + > |
| 90 | + <MessageContent |
| 91 | + markdown={true} |
| 92 | + className={cn( |
| 93 | + message.role === "user" && "bg-blue-600 text-white", |
| 94 | + message.role === "assistant" && |
| 95 | + "w-full min-w-full bg-transparent", |
| 96 | + "prose-h1:scroll-m-20 prose-h1:text-2xl prose-h1:font-semibold prose-h2:mt-8 prose-h2:scroll-m-20 prose-h2:text-xl prose-h2:mb-3 prose-h2:font-medium prose-h3:scroll-m-20 prose-h3:text-base prose-h3:font-medium prose-h4:scroll-m-20 prose-h5:scroll-m-20 prose-h6:scroll-m-20 prose-strong:font-medium prose-table:block prose-table:overflow-y-auto" |
| 97 | + )} |
| 98 | + > |
| 99 | + {message.content} |
| 100 | + </MessageContent> |
| 101 | + </Message> |
| 102 | + {sources && <SourcesList sources={sources} />} |
| 103 | + </div> |
| 104 | + ) |
| 105 | + })} |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + </> |
| 109 | + ) |
| 110 | +} |
0 commit comments