@lark-apaas/devtool-kits 1.2.15 → 1.2.16-beta.0

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/index.js CHANGED
@@ -1220,11 +1220,8 @@ async function parseAndGenerateNestResourceTemplate(options) {
1220
1220
  __name(parseAndGenerateNestResourceTemplate, "parseAndGenerateNestResourceTemplate");
1221
1221
 
1222
1222
  // src/helpers/proxy-error/index.ts
1223
- import fs3 from "fs";
1224
- import path3 from "path";
1225
- import http from "http";
1226
- import https from "https";
1227
- var errorHtmlTemplate = null;
1223
+ import * as http from "http";
1224
+ import * as https from "https";
1228
1225
  function isConnectionError(err) {
1229
1226
  const code = err.code;
1230
1227
  const connectionErrorCodes = [
@@ -1237,7 +1234,7 @@ function isConnectionError(err) {
1237
1234
  return connectionErrorCodes.includes(code || "");
1238
1235
  }
1239
1236
  __name(isConnectionError, "isConnectionError");
1240
- function checkServiceAvailable(targetUrl, timeout = 1e3) {
1237
+ function checkServiceAvailable(targetUrl, timeout = 2e3) {
1241
1238
  return new Promise((resolve) => {
1242
1239
  try {
1243
1240
  const url = new URL(targetUrl);
@@ -1250,8 +1247,7 @@ function checkServiceAvailable(targetUrl, timeout = 1e3) {
1250
1247
  method: "HEAD",
1251
1248
  timeout
1252
1249
  }, (res) => {
1253
- const available = res.statusCode !== 502 && !res.headers["x-proxy-error-page"];
1254
- resolve(available);
1250
+ resolve(res.statusCode !== 502);
1255
1251
  });
1256
1252
  req.on("timeout", () => {
1257
1253
  req.destroy();
@@ -1261,7 +1257,7 @@ function checkServiceAvailable(targetUrl, timeout = 1e3) {
1261
1257
  resolve(false);
1262
1258
  });
1263
1259
  req.end();
1264
- } catch (e) {
1260
+ } catch {
1265
1261
  resolve(false);
1266
1262
  }
1267
1263
  });
@@ -1279,218 +1275,85 @@ async function waitForServiceRecovery(targetUrl, timeout, interval) {
1279
1275
  return false;
1280
1276
  }
1281
1277
  __name(waitForServiceRecovery, "waitForServiceRecovery");
1282
- function getDirname() {
1283
- return __dirname;
1284
- }
1285
- __name(getDirname, "getDirname");
1286
- function getErrorHtmlTemplate() {
1287
- if (!errorHtmlTemplate) {
1288
- const dirname = getDirname();
1289
- const htmlPath = path3.join(dirname, "error.html");
1290
- errorHtmlTemplate = fs3.readFileSync(htmlPath, "utf-8");
1291
- }
1292
- return errorHtmlTemplate;
1293
- }
1294
- __name(getErrorHtmlTemplate, "getErrorHtmlTemplate");
1295
- function parseLogLine(line) {
1296
- const trimmed = line.trim();
1297
- if (!trimmed) return null;
1298
- const match = trimmed.match(/^\[\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\]\s+\[server\]\s+(.*)$/);
1299
- if (match) {
1300
- const content = match[1].trim();
1301
- return content || null;
1302
- }
1303
- return null;
1304
- }
1305
- __name(parseLogLine, "parseLogLine");
1306
- async function readRecentErrorLogs(logDir, maxLogs, fileName) {
1307
- const logFilePath = path3.join(logDir, fileName);
1308
- let fileStats;
1309
- try {
1310
- fileStats = await fs3.promises.stat(logFilePath);
1311
- } catch {
1312
- return {
1313
- logs: [],
1314
- hasCompileError: false
1315
- };
1316
- }
1317
- const fileSize = fileStats.size;
1318
- const maxReadSize = 1024 * 1024;
1319
- const readSize = Math.min(fileSize, maxReadSize);
1320
- const startPosition = Math.max(0, fileSize - readSize);
1321
- const buffer = Buffer.allocUnsafe(readSize);
1322
- let fileHandle;
1323
- try {
1324
- fileHandle = await fs3.promises.open(logFilePath, "r");
1325
- await fileHandle.read(buffer, 0, readSize, startPosition);
1326
- } catch (error) {
1327
- console.error("[Proxy Error]: Failed to read log file:", error);
1328
- return {
1329
- logs: [],
1330
- hasCompileError: false
1331
- };
1332
- } finally {
1333
- if (fileHandle) {
1334
- await fileHandle.close();
1335
- }
1336
- }
1337
- const content = buffer.toString("utf8");
1338
- const lines = content.split("\n");
1339
- if (startPosition > 0 && lines.length > 0) {
1340
- lines.shift();
1341
- }
1342
- const allLines = [];
1343
- for (const line of lines) {
1344
- const parsed = parseLogLine(line);
1345
- if (parsed !== null) {
1346
- allLines.push(parsed);
1347
- }
1348
- }
1349
- let startIndex = -1;
1350
- for (let i = allLines.length - 1; i >= 0; i--) {
1351
- const line = allLines[i];
1352
- if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
1353
- startIndex = i;
1354
- break;
1355
- }
1356
- }
1357
- if (startIndex === -1) {
1358
- console.log("[Proxy Error]: No compilation start marker found, returning last logs");
1359
- const fallbackLogs = allLines.slice(-maxLogs);
1360
- const hasCompileError2 = checkForErrors(fallbackLogs);
1361
- return {
1362
- logs: fallbackLogs,
1363
- hasCompileError: hasCompileError2
1364
- };
1365
- }
1366
- let endIndex = allLines.length;
1367
- for (let i = startIndex + 1; i < allLines.length; i++) {
1368
- const line = allLines[i];
1369
- if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
1370
- endIndex = i;
1371
- break;
1372
- }
1373
- }
1374
- const errorSection = allLines.slice(startIndex, endIndex);
1375
- const hasCompileError = checkForErrors(errorSection);
1376
- const logs = errorSection.length > maxLogs ? errorSection.slice(-maxLogs) : errorSection;
1377
- return {
1378
- logs,
1379
- hasCompileError
1380
- };
1381
- }
1382
- __name(readRecentErrorLogs, "readRecentErrorLogs");
1383
- function checkForErrors(logs) {
1384
- for (const line of logs) {
1385
- const compileErrorMatch = line.match(/Found (\d+) errors?\. Watching for file changes/);
1386
- if (compileErrorMatch) {
1387
- const errorCount = parseInt(compileErrorMatch[1], 10);
1388
- if (errorCount > 0) {
1389
- console.log(`[Proxy Error]: Found ${errorCount} compilation error(s)`);
1390
- return true;
1391
- }
1392
- }
1393
- }
1394
- return false;
1278
+ function send502Json(res) {
1279
+ if (res.headersSent) return;
1280
+ res.writeHead(502, {
1281
+ "Content-Type": "application/json; charset=utf-8",
1282
+ "Cache-Control": "no-cache, no-store, must-revalidate"
1283
+ });
1284
+ res.end(JSON.stringify({
1285
+ error: "Bad Gateway",
1286
+ message: "Backend service is temporarily unavailable"
1287
+ }));
1395
1288
  }
1396
- __name(checkForErrors, "checkForErrors");
1397
- function injectTemplateData(template, clientBasePath, parentOrigin) {
1398
- return template.replace("{{.clientBasePath}}", clientBasePath).replace("{{.parentOrigin}}", parentOrigin);
1289
+ __name(send502Json, "send502Json");
1290
+ function sendRedirect(req, res) {
1291
+ if (res.headersSent) return;
1292
+ const originalUrl = req.url || "/";
1293
+ console.log("[Proxy] Service recovered, redirecting to", originalUrl);
1294
+ res.writeHead(302, {
1295
+ "Location": originalUrl,
1296
+ "Cache-Control": "no-cache, no-store, must-revalidate"
1297
+ });
1298
+ res.end();
1399
1299
  }
1400
- __name(injectTemplateData, "injectTemplateData");
1300
+ __name(sendRedirect, "sendRedirect");
1401
1301
  function handleDevProxyError(err, req, res, options) {
1402
- const { logDir = path3.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}`, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
1403
- const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
1404
- console.error("[Proxy Error]:", err.message, clientBasePathWithoutSlash);
1302
+ const { retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}` } = options || {};
1303
+ console.error("[Proxy] Error:", err.message);
1405
1304
  if (res.headersSent) {
1406
- console.error("[Proxy Error]: Headers already sent, cannot send error page");
1305
+ console.error("[Proxy] Headers already sent, cannot handle error");
1306
+ return;
1307
+ }
1308
+ if (!isConnectionError(err)) {
1309
+ console.log("[Proxy] Non-connection error, returning 502");
1310
+ send502Json(res);
1407
1311
  return;
1408
1312
  }
1313
+ console.log("[Proxy] Connection error, waiting for service recovery...");
1409
1314
  (async () => {
1410
1315
  try {
1411
- const isConnError = isConnectionError(err);
1412
- const { hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
1413
- if (isConnError && !hasCompileError) {
1414
- console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
1415
- try {
1416
- new URL(target);
1417
- } catch (e) {
1418
- console.error("[Proxy Error]: Invalid target URL:", target);
1419
- console.log("[Proxy Error]: Showing error page due to invalid target");
1420
- }
1421
- console.log(`[Proxy Error]: Waiting for service recovery at ${target} (timeout: ${retryTimeout}ms)...`);
1422
- const recovered = await waitForServiceRecovery(target, retryTimeout, retryInterval);
1423
- if (recovered) {
1424
- console.log("[Proxy Error]: Service recovered within timeout, sending 302 redirect");
1425
- sendSimpleRedirect(req, res);
1426
- return;
1427
- }
1428
- console.log("[Proxy Error]: Service did not recover within timeout, showing error page with probe");
1429
- }
1430
- if (isConnError && !hasCompileError) {
1431
- console.log("[Proxy Error]: Showing error page with auto-refresh probe");
1316
+ const recovered = await waitForServiceRecovery(target, retryTimeout, retryInterval);
1317
+ if (recovered) {
1318
+ sendRedirect(req, res);
1432
1319
  } else {
1433
- console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
1320
+ console.log("[Proxy] Service did not recover within timeout, returning 502");
1321
+ send502Json(res);
1434
1322
  }
1435
- const template = getErrorHtmlTemplate();
1436
- const parentOrigin = process.env.FORCE_FRAMEWORK_DOMAIN_MAIN || "";
1437
- const html = injectTemplateData(template, clientBasePathWithoutSlash, parentOrigin);
1438
- res.writeHead(200, {
1439
- "Content-Type": "text/html; charset=utf-8",
1440
- "Cache-Control": "no-cache, no-store, must-revalidate",
1441
- "X-Proxy-Error-Page": "true"
1442
- });
1443
- res.end(html);
1444
1323
  } catch (error) {
1445
- console.error("[Proxy Error]: Failed to handle error:", error);
1446
- if (!res.headersSent) {
1447
- res.writeHead(502, {
1448
- "Content-Type": "text/plain; charset=utf-8"
1449
- });
1450
- res.end(`Node \u670D\u52A1\u542F\u52A8\u5F02\u5E38\uFF0C\u8BF7\u6839\u636E\u65E5\u5FD7\u4FEE\u590D\u76F8\u5173\u95EE\u9898`);
1451
- }
1324
+ console.error("[Proxy] Error during recovery wait:", error);
1325
+ send502Json(res);
1452
1326
  }
1453
1327
  })();
1454
1328
  }
1455
1329
  __name(handleDevProxyError, "handleDevProxyError");
1456
- function sendSimpleRedirect(req, res) {
1457
- if (res.headersSent) return;
1458
- const originalUrl = req.url || "/";
1459
- console.log("[Proxy Error]: Sending 302 redirect to", originalUrl);
1460
- res.writeHead(302, {
1461
- "Location": originalUrl,
1462
- "Cache-Control": "no-cache, no-store, must-revalidate"
1463
- });
1464
- res.end();
1465
- }
1466
- __name(sendSimpleRedirect, "sendSimpleRedirect");
1467
1330
 
1468
1331
  // src/middlewares/index.ts
1469
- import path7 from "path";
1332
+ import path6 from "path";
1470
1333
 
1471
1334
  // src/middlewares/openapi/router.ts
1472
1335
  import express from "express";
1473
1336
 
1474
1337
  // src/middlewares/openapi/controller.ts
1475
- import fs6 from "fs/promises";
1338
+ import fs5 from "fs/promises";
1476
1339
  import crypto from "crypto";
1477
1340
 
1478
1341
  // src/middlewares/openapi/services.ts
1479
- import { promises as fs5 } from "fs";
1480
- import path5 from "path";
1342
+ import { promises as fs4 } from "fs";
1343
+ import path4 from "path";
1481
1344
  import ts from "typescript";
1482
1345
 
1483
1346
  // src/middlewares/openapi/utils.ts
1484
- import path4 from "path";
1485
- import { promises as fs4 } from "fs";
1347
+ import path3 from "path";
1348
+ import { promises as fs3 } from "fs";
1486
1349
  async function findControllerFiles(dir) {
1487
1350
  const files = [];
1488
1351
  async function scan(currentDir) {
1489
- const entries = await fs4.readdir(currentDir, {
1352
+ const entries = await fs3.readdir(currentDir, {
1490
1353
  withFileTypes: true
1491
1354
  });
1492
1355
  for (const entry of entries) {
1493
- const fullPath = path4.join(currentDir, entry.name);
1356
+ const fullPath = path3.join(currentDir, entry.name);
1494
1357
  if (entry.isDirectory()) {
1495
1358
  await scan(fullPath);
1496
1359
  } else if (entry.isFile() && entry.name.endsWith(".controller.ts")) {
@@ -1582,21 +1445,21 @@ __name(transformOpenapiPaths, "transformOpenapiPaths");
1582
1445
  // src/middlewares/openapi/services.ts
1583
1446
  async function enhanceOpenApiWithSourceInfo(options = {}) {
1584
1447
  const startTime = Date.now();
1585
- const openapiPath = options.openapiPath || path5.resolve(__dirname, "../client/src/api/gen/openapi.json");
1586
- const serverDir = options.serverDir || path5.resolve(__dirname, "../server");
1448
+ const openapiPath = options.openapiPath || path4.resolve(__dirname, "../client/src/api/gen/openapi.json");
1449
+ const serverDir = options.serverDir || path4.resolve(__dirname, "../server");
1587
1450
  const writeFile2 = options.writeFile !== false;
1588
1451
  let openapi;
1589
1452
  if (options.openapiData) {
1590
1453
  openapi = JSON.parse(JSON.stringify(options.openapiData));
1591
1454
  } else {
1592
- const openapiContent = await fs5.readFile(openapiPath, "utf-8");
1455
+ const openapiContent = await fs4.readFile(openapiPath, "utf-8");
1593
1456
  openapi = JSON.parse(openapiContent);
1594
1457
  }
1595
1458
  const controllerFiles = await findControllerFiles(serverDir);
1596
1459
  const sourceMap = await buildSourceMap(controllerFiles, processControllerFile);
1597
1460
  const enhanced = enhanceOpenApiPaths(openapi, sourceMap);
1598
1461
  if (writeFile2) {
1599
- await fs5.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
1462
+ await fs4.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
1600
1463
  }
1601
1464
  const duration = Date.now() - startTime;
1602
1465
  return {
@@ -1611,8 +1474,8 @@ async function enhanceOpenApiWithSourceInfo(options = {}) {
1611
1474
  }
1612
1475
  __name(enhanceOpenApiWithSourceInfo, "enhanceOpenApiWithSourceInfo");
1613
1476
  async function processControllerFile(filePath) {
1614
- const relativePath = path5.relative(process.cwd(), filePath);
1615
- const content = await fs5.readFile(filePath, "utf-8");
1477
+ const relativePath = path4.relative(process.cwd(), filePath);
1478
+ const content = await fs4.readFile(filePath, "utf-8");
1616
1479
  const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
1617
1480
  return extractControllerMetadata(sourceFile, relativePath);
1618
1481
  }
@@ -1705,7 +1568,7 @@ function createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir) {
1705
1568
  let cache = null;
1706
1569
  return async (_req, res, context) => {
1707
1570
  try {
1708
- const fileBuffer = await fs6.readFile(openapiFilePath, "utf-8");
1571
+ const fileBuffer = await fs5.readFile(openapiFilePath, "utf-8");
1709
1572
  const currentHash = crypto.createHash("md5").update(fileBuffer).digest("hex");
1710
1573
  if (cache && cache.fileHash === currentHash) {
1711
1574
  return res.json(cache.data);
@@ -1777,7 +1640,7 @@ __name(createOpenapiMiddleware, "createOpenapiMiddleware");
1777
1640
  import express2 from "express";
1778
1641
 
1779
1642
  // src/middlewares/dev-logs/utils.ts
1780
- import { promises as fs7 } from "fs";
1643
+ import { promises as fs6 } from "fs";
1781
1644
  import { isAbsolute, join as join2, relative } from "path";
1782
1645
 
1783
1646
  // src/middlewares/dev-logs/helper/path-matcher.ts
@@ -1810,8 +1673,8 @@ function hasSpecialPatterns(pattern) {
1810
1673
  return /[{*]/.test(pattern);
1811
1674
  }
1812
1675
  __name(hasSpecialPatterns, "hasSpecialPatterns");
1813
- function normalizePathForMatching(path8) {
1814
- return path8.replace(/\/+/g, "/").replace(/\/+$/, "");
1676
+ function normalizePathForMatching(path7) {
1677
+ return path7.replace(/\/+/g, "/").replace(/\/+$/, "");
1815
1678
  }
1816
1679
  __name(normalizePathForMatching, "normalizePathForMatching");
1817
1680
 
@@ -1829,14 +1692,14 @@ function getRelativePath(filePath) {
1829
1692
  __name(getRelativePath, "getRelativePath");
1830
1693
  async function fileExists(filePath) {
1831
1694
  try {
1832
- await fs7.access(filePath);
1695
+ await fs6.access(filePath);
1833
1696
  return true;
1834
1697
  } catch {
1835
1698
  return false;
1836
1699
  }
1837
1700
  }
1838
1701
  __name(fileExists, "fileExists");
1839
- function parseLogLine2(line) {
1702
+ function parseLogLine(line) {
1840
1703
  const trimmed = line.trim();
1841
1704
  if (!trimmed) return void 0;
1842
1705
  try {
@@ -1845,7 +1708,7 @@ function parseLogLine2(line) {
1845
1708
  return void 0;
1846
1709
  }
1847
1710
  }
1848
- __name(parseLogLine2, "parseLogLine");
1711
+ __name(parseLogLine, "parseLogLine");
1849
1712
  function extractNumber(message, pattern) {
1850
1713
  if (typeof message !== "string") return void 0;
1851
1714
  const match = message.match(pattern);
@@ -1912,9 +1775,9 @@ __name(serializeError, "serializeError");
1912
1775
  import { join as join4 } from "path";
1913
1776
 
1914
1777
  // src/middlewares/dev-logs/services/file-reader.ts
1915
- import { promises as fs8 } from "fs";
1778
+ import { promises as fs7 } from "fs";
1916
1779
  async function readFileReverse(filePath, chunkSize, processLine) {
1917
- const handle = await fs8.open(filePath, "r");
1780
+ const handle = await fs7.open(filePath, "r");
1918
1781
  try {
1919
1782
  const stats = await handle.stat();
1920
1783
  let position = stats.size;
@@ -2112,7 +1975,7 @@ async function readLogEntriesByTrace(filePath, traceId, limit) {
2112
1975
  crlfDelay: Infinity
2113
1976
  });
2114
1977
  for await (const line of rl) {
2115
- const entry = parseLogLine2(line);
1978
+ const entry = parseLogLine(line);
2116
1979
  if (!entry) continue;
2117
1980
  if (entry.trace_id !== traceId) continue;
2118
1981
  matches.push(entry);
@@ -2186,7 +2049,7 @@ async function readRecentTraceCalls(filePath, page, pageSize, pathFilter, method
2186
2049
  }
2187
2050
  }, "processLogEntry");
2188
2051
  const processLine = /* @__PURE__ */ __name((line) => {
2189
- const entry = parseLogLine2(line);
2052
+ const entry = parseLogLine(line);
2190
2053
  if (entry?.trace_id) {
2191
2054
  processLogEntry(entry);
2192
2055
  }
@@ -2358,7 +2221,7 @@ __name(readLogsBySource, "readLogsBySource");
2358
2221
  // src/middlewares/dev-logs/services/trigger.service.ts
2359
2222
  import { createReadStream as createReadStream3 } from "fs";
2360
2223
  import { createInterface as createInterface3 } from "readline";
2361
- async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2224
+ async function readTriggerList(filePath, trigger, path7, limit, triggerID) {
2362
2225
  if (!await fileExists(filePath)) {
2363
2226
  return void 0;
2364
2227
  }
@@ -2384,7 +2247,7 @@ async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2384
2247
  if (alreadyAdded) {
2385
2248
  return false;
2386
2249
  }
2387
- const isAutomationTrigger = builder.path?.endsWith(path8);
2250
+ const isAutomationTrigger = builder.path?.endsWith(path7);
2388
2251
  if (!isAutomationTrigger) {
2389
2252
  return false;
2390
2253
  }
@@ -2443,7 +2306,7 @@ async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2443
2306
  }
2444
2307
  }, "processLogEntry");
2445
2308
  const processLine = /* @__PURE__ */ __name((line) => {
2446
- const entry = parseLogLine2(line);
2309
+ const entry = parseLogLine(line);
2447
2310
  if (entry?.trace_id) {
2448
2311
  processLogEntry(entry);
2449
2312
  }
@@ -2467,7 +2330,7 @@ async function readTriggerList(filePath, trigger, path8, limit, triggerID) {
2467
2330
  };
2468
2331
  }
2469
2332
  __name(readTriggerList, "readTriggerList");
2470
- async function readTriggerDetail(filePath, path8, instanceID) {
2333
+ async function readTriggerDetail(filePath, path7, instanceID) {
2471
2334
  const exists = await fileExists(filePath);
2472
2335
  if (!exists) {
2473
2336
  return void 0;
@@ -2481,9 +2344,9 @@ async function readTriggerDetail(filePath, path8, instanceID) {
2481
2344
  crlfDelay: Infinity
2482
2345
  });
2483
2346
  for await (const line of rl) {
2484
- const entry = parseLogLine2(line);
2347
+ const entry = parseLogLine(line);
2485
2348
  if (!entry) continue;
2486
- const isAutomationTrigger = entry.path?.endsWith(path8);
2349
+ const isAutomationTrigger = entry.path?.endsWith(path7);
2487
2350
  const hasInstanceID = entry.instance_id === instanceID && entry.trigger;
2488
2351
  if (!isAutomationTrigger || !hasInstanceID) continue;
2489
2352
  matches.push(entry);
@@ -2577,7 +2440,7 @@ async function readCapabilityTraceList(filePath, capabilityId, limit) {
2577
2440
  updateBuilderMetadata(builder, entry);
2578
2441
  }, "processLogEntry");
2579
2442
  const processLine = /* @__PURE__ */ __name((line) => {
2580
- const entry = parseLogLine2(line);
2443
+ const entry = parseLogLine(line);
2581
2444
  if (entry?.capability_id) {
2582
2445
  processLogEntry(entry);
2583
2446
  }
@@ -2737,16 +2600,16 @@ function createGetTriggerListHandler(logDir) {
2737
2600
  });
2738
2601
  }
2739
2602
  const triggerID = typeof req.query.triggerID === "string" ? req.query.triggerID.trim() : void 0;
2740
- const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2603
+ const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2741
2604
  const limit = parseLimit(req.query.limit, 10, 200);
2742
2605
  try {
2743
- const result = await readTriggerList(traceLogPath, trigger, path8, limit, triggerID);
2606
+ const result = await readTriggerList(traceLogPath, trigger, path7, limit, triggerID);
2744
2607
  if (!result) {
2745
2608
  return handleNotFound(res, traceLogPath);
2746
2609
  }
2747
2610
  res.json({
2748
2611
  file: getRelativePath(traceLogPath),
2749
- path: path8,
2612
+ path: path7,
2750
2613
  ...result
2751
2614
  });
2752
2615
  } catch (error) {
@@ -2764,9 +2627,9 @@ function createGetTriggerDetailHandler(logDir) {
2764
2627
  message: "instanceID is required"
2765
2628
  });
2766
2629
  }
2767
- const path8 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2630
+ const path7 = typeof req.query.path === "string" ? req.query.path.trim() : "/__innerapi__/automation/invoke";
2768
2631
  try {
2769
- const result = await readTriggerDetail(traceLogPath, path8, instanceID);
2632
+ const result = await readTriggerDetail(traceLogPath, path7, instanceID);
2770
2633
  if (!result) {
2771
2634
  return handleNotFound(res, traceLogPath);
2772
2635
  }
@@ -2874,8 +2737,8 @@ function createHealthCheckHandler(options = {}) {
2874
2737
  __name(createHealthCheckHandler, "createHealthCheckHandler");
2875
2738
 
2876
2739
  // src/middlewares/dev-logs/sse/log-watcher.ts
2877
- import * as fs9 from "fs";
2878
- import * as path6 from "path";
2740
+ import * as fs8 from "fs";
2741
+ import * as path5 from "path";
2879
2742
  function mapPinoLevelToServerLogLevel2(pinoLevel) {
2880
2743
  if (typeof pinoLevel === "string") {
2881
2744
  const lower = pinoLevel.toLowerCase();
@@ -3090,13 +2953,13 @@ var LogWatcher = class {
3090
2953
  * Watch a single log file
3091
2954
  */
3092
2955
  watchFile(config) {
3093
- const filePath = path6.join(this.logDir, config.fileName);
3094
- if (!fs9.existsSync(filePath)) {
2956
+ const filePath = path5.join(this.logDir, config.fileName);
2957
+ if (!fs8.existsSync(filePath)) {
3095
2958
  this.log(`File not found, skipping: ${config.fileName}`);
3096
2959
  return;
3097
2960
  }
3098
2961
  try {
3099
- const stats = fs9.statSync(filePath);
2962
+ const stats = fs8.statSync(filePath);
3100
2963
  this.filePositions.set(config.fileName, stats.size);
3101
2964
  this.log(`Initialized position for ${config.fileName}: ${stats.size} bytes`);
3102
2965
  } catch (error) {
@@ -3104,7 +2967,7 @@ var LogWatcher = class {
3104
2967
  this.filePositions.set(config.fileName, 0);
3105
2968
  }
3106
2969
  try {
3107
- const watcher = fs9.watch(filePath, (eventType) => {
2970
+ const watcher = fs8.watch(filePath, (eventType) => {
3108
2971
  if (eventType === "change") {
3109
2972
  this.handleFileChange(config);
3110
2973
  }
@@ -3139,10 +3002,10 @@ var LogWatcher = class {
3139
3002
  * Handle file change event - read new content
3140
3003
  */
3141
3004
  handleFileChange(config) {
3142
- const filePath = path6.join(this.logDir, config.fileName);
3005
+ const filePath = path5.join(this.logDir, config.fileName);
3143
3006
  const lastPosition = this.filePositions.get(config.fileName) || 0;
3144
3007
  try {
3145
- const stats = fs9.statSync(filePath);
3008
+ const stats = fs8.statSync(filePath);
3146
3009
  const currentSize = stats.size;
3147
3010
  if (currentSize < lastPosition) {
3148
3011
  this.log(`File ${config.fileName} was truncated, resetting position`);
@@ -3155,11 +3018,11 @@ var LogWatcher = class {
3155
3018
  }
3156
3019
  const readSize = currentSize - lastPosition;
3157
3020
  const buffer = Buffer.alloc(readSize);
3158
- const fd = fs9.openSync(filePath, "r");
3021
+ const fd = fs8.openSync(filePath, "r");
3159
3022
  try {
3160
- fs9.readSync(fd, buffer, 0, readSize, lastPosition);
3023
+ fs8.readSync(fd, buffer, 0, readSize, lastPosition);
3161
3024
  } finally {
3162
- fs9.closeSync(fd);
3025
+ fs8.closeSync(fd);
3163
3026
  }
3164
3027
  this.filePositions.set(config.fileName, currentSize);
3165
3028
  const content = buffer.toString("utf8");
@@ -3459,11 +3322,11 @@ import express3 from "express";
3459
3322
 
3460
3323
  // src/middlewares/collect-logs/controller.ts
3461
3324
  import { join as join7 } from "path";
3462
- import fs11 from "fs";
3325
+ import fs10 from "fs";
3463
3326
 
3464
3327
  // src/middlewares/collect-logs/utils.ts
3465
3328
  import { isAbsolute as isAbsolute2, join as join6 } from "path";
3466
- import fs10 from "fs";
3329
+ import fs9 from "fs";
3467
3330
  function resolveLogDir2(provided) {
3468
3331
  if (!provided) {
3469
3332
  return join6(process.cwd(), "logs");
@@ -3472,8 +3335,8 @@ function resolveLogDir2(provided) {
3472
3335
  }
3473
3336
  __name(resolveLogDir2, "resolveLogDir");
3474
3337
  function ensureDir(dir) {
3475
- if (!fs10.existsSync(dir)) {
3476
- fs10.mkdirSync(dir, {
3338
+ if (!fs9.existsSync(dir)) {
3339
+ fs9.mkdirSync(dir, {
3477
3340
  recursive: true
3478
3341
  });
3479
3342
  }
@@ -3505,7 +3368,7 @@ function collectLogsHandler(logDir, fileName) {
3505
3368
  ...logContent,
3506
3369
  server_time: (/* @__PURE__ */ new Date()).toISOString()
3507
3370
  }) + "\n";
3508
- await fs11.promises.appendFile(filePath, logLine);
3371
+ await fs10.promises.appendFile(filePath, logLine);
3509
3372
  res.json({
3510
3373
  success: true
3511
3374
  });
@@ -3533,7 +3396,7 @@ function collectLogsBatchHandler(logDir, fileName) {
3533
3396
  server_time: (/* @__PURE__ */ new Date()).toISOString()
3534
3397
  }) + "\n");
3535
3398
  }
3536
- await fs11.promises.appendFile(filePath, logLines.join(""));
3399
+ await fs10.promises.appendFile(filePath, logLines.join(""));
3537
3400
  res.json({
3538
3401
  success: true
3539
3402
  });
@@ -3596,7 +3459,7 @@ function isGlobalMiddleware(middleware) {
3596
3459
  }
3597
3460
  __name(isGlobalMiddleware, "isGlobalMiddleware");
3598
3461
  function computeMountPath(basePath, mountPath) {
3599
- const routePath = path7.posix.join(basePath, mountPath);
3462
+ const routePath = path6.posix.join(basePath, mountPath);
3600
3463
  return routePath.startsWith("/") ? routePath : `/${routePath}`;
3601
3464
  }
3602
3465
  __name(computeMountPath, "computeMountPath");
@@ -3604,7 +3467,7 @@ function logMiddlewareRegistration(middleware, fullMountPath) {
3604
3467
  if (middleware.routes && middleware.routes.length > 0) {
3605
3468
  console.log(`[Middleware] Registered: ${middleware.name} at ${fullMountPath}`);
3606
3469
  middleware.routes.forEach((route) => {
3607
- const routePath = route.path === "/" ? fullMountPath : path7.posix.join(fullMountPath, route.path);
3470
+ const routePath = route.path === "/" ? fullMountPath : path6.posix.join(fullMountPath, route.path);
3608
3471
  console.log(` ${route.method} ${routePath} - ${route.description}`);
3609
3472
  });
3610
3473
  } else {