vite-plugin-opencode-assistant 1.0.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 +282 -0
- package/dist/client.d.ts +0 -0
- package/dist/client.js +1549 -0
- package/dist/constants.d.ts +76 -0
- package/dist/constants.js +77 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +448 -0
- package/dist/injector.d.ts +20 -0
- package/dist/injector.js +24 -0
- package/dist/plugins/page-context.d.ts +20 -0
- package/dist/plugins/page-context.js +121 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +42 -0
- package/dist/utils.js +156 -0
- package/dist/web.d.ts +18 -0
- package/dist/web.js +95 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# vite-plugin-opencode
|
|
2
|
+
|
|
3
|
+
A Vite plugin that embeds OpenCode Web UI in your development environment, enabling real-time code modification through AI chat.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Auto-start OpenCode services** - Automatically starts OpenCode Server and Web UI
|
|
8
|
+
- 💬 **Embedded Chat Interface** - Customer support-like chat widget in your app
|
|
9
|
+
- 🔄 **Real-time Code Modification** - AI can modify your code and see changes instantly via HMR
|
|
10
|
+
- 🎨 **Customizable** - Configurable position, theme, and behavior
|
|
11
|
+
- ⚡ **Zero Configuration** - Works out of the box with sensible defaults
|
|
12
|
+
- 🔧 **Framework Agnostic** - Works with React, Vue, Svelte, and more
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -D vite-plugin-opencode
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
This plugin requires [OpenCode](https://opencode.ai) to be installed on your system.
|
|
23
|
+
|
|
24
|
+
### Install OpenCode
|
|
25
|
+
|
|
26
|
+
**Using Homebrew (macOS):**
|
|
27
|
+
```bash
|
|
28
|
+
brew install opencode-ai/tap/opencode
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Using the install script:**
|
|
32
|
+
```bash
|
|
33
|
+
curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/main/install | bash
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Using Go:**
|
|
37
|
+
```bash
|
|
38
|
+
go install github.com/opencode-ai/opencode@latest
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Basic Setup
|
|
44
|
+
|
|
45
|
+
Add the plugin to your `vite.config.ts`:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { defineConfig } from 'vite'
|
|
49
|
+
import opencode from 'vite-plugin-opencode'
|
|
50
|
+
|
|
51
|
+
export default defineConfig({
|
|
52
|
+
plugins: [
|
|
53
|
+
opencode(),
|
|
54
|
+
],
|
|
55
|
+
})
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### With Configuration
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { defineConfig } from 'vite'
|
|
62
|
+
import opencode from 'vite-plugin-opencode'
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
plugins: [
|
|
66
|
+
opencode({
|
|
67
|
+
serverPort: 4096, // OpenCode Server port
|
|
68
|
+
webPort: 4097, // OpenCode Web UI port
|
|
69
|
+
hostname: 'localhost',
|
|
70
|
+
position: 'bottom-right',
|
|
71
|
+
theme: 'auto',
|
|
72
|
+
open: false,
|
|
73
|
+
autoReload: true,
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Start Development
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm run dev
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
You'll see a floating button in the bottom-right corner of your app. Click it to open the AI chat interface!
|
|
86
|
+
|
|
87
|
+
## How It Works
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
┌─────────────────────────────────────────────────┐
|
|
91
|
+
│ Vite Dev Server (5173) │
|
|
92
|
+
│ │
|
|
93
|
+
│ ┌───────────────────────────────────────────┐ │
|
|
94
|
+
│ │ Your App (with HMR) │ │
|
|
95
|
+
│ │ - Embedded OpenCode Widget │ │
|
|
96
|
+
│ └───────────────────────────────────────────┘ │
|
|
97
|
+
│ │
|
|
98
|
+
│ ┌───────────────────────────────────────────┐ │
|
|
99
|
+
│ │ vite-plugin-opencode │ │
|
|
100
|
+
│ │ - OpenCode Server (4096) │ │
|
|
101
|
+
│ │ - OpenCode Web (4097) │ │
|
|
102
|
+
│ └───────────────────────────────────────────┘ │
|
|
103
|
+
└─────────────────────────────────────────────────┘
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Workflow
|
|
107
|
+
|
|
108
|
+
1. **User** asks AI to modify code (e.g., "Change button color to red")
|
|
109
|
+
2. **OpenCode Web** sends request to OpenCode Server
|
|
110
|
+
3. **OpenCode Server** reads and modifies the file
|
|
111
|
+
4. **Vite HMR** detects file change and hot-reloads the page
|
|
112
|
+
5. **User** sees the change instantly!
|
|
113
|
+
|
|
114
|
+
## Configuration Options
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface OpenCodeOptions {
|
|
118
|
+
// Enable/disable the plugin (default: true)
|
|
119
|
+
enabled?: boolean
|
|
120
|
+
|
|
121
|
+
// OpenCode Server port (default: 4096)
|
|
122
|
+
serverPort?: number
|
|
123
|
+
|
|
124
|
+
// OpenCode Web UI port (default: 4097)
|
|
125
|
+
webPort?: number
|
|
126
|
+
|
|
127
|
+
// Hostname (default: 'localhost')
|
|
128
|
+
hostname?: string
|
|
129
|
+
|
|
130
|
+
// Widget position (default: 'bottom-right')
|
|
131
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
|
|
132
|
+
|
|
133
|
+
// Theme (default: 'auto')
|
|
134
|
+
theme?: 'light' | 'dark' | 'auto'
|
|
135
|
+
|
|
136
|
+
// Auto-open chat window (default: false)
|
|
137
|
+
open?: boolean
|
|
138
|
+
|
|
139
|
+
// Enable auto-reload notifications (default: true)
|
|
140
|
+
autoReload?: boolean
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Examples
|
|
145
|
+
|
|
146
|
+
### React
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// vite.config.ts
|
|
150
|
+
import { defineConfig } from 'vite'
|
|
151
|
+
import react from '@vitejs/plugin-react'
|
|
152
|
+
import opencode from 'vite-plugin-opencode'
|
|
153
|
+
|
|
154
|
+
export default defineConfig({
|
|
155
|
+
plugins: [
|
|
156
|
+
react(),
|
|
157
|
+
opencode(),
|
|
158
|
+
],
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Vue
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// vite.config.ts
|
|
166
|
+
import { defineConfig } from 'vite'
|
|
167
|
+
import vue from '@vitejs/plugin-vue'
|
|
168
|
+
import opencode from 'vite-plugin-opencode'
|
|
169
|
+
|
|
170
|
+
export default defineConfig({
|
|
171
|
+
plugins: [
|
|
172
|
+
vue(),
|
|
173
|
+
opencode(),
|
|
174
|
+
],
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Use Cases
|
|
179
|
+
|
|
180
|
+
### 1. Style Modifications
|
|
181
|
+
```
|
|
182
|
+
User: "Change the button color to red"
|
|
183
|
+
AI: Modifies App.css
|
|
184
|
+
Result: Button turns red instantly
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 2. Component Creation
|
|
188
|
+
```
|
|
189
|
+
User: "Add a login form"
|
|
190
|
+
AI: Creates LoginForm.jsx
|
|
191
|
+
Result: Login form appears on page
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 3. Bug Fixes
|
|
195
|
+
```
|
|
196
|
+
User: "Fix the counter not working"
|
|
197
|
+
AI: Modifies App.jsx
|
|
198
|
+
Result: Counter works correctly
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## API
|
|
202
|
+
|
|
203
|
+
The plugin exposes a global API that you can use in your code:
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
// Open the chat widget
|
|
207
|
+
window.OpenCodeWidget.open()
|
|
208
|
+
|
|
209
|
+
// Close the chat widget
|
|
210
|
+
window.OpenCodeWidget.close()
|
|
211
|
+
|
|
212
|
+
// Toggle the chat widget
|
|
213
|
+
window.OpenCodeWidget.toggle()
|
|
214
|
+
|
|
215
|
+
// Show a notification
|
|
216
|
+
window.OpenCodeWidget.showNotification('Code updated!')
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Keyboard Shortcuts
|
|
220
|
+
|
|
221
|
+
- `Ctrl/Cmd + K` - Toggle chat widget
|
|
222
|
+
|
|
223
|
+
## Troubleshooting
|
|
224
|
+
|
|
225
|
+
### OpenCode not installed
|
|
226
|
+
|
|
227
|
+
If you see an error message about OpenCode not being installed, follow the installation instructions above.
|
|
228
|
+
|
|
229
|
+
### Port conflicts
|
|
230
|
+
|
|
231
|
+
If ports 4096 or 4097 are already in use, you can configure different ports:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
opencode({
|
|
235
|
+
serverPort: 5000,
|
|
236
|
+
webPort: 5001,
|
|
237
|
+
})
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### CORS issues
|
|
241
|
+
|
|
242
|
+
The plugin automatically configures CORS for local development. If you encounter CORS issues, make sure you're using the correct hostname and ports.
|
|
243
|
+
|
|
244
|
+
## Development
|
|
245
|
+
|
|
246
|
+
### Build the plugin
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
npm run build
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Run tests
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
npm test
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Run the example
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
cd example
|
|
262
|
+
npm install
|
|
263
|
+
npm run dev
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Contributing
|
|
267
|
+
|
|
268
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
269
|
+
|
|
270
|
+
## License
|
|
271
|
+
|
|
272
|
+
MIT
|
|
273
|
+
|
|
274
|
+
## Links
|
|
275
|
+
|
|
276
|
+
- [OpenCode Documentation](https://opencode.ai/docs)
|
|
277
|
+
- [OpenCode GitHub](https://github.com/opencode-ai/opencode)
|
|
278
|
+
- [Vite Plugin API](https://vite.dev/guide/api-plugin.html)
|
|
279
|
+
|
|
280
|
+
## Acknowledgments
|
|
281
|
+
|
|
282
|
+
This plugin is built on top of [OpenCode](https://opencode.ai), an open-source AI coding assistant.
|
package/dist/client.d.ts
ADDED
|
File without changes
|