Skip to content

Commit 5713376

Browse files
committed
init
0 parents  commit 5713376

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5188
-0
lines changed

.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_BASE_PATH=/CUA-Trace-Viewer

.github/workflows/deploy.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
# 设置GITHUB_TOKEN的权限
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
# 允许一个并发部署
15+
concurrency:
16+
group: "pages"
17+
cancel-in-progress: false
18+
19+
jobs:
20+
# 单个部署工作流
21+
build-and-deploy:
22+
environment:
23+
name: github-pages
24+
url: ${{ steps.deployment.outputs.page_url }}
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Node
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: "18"
34+
cache: 'npm'
35+
36+
- name: Setup Pages
37+
uses: actions/configure-pages@v4
38+
39+
- name: Install dependencies
40+
run: npm ci
41+
42+
- name: Build
43+
run: npm run build
44+
45+
- name: Upload artifact
46+
uses: actions/upload-pages-artifact@v3
47+
with:
48+
path: ./out
49+
50+
- name: Deploy to GitHub Pages
51+
id: deployment
52+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# dependencies
2+
/node_modules
3+
/.pnp
4+
.pnp.js
5+
6+
# testing
7+
/coverage
8+
9+
# next.js
10+
/.next/
11+
/out/
12+
13+
# production
14+
/build
15+
16+
# misc
17+
.DS_Store
18+
*.pem
19+
20+
# debug
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# local env files
26+
.env*.local
27+
.env
28+
29+
# vercel
30+
.vercel
31+
32+
# typescript
33+
*.tsbuildinfo
34+
next-env.d.ts
35+
36+
# IDE specific files
37+
.idea
38+
.vscode
39+
*.swp
40+
*.swo
41+
42+
# Media files (since they might be large and project-specific)
43+
# /public/screenshots/*
44+
# /public/videos/*
45+
# !public/screenshots/.gitkeep
46+
# !public/videos/.gitkeep

README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Computer Use Agent Trace Viewer
2+
3+
A web-based visualization tool for Computer Use Agent traces, displaying the agent's thought process, actions, screenshots, and corresponding videos.
4+
5+
![Computer Use Agent Trace Viewer](figure/page.png)
6+
7+
## 📋 Features
8+
9+
- Interactive timeline of agent activities with screenshots, thoughts, and actions
10+
- Synchronized video playback
11+
- Adjustable split view (drag to resize)
12+
- Time-synchronized scrolling
13+
- Multiple trace instances on a single page
14+
- External JSON data support
15+
16+
## 🛠️ Prerequisites
17+
18+
- [Node.js](https://nodejs.org/) (v16.x or newer)
19+
- npm (comes with Node.js) or [Yarn](https://yarnpkg.com/)
20+
21+
## 🚀 Getting Started
22+
23+
### 1. Clone the Repository
24+
25+
```bash
26+
git clone https://github.com/Computer-use-agents/CUA-Trace-Viewer.git
27+
cd CUA-Trace-Viewer
28+
```
29+
30+
### 2. Install Dependencies
31+
32+
```bash
33+
npm install
34+
```
35+
36+
### 3. Start the Development Server
37+
38+
```bash
39+
npm run dev
40+
```
41+
42+
Visit [http://localhost:3000](http://localhost:3000) to see your trace viewer in action!
43+
44+
## 📁 Project Structure
45+
46+
The project uses the following structure for its data:
47+
48+
## Screenshots and Videos
49+
50+
Create the following directories:
51+
52+
```bash
53+
mkdir -p public public/screenshots public/videos
54+
```
55+
56+
Place your screenshots and videos in the following directories:
57+
58+
- `public/screenshots/`: Contains the screenshots
59+
- `public/videos/`: Contains the videos
60+
61+
### JSON Data Files
62+
63+
The trace data is stored in JSON files under `src/data/` directory:
64+
- `trace1.json`: Contains the first set of agent activities
65+
- `trace2.json`: Contains the second set of agent activities
66+
67+
Each item in the trace data follows this format:
68+
69+
```json
70+
{
71+
"timestamp": "2024-03-20T10:00:00Z",
72+
"screenshot": "/screenshots/image.png",
73+
"thought": "Agent is analyzing the current screen content...",
74+
"action": "click the button",
75+
"video": "/videos/test.mp4",
76+
"timeRange": {
77+
"start": 0,
78+
"end": 5
79+
}
80+
}
81+
```
82+
83+
## ✨ Customization
84+
85+
### Adding More Trace Viewers
86+
87+
To add more trace viewers, create a new JSON file in `src/data/` directory and import it in `app/page.tsx`:
88+
89+
```typescript
90+
import trace3Data from '../src/data/trace3.json';
91+
92+
// Then use it in a TraceViewer component
93+
<TraceViewer data={trace3Data} id="viewer3" />
94+
```
95+
96+
### Modifying the Layout
97+
98+
- Adjust the default split ratio in the `TraceViewer` component by changing the `splitPosition` initial state
99+
- Customize the styling using Tailwind classes in the component files
100+
101+
### Loading Data from API
102+
103+
To load data from an API instead of JSON files:
104+
105+
```typescript
106+
'use client';
107+
import { useState, useEffect } from 'react';
108+
import TraceViewer from '../src/components/TraceViewer';
109+
110+
export default function Home() {
111+
const [data, setData] = useState(null);
112+
const [loading, setLoading] = useState(true);
113+
114+
useEffect(() => {
115+
async function fetchData() {
116+
try {
117+
const response = await fetch('/api/traces/1');
118+
const data = await response.json();
119+
setData(data);
120+
} finally {
121+
setLoading(false);
122+
}
123+
}
124+
fetchData();
125+
}, []);
126+
127+
if (loading) return <div>Loading traces...</div>;
128+
129+
return (
130+
<main>
131+
{data && <TraceViewer data={data} id="viewer1" />}
132+
</main>
133+
);
134+
}
135+
```
136+
137+
## 🔧 Troubleshooting
138+
139+
### Images or Videos Not Loading
140+
141+
- Ensure the paths in your data match the actual file paths in the `public` directory
142+
- Paths should be relative to the `public` directory (e.g., `/screenshots/image.png`, not `public/screenshots/image.png`)
143+
- Check browser console for any 404 errors
144+
145+
### JSON Data Issues
146+
147+
- Verify your JSON files are properly formatted with valid JSON
148+
- Make sure all required fields are present (timestamp, screenshot, thought, action, video, timeRange)
149+
- Check that timeRange contains valid start and end values
150+
151+
## 🤝 Contributing
152+
153+
Contributions are welcome! Please feel free to submit a Pull Request.
154+
155+
## 📄 License
156+
157+
This project is open source and available under the [MIT License](LICENSE).

app/layout.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import '../src/styles/globals.css'
2+
import { Metadata } from 'next'
3+
4+
export const metadata: Metadata = {
5+
title: 'Computer Use Agent - macOS Agent',
6+
description: 'Intelligent Desktop Automation',
7+
}
8+
9+
export default function RootLayout({
10+
children,
11+
}: {
12+
children: React.ReactNode
13+
}) {
14+
return (
15+
<html lang="en">
16+
<head>
17+
<meta charSet="utf-8" />
18+
<meta name="viewport" content="width=device-width, initial-scale=1" />
19+
<link
20+
rel="stylesheet"
21+
href={process.env.NODE_ENV === 'production' ? '/CUA-Trace-Viewer/_next/static/css/app/layout.css' : '/_next/static/css/app/layout.css'}
22+
/>
23+
</head>
24+
<body>{children}</body>
25+
</html>
26+
)
27+
}

app/not-found.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Link from 'next/link'
2+
3+
export default function NotFound() {
4+
return (
5+
<div className="flex flex-col items-center justify-center min-h-screen text-center p-4">
6+
<h2 className="text-2xl font-bold mb-4">页面未找到</h2>
7+
<p className="mb-4">找不到请求的资源</p>
8+
<Link href="/" className="text-blue-500 hover:underline">
9+
返回首页
10+
</Link>
11+
</div>
12+
)
13+
}

0 commit comments

Comments
 (0)