next-ai-editor 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -77
- package/dist/index.cjs +537 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +50 -0
- package/dist/index.js +538 -20
- package/dist/index.js.map +1 -1
- package/dist/next-ai-editor.css +707 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
# Next AI Editor
|
|
2
2
|
|
|
3
|
-
> AI-powered React component editor for Next.js -
|
|
3
|
+
> AI-powered React component editor for Next.js - chat with your UI in development mode
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Next AI Editor is a development tool that lets you interact with your React components using natural language. Click any component in your Next.js app and chat with an AI agent to make changes, add features, or refactor code - all while your app is running.
|
|
4
8
|
|
|
5
9
|
## Features
|
|
6
10
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
11
|
+
- 💬 **Chat Interface**: Natural conversation with AI about your components
|
|
12
|
+
- 🎯 **Click-to-Select**: Click any component in your Next.js app to start editing
|
|
13
|
+
- 🤖 **AI Agent**: Powered by Claude Agent SDK for intelligent code modifications
|
|
14
|
+
- 🔍 **Smart Detection**: Automatically finds exact component locations in your source code
|
|
10
15
|
- 📍 **Source Maps**: Works with both Server Components and Client Components using Turbopack source maps
|
|
11
16
|
- 🎨 **Syntax Highlighting**: Beautiful code preview with theme-aware syntax highlighting
|
|
12
|
-
-
|
|
13
|
-
- 🔄 **
|
|
14
|
-
- 🛡️ **Safe**: Only works in development mode
|
|
17
|
+
- 📜 **Task History**: Track all changes made by the AI agent
|
|
18
|
+
- 🔄 **Hot Reload**: See changes immediately in your browser
|
|
19
|
+
- 🛡️ **Safe**: Only works in development mode
|
|
20
|
+
|
|
21
|
+
## Architecture
|
|
22
|
+
|
|
23
|
+
The package is split into two parts:
|
|
24
|
+
|
|
25
|
+
1. **next-ai-editor** (this package): Client-side React components and UI
|
|
26
|
+
2. **next-ai-editor-service**: Background service that handles file operations, AI processing, and code analysis
|
|
27
|
+
|
|
28
|
+
The client communicates with the service via HTTP/WebSocket on port 3456.
|
|
15
29
|
|
|
16
30
|
## Installation
|
|
17
31
|
|
|
@@ -25,21 +39,38 @@ yarn add next-ai-editor
|
|
|
25
39
|
|
|
26
40
|
## Setup
|
|
27
41
|
|
|
28
|
-
### 1.
|
|
42
|
+
### 1. Start the AI Editor Service
|
|
43
|
+
|
|
44
|
+
The AI editor requires a background service to handle file operations and AI processing. The service is located in the `packages/ai-editor-service` directory of this monorepo.
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
**Environment Variables**
|
|
47
|
+
|
|
48
|
+
Create a `.env` file in the service directory:
|
|
31
49
|
|
|
32
50
|
```env
|
|
33
51
|
ANTHROPIC_API_KEY=sk-ant-api03-...
|
|
52
|
+
NODE_ENV=development
|
|
53
|
+
NEXT_PUBLIC_AI_EDITOR_ENABLED=true
|
|
34
54
|
```
|
|
35
55
|
|
|
36
|
-
|
|
56
|
+
**Run the Service**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd packages/ai-editor-service
|
|
60
|
+
pnpm install
|
|
61
|
+
pnpm dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The service will start on port 3456 by default.
|
|
65
|
+
|
|
66
|
+
### 2. Add to Your Next.js App
|
|
37
67
|
|
|
38
68
|
Wrap your root layout with the `AIEditorProvider`:
|
|
39
69
|
|
|
40
70
|
```tsx
|
|
41
71
|
// app/layout.tsx
|
|
42
72
|
import { AIEditorProvider } from "next-ai-editor";
|
|
73
|
+
import "next-ai-editor/styles";
|
|
43
74
|
|
|
44
75
|
export default function RootLayout({
|
|
45
76
|
children,
|
|
@@ -58,34 +89,48 @@ export default function RootLayout({
|
|
|
58
89
|
}
|
|
59
90
|
```
|
|
60
91
|
|
|
61
|
-
|
|
92
|
+
That's it! No API routes needed - the package communicates directly with the service.
|
|
62
93
|
|
|
63
|
-
|
|
94
|
+
## Usage
|
|
64
95
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
96
|
+
### Basic Chat Workflow
|
|
97
|
+
|
|
98
|
+
1. **Enable AI Editor**: Press `Ctrl+Shift+E` (or `Cmd+Shift+E` on Mac)
|
|
99
|
+
2. **Open Chat Panel**: Click the chat button in the bottom-right corner
|
|
100
|
+
3. **Select Component**: Click the component selector tool and click any component
|
|
101
|
+
4. **Chat**: Describe what you want to change, add, or refactor
|
|
102
|
+
5. **Apply**: The AI agent will make the changes automatically
|
|
103
|
+
|
|
104
|
+
### Example Prompts
|
|
68
105
|
|
|
69
|
-
|
|
70
|
-
|
|
106
|
+
**Simple Changes**
|
|
107
|
+
```
|
|
108
|
+
"Change the button color to blue"
|
|
109
|
+
"Add a shadow to this card"
|
|
110
|
+
"Make the heading text larger"
|
|
71
111
|
```
|
|
72
112
|
|
|
73
|
-
|
|
113
|
+
**Adding Features**
|
|
114
|
+
```
|
|
115
|
+
"Add a loading state to this button"
|
|
116
|
+
"Add error handling to this form"
|
|
117
|
+
"Make this component responsive"
|
|
118
|
+
```
|
|
74
119
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
120
|
+
**Refactoring**
|
|
121
|
+
```
|
|
122
|
+
"Extract this form into a separate component"
|
|
123
|
+
"Convert this to use TypeScript"
|
|
124
|
+
"Add proper prop types to this component"
|
|
125
|
+
```
|
|
81
126
|
|
|
82
127
|
## API Reference
|
|
83
128
|
|
|
84
|
-
### Client
|
|
129
|
+
### Client Components
|
|
85
130
|
|
|
86
131
|
#### `AIEditorProvider`
|
|
87
132
|
|
|
88
|
-
|
|
133
|
+
Main provider component that wraps your app.
|
|
89
134
|
|
|
90
135
|
```tsx
|
|
91
136
|
import { AIEditorProvider } from "next-ai-editor";
|
|
@@ -99,41 +144,91 @@ import { AIEditorProvider } from "next-ai-editor";
|
|
|
99
144
|
- `theme?: "dark" | "light"` - UI theme (default: "dark")
|
|
100
145
|
- `children: ReactNode` - Your app content
|
|
101
146
|
|
|
102
|
-
|
|
147
|
+
#### `ChatPanel`
|
|
148
|
+
|
|
149
|
+
Standalone chat panel component for advanced use cases.
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { ChatPanel } from "next-ai-editor";
|
|
153
|
+
|
|
154
|
+
<ChatPanel
|
|
155
|
+
isExpanded={true}
|
|
156
|
+
onToggle={() => {}}
|
|
157
|
+
activeTool={null}
|
|
158
|
+
onToolChange={(tool) => {}}
|
|
159
|
+
attachedContext={null}
|
|
160
|
+
onClearContext={() => {}}
|
|
161
|
+
theme="dark"
|
|
162
|
+
/>
|
|
163
|
+
```
|
|
103
164
|
|
|
104
|
-
#### `
|
|
165
|
+
#### `ControlPill`
|
|
105
166
|
|
|
106
|
-
|
|
167
|
+
Floating control button for toggling the editor.
|
|
107
168
|
|
|
108
169
|
```tsx
|
|
109
|
-
import {
|
|
170
|
+
import { ControlPill } from "next-ai-editor";
|
|
110
171
|
|
|
111
|
-
|
|
112
|
-
|
|
172
|
+
<ControlPill
|
|
173
|
+
isEditorEnabled={true}
|
|
174
|
+
onToggle={() => {}}
|
|
175
|
+
theme="dark"
|
|
176
|
+
/>
|
|
113
177
|
```
|
|
114
178
|
|
|
115
|
-
|
|
179
|
+
### Types
|
|
116
180
|
|
|
117
|
-
|
|
181
|
+
```tsx
|
|
182
|
+
import type {
|
|
183
|
+
SourceLocation,
|
|
184
|
+
ElementContext,
|
|
185
|
+
ChatPanelProps,
|
|
186
|
+
ControlPillProps,
|
|
187
|
+
AttachedContext,
|
|
188
|
+
ToolType,
|
|
189
|
+
TaskHistoryItem,
|
|
190
|
+
} from "next-ai-editor";
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Service Configuration
|
|
118
194
|
|
|
119
195
|
```tsx
|
|
120
|
-
import {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
} from "next-ai-editor/server";
|
|
196
|
+
import { getServiceUrl, buildServiceUrl } from "next-ai-editor";
|
|
197
|
+
|
|
198
|
+
// Get the service base URL (auto-detects localhost or deployed)
|
|
199
|
+
const serviceUrl = getServiceUrl(); // "http://localhost:3456"
|
|
200
|
+
|
|
201
|
+
// Build full endpoint URL
|
|
202
|
+
const endpoint = buildServiceUrl("api/chat"); // "http://localhost:3456/api/chat"
|
|
128
203
|
```
|
|
129
204
|
|
|
130
205
|
## How It Works
|
|
131
206
|
|
|
132
|
-
1.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
207
|
+
### 1. Component Detection
|
|
208
|
+
Uses React Fiber's `_debugStack` to capture component hierarchy and location when you click an element.
|
|
209
|
+
|
|
210
|
+
### 2. Source Mapping
|
|
211
|
+
Resolves compiled positions to original source using Turbopack source maps. This works for both Server Components and Client Components.
|
|
212
|
+
|
|
213
|
+
### 3. AI Agent
|
|
214
|
+
The service runs a Claude Agent (via Claude Agent SDK) that can:
|
|
215
|
+
- Read and analyze your source code
|
|
216
|
+
- Make precise edits using AST parsing (Babel)
|
|
217
|
+
- Understand context from previous changes
|
|
218
|
+
- Handle multi-step tasks autonomously
|
|
219
|
+
|
|
220
|
+
### 4. Live Updates
|
|
221
|
+
Changes are written to your source files, and Next.js's hot reload automatically updates the browser.
|
|
222
|
+
|
|
223
|
+
## Service Architecture
|
|
224
|
+
|
|
225
|
+
The `next-ai-editor-service` package handles:
|
|
226
|
+
|
|
227
|
+
- **File Operations**: Reading and writing source files safely
|
|
228
|
+
- **Source Map Resolution**: Mapping compiled code positions to original source
|
|
229
|
+
- **AST Parsing**: Using Babel to analyze and modify code precisely
|
|
230
|
+
- **AI Processing**: Running Claude Agent SDK with access to your codebase
|
|
231
|
+
- **WebSocket Streaming**: Real-time chat updates and tool execution feedback
|
|
137
232
|
|
|
138
233
|
## Requirements
|
|
139
234
|
|
|
@@ -141,62 +236,63 @@ import {
|
|
|
141
236
|
- **React**: 18.0.0 or higher
|
|
142
237
|
- **Node.js**: 18.0.0 or higher
|
|
143
238
|
- **Anthropic API Key**: Required for AI functionality
|
|
239
|
+
- **AI Editor Service**: Must be running on port 3456
|
|
144
240
|
|
|
145
241
|
## Development Only
|
|
146
242
|
|
|
147
|
-
This package is designed for development only.
|
|
243
|
+
This package is designed for development only. The service will refuse to run in production (`NODE_ENV=production`), and all file operations are restricted to your project directory.
|
|
148
244
|
|
|
149
|
-
##
|
|
245
|
+
## Configuration
|
|
150
246
|
|
|
151
|
-
###
|
|
247
|
+
### Service URL
|
|
152
248
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
"increase the font size to 18px"
|
|
157
|
-
```
|
|
249
|
+
By default, the package auto-detects the service URL:
|
|
250
|
+
- **Local development**: `http://localhost:3456`
|
|
251
|
+
- **Deployed**: `https://${hostname}:3456`
|
|
158
252
|
|
|
159
|
-
|
|
253
|
+
You can override this by setting `NEXT_PUBLIC_AI_EDITOR_SERVICE_URL` in your environment variables.
|
|
160
254
|
|
|
161
|
-
|
|
162
|
-
"center this vertically"
|
|
163
|
-
"make this a flex row"
|
|
164
|
-
"add 20px padding around this"
|
|
165
|
-
```
|
|
255
|
+
### Keyboard Shortcuts
|
|
166
256
|
|
|
167
|
-
|
|
257
|
+
- `Ctrl+Shift+E` / `Cmd+Shift+E` - Toggle AI Editor
|
|
258
|
+
- `Ctrl+Enter` / `Cmd+Enter` - Send chat message
|
|
168
259
|
|
|
169
|
-
|
|
170
|
-
"change the text to 'Hello World'"
|
|
171
|
-
"add a subtitle under this heading"
|
|
172
|
-
"make this bold"
|
|
173
|
-
```
|
|
260
|
+
## Troubleshooting
|
|
174
261
|
|
|
175
|
-
###
|
|
262
|
+
### Service Connection Issues
|
|
176
263
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
264
|
+
Make sure the AI editor service is running:
|
|
265
|
+
```bash
|
|
266
|
+
cd packages/ai-editor-service
|
|
267
|
+
pnpm dev
|
|
181
268
|
```
|
|
182
269
|
|
|
183
|
-
|
|
270
|
+
Check the console for errors connecting to `http://localhost:3456`.
|
|
184
271
|
|
|
185
272
|
### Component Not Detected
|
|
186
273
|
|
|
187
|
-
-
|
|
188
|
-
- Only React components are
|
|
274
|
+
- Ensure you're running Next.js dev server (`npm run dev`)
|
|
275
|
+
- Only React components are selectable (not plain HTML)
|
|
189
276
|
- Server Components and Client Components are both supported
|
|
190
277
|
|
|
191
278
|
### Source Mapping Issues
|
|
192
279
|
|
|
193
280
|
- Ensure `.next/dev/` directory exists with source maps
|
|
194
281
|
- Turbopack generates `.map` files automatically in development
|
|
282
|
+
- Check that your component has valid `_debugStack` in React Fiber
|
|
195
283
|
|
|
196
284
|
### API Key Issues
|
|
197
285
|
|
|
198
|
-
- Verify `ANTHROPIC_API_KEY` is set in `.env
|
|
199
|
-
- Restart
|
|
286
|
+
- Verify `ANTHROPIC_API_KEY` is set in the service's `.env` file
|
|
287
|
+
- Restart the service after adding environment variables
|
|
288
|
+
- Check service logs for authentication errors
|
|
289
|
+
|
|
290
|
+
## Examples
|
|
291
|
+
|
|
292
|
+
Check out the demo apps in the monorepo:
|
|
293
|
+
- `apps/patchy` - Full-featured example with the AI editor
|
|
294
|
+
- `demos/blog` - Blog demo with AI editor
|
|
295
|
+
- `demos/e-commerce` - E-commerce demo with AI editor
|
|
200
296
|
|
|
201
297
|
## Contributing
|
|
202
298
|
|
|
@@ -211,3 +307,4 @@ MIT © Jesse Halpern
|
|
|
211
307
|
- [GitHub Repository](https://github.com/anon-dot-com/next-ai-editor)
|
|
212
308
|
- [Issue Tracker](https://github.com/anon-dot-com/next-ai-editor/issues)
|
|
213
309
|
- [Anthropic API](https://www.anthropic.com)
|
|
310
|
+
- [Claude Agent SDK](https://github.com/anthropics/claude-agent-sdk)
|