Skip to content

chore: add agent chat example #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
161 changes: 161 additions & 0 deletions examples/agent-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Agent Sync Chat

A modern real-time chat application with AI integration, built using ActorCore, TypeScript, and Next.js.

## Features

- Real-time messaging using ActorCore's actor model
- Claude AI integration for intelligent chat assistance
- Multiple chat rooms with isolated actor states
- Real-time user presence and typing indicators
- Modern, responsive UI with Tailwind CSS
- Persistent message storage using ActorCore's state management
- Fast and efficient message delivery through WebSocket
- Mobile-friendly design with animations

## Architecture

The application uses ActorCore's actor model for real-time communication:

- Each chat room is an isolated actor instance
- Messages are broadcasted using ActorCore's event system
- User state is managed through actor connections
- Claude AI integration runs in a separate service
- Frontend uses React with Next.js for optimal performance

## Technologies

- [ActorCore](https://github.com/rivet-gg/actorcore) - Actor model framework for real-time applications
- [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript
- [Next.js](https://nextjs.org/) - React framework for production
- [Anthropic Claude API](https://www.anthropic.com/claude) - AI language model
- [Tailwind CSS](https://tailwindcss.com/) - Utility-first CSS framework

## Prerequisites

- Node.js 18+ and yarn
- Anthropic API key for Claude integration

## Installation

1. Clone the repository:
```bash
git clone https://github.com/yourusername/agentsyncchat.git
cd agentsyncchat
```

2. Install dependencies:
```bash
# Install root dependencies
yarn install

# Install frontend dependencies
cd frontend && yarn install
```

3. Configure environment variables:

Create a `.env` file in the root directory:
```env
PORT=3000
ANTHROPIC_API_KEY=your_api_key_here
```

Create a `.env.local` file in the `frontend` directory:
```env
NEXT_PUBLIC_API_URL=http://localhost:3000
```

4. Start the development servers:

```bash
# Start the backend server
yarn dev

# In a new terminal, start the frontend
cd frontend && yarn dev
```

The application will be available at:
- Frontend: http://localhost:3001
- Backend: http://localhost:3000

## Project Structure

```
├── src/ # Backend source code
│ ├── index.ts # Main entry point and server setup
│ ├── chat-room.ts # Chat room actor implementation
│ ├── claude-service.ts # Claude AI integration service
│ ├── client.ts # ActorCore client configuration
│ └── web-server-actor.ts# Web server actor implementation
├── frontend/ # Frontend application
│ ├── app/ # Next.js app directory
│ │ └── page.tsx # Main chat interface
│ ├── public/ # Static assets
│ └── package.json # Frontend dependencies
└── package.json # Backend dependencies
```

## Actor Implementation

The chat system uses ActorCore's actor model:

- Each chat room is an isolated actor instance
- Messages are handled through RPC calls
- State is automatically persisted between calls
- Events are used for real-time updates
- Typing indicators use ActorCore's event system

## Development

- Use `yarn check-types` to verify TypeScript types
- The frontend auto-reloads when you make changes
- The backend uses `tsx watch` for automatic reloading
- Follow ActorCore's development guide for best practices

## Troubleshooting

Common issues and solutions:

1. Port conflicts:
```bash
# Check for processes using ports
lsof -i :3000,3001

# Kill the processes if needed
kill -9 <PID>
```

2. TypeScript errors:
```bash
# Run type checking
yarn check-types

# Clean and rebuild
yarn clean && yarn build
```

## Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Follow ActorCore development guidelines
4. Run tests and type checks
5. Commit your changes (`git commit -m 'Add feature'`)
6. Push to the branch (`git push origin feature/amazing-feature`)
7. Open a Pull Request

## License

MIT

## Security

- Never commit API keys or sensitive data
- Use environment variables for configuration
- Follow ActorCore's security guidelines
- Validate all user inputs
- Use appropriate CORS settings
6 changes: 6 additions & 0 deletions examples/agent-chat/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"next/core-web-vitals",
"next/typescript"
]
}
41 changes: 41 additions & 0 deletions examples/agent-chat/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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/agent-chat/frontend/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.
Binary file added examples/agent-chat/frontend/app/favicon.ico
Binary file not shown.
24 changes: 24 additions & 0 deletions examples/agent-chat/frontend/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import "tailwindcss";

@theme {
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}

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

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

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}
34 changes: 34 additions & 0 deletions examples/agent-chat/frontend/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
Loading