Skip to content

Commit fd56f30

Browse files
committed
Improve Docs, Cleanup Code
1 parent f6cb76e commit fd56f30

File tree

6 files changed

+66
-54
lines changed

6 files changed

+66
-54
lines changed

typescript/agent/README.md

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,69 @@
1-
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
1+
## Browser Use Agent
22

3-
## Getting Started
3+
> Create an agent that can Browse the Web using Browser Use.
44
5-
First, run the development server:
5+
A Next.js application that provides an AI-powered web browsing assistant using the Browser Use SDK. This agent can execute tasks in a web browser, monitor their progress, and provide real-time updates through a streaming interface.
6+
7+
## Features
8+
9+
- **Web Task Execution**: Run automated tasks in web browsers
10+
- **Real-time Monitoring**: Stream task progress and status updates
11+
- **Session Management**: Continue tasks across browser sessions
12+
- **AI Integration**: Powered by AI models for intelligent task handling
13+
- **Streaming Responses**: Real-time updates using Vercel AI SDK
14+
15+
## Core Components
16+
17+
### API Route (`/api/chat`)
18+
The main API endpoint that handles chat interactions and web task execution:
19+
20+
- **`runTask`**: Creates and executes new browser tasks
21+
- **`continueTask`**: Continues existing tasks using session IDs
22+
- **Task Status Tracking**: Monitors running, paused, stopped, and finished states
23+
- **Live URL Access**: Provides real-time browser session URLs
24+
25+
## Setup
26+
27+
### Prerequisites
28+
- Node.js 18+
29+
- pnpm package manager
30+
31+
### Environment Variables
32+
Create a `.env.local` file with the following variables:
633

734
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
35+
# Browser Use API Key (required)
36+
BROWSER_USE_API_KEY=your_browser_use_api_key_here
1537
```
1638

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18-
19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
39+
### Installation & Development
2040

21-
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
41+
```bash
42+
# Install dependencies
43+
pnpm i
2244

23-
## Learn More
45+
# Start Dev Server
46+
pnpm dev
47+
```
2448

25-
To learn more about Next.js, take a look at the following resources:
49+
Open [http://localhost:3000](http://localhost:3000) to view the application.
2650

27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
51+
## Usage
2952

30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
53+
1. **Start a Task**: Use the chat interface to describe what you want to accomplish in the browser
54+
2. **Monitor Progress**: Watch real-time updates as the task executes
55+
3. **Access Live Session**: Click on the live URL to see the browser in action
56+
4. **Continue Tasks**: Use session IDs to resume interrupted tasks
3157

32-
## Deploy on Vercel
58+
## Architecture
3359

34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
60+
The application uses:
61+
- **Next.js 14** with App Router
62+
- **Vercel AI SDK** for streaming responses
63+
- **Browser Use SDK** for web automation
64+
- **TypeScript** for type safety
65+
- **Tailwind CSS** for styling
3566

36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
67+
<p align="center">
68+
<img src="media/app.png" alt="App Screenshot" height="400" />
69+
</p>

typescript/agent/media/app.png

1.03 MB
Loading

typescript/agent/public/browseruse-black.svg

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Loading

typescript/agent/src/app/api/chat/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ export type ChatMessage = UIMessage<never, UIDataTypes, ChatTools>;
151151
// ROUTE
152152

153153
export async function POST(req: Request) {
154-
const { messages, model, webSearch }: { messages: UIMessage[]; model: string; webSearch: boolean } = await req.json();
154+
const { messages, model }: { messages: UIMessage[]; model: string } = await req.json();
155155

156156
const result = streamText({
157-
model: webSearch ? "perplexity/sonar" : model,
157+
model: model,
158158
messages: convertToModelMessages(messages),
159159
system:
160160
"You are a helpful assistant that can answer questions and help with tasks. You can use the tools provided to you to help you answer questions and help with tasks.",

typescript/agent/src/app/page.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Conversation, ConversationContent, ConversationScrollButton } from "@/c
44
import { Message, MessageContent } from "@/components/ai-elements/message";
55
import {
66
PromptInput,
7-
PromptInputButton,
87
PromptInputModelSelect,
98
PromptInputModelSelectContent,
109
PromptInputModelSelectItem,
@@ -19,7 +18,7 @@ import { Reasoning, ReasoningContent, ReasoningTrigger } from "@/components/ai-e
1918
import { Response } from "@/components/ai-elements/response";
2019
import { useChat } from "@ai-sdk/react";
2120
import { DefaultChatTransport } from "ai";
22-
import { GlobeIcon, Loader } from "lucide-react";
21+
import { Loader } from "lucide-react";
2322
import Image from "next/image";
2423
import { useCallback, useEffect, useMemo, useState } from "react";
2524

@@ -39,7 +38,6 @@ const MODELS = [
3938
export default function Home() {
4039
const [input, setInput] = useState("");
4140
const [model, setModel] = useState<string>(MODELS[0].value);
42-
const [webSearch, setWebSearch] = useState(false);
4341
const { messages, sendMessage, status } = useChat<ChatMessage>({
4442
transport: new DefaultChatTransport({
4543
api: "/api/chat",
@@ -55,14 +53,13 @@ export default function Home() {
5553
{
5654
body: {
5755
model: model,
58-
webSearch: webSearch,
5956
},
6057
},
6158
);
6259
setInput("");
6360
}
6461
},
65-
[input, model, webSearch, sendMessage],
62+
[input, model, sendMessage],
6663
);
6764

6865
const liveUrl = useMemo(() => {
@@ -96,7 +93,7 @@ export default function Home() {
9693
{liveUrl != null ? (
9794
<iframe src={liveUrl} className="w-full h-full border border-dashed border-gray-400" />
9895
) : (
99-
<Image src="/browseruse-black.svg" alt="logo" width={40} height={40} className="size-16 object-contain" />
96+
<Image src="/browseruse.svg" alt="logo" width={40} height={40} className="size-16 object-contain" />
10097
)}
10198
</div>
10299
</div>
@@ -124,7 +121,7 @@ export default function Home() {
124121
return (
125122
<Reasoning
126123
key={`${message.id}-${i}`}
127-
className="w-full"
124+
className="w-full mb-0"
128125
isStreaming={status === "streaming"}
129126
>
130127
<ReasoningTrigger />
@@ -164,10 +161,6 @@ export default function Home() {
164161
<PromptInputTextarea onChange={(e) => setInput(e.target.value)} value={input} />
165162
<PromptInputToolbar>
166163
<PromptInputTools>
167-
<PromptInputButton variant={webSearch ? "default" : "ghost"} onClick={() => setWebSearch(!webSearch)}>
168-
<GlobeIcon size={16} />
169-
<span>Search</span>
170-
</PromptInputButton>
171164
<PromptInputModelSelect
172165
onValueChange={(value) => {
173166
setModel(value);

0 commit comments

Comments
 (0)