@jiangxiaoxu/lm-tools-bridge-proxy 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/index.js +68 -1
  2. 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,43 @@ function appendLog(message) {
154
166
  }
155
167
  function createStdioMessageHandler(targetGetter, targetRefresher) {
156
168
  return async (message) => {
169
+ if (message?.method === "roots/list") {
170
+ if (message.id === void 0 || message.id === null) {
171
+ return;
172
+ }
173
+ let target2 = targetGetter();
174
+ if (!target2) {
175
+ const now2 = Date.now();
176
+ const graceDeadline2 = STARTUP_TIME + STARTUP_GRACE_MS;
177
+ const refreshResult2 = await targetRefresher(now2 < graceDeadline2 ? graceDeadline2 : void 0);
178
+ target2 = refreshResult2?.target;
179
+ if (!target2) {
180
+ const errorKind = refreshResult2?.errorKind ?? "unreachable";
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 resultPayload = {
195
+ jsonrpc: "2.0",
196
+ id: message.id,
197
+ result: {
198
+ roots: buildRoots(target2)
199
+ }
200
+ };
201
+ appendLog(`roots/list => ${JSON.stringify(resultPayload.result)}`);
202
+ import_node_process.default.stdout.write(`${JSON.stringify(resultPayload)}
203
+ `);
204
+ return;
205
+ }
157
206
  const payload = JSON.stringify(message);
158
207
  let target = targetGetter();
159
208
  if (!target) {
@@ -201,8 +250,26 @@ function createStdioMessageHandler(targetGetter, targetRefresher) {
201
250
  response.on("end", () => {
202
251
  const text = Buffer.concat(chunks).toString("utf8");
203
252
  if (text.length > 0) {
204
- import_node_process.default.stdout.write(`${text}
253
+ const contentType = Array.isArray(response.headers["content-type"]) ? response.headers["content-type"].join(";") : response.headers["content-type"] ?? "";
254
+ if (contentType.includes("text/event-stream")) {
255
+ const events = text.split(/\r?\n\r?\n/);
256
+ for (const eventBlock of events) {
257
+ const lines = eventBlock.split(/\r?\n/);
258
+ const dataLines = lines.filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart());
259
+ if (dataLines.length === 0) {
260
+ continue;
261
+ }
262
+ const dataText = dataLines.join("\n").trim();
263
+ if (dataText.length === 0 || dataText === "[DONE]") {
264
+ continue;
265
+ }
266
+ import_node_process.default.stdout.write(`${dataText}
267
+ `);
268
+ }
269
+ } else {
270
+ import_node_process.default.stdout.write(`${text}
205
271
  `);
272
+ }
206
273
  }
207
274
  resolve({ ok: true });
208
275
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jiangxiaoxu/lm-tools-bridge-proxy",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Stdio MCP proxy for LM Tools Bridge (Windows Named Pipe resolve).",
5
5
  "license": "MIT",
6
6
  "bin": {