@ultrst-armada/krnl 1.0.1 → 1.0.3
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/README.md +67 -65
- package/package.json +13 -9
- package/packages/cli/dist/bin/krnl.cjs +1535 -9508
- package/packages/cli/dist/bin/krnl.js +55 -1915
- package/packages/cli/dist/chunk-6SHSECXR.js +1628 -0
- package/packages/cli/dist/index.cjs +1244 -7373
- package/packages/cli/dist/index.d.cts +45 -2
- package/packages/cli/dist/index.d.ts +45 -2
- package/packages/cli/dist/index.js +5 -20
- package/packages/cli/package.json +17 -10
- package/packages/core/dist/index.cjs +3039 -141
- package/packages/core/dist/index.d.cts +633 -27
- package/packages/core/dist/index.d.ts +633 -27
- package/packages/core/dist/index.js +3028 -139
- package/packages/core/package.json +15 -7
- package/packages/create-krnl/dist/index.cjs +322 -316
- package/packages/create-krnl/dist/index.js +322 -316
- package/packages/create-krnl/package.json +5 -3
- package/packages/eslint-plugin/dist/index.cjs +17 -55
- package/packages/eslint-plugin/dist/index.d.cts +8 -43
- package/packages/eslint-plugin/dist/index.d.ts +8 -43
- package/packages/eslint-plugin/dist/index.js +17 -55
- package/packages/eslint-plugin/package.json +5 -4
- package/packages/validate/dist/index.cjs +692 -361
- package/packages/validate/dist/index.d.cts +12 -14
- package/packages/validate/dist/index.d.ts +12 -14
- package/packages/validate/dist/index.js +692 -361
- package/packages/validate/package.json +14 -7
- package/packages/cli/dist/K_ENT_Entity-PQ5MURQY-ZG6FZXXX.js +0 -13
- package/packages/cli/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-K4CRQYA5.js +0 -8
- package/packages/cli/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-LNPXZYOE.js +0 -110
- package/packages/cli/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-3ALZPNX4.js +0 -11
- package/packages/cli/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-PJTICYSW.js +0 -11
- package/packages/cli/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-M5TYU55O.js +0 -8
- package/packages/cli/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-H6STOXRK.js +0 -20
- package/packages/cli/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-XPJXSF7D.js +0 -19
- package/packages/cli/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-CUYGTWOW.js +0 -7
- package/packages/cli/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-VR6T4N6J.js +0 -17
- package/packages/cli/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-RLJ4QWDP.js +0 -58
- package/packages/cli/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-BOQGUASC.js +0 -22
- package/packages/cli/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-XJI7KIT5.js +0 -8
- package/packages/cli/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-K5VCWAFW.js +0 -9
- package/packages/cli/dist/chunk-3TRM6CYL.js +0 -152
- package/packages/cli/dist/chunk-5JDK35TG.js +0 -3872
- package/packages/cli/dist/chunk-63PTK33I.js +0 -997
- package/packages/cli/dist/chunk-6NIKAMUZ.js +0 -82
- package/packages/cli/dist/chunk-BOXWWXQG.js +0 -400
- package/packages/cli/dist/chunk-EEKLK7QJ.js +0 -565
- package/packages/cli/dist/chunk-EG7T2IAD.js +0 -107
- package/packages/cli/dist/chunk-F5EHXE2O.js +0 -1036
- package/packages/cli/dist/chunk-F65ANSQG.js +0 -269
- package/packages/cli/dist/chunk-FDNCADFE.js +0 -71
- package/packages/cli/dist/chunk-GDLRMDAN.js +0 -127
- package/packages/cli/dist/chunk-HWMTCMOS.js +0 -656
- package/packages/cli/dist/chunk-I74QIQOD.js +0 -5536
- package/packages/cli/dist/chunk-JTLSTO25.js +0 -71
- package/packages/cli/dist/chunk-JULBBJ27.js +0 -1033
- package/packages/cli/dist/chunk-OHVMVRBP.js +0 -117
- package/packages/cli/dist/chunk-P2PCLEKX.js +0 -666
- package/packages/cli/dist/chunk-PJQIUOX2.js +0 -7767
- package/packages/cli/dist/chunk-PPOF3DJW.js +0 -471
- package/packages/cli/dist/chunk-Q45257P6.js +0 -173
- package/packages/cli/dist/chunk-QNROWGBI.js +0 -1036
- package/packages/cli/dist/chunk-RJNYUXZD.js +0 -977
- package/packages/cli/dist/chunk-SRTOPJ5W.js +0 -104
- package/packages/cli/dist/chunk-TCEX3MPS.js +0 -702
- package/packages/cli/dist/chunk-TNOAJO2J.js +0 -675
- package/packages/cli/dist/chunk-UR2SUCSF.js +0 -701
- package/packages/cli/dist/chunk-X5LOIFM7.js +0 -68
- package/packages/cli/dist/chunk-XIRFOO3H.js +0 -589
- package/packages/cli/dist/chunk-ZAAV3JXQ.js +0 -809
- package/packages/core/dist/K_ENT_Entity-4MB7CU4A.js +0 -12
- package/packages/core/dist/K_ENT_Entity-DEJGIDGH.js +0 -12
- package/packages/core/dist/K_ENT_Entity-FXZO5UZ2.js +0 -12
- package/packages/core/dist/K_ENT_Entity-HDSCXC5F.js +0 -12
- package/packages/core/dist/K_ENT_Entity-JILABHLW.js +0 -12
- package/packages/core/dist/K_ENT_Entity-PQ5MURQY.js +0 -13
- package/packages/core/dist/K_ENT_Entity-ROAKDIHW.js +0 -12
- package/packages/core/dist/K_ENT_Entity-TBVFSKDV.js +0 -12
- package/packages/core/dist/K_ENT_Entity-ZFLKG3JO.js +0 -12
- package/packages/core/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW.js +0 -8
- package/packages/core/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF.js +0 -110
- package/packages/core/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF.js +0 -9
- package/packages/core/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X.js +0 -9
- package/packages/core/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW.js +0 -8
- package/packages/core/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2.js +0 -20
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-4C6GBQAG.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-6V23A6F6.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK.js +0 -19
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-DYLLC5G2.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-F4FOFAUP.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-FBOXXMI3.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-Q73BWLNP.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QM2C4MVA.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QUGI6SMP.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RGMTBHNP.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RWR7UNDW.js +0 -18
- package/packages/core/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7.js +0 -7
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-32MFJJ5Z.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-4J4CEWRY.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-A366YHF2.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-LK4LYJHI.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-NW3K63II.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-QDHTI5ZV.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-VHCT6VIW.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-WBRKF24R.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-XKYQYT6Q.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-Z2PWZYDZ.js +0 -17
- package/packages/core/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5.js +0 -58
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-2EZU7QF4.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-6G3AQNAV.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-B2NZMQUG.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-C2RABMZP.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-HHE3NZ4F.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-LHFGR6WK.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-M74BLM3N.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-PT6ZA6EA.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-SP52V3CX.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF.js +0 -22
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-YNSEUHJJ.js +0 -21
- package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-M6SBHIVA.js +0 -8
- package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG.js +0 -8
- package/packages/core/dist/K_LIB_Krnl_Telemetry-77FRZ3KV.js +0 -9
- package/packages/core/dist/chunk-33L2J7V7.js +0 -82
- package/packages/core/dist/chunk-3ES4K2ZP.js +0 -817
- package/packages/core/dist/chunk-3SMHVVLL.js +0 -82
- package/packages/core/dist/chunk-3UEZ7JQA.js +0 -4877
- package/packages/core/dist/chunk-3XIE6KBD.js +0 -4877
- package/packages/core/dist/chunk-46ZLCML6.js +0 -107
- package/packages/core/dist/chunk-4UEL3DWJ.js +0 -107
- package/packages/core/dist/chunk-54GWZ5PC.js +0 -82
- package/packages/core/dist/chunk-6QCYRS5L.js +0 -127
- package/packages/core/dist/chunk-6ULMHNXR.js +0 -104
- package/packages/core/dist/chunk-7WUETJEV.js +0 -117
- package/packages/core/dist/chunk-A5KRAYDB.js +0 -107
- package/packages/core/dist/chunk-ANEAZ3PO.js +0 -107
- package/packages/core/dist/chunk-BE76RL6F.js +0 -82
- package/packages/core/dist/chunk-CIARVYDO.js +0 -107
- package/packages/core/dist/chunk-CR2ANE62.js +0 -107
- package/packages/core/dist/chunk-DI27MOR7.js +0 -173
- package/packages/core/dist/chunk-E6RLFHM5.js +0 -596
- package/packages/core/dist/chunk-EELAPMNV.js +0 -4877
- package/packages/core/dist/chunk-ENZ2RQVJ.js +0 -107
- package/packages/core/dist/chunk-F2U6CX4F.js +0 -4877
- package/packages/core/dist/chunk-FKG64OHL.js +0 -82
- package/packages/core/dist/chunk-FYAZJYM5.js +0 -772
- package/packages/core/dist/chunk-G4NP4RDQ.js +0 -82
- package/packages/core/dist/chunk-GADIRLRS.js +0 -473
- package/packages/core/dist/chunk-GR6CSLQJ.js +0 -772
- package/packages/core/dist/chunk-HDS7AT6O.js +0 -772
- package/packages/core/dist/chunk-HIMEZUU2.js +0 -71
- package/packages/core/dist/chunk-IB4UHG5I.js +0 -596
- package/packages/core/dist/chunk-J7ZYNVRS.js +0 -772
- package/packages/core/dist/chunk-JVLZU4K7.js +0 -604
- package/packages/core/dist/chunk-JYXXI7Q3.js +0 -82
- package/packages/core/dist/chunk-K54K2KZW.js +0 -192
- package/packages/core/dist/chunk-K6VHLBNH.js +0 -3316
- package/packages/core/dist/chunk-KCBP7ZYA.js +0 -596
- package/packages/core/dist/chunk-KFQGP6VL.js +0 -33
- package/packages/core/dist/chunk-KIUEUI7K.js +0 -82
- package/packages/core/dist/chunk-LB67NIZP.js +0 -949
- package/packages/core/dist/chunk-LDTYFUNW.js +0 -596
- package/packages/core/dist/chunk-MLVWARD4.js +0 -596
- package/packages/core/dist/chunk-MPYVXHKO.js +0 -2777
- package/packages/core/dist/chunk-MRQ3MITU.js +0 -772
- package/packages/core/dist/chunk-MVUN7I7O.js +0 -107
- package/packages/core/dist/chunk-NDDOIRW7.js +0 -596
- package/packages/core/dist/chunk-O3KDB5MH.js +0 -3330
- package/packages/core/dist/chunk-OEINUDSE.js +0 -400
- package/packages/core/dist/chunk-OPDENPT4.js +0 -4877
- package/packages/core/dist/chunk-P6XEM2LA.js +0 -429
- package/packages/core/dist/chunk-QKMRSQV4.js +0 -82
- package/packages/core/dist/chunk-R6CCWALL.js +0 -4877
- package/packages/core/dist/chunk-RAMMOO73.js +0 -774
- package/packages/core/dist/chunk-S3FTZFG6.js +0 -772
- package/packages/core/dist/chunk-T2ZVN434.js +0 -4877
- package/packages/core/dist/chunk-TFHLDMIA.js +0 -107
- package/packages/core/dist/chunk-TI3QUCIJ.js +0 -107
- package/packages/core/dist/chunk-TR2BAIGI.js +0 -107
- package/packages/core/dist/chunk-UGVVJKC6.js +0 -4877
- package/packages/core/dist/chunk-V2DX7YIU.js +0 -984
- package/packages/core/dist/chunk-W4IHYUYD.js +0 -772
- package/packages/core/dist/chunk-W6WBG5OY.js +0 -4877
- package/packages/core/dist/chunk-WN3M7O7H.js +0 -3312
- package/packages/core/dist/chunk-WR3NCU7U.js +0 -4877
- package/packages/core/dist/chunk-XC6B6L27.js +0 -82
- package/packages/core/dist/chunk-XNSE64ZY.js +0 -3316
- package/packages/core/dist/chunk-XROES2WN.js +0 -634
- package/packages/core/dist/chunk-XSCKNRCZ.js +0 -5020
- package/packages/core/dist/chunk-XVABPAUZ.js +0 -82
- package/packages/core/dist/chunk-YOBCB5C5.js +0 -596
- package/packages/core/dist/chunk-YUK6Q563.js +0 -666
- package/packages/core/dist/chunk-YXGL3ZEU.js +0 -1030
- package/packages/core/dist/chunk-ZINJ5OUX.js +0 -596
- package/packages/core/dist/chunk-ZPFD4BIQ.js +0 -604
- package/packages/core/dist/chunk-ZQZBFG6F.js +0 -4826
- package/packages/core/dist/chunk-ZZFRJGXM.js +0 -4877
- package/packages/create-krnl/dist/K_ENT_Entity-PQ5MURQY-R2OH4VXE.js +0 -14
- package/packages/create-krnl/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-AZM5HF4M.js +0 -9
- package/packages/create-krnl/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-X5N6SV2S.js +0 -111
- package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-5PFHF4JU.js +0 -12
- package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-ED33OQPH.js +0 -12
- package/packages/create-krnl/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-YGQLVR4P.js +0 -9
- package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-VM7CTU2L.js +0 -21
- package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-Y2GQFJ7I.js +0 -21
- package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-L3JQWO54.js +0 -8
- package/packages/create-krnl/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-KQARASPR.js +0 -19
- package/packages/create-krnl/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-OF3IGLVL.js +0 -59
- package/packages/create-krnl/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-JOLHKOEX.js +0 -24
- package/packages/create-krnl/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-L46LSHKQ.js +0 -10
- package/packages/create-krnl/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-4JUPRR3X.js +0 -10
- package/packages/create-krnl/dist/chunk-3TRM6CYL.js +0 -152
- package/packages/create-krnl/dist/chunk-3URCB3QS.js +0 -127
- package/packages/create-krnl/dist/chunk-5JDK35TG.js +0 -3872
- package/packages/create-krnl/dist/chunk-A2XAXDOW.js +0 -812
- package/packages/create-krnl/dist/chunk-AN6TMQHG.js +0 -1033
- package/packages/create-krnl/dist/chunk-BOXWWXQG.js +0 -400
- package/packages/create-krnl/dist/chunk-BPTBREBG.js +0 -38
- package/packages/create-krnl/dist/chunk-FDNCADFE.js +0 -71
- package/packages/create-krnl/dist/chunk-JTLSTO25.js +0 -71
- package/packages/create-krnl/dist/chunk-M3NCUIPL.js +0 -107
- package/packages/create-krnl/dist/chunk-N2EONSOC.js +0 -7769
- package/packages/create-krnl/dist/chunk-OHVMVRBP.js +0 -117
- package/packages/create-krnl/dist/chunk-Q45257P6.js +0 -173
- package/packages/create-krnl/dist/chunk-QGM4M3NI.js +0 -37
- package/packages/create-krnl/dist/chunk-RJNYUXZD.js +0 -977
- package/packages/create-krnl/dist/chunk-SRTOPJ5W.js +0 -104
- package/packages/create-krnl/dist/chunk-UPBIGEC3.js +0 -666
- package/packages/create-krnl/dist/chunk-V2DB7UD7.js +0 -82
- package/packages/create-krnl/dist/chunk-WMHLIUI6.js +0 -3644
- package/packages/create-krnl/dist/chunk-XIRFOO3H.js +0 -589
- package/packages/create-krnl/dist/chunk-Y2CEEVZP.js +0 -5536
- package/packages/create-krnl/dist/main-DXUMPBND.js +0 -2217
- package/packages/create-krnl/dist/wrapper-SDF2VKX3.js +0 -31
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
krnlSystemEntityBase
|
|
3
|
-
} from "./chunk-WR3NCU7U.js";
|
|
4
|
-
import {
|
|
5
|
-
KrnlShell
|
|
6
|
-
} from "./chunk-GADIRLRS.js";
|
|
7
|
-
|
|
8
|
-
// src/core/K_LIB_Krnl_System_App_Adapter.ts
|
|
9
|
-
import fs from "fs";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import http from "http";
|
|
12
|
-
import net from "net";
|
|
13
|
-
var KrnlNonKrnlAppAdapter = class extends krnlSystemEntityBase {
|
|
14
|
-
childProcess = null;
|
|
15
|
-
appPort = -1;
|
|
16
|
-
appPath;
|
|
17
|
-
constructor(name, appPath) {
|
|
18
|
-
super(name, null, -1, "127.0.0.1", { Singleton: true, _skipMagneticLoading: true });
|
|
19
|
-
this.appPath = appPath;
|
|
20
|
-
this._isIngressNetworkMember = true;
|
|
21
|
-
this.unifiedHttpAdapter._handleRequest = async (req, res) => {
|
|
22
|
-
await this.proxyRequest(req, res, req.url || "/");
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async startApp() {
|
|
26
|
-
this.appPort = await this._probeAvailablePort(11e3, "127.0.0.1");
|
|
27
|
-
let command = "node";
|
|
28
|
-
let args = ["."];
|
|
29
|
-
try {
|
|
30
|
-
const pkgPath = path.join(this.appPath, "package.json");
|
|
31
|
-
if (fs.existsSync(pkgPath)) {
|
|
32
|
-
const packageJson = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
33
|
-
if (packageJson.scripts?.start) {
|
|
34
|
-
command = "npm";
|
|
35
|
-
args = ["run", "start"];
|
|
36
|
-
} else if (packageJson.main) {
|
|
37
|
-
args = [packageJson.main];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
} catch (_) {
|
|
41
|
-
}
|
|
42
|
-
const env = {
|
|
43
|
-
...process.env,
|
|
44
|
-
PORT: this.appPort.toString()
|
|
45
|
-
};
|
|
46
|
-
console.log(`[AppAdapter] Spawning non-Krnl app '${this.entityName}' in background (Port: ${this.appPort})...`);
|
|
47
|
-
this.childProcess = KrnlShell.spawn(command, args, {
|
|
48
|
-
cwd: this.appPath,
|
|
49
|
-
env,
|
|
50
|
-
stdio: "inherit"
|
|
51
|
-
});
|
|
52
|
-
let ready = false;
|
|
53
|
-
const timeout = 15e3;
|
|
54
|
-
const start = Date.now();
|
|
55
|
-
while (Date.now() - start < timeout) {
|
|
56
|
-
ready = await new Promise((resolve) => {
|
|
57
|
-
const socket = net.connect(this.appPort, "127.0.0.1");
|
|
58
|
-
socket.on("connect", () => {
|
|
59
|
-
socket.destroy();
|
|
60
|
-
resolve(true);
|
|
61
|
-
});
|
|
62
|
-
socket.on("error", () => resolve(false));
|
|
63
|
-
});
|
|
64
|
-
if (ready) break;
|
|
65
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
66
|
-
}
|
|
67
|
-
if (!ready) {
|
|
68
|
-
throw new Error(`[AppAdapter] Non-Krnl app '${this.entityName}' failed to boot on port ${this.appPort} within 15s.`);
|
|
69
|
-
}
|
|
70
|
-
console.log(`[AppAdapter] Non-Krnl app '${this.entityName}' successfully booted.`);
|
|
71
|
-
}
|
|
72
|
-
async proxyRequest(req, res, subPath) {
|
|
73
|
-
if (this.appPort === -1) {
|
|
74
|
-
res.writeHead(503, { "Content-Type": "application/json" });
|
|
75
|
-
res.end(JSON.stringify({ status: "error", message: "Service Temporarily Unavailable: Sub-app not running." }));
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const options = {
|
|
79
|
-
hostname: "127.0.0.1",
|
|
80
|
-
port: this.appPort,
|
|
81
|
-
path: subPath,
|
|
82
|
-
method: req.method,
|
|
83
|
-
headers: req.headers
|
|
84
|
-
};
|
|
85
|
-
const proxyReq = http.request(options, (proxyRes) => {
|
|
86
|
-
res.writeHead(proxyRes.statusCode || 500, proxyRes.headers);
|
|
87
|
-
proxyRes.pipe(res);
|
|
88
|
-
});
|
|
89
|
-
proxyReq.on("error", (err) => {
|
|
90
|
-
res.writeHead(502, { "Content-Type": "application/json" });
|
|
91
|
-
res.end(JSON.stringify({ status: "error", message: `Bad Gateway: ${err.message}` }));
|
|
92
|
-
});
|
|
93
|
-
req.pipe(proxyReq);
|
|
94
|
-
}
|
|
95
|
-
dispose() {
|
|
96
|
-
if (this.childProcess) {
|
|
97
|
-
console.log(`[AppAdapter] Killing child process (PID: ${this.childProcess.pid}) for '${this.entityName}'`);
|
|
98
|
-
this.childProcess.kill("SIGTERM");
|
|
99
|
-
this.childProcess = null;
|
|
100
|
-
}
|
|
101
|
-
super.dispose();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export {
|
|
106
|
-
KrnlNonKrnlAppAdapter
|
|
107
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
krnlSystemEntityBase
|
|
3
|
-
} from "./chunk-W6WBG5OY.js";
|
|
4
|
-
import {
|
|
5
|
-
KrnlShell
|
|
6
|
-
} from "./chunk-GADIRLRS.js";
|
|
7
|
-
|
|
8
|
-
// src/core/K_LIB_Krnl_System_App_Adapter.ts
|
|
9
|
-
import fs from "fs";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import http from "http";
|
|
12
|
-
import net from "net";
|
|
13
|
-
var KrnlNonKrnlAppAdapter = class extends krnlSystemEntityBase {
|
|
14
|
-
childProcess = null;
|
|
15
|
-
appPort = -1;
|
|
16
|
-
appPath;
|
|
17
|
-
constructor(name, appPath) {
|
|
18
|
-
super(name, null, -1, "127.0.0.1", { Singleton: true, _skipMagneticLoading: true });
|
|
19
|
-
this.appPath = appPath;
|
|
20
|
-
this._isIngressNetworkMember = true;
|
|
21
|
-
this.unifiedHttpAdapter._handleRequest = async (req, res) => {
|
|
22
|
-
await this.proxyRequest(req, res, req.url || "/");
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
async startApp() {
|
|
26
|
-
this.appPort = await this._probeAvailablePort(11e3, "127.0.0.1");
|
|
27
|
-
let command = "node";
|
|
28
|
-
let args = ["."];
|
|
29
|
-
try {
|
|
30
|
-
const pkgPath = path.join(this.appPath, "package.json");
|
|
31
|
-
if (fs.existsSync(pkgPath)) {
|
|
32
|
-
const packageJson = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
33
|
-
if (packageJson.scripts?.start) {
|
|
34
|
-
command = "npm";
|
|
35
|
-
args = ["run", "start"];
|
|
36
|
-
} else if (packageJson.main) {
|
|
37
|
-
args = [packageJson.main];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
} catch (_) {
|
|
41
|
-
}
|
|
42
|
-
const env = {
|
|
43
|
-
...process.env,
|
|
44
|
-
PORT: this.appPort.toString()
|
|
45
|
-
};
|
|
46
|
-
console.log(`[AppAdapter] Spawning non-Krnl app '${this.entityName}' in background (Port: ${this.appPort})...`);
|
|
47
|
-
this.childProcess = KrnlShell.spawn(command, args, {
|
|
48
|
-
cwd: this.appPath,
|
|
49
|
-
env,
|
|
50
|
-
stdio: "inherit"
|
|
51
|
-
});
|
|
52
|
-
let ready = false;
|
|
53
|
-
const timeout = 15e3;
|
|
54
|
-
const start = Date.now();
|
|
55
|
-
while (Date.now() - start < timeout) {
|
|
56
|
-
ready = await new Promise((resolve) => {
|
|
57
|
-
const socket = net.connect(this.appPort, "127.0.0.1");
|
|
58
|
-
socket.on("connect", () => {
|
|
59
|
-
socket.destroy();
|
|
60
|
-
resolve(true);
|
|
61
|
-
});
|
|
62
|
-
socket.on("error", () => resolve(false));
|
|
63
|
-
});
|
|
64
|
-
if (ready) break;
|
|
65
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
66
|
-
}
|
|
67
|
-
if (!ready) {
|
|
68
|
-
throw new Error(`[AppAdapter] Non-Krnl app '${this.entityName}' failed to boot on port ${this.appPort} within 15s.`);
|
|
69
|
-
}
|
|
70
|
-
console.log(`[AppAdapter] Non-Krnl app '${this.entityName}' successfully booted.`);
|
|
71
|
-
}
|
|
72
|
-
async proxyRequest(req, res, subPath) {
|
|
73
|
-
if (this.appPort === -1) {
|
|
74
|
-
res.writeHead(503, { "Content-Type": "application/json" });
|
|
75
|
-
res.end(JSON.stringify({ status: "error", message: "Service Temporarily Unavailable: Sub-app not running." }));
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const options = {
|
|
79
|
-
hostname: "127.0.0.1",
|
|
80
|
-
port: this.appPort,
|
|
81
|
-
path: subPath,
|
|
82
|
-
method: req.method,
|
|
83
|
-
headers: req.headers
|
|
84
|
-
};
|
|
85
|
-
const proxyReq = http.request(options, (proxyRes) => {
|
|
86
|
-
res.writeHead(proxyRes.statusCode || 500, proxyRes.headers);
|
|
87
|
-
proxyRes.pipe(res);
|
|
88
|
-
});
|
|
89
|
-
proxyReq.on("error", (err) => {
|
|
90
|
-
res.writeHead(502, { "Content-Type": "application/json" });
|
|
91
|
-
res.end(JSON.stringify({ status: "error", message: `Bad Gateway: ${err.message}` }));
|
|
92
|
-
});
|
|
93
|
-
req.pipe(proxyReq);
|
|
94
|
-
}
|
|
95
|
-
dispose() {
|
|
96
|
-
if (this.childProcess) {
|
|
97
|
-
console.log(`[AppAdapter] Killing child process (PID: ${this.childProcess.pid}) for '${this.entityName}'`);
|
|
98
|
-
this.childProcess.kill("SIGTERM");
|
|
99
|
-
this.childProcess = null;
|
|
100
|
-
}
|
|
101
|
-
super.dispose();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export {
|
|
106
|
-
KrnlNonKrnlAppAdapter
|
|
107
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
subappLocalStorage
|
|
3
|
-
} from "./chunk-NDDOIRW7.js";
|
|
4
|
-
|
|
5
|
-
// src/core/K_LIB_Krnl_SubApp_Registry.ts
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { pathToFileURL } from "url";
|
|
8
|
-
var KrnlSubAppLoader = class {
|
|
9
|
-
/**
|
|
10
|
-
* Loads a single sub-app into the parent entity's _subAppRegistry.
|
|
11
|
-
*
|
|
12
|
-
* For 'local' mode the sub-app class is instantiated directly in the parent process.
|
|
13
|
-
* Networking is suppressed automatically because the entity is constructed inside the
|
|
14
|
-
* subappLocalStorage async context (sets _isSubApp = true) and _startSharedServer()
|
|
15
|
-
* returns early for sub-app entities.
|
|
16
|
-
*
|
|
17
|
-
* For 'worker' mode a worker_thread is spawned and a KrnlSubAppWorkerHost proxy is
|
|
18
|
-
* registered in its place. All calls transit via MessagePort — no TCP/HTTP involved.
|
|
19
|
-
*/
|
|
20
|
-
static async load(parent, config) {
|
|
21
|
-
const mode = config.executionMode ?? "local";
|
|
22
|
-
const prefix = config.prefix.toLowerCase();
|
|
23
|
-
if (parent._subAppRegistry.has(prefix)) {
|
|
24
|
-
console.log(`[SubAppRegistry] Sub-app '${prefix}' already registered. Skipping.`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
let entry;
|
|
28
|
-
if (mode === "local") {
|
|
29
|
-
const appDir = config.entryPath ? path.dirname(config.entryPath) : "";
|
|
30
|
-
let entity;
|
|
31
|
-
if (config.isKrnl === false || !config.ServiceClass) {
|
|
32
|
-
const { KrnlNonKrnlAppAdapter } = await import("./K_LIB_Krnl_System_App_Adapter-VHCT6VIW.js");
|
|
33
|
-
const adapter = new KrnlNonKrnlAppAdapter(config.prefix, config.entryPath || "");
|
|
34
|
-
await adapter.startApp();
|
|
35
|
-
entity = adapter;
|
|
36
|
-
} else {
|
|
37
|
-
const options = { host: "0.0.0.0" };
|
|
38
|
-
if (config.entryPath) options.sourcePath = pathToFileURL(config.entryPath).href;
|
|
39
|
-
entity = await subappLocalStorage.run({ appPath: appDir }, async () => {
|
|
40
|
-
const inst = new config.ServiceClass(-1, options, ...config.constructorArgs ?? []);
|
|
41
|
-
if (typeof inst.boot === "function") {
|
|
42
|
-
try {
|
|
43
|
-
await inst.boot();
|
|
44
|
-
} catch (bootErr) {
|
|
45
|
-
console.warn(`[SubAppRegistry] Auto-boot warning on sub-app '${prefix}':`, bootErr.message || bootErr);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (inst._magneticLoadPromise) {
|
|
49
|
-
await inst._magneticLoadPromise;
|
|
50
|
-
}
|
|
51
|
-
return inst;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (typeof entity._resolveReady === "function") {
|
|
55
|
-
entity._resolveReady();
|
|
56
|
-
}
|
|
57
|
-
parent.hierarchyManager.addComponentEntityInstance(entity);
|
|
58
|
-
entry = {
|
|
59
|
-
prefix,
|
|
60
|
-
executionMode: "local",
|
|
61
|
-
entity,
|
|
62
|
-
addedAt: Date.now()
|
|
63
|
-
};
|
|
64
|
-
console.log(`[SubAppRegistry] Loaded sub-app '${prefix}' in LOCAL mode (in-process).`);
|
|
65
|
-
} else {
|
|
66
|
-
const { KrnlSubAppWorkerHost } = await import("./K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7.js");
|
|
67
|
-
const host = await KrnlSubAppWorkerHost.create(config);
|
|
68
|
-
entry = {
|
|
69
|
-
prefix,
|
|
70
|
-
executionMode: "worker",
|
|
71
|
-
entity: host,
|
|
72
|
-
addedAt: Date.now()
|
|
73
|
-
};
|
|
74
|
-
console.log(`[SubAppRegistry] Loaded sub-app '${prefix}' in WORKER mode (isolated thread).`);
|
|
75
|
-
}
|
|
76
|
-
parent._subAppRegistry.set(prefix, entry);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export {
|
|
81
|
-
KrnlSubAppLoader
|
|
82
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__esm,
|
|
3
|
-
__export
|
|
4
|
-
} from "./chunk-KFQGP6VL.js";
|
|
5
|
-
|
|
6
|
-
// src/core/K_LIB_Krnl_Frontend_Builder.ts
|
|
7
|
-
var K_LIB_Krnl_Frontend_Builder_exports = {};
|
|
8
|
-
__export(K_LIB_Krnl_Frontend_Builder_exports, {
|
|
9
|
-
KrnlFrontendBuilder: () => KrnlFrontendBuilder
|
|
10
|
-
});
|
|
11
|
-
import fs from "fs";
|
|
12
|
-
import path from "path";
|
|
13
|
-
var KrnlFrontendBuilder;
|
|
14
|
-
var init_K_LIB_Krnl_Frontend_Builder = __esm({
|
|
15
|
-
"src/core/K_LIB_Krnl_Frontend_Builder.ts"() {
|
|
16
|
-
KrnlFrontendBuilder = class {
|
|
17
|
-
static activeContexts = /* @__PURE__ */ new Map();
|
|
18
|
-
/**
|
|
19
|
-
* Bundles frontend/src/index.ts -> frontend/dist/bundle.js
|
|
20
|
-
*/
|
|
21
|
-
static async build(frontendDir) {
|
|
22
|
-
const entryFileTs = path.join(frontendDir, "src", "index.ts");
|
|
23
|
-
const entryFileTsx = path.join(frontendDir, "src", "index.tsx");
|
|
24
|
-
const entryFile = fs.existsSync(entryFileTs) ? entryFileTs : entryFileTsx;
|
|
25
|
-
if (!fs.existsSync(entryFile)) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const distDir = path.join(frontendDir, "dist");
|
|
29
|
-
fs.mkdirSync(distDir, { recursive: true });
|
|
30
|
-
try {
|
|
31
|
-
const candidates = [
|
|
32
|
-
// When running from inside KrnlTS dist (relative to __dirname)
|
|
33
|
-
path.resolve(__dirname, "..", "..", "frontend", "atoms"),
|
|
34
|
-
path.resolve(__dirname, "..", "frontend", "atoms"),
|
|
35
|
-
// Scoped package (@dinilmusick/krnlts) installed in consuming app
|
|
36
|
-
path.resolve(process.cwd(), "node_modules", "@dinilmusick", "krnlts", "dist", "frontend", "atoms"),
|
|
37
|
-
path.resolve(process.cwd(), "node_modules", "@dinilmusick", "krnlts", "src", "krnl", "frontend", "atoms"),
|
|
38
|
-
// Unscoped fallback (krnlts)
|
|
39
|
-
path.resolve(process.cwd(), "node_modules", "krnlts", "dist", "frontend", "atoms"),
|
|
40
|
-
path.resolve(process.cwd(), "node_modules", "krnlts", "src", "krnl", "frontend", "atoms")
|
|
41
|
-
];
|
|
42
|
-
const nodeModulesAtoms = candidates.find((c) => fs.existsSync(c));
|
|
43
|
-
const srcAtoms = path.join(frontendDir, "src", "atoms");
|
|
44
|
-
if (nodeModulesAtoms) {
|
|
45
|
-
fs.mkdirSync(srcAtoms, { recursive: true });
|
|
46
|
-
fs.cpSync(nodeModulesAtoms, srcAtoms, { recursive: true, force: true });
|
|
47
|
-
console.log(`[KrnlFrontendBuilder] Atoms synced from ${nodeModulesAtoms}`);
|
|
48
|
-
} else {
|
|
49
|
-
console.warn(`[KrnlFrontendBuilder] No atoms source found in any candidate path.`);
|
|
50
|
-
}
|
|
51
|
-
} catch (e) {
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const esbuild = await import("esbuild");
|
|
55
|
-
console.log(`[KrnlFrontendBuilder] Bundling ${entryFile} -> ${distDir}/bundle.js...`);
|
|
56
|
-
await esbuild.build({
|
|
57
|
-
entryPoints: [entryFile],
|
|
58
|
-
bundle: true,
|
|
59
|
-
outfile: path.join(distDir, "bundle.js"),
|
|
60
|
-
loader: {
|
|
61
|
-
".css": "css",
|
|
62
|
-
".ts": "ts",
|
|
63
|
-
".js": "js"
|
|
64
|
-
},
|
|
65
|
-
sourcemap: process.env.NODE_ENV !== "production",
|
|
66
|
-
minify: process.env.NODE_ENV === "production",
|
|
67
|
-
logLevel: "warning"
|
|
68
|
-
});
|
|
69
|
-
console.log(`[KrnlFrontendBuilder] Bundle build successful.`);
|
|
70
|
-
return true;
|
|
71
|
-
} catch (err) {
|
|
72
|
-
if (err.code === "ERR_MODULE_NOT_FOUND" || err.message?.includes("Cannot find module")) {
|
|
73
|
-
console.warn(`[KrnlFrontendBuilder] esbuild peer dependency not found. Skipping build. Run 'npm i esbuild' to enable in-process UI compilation.`);
|
|
74
|
-
} else {
|
|
75
|
-
console.error(`[KrnlFrontendBuilder] Build failed:`, err.message || err);
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Starts esbuild watch mode for live updates during development
|
|
82
|
-
*/
|
|
83
|
-
static async watch(frontendDir) {
|
|
84
|
-
if (this.activeContexts.has(frontendDir)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const entryFileTs = path.join(frontendDir, "src", "index.ts");
|
|
88
|
-
const entryFileTsx = path.join(frontendDir, "src", "index.tsx");
|
|
89
|
-
const entryFile = fs.existsSync(entryFileTs) ? entryFileTs : entryFileTsx;
|
|
90
|
-
if (!fs.existsSync(entryFile)) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
const esbuild = await import("esbuild");
|
|
95
|
-
const ctx = await esbuild.context({
|
|
96
|
-
entryPoints: [entryFile],
|
|
97
|
-
bundle: true,
|
|
98
|
-
outfile: path.join(frontendDir, "dist", "bundle.js"),
|
|
99
|
-
loader: {
|
|
100
|
-
".css": "css",
|
|
101
|
-
".ts": "ts",
|
|
102
|
-
".js": "js"
|
|
103
|
-
},
|
|
104
|
-
logLevel: "warning"
|
|
105
|
-
});
|
|
106
|
-
await ctx.watch();
|
|
107
|
-
this.activeContexts.set(frontendDir, ctx);
|
|
108
|
-
console.log(`[KrnlFrontendBuilder] esbuild watching ${frontendDir}/src for changes.`);
|
|
109
|
-
} catch (err) {
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
static stop(frontendDir) {
|
|
113
|
-
const ctx = this.activeContexts.get(frontendDir);
|
|
114
|
-
if (ctx) {
|
|
115
|
-
ctx.dispose();
|
|
116
|
-
this.activeContexts.delete(frontendDir);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
export {
|
|
124
|
-
KrnlFrontendBuilder,
|
|
125
|
-
K_LIB_Krnl_Frontend_Builder_exports,
|
|
126
|
-
init_K_LIB_Krnl_Frontend_Builder
|
|
127
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Logger
|
|
3
|
-
} from "./chunk-K54K2KZW.js";
|
|
4
|
-
|
|
5
|
-
// src/core/K_LIB_Krnl_Registry_Client.ts
|
|
6
|
-
var KrnlRegistryClient = class {
|
|
7
|
-
constructor(registryPort = 10099) {
|
|
8
|
-
this.registryPort = registryPort;
|
|
9
|
-
}
|
|
10
|
-
registryPort;
|
|
11
|
-
getUrl(action) {
|
|
12
|
-
return `http://127.0.0.1:${this.registryPort}/call/${action}`;
|
|
13
|
-
}
|
|
14
|
-
async isRegistryAlive() {
|
|
15
|
-
try {
|
|
16
|
-
const controller = new AbortController();
|
|
17
|
-
const id = setTimeout(() => controller.abort(), 800);
|
|
18
|
-
const res = await fetch(this.getUrl("heartbeat"), {
|
|
19
|
-
method: "POST",
|
|
20
|
-
headers: { "Content-Type": "application/json" },
|
|
21
|
-
body: JSON.stringify({}),
|
|
22
|
-
signal: controller.signal
|
|
23
|
-
});
|
|
24
|
-
clearTimeout(id);
|
|
25
|
-
return res.ok;
|
|
26
|
-
} catch (_) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async register(name, port, pid) {
|
|
31
|
-
try {
|
|
32
|
-
const res = await fetch(this.getUrl("registerApp"), {
|
|
33
|
-
method: "POST",
|
|
34
|
-
headers: { "Content-Type": "application/json" },
|
|
35
|
-
body: JSON.stringify({ name, port, pid })
|
|
36
|
-
});
|
|
37
|
-
if (res.ok) {
|
|
38
|
-
const body = await res.json();
|
|
39
|
-
return body?.status === "success" || body?.success === true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
} catch (err) {
|
|
43
|
-
Logger.error(`[KrnlRegistryClient] Register error:`, err.message);
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
async deregister(name) {
|
|
48
|
-
try {
|
|
49
|
-
const res = await fetch(this.getUrl("deregisterApp"), {
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers: { "Content-Type": "application/json" },
|
|
52
|
-
body: JSON.stringify({ name })
|
|
53
|
-
});
|
|
54
|
-
if (res.ok) {
|
|
55
|
-
const body = await res.json();
|
|
56
|
-
return body?.status === "success" || body?.success === true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
} catch (err) {
|
|
60
|
-
Logger.error(`[KrnlRegistryClient] Deregister error:`, err.message);
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async heartbeat(name) {
|
|
65
|
-
try {
|
|
66
|
-
const res = await fetch(this.getUrl("heartbeatApp"), {
|
|
67
|
-
method: "POST",
|
|
68
|
-
headers: { "Content-Type": "application/json" },
|
|
69
|
-
body: JSON.stringify({ name })
|
|
70
|
-
});
|
|
71
|
-
if (res.ok) {
|
|
72
|
-
const body = await res.json();
|
|
73
|
-
return body?.status === "success" || body?.success === true;
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
} catch (err) {
|
|
77
|
-
Logger.error(`[KrnlRegistryClient] Heartbeat error:`, err.message);
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async lookup(name) {
|
|
82
|
-
try {
|
|
83
|
-
const res = await fetch(this.getUrl("lookupApp"), {
|
|
84
|
-
method: "POST",
|
|
85
|
-
headers: { "Content-Type": "application/json" },
|
|
86
|
-
body: JSON.stringify({ name })
|
|
87
|
-
});
|
|
88
|
-
if (res.ok) {
|
|
89
|
-
const body = await res.json();
|
|
90
|
-
const payload = body?.payload || body?.data || body;
|
|
91
|
-
if (payload && payload.port) {
|
|
92
|
-
return payload;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
} catch (_) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export {
|
|
103
|
-
KrnlRegistryClient
|
|
104
|
-
};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
// src/core/K_LIB_Krnl_SubApp_Worker_Host.ts
|
|
2
|
-
import { Worker } from "worker_threads";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import path from "path";
|
|
5
|
-
var __filename = fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = path.dirname(__filename);
|
|
7
|
-
var _rpcSeq = 0;
|
|
8
|
-
var KrnlSubAppWorkerHost = class _KrnlSubAppWorkerHost {
|
|
9
|
-
prefix;
|
|
10
|
-
_worker;
|
|
11
|
-
_manifest;
|
|
12
|
-
_pending;
|
|
13
|
-
_ready;
|
|
14
|
-
_resolveReady;
|
|
15
|
-
_rejectReady;
|
|
16
|
-
constructor(prefix, worker) {
|
|
17
|
-
this.prefix = prefix;
|
|
18
|
-
this._worker = worker;
|
|
19
|
-
this._manifest = null;
|
|
20
|
-
this._pending = /* @__PURE__ */ new Map();
|
|
21
|
-
this._ready = new Promise((resolve, reject) => {
|
|
22
|
-
this._resolveReady = resolve;
|
|
23
|
-
this._rejectReady = reject;
|
|
24
|
-
});
|
|
25
|
-
this._worker.on("message", (msg) => {
|
|
26
|
-
if (msg.type === "manifest") {
|
|
27
|
-
this._manifest = msg.manifest;
|
|
28
|
-
this._resolveReady();
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (msg.type === "result") {
|
|
32
|
-
const pending = this._pending.get(msg.requestId);
|
|
33
|
-
if (!pending) return;
|
|
34
|
-
clearTimeout(pending.timeoutId);
|
|
35
|
-
this._pending.delete(msg.requestId);
|
|
36
|
-
if (msg.ok) pending.resolve(msg.result);
|
|
37
|
-
else pending.reject(new Error(msg.error || "Worker sub-app error"));
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
this._worker.on("error", (err) => {
|
|
41
|
-
console.error(`[SubAppWorkerHost:${prefix}] Worker error:`, err.message || err);
|
|
42
|
-
this._rejectReady(err instanceof Error ? err : new Error(String(err)));
|
|
43
|
-
for (const [id, p] of this._pending) {
|
|
44
|
-
clearTimeout(p.timeoutId);
|
|
45
|
-
p.reject(err);
|
|
46
|
-
this._pending.delete(id);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
this._worker.on("exit", (code) => {
|
|
50
|
-
if (code !== 0) {
|
|
51
|
-
console.error(`[SubAppWorkerHost:${prefix}] Worker exited with code ${code}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Spawn a worker_thread for the given sub-app config and wait for the manifest.
|
|
57
|
-
*/
|
|
58
|
-
static async create(config, timeoutMs = 3e4) {
|
|
59
|
-
const runtimePath = path.resolve(__dirname, "K_LIB_Krnl_SubApp_Worker_Runtime.js");
|
|
60
|
-
const worker = new Worker(runtimePath, {
|
|
61
|
-
workerData: {
|
|
62
|
-
entryPath: config.entryPath ?? "",
|
|
63
|
-
prefix: config.prefix,
|
|
64
|
-
constructorArgs: config.constructorArgs ?? []
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const host = new _KrnlSubAppWorkerHost(config.prefix, worker);
|
|
68
|
-
const timeout = new Promise(
|
|
69
|
-
(_, reject) => setTimeout(() => reject(new Error(`[SubAppWorkerHost:${config.prefix}] Timed out waiting for worker ready signal.`)), timeoutMs)
|
|
70
|
-
);
|
|
71
|
-
await Promise.race([host._ready, timeout]);
|
|
72
|
-
return host;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Call a functionality on the worker-hosted sub-app.
|
|
76
|
-
* This is the primary dispatch path for worker-mode sub-apps.
|
|
77
|
-
* Uses MessagePort IPC — no networking.
|
|
78
|
-
*/
|
|
79
|
-
async callInternal(fid, input = {}, timeoutMs = 3e4) {
|
|
80
|
-
const requestId = `wkr_${Date.now()}_${(_rpcSeq++).toString(36)}`;
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
const timeoutId = setTimeout(() => {
|
|
83
|
-
this._pending.delete(requestId);
|
|
84
|
-
reject(new Error(`[SubAppWorkerHost:${this.prefix}] Call '${fid}' timed out after ${timeoutMs}ms`));
|
|
85
|
-
}, timeoutMs);
|
|
86
|
-
this._pending.set(requestId, { resolve, reject, timeoutId });
|
|
87
|
-
this._worker.postMessage({ type: "call", requestId, fid, input });
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Alias so both local entities and worker hosts expose the same dispatch surface.
|
|
92
|
-
*/
|
|
93
|
-
async call(fid, input = {}) {
|
|
94
|
-
return this.callInternal(fid, input);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Returns the sub-app manifest obtained from the worker at startup.
|
|
98
|
-
*/
|
|
99
|
-
getManifest() {
|
|
100
|
-
return this._manifest;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Terminate the worker thread gracefully.
|
|
104
|
-
*/
|
|
105
|
-
async gracefulShutdown() {
|
|
106
|
-
try {
|
|
107
|
-
this._worker.postMessage({ type: "shutdown" });
|
|
108
|
-
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
109
|
-
} finally {
|
|
110
|
-
await this._worker.terminate();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export {
|
|
116
|
-
KrnlSubAppWorkerHost
|
|
117
|
-
};
|