@ultrst-armada/krnl 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -65
- package/package.json +15 -8
- package/packages/cli/dist/bin/krnl.cjs +808 -331
- package/packages/cli/dist/bin/krnl.js +50 -65
- package/packages/cli/dist/chunk-GHWYEAPD.js +1642 -0
- package/packages/cli/dist/index.cjs +761 -263
- 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 -1
- package/packages/cli/package.json +17 -10
- package/packages/core/dist/index.cjs +2912 -140
- package/packages/core/dist/index.d.cts +614 -27
- package/packages/core/dist/index.d.ts +614 -27
- package/packages/core/dist/index.js +2903 -140
- package/packages/core/package.json +15 -6
- package/packages/create-krnl/dist/index.cjs +102 -65
- package/packages/create-krnl/dist/index.js +102 -65
- 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 +378 -85
- package/packages/validate/dist/index.d.cts +11 -1
- package/packages/validate/dist/index.d.ts +11 -1
- package/packages/validate/dist/index.js +375 -82
- 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-ESTKOQ7T.js +0 -1146
- 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-FZ6X7PHR.js +0 -1146
- 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,949 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
krnlEntityBase,
|
|
3
|
-
krnlLocalFunctionality
|
|
4
|
-
} from "./chunk-XSCKNRCZ.js";
|
|
5
|
-
import {
|
|
6
|
-
ObjectKit
|
|
7
|
-
} from "./chunk-MLVWARD4.js";
|
|
8
|
-
import {
|
|
9
|
-
KrnlSubAppDiscovery,
|
|
10
|
-
KrnlSubAppLifecycle,
|
|
11
|
-
KrnlSubAppValidator
|
|
12
|
-
} from "./chunk-OEINUDSE.js";
|
|
13
|
-
|
|
14
|
-
// src/core/K_LIB_Krnl_Flow.ts
|
|
15
|
-
var OrchestrationRuleViolationError = class extends Error {
|
|
16
|
-
constructor(message) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = "OrchestrationRuleViolationError";
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var OrchestrationChain = class _OrchestrationChain {
|
|
22
|
-
entity;
|
|
23
|
-
id;
|
|
24
|
-
steps = [];
|
|
25
|
-
consecutiveFunctionCalls = 0;
|
|
26
|
-
constructor(entity, id) {
|
|
27
|
-
this.entity = entity;
|
|
28
|
-
this.id = id;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Chain a local functionality call on the entity.
|
|
32
|
-
* Resets the consecutive function call counter to 0.
|
|
33
|
-
*/
|
|
34
|
-
thenFunctionality(fid) {
|
|
35
|
-
this.steps.push({ type: "functionality", fid });
|
|
36
|
-
this.consecutiveFunctionCalls = 0;
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Sequential alias for thenFunctionality.
|
|
41
|
-
*/
|
|
42
|
-
then(fid) {
|
|
43
|
-
return this.thenFunctionality(fid);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Chain an imported global library function call.
|
|
47
|
-
* Enforces the rule: maximum 2 consecutive global function calls between functionalities.
|
|
48
|
-
*/
|
|
49
|
-
thenFunction(fnOrRef, libName) {
|
|
50
|
-
if (this.consecutiveFunctionCalls >= 2) {
|
|
51
|
-
throw new OrchestrationRuleViolationError(
|
|
52
|
-
`Orchestration Rule Violation in chain '${this.id}': Cannot chain more than 2 global functions between functionalities (Functionality1 -> Function1 -> Function2 -> Functionality2). Compose additional logic into a single library function in a global library file instead.`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
if (typeof fnOrRef === "function") {
|
|
56
|
-
const fnName = fnOrRef.name || "anonymousLibraryFunction";
|
|
57
|
-
this.steps.push({
|
|
58
|
-
type: "function",
|
|
59
|
-
fn: fnOrRef,
|
|
60
|
-
fnName,
|
|
61
|
-
libName: libName || "GlobalLibrary"
|
|
62
|
-
});
|
|
63
|
-
} else {
|
|
64
|
-
this.steps.push({
|
|
65
|
-
type: "function",
|
|
66
|
-
fnName: fnOrRef,
|
|
67
|
-
libName: libName || "GlobalLibrary"
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
this.consecutiveFunctionCalls++;
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Built-in Flow Control: Branching
|
|
75
|
-
* Evaluates predicate; routes output to trueBranch or falseBranch.
|
|
76
|
-
*/
|
|
77
|
-
branch(pred, trueBranch, falseBranch) {
|
|
78
|
-
let resolvedTrue;
|
|
79
|
-
if (typeof trueBranch === "function") {
|
|
80
|
-
const sub = new _OrchestrationChain(this.entity, `${this.id}_branch_true`);
|
|
81
|
-
trueBranch(sub);
|
|
82
|
-
resolvedTrue = sub;
|
|
83
|
-
} else {
|
|
84
|
-
resolvedTrue = trueBranch;
|
|
85
|
-
}
|
|
86
|
-
let resolvedFalse = void 0;
|
|
87
|
-
if (falseBranch) {
|
|
88
|
-
if (typeof falseBranch === "function") {
|
|
89
|
-
const sub = new _OrchestrationChain(this.entity, `${this.id}_branch_false`);
|
|
90
|
-
falseBranch(sub);
|
|
91
|
-
resolvedFalse = sub;
|
|
92
|
-
} else {
|
|
93
|
-
resolvedFalse = falseBranch;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this.steps.push({
|
|
97
|
-
type: "branch",
|
|
98
|
-
pred,
|
|
99
|
-
trueChain: resolvedTrue,
|
|
100
|
-
falseChain: resolvedFalse
|
|
101
|
-
});
|
|
102
|
-
this.consecutiveFunctionCalls = 0;
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Built-in Flow Control: Switching
|
|
107
|
-
* Evaluates keyFn on the current payload and routes to matching branch.
|
|
108
|
-
*/
|
|
109
|
-
switch(keyFn, cases, defaultCase) {
|
|
110
|
-
const resolvedCases = {};
|
|
111
|
-
for (const [key, handler] of Object.entries(cases)) {
|
|
112
|
-
if (typeof handler === "function") {
|
|
113
|
-
const sub = new _OrchestrationChain(this.entity, `${this.id}_case_${key}`);
|
|
114
|
-
handler(sub);
|
|
115
|
-
resolvedCases[key] = sub;
|
|
116
|
-
} else {
|
|
117
|
-
resolvedCases[key] = handler;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
let resolvedDefault = void 0;
|
|
121
|
-
if (defaultCase) {
|
|
122
|
-
if (typeof defaultCase === "function") {
|
|
123
|
-
const sub = new _OrchestrationChain(this.entity, `${this.id}_default`);
|
|
124
|
-
defaultCase(sub);
|
|
125
|
-
resolvedDefault = sub;
|
|
126
|
-
} else {
|
|
127
|
-
resolvedDefault = defaultCase;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
this.steps.push({
|
|
131
|
-
type: "switch",
|
|
132
|
-
keyFn,
|
|
133
|
-
cases: resolvedCases,
|
|
134
|
-
defaultCase: resolvedDefault
|
|
135
|
-
});
|
|
136
|
-
this.consecutiveFunctionCalls = 0;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Built-in Flow Control: Merging
|
|
141
|
-
* Joins multiple branch pathways or parallel results into current chain.
|
|
142
|
-
*/
|
|
143
|
-
merge(...branchNames) {
|
|
144
|
-
this.steps.push({
|
|
145
|
-
type: "merge",
|
|
146
|
-
mergeBranches: branchNames
|
|
147
|
-
});
|
|
148
|
-
this.consecutiveFunctionCalls = 0;
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Built-in Flow Control: Parallel
|
|
153
|
-
* Runs all targets concurrently with current input, returning array of results.
|
|
154
|
-
*/
|
|
155
|
-
parallel(...targets) {
|
|
156
|
-
const parallelSteps = targets.map((t) => {
|
|
157
|
-
if (typeof t === "string") {
|
|
158
|
-
return { type: "functionality", target: t };
|
|
159
|
-
}
|
|
160
|
-
return { type: "function", target: t };
|
|
161
|
-
});
|
|
162
|
-
this.steps.push({
|
|
163
|
-
type: "parallel",
|
|
164
|
-
parallelSteps
|
|
165
|
-
});
|
|
166
|
-
this.consecutiveFunctionCalls = 0;
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Returns copy of all orchestration steps in this chain.
|
|
171
|
-
*/
|
|
172
|
-
getSteps() {
|
|
173
|
-
return [...this.steps];
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Register this orchestration chain as a local capability on the host entity.
|
|
177
|
-
*/
|
|
178
|
-
register(opts) {
|
|
179
|
-
const steps = [...this.steps];
|
|
180
|
-
const entity = this.entity;
|
|
181
|
-
const chainId = this.id;
|
|
182
|
-
return entity.addLocal({
|
|
183
|
-
id: chainId,
|
|
184
|
-
visibility: opts?.visibility ?? "public",
|
|
185
|
-
description: opts?.description || `Orchestration [${chainId}] composing [${steps.map((s) => s.fid || s.fnName || s.type).join(" \u2192 ")}]`,
|
|
186
|
-
uiSpec: opts?.uiSpec,
|
|
187
|
-
intelligenceSpec: opts?.intelligenceSpec,
|
|
188
|
-
manifest: opts?.manifest,
|
|
189
|
-
api: async (input) => _OrchestrationChain._execute(entity, steps, input)
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
/** Execute the chain directly */
|
|
193
|
-
async run(input) {
|
|
194
|
-
return _OrchestrationChain._execute(this.entity, this.steps, input);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Inbuilt step executor walking functionalities, global library functions, and flow constructs.
|
|
198
|
-
*/
|
|
199
|
-
static async _execute(entity, steps, input) {
|
|
200
|
-
let current = input;
|
|
201
|
-
for (const step of steps) {
|
|
202
|
-
if (step.type === "functionality") {
|
|
203
|
-
current = await entity.call(step.fid, current);
|
|
204
|
-
} else if (step.type === "function") {
|
|
205
|
-
if (typeof step.fn === "function") {
|
|
206
|
-
current = await step.fn(current);
|
|
207
|
-
} else if (step.fnName) {
|
|
208
|
-
const libMethod = entity[step.fnName] || globalThis[step.fnName];
|
|
209
|
-
if (typeof libMethod === "function") {
|
|
210
|
-
current = await libMethod(current);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
} else if (step.type === "branch") {
|
|
214
|
-
const matches = step.pred ? step.pred(current) : Boolean(current);
|
|
215
|
-
const branchTarget = matches ? step.trueChain : step.falseChain;
|
|
216
|
-
if (branchTarget instanceof _OrchestrationChain) {
|
|
217
|
-
current = await branchTarget.run(current);
|
|
218
|
-
} else if (typeof branchTarget === "string") {
|
|
219
|
-
current = await entity.call(branchTarget, current);
|
|
220
|
-
}
|
|
221
|
-
} else if (step.type === "switch") {
|
|
222
|
-
const key = step.keyFn ? step.keyFn(current) : String(current);
|
|
223
|
-
const branchTarget = step.cases && step.cases[key] ? step.cases[key] : step.defaultCase;
|
|
224
|
-
if (branchTarget instanceof _OrchestrationChain) {
|
|
225
|
-
current = await branchTarget.run(current);
|
|
226
|
-
} else if (typeof branchTarget === "string") {
|
|
227
|
-
current = await entity.call(branchTarget, current);
|
|
228
|
-
}
|
|
229
|
-
} else if (step.type === "merge") {
|
|
230
|
-
if (Array.isArray(current) && current.length > 0 && Array.isArray(current[0])) {
|
|
231
|
-
current = current.flat();
|
|
232
|
-
}
|
|
233
|
-
} else if (step.type === "parallel") {
|
|
234
|
-
const pSteps = step.parallelSteps || [];
|
|
235
|
-
current = await Promise.all(pSteps.map((ps) => {
|
|
236
|
-
if (ps.type === "functionality" && typeof ps.target === "string") {
|
|
237
|
-
return entity.call(ps.target, current);
|
|
238
|
-
} else if (typeof ps.target === "function") {
|
|
239
|
-
return ps.target(current);
|
|
240
|
-
}
|
|
241
|
-
return current;
|
|
242
|
-
}));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return current;
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
var KrnlFlowBuilder = class extends OrchestrationChain {
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// src/core/K_ENT_Entity.ts
|
|
252
|
-
var Entity = class _Entity extends krnlEntityBase {
|
|
253
|
-
/** Strongly-typed reactive entity state */
|
|
254
|
-
state;
|
|
255
|
-
/** True while this entity occupies root position and actively self-hosts protocol adapters */
|
|
256
|
-
_selfHosting = false;
|
|
257
|
-
/** Protocol adapters attached to this entity. Operational only in root position. */
|
|
258
|
-
_protocolAdapters = /* @__PURE__ */ new Map();
|
|
259
|
-
/** Sub-Apps registered directly under this entity */
|
|
260
|
-
_subApps = /* @__PURE__ */ new Map();
|
|
261
|
-
/** Reservation state for access control and mutual exclusion */
|
|
262
|
-
reservation = {
|
|
263
|
-
busy: false,
|
|
264
|
-
reservedBy: null,
|
|
265
|
-
reservedAt: null
|
|
266
|
-
};
|
|
267
|
-
/** Discoverability state for network beacons / registries */
|
|
268
|
-
discoverable = true;
|
|
269
|
-
constructor(name, owner = null, options = {}) {
|
|
270
|
-
super(name, owner, options);
|
|
271
|
-
this.systemType = "Entity";
|
|
272
|
-
this.state = options.initialState ?? {};
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Get an immutable, read-only snapshot of current entity state.
|
|
276
|
-
*/
|
|
277
|
-
getState() {
|
|
278
|
-
return Object.freeze(ObjectKit.deepClone(this.state));
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Mutates the entity state via deep-merge and emits a reactive state:changed event.
|
|
282
|
-
*/
|
|
283
|
-
setState(mutation) {
|
|
284
|
-
this.state = ObjectKit.deepMerge(this.state, mutation);
|
|
285
|
-
this.emit("state:changed", {
|
|
286
|
-
entity: this.entityName,
|
|
287
|
-
delta: mutation,
|
|
288
|
-
state: this.getState()
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Resets entity state to a new or initial baseline.
|
|
293
|
-
*/
|
|
294
|
-
resetState(newState) {
|
|
295
|
-
this.state = newState ?? {};
|
|
296
|
-
this.emit("state:reset", {
|
|
297
|
-
entity: this.entityName,
|
|
298
|
-
state: this.getState()
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
/** Private cache mapping event names to krnlEmitters */
|
|
302
|
-
_eventEmitterMap = /* @__PURE__ */ new Map();
|
|
303
|
-
/**
|
|
304
|
-
* Subscribes a listener to a domain event on this entity.
|
|
305
|
-
*/
|
|
306
|
-
on(event, handler) {
|
|
307
|
-
let emitter = this._eventEmitterMap.get(event);
|
|
308
|
-
if (!emitter) {
|
|
309
|
-
emitter = this.interface.createEmitter(event);
|
|
310
|
-
this._eventEmitterMap.set(event, emitter);
|
|
311
|
-
}
|
|
312
|
-
return emitter.subscribe((msg) => handler(msg.data));
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Emits an event with a data payload to all subscribers.
|
|
316
|
-
*/
|
|
317
|
-
emit(event, payload) {
|
|
318
|
-
let emitter = this._eventEmitterMap.get(event);
|
|
319
|
-
if (!emitter) {
|
|
320
|
-
emitter = this.interface.createEmitter(event);
|
|
321
|
-
this._eventEmitterMap.set(event, emitter);
|
|
322
|
-
}
|
|
323
|
-
emitter.pushDataStreamToEmitter(payload);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Dispatches a strongly-typed domain event.
|
|
327
|
-
*/
|
|
328
|
-
emitEvent(event, payload) {
|
|
329
|
-
this.emit(String(event), payload);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* System flags representing discoverability and reservation status.
|
|
333
|
-
*/
|
|
334
|
-
getSystemFlags() {
|
|
335
|
-
return {
|
|
336
|
-
discoverable: this.discoverable,
|
|
337
|
-
busy: this.reservation.busy,
|
|
338
|
-
reservedBy: this.reservation.reservedBy,
|
|
339
|
-
reservedAt: this.reservation.reservedAt
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Set discoverability status.
|
|
344
|
-
*/
|
|
345
|
-
setDiscoverable(value) {
|
|
346
|
-
this.discoverable = Boolean(value);
|
|
347
|
-
return this.getSystemFlags();
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Reserve this entity for exclusive access by serviceName.
|
|
351
|
-
*/
|
|
352
|
-
reserveFor(serviceName = "unknown") {
|
|
353
|
-
this.reservation = {
|
|
354
|
-
busy: true,
|
|
355
|
-
reservedBy: serviceName,
|
|
356
|
-
reservedAt: Date.now()
|
|
357
|
-
};
|
|
358
|
-
return this.getSystemFlags();
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Release reservation held by serviceName.
|
|
362
|
-
*/
|
|
363
|
-
releaseReservation(serviceName = null) {
|
|
364
|
-
if (serviceName && this.reservation.reservedBy && this.reservation.reservedBy !== serviceName) {
|
|
365
|
-
throw new Error(
|
|
366
|
-
`[${this.entityName}] Reservation owned by ${this.reservation.reservedBy}; cannot release as ${serviceName}.`
|
|
367
|
-
);
|
|
368
|
-
}
|
|
369
|
-
this.reservation = {
|
|
370
|
-
busy: false,
|
|
371
|
-
reservedBy: null,
|
|
372
|
-
reservedAt: null
|
|
373
|
-
};
|
|
374
|
-
return this.getSystemFlags();
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Guard checking if entity is available for remote caller.
|
|
378
|
-
*/
|
|
379
|
-
_assertAvailableForRemoteAccess(requester = null) {
|
|
380
|
-
if (!this.reservation.busy) return;
|
|
381
|
-
if (requester && requester === this.reservation.reservedBy) return;
|
|
382
|
-
const by = this.reservation.reservedBy || "another service";
|
|
383
|
-
throw new Error(`[${this.entityName}] Entity is busy/reserved by ${by}.`);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Get dynamic manifest of all capabilities, flags, and endpoints.
|
|
387
|
-
*/
|
|
388
|
-
getManifest() {
|
|
389
|
-
const apiNames = [];
|
|
390
|
-
const eventsNames = [];
|
|
391
|
-
const api = {};
|
|
392
|
-
for (const [id, f] of this.localFunctionalities) {
|
|
393
|
-
apiNames.push(id);
|
|
394
|
-
api[id] = {
|
|
395
|
-
id,
|
|
396
|
-
type: "local",
|
|
397
|
-
visibility: f.visibility || "public",
|
|
398
|
-
manifest: f.manifest || null,
|
|
399
|
-
schema: f.schema || null
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
for (const [id, f] of this.remoteFunctionalities) {
|
|
403
|
-
apiNames.push(id);
|
|
404
|
-
api[id] = {
|
|
405
|
-
id,
|
|
406
|
-
type: "remote",
|
|
407
|
-
visibility: f.visibility || "public",
|
|
408
|
-
schema: f.schema || null
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
return {
|
|
412
|
-
entity: this.entityName,
|
|
413
|
-
entityName: this.entityName,
|
|
414
|
-
type: this.systemType,
|
|
415
|
-
flags: this.getSystemFlags(),
|
|
416
|
-
apiNames,
|
|
417
|
-
eventsNames,
|
|
418
|
-
api,
|
|
419
|
-
inputs: {
|
|
420
|
-
api
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Generates a structured 404 response payload for unmatched routes.
|
|
426
|
-
*/
|
|
427
|
-
getNotFoundResponse(reqPath) {
|
|
428
|
-
return {
|
|
429
|
-
status: "error",
|
|
430
|
-
message: `Route not found: ${reqPath}`,
|
|
431
|
-
entity: this.entityName,
|
|
432
|
-
availableRoutes: [
|
|
433
|
-
"/call/:fid",
|
|
434
|
-
"/mcp",
|
|
435
|
-
"/acp",
|
|
436
|
-
"/manifest",
|
|
437
|
-
"/health",
|
|
438
|
-
"/events/:fid"
|
|
439
|
-
]
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
// ── Protocol Adapter Management ──────────────────────────────────────────
|
|
443
|
-
/**
|
|
444
|
-
* Attach a protocol adapter to this entity (declarative step during discovery/construction).
|
|
445
|
-
* Does NOT start the server. Servers are started only during `finalize()` if this entity is root.
|
|
446
|
-
*/
|
|
447
|
-
attachAdapter(adapter) {
|
|
448
|
-
if (!adapter || !adapter.name) {
|
|
449
|
-
throw new Error(`[Entity:${this.id}] Invalid protocol adapter provided.`);
|
|
450
|
-
}
|
|
451
|
-
this._protocolAdapters.set(adapter.name, adapter);
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Return all attached protocol adapters.
|
|
455
|
-
*/
|
|
456
|
-
getAdapters() {
|
|
457
|
-
return Array.from(this._protocolAdapters.values());
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Get a specific protocol adapter by name (e.g. 'https', 'wss').
|
|
461
|
-
*/
|
|
462
|
-
getAdapter(name) {
|
|
463
|
-
return this._protocolAdapters.get(name);
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Access the WebSocket commComponent adapter if attached.
|
|
467
|
-
*/
|
|
468
|
-
get commComponent() {
|
|
469
|
-
return this._protocolAdapters.get("wss");
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Access the Unified HTTP adapter if attached.
|
|
473
|
-
*/
|
|
474
|
-
get unifiedHttpAdapter() {
|
|
475
|
-
return this._protocolAdapters.get("https");
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Port of active listening adapter.
|
|
479
|
-
*/
|
|
480
|
-
get commPort() {
|
|
481
|
-
const http = this._protocolAdapters.get("https");
|
|
482
|
-
if (http && typeof http.port === "number") return http.port;
|
|
483
|
-
const wss = this._protocolAdapters.get("wss");
|
|
484
|
-
if (wss && typeof wss.listenPort === "number") return wss.listenPort;
|
|
485
|
-
return 10099;
|
|
486
|
-
}
|
|
487
|
-
// ── Activation / Finalize Lifecycle ──────────────────────────────────────
|
|
488
|
-
/**
|
|
489
|
-
* Finalizes construction and activates the entity if it occupies root position.
|
|
490
|
-
* Called after tree construction and Shell materialization.
|
|
491
|
-
*/
|
|
492
|
-
async finalize(options = {}) {
|
|
493
|
-
const hasParent = Boolean(this.hierarchyManager.getOwnerEntity());
|
|
494
|
-
if (!hasParent && this._protocolAdapters.size > 0 && !this._selfHosting) {
|
|
495
|
-
await this._startHosting(options);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Starts all attached protocol adapters.
|
|
500
|
-
*/
|
|
501
|
-
async _startHosting(options = {}) {
|
|
502
|
-
if (this._selfHosting) return;
|
|
503
|
-
for (const adapter of this._protocolAdapters.values()) {
|
|
504
|
-
try {
|
|
505
|
-
await adapter.start(this, options);
|
|
506
|
-
} catch (err) {
|
|
507
|
-
console.error(`[Entity:${this.id}] Error starting adapter '${adapter.name}':`, err.message || err);
|
|
508
|
-
throw err;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
this._selfHosting = true;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Stops all self-hosted protocol adapters gracefully.
|
|
515
|
-
*/
|
|
516
|
-
async stopHosting() {
|
|
517
|
-
if (!this._selfHosting) return;
|
|
518
|
-
for (const adapter of this._protocolAdapters.values()) {
|
|
519
|
-
try {
|
|
520
|
-
await adapter.stop();
|
|
521
|
-
} catch (err) {
|
|
522
|
-
console.warn(`[Entity:${this.id}] Warning stopping adapter '${adapter.name}':`, err.message || err);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
this._selfHosting = false;
|
|
526
|
-
}
|
|
527
|
-
// ── Root / Child Bidirectional State Machine ─────────────────────────────
|
|
528
|
-
/**
|
|
529
|
-
* Lifecycle hook: called when this entity is adopted as a child component by a parent entity.
|
|
530
|
-
* Action: Relinquish root position duties by stopping any self-hosted servers.
|
|
531
|
-
* Note: Capability bubbling is handled automatically by the hierarchy manager.
|
|
532
|
-
*/
|
|
533
|
-
async _onAdoptedByParent() {
|
|
534
|
-
if (this._selfHosting) {
|
|
535
|
-
this._selfHosting = false;
|
|
536
|
-
await this.stopHosting();
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Lifecycle hook: called when this entity is detached or promoted to root position.
|
|
541
|
-
* Action: If no parent and adapters exist, activate self-hosting.
|
|
542
|
-
*/
|
|
543
|
-
async _onPromotedToRoot(options = {}) {
|
|
544
|
-
const hasParent = Boolean(this.hierarchyManager.getOwnerEntity());
|
|
545
|
-
if (!hasParent && this._protocolAdapters.size > 0 && !this._selfHosting) {
|
|
546
|
-
await this._startHosting(options);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
// ── Capability Surface & Bubbling Integration ────────────────────────────
|
|
550
|
-
/**
|
|
551
|
-
* Overrides component functionality addition to notify active protocol adapters.
|
|
552
|
-
*/
|
|
553
|
-
_onComponentFunctionalityAdded(component, functionality) {
|
|
554
|
-
super._onComponentFunctionalityAdded(component, functionality);
|
|
555
|
-
if (this._selfHosting) {
|
|
556
|
-
this._notifyAdaptersOfSurfaceChange();
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Notifies all attached protocol adapters that the exposed capability surface has changed.
|
|
561
|
-
* Idempotent: adapters diff and reconcile their route mappings.
|
|
562
|
-
*/
|
|
563
|
-
_notifyAdaptersOfSurfaceChange() {
|
|
564
|
-
for (const adapter of this._protocolAdapters.values()) {
|
|
565
|
-
try {
|
|
566
|
-
adapter.onCapabilitySurfaceChanged(this);
|
|
567
|
-
} catch (err) {
|
|
568
|
-
console.warn(`[Entity:${this.id}] Adapter '${adapter.name}' surface change notification error:`, err.message || err);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
// ── Qualified Capability Projections & Resolution ────────────────────────
|
|
573
|
-
/**
|
|
574
|
-
* Computes the hierarchical qualified ID for a local functionality ID.
|
|
575
|
-
* e.g. "Root.OrderService.settings"
|
|
576
|
-
*/
|
|
577
|
-
getQualifiedId(fid) {
|
|
578
|
-
const parent = this.hierarchyManager.getOwnerEntity();
|
|
579
|
-
if (parent && typeof parent.getQualifiedId === "function") {
|
|
580
|
-
return `${parent.getQualifiedId(this.id)}.${fid}`;
|
|
581
|
-
}
|
|
582
|
-
return `${this.id}.${fid}`;
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Resolves an external qualified capability ID to the owning Entity instance and local fid.
|
|
586
|
-
* The caller/adapter invokes:
|
|
587
|
-
* const res = root.resolveCapability("Root.OrderService.settings");
|
|
588
|
-
* return await res.owner.call(res.fid, input);
|
|
589
|
-
*/
|
|
590
|
-
resolveCapability(qualifiedId) {
|
|
591
|
-
return this._resolveCapabilityRecursive(qualifiedId);
|
|
592
|
-
}
|
|
593
|
-
_resolveCapabilityRecursive(qualifiedId) {
|
|
594
|
-
for (const [fid, func] of this.localFunctionalities) {
|
|
595
|
-
if (func.visibility === "public" || func.visibility === "protected" || !func.visibility) {
|
|
596
|
-
if (this.getQualifiedId(fid) === qualifiedId || fid === qualifiedId) {
|
|
597
|
-
return { owner: this, fid };
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
for (const child of this.hierarchyManager.getAllOwnedComponentEntities()) {
|
|
602
|
-
if (typeof child._resolveCapabilityRecursive === "function") {
|
|
603
|
-
const res = child._resolveCapabilityRecursive(qualifiedId);
|
|
604
|
-
if (res) return res;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
return void 0;
|
|
608
|
-
}
|
|
609
|
-
// ── Sub-App Integration & Lifecycle ───────────────────────────────────────
|
|
610
|
-
/**
|
|
611
|
-
* Discovers sub-apps in the specified directory (or default 'subapps/').
|
|
612
|
-
*/
|
|
613
|
-
async discoverSubApps(searchPath) {
|
|
614
|
-
const targetDir = searchPath || "subapps";
|
|
615
|
-
return await KrnlSubAppDiscovery.discoverSubApps(targetDir);
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Loads, validates, registers, and initializes a sub-app onto this entity.
|
|
619
|
-
*/
|
|
620
|
-
async loadSubApp(descriptorOrPath, config = {}) {
|
|
621
|
-
let descriptor = null;
|
|
622
|
-
if (typeof descriptorOrPath === "string") {
|
|
623
|
-
descriptor = await KrnlSubAppDiscovery.locateDescriptor(descriptorOrPath);
|
|
624
|
-
if (!descriptor) {
|
|
625
|
-
throw new Error(`[Entity:${this.id}] Could not locate a valid sub-app descriptor at '${descriptorOrPath}'.`);
|
|
626
|
-
}
|
|
627
|
-
} else {
|
|
628
|
-
descriptor = descriptorOrPath;
|
|
629
|
-
}
|
|
630
|
-
const instance = await KrnlSubAppLifecycle.loadAndRegister(this, descriptor, config);
|
|
631
|
-
if (instance.state === "READY") {
|
|
632
|
-
this._registerSubAppInstance(instance);
|
|
633
|
-
} else if (instance.state === "ERROR") {
|
|
634
|
-
console.warn(`[Entity:${this.id}] Sub-app '${instance.id}' failed registration:`, instance.error?.message);
|
|
635
|
-
}
|
|
636
|
-
this._subApps.set(instance.id, instance);
|
|
637
|
-
return instance;
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Programmatically registers a sub-app registration object.
|
|
641
|
-
*/
|
|
642
|
-
async registerSubApp(registration, descriptor) {
|
|
643
|
-
const subAppId = registration.name || descriptor?.id || `subapp_${Date.now()}`;
|
|
644
|
-
const desc = descriptor || {
|
|
645
|
-
id: subAppId,
|
|
646
|
-
path: "",
|
|
647
|
-
registrationPath: "",
|
|
648
|
-
manifest: { name: subAppId, version: "1.0.0" }
|
|
649
|
-
};
|
|
650
|
-
const instance = {
|
|
651
|
-
id: subAppId,
|
|
652
|
-
state: "VALIDATING",
|
|
653
|
-
manifest: desc.manifest || { name: subAppId, version: "1.0.0" },
|
|
654
|
-
descriptor: desc,
|
|
655
|
-
operations: /* @__PURE__ */ new Map(),
|
|
656
|
-
error: null,
|
|
657
|
-
errorDetails: [],
|
|
658
|
-
loadedAt: Date.now()
|
|
659
|
-
};
|
|
660
|
-
const existingCaps = /* @__PURE__ */ new Set();
|
|
661
|
-
for (const k of this.localFunctionalities.keys()) existingCaps.add(k);
|
|
662
|
-
for (const k of this.remoteFunctionalities.keys()) existingCaps.add(k);
|
|
663
|
-
const check = KrnlSubAppValidator.validateRegistration(registration, existingCaps, subAppId);
|
|
664
|
-
if (!check.valid) {
|
|
665
|
-
instance.state = "ERROR";
|
|
666
|
-
instance.errorDetails = check.errors;
|
|
667
|
-
instance.error = new Error(`[SubApp:${subAppId}] Registration validation failed: ${check.errors.map((e) => e.message).join(", ")}`);
|
|
668
|
-
this._subApps.set(subAppId, instance);
|
|
669
|
-
return instance;
|
|
670
|
-
}
|
|
671
|
-
instance.state = "REGISTERED";
|
|
672
|
-
instance.registration = registration;
|
|
673
|
-
for (const op of registration.operations) {
|
|
674
|
-
instance.operations.set(op.name, op);
|
|
675
|
-
}
|
|
676
|
-
this._registerSubAppInstance(instance);
|
|
677
|
-
if (typeof registration.onInitialize === "function") {
|
|
678
|
-
instance.state = "INITIALIZING";
|
|
679
|
-
const regContext = {
|
|
680
|
-
entity: this,
|
|
681
|
-
services: this._serviceContainer || { get: () => void 0, has: () => false, register: () => {
|
|
682
|
-
}, list: () => [] },
|
|
683
|
-
operations: {
|
|
684
|
-
register: (op) => this.registerSubAppOperations(subAppId, [op]),
|
|
685
|
-
registerBatch: (ops) => this.registerSubAppOperations(subAppId, ops),
|
|
686
|
-
get: (name) => instance.operations.get(name),
|
|
687
|
-
list: () => Array.from(instance.operations.values())
|
|
688
|
-
},
|
|
689
|
-
events: {
|
|
690
|
-
emit: (event, data) => this.interface?.getEmitter(event)?.pushDataStreamToEmitter(data),
|
|
691
|
-
on: (event, listener) => this.interface?.getEmitter(event)?.subscribe((m) => listener(m.data || m)) || (() => {
|
|
692
|
-
})
|
|
693
|
-
},
|
|
694
|
-
config: {},
|
|
695
|
-
logger: this.logger || console
|
|
696
|
-
};
|
|
697
|
-
await registration.onInitialize(regContext);
|
|
698
|
-
}
|
|
699
|
-
instance.state = "READY";
|
|
700
|
-
instance.readyAt = Date.now();
|
|
701
|
-
this._subApps.set(subAppId, instance);
|
|
702
|
-
return instance;
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Internal helper: wraps sub-app operations into first-class Entity functionalities.
|
|
706
|
-
*/
|
|
707
|
-
_registerSubAppInstance(instance) {
|
|
708
|
-
if (!instance.operations) return;
|
|
709
|
-
for (const op of instance.operations.values()) {
|
|
710
|
-
this._wrapAndAddSubAppOperation(instance.id, op);
|
|
711
|
-
}
|
|
712
|
-
if (this._selfHosting) {
|
|
713
|
-
this._notifyAdaptersOfSurfaceChange();
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* Wraps a single operation definition into a krnlLocalFunctionality and binds to this Entity.
|
|
718
|
-
*/
|
|
719
|
-
_wrapAndAddSubAppOperation(subAppId, op) {
|
|
720
|
-
const qualifiedFid = `${subAppId}.${op.name}`;
|
|
721
|
-
const atomConfig = {
|
|
722
|
-
id: qualifiedFid,
|
|
723
|
-
visibility: op.visibility || "public",
|
|
724
|
-
description: op.description || "",
|
|
725
|
-
method: op.method || "POST",
|
|
726
|
-
schema: {
|
|
727
|
-
input: op.input || null,
|
|
728
|
-
output: op.output || null
|
|
729
|
-
},
|
|
730
|
-
metadata: op.metadata || {},
|
|
731
|
-
api: async (input, ctx) => {
|
|
732
|
-
return await op.handler(input, {
|
|
733
|
-
caller: ctx?.caller,
|
|
734
|
-
callerPort: ctx?.callerPort,
|
|
735
|
-
accessKey: ctx?.accessKey,
|
|
736
|
-
entity: this,
|
|
737
|
-
metadata: op.metadata
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
};
|
|
741
|
-
const localAtom = new krnlLocalFunctionality(atomConfig);
|
|
742
|
-
this.addLocal(localAtom);
|
|
743
|
-
if (!this.localFunctionalities.has(op.name) && !this.remoteFunctionalities.has(op.name)) {
|
|
744
|
-
const aliasAtom = new krnlLocalFunctionality({
|
|
745
|
-
...atomConfig,
|
|
746
|
-
id: op.name
|
|
747
|
-
});
|
|
748
|
-
this.addLocal(aliasAtom);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Registers additional operations under an existing sub-app.
|
|
753
|
-
*/
|
|
754
|
-
registerSubAppOperations(subAppId, operations) {
|
|
755
|
-
const instance = this._subApps.get(subAppId);
|
|
756
|
-
for (const op of operations) {
|
|
757
|
-
if (instance) {
|
|
758
|
-
instance.operations.set(op.name, op);
|
|
759
|
-
}
|
|
760
|
-
this._wrapAndAddSubAppOperation(subAppId, op);
|
|
761
|
-
}
|
|
762
|
-
if (this._selfHosting) {
|
|
763
|
-
this._notifyAdaptersOfSurfaceChange();
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Unregisters and disposes a sub-app from this entity.
|
|
768
|
-
*/
|
|
769
|
-
async unregisterSubApp(subAppId) {
|
|
770
|
-
const instance = this._subApps.get(subAppId);
|
|
771
|
-
if (!instance) return;
|
|
772
|
-
for (const opName of instance.operations.keys()) {
|
|
773
|
-
const qualifiedFid = `${subAppId}.${opName}`;
|
|
774
|
-
if (this.localFunctionalities.has(qualifiedFid)) {
|
|
775
|
-
const func = this.localFunctionalities.get(qualifiedFid);
|
|
776
|
-
if (func && typeof func._unregisterFromInterface === "function") {
|
|
777
|
-
func._unregisterFromInterface();
|
|
778
|
-
}
|
|
779
|
-
this.localFunctionalities.delete(qualifiedFid);
|
|
780
|
-
}
|
|
781
|
-
if (this.localFunctionalities.has(opName)) {
|
|
782
|
-
const func = this.localFunctionalities.get(opName);
|
|
783
|
-
if (func && typeof func._unregisterFromInterface === "function") {
|
|
784
|
-
func._unregisterFromInterface();
|
|
785
|
-
}
|
|
786
|
-
this.localFunctionalities.delete(opName);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
await KrnlSubAppLifecycle.dispose(instance);
|
|
790
|
-
this._subApps.delete(subAppId);
|
|
791
|
-
if (this._selfHosting) {
|
|
792
|
-
this._notifyAdaptersOfSurfaceChange();
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Retrieve a registered sub-app instance by ID.
|
|
797
|
-
*/
|
|
798
|
-
getSubApp(subAppId) {
|
|
799
|
-
return this._subApps.get(subAppId);
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Returns all sub-app instances registered under this entity.
|
|
803
|
-
*/
|
|
804
|
-
getSubApps() {
|
|
805
|
-
return Array.from(this._subApps.values());
|
|
806
|
-
}
|
|
807
|
-
// ── Manifest Aggregation (Kernel Declares → Shell Materializes) ──────────
|
|
808
|
-
/**
|
|
809
|
-
* Aggregates dependency manifests from all local functionalities, sub-apps, and descendant entities.
|
|
810
|
-
* Returns a consolidated workspace requirements document.
|
|
811
|
-
*/
|
|
812
|
-
getWorkspaceRequirements() {
|
|
813
|
-
const reqs = {
|
|
814
|
-
dependencies: {},
|
|
815
|
-
devDependencies: {},
|
|
816
|
-
buildRequirements: [],
|
|
817
|
-
resources: [],
|
|
818
|
-
conflicts: []
|
|
819
|
-
};
|
|
820
|
-
this._aggregateManifestInto(reqs);
|
|
821
|
-
return reqs;
|
|
822
|
-
}
|
|
823
|
-
_aggregateManifestInto(reqs) {
|
|
824
|
-
this.localFunctionalities.forEach((func) => {
|
|
825
|
-
if (func.manifest) {
|
|
826
|
-
_Entity._mergeManifestRequirements(reqs, func.manifest, `${this.id}:${func.id}`);
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
this._subApps.forEach((subApp) => {
|
|
830
|
-
if (subApp.manifest) {
|
|
831
|
-
_Entity._mergeManifestRequirements(reqs, subApp.manifest, `${this.id}:${subApp.id}`);
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
this.hierarchyManager.getAllOwnedComponentEntities().forEach((child) => {
|
|
835
|
-
if (typeof child._aggregateManifestInto === "function") {
|
|
836
|
-
child._aggregateManifestInto(reqs);
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
static _mergeManifestRequirements(target, manifest, sourceId) {
|
|
841
|
-
if (manifest.dependencies) {
|
|
842
|
-
for (const [pkg, ver] of Object.entries(manifest.dependencies)) {
|
|
843
|
-
if (target.dependencies[pkg] && target.dependencies[pkg] !== ver) {
|
|
844
|
-
target.conflicts = target.conflicts || [];
|
|
845
|
-
target.conflicts.push({
|
|
846
|
-
package: pkg,
|
|
847
|
-
versionA: target.dependencies[pkg],
|
|
848
|
-
versionB: ver,
|
|
849
|
-
sources: [sourceId]
|
|
850
|
-
});
|
|
851
|
-
} else {
|
|
852
|
-
target.dependencies[pkg] = ver;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
if (manifest.devDependencies) {
|
|
857
|
-
for (const [pkg, ver] of Object.entries(manifest.devDependencies)) {
|
|
858
|
-
target.devDependencies[pkg] = ver;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
if (manifest.buildRequirements) {
|
|
862
|
-
for (const req of manifest.buildRequirements) {
|
|
863
|
-
if (!target.buildRequirements.includes(req)) {
|
|
864
|
-
target.buildRequirements.push(req);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
if (manifest.resources) {
|
|
869
|
-
for (const res of manifest.resources) {
|
|
870
|
-
target.resources.push(res);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
// ── UI Spec Recursive Aggregation ────────────────────────────────────────
|
|
875
|
-
/**
|
|
876
|
-
* Aggregates UI specifications from all functionalities and sub-apps across the entity tree.
|
|
877
|
-
* Qualified IDs ensure namespace stability and avoid collisions.
|
|
878
|
-
*/
|
|
879
|
-
aggregateUI() {
|
|
880
|
-
const list = [];
|
|
881
|
-
this.localFunctionalities.forEach((func, fid) => {
|
|
882
|
-
if (func.uiSpec) {
|
|
883
|
-
list.push({
|
|
884
|
-
qualifiedId: this.getQualifiedId(fid),
|
|
885
|
-
uiSpec: func.uiSpec,
|
|
886
|
-
source: this
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
this._subApps.forEach((subApp) => {
|
|
891
|
-
const uiConfig = subApp.registration?.ui || subApp.manifest?.ui;
|
|
892
|
-
if (uiConfig) {
|
|
893
|
-
list.push({
|
|
894
|
-
qualifiedId: this.getQualifiedId(subApp.id),
|
|
895
|
-
uiSpec: typeof uiConfig === "string" ? { entry: uiConfig } : uiConfig,
|
|
896
|
-
source: this
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
this.hierarchyManager.getAllOwnedComponentEntities().forEach((child) => {
|
|
901
|
-
if (typeof child.aggregateUI === "function") {
|
|
902
|
-
list.push(...child.aggregateUI());
|
|
903
|
-
}
|
|
904
|
-
});
|
|
905
|
-
return list;
|
|
906
|
-
}
|
|
907
|
-
// ── Orchestration & Flow Factory ─────────────────────────────────────────
|
|
908
|
-
/**
|
|
909
|
-
* Create an OrchestrationChain instance bound to this entity.
|
|
910
|
-
* Defines declarative orchestration of local functionalities and global library functions.
|
|
911
|
-
*/
|
|
912
|
-
orchestration(id) {
|
|
913
|
-
return new OrchestrationChain(this, id);
|
|
914
|
-
}
|
|
915
|
-
/**
|
|
916
|
-
* Create a FlowBuilder instance bound to this entity.
|
|
917
|
-
*/
|
|
918
|
-
flow(id) {
|
|
919
|
-
return new OrchestrationChain(this, id);
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Clean disposal of all entity resources, sub-apps, child components, and adapters.
|
|
923
|
-
*/
|
|
924
|
-
dispose() {
|
|
925
|
-
if (this._selfHosting) {
|
|
926
|
-
this.stopHosting().catch(() => {
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
for (const subApp of this._subApps.values()) {
|
|
930
|
-
KrnlSubAppLifecycle.dispose(subApp).catch(() => {
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
this._subApps.clear();
|
|
934
|
-
for (const adapter of this._protocolAdapters.values()) {
|
|
935
|
-
if (typeof adapter.dispose === "function") {
|
|
936
|
-
adapter.dispose();
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
this._protocolAdapters.clear();
|
|
940
|
-
super.dispose();
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
export {
|
|
945
|
-
OrchestrationRuleViolationError,
|
|
946
|
-
OrchestrationChain,
|
|
947
|
-
KrnlFlowBuilder,
|
|
948
|
-
Entity
|
|
949
|
-
};
|