Skip to content

Commit 927d76a

Browse files
committed
Add Suggestions
1 parent f51b020 commit 927d76a

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

typescript/agent/src/app/page.tsx

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Image from "next/image";
2323
import { useCallback, useEffect, useMemo, useState } from "react";
2424

2525
import type { ChatMessage } from "@/app/api/chat/route";
26+
import { Suggestion, Suggestions } from "@/components/ai-elements/suggestion";
2627

2728
const MODELS = [
2829
{
@@ -35,6 +36,12 @@ const MODELS = [
3536
},
3637
];
3738

39+
const SUGGESTIONS = [
40+
"Find top 5 places to visit in Ljubljana, Slovenia",
41+
"Extract top 10 Hacker News articles",
42+
"Get latest NBA scores",
43+
];
44+
3845
export default function Home() {
3946
const [input, setInput] = useState("");
4047
const [model, setModel] = useState<string>(MODELS[0].value);
@@ -48,20 +55,20 @@ export default function Home() {
4855
(e: React.FormEvent) => {
4956
e.preventDefault();
5057
if (input.trim()) {
51-
sendMessage(
52-
{ text: input },
53-
{
54-
body: {
55-
model: model,
56-
},
57-
},
58-
);
58+
sendMessage({ text: input }, { body: { model: model } });
5959
setInput("");
6060
}
6161
},
6262
[input, model, sendMessage],
6363
);
6464

65+
const handleSuggestionClick = useCallback(
66+
(suggestion: string) => {
67+
sendMessage({ text: suggestion }, { body: { model: model } });
68+
},
69+
[sendMessage, model],
70+
);
71+
6572
const liveUrl = useMemo(() => {
6673
let url: string | undefined = undefined;
6774

@@ -81,6 +88,7 @@ export default function Home() {
8188
}, [messages]);
8289

8390
useEffect(() => {
91+
// DEBUG
8492
console.log(messages);
8593
}, [messages]);
8694

@@ -160,9 +168,24 @@ export default function Home() {
160168
</Conversation>
161169

162170
{/* Input */}
171+
{messages.length === 0 && (
172+
<div className="flex-none w-full mb-2 border border-transparent">
173+
<Suggestions className="px-2">
174+
{SUGGESTIONS.map((suggestion) => (
175+
<Suggestion key={suggestion} onClick={handleSuggestionClick} suggestion={suggestion} />
176+
))}
177+
</Suggestions>
178+
</div>
179+
)}
180+
163181
<div className="flex-none p-2 pt-0">
164182
<PromptInput onSubmit={handleSubmit}>
165-
<PromptInputTextarea onChange={(e) => setInput(e.target.value)} value={input} />
183+
<PromptInputTextarea
184+
onChange={(e) => setInput(e.target.value)}
185+
value={input}
186+
placeholder="Automate the web..."
187+
rows={2}
188+
/>
166189
<PromptInputToolbar>
167190
<PromptInputTools>
168191
<PromptInputModelSelect

0 commit comments

Comments
 (0)