@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.
Files changed (235) hide show
  1. package/README.md +67 -65
  2. package/package.json +13 -9
  3. package/packages/cli/dist/bin/krnl.cjs +1535 -9508
  4. package/packages/cli/dist/bin/krnl.js +55 -1915
  5. package/packages/cli/dist/chunk-6SHSECXR.js +1628 -0
  6. package/packages/cli/dist/index.cjs +1244 -7373
  7. package/packages/cli/dist/index.d.cts +45 -2
  8. package/packages/cli/dist/index.d.ts +45 -2
  9. package/packages/cli/dist/index.js +5 -20
  10. package/packages/cli/package.json +17 -10
  11. package/packages/core/dist/index.cjs +3039 -141
  12. package/packages/core/dist/index.d.cts +633 -27
  13. package/packages/core/dist/index.d.ts +633 -27
  14. package/packages/core/dist/index.js +3028 -139
  15. package/packages/core/package.json +15 -7
  16. package/packages/create-krnl/dist/index.cjs +322 -316
  17. package/packages/create-krnl/dist/index.js +322 -316
  18. package/packages/create-krnl/package.json +5 -3
  19. package/packages/eslint-plugin/dist/index.cjs +17 -55
  20. package/packages/eslint-plugin/dist/index.d.cts +8 -43
  21. package/packages/eslint-plugin/dist/index.d.ts +8 -43
  22. package/packages/eslint-plugin/dist/index.js +17 -55
  23. package/packages/eslint-plugin/package.json +5 -4
  24. package/packages/validate/dist/index.cjs +692 -361
  25. package/packages/validate/dist/index.d.cts +12 -14
  26. package/packages/validate/dist/index.d.ts +12 -14
  27. package/packages/validate/dist/index.js +692 -361
  28. package/packages/validate/package.json +14 -7
  29. package/packages/cli/dist/K_ENT_Entity-PQ5MURQY-ZG6FZXXX.js +0 -13
  30. package/packages/cli/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-K4CRQYA5.js +0 -8
  31. package/packages/cli/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-LNPXZYOE.js +0 -110
  32. package/packages/cli/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-3ALZPNX4.js +0 -11
  33. package/packages/cli/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-PJTICYSW.js +0 -11
  34. package/packages/cli/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-M5TYU55O.js +0 -8
  35. package/packages/cli/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-H6STOXRK.js +0 -20
  36. package/packages/cli/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-XPJXSF7D.js +0 -19
  37. package/packages/cli/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-CUYGTWOW.js +0 -7
  38. package/packages/cli/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-VR6T4N6J.js +0 -17
  39. package/packages/cli/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-RLJ4QWDP.js +0 -58
  40. package/packages/cli/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-BOQGUASC.js +0 -22
  41. package/packages/cli/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-XJI7KIT5.js +0 -8
  42. package/packages/cli/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-K5VCWAFW.js +0 -9
  43. package/packages/cli/dist/chunk-3TRM6CYL.js +0 -152
  44. package/packages/cli/dist/chunk-5JDK35TG.js +0 -3872
  45. package/packages/cli/dist/chunk-63PTK33I.js +0 -997
  46. package/packages/cli/dist/chunk-6NIKAMUZ.js +0 -82
  47. package/packages/cli/dist/chunk-BOXWWXQG.js +0 -400
  48. package/packages/cli/dist/chunk-EEKLK7QJ.js +0 -565
  49. package/packages/cli/dist/chunk-EG7T2IAD.js +0 -107
  50. package/packages/cli/dist/chunk-F5EHXE2O.js +0 -1036
  51. package/packages/cli/dist/chunk-F65ANSQG.js +0 -269
  52. package/packages/cli/dist/chunk-FDNCADFE.js +0 -71
  53. package/packages/cli/dist/chunk-GDLRMDAN.js +0 -127
  54. package/packages/cli/dist/chunk-HWMTCMOS.js +0 -656
  55. package/packages/cli/dist/chunk-I74QIQOD.js +0 -5536
  56. package/packages/cli/dist/chunk-JTLSTO25.js +0 -71
  57. package/packages/cli/dist/chunk-JULBBJ27.js +0 -1033
  58. package/packages/cli/dist/chunk-OHVMVRBP.js +0 -117
  59. package/packages/cli/dist/chunk-P2PCLEKX.js +0 -666
  60. package/packages/cli/dist/chunk-PJQIUOX2.js +0 -7767
  61. package/packages/cli/dist/chunk-PPOF3DJW.js +0 -471
  62. package/packages/cli/dist/chunk-Q45257P6.js +0 -173
  63. package/packages/cli/dist/chunk-QNROWGBI.js +0 -1036
  64. package/packages/cli/dist/chunk-RJNYUXZD.js +0 -977
  65. package/packages/cli/dist/chunk-SRTOPJ5W.js +0 -104
  66. package/packages/cli/dist/chunk-TCEX3MPS.js +0 -702
  67. package/packages/cli/dist/chunk-TNOAJO2J.js +0 -675
  68. package/packages/cli/dist/chunk-UR2SUCSF.js +0 -701
  69. package/packages/cli/dist/chunk-X5LOIFM7.js +0 -68
  70. package/packages/cli/dist/chunk-XIRFOO3H.js +0 -589
  71. package/packages/cli/dist/chunk-ZAAV3JXQ.js +0 -809
  72. package/packages/core/dist/K_ENT_Entity-4MB7CU4A.js +0 -12
  73. package/packages/core/dist/K_ENT_Entity-DEJGIDGH.js +0 -12
  74. package/packages/core/dist/K_ENT_Entity-FXZO5UZ2.js +0 -12
  75. package/packages/core/dist/K_ENT_Entity-HDSCXC5F.js +0 -12
  76. package/packages/core/dist/K_ENT_Entity-JILABHLW.js +0 -12
  77. package/packages/core/dist/K_ENT_Entity-PQ5MURQY.js +0 -13
  78. package/packages/core/dist/K_ENT_Entity-ROAKDIHW.js +0 -12
  79. package/packages/core/dist/K_ENT_Entity-TBVFSKDV.js +0 -12
  80. package/packages/core/dist/K_ENT_Entity-ZFLKG3JO.js +0 -12
  81. package/packages/core/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW.js +0 -8
  82. package/packages/core/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF.js +0 -110
  83. package/packages/core/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF.js +0 -9
  84. package/packages/core/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X.js +0 -9
  85. package/packages/core/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW.js +0 -8
  86. package/packages/core/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2.js +0 -20
  87. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-4C6GBQAG.js +0 -18
  88. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-6V23A6F6.js +0 -18
  89. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK.js +0 -19
  90. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-DYLLC5G2.js +0 -18
  91. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-F4FOFAUP.js +0 -18
  92. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-FBOXXMI3.js +0 -18
  93. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-Q73BWLNP.js +0 -18
  94. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QM2C4MVA.js +0 -18
  95. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QUGI6SMP.js +0 -18
  96. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RGMTBHNP.js +0 -18
  97. package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RWR7UNDW.js +0 -18
  98. package/packages/core/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7.js +0 -7
  99. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-32MFJJ5Z.js +0 -17
  100. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-4J4CEWRY.js +0 -17
  101. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-A366YHF2.js +0 -17
  102. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-LK4LYJHI.js +0 -17
  103. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU.js +0 -17
  104. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-NW3K63II.js +0 -17
  105. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-QDHTI5ZV.js +0 -17
  106. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-VHCT6VIW.js +0 -17
  107. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-WBRKF24R.js +0 -17
  108. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-XKYQYT6Q.js +0 -17
  109. package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-Z2PWZYDZ.js +0 -17
  110. package/packages/core/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5.js +0 -58
  111. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-2EZU7QF4.js +0 -21
  112. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-6G3AQNAV.js +0 -21
  113. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-B2NZMQUG.js +0 -21
  114. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-C2RABMZP.js +0 -21
  115. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-HHE3NZ4F.js +0 -21
  116. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-LHFGR6WK.js +0 -21
  117. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-M74BLM3N.js +0 -21
  118. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-PT6ZA6EA.js +0 -21
  119. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-SP52V3CX.js +0 -21
  120. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF.js +0 -22
  121. package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-YNSEUHJJ.js +0 -21
  122. package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-M6SBHIVA.js +0 -8
  123. package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG.js +0 -8
  124. package/packages/core/dist/K_LIB_Krnl_Telemetry-77FRZ3KV.js +0 -9
  125. package/packages/core/dist/chunk-33L2J7V7.js +0 -82
  126. package/packages/core/dist/chunk-3ES4K2ZP.js +0 -817
  127. package/packages/core/dist/chunk-3SMHVVLL.js +0 -82
  128. package/packages/core/dist/chunk-3UEZ7JQA.js +0 -4877
  129. package/packages/core/dist/chunk-3XIE6KBD.js +0 -4877
  130. package/packages/core/dist/chunk-46ZLCML6.js +0 -107
  131. package/packages/core/dist/chunk-4UEL3DWJ.js +0 -107
  132. package/packages/core/dist/chunk-54GWZ5PC.js +0 -82
  133. package/packages/core/dist/chunk-6QCYRS5L.js +0 -127
  134. package/packages/core/dist/chunk-6ULMHNXR.js +0 -104
  135. package/packages/core/dist/chunk-7WUETJEV.js +0 -117
  136. package/packages/core/dist/chunk-A5KRAYDB.js +0 -107
  137. package/packages/core/dist/chunk-ANEAZ3PO.js +0 -107
  138. package/packages/core/dist/chunk-BE76RL6F.js +0 -82
  139. package/packages/core/dist/chunk-CIARVYDO.js +0 -107
  140. package/packages/core/dist/chunk-CR2ANE62.js +0 -107
  141. package/packages/core/dist/chunk-DI27MOR7.js +0 -173
  142. package/packages/core/dist/chunk-E6RLFHM5.js +0 -596
  143. package/packages/core/dist/chunk-EELAPMNV.js +0 -4877
  144. package/packages/core/dist/chunk-ENZ2RQVJ.js +0 -107
  145. package/packages/core/dist/chunk-F2U6CX4F.js +0 -4877
  146. package/packages/core/dist/chunk-FKG64OHL.js +0 -82
  147. package/packages/core/dist/chunk-FYAZJYM5.js +0 -772
  148. package/packages/core/dist/chunk-G4NP4RDQ.js +0 -82
  149. package/packages/core/dist/chunk-GADIRLRS.js +0 -473
  150. package/packages/core/dist/chunk-GR6CSLQJ.js +0 -772
  151. package/packages/core/dist/chunk-HDS7AT6O.js +0 -772
  152. package/packages/core/dist/chunk-HIMEZUU2.js +0 -71
  153. package/packages/core/dist/chunk-IB4UHG5I.js +0 -596
  154. package/packages/core/dist/chunk-J7ZYNVRS.js +0 -772
  155. package/packages/core/dist/chunk-JVLZU4K7.js +0 -604
  156. package/packages/core/dist/chunk-JYXXI7Q3.js +0 -82
  157. package/packages/core/dist/chunk-K54K2KZW.js +0 -192
  158. package/packages/core/dist/chunk-K6VHLBNH.js +0 -3316
  159. package/packages/core/dist/chunk-KCBP7ZYA.js +0 -596
  160. package/packages/core/dist/chunk-KFQGP6VL.js +0 -33
  161. package/packages/core/dist/chunk-KIUEUI7K.js +0 -82
  162. package/packages/core/dist/chunk-LB67NIZP.js +0 -949
  163. package/packages/core/dist/chunk-LDTYFUNW.js +0 -596
  164. package/packages/core/dist/chunk-MLVWARD4.js +0 -596
  165. package/packages/core/dist/chunk-MPYVXHKO.js +0 -2777
  166. package/packages/core/dist/chunk-MRQ3MITU.js +0 -772
  167. package/packages/core/dist/chunk-MVUN7I7O.js +0 -107
  168. package/packages/core/dist/chunk-NDDOIRW7.js +0 -596
  169. package/packages/core/dist/chunk-O3KDB5MH.js +0 -3330
  170. package/packages/core/dist/chunk-OEINUDSE.js +0 -400
  171. package/packages/core/dist/chunk-OPDENPT4.js +0 -4877
  172. package/packages/core/dist/chunk-P6XEM2LA.js +0 -429
  173. package/packages/core/dist/chunk-QKMRSQV4.js +0 -82
  174. package/packages/core/dist/chunk-R6CCWALL.js +0 -4877
  175. package/packages/core/dist/chunk-RAMMOO73.js +0 -774
  176. package/packages/core/dist/chunk-S3FTZFG6.js +0 -772
  177. package/packages/core/dist/chunk-T2ZVN434.js +0 -4877
  178. package/packages/core/dist/chunk-TFHLDMIA.js +0 -107
  179. package/packages/core/dist/chunk-TI3QUCIJ.js +0 -107
  180. package/packages/core/dist/chunk-TR2BAIGI.js +0 -107
  181. package/packages/core/dist/chunk-UGVVJKC6.js +0 -4877
  182. package/packages/core/dist/chunk-V2DX7YIU.js +0 -984
  183. package/packages/core/dist/chunk-W4IHYUYD.js +0 -772
  184. package/packages/core/dist/chunk-W6WBG5OY.js +0 -4877
  185. package/packages/core/dist/chunk-WN3M7O7H.js +0 -3312
  186. package/packages/core/dist/chunk-WR3NCU7U.js +0 -4877
  187. package/packages/core/dist/chunk-XC6B6L27.js +0 -82
  188. package/packages/core/dist/chunk-XNSE64ZY.js +0 -3316
  189. package/packages/core/dist/chunk-XROES2WN.js +0 -634
  190. package/packages/core/dist/chunk-XSCKNRCZ.js +0 -5020
  191. package/packages/core/dist/chunk-XVABPAUZ.js +0 -82
  192. package/packages/core/dist/chunk-YOBCB5C5.js +0 -596
  193. package/packages/core/dist/chunk-YUK6Q563.js +0 -666
  194. package/packages/core/dist/chunk-YXGL3ZEU.js +0 -1030
  195. package/packages/core/dist/chunk-ZINJ5OUX.js +0 -596
  196. package/packages/core/dist/chunk-ZPFD4BIQ.js +0 -604
  197. package/packages/core/dist/chunk-ZQZBFG6F.js +0 -4826
  198. package/packages/core/dist/chunk-ZZFRJGXM.js +0 -4877
  199. package/packages/create-krnl/dist/K_ENT_Entity-PQ5MURQY-R2OH4VXE.js +0 -14
  200. package/packages/create-krnl/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-AZM5HF4M.js +0 -9
  201. package/packages/create-krnl/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-X5N6SV2S.js +0 -111
  202. package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-5PFHF4JU.js +0 -12
  203. package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-ED33OQPH.js +0 -12
  204. package/packages/create-krnl/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-YGQLVR4P.js +0 -9
  205. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-VM7CTU2L.js +0 -21
  206. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-Y2GQFJ7I.js +0 -21
  207. package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-L3JQWO54.js +0 -8
  208. package/packages/create-krnl/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-KQARASPR.js +0 -19
  209. package/packages/create-krnl/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-OF3IGLVL.js +0 -59
  210. package/packages/create-krnl/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-JOLHKOEX.js +0 -24
  211. package/packages/create-krnl/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-L46LSHKQ.js +0 -10
  212. package/packages/create-krnl/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-4JUPRR3X.js +0 -10
  213. package/packages/create-krnl/dist/chunk-3TRM6CYL.js +0 -152
  214. package/packages/create-krnl/dist/chunk-3URCB3QS.js +0 -127
  215. package/packages/create-krnl/dist/chunk-5JDK35TG.js +0 -3872
  216. package/packages/create-krnl/dist/chunk-A2XAXDOW.js +0 -812
  217. package/packages/create-krnl/dist/chunk-AN6TMQHG.js +0 -1033
  218. package/packages/create-krnl/dist/chunk-BOXWWXQG.js +0 -400
  219. package/packages/create-krnl/dist/chunk-BPTBREBG.js +0 -38
  220. package/packages/create-krnl/dist/chunk-FDNCADFE.js +0 -71
  221. package/packages/create-krnl/dist/chunk-JTLSTO25.js +0 -71
  222. package/packages/create-krnl/dist/chunk-M3NCUIPL.js +0 -107
  223. package/packages/create-krnl/dist/chunk-N2EONSOC.js +0 -7769
  224. package/packages/create-krnl/dist/chunk-OHVMVRBP.js +0 -117
  225. package/packages/create-krnl/dist/chunk-Q45257P6.js +0 -173
  226. package/packages/create-krnl/dist/chunk-QGM4M3NI.js +0 -37
  227. package/packages/create-krnl/dist/chunk-RJNYUXZD.js +0 -977
  228. package/packages/create-krnl/dist/chunk-SRTOPJ5W.js +0 -104
  229. package/packages/create-krnl/dist/chunk-UPBIGEC3.js +0 -666
  230. package/packages/create-krnl/dist/chunk-V2DB7UD7.js +0 -82
  231. package/packages/create-krnl/dist/chunk-WMHLIUI6.js +0 -3644
  232. package/packages/create-krnl/dist/chunk-XIRFOO3H.js +0 -589
  233. package/packages/create-krnl/dist/chunk-Y2CEEVZP.js +0 -5536
  234. package/packages/create-krnl/dist/main-DXUMPBND.js +0 -2217
  235. 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
- };