vite-plugin-opencode-assistant 1.0.30 → 1.0.32

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.
@@ -456,7 +456,7 @@ function startProxyServer(targetUrl, port, options = {}) {
456
456
  server.listen(port, () => {
457
457
  const address = server.address();
458
458
  const actualPort = typeof address === "object" && address ? address.port : port;
459
- log.info(`Proxy server started on port ${actualPort} -> ${targetUrl}`);
459
+ log.debug(`Proxy server started on port ${actualPort} -> ${targetUrl}`);
460
460
  resolve({ server, actualPort });
461
461
  });
462
462
  });
@@ -25,7 +25,7 @@ export declare class OpenCodeService {
25
25
  workspaceRoot: string | null;
26
26
  constructor(config: Required<OpenCodeOptions>, api: OpenCodeAPI, sseClients: Set<http.ServerResponse>, onPortAllocated: (port: number) => void, onProxyPortAllocated: (port: number) => void);
27
27
  private sendTaskUpdate;
28
- start(corsOrigins?: string[], contextApiUrl?: string, viteOrigin?: string): Promise<void>;
28
+ start(corsOrigins?: string[], contextApiUrl?: string, logsApiUrl?: string, viteOrigin?: string): Promise<void>;
29
29
  retryWarmupChromeMcp(viteOrigin?: string): Promise<{
30
30
  success: boolean;
31
31
  errorType?: string;
@@ -94,7 +94,7 @@ class OpenCodeService {
94
94
  }
95
95
  });
96
96
  }
97
- start(corsOrigins, contextApiUrl, viteOrigin) {
97
+ start(corsOrigins, contextApiUrl, logsApiUrl, viteOrigin) {
98
98
  return __async(this, null, function* () {
99
99
  if (this.isStarted && this.webProcess) {
100
100
  log.debug("Services already started, skipping");
@@ -109,6 +109,7 @@ class OpenCodeService {
109
109
  const timer = log.timer("startServices", {
110
110
  corsOrigins,
111
111
  contextApiUrl,
112
+ logsApiUrl,
112
113
  viteOrigin
113
114
  });
114
115
  log.info("Starting OpenCode services...");
@@ -152,7 +153,7 @@ Please install OpenCode first:
152
153
  }
153
154
  timer.checkpoint("Port allocated");
154
155
  this.workspaceRoot = (0, import_system.findGitRoot)(process.cwd());
155
- log.info(`Using workspace root: ${this.workspaceRoot}`);
156
+ log.debug(`Using workspace root: ${this.workspaceRoot}`);
156
157
  this.sendTaskUpdate("preparing_runtime");
157
158
  const configDir = (0, import_opencode.prepareOpenCodeRuntime)(this.workspaceRoot);
158
159
  timer.checkpoint("Plugin setup complete");
@@ -169,11 +170,12 @@ Please install OpenCode first:
169
170
  cwd: this.workspaceRoot,
170
171
  configDir,
171
172
  corsOrigins,
172
- contextApiUrl
173
+ contextApiUrl,
174
+ logsApiUrl
173
175
  });
174
176
  timer.checkpoint("Web process started");
175
177
  const webUrl = `http://${this.config.hostname}:${this.actualWebPort}`;
176
- log.info(`Waiting for OpenCode Web to become ready at ${webUrl}...`);
178
+ log.debug(`Waiting for OpenCode Web to become ready at ${webUrl}...`);
177
179
  this.sendTaskUpdate("waiting_web_ready");
178
180
  try {
179
181
  yield (0, import_system.waitForServer)(webUrl, import_shared.SERVER_START_TIMEOUT, this.webProcess);
@@ -1,4 +1,6 @@
1
1
  import type { ViteDevServer } from "vite";
2
2
  import type { EndpointContext } from "./types.js";
3
+ import { LOGS_API_PATH } from "./logs.js";
3
4
  export * from "./types.js";
5
+ export { LOGS_API_PATH };
4
6
  export declare function setupMiddlewares(server: ViteDevServer, ctx: EndpointContext): void;
@@ -18,6 +18,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var endpoints_exports = {};
20
20
  __export(endpoints_exports, {
21
+ LOGS_API_PATH: () => import_logs.LOGS_API_PATH,
21
22
  setupMiddlewares: () => setupMiddlewares
22
23
  });
23
24
  module.exports = __toCommonJS(endpoints_exports);
@@ -27,6 +28,7 @@ var import_start = require("./start.js");
27
28
  var import_sse = require("./sse.js");
28
29
  var import_sessions = require("./sessions.js");
29
30
  var import_warmup = require("./warmup.js");
31
+ var import_logs = require("./logs.js");
30
32
  __reExport(endpoints_exports, require("./types.js"), module.exports);
31
33
  function setupMiddlewares(server, ctx) {
32
34
  (0, import_widget.setupWidgetEndpoints)(server, ctx);
@@ -35,9 +37,11 @@ function setupMiddlewares(server, ctx) {
35
37
  (0, import_sse.setupSseEndpoint)(server, ctx);
36
38
  (0, import_sessions.setupSessionsEndpoint)(server, ctx);
37
39
  (0, import_warmup.setupWarmupEndpoint)(server, ctx);
40
+ (0, import_logs.setupLogsEndpoint)(server);
38
41
  }
39
42
  // Annotate the CommonJS export names for ESM import in node:
40
43
  0 && (module.exports = {
44
+ LOGS_API_PATH,
41
45
  setupMiddlewares,
42
46
  ...require("./types.js")
43
47
  });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @fileoverview 进程日志端点
3
+ * @description 提供 HTTP API 获取 Vite 进程日志缓冲区内容
4
+ */
5
+ import type { ViteDevServer } from "vite";
6
+ /** 日志 API 路径 */
7
+ export declare const LOGS_API_PATH = "/__opencode_process_logs__";
8
+ /**
9
+ * 设置日志端点
10
+ */
11
+ export declare function setupLogsEndpoint(server: ViteDevServer): void;
@@ -0,0 +1,129 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __async = (__this, __arguments, generator) => {
19
+ return new Promise((resolve, reject) => {
20
+ var fulfilled = (value) => {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ };
27
+ var rejected = (value) => {
28
+ try {
29
+ step(generator.throw(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ };
34
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
+ step((generator = generator.apply(__this, __arguments)).next());
36
+ });
37
+ };
38
+ var logs_exports = {};
39
+ __export(logs_exports, {
40
+ LOGS_API_PATH: () => LOGS_API_PATH,
41
+ setupLogsEndpoint: () => setupLogsEndpoint
42
+ });
43
+ module.exports = __toCommonJS(logs_exports);
44
+ var import_shared = require("@vite-plugin-opencode-assistant/shared");
45
+ var import_shared2 = require("@vite-plugin-opencode-assistant/shared");
46
+ const log = (0, import_shared2.createLogger)("Endpoints:Logs");
47
+ const LOGS_API_PATH = "/__opencode_process_logs__";
48
+ function setupLogsEndpoint(server) {
49
+ server.middlewares.use(LOGS_API_PATH, (req, res) => __async(null, null, function* () {
50
+ const reqCtx = new import_shared2.RequestContext(req.method || "GET", LOGS_API_PATH);
51
+ res.setHeader("Content-Type", "application/json");
52
+ res.setHeader("Access-Control-Allow-Origin", "*");
53
+ res.setHeader("Access-Control-Allow-Methods", "GET, DELETE, OPTIONS");
54
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type");
55
+ if (req.method === "OPTIONS") {
56
+ res.writeHead(200);
57
+ res.end();
58
+ reqCtx.end(200);
59
+ return;
60
+ }
61
+ const buffer = (0, import_shared.getProcessLogBuffer)();
62
+ if (req.method === "GET") {
63
+ try {
64
+ const url = new URL(req.url || "", `http://${req.headers.host || "localhost"}`);
65
+ const levelParam = url.searchParams.get("level");
66
+ const limitParam = url.searchParams.get("limit");
67
+ const sourceParam = url.searchParams.get("source");
68
+ const sinceParam = url.searchParams.get("since");
69
+ const options = {};
70
+ if (levelParam) {
71
+ const levels = levelParam.split(",").map((l) => l.trim());
72
+ options.level = levels.length === 1 ? levels[0] : levels;
73
+ }
74
+ if (limitParam) {
75
+ const limit = parseInt(limitParam, 10);
76
+ if (limit > 0 && limit <= 1e3) {
77
+ options.limit = limit;
78
+ }
79
+ }
80
+ if (sourceParam) {
81
+ options.source = sourceParam;
82
+ }
83
+ if (sinceParam) {
84
+ options.since = sinceParam;
85
+ }
86
+ const logs = buffer.getLogs(options);
87
+ log.debug("Logs requested", {
88
+ params: { level: levelParam, limit: limitParam, source: sourceParam, since: sinceParam },
89
+ resultCount: logs.length,
90
+ bufferSize: buffer.size()
91
+ });
92
+ res.writeHead(200);
93
+ res.end(
94
+ JSON.stringify({
95
+ logs,
96
+ meta: {
97
+ total: buffer.size(),
98
+ returned: logs.length,
99
+ filters: options
100
+ }
101
+ })
102
+ );
103
+ reqCtx.end(200);
104
+ } catch (e) {
105
+ log.error("Failed to get logs", { error: e });
106
+ res.writeHead(500);
107
+ res.end(JSON.stringify({ error: "Internal server error" }));
108
+ reqCtx.error(e);
109
+ }
110
+ return;
111
+ }
112
+ if (req.method === "DELETE") {
113
+ buffer.clear();
114
+ log.info("Log buffer cleared");
115
+ res.writeHead(200);
116
+ res.end(JSON.stringify({ success: true, message: "Log buffer cleared" }));
117
+ reqCtx.end(200);
118
+ return;
119
+ }
120
+ res.writeHead(405);
121
+ res.end(JSON.stringify({ error: "Method not allowed" }));
122
+ reqCtx.end(405);
123
+ }));
124
+ }
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ LOGS_API_PATH,
128
+ setupLogsEndpoint
129
+ });
package/lib/index.js CHANGED
@@ -87,6 +87,7 @@ function createOpenCodePlugin(options = {}) {
87
87
  var _a;
88
88
  const config = __spreadValues(__spreadValues({}, import_shared.DEFAULT_CONFIG), options);
89
89
  (0, import_shared.setVerbose)(config.verbose);
90
+ (0, import_shared.initProcessLogCapture)({ maxSize: 500 });
90
91
  const log = (0, import_shared.createLogger)("Plugin");
91
92
  let actualWebPort = config.webPort;
92
93
  let actualProxyPort = (_a = config.proxyPort) != null ? _a : import_shared.DEFAULT_PROXY_PORT;
@@ -168,14 +169,16 @@ function createOpenCodePlugin(options = {}) {
168
169
  }
169
170
  viteOrigin = `http://${viteHost}:${vitePort}`;
170
171
  const contextApiUrl = `http://${viteHost}:${vitePort}${import_shared.CONTEXT_API_PATH}`;
172
+ const logsApiUrl = `http://${viteHost}:${vitePort}${import_endpoints.LOGS_API_PATH}`;
171
173
  log.debug("Vite server ready", {
172
174
  vitePort,
173
175
  viteHost,
174
176
  viteOrigin,
175
- contextApiUrl
177
+ contextApiUrl,
178
+ logsApiUrl
176
179
  });
177
180
  try {
178
- yield service.start([viteOrigin], contextApiUrl, viteOrigin);
181
+ yield service.start([viteOrigin], contextApiUrl, logsApiUrl, viteOrigin);
179
182
  } catch (e) {
180
183
  log.error("Failed to start services", { error: e });
181
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-opencode-assistant",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
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.js",
@@ -36,9 +36,9 @@
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
38
  "unplugin-vue-inspector": "^2.4.0",
39
- "@vite-plugin-opencode-assistant/opencode": "1.0.30",
40
- "@vite-plugin-opencode-assistant/shared": "1.0.30",
41
- "@vite-plugin-opencode-assistant/components": "1.0.30"
39
+ "@vite-plugin-opencode-assistant/shared": "1.0.32",
40
+ "@vite-plugin-opencode-assistant/components": "1.0.32",
41
+ "@vite-plugin-opencode-assistant/opencode": "1.0.32"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "vite": ">=4.0.0"