@atlisp/mcp 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atlisp-mcp.js +500 -251
- package/package.json +1 -1
package/dist/atlisp-mcp.js
CHANGED
|
@@ -70,7 +70,8 @@ function parseArgs() {
|
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
72
72
|
function loadConfigFile(filePath) {
|
|
73
|
-
if (!filePath || !fs.existsSync(filePath))
|
|
73
|
+
if (!filePath || !fs.existsSync(filePath))
|
|
74
|
+
return null;
|
|
74
75
|
try {
|
|
75
76
|
const raw = fs.readFileSync(filePath, "utf-8");
|
|
76
77
|
const parsed = JSON.parse(raw);
|
|
@@ -226,7 +227,8 @@ function onDocumentChanged(callback) {
|
|
|
226
227
|
_docChangeCallbacks.push(callback);
|
|
227
228
|
}
|
|
228
229
|
function emitDocumentChanged(info) {
|
|
229
|
-
if (info.docName === _activeDocName)
|
|
230
|
+
if (info.docName === _activeDocName)
|
|
231
|
+
return;
|
|
230
232
|
_activeDocName = info.docName || "";
|
|
231
233
|
for (const cb of _docChangeCallbacks) {
|
|
232
234
|
try {
|
|
@@ -285,7 +287,8 @@ function setupStdoutHandler(w) {
|
|
|
285
287
|
const lines = buffer.split("\n");
|
|
286
288
|
buffer = lines.pop() || "";
|
|
287
289
|
for (const line of lines) {
|
|
288
|
-
if (!line.trim())
|
|
290
|
+
if (!line.trim())
|
|
291
|
+
continue;
|
|
289
292
|
try {
|
|
290
293
|
const result = JSON.parse(line);
|
|
291
294
|
const rid = result.requestId;
|
|
@@ -313,7 +316,8 @@ function setupStdoutHandler(w) {
|
|
|
313
316
|
}
|
|
314
317
|
function getWorker(force = false) {
|
|
315
318
|
if (!worker || !worker.connected || force) {
|
|
316
|
-
if (worker)
|
|
319
|
+
if (worker)
|
|
320
|
+
worker.kill();
|
|
317
321
|
worker = spawn("node", [workerPath], {
|
|
318
322
|
stdio: ["pipe", "pipe", "pipe"]
|
|
319
323
|
});
|
|
@@ -321,7 +325,8 @@ function getWorker(force = false) {
|
|
|
321
325
|
const w = worker;
|
|
322
326
|
w.on("exit", (code) => {
|
|
323
327
|
console.error("worker exited with code:", code);
|
|
324
|
-
if (w !== worker)
|
|
328
|
+
if (w !== worker)
|
|
329
|
+
return;
|
|
325
330
|
w.connected = false;
|
|
326
331
|
for (const [id, { reject, timeout }] of pendingRequests) {
|
|
327
332
|
clearTimeout(timeout);
|
|
@@ -342,7 +347,8 @@ function getWorker(force = false) {
|
|
|
342
347
|
return worker;
|
|
343
348
|
}
|
|
344
349
|
function startHeartbeat() {
|
|
345
|
-
if (heartbeatTimer)
|
|
350
|
+
if (heartbeatTimer)
|
|
351
|
+
clearInterval(heartbeatTimer);
|
|
346
352
|
heartbeatTimer = setInterval(async () => {
|
|
347
353
|
try {
|
|
348
354
|
const result = await sendMessage({ type: "ping" });
|
|
@@ -443,13 +449,16 @@ var init_cad = __esm({
|
|
|
443
449
|
return null;
|
|
444
450
|
}
|
|
445
451
|
async _process() {
|
|
446
|
-
if (this.#processing)
|
|
452
|
+
if (this.#processing)
|
|
453
|
+
return;
|
|
447
454
|
this.#processing = true;
|
|
448
455
|
while (this._hasPending()) {
|
|
449
456
|
const cmd = this._dequeue();
|
|
450
|
-
if (!cmd)
|
|
457
|
+
if (!cmd)
|
|
458
|
+
continue;
|
|
451
459
|
const dedupKey = this._dedupKey(cmd);
|
|
452
|
-
if (dedupKey)
|
|
460
|
+
if (dedupKey)
|
|
461
|
+
this.#dedupMap.delete(dedupKey);
|
|
453
462
|
try {
|
|
454
463
|
const result = await sendMessage(cmd);
|
|
455
464
|
cmd.resolve(result);
|
|
@@ -464,7 +473,8 @@ var init_cad = __esm({
|
|
|
464
473
|
}
|
|
465
474
|
_dequeue() {
|
|
466
475
|
for (const q of this.#queues) {
|
|
467
|
-
if (q.length > 0)
|
|
476
|
+
if (q.length > 0)
|
|
477
|
+
return q.shift();
|
|
468
478
|
}
|
|
469
479
|
return null;
|
|
470
480
|
}
|
|
@@ -492,7 +502,8 @@ var init_cad = __esm({
|
|
|
492
502
|
return process.platform === "win32";
|
|
493
503
|
}
|
|
494
504
|
async connect(platform = null) {
|
|
495
|
-
if (!this.isAvailable())
|
|
505
|
+
if (!this.isAvailable())
|
|
506
|
+
return false;
|
|
496
507
|
try {
|
|
497
508
|
const msg = platform ? { type: "connect", platform } : { type: "connect" };
|
|
498
509
|
const result = await sendMessage(msg);
|
|
@@ -516,7 +527,8 @@ var init_cad = __esm({
|
|
|
516
527
|
return false;
|
|
517
528
|
}
|
|
518
529
|
async sendCommand(code) {
|
|
519
|
-
if (!this.connected)
|
|
530
|
+
if (!this.connected)
|
|
531
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
520
532
|
return new Promise((resolve, reject) => {
|
|
521
533
|
commandQueue.enqueue({
|
|
522
534
|
type: "send",
|
|
@@ -526,12 +538,14 @@ var init_cad = __esm({
|
|
|
526
538
|
reject
|
|
527
539
|
}, PRIORITY_NORMAL);
|
|
528
540
|
}).then((result) => {
|
|
529
|
-
if (result.success)
|
|
541
|
+
if (result.success)
|
|
542
|
+
return true;
|
|
530
543
|
throw new Error(result.error || "\u53D1\u9001\u5931\u8D25");
|
|
531
544
|
});
|
|
532
545
|
}
|
|
533
546
|
async sendCommandWithResult(code, encoding = null) {
|
|
534
|
-
if (!this.connected)
|
|
547
|
+
if (!this.connected)
|
|
548
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
535
549
|
return new Promise((resolve, reject) => {
|
|
536
550
|
commandQueue.enqueue({
|
|
537
551
|
type: "sendResult",
|
|
@@ -542,7 +556,8 @@ var init_cad = __esm({
|
|
|
542
556
|
reject
|
|
543
557
|
}, PRIORITY_NORMAL);
|
|
544
558
|
}).then((result) => {
|
|
545
|
-
if (result.success)
|
|
559
|
+
if (result.success)
|
|
560
|
+
return result.result || "";
|
|
546
561
|
throw new Error(result.error || "\u53D1\u9001\u5931\u8D25");
|
|
547
562
|
});
|
|
548
563
|
}
|
|
@@ -553,7 +568,8 @@ var init_cad = __esm({
|
|
|
553
568
|
return this.product;
|
|
554
569
|
}
|
|
555
570
|
async isBusy() {
|
|
556
|
-
if (!this.connected)
|
|
571
|
+
if (!this.connected)
|
|
572
|
+
return false;
|
|
557
573
|
try {
|
|
558
574
|
const result = await sendMessage({ type: "isBusy", platform: _platform });
|
|
559
575
|
return result && result.isBusy;
|
|
@@ -562,7 +578,8 @@ var init_cad = __esm({
|
|
|
562
578
|
}
|
|
563
579
|
}
|
|
564
580
|
async hasDoc() {
|
|
565
|
-
if (!this.connected)
|
|
581
|
+
if (!this.connected)
|
|
582
|
+
return { hasDoc: false, docCount: 0 };
|
|
566
583
|
try {
|
|
567
584
|
const result = await sendMessage({ type: "hasdoc", platform: _platform });
|
|
568
585
|
return result || { hasDoc: false, docCount: 0 };
|
|
@@ -571,7 +588,8 @@ var init_cad = __esm({
|
|
|
571
588
|
}
|
|
572
589
|
}
|
|
573
590
|
async newDoc() {
|
|
574
|
-
if (!this.connected)
|
|
591
|
+
if (!this.connected)
|
|
592
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
575
593
|
try {
|
|
576
594
|
const result = await sendMessage({ type: "newdoc", platform: _platform });
|
|
577
595
|
return result && result.success;
|
|
@@ -580,7 +598,8 @@ var init_cad = __esm({
|
|
|
580
598
|
}
|
|
581
599
|
}
|
|
582
600
|
async bringToFront() {
|
|
583
|
-
if (!this.connected)
|
|
601
|
+
if (!this.connected)
|
|
602
|
+
throw new Error("\u672A\u8FDE\u63A5 CAD");
|
|
584
603
|
try {
|
|
585
604
|
const result = await sendMessage({ type: "bringToFront", platform: _platform });
|
|
586
605
|
return result && result.success;
|
|
@@ -589,7 +608,8 @@ var init_cad = __esm({
|
|
|
589
608
|
}
|
|
590
609
|
}
|
|
591
610
|
async getActiveDocInfo() {
|
|
592
|
-
if (!this.connected)
|
|
611
|
+
if (!this.connected)
|
|
612
|
+
return { docName: "", docPath: "", docCount: 0 };
|
|
593
613
|
try {
|
|
594
614
|
const result = await sendMessage({ type: "getActiveDocInfo", platform: _platform });
|
|
595
615
|
return result || { docName: "", docPath: "", docCount: 0 };
|
|
@@ -598,7 +618,8 @@ var init_cad = __esm({
|
|
|
598
618
|
}
|
|
599
619
|
}
|
|
600
620
|
async getInfo() {
|
|
601
|
-
if (!this.connected)
|
|
621
|
+
if (!this.connected)
|
|
622
|
+
return "CAD \u672A\u8FDE\u63A5";
|
|
602
623
|
return `Platform: ${this.product}, Version: ${this.version}, Status: Connected`;
|
|
603
624
|
}
|
|
604
625
|
async disconnect() {
|
|
@@ -643,14 +664,16 @@ __export(renderer_exports, {
|
|
|
643
664
|
renderTemplate: () => renderTemplate
|
|
644
665
|
});
|
|
645
666
|
function escapeLispString2(str) {
|
|
646
|
-
if (typeof str !== "string")
|
|
667
|
+
if (typeof str !== "string")
|
|
668
|
+
return "";
|
|
647
669
|
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
648
670
|
}
|
|
649
671
|
function resolvePath(obj, path12) {
|
|
650
672
|
const parts = path12.split(/[.\[\]]/g).filter(Boolean);
|
|
651
673
|
let val = obj;
|
|
652
674
|
for (const p of parts) {
|
|
653
|
-
if (val == null)
|
|
675
|
+
if (val == null)
|
|
676
|
+
return void 0;
|
|
654
677
|
val = val[p];
|
|
655
678
|
}
|
|
656
679
|
return val;
|
|
@@ -659,9 +682,11 @@ function renderTemplate(template, args) {
|
|
|
659
682
|
return template.replace(PARAM_RE, (match, rawExpr, expr) => {
|
|
660
683
|
const path12 = rawExpr || expr;
|
|
661
684
|
const val = resolvePath(args, path12);
|
|
662
|
-
if (val == null)
|
|
685
|
+
if (val == null)
|
|
686
|
+
return "";
|
|
663
687
|
const strVal = String(val);
|
|
664
|
-
if (rawExpr)
|
|
688
|
+
if (rawExpr)
|
|
689
|
+
return strVal;
|
|
665
690
|
return escapeLispString2(strVal);
|
|
666
691
|
});
|
|
667
692
|
}
|
|
@@ -720,8 +745,9 @@ import express2 from "express";
|
|
|
720
745
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
721
746
|
|
|
722
747
|
// src/logger.js
|
|
723
|
-
import fs2 from "fs";
|
|
724
748
|
init_config();
|
|
749
|
+
import fs2 from "fs";
|
|
750
|
+
import fsp from "fs/promises";
|
|
725
751
|
import path3 from "path";
|
|
726
752
|
import os2 from "os";
|
|
727
753
|
var DEBUG_FILE = config_default.debugFile || path3.join(os2.tmpdir(), "mcp-server-debug.log");
|
|
@@ -730,9 +756,11 @@ var MAX_LOG_FILES = 5;
|
|
|
730
756
|
var stream = null;
|
|
731
757
|
function rotateLog() {
|
|
732
758
|
try {
|
|
733
|
-
if (!fs2.existsSync(DEBUG_FILE))
|
|
759
|
+
if (!fs2.existsSync(DEBUG_FILE))
|
|
760
|
+
return;
|
|
734
761
|
const stat = fs2.statSync(DEBUG_FILE);
|
|
735
|
-
if (stat.size < MAX_LOG_SIZE)
|
|
762
|
+
if (stat.size < MAX_LOG_SIZE)
|
|
763
|
+
return;
|
|
736
764
|
if (stream) {
|
|
737
765
|
stream.end();
|
|
738
766
|
stream = null;
|
|
@@ -806,9 +834,11 @@ function ensureRequestLogDir() {
|
|
|
806
834
|
}
|
|
807
835
|
function rotateRequestLog() {
|
|
808
836
|
try {
|
|
809
|
-
if (!fs2.existsSync(REQUEST_LOG_FILE))
|
|
837
|
+
if (!fs2.existsSync(REQUEST_LOG_FILE))
|
|
838
|
+
return;
|
|
810
839
|
const stat = fs2.statSync(REQUEST_LOG_FILE);
|
|
811
|
-
if (stat.size < 10 * 1024 * 1024)
|
|
840
|
+
if (stat.size < 10 * 1024 * 1024)
|
|
841
|
+
return;
|
|
812
842
|
if (requestStream) {
|
|
813
843
|
requestStream.end();
|
|
814
844
|
requestStream = null;
|
|
@@ -833,7 +863,8 @@ function rotateRequestLog() {
|
|
|
833
863
|
}
|
|
834
864
|
}
|
|
835
865
|
function logRequest(req) {
|
|
836
|
-
if (!config_default.requestLogEnabled)
|
|
866
|
+
if (!config_default.requestLogEnabled)
|
|
867
|
+
return;
|
|
837
868
|
try {
|
|
838
869
|
ensureRequestLogDir();
|
|
839
870
|
rotateRequestLog();
|
|
@@ -854,7 +885,8 @@ function logRequest(req) {
|
|
|
854
885
|
}
|
|
855
886
|
}
|
|
856
887
|
function logResponse(req, res, duration) {
|
|
857
|
-
if (!config_default.requestLogEnabled)
|
|
888
|
+
if (!config_default.requestLogEnabled)
|
|
889
|
+
return;
|
|
858
890
|
try {
|
|
859
891
|
ensureRequestLogDir();
|
|
860
892
|
if (!requestStream) {
|
|
@@ -1033,21 +1065,27 @@ async function ensureCadConnected() {
|
|
|
1033
1065
|
}
|
|
1034
1066
|
}
|
|
1035
1067
|
function escapeLispString(str) {
|
|
1036
|
-
if (typeof str !== "string")
|
|
1068
|
+
if (typeof str !== "string")
|
|
1069
|
+
return "";
|
|
1037
1070
|
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
1038
1071
|
}
|
|
1039
1072
|
function tryNumber(val) {
|
|
1040
|
-
if (typeof val === "number")
|
|
1073
|
+
if (typeof val === "number")
|
|
1074
|
+
return val;
|
|
1041
1075
|
const n = Number(val);
|
|
1042
|
-
if (!isNaN(n) && val !== "")
|
|
1076
|
+
if (!isNaN(n) && val !== "")
|
|
1077
|
+
return n;
|
|
1043
1078
|
return val;
|
|
1044
1079
|
}
|
|
1045
1080
|
function parseLispList(str) {
|
|
1046
|
-
if (!str || typeof str !== "string")
|
|
1081
|
+
if (!str || typeof str !== "string")
|
|
1082
|
+
return null;
|
|
1047
1083
|
const trimmed = str.trim();
|
|
1048
|
-
if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
|
|
1084
|
+
if (!trimmed.startsWith("(") || !trimmed.endsWith(")"))
|
|
1085
|
+
return null;
|
|
1049
1086
|
const content = trimmed.slice(1, -1).trim();
|
|
1050
|
-
if (!content)
|
|
1087
|
+
if (!content)
|
|
1088
|
+
return [];
|
|
1051
1089
|
const result = [];
|
|
1052
1090
|
let depth = 0;
|
|
1053
1091
|
let current = "";
|
|
@@ -1089,29 +1127,39 @@ function parseLispList(str) {
|
|
|
1089
1127
|
}
|
|
1090
1128
|
current += ch;
|
|
1091
1129
|
}
|
|
1092
|
-
if (current.trim())
|
|
1130
|
+
if (current.trim())
|
|
1131
|
+
result.push(current.trim());
|
|
1093
1132
|
return result.map((item) => {
|
|
1094
1133
|
const t = item.trim();
|
|
1095
|
-
if (t === "nil" || t === "NIL")
|
|
1096
|
-
|
|
1097
|
-
if (t
|
|
1134
|
+
if (t === "nil" || t === "NIL")
|
|
1135
|
+
return null;
|
|
1136
|
+
if (t === "t" || t === "T")
|
|
1137
|
+
return true;
|
|
1138
|
+
if (t.startsWith('"') && t.endsWith('"'))
|
|
1139
|
+
return t.slice(1, -1);
|
|
1098
1140
|
return tryNumber(t);
|
|
1099
1141
|
});
|
|
1100
1142
|
}
|
|
1101
1143
|
function parseLispRecursive(str) {
|
|
1102
|
-
if (!str || typeof str !== "string")
|
|
1144
|
+
if (!str || typeof str !== "string")
|
|
1145
|
+
return null;
|
|
1103
1146
|
str = str.trim();
|
|
1104
|
-
if (!str)
|
|
1147
|
+
if (!str)
|
|
1148
|
+
return null;
|
|
1105
1149
|
let pos = 0;
|
|
1106
1150
|
function skipWs() {
|
|
1107
|
-
while (pos < str.length && /\s/.test(str[pos]))
|
|
1151
|
+
while (pos < str.length && /\s/.test(str[pos]))
|
|
1152
|
+
pos++;
|
|
1108
1153
|
}
|
|
1109
1154
|
function parseValue() {
|
|
1110
1155
|
skipWs();
|
|
1111
|
-
if (pos >= str.length)
|
|
1156
|
+
if (pos >= str.length)
|
|
1157
|
+
return null;
|
|
1112
1158
|
const ch = str[pos];
|
|
1113
|
-
if (ch === "(")
|
|
1114
|
-
|
|
1159
|
+
if (ch === "(")
|
|
1160
|
+
return parseList();
|
|
1161
|
+
if (ch === '"')
|
|
1162
|
+
return parseString();
|
|
1115
1163
|
if (ch === "'") {
|
|
1116
1164
|
pos++;
|
|
1117
1165
|
return parseValue();
|
|
@@ -1124,11 +1172,16 @@ function parseLispRecursive(str) {
|
|
|
1124
1172
|
while (pos < str.length && str[pos] !== '"') {
|
|
1125
1173
|
if (str[pos] === "\\" && pos + 1 < str.length) {
|
|
1126
1174
|
pos++;
|
|
1127
|
-
if (str[pos] === '"')
|
|
1128
|
-
|
|
1129
|
-
else if (str[pos] === "
|
|
1130
|
-
|
|
1131
|
-
else
|
|
1175
|
+
if (str[pos] === '"')
|
|
1176
|
+
r += '"';
|
|
1177
|
+
else if (str[pos] === "n")
|
|
1178
|
+
r += "\n";
|
|
1179
|
+
else if (str[pos] === "t")
|
|
1180
|
+
r += " ";
|
|
1181
|
+
else if (str[pos] === "\\")
|
|
1182
|
+
r += "\\";
|
|
1183
|
+
else
|
|
1184
|
+
r += str[pos];
|
|
1132
1185
|
} else {
|
|
1133
1186
|
r += str[pos];
|
|
1134
1187
|
}
|
|
@@ -1139,10 +1192,13 @@ function parseLispRecursive(str) {
|
|
|
1139
1192
|
}
|
|
1140
1193
|
function parseAtom() {
|
|
1141
1194
|
const start = pos;
|
|
1142
|
-
while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(")
|
|
1195
|
+
while (pos < str.length && !/\s/.test(str[pos]) && str[pos] !== ")" && str[pos] !== "(")
|
|
1196
|
+
pos++;
|
|
1143
1197
|
const atom = str.slice(start, pos);
|
|
1144
|
-
if (atom === "nil" || atom === "NIL")
|
|
1145
|
-
|
|
1198
|
+
if (atom === "nil" || atom === "NIL")
|
|
1199
|
+
return null;
|
|
1200
|
+
if (atom === "t" || atom === "T")
|
|
1201
|
+
return true;
|
|
1146
1202
|
return tryNumber(atom);
|
|
1147
1203
|
}
|
|
1148
1204
|
function parseList() {
|
|
@@ -1150,13 +1206,15 @@ function parseLispRecursive(str) {
|
|
|
1150
1206
|
const items = [];
|
|
1151
1207
|
while (pos < str.length) {
|
|
1152
1208
|
skipWs();
|
|
1153
|
-
if (pos >= str.length)
|
|
1209
|
+
if (pos >= str.length)
|
|
1210
|
+
break;
|
|
1154
1211
|
if (str[pos] === ")") {
|
|
1155
1212
|
pos++;
|
|
1156
1213
|
return items;
|
|
1157
1214
|
}
|
|
1158
1215
|
const left = parseValue();
|
|
1159
|
-
if (left === void 0)
|
|
1216
|
+
if (left === void 0)
|
|
1217
|
+
break;
|
|
1160
1218
|
skipWs();
|
|
1161
1219
|
if (str[pos] === "." && (pos + 1 >= str.length || /\s/.test(str[pos + 1]) || str[pos + 1] === ")")) {
|
|
1162
1220
|
pos++;
|
|
@@ -1233,7 +1291,8 @@ var ENTITY_PROPERTIES_LISP = `
|
|
|
1233
1291
|
result)
|
|
1234
1292
|
`;
|
|
1235
1293
|
function propertyPairsToObject(pairs) {
|
|
1236
|
-
if (!Array.isArray(pairs))
|
|
1294
|
+
if (!Array.isArray(pairs))
|
|
1295
|
+
return null;
|
|
1237
1296
|
const obj = {};
|
|
1238
1297
|
for (const pair of pairs) {
|
|
1239
1298
|
if (Array.isArray(pair) && pair.length >= 2) {
|
|
@@ -1244,8 +1303,10 @@ function propertyPairsToObject(pairs) {
|
|
|
1244
1303
|
}
|
|
1245
1304
|
function buildEntityPropertiesCode({ type, layer, bbox }) {
|
|
1246
1305
|
const items = [];
|
|
1247
|
-
if (type)
|
|
1248
|
-
|
|
1306
|
+
if (type)
|
|
1307
|
+
items.push(`(cons 0 "${escapeLispString(type)}")`);
|
|
1308
|
+
if (layer)
|
|
1309
|
+
items.push(`(cons 8 "${escapeLispString(layer)}")`);
|
|
1249
1310
|
if (bbox) {
|
|
1250
1311
|
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
1251
1312
|
if (parts.length === 4) {
|
|
@@ -1271,8 +1332,10 @@ ${ENTITY_PROPERTIES_LISP}
|
|
|
1271
1332
|
(vl-prin1-to-string (list @e:total (reverse @e:ents))))`;
|
|
1272
1333
|
}
|
|
1273
1334
|
async function getEntityByHandle(handle) {
|
|
1274
|
-
if (!cad.connected)
|
|
1275
|
-
|
|
1335
|
+
if (!cad.connected)
|
|
1336
|
+
await cad.connect();
|
|
1337
|
+
if (!cad.connected)
|
|
1338
|
+
return { error: "CAD \u672A\u8FDE\u63A5" };
|
|
1276
1339
|
const code = `(progn
|
|
1277
1340
|
(vl-load-com)
|
|
1278
1341
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -1292,7 +1355,8 @@ async function getEntityByHandle(handle) {
|
|
|
1292
1355
|
)`;
|
|
1293
1356
|
try {
|
|
1294
1357
|
const result = await cad.sendCommandWithResult(code);
|
|
1295
|
-
if (!result || result === "nil")
|
|
1358
|
+
if (!result || result === "nil")
|
|
1359
|
+
return { error: `\u672A\u627E\u5230\u5B9E\u4F53: ${handle}` };
|
|
1296
1360
|
try {
|
|
1297
1361
|
return JSON.parse(result);
|
|
1298
1362
|
} catch {
|
|
@@ -1304,7 +1368,8 @@ async function getEntityByHandle(handle) {
|
|
|
1304
1368
|
}
|
|
1305
1369
|
async function getCadInfo() {
|
|
1306
1370
|
const cached = getCached("cad:info");
|
|
1307
|
-
if (cached)
|
|
1371
|
+
if (cached)
|
|
1372
|
+
return cached;
|
|
1308
1373
|
if (!cad.connected) {
|
|
1309
1374
|
await cad.connect();
|
|
1310
1375
|
}
|
|
@@ -1329,8 +1394,10 @@ async function getCadInfo() {
|
|
|
1329
1394
|
async function getEntities(params = {}) {
|
|
1330
1395
|
const cacheKey = `dwg:entities:${JSON.stringify(params)}`;
|
|
1331
1396
|
const cached = getCached(cacheKey);
|
|
1332
|
-
if (cached)
|
|
1333
|
-
|
|
1397
|
+
if (cached)
|
|
1398
|
+
return cached;
|
|
1399
|
+
if (!cad.connected)
|
|
1400
|
+
await cad.connect();
|
|
1334
1401
|
if (!cad.connected) {
|
|
1335
1402
|
return { total: 0, entities: [] };
|
|
1336
1403
|
}
|
|
@@ -1425,7 +1492,8 @@ function buildTextContentCode({ layer, bbox, offset, limit }) {
|
|
|
1425
1492
|
`'(0 . "ATTRIB")`,
|
|
1426
1493
|
`'(-4 . "OR>")`
|
|
1427
1494
|
];
|
|
1428
|
-
if (layer)
|
|
1495
|
+
if (layer)
|
|
1496
|
+
items.push(`(cons 8 "${escapeLispString(layer)}")`);
|
|
1429
1497
|
if (bbox) {
|
|
1430
1498
|
const parts = bbox.split(",").map((s) => parseFloat(s.trim()));
|
|
1431
1499
|
if (parts.length === 4) {
|
|
@@ -1455,8 +1523,10 @@ function buildTextContentCode({ layer, bbox, offset, limit }) {
|
|
|
1455
1523
|
async function getTextContent(params = {}) {
|
|
1456
1524
|
const cacheKey = `dwg:text-content:${JSON.stringify(params)}`;
|
|
1457
1525
|
const cached = getCached(cacheKey);
|
|
1458
|
-
if (cached)
|
|
1459
|
-
|
|
1526
|
+
if (cached)
|
|
1527
|
+
return cached;
|
|
1528
|
+
if (!cad.connected)
|
|
1529
|
+
await cad.connect();
|
|
1460
1530
|
if (!cad.connected) {
|
|
1461
1531
|
return { total: 0, offset: 0, limit: 5e3, texts: [] };
|
|
1462
1532
|
}
|
|
@@ -1484,12 +1554,14 @@ async function getTextContent(params = {}) {
|
|
|
1484
1554
|
}
|
|
1485
1555
|
}
|
|
1486
1556
|
data.texts = rawTexts.map((item) => {
|
|
1487
|
-
if (!Array.isArray(item))
|
|
1557
|
+
if (!Array.isArray(item))
|
|
1558
|
+
return null;
|
|
1488
1559
|
const obj = {};
|
|
1489
1560
|
for (let i = 0; i < item.length - 1; i += 2) {
|
|
1490
1561
|
const key = item[i];
|
|
1491
1562
|
const val = item[i + 1];
|
|
1492
|
-
if (key === "text")
|
|
1563
|
+
if (key === "text")
|
|
1564
|
+
obj.text = String(val || "");
|
|
1493
1565
|
else if (key === "position") {
|
|
1494
1566
|
obj.position = Array.isArray(val) ? val.map((v) => typeof v === "number" ? v : 0) : [];
|
|
1495
1567
|
}
|
|
@@ -1504,8 +1576,10 @@ async function getTextContent(params = {}) {
|
|
|
1504
1576
|
}
|
|
1505
1577
|
}
|
|
1506
1578
|
async function getDwgName() {
|
|
1507
|
-
if (!cad.connected)
|
|
1508
|
-
|
|
1579
|
+
if (!cad.connected)
|
|
1580
|
+
await cad.connect();
|
|
1581
|
+
if (!cad.connected)
|
|
1582
|
+
return { name: null };
|
|
1509
1583
|
try {
|
|
1510
1584
|
const code = `(vl-princ-to-string (getvar "dwgname"))`;
|
|
1511
1585
|
const name = await cad.sendCommandWithResult(code);
|
|
@@ -1515,8 +1589,10 @@ async function getDwgName() {
|
|
|
1515
1589
|
}
|
|
1516
1590
|
}
|
|
1517
1591
|
async function getDwgPath() {
|
|
1518
|
-
if (!cad.connected)
|
|
1519
|
-
|
|
1592
|
+
if (!cad.connected)
|
|
1593
|
+
await cad.connect();
|
|
1594
|
+
if (!cad.connected)
|
|
1595
|
+
return { path: null, name: null };
|
|
1520
1596
|
try {
|
|
1521
1597
|
const code = `(progn
|
|
1522
1598
|
(setq prefix (vl-princ-to-string (getvar "dwgprefix")))
|
|
@@ -1535,7 +1611,8 @@ async function getDwgPath() {
|
|
|
1535
1611
|
}
|
|
1536
1612
|
if (!parsed) {
|
|
1537
1613
|
const listResult = parseLispList(result);
|
|
1538
|
-
if (listResult && listResult.length >= 2)
|
|
1614
|
+
if (listResult && listResult.length >= 2)
|
|
1615
|
+
parsed = listResult;
|
|
1539
1616
|
}
|
|
1540
1617
|
if (parsed && Array.isArray(parsed) && parsed.length >= 2) {
|
|
1541
1618
|
return { path: String(parsed[0]), name: String(parsed[1]) };
|
|
@@ -1593,8 +1670,10 @@ function buildBlockRefsCode(filterBlockName) {
|
|
|
1593
1670
|
async function getBlockRefs(params = {}) {
|
|
1594
1671
|
const cacheKey = `dwg:block-refs:${params.blockName || "all"}`;
|
|
1595
1672
|
const cached = getCached(cacheKey);
|
|
1596
|
-
if (cached)
|
|
1597
|
-
|
|
1673
|
+
if (cached)
|
|
1674
|
+
return cached;
|
|
1675
|
+
if (!cad.connected)
|
|
1676
|
+
await cad.connect();
|
|
1598
1677
|
if (!cad.connected) {
|
|
1599
1678
|
return { total: 0, blockRefs: [] };
|
|
1600
1679
|
}
|
|
@@ -1630,13 +1709,15 @@ async function getBlockRefs(params = {}) {
|
|
|
1630
1709
|
} else if (key === "attributes" && Array.isArray(val)) {
|
|
1631
1710
|
const o = {};
|
|
1632
1711
|
val.forEach((p) => {
|
|
1633
|
-
if (Array.isArray(p) && p.length >= 2)
|
|
1712
|
+
if (Array.isArray(p) && p.length >= 2)
|
|
1713
|
+
o[String(p[0])] = p[1];
|
|
1634
1714
|
});
|
|
1635
1715
|
val = o;
|
|
1636
1716
|
} else if (key === "dynamicProperties" && Array.isArray(val)) {
|
|
1637
1717
|
const o = {};
|
|
1638
1718
|
val.forEach((p) => {
|
|
1639
|
-
if (Array.isArray(p) && p.length >= 2)
|
|
1719
|
+
if (Array.isArray(p) && p.length >= 2)
|
|
1720
|
+
o[String(p[0])] = p[1];
|
|
1640
1721
|
});
|
|
1641
1722
|
val = o;
|
|
1642
1723
|
}
|
|
@@ -1683,7 +1764,8 @@ function buildTablesCode(tblName) {
|
|
|
1683
1764
|
return `(progn (vl-load-com) ${VLA_HELPER_LISP} (list ${parts.join(" ")}))`;
|
|
1684
1765
|
}
|
|
1685
1766
|
function parseTableRecord(rec, tableName) {
|
|
1686
|
-
if (!rec || !Array.isArray(rec))
|
|
1767
|
+
if (!rec || !Array.isArray(rec))
|
|
1768
|
+
return null;
|
|
1687
1769
|
const obj = {};
|
|
1688
1770
|
const isLayer = tableName === "layer";
|
|
1689
1771
|
for (const pair of rec) {
|
|
@@ -1692,24 +1774,35 @@ function parseTableRecord(rec, tableName) {
|
|
|
1692
1774
|
const val = pair[1];
|
|
1693
1775
|
const isDxfCode = typeof pair[0] === "number";
|
|
1694
1776
|
if (isDxfCode) {
|
|
1695
|
-
if (key === "2")
|
|
1696
|
-
|
|
1697
|
-
else if (key === "
|
|
1777
|
+
if (key === "2")
|
|
1778
|
+
obj.name = String(val);
|
|
1779
|
+
else if (key === "62")
|
|
1780
|
+
obj.color = typeof val === "number" ? val : 7;
|
|
1781
|
+
else if (key === "6")
|
|
1782
|
+
obj.linetype = String(val);
|
|
1698
1783
|
else if (key === "70") {
|
|
1699
1784
|
obj.flags = typeof val === "number" ? val : 0;
|
|
1700
1785
|
if (isLayer) {
|
|
1701
1786
|
obj.frozen = (val & 1) !== 0;
|
|
1702
1787
|
obj.locked = (val & 4) !== 0;
|
|
1703
1788
|
}
|
|
1704
|
-
} else if (key === "60")
|
|
1705
|
-
|
|
1706
|
-
else if (key === "
|
|
1707
|
-
|
|
1708
|
-
else if (key === "
|
|
1709
|
-
|
|
1710
|
-
else if (key === "
|
|
1789
|
+
} else if (key === "60")
|
|
1790
|
+
obj.on = val === 0;
|
|
1791
|
+
else if (key === "1")
|
|
1792
|
+
obj.font = String(val);
|
|
1793
|
+
else if (key === "40")
|
|
1794
|
+
obj.height = typeof val === "number" ? val : 0;
|
|
1795
|
+
else if (key === "41")
|
|
1796
|
+
obj.width = typeof val === "number" ? val : 1;
|
|
1797
|
+
else if (key === "42")
|
|
1798
|
+
obj.oblique = typeof val === "number" ? val : 0;
|
|
1799
|
+
else if (key === "3")
|
|
1800
|
+
obj.bigfont = String(val);
|
|
1801
|
+
else if (key === "50")
|
|
1802
|
+
obj.flags = typeof val === "number" ? val : 0;
|
|
1711
1803
|
} else {
|
|
1712
|
-
if (key === "Name")
|
|
1804
|
+
if (key === "Name")
|
|
1805
|
+
obj.name = val;
|
|
1713
1806
|
obj[key] = val;
|
|
1714
1807
|
}
|
|
1715
1808
|
}
|
|
@@ -1720,9 +1813,12 @@ async function getTables(params = {}) {
|
|
|
1720
1813
|
const tblName = params.tbl || params.type || "all";
|
|
1721
1814
|
const cacheKey = `dwg:tbl:${tblName}`;
|
|
1722
1815
|
const cached = getCached(cacheKey);
|
|
1723
|
-
if (cached)
|
|
1724
|
-
|
|
1725
|
-
if (!cad.connected)
|
|
1816
|
+
if (cached)
|
|
1817
|
+
return cached;
|
|
1818
|
+
if (!cad.connected)
|
|
1819
|
+
await cad.connect();
|
|
1820
|
+
if (!cad.connected)
|
|
1821
|
+
return { table: tblName, data: [] };
|
|
1726
1822
|
try {
|
|
1727
1823
|
const code = buildTablesCode(tblName);
|
|
1728
1824
|
const resultStr = await cad.sendCommandWithResult(code);
|
|
@@ -1741,7 +1837,8 @@ async function getTables(params = {}) {
|
|
|
1741
1837
|
for (const item of parsed) {
|
|
1742
1838
|
if (Array.isArray(item) && item.length >= 2) {
|
|
1743
1839
|
const key = String(item[0]).toUpperCase();
|
|
1744
|
-
if (key === "TOTAL")
|
|
1840
|
+
if (key === "TOTAL")
|
|
1841
|
+
total = typeof item[1] === "number" ? item[1] : 0;
|
|
1745
1842
|
else if (key === "DATA") {
|
|
1746
1843
|
if (Array.isArray(item[1]) && item[1].length > 0) {
|
|
1747
1844
|
tblData = item[1];
|
|
@@ -1760,16 +1857,19 @@ async function getTables(params = {}) {
|
|
|
1760
1857
|
} else {
|
|
1761
1858
|
const allData = {};
|
|
1762
1859
|
parsed.forEach((item) => {
|
|
1763
|
-
if (!Array.isArray(item) || item.length < 2)
|
|
1860
|
+
if (!Array.isArray(item) || item.length < 2)
|
|
1861
|
+
return;
|
|
1764
1862
|
let tableKey = null;
|
|
1765
1863
|
const entry = { total: 0, data: [] };
|
|
1766
1864
|
if (Array.isArray(item[0]) && item[0].length >= 2 && String(item[0][0]).toLowerCase() === "table") {
|
|
1767
1865
|
tableKey = String(item[0][1]).toLowerCase();
|
|
1768
1866
|
for (let i = 1; i < item.length; i++) {
|
|
1769
1867
|
const sub = item[i];
|
|
1770
|
-
if (!Array.isArray(sub) || sub.length < 2)
|
|
1868
|
+
if (!Array.isArray(sub) || sub.length < 2)
|
|
1869
|
+
continue;
|
|
1771
1870
|
const subKey = String(sub[0]).toUpperCase();
|
|
1772
|
-
if (subKey === "TOTAL")
|
|
1871
|
+
if (subKey === "TOTAL")
|
|
1872
|
+
entry.total = typeof sub[1] === "number" ? sub[1] : 0;
|
|
1773
1873
|
else if (subKey === "DATA") {
|
|
1774
1874
|
const raw = Array.isArray(sub[1]) ? sub[1] : sub.slice(1);
|
|
1775
1875
|
entry.data = raw.map((r) => parseTableRecord(r, tableKey)).filter(Boolean);
|
|
@@ -1779,7 +1879,8 @@ async function getTables(params = {}) {
|
|
|
1779
1879
|
tableKey = String(item[0]).toLowerCase();
|
|
1780
1880
|
for (let i = 1; i < item.length; i++) {
|
|
1781
1881
|
const sub = item[i];
|
|
1782
|
-
if (!Array.isArray(sub) || sub.length < 2)
|
|
1882
|
+
if (!Array.isArray(sub) || sub.length < 2)
|
|
1883
|
+
continue;
|
|
1783
1884
|
const subKey = String(sub[0]).toUpperCase();
|
|
1784
1885
|
if (subKey === "TOTAL") {
|
|
1785
1886
|
entry.total = typeof sub[1] === "number" ? sub[1] : 0;
|
|
@@ -1789,7 +1890,8 @@ async function getTables(params = {}) {
|
|
|
1789
1890
|
}
|
|
1790
1891
|
}
|
|
1791
1892
|
}
|
|
1792
|
-
if (tableKey)
|
|
1893
|
+
if (tableKey)
|
|
1894
|
+
allData[tableKey] = entry;
|
|
1793
1895
|
});
|
|
1794
1896
|
result = allData;
|
|
1795
1897
|
}
|
|
@@ -1803,9 +1905,12 @@ async function getTables(params = {}) {
|
|
|
1803
1905
|
async function getPackages(filterName = null) {
|
|
1804
1906
|
const cacheKey = filterName ? `packages:${filterName}` : "packages:all";
|
|
1805
1907
|
const cached = getCached(cacheKey);
|
|
1806
|
-
if (cached)
|
|
1807
|
-
|
|
1808
|
-
if (!cad.connected)
|
|
1908
|
+
if (cached)
|
|
1909
|
+
return cached;
|
|
1910
|
+
if (!cad.connected)
|
|
1911
|
+
await cad.connect();
|
|
1912
|
+
if (!cad.connected)
|
|
1913
|
+
return [];
|
|
1809
1914
|
try {
|
|
1810
1915
|
const code = `(mapcar 'cdr @::*local-pkgs*)`;
|
|
1811
1916
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -1818,7 +1923,8 @@ async function getPackages(filterName = null) {
|
|
|
1818
1923
|
} catch {
|
|
1819
1924
|
raw = parseLispList(result) || [];
|
|
1820
1925
|
}
|
|
1821
|
-
if (!Array.isArray(raw))
|
|
1926
|
+
if (!Array.isArray(raw))
|
|
1927
|
+
raw = [];
|
|
1822
1928
|
const packages = raw.map((item) => {
|
|
1823
1929
|
if (Array.isArray(item)) {
|
|
1824
1930
|
const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
|
|
@@ -1827,13 +1933,20 @@ async function getPackages(filterName = null) {
|
|
|
1827
1933
|
const [[key, val]] = Object.entries(entry);
|
|
1828
1934
|
const k = String(key);
|
|
1829
1935
|
const v = String(val);
|
|
1830
|
-
if (k === ":NAME")
|
|
1831
|
-
|
|
1832
|
-
else if (k === ":
|
|
1833
|
-
|
|
1834
|
-
else if (k === ":
|
|
1835
|
-
|
|
1836
|
-
else if (k === ":
|
|
1936
|
+
if (k === ":NAME")
|
|
1937
|
+
pkg.name = v;
|
|
1938
|
+
else if (k === ":VERSION")
|
|
1939
|
+
pkg.version = v;
|
|
1940
|
+
else if (k === ":DESCRIPTION")
|
|
1941
|
+
pkg.description = v;
|
|
1942
|
+
else if (k === ":FULL-NAME")
|
|
1943
|
+
pkg.fullName = v;
|
|
1944
|
+
else if (k === ":AUTHOR")
|
|
1945
|
+
pkg.author = v;
|
|
1946
|
+
else if (k === ":CATEGORY")
|
|
1947
|
+
pkg.category = v;
|
|
1948
|
+
else if (k === ":URL")
|
|
1949
|
+
pkg.url = v;
|
|
1837
1950
|
}
|
|
1838
1951
|
}
|
|
1839
1952
|
return pkg;
|
|
@@ -1844,15 +1957,22 @@ async function getPackages(filterName = null) {
|
|
|
1844
1957
|
if (item && typeof item === "object") {
|
|
1845
1958
|
const pkg = { name: "", version: "0.0.0", description: "", loaded: true };
|
|
1846
1959
|
const nameVal = item.name || item.Name || item.NAME || item[":NAME"];
|
|
1847
|
-
if (nameVal)
|
|
1960
|
+
if (nameVal)
|
|
1961
|
+
pkg.name = String(nameVal);
|
|
1848
1962
|
const verVal = item.version || item.Version || item.VERSION || item[":VERSION"];
|
|
1849
|
-
if (verVal)
|
|
1963
|
+
if (verVal)
|
|
1964
|
+
pkg.version = String(verVal);
|
|
1850
1965
|
const descVal = item.description || item.Description || item.DESCRIPTION || item[":DESCRIPTION"];
|
|
1851
|
-
if (descVal)
|
|
1852
|
-
|
|
1853
|
-
if (item.
|
|
1854
|
-
|
|
1855
|
-
if (item.
|
|
1966
|
+
if (descVal)
|
|
1967
|
+
pkg.description = String(descVal);
|
|
1968
|
+
if (item.fullName || item.full_name)
|
|
1969
|
+
pkg.fullName = String(item.fullName || item.full_name);
|
|
1970
|
+
if (item.author || item.Author)
|
|
1971
|
+
pkg.author = String(item.author || item.Author);
|
|
1972
|
+
if (item.category || item.Category)
|
|
1973
|
+
pkg.category = String(item.category || item.Category);
|
|
1974
|
+
if (item.url || item.Url || item.URL)
|
|
1975
|
+
pkg.url = String(item.url || item.Url || item.URL);
|
|
1856
1976
|
return pkg;
|
|
1857
1977
|
}
|
|
1858
1978
|
return null;
|
|
@@ -1877,9 +1997,12 @@ function getPlatforms() {
|
|
|
1877
1997
|
async function getDwgList() {
|
|
1878
1998
|
const cacheKey = "cad:dwgs";
|
|
1879
1999
|
const cached = getCached(cacheKey);
|
|
1880
|
-
if (cached)
|
|
1881
|
-
|
|
1882
|
-
if (!cad.connected)
|
|
2000
|
+
if (cached)
|
|
2001
|
+
return cached;
|
|
2002
|
+
if (!cad.connected)
|
|
2003
|
+
await cad.connect();
|
|
2004
|
+
if (!cad.connected)
|
|
2005
|
+
return [];
|
|
1883
2006
|
try {
|
|
1884
2007
|
const code = `(progn
|
|
1885
2008
|
(vl-load-com)
|
|
@@ -1902,7 +2025,8 @@ async function getDwgList() {
|
|
|
1902
2025
|
parsed = listResult;
|
|
1903
2026
|
}
|
|
1904
2027
|
}
|
|
1905
|
-
if (!Array.isArray(parsed))
|
|
2028
|
+
if (!Array.isArray(parsed))
|
|
2029
|
+
parsed = [];
|
|
1906
2030
|
const dwgList = parsed.map((item) => {
|
|
1907
2031
|
if (Array.isArray(item) && item.length >= 2) {
|
|
1908
2032
|
return { name: String(item[0]), path: String(item[1]) };
|
|
@@ -1928,7 +2052,8 @@ function loadStandardsFile(filename) {
|
|
|
1928
2052
|
var standardsCache = /* @__PURE__ */ new Map();
|
|
1929
2053
|
function getCachedStandards(key) {
|
|
1930
2054
|
const entry = standardsCache.get(key);
|
|
1931
|
-
if (entry && Date.now() - entry.timestamp < 3e4)
|
|
2055
|
+
if (entry && Date.now() - entry.timestamp < 3e4)
|
|
2056
|
+
return entry.data;
|
|
1932
2057
|
standardsCache.delete(key);
|
|
1933
2058
|
return null;
|
|
1934
2059
|
}
|
|
@@ -1937,40 +2062,49 @@ function setCachedStandards(key, data) {
|
|
|
1937
2062
|
}
|
|
1938
2063
|
function getDraftingStandards() {
|
|
1939
2064
|
const cached = getCachedStandards("drafting");
|
|
1940
|
-
if (cached)
|
|
2065
|
+
if (cached)
|
|
2066
|
+
return cached;
|
|
1941
2067
|
const data = loadStandardsFile("drafting.json");
|
|
1942
|
-
if (data)
|
|
2068
|
+
if (data)
|
|
2069
|
+
setCachedStandards("drafting", data);
|
|
1943
2070
|
return data || { error: "\u5236\u56FE\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
|
|
1944
2071
|
}
|
|
1945
2072
|
function getCodingStandards() {
|
|
1946
2073
|
const cached = getCachedStandards("coding");
|
|
1947
|
-
if (cached)
|
|
2074
|
+
if (cached)
|
|
2075
|
+
return cached;
|
|
1948
2076
|
const data = loadStandardsFile("coding.json");
|
|
1949
|
-
if (data)
|
|
2077
|
+
if (data)
|
|
2078
|
+
setCachedStandards("coding", data);
|
|
1950
2079
|
return data || { error: "\u7F16\u7801\u89C4\u8303\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25" };
|
|
1951
2080
|
}
|
|
1952
2081
|
|
|
1953
2082
|
// src/handlers/resource-handlers.js
|
|
1954
2083
|
function parseQuery(uri) {
|
|
1955
2084
|
const qIdx = uri.indexOf("?");
|
|
1956
|
-
if (qIdx === -1)
|
|
2085
|
+
if (qIdx === -1)
|
|
2086
|
+
return { base: uri, params: {} };
|
|
1957
2087
|
const base = uri.substring(0, qIdx);
|
|
1958
2088
|
const params = {};
|
|
1959
2089
|
uri.substring(qIdx + 1).split("&").forEach((p) => {
|
|
1960
2090
|
const eqIdx = p.indexOf("=");
|
|
1961
2091
|
const k = eqIdx === -1 ? p : p.substring(0, eqIdx);
|
|
1962
2092
|
const v = eqIdx === -1 ? "" : p.substring(eqIdx + 1);
|
|
1963
|
-
if (k)
|
|
2093
|
+
if (k)
|
|
2094
|
+
params[k] = decodeURIComponent(v);
|
|
1964
2095
|
});
|
|
1965
2096
|
return { base, params };
|
|
1966
2097
|
}
|
|
1967
2098
|
function parseTemplateUri(uri) {
|
|
1968
2099
|
const entityMatch = uri.match(/^atlisp:\/\/dwg\/entity\/([^?]+)$/);
|
|
1969
|
-
if (entityMatch)
|
|
2100
|
+
if (entityMatch)
|
|
2101
|
+
return { type: "entity", handle: entityMatch[1] };
|
|
1970
2102
|
const tblMatch = uri.match(/^atlisp:\/\/dwg\/tbl\/([^?]+)$/);
|
|
1971
|
-
if (tblMatch)
|
|
2103
|
+
if (tblMatch)
|
|
2104
|
+
return { type: "tbl", tblName: tblMatch[1] };
|
|
1972
2105
|
const blockRefMatch = uri.match(/^atlisp:\/\/dwg\/block-refs\/([^?]+)$/);
|
|
1973
|
-
if (blockRefMatch)
|
|
2106
|
+
if (blockRefMatch)
|
|
2107
|
+
return { type: "block-refs", blockName: blockRefMatch[1] };
|
|
1974
2108
|
return null;
|
|
1975
2109
|
}
|
|
1976
2110
|
async function listResources(subscribedUris = []) {
|
|
@@ -2130,8 +2264,10 @@ function isPrefixUri(uri) {
|
|
|
2130
2264
|
return uri.endsWith("/");
|
|
2131
2265
|
}
|
|
2132
2266
|
function matchesSubscription(subscribedUri, targetUri) {
|
|
2133
|
-
if (subscribedUri === targetUri)
|
|
2134
|
-
|
|
2267
|
+
if (subscribedUri === targetUri)
|
|
2268
|
+
return true;
|
|
2269
|
+
if (isPrefixUri(subscribedUri) && targetUri.startsWith(subscribedUri))
|
|
2270
|
+
return true;
|
|
2135
2271
|
return false;
|
|
2136
2272
|
}
|
|
2137
2273
|
function isSubscribed(uri, sessionId) {
|
|
@@ -2141,7 +2277,8 @@ function isSubscribed(uri, sessionId) {
|
|
|
2141
2277
|
}
|
|
2142
2278
|
const allUris = sessionManager.getAllSubscribedUris();
|
|
2143
2279
|
for (const su of allUris) {
|
|
2144
|
-
if (matchesSubscription(su, uri))
|
|
2280
|
+
if (matchesSubscription(su, uri))
|
|
2281
|
+
return true;
|
|
2145
2282
|
}
|
|
2146
2283
|
return false;
|
|
2147
2284
|
}
|
|
@@ -2250,9 +2387,11 @@ var SseSession = class {
|
|
|
2250
2387
|
return lines.join("\n") + "\n\n";
|
|
2251
2388
|
}
|
|
2252
2389
|
_setupDrain() {
|
|
2253
|
-
if (typeof this.#res.on !== "function")
|
|
2390
|
+
if (typeof this.#res.on !== "function")
|
|
2391
|
+
return;
|
|
2254
2392
|
this.#drainHandler = () => {
|
|
2255
|
-
if (!this.#active)
|
|
2393
|
+
if (!this.#active)
|
|
2394
|
+
return;
|
|
2256
2395
|
if (this.#backpressureBuffer.length > 0) {
|
|
2257
2396
|
this._drainBuffer();
|
|
2258
2397
|
}
|
|
@@ -2274,7 +2413,8 @@ var SseSession = class {
|
|
|
2274
2413
|
}
|
|
2275
2414
|
}
|
|
2276
2415
|
_write(content) {
|
|
2277
|
-
if (!this.#active)
|
|
2416
|
+
if (!this.#active)
|
|
2417
|
+
return false;
|
|
2278
2418
|
try {
|
|
2279
2419
|
if (this.#backpressureBuffer.length > 0) {
|
|
2280
2420
|
this.#backpressureBuffer.push(content);
|
|
@@ -2403,7 +2543,8 @@ function persistSessionData(clientId, sessionData) {
|
|
|
2403
2543
|
function loadPersistedSessionData(clientId) {
|
|
2404
2544
|
try {
|
|
2405
2545
|
const filePath = getSessionStorePath(clientId);
|
|
2406
|
-
if (!fs4.existsSync(filePath))
|
|
2546
|
+
if (!fs4.existsSync(filePath))
|
|
2547
|
+
return null;
|
|
2407
2548
|
const raw = fs4.readFileSync(filePath, "utf-8");
|
|
2408
2549
|
const store = JSON.parse(raw);
|
|
2409
2550
|
if (Date.now() - store.savedAt > SESSION_STORE_TTL) {
|
|
@@ -2467,7 +2608,8 @@ var SseSessionManager = class {
|
|
|
2467
2608
|
session.close();
|
|
2468
2609
|
this.#sessions.delete(clientId);
|
|
2469
2610
|
const idx = this.#accessOrder.indexOf(clientId);
|
|
2470
|
-
if (idx !== -1)
|
|
2611
|
+
if (idx !== -1)
|
|
2612
|
+
this.#accessOrder.splice(idx, 1);
|
|
2471
2613
|
return true;
|
|
2472
2614
|
}
|
|
2473
2615
|
return false;
|
|
@@ -2554,7 +2696,8 @@ var SseSessionManager = class {
|
|
|
2554
2696
|
session.close();
|
|
2555
2697
|
this.#sessions.delete(clientId);
|
|
2556
2698
|
const idx = this.#accessOrder.indexOf(clientId);
|
|
2557
|
-
if (idx !== -1)
|
|
2699
|
+
if (idx !== -1)
|
|
2700
|
+
this.#accessOrder.splice(idx, 1);
|
|
2558
2701
|
}
|
|
2559
2702
|
}
|
|
2560
2703
|
}
|
|
@@ -2602,7 +2745,8 @@ var SessionTransport = class {
|
|
|
2602
2745
|
this._started = true;
|
|
2603
2746
|
}
|
|
2604
2747
|
async send(message) {
|
|
2605
|
-
if (this._closed)
|
|
2748
|
+
if (this._closed)
|
|
2749
|
+
return;
|
|
2606
2750
|
if (this._pendingRequest) {
|
|
2607
2751
|
const { resolve, reject, timeout } = this._pendingRequest;
|
|
2608
2752
|
clearTimeout(timeout);
|
|
@@ -2611,7 +2755,8 @@ var SessionTransport = class {
|
|
|
2611
2755
|
}
|
|
2612
2756
|
}
|
|
2613
2757
|
async close() {
|
|
2614
|
-
if (this._closed)
|
|
2758
|
+
if (this._closed)
|
|
2759
|
+
return;
|
|
2615
2760
|
this._closed = true;
|
|
2616
2761
|
if (this._pendingRequest) {
|
|
2617
2762
|
const { reject, timeout } = this._pendingRequest;
|
|
@@ -2685,10 +2830,12 @@ var DEFS_DIR = path7.join(__dirname3, "definitions");
|
|
|
2685
2830
|
var PROMPTS_DIR = path7.join(__dirname3, "..", "..", "prompts");
|
|
2686
2831
|
var builtinDefs = null;
|
|
2687
2832
|
function loadBuiltinDefs() {
|
|
2688
|
-
if (builtinDefs)
|
|
2833
|
+
if (builtinDefs)
|
|
2834
|
+
return builtinDefs;
|
|
2689
2835
|
builtinDefs = {};
|
|
2690
2836
|
try {
|
|
2691
|
-
if (!fs5.existsSync(DEFS_DIR))
|
|
2837
|
+
if (!fs5.existsSync(DEFS_DIR))
|
|
2838
|
+
return builtinDefs;
|
|
2692
2839
|
const files = fs5.readdirSync(DEFS_DIR).filter((f) => f.endsWith(".json"));
|
|
2693
2840
|
for (const file of files) {
|
|
2694
2841
|
try {
|
|
@@ -2750,12 +2897,15 @@ function formatLispPoints(pointsStr) {
|
|
|
2750
2897
|
return `(list ${ptList.join(" ")})`;
|
|
2751
2898
|
}
|
|
2752
2899
|
function getDimensionStyleLisp(style) {
|
|
2753
|
-
if (style === "horizontal" || style === "vertical")
|
|
2900
|
+
if (style === "horizontal" || style === "vertical")
|
|
2901
|
+
return "DIMLINEAR";
|
|
2754
2902
|
return "DIMALIGNED";
|
|
2755
2903
|
}
|
|
2756
2904
|
function getDimensionStyleLabel(style) {
|
|
2757
|
-
if (style === "horizontal")
|
|
2758
|
-
|
|
2905
|
+
if (style === "horizontal")
|
|
2906
|
+
return "\u6C34\u5E73";
|
|
2907
|
+
if (style === "vertical")
|
|
2908
|
+
return "\u5782\u76F4";
|
|
2759
2909
|
return "aligned";
|
|
2760
2910
|
}
|
|
2761
2911
|
async function handleComplexPrompt(def, args) {
|
|
@@ -2789,10 +2939,14 @@ async function handleComplexPrompt(def, args) {
|
|
|
2789
2939
|
} catch {
|
|
2790
2940
|
}
|
|
2791
2941
|
const suggestions = [];
|
|
2792
|
-
if (entities.total > 1e3)
|
|
2793
|
-
|
|
2794
|
-
if (
|
|
2795
|
-
|
|
2942
|
+
if (entities.total > 1e3)
|
|
2943
|
+
suggestions.push("- \u56FE\u7EB8\u5B9E\u4F53\u8F83\u591A\uFF0C\u5EFA\u8BAE\u4F7F\u7528\u56FE\u5C42\u5206\u7C7B\u7BA1\u7406");
|
|
2944
|
+
if (layers.length > 20)
|
|
2945
|
+
suggestions.push("- \u56FE\u5C42\u8F83\u591A\uFF0C\u5EFA\u8BAE\u6E05\u7406\u672A\u4F7F\u7528\u7684\u56FE\u5C42");
|
|
2946
|
+
if (entities.byType.LINE && entities.byType.LINE > 500)
|
|
2947
|
+
suggestions.push("- \u7EBF\u6761\u8F83\u591A\uFF0C\u53EF\u8003\u8651\u4F7F\u7528 BLOCK \u51CF\u5C11\u5B9E\u4F53\u6570\u91CF");
|
|
2948
|
+
if (!entities.byType.DIMENSION)
|
|
2949
|
+
suggestions.push("- \u672A\u53D1\u73B0\u5C3A\u5BF8\u6807\u6CE8\uFF0C\u5EFA\u8BAE\u6DFB\u52A0\u6807\u6CE8");
|
|
2796
2950
|
return {
|
|
2797
2951
|
messages: [{
|
|
2798
2952
|
role: "user",
|
|
@@ -2985,7 +3139,8 @@ ${code}
|
|
|
2985
3139
|
}
|
|
2986
3140
|
const defs = loadBuiltinDefs();
|
|
2987
3141
|
const def = defs[name];
|
|
2988
|
-
if (!def)
|
|
3142
|
+
if (!def)
|
|
3143
|
+
throw new Error(`Unknown prompt: ${name}`);
|
|
2989
3144
|
if (def.handler) {
|
|
2990
3145
|
return handleComplexPrompt(def, args);
|
|
2991
3146
|
}
|
|
@@ -3010,7 +3165,8 @@ import path8 from "path";
|
|
|
3010
3165
|
init_config();
|
|
3011
3166
|
var MAX_HISTORY_VALUES = 1e3;
|
|
3012
3167
|
function percentile(sorted, p) {
|
|
3013
|
-
if (sorted.length === 0)
|
|
3168
|
+
if (sorted.length === 0)
|
|
3169
|
+
return 0;
|
|
3014
3170
|
const idx = Math.ceil(p * sorted.length) - 1;
|
|
3015
3171
|
return sorted[Math.max(0, Math.min(idx, sorted.length - 1))];
|
|
3016
3172
|
}
|
|
@@ -3301,7 +3457,8 @@ async function evalLisp(code, withResult = false, encoding = null) {
|
|
|
3301
3457
|
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3302
3458
|
}
|
|
3303
3459
|
const trimmed = (code || "").trim();
|
|
3304
|
-
if (!trimmed)
|
|
3460
|
+
if (!trimmed)
|
|
3461
|
+
return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3305
3462
|
try {
|
|
3306
3463
|
if (withResult) {
|
|
3307
3464
|
const result = await cad.sendCommandWithResult(trimmed, encoding);
|
|
@@ -3321,14 +3478,17 @@ async function getCadInfo2() {
|
|
|
3321
3478
|
if (!cad.connected) {
|
|
3322
3479
|
await cad.connect();
|
|
3323
3480
|
}
|
|
3324
|
-
if (!cad.connected)
|
|
3481
|
+
if (!cad.connected)
|
|
3482
|
+
return { content: [{ type: "text", text: "CAD \u672A\u8FDE\u63A5" }] };
|
|
3325
3483
|
const info = await cad.getInfo();
|
|
3326
3484
|
return { content: [{ type: "text", text: info }] };
|
|
3327
3485
|
}
|
|
3328
3486
|
async function atCommand(command) {
|
|
3329
|
-
if (!cad.connected)
|
|
3487
|
+
if (!cad.connected)
|
|
3488
|
+
return { content: [{ type: "text", text: "\u8BF7\u5148\u8FDE\u63A5 CAD" }], isError: true };
|
|
3330
3489
|
const trimmed = (command || "").trim();
|
|
3331
|
-
if (!trimmed)
|
|
3490
|
+
if (!trimmed)
|
|
3491
|
+
return { content: [{ type: "text", text: "\u547D\u4EE4\u4E3A\u7A7A\uFF0C\u672A\u53D1\u9001" }] };
|
|
3332
3492
|
await cad.sendCommand(trimmed + "\n");
|
|
3333
3493
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001\u547D\u4EE4" }] };
|
|
3334
3494
|
}
|
|
@@ -3336,7 +3496,8 @@ async function newDocument() {
|
|
|
3336
3496
|
if (!cad.connected) {
|
|
3337
3497
|
await cad.connect();
|
|
3338
3498
|
}
|
|
3339
|
-
if (!cad.connected)
|
|
3499
|
+
if (!cad.connected)
|
|
3500
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3340
3501
|
const result = await cad.newDoc();
|
|
3341
3502
|
if (result) {
|
|
3342
3503
|
return { content: [{ type: "text", text: "\u5DF2\u5728 CAD \u4E2D\u65B0\u5EFA\u7A7A\u767D\u6587\u6863" }] };
|
|
@@ -3347,7 +3508,8 @@ async function bringToFront() {
|
|
|
3347
3508
|
if (!cad.connected) {
|
|
3348
3509
|
await cad.connect();
|
|
3349
3510
|
}
|
|
3350
|
-
if (!cad.connected)
|
|
3511
|
+
if (!cad.connected)
|
|
3512
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3351
3513
|
const result = await cad.bringToFront();
|
|
3352
3514
|
if (result) {
|
|
3353
3515
|
return { content: [{ type: "text", text: "\u5DF2\u5C06 CAD \u7A97\u53E3\u5207\u6362\u5230\u524D\u53F0" }] };
|
|
@@ -3358,7 +3520,8 @@ async function installAtlisp() {
|
|
|
3358
3520
|
if (!cad.connected) {
|
|
3359
3521
|
await cad.connect();
|
|
3360
3522
|
}
|
|
3361
|
-
if (!cad.connected)
|
|
3523
|
+
if (!cad.connected)
|
|
3524
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3362
3525
|
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))))`;
|
|
3363
3526
|
await cad.sendCommand(installCode + "\n");
|
|
3364
3527
|
return { content: [{ type: "text", text: "\u5DF2\u53D1\u9001 @lisp \u5B89\u88C5\u4EE3\u7801\u5230 CAD" }] };
|
|
@@ -3367,10 +3530,12 @@ async function listFunctionsInCad() {
|
|
|
3367
3530
|
if (!cad.connected) {
|
|
3368
3531
|
await cad.connect();
|
|
3369
3532
|
}
|
|
3370
|
-
if (!cad.connected)
|
|
3533
|
+
if (!cad.connected)
|
|
3534
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3371
3535
|
try {
|
|
3372
3536
|
const result = await cad.sendCommandWithResult("(atoms-family 0)", null);
|
|
3373
|
-
if (result)
|
|
3537
|
+
if (result)
|
|
3538
|
+
return { content: [{ type: "text", text: result }] };
|
|
3374
3539
|
return { content: [{ type: "text", text: "CAD \u51FD\u6570\u5217\u8868\u4E3A\u7A7A" }] };
|
|
3375
3540
|
} catch (e) {
|
|
3376
3541
|
return { content: [{ type: "text", text: `\u9519\u8BEF: ${e.message}` }], isError: true };
|
|
@@ -3427,7 +3592,8 @@ async function initAtlisp() {
|
|
|
3427
3592
|
if (!cad.connected) {
|
|
3428
3593
|
await cad.connect();
|
|
3429
3594
|
}
|
|
3430
|
-
if (!cad.connected)
|
|
3595
|
+
if (!cad.connected)
|
|
3596
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3431
3597
|
const code = `(if (null @::load-module)
|
|
3432
3598
|
(progn
|
|
3433
3599
|
(vl-load-com)
|
|
@@ -3469,12 +3635,15 @@ async function fetchPackages() {
|
|
|
3469
3635
|
return cachedPackages || MOCK_PACKAGES;
|
|
3470
3636
|
}
|
|
3471
3637
|
function flattenPackages(data) {
|
|
3472
|
-
if (Array.isArray(data))
|
|
3473
|
-
|
|
3638
|
+
if (Array.isArray(data))
|
|
3639
|
+
return data;
|
|
3640
|
+
if (data && Array.isArray(data.packages))
|
|
3641
|
+
return data.packages;
|
|
3474
3642
|
return [];
|
|
3475
3643
|
}
|
|
3476
3644
|
async function listPackages() {
|
|
3477
|
-
if (!cad.connected)
|
|
3645
|
+
if (!cad.connected)
|
|
3646
|
+
await cad.connect();
|
|
3478
3647
|
if (!cad.connected) {
|
|
3479
3648
|
const data2 = await fetchPackages();
|
|
3480
3649
|
const items2 = flattenPackages(data2);
|
|
@@ -3482,7 +3651,8 @@ async function listPackages() {
|
|
|
3482
3651
|
return { content: [{ type: "text", text: text2 }] };
|
|
3483
3652
|
}
|
|
3484
3653
|
const result = await cad.sendCommandWithResult("(@::package-list-in-local)");
|
|
3485
|
-
if (result && result !== "nil")
|
|
3654
|
+
if (result && result !== "nil")
|
|
3655
|
+
return { content: [{ type: "text", text: result }] };
|
|
3486
3656
|
const data = await fetchPackages();
|
|
3487
3657
|
const items = flattenPackages(data);
|
|
3488
3658
|
const text = items.length ? `\u4ECE\u6CE8\u518C\u8868\u83B7\u53D6\u7684 @lisp \u5305:
|
|
@@ -3502,10 +3672,12 @@ async function searchPackages(query) {
|
|
|
3502
3672
|
for (const p of items) {
|
|
3503
3673
|
const name = (p.name || "").toLowerCase();
|
|
3504
3674
|
const desc = (p.description || "").toLowerCase();
|
|
3505
|
-
if (name.includes(q) || desc.includes(q))
|
|
3675
|
+
if (name.includes(q) || desc.includes(q))
|
|
3676
|
+
results.push(p);
|
|
3506
3677
|
}
|
|
3507
3678
|
} else {
|
|
3508
|
-
for (const p of items)
|
|
3679
|
+
for (const p of items)
|
|
3680
|
+
results.push(p);
|
|
3509
3681
|
}
|
|
3510
3682
|
if (results.length === 0) {
|
|
3511
3683
|
return { content: [{ type: "text", text: `\u672A\u627E\u5230\u5305\u542B "${query}" \u7684\u5305` }] };
|
|
@@ -3594,7 +3766,8 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
3594
3766
|
if (data) {
|
|
3595
3767
|
const funcs = Object.values(data.all_functions || {});
|
|
3596
3768
|
const func = funcs.find((f2) => f2.name === funcName || f2.name === `${packageName}:${funcName}`);
|
|
3597
|
-
if (func)
|
|
3769
|
+
if (func)
|
|
3770
|
+
results.push(func);
|
|
3598
3771
|
}
|
|
3599
3772
|
if (results.length === 0 && FUNCTIONS_DIR) {
|
|
3600
3773
|
try {
|
|
@@ -3603,7 +3776,8 @@ async function getFunctionUsage(funcName, packageName) {
|
|
|
3603
3776
|
const raw = fs6.readFileSync(path9.join(FUNCTIONS_DIR, file), "utf-8");
|
|
3604
3777
|
const data2 = JSON.parse(raw);
|
|
3605
3778
|
const func = data2.functions?.find((f2) => f2.name === funcName);
|
|
3606
|
-
if (func)
|
|
3779
|
+
if (func)
|
|
3780
|
+
results.push(func);
|
|
3607
3781
|
}
|
|
3608
3782
|
} catch (e) {
|
|
3609
3783
|
log(`function-handlers: FUNCTIONS_DIR read error: ${e.message}`);
|
|
@@ -3673,7 +3847,8 @@ async function getEntity(handle) {
|
|
|
3673
3847
|
if (!cad.connected) {
|
|
3674
3848
|
await cad.connect();
|
|
3675
3849
|
}
|
|
3676
|
-
if (!cad.connected)
|
|
3850
|
+
if (!cad.connected)
|
|
3851
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3677
3852
|
const code = `(progn
|
|
3678
3853
|
(vl-load-com)
|
|
3679
3854
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -3705,7 +3880,8 @@ async function setEntityProperty(handle, property, value) {
|
|
|
3705
3880
|
if (!cad.connected) {
|
|
3706
3881
|
await cad.connect();
|
|
3707
3882
|
}
|
|
3708
|
-
if (!cad.connected)
|
|
3883
|
+
if (!cad.connected)
|
|
3884
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3709
3885
|
let propCode = "";
|
|
3710
3886
|
switch (property) {
|
|
3711
3887
|
case "layer":
|
|
@@ -3748,7 +3924,8 @@ async function deleteEntity(handle) {
|
|
|
3748
3924
|
if (!cad.connected) {
|
|
3749
3925
|
await cad.connect();
|
|
3750
3926
|
}
|
|
3751
|
-
if (!cad.connected)
|
|
3927
|
+
if (!cad.connected)
|
|
3928
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3752
3929
|
const code = `(progn
|
|
3753
3930
|
(vl-load-com)
|
|
3754
3931
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -3773,12 +3950,15 @@ async function selectEntities(filter) {
|
|
|
3773
3950
|
if (!cad.connected) {
|
|
3774
3951
|
await cad.connect();
|
|
3775
3952
|
}
|
|
3776
|
-
if (!cad.connected)
|
|
3953
|
+
if (!cad.connected)
|
|
3954
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3777
3955
|
let filterCode = "nil";
|
|
3778
3956
|
if (filter && (filter.type || filter.layer)) {
|
|
3779
3957
|
const items = [];
|
|
3780
|
-
if (filter.type)
|
|
3781
|
-
|
|
3958
|
+
if (filter.type)
|
|
3959
|
+
items.push(`'(0 . "${escapeLispString(filter.type)}")`);
|
|
3960
|
+
if (filter.layer)
|
|
3961
|
+
items.push(`'(8 . "${escapeLispString(filter.layer)}")`);
|
|
3782
3962
|
filterCode = `(list ${items.join(" ")})`;
|
|
3783
3963
|
}
|
|
3784
3964
|
const code = `(progn
|
|
@@ -3811,7 +3991,8 @@ async function createLayer(name, color = 7, linetype = "Continuous") {
|
|
|
3811
3991
|
if (!cad.connected) {
|
|
3812
3992
|
await cad.connect();
|
|
3813
3993
|
}
|
|
3814
|
-
if (!cad.connected)
|
|
3994
|
+
if (!cad.connected)
|
|
3995
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3815
3996
|
const code = `(progn
|
|
3816
3997
|
(vl-load-com)
|
|
3817
3998
|
(if (not (tblsearch "LAYER" "${escapeLispString(name)}"))
|
|
@@ -3847,7 +4028,8 @@ async function deleteLayer(name) {
|
|
|
3847
4028
|
if (!cad.connected) {
|
|
3848
4029
|
await cad.connect();
|
|
3849
4030
|
}
|
|
3850
|
-
if (!cad.connected)
|
|
4031
|
+
if (!cad.connected)
|
|
4032
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3851
4033
|
const code = `(progn
|
|
3852
4034
|
(vl-load-com)
|
|
3853
4035
|
(cond
|
|
@@ -3881,7 +4063,8 @@ async function setLayerProperty(name, property, value) {
|
|
|
3881
4063
|
if (!cad.connected) {
|
|
3882
4064
|
await cad.connect();
|
|
3883
4065
|
}
|
|
3884
|
-
if (!cad.connected)
|
|
4066
|
+
if (!cad.connected)
|
|
4067
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3885
4068
|
let propCode = "";
|
|
3886
4069
|
switch (property) {
|
|
3887
4070
|
case "color":
|
|
@@ -3929,7 +4112,8 @@ async function setCurrentLayer(name) {
|
|
|
3929
4112
|
if (!cad.connected) {
|
|
3930
4113
|
await cad.connect();
|
|
3931
4114
|
}
|
|
3932
|
-
if (!cad.connected)
|
|
4115
|
+
if (!cad.connected)
|
|
4116
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3933
4117
|
const code = `(progn
|
|
3934
4118
|
(vl-load-com)
|
|
3935
4119
|
(if (tblsearch "LAYER" "${escapeLispString(name)}")
|
|
@@ -3957,7 +4141,8 @@ async function createBlock(name, entities) {
|
|
|
3957
4141
|
if (!cad.connected) {
|
|
3958
4142
|
await cad.connect();
|
|
3959
4143
|
}
|
|
3960
|
-
if (!cad.connected)
|
|
4144
|
+
if (!cad.connected)
|
|
4145
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3961
4146
|
const code = `(progn
|
|
3962
4147
|
(vl-load-com)
|
|
3963
4148
|
(if (not (tblsearch "BLOCK" "${escapeLispString(name)}"))
|
|
@@ -3994,7 +4179,8 @@ async function insertBlock(blockName, point, scale = 1, rotation = 0) {
|
|
|
3994
4179
|
if (!cad.connected) {
|
|
3995
4180
|
await cad.connect();
|
|
3996
4181
|
}
|
|
3997
|
-
if (!cad.connected)
|
|
4182
|
+
if (!cad.connected)
|
|
4183
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
3998
4184
|
const coords = Array.isArray(point) ? point : point.split(",").map((s) => parseFloat(s.trim()));
|
|
3999
4185
|
if (coords.length < 2) {
|
|
4000
4186
|
return { content: [{ type: "text", text: "\u63D2\u5165\u70B9\u683C\u5F0F\u9519\u8BEF\uFF0C\u9700\u8981 x,y \u6216 [x,y,z]" }], isError: true };
|
|
@@ -4024,7 +4210,8 @@ async function getBlocks() {
|
|
|
4024
4210
|
if (!cad.connected) {
|
|
4025
4211
|
await cad.connect();
|
|
4026
4212
|
}
|
|
4027
|
-
if (!cad.connected)
|
|
4213
|
+
if (!cad.connected)
|
|
4214
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4028
4215
|
const code = `(progn
|
|
4029
4216
|
(vl-load-com)
|
|
4030
4217
|
(setq blocks nil)
|
|
@@ -4047,7 +4234,8 @@ async function explodeBlock(handle) {
|
|
|
4047
4234
|
if (!cad.connected) {
|
|
4048
4235
|
await cad.connect();
|
|
4049
4236
|
}
|
|
4050
|
-
if (!cad.connected)
|
|
4237
|
+
if (!cad.connected)
|
|
4238
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4051
4239
|
const code = `(progn
|
|
4052
4240
|
(vl-load-com)
|
|
4053
4241
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -4083,7 +4271,8 @@ async function openDwg(filePath) {
|
|
|
4083
4271
|
if (!cad.connected) {
|
|
4084
4272
|
await cad.connect();
|
|
4085
4273
|
}
|
|
4086
|
-
if (!cad.connected)
|
|
4274
|
+
if (!cad.connected)
|
|
4275
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4087
4276
|
try {
|
|
4088
4277
|
validateFilePath(filePath);
|
|
4089
4278
|
} catch (e) {
|
|
@@ -4124,7 +4313,8 @@ async function saveDwg(filePath = null) {
|
|
|
4124
4313
|
if (!cad.connected) {
|
|
4125
4314
|
await cad.connect();
|
|
4126
4315
|
}
|
|
4127
|
-
if (!cad.connected)
|
|
4316
|
+
if (!cad.connected)
|
|
4317
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4128
4318
|
if (filePath) {
|
|
4129
4319
|
try {
|
|
4130
4320
|
validateFilePath(filePath);
|
|
@@ -4155,7 +4345,8 @@ async function exportPdf(outputPath, layout = "Model") {
|
|
|
4155
4345
|
if (!cad.connected) {
|
|
4156
4346
|
await cad.connect();
|
|
4157
4347
|
}
|
|
4158
|
-
if (!cad.connected)
|
|
4348
|
+
if (!cad.connected)
|
|
4349
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4159
4350
|
try {
|
|
4160
4351
|
validateFilePath(outputPath);
|
|
4161
4352
|
} catch (e) {
|
|
@@ -4187,7 +4378,8 @@ async function closeDwg(save = false) {
|
|
|
4187
4378
|
if (!cad.connected) {
|
|
4188
4379
|
await cad.connect();
|
|
4189
4380
|
}
|
|
4190
|
-
if (!cad.connected)
|
|
4381
|
+
if (!cad.connected)
|
|
4382
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4191
4383
|
const code = `(progn
|
|
4192
4384
|
(vl-load-com)
|
|
4193
4385
|
(if ${save ? "T" : "nil"}
|
|
@@ -4214,7 +4406,8 @@ async function createDimension(type, points, style = {}) {
|
|
|
4214
4406
|
if (!cad.connected) {
|
|
4215
4407
|
await cad.connect();
|
|
4216
4408
|
}
|
|
4217
|
-
if (!cad.connected)
|
|
4409
|
+
if (!cad.connected)
|
|
4410
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4218
4411
|
let dimCode = "";
|
|
4219
4412
|
const validTypes = ["ALIGNED", "LINEAR", "ORDINATE", "RADIAL", "DIAMETER", "ANGULAR"];
|
|
4220
4413
|
const dimType = (type || "ALIGNED").toUpperCase();
|
|
@@ -4256,7 +4449,8 @@ async function getDimensionValue(handle) {
|
|
|
4256
4449
|
if (!cad.connected) {
|
|
4257
4450
|
await cad.connect();
|
|
4258
4451
|
}
|
|
4259
|
-
if (!cad.connected)
|
|
4452
|
+
if (!cad.connected)
|
|
4453
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4260
4454
|
const code = `(progn
|
|
4261
4455
|
(vl-load-com)
|
|
4262
4456
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -4287,7 +4481,8 @@ async function createHatch(patternName, boundary, scale = 1, angle = 0) {
|
|
|
4287
4481
|
if (!cad.connected) {
|
|
4288
4482
|
await cad.connect();
|
|
4289
4483
|
}
|
|
4290
|
-
if (!cad.connected)
|
|
4484
|
+
if (!cad.connected)
|
|
4485
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4291
4486
|
const code = `(progn
|
|
4292
4487
|
(vl-load-com)
|
|
4293
4488
|
(command "._BHATCH" "p" "${escapeLispString(patternName)}" "s" "s" "sc" ${scale} "an" ${angle} "")
|
|
@@ -4307,12 +4502,17 @@ async function setHatchProperties(handle, props) {
|
|
|
4307
4502
|
if (!cad.connected) {
|
|
4308
4503
|
await cad.connect();
|
|
4309
4504
|
}
|
|
4310
|
-
if (!cad.connected)
|
|
4505
|
+
if (!cad.connected)
|
|
4506
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4311
4507
|
let propCode = "";
|
|
4312
|
-
if (props.pattern)
|
|
4313
|
-
|
|
4314
|
-
if (props.
|
|
4315
|
-
|
|
4508
|
+
if (props.pattern)
|
|
4509
|
+
propCode += `(command "._HATCHEDIT" "${escapeLispString(handle)}" "p" "${escapeLispString(props.pattern)}")`;
|
|
4510
|
+
if (props.scale)
|
|
4511
|
+
propCode += `(command "._HATCHEDIT" "${escapeLispString(handle)}" "s" ${parseFloat(props.scale) || 1})`;
|
|
4512
|
+
if (props.angle)
|
|
4513
|
+
propCode += `(command "._HATCHEDIT" "${escapeLispString(handle)}" "an" ${parseFloat(props.angle) || 0})`;
|
|
4514
|
+
if (props.color)
|
|
4515
|
+
propCode += `(command "._HATCHEDIT" "${escapeLispString(handle)}" "c" ${parseInt(props.color) || 256})`;
|
|
4316
4516
|
const code = `(progn
|
|
4317
4517
|
(vl-load-com)
|
|
4318
4518
|
${propCode}
|
|
@@ -4329,7 +4529,8 @@ async function getBlockAttributes(blockHandle) {
|
|
|
4329
4529
|
if (!cad.connected) {
|
|
4330
4530
|
await cad.connect();
|
|
4331
4531
|
}
|
|
4332
|
-
if (!cad.connected)
|
|
4532
|
+
if (!cad.connected)
|
|
4533
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4333
4534
|
const code = `(progn
|
|
4334
4535
|
(vl-load-com)
|
|
4335
4536
|
(if (setq ent (handent "${escapeLispString(blockHandle)}"))
|
|
@@ -4358,7 +4559,8 @@ async function setBlockAttribute(blockHandle, tag, value) {
|
|
|
4358
4559
|
if (!cad.connected) {
|
|
4359
4560
|
await cad.connect();
|
|
4360
4561
|
}
|
|
4361
|
-
if (!cad.connected)
|
|
4562
|
+
if (!cad.connected)
|
|
4563
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4362
4564
|
const code = `(progn
|
|
4363
4565
|
(vl-load-com)
|
|
4364
4566
|
(if (setq ent (handent "${escapeLispString(blockHandle)}"))
|
|
@@ -4394,7 +4596,8 @@ async function zoomToExtents() {
|
|
|
4394
4596
|
if (!cad.connected) {
|
|
4395
4597
|
await cad.connect();
|
|
4396
4598
|
}
|
|
4397
|
-
if (!cad.connected)
|
|
4599
|
+
if (!cad.connected)
|
|
4600
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4398
4601
|
const code = `(progn
|
|
4399
4602
|
(vl-load-com)
|
|
4400
4603
|
(command "._ZOOM" "E")
|
|
@@ -4411,7 +4614,8 @@ async function zoomToWindow(p1, p2) {
|
|
|
4411
4614
|
if (!cad.connected) {
|
|
4412
4615
|
await cad.connect();
|
|
4413
4616
|
}
|
|
4414
|
-
if (!cad.connected)
|
|
4617
|
+
if (!cad.connected)
|
|
4618
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4415
4619
|
const code = `(command "._ZOOM" "W" (list ${toSafePoint(p1)}) (list ${toSafePoint(p2)}))`;
|
|
4416
4620
|
try {
|
|
4417
4621
|
await cad.sendCommand(code + "\n");
|
|
@@ -4424,7 +4628,8 @@ async function createNamedView(viewName, center = null) {
|
|
|
4424
4628
|
if (!cad.connected) {
|
|
4425
4629
|
await cad.connect();
|
|
4426
4630
|
}
|
|
4427
|
-
if (!cad.connected)
|
|
4631
|
+
if (!cad.connected)
|
|
4632
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4428
4633
|
const code = center ? `(command ".-VIEW" "S" "${escapeLispString(viewName)}" "C" (list ${toSafePoint(center)}))` : `(command ".-VIEW" "S" "${escapeLispString(viewName)}")`;
|
|
4429
4634
|
try {
|
|
4430
4635
|
await cad.sendCommand(code + "\n");
|
|
@@ -4437,7 +4642,8 @@ async function restoreNamedView(viewName) {
|
|
|
4437
4642
|
if (!cad.connected) {
|
|
4438
4643
|
await cad.connect();
|
|
4439
4644
|
}
|
|
4440
|
-
if (!cad.connected)
|
|
4645
|
+
if (!cad.connected)
|
|
4646
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4441
4647
|
const code = `(command ".-VIEW" "R" "${escapeLispString(viewName)}")`;
|
|
4442
4648
|
try {
|
|
4443
4649
|
await cad.sendCommand(code + "\n");
|
|
@@ -4450,7 +4656,8 @@ async function listNamedViews() {
|
|
|
4450
4656
|
if (!cad.connected) {
|
|
4451
4657
|
await cad.connect();
|
|
4452
4658
|
}
|
|
4453
|
-
if (!cad.connected)
|
|
4659
|
+
if (!cad.connected)
|
|
4660
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4454
4661
|
const code = `(progn
|
|
4455
4662
|
(vl-load-com)
|
|
4456
4663
|
(setq views nil)
|
|
@@ -4470,7 +4677,8 @@ async function exportDxf(outputPath, version2 = "R2018") {
|
|
|
4470
4677
|
if (!cad.connected) {
|
|
4471
4678
|
await cad.connect();
|
|
4472
4679
|
}
|
|
4473
|
-
if (!cad.connected)
|
|
4680
|
+
if (!cad.connected)
|
|
4681
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4474
4682
|
const versionMap = {
|
|
4475
4683
|
"R2018": "AC1027",
|
|
4476
4684
|
"R2015": "AC1024",
|
|
@@ -4500,7 +4708,8 @@ async function exportDwf(outputPath) {
|
|
|
4500
4708
|
if (!cad.connected) {
|
|
4501
4709
|
await cad.connect();
|
|
4502
4710
|
}
|
|
4503
|
-
if (!cad.connected)
|
|
4711
|
+
if (!cad.connected)
|
|
4712
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4504
4713
|
const code = `(progn
|
|
4505
4714
|
(vl-load-com)
|
|
4506
4715
|
(vla-export (vla-get-activedocument (vlax-get-acad-object)) "${escapeLispString(outputPath)}" "dwf")
|
|
@@ -4520,7 +4729,8 @@ async function batchSetLayer(handles, layerName) {
|
|
|
4520
4729
|
if (!cad.connected) {
|
|
4521
4730
|
await cad.connect();
|
|
4522
4731
|
}
|
|
4523
|
-
if (!cad.connected)
|
|
4732
|
+
if (!cad.connected)
|
|
4733
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4524
4734
|
if (!Array.isArray(handles) || handles.length === 0) {
|
|
4525
4735
|
return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
|
|
4526
4736
|
}
|
|
@@ -4550,7 +4760,8 @@ async function createUcs(name, origin = "0,0,0", xAxis = "1,0,0", yAxis = "0,1,0
|
|
|
4550
4760
|
if (!cad.connected) {
|
|
4551
4761
|
await cad.connect();
|
|
4552
4762
|
}
|
|
4553
|
-
if (!cad.connected)
|
|
4763
|
+
if (!cad.connected)
|
|
4764
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4554
4765
|
const code = `(progn
|
|
4555
4766
|
(vl-load-com)
|
|
4556
4767
|
(if (not (tblsearch "UCS" "${escapeLispString(name)}"))
|
|
@@ -4581,7 +4792,8 @@ async function setUcs(name) {
|
|
|
4581
4792
|
if (!cad.connected) {
|
|
4582
4793
|
await cad.connect();
|
|
4583
4794
|
}
|
|
4584
|
-
if (!cad.connected)
|
|
4795
|
+
if (!cad.connected)
|
|
4796
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4585
4797
|
const code = `(progn
|
|
4586
4798
|
(vl-load-com)
|
|
4587
4799
|
(if (tblsearch "UCS" "${escapeLispString(name)}")
|
|
@@ -4606,7 +4818,8 @@ async function listUcs() {
|
|
|
4606
4818
|
if (!cad.connected) {
|
|
4607
4819
|
await cad.connect();
|
|
4608
4820
|
}
|
|
4609
|
-
if (!cad.connected)
|
|
4821
|
+
if (!cad.connected)
|
|
4822
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4610
4823
|
const code = `(progn
|
|
4611
4824
|
(vl-load-com)
|
|
4612
4825
|
(setq ucsList nil)
|
|
@@ -4629,7 +4842,8 @@ async function deleteUcs(name) {
|
|
|
4629
4842
|
if (!cad.connected) {
|
|
4630
4843
|
await cad.connect();
|
|
4631
4844
|
}
|
|
4632
|
-
if (!cad.connected)
|
|
4845
|
+
if (!cad.connected)
|
|
4846
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4633
4847
|
const code = `(progn
|
|
4634
4848
|
(vl-load-com)
|
|
4635
4849
|
(if (tblsearch "UCS" "${escapeLispString(name)}")
|
|
@@ -4654,7 +4868,8 @@ async function getCurrentUcs() {
|
|
|
4654
4868
|
if (!cad.connected) {
|
|
4655
4869
|
await cad.connect();
|
|
4656
4870
|
}
|
|
4657
|
-
if (!cad.connected)
|
|
4871
|
+
if (!cad.connected)
|
|
4872
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4658
4873
|
const code = `(progn
|
|
4659
4874
|
(vl-load-com)
|
|
4660
4875
|
(vla-get-activeutilities (vla-get-document (vla-get-application (vlax-get-acad-object))))
|
|
@@ -4671,7 +4886,8 @@ async function createLayout(name) {
|
|
|
4671
4886
|
if (!cad.connected) {
|
|
4672
4887
|
await cad.connect();
|
|
4673
4888
|
}
|
|
4674
|
-
if (!cad.connected)
|
|
4889
|
+
if (!cad.connected)
|
|
4890
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4675
4891
|
const code = `(progn
|
|
4676
4892
|
(vl-load-com)
|
|
4677
4893
|
(if (not (tblsearch "LAYOUT" "${escapeLispString(name)}"))
|
|
@@ -4699,7 +4915,8 @@ async function setLayout(name) {
|
|
|
4699
4915
|
if (!cad.connected) {
|
|
4700
4916
|
await cad.connect();
|
|
4701
4917
|
}
|
|
4702
|
-
if (!cad.connected)
|
|
4918
|
+
if (!cad.connected)
|
|
4919
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4703
4920
|
const code = `(progn
|
|
4704
4921
|
(vl-load-com)
|
|
4705
4922
|
(vlax-for layout (vla-get-layouts (vla-get-activedocument (vla-get-application (vlax-get-acad-object))))
|
|
@@ -4729,7 +4946,8 @@ async function listLayouts() {
|
|
|
4729
4946
|
if (!cad.connected) {
|
|
4730
4947
|
await cad.connect();
|
|
4731
4948
|
}
|
|
4732
|
-
if (!cad.connected)
|
|
4949
|
+
if (!cad.connected)
|
|
4950
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4733
4951
|
const code = `(progn
|
|
4734
4952
|
(vl-load-com)
|
|
4735
4953
|
(setq layouts nil)
|
|
@@ -4752,7 +4970,8 @@ async function deleteLayout(name) {
|
|
|
4752
4970
|
if (!cad.connected) {
|
|
4753
4971
|
await cad.connect();
|
|
4754
4972
|
}
|
|
4755
|
-
if (!cad.connected)
|
|
4973
|
+
if (!cad.connected)
|
|
4974
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4756
4975
|
if (name === "Model" || name === "\u6A21\u578B") {
|
|
4757
4976
|
return { content: [{ type: "text", text: "\u65E0\u6CD5\u5220\u9664\u6A21\u578B\u7A7A\u95F4" }], isError: true };
|
|
4758
4977
|
}
|
|
@@ -4780,7 +4999,8 @@ async function getCurrentLayout() {
|
|
|
4780
4999
|
if (!cad.connected) {
|
|
4781
5000
|
await cad.connect();
|
|
4782
5001
|
}
|
|
4783
|
-
if (!cad.connected)
|
|
5002
|
+
if (!cad.connected)
|
|
5003
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4784
5004
|
const code = `(vl-prin1-to-string (getvar "CTAB"))`;
|
|
4785
5005
|
try {
|
|
4786
5006
|
const result = await cad.sendCommandWithResult(code);
|
|
@@ -4793,7 +5013,8 @@ async function renameLayout(oldName, newName) {
|
|
|
4793
5013
|
if (!cad.connected) {
|
|
4794
5014
|
await cad.connect();
|
|
4795
5015
|
}
|
|
4796
|
-
if (!cad.connected)
|
|
5016
|
+
if (!cad.connected)
|
|
5017
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4797
5018
|
const code = `(progn
|
|
4798
5019
|
(vl-load-com)
|
|
4799
5020
|
(if (tblsearch "LAYOUT" "${escapeLispString(oldName)}")
|
|
@@ -4825,7 +5046,8 @@ async function plotToPdf(outputPath, layout = "Model", style = {}) {
|
|
|
4825
5046
|
if (!cad.connected) {
|
|
4826
5047
|
await cad.connect();
|
|
4827
5048
|
}
|
|
4828
|
-
if (!cad.connected)
|
|
5049
|
+
if (!cad.connected)
|
|
5050
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4829
5051
|
const paperSize = style.paperSize || "A4";
|
|
4830
5052
|
const code = `(progn
|
|
4831
5053
|
(vl-load-com)
|
|
@@ -4855,7 +5077,8 @@ async function plotToPrinter(printerName, layout = "Model") {
|
|
|
4855
5077
|
if (!cad.connected) {
|
|
4856
5078
|
await cad.connect();
|
|
4857
5079
|
}
|
|
4858
|
-
if (!cad.connected)
|
|
5080
|
+
if (!cad.connected)
|
|
5081
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4859
5082
|
const code = `(progn
|
|
4860
5083
|
(vl-load-com)
|
|
4861
5084
|
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
|
|
@@ -4881,7 +5104,8 @@ async function createGroup(name, handles) {
|
|
|
4881
5104
|
if (!cad.connected) {
|
|
4882
5105
|
await cad.connect();
|
|
4883
5106
|
}
|
|
4884
|
-
if (!cad.connected)
|
|
5107
|
+
if (!cad.connected)
|
|
5108
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4885
5109
|
if (!Array.isArray(handles) || handles.length === 0) {
|
|
4886
5110
|
return { content: [{ type: "text", text: "\u53E5\u67C4\u5217\u8868\u4E3A\u7A7A" }], isError: true };
|
|
4887
5111
|
}
|
|
@@ -4907,7 +5131,8 @@ async function deleteGroup(name) {
|
|
|
4907
5131
|
if (!cad.connected) {
|
|
4908
5132
|
await cad.connect();
|
|
4909
5133
|
}
|
|
4910
|
-
if (!cad.connected)
|
|
5134
|
+
if (!cad.connected)
|
|
5135
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4911
5136
|
const code = `(progn
|
|
4912
5137
|
(vl-load-com)
|
|
4913
5138
|
(if (tblsearch "GROUP" "${escapeLispString(name)}")
|
|
@@ -4932,7 +5157,8 @@ async function listGroups() {
|
|
|
4932
5157
|
if (!cad.connected) {
|
|
4933
5158
|
await cad.connect();
|
|
4934
5159
|
}
|
|
4935
|
-
if (!cad.connected)
|
|
5160
|
+
if (!cad.connected)
|
|
5161
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4936
5162
|
const code = `(progn
|
|
4937
5163
|
(vl-load-com)
|
|
4938
5164
|
(setq groups nil)
|
|
@@ -4952,7 +5178,8 @@ async function getGroupEntities(groupName) {
|
|
|
4952
5178
|
if (!cad.connected) {
|
|
4953
5179
|
await cad.connect();
|
|
4954
5180
|
}
|
|
4955
|
-
if (!cad.connected)
|
|
5181
|
+
if (!cad.connected)
|
|
5182
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4956
5183
|
const code = `(progn
|
|
4957
5184
|
(vl-load-com)
|
|
4958
5185
|
(if (tblsearch "GROUP" "${escapeLispString(groupName)}")
|
|
@@ -4990,15 +5217,16 @@ async function measureDistance(p1, p2) {
|
|
|
4990
5217
|
if (!cad.connected) {
|
|
4991
5218
|
await cad.connect();
|
|
4992
5219
|
}
|
|
4993
|
-
if (!cad.connected)
|
|
5220
|
+
if (!cad.connected)
|
|
5221
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
4994
5222
|
const code = `(progn
|
|
4995
5223
|
(vl-load-com)
|
|
4996
5224
|
(setq pt1 (list ${toSafePoint3(p1)}) pt2 (list ${toSafePoint3(p2)}))
|
|
4997
5225
|
(setq dist (distance pt1 pt2))
|
|
4998
|
-
(setq
|
|
5226
|
+
(setq ang (angle pt1 pt2))
|
|
4999
5227
|
(list
|
|
5000
5228
|
(strcat "Distance: " (rtos dist 2 4))
|
|
5001
|
-
(strcat "Angle: " (rtos (* 180 (/
|
|
5229
|
+
(strcat "Angle: " (rtos (* 180 (/ ang pi)) 2 2) "\xB0")
|
|
5002
5230
|
(strcat "DX: " (rtos (- (car pt2) (car pt1)) 2 4))
|
|
5003
5231
|
(strcat "DY: " (rtos (- (cadr pt2) (cadr pt1)) 2 4))
|
|
5004
5232
|
)
|
|
@@ -5014,7 +5242,8 @@ async function measureArea(points) {
|
|
|
5014
5242
|
if (!cad.connected) {
|
|
5015
5243
|
await cad.connect();
|
|
5016
5244
|
}
|
|
5017
|
-
if (!cad.connected)
|
|
5245
|
+
if (!cad.connected)
|
|
5246
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
5018
5247
|
const pts = Array.isArray(points) ? points : points.split(/[\s,]+/).filter(Boolean);
|
|
5019
5248
|
if (pts.length < 3) {
|
|
5020
5249
|
return { content: [{ type: "text", text: "\u81F3\u5C11\u9700\u8981 3 \u4E2A\u70B9" }], isError: true };
|
|
@@ -5051,7 +5280,8 @@ async function getEntityInfo(handle) {
|
|
|
5051
5280
|
if (!cad.connected) {
|
|
5052
5281
|
await cad.connect();
|
|
5053
5282
|
}
|
|
5054
|
-
if (!cad.connected)
|
|
5283
|
+
if (!cad.connected)
|
|
5284
|
+
return { content: [{ type: "text", text: "\u672A\u8FDE\u63A5 CAD" }], isError: true };
|
|
5055
5285
|
const code = `(progn
|
|
5056
5286
|
(vl-load-com)
|
|
5057
5287
|
(if (setq ent (handent "${escapeLispString(handle)}"))
|
|
@@ -5091,7 +5321,8 @@ function parseHandleList(handles) {
|
|
|
5091
5321
|
handles = handles.split(",").map((h) => h.trim());
|
|
5092
5322
|
}
|
|
5093
5323
|
}
|
|
5094
|
-
if (!Array.isArray(handles))
|
|
5324
|
+
if (!Array.isArray(handles))
|
|
5325
|
+
handles = [handles];
|
|
5095
5326
|
return handles;
|
|
5096
5327
|
}
|
|
5097
5328
|
async function batchRename(handles, newNameTemplate, startNum = 1) {
|
|
@@ -5465,7 +5696,8 @@ async function copyXdata(sourceHandle, targetHandle, appName = null) {
|
|
|
5465
5696
|
const xdataResult = await getXdata(sourceHandle, appName);
|
|
5466
5697
|
if (xdataResult.content?.[0]) {
|
|
5467
5698
|
const parsed = JSON.parse(xdataResult.content[0].text);
|
|
5468
|
-
if (parsed.xdata)
|
|
5699
|
+
if (parsed.xdata)
|
|
5700
|
+
return await setXdata(targetHandle, appName, parsed.xdata);
|
|
5469
5701
|
}
|
|
5470
5702
|
return mcpError("\u6E90\u5B9E\u4F53\u672A\u627E\u5230\u6269\u5C55\u6570\u636E");
|
|
5471
5703
|
} else {
|
|
@@ -5700,8 +5932,10 @@ async function createSheetSetArchive(sheetSetName, archivePath) {
|
|
|
5700
5932
|
// src/handlers/3d-handlers.js
|
|
5701
5933
|
init_cad();
|
|
5702
5934
|
function parsePoint(point) {
|
|
5703
|
-
if (Array.isArray(point))
|
|
5704
|
-
|
|
5935
|
+
if (Array.isArray(point))
|
|
5936
|
+
return point.join(" ");
|
|
5937
|
+
if (typeof point === "string")
|
|
5938
|
+
return point;
|
|
5705
5939
|
return "0,0,0";
|
|
5706
5940
|
}
|
|
5707
5941
|
async function createBox(center, length, width, height) {
|
|
@@ -8173,7 +8407,8 @@ function validateToolArgs(name, args) {
|
|
|
8173
8407
|
const baseType = type.replace("?", "");
|
|
8174
8408
|
const val = args[key];
|
|
8175
8409
|
if (val === void 0 || val === null) {
|
|
8176
|
-
if (isOptional)
|
|
8410
|
+
if (isOptional)
|
|
8411
|
+
continue;
|
|
8177
8412
|
throw new Error(`Missing required argument: ${key}`);
|
|
8178
8413
|
}
|
|
8179
8414
|
const actualType = typeof args[key];
|
|
@@ -8218,7 +8453,8 @@ ${CAD_PLATFORMS.join("\n")}
|
|
|
8218
8453
|
},
|
|
8219
8454
|
import_funlib: async (a) => {
|
|
8220
8455
|
const data = await loadAtlibFunctionLib();
|
|
8221
|
-
if (!data)
|
|
8456
|
+
if (!data)
|
|
8457
|
+
return { content: [{ type: "text", text: "\u52A0\u8F7D\u51FD\u6570\u5E93\u5931\u8D25" }], isError: true };
|
|
8222
8458
|
if (a.format === "list") {
|
|
8223
8459
|
const items = Object.values(data.all_functions || {}).map((f) => `${f.name}: ${f.description || ""}`);
|
|
8224
8460
|
return { content: [{ type: "text", text: items.join("\n") }] };
|
|
@@ -8428,7 +8664,8 @@ function notifyResourceChanges(toolName) {
|
|
|
8428
8664
|
}
|
|
8429
8665
|
async function handleToolCall(name, args) {
|
|
8430
8666
|
const handler = TOOL_HANDLERS[name];
|
|
8431
|
-
if (!handler)
|
|
8667
|
+
if (!handler)
|
|
8668
|
+
return { content: [{ type: "text", text: `\u672A\u77E5\u5DE5\u5177: ${name}` }], isError: true };
|
|
8432
8669
|
try {
|
|
8433
8670
|
validateToolArgs(name, args || {});
|
|
8434
8671
|
const result = await handler(args || {});
|
|
@@ -8489,10 +8726,12 @@ var RateLimiter = class {
|
|
|
8489
8726
|
this.keyLimits = /* @__PURE__ */ new Map();
|
|
8490
8727
|
}
|
|
8491
8728
|
getKeyLimit(apiKey2) {
|
|
8492
|
-
if (!apiKey2)
|
|
8729
|
+
if (!apiKey2)
|
|
8730
|
+
return this.defaultLimit;
|
|
8493
8731
|
if (config_default.apiKeys && config_default.apiKeys.length > 0) {
|
|
8494
8732
|
const found = config_default.apiKeys.find((k) => k.key === apiKey2);
|
|
8495
|
-
if (found)
|
|
8733
|
+
if (found)
|
|
8734
|
+
return found.limit;
|
|
8496
8735
|
}
|
|
8497
8736
|
if (config_default.apiKey && apiKey2 === config_default.apiKey) {
|
|
8498
8737
|
return config_default.apiKeyRateLimit || 1e3;
|
|
@@ -8500,10 +8739,12 @@ var RateLimiter = class {
|
|
|
8500
8739
|
return this.defaultLimit;
|
|
8501
8740
|
}
|
|
8502
8741
|
getKeyInfo(apiKey2) {
|
|
8503
|
-
if (!apiKey2)
|
|
8742
|
+
if (!apiKey2)
|
|
8743
|
+
return { name: "anonymous", limit: this.defaultLimit };
|
|
8504
8744
|
if (config_default.apiKeys && config_default.apiKeys.length > 0) {
|
|
8505
8745
|
const found = config_default.apiKeys.find((k) => k.key === apiKey2);
|
|
8506
|
-
if (found)
|
|
8746
|
+
if (found)
|
|
8747
|
+
return { name: found.name || apiKey2, limit: found.limit };
|
|
8507
8748
|
}
|
|
8508
8749
|
if (config_default.apiKey && apiKey2 === config_default.apiKey) {
|
|
8509
8750
|
return { name: "admin", limit: config_default.apiKeyRateLimit || 1e3 };
|
|
@@ -8599,7 +8840,8 @@ var JSON_CONTENT_TYPES = ["application/json", "application/json-rpc", "applicati
|
|
|
8599
8840
|
function createJsonBodyParser() {
|
|
8600
8841
|
return async (req, res, next) => {
|
|
8601
8842
|
const ct = (req.headers["content-type"] || "").toLowerCase();
|
|
8602
|
-
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
|
|
8843
|
+
if (!JSON_CONTENT_TYPES.some((t) => ct.startsWith(t)))
|
|
8844
|
+
return next();
|
|
8603
8845
|
try {
|
|
8604
8846
|
const chunks = [];
|
|
8605
8847
|
for await (const chunk of req) {
|
|
@@ -8632,9 +8874,11 @@ function createAuthMiddleware() {
|
|
|
8632
8874
|
const PUBLIC_PATHS = ["/health"];
|
|
8633
8875
|
return (req, res, next) => {
|
|
8634
8876
|
if (apiKey) {
|
|
8635
|
-
if (PUBLIC_PATHS.includes(req.path))
|
|
8877
|
+
if (PUBLIC_PATHS.includes(req.path))
|
|
8878
|
+
return next();
|
|
8636
8879
|
const auth = req.get("Authorization");
|
|
8637
|
-
if (auth === `Bearer ${apiKey}`)
|
|
8880
|
+
if (auth === `Bearer ${apiKey}`)
|
|
8881
|
+
return next();
|
|
8638
8882
|
return res.status(401).json({ error: "Unauthorized" });
|
|
8639
8883
|
}
|
|
8640
8884
|
next();
|
|
@@ -8642,14 +8886,16 @@ function createAuthMiddleware() {
|
|
|
8642
8886
|
}
|
|
8643
8887
|
function createCorsMiddleware() {
|
|
8644
8888
|
return (req, res, next) => {
|
|
8645
|
-
if (!enableCors)
|
|
8889
|
+
if (!enableCors)
|
|
8890
|
+
return next();
|
|
8646
8891
|
res.setHeader("Access-Control-Allow-Origin", corsOrigin);
|
|
8647
8892
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, CONNECT");
|
|
8648
8893
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, mcp-session-id, last-event-id");
|
|
8649
8894
|
res.setHeader("Access-Control-Expose-Headers", "mcp-session-id, content-type, x-accel-buffering");
|
|
8650
8895
|
res.setHeader("Access-Control-Max-Age", "86400");
|
|
8651
8896
|
res.setHeader("Vary", "Accept");
|
|
8652
|
-
if (req.method === "OPTIONS")
|
|
8897
|
+
if (req.method === "OPTIONS")
|
|
8898
|
+
return res.status(204).end();
|
|
8653
8899
|
next();
|
|
8654
8900
|
};
|
|
8655
8901
|
}
|
|
@@ -9066,7 +9312,8 @@ For more info: https://atlisp.cn
|
|
|
9066
9312
|
}
|
|
9067
9313
|
}
|
|
9068
9314
|
}
|
|
9069
|
-
if (config_default.apiKey)
|
|
9315
|
+
if (config_default.apiKey)
|
|
9316
|
+
log("API Key authentication enabled");
|
|
9070
9317
|
async function initCadConnection() {
|
|
9071
9318
|
log("Attempting to connect to CAD on startup...");
|
|
9072
9319
|
try {
|
|
@@ -9131,8 +9378,10 @@ async function startServer() {
|
|
|
9131
9378
|
await cad.disconnect();
|
|
9132
9379
|
closeLog();
|
|
9133
9380
|
httpServer.close(() => {
|
|
9134
|
-
if (httpsServer)
|
|
9135
|
-
|
|
9381
|
+
if (httpsServer)
|
|
9382
|
+
httpsServer.close(() => process.exit(0));
|
|
9383
|
+
else
|
|
9384
|
+
process.exit(0);
|
|
9136
9385
|
});
|
|
9137
9386
|
setTimeout(() => process.exit(1), 5e3);
|
|
9138
9387
|
}
|