@kevisual/cli 0.0.77 → 0.0.78

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.
@@ -41464,7 +41464,7 @@ var require_commander = __commonJS((exports) => {
41464
41464
  exports.InvalidOptionArgumentError = InvalidArgumentError;
41465
41465
  });
41466
41466
 
41467
- // ../node_modules/.pnpm/@kevisual+router@0.0.49_supports-color@10.2.2/node_modules/@kevisual/router/dist/router.js
41467
+ // ../node_modules/.pnpm/@kevisual+router@0.0.51_supports-color@10.2.2/node_modules/@kevisual/router/dist/router.js
41468
41468
  import require$$1, { webcrypto } from "node:crypto";
41469
41469
  import require$$2 from "node:http";
41470
41470
  import require$$1$1 from "node:https";
@@ -41994,13 +41994,13 @@ class QueryRouter {
41994
41994
  hasRoute(path, key = "") {
41995
41995
  return this.routes.find((r) => r.path === path && r.key === key);
41996
41996
  }
41997
- createRouteList(force = false) {
41998
- const hasListRoute = this.hasRoute("route", "list");
41997
+ createRouteList(force = false, filter) {
41998
+ const hasListRoute = this.hasRoute("router", "list");
41999
41999
  if (!hasListRoute || force) {
42000
- const listRoute = new Route("route", "list", {
42000
+ const listRoute = new Route("router", "list", {
42001
42001
  description: "列出当前应用下的所有的路由信息",
42002
42002
  run: async (ctx) => {
42003
- const list = this.getList();
42003
+ const list = this.getList(filter);
42004
42004
  ctx.body = list;
42005
42005
  }
42006
42006
  });
@@ -42010,7 +42010,7 @@ class QueryRouter {
42010
42010
  wait(params, opts) {
42011
42011
  const getList = opts?.getList ?? true;
42012
42012
  if (getList) {
42013
- this.createRouteList();
42013
+ this.createRouteList(opts?.force ?? false, opts?.filter);
42014
42014
  }
42015
42015
  return listenProcess({ app: this, params, ...opts });
42016
42016
  }
@@ -46054,7 +46054,7 @@ class App {
46054
46054
  }
46055
46055
  }
46056
46056
 
46057
- // ../node_modules/.pnpm/@kevisual+router@0.0.49_supports-color@10.2.2/node_modules/@kevisual/router/dist/router-sign.js
46057
+ // ../node_modules/.pnpm/@kevisual+router@0.0.51_supports-color@10.2.2/node_modules/@kevisual/router/dist/router-sign.js
46058
46058
  import require$$12 from "node:crypto";
46059
46059
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
46060
46060
  function getAugmentedNamespace(n) {
@@ -58841,13 +58841,122 @@ function requireSelfsigned() {
58841
58841
  return "SHA-1";
58842
58842
  }
58843
58843
  }
58844
- function getSigningAlgorithm(key) {
58845
- const hashAlg = getAlgorithmName(key);
58844
+ function getSigningAlgorithm(hashKey, keyType) {
58845
+ const hashAlg = getAlgorithmName(hashKey);
58846
+ if (keyType === "ec") {
58847
+ return {
58848
+ name: "ECDSA",
58849
+ hash: hashAlg
58850
+ };
58851
+ }
58852
+ return {
58853
+ name: "RSASSA-PKCS1-v1_5",
58854
+ hash: hashAlg
58855
+ };
58856
+ }
58857
+ function getKeyAlgorithm(options) {
58858
+ const keyType = options.keyType || "rsa";
58859
+ const hashAlg = getAlgorithmName(options.algorithm || "sha1");
58860
+ if (keyType === "ec") {
58861
+ const curve = options.curve || "P-256";
58862
+ return {
58863
+ name: "ECDSA",
58864
+ namedCurve: curve
58865
+ };
58866
+ }
58846
58867
  return {
58847
58868
  name: "RSASSA-PKCS1-v1_5",
58869
+ modulusLength: options.keySize || 2048,
58870
+ publicExponent: new Uint8Array([1, 0, 1]),
58848
58871
  hash: hashAlg
58849
58872
  };
58850
58873
  }
58874
+ function buildExtensions(userExtensions, commonName) {
58875
+ if (!userExtensions || userExtensions.length === 0) {
58876
+ return [
58877
+ new BasicConstraintsExtension2(false, undefined, true),
58878
+ new KeyUsagesExtension2(KeyUsageFlags2.digitalSignature | KeyUsageFlags2.keyEncipherment, true),
58879
+ new ExtendedKeyUsageExtension2([ExtendedKeyUsage3.serverAuth, ExtendedKeyUsage3.clientAuth], false),
58880
+ new SubjectAlternativeNameExtension2([
58881
+ { type: "dns", value: commonName },
58882
+ ...commonName === "localhost" ? [{ type: "ip", value: "127.0.0.1" }] : []
58883
+ ], false)
58884
+ ];
58885
+ }
58886
+ const extensions = [];
58887
+ for (const ext of userExtensions) {
58888
+ const critical = ext.critical || false;
58889
+ switch (ext.name) {
58890
+ case "basicConstraints":
58891
+ extensions.push(new BasicConstraintsExtension2(ext.cA || false, ext.pathLenConstraint, critical));
58892
+ break;
58893
+ case "keyUsage":
58894
+ let flags = 0;
58895
+ if (ext.digitalSignature)
58896
+ flags |= KeyUsageFlags2.digitalSignature;
58897
+ if (ext.nonRepudiation || ext.contentCommitment)
58898
+ flags |= KeyUsageFlags2.nonRepudiation;
58899
+ if (ext.keyEncipherment)
58900
+ flags |= KeyUsageFlags2.keyEncipherment;
58901
+ if (ext.dataEncipherment)
58902
+ flags |= KeyUsageFlags2.dataEncipherment;
58903
+ if (ext.keyAgreement)
58904
+ flags |= KeyUsageFlags2.keyAgreement;
58905
+ if (ext.keyCertSign)
58906
+ flags |= KeyUsageFlags2.keyCertSign;
58907
+ if (ext.cRLSign)
58908
+ flags |= KeyUsageFlags2.cRLSign;
58909
+ if (ext.encipherOnly)
58910
+ flags |= KeyUsageFlags2.encipherOnly;
58911
+ if (ext.decipherOnly)
58912
+ flags |= KeyUsageFlags2.decipherOnly;
58913
+ extensions.push(new KeyUsagesExtension2(flags, critical));
58914
+ break;
58915
+ case "extKeyUsage":
58916
+ const usages = [];
58917
+ if (ext.serverAuth)
58918
+ usages.push(ExtendedKeyUsage3.serverAuth);
58919
+ if (ext.clientAuth)
58920
+ usages.push(ExtendedKeyUsage3.clientAuth);
58921
+ if (ext.codeSigning)
58922
+ usages.push(ExtendedKeyUsage3.codeSigning);
58923
+ if (ext.emailProtection)
58924
+ usages.push(ExtendedKeyUsage3.emailProtection);
58925
+ if (ext.timeStamping)
58926
+ usages.push(ExtendedKeyUsage3.timeStamping);
58927
+ extensions.push(new ExtendedKeyUsageExtension2(usages, critical));
58928
+ break;
58929
+ case "subjectAltName":
58930
+ const altNames = (ext.altNames || []).map((alt) => {
58931
+ switch (alt.type) {
58932
+ case 1:
58933
+ return { type: "email", value: alt.value };
58934
+ case 2:
58935
+ return { type: "dns", value: alt.value };
58936
+ case 6:
58937
+ return { type: "url", value: alt.value };
58938
+ case 7:
58939
+ return { type: "ip", value: alt.ip || alt.value };
58940
+ default:
58941
+ if (alt.ip)
58942
+ return { type: "ip", value: alt.ip };
58943
+ if (alt.dns)
58944
+ return { type: "dns", value: alt.dns };
58945
+ if (alt.email)
58946
+ return { type: "email", value: alt.email };
58947
+ if (alt.uri || alt.url)
58948
+ return { type: "url", value: alt.uri || alt.url };
58949
+ return { type: "dns", value: alt.value };
58950
+ }
58951
+ });
58952
+ extensions.push(new SubjectAlternativeNameExtension2(altNames, critical));
58953
+ break;
58954
+ default:
58955
+ console.warn(`Unknown extension "${ext.name}" ignored`);
58956
+ }
58957
+ }
58958
+ return extensions;
58959
+ }
58851
58960
  function convertAttributes(attrs) {
58852
58961
  const nameMap = {
58853
58962
  commonName: "CN",
@@ -58863,36 +58972,62 @@ function requireSelfsigned() {
58863
58972
  return `${oid}=${attr.value}`;
58864
58973
  }).join(", ");
58865
58974
  }
58866
- async function importPrivateKey(pemKey, algorithm) {
58867
- const pkcs8Match = pemKey.match(/-----BEGIN PRIVATE KEY-----([\s\S]*?)-----END PRIVATE KEY-----/);
58868
- const rsaMatch = pemKey.match(/-----BEGIN RSA PRIVATE KEY-----([\s\S]*?)-----END RSA PRIVATE KEY-----/);
58869
- if (pkcs8Match) {
58870
- const pemContents = pkcs8Match[1].replace(/\s/g, "");
58871
- const binaryDer = Buffer.from(pemContents, "base64");
58872
- return await crypto2.subtle.importKey("pkcs8", binaryDer, {
58873
- name: "RSASSA-PKCS1-v1_5",
58874
- hash: getAlgorithmName(algorithm)
58875
- }, true, ["sign"]);
58876
- } else if (rsaMatch) {
58877
- const keyObject = nodeCrypto.createPrivateKey(pemKey);
58878
- const pkcs8Pem = keyObject.export({ type: "pkcs8", format: "pem" });
58879
- const pemContents = pkcs8Pem.replace(/-----BEGIN PRIVATE KEY-----/, "").replace(/-----END PRIVATE KEY-----/, "").replace(/\s/g, "");
58880
- const binaryDer = Buffer.from(pemContents, "base64");
58881
- return await crypto2.subtle.importKey("pkcs8", binaryDer, {
58975
+ function normalizeECCurve(curveName) {
58976
+ const curveMap = {
58977
+ prime256v1: "P-256",
58978
+ secp384r1: "P-384",
58979
+ secp521r1: "P-521",
58980
+ "P-256": "P-256",
58981
+ "P-384": "P-384",
58982
+ "P-521": "P-521"
58983
+ };
58984
+ return curveMap[curveName] || curveName;
58985
+ }
58986
+ function getECCurve(keyObject) {
58987
+ const details = keyObject.asymmetricKeyDetails;
58988
+ if (details && details.namedCurve) {
58989
+ return normalizeECCurve(details.namedCurve);
58990
+ }
58991
+ return "P-256";
58992
+ }
58993
+ async function importPrivateKey(pemKey, algorithm, keyType) {
58994
+ const keyObject = nodeCrypto.createPrivateKey(pemKey);
58995
+ const detectedKeyType = keyObject.asymmetricKeyType;
58996
+ const actualKeyType = keyType || detectedKeyType;
58997
+ const pkcs8Pem = keyObject.export({ type: "pkcs8", format: "pem" });
58998
+ const pemContents = pkcs8Pem.replace(/-----BEGIN PRIVATE KEY-----/, "").replace(/-----END PRIVATE KEY-----/, "").replace(/\s/g, "");
58999
+ const binaryDer = Buffer.from(pemContents, "base64");
59000
+ let importAlgorithm;
59001
+ if (actualKeyType === "ec") {
59002
+ const curve = getECCurve(keyObject);
59003
+ importAlgorithm = {
59004
+ name: "ECDSA",
59005
+ namedCurve: curve
59006
+ };
59007
+ } else {
59008
+ importAlgorithm = {
58882
59009
  name: "RSASSA-PKCS1-v1_5",
58883
59010
  hash: getAlgorithmName(algorithm)
58884
- }, true, ["sign"]);
58885
- } else {
58886
- throw new Error("Unsupported private key format. Expected PKCS#8 or PKCS#1 RSA key.");
59011
+ };
58887
59012
  }
59013
+ return await crypto2.subtle.importKey("pkcs8", binaryDer, importAlgorithm, true, ["sign"]);
58888
59014
  }
58889
- async function importPublicKey(pemKey, algorithm) {
59015
+ async function importPublicKey(pemKey, algorithm, keyType, curve) {
58890
59016
  const pemContents = pemKey.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, "");
58891
59017
  const binaryDer = Buffer.from(pemContents, "base64");
58892
- return await crypto2.subtle.importKey("spki", binaryDer, {
58893
- name: "RSASSA-PKCS1-v1_5",
58894
- hash: getAlgorithmName(algorithm)
58895
- }, true, ["verify"]);
59018
+ let importAlgorithm;
59019
+ if (keyType === "ec") {
59020
+ importAlgorithm = {
59021
+ name: "ECDSA",
59022
+ namedCurve: curve
59023
+ };
59024
+ } else {
59025
+ importAlgorithm = {
59026
+ name: "RSASSA-PKCS1-v1_5",
59027
+ hash: getAlgorithmName(algorithm)
59028
+ };
59029
+ }
59030
+ return await crypto2.subtle.importKey("spki", binaryDer, importAlgorithm, true, ["verify"]);
58896
59031
  }
58897
59032
  async function generatePemAsync(keyPair, attrs, options, ca) {
58898
59033
  const { privateKey, publicKey } = keyPair;
@@ -58933,22 +59068,15 @@ function requireSelfsigned() {
58933
59068
  }
58934
59069
  ];
58935
59070
  const subjectName = convertAttributes(attrs);
58936
- const signingAlg = getSigningAlgorithm(options.algorithm);
59071
+ const keyType = options.keyType || "rsa";
59072
+ const signingAlg = getSigningAlgorithm(options.algorithm, keyType);
58937
59073
  const commonNameAttr = attrs.find((attr) => attr.name === "commonName" || attr.shortName === "CN");
58938
59074
  const commonName = commonNameAttr ? commonNameAttr.value : "localhost";
58939
- const extensions = [
58940
- new BasicConstraintsExtension2(false, undefined, true),
58941
- new KeyUsagesExtension2(KeyUsageFlags2.digitalSignature | KeyUsageFlags2.keyEncipherment, true),
58942
- new ExtendedKeyUsageExtension2([ExtendedKeyUsage3.serverAuth, ExtendedKeyUsage3.clientAuth], false),
58943
- new SubjectAlternativeNameExtension2([
58944
- { type: "dns", value: commonName },
58945
- ...commonName === "localhost" ? [{ type: "ip", value: "127.0.0.1" }] : []
58946
- ], false)
58947
- ];
59075
+ const extensions = buildExtensions(options.extensions, commonName);
58948
59076
  let cert;
58949
59077
  if (ca) {
58950
59078
  const caCert = new X509Certificate2(ca.cert);
58951
- const caPrivateKey = await importPrivateKey(ca.key, options.algorithm || "sha256");
59079
+ const caPrivateKey = await importPrivateKey(ca.key, options.algorithm || "sha256", keyType);
58952
59080
  cert = await X509CertificateGenerator2.create({
58953
59081
  serialNumber: serialHex,
58954
59082
  subject: subjectName,
@@ -59016,12 +59144,15 @@ function requireSelfsigned() {
59016
59144
  const clientKeySize = clientOpts.keySize || options.clientCertificateKeySize || 2048;
59017
59145
  const clientAlgorithm = clientOpts.algorithm || options.algorithm || "sha1";
59018
59146
  const clientCN = clientOpts.cn || options.clientCertificateCN || "John Doe jdoe123";
59019
- const clientKeyPair = await crypto2.subtle.generateKey({
59020
- name: "RSASSA-PKCS1-v1_5",
59021
- modulusLength: clientKeySize,
59022
- publicExponent: new Uint8Array([1, 0, 1]),
59023
- hash: getAlgorithmName(clientAlgorithm)
59024
- }, true, ["sign", "verify"]);
59147
+ const clientKeyType = clientOpts.keyType || keyType;
59148
+ const clientCurve = clientOpts.curve || options.curve || "P-256";
59149
+ const clientKeyAlg = getKeyAlgorithm({
59150
+ keyType: clientKeyType,
59151
+ keySize: clientKeySize,
59152
+ algorithm: clientAlgorithm,
59153
+ curve: clientCurve
59154
+ });
59155
+ const clientKeyPair = await crypto2.subtle.generateKey(clientKeyAlg, true, ["sign", "verify"]);
59025
59156
  const clientSerialBytes = crypto2.getRandomValues(new Uint8Array(9));
59026
59157
  const clientSerialHex = toPositiveHex(Buffer.from(clientSerialBytes).toString("hex"));
59027
59158
  const clientNotBefore = clientOpts.notBeforeDate || new Date;
@@ -59043,7 +59174,7 @@ function requireSelfsigned() {
59043
59174
  }
59044
59175
  const clientSubjectName = convertAttributes(clientAttrs);
59045
59176
  const issuerName = convertAttributes(attrs);
59046
- const clientSigningAlg = getSigningAlgorithm(clientAlgorithm);
59177
+ const clientSigningAlg = getSigningAlgorithm(clientAlgorithm, keyType);
59047
59178
  const clientCertRaw = await X509CertificateGenerator2.create({
59048
59179
  serialNumber: clientSerialHex,
59049
59180
  subject: clientSubjectName,
@@ -59086,20 +59217,17 @@ function requireSelfsigned() {
59086
59217
  selfsigned.generate = async function generate(attrs, options) {
59087
59218
  attrs = attrs || undefined;
59088
59219
  options = options || {};
59089
- const keySize = options.keySize || 2048;
59220
+ const keyType = options.keyType || "rsa";
59221
+ const curve = options.curve || "P-256";
59090
59222
  let keyPair;
59091
59223
  if (options.keyPair) {
59092
59224
  keyPair = {
59093
- privateKey: await importPrivateKey(options.keyPair.privateKey, options.algorithm || "sha1"),
59094
- publicKey: await importPublicKey(options.keyPair.publicKey, options.algorithm || "sha1")
59225
+ privateKey: await importPrivateKey(options.keyPair.privateKey, options.algorithm || "sha1", keyType),
59226
+ publicKey: await importPublicKey(options.keyPair.publicKey, options.algorithm || "sha1", keyType, curve)
59095
59227
  };
59096
59228
  } else {
59097
- keyPair = await crypto2.subtle.generateKey({
59098
- name: "RSASSA-PKCS1-v1_5",
59099
- modulusLength: keySize,
59100
- publicExponent: new Uint8Array([1, 0, 1]),
59101
- hash: getAlgorithmName(options.algorithm || "sha1")
59102
- }, true, ["sign", "verify"]);
59229
+ const keyAlg = getKeyAlgorithm(options);
59230
+ keyPair = await crypto2.subtle.generateKey(keyAlg, true, ["sign", "verify"]);
59103
59231
  }
59104
59232
  return await generatePemAsync(keyPair, attrs, options, options.ca);
59105
59233
  };
@@ -68535,6 +68663,7 @@ var import_fast_glob = __toESM(require_out4(), 1);
68535
68663
  import fs8 from "node:fs";
68536
68664
 
68537
68665
  // src/module/local-apps/src/modules/pm2.ts
68666
+ import { spawn } from "node:child_process";
68538
68667
  import pm23 from "pm2";
68539
68668
  import { promisify as promisify3 } from "node:util";
68540
68669
  var normalizeScriptPath2 = (scriptPath) => {
@@ -68561,6 +68690,23 @@ var restart3 = promisify3(pm23.restart).bind(pm23);
68561
68690
  var reload2 = promisify3(pm23.reload).bind(pm23);
68562
68691
  var deleteProcess3 = promisify3(pm23.delete).bind(pm23);
68563
68692
  var list3 = promisify3(pm23.list).bind(pm23);
68693
+ var checkInstall = async (app) => {
68694
+ return new Promise((resolve, reject) => {
68695
+ const install = spawn("pnpm", ["install"], {
68696
+ cwd: app.path,
68697
+ stdio: "inherit"
68698
+ });
68699
+ install.on("close", (code) => {
68700
+ if (code !== 0) {
68701
+ console.log("install failed");
68702
+ return resolve(false);
68703
+ }
68704
+ console.log("install success");
68705
+ resolve(true);
68706
+ });
68707
+ });
68708
+ };
68709
+
68564
68710
  class Pm2Connect2 {
68565
68711
  needConnect = true;
68566
68712
  isConnected = false;
@@ -68702,6 +68848,9 @@ class Pm2Manager2 {
68702
68848
  this.pm2Connect.checkDisconnect(runOpts);
68703
68849
  }
68704
68850
  }
68851
+ async remove(runOpts) {
68852
+ this.deleteProcess(runOpts);
68853
+ }
68705
68854
  async deleteProcess(runOpts) {
68706
68855
  try {
68707
68856
  await this.pm2Connect.checkConnect();
@@ -68749,61 +68898,7 @@ class Manager2 {
68749
68898
  async loadApp(app) {
68750
68899
  const mainApp = this.mainApp;
68751
68900
  this.apps.set(app.key, app);
68752
- if (app.status !== "running") {
68753
- return;
68754
- }
68755
- if (!fileIsExist2(app.path)) {
68756
- console.error("app is not found");
68757
- return;
68758
- }
68759
- const pathEntry = path8.join(app.path, app.entry);
68760
- if (!fileIsExist2(pathEntry)) {
68761
- console.error("file entry not found");
68762
- return;
68763
- }
68764
- const entry2 = app.entry + `?timestamp=${app?.timestamp}`;
68765
- if (app.type === "micro-app" /* MicroApp */) {
68766
- const childProcess = fork2(app.entry, [], {
68767
- stdio: "inherit",
68768
- cwd: app.path,
68769
- env: {
68770
- ...process.env,
68771
- ...app.env,
68772
- APP_KEY: app.key,
68773
- APP_PATH: app.path,
68774
- APP_ENTRY: entry2
68775
- }
68776
- });
68777
- app.process = childProcess;
68778
- } else if (app.type === "system-app" /* SystemApp */) {
68779
- const pathEntryAndTimestamp = path8.join(app.path, entry2);
68780
- const importPath = process.platform === "win32" ? "file:///" + pathEntryAndTimestamp.replace(/\\/g, "/") : pathEntryAndTimestamp;
68781
- const module = await import(importPath);
68782
- if (module.loadApp && mainApp) {
68783
- await module.loadApp?.(mainApp, app);
68784
- }
68785
- } else if (app.type === "gateway-app" /* GatewayApp */) {
68786
- console.log("gateway app not support");
68787
- } else if (app.type === "pm2-system-app" /* Pm2SystemApp */) {
68788
- const pathEntry2 = path8.join(app.path, app.entry);
68789
- const pm2Manager = new Pm2Manager2({
68790
- appName: app.key,
68791
- script: pathEntry2,
68792
- pm2Connect: this.#pm2Connect
68793
- });
68794
- const pm2Options = app.pm2Options || {};
68795
- if (app?.engine) {
68796
- pm2Options.interpreter = pm2Options.interpreter || app?.engine;
68797
- }
68798
- if (!pm2Options.cwd) {
68799
- pm2Options.cwd = path8.join(app.path, "../..");
68800
- }
68801
- await pm2Manager.start(pm2Options);
68802
- } else {
68803
- console.error("app type not support", app.type);
68804
- }
68805
- console.log(`load ${app.type} success`, app.key);
68806
- return true;
68901
+ return await LoadApp(app, { mainApp, pm2Connect: this.#pm2Connect });
68807
68902
  }
68808
68903
  async saveAppInfo(app, newTimeData = false) {
68809
68904
  const list4 = this.appInfo.list || [];
@@ -68904,24 +68999,7 @@ class Manager2 {
68904
68999
  if (!app) {
68905
69000
  return;
68906
69001
  }
68907
- if (app.status === "stop" && app.type === "system-app" /* SystemApp */) {
68908
- console.log(`app ${key} is stopped`);
68909
- return;
68910
- }
68911
- app.status = "stop";
68912
- if (app.type === "micro-app" /* MicroApp */) {
68913
- if (app.process) {
68914
- app.process.kill();
68915
- }
68916
- }
68917
- if (app.type === "pm2-system-app" /* Pm2SystemApp */) {
68918
- const pm2Manager = new Pm2Manager2({
68919
- appName: app.key,
68920
- script: app.entry,
68921
- pm2Connect: this.#pm2Connect
68922
- });
68923
- await pm2Manager.stop();
68924
- }
69002
+ await StopApp(app, { pm2Connect: this.#pm2Connect, todo: "stop" });
68925
69003
  await this.saveAppInfo(app);
68926
69004
  }
68927
69005
  async restart(key) {
@@ -68968,8 +69046,9 @@ class Manager2 {
68968
69046
  await this.saveAppInfo(app);
68969
69047
  return onAppShowInfo2(app);
68970
69048
  }
68971
- async removeApp(key) {
69049
+ async removeApp(key, opts) {
68972
69050
  const app = this.apps.get(key);
69051
+ const deleteFile = opts?.deleteFile ?? true;
68973
69052
  if (!app) {
68974
69053
  return false;
68975
69054
  }
@@ -68989,6 +69068,9 @@ class Manager2 {
68989
69068
  } catch (e) {
68990
69069
  console.log("delete pm2 process error", e);
68991
69070
  }
69071
+ if (!deleteFile) {
69072
+ return true;
69073
+ }
68992
69074
  try {
68993
69075
  deleteFileAppInfo2(key, this.appsPath);
68994
69076
  } catch (e) {
@@ -69054,6 +69136,99 @@ class Manager2 {
69054
69136
  }
69055
69137
  }
69056
69138
  }
69139
+ var LoadApp = async (app, opts) => {
69140
+ const mainApp = opts?.mainApp;
69141
+ const pm2Connect = opts?.pm2Connect;
69142
+ if (app.status !== "running") {
69143
+ return false;
69144
+ }
69145
+ if (!fileIsExist2(app.path)) {
69146
+ console.error("app is not found");
69147
+ return false;
69148
+ }
69149
+ const pathEntry = path8.join(app.path, app.entry);
69150
+ if (!fileIsExist2(pathEntry)) {
69151
+ console.error("file entry not found");
69152
+ return false;
69153
+ }
69154
+ const entry2 = app.entry + `?timestamp=${app?.timestamp}`;
69155
+ if (app.type === "micro-app" /* MicroApp */) {
69156
+ const childProcess = fork2(app.entry, [], {
69157
+ stdio: "inherit",
69158
+ cwd: app.path,
69159
+ env: {
69160
+ ...process.env,
69161
+ ...app.env,
69162
+ APP_KEY: app.key,
69163
+ APP_PATH: app.path,
69164
+ APP_ENTRY: entry2
69165
+ }
69166
+ });
69167
+ app.process = childProcess;
69168
+ } else if (app.type === "system-app" /* SystemApp */) {
69169
+ const pathEntryAndTimestamp = path8.join(app.path, entry2);
69170
+ const importPath = process.platform === "win32" ? "file:///" + pathEntryAndTimestamp.replace(/\\/g, "/") : pathEntryAndTimestamp;
69171
+ const module = await import(importPath);
69172
+ if (module.loadApp && mainApp) {
69173
+ await module.loadApp?.(mainApp, app);
69174
+ }
69175
+ } else if (app.type === "gateway-app" /* GatewayApp */) {
69176
+ console.log("gateway app not support");
69177
+ } else if (app.type === "pm2-system-app" /* Pm2SystemApp */) {
69178
+ const pathEntry2 = path8.join(app.path, app.entry);
69179
+ console.log("pm2 system app start", pathEntry2);
69180
+ const pm2Manager = new Pm2Manager2({
69181
+ appName: app.key,
69182
+ script: pathEntry2,
69183
+ pm2Connect
69184
+ });
69185
+ if (app?.init) {
69186
+ const isInstall = await checkInstall(app);
69187
+ if (!isInstall) {
69188
+ console.log("install failed");
69189
+ return false;
69190
+ }
69191
+ }
69192
+ const pm2Options = app.pm2Options || {};
69193
+ if (app?.engine) {
69194
+ pm2Options.interpreter = pm2Options.interpreter || app?.engine;
69195
+ }
69196
+ if (!pm2Options.cwd) {
69197
+ pm2Options.cwd = path8.join(app.path, "../..");
69198
+ }
69199
+ console.log("pm2 start options", pm2Options);
69200
+ await pm2Manager.start(pm2Options);
69201
+ } else if (app.type === "script-app" /* ScriptApp */) {
69202
+ return true;
69203
+ } else {
69204
+ console.error("app type not support", app.type);
69205
+ }
69206
+ console.log(`load ${app.type} success`, app.key);
69207
+ return true;
69208
+ };
69209
+ var StopApp = async (app, opts) => {
69210
+ const key = app.key;
69211
+ const pm2Connect = opts?.pm2Connect;
69212
+ const todo = opts?.todo || "stop";
69213
+ if (app.status === "stop" && app.type === "system-app" /* SystemApp */) {
69214
+ console.log(`app ${key} is stopped`);
69215
+ return;
69216
+ }
69217
+ app.status = "stop";
69218
+ if (app.type === "micro-app" /* MicroApp */) {
69219
+ if (app.process) {
69220
+ app.process.kill();
69221
+ }
69222
+ }
69223
+ if (app.type === "pm2-system-app" /* Pm2SystemApp */) {
69224
+ const pm2Manager = new Pm2Manager2({
69225
+ appName: app.key,
69226
+ script: app.entry,
69227
+ pm2Connect
69228
+ });
69229
+ await pm2Manager[todo]?.();
69230
+ }
69231
+ };
69057
69232
  var installAppFromKey2 = async (key, _appPath) => {
69058
69233
  const normalizedKey = key.replace(/\//g, path8.sep);
69059
69234
  const directory = path8.join(_appPath, normalizedKey);
@@ -69641,7 +69816,7 @@ class AssistantQuery {
69641
69816
  }
69642
69817
  }
69643
69818
  // src/module/npm-install.ts
69644
- import { spawn, spawnSync } from "child_process";
69819
+ import { spawn as spawn2, spawnSync } from "child_process";
69645
69820
  var checkPnpm = () => {
69646
69821
  try {
69647
69822
  spawnSync("pnpm", ["--version"]);
@@ -69661,7 +69836,7 @@ var installDeps = async (opts) => {
69661
69836
  params.push("--omit=dev");
69662
69837
  }
69663
69838
  console.log("installDeps", appPath, params);
69664
- const syncSpawn = opts.sync ? spawnSync : spawn;
69839
+ const syncSpawn = opts.sync ? spawnSync : spawn2;
69665
69840
  if (isPnpm) {
69666
69841
  syncSpawn("pnpm", params, { cwd: appPath, stdio: "inherit", env: process.env });
69667
69842
  } else {
@@ -70476,6 +70651,14 @@ var app = useContextKey("app", () => {
70476
70651
  }
70477
70652
  });
70478
70653
  });
70654
+ app.route({
70655
+ path: "router",
70656
+ key: "list",
70657
+ description: "获取路由列表"
70658
+ }).define(async (ctx) => {
70659
+ const list4 = ctx.app.getList();
70660
+ ctx.body = { list: list4 };
70661
+ }).addTo(app);
70479
70662
 
70480
70663
  // src/module/local-proxy/index.ts
70481
70664
  import fs12 from "node:fs";
@@ -72368,7 +72551,7 @@ var dist_default2 = createPrompt((config2, done) => {
72368
72551
  // ../node_modules/.pnpm/@inquirer+external-editor@2.0.2_@types+node@25.0.3/node_modules/@inquirer/external-editor/dist/index.js
72369
72552
  var import_chardet = __toESM(require_lib2(), 1);
72370
72553
  var import_iconv_lite = __toESM(require_lib3(), 1);
72371
- import { spawn as spawn2, spawnSync as spawnSync2 } from "child_process";
72554
+ import { spawn as spawn3, spawnSync as spawnSync2 } from "child_process";
72372
72555
  import { readFileSync, unlinkSync, writeFileSync } from "fs";
72373
72556
  import path12 from "node:path";
72374
72557
  import os3 from "node:os";
@@ -72554,7 +72737,7 @@ class ExternalEditor {
72554
72737
  }
72555
72738
  launchEditorAsync(callback) {
72556
72739
  try {
72557
- const editorProcess = spawn2(this.editor.bin, this.editor.args.concat([this.tempFile]), { stdio: "inherit" });
72740
+ const editorProcess = spawn3(this.editor.bin, this.editor.args.concat([this.tempFile]), { stdio: "inherit" });
72558
72741
  editorProcess.on("exit", (code) => {
72559
72742
  this.lastExitStatus = code;
72560
72743
  setImmediate(callback);
@@ -77519,6 +77702,15 @@ var wrapper_default = import_websocket.default;
77519
77702
  // src/services/proxy/proxy-page-index.ts
77520
77703
  var localProxy = new LocalProxy({});
77521
77704
  localProxy.initFromAssistantConfig(assistantConfig2);
77705
+ var isOpenPath = (pathname) => {
77706
+ const openPaths = ["/root/home", "/root/cli"];
77707
+ for (const openPath of openPaths) {
77708
+ if (pathname.startsWith(openPath)) {
77709
+ return true;
77710
+ }
77711
+ }
77712
+ return false;
77713
+ };
77522
77714
  var authFilter = async (req, res) => {
77523
77715
  const _assistantConfig = assistantConfig2.getCacheAssistantConfig();
77524
77716
  const auth = _assistantConfig?.auth || {};
@@ -77606,6 +77798,7 @@ var proxyRoute = async (req, res) => {
77606
77798
  target: apiBackendProxy.target
77607
77799
  });
77608
77800
  }
77801
+ logger.debug("proxyRoute handle by router", { url: req.url }, noAdmin);
77609
77802
  const urls = pathname.split("/");
77610
77803
  const [_2, _user, _app] = urls;
77611
77804
  if (!_app) {
@@ -77613,7 +77806,9 @@ var proxyRoute = async (req, res) => {
77613
77806
  res.end("Not Found Proxy");
77614
77807
  return;
77615
77808
  }
77616
- if (noAdmin) {
77809
+ const isOpen = isOpenPath(pathname);
77810
+ log.debug("proxyRoute", { _user, _app, pathname, noAdmin, isOpen });
77811
+ if (noAdmin && !isOpen) {
77617
77812
  return toSetting();
77618
77813
  }
77619
77814
  if (_app && urls.length === 3) {
@@ -77951,7 +78146,7 @@ var getBunPath = () => {
77951
78146
  return bunExecutableName;
77952
78147
  };
77953
78148
 
77954
- // ../node_modules/.pnpm/@kevisual+video-tools@0.0.12_dotenv@17.2.3_supports-color@10.2.2/node_modules/@kevisual/video-tools/src/ws/index.ts
78149
+ // ../node_modules/.pnpm/@kevisual+video-tools@0.0.13_dotenv@17.2.3_supports-color@10.2.2/node_modules/@kevisual/video-tools/src/ws/index.ts
77955
78150
  var isBrowser3 = typeof process === "undefined" || typeof window !== "undefined" && typeof window.document !== "undefined" || typeof process !== "undefined" && process?.env?.BROWSER === "true";
77956
78151
  var chantHttpToWs = (url2) => {
77957
78152
  if (url2.startsWith("http://")) {
@@ -77980,7 +78175,7 @@ var initWs = async (url2, options) => {
77980
78175
  return ws;
77981
78176
  };
77982
78177
 
77983
- // ../node_modules/.pnpm/@kevisual+video-tools@0.0.12_dotenv@17.2.3_supports-color@10.2.2/node_modules/@kevisual/video-tools/src/asr/ws.ts
78178
+ // ../node_modules/.pnpm/@kevisual+video-tools@0.0.13_dotenv@17.2.3_supports-color@10.2.2/node_modules/@kevisual/video-tools/src/asr/ws.ts
77984
78179
  class WSServer {
77985
78180
  ws;
77986
78181
  onConnect;
@@ -78161,9 +78356,20 @@ class WSServer {
78161
78356
  async sendBlankJson() {
78162
78357
  this.ws.send(JSON.stringify({ type: "blankVoice" }));
78163
78358
  }
78359
+ async fixBrowerBuffer(base64) {
78360
+ let voice = Buffer.from(base64, "base64");
78361
+ const floatArray = new Float32Array(voice.buffer, voice.byteOffset, voice.length / 4);
78362
+ const pcm16 = Buffer.alloc(floatArray.length * 2);
78363
+ for (let i = 0;i < floatArray.length; i++) {
78364
+ const sample = Math.max(-1, Math.min(1, floatArray[i]));
78365
+ pcm16.writeInt16LE(sample < 0 ? sample * 32768 : sample * 32767, i * 2);
78366
+ }
78367
+ voice = pcm16;
78368
+ return voice;
78369
+ }
78164
78370
  }
78165
78371
 
78166
- // ../node_modules/.pnpm/@kevisual+video-tools@0.0.12_dotenv@17.2.3_supports-color@10.2.2/node_modules/@kevisual/video-tools/src/asr/provider/aliyun/base.ts
78372
+ // ../node_modules/.pnpm/@kevisual+video-tools@0.0.13_dotenv@17.2.3_supports-color@10.2.2/node_modules/@kevisual/video-tools/src/asr/provider/aliyun/base.ts
78167
78373
  class AsrRelatime extends WSServer {
78168
78374
  static baseURL = "wss://dashscope.aliyuncs.com/api-ws/v1/realtime";
78169
78375
  enableServerVad = true;
@@ -78266,17 +78472,6 @@ class AsrRelatime extends WSServer {
78266
78472
  console.log("error", error2);
78267
78473
  }
78268
78474
  }
78269
- async fixBrowerBuffer(base64) {
78270
- let voice = Buffer.from(base64, "base64");
78271
- const floatArray = new Float32Array(voice.buffer, voice.byteOffset, voice.length / 4);
78272
- const pcm16 = Buffer.alloc(floatArray.length * 2);
78273
- for (let i = 0;i < floatArray.length; i++) {
78274
- const sample = Math.max(-1, Math.min(1, floatArray[i]));
78275
- pcm16.writeInt16LE(sample < 0 ? sample * 32768 : sample * 32767, i * 2);
78276
- }
78277
- voice = pcm16;
78278
- return voice;
78279
- }
78280
78475
  async onClose(event) {
78281
78476
  let { code } = event;
78282
78477
  if (code === 1007) {
@@ -79779,7 +79974,19 @@ var func = async (req, res) => {
79779
79974
  return;
79780
79975
  }
79781
79976
  if (!asr) {
79782
- const token = process.env.BAILIAN_API_KEY || "";
79977
+ const confg = assistantConfig2.getConfig();
79978
+ const asrConfig = confg?.asr;
79979
+ if (!asrConfig?.enabled) {
79980
+ ws.send(JSON.stringify({ type: "error", message: "asr服务未启用" }));
79981
+ ws.close();
79982
+ return;
79983
+ }
79984
+ const token = asrConfig?.token;
79985
+ if (!token) {
79986
+ ws.send(JSON.stringify({ type: "error", message: "asr服务未配置token" }));
79987
+ ws.close();
79988
+ return;
79989
+ }
79783
79990
  asr = new AsrRelatime({
79784
79991
  token,
79785
79992
  onConnect: () => {
@@ -79853,20 +80060,17 @@ var func = async (req, res) => {
79853
80060
  console.log("ASR receive data", "blank voice");
79854
80061
  } else if (data?.voice) {
79855
80062
  if (!data?.isRelatime) {
79856
- console.log("ASR receive data", "has voice", !!data?.voice);
79857
- }
79858
- const isBrowserFormat = data.format === "float32";
79859
- const time = data?.time || 0;
79860
- if (time) {
80063
+ console.log("ASR receive data", "has voice", !!data?.voice, data?.isRelatime);
80064
+ const time = data?.time || 0;
79861
80065
  console.log("receiveDelay", Date.now() - time);
79862
80066
  }
80067
+ const isBrowserFormat = data.format === "float32";
79863
80068
  let voice;
79864
80069
  if (isBrowserFormat) {
79865
80070
  voice = await asr.fixBrowerBuffer(data.voice);
79866
80071
  } else {
79867
80072
  voice = Buffer.from(data.voice, "base64");
79868
80073
  }
79869
- console.log("sendTime", Date.now());
79870
80074
  ws.data.startTime = Date.now();
79871
80075
  asr.sendBuffer(voice);
79872
80076
  }
@@ -79904,7 +80108,11 @@ var runServer = async (port = 51515, listenPath = "127.0.0.1") => {
79904
80108
  } else {
79905
80109
  app.listen(_port, listenPath, () => {
79906
80110
  const protocol = assistantConfig2.getHttps().protocol;
79907
- console.log(`Server is running on ${protocol}://${listenPath}:${_port}`);
80111
+ let showListenPath = listenPath;
80112
+ if (listenPath === "::") {
80113
+ showListenPath = "localhost";
80114
+ }
80115
+ console.log(`Server is running on ${protocol}://${showListenPath}:${_port}`);
79908
80116
  });
79909
80117
  }
79910
80118
  app.server.on([