"use client"; import { useEffect, useRef } from "react"; import { useParams } from "next/navigation"; import { useChat } from "@ai-sdk/react"; import { AlertTriangle, Bot, Loader2, Send, Sparkles, User } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; export default function AIPage() { const params = useParams(); const workspaceSlug = typeof params?.workspaceSlug === "string" ? params.workspaceSlug : ""; const scrollRef = useRef(null); const inputRef = useRef(null); const { messages, input, handleInputChange, handleSubmit, status, error, setInput, } = useChat({ api: "/api/chat", body: { workspace: workspaceSlug }, }); const isBusy = status === "submitted" || status === "streaming"; useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, status]); return (

AI Assistant

Ask me anything about your workspace

{messages.length === 0 ? (

How can I help you today?

Ask me to break down a task, draft an outline, or summarize what you have open.

{[ "Break this project into subtasks", "Summarize my open tasks", "Draft a sprint plan for this week", ].map((suggestion) => ( ))}
) : (
{messages.map((msg) => (
{msg.role === "user" ? ( ) : ( )}
{msg.content}
))} {status === "submitted" && (
)}
)} {error ? : null}