@atlisp/mcp 1.6.2 → 1.6.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.
- package/dist/atlisp-mcp.js +416 -210
- package/dist/cad-worker.js +10 -10
- package/package.json +2 -2
package/dist/atlisp-mcp.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/atlisp-mcp.js
|
|
4
4
|
import path10 from "path";
|
|
5
|
+
import fs8 from "fs";
|
|
5
6
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
6
7
|
import { createRequire } from "module";
|
|
7
8
|
import express2 from "express";
|
|
@@ -22,7 +23,7 @@ var FILE_EXTENSIONS = {
|
|
|
22
23
|
"BricsCAD": [".des"]
|
|
23
24
|
};
|
|
24
25
|
var SERVER_NAME = "atlisp-mcp-server";
|
|
25
|
-
var SERVER_VERSION = "1.6.
|
|
26
|
+
var SERVER_VERSION = "1.6.4";
|
|
26
27
|
var MOCK_PACKAGES = [
|
|
27
28
|
{ name: "base", description: "\u57FA\u7840\u51FD\u6570\u5E93", version: "1.0.0" },
|
|
28
29
|
{ name: "at-pm", description: "\u5DE5\u7A0B\u9879\u76EE\u7BA1\u7406", version: "2.1.0" },
|
|
@@ -115,7 +116,8 @@ function parseArgs() {
|
|
|
115
116
|
return result;
|
|
116
117
|
}
|
|
117
118
|
function loadConfigFile(filePath) {
|
|
118
|
-
if (!filePath || !fs.existsSync(filePath))
|
|
119
|
+
if (!filePath || !fs.existsSync(filePath))
|
|
120
|
+
return null;
|
|
119
121
|
try {
|
|
120
122
|
const raw = fs.readFileSync(filePath, "utf-8");
|
|
121
123
|
const parsed = JSON.parse(raw);
|
|
@@ -253,7 +255,8 @@ function setupStdoutHandler(w) {
|
|
|
253
255
|
const lines = buffer.split("\n");
|
|
254
256
|
buffer = lines.pop() || "";
|
|
255
257
|
for (const line of lines) {
|
|
256
|
-
if (!line.trim())
|
|
258
|
+
if (!line.trim())
|
|
259
|
+
continue;
|
|
257
260
|
try {
|
|
258
261
|
const result = JSON.parse(line);
|
|
259
262
|
const rid = result.requestId;
|
|
@@ -279,7 +282,8 @@ function setupStdoutHandler(w) {
|
|
|
279
282
|
}
|
|
280
283
|
function getWorker(force = false) {
|
|
281
284
|
if (!worker || !worker.connected || force) {
|
|
282
|
-
if (worker)
|
|
285
|
+
if (worker)
|
|
286
|
+
worker.kill();
|
|
283
287
|
worker = spawn("node", [workerPath], {
|
|
284
288
|
stdio: ["pipe", "pipe", "pipe"]
|
|
285
289
|
});
|
|
@@ -287,7 +291,8 @@ function getWorker(force = false) {
|
|
|
287
291
|
const w = worker;
|
|
288
292
|
w.on("exit", (code) => {
|
|
289
293
|
console.error("worker exited with code:", code);
|
|
290
|
-
if (w !== worker)
|
|
294
|
+
if (w !== worker)
|
|
295
|
+
return;
|
|
291
296
|
w.connected = false;
|
|
292
297
|
for (const [id, { reject, timeout }] of pendingRequests) {
|
|
293
298
|
clearTimeout(timeout);
|
|
@@ -308,7 +313,8 @@ function getWorker(force = false) {
|
|
|
308
313
|
return worker;
|
|
309
314
|
}
|
|
310
315
|
function startHeartbeat() {
|
|
311
|
-
if (heartbeatTimer)
|
|
316
|
+
if (heartbeatTimer)
|
|
317
|
+
clearInterval(heartbeatTimer);
|
|
312
318
|
heartbeatTimer = setInterval(async () => {
|
|
313
319
|
try {
|
|
314
320
|
const result = await sendMessage({ type: "ping" });
|
|
@@ -353,7 +359,8 @@ var CadConnection = class {
|
|
|
353
359
|
return process.platform === "win32";
|
|
354
360
|
}
|
|
355
361
|
async connect(platform = null) {
|
|
356
|
-
if (!this.isAvailable())
|
|
362
|
+
if (!this.isAvailable())
|
|
363
|
+
return false;
|
|
357
364
|
try {
|
|
358
365
|
const msg = platform ? { type: "connect", platform } : { type: "connect" };
|
|
359
366
|
const result = await sendMessage(msg);
|
|
@@ -370,13 +377,16 @@ var CadConnection = class {
|
|
|
370
377
|
return false;
|
|
371
378
|
}
|
|
372
379
|
async sendCommand(code) {
|
|
373
|
-
if (!this.connected)
|
|
380
|
+
if (!this.connected)
|
|
381
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
374
382
|
const result = await sendMessage({ type: "send", code, platform: _platform });
|
|
375
|
-
if (result.success)
|
|
383
|
+
if (result.success)
|
|
384
|
+
return true;
|
|
376
385
|
throw new Error(result.error || "\u53D1\u9001\u5931\u8D25");
|
|
377
386
|
}
|
|
378
387
|
async sendCommandWithResult(code, encoding = null) {
|
|
379
|
-
if (!this.connected)
|
|
388
|
+
if (!this.connected)
|
|
389
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
380
390
|
const result = await sendMessage({ type: "sendResult", code, platform: _platform, encoding: encoding || "" });
|
|
381
391
|
if (result.success) {
|
|
382
392
|
return result.result || "";
|
|
@@ -390,7 +400,8 @@ var CadConnection = class {
|
|
|
390
400
|
return this.product;
|
|
391
401
|
}
|
|
392
402
|
async isBusy() {
|
|
393
|
-
if (!this.connected)
|
|
403
|
+
if (!this.connected)
|
|
404
|
+
return false;
|
|
394
405
|
try {
|
|
395
406
|
const result = await sendMessage({ type: "isBusy", platform: _platform });
|
|
396
407
|
return result && result.isBusy;
|
|
@@ -399,7 +410,8 @@ var CadConnection = class {
|
|
|
399
410
|
}
|
|
400
411
|
}
|
|
401
412
|
async hasDoc() {
|
|
402
|
-
if (!this.connected)
|
|
413
|
+
if (!this.connected)
|
|
414
|
+
return { hasDoc: false, docCount: 0 };
|
|
403
415
|
try {
|
|
404
416
|
const result = await sendMessage({ type: "hasdoc", platform: _platform });
|
|
405
417
|
return result || { hasDoc: false, docCount: 0 };
|
|
@@ -408,7 +420,8 @@ var CadConnection = class {
|
|
|
408
420
|
}
|
|
409
421
|
}
|
|
410
422
|
async newDoc() {
|
|
411
|
-
if (!this.connected)
|
|
423
|
+
if (!this.connected)
|
|
424
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
412
425
|
try {
|
|
413
426
|
const result = await sendMessage({ type: "newdoc", platform: _platform });
|
|
414
427
|
return result && result.success;
|
|
@@ -417,7 +430,8 @@ var CadConnection = class {
|
|
|
417
430
|
}
|
|
418
431
|
}
|
|
419
432
|
async bringToFront() {
|
|
420
|
-
if (!this.connected)
|
|
433
|
+
if (!this.connected)
|
|
434
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
421
435
|
try {
|
|
422
436
|
const result = await sendMessage({ type: "bringToFront", platform: _platform });
|
|
423
437
|
return result && result.success;
|
|
@@ -426,7 +440,8 @@ var CadConnection = class {
|
|
|
426
440
|
}
|
|
427
441
|
}
|
|
428
442
|
async getInfo() {
|
|
429
|
-
if (!this.connected)
|
|
443
|
+
if (!this.connected)
|
|
444
|
+
return "CAD \u672A\u8FDE\u63A5";
|
|
430
445
|
return `Platform: ${this.product}, Version: ${this.version}, Status: Connected`;
|
|
431
446
|
}
|
|
432
447
|
async disconnect() {
|
|
@@ -463,9 +478,11 @@ var MAX_LOG_SIZE = 10 * 1024 * 1024;
|
|
|
463
478
|
var MAX_LOG_FILES = 5;
|
|
464
479
|
var stream = null;
|
|
465
480
|
function rotateLog() {
|
|
466
|
-
if (!fs2.existsSync(DEBUG_FILE))
|
|
481
|
+
if (!fs2.existsSync(DEBUG_FILE))
|
|
482
|
+
return;
|
|
467
483
|
const stat = fs2.statSync(DEBUG_FILE);
|
|
468
|
-
if (stat.size < MAX_LOG_SIZE)
|
|
484
|
+
if (stat.size < MAX_LOG_SIZE)
|
|
485
|
+
return;
|
|
469
486
|
if (stream) {
|
|
470
487
|
stream.end();
|
|
471
488
|
stream = null;
|
|
@@ -529,9 +546,11 @@ function ensureRequestLogDir() {
|
|
|
529
546
|
}
|
|
530
547
|
}
|
|
531
548
|
function rotateRequestLog() {
|
|
532
|
-
if (!fs2.existsSync(REQUEST_LOG_FILE))
|
|
549
|
+
if (!fs2.existsSync(REQUEST_LOG_FILE))
|
|
550
|
+
return;
|
|
533
551
|
const stat = fs2.statSync(REQUEST_LOG_FILE);
|
|
534
|
-
if (stat.size < 10 * 1024 * 1024)
|
|
552
|
+
if (stat.size < 10 * 1024 * 1024)
|
|
553
|
+
return;
|
|
535
554
|
const dir = path3.dirname(REQUEST_LOG_FILE);
|
|
536
555
|
for (let i = 5; i > 0; i--) {
|
|
537
556
|
const oldPath = `${REQUEST_LOG_FILE}.${i}`;
|
|
@@ -549,7 +568,8 @@ function rotateRequestLog() {
|
|
|
549
568
|
}
|
|
550
569
|
}
|
|
551
570
|
function logRequest(req) {
|
|
552
|
-
if (!config_default.requestLogEnabled)
|
|
571
|
+
if (!config_default.requestLogEnabled)
|
|
572
|
+
return;
|
|
553
573
|
try {
|
|
554
574
|
ensureRequestLogDir();
|
|
555
575
|
rotateRequestLog();
|
|
@@ -566,7 +586,8 @@ function logRequest(req) {
|
|
|
566
586
|
}
|
|
567
587
|
}
|
|
568
588
|
function logResponse(req, res, duration) {
|
|
569
|
-
if (!config_default.requestLogEnabled)
|
|
589
|
+
if (!config_default.requestLogEnabled)
|
|
590
|
+
return;
|
|
570
591
|
try {
|
|
571
592
|
ensureRequestLogDir();
|
|
572
593
|
const entry = {
|
|
@@ -612,11 +633,14 @@ function clearCache(uri) {
|
|
|
612
633
|
}
|
|
613
634
|
}
|
|
614
635
|
function parseLispList(str) {
|
|
615
|
-
if (!str || typeof str !== "string")
|
|
636
|
+
if (!str || typeof str !== "string")
|
|
637
|
+
return null;
|
|
616
638
|
const trimmed = str.trim();
|
|
617
|
-
if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
|
|
639
|
+
if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
|
|
640
|
+
return null;
|
|
618
641
|
const content = trimmed.slice(1, -1).trim();
|
|
619
|
-
if (!content)
|
|
642
|
+
if (!content)
|
|
643
|
+
return [];
|
|
620
644
|
const result = [];
|
|
621
645
|
let depth = 0;
|
|
622
646
|
let current = "";
|
|
@@ -658,32 +682,44 @@ function parseLispList(str) {
|
|
|
658
682
|
}
|
|
659
683
|
current += ch;
|
|
660
684
|
}
|
|
661
|
-
if (current.trim())
|
|
685
|
+
if (current.trim())
|
|
686
|
+
result.push(current.trim());
|
|
662
687
|
return result.map((item) => {
|
|
663
688
|
const t = item.trim();
|
|
664
|
-
if (t === "nil")
|
|
665
|
-
|
|
666
|
-
if (t === "
|
|
689
|
+
if (t === "nil")
|
|
690
|
+
return null;
|
|
691
|
+
if (t === "t")
|
|
692
|
+
return true;
|
|
693
|
+
if (t === "T")
|
|
694
|
+
return true;
|
|
667
695
|
const num = Number(t);
|
|
668
|
-
if (!isNaN(num) && t !== "")
|
|
669
|
-
|
|
696
|
+
if (!isNaN(num) && t !== "")
|
|
697
|
+
return num;
|
|
698
|
+
if (t.startsWith('"') && t.endsWith('"'))
|
|
699
|
+
return t.slice(1, -1);
|
|
670
700
|
return t;
|
|
671
701
|
});
|
|
672
702
|
}
|
|
673
703
|
function parseLispRecursive(str) {
|
|
674
|
-
if (!str || typeof str !== "string")
|
|
704
|
+
if (!str || typeof str !== "string")
|
|
705
|
+
return null;
|
|
675
706
|
str = str.trim();
|
|
676
|
-
if (!str)
|
|
707
|
+
if (!str)
|
|
708
|
+
return null;
|
|
677
709
|
let pos = 0;
|
|
678
710
|
function skipWs() {
|
|
679
|
-
while (pos < str.length && /\s/.test(str[pos]))
|
|
711
|
+
while (pos < str.length && /\s/.test(str[pos]))
|
|
712
|
+
pos++;
|
|
680
713
|
}
|
|
681
714
|
function parseValue() {
|
|
682
715
|
skipWs();
|
|
683
|
-
if (pos >= str.length)
|
|
716
|
+
if (pos >= str.length)
|
|
717
|
+
return null;
|
|
684
718
|
const ch = str[pos];
|
|
685
|
-
if (ch === "(")
|
|
686
|
-
|
|
719
|
+
if (ch === "(")
|
|
720
|
+
return parseList();
|
|
721
|
+
if (ch === '"')
|
|
722
|
+
return parseString();
|
|
687
723
|
if (ch === "'") {
|
|
688
724
|
pos++;
|
|
689
725
|
return parseValue();
|
|
@@ -696,11 +732,16 @@ function parseLispRecursive(str) {
|
|
|
696
732
|
while (pos < str.length && str[pos] !== '"') {
|
|
697
733
|
if (str[pos] === "\\" && pos + 1 < str.length) {
|
|
698
734
|
pos++;
|
|
699
|
-
if (str[pos] === '"')
|
|
700
|
-
|
|
701
|
-
else if (str[pos] === "
|
|
702
|
-
|
|
703
|
-
else
|
|
735
|
+
if (str[pos] === '"')
|
|
736
|
+
r += '"';
|
|
737
|
+
else if (str[pos] === "n")
|
|
738
|
+
r += "\n";
|
|
739
|
+
else if (str[pos] === "t")
|
|
740
|
+
r += " ";
|
|
741
|
+
else if (str[pos] === "\\")
|
|
742
|
+
r += "\\";
|
|
743
|
+
else
|
|
744
|
+
r += str[pos];
|
|
704
745
|
} else {
|
|
705
746
|
r += str[pos];
|
|
706
747
|
}
|
|
@@ -711,12 +752,16 @@ function parseLispRecursive(str) {
|
|
|
711
752
|
}
|
|
712
753
|
function parseAtom() {
|
|
713
754
|
const start = pos;
|
|
714
|
-
while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(")
|
|
755
|
+
while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(")
|
|
756
|
+
pos++;
|
|
715
757
|
const atom = str.slice(start, pos);
|
|
716
|
-
if (atom === "nil" || atom === "NIL")
|
|
717
|
-
|
|
758
|
+
if (atom === "nil" || atom === "NIL")
|
|
759
|
+
return null;
|
|
760
|
+
if (atom === "t" || atom === "T")
|
|
761
|
+
return true;
|
|
718
762
|
const num = Number(atom);
|
|
719
|
-
if (!isNaN(num) && atom !== "")
|
|
763
|
+
if (!isNaN(num) && atom !== "")
|
|
764
|
+
return num;
|
|
720
765
|
return atom;
|
|
721
766
|
}
|
|
722
767
|
function parseList() {
|
|
@@ -724,13 +769,15 @@ function parseLispRecursive(str) {
|
|
|
724
769
|
const items = [];
|
|
725
770
|
while (pos < str.length) {
|
|
726
771
|
skipWs();
|
|
727
|
-
if (pos >= str.length)
|
|
772
|
+
if (pos >= str.length)
|
|
773
|
+
break;
|
|
728
774
|
if (str[pos] === ")") {
|
|
729
775
|
pos++;
|
|
730
776
|
return items;
|
|
731
777
|
}
|
|
732
778
|
const left = parseValue();
|
|
733
|
-
if (left === void 0)
|
|
779
|
+
if (left === void 0)
|
|
780
|
+
break;
|
|
734
781
|
skipWs();
|
|
735
782
|
if (str[pos] === "." && (pos + 1 >= str.length || /\s/.test(str[pos + 1]) || str[pos + 1] === ")")) {
|
|
736
783
|
pos++;
|
|
@@ -753,7 +800,8 @@ function parseLispRecursive(str) {
|
|
|
753
800
|
return parseValue();
|
|
754
801
|
}
|
|
755
802
|
function lispPairsToObject(pairs) {
|
|
756
|
-
if (!Array.isArray(pairs))
|
|
803
|
+
if (!Array.isArray(pairs))
|
|
804
|
+
return pairs;
|
|
757
805
|
const obj = {};
|
|
758
806
|
for (let i = 0; i < pairs.length - 1; i += 2) {
|
|
759
807
|
const key = pairs[i];
|
|
@@ -765,7 +813,8 @@ function lispPairsToObject(pairs) {
|
|
|
765
813
|
return obj;
|
|
766
814
|
}
|
|
767
815
|
function parseEntity(arr) {
|
|
768
|
-
if (!Array.isArray(arr) || arr.length < 5)
|
|
816
|
+
if (!Array.isArray(arr) || arr.length < 5)
|
|
817
|
+
return null;
|
|
769
818
|
const [type, handle, layer, color, linetype, ...rest] = arr;
|
|
770
819
|
const entity = {
|
|
771
820
|
type: String(type).toUpperCase().replace(/^"|"$/g, ""),
|
|
@@ -792,8 +841,10 @@ function parseEntity(arr) {
|
|
|
792
841
|
}
|
|
793
842
|
function buildEntityCode({ type, layer, bbox }) {
|
|
794
843
|
const items = [];
|
|
795
|
-
if (type)
|
|
796
|
-
|
|
844
|
+
if (type)
|
|
845
|
+
items.push(`(cons 0 "${type.replace(/"/g, '\\"')}")`);
|
|
846
|
+
if (layer)
|
|
847
|
+
items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
|
|
797
848
|
if (bbox) {
|
|
798
849
|
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
799
850
|
if (parts.length === 4) {
|
|
@@ -835,7 +886,8 @@ function buildEntityCode({ type, layer, bbox }) {
|
|
|
835
886
|
}
|
|
836
887
|
function buildTextCode({ layer, bbox, offset, limit }) {
|
|
837
888
|
const items = [`'(0 . "TEXT,MTEXT,ATTRIB,TCH_TEXT")`];
|
|
838
|
-
if (layer)
|
|
889
|
+
if (layer)
|
|
890
|
+
items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
|
|
839
891
|
if (bbox) {
|
|
840
892
|
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
841
893
|
if (parts.length === 4) {
|
|
@@ -886,20 +938,23 @@ var RESOURCES = [
|
|
|
886
938
|
];
|
|
887
939
|
function parseQuery(uri) {
|
|
888
940
|
const qIdx = uri.indexOf("?");
|
|
889
|
-
if (qIdx === -1)
|
|
941
|
+
if (qIdx === -1)
|
|
942
|
+
return { base: uri, params: {} };
|
|
890
943
|
const base = uri.substring(0, qIdx);
|
|
891
944
|
const params = {};
|
|
892
945
|
uri.substring(qIdx + 1).split("&").forEach((p) => {
|
|
893
946
|
const eqIdx = p.indexOf("=");
|
|
894
947
|
const k = eqIdx === -1 ? p : p.substring(0, eqIdx);
|
|
895
948
|
const v = eqIdx === -1 ? "" : p.substring(eqIdx + 1);
|
|
896
|
-
if (k)
|
|
949
|
+
if (k)
|
|
950
|
+
params[k] = decodeURIComponent(v);
|
|
897
951
|
});
|
|
898
952
|
return { base, params };
|
|
899
953
|
}
|
|
900
954
|
function parseTemplateUri(uri) {
|
|
901
955
|
const match = uri.match(/^atlisp:\/\/dwg\/entity\/([^?]+)$/);
|
|
902
|
-
if (match)
|
|
956
|
+
if (match)
|
|
957
|
+
return { type: "entity", handle: match[1] };
|
|
903
958
|
return null;
|
|
904
959
|
}
|
|
905
960
|
async function listResources(subscribedUris = []) {
|
|
@@ -945,8 +1000,10 @@ async function readResource(uri) {
|
|
|
945
1000
|
}
|
|
946
1001
|
}
|
|
947
1002
|
async function getEntityByHandle(handle) {
|
|
948
|
-
if (!cad.connected)
|
|
949
|
-
|
|
1003
|
+
if (!cad.connected)
|
|
1004
|
+
await cad.connect();
|
|
1005
|
+
if (!cad.connected)
|
|
1006
|
+
return { error: "CAD \u672A\u8FDE\u63A5" };
|
|
950
1007
|
const code = `(progn
|
|
951
1008
|
(vl-load-com)
|
|
952
1009
|
(if (setq ent (handent "${handle}"))
|
|
@@ -966,7 +1023,8 @@ async function getEntityByHandle(handle) {
|
|
|
966
1023
|
)`;
|
|
967
1024
|
try {
|
|
968
1025
|
const result = await cad.sendCommandWithResult(code);
|
|
969
|
-
if (!result || result === "nil")
|
|
1026
|
+
if (!result || result === "nil")
|
|
1027
|
+
return { error: `\u672A\u627E\u5230\u5B9E\u4F53: ${handle}` };
|
|
970
1028
|
try {
|
|
971
1029
|
return JSON.parse(result);
|
|
972
1030
|
} catch {
|
|
@@ -978,7 +1036,8 @@ async function getEntityByHandle(handle) {
|
|
|
978
1036
|
}
|
|
979
1037
|
async function getCadInfo() {
|
|
980
1038
|
const cached = getCached("cad:info");
|
|
981
|
-
if (cached)
|
|
1039
|
+
if (cached)
|
|
1040
|
+
return cached;
|
|
982
1041
|
if (!cad.connected) {
|
|
983
1042
|
await cad.connect();
|
|
984
1043
|
}
|
|
@@ -1005,9 +1064,12 @@ async function getCadInfo() {
|
|
|
1005
1064
|
async function getLayers(filterName = null) {
|
|
1006
1065
|
const cacheKey = filterName ? `dwg:layers:${filterName}` : "dwg:layers:all";
|
|
1007
1066
|
const cached = getCached(cacheKey);
|
|
1008
|
-
if (cached)
|
|
1009
|
-
|
|
1010
|
-
if (!cad.connected)
|
|
1067
|
+
if (cached)
|
|
1068
|
+
return cached;
|
|
1069
|
+
if (!cad.connected)
|
|
1070
|
+
await cad.connect();
|
|
1071
|
+
if (!cad.connected)
|
|
1072
|
+
return [];
|
|
1011
1073
|
try {
|
|
1012
1074
|
const code = filterName ? `(vl-prin1-to-string (cdr (assoc 2 (tblnext "LAYER" T))))` : `(progn (setq res nil)(while (setq e (tblnext "LAYER" (null res)))(setq res (cons (list (vl-prin1-to-string (cdr (assoc 2 e))) (cdr (assoc 62 e)) (cdr (assoc 70 e))) res))) (reverse res))`;
|
|
1013
1075
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -1054,8 +1116,10 @@ async function getLayers(filterName = null) {
|
|
|
1054
1116
|
async function getEntities(params = {}) {
|
|
1055
1117
|
const cacheKey = `dwg:entities:${JSON.stringify(params)}`;
|
|
1056
1118
|
const cached = getCached(cacheKey);
|
|
1057
|
-
if (cached)
|
|
1058
|
-
|
|
1119
|
+
if (cached)
|
|
1120
|
+
return cached;
|
|
1121
|
+
if (!cad.connected)
|
|
1122
|
+
await cad.connect();
|
|
1059
1123
|
if (!cad.connected) {
|
|
1060
1124
|
const result = { total: 0, entities: [] };
|
|
1061
1125
|
setCache(cacheKey, result);
|
|
@@ -1157,8 +1221,10 @@ async function getEntitiesSummary(cacheKey) {
|
|
|
1157
1221
|
async function getTexts(params = {}) {
|
|
1158
1222
|
const cacheKey = `dwg:texts:${JSON.stringify(params)}`;
|
|
1159
1223
|
const cached = getCached(cacheKey);
|
|
1160
|
-
if (cached)
|
|
1161
|
-
|
|
1224
|
+
if (cached)
|
|
1225
|
+
return cached;
|
|
1226
|
+
if (!cad.connected)
|
|
1227
|
+
await cad.connect();
|
|
1162
1228
|
if (!cad.connected) {
|
|
1163
1229
|
const result = { total: 0, texts: [] };
|
|
1164
1230
|
setCache(cacheKey, result);
|
|
@@ -1196,8 +1262,10 @@ async function getTexts(params = {}) {
|
|
|
1196
1262
|
}
|
|
1197
1263
|
}
|
|
1198
1264
|
async function getDwgName() {
|
|
1199
|
-
if (!cad.connected)
|
|
1200
|
-
|
|
1265
|
+
if (!cad.connected)
|
|
1266
|
+
await cad.connect();
|
|
1267
|
+
if (!cad.connected)
|
|
1268
|
+
return { name: null };
|
|
1201
1269
|
try {
|
|
1202
1270
|
const code = `(vl-princ-to-string (getvar "dwgname"))`;
|
|
1203
1271
|
const name = await cad.sendCommandWithResult(code);
|
|
@@ -1207,8 +1275,10 @@ async function getDwgName() {
|
|
|
1207
1275
|
}
|
|
1208
1276
|
}
|
|
1209
1277
|
async function getDwgPath() {
|
|
1210
|
-
if (!cad.connected)
|
|
1211
|
-
|
|
1278
|
+
if (!cad.connected)
|
|
1279
|
+
await cad.connect();
|
|
1280
|
+
if (!cad.connected)
|
|
1281
|
+
return { path: null, name: null };
|
|
1212
1282
|
try {
|
|
1213
1283
|
const code = `(progn
|
|
1214
1284
|
(setq prefix (vl-princ-to-string (getvar "dwgprefix")))
|
|
@@ -1226,7 +1296,8 @@ async function getDwgPath() {
|
|
|
1226
1296
|
}
|
|
1227
1297
|
if (!parsed) {
|
|
1228
1298
|
const listResult = parseLispList(result);
|
|
1229
|
-
if (listResult && listResult.length >= 2)
|
|
1299
|
+
if (listResult && listResult.length >= 2)
|
|
1300
|
+
parsed = listResult;
|
|
1230
1301
|
}
|
|
1231
1302
|
if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
|
|
1232
1303
|
return { path: String(parsed[0]), name: String(parsed[1]) };
|
|
@@ -1239,9 +1310,12 @@ async function getDwgPath() {
|
|
|
1239
1310
|
async function getPackages(filterName = null) {
|
|
1240
1311
|
const cacheKey = filterName ? `packages:${filterName}` : "packages:all";
|
|
1241
1312
|
const cached = getCached(cacheKey);
|
|
1242
|
-
if (cached)
|
|
1243
|
-
|
|
1244
|
-
if (!cad.connected)
|
|
1313
|
+
if (cached)
|
|
1314
|
+
return cached;
|
|
1315
|
+
if (!cad.connected)
|
|
1316
|
+
await cad.connect();
|
|
1317
|
+
if (!cad.connected)
|
|
1318
|
+
return [];
|
|
1245
1319
|
try {
|
|
1246
1320
|
const code = `(mapcar 'cdr @::*local-pkgs*)`;
|
|
1247
1321
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -1255,7 +1329,8 @@ async function getPackages(filterName = null) {
|
|
|
1255
1329
|
} catch {
|
|
1256
1330
|
raw = parseLispList(result) || [];
|
|
1257
1331
|
}
|
|
1258
|
-
if (!Array.isArray(raw))
|
|
1332
|
+
if (!Array.isArray(raw))
|
|
1333
|
+
raw = [];
|
|
1259
1334
|
const packages = raw.map((item) => {
|
|
1260
1335
|
if (Array.isArray(item)) {
|
|
1261
1336
|
const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
|
|
@@ -1264,13 +1339,20 @@ async function getPackages(filterName = null) {
|
|
|
1264
1339
|
const [[key, val]] = Object.entries(entry);
|
|
1265
1340
|
const k = String(key);
|
|
1266
1341
|
const v = String(val);
|
|
1267
|
-
if (k === ":NAME")
|
|
1268
|
-
|
|
1269
|
-
else if (k === ":
|
|
1270
|
-
|
|
1271
|
-
else if (k === ":
|
|
1272
|
-
|
|
1273
|
-
else if (k === ":
|
|
1342
|
+
if (k === ":NAME")
|
|
1343
|
+
pkg.name = v;
|
|
1344
|
+
else if (k === ":VERSION")
|
|
1345
|
+
pkg.version = v;
|
|
1346
|
+
else if (k === ":DESCRIPTION")
|
|
1347
|
+
pkg.description = v;
|
|
1348
|
+
else if (k === ":FULL-NAME")
|
|
1349
|
+
pkg.fullName = v;
|
|
1350
|
+
else if (k === ":AUTHOR")
|
|
1351
|
+
pkg.author = v;
|
|
1352
|
+
else if (k === ":CATEGORY")
|
|
1353
|
+
pkg.category = v;
|
|
1354
|
+
else if (k === ":URL")
|
|
1355
|
+
pkg.url = v;
|
|
1274
1356
|
}
|
|
1275
1357
|
}
|
|
1276
1358
|
return pkg;
|
|
@@ -1281,15 +1363,22 @@ async function getPackages(filterName = null) {
|
|
|
1281
1363
|
if (item && typeof item === "object") {
|
|
1282
1364
|
const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
|
|
1283
1365
|
const nameVal = item.name || item.Name || item.NAME || item[":NAME"];
|
|
1284
|
-
if (nameVal)
|
|
1366
|
+
if (nameVal)
|
|
1367
|
+
pkg.name = String(nameVal);
|
|
1285
1368
|
const verVal = item.version || item.Version || item.VERSION || item[":VERSION"];
|
|
1286
|
-
if (verVal)
|
|
1369
|
+
if (verVal)
|
|
1370
|
+
pkg.version = String(verVal);
|
|
1287
1371
|
const descVal = item.description || item.Description || item.DESCRIPTION || item[":DESCRIPTION"];
|
|
1288
|
-
if (descVal)
|
|
1289
|
-
|
|
1290
|
-
if (item.
|
|
1291
|
-
|
|
1292
|
-
if (item.
|
|
1372
|
+
if (descVal)
|
|
1373
|
+
pkg.description = String(descVal);
|
|
1374
|
+
if (item.fullName || item.full_name)
|
|
1375
|
+
pkg.fullName = String(item.fullName || item.full_name);
|
|
1376
|
+
if (item.author || item.Author)
|
|
1377
|
+
pkg.author = String(item.author || item.Author);
|
|
1378
|
+
if (item.category || item.Category)
|
|
1379
|
+
pkg.category = String(item.category || item.Category);
|
|
1380
|
+
if (item.url || item.Url || item.URL)
|
|
1381
|
+
pkg.url = String(item.url || item.Url || item.URL);
|
|
1293
1382
|
return pkg;
|
|
1294
1383
|
}
|
|
1295
1384
|
return null;
|
|
@@ -1315,9 +1404,12 @@ function getPlatforms() {
|
|
|
1315
1404
|
async function getDwgList() {
|
|
1316
1405
|
const cacheKey = "cad:dwgs";
|
|
1317
1406
|
const cached = getCached(cacheKey);
|
|
1318
|
-
if (cached)
|
|
1319
|
-
|
|
1320
|
-
if (!cad.connected)
|
|
1407
|
+
if (cached)
|
|
1408
|
+
return cached;
|
|
1409
|
+
if (!cad.connected)
|
|
1410
|
+
await cad.connect();
|
|
1411
|
+
if (!cad.connected)
|
|
1412
|
+
return [];
|
|
1321
1413
|
try {
|
|
1322
1414
|
const code = `(progn
|
|
1323
1415
|
(vl-load-com)
|
|
@@ -1341,7 +1433,8 @@ async function getDwgList() {
|
|
|
1341
1433
|
parsed = listResult;
|
|
1342
1434
|
}
|
|
1343
1435
|
}
|
|
1344
|
-
if (!Array.isArray(parsed))
|
|
1436
|
+
if (!Array.isArray(parsed))
|
|
1437
|
+
parsed = [];
|
|
1345
1438
|
const dwgList = parsed.map((item) => {
|
|
1346
1439
|
if (Array.isArray(item) && item.length >= 2) {
|
|
1347
1440
|
return { name: String(item[0]), path: String(item[1]) };
|
|
@@ -1368,7 +1461,8 @@ function loadStandardsFile(filename) {
|
|
|
1368
1461
|
var standardsCache = /* @__PURE__ */ new Map();
|
|
1369
1462
|
function getCachedStandards(key) {
|
|
1370
1463
|
const entry = standardsCache.get(key);
|
|
1371
|
-
if (entry && Date.now() - entry.timestamp < 3e4)
|
|
1464
|
+
if (entry && Date.now() - entry.timestamp < 3e4)
|
|
1465
|
+
return entry.data;
|
|
1372
1466
|
standardsCache.delete(key);
|
|
1373
1467
|
return null;
|
|
1374
1468
|
}
|
|
@@ -1377,16 +1471,20 @@ function setCachedStandards(key, data) {
|
|
|
1377
1471
|
}
|
|
1378
1472
|
function getDraftingStandards() {
|
|
1379
1473
|
const cached = getCachedStandards("drafting");
|
|
1380
|
-
if (cached)
|
|
1474
|
+
if (cached)
|
|
1475
|
+
return cached;
|
|
1381
1476
|
const data = loadStandardsFile("drafting.json");
|
|
1382
|
-
if (data)
|
|
1477
|
+
if (data)
|
|
1478
|
+
setCachedStandards("drafting", data);
|
|
1383
1479
|
return data || { error: "\u5236\u56FE\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
|
|
1384
1480
|
}
|
|
1385
1481
|
function getCodingStandards() {
|
|
1386
1482
|
const cached = getCachedStandards("coding");
|
|
1387
|
-
if (cached)
|
|
1483
|
+
if (cached)
|
|
1484
|
+
return cached;
|
|
1388
1485
|
const data = loadStandardsFile("coding.json");
|
|
1389
|
-
if (data)
|
|
1486
|
+
if (data)
|
|
1487
|
+
setCachedStandards("coding", data);
|
|
1390
1488
|
return data || { error: "\u7F16\u7801\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
|
|
1391
1489
|
}
|
|
1392
1490
|
|
|
@@ -1601,9 +1699,11 @@ var SseSession = class {
|
|
|
1601
1699
|
return lines.join("\n") + "\n\n";
|
|
1602
1700
|
}
|
|
1603
1701
|
_setupDrain() {
|
|
1604
|
-
if (typeof this.#res.on !== "function")
|
|
1702
|
+
if (typeof this.#res.on !== "function")
|
|
1703
|
+
return;
|
|
1605
1704
|
this.#drainHandler = () => {
|
|
1606
|
-
if (!this.#active)
|
|
1705
|
+
if (!this.#active)
|
|
1706
|
+
return;
|
|
1607
1707
|
if (this.#backpressureBuffer.length > 0) {
|
|
1608
1708
|
this._drainBuffer();
|
|
1609
1709
|
}
|
|
@@ -1625,7 +1725,8 @@ var SseSession = class {
|
|
|
1625
1725
|
}
|
|
1626
1726
|
}
|
|
1627
1727
|
_write(content) {
|
|
1628
|
-
if (!this.#active)
|
|
1728
|
+
if (!this.#active)
|
|
1729
|
+
return false;
|
|
1629
1730
|
try {
|
|
1630
1731
|
if (this.#backpressureBuffer.length > 0) {
|
|
1631
1732
|
this.#backpressureBuffer.push(content);
|
|
@@ -1753,7 +1854,8 @@ function persistSessionData(clientId, sessionData) {
|
|
|
1753
1854
|
function loadPersistedSessionData(clientId) {
|
|
1754
1855
|
try {
|
|
1755
1856
|
const filePath = getSessionStorePath(clientId);
|
|
1756
|
-
if (!fs4.existsSync(filePath))
|
|
1857
|
+
if (!fs4.existsSync(filePath))
|
|
1858
|
+
return null;
|
|
1757
1859
|
const raw = fs4.readFileSync(filePath, "utf-8");
|
|
1758
1860
|
const store = JSON.parse(raw);
|
|
1759
1861
|
if (Date.now() - store.savedAt > SESSION_STORE_TTL) {
|
|
@@ -1913,7 +2015,8 @@ var SessionTransport = class {
|
|
|
1913
2015
|
this._started = true;
|
|
1914
2016
|
}
|
|
1915
2017
|
async send(message) {
|
|
1916
|
-
if (this._closed)
|
|
2018
|
+
if (this._closed)
|
|
2019
|
+
return;
|
|
1917
2020
|
if (this._pendingRequest) {
|
|
1918
2021
|
const { resolve, reject, timeout } = this._pendingRequest;
|
|
1919
2022
|
clearTimeout(timeout);
|
|
@@ -1922,7 +2025,8 @@ var SessionTransport = class {
|
|
|
1922
2025
|
}
|
|
1923
2026
|
}
|
|
1924
2027
|
async close() {
|
|
1925
|
-
if (this._closed)
|
|
2028
|
+
if (this._closed)
|
|
2029
|
+
return;
|
|
1926
2030
|
this._closed = true;
|
|
1927
2031
|
if (this._pendingRequest) {
|
|
1928
2032
|
const { reject, timeout } = this._pendingRequest;
|
|
@@ -2234,10 +2338,14 @@ ${generateSuggestions(entities, layers)}`
|
|
|
2234
2338
|
}
|
|
2235
2339
|
function generateSuggestions(entities, layers) {
|
|
2236
2340
|
const suggestions = [];
|
|
2237
|
-
if (entities.total > 1e3)
|
|
2238
|
-
|
|
2239
|
-
if (
|
|
2240
|
-
|
|
2341
|
+
if (entities.total > 1e3)
|
|
2342
|
+
suggestions.push("- \u56FE\u7EB8\u5B9E\u4F53\u8F83\u591A\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u56FE\u5C42\u5206\u7C7B\u7BA1\u7406");
|
|
2343
|
+
if (layers.length > 20)
|
|
2344
|
+
suggestions.push("- \u56FE\u5C42\u8F83\u591A\uFF0C\u5EFA\u8BAE\u6E05\u7406\u672A\u4F7F\u7528\u7684\u56FE\u5C42");
|
|
2345
|
+
if (entities.byType.LINE && entities.byType.LINE > 500)
|
|
2346
|
+
suggestions.push("- \u7EBF\u6761\u8F83\u591A\uFF0C\u53EF\u8003\u8651\u4F7F\u7528 BLOCK \u51CF\u5C11\u5B9E\u4F53\u6570\u91CF");
|
|
2347
|
+
if (!entities.byType.DIMENSION)
|
|
2348
|
+
suggestions.push("- \u672A\u53D1\u73B0\u5C3A\u5BF8\u6807\u6CE8\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u6807\u6CE8");
|
|
2241
2349
|
return suggestions.length ? suggestions.join("\n") : "- \u56FE\u7EB8\u7ED3\u6784\u826F\u597D";
|
|
2242
2350
|
}
|
|
2243
2351
|
async function generateBatchLinesPrompt(args) {
|
|
@@ -2782,7 +2890,8 @@ var Metrics = class {
|
|
|
2782
2890
|
bucket.sum += value;
|
|
2783
2891
|
bucket.min = Math.min(bucket.min, value);
|
|
2784
2892
|
bucket.max = Math.max(bucket.max, value);
|
|
2785
|
-
if (!bucket.values)
|
|
2893
|
+
if (!bucket.values)
|
|
2894
|
+
bucket.values = [];
|
|
2786
2895
|
bucket.values.push(value);
|
|
2787
2896
|
this.histograms.set(key, bucket);
|
|
2788
2897
|
}
|
|
@@ -3015,7 +3124,8 @@ async function evalLisp(code, withResult = false, encoding = null) {
|
|
|
3015
3124
|
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3016
3125
|
}
|
|
3017
3126
|
const trimmed = (code || "").trim();
|
|
3018
|
-
if (!trimmed)
|
|
3127
|
+
if (!trimmed)
|
|
3128
|
+
return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3019
3129
|
try {
|
|
3020
3130
|
if (withResult) {
|
|
3021
3131
|
const result = await cad.sendCommandWithResult(trimmed, encoding);
|
|
@@ -3035,14 +3145,17 @@ async function getCadInfo2() {
|
|
|
3035
3145
|
if (!cad.connected) {
|
|
3036
3146
|
await cad.connect();
|
|
3037
3147
|
}
|
|
3038
|
-
if (!cad.connected)
|
|
3148
|
+
if (!cad.connected)
|
|
3149
|
+
return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
|
|
3039
3150
|
const info = await cad.getInfo();
|
|
3040
3151
|
return { content: [{ type: "text", text: info }] };
|
|
3041
3152
|
}
|
|
3042
3153
|
async function atCommand(command) {
|
|
3043
|
-
if (!cad.connected)
|
|
3154
|
+
if (!cad.connected)
|
|
3155
|
+
return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
|
|
3044
3156
|
const trimmed = (command || "").trim();
|
|
3045
|
-
if (!trimmed)
|
|
3157
|
+
if (!trimmed)
|
|
3158
|
+
return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3046
3159
|
await cad.sendCommand(trimmed + "\n");
|
|
3047
3160
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001\u547D\u4EE4" }] };
|
|
3048
3161
|
}
|
|
@@ -3050,7 +3163,8 @@ async function newDocument() {
|
|
|
3050
3163
|
if (!cad.connected) {
|
|
3051
3164
|
await cad.connect();
|
|
3052
3165
|
}
|
|
3053
|
-
if (!cad.connected)
|
|
3166
|
+
if (!cad.connected)
|
|
3167
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3054
3168
|
const result = await cad.newDoc();
|
|
3055
3169
|
if (result) {
|
|
3056
3170
|
return { content: [{ type: "text", text: "\u5DF2\u5728 CAD \u4E2D\u65B0\u5EFA\u7A7A\u767D\u6587\u6863" }] };
|
|
@@ -3061,7 +3175,8 @@ async function bringToFront() {
|
|
|
3061
3175
|
if (!cad.connected) {
|
|
3062
3176
|
await cad.connect();
|
|
3063
3177
|
}
|
|
3064
|
-
if (!cad.connected)
|
|
3178
|
+
if (!cad.connected)
|
|
3179
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3065
3180
|
const result = await cad.bringToFront();
|
|
3066
3181
|
if (result) {
|
|
3067
3182
|
return { content: [{ type: "text", text: "\u5DF2\u5C06 CAD \u7A97\u53E3\u5207\u6362\u5230\u524D\u53F0" }] };
|
|
@@ -3072,7 +3187,8 @@ async function installAtlisp() {
|
|
|
3072
3187
|
if (!cad.connected) {
|
|
3073
3188
|
await cad.connect();
|
|
3074
3189
|
}
|
|
3075
|
-
if (!cad.connected)
|
|
3190
|
+
if (!cad.connected)
|
|
3191
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3076
3192
|
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))))`;
|
|
3077
3193
|
await cad.sendCommand(installCode + "\n");
|
|
3078
3194
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u5B89\u88C5\u4EE3\u7801\u5230 CAD" }] };
|
|
@@ -3081,10 +3197,12 @@ async function listFunctionsInCad() {
|
|
|
3081
3197
|
if (!cad.connected) {
|
|
3082
3198
|
await cad.connect();
|
|
3083
3199
|
}
|
|
3084
|
-
if (!cad.connected)
|
|
3200
|
+
if (!cad.connected)
|
|
3201
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3085
3202
|
try {
|
|
3086
3203
|
const result = await cad.sendCommandWithResult("(atoms-family 0)", null);
|
|
3087
|
-
if (result)
|
|
3204
|
+
if (result)
|
|
3205
|
+
return { content: [{ type: "text", text: result }] };
|
|
3088
3206
|
return { content: [{ type: "text", text: "CAD \u51FD\u6570\u5217\u8868\u4E3A\u7A7A" }] };
|
|
3089
3207
|
} catch (e) {
|
|
3090
3208
|
return { content: [{ type: "text", text: `\u9519\u8BEF: ${e.message}` }], isError: true };
|
|
@@ -3139,7 +3257,8 @@ async function initAtlisp() {
|
|
|
3139
3257
|
if (!cad.connected) {
|
|
3140
3258
|
await cad.connect();
|
|
3141
3259
|
}
|
|
3142
|
-
if (!cad.connected)
|
|
3260
|
+
if (!cad.connected)
|
|
3261
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3143
3262
|
const code = `(if (null @::load-module)
|
|
3144
3263
|
(progn
|
|
3145
3264
|
(vl-load-com)
|
|
@@ -3179,12 +3298,15 @@ async function fetchPackages() {
|
|
|
3179
3298
|
return cachedPackages || MOCK_PACKAGES;
|
|
3180
3299
|
}
|
|
3181
3300
|
function flattenPackages(data) {
|
|
3182
|
-
if (Array.isArray(data))
|
|
3183
|
-
|
|
3301
|
+
if (Array.isArray(data))
|
|
3302
|
+
return data;
|
|
3303
|
+
if (data && Array.isArray(data.packages))
|
|
3304
|
+
return data.packages;
|
|
3184
3305
|
return [];
|
|
3185
3306
|
}
|
|
3186
3307
|
async function listPackages() {
|
|
3187
|
-
if (!cad.connected)
|
|
3308
|
+
if (!cad.connected)
|
|
3309
|
+
await cad.connect();
|
|
3188
3310
|
if (!cad.connected) {
|
|
3189
3311
|
const data2 = await fetchPackages();
|
|
3190
3312
|
const items2 = flattenPackages(data2);
|
|
@@ -3192,7 +3314,8 @@ async function listPackages() {
|
|
|
3192
3314
|
return { content: [{ type: "text", text: text2 }] };
|
|
3193
3315
|
}
|
|
3194
3316
|
const result = await cad.sendCommandWithResult("(@::package-list-in-local)");
|
|
3195
|
-
if (result && result !== "nil")
|
|
3317
|
+
if (result && result !== "nil")
|
|
3318
|
+
return { content: [{ type: "text", text: result }] };
|
|
3196
3319
|
const data = await fetchPackages();
|
|
3197
3320
|
const items = flattenPackages(data);
|
|
3198
3321
|
const text = items.length ? `\u4ECE\u6CE8\u518C\u8868\u83B7\u53D6\u7684 @lisp \u5305:
|
|
@@ -3212,10 +3335,12 @@ async function searchPackages(query) {
|
|
|
3212
3335
|
for (const p of items) {
|
|
3213
3336
|
const name = (p.name || "").toLowerCase();
|
|
3214
3337
|
const desc = (p.description || "").toLowerCase();
|
|
3215
|
-
if (name.includes(q) || desc.includes(q))
|
|
3338
|
+
if (name.includes(q) || desc.includes(q))
|
|
3339
|
+
results.push(p);
|
|
3216
3340
|
}
|
|
3217
3341
|
} else {
|
|
3218
|
-
for (const p of items)
|
|
3342
|
+
for (const p of items)
|
|
3343
|
+
results.push(p);
|
|
3219
3344
|
}
|
|
3220
3345
|
if (results.length === 0) {
|
|
3221
3346
|
return { content: [{ type: "text", text: `\u672A\u627E\u5230\u5305\u542B "${query}" \u7684\u5305` }] };
|
|
@@ -3267,7 +3392,8 @@ function writeCacheToDisk(data) {
|
|
|
3267
3392
|
}
|
|
3268
3393
|
async function fetchFunctions() {
|
|
3269
3394
|
const diskCache = readCacheFromDisk();
|
|
3270
|
-
if (diskCache)
|
|
3395
|
+
if (diskCache)
|
|
3396
|
+
return diskCache;
|
|
3271
3397
|
try {
|
|
3272
3398
|
const response = await fetch(FUNCTIONS_URL, { headers: { "User-Agent": "atlisp-mcp" } });
|
|
3273
3399
|
if (response.ok) {
|
|
@@ -3287,7 +3413,8 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
3287
3413
|
if (data) {
|
|
3288
3414
|
const funcs = Object.values(data.all_functions || {});
|
|
3289
3415
|
const func = funcs.find((f2) => f2.name === funcName || f2.name === `${packageName}:${funcName}`);
|
|
3290
|
-
if (func)
|
|
3416
|
+
if (func)
|
|
3417
|
+
results.push(func);
|
|
3291
3418
|
}
|
|
3292
3419
|
if (results.length === 0 && FUNCTIONS_DIR) {
|
|
3293
3420
|
try {
|
|
@@ -3296,7 +3423,8 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
3296
3423
|
const raw = fs6.readFileSync(path8.join(FUNCTIONS_DIR, file), "utf-8");
|
|
3297
3424
|
const data2 = JSON.parse(raw);
|
|
3298
3425
|
const func = data2.functions?.find((f2) => f2.name === funcName);
|
|
3299
|
-
if (func)
|
|
3426
|
+
if (func)
|
|
3427
|
+
results.push(func);
|
|
3300
3428
|
}
|
|
3301
3429
|
} catch {
|
|
3302
3430
|
}
|
|
@@ -3364,7 +3492,8 @@ async function getEntity(handle) {
|
|
|
3364
3492
|
if (!cad.connected) {
|
|
3365
3493
|
await cad.connect();
|
|
3366
3494
|
}
|
|
3367
|
-
if (!cad.connected)
|
|
3495
|
+
if (!cad.connected)
|
|
3496
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3368
3497
|
const code = `(progn
|
|
3369
3498
|
(vl-load-com)
|
|
3370
3499
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3396,7 +3525,8 @@ async function setEntityProperty(handle, property, value) {
|
|
|
3396
3525
|
if (!cad.connected) {
|
|
3397
3526
|
await cad.connect();
|
|
3398
3527
|
}
|
|
3399
|
-
if (!cad.connected)
|
|
3528
|
+
if (!cad.connected)
|
|
3529
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3400
3530
|
let propCode = "";
|
|
3401
3531
|
switch (property) {
|
|
3402
3532
|
case "layer":
|
|
@@ -3439,7 +3569,8 @@ async function deleteEntity(handle) {
|
|
|
3439
3569
|
if (!cad.connected) {
|
|
3440
3570
|
await cad.connect();
|
|
3441
3571
|
}
|
|
3442
|
-
if (!cad.connected)
|
|
3572
|
+
if (!cad.connected)
|
|
3573
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3443
3574
|
const code = `(progn
|
|
3444
3575
|
(vl-load-com)
|
|
3445
3576
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3464,12 +3595,15 @@ async function selectEntities(filter) {
|
|
|
3464
3595
|
if (!cad.connected) {
|
|
3465
3596
|
await cad.connect();
|
|
3466
3597
|
}
|
|
3467
|
-
if (!cad.connected)
|
|
3598
|
+
if (!cad.connected)
|
|
3599
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3468
3600
|
let filterCode = "nil";
|
|
3469
3601
|
if (filter && (filter.type || filter.layer)) {
|
|
3470
3602
|
const items = [];
|
|
3471
|
-
if (filter.type)
|
|
3472
|
-
|
|
3603
|
+
if (filter.type)
|
|
3604
|
+
items.push(`'(0 . "${filter.type}")`);
|
|
3605
|
+
if (filter.layer)
|
|
3606
|
+
items.push(`'(8 . "${filter.layer}")`);
|
|
3473
3607
|
filterCode = `(list ${items.join(" ")})`;
|
|
3474
3608
|
}
|
|
3475
3609
|
const code = `(progn
|
|
@@ -3501,7 +3635,8 @@ async function createLayer(name, color = 7, linetype = "Continuous") {
|
|
|
3501
3635
|
if (!cad.connected) {
|
|
3502
3636
|
await cad.connect();
|
|
3503
3637
|
}
|
|
3504
|
-
if (!cad.connected)
|
|
3638
|
+
if (!cad.connected)
|
|
3639
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3505
3640
|
const code = `(progn
|
|
3506
3641
|
(vl-load-com)
|
|
3507
3642
|
(if (not (tblsearch "LAYER" "${name}"))
|
|
@@ -3537,7 +3672,8 @@ async function deleteLayer(name) {
|
|
|
3537
3672
|
if (!cad.connected) {
|
|
3538
3673
|
await cad.connect();
|
|
3539
3674
|
}
|
|
3540
|
-
if (!cad.connected)
|
|
3675
|
+
if (!cad.connected)
|
|
3676
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3541
3677
|
const code = `(progn
|
|
3542
3678
|
(vl-load-com)
|
|
3543
3679
|
(cond
|
|
@@ -3571,7 +3707,8 @@ async function setLayerProperty(name, property, value) {
|
|
|
3571
3707
|
if (!cad.connected) {
|
|
3572
3708
|
await cad.connect();
|
|
3573
3709
|
}
|
|
3574
|
-
if (!cad.connected)
|
|
3710
|
+
if (!cad.connected)
|
|
3711
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3575
3712
|
let propCode = "";
|
|
3576
3713
|
switch (property) {
|
|
3577
3714
|
case "color":
|
|
@@ -3619,7 +3756,8 @@ async function setCurrentLayer(name) {
|
|
|
3619
3756
|
if (!cad.connected) {
|
|
3620
3757
|
await cad.connect();
|
|
3621
3758
|
}
|
|
3622
|
-
if (!cad.connected)
|
|
3759
|
+
if (!cad.connected)
|
|
3760
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3623
3761
|
const code = `(progn
|
|
3624
3762
|
(vl-load-com)
|
|
3625
3763
|
(if (tblsearch "LAYER" "${name}")
|
|
@@ -3646,7 +3784,8 @@ async function createBlock(name, entities) {
|
|
|
3646
3784
|
if (!cad.connected) {
|
|
3647
3785
|
await cad.connect();
|
|
3648
3786
|
}
|
|
3649
|
-
if (!cad.connected)
|
|
3787
|
+
if (!cad.connected)
|
|
3788
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3650
3789
|
const code = `(progn
|
|
3651
3790
|
(vl-load-com)
|
|
3652
3791
|
(if (not (tblsearch "BLOCK" "${name}"))
|
|
@@ -3683,7 +3822,8 @@ async function insertBlock(blockName, point, scale = 1, rotation = 0) {
|
|
|
3683
3822
|
if (!cad.connected) {
|
|
3684
3823
|
await cad.connect();
|
|
3685
3824
|
}
|
|
3686
|
-
if (!cad.connected)
|
|
3825
|
+
if (!cad.connected)
|
|
3826
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3687
3827
|
const coords = Array.isArray(point) ? point : point.split(",").map((s) => parseFloat(s.trim()));
|
|
3688
3828
|
if (coords.length < 2) {
|
|
3689
3829
|
return { content: [{ type: "text", text: "\u63D2\u5165\u70B9\u683C\u5F0F\u9519\u8BEF\uFF0C\u9700\u8981 x,y \u6216 [x,y,z]" }], isError: true };
|
|
@@ -3713,7 +3853,8 @@ async function getBlocks() {
|
|
|
3713
3853
|
if (!cad.connected) {
|
|
3714
3854
|
await cad.connect();
|
|
3715
3855
|
}
|
|
3716
|
-
if (!cad.connected)
|
|
3856
|
+
if (!cad.connected)
|
|
3857
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3717
3858
|
const code = `(progn
|
|
3718
3859
|
(vl-load-com)
|
|
3719
3860
|
(setq blocks nil)
|
|
@@ -3736,7 +3877,8 @@ async function explodeBlock(handle) {
|
|
|
3736
3877
|
if (!cad.connected) {
|
|
3737
3878
|
await cad.connect();
|
|
3738
3879
|
}
|
|
3739
|
-
if (!cad.connected)
|
|
3880
|
+
if (!cad.connected)
|
|
3881
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3740
3882
|
const code = `(progn
|
|
3741
3883
|
(vl-load-com)
|
|
3742
3884
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3763,7 +3905,8 @@ async function openDwg(filePath) {
|
|
|
3763
3905
|
if (!cad.connected) {
|
|
3764
3906
|
await cad.connect();
|
|
3765
3907
|
}
|
|
3766
|
-
if (!cad.connected)
|
|
3908
|
+
if (!cad.connected)
|
|
3909
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3767
3910
|
const normalizedPath = filePath.replace(/\\/g, "\\\\");
|
|
3768
3911
|
const code = `(progn
|
|
3769
3912
|
(vl-load-com)
|
|
@@ -3800,7 +3943,8 @@ async function saveDwg(filePath = null) {
|
|
|
3800
3943
|
if (!cad.connected) {
|
|
3801
3944
|
await cad.connect();
|
|
3802
3945
|
}
|
|
3803
|
-
if (!cad.connected)
|
|
3946
|
+
if (!cad.connected)
|
|
3947
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3804
3948
|
const code = filePath ? `(progn
|
|
3805
3949
|
(vl-load-com)
|
|
3806
3950
|
(command "._SAVEAS" "${filePath.replace(/\\/g, "\\\\")}")
|
|
@@ -3824,7 +3968,8 @@ async function exportPdf(outputPath, layout = "Model") {
|
|
|
3824
3968
|
if (!cad.connected) {
|
|
3825
3969
|
await cad.connect();
|
|
3826
3970
|
}
|
|
3827
|
-
if (!cad.connected)
|
|
3971
|
+
if (!cad.connected)
|
|
3972
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3828
3973
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
3829
3974
|
const code = `(progn
|
|
3830
3975
|
(vl-load-com)
|
|
@@ -3852,7 +3997,8 @@ async function closeDwg(save = false) {
|
|
|
3852
3997
|
if (!cad.connected) {
|
|
3853
3998
|
await cad.connect();
|
|
3854
3999
|
}
|
|
3855
|
-
if (!cad.connected)
|
|
4000
|
+
if (!cad.connected)
|
|
4001
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3856
4002
|
const code = `(progn
|
|
3857
4003
|
(vl-load-com)
|
|
3858
4004
|
(if ${save ? "T" : "nil"}
|
|
@@ -3874,7 +4020,8 @@ async function createDimension(type, points, style = {}) {
|
|
|
3874
4020
|
if (!cad.connected) {
|
|
3875
4021
|
await cad.connect();
|
|
3876
4022
|
}
|
|
3877
|
-
if (!cad.connected)
|
|
4023
|
+
if (!cad.connected)
|
|
4024
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3878
4025
|
let dimCode = "";
|
|
3879
4026
|
const validTypes = ["ALIGNED", "LINEAR", "ORDINATE", "RADIAL", "DIAMETER", "ANGULAR"];
|
|
3880
4027
|
const dimType = (type || "ALIGNED").toUpperCase();
|
|
@@ -3916,7 +4063,8 @@ async function getDimensionValue(handle) {
|
|
|
3916
4063
|
if (!cad.connected) {
|
|
3917
4064
|
await cad.connect();
|
|
3918
4065
|
}
|
|
3919
|
-
if (!cad.connected)
|
|
4066
|
+
if (!cad.connected)
|
|
4067
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3920
4068
|
const code = `(progn
|
|
3921
4069
|
(vl-load-com)
|
|
3922
4070
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3947,7 +4095,8 @@ async function createHatch(patternName, boundary, scale = 1, angle = 0) {
|
|
|
3947
4095
|
if (!cad.connected) {
|
|
3948
4096
|
await cad.connect();
|
|
3949
4097
|
}
|
|
3950
|
-
if (!cad.connected)
|
|
4098
|
+
if (!cad.connected)
|
|
4099
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3951
4100
|
const code = `(progn
|
|
3952
4101
|
(vl-load-com)
|
|
3953
4102
|
(command "._BHATCH" "p" "${patternName}" "s" "s" "sc" ${scale} "an" ${angle} "")
|
|
@@ -3967,12 +4116,17 @@ async function setHatchProperties(handle, props) {
|
|
|
3967
4116
|
if (!cad.connected) {
|
|
3968
4117
|
await cad.connect();
|
|
3969
4118
|
}
|
|
3970
|
-
if (!cad.connected)
|
|
4119
|
+
if (!cad.connected)
|
|
4120
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3971
4121
|
let propCode = "";
|
|
3972
|
-
if (props.pattern)
|
|
3973
|
-
|
|
3974
|
-
if (props.
|
|
3975
|
-
|
|
4122
|
+
if (props.pattern)
|
|
4123
|
+
propCode += `(command "._HATCHEDIT" "${handle}" "p" "${props.pattern}")`;
|
|
4124
|
+
if (props.scale)
|
|
4125
|
+
propCode += `(command "._HATCHEDIT" "${handle}" "s" ${props.scale})`;
|
|
4126
|
+
if (props.angle)
|
|
4127
|
+
propCode += `(command "._HATCHEDIT" "${handle}" "an" ${props.angle})`;
|
|
4128
|
+
if (props.color)
|
|
4129
|
+
propCode += `(command "._HATCHEDIT" "${handle}" "c" ${props.color})`;
|
|
3976
4130
|
const code = `(progn
|
|
3977
4131
|
(vl-load-com)
|
|
3978
4132
|
${propCode}
|
|
@@ -3989,7 +4143,8 @@ async function getBlockAttributes(blockHandle) {
|
|
|
3989
4143
|
if (!cad.connected) {
|
|
3990
4144
|
await cad.connect();
|
|
3991
4145
|
}
|
|
3992
|
-
if (!cad.connected)
|
|
4146
|
+
if (!cad.connected)
|
|
4147
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3993
4148
|
const code = `(progn
|
|
3994
4149
|
(vl-load-com)
|
|
3995
4150
|
(if (setq ent (handent "${blockHandle}"))
|
|
@@ -4018,7 +4173,8 @@ async function setBlockAttribute(blockHandle, tag, value) {
|
|
|
4018
4173
|
if (!cad.connected) {
|
|
4019
4174
|
await cad.connect();
|
|
4020
4175
|
}
|
|
4021
|
-
if (!cad.connected)
|
|
4176
|
+
if (!cad.connected)
|
|
4177
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4022
4178
|
const code = `(progn
|
|
4023
4179
|
(vl-load-com)
|
|
4024
4180
|
(if (setq ent (handent "${blockHandle}"))
|
|
@@ -4054,7 +4210,8 @@ async function zoomToExtents() {
|
|
|
4054
4210
|
if (!cad.connected) {
|
|
4055
4211
|
await cad.connect();
|
|
4056
4212
|
}
|
|
4057
|
-
if (!cad.connected)
|
|
4213
|
+
if (!cad.connected)
|
|
4214
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4058
4215
|
const code = `(progn
|
|
4059
4216
|
(vl-load-com)
|
|
4060
4217
|
(command "._ZOOM" "E")
|
|
@@ -4071,7 +4228,8 @@ async function zoomToWindow(p1, p2) {
|
|
|
4071
4228
|
if (!cad.connected) {
|
|
4072
4229
|
await cad.connect();
|
|
4073
4230
|
}
|
|
4074
|
-
if (!cad.connected)
|
|
4231
|
+
if (!cad.connected)
|
|
4232
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4075
4233
|
const code = `(command "._ZOOM" "W" (list ${p1}) (list ${p2}))`;
|
|
4076
4234
|
try {
|
|
4077
4235
|
await cad.sendCommand(code + "\n");
|
|
@@ -4084,7 +4242,8 @@ async function createNamedView(viewName, center = null) {
|
|
|
4084
4242
|
if (!cad.connected) {
|
|
4085
4243
|
await cad.connect();
|
|
4086
4244
|
}
|
|
4087
|
-
if (!cad.connected)
|
|
4245
|
+
if (!cad.connected)
|
|
4246
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4088
4247
|
const code = center ? `(command ".-VIEW" "S" "${viewName}" "C" (list ${center}))` : `(command ".-VIEW" "S" "${viewName}")`;
|
|
4089
4248
|
try {
|
|
4090
4249
|
await cad.sendCommand(code + "\n");
|
|
@@ -4097,7 +4256,8 @@ async function restoreNamedView(viewName) {
|
|
|
4097
4256
|
if (!cad.connected) {
|
|
4098
4257
|
await cad.connect();
|
|
4099
4258
|
}
|
|
4100
|
-
if (!cad.connected)
|
|
4259
|
+
if (!cad.connected)
|
|
4260
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4101
4261
|
const code = `(command ".-VIEW" "R" "${viewName}")`;
|
|
4102
4262
|
try {
|
|
4103
4263
|
await cad.sendCommand(code + "\n");
|
|
@@ -4110,7 +4270,8 @@ async function listNamedViews() {
|
|
|
4110
4270
|
if (!cad.connected) {
|
|
4111
4271
|
await cad.connect();
|
|
4112
4272
|
}
|
|
4113
|
-
if (!cad.connected)
|
|
4273
|
+
if (!cad.connected)
|
|
4274
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4114
4275
|
const code = `(progn
|
|
4115
4276
|
(vl-load-com)
|
|
4116
4277
|
(setq views nil)
|
|
@@ -4130,7 +4291,8 @@ async function exportDxf(outputPath, version2 = "R2018") {
|
|
|
4130
4291
|
if (!cad.connected) {
|
|
4131
4292
|
await cad.connect();
|
|
4132
4293
|
}
|
|
4133
|
-
if (!cad.connected)
|
|
4294
|
+
if (!cad.connected)
|
|
4295
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4134
4296
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4135
4297
|
const versionMap = {
|
|
4136
4298
|
"R2018": "AC1027",
|
|
@@ -4161,7 +4323,8 @@ async function exportDwf(outputPath) {
|
|
|
4161
4323
|
if (!cad.connected) {
|
|
4162
4324
|
await cad.connect();
|
|
4163
4325
|
}
|
|
4164
|
-
if (!cad.connected)
|
|
4326
|
+
if (!cad.connected)
|
|
4327
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4165
4328
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4166
4329
|
const code = `(progn
|
|
4167
4330
|
(vl-load-com)
|
|
@@ -4182,7 +4345,8 @@ async function batchSetLayer(handles, layerName) {
|
|
|
4182
4345
|
if (!cad.connected) {
|
|
4183
4346
|
await cad.connect();
|
|
4184
4347
|
}
|
|
4185
|
-
if (!cad.connected)
|
|
4348
|
+
if (!cad.connected)
|
|
4349
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4186
4350
|
if (!Array.isArray(handles) || handles.length === 0) {
|
|
4187
4351
|
return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
|
|
4188
4352
|
}
|
|
@@ -4207,7 +4371,8 @@ async function createUcs(name, origin = "0,0,0", xAxis = "1,0,0", yAxis = "0,1,0
|
|
|
4207
4371
|
if (!cad.connected) {
|
|
4208
4372
|
await cad.connect();
|
|
4209
4373
|
}
|
|
4210
|
-
if (!cad.connected)
|
|
4374
|
+
if (!cad.connected)
|
|
4375
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4211
4376
|
const code = `(progn
|
|
4212
4377
|
(vl-load-com)
|
|
4213
4378
|
(if (not (tblsearch "UCS" "${name}"))
|
|
@@ -4238,7 +4403,8 @@ async function setUcs(name) {
|
|
|
4238
4403
|
if (!cad.connected) {
|
|
4239
4404
|
await cad.connect();
|
|
4240
4405
|
}
|
|
4241
|
-
if (!cad.connected)
|
|
4406
|
+
if (!cad.connected)
|
|
4407
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4242
4408
|
const code = `(progn
|
|
4243
4409
|
(vl-load-com)
|
|
4244
4410
|
(if (tblsearch "UCS" "${name}")
|
|
@@ -4263,7 +4429,8 @@ async function listUcs() {
|
|
|
4263
4429
|
if (!cad.connected) {
|
|
4264
4430
|
await cad.connect();
|
|
4265
4431
|
}
|
|
4266
|
-
if (!cad.connected)
|
|
4432
|
+
if (!cad.connected)
|
|
4433
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4267
4434
|
const code = `(progn
|
|
4268
4435
|
(vl-load-com)
|
|
4269
4436
|
(setq ucsList nil)
|
|
@@ -4286,7 +4453,8 @@ async function deleteUcs(name) {
|
|
|
4286
4453
|
if (!cad.connected) {
|
|
4287
4454
|
await cad.connect();
|
|
4288
4455
|
}
|
|
4289
|
-
if (!cad.connected)
|
|
4456
|
+
if (!cad.connected)
|
|
4457
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4290
4458
|
const code = `(progn
|
|
4291
4459
|
(vl-load-com)
|
|
4292
4460
|
(if (tblsearch "UCS" "${name}")
|
|
@@ -4311,7 +4479,8 @@ async function getCurrentUcs() {
|
|
|
4311
4479
|
if (!cad.connected) {
|
|
4312
4480
|
await cad.connect();
|
|
4313
4481
|
}
|
|
4314
|
-
if (!cad.connected)
|
|
4482
|
+
if (!cad.connected)
|
|
4483
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4315
4484
|
const code = `(progn
|
|
4316
4485
|
(vl-load-com)
|
|
4317
4486
|
(vla-get-activeutilities (vla-get-document (vla-get-application (vlax-get-acad-object))))
|
|
@@ -4328,7 +4497,8 @@ async function createLayout(name) {
|
|
|
4328
4497
|
if (!cad.connected) {
|
|
4329
4498
|
await cad.connect();
|
|
4330
4499
|
}
|
|
4331
|
-
if (!cad.connected)
|
|
4500
|
+
if (!cad.connected)
|
|
4501
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4332
4502
|
const code = `(progn
|
|
4333
4503
|
(vl-load-com)
|
|
4334
4504
|
(if (not (tblsearch "LAYOUT" "${name}"))
|
|
@@ -4356,7 +4526,8 @@ async function setLayout(name) {
|
|
|
4356
4526
|
if (!cad.connected) {
|
|
4357
4527
|
await cad.connect();
|
|
4358
4528
|
}
|
|
4359
|
-
if (!cad.connected)
|
|
4529
|
+
if (!cad.connected)
|
|
4530
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4360
4531
|
const code = `(progn
|
|
4361
4532
|
(vl-load-com)
|
|
4362
4533
|
(vlax-for layout (vla-get-layouts (vla-get-activedocument (vla-get-application (vlax-get-acad-object))))
|
|
@@ -4386,7 +4557,8 @@ async function listLayouts() {
|
|
|
4386
4557
|
if (!cad.connected) {
|
|
4387
4558
|
await cad.connect();
|
|
4388
4559
|
}
|
|
4389
|
-
if (!cad.connected)
|
|
4560
|
+
if (!cad.connected)
|
|
4561
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4390
4562
|
const code = `(progn
|
|
4391
4563
|
(vl-load-com)
|
|
4392
4564
|
(setq layouts nil)
|
|
@@ -4409,7 +4581,8 @@ async function deleteLayout(name) {
|
|
|
4409
4581
|
if (!cad.connected) {
|
|
4410
4582
|
await cad.connect();
|
|
4411
4583
|
}
|
|
4412
|
-
if (!cad.connected)
|
|
4584
|
+
if (!cad.connected)
|
|
4585
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4413
4586
|
if (name === "Model" || name === "\u6A21\u578B") {
|
|
4414
4587
|
return { content: [{ type: "text", text: "\u65E0\u6CD5\u5220\u9664\u6A21\u578B\u7A7A\u95F4" }], isError: true };
|
|
4415
4588
|
}
|
|
@@ -4437,7 +4610,8 @@ async function getCurrentLayout() {
|
|
|
4437
4610
|
if (!cad.connected) {
|
|
4438
4611
|
await cad.connect();
|
|
4439
4612
|
}
|
|
4440
|
-
if (!cad.connected)
|
|
4613
|
+
if (!cad.connected)
|
|
4614
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4441
4615
|
const code = `(vl-prin1-to-string (getvar "CTAB"))`;
|
|
4442
4616
|
try {
|
|
4443
4617
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -4450,7 +4624,8 @@ async function renameLayout(oldName, newName) {
|
|
|
4450
4624
|
if (!cad.connected) {
|
|
4451
4625
|
await cad.connect();
|
|
4452
4626
|
}
|
|
4453
|
-
if (!cad.connected)
|
|
4627
|
+
if (!cad.connected)
|
|
4628
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4454
4629
|
const code = `(progn
|
|
4455
4630
|
(vl-load-com)
|
|
4456
4631
|
(if (tblsearch "LAYOUT" "${oldName}")
|
|
@@ -4477,7 +4652,8 @@ async function plotToPdf(outputPath, layout = "Model", style = {}) {
|
|
|
4477
4652
|
if (!cad.connected) {
|
|
4478
4653
|
await cad.connect();
|
|
4479
4654
|
}
|
|
4480
|
-
if (!cad.connected)
|
|
4655
|
+
if (!cad.connected)
|
|
4656
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4481
4657
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4482
4658
|
const paperSize = style.paperSize || "A4";
|
|
4483
4659
|
const plotScale = style.plotScale || "1:1";
|
|
@@ -4510,7 +4686,8 @@ async function plotToPrinter(printerName, layout = "Model") {
|
|
|
4510
4686
|
if (!cad.connected) {
|
|
4511
4687
|
await cad.connect();
|
|
4512
4688
|
}
|
|
4513
|
-
if (!cad.connected)
|
|
4689
|
+
if (!cad.connected)
|
|
4690
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4514
4691
|
const code = `(progn
|
|
4515
4692
|
(vl-load-com)
|
|
4516
4693
|
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
|
|
@@ -4536,7 +4713,8 @@ async function createGroup(name, handles) {
|
|
|
4536
4713
|
if (!cad.connected) {
|
|
4537
4714
|
await cad.connect();
|
|
4538
4715
|
}
|
|
4539
|
-
if (!cad.connected)
|
|
4716
|
+
if (!cad.connected)
|
|
4717
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4540
4718
|
if (!Array.isArray(handles) || handles.length === 0) {
|
|
4541
4719
|
return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
|
|
4542
4720
|
}
|
|
@@ -4562,7 +4740,8 @@ async function deleteGroup(name) {
|
|
|
4562
4740
|
if (!cad.connected) {
|
|
4563
4741
|
await cad.connect();
|
|
4564
4742
|
}
|
|
4565
|
-
if (!cad.connected)
|
|
4743
|
+
if (!cad.connected)
|
|
4744
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4566
4745
|
const code = `(progn
|
|
4567
4746
|
(vl-load-com)
|
|
4568
4747
|
(if (tblsearch "GROUP" "${name}")
|
|
@@ -4587,7 +4766,8 @@ async function listGroups() {
|
|
|
4587
4766
|
if (!cad.connected) {
|
|
4588
4767
|
await cad.connect();
|
|
4589
4768
|
}
|
|
4590
|
-
if (!cad.connected)
|
|
4769
|
+
if (!cad.connected)
|
|
4770
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4591
4771
|
const code = `(progn
|
|
4592
4772
|
(vl-load-com)
|
|
4593
4773
|
(setq groups nil)
|
|
@@ -4607,7 +4787,8 @@ async function getGroupEntities(groupName) {
|
|
|
4607
4787
|
if (!cad.connected) {
|
|
4608
4788
|
await cad.connect();
|
|
4609
4789
|
}
|
|
4610
|
-
if (!cad.connected)
|
|
4790
|
+
if (!cad.connected)
|
|
4791
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4611
4792
|
const code = `(progn
|
|
4612
4793
|
(vl-load-com)
|
|
4613
4794
|
(if (tblsearch "GROUP" "${groupName}")
|
|
@@ -4645,7 +4826,8 @@ async function measureDistance(p1, p2) {
|
|
|
4645
4826
|
if (!cad.connected) {
|
|
4646
4827
|
await cad.connect();
|
|
4647
4828
|
}
|
|
4648
|
-
if (!cad.connected)
|
|
4829
|
+
if (!cad.connected)
|
|
4830
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4649
4831
|
const code = `(progn
|
|
4650
4832
|
(vl-load-com)
|
|
4651
4833
|
(setq pt1 (list ${p1}) pt2 (list ${p2}))
|
|
@@ -4669,7 +4851,8 @@ async function measureArea(points) {
|
|
|
4669
4851
|
if (!cad.connected) {
|
|
4670
4852
|
await cad.connect();
|
|
4671
4853
|
}
|
|
4672
|
-
if (!cad.connected)
|
|
4854
|
+
if (!cad.connected)
|
|
4855
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4673
4856
|
const pts = Array.isArray(points) ? points : points.split(/[\s,]+/).filter(Boolean);
|
|
4674
4857
|
if (pts.length < 3) {
|
|
4675
4858
|
return { content: [{ type: "text", text: "\u81F3\u5C11\u9700\u8981 3 \u4E2A\u70B9" }], isError: true };
|
|
@@ -4706,7 +4889,8 @@ async function getEntityInfo(handle) {
|
|
|
4706
4889
|
if (!cad.connected) {
|
|
4707
4890
|
await cad.connect();
|
|
4708
4891
|
}
|
|
4709
|
-
if (!cad.connected)
|
|
4892
|
+
if (!cad.connected)
|
|
4893
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4710
4894
|
const code = `(progn
|
|
4711
4895
|
(vl-load-com)
|
|
4712
4896
|
(if (setq ent (handent "${handle}"))
|
|
@@ -4741,7 +4925,8 @@ async function ensureConnected() {
|
|
|
4741
4925
|
if (!cad.connected) {
|
|
4742
4926
|
await cad.connect();
|
|
4743
4927
|
}
|
|
4744
|
-
if (!cad.connected)
|
|
4928
|
+
if (!cad.connected)
|
|
4929
|
+
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
4745
4930
|
}
|
|
4746
4931
|
function parseHandleList(handles) {
|
|
4747
4932
|
if (typeof handles === "string") {
|
|
@@ -4982,7 +5167,8 @@ async function ensureConnected2() {
|
|
|
4982
5167
|
if (!cad.connected) {
|
|
4983
5168
|
await cad.connect();
|
|
4984
5169
|
}
|
|
4985
|
-
if (!cad.connected)
|
|
5170
|
+
if (!cad.connected)
|
|
5171
|
+
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
4986
5172
|
}
|
|
4987
5173
|
async function getXdata(handle, appName = "ACAD") {
|
|
4988
5174
|
await ensureConnected2();
|
|
@@ -5188,10 +5374,11 @@ async function searchByXdata(appName, key, value) {
|
|
|
5188
5374
|
async function exportXdataToFile(handle, filePath) {
|
|
5189
5375
|
await ensureConnected2();
|
|
5190
5376
|
const xdata = await getAllEntityXdata(handle);
|
|
5191
|
-
if (!xdata.success)
|
|
5377
|
+
if (!xdata.success)
|
|
5378
|
+
return xdata;
|
|
5192
5379
|
try {
|
|
5193
|
-
const
|
|
5194
|
-
|
|
5380
|
+
const fs9 = await import("fs");
|
|
5381
|
+
fs9.writeFileSync(filePath, JSON.stringify(xdata.xdata, null, 2));
|
|
5195
5382
|
return { handle, filePath, success: true };
|
|
5196
5383
|
} catch (e) {
|
|
5197
5384
|
return { error: e.message, success: false };
|
|
@@ -5200,8 +5387,8 @@ async function exportXdataToFile(handle, filePath) {
|
|
|
5200
5387
|
async function importXdataFromFile(handle, filePath, appName) {
|
|
5201
5388
|
await ensureConnected2();
|
|
5202
5389
|
try {
|
|
5203
|
-
const
|
|
5204
|
-
const data =
|
|
5390
|
+
const fs9 = await import("fs");
|
|
5391
|
+
const data = fs9.readFileSync(filePath, "utf8");
|
|
5205
5392
|
const xdata = JSON.parse(data);
|
|
5206
5393
|
if (appName && xdata[appName]) {
|
|
5207
5394
|
return await setXdata(handle, appName, xdata[appName]);
|
|
@@ -5221,7 +5408,8 @@ async function ensureConnected3() {
|
|
|
5221
5408
|
if (!cad.connected) {
|
|
5222
5409
|
await cad.connect();
|
|
5223
5410
|
}
|
|
5224
|
-
if (!cad.connected)
|
|
5411
|
+
if (!cad.connected)
|
|
5412
|
+
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5225
5413
|
}
|
|
5226
5414
|
async function createSheetSet(name, description = "") {
|
|
5227
5415
|
await ensureConnected3();
|
|
@@ -5422,11 +5610,14 @@ async function ensureConnected4() {
|
|
|
5422
5610
|
if (!cad.connected) {
|
|
5423
5611
|
await cad.connect();
|
|
5424
5612
|
}
|
|
5425
|
-
if (!cad.connected)
|
|
5613
|
+
if (!cad.connected)
|
|
5614
|
+
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5426
5615
|
}
|
|
5427
5616
|
function parsePoint(point) {
|
|
5428
|
-
if (Array.isArray(point))
|
|
5429
|
-
|
|
5617
|
+
if (Array.isArray(point))
|
|
5618
|
+
return point.join(" ");
|
|
5619
|
+
if (typeof point === "string")
|
|
5620
|
+
return point;
|
|
5430
5621
|
return "0,0,0";
|
|
5431
5622
|
}
|
|
5432
5623
|
async function createBox(center, length, width, height) {
|
|
@@ -5686,7 +5877,8 @@ async function ensureConnected5() {
|
|
|
5686
5877
|
if (!cad.connected) {
|
|
5687
5878
|
await cad.connect();
|
|
5688
5879
|
}
|
|
5689
|
-
if (!cad.connected)
|
|
5880
|
+
if (!cad.connected)
|
|
5881
|
+
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5690
5882
|
}
|
|
5691
5883
|
async function createDimensionStyle(name, color = "bylayer", arrow = "ClosedFilled", textStyle = "") {
|
|
5692
5884
|
await ensureConnected5();
|
|
@@ -5912,7 +6104,8 @@ async function ensureConnected6() {
|
|
|
5912
6104
|
if (!cad.connected) {
|
|
5913
6105
|
await cad.connect();
|
|
5914
6106
|
}
|
|
5915
|
-
if (!cad.connected)
|
|
6107
|
+
if (!cad.connected)
|
|
6108
|
+
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5916
6109
|
}
|
|
5917
6110
|
async function attachPdf(point, pdfPath, scale = 1, rotation = 0) {
|
|
5918
6111
|
await ensureConnected6();
|
|
@@ -6352,7 +6545,8 @@ function validateToolArgs(name, args) {
|
|
|
6352
6545
|
const baseType = type.replace("?", "");
|
|
6353
6546
|
const val = args[key];
|
|
6354
6547
|
if (val === void 0 || val === null) {
|
|
6355
|
-
if (isOptional)
|
|
6548
|
+
if (isOptional)
|
|
6549
|
+
continue;
|
|
6356
6550
|
throw new Error(`Missing required argument: ${key}`);
|
|
6357
6551
|
}
|
|
6358
6552
|
const actualType = typeof args[key];
|
|
@@ -6397,7 +6591,8 @@ ${CAD_PLATFORMS.join("\n")}
|
|
|
6397
6591
|
},
|
|
6398
6592
|
import_funlib: async (a) => {
|
|
6399
6593
|
const data = await loadAtlibFunctionLib();
|
|
6400
|
-
if (!data)
|
|
6594
|
+
if (!data)
|
|
6595
|
+
return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
|
|
6401
6596
|
if (a.format === "list") {
|
|
6402
6597
|
const items = Object.values(data.all_functions || {}).map((f) => `${f.name}: ${f.description || ""}`);
|
|
6403
6598
|
return { content: [{ type: "text", text: items.join("\n") }] };
|
|
@@ -8220,7 +8415,8 @@ function notifyResourceChanges(toolName) {
|
|
|
8220
8415
|
}
|
|
8221
8416
|
async function handleToolCall(name, args) {
|
|
8222
8417
|
const handler = TOOL_HANDLERS[name];
|
|
8223
|
-
if (!handler)
|
|
8418
|
+
if (!handler)
|
|
8419
|
+
return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
|
|
8224
8420
|
try {
|
|
8225
8421
|
validateToolArgs(name, args || {});
|
|
8226
8422
|
const result = await handler(args || {});
|
|
@@ -8280,10 +8476,12 @@ var RateLimiter = class {
|
|
|
8280
8476
|
this.keyLimits = /* @__PURE__ */ new Map();
|
|
8281
8477
|
}
|
|
8282
8478
|
getKeyLimit(apiKey2) {
|
|
8283
|
-
if (!apiKey2)
|
|
8479
|
+
if (!apiKey2)
|
|
8480
|
+
return this.defaultLimit;
|
|
8284
8481
|
if (config_default.apiKeys && config_default.apiKeys.length > 0) {
|
|
8285
8482
|
const found = config_default.apiKeys.find((k) => k.key === apiKey2);
|
|
8286
|
-
if (found)
|
|
8483
|
+
if (found)
|
|
8484
|
+
return found.limit;
|
|
8287
8485
|
}
|
|
8288
8486
|
if (config_default.apiKey && apiKey2 === config_default.apiKey) {
|
|
8289
8487
|
return config_default.apiKeyRateLimit || 1e3;
|
|
@@ -8291,10 +8489,12 @@ var RateLimiter = class {
|
|
|
8291
8489
|
return this.defaultLimit;
|
|
8292
8490
|
}
|
|
8293
8491
|
getKeyInfo(apiKey2) {
|
|
8294
|
-
if (!apiKey2)
|
|
8492
|
+
if (!apiKey2)
|
|
8493
|
+
return { name: "anonymous", limit: this.defaultLimit };
|
|
8295
8494
|
if (config_default.apiKeys && config_default.apiKeys.length > 0) {
|
|
8296
8495
|
const found = config_default.apiKeys.find((k) => k.key === apiKey2);
|
|
8297
|
-
if (found)
|
|
8496
|
+
if (found)
|
|
8497
|
+
return { name: found.name || apiKey2, limit: found.limit };
|
|
8298
8498
|
}
|
|
8299
8499
|
if (config_default.apiKey && apiKey2 === config_default.apiKey) {
|
|
8300
8500
|
return { name: "admin", limit: config_default.apiKeyRateLimit || 1e3 };
|
|
@@ -8390,7 +8590,8 @@ var JSON_CONTENT_TYPES = ["application/json", "application/json-rpc", "applicati
|
|
|
8390
8590
|
function createJsonBodyParser() {
|
|
8391
8591
|
return async (req, res, next) => {
|
|
8392
8592
|
const ct = (req.headers["content-type"] || "").toLowerCase();
|
|
8393
|
-
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
|
|
8593
|
+
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
|
|
8594
|
+
return next();
|
|
8394
8595
|
try {
|
|
8395
8596
|
const chunks = [];
|
|
8396
8597
|
for await (const chunk of req) {
|
|
@@ -8423,9 +8624,11 @@ function createAuthMiddleware() {
|
|
|
8423
8624
|
const PUBLIC_PATHS = ["/health"];
|
|
8424
8625
|
return (req, res, next) => {
|
|
8425
8626
|
if (apiKey) {
|
|
8426
|
-
if (PUBLIC_PATHS.includes(req.path))
|
|
8627
|
+
if (PUBLIC_PATHS.includes(req.path))
|
|
8628
|
+
return next();
|
|
8427
8629
|
const auth = req.get("Authorization");
|
|
8428
|
-
if (auth === `Bearer ${apiKey}`)
|
|
8630
|
+
if (auth === `Bearer ${apiKey}`)
|
|
8631
|
+
return next();
|
|
8429
8632
|
return res.status(401).json({ error: "Unauthorized" });
|
|
8430
8633
|
}
|
|
8431
8634
|
next();
|
|
@@ -8433,14 +8636,16 @@ function createAuthMiddleware() {
|
|
|
8433
8636
|
}
|
|
8434
8637
|
function createCorsMiddleware() {
|
|
8435
8638
|
return (req, res, next) => {
|
|
8436
|
-
if (!enableCors)
|
|
8639
|
+
if (!enableCors)
|
|
8640
|
+
return next();
|
|
8437
8641
|
res.setHeader("Access-Control-Allow-Origin", corsOrigin);
|
|
8438
8642
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, CONNECT");
|
|
8439
8643
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, mcp-session-id, last-event-id");
|
|
8440
8644
|
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id, content-type, x-accel-buffering");
|
|
8441
8645
|
res.setHeader("Access-Control-Max-Age", "86400");
|
|
8442
8646
|
res.setHeader("Vary", "Accept");
|
|
8443
|
-
if (req.method === "OPTIONS")
|
|
8647
|
+
if (req.method === "OPTIONS")
|
|
8648
|
+
return res.status(204).end();
|
|
8444
8649
|
next();
|
|
8445
8650
|
};
|
|
8446
8651
|
}
|
|
@@ -8852,7 +9057,8 @@ For more info: https://atlisp.cn
|
|
|
8852
9057
|
}
|
|
8853
9058
|
}
|
|
8854
9059
|
}
|
|
8855
|
-
if (config_default.apiKey)
|
|
9060
|
+
if (config_default.apiKey)
|
|
9061
|
+
log("API Key authentication enabled");
|
|
8856
9062
|
async function initCadConnection() {
|
|
8857
9063
|
log("Attempting to connect to CAD on startup...");
|
|
8858
9064
|
try {
|