vite-plugin-opencode-assistant 1.1.24 → 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/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(server, {
110
- get webUrl() {
111
- return actualWebPort ? `http://${config.hostname}:${actualWebPort}` : null;
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
- get sseClients() {
114
- return sseClients;
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 service.start([viteOrigin], contextApiUrl, logsApiUrl, viteOrigin);
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
- var prefix = sessionStorage.getItem(KEY);
227
- if (!prefix) {
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();