vite-plugin-opencode-assistant 1.0.4 → 1.0.6
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/{dist/vite → es}/index.d.ts +1 -1
- 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 +28 -33
- package/README.md +0 -287
- package/dist/constants.d.ts +0 -74
- package/dist/constants.js +0 -75
- 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 -372
- 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 -126
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/vite/client.js +0 -2468
- package/dist/vite/client.js.map +0 -1
- package/dist/vite/index.js +0 -697
- 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,287 +0,0 @@
|
|
|
1
|
-
# vite-plugin-opencode-assistant
|
|
2
|
-
|
|
3
|
-
一个面向 Vite 开发环境的插件:在页面内注入 OpenCode 对话挂件,自动启动 OpenCode Web,并把当前页面 URL、标题以及选中的页面节点同步给 AI,便于一边聊天一边改代码、立即通过 HMR 看到结果。
|
|
4
|
-
|
|
5
|
-
## 它能做什么
|
|
6
|
-
|
|
7
|
-
- 在 `vite serve` 时自动注入一个悬浮 AI 按钮和对话面板
|
|
8
|
-
- 自动启动本地 OpenCode Web 服务,并为当前项目复用或创建会话
|
|
9
|
-
- 把当前页面 URL、标题同步到 OpenCode 会话上下文
|
|
10
|
-
- 支持把页面上选中的节点信息同步给 AI,帮助它直接定位组件文件与行号
|
|
11
|
-
- 内置会话列表,可在挂件中切换、新建、删除当前项目的 OpenCode 会话
|
|
12
|
-
- 支持快捷键、主题、初始展开状态、悬浮位置等配置
|
|
13
|
-
- 支持启动后预热 Chrome DevTools MCP,减少首次使用浏览器工具时的等待
|
|
14
|
-
|
|
15
|
-
## 工作方式
|
|
16
|
-
|
|
17
|
-
启动 Vite 开发服务器后,插件会做这几件事:
|
|
18
|
-
|
|
19
|
-
1. 在 HTML 中注入浏览器端挂件脚本
|
|
20
|
-
2. 检查本机是否已安装 `opencode`
|
|
21
|
-
3. 启动 OpenCode Web 服务,默认使用 `127.0.0.1:4097`
|
|
22
|
-
4. 在当前项目目录下查找已有会话;如果没有,则创建新会话
|
|
23
|
-
5. 把页面上下文通过本地接口同步给 OpenCode
|
|
24
|
-
6. 页面代码被 OpenCode 修改后,由 Vite HMR 立即刷新效果
|
|
25
|
-
|
|
26
|
-
当前实现只在开发模式生效:
|
|
27
|
-
|
|
28
|
-
- 仅在 `vite serve` 时启用
|
|
29
|
-
- `build` 阶段不会注入挂件
|
|
30
|
-
- `enabled` 默认值是 `false`,需要显式开启
|
|
31
|
-
|
|
32
|
-
## 安装
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npm install -D vite-plugin-opencode-assistant
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## 前置条件
|
|
39
|
-
|
|
40
|
-
本插件依赖本机已安装 [OpenCode](https://opencode.ai) CLI。
|
|
41
|
-
|
|
42
|
-
推荐安装方式:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
curl -fsSL https://opencode.ai/install | bash
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
也可以使用包管理器:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
npm i -g opencode-ai@latest
|
|
52
|
-
brew install anomalyco/tap/opencode
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
如果你保留默认的 `warmupChromeMcp: true`,首次启动时还会通过 `npx` 拉起 `chrome-devtools-mcp` 来预热浏览器工具链。
|
|
56
|
-
|
|
57
|
-
## 快速开始
|
|
58
|
-
|
|
59
|
-
由于当前实现默认 `enabled: false`,最小可用配置如下:
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
import { defineConfig } from "vite";
|
|
63
|
-
import opencodeAssistant from "vite-plugin-opencode-assistant";
|
|
64
|
-
|
|
65
|
-
export default defineConfig({
|
|
66
|
-
plugins: [
|
|
67
|
-
opencodeAssistant({
|
|
68
|
-
enabled: true,
|
|
69
|
-
}),
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
启动开发服务器:
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
npm run dev
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
启动后页面右下角会出现悬浮按钮,点击即可打开 OpenCode 面板。
|
|
81
|
-
|
|
82
|
-
## 推荐配置示例
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
import { defineConfig } from "vite";
|
|
86
|
-
import vue from "@vitejs/plugin-vue";
|
|
87
|
-
import opencodeAssistant from "vite-plugin-opencode-assistant";
|
|
88
|
-
|
|
89
|
-
export default defineConfig({
|
|
90
|
-
plugins: [
|
|
91
|
-
vue(),
|
|
92
|
-
opencodeAssistant({
|
|
93
|
-
enabled: true,
|
|
94
|
-
webPort: 4097,
|
|
95
|
-
hostname: "127.0.0.1",
|
|
96
|
-
position: "bottom-right",
|
|
97
|
-
theme: "auto",
|
|
98
|
-
open: false,
|
|
99
|
-
autoReload: true,
|
|
100
|
-
verbose: false,
|
|
101
|
-
hotkey: "ctrl+k",
|
|
102
|
-
warmupChromeMcp: true,
|
|
103
|
-
}),
|
|
104
|
-
],
|
|
105
|
-
});
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## 配置项
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
interface OpenCodeOptions {
|
|
112
|
-
enabled?: boolean;
|
|
113
|
-
webPort?: number;
|
|
114
|
-
hostname?: string;
|
|
115
|
-
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
116
|
-
theme?: "light" | "dark" | "auto";
|
|
117
|
-
open?: boolean;
|
|
118
|
-
autoReload?: boolean;
|
|
119
|
-
verbose?: boolean;
|
|
120
|
-
hotkey?: string;
|
|
121
|
-
warmupChromeMcp?: boolean;
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
配置说明:
|
|
126
|
-
|
|
127
|
-
| 配置项 | 默认值 | 说明 |
|
|
128
|
-
| ----------------- | ---------------- | ------------------------------------------------------------------- |
|
|
129
|
-
| `enabled` | `false` | 是否启用插件。当前版本必须手动设为 `true` 才会生效 |
|
|
130
|
-
| `webPort` | `4097` | OpenCode Web 端口。如果端口被占用,会从当前端口开始向后寻找可用端口 |
|
|
131
|
-
| `hostname` | `127.0.0.1` | OpenCode Web 绑定地址 |
|
|
132
|
-
| `position` | `"bottom-right"` | 悬浮挂件位置 |
|
|
133
|
-
| `theme` | `"auto"` | 挂件主题,`auto` 会跟随系统明暗色 |
|
|
134
|
-
| `open` | `false` | 页面初始化后是否自动展开挂件 |
|
|
135
|
-
| `autoReload` | `true` | 控制挂件侧的自动重载提示行为 |
|
|
136
|
-
| `verbose` | `false` | 是否输出更详细的插件日志 |
|
|
137
|
-
| `hotkey` | `"ctrl+k"` | 切换挂件的快捷键,macOS 下同样支持 `cmd+k` |
|
|
138
|
-
| `warmupChromeMcp` | `true` | 启动后是否预热 Chrome DevTools MCP |
|
|
139
|
-
|
|
140
|
-
## 使用说明
|
|
141
|
-
|
|
142
|
-
### 1. 打开对话挂件
|
|
143
|
-
|
|
144
|
-
- 点击页面右下角悬浮按钮
|
|
145
|
-
- 或使用默认快捷键 `Ctrl/Cmd + K`
|
|
146
|
-
|
|
147
|
-
### 2. 切换会话
|
|
148
|
-
|
|
149
|
-
挂件左侧带有当前项目的会话列表,支持:
|
|
150
|
-
|
|
151
|
-
- 查看当前项目下已有会话
|
|
152
|
-
- 新建会话
|
|
153
|
-
- 切换会话
|
|
154
|
-
- 删除会话
|
|
155
|
-
|
|
156
|
-
### 3. 同步页面上下文
|
|
157
|
-
|
|
158
|
-
挂件会自动同步以下信息:
|
|
159
|
-
|
|
160
|
-
- 当前页面 URL
|
|
161
|
-
- 当前页面标题
|
|
162
|
-
- 当前选中的页面节点
|
|
163
|
-
|
|
164
|
-
它会监听:
|
|
165
|
-
|
|
166
|
-
- `history.pushState`
|
|
167
|
-
- `history.replaceState`
|
|
168
|
-
- `popstate`
|
|
169
|
-
- `hashchange`
|
|
170
|
-
- `document.title` 变化
|
|
171
|
-
|
|
172
|
-
这意味着在 SPA 场景下切页后,上下文也会自动更新。
|
|
173
|
-
|
|
174
|
-
### 4. 选择页面节点
|
|
175
|
-
|
|
176
|
-
当前实现支持把页面节点作为上下文传给 AI,节点信息包括:
|
|
177
|
-
|
|
178
|
-
- 源文件路径
|
|
179
|
-
- 行号和列号
|
|
180
|
-
- 节点文本
|
|
181
|
-
- 节点描述
|
|
182
|
-
|
|
183
|
-
默认通过 `Ctrl/Cmd + P` 进入选择模式。
|
|
184
|
-
|
|
185
|
-
需要注意:
|
|
186
|
-
|
|
187
|
-
- 这项能力依赖页面中可用的 Vue Inspector 钩子
|
|
188
|
-
- 如果页面中没有可用的 Inspector,挂件会提示“Vue Inspector 未加载,无法使用元素选择功能”
|
|
189
|
-
- 选中的节点会暂存在 `sessionStorage` 中
|
|
190
|
-
|
|
191
|
-
## 浏览器端全局 API
|
|
192
|
-
|
|
193
|
-
挂件会暴露一个全局对象:
|
|
194
|
-
|
|
195
|
-
```js
|
|
196
|
-
window.OpenCodeWidget.open();
|
|
197
|
-
window.OpenCodeWidget.close();
|
|
198
|
-
window.OpenCodeWidget.toggle();
|
|
199
|
-
window.OpenCodeWidget.showNotification("Code updated!");
|
|
200
|
-
window.OpenCodeWidget.updateContext();
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
适用场景:
|
|
204
|
-
|
|
205
|
-
- 从你自己的调试面板中主动打开挂件
|
|
206
|
-
- 在页面状态发生重要变化后手动触发一次上下文同步
|
|
207
|
-
- 在自定义流程中复用现有的通知能力
|
|
208
|
-
|
|
209
|
-
## 本地接口
|
|
210
|
-
|
|
211
|
-
插件会在 Vite 开发服务器上挂出几个内部接口,供挂件与 OpenCode 协作使用:
|
|
212
|
-
|
|
213
|
-
| 路径 | 说明 |
|
|
214
|
-
| ------------------------- | ------------------------------------------ |
|
|
215
|
-
| `/__opencode_widget__.js` | 浏览器端挂件脚本 |
|
|
216
|
-
| `/__opencode_start__` | 返回当前服务启动状态与会话地址 |
|
|
217
|
-
| `/__opencode_context__` | 读写页面上下文、清空已选节点 |
|
|
218
|
-
| `/__opencode_sessions__` | 查询、创建、删除 OpenCode 会话 |
|
|
219
|
-
| `/__opencode_events__` | SSE 事件流,用于同步会话就绪和节点清空事件 |
|
|
220
|
-
|
|
221
|
-
这些接口是插件内部实现细节,通常不需要业务代码直接调用。
|
|
222
|
-
|
|
223
|
-
## 常见问题
|
|
224
|
-
|
|
225
|
-
### OpenCode not installed
|
|
226
|
-
|
|
227
|
-
如果控制台提示未安装 OpenCode,先确认命令行里可以正常执行:
|
|
228
|
-
|
|
229
|
-
```bash
|
|
230
|
-
opencode --version
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
若无法执行,请先完成 OpenCode CLI 安装。
|
|
234
|
-
|
|
235
|
-
### 端口冲突
|
|
236
|
-
|
|
237
|
-
当前实现只开放了 `webPort` 配置项,没有单独暴露 server 端口配置。
|
|
238
|
-
|
|
239
|
-
如果默认端口被占用,可以改成:
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
opencodeAssistant({
|
|
243
|
-
enabled: true,
|
|
244
|
-
webPort: 5001,
|
|
245
|
-
});
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
如果你不改配置,插件也会从 `webPort` 开始继续向后寻找可用端口。
|
|
249
|
-
|
|
250
|
-
### 页面里没有节点选择能力
|
|
251
|
-
|
|
252
|
-
这通常意味着当前页面里没有可用的 Vue Inspector 钩子。挂件仍然可以正常聊天和同步 URL/标题,只是无法通过页面点选节点来辅助定位代码。
|
|
253
|
-
|
|
254
|
-
### 构建产物里为什么没有挂件
|
|
255
|
-
|
|
256
|
-
这是当前实现的预期行为。插件只在开发服务器模式下工作,不会影响生产构建结果。
|
|
257
|
-
|
|
258
|
-
## 示例项目
|
|
259
|
-
|
|
260
|
-
仓库自带了一个 `example` 工作区用于本地联调。
|
|
261
|
-
|
|
262
|
-
由于示例直接引用 `../dist/vite/index`,请先在仓库根目录构建插件:
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
npm install
|
|
266
|
-
npm run build
|
|
267
|
-
cd example
|
|
268
|
-
npm install
|
|
269
|
-
npm run dev
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## 开发
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
|
-
npm run build
|
|
276
|
-
npm test
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## License
|
|
280
|
-
|
|
281
|
-
MIT
|
|
282
|
-
|
|
283
|
-
## 相关链接
|
|
284
|
-
|
|
285
|
-
- [OpenCode](https://opencode.ai)
|
|
286
|
-
- [OpenCode GitHub](https://github.com/opencode-ai/opencode)
|
|
287
|
-
- [Vite Plugin API](https://vite.dev/guide/api-plugin.html)
|
package/dist/constants.d.ts
DELETED
|
@@ -1,74 +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 = 300000;
|
|
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
|
-
warmupChromeMcp: boolean;
|
|
74
|
-
};
|
package/dist/constants.js
DELETED
|
@@ -1,75 +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 = 300000;
|
|
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: false,
|
|
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
|
-
warmupChromeMcp: true,
|
|
74
|
-
};
|
|
75
|
-
//# 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,CAAC;AAE5C,kBAAkB;AAClB,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,oBAAoB;AACpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE3C,kBAAkB;AAClB,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC,eAAe;AACf,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,qDAAqD;AAErD,eAAe;AACf,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAEnD,wBAAwB;AACxB,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAE/C,0BAA0B;AAC1B,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEvD,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAE5D,cAAc;AACd,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEvD,iBAAiB;AACjB,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAEpD,kBAAkB;AAClB,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D,gBAAgB;AAChB,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAEtD,kBAAkB;AAClB,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,kBAAkB;AAClB,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAEzC,6BAA6B;AAC7B,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,iBAAiB;AACjB,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC;AAEpC,iBAAiB;AACjB,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C,qDAAqD;AAErD,YAAY;AACZ,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAEtD,cAAc;AACd,MAAM,CAAC,MAAM,qBAAqB,GAAG,gCAAgC,CAAC;AAEtE,qDAAqD;AAErD,iBAAiB;AACjB,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC,cAAc;AACd,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC,qDAAqD;AAErD,aAAa;AACb,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,KAAK;IACd,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;IAChB,eAAe,EAAE,IAAI;CACtB,CAAC","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 = 300000;\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: false,\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 warmupChromeMcp: true,\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 {};
|