@atlisp/mcp 1.6.3 → 1.6.7

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,6 +2,7 @@
2
2
 
3
3
  // src/atlisp-mcp.js
4
4
  import path10 from "path";
5
+ import fs8 from "fs";
5
6
  import { fileURLToPath as fileURLToPath4 } from "url";
6
7
  import { createRequire } from "module";
7
8
  import express2 from "express";
@@ -22,7 +23,7 @@ var FILE_EXTENSIONS = {
22
23
  "BricsCAD": [".des"]
23
24
  };
24
25
  var SERVER_NAME = "atlisp-mcp-server";
25
- var SERVER_VERSION = "1.6.3";
26
+ var SERVER_VERSION = "1.6.7";
26
27
  var MOCK_PACKAGES = [
27
28
  { name: "base", description: "\u57FA\u7840\u51FD\u6570\u5E93", version: "1.0.0" },
28
29
  { name: "at-pm", description: "\u5DE5\u7A0B\u9879\u76EE\u7BA1\u7406", version: "2.1.0" },
@@ -115,7 +116,8 @@ function parseArgs() {
115
116
  return result;
116
117
  }
117
118
  function loadConfigFile(filePath) {
118
- if (!filePath || !fs.existsSync(filePath)) return null;
119
+ if (!filePath || !fs.existsSync(filePath))
120
+ return null;
119
121
  try {
120
122
  const raw = fs.readFileSync(filePath, "utf-8");
121
123
  const parsed = JSON.parse(raw);
@@ -253,7 +255,8 @@ function setupStdoutHandler(w) {
253
255
  const lines = buffer.split("\n");
254
256
  buffer = lines.pop() || "";
255
257
  for (const line of lines) {
256
- if (!line.trim()) continue;
258
+ if (!line.trim())
259
+ continue;
257
260
  try {
258
261
  const result = JSON.parse(line);
259
262
  const rid = result.requestId;
@@ -279,7 +282,8 @@ function setupStdoutHandler(w) {
279
282
  }
280
283
  function getWorker(force = false) {
281
284
  if (!worker || !worker.connected || force) {
282
- if (worker) worker.kill();
285
+ if (worker)
286
+ worker.kill();
283
287
  worker = spawn("node", [workerPath], {
284
288
  stdio: ["pipe", "pipe", "pipe"]
285
289
  });
@@ -287,7 +291,8 @@ function getWorker(force = false) {
287
291
  const w = worker;
288
292
  w.on("exit", (code) => {
289
293
  console.error("worker exited with code:", code);
290
- if (w !== worker) return;
294
+ if (w !== worker)
295
+ return;
291
296
  w.connected = false;
292
297
  for (const [id, { reject, timeout }] of pendingRequests) {
293
298
  clearTimeout(timeout);
@@ -308,7 +313,8 @@ function getWorker(force = false) {
308
313
  return worker;
309
314
  }
310
315
  function startHeartbeat() {
311
- if (heartbeatTimer) clearInterval(heartbeatTimer);
316
+ if (heartbeatTimer)
317
+ clearInterval(heartbeatTimer);
312
318
  heartbeatTimer = setInterval(async () => {
313
319
  try {
314
320
  const result = await sendMessage({ type: "ping" });
@@ -353,7 +359,8 @@ var CadConnection = class {
353
359
  return process.platform === "win32";
354
360
  }
355
361
  async connect(platform = null) {
356
- if (!this.isAvailable()) return false;
362
+ if (!this.isAvailable())
363
+ return false;
357
364
  try {
358
365
  const msg = platform ? { type: "connect", platform } : { type: "connect" };
359
366
  const result = await sendMessage(msg);
@@ -370,13 +377,16 @@ var CadConnection = class {
370
377
  return false;
371
378
  }
372
379
  async sendCommand(code) {
373
- if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
380
+ if (!this.connected)
381
+ throw new Error("\u672A\u8FDE\u63A5 CAD");
374
382
  const result = await sendMessage({ type: "send", code, platform: _platform });
375
- if (result.success) return true;
383
+ if (result.success)
384
+ return true;
376
385
  throw new Error(result.error || "\u53D1\u9001\u5931\u8D25");
377
386
  }
378
387
  async sendCommandWithResult(code, encoding = null) {
379
- if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
388
+ if (!this.connected)
389
+ throw new Error("\u672A\u8FDE\u63A5 CAD");
380
390
  const result = await sendMessage({ type: "sendResult", code, platform: _platform, encoding: encoding || "" });
381
391
  if (result.success) {
382
392
  return result.result || "";
@@ -390,7 +400,8 @@ var CadConnection = class {
390
400
  return this.product;
391
401
  }
392
402
  async isBusy() {
393
- if (!this.connected) return false;
403
+ if (!this.connected)
404
+ return false;
394
405
  try {
395
406
  const result = await sendMessage({ type: "isBusy", platform: _platform });
396
407
  return result && result.isBusy;
@@ -399,7 +410,8 @@ var CadConnection = class {
399
410
  }
400
411
  }
401
412
  async hasDoc() {
402
- if (!this.connected) return { hasDoc: false, docCount: 0 };
413
+ if (!this.connected)
414
+ return { hasDoc: false, docCount: 0 };
403
415
  try {
404
416
  const result = await sendMessage({ type: "hasdoc", platform: _platform });
405
417
  return result || { hasDoc: false, docCount: 0 };
@@ -408,7 +420,8 @@ var CadConnection = class {
408
420
  }
409
421
  }
410
422
  async newDoc() {
411
- if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
423
+ if (!this.connected)
424
+ throw new Error("\u672A\u8FDE\u63A5 CAD");
412
425
  try {
413
426
  const result = await sendMessage({ type: "newdoc", platform: _platform });
414
427
  return result && result.success;
@@ -417,7 +430,8 @@ var CadConnection = class {
417
430
  }
418
431
  }
419
432
  async bringToFront() {
420
- if (!this.connected) throw new Error("\u672A\u8FDE\u63A5 CAD");
433
+ if (!this.connected)
434
+ throw new Error("\u672A\u8FDE\u63A5 CAD");
421
435
  try {
422
436
  const result = await sendMessage({ type: "bringToFront", platform: _platform });
423
437
  return result && result.success;
@@ -426,7 +440,8 @@ var CadConnection = class {
426
440
  }
427
441
  }
428
442
  async getInfo() {
429
- if (!this.connected) return "CAD \u672A\u8FDE\u63A5";
443
+ if (!this.connected)
444
+ return "CAD \u672A\u8FDE\u63A5";
430
445
  return `Platform: ${this.product}, Version: ${this.version}, Status: Connected`;
431
446
  }
432
447
  async disconnect() {
@@ -463,9 +478,11 @@ var MAX_LOG_SIZE = 10 * 1024 * 1024;
463
478
  var MAX_LOG_FILES = 5;
464
479
  var stream = null;
465
480
  function rotateLog() {
466
- if (!fs2.existsSync(DEBUG_FILE)) return;
481
+ if (!fs2.existsSync(DEBUG_FILE))
482
+ return;
467
483
  const stat = fs2.statSync(DEBUG_FILE);
468
- if (stat.size < MAX_LOG_SIZE) return;
484
+ if (stat.size < MAX_LOG_SIZE)
485
+ return;
469
486
  if (stream) {
470
487
  stream.end();
471
488
  stream = null;
@@ -529,9 +546,11 @@ function ensureRequestLogDir() {
529
546
  }
530
547
  }
531
548
  function rotateRequestLog() {
532
- if (!fs2.existsSync(REQUEST_LOG_FILE)) return;
549
+ if (!fs2.existsSync(REQUEST_LOG_FILE))
550
+ return;
533
551
  const stat = fs2.statSync(REQUEST_LOG_FILE);
534
- if (stat.size < 10 * 1024 * 1024) return;
552
+ if (stat.size < 10 * 1024 * 1024)
553
+ return;
535
554
  const dir = path3.dirname(REQUEST_LOG_FILE);
536
555
  for (let i = 5; i > 0; i--) {
537
556
  const oldPath = `${REQUEST_LOG_FILE}.${i}`;
@@ -549,7 +568,8 @@ function rotateRequestLog() {
549
568
  }
550
569
  }
551
570
  function logRequest(req) {
552
- if (!config_default.requestLogEnabled) return;
571
+ if (!config_default.requestLogEnabled)
572
+ return;
553
573
  try {
554
574
  ensureRequestLogDir();
555
575
  rotateRequestLog();
@@ -566,7 +586,8 @@ function logRequest(req) {
566
586
  }
567
587
  }
568
588
  function logResponse(req, res, duration) {
569
- if (!config_default.requestLogEnabled) return;
589
+ if (!config_default.requestLogEnabled)
590
+ return;
570
591
  try {
571
592
  ensureRequestLogDir();
572
593
  const entry = {
@@ -589,6 +610,58 @@ var __dirname2 = path4.dirname(fileURLToPath2(import.meta.url));
589
610
  var STANDARDS_DIR = path4.join(__dirname2, "..", "standards");
590
611
  var CACHE_TTL = config_default.resourceCacheTtl;
591
612
  var resourceCache = /* @__PURE__ */ new Map();
613
+ var ENTITY_PROPERTIES_LISP = `
614
+ (defun entity:to-list (val)
615
+ (cond
616
+ ((= (type val) 'VARIANT) (entity:to-list (vlax-variant-value val)))
617
+ ((= (type val) 'SAFEARRAY) (vlax-safearray->list val))
618
+ (T val)))
619
+
620
+ (defun entity:try-get (obj names / result val)
621
+ (foreach name names
622
+ (if (not (vl-catch-all-error-p
623
+ (setq val (vl-catch-all-apply
624
+ (function vlax-get-property)
625
+ (list obj name)))))
626
+ (setq result (cons (cons name (entity:to-list val)) result))))
627
+ (reverse result))
628
+
629
+ (setq *common-props* '(ObjectName Handle Layer Color Linetype LinetypeScale Lineweight Visibility Material))
630
+
631
+ (setq *entity-props*
632
+ '((AcDbLine StartPoint EndPoint Angle Delta Length Thickness Normal)
633
+ (AcDbCircle Center Radius Diameter Circumference Area Thickness Normal)
634
+ (AcDbArc Center Radius StartAngle EndAngle TotalAngle ArcLength Area Normal)
635
+ (AcDbPoint Position Thickness Normal)
636
+ (AcDbText TextString Position Height Width ObliqueAngle Rotation StyleName HorizontalAlignment VerticalAlignment Normal Backward UpsideDown)
637
+ (AcDbMText TextString Location Height Width Rotation StyleName AttachmentPoint DrawingDirection LinespacingFactor LinespacingDistance LinespacingStyle FlowDirection)
638
+ (AcDbBlockReference Name InsertionPoint Rotation XScale YScale ZScale Normal)
639
+ (AcDbPolyline Coordinates Closed ConstantWidth Elevation Normal Thickness LinetypeGeneration Area Length)
640
+ (AcDb2dPolyline Coordinates Closed Elevation Normal Thickness LinetypeGeneration Area Length Type Width)
641
+ (AcDb3dPolyline Coordinates Closed Type Normal Length Area)
642
+ (AcDbAlignedDimension DimLinePoint1 DimLinePoint2 ExtLinePoint1 ExtLinePoint2 TextPosition TextRotation Measurement)
643
+ (AcDbRotatedDimension DimLinePoint1 DimLinePoint2 ExtLinePoint1 ExtLinePoint2 TextPosition TextRotation Measurement Rotation)
644
+ (AcDbRadialDimension Center Diameter LeaderLength TextPosition)
645
+ (AcDbDiametricDimension Center Diameter LeaderLength TextPosition)
646
+ (AcDbAngularDimension AngleVertex AngleEndPoint ArcPoint TextPosition Measurement)
647
+ (AcDbHatch PatternName PatternType Area Elevation Normal NumberOfLoops AssociativeHatch HatchObjectType PatternAngle PatternScale PatternSpace ISOPenWidth)
648
+ (AcDbSpline Degree NumberOfControlPoints NumberOfFitPoints ControlPoints FitPoints Knots Weights Area Length Closed Periodic StartTanVector EndTanVector Elevation Normal)
649
+ (AcDbEllipse Center MajorRadius MinorRadius RadiusRatio StartAngle EndAngle Area Circumference Normal)
650
+ (AcDbRegion Area Perimeter Centroid MomentsOfInertia PrincipalMoments PrincipalDirections Normal)
651
+ (AcDb3dSolid Volume Area Centroid MomentsOfInertia PrincipalMoments PrincipalDirections)
652
+ (AcDbRasterImage ImageFile ImageWidth ImageHeight Origin Rotation Width Height ShowImage ClippingEnabled)
653
+ (AcDbLeader Coordinates ArrowheadType ArrowheadSize Color ScaleFactor StyleName TextString TextPosition Type Normal)
654
+ (AcDbViewport Center Width Height ScaleFactor CustomScale StandardScale GridOn SnapOn On DisplayLocked)
655
+ (AcDbTable TableStyleName Position Rows Columns Direction FlowDirection)))
656
+
657
+ (defun entity:properties (ent / obj object-name result)
658
+ (setq obj (if (= (type ent) 'VLA-OBJECT) ent (vlax-ename->vla-object ent)))
659
+ (setq result (entity:try-get obj *common-props*))
660
+ (setq object-name (cdr (assoc 'ObjectName result)))
661
+ (if object-name
662
+ (setq result (append result (entity:try-get obj (cdr (assoc (read object-name) *entity-props*))))))
663
+ result)
664
+ `;
592
665
  function getCached(key) {
593
666
  const entry = resourceCache.get(key);
594
667
  if (entry && Date.now() - entry.timestamp < CACHE_TTL) {
@@ -612,11 +685,14 @@ function clearCache(uri) {
612
685
  }
613
686
  }
614
687
  function parseLispList(str) {
615
- if (!str || typeof str !== "string") return null;
688
+ if (!str || typeof str !== "string")
689
+ return null;
616
690
  const trimmed = str.trim();
617
- if (!trimmed.startsWith("(") || !trimmed.endsWith(")")) return null;
691
+ if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
692
+ return null;
618
693
  const content = trimmed.slice(1, -1).trim();
619
- if (!content) return [];
694
+ if (!content)
695
+ return [];
620
696
  const result = [];
621
697
  let depth = 0;
622
698
  let current = "";
@@ -658,32 +734,44 @@ function parseLispList(str) {
658
734
  }
659
735
  current += ch;
660
736
  }
661
- if (current.trim()) result.push(current.trim());
737
+ if (current.trim())
738
+ result.push(current.trim());
662
739
  return result.map((item) => {
663
740
  const t = item.trim();
664
- if (t === "nil") return null;
665
- if (t === "t") return true;
666
- if (t === "T") return true;
741
+ if (t === "nil")
742
+ return null;
743
+ if (t === "t")
744
+ return true;
745
+ if (t === "T")
746
+ return true;
667
747
  const num = Number(t);
668
- if (!isNaN(num) && t !== "") return num;
669
- if (t.startsWith('"') && t.endsWith('"')) return t.slice(1, -1);
748
+ if (!isNaN(num) && t !== "")
749
+ return num;
750
+ if (t.startsWith('"') && t.endsWith('"'))
751
+ return t.slice(1, -1);
670
752
  return t;
671
753
  });
672
754
  }
673
755
  function parseLispRecursive(str) {
674
- if (!str || typeof str !== "string") return null;
756
+ if (!str || typeof str !== "string")
757
+ return null;
675
758
  str = str.trim();
676
- if (!str) return null;
759
+ if (!str)
760
+ return null;
677
761
  let pos = 0;
678
762
  function skipWs() {
679
- while (pos < str.length && /\s/.test(str[pos])) pos++;
763
+ while (pos < str.length && /\s/.test(str[pos]))
764
+ pos++;
680
765
  }
681
766
  function parseValue() {
682
767
  skipWs();
683
- if (pos >= str.length) return null;
768
+ if (pos >= str.length)
769
+ return null;
684
770
  const ch = str[pos];
685
- if (ch === "(") return parseList();
686
- if (ch === '"') return parseString();
771
+ if (ch === "(")
772
+ return parseList();
773
+ if (ch === '"')
774
+ return parseString();
687
775
  if (ch === "'") {
688
776
  pos++;
689
777
  return parseValue();
@@ -696,11 +784,16 @@ function parseLispRecursive(str) {
696
784
  while (pos < str.length && str[pos] !== '"') {
697
785
  if (str[pos] === "\\" && pos + 1 < str.length) {
698
786
  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];
787
+ if (str[pos] === '"')
788
+ r += '"';
789
+ else if (str[pos] === "n")
790
+ r += "\n";
791
+ else if (str[pos] === "t")
792
+ r += " ";
793
+ else if (str[pos] === "\\")
794
+ r += "\\";
795
+ else
796
+ r += str[pos];
704
797
  } else {
705
798
  r += str[pos];
706
799
  }
@@ -711,12 +804,16 @@ function parseLispRecursive(str) {
711
804
  }
712
805
  function parseAtom() {
713
806
  const start = pos;
714
- while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(") pos++;
807
+ while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(")
808
+ pos++;
715
809
  const atom = str.slice(start, pos);
716
- if (atom === "nil" || atom === "NIL") return null;
717
- if (atom === "t" || atom === "T") return true;
810
+ if (atom === "nil" || atom === "NIL")
811
+ return null;
812
+ if (atom === "t" || atom === "T")
813
+ return true;
718
814
  const num = Number(atom);
719
- if (!isNaN(num) && atom !== "") return num;
815
+ if (!isNaN(num) && atom !== "")
816
+ return num;
720
817
  return atom;
721
818
  }
722
819
  function parseList() {
@@ -724,13 +821,15 @@ function parseLispRecursive(str) {
724
821
  const items = [];
725
822
  while (pos < str.length) {
726
823
  skipWs();
727
- if (pos >= str.length) break;
824
+ if (pos >= str.length)
825
+ break;
728
826
  if (str[pos] === ")") {
729
827
  pos++;
730
828
  return items;
731
829
  }
732
830
  const left = parseValue();
733
- if (left === void 0) break;
831
+ if (left === void 0)
832
+ break;
734
833
  skipWs();
735
834
  if (str[pos] === "." && (pos + 1 >= str.length || /\s/.test(str[pos + 1]) || str[pos + 1] === ")")) {
736
835
  pos++;
@@ -753,7 +852,8 @@ function parseLispRecursive(str) {
753
852
  return parseValue();
754
853
  }
755
854
  function lispPairsToObject(pairs) {
756
- if (!Array.isArray(pairs)) return pairs;
855
+ if (!Array.isArray(pairs))
856
+ return pairs;
757
857
  const obj = {};
758
858
  for (let i = 0; i < pairs.length - 1; i += 2) {
759
859
  const key = pairs[i];
@@ -765,7 +865,8 @@ function lispPairsToObject(pairs) {
765
865
  return obj;
766
866
  }
767
867
  function parseEntity(arr) {
768
- if (!Array.isArray(arr) || arr.length < 5) return null;
868
+ if (!Array.isArray(arr) || arr.length < 5)
869
+ return null;
769
870
  const [type, handle, layer, color, linetype, ...rest] = arr;
770
871
  const entity = {
771
872
  type: String(type).toUpperCase().replace(/^"|"$/g, ""),
@@ -790,10 +891,23 @@ function parseEntity(arr) {
790
891
  }
791
892
  return entity;
792
893
  }
793
- function buildEntityCode({ type, layer, bbox }) {
894
+ function propertyPairsToObject(pairs) {
895
+ if (!Array.isArray(pairs))
896
+ return null;
897
+ const obj = {};
898
+ for (const pair of pairs) {
899
+ if (Array.isArray(pair) && pair.length >= 2) {
900
+ obj[String(pair[0])] = pair[1] !== null && pair[1] !== void 0 ? pair[1] : null;
901
+ }
902
+ }
903
+ return obj;
904
+ }
905
+ function buildEntityPropertiesCode({ type, layer, bbox }) {
794
906
  const items = [];
795
- if (type) items.push(`(cons 0 "${type.replace(/"/g, '\\"')}")`);
796
- if (layer) items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
907
+ if (type)
908
+ items.push(`(cons 0 "${type.replace(/"/g, '\\"')}")`);
909
+ if (layer)
910
+ items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
797
911
  if (bbox) {
798
912
  const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
799
913
  if (parts.length === 4) {
@@ -810,32 +924,18 @@ function buildEntityCode({ type, layer, bbox }) {
810
924
  const ssgetExpr = items.length ? `(ssget "_X" ${filterExpr})` : '(ssget "_X")';
811
925
  return `(progn
812
926
  (vl-load-com)
813
- (defun @e:safe-fn (f ent / r)
814
- (setq r (vl-catch-all-apply f (list ent)))
815
- (if (vl-catch-all-error-p r) nil r))
816
- (defun @e:dp (ent / ed typ gcl is)
817
- (setq ed (entget ent) typ (cdr (assoc 0 ed)) gcl (assoc 62 ed) is (assoc 6 ed))
818
- (append
819
- (list typ (cdr (assoc 5 ed)) (cdr (assoc 8 ed))
820
- (if gcl (cdr gcl) 256)
821
- (if is (cdr is) "ByLayer"))
822
- (cond
823
- ((wcmatch typ "TEXT,MTEXT,ATTRIB,TCH_TEXT")
824
- (list (@e:safe-fn '(lambda (e) (text:remove-fmt (text:get-mtext e))) ent)))
825
- ((wcmatch typ "LINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,SPLINE,ELLIPSE,XLINE,RAY")
826
- (list (@e:safe-fn 'curve:get-points ent)))
827
- ((= typ "INSERT")
828
- (list (@e:safe-fn 'block:get-effectivename ent)))
829
- (t nil))))
927
+ ${ENTITY_PROPERTIES_LISP}
830
928
  (setq @e:total (if (setq @e:ss ${ssgetExpr}) (sslength @e:ss) 0)
831
929
  @e:ents nil @e:i 0)
832
- (while (and @e:ss (< @e:i @e:total)(< (length @e:ents) 3000))
833
- (setq @e:ents (cons (@e:dp (ssname @e:ss @e:i)) @e:ents) @e:i (1+ @e:i)))
930
+ (while (and @e:ss (< @e:i @e:total) (< (length @e:ents) 3000))
931
+ (setq @e:ents (cons (entity:properties (ssname @e:ss @e:i)) @e:ents)
932
+ @e:i (1+ @e:i)))
834
933
  (vl-prin1-to-string (list @e:total (reverse @e:ents))))`;
835
934
  }
836
935
  function buildTextCode({ layer, bbox, offset, limit }) {
837
936
  const items = [`'(0 . "TEXT,MTEXT,ATTRIB,TCH_TEXT")`];
838
- if (layer) items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
937
+ if (layer)
938
+ items.push(`(cons 8 "${layer.replace(/"/g, '\\"')}")`);
839
939
  if (bbox) {
840
940
  const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
841
941
  if (parts.length === 4) {
@@ -874,7 +974,7 @@ function buildTextCode({ layer, bbox, offset, limit }) {
874
974
  var RESOURCES = [
875
975
  { uri: "atlisp://cad/info", name: "CAD Info", description: "CAD \u8FDE\u63A5\u4FE1\u606F", mimeType: "application/json", subscribable: true },
876
976
  { uri: "atlisp://dwg/layers", name: "Layers", description: "\u56FE\u5C42\u5217\u8868", mimeType: "application/json", subscribable: true },
877
- { uri: "atlisp://dwg/entities", name: "Entities", description: "\u56FE\u5143\u5217\u8868\uFF0C\u8FD4\u56DE\u603B\u6570\u548C\u524D3000\u4E2A\u56FE\u5143\uFF0C\u6587\u672C\u9644\u52A0 text \u5B57\u6BB5\uFF0C\u66F2\u7EBF\u9644\u52A0 points \u6570\u7EC4\uFF0CINSERT \u9644\u52A0 blockName\uFF0C\u652F\u6301 ?type=LINE&layer=0&bbox=0,0,100,100 \u8FC7\u6EE4", mimeType: "application/json", subscribable: true },
977
+ { 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 },
878
978
  { uri: "atlisp://dwg/texts", name: "Texts", description: "\u6587\u672C\u5B9E\u4F53\u5185\u5BB9\u5217\u8868 (TEXT/MTEXT/ATTRIB/TCH_TEXT)\uFF0C\u652F\u6301 ?layer=0&bbox=0,0,100,100&limit=5000&offset=0", mimeType: "application/json", subscribable: true },
879
979
  { uri: "atlisp://dwg/name", name: "DWG Name", description: "\u5F53\u524D DWG \u6587\u4EF6\u540D", mimeType: "application/json", subscribable: true },
880
980
  { uri: "atlisp://dwg/path", name: "DWG Path", description: "\u6587\u4EF6\u5B8C\u6574\u8DEF\u5F84", mimeType: "application/json", subscribable: true },
@@ -886,20 +986,23 @@ var RESOURCES = [
886
986
  ];
887
987
  function parseQuery(uri) {
888
988
  const qIdx = uri.indexOf("?");
889
- if (qIdx === -1) return { base: uri, params: {} };
989
+ if (qIdx === -1)
990
+ return { base: uri, params: {} };
890
991
  const base = uri.substring(0, qIdx);
891
992
  const params = {};
892
993
  uri.substring(qIdx + 1).split("&").forEach((p) => {
893
994
  const eqIdx = p.indexOf("=");
894
995
  const k = eqIdx === -1 ? p : p.substring(0, eqIdx);
895
996
  const v = eqIdx === -1 ? "" : p.substring(eqIdx + 1);
896
- if (k) params[k] = decodeURIComponent(v);
997
+ if (k)
998
+ params[k] = decodeURIComponent(v);
897
999
  });
898
1000
  return { base, params };
899
1001
  }
900
1002
  function parseTemplateUri(uri) {
901
1003
  const match = uri.match(/^atlisp:\/\/dwg\/entity\/([^?]+)$/);
902
- if (match) return { type: "entity", handle: match[1] };
1004
+ if (match)
1005
+ return { type: "entity", handle: match[1] };
903
1006
  return null;
904
1007
  }
905
1008
  async function listResources(subscribedUris = []) {
@@ -945,8 +1048,10 @@ async function readResource(uri) {
945
1048
  }
946
1049
  }
947
1050
  async function getEntityByHandle(handle) {
948
- if (!cad.connected) await cad.connect();
949
- if (!cad.connected) return { error: "CAD \u672A\u8FDE\u63A5" };
1051
+ if (!cad.connected)
1052
+ await cad.connect();
1053
+ if (!cad.connected)
1054
+ return { error: "CAD \u672A\u8FDE\u63A5" };
950
1055
  const code = `(progn
951
1056
  (vl-load-com)
952
1057
  (if (setq ent (handent "${handle}"))
@@ -966,7 +1071,8 @@ async function getEntityByHandle(handle) {
966
1071
  )`;
967
1072
  try {
968
1073
  const result = await cad.sendCommandWithResult(code);
969
- if (!result || result === "nil") return { error: `\u672A\u627E\u5230\u5B9E\u4F53: ${handle}` };
1074
+ if (!result || result === "nil")
1075
+ return { error: `\u672A\u627E\u5230\u5B9E\u4F53: ${handle}` };
970
1076
  try {
971
1077
  return JSON.parse(result);
972
1078
  } catch {
@@ -978,7 +1084,8 @@ async function getEntityByHandle(handle) {
978
1084
  }
979
1085
  async function getCadInfo() {
980
1086
  const cached = getCached("cad:info");
981
- if (cached) return cached;
1087
+ if (cached)
1088
+ return cached;
982
1089
  if (!cad.connected) {
983
1090
  await cad.connect();
984
1091
  }
@@ -1005,9 +1112,12 @@ async function getCadInfo() {
1005
1112
  async function getLayers(filterName = null) {
1006
1113
  const cacheKey = filterName ? `dwg:layers:${filterName}` : "dwg:layers:all";
1007
1114
  const cached = getCached(cacheKey);
1008
- if (cached) return cached;
1009
- if (!cad.connected) await cad.connect();
1010
- if (!cad.connected) return [];
1115
+ if (cached)
1116
+ return cached;
1117
+ if (!cad.connected)
1118
+ await cad.connect();
1119
+ if (!cad.connected)
1120
+ return [];
1011
1121
  try {
1012
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))`;
1013
1123
  const result = await cad.sendCommandWithResult(code);
@@ -1054,8 +1164,10 @@ async function getLayers(filterName = null) {
1054
1164
  async function getEntities(params = {}) {
1055
1165
  const cacheKey = `dwg:entities:${JSON.stringify(params)}`;
1056
1166
  const cached = getCached(cacheKey);
1057
- if (cached) return cached;
1058
- if (!cad.connected) await cad.connect();
1167
+ if (cached)
1168
+ return cached;
1169
+ if (!cad.connected)
1170
+ await cad.connect();
1059
1171
  if (!cad.connected) {
1060
1172
  const result = { total: 0, entities: [] };
1061
1173
  setCache(cacheKey, result);
@@ -1066,7 +1178,7 @@ async function getEntities(params = {}) {
1066
1178
  return await getEntitiesSummary(cacheKey);
1067
1179
  }
1068
1180
  try {
1069
- const code = buildEntityCode({
1181
+ const code = buildEntityPropertiesCode({
1070
1182
  type: params.type || null,
1071
1183
  layer: params.layer || null,
1072
1184
  bbox: params.bbox || null
@@ -1083,7 +1195,7 @@ async function getEntities(params = {}) {
1083
1195
  if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
1084
1196
  total = typeof parsed[0] === "number" ? parsed[0] : 0;
1085
1197
  const rawEntities = Array.isArray(parsed[1]) ? parsed[1] : [];
1086
- entities = rawEntities.map(parseEntity).filter(Boolean);
1198
+ entities = rawEntities.map(propertyPairsToObject).filter(Boolean);
1087
1199
  }
1088
1200
  const result = { total, entities };
1089
1201
  log(`getEntities: total=${total}, returned=${entities.length}`);
@@ -1157,8 +1269,10 @@ async function getEntitiesSummary(cacheKey) {
1157
1269
  async function getTexts(params = {}) {
1158
1270
  const cacheKey = `dwg:texts:${JSON.stringify(params)}`;
1159
1271
  const cached = getCached(cacheKey);
1160
- if (cached) return cached;
1161
- if (!cad.connected) await cad.connect();
1272
+ if (cached)
1273
+ return cached;
1274
+ if (!cad.connected)
1275
+ await cad.connect();
1162
1276
  if (!cad.connected) {
1163
1277
  const result = { total: 0, texts: [] };
1164
1278
  setCache(cacheKey, result);
@@ -1196,8 +1310,10 @@ async function getTexts(params = {}) {
1196
1310
  }
1197
1311
  }
1198
1312
  async function getDwgName() {
1199
- if (!cad.connected) await cad.connect();
1200
- if (!cad.connected) return { name: null };
1313
+ if (!cad.connected)
1314
+ await cad.connect();
1315
+ if (!cad.connected)
1316
+ return { name: null };
1201
1317
  try {
1202
1318
  const code = `(vl-princ-to-string (getvar "dwgname"))`;
1203
1319
  const name = await cad.sendCommandWithResult(code);
@@ -1207,8 +1323,10 @@ async function getDwgName() {
1207
1323
  }
1208
1324
  }
1209
1325
  async function getDwgPath() {
1210
- if (!cad.connected) await cad.connect();
1211
- if (!cad.connected) return { path: null, name: null };
1326
+ if (!cad.connected)
1327
+ await cad.connect();
1328
+ if (!cad.connected)
1329
+ return { path: null, name: null };
1212
1330
  try {
1213
1331
  const code = `(progn
1214
1332
  (setq prefix (vl-princ-to-string (getvar "dwgprefix")))
@@ -1226,7 +1344,8 @@ async function getDwgPath() {
1226
1344
  }
1227
1345
  if (!parsed) {
1228
1346
  const listResult = parseLispList(result);
1229
- if (listResult && listResult.length >= 2) parsed = listResult;
1347
+ if (listResult && listResult.length >= 2)
1348
+ parsed = listResult;
1230
1349
  }
1231
1350
  if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
1232
1351
  return { path: String(parsed[0]), name: String(parsed[1]) };
@@ -1239,9 +1358,12 @@ async function getDwgPath() {
1239
1358
  async function getPackages(filterName = null) {
1240
1359
  const cacheKey = filterName ? `packages:${filterName}` : "packages:all";
1241
1360
  const cached = getCached(cacheKey);
1242
- if (cached) return cached;
1243
- if (!cad.connected) await cad.connect();
1244
- if (!cad.connected) return [];
1361
+ if (cached)
1362
+ return cached;
1363
+ if (!cad.connected)
1364
+ await cad.connect();
1365
+ if (!cad.connected)
1366
+ return [];
1245
1367
  try {
1246
1368
  const code = `(mapcar 'cdr @::*local-pkgs*)`;
1247
1369
  const result = await cad.sendCommandWithResult(code);
@@ -1255,7 +1377,8 @@ async function getPackages(filterName = null) {
1255
1377
  } catch {
1256
1378
  raw = parseLispList(result) || [];
1257
1379
  }
1258
- if (!Array.isArray(raw)) raw = [];
1380
+ if (!Array.isArray(raw))
1381
+ raw = [];
1259
1382
  const packages = raw.map((item) => {
1260
1383
  if (Array.isArray(item)) {
1261
1384
  const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
@@ -1264,13 +1387,20 @@ async function getPackages(filterName = null) {
1264
1387
  const [[key, val]] = Object.entries(entry);
1265
1388
  const k = String(key);
1266
1389
  const v = String(val);
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;
1390
+ if (k === ":NAME")
1391
+ pkg.name = v;
1392
+ else if (k === ":VERSION")
1393
+ pkg.version = v;
1394
+ else if (k === ":DESCRIPTION")
1395
+ pkg.description = v;
1396
+ else if (k === ":FULL-NAME")
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;
1274
1404
  }
1275
1405
  }
1276
1406
  return pkg;
@@ -1281,15 +1411,22 @@ async function getPackages(filterName = null) {
1281
1411
  if (item && typeof item === "object") {
1282
1412
  const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
1283
1413
  const nameVal = item.name || item.Name || item.NAME || item[":NAME"];
1284
- if (nameVal) pkg.name = String(nameVal);
1414
+ if (nameVal)
1415
+ pkg.name = String(nameVal);
1285
1416
  const verVal = item.version || item.Version || item.VERSION || item[":VERSION"];
1286
- if (verVal) pkg.version = String(verVal);
1417
+ if (verVal)
1418
+ pkg.version = String(verVal);
1287
1419
  const descVal = item.description || item.Description || item.DESCRIPTION || item[":DESCRIPTION"];
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);
1420
+ if (descVal)
1421
+ pkg.description = String(descVal);
1422
+ if (item.fullName || item.full_name)
1423
+ pkg.fullName = String(item.fullName || item.full_name);
1424
+ if (item.author || item.Author)
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);
1293
1430
  return pkg;
1294
1431
  }
1295
1432
  return null;
@@ -1315,9 +1452,12 @@ function getPlatforms() {
1315
1452
  async function getDwgList() {
1316
1453
  const cacheKey = "cad:dwgs";
1317
1454
  const cached = getCached(cacheKey);
1318
- if (cached) return cached;
1319
- if (!cad.connected) await cad.connect();
1320
- if (!cad.connected) return [];
1455
+ if (cached)
1456
+ return cached;
1457
+ if (!cad.connected)
1458
+ await cad.connect();
1459
+ if (!cad.connected)
1460
+ return [];
1321
1461
  try {
1322
1462
  const code = `(progn
1323
1463
  (vl-load-com)
@@ -1341,7 +1481,8 @@ async function getDwgList() {
1341
1481
  parsed = listResult;
1342
1482
  }
1343
1483
  }
1344
- if (!Array.isArray(parsed)) parsed = [];
1484
+ if (!Array.isArray(parsed))
1485
+ parsed = [];
1345
1486
  const dwgList = parsed.map((item) => {
1346
1487
  if (Array.isArray(item) && item.length >= 2) {
1347
1488
  return { name: String(item[0]), path: String(item[1]) };
@@ -1368,7 +1509,8 @@ function loadStandardsFile(filename) {
1368
1509
  var standardsCache = /* @__PURE__ */ new Map();
1369
1510
  function getCachedStandards(key) {
1370
1511
  const entry = standardsCache.get(key);
1371
- if (entry && Date.now() - entry.timestamp < 3e4) return entry.data;
1512
+ if (entry && Date.now() - entry.timestamp < 3e4)
1513
+ return entry.data;
1372
1514
  standardsCache.delete(key);
1373
1515
  return null;
1374
1516
  }
@@ -1377,16 +1519,20 @@ function setCachedStandards(key, data) {
1377
1519
  }
1378
1520
  function getDraftingStandards() {
1379
1521
  const cached = getCachedStandards("drafting");
1380
- if (cached) return cached;
1522
+ if (cached)
1523
+ return cached;
1381
1524
  const data = loadStandardsFile("drafting.json");
1382
- if (data) setCachedStandards("drafting", data);
1525
+ if (data)
1526
+ setCachedStandards("drafting", data);
1383
1527
  return data || { error: "\u5236\u56FE\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
1384
1528
  }
1385
1529
  function getCodingStandards() {
1386
1530
  const cached = getCachedStandards("coding");
1387
- if (cached) return cached;
1531
+ if (cached)
1532
+ return cached;
1388
1533
  const data = loadStandardsFile("coding.json");
1389
- if (data) setCachedStandards("coding", data);
1534
+ if (data)
1535
+ setCachedStandards("coding", data);
1390
1536
  return data || { error: "\u7F16\u7801\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
1391
1537
  }
1392
1538
 
@@ -1601,9 +1747,11 @@ var SseSession = class {
1601
1747
  return lines.join("\n") + "\n\n";
1602
1748
  }
1603
1749
  _setupDrain() {
1604
- if (typeof this.#res.on !== "function") return;
1750
+ if (typeof this.#res.on !== "function")
1751
+ return;
1605
1752
  this.#drainHandler = () => {
1606
- if (!this.#active) return;
1753
+ if (!this.#active)
1754
+ return;
1607
1755
  if (this.#backpressureBuffer.length > 0) {
1608
1756
  this._drainBuffer();
1609
1757
  }
@@ -1625,7 +1773,8 @@ var SseSession = class {
1625
1773
  }
1626
1774
  }
1627
1775
  _write(content) {
1628
- if (!this.#active) return false;
1776
+ if (!this.#active)
1777
+ return false;
1629
1778
  try {
1630
1779
  if (this.#backpressureBuffer.length > 0) {
1631
1780
  this.#backpressureBuffer.push(content);
@@ -1753,7 +1902,8 @@ function persistSessionData(clientId, sessionData) {
1753
1902
  function loadPersistedSessionData(clientId) {
1754
1903
  try {
1755
1904
  const filePath = getSessionStorePath(clientId);
1756
- if (!fs4.existsSync(filePath)) return null;
1905
+ if (!fs4.existsSync(filePath))
1906
+ return null;
1757
1907
  const raw = fs4.readFileSync(filePath, "utf-8");
1758
1908
  const store = JSON.parse(raw);
1759
1909
  if (Date.now() - store.savedAt > SESSION_STORE_TTL) {
@@ -1913,7 +2063,8 @@ var SessionTransport = class {
1913
2063
  this._started = true;
1914
2064
  }
1915
2065
  async send(message) {
1916
- if (this._closed) return;
2066
+ if (this._closed)
2067
+ return;
1917
2068
  if (this._pendingRequest) {
1918
2069
  const { resolve, reject, timeout } = this._pendingRequest;
1919
2070
  clearTimeout(timeout);
@@ -1922,7 +2073,8 @@ var SessionTransport = class {
1922
2073
  }
1923
2074
  }
1924
2075
  async close() {
1925
- if (this._closed) return;
2076
+ if (this._closed)
2077
+ return;
1926
2078
  this._closed = true;
1927
2079
  if (this._pendingRequest) {
1928
2080
  const { reject, timeout } = this._pendingRequest;
@@ -2234,10 +2386,14 @@ ${generateSuggestions(entities, layers)}`
2234
2386
  }
2235
2387
  function generateSuggestions(entities, layers) {
2236
2388
  const suggestions = [];
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");
2389
+ if (entities.total > 1e3)
2390
+ suggestions.push("- \u56FE\u7EB8\u5B9E\u4F53\u8F83\u591A\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u56FE\u5C42\u5206\u7C7B\u7BA1\u7406");
2391
+ if (layers.length > 20)
2392
+ suggestions.push("- \u56FE\u5C42\u8F83\u591A\uFF0C\u5EFA\u8BAE\u6E05\u7406\u672A\u4F7F\u7528\u7684\u56FE\u5C42");
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");
2241
2397
  return suggestions.length ? suggestions.join("\n") : "- \u56FE\u7EB8\u7ED3\u6784\u826F\u597D";
2242
2398
  }
2243
2399
  async function generateBatchLinesPrompt(args) {
@@ -2782,7 +2938,8 @@ var Metrics = class {
2782
2938
  bucket.sum += value;
2783
2939
  bucket.min = Math.min(bucket.min, value);
2784
2940
  bucket.max = Math.max(bucket.max, value);
2785
- if (!bucket.values) bucket.values = [];
2941
+ if (!bucket.values)
2942
+ bucket.values = [];
2786
2943
  bucket.values.push(value);
2787
2944
  this.histograms.set(key, bucket);
2788
2945
  }
@@ -2873,9 +3030,15 @@ var RESOURCE_TEMPLATES = [
2873
3030
  mimeType: "application/json"
2874
3031
  },
2875
3032
  {
2876
- uriTemplate: "atlisp://dwg/entities?type={type}",
2877
- name: "Entities by Type",
2878
- description: "\u6309\u7C7B\u578B\u67E5\u8BE2\u5B9E\u4F53\u5217\u8868",
3033
+ uriTemplate: "atlisp://dwg/entities",
3034
+ name: "Entities Summary",
3035
+ description: "\u8FD4\u56DE\u56FE\u5143\u603B\u6570\u548C\u6309\u7C7B\u578B\u7EDF\u8BA1\u5217\u8868",
3036
+ mimeType: "application/json"
3037
+ },
3038
+ {
3039
+ uriTemplate: "atlisp://dwg/entities?type={type}&layer={layer}&bbox={bbox}",
3040
+ name: "Filtered Entities",
3041
+ description: "\u6309 type/layer/bbox \u8FC7\u6EE4\u56FE\u5143\uFF0C\u8FD4\u56DE entity:properties \u5168\u5C5E\u6027 JSON\uFF08ObjectName, Handle, Layer, Color, Center, Radius \u7B49\uFF09",
2879
3042
  mimeType: "application/json"
2880
3043
  },
2881
3044
  {
@@ -3015,7 +3178,8 @@ async function evalLisp(code, withResult = false, encoding = null) {
3015
3178
  return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3016
3179
  }
3017
3180
  const trimmed = (code || "").trim();
3018
- if (!trimmed) return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
3181
+ if (!trimmed)
3182
+ return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
3019
3183
  try {
3020
3184
  if (withResult) {
3021
3185
  const result = await cad.sendCommandWithResult(trimmed, encoding);
@@ -3035,14 +3199,17 @@ async function getCadInfo2() {
3035
3199
  if (!cad.connected) {
3036
3200
  await cad.connect();
3037
3201
  }
3038
- if (!cad.connected) return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
3202
+ if (!cad.connected)
3203
+ return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
3039
3204
  const info = await cad.getInfo();
3040
3205
  return { content: [{ type: "text", text: info }] };
3041
3206
  }
3042
3207
  async function atCommand(command) {
3043
- if (!cad.connected) return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
3208
+ if (!cad.connected)
3209
+ return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
3044
3210
  const trimmed = (command || "").trim();
3045
- if (!trimmed) return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
3211
+ if (!trimmed)
3212
+ return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
3046
3213
  await cad.sendCommand(trimmed + "\n");
3047
3214
  return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001\u547D\u4EE4" }] };
3048
3215
  }
@@ -3050,7 +3217,8 @@ async function newDocument() {
3050
3217
  if (!cad.connected) {
3051
3218
  await cad.connect();
3052
3219
  }
3053
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3220
+ if (!cad.connected)
3221
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3054
3222
  const result = await cad.newDoc();
3055
3223
  if (result) {
3056
3224
  return { content: [{ type: "text", text: "\u5DF2\u5728 CAD \u4E2D\u65B0\u5EFA\u7A7A\u767D\u6587\u6863" }] };
@@ -3061,7 +3229,8 @@ async function bringToFront() {
3061
3229
  if (!cad.connected) {
3062
3230
  await cad.connect();
3063
3231
  }
3064
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3232
+ if (!cad.connected)
3233
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3065
3234
  const result = await cad.bringToFront();
3066
3235
  if (result) {
3067
3236
  return { content: [{ type: "text", text: "\u5DF2\u5C06 CAD \u7A97\u53E3\u5207\u6362\u5230\u524D\u53F0" }] };
@@ -3072,7 +3241,8 @@ async function installAtlisp() {
3072
3241
  if (!cad.connected) {
3073
3242
  await cad.connect();
3074
3243
  }
3075
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3244
+ if (!cad.connected)
3245
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3076
3246
  const installCode = `(progn(vl-load-com)(setq s strcat h "http" o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://atlisp.""cn/@"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get-property o'ResponseText))))`;
3077
3247
  await cad.sendCommand(installCode + "\n");
3078
3248
  return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u5B89\u88C5\u4EE3\u7801\u5230 CAD" }] };
@@ -3081,10 +3251,12 @@ async function listFunctionsInCad() {
3081
3251
  if (!cad.connected) {
3082
3252
  await cad.connect();
3083
3253
  }
3084
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3254
+ if (!cad.connected)
3255
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3085
3256
  try {
3086
3257
  const result = await cad.sendCommandWithResult("(atoms-family 0)", null);
3087
- if (result) return { content: [{ type: "text", text: result }] };
3258
+ if (result)
3259
+ return { content: [{ type: "text", text: result }] };
3088
3260
  return { content: [{ type: "text", text: "CAD \u51FD\u6570\u5217\u8868\u4E3A\u7A7A" }] };
3089
3261
  } catch (e) {
3090
3262
  return { content: [{ type: "text", text: `\u9519\u8BEF: ${e.message}` }], isError: true };
@@ -3139,7 +3311,8 @@ async function initAtlisp() {
3139
3311
  if (!cad.connected) {
3140
3312
  await cad.connect();
3141
3313
  }
3142
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3314
+ if (!cad.connected)
3315
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3143
3316
  const code = `(if (null @::load-module)
3144
3317
  (progn
3145
3318
  (vl-load-com)
@@ -3179,12 +3352,15 @@ async function fetchPackages() {
3179
3352
  return cachedPackages || MOCK_PACKAGES;
3180
3353
  }
3181
3354
  function flattenPackages(data) {
3182
- if (Array.isArray(data)) return data;
3183
- if (data && Array.isArray(data.packages)) return data.packages;
3355
+ if (Array.isArray(data))
3356
+ return data;
3357
+ if (data && Array.isArray(data.packages))
3358
+ return data.packages;
3184
3359
  return [];
3185
3360
  }
3186
3361
  async function listPackages() {
3187
- if (!cad.connected) await cad.connect();
3362
+ if (!cad.connected)
3363
+ await cad.connect();
3188
3364
  if (!cad.connected) {
3189
3365
  const data2 = await fetchPackages();
3190
3366
  const items2 = flattenPackages(data2);
@@ -3192,7 +3368,8 @@ async function listPackages() {
3192
3368
  return { content: [{ type: "text", text: text2 }] };
3193
3369
  }
3194
3370
  const result = await cad.sendCommandWithResult("(@::package-list-in-local)");
3195
- if (result && result !== "nil") return { content: [{ type: "text", text: result }] };
3371
+ if (result && result !== "nil")
3372
+ return { content: [{ type: "text", text: result }] };
3196
3373
  const data = await fetchPackages();
3197
3374
  const items = flattenPackages(data);
3198
3375
  const text = items.length ? `\u4ECE\u6CE8\u518C\u8868\u83B7\u53D6\u7684 @lisp \u5305:
@@ -3212,10 +3389,12 @@ async function searchPackages(query) {
3212
3389
  for (const p of items) {
3213
3390
  const name = (p.name || "").toLowerCase();
3214
3391
  const desc = (p.description || "").toLowerCase();
3215
- if (name.includes(q) || desc.includes(q)) results.push(p);
3392
+ if (name.includes(q) || desc.includes(q))
3393
+ results.push(p);
3216
3394
  }
3217
3395
  } else {
3218
- for (const p of items) results.push(p);
3396
+ for (const p of items)
3397
+ results.push(p);
3219
3398
  }
3220
3399
  if (results.length === 0) {
3221
3400
  return { content: [{ type: "text", text: `\u672A\u627E\u5230\u5305\u542B "${query}" \u7684\u5305` }] };
@@ -3267,7 +3446,8 @@ function writeCacheToDisk(data) {
3267
3446
  }
3268
3447
  async function fetchFunctions() {
3269
3448
  const diskCache = readCacheFromDisk();
3270
- if (diskCache) return diskCache;
3449
+ if (diskCache)
3450
+ return diskCache;
3271
3451
  try {
3272
3452
  const response = await fetch(FUNCTIONS_URL, { headers: { "User-Agent": "atlisp-mcp" } });
3273
3453
  if (response.ok) {
@@ -3287,7 +3467,8 @@ async function getFunctionUsage(funcName, packageName) {
3287
3467
  if (data) {
3288
3468
  const funcs = Object.values(data.all_functions || {});
3289
3469
  const func = funcs.find((f2) => f2.name === funcName || f2.name === `${packageName}:${funcName}`);
3290
- if (func) results.push(func);
3470
+ if (func)
3471
+ results.push(func);
3291
3472
  }
3292
3473
  if (results.length === 0 && FUNCTIONS_DIR) {
3293
3474
  try {
@@ -3296,7 +3477,8 @@ async function getFunctionUsage(funcName, packageName) {
3296
3477
  const raw = fs6.readFileSync(path8.join(FUNCTIONS_DIR, file), "utf-8");
3297
3478
  const data2 = JSON.parse(raw);
3298
3479
  const func = data2.functions?.find((f2) => f2.name === funcName);
3299
- if (func) results.push(func);
3480
+ if (func)
3481
+ results.push(func);
3300
3482
  }
3301
3483
  } catch {
3302
3484
  }
@@ -3364,7 +3546,8 @@ async function getEntity(handle) {
3364
3546
  if (!cad.connected) {
3365
3547
  await cad.connect();
3366
3548
  }
3367
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3549
+ if (!cad.connected)
3550
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3368
3551
  const code = `(progn
3369
3552
  (vl-load-com)
3370
3553
  (if (setq ent (handent "${handle}"))
@@ -3396,7 +3579,8 @@ async function setEntityProperty(handle, property, value) {
3396
3579
  if (!cad.connected) {
3397
3580
  await cad.connect();
3398
3581
  }
3399
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3582
+ if (!cad.connected)
3583
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3400
3584
  let propCode = "";
3401
3585
  switch (property) {
3402
3586
  case "layer":
@@ -3439,7 +3623,8 @@ async function deleteEntity(handle) {
3439
3623
  if (!cad.connected) {
3440
3624
  await cad.connect();
3441
3625
  }
3442
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3626
+ if (!cad.connected)
3627
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3443
3628
  const code = `(progn
3444
3629
  (vl-load-com)
3445
3630
  (if (setq ent (handent "${handle}"))
@@ -3464,12 +3649,15 @@ async function selectEntities(filter) {
3464
3649
  if (!cad.connected) {
3465
3650
  await cad.connect();
3466
3651
  }
3467
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3652
+ if (!cad.connected)
3653
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3468
3654
  let filterCode = "nil";
3469
3655
  if (filter && (filter.type || filter.layer)) {
3470
3656
  const items = [];
3471
- if (filter.type) items.push(`'(0 . "${filter.type}")`);
3472
- if (filter.layer) items.push(`'(8 . "${filter.layer}")`);
3657
+ if (filter.type)
3658
+ items.push(`'(0 . "${filter.type}")`);
3659
+ if (filter.layer)
3660
+ items.push(`'(8 . "${filter.layer}")`);
3473
3661
  filterCode = `(list ${items.join(" ")})`;
3474
3662
  }
3475
3663
  const code = `(progn
@@ -3501,7 +3689,8 @@ async function createLayer(name, color = 7, linetype = "Continuous") {
3501
3689
  if (!cad.connected) {
3502
3690
  await cad.connect();
3503
3691
  }
3504
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3692
+ if (!cad.connected)
3693
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3505
3694
  const code = `(progn
3506
3695
  (vl-load-com)
3507
3696
  (if (not (tblsearch "LAYER" "${name}"))
@@ -3537,7 +3726,8 @@ async function deleteLayer(name) {
3537
3726
  if (!cad.connected) {
3538
3727
  await cad.connect();
3539
3728
  }
3540
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3729
+ if (!cad.connected)
3730
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3541
3731
  const code = `(progn
3542
3732
  (vl-load-com)
3543
3733
  (cond
@@ -3571,7 +3761,8 @@ async function setLayerProperty(name, property, value) {
3571
3761
  if (!cad.connected) {
3572
3762
  await cad.connect();
3573
3763
  }
3574
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3764
+ if (!cad.connected)
3765
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3575
3766
  let propCode = "";
3576
3767
  switch (property) {
3577
3768
  case "color":
@@ -3619,7 +3810,8 @@ async function setCurrentLayer(name) {
3619
3810
  if (!cad.connected) {
3620
3811
  await cad.connect();
3621
3812
  }
3622
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3813
+ if (!cad.connected)
3814
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3623
3815
  const code = `(progn
3624
3816
  (vl-load-com)
3625
3817
  (if (tblsearch "LAYER" "${name}")
@@ -3646,7 +3838,8 @@ async function createBlock(name, entities) {
3646
3838
  if (!cad.connected) {
3647
3839
  await cad.connect();
3648
3840
  }
3649
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3841
+ if (!cad.connected)
3842
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3650
3843
  const code = `(progn
3651
3844
  (vl-load-com)
3652
3845
  (if (not (tblsearch "BLOCK" "${name}"))
@@ -3683,7 +3876,8 @@ async function insertBlock(blockName, point, scale = 1, rotation = 0) {
3683
3876
  if (!cad.connected) {
3684
3877
  await cad.connect();
3685
3878
  }
3686
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3879
+ if (!cad.connected)
3880
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3687
3881
  const coords = Array.isArray(point) ? point : point.split(",").map((s) => parseFloat(s.trim()));
3688
3882
  if (coords.length < 2) {
3689
3883
  return { content: [{ type: "text", text: "\u63D2\u5165\u70B9\u683C\u5F0F\u9519\u8BEF\uFF0C\u9700\u8981 x,y \u6216 [x,y,z]" }], isError: true };
@@ -3713,7 +3907,8 @@ async function getBlocks() {
3713
3907
  if (!cad.connected) {
3714
3908
  await cad.connect();
3715
3909
  }
3716
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3910
+ if (!cad.connected)
3911
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3717
3912
  const code = `(progn
3718
3913
  (vl-load-com)
3719
3914
  (setq blocks nil)
@@ -3736,7 +3931,8 @@ async function explodeBlock(handle) {
3736
3931
  if (!cad.connected) {
3737
3932
  await cad.connect();
3738
3933
  }
3739
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3934
+ if (!cad.connected)
3935
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3740
3936
  const code = `(progn
3741
3937
  (vl-load-com)
3742
3938
  (if (setq ent (handent "${handle}"))
@@ -3763,7 +3959,8 @@ async function openDwg(filePath) {
3763
3959
  if (!cad.connected) {
3764
3960
  await cad.connect();
3765
3961
  }
3766
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3962
+ if (!cad.connected)
3963
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3767
3964
  const normalizedPath = filePath.replace(/\\/g, "\\\\");
3768
3965
  const code = `(progn
3769
3966
  (vl-load-com)
@@ -3800,7 +3997,8 @@ async function saveDwg(filePath = null) {
3800
3997
  if (!cad.connected) {
3801
3998
  await cad.connect();
3802
3999
  }
3803
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4000
+ if (!cad.connected)
4001
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3804
4002
  const code = filePath ? `(progn
3805
4003
  (vl-load-com)
3806
4004
  (command "._SAVEAS" "${filePath.replace(/\\/g, "\\\\")}")
@@ -3824,7 +4022,8 @@ async function exportPdf(outputPath, layout = "Model") {
3824
4022
  if (!cad.connected) {
3825
4023
  await cad.connect();
3826
4024
  }
3827
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4025
+ if (!cad.connected)
4026
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3828
4027
  const normalizedPath = outputPath.replace(/\\/g, "\\\\");
3829
4028
  const code = `(progn
3830
4029
  (vl-load-com)
@@ -3852,7 +4051,8 @@ async function closeDwg(save = false) {
3852
4051
  if (!cad.connected) {
3853
4052
  await cad.connect();
3854
4053
  }
3855
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4054
+ if (!cad.connected)
4055
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3856
4056
  const code = `(progn
3857
4057
  (vl-load-com)
3858
4058
  (if ${save ? "T" : "nil"}
@@ -3874,7 +4074,8 @@ async function createDimension(type, points, style = {}) {
3874
4074
  if (!cad.connected) {
3875
4075
  await cad.connect();
3876
4076
  }
3877
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4077
+ if (!cad.connected)
4078
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3878
4079
  let dimCode = "";
3879
4080
  const validTypes = ["ALIGNED", "LINEAR", "ORDINATE", "RADIAL", "DIAMETER", "ANGULAR"];
3880
4081
  const dimType = (type || "ALIGNED").toUpperCase();
@@ -3916,7 +4117,8 @@ async function getDimensionValue(handle) {
3916
4117
  if (!cad.connected) {
3917
4118
  await cad.connect();
3918
4119
  }
3919
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4120
+ if (!cad.connected)
4121
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3920
4122
  const code = `(progn
3921
4123
  (vl-load-com)
3922
4124
  (if (setq ent (handent "${handle}"))
@@ -3947,7 +4149,8 @@ async function createHatch(patternName, boundary, scale = 1, angle = 0) {
3947
4149
  if (!cad.connected) {
3948
4150
  await cad.connect();
3949
4151
  }
3950
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4152
+ if (!cad.connected)
4153
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3951
4154
  const code = `(progn
3952
4155
  (vl-load-com)
3953
4156
  (command "._BHATCH" "p" "${patternName}" "s" "s" "sc" ${scale} "an" ${angle} "")
@@ -3967,12 +4170,17 @@ async function setHatchProperties(handle, props) {
3967
4170
  if (!cad.connected) {
3968
4171
  await cad.connect();
3969
4172
  }
3970
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4173
+ if (!cad.connected)
4174
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3971
4175
  let propCode = "";
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})`;
4176
+ if (props.pattern)
4177
+ propCode += `(command "._HATCHEDIT" "${handle}" "p" "${props.pattern}")`;
4178
+ if (props.scale)
4179
+ propCode += `(command "._HATCHEDIT" "${handle}" "s" ${props.scale})`;
4180
+ if (props.angle)
4181
+ propCode += `(command "._HATCHEDIT" "${handle}" "an" ${props.angle})`;
4182
+ if (props.color)
4183
+ propCode += `(command "._HATCHEDIT" "${handle}" "c" ${props.color})`;
3976
4184
  const code = `(progn
3977
4185
  (vl-load-com)
3978
4186
  ${propCode}
@@ -3989,7 +4197,8 @@ async function getBlockAttributes(blockHandle) {
3989
4197
  if (!cad.connected) {
3990
4198
  await cad.connect();
3991
4199
  }
3992
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4200
+ if (!cad.connected)
4201
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
3993
4202
  const code = `(progn
3994
4203
  (vl-load-com)
3995
4204
  (if (setq ent (handent "${blockHandle}"))
@@ -4018,7 +4227,8 @@ async function setBlockAttribute(blockHandle, tag, value) {
4018
4227
  if (!cad.connected) {
4019
4228
  await cad.connect();
4020
4229
  }
4021
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4230
+ if (!cad.connected)
4231
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4022
4232
  const code = `(progn
4023
4233
  (vl-load-com)
4024
4234
  (if (setq ent (handent "${blockHandle}"))
@@ -4054,7 +4264,8 @@ async function zoomToExtents() {
4054
4264
  if (!cad.connected) {
4055
4265
  await cad.connect();
4056
4266
  }
4057
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4267
+ if (!cad.connected)
4268
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4058
4269
  const code = `(progn
4059
4270
  (vl-load-com)
4060
4271
  (command "._ZOOM" "E")
@@ -4071,7 +4282,8 @@ async function zoomToWindow(p1, p2) {
4071
4282
  if (!cad.connected) {
4072
4283
  await cad.connect();
4073
4284
  }
4074
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4285
+ if (!cad.connected)
4286
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4075
4287
  const code = `(command "._ZOOM" "W" (list ${p1}) (list ${p2}))`;
4076
4288
  try {
4077
4289
  await cad.sendCommand(code + "\n");
@@ -4084,7 +4296,8 @@ async function createNamedView(viewName, center = null) {
4084
4296
  if (!cad.connected) {
4085
4297
  await cad.connect();
4086
4298
  }
4087
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4299
+ if (!cad.connected)
4300
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4088
4301
  const code = center ? `(command ".-VIEW" "S" "${viewName}" "C" (list ${center}))` : `(command ".-VIEW" "S" "${viewName}")`;
4089
4302
  try {
4090
4303
  await cad.sendCommand(code + "\n");
@@ -4097,7 +4310,8 @@ async function restoreNamedView(viewName) {
4097
4310
  if (!cad.connected) {
4098
4311
  await cad.connect();
4099
4312
  }
4100
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4313
+ if (!cad.connected)
4314
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4101
4315
  const code = `(command ".-VIEW" "R" "${viewName}")`;
4102
4316
  try {
4103
4317
  await cad.sendCommand(code + "\n");
@@ -4110,7 +4324,8 @@ async function listNamedViews() {
4110
4324
  if (!cad.connected) {
4111
4325
  await cad.connect();
4112
4326
  }
4113
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4327
+ if (!cad.connected)
4328
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4114
4329
  const code = `(progn
4115
4330
  (vl-load-com)
4116
4331
  (setq views nil)
@@ -4130,7 +4345,8 @@ async function exportDxf(outputPath, version2 = "R2018") {
4130
4345
  if (!cad.connected) {
4131
4346
  await cad.connect();
4132
4347
  }
4133
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4348
+ if (!cad.connected)
4349
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4134
4350
  const normalizedPath = outputPath.replace(/\\/g, "\\\\");
4135
4351
  const versionMap = {
4136
4352
  "R2018": "AC1027",
@@ -4161,7 +4377,8 @@ async function exportDwf(outputPath) {
4161
4377
  if (!cad.connected) {
4162
4378
  await cad.connect();
4163
4379
  }
4164
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4380
+ if (!cad.connected)
4381
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4165
4382
  const normalizedPath = outputPath.replace(/\\/g, "\\\\");
4166
4383
  const code = `(progn
4167
4384
  (vl-load-com)
@@ -4182,7 +4399,8 @@ async function batchSetLayer(handles, layerName) {
4182
4399
  if (!cad.connected) {
4183
4400
  await cad.connect();
4184
4401
  }
4185
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4402
+ if (!cad.connected)
4403
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4186
4404
  if (!Array.isArray(handles) || handles.length === 0) {
4187
4405
  return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
4188
4406
  }
@@ -4207,7 +4425,8 @@ async function createUcs(name, origin = "0,0,0", xAxis = "1,0,0", yAxis = "0,1,0
4207
4425
  if (!cad.connected) {
4208
4426
  await cad.connect();
4209
4427
  }
4210
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4428
+ if (!cad.connected)
4429
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4211
4430
  const code = `(progn
4212
4431
  (vl-load-com)
4213
4432
  (if (not (tblsearch "UCS" "${name}"))
@@ -4238,7 +4457,8 @@ async function setUcs(name) {
4238
4457
  if (!cad.connected) {
4239
4458
  await cad.connect();
4240
4459
  }
4241
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4460
+ if (!cad.connected)
4461
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4242
4462
  const code = `(progn
4243
4463
  (vl-load-com)
4244
4464
  (if (tblsearch "UCS" "${name}")
@@ -4263,7 +4483,8 @@ async function listUcs() {
4263
4483
  if (!cad.connected) {
4264
4484
  await cad.connect();
4265
4485
  }
4266
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4486
+ if (!cad.connected)
4487
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4267
4488
  const code = `(progn
4268
4489
  (vl-load-com)
4269
4490
  (setq ucsList nil)
@@ -4286,7 +4507,8 @@ async function deleteUcs(name) {
4286
4507
  if (!cad.connected) {
4287
4508
  await cad.connect();
4288
4509
  }
4289
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4510
+ if (!cad.connected)
4511
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4290
4512
  const code = `(progn
4291
4513
  (vl-load-com)
4292
4514
  (if (tblsearch "UCS" "${name}")
@@ -4311,7 +4533,8 @@ async function getCurrentUcs() {
4311
4533
  if (!cad.connected) {
4312
4534
  await cad.connect();
4313
4535
  }
4314
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4536
+ if (!cad.connected)
4537
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4315
4538
  const code = `(progn
4316
4539
  (vl-load-com)
4317
4540
  (vla-get-activeutilities (vla-get-document (vla-get-application (vlax-get-acad-object))))
@@ -4328,7 +4551,8 @@ async function createLayout(name) {
4328
4551
  if (!cad.connected) {
4329
4552
  await cad.connect();
4330
4553
  }
4331
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4554
+ if (!cad.connected)
4555
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4332
4556
  const code = `(progn
4333
4557
  (vl-load-com)
4334
4558
  (if (not (tblsearch "LAYOUT" "${name}"))
@@ -4356,7 +4580,8 @@ async function setLayout(name) {
4356
4580
  if (!cad.connected) {
4357
4581
  await cad.connect();
4358
4582
  }
4359
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4583
+ if (!cad.connected)
4584
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4360
4585
  const code = `(progn
4361
4586
  (vl-load-com)
4362
4587
  (vlax-for layout (vla-get-layouts (vla-get-activedocument (vla-get-application (vlax-get-acad-object))))
@@ -4386,7 +4611,8 @@ async function listLayouts() {
4386
4611
  if (!cad.connected) {
4387
4612
  await cad.connect();
4388
4613
  }
4389
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4614
+ if (!cad.connected)
4615
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4390
4616
  const code = `(progn
4391
4617
  (vl-load-com)
4392
4618
  (setq layouts nil)
@@ -4409,7 +4635,8 @@ async function deleteLayout(name) {
4409
4635
  if (!cad.connected) {
4410
4636
  await cad.connect();
4411
4637
  }
4412
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4638
+ if (!cad.connected)
4639
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4413
4640
  if (name === "Model" || name === "\u6A21\u578B") {
4414
4641
  return { content: [{ type: "text", text: "\u65E0\u6CD5\u5220\u9664\u6A21\u578B\u7A7A\u95F4" }], isError: true };
4415
4642
  }
@@ -4437,7 +4664,8 @@ async function getCurrentLayout() {
4437
4664
  if (!cad.connected) {
4438
4665
  await cad.connect();
4439
4666
  }
4440
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4667
+ if (!cad.connected)
4668
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4441
4669
  const code = `(vl-prin1-to-string (getvar "CTAB"))`;
4442
4670
  try {
4443
4671
  const result = await cad.sendCommandWithResult(code);
@@ -4450,7 +4678,8 @@ async function renameLayout(oldName, newName) {
4450
4678
  if (!cad.connected) {
4451
4679
  await cad.connect();
4452
4680
  }
4453
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4681
+ if (!cad.connected)
4682
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4454
4683
  const code = `(progn
4455
4684
  (vl-load-com)
4456
4685
  (if (tblsearch "LAYOUT" "${oldName}")
@@ -4477,7 +4706,8 @@ async function plotToPdf(outputPath, layout = "Model", style = {}) {
4477
4706
  if (!cad.connected) {
4478
4707
  await cad.connect();
4479
4708
  }
4480
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4709
+ if (!cad.connected)
4710
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4481
4711
  const normalizedPath = outputPath.replace(/\\/g, "\\\\");
4482
4712
  const paperSize = style.paperSize || "A4";
4483
4713
  const plotScale = style.plotScale || "1:1";
@@ -4510,7 +4740,8 @@ async function plotToPrinter(printerName, layout = "Model") {
4510
4740
  if (!cad.connected) {
4511
4741
  await cad.connect();
4512
4742
  }
4513
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4743
+ if (!cad.connected)
4744
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4514
4745
  const code = `(progn
4515
4746
  (vl-load-com)
4516
4747
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
@@ -4536,7 +4767,8 @@ async function createGroup(name, handles) {
4536
4767
  if (!cad.connected) {
4537
4768
  await cad.connect();
4538
4769
  }
4539
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4770
+ if (!cad.connected)
4771
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4540
4772
  if (!Array.isArray(handles) || handles.length === 0) {
4541
4773
  return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
4542
4774
  }
@@ -4562,7 +4794,8 @@ async function deleteGroup(name) {
4562
4794
  if (!cad.connected) {
4563
4795
  await cad.connect();
4564
4796
  }
4565
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4797
+ if (!cad.connected)
4798
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4566
4799
  const code = `(progn
4567
4800
  (vl-load-com)
4568
4801
  (if (tblsearch "GROUP" "${name}")
@@ -4587,7 +4820,8 @@ async function listGroups() {
4587
4820
  if (!cad.connected) {
4588
4821
  await cad.connect();
4589
4822
  }
4590
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4823
+ if (!cad.connected)
4824
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4591
4825
  const code = `(progn
4592
4826
  (vl-load-com)
4593
4827
  (setq groups nil)
@@ -4607,7 +4841,8 @@ async function getGroupEntities(groupName) {
4607
4841
  if (!cad.connected) {
4608
4842
  await cad.connect();
4609
4843
  }
4610
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4844
+ if (!cad.connected)
4845
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4611
4846
  const code = `(progn
4612
4847
  (vl-load-com)
4613
4848
  (if (tblsearch "GROUP" "${groupName}")
@@ -4645,7 +4880,8 @@ async function measureDistance(p1, p2) {
4645
4880
  if (!cad.connected) {
4646
4881
  await cad.connect();
4647
4882
  }
4648
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4883
+ if (!cad.connected)
4884
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4649
4885
  const code = `(progn
4650
4886
  (vl-load-com)
4651
4887
  (setq pt1 (list ${p1}) pt2 (list ${p2}))
@@ -4669,7 +4905,8 @@ async function measureArea(points) {
4669
4905
  if (!cad.connected) {
4670
4906
  await cad.connect();
4671
4907
  }
4672
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4908
+ if (!cad.connected)
4909
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4673
4910
  const pts = Array.isArray(points) ? points : points.split(/[\s,]+/).filter(Boolean);
4674
4911
  if (pts.length < 3) {
4675
4912
  return { content: [{ type: "text", text: "\u81F3\u5C11\u9700\u8981 3 \u4E2A\u70B9" }], isError: true };
@@ -4706,7 +4943,8 @@ async function getEntityInfo(handle) {
4706
4943
  if (!cad.connected) {
4707
4944
  await cad.connect();
4708
4945
  }
4709
- if (!cad.connected) return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4946
+ if (!cad.connected)
4947
+ return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
4710
4948
  const code = `(progn
4711
4949
  (vl-load-com)
4712
4950
  (if (setq ent (handent "${handle}"))
@@ -4741,7 +4979,8 @@ async function ensureConnected() {
4741
4979
  if (!cad.connected) {
4742
4980
  await cad.connect();
4743
4981
  }
4744
- if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
4982
+ if (!cad.connected)
4983
+ throw new Error("CAD \u672A\u8FDE\u63A5");
4745
4984
  }
4746
4985
  function parseHandleList(handles) {
4747
4986
  if (typeof handles === "string") {
@@ -4982,7 +5221,8 @@ async function ensureConnected2() {
4982
5221
  if (!cad.connected) {
4983
5222
  await cad.connect();
4984
5223
  }
4985
- if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
5224
+ if (!cad.connected)
5225
+ throw new Error("CAD \u672A\u8FDE\u63A5");
4986
5226
  }
4987
5227
  async function getXdata(handle, appName = "ACAD") {
4988
5228
  await ensureConnected2();
@@ -5188,10 +5428,11 @@ async function searchByXdata(appName, key, value) {
5188
5428
  async function exportXdataToFile(handle, filePath) {
5189
5429
  await ensureConnected2();
5190
5430
  const xdata = await getAllEntityXdata(handle);
5191
- if (!xdata.success) return xdata;
5431
+ if (!xdata.success)
5432
+ return xdata;
5192
5433
  try {
5193
- const fs8 = await import("fs");
5194
- fs8.writeFileSync(filePath, JSON.stringify(xdata.xdata, null, 2));
5434
+ const fs9 = await import("fs");
5435
+ fs9.writeFileSync(filePath, JSON.stringify(xdata.xdata, null, 2));
5195
5436
  return { handle, filePath, success: true };
5196
5437
  } catch (e) {
5197
5438
  return { error: e.message, success: false };
@@ -5200,8 +5441,8 @@ async function exportXdataToFile(handle, filePath) {
5200
5441
  async function importXdataFromFile(handle, filePath, appName) {
5201
5442
  await ensureConnected2();
5202
5443
  try {
5203
- const fs8 = await import("fs");
5204
- const data = fs8.readFileSync(filePath, "utf8");
5444
+ const fs9 = await import("fs");
5445
+ const data = fs9.readFileSync(filePath, "utf8");
5205
5446
  const xdata = JSON.parse(data);
5206
5447
  if (appName && xdata[appName]) {
5207
5448
  return await setXdata(handle, appName, xdata[appName]);
@@ -5221,7 +5462,8 @@ async function ensureConnected3() {
5221
5462
  if (!cad.connected) {
5222
5463
  await cad.connect();
5223
5464
  }
5224
- if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
5465
+ if (!cad.connected)
5466
+ throw new Error("CAD \u672A\u8FDE\u63A5");
5225
5467
  }
5226
5468
  async function createSheetSet(name, description = "") {
5227
5469
  await ensureConnected3();
@@ -5422,11 +5664,14 @@ async function ensureConnected4() {
5422
5664
  if (!cad.connected) {
5423
5665
  await cad.connect();
5424
5666
  }
5425
- if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
5667
+ if (!cad.connected)
5668
+ throw new Error("CAD \u672A\u8FDE\u63A5");
5426
5669
  }
5427
5670
  function parsePoint(point) {
5428
- if (Array.isArray(point)) return point.join(" ");
5429
- if (typeof point === "string") return point;
5671
+ if (Array.isArray(point))
5672
+ return point.join(" ");
5673
+ if (typeof point === "string")
5674
+ return point;
5430
5675
  return "0,0,0";
5431
5676
  }
5432
5677
  async function createBox(center, length, width, height) {
@@ -5686,7 +5931,8 @@ async function ensureConnected5() {
5686
5931
  if (!cad.connected) {
5687
5932
  await cad.connect();
5688
5933
  }
5689
- if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
5934
+ if (!cad.connected)
5935
+ throw new Error("CAD \u672A\u8FDE\u63A5");
5690
5936
  }
5691
5937
  async function createDimensionStyle(name, color = "bylayer", arrow = "ClosedFilled", textStyle = "") {
5692
5938
  await ensureConnected5();
@@ -5912,7 +6158,8 @@ async function ensureConnected6() {
5912
6158
  if (!cad.connected) {
5913
6159
  await cad.connect();
5914
6160
  }
5915
- if (!cad.connected) throw new Error("CAD \u672A\u8FDE\u63A5");
6161
+ if (!cad.connected)
6162
+ throw new Error("CAD \u672A\u8FDE\u63A5");
5916
6163
  }
5917
6164
  async function attachPdf(point, pdfPath, scale = 1, rotation = 0) {
5918
6165
  await ensureConnected6();
@@ -6352,7 +6599,8 @@ function validateToolArgs(name, args) {
6352
6599
  const baseType = type.replace("?", "");
6353
6600
  const val = args[key];
6354
6601
  if (val === void 0 || val === null) {
6355
- if (isOptional) continue;
6602
+ if (isOptional)
6603
+ continue;
6356
6604
  throw new Error(`Missing required argument: ${key}`);
6357
6605
  }
6358
6606
  const actualType = typeof args[key];
@@ -6397,7 +6645,8 @@ ${CAD_PLATFORMS.join("\n")}
6397
6645
  },
6398
6646
  import_funlib: async (a) => {
6399
6647
  const data = await loadAtlibFunctionLib();
6400
- if (!data) return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
6648
+ if (!data)
6649
+ return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
6401
6650
  if (a.format === "list") {
6402
6651
  const items = Object.values(data.all_functions || {}).map((f) => `${f.name}: ${f.description || ""}`);
6403
6652
  return { content: [{ type: "text", text: items.join("\n") }] };
@@ -8220,7 +8469,8 @@ function notifyResourceChanges(toolName) {
8220
8469
  }
8221
8470
  async function handleToolCall(name, args) {
8222
8471
  const handler = TOOL_HANDLERS[name];
8223
- if (!handler) return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
8472
+ if (!handler)
8473
+ return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
8224
8474
  try {
8225
8475
  validateToolArgs(name, args || {});
8226
8476
  const result = await handler(args || {});
@@ -8280,10 +8530,12 @@ var RateLimiter = class {
8280
8530
  this.keyLimits = /* @__PURE__ */ new Map();
8281
8531
  }
8282
8532
  getKeyLimit(apiKey2) {
8283
- if (!apiKey2) return this.defaultLimit;
8533
+ if (!apiKey2)
8534
+ return this.defaultLimit;
8284
8535
  if (config_default.apiKeys && config_default.apiKeys.length > 0) {
8285
8536
  const found = config_default.apiKeys.find((k) => k.key === apiKey2);
8286
- if (found) return found.limit;
8537
+ if (found)
8538
+ return found.limit;
8287
8539
  }
8288
8540
  if (config_default.apiKey && apiKey2 === config_default.apiKey) {
8289
8541
  return config_default.apiKeyRateLimit || 1e3;
@@ -8291,10 +8543,12 @@ var RateLimiter = class {
8291
8543
  return this.defaultLimit;
8292
8544
  }
8293
8545
  getKeyInfo(apiKey2) {
8294
- if (!apiKey2) return { name: "anonymous", limit: this.defaultLimit };
8546
+ if (!apiKey2)
8547
+ return { name: "anonymous", limit: this.defaultLimit };
8295
8548
  if (config_default.apiKeys && config_default.apiKeys.length > 0) {
8296
8549
  const found = config_default.apiKeys.find((k) => k.key === apiKey2);
8297
- if (found) return { name: found.name || apiKey2, limit: found.limit };
8550
+ if (found)
8551
+ return { name: found.name || apiKey2, limit: found.limit };
8298
8552
  }
8299
8553
  if (config_default.apiKey && apiKey2 === config_default.apiKey) {
8300
8554
  return { name: "admin", limit: config_default.apiKeyRateLimit || 1e3 };
@@ -8390,7 +8644,8 @@ var JSON_CONTENT_TYPES = ["application/json", "application/json-rpc", "applicati
8390
8644
  function createJsonBodyParser() {
8391
8645
  return async (req, res, next) => {
8392
8646
  const ct = (req.headers["content-type"] || "").toLowerCase();
8393
- if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t))) return next();
8647
+ if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
8648
+ return next();
8394
8649
  try {
8395
8650
  const chunks = [];
8396
8651
  for await (const chunk of req) {
@@ -8423,9 +8678,11 @@ function createAuthMiddleware() {
8423
8678
  const PUBLIC_PATHS = ["/health"];
8424
8679
  return (req, res, next) => {
8425
8680
  if (apiKey) {
8426
- if (PUBLIC_PATHS.includes(req.path)) return next();
8681
+ if (PUBLIC_PATHS.includes(req.path))
8682
+ return next();
8427
8683
  const auth = req.get("Authorization");
8428
- if (auth === `Bearer ${apiKey}`) return next();
8684
+ if (auth === `Bearer ${apiKey}`)
8685
+ return next();
8429
8686
  return res.status(401).json({ error: "Unauthorized" });
8430
8687
  }
8431
8688
  next();
@@ -8433,14 +8690,16 @@ function createAuthMiddleware() {
8433
8690
  }
8434
8691
  function createCorsMiddleware() {
8435
8692
  return (req, res, next) => {
8436
- if (!enableCors) return next();
8693
+ if (!enableCors)
8694
+ return next();
8437
8695
  res.setHeader("Access-Control-Allow-Origin", corsOrigin);
8438
8696
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, CONNECT");
8439
8697
  res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, mcp-session-id, last-event-id");
8440
8698
  res.setHeader("Access-Control-Expose-Headers", "mcp-session-id, content-type, x-accel-buffering");
8441
8699
  res.setHeader("Access-Control-Max-Age", "86400");
8442
8700
  res.setHeader("Vary", "Accept");
8443
- if (req.method === "OPTIONS") return res.status(204).end();
8701
+ if (req.method === "OPTIONS")
8702
+ return res.status(204).end();
8444
8703
  next();
8445
8704
  };
8446
8705
  }
@@ -8852,7 +9111,8 @@ For more info: https://atlisp.cn
8852
9111
  }
8853
9112
  }
8854
9113
  }
8855
- if (config_default.apiKey) log("API Key authentication enabled");
9114
+ if (config_default.apiKey)
9115
+ log("API Key authentication enabled");
8856
9116
  async function initCadConnection() {
8857
9117
  log("Attempting to connect to CAD on startup...");
8858
9118
  try {