@holoscript/core 7.0.0 → 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.
- package/README.md +2 -2
- package/bin/holoscript.cjs +3 -0
- package/dist/GLTFPipeline-276GE64O.js +16 -0
- package/dist/GLTFPipeline-M7WSSJED.cjs +37 -0
- package/dist/HoloScriptPlusParser-7FBIFUFC.js +693 -0
- package/dist/HoloScriptPlusParser-A2W7OCN2.cjs +698 -0
- package/dist/HoloScriptPlusParser-F2Z56FJR.js +10 -0
- package/dist/HoloScriptPlusParser-WKHRIH6T.cjs +27 -0
- package/dist/HoloScriptRuntime-3URVTKPJ.js +10 -0
- package/dist/HoloScriptRuntime-SXEAEU2N.cjs +19 -0
- package/dist/USDZExporter-3FWJ25JI.cjs +1037 -0
- package/dist/USDZExporter-D2HQLQYK.js +1035 -0
- package/dist/agents/index.cjs +19 -0
- package/dist/agents/index.d.ts +100 -0
- package/dist/agents/index.js +17 -0
- package/dist/chunk-23J755AR.js +1046 -0
- package/dist/chunk-253GBQZY.cjs +627 -0
- package/dist/chunk-25IQCHTO.cjs +781 -0
- package/dist/chunk-2BSMSUCE.js +1941 -0
- package/dist/chunk-2M2DPHKB.js +762 -0
- package/dist/chunk-2YSNA2F2.cjs +1274 -0
- package/dist/chunk-3AO425MZ.cjs +886 -0
- package/dist/chunk-3FOKASKO.cjs +348 -0
- package/dist/chunk-3HYYMEXI.cjs +56578 -0
- package/dist/chunk-3NFFOWGG.js +4287 -0
- package/dist/chunk-3WZEJHUQ.cjs +116 -0
- package/dist/chunk-4C57PR42.js +468 -0
- package/dist/chunk-4N4SXXWF.js +769 -0
- package/dist/chunk-4PDEPEQW.cjs +41 -0
- package/dist/chunk-4R6SBXDB.js +45 -0
- package/dist/chunk-4V2E7U7Q.cjs +2015 -0
- package/dist/chunk-5FSKKMR7.cjs +2092 -0
- package/dist/chunk-5GLCTO44.js +161 -0
- package/dist/chunk-5JEU52DW.js +382 -0
- package/dist/chunk-5S7RKFGR.cjs +446 -0
- package/dist/chunk-5WUNN6ZN.cjs +428 -0
- package/dist/chunk-62FBK3B7.js +70 -0
- package/dist/chunk-6CTRH7HT.cjs +1985 -0
- package/dist/chunk-6DPSFNJB.cjs +847 -0
- package/dist/chunk-6EX3I5P4.cjs +130 -0
- package/dist/chunk-73FELZVJ.cjs +611 -0
- package/dist/chunk-7CUEMLDZ.cjs +6445 -0
- package/dist/chunk-7HIASF7S.cjs +814 -0
- package/dist/chunk-A6KINLZJ.js +236 -0
- package/dist/chunk-AIA52I7T.cjs +543 -0
- package/dist/chunk-ANXZFVY2.js +113 -0
- package/dist/chunk-AYBXB26F.js +2176 -0
- package/dist/chunk-B4TFTDG4.js +449 -0
- package/dist/chunk-BE4UJCQT.js +623 -0
- package/dist/chunk-BRQJKJGT.cjs +20 -0
- package/dist/chunk-C2A5DUMF.cjs +689 -0
- package/dist/chunk-C37BHB7N.cjs +636 -0
- package/dist/chunk-CBJY23VL.js +126 -0
- package/dist/chunk-CIWWXYHZ.cjs +50 -0
- package/dist/chunk-CXFDRBQU.cjs +672 -0
- package/dist/chunk-D54CNIAJ.cjs +413 -0
- package/dist/chunk-DAJXW4KX.js +725 -0
- package/dist/chunk-DTGBOSEM.cjs +319 -0
- package/dist/chunk-E7JP3BS3.cjs +61 -0
- package/dist/chunk-EKBKLK7P.js +1169 -0
- package/dist/chunk-EKYL4PE3.cjs +404 -0
- package/dist/chunk-EUDQTK7N.cjs +4310 -0
- package/dist/chunk-EXKSFGSX.cjs +274 -0
- package/dist/chunk-EXUP2BUM.cjs +1173 -0
- package/dist/chunk-F43YAA34.js +623 -0
- package/dist/chunk-FDSGHPAK.js +130 -0
- package/dist/chunk-FEWUHQNM.cjs +144 -0
- package/dist/chunk-FGGJQRLZ.js +270 -0
- package/dist/chunk-FHP6LXJS.js +415 -0
- package/dist/chunk-FJPADH77.cjs +666 -0
- package/dist/chunk-FYSPZT4V.cjs +169 -0
- package/dist/chunk-GIOYPNTH.js +5575 -0
- package/dist/chunk-GJNCFRJU.cjs +125 -0
- package/dist/chunk-GMP623FG.cjs +1508 -0
- package/dist/chunk-GQHQOPXZ.cjs +5580 -0
- package/dist/chunk-GQT4TYKY.cjs +4381 -0
- package/dist/chunk-GTU2Z2WW.cjs +262 -0
- package/dist/chunk-GYZE55MO.js +2007 -0
- package/dist/chunk-GZG4KA4E.js +529 -0
- package/dist/chunk-H652NHX5.js +600 -0
- package/dist/chunk-HCCQLAA4.cjs +74 -0
- package/dist/chunk-HINXWAOD.cjs +1049 -0
- package/dist/chunk-HYNTS5CP.js +422 -0
- package/dist/chunk-HZSPDCXV.cjs +457 -0
- package/dist/chunk-HZTDET3N.js +1399 -0
- package/dist/chunk-I6XZ5DZF.cjs +488 -0
- package/dist/chunk-ILRBGFVD.cjs +72 -0
- package/dist/chunk-IPWSXCCN.js +1183 -0
- package/dist/chunk-IUTY5WQ2.cjs +424 -0
- package/dist/chunk-IVSZDECV.js +882 -0
- package/dist/chunk-IVY74O6C.js +247 -0
- package/dist/chunk-IZM5VQZD.js +714 -0
- package/dist/chunk-J32ZJZJH.js +554 -0
- package/dist/chunk-J6M4FPK5.js +421 -0
- package/dist/chunk-JC5YBPSF.cjs +984 -0
- package/dist/chunk-JCLBKPMX.js +3813 -0
- package/dist/chunk-JD7CIZ33.js +1949 -0
- package/dist/chunk-JIYN45TV.cjs +2525 -0
- package/dist/chunk-JJBE3TIH.cjs +1189 -0
- package/dist/chunk-JX7YL6ZE.js +2252 -0
- package/dist/chunk-K4VVR7CN.cjs +2433 -0
- package/dist/chunk-KEFNV2WM.cjs +2257 -0
- package/dist/chunk-KH4CNH66.cjs +424 -0
- package/dist/chunk-KJLB4OPV.js +5731 -0
- package/dist/chunk-KKFZ3B6J.cjs +557 -0
- package/dist/chunk-KKP7JKN4.cjs +6002 -0
- package/dist/chunk-KPJL34Y7.cjs +186 -0
- package/dist/chunk-KQCN6AKJ.cjs +3042 -0
- package/dist/chunk-KVRSTFNH.cjs +72 -0
- package/dist/chunk-LICPB5HZ.cjs +1409 -0
- package/dist/chunk-LM2VU56C.cjs +37 -0
- package/dist/chunk-M56JSP4A.js +400 -0
- package/dist/chunk-MBOOR7X4.js +18 -0
- package/dist/chunk-MGE5Z4GS.js +608 -0
- package/dist/chunk-MXFUTKCO.js +56 -0
- package/dist/chunk-MYY4PMWX.cjs +264 -0
- package/dist/chunk-N75IH2HY.js +258 -0
- package/dist/chunk-NBMHU6SW.js +669 -0
- package/dist/chunk-NG77ATEW.cjs +778 -0
- package/dist/chunk-NGKREZ36.js +6384 -0
- package/dist/chunk-NHWSN2SD.cjs +718 -0
- package/dist/chunk-NV4VMVXU.js +421 -0
- package/dist/chunk-NW5G5FBQ.js +215 -0
- package/dist/chunk-NXZFOPVD.cjs +5737 -0
- package/dist/chunk-OBIYPYYS.cjs +1993 -0
- package/dist/chunk-OIQYIIO3.cjs +473 -0
- package/dist/chunk-OL46QLBJ.js +61 -0
- package/dist/chunk-OMXII44L.js +5386 -0
- package/dist/chunk-OR4Q2BGL.cjs +759 -0
- package/dist/chunk-OSYNRVOV.cjs +243 -0
- package/dist/chunk-PGANYCAG.cjs +220 -0
- package/dist/chunk-PHENW4MQ.js +65 -0
- package/dist/chunk-PHVRG4I2.js +844 -0
- package/dist/chunk-Q56TT7IL.js +483 -0
- package/dist/chunk-QPOQ7VPI.js +1491 -0
- package/dist/chunk-QPSKHBJP.js +5963 -0
- package/dist/chunk-QXH7QDSZ.js +1989 -0
- package/dist/chunk-R75BSDH7.cjs +50 -0
- package/dist/chunk-RARB3MBR.js +207 -0
- package/dist/chunk-RVBHAXFG.js +56160 -0
- package/dist/chunk-S3MDHNKB.cjs +490 -0
- package/dist/chunk-S4W6Z2MN.js +2426 -0
- package/dist/chunk-S6YWHCKV.cjs +410 -0
- package/dist/chunk-SIEXCILW.js +229 -0
- package/dist/chunk-SJBGLS25.cjs +2196 -0
- package/dist/chunk-SLU6UPJI.cjs +410 -0
- package/dist/chunk-SMIWS6DE.cjs +212 -0
- package/dist/chunk-T2QCTZMO.js +811 -0
- package/dist/chunk-T5J7ZKP3.cjs +4885 -0
- package/dist/chunk-TDCNJHWO.js +341 -0
- package/dist/chunk-TG7O4WBC.js +406 -0
- package/dist/chunk-THCK6ECW.js +2085 -0
- package/dist/chunk-TJHVSBP2.js +439 -0
- package/dist/chunk-TVHSPJ4N.cjs +606 -0
- package/dist/chunk-U44IKGG7.cjs +5390 -0
- package/dist/chunk-UJXISJBN.js +487 -0
- package/dist/chunk-UM6C3CGK.js +4375 -0
- package/dist/chunk-UMABK6SI.js +686 -0
- package/dist/chunk-UOIGFQXC.cjs +9750 -0
- package/dist/chunk-URG2SJLK.js +2521 -0
- package/dist/chunk-V6MKC2FZ.js +979 -0
- package/dist/chunk-VECQYRXL.js +474 -0
- package/dist/chunk-VJ3L7CHT.cjs +169 -0
- package/dist/chunk-VMLKSV26.js +1216 -0
- package/dist/chunk-VVKVQZI6.js +55 -0
- package/dist/chunk-W6RW64BB.cjs +1219 -0
- package/dist/chunk-W7VDOASB.cjs +639 -0
- package/dist/chunk-WDT3JTGM.cjs +483 -0
- package/dist/chunk-WJIHFLMJ.js +404 -0
- package/dist/chunk-WKX5AMOY.js +309 -0
- package/dist/chunk-WNNE3PO3.js +34 -0
- package/dist/chunk-WRKUDAZJ.js +3038 -0
- package/dist/chunk-WRLUBRKS.cjs +1943 -0
- package/dist/chunk-WRNEH5MO.js +3169 -0
- package/dist/chunk-WRWEX5ZF.js +658 -0
- package/dist/chunk-X3GJPRVK.cjs +3246 -0
- package/dist/chunk-XHIV6326.cjs +793 -0
- package/dist/chunk-XIVIE43A.cjs +729 -0
- package/dist/chunk-XJAN7CZG.cjs +432 -0
- package/dist/chunk-XKTPFXGA.js +164 -0
- package/dist/chunk-XL6INWKT.js +121 -0
- package/dist/chunk-XSFNHP2E.js +632 -0
- package/dist/chunk-XT6JY5W5.js +9684 -0
- package/dist/chunk-XUILI4KB.cjs +430 -0
- package/dist/chunk-XUUVDHIF.cjs +3962 -0
- package/dist/chunk-YF2I3MV3.js +46 -0
- package/dist/chunk-YIMN575O.js +4847 -0
- package/dist/chunk-YIVFJNYV.js +176 -0
- package/dist/chunk-YKGPCZEE.cjs +237 -0
- package/dist/chunk-YN6V7R3L.cjs +327 -0
- package/dist/chunk-YQELFNJV.js +39 -0
- package/dist/chunk-YYXH45E2.js +426 -0
- package/dist/chunk-ZBQXLH2L.js +756 -0
- package/dist/chunk-ZDSYWBIE.cjs +69 -0
- package/dist/chunk-ZU7NIRT6.js +325 -0
- package/dist/chunk-ZZ7RO2UQ.js +1243 -0
- package/dist/chunk-ZZEI7MV4.js +778 -0
- package/dist/cli/holoscript-runner.cjs +2255 -0
- package/dist/cli/holoscript-runner.js +2230 -0
- package/dist/codebase/index.cjs +336 -0
- package/dist/codebase/index.js +331 -0
- package/dist/compiler/agent-inference.cjs +31 -0
- package/dist/compiler/agent-inference.js +8 -0
- package/dist/compiler/android-xr.cjs +24 -0
- package/dist/compiler/android-xr.js +14 -0
- package/dist/compiler/android.cjs +24 -0
- package/dist/compiler/android.js +14 -0
- package/dist/compiler/ar.cjs +23 -0
- package/dist/compiler/ar.js +11 -0
- package/dist/compiler/babylon.cjs +21 -0
- package/dist/compiler/babylon.js +15 -0
- package/dist/compiler/business-quest.cjs +43 -0
- package/dist/compiler/business-quest.js +4 -0
- package/dist/compiler/coco.cjs +27 -0
- package/dist/compiler/coco.js +4 -0
- package/dist/compiler/context.cjs +25 -0
- package/dist/compiler/context.d.ts +28 -0
- package/dist/compiler/context.js +8 -0
- package/dist/compiler/domain-block-utils.cjs +605 -0
- package/dist/compiler/domain-block-utils.js +11 -0
- package/dist/compiler/dtdl.cjs +27 -0
- package/dist/compiler/dtdl.js +11 -0
- package/dist/compiler/gltf-pipeline.cjs +39 -0
- package/dist/compiler/gltf-pipeline.js +4 -0
- package/dist/compiler/godot.cjs +18 -0
- package/dist/compiler/godot.js +12 -0
- package/dist/compiler/incremental.cjs +34 -0
- package/dist/compiler/incremental.js +9 -0
- package/dist/compiler/index.cjs +5860 -0
- package/dist/compiler/index.d.ts +322 -21
- package/dist/compiler/index.js +5525 -0
- package/dist/compiler/ios.cjs +23 -0
- package/dist/compiler/ios.js +13 -0
- package/dist/compiler/llm-provider-capabilities.cjs +25 -0
- package/dist/compiler/llm-provider-capabilities.d.ts +43 -0
- package/dist/compiler/llm-provider-capabilities.js +8 -0
- package/dist/compiler/multi-layer.cjs +24 -0
- package/dist/compiler/multi-layer.js +15 -0
- package/dist/compiler/nodetoy.cjs +23 -0
- package/dist/compiler/nodetoy.js +4 -0
- package/dist/compiler/openxr.cjs +19 -0
- package/dist/compiler/openxr.js +13 -0
- package/dist/compiler/playcanvas.cjs +19 -0
- package/dist/compiler/playcanvas.js +13 -0
- package/dist/compiler/r3f.cjs +38 -0
- package/dist/compiler/r3f.d.ts +22 -0
- package/dist/compiler/r3f.js +16 -0
- package/dist/compiler/remotion.cjs +23 -0
- package/dist/compiler/remotion.js +4 -0
- package/dist/compiler/reproducibility.cjs +39 -0
- package/dist/compiler/reproducibility.js +4 -0
- package/dist/compiler/sdf.cjs +24 -0
- package/dist/compiler/sdf.js +12 -0
- package/dist/compiler/semantic-scene.cjs +31 -0
- package/dist/compiler/semantic-scene.js +4 -0
- package/dist/compiler/state.cjs +21 -0
- package/dist/compiler/state.js +11 -0
- package/dist/compiler/trait-composition.cjs +30 -0
- package/dist/compiler/trait-composition.js +9 -0
- package/dist/compiler/unity.cjs +19 -0
- package/dist/compiler/unity.js +13 -0
- package/dist/compiler/unreal.cjs +23 -0
- package/dist/compiler/unreal.js +13 -0
- package/dist/compiler/urdf.cjs +52 -0
- package/dist/compiler/urdf.js +12 -0
- package/dist/compiler/usd-physics.cjs +26 -0
- package/dist/compiler/usd-physics.js +9 -0
- package/dist/compiler/visionos.cjs +19 -0
- package/dist/compiler/visionos.js +13 -0
- package/dist/compiler/vrchat.cjs +22 -0
- package/dist/compiler/vrchat.js +12 -0
- package/dist/compiler/vrr.cjs +24 -0
- package/dist/compiler/vrr.js +12 -0
- package/dist/compiler/wasm.cjs +36 -0
- package/dist/compiler/wasm.js +12 -0
- package/dist/compiler/webgpu.cjs +18 -0
- package/dist/compiler/webgpu.js +12 -0
- package/dist/coordinators/index.cjs +1266 -0
- package/dist/coordinators/index.d.ts +72 -1
- package/dist/coordinators/index.js +1259 -0
- package/dist/debugger.cjs +24 -0
- package/dist/debugger.js +11 -0
- package/dist/entries/interop.cjs +64 -0
- package/dist/entries/interop.js +7 -0
- package/dist/entries/scripting.cjs +55 -0
- package/dist/entries/scripting.js +10 -0
- package/dist/hololand/index.cjs +146 -0
- package/dist/hololand/index.d.ts +70 -0
- package/dist/hololand/index.js +5 -0
- package/dist/index.cjs +43233 -0
- package/dist/index.d.ts +976 -21
- package/dist/index.js +39995 -0
- package/dist/math/tropical-spmv.cjs +45 -0
- package/dist/math/tropical-spmv.js +4 -0
- package/dist/math/vec3.cjs +57 -0
- package/dist/math/vec3.js +4 -0
- package/dist/ml-dsa-FSKBTE3W.cjs +1265 -0
- package/dist/ml-dsa-Z7JDKW4L.js +1265 -0
- package/dist/paper-0c-spike/index.cjs +150 -0
- package/dist/paper-0c-spike/index.js +141 -0
- package/dist/parser.cjs +61 -0
- package/dist/parser.d.ts +11 -0
- package/dist/parser.js +12 -0
- package/dist/playwright-3AT3AKTV.cjs +98673 -0
- package/dist/playwright-VZPDVUEQ.js +98660 -0
- package/dist/reconstruction/index.cjs +153 -0
- package/dist/reconstruction/index.d.ts +29 -2
- package/dist/reconstruction/index.js +8 -0
- package/dist/runtime.cjs +316 -0
- package/dist/runtime.d.ts +61 -0
- package/dist/runtime.js +31 -0
- package/dist/self-improvement/index.cjs +563 -0
- package/dist/self-improvement/index.js +545 -0
- package/dist/storage/index.cjs +38 -0
- package/dist/storage/index.js +5 -0
- package/dist/testing.cjs +25 -0
- package/dist/testing.d.ts +70 -0
- package/dist/testing.js +4 -0
- package/dist/traitDocs/traitDocs.cjs +33 -0
- package/dist/traitDocs/traitDocs.js +7 -0
- package/dist/traits/botanical-lotus.cjs +41 -0
- package/dist/traits/botanical-lotus.d.ts +172 -0
- package/dist/traits/botanical-lotus.js +4 -0
- package/dist/traits/engines/index.cjs +520 -0
- package/dist/traits/engines/index.js +380 -0
- package/dist/traits/index.cjs +24409 -0
- package/dist/traits/index.d.ts +171 -35
- package/dist/traits/index.js +21634 -0
- package/dist/traits/simulation-solver-factory.cjs +13 -0
- package/dist/traits/simulation-solver-factory.d.ts +23 -0
- package/dist/traits/simulation-solver-factory.js +4 -0
- package/dist/traits/webcam-gaze.cjs +35 -0
- package/dist/traits/webcam-gaze.d.ts +17 -0
- package/dist/traits/webcam-gaze.js +4 -0
- package/dist/type-checker.cjs +19 -0
- package/dist/type-checker.js +6 -0
- package/dist/world/index.cjs +947 -0
- package/dist/world/index.d.ts +147 -0
- package/dist/world/index.js +939 -0
- package/dist/world-model/index.cjs +1446 -0
- package/dist/world-model/index.d.ts +119 -0
- package/dist/world-model/index.js +1414 -0
- package/dist/wot/index.cjs +29 -0
- package/dist/wot/index.js +4 -0
- package/package.json +93 -49
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkILRBGFVD_cjs = require('./chunk-ILRBGFVD.cjs');
|
|
4
|
+
|
|
5
|
+
// src/traits/MitosisTrait.ts
|
|
6
|
+
var mitosisHandler = {
|
|
7
|
+
name: "mitosis",
|
|
8
|
+
defaultConfig: {
|
|
9
|
+
strategy: "collaborative",
|
|
10
|
+
max_children: 5,
|
|
11
|
+
auto_cleanup: true
|
|
12
|
+
},
|
|
13
|
+
onAttach(node, config, context) {
|
|
14
|
+
const state = {
|
|
15
|
+
parent_id: ("parent_id" in config ? config.parent_id : null) || null,
|
|
16
|
+
active_children: [],
|
|
17
|
+
tasks_delegated: 0,
|
|
18
|
+
completed_tasks: 0,
|
|
19
|
+
last_sync_time: Date.now()
|
|
20
|
+
};
|
|
21
|
+
node.__mitosisState = state;
|
|
22
|
+
context.emit?.("mitosis_init", {
|
|
23
|
+
nodeId: node.id,
|
|
24
|
+
strategy: config.strategy,
|
|
25
|
+
parent_id: state.parent_id
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
onDetach(node, config, context) {
|
|
29
|
+
const state = node.__mitosisState;
|
|
30
|
+
if (state && config.auto_cleanup) {
|
|
31
|
+
for (const childId of state.active_children) {
|
|
32
|
+
context.emit?.("mitosis_despawn_child", { childId });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
delete node.__mitosisState;
|
|
36
|
+
},
|
|
37
|
+
onEvent(node, config, context, event) {
|
|
38
|
+
const state = node.__mitosisState;
|
|
39
|
+
if (!state) return;
|
|
40
|
+
if (event.type === "mitosis_spawned") {
|
|
41
|
+
const childId = event.childId;
|
|
42
|
+
const parentId = event.parentId;
|
|
43
|
+
if (node.id === parentId) {
|
|
44
|
+
state.active_children.push(childId);
|
|
45
|
+
state.tasks_delegated++;
|
|
46
|
+
context.emit?.("on_mitosis_spawned", { childId, parentId: node.id });
|
|
47
|
+
}
|
|
48
|
+
} else if (event.type === "mitosis_child_complete") {
|
|
49
|
+
const childId = "childId" in event ? event.childId : "";
|
|
50
|
+
const parentId = "parentId" in event ? event.parentId : "";
|
|
51
|
+
const result = "result" in event ? event.result : void 0;
|
|
52
|
+
if (node.id === parentId) {
|
|
53
|
+
state.completed_tasks++;
|
|
54
|
+
state.last_sync_time = Date.now();
|
|
55
|
+
context.emit?.("mitosis_synced", {
|
|
56
|
+
parentId: node.id,
|
|
57
|
+
childId,
|
|
58
|
+
result
|
|
59
|
+
});
|
|
60
|
+
if (config.strategy === "collaborative") {
|
|
61
|
+
if (result && typeof result === "object") {
|
|
62
|
+
Object.assign(node.properties || {}, result);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else if (event.type === "mitosis_child_failed") {
|
|
67
|
+
context.emit?.("on_mitosis_error", {
|
|
68
|
+
parentId: node.id,
|
|
69
|
+
childId: event.childId,
|
|
70
|
+
error: event.error
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/traits/JEPAPredictor.ts
|
|
77
|
+
var JEPAPredictor = class {
|
|
78
|
+
constructor(config, weights) {
|
|
79
|
+
if (!Number.isInteger(config.latentDim) || config.latentDim < 1) {
|
|
80
|
+
throw new RangeError(`JEPAPredictor: latentDim must be a positive integer, got ${config.latentDim}`);
|
|
81
|
+
}
|
|
82
|
+
if (!Number.isInteger(config.condDim) || config.condDim < 0) {
|
|
83
|
+
throw new RangeError(`JEPAPredictor: condDim must be a non-negative integer, got ${config.condDim}`);
|
|
84
|
+
}
|
|
85
|
+
this.latentDim = config.latentDim;
|
|
86
|
+
this.condDim = config.condDim;
|
|
87
|
+
this.weights = weights ?? initDeterministicWeights(config.latentDim, config.condDim);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Forward pass: predict next-state embedding.
|
|
91
|
+
*
|
|
92
|
+
* @param contextEmb Float32Array of length latentDim (context encoder output)
|
|
93
|
+
* @param conditioning Float32Array of length condDim, or null/undefined for
|
|
94
|
+
* unconditional prediction
|
|
95
|
+
*/
|
|
96
|
+
forward(contextEmb, conditioning) {
|
|
97
|
+
const { latentDim, condDim } = this;
|
|
98
|
+
const inputDim = latentDim + condDim;
|
|
99
|
+
if (contextEmb.length !== latentDim) {
|
|
100
|
+
throw new RangeError(
|
|
101
|
+
`JEPAPredictor.forward: contextEmb.length=${contextEmb.length} \u2260 latentDim=${latentDim}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const input = new Float32Array(inputDim);
|
|
105
|
+
input.set(contextEmb, 0);
|
|
106
|
+
if (condDim > 0) {
|
|
107
|
+
const cond = conditioning ?? new Float32Array(condDim);
|
|
108
|
+
if (cond.length !== condDim) {
|
|
109
|
+
throw new RangeError(
|
|
110
|
+
`JEPAPredictor.forward: conditioning.length=${cond.length} \u2260 condDim=${condDim}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
input.set(cond, latentDim);
|
|
114
|
+
}
|
|
115
|
+
const hidden = matMulVec(this.weights.W1, input, inputDim, latentDim);
|
|
116
|
+
addInPlace(hidden, this.weights.b1);
|
|
117
|
+
reluInPlace(hidden);
|
|
118
|
+
const predicted = matMulVec(this.weights.W2, hidden, latentDim, latentDim);
|
|
119
|
+
addInPlace(predicted, this.weights.b2);
|
|
120
|
+
return { predicted, hidden };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Replace weights (e.g. after an external training step or gradient update).
|
|
124
|
+
* Does NOT implement EMA — callers manage weight schedule externally.
|
|
125
|
+
*/
|
|
126
|
+
setWeights(weights) {
|
|
127
|
+
validateWeights(weights, this.latentDim, this.condDim);
|
|
128
|
+
this.weights = weights;
|
|
129
|
+
}
|
|
130
|
+
/** Read-only access to current weights for serialisation. */
|
|
131
|
+
getWeights() {
|
|
132
|
+
return this.weights;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Plan: given a context state string and a list of candidate action names,
|
|
136
|
+
* return the action predicted to yield the highest-confidence next-state
|
|
137
|
+
* embedding (lowest L2 norm from the current state embedding — a proxy for
|
|
138
|
+
* "least surprising / most on-manifold" outcome).
|
|
139
|
+
*
|
|
140
|
+
* Encoding strategy: deterministic text→float32 hash (same technique used
|
|
141
|
+
* in JEPAObjective.encodeContext — no async/LLM dependency at plan time).
|
|
142
|
+
*
|
|
143
|
+
* @param currentState Snapshot string of the agent's current state.
|
|
144
|
+
* @param candidateActions Non-empty list of action name strings to score.
|
|
145
|
+
* @returns The action name with the highest predicted confidence, plus its
|
|
146
|
+
* predicted embedding for downstream SimulationContract verification.
|
|
147
|
+
*/
|
|
148
|
+
plan(currentState, candidateActions) {
|
|
149
|
+
if (candidateActions.length === 0) {
|
|
150
|
+
throw new RangeError("JEPAPredictor.plan: candidateActions must be non-empty");
|
|
151
|
+
}
|
|
152
|
+
const contextEmb = textToEmbedding(currentState, this.latentDim);
|
|
153
|
+
let bestAction = candidateActions[0];
|
|
154
|
+
let bestPredicted = new Float32Array(this.latentDim);
|
|
155
|
+
let bestConfidence = -Infinity;
|
|
156
|
+
for (const action of candidateActions) {
|
|
157
|
+
const conditioning = this.condDim > 0 ? textToEmbedding(action, this.condDim) : null;
|
|
158
|
+
const { predicted } = this.forward(contextEmb, conditioning);
|
|
159
|
+
const confidence = -l2Norm(predicted);
|
|
160
|
+
if (confidence > bestConfidence) {
|
|
161
|
+
bestConfidence = confidence;
|
|
162
|
+
bestAction = action;
|
|
163
|
+
bestPredicted = predicted;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { action: bestAction, predicted: bestPredicted, confidence: bestConfidence };
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
function matMulVec(matrix, vec, inputDim, outputDim) {
|
|
170
|
+
const out = new Float32Array(outputDim);
|
|
171
|
+
for (let i = 0; i < outputDim; i++) {
|
|
172
|
+
let acc = 0;
|
|
173
|
+
const base = i * inputDim;
|
|
174
|
+
for (let j = 0; j < inputDim; j++) {
|
|
175
|
+
acc += matrix[base + j] * vec[j];
|
|
176
|
+
}
|
|
177
|
+
out[i] = acc;
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
function addInPlace(a, b) {
|
|
182
|
+
for (let i = 0; i < a.length; i++) {
|
|
183
|
+
a[i] += b[i];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function reluInPlace(a) {
|
|
187
|
+
for (let i = 0; i < a.length; i++) {
|
|
188
|
+
if (a[i] < 0) a[i] = 0;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function initDeterministicWeights(latentDim, condDim) {
|
|
192
|
+
const inputDim = latentDim + condDim;
|
|
193
|
+
const scale1 = Math.sqrt(2 / inputDim);
|
|
194
|
+
const scale2 = Math.sqrt(2 / latentDim);
|
|
195
|
+
const W1 = new Float32Array(inputDim * latentDim);
|
|
196
|
+
const b1 = new Float32Array(latentDim);
|
|
197
|
+
const W2 = new Float32Array(latentDim * latentDim);
|
|
198
|
+
const b2 = new Float32Array(latentDim);
|
|
199
|
+
let seed = 3735928559;
|
|
200
|
+
const lcg = () => {
|
|
201
|
+
seed = Math.imul(seed, 1664525) + 1013904223;
|
|
202
|
+
return (seed >>> 0) / 4294967296 * 2 - 1;
|
|
203
|
+
};
|
|
204
|
+
for (let i = 0; i < W1.length; i++) W1[i] = lcg() * scale1;
|
|
205
|
+
for (let i = 0; i < W2.length; i++) W2[i] = lcg() * scale2;
|
|
206
|
+
return { W1, b1, W2, b2 };
|
|
207
|
+
}
|
|
208
|
+
function textToEmbedding(text, dim) {
|
|
209
|
+
const out = new Float32Array(dim);
|
|
210
|
+
let h = 5381;
|
|
211
|
+
for (let i = 0; i < text.length; i++) {
|
|
212
|
+
h = Math.imul(h, 33) ^ text.charCodeAt(i);
|
|
213
|
+
h = h >>> 0;
|
|
214
|
+
}
|
|
215
|
+
for (let d = 0; d < dim; d++) {
|
|
216
|
+
h = Math.imul(h, 1664525) + 1013904223;
|
|
217
|
+
h = h >>> 0;
|
|
218
|
+
out[d] = h / 4294967296 * 2 - 1;
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
function l2Norm(v) {
|
|
223
|
+
let sum = 0;
|
|
224
|
+
for (let i = 0; i < v.length; i++) sum += v[i] * v[i];
|
|
225
|
+
return Math.sqrt(sum);
|
|
226
|
+
}
|
|
227
|
+
function validateWeights(w, latentDim, condDim) {
|
|
228
|
+
const inputDim = latentDim + condDim;
|
|
229
|
+
const expected = {
|
|
230
|
+
W1: inputDim * latentDim,
|
|
231
|
+
b1: latentDim,
|
|
232
|
+
W2: latentDim * latentDim,
|
|
233
|
+
b2: latentDim
|
|
234
|
+
};
|
|
235
|
+
for (const key of ["W1", "b1", "W2", "b2"]) {
|
|
236
|
+
if (w[key].length !== expected[key]) {
|
|
237
|
+
throw new RangeError(
|
|
238
|
+
`JEPAPredictor: weights.${key}.length=${w[key].length} \u2260 expected ${expected[key]}`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/traits/EmbeddingTrait.ts
|
|
245
|
+
var embeddingHandler = {
|
|
246
|
+
name: "embedding",
|
|
247
|
+
defaultConfig: { default_model: "text-embedding-3-small", default_dimensions: 1536 },
|
|
248
|
+
onAttach(node) {
|
|
249
|
+
node.__embeddingState = { generated: 0 };
|
|
250
|
+
},
|
|
251
|
+
onDetach(node) {
|
|
252
|
+
delete node.__embeddingState;
|
|
253
|
+
},
|
|
254
|
+
onUpdate() {
|
|
255
|
+
},
|
|
256
|
+
onEvent(node, config, context, event) {
|
|
257
|
+
const state = node.__embeddingState;
|
|
258
|
+
if (!state) return;
|
|
259
|
+
if ((typeof event === "string" ? event : event.type) === "embedding:generate") {
|
|
260
|
+
state.generated++;
|
|
261
|
+
const dims = resolveEmbeddingDimensions(event, config);
|
|
262
|
+
const model = event.model ?? config.default_model;
|
|
263
|
+
const input = event.input ?? event.payload?.input ?? "";
|
|
264
|
+
context.emit?.("embedding:result", {
|
|
265
|
+
vector: createDeterministicEmbedding(input, dims, model),
|
|
266
|
+
dimensions: dims,
|
|
267
|
+
model,
|
|
268
|
+
source: "local-deterministic-fallback",
|
|
269
|
+
index: state.generated
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
function resolveEmbeddingDimensions(event, config) {
|
|
275
|
+
const rawDimensions = event.dimensions ?? event.payload?.dimensions;
|
|
276
|
+
const dimensions = typeof rawDimensions === "number" ? rawDimensions : config.default_dimensions;
|
|
277
|
+
if (!Number.isFinite(dimensions) || dimensions <= 0) {
|
|
278
|
+
return Math.max(1, Math.floor(config.default_dimensions));
|
|
279
|
+
}
|
|
280
|
+
return Math.floor(dimensions);
|
|
281
|
+
}
|
|
282
|
+
function createDeterministicEmbedding(input, dimensions, model) {
|
|
283
|
+
const vector = new Float32Array(dimensions);
|
|
284
|
+
const text = stringifyEmbeddingInput(input);
|
|
285
|
+
const features = extractEmbeddingFeatures(text);
|
|
286
|
+
for (let i = 0; i < features.length; i++) {
|
|
287
|
+
const feature = features[i];
|
|
288
|
+
const hash = fnv1a(`${model}\0${feature}\0${i}`);
|
|
289
|
+
const index = hash % dimensions;
|
|
290
|
+
const sign = hash & 1 ? 1 : -1;
|
|
291
|
+
const weight = 1 + Math.log1p(feature.length);
|
|
292
|
+
vector[index] += sign * weight;
|
|
293
|
+
}
|
|
294
|
+
normalizeVector(vector);
|
|
295
|
+
return vector;
|
|
296
|
+
}
|
|
297
|
+
function stringifyEmbeddingInput(input) {
|
|
298
|
+
if (typeof input === "string") return input;
|
|
299
|
+
if (input === null || input === void 0) return "";
|
|
300
|
+
try {
|
|
301
|
+
return JSON.stringify(input);
|
|
302
|
+
} catch {
|
|
303
|
+
return String(input);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function extractEmbeddingFeatures(text) {
|
|
307
|
+
const normalized = text.trim().toLowerCase();
|
|
308
|
+
if (!normalized) return ["<empty>"];
|
|
309
|
+
const tokens = normalized.match(/[a-z0-9_:-]+/g) ?? [normalized];
|
|
310
|
+
const features = [...tokens, `len:${normalized.length}`];
|
|
311
|
+
for (const token of tokens) {
|
|
312
|
+
if (token.length <= 3) {
|
|
313
|
+
features.push(`tok:${token}`);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
for (let i = 0; i <= token.length - 3; i++) {
|
|
317
|
+
features.push(`tri:${token.slice(i, i + 3)}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return features;
|
|
321
|
+
}
|
|
322
|
+
function normalizeVector(vector) {
|
|
323
|
+
let normSquared = 0;
|
|
324
|
+
for (const value of vector) {
|
|
325
|
+
normSquared += value * value;
|
|
326
|
+
}
|
|
327
|
+
if (normSquared === 0) {
|
|
328
|
+
vector[0] = 1;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const norm = Math.sqrt(normSquared);
|
|
332
|
+
for (let i = 0; i < vector.length; i++) {
|
|
333
|
+
vector[i] = vector[i] / norm;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function fnv1a(value) {
|
|
337
|
+
let hash = 2166136261;
|
|
338
|
+
for (let i = 0; i < value.length; i++) {
|
|
339
|
+
hash ^= value.charCodeAt(i);
|
|
340
|
+
hash = Math.imul(hash, 16777619);
|
|
341
|
+
}
|
|
342
|
+
return hash >>> 0;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/traits/JEPAObjective.ts
|
|
346
|
+
var jepObjectiveHandler = {
|
|
347
|
+
name: "jepa_objective",
|
|
348
|
+
defaultConfig: {
|
|
349
|
+
latentDim: 128,
|
|
350
|
+
condDim: 0,
|
|
351
|
+
sigregWeight: 0.05,
|
|
352
|
+
sigregProjections: 64,
|
|
353
|
+
sigregSigma: 1,
|
|
354
|
+
embeddingModel: "jepa-context-encoder"
|
|
355
|
+
},
|
|
356
|
+
onAttach(node, config) {
|
|
357
|
+
const predictorConfig = {
|
|
358
|
+
latentDim: config.latentDim,
|
|
359
|
+
condDim: config.condDim
|
|
360
|
+
};
|
|
361
|
+
node.__jepaState = {
|
|
362
|
+
step: 0,
|
|
363
|
+
predictor: new JEPAPredictor(predictorConfig),
|
|
364
|
+
embeddingConfig: {
|
|
365
|
+
default_model: config.embeddingModel,
|
|
366
|
+
default_dimensions: config.latentDim
|
|
367
|
+
},
|
|
368
|
+
pendingContextEmb: null
|
|
369
|
+
};
|
|
370
|
+
},
|
|
371
|
+
onDetach(node) {
|
|
372
|
+
delete node.__jepaState;
|
|
373
|
+
},
|
|
374
|
+
onUpdate() {
|
|
375
|
+
},
|
|
376
|
+
onEvent(node, config, context, event) {
|
|
377
|
+
const state = node.__jepaState;
|
|
378
|
+
if (!state) return;
|
|
379
|
+
const eventType = typeof event === "string" ? event : event.type;
|
|
380
|
+
if (eventType === "jepa:update_weights") {
|
|
381
|
+
handleWeightUpdate(state, context, event);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (eventType !== "jepa:encode_pair") return;
|
|
385
|
+
state.step++;
|
|
386
|
+
const step = state.step;
|
|
387
|
+
const contextStr = readString(event.context);
|
|
388
|
+
if (!contextStr) {
|
|
389
|
+
emitError(context, { code: "JEPA_CONTEXT_REQUIRED", message: "jepa:encode_pair requires a non-empty context string", step });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const targetVec = toFloat32Array(event.targetVec);
|
|
393
|
+
if (!targetVec) {
|
|
394
|
+
emitError(context, { code: "JEPA_TARGET_VEC_REQUIRED", message: "jepa:encode_pair requires targetVec (Float32Array or number[])", step });
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (targetVec.length !== config.latentDim) {
|
|
398
|
+
emitError(context, {
|
|
399
|
+
code: "JEPA_TARGET_DIM_MISMATCH",
|
|
400
|
+
message: `targetVec.length=${targetVec.length} \u2260 latentDim=${config.latentDim}`,
|
|
401
|
+
step
|
|
402
|
+
});
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const contextEmb = encodeContext(state, config, contextStr);
|
|
406
|
+
if (!contextEmb) {
|
|
407
|
+
emitError(context, { code: "JEPA_ENCODE_FAILED", message: "Context encoding returned null vector", step });
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const conditioning = toFloat32ArrayOrNull(event.conditioning);
|
|
411
|
+
const { predicted } = state.predictor.forward(contextEmb, conditioning);
|
|
412
|
+
const predictionLoss = mseLoss(predicted, targetVec);
|
|
413
|
+
const sigregLoss = computeSIGReg(
|
|
414
|
+
predicted,
|
|
415
|
+
config.sigregProjections,
|
|
416
|
+
config.sigregSigma
|
|
417
|
+
);
|
|
418
|
+
const totalLoss = predictionLoss + config.sigregWeight * sigregLoss;
|
|
419
|
+
context.emit?.("jepa:loss", {
|
|
420
|
+
predictionLoss,
|
|
421
|
+
sigregLoss,
|
|
422
|
+
totalLoss,
|
|
423
|
+
step,
|
|
424
|
+
predicted
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
function encodeContext(state, config, contextStr) {
|
|
429
|
+
let result = null;
|
|
430
|
+
const captureContext = {
|
|
431
|
+
vr: null,
|
|
432
|
+
physics: null,
|
|
433
|
+
audio: null,
|
|
434
|
+
haptics: null,
|
|
435
|
+
emit(eventName, payload) {
|
|
436
|
+
if (eventName === "embedding:result") {
|
|
437
|
+
const p = payload;
|
|
438
|
+
const v = p.vector;
|
|
439
|
+
if (v instanceof Float32Array) result = v;
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
getState: () => ({}),
|
|
443
|
+
setState: () => {
|
|
444
|
+
},
|
|
445
|
+
getScaleMultiplier: () => 1,
|
|
446
|
+
setScaleContext: () => {
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
const mockNode = {};
|
|
450
|
+
embeddingHandler.onAttach?.(mockNode, state.embeddingConfig, captureContext);
|
|
451
|
+
embeddingHandler.onEvent?.(
|
|
452
|
+
mockNode,
|
|
453
|
+
state.embeddingConfig,
|
|
454
|
+
captureContext,
|
|
455
|
+
{
|
|
456
|
+
type: "embedding:generate",
|
|
457
|
+
input: contextStr,
|
|
458
|
+
model: config.embeddingModel,
|
|
459
|
+
dimensions: config.latentDim
|
|
460
|
+
}
|
|
461
|
+
);
|
|
462
|
+
embeddingHandler.onDetach?.(mockNode, state.embeddingConfig, captureContext);
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
465
|
+
function computeSIGReg(z, numProjections, sigma) {
|
|
466
|
+
const dim = z.length;
|
|
467
|
+
const sigmaSquared = sigma * sigma;
|
|
468
|
+
let total = 0;
|
|
469
|
+
let seed = 3405648436;
|
|
470
|
+
const lcg = () => {
|
|
471
|
+
seed = Math.imul(seed, 1664525) + 1013904223;
|
|
472
|
+
return (seed >>> 0) / 4294967296 * 2 - 1;
|
|
473
|
+
};
|
|
474
|
+
const gaussianPair = () => {
|
|
475
|
+
const u1 = Math.max(1e-12, (lcg() + 1) / 2);
|
|
476
|
+
const u2 = (lcg() + 1) / 2;
|
|
477
|
+
const r = Math.sqrt(-2 * Math.log(u1));
|
|
478
|
+
const theta = 2 * Math.PI * u2;
|
|
479
|
+
return [r * Math.cos(theta), r * Math.sin(theta)];
|
|
480
|
+
};
|
|
481
|
+
for (let p = 0; p < numProjections; p++) {
|
|
482
|
+
let dot = 0;
|
|
483
|
+
for (let i = 0; i < dim; i += 2) {
|
|
484
|
+
const [g1, g2] = gaussianPair();
|
|
485
|
+
const scale = 1 / Math.sqrt(dim);
|
|
486
|
+
dot += z[i] * (g1 * scale);
|
|
487
|
+
if (i + 1 < dim) dot += z[i + 1] * (g2 * scale);
|
|
488
|
+
}
|
|
489
|
+
const proj2 = dot * dot;
|
|
490
|
+
const ratio = proj2 / sigmaSquared;
|
|
491
|
+
if (ratio > 0) {
|
|
492
|
+
total += ratio - 1 - Math.log(ratio);
|
|
493
|
+
} else {
|
|
494
|
+
total += 1;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return total / numProjections;
|
|
498
|
+
}
|
|
499
|
+
function handleWeightUpdate(state, context, event) {
|
|
500
|
+
try {
|
|
501
|
+
state.predictor.setWeights({
|
|
502
|
+
W1: requireFloat32(event.W1, "W1"),
|
|
503
|
+
b1: requireFloat32(event.b1, "b1"),
|
|
504
|
+
W2: requireFloat32(event.W2, "W2"),
|
|
505
|
+
b2: requireFloat32(event.b2, "b2")
|
|
506
|
+
});
|
|
507
|
+
} catch (err) {
|
|
508
|
+
emitError(context, {
|
|
509
|
+
code: "JEPA_WEIGHTS_INVALID",
|
|
510
|
+
message: err instanceof Error ? err.message : String(err),
|
|
511
|
+
step: state.step
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function mseLoss(a, b) {
|
|
516
|
+
let sum = 0;
|
|
517
|
+
for (let i = 0; i < a.length; i++) {
|
|
518
|
+
const diff = a[i] - b[i];
|
|
519
|
+
sum += diff * diff;
|
|
520
|
+
}
|
|
521
|
+
return sum / a.length;
|
|
522
|
+
}
|
|
523
|
+
function emitError(context, payload) {
|
|
524
|
+
context.emit?.("jepa:error", payload);
|
|
525
|
+
}
|
|
526
|
+
function readString(value) {
|
|
527
|
+
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
528
|
+
}
|
|
529
|
+
function toFloat32Array(value) {
|
|
530
|
+
if (value instanceof Float32Array) return value;
|
|
531
|
+
if (Array.isArray(value) && value.every((v) => typeof v === "number")) {
|
|
532
|
+
return new Float32Array(value);
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
function toFloat32ArrayOrNull(value) {
|
|
537
|
+
if (value == null) return null;
|
|
538
|
+
return toFloat32Array(value);
|
|
539
|
+
}
|
|
540
|
+
function requireFloat32(value, name) {
|
|
541
|
+
if (value instanceof Float32Array) return value;
|
|
542
|
+
throw new TypeError(`jepa:update_weights: ${name} must be a Float32Array`);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// src/traits/OrbitalTrait.ts
|
|
546
|
+
var _orbital = null;
|
|
547
|
+
var orbitalHandler = {
|
|
548
|
+
name: "orbital",
|
|
549
|
+
defaultConfig: {},
|
|
550
|
+
/**
|
|
551
|
+
* Called when trait is attached to a node
|
|
552
|
+
*/
|
|
553
|
+
onAttach(node, _config, _context) {
|
|
554
|
+
chunkILRBGFVD_cjs.logger.info(`[OrbitalTrait] Attached to ${node.name}`);
|
|
555
|
+
},
|
|
556
|
+
/**
|
|
557
|
+
* Called every frame to update orbital position
|
|
558
|
+
*/
|
|
559
|
+
async onUpdate(node, config, context, _delta) {
|
|
560
|
+
const properties = node.properties || {};
|
|
561
|
+
const mergedConfig = { ...properties, ...config };
|
|
562
|
+
if (!mergedConfig || !mergedConfig.semiMajorAxis) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
_orbital ?? (_orbital = await import('@holoscript/engine/orbital'));
|
|
566
|
+
const { calculatePosition } = _orbital;
|
|
567
|
+
const julianDate = context.julianDate || 0;
|
|
568
|
+
const visualScale = context.getScaleMultiplier() * 50;
|
|
569
|
+
const satelliteScale = 5;
|
|
570
|
+
const rawPosition = calculatePosition(mergedConfig, julianDate);
|
|
571
|
+
const currentScale = mergedConfig.parent ? visualScale * satelliteScale : visualScale;
|
|
572
|
+
let finalPosition = [
|
|
573
|
+
rawPosition[0] * currentScale,
|
|
574
|
+
rawPosition[2] * currentScale,
|
|
575
|
+
rawPosition[1] * currentScale
|
|
576
|
+
];
|
|
577
|
+
if (mergedConfig.parent) {
|
|
578
|
+
let parentNode = context.getNode?.(mergedConfig.parent);
|
|
579
|
+
if (!parentNode && typeof mergedConfig.parent === "object" && mergedConfig.parent && mergedConfig.parent.position) {
|
|
580
|
+
parentNode = mergedConfig.parent;
|
|
581
|
+
}
|
|
582
|
+
if (parentNode && parentNode.position) {
|
|
583
|
+
finalPosition = [
|
|
584
|
+
finalPosition[0] + (parentNode.position[0] || 0),
|
|
585
|
+
finalPosition[1] + (parentNode.position[1] || 0),
|
|
586
|
+
finalPosition[2] + (parentNode.position[2] || 0)
|
|
587
|
+
];
|
|
588
|
+
} else {
|
|
589
|
+
if (typeof mergedConfig.parent === "string") {
|
|
590
|
+
chunkILRBGFVD_cjs.logger.warn(`[OrbitalTrait] Parent "${mergedConfig.parent}" not found for ${node.name}`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const posArray = [finalPosition[0], finalPosition[1], finalPosition[2]];
|
|
595
|
+
node.position = posArray;
|
|
596
|
+
context.emit("position_update", { position: posArray });
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
exports.JEPAPredictor = JEPAPredictor;
|
|
601
|
+
exports.embeddingHandler = embeddingHandler;
|
|
602
|
+
exports.jepObjectiveHandler = jepObjectiveHandler;
|
|
603
|
+
exports.mitosisHandler = mitosisHandler;
|
|
604
|
+
exports.orbitalHandler = orbitalHandler;
|
|
605
|
+
//# sourceMappingURL=chunk-TVHSPJ4N.cjs.map
|
|
606
|
+
//# sourceMappingURL=chunk-TVHSPJ4N.cjs.map
|