vite-plugin-opencode-assistant 1.1.24 → 1.1.26
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-chrome.d.ts +43 -0
- package/es/core/mcp-chrome.mjs +147 -0
- 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.mjs +7 -2
- package/es/endpoints/index.d.ts +4 -2
- package/es/endpoints/index.mjs +4 -1
- package/es/endpoints/mcp-tools.d.ts +17 -0
- package/es/endpoints/mcp-tools.mjs +519 -0
- package/es/endpoints/mcp.d.ts +6 -0
- package/es/endpoints/mcp.mjs +290 -0
- package/es/index.mjs +71 -66
- package/lib/client.js +564 -563
- package/lib/core/mcp-chrome.cjs +174 -0
- package/lib/core/mcp-chrome.d.ts +43 -0
- 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 +7 -2
- package/lib/endpoints/index.cjs +5 -1
- package/lib/endpoints/index.d.ts +4 -2
- package/lib/endpoints/mcp-tools.cjs +541 -0
- package/lib/endpoints/mcp-tools.d.ts +17 -0
- package/lib/endpoints/mcp.cjs +307 -0
- package/lib/endpoints/mcp.d.ts +6 -0
- package/lib/index.cjs +71 -66
- package/package.json +6 -5
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
import { MCP_API_PATH } from "@vite-plugin-opencode-assistant/shared";
|
|
38
|
+
import { createLogger } from "@vite-plugin-opencode-assistant/shared/node";
|
|
39
|
+
import {
|
|
40
|
+
parseListPages,
|
|
41
|
+
resolveChromePageId,
|
|
42
|
+
getProjectOrigins,
|
|
43
|
+
isProjectPage
|
|
44
|
+
} from "../core/mcp-chrome.mjs";
|
|
45
|
+
import { CUSTOM_TOOLS, TOOL_MAP } from "./mcp-tools.mjs";
|
|
46
|
+
const log = createLogger("McpEndpoint");
|
|
47
|
+
function setupMcpEndpoint(server, mcp, getPageContext) {
|
|
48
|
+
server.middlewares.use((req, res, next) => __async(null, null, function* () {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
if (!((_a = req.url) == null ? void 0 : _a.startsWith(MCP_API_PATH))) return next();
|
|
51
|
+
const url = new URL(req.url, `http://localhost`);
|
|
52
|
+
const token = (_c = url.searchParams.get("token")) != null ? _c : (_b = req.headers["authorization"]) == null ? void 0 : _b.replace(/^Bearer /i, "");
|
|
53
|
+
if (token !== mcp.accessToken) {
|
|
54
|
+
sendMcpJson(res, 401, { error: "Unauthorized" });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
58
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
|
59
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Mcp-Session-Id, Authorization");
|
|
60
|
+
res.setHeader("Access-Control-Expose-Headers", "Mcp-Session-Id");
|
|
61
|
+
if (req.method === "OPTIONS") {
|
|
62
|
+
res.writeHead(204);
|
|
63
|
+
res.end();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (req.method === "GET") {
|
|
67
|
+
handleGetSse(req, res, mcp);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (req.method === "DELETE") {
|
|
71
|
+
res.writeHead(200);
|
|
72
|
+
res.end();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (req.method === "POST") {
|
|
76
|
+
yield handlePost(req, res, mcp, getProjectOrigins(server), getPageContext);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
next();
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
function handleGetSse(req, res, mcp) {
|
|
83
|
+
res.writeHead(200, {
|
|
84
|
+
"Content-Type": "text/event-stream",
|
|
85
|
+
"Cache-Control": "no-cache",
|
|
86
|
+
Connection: "keep-alive",
|
|
87
|
+
"Mcp-Session-Id": mcp.sessionId
|
|
88
|
+
});
|
|
89
|
+
res.write(":ok\n\n");
|
|
90
|
+
const keepAlive = setInterval(() => res.write(":ping\n\n"), 15e3);
|
|
91
|
+
req.on("close", () => clearInterval(keepAlive));
|
|
92
|
+
}
|
|
93
|
+
function handlePost(req, res, mcp, projectOrigins, getPageContext) {
|
|
94
|
+
return __async(this, null, function* () {
|
|
95
|
+
try {
|
|
96
|
+
const body = yield readBody(req);
|
|
97
|
+
if (!body) {
|
|
98
|
+
res.writeHead(400);
|
|
99
|
+
res.end("Empty body");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const { method, id } = tryParseRequest(body);
|
|
103
|
+
log.debug("MCP request", { method, body: body.substring(0, 150) });
|
|
104
|
+
switch (method) {
|
|
105
|
+
case "tools/list":
|
|
106
|
+
return handleToolsList(res, id, mcp.sessionId);
|
|
107
|
+
case "tools/call":
|
|
108
|
+
return handleToolsCall(res, id, body, mcp, projectOrigins, getPageContext);
|
|
109
|
+
default:
|
|
110
|
+
return handleForward(res, body, mcp);
|
|
111
|
+
}
|
|
112
|
+
} catch (e) {
|
|
113
|
+
log.debug("MCP POST error", { error: e.message });
|
|
114
|
+
sendMcpJson(res, 500, {
|
|
115
|
+
jsonrpc: "2.0",
|
|
116
|
+
error: { code: -32603, message: e.message }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function handleToolsList(res, id, sessionId) {
|
|
122
|
+
sendMcpJson(res, 200, { jsonrpc: "2.0", id, result: { tools: CUSTOM_TOOLS } }, sessionId);
|
|
123
|
+
}
|
|
124
|
+
function handleToolsCall(res, id, body, mcp, projectOrigins, getPageContext) {
|
|
125
|
+
const params = tryParseParams(body);
|
|
126
|
+
const toolName = params == null ? void 0 : params.name;
|
|
127
|
+
const mapped = toolName != null ? TOOL_MAP[toolName] : void 0;
|
|
128
|
+
if (!mapped) {
|
|
129
|
+
sendMcpError(res, id, -32601, `Tool not found: ${toolName}`, mcp.sessionId);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
switch (toolName) {
|
|
133
|
+
case "devtools_list_pages":
|
|
134
|
+
return handleListPages(res, id, mcp, projectOrigins, getPageContext);
|
|
135
|
+
default:
|
|
136
|
+
return handleDevTool(res, id, mcp, mapped, (params == null ? void 0 : params.arguments) || {}, projectOrigins);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function handleListPages(res, id, mcp, projectOrigins, getPageContext) {
|
|
140
|
+
return __async(this, null, function* () {
|
|
141
|
+
var _a, _b, _c, _d;
|
|
142
|
+
const listResult = yield mcp.callChromeDevTool("list_pages", {});
|
|
143
|
+
const text = (_c = (_b = (_a = listResult == null ? void 0 : listResult.result) == null ? void 0 : _a.content) == null ? void 0 : _b[0]) == null ? void 0 : _c.text;
|
|
144
|
+
const allPages = text ? parseListPages(text) : [];
|
|
145
|
+
log.debug("Chrome pages", { total: allPages.length, urls: allPages.map((p) => p.url) });
|
|
146
|
+
log.debug("project origins", { origins: projectOrigins });
|
|
147
|
+
const filtered = allPages.filter((p) => isProjectPage(p.url, projectOrigins));
|
|
148
|
+
log.debug("filtered pages", { count: filtered.length, pageIds: filtered.map((p) => p.pageId) });
|
|
149
|
+
if (filtered.length === 0) {
|
|
150
|
+
sendMcpResult(res, id, "\u6682\u65E0\u9879\u76EE\u9875\u9762\uFF0C\u8BF7\u5148\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00\u672C\u5730\u5F00\u53D1\u9875\u9762", mcp.sessionId);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const pc = getPageContext();
|
|
154
|
+
const chromeSelectedPageId = (_d = allPages.find((p) => p.selected)) == null ? void 0 : _d.pageId;
|
|
155
|
+
const resolved = yield resolveChromePageId(
|
|
156
|
+
mcp,
|
|
157
|
+
pc.url,
|
|
158
|
+
pc.title,
|
|
159
|
+
projectOrigins,
|
|
160
|
+
pc.sessionId,
|
|
161
|
+
filtered,
|
|
162
|
+
chromeSelectedPageId
|
|
163
|
+
);
|
|
164
|
+
const activePageId = resolved.ok ? resolved.pageId : null;
|
|
165
|
+
const pageList = filtered.map((p) => ({
|
|
166
|
+
pageId: p.pageId,
|
|
167
|
+
url: p.url,
|
|
168
|
+
title: p.title,
|
|
169
|
+
active: activePageId != null ? p.pageId === activePageId : false,
|
|
170
|
+
selected: p.selected
|
|
171
|
+
}));
|
|
172
|
+
sendMcpResult(res, id, JSON.stringify(pageList, null, 2), mcp.sessionId);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function handleDevTool(res, id, mcp, mapped, args, projectOrigins) {
|
|
176
|
+
return __async(this, null, function* () {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
const pageId = args["pageId"];
|
|
179
|
+
if (typeof pageId !== "number") {
|
|
180
|
+
sendMcpError(
|
|
181
|
+
res,
|
|
182
|
+
id,
|
|
183
|
+
-32e3,
|
|
184
|
+
"\u7F3A\u5C11 pageId \u53C2\u6570\uFF0C\u8BF7\u5148\u8C03\u7528 devtools_list_pages \u83B7\u53D6\u53EF\u7528\u9875\u9762\u5217\u8868",
|
|
185
|
+
mcp.sessionId
|
|
186
|
+
);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const checkResult = yield mcp.callChromeDevTool("list_pages", {});
|
|
190
|
+
const checkText = (_c = (_b = (_a = checkResult == null ? void 0 : checkResult.result) == null ? void 0 : _a.content) == null ? void 0 : _b[0]) == null ? void 0 : _c.text;
|
|
191
|
+
const checkPages = checkText ? parseListPages(checkText) : [];
|
|
192
|
+
const projectPages = checkPages.filter((p) => isProjectPage(p.url, projectOrigins));
|
|
193
|
+
const isValid = projectPages.some((p) => p.pageId === pageId);
|
|
194
|
+
log.debug("handleDevTool validation", {
|
|
195
|
+
pageId,
|
|
196
|
+
totalChromePages: checkPages.length,
|
|
197
|
+
projectPages: projectPages.length,
|
|
198
|
+
projectPageIds: projectPages.map((p) => p.pageId),
|
|
199
|
+
origins: projectOrigins,
|
|
200
|
+
isValid
|
|
201
|
+
});
|
|
202
|
+
if (!isValid) {
|
|
203
|
+
sendMcpError(res, id, -32e3, "pageId \u65E0\u6548\u6216\u975E\u9879\u76EE\u9875\u9762", mcp.sessionId);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
yield mcp.callChromeDevTool("select_page", { pageId, bringToFront: false });
|
|
207
|
+
const forwardArgs = __spreadValues({}, args);
|
|
208
|
+
delete forwardArgs["pageId"];
|
|
209
|
+
const forwardBody = JSON.stringify({
|
|
210
|
+
jsonrpc: "2.0",
|
|
211
|
+
id,
|
|
212
|
+
method: "tools/call",
|
|
213
|
+
params: { name: mapped, arguments: forwardArgs }
|
|
214
|
+
});
|
|
215
|
+
const responseText = yield mcp.forward(forwardBody);
|
|
216
|
+
log.debug("MCP response", { mapped, response: responseText.substring(0, 100) });
|
|
217
|
+
sendMcpJson(res, 200, responseText, mcp.sessionId);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function handleForward(res, body, mcp) {
|
|
221
|
+
return __async(this, null, function* () {
|
|
222
|
+
const responseText = yield mcp.forward(body);
|
|
223
|
+
sendMcpJson(res, 200, responseText, mcp.sessionId);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function sendMcpResult(res, id, text, sessionId) {
|
|
227
|
+
sendMcpJson(
|
|
228
|
+
res,
|
|
229
|
+
200,
|
|
230
|
+
{
|
|
231
|
+
jsonrpc: "2.0",
|
|
232
|
+
id,
|
|
233
|
+
result: { content: [{ type: "text", text }] }
|
|
234
|
+
},
|
|
235
|
+
sessionId
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
function sendMcpError(res, id, code, message, sessionId) {
|
|
239
|
+
sendMcpJson(
|
|
240
|
+
res,
|
|
241
|
+
200,
|
|
242
|
+
{
|
|
243
|
+
jsonrpc: "2.0",
|
|
244
|
+
id,
|
|
245
|
+
error: { code, message }
|
|
246
|
+
},
|
|
247
|
+
sessionId
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
function sendMcpJson(res, statusCode, body, sessionId) {
|
|
251
|
+
const headers = { "Content-Type": "application/json" };
|
|
252
|
+
if (sessionId) headers["Mcp-Session-Id"] = sessionId;
|
|
253
|
+
res.writeHead(statusCode, headers);
|
|
254
|
+
res.end(typeof body === "string" ? body : JSON.stringify(body));
|
|
255
|
+
}
|
|
256
|
+
function readBody(req, maxSize = 1024 * 1024) {
|
|
257
|
+
return new Promise((resolve, reject) => {
|
|
258
|
+
let body = "";
|
|
259
|
+
req.on("data", (chunk) => {
|
|
260
|
+
body += chunk.toString();
|
|
261
|
+
if (body.length > maxSize) {
|
|
262
|
+
req.destroy();
|
|
263
|
+
reject(new Error("Request body too large"));
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
req.on("end", () => resolve(body));
|
|
267
|
+
req.on("error", reject);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function tryParseRequest(body) {
|
|
271
|
+
var _a;
|
|
272
|
+
try {
|
|
273
|
+
const data = JSON.parse(body);
|
|
274
|
+
return { method: data.method || "unknown", id: (_a = data.id) != null ? _a : null };
|
|
275
|
+
} catch (e) {
|
|
276
|
+
return { method: "unknown", id: null };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function tryParseParams(body) {
|
|
280
|
+
var _a;
|
|
281
|
+
try {
|
|
282
|
+
return (_a = JSON.parse(body).params) != null ? _a : null;
|
|
283
|
+
} catch (e) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
MCP_API_PATH,
|
|
289
|
+
setupMcpEndpoint
|
|
290
|
+
};
|
package/es/index.mjs
CHANGED
|
@@ -47,7 +47,9 @@ import { setupMiddlewares, LOGS_API_PATH } from "./endpoints/index.mjs";
|
|
|
47
47
|
import { injectWidget } from "./core/injector.mjs";
|
|
48
48
|
import { OpenCodeAPI } from "./core/api.mjs";
|
|
49
49
|
import { OpenCodeService } from "./core/service.mjs";
|
|
50
|
+
import { McpProxy } from "./core/mcp-proxy.mjs";
|
|
50
51
|
import { resolveWidgetPath, resolveWidgetStylePath } from "./utils/paths.mjs";
|
|
52
|
+
import { findGitRoot } from "./utils/system.mjs";
|
|
51
53
|
function opencodePlugin(options = {}) {
|
|
52
54
|
const plugins = [];
|
|
53
55
|
plugins.push(
|
|
@@ -75,6 +77,7 @@ function createOpenCodePlugin(options = {}) {
|
|
|
75
77
|
let activeTabId = DEFAULT_TAB;
|
|
76
78
|
const serviceInstanceId = crypto.randomUUID();
|
|
77
79
|
const sseClients = /* @__PURE__ */ new Set();
|
|
80
|
+
const mcpProxy = new McpProxy();
|
|
78
81
|
const api = new OpenCodeAPI(
|
|
79
82
|
config.hostname,
|
|
80
83
|
() => actualWebPort,
|
|
@@ -93,6 +96,7 @@ function createOpenCodePlugin(options = {}) {
|
|
|
93
96
|
actualProxyPort = port;
|
|
94
97
|
}
|
|
95
98
|
);
|
|
99
|
+
service.workspaceRoot = findGitRoot(process.cwd());
|
|
96
100
|
return {
|
|
97
101
|
name: "vite-plugin-opencode",
|
|
98
102
|
apply(_viteConfig, env) {
|
|
@@ -106,56 +110,60 @@ function createOpenCodePlugin(options = {}) {
|
|
|
106
110
|
projectRoot = server.config.root;
|
|
107
111
|
let viteOrigin = "";
|
|
108
112
|
const getViteOrigin = () => viteOrigin;
|
|
109
|
-
setupMiddlewares(
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
setupMiddlewares(
|
|
114
|
+
server,
|
|
115
|
+
{
|
|
116
|
+
get webUrl() {
|
|
117
|
+
return actualWebPort ? `http://${config.hostname}:${actualWebPort}` : null;
|
|
118
|
+
},
|
|
119
|
+
get sseClients() {
|
|
120
|
+
return sseClients;
|
|
121
|
+
},
|
|
122
|
+
getPageContext() {
|
|
123
|
+
return pageContexts.get(activeTabId) || pageContexts.get(DEFAULT_TAB) || { url: "", title: "" };
|
|
124
|
+
},
|
|
125
|
+
setPageContext(tabId, ctx) {
|
|
126
|
+
pageContexts.set(tabId || DEFAULT_TAB, ctx);
|
|
127
|
+
},
|
|
128
|
+
setActiveTabId(tabId) {
|
|
129
|
+
activeTabId = tabId;
|
|
130
|
+
},
|
|
131
|
+
clearSelectedElements() {
|
|
132
|
+
const ctx = pageContexts.get(activeTabId);
|
|
133
|
+
if (ctx) {
|
|
134
|
+
ctx.selectedElements = [];
|
|
135
|
+
pageContexts.set(activeTabId, ctx);
|
|
136
|
+
}
|
|
137
|
+
const defaultCtx = pageContexts.get(DEFAULT_TAB);
|
|
138
|
+
if (defaultCtx) {
|
|
139
|
+
defaultCtx.selectedElements = [];
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
get isServiceStarted() {
|
|
143
|
+
return service.isStarted;
|
|
144
|
+
},
|
|
145
|
+
get currentTask() {
|
|
146
|
+
return service.currentTask;
|
|
147
|
+
},
|
|
148
|
+
get actualProxyPort() {
|
|
149
|
+
return actualProxyPort;
|
|
150
|
+
},
|
|
151
|
+
get actualWebPort() {
|
|
152
|
+
return actualWebPort;
|
|
153
|
+
},
|
|
154
|
+
get serviceInstanceId() {
|
|
155
|
+
return serviceInstanceId;
|
|
156
|
+
},
|
|
157
|
+
getSessions: () => api.getSessions(service.workspaceRoot),
|
|
158
|
+
createSession: () => api.createSession(service.workspaceRoot),
|
|
159
|
+
deleteSession: (id) => api.deleteSession(id),
|
|
160
|
+
resolveWidgetPath,
|
|
161
|
+
resolveWidgetStylePath,
|
|
162
|
+
getAvailableModels: () => service.getAvailableModels(),
|
|
163
|
+
retryWarmupChromeMcp: (selectedModel) => service.retryWarmupChromeMcp(getViteOrigin(), selectedModel)
|
|
112
164
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
116
|
-
getPageContext() {
|
|
117
|
-
return pageContexts.get(activeTabId) || pageContexts.get(DEFAULT_TAB) || { url: "", title: "" };
|
|
118
|
-
},
|
|
119
|
-
setPageContext(tabId, ctx) {
|
|
120
|
-
pageContexts.set(tabId || DEFAULT_TAB, ctx);
|
|
121
|
-
},
|
|
122
|
-
setActiveTabId(tabId) {
|
|
123
|
-
activeTabId = tabId;
|
|
124
|
-
},
|
|
125
|
-
clearSelectedElements() {
|
|
126
|
-
const ctx = pageContexts.get(activeTabId);
|
|
127
|
-
if (ctx) {
|
|
128
|
-
ctx.selectedElements = [];
|
|
129
|
-
pageContexts.set(activeTabId, ctx);
|
|
130
|
-
}
|
|
131
|
-
const defaultCtx = pageContexts.get(DEFAULT_TAB);
|
|
132
|
-
if (defaultCtx) {
|
|
133
|
-
defaultCtx.selectedElements = [];
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
get isServiceStarted() {
|
|
137
|
-
return service.isStarted;
|
|
138
|
-
},
|
|
139
|
-
get currentTask() {
|
|
140
|
-
return service.currentTask;
|
|
141
|
-
},
|
|
142
|
-
get actualProxyPort() {
|
|
143
|
-
return actualProxyPort;
|
|
144
|
-
},
|
|
145
|
-
get actualWebPort() {
|
|
146
|
-
return actualWebPort;
|
|
147
|
-
},
|
|
148
|
-
get serviceInstanceId() {
|
|
149
|
-
return serviceInstanceId;
|
|
150
|
-
},
|
|
151
|
-
getSessions: () => api.getSessions(service.workspaceRoot),
|
|
152
|
-
createSession: () => api.createSession(service.workspaceRoot),
|
|
153
|
-
deleteSession: (id) => api.deleteSession(id),
|
|
154
|
-
resolveWidgetPath,
|
|
155
|
-
resolveWidgetStylePath,
|
|
156
|
-
getAvailableModels: () => service.getAvailableModels(),
|
|
157
|
-
retryWarmupChromeMcp: (selectedModel) => service.retryWarmupChromeMcp(getViteOrigin(), selectedModel)
|
|
158
|
-
});
|
|
165
|
+
mcpProxy
|
|
166
|
+
);
|
|
159
167
|
(_a2 = server.httpServer) == null ? void 0 : _a2.on("listening", () => __async(null, null, function* () {
|
|
160
168
|
var _a3;
|
|
161
169
|
log.debug("Vite server listening event fired");
|
|
@@ -186,7 +194,16 @@ function createOpenCodePlugin(options = {}) {
|
|
|
186
194
|
logsApiUrl
|
|
187
195
|
});
|
|
188
196
|
try {
|
|
189
|
-
yield
|
|
197
|
+
yield mcpProxy.start();
|
|
198
|
+
yield service.start(
|
|
199
|
+
mcpProxy.accessToken,
|
|
200
|
+
vitePort,
|
|
201
|
+
[viteOrigin],
|
|
202
|
+
contextApiUrl,
|
|
203
|
+
logsApiUrl,
|
|
204
|
+
viteOrigin,
|
|
205
|
+
mcpProxy
|
|
206
|
+
);
|
|
190
207
|
} catch (e) {
|
|
191
208
|
log.error("Failed to start services", { error: e });
|
|
192
209
|
}
|
|
@@ -194,9 +211,11 @@ function createOpenCodePlugin(options = {}) {
|
|
|
194
211
|
(_b2 = server.httpServer) == null ? void 0 : _b2.on("close", () => {
|
|
195
212
|
log.debug("HTTP server closing");
|
|
196
213
|
service.stop();
|
|
214
|
+
mcpProxy.stop();
|
|
197
215
|
});
|
|
198
216
|
const cleanup = () => __async(null, null, function* () {
|
|
199
217
|
log.debug("Process cleanup triggered");
|
|
218
|
+
mcpProxy.stop();
|
|
200
219
|
yield service.stop();
|
|
201
220
|
process.exit(0);
|
|
202
221
|
});
|
|
@@ -223,23 +242,9 @@ function createOpenCodePlugin(options = {}) {
|
|
|
223
242
|
const titleInject = `<script>
|
|
224
243
|
(function () {
|
|
225
244
|
var KEY = "_opencode_pk";
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
prefix = "[" + Math.random().toString(36).slice(2, 5) + "]";
|
|
229
|
-
sessionStorage.setItem(KEY, prefix);
|
|
230
|
-
}
|
|
231
|
-
var applied = false;
|
|
232
|
-
function apply() {
|
|
233
|
-
if (applied) return;
|
|
234
|
-
var title = document.title;
|
|
235
|
-
if (title.indexOf(prefix) === 0) return;
|
|
236
|
-
applied = true;
|
|
237
|
-
document.title = prefix + title.replace(prefix, "");
|
|
238
|
-
applied = false;
|
|
245
|
+
if (!sessionStorage.getItem(KEY)) {
|
|
246
|
+
sessionStorage.setItem(KEY, "[" + Math.random().toString(36).slice(2, 5) + "]");
|
|
239
247
|
}
|
|
240
|
-
apply();
|
|
241
|
-
var target = document.querySelector("title") || document.head;
|
|
242
|
-
new MutationObserver(apply).observe(target, { childList: true });
|
|
243
248
|
})();
|
|
244
249
|
</script>`;
|
|
245
250
|
timer.end();
|