Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ yarn-error.log*
pnpm-debug.log*
/dist
/.turbo
.vscode/
.idea/
*.swp
*.swo
*~
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"postman.settings.dotenv-detection-notification-visibility": false
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: VSCode settings file committed despite being in gitignore

The .vscode/settings.json file is being committed to the repository in the same PR that adds .vscode/ to the .gitignore. This appears to be accidentally committed IDE configuration that contains personal Postman settings and contradicts the intent of adding the directory to .gitignore.

Additional Locations (1)

Fix in Cursor Fix in Web

42 changes: 42 additions & 0 deletions examples/computer-use-nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

36 changes: 36 additions & 0 deletions examples/computer-use-nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

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.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

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.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
67 changes: 67 additions & 0 deletions examples/computer-use-nextjs/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { anthropic } from "@ai-sdk/anthropic";
import { streamText, UIMessage } from "ai";
import { killBrowser } from "@/lib/kernel/utils";
import { createComputerTool } from "@/lib/kernel/tool";
import { prunedMessages } from "@/lib/utils";

// Allow streaming responses up to 5 minutes
export const maxDuration = 300;

export async function POST(req: Request) {
const {
messages,
sandboxId,
}: {
messages: UIMessage[];
sandboxId: string;
} = await req.json();

try {
// Log request to monitor token usage
console.log(
`[${new Date().toISOString()}] Chat request - Messages: ${
messages.length
}, SandboxId: ${sandboxId}`
);

const result = streamText({
model: anthropic("claude-3-7-sonnet-20250219"),
system:
"You are an autonomous agent with access to a computer. " +
"Use the computer tool to help the user with their requests. " +
"Do not provide conversational responses - just use the tools to complete the task. " +
"Work silently and efficiently. Only use tools to perform actions. " +
"If the browser opens with a setup wizard, YOU MUST IGNORE IT and move straight to the next step (e.g. input the url in the search bar).",
messages: prunedMessages(messages),
tools: {
computer: createComputerTool(sandboxId),
},
providerOptions: {
anthropic: { cacheControl: { type: "ephemeral" } },
},
});

// Create response stream
const response = result.toDataStreamResponse({
// @ts-expect-error - AI SDK type mismatch
getErrorMessage(error) {
console.error("Stream error:", error);

return error;
},
});

return response;
} catch (error) {
console.error("Chat API error:", error);

// Force cleanup on error
console.log(`killing browser with id: ${sandboxId}`);
await killBrowser(sandboxId);

return new Response(JSON.stringify({ error: "Internal Server Error" }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
}
}
28 changes: 28 additions & 0 deletions examples/computer-use-nextjs/app/api/kill-desktop/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { killBrowser } from "@/lib/kernel/utils";
import { NextRequest } from "next/server";

export async function POST(req: NextRequest) {
try {
const sandboxId = req.nextUrl.searchParams.get("sandboxId");

if (!sandboxId) {
return new Response(
JSON.stringify({ error: "sandboxId is required" }),
{ status: 400 }
);
}

await killBrowser(sandboxId);

return new Response(
JSON.stringify({ success: true }),
{ status: 200 }
);
} catch (error) {
console.error("Failed to kill browser:", error);
return new Response(
JSON.stringify({ error: "Failed to kill browser" }),
{ status: 500 }
);
}
}
Binary file added examples/computer-use-nextjs/app/favicon.ico
Binary file not shown.
26 changes: 26 additions & 0 deletions examples/computer-use-nextjs/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import "tailwindcss";

:root {
--background: #ffffff;
--foreground: #171717;
}

@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}
34 changes: 34 additions & 0 deletions examples/computer-use-nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
Loading