|
| 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 | + |
| 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). |
0 commit comments