@holoscript/core 7.0.0 → 8.0.1
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 +4 -4
- package/bin/holoscript.cjs +3 -0
- package/dist/GLTFPipeline-N6B6PJ6G.cjs +38 -0
- package/dist/GLTFPipeline-P3WMNYCN.js +17 -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-CBYJX3LZ.js +10 -0
- package/dist/HoloScriptRuntime-VJ374RER.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-2BSMSUCE.js +1941 -0
- package/dist/chunk-2IWC4FP7.cjs +1189 -0
- package/dist/chunk-2M2DPHKB.js +762 -0
- package/dist/chunk-2X7NGX3M.js +2426 -0
- package/dist/chunk-2YSNA2F2.cjs +1274 -0
- package/dist/chunk-3FOKASKO.cjs +348 -0
- package/dist/chunk-3WZEJHUQ.cjs +116 -0
- package/dist/chunk-4C57PR42.js +468 -0
- package/dist/chunk-4GU5GCIY.js +1384 -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-4SDKXQ4C.js +811 -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-5H2G27PK.cjs +627 -0
- package/dist/chunk-5JEU52DW.js +382 -0
- package/dist/chunk-5NWINHR5.cjs +689 -0
- package/dist/chunk-5S7RKFGR.cjs +446 -0
- package/dist/chunk-5WUNN6ZN.cjs +428 -0
- package/dist/chunk-6CTRH7HT.cjs +1985 -0
- package/dist/chunk-6EX3I5P4.cjs +130 -0
- package/dist/chunk-6Q7RC2MK.cjs +1418 -0
- package/dist/chunk-7H33U5SM.cjs +413 -0
- package/dist/chunk-7M3PNU2M.cjs +672 -0
- package/dist/chunk-7T25IEZ2.js +449 -0
- package/dist/chunk-7V4JI5TB.cjs +6947 -0
- package/dist/chunk-A6KINLZJ.js +236 -0
- package/dist/chunk-ADADVMXY.js +404 -0
- package/dist/chunk-AIA52I7T.cjs +543 -0
- package/dist/chunk-ALC6K7GL.cjs +4402 -0
- package/dist/chunk-ANXZFVY2.js +113 -0
- package/dist/chunk-AOVGZ25K.cjs +56583 -0
- package/dist/chunk-AVJHHUC5.cjs +718 -0
- package/dist/chunk-BGY3SDG3.js +4396 -0
- package/dist/chunk-BOVPWH4H.js +3857 -0
- package/dist/chunk-BRQJKJGT.cjs +20 -0
- package/dist/chunk-C37BHB7N.cjs +636 -0
- package/dist/chunk-CBJY23VL.js +126 -0
- package/dist/chunk-CCATWPXM.js +778 -0
- package/dist/chunk-CIWWXYHZ.cjs +50 -0
- package/dist/chunk-CMT5NMMS.js +669 -0
- package/dist/chunk-CR4FMIWL.cjs +1049 -0
- package/dist/chunk-CR7XRXRN.cjs +639 -0
- package/dist/chunk-CSD27UNQ.js +2176 -0
- package/dist/chunk-D3STJ56J.js +714 -0
- package/dist/chunk-DAJXW4KX.js +725 -0
- package/dist/chunk-DHO2YRIM.js +756 -0
- package/dist/chunk-DTGBOSEM.cjs +319 -0
- package/dist/chunk-E6XXE66V.js +2252 -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-EXKSFGSX.cjs +274 -0
- package/dist/chunk-EXUP2BUM.cjs +1173 -0
- package/dist/chunk-FDSGHPAK.js +130 -0
- package/dist/chunk-FEWUHQNM.cjs +144 -0
- package/dist/chunk-FFAOS5HQ.js +70 -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-FL33V6U7.js +421 -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-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-HKEXJUWS.cjs +4007 -0
- package/dist/chunk-HNDK4IQU.cjs +5737 -0
- package/dist/chunk-HR2OSYVQ.js +56165 -0
- package/dist/chunk-HYNTS5CP.js +422 -0
- package/dist/chunk-I6XZ5DZF.cjs +488 -0
- package/dist/chunk-ILRBGFVD.cjs +72 -0
- package/dist/chunk-IUDGEUDO.cjs +1409 -0
- package/dist/chunk-IUTY5WQ2.cjs +424 -0
- package/dist/chunk-IVY74O6C.js +247 -0
- package/dist/chunk-IWC5DM2M.cjs +611 -0
- package/dist/chunk-J32ZJZJH.js +554 -0
- package/dist/chunk-J52VSAQ7.js +6884 -0
- package/dist/chunk-J6M4FPK5.js +421 -0
- package/dist/chunk-J7XZV333.js +844 -0
- package/dist/chunk-JBNDTXXV.cjs +2433 -0
- package/dist/chunk-JC5YBPSF.cjs +984 -0
- package/dist/chunk-JD7CIZ33.js +1949 -0
- package/dist/chunk-JIBL5LRK.js +4287 -0
- package/dist/chunk-JIYN45TV.cjs +2525 -0
- package/dist/chunk-K574J76X.cjs +457 -0
- package/dist/chunk-KHDZJE5D.cjs +2196 -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-L5LKKENW.cjs +424 -0
- package/dist/chunk-LHAXPADA.js +882 -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-MQWAT42R.cjs +4310 -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-NCWCUZNS.cjs +72 -0
- package/dist/chunk-NG77ATEW.cjs +778 -0
- package/dist/chunk-NW5G5FBQ.js +215 -0
- package/dist/chunk-OBIYPYYS.cjs +1993 -0
- package/dist/chunk-OH2FAIVU.js +608 -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-OSYNRVOV.cjs +243 -0
- package/dist/chunk-PGANYCAG.cjs +220 -0
- package/dist/chunk-PHENW4MQ.js +65 -0
- package/dist/chunk-PY37LNDP.js +686 -0
- package/dist/chunk-Q56TT7IL.js +483 -0
- package/dist/chunk-QD32ADK6.js +1046 -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-R24NNAEG.js +1399 -0
- package/dist/chunk-R75BSDH7.cjs +50 -0
- package/dist/chunk-RARB3MBR.js +207 -0
- package/dist/chunk-ROHLEP2W.cjs +847 -0
- package/dist/chunk-S3MDHNKB.cjs +490 -0
- package/dist/chunk-S6YWHCKV.cjs +410 -0
- package/dist/chunk-SIEXCILW.js +229 -0
- package/dist/chunk-SLU6UPJI.cjs +410 -0
- package/dist/chunk-SMIWS6DE.cjs +212 -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-TWUXUCEW.cjs +781 -0
- package/dist/chunk-U44IKGG7.cjs +5390 -0
- package/dist/chunk-UFZZ7TSN.cjs +886 -0
- package/dist/chunk-UJXISJBN.js +487 -0
- package/dist/chunk-UOIGFQXC.cjs +9750 -0
- package/dist/chunk-URG2SJLK.js +2521 -0
- package/dist/chunk-UWJHCOH2.js +623 -0
- package/dist/chunk-V6MKC2FZ.js +979 -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-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-X3UVCWNL.cjs +2257 -0
- package/dist/chunk-XB274MW5.cjs +814 -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-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-YN2YWTXW.js +5731 -0
- package/dist/chunk-YN6V7R3L.cjs +327 -0
- package/dist/chunk-YQELFNJV.js +39 -0
- package/dist/chunk-YVD3CSO3.js +1183 -0
- package/dist/chunk-YVOAF4ML.js +623 -0
- package/dist/chunk-YWOBW2PV.cjs +759 -0
- package/dist/chunk-YYXH45E2.js +426 -0
- package/dist/chunk-ZDSYWBIE.cjs +69 -0
- package/dist/chunk-ZU7NIRT6.js +325 -0
- package/dist/chunk-ZZ7RO2UQ.js +1243 -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 +609 -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 +5408 -0
- package/dist/compiler/index.d.ts +334 -21
- package/dist/compiler/index.js +5069 -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.d.ts +69 -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 +39 -0
- package/dist/compiler/r3f.d.ts +22 -0
- package/dist/compiler/r3f.js +17 -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/dist-ACXG6IH5.cjs +3113 -0
- package/dist/dist-VD4L6V7Q.js +3076 -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 +44660 -0
- package/dist/index.d.ts +978 -21
- package/dist/index.js +41422 -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/src-4ROC227P.cjs +2094 -0
- package/dist/src-HCCCSYP7.js +2073 -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 +177 -0
- package/dist/traits/botanical-lotus.d.ts +502 -0
- package/dist/traits/botanical-lotus.js +7 -0
- package/dist/traits/engines/index.cjs +520 -0
- package/dist/traits/engines/index.js +380 -0
- package/dist/traits/index.cjs +24548 -0
- package/dist/traits/index.d.ts +171 -35
- package/dist/traits/index.js +21638 -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,1259 @@
|
|
|
1
|
+
import '../chunk-OL46QLBJ.js';
|
|
2
|
+
|
|
3
|
+
// src/coordinators/AssetLoadCoordinator.ts
|
|
4
|
+
var ASSET_LOAD_EVENTS = [
|
|
5
|
+
// GLTF
|
|
6
|
+
"gltf:loaded",
|
|
7
|
+
"gltf:loading_progress",
|
|
8
|
+
"gltf:load_error",
|
|
9
|
+
"gltf:load_started",
|
|
10
|
+
// USD
|
|
11
|
+
"usd:loaded",
|
|
12
|
+
"usd:loading_progress",
|
|
13
|
+
"usd:load_error",
|
|
14
|
+
"usd:load_started",
|
|
15
|
+
// FBX
|
|
16
|
+
"fbx:loaded",
|
|
17
|
+
"fbx:loading_progress",
|
|
18
|
+
"fbx:load_error",
|
|
19
|
+
"fbx:load_started",
|
|
20
|
+
// Format-agnostic shared channel — all three traits ALSO emit these
|
|
21
|
+
// for cross-format observers that don't care about the source format.
|
|
22
|
+
"on_asset_loaded",
|
|
23
|
+
"on_asset_progress",
|
|
24
|
+
"on_asset_error"
|
|
25
|
+
];
|
|
26
|
+
var AssetLoadCoordinator = class {
|
|
27
|
+
constructor(source) {
|
|
28
|
+
this.states = /* @__PURE__ */ new Map();
|
|
29
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
30
|
+
for (const event of ASSET_LOAD_EVENTS) {
|
|
31
|
+
source.on(event, (payload) => this.handleEvent(event, payload));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
handleEvent(event, payload) {
|
|
35
|
+
if (!payload || typeof payload !== "object") return;
|
|
36
|
+
const p = payload;
|
|
37
|
+
const url = p.url ?? p.modelId ?? p.assetId;
|
|
38
|
+
if (!url || typeof url !== "string") return;
|
|
39
|
+
const format = this.formatFromEvent(event);
|
|
40
|
+
const phase = this.phaseFromEvent(event);
|
|
41
|
+
const existing = this.states.get(url);
|
|
42
|
+
const next = {
|
|
43
|
+
url,
|
|
44
|
+
format: existing?.format && existing.format !== "unknown" ? existing.format : format,
|
|
45
|
+
status: "idle",
|
|
46
|
+
progress: existing?.progress ?? 0,
|
|
47
|
+
updatedAt: Date.now()
|
|
48
|
+
};
|
|
49
|
+
if (phase === "started") {
|
|
50
|
+
next.status = "loading";
|
|
51
|
+
next.progress = 0;
|
|
52
|
+
} else if (phase === "progress") {
|
|
53
|
+
next.status = "loading";
|
|
54
|
+
const progressVal = p.progress;
|
|
55
|
+
if (typeof progressVal === "number" && progressVal >= 0 && progressVal <= 1) {
|
|
56
|
+
next.progress = progressVal;
|
|
57
|
+
}
|
|
58
|
+
} else if (phase === "loaded") {
|
|
59
|
+
next.status = "loaded";
|
|
60
|
+
next.progress = 1;
|
|
61
|
+
} else if (phase === "error") {
|
|
62
|
+
next.status = "error";
|
|
63
|
+
next.error = typeof p.error === "string" ? p.error : typeof p.message === "string" ? p.message : "unknown error";
|
|
64
|
+
}
|
|
65
|
+
this.states.set(url, next);
|
|
66
|
+
this.notifyListeners(next);
|
|
67
|
+
}
|
|
68
|
+
formatFromEvent(event) {
|
|
69
|
+
if (event.startsWith("gltf:")) return "gltf";
|
|
70
|
+
if (event.startsWith("usd:")) return "usd";
|
|
71
|
+
if (event.startsWith("fbx:")) return "fbx";
|
|
72
|
+
return "unknown";
|
|
73
|
+
}
|
|
74
|
+
phaseFromEvent(event) {
|
|
75
|
+
if (event.endsWith(":loaded") || event === "on_asset_loaded") return "loaded";
|
|
76
|
+
if (event.endsWith(":load_error") || event === "on_asset_error") return "error";
|
|
77
|
+
if (event.endsWith(":loading_progress") || event === "on_asset_progress") return "progress";
|
|
78
|
+
if (event.endsWith(":load_started")) return "started";
|
|
79
|
+
return "unknown";
|
|
80
|
+
}
|
|
81
|
+
notifyListeners(state) {
|
|
82
|
+
for (const listener of this.listeners) {
|
|
83
|
+
try {
|
|
84
|
+
listener(state);
|
|
85
|
+
} catch (_) {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Subscribe to all asset-state changes. Returns an unsubscribe function. */
|
|
90
|
+
subscribe(listener) {
|
|
91
|
+
this.listeners.add(listener);
|
|
92
|
+
return () => {
|
|
93
|
+
this.listeners.delete(listener);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Read the current state of one asset (or undefined if never seen). */
|
|
97
|
+
getAssetState(url) {
|
|
98
|
+
return this.states.get(url);
|
|
99
|
+
}
|
|
100
|
+
/** Read all tracked asset states (snapshot copy — safe to iterate). */
|
|
101
|
+
getAllStates() {
|
|
102
|
+
return Array.from(this.states.values());
|
|
103
|
+
}
|
|
104
|
+
/** Aggregate stats across all tracked assets. */
|
|
105
|
+
getStats() {
|
|
106
|
+
const all = Array.from(this.states.values());
|
|
107
|
+
const loading = all.filter((s) => s.status === "loading");
|
|
108
|
+
const loaded = all.filter((s) => s.status === "loaded");
|
|
109
|
+
const failed = all.filter((s) => s.status === "error");
|
|
110
|
+
const averageProgress = loading.length > 0 ? loading.reduce((sum, s) => sum + s.progress, 0) / loading.length : 0;
|
|
111
|
+
return {
|
|
112
|
+
total: all.length,
|
|
113
|
+
loading: loading.length,
|
|
114
|
+
loaded: loaded.length,
|
|
115
|
+
failed: failed.length,
|
|
116
|
+
averageProgress
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Clear all tracked state — typically called on scene change. */
|
|
120
|
+
reset() {
|
|
121
|
+
this.states.clear();
|
|
122
|
+
}
|
|
123
|
+
/** Number of distinct event types this coordinator subscribes to (diagnostic). */
|
|
124
|
+
get subscribedEventCount() {
|
|
125
|
+
return ASSET_LOAD_EVENTS.length;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/coordinators/SecurityEventBus.ts
|
|
130
|
+
var SECURITY_EVENTS = [
|
|
131
|
+
// --- RBAC (authz) ---
|
|
132
|
+
"rbac_initialized",
|
|
133
|
+
"rbac_error",
|
|
134
|
+
"rbac_role_assigned",
|
|
135
|
+
"rbac_role_revoked",
|
|
136
|
+
"rbac_permission_result",
|
|
137
|
+
"rbac_custom_role_created",
|
|
138
|
+
"rbac_custom_role_deleted",
|
|
139
|
+
"rbac_user_roles",
|
|
140
|
+
"rbac_access_log",
|
|
141
|
+
"rbac_capability_result",
|
|
142
|
+
"rbac_capability_granted",
|
|
143
|
+
"rbac_capability_revoked",
|
|
144
|
+
"rbac_tenant_changed",
|
|
145
|
+
"rbac_capability_delegated",
|
|
146
|
+
"rbac_tenant_id",
|
|
147
|
+
"rbac_agent_capabilities",
|
|
148
|
+
"rbac_sync_roles",
|
|
149
|
+
// --- SSO (auth) ---
|
|
150
|
+
"sso_initialized",
|
|
151
|
+
"sso_error",
|
|
152
|
+
"sso_session_revoked",
|
|
153
|
+
"sso_session_expired",
|
|
154
|
+
"sso_idp_registered",
|
|
155
|
+
"sso_idp_removed",
|
|
156
|
+
"sso_auth_error",
|
|
157
|
+
"sso_saml_authn_request",
|
|
158
|
+
"sso_oidc_auth_redirect",
|
|
159
|
+
"sso_user_provisioned",
|
|
160
|
+
"sso_authenticated",
|
|
161
|
+
"sso_global_logout",
|
|
162
|
+
"sso_saml_slo_request",
|
|
163
|
+
"sso_session_validation",
|
|
164
|
+
"sso_info",
|
|
165
|
+
// --- Quota ---
|
|
166
|
+
"quota_initialized",
|
|
167
|
+
"quota_error",
|
|
168
|
+
"quota_reset",
|
|
169
|
+
"quota_grace_expired",
|
|
170
|
+
"quota_grace_started",
|
|
171
|
+
"quota_exceeded",
|
|
172
|
+
"quota_threshold_reached",
|
|
173
|
+
"quota_consumed",
|
|
174
|
+
"quota_released",
|
|
175
|
+
"quota_limit_changed",
|
|
176
|
+
"quota_tier_applied",
|
|
177
|
+
"quota_info",
|
|
178
|
+
"quota_usage_report_result",
|
|
179
|
+
// --- Tenant ---
|
|
180
|
+
"tenant_provisioned",
|
|
181
|
+
"tenant_error",
|
|
182
|
+
"tenant_decommissioned",
|
|
183
|
+
"tenant_status_changed",
|
|
184
|
+
"tenant_trait_registered",
|
|
185
|
+
"tenant_trait_unregistered",
|
|
186
|
+
"tenant_tier_changed",
|
|
187
|
+
"tenant_info",
|
|
188
|
+
"cross_tenant_grant_created",
|
|
189
|
+
"cross_tenant_grant_revoked",
|
|
190
|
+
"cross_tenant_grant_denied",
|
|
191
|
+
"cross_tenant_grant_expired",
|
|
192
|
+
// --- AuditLog (cross-cutting) ---
|
|
193
|
+
"audit_log",
|
|
194
|
+
"audit_entry_created",
|
|
195
|
+
"audit_siem_notify",
|
|
196
|
+
"audit_critical_event",
|
|
197
|
+
"audit_query_result",
|
|
198
|
+
"audit_integrity_result",
|
|
199
|
+
"audit_stats_result",
|
|
200
|
+
"audit_export_result",
|
|
201
|
+
"audit_error",
|
|
202
|
+
// --- ForgetPolicy ---
|
|
203
|
+
"forget_policy_attached",
|
|
204
|
+
"forget_policy_detached",
|
|
205
|
+
"forget_evaluate",
|
|
206
|
+
"forget_audit_entry",
|
|
207
|
+
"forget_apply",
|
|
208
|
+
"forget_audit_log",
|
|
209
|
+
"forget_error"
|
|
210
|
+
];
|
|
211
|
+
var DEFAULT_AUDIT_BUFFER_SIZE = 256;
|
|
212
|
+
var SecurityEventBus = class {
|
|
213
|
+
constructor(source, auditBufferSize = DEFAULT_AUDIT_BUFFER_SIZE) {
|
|
214
|
+
this.sessions = /* @__PURE__ */ new Map();
|
|
215
|
+
this.agents = /* @__PURE__ */ new Map();
|
|
216
|
+
this.quotas = /* @__PURE__ */ new Map();
|
|
217
|
+
// key = `${resource}:${subject}`
|
|
218
|
+
this.tenants = /* @__PURE__ */ new Map();
|
|
219
|
+
this.auditLog = [];
|
|
220
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
221
|
+
this.auditBufferSize = Math.max(0, Math.floor(auditBufferSize));
|
|
222
|
+
for (const event of SECURITY_EVENTS) {
|
|
223
|
+
source.on(event, (payload) => this.handleEvent(event, payload));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// ---- Event ingestion ---------------------------------------------------
|
|
227
|
+
handleEvent(event, payload) {
|
|
228
|
+
const domain = this.domainFromEvent(event);
|
|
229
|
+
const observedAt = Date.now();
|
|
230
|
+
if (domain === "auth") this.applyAuthEvent(event, payload, observedAt);
|
|
231
|
+
else if (domain === "authz") this.applyAuthzEvent(event, payload, observedAt);
|
|
232
|
+
else if (domain === "quota") this.applyQuotaEvent(event, payload, observedAt);
|
|
233
|
+
else if (domain === "tenant") this.applyTenantEvent(event, payload, observedAt);
|
|
234
|
+
if (domain === "audit" || event === "audit_log" || event === "forget_audit_log" || event === "forget_audit_entry") {
|
|
235
|
+
this.appendAudit(event, payload, observedAt);
|
|
236
|
+
}
|
|
237
|
+
this.notifyListeners({ domain, event, payload, observedAt });
|
|
238
|
+
}
|
|
239
|
+
domainFromEvent(event) {
|
|
240
|
+
if (event.startsWith("sso_")) return "auth";
|
|
241
|
+
if (event.startsWith("rbac_")) return "authz";
|
|
242
|
+
if (event.startsWith("quota_")) return "quota";
|
|
243
|
+
if (event.startsWith("tenant_") || event.startsWith("cross_tenant_")) return "tenant";
|
|
244
|
+
if (event.startsWith("audit_")) return "audit";
|
|
245
|
+
if (event.startsWith("forget_")) return "forget";
|
|
246
|
+
return "unknown";
|
|
247
|
+
}
|
|
248
|
+
applyAuthEvent(event, payload, observedAt) {
|
|
249
|
+
if (!payload || typeof payload !== "object") return;
|
|
250
|
+
const p = payload;
|
|
251
|
+
const sessionId = p.sessionId ?? p.sid;
|
|
252
|
+
if (!sessionId || typeof sessionId !== "string") return;
|
|
253
|
+
const existing = this.sessions.get(sessionId);
|
|
254
|
+
let status = null;
|
|
255
|
+
if (event === "sso_authenticated") status = "authenticated";
|
|
256
|
+
else if (event === "sso_session_expired") status = "expired";
|
|
257
|
+
else if (event === "sso_session_revoked" || event === "sso_global_logout") status = "revoked";
|
|
258
|
+
if (status === null) return;
|
|
259
|
+
const next = {
|
|
260
|
+
sessionId,
|
|
261
|
+
status,
|
|
262
|
+
idp: typeof p.idp === "string" ? p.idp : existing?.idp,
|
|
263
|
+
userId: typeof p.userId === "string" ? p.userId : existing?.userId,
|
|
264
|
+
updatedAt: observedAt
|
|
265
|
+
};
|
|
266
|
+
this.sessions.set(sessionId, next);
|
|
267
|
+
}
|
|
268
|
+
applyAuthzEvent(event, payload, observedAt) {
|
|
269
|
+
if (!payload || typeof payload !== "object") return;
|
|
270
|
+
const p = payload;
|
|
271
|
+
const agentId = p.agentId ?? p.userId ?? p.subject;
|
|
272
|
+
if (!agentId || typeof agentId !== "string") return;
|
|
273
|
+
const existing = this.agents.get(agentId) ?? {
|
|
274
|
+
roles: /* @__PURE__ */ new Set(),
|
|
275
|
+
capabilities: /* @__PURE__ */ new Set()};
|
|
276
|
+
const roles = new Set(existing.roles);
|
|
277
|
+
const capabilities = new Set(existing.capabilities);
|
|
278
|
+
let tenantId = existing.tenantId;
|
|
279
|
+
if (event === "rbac_role_assigned" && typeof p.role === "string") roles.add(p.role);
|
|
280
|
+
else if (event === "rbac_role_revoked" && typeof p.role === "string") roles.delete(p.role);
|
|
281
|
+
else if (event === "rbac_capability_granted" && typeof p.capability === "string") capabilities.add(p.capability);
|
|
282
|
+
else if (event === "rbac_capability_revoked" && typeof p.capability === "string") capabilities.delete(p.capability);
|
|
283
|
+
else if (event === "rbac_tenant_changed" && typeof p.tenantId === "string") tenantId = p.tenantId;
|
|
284
|
+
else if (event === "rbac_user_roles" && Array.isArray(p.roles)) {
|
|
285
|
+
roles.clear();
|
|
286
|
+
for (const r of p.roles) if (typeof r === "string") roles.add(r);
|
|
287
|
+
} else if (event === "rbac_agent_capabilities" && Array.isArray(p.capabilities)) {
|
|
288
|
+
capabilities.clear();
|
|
289
|
+
for (const c of p.capabilities) if (typeof c === "string") capabilities.add(c);
|
|
290
|
+
} else {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
this.agents.set(agentId, { agentId, tenantId, roles, capabilities, updatedAt: observedAt });
|
|
294
|
+
}
|
|
295
|
+
applyQuotaEvent(event, payload, observedAt) {
|
|
296
|
+
if (!payload || typeof payload !== "object") return;
|
|
297
|
+
const p = payload;
|
|
298
|
+
const resource = typeof p.resource === "string" ? p.resource : void 0;
|
|
299
|
+
const subject = typeof p.tenantId === "string" && p.tenantId || typeof p.agentId === "string" && p.agentId || typeof p.subject === "string" && p.subject || void 0;
|
|
300
|
+
if (!resource || !subject) return;
|
|
301
|
+
const key = `${resource}:${subject}`;
|
|
302
|
+
const existing = this.quotas.get(key) ?? {
|
|
303
|
+
consumed: 0,
|
|
304
|
+
limit: 0,
|
|
305
|
+
status: "ok"};
|
|
306
|
+
let status = existing.status;
|
|
307
|
+
let consumed = existing.consumed;
|
|
308
|
+
let limit = existing.limit;
|
|
309
|
+
if (typeof p.consumed === "number") consumed = p.consumed;
|
|
310
|
+
if (typeof p.limit === "number") limit = p.limit;
|
|
311
|
+
if (event === "quota_exceeded") status = "exceeded";
|
|
312
|
+
else if (event === "quota_grace_started") status = "grace";
|
|
313
|
+
else if (event === "quota_grace_expired") status = "exceeded";
|
|
314
|
+
else if (event === "quota_threshold_reached") status = "threshold_reached";
|
|
315
|
+
else if (event === "quota_reset" || event === "quota_released" || event === "quota_consumed") {
|
|
316
|
+
if (limit > 0 && consumed >= limit) status = "exceeded";
|
|
317
|
+
else if (limit > 0 && consumed >= limit * 0.9) status = "threshold_reached";
|
|
318
|
+
else status = "ok";
|
|
319
|
+
}
|
|
320
|
+
this.quotas.set(key, { resource, subject, consumed, limit, status, updatedAt: observedAt });
|
|
321
|
+
}
|
|
322
|
+
applyTenantEvent(event, payload, observedAt) {
|
|
323
|
+
if (!payload || typeof payload !== "object") return;
|
|
324
|
+
const p = payload;
|
|
325
|
+
const tenantId = typeof p.tenantId === "string" ? p.tenantId : void 0;
|
|
326
|
+
if (!tenantId) return;
|
|
327
|
+
const existing = this.tenants.get(tenantId);
|
|
328
|
+
let status = existing?.status;
|
|
329
|
+
let tier = existing?.tier;
|
|
330
|
+
if (event === "tenant_provisioned") status = "provisioned";
|
|
331
|
+
else if (event === "tenant_decommissioned") status = "decommissioned";
|
|
332
|
+
else if (event === "tenant_status_changed" && typeof p.status === "string") {
|
|
333
|
+
const s = p.status;
|
|
334
|
+
if (s === "active" || s === "suspended" || s === "provisioned" || s === "decommissioned") status = s;
|
|
335
|
+
} else if (event === "tenant_tier_changed" && typeof p.tier === "string") {
|
|
336
|
+
tier = p.tier;
|
|
337
|
+
} else {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (!status) return;
|
|
341
|
+
this.tenants.set(tenantId, { tenantId, status, tier, updatedAt: observedAt });
|
|
342
|
+
}
|
|
343
|
+
appendAudit(event, payload, observedAt) {
|
|
344
|
+
if (this.auditBufferSize === 0) return;
|
|
345
|
+
const p = payload && typeof payload === "object" ? payload : {};
|
|
346
|
+
const entry = {
|
|
347
|
+
event,
|
|
348
|
+
action: typeof p.action === "string" ? p.action : void 0,
|
|
349
|
+
actor: typeof p.actor === "string" && p.actor || typeof p.agentId === "string" && p.agentId || typeof p.userId === "string" && p.userId || void 0,
|
|
350
|
+
tenantId: typeof p.tenantId === "string" ? p.tenantId : void 0,
|
|
351
|
+
outcome: p.outcome === "success" || p.outcome === "denied" || p.outcome === "error" ? p.outcome : void 0,
|
|
352
|
+
observedAt
|
|
353
|
+
};
|
|
354
|
+
this.auditLog.push(entry);
|
|
355
|
+
if (this.auditLog.length > this.auditBufferSize) {
|
|
356
|
+
this.auditLog.splice(0, this.auditLog.length - this.auditBufferSize);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
notifyListeners(envelope) {
|
|
360
|
+
for (const listener of this.listeners) {
|
|
361
|
+
try {
|
|
362
|
+
listener(envelope);
|
|
363
|
+
} catch (_) {
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// ---- Public API --------------------------------------------------------
|
|
368
|
+
/** Subscribe to all security events. Returns an unsubscribe function. */
|
|
369
|
+
subscribe(listener) {
|
|
370
|
+
this.listeners.add(listener);
|
|
371
|
+
return () => {
|
|
372
|
+
this.listeners.delete(listener);
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
getSession(sessionId) {
|
|
376
|
+
return this.sessions.get(sessionId);
|
|
377
|
+
}
|
|
378
|
+
getAllSessions() {
|
|
379
|
+
return Array.from(this.sessions.values());
|
|
380
|
+
}
|
|
381
|
+
getAgent(agentId) {
|
|
382
|
+
const a = this.agents.get(agentId);
|
|
383
|
+
if (!a) return void 0;
|
|
384
|
+
return { ...a, roles: new Set(a.roles), capabilities: new Set(a.capabilities) };
|
|
385
|
+
}
|
|
386
|
+
getAllAgents() {
|
|
387
|
+
return Array.from(this.agents.values()).map((a) => ({
|
|
388
|
+
...a,
|
|
389
|
+
roles: new Set(a.roles),
|
|
390
|
+
capabilities: new Set(a.capabilities)
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
getQuota(resource, subject) {
|
|
394
|
+
return this.quotas.get(`${resource}:${subject}`);
|
|
395
|
+
}
|
|
396
|
+
getAllQuotas() {
|
|
397
|
+
return Array.from(this.quotas.values());
|
|
398
|
+
}
|
|
399
|
+
getTenant(tenantId) {
|
|
400
|
+
return this.tenants.get(tenantId);
|
|
401
|
+
}
|
|
402
|
+
getAllTenants() {
|
|
403
|
+
return Array.from(this.tenants.values());
|
|
404
|
+
}
|
|
405
|
+
/** Snapshot of the rolling audit-log buffer (oldest first). */
|
|
406
|
+
getAuditLog() {
|
|
407
|
+
return this.auditLog.slice();
|
|
408
|
+
}
|
|
409
|
+
getStats() {
|
|
410
|
+
const sessions = Array.from(this.sessions.values());
|
|
411
|
+
const tenants = Array.from(this.tenants.values());
|
|
412
|
+
const quotas = Array.from(this.quotas.values());
|
|
413
|
+
return {
|
|
414
|
+
sessions: {
|
|
415
|
+
authenticated: sessions.filter((s) => s.status === "authenticated").length,
|
|
416
|
+
expired: sessions.filter((s) => s.status === "expired").length,
|
|
417
|
+
revoked: sessions.filter((s) => s.status === "revoked").length
|
|
418
|
+
},
|
|
419
|
+
agents: { tracked: this.agents.size },
|
|
420
|
+
tenants: {
|
|
421
|
+
active: tenants.filter((t) => t.status === "active" || t.status === "provisioned").length,
|
|
422
|
+
suspended: tenants.filter((t) => t.status === "suspended").length,
|
|
423
|
+
decommissioned: tenants.filter((t) => t.status === "decommissioned").length
|
|
424
|
+
},
|
|
425
|
+
quotas: {
|
|
426
|
+
tracked: quotas.length,
|
|
427
|
+
exceeded: quotas.filter((q) => q.status === "exceeded").length,
|
|
428
|
+
grace: quotas.filter((q) => q.status === "grace").length
|
|
429
|
+
},
|
|
430
|
+
auditLog: { entries: this.auditLog.length, capacity: this.auditBufferSize }
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/** Clear all tracked state — typically called on tenant teardown or test reset. */
|
|
434
|
+
reset() {
|
|
435
|
+
this.sessions.clear();
|
|
436
|
+
this.agents.clear();
|
|
437
|
+
this.quotas.clear();
|
|
438
|
+
this.tenants.clear();
|
|
439
|
+
this.auditLog = [];
|
|
440
|
+
}
|
|
441
|
+
/** Number of distinct event types this bus subscribes to (diagnostic). */
|
|
442
|
+
get subscribedEventCount() {
|
|
443
|
+
return SECURITY_EVENTS.length;
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/coordinators/GenerativeJobMonitor.ts
|
|
448
|
+
var GENERATIVE_JOB_EVENTS = [
|
|
449
|
+
// --- AiInpainting ---
|
|
450
|
+
"inpainting:ready",
|
|
451
|
+
"inpainting:cancelled",
|
|
452
|
+
"inpainting:mask_set",
|
|
453
|
+
"inpainting:started",
|
|
454
|
+
"inpainting:result",
|
|
455
|
+
"inpainting:original_restored",
|
|
456
|
+
"inpainting:error",
|
|
457
|
+
// --- AiTextureGen ---
|
|
458
|
+
"texture_gen:ready",
|
|
459
|
+
"texture_gen:cancelled",
|
|
460
|
+
"texture_gen:queued",
|
|
461
|
+
"texture_gen:started",
|
|
462
|
+
"texture_gen:applied",
|
|
463
|
+
// --- ControlNet ---
|
|
464
|
+
"controlnet:ready",
|
|
465
|
+
"controlnet:cancelled",
|
|
466
|
+
"controlnet:started",
|
|
467
|
+
"controlnet:result",
|
|
468
|
+
"controlnet:error",
|
|
469
|
+
"controlnet:map_requested",
|
|
470
|
+
// --- DiffusionRealtime ---
|
|
471
|
+
"diffusion_rt:ready",
|
|
472
|
+
"diffusion_rt:stopped",
|
|
473
|
+
"diffusion_rt:started",
|
|
474
|
+
"diffusion_rt:frame_ready",
|
|
475
|
+
"diffusion_rt:prompt_updated"
|
|
476
|
+
];
|
|
477
|
+
var KIND_PREFIXES = [
|
|
478
|
+
["inpainting:", "inpainting"],
|
|
479
|
+
["texture_gen:", "texture_gen"],
|
|
480
|
+
["controlnet:", "controlnet"],
|
|
481
|
+
["diffusion_rt:", "diffusion_rt"]
|
|
482
|
+
];
|
|
483
|
+
var GenerativeJobMonitor = class {
|
|
484
|
+
constructor(source) {
|
|
485
|
+
this.jobs = /* @__PURE__ */ new Map();
|
|
486
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
487
|
+
/** Tracks which trait kinds have fired their `<kind>:ready` event. */
|
|
488
|
+
this.readyKinds = /* @__PURE__ */ new Set();
|
|
489
|
+
for (const event of GENERATIVE_JOB_EVENTS) {
|
|
490
|
+
source.on(event, (payload) => this.handleEvent(event, payload));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
// ---- Event ingestion ---------------------------------------------------
|
|
494
|
+
handleEvent(event, payload) {
|
|
495
|
+
const kind = this.kindFromEvent(event);
|
|
496
|
+
if (!kind) return;
|
|
497
|
+
const phase = this.phaseFromEvent(event);
|
|
498
|
+
const observedAt = Date.now();
|
|
499
|
+
if (phase === "ready") {
|
|
500
|
+
this.readyKinds.add(kind);
|
|
501
|
+
this.notifyListeners({
|
|
502
|
+
jobId: `__ready:${kind}`,
|
|
503
|
+
kind,
|
|
504
|
+
status: "completed",
|
|
505
|
+
startedAt: observedAt,
|
|
506
|
+
updatedAt: observedAt
|
|
507
|
+
});
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (phase === "config") return;
|
|
511
|
+
if (!payload || typeof payload !== "object") return;
|
|
512
|
+
const p = payload;
|
|
513
|
+
const jobId = this.jobIdFromPayload(p, kind);
|
|
514
|
+
if (!jobId) return;
|
|
515
|
+
const existing = this.jobs.get(jobId);
|
|
516
|
+
const startedAt = existing?.startedAt ?? observedAt;
|
|
517
|
+
let status = null;
|
|
518
|
+
let durationMs = existing?.durationMs;
|
|
519
|
+
let error = existing?.error;
|
|
520
|
+
if (phase === "queued") {
|
|
521
|
+
status = "queued";
|
|
522
|
+
} else if (phase === "started") {
|
|
523
|
+
status = "running";
|
|
524
|
+
} else if (phase === "success") {
|
|
525
|
+
status = "completed";
|
|
526
|
+
durationMs = observedAt - startedAt;
|
|
527
|
+
} else if (phase === "cancelled") {
|
|
528
|
+
status = "cancelled";
|
|
529
|
+
durationMs = observedAt - startedAt;
|
|
530
|
+
} else if (phase === "error") {
|
|
531
|
+
status = "errored";
|
|
532
|
+
durationMs = observedAt - startedAt;
|
|
533
|
+
error = typeof p.error === "string" ? p.error : typeof p.message === "string" ? p.message : "unknown error";
|
|
534
|
+
}
|
|
535
|
+
if (status === null) return;
|
|
536
|
+
const next = {
|
|
537
|
+
jobId,
|
|
538
|
+
kind,
|
|
539
|
+
status,
|
|
540
|
+
startedAt,
|
|
541
|
+
updatedAt: observedAt,
|
|
542
|
+
durationMs,
|
|
543
|
+
error
|
|
544
|
+
};
|
|
545
|
+
this.jobs.set(jobId, next);
|
|
546
|
+
this.notifyListeners(next);
|
|
547
|
+
}
|
|
548
|
+
kindFromEvent(event) {
|
|
549
|
+
for (const [prefix, kind] of KIND_PREFIXES) {
|
|
550
|
+
if (event.startsWith(prefix)) return kind;
|
|
551
|
+
}
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
phaseFromEvent(event) {
|
|
555
|
+
const suffix = event.slice(event.indexOf(":") + 1);
|
|
556
|
+
if (suffix === "ready") return "ready";
|
|
557
|
+
if (suffix === "queued") return "queued";
|
|
558
|
+
if (suffix === "started") return "started";
|
|
559
|
+
if (suffix === "result" || suffix === "applied" || suffix === "original_restored" || suffix === "frame_ready")
|
|
560
|
+
return "success";
|
|
561
|
+
if (suffix === "cancelled" || suffix === "stopped") return "cancelled";
|
|
562
|
+
if (suffix === "error") return "error";
|
|
563
|
+
if (suffix === "mask_set" || suffix === "map_requested" || suffix === "prompt_updated") return "config";
|
|
564
|
+
return "unknown";
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Resolve the stable job ID from a payload, falling back across the
|
|
568
|
+
* fields each trait happens to use. Mirrors the heuristic in
|
|
569
|
+
* AssetLoadCoordinator.handleEvent.
|
|
570
|
+
*/
|
|
571
|
+
jobIdFromPayload(p, kind) {
|
|
572
|
+
if (kind === "diffusion_rt" && typeof p.frameNumber === "number") {
|
|
573
|
+
const sid = typeof p.sessionId === "string" ? p.sessionId : "rt";
|
|
574
|
+
return `${sid}:${p.frameNumber}`;
|
|
575
|
+
}
|
|
576
|
+
const candidates = [p.requestId, p.jobId, p.textureId, p.sessionId, p.nodeId, p.id];
|
|
577
|
+
for (const c of candidates) {
|
|
578
|
+
if (typeof c === "string" && c.length > 0) return c;
|
|
579
|
+
}
|
|
580
|
+
return void 0;
|
|
581
|
+
}
|
|
582
|
+
notifyListeners(state) {
|
|
583
|
+
for (const listener of this.listeners) {
|
|
584
|
+
try {
|
|
585
|
+
listener(state);
|
|
586
|
+
} catch (_) {
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
// ---- Public API --------------------------------------------------------
|
|
591
|
+
/** Subscribe to all job-state changes. Returns an unsubscribe function. */
|
|
592
|
+
subscribe(listener) {
|
|
593
|
+
this.listeners.add(listener);
|
|
594
|
+
return () => {
|
|
595
|
+
this.listeners.delete(listener);
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
getJob(jobId) {
|
|
599
|
+
return this.jobs.get(jobId);
|
|
600
|
+
}
|
|
601
|
+
getAllJobs() {
|
|
602
|
+
return Array.from(this.jobs.values());
|
|
603
|
+
}
|
|
604
|
+
getJobsByKind(kind) {
|
|
605
|
+
return Array.from(this.jobs.values()).filter((j) => j.kind === kind);
|
|
606
|
+
}
|
|
607
|
+
isReady(kind) {
|
|
608
|
+
return this.readyKinds.has(kind);
|
|
609
|
+
}
|
|
610
|
+
getStats() {
|
|
611
|
+
const empty = () => ({
|
|
612
|
+
queued: 0,
|
|
613
|
+
running: 0,
|
|
614
|
+
completed: 0,
|
|
615
|
+
cancelled: 0,
|
|
616
|
+
errored: 0,
|
|
617
|
+
meanLatencyMs: 0
|
|
618
|
+
});
|
|
619
|
+
const byKind = {
|
|
620
|
+
inpainting: empty(),
|
|
621
|
+
texture_gen: empty(),
|
|
622
|
+
controlnet: empty(),
|
|
623
|
+
diffusion_rt: empty()
|
|
624
|
+
};
|
|
625
|
+
const latencyTotals = {
|
|
626
|
+
inpainting: { sum: 0, count: 0 },
|
|
627
|
+
texture_gen: { sum: 0, count: 0 },
|
|
628
|
+
controlnet: { sum: 0, count: 0 },
|
|
629
|
+
diffusion_rt: { sum: 0, count: 0 }
|
|
630
|
+
};
|
|
631
|
+
for (const job of this.jobs.values()) {
|
|
632
|
+
const stats = byKind[job.kind];
|
|
633
|
+
if (job.status === "queued") stats.queued++;
|
|
634
|
+
else if (job.status === "running") stats.running++;
|
|
635
|
+
else if (job.status === "completed") {
|
|
636
|
+
stats.completed++;
|
|
637
|
+
if (typeof job.durationMs === "number") {
|
|
638
|
+
latencyTotals[job.kind].sum += job.durationMs;
|
|
639
|
+
latencyTotals[job.kind].count++;
|
|
640
|
+
}
|
|
641
|
+
} else if (job.status === "cancelled") stats.cancelled++;
|
|
642
|
+
else if (job.status === "errored") stats.errored++;
|
|
643
|
+
}
|
|
644
|
+
for (const k of Object.keys(byKind)) {
|
|
645
|
+
const t = latencyTotals[k];
|
|
646
|
+
byKind[k].meanLatencyMs = t.count > 0 ? t.sum / t.count : 0;
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
total: this.jobs.size,
|
|
650
|
+
byKind,
|
|
651
|
+
anyReady: this.readyKinds.size > 0
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
/** Clear all tracked jobs — typically called on scene change. */
|
|
655
|
+
reset() {
|
|
656
|
+
this.jobs.clear();
|
|
657
|
+
this.readyKinds.clear();
|
|
658
|
+
}
|
|
659
|
+
/** Number of distinct event types this monitor subscribes to (diagnostic). */
|
|
660
|
+
get subscribedEventCount() {
|
|
661
|
+
return GENERATIVE_JOB_EVENTS.length;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
// src/coordinators/SessionPresenceCoordinator.ts
|
|
666
|
+
var PRESENCE_EVENTS = [
|
|
667
|
+
// --- SharePlay ---
|
|
668
|
+
"shareplay:ready",
|
|
669
|
+
"shareplay:ended",
|
|
670
|
+
"shareplay:started",
|
|
671
|
+
"shareplay:joined",
|
|
672
|
+
"shareplay:participant_joined",
|
|
673
|
+
"shareplay:participant_left",
|
|
674
|
+
"shareplay:state_synced",
|
|
675
|
+
// --- SpatialVoice ---
|
|
676
|
+
"spatial_voice_create",
|
|
677
|
+
"spatial_voice_destroy",
|
|
678
|
+
"spatial_voice_position",
|
|
679
|
+
"spatial_voice_peer_joined",
|
|
680
|
+
"spatial_voice_peer_left",
|
|
681
|
+
"spatial_voice_muted",
|
|
682
|
+
"spatial_voice_unmuted",
|
|
683
|
+
"on_voice_activity",
|
|
684
|
+
// --- Messaging ---
|
|
685
|
+
"messaging_connected",
|
|
686
|
+
"messaging_disconnected",
|
|
687
|
+
"messaging_error",
|
|
688
|
+
"messaging_stats",
|
|
689
|
+
"message_received",
|
|
690
|
+
"message_sent",
|
|
691
|
+
"command_parsed",
|
|
692
|
+
// (`command_<name>` events are dynamic — not subscribed here. Consumers
|
|
693
|
+
// that care about specific commands subscribe directly through the
|
|
694
|
+
// event source.)
|
|
695
|
+
// --- WorldHeartbeat ---
|
|
696
|
+
"heartbeat_initialized",
|
|
697
|
+
"heartbeat_tick",
|
|
698
|
+
"heartbeat_failover",
|
|
699
|
+
"heartbeat_error"
|
|
700
|
+
];
|
|
701
|
+
var SessionPresenceCoordinator = class {
|
|
702
|
+
constructor(source) {
|
|
703
|
+
this.sessions = /* @__PURE__ */ new Map();
|
|
704
|
+
this.voice = /* @__PURE__ */ new Map();
|
|
705
|
+
this.messaging = /* @__PURE__ */ new Map();
|
|
706
|
+
this.heartbeats = /* @__PURE__ */ new Map();
|
|
707
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
708
|
+
for (const event of PRESENCE_EVENTS) {
|
|
709
|
+
source.on(event, (payload) => this.handleEvent(event, payload));
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
// ---- Event ingestion ---------------------------------------------------
|
|
713
|
+
handleEvent(event, payload) {
|
|
714
|
+
const domain = this.domainFromEvent(event);
|
|
715
|
+
const observedAt = Date.now();
|
|
716
|
+
if (domain === "shareplay") this.applySharePlayEvent(event, payload, observedAt);
|
|
717
|
+
else if (domain === "voice") this.applyVoiceEvent(event, payload, observedAt);
|
|
718
|
+
else if (domain === "messaging") this.applyMessagingEvent(event, payload, observedAt);
|
|
719
|
+
else if (domain === "heartbeat") this.applyHeartbeatEvent(event, payload, observedAt);
|
|
720
|
+
this.notifyListeners({ domain, event, payload, observedAt });
|
|
721
|
+
}
|
|
722
|
+
domainFromEvent(event) {
|
|
723
|
+
if (event.startsWith("shareplay:")) return "shareplay";
|
|
724
|
+
if (event.startsWith("spatial_voice_") || event === "on_voice_activity") return "voice";
|
|
725
|
+
if (event.startsWith("messaging_") || event === "message_received" || event === "message_sent" || event === "command_parsed")
|
|
726
|
+
return "messaging";
|
|
727
|
+
if (event.startsWith("heartbeat_")) return "heartbeat";
|
|
728
|
+
return "unknown";
|
|
729
|
+
}
|
|
730
|
+
// ---- SharePlay ---------------------------------------------------------
|
|
731
|
+
applySharePlayEvent(event, payload, observedAt) {
|
|
732
|
+
if (!payload || typeof payload !== "object") return;
|
|
733
|
+
const p = payload;
|
|
734
|
+
if (event === "shareplay:ready") return;
|
|
735
|
+
const sessionId = typeof p.sessionId === "string" ? p.sessionId : void 0;
|
|
736
|
+
if (!sessionId) return;
|
|
737
|
+
const existing = this.sessions.get(sessionId);
|
|
738
|
+
const participants = new Set(existing?.participants ?? []);
|
|
739
|
+
let status = existing?.status ?? "idle";
|
|
740
|
+
if (event === "shareplay:started") status = "started";
|
|
741
|
+
else if (event === "shareplay:joined") status = "joined";
|
|
742
|
+
else if (event === "shareplay:ended") status = "ended";
|
|
743
|
+
else if (event === "shareplay:participant_joined") {
|
|
744
|
+
const pid = typeof p.participantId === "string" ? p.participantId : void 0;
|
|
745
|
+
if (pid) participants.add(pid);
|
|
746
|
+
} else if (event === "shareplay:participant_left") {
|
|
747
|
+
const pid = typeof p.participantId === "string" ? p.participantId : void 0;
|
|
748
|
+
if (pid) participants.delete(pid);
|
|
749
|
+
}
|
|
750
|
+
this.sessions.set(sessionId, {
|
|
751
|
+
sessionId,
|
|
752
|
+
status,
|
|
753
|
+
participants,
|
|
754
|
+
activityTitle: existing?.activityTitle,
|
|
755
|
+
updatedAt: observedAt
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
// ---- SpatialVoice ------------------------------------------------------
|
|
759
|
+
applyVoiceEvent(event, payload, observedAt) {
|
|
760
|
+
if (!payload || typeof payload !== "object") return;
|
|
761
|
+
const p = payload;
|
|
762
|
+
const nodeId = typeof p.nodeId === "string" ? p.nodeId : void 0;
|
|
763
|
+
if (event === "spatial_voice_create" && nodeId) {
|
|
764
|
+
this.voice.set(nodeId, {
|
|
765
|
+
nodeId,
|
|
766
|
+
peers: /* @__PURE__ */ new Set(),
|
|
767
|
+
muted: false,
|
|
768
|
+
lastVoiceActivityAt: 0,
|
|
769
|
+
updatedAt: observedAt
|
|
770
|
+
});
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (event === "spatial_voice_destroy" && nodeId) {
|
|
774
|
+
this.voice.delete(nodeId);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (event === "spatial_voice_peer_joined" && nodeId) {
|
|
778
|
+
const peerId = typeof p.peerId === "string" ? p.peerId : void 0;
|
|
779
|
+
const existing = this.voice.get(nodeId);
|
|
780
|
+
if (!existing || !peerId) return;
|
|
781
|
+
const peers = new Set(existing.peers);
|
|
782
|
+
peers.add(peerId);
|
|
783
|
+
this.voice.set(nodeId, { ...existing, peers, updatedAt: observedAt });
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (event === "spatial_voice_peer_left" && nodeId) {
|
|
787
|
+
const peerId = typeof p.peerId === "string" ? p.peerId : void 0;
|
|
788
|
+
const existing = this.voice.get(nodeId);
|
|
789
|
+
if (!existing || !peerId) return;
|
|
790
|
+
const peers = new Set(existing.peers);
|
|
791
|
+
peers.delete(peerId);
|
|
792
|
+
this.voice.set(nodeId, { ...existing, peers, updatedAt: observedAt });
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
for (const existing of this.voice.values()) {
|
|
796
|
+
let next = existing;
|
|
797
|
+
if (event === "spatial_voice_muted") next = { ...existing, muted: true, updatedAt: observedAt };
|
|
798
|
+
else if (event === "spatial_voice_unmuted") next = { ...existing, muted: false, updatedAt: observedAt };
|
|
799
|
+
else if (event === "on_voice_activity")
|
|
800
|
+
next = { ...existing, lastVoiceActivityAt: observedAt, updatedAt: observedAt };
|
|
801
|
+
else continue;
|
|
802
|
+
this.voice.set(existing.nodeId, next);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
// ---- Messaging ---------------------------------------------------------
|
|
806
|
+
applyMessagingEvent(event, payload, observedAt) {
|
|
807
|
+
if (!payload || typeof payload !== "object") return;
|
|
808
|
+
const p = payload;
|
|
809
|
+
const platform = typeof p.platform === "string" ? p.platform : void 0;
|
|
810
|
+
if (!platform) return;
|
|
811
|
+
const existing = this.messaging.get(platform) ?? {
|
|
812
|
+
status: "disconnected",
|
|
813
|
+
messagesReceived: 0,
|
|
814
|
+
messagesSent: 0};
|
|
815
|
+
let status = existing.status;
|
|
816
|
+
let error = existing.error;
|
|
817
|
+
let received = existing.messagesReceived;
|
|
818
|
+
let sent = existing.messagesSent;
|
|
819
|
+
if (event === "messaging_connected") {
|
|
820
|
+
status = "connected";
|
|
821
|
+
error = void 0;
|
|
822
|
+
} else if (event === "messaging_disconnected") {
|
|
823
|
+
status = "disconnected";
|
|
824
|
+
} else if (event === "messaging_error") {
|
|
825
|
+
status = "errored";
|
|
826
|
+
error = typeof p.error === "string" ? p.error : "unknown error";
|
|
827
|
+
} else if (event === "message_received") {
|
|
828
|
+
received++;
|
|
829
|
+
} else if (event === "message_sent") {
|
|
830
|
+
sent++;
|
|
831
|
+
} else ;
|
|
832
|
+
this.messaging.set(platform, {
|
|
833
|
+
platform,
|
|
834
|
+
status,
|
|
835
|
+
messagesReceived: received,
|
|
836
|
+
messagesSent: sent,
|
|
837
|
+
error,
|
|
838
|
+
updatedAt: observedAt
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
// ---- WorldHeartbeat ----------------------------------------------------
|
|
842
|
+
applyHeartbeatEvent(event, payload, observedAt) {
|
|
843
|
+
if (!payload || typeof payload !== "object") return;
|
|
844
|
+
const p = payload;
|
|
845
|
+
const nodeId = typeof p.nodeId === "string" && p.nodeId || typeof p.worldId === "string" && p.worldId || typeof p.id === "string" && p.id || void 0;
|
|
846
|
+
if (!nodeId) return;
|
|
847
|
+
const existing = this.heartbeats.get(nodeId) ?? {
|
|
848
|
+
status: "initialized",
|
|
849
|
+
ticks: 0,
|
|
850
|
+
lastTickAt: 0};
|
|
851
|
+
let status = existing.status;
|
|
852
|
+
let ticks = existing.ticks;
|
|
853
|
+
let lastTickAt = existing.lastTickAt;
|
|
854
|
+
let error = existing.error;
|
|
855
|
+
if (event === "heartbeat_initialized") {
|
|
856
|
+
status = "initialized";
|
|
857
|
+
error = void 0;
|
|
858
|
+
} else if (event === "heartbeat_tick") {
|
|
859
|
+
status = "alive";
|
|
860
|
+
ticks++;
|
|
861
|
+
lastTickAt = observedAt;
|
|
862
|
+
} else if (event === "heartbeat_failover") {
|
|
863
|
+
status = "failover";
|
|
864
|
+
} else if (event === "heartbeat_error") {
|
|
865
|
+
status = "errored";
|
|
866
|
+
error = typeof p.error === "string" ? p.error : typeof p.message === "string" ? p.message : "unknown error";
|
|
867
|
+
}
|
|
868
|
+
this.heartbeats.set(nodeId, { nodeId, status, ticks, lastTickAt, error, updatedAt: observedAt });
|
|
869
|
+
}
|
|
870
|
+
notifyListeners(envelope) {
|
|
871
|
+
for (const listener of this.listeners) {
|
|
872
|
+
try {
|
|
873
|
+
listener(envelope);
|
|
874
|
+
} catch (_) {
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
// ---- Public API --------------------------------------------------------
|
|
879
|
+
/** Subscribe to all presence events. Returns an unsubscribe function. */
|
|
880
|
+
subscribe(listener) {
|
|
881
|
+
this.listeners.add(listener);
|
|
882
|
+
return () => {
|
|
883
|
+
this.listeners.delete(listener);
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
// SharePlay
|
|
887
|
+
getSession(sessionId) {
|
|
888
|
+
const s = this.sessions.get(sessionId);
|
|
889
|
+
return s ? { ...s, participants: new Set(s.participants) } : void 0;
|
|
890
|
+
}
|
|
891
|
+
getAllSessions() {
|
|
892
|
+
return Array.from(this.sessions.values()).map((s) => ({ ...s, participants: new Set(s.participants) }));
|
|
893
|
+
}
|
|
894
|
+
// SpatialVoice
|
|
895
|
+
getVoiceNode(nodeId) {
|
|
896
|
+
const v = this.voice.get(nodeId);
|
|
897
|
+
return v ? { ...v, peers: new Set(v.peers) } : void 0;
|
|
898
|
+
}
|
|
899
|
+
getAllVoiceNodes() {
|
|
900
|
+
return Array.from(this.voice.values()).map((v) => ({ ...v, peers: new Set(v.peers) }));
|
|
901
|
+
}
|
|
902
|
+
// Messaging
|
|
903
|
+
getMessagingConnection(platform) {
|
|
904
|
+
return this.messaging.get(platform);
|
|
905
|
+
}
|
|
906
|
+
getAllMessagingConnections() {
|
|
907
|
+
return Array.from(this.messaging.values());
|
|
908
|
+
}
|
|
909
|
+
// Heartbeat
|
|
910
|
+
getHeartbeat(nodeId) {
|
|
911
|
+
return this.heartbeats.get(nodeId);
|
|
912
|
+
}
|
|
913
|
+
getAllHeartbeats() {
|
|
914
|
+
return Array.from(this.heartbeats.values());
|
|
915
|
+
}
|
|
916
|
+
getStats() {
|
|
917
|
+
const sessions = Array.from(this.sessions.values());
|
|
918
|
+
const voice = Array.from(this.voice.values());
|
|
919
|
+
const messaging = Array.from(this.messaging.values());
|
|
920
|
+
const heartbeats = Array.from(this.heartbeats.values());
|
|
921
|
+
const totalParticipants = sessions.reduce((sum, s) => sum + s.participants.size, 0);
|
|
922
|
+
const totalPeers = voice.reduce((sum, v) => sum + v.peers.size, 0);
|
|
923
|
+
return {
|
|
924
|
+
sessions: {
|
|
925
|
+
active: sessions.filter((s) => s.status === "started" || s.status === "joined").length,
|
|
926
|
+
ended: sessions.filter((s) => s.status === "ended").length,
|
|
927
|
+
participants: totalParticipants
|
|
928
|
+
},
|
|
929
|
+
voice: {
|
|
930
|
+
nodes: voice.length,
|
|
931
|
+
peers: totalPeers,
|
|
932
|
+
muted: voice.filter((v) => v.muted).length
|
|
933
|
+
},
|
|
934
|
+
messaging: {
|
|
935
|
+
connections: messaging.length,
|
|
936
|
+
connected: messaging.filter((m) => m.status === "connected").length,
|
|
937
|
+
errored: messaging.filter((m) => m.status === "errored").length
|
|
938
|
+
},
|
|
939
|
+
heartbeat: {
|
|
940
|
+
tracked: heartbeats.length,
|
|
941
|
+
alive: heartbeats.filter((h) => h.status === "alive").length,
|
|
942
|
+
failover: heartbeats.filter((h) => h.status === "failover").length,
|
|
943
|
+
errored: heartbeats.filter((h) => h.status === "errored").length
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
/** Clear all tracked state — typically called on world teardown / scene change. */
|
|
948
|
+
reset() {
|
|
949
|
+
this.sessions.clear();
|
|
950
|
+
this.voice.clear();
|
|
951
|
+
this.messaging.clear();
|
|
952
|
+
this.heartbeats.clear();
|
|
953
|
+
}
|
|
954
|
+
/** Number of distinct event types this coordinator subscribes to (diagnostic). */
|
|
955
|
+
get subscribedEventCount() {
|
|
956
|
+
return PRESENCE_EVENTS.length;
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
// src/coordinators/NeuralForgeCoordinator.ts
|
|
961
|
+
var NEURAL_FORGE_EVENTS = [
|
|
962
|
+
"neural_forge_connected",
|
|
963
|
+
"neural_synthesis_request",
|
|
964
|
+
"neural_synthesis_timeout",
|
|
965
|
+
"neural_shard_created",
|
|
966
|
+
"neural_cognition_evolved"
|
|
967
|
+
];
|
|
968
|
+
var NeuralForgeCoordinator = class {
|
|
969
|
+
constructor(source) {
|
|
970
|
+
this.nodes = /* @__PURE__ */ new Map();
|
|
971
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
972
|
+
/** Tracks which nodes have fired neural_forge_connected. */
|
|
973
|
+
this.connectedNodes = /* @__PURE__ */ new Set();
|
|
974
|
+
for (const event of NEURAL_FORGE_EVENTS) {
|
|
975
|
+
source.on(event, (payload) => this.handleEvent(event, payload));
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
// ---- Event ingestion ---------------------------------------------------
|
|
979
|
+
handleEvent(event, payload) {
|
|
980
|
+
if (!payload || typeof payload !== "object") return;
|
|
981
|
+
const p = payload;
|
|
982
|
+
const nodeObj = p.node;
|
|
983
|
+
const nodeId = nodeObj?.id ?? p.nodeId ?? p.sourceId;
|
|
984
|
+
if (!nodeId || typeof nodeId !== "string") return;
|
|
985
|
+
const observedAt = Date.now();
|
|
986
|
+
switch (event) {
|
|
987
|
+
case "neural_forge_connected": {
|
|
988
|
+
this.connectedNodes.add(nodeId);
|
|
989
|
+
const existing = this.nodes.get(nodeId);
|
|
990
|
+
const next = {
|
|
991
|
+
nodeId,
|
|
992
|
+
status: existing?.status ?? "connected",
|
|
993
|
+
shardCount: existing?.shardCount ?? 0,
|
|
994
|
+
weights: existing?.weights ?? {},
|
|
995
|
+
lastSynthesisAt: existing?.lastSynthesisAt ?? null,
|
|
996
|
+
pendingExternalSynthesis: existing?.pendingExternalSynthesis ?? false,
|
|
997
|
+
pendingSince: existing?.pendingSince ?? null,
|
|
998
|
+
experienceLogLength: existing?.experienceLogLength ?? 0,
|
|
999
|
+
updatedAt: observedAt
|
|
1000
|
+
};
|
|
1001
|
+
this.nodes.set(nodeId, next);
|
|
1002
|
+
this.notifyListeners(next);
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
case "neural_synthesis_request": {
|
|
1006
|
+
const mode = p.mode;
|
|
1007
|
+
const experiences = p.experiences;
|
|
1008
|
+
const weights = p.currentWeights;
|
|
1009
|
+
const existing = this.nodes.get(nodeId);
|
|
1010
|
+
const next = {
|
|
1011
|
+
nodeId,
|
|
1012
|
+
status: mode === "external" ? "synthesizing" : existing?.status ?? "idle",
|
|
1013
|
+
shardCount: existing?.shardCount ?? 0,
|
|
1014
|
+
weights: weights ?? existing?.weights ?? {},
|
|
1015
|
+
lastSynthesisAt: existing?.lastSynthesisAt ?? null,
|
|
1016
|
+
pendingExternalSynthesis: mode === "external",
|
|
1017
|
+
pendingSince: mode === "external" ? observedAt : null,
|
|
1018
|
+
experienceLogLength: Array.isArray(experiences) ? experiences.length : existing?.experienceLogLength ?? 0,
|
|
1019
|
+
updatedAt: observedAt
|
|
1020
|
+
};
|
|
1021
|
+
this.nodes.set(nodeId, next);
|
|
1022
|
+
this.notifyListeners(next);
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
case "neural_synthesis_timeout": {
|
|
1026
|
+
const experienceCount = p.experienceCount;
|
|
1027
|
+
const existing = this.nodes.get(nodeId);
|
|
1028
|
+
const next = {
|
|
1029
|
+
nodeId,
|
|
1030
|
+
status: "timeout_fallback",
|
|
1031
|
+
shardCount: existing?.shardCount ?? 0,
|
|
1032
|
+
weights: existing?.weights ?? {},
|
|
1033
|
+
lastSynthesisAt: existing?.lastSynthesisAt ?? null,
|
|
1034
|
+
pendingExternalSynthesis: false,
|
|
1035
|
+
pendingSince: null,
|
|
1036
|
+
experienceLogLength: experienceCount ?? (existing?.experienceLogLength ?? 0),
|
|
1037
|
+
updatedAt: observedAt
|
|
1038
|
+
};
|
|
1039
|
+
this.nodes.set(nodeId, next);
|
|
1040
|
+
this.notifyListeners(next);
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
case "neural_shard_created": {
|
|
1044
|
+
p.shard;
|
|
1045
|
+
const existing = this.nodes.get(nodeId);
|
|
1046
|
+
const next = {
|
|
1047
|
+
nodeId,
|
|
1048
|
+
status: existing?.pendingExternalSynthesis ? "synthesizing" : existing?.status ?? "idle",
|
|
1049
|
+
shardCount: (existing?.shardCount ?? 0) + 1,
|
|
1050
|
+
weights: existing?.weights ?? {},
|
|
1051
|
+
lastSynthesisAt: observedAt,
|
|
1052
|
+
pendingExternalSynthesis: existing?.pendingExternalSynthesis ?? false,
|
|
1053
|
+
pendingSince: existing?.pendingSince ?? null,
|
|
1054
|
+
experienceLogLength: existing?.experienceLogLength ?? 0,
|
|
1055
|
+
updatedAt: observedAt
|
|
1056
|
+
};
|
|
1057
|
+
this.nodes.set(nodeId, next);
|
|
1058
|
+
this.notifyListeners(next);
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
1061
|
+
case "neural_cognition_evolved": {
|
|
1062
|
+
const weights = p.currentWeights;
|
|
1063
|
+
const existing = this.nodes.get(nodeId);
|
|
1064
|
+
if (!existing) {
|
|
1065
|
+
const next = {
|
|
1066
|
+
nodeId,
|
|
1067
|
+
status: "idle",
|
|
1068
|
+
shardCount: 0,
|
|
1069
|
+
weights: weights ?? {},
|
|
1070
|
+
lastSynthesisAt: null,
|
|
1071
|
+
pendingExternalSynthesis: false,
|
|
1072
|
+
pendingSince: null,
|
|
1073
|
+
experienceLogLength: 0,
|
|
1074
|
+
updatedAt: observedAt
|
|
1075
|
+
};
|
|
1076
|
+
this.nodes.set(nodeId, next);
|
|
1077
|
+
this.notifyListeners(next);
|
|
1078
|
+
} else {
|
|
1079
|
+
existing.weights = weights ?? existing.weights;
|
|
1080
|
+
existing.updatedAt = observedAt;
|
|
1081
|
+
this.notifyListeners(existing);
|
|
1082
|
+
}
|
|
1083
|
+
break;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
notifyListeners(state) {
|
|
1088
|
+
for (const listener of this.listeners) {
|
|
1089
|
+
try {
|
|
1090
|
+
listener(state);
|
|
1091
|
+
} catch (_) {
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
// ---- Public API --------------------------------------------------------
|
|
1096
|
+
/** Subscribe to all neural-node state changes. Returns an unsubscribe function. */
|
|
1097
|
+
subscribe(listener) {
|
|
1098
|
+
this.listeners.add(listener);
|
|
1099
|
+
return () => {
|
|
1100
|
+
this.listeners.delete(listener);
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
/** Get the state of a specific node (undefined if never seen). */
|
|
1104
|
+
getNodeState(nodeId) {
|
|
1105
|
+
return this.nodes.get(nodeId);
|
|
1106
|
+
}
|
|
1107
|
+
/** Get all tracked node states (snapshot — safe to iterate). */
|
|
1108
|
+
getAllStates() {
|
|
1109
|
+
return Array.from(this.nodes.values());
|
|
1110
|
+
}
|
|
1111
|
+
/** Whether a specific node has fired neural_forge_connected. */
|
|
1112
|
+
isConnected(nodeId) {
|
|
1113
|
+
return this.connectedNodes.has(nodeId);
|
|
1114
|
+
}
|
|
1115
|
+
/** Aggregate stats across all tracked nodes. */
|
|
1116
|
+
getStats() {
|
|
1117
|
+
const all = Array.from(this.nodes.values());
|
|
1118
|
+
return {
|
|
1119
|
+
total: all.length,
|
|
1120
|
+
synthesizing: all.filter((s) => s.status === "synthesizing").length,
|
|
1121
|
+
timeoutFallback: all.filter((s) => s.status === "timeout_fallback").length,
|
|
1122
|
+
totalShards: all.reduce((sum, s) => sum + s.shardCount, 0),
|
|
1123
|
+
anyConnected: this.connectedNodes.size > 0
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
/** Clear all tracked state — typically called on scene change. */
|
|
1127
|
+
reset() {
|
|
1128
|
+
this.nodes.clear();
|
|
1129
|
+
this.connectedNodes.clear();
|
|
1130
|
+
}
|
|
1131
|
+
/** Number of distinct event types this coordinator subscribes to (diagnostic). */
|
|
1132
|
+
get subscribedEventCount() {
|
|
1133
|
+
return NEURAL_FORGE_EVENTS.length;
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
// src/coordinators/ObjectTrackingCoordinator.ts
|
|
1138
|
+
var OBJECT_TRACKING_EVENTS = [
|
|
1139
|
+
"tracking:init",
|
|
1140
|
+
"tracking:updated",
|
|
1141
|
+
"tracking:lost",
|
|
1142
|
+
"tracking:recovery_attempt",
|
|
1143
|
+
"tracking:anchor_removed"
|
|
1144
|
+
];
|
|
1145
|
+
function isRecord(value) {
|
|
1146
|
+
return typeof value === "object" && value !== null;
|
|
1147
|
+
}
|
|
1148
|
+
function readString(value) {
|
|
1149
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1150
|
+
}
|
|
1151
|
+
function readNumber(value) {
|
|
1152
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
1153
|
+
}
|
|
1154
|
+
function readVector3(value) {
|
|
1155
|
+
if (!Array.isArray(value) || value.length !== 3 || !value.every((n) => Number.isFinite(n))) {
|
|
1156
|
+
return void 0;
|
|
1157
|
+
}
|
|
1158
|
+
return [...value];
|
|
1159
|
+
}
|
|
1160
|
+
function clampConfidence(value, fallback) {
|
|
1161
|
+
const confidence = readNumber(value);
|
|
1162
|
+
if (confidence === void 0) return fallback;
|
|
1163
|
+
return Math.max(0, Math.min(1, confidence));
|
|
1164
|
+
}
|
|
1165
|
+
var ObjectTrackingCoordinator = class {
|
|
1166
|
+
constructor(source) {
|
|
1167
|
+
this.targets = /* @__PURE__ */ new Map();
|
|
1168
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
1169
|
+
for (const event of OBJECT_TRACKING_EVENTS) {
|
|
1170
|
+
source.on(event, (payload) => this.handleEvent(event, payload));
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
handleEvent(event, payload) {
|
|
1174
|
+
if (!isRecord(payload)) return;
|
|
1175
|
+
const key = this.resolveKey(payload);
|
|
1176
|
+
if (!key) return;
|
|
1177
|
+
const observedAt = Date.now();
|
|
1178
|
+
const existing = this.targets.get(key);
|
|
1179
|
+
const next = existing ? { ...existing, updatedAt: observedAt } : {
|
|
1180
|
+
nodeId: key,
|
|
1181
|
+
anchorId: null,
|
|
1182
|
+
status: "initialized",
|
|
1183
|
+
position: null,
|
|
1184
|
+
rotation: null,
|
|
1185
|
+
confidence: 0,
|
|
1186
|
+
recoveryAttempts: 0,
|
|
1187
|
+
timestampMs: null,
|
|
1188
|
+
updatedAt: observedAt
|
|
1189
|
+
};
|
|
1190
|
+
next.target = readString(payload.target) ?? next.target;
|
|
1191
|
+
next.anchorId = readString(payload.anchorId) ?? next.anchorId;
|
|
1192
|
+
if (event === "tracking:init") {
|
|
1193
|
+
next.status = "initialized";
|
|
1194
|
+
} else if (event === "tracking:updated") {
|
|
1195
|
+
next.status = "tracking";
|
|
1196
|
+
next.position = readVector3(payload.position) ?? next.position;
|
|
1197
|
+
next.rotation = readVector3(payload.rotation) ?? next.rotation;
|
|
1198
|
+
next.confidence = clampConfidence(payload.confidence, next.confidence);
|
|
1199
|
+
next.source = readString(payload.source) ?? next.source;
|
|
1200
|
+
next.timestampMs = readNumber(payload.timestampMs) ?? next.timestampMs;
|
|
1201
|
+
} else if (event === "tracking:lost") {
|
|
1202
|
+
next.status = "lost";
|
|
1203
|
+
next.confidence = 0;
|
|
1204
|
+
} else if (event === "tracking:recovery_attempt") {
|
|
1205
|
+
next.status = "recovering";
|
|
1206
|
+
next.recoveryAttempts = readNumber(payload.attempt) ?? next.recoveryAttempts + 1;
|
|
1207
|
+
} else if (event === "tracking:anchor_removed") {
|
|
1208
|
+
next.status = "removed";
|
|
1209
|
+
}
|
|
1210
|
+
this.targets.set(key, next);
|
|
1211
|
+
this.notifyListeners(next);
|
|
1212
|
+
}
|
|
1213
|
+
resolveKey(payload) {
|
|
1214
|
+
const nodeId = readString(payload.nodeId);
|
|
1215
|
+
if (nodeId) return nodeId;
|
|
1216
|
+
const anchorId = readString(payload.anchorId);
|
|
1217
|
+
if (anchorId) return `anchor:${anchorId}`;
|
|
1218
|
+
const target = readString(payload.target);
|
|
1219
|
+
return target ? `target:${target}` : void 0;
|
|
1220
|
+
}
|
|
1221
|
+
notifyListeners(state) {
|
|
1222
|
+
for (const listener of this.listeners) {
|
|
1223
|
+
try {
|
|
1224
|
+
listener(state);
|
|
1225
|
+
} catch {
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
subscribe(listener) {
|
|
1230
|
+
this.listeners.add(listener);
|
|
1231
|
+
return () => this.listeners.delete(listener);
|
|
1232
|
+
}
|
|
1233
|
+
getTrackingState(nodeId) {
|
|
1234
|
+
return this.targets.get(nodeId);
|
|
1235
|
+
}
|
|
1236
|
+
getAllStates() {
|
|
1237
|
+
return Array.from(this.targets.values());
|
|
1238
|
+
}
|
|
1239
|
+
getStats() {
|
|
1240
|
+
const states = this.getAllStates();
|
|
1241
|
+
return {
|
|
1242
|
+
total: states.length,
|
|
1243
|
+
tracking: states.filter((s) => s.status === "tracking").length,
|
|
1244
|
+
lost: states.filter((s) => s.status === "lost").length,
|
|
1245
|
+
recovering: states.filter((s) => s.status === "recovering").length,
|
|
1246
|
+
removed: states.filter((s) => s.status === "removed").length
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
reset() {
|
|
1250
|
+
this.targets.clear();
|
|
1251
|
+
}
|
|
1252
|
+
get subscribedEventCount() {
|
|
1253
|
+
return OBJECT_TRACKING_EVENTS.length;
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
export { AssetLoadCoordinator, GenerativeJobMonitor, NeuralForgeCoordinator, ObjectTrackingCoordinator, SecurityEventBus, SessionPresenceCoordinator };
|
|
1258
|
+
//# sourceMappingURL=index.js.map
|
|
1259
|
+
//# sourceMappingURL=index.js.map
|