vite-plugin-opencode-assistant 1.1.23 → 1.1.25
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/core/mcp-proxy.d.ts +21 -0
- package/es/core/mcp-proxy.mjs +254 -0
- package/es/core/opencode-web.d.ts +1 -1
- package/es/core/opencode-web.mjs +4 -4
- package/es/core/service.d.ts +2 -1
- package/es/core/service.mjs +4 -3
- package/es/endpoints/context.d.ts +35 -0
- package/es/endpoints/context.mjs +126 -2
- package/es/endpoints/index.d.ts +4 -2
- package/es/endpoints/index.mjs +4 -1
- package/es/endpoints/mcp-tools.d.ts +16 -0
- package/es/endpoints/mcp-tools.mjs +325 -0
- package/es/endpoints/mcp.d.ts +6 -0
- package/es/endpoints/mcp.mjs +259 -0
- package/es/index.mjs +71 -66
- package/lib/client.js +564 -563
- package/lib/core/mcp-proxy.cjs +286 -0
- package/lib/core/mcp-proxy.d.ts +21 -0
- package/lib/core/opencode-web.cjs +4 -4
- package/lib/core/opencode-web.d.ts +1 -1
- package/lib/core/service.cjs +4 -3
- package/lib/core/service.d.ts +2 -1
- package/lib/endpoints/context.cjs +130 -2
- package/lib/endpoints/context.d.ts +35 -0
- package/lib/endpoints/index.cjs +5 -1
- package/lib/endpoints/index.d.ts +4 -2
- package/lib/endpoints/mcp-tools.cjs +349 -0
- package/lib/endpoints/mcp-tools.d.ts +16 -0
- package/lib/endpoints/mcp.cjs +283 -0
- package/lib/endpoints/mcp.d.ts +6 -0
- package/lib/index.cjs +71 -66
- package/package.json +6 -5
package/lib/index.cjs
CHANGED
|
@@ -72,7 +72,9 @@ var import_endpoints = require("./endpoints/index.cjs");
|
|
|
72
72
|
var import_injector = require("./core/injector.cjs");
|
|
73
73
|
var import_api = require("./core/api.cjs");
|
|
74
74
|
var import_service = require("./core/service.cjs");
|
|
75
|
+
var import_mcp_proxy = require("./core/mcp-proxy.cjs");
|
|
75
76
|
var import_paths = require("./utils/paths.cjs");
|
|
77
|
+
var import_system = require("./utils/system.cjs");
|
|
76
78
|
function opencodePlugin(options = {}) {
|
|
77
79
|
const plugins = [];
|
|
78
80
|
plugins.push(
|
|
@@ -100,6 +102,7 @@ function createOpenCodePlugin(options = {}) {
|
|
|
100
102
|
let activeTabId = DEFAULT_TAB;
|
|
101
103
|
const serviceInstanceId = import_crypto.default.randomUUID();
|
|
102
104
|
const sseClients = /* @__PURE__ */ new Set();
|
|
105
|
+
const mcpProxy = new import_mcp_proxy.McpProxy();
|
|
103
106
|
const api = new import_api.OpenCodeAPI(
|
|
104
107
|
config.hostname,
|
|
105
108
|
() => actualWebPort,
|
|
@@ -118,6 +121,7 @@ function createOpenCodePlugin(options = {}) {
|
|
|
118
121
|
actualProxyPort = port;
|
|
119
122
|
}
|
|
120
123
|
);
|
|
124
|
+
service.workspaceRoot = (0, import_system.findGitRoot)(process.cwd());
|
|
121
125
|
return {
|
|
122
126
|
name: "vite-plugin-opencode",
|
|
123
127
|
apply(_viteConfig, env) {
|
|
@@ -131,56 +135,60 @@ function createOpenCodePlugin(options = {}) {
|
|
|
131
135
|
projectRoot = server.config.root;
|
|
132
136
|
let viteOrigin = "";
|
|
133
137
|
const getViteOrigin = () => viteOrigin;
|
|
134
|
-
(0, import_endpoints.setupMiddlewares)(
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
(0, import_endpoints.setupMiddlewares)(
|
|
139
|
+
server,
|
|
140
|
+
{
|
|
141
|
+
get webUrl() {
|
|
142
|
+
return actualWebPort ? `http://${config.hostname}:${actualWebPort}` : null;
|
|
143
|
+
},
|
|
144
|
+
get sseClients() {
|
|
145
|
+
return sseClients;
|
|
146
|
+
},
|
|
147
|
+
getPageContext() {
|
|
148
|
+
return pageContexts.get(activeTabId) || pageContexts.get(DEFAULT_TAB) || { url: "", title: "" };
|
|
149
|
+
},
|
|
150
|
+
setPageContext(tabId, ctx) {
|
|
151
|
+
pageContexts.set(tabId || DEFAULT_TAB, ctx);
|
|
152
|
+
},
|
|
153
|
+
setActiveTabId(tabId) {
|
|
154
|
+
activeTabId = tabId;
|
|
155
|
+
},
|
|
156
|
+
clearSelectedElements() {
|
|
157
|
+
const ctx = pageContexts.get(activeTabId);
|
|
158
|
+
if (ctx) {
|
|
159
|
+
ctx.selectedElements = [];
|
|
160
|
+
pageContexts.set(activeTabId, ctx);
|
|
161
|
+
}
|
|
162
|
+
const defaultCtx = pageContexts.get(DEFAULT_TAB);
|
|
163
|
+
if (defaultCtx) {
|
|
164
|
+
defaultCtx.selectedElements = [];
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
get isServiceStarted() {
|
|
168
|
+
return service.isStarted;
|
|
169
|
+
},
|
|
170
|
+
get currentTask() {
|
|
171
|
+
return service.currentTask;
|
|
172
|
+
},
|
|
173
|
+
get actualProxyPort() {
|
|
174
|
+
return actualProxyPort;
|
|
175
|
+
},
|
|
176
|
+
get actualWebPort() {
|
|
177
|
+
return actualWebPort;
|
|
178
|
+
},
|
|
179
|
+
get serviceInstanceId() {
|
|
180
|
+
return serviceInstanceId;
|
|
181
|
+
},
|
|
182
|
+
getSessions: () => api.getSessions(service.workspaceRoot),
|
|
183
|
+
createSession: () => api.createSession(service.workspaceRoot),
|
|
184
|
+
deleteSession: (id) => api.deleteSession(id),
|
|
185
|
+
resolveWidgetPath: import_paths.resolveWidgetPath,
|
|
186
|
+
resolveWidgetStylePath: import_paths.resolveWidgetStylePath,
|
|
187
|
+
getAvailableModels: () => service.getAvailableModels(),
|
|
188
|
+
retryWarmupChromeMcp: (selectedModel) => service.retryWarmupChromeMcp(getViteOrigin(), selectedModel)
|
|
137
189
|
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
getPageContext() {
|
|
142
|
-
return pageContexts.get(activeTabId) || pageContexts.get(DEFAULT_TAB) || { url: "", title: "" };
|
|
143
|
-
},
|
|
144
|
-
setPageContext(tabId, ctx) {
|
|
145
|
-
pageContexts.set(tabId || DEFAULT_TAB, ctx);
|
|
146
|
-
},
|
|
147
|
-
setActiveTabId(tabId) {
|
|
148
|
-
activeTabId = tabId;
|
|
149
|
-
},
|
|
150
|
-
clearSelectedElements() {
|
|
151
|
-
const ctx = pageContexts.get(activeTabId);
|
|
152
|
-
if (ctx) {
|
|
153
|
-
ctx.selectedElements = [];
|
|
154
|
-
pageContexts.set(activeTabId, ctx);
|
|
155
|
-
}
|
|
156
|
-
const defaultCtx = pageContexts.get(DEFAULT_TAB);
|
|
157
|
-
if (defaultCtx) {
|
|
158
|
-
defaultCtx.selectedElements = [];
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
get isServiceStarted() {
|
|
162
|
-
return service.isStarted;
|
|
163
|
-
},
|
|
164
|
-
get currentTask() {
|
|
165
|
-
return service.currentTask;
|
|
166
|
-
},
|
|
167
|
-
get actualProxyPort() {
|
|
168
|
-
return actualProxyPort;
|
|
169
|
-
},
|
|
170
|
-
get actualWebPort() {
|
|
171
|
-
return actualWebPort;
|
|
172
|
-
},
|
|
173
|
-
get serviceInstanceId() {
|
|
174
|
-
return serviceInstanceId;
|
|
175
|
-
},
|
|
176
|
-
getSessions: () => api.getSessions(service.workspaceRoot),
|
|
177
|
-
createSession: () => api.createSession(service.workspaceRoot),
|
|
178
|
-
deleteSession: (id) => api.deleteSession(id),
|
|
179
|
-
resolveWidgetPath: import_paths.resolveWidgetPath,
|
|
180
|
-
resolveWidgetStylePath: import_paths.resolveWidgetStylePath,
|
|
181
|
-
getAvailableModels: () => service.getAvailableModels(),
|
|
182
|
-
retryWarmupChromeMcp: (selectedModel) => service.retryWarmupChromeMcp(getViteOrigin(), selectedModel)
|
|
183
|
-
});
|
|
190
|
+
mcpProxy
|
|
191
|
+
);
|
|
184
192
|
(_a2 = server.httpServer) == null ? void 0 : _a2.on("listening", () => __async(null, null, function* () {
|
|
185
193
|
var _a3;
|
|
186
194
|
log.debug("Vite server listening event fired");
|
|
@@ -211,7 +219,16 @@ function createOpenCodePlugin(options = {}) {
|
|
|
211
219
|
logsApiUrl
|
|
212
220
|
});
|
|
213
221
|
try {
|
|
214
|
-
yield
|
|
222
|
+
yield mcpProxy.start();
|
|
223
|
+
yield service.start(
|
|
224
|
+
mcpProxy.accessToken,
|
|
225
|
+
vitePort,
|
|
226
|
+
[viteOrigin],
|
|
227
|
+
contextApiUrl,
|
|
228
|
+
logsApiUrl,
|
|
229
|
+
viteOrigin,
|
|
230
|
+
mcpProxy
|
|
231
|
+
);
|
|
215
232
|
} catch (e) {
|
|
216
233
|
log.error("Failed to start services", { error: e });
|
|
217
234
|
}
|
|
@@ -219,9 +236,11 @@ function createOpenCodePlugin(options = {}) {
|
|
|
219
236
|
(_b2 = server.httpServer) == null ? void 0 : _b2.on("close", () => {
|
|
220
237
|
log.debug("HTTP server closing");
|
|
221
238
|
service.stop();
|
|
239
|
+
mcpProxy.stop();
|
|
222
240
|
});
|
|
223
241
|
const cleanup = () => __async(null, null, function* () {
|
|
224
242
|
log.debug("Process cleanup triggered");
|
|
243
|
+
mcpProxy.stop();
|
|
225
244
|
yield service.stop();
|
|
226
245
|
process.exit(0);
|
|
227
246
|
});
|
|
@@ -248,23 +267,9 @@ function createOpenCodePlugin(options = {}) {
|
|
|
248
267
|
const titleInject = `<script>
|
|
249
268
|
(function () {
|
|
250
269
|
var KEY = "_opencode_pk";
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
prefix = "[" + Math.random().toString(36).slice(2, 5) + "]";
|
|
254
|
-
sessionStorage.setItem(KEY, prefix);
|
|
255
|
-
}
|
|
256
|
-
var applied = false;
|
|
257
|
-
function apply() {
|
|
258
|
-
if (applied) return;
|
|
259
|
-
var title = document.title;
|
|
260
|
-
if (title.indexOf(prefix) === 0) return;
|
|
261
|
-
applied = true;
|
|
262
|
-
document.title = prefix + title.replace(prefix, "");
|
|
263
|
-
applied = false;
|
|
270
|
+
if (!sessionStorage.getItem(KEY)) {
|
|
271
|
+
sessionStorage.setItem(KEY, "[" + Math.random().toString(36).slice(2, 5) + "]");
|
|
264
272
|
}
|
|
265
|
-
apply();
|
|
266
|
-
var target = document.querySelector("title") || document.head;
|
|
267
|
-
new MutationObserver(apply).observe(target, { childList: true });
|
|
268
273
|
})();
|
|
269
274
|
</script>`;
|
|
270
275
|
timer.end();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-opencode-assistant",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
4
4
|
"description": "Embed OpenCode Web UI in your Vite dev server for real-time code modification and preview",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -35,17 +35,18 @@
|
|
|
35
35
|
"author": "",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"chrome-devtools-mcp": "^1.6.0",
|
|
38
39
|
"unplugin-vue-inspector": "^3.0.0",
|
|
39
40
|
"execa": "^9.6.1",
|
|
40
|
-
"@vite-plugin-opencode-assistant/
|
|
41
|
-
"@vite-plugin-opencode-assistant/
|
|
42
|
-
"@vite-plugin-opencode-assistant/
|
|
41
|
+
"@vite-plugin-opencode-assistant/opencode": "1.1.25",
|
|
42
|
+
"@vite-plugin-opencode-assistant/shared": "1.1.25",
|
|
43
|
+
"@vite-plugin-opencode-assistant/components": "1.1.25"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"vite": ">=5.0.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@vite-plugin-opencode-assistant/client": "1.1.
|
|
49
|
+
"@vite-plugin-opencode-assistant/client": "1.1.25"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"build": "pagoda-cli build && vite build -c vite.client.config.ts",
|