Run biome check and add ChatError component
This commit is contained in:
parent
6a5041be43
commit
08f45451bb
13 changed files with 228 additions and 136 deletions
14
components/chat/chat-error.tsx
Normal file
14
components/chat/chat-error.tsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { AlertTriangleIcon } from "lucide-react";
|
||||
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
|
||||
|
||||
export function ChatError({ error }: { error?: Error }) {
|
||||
if (!error) return null;
|
||||
|
||||
return (
|
||||
<Alert variant="destructive">
|
||||
<AlertTriangleIcon />
|
||||
<AlertTitle>{error.name}</AlertTitle>
|
||||
<AlertDescription>{error.message}</AlertDescription>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { useState, type SubmitEvent } from "react";
|
||||
import { ArrowUpIcon } from "lucide-react";
|
||||
import { type SubmitEvent, useState } from "react";
|
||||
import { Button } from "../ui/button";
|
||||
import { Textarea } from "../ui/textarea";
|
||||
import { ArrowUpIcon, SendIcon } from "lucide-react";
|
||||
|
||||
interface ChatFormProps {
|
||||
onMessage: (message: { text: string }) => void;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { UIMessage } from "ai";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { UIMessage } from "ai";
|
||||
|
||||
interface ChatMessagesProps {
|
||||
messages: UIMessage[];
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
"use client";
|
||||
|
||||
import { ChatMessages } from "./chat-messages";
|
||||
import { ChatForm } from "./chat-form";
|
||||
import { DefaultChatTransport } from "ai";
|
||||
import { useChat } from "@ai-sdk/react";
|
||||
import { DefaultChatTransport } from "ai";
|
||||
import { ChatError } from "./chat-error";
|
||||
import { ChatForm } from "./chat-form";
|
||||
import { ChatMessages } from "./chat-messages";
|
||||
|
||||
export function Chat() {
|
||||
const { messages, sendMessage, status, error } = useChat({
|
||||
|
|
@ -13,7 +14,8 @@ export function Chat() {
|
|||
});
|
||||
|
||||
return (
|
||||
<div className="max-w-2xl flex flex-col gap-2">
|
||||
<div className="max-w-2xl flex flex-col gap-4">
|
||||
<ChatError error={error} />
|
||||
<ChatMessages messages={messages} />
|
||||
<ChatForm
|
||||
onMessage={sendMessage}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue