@vite-plugin-opencode-assistant/opencode 1.0.57 → 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/plugins/service-logs.d.ts +3 -0
- package/es/plugins/service-logs.js +212 -0
- package/es/plugins/service-logs.mjs +124 -0
- package/es/plugins/tool.js +9389 -0
- package/es/plugins/vite-logs.js +36 -9421
- package/es/web.mjs +21 -5
- package/lib/plugins/service-logs.cjs +147 -0
- package/lib/plugins/service-logs.d.ts +3 -0
- package/lib/web.cjs +21 -5
- package/package.json +2 -2
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
|
-
]
|
|
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
|
-
|
|
79
|
+
logFilesJson,
|
|
80
|
+
pluginPathsStr
|
|
76
81
|
});
|
|
77
|
-
const env = buildProcessEnv(
|
|
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 {
|
|
@@ -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
|
+
});
|
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
|
-
]
|
|
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
|
-
|
|
110
|
+
logFilesJson,
|
|
111
|
+
pluginPathsStr
|
|
107
112
|
});
|
|
108
|
-
const env = buildProcessEnv(
|
|
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.
|
|
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.
|
|
25
|
+
"@vite-plugin-opencode-assistant/shared": "1.0.58"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@opencode-ai/plugin": "^1.3.15",
|