@atlisp/mcp 1.6.0 → 1.6.2

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