@atlisp/mcp 1.8.0 → 1.8.1
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/atlisp-mcp.js +69 -1
- package/dist/cad-worker.js +73 -0
- package/package.json +1 -1
package/dist/atlisp-mcp.js
CHANGED
|
@@ -215,6 +215,7 @@ __export(cad_exports, {
|
|
|
215
215
|
cad: () => cad,
|
|
216
216
|
default: () => cad_default,
|
|
217
217
|
getWorker: () => getWorker,
|
|
218
|
+
onDocumentChanged: () => onDocumentChanged,
|
|
218
219
|
resetWorker: () => resetWorker,
|
|
219
220
|
sendMessage: () => sendMessage
|
|
220
221
|
});
|
|
@@ -222,6 +223,21 @@ import { spawn } from "child_process";
|
|
|
222
223
|
import path2 from "path";
|
|
223
224
|
import { fileURLToPath } from "url";
|
|
224
225
|
import { randomUUID } from "crypto";
|
|
226
|
+
function onDocumentChanged(callback) {
|
|
227
|
+
_docChangeCallbacks.push(callback);
|
|
228
|
+
}
|
|
229
|
+
function emitDocumentChanged(info) {
|
|
230
|
+
if (info.docName === _activeDocName)
|
|
231
|
+
return;
|
|
232
|
+
_activeDocName = info.docName || "";
|
|
233
|
+
for (const cb of _docChangeCallbacks) {
|
|
234
|
+
try {
|
|
235
|
+
cb(info);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
console.error("doc change callback error:", e.message);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
225
241
|
function resetWorker() {
|
|
226
242
|
for (const [id, { reject, timeout }] of pendingRequests) {
|
|
227
243
|
clearTimeout(timeout);
|
|
@@ -285,6 +301,8 @@ function setupStdoutHandler(w) {
|
|
|
285
301
|
} else {
|
|
286
302
|
resolve(result);
|
|
287
303
|
}
|
|
304
|
+
} else if (result.type === "event" && result.eventType === "documentChanged") {
|
|
305
|
+
emitDocumentChanged({ docName: result.docName, docPath: result.docPath });
|
|
288
306
|
}
|
|
289
307
|
} catch (parseErr) {
|
|
290
308
|
console.error("JSON parse error in worker output:", parseErr.message);
|
|
@@ -337,6 +355,16 @@ function startHeartbeat() {
|
|
|
337
355
|
if (!result?.pong) {
|
|
338
356
|
console.error("heartbeat failed, worker may be dead");
|
|
339
357
|
resetWorker();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (_platform) {
|
|
361
|
+
try {
|
|
362
|
+
const docResult = await sendMessage({ type: "getActiveDocInfo", platform: _platform });
|
|
363
|
+
if (docResult?.docName) {
|
|
364
|
+
emitDocumentChanged({ docName: docResult.docName, docPath: docResult.docPath || "" });
|
|
365
|
+
}
|
|
366
|
+
} catch (e) {
|
|
367
|
+
}
|
|
340
368
|
}
|
|
341
369
|
} catch (e) {
|
|
342
370
|
console.error("heartbeat error:", e.message);
|
|
@@ -365,7 +393,7 @@ function sendMessage(msg) {
|
|
|
365
393
|
}
|
|
366
394
|
});
|
|
367
395
|
}
|
|
368
|
-
var MESSAGE_TIMEOUT, HEARTBEAT_INTERVAL, MAX_RESTART_ATTEMPTS, RESTART_BACKOFF_BASE, __dirname, workerPath, worker, _platform, heartbeatTimer, pendingRequests, stdoutHandlerSetup, MAX_BUFFER_SIZE, restartCount, restartTimer, PRIORITY_NORMAL, MAX_QUEUE_SIZE, CommandQueue, commandQueue, CadConnection, cad, cad_default;
|
|
396
|
+
var MESSAGE_TIMEOUT, HEARTBEAT_INTERVAL, MAX_RESTART_ATTEMPTS, RESTART_BACKOFF_BASE, __dirname, workerPath, worker, _platform, heartbeatTimer, pendingRequests, stdoutHandlerSetup, MAX_BUFFER_SIZE, restartCount, restartTimer, PRIORITY_NORMAL, MAX_QUEUE_SIZE, _docChangeCallbacks, _activeDocName, _monitorStarted, CommandQueue, commandQueue, CadConnection, cad, cad_default;
|
|
369
397
|
var init_cad = __esm({
|
|
370
398
|
"src/cad.js"() {
|
|
371
399
|
init_constants();
|
|
@@ -386,6 +414,9 @@ var init_cad = __esm({
|
|
|
386
414
|
restartTimer = null;
|
|
387
415
|
PRIORITY_NORMAL = 1;
|
|
388
416
|
MAX_QUEUE_SIZE = 500;
|
|
417
|
+
_docChangeCallbacks = [];
|
|
418
|
+
_activeDocName = null;
|
|
419
|
+
_monitorStarted = false;
|
|
389
420
|
CommandQueue = class {
|
|
390
421
|
#queues = [[], [], []];
|
|
391
422
|
#processing = false;
|
|
@@ -481,6 +512,13 @@ var init_cad = __esm({
|
|
|
481
512
|
this.product = result.platform;
|
|
482
513
|
_platform = result.platform;
|
|
483
514
|
this.connected = true;
|
|
515
|
+
_activeDocName = null;
|
|
516
|
+
if (!_monitorStarted) {
|
|
517
|
+
_monitorStarted = true;
|
|
518
|
+
sendMessage({ type: "startMonitor", platform: _platform }).catch(() => {
|
|
519
|
+
_monitorStarted = false;
|
|
520
|
+
});
|
|
521
|
+
}
|
|
484
522
|
return true;
|
|
485
523
|
}
|
|
486
524
|
} catch (e) {
|
|
@@ -569,6 +607,16 @@ var init_cad = __esm({
|
|
|
569
607
|
return false;
|
|
570
608
|
}
|
|
571
609
|
}
|
|
610
|
+
async getActiveDocInfo() {
|
|
611
|
+
if (!this.connected)
|
|
612
|
+
return { docName: "", docPath: "", docCount: 0 };
|
|
613
|
+
try {
|
|
614
|
+
const result = await sendMessage({ type: "getActiveDocInfo", platform: _platform });
|
|
615
|
+
return result || { docName: "", docPath: "", docCount: 0 };
|
|
616
|
+
} catch (e) {
|
|
617
|
+
return { docName: "", docPath: "", docCount: 0 };
|
|
618
|
+
}
|
|
619
|
+
}
|
|
572
620
|
async getInfo() {
|
|
573
621
|
if (!this.connected)
|
|
574
622
|
return "CAD \u672A\u8FDE\u63A5";
|
|
@@ -579,6 +627,8 @@ var init_cad = __esm({
|
|
|
579
627
|
this.version = null;
|
|
580
628
|
this.product = null;
|
|
581
629
|
_platform = null;
|
|
630
|
+
_activeDocName = null;
|
|
631
|
+
_monitorStarted = false;
|
|
582
632
|
commandQueue.clear();
|
|
583
633
|
resetWorker();
|
|
584
634
|
}
|
|
@@ -595,6 +645,8 @@ var init_cad = __esm({
|
|
|
595
645
|
this.version = null;
|
|
596
646
|
this.product = null;
|
|
597
647
|
_platform = null;
|
|
648
|
+
_activeDocName = null;
|
|
649
|
+
_monitorStarted = false;
|
|
598
650
|
commandQueue.clear();
|
|
599
651
|
resetWorker();
|
|
600
652
|
}
|
|
@@ -9328,6 +9380,22 @@ async function startServer() {
|
|
|
9328
9380
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
9329
9381
|
}
|
|
9330
9382
|
}
|
|
9383
|
+
onDocumentChanged((info) => {
|
|
9384
|
+
const uris = [
|
|
9385
|
+
"atlisp://dwg/name",
|
|
9386
|
+
"atlisp://dwg/path",
|
|
9387
|
+
"atlisp://cad/dwgs",
|
|
9388
|
+
"atlisp://dwg/tbl",
|
|
9389
|
+
"atlisp://dwg/entities",
|
|
9390
|
+
"atlisp://dwg/block-refs",
|
|
9391
|
+
"atlisp://dwg/text-content",
|
|
9392
|
+
"atlisp://dwg/groups"
|
|
9393
|
+
];
|
|
9394
|
+
for (const uri of uris) {
|
|
9395
|
+
clearCache(uri);
|
|
9396
|
+
notify(uri, { docName: info.docName, docPath: info.docPath });
|
|
9397
|
+
}
|
|
9398
|
+
});
|
|
9331
9399
|
if (!process.env.VITEST) {
|
|
9332
9400
|
await startServer();
|
|
9333
9401
|
}
|
package/dist/cad-worker.js
CHANGED
|
@@ -245,6 +245,63 @@ string encoding = d.encoding != null ? d.encoding.ToString() : "";
|
|
|
245
245
|
}
|
|
246
246
|
*/});
|
|
247
247
|
|
|
248
|
+
const cadGetActiveDocInfo = edge.func(function() {/*
|
|
249
|
+
async (input) => {
|
|
250
|
+
try {
|
|
251
|
+
string platform = input.ToString();
|
|
252
|
+
string progId = platform == "BricsCAD" ? "BricscadApp.AcadApplication" : platform + ".Application";
|
|
253
|
+
dynamic cad = System.Runtime.InteropServices.Marshal.GetActiveObject(progId);
|
|
254
|
+
if (cad != null) {
|
|
255
|
+
int docCount = cad.Documents.Count;
|
|
256
|
+
string docName = "";
|
|
257
|
+
string docPath = "";
|
|
258
|
+
try {
|
|
259
|
+
docName = cad.ActiveDocument.Name;
|
|
260
|
+
docPath = cad.ActiveDocument.FullName;
|
|
261
|
+
} catch {}
|
|
262
|
+
return new { hasDoc = docCount > 0, docCount = docCount, docName = docName, docPath = docPath };
|
|
263
|
+
}
|
|
264
|
+
} catch (Exception ex) {
|
|
265
|
+
System.Diagnostics.Debug.WriteLine("cadGetActiveDocInfo error: " + ex.Message);
|
|
266
|
+
}
|
|
267
|
+
return new { hasDoc = false, docCount = 0, docName = "", docPath = "" };
|
|
268
|
+
}
|
|
269
|
+
*/});
|
|
270
|
+
|
|
271
|
+
const cadStartMonitor = edge.func(function() {/*
|
|
272
|
+
async (input) => {
|
|
273
|
+
try {
|
|
274
|
+
string platform = input.ToString();
|
|
275
|
+
string progId = platform == "BricsCAD" ? "BricscadApp.AcadApplication" : platform + ".Application";
|
|
276
|
+
dynamic cad = System.Runtime.InteropServices.Marshal.GetActiveObject(progId);
|
|
277
|
+
if (cad == null) return new { success = false, error = "CAD not found" };
|
|
278
|
+
|
|
279
|
+
string prevName = "";
|
|
280
|
+
var timer = new System.Threading.Timer((_) => {
|
|
281
|
+
try {
|
|
282
|
+
string docName = cad.ActiveDocument.Name;
|
|
283
|
+
if (docName != prevName) {
|
|
284
|
+
prevName = docName;
|
|
285
|
+
string docPath = "";
|
|
286
|
+
try { docPath = cad.ActiveDocument.FullName; } catch {}
|
|
287
|
+
string json = "{\"type\":\"event\",\"eventType\":\"documentChanged\",\"docName\":\"" +
|
|
288
|
+
docName.Replace("\\", "\\\\").Replace("\"", "\\\"") +
|
|
289
|
+
"\",\"docPath\":\"" +
|
|
290
|
+
docPath.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"}";
|
|
291
|
+
Console.WriteLine(json);
|
|
292
|
+
}
|
|
293
|
+
} catch (Exception ex) {
|
|
294
|
+
System.Diagnostics.Debug.WriteLine("cadMonitor timer error: " + ex.Message);
|
|
295
|
+
}
|
|
296
|
+
}, null, 3000, 3000);
|
|
297
|
+
|
|
298
|
+
return new { success = true };
|
|
299
|
+
} catch (Exception ex) {
|
|
300
|
+
return new { success = false, error = ex.Message };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
*/});
|
|
304
|
+
|
|
248
305
|
process.stdin.setEncoding('utf8');
|
|
249
306
|
|
|
250
307
|
let stdinBuffer = '';
|
|
@@ -581,5 +638,21 @@ async function handleMessage(msg) {
|
|
|
581
638
|
});
|
|
582
639
|
});
|
|
583
640
|
}
|
|
641
|
+
if (msg.type === 'getActiveDocInfo') {
|
|
642
|
+
return new Promise((resolve, reject) => {
|
|
643
|
+
cadGetActiveDocInfo(msg.platform || 'AutoCAD', (e, r) => {
|
|
644
|
+
if (e) reject(e);
|
|
645
|
+
else resolve(r);
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
if (msg.type === 'startMonitor') {
|
|
650
|
+
return new Promise((resolve, reject) => {
|
|
651
|
+
cadStartMonitor(msg.platform || 'AutoCAD', (e, r) => {
|
|
652
|
+
if (e) reject(e);
|
|
653
|
+
else resolve(r);
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
}
|
|
584
657
|
return { error: 'unknown message type' };
|
|
585
658
|
}
|