vite-plugin-opencode-assistant 1.0.3 → 1.0.5
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/es/client/index.d.ts +1 -0
- package/es/client/index.js +328 -0
- package/es/core/api.d.ts +14 -0
- package/es/core/api.js +294 -0
- package/es/core/injector.d.ts +2 -0
- package/es/core/injector.js +11 -0
- package/es/core/service.d.ts +18 -0
- package/es/core/service.js +163 -0
- package/es/endpoints/context.d.ts +3 -0
- package/es/endpoints/context.js +114 -0
- package/es/endpoints/index.d.ts +4 -0
- package/es/endpoints/index.js +16 -0
- package/es/endpoints/sessions.d.ts +3 -0
- package/es/endpoints/sessions.js +79 -0
- package/es/endpoints/sse.d.ts +3 -0
- package/es/endpoints/sse.js +56 -0
- package/es/endpoints/start.d.ts +3 -0
- package/es/endpoints/start.js +35 -0
- package/es/endpoints/types.d.ts +13 -0
- package/es/endpoints/widget.d.ts +3 -0
- package/es/endpoints/widget.js +57 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +168 -0
- package/es/utils/paths.d.ts +3 -0
- package/es/utils/paths.js +38 -0
- package/es/utils/system.js +241 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +328 -0
- package/lib/client.js +5597 -0
- package/lib/core/api.d.ts +14 -0
- package/lib/core/api.js +321 -0
- package/lib/core/injector.d.ts +2 -0
- package/lib/core/injector.js +34 -0
- package/lib/core/service.d.ts +18 -0
- package/lib/core/service.js +180 -0
- package/lib/endpoints/context.d.ts +3 -0
- package/lib/endpoints/context.js +137 -0
- package/lib/endpoints/index.d.ts +4 -0
- package/lib/endpoints/index.js +41 -0
- package/lib/endpoints/sessions.d.ts +3 -0
- package/lib/endpoints/sessions.js +102 -0
- package/lib/endpoints/sse.d.ts +3 -0
- package/lib/endpoints/sse.js +79 -0
- package/lib/endpoints/start.d.ts +3 -0
- package/lib/endpoints/start.js +58 -0
- package/lib/endpoints/types.d.ts +13 -0
- package/lib/endpoints/types.js +15 -0
- package/lib/endpoints/widget.d.ts +3 -0
- package/lib/endpoints/widget.js +90 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +190 -0
- package/lib/style.css +1 -0
- package/lib/utils/paths.d.ts +3 -0
- package/lib/utils/paths.js +73 -0
- package/lib/utils/system.d.ts +5 -0
- package/lib/utils/system.js +274 -0
- package/package.json +29 -31
- package/README.md +0 -282
- package/dist/constants.d.ts +0 -73
- package/dist/constants.js +0 -74
- package/dist/constants.js.map +0 -1
- package/dist/logger.d.ts +0 -64
- package/dist/logger.js +0 -311
- package/dist/logger.js.map +0 -1
- package/dist/opencode/plugins/page-context.d.ts +0 -7
- package/dist/opencode/plugins/page-context.js +0 -345
- package/dist/opencode/plugins/page-context.js.map +0 -1
- package/dist/opencode/web.d.ts +0 -3
- package/dist/opencode/web.js +0 -81
- package/dist/opencode/web.js.map +0 -1
- package/dist/types.d.ts +0 -124
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/vite/client.js +0 -2288
- package/dist/vite/client.js.map +0 -1
- package/dist/vite/index.d.ts +0 -3
- package/dist/vite/index.js +0 -520
- package/dist/vite/index.js.map +0 -1
- package/dist/vite/injector.d.ts +0 -2
- package/dist/vite/injector.js +0 -6
- package/dist/vite/injector.js.map +0 -1
- package/dist/vite/utils.js +0 -206
- package/dist/vite/utils.js.map +0 -1
- /package/{dist/vite/client.d.ts → es/endpoints/types.js} +0 -0
- /package/{dist/vite/utils.d.ts → es/utils/system.d.ts} +0 -0
package/README.md
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
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/constants.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview OpenCode 插件常量定义
|
|
3
|
-
*/
|
|
4
|
-
/** ==================== 网络相关 ==================== */
|
|
5
|
-
/** 默认主机名 */
|
|
6
|
-
export declare const DEFAULT_HOSTNAME = "127.0.0.1";
|
|
7
|
-
/** 默认 Web 服务端口 */
|
|
8
|
-
export declare const DEFAULT_WEB_PORT = 4097;
|
|
9
|
-
/** 服务器启动超时时间(毫秒) */
|
|
10
|
-
export declare const SERVER_START_TIMEOUT = 15000;
|
|
11
|
-
/** 服务器检查间隔(毫秒) */
|
|
12
|
-
export declare const SERVER_CHECK_INTERVAL = 100;
|
|
13
|
-
/** ==================== 重试相关 ==================== */
|
|
14
|
-
/** 默认重试次数 */
|
|
15
|
-
export declare const DEFAULT_RETRIES = 5;
|
|
16
|
-
/** 重试延迟(毫秒) */
|
|
17
|
-
export declare const RETRY_DELAY = 500;
|
|
18
|
-
/** ==================== 端口查找 ==================== */
|
|
19
|
-
/** 最大端口尝试次数 */
|
|
20
|
-
export declare const MAX_PORT_TRIES = 10;
|
|
21
|
-
/** ==================== 日志相关 ==================== */
|
|
22
|
-
/** 插件日志前缀 */
|
|
23
|
-
export declare const LOG_PREFIX = "[vite-plugin-opencode]";
|
|
24
|
-
/** OpenCode Web 日志前缀 */
|
|
25
|
-
export declare const WEB_LOG_PREFIX = "[OpenCode Web]";
|
|
26
|
-
/** OpenCode Web 错误日志前缀 */
|
|
27
|
-
export declare const WEB_ERROR_PREFIX = "[OpenCode Web Error]";
|
|
28
|
-
/** ==================== 挂件相关 ==================== */
|
|
29
|
-
/** 挂件脚本路径 */
|
|
30
|
-
export declare const WIDGET_SCRIPT_PATH = "/__opencode_widget__.js";
|
|
31
|
-
/** 配置数据属性名 */
|
|
32
|
-
export declare const CONFIG_DATA_ATTR = "data-opencode-config";
|
|
33
|
-
/** 上下文 API 路径 */
|
|
34
|
-
export declare const CONTEXT_API_PATH = "/__opencode_context__";
|
|
35
|
-
/** 启动 API 路径 */
|
|
36
|
-
export declare const START_API_PATH = "/__opencode_start__";
|
|
37
|
-
/** 会话列表 API 路径 */
|
|
38
|
-
export declare const SESSIONS_API_PATH = "/__opencode_sessions__";
|
|
39
|
-
/** SSE 事件流路径 */
|
|
40
|
-
export declare const SSE_EVENTS_PATH = "/__opencode_events__";
|
|
41
|
-
/** 上下文更新间隔(毫秒) */
|
|
42
|
-
export declare const CONTEXT_UPDATE_INTERVAL = 500;
|
|
43
|
-
/** 服务器同步间隔(毫秒) */
|
|
44
|
-
export declare const SERVER_SYNC_INTERVAL = 2000;
|
|
45
|
-
/** Vue Inspector 检查间隔(毫秒) */
|
|
46
|
-
export declare const INSPECTOR_CHECK_INTERVAL = 500;
|
|
47
|
-
/** 自动打开延迟(毫秒) */
|
|
48
|
-
export declare const AUTO_OPEN_DELAY = 1000;
|
|
49
|
-
/** 通知显示时间(毫秒) */
|
|
50
|
-
export declare const NOTIFICATION_DURATION = 3000;
|
|
51
|
-
/** ==================== 存储相关 ==================== */
|
|
52
|
-
/** 初始化标记 */
|
|
53
|
-
export declare const INIT_MARKER = "__OPENCODE_INITIALIZED__";
|
|
54
|
-
/** 选中元素存储键 */
|
|
55
|
-
export declare const SELECTED_ELEMENTS_KEY = "__opencode_selected_elements__";
|
|
56
|
-
/** ==================== 文本处理 ==================== */
|
|
57
|
-
/** 元素文本最大显示长度 */
|
|
58
|
-
export declare const MAX_TEXT_LENGTH = 100;
|
|
59
|
-
/** 元素上下文标记 */
|
|
60
|
-
export declare const CONTEXT_MARKER = "[\u5143\u7D20\u4E0A\u4E0B\u6587]";
|
|
61
|
-
/** ==================== 默认配置 ==================== */
|
|
62
|
-
/** 默认插件配置 */
|
|
63
|
-
export declare const DEFAULT_CONFIG: {
|
|
64
|
-
enabled: boolean;
|
|
65
|
-
webPort: number;
|
|
66
|
-
hostname: string;
|
|
67
|
-
position: "bottom-right";
|
|
68
|
-
theme: "auto";
|
|
69
|
-
open: boolean;
|
|
70
|
-
autoReload: boolean;
|
|
71
|
-
verbose: boolean;
|
|
72
|
-
hotkey: string;
|
|
73
|
-
};
|
package/dist/constants.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview OpenCode 插件常量定义
|
|
3
|
-
*/
|
|
4
|
-
/** ==================== 网络相关 ==================== */
|
|
5
|
-
/** 默认主机名 */
|
|
6
|
-
export const DEFAULT_HOSTNAME = '127.0.0.1';
|
|
7
|
-
/** 默认 Web 服务端口 */
|
|
8
|
-
export const DEFAULT_WEB_PORT = 4097;
|
|
9
|
-
/** 服务器启动超时时间(毫秒) */
|
|
10
|
-
export const SERVER_START_TIMEOUT = 15000;
|
|
11
|
-
/** 服务器检查间隔(毫秒) */
|
|
12
|
-
export const SERVER_CHECK_INTERVAL = 100;
|
|
13
|
-
/** ==================== 重试相关 ==================== */
|
|
14
|
-
/** 默认重试次数 */
|
|
15
|
-
export const DEFAULT_RETRIES = 5;
|
|
16
|
-
/** 重试延迟(毫秒) */
|
|
17
|
-
export const RETRY_DELAY = 500;
|
|
18
|
-
/** ==================== 端口查找 ==================== */
|
|
19
|
-
/** 最大端口尝试次数 */
|
|
20
|
-
export const MAX_PORT_TRIES = 10;
|
|
21
|
-
/** ==================== 日志相关 ==================== */
|
|
22
|
-
/** 插件日志前缀 */
|
|
23
|
-
export const LOG_PREFIX = '[vite-plugin-opencode]';
|
|
24
|
-
/** OpenCode Web 日志前缀 */
|
|
25
|
-
export const WEB_LOG_PREFIX = '[OpenCode Web]';
|
|
26
|
-
/** OpenCode Web 错误日志前缀 */
|
|
27
|
-
export const WEB_ERROR_PREFIX = '[OpenCode Web Error]';
|
|
28
|
-
/** ==================== 挂件相关 ==================== */
|
|
29
|
-
/** 挂件脚本路径 */
|
|
30
|
-
export const WIDGET_SCRIPT_PATH = '/__opencode_widget__.js';
|
|
31
|
-
/** 配置数据属性名 */
|
|
32
|
-
export const CONFIG_DATA_ATTR = 'data-opencode-config';
|
|
33
|
-
/** 上下文 API 路径 */
|
|
34
|
-
export const CONTEXT_API_PATH = '/__opencode_context__';
|
|
35
|
-
/** 启动 API 路径 */
|
|
36
|
-
export const START_API_PATH = '/__opencode_start__';
|
|
37
|
-
/** 会话列表 API 路径 */
|
|
38
|
-
export const SESSIONS_API_PATH = '/__opencode_sessions__';
|
|
39
|
-
/** SSE 事件流路径 */
|
|
40
|
-
export const SSE_EVENTS_PATH = '/__opencode_events__';
|
|
41
|
-
/** 上下文更新间隔(毫秒) */
|
|
42
|
-
export const CONTEXT_UPDATE_INTERVAL = 500;
|
|
43
|
-
/** 服务器同步间隔(毫秒) */
|
|
44
|
-
export const SERVER_SYNC_INTERVAL = 2000;
|
|
45
|
-
/** Vue Inspector 检查间隔(毫秒) */
|
|
46
|
-
export const INSPECTOR_CHECK_INTERVAL = 500;
|
|
47
|
-
/** 自动打开延迟(毫秒) */
|
|
48
|
-
export const AUTO_OPEN_DELAY = 1000;
|
|
49
|
-
/** 通知显示时间(毫秒) */
|
|
50
|
-
export const NOTIFICATION_DURATION = 3000;
|
|
51
|
-
/** ==================== 存储相关 ==================== */
|
|
52
|
-
/** 初始化标记 */
|
|
53
|
-
export const INIT_MARKER = '__OPENCODE_INITIALIZED__';
|
|
54
|
-
/** 选中元素存储键 */
|
|
55
|
-
export const SELECTED_ELEMENTS_KEY = '__opencode_selected_elements__';
|
|
56
|
-
/** ==================== 文本处理 ==================== */
|
|
57
|
-
/** 元素文本最大显示长度 */
|
|
58
|
-
export const MAX_TEXT_LENGTH = 100;
|
|
59
|
-
/** 元素上下文标记 */
|
|
60
|
-
export const CONTEXT_MARKER = '[元素上下文]';
|
|
61
|
-
/** ==================== 默认配置 ==================== */
|
|
62
|
-
/** 默认插件配置 */
|
|
63
|
-
export const DEFAULT_CONFIG = {
|
|
64
|
-
enabled: true,
|
|
65
|
-
webPort: DEFAULT_WEB_PORT,
|
|
66
|
-
hostname: DEFAULT_HOSTNAME,
|
|
67
|
-
position: 'bottom-right',
|
|
68
|
-
theme: 'auto',
|
|
69
|
-
open: false,
|
|
70
|
-
autoReload: true,
|
|
71
|
-
verbose: false,
|
|
72
|
-
hotkey: 'ctrl+k',
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qDAAqD;AAErD,YAAY;AACZ,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAA;AAE3C,kBAAkB;AAClB,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAEpC,oBAAoB;AACpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAA;AAEzC,kBAAkB;AAClB,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAA;AAExC,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAA;AAEhC,eAAe;AACf,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAA;AAE9B,qDAAqD;AAErD,eAAe;AACf,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAA;AAEhC,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,UAAU,GAAG,wBAAwB,CAAA;AAElD,wBAAwB;AACxB,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAE9C,0BAA0B;AAC1B,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAA;AAEtD,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAE3D,cAAc;AACd,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAA;AAEtD,iBAAiB;AACjB,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAEvD,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAA;AAEnD,kBAAkB;AAClB,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAA;AAEzD,gBAAgB;AAChB,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAA;AAErD,kBAAkB;AAClB,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAE1C,kBAAkB;AAClB,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAA;AAExC,6BAA6B;AAC7B,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAA;AAE3C,iBAAiB;AACjB,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAA;AAEnC,iBAAiB;AACjB,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAA;AAEzC,qDAAqD;AAErD,YAAY;AACZ,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAA;AAErD,cAAc;AACd,MAAM,CAAC,MAAM,qBAAqB,GAAG,gCAAgC,CAAA;AAErE,qDAAqD;AAErD,iBAAiB;AACjB,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAA;AAElC,cAAc;AACd,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAA;AAEvC,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,gBAAgB;IACzB,QAAQ,EAAE,gBAAgB;IAC1B,QAAQ,EAAE,cAAuB;IACjC,KAAK,EAAE,MAAe;IACtB,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,QAAQ;CACjB,CAAA","sourcesContent":["/**\n * @fileoverview OpenCode 插件常量定义\n */\n\n/** ==================== 网络相关 ==================== */\n\n/** 默认主机名 */\nexport const DEFAULT_HOSTNAME = '127.0.0.1'\n\n/** 默认 Web 服务端口 */\nexport const DEFAULT_WEB_PORT = 4097\n\n/** 服务器启动超时时间(毫秒) */\nexport const SERVER_START_TIMEOUT = 15000\n\n/** 服务器检查间隔(毫秒) */\nexport const SERVER_CHECK_INTERVAL = 100\n\n/** ==================== 重试相关 ==================== */\n\n/** 默认重试次数 */\nexport const DEFAULT_RETRIES = 5\n\n/** 重试延迟(毫秒) */\nexport const RETRY_DELAY = 500\n\n/** ==================== 端口查找 ==================== */\n\n/** 最大端口尝试次数 */\nexport const MAX_PORT_TRIES = 10\n\n/** ==================== 日志相关 ==================== */\n\n/** 插件日志前缀 */\nexport const LOG_PREFIX = '[vite-plugin-opencode]'\n\n/** OpenCode Web 日志前缀 */\nexport const WEB_LOG_PREFIX = '[OpenCode Web]'\n\n/** OpenCode Web 错误日志前缀 */\nexport const WEB_ERROR_PREFIX = '[OpenCode Web Error]'\n\n/** ==================== 挂件相关 ==================== */\n\n/** 挂件脚本路径 */\nexport const WIDGET_SCRIPT_PATH = '/__opencode_widget__.js'\n\n/** 配置数据属性名 */\nexport const CONFIG_DATA_ATTR = 'data-opencode-config'\n\n/** 上下文 API 路径 */\nexport const CONTEXT_API_PATH = '/__opencode_context__'\n\n/** 启动 API 路径 */\nexport const START_API_PATH = '/__opencode_start__'\n\n/** 会话列表 API 路径 */\nexport const SESSIONS_API_PATH = '/__opencode_sessions__'\n\n/** SSE 事件流路径 */\nexport const SSE_EVENTS_PATH = '/__opencode_events__'\n\n/** 上下文更新间隔(毫秒) */\nexport const CONTEXT_UPDATE_INTERVAL = 500\n\n/** 服务器同步间隔(毫秒) */\nexport const SERVER_SYNC_INTERVAL = 2000\n\n/** Vue Inspector 检查间隔(毫秒) */\nexport const INSPECTOR_CHECK_INTERVAL = 500\n\n/** 自动打开延迟(毫秒) */\nexport const AUTO_OPEN_DELAY = 1000\n\n/** 通知显示时间(毫秒) */\nexport const NOTIFICATION_DURATION = 3000\n\n/** ==================== 存储相关 ==================== */\n\n/** 初始化标记 */\nexport const INIT_MARKER = '__OPENCODE_INITIALIZED__'\n\n/** 选中元素存储键 */\nexport const SELECTED_ELEMENTS_KEY = '__opencode_selected_elements__'\n\n/** ==================== 文本处理 ==================== */\n\n/** 元素文本最大显示长度 */\nexport const MAX_TEXT_LENGTH = 100\n\n/** 元素上下文标记 */\nexport const CONTEXT_MARKER = '[元素上下文]'\n\n/** ==================== 默认配置 ==================== */\n\n/** 默认插件配置 */\nexport const DEFAULT_CONFIG = {\n enabled: true,\n webPort: DEFAULT_WEB_PORT,\n hostname: DEFAULT_HOSTNAME,\n position: 'bottom-right' as const,\n theme: 'auto' as const,\n open: false,\n autoReload: true,\n verbose: false,\n hotkey: 'ctrl+k',\n}\n"]}
|
package/dist/logger.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export declare enum LogLevel {
|
|
2
|
-
DEBUG = 0,
|
|
3
|
-
INFO = 1,
|
|
4
|
-
WARN = 2,
|
|
5
|
-
ERROR = 3,
|
|
6
|
-
NONE = 4
|
|
7
|
-
}
|
|
8
|
-
export interface LogContext {
|
|
9
|
-
module?: string;
|
|
10
|
-
operation?: string;
|
|
11
|
-
traceId?: string;
|
|
12
|
-
duration?: number;
|
|
13
|
-
error?: Error | unknown;
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
}
|
|
16
|
-
interface LoggerConfig {
|
|
17
|
-
verbose: boolean;
|
|
18
|
-
level: LogLevel;
|
|
19
|
-
showTimestamp: boolean;
|
|
20
|
-
showCaller: boolean;
|
|
21
|
-
showTrace: boolean;
|
|
22
|
-
indent: string;
|
|
23
|
-
}
|
|
24
|
-
export declare function configureLogger(options: Partial<LoggerConfig>): void;
|
|
25
|
-
export declare function setVerbose(verbose: boolean): void;
|
|
26
|
-
export declare const logger: {
|
|
27
|
-
debug(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
28
|
-
info(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
29
|
-
warn(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
30
|
-
error(message: string, context?: LogContext, ...args: unknown[]): void;
|
|
31
|
-
group(label: string, context?: LogContext): void;
|
|
32
|
-
groupEnd(): void;
|
|
33
|
-
};
|
|
34
|
-
export declare function generateTraceId(): string;
|
|
35
|
-
export declare class PerformanceTimer {
|
|
36
|
-
private startTime;
|
|
37
|
-
private context;
|
|
38
|
-
private operation;
|
|
39
|
-
constructor(operation: string, context?: LogContext);
|
|
40
|
-
end(message?: string): number;
|
|
41
|
-
checkpoint(label: string): number;
|
|
42
|
-
}
|
|
43
|
-
export declare class RequestContext {
|
|
44
|
-
traceId: string;
|
|
45
|
-
method: string;
|
|
46
|
-
path: string;
|
|
47
|
-
startTime: number;
|
|
48
|
-
private checkpoints;
|
|
49
|
-
constructor(method: string, path: string);
|
|
50
|
-
checkpoint(label: string): void;
|
|
51
|
-
end(statusCode: number): void;
|
|
52
|
-
error(error: Error | unknown): void;
|
|
53
|
-
}
|
|
54
|
-
export declare function createLogger(module: string): {
|
|
55
|
-
debug(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
|
|
56
|
-
info(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
|
|
57
|
-
warn(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
|
|
58
|
-
error(message: string, context?: Omit<LogContext, "module">, ...args: unknown[]): void;
|
|
59
|
-
timer(operation: string, context?: Omit<LogContext, "module">): PerformanceTimer;
|
|
60
|
-
};
|
|
61
|
-
export declare function logMethod(target: unknown, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
62
|
-
export declare function formatBytes(bytes: number): string;
|
|
63
|
-
export declare function formatDuration(ms: number): string;
|
|
64
|
-
export {};
|