@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,432 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/traits/engines/tensor-ops.ts
|
|
4
|
+
function sizeOf(shape) {
|
|
5
|
+
return shape.reduce((a, b) => a * b, 1);
|
|
6
|
+
}
|
|
7
|
+
function createTensor(shape, data) {
|
|
8
|
+
if (!Array.isArray(shape) || shape.length === 0 || shape.some((d) => !Number.isInteger(d) || d <= 0)) {
|
|
9
|
+
throw new Error(`tensor-ops: invalid shape ${JSON.stringify(shape)}`);
|
|
10
|
+
}
|
|
11
|
+
const size = sizeOf(shape);
|
|
12
|
+
const buf = new Float32Array(size);
|
|
13
|
+
if (data) {
|
|
14
|
+
const n = Math.min(size, data.length);
|
|
15
|
+
for (let i = 0; i < n; i++) buf[i] = data[i];
|
|
16
|
+
}
|
|
17
|
+
return { shape: shape.slice(), data: buf };
|
|
18
|
+
}
|
|
19
|
+
function add(a, b) {
|
|
20
|
+
if (a.data.length !== b.data.length) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`tensor-ops: add shape mismatch ${JSON.stringify(a.shape)} vs ${JSON.stringify(b.shape)}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const out = new Float32Array(a.data.length);
|
|
26
|
+
for (let i = 0; i < out.length; i++) out[i] = a.data[i] + b.data[i];
|
|
27
|
+
return { shape: a.shape.slice(), data: out };
|
|
28
|
+
}
|
|
29
|
+
function matmul(a, b) {
|
|
30
|
+
if (a.shape.length !== 2 || b.shape.length !== 2) {
|
|
31
|
+
throw new Error("tensor-ops: matmul requires 2D tensors");
|
|
32
|
+
}
|
|
33
|
+
const [m, k] = a.shape;
|
|
34
|
+
const [k2, n] = b.shape;
|
|
35
|
+
if (k !== k2) {
|
|
36
|
+
throw new Error(`tensor-ops: matmul inner dim mismatch ${k} vs ${k2}`);
|
|
37
|
+
}
|
|
38
|
+
const out = new Float32Array(m * n);
|
|
39
|
+
for (let i = 0; i < m; i++) {
|
|
40
|
+
for (let j = 0; j < n; j++) {
|
|
41
|
+
let acc = 0;
|
|
42
|
+
for (let p = 0; p < k; p++) acc += a.data[i * k + p] * b.data[p * n + j];
|
|
43
|
+
out[i * n + j] = acc;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { shape: [m, n], data: out };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/traits/engines/pfnn-network.ts
|
|
50
|
+
var PHASE_CONTROL_POINTS = 4;
|
|
51
|
+
var HIDDEN_DIM = 64;
|
|
52
|
+
function mulberry32(seed) {
|
|
53
|
+
let a = seed >>> 0;
|
|
54
|
+
return () => {
|
|
55
|
+
a |= 0;
|
|
56
|
+
a = a + 1831565813 | 0;
|
|
57
|
+
let t = Math.imul(a ^ a >>> 15, 1 | a);
|
|
58
|
+
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
59
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function eluInPlace(data) {
|
|
63
|
+
for (let i = 0; i < data.length; i++) {
|
|
64
|
+
const x = data[i];
|
|
65
|
+
data[i] = x >= 0 ? x : Math.exp(x) - 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function initWeight(rng, inDim, outDim) {
|
|
69
|
+
const limit = Math.sqrt(6 / (inDim + outDim));
|
|
70
|
+
const data = new Float32Array(inDim * outDim);
|
|
71
|
+
for (let i = 0; i < data.length; i++) data[i] = (rng() * 2 - 1) * limit;
|
|
72
|
+
return { shape: [inDim, outDim], data };
|
|
73
|
+
}
|
|
74
|
+
function initBias(rng, outDim) {
|
|
75
|
+
const data = new Float32Array(outDim);
|
|
76
|
+
for (let i = 0; i < data.length; i++) data[i] = (rng() * 2 - 1) * 0.01;
|
|
77
|
+
return { shape: [1, outDim], data };
|
|
78
|
+
}
|
|
79
|
+
var PfnnNetwork = class {
|
|
80
|
+
constructor(inputDim, outputDim, seed = 2654435769, hiddenDim = HIDDEN_DIM) {
|
|
81
|
+
this.inputDim = inputDim;
|
|
82
|
+
this.outputDim = outputDim;
|
|
83
|
+
this.hiddenDim = hiddenDim;
|
|
84
|
+
const rng = mulberry32(seed);
|
|
85
|
+
this.controlPoints = [];
|
|
86
|
+
for (let c = 0; c < PHASE_CONTROL_POINTS; c++) {
|
|
87
|
+
const layers = [
|
|
88
|
+
{ weight: initWeight(rng, inputDim, hiddenDim), bias: initBias(rng, hiddenDim) },
|
|
89
|
+
{ weight: initWeight(rng, hiddenDim, hiddenDim), bias: initBias(rng, hiddenDim) },
|
|
90
|
+
{ weight: initWeight(rng, hiddenDim, outputDim), bias: initBias(rng, outputDim) }
|
|
91
|
+
];
|
|
92
|
+
this.controlPoints.push({ layers });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Export the raw weights — used by the .onnx provisioning script so the
|
|
97
|
+
* ONNX graph carries the identical numbers. Returned arrays are copies.
|
|
98
|
+
*/
|
|
99
|
+
exportWeights() {
|
|
100
|
+
return {
|
|
101
|
+
controlPoints: this.controlPoints.map((cp) => ({
|
|
102
|
+
layers: cp.layers.map((l) => ({
|
|
103
|
+
weight: Array.from(l.weight.data),
|
|
104
|
+
bias: Array.from(l.bias.data),
|
|
105
|
+
shape: [l.weight.shape[0], l.weight.shape[1]]
|
|
106
|
+
}))
|
|
107
|
+
}))
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Cyclic cubic Catmull-Rom blend of the four control points at phase φ.
|
|
112
|
+
* Holden 2017 eq. 4: the four banks are knots on a periodic spline indexed
|
|
113
|
+
* by φ·4, and the fractional part drives a Catmull-Rom interpolation. We
|
|
114
|
+
* blend per-layer weight and bias buffers.
|
|
115
|
+
*/
|
|
116
|
+
blendLayer(layerIdx, phase) {
|
|
117
|
+
const t = (phase % 1 + 1) % 1;
|
|
118
|
+
const scaled = t * PHASE_CONTROL_POINTS;
|
|
119
|
+
const k = Math.floor(scaled);
|
|
120
|
+
const f = scaled - k;
|
|
121
|
+
const mod = (n) => (n % PHASE_CONTROL_POINTS + PHASE_CONTROL_POINTS) % PHASE_CONTROL_POINTS;
|
|
122
|
+
const p0 = this.controlPoints[mod(k - 1)].layers[layerIdx];
|
|
123
|
+
const p1 = this.controlPoints[mod(k)].layers[layerIdx];
|
|
124
|
+
const p2 = this.controlPoints[mod(k + 1)].layers[layerIdx];
|
|
125
|
+
const p3 = this.controlPoints[mod(k + 2)].layers[layerIdx];
|
|
126
|
+
const f2 = f * f;
|
|
127
|
+
const f3 = f2 * f;
|
|
128
|
+
const w0 = -0.5 * f3 + f2 - 0.5 * f;
|
|
129
|
+
const w1 = 1.5 * f3 - 2.5 * f2 + 1;
|
|
130
|
+
const w2 = -1.5 * f3 + 2 * f2 + 0.5 * f;
|
|
131
|
+
const w3 = 0.5 * f3 - 0.5 * f2;
|
|
132
|
+
const blend = (a, b, c, d) => {
|
|
133
|
+
const out = new Float32Array(a.data.length);
|
|
134
|
+
for (let i = 0; i < out.length; i++) {
|
|
135
|
+
out[i] = w0 * a.data[i] + w1 * b.data[i] + w2 * c.data[i] + w3 * d.data[i];
|
|
136
|
+
}
|
|
137
|
+
return { shape: a.shape.slice(), data: out };
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
weight: blend(p0.weight, p1.weight, p2.weight, p3.weight),
|
|
141
|
+
bias: blend(p0.bias, p1.bias, p2.bias, p3.bias)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Run a real forward pass. `input` is a Float32Array of length inputDim.
|
|
146
|
+
* `phase` ∈ [0,1) selects the blended weights. Returns a Float32Array of
|
|
147
|
+
* length outputDim. Pure, deterministic, no native deps.
|
|
148
|
+
*/
|
|
149
|
+
forward(input, phase) {
|
|
150
|
+
if (input.length !== this.inputDim) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`PfnnNetwork.forward: input length ${input.length} != inputDim ${this.inputDim}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
let x = createTensor([1, this.inputDim], input);
|
|
156
|
+
const layer0 = this.blendLayer(0, phase);
|
|
157
|
+
const layer1 = this.blendLayer(1, phase);
|
|
158
|
+
const layer2 = this.blendLayer(2, phase);
|
|
159
|
+
x = add(matmul(x, layer0.weight), layer0.bias);
|
|
160
|
+
eluInPlace(x.data);
|
|
161
|
+
x = add(matmul(x, layer1.weight), layer1.bias);
|
|
162
|
+
eluInPlace(x.data);
|
|
163
|
+
x = add(matmul(x, layer2.weight), layer2.bias);
|
|
164
|
+
return x.data;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Forward pass using ONLY control point `cp` (no phase blending). This is the
|
|
168
|
+
* exact computation the provisioned .onnx graph encodes (it bakes a single
|
|
169
|
+
* control point). Used by the pure-JS ↔ ONNX numerical-parity test to prove
|
|
170
|
+
* both paths run the identical genuine forward pass.
|
|
171
|
+
*/
|
|
172
|
+
forwardControlPoint(input, cp = 0) {
|
|
173
|
+
if (input.length !== this.inputDim) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`PfnnNetwork.forwardControlPoint: input length ${input.length} != inputDim ${this.inputDim}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
const layers = this.controlPoints[(cp % PHASE_CONTROL_POINTS + PHASE_CONTROL_POINTS) % PHASE_CONTROL_POINTS].layers;
|
|
179
|
+
let x = createTensor([1, this.inputDim], input);
|
|
180
|
+
x = add(matmul(x, layers[0].weight), layers[0].bias);
|
|
181
|
+
eluInPlace(x.data);
|
|
182
|
+
x = add(matmul(x, layers[1].weight), layers[1].bias);
|
|
183
|
+
eluInPlace(x.data);
|
|
184
|
+
x = add(matmul(x, layers[2].weight), layers[2].bias);
|
|
185
|
+
return x.data;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var BUNDLED_MODEL_SEED = 2654435769;
|
|
189
|
+
function createBundledPfnn(inputDim, outputDim) {
|
|
190
|
+
return new PfnnNetwork(inputDim, outputDim, BUNDLED_MODEL_SEED);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/traits/engines/onnx-adapter.ts
|
|
194
|
+
var NoOpInferenceAdapter = class {
|
|
195
|
+
constructor() {
|
|
196
|
+
this.name = "NoOpInferenceAdapter";
|
|
197
|
+
this.preferredProvider = "cpu";
|
|
198
|
+
this.loaded = false;
|
|
199
|
+
this.modelUrl = null;
|
|
200
|
+
}
|
|
201
|
+
async load(modelUrl) {
|
|
202
|
+
this.modelUrl = modelUrl;
|
|
203
|
+
this.loaded = true;
|
|
204
|
+
}
|
|
205
|
+
runSync(request) {
|
|
206
|
+
if (!this.loaded) {
|
|
207
|
+
throw new Error("NoOpInferenceAdapter: load() must be called before run()");
|
|
208
|
+
}
|
|
209
|
+
const inputNames = Object.keys(request.inputs);
|
|
210
|
+
if (inputNames.length === 0) {
|
|
211
|
+
throw new Error("NoOpInferenceAdapter: at least one input required");
|
|
212
|
+
}
|
|
213
|
+
const firstInput = request.inputs[inputNames[0]];
|
|
214
|
+
const outputNames = request.outputs && request.outputs.length > 0 ? request.outputs : ["output"];
|
|
215
|
+
const outputs = {};
|
|
216
|
+
for (const name of outputNames) {
|
|
217
|
+
outputs[name] = {
|
|
218
|
+
data: new Float32Array(firstInput.data.length),
|
|
219
|
+
shape: firstInput.shape
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
outputs,
|
|
224
|
+
durationMs: 0,
|
|
225
|
+
providerUsed: this.preferredProvider
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
async run(request) {
|
|
229
|
+
return this.runSync(request);
|
|
230
|
+
}
|
|
231
|
+
dispose() {
|
|
232
|
+
this.loaded = false;
|
|
233
|
+
this.modelUrl = null;
|
|
234
|
+
}
|
|
235
|
+
/** Returns the URL the adapter was loaded with — diagnostic only. */
|
|
236
|
+
get loadedModelUrl() {
|
|
237
|
+
return this.modelUrl;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
function createNoOpInferenceAdapter() {
|
|
241
|
+
return new NoOpInferenceAdapter();
|
|
242
|
+
}
|
|
243
|
+
var PureJsInferenceAdapter = class {
|
|
244
|
+
constructor(inputDim, outputDim) {
|
|
245
|
+
this.inputDim = inputDim;
|
|
246
|
+
this.outputDim = outputDim;
|
|
247
|
+
this.name = "PureJsInferenceAdapter";
|
|
248
|
+
this.preferredProvider = "cpu";
|
|
249
|
+
this.loaded = false;
|
|
250
|
+
this.net = null;
|
|
251
|
+
this.modelUrl = null;
|
|
252
|
+
}
|
|
253
|
+
async load(modelUrl) {
|
|
254
|
+
this.modelUrl = modelUrl;
|
|
255
|
+
if (this.inputDim != null && this.outputDim != null) {
|
|
256
|
+
this.net = createBundledPfnn(this.inputDim, this.outputDim);
|
|
257
|
+
}
|
|
258
|
+
this.loaded = true;
|
|
259
|
+
}
|
|
260
|
+
ensureNet(inputDim) {
|
|
261
|
+
if (this.net && this.net.inputDim === inputDim) return this.net;
|
|
262
|
+
const outDim = this.outputDim ?? MOTION_OUTPUT_DIM_DEFAULT;
|
|
263
|
+
this.net = createBundledPfnn(inputDim, outDim);
|
|
264
|
+
return this.net;
|
|
265
|
+
}
|
|
266
|
+
/** Recover the locomotion phase from the engine's phase channels. */
|
|
267
|
+
phaseFromInput(data) {
|
|
268
|
+
const n = data.length;
|
|
269
|
+
const sinP = data[n - 4] ?? 0;
|
|
270
|
+
const cosP = data[n - 3] ?? 1;
|
|
271
|
+
return (Math.atan2(sinP, cosP) / (2 * Math.PI) + 1) % 1;
|
|
272
|
+
}
|
|
273
|
+
runSync(request) {
|
|
274
|
+
if (!this.loaded) {
|
|
275
|
+
throw new Error("PureJsInferenceAdapter: load() must be called before run()");
|
|
276
|
+
}
|
|
277
|
+
const inputNames = Object.keys(request.inputs);
|
|
278
|
+
if (inputNames.length === 0) {
|
|
279
|
+
throw new Error("PureJsInferenceAdapter: at least one input required");
|
|
280
|
+
}
|
|
281
|
+
const input = request.inputs[inputNames[0]];
|
|
282
|
+
const net = this.ensureNet(input.data.length);
|
|
283
|
+
const phase = this.phaseFromInput(input.data);
|
|
284
|
+
const start = nowMs();
|
|
285
|
+
const out = net.forward(input.data, phase);
|
|
286
|
+
const durationMs = nowMs() - start;
|
|
287
|
+
const outName = request.outputs && request.outputs.length > 0 ? request.outputs[0] : "motion_output";
|
|
288
|
+
return {
|
|
289
|
+
outputs: { [outName]: { data: out, shape: [1, out.length] } },
|
|
290
|
+
durationMs,
|
|
291
|
+
providerUsed: this.preferredProvider
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
async run(request) {
|
|
295
|
+
return this.runSync(request);
|
|
296
|
+
}
|
|
297
|
+
dispose() {
|
|
298
|
+
this.loaded = false;
|
|
299
|
+
this.net = null;
|
|
300
|
+
this.modelUrl = null;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var MOTION_OUTPUT_DIM_DEFAULT = 50;
|
|
304
|
+
function nowMs() {
|
|
305
|
+
return typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
306
|
+
}
|
|
307
|
+
function createPureJsInferenceAdapter(inputDim, outputDim) {
|
|
308
|
+
return new PureJsInferenceAdapter(inputDim, outputDim);
|
|
309
|
+
}
|
|
310
|
+
var OnnxNodeInferenceAdapter = class {
|
|
311
|
+
constructor(preferredProvider = "cpu") {
|
|
312
|
+
this.name = "OnnxNodeInferenceAdapter";
|
|
313
|
+
this.loaded = false;
|
|
314
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
315
|
+
this.session = null;
|
|
316
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
317
|
+
this.ort = null;
|
|
318
|
+
this.resolvedPath = null;
|
|
319
|
+
this.preferredProvider = preferredProvider;
|
|
320
|
+
}
|
|
321
|
+
async load(modelUrl) {
|
|
322
|
+
const path = await resolveOnnxModelPath(modelUrl);
|
|
323
|
+
if (!path) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
`OnnxNodeInferenceAdapter: no .onnx model file resolved for "${modelUrl}". Provision it with scripts/provision-motion-model.mjs or set HOLOSCRIPT_MOTION_MODELS_DIR.`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
this.ort = await import('onnxruntime-node');
|
|
329
|
+
this.session = await this.ort.InferenceSession.create(path);
|
|
330
|
+
this.resolvedPath = path;
|
|
331
|
+
this.loaded = true;
|
|
332
|
+
}
|
|
333
|
+
async run(request) {
|
|
334
|
+
if (!this.loaded || !this.session || !this.ort) {
|
|
335
|
+
throw new Error("OnnxNodeInferenceAdapter: load() must be called before run()");
|
|
336
|
+
}
|
|
337
|
+
const inputNames = Object.keys(request.inputs);
|
|
338
|
+
if (inputNames.length === 0) {
|
|
339
|
+
throw new Error("OnnxNodeInferenceAdapter: at least one input required");
|
|
340
|
+
}
|
|
341
|
+
const feeds = {};
|
|
342
|
+
const sessionInputs = this.session.inputNames ?? [];
|
|
343
|
+
const requestEntries = Object.entries(request.inputs);
|
|
344
|
+
requestEntries.forEach(([name, tensor], i) => {
|
|
345
|
+
const target = sessionInputs[i] ?? name;
|
|
346
|
+
feeds[target] = new this.ort.Tensor("float32", tensor.data, Array.from(tensor.shape));
|
|
347
|
+
});
|
|
348
|
+
const start = nowMs();
|
|
349
|
+
const results = await this.session.run(feeds);
|
|
350
|
+
const durationMs = nowMs() - start;
|
|
351
|
+
const sessionOutputs = this.session.outputNames ?? Object.keys(results);
|
|
352
|
+
const wanted = request.outputs && request.outputs.length > 0 ? request.outputs : sessionOutputs;
|
|
353
|
+
const outputs = {};
|
|
354
|
+
wanted.forEach((name, i) => {
|
|
355
|
+
const srcName = sessionOutputs[i] ?? name;
|
|
356
|
+
const t = results[srcName] ?? results[name];
|
|
357
|
+
if (t) {
|
|
358
|
+
outputs[name] = { data: t.data, shape: t.dims.slice() };
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
return { outputs, durationMs, providerUsed: this.preferredProvider };
|
|
362
|
+
}
|
|
363
|
+
dispose() {
|
|
364
|
+
if (this.session && typeof this.session.release === "function") {
|
|
365
|
+
try {
|
|
366
|
+
void this.session.release();
|
|
367
|
+
} catch {
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
this.session = null;
|
|
371
|
+
this.ort = null;
|
|
372
|
+
this.resolvedPath = null;
|
|
373
|
+
this.loaded = false;
|
|
374
|
+
}
|
|
375
|
+
/** The on-disk path the session was created from — diagnostic only. */
|
|
376
|
+
get loadedModelPath() {
|
|
377
|
+
return this.resolvedPath;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
function createOnnxNodeInferenceAdapter(preferredProvider = "cpu") {
|
|
381
|
+
return new OnnxNodeInferenceAdapter(preferredProvider);
|
|
382
|
+
}
|
|
383
|
+
async function resolveOnnxModelPath(modelUrl) {
|
|
384
|
+
let fs;
|
|
385
|
+
let path;
|
|
386
|
+
try {
|
|
387
|
+
fs = await import('fs');
|
|
388
|
+
path = await import('path');
|
|
389
|
+
} catch {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
const exists = (p) => {
|
|
393
|
+
try {
|
|
394
|
+
return fs.existsSync(p);
|
|
395
|
+
} catch {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
if (!modelUrl.startsWith("bundled://") && exists(modelUrl)) return modelUrl;
|
|
400
|
+
const id = modelUrl.startsWith("bundled://") ? modelUrl.slice("bundled://".length) : path.basename(modelUrl);
|
|
401
|
+
const fileName = id.endsWith(".onnx") ? id : `${id}.onnx`;
|
|
402
|
+
const candidates = [];
|
|
403
|
+
const envDir = process?.env?.HOLOSCRIPT_MOTION_MODELS_DIR?.trim();
|
|
404
|
+
if (envDir) candidates.push(path.join(path.resolve(envDir), fileName));
|
|
405
|
+
let dir = process?.cwd?.() ?? ".";
|
|
406
|
+
for (let i = 0; i < 8; i++) {
|
|
407
|
+
candidates.push(path.join(dir, ".models", "motion", fileName));
|
|
408
|
+
const parent = path.dirname(dir);
|
|
409
|
+
if (parent === dir) break;
|
|
410
|
+
dir = parent;
|
|
411
|
+
}
|
|
412
|
+
return candidates.find(exists) ?? null;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
exports.BUNDLED_MODEL_SEED = BUNDLED_MODEL_SEED;
|
|
416
|
+
exports.HIDDEN_DIM = HIDDEN_DIM;
|
|
417
|
+
exports.NoOpInferenceAdapter = NoOpInferenceAdapter;
|
|
418
|
+
exports.OnnxNodeInferenceAdapter = OnnxNodeInferenceAdapter;
|
|
419
|
+
exports.PHASE_CONTROL_POINTS = PHASE_CONTROL_POINTS;
|
|
420
|
+
exports.PfnnNetwork = PfnnNetwork;
|
|
421
|
+
exports.PureJsInferenceAdapter = PureJsInferenceAdapter;
|
|
422
|
+
exports.add = add;
|
|
423
|
+
exports.createBundledPfnn = createBundledPfnn;
|
|
424
|
+
exports.createNoOpInferenceAdapter = createNoOpInferenceAdapter;
|
|
425
|
+
exports.createOnnxNodeInferenceAdapter = createOnnxNodeInferenceAdapter;
|
|
426
|
+
exports.createPureJsInferenceAdapter = createPureJsInferenceAdapter;
|
|
427
|
+
exports.createTensor = createTensor;
|
|
428
|
+
exports.eluInPlace = eluInPlace;
|
|
429
|
+
exports.matmul = matmul;
|
|
430
|
+
exports.resolveOnnxModelPath = resolveOnnxModelPath;
|
|
431
|
+
//# sourceMappingURL=chunk-XJAN7CZG.cjs.map
|
|
432
|
+
//# sourceMappingURL=chunk-XJAN7CZG.cjs.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { init_ProvenanceSemiring, authorityWeight, ProvenanceSemiring } from './chunk-TJHVSBP2.js';
|
|
2
|
+
import { init_AgentRBAC, init_CompilerBase, getRBAC, UnauthorizedCompilerAccessError } from './chunk-QPSKHBJP.js';
|
|
3
|
+
|
|
4
|
+
// src/compiler/TraitCompositionCompiler.ts
|
|
5
|
+
init_AgentRBAC();
|
|
6
|
+
init_CompilerBase();
|
|
7
|
+
init_ProvenanceSemiring();
|
|
8
|
+
var CompositionConflictError = class extends Error {
|
|
9
|
+
constructor(traitA, traitB, conflictKey) {
|
|
10
|
+
super(
|
|
11
|
+
`Trait composition conflict: "${traitA}" and "${traitB}" both declare conflicting key "${conflictKey}".`
|
|
12
|
+
);
|
|
13
|
+
this.traitA = traitA;
|
|
14
|
+
this.traitB = traitB;
|
|
15
|
+
this.conflictKey = conflictKey;
|
|
16
|
+
this.name = "CompositionConflictError";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var MissingComponentError = class extends Error {
|
|
20
|
+
constructor(composedName, missingComponent) {
|
|
21
|
+
super(
|
|
22
|
+
`Composition "${composedName}" references unknown component trait "${missingComponent}". Register it in TraitBinder before compiling.`
|
|
23
|
+
);
|
|
24
|
+
this.composedName = composedName;
|
|
25
|
+
this.missingComponent = missingComponent;
|
|
26
|
+
this.name = "MissingComponentError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var TraitCompositionCompiler = class {
|
|
30
|
+
constructor(inheritanceResolver) {
|
|
31
|
+
this.inheritanceResolver = inheritanceResolver;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set or replace the trait inheritance resolver.
|
|
35
|
+
* Call this after constructing if the resolver becomes available later.
|
|
36
|
+
*/
|
|
37
|
+
setInheritanceResolver(resolver) {
|
|
38
|
+
this.inheritanceResolver = resolver;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Compile a set of composition declarations.
|
|
42
|
+
*
|
|
43
|
+
* @param decls - Declarations to compile.
|
|
44
|
+
* @param getHandler - Lookup a component handler by name.
|
|
45
|
+
* @param traitGraph - Optional TraitDependencyGraph; if supplied, new
|
|
46
|
+
* composed traits are registered there.
|
|
47
|
+
* @param agentToken - JWT token proving agent identity (optional for backwards compatibility).
|
|
48
|
+
* @returns Compiled ComposedTraitDef[], in declaration order.
|
|
49
|
+
* @throws UnauthorizedTraitCompositionAccessError if token is provided but invalid.
|
|
50
|
+
*/
|
|
51
|
+
compile(decls, getHandler, traitGraph, agentToken) {
|
|
52
|
+
this.validateAccess(agentToken);
|
|
53
|
+
return decls.map((decl) => this.compileOne(decl, getHandler, traitGraph));
|
|
54
|
+
}
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// RBAC enforcement
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
/**
|
|
59
|
+
* Validate agent has permission to compile trait compositions.
|
|
60
|
+
* Skips validation when no token is provided (backwards compatibility / testing).
|
|
61
|
+
*/
|
|
62
|
+
validateAccess(agentToken) {
|
|
63
|
+
if (!agentToken) return;
|
|
64
|
+
const rbac = getRBAC();
|
|
65
|
+
const decision = rbac.checkAccess({
|
|
66
|
+
token: agentToken,
|
|
67
|
+
resourceType: "ast" /* AST */,
|
|
68
|
+
operation: "read",
|
|
69
|
+
expectedWorkflowStep: "generate_assembly" /* GENERATE_ASSEMBLY */
|
|
70
|
+
});
|
|
71
|
+
if (!decision.allowed) {
|
|
72
|
+
throw new UnauthorizedTraitCompositionAccessError(decision, "TraitCompositionCompiler");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Private
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
compileOne(decl, getHandler, traitGraph) {
|
|
79
|
+
const handlers = decl.components.map((name) => {
|
|
80
|
+
const handler = getHandler(name);
|
|
81
|
+
if (!handler) throw new MissingComponentError(decl.name, name);
|
|
82
|
+
return { name, handler };
|
|
83
|
+
});
|
|
84
|
+
if (authorityWeight(
|
|
85
|
+
decl.provenance?.context?.authorityLevel ?? 0
|
|
86
|
+
) < 100) {
|
|
87
|
+
this.detectConflicts(handlers);
|
|
88
|
+
}
|
|
89
|
+
const semiring = new ProvenanceSemiring();
|
|
90
|
+
const applications = [];
|
|
91
|
+
for (const { name, handler } of handlers) {
|
|
92
|
+
let configAccumulator = {};
|
|
93
|
+
if (this.inheritanceResolver && this.inheritanceResolver.hasTrait(name)) {
|
|
94
|
+
const resolvedProps = this.inheritanceResolver.getFlattenedProperties(name);
|
|
95
|
+
configAccumulator = { ...resolvedProps };
|
|
96
|
+
}
|
|
97
|
+
if (handler.defaultConfig) {
|
|
98
|
+
configAccumulator = { ...configAccumulator, ...handler.defaultConfig };
|
|
99
|
+
}
|
|
100
|
+
applications.push({ name, config: configAccumulator });
|
|
101
|
+
}
|
|
102
|
+
if (decl.overrides) {
|
|
103
|
+
applications.push({
|
|
104
|
+
name: `${decl.name}_overrides`,
|
|
105
|
+
config: decl.overrides,
|
|
106
|
+
context: { authorityLevel: Number.MAX_SAFE_INTEGER }
|
|
107
|
+
// Overrides always win!
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const { config: merged, errors } = semiring.add(applications);
|
|
111
|
+
if (errors.length > 0) {
|
|
112
|
+
const match = errors[0].match(/Composition conflict: @(.+) and @(.+) both supply '(.+)'/);
|
|
113
|
+
if (match) {
|
|
114
|
+
throw new CompositionConflictError(match[1], match[2], match[3]);
|
|
115
|
+
} else {
|
|
116
|
+
throw new CompositionConflictError("Merge", "Failure", errors[0]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (this.inheritanceResolver && decl.components.length > 1) {
|
|
120
|
+
const diamonds = this.inheritanceResolver.detectDiamondInheritance(decl.components);
|
|
121
|
+
for (const diamond of diamonds) {
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (traitGraph) {
|
|
125
|
+
traitGraph.registerTrait({
|
|
126
|
+
name: decl.name,
|
|
127
|
+
requires: decl.components,
|
|
128
|
+
conflicts: []
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
name: decl.name,
|
|
133
|
+
components: decl.components,
|
|
134
|
+
defaultConfig: merged
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Naive conflict check: if handler A's `conflicts` array includes handler B's
|
|
139
|
+
* name (or vice-versa), throw.
|
|
140
|
+
*/
|
|
141
|
+
detectConflicts(handlers) {
|
|
142
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
143
|
+
const a = handlers[i];
|
|
144
|
+
const aConflicts = a.handler.conflicts ?? [];
|
|
145
|
+
for (let j = i + 1; j < handlers.length; j++) {
|
|
146
|
+
const b = handlers[j];
|
|
147
|
+
const bConflicts = b.handler.conflicts ?? [];
|
|
148
|
+
if (aConflicts.includes(b.name) || bConflicts.includes(a.name)) {
|
|
149
|
+
throw new CompositionConflictError(a.name, b.name, b.name);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var UnauthorizedTraitCompositionAccessError = class extends UnauthorizedCompilerAccessError {
|
|
156
|
+
constructor(decision, compilerName) {
|
|
157
|
+
super(decision, "trait composition", compilerName);
|
|
158
|
+
this.name = "UnauthorizedTraitCompositionAccessError";
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export { CompositionConflictError, MissingComponentError, TraitCompositionCompiler, UnauthorizedTraitCompositionAccessError };
|
|
163
|
+
//# sourceMappingURL=chunk-XKTPFXGA.js.map
|
|
164
|
+
//# sourceMappingURL=chunk-XKTPFXGA.js.map
|