@nice2dev/game-engine 1.3.15 → 1.3.17

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 (434) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/accessibility/Accessibility.js +152 -165
  3. package/dist/cjs/ai/AI.js +292 -294
  4. package/dist/cjs/ai/BehaviorTree.js +1029 -1113
  5. package/dist/cjs/ai/StateMachine.js +694 -756
  6. package/dist/cjs/animation/Animation.js +232 -241
  7. package/dist/cjs/audio/AudioAdvanced.js +221 -236
  8. package/dist/cjs/audio/AudioBridge.js +441 -435
  9. package/dist/cjs/audio/AudioManager.js +242 -259
  10. package/dist/cjs/build-cloud/BuildOrchestration.js +1059 -1098
  11. package/dist/cjs/build-cloud/GodotBuildCloud.js +641 -670
  12. package/dist/cjs/build-cloud/UnityBuildCloud.js +563 -610
  13. package/dist/cjs/build-cloud/UnrealBuildCloud.js +610 -635
  14. package/dist/cjs/core/EventBus.js +51 -56
  15. package/dist/cjs/core/GameClock.js +62 -66
  16. package/dist/cjs/core/GameConfig.js +72 -79
  17. package/dist/cjs/core/GameLoop.js +80 -89
  18. package/dist/cjs/core/ServiceLocator.js +61 -65
  19. package/dist/cjs/core/Validation.js +72 -82
  20. package/dist/cjs/core/math.js +108 -112
  21. package/dist/cjs/devtools/DevTools.js +542 -563
  22. package/dist/cjs/devtools/DeveloperExperience.js +521 -559
  23. package/dist/cjs/devtools/GameplayAnalytics.js +636 -646
  24. package/dist/cjs/dialogue/DialogueSystem.js +984 -986
  25. package/dist/cjs/docs/DocGenerator.js +339 -364
  26. package/dist/cjs/ecs/World.js +355 -371
  27. package/dist/cjs/editor/AchievementEditor.js +580 -636
  28. package/dist/cjs/editor/AdvancedEditor.js +184 -191
  29. package/dist/cjs/editor/AnimationRetargeting.js +696 -741
  30. package/dist/cjs/editor/AssetBrowser.js +1072 -1160
  31. package/dist/cjs/editor/AssetManager.js +187 -192
  32. package/dist/cjs/editor/ConsolePro.js +971 -1061
  33. package/dist/cjs/editor/CraftingEditor.js +680 -730
  34. package/dist/cjs/editor/DebugTools.js +187 -185
  35. package/dist/cjs/editor/DialogueSystem.js +844 -901
  36. package/dist/cjs/editor/LeaderboardSystem.js +429 -483
  37. package/dist/cjs/editor/NiceGameEditor.js +1903 -1201
  38. package/dist/cjs/editor/PrefabSystem.js +772 -838
  39. package/dist/cjs/editor/ProfilerPanel.js +649 -700
  40. package/dist/cjs/editor/QuestEditor.js +792 -839
  41. package/dist/cjs/editor/ReplaySystem.js +585 -634
  42. package/dist/cjs/editor/SceneEditor.js +176 -200
  43. package/dist/cjs/editor/ScreenshotMode.js +621 -688
  44. package/dist/cjs/editor/ShaderGraph.js +1556 -1582
  45. package/dist/cjs/editor/TimelineEditor.js +715 -778
  46. package/dist/cjs/editor/UndoRedoPro.js +830 -904
  47. package/dist/cjs/editor/VRARMode.js +582 -645
  48. package/dist/cjs/engine/NiceGameEngine.js +141 -164
  49. package/dist/cjs/engine/SaveSystem.js +441 -495
  50. package/dist/cjs/enterprise/Enterprise.js +254 -261
  51. package/dist/cjs/export/BevyExporter.js +927 -967
  52. package/dist/cjs/export/CocosExporter.js +644 -673
  53. package/dist/cjs/export/Construct3Exporter.js +783 -794
  54. package/dist/cjs/export/DefoldExporter.js +1028 -1069
  55. package/dist/cjs/export/GDevelopExporter.js +674 -708
  56. package/dist/cjs/export/GameMakerExporter.js +791 -805
  57. package/dist/cjs/export/GodotExporter.js +1003 -1045
  58. package/dist/cjs/export/MinecraftBedrockExporter.js +573 -578
  59. package/dist/cjs/export/MonoGameExporter.js +1265 -1293
  60. package/dist/cjs/export/Pico8Exporter.js +766 -812
  61. package/dist/cjs/export/PlatformExporter.js +188 -206
  62. package/dist/cjs/export/RPGMakerExporter.js +860 -879
  63. package/dist/cjs/export/RobloxExporter.js +883 -919
  64. package/dist/cjs/export/Solar2DExporter.js +1218 -1256
  65. package/dist/cjs/export/ThreeJSExporter.js +1006 -1073
  66. package/dist/cjs/export/Tic80Exporter.js +1210 -1267
  67. package/dist/cjs/export/UnityExporter.js +1116 -1131
  68. package/dist/cjs/export/UnrealExporter.js +889 -919
  69. package/dist/cjs/export/WebExporter.js +931 -970
  70. package/dist/cjs/export/index.js +42 -65
  71. package/dist/cjs/godot-integration/GodotAssetLibrary.js +659 -692
  72. package/dist/cjs/godot-integration/GodotImport.js +929 -1027
  73. package/dist/cjs/godot-integration/GodotLiveLink.js +915 -945
  74. package/dist/cjs/godot-integration/components/GodotProjectBrowser.js +911 -611
  75. package/dist/cjs/i18n/I18n.js +860 -900
  76. package/dist/cjs/i18n/useTranslation.js +84 -89
  77. package/dist/cjs/import/AsepriteImporter.js +658 -716
  78. package/dist/cjs/import/DragonBonesImporter.js +437 -461
  79. package/dist/cjs/import/GameMakerImporter.js +511 -521
  80. package/dist/cjs/import/GodotSceneImporter.js +788 -822
  81. package/dist/cjs/import/LDtkImporter.js +436 -454
  82. package/dist/cjs/import/Live2DImporter.js +497 -518
  83. package/dist/cjs/import/NdgFormat.js +424 -457
  84. package/dist/cjs/import/OgmoImporter.js +466 -493
  85. package/dist/cjs/import/RPGMakerImporter.js +451 -477
  86. package/dist/cjs/import/SceneImporter.js +378 -423
  87. package/dist/cjs/import/SpineImporter.js +511 -546
  88. package/dist/cjs/import/SpriterImporter.js +590 -613
  89. package/dist/cjs/import/TiledMapImporter.js +811 -846
  90. package/dist/cjs/import/UnitySceneImporter.js +687 -703
  91. package/dist/cjs/import/index.js +206 -251
  92. package/dist/cjs/index.js +275 -278
  93. package/dist/cjs/input/GamepadNavigation.js +185 -205
  94. package/dist/cjs/input/InputManager.js +397 -421
  95. package/dist/cjs/input/useGamepads.js +70 -81
  96. package/dist/cjs/integration/IconSprite.js +129 -256
  97. package/dist/cjs/inventory/InventorySystem.js +920 -995
  98. package/dist/cjs/kids/KidMode.js +997 -1022
  99. package/dist/cjs/kids/KidTools.js +570 -594
  100. package/dist/cjs/monetization/Monetization.js +170 -177
  101. package/dist/cjs/multiplayer/LocalMultiplayer.js +287 -287
  102. package/dist/cjs/multiplayer/MiniGameTypes.js +49 -59
  103. package/dist/cjs/native-engine/AnimationSystem.js +731 -806
  104. package/dist/cjs/native-engine/AssetPipeline.js +454 -515
  105. package/dist/cjs/native-engine/AudioEngine.js +763 -804
  106. package/dist/cjs/native-engine/InputSystem.js +1075 -1145
  107. package/dist/cjs/native-engine/NetworkingSystem.js +733 -793
  108. package/dist/cjs/native-engine/PhysicsEngine.js +583 -607
  109. package/dist/cjs/native-engine/RenderingEngine.js +302 -350
  110. package/dist/cjs/native-engine/SceneGraph.js +769 -808
  111. package/dist/cjs/network/MultiplayerTransport.js +97 -132
  112. package/dist/cjs/network/Networking.js +549 -564
  113. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AbortController.js +21 -29
  114. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +40 -48
  115. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +35 -43
  116. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +10 -15
  117. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Errors.js +103 -135
  118. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +131 -158
  119. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +39 -53
  120. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +5 -8
  121. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +40 -48
  122. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +494 -572
  123. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +826 -953
  124. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +125 -146
  125. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +13 -23
  126. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ILogger.js +11 -25
  127. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ITransport.js +13 -24
  128. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +108 -121
  129. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Loggers.js +10 -14
  130. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +150 -185
  131. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +158 -196
  132. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +90 -105
  133. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Subject.js +30 -35
  134. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +16 -21
  135. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/Utils.js +215 -248
  136. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +135 -157
  137. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +76 -85
  138. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/index.js +24 -27
  139. package/dist/cjs/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +3 -4
  140. package/dist/cjs/pathfinding/Pathfinding.js +245 -263
  141. package/dist/cjs/performance/AssetStreaming.js +561 -635
  142. package/dist/cjs/performance/BenchmarkSuite.js +283 -311
  143. package/dist/cjs/performance/DeltaCompression.js +467 -526
  144. package/dist/cjs/performance/DeterministicPhysics.js +450 -498
  145. package/dist/cjs/performance/ECSOptimization.js +644 -695
  146. package/dist/cjs/performance/GameSaveSystem.js +509 -556
  147. package/dist/cjs/performance/HotReload.js +447 -500
  148. package/dist/cjs/performance/InputRecording.js +511 -561
  149. package/dist/cjs/performance/InterestManagement.js +453 -500
  150. package/dist/cjs/performance/LocalizationRuntime.js +376 -423
  151. package/dist/cjs/performance/MemoryManagement.js +410 -470
  152. package/dist/cjs/performance/ModSupport.js +445 -496
  153. package/dist/cjs/performance/MultiThreadedPhysics.js +400 -443
  154. package/dist/cjs/performance/NetworkPrediction.js +424 -482
  155. package/dist/cjs/performance/ObjectPooling.js +569 -617
  156. package/dist/cjs/performance/Performance.js +174 -190
  157. package/dist/cjs/performance/PerformanceAdvanced.js +614 -637
  158. package/dist/cjs/performance/WebGPURenderer.js +656 -683
  159. package/dist/cjs/physics/PhysicsAdvanced.js +345 -379
  160. package/dist/cjs/physics/PhysicsEngine2D.js +391 -427
  161. package/dist/cjs/plugins/PluginSDK.js +432 -466
  162. package/dist/cjs/plugins/PluginTestKit.js +307 -330
  163. package/dist/cjs/procedural/Procedural.js +243 -254
  164. package/dist/cjs/procedural/WorldBuilding.js +297 -314
  165. package/dist/cjs/quest/QuestSystem.js +975 -932
  166. package/dist/cjs/release/MobileExport.js +157 -163
  167. package/dist/cjs/release/Release.js +225 -238
  168. package/dist/cjs/rendering/Camera2D.js +121 -124
  169. package/dist/cjs/rendering/Renderer2D.js +321 -335
  170. package/dist/cjs/rendering/WebGPURenderPipeline.js +632 -651
  171. package/dist/cjs/runtime3d/Runtime3D.js +359 -378
  172. package/dist/cjs/runtime3d/SceneEditor3D.js +252 -263
  173. package/dist/cjs/scene/SceneManager.js +177 -193
  174. package/dist/cjs/scripting/GraphToAST.js +574 -547
  175. package/dist/cjs/scripting/LanguageExporter.js +254 -279
  176. package/dist/cjs/scripting/NodeGraph.js +546 -570
  177. package/dist/cjs/scripting/ScriptAST.js +31 -39
  178. package/dist/cjs/scripting/VisualScripting2.js +1016 -1065
  179. package/dist/cjs/scripting/exporters/CSharpExporter.js +464 -496
  180. package/dist/cjs/scripting/exporters/GDScriptExporter.js +390 -442
  181. package/dist/cjs/scripting/exporters/LuaExporter.js +406 -447
  182. package/dist/cjs/scripting/exporters/PythonExporter.js +484 -549
  183. package/dist/cjs/scripting/exporters/RustExporter.js +459 -512
  184. package/dist/cjs/scripting/exporters/TypeScriptExporter.js +505 -556
  185. package/dist/cjs/social/Social.js +72 -80
  186. package/dist/cjs/systems/LightingSystem.js +844 -931
  187. package/dist/cjs/systems/ParticleSystem2.js +1447 -1451
  188. package/dist/cjs/systems/PhysicsDebugSystem.js +1070 -1141
  189. package/dist/cjs/systems/TerrainSystem.js +985 -1098
  190. package/dist/cjs/templates/ActionTemplates.js +296 -309
  191. package/dist/cjs/templates/FightingTemplate.js +417 -463
  192. package/dist/cjs/templates/MetroidvaniaTemplate.js +353 -405
  193. package/dist/cjs/templates/PartyTemplates.js +190 -202
  194. package/dist/cjs/templates/PuzzleTemplates.js +245 -261
  195. package/dist/cjs/templates/RPGTemplates.js +160 -178
  196. package/dist/cjs/templates/SportsTemplates.js +237 -250
  197. package/dist/cjs/templates/StrategyTemplates.js +143 -153
  198. package/dist/cjs/templates/SurvivalTemplate.js +336 -380
  199. package/dist/cjs/templates/WaveDefense.js +499 -526
  200. package/dist/cjs/tilemap/Tilemap.js +207 -214
  201. package/dist/cjs/tutorials/TutorialBranching.js +396 -417
  202. package/dist/cjs/tutorials/TutorialEngine.js +888 -931
  203. package/dist/cjs/tutorials/TutorialOverlay.js +602 -640
  204. package/dist/cjs/tutorials/content/Tutorials_T05_T08.js +787 -809
  205. package/dist/cjs/tutorials/content/Tutorials_T09_T11.js +736 -756
  206. package/dist/cjs/tutorials/content/Tutorials_T12_T15.js +754 -778
  207. package/dist/cjs/ui/GameUI.js +295 -312
  208. package/dist/cjs/unity-integration/UnityAssetStore.js +700 -741
  209. package/dist/cjs/unity-integration/UnityImport.js +1066 -1176
  210. package/dist/cjs/unity-integration/UnityLiveLink.js +934 -981
  211. package/dist/cjs/unity-integration/components/UnityAssetStoreBrowser.js +1233 -757
  212. package/dist/cjs/unity-integration/components/UnityProjectBrowser.js +1240 -768
  213. package/dist/cjs/unreal-integration/UnrealImport.js +391 -412
  214. package/dist/cjs/unreal-integration/UnrealLiveLink.js +1102 -1137
  215. package/dist/cjs/unreal-integration/UnrealMarketplace.js +436 -473
  216. package/dist/cjs/unreal-integration/components/UnrealProjectBrowser.js +1150 -767
  217. package/dist/cjs/xr/ARVR.js +167 -175
  218. package/dist/esm/accessibility/Accessibility.js +160 -164
  219. package/dist/esm/ai/AI.js +310 -293
  220. package/dist/esm/ai/BehaviorTree.js +1057 -1112
  221. package/dist/esm/ai/StateMachine.js +709 -755
  222. package/dist/esm/animation/Animation.js +237 -240
  223. package/dist/esm/audio/AudioAdvanced.js +239 -235
  224. package/dist/esm/audio/AudioBridge.js +448 -434
  225. package/dist/esm/audio/AudioManager.js +243 -258
  226. package/dist/esm/build-cloud/BuildOrchestration.js +1071 -1097
  227. package/dist/esm/build-cloud/GodotBuildCloud.js +647 -669
  228. package/dist/esm/build-cloud/UnityBuildCloud.js +571 -609
  229. package/dist/esm/build-cloud/UnrealBuildCloud.js +615 -634
  230. package/dist/esm/core/EventBus.js +52 -55
  231. package/dist/esm/core/GameClock.js +63 -65
  232. package/dist/esm/core/GameConfig.js +77 -78
  233. package/dist/esm/core/GameLoop.js +81 -88
  234. package/dist/esm/core/ServiceLocator.js +63 -64
  235. package/dist/esm/core/Validation.js +82 -81
  236. package/dist/esm/core/math.js +109 -111
  237. package/dist/esm/devtools/DevTools.js +546 -562
  238. package/dist/esm/devtools/DeveloperExperience.js +535 -558
  239. package/dist/esm/devtools/GameplayAnalytics.js +647 -645
  240. package/dist/esm/dialogue/DialogueSystem.js +998 -985
  241. package/dist/esm/docs/DocGenerator.js +342 -363
  242. package/dist/esm/ecs/World.js +358 -370
  243. package/dist/esm/editor/AchievementEditor.js +584 -635
  244. package/dist/esm/editor/AdvancedEditor.js +191 -190
  245. package/dist/esm/editor/AnimationRetargeting.js +700 -740
  246. package/dist/esm/editor/AssetBrowser.js +1078 -1159
  247. package/dist/esm/editor/AssetManager.js +188 -191
  248. package/dist/esm/editor/ConsolePro.js +977 -1060
  249. package/dist/esm/editor/CraftingEditor.js +684 -729
  250. package/dist/esm/editor/DebugTools.js +194 -184
  251. package/dist/esm/editor/DialogueSystem.js +849 -900
  252. package/dist/esm/editor/LeaderboardSystem.js +433 -482
  253. package/dist/esm/editor/NiceGameEditor.js +1908 -1200
  254. package/dist/esm/editor/PrefabSystem.js +777 -837
  255. package/dist/esm/editor/ProfilerPanel.js +654 -699
  256. package/dist/esm/editor/QuestEditor.js +795 -838
  257. package/dist/esm/editor/ReplaySystem.js +591 -633
  258. package/dist/esm/editor/SceneEditor.js +189 -199
  259. package/dist/esm/editor/ScreenshotMode.js +628 -687
  260. package/dist/esm/editor/ShaderGraph.js +1565 -1581
  261. package/dist/esm/editor/TimelineEditor.js +733 -777
  262. package/dist/esm/editor/UndoRedoPro.js +835 -903
  263. package/dist/esm/editor/VRARMode.js +586 -644
  264. package/dist/esm/engine/NiceGameEngine.js +142 -163
  265. package/dist/esm/engine/SaveSystem.js +447 -494
  266. package/dist/esm/enterprise/Enterprise.js +265 -260
  267. package/dist/esm/export/BevyExporter.js +929 -966
  268. package/dist/esm/export/CocosExporter.js +646 -672
  269. package/dist/esm/export/Construct3Exporter.js +785 -793
  270. package/dist/esm/export/DefoldExporter.js +1030 -1068
  271. package/dist/esm/export/GDevelopExporter.js +676 -707
  272. package/dist/esm/export/GameMakerExporter.js +793 -804
  273. package/dist/esm/export/GodotExporter.js +1004 -1044
  274. package/dist/esm/export/MinecraftBedrockExporter.js +575 -577
  275. package/dist/esm/export/MonoGameExporter.js +1267 -1292
  276. package/dist/esm/export/Pico8Exporter.js +768 -811
  277. package/dist/esm/export/PlatformExporter.js +193 -205
  278. package/dist/esm/export/RPGMakerExporter.js +862 -878
  279. package/dist/esm/export/RobloxExporter.js +885 -918
  280. package/dist/esm/export/Solar2DExporter.js +1220 -1255
  281. package/dist/esm/export/ThreeJSExporter.js +1007 -1072
  282. package/dist/esm/export/Tic80Exporter.js +1212 -1266
  283. package/dist/esm/export/UnityExporter.js +1117 -1130
  284. package/dist/esm/export/UnrealExporter.js +891 -918
  285. package/dist/esm/export/WebExporter.js +933 -969
  286. package/dist/esm/export/index.js +86 -71
  287. package/dist/esm/godot-integration/GodotAssetLibrary.js +663 -691
  288. package/dist/esm/godot-integration/GodotImport.js +935 -1026
  289. package/dist/esm/godot-integration/GodotLiveLink.js +918 -944
  290. package/dist/esm/godot-integration/components/GodotProjectBrowser.js +912 -610
  291. package/dist/esm/i18n/I18n.js +871 -899
  292. package/dist/esm/i18n/useTranslation.js +88 -88
  293. package/dist/esm/import/AsepriteImporter.js +637 -715
  294. package/dist/esm/import/DragonBonesImporter.js +417 -460
  295. package/dist/esm/import/GameMakerImporter.js +491 -520
  296. package/dist/esm/import/GodotSceneImporter.js +767 -821
  297. package/dist/esm/import/LDtkImporter.js +415 -453
  298. package/dist/esm/import/Live2DImporter.js +477 -517
  299. package/dist/esm/import/NdgFormat.js +410 -456
  300. package/dist/esm/import/OgmoImporter.js +446 -492
  301. package/dist/esm/import/RPGMakerImporter.js +431 -476
  302. package/dist/esm/import/SceneImporter.js +385 -422
  303. package/dist/esm/import/SpineImporter.js +491 -545
  304. package/dist/esm/import/SpriterImporter.js +570 -612
  305. package/dist/esm/import/TiledMapImporter.js +790 -845
  306. package/dist/esm/import/UnitySceneImporter.js +666 -702
  307. package/dist/esm/import/index.js +247 -258
  308. package/dist/esm/index.js +1332 -188
  309. package/dist/esm/input/GamepadNavigation.js +187 -204
  310. package/dist/esm/input/InputManager.js +401 -420
  311. package/dist/esm/input/useGamepads.js +72 -80
  312. package/dist/esm/integration/IconSprite.js +143 -255
  313. package/dist/esm/inventory/InventorySystem.js +925 -994
  314. package/dist/esm/kids/KidMode.js +1003 -1021
  315. package/dist/esm/kids/KidTools.js +573 -593
  316. package/dist/esm/monetization/Monetization.js +180 -176
  317. package/dist/esm/multiplayer/LocalMultiplayer.js +290 -286
  318. package/dist/esm/multiplayer/MiniGameTypes.js +58 -58
  319. package/dist/esm/native-engine/AnimationSystem.js +735 -805
  320. package/dist/esm/native-engine/AssetPipeline.js +456 -514
  321. package/dist/esm/native-engine/AudioEngine.js +765 -803
  322. package/dist/esm/native-engine/InputSystem.js +1079 -1144
  323. package/dist/esm/native-engine/NetworkingSystem.js +740 -792
  324. package/dist/esm/native-engine/PhysicsEngine.js +585 -606
  325. package/dist/esm/native-engine/RenderingEngine.js +304 -349
  326. package/dist/esm/native-engine/SceneGraph.js +773 -807
  327. package/dist/esm/network/MultiplayerTransport.js +99 -131
  328. package/dist/esm/network/Networking.js +556 -563
  329. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AbortController.js +22 -28
  330. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/AccessTokenHttpClient.js +41 -47
  331. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +36 -42
  332. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +11 -14
  333. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Errors.js +111 -134
  334. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +132 -157
  335. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +40 -52
  336. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +6 -7
  337. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +42 -47
  338. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +496 -571
  339. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +828 -952
  340. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +126 -145
  341. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +14 -23
  342. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ILogger.js +12 -25
  343. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ITransport.js +15 -24
  344. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +109 -120
  345. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Loggers.js +11 -13
  346. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +151 -184
  347. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/MessageBuffer.js +159 -195
  348. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +91 -104
  349. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Subject.js +31 -34
  350. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +17 -20
  351. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/Utils.js +230 -248
  352. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +136 -156
  353. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +77 -84
  354. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/index.js +31 -12
  355. package/dist/esm/node_modules/@microsoft/signalr/dist/esm/pkg-version.js +4 -3
  356. package/dist/esm/pathfinding/Pathfinding.js +249 -262
  357. package/dist/esm/performance/AssetStreaming.js +567 -634
  358. package/dist/esm/performance/BenchmarkSuite.js +285 -310
  359. package/dist/esm/performance/DeltaCompression.js +478 -525
  360. package/dist/esm/performance/DeterministicPhysics.js +479 -497
  361. package/dist/esm/performance/ECSOptimization.js +653 -694
  362. package/dist/esm/performance/GameSaveSystem.js +515 -555
  363. package/dist/esm/performance/HotReload.js +454 -499
  364. package/dist/esm/performance/InputRecording.js +520 -560
  365. package/dist/esm/performance/InterestManagement.js +460 -499
  366. package/dist/esm/performance/LocalizationRuntime.js +382 -422
  367. package/dist/esm/performance/MemoryManagement.js +415 -469
  368. package/dist/esm/performance/ModSupport.js +455 -495
  369. package/dist/esm/performance/MultiThreadedPhysics.js +408 -442
  370. package/dist/esm/performance/NetworkPrediction.js +436 -481
  371. package/dist/esm/performance/ObjectPooling.js +582 -616
  372. package/dist/esm/performance/Performance.js +182 -189
  373. package/dist/esm/performance/PerformanceAdvanced.js +621 -636
  374. package/dist/esm/performance/WebGPURenderer.js +660 -682
  375. package/dist/esm/physics/PhysicsAdvanced.js +359 -378
  376. package/dist/esm/physics/PhysicsEngine2D.js +393 -426
  377. package/dist/esm/plugins/PluginSDK.js +435 -465
  378. package/dist/esm/plugins/PluginTestKit.js +315 -329
  379. package/dist/esm/procedural/Procedural.js +248 -253
  380. package/dist/esm/procedural/WorldBuilding.js +316 -313
  381. package/dist/esm/quest/QuestSystem.js +982 -931
  382. package/dist/esm/release/MobileExport.js +163 -162
  383. package/dist/esm/release/Release.js +234 -237
  384. package/dist/esm/rendering/Camera2D.js +122 -123
  385. package/dist/esm/rendering/Renderer2D.js +323 -334
  386. package/dist/esm/rendering/WebGPURenderPipeline.js +647 -650
  387. package/dist/esm/runtime3d/Runtime3D.js +368 -377
  388. package/dist/esm/runtime3d/SceneEditor3D.js +268 -262
  389. package/dist/esm/scene/SceneManager.js +178 -192
  390. package/dist/esm/scripting/GraphToAST.js +576 -546
  391. package/dist/esm/scripting/LanguageExporter.js +263 -278
  392. package/dist/esm/scripting/NodeGraph.js +550 -569
  393. package/dist/esm/scripting/ScriptAST.js +45 -38
  394. package/dist/esm/scripting/VisualScripting2.js +1025 -1064
  395. package/dist/esm/scripting/exporters/CSharpExporter.js +465 -495
  396. package/dist/esm/scripting/exporters/GDScriptExporter.js +391 -441
  397. package/dist/esm/scripting/exporters/LuaExporter.js +407 -446
  398. package/dist/esm/scripting/exporters/PythonExporter.js +485 -548
  399. package/dist/esm/scripting/exporters/RustExporter.js +460 -511
  400. package/dist/esm/scripting/exporters/TypeScriptExporter.js +506 -555
  401. package/dist/esm/social/Social.js +77 -79
  402. package/dist/esm/systems/LightingSystem.js +855 -930
  403. package/dist/esm/systems/ParticleSystem2.js +1453 -1450
  404. package/dist/esm/systems/PhysicsDebugSystem.js +1078 -1140
  405. package/dist/esm/systems/TerrainSystem.js +996 -1097
  406. package/dist/esm/templates/ActionTemplates.js +307 -308
  407. package/dist/esm/templates/FightingTemplate.js +439 -462
  408. package/dist/esm/templates/MetroidvaniaTemplate.js +391 -404
  409. package/dist/esm/templates/PartyTemplates.js +206 -201
  410. package/dist/esm/templates/PuzzleTemplates.js +260 -260
  411. package/dist/esm/templates/RPGTemplates.js +172 -177
  412. package/dist/esm/templates/SportsTemplates.js +251 -249
  413. package/dist/esm/templates/StrategyTemplates.js +158 -152
  414. package/dist/esm/templates/SurvivalTemplate.js +367 -379
  415. package/dist/esm/templates/WaveDefense.js +501 -525
  416. package/dist/esm/tilemap/Tilemap.js +209 -213
  417. package/dist/esm/tutorials/TutorialBranching.js +399 -416
  418. package/dist/esm/tutorials/TutorialEngine.js +893 -930
  419. package/dist/esm/tutorials/TutorialOverlay.js +603 -639
  420. package/dist/esm/tutorials/content/Tutorials_T05_T08.js +792 -808
  421. package/dist/esm/tutorials/content/Tutorials_T09_T11.js +740 -755
  422. package/dist/esm/tutorials/content/Tutorials_T12_T15.js +759 -777
  423. package/dist/esm/ui/GameUI.js +296 -311
  424. package/dist/esm/unity-integration/UnityAssetStore.js +704 -740
  425. package/dist/esm/unity-integration/UnityImport.js +1071 -1175
  426. package/dist/esm/unity-integration/UnityLiveLink.js +938 -980
  427. package/dist/esm/unity-integration/components/UnityAssetStoreBrowser.js +1234 -756
  428. package/dist/esm/unity-integration/components/UnityProjectBrowser.js +1241 -767
  429. package/dist/esm/unreal-integration/UnrealImport.js +395 -411
  430. package/dist/esm/unreal-integration/UnrealLiveLink.js +1105 -1136
  431. package/dist/esm/unreal-integration/UnrealMarketplace.js +442 -472
  432. package/dist/esm/unreal-integration/components/UnrealProjectBrowser.js +1151 -766
  433. package/dist/esm/xr/ARVR.js +181 -174
  434. package/package.json +7 -12
@@ -1,1128 +1,1102 @@
1
- /**
2
- * @file BuildOrchestration.ts
3
- * @description Build Orchestration system for managing cloud builds
4
- * PRO-1.7.4: Build Orchestration
5
- *
6
- * Features:
7
- * - Build Queue Manager (Kubernetes-based job scheduler)
8
- * - Priority queues (paid vs free tier)
9
- * - Concurrent build limits
10
- * - Auto-scaling workers
11
- * - Spot instance support
12
- * - Build Agent Pool management
13
- * - Artifact Storage (S3/MinIO)
14
- * - Build Notifications (webhooks, email, Slack, Discord)
15
- * - Build Analytics
16
- */
17
1
  class BuildQueueManager {
18
- constructor() {
19
- this.queues = new Map();
20
- this.jobs = new Map();
21
- this.jobQueues = new Map(); // queue name -> job IDs
22
- this.callbacks = {};
23
- // Create default queues
24
- this.createDefaultQueues();
25
- }
26
- createDefaultQueues() {
27
- const defaultQueues = [
28
- {
29
- name: 'free-linux',
30
- priority: 'low',
31
- maxConcurrent: 2,
32
- maxQueueSize: 100,
33
- buildTimeout: 1800000, // 30 min
34
- supportedEngines: ['unity', 'godot', 'nice2dev'],
35
- supportedPlatforms: ['linux', 'webgl', 'web'],
36
- isPaidTier: false,
37
- rateLimitPerHour: 5,
38
- },
39
- {
40
- name: 'free-windows',
41
- priority: 'low',
42
- maxConcurrent: 2,
43
- maxQueueSize: 100,
44
- buildTimeout: 1800000,
45
- supportedEngines: ['unity', 'godot', 'unreal', 'nice2dev'],
46
- supportedPlatforms: ['windows', 'android'],
47
- isPaidTier: false,
48
- rateLimitPerHour: 5,
49
- },
50
- {
51
- name: 'pro-priority',
52
- priority: 'high',
53
- maxConcurrent: 10,
54
- maxQueueSize: 500,
55
- buildTimeout: 7200000, // 2 hours
56
- supportedEngines: ['unity', 'godot', 'unreal', 'nice2dev'],
57
- supportedPlatforms: ['*'],
58
- isPaidTier: true,
59
- },
60
- {
61
- name: 'enterprise',
62
- priority: 'critical',
63
- maxConcurrent: 50,
64
- maxQueueSize: 1000,
65
- buildTimeout: 14400000, // 4 hours
66
- supportedEngines: ['unity', 'godot', 'unreal', 'nice2dev'],
67
- supportedPlatforms: ['*'],
68
- isPaidTier: true,
69
- },
70
- ];
71
- for (const queue of defaultQueues) {
72
- this.queues.set(queue.name, queue);
73
- this.jobQueues.set(queue.name, []);
74
- }
75
- }
76
- // ─── Queue Management ──────────────────────────────────
77
- createQueue(config) {
78
- this.queues.set(config.name, config);
79
- this.jobQueues.set(config.name, []);
80
- }
81
- getQueue(name) {
82
- return this.queues.get(name);
83
- }
84
- getQueues() {
85
- return Array.from(this.queues.values());
86
- }
87
- deleteQueue(name) {
88
- if (!this.queues.has(name)) {
89
- return false;
90
- }
91
- // Cancel all jobs in queue
92
- const queueJobs = this.jobQueues.get(name) ?? [];
93
- for (const jobId of queueJobs) {
94
- this.cancelJob(jobId);
95
- }
96
- this.queues.delete(name);
97
- this.jobQueues.delete(name);
98
- return true;
99
- }
100
- // ─── Job Management ────────────────────────────────────
101
- submitJob(engine, platform, buildConfig, options) {
102
- const jobId = this.generateJobId();
103
- const priority = options?.priority ?? 'normal';
104
- // Find appropriate queue
105
- const queueName = this.findQueueForJob(engine, platform, priority);
106
- if (!queueName) {
107
- throw new Error(`No available queue for ${engine}/${platform}`);
108
- }
109
- const queue = this.queues.get(queueName);
110
- const queueJobs = this.jobQueues.get(queueName);
111
- // Check queue limits
112
- if (queueJobs.length >= queue.maxQueueSize) {
113
- throw new Error(`Queue ${queueName} is full`);
114
- }
115
- const job = {
116
- id: jobId,
117
- userId: options?.userId ?? 'anonymous',
118
- engine,
119
- platform,
120
- priority,
121
- status: 'queued',
122
- queuePosition: queueJobs.length + 1,
123
- createdAt: Date.now(),
124
- buildConfig,
125
- retryCount: 0,
126
- maxRetries: options?.maxRetries ?? 3,
127
- estimatedWaitTime: this.estimateWaitTime(queueName),
128
- estimatedBuildTime: this.estimateBuildTime(engine, platform),
129
- };
130
- this.jobs.set(jobId, job);
131
- queueJobs.push(jobId);
132
- this.callbacks.onJobQueued?.(job);
133
- return job;
134
- }
135
- findQueueForJob(engine, platform, priority) {
136
- for (const [name, queue] of this.queues) {
137
- if (!queue.supportedEngines.includes(engine)) {
138
- continue;
139
- }
140
- if (!queue.supportedPlatforms.includes('*') && !queue.supportedPlatforms.includes(platform)) {
141
- continue;
142
- }
143
- if (this.getPriorityLevel(priority) > this.getPriorityLevel(queue.priority)) {
144
- continue;
145
- }
146
- return name;
147
- }
148
- return null;
149
- }
150
- getPriorityLevel(priority) {
151
- const levels = {
152
- low: 0,
153
- normal: 1,
154
- high: 2,
155
- critical: 3,
156
- };
157
- return levels[priority];
158
- }
159
- generateJobId() {
160
- return `job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
161
- }
162
- estimateWaitTime(queueName) {
163
- const queue = this.queues.get(queueName);
164
- const queueJobs = this.jobQueues.get(queueName);
165
- if (!queue || !queueJobs) {
166
- return 0;
167
- }
168
- // Simple estimation: position * average build time / concurrent builds
169
- const avgBuildTime = 600000; // 10 minutes average
170
- return (queueJobs.length * avgBuildTime) / queue.maxConcurrent;
171
- }
172
- estimateBuildTime(engine, _platform) {
173
- // Rough estimates in ms
174
- const estimates = {
175
- unity: 900000, // 15 minutes
176
- godot: 300000, // 5 minutes
177
- unreal: 1800000, // 30 minutes
178
- nice2dev: 120000, // 2 minutes
179
- };
180
- return estimates[engine] ?? 600000;
181
- }
182
- cancelJob(jobId) {
183
- const job = this.jobs.get(jobId);
184
- if (!job) {
185
- return false;
186
- }
187
- if (job.status === 'completed' || job.status === 'cancelled') {
188
- return false;
189
- }
190
- job.status = 'cancelled';
191
- job.completedAt = Date.now();
192
- // Remove from queue
193
- for (const [queueName, queueJobs] of this.jobQueues) {
194
- const idx = queueJobs.indexOf(jobId);
195
- if (idx !== -1) {
196
- queueJobs.splice(idx, 1);
197
- this.updateQueuePositions(queueName);
198
- break;
199
- }
200
- }
201
- this.callbacks.onJobCancelled?.(job);
202
- return true;
203
- }
204
- updateQueuePositions(queueName) {
205
- const queueJobs = this.jobQueues.get(queueName);
206
- if (!queueJobs) {
207
- return;
208
- }
209
- for (let i = 0; i < queueJobs.length; i++) {
210
- const job = this.jobs.get(queueJobs[i]);
211
- if (job && job.status === 'queued') {
212
- job.queuePosition = i + 1;
213
- }
214
- }
215
- }
216
- getJob(jobId) {
217
- return this.jobs.get(jobId);
218
- }
219
- getJobsByUser(userId) {
220
- return Array.from(this.jobs.values()).filter((job) => job.userId === userId);
221
- }
222
- getJobsByStatus(status) {
223
- return Array.from(this.jobs.values()).filter((job) => job.status === status);
224
- }
225
- // ─── Job Assignment ────────────────────────────────────
226
- assignJobToAgent(jobId, agentId) {
227
- const job = this.jobs.get(jobId);
228
- if (!job || job.status !== 'queued') {
229
- return false;
230
- }
231
- job.status = 'assigned';
232
- job.assignedAgentId = agentId;
233
- job.startedAt = Date.now();
234
- this.callbacks.onJobAssigned?.(job, agentId);
235
- return true;
236
- }
237
- startJob(jobId) {
238
- const job = this.jobs.get(jobId);
239
- if (!job || job.status !== 'assigned') {
240
- return false;
241
- }
242
- job.status = 'running';
243
- this.callbacks.onJobStarted?.(job);
244
- return true;
245
- }
246
- completeJob(jobId, artifacts) {
247
- const job = this.jobs.get(jobId);
248
- if (!job || job.status !== 'running') {
249
- return false;
250
- }
251
- job.status = 'completed';
252
- job.completedAt = Date.now();
253
- job.artifacts = artifacts;
254
- this.callbacks.onJobCompleted?.(job);
255
- return true;
256
- }
257
- failJob(jobId, error) {
258
- const job = this.jobs.get(jobId);
259
- if (!job) {
260
- return false;
261
- }
262
- job.error = error;
263
- // Check if should retry
264
- if (job.retryCount < job.maxRetries) {
265
- job.retryCount++;
266
- job.status = 'queued';
267
- job.assignedAgentId = undefined;
268
- job.startedAt = undefined;
269
- this.callbacks.onJobRetry?.(job);
270
- }
271
- else {
272
- job.status = 'failed';
273
- job.completedAt = Date.now();
274
- this.callbacks.onJobFailed?.(job, error);
275
- }
276
- return true;
277
- }
278
- // ─── Queue Stats ───────────────────────────────────────
279
- getQueueStats(queueName) {
280
- const queue = this.queues.get(queueName);
281
- const queueJobs = this.jobQueues.get(queueName);
282
- if (!queue || !queueJobs) {
283
- return undefined;
284
- }
285
- let running = 0;
286
- let waiting = 0;
287
- for (const jobId of queueJobs) {
288
- const job = this.jobs.get(jobId);
289
- if (!job) {
290
- continue;
291
- }
292
- if (job.status === 'running') {
293
- running++;
294
- }
295
- else if (job.status === 'queued') {
296
- waiting++;
297
- }
298
- }
299
- return {
300
- queueName,
301
- totalJobs: queueJobs.length,
302
- runningJobs: running,
303
- waitingJobs: waiting,
304
- maxConcurrent: queue.maxConcurrent,
305
- maxQueueSize: queue.maxQueueSize,
306
- utilizationPercent: (running / queue.maxConcurrent) * 100,
307
- estimatedWaitTime: this.estimateWaitTime(queueName),
308
- };
309
- }
310
- getAllQueueStats() {
311
- return Array.from(this.queues.keys())
312
- .map((name) => this.getQueueStats(name))
313
- .filter(Boolean);
314
- }
315
- // ─── Callbacks ─────────────────────────────────────────
316
- setCallbacks(callbacks) {
317
- this.callbacks = { ...this.callbacks, ...callbacks };
318
- }
2
+ constructor() {
3
+ this.queues = /* @__PURE__ */ new Map();
4
+ this.jobs = /* @__PURE__ */ new Map();
5
+ this.jobQueues = /* @__PURE__ */ new Map();
6
+ this.callbacks = {};
7
+ this.createDefaultQueues();
8
+ }
9
+ createDefaultQueues() {
10
+ const defaultQueues = [
11
+ {
12
+ name: "free-linux",
13
+ priority: "low",
14
+ maxConcurrent: 2,
15
+ maxQueueSize: 100,
16
+ buildTimeout: 18e5,
17
+ // 30 min
18
+ supportedEngines: ["unity", "godot", "nice2dev"],
19
+ supportedPlatforms: ["linux", "webgl", "web"],
20
+ isPaidTier: false,
21
+ rateLimitPerHour: 5
22
+ },
23
+ {
24
+ name: "free-windows",
25
+ priority: "low",
26
+ maxConcurrent: 2,
27
+ maxQueueSize: 100,
28
+ buildTimeout: 18e5,
29
+ supportedEngines: ["unity", "godot", "unreal", "nice2dev"],
30
+ supportedPlatforms: ["windows", "android"],
31
+ isPaidTier: false,
32
+ rateLimitPerHour: 5
33
+ },
34
+ {
35
+ name: "pro-priority",
36
+ priority: "high",
37
+ maxConcurrent: 10,
38
+ maxQueueSize: 500,
39
+ buildTimeout: 72e5,
40
+ // 2 hours
41
+ supportedEngines: ["unity", "godot", "unreal", "nice2dev"],
42
+ supportedPlatforms: ["*"],
43
+ isPaidTier: true
44
+ },
45
+ {
46
+ name: "enterprise",
47
+ priority: "critical",
48
+ maxConcurrent: 50,
49
+ maxQueueSize: 1e3,
50
+ buildTimeout: 144e5,
51
+ // 4 hours
52
+ supportedEngines: ["unity", "godot", "unreal", "nice2dev"],
53
+ supportedPlatforms: ["*"],
54
+ isPaidTier: true
55
+ }
56
+ ];
57
+ for (const queue of defaultQueues) {
58
+ this.queues.set(queue.name, queue);
59
+ this.jobQueues.set(queue.name, []);
60
+ }
61
+ }
62
+ // ─── Queue Management ──────────────────────────────────
63
+ createQueue(config) {
64
+ this.queues.set(config.name, config);
65
+ this.jobQueues.set(config.name, []);
66
+ }
67
+ getQueue(name) {
68
+ return this.queues.get(name);
69
+ }
70
+ getQueues() {
71
+ return Array.from(this.queues.values());
72
+ }
73
+ deleteQueue(name) {
74
+ if (!this.queues.has(name)) {
75
+ return false;
76
+ }
77
+ const queueJobs = this.jobQueues.get(name) ?? [];
78
+ for (const jobId of queueJobs) {
79
+ this.cancelJob(jobId);
80
+ }
81
+ this.queues.delete(name);
82
+ this.jobQueues.delete(name);
83
+ return true;
84
+ }
85
+ // ─── Job Management ────────────────────────────────────
86
+ submitJob(engine, platform, buildConfig, options) {
87
+ const jobId = this.generateJobId();
88
+ const priority = options?.priority ?? "normal";
89
+ const queueName = this.findQueueForJob(engine, platform, priority);
90
+ if (!queueName) {
91
+ throw new Error(`No available queue for ${engine}/${platform}`);
92
+ }
93
+ const queue = this.queues.get(queueName);
94
+ const queueJobs = this.jobQueues.get(queueName);
95
+ if (queueJobs.length >= queue.maxQueueSize) {
96
+ throw new Error(`Queue ${queueName} is full`);
97
+ }
98
+ const job = {
99
+ id: jobId,
100
+ userId: options?.userId ?? "anonymous",
101
+ engine,
102
+ platform,
103
+ priority,
104
+ status: "queued",
105
+ queuePosition: queueJobs.length + 1,
106
+ createdAt: Date.now(),
107
+ buildConfig,
108
+ retryCount: 0,
109
+ maxRetries: options?.maxRetries ?? 3,
110
+ estimatedWaitTime: this.estimateWaitTime(queueName),
111
+ estimatedBuildTime: this.estimateBuildTime(engine, platform)
112
+ };
113
+ this.jobs.set(jobId, job);
114
+ queueJobs.push(jobId);
115
+ this.callbacks.onJobQueued?.(job);
116
+ return job;
117
+ }
118
+ findQueueForJob(engine, platform, priority) {
119
+ for (const [name, queue] of this.queues) {
120
+ if (!queue.supportedEngines.includes(engine)) {
121
+ continue;
122
+ }
123
+ if (!queue.supportedPlatforms.includes("*") && !queue.supportedPlatforms.includes(platform)) {
124
+ continue;
125
+ }
126
+ if (this.getPriorityLevel(priority) > this.getPriorityLevel(queue.priority)) {
127
+ continue;
128
+ }
129
+ return name;
130
+ }
131
+ return null;
132
+ }
133
+ getPriorityLevel(priority) {
134
+ const levels = {
135
+ low: 0,
136
+ normal: 1,
137
+ high: 2,
138
+ critical: 3
139
+ };
140
+ return levels[priority];
141
+ }
142
+ generateJobId() {
143
+ return `job-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
144
+ }
145
+ estimateWaitTime(queueName) {
146
+ const queue = this.queues.get(queueName);
147
+ const queueJobs = this.jobQueues.get(queueName);
148
+ if (!queue || !queueJobs) {
149
+ return 0;
150
+ }
151
+ const avgBuildTime = 6e5;
152
+ return queueJobs.length * avgBuildTime / queue.maxConcurrent;
153
+ }
154
+ estimateBuildTime(engine, _platform) {
155
+ const estimates = {
156
+ unity: 9e5,
157
+ // 15 minutes
158
+ godot: 3e5,
159
+ // 5 minutes
160
+ unreal: 18e5,
161
+ // 30 minutes
162
+ nice2dev: 12e4
163
+ // 2 minutes
164
+ };
165
+ return estimates[engine] ?? 6e5;
166
+ }
167
+ cancelJob(jobId) {
168
+ const job = this.jobs.get(jobId);
169
+ if (!job) {
170
+ return false;
171
+ }
172
+ if (job.status === "completed" || job.status === "cancelled") {
173
+ return false;
174
+ }
175
+ job.status = "cancelled";
176
+ job.completedAt = Date.now();
177
+ for (const [queueName, queueJobs] of this.jobQueues) {
178
+ const idx = queueJobs.indexOf(jobId);
179
+ if (idx !== -1) {
180
+ queueJobs.splice(idx, 1);
181
+ this.updateQueuePositions(queueName);
182
+ break;
183
+ }
184
+ }
185
+ this.callbacks.onJobCancelled?.(job);
186
+ return true;
187
+ }
188
+ updateQueuePositions(queueName) {
189
+ const queueJobs = this.jobQueues.get(queueName);
190
+ if (!queueJobs) {
191
+ return;
192
+ }
193
+ for (let i = 0; i < queueJobs.length; i++) {
194
+ const job = this.jobs.get(queueJobs[i]);
195
+ if (job && job.status === "queued") {
196
+ job.queuePosition = i + 1;
197
+ }
198
+ }
199
+ }
200
+ getJob(jobId) {
201
+ return this.jobs.get(jobId);
202
+ }
203
+ getJobsByUser(userId) {
204
+ return Array.from(this.jobs.values()).filter((job) => job.userId === userId);
205
+ }
206
+ getJobsByStatus(status) {
207
+ return Array.from(this.jobs.values()).filter((job) => job.status === status);
208
+ }
209
+ // ─── Job Assignment ────────────────────────────────────
210
+ assignJobToAgent(jobId, agentId) {
211
+ const job = this.jobs.get(jobId);
212
+ if (!job || job.status !== "queued") {
213
+ return false;
214
+ }
215
+ job.status = "assigned";
216
+ job.assignedAgentId = agentId;
217
+ job.startedAt = Date.now();
218
+ this.callbacks.onJobAssigned?.(job, agentId);
219
+ return true;
220
+ }
221
+ startJob(jobId) {
222
+ const job = this.jobs.get(jobId);
223
+ if (!job || job.status !== "assigned") {
224
+ return false;
225
+ }
226
+ job.status = "running";
227
+ this.callbacks.onJobStarted?.(job);
228
+ return true;
229
+ }
230
+ completeJob(jobId, artifacts) {
231
+ const job = this.jobs.get(jobId);
232
+ if (!job || job.status !== "running") {
233
+ return false;
234
+ }
235
+ job.status = "completed";
236
+ job.completedAt = Date.now();
237
+ job.artifacts = artifacts;
238
+ this.callbacks.onJobCompleted?.(job);
239
+ return true;
240
+ }
241
+ failJob(jobId, error) {
242
+ const job = this.jobs.get(jobId);
243
+ if (!job) {
244
+ return false;
245
+ }
246
+ job.error = error;
247
+ if (job.retryCount < job.maxRetries) {
248
+ job.retryCount++;
249
+ job.status = "queued";
250
+ job.assignedAgentId = void 0;
251
+ job.startedAt = void 0;
252
+ this.callbacks.onJobRetry?.(job);
253
+ } else {
254
+ job.status = "failed";
255
+ job.completedAt = Date.now();
256
+ this.callbacks.onJobFailed?.(job, error);
257
+ }
258
+ return true;
259
+ }
260
+ // ─── Queue Stats ───────────────────────────────────────
261
+ getQueueStats(queueName) {
262
+ const queue = this.queues.get(queueName);
263
+ const queueJobs = this.jobQueues.get(queueName);
264
+ if (!queue || !queueJobs) {
265
+ return void 0;
266
+ }
267
+ let running = 0;
268
+ let waiting = 0;
269
+ for (const jobId of queueJobs) {
270
+ const job = this.jobs.get(jobId);
271
+ if (!job) {
272
+ continue;
273
+ }
274
+ if (job.status === "running") {
275
+ running++;
276
+ } else if (job.status === "queued") {
277
+ waiting++;
278
+ }
279
+ }
280
+ return {
281
+ queueName,
282
+ totalJobs: queueJobs.length,
283
+ runningJobs: running,
284
+ waitingJobs: waiting,
285
+ maxConcurrent: queue.maxConcurrent,
286
+ maxQueueSize: queue.maxQueueSize,
287
+ utilizationPercent: running / queue.maxConcurrent * 100,
288
+ estimatedWaitTime: this.estimateWaitTime(queueName)
289
+ };
290
+ }
291
+ getAllQueueStats() {
292
+ return Array.from(this.queues.keys()).map((name) => this.getQueueStats(name)).filter(Boolean);
293
+ }
294
+ // ─── Callbacks ─────────────────────────────────────────
295
+ setCallbacks(callbacks) {
296
+ this.callbacks = { ...this.callbacks, ...callbacks };
297
+ }
319
298
  }
320
299
  class BuildAgentPool {
321
- constructor() {
322
- this.agents = new Map();
323
- this.pools = new Map();
324
- this.callbacks = {};
325
- this.heartbeatInterval = 30000; // 30 seconds
326
- this.heartbeatTimeout = 90000; // 90 seconds
327
- // Create default pools
328
- this.createDefaultPools();
329
- }
330
- createDefaultPools() {
331
- const defaultPools = [
332
- {
333
- name: 'linux-pool',
334
- minAgents: 2,
335
- maxAgents: 20,
336
- agentTemplate: {
337
- os: 'linux',
338
- supportedEngines: ['unity', 'godot', 'nice2dev'],
339
- supportedPlatforms: ['linux', 'webgl', 'web', 'android'],
340
- cpuCores: 8,
341
- memoryGB: 32,
342
- diskGB: 500,
343
- },
344
- autoScaling: true,
345
- scaleUpThreshold: 5,
346
- scaleDownThreshold: 300000, // 5 minutes
347
- useSpotInstances: true,
348
- spotPercentage: 50,
349
- },
350
- {
351
- name: 'windows-pool',
352
- minAgents: 2,
353
- maxAgents: 20,
354
- agentTemplate: {
355
- os: 'windows',
356
- supportedEngines: ['unity', 'godot', 'unreal', 'nice2dev'],
357
- supportedPlatforms: ['windows', 'android', 'uwp'],
358
- cpuCores: 16,
359
- memoryGB: 64,
360
- diskGB: 1000,
361
- },
362
- autoScaling: true,
363
- scaleUpThreshold: 3,
364
- scaleDownThreshold: 300000,
365
- useSpotInstances: true,
366
- spotPercentage: 30,
367
- },
368
- {
369
- name: 'macos-pool',
370
- minAgents: 1,
371
- maxAgents: 10,
372
- agentTemplate: {
373
- os: 'macos',
374
- supportedEngines: ['unity', 'godot', 'unreal', 'nice2dev'],
375
- supportedPlatforms: ['macos', 'ios', 'tvos'],
376
- cpuCores: 8,
377
- memoryGB: 32,
378
- diskGB: 500,
379
- },
380
- autoScaling: true,
381
- scaleUpThreshold: 2,
382
- scaleDownThreshold: 600000, // 10 minutes (more expensive)
383
- useSpotInstances: false,
384
- spotPercentage: 0,
385
- },
386
- ];
387
- for (const pool of defaultPools) {
388
- this.pools.set(pool.name, pool);
389
- }
390
- }
391
- // ─── Pool Management ───────────────────────────────────
392
- createPool(config) {
393
- this.pools.set(config.name, config);
394
- }
395
- getPool(name) {
396
- return this.pools.get(name);
397
- }
398
- getPools() {
399
- return Array.from(this.pools.values());
400
- }
401
- deletePool(name) {
402
- return this.pools.delete(name);
403
- }
404
- // ─── Agent Management ──────────────────────────────────
405
- registerAgent(agent) {
406
- const fullAgent = {
407
- ...agent,
408
- id: this.generateAgentId(),
409
- lastHeartbeat: Date.now(),
410
- jobsCompleted: 0,
411
- jobsFailed: 0,
412
- avgBuildTime: 0,
413
- };
414
- this.agents.set(fullAgent.id, fullAgent);
415
- this.callbacks.onAgentRegistered?.(fullAgent);
416
- return fullAgent;
417
- }
418
- generateAgentId() {
419
- return `agent-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
420
- }
421
- unregisterAgent(agentId) {
422
- const agent = this.agents.get(agentId);
423
- if (!agent) {
424
- return false;
425
- }
426
- // If agent has a job, mark it for reassignment
300
+ // 90 seconds
301
+ constructor() {
302
+ this.agents = /* @__PURE__ */ new Map();
303
+ this.pools = /* @__PURE__ */ new Map();
304
+ this.callbacks = {};
305
+ this.heartbeatInterval = 3e4;
306
+ this.heartbeatTimeout = 9e4;
307
+ this.createDefaultPools();
308
+ }
309
+ createDefaultPools() {
310
+ const defaultPools = [
311
+ {
312
+ name: "linux-pool",
313
+ minAgents: 2,
314
+ maxAgents: 20,
315
+ agentTemplate: {
316
+ os: "linux",
317
+ supportedEngines: ["unity", "godot", "nice2dev"],
318
+ supportedPlatforms: ["linux", "webgl", "web", "android"],
319
+ cpuCores: 8,
320
+ memoryGB: 32,
321
+ diskGB: 500
322
+ },
323
+ autoScaling: true,
324
+ scaleUpThreshold: 5,
325
+ scaleDownThreshold: 3e5,
326
+ // 5 minutes
327
+ useSpotInstances: true,
328
+ spotPercentage: 50
329
+ },
330
+ {
331
+ name: "windows-pool",
332
+ minAgents: 2,
333
+ maxAgents: 20,
334
+ agentTemplate: {
335
+ os: "windows",
336
+ supportedEngines: ["unity", "godot", "unreal", "nice2dev"],
337
+ supportedPlatforms: ["windows", "android", "uwp"],
338
+ cpuCores: 16,
339
+ memoryGB: 64,
340
+ diskGB: 1e3
341
+ },
342
+ autoScaling: true,
343
+ scaleUpThreshold: 3,
344
+ scaleDownThreshold: 3e5,
345
+ useSpotInstances: true,
346
+ spotPercentage: 30
347
+ },
348
+ {
349
+ name: "macos-pool",
350
+ minAgents: 1,
351
+ maxAgents: 10,
352
+ agentTemplate: {
353
+ os: "macos",
354
+ supportedEngines: ["unity", "godot", "unreal", "nice2dev"],
355
+ supportedPlatforms: ["macos", "ios", "tvos"],
356
+ cpuCores: 8,
357
+ memoryGB: 32,
358
+ diskGB: 500
359
+ },
360
+ autoScaling: true,
361
+ scaleUpThreshold: 2,
362
+ scaleDownThreshold: 6e5,
363
+ // 10 minutes (more expensive)
364
+ useSpotInstances: false,
365
+ spotPercentage: 0
366
+ }
367
+ ];
368
+ for (const pool of defaultPools) {
369
+ this.pools.set(pool.name, pool);
370
+ }
371
+ }
372
+ // ─── Pool Management ───────────────────────────────────
373
+ createPool(config) {
374
+ this.pools.set(config.name, config);
375
+ }
376
+ getPool(name) {
377
+ return this.pools.get(name);
378
+ }
379
+ getPools() {
380
+ return Array.from(this.pools.values());
381
+ }
382
+ deletePool(name) {
383
+ return this.pools.delete(name);
384
+ }
385
+ // ─── Agent Management ──────────────────────────────────
386
+ registerAgent(agent) {
387
+ const fullAgent = {
388
+ ...agent,
389
+ id: this.generateAgentId(),
390
+ lastHeartbeat: Date.now(),
391
+ jobsCompleted: 0,
392
+ jobsFailed: 0,
393
+ avgBuildTime: 0
394
+ };
395
+ this.agents.set(fullAgent.id, fullAgent);
396
+ this.callbacks.onAgentRegistered?.(fullAgent);
397
+ return fullAgent;
398
+ }
399
+ generateAgentId() {
400
+ return `agent-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
401
+ }
402
+ unregisterAgent(agentId) {
403
+ const agent = this.agents.get(agentId);
404
+ if (!agent) {
405
+ return false;
406
+ }
407
+ if (agent.currentJobId) {
408
+ this.callbacks.onAgentLostJob?.(agent, agent.currentJobId);
409
+ }
410
+ this.agents.delete(agentId);
411
+ this.callbacks.onAgentUnregistered?.(agent);
412
+ return true;
413
+ }
414
+ getAgent(agentId) {
415
+ return this.agents.get(agentId);
416
+ }
417
+ getAgents() {
418
+ return Array.from(this.agents.values());
419
+ }
420
+ getAgentsByStatus(status) {
421
+ return Array.from(this.agents.values()).filter((a) => a.status === status);
422
+ }
423
+ getAgentsByOS(os) {
424
+ return Array.from(this.agents.values()).filter((a) => a.os === os);
425
+ }
426
+ getIdleAgents() {
427
+ return this.getAgentsByStatus("idle");
428
+ }
429
+ // ─── Agent Lifecycle ───────────────────────────────────
430
+ heartbeat(agentId) {
431
+ const agent = this.agents.get(agentId);
432
+ if (!agent) {
433
+ return false;
434
+ }
435
+ agent.lastHeartbeat = Date.now();
436
+ if (agent.status === "offline") {
437
+ agent.status = agent.currentJobId ? "busy" : "idle";
438
+ this.callbacks.onAgentOnline?.(agent);
439
+ }
440
+ return true;
441
+ }
442
+ checkAgentHealth() {
443
+ const now = Date.now();
444
+ for (const agent of this.agents.values()) {
445
+ if (now - agent.lastHeartbeat > this.heartbeatTimeout && agent.status !== "offline") {
446
+ agent.status = "offline";
447
+ this.callbacks.onAgentOffline?.(agent);
427
448
  if (agent.currentJobId) {
428
- this.callbacks.onAgentLostJob?.(agent, agent.currentJobId);
449
+ this.callbacks.onAgentLostJob?.(agent, agent.currentJobId);
429
450
  }
430
- this.agents.delete(agentId);
431
- this.callbacks.onAgentUnregistered?.(agent);
432
- return true;
433
- }
434
- getAgent(agentId) {
435
- return this.agents.get(agentId);
436
- }
437
- getAgents() {
438
- return Array.from(this.agents.values());
439
- }
440
- getAgentsByStatus(status) {
441
- return Array.from(this.agents.values()).filter((a) => a.status === status);
442
- }
443
- getAgentsByOS(os) {
444
- return Array.from(this.agents.values()).filter((a) => a.os === os);
445
- }
446
- getIdleAgents() {
447
- return this.getAgentsByStatus('idle');
448
- }
449
- // ─── Agent Lifecycle ───────────────────────────────────
450
- heartbeat(agentId) {
451
- const agent = this.agents.get(agentId);
452
- if (!agent) {
453
- return false;
454
- }
455
- agent.lastHeartbeat = Date.now();
456
- // Update status if was offline
457
- if (agent.status === 'offline') {
458
- agent.status = agent.currentJobId ? 'busy' : 'idle';
459
- this.callbacks.onAgentOnline?.(agent);
460
- }
461
- return true;
462
- }
463
- checkAgentHealth() {
451
+ }
452
+ }
453
+ }
454
+ assignJob(agentId, jobId) {
455
+ const agent = this.agents.get(agentId);
456
+ if (!agent || agent.status !== "idle") {
457
+ return false;
458
+ }
459
+ agent.status = "busy";
460
+ agent.currentJobId = jobId;
461
+ this.callbacks.onAgentBusy?.(agent, jobId);
462
+ return true;
463
+ }
464
+ completeJob(agentId, success, buildTime) {
465
+ const agent = this.agents.get(agentId);
466
+ if (!agent || !agent.currentJobId) {
467
+ return false;
468
+ }
469
+ const jobId = agent.currentJobId;
470
+ agent.currentJobId = void 0;
471
+ agent.status = "idle";
472
+ if (success) {
473
+ agent.jobsCompleted++;
474
+ const totalTime = agent.avgBuildTime * (agent.jobsCompleted - 1) + buildTime;
475
+ agent.avgBuildTime = totalTime / agent.jobsCompleted;
476
+ } else {
477
+ agent.jobsFailed++;
478
+ }
479
+ this.callbacks.onAgentIdle?.(agent, jobId);
480
+ return true;
481
+ }
482
+ // ─── Auto-scaling ──────────────────────────────────────
483
+ evaluateScaling(queueManager) {
484
+ const decisions = [];
485
+ for (const [poolName, pool] of this.pools) {
486
+ if (!pool.autoScaling) {
487
+ continue;
488
+ }
489
+ const poolAgents = Array.from(this.agents.values()).filter(
490
+ (a) => a.os === pool.agentTemplate.os && a.region === (pool.agentTemplate.region ?? "default")
491
+ );
492
+ const idleAgents = poolAgents.filter((a) => a.status === "idle");
493
+ poolAgents.filter((a) => a.status === "busy");
494
+ const queueStats = queueManager.getAllQueueStats();
495
+ const waitingJobs = queueStats.reduce((sum, s) => sum + s.waitingJobs, 0);
496
+ if (waitingJobs >= pool.scaleUpThreshold && poolAgents.length < pool.maxAgents) {
497
+ const toAdd = Math.min(Math.ceil(waitingJobs / 2), pool.maxAgents - poolAgents.length);
498
+ decisions.push({
499
+ pool: poolName,
500
+ action: "scale_up",
501
+ count: toAdd,
502
+ reason: `${waitingJobs} jobs waiting, threshold is ${pool.scaleUpThreshold}`,
503
+ useSpot: pool.useSpotInstances && Math.random() < pool.spotPercentage / 100
504
+ });
505
+ }
506
+ if (idleAgents.length > 0 && poolAgents.length > pool.minAgents) {
464
507
  const now = Date.now();
465
- for (const agent of this.agents.values()) {
466
- if (now - agent.lastHeartbeat > this.heartbeatTimeout && agent.status !== 'offline') {
467
- agent.status = 'offline';
468
- this.callbacks.onAgentOffline?.(agent);
469
- // Handle lost job
470
- if (agent.currentJobId) {
471
- this.callbacks.onAgentLostJob?.(agent, agent.currentJobId);
472
- }
473
- }
474
- }
475
- }
476
- assignJob(agentId, jobId) {
477
- const agent = this.agents.get(agentId);
478
- if (!agent || agent.status !== 'idle') {
479
- return false;
480
- }
481
- agent.status = 'busy';
482
- agent.currentJobId = jobId;
483
- this.callbacks.onAgentBusy?.(agent, jobId);
484
- return true;
485
- }
486
- completeJob(agentId, success, buildTime) {
487
- const agent = this.agents.get(agentId);
488
- if (!agent || !agent.currentJobId) {
489
- return false;
490
- }
491
- const jobId = agent.currentJobId;
492
- agent.currentJobId = undefined;
493
- agent.status = 'idle';
494
- if (success) {
495
- agent.jobsCompleted++;
496
- // Update average build time
497
- const totalTime = agent.avgBuildTime * (agent.jobsCompleted - 1) + buildTime;
498
- agent.avgBuildTime = totalTime / agent.jobsCompleted;
499
- }
500
- else {
501
- agent.jobsFailed++;
502
- }
503
- this.callbacks.onAgentIdle?.(agent, jobId);
504
- return true;
505
- }
506
- // ─── Auto-scaling ──────────────────────────────────────
507
- evaluateScaling(queueManager) {
508
- const decisions = [];
509
- for (const [poolName, pool] of this.pools) {
510
- if (!pool.autoScaling) {
511
- continue;
512
- }
513
- const poolAgents = Array.from(this.agents.values()).filter((a) => a.os === pool.agentTemplate.os && a.region === (pool.agentTemplate.region ?? 'default'));
514
- const idleAgents = poolAgents.filter((a) => a.status === 'idle');
515
- poolAgents.filter((a) => a.status === 'busy');
516
- // Get queue pressure
517
- const queueStats = queueManager.getAllQueueStats();
518
- const waitingJobs = queueStats.reduce((sum, s) => sum + s.waitingJobs, 0);
519
- // Scale up decision
520
- if (waitingJobs >= pool.scaleUpThreshold && poolAgents.length < pool.maxAgents) {
521
- const toAdd = Math.min(Math.ceil(waitingJobs / 2), pool.maxAgents - poolAgents.length);
522
- decisions.push({
523
- pool: poolName,
524
- action: 'scale_up',
525
- count: toAdd,
526
- reason: `${waitingJobs} jobs waiting, threshold is ${pool.scaleUpThreshold}`,
527
- useSpot: pool.useSpotInstances && Math.random() < pool.spotPercentage / 100,
528
- });
529
- }
530
- // Scale down decision
531
- if (idleAgents.length > 0 && poolAgents.length > pool.minAgents) {
532
- // Check idle time
533
- const now = Date.now();
534
- const longIdleAgents = idleAgents.filter((a) => {
535
- // Estimate idle time based on last heartbeat
536
- const idleTime = now - a.lastHeartbeat;
537
- return idleTime > pool.scaleDownThreshold;
538
- });
539
- // Prefer removing spot instances first
540
- const spotAgents = longIdleAgents.filter((a) => a.instanceType === 'spot');
541
- const toRemove = spotAgents.length > 0 ? spotAgents : longIdleAgents;
542
- if (toRemove.length > 0) {
543
- const removeCount = Math.min(toRemove.length, poolAgents.length - pool.minAgents);
544
- decisions.push({
545
- pool: poolName,
546
- action: 'scale_down',
547
- count: removeCount,
548
- reason: `${longIdleAgents.length} agents idle for ${pool.scaleDownThreshold}ms`,
549
- agentIds: toRemove.slice(0, removeCount).map((a) => a.id),
550
- });
551
- }
552
- }
553
- }
554
- return decisions;
555
- }
556
- // ─── Stats ─────────────────────────────────────────────
557
- getPoolStats(poolName) {
558
- const pool = this.pools.get(poolName);
559
- if (!pool) {
560
- return undefined;
561
- }
562
- const poolAgents = Array.from(this.agents.values()).filter((a) => a.os === pool.agentTemplate.os);
563
- return {
564
- poolName,
565
- totalAgents: poolAgents.length,
566
- idleAgents: poolAgents.filter((a) => a.status === 'idle').length,
567
- busyAgents: poolAgents.filter((a) => a.status === 'busy').length,
568
- offlineAgents: poolAgents.filter((a) => a.status === 'offline').length,
569
- spotAgents: poolAgents.filter((a) => a.instanceType === 'spot').length,
570
- dedicatedAgents: poolAgents.filter((a) => a.instanceType === 'dedicated').length,
571
- minAgents: pool.minAgents,
572
- maxAgents: pool.maxAgents,
573
- avgBuildTime: this.calculateAvgBuildTime(poolAgents),
574
- totalJobsCompleted: poolAgents.reduce((sum, a) => sum + a.jobsCompleted, 0),
575
- totalJobsFailed: poolAgents.reduce((sum, a) => sum + a.jobsFailed, 0),
576
- };
577
- }
578
- calculateAvgBuildTime(agents) {
579
- const agentsWithJobs = agents.filter((a) => a.jobsCompleted > 0);
580
- if (agentsWithJobs.length === 0) {
581
- return 0;
508
+ const longIdleAgents = idleAgents.filter((a) => {
509
+ const idleTime = now - a.lastHeartbeat;
510
+ return idleTime > pool.scaleDownThreshold;
511
+ });
512
+ const spotAgents = longIdleAgents.filter((a) => a.instanceType === "spot");
513
+ const toRemove = spotAgents.length > 0 ? spotAgents : longIdleAgents;
514
+ if (toRemove.length > 0) {
515
+ const removeCount = Math.min(toRemove.length, poolAgents.length - pool.minAgents);
516
+ decisions.push({
517
+ pool: poolName,
518
+ action: "scale_down",
519
+ count: removeCount,
520
+ reason: `${longIdleAgents.length} agents idle for ${pool.scaleDownThreshold}ms`,
521
+ agentIds: toRemove.slice(0, removeCount).map((a) => a.id)
522
+ });
582
523
  }
583
- const totalWeightedTime = agentsWithJobs.reduce((sum, a) => sum + a.avgBuildTime * a.jobsCompleted, 0);
584
- const totalJobs = agentsWithJobs.reduce((sum, a) => sum + a.jobsCompleted, 0);
585
- return totalWeightedTime / totalJobs;
586
- }
587
- getAllPoolStats() {
588
- return Array.from(this.pools.keys())
589
- .map((name) => this.getPoolStats(name))
590
- .filter(Boolean);
591
- }
592
- // ─── Callbacks ─────────────────────────────────────────
593
- setCallbacks(callbacks) {
594
- this.callbacks = { ...this.callbacks, ...callbacks };
595
- }
524
+ }
525
+ }
526
+ return decisions;
527
+ }
528
+ // ─── Stats ─────────────────────────────────────────────
529
+ getPoolStats(poolName) {
530
+ const pool = this.pools.get(poolName);
531
+ if (!pool) {
532
+ return void 0;
533
+ }
534
+ const poolAgents = Array.from(this.agents.values()).filter(
535
+ (a) => a.os === pool.agentTemplate.os
536
+ );
537
+ return {
538
+ poolName,
539
+ totalAgents: poolAgents.length,
540
+ idleAgents: poolAgents.filter((a) => a.status === "idle").length,
541
+ busyAgents: poolAgents.filter((a) => a.status === "busy").length,
542
+ offlineAgents: poolAgents.filter((a) => a.status === "offline").length,
543
+ spotAgents: poolAgents.filter((a) => a.instanceType === "spot").length,
544
+ dedicatedAgents: poolAgents.filter((a) => a.instanceType === "dedicated").length,
545
+ minAgents: pool.minAgents,
546
+ maxAgents: pool.maxAgents,
547
+ avgBuildTime: this.calculateAvgBuildTime(poolAgents),
548
+ totalJobsCompleted: poolAgents.reduce((sum, a) => sum + a.jobsCompleted, 0),
549
+ totalJobsFailed: poolAgents.reduce((sum, a) => sum + a.jobsFailed, 0)
550
+ };
551
+ }
552
+ calculateAvgBuildTime(agents) {
553
+ const agentsWithJobs = agents.filter((a) => a.jobsCompleted > 0);
554
+ if (agentsWithJobs.length === 0) {
555
+ return 0;
556
+ }
557
+ const totalWeightedTime = agentsWithJobs.reduce(
558
+ (sum, a) => sum + a.avgBuildTime * a.jobsCompleted,
559
+ 0
560
+ );
561
+ const totalJobs = agentsWithJobs.reduce((sum, a) => sum + a.jobsCompleted, 0);
562
+ return totalWeightedTime / totalJobs;
563
+ }
564
+ getAllPoolStats() {
565
+ return Array.from(this.pools.keys()).map((name) => this.getPoolStats(name)).filter(Boolean);
566
+ }
567
+ // ─── Callbacks ─────────────────────────────────────────
568
+ setCallbacks(callbacks) {
569
+ this.callbacks = { ...this.callbacks, ...callbacks };
570
+ }
596
571
  }
597
572
  class ArtifactStorage {
598
- constructor(config) {
599
- this.artifacts = new Map();
600
- this.config = config;
601
- }
602
- async uploadArtifact(jobId, name, data, options) {
603
- const artifactId = this.generateArtifactId();
604
- const path = `${jobId}/${artifactId}/${name}`;
605
- // Calculate size and checksum
606
- const size = typeof data === 'string' ? data.length : data instanceof Blob ? data.size : data.byteLength;
607
- const checksum = await this.calculateChecksum(data);
608
- // Check size limit
609
- if (size > this.config.maxArtifactSize) {
610
- throw new Error(`Artifact size ${size} exceeds limit ${this.config.maxArtifactSize}`);
611
- }
612
- const retentionDays = options?.retentionDays ?? this.config.retentionDays;
613
- const expiresAt = Date.now() + retentionDays * 24 * 60 * 60 * 1000;
614
- const artifact = {
615
- id: artifactId,
616
- jobId,
617
- name,
618
- path,
619
- size,
620
- checksum,
621
- contentType: options?.contentType ?? 'application/octet-stream',
622
- uploadedAt: Date.now(),
623
- expiresAt,
624
- metadata: options?.metadata ?? {},
625
- };
626
- // Generate download URL
627
- if (this.config.signedUrls) {
628
- artifact.downloadUrl = await this.generateSignedUrl(path);
629
- }
630
- else if (this.config.cdnUrl) {
631
- artifact.downloadUrl = `${this.config.cdnUrl}/${path}`;
632
- }
633
- // In production, this would upload to the actual storage
634
- this.artifacts.set(artifactId, artifact);
635
- return artifact;
636
- }
637
- generateArtifactId() {
638
- return `art-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
639
- }
640
- async calculateChecksum(data) {
641
- // Simplified checksum - in production use SHA-256
642
- let input;
643
- if (typeof data === 'string') {
644
- input = new TextEncoder().encode(data).buffer;
645
- }
646
- else if (data instanceof Blob) {
647
- input = await data.arrayBuffer();
648
- }
649
- else {
650
- input = data;
651
- }
652
- const bytes = new Uint8Array(input);
653
- let hash = 0;
654
- for (let i = 0; i < bytes.length; i++) {
655
- hash = ((hash << 5) - hash + bytes[i]) | 0;
656
- }
657
- return Math.abs(hash).toString(16).padStart(8, '0');
658
- }
659
- async generateSignedUrl(path) {
660
- const expiration = Math.floor(Date.now() / 1000) + this.config.signedUrlExpiration;
661
- const signature = await this.generateSignature(path, expiration);
662
- const baseUrl = this.config.cdnUrl ?? `${this.config.endpoint}/${this.config.bucket}`;
663
- return `${baseUrl}/${path}?expires=${expiration}&signature=${signature}`;
664
- }
665
- async generateSignature(path, expiration) {
666
- // Simplified signature - in production use HMAC-SHA256
667
- const data = `${path}:${expiration}:${this.config.secretKey ?? 'secret'}`;
668
- let hash = 0;
669
- for (let i = 0; i < data.length; i++) {
670
- hash = ((hash << 5) - hash + data.charCodeAt(i)) | 0;
671
- }
672
- return Math.abs(hash).toString(16);
673
- }
674
- async getArtifact(artifactId) {
675
- return this.artifacts.get(artifactId);
676
- }
677
- async getArtifactsByJob(jobId) {
678
- return Array.from(this.artifacts.values()).filter((a) => a.jobId === jobId);
679
- }
680
- async deleteArtifact(artifactId) {
681
- return this.artifacts.delete(artifactId);
682
- }
683
- async deleteArtifactsByJob(jobId) {
684
- let deleted = 0;
685
- for (const [id, artifact] of this.artifacts) {
686
- if (artifact.jobId === jobId) {
687
- this.artifacts.delete(id);
688
- deleted++;
689
- }
690
- }
691
- return deleted;
692
- }
693
- async cleanupExpiredArtifacts() {
694
- const now = Date.now();
695
- let deleted = 0;
696
- for (const [id, artifact] of this.artifacts) {
697
- if (artifact.expiresAt < now) {
698
- this.artifacts.delete(id);
699
- deleted++;
700
- }
701
- }
702
- return deleted;
703
- }
704
- getStorageStats() {
705
- let totalSize = 0;
706
- let artifactCount = 0;
707
- for (const artifact of this.artifacts.values()) {
708
- totalSize += artifact.size;
709
- artifactCount++;
710
- }
711
- return {
712
- artifactCount,
713
- totalSize,
714
- bucket: this.config.bucket,
715
- region: this.config.region,
716
- };
717
- }
573
+ constructor(config) {
574
+ this.artifacts = /* @__PURE__ */ new Map();
575
+ this.config = config;
576
+ }
577
+ async uploadArtifact(jobId, name, data, options) {
578
+ const artifactId = this.generateArtifactId();
579
+ const path = `${jobId}/${artifactId}/${name}`;
580
+ const size = typeof data === "string" ? data.length : data instanceof Blob ? data.size : data.byteLength;
581
+ const checksum = await this.calculateChecksum(data);
582
+ if (size > this.config.maxArtifactSize) {
583
+ throw new Error(`Artifact size ${size} exceeds limit ${this.config.maxArtifactSize}`);
584
+ }
585
+ const retentionDays = options?.retentionDays ?? this.config.retentionDays;
586
+ const expiresAt = Date.now() + retentionDays * 24 * 60 * 60 * 1e3;
587
+ const artifact = {
588
+ id: artifactId,
589
+ jobId,
590
+ name,
591
+ path,
592
+ size,
593
+ checksum,
594
+ contentType: options?.contentType ?? "application/octet-stream",
595
+ uploadedAt: Date.now(),
596
+ expiresAt,
597
+ metadata: options?.metadata ?? {}
598
+ };
599
+ if (this.config.signedUrls) {
600
+ artifact.downloadUrl = await this.generateSignedUrl(path);
601
+ } else if (this.config.cdnUrl) {
602
+ artifact.downloadUrl = `${this.config.cdnUrl}/${path}`;
603
+ }
604
+ this.artifacts.set(artifactId, artifact);
605
+ return artifact;
606
+ }
607
+ generateArtifactId() {
608
+ return `art-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
609
+ }
610
+ async calculateChecksum(data) {
611
+ let input;
612
+ if (typeof data === "string") {
613
+ input = new TextEncoder().encode(data).buffer;
614
+ } else if (data instanceof Blob) {
615
+ input = await data.arrayBuffer();
616
+ } else {
617
+ input = data;
618
+ }
619
+ const bytes = new Uint8Array(input);
620
+ let hash = 0;
621
+ for (let i = 0; i < bytes.length; i++) {
622
+ hash = (hash << 5) - hash + bytes[i] | 0;
623
+ }
624
+ return Math.abs(hash).toString(16).padStart(8, "0");
625
+ }
626
+ async generateSignedUrl(path) {
627
+ const expiration = Math.floor(Date.now() / 1e3) + this.config.signedUrlExpiration;
628
+ const signature = await this.generateSignature(path, expiration);
629
+ const baseUrl = this.config.cdnUrl ?? `${this.config.endpoint}/${this.config.bucket}`;
630
+ return `${baseUrl}/${path}?expires=${expiration}&signature=${signature}`;
631
+ }
632
+ async generateSignature(path, expiration) {
633
+ const data = `${path}:${expiration}:${this.config.secretKey ?? "secret"}`;
634
+ let hash = 0;
635
+ for (let i = 0; i < data.length; i++) {
636
+ hash = (hash << 5) - hash + data.charCodeAt(i) | 0;
637
+ }
638
+ return Math.abs(hash).toString(16);
639
+ }
640
+ async getArtifact(artifactId) {
641
+ return this.artifacts.get(artifactId);
642
+ }
643
+ async getArtifactsByJob(jobId) {
644
+ return Array.from(this.artifacts.values()).filter((a) => a.jobId === jobId);
645
+ }
646
+ async deleteArtifact(artifactId) {
647
+ return this.artifacts.delete(artifactId);
648
+ }
649
+ async deleteArtifactsByJob(jobId) {
650
+ let deleted = 0;
651
+ for (const [id, artifact] of this.artifacts) {
652
+ if (artifact.jobId === jobId) {
653
+ this.artifacts.delete(id);
654
+ deleted++;
655
+ }
656
+ }
657
+ return deleted;
658
+ }
659
+ async cleanupExpiredArtifacts() {
660
+ const now = Date.now();
661
+ let deleted = 0;
662
+ for (const [id, artifact] of this.artifacts) {
663
+ if (artifact.expiresAt < now) {
664
+ this.artifacts.delete(id);
665
+ deleted++;
666
+ }
667
+ }
668
+ return deleted;
669
+ }
670
+ getStorageStats() {
671
+ let totalSize = 0;
672
+ let artifactCount = 0;
673
+ for (const artifact of this.artifacts.values()) {
674
+ totalSize += artifact.size;
675
+ artifactCount++;
676
+ }
677
+ return {
678
+ artifactCount,
679
+ totalSize,
680
+ bucket: this.config.bucket,
681
+ region: this.config.region
682
+ };
683
+ }
718
684
  }
719
685
  class BuildNotifications {
720
- constructor() {
721
- this.configs = new Map();
722
- }
723
- addConfig(name, config) {
724
- this.configs.set(name, config);
725
- }
726
- removeConfig(name) {
727
- return this.configs.delete(name);
728
- }
729
- getConfig(name) {
730
- return this.configs.get(name);
731
- }
732
- async notify(payload) {
733
- const results = [];
734
- for (const [name, config] of this.configs) {
735
- if (!config.enabled) {
736
- continue;
737
- }
738
- if (!config.events.includes(payload.event)) {
739
- continue;
740
- }
741
- try {
742
- await this.sendNotification(config, payload);
743
- results.push({ name, success: true });
744
- }
745
- catch (error) {
746
- results.push({
747
- name,
748
- success: false,
749
- error: error instanceof Error ? error.message : 'Unknown error',
750
- });
751
- }
686
+ constructor() {
687
+ this.configs = /* @__PURE__ */ new Map();
688
+ }
689
+ addConfig(name, config) {
690
+ this.configs.set(name, config);
691
+ }
692
+ removeConfig(name) {
693
+ return this.configs.delete(name);
694
+ }
695
+ getConfig(name) {
696
+ return this.configs.get(name);
697
+ }
698
+ async notify(payload) {
699
+ const results = [];
700
+ for (const [name, config] of this.configs) {
701
+ if (!config.enabled) {
702
+ continue;
703
+ }
704
+ if (!config.events.includes(payload.event)) {
705
+ continue;
706
+ }
707
+ try {
708
+ await this.sendNotification(config, payload);
709
+ results.push({ name, success: true });
710
+ } catch (error) {
711
+ results.push({
712
+ name,
713
+ success: false,
714
+ error: error instanceof Error ? error.message : "Unknown error"
715
+ });
716
+ }
717
+ }
718
+ return results;
719
+ }
720
+ async sendNotification(config, payload) {
721
+ switch (config.type) {
722
+ case "webhook":
723
+ await this.sendWebhook(config.webhookUrl, payload);
724
+ break;
725
+ case "slack":
726
+ await this.sendSlack(config.slack, payload);
727
+ break;
728
+ case "discord":
729
+ await this.sendDiscord(config.discord, payload);
730
+ break;
731
+ case "github":
732
+ await this.sendGitHubStatus(config.github, payload);
733
+ break;
734
+ case "gitlab":
735
+ await this.sendGitLabStatus(config.gitlab, payload);
736
+ break;
737
+ case "email":
738
+ console.log(`Would send email to: ${config.emails?.join(", ")}`);
739
+ break;
740
+ }
741
+ }
742
+ async sendWebhook(url, payload) {
743
+ console.log(`Webhook to ${url}:`, JSON.stringify(payload));
744
+ }
745
+ async sendSlack(config, payload) {
746
+ const color = this.getStatusColor(payload.job.status);
747
+ const slackPayload = {
748
+ channel: config.channel,
749
+ username: config.username ?? "Nice2Dev Build",
750
+ icon_emoji: config.iconEmoji ?? ":hammer:",
751
+ attachments: [
752
+ {
753
+ color,
754
+ title: `Build ${payload.event.replace("_", " ").toUpperCase()}`,
755
+ text: payload.message,
756
+ fields: [
757
+ { title: "Job ID", value: payload.job.id, short: true },
758
+ { title: "Engine", value: payload.job.engine, short: true },
759
+ { title: "Platform", value: payload.job.platform, short: true },
760
+ { title: "Status", value: payload.job.status, short: true }
761
+ ],
762
+ footer: "Nice2Dev Build Cloud",
763
+ ts: Math.floor(payload.timestamp / 1e3)
752
764
  }
753
- return results;
754
- }
755
- async sendNotification(config, payload) {
756
- switch (config.type) {
757
- case 'webhook':
758
- await this.sendWebhook(config.webhookUrl, payload);
759
- break;
760
- case 'slack':
761
- await this.sendSlack(config.slack, payload);
762
- break;
763
- case 'discord':
764
- await this.sendDiscord(config.discord, payload);
765
- break;
766
- case 'github':
767
- await this.sendGitHubStatus(config.github, payload);
768
- break;
769
- case 'gitlab':
770
- await this.sendGitLabStatus(config.gitlab, payload);
771
- break;
772
- case 'email':
773
- // Email would require SMTP configuration
774
- console.log(`Would send email to: ${config.emails?.join(', ')}`);
775
- break;
765
+ ]
766
+ };
767
+ console.log(`Slack webhook:`, JSON.stringify(slackPayload));
768
+ }
769
+ async sendDiscord(config, payload) {
770
+ const color = this.getStatusColorInt(payload.job.status);
771
+ const discordPayload = {
772
+ username: config.username ?? "Nice2Dev Build",
773
+ avatar_url: config.avatarUrl,
774
+ embeds: [
775
+ {
776
+ title: `Build ${payload.event.replace("_", " ").toUpperCase()}`,
777
+ description: payload.message,
778
+ color,
779
+ fields: [
780
+ { name: "Job ID", value: payload.job.id, inline: true },
781
+ { name: "Engine", value: payload.job.engine, inline: true },
782
+ { name: "Platform", value: payload.job.platform, inline: true },
783
+ { name: "Status", value: payload.job.status, inline: true }
784
+ ],
785
+ footer: { text: "Nice2Dev Build Cloud" },
786
+ timestamp: new Date(payload.timestamp).toISOString()
776
787
  }
777
- }
778
- async sendWebhook(url, payload) {
779
- // In production, use fetch
780
- console.log(`Webhook to ${url}:`, JSON.stringify(payload));
781
- }
782
- async sendSlack(config, payload) {
783
- const color = this.getStatusColor(payload.job.status);
784
- const slackPayload = {
785
- channel: config.channel,
786
- username: config.username ?? 'Nice2Dev Build',
787
- icon_emoji: config.iconEmoji ?? ':hammer:',
788
- attachments: [
789
- {
790
- color,
791
- title: `Build ${payload.event.replace('_', ' ').toUpperCase()}`,
792
- text: payload.message,
793
- fields: [
794
- { title: 'Job ID', value: payload.job.id, short: true },
795
- { title: 'Engine', value: payload.job.engine, short: true },
796
- { title: 'Platform', value: payload.job.platform, short: true },
797
- { title: 'Status', value: payload.job.status, short: true },
798
- ],
799
- footer: 'Nice2Dev Build Cloud',
800
- ts: Math.floor(payload.timestamp / 1000),
801
- },
802
- ],
803
- };
804
- console.log(`Slack webhook:`, JSON.stringify(slackPayload));
805
- }
806
- async sendDiscord(config, payload) {
807
- const color = this.getStatusColorInt(payload.job.status);
808
- const discordPayload = {
809
- username: config.username ?? 'Nice2Dev Build',
810
- avatar_url: config.avatarUrl,
811
- embeds: [
812
- {
813
- title: `Build ${payload.event.replace('_', ' ').toUpperCase()}`,
814
- description: payload.message,
815
- color,
816
- fields: [
817
- { name: 'Job ID', value: payload.job.id, inline: true },
818
- { name: 'Engine', value: payload.job.engine, inline: true },
819
- { name: 'Platform', value: payload.job.platform, inline: true },
820
- { name: 'Status', value: payload.job.status, inline: true },
821
- ],
822
- footer: { text: 'Nice2Dev Build Cloud' },
823
- timestamp: new Date(payload.timestamp).toISOString(),
824
- },
825
- ],
826
- };
827
- console.log(`Discord webhook:`, JSON.stringify(discordPayload));
828
- }
829
- async sendGitHubStatus(config, payload) {
830
- const state = this.getGitHubState(payload.job.status);
831
- const statusPayload = {
832
- state,
833
- target_url: payload.artifactUrl,
834
- description: payload.message.slice(0, 140),
835
- context: `Nice2Dev/${payload.job.engine}/${payload.job.platform}`,
836
- };
837
- console.log(`GitHub status for ${config.owner}/${config.repo}:`, JSON.stringify(statusPayload));
838
- }
839
- async sendGitLabStatus(config, payload) {
840
- const state = this.getGitLabState(payload.job.status);
841
- const statusPayload = {
842
- state,
843
- target_url: payload.artifactUrl,
844
- description: payload.message.slice(0, 255),
845
- name: `Nice2Dev/${payload.job.engine}/${payload.job.platform}`,
846
- };
847
- console.log(`GitLab status for project ${config.projectId}:`, JSON.stringify(statusPayload));
848
- }
849
- getStatusColor(status) {
850
- const colors = {
851
- completed: '#36a64f',
852
- failed: '#d00000',
853
- cancelled: '#808080',
854
- running: '#2196f3',
855
- queued: '#ffc107',
856
- };
857
- return colors[status] ?? '#808080';
858
- }
859
- getStatusColorInt(status) {
860
- const colors = {
861
- completed: 0x36a64f,
862
- failed: 0xd00000,
863
- cancelled: 0x808080,
864
- running: 0x2196f3,
865
- queued: 0xffc107,
866
- };
867
- return colors[status] ?? 0x808080;
868
- }
869
- getGitHubState(status) {
870
- const states = {
871
- completed: 'success',
872
- failed: 'failure',
873
- cancelled: 'error',
874
- running: 'pending',
875
- queued: 'pending',
876
- };
877
- return states[status] ?? 'pending';
878
- }
879
- getGitLabState(status) {
880
- const states = {
881
- completed: 'success',
882
- failed: 'failed',
883
- cancelled: 'canceled',
884
- running: 'running',
885
- queued: 'pending',
886
- };
887
- return states[status] ?? 'pending';
888
- }
788
+ ]
789
+ };
790
+ console.log(`Discord webhook:`, JSON.stringify(discordPayload));
791
+ }
792
+ async sendGitHubStatus(config, payload) {
793
+ const state = this.getGitHubState(payload.job.status);
794
+ const statusPayload = {
795
+ state,
796
+ target_url: payload.artifactUrl,
797
+ description: payload.message.slice(0, 140),
798
+ context: `Nice2Dev/${payload.job.engine}/${payload.job.platform}`
799
+ };
800
+ console.log(`GitHub status for ${config.owner}/${config.repo}:`, JSON.stringify(statusPayload));
801
+ }
802
+ async sendGitLabStatus(config, payload) {
803
+ const state = this.getGitLabState(payload.job.status);
804
+ const statusPayload = {
805
+ state,
806
+ target_url: payload.artifactUrl,
807
+ description: payload.message.slice(0, 255),
808
+ name: `Nice2Dev/${payload.job.engine}/${payload.job.platform}`
809
+ };
810
+ console.log(`GitLab status for project ${config.projectId}:`, JSON.stringify(statusPayload));
811
+ }
812
+ getStatusColor(status) {
813
+ const colors = {
814
+ completed: "#36a64f",
815
+ failed: "#d00000",
816
+ cancelled: "#808080",
817
+ running: "#2196f3",
818
+ queued: "#ffc107"
819
+ };
820
+ return colors[status] ?? "#808080";
821
+ }
822
+ getStatusColorInt(status) {
823
+ const colors = {
824
+ completed: 3581519,
825
+ failed: 13631488,
826
+ cancelled: 8421504,
827
+ running: 2201331,
828
+ queued: 16761095
829
+ };
830
+ return colors[status] ?? 8421504;
831
+ }
832
+ getGitHubState(status) {
833
+ const states = {
834
+ completed: "success",
835
+ failed: "failure",
836
+ cancelled: "error",
837
+ running: "pending",
838
+ queued: "pending"
839
+ };
840
+ return states[status] ?? "pending";
841
+ }
842
+ getGitLabState(status) {
843
+ const states = {
844
+ completed: "success",
845
+ failed: "failed",
846
+ cancelled: "canceled",
847
+ running: "running",
848
+ queued: "pending"
849
+ };
850
+ return states[status] ?? "pending";
851
+ }
889
852
  }
890
853
  class BuildAnalytics {
891
- constructor() {
892
- this.buildHistory = [];
893
- this.data = this.createEmptyData();
894
- }
895
- createEmptyData() {
896
- return {
897
- totalBuilds: 0,
898
- successfulBuilds: 0,
899
- failedBuilds: 0,
900
- cancelledBuilds: 0,
901
- successRate: 0,
902
- avgBuildTime: 0,
903
- avgWaitTime: 0,
904
- totalBuildTime: 0,
905
- buildsByEngine: { unity: 0, godot: 0, unreal: 0, nice2dev: 0 },
906
- buildsByPlatform: {},
907
- buildsByDay: {},
908
- peakConcurrentBuilds: 0,
909
- estimatedCost: 0,
910
- };
911
- }
912
- recordBuild(jobId, engine, platform, status, waitTime, buildTime) {
913
- const timestamp = Date.now();
914
- const day = new Date(timestamp).toISOString().slice(0, 10);
915
- this.buildHistory.push({
916
- jobId,
917
- engine,
918
- platform,
919
- status,
920
- waitTime,
921
- buildTime,
922
- timestamp,
923
- });
924
- // Update counters
925
- this.data.totalBuilds++;
926
- if (status === 'completed') {
927
- this.data.successfulBuilds++;
928
- }
929
- else if (status === 'failed') {
930
- this.data.failedBuilds++;
931
- }
932
- else if (status === 'cancelled') {
933
- this.data.cancelledBuilds++;
934
- }
935
- // Update rates
936
- this.data.successRate = this.data.successfulBuilds / this.data.totalBuilds;
937
- // Update times
938
- this.data.totalBuildTime += buildTime;
939
- this.data.avgBuildTime = this.data.totalBuildTime / this.data.totalBuilds;
940
- const totalWaitTime = this.buildHistory.reduce((sum, b) => sum + b.waitTime, 0);
941
- this.data.avgWaitTime = totalWaitTime / this.buildHistory.length;
942
- // Update by engine
943
- this.data.buildsByEngine[engine]++;
944
- // Update by platform
945
- this.data.buildsByPlatform[platform] = (this.data.buildsByPlatform[platform] ?? 0) + 1;
946
- // Update by day
947
- this.data.buildsByDay[day] = (this.data.buildsByDay[day] ?? 0) + 1;
948
- // Update cost estimate (rough: $0.01 per minute)
949
- this.data.estimatedCost += (buildTime / 60000) * 0.01;
950
- }
951
- updateConcurrentBuilds(count) {
952
- if (count > this.data.peakConcurrentBuilds) {
953
- this.data.peakConcurrentBuilds = count;
954
- }
955
- }
956
- getData() {
957
- return { ...this.data };
958
- }
959
- getDataForPeriod(startDate, endDate) {
960
- const startTs = startDate.getTime();
961
- const endTs = endDate.getTime();
962
- const filteredBuilds = this.buildHistory.filter((b) => b.timestamp >= startTs && b.timestamp <= endTs);
963
- const data = this.createEmptyData();
964
- for (const build of filteredBuilds) {
965
- const day = new Date(build.timestamp).toISOString().slice(0, 10);
966
- data.totalBuilds++;
967
- if (build.status === 'completed') {
968
- data.successfulBuilds++;
969
- }
970
- else if (build.status === 'failed') {
971
- data.failedBuilds++;
972
- }
973
- else if (build.status === 'cancelled') {
974
- data.cancelledBuilds++;
975
- }
976
- data.totalBuildTime += build.buildTime;
977
- data.buildsByEngine[build.engine]++;
978
- data.buildsByPlatform[build.platform] = (data.buildsByPlatform[build.platform] ?? 0) + 1;
979
- data.buildsByDay[day] = (data.buildsByDay[day] ?? 0) + 1;
980
- data.estimatedCost += (build.buildTime / 60000) * 0.01;
981
- }
982
- if (data.totalBuilds > 0) {
983
- data.successRate = data.successfulBuilds / data.totalBuilds;
984
- data.avgBuildTime = data.totalBuildTime / data.totalBuilds;
985
- data.avgWaitTime =
986
- filteredBuilds.reduce((sum, b) => sum + b.waitTime, 0) / filteredBuilds.length;
987
- }
988
- return data;
989
- }
990
- getTopPlatforms(limit = 5) {
991
- return Object.entries(this.data.buildsByPlatform)
992
- .sort((a, b) => b[1] - a[1])
993
- .slice(0, limit)
994
- .map(([platform, count]) => ({ platform, count }));
995
- }
996
- getRecentBuilds(limit = 10) {
997
- return this.buildHistory.slice(-limit).reverse();
998
- }
999
- clearHistory() {
1000
- this.buildHistory = [];
1001
- this.data = this.createEmptyData();
1002
- }
854
+ constructor() {
855
+ this.buildHistory = [];
856
+ this.data = this.createEmptyData();
857
+ }
858
+ createEmptyData() {
859
+ return {
860
+ totalBuilds: 0,
861
+ successfulBuilds: 0,
862
+ failedBuilds: 0,
863
+ cancelledBuilds: 0,
864
+ successRate: 0,
865
+ avgBuildTime: 0,
866
+ avgWaitTime: 0,
867
+ totalBuildTime: 0,
868
+ buildsByEngine: { unity: 0, godot: 0, unreal: 0, nice2dev: 0 },
869
+ buildsByPlatform: {},
870
+ buildsByDay: {},
871
+ peakConcurrentBuilds: 0,
872
+ estimatedCost: 0
873
+ };
874
+ }
875
+ recordBuild(jobId, engine, platform, status, waitTime, buildTime) {
876
+ const timestamp = Date.now();
877
+ const day = new Date(timestamp).toISOString().slice(0, 10);
878
+ this.buildHistory.push({
879
+ jobId,
880
+ engine,
881
+ platform,
882
+ status,
883
+ waitTime,
884
+ buildTime,
885
+ timestamp
886
+ });
887
+ this.data.totalBuilds++;
888
+ if (status === "completed") {
889
+ this.data.successfulBuilds++;
890
+ } else if (status === "failed") {
891
+ this.data.failedBuilds++;
892
+ } else if (status === "cancelled") {
893
+ this.data.cancelledBuilds++;
894
+ }
895
+ this.data.successRate = this.data.successfulBuilds / this.data.totalBuilds;
896
+ this.data.totalBuildTime += buildTime;
897
+ this.data.avgBuildTime = this.data.totalBuildTime / this.data.totalBuilds;
898
+ const totalWaitTime = this.buildHistory.reduce((sum, b) => sum + b.waitTime, 0);
899
+ this.data.avgWaitTime = totalWaitTime / this.buildHistory.length;
900
+ this.data.buildsByEngine[engine]++;
901
+ this.data.buildsByPlatform[platform] = (this.data.buildsByPlatform[platform] ?? 0) + 1;
902
+ this.data.buildsByDay[day] = (this.data.buildsByDay[day] ?? 0) + 1;
903
+ this.data.estimatedCost += buildTime / 6e4 * 0.01;
904
+ }
905
+ updateConcurrentBuilds(count) {
906
+ if (count > this.data.peakConcurrentBuilds) {
907
+ this.data.peakConcurrentBuilds = count;
908
+ }
909
+ }
910
+ getData() {
911
+ return { ...this.data };
912
+ }
913
+ getDataForPeriod(startDate, endDate) {
914
+ const startTs = startDate.getTime();
915
+ const endTs = endDate.getTime();
916
+ const filteredBuilds = this.buildHistory.filter(
917
+ (b) => b.timestamp >= startTs && b.timestamp <= endTs
918
+ );
919
+ const data = this.createEmptyData();
920
+ for (const build of filteredBuilds) {
921
+ const day = new Date(build.timestamp).toISOString().slice(0, 10);
922
+ data.totalBuilds++;
923
+ if (build.status === "completed") {
924
+ data.successfulBuilds++;
925
+ } else if (build.status === "failed") {
926
+ data.failedBuilds++;
927
+ } else if (build.status === "cancelled") {
928
+ data.cancelledBuilds++;
929
+ }
930
+ data.totalBuildTime += build.buildTime;
931
+ data.buildsByEngine[build.engine]++;
932
+ data.buildsByPlatform[build.platform] = (data.buildsByPlatform[build.platform] ?? 0) + 1;
933
+ data.buildsByDay[day] = (data.buildsByDay[day] ?? 0) + 1;
934
+ data.estimatedCost += build.buildTime / 6e4 * 0.01;
935
+ }
936
+ if (data.totalBuilds > 0) {
937
+ data.successRate = data.successfulBuilds / data.totalBuilds;
938
+ data.avgBuildTime = data.totalBuildTime / data.totalBuilds;
939
+ data.avgWaitTime = filteredBuilds.reduce((sum, b) => sum + b.waitTime, 0) / filteredBuilds.length;
940
+ }
941
+ return data;
942
+ }
943
+ getTopPlatforms(limit = 5) {
944
+ return Object.entries(this.data.buildsByPlatform).sort((a, b) => b[1] - a[1]).slice(0, limit).map(([platform, count]) => ({ platform, count }));
945
+ }
946
+ getRecentBuilds(limit = 10) {
947
+ return this.buildHistory.slice(-limit).reverse();
948
+ }
949
+ clearHistory() {
950
+ this.buildHistory = [];
951
+ this.data = this.createEmptyData();
952
+ }
1003
953
  }
1004
- // ============================================================
1005
- // Factory Functions
1006
- // ============================================================
1007
954
  function createBuildQueueManager() {
1008
- return new BuildQueueManager();
955
+ return new BuildQueueManager();
1009
956
  }
1010
957
  function createBuildAgentPool() {
1011
- return new BuildAgentPool();
958
+ return new BuildAgentPool();
1012
959
  }
1013
960
  function createArtifactStorage(config) {
1014
- return new ArtifactStorage(config);
961
+ return new ArtifactStorage(config);
1015
962
  }
1016
963
  function createBuildNotifications() {
1017
- return new BuildNotifications();
964
+ return new BuildNotifications();
1018
965
  }
1019
966
  function createBuildAnalytics() {
1020
- return new BuildAnalytics();
967
+ return new BuildAnalytics();
1021
968
  }
1022
969
  function createBuildOrchestrator(config) {
1023
- return new BuildOrchestrator(config?.queueManager ?? createBuildQueueManager(), config?.agentPool ?? createBuildAgentPool(), config?.storage ??
1024
- createArtifactStorage({
1025
- type: 'local',
1026
- bucket: 'builds',
1027
- retentionDays: 7,
1028
- maxArtifactSize: 5000000000,
1029
- signedUrls: true,
1030
- signedUrlExpiration: 3600,
1031
- }), config?.notifications ?? createBuildNotifications(), config?.analytics ?? createBuildAnalytics());
970
+ return new BuildOrchestrator(
971
+ config?.queueManager ?? createBuildQueueManager(),
972
+ config?.agentPool ?? createBuildAgentPool(),
973
+ config?.storage ?? createArtifactStorage({
974
+ type: "local",
975
+ bucket: "builds",
976
+ retentionDays: 7,
977
+ maxArtifactSize: 5e9,
978
+ signedUrls: true,
979
+ signedUrlExpiration: 3600
980
+ }),
981
+ config?.notifications ?? createBuildNotifications(),
982
+ config?.analytics ?? createBuildAnalytics()
983
+ );
1032
984
  }
1033
- // ============================================================
1034
- // Build Orchestrator (combines all components)
1035
- // ============================================================
1036
985
  class BuildOrchestrator {
1037
- constructor(queueManager, agentPool, storage, notifications, analytics) {
1038
- this.queueManager = queueManager;
1039
- this.agentPool = agentPool;
1040
- this.storage = storage;
1041
- this.notifications = notifications;
1042
- this.analytics = analytics;
1043
- this.setupCallbacks();
1044
- }
1045
- setupCallbacks() {
1046
- // Wire up queue callbacks
1047
- this.queueManager.setCallbacks({
1048
- onJobQueued: (job) => {
1049
- this.notifications.notify({
1050
- event: 'build_queued',
1051
- timestamp: Date.now(),
1052
- job: {
1053
- id: job.id,
1054
- userId: job.userId,
1055
- engine: job.engine,
1056
- platform: job.platform,
1057
- status: job.status,
1058
- },
1059
- message: `Build ${job.id} queued for ${job.engine}/${job.platform}`,
1060
- });
1061
- },
1062
- onJobStarted: (job) => {
1063
- this.notifications.notify({
1064
- event: 'build_started',
1065
- timestamp: Date.now(),
1066
- job: {
1067
- id: job.id,
1068
- userId: job.userId,
1069
- engine: job.engine,
1070
- platform: job.platform,
1071
- status: job.status,
1072
- },
1073
- message: `Build ${job.id} started`,
1074
- });
1075
- this.analytics.updateConcurrentBuilds(this.queueManager.getJobsByStatus('running').length);
1076
- },
1077
- onJobCompleted: (job) => {
1078
- const waitTime = job.startedAt - job.createdAt;
1079
- const buildTime = job.completedAt - job.startedAt;
1080
- this.analytics.recordBuild(job.id, job.engine, job.platform, job.status, waitTime, buildTime);
1081
- this.notifications.notify({
1082
- event: 'build_completed',
1083
- timestamp: Date.now(),
1084
- job: {
1085
- id: job.id,
1086
- userId: job.userId,
1087
- engine: job.engine,
1088
- platform: job.platform,
1089
- status: job.status,
1090
- },
1091
- message: `Build ${job.id} completed successfully`,
1092
- artifactUrl: job.artifacts?.[0]?.downloadUrl,
1093
- });
1094
- },
1095
- onJobFailed: (job, error) => {
1096
- const waitTime = job.startedAt ? job.startedAt - job.createdAt : 0;
1097
- const buildTime = job.completedAt && job.startedAt ? job.completedAt - job.startedAt : 0;
1098
- this.analytics.recordBuild(job.id, job.engine, job.platform, job.status, waitTime, buildTime);
1099
- this.notifications.notify({
1100
- event: 'build_failed',
1101
- timestamp: Date.now(),
1102
- job: {
1103
- id: job.id,
1104
- userId: job.userId,
1105
- engine: job.engine,
1106
- platform: job.platform,
1107
- status: job.status,
1108
- },
1109
- message: `Build ${job.id} failed: ${error}`,
1110
- details: { error },
1111
- });
1112
- },
986
+ constructor(queueManager, agentPool, storage, notifications, analytics) {
987
+ this.queueManager = queueManager;
988
+ this.agentPool = agentPool;
989
+ this.storage = storage;
990
+ this.notifications = notifications;
991
+ this.analytics = analytics;
992
+ this.setupCallbacks();
993
+ }
994
+ setupCallbacks() {
995
+ this.queueManager.setCallbacks({
996
+ onJobQueued: (job) => {
997
+ this.notifications.notify({
998
+ event: "build_queued",
999
+ timestamp: Date.now(),
1000
+ job: {
1001
+ id: job.id,
1002
+ userId: job.userId,
1003
+ engine: job.engine,
1004
+ platform: job.platform,
1005
+ status: job.status
1006
+ },
1007
+ message: `Build ${job.id} queued for ${job.engine}/${job.platform}`
1113
1008
  });
1114
- }
1115
- async submitBuild(engine, platform, buildConfig, options) {
1116
- return this.queueManager.submitJob(engine, platform, buildConfig, options);
1117
- }
1118
- getStats() {
1119
- return {
1120
- queues: this.queueManager.getAllQueueStats(),
1121
- pools: this.agentPool.getAllPoolStats(),
1122
- storage: this.storage.getStorageStats(),
1123
- analytics: this.analytics.getData(),
1124
- };
1125
- }
1009
+ },
1010
+ onJobStarted: (job) => {
1011
+ this.notifications.notify({
1012
+ event: "build_started",
1013
+ timestamp: Date.now(),
1014
+ job: {
1015
+ id: job.id,
1016
+ userId: job.userId,
1017
+ engine: job.engine,
1018
+ platform: job.platform,
1019
+ status: job.status
1020
+ },
1021
+ message: `Build ${job.id} started`
1022
+ });
1023
+ this.analytics.updateConcurrentBuilds(this.queueManager.getJobsByStatus("running").length);
1024
+ },
1025
+ onJobCompleted: (job) => {
1026
+ const waitTime = job.startedAt - job.createdAt;
1027
+ const buildTime = job.completedAt - job.startedAt;
1028
+ this.analytics.recordBuild(
1029
+ job.id,
1030
+ job.engine,
1031
+ job.platform,
1032
+ job.status,
1033
+ waitTime,
1034
+ buildTime
1035
+ );
1036
+ this.notifications.notify({
1037
+ event: "build_completed",
1038
+ timestamp: Date.now(),
1039
+ job: {
1040
+ id: job.id,
1041
+ userId: job.userId,
1042
+ engine: job.engine,
1043
+ platform: job.platform,
1044
+ status: job.status
1045
+ },
1046
+ message: `Build ${job.id} completed successfully`,
1047
+ artifactUrl: job.artifacts?.[0]?.downloadUrl
1048
+ });
1049
+ },
1050
+ onJobFailed: (job, error) => {
1051
+ const waitTime = job.startedAt ? job.startedAt - job.createdAt : 0;
1052
+ const buildTime = job.completedAt && job.startedAt ? job.completedAt - job.startedAt : 0;
1053
+ this.analytics.recordBuild(
1054
+ job.id,
1055
+ job.engine,
1056
+ job.platform,
1057
+ job.status,
1058
+ waitTime,
1059
+ buildTime
1060
+ );
1061
+ this.notifications.notify({
1062
+ event: "build_failed",
1063
+ timestamp: Date.now(),
1064
+ job: {
1065
+ id: job.id,
1066
+ userId: job.userId,
1067
+ engine: job.engine,
1068
+ platform: job.platform,
1069
+ status: job.status
1070
+ },
1071
+ message: `Build ${job.id} failed: ${error}`,
1072
+ details: { error }
1073
+ });
1074
+ }
1075
+ });
1076
+ }
1077
+ async submitBuild(engine, platform, buildConfig, options) {
1078
+ return this.queueManager.submitJob(engine, platform, buildConfig, options);
1079
+ }
1080
+ getStats() {
1081
+ return {
1082
+ queues: this.queueManager.getAllQueueStats(),
1083
+ pools: this.agentPool.getAllPoolStats(),
1084
+ storage: this.storage.getStorageStats(),
1085
+ analytics: this.analytics.getData()
1086
+ };
1087
+ }
1126
1088
  }
1127
-
1128
- export { ArtifactStorage, BuildAgentPool, BuildAnalytics, BuildNotifications, BuildOrchestrator, BuildQueueManager, createArtifactStorage, createBuildAgentPool, createBuildAnalytics, createBuildNotifications, createBuildOrchestrator, createBuildQueueManager };
1089
+ export {
1090
+ ArtifactStorage,
1091
+ BuildAgentPool,
1092
+ BuildAnalytics,
1093
+ BuildNotifications,
1094
+ BuildOrchestrator,
1095
+ BuildQueueManager,
1096
+ createArtifactStorage,
1097
+ createBuildAgentPool,
1098
+ createBuildAnalytics,
1099
+ createBuildNotifications,
1100
+ createBuildOrchestrator,
1101
+ createBuildQueueManager
1102
+ };