@atlisp/mcp 1.6.7 → 1.6.9
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 +545 -578
- package/dist/cad-worker.js +10 -10
- package/package.json +1 -1
package/dist/atlisp-mcp.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
// src/atlisp-mcp.js
|
|
4
4
|
import path10 from "path";
|
|
5
|
-
import fs8 from "fs";
|
|
6
5
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
7
6
|
import { createRequire } from "module";
|
|
8
7
|
import express2 from "express";
|
|
@@ -23,7 +22,7 @@ var FILE_EXTENSIONS = {
|
|
|
23
22
|
"BricsCAD": [".des"]
|
|
24
23
|
};
|
|
25
24
|
var SERVER_NAME = "atlisp-mcp-server";
|
|
26
|
-
var SERVER_VERSION = "1.6.
|
|
25
|
+
var SERVER_VERSION = "1.6.4";
|
|
27
26
|
var MOCK_PACKAGES = [
|
|
28
27
|
{ name: "base", description: "\u57FA\u7840\u51FD\u6570\u5E93", version: "1.0.0" },
|
|
29
28
|
{ name: "at-pm", description: "\u5DE5\u7A0B\u9879\u76EE\u7BA1\u7406", version: "2.1.0" },
|
|
@@ -116,8 +115,7 @@ function parseArgs() {
|
|
|
116
115
|
return result;
|
|
117
116
|
}
|
|
118
117
|
function loadConfigFile(filePath) {
|
|
119
|
-
if (!filePath || !fs.existsSync(filePath))
|
|
120
|
-
return null;
|
|
118
|
+
if (!filePath || !fs.existsSync(filePath)) return null;
|
|
121
119
|
try {
|
|
122
120
|
const raw = fs.readFileSync(filePath, "utf-8");
|
|
123
121
|
const parsed = JSON.parse(raw);
|
|
@@ -255,8 +253,7 @@ function setupStdoutHandler(w) {
|
|
|
255
253
|
const lines = buffer.split("\n");
|
|
256
254
|
buffer = lines.pop() || "";
|
|
257
255
|
for (const line of lines) {
|
|
258
|
-
if (!line.trim())
|
|
259
|
-
continue;
|
|
256
|
+
if (!line.trim()) continue;
|
|
260
257
|
try {
|
|
261
258
|
const result = JSON.parse(line);
|
|
262
259
|
const rid = result.requestId;
|
|
@@ -282,8 +279,7 @@ function setupStdoutHandler(w) {
|
|
|
282
279
|
}
|
|
283
280
|
function getWorker(force = false) {
|
|
284
281
|
if (!worker || !worker.connected || force) {
|
|
285
|
-
if (worker)
|
|
286
|
-
worker.kill();
|
|
282
|
+
if (worker) worker.kill();
|
|
287
283
|
worker = spawn("node", [workerPath], {
|
|
288
284
|
stdio: ["pipe", "pipe", "pipe"]
|
|
289
285
|
});
|
|
@@ -291,8 +287,7 @@ function getWorker(force = false) {
|
|
|
291
287
|
const w = worker;
|
|
292
288
|
w.on("exit", (code) => {
|
|
293
289
|
console.error("worker exited with code:", code);
|
|
294
|
-
if (w !== worker)
|
|
295
|
-
return;
|
|
290
|
+
if (w !== worker) return;
|
|
296
291
|
w.connected = false;
|
|
297
292
|
for (const [id, { reject, timeout }] of pendingRequests) {
|
|
298
293
|
clearTimeout(timeout);
|
|
@@ -313,8 +308,7 @@ function getWorker(force = false) {
|
|
|
313
308
|
return worker;
|
|
314
309
|
}
|
|
315
310
|
function startHeartbeat() {
|
|
316
|
-
if (heartbeatTimer)
|
|
317
|
-
clearInterval(heartbeatTimer);
|
|
311
|
+
if (heartbeatTimer) clearInterval(heartbeatTimer);
|
|
318
312
|
heartbeatTimer = setInterval(async () => {
|
|
319
313
|
try {
|
|
320
314
|
const result = await sendMessage({ type: "ping" });
|
|
@@ -359,8 +353,7 @@ var CadConnection = class {
|
|
|
359
353
|
return process.platform === "win32";
|
|
360
354
|
}
|
|
361
355
|
async connect(platform = null) {
|
|
362
|
-
if (!this.isAvailable())
|
|
363
|
-
return false;
|
|
356
|
+
if (!this.isAvailable()) return false;
|
|
364
357
|
try {
|
|
365
358
|
const msg = platform ? { type: "connect", platform } : { type: "connect" };
|
|
366
359
|
const result = await sendMessage(msg);
|
|
@@ -377,16 +370,13 @@ var CadConnection = class {
|
|
|
377
370
|
return false;
|
|
378
371
|
}
|
|
379
372
|
async sendCommand(code) {
|
|
380
|
-
if (!this.connected)
|
|
381
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
373
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
382
374
|
const result = await sendMessage({ type: "send", code, platform: _platform });
|
|
383
|
-
if (result.success)
|
|
384
|
-
return true;
|
|
375
|
+
if (result.success) return true;
|
|
385
376
|
throw new Error(result.error || "\u53D1\u9001\u5931\u8D25");
|
|
386
377
|
}
|
|
387
378
|
async sendCommandWithResult(code, encoding = null) {
|
|
388
|
-
if (!this.connected)
|
|
389
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
379
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
390
380
|
const result = await sendMessage({ type: "sendResult", code, platform: _platform, encoding: encoding || "" });
|
|
391
381
|
if (result.success) {
|
|
392
382
|
return result.result || "";
|
|
@@ -400,8 +390,7 @@ var CadConnection = class {
|
|
|
400
390
|
return this.product;
|
|
401
391
|
}
|
|
402
392
|
async isBusy() {
|
|
403
|
-
if (!this.connected)
|
|
404
|
-
return false;
|
|
393
|
+
if (!this.connected) return false;
|
|
405
394
|
try {
|
|
406
395
|
const result = await sendMessage({ type: "isBusy", platform: _platform });
|
|
407
396
|
return result && result.isBusy;
|
|
@@ -410,8 +399,7 @@ var CadConnection = class {
|
|
|
410
399
|
}
|
|
411
400
|
}
|
|
412
401
|
async hasDoc() {
|
|
413
|
-
if (!this.connected)
|
|
414
|
-
return { hasDoc: false, docCount: 0 };
|
|
402
|
+
if (!this.connected) return { hasDoc: false, docCount: 0 };
|
|
415
403
|
try {
|
|
416
404
|
const result = await sendMessage({ type: "hasdoc", platform: _platform });
|
|
417
405
|
return result || { hasDoc: false, docCount: 0 };
|
|
@@ -420,8 +408,7 @@ var CadConnection = class {
|
|
|
420
408
|
}
|
|
421
409
|
}
|
|
422
410
|
async newDoc() {
|
|
423
|
-
if (!this.connected)
|
|
424
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
411
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
425
412
|
try {
|
|
426
413
|
const result = await sendMessage({ type: "newdoc", platform: _platform });
|
|
427
414
|
return result && result.success;
|
|
@@ -430,8 +417,7 @@ var CadConnection = class {
|
|
|
430
417
|
}
|
|
431
418
|
}
|
|
432
419
|
async bringToFront() {
|
|
433
|
-
if (!this.connected)
|
|
434
|
-
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
420
|
+
if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
435
421
|
try {
|
|
436
422
|
const result = await sendMessage({ type: "bringToFront", platform: _platform });
|
|
437
423
|
return result && result.success;
|
|
@@ -440,8 +426,7 @@ var CadConnection = class {
|
|
|
440
426
|
}
|
|
441
427
|
}
|
|
442
428
|
async getInfo() {
|
|
443
|
-
if (!this.connected)
|
|
444
|
-
return "CAD \u672A\u8FDE\u63A5";
|
|
429
|
+
if (!this.connected) return "CAD \u672A\u8FDE\u63A5";
|
|
445
430
|
return `Platform: ${this.product}, Version: ${this.version}, Status: Connected`;
|
|
446
431
|
}
|
|
447
432
|
async disconnect() {
|
|
@@ -478,11 +463,9 @@ var MAX_LOG_SIZE = 10 * 1024 * 1024;
|
|
|
478
463
|
var MAX_LOG_FILES = 5;
|
|
479
464
|
var stream = null;
|
|
480
465
|
function rotateLog() {
|
|
481
|
-
if (!fs2.existsSync(DEBUG_FILE))
|
|
482
|
-
return;
|
|
466
|
+
if (!fs2.existsSync(DEBUG_FILE)) return;
|
|
483
467
|
const stat = fs2.statSync(DEBUG_FILE);
|
|
484
|
-
if (stat.size < MAX_LOG_SIZE)
|
|
485
|
-
return;
|
|
468
|
+
if (stat.size < MAX_LOG_SIZE) return;
|
|
486
469
|
if (stream) {
|
|
487
470
|
stream.end();
|
|
488
471
|
stream = null;
|
|
@@ -546,11 +529,9 @@ function ensureRequestLogDir() {
|
|
|
546
529
|
}
|
|
547
530
|
}
|
|
548
531
|
function rotateRequestLog() {
|
|
549
|
-
if (!fs2.existsSync(REQUEST_LOG_FILE))
|
|
550
|
-
return;
|
|
532
|
+
if (!fs2.existsSync(REQUEST_LOG_FILE)) return;
|
|
551
533
|
const stat = fs2.statSync(REQUEST_LOG_FILE);
|
|
552
|
-
if (stat.size < 10 * 1024 * 1024)
|
|
553
|
-
return;
|
|
534
|
+
if (stat.size < 10 * 1024 * 1024) return;
|
|
554
535
|
const dir = path3.dirname(REQUEST_LOG_FILE);
|
|
555
536
|
for (let i = 5; i > 0; i--) {
|
|
556
537
|
const oldPath = `${REQUEST_LOG_FILE}.${i}`;
|
|
@@ -568,8 +549,7 @@ function rotateRequestLog() {
|
|
|
568
549
|
}
|
|
569
550
|
}
|
|
570
551
|
function logRequest(req) {
|
|
571
|
-
if (!config_default.requestLogEnabled)
|
|
572
|
-
return;
|
|
552
|
+
if (!config_default.requestLogEnabled) return;
|
|
573
553
|
try {
|
|
574
554
|
ensureRequestLogDir();
|
|
575
555
|
rotateRequestLog();
|
|
@@ -586,8 +566,7 @@ function logRequest(req) {
|
|
|
586
566
|
}
|
|
587
567
|
}
|
|
588
568
|
function logResponse(req, res, duration) {
|
|
589
|
-
if (!config_default.requestLogEnabled)
|
|
590
|
-
return;
|
|
569
|
+
if (!config_default.requestLogEnabled) return;
|
|
591
570
|
try {
|
|
592
571
|
ensureRequestLogDir();
|
|
593
572
|
const entry = {
|
|
@@ -685,14 +664,11 @@ function clearCache(uri) {
|
|
|
685
664
|
}
|
|
686
665
|
}
|
|
687
666
|
function parseLispList(str) {
|
|
688
|
-
if (!str || typeof str !== "string")
|
|
689
|
-
return null;
|
|
667
|
+
if (!str || typeof str !== "string") return null;
|
|
690
668
|
const trimmed = str.trim();
|
|
691
|
-
if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
|
|
692
|
-
return null;
|
|
669
|
+
if (!trimmed.startsWith("(") || !trimmed.endsWith(")")) return null;
|
|
693
670
|
const content = trimmed.slice(1, -1).trim();
|
|
694
|
-
if (!content)
|
|
695
|
-
return [];
|
|
671
|
+
if (!content) return [];
|
|
696
672
|
const result = [];
|
|
697
673
|
let depth = 0;
|
|
698
674
|
let current = "";
|
|
@@ -734,44 +710,32 @@ function parseLispList(str) {
|
|
|
734
710
|
}
|
|
735
711
|
current += ch;
|
|
736
712
|
}
|
|
737
|
-
if (current.trim())
|
|
738
|
-
result.push(current.trim());
|
|
713
|
+
if (current.trim()) result.push(current.trim());
|
|
739
714
|
return result.map((item) => {
|
|
740
715
|
const t = item.trim();
|
|
741
|
-
if (t === "nil")
|
|
742
|
-
|
|
743
|
-
if (t === "
|
|
744
|
-
return true;
|
|
745
|
-
if (t === "T")
|
|
746
|
-
return true;
|
|
716
|
+
if (t === "nil") return null;
|
|
717
|
+
if (t === "t") return true;
|
|
718
|
+
if (t === "T") return true;
|
|
747
719
|
const num = Number(t);
|
|
748
|
-
if (!isNaN(num) && t !== "")
|
|
749
|
-
|
|
750
|
-
if (t.startsWith('"') && t.endsWith('"'))
|
|
751
|
-
return t.slice(1, -1);
|
|
720
|
+
if (!isNaN(num) && t !== "") return num;
|
|
721
|
+
if (t.startsWith('"') && t.endsWith('"')) return t.slice(1, -1);
|
|
752
722
|
return t;
|
|
753
723
|
});
|
|
754
724
|
}
|
|
755
725
|
function parseLispRecursive(str) {
|
|
756
|
-
if (!str || typeof str !== "string")
|
|
757
|
-
return null;
|
|
726
|
+
if (!str || typeof str !== "string") return null;
|
|
758
727
|
str = str.trim();
|
|
759
|
-
if (!str)
|
|
760
|
-
return null;
|
|
728
|
+
if (!str) return null;
|
|
761
729
|
let pos = 0;
|
|
762
730
|
function skipWs() {
|
|
763
|
-
while (pos < str.length && /\s/.test(str[pos]))
|
|
764
|
-
pos++;
|
|
731
|
+
while (pos < str.length && /\s/.test(str[pos])) pos++;
|
|
765
732
|
}
|
|
766
733
|
function parseValue() {
|
|
767
734
|
skipWs();
|
|
768
|
-
if (pos >= str.length)
|
|
769
|
-
return null;
|
|
735
|
+
if (pos >= str.length) return null;
|
|
770
736
|
const ch = str[pos];
|
|
771
|
-
if (ch === "(")
|
|
772
|
-
|
|
773
|
-
if (ch === '"')
|
|
774
|
-
return parseString();
|
|
737
|
+
if (ch === "(") return parseList();
|
|
738
|
+
if (ch === '"') return parseString();
|
|
775
739
|
if (ch === "'") {
|
|
776
740
|
pos++;
|
|
777
741
|
return parseValue();
|
|
@@ -784,16 +748,11 @@ function parseLispRecursive(str) {
|
|
|
784
748
|
while (pos < str.length && str[pos] !== '"') {
|
|
785
749
|
if (str[pos] === "\\" && pos + 1 < str.length) {
|
|
786
750
|
pos++;
|
|
787
|
-
if (str[pos] === '"')
|
|
788
|
-
|
|
789
|
-
else if (str[pos] === "
|
|
790
|
-
|
|
791
|
-
else
|
|
792
|
-
r += " ";
|
|
793
|
-
else if (str[pos] === "\\")
|
|
794
|
-
r += "\\";
|
|
795
|
-
else
|
|
796
|
-
r += str[pos];
|
|
751
|
+
if (str[pos] === '"') r += '"';
|
|
752
|
+
else if (str[pos] === "n") r += "\n";
|
|
753
|
+
else if (str[pos] === "t") r += " ";
|
|
754
|
+
else if (str[pos] === "\\") r += "\\";
|
|
755
|
+
else r += str[pos];
|
|
797
756
|
} else {
|
|
798
757
|
r += str[pos];
|
|
799
758
|
}
|
|
@@ -804,16 +763,12 @@ function parseLispRecursive(str) {
|
|
|
804
763
|
}
|
|
805
764
|
function parseAtom() {
|
|
806
765
|
const start = pos;
|
|
807
|
-
while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(")
|
|
808
|
-
pos++;
|
|
766
|
+
while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(") pos++;
|
|
809
767
|
const atom = str.slice(start, pos);
|
|
810
|
-
if (atom === "nil" || atom === "NIL")
|
|
811
|
-
|
|
812
|
-
if (atom === "t" || atom === "T")
|
|
813
|
-
return true;
|
|
768
|
+
if (atom === "nil" || atom === "NIL") return null;
|
|
769
|
+
if (atom === "t" || atom === "T") return true;
|
|
814
770
|
const num = Number(atom);
|
|
815
|
-
if (!isNaN(num) && atom !== "")
|
|
816
|
-
return num;
|
|
771
|
+
if (!isNaN(num) && atom !== "") return num;
|
|
817
772
|
return atom;
|
|
818
773
|
}
|
|
819
774
|
function parseList() {
|
|
@@ -821,15 +776,13 @@ function parseLispRecursive(str) {
|
|
|
821
776
|
const items = [];
|
|
822
777
|
while (pos < str.length) {
|
|
823
778
|
skipWs();
|
|
824
|
-
if (pos >= str.length)
|
|
825
|
-
break;
|
|
779
|
+
if (pos >= str.length) break;
|
|
826
780
|
if (str[pos] === ")") {
|
|
827
781
|
pos++;
|
|
828
782
|
return items;
|
|
829
783
|
}
|
|
830
784
|
const left = parseValue();
|
|
831
|
-
if (left === void 0)
|
|
832
|
-
break;
|
|
785
|
+
if (left === void 0) break;
|
|
833
786
|
skipWs();
|
|
834
787
|
if (str[pos] === "." && (pos + 1 >= str.length || /\s/.test(str[pos + 1]) || str[pos + 1] === ")")) {
|
|
835
788
|
pos++;
|
|
@@ -852,8 +805,7 @@ function parseLispRecursive(str) {
|
|
|
852
805
|
return parseValue();
|
|
853
806
|
}
|
|
854
807
|
function lispPairsToObject(pairs) {
|
|
855
|
-
if (!Array.isArray(pairs))
|
|
856
|
-
return pairs;
|
|
808
|
+
if (!Array.isArray(pairs)) return pairs;
|
|
857
809
|
const obj = {};
|
|
858
810
|
for (let i = 0; i < pairs.length - 1; i += 2) {
|
|
859
811
|
const key = pairs[i];
|
|
@@ -864,36 +816,8 @@ function lispPairsToObject(pairs) {
|
|
|
864
816
|
}
|
|
865
817
|
return obj;
|
|
866
818
|
}
|
|
867
|
-
function parseEntity(arr) {
|
|
868
|
-
if (!Array.isArray(arr) || arr.length < 5)
|
|
869
|
-
return null;
|
|
870
|
-
const [type, handle, layer, color, linetype, ...rest] = arr;
|
|
871
|
-
const entity = {
|
|
872
|
-
type: String(type).toUpperCase().replace(/^"|"$/g, ""),
|
|
873
|
-
handle: String(handle),
|
|
874
|
-
layer: String(layer),
|
|
875
|
-
color,
|
|
876
|
-
linetype: String(linetype)
|
|
877
|
-
};
|
|
878
|
-
const entType = typeof entity.type === "string" ? entity.type.toUpperCase() : entity.type;
|
|
879
|
-
if (/^(TEXT|MTEXT|ATTRIB|TCH_TEXT)$/.test(entType) && rest[0] != null) {
|
|
880
|
-
entity.text = String(rest[0]);
|
|
881
|
-
}
|
|
882
|
-
if (/^(LINE|LWPOLYLINE|POLYLINE|ARC|CIRCLE|SPLINE|ELLIPSE|XLINE|RAY)$/.test(entType) && Array.isArray(rest[0])) {
|
|
883
|
-
entity.points = rest[0].map((pt) => {
|
|
884
|
-
if (Array.isArray(pt) && pt.length >= 2)
|
|
885
|
-
return { x: Number(pt[0]), y: Number(pt[1]), z: Number(pt[2] || 0) };
|
|
886
|
-
return null;
|
|
887
|
-
}).filter(Boolean);
|
|
888
|
-
}
|
|
889
|
-
if (entType === "INSERT" && rest[0] != null) {
|
|
890
|
-
entity.blockName = String(rest[0]);
|
|
891
|
-
}
|
|
892
|
-
return entity;
|
|
893
|
-
}
|
|
894
819
|
function propertyPairsToObject(pairs) {
|
|
895
|
-
if (!Array.isArray(pairs))
|
|
896
|
-
return null;
|
|
820
|
+
if (!Array.isArray(pairs)) return null;
|
|
897
821
|
const obj = {};
|
|
898
822
|
for (const pair of pairs) {
|
|
899
823
|
if (Array.isArray(pair) && pair.length >= 2) {
|
|
@@ -904,10 +828,8 @@ function propertyPairsToObject(pairs) {
|
|
|
904
828
|
}
|
|
905
829
|
function buildEntityPropertiesCode({ type, layer, bbox }) {
|
|
906
830
|
const items = [];
|
|
907
|
-
if (type)
|
|
908
|
-
|
|
909
|
-
if (layer)
|
|
910
|
-
items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
|
|
831
|
+
if (type) items.push(`(cons 0 "${type.replace(/"/g, '\\"')}")`);
|
|
832
|
+
if (layer) items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
|
|
911
833
|
if (bbox) {
|
|
912
834
|
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
913
835
|
if (parts.length === 4) {
|
|
@@ -932,52 +854,14 @@ ${ENTITY_PROPERTIES_LISP}
|
|
|
932
854
|
@e:i (1+ @e:i)))
|
|
933
855
|
(vl-prin1-to-string (list @e:total (reverse @e:ents))))`;
|
|
934
856
|
}
|
|
935
|
-
function buildTextCode({ layer, bbox, offset, limit }) {
|
|
936
|
-
const items = [`'(0 . "TEXT,MTEXT,ATTRIB,TCH_TEXT")`];
|
|
937
|
-
if (layer)
|
|
938
|
-
items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
|
|
939
|
-
if (bbox) {
|
|
940
|
-
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
941
|
-
if (parts.length === 4) {
|
|
942
|
-
const [x1, y1, x2, y2] = parts;
|
|
943
|
-
items.push(
|
|
944
|
-
`'(-4 . "<AND")`,
|
|
945
|
-
`'(-4 . ">=,>=,*") (list 10 ${x1} ${y1} 0.0)`,
|
|
946
|
-
`'(-4 . "<=,<=,*") (list 10 ${x2} ${y2} 0.0)`,
|
|
947
|
-
`'(-4 . "AND>")`
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
const filterExpr = `(list ${items.join(" ")})`;
|
|
952
|
-
return `(progn
|
|
953
|
-
(defun @t:props (ent / ed typ result item ins)
|
|
954
|
-
(setq ed (entget ent) typ (cdr (assoc 0 ed)))
|
|
955
|
-
(setq result (list (vl-prin1-to-string typ) (vl-prin1-to-string (cdr (assoc 5 ed))) (vl-prin1-to-string (cdr (assoc 8 ed)))
|
|
956
|
-
(if (setq item (assoc 62 ed)) (cdr item) "ByLayer")
|
|
957
|
-
(vl-prin1-to-string (if (setq item (assoc 6 ed)) (cdr item) "ByLayer"))))
|
|
958
|
-
(setq ins (cdr (assoc 10 ed)))
|
|
959
|
-
(append result (list (vl-prin1-to-string (cdr (assoc 1 ed))) (car ins) (cadr ins) (caddr ins)
|
|
960
|
-
(cdr (assoc 40 ed)) (cdr (assoc 50 ed))
|
|
961
|
-
(vl-prin1-to-string (if (setq item (assoc 7 ed)) (cdr item) "Standard")))))
|
|
962
|
-
(defun @t:run nil
|
|
963
|
-
(setq ss (ssget "_X" ${filterExpr}))
|
|
964
|
-
(if (null ss)
|
|
965
|
-
(list "total" 0 "offset" ${offset} "limit" ${limit})
|
|
966
|
-
(progn
|
|
967
|
-
(setq total (sslength ss) texts nil i ${offset})
|
|
968
|
-
(while (and (< i total) (< (length texts) ${limit}))
|
|
969
|
-
(setq texts (append texts (list (@t:props (ssname ss i)))) i (1+ i)))
|
|
970
|
-
(list "total" total "offset" ${offset} "limit" ${limit} "texts" texts))))
|
|
971
|
-
(@t:run))
|
|
972
|
-
`;
|
|
973
|
-
}
|
|
974
857
|
var RESOURCES = [
|
|
975
858
|
{ uri: "atlisp://cad/info", name: "CAD Info", description: "CAD \u8FDE\u63A5\u4FE1\u606F", mimeType: "application/json", subscribable: true },
|
|
976
|
-
{ uri: "atlisp://dwg/layers", name: "Layers", description: "\u56FE\u5C42\u5217\u8868", mimeType: "application/json", subscribable: true },
|
|
977
859
|
{ uri: "atlisp://dwg/entities", name: "Entities", description: "\u56FE\u5143\u5217\u8868\u3002\u65E0\u53C2\u6570\u65F6\u8FD4\u56DE\u603B\u6570\u548C\u6309\u7C7B\u578B\u7EDF\u8BA1\uFF1B\u6709\u53C2\u6570\u65F6\u8FD4\u56DE filtered \u56FE\u6587\u7684 entity:properties \u5168\u5C5E\u6027 JSON\uFF08ObjectName, Handle, Layer, Color, Center, Radius \u7B49\uFF09\uFF0C\u652F\u6301 ?type=LINE&layer=0&bbox=0,0,100,100", mimeType: "application/json", subscribable: true },
|
|
978
|
-
{ uri: "atlisp://dwg/
|
|
860
|
+
{ uri: "atlisp://dwg/text-content", name: "Text Content", description: "\u6587\u672C\u5185\u5BB9\u53CA\u4F4D\u7F6E\uFF0C\u7528\u4E8E\u8BED\u4E49\u5206\u6790\u3002\u652F\u6301 ?layer=0&bbox=0,0,100,100&limit=5000&offset=0", mimeType: "application/json", subscribable: true },
|
|
979
861
|
{ uri: "atlisp://dwg/name", name: "DWG Name", description: "\u5F53\u524D DWG \u6587\u4EF6\u540D", mimeType: "application/json", subscribable: true },
|
|
980
862
|
{ uri: "atlisp://dwg/path", name: "DWG Path", description: "\u6587\u4EF6\u5B8C\u6574\u8DEF\u5F84", mimeType: "application/json", subscribable: true },
|
|
863
|
+
{ uri: "atlisp://dwg/block-refs", name: "Block References", description: "\u5757\u53C2\u7167\u5217\u8868\u53CA\u5C5E\u6027\u503C\u3001\u52A8\u6001\u5757\u7279\u6027\uFF0C\u652F\u6301 ?blockName=xxx", mimeType: "application/json", subscribable: true },
|
|
864
|
+
{ uri: "atlisp://dwg/tbl", name: "Tables", description: "CAD \u8868\u6570\u636E (layer, block, textstyle, dimstyle, linetype, ucs, view, viewport, regapp)\uFF0C\u652F\u6301 ?tbl=layer", mimeType: "application/json", subscribable: true },
|
|
981
865
|
{ uri: "atlisp://cad/dwgs", name: "DWG List", description: "\u6240\u6709\u6253\u5F00\u7684 DWG \u6587\u4EF6\u5217\u8868", mimeType: "application/json", subscribable: true },
|
|
982
866
|
{ uri: "atlisp://packages", name: "Packages", description: "\u5DF2\u5B89\u88C5\u5305\u5217\u8868", mimeType: "application/json", subscribable: true },
|
|
983
867
|
{ uri: "atlisp://platforms", name: "Platforms", description: "\u652F\u6301\u7684\u5E73\u53F0\u4FE1\u606F", mimeType: "application/json", subscribable: false },
|
|
@@ -986,23 +870,20 @@ var RESOURCES = [
|
|
|
986
870
|
];
|
|
987
871
|
function parseQuery(uri) {
|
|
988
872
|
const qIdx = uri.indexOf("?");
|
|
989
|
-
if (qIdx === -1)
|
|
990
|
-
return { base: uri, params: {} };
|
|
873
|
+
if (qIdx === -1) return { base: uri, params: {} };
|
|
991
874
|
const base = uri.substring(0, qIdx);
|
|
992
875
|
const params = {};
|
|
993
876
|
uri.substring(qIdx + 1).split("&").forEach((p) => {
|
|
994
877
|
const eqIdx = p.indexOf("=");
|
|
995
878
|
const k = eqIdx === -1 ? p : p.substring(0, eqIdx);
|
|
996
879
|
const v = eqIdx === -1 ? "" : p.substring(eqIdx + 1);
|
|
997
|
-
if (k)
|
|
998
|
-
params[k] = decodeURIComponent(v);
|
|
880
|
+
if (k) params[k] = decodeURIComponent(v);
|
|
999
881
|
});
|
|
1000
882
|
return { base, params };
|
|
1001
883
|
}
|
|
1002
884
|
function parseTemplateUri(uri) {
|
|
1003
885
|
const match = uri.match(/^atlisp:\/\/dwg\/entity\/([^?]+)$/);
|
|
1004
|
-
if (match)
|
|
1005
|
-
return { type: "entity", handle: match[1] };
|
|
886
|
+
if (match) return { type: "entity", handle: match[1] };
|
|
1006
887
|
return null;
|
|
1007
888
|
}
|
|
1008
889
|
async function listResources(subscribedUris = []) {
|
|
@@ -1023,16 +904,18 @@ async function readResource(uri) {
|
|
|
1023
904
|
switch (base) {
|
|
1024
905
|
case "atlisp://cad/info":
|
|
1025
906
|
return await getCadInfo();
|
|
1026
|
-
case "atlisp://dwg/layers":
|
|
1027
|
-
return await getLayers(params.name);
|
|
1028
907
|
case "atlisp://dwg/entities":
|
|
1029
908
|
return await getEntities(params);
|
|
1030
|
-
case "atlisp://dwg/
|
|
1031
|
-
return await
|
|
909
|
+
case "atlisp://dwg/text-content":
|
|
910
|
+
return await getTextContent(params);
|
|
1032
911
|
case "atlisp://dwg/name":
|
|
1033
912
|
return await getDwgName();
|
|
1034
913
|
case "atlisp://dwg/path":
|
|
1035
914
|
return await getDwgPath();
|
|
915
|
+
case "atlisp://dwg/block-refs":
|
|
916
|
+
return await getBlockRefs(params);
|
|
917
|
+
case "atlisp://dwg/tbl":
|
|
918
|
+
return await getTables(params);
|
|
1036
919
|
case "atlisp://cad/dwgs":
|
|
1037
920
|
return await getDwgList();
|
|
1038
921
|
case "atlisp://packages":
|
|
@@ -1048,10 +931,8 @@ async function readResource(uri) {
|
|
|
1048
931
|
}
|
|
1049
932
|
}
|
|
1050
933
|
async function getEntityByHandle(handle) {
|
|
1051
|
-
if (!cad.connected)
|
|
1052
|
-
|
|
1053
|
-
if (!cad.connected)
|
|
1054
|
-
return { error: "CAD \u672A\u8FDE\u63A5" };
|
|
934
|
+
if (!cad.connected) await cad.connect();
|
|
935
|
+
if (!cad.connected) return { error: "CAD \u672A\u8FDE\u63A5" };
|
|
1055
936
|
const code = `(progn
|
|
1056
937
|
(vl-load-com)
|
|
1057
938
|
(if (setq ent (handent "${handle}"))
|
|
@@ -1071,8 +952,7 @@ async function getEntityByHandle(handle) {
|
|
|
1071
952
|
)`;
|
|
1072
953
|
try {
|
|
1073
954
|
const result = await cad.sendCommandWithResult(code);
|
|
1074
|
-
if (!result || result === "nil")
|
|
1075
|
-
return { error: `\u672A\u627E\u5230\u5B9E\u4F53: ${handle}` };
|
|
955
|
+
if (!result || result === "nil") return { error: `\u672A\u627E\u5230\u5B9E\u4F53: ${handle}` };
|
|
1076
956
|
try {
|
|
1077
957
|
return JSON.parse(result);
|
|
1078
958
|
} catch {
|
|
@@ -1084,8 +964,7 @@ async function getEntityByHandle(handle) {
|
|
|
1084
964
|
}
|
|
1085
965
|
async function getCadInfo() {
|
|
1086
966
|
const cached = getCached("cad:info");
|
|
1087
|
-
if (cached)
|
|
1088
|
-
return cached;
|
|
967
|
+
if (cached) return cached;
|
|
1089
968
|
if (!cad.connected) {
|
|
1090
969
|
await cad.connect();
|
|
1091
970
|
}
|
|
@@ -1109,65 +988,11 @@ async function getCadInfo() {
|
|
|
1109
988
|
setCache("cad:info", result);
|
|
1110
989
|
return result;
|
|
1111
990
|
}
|
|
1112
|
-
async function getLayers(filterName = null) {
|
|
1113
|
-
const cacheKey = filterName ? `dwg:layers:${filterName}` : "dwg:layers:all";
|
|
1114
|
-
const cached = getCached(cacheKey);
|
|
1115
|
-
if (cached)
|
|
1116
|
-
return cached;
|
|
1117
|
-
if (!cad.connected)
|
|
1118
|
-
await cad.connect();
|
|
1119
|
-
if (!cad.connected)
|
|
1120
|
-
return [];
|
|
1121
|
-
try {
|
|
1122
|
-
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))`;
|
|
1123
|
-
const result = await cad.sendCommandWithResult(code);
|
|
1124
|
-
if (!result || result === "" || result === "nil") {
|
|
1125
|
-
setCache(cacheKey, []);
|
|
1126
|
-
return [];
|
|
1127
|
-
}
|
|
1128
|
-
let layers = [];
|
|
1129
|
-
try {
|
|
1130
|
-
layers = JSON.parse(result);
|
|
1131
|
-
} catch (e) {
|
|
1132
|
-
const parsed = parseLispList(result);
|
|
1133
|
-
if (parsed) {
|
|
1134
|
-
layers = parsed;
|
|
1135
|
-
} else {
|
|
1136
|
-
layers = [];
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
if (!Array.isArray(layers)) {
|
|
1140
|
-
if (typeof layers === "number") {
|
|
1141
|
-
layers = [[result, layers, 0]];
|
|
1142
|
-
} else if (typeof layers === "string") {
|
|
1143
|
-
layers = [[layers, 7, 0]];
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
const mapped = layers.map((l) => {
|
|
1147
|
-
const name = Array.isArray(l) ? l[0] : l;
|
|
1148
|
-
const color = Array.isArray(l) && l[1] !== void 0 ? l[1] : 7;
|
|
1149
|
-
const flags = Array.isArray(l) && l[2] !== void 0 ? l[2] : 0;
|
|
1150
|
-
return {
|
|
1151
|
-
name: String(name),
|
|
1152
|
-
color,
|
|
1153
|
-
locked: (flags & 4) !== 0,
|
|
1154
|
-
frozen: (flags & 1) !== 0
|
|
1155
|
-
};
|
|
1156
|
-
});
|
|
1157
|
-
setCache(cacheKey, mapped);
|
|
1158
|
-
return mapped;
|
|
1159
|
-
} catch (e) {
|
|
1160
|
-
setCache(cacheKey, []);
|
|
1161
|
-
return [];
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
991
|
async function getEntities(params = {}) {
|
|
1165
992
|
const cacheKey = `dwg:entities:${JSON.stringify(params)}`;
|
|
1166
993
|
const cached = getCached(cacheKey);
|
|
1167
|
-
if (cached)
|
|
1168
|
-
|
|
1169
|
-
if (!cad.connected)
|
|
1170
|
-
await cad.connect();
|
|
994
|
+
if (cached) return cached;
|
|
995
|
+
if (!cad.connected) await cad.connect();
|
|
1171
996
|
if (!cad.connected) {
|
|
1172
997
|
const result = { total: 0, entities: [] };
|
|
1173
998
|
setCache(cacheKey, result);
|
|
@@ -1266,27 +1091,48 @@ async function getEntitiesSummary(cacheKey) {
|
|
|
1266
1091
|
return result;
|
|
1267
1092
|
}
|
|
1268
1093
|
}
|
|
1269
|
-
|
|
1270
|
-
const
|
|
1094
|
+
function buildTextContentCode({ layer, bbox, offset, limit }) {
|
|
1095
|
+
const items = [`'(0 . "TEXT,MTEXT,ATTRIB,TCH_TEXT")`];
|
|
1096
|
+
if (layer) items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
|
|
1097
|
+
if (bbox) {
|
|
1098
|
+
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
1099
|
+
if (parts.length === 4) {
|
|
1100
|
+
const [x1, y1, x2, y2] = parts;
|
|
1101
|
+
items.push(
|
|
1102
|
+
`'(-4 . "<AND")`,
|
|
1103
|
+
`'(-4 . ">=,>=,*") (list 10 ${x1} ${y1} 0.0)`,
|
|
1104
|
+
`'(-4 . "<=,<=,*") (list 10 ${x2} ${y2} 0.0)`,
|
|
1105
|
+
`'(-4 . "AND>")`
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
const filterExpr = `(list ${items.join(" ")})`;
|
|
1110
|
+
return `(progn
|
|
1111
|
+
(setq ss (ssget "_X" ${filterExpr}))
|
|
1112
|
+
(if (null ss)
|
|
1113
|
+
(list "total" 0 "offset" ${offset} "limit" ${limit} "texts" nil)
|
|
1114
|
+
(progn
|
|
1115
|
+
(setq total (sslength ss) i ${offset} texts nil)
|
|
1116
|
+
(while (and (< i total) (< (length texts) ${limit}))
|
|
1117
|
+
(setq ent (ssname ss i) ed (entget ent) ins (cdr (assoc 10 ed)))
|
|
1118
|
+
(setq texts (append texts (list (list "text" (vl-prin1-to-string (cdr (assoc 1 ed))) "position" (list (car ins) (cadr ins) (caddr ins))))) i (1+ i)))
|
|
1119
|
+
(list "total" total "offset" ${offset} "limit" ${limit} "texts" texts))))
|
|
1120
|
+
)`;
|
|
1121
|
+
}
|
|
1122
|
+
async function getTextContent(params = {}) {
|
|
1123
|
+
const cacheKey = `dwg:text-content:${JSON.stringify(params)}`;
|
|
1271
1124
|
const cached = getCached(cacheKey);
|
|
1272
|
-
if (cached)
|
|
1273
|
-
|
|
1274
|
-
if (!cad.connected)
|
|
1275
|
-
await cad.connect();
|
|
1125
|
+
if (cached) return cached;
|
|
1126
|
+
if (!cad.connected) await cad.connect();
|
|
1276
1127
|
if (!cad.connected) {
|
|
1277
|
-
const result = { total: 0, texts: [] };
|
|
1128
|
+
const result = { total: 0, offset: 0, limit: 5e3, texts: [] };
|
|
1278
1129
|
setCache(cacheKey, result);
|
|
1279
1130
|
return result;
|
|
1280
1131
|
}
|
|
1281
1132
|
const offset = Math.max(0, parseInt(params.offset) || 0);
|
|
1282
1133
|
const limit = Math.min(Math.max(1, parseInt(params.limit) || 5e3), 5e3);
|
|
1283
1134
|
try {
|
|
1284
|
-
const code =
|
|
1285
|
-
layer: params.layer || null,
|
|
1286
|
-
bbox: params.bbox || null,
|
|
1287
|
-
offset,
|
|
1288
|
-
limit
|
|
1289
|
-
});
|
|
1135
|
+
const code = buildTextContentCode({ layer: params.layer, bbox: params.bbox, offset, limit });
|
|
1290
1136
|
const resultStr = await cad.sendCommandWithResult(code);
|
|
1291
1137
|
if (!resultStr || resultStr === "" || resultStr === "nil" || resultStr === "0") {
|
|
1292
1138
|
const result = { total: 0, offset, limit, texts: [] };
|
|
@@ -1294,26 +1140,38 @@ async function getTexts(params = {}) {
|
|
|
1294
1140
|
return result;
|
|
1295
1141
|
}
|
|
1296
1142
|
const parsed = parseLispRecursive(resultStr);
|
|
1297
|
-
|
|
1298
|
-
|
|
1143
|
+
if (!parsed || !Array.isArray(parsed)) {
|
|
1144
|
+
const result = { total: 0, offset, limit, texts: [] };
|
|
1145
|
+
setCache(cacheKey, result);
|
|
1146
|
+
return result;
|
|
1147
|
+
}
|
|
1299
1148
|
const data = lispPairsToObject(parsed);
|
|
1300
|
-
|
|
1301
|
-
data.
|
|
1302
|
-
|
|
1149
|
+
const rawTexts = Array.isArray(data.texts) ? data.texts : [];
|
|
1150
|
+
data.texts = rawTexts.map((item) => {
|
|
1151
|
+
if (!Array.isArray(item)) return null;
|
|
1152
|
+
const obj = {};
|
|
1153
|
+
item.forEach((pair) => {
|
|
1154
|
+
if (Array.isArray(pair) && pair.length >= 2) {
|
|
1155
|
+
if (pair[0] === "text") obj.text = String(pair[1] || "");
|
|
1156
|
+
else if (pair[0] === "position" && Array.isArray(pair[1])) {
|
|
1157
|
+
obj.position = pair[1].map((v) => typeof v === "number" ? v : 0);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
return obj.text ? obj : null;
|
|
1162
|
+
}).filter(Boolean);
|
|
1303
1163
|
setCache(cacheKey, data);
|
|
1304
1164
|
return data;
|
|
1305
1165
|
} catch (e) {
|
|
1306
|
-
log(`
|
|
1166
|
+
log(`getTextContent error: ${e.message}`);
|
|
1307
1167
|
const result = { total: 0, offset, limit, texts: [] };
|
|
1308
1168
|
setCache(cacheKey, result);
|
|
1309
1169
|
return result;
|
|
1310
1170
|
}
|
|
1311
1171
|
}
|
|
1312
1172
|
async function getDwgName() {
|
|
1313
|
-
if (!cad.connected)
|
|
1314
|
-
|
|
1315
|
-
if (!cad.connected)
|
|
1316
|
-
return { name: null };
|
|
1173
|
+
if (!cad.connected) await cad.connect();
|
|
1174
|
+
if (!cad.connected) return { name: null };
|
|
1317
1175
|
try {
|
|
1318
1176
|
const code = `(vl-princ-to-string (getvar "dwgname"))`;
|
|
1319
1177
|
const name = await cad.sendCommandWithResult(code);
|
|
@@ -1323,10 +1181,8 @@ async function getDwgName() {
|
|
|
1323
1181
|
}
|
|
1324
1182
|
}
|
|
1325
1183
|
async function getDwgPath() {
|
|
1326
|
-
if (!cad.connected)
|
|
1327
|
-
|
|
1328
|
-
if (!cad.connected)
|
|
1329
|
-
return { path: null, name: null };
|
|
1184
|
+
if (!cad.connected) await cad.connect();
|
|
1185
|
+
if (!cad.connected) return { path: null, name: null };
|
|
1330
1186
|
try {
|
|
1331
1187
|
const code = `(progn
|
|
1332
1188
|
(setq prefix (vl-princ-to-string (getvar "dwgprefix")))
|
|
@@ -1344,8 +1200,7 @@ async function getDwgPath() {
|
|
|
1344
1200
|
}
|
|
1345
1201
|
if (!parsed) {
|
|
1346
1202
|
const listResult = parseLispList(result);
|
|
1347
|
-
if (listResult && listResult.length >= 2)
|
|
1348
|
-
parsed = listResult;
|
|
1203
|
+
if (listResult && listResult.length >= 2) parsed = listResult;
|
|
1349
1204
|
}
|
|
1350
1205
|
if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
|
|
1351
1206
|
return { path: String(parsed[0]), name: String(parsed[1]) };
|
|
@@ -1355,15 +1210,257 @@ async function getDwgPath() {
|
|
|
1355
1210
|
return { path: null, name: null };
|
|
1356
1211
|
}
|
|
1357
1212
|
}
|
|
1213
|
+
function buildBlockRefsCode(filterBlockName) {
|
|
1214
|
+
const filterExpr = filterBlockName ? `(list (cons 2 "${filterBlockName.replace(/"/g, '\\"')}"))` : "nil";
|
|
1215
|
+
return `(progn
|
|
1216
|
+
(vl-load-com)
|
|
1217
|
+
(defun @br:attr (ent / atts)
|
|
1218
|
+
(if (= (type ent) 'VLA-OBJECT)
|
|
1219
|
+
(progn
|
|
1220
|
+
(setq atts (vlax-variant-value (vla-getattributes ent)))
|
|
1221
|
+
(if (safearray-value atts)
|
|
1222
|
+
(mapcar '(lambda (x) (cons (vla-get-tagstring x) (vla-get-textstring x)))
|
|
1223
|
+
(vlax-safearray->list atts))
|
|
1224
|
+
nil))
|
|
1225
|
+
(if (setq att (entnext ent))
|
|
1226
|
+
(progn
|
|
1227
|
+
(setq atts nil)
|
|
1228
|
+
(while (= (cdr (assoc 0 (entget att))) "ATTRIB")
|
|
1229
|
+
(setq atts (cons (cons (cdr (assoc 2 (entget att))) (cdr (assoc 1 (entget att)))) atts))
|
|
1230
|
+
att (entnext att))
|
|
1231
|
+
(reverse atts))
|
|
1232
|
+
nil))))
|
|
1233
|
+
|
|
1234
|
+
(defun @br:dynprops (ent / obj props)
|
|
1235
|
+
(if (= (type ent) 'VLA-OBJECT)
|
|
1236
|
+
(progn
|
|
1237
|
+
(setq obj ent)
|
|
1238
|
+
(if (vlax-property-available-p obj 'isdynamicblock)
|
|
1239
|
+
(if (vla-get-isdynamicblock obj)
|
|
1240
|
+
(progn
|
|
1241
|
+
(setq props (vlax-invoke obj 'getdynamicblockproperties))
|
|
1242
|
+
(mapcar '(lambda (x)
|
|
1243
|
+
(cons (vla-get-propertyname x)
|
|
1244
|
+
(list (cons "value" (vla-get-value x))
|
|
1245
|
+
(cons "readOnly" (vla-get-readonly x))
|
|
1246
|
+
(cons "show" (vla-get-show x)))))
|
|
1247
|
+
(vlax-safearray->list props)))
|
|
1248
|
+
nil)
|
|
1249
|
+
nil))
|
|
1250
|
+
(if (and (setq obj (vlax-ename->vla-object ent))
|
|
1251
|
+
(vlax-property-available-p obj 'isdynamicblock)
|
|
1252
|
+
(vla-get-isdynamicblock obj))
|
|
1253
|
+
(progn
|
|
1254
|
+
(setq props (vlax-invoke obj 'getdynamicblockproperties))
|
|
1255
|
+
(mapcar '(lambda (x)
|
|
1256
|
+
(cons (vla-get-propertyname x)
|
|
1257
|
+
(list (cons "value" (vla-get-value x))
|
|
1258
|
+
(cons "readOnly" (vla-get-readonly x))
|
|
1259
|
+
(cons "show" (vla-get-show x)))))
|
|
1260
|
+
(vlax-safearray->list props)))
|
|
1261
|
+
nil)))
|
|
1262
|
+
|
|
1263
|
+
(defun @br:props (ent / obj blkname result)
|
|
1264
|
+
(setq obj (vlax-ename->vla-object ent))
|
|
1265
|
+
(setq result (list
|
|
1266
|
+
(cons "handle" (cdr (assoc 5 (entget ent))))
|
|
1267
|
+
(cons "layer" (cdr (assoc 8 (entget ent))))
|
|
1268
|
+
(cons "blockName" (vla-get-name obj))
|
|
1269
|
+
(cons "effectiveBlockName" (vla-get-effectivename obj))
|
|
1270
|
+
(cons "insertionPoint" (vlax-safearray->list (vla-get-insertionpoint obj)))
|
|
1271
|
+
(cons "rotation" (vla-get-rotation obj))
|
|
1272
|
+
(cons "scale" (list (vla-get-xscale obj) (vla-get-yscale obj) (vla-get-zscale obj)))
|
|
1273
|
+
(cons "isDynamic" (if (vlax-property-available-p obj 'isdynamicblock) (vla-get-isdynamicblock obj) nil))
|
|
1274
|
+
(cons "attributes" (@br:attr obj))
|
|
1275
|
+
(cons "dynamicProperties" (@br:dynprops obj))))
|
|
1276
|
+
result)
|
|
1277
|
+
|
|
1278
|
+
(setq ss (ssget "_X" (list (cons 0 "INSERT") ${filterExpr})))
|
|
1279
|
+
(if (null ss)
|
|
1280
|
+
(list (cons "total" 0) (cons "blockRefs" nil))
|
|
1281
|
+
(progn
|
|
1282
|
+
(setq total (sslength ss) i 0 refs nil)
|
|
1283
|
+
(while (< i total)
|
|
1284
|
+
(setq refs (cons (@br:props (ssname ss i)) refs) i (1+ i)))
|
|
1285
|
+
(list (cons "total" total) (cons "blockRefs" (reverse refs))))))`;
|
|
1286
|
+
}
|
|
1287
|
+
async function getBlockRefs(params = {}) {
|
|
1288
|
+
const cacheKey = `dwg:block-refs:${params.blockName || "all"}`;
|
|
1289
|
+
const cached = getCached(cacheKey);
|
|
1290
|
+
if (cached) return cached;
|
|
1291
|
+
if (!cad.connected) await cad.connect();
|
|
1292
|
+
if (!cad.connected) {
|
|
1293
|
+
const result = { total: 0, blockRefs: [] };
|
|
1294
|
+
setCache(cacheKey, result);
|
|
1295
|
+
return result;
|
|
1296
|
+
}
|
|
1297
|
+
try {
|
|
1298
|
+
const code = buildBlockRefsCode(params.blockName);
|
|
1299
|
+
const resultStr = await cad.sendCommandWithResult(code);
|
|
1300
|
+
if (!resultStr || resultStr === "" || resultStr === "nil") {
|
|
1301
|
+
const result2 = { total: 0, blockRefs: [] };
|
|
1302
|
+
setCache(cacheKey, result2);
|
|
1303
|
+
return result2;
|
|
1304
|
+
}
|
|
1305
|
+
const parsed = parseLispRecursive(resultStr);
|
|
1306
|
+
if (!parsed || !Array.isArray(parsed)) {
|
|
1307
|
+
const result2 = { total: 0, blockRefs: [] };
|
|
1308
|
+
setCache(cacheKey, result2);
|
|
1309
|
+
return result2;
|
|
1310
|
+
}
|
|
1311
|
+
const result = lispPairsToObject(parsed);
|
|
1312
|
+
const blockRefs = Array.isArray(result.blockRefs) ? result.blockRefs : [];
|
|
1313
|
+
const finalResult = {
|
|
1314
|
+
total: typeof result.total === "number" ? result.total : blockRefs.length,
|
|
1315
|
+
blockRefs: blockRefs.map((br) => {
|
|
1316
|
+
const obj = {};
|
|
1317
|
+
if (Array.isArray(br)) {
|
|
1318
|
+
br.forEach((pair) => {
|
|
1319
|
+
if (Array.isArray(pair) && pair.length >= 2) {
|
|
1320
|
+
const key = pair[0];
|
|
1321
|
+
let val = pair[1];
|
|
1322
|
+
if (key === "insertionPoint" && Array.isArray(val)) {
|
|
1323
|
+
val = val.map((v) => typeof v === "number" ? v : 0);
|
|
1324
|
+
} else if (key === "scale" && Array.isArray(val)) {
|
|
1325
|
+
val = val.map((v) => typeof v === "number" ? v : 1);
|
|
1326
|
+
} else if (key === "isDynamic") {
|
|
1327
|
+
val = val === true || val === "true" || val === 1;
|
|
1328
|
+
}
|
|
1329
|
+
obj[key] = val;
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
return obj;
|
|
1334
|
+
})
|
|
1335
|
+
};
|
|
1336
|
+
setCache(cacheKey, finalResult);
|
|
1337
|
+
return finalResult;
|
|
1338
|
+
} catch (e) {
|
|
1339
|
+
log(`getBlockRefs error: ${e.message}`);
|
|
1340
|
+
const result = { total: 0, blockRefs: [] };
|
|
1341
|
+
setCache(cacheKey, result);
|
|
1342
|
+
return result;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
var TBL_INFO = {
|
|
1346
|
+
layer: { name: "\u56FE\u5C42", fields: ["name", "color", "linetype", "frozen", "locked", "on"] },
|
|
1347
|
+
block: { name: "\u5757\u5B9A\u4E49", fields: ["name", "path", "flags"] },
|
|
1348
|
+
textstyle: { name: "\u6587\u5B57\u6837\u5F0F", fields: ["name", "font", "height", "width", "oblique"] },
|
|
1349
|
+
dimstyle: { name: "\u6807\u6CE8\u6837\u5F0F", fields: ["name", "arrow", "textheight", "scale"] },
|
|
1350
|
+
linetype: { name: "\u7EBF\u578B", fields: ["name", "description", "pattern"] },
|
|
1351
|
+
ucs: { name: "UCS", fields: ["name", "origin", "xaxis", "yaxis"] },
|
|
1352
|
+
view: { name: "\u89C6\u56FE", fields: ["name", "center", "height", "width"] },
|
|
1353
|
+
viewport: { name: "\u89C6\u53E3", fields: ["name", "number", "flags"] },
|
|
1354
|
+
regapp: { name: "\u6CE8\u518C\u5E94\u7528", fields: ["name"] },
|
|
1355
|
+
viewport: { name: "\u89C6\u53E3\u914D\u7F6E", fields: ["name", "number"] },
|
|
1356
|
+
plotstyle: { name: "\u6253\u5370\u6837\u5F0F", fields: ["name"] }
|
|
1357
|
+
};
|
|
1358
|
+
function buildTablesCode(tblName) {
|
|
1359
|
+
const validTbls = Object.keys(TBL_INFO).join('","');
|
|
1360
|
+
return `(progn
|
|
1361
|
+
(vl-load-com)
|
|
1362
|
+
(defun @tbl:get (tbl / res)
|
|
1363
|
+
(setq res nil)
|
|
1364
|
+
(while (setq rec (tblnext tbl (null res)))
|
|
1365
|
+
(setq res (cons (list (cdr (assoc 2 rec)) rec) res)))
|
|
1366
|
+
(reverse res))
|
|
1367
|
+
(defun @tbl:get-all nil
|
|
1368
|
+
(list
|
|
1369
|
+
(cons "layer" (@tbl:get "LAYER"))
|
|
1370
|
+
(cons "block" (@tbl:get "BLOCK"))
|
|
1371
|
+
(cons "textstyle" (@tbl:get "STYLE"))
|
|
1372
|
+
(cons "dimstyle" (@tbl:get "DIMSTYLE"))
|
|
1373
|
+
(cons "linetype" (@tbl:get "LTYPE"))
|
|
1374
|
+
(cons "ucs" (@tbl:get "UCS"))
|
|
1375
|
+
(cons "view" (@tbl:get "VIEW"))
|
|
1376
|
+
(cons "regapp" (@tbl:get "REGAPP"))
|
|
1377
|
+
))
|
|
1378
|
+
(if (member (strcase "${tblName}") (list "${validTbls}"))
|
|
1379
|
+
(list (cons "table" (strcase "${tblName}")) (cons "data" (@tbl:get (strcase "${tblName}"))))
|
|
1380
|
+
(@tbl:get-all)))
|
|
1381
|
+
`;
|
|
1382
|
+
}
|
|
1383
|
+
function parseTableRecord(rec) {
|
|
1384
|
+
if (!Array.isArray(rec) || rec.length < 2) return null;
|
|
1385
|
+
const name = rec[0];
|
|
1386
|
+
const data = rec[1];
|
|
1387
|
+
if (!Array.isArray(data)) return { name };
|
|
1388
|
+
const obj = { name: String(name) };
|
|
1389
|
+
data.forEach((pair) => {
|
|
1390
|
+
if (Array.isArray(pair) && pair.length >= 2) {
|
|
1391
|
+
const key = pair[0];
|
|
1392
|
+
let val = pair[1];
|
|
1393
|
+
if (key === 62) obj.color = typeof val === "number" ? val : 7;
|
|
1394
|
+
else if (key === 6) obj.linetype = String(val);
|
|
1395
|
+
else if (key === 70) obj.flags = typeof val === "number" ? val : 0;
|
|
1396
|
+
else if (key === 1) obj.font = String(val);
|
|
1397
|
+
else if (key === 40) obj.height = typeof val === "number" ? val : 0;
|
|
1398
|
+
else if (key === 41) obj.width = typeof val === "number" ? val : 1;
|
|
1399
|
+
else if (key === 42) obj.oblique = typeof val === "number" ? val : 0;
|
|
1400
|
+
else if (key === 3) obj.description = String(val);
|
|
1401
|
+
else if (key === 10 && Array.isArray(val)) obj.origin = val;
|
|
1402
|
+
else if (key === 11 && Array.isArray(val)) obj.xaxis = val;
|
|
1403
|
+
else if (key === 12 && Array.isArray(val)) obj.yaxis = val;
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
return obj;
|
|
1407
|
+
}
|
|
1408
|
+
async function getTables(params = {}) {
|
|
1409
|
+
const tblName = params.tbl || "all";
|
|
1410
|
+
const cacheKey = `dwg:tbl:${tblName}`;
|
|
1411
|
+
const cached = getCached(cacheKey);
|
|
1412
|
+
if (cached) return cached;
|
|
1413
|
+
if (!cad.connected) await cad.connect();
|
|
1414
|
+
if (!cad.connected) return { table: tblName, data: [] };
|
|
1415
|
+
try {
|
|
1416
|
+
const code = buildTablesCode(tblName);
|
|
1417
|
+
const resultStr = await cad.sendCommandWithResult(code);
|
|
1418
|
+
if (!resultStr || resultStr === "" || resultStr === "nil") {
|
|
1419
|
+
const result2 = { table: tblName, data: [] };
|
|
1420
|
+
setCache(cacheKey, result2);
|
|
1421
|
+
return result2;
|
|
1422
|
+
}
|
|
1423
|
+
const parsed = parseLispRecursive(resultStr);
|
|
1424
|
+
if (!parsed || !Array.isArray(parsed)) {
|
|
1425
|
+
const result2 = { table: tblName, data: [] };
|
|
1426
|
+
setCache(cacheKey, result2);
|
|
1427
|
+
return result2;
|
|
1428
|
+
}
|
|
1429
|
+
const isSingleTable = parsed.length >= 2 && parsed[0] === "table";
|
|
1430
|
+
let result;
|
|
1431
|
+
if (isSingleTable) {
|
|
1432
|
+
const data = Array.isArray(parsed[1]) ? parsed[1] : [];
|
|
1433
|
+
const tblData = Array.isArray(parsed[2]) ? parsed[2] : [];
|
|
1434
|
+
result = {
|
|
1435
|
+
table: String(data),
|
|
1436
|
+
data: tblData.map(parseTableRecord).filter(Boolean)
|
|
1437
|
+
};
|
|
1438
|
+
} else {
|
|
1439
|
+
const allData = {};
|
|
1440
|
+
parsed.forEach((item) => {
|
|
1441
|
+
if (Array.isArray(item) && item.length >= 2) {
|
|
1442
|
+
const key = item[0];
|
|
1443
|
+
const vals = Array.isArray(item[1]) ? item[1] : [];
|
|
1444
|
+
allData[key] = vals.map(parseTableRecord).filter(Boolean);
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
result = allData;
|
|
1448
|
+
}
|
|
1449
|
+
setCache(cacheKey, result);
|
|
1450
|
+
return result;
|
|
1451
|
+
} catch (e) {
|
|
1452
|
+
log(`getTables error: ${e.message}`);
|
|
1453
|
+
const result = { table: tblName, data: [] };
|
|
1454
|
+
setCache(cacheKey, result);
|
|
1455
|
+
return result;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1358
1458
|
async function getPackages(filterName = null) {
|
|
1359
1459
|
const cacheKey = filterName ? `packages:${filterName}` : "packages:all";
|
|
1360
1460
|
const cached = getCached(cacheKey);
|
|
1361
|
-
if (cached)
|
|
1362
|
-
|
|
1363
|
-
if (!cad.connected)
|
|
1364
|
-
await cad.connect();
|
|
1365
|
-
if (!cad.connected)
|
|
1366
|
-
return [];
|
|
1461
|
+
if (cached) return cached;
|
|
1462
|
+
if (!cad.connected) await cad.connect();
|
|
1463
|
+
if (!cad.connected) return [];
|
|
1367
1464
|
try {
|
|
1368
1465
|
const code = `(mapcar 'cdr @::*local-pkgs*)`;
|
|
1369
1466
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -1377,8 +1474,7 @@ async function getPackages(filterName = null) {
|
|
|
1377
1474
|
} catch {
|
|
1378
1475
|
raw = parseLispList(result) || [];
|
|
1379
1476
|
}
|
|
1380
|
-
if (!Array.isArray(raw))
|
|
1381
|
-
raw = [];
|
|
1477
|
+
if (!Array.isArray(raw)) raw = [];
|
|
1382
1478
|
const packages = raw.map((item) => {
|
|
1383
1479
|
if (Array.isArray(item)) {
|
|
1384
1480
|
const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
|
|
@@ -1387,20 +1483,13 @@ async function getPackages(filterName = null) {
|
|
|
1387
1483
|
const [[key, val]] = Object.entries(entry);
|
|
1388
1484
|
const k = String(key);
|
|
1389
1485
|
const v = String(val);
|
|
1390
|
-
if (k === ":NAME")
|
|
1391
|
-
|
|
1392
|
-
else if (k === ":
|
|
1393
|
-
|
|
1394
|
-
else if (k === ":
|
|
1395
|
-
|
|
1396
|
-
else if (k === ":
|
|
1397
|
-
pkg.fullName = v;
|
|
1398
|
-
else if (k === ":AUTHOR")
|
|
1399
|
-
pkg.author = v;
|
|
1400
|
-
else if (k === ":CATEGORY")
|
|
1401
|
-
pkg.category = v;
|
|
1402
|
-
else if (k === ":URL")
|
|
1403
|
-
pkg.url = v;
|
|
1486
|
+
if (k === ":NAME") pkg.name = v;
|
|
1487
|
+
else if (k === ":VERSION") pkg.version = v;
|
|
1488
|
+
else if (k === ":DESCRIPTION") pkg.description = v;
|
|
1489
|
+
else if (k === ":FULL-NAME") pkg.fullName = v;
|
|
1490
|
+
else if (k === ":AUTHOR") pkg.author = v;
|
|
1491
|
+
else if (k === ":CATEGORY") pkg.category = v;
|
|
1492
|
+
else if (k === ":URL") pkg.url = v;
|
|
1404
1493
|
}
|
|
1405
1494
|
}
|
|
1406
1495
|
return pkg;
|
|
@@ -1411,22 +1500,15 @@ async function getPackages(filterName = null) {
|
|
|
1411
1500
|
if (item && typeof item === "object") {
|
|
1412
1501
|
const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
|
|
1413
1502
|
const nameVal = item.name || item.Name || item.NAME || item[":NAME"];
|
|
1414
|
-
if (nameVal)
|
|
1415
|
-
pkg.name = String(nameVal);
|
|
1503
|
+
if (nameVal) pkg.name = String(nameVal);
|
|
1416
1504
|
const verVal = item.version || item.Version || item.VERSION || item[":VERSION"];
|
|
1417
|
-
if (verVal)
|
|
1418
|
-
pkg.version = String(verVal);
|
|
1505
|
+
if (verVal) pkg.version = String(verVal);
|
|
1419
1506
|
const descVal = item.description || item.Description || item.DESCRIPTION || item[":DESCRIPTION"];
|
|
1420
|
-
if (descVal)
|
|
1421
|
-
|
|
1422
|
-
if (item.
|
|
1423
|
-
|
|
1424
|
-
if (item.
|
|
1425
|
-
pkg.author = String(item.author || item.Author);
|
|
1426
|
-
if (item.category || item.Category)
|
|
1427
|
-
pkg.category = String(item.category || item.Category);
|
|
1428
|
-
if (item.url || item.Url || item.URL)
|
|
1429
|
-
pkg.url = String(item.url || item.Url || item.URL);
|
|
1507
|
+
if (descVal) pkg.description = String(descVal);
|
|
1508
|
+
if (item.fullName || item.full_name) pkg.fullName = String(item.fullName || item.full_name);
|
|
1509
|
+
if (item.author || item.Author) pkg.author = String(item.author || item.Author);
|
|
1510
|
+
if (item.category || item.Category) pkg.category = String(item.category || item.Category);
|
|
1511
|
+
if (item.url || item.Url || item.URL) pkg.url = String(item.url || item.Url || item.URL);
|
|
1430
1512
|
return pkg;
|
|
1431
1513
|
}
|
|
1432
1514
|
return null;
|
|
@@ -1452,12 +1534,9 @@ function getPlatforms() {
|
|
|
1452
1534
|
async function getDwgList() {
|
|
1453
1535
|
const cacheKey = "cad:dwgs";
|
|
1454
1536
|
const cached = getCached(cacheKey);
|
|
1455
|
-
if (cached)
|
|
1456
|
-
|
|
1457
|
-
if (!cad.connected)
|
|
1458
|
-
await cad.connect();
|
|
1459
|
-
if (!cad.connected)
|
|
1460
|
-
return [];
|
|
1537
|
+
if (cached) return cached;
|
|
1538
|
+
if (!cad.connected) await cad.connect();
|
|
1539
|
+
if (!cad.connected) return [];
|
|
1461
1540
|
try {
|
|
1462
1541
|
const code = `(progn
|
|
1463
1542
|
(vl-load-com)
|
|
@@ -1481,8 +1560,7 @@ async function getDwgList() {
|
|
|
1481
1560
|
parsed = listResult;
|
|
1482
1561
|
}
|
|
1483
1562
|
}
|
|
1484
|
-
if (!Array.isArray(parsed))
|
|
1485
|
-
parsed = [];
|
|
1563
|
+
if (!Array.isArray(parsed)) parsed = [];
|
|
1486
1564
|
const dwgList = parsed.map((item) => {
|
|
1487
1565
|
if (Array.isArray(item) && item.length >= 2) {
|
|
1488
1566
|
return { name: String(item[0]), path: String(item[1]) };
|
|
@@ -1509,8 +1587,7 @@ function loadStandardsFile(filename) {
|
|
|
1509
1587
|
var standardsCache = /* @__PURE__ */ new Map();
|
|
1510
1588
|
function getCachedStandards(key) {
|
|
1511
1589
|
const entry = standardsCache.get(key);
|
|
1512
|
-
if (entry && Date.now() - entry.timestamp < 3e4)
|
|
1513
|
-
return entry.data;
|
|
1590
|
+
if (entry && Date.now() - entry.timestamp < 3e4) return entry.data;
|
|
1514
1591
|
standardsCache.delete(key);
|
|
1515
1592
|
return null;
|
|
1516
1593
|
}
|
|
@@ -1519,20 +1596,16 @@ function setCachedStandards(key, data) {
|
|
|
1519
1596
|
}
|
|
1520
1597
|
function getDraftingStandards() {
|
|
1521
1598
|
const cached = getCachedStandards("drafting");
|
|
1522
|
-
if (cached)
|
|
1523
|
-
return cached;
|
|
1599
|
+
if (cached) return cached;
|
|
1524
1600
|
const data = loadStandardsFile("drafting.json");
|
|
1525
|
-
if (data)
|
|
1526
|
-
setCachedStandards("drafting", data);
|
|
1601
|
+
if (data) setCachedStandards("drafting", data);
|
|
1527
1602
|
return data || { error: "\u5236\u56FE\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
|
|
1528
1603
|
}
|
|
1529
1604
|
function getCodingStandards() {
|
|
1530
1605
|
const cached = getCachedStandards("coding");
|
|
1531
|
-
if (cached)
|
|
1532
|
-
return cached;
|
|
1606
|
+
if (cached) return cached;
|
|
1533
1607
|
const data = loadStandardsFile("coding.json");
|
|
1534
|
-
if (data)
|
|
1535
|
-
setCachedStandards("coding", data);
|
|
1608
|
+
if (data) setCachedStandards("coding", data);
|
|
1536
1609
|
return data || { error: "\u7F16\u7801\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
|
|
1537
1610
|
}
|
|
1538
1611
|
|
|
@@ -1747,11 +1820,9 @@ var SseSession = class {
|
|
|
1747
1820
|
return lines.join("\n") + "\n\n";
|
|
1748
1821
|
}
|
|
1749
1822
|
_setupDrain() {
|
|
1750
|
-
if (typeof this.#res.on !== "function")
|
|
1751
|
-
return;
|
|
1823
|
+
if (typeof this.#res.on !== "function") return;
|
|
1752
1824
|
this.#drainHandler = () => {
|
|
1753
|
-
if (!this.#active)
|
|
1754
|
-
return;
|
|
1825
|
+
if (!this.#active) return;
|
|
1755
1826
|
if (this.#backpressureBuffer.length > 0) {
|
|
1756
1827
|
this._drainBuffer();
|
|
1757
1828
|
}
|
|
@@ -1773,8 +1844,7 @@ var SseSession = class {
|
|
|
1773
1844
|
}
|
|
1774
1845
|
}
|
|
1775
1846
|
_write(content) {
|
|
1776
|
-
if (!this.#active)
|
|
1777
|
-
return false;
|
|
1847
|
+
if (!this.#active) return false;
|
|
1778
1848
|
try {
|
|
1779
1849
|
if (this.#backpressureBuffer.length > 0) {
|
|
1780
1850
|
this.#backpressureBuffer.push(content);
|
|
@@ -1902,8 +1972,7 @@ function persistSessionData(clientId, sessionData) {
|
|
|
1902
1972
|
function loadPersistedSessionData(clientId) {
|
|
1903
1973
|
try {
|
|
1904
1974
|
const filePath = getSessionStorePath(clientId);
|
|
1905
|
-
if (!fs4.existsSync(filePath))
|
|
1906
|
-
return null;
|
|
1975
|
+
if (!fs4.existsSync(filePath)) return null;
|
|
1907
1976
|
const raw = fs4.readFileSync(filePath, "utf-8");
|
|
1908
1977
|
const store = JSON.parse(raw);
|
|
1909
1978
|
if (Date.now() - store.savedAt > SESSION_STORE_TTL) {
|
|
@@ -2063,8 +2132,7 @@ var SessionTransport = class {
|
|
|
2063
2132
|
this._started = true;
|
|
2064
2133
|
}
|
|
2065
2134
|
async send(message) {
|
|
2066
|
-
if (this._closed)
|
|
2067
|
-
return;
|
|
2135
|
+
if (this._closed) return;
|
|
2068
2136
|
if (this._pendingRequest) {
|
|
2069
2137
|
const { resolve, reject, timeout } = this._pendingRequest;
|
|
2070
2138
|
clearTimeout(timeout);
|
|
@@ -2073,8 +2141,7 @@ var SessionTransport = class {
|
|
|
2073
2141
|
}
|
|
2074
2142
|
}
|
|
2075
2143
|
async close() {
|
|
2076
|
-
if (this._closed)
|
|
2077
|
-
return;
|
|
2144
|
+
if (this._closed) return;
|
|
2078
2145
|
this._closed = true;
|
|
2079
2146
|
if (this._pendingRequest) {
|
|
2080
2147
|
const { reject, timeout } = this._pendingRequest;
|
|
@@ -2386,14 +2453,10 @@ ${generateSuggestions(entities, layers)}`
|
|
|
2386
2453
|
}
|
|
2387
2454
|
function generateSuggestions(entities, layers) {
|
|
2388
2455
|
const suggestions = [];
|
|
2389
|
-
if (entities.total > 1e3)
|
|
2390
|
-
|
|
2391
|
-
if (
|
|
2392
|
-
|
|
2393
|
-
if (entities.byType.LINE && entities.byType.LINE > 500)
|
|
2394
|
-
suggestions.push("- \u7EBF\u6761\u8F83\u591A\uFF0C\u53EF\u8003\u8651\u4F7F\u7528 BLOCK \u51CF\u5C11\u5B9E\u4F53\u6570\u91CF");
|
|
2395
|
-
if (!entities.byType.DIMENSION)
|
|
2396
|
-
suggestions.push("- \u672A\u53D1\u73B0\u5C3A\u5BF8\u6807\u6CE8\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u6807\u6CE8");
|
|
2456
|
+
if (entities.total > 1e3) suggestions.push("- \u56FE\u7EB8\u5B9E\u4F53\u8F83\u591A\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u56FE\u5C42\u5206\u7C7B\u7BA1\u7406");
|
|
2457
|
+
if (layers.length > 20) suggestions.push("- \u56FE\u5C42\u8F83\u591A\uFF0C\u5EFA\u8BAE\u6E05\u7406\u672A\u4F7F\u7528\u7684\u56FE\u5C42");
|
|
2458
|
+
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");
|
|
2459
|
+
if (!entities.byType.DIMENSION) suggestions.push("- \u672A\u53D1\u73B0\u5C3A\u5BF8\u6807\u6CE8\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u6807\u6CE8");
|
|
2397
2460
|
return suggestions.length ? suggestions.join("\n") : "- \u56FE\u7EB8\u7ED3\u6784\u826F\u597D";
|
|
2398
2461
|
}
|
|
2399
2462
|
async function generateBatchLinesPrompt(args) {
|
|
@@ -2938,8 +3001,7 @@ var Metrics = class {
|
|
|
2938
3001
|
bucket.sum += value;
|
|
2939
3002
|
bucket.min = Math.min(bucket.min, value);
|
|
2940
3003
|
bucket.max = Math.max(bucket.max, value);
|
|
2941
|
-
if (!bucket.values)
|
|
2942
|
-
bucket.values = [];
|
|
3004
|
+
if (!bucket.values) bucket.values = [];
|
|
2943
3005
|
bucket.values.push(value);
|
|
2944
3006
|
this.histograms.set(key, bucket);
|
|
2945
3007
|
}
|
|
@@ -3030,33 +3092,33 @@ var RESOURCE_TEMPLATES = [
|
|
|
3030
3092
|
mimeType: "application/json"
|
|
3031
3093
|
},
|
|
3032
3094
|
{
|
|
3033
|
-
uriTemplate: "atlisp://dwg/entities",
|
|
3034
|
-
name: "Entities
|
|
3035
|
-
description: "\
|
|
3095
|
+
uriTemplate: "atlisp://dwg/entities?type={type}",
|
|
3096
|
+
name: "Entities by Type",
|
|
3097
|
+
description: "\u6309\u7C7B\u578B\u67E5\u8BE2\u5B9E\u4F53\u5217\u8868",
|
|
3036
3098
|
mimeType: "application/json"
|
|
3037
3099
|
},
|
|
3038
3100
|
{
|
|
3039
|
-
uriTemplate: "atlisp://
|
|
3040
|
-
name: "
|
|
3041
|
-
description: "\
|
|
3101
|
+
uriTemplate: "atlisp://packages?search={query}",
|
|
3102
|
+
name: "Package Search",
|
|
3103
|
+
description: "\u641C\u7D22 @lisp \u5305",
|
|
3042
3104
|
mimeType: "application/json"
|
|
3043
3105
|
},
|
|
3044
3106
|
{
|
|
3045
|
-
uriTemplate: "atlisp://dwg/
|
|
3046
|
-
name: "
|
|
3047
|
-
description: "\
|
|
3107
|
+
uriTemplate: "atlisp://dwg/block-refs?blockName={blockName}",
|
|
3108
|
+
name: "Block References",
|
|
3109
|
+
description: "\u83B7\u53D6\u5757\u53C2\u7167\u5217\u8868\uFF0C\u652F\u6301\u6309\u5757\u540D\u8FC7\u6EE4",
|
|
3048
3110
|
mimeType: "application/json"
|
|
3049
3111
|
},
|
|
3050
3112
|
{
|
|
3051
|
-
uriTemplate: "atlisp://
|
|
3052
|
-
name: "
|
|
3053
|
-
description: "\
|
|
3113
|
+
uriTemplate: "atlisp://dwg/tbl?tbl={tbl}",
|
|
3114
|
+
name: "CAD Tables",
|
|
3115
|
+
description: "\u83B7\u53D6 CAD \u8868\u6570\u636E (layer, block, textstyle, dimstyle, linetype, ucs, view, regapp)",
|
|
3054
3116
|
mimeType: "application/json"
|
|
3055
3117
|
},
|
|
3056
3118
|
{
|
|
3057
|
-
uriTemplate: "atlisp://dwg/
|
|
3058
|
-
name: "Text
|
|
3059
|
-
description: "\
|
|
3119
|
+
uriTemplate: "atlisp://dwg/text-content?bbox={bbox}&layer={layer}&offset={offset}&limit={limit}",
|
|
3120
|
+
name: "Text Content",
|
|
3121
|
+
description: "\u6587\u672C\u5185\u5BB9\u53CA\u4F4D\u7F6E\uFF0C\u7528\u4E8E\u8BED\u4E49\u5206\u6790",
|
|
3060
3122
|
mimeType: "application/json"
|
|
3061
3123
|
}
|
|
3062
3124
|
];
|
|
@@ -3178,8 +3240,7 @@ async function evalLisp(code, withResult = false, encoding = null) {
|
|
|
3178
3240
|
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3179
3241
|
}
|
|
3180
3242
|
const trimmed = (code || "").trim();
|
|
3181
|
-
if (!trimmed)
|
|
3182
|
-
return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3243
|
+
if (!trimmed) return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3183
3244
|
try {
|
|
3184
3245
|
if (withResult) {
|
|
3185
3246
|
const result = await cad.sendCommandWithResult(trimmed, encoding);
|
|
@@ -3199,17 +3260,14 @@ async function getCadInfo2() {
|
|
|
3199
3260
|
if (!cad.connected) {
|
|
3200
3261
|
await cad.connect();
|
|
3201
3262
|
}
|
|
3202
|
-
if (!cad.connected)
|
|
3203
|
-
return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
|
|
3263
|
+
if (!cad.connected) return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
|
|
3204
3264
|
const info = await cad.getInfo();
|
|
3205
3265
|
return { content: [{ type: "text", text: info }] };
|
|
3206
3266
|
}
|
|
3207
3267
|
async function atCommand(command) {
|
|
3208
|
-
if (!cad.connected)
|
|
3209
|
-
return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
|
|
3268
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
|
|
3210
3269
|
const trimmed = (command || "").trim();
|
|
3211
|
-
if (!trimmed)
|
|
3212
|
-
return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3270
|
+
if (!trimmed) return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3213
3271
|
await cad.sendCommand(trimmed + "\n");
|
|
3214
3272
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001\u547D\u4EE4" }] };
|
|
3215
3273
|
}
|
|
@@ -3217,8 +3275,7 @@ async function newDocument() {
|
|
|
3217
3275
|
if (!cad.connected) {
|
|
3218
3276
|
await cad.connect();
|
|
3219
3277
|
}
|
|
3220
|
-
if (!cad.connected)
|
|
3221
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3278
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3222
3279
|
const result = await cad.newDoc();
|
|
3223
3280
|
if (result) {
|
|
3224
3281
|
return { content: [{ type: "text", text: "\u5DF2\u5728 CAD \u4E2D\u65B0\u5EFA\u7A7A\u767D\u6587\u6863" }] };
|
|
@@ -3229,8 +3286,7 @@ async function bringToFront() {
|
|
|
3229
3286
|
if (!cad.connected) {
|
|
3230
3287
|
await cad.connect();
|
|
3231
3288
|
}
|
|
3232
|
-
if (!cad.connected)
|
|
3233
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3289
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3234
3290
|
const result = await cad.bringToFront();
|
|
3235
3291
|
if (result) {
|
|
3236
3292
|
return { content: [{ type: "text", text: "\u5DF2\u5C06 CAD \u7A97\u53E3\u5207\u6362\u5230\u524D\u53F0" }] };
|
|
@@ -3241,8 +3297,7 @@ async function installAtlisp() {
|
|
|
3241
3297
|
if (!cad.connected) {
|
|
3242
3298
|
await cad.connect();
|
|
3243
3299
|
}
|
|
3244
|
-
if (!cad.connected)
|
|
3245
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3300
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3246
3301
|
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))))`;
|
|
3247
3302
|
await cad.sendCommand(installCode + "\n");
|
|
3248
3303
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u5B89\u88C5\u4EE3\u7801\u5230 CAD" }] };
|
|
@@ -3251,12 +3306,10 @@ async function listFunctionsInCad() {
|
|
|
3251
3306
|
if (!cad.connected) {
|
|
3252
3307
|
await cad.connect();
|
|
3253
3308
|
}
|
|
3254
|
-
if (!cad.connected)
|
|
3255
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3309
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3256
3310
|
try {
|
|
3257
3311
|
const result = await cad.sendCommandWithResult("(atoms-family 0)", null);
|
|
3258
|
-
if (result)
|
|
3259
|
-
return { content: [{ type: "text", text: result }] };
|
|
3312
|
+
if (result) return { content: [{ type: "text", text: result }] };
|
|
3260
3313
|
return { content: [{ type: "text", text: "CAD \u51FD\u6570\u5217\u8868\u4E3A\u7A7A" }] };
|
|
3261
3314
|
} catch (e) {
|
|
3262
3315
|
return { content: [{ type: "text", text: `\u9519\u8BEF: ${e.message}` }], isError: true };
|
|
@@ -3311,8 +3364,7 @@ async function initAtlisp() {
|
|
|
3311
3364
|
if (!cad.connected) {
|
|
3312
3365
|
await cad.connect();
|
|
3313
3366
|
}
|
|
3314
|
-
if (!cad.connected)
|
|
3315
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3367
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3316
3368
|
const code = `(if (null @::load-module)
|
|
3317
3369
|
(progn
|
|
3318
3370
|
(vl-load-com)
|
|
@@ -3352,15 +3404,12 @@ async function fetchPackages() {
|
|
|
3352
3404
|
return cachedPackages || MOCK_PACKAGES;
|
|
3353
3405
|
}
|
|
3354
3406
|
function flattenPackages(data) {
|
|
3355
|
-
if (Array.isArray(data))
|
|
3356
|
-
|
|
3357
|
-
if (data && Array.isArray(data.packages))
|
|
3358
|
-
return data.packages;
|
|
3407
|
+
if (Array.isArray(data)) return data;
|
|
3408
|
+
if (data && Array.isArray(data.packages)) return data.packages;
|
|
3359
3409
|
return [];
|
|
3360
3410
|
}
|
|
3361
3411
|
async function listPackages() {
|
|
3362
|
-
if (!cad.connected)
|
|
3363
|
-
await cad.connect();
|
|
3412
|
+
if (!cad.connected) await cad.connect();
|
|
3364
3413
|
if (!cad.connected) {
|
|
3365
3414
|
const data2 = await fetchPackages();
|
|
3366
3415
|
const items2 = flattenPackages(data2);
|
|
@@ -3368,8 +3417,7 @@ async function listPackages() {
|
|
|
3368
3417
|
return { content: [{ type: "text", text: text2 }] };
|
|
3369
3418
|
}
|
|
3370
3419
|
const result = await cad.sendCommandWithResult("(@::package-list-in-local)");
|
|
3371
|
-
if (result && result !== "nil")
|
|
3372
|
-
return { content: [{ type: "text", text: result }] };
|
|
3420
|
+
if (result && result !== "nil") return { content: [{ type: "text", text: result }] };
|
|
3373
3421
|
const data = await fetchPackages();
|
|
3374
3422
|
const items = flattenPackages(data);
|
|
3375
3423
|
const text = items.length ? `\u4ECE\u6CE8\u518C\u8868\u83B7\u53D6\u7684 @lisp \u5305:
|
|
@@ -3389,12 +3437,10 @@ async function searchPackages(query) {
|
|
|
3389
3437
|
for (const p of items) {
|
|
3390
3438
|
const name = (p.name || "").toLowerCase();
|
|
3391
3439
|
const desc = (p.description || "").toLowerCase();
|
|
3392
|
-
if (name.includes(q) || desc.includes(q))
|
|
3393
|
-
results.push(p);
|
|
3440
|
+
if (name.includes(q) || desc.includes(q)) results.push(p);
|
|
3394
3441
|
}
|
|
3395
3442
|
} else {
|
|
3396
|
-
for (const p of items)
|
|
3397
|
-
results.push(p);
|
|
3443
|
+
for (const p of items) results.push(p);
|
|
3398
3444
|
}
|
|
3399
3445
|
if (results.length === 0) {
|
|
3400
3446
|
return { content: [{ type: "text", text: `\u672A\u627E\u5230\u5305\u542B "${query}" \u7684\u5305` }] };
|
|
@@ -3446,8 +3492,7 @@ function writeCacheToDisk(data) {
|
|
|
3446
3492
|
}
|
|
3447
3493
|
async function fetchFunctions() {
|
|
3448
3494
|
const diskCache = readCacheFromDisk();
|
|
3449
|
-
if (diskCache)
|
|
3450
|
-
return diskCache;
|
|
3495
|
+
if (diskCache) return diskCache;
|
|
3451
3496
|
try {
|
|
3452
3497
|
const response = await fetch(FUNCTIONS_URL, { headers: { "User-Agent": "atlisp-mcp" } });
|
|
3453
3498
|
if (response.ok) {
|
|
@@ -3467,8 +3512,7 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
3467
3512
|
if (data) {
|
|
3468
3513
|
const funcs = Object.values(data.all_functions || {});
|
|
3469
3514
|
const func = funcs.find((f2) => f2.name === funcName || f2.name === `${packageName}:${funcName}`);
|
|
3470
|
-
if (func)
|
|
3471
|
-
results.push(func);
|
|
3515
|
+
if (func) results.push(func);
|
|
3472
3516
|
}
|
|
3473
3517
|
if (results.length === 0 && FUNCTIONS_DIR) {
|
|
3474
3518
|
try {
|
|
@@ -3477,8 +3521,7 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
3477
3521
|
const raw = fs6.readFileSync(path8.join(FUNCTIONS_DIR, file), "utf-8");
|
|
3478
3522
|
const data2 = JSON.parse(raw);
|
|
3479
3523
|
const func = data2.functions?.find((f2) => f2.name === funcName);
|
|
3480
|
-
if (func)
|
|
3481
|
-
results.push(func);
|
|
3524
|
+
if (func) results.push(func);
|
|
3482
3525
|
}
|
|
3483
3526
|
} catch {
|
|
3484
3527
|
}
|
|
@@ -3546,8 +3589,7 @@ async function getEntity(handle) {
|
|
|
3546
3589
|
if (!cad.connected) {
|
|
3547
3590
|
await cad.connect();
|
|
3548
3591
|
}
|
|
3549
|
-
if (!cad.connected)
|
|
3550
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3592
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3551
3593
|
const code = `(progn
|
|
3552
3594
|
(vl-load-com)
|
|
3553
3595
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3579,8 +3621,7 @@ async function setEntityProperty(handle, property, value) {
|
|
|
3579
3621
|
if (!cad.connected) {
|
|
3580
3622
|
await cad.connect();
|
|
3581
3623
|
}
|
|
3582
|
-
if (!cad.connected)
|
|
3583
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3624
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3584
3625
|
let propCode = "";
|
|
3585
3626
|
switch (property) {
|
|
3586
3627
|
case "layer":
|
|
@@ -3623,8 +3664,7 @@ async function deleteEntity(handle) {
|
|
|
3623
3664
|
if (!cad.connected) {
|
|
3624
3665
|
await cad.connect();
|
|
3625
3666
|
}
|
|
3626
|
-
if (!cad.connected)
|
|
3627
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3667
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3628
3668
|
const code = `(progn
|
|
3629
3669
|
(vl-load-com)
|
|
3630
3670
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3649,15 +3689,12 @@ async function selectEntities(filter) {
|
|
|
3649
3689
|
if (!cad.connected) {
|
|
3650
3690
|
await cad.connect();
|
|
3651
3691
|
}
|
|
3652
|
-
if (!cad.connected)
|
|
3653
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3692
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3654
3693
|
let filterCode = "nil";
|
|
3655
3694
|
if (filter && (filter.type || filter.layer)) {
|
|
3656
3695
|
const items = [];
|
|
3657
|
-
if (filter.type)
|
|
3658
|
-
|
|
3659
|
-
if (filter.layer)
|
|
3660
|
-
items.push(`'(8 . "${filter.layer}")`);
|
|
3696
|
+
if (filter.type) items.push(`'(0 . "${filter.type}")`);
|
|
3697
|
+
if (filter.layer) items.push(`'(8 . "${filter.layer}")`);
|
|
3661
3698
|
filterCode = `(list ${items.join(" ")})`;
|
|
3662
3699
|
}
|
|
3663
3700
|
const code = `(progn
|
|
@@ -3689,8 +3726,7 @@ async function createLayer(name, color = 7, linetype = "Continuous") {
|
|
|
3689
3726
|
if (!cad.connected) {
|
|
3690
3727
|
await cad.connect();
|
|
3691
3728
|
}
|
|
3692
|
-
if (!cad.connected)
|
|
3693
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3729
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3694
3730
|
const code = `(progn
|
|
3695
3731
|
(vl-load-com)
|
|
3696
3732
|
(if (not (tblsearch "LAYER" "${name}"))
|
|
@@ -3726,8 +3762,7 @@ async function deleteLayer(name) {
|
|
|
3726
3762
|
if (!cad.connected) {
|
|
3727
3763
|
await cad.connect();
|
|
3728
3764
|
}
|
|
3729
|
-
if (!cad.connected)
|
|
3730
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3765
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3731
3766
|
const code = `(progn
|
|
3732
3767
|
(vl-load-com)
|
|
3733
3768
|
(cond
|
|
@@ -3761,8 +3796,7 @@ async function setLayerProperty(name, property, value) {
|
|
|
3761
3796
|
if (!cad.connected) {
|
|
3762
3797
|
await cad.connect();
|
|
3763
3798
|
}
|
|
3764
|
-
if (!cad.connected)
|
|
3765
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3799
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3766
3800
|
let propCode = "";
|
|
3767
3801
|
switch (property) {
|
|
3768
3802
|
case "color":
|
|
@@ -3810,8 +3844,7 @@ async function setCurrentLayer(name) {
|
|
|
3810
3844
|
if (!cad.connected) {
|
|
3811
3845
|
await cad.connect();
|
|
3812
3846
|
}
|
|
3813
|
-
if (!cad.connected)
|
|
3814
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3847
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3815
3848
|
const code = `(progn
|
|
3816
3849
|
(vl-load-com)
|
|
3817
3850
|
(if (tblsearch "LAYER" "${name}")
|
|
@@ -3838,8 +3871,7 @@ async function createBlock(name, entities) {
|
|
|
3838
3871
|
if (!cad.connected) {
|
|
3839
3872
|
await cad.connect();
|
|
3840
3873
|
}
|
|
3841
|
-
if (!cad.connected)
|
|
3842
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3874
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3843
3875
|
const code = `(progn
|
|
3844
3876
|
(vl-load-com)
|
|
3845
3877
|
(if (not (tblsearch "BLOCK" "${name}"))
|
|
@@ -3876,8 +3908,7 @@ async function insertBlock(blockName, point, scale = 1, rotation = 0) {
|
|
|
3876
3908
|
if (!cad.connected) {
|
|
3877
3909
|
await cad.connect();
|
|
3878
3910
|
}
|
|
3879
|
-
if (!cad.connected)
|
|
3880
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3911
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3881
3912
|
const coords = Array.isArray(point) ? point : point.split(",").map((s) => parseFloat(s.trim()));
|
|
3882
3913
|
if (coords.length < 2) {
|
|
3883
3914
|
return { content: [{ type: "text", text: "\u63D2\u5165\u70B9\u683C\u5F0F\u9519\u8BEF\uFF0C\u9700\u8981 x,y \u6216 [x,y,z]" }], isError: true };
|
|
@@ -3907,8 +3938,7 @@ async function getBlocks() {
|
|
|
3907
3938
|
if (!cad.connected) {
|
|
3908
3939
|
await cad.connect();
|
|
3909
3940
|
}
|
|
3910
|
-
if (!cad.connected)
|
|
3911
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3941
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3912
3942
|
const code = `(progn
|
|
3913
3943
|
(vl-load-com)
|
|
3914
3944
|
(setq blocks nil)
|
|
@@ -3931,8 +3961,7 @@ async function explodeBlock(handle) {
|
|
|
3931
3961
|
if (!cad.connected) {
|
|
3932
3962
|
await cad.connect();
|
|
3933
3963
|
}
|
|
3934
|
-
if (!cad.connected)
|
|
3935
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3964
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3936
3965
|
const code = `(progn
|
|
3937
3966
|
(vl-load-com)
|
|
3938
3967
|
(if (setq ent (handent "${handle}"))
|
|
@@ -3959,8 +3988,7 @@ async function openDwg(filePath) {
|
|
|
3959
3988
|
if (!cad.connected) {
|
|
3960
3989
|
await cad.connect();
|
|
3961
3990
|
}
|
|
3962
|
-
if (!cad.connected)
|
|
3963
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3991
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3964
3992
|
const normalizedPath = filePath.replace(/\\/g, "\\\\");
|
|
3965
3993
|
const code = `(progn
|
|
3966
3994
|
(vl-load-com)
|
|
@@ -3997,8 +4025,7 @@ async function saveDwg(filePath = null) {
|
|
|
3997
4025
|
if (!cad.connected) {
|
|
3998
4026
|
await cad.connect();
|
|
3999
4027
|
}
|
|
4000
|
-
if (!cad.connected)
|
|
4001
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4028
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4002
4029
|
const code = filePath ? `(progn
|
|
4003
4030
|
(vl-load-com)
|
|
4004
4031
|
(command "._SAVEAS" "${filePath.replace(/\\/g, "\\\\")}")
|
|
@@ -4022,8 +4049,7 @@ async function exportPdf(outputPath, layout = "Model") {
|
|
|
4022
4049
|
if (!cad.connected) {
|
|
4023
4050
|
await cad.connect();
|
|
4024
4051
|
}
|
|
4025
|
-
if (!cad.connected)
|
|
4026
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4052
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4027
4053
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4028
4054
|
const code = `(progn
|
|
4029
4055
|
(vl-load-com)
|
|
@@ -4051,8 +4077,7 @@ async function closeDwg(save = false) {
|
|
|
4051
4077
|
if (!cad.connected) {
|
|
4052
4078
|
await cad.connect();
|
|
4053
4079
|
}
|
|
4054
|
-
if (!cad.connected)
|
|
4055
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4080
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4056
4081
|
const code = `(progn
|
|
4057
4082
|
(vl-load-com)
|
|
4058
4083
|
(if ${save ? "T" : "nil"}
|
|
@@ -4074,8 +4099,7 @@ async function createDimension(type, points, style = {}) {
|
|
|
4074
4099
|
if (!cad.connected) {
|
|
4075
4100
|
await cad.connect();
|
|
4076
4101
|
}
|
|
4077
|
-
if (!cad.connected)
|
|
4078
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4102
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4079
4103
|
let dimCode = "";
|
|
4080
4104
|
const validTypes = ["ALIGNED", "LINEAR", "ORDINATE", "RADIAL", "DIAMETER", "ANGULAR"];
|
|
4081
4105
|
const dimType = (type || "ALIGNED").toUpperCase();
|
|
@@ -4117,8 +4141,7 @@ async function getDimensionValue(handle) {
|
|
|
4117
4141
|
if (!cad.connected) {
|
|
4118
4142
|
await cad.connect();
|
|
4119
4143
|
}
|
|
4120
|
-
if (!cad.connected)
|
|
4121
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4144
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4122
4145
|
const code = `(progn
|
|
4123
4146
|
(vl-load-com)
|
|
4124
4147
|
(if (setq ent (handent "${handle}"))
|
|
@@ -4149,8 +4172,7 @@ async function createHatch(patternName, boundary, scale = 1, angle = 0) {
|
|
|
4149
4172
|
if (!cad.connected) {
|
|
4150
4173
|
await cad.connect();
|
|
4151
4174
|
}
|
|
4152
|
-
if (!cad.connected)
|
|
4153
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4175
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4154
4176
|
const code = `(progn
|
|
4155
4177
|
(vl-load-com)
|
|
4156
4178
|
(command "._BHATCH" "p" "${patternName}" "s" "s" "sc" ${scale} "an" ${angle} "")
|
|
@@ -4170,17 +4192,12 @@ async function setHatchProperties(handle, props) {
|
|
|
4170
4192
|
if (!cad.connected) {
|
|
4171
4193
|
await cad.connect();
|
|
4172
4194
|
}
|
|
4173
|
-
if (!cad.connected)
|
|
4174
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4195
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4175
4196
|
let propCode = "";
|
|
4176
|
-
if (props.pattern)
|
|
4177
|
-
|
|
4178
|
-
if (props.
|
|
4179
|
-
|
|
4180
|
-
if (props.angle)
|
|
4181
|
-
propCode += `(command "._HATCHEDIT" "${handle}" "an" ${props.angle})`;
|
|
4182
|
-
if (props.color)
|
|
4183
|
-
propCode += `(command "._HATCHEDIT" "${handle}" "c" ${props.color})`;
|
|
4197
|
+
if (props.pattern) propCode += `(command "._HATCHEDIT" "${handle}" "p" "${props.pattern}")`;
|
|
4198
|
+
if (props.scale) propCode += `(command "._HATCHEDIT" "${handle}" "s" ${props.scale})`;
|
|
4199
|
+
if (props.angle) propCode += `(command "._HATCHEDIT" "${handle}" "an" ${props.angle})`;
|
|
4200
|
+
if (props.color) propCode += `(command "._HATCHEDIT" "${handle}" "c" ${props.color})`;
|
|
4184
4201
|
const code = `(progn
|
|
4185
4202
|
(vl-load-com)
|
|
4186
4203
|
${propCode}
|
|
@@ -4197,8 +4214,7 @@ async function getBlockAttributes(blockHandle) {
|
|
|
4197
4214
|
if (!cad.connected) {
|
|
4198
4215
|
await cad.connect();
|
|
4199
4216
|
}
|
|
4200
|
-
if (!cad.connected)
|
|
4201
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4217
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4202
4218
|
const code = `(progn
|
|
4203
4219
|
(vl-load-com)
|
|
4204
4220
|
(if (setq ent (handent "${blockHandle}"))
|
|
@@ -4227,8 +4243,7 @@ async function setBlockAttribute(blockHandle, tag, value) {
|
|
|
4227
4243
|
if (!cad.connected) {
|
|
4228
4244
|
await cad.connect();
|
|
4229
4245
|
}
|
|
4230
|
-
if (!cad.connected)
|
|
4231
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4246
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4232
4247
|
const code = `(progn
|
|
4233
4248
|
(vl-load-com)
|
|
4234
4249
|
(if (setq ent (handent "${blockHandle}"))
|
|
@@ -4264,8 +4279,7 @@ async function zoomToExtents() {
|
|
|
4264
4279
|
if (!cad.connected) {
|
|
4265
4280
|
await cad.connect();
|
|
4266
4281
|
}
|
|
4267
|
-
if (!cad.connected)
|
|
4268
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4282
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4269
4283
|
const code = `(progn
|
|
4270
4284
|
(vl-load-com)
|
|
4271
4285
|
(command "._ZOOM" "E")
|
|
@@ -4282,8 +4296,7 @@ async function zoomToWindow(p1, p2) {
|
|
|
4282
4296
|
if (!cad.connected) {
|
|
4283
4297
|
await cad.connect();
|
|
4284
4298
|
}
|
|
4285
|
-
if (!cad.connected)
|
|
4286
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4299
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4287
4300
|
const code = `(command "._ZOOM" "W" (list ${p1}) (list ${p2}))`;
|
|
4288
4301
|
try {
|
|
4289
4302
|
await cad.sendCommand(code + "\n");
|
|
@@ -4296,8 +4309,7 @@ async function createNamedView(viewName, center = null) {
|
|
|
4296
4309
|
if (!cad.connected) {
|
|
4297
4310
|
await cad.connect();
|
|
4298
4311
|
}
|
|
4299
|
-
if (!cad.connected)
|
|
4300
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4312
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4301
4313
|
const code = center ? `(command ".-VIEW" "S" "${viewName}" "C" (list ${center}))` : `(command ".-VIEW" "S" "${viewName}")`;
|
|
4302
4314
|
try {
|
|
4303
4315
|
await cad.sendCommand(code + "\n");
|
|
@@ -4310,8 +4322,7 @@ async function restoreNamedView(viewName) {
|
|
|
4310
4322
|
if (!cad.connected) {
|
|
4311
4323
|
await cad.connect();
|
|
4312
4324
|
}
|
|
4313
|
-
if (!cad.connected)
|
|
4314
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4325
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4315
4326
|
const code = `(command ".-VIEW" "R" "${viewName}")`;
|
|
4316
4327
|
try {
|
|
4317
4328
|
await cad.sendCommand(code + "\n");
|
|
@@ -4324,8 +4335,7 @@ async function listNamedViews() {
|
|
|
4324
4335
|
if (!cad.connected) {
|
|
4325
4336
|
await cad.connect();
|
|
4326
4337
|
}
|
|
4327
|
-
if (!cad.connected)
|
|
4328
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4338
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4329
4339
|
const code = `(progn
|
|
4330
4340
|
(vl-load-com)
|
|
4331
4341
|
(setq views nil)
|
|
@@ -4345,8 +4355,7 @@ async function exportDxf(outputPath, version2 = "R2018") {
|
|
|
4345
4355
|
if (!cad.connected) {
|
|
4346
4356
|
await cad.connect();
|
|
4347
4357
|
}
|
|
4348
|
-
if (!cad.connected)
|
|
4349
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4358
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4350
4359
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4351
4360
|
const versionMap = {
|
|
4352
4361
|
"R2018": "AC1027",
|
|
@@ -4377,8 +4386,7 @@ async function exportDwf(outputPath) {
|
|
|
4377
4386
|
if (!cad.connected) {
|
|
4378
4387
|
await cad.connect();
|
|
4379
4388
|
}
|
|
4380
|
-
if (!cad.connected)
|
|
4381
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4389
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4382
4390
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4383
4391
|
const code = `(progn
|
|
4384
4392
|
(vl-load-com)
|
|
@@ -4399,8 +4407,7 @@ async function batchSetLayer(handles, layerName) {
|
|
|
4399
4407
|
if (!cad.connected) {
|
|
4400
4408
|
await cad.connect();
|
|
4401
4409
|
}
|
|
4402
|
-
if (!cad.connected)
|
|
4403
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4410
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4404
4411
|
if (!Array.isArray(handles) || handles.length === 0) {
|
|
4405
4412
|
return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
|
|
4406
4413
|
}
|
|
@@ -4425,8 +4432,7 @@ async function createUcs(name, origin = "0,0,0", xAxis = "1,0,0", yAxis = "0,1,0
|
|
|
4425
4432
|
if (!cad.connected) {
|
|
4426
4433
|
await cad.connect();
|
|
4427
4434
|
}
|
|
4428
|
-
if (!cad.connected)
|
|
4429
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4435
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4430
4436
|
const code = `(progn
|
|
4431
4437
|
(vl-load-com)
|
|
4432
4438
|
(if (not (tblsearch "UCS" "${name}"))
|
|
@@ -4457,8 +4463,7 @@ async function setUcs(name) {
|
|
|
4457
4463
|
if (!cad.connected) {
|
|
4458
4464
|
await cad.connect();
|
|
4459
4465
|
}
|
|
4460
|
-
if (!cad.connected)
|
|
4461
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4466
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4462
4467
|
const code = `(progn
|
|
4463
4468
|
(vl-load-com)
|
|
4464
4469
|
(if (tblsearch "UCS" "${name}")
|
|
@@ -4483,8 +4488,7 @@ async function listUcs() {
|
|
|
4483
4488
|
if (!cad.connected) {
|
|
4484
4489
|
await cad.connect();
|
|
4485
4490
|
}
|
|
4486
|
-
if (!cad.connected)
|
|
4487
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4491
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4488
4492
|
const code = `(progn
|
|
4489
4493
|
(vl-load-com)
|
|
4490
4494
|
(setq ucsList nil)
|
|
@@ -4507,8 +4511,7 @@ async function deleteUcs(name) {
|
|
|
4507
4511
|
if (!cad.connected) {
|
|
4508
4512
|
await cad.connect();
|
|
4509
4513
|
}
|
|
4510
|
-
if (!cad.connected)
|
|
4511
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4514
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4512
4515
|
const code = `(progn
|
|
4513
4516
|
(vl-load-com)
|
|
4514
4517
|
(if (tblsearch "UCS" "${name}")
|
|
@@ -4533,8 +4536,7 @@ async function getCurrentUcs() {
|
|
|
4533
4536
|
if (!cad.connected) {
|
|
4534
4537
|
await cad.connect();
|
|
4535
4538
|
}
|
|
4536
|
-
if (!cad.connected)
|
|
4537
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4539
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4538
4540
|
const code = `(progn
|
|
4539
4541
|
(vl-load-com)
|
|
4540
4542
|
(vla-get-activeutilities (vla-get-document (vla-get-application (vlax-get-acad-object))))
|
|
@@ -4551,8 +4553,7 @@ async function createLayout(name) {
|
|
|
4551
4553
|
if (!cad.connected) {
|
|
4552
4554
|
await cad.connect();
|
|
4553
4555
|
}
|
|
4554
|
-
if (!cad.connected)
|
|
4555
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4556
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4556
4557
|
const code = `(progn
|
|
4557
4558
|
(vl-load-com)
|
|
4558
4559
|
(if (not (tblsearch "LAYOUT" "${name}"))
|
|
@@ -4580,8 +4581,7 @@ async function setLayout(name) {
|
|
|
4580
4581
|
if (!cad.connected) {
|
|
4581
4582
|
await cad.connect();
|
|
4582
4583
|
}
|
|
4583
|
-
if (!cad.connected)
|
|
4584
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4584
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4585
4585
|
const code = `(progn
|
|
4586
4586
|
(vl-load-com)
|
|
4587
4587
|
(vlax-for layout (vla-get-layouts (vla-get-activedocument (vla-get-application (vlax-get-acad-object))))
|
|
@@ -4611,8 +4611,7 @@ async function listLayouts() {
|
|
|
4611
4611
|
if (!cad.connected) {
|
|
4612
4612
|
await cad.connect();
|
|
4613
4613
|
}
|
|
4614
|
-
if (!cad.connected)
|
|
4615
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4614
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4616
4615
|
const code = `(progn
|
|
4617
4616
|
(vl-load-com)
|
|
4618
4617
|
(setq layouts nil)
|
|
@@ -4635,8 +4634,7 @@ async function deleteLayout(name) {
|
|
|
4635
4634
|
if (!cad.connected) {
|
|
4636
4635
|
await cad.connect();
|
|
4637
4636
|
}
|
|
4638
|
-
if (!cad.connected)
|
|
4639
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4637
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4640
4638
|
if (name === "Model" || name === "\u6A21\u578B") {
|
|
4641
4639
|
return { content: [{ type: "text", text: "\u65E0\u6CD5\u5220\u9664\u6A21\u578B\u7A7A\u95F4" }], isError: true };
|
|
4642
4640
|
}
|
|
@@ -4664,8 +4662,7 @@ async function getCurrentLayout() {
|
|
|
4664
4662
|
if (!cad.connected) {
|
|
4665
4663
|
await cad.connect();
|
|
4666
4664
|
}
|
|
4667
|
-
if (!cad.connected)
|
|
4668
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4665
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4669
4666
|
const code = `(vl-prin1-to-string (getvar "CTAB"))`;
|
|
4670
4667
|
try {
|
|
4671
4668
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -4678,8 +4675,7 @@ async function renameLayout(oldName, newName) {
|
|
|
4678
4675
|
if (!cad.connected) {
|
|
4679
4676
|
await cad.connect();
|
|
4680
4677
|
}
|
|
4681
|
-
if (!cad.connected)
|
|
4682
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4678
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4683
4679
|
const code = `(progn
|
|
4684
4680
|
(vl-load-com)
|
|
4685
4681
|
(if (tblsearch "LAYOUT" "${oldName}")
|
|
@@ -4706,8 +4702,7 @@ async function plotToPdf(outputPath, layout = "Model", style = {}) {
|
|
|
4706
4702
|
if (!cad.connected) {
|
|
4707
4703
|
await cad.connect();
|
|
4708
4704
|
}
|
|
4709
|
-
if (!cad.connected)
|
|
4710
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4705
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4711
4706
|
const normalizedPath = outputPath.replace(/\\/g, "\\\\");
|
|
4712
4707
|
const paperSize = style.paperSize || "A4";
|
|
4713
4708
|
const plotScale = style.plotScale || "1:1";
|
|
@@ -4740,8 +4735,7 @@ async function plotToPrinter(printerName, layout = "Model") {
|
|
|
4740
4735
|
if (!cad.connected) {
|
|
4741
4736
|
await cad.connect();
|
|
4742
4737
|
}
|
|
4743
|
-
if (!cad.connected)
|
|
4744
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4738
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4745
4739
|
const code = `(progn
|
|
4746
4740
|
(vl-load-com)
|
|
4747
4741
|
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
|
|
@@ -4767,8 +4761,7 @@ async function createGroup(name, handles) {
|
|
|
4767
4761
|
if (!cad.connected) {
|
|
4768
4762
|
await cad.connect();
|
|
4769
4763
|
}
|
|
4770
|
-
if (!cad.connected)
|
|
4771
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4764
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4772
4765
|
if (!Array.isArray(handles) || handles.length === 0) {
|
|
4773
4766
|
return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
|
|
4774
4767
|
}
|
|
@@ -4794,8 +4787,7 @@ async function deleteGroup(name) {
|
|
|
4794
4787
|
if (!cad.connected) {
|
|
4795
4788
|
await cad.connect();
|
|
4796
4789
|
}
|
|
4797
|
-
if (!cad.connected)
|
|
4798
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4790
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4799
4791
|
const code = `(progn
|
|
4800
4792
|
(vl-load-com)
|
|
4801
4793
|
(if (tblsearch "GROUP" "${name}")
|
|
@@ -4820,8 +4812,7 @@ async function listGroups() {
|
|
|
4820
4812
|
if (!cad.connected) {
|
|
4821
4813
|
await cad.connect();
|
|
4822
4814
|
}
|
|
4823
|
-
if (!cad.connected)
|
|
4824
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4815
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4825
4816
|
const code = `(progn
|
|
4826
4817
|
(vl-load-com)
|
|
4827
4818
|
(setq groups nil)
|
|
@@ -4841,8 +4832,7 @@ async function getGroupEntities(groupName) {
|
|
|
4841
4832
|
if (!cad.connected) {
|
|
4842
4833
|
await cad.connect();
|
|
4843
4834
|
}
|
|
4844
|
-
if (!cad.connected)
|
|
4845
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4835
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4846
4836
|
const code = `(progn
|
|
4847
4837
|
(vl-load-com)
|
|
4848
4838
|
(if (tblsearch "GROUP" "${groupName}")
|
|
@@ -4880,8 +4870,7 @@ async function measureDistance(p1, p2) {
|
|
|
4880
4870
|
if (!cad.connected) {
|
|
4881
4871
|
await cad.connect();
|
|
4882
4872
|
}
|
|
4883
|
-
if (!cad.connected)
|
|
4884
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4873
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4885
4874
|
const code = `(progn
|
|
4886
4875
|
(vl-load-com)
|
|
4887
4876
|
(setq pt1 (list ${p1}) pt2 (list ${p2}))
|
|
@@ -4905,8 +4894,7 @@ async function measureArea(points) {
|
|
|
4905
4894
|
if (!cad.connected) {
|
|
4906
4895
|
await cad.connect();
|
|
4907
4896
|
}
|
|
4908
|
-
if (!cad.connected)
|
|
4909
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4897
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4910
4898
|
const pts = Array.isArray(points) ? points : points.split(/[\s,]+/).filter(Boolean);
|
|
4911
4899
|
if (pts.length < 3) {
|
|
4912
4900
|
return { content: [{ type: "text", text: "\u81F3\u5C11\u9700\u8981 3 \u4E2A\u70B9" }], isError: true };
|
|
@@ -4943,8 +4931,7 @@ async function getEntityInfo(handle) {
|
|
|
4943
4931
|
if (!cad.connected) {
|
|
4944
4932
|
await cad.connect();
|
|
4945
4933
|
}
|
|
4946
|
-
if (!cad.connected)
|
|
4947
|
-
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4934
|
+
if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4948
4935
|
const code = `(progn
|
|
4949
4936
|
(vl-load-com)
|
|
4950
4937
|
(if (setq ent (handent "${handle}"))
|
|
@@ -4979,8 +4966,7 @@ async function ensureConnected() {
|
|
|
4979
4966
|
if (!cad.connected) {
|
|
4980
4967
|
await cad.connect();
|
|
4981
4968
|
}
|
|
4982
|
-
if (!cad.connected)
|
|
4983
|
-
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
4969
|
+
if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
4984
4970
|
}
|
|
4985
4971
|
function parseHandleList(handles) {
|
|
4986
4972
|
if (typeof handles === "string") {
|
|
@@ -5221,8 +5207,7 @@ async function ensureConnected2() {
|
|
|
5221
5207
|
if (!cad.connected) {
|
|
5222
5208
|
await cad.connect();
|
|
5223
5209
|
}
|
|
5224
|
-
if (!cad.connected)
|
|
5225
|
-
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5210
|
+
if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5226
5211
|
}
|
|
5227
5212
|
async function getXdata(handle, appName = "ACAD") {
|
|
5228
5213
|
await ensureConnected2();
|
|
@@ -5428,11 +5413,10 @@ async function searchByXdata(appName, key, value) {
|
|
|
5428
5413
|
async function exportXdataToFile(handle, filePath) {
|
|
5429
5414
|
await ensureConnected2();
|
|
5430
5415
|
const xdata = await getAllEntityXdata(handle);
|
|
5431
|
-
if (!xdata.success)
|
|
5432
|
-
return xdata;
|
|
5416
|
+
if (!xdata.success) return xdata;
|
|
5433
5417
|
try {
|
|
5434
|
-
const
|
|
5435
|
-
|
|
5418
|
+
const fs8 = await import("fs");
|
|
5419
|
+
fs8.writeFileSync(filePath, JSON.stringify(xdata.xdata, null, 2));
|
|
5436
5420
|
return { handle, filePath, success: true };
|
|
5437
5421
|
} catch (e) {
|
|
5438
5422
|
return { error: e.message, success: false };
|
|
@@ -5441,8 +5425,8 @@ async function exportXdataToFile(handle, filePath) {
|
|
|
5441
5425
|
async function importXdataFromFile(handle, filePath, appName) {
|
|
5442
5426
|
await ensureConnected2();
|
|
5443
5427
|
try {
|
|
5444
|
-
const
|
|
5445
|
-
const data =
|
|
5428
|
+
const fs8 = await import("fs");
|
|
5429
|
+
const data = fs8.readFileSync(filePath, "utf8");
|
|
5446
5430
|
const xdata = JSON.parse(data);
|
|
5447
5431
|
if (appName && xdata[appName]) {
|
|
5448
5432
|
return await setXdata(handle, appName, xdata[appName]);
|
|
@@ -5462,8 +5446,7 @@ async function ensureConnected3() {
|
|
|
5462
5446
|
if (!cad.connected) {
|
|
5463
5447
|
await cad.connect();
|
|
5464
5448
|
}
|
|
5465
|
-
if (!cad.connected)
|
|
5466
|
-
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5449
|
+
if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5467
5450
|
}
|
|
5468
5451
|
async function createSheetSet(name, description = "") {
|
|
5469
5452
|
await ensureConnected3();
|
|
@@ -5664,14 +5647,11 @@ async function ensureConnected4() {
|
|
|
5664
5647
|
if (!cad.connected) {
|
|
5665
5648
|
await cad.connect();
|
|
5666
5649
|
}
|
|
5667
|
-
if (!cad.connected)
|
|
5668
|
-
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5650
|
+
if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5669
5651
|
}
|
|
5670
5652
|
function parsePoint(point) {
|
|
5671
|
-
if (Array.isArray(point))
|
|
5672
|
-
|
|
5673
|
-
if (typeof point === "string")
|
|
5674
|
-
return point;
|
|
5653
|
+
if (Array.isArray(point)) return point.join(" ");
|
|
5654
|
+
if (typeof point === "string") return point;
|
|
5675
5655
|
return "0,0,0";
|
|
5676
5656
|
}
|
|
5677
5657
|
async function createBox(center, length, width, height) {
|
|
@@ -5931,8 +5911,7 @@ async function ensureConnected5() {
|
|
|
5931
5911
|
if (!cad.connected) {
|
|
5932
5912
|
await cad.connect();
|
|
5933
5913
|
}
|
|
5934
|
-
if (!cad.connected)
|
|
5935
|
-
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5914
|
+
if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
5936
5915
|
}
|
|
5937
5916
|
async function createDimensionStyle(name, color = "bylayer", arrow = "ClosedFilled", textStyle = "") {
|
|
5938
5917
|
await ensureConnected5();
|
|
@@ -6158,8 +6137,7 @@ async function ensureConnected6() {
|
|
|
6158
6137
|
if (!cad.connected) {
|
|
6159
6138
|
await cad.connect();
|
|
6160
6139
|
}
|
|
6161
|
-
if (!cad.connected)
|
|
6162
|
-
throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
6140
|
+
if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
|
|
6163
6141
|
}
|
|
6164
6142
|
async function attachPdf(point, pdfPath, scale = 1, rotation = 0) {
|
|
6165
6143
|
await ensureConnected6();
|
|
@@ -6599,8 +6577,7 @@ function validateToolArgs(name, args) {
|
|
|
6599
6577
|
const baseType = type.replace("?", "");
|
|
6600
6578
|
const val = args[key];
|
|
6601
6579
|
if (val === void 0 || val === null) {
|
|
6602
|
-
if (isOptional)
|
|
6603
|
-
continue;
|
|
6580
|
+
if (isOptional) continue;
|
|
6604
6581
|
throw new Error(`Missing required argument: ${key}`);
|
|
6605
6582
|
}
|
|
6606
6583
|
const actualType = typeof args[key];
|
|
@@ -6645,8 +6622,7 @@ ${CAD_PLATFORMS.join("\n")}
|
|
|
6645
6622
|
},
|
|
6646
6623
|
import_funlib: async (a) => {
|
|
6647
6624
|
const data = await loadAtlibFunctionLib();
|
|
6648
|
-
if (!data)
|
|
6649
|
-
return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
|
|
6625
|
+
if (!data) return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
|
|
6650
6626
|
if (a.format === "list") {
|
|
6651
6627
|
const items = Object.values(data.all_functions || {}).map((f) => `${f.name}: ${f.description || ""}`);
|
|
6652
6628
|
return { content: [{ type: "text", text: items.join("\n") }] };
|
|
@@ -8400,25 +8376,27 @@ var tools = [
|
|
|
8400
8376
|
];
|
|
8401
8377
|
function notifyResourceChanges(toolName) {
|
|
8402
8378
|
const resourceMap = {
|
|
8403
|
-
connect_cad: ["atlisp://cad/info", "atlisp://dwg/
|
|
8404
|
-
new_document: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs", "atlisp://dwg/
|
|
8379
|
+
connect_cad: ["atlisp://cad/info", "atlisp://dwg/tbl", "atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs", "atlisp://packages"],
|
|
8380
|
+
new_document: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs", "atlisp://dwg/tbl", "atlisp://dwg/entities", "atlisp://dwg/text-content"],
|
|
8405
8381
|
install_package: ["atlisp://packages"],
|
|
8406
8382
|
install_atlisp: ["atlisp://packages", "atlisp://cad/info"],
|
|
8407
8383
|
init_atlisp: ["atlisp://packages", "atlisp://cad/info"],
|
|
8408
|
-
create_layer: ["atlisp://dwg/
|
|
8409
|
-
delete_layer: ["atlisp://dwg/
|
|
8410
|
-
set_layer: ["atlisp://dwg/
|
|
8411
|
-
set_current_layer: ["atlisp://dwg/
|
|
8412
|
-
create_block: ["atlisp://dwg/
|
|
8413
|
-
open_dwg: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs", "atlisp://dwg/
|
|
8384
|
+
create_layer: ["atlisp://dwg/tbl"],
|
|
8385
|
+
delete_layer: ["atlisp://dwg/tbl"],
|
|
8386
|
+
set_layer: ["atlisp://dwg/tbl"],
|
|
8387
|
+
set_current_layer: ["atlisp://dwg/tbl"],
|
|
8388
|
+
create_block: ["atlisp://dwg/block-refs", "atlisp://dwg/tbl"],
|
|
8389
|
+
open_dwg: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs", "atlisp://dwg/tbl", "atlisp://dwg/entities", "atlisp://dwg/block-refs", "atlisp://dwg/text-content"],
|
|
8414
8390
|
save_dwg: ["atlisp://dwg/name", "atlisp://dwg/path"],
|
|
8415
8391
|
export_pdf: [],
|
|
8416
|
-
close_dwg: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs"],
|
|
8417
|
-
|
|
8418
|
-
|
|
8392
|
+
close_dwg: ["atlisp://dwg/name", "atlisp://dwg/path", "atlisp://cad/dwgs", "atlisp://dwg/block-refs", "atlisp://dwg/text-content"],
|
|
8393
|
+
delete_entity: ["atlisp://dwg/entities", "atlisp://dwg/block-refs"],
|
|
8394
|
+
batch_delete: ["atlisp://dwg/entities", "atlisp://dwg/block-refs"],
|
|
8395
|
+
batch_explode: ["atlisp://dwg/entities", "atlisp://dwg/block-refs"],
|
|
8396
|
+
explode_block: ["atlisp://dwg/entities", "atlisp://dwg/block-refs"],
|
|
8419
8397
|
batch_set_color: ["atlisp://dwg/entities"],
|
|
8420
8398
|
batch_set_linetype: ["atlisp://dwg/entities"],
|
|
8421
|
-
batch_move: ["atlisp://dwg/entities", "atlisp://dwg/
|
|
8399
|
+
batch_move: ["atlisp://dwg/entities", "atlisp://dwg/tbl"],
|
|
8422
8400
|
batch_rename: ["atlisp://dwg/entities"],
|
|
8423
8401
|
batch_create_group: ["atlisp://dwg/groups"],
|
|
8424
8402
|
batch_add_to_group: ["atlisp://dwg/groups"],
|
|
@@ -8444,10 +8422,10 @@ function notifyResourceChanges(toolName) {
|
|
|
8444
8422
|
thicken_surface: ["atlisp://dwg/entities"],
|
|
8445
8423
|
create_region: ["atlisp://dwg/entities"],
|
|
8446
8424
|
create_loft_surface: ["atlisp://dwg/entities"],
|
|
8447
|
-
create_dimension_style: [],
|
|
8448
|
-
create_text_style: [],
|
|
8449
|
-
create_linetype: [],
|
|
8450
|
-
load_linetype: [],
|
|
8425
|
+
create_dimension_style: ["atlisp://dwg/tbl"],
|
|
8426
|
+
create_text_style: ["atlisp://dwg/tbl"],
|
|
8427
|
+
create_linetype: ["atlisp://dwg/tbl"],
|
|
8428
|
+
load_linetype: ["atlisp://dwg/tbl"],
|
|
8451
8429
|
attach_pdf: ["atlisp://dwg/entities"],
|
|
8452
8430
|
detach_pdf: ["atlisp://dwg/entities"],
|
|
8453
8431
|
import_dxf: ["atlisp://dwg/entities"],
|
|
@@ -8469,8 +8447,7 @@ function notifyResourceChanges(toolName) {
|
|
|
8469
8447
|
}
|
|
8470
8448
|
async function handleToolCall(name, args) {
|
|
8471
8449
|
const handler = TOOL_HANDLERS[name];
|
|
8472
|
-
if (!handler)
|
|
8473
|
-
return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
|
|
8450
|
+
if (!handler) return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
|
|
8474
8451
|
try {
|
|
8475
8452
|
validateToolArgs(name, args || {});
|
|
8476
8453
|
const result = await handler(args || {});
|
|
@@ -8530,12 +8507,10 @@ var RateLimiter = class {
|
|
|
8530
8507
|
this.keyLimits = /* @__PURE__ */ new Map();
|
|
8531
8508
|
}
|
|
8532
8509
|
getKeyLimit(apiKey2) {
|
|
8533
|
-
if (!apiKey2)
|
|
8534
|
-
return this.defaultLimit;
|
|
8510
|
+
if (!apiKey2) return this.defaultLimit;
|
|
8535
8511
|
if (config_default.apiKeys && config_default.apiKeys.length > 0) {
|
|
8536
8512
|
const found = config_default.apiKeys.find((k) => k.key === apiKey2);
|
|
8537
|
-
if (found)
|
|
8538
|
-
return found.limit;
|
|
8513
|
+
if (found) return found.limit;
|
|
8539
8514
|
}
|
|
8540
8515
|
if (config_default.apiKey && apiKey2 === config_default.apiKey) {
|
|
8541
8516
|
return config_default.apiKeyRateLimit || 1e3;
|
|
@@ -8543,12 +8518,10 @@ var RateLimiter = class {
|
|
|
8543
8518
|
return this.defaultLimit;
|
|
8544
8519
|
}
|
|
8545
8520
|
getKeyInfo(apiKey2) {
|
|
8546
|
-
if (!apiKey2)
|
|
8547
|
-
return { name: "anonymous", limit: this.defaultLimit };
|
|
8521
|
+
if (!apiKey2) return { name: "anonymous", limit: this.defaultLimit };
|
|
8548
8522
|
if (config_default.apiKeys && config_default.apiKeys.length > 0) {
|
|
8549
8523
|
const found = config_default.apiKeys.find((k) => k.key === apiKey2);
|
|
8550
|
-
if (found)
|
|
8551
|
-
return { name: found.name || apiKey2, limit: found.limit };
|
|
8524
|
+
if (found) return { name: found.name || apiKey2, limit: found.limit };
|
|
8552
8525
|
}
|
|
8553
8526
|
if (config_default.apiKey && apiKey2 === config_default.apiKey) {
|
|
8554
8527
|
return { name: "admin", limit: config_default.apiKeyRateLimit || 1e3 };
|
|
@@ -8644,8 +8617,7 @@ var JSON_CONTENT_TYPES = ["application/json", "application/json-rpc", "applicati
|
|
|
8644
8617
|
function createJsonBodyParser() {
|
|
8645
8618
|
return async (req, res, next) => {
|
|
8646
8619
|
const ct = (req.headers["content-type"] || "").toLowerCase();
|
|
8647
|
-
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
|
|
8648
|
-
return next();
|
|
8620
|
+
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t))) return next();
|
|
8649
8621
|
try {
|
|
8650
8622
|
const chunks = [];
|
|
8651
8623
|
for await (const chunk of req) {
|
|
@@ -8678,11 +8650,9 @@ function createAuthMiddleware() {
|
|
|
8678
8650
|
const PUBLIC_PATHS = ["/health"];
|
|
8679
8651
|
return (req, res, next) => {
|
|
8680
8652
|
if (apiKey) {
|
|
8681
|
-
if (PUBLIC_PATHS.includes(req.path))
|
|
8682
|
-
return next();
|
|
8653
|
+
if (PUBLIC_PATHS.includes(req.path)) return next();
|
|
8683
8654
|
const auth = req.get("Authorization");
|
|
8684
|
-
if (auth === `Bearer ${apiKey}`)
|
|
8685
|
-
return next();
|
|
8655
|
+
if (auth === `Bearer ${apiKey}`) return next();
|
|
8686
8656
|
return res.status(401).json({ error: "Unauthorized" });
|
|
8687
8657
|
}
|
|
8688
8658
|
next();
|
|
@@ -8690,16 +8660,14 @@ function createAuthMiddleware() {
|
|
|
8690
8660
|
}
|
|
8691
8661
|
function createCorsMiddleware() {
|
|
8692
8662
|
return (req, res, next) => {
|
|
8693
|
-
if (!enableCors)
|
|
8694
|
-
return next();
|
|
8663
|
+
if (!enableCors) return next();
|
|
8695
8664
|
res.setHeader("Access-Control-Allow-Origin", corsOrigin);
|
|
8696
8665
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, CONNECT");
|
|
8697
8666
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, mcp-session-id, last-event-id");
|
|
8698
8667
|
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id, content-type, x-accel-buffering");
|
|
8699
8668
|
res.setHeader("Access-Control-Max-Age", "86400");
|
|
8700
8669
|
res.setHeader("Vary", "Accept");
|
|
8701
|
-
if (req.method === "OPTIONS")
|
|
8702
|
-
return res.status(204).end();
|
|
8670
|
+
if (req.method === "OPTIONS") return res.status(204).end();
|
|
8703
8671
|
next();
|
|
8704
8672
|
};
|
|
8705
8673
|
}
|
|
@@ -9111,8 +9079,7 @@ For more info: https://atlisp.cn
|
|
|
9111
9079
|
}
|
|
9112
9080
|
}
|
|
9113
9081
|
}
|
|
9114
|
-
if (config_default.apiKey)
|
|
9115
|
-
log("API Key authentication enabled");
|
|
9082
|
+
if (config_default.apiKey) log("API Key authentication enabled");
|
|
9116
9083
|
async function initCadConnection() {
|
|
9117
9084
|
log("Attempting to connect to CAD on startup...");
|
|
9118
9085
|
try {
|