@jiangxiaoxu/lm-tools-bridge-proxy 0.1.5 → 0.1.7
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/dist/index.js +56 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -29,6 +29,8 @@ var import_node_process = __toESM(require("node:process"));
|
|
|
29
29
|
var import_node_crypto = __toESM(require("node:crypto"));
|
|
30
30
|
var import_node_os = __toESM(require("node:os"));
|
|
31
31
|
var import_node_fs = __toESM(require("node:fs"));
|
|
32
|
+
var import_node_path = __toESM(require("node:path"));
|
|
33
|
+
var import_node_url = require("node:url");
|
|
32
34
|
var MANAGER_TIMEOUT_MS = 1500;
|
|
33
35
|
var RESOLVE_RETRIES = 10;
|
|
34
36
|
var RESOLVE_RETRY_DELAY_MS = 500;
|
|
@@ -86,6 +88,16 @@ function isSameTarget(left, right) {
|
|
|
86
88
|
}
|
|
87
89
|
return left.host === right.host && left.port === right.port;
|
|
88
90
|
}
|
|
91
|
+
function buildRoots(match) {
|
|
92
|
+
const folders = Array.isArray(match.workspaceFolders) ? match.workspaceFolders : [];
|
|
93
|
+
return folders.map((folder) => {
|
|
94
|
+
const resolved = import_node_path.default.resolve(folder);
|
|
95
|
+
return {
|
|
96
|
+
uri: (0, import_node_url.pathToFileURL)(resolved).toString(),
|
|
97
|
+
name: import_node_path.default.basename(resolved)
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
89
101
|
async function managerRequest(method, requestPath, body) {
|
|
90
102
|
return new Promise((resolve) => {
|
|
91
103
|
const payload = body ? JSON.stringify(body) : void 0;
|
|
@@ -154,6 +166,49 @@ function appendLog(message) {
|
|
|
154
166
|
}
|
|
155
167
|
function createStdioMessageHandler(targetGetter, targetRefresher) {
|
|
156
168
|
return async (message) => {
|
|
169
|
+
if (message?.method === "roots/list") {
|
|
170
|
+
let target2 = targetGetter();
|
|
171
|
+
if (!target2) {
|
|
172
|
+
const now2 = Date.now();
|
|
173
|
+
const graceDeadline2 = STARTUP_TIME + STARTUP_GRACE_MS;
|
|
174
|
+
const refreshResult2 = await targetRefresher(now2 < graceDeadline2 ? graceDeadline2 : void 0);
|
|
175
|
+
target2 = refreshResult2?.target;
|
|
176
|
+
if (!target2) {
|
|
177
|
+
const errorKind = refreshResult2?.errorKind ?? "unreachable";
|
|
178
|
+
if (message.id === void 0 || message.id === null) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const errorPayload2 = {
|
|
182
|
+
jsonrpc: "2.0",
|
|
183
|
+
id: message.id,
|
|
184
|
+
error: {
|
|
185
|
+
code: errorKind === "no_match" ? ERROR_NO_MATCH : ERROR_MANAGER_UNREACHABLE,
|
|
186
|
+
message: errorKind === "no_match" ? "No matching VS Code instance for current workspace." : "Manager unreachable."
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
import_node_process.default.stdout.write(`${JSON.stringify(errorPayload2)}
|
|
190
|
+
`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const rootsResult = {
|
|
195
|
+
roots: buildRoots(target2)
|
|
196
|
+
};
|
|
197
|
+
appendLog(`roots/list => ${JSON.stringify(rootsResult)}`);
|
|
198
|
+
if (message.id === void 0 || message.id === null) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const resultPayload = {
|
|
202
|
+
jsonrpc: "2.0",
|
|
203
|
+
id: message.id,
|
|
204
|
+
result: {
|
|
205
|
+
roots: rootsResult.roots
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
import_node_process.default.stdout.write(`${JSON.stringify(resultPayload)}
|
|
209
|
+
`);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
157
212
|
const payload = JSON.stringify(message);
|
|
158
213
|
let target = targetGetter();
|
|
159
214
|
if (!target) {
|
|
@@ -334,6 +389,7 @@ async function main() {
|
|
|
334
389
|
import_node_process.default.stdin.on("end", () => {
|
|
335
390
|
import_node_process.default.exit(0);
|
|
336
391
|
});
|
|
392
|
+
void handler({ jsonrpc: "2.0", id: null, method: "roots/list" });
|
|
337
393
|
}
|
|
338
394
|
main().catch((error) => {
|
|
339
395
|
appendLog(`MCP proxy startup failed: ${String(error)}`);
|