@holoscript/core 8.0.13 → 8.0.14
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 +14 -0
- package/bin/holo-decision.mjs +133 -0
- package/dist/{GLTFPipeline-L76YTXKA.js → GLTFPipeline-6LS3UDYX.js} +6 -6
- package/dist/{GLTFPipeline-ZWJN7GI6.cjs → GLTFPipeline-VTI6PRRQ.cjs} +10 -10
- package/dist/{HoloCompositionParser-P4Y3CXKQ.js → HoloCompositionParser-GILABNN3.js} +4 -4
- package/dist/{HoloCompositionParser-6GW2BZID.cjs → HoloCompositionParser-ZVRYVEA5.cjs} +11 -11
- package/dist/{HoloScriptPlusParser-RFNHRMPE.cjs → HoloScriptPlusParser-WTPRPRPR.cjs} +7 -7
- package/dist/{HoloScriptPlusParser-HQV6IJAH.js → HoloScriptPlusParser-ZP53ECSL.js} +4 -4
- package/dist/{SceneIRCompiler-KWUFHZ4O.cjs → SceneIRCompiler-7KQ5NKAU.cjs} +11 -11
- package/dist/{SceneIRCompiler-63KA3M2F.js → SceneIRCompiler-VX75RB6H.js} +6 -6
- package/dist/{chunk-EM2OGPYE.js → chunk-2GKF7JQ6.js} +3 -3
- package/dist/{chunk-HVX7QQYK.js → chunk-3KHRZTNW.js} +3 -3
- package/dist/{chunk-UTUD6GJI.js → chunk-42Z3SVHQ.js} +3 -3
- package/dist/{chunk-A4OOLBZD.js → chunk-47XZ62KM.js} +5 -5
- package/dist/{chunk-GGR7QUKK.cjs → chunk-4CRMVEON.cjs} +37 -37
- package/dist/{chunk-QBY7LRN2.js → chunk-4NEPHK2K.js} +3 -3
- package/dist/{chunk-65S62L4D.cjs → chunk-5B2AJKA5.cjs} +20 -20
- package/dist/{chunk-PJFTTSKE.js → chunk-5T6BWIB7.js} +4 -4
- package/dist/{chunk-KFVNCW4Q.js → chunk-62OYZT6Q.js} +3 -3
- package/dist/{chunk-Y57AVOM2.cjs → chunk-645EWDZW.cjs} +4 -4
- package/dist/{chunk-BP4KTMLY.js → chunk-6FCNMTL5.js} +4 -4
- package/dist/{chunk-77QI552M.js → chunk-73EDVY5D.js} +3 -3
- package/dist/{chunk-7IDJDMPU.cjs → chunk-7FYSSI3C.cjs} +27 -2
- package/dist/{chunk-WNYXT4TE.cjs → chunk-7ITJP33Q.cjs} +3 -3
- package/dist/chunk-7ZKQ32XK.js +1571 -0
- package/dist/{chunk-P7JEKJTZ.cjs → chunk-B6JHTTMR.cjs} +25 -14
- package/dist/{chunk-FG6PYGIZ.js → chunk-BLCWQ225.js} +4 -4
- package/dist/{chunk-FRSKLX6I.js → chunk-C73GVAYC.js} +10 -7
- package/dist/{chunk-PXVAPGTR.cjs → chunk-CESMPUEZ.cjs} +3774 -1138
- package/dist/{chunk-SQXAZHDG.js → chunk-CHIZSMWD.js} +3 -3
- package/dist/{chunk-G35CAQ7I.cjs → chunk-D44CEFY4.cjs} +5 -5
- package/dist/{chunk-TC7JEO6R.cjs → chunk-ERYKKPHW.cjs} +711 -52
- package/dist/{chunk-DJ5BNRIS.js → chunk-EYHPTJ3F.js} +3675 -1046
- package/dist/{chunk-J3UHV5T4.cjs → chunk-FGXJPJ3W.cjs} +4 -4
- package/dist/{chunk-IJU6AS67.cjs → chunk-FHR2AVMA.cjs} +23 -23
- package/dist/{chunk-LMB555QB.cjs → chunk-FOM36K5I.cjs} +18 -18
- package/dist/{chunk-ZRPALBQB.cjs → chunk-GGH3ZYDB.cjs} +5 -5
- package/dist/{chunk-2BYAUHBO.js → chunk-GI5YYZH6.js} +3 -3
- package/dist/{chunk-VTEXJOSD.cjs → chunk-GYJLP4BO.cjs} +30 -30
- package/dist/{chunk-OC6GV5QH.cjs → chunk-HCONR4J6.cjs} +38 -38
- package/dist/{chunk-B3CWTCK2.js → chunk-IA7FCSRY.js} +27 -2
- package/dist/{chunk-5FYMCVBY.js → chunk-IXFNA5TT.js} +4 -4
- package/dist/{chunk-G6KACNMO.js → chunk-JCVSCKUH.js} +4 -4
- package/dist/{chunk-FHVPN7BN.js → chunk-JQCXLKAU.js} +3 -3
- package/dist/{chunk-F3YT6GUF.cjs → chunk-KLM6QD6D.cjs} +14 -14
- package/dist/{chunk-UGQ3QNV6.js → chunk-KOGPVAP6.js} +24 -8
- package/dist/{chunk-CKV5NYAE.js → chunk-KYJD2UMV.js} +4 -4
- package/dist/{chunk-LB3ZZMKT.cjs → chunk-L4DBUX3N.cjs} +10 -10
- package/dist/{chunk-RXQNRZ5F.js → chunk-LGRKBTPM.js} +3 -3
- package/dist/{chunk-PDXX5UI4.cjs → chunk-LQNL3IYV.cjs} +38 -38
- package/dist/{chunk-WWNCM473.js → chunk-M7XR3F53.js} +4 -4
- package/dist/{chunk-IFW5IW4L.cjs → chunk-ML4V5PVU.cjs} +670 -627
- package/dist/{chunk-Q4K2GEMW.cjs → chunk-N7IYRAFG.cjs} +13 -10
- package/dist/chunk-N7MIIDLI.cjs +1605 -0
- package/dist/{chunk-G6EKZHXY.js → chunk-NWKARJM2.js} +4 -4
- package/dist/{chunk-VVAAZITA.cjs → chunk-OOP4S3GU.cjs} +5 -5
- package/dist/{chunk-U3D4SYQ5.js → chunk-ORBVCOTC.js} +3 -3
- package/dist/{chunk-RRQIAJLQ.cjs → chunk-OSKGCXAQ.cjs} +5 -5
- package/dist/{chunk-QEDMOGF3.cjs → chunk-P65OIMJT.cjs} +7 -7
- package/dist/{chunk-QM7FJB5W.js → chunk-PSWCJQS4.js} +4 -4
- package/dist/{chunk-RZ2EPXO3.cjs → chunk-PZ46WRHX.cjs} +8 -8
- package/dist/{chunk-AATYYLYK.js → chunk-Q4J2K7FI.js} +16 -5
- package/dist/{chunk-ONPVM4IV.js → chunk-QLPRI3QW.js} +698 -45
- package/dist/{chunk-WTH23ISI.js → chunk-R5VKLUMR.js} +4 -4
- package/dist/{chunk-NQN5LFN4.cjs → chunk-REN3LHO6.cjs} +19 -19
- package/dist/{chunk-JEJ7TT54.js → chunk-RVN7OPCP.js} +4 -4
- package/dist/{chunk-ZK7KX5CD.cjs → chunk-SE2Y5BSL.cjs} +6 -6
- package/dist/{chunk-2X3IPCBK.cjs → chunk-SKVBUGMC.cjs} +7 -7
- package/dist/{chunk-GZPUA2TL.cjs → chunk-SNMQUWIO.cjs} +10 -10
- package/dist/{chunk-OIBRWLPY.cjs → chunk-TKDDIE3T.cjs} +54 -3
- package/dist/{chunk-SQAAWO4V.cjs → chunk-TMNAKNV2.cjs} +5 -5
- package/dist/{chunk-5LVFTGKH.js → chunk-TZQKJOPC.js} +3 -3
- package/dist/{chunk-TSTFYGGX.js → chunk-UKEK2NZJ.js} +3 -3
- package/dist/{chunk-3IUHTGDD.cjs → chunk-VA7THINF.cjs} +38 -38
- package/dist/{chunk-Z557DVYN.js → chunk-VMCR5QVI.js} +4 -4
- package/dist/{chunk-IS7NTKY5.cjs → chunk-VTFLKSJL.cjs} +14 -14
- package/dist/{chunk-RVNXBF2M.js → chunk-VXHB6ZHY.js} +4 -4
- package/dist/{chunk-S4O7CFHQ.cjs → chunk-VZI7S7P6.cjs} +7 -7
- package/dist/{chunk-BQJ3YBF3.js → chunk-W4AJMMQR.js} +667 -628
- package/dist/{chunk-2KKOYZYI.cjs → chunk-XZC75AJ4.cjs} +5 -5
- package/dist/{chunk-FWCHPCD4.js → chunk-Y2OCKXVD.js} +4 -4
- package/dist/{chunk-XF63CZ7E.cjs → chunk-YBM34FUJ.cjs} +6 -6
- package/dist/{chunk-DUG3OQAS.js → chunk-YDSNDCV3.js} +3 -3
- package/dist/{chunk-566ZB4LZ.cjs → chunk-YM7UUYR5.cjs} +5 -5
- package/dist/{chunk-BCP4E7MD.cjs → chunk-YMI3ED3B.cjs} +26 -10
- package/dist/{chunk-CP7V3ATL.js → chunk-Z7NUL73U.js} +51 -4
- package/dist/cli/holoscript-runner.cjs +10 -10
- package/dist/cli/holoscript-runner.js +3 -3
- package/dist/compiler/agent-inference.cjs +8 -8
- package/dist/compiler/agent-inference.js +4 -4
- package/dist/compiler/android-xr.cjs +7 -7
- package/dist/compiler/android-xr.js +5 -5
- package/dist/compiler/android.cjs +6 -6
- package/dist/compiler/android.js +4 -4
- package/dist/compiler/context.cjs +6 -6
- package/dist/compiler/context.js +3 -3
- package/dist/compiler/daimon-seed.cjs +9 -9
- package/dist/compiler/daimon-seed.js +4 -4
- package/dist/compiler/domain-block-utils.cjs +165 -165
- package/dist/compiler/domain-block-utils.js +4 -4
- package/dist/compiler/dtdl.cjs +7 -7
- package/dist/compiler/dtdl.js +4 -4
- package/dist/compiler/gltf-pipeline.cjs +8 -8
- package/dist/compiler/gltf-pipeline.js +1 -1
- package/dist/compiler/godot.cjs +6 -6
- package/dist/compiler/godot.js +5 -5
- package/dist/compiler/incremental.cjs +8 -8
- package/dist/compiler/incremental.js +3 -3
- package/dist/compiler/index.cjs +871 -207
- package/dist/compiler/index.d.ts +21 -1
- package/dist/compiler/index.js +696 -60
- package/dist/compiler/ios.cjs +6 -6
- package/dist/compiler/ios.js +4 -4
- package/dist/compiler/llm-provider-capabilities.cjs +6 -6
- package/dist/compiler/llm-provider-capabilities.js +3 -3
- package/dist/compiler/openxr.cjs +6 -6
- package/dist/compiler/openxr.js +5 -5
- package/dist/compiler/sdf.cjs +7 -7
- package/dist/compiler/sdf.js +5 -5
- package/dist/compiler/state.cjs +6 -6
- package/dist/compiler/state.js +4 -4
- package/dist/compiler/trait-composition.cjs +7 -7
- package/dist/compiler/trait-composition.js +3 -3
- package/dist/compiler/unity.cjs +6 -6
- package/dist/compiler/unity.js +5 -5
- package/dist/compiler/unreal.cjs +7 -7
- package/dist/compiler/unreal.js +5 -5
- package/dist/compiler/urdf.cjs +14 -14
- package/dist/compiler/urdf.js +5 -5
- package/dist/compiler/usd-physics.cjs +7 -7
- package/dist/compiler/usd-physics.js +4 -4
- package/dist/compiler/visionos.cjs +6 -6
- package/dist/compiler/visionos.js +5 -5
- package/dist/compiler/vrchat.cjs +7 -7
- package/dist/compiler/vrchat.js +5 -5
- package/dist/compiler/wasm.cjs +10 -10
- package/dist/compiler/wasm.js +5 -5
- package/dist/compiler/webgpu.cjs +6 -6
- package/dist/compiler/webgpu.js +5 -5
- package/dist/entries/scripting.cjs +5 -5
- package/dist/entries/scripting.js +1 -1
- package/dist/evolution/index.cjs +17 -17
- package/dist/evolution/index.js +5 -5
- package/dist/index.cjs +915 -704
- package/dist/index.d.ts +70 -5
- package/dist/index.js +191 -108
- package/dist/parser.cjs +18 -18
- package/dist/parser.js +4 -4
- package/dist/reconstruction/index.cjs +127 -38
- package/dist/reconstruction/index.d.ts +159 -0
- package/dist/reconstruction/index.js +11 -2
- package/dist/runtime.d.ts +1 -0
- package/dist/traitDocs/traitDocs.cjs +8 -8
- package/dist/traitDocs/traitDocs.js +2 -2
- package/dist/traits/index.cjs +566 -471
- package/dist/traits/index.js +93 -11
- package/package.json +20 -16
- package/dist/chunk-DVHZD5HV.cjs +0 -639
- package/dist/chunk-G72754QB.js +0 -625
|
@@ -2727,6 +2727,44 @@ var evolveProgramHandler = {
|
|
|
2727
2727
|
}
|
|
2728
2728
|
};
|
|
2729
2729
|
|
|
2730
|
+
// src/traits/FreezeWhenTrait.ts
|
|
2731
|
+
var DEFAULT_EXEMPT = ["fix", "native-format", "infra-repair"];
|
|
2732
|
+
var freezeWhenHandler = {
|
|
2733
|
+
name: "freeze_when",
|
|
2734
|
+
defaultConfig: {
|
|
2735
|
+
id: "",
|
|
2736
|
+
scope: "",
|
|
2737
|
+
signal: "",
|
|
2738
|
+
unfreeze: "",
|
|
2739
|
+
exempt: DEFAULT_EXEMPT,
|
|
2740
|
+
severity: "advisory",
|
|
2741
|
+
reason: "",
|
|
2742
|
+
repair: ""
|
|
2743
|
+
},
|
|
2744
|
+
onAttach(node, config, context) {
|
|
2745
|
+
node.__freezeWhen = {
|
|
2746
|
+
id: config.id,
|
|
2747
|
+
scope: config.scope,
|
|
2748
|
+
signal: config.signal,
|
|
2749
|
+
unfreeze: config.unfreeze,
|
|
2750
|
+
exempt: config.exempt ?? DEFAULT_EXEMPT,
|
|
2751
|
+
severity: config.severity ?? "advisory",
|
|
2752
|
+
reason: config.reason ?? "",
|
|
2753
|
+
repair: config.repair ?? ""
|
|
2754
|
+
};
|
|
2755
|
+
context.emit?.("freeze_declared", {
|
|
2756
|
+
node,
|
|
2757
|
+
rule: node.__freezeWhen,
|
|
2758
|
+
derived: true,
|
|
2759
|
+
nativeExempt: true
|
|
2760
|
+
});
|
|
2761
|
+
},
|
|
2762
|
+
onDetach(node, _config, context) {
|
|
2763
|
+
delete node.__freezeWhen;
|
|
2764
|
+
context.emit?.("freeze_when_detached", { node });
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2730
2768
|
// src/traits/AiUpscalingTrait.ts
|
|
2731
2769
|
var aiUpscalingHandler = {
|
|
2732
2770
|
name: "ai_upscaling",
|
|
@@ -24325,6 +24363,200 @@ export default IframeSandbox;`;
|
|
|
24325
24363
|
}
|
|
24326
24364
|
};
|
|
24327
24365
|
|
|
24366
|
+
// src/traits/RetryTrait.ts
|
|
24367
|
+
function computeDelay(config, attempt) {
|
|
24368
|
+
let delay;
|
|
24369
|
+
switch (config.backoff) {
|
|
24370
|
+
case "exponential":
|
|
24371
|
+
delay = config.base_delay_ms * Math.pow(2, attempt);
|
|
24372
|
+
break;
|
|
24373
|
+
case "linear":
|
|
24374
|
+
delay = config.base_delay_ms * (attempt + 1);
|
|
24375
|
+
break;
|
|
24376
|
+
case "constant":
|
|
24377
|
+
default:
|
|
24378
|
+
delay = config.base_delay_ms;
|
|
24379
|
+
break;
|
|
24380
|
+
}
|
|
24381
|
+
delay = Math.min(delay, config.max_delay_ms);
|
|
24382
|
+
if (config.jitter > 0) {
|
|
24383
|
+
const jitterAmount = delay * config.jitter;
|
|
24384
|
+
delay += Math.random() * jitterAmount * 2 - jitterAmount;
|
|
24385
|
+
}
|
|
24386
|
+
return Math.max(0, Math.round(delay));
|
|
24387
|
+
}
|
|
24388
|
+
var retryHandler = {
|
|
24389
|
+
name: "retry",
|
|
24390
|
+
defaultConfig: {
|
|
24391
|
+
max_retries: 3,
|
|
24392
|
+
base_delay_ms: 1e3,
|
|
24393
|
+
max_delay_ms: 3e4,
|
|
24394
|
+
backoff: "exponential",
|
|
24395
|
+
jitter: 0.1,
|
|
24396
|
+
circuit_threshold: 5,
|
|
24397
|
+
circuit_reset_ms: 6e4
|
|
24398
|
+
},
|
|
24399
|
+
onAttach(node, _config, _context) {
|
|
24400
|
+
const state = {
|
|
24401
|
+
circuit: "closed",
|
|
24402
|
+
consecutiveFailures: 0,
|
|
24403
|
+
circuitOpenedAt: 0,
|
|
24404
|
+
totalAttempts: 0,
|
|
24405
|
+
totalSuccesses: 0,
|
|
24406
|
+
totalFailures: 0,
|
|
24407
|
+
pendingActions: /* @__PURE__ */ new Map(),
|
|
24408
|
+
actionCounter: 0
|
|
24409
|
+
};
|
|
24410
|
+
node.__retryState = state;
|
|
24411
|
+
},
|
|
24412
|
+
onDetach(node, _config, _context) {
|
|
24413
|
+
delete node.__retryState;
|
|
24414
|
+
},
|
|
24415
|
+
onUpdate(node, config, context, _delta) {
|
|
24416
|
+
const state = node.__retryState;
|
|
24417
|
+
if (!state) return;
|
|
24418
|
+
if (state.circuit === "open") {
|
|
24419
|
+
const elapsed = Date.now() - state.circuitOpenedAt;
|
|
24420
|
+
if (elapsed >= config.circuit_reset_ms) {
|
|
24421
|
+
state.circuit = "half-open";
|
|
24422
|
+
context.emit?.("retry:circuit_half", {
|
|
24423
|
+
testAttempt: state.totalAttempts + 1
|
|
24424
|
+
});
|
|
24425
|
+
}
|
|
24426
|
+
}
|
|
24427
|
+
},
|
|
24428
|
+
onEvent(node, config, context, event) {
|
|
24429
|
+
const state = node.__retryState;
|
|
24430
|
+
if (!state) return;
|
|
24431
|
+
const eventType = typeof event === "string" ? event : event.type;
|
|
24432
|
+
const payload = extractPayload(event);
|
|
24433
|
+
switch (eventType) {
|
|
24434
|
+
case "retry:execute": {
|
|
24435
|
+
const actionName = payload.action;
|
|
24436
|
+
if (!actionName) break;
|
|
24437
|
+
if (state.circuit === "open") {
|
|
24438
|
+
context.emit?.("retry:failure", {
|
|
24439
|
+
actionName,
|
|
24440
|
+
attempt: 0,
|
|
24441
|
+
error: "Circuit breaker is OPEN"
|
|
24442
|
+
});
|
|
24443
|
+
break;
|
|
24444
|
+
}
|
|
24445
|
+
const retryId = `retry_${state.actionCounter++}`;
|
|
24446
|
+
state.pendingActions.set(retryId, {
|
|
24447
|
+
actionName,
|
|
24448
|
+
attempt: 0,
|
|
24449
|
+
startedAt: Date.now()
|
|
24450
|
+
});
|
|
24451
|
+
state.totalAttempts++;
|
|
24452
|
+
context.emit?.("retry:attempt", {
|
|
24453
|
+
retryId,
|
|
24454
|
+
actionName,
|
|
24455
|
+
attempt: 0,
|
|
24456
|
+
maxRetries: config.max_retries
|
|
24457
|
+
});
|
|
24458
|
+
context.emit?.(actionName, {
|
|
24459
|
+
...payload.params,
|
|
24460
|
+
__retryId: retryId
|
|
24461
|
+
});
|
|
24462
|
+
break;
|
|
24463
|
+
}
|
|
24464
|
+
case "retry:action_result": {
|
|
24465
|
+
const retryId = payload.retryId;
|
|
24466
|
+
const success = payload.success;
|
|
24467
|
+
const error = payload.error;
|
|
24468
|
+
const pending = state.pendingActions.get(retryId);
|
|
24469
|
+
if (!pending) break;
|
|
24470
|
+
if (success) {
|
|
24471
|
+
state.totalSuccesses++;
|
|
24472
|
+
state.consecutiveFailures = 0;
|
|
24473
|
+
state.pendingActions.delete(retryId);
|
|
24474
|
+
if (state.circuit === "half-open") {
|
|
24475
|
+
state.circuit = "closed";
|
|
24476
|
+
context.emit?.("retry:circuit_close", {
|
|
24477
|
+
recoveredAfterMs: Date.now() - state.circuitOpenedAt
|
|
24478
|
+
});
|
|
24479
|
+
}
|
|
24480
|
+
context.emit?.("retry:success", {
|
|
24481
|
+
actionName: pending.actionName,
|
|
24482
|
+
attempt: pending.attempt,
|
|
24483
|
+
elapsed: Date.now() - pending.startedAt
|
|
24484
|
+
});
|
|
24485
|
+
} else {
|
|
24486
|
+
state.totalFailures++;
|
|
24487
|
+
state.consecutiveFailures++;
|
|
24488
|
+
pending.attempt++;
|
|
24489
|
+
context.emit?.("retry:failure", {
|
|
24490
|
+
actionName: pending.actionName,
|
|
24491
|
+
attempt: pending.attempt,
|
|
24492
|
+
error: error ?? "unknown"
|
|
24493
|
+
});
|
|
24494
|
+
if (state.consecutiveFailures >= config.circuit_threshold) {
|
|
24495
|
+
state.circuit = "open";
|
|
24496
|
+
state.circuitOpenedAt = Date.now();
|
|
24497
|
+
state.pendingActions.delete(retryId);
|
|
24498
|
+
context.emit?.("retry:circuit_open", {
|
|
24499
|
+
consecutiveFailures: state.consecutiveFailures,
|
|
24500
|
+
resetMs: config.circuit_reset_ms
|
|
24501
|
+
});
|
|
24502
|
+
break;
|
|
24503
|
+
}
|
|
24504
|
+
if (state.circuit === "half-open") {
|
|
24505
|
+
state.circuit = "open";
|
|
24506
|
+
state.circuitOpenedAt = Date.now();
|
|
24507
|
+
state.pendingActions.delete(retryId);
|
|
24508
|
+
context.emit?.("retry:circuit_open", {
|
|
24509
|
+
consecutiveFailures: state.consecutiveFailures,
|
|
24510
|
+
resetMs: config.circuit_reset_ms
|
|
24511
|
+
});
|
|
24512
|
+
break;
|
|
24513
|
+
}
|
|
24514
|
+
if (pending.attempt > config.max_retries) {
|
|
24515
|
+
state.pendingActions.delete(retryId);
|
|
24516
|
+
context.emit?.("retry:exhausted", {
|
|
24517
|
+
actionName: pending.actionName,
|
|
24518
|
+
totalAttempts: pending.attempt
|
|
24519
|
+
});
|
|
24520
|
+
} else {
|
|
24521
|
+
const delay = computeDelay(config, pending.attempt - 1);
|
|
24522
|
+
state.totalAttempts++;
|
|
24523
|
+
setTimeout(() => {
|
|
24524
|
+
if (!node.__retryState) return;
|
|
24525
|
+
context.emit?.("retry:attempt", {
|
|
24526
|
+
retryId,
|
|
24527
|
+
actionName: pending.actionName,
|
|
24528
|
+
attempt: pending.attempt,
|
|
24529
|
+
maxRetries: config.max_retries
|
|
24530
|
+
});
|
|
24531
|
+
context.emit?.(pending.actionName, {
|
|
24532
|
+
__retryId: retryId
|
|
24533
|
+
});
|
|
24534
|
+
}, delay);
|
|
24535
|
+
}
|
|
24536
|
+
}
|
|
24537
|
+
break;
|
|
24538
|
+
}
|
|
24539
|
+
case "retry:reset_circuit": {
|
|
24540
|
+
state.circuit = "closed";
|
|
24541
|
+
state.consecutiveFailures = 0;
|
|
24542
|
+
context.emit?.("retry:circuit_close", { recoveredAfterMs: 0 });
|
|
24543
|
+
break;
|
|
24544
|
+
}
|
|
24545
|
+
case "retry:get_status": {
|
|
24546
|
+
context.emit?.("retry:status", {
|
|
24547
|
+
circuit: state.circuit,
|
|
24548
|
+
consecutiveFailures: state.consecutiveFailures,
|
|
24549
|
+
totalAttempts: state.totalAttempts,
|
|
24550
|
+
totalSuccesses: state.totalSuccesses,
|
|
24551
|
+
totalFailures: state.totalFailures,
|
|
24552
|
+
pending: state.pendingActions.size
|
|
24553
|
+
});
|
|
24554
|
+
break;
|
|
24555
|
+
}
|
|
24556
|
+
}
|
|
24557
|
+
}
|
|
24558
|
+
};
|
|
24559
|
+
|
|
24328
24560
|
// src/traits/SchedulerTrait.ts
|
|
24329
24561
|
var schedulerHandler = {
|
|
24330
24562
|
name: "scheduler",
|
|
@@ -25414,6 +25646,110 @@ function addEntry(state, config, context, level, payload) {
|
|
|
25414
25646
|
}
|
|
25415
25647
|
}
|
|
25416
25648
|
|
|
25649
|
+
// src/traits/CacheTrait.ts
|
|
25650
|
+
var cacheHandler = {
|
|
25651
|
+
name: "cache",
|
|
25652
|
+
defaultConfig: {
|
|
25653
|
+
max_size: 1e3,
|
|
25654
|
+
default_ttl_ms: 6e4,
|
|
25655
|
+
eviction_policy: "lru"
|
|
25656
|
+
},
|
|
25657
|
+
onAttach(node, _config, _context) {
|
|
25658
|
+
node.__cacheState = {
|
|
25659
|
+
entries: /* @__PURE__ */ new Map(),
|
|
25660
|
+
hits: 0,
|
|
25661
|
+
misses: 0,
|
|
25662
|
+
evictions: 0
|
|
25663
|
+
};
|
|
25664
|
+
},
|
|
25665
|
+
onDetach(node) {
|
|
25666
|
+
delete node.__cacheState;
|
|
25667
|
+
},
|
|
25668
|
+
onUpdate(node, config, _context, _delta) {
|
|
25669
|
+
const state = node.__cacheState;
|
|
25670
|
+
if (!state) return;
|
|
25671
|
+
const now = Date.now();
|
|
25672
|
+
for (const [key, entry] of state.entries) {
|
|
25673
|
+
if (entry.expiresAt > 0 && now >= entry.expiresAt) {
|
|
25674
|
+
state.entries.delete(key);
|
|
25675
|
+
state.evictions++;
|
|
25676
|
+
}
|
|
25677
|
+
}
|
|
25678
|
+
},
|
|
25679
|
+
onEvent(node, config, context, event) {
|
|
25680
|
+
const state = node.__cacheState;
|
|
25681
|
+
if (!state) return;
|
|
25682
|
+
const eventType = typeof event === "string" ? event : event.type;
|
|
25683
|
+
switch (eventType) {
|
|
25684
|
+
case "cache:set": {
|
|
25685
|
+
const key = event.key;
|
|
25686
|
+
if (!key) break;
|
|
25687
|
+
const ttl = event.ttl ?? config.default_ttl_ms;
|
|
25688
|
+
if (state.entries.size >= config.max_size && !state.entries.has(key)) {
|
|
25689
|
+
evictOne(state, config, context);
|
|
25690
|
+
}
|
|
25691
|
+
const now = Date.now();
|
|
25692
|
+
state.entries.set(key, {
|
|
25693
|
+
value: event.value,
|
|
25694
|
+
expiresAt: ttl > 0 ? now + ttl : 0,
|
|
25695
|
+
accessedAt: now,
|
|
25696
|
+
createdAt: now
|
|
25697
|
+
});
|
|
25698
|
+
break;
|
|
25699
|
+
}
|
|
25700
|
+
case "cache:get": {
|
|
25701
|
+
const key = event.key;
|
|
25702
|
+
if (!key) break;
|
|
25703
|
+
const entry = state.entries.get(key);
|
|
25704
|
+
if (entry && (entry.expiresAt === 0 || Date.now() < entry.expiresAt)) {
|
|
25705
|
+
state.hits++;
|
|
25706
|
+
entry.accessedAt = Date.now();
|
|
25707
|
+
context.emit?.("cache:result", { key, value: entry.value, hit: true });
|
|
25708
|
+
} else {
|
|
25709
|
+
state.misses++;
|
|
25710
|
+
if (entry) state.entries.delete(key);
|
|
25711
|
+
context.emit?.("cache:result", { key, value: void 0, hit: false });
|
|
25712
|
+
}
|
|
25713
|
+
break;
|
|
25714
|
+
}
|
|
25715
|
+
case "cache:invalidate": {
|
|
25716
|
+
const key = event.key;
|
|
25717
|
+
if (key) state.entries.delete(key);
|
|
25718
|
+
break;
|
|
25719
|
+
}
|
|
25720
|
+
case "cache:clear": {
|
|
25721
|
+
state.entries.clear();
|
|
25722
|
+
break;
|
|
25723
|
+
}
|
|
25724
|
+
case "cache:get_stats": {
|
|
25725
|
+
context.emit?.("cache:stats", {
|
|
25726
|
+
hits: state.hits,
|
|
25727
|
+
misses: state.misses,
|
|
25728
|
+
size: state.entries.size,
|
|
25729
|
+
evictions: state.evictions,
|
|
25730
|
+
hitRate: state.hits + state.misses > 0 ? state.hits / (state.hits + state.misses) : 0
|
|
25731
|
+
});
|
|
25732
|
+
break;
|
|
25733
|
+
}
|
|
25734
|
+
}
|
|
25735
|
+
}
|
|
25736
|
+
};
|
|
25737
|
+
function evictOne(state, config, context) {
|
|
25738
|
+
if (state.entries.size === 0) return;
|
|
25739
|
+
let oldest = null;
|
|
25740
|
+
for (const [key, entry] of state.entries) {
|
|
25741
|
+
const time = config.eviction_policy === "lru" ? entry.accessedAt : entry.createdAt;
|
|
25742
|
+
if (!oldest || time < oldest.time) {
|
|
25743
|
+
oldest = { key, time };
|
|
25744
|
+
}
|
|
25745
|
+
}
|
|
25746
|
+
if (oldest) {
|
|
25747
|
+
state.entries.delete(oldest.key);
|
|
25748
|
+
state.evictions++;
|
|
25749
|
+
context.emit?.("cache:evict", { key: oldest.key, reason: config.eviction_policy });
|
|
25750
|
+
}
|
|
25751
|
+
}
|
|
25752
|
+
|
|
25417
25753
|
// src/traits/FairnessMonitorTrait.ts
|
|
25418
25754
|
var DEFAULT_POSITIVE_DECISION_VALUES = ["true", "approved", "approve", "pass", "1", "yes"];
|
|
25419
25755
|
var DEFAULT_CONFIG5 = {
|
|
@@ -44490,6 +44826,333 @@ var environmentalAudioHandler = {
|
|
|
44490
44826
|
}
|
|
44491
44827
|
};
|
|
44492
44828
|
|
|
44829
|
+
// src/traits/FluidSimulationTrait.ts
|
|
44830
|
+
function poly6Kernel(r, h) {
|
|
44831
|
+
if (r < 0 || r > h) return 0;
|
|
44832
|
+
const coeff = 315 / (64 * Math.PI * h ** 9);
|
|
44833
|
+
return coeff * (h * h - r * r) ** 3;
|
|
44834
|
+
}
|
|
44835
|
+
function spikyKernelGradient(dx, dy, dz, h) {
|
|
44836
|
+
const r = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
44837
|
+
if (r > h || r < 1e-5) return [0, 0, 0];
|
|
44838
|
+
const coeff = -45 / (Math.PI * h ** 6) * (h - r) ** 2;
|
|
44839
|
+
return [coeff * (dx / r), coeff * (dy / r), coeff * (dz / r)];
|
|
44840
|
+
}
|
|
44841
|
+
function viscosityKernelLaplacian(r, h) {
|
|
44842
|
+
if (r < 0 || r > h) return 0;
|
|
44843
|
+
return 45 / (Math.PI * h ** 6) * (h - r);
|
|
44844
|
+
}
|
|
44845
|
+
var SpatialHash = class {
|
|
44846
|
+
constructor(cellSize) {
|
|
44847
|
+
this.cells = /* @__PURE__ */ new Map();
|
|
44848
|
+
this.cellSize = cellSize;
|
|
44849
|
+
}
|
|
44850
|
+
key(x, y, z) {
|
|
44851
|
+
const cx = Math.floor(x / this.cellSize);
|
|
44852
|
+
const cy = Math.floor(y / this.cellSize);
|
|
44853
|
+
const cz = Math.floor(z / this.cellSize);
|
|
44854
|
+
return `${cx},${cy},${cz}`;
|
|
44855
|
+
}
|
|
44856
|
+
insert(id, pos) {
|
|
44857
|
+
const k = this.key(pos[0], pos[1], pos[2]);
|
|
44858
|
+
if (!this.cells.has(k)) this.cells.set(k, []);
|
|
44859
|
+
this.cells.get(k).push(id);
|
|
44860
|
+
}
|
|
44861
|
+
getNeighbors(pos) {
|
|
44862
|
+
const cx = Math.floor(pos[0] / this.cellSize);
|
|
44863
|
+
const cy = Math.floor(pos[1] / this.cellSize);
|
|
44864
|
+
const cz = Math.floor(pos[2] / this.cellSize);
|
|
44865
|
+
const result = [];
|
|
44866
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
44867
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
44868
|
+
for (let dz = -1; dz <= 1; dz++) {
|
|
44869
|
+
const k = `${cx + dx},${cy + dy},${cz + dz}`;
|
|
44870
|
+
const cell = this.cells.get(k);
|
|
44871
|
+
if (cell) result.push(...cell);
|
|
44872
|
+
}
|
|
44873
|
+
}
|
|
44874
|
+
}
|
|
44875
|
+
return result;
|
|
44876
|
+
}
|
|
44877
|
+
clear() {
|
|
44878
|
+
this.cells.clear();
|
|
44879
|
+
}
|
|
44880
|
+
};
|
|
44881
|
+
var FluidSimulationSystem = class {
|
|
44882
|
+
constructor(config = {}) {
|
|
44883
|
+
this.particles = /* @__PURE__ */ new Map();
|
|
44884
|
+
this.nextId = 0;
|
|
44885
|
+
this.boundaries = [];
|
|
44886
|
+
this.cfg = {
|
|
44887
|
+
restDensity: config.restDensity ?? 1e3,
|
|
44888
|
+
viscosity: config.viscosity ?? 1e-3,
|
|
44889
|
+
gravity: config.gravity ?? [0, -9.81, 0],
|
|
44890
|
+
solverType: config.solverType ?? "sph",
|
|
44891
|
+
timeStep: config.timeStep ?? 0.016,
|
|
44892
|
+
maxVelocity: config.maxVelocity ?? 100,
|
|
44893
|
+
smoothingRadius: config.smoothingRadius ?? 0.04,
|
|
44894
|
+
gridCellSize: config.gridCellSize ?? 0.04,
|
|
44895
|
+
particleRadius: config.particleRadius ?? 0.01,
|
|
44896
|
+
gasConstant: config.gasConstant ?? 8.314,
|
|
44897
|
+
surfaceTension: config.surfaceTension ?? 0.072
|
|
44898
|
+
};
|
|
44899
|
+
this.spatialHash = new SpatialHash(this.cfg.gridCellSize);
|
|
44900
|
+
}
|
|
44901
|
+
// ── Particle Management ────────────────────────────────────────────────
|
|
44902
|
+
addParticle(position, velocity) {
|
|
44903
|
+
const id = this.nextId++;
|
|
44904
|
+
this.particles.set(id, {
|
|
44905
|
+
id,
|
|
44906
|
+
position: [...position],
|
|
44907
|
+
velocity: velocity ? [...velocity] : [0, 0, 0],
|
|
44908
|
+
force: [0, 0, 0],
|
|
44909
|
+
density: this.cfg.restDensity,
|
|
44910
|
+
pressure: 0,
|
|
44911
|
+
mass: 1
|
|
44912
|
+
});
|
|
44913
|
+
return id;
|
|
44914
|
+
}
|
|
44915
|
+
getParticle(id) {
|
|
44916
|
+
return this.particles.get(id);
|
|
44917
|
+
}
|
|
44918
|
+
getParticles() {
|
|
44919
|
+
return Array.from(this.particles.values());
|
|
44920
|
+
}
|
|
44921
|
+
getParticleCount() {
|
|
44922
|
+
return this.particles.size;
|
|
44923
|
+
}
|
|
44924
|
+
removeParticle(id) {
|
|
44925
|
+
return this.particles.delete(id);
|
|
44926
|
+
}
|
|
44927
|
+
clearParticles() {
|
|
44928
|
+
this.particles.clear();
|
|
44929
|
+
this.nextId = 0;
|
|
44930
|
+
}
|
|
44931
|
+
// ── Boundary Management ────────────────────────────────────────────────
|
|
44932
|
+
addBoundary(boundary) {
|
|
44933
|
+
this.boundaries.push(boundary);
|
|
44934
|
+
}
|
|
44935
|
+
getBoundaries() {
|
|
44936
|
+
return [...this.boundaries];
|
|
44937
|
+
}
|
|
44938
|
+
clearBoundaries() {
|
|
44939
|
+
this.boundaries.length = 0;
|
|
44940
|
+
}
|
|
44941
|
+
// ── Configuration ──────────────────────────────────────────────────────
|
|
44942
|
+
getConfig() {
|
|
44943
|
+
return { ...this.cfg };
|
|
44944
|
+
}
|
|
44945
|
+
setConfig(partial) {
|
|
44946
|
+
Object.assign(this.cfg, partial);
|
|
44947
|
+
if (partial.gridCellSize !== void 0) {
|
|
44948
|
+
this.spatialHash = new SpatialHash(this.cfg.gridCellSize);
|
|
44949
|
+
}
|
|
44950
|
+
}
|
|
44951
|
+
// ── Simulation Step ────────────────────────────────────────────────────
|
|
44952
|
+
step(dt) {
|
|
44953
|
+
const h = this.cfg.smoothingRadius;
|
|
44954
|
+
const deltaT = dt ?? this.cfg.timeStep;
|
|
44955
|
+
const particles = Array.from(this.particles.values());
|
|
44956
|
+
this.spatialHash.clear();
|
|
44957
|
+
for (const p of particles) {
|
|
44958
|
+
this.spatialHash.insert(p.id, p.position);
|
|
44959
|
+
}
|
|
44960
|
+
for (const pi of particles) {
|
|
44961
|
+
let density = 0;
|
|
44962
|
+
for (const pj of particles) {
|
|
44963
|
+
const r = this.dist(pi.position, pj.position);
|
|
44964
|
+
density += pj.mass * poly6Kernel(r, h);
|
|
44965
|
+
}
|
|
44966
|
+
pi.density = Math.max(density, this.cfg.restDensity * 0.01);
|
|
44967
|
+
pi.pressure = this.cfg.gasConstant * (pi.density - this.cfg.restDensity);
|
|
44968
|
+
}
|
|
44969
|
+
for (const pi of particles) {
|
|
44970
|
+
pi.force = [
|
|
44971
|
+
this.cfg.gravity[0] * pi.mass,
|
|
44972
|
+
this.cfg.gravity[1] * pi.mass,
|
|
44973
|
+
this.cfg.gravity[2] * pi.mass
|
|
44974
|
+
];
|
|
44975
|
+
for (const pj of particles) {
|
|
44976
|
+
if (pi.id === pj.id) continue;
|
|
44977
|
+
const dx = pi.position[0] - pj.position[0];
|
|
44978
|
+
const dy = pi.position[1] - pj.position[1];
|
|
44979
|
+
const dz = pi.position[2] - pj.position[2];
|
|
44980
|
+
const r = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
44981
|
+
if (r < h && r > 1e-5) {
|
|
44982
|
+
const grad = spikyKernelGradient(dx, dy, dz, h);
|
|
44983
|
+
const pScale = -pj.mass * ((pi.pressure + pj.pressure) / (2 * pj.density));
|
|
44984
|
+
pi.force[0] += pScale * grad[0];
|
|
44985
|
+
pi.force[1] += pScale * grad[1];
|
|
44986
|
+
pi.force[2] += pScale * grad[2];
|
|
44987
|
+
const viscLap = viscosityKernelLaplacian(r, h);
|
|
44988
|
+
const vScale = this.cfg.viscosity * pj.mass * (1 / pj.density) * viscLap;
|
|
44989
|
+
pi.force[0] += vScale * (pj.velocity[0] - pi.velocity[0]);
|
|
44990
|
+
pi.force[1] += vScale * (pj.velocity[1] - pi.velocity[1]);
|
|
44991
|
+
pi.force[2] += vScale * (pj.velocity[2] - pi.velocity[2]);
|
|
44992
|
+
}
|
|
44993
|
+
}
|
|
44994
|
+
}
|
|
44995
|
+
for (const p of particles) {
|
|
44996
|
+
p.velocity[0] += p.force[0] / p.mass * deltaT;
|
|
44997
|
+
p.velocity[1] += p.force[1] / p.mass * deltaT;
|
|
44998
|
+
p.velocity[2] += p.force[2] / p.mass * deltaT;
|
|
44999
|
+
const speed = Math.sqrt(p.velocity[0] ** 2 + p.velocity[1] ** 2 + p.velocity[2] ** 2);
|
|
45000
|
+
if (speed > this.cfg.maxVelocity) {
|
|
45001
|
+
const scale = this.cfg.maxVelocity / speed;
|
|
45002
|
+
p.velocity[0] *= scale;
|
|
45003
|
+
p.velocity[1] *= scale;
|
|
45004
|
+
p.velocity[2] *= scale;
|
|
45005
|
+
}
|
|
45006
|
+
p.position[0] += p.velocity[0] * deltaT;
|
|
45007
|
+
p.position[1] += p.velocity[1] * deltaT;
|
|
45008
|
+
p.position[2] += p.velocity[2] * deltaT;
|
|
45009
|
+
}
|
|
45010
|
+
for (const p of particles) {
|
|
45011
|
+
this.applyBoundaries(p);
|
|
45012
|
+
}
|
|
45013
|
+
}
|
|
45014
|
+
// ── Density Queries ────────────────────────────────────────────────────
|
|
45015
|
+
getDensityAt(position) {
|
|
45016
|
+
const h = this.cfg.smoothingRadius;
|
|
45017
|
+
let density = 0;
|
|
45018
|
+
for (const p of this.particles.values()) {
|
|
45019
|
+
const r = this.dist(position, p.position);
|
|
45020
|
+
density += p.mass * poly6Kernel(r, h);
|
|
45021
|
+
}
|
|
45022
|
+
return density;
|
|
45023
|
+
}
|
|
45024
|
+
isInsideFluid(position) {
|
|
45025
|
+
return this.getDensityAt(position) > this.cfg.restDensity * 0.5;
|
|
45026
|
+
}
|
|
45027
|
+
// ── Statistics ─────────────────────────────────────────────────────────
|
|
45028
|
+
getKineticEnergy() {
|
|
45029
|
+
let energy = 0;
|
|
45030
|
+
for (const p of this.particles.values()) {
|
|
45031
|
+
energy += 0.5 * p.mass * (p.velocity[0] ** 2 + p.velocity[1] ** 2 + p.velocity[2] ** 2);
|
|
45032
|
+
}
|
|
45033
|
+
return energy;
|
|
45034
|
+
}
|
|
45035
|
+
getAverageDensity() {
|
|
45036
|
+
if (this.particles.size === 0) return 0;
|
|
45037
|
+
let total = 0;
|
|
45038
|
+
for (const p of this.particles.values()) total += p.density;
|
|
45039
|
+
return total / this.particles.size;
|
|
45040
|
+
}
|
|
45041
|
+
reset() {
|
|
45042
|
+
this.particles.clear();
|
|
45043
|
+
this.spatialHash.clear();
|
|
45044
|
+
this.boundaries.length = 0;
|
|
45045
|
+
this.nextId = 0;
|
|
45046
|
+
}
|
|
45047
|
+
// ── Private Helpers ────────────────────────────────────────────────────
|
|
45048
|
+
dist(a, b) {
|
|
45049
|
+
return Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + (a[2] - b[2]) ** 2);
|
|
45050
|
+
}
|
|
45051
|
+
applyBoundaries(p) {
|
|
45052
|
+
const pr = this.cfg.particleRadius;
|
|
45053
|
+
for (const b of this.boundaries) {
|
|
45054
|
+
if (b.type === "plane") {
|
|
45055
|
+
const dx = p.position[0] - b.position[0];
|
|
45056
|
+
const dy = p.position[1] - b.position[1];
|
|
45057
|
+
const dz = p.position[2] - b.position[2];
|
|
45058
|
+
const d = dx * b.normal[0] + dy * b.normal[1] + dz * b.normal[2];
|
|
45059
|
+
if (d < pr) {
|
|
45060
|
+
p.position[0] += b.normal[0] * (pr - d);
|
|
45061
|
+
p.position[1] += b.normal[1] * (pr - d);
|
|
45062
|
+
p.position[2] += b.normal[2] * (pr - d);
|
|
45063
|
+
const vn = p.velocity[0] * b.normal[0] + p.velocity[1] * b.normal[1] + p.velocity[2] * b.normal[2];
|
|
45064
|
+
if (vn < 0) {
|
|
45065
|
+
p.velocity[0] -= (1 + b.restitution) * vn * b.normal[0];
|
|
45066
|
+
p.velocity[1] -= (1 + b.restitution) * vn * b.normal[1];
|
|
45067
|
+
p.velocity[2] -= (1 + b.restitution) * vn * b.normal[2];
|
|
45068
|
+
}
|
|
45069
|
+
}
|
|
45070
|
+
} else if (b.type === "sphere") {
|
|
45071
|
+
const dx = p.position[0] - b.position[0];
|
|
45072
|
+
const dy = p.position[1] - b.position[1];
|
|
45073
|
+
const dz = p.position[2] - b.position[2];
|
|
45074
|
+
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
45075
|
+
const maxDist = b.radius - pr;
|
|
45076
|
+
if (dist > maxDist && dist > 1e-6) {
|
|
45077
|
+
const nx = dx / dist;
|
|
45078
|
+
const ny = dy / dist;
|
|
45079
|
+
const nz = dz / dist;
|
|
45080
|
+
p.position[0] = b.position[0] + nx * maxDist;
|
|
45081
|
+
p.position[1] = b.position[1] + ny * maxDist;
|
|
45082
|
+
p.position[2] = b.position[2] + nz * maxDist;
|
|
45083
|
+
const vn = p.velocity[0] * nx + p.velocity[1] * ny + p.velocity[2] * nz;
|
|
45084
|
+
if (vn > 0) {
|
|
45085
|
+
p.velocity[0] -= (1 + b.restitution) * vn * nx;
|
|
45086
|
+
p.velocity[1] -= (1 + b.restitution) * vn * ny;
|
|
45087
|
+
p.velocity[2] -= (1 + b.restitution) * vn * nz;
|
|
45088
|
+
}
|
|
45089
|
+
}
|
|
45090
|
+
} else if (b.type === "box") {
|
|
45091
|
+
const halfX = b.size[0] / 2;
|
|
45092
|
+
const halfY = b.size[1] / 2;
|
|
45093
|
+
const halfZ = b.size[2] / 2;
|
|
45094
|
+
const limit = pr;
|
|
45095
|
+
if (p.position[0] > b.position[0] + halfX - limit) {
|
|
45096
|
+
p.position[0] = b.position[0] + halfX - limit;
|
|
45097
|
+
p.velocity[0] *= -b.restitution;
|
|
45098
|
+
} else if (p.position[0] < b.position[0] - halfX + limit) {
|
|
45099
|
+
p.position[0] = b.position[0] - halfX + limit;
|
|
45100
|
+
p.velocity[0] *= -b.restitution;
|
|
45101
|
+
}
|
|
45102
|
+
if (p.position[1] > b.position[1] + halfY - limit) {
|
|
45103
|
+
p.position[1] = b.position[1] + halfY - limit;
|
|
45104
|
+
p.velocity[1] *= -b.restitution;
|
|
45105
|
+
} else if (p.position[1] < b.position[1] - halfY + limit) {
|
|
45106
|
+
p.position[1] = b.position[1] - halfY + limit;
|
|
45107
|
+
p.velocity[1] *= -b.restitution;
|
|
45108
|
+
}
|
|
45109
|
+
if (p.position[2] > b.position[2] + halfZ - limit) {
|
|
45110
|
+
p.position[2] = b.position[2] + halfZ - limit;
|
|
45111
|
+
p.velocity[2] *= -b.restitution;
|
|
45112
|
+
} else if (p.position[2] < b.position[2] - halfZ + limit) {
|
|
45113
|
+
p.position[2] = b.position[2] - halfZ + limit;
|
|
45114
|
+
p.velocity[2] *= -b.restitution;
|
|
45115
|
+
}
|
|
45116
|
+
}
|
|
45117
|
+
}
|
|
45118
|
+
}
|
|
45119
|
+
};
|
|
45120
|
+
var fluidSimulationHandler = {
|
|
45121
|
+
name: "fluid_simulation",
|
|
45122
|
+
defaultConfig: {},
|
|
45123
|
+
onAttach(node, config, ctx) {
|
|
45124
|
+
const instance = new FluidSimulationSystem(config);
|
|
45125
|
+
node.__fluid_simulation_instance = instance;
|
|
45126
|
+
ctx.emit("fluid_simulation_attached", { node, config });
|
|
45127
|
+
},
|
|
45128
|
+
onDetach(node, _config, ctx) {
|
|
45129
|
+
const instance = node.__fluid_simulation_instance;
|
|
45130
|
+
if (instance) {
|
|
45131
|
+
if (typeof instance.onDetach === "function") instance.onDetach(node, ctx);
|
|
45132
|
+
else if (typeof instance.dispose === "function") instance.dispose();
|
|
45133
|
+
else if (typeof instance.cleanup === "function") instance.cleanup();
|
|
45134
|
+
}
|
|
45135
|
+
ctx.emit("fluid_simulation_detached", { node });
|
|
45136
|
+
delete node.__fluid_simulation_instance;
|
|
45137
|
+
},
|
|
45138
|
+
onEvent(node, _config, ctx, event) {
|
|
45139
|
+
const instance = node.__fluid_simulation_instance;
|
|
45140
|
+
if (!instance) return;
|
|
45141
|
+
if (typeof instance.onEvent === "function") instance.onEvent(event);
|
|
45142
|
+
else if (typeof instance.emit === "function" && event.type) instance.emit(event);
|
|
45143
|
+
if (event.type === "fluid_simulation_configure" && event.payload) {
|
|
45144
|
+
Object.assign(instance, event.payload);
|
|
45145
|
+
ctx.emit("fluid_simulation_configured", { node });
|
|
45146
|
+
}
|
|
45147
|
+
},
|
|
45148
|
+
onUpdate(node, _config, ctx, dt) {
|
|
45149
|
+
const instance = node.__fluid_simulation_instance;
|
|
45150
|
+
if (!instance) return;
|
|
45151
|
+
if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
|
|
45152
|
+
else if (typeof instance.step === "function") instance.step(dt);
|
|
45153
|
+
}
|
|
45154
|
+
};
|
|
45155
|
+
|
|
44493
45156
|
// src/traits/GranularMaterialTrait.ts
|
|
44494
45157
|
function toVec3(v) {
|
|
44495
45158
|
if (Array.isArray(v)) {
|
|
@@ -53790,200 +54453,6 @@ var httpClientHandler = {
|
|
|
53790
54453
|
}
|
|
53791
54454
|
};
|
|
53792
54455
|
|
|
53793
|
-
// src/traits/RetryTrait.ts
|
|
53794
|
-
function computeDelay(config, attempt) {
|
|
53795
|
-
let delay;
|
|
53796
|
-
switch (config.backoff) {
|
|
53797
|
-
case "exponential":
|
|
53798
|
-
delay = config.base_delay_ms * Math.pow(2, attempt);
|
|
53799
|
-
break;
|
|
53800
|
-
case "linear":
|
|
53801
|
-
delay = config.base_delay_ms * (attempt + 1);
|
|
53802
|
-
break;
|
|
53803
|
-
case "constant":
|
|
53804
|
-
default:
|
|
53805
|
-
delay = config.base_delay_ms;
|
|
53806
|
-
break;
|
|
53807
|
-
}
|
|
53808
|
-
delay = Math.min(delay, config.max_delay_ms);
|
|
53809
|
-
if (config.jitter > 0) {
|
|
53810
|
-
const jitterAmount = delay * config.jitter;
|
|
53811
|
-
delay += Math.random() * jitterAmount * 2 - jitterAmount;
|
|
53812
|
-
}
|
|
53813
|
-
return Math.max(0, Math.round(delay));
|
|
53814
|
-
}
|
|
53815
|
-
var retryHandler = {
|
|
53816
|
-
name: "retry",
|
|
53817
|
-
defaultConfig: {
|
|
53818
|
-
max_retries: 3,
|
|
53819
|
-
base_delay_ms: 1e3,
|
|
53820
|
-
max_delay_ms: 3e4,
|
|
53821
|
-
backoff: "exponential",
|
|
53822
|
-
jitter: 0.1,
|
|
53823
|
-
circuit_threshold: 5,
|
|
53824
|
-
circuit_reset_ms: 6e4
|
|
53825
|
-
},
|
|
53826
|
-
onAttach(node, _config, _context) {
|
|
53827
|
-
const state = {
|
|
53828
|
-
circuit: "closed",
|
|
53829
|
-
consecutiveFailures: 0,
|
|
53830
|
-
circuitOpenedAt: 0,
|
|
53831
|
-
totalAttempts: 0,
|
|
53832
|
-
totalSuccesses: 0,
|
|
53833
|
-
totalFailures: 0,
|
|
53834
|
-
pendingActions: /* @__PURE__ */ new Map(),
|
|
53835
|
-
actionCounter: 0
|
|
53836
|
-
};
|
|
53837
|
-
node.__retryState = state;
|
|
53838
|
-
},
|
|
53839
|
-
onDetach(node, _config, _context) {
|
|
53840
|
-
delete node.__retryState;
|
|
53841
|
-
},
|
|
53842
|
-
onUpdate(node, config, context, _delta) {
|
|
53843
|
-
const state = node.__retryState;
|
|
53844
|
-
if (!state) return;
|
|
53845
|
-
if (state.circuit === "open") {
|
|
53846
|
-
const elapsed = Date.now() - state.circuitOpenedAt;
|
|
53847
|
-
if (elapsed >= config.circuit_reset_ms) {
|
|
53848
|
-
state.circuit = "half-open";
|
|
53849
|
-
context.emit?.("retry:circuit_half", {
|
|
53850
|
-
testAttempt: state.totalAttempts + 1
|
|
53851
|
-
});
|
|
53852
|
-
}
|
|
53853
|
-
}
|
|
53854
|
-
},
|
|
53855
|
-
onEvent(node, config, context, event) {
|
|
53856
|
-
const state = node.__retryState;
|
|
53857
|
-
if (!state) return;
|
|
53858
|
-
const eventType = typeof event === "string" ? event : event.type;
|
|
53859
|
-
const payload = extractPayload(event);
|
|
53860
|
-
switch (eventType) {
|
|
53861
|
-
case "retry:execute": {
|
|
53862
|
-
const actionName = payload.action;
|
|
53863
|
-
if (!actionName) break;
|
|
53864
|
-
if (state.circuit === "open") {
|
|
53865
|
-
context.emit?.("retry:failure", {
|
|
53866
|
-
actionName,
|
|
53867
|
-
attempt: 0,
|
|
53868
|
-
error: "Circuit breaker is OPEN"
|
|
53869
|
-
});
|
|
53870
|
-
break;
|
|
53871
|
-
}
|
|
53872
|
-
const retryId = `retry_${state.actionCounter++}`;
|
|
53873
|
-
state.pendingActions.set(retryId, {
|
|
53874
|
-
actionName,
|
|
53875
|
-
attempt: 0,
|
|
53876
|
-
startedAt: Date.now()
|
|
53877
|
-
});
|
|
53878
|
-
state.totalAttempts++;
|
|
53879
|
-
context.emit?.("retry:attempt", {
|
|
53880
|
-
retryId,
|
|
53881
|
-
actionName,
|
|
53882
|
-
attempt: 0,
|
|
53883
|
-
maxRetries: config.max_retries
|
|
53884
|
-
});
|
|
53885
|
-
context.emit?.(actionName, {
|
|
53886
|
-
...payload.params,
|
|
53887
|
-
__retryId: retryId
|
|
53888
|
-
});
|
|
53889
|
-
break;
|
|
53890
|
-
}
|
|
53891
|
-
case "retry:action_result": {
|
|
53892
|
-
const retryId = payload.retryId;
|
|
53893
|
-
const success = payload.success;
|
|
53894
|
-
const error = payload.error;
|
|
53895
|
-
const pending = state.pendingActions.get(retryId);
|
|
53896
|
-
if (!pending) break;
|
|
53897
|
-
if (success) {
|
|
53898
|
-
state.totalSuccesses++;
|
|
53899
|
-
state.consecutiveFailures = 0;
|
|
53900
|
-
state.pendingActions.delete(retryId);
|
|
53901
|
-
if (state.circuit === "half-open") {
|
|
53902
|
-
state.circuit = "closed";
|
|
53903
|
-
context.emit?.("retry:circuit_close", {
|
|
53904
|
-
recoveredAfterMs: Date.now() - state.circuitOpenedAt
|
|
53905
|
-
});
|
|
53906
|
-
}
|
|
53907
|
-
context.emit?.("retry:success", {
|
|
53908
|
-
actionName: pending.actionName,
|
|
53909
|
-
attempt: pending.attempt,
|
|
53910
|
-
elapsed: Date.now() - pending.startedAt
|
|
53911
|
-
});
|
|
53912
|
-
} else {
|
|
53913
|
-
state.totalFailures++;
|
|
53914
|
-
state.consecutiveFailures++;
|
|
53915
|
-
pending.attempt++;
|
|
53916
|
-
context.emit?.("retry:failure", {
|
|
53917
|
-
actionName: pending.actionName,
|
|
53918
|
-
attempt: pending.attempt,
|
|
53919
|
-
error: error ?? "unknown"
|
|
53920
|
-
});
|
|
53921
|
-
if (state.consecutiveFailures >= config.circuit_threshold) {
|
|
53922
|
-
state.circuit = "open";
|
|
53923
|
-
state.circuitOpenedAt = Date.now();
|
|
53924
|
-
state.pendingActions.delete(retryId);
|
|
53925
|
-
context.emit?.("retry:circuit_open", {
|
|
53926
|
-
consecutiveFailures: state.consecutiveFailures,
|
|
53927
|
-
resetMs: config.circuit_reset_ms
|
|
53928
|
-
});
|
|
53929
|
-
break;
|
|
53930
|
-
}
|
|
53931
|
-
if (state.circuit === "half-open") {
|
|
53932
|
-
state.circuit = "open";
|
|
53933
|
-
state.circuitOpenedAt = Date.now();
|
|
53934
|
-
state.pendingActions.delete(retryId);
|
|
53935
|
-
context.emit?.("retry:circuit_open", {
|
|
53936
|
-
consecutiveFailures: state.consecutiveFailures,
|
|
53937
|
-
resetMs: config.circuit_reset_ms
|
|
53938
|
-
});
|
|
53939
|
-
break;
|
|
53940
|
-
}
|
|
53941
|
-
if (pending.attempt > config.max_retries) {
|
|
53942
|
-
state.pendingActions.delete(retryId);
|
|
53943
|
-
context.emit?.("retry:exhausted", {
|
|
53944
|
-
actionName: pending.actionName,
|
|
53945
|
-
totalAttempts: pending.attempt
|
|
53946
|
-
});
|
|
53947
|
-
} else {
|
|
53948
|
-
const delay = computeDelay(config, pending.attempt - 1);
|
|
53949
|
-
state.totalAttempts++;
|
|
53950
|
-
setTimeout(() => {
|
|
53951
|
-
if (!node.__retryState) return;
|
|
53952
|
-
context.emit?.("retry:attempt", {
|
|
53953
|
-
retryId,
|
|
53954
|
-
actionName: pending.actionName,
|
|
53955
|
-
attempt: pending.attempt,
|
|
53956
|
-
maxRetries: config.max_retries
|
|
53957
|
-
});
|
|
53958
|
-
context.emit?.(pending.actionName, {
|
|
53959
|
-
__retryId: retryId
|
|
53960
|
-
});
|
|
53961
|
-
}, delay);
|
|
53962
|
-
}
|
|
53963
|
-
}
|
|
53964
|
-
break;
|
|
53965
|
-
}
|
|
53966
|
-
case "retry:reset_circuit": {
|
|
53967
|
-
state.circuit = "closed";
|
|
53968
|
-
state.consecutiveFailures = 0;
|
|
53969
|
-
context.emit?.("retry:circuit_close", { recoveredAfterMs: 0 });
|
|
53970
|
-
break;
|
|
53971
|
-
}
|
|
53972
|
-
case "retry:get_status": {
|
|
53973
|
-
context.emit?.("retry:status", {
|
|
53974
|
-
circuit: state.circuit,
|
|
53975
|
-
consecutiveFailures: state.consecutiveFailures,
|
|
53976
|
-
totalAttempts: state.totalAttempts,
|
|
53977
|
-
totalSuccesses: state.totalSuccesses,
|
|
53978
|
-
totalFailures: state.totalFailures,
|
|
53979
|
-
pending: state.pendingActions.size
|
|
53980
|
-
});
|
|
53981
|
-
break;
|
|
53982
|
-
}
|
|
53983
|
-
}
|
|
53984
|
-
}
|
|
53985
|
-
};
|
|
53986
|
-
|
|
53987
54456
|
// src/traits/DatabaseTrait.ts
|
|
53988
54457
|
var databaseHandler = {
|
|
53989
54458
|
name: "database",
|
|
@@ -54085,110 +54554,6 @@ var databaseHandler = {
|
|
|
54085
54554
|
}
|
|
54086
54555
|
};
|
|
54087
54556
|
|
|
54088
|
-
// src/traits/CacheTrait.ts
|
|
54089
|
-
var cacheHandler = {
|
|
54090
|
-
name: "cache",
|
|
54091
|
-
defaultConfig: {
|
|
54092
|
-
max_size: 1e3,
|
|
54093
|
-
default_ttl_ms: 6e4,
|
|
54094
|
-
eviction_policy: "lru"
|
|
54095
|
-
},
|
|
54096
|
-
onAttach(node, _config, _context) {
|
|
54097
|
-
node.__cacheState = {
|
|
54098
|
-
entries: /* @__PURE__ */ new Map(),
|
|
54099
|
-
hits: 0,
|
|
54100
|
-
misses: 0,
|
|
54101
|
-
evictions: 0
|
|
54102
|
-
};
|
|
54103
|
-
},
|
|
54104
|
-
onDetach(node) {
|
|
54105
|
-
delete node.__cacheState;
|
|
54106
|
-
},
|
|
54107
|
-
onUpdate(node, config, _context, _delta) {
|
|
54108
|
-
const state = node.__cacheState;
|
|
54109
|
-
if (!state) return;
|
|
54110
|
-
const now = Date.now();
|
|
54111
|
-
for (const [key, entry] of state.entries) {
|
|
54112
|
-
if (entry.expiresAt > 0 && now >= entry.expiresAt) {
|
|
54113
|
-
state.entries.delete(key);
|
|
54114
|
-
state.evictions++;
|
|
54115
|
-
}
|
|
54116
|
-
}
|
|
54117
|
-
},
|
|
54118
|
-
onEvent(node, config, context, event) {
|
|
54119
|
-
const state = node.__cacheState;
|
|
54120
|
-
if (!state) return;
|
|
54121
|
-
const eventType = typeof event === "string" ? event : event.type;
|
|
54122
|
-
switch (eventType) {
|
|
54123
|
-
case "cache:set": {
|
|
54124
|
-
const key = event.key;
|
|
54125
|
-
if (!key) break;
|
|
54126
|
-
const ttl = event.ttl ?? config.default_ttl_ms;
|
|
54127
|
-
if (state.entries.size >= config.max_size && !state.entries.has(key)) {
|
|
54128
|
-
evictOne(state, config, context);
|
|
54129
|
-
}
|
|
54130
|
-
const now = Date.now();
|
|
54131
|
-
state.entries.set(key, {
|
|
54132
|
-
value: event.value,
|
|
54133
|
-
expiresAt: ttl > 0 ? now + ttl : 0,
|
|
54134
|
-
accessedAt: now,
|
|
54135
|
-
createdAt: now
|
|
54136
|
-
});
|
|
54137
|
-
break;
|
|
54138
|
-
}
|
|
54139
|
-
case "cache:get": {
|
|
54140
|
-
const key = event.key;
|
|
54141
|
-
if (!key) break;
|
|
54142
|
-
const entry = state.entries.get(key);
|
|
54143
|
-
if (entry && (entry.expiresAt === 0 || Date.now() < entry.expiresAt)) {
|
|
54144
|
-
state.hits++;
|
|
54145
|
-
entry.accessedAt = Date.now();
|
|
54146
|
-
context.emit?.("cache:result", { key, value: entry.value, hit: true });
|
|
54147
|
-
} else {
|
|
54148
|
-
state.misses++;
|
|
54149
|
-
if (entry) state.entries.delete(key);
|
|
54150
|
-
context.emit?.("cache:result", { key, value: void 0, hit: false });
|
|
54151
|
-
}
|
|
54152
|
-
break;
|
|
54153
|
-
}
|
|
54154
|
-
case "cache:invalidate": {
|
|
54155
|
-
const key = event.key;
|
|
54156
|
-
if (key) state.entries.delete(key);
|
|
54157
|
-
break;
|
|
54158
|
-
}
|
|
54159
|
-
case "cache:clear": {
|
|
54160
|
-
state.entries.clear();
|
|
54161
|
-
break;
|
|
54162
|
-
}
|
|
54163
|
-
case "cache:get_stats": {
|
|
54164
|
-
context.emit?.("cache:stats", {
|
|
54165
|
-
hits: state.hits,
|
|
54166
|
-
misses: state.misses,
|
|
54167
|
-
size: state.entries.size,
|
|
54168
|
-
evictions: state.evictions,
|
|
54169
|
-
hitRate: state.hits + state.misses > 0 ? state.hits / (state.hits + state.misses) : 0
|
|
54170
|
-
});
|
|
54171
|
-
break;
|
|
54172
|
-
}
|
|
54173
|
-
}
|
|
54174
|
-
}
|
|
54175
|
-
};
|
|
54176
|
-
function evictOne(state, config, context) {
|
|
54177
|
-
if (state.entries.size === 0) return;
|
|
54178
|
-
let oldest = null;
|
|
54179
|
-
for (const [key, entry] of state.entries) {
|
|
54180
|
-
const time = config.eviction_policy === "lru" ? entry.accessedAt : entry.createdAt;
|
|
54181
|
-
if (!oldest || time < oldest.time) {
|
|
54182
|
-
oldest = { key, time };
|
|
54183
|
-
}
|
|
54184
|
-
}
|
|
54185
|
-
if (oldest) {
|
|
54186
|
-
state.entries.delete(oldest.key);
|
|
54187
|
-
state.evictions++;
|
|
54188
|
-
context.emit?.("cache:evict", { key: oldest.key, reason: config.eviction_policy });
|
|
54189
|
-
}
|
|
54190
|
-
}
|
|
54191
|
-
|
|
54192
54557
|
// src/traits/StreamTrait.ts
|
|
54193
54558
|
var streamHandler = {
|
|
54194
54559
|
name: "stream",
|
|
@@ -59989,333 +60354,6 @@ var gotchaHandler = {
|
|
|
59989
60354
|
}
|
|
59990
60355
|
};
|
|
59991
60356
|
|
|
59992
|
-
// src/traits/FluidSimulationTrait.ts
|
|
59993
|
-
function poly6Kernel(r, h) {
|
|
59994
|
-
if (r < 0 || r > h) return 0;
|
|
59995
|
-
const coeff = 315 / (64 * Math.PI * h ** 9);
|
|
59996
|
-
return coeff * (h * h - r * r) ** 3;
|
|
59997
|
-
}
|
|
59998
|
-
function spikyKernelGradient(dx, dy, dz, h) {
|
|
59999
|
-
const r = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
60000
|
-
if (r > h || r < 1e-5) return [0, 0, 0];
|
|
60001
|
-
const coeff = -45 / (Math.PI * h ** 6) * (h - r) ** 2;
|
|
60002
|
-
return [coeff * (dx / r), coeff * (dy / r), coeff * (dz / r)];
|
|
60003
|
-
}
|
|
60004
|
-
function viscosityKernelLaplacian(r, h) {
|
|
60005
|
-
if (r < 0 || r > h) return 0;
|
|
60006
|
-
return 45 / (Math.PI * h ** 6) * (h - r);
|
|
60007
|
-
}
|
|
60008
|
-
var SpatialHash = class {
|
|
60009
|
-
constructor(cellSize) {
|
|
60010
|
-
this.cells = /* @__PURE__ */ new Map();
|
|
60011
|
-
this.cellSize = cellSize;
|
|
60012
|
-
}
|
|
60013
|
-
key(x, y, z) {
|
|
60014
|
-
const cx = Math.floor(x / this.cellSize);
|
|
60015
|
-
const cy = Math.floor(y / this.cellSize);
|
|
60016
|
-
const cz = Math.floor(z / this.cellSize);
|
|
60017
|
-
return `${cx},${cy},${cz}`;
|
|
60018
|
-
}
|
|
60019
|
-
insert(id, pos) {
|
|
60020
|
-
const k = this.key(pos[0], pos[1], pos[2]);
|
|
60021
|
-
if (!this.cells.has(k)) this.cells.set(k, []);
|
|
60022
|
-
this.cells.get(k).push(id);
|
|
60023
|
-
}
|
|
60024
|
-
getNeighbors(pos) {
|
|
60025
|
-
const cx = Math.floor(pos[0] / this.cellSize);
|
|
60026
|
-
const cy = Math.floor(pos[1] / this.cellSize);
|
|
60027
|
-
const cz = Math.floor(pos[2] / this.cellSize);
|
|
60028
|
-
const result = [];
|
|
60029
|
-
for (let dx = -1; dx <= 1; dx++) {
|
|
60030
|
-
for (let dy = -1; dy <= 1; dy++) {
|
|
60031
|
-
for (let dz = -1; dz <= 1; dz++) {
|
|
60032
|
-
const k = `${cx + dx},${cy + dy},${cz + dz}`;
|
|
60033
|
-
const cell = this.cells.get(k);
|
|
60034
|
-
if (cell) result.push(...cell);
|
|
60035
|
-
}
|
|
60036
|
-
}
|
|
60037
|
-
}
|
|
60038
|
-
return result;
|
|
60039
|
-
}
|
|
60040
|
-
clear() {
|
|
60041
|
-
this.cells.clear();
|
|
60042
|
-
}
|
|
60043
|
-
};
|
|
60044
|
-
var FluidSimulationSystem = class {
|
|
60045
|
-
constructor(config = {}) {
|
|
60046
|
-
this.particles = /* @__PURE__ */ new Map();
|
|
60047
|
-
this.nextId = 0;
|
|
60048
|
-
this.boundaries = [];
|
|
60049
|
-
this.cfg = {
|
|
60050
|
-
restDensity: config.restDensity ?? 1e3,
|
|
60051
|
-
viscosity: config.viscosity ?? 1e-3,
|
|
60052
|
-
gravity: config.gravity ?? [0, -9.81, 0],
|
|
60053
|
-
solverType: config.solverType ?? "sph",
|
|
60054
|
-
timeStep: config.timeStep ?? 0.016,
|
|
60055
|
-
maxVelocity: config.maxVelocity ?? 100,
|
|
60056
|
-
smoothingRadius: config.smoothingRadius ?? 0.04,
|
|
60057
|
-
gridCellSize: config.gridCellSize ?? 0.04,
|
|
60058
|
-
particleRadius: config.particleRadius ?? 0.01,
|
|
60059
|
-
gasConstant: config.gasConstant ?? 8.314,
|
|
60060
|
-
surfaceTension: config.surfaceTension ?? 0.072
|
|
60061
|
-
};
|
|
60062
|
-
this.spatialHash = new SpatialHash(this.cfg.gridCellSize);
|
|
60063
|
-
}
|
|
60064
|
-
// ── Particle Management ────────────────────────────────────────────────
|
|
60065
|
-
addParticle(position, velocity) {
|
|
60066
|
-
const id = this.nextId++;
|
|
60067
|
-
this.particles.set(id, {
|
|
60068
|
-
id,
|
|
60069
|
-
position: [...position],
|
|
60070
|
-
velocity: velocity ? [...velocity] : [0, 0, 0],
|
|
60071
|
-
force: [0, 0, 0],
|
|
60072
|
-
density: this.cfg.restDensity,
|
|
60073
|
-
pressure: 0,
|
|
60074
|
-
mass: 1
|
|
60075
|
-
});
|
|
60076
|
-
return id;
|
|
60077
|
-
}
|
|
60078
|
-
getParticle(id) {
|
|
60079
|
-
return this.particles.get(id);
|
|
60080
|
-
}
|
|
60081
|
-
getParticles() {
|
|
60082
|
-
return Array.from(this.particles.values());
|
|
60083
|
-
}
|
|
60084
|
-
getParticleCount() {
|
|
60085
|
-
return this.particles.size;
|
|
60086
|
-
}
|
|
60087
|
-
removeParticle(id) {
|
|
60088
|
-
return this.particles.delete(id);
|
|
60089
|
-
}
|
|
60090
|
-
clearParticles() {
|
|
60091
|
-
this.particles.clear();
|
|
60092
|
-
this.nextId = 0;
|
|
60093
|
-
}
|
|
60094
|
-
// ── Boundary Management ────────────────────────────────────────────────
|
|
60095
|
-
addBoundary(boundary) {
|
|
60096
|
-
this.boundaries.push(boundary);
|
|
60097
|
-
}
|
|
60098
|
-
getBoundaries() {
|
|
60099
|
-
return [...this.boundaries];
|
|
60100
|
-
}
|
|
60101
|
-
clearBoundaries() {
|
|
60102
|
-
this.boundaries.length = 0;
|
|
60103
|
-
}
|
|
60104
|
-
// ── Configuration ──────────────────────────────────────────────────────
|
|
60105
|
-
getConfig() {
|
|
60106
|
-
return { ...this.cfg };
|
|
60107
|
-
}
|
|
60108
|
-
setConfig(partial) {
|
|
60109
|
-
Object.assign(this.cfg, partial);
|
|
60110
|
-
if (partial.gridCellSize !== void 0) {
|
|
60111
|
-
this.spatialHash = new SpatialHash(this.cfg.gridCellSize);
|
|
60112
|
-
}
|
|
60113
|
-
}
|
|
60114
|
-
// ── Simulation Step ────────────────────────────────────────────────────
|
|
60115
|
-
step(dt) {
|
|
60116
|
-
const h = this.cfg.smoothingRadius;
|
|
60117
|
-
const deltaT = dt ?? this.cfg.timeStep;
|
|
60118
|
-
const particles = Array.from(this.particles.values());
|
|
60119
|
-
this.spatialHash.clear();
|
|
60120
|
-
for (const p of particles) {
|
|
60121
|
-
this.spatialHash.insert(p.id, p.position);
|
|
60122
|
-
}
|
|
60123
|
-
for (const pi of particles) {
|
|
60124
|
-
let density = 0;
|
|
60125
|
-
for (const pj of particles) {
|
|
60126
|
-
const r = this.dist(pi.position, pj.position);
|
|
60127
|
-
density += pj.mass * poly6Kernel(r, h);
|
|
60128
|
-
}
|
|
60129
|
-
pi.density = Math.max(density, this.cfg.restDensity * 0.01);
|
|
60130
|
-
pi.pressure = this.cfg.gasConstant * (pi.density - this.cfg.restDensity);
|
|
60131
|
-
}
|
|
60132
|
-
for (const pi of particles) {
|
|
60133
|
-
pi.force = [
|
|
60134
|
-
this.cfg.gravity[0] * pi.mass,
|
|
60135
|
-
this.cfg.gravity[1] * pi.mass,
|
|
60136
|
-
this.cfg.gravity[2] * pi.mass
|
|
60137
|
-
];
|
|
60138
|
-
for (const pj of particles) {
|
|
60139
|
-
if (pi.id === pj.id) continue;
|
|
60140
|
-
const dx = pi.position[0] - pj.position[0];
|
|
60141
|
-
const dy = pi.position[1] - pj.position[1];
|
|
60142
|
-
const dz = pi.position[2] - pj.position[2];
|
|
60143
|
-
const r = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
60144
|
-
if (r < h && r > 1e-5) {
|
|
60145
|
-
const grad = spikyKernelGradient(dx, dy, dz, h);
|
|
60146
|
-
const pScale = -pj.mass * ((pi.pressure + pj.pressure) / (2 * pj.density));
|
|
60147
|
-
pi.force[0] += pScale * grad[0];
|
|
60148
|
-
pi.force[1] += pScale * grad[1];
|
|
60149
|
-
pi.force[2] += pScale * grad[2];
|
|
60150
|
-
const viscLap = viscosityKernelLaplacian(r, h);
|
|
60151
|
-
const vScale = this.cfg.viscosity * pj.mass * (1 / pj.density) * viscLap;
|
|
60152
|
-
pi.force[0] += vScale * (pj.velocity[0] - pi.velocity[0]);
|
|
60153
|
-
pi.force[1] += vScale * (pj.velocity[1] - pi.velocity[1]);
|
|
60154
|
-
pi.force[2] += vScale * (pj.velocity[2] - pi.velocity[2]);
|
|
60155
|
-
}
|
|
60156
|
-
}
|
|
60157
|
-
}
|
|
60158
|
-
for (const p of particles) {
|
|
60159
|
-
p.velocity[0] += p.force[0] / p.mass * deltaT;
|
|
60160
|
-
p.velocity[1] += p.force[1] / p.mass * deltaT;
|
|
60161
|
-
p.velocity[2] += p.force[2] / p.mass * deltaT;
|
|
60162
|
-
const speed = Math.sqrt(p.velocity[0] ** 2 + p.velocity[1] ** 2 + p.velocity[2] ** 2);
|
|
60163
|
-
if (speed > this.cfg.maxVelocity) {
|
|
60164
|
-
const scale = this.cfg.maxVelocity / speed;
|
|
60165
|
-
p.velocity[0] *= scale;
|
|
60166
|
-
p.velocity[1] *= scale;
|
|
60167
|
-
p.velocity[2] *= scale;
|
|
60168
|
-
}
|
|
60169
|
-
p.position[0] += p.velocity[0] * deltaT;
|
|
60170
|
-
p.position[1] += p.velocity[1] * deltaT;
|
|
60171
|
-
p.position[2] += p.velocity[2] * deltaT;
|
|
60172
|
-
}
|
|
60173
|
-
for (const p of particles) {
|
|
60174
|
-
this.applyBoundaries(p);
|
|
60175
|
-
}
|
|
60176
|
-
}
|
|
60177
|
-
// ── Density Queries ────────────────────────────────────────────────────
|
|
60178
|
-
getDensityAt(position) {
|
|
60179
|
-
const h = this.cfg.smoothingRadius;
|
|
60180
|
-
let density = 0;
|
|
60181
|
-
for (const p of this.particles.values()) {
|
|
60182
|
-
const r = this.dist(position, p.position);
|
|
60183
|
-
density += p.mass * poly6Kernel(r, h);
|
|
60184
|
-
}
|
|
60185
|
-
return density;
|
|
60186
|
-
}
|
|
60187
|
-
isInsideFluid(position) {
|
|
60188
|
-
return this.getDensityAt(position) > this.cfg.restDensity * 0.5;
|
|
60189
|
-
}
|
|
60190
|
-
// ── Statistics ─────────────────────────────────────────────────────────
|
|
60191
|
-
getKineticEnergy() {
|
|
60192
|
-
let energy = 0;
|
|
60193
|
-
for (const p of this.particles.values()) {
|
|
60194
|
-
energy += 0.5 * p.mass * (p.velocity[0] ** 2 + p.velocity[1] ** 2 + p.velocity[2] ** 2);
|
|
60195
|
-
}
|
|
60196
|
-
return energy;
|
|
60197
|
-
}
|
|
60198
|
-
getAverageDensity() {
|
|
60199
|
-
if (this.particles.size === 0) return 0;
|
|
60200
|
-
let total = 0;
|
|
60201
|
-
for (const p of this.particles.values()) total += p.density;
|
|
60202
|
-
return total / this.particles.size;
|
|
60203
|
-
}
|
|
60204
|
-
reset() {
|
|
60205
|
-
this.particles.clear();
|
|
60206
|
-
this.spatialHash.clear();
|
|
60207
|
-
this.boundaries.length = 0;
|
|
60208
|
-
this.nextId = 0;
|
|
60209
|
-
}
|
|
60210
|
-
// ── Private Helpers ────────────────────────────────────────────────────
|
|
60211
|
-
dist(a, b) {
|
|
60212
|
-
return Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + (a[2] - b[2]) ** 2);
|
|
60213
|
-
}
|
|
60214
|
-
applyBoundaries(p) {
|
|
60215
|
-
const pr = this.cfg.particleRadius;
|
|
60216
|
-
for (const b of this.boundaries) {
|
|
60217
|
-
if (b.type === "plane") {
|
|
60218
|
-
const dx = p.position[0] - b.position[0];
|
|
60219
|
-
const dy = p.position[1] - b.position[1];
|
|
60220
|
-
const dz = p.position[2] - b.position[2];
|
|
60221
|
-
const d = dx * b.normal[0] + dy * b.normal[1] + dz * b.normal[2];
|
|
60222
|
-
if (d < pr) {
|
|
60223
|
-
p.position[0] += b.normal[0] * (pr - d);
|
|
60224
|
-
p.position[1] += b.normal[1] * (pr - d);
|
|
60225
|
-
p.position[2] += b.normal[2] * (pr - d);
|
|
60226
|
-
const vn = p.velocity[0] * b.normal[0] + p.velocity[1] * b.normal[1] + p.velocity[2] * b.normal[2];
|
|
60227
|
-
if (vn < 0) {
|
|
60228
|
-
p.velocity[0] -= (1 + b.restitution) * vn * b.normal[0];
|
|
60229
|
-
p.velocity[1] -= (1 + b.restitution) * vn * b.normal[1];
|
|
60230
|
-
p.velocity[2] -= (1 + b.restitution) * vn * b.normal[2];
|
|
60231
|
-
}
|
|
60232
|
-
}
|
|
60233
|
-
} else if (b.type === "sphere") {
|
|
60234
|
-
const dx = p.position[0] - b.position[0];
|
|
60235
|
-
const dy = p.position[1] - b.position[1];
|
|
60236
|
-
const dz = p.position[2] - b.position[2];
|
|
60237
|
-
const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
60238
|
-
const maxDist = b.radius - pr;
|
|
60239
|
-
if (dist > maxDist && dist > 1e-6) {
|
|
60240
|
-
const nx = dx / dist;
|
|
60241
|
-
const ny = dy / dist;
|
|
60242
|
-
const nz = dz / dist;
|
|
60243
|
-
p.position[0] = b.position[0] + nx * maxDist;
|
|
60244
|
-
p.position[1] = b.position[1] + ny * maxDist;
|
|
60245
|
-
p.position[2] = b.position[2] + nz * maxDist;
|
|
60246
|
-
const vn = p.velocity[0] * nx + p.velocity[1] * ny + p.velocity[2] * nz;
|
|
60247
|
-
if (vn > 0) {
|
|
60248
|
-
p.velocity[0] -= (1 + b.restitution) * vn * nx;
|
|
60249
|
-
p.velocity[1] -= (1 + b.restitution) * vn * ny;
|
|
60250
|
-
p.velocity[2] -= (1 + b.restitution) * vn * nz;
|
|
60251
|
-
}
|
|
60252
|
-
}
|
|
60253
|
-
} else if (b.type === "box") {
|
|
60254
|
-
const halfX = b.size[0] / 2;
|
|
60255
|
-
const halfY = b.size[1] / 2;
|
|
60256
|
-
const halfZ = b.size[2] / 2;
|
|
60257
|
-
const limit = pr;
|
|
60258
|
-
if (p.position[0] > b.position[0] + halfX - limit) {
|
|
60259
|
-
p.position[0] = b.position[0] + halfX - limit;
|
|
60260
|
-
p.velocity[0] *= -b.restitution;
|
|
60261
|
-
} else if (p.position[0] < b.position[0] - halfX + limit) {
|
|
60262
|
-
p.position[0] = b.position[0] - halfX + limit;
|
|
60263
|
-
p.velocity[0] *= -b.restitution;
|
|
60264
|
-
}
|
|
60265
|
-
if (p.position[1] > b.position[1] + halfY - limit) {
|
|
60266
|
-
p.position[1] = b.position[1] + halfY - limit;
|
|
60267
|
-
p.velocity[1] *= -b.restitution;
|
|
60268
|
-
} else if (p.position[1] < b.position[1] - halfY + limit) {
|
|
60269
|
-
p.position[1] = b.position[1] - halfY + limit;
|
|
60270
|
-
p.velocity[1] *= -b.restitution;
|
|
60271
|
-
}
|
|
60272
|
-
if (p.position[2] > b.position[2] + halfZ - limit) {
|
|
60273
|
-
p.position[2] = b.position[2] + halfZ - limit;
|
|
60274
|
-
p.velocity[2] *= -b.restitution;
|
|
60275
|
-
} else if (p.position[2] < b.position[2] - halfZ + limit) {
|
|
60276
|
-
p.position[2] = b.position[2] - halfZ + limit;
|
|
60277
|
-
p.velocity[2] *= -b.restitution;
|
|
60278
|
-
}
|
|
60279
|
-
}
|
|
60280
|
-
}
|
|
60281
|
-
}
|
|
60282
|
-
};
|
|
60283
|
-
var fluidSimulationHandler = {
|
|
60284
|
-
name: "fluid_simulation",
|
|
60285
|
-
defaultConfig: {},
|
|
60286
|
-
onAttach(node, config, ctx) {
|
|
60287
|
-
const instance = new FluidSimulationSystem(config);
|
|
60288
|
-
node.__fluid_simulation_instance = instance;
|
|
60289
|
-
ctx.emit("fluid_simulation_attached", { node, config });
|
|
60290
|
-
},
|
|
60291
|
-
onDetach(node, _config, ctx) {
|
|
60292
|
-
const instance = node.__fluid_simulation_instance;
|
|
60293
|
-
if (instance) {
|
|
60294
|
-
if (typeof instance.onDetach === "function") instance.onDetach(node, ctx);
|
|
60295
|
-
else if (typeof instance.dispose === "function") instance.dispose();
|
|
60296
|
-
else if (typeof instance.cleanup === "function") instance.cleanup();
|
|
60297
|
-
}
|
|
60298
|
-
ctx.emit("fluid_simulation_detached", { node });
|
|
60299
|
-
delete node.__fluid_simulation_instance;
|
|
60300
|
-
},
|
|
60301
|
-
onEvent(node, _config, ctx, event) {
|
|
60302
|
-
const instance = node.__fluid_simulation_instance;
|
|
60303
|
-
if (!instance) return;
|
|
60304
|
-
if (typeof instance.onEvent === "function") instance.onEvent(event);
|
|
60305
|
-
else if (typeof instance.emit === "function" && event.type) instance.emit(event);
|
|
60306
|
-
if (event.type === "fluid_simulation_configure" && event.payload) {
|
|
60307
|
-
Object.assign(instance, event.payload);
|
|
60308
|
-
ctx.emit("fluid_simulation_configured", { node });
|
|
60309
|
-
}
|
|
60310
|
-
},
|
|
60311
|
-
onUpdate(node, _config, ctx, dt) {
|
|
60312
|
-
const instance = node.__fluid_simulation_instance;
|
|
60313
|
-
if (!instance) return;
|
|
60314
|
-
if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
|
|
60315
|
-
else if (typeof instance.step === "function") instance.step(dt);
|
|
60316
|
-
}
|
|
60317
|
-
};
|
|
60318
|
-
|
|
60319
60357
|
// src/traits/VRTraitSystem.ts
|
|
60320
60358
|
function vec3ToTuple(v) {
|
|
60321
60359
|
return v;
|
|
@@ -61139,6 +61177,7 @@ var VRTraitRegistry = class {
|
|
|
61139
61177
|
this.register(provenanceHandler);
|
|
61140
61178
|
this.register(provenanceDensifyHandler);
|
|
61141
61179
|
this.register(evolveProgramHandler);
|
|
61180
|
+
this.register(freezeWhenHandler);
|
|
61142
61181
|
this.register(bodyHandler);
|
|
61143
61182
|
this.register(proactiveHandler);
|
|
61144
61183
|
this.register(eventTraitHandler);
|
|
@@ -61757,6 +61796,7 @@ exports.bufferHandler = bufferHandler;
|
|
|
61757
61796
|
exports.buildBehaviorFactDisclosure = buildBehaviorFactDisclosure;
|
|
61758
61797
|
exports.buoyancyHandler = buoyancyHandler;
|
|
61759
61798
|
exports.cRDTRoomHandler = cRDTRoomHandler;
|
|
61799
|
+
exports.cacheHandler = cacheHandler;
|
|
61760
61800
|
exports.careEthicsHandler = careEthicsHandler;
|
|
61761
61801
|
exports.chainHandler = chainHandler;
|
|
61762
61802
|
exports.characterHandler = characterHandler;
|
|
@@ -61854,8 +61894,10 @@ exports.findReachablePath = findReachablePath;
|
|
|
61854
61894
|
exports.findWalkableNodeAt = findWalkableNodeAt;
|
|
61855
61895
|
exports.flowFieldHandler = flowFieldHandler;
|
|
61856
61896
|
exports.fluidHandler = fluidHandler;
|
|
61897
|
+
exports.fluidSimulationHandler = fluidSimulationHandler;
|
|
61857
61898
|
exports.forgetPolicyHandler = forgetPolicyHandler;
|
|
61858
61899
|
exports.formationControlHandler = formationControlHandler;
|
|
61900
|
+
exports.freezeWhenHandler = freezeWhenHandler;
|
|
61859
61901
|
exports.gardenerPulseJitter = gardenerPulseJitter;
|
|
61860
61902
|
exports.gaussianSplatHandler = gaussianSplatHandler;
|
|
61861
61903
|
exports.gazeFocusAnalyticsHandler = gazeFocusAnalyticsHandler;
|
|
@@ -62023,6 +62065,7 @@ exports.resolveBloomStage = resolveBloomStage;
|
|
|
62023
62065
|
exports.resolveCRDTRoomTraitConfig = resolveCRDTRoomTraitConfig;
|
|
62024
62066
|
exports.resolvePulseHz = resolvePulseHz;
|
|
62025
62067
|
exports.resourceAccountingHandler = resourceAccountingHandler;
|
|
62068
|
+
exports.retryHandler = retryHandler;
|
|
62026
62069
|
exports.reverbZoneHandler = reverbZoneHandler;
|
|
62027
62070
|
exports.rigidbodyHandler = rigidbodyHandler;
|
|
62028
62071
|
exports.roadmapNodeHandler = roadmapNodeHandler;
|
|
@@ -62105,5 +62148,5 @@ exports.withNegotiation = withNegotiation;
|
|
|
62105
62148
|
exports.worldPortalHandler = worldPortalHandler;
|
|
62106
62149
|
exports.wotThingHandler = wotThingHandler;
|
|
62107
62150
|
exports.zkPrivateHandler = zkPrivateHandler;
|
|
62108
|
-
//# sourceMappingURL=chunk-
|
|
62109
|
-
//# sourceMappingURL=chunk-
|
|
62151
|
+
//# sourceMappingURL=chunk-ML4V5PVU.cjs.map
|
|
62152
|
+
//# sourceMappingURL=chunk-ML4V5PVU.cjs.map
|