diff --git a/src/components/ChatWindow.tsx b/src/components/ChatWindow.tsx index 6bf6411..4ea4dd1 100644 --- a/src/components/ChatWindow.tsx +++ b/src/components/ChatWindow.tsx @@ -1,6 +1,7 @@ import cx from "classnames"; import type { ReactNode } from "react"; import React, { useEffect, useRef } from "react"; +import { FaBrain, FaListAlt, FaPlayCircle, FaStar } from "react-icons/fa"; interface ChatWindowProps { children?: ReactNode; @@ -34,6 +35,8 @@ const ChatWindow = ({ messages, children, className }: ChatWindowProps) => { ))} {children} + + ); @@ -53,16 +56,42 @@ const MacWindowHeader = () => { const ChatMessage = ({ message }: { message: Message }) => { return ( -
- - {message.type === "goal" ? "🌟 Embarking on a new goal: " : ""} - {message.type === "task" ? "📝 Adding task: " : ""} - - {message.value} +
+
+ {getMessageIcon(message)} +
+ {getMessagePrefix(message)} + {message.value}
); }; +const getMessageIcon = (message: Message) => { + switch (message.type) { + case "goal": + return ; + case "task": + return ; + case "thinking": + return ; + case "action": + return ; + } +}; + +const getMessagePrefix = (message: Message) => { + switch (message.type) { + case "goal": + return "Embarking on a new goal:"; + case "task": + return "Added task:"; + case "thinking": + return "Thinking..."; + case "action": + return "Executing action:"; + } +}; + export interface Message { type: "goal" | "thinking" | "task" | "action"; value: string; diff --git a/src/components/Input.tsx b/src/components/Input.tsx index e62b92c..10712f0 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -5,9 +5,16 @@ interface InputProps { value: string; onChange: (e: React.ChangeEvent) => void; placeholder?: string; + disabled?: boolean; } -const Input = ({ placeholder, left, value, onChange }: InputProps) => { +const Input = ({ + placeholder, + left, + value, + onChange, + disabled, +}: InputProps) => { return (
{left != null ? ( @@ -16,11 +23,15 @@ const Input = ({ placeholder, left, value, onChange }: InputProps) => {
) : null}
); diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5330fb5..77482da 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -4,7 +4,6 @@ import DefaultLayout from "../layout/default"; import React from "react"; import type { Message } from "../components/ChatWindow"; import ChatWindow, { - ChatMessage, CreateGoalMessage, CreateTaskMessage, } from "../components/ChatWindow"; @@ -13,29 +12,24 @@ import Drawer from "../components/Drawer"; import Input from "../components/Input"; import Button from "../components/Button"; import { FaRobot, FaStar } from "react-icons/fa"; +import { VscLoading } from "react-icons/vsc"; +import type AutonomousAgent from "../components/AutonomousAgent"; const Home: NextPage = () => { - const [loading, setLoading] = React.useState(false); const [name, setName] = React.useState(""); const [goalInput, setGoalInput] = React.useState(""); + const [agent, setAgent] = React.useState(null); + const [messages, setMessages] = React.useState([]); - const [goal, setGoal] = React.useState(""); const handleNewGoal = async () => { - setLoading(true); - setGoal(goalInput); setMessages([...messages, CreateGoalMessage(goalInput)]); - const res = await axios.post( - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - `${process.env.NEXT_PUBLIC_BACKEND_URL}/api/chain?prompt=test`, - { prompt: goalInput } - ); + const res = await axios.post(`/api/chain`, { prompt: goalInput }); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access const tasks: string[] = JSON.parse(res.data.tasks); setMessages((prev) => [...prev, ...tasks.map(CreateTaskMessage)]); - setLoading(false); }; return ( @@ -62,13 +56,7 @@ const Home: NextPage = () => { - - {loading ? ( - - ) : null} - + { } value={name} + disabled={agent != null} onChange={(e) => setName(e.target.value)} placeholder="AgentGPT (Note: this field doesn't do anything right now)" /> @@ -89,17 +78,25 @@ const Home: NextPage = () => { Goal: } + disabled={agent != null} value={goalInput} onChange={(e) => setGoalInput(e.target.value)} placeholder="Make the world a better place." />