@holoscript/core 6.1.3 → 8.0.0

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 (166) hide show
  1. package/dist/{GLTFPipeline-SFIORFJU.js → GLTFPipeline-276GE64O.js} +6 -6
  2. package/dist/{GLTFPipeline-VNNDPONV.cjs → GLTFPipeline-M7WSSJED.cjs} +10 -10
  3. package/dist/HoloScriptRuntime-3URVTKPJ.js +10 -0
  4. package/dist/HoloScriptRuntime-SXEAEU2N.cjs +19 -0
  5. package/dist/{chunk-2B7WVIDZ.js → chunk-23J755AR.js} +4 -4
  6. package/dist/{chunk-HANL7K2Q.cjs → chunk-253GBQZY.cjs} +38 -38
  7. package/dist/{chunk-KQTPCYTG.cjs → chunk-25IQCHTO.cjs} +38 -38
  8. package/dist/{chunk-V73NPPTM.cjs → chunk-3AO425MZ.cjs} +20 -20
  9. package/dist/{chunk-6S6TKNEA.cjs → chunk-3HYYMEXI.cjs} +279 -124
  10. package/dist/{chunk-IHESJZSW.js → chunk-3NFFOWGG.js} +6 -209
  11. package/dist/{chunk-AO4I2Z7M.cjs → chunk-3WZEJHUQ.cjs} +7 -7
  12. package/dist/{chunk-IRWWS72C.cjs → chunk-4V2E7U7Q.cjs} +7 -7
  13. package/dist/{chunk-ER4GATIU.js → chunk-62FBK3B7.js} +6 -6
  14. package/dist/{chunk-L63H3SQ4.cjs → chunk-6DPSFNJB.cjs} +19 -19
  15. package/dist/{chunk-XFXGA5IW.cjs → chunk-73FELZVJ.cjs} +14 -14
  16. package/dist/{chunk-QWNQ523V.cjs → chunk-7CUEMLDZ.cjs} +47 -47
  17. package/dist/{chunk-52ULD552.cjs → chunk-7HIASF7S.cjs} +13 -13
  18. package/dist/{chunk-U4NBQJBY.js → chunk-ANXZFVY2.js} +3 -3
  19. package/dist/{chunk-NHHVLKV3.js → chunk-AYBXB26F.js} +5 -5
  20. package/dist/{chunk-KX76JUQY.js → chunk-B4TFTDG4.js} +3 -3
  21. package/dist/{chunk-OEFY723R.js → chunk-BE4UJCQT.js} +4 -4
  22. package/dist/{chunk-DIL6DDDN.cjs → chunk-C2A5DUMF.cjs} +38 -38
  23. package/dist/{chunk-H3MGK7TX.cjs → chunk-CXFDRBQU.cjs} +10 -10
  24. package/dist/{chunk-4SY77NA4.cjs → chunk-D54CNIAJ.cjs} +2 -2
  25. package/dist/{chunk-22W6NGYN.js → chunk-DAJXW4KX.js} +3 -3
  26. package/dist/{chunk-RUXGBKPS.cjs → chunk-EUDQTK7N.cjs} +15 -222
  27. package/dist/{chunk-SXYLMIGP.js → chunk-F43YAA34.js} +3 -3
  28. package/dist/{chunk-H5DZIHJP.cjs → chunk-FYSPZT4V.cjs} +7 -7
  29. package/dist/{chunk-TK74TR4H.js → chunk-GIOYPNTH.js} +36 -2
  30. package/dist/{chunk-2HLIGOKU.cjs → chunk-GQHQOPXZ.cjs} +36 -2
  31. package/dist/{chunk-BPICAGBV.cjs → chunk-GQT4TYKY.cjs} +35 -35
  32. package/dist/{chunk-QAVXL2IH.js → chunk-GYZE55MO.js} +3 -3
  33. package/dist/{chunk-77V4GTCA.js → chunk-H652NHX5.js} +78 -74
  34. package/dist/{chunk-KHPCJRI3.cjs → chunk-HINXWAOD.cjs} +14 -14
  35. package/dist/{chunk-W6P2GBHH.cjs → chunk-HZSPDCXV.cjs} +3 -3
  36. package/dist/{chunk-EMMC5CSQ.js → chunk-HZTDET3N.js} +4 -4
  37. package/dist/{chunk-5CKA5SXU.js → chunk-IPWSXCCN.js} +4 -4
  38. package/dist/{chunk-GQYKQSTC.cjs → chunk-IUTY5WQ2.cjs} +5 -5
  39. package/dist/{chunk-MSMIFMBL.js → chunk-IVSZDECV.js} +4 -4
  40. package/dist/{chunk-2A7FURVO.js → chunk-IZM5VQZD.js} +4 -4
  41. package/dist/{chunk-33XCOVE3.js → chunk-J6M4FPK5.js} +3 -3
  42. package/dist/{chunk-6KMK2UXT.cjs → chunk-JC5YBPSF.cjs} +5 -5
  43. package/dist/{chunk-W55Z7QIX.js → chunk-JCLBKPMX.js} +3 -3
  44. package/dist/{chunk-MXJ5SS53.cjs → chunk-JJBE3TIH.cjs} +10 -10
  45. package/dist/{chunk-HRODTEEO.js → chunk-JX7YL6ZE.js} +5 -5
  46. package/dist/{chunk-IVIA7K75.cjs → chunk-K4VVR7CN.cjs} +18 -18
  47. package/dist/{chunk-VSK7W3O5.cjs → chunk-KEFNV2WM.cjs} +16 -16
  48. package/dist/{chunk-HZCQO4JM.cjs → chunk-KH4CNH66.cjs} +4 -4
  49. package/dist/{chunk-6FGQNDR4.js → chunk-KJLB4OPV.js} +4 -4
  50. package/dist/{chunk-RMHC2VG7.cjs → chunk-KKP7JKN4.cjs} +6 -2
  51. package/dist/{chunk-OEV5RMZO.cjs → chunk-KQCN6AKJ.cjs} +5 -5
  52. package/dist/{chunk-7AD52FRS.cjs → chunk-KVRSTFNH.cjs} +14 -14
  53. package/dist/{chunk-ZKSS47EV.cjs → chunk-LICPB5HZ.cjs} +13 -13
  54. package/dist/{chunk-S5IFXW6E.js → chunk-MGE5Z4GS.js} +4 -4
  55. package/dist/{chunk-6L4VE27M.js → chunk-NBMHU6SW.js} +4 -4
  56. package/dist/{chunk-QCCBXSCE.js → chunk-NGKREZ36.js} +5 -5
  57. package/dist/{chunk-27MPVJVZ.cjs → chunk-NHWSN2SD.cjs} +21 -21
  58. package/dist/{chunk-XMWZG36H.js → chunk-NV4VMVXU.js} +3 -3
  59. package/dist/{chunk-Y3MWXQSB.cjs → chunk-NXZFOPVD.cjs} +19 -19
  60. package/dist/{chunk-ZUL5AVTX.cjs → chunk-OBIYPYYS.cjs} +5 -5
  61. package/dist/{chunk-ZXBZVXDW.js → chunk-OMXII44L.js} +3 -3
  62. package/dist/{chunk-MJVIRCUV.cjs → chunk-OR4Q2BGL.cjs} +18 -18
  63. package/dist/{chunk-6ASWLXXN.js → chunk-PHVRG4I2.js} +4 -4
  64. package/dist/{chunk-QTPMJRGS.js → chunk-QPSKHBJP.js} +6 -2
  65. package/dist/{chunk-VEXPG4WN.js → chunk-QXH7QDSZ.js} +3 -3
  66. package/dist/chunk-RARB3MBR.js +207 -0
  67. package/dist/{chunk-EOBB6A4B.js → chunk-RVBHAXFG.js} +231 -76
  68. package/dist/{chunk-XXZJEFKW.cjs → chunk-S3MDHNKB.cjs} +5 -5
  69. package/dist/{chunk-4UUKPCY4.js → chunk-S4W6Z2MN.js} +4 -4
  70. package/dist/{chunk-BVLP6D3Q.cjs → chunk-SJBGLS25.cjs} +5 -5
  71. package/dist/chunk-SMIWS6DE.cjs +212 -0
  72. package/dist/{chunk-R3IVNY6P.js → chunk-T2QCTZMO.js} +4 -4
  73. package/dist/{chunk-AIX25INK.cjs → chunk-TVHSPJ4N.cjs} +79 -75
  74. package/dist/{chunk-Z5XMPRNC.cjs → chunk-U44IKGG7.cjs} +30 -30
  75. package/dist/{chunk-OPZ7XDDI.js → chunk-UJXISJBN.js} +3 -3
  76. package/dist/{chunk-FXKTYFYA.js → chunk-UM6C3CGK.js} +4 -4
  77. package/dist/{chunk-LAOCQJ2M.js → chunk-UMABK6SI.js} +4 -4
  78. package/dist/{chunk-GN3KDX4W.js → chunk-V6MKC2FZ.js} +3 -3
  79. package/dist/{chunk-EDPQSGB3.cjs → chunk-W7VDOASB.cjs} +5 -5
  80. package/dist/{chunk-DMXC24WV.js → chunk-WJIHFLMJ.js} +2 -2
  81. package/dist/{chunk-UDMYRFDZ.js → chunk-WRKUDAZJ.js} +3 -3
  82. package/dist/{chunk-GCMWDSBZ.cjs → chunk-XIVIE43A.cjs} +5 -5
  83. package/dist/{chunk-UD3DSHZM.js → chunk-XKTPFXGA.js} +3 -3
  84. package/dist/{chunk-HGVXZDSK.cjs → chunk-XUUVDHIF.cjs} +7 -7
  85. package/dist/{chunk-5N54COB6.cjs → chunk-YN6V7R3L.cjs} +13 -13
  86. package/dist/{chunk-I2O7TW6B.js → chunk-ZBQXLH2L.js} +4 -4
  87. package/dist/{chunk-EOFNVCM6.js → chunk-ZU7NIRT6.js} +11 -11
  88. package/dist/{chunk-P7YIA5LN.js → chunk-ZZEI7MV4.js} +4 -4
  89. package/dist/compiler/agent-inference.cjs +6 -6
  90. package/dist/compiler/agent-inference.js +2 -2
  91. package/dist/compiler/android-xr.cjs +6 -6
  92. package/dist/compiler/android-xr.js +4 -4
  93. package/dist/compiler/android.cjs +5 -5
  94. package/dist/compiler/android.js +3 -3
  95. package/dist/compiler/ar.cjs +5 -5
  96. package/dist/compiler/ar.js +3 -3
  97. package/dist/compiler/babylon.cjs +5 -5
  98. package/dist/compiler/babylon.js +4 -4
  99. package/dist/compiler/business-quest.cjs +9 -9
  100. package/dist/compiler/business-quest.js +1 -1
  101. package/dist/compiler/context.cjs +5 -5
  102. package/dist/compiler/context.js +2 -2
  103. package/dist/compiler/domain-block-utils.cjs +151 -151
  104. package/dist/compiler/domain-block-utils.js +3 -3
  105. package/dist/compiler/dtdl.cjs +6 -6
  106. package/dist/compiler/dtdl.js +3 -3
  107. package/dist/compiler/gltf-pipeline.cjs +8 -8
  108. package/dist/compiler/gltf-pipeline.js +1 -1
  109. package/dist/compiler/godot.cjs +5 -5
  110. package/dist/compiler/godot.js +4 -4
  111. package/dist/compiler/incremental.cjs +7 -7
  112. package/dist/compiler/incremental.js +2 -2
  113. package/dist/compiler/index.cjs +182 -182
  114. package/dist/compiler/index.js +56 -56
  115. package/dist/compiler/ios.cjs +5 -5
  116. package/dist/compiler/ios.js +3 -3
  117. package/dist/compiler/llm-provider-capabilities.cjs +5 -5
  118. package/dist/compiler/llm-provider-capabilities.js +2 -2
  119. package/dist/compiler/multi-layer.cjs +7 -7
  120. package/dist/compiler/multi-layer.js +6 -6
  121. package/dist/compiler/openxr.cjs +5 -5
  122. package/dist/compiler/openxr.js +4 -4
  123. package/dist/compiler/playcanvas.cjs +5 -5
  124. package/dist/compiler/playcanvas.js +4 -4
  125. package/dist/compiler/r3f.cjs +9 -9
  126. package/dist/compiler/r3f.js +4 -4
  127. package/dist/compiler/sdf.cjs +6 -6
  128. package/dist/compiler/sdf.js +4 -4
  129. package/dist/compiler/state.cjs +5 -5
  130. package/dist/compiler/state.js +3 -3
  131. package/dist/compiler/trait-composition.cjs +6 -6
  132. package/dist/compiler/trait-composition.js +2 -2
  133. package/dist/compiler/unity.cjs +5 -5
  134. package/dist/compiler/unity.js +4 -4
  135. package/dist/compiler/unreal.cjs +6 -6
  136. package/dist/compiler/unreal.js +4 -4
  137. package/dist/compiler/urdf.cjs +13 -13
  138. package/dist/compiler/urdf.js +4 -4
  139. package/dist/compiler/usd-physics.cjs +6 -6
  140. package/dist/compiler/usd-physics.js +3 -3
  141. package/dist/compiler/visionos.cjs +5 -5
  142. package/dist/compiler/visionos.js +4 -4
  143. package/dist/compiler/vrchat.cjs +6 -6
  144. package/dist/compiler/vrchat.js +4 -4
  145. package/dist/compiler/vrr.cjs +6 -6
  146. package/dist/compiler/vrr.js +4 -4
  147. package/dist/compiler/wasm.cjs +9 -9
  148. package/dist/compiler/wasm.js +4 -4
  149. package/dist/compiler/webgpu.cjs +5 -5
  150. package/dist/compiler/webgpu.js +4 -4
  151. package/dist/debugger.cjs +7 -6
  152. package/dist/debugger.js +5 -4
  153. package/dist/entries/scripting.cjs +0 -13
  154. package/dist/entries/scripting.js +0 -1
  155. package/dist/index.cjs +1002 -881
  156. package/dist/index.js +506 -87
  157. package/dist/parser.cjs +5 -5
  158. package/dist/parser.js +1 -1
  159. package/dist/reconstruction/index.cjs +31 -31
  160. package/dist/reconstruction/index.js +2 -2
  161. package/dist/runtime.cjs +302 -4
  162. package/dist/runtime.d.ts +61 -0
  163. package/dist/runtime.js +25 -3
  164. package/dist/traits/index.cjs +450 -439
  165. package/dist/traits/index.js +24 -13
  166. package/package.json +20 -20
@@ -4,33 +4,15 @@ import { botanicalLotusHandler } from './chunk-VECQYRXL.js';
4
4
  import { SimulationSolverFactory } from './chunk-YQELFNJV.js';
5
5
  import { createTensor, createNoOpInferenceAdapter, add, matmul } from './chunk-FHP6LXJS.js';
6
6
  import { absorbHandler, hotReloadHandler, scriptTestHandler } from './chunk-2M2DPHKB.js';
7
- import { mitosisHandler, embeddingHandler, jepObjectiveHandler, orbitalHandler } from './chunk-77V4GTCA.js';
7
+ import { mitosisHandler, embeddingHandler, jepObjectiveHandler, orbitalHandler } from './chunk-H652NHX5.js';
8
8
  import { logger } from './chunk-PHENW4MQ.js';
9
9
  import { init_safeJsonParse, readJson } from './chunk-VVKVQZI6.js';
10
10
  import { __require } from './chunk-OL46QLBJ.js';
11
- import { getNavigationEngine } from '@holoscript/engine/runtime/NavigationEngine';
12
- import { getVoiceSynthesizer, voiceSynthesizerRegistry } from '@holoscript/engine/runtime/VoiceSynthesizer';
13
- import { getEmotionDetector } from '@holoscript/engine/runtime/EmotionDetector';
14
- import { getPhysicsEngine } from '@holoscript/engine/runtime/PhysicsEngine';
15
- import { IslandDetector } from '@holoscript/engine/physics/IslandDetector';
16
- import { SoftBodyAdapter } from '@holoscript/engine/physics/SoftBodyAdapter';
17
- import { MLSMPMFluid } from '@holoscript/engine/physics/MLSMPMFluid';
18
- import { weatherBlackboard } from '@holoscript/engine/environment/WeatherBlackboard';
19
- import { SoftBodySolver } from '@holoscript/engine/physics/SoftBodySolver';
20
- import { ChoreographyPlanner, ChoreographyEngine } from '@holoscript/engine/choreography';
21
- import { getNegotiationProtocol, getTrustWeight } from '@holoscript/framework/negotiation';
22
- import { SYNC_TIER_RATES, WebRTCTransport, WebSocketTransport, RaftConsensus, ConsensusManager, SyncProtocol } from '@holoscript/mesh';
23
- import { getDefaultRegistry } from '@holoscript/framework/agents';
24
- import { getMQTTClient, createMQTTClient, registerMQTTClient, MQTTClient } from '@holoscript/engine/runtime/protocols/MQTTClient';
25
- import { BoneSystem } from '@holoscript/engine/animation/BoneSystem';
26
- import { IKSolver } from '@holoscript/engine/animation/IKSolver';
27
- import { AvatarController } from '@holoscript/engine/animation/AvatarController';
28
- import { getDefaultAIAdapter } from '@holoscript/framework/ai';
29
- import { SpringAnimator, SpringPresets } from '@holoscript/engine/animation/SpringAnimator';
30
11
  import { EventEmitter } from 'events';
31
- import { DEFAULT_SPATIAL_CONFIG, SpatialContextProvider } from '@holoscript/engine/spatial';
32
12
  import { jwtVerify, SignJWT } from 'jose';
33
13
 
14
+ // src/traits/FlowFieldTrait.ts
15
+ var _navigationEngine = null;
34
16
  function toTuple(v) {
35
17
  if (Array.isArray(v)) return v;
36
18
  return [v[0] ?? 0, v[1] ?? 0, v[2] ?? 0];
@@ -53,9 +35,11 @@ var flowFieldHandler = {
53
35
  onDetach(node) {
54
36
  delete node.__flowFieldState;
55
37
  },
56
- onUpdate(node, config, context, delta) {
38
+ async onUpdate(node, config, context, delta) {
57
39
  const state = node.__flowFieldState;
58
40
  if (!state || !config.destinationId) return;
41
+ _navigationEngine ?? (_navigationEngine = await import('@holoscript/engine/runtime/NavigationEngine'));
42
+ const { getNavigationEngine } = _navigationEngine;
59
43
  const navEngine = getNavigationEngine("gpu_flowfield") || getNavigationEngine("default");
60
44
  if (!navEngine) return;
61
45
  const currentPos = toTuple(node.properties?.position || [0, 0, 0]);
@@ -964,6 +948,9 @@ var rbacHandler = {
964
948
  }
965
949
  }
966
950
  };
951
+
952
+ // src/traits/EmotionalVoiceTrait.ts
953
+ var _voiceSynthesizer = null;
967
954
  var emotionalVoiceHandler = {
968
955
  name: "emotional_voice",
969
956
  defaultConfig: {
@@ -1001,6 +988,8 @@ var emotionalVoiceHandler = {
1001
988
  }
1002
989
  };
1003
990
  emotionalVoiceHandler.handleSpeak = async function(node, config, state, request) {
991
+ _voiceSynthesizer ?? (_voiceSynthesizer = await import('@holoscript/engine/runtime/VoiceSynthesizer'));
992
+ const { getVoiceSynthesizer, voiceSynthesizerRegistry } = _voiceSynthesizer;
1004
993
  const synthesizer = getVoiceSynthesizer("default") || Array.from(voiceSynthesizerRegistry.values())[0];
1005
994
  if (!synthesizer) {
1006
995
  console.warn("No VoiceSynthesizer registered. Skipping speech for", node.name);
@@ -1031,8 +1020,13 @@ emotionalVoiceHandler.handleSpeak = async function(node, config, state, request)
1031
1020
  request
1032
1021
  });
1033
1022
  };
1023
+
1024
+ // src/traits/UserMonitorTrait.ts
1025
+ var _emotionDetector = null;
1034
1026
  var traitState = /* @__PURE__ */ new WeakMap();
1035
- function performInference(node, config, _context, state) {
1027
+ async function performInference(node, config, _context, state) {
1028
+ _emotionDetector ?? (_emotionDetector = await import('@holoscript/engine/runtime/EmotionDetector'));
1029
+ const { getEmotionDetector } = _emotionDetector;
1036
1030
  const detector = getEmotionDetector("default") || getEmotionDetector("lite");
1037
1031
  if (!detector) return;
1038
1032
  const headStability = calculateStability(state.headPositions);
@@ -1077,7 +1071,7 @@ var userMonitorHandler = {
1077
1071
  traitState.delete(node);
1078
1072
  delete node.__userMonitorState;
1079
1073
  },
1080
- onUpdate(node, config, context, delta) {
1074
+ async onUpdate(node, config, context, delta) {
1081
1075
  const state = traitState.get(node);
1082
1076
  if (!state) return;
1083
1077
  const headPos = context.vr.headset.position;
@@ -1098,7 +1092,7 @@ var userMonitorHandler = {
1098
1092
  state.lastInferenceTime += delta;
1099
1093
  if (state.lastInferenceTime >= (config.updateRate ?? 0.2)) {
1100
1094
  state.lastInferenceTime = 0;
1101
- performInference(node, config, context, state);
1095
+ await performInference(node, config, context, state);
1102
1096
  }
1103
1097
  },
1104
1098
  onEvent(node, config, context, event) {
@@ -7055,6 +7049,11 @@ var gpuParticleHandler = {
7055
7049
  }
7056
7050
  }
7057
7051
  };
7052
+
7053
+ // src/traits/GPUPhysicsTrait.ts
7054
+ var _physicsEngineModule = null;
7055
+ var _islandDetectorModule = null;
7056
+ var _softBodyAdapterModule = null;
7058
7057
  function extractPosition(node) {
7059
7058
  const pos = node?.properties?.position ?? node?.position;
7060
7059
  if (Array.isArray(pos) && pos.length >= 3) {
@@ -7079,8 +7078,12 @@ var gpuPhysicsHandler = {
7079
7078
  restitution: 0.3,
7080
7079
  isStatic: false
7081
7080
  },
7082
- onAttach(node, config, _context) {
7081
+ async onAttach(node, config, _context) {
7082
+ _islandDetectorModule ?? (_islandDetectorModule = await import('@holoscript/engine/physics/IslandDetector'));
7083
+ const { IslandDetector } = _islandDetectorModule;
7083
7084
  if (config.sim_type === "soft_body") {
7085
+ _softBodyAdapterModule ?? (_softBodyAdapterModule = await import('@holoscript/engine/physics/SoftBodyAdapter'));
7086
+ const { SoftBodyAdapter } = _softBodyAdapterModule;
7084
7087
  const softBody = new SoftBodyAdapter(node, config);
7085
7088
  node.__gpuPhysicsState = {
7086
7089
  engineId: "soft_body_solver",
@@ -7091,6 +7094,8 @@ var gpuPhysicsHandler = {
7091
7094
  };
7092
7095
  return;
7093
7096
  }
7097
+ _physicsEngineModule ?? (_physicsEngineModule = await import('@holoscript/engine/runtime/PhysicsEngine'));
7098
+ const { getPhysicsEngine } = _physicsEngineModule;
7094
7099
  const engine = getPhysicsEngine("webgpu") || getPhysicsEngine("default");
7095
7100
  if (!engine) {
7096
7101
  console.warn("No GPU PhysicsEngine found. Physics will be disabled for", node.name);
@@ -7115,23 +7120,27 @@ var gpuPhysicsHandler = {
7115
7120
  restitution: config.restitution
7116
7121
  });
7117
7122
  },
7118
- onDetach(node) {
7123
+ async onDetach(node) {
7119
7124
  const state = node.__gpuPhysicsState;
7120
7125
  if (state) {
7121
7126
  if (state.softBody) ; else {
7127
+ _physicsEngineModule ?? (_physicsEngineModule = await import('@holoscript/engine/runtime/PhysicsEngine'));
7128
+ const { getPhysicsEngine } = _physicsEngineModule;
7122
7129
  const engine = getPhysicsEngine(state.engineId);
7123
7130
  engine?.removeBody(node.name || "");
7124
7131
  }
7125
7132
  delete node.__gpuPhysicsState;
7126
7133
  }
7127
7134
  },
7128
- onUpdate(node, _config, _context, _delta) {
7135
+ async onUpdate(node, _config, _context, _delta) {
7129
7136
  const state = node.__gpuPhysicsState;
7130
7137
  if (!state || !state.isSimulating) return;
7131
7138
  if (state.softBody) {
7132
7139
  state.softBody.update(_delta);
7133
7140
  return;
7134
7141
  }
7142
+ _physicsEngineModule ?? (_physicsEngineModule = await import('@holoscript/engine/runtime/PhysicsEngine'));
7143
+ const { getPhysicsEngine } = _physicsEngineModule;
7135
7144
  const engine = getPhysicsEngine(state.engineId);
7136
7145
  if (!engine) return;
7137
7146
  const states = engine.getStates();
@@ -7141,12 +7150,14 @@ var gpuPhysicsHandler = {
7141
7150
  node.rotation = bodyState.rotation;
7142
7151
  }
7143
7152
  },
7144
- onEvent(node, config, context, event) {
7153
+ async onEvent(node, config, context, event) {
7145
7154
  const state = node.__gpuPhysicsState;
7146
7155
  if (!state) return;
7147
7156
  const eventType = typeof event === "string" ? event : event.type;
7148
7157
  if (eventType === "apply-force") {
7149
7158
  if (state.softBody) ; else {
7159
+ _physicsEngineModule ?? (_physicsEngineModule = await import('@holoscript/engine/runtime/PhysicsEngine'));
7160
+ const { getPhysicsEngine } = _physicsEngineModule;
7150
7161
  const engine = getPhysicsEngine(state.engineId || "webgpu");
7151
7162
  engine?.applyForce(
7152
7163
  node.name || "",
@@ -16771,6 +16782,10 @@ function initializeClothMesh(state, config) {
16771
16782
  }
16772
16783
  }
16773
16784
  }
16785
+
16786
+ // src/traits/FluidTrait.ts
16787
+ var _mlsMpmModule = null;
16788
+ var _weatherModule = null;
16774
16789
  var fluidHandler = {
16775
16790
  name: "fluid",
16776
16791
  defaultConfig: {
@@ -16793,7 +16808,7 @@ var fluidHandler = {
16793
16808
  absorption_color: [0.4, 0.04, 0],
16794
16809
  absorption_strength: 2
16795
16810
  },
16796
- onAttach(node, config, context) {
16811
+ async onAttach(node, config, context) {
16797
16812
  const state = {
16798
16813
  isSimulating: false,
16799
16814
  particleCount: 0,
@@ -16809,6 +16824,8 @@ var fluidHandler = {
16809
16824
  };
16810
16825
  node.__fluidState = state;
16811
16826
  if (config.method === "mls_mpm" && context.gpuDevice) {
16827
+ _mlsMpmModule ?? (_mlsMpmModule = await import('@holoscript/engine/physics/MLSMPMFluid'));
16828
+ const { MLSMPMFluid } = _mlsMpmModule;
16812
16829
  const sim = new MLSMPMFluid({
16813
16830
  type: "liquid",
16814
16831
  particleCount: config.particle_count,
@@ -16857,10 +16874,12 @@ var fluidHandler = {
16857
16874
  }
16858
16875
  delete node.__fluidState;
16859
16876
  },
16860
- onUpdate(node, config, context, delta) {
16877
+ async onUpdate(node, config, context, delta) {
16861
16878
  const state = node.__fluidState;
16862
16879
  if (!state || !state.isSimulating) return;
16863
16880
  if (state.mlsMpm && state.gpuReady) {
16881
+ _weatherModule ?? (_weatherModule = await import('@holoscript/engine/environment/WeatherBlackboard'));
16882
+ const { weatherBlackboard } = _weatherModule;
16864
16883
  if (config.wind_sensitivity > 0 && weatherBlackboard.wind_speed > 0) {
16865
16884
  const s = config.wind_sensitivity;
16866
16885
  const wv = weatherBlackboard.wind_vector;
@@ -16978,6 +16997,9 @@ var fluidHandler = {
16978
16997
  }
16979
16998
  }
16980
16999
  };
17000
+
17001
+ // src/traits/SoftBodyTrait.ts
17002
+ var _softBodySolverModule = null;
16981
17003
  function autoPopulateFromMesh(node, config) {
16982
17004
  const meshData = node.properties?.meshData;
16983
17005
  if (!meshData || !meshData.positions || !meshData.indices) {
@@ -17039,7 +17061,7 @@ var softBodyHandler = {
17039
17061
  surface_stiffness: 0.5,
17040
17062
  bending_stiffness: 0.3
17041
17063
  },
17042
- onAttach(node, config, context) {
17064
+ async onAttach(node, config, context) {
17043
17065
  const state = {
17044
17066
  isSimulating: false,
17045
17067
  isDeformed: false,
@@ -17051,6 +17073,8 @@ var softBodyHandler = {
17051
17073
  solver: null
17052
17074
  };
17053
17075
  node.__softBodyState = state;
17076
+ _softBodySolverModule ?? (_softBodySolverModule = await import('@holoscript/engine/physics/SoftBodySolver'));
17077
+ const { SoftBodySolver } = _softBodySolverModule;
17054
17078
  const { particles, constraints } = autoPopulateFromMesh(node, config);
17055
17079
  state.solver = new SoftBodySolver(particles, constraints);
17056
17080
  state.isSimulating = true;
@@ -18632,6 +18656,9 @@ var layerAwareHandler = {
18632
18656
  onUpdate(node, config, context, _delta) {
18633
18657
  }
18634
18658
  };
18659
+
18660
+ // src/traits/ChoreographyTrait.ts
18661
+ var _choreography = null;
18635
18662
  var DEFAULT_CHOREOGRAPHY_CONFIG = {
18636
18663
  mode: "participant",
18637
18664
  auto_start: true,
@@ -18670,7 +18697,9 @@ function addEvent(state, type, planId, config, stepId) {
18670
18697
  var choreographyHandler = {
18671
18698
  name: "choreography",
18672
18699
  defaultConfig: DEFAULT_CHOREOGRAPHY_CONFIG,
18673
- onAttach(node, config, _context) {
18700
+ async onAttach(node, config, _context) {
18701
+ _choreography ?? (_choreography = await import('@holoscript/engine/choreography'));
18702
+ const { ChoreographyEngine, ChoreographyPlanner } = _choreography;
18674
18703
  const cfg = { ...DEFAULT_CHOREOGRAPHY_CONFIG, ...config };
18675
18704
  const state = createDefaultState();
18676
18705
  state.mode = cfg.mode;
@@ -18729,6 +18758,9 @@ var choreographyHandler = {
18729
18758
  delete n.__choreography_state;
18730
18759
  }
18731
18760
  };
18761
+
18762
+ // src/traits/NegotiationTrait.ts
18763
+ var _negotiationMod = null;
18732
18764
  var DEFAULT_NEGOTIATION_CONFIG = {
18733
18765
  role: "participant",
18734
18766
  default_mechanism: "majority",
@@ -18801,6 +18833,8 @@ async function autoVoteInternal(node, sessionId, config) {
18801
18833
  default:
18802
18834
  return null;
18803
18835
  }
18836
+ _negotiationMod ?? (_negotiationMod = await import('@holoscript/framework/negotiation'));
18837
+ const { getTrustWeight } = _negotiationMod;
18804
18838
  const voteResult = await state.protocol.vote(sessionId, {
18805
18839
  agentId: state.agentId,
18806
18840
  ranking,
@@ -18818,12 +18852,14 @@ async function autoVoteInternal(node, sessionId, config) {
18818
18852
  var negotiationHandler = {
18819
18853
  name: "negotiation",
18820
18854
  defaultConfig: DEFAULT_NEGOTIATION_CONFIG,
18821
- onAttach(node, config, _context) {
18855
+ async onAttach(node, config, _context) {
18822
18856
  const cfg = { ...DEFAULT_NEGOTIATION_CONFIG, ...config };
18823
18857
  const state = createDefaultState2();
18824
18858
  state.role = cfg.role;
18825
18859
  state.agentId = cfg.agent_id || node.id || `agent-${Date.now()}`;
18826
18860
  node.__negotiation_state = state;
18861
+ _negotiationMod ?? (_negotiationMod = await import('@holoscript/framework/negotiation'));
18862
+ const { getNegotiationProtocol } = _negotiationMod;
18827
18863
  state.protocol = getNegotiationProtocol();
18828
18864
  const unsub1 = state.protocol.on("sessionStarted", ({ session }) => {
18829
18865
  if (session.participants.includes(state.agentId)) {
@@ -18911,6 +18947,8 @@ async function vote(node, sessionId, ranking, options) {
18911
18947
  if (state.role === "observer") {
18912
18948
  throw new Error("Observers cannot vote");
18913
18949
  }
18950
+ _negotiationMod ?? (_negotiationMod = await import('@holoscript/framework/negotiation'));
18951
+ const { getTrustWeight } = _negotiationMod;
18914
18952
  const voteResult = await state.protocol.vote(sessionId, {
18915
18953
  agentId: state.agentId,
18916
18954
  ranking,
@@ -19033,9 +19071,14 @@ function getNegotiationMethods(node) {
19033
19071
  leave: (sessionId) => leave(node, sessionId)
19034
19072
  };
19035
19073
  }
19074
+
19075
+ // src/traits/NetworkedTrait.ts
19036
19076
  init_safeJsonParse();
19077
+ var _mesh = null;
19037
19078
  var syncProtocolPool = /* @__PURE__ */ new Map();
19038
- function getOrCreateSyncProtocol(roomId, transport = "local", serverUrl) {
19079
+ async function getOrCreateSyncProtocol(roomId, transport = "local", serverUrl) {
19080
+ _mesh ?? (_mesh = await import('@holoscript/mesh'));
19081
+ const { SyncProtocol } = _mesh;
19039
19082
  const isTestEnv = process.env.NODE_ENV === "test" || !!process.env.VITEST;
19040
19083
  if (isTestEnv) {
19041
19084
  return new SyncProtocol({
@@ -19105,6 +19148,8 @@ var NetworkedTrait = class {
19105
19148
  */
19106
19149
  async connect(transport = "local", serverUrl) {
19107
19150
  const roomId = this.config.room || "default-room";
19151
+ _mesh ?? (_mesh = await import('@holoscript/mesh'));
19152
+ const { WebRTCTransport, WebSocketTransport } = _mesh;
19108
19153
  if (transport === "auto" && serverUrl) {
19109
19154
  try {
19110
19155
  this.rtcTransport = new WebRTCTransport(serverUrl);
@@ -19171,7 +19216,7 @@ var NetworkedTrait = class {
19171
19216
  logger.warn(`[NetworkedTrait] WebRTC connection failed, using local sync: ${error}`);
19172
19217
  }
19173
19218
  }
19174
- this.syncProtocol = getOrCreateSyncProtocol(roomId, "local", serverUrl);
19219
+ this.syncProtocol = await getOrCreateSyncProtocol(roomId, "local", serverUrl);
19175
19220
  this.syncProtocol.on("state-updated", (event) => {
19176
19221
  const data = event.data;
19177
19222
  if (data.entityId === this.entityId && !this.isOwner) {
@@ -19724,6 +19769,9 @@ function createNetworkedTrait(config) {
19724
19769
  ...config
19725
19770
  });
19726
19771
  }
19772
+
19773
+ // src/traits/NetworkedTraitHandler.ts
19774
+ var _mesh2 = null;
19727
19775
  var handlerStates = /* @__PURE__ */ new Map();
19728
19776
  function getNodeKey(node) {
19729
19777
  return node.id || `__anon_${Math.random().toString(36).slice(2, 8)}`;
@@ -19833,11 +19881,13 @@ var networkedHandler = {
19833
19881
  // ===========================================================================
19834
19882
  // onUpdate — per-frame sync
19835
19883
  // ===========================================================================
19836
- onUpdate(node, config, context, delta) {
19884
+ async onUpdate(node, config, context, delta) {
19837
19885
  const key = getNodeKey(node);
19838
19886
  const state = handlerStates.get(key);
19839
19887
  if (!state || !state.registered) return;
19840
19888
  const trait = state.trait;
19889
+ _mesh2 ?? (_mesh2 = await import('@holoscript/mesh'));
19890
+ const { SYNC_TIER_RATES } = _mesh2;
19841
19891
  const baseSyncRate = SYNC_TIER_RATES[config.syncTier] ?? config.syncRate;
19842
19892
  const effectiveRate = baseSyncRate * state.priorityWeight;
19843
19893
  const syncIntervalMs = effectiveRate > 0 ? 1e3 / effectiveRate : Infinity;
@@ -24819,6 +24869,9 @@ function average(values) {
24819
24869
  function round(value) {
24820
24870
  return Math.round(value * 1e6) / 1e6;
24821
24871
  }
24872
+
24873
+ // src/traits/AgentDiscoveryTrait.ts
24874
+ var _frameworkAgents = null;
24822
24875
  function generateAgentId() {
24823
24876
  return `agent_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
24824
24877
  }
@@ -24866,7 +24919,9 @@ var agentDiscoveryHandler = {
24866
24919
  registry_config: null,
24867
24920
  tags: []
24868
24921
  },
24869
- onAttach(node, config, context) {
24922
+ async onAttach(node, config, context) {
24923
+ _frameworkAgents ?? (_frameworkAgents = await import('@holoscript/framework/agents'));
24924
+ const { getDefaultRegistry } = _frameworkAgents;
24870
24925
  const state = {
24871
24926
  registrationStatus: "unregistered",
24872
24927
  manifest: null,
@@ -29576,6 +29631,9 @@ var messagingHandler = {
29576
29631
  });
29577
29632
  }
29578
29633
  };
29634
+
29635
+ // src/traits/MQTTSinkTrait.ts
29636
+ var _mqttClientMod = null;
29579
29637
  var defaultConfig = {
29580
29638
  broker: "mqtt://localhost:1883",
29581
29639
  topic: "holoscript/{nodeId}/state",
@@ -29589,7 +29647,7 @@ var defaultConfig = {
29589
29647
  var mqttSinkHandler = {
29590
29648
  name: "mqtt_sink",
29591
29649
  defaultConfig,
29592
- onAttach(node, config, context) {
29650
+ async onAttach(node, config, context) {
29593
29651
  const state = {
29594
29652
  connected: false,
29595
29653
  publishCount: 0,
@@ -29599,6 +29657,8 @@ var mqttSinkHandler = {
29599
29657
  lastStateHash: null
29600
29658
  };
29601
29659
  node.__mqttSinkState = state;
29660
+ _mqttClientMod ?? (_mqttClientMod = await import('@holoscript/engine/runtime/protocols/MQTTClient'));
29661
+ const { createMQTTClient, getMQTTClient, registerMQTTClient } = _mqttClientMod;
29602
29662
  const clientKey = `${config.broker}_${config.clientId || "default"}`;
29603
29663
  let client = getMQTTClient(clientKey);
29604
29664
  if (!client) {
@@ -29754,6 +29814,9 @@ function publishToMQTTSink(node, payload, topic) {
29754
29814
  }
29755
29815
  );
29756
29816
  }
29817
+
29818
+ // src/traits/MQTTSourceTrait.ts
29819
+ var _mqttClientMod2 = null;
29757
29820
  var defaultConfig2 = {
29758
29821
  broker: "mqtt://localhost:1883",
29759
29822
  topic: "#",
@@ -29765,7 +29828,7 @@ var defaultConfig2 = {
29765
29828
  var mqttSourceHandler = {
29766
29829
  name: "mqtt_source",
29767
29830
  defaultConfig: defaultConfig2,
29768
- onAttach(node, config, context) {
29831
+ async onAttach(node, config, context) {
29769
29832
  const state = {
29770
29833
  connected: false,
29771
29834
  lastMessage: null,
@@ -29775,6 +29838,8 @@ var mqttSourceHandler = {
29775
29838
  client: null
29776
29839
  };
29777
29840
  node.__mqttSourceState = state;
29841
+ _mqttClientMod2 ?? (_mqttClientMod2 = await import('@holoscript/engine/runtime/protocols/MQTTClient'));
29842
+ const { createMQTTClient, getMQTTClient, registerMQTTClient } = _mqttClientMod2;
29778
29843
  const clientKey = `${config.broker}_${config.clientId || "default"}`;
29779
29844
  let client = getMQTTClient(clientKey);
29780
29845
  if (!client) {
@@ -29816,8 +29881,8 @@ var mqttSourceHandler = {
29816
29881
  };
29817
29882
  client.subscribe({ topic: config.topic, qos: config.qos }, (message) => {
29818
29883
  let value = message.payload;
29819
- if (config.parseJson) {
29820
- value = MQTTClient.parsePayload(message);
29884
+ if (config.parseJson && _mqttClientMod2) {
29885
+ value = _mqttClientMod2.MQTTClient.parsePayload(message);
29821
29886
  }
29822
29887
  if (config.debounce && config.debounce > 0) {
29823
29888
  pendingMessage = value;
@@ -30279,13 +30344,24 @@ var multiAgentHandler = {
30279
30344
  }
30280
30345
  }
30281
30346
  };
30347
+
30348
+ // src/traits/NetworkedAvatarTrait.ts
30349
+ var _boneSystemMod = null;
30350
+ var _ikSolverMod = null;
30351
+ var _avatarControllerMod = null;
30282
30352
  var networkedAvatarHandler = {
30283
30353
  name: "networked_avatar",
30284
30354
  defaultConfig: {
30285
30355
  isLocal: false,
30286
30356
  updateRate: 30
30287
30357
  },
30288
- onAttach(node, config, context) {
30358
+ async onAttach(node, config, context) {
30359
+ _boneSystemMod ?? (_boneSystemMod = await import('@holoscript/engine/animation/BoneSystem'));
30360
+ _ikSolverMod ?? (_ikSolverMod = await import('@holoscript/engine/animation/IKSolver'));
30361
+ _avatarControllerMod ?? (_avatarControllerMod = await import('@holoscript/engine/animation/AvatarController'));
30362
+ const { BoneSystem } = _boneSystemMod;
30363
+ const { IKSolver } = _ikSolverMod;
30364
+ const { AvatarController } = _avatarControllerMod;
30289
30365
  const bones = new BoneSystem();
30290
30366
  const solver = new IKSolver();
30291
30367
  const controller = new AvatarController(solver, bones);
@@ -30699,6 +30775,9 @@ var neuralForgeHandler = {
30699
30775
  }
30700
30776
  }
30701
30777
  };
30778
+
30779
+ // src/traits/NPCAITrait.ts
30780
+ var _frameworkAI = null;
30702
30781
  var npcAIHandler = {
30703
30782
  name: "npc_ai",
30704
30783
  defaultConfig: {
@@ -30727,7 +30806,7 @@ var npcAIHandler = {
30727
30806
  const state = node.__npcAIState;
30728
30807
  if (!state || state.isThinking) return;
30729
30808
  },
30730
- onEvent(node, config, context, event) {
30809
+ async onEvent(node, config, context, event) {
30731
30810
  const state = node.__npcAIState;
30732
30811
  if (!state) return;
30733
30812
  if (event.type === "npc_ai_prompt") {
@@ -30735,6 +30814,8 @@ var npcAIHandler = {
30735
30814
  state.isThinking = true;
30736
30815
  state.conversationHistory.push({ role: "user", content: prompt });
30737
30816
  context.emit?.("npc_ai_think_begin", { node, prompt });
30817
+ _frameworkAI ?? (_frameworkAI = await import('@holoscript/framework/ai'));
30818
+ const { getDefaultAIAdapter } = _frameworkAI;
30738
30819
  const adapter = getDefaultAIAdapter();
30739
30820
  if (adapter && adapter.chat) {
30740
30821
  adapter.chat(prompt, void 0, state.conversationHistory.slice(0, -1)).then((response) => {
@@ -36257,6 +36338,9 @@ var lotusGenesisTriggerHandler = {
36257
36338
  });
36258
36339
  }
36259
36340
  };
36341
+
36342
+ // src/traits/HandMenuTrait.ts
36343
+ var _springAnimatorModule = null;
36260
36344
  var getCoord = (v, idx, key) => (Array.isArray(v) ? v[idx] : v[key]) ?? 0;
36261
36345
  var add2 = (v1, v2) => [
36262
36346
  getCoord(v1, 0, "x") + getCoord(v2, 0, "x"),
@@ -36272,7 +36356,9 @@ var handMenuHandler = {
36272
36356
  offset: [0, 0.2, 0],
36273
36357
  scale: 1
36274
36358
  },
36275
- onAttach(node, config, context) {
36359
+ async onAttach(node, config, context) {
36360
+ _springAnimatorModule ?? (_springAnimatorModule = await import('@holoscript/engine/animation/SpringAnimator'));
36361
+ const { SpringAnimator, SpringPresets } = _springAnimatorModule;
36276
36362
  const spring = new SpringAnimator(0, SpringPresets.gentle);
36277
36363
  menuSprings.set(node.id, spring);
36278
36364
  if (node.properties) {
@@ -36317,6 +36403,9 @@ var handMenuHandler = {
36317
36403
  }
36318
36404
  }
36319
36405
  };
36406
+
36407
+ // src/traits/ScrollableTrait.ts
36408
+ var _springAnimatorModule2 = null;
36320
36409
  var scrollStates = /* @__PURE__ */ new Map();
36321
36410
  var scrollableHandler = {
36322
36411
  name: "scrollable",
@@ -36327,7 +36416,9 @@ var scrollableHandler = {
36327
36416
  elasticity: 0.1,
36328
36417
  useSpringBounce: true
36329
36418
  },
36330
- onAttach(node, config, context) {
36419
+ async onAttach(node, config, context) {
36420
+ _springAnimatorModule2 ?? (_springAnimatorModule2 = await import('@holoscript/engine/animation/SpringAnimator'));
36421
+ const { SpringAnimator, SpringPresets } = _springAnimatorModule2;
36331
36422
  const spring = config.useSpringBounce ? new SpringAnimator(0, { ...SpringPresets.gentle, precision: 5e-3 }) : null;
36332
36423
  scrollStates.set(node.id, {
36333
36424
  offset: 0,
@@ -38408,6 +38499,7 @@ var characterHandler = {
38408
38499
  if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
38409
38500
  }
38410
38501
  };
38502
+ var _mesh3 = null;
38411
38503
  var DEFAULT_TRAIT_CONFIG = {
38412
38504
  mechanism: "simple_majority",
38413
38505
  timeout: 5e3
@@ -38428,8 +38520,10 @@ var ConsensusTrait = class extends EventEmitter {
38428
38520
  /**
38429
38521
  * Start the consensus trait
38430
38522
  */
38431
- start() {
38523
+ async start() {
38432
38524
  if (this.isStarted) return;
38525
+ _mesh3 ?? (_mesh3 = await import('@holoscript/mesh'));
38526
+ const { RaftConsensus, ConsensusManager } = _mesh3;
38433
38527
  const nodeId = this.config.nodeId || this.entityId;
38434
38528
  const mechanism = this.config.mechanism || "simple_majority";
38435
38529
  if (mechanism === "raft") {
@@ -44589,15 +44683,26 @@ var slidableHandler = {
44589
44683
  if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
44590
44684
  }
44591
44685
  };
44686
+ var _spatial = null;
44592
44687
  var DEFAULT_TRAIT_CONFIG2 = {
44593
- ...DEFAULT_SPATIAL_CONFIG,
44594
44688
  initialPosition: [0, 0, 0],
44595
44689
  autoStart: true
44596
44690
  };
44597
44691
  var SpatialAwarenessTrait = class extends EventEmitter {
44598
44692
  constructor(id, config = {}) {
44599
44693
  super();
44694
+ /**
44695
+ * The underlying spatial provider. `null` until `ensureInitialized()` has run
44696
+ * (it lazy-imports the optional engine peer to construct it). All sync methods
44697
+ * that touch `this.provider` null-guard and no-op until initialization, since
44698
+ * the trait is not "active" until `start()` / `ensureInitialized()` completes.
44699
+ */
44700
+ this.provider = null;
44600
44701
  this.ownsProvider = false;
44702
+ /** True once `ensureInitialized()` has constructed the provider + wired events. */
44703
+ this.initialized = false;
44704
+ /** In-flight initialization promise so concurrent `ensureInitialized()` calls share one import. */
44705
+ this.initPromise = null;
44601
44706
  this.velocity = [0, 0, 0];
44602
44707
  this.isActive = false;
44603
44708
  this.lastContext = null;
@@ -44606,26 +44711,53 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44606
44711
  this.id = id;
44607
44712
  this.config = { ...DEFAULT_TRAIT_CONFIG2, ...config };
44608
44713
  this.position = this.config.initialPosition || [0, 0, 0];
44609
- if (this.config.sharedProvider) {
44610
- this.provider = this.config.sharedProvider;
44611
- this.ownsProvider = false;
44612
- } else {
44613
- this.provider = new SpatialContextProvider();
44614
- this.ownsProvider = true;
44615
- }
44616
- this.setupEventHandlers();
44714
+ this.ownsProvider = !this.config.sharedProvider;
44617
44715
  if (this.config.autoStart) {
44618
- this.start();
44716
+ void this.start().catch(() => {
44717
+ });
44619
44718
  }
44620
44719
  }
44621
44720
  // ===========================================================================
44622
44721
  // LIFECYCLE
44623
44722
  // ===========================================================================
44624
44723
  /**
44625
- * Start spatial awareness
44724
+ * Lazily load the optional `@holoscript/engine/spatial` peer, construct the
44725
+ * provider, merge in the spatial defaults, and wire event forwarding.
44726
+ *
44727
+ * This is the single place the optional engine module is dynamically imported,
44728
+ * so a cold `import '@holoscript/core'` never touches it. Safe to call multiple
44729
+ * times — the import + construction happen exactly once (guarded by `initPromise`
44730
+ * and `this.initialized`).
44731
+ *
44732
+ * @throws if `@holoscript/engine/spatial` is not installed (the optional peer).
44733
+ */
44734
+ async ensureInitialized() {
44735
+ if (this.initialized) return;
44736
+ if (this.initPromise) return this.initPromise;
44737
+ this.initPromise = (async () => {
44738
+ _spatial ?? (_spatial = await import('@holoscript/engine/spatial'));
44739
+ this.config = { ..._spatial.DEFAULT_SPATIAL_CONFIG, ...this.config };
44740
+ this.provider = this.config.sharedProvider ?? new _spatial.SpatialContextProvider();
44741
+ this.setupEventHandlers();
44742
+ this.initialized = true;
44743
+ })();
44744
+ try {
44745
+ await this.initPromise;
44746
+ } finally {
44747
+ this.initPromise = null;
44748
+ }
44749
+ }
44750
+ /**
44751
+ * Start spatial awareness.
44752
+ *
44753
+ * Now async: it first awaits `ensureInitialized()` (which lazy-imports the
44754
+ * optional engine peer and constructs the provider), then registers the agent.
44626
44755
  */
44627
- start() {
44756
+ async start() {
44628
44757
  if (this.isActive) return;
44758
+ await this.ensureInitialized();
44759
+ if (this.isActive) return;
44760
+ if (!this.provider) return;
44629
44761
  this.provider.registerAgent(this.id, this.position, this.config);
44630
44762
  if (this.ownsProvider) {
44631
44763
  this.provider.start();
@@ -44637,6 +44769,10 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44637
44769
  */
44638
44770
  stop() {
44639
44771
  if (!this.isActive) return;
44772
+ if (!this.provider) {
44773
+ this.isActive = false;
44774
+ return;
44775
+ }
44640
44776
  this.provider.unregisterAgent(this.id);
44641
44777
  if (this.ownsProvider) {
44642
44778
  this.provider.stop();
@@ -44664,7 +44800,7 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44664
44800
  */
44665
44801
  setPosition(position) {
44666
44802
  this.position = position;
44667
- if (this.isActive) {
44803
+ if (this.isActive && this.provider) {
44668
44804
  this.provider.updateAgentPosition(this.id, position, this.velocity);
44669
44805
  }
44670
44806
  }
@@ -44679,7 +44815,7 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44679
44815
  */
44680
44816
  setVelocity(velocity) {
44681
44817
  this.velocity = velocity;
44682
- if (this.isActive) {
44818
+ if (this.isActive && this.provider) {
44683
44819
  this.provider.updateAgentPosition(this.id, this.position, velocity);
44684
44820
  }
44685
44821
  }
@@ -44696,7 +44832,9 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44696
44832
  * Get current spatial context
44697
44833
  */
44698
44834
  getContext() {
44699
- return this.lastContext || this.provider.getContext(this.id);
44835
+ if (this.lastContext) return this.lastContext;
44836
+ if (!this.provider) return null;
44837
+ return this.provider.getContext(this.id);
44700
44838
  }
44701
44839
  /**
44702
44840
  * Get nearby entities
@@ -44726,6 +44864,7 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44726
44864
  * Find nearest entity
44727
44865
  */
44728
44866
  findNearest(typeFilter) {
44867
+ if (!this.provider) return null;
44729
44868
  const results = this.provider.findNearest(this.position, 1, typeFilter);
44730
44869
  return results[0] || null;
44731
44870
  }
@@ -44733,12 +44872,14 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44733
44872
  * Find all entities within radius
44734
44873
  */
44735
44874
  findWithin(radius, typeFilter) {
44875
+ if (!this.provider) return [];
44736
44876
  return this.provider.findWithin(this.position, radius, typeFilter);
44737
44877
  }
44738
44878
  /**
44739
44879
  * Find visible entities
44740
44880
  */
44741
44881
  findVisible(direction, fov, maxDistance) {
44882
+ if (!this.provider) return [];
44742
44883
  return this.provider.findVisible(this.position, direction, fov, maxDistance);
44743
44884
  }
44744
44885
  /**
@@ -44766,18 +44907,21 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44766
44907
  * Register an entity for tracking
44767
44908
  */
44768
44909
  registerEntity(entity) {
44910
+ if (!this.provider) return;
44769
44911
  this.provider.setEntity(entity);
44770
44912
  }
44771
44913
  /**
44772
44914
  * Unregister an entity
44773
44915
  */
44774
44916
  unregisterEntity(entityId) {
44917
+ if (!this.provider) return;
44775
44918
  this.provider.removeEntity(entityId);
44776
44919
  }
44777
44920
  /**
44778
44921
  * Batch register entities
44779
44922
  */
44780
44923
  registerEntities(entities) {
44924
+ if (!this.provider) return;
44781
44925
  this.provider.setEntities(entities);
44782
44926
  }
44783
44927
  // ===========================================================================
@@ -44787,24 +44931,28 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44787
44931
  * Register a region
44788
44932
  */
44789
44933
  registerRegion(region) {
44934
+ if (!this.provider) return;
44790
44935
  this.provider.setRegion(region);
44791
44936
  }
44792
44937
  /**
44793
44938
  * Unregister a region
44794
44939
  */
44795
44940
  unregisterRegion(regionId) {
44941
+ if (!this.provider) return;
44796
44942
  this.provider.removeRegion(regionId);
44797
44943
  }
44798
44944
  /**
44799
44945
  * Subscribe to region events
44800
44946
  */
44801
44947
  watchRegion(regionId, callback) {
44948
+ if (!this.provider) return;
44802
44949
  this.provider.subscribeToRegion(this.id, regionId, callback);
44803
44950
  }
44804
44951
  /**
44805
44952
  * Unsubscribe from region events
44806
44953
  */
44807
44954
  unwatchRegion(regionId) {
44955
+ if (!this.provider) return;
44808
44956
  this.provider.unsubscribeFromRegion(this.id, regionId);
44809
44957
  }
44810
44958
  // ===========================================================================
@@ -44815,23 +44963,26 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44815
44963
  */
44816
44964
  setPerceptionRadius(radius) {
44817
44965
  this.config.perceptionRadius = radius;
44818
- if (this.isActive) {
44966
+ if (this.isActive && this.provider) {
44819
44967
  this.provider.unregisterAgent(this.id);
44820
44968
  this.provider.registerAgent(this.id, this.position, this.config);
44821
44969
  }
44822
44970
  }
44823
44971
  /**
44824
44972
  * Get perception radius
44973
+ *
44974
+ * Returns 0 if the spatial defaults have not yet been merged (i.e. before
44975
+ * `ensureInitialized()` ran and no explicit value was supplied in config).
44825
44976
  */
44826
44977
  getPerceptionRadius() {
44827
- return this.config.perceptionRadius;
44978
+ return this.config.perceptionRadius ?? 0;
44828
44979
  }
44829
44980
  /**
44830
44981
  * Set entity type filter
44831
44982
  */
44832
44983
  setEntityTypeFilter(types) {
44833
44984
  this.config.entityTypeFilter = types;
44834
- if (this.isActive) {
44985
+ if (this.isActive && this.provider) {
44835
44986
  this.provider.unregisterAgent(this.id);
44836
44987
  this.provider.registerAgent(this.id, this.position, this.config);
44837
44988
  }
@@ -44843,38 +44994,40 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44843
44994
  * Setup event handlers from provider
44844
44995
  */
44845
44996
  setupEventHandlers() {
44846
- this.provider.on("entity:entered", (agentId, event) => {
44997
+ const provider = this.provider;
44998
+ if (!provider) return;
44999
+ provider.on("entity:entered", (agentId, event) => {
44847
45000
  if (agentId !== this.id) return;
44848
45001
  if (event.type === "entity_entered") {
44849
45002
  this.emit("entity:entered", event.entity, event.distance);
44850
45003
  }
44851
45004
  });
44852
- this.provider.on("entity:exited", (agentId, event) => {
45005
+ provider.on("entity:exited", (agentId, event) => {
44853
45006
  if (agentId !== this.id) return;
44854
45007
  if (event.type === "entity_exited") {
44855
45008
  this.emit("entity:exited", event.entity);
44856
45009
  }
44857
45010
  });
44858
- this.provider.on("region:entered", (agentId, event) => {
45011
+ provider.on("region:entered", (agentId, event) => {
44859
45012
  if (agentId !== this.id) return;
44860
45013
  if (event.type === "region_entered") {
44861
45014
  this.emit("region:entered", event.region, event.previousRegion);
44862
45015
  }
44863
45016
  });
44864
- this.provider.on("region:exited", (agentId, event) => {
45017
+ provider.on("region:exited", (agentId, event) => {
44865
45018
  if (agentId !== this.id) return;
44866
45019
  if (event.type === "region_exited") {
44867
45020
  this.emit("region:exited", event.region);
44868
45021
  }
44869
45022
  });
44870
- this.provider.on("visibility:changed", (agentId, event) => {
45023
+ provider.on("visibility:changed", (agentId, event) => {
44871
45024
  if (agentId !== this.id) return;
44872
45025
  if (event.type === "visibility_changed") {
44873
45026
  this.visibleEntities.set(event.entityId, event.visible);
44874
45027
  this.emit("visibility:changed", event.entityId, event.visible);
44875
45028
  }
44876
45029
  });
44877
- this.provider.on("context:updated", (agentId, context) => {
45030
+ provider.on("context:updated", (agentId, context) => {
44878
45031
  if (agentId !== this.id) return;
44879
45032
  this.lastContext = context;
44880
45033
  this.emit("context:updated", context);
@@ -44884,15 +45037,17 @@ var SpatialAwarenessTrait = class extends EventEmitter {
44884
45037
  function createSpatialAwarenessTrait(id, config) {
44885
45038
  return new SpatialAwarenessTrait(id, config);
44886
45039
  }
44887
- function createSharedSpatialProvider() {
44888
- return new SpatialContextProvider();
45040
+ async function createSharedSpatialProvider() {
45041
+ _spatial ?? (_spatial = await import('@holoscript/engine/spatial'));
45042
+ return new _spatial.SpatialContextProvider();
44889
45043
  }
44890
45044
  var spatialAwarenessHandler = {
44891
45045
  name: "spatial_awareness",
44892
45046
  defaultConfig: {},
44893
- onAttach(node, config, ctx) {
45047
+ async onAttach(node, config, ctx) {
44894
45048
  const instance = new SpatialAwarenessTrait(node.id || "spatial_awareness", config);
44895
45049
  node.__spatial_awareness_instance = instance;
45050
+ await instance.start();
44896
45051
  ctx.emit("spatial_awareness_attached", { node, config });
44897
45052
  },
44898
45053
  onDetach(node, _config, ctx) {
@@ -56001,5 +56156,5 @@ var VRTraitRegistry = class {
56001
56156
  var vrTraitRegistry = new VRTraitRegistry();
56002
56157
 
56003
56158
  export { AIDriverTrait, ALL_CIRCUITS, ARKIT_MOUTH_SHAPES, AnimationTrait, BUILTIN_CIRCUITS, BarretenbergBackend, BehaviorTreeRunner, CARE_ETHICS_TRAIT, CRDTRoomTraitValidationError, CRDT_ROOM_TRAIT_DEFAULTS, CharacterTrait, ComponentType, ConsensusTrait, DEFAULT_ANIMATION_MAP, DEFAULT_AUTONOMY_GUARD_POLICY, DEFAULT_BEHAVIOR_FACT_TTL_ALERT_RULE, DEFAULT_EXPRESSION_PRESETS, DEFAULT_EXTERNAL_TIMEOUT_MS, DEFAULT_FOVEATED_BLEND, DEFAULT_FREQUENCY_BANDS, DEFAULT_REPUTATION_LEDGER_MAX_FACTS, DEFAULT_REPUTATION_LEDGER_TTL_DAYS, DEFAULT_SYNC_FIELD, DEFAULT_TRAIT_CONFIG2 as DEFAULT_TRAIT_CONFIG, DRAFT_DEFAULTS, DRAFT_TRAIT, DialogTrait, DraftManager, ECSWorld, EmotionDirectiveTrait, EnvironmentalAudioSystem, GEM_RESONANCE_ELEMENT_FREQUENCIES, GOAPPlanner, GOLDEN_ANGLE_DEG, IKTrait, InteractiveGraphTrait, JobQueuePersistence, JointTrait, LOCAL_WEBCAM_VIEW_ID, LipSyncTrait, LobbyTrait, MAX_EXPERIENCE_LOG_ENTRIES, MorphTrait, MultiviewGaussianRendererTrait, NetworkedTrait, OCULUS_VISEME_MAP, PIDControllerTrait, PressableTrait, REFERENCE_SPACE_CHAIN, REFUSED_CARE_OPTIMIZATION_TARGETS, RigidbodyTrait, SPATIAL_PREDICATE_CIRCUITS, SYNC_PRESETS, SandboxExecutionTrait, SlidableTrait, SpatialAwarenessTrait, SyncTierTrait, TIER_DEFAULTS, TriggerTrait, URDFRobotTrait, VRTraitRegistry, VoiceInputTrait, VoiceOutputTrait, VoronoiFractureSystem, WEATHER_PRESETS, aIDriverHandler, abTestHandler, abstain, accessibleHandler, advancedClothHandler, affinityHandler, agentDiscoveryHandler, agentMemoryHandler, agentMovementSystem, agentPortalHandler, aiInpaintingHandler, aiTextureGenHandler, aiUpscalingHandler, ainpcBrainHandler, alertHandler, altTextHandler, ambisonicsHandler, analyticsHandler, anchorHandler, applyFBXAxisConversion, applyStatModifiers, applyUSDAxisConversion, approve, audioMaterialHandler, audioOcclusionHandler, audioPortalHandler, auditLogHandler, autoVote, avatarEmbodimentHandler, behaviorTreeHandler, biofeedbackHandler, blackboardHandler, bloomReactiveHandler, bodyTrackingHandler, bufferHandler, buildBehaviorFactDisclosure, buoyancyHandler, cRDTRoomHandler, careEthicsHandler, chainHandler, characterHandler, choreographyHandler, circuitBreakerHandler, clothHandler, coLocatedHandler, compareSemVer, computeHandler, computePhyllotaxisPosition, computerUseHandler, consensusHandler, consentGateHandler, controlNetHandler, controllerInputHandler, controlnetHandler, createAIDriverTrait, createAnimationTrait, createApprovalRequest, createBaseMainnetAccountingAdapter, createBehaviorFactTtlAlertRule, createCRDTRoomTraitConfig, createCanBusAccountingAdapter, createCareField, createCharacterTrait, createConsensusTrait, createDialogTrait, createEdiX12AccountingAdapter, createEmotionDirectiveTrait, createHl7FhirAccountingAdapter, createIKTrait, createJointTrait, createLipSyncTrait, createLobbyTrait, createMorphTrait, createNetworkedTrait, createRepairLoop, createRigidbodyTrait, createRollbackCheckpoint, createSelectiveDisclosure, createSharedSpatialProvider, createSimulatedController, createSpatialAwarenessTrait, createTriggerTrait, createURDFRobotTrait, createVoiceInputTrait, createVoiceOutputTrait, cronHandler, dataBindingHandler, deriveBloomReactiveOutput, deriveLotusCenterPhase, deriveLotusGardenerSchedule, deriveLotusGenesisGate, deriveLotusGenesisSeed, deriveLotusPetalVisual, deriveLotusRootEmissive, deriveLotusStalkPosture, deriveWalkableNavmesh, destructionHandler, deviceProfiles, dialogHandler, dialogueHandler, diffusionRealtimeHandler, digitalTwinHandler, dropTableHandler, economyPrimitivesHandler, effectiveWeight, embeddingSearchHandler, emissiveAt, emotionDirectiveHandler, emotionHandler, emotionalVoiceHandler, encounterHandler, environmentalAudioHandler, evaluateAction, evaluateAutonomyGuard, evaluateCareEthicsTurn, extractLotusGenesisAnchorHash, extractPayload, eyeTrackedHandler, faceTrackingHandler, factionHandler, fbxHandler, feedbackLoopHandler, findReachablePath, findWalkableNodeAt, flowFieldHandler, fluidHandler, gardenerPulseJitter, gaussianSplatHandler, gemResonanceHandler, geospatialAnchorHandler, geospatialEnvHandler, gestureHandler, getActiveSessions, getAgentId, getAirAbsorption, getAuditLog, getCachedThingDescription, getCapabilities, getCareEthicsState, getEventHistory, getFBXAnimationStacks, getFBXBoneNames, getFBXMorphTargets, getFBXState, getGLTFAnimations, getGLTFMorphTargets, getGLTFState, getMQTTSinkClient, getMQTTSinkState, getMQTTSourceClient, getMQTTSourceState, getMyProposals, getMyVotes, getNegotiationMethods, getPredicateCircuitId, getSession, getUSDActiveVariant, getUSDAnimation, getUSDBlendShapes, getUSDJointNames, getUSDState, getUSDVariantSets, getWoTThingState, gltfHandler, goalOrientedHandler, gpuBufferHandler, gpuParticleHandler, gpuPhysicsHandler, granularMaterialHandler, handMenuHandler, handMeshAIHandler, handTrackingHandler, hapticCueHandler, hapticHandler, hasMQTTSinkTrait, hasMQTTSourceTrait, hasVoted, hasWoTThingTrait, hashGardenerSeed, hashSeed, headTrackedAudioHandler, heatmap3dHandler, highContrastHandler, hitlHandler, hrtfHandler, iKHandler, initiate, invalidateThingDescription, isConsentGranted, isFBXLoaded, isGLTFLoaded, isInSession, isMQTTSinkConnected, isMQTTSourceConnected, isReservedPaperId, isUSDLoaded, isUSDZ, isWalkableAt, jointHandler, layerAwareHandler, leave, lightEstimationHandler, lipSyncHandler, llmAgentHandler, lobbyHandler, localLLMHandler, lodSystem, lotusCenterHandler, lotusGardenerHandler, lotusGenesisTriggerHandler, lotusPetalHandler, lotusRootHandler, lotusStalkHandler, luckHandler, magnifiableHandler, marketplaceHandler, marketplaceIntegrationHandler, matchesCondition, materialXHandler, memoryHandler, meshDetectionHandler, messagingHandler, modifiedThreshold, morphHandler, motionReducedHandler, mqttSinkHandler, mqttSourceHandler, multiAgentHandler, multiviewGaussianRendererHandler, negotiationHandler, nerfHandler, networkedAvatarHandler, networkedHandler, neuralAnimationHandler, neuralForgeHandler, neuralLinkHandler, neuralUpscalingHandler, nftHandler, normalizeCenter, normalizeLotusSeed, normalizePointCloud, npcAIHandler, objectTrackingHandler, occlusionHandler, openXRHALHandler, parseCRDTRoomEntityConfig, parseCRDTRoomTraitConfig, partnerSDKHandler, patrolHandler, perceptionHandler, persistentAnchorHandler, photogrammetryHandler, phyllotaxisHandler, physicsSystem, pickByWeight, planeDetectionHandler, poiHandler, pointCloudHandler, portableHandler, poseEstimationHandler, pressableHandler, propose, publishToMQTTSink, quotaHandler, ragKnowledgeHandler, rateLimiterHandler, rbacHandler, realityKitMeshHandler, recordGratitude, rememberRelationalContext, remotePresenceHandler, renderNetworkHandler, reputationLedgerHandler, resolveBloomStage, resolveCRDTRoomTraitConfig, resolvePulseHz, resourceAccountingHandler, reverbZoneHandler, rigidbodyHandler, roadmapNodeHandler, roleHandler, rooftopAnchorHandler, roomMeshHandler, ropeHandler, runECSBenchmark, runResourceAccountingAudit, sceneGraphHandler, sceneReconstructionHandler, schedulerHandler, screenReaderHandler, scrollableHandler, seatedHandler, secondsToUSDTimeCode, seededRand01, sensorHandler, setAgentManifest, sharePlayHandler, sharedAnchorHandler, sharedWorldHandler, shouldFire, signRequest, skillRegistryHandler, slidableHandler, softBodyHandler, sonificationHandler, spatialAccessoryHandler, spatialAudioCueHandler, spatialAwarenessHandler, spatialNavigationHandler, spatialPersonaHandler, spectatorHandler, ssoOidcHandler, ssoSamlHandler, stableDiffusionHandler, stableResourceAccountingReceiptHash, statHandler, structuredLoggerHandler, subtitleHandler, syncTierHandler, tenantHandler, terrainAnchorHandler, timeoutGuardHandler, tokenGatedHandler, transformHandler, triggerHandler, urdfRobotHandler, usdHandler, usdTimeCodeToSeconds, userMonitorHandler, validateCRDTRoomTraitConfig, validateCareField, validateSemVer, vectorDBHandler, verifyWebhookSignature, visionHandler, voiceInputHandler, voiceMeshHandler, voiceOutputHandler, voiceProximityHandler, volumetricHandler, volumetricVideoHandler, volumetricWindowHandler, voronoiFractureHandler, vote, vpsHandler, vrTraitRegistry, walletHandler, wasmBridgeHandler, windHandler, withNegotiation, wotThingHandler, zkPrivateHandler };
56004
- //# sourceMappingURL=chunk-EOBB6A4B.js.map
56005
- //# sourceMappingURL=chunk-EOBB6A4B.js.map
56159
+ //# sourceMappingURL=chunk-RVBHAXFG.js.map
56160
+ //# sourceMappingURL=chunk-RVBHAXFG.js.map