@vite-plugin-opencode-assistant/opencode 1.0.56 → 1.0.58

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/web.mjs CHANGED
@@ -60,21 +60,33 @@ function prepareOpenCodeRuntime(cwd) {
60
60
  }
61
61
  function startOpenCodeWeb(options) {
62
62
  var _a, _b;
63
- const { port, hostname, cwd, configDir, corsOrigins, contextApiUrl, logsApiUrl } = options;
63
+ const { port, hostname, cwd, configDir, corsOrigins, contextApiUrl, logsApiUrl, logFilesJson } = options;
64
64
  const stateDir = createStateDirectory(cwd);
65
65
  const pluginsDir = path.join(stateDir, "plugins");
66
66
  const pluginPaths = [
67
67
  path.join(pluginsDir, "page-context.js"),
68
68
  path.join(pluginsDir, "vite-logs.js")
69
- ].join(",");
69
+ ];
70
+ if (logFilesJson) {
71
+ pluginPaths.push(path.join(pluginsDir, "service-logs.js"));
72
+ }
73
+ const pluginPathsStr = pluginPaths.join(",");
70
74
  log.debug("Building process environment", {
71
75
  stateDir,
72
76
  configDir,
73
77
  contextApiUrl,
74
78
  logsApiUrl,
75
- pluginPaths
79
+ logFilesJson,
80
+ pluginPathsStr
76
81
  });
77
- const env = buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginPaths);
82
+ const env = buildProcessEnv(
83
+ stateDir,
84
+ configDir,
85
+ contextApiUrl,
86
+ logsApiUrl,
87
+ pluginPathsStr,
88
+ logFilesJson
89
+ );
78
90
  const args = ["serve", "--port", String(port), "--hostname", hostname];
79
91
  if (corsOrigins && corsOrigins.length > 0) {
80
92
  corsOrigins.forEach((origin) => {
@@ -143,7 +155,7 @@ function copyPluginFiles(sourceDir, targetDir) {
143
155
  }
144
156
  log.debug("All plugin files copied", { count: files.length, files });
145
157
  }
146
- function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginPaths) {
158
+ function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginPaths, logFilesJson) {
147
159
  const env = __spreadProps(__spreadValues({}, Object.fromEntries(
148
160
  Object.entries(process.env).filter(([, v]) => v !== void 0)
149
161
  )), {
@@ -165,6 +177,10 @@ function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginP
165
177
  env.OPENCODE_PLUGINS = pluginPaths;
166
178
  log.debug("Set OPENCODE_PLUGINS", { pluginPaths });
167
179
  }
180
+ if (logFilesJson) {
181
+ env.OPENCODE_LOG_FILES_JSON = logFilesJson;
182
+ log.debug("Set OPENCODE_LOG_FILES_JSON", { logFilesJson });
183
+ }
168
184
  return env;
169
185
  }
170
186
  export {
@@ -80,7 +80,7 @@ const PageContextPlugin = () => __async(null, null, function* () {
80
80
 
81
81
  ## \u26A0\uFE0F \u91CD\u8981\uFF1A\u9875\u9762\u4E0A\u4E0B\u6587\u4F18\u5148\u7EA7\u89C4\u5219
82
82
 
83
- **\u5F53\u7528\u6237\u5728\u4E0D\u540C\u9875\u9762\u63D0\u95EE\u65F6\uFF0C\u4F60\u5FC5\u987B\u4F18\u5148\u6839\u636E\u7528\u6237\u5F53\u524D\u6D4F\u89C8\u9875\u9762\u7684\u4E0A\u4E0B\u6587\u6765\u7406\u89E3\u95EE\u9898\uFF0C\u800C\u4E0D\u662F\u4F9D\u8D56\u4F1A\u8BDD\u5386\u53F2\u8BB0\u5F55\u3002**
83
+ **\u5F53\u7528\u6237\u5728\u4E0D\u540C\u9875\u9762\u63D0\u95EE\u65F6\uFF0C\u4F60\u5FC5\u987B\u4F18\u5148\u6839\u636E\u7528\u6237\u5F53\u524D\u6D4F\u89C8\u9875\u9762\u7684\u4E0A\u4E0B\u6587\u6765\u7406\u89E3\u95EE\u9898\uFF0C\u7981\u6B62\u4F9D\u8D56\u4F1A\u8BDD\u5386\u53F2\u8BB0\u5F55\u6216\u5176\u4ED6\u4E0A\u4E0B\u6587\u3002**
84
84
 
85
85
  \u7528\u6237\u53EF\u80FD\u5728\u4E0D\u540C\u9875\u9762\u4E4B\u95F4\u5207\u6362\uFF0C\u6BCF\u6B21\u63D0\u95EE\u90FD\u5E94\u8BE5\u57FA\u4E8E\u5F53\u524D\u9875\u9762\u4E0A\u4E0B\u6587\uFF1A
86
86
 
@@ -93,7 +93,7 @@ const PageContextPlugin = () => __async(null, null, function* () {
93
93
  1. **\u5F53\u524D\u9875\u9762\u4E0A\u4E0B\u6587**\uFF08\u6700\u9AD8\u4F18\u5148\u7EA7\uFF09 - \u6839\u636E\u7528\u6237\u5F53\u524D\u6240\u5728\u9875\u9762\u7684 URL \u548C\u6807\u9898\u7406\u89E3\u95EE\u9898\u80CC\u666F
94
94
  2. **\u7528\u6237\u9009\u4E2D\u7684\u5143\u7D20** - \u5982\u679C\u7528\u6237\u9009\u4E2D\u4E86\u9875\u9762\u5143\u7D20\uFF0C\u8FD9\u4E9B\u5143\u7D20\u4FE1\u606F\u662F\u7406\u89E3\u95EE\u9898\u7684\u5173\u952E
95
95
  3. **\u7528\u6237\u5F53\u524D\u8F93\u5165** - \u7528\u6237\u672C\u6B21\u53D1\u9001\u7684\u5177\u4F53\u95EE\u9898\u5185\u5BB9
96
- 4. **\u4F1A\u8BDD\u5386\u53F2**\uFF08\u6700\u4F4E\u4F18\u5148\u7EA7\uFF09 - \u4EC5\u4F5C\u4E3A\u8F85\u52A9\u53C2\u8003\uFF0C\u4E0D\u5E94\u4F18\u5148\u4E8E\u5F53\u524D\u9875\u9762\u4E0A\u4E0B\u6587
96
+ 4. **\u4F1A\u8BDD\u5386\u53F2**\uFF08\u6700\u4F4E\u4F18\u5148\u7EA7\uFF09 - \u4EC5\u4F5C\u4E3A\u8F85\u52A9\u53C2\u8003\uFF0C\u7EDD\u4E0D\u80FD\u4F18\u5148\u4E8E\u5F53\u524D\u9875\u9762\u4E0A\u4E0B\u6587
97
97
 
98
98
  ## \u4F60\u7684\u5DE5\u4F5C\u73AF\u5883
99
99
 
@@ -0,0 +1,147 @@
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 service_logs_exports = {};
39
+ __export(service_logs_exports, {
40
+ ServiceLogsPlugin: () => ServiceLogsPlugin,
41
+ default: () => service_logs_default
42
+ });
43
+ module.exports = __toCommonJS(service_logs_exports);
44
+ var import_plugin = require("@opencode-ai/plugin");
45
+ var import_shared = require("@vite-plugin-opencode-assistant/shared");
46
+ const log = (0, import_shared.createLogger)("ServiceLogsPlugin");
47
+ const ServiceLogsPlugin = () => __async(null, null, function* () {
48
+ var _a;
49
+ log.debug("ServiceLogsPlugin loading...");
50
+ const logFilesJson = process.env.OPENCODE_LOG_FILES_JSON;
51
+ log.debug("Log files JSON from env:", { logFilesJson: logFilesJson ? "set" : "not set" });
52
+ if (!logFilesJson) {
53
+ log.debug("OPENCODE_LOG_FILES_JSON is not set, service logs plugin will not register tools");
54
+ return {};
55
+ }
56
+ let logFiles;
57
+ try {
58
+ logFiles = JSON.parse(logFilesJson);
59
+ log.debug("Parsed log files config", { count: logFiles.length });
60
+ } catch (e) {
61
+ log.error("Failed to parse OPENCODE_LOG_FILES_JSON", { error: e });
62
+ return {};
63
+ }
64
+ if (!logFiles || logFiles.length === 0) {
65
+ log.debug("No log files configured, plugin will not register any tools");
66
+ return {};
67
+ }
68
+ const watcher = (0, import_shared.getServiceLogWatcher)();
69
+ watcher.setProjectRoot(process.cwd());
70
+ for (const logFileConfig of logFiles) {
71
+ watcher.addLogFile({
72
+ name: logFileConfig.name,
73
+ filePath: logFileConfig.path,
74
+ maxBufferSize: logFileConfig.maxBufferSize,
75
+ watchExisting: logFileConfig.watchExisting
76
+ });
77
+ log.debug(`Added log file watcher: ${logFileConfig.name} -> ${logFileConfig.path}`);
78
+ }
79
+ const tools = {};
80
+ for (const logFileConfig of logFiles) {
81
+ let _b;
82
+ const toolName = `get_${logFileConfig.name}_logs`;
83
+ const description = `\u83B7\u53D6 ${logFileConfig.name} \u7684\u65E5\u5FD7\u3002
84
+
85
+ **\u4F55\u65F6\u4F7F\u7528\u6B64\u5DE5\u5177**\uFF1A
86
+ ${logFileConfig.description}
87
+
88
+ **\u65E5\u5FD7\u5185\u5BB9**\uFF1A
89
+ - \u6765\u81EA\u65E5\u5FD7\u6587\u4EF6 ${logFileConfig.path} \u7684\u5B9E\u65F6\u65E5\u5FD7
90
+ - \u6700\u591A\u4FDD\u7559 ${(_a = logFileConfig.maxBufferSize) != null ? _a : 200} \u6761\u65E5\u5FD7`;
91
+ const getLogsTool = (0, import_plugin.tool)({
92
+ description,
93
+ args: {
94
+ level: import_plugin.tool.schema.string().optional().describe(
95
+ "\u65E5\u5FD7\u7EA7\u522B\u8FC7\u6EE4\uFF1Aerror(\u9519\u8BEF)\u3001warn(\u8B66\u544A)\u3001info(\u4FE1\u606F)\u3002\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF0C\u5982 'error,warn'"
96
+ ),
97
+ limit: import_plugin.tool.schema.number().int().min(1).max(200).optional().default(50).describe("\u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 50\uFF0C\u6700\u5927 200"),
98
+ since: import_plugin.tool.schema.string().optional().describe("\u8D77\u59CB\u65F6\u95F4\uFF08ISO \u683C\u5F0F\uFF09\uFF0C\u83B7\u53D6\u6B64\u65F6\u95F4\u4E4B\u540E\u7684\u65E5\u5FD7")
99
+ },
100
+ execute(args, context) {
101
+ return __async(this, null, function* () {
102
+ const { level, limit, since } = args;
103
+ log.debug(`${toolName} called`, {
104
+ args,
105
+ sessionID: context.sessionID,
106
+ directory: context.directory
107
+ });
108
+ const buffer = watcher.getBuffer(logFileConfig.name);
109
+ if (!buffer) {
110
+ return `\u65E5\u5FD7\u6587\u4EF6 "${logFileConfig.name}" \u672A\u627E\u5230\u3002\u8BF7\u68C0\u67E5\u914D\u7F6E\u3002`;
111
+ }
112
+ const logs = buffer.getLogs({
113
+ level: level ? level.split(",").map((l) => l.trim()) : void 0,
114
+ limit,
115
+ since
116
+ });
117
+ if (logs.length === 0) {
118
+ return `\u5F53\u524D\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u65E5\u5FD7\uFF08\u7F13\u51B2\u533A\u5171 ${buffer.size()} \u6761\uFF09\u3002
119
+
120
+ \u5EFA\u8BAE\uFF1A
121
+ - \u4E0D\u6307\u5B9A\u53C2\u6570\u83B7\u53D6\u6240\u6709\u65E5\u5FD7
122
+ - \u4F7F\u7528 level=error,warn \u83B7\u53D6\u9519\u8BEF\u548C\u8B66\u544A`;
123
+ }
124
+ const formattedLogs = logs.map((entry) => {
125
+ const time = new Date(entry.timestamp).toLocaleTimeString();
126
+ const levelIcon = entry.level === "error" ? "\u274C" : entry.level === "warn" ? "\u26A0\uFE0F" : "\u2139\uFE0F";
127
+ return `${time} ${levelIcon} ${entry.message}`;
128
+ }).join("\n");
129
+ return `${logFileConfig.name} \u65E5\u5FD7\uFF08${logs.length}/${buffer.size()} \u6761\uFF09\uFF1A
130
+
131
+ ${formattedLogs}`;
132
+ });
133
+ }
134
+ });
135
+ tools[toolName] = getLogsTool;
136
+ log.debug(`Registered tool: ${toolName}`);
137
+ }
138
+ log.debug(`Plugin initialized with ${Object.keys(tools).length} log tools`);
139
+ return {
140
+ tool: tools
141
+ };
142
+ });
143
+ var service_logs_default = ServiceLogsPlugin;
144
+ // Annotate the CommonJS export names for ESM import in node:
145
+ 0 && (module.exports = {
146
+ ServiceLogsPlugin
147
+ });
@@ -0,0 +1,3 @@
1
+ import type { Hooks } from "@opencode-ai/plugin";
2
+ export declare const ServiceLogsPlugin: () => Promise<Hooks>;
3
+ export default ServiceLogsPlugin;
package/lib/web.cjs CHANGED
@@ -91,21 +91,33 @@ function prepareOpenCodeRuntime(cwd) {
91
91
  }
92
92
  function startOpenCodeWeb(options) {
93
93
  var _a, _b;
94
- const { port, hostname, cwd, configDir, corsOrigins, contextApiUrl, logsApiUrl } = options;
94
+ const { port, hostname, cwd, configDir, corsOrigins, contextApiUrl, logsApiUrl, logFilesJson } = options;
95
95
  const stateDir = createStateDirectory(cwd);
96
96
  const pluginsDir = import_path.default.join(stateDir, "plugins");
97
97
  const pluginPaths = [
98
98
  import_path.default.join(pluginsDir, "page-context.js"),
99
99
  import_path.default.join(pluginsDir, "vite-logs.js")
100
- ].join(",");
100
+ ];
101
+ if (logFilesJson) {
102
+ pluginPaths.push(import_path.default.join(pluginsDir, "service-logs.js"));
103
+ }
104
+ const pluginPathsStr = pluginPaths.join(",");
101
105
  log.debug("Building process environment", {
102
106
  stateDir,
103
107
  configDir,
104
108
  contextApiUrl,
105
109
  logsApiUrl,
106
- pluginPaths
110
+ logFilesJson,
111
+ pluginPathsStr
107
112
  });
108
- const env = buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginPaths);
113
+ const env = buildProcessEnv(
114
+ stateDir,
115
+ configDir,
116
+ contextApiUrl,
117
+ logsApiUrl,
118
+ pluginPathsStr,
119
+ logFilesJson
120
+ );
109
121
  const args = ["serve", "--port", String(port), "--hostname", hostname];
110
122
  if (corsOrigins && corsOrigins.length > 0) {
111
123
  corsOrigins.forEach((origin) => {
@@ -174,7 +186,7 @@ function copyPluginFiles(sourceDir, targetDir) {
174
186
  }
175
187
  log.debug("All plugin files copied", { count: files.length, files });
176
188
  }
177
- function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginPaths) {
189
+ function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginPaths, logFilesJson) {
178
190
  const env = __spreadProps(__spreadValues({}, Object.fromEntries(
179
191
  Object.entries(process.env).filter(([, v]) => v !== void 0)
180
192
  )), {
@@ -196,6 +208,10 @@ function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, pluginP
196
208
  env.OPENCODE_PLUGINS = pluginPaths;
197
209
  log.debug("Set OPENCODE_PLUGINS", { pluginPaths });
198
210
  }
211
+ if (logFilesJson) {
212
+ env.OPENCODE_LOG_FILES_JSON = logFilesJson;
213
+ log.debug("Set OPENCODE_LOG_FILES_JSON", { logFilesJson });
214
+ }
199
215
  return env;
200
216
  }
201
217
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-plugin-opencode-assistant/opencode",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.mjs",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "execa": "^9.6.1",
25
- "@vite-plugin-opencode-assistant/shared": "1.0.56"
25
+ "@vite-plugin-opencode-assistant/shared": "1.0.58"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@opencode-ai/plugin": "^1.3.15",