@atlisp/mcp 1.3.4 → 1.3.5
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 +66 -132
- package/dist/cad-worker.js +11 -0
- package/package.json +1 -1
package/dist/atlisp-mcp.js
CHANGED
|
@@ -34,8 +34,7 @@ var SessionTransport = class {
|
|
|
34
34
|
this._started = true;
|
|
35
35
|
}
|
|
36
36
|
async send(message) {
|
|
37
|
-
if (this._closed)
|
|
38
|
-
return;
|
|
37
|
+
if (this._closed) return;
|
|
39
38
|
if (this._pendingRequest) {
|
|
40
39
|
const { resolve, reject, timeout } = this._pendingRequest;
|
|
41
40
|
clearTimeout(timeout);
|
|
@@ -44,8 +43,7 @@ var SessionTransport = class {
|
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
async close() {
|
|
47
|
-
if (this._closed)
|
|
48
|
-
return;
|
|
46
|
+
if (this._closed) return;
|
|
49
47
|
this._closed = true;
|
|
50
48
|
if (this._pendingRequest) {
|
|
51
49
|
const { reject, timeout } = this._pendingRequest;
|
|
@@ -212,8 +210,7 @@ function setupStdoutHandler(w) {
|
|
|
212
210
|
const lines = buffer.split("\n");
|
|
213
211
|
buffer = lines.pop() || "";
|
|
214
212
|
for (const line of lines) {
|
|
215
|
-
if (!line.trim())
|
|
216
|
-
continue;
|
|
213
|
+
if (!line.trim()) continue;
|
|
217
214
|
try {
|
|
218
215
|
const result = JSON.parse(line);
|
|
219
216
|
const rid = result.requestId;
|
|
@@ -238,8 +235,7 @@ function setupStdoutHandler(w) {
|
|
|
238
235
|
}
|
|
239
236
|
function getWorker() {
|
|
240
237
|
if (!worker || !worker.connected) {
|
|
241
|
-
if (worker)
|
|
242
|
-
worker.kill();
|
|
238
|
+
if (worker) worker.kill();
|
|
243
239
|
worker = spawn("node", [workerPath], {
|
|
244
240
|
stdio: ["pipe", "pipe", "pipe"]
|
|
245
241
|
});
|
|
@@ -248,8 +244,7 @@ function getWorker() {
|
|
|
248
244
|
const w = worker;
|
|
249
245
|
w.on("exit", (code) => {
|
|
250
246
|
console.error("worker exited:", code);
|
|
251
|
-
if (w !== worker)
|
|
252
|
-
return;
|
|
247
|
+
if (w !== worker) return;
|
|
253
248
|
w.connected = false;
|
|
254
249
|
for (const [id, { reject, timeout }] of pendingRequests) {
|
|
255
250
|
clearTimeout(timeout);
|
|
@@ -268,8 +263,7 @@ function getWorker() {
|
|
|
268
263
|
return worker;
|
|
269
264
|
}
|
|
270
265
|
function startHeartbeat() {
|
|
271
|
-
if (heartbeatTimer)
|
|
272
|
-
clearInterval(heartbeatTimer);
|
|
266
|
+
if (heartbeatTimer) clearInterval(heartbeatTimer);
|
|
273
267
|
heartbeatTimer = setInterval(async () => {
|
|
274
268
|
try {
|
|
275
269
|
const result = await sendMessage({ type: "ping" });
|
|
@@ -314,8 +308,7 @@ var CadConnection = class {
|
|
|
314
308
|
return process.platform === "win32";
|
|
315
309
|
}
|
|
316
310
|
async connect() {
|
|
317
|
-
if (!this.isAvailable())
|
|
318
|
-
return false;
|
|
311
|
+
if (!this.isAvailable()) return false;
|
|
319
312
|
try {
|
|
320
313
|
const result = await sendMessage({ type: "connect" });
|
|
321
314
|
if (result && result.success) {
|
|
@@ -331,16 +324,13 @@ var CadConnection = class {
|
|
|
331
324
|
return false;
|
|
332
325
|
}
|
|
333
326
|
async sendCommand(code) {
|
|
334
|
-
if (!this.connected)
|
|
335
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
327
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
336
328
|
const result = await sendMessage({ type: "send", code, platform: _platform });
|
|
337
|
-
if (result.success)
|
|
338
|
-
return true;
|
|
329
|
+
if (result.success) return true;
|
|
339
330
|
throw new Error(result.error || "\u53D1\u9001\u5931\u8D25");
|
|
340
331
|
}
|
|
341
332
|
async sendCommandWithResult(code, encoding = null) {
|
|
342
|
-
if (!this.connected)
|
|
343
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
333
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
344
334
|
const result = await sendMessage({ type: "sendResult", code, platform: _platform, encoding: encoding || "" });
|
|
345
335
|
if (result.success) {
|
|
346
336
|
return result.result || "";
|
|
@@ -354,8 +344,7 @@ var CadConnection = class {
|
|
|
354
344
|
return this.product;
|
|
355
345
|
}
|
|
356
346
|
async isBusy() {
|
|
357
|
-
if (!this.connected)
|
|
358
|
-
return false;
|
|
347
|
+
if (!this.connected) return false;
|
|
359
348
|
try {
|
|
360
349
|
const result = await sendMessage({ type: "isBusy", platform: _platform });
|
|
361
350
|
return result && result.isBusy;
|
|
@@ -364,8 +353,7 @@ var CadConnection = class {
|
|
|
364
353
|
}
|
|
365
354
|
}
|
|
366
355
|
async hasDoc() {
|
|
367
|
-
if (!this.connected)
|
|
368
|
-
return { hasDoc: false, docCount: 0 };
|
|
356
|
+
if (!this.connected) return { hasDoc: false, docCount: 0 };
|
|
369
357
|
try {
|
|
370
358
|
const result = await sendMessage({ type: "hasdoc", platform: _platform });
|
|
371
359
|
return result || { hasDoc: false, docCount: 0 };
|
|
@@ -374,8 +362,7 @@ var CadConnection = class {
|
|
|
374
362
|
}
|
|
375
363
|
}
|
|
376
364
|
async newDoc() {
|
|
377
|
-
if (!this.connected)
|
|
378
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
365
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
379
366
|
try {
|
|
380
367
|
const result = await sendMessage({ type: "newdoc", platform: _platform });
|
|
381
368
|
return result && result.success;
|
|
@@ -384,8 +371,7 @@ var CadConnection = class {
|
|
|
384
371
|
}
|
|
385
372
|
}
|
|
386
373
|
async bringToFront() {
|
|
387
|
-
if (!this.connected)
|
|
388
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
374
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
389
375
|
try {
|
|
390
376
|
const result = await sendMessage({ type: "bringToFront", platform: _platform });
|
|
391
377
|
return result && result.success;
|
|
@@ -394,8 +380,7 @@ var CadConnection = class {
|
|
|
394
380
|
}
|
|
395
381
|
}
|
|
396
382
|
async getInfo() {
|
|
397
|
-
if (!this.connected)
|
|
398
|
-
return "CAD \u672A\u8FDE\u63A5";
|
|
383
|
+
if (!this.connected) return "CAD \u672A\u8FDE\u63A5";
|
|
399
384
|
return `Platform: ${this.product}, Version: ${this.version}, Status: Connected`;
|
|
400
385
|
}
|
|
401
386
|
async disconnect() {
|
|
@@ -488,14 +473,12 @@ async function getCadInfo() {
|
|
|
488
473
|
if (!cad.connected) {
|
|
489
474
|
await cad.connect();
|
|
490
475
|
}
|
|
491
|
-
if (!cad.connected)
|
|
492
|
-
return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
|
|
476
|
+
if (!cad.connected) return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
|
|
493
477
|
const info = await cad.getInfo();
|
|
494
478
|
return { content: [{ type: "text", text: info }] };
|
|
495
479
|
}
|
|
496
480
|
async function atCommand(command) {
|
|
497
|
-
if (!cad.connected)
|
|
498
|
-
return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
|
|
481
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
|
|
499
482
|
await cad.sendCommand(command + "\n");
|
|
500
483
|
return { content: [{ type: "text", text: `\u5DF2\u53D1\u9001\u547D\u4EE4: ${command}` }] };
|
|
501
484
|
}
|
|
@@ -503,8 +486,7 @@ async function newDocument() {
|
|
|
503
486
|
if (!cad.connected) {
|
|
504
487
|
await cad.connect();
|
|
505
488
|
}
|
|
506
|
-
if (!cad.connected)
|
|
507
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
489
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
508
490
|
const result = await cad.newDoc();
|
|
509
491
|
if (result) {
|
|
510
492
|
return { content: [{ type: "text", text: "\u5DF2\u5728 CAD \u4E2D\u65B0\u5EFA\u7A7A\u767D\u6587\u6863" }] };
|
|
@@ -515,8 +497,7 @@ async function bringToFront() {
|
|
|
515
497
|
if (!cad.connected) {
|
|
516
498
|
await cad.connect();
|
|
517
499
|
}
|
|
518
|
-
if (!cad.connected)
|
|
519
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
500
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
520
501
|
const result = await cad.bringToFront();
|
|
521
502
|
if (result) {
|
|
522
503
|
return { content: [{ type: "text", text: "\u5DF2\u5C06 CAD \u7A97\u53E3\u5207\u6362\u5230\u524D\u53F0" }] };
|
|
@@ -527,8 +508,7 @@ async function installAtlisp() {
|
|
|
527
508
|
if (!cad.connected) {
|
|
528
509
|
await cad.connect();
|
|
529
510
|
}
|
|
530
|
-
if (!cad.connected)
|
|
531
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
511
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
532
512
|
const installCode = `(progn(vl-load-com)(setq s strcat h "http" o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://atlisp.""cn/@"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get-property o'ResponseText))))`;
|
|
533
513
|
await cad.sendCommand(installCode + "\n");
|
|
534
514
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u5B89\u88C5\u4EE3\u7801\u5230 CAD" }] };
|
|
@@ -537,12 +517,10 @@ async function listFunctionsInCad() {
|
|
|
537
517
|
if (!cad.connected) {
|
|
538
518
|
await cad.connect();
|
|
539
519
|
}
|
|
540
|
-
if (!cad.connected)
|
|
541
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
520
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
542
521
|
try {
|
|
543
522
|
const result = await cad.sendCommandWithResult("(atoms-family 0)", null);
|
|
544
|
-
if (result)
|
|
545
|
-
return { content: [{ type: "text", text: result }] };
|
|
523
|
+
if (result) return { content: [{ type: "text", text: result }] };
|
|
546
524
|
return { content: [{ type: "text", text: "CAD \u51FD\u6570\u5217\u8868\u4E3A\u7A7A" }] };
|
|
547
525
|
} catch (e) {
|
|
548
526
|
return { content: [{ type: "text", text: `\u9519\u8BEF: ${e.message}` }], isError: true };
|
|
@@ -552,8 +530,7 @@ async function initAtlisp() {
|
|
|
552
530
|
if (!cad.connected) {
|
|
553
531
|
await cad.connect();
|
|
554
532
|
}
|
|
555
|
-
if (!cad.connected)
|
|
556
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
533
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
557
534
|
const code = `(if (null @::load-module)
|
|
558
535
|
(progn
|
|
559
536
|
(vl-load-com)
|
|
@@ -593,13 +570,10 @@ async function fetchPackages() {
|
|
|
593
570
|
return null;
|
|
594
571
|
}
|
|
595
572
|
async function listPackages() {
|
|
596
|
-
if (!cad.connected)
|
|
597
|
-
|
|
598
|
-
if (!cad.connected)
|
|
599
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
573
|
+
if (!cad.connected) await cad.connect();
|
|
574
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
600
575
|
const result = await cad.sendCommandWithResult("(@::package-list-in-local)");
|
|
601
|
-
if (result && result !== "nil")
|
|
602
|
-
return { content: [{ type: "text", text: result }] };
|
|
576
|
+
if (result && result !== "nil") return { content: [{ type: "text", text: result }] };
|
|
603
577
|
const packages = MOCK_PACKAGES.map((p) => `${p.name} v${p.version} - ${p.description}`);
|
|
604
578
|
return { content: [{ type: "text", text: `\u5DF2\u5B89\u88C5\u7684 @lisp \u5305:
|
|
605
579
|
${packages.join("\n")}` }] };
|
|
@@ -616,12 +590,10 @@ async function searchPackages(query) {
|
|
|
616
590
|
for (const p of items) {
|
|
617
591
|
const name = (p.name || "").toLowerCase();
|
|
618
592
|
const desc = (p.description || "").toLowerCase();
|
|
619
|
-
if (name.includes(q) || desc.includes(q))
|
|
620
|
-
results.push(p);
|
|
593
|
+
if (name.includes(q) || desc.includes(q)) results.push(p);
|
|
621
594
|
}
|
|
622
595
|
} else {
|
|
623
|
-
for (const p of items)
|
|
624
|
-
results.push(p);
|
|
596
|
+
for (const p of items) results.push(p);
|
|
625
597
|
}
|
|
626
598
|
if (results.length === 0) {
|
|
627
599
|
return { content: [{ type: "text", text: `\u672A\u627E\u5230\u5305\u542B "${query}" \u7684\u5305` }] };
|
|
@@ -663,8 +635,7 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
663
635
|
const data = await response.json();
|
|
664
636
|
const funcs = Object.values(data.all_functions || {});
|
|
665
637
|
const func = funcs.find((f2) => f2.name === funcName || f2.name === `${packageName}:${funcName}`);
|
|
666
|
-
if (func)
|
|
667
|
-
results.push(func);
|
|
638
|
+
if (func) results.push(func);
|
|
668
639
|
}
|
|
669
640
|
} catch (e) {
|
|
670
641
|
log(`function-handlers fetch error: ${e.message}`);
|
|
@@ -675,8 +646,7 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
675
646
|
const raw = await fs2.readFile(path3.join(FUNCTIONS_DIR, file), "utf-8");
|
|
676
647
|
const data = JSON.parse(raw);
|
|
677
648
|
const func = data.functions?.find((f2) => f2.name === funcName);
|
|
678
|
-
if (func)
|
|
679
|
-
results.push(func);
|
|
649
|
+
if (func) results.push(func);
|
|
680
650
|
}
|
|
681
651
|
}
|
|
682
652
|
if (results.length === 0) {
|
|
@@ -757,14 +727,11 @@ function setCache(key, data) {
|
|
|
757
727
|
resourceCache.set(key, { data, timestamp: Date.now() });
|
|
758
728
|
}
|
|
759
729
|
function parseLispList(str) {
|
|
760
|
-
if (!str || typeof str !== "string")
|
|
761
|
-
return null;
|
|
730
|
+
if (!str || typeof str !== "string") return null;
|
|
762
731
|
const trimmed = str.trim();
|
|
763
|
-
if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
|
|
764
|
-
return null;
|
|
732
|
+
if (!trimmed.startsWith("(") || !trimmed.endsWith(")")) return null;
|
|
765
733
|
const content = trimmed.slice(1, -1).trim();
|
|
766
|
-
if (!content)
|
|
767
|
-
return [];
|
|
734
|
+
if (!content) return [];
|
|
768
735
|
const result = [];
|
|
769
736
|
let depth = 0;
|
|
770
737
|
let current = "";
|
|
@@ -806,21 +773,15 @@ function parseLispList(str) {
|
|
|
806
773
|
}
|
|
807
774
|
current += ch;
|
|
808
775
|
}
|
|
809
|
-
if (current.trim())
|
|
810
|
-
result.push(current.trim());
|
|
776
|
+
if (current.trim()) result.push(current.trim());
|
|
811
777
|
return result.map((item) => {
|
|
812
778
|
const t = item.trim();
|
|
813
|
-
if (t === "nil")
|
|
814
|
-
|
|
815
|
-
if (t === "
|
|
816
|
-
return true;
|
|
817
|
-
if (t === "T")
|
|
818
|
-
return true;
|
|
779
|
+
if (t === "nil") return null;
|
|
780
|
+
if (t === "t") return true;
|
|
781
|
+
if (t === "T") return true;
|
|
819
782
|
const num = Number(t);
|
|
820
|
-
if (!isNaN(num) && t !== "")
|
|
821
|
-
|
|
822
|
-
if (t.startsWith('"') && t.endsWith('"'))
|
|
823
|
-
return t.slice(1, -1);
|
|
783
|
+
if (!isNaN(num) && t !== "") return num;
|
|
784
|
+
if (t.startsWith('"') && t.endsWith('"')) return t.slice(1, -1);
|
|
824
785
|
return t;
|
|
825
786
|
});
|
|
826
787
|
}
|
|
@@ -835,16 +796,14 @@ var RESOURCES = [
|
|
|
835
796
|
];
|
|
836
797
|
function parseQuery(uri) {
|
|
837
798
|
const qIdx = uri.indexOf("?");
|
|
838
|
-
if (qIdx === -1)
|
|
839
|
-
return { base: uri, params: {} };
|
|
799
|
+
if (qIdx === -1) return { base: uri, params: {} };
|
|
840
800
|
const base = uri.substring(0, qIdx);
|
|
841
801
|
const params = {};
|
|
842
802
|
uri.substring(qIdx + 1).split("&").forEach((p) => {
|
|
843
803
|
const eqIdx = p.indexOf("=");
|
|
844
804
|
const k = eqIdx === -1 ? p : p.substring(0, eqIdx);
|
|
845
805
|
const v = eqIdx === -1 ? "" : p.substring(eqIdx + 1);
|
|
846
|
-
if (k)
|
|
847
|
-
params[k] = decodeURIComponent(v);
|
|
806
|
+
if (k) params[k] = decodeURIComponent(v);
|
|
848
807
|
});
|
|
849
808
|
return { base, params };
|
|
850
809
|
}
|
|
@@ -880,8 +839,7 @@ async function readResource(uri) {
|
|
|
880
839
|
}
|
|
881
840
|
async function getCadInfo2() {
|
|
882
841
|
const cached = getCached("cad:info");
|
|
883
|
-
if (cached)
|
|
884
|
-
return cached;
|
|
842
|
+
if (cached) return cached;
|
|
885
843
|
if (!cad.connected) {
|
|
886
844
|
await cad.connect();
|
|
887
845
|
}
|
|
@@ -908,12 +866,9 @@ async function getCadInfo2() {
|
|
|
908
866
|
async function getLayers(filterName = null) {
|
|
909
867
|
const cacheKey = filterName ? `layers:${filterName}` : "layers:all";
|
|
910
868
|
const cached = getCached(cacheKey);
|
|
911
|
-
if (cached)
|
|
912
|
-
|
|
913
|
-
if (!cad.connected)
|
|
914
|
-
await cad.connect();
|
|
915
|
-
if (!cad.connected)
|
|
916
|
-
return [];
|
|
869
|
+
if (cached) return cached;
|
|
870
|
+
if (!cad.connected) await cad.connect();
|
|
871
|
+
if (!cad.connected) return [];
|
|
917
872
|
try {
|
|
918
873
|
const code = filterName ? `(tblnext "LAYER" T)` : `(progn (setq res nil)(while (setq e (tblnext "LAYER" (null res)))(setq res (cons (list (cdr (assoc 2 e)) (cdr (assoc 62 e)) (cdr (assoc 70 e))) res))) (reverse res))`;
|
|
919
874
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -960,10 +915,8 @@ async function getLayers(filterName = null) {
|
|
|
960
915
|
async function getEntities(filterType = null) {
|
|
961
916
|
const cacheKey = filterType ? `entities:${filterType}` : "entities:all";
|
|
962
917
|
const cached = getCached(cacheKey);
|
|
963
|
-
if (cached)
|
|
964
|
-
|
|
965
|
-
if (!cad.connected)
|
|
966
|
-
await cad.connect();
|
|
918
|
+
if (cached) return cached;
|
|
919
|
+
if (!cad.connected) await cad.connect();
|
|
967
920
|
if (!cad.connected) {
|
|
968
921
|
const result = { total: 0, byType: {} };
|
|
969
922
|
setCache(cacheKey, result);
|
|
@@ -1017,10 +970,8 @@ async function getEntities(filterType = null) {
|
|
|
1017
970
|
}
|
|
1018
971
|
}
|
|
1019
972
|
async function getDwgName() {
|
|
1020
|
-
if (!cad.connected)
|
|
1021
|
-
|
|
1022
|
-
if (!cad.connected)
|
|
1023
|
-
return { name: null };
|
|
973
|
+
if (!cad.connected) await cad.connect();
|
|
974
|
+
if (!cad.connected) return { name: null };
|
|
1024
975
|
try {
|
|
1025
976
|
const code = `(vl-princ-to-string (getvar "dwgname"))`;
|
|
1026
977
|
const name = await cad.sendCommandWithResult(code);
|
|
@@ -1030,10 +981,8 @@ async function getDwgName() {
|
|
|
1030
981
|
}
|
|
1031
982
|
}
|
|
1032
983
|
async function getDwgPath() {
|
|
1033
|
-
if (!cad.connected)
|
|
1034
|
-
|
|
1035
|
-
if (!cad.connected)
|
|
1036
|
-
return { path: null, name: null };
|
|
984
|
+
if (!cad.connected) await cad.connect();
|
|
985
|
+
if (!cad.connected) return { path: null, name: null };
|
|
1037
986
|
try {
|
|
1038
987
|
const code = `(progn
|
|
1039
988
|
(setq prefix (vl-princ-to-string (getvar "dwgprefix")))
|
|
@@ -1051,8 +1000,7 @@ async function getDwgPath() {
|
|
|
1051
1000
|
}
|
|
1052
1001
|
if (!parsed) {
|
|
1053
1002
|
const listResult = parseLispList(result);
|
|
1054
|
-
if (listResult && listResult.length >= 2)
|
|
1055
|
-
parsed = listResult;
|
|
1003
|
+
if (listResult && listResult.length >= 2) parsed = listResult;
|
|
1056
1004
|
}
|
|
1057
1005
|
if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
|
|
1058
1006
|
return { path: String(parsed[0]), name: String(parsed[1]) };
|
|
@@ -1256,14 +1204,10 @@ ${generateSuggestions(entities, layers)}`
|
|
|
1256
1204
|
}
|
|
1257
1205
|
function generateSuggestions(entities, layers) {
|
|
1258
1206
|
const suggestions = [];
|
|
1259
|
-
if (entities.total > 1e3)
|
|
1260
|
-
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1263
|
-
if (entities.byType.LINE && entities.byType.LINE > 500)
|
|
1264
|
-
suggestions.push("- \u7EBF\u6761\u8F83\u591A\uFF0C\u53EF\u8003\u8651\u4F7F\u7528 BLOCK \u51CF\u5C11\u5B9E\u4F53\u6570\u91CF");
|
|
1265
|
-
if (!entities.byType.DIMENSION)
|
|
1266
|
-
suggestions.push("- \u672A\u53D1\u73B0\u5C3A\u5BF8\u6807\u6CE8\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u6807\u6CE8");
|
|
1207
|
+
if (entities.total > 1e3) suggestions.push("- \u56FE\u7EB8\u5B9E\u4F53\u8F83\u591A\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u56FE\u5C42\u5206\u7C7B\u7BA1\u7406");
|
|
1208
|
+
if (layers.length > 20) suggestions.push("- \u56FE\u5C42\u8F83\u591A\uFF0C\u5EFA\u8BAE\u6E05\u7406\u672A\u4F7F\u7528\u7684\u56FE\u5C42");
|
|
1209
|
+
if (entities.byType.LINE && entities.byType.LINE > 500) suggestions.push("- \u7EBF\u6761\u8F83\u591A\uFF0C\u53EF\u8003\u8651\u4F7F\u7528 BLOCK \u51CF\u5C11\u5B9E\u4F53\u6570\u91CF");
|
|
1210
|
+
if (!entities.byType.DIMENSION) suggestions.push("- \u672A\u53D1\u73B0\u5C3A\u5BF8\u6807\u6CE8\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u6807\u6CE8");
|
|
1267
1211
|
return suggestions.length ? suggestions.join("\n") : "- \u56FE\u7EB8\u7ED3\u6784\u826F\u597D";
|
|
1268
1212
|
}
|
|
1269
1213
|
async function generateBatchLinesPrompt(args) {
|
|
@@ -1579,11 +1523,9 @@ var SseSession = class {
|
|
|
1579
1523
|
return lines.join("\n") + "\n\n";
|
|
1580
1524
|
}
|
|
1581
1525
|
_setupDrain() {
|
|
1582
|
-
if (typeof this.#res.on !== "function")
|
|
1583
|
-
return;
|
|
1526
|
+
if (typeof this.#res.on !== "function") return;
|
|
1584
1527
|
this.#drainHandler = () => {
|
|
1585
|
-
if (!this.#active)
|
|
1586
|
-
return;
|
|
1528
|
+
if (!this.#active) return;
|
|
1587
1529
|
if (this.#backpressureBuffer.length > 0) {
|
|
1588
1530
|
this._drainBuffer();
|
|
1589
1531
|
}
|
|
@@ -1605,8 +1547,7 @@ var SseSession = class {
|
|
|
1605
1547
|
}
|
|
1606
1548
|
}
|
|
1607
1549
|
_write(content) {
|
|
1608
|
-
if (!this.#active)
|
|
1609
|
-
return false;
|
|
1550
|
+
if (!this.#active) return false;
|
|
1610
1551
|
try {
|
|
1611
1552
|
if (this.#backpressureBuffer.length > 0) {
|
|
1612
1553
|
this.#backpressureBuffer.push(content);
|
|
@@ -1876,8 +1817,7 @@ var SERVER_CAPABILITIES = {
|
|
|
1876
1817
|
prompts: {}
|
|
1877
1818
|
};
|
|
1878
1819
|
var { port, host, transport, apiKey, rateLimitWindow, rateLimitMax } = config_default;
|
|
1879
|
-
if (apiKey)
|
|
1880
|
-
log("API Key authentication enabled");
|
|
1820
|
+
if (apiKey) log("API Key authentication enabled");
|
|
1881
1821
|
var mcpLimiter = rateLimit({
|
|
1882
1822
|
windowMs: rateLimitWindow,
|
|
1883
1823
|
max: rateLimitMax,
|
|
@@ -1927,8 +1867,7 @@ ${CAD_PLATFORMS.join("\n")}
|
|
|
1927
1867
|
list_symbols: (a) => listSymbols(a.package),
|
|
1928
1868
|
import_funlib: async (a) => {
|
|
1929
1869
|
const data = await loadAtlibFunctionLib();
|
|
1930
|
-
if (!data)
|
|
1931
|
-
return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
|
|
1870
|
+
if (!data) return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
|
|
1932
1871
|
if (a.format === "list") {
|
|
1933
1872
|
const items = Object.values(data.all_functions || {}).map((f) => `${f.name}: ${f.description || ""}`);
|
|
1934
1873
|
return { content: [{ type: "text", text: items.join("\n") }] };
|
|
@@ -2090,8 +2029,7 @@ var tools = [
|
|
|
2090
2029
|
];
|
|
2091
2030
|
async function handleToolCall(name, args) {
|
|
2092
2031
|
const handler = TOOL_HANDLERS[name];
|
|
2093
|
-
if (!handler)
|
|
2094
|
-
return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
|
|
2032
|
+
if (!handler) return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
|
|
2095
2033
|
try {
|
|
2096
2034
|
const result = await handler(args || {});
|
|
2097
2035
|
notifyResourceChanges(name);
|
|
@@ -2212,8 +2150,7 @@ async function startServer() {
|
|
|
2212
2150
|
const JSON_CONTENT_TYPES = ["application/json", "application/json-rpc", "application/vnd.api+json"];
|
|
2213
2151
|
app.use(async (req, res, next) => {
|
|
2214
2152
|
const ct = (req.headers["content-type"] || "").toLowerCase();
|
|
2215
|
-
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
|
|
2216
|
-
return next();
|
|
2153
|
+
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t))) return next();
|
|
2217
2154
|
try {
|
|
2218
2155
|
const buf = await rawBody(req, { limit: "10mb" });
|
|
2219
2156
|
const m = ct.match(/charset\s*=\s*([^\s;]+)/i);
|
|
@@ -2234,11 +2171,9 @@ async function startServer() {
|
|
|
2234
2171
|
const PUBLIC_PATHS = ["/health"];
|
|
2235
2172
|
if (apiKey) {
|
|
2236
2173
|
app.use((req, res, next) => {
|
|
2237
|
-
if (PUBLIC_PATHS.includes(req.path))
|
|
2238
|
-
return next();
|
|
2174
|
+
if (PUBLIC_PATHS.includes(req.path)) return next();
|
|
2239
2175
|
const auth = req.get("Authorization");
|
|
2240
|
-
if (auth === `Bearer ${apiKey}`)
|
|
2241
|
-
return next();
|
|
2176
|
+
if (auth === `Bearer ${apiKey}`) return next();
|
|
2242
2177
|
res.status(401).json({ error: "Unauthorized" });
|
|
2243
2178
|
});
|
|
2244
2179
|
}
|
|
@@ -2253,8 +2188,7 @@ async function startServer() {
|
|
|
2253
2188
|
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id, content-type, x-accel-buffering");
|
|
2254
2189
|
res.setHeader("Access-Control-Max-Age", "86400");
|
|
2255
2190
|
res.setHeader("Vary", "Accept");
|
|
2256
|
-
if (req.method === "OPTIONS")
|
|
2257
|
-
return res.status(204).end();
|
|
2191
|
+
if (req.method === "OPTIONS") return res.status(204).end();
|
|
2258
2192
|
next();
|
|
2259
2193
|
});
|
|
2260
2194
|
}
|
package/dist/cad-worker.js
CHANGED
|
@@ -440,6 +440,17 @@ async function handleMessage(msg) {
|
|
|
440
440
|
if (!parenCheck.valid) {
|
|
441
441
|
return { success: false, error: `括号错误: ${parenCheck.error} (位置 ${parenCheck.pos})` };
|
|
442
442
|
}
|
|
443
|
+
if (msg.code.length > 255) {
|
|
444
|
+
log(`send (long code ${msg.code.length} chars, fallback to sendResult): ${msg.code.substring(0, 80)}...`);
|
|
445
|
+
const r = await new Promise((resolve, reject) => {
|
|
446
|
+
cadSendWithResult({ code: msg.code, platform: msg.platform || 'AutoCAD', encoding: '' }, (e, r) => {
|
|
447
|
+
if (e) reject(e);
|
|
448
|
+
else resolve(r);
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
log(`send result (long code): ${JSON.stringify(r)}`);
|
|
452
|
+
return r;
|
|
453
|
+
}
|
|
443
454
|
const maxRetries = 3;
|
|
444
455
|
let lastError = null;
|
|
445
456
|
for (let i = 0; i < maxRetries; i++) {
|