"use client"; import { useLayoutEffect, useRef } from "react"; import { useChat } from "@ai-sdk/react"; import { AlertTriangle, Bot, Loader2, User } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { WorkspaceComposer } from "./workspace-composer"; import { createChatScrollMemory } from "./workspace-interaction"; export function ChatMode({ workspaceSlug, active, }: { workspaceSlug: string; active: boolean; }) { const scrollRef = useRef(null); const inputRef = useRef(null); const scrollMemory = useRef(createChatScrollMemory()); const { messages, input, handleSubmit, status, error, setInput, stop } = useChat({ api: "/api/chat", body: { workspace: workspaceSlug }, }); const isBusy = status === "submitted" || status === "streaming"; useLayoutEffect(() => { const container = scrollRef.current; if (container) scrollMemory.current.update(container, active); }, [messages, status, active]); return (
{ scrollMemory.current.record(event.currentTarget, active); }} className="min-h-0 flex-1 overflow-y-auto" > {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.role === "user" ? "You" : "Assistant"}:{" "}

{msg.content}

))} {isBusy && messages[messages.length - 1]?.role === "user" && (
)}
)} {error && (
)}
); }