@holoscript/framework 6.0.3
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/ALL-test-results.json +1 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/ROADMAP.md +175 -0
- package/dist/AgentManifest-CB4xM-Ma.d.cts +704 -0
- package/dist/AgentManifest-CB4xM-Ma.d.ts +704 -0
- package/dist/BehaviorTree-BrBFECv5.d.cts +103 -0
- package/dist/BehaviorTree-BrBFECv5.d.ts +103 -0
- package/dist/InvisibleWallet-BB6tFvRA.d.cts +1732 -0
- package/dist/InvisibleWallet-rtRrBOA8.d.ts +1732 -0
- package/dist/OrchestratorAgent-BvWgf9uw.d.cts +798 -0
- package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +798 -0
- package/dist/agents/index.cjs +4790 -0
- package/dist/agents/index.d.cts +1788 -0
- package/dist/agents/index.d.ts +1788 -0
- package/dist/agents/index.js +4695 -0
- package/dist/ai/index.cjs +5347 -0
- package/dist/ai/index.d.cts +1753 -0
- package/dist/ai/index.d.ts +1753 -0
- package/dist/ai/index.js +5244 -0
- package/dist/behavior.cjs +449 -0
- package/dist/behavior.d.cts +130 -0
- package/dist/behavior.d.ts +130 -0
- package/dist/behavior.js +407 -0
- package/dist/economy/index.cjs +3659 -0
- package/dist/economy/index.d.cts +747 -0
- package/dist/economy/index.d.ts +747 -0
- package/dist/economy/index.js +3617 -0
- package/dist/implementations-D9T3un9D.d.cts +236 -0
- package/dist/implementations-D9T3un9D.d.ts +236 -0
- package/dist/index.cjs +24550 -0
- package/dist/index.d.cts +1729 -0
- package/dist/index.d.ts +1729 -0
- package/dist/index.js +24277 -0
- package/dist/learning/index.cjs +219 -0
- package/dist/learning/index.d.cts +104 -0
- package/dist/learning/index.d.ts +104 -0
- package/dist/learning/index.js +189 -0
- package/dist/negotiation/index.cjs +970 -0
- package/dist/negotiation/index.d.cts +610 -0
- package/dist/negotiation/index.d.ts +610 -0
- package/dist/negotiation/index.js +931 -0
- package/dist/skills/index.cjs +1118 -0
- package/dist/skills/index.d.cts +289 -0
- package/dist/skills/index.d.ts +289 -0
- package/dist/skills/index.js +1079 -0
- package/dist/swarm/index.cjs +5268 -0
- package/dist/swarm/index.d.cts +2433 -0
- package/dist/swarm/index.d.ts +2433 -0
- package/dist/swarm/index.js +5221 -0
- package/dist/training/index.cjs +2745 -0
- package/dist/training/index.d.cts +1734 -0
- package/dist/training/index.d.ts +1734 -0
- package/dist/training/index.js +2687 -0
- package/extract-failures.js +10 -0
- package/package.json +82 -0
- package/src/__tests__/bounty-marketplace.test.ts +374 -0
- package/src/__tests__/delegation.test.ts +144 -0
- package/src/__tests__/distributed-claimer.test.ts +147 -0
- package/src/__tests__/done-log-audit.test.ts +342 -0
- package/src/__tests__/framework.test.ts +865 -0
- package/src/__tests__/goal-synthesizer.test.ts +236 -0
- package/src/__tests__/presence.test.ts +223 -0
- package/src/__tests__/protocol-agent.test.ts +254 -0
- package/src/__tests__/revenue-splitter.test.ts +114 -0
- package/src/__tests__/scenario-driven-todo.test.ts +197 -0
- package/src/__tests__/self-improve.test.ts +349 -0
- package/src/__tests__/service-lifecycle.test.ts +237 -0
- package/src/__tests__/skill-router.test.ts +121 -0
- package/src/agents/AgentManifest.ts +493 -0
- package/src/agents/AgentRegistry.ts +475 -0
- package/src/agents/AgentTypes.ts +585 -0
- package/src/agents/AgentWalletRegistry.ts +83 -0
- package/src/agents/AuthenticatedCRDT.ts +388 -0
- package/src/agents/CapabilityMatcher.ts +453 -0
- package/src/agents/CrossRealityHandoff.ts +305 -0
- package/src/agents/CulturalMemory.ts +454 -0
- package/src/agents/FederatedRegistryAdapter.ts +429 -0
- package/src/agents/NormEngine.ts +450 -0
- package/src/agents/OrchestratorAgent.ts +414 -0
- package/src/agents/SkillWorkflowEngine.ts +472 -0
- package/src/agents/TaskDelegationService.ts +551 -0
- package/src/agents/__tests__/AgentManifest.prod.test.ts +134 -0
- package/src/agents/__tests__/AgentManifest.test.ts +182 -0
- package/src/agents/__tests__/AgentModule.test.ts +864 -0
- package/src/agents/__tests__/AgentRegistry.prod.test.ts +125 -0
- package/src/agents/__tests__/AgentRegistry.test.ts +148 -0
- package/src/agents/__tests__/AgentTypes.test.ts +534 -0
- package/src/agents/__tests__/AgentWalletRegistry.test.ts +152 -0
- package/src/agents/__tests__/AuthenticatedCRDT.test.ts +558 -0
- package/src/agents/__tests__/CapabilityMatcher.prod.test.ts +117 -0
- package/src/agents/__tests__/CapabilityMatcher.test.ts +178 -0
- package/src/agents/__tests__/CrossRealityHandoff.test.ts +402 -0
- package/src/agents/__tests__/CulturalMemory.test.ts +200 -0
- package/src/agents/__tests__/FederatedRegistryAdapter.test.ts +409 -0
- package/src/agents/__tests__/NormEngine.test.ts +276 -0
- package/src/agents/__tests__/OrchestratorAgent.test.ts +182 -0
- package/src/agents/__tests__/SkillWorkflowEngine.test.ts +357 -0
- package/src/agents/__tests__/TaskDelegationService.test.ts +446 -0
- package/src/agents/index.ts +107 -0
- package/src/agents/spatial-comms/Layer1RealTime.ts +621 -0
- package/src/agents/spatial-comms/Layer2A2A.ts +661 -0
- package/src/agents/spatial-comms/Layer3MCP.ts +651 -0
- package/src/agents/spatial-comms/ProtocolTypes.ts +543 -0
- package/src/agents/spatial-comms/SpatialCommClient.ts +483 -0
- package/src/agents/spatial-comms/__tests__/performance-benchmark.test.ts +465 -0
- package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +409 -0
- package/src/agents/spatial-comms/index.ts +66 -0
- package/src/ai/AIAdapter.ts +313 -0
- package/src/ai/AICopilot.ts +331 -0
- package/src/ai/AIOutputValidator.ts +203 -0
- package/src/ai/BTNodes.ts +239 -0
- package/src/ai/BehaviorSelector.ts +135 -0
- package/src/ai/BehaviorTree.ts +153 -0
- package/src/ai/Blackboard.ts +165 -0
- package/src/ai/GenerationAnalytics.ts +461 -0
- package/src/ai/GenerationCache.ts +265 -0
- package/src/ai/GoalPlanner.ts +165 -0
- package/src/ai/HoloScriptGenerator.ts +580 -0
- package/src/ai/InfluenceMap.ts +180 -0
- package/src/ai/NavMesh.ts +168 -0
- package/src/ai/PerceptionSystem.ts +178 -0
- package/src/ai/PromptTemplates.ts +453 -0
- package/src/ai/SemanticSearchService.ts +80 -0
- package/src/ai/StateMachine.ts +196 -0
- package/src/ai/SteeringBehavior.ts +150 -0
- package/src/ai/SteeringBehaviors.ts +244 -0
- package/src/ai/TrainingDataGenerator.ts +1082 -0
- package/src/ai/UtilityAI.ts +145 -0
- package/src/ai/__tests__/AIAdapter.prod.test.ts +259 -0
- package/src/ai/__tests__/AIAdapter.test.ts +109 -0
- package/src/ai/__tests__/AICopilot.prod.test.ts +341 -0
- package/src/ai/__tests__/AICopilot.test.ts +178 -0
- package/src/ai/__tests__/AIOutputValidator.prod.test.ts +226 -0
- package/src/ai/__tests__/AIOutputValidator.test.ts +138 -0
- package/src/ai/__tests__/BTNodes.prod.test.ts +391 -0
- package/src/ai/__tests__/BTNodes.test.ts +263 -0
- package/src/ai/__tests__/BehaviorSelector.prod.test.ts +129 -0
- package/src/ai/__tests__/BehaviorSelector.test.ts +132 -0
- package/src/ai/__tests__/BehaviorTree.prod.test.ts +266 -0
- package/src/ai/__tests__/BehaviorTree.test.ts +216 -0
- package/src/ai/__tests__/Blackboard.prod.test.ts +339 -0
- package/src/ai/__tests__/Blackboard.test.ts +183 -0
- package/src/ai/__tests__/GenerationAnalytics.prod.test.ts +141 -0
- package/src/ai/__tests__/GenerationAnalytics.test.ts +165 -0
- package/src/ai/__tests__/GenerationCache.prod.test.ts +144 -0
- package/src/ai/__tests__/GenerationCache.test.ts +171 -0
- package/src/ai/__tests__/GoalPlanner.prod.test.ts +189 -0
- package/src/ai/__tests__/GoalPlanner.test.ts +137 -0
- package/src/ai/__tests__/GoalPlannerDepth.prod.test.ts +217 -0
- package/src/ai/__tests__/HoloScriptGenerator.test.ts +125 -0
- package/src/ai/__tests__/InfluenceMap.prod.test.ts +146 -0
- package/src/ai/__tests__/InfluenceMap.test.ts +149 -0
- package/src/ai/__tests__/NavMesh.prod.test.ts +141 -0
- package/src/ai/__tests__/NavMesh.test.ts +159 -0
- package/src/ai/__tests__/PerceptionSystem.prod.test.ts +135 -0
- package/src/ai/__tests__/PerceptionSystem.test.ts +250 -0
- package/src/ai/__tests__/PromptTemplates.prod.test.ts +313 -0
- package/src/ai/__tests__/PromptTemplates.test.ts +146 -0
- package/src/ai/__tests__/SemanticSearch.test.ts +37 -0
- package/src/ai/__tests__/StateMachine.prod.test.ts +162 -0
- package/src/ai/__tests__/StateMachine.test.ts +163 -0
- package/src/ai/__tests__/SteeringBehavior.prod.test.ts +251 -0
- package/src/ai/__tests__/SteeringBehavior.test.ts +135 -0
- package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +133 -0
- package/src/ai/__tests__/SteeringBehaviors.test.ts +151 -0
- package/src/ai/__tests__/TrainingDataGenerator.prod.test.ts +286 -0
- package/src/ai/__tests__/TrainingDataGenerator.test.ts +286 -0
- package/src/ai/__tests__/UtilityAI.prod.test.ts +207 -0
- package/src/ai/__tests__/UtilityAI.test.ts +155 -0
- package/src/ai/__tests__/adapters.prod.test.ts +263 -0
- package/src/ai/__tests__/adapters.test.ts +320 -0
- package/src/ai/adapters.ts +1585 -0
- package/src/ai/index.ts +130 -0
- package/src/behavior/BehaviorPresets.ts +140 -0
- package/src/behavior/BehaviorTree.ts +236 -0
- package/src/behavior/StateMachine.ts +176 -0
- package/src/behavior/StateTrait.ts +67 -0
- package/src/behavior/index.ts +8 -0
- package/src/behavior.ts +8 -0
- package/src/board/audit.ts +284 -0
- package/src/board/board-ops.ts +336 -0
- package/src/board/board-types.ts +302 -0
- package/src/board/index.ts +69 -0
- package/src/define-agent.ts +46 -0
- package/src/define-team.ts +33 -0
- package/src/delegation.ts +265 -0
- package/src/distributed-claimer.ts +228 -0
- package/src/economy/AgentBudgetEnforcer.ts +464 -0
- package/src/economy/BountyManager.ts +185 -0
- package/src/economy/CreatorRevenueAggregator.ts +460 -0
- package/src/economy/InvisibleWallet.ts +82 -0
- package/src/economy/KnowledgeMarketplace.ts +193 -0
- package/src/economy/PaymentWebhookService.ts +512 -0
- package/src/economy/RevenueSplitter.ts +156 -0
- package/src/economy/SubscriptionManager.ts +546 -0
- package/src/economy/UnifiedBudgetOptimizer.ts +635 -0
- package/src/economy/UsageMeter.ts +440 -0
- package/src/economy/_core-stubs.ts +219 -0
- package/src/economy/index.ts +100 -0
- package/src/economy/x402-facilitator.ts +1978 -0
- package/src/index.ts +348 -0
- package/src/knowledge/__tests__/knowledge-consolidator.test.ts +444 -0
- package/src/knowledge/__tests__/knowledge-store-vector.test.ts +291 -0
- package/src/knowledge/brain.ts +167 -0
- package/src/knowledge/consolidation.ts +581 -0
- package/src/knowledge/knowledge-consolidator.ts +510 -0
- package/src/knowledge/knowledge-store.ts +616 -0
- package/src/learning/MemoryConsolidator.ts +102 -0
- package/src/learning/MemoryScorer.ts +69 -0
- package/src/learning/ProceduralCompiler.ts +45 -0
- package/src/learning/SemanticClusterer.ts +66 -0
- package/src/learning/index.ts +8 -0
- package/src/llm/llm-adapter.ts +159 -0
- package/src/mesh/index.ts +309 -0
- package/src/negotiation/NegotiationProtocol.ts +694 -0
- package/src/negotiation/NegotiationTypes.ts +473 -0
- package/src/negotiation/VotingMechanisms.ts +691 -0
- package/src/negotiation/index.ts +49 -0
- package/src/protocol/goal-synthesizer.ts +317 -0
- package/src/protocol/implementations.ts +474 -0
- package/src/protocol/micro-phase-decomposer.ts +299 -0
- package/src/protocol/micro-step-decomposer.test.ts +306 -0
- package/src/protocol-agent.test.ts +353 -0
- package/src/protocol-agent.ts +670 -0
- package/src/self-improve/absorb-scanner.ts +252 -0
- package/src/self-improve/evolution-engine.ts +149 -0
- package/src/self-improve/framework-absorber.ts +214 -0
- package/src/self-improve/index.ts +50 -0
- package/src/self-improve/prompt-optimizer.ts +212 -0
- package/src/self-improve/test-generator.ts +175 -0
- package/src/skill-router.ts +186 -0
- package/src/skills/index.ts +5 -0
- package/src/skills/skill-md-bridge.ts +1699 -0
- package/src/swarm/ACOEngine.ts +261 -0
- package/src/swarm/CollectiveIntelligence.ts +383 -0
- package/src/swarm/ContributionSynthesizer.ts +481 -0
- package/src/swarm/LeaderElection.ts +393 -0
- package/src/swarm/PSOEngine.ts +206 -0
- package/src/swarm/QuorumPolicy.ts +173 -0
- package/src/swarm/SwarmCoordinator.ts +335 -0
- package/src/swarm/SwarmManager.ts +442 -0
- package/src/swarm/SwarmMembership.ts +456 -0
- package/src/swarm/VotingRound.ts +255 -0
- package/src/swarm/__tests__/ACOEngine.prod.test.ts +164 -0
- package/src/swarm/__tests__/ACOEngine.test.ts +117 -0
- package/src/swarm/__tests__/CollectiveIntelligence.prod.test.ts +296 -0
- package/src/swarm/__tests__/CollectiveIntelligence.test.ts +457 -0
- package/src/swarm/__tests__/ContributionSynthesizer.prod.test.ts +269 -0
- package/src/swarm/__tests__/ContributionSynthesizer.test.ts +254 -0
- package/src/swarm/__tests__/LeaderElection.prod.test.ts +196 -0
- package/src/swarm/__tests__/LeaderElection.test.ts +151 -0
- package/src/swarm/__tests__/PSOEngine.prod.test.ts +162 -0
- package/src/swarm/__tests__/PSOEngine.test.ts +106 -0
- package/src/swarm/__tests__/QuorumPolicy.prod.test.ts +216 -0
- package/src/swarm/__tests__/QuorumPolicy.test.ts +177 -0
- package/src/swarm/__tests__/SwarmCoordinator.prod.test.ts +186 -0
- package/src/swarm/__tests__/SwarmCoordinator.test.ts +167 -0
- package/src/swarm/__tests__/SwarmManager.prod.test.ts +308 -0
- package/src/swarm/__tests__/SwarmManager.test.ts +373 -0
- package/src/swarm/__tests__/SwarmMembership.prod.test.ts +273 -0
- package/src/swarm/__tests__/SwarmMembership.test.ts +264 -0
- package/src/swarm/__tests__/VotingRound.prod.test.ts +233 -0
- package/src/swarm/__tests__/VotingRound.test.ts +174 -0
- package/src/swarm/analytics/SwarmInspector.ts +476 -0
- package/src/swarm/analytics/SwarmMetrics.ts +449 -0
- package/src/swarm/analytics/__tests__/SwarmInspector.prod.test.ts +366 -0
- package/src/swarm/analytics/__tests__/SwarmInspector.test.ts +454 -0
- package/src/swarm/analytics/__tests__/SwarmMetrics.prod.test.ts +254 -0
- package/src/swarm/analytics/__tests__/SwarmMetrics.test.ts +370 -0
- package/src/swarm/analytics/index.ts +7 -0
- package/src/swarm/index.ts +69 -0
- package/src/swarm/messaging/BroadcastChannel.ts +509 -0
- package/src/swarm/messaging/GossipProtocol.ts +565 -0
- package/src/swarm/messaging/SwarmEventBus.ts +443 -0
- package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +331 -0
- package/src/swarm/messaging/__tests__/BroadcastChannel.test.ts +333 -0
- package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +356 -0
- package/src/swarm/messaging/__tests__/GossipProtocol.test.ts +437 -0
- package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +191 -0
- package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +247 -0
- package/src/swarm/messaging/index.ts +8 -0
- package/src/swarm/spatial/FlockingBehavior.ts +462 -0
- package/src/swarm/spatial/FormationController.ts +500 -0
- package/src/swarm/spatial/Vector3.ts +170 -0
- package/src/swarm/spatial/ZoneClaiming.ts +509 -0
- package/src/swarm/spatial/__tests__/FlockingBehavior.prod.test.ts +239 -0
- package/src/swarm/spatial/__tests__/FlockingBehavior.test.ts +298 -0
- package/src/swarm/spatial/__tests__/FormationController.prod.test.ts +240 -0
- package/src/swarm/spatial/__tests__/FormationController.test.ts +297 -0
- package/src/swarm/spatial/__tests__/Vector3.prod.test.ts +283 -0
- package/src/swarm/spatial/__tests__/Vector3.test.ts +224 -0
- package/src/swarm/spatial/__tests__/ZoneClaiming.prod.test.ts +246 -0
- package/src/swarm/spatial/__tests__/ZoneClaiming.test.ts +374 -0
- package/src/swarm/spatial/index.ts +28 -0
- package/src/team.ts +1245 -0
- package/src/training/LRScheduler.ts +377 -0
- package/src/training/QualityScoringPipeline.ts +139 -0
- package/src/training/SoftDedup.ts +461 -0
- package/src/training/SparsityMonitor.ts +685 -0
- package/src/training/SparsityMonitorTypes.ts +209 -0
- package/src/training/SpatialTrainingDataGenerator.ts +1526 -0
- package/src/training/SpatialTrainingDataTypes.ts +216 -0
- package/src/training/TrainingPipelineConfig.ts +215 -0
- package/src/training/constants.ts +94 -0
- package/src/training/index.ts +138 -0
- package/src/training/schema.ts +147 -0
- package/src/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
- package/src/training/scripts/generate-spatial-dataset.ts +521 -0
- package/src/training/training/data/novel-use-cases.jsonl +153 -0
- package/src/training/training/data/spatial-reasoning-10k.jsonl +9354 -0
- package/src/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
- package/src/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
- package/src/training/trainingmonkey/index.ts +26 -0
- package/src/training/trait-mappings.ts +157 -0
- package/src/types/core-stubs.d.ts +113 -0
- package/src/types.ts +304 -0
- package/test-output.txt +0 -0
- package/test-result.json +1 -0
- package/tsc-errors.txt +4 -0
- package/tsc_output.txt +0 -0
- package/tsconfig.json +14 -0
- package/tsup-learning-esm.config.ts +12 -0
- package/tsup.config.ts +21 -0
- package/typescript-errors-2.txt +0 -0
- package/typescript-errors.txt +22 -0
- package/vitest-log-utf8.txt +268 -0
- package/vitest-log.txt +0 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/behavior.ts
|
|
21
|
+
var behavior_exports = {};
|
|
22
|
+
__export(behavior_exports, {
|
|
23
|
+
ActionNode: () => ActionNode,
|
|
24
|
+
BehaviorTree: () => BehaviorTree,
|
|
25
|
+
ConditionNode: () => ConditionNode,
|
|
26
|
+
InverterNode: () => InverterNode,
|
|
27
|
+
RepeaterNode: () => RepeaterNode,
|
|
28
|
+
SelectorNode: () => SelectorNode,
|
|
29
|
+
SequenceNode: () => SequenceNode,
|
|
30
|
+
StateMachine: () => StateMachine,
|
|
31
|
+
WaitNode: () => WaitNode,
|
|
32
|
+
createAlertBehavior: () => createAlertBehavior,
|
|
33
|
+
createFollowBehavior: () => createFollowBehavior,
|
|
34
|
+
createIdleBehavior: () => createIdleBehavior,
|
|
35
|
+
createInteractBehavior: () => createInteractBehavior,
|
|
36
|
+
createPatrolBehavior: () => createPatrolBehavior,
|
|
37
|
+
getNodeStateMachine: () => getNodeStateMachine,
|
|
38
|
+
stateTraitHandler: () => stateTraitHandler
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(behavior_exports);
|
|
41
|
+
|
|
42
|
+
// src/behavior/BehaviorTree.ts
|
|
43
|
+
var ActionNode = class {
|
|
44
|
+
constructor(name, fn) {
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.fn = fn;
|
|
47
|
+
}
|
|
48
|
+
type = "action";
|
|
49
|
+
tick(context, delta) {
|
|
50
|
+
return this.fn(context, delta);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var ConditionNode = class {
|
|
54
|
+
constructor(name, predicate) {
|
|
55
|
+
this.name = name;
|
|
56
|
+
this.predicate = predicate;
|
|
57
|
+
}
|
|
58
|
+
type = "condition";
|
|
59
|
+
tick(context) {
|
|
60
|
+
return this.predicate(context) ? "success" : "failure";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var WaitNode = class {
|
|
64
|
+
constructor(duration) {
|
|
65
|
+
this.duration = duration;
|
|
66
|
+
}
|
|
67
|
+
type = "wait";
|
|
68
|
+
elapsed = 0;
|
|
69
|
+
tick(_context, delta) {
|
|
70
|
+
this.elapsed += delta;
|
|
71
|
+
if (this.elapsed >= this.duration) {
|
|
72
|
+
return "success";
|
|
73
|
+
}
|
|
74
|
+
return "running";
|
|
75
|
+
}
|
|
76
|
+
reset() {
|
|
77
|
+
this.elapsed = 0;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var SequenceNode = class {
|
|
81
|
+
constructor(children) {
|
|
82
|
+
this.children = children;
|
|
83
|
+
}
|
|
84
|
+
type = "sequence";
|
|
85
|
+
currentIndex = 0;
|
|
86
|
+
tick(context, delta) {
|
|
87
|
+
while (this.currentIndex < this.children.length) {
|
|
88
|
+
const status = this.children[this.currentIndex].tick(context, delta);
|
|
89
|
+
if (status === "failure") {
|
|
90
|
+
this.currentIndex = 0;
|
|
91
|
+
return "failure";
|
|
92
|
+
}
|
|
93
|
+
if (status === "running") {
|
|
94
|
+
return "running";
|
|
95
|
+
}
|
|
96
|
+
this.currentIndex++;
|
|
97
|
+
}
|
|
98
|
+
this.currentIndex = 0;
|
|
99
|
+
return "success";
|
|
100
|
+
}
|
|
101
|
+
reset() {
|
|
102
|
+
this.currentIndex = 0;
|
|
103
|
+
for (const child of this.children) child.reset?.();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var SelectorNode = class {
|
|
107
|
+
constructor(children) {
|
|
108
|
+
this.children = children;
|
|
109
|
+
}
|
|
110
|
+
type = "selector";
|
|
111
|
+
currentIndex = 0;
|
|
112
|
+
tick(context, delta) {
|
|
113
|
+
while (this.currentIndex < this.children.length) {
|
|
114
|
+
const status = this.children[this.currentIndex].tick(context, delta);
|
|
115
|
+
if (status === "success") {
|
|
116
|
+
this.currentIndex = 0;
|
|
117
|
+
return "success";
|
|
118
|
+
}
|
|
119
|
+
if (status === "running") {
|
|
120
|
+
return "running";
|
|
121
|
+
}
|
|
122
|
+
this.currentIndex++;
|
|
123
|
+
}
|
|
124
|
+
this.currentIndex = 0;
|
|
125
|
+
return "failure";
|
|
126
|
+
}
|
|
127
|
+
reset() {
|
|
128
|
+
this.currentIndex = 0;
|
|
129
|
+
for (const child of this.children) child.reset?.();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var InverterNode = class {
|
|
133
|
+
constructor(child) {
|
|
134
|
+
this.child = child;
|
|
135
|
+
}
|
|
136
|
+
type = "inverter";
|
|
137
|
+
tick(context, delta) {
|
|
138
|
+
const status = this.child.tick(context, delta);
|
|
139
|
+
if (status === "success") return "failure";
|
|
140
|
+
if (status === "failure") return "success";
|
|
141
|
+
return "running";
|
|
142
|
+
}
|
|
143
|
+
reset() {
|
|
144
|
+
this.child.reset?.();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var RepeaterNode = class {
|
|
148
|
+
constructor(child, maxCount = -1) {
|
|
149
|
+
this.child = child;
|
|
150
|
+
this.maxCount = maxCount;
|
|
151
|
+
}
|
|
152
|
+
type = "repeater";
|
|
153
|
+
count = 0;
|
|
154
|
+
tick(context, delta) {
|
|
155
|
+
const status = this.child.tick(context, delta);
|
|
156
|
+
if (status === "running") return "running";
|
|
157
|
+
this.count++;
|
|
158
|
+
this.child.reset?.();
|
|
159
|
+
if (this.maxCount !== -1 && this.count >= this.maxCount) {
|
|
160
|
+
this.count = 0;
|
|
161
|
+
return "success";
|
|
162
|
+
}
|
|
163
|
+
return "running";
|
|
164
|
+
}
|
|
165
|
+
reset() {
|
|
166
|
+
this.count = 0;
|
|
167
|
+
this.child.reset?.();
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var BehaviorTree = class {
|
|
171
|
+
root;
|
|
172
|
+
context;
|
|
173
|
+
constructor(root, context = {}) {
|
|
174
|
+
this.root = root;
|
|
175
|
+
this.context = context;
|
|
176
|
+
}
|
|
177
|
+
tick(delta) {
|
|
178
|
+
return this.root.tick(this.context, delta);
|
|
179
|
+
}
|
|
180
|
+
getContext() {
|
|
181
|
+
return this.context;
|
|
182
|
+
}
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches BTContext index signature
|
|
184
|
+
setContext(key, value) {
|
|
185
|
+
this.context[key] = value;
|
|
186
|
+
}
|
|
187
|
+
reset() {
|
|
188
|
+
this.root.reset?.();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/behavior/BehaviorPresets.ts
|
|
193
|
+
function createPatrolBehavior(waypointCount = 3, pauseDuration = 2) {
|
|
194
|
+
return new RepeaterNode(
|
|
195
|
+
new SequenceNode([
|
|
196
|
+
new ActionNode("selectNextWaypoint", (ctx) => {
|
|
197
|
+
ctx.waypointIndex = ((ctx.waypointIndex || 0) + 1) % waypointCount;
|
|
198
|
+
ctx.targetReached = false;
|
|
199
|
+
return "success";
|
|
200
|
+
}),
|
|
201
|
+
new ActionNode("moveToWaypoint", (ctx, delta) => {
|
|
202
|
+
ctx.moveProgress = (ctx.moveProgress || 0) + delta * 0.5;
|
|
203
|
+
if (ctx.moveProgress >= 1) {
|
|
204
|
+
ctx.moveProgress = 0;
|
|
205
|
+
ctx.targetReached = true;
|
|
206
|
+
return "success";
|
|
207
|
+
}
|
|
208
|
+
return "running";
|
|
209
|
+
}),
|
|
210
|
+
new WaitNode(pauseDuration)
|
|
211
|
+
]),
|
|
212
|
+
-1
|
|
213
|
+
// Infinite loop
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function createIdleBehavior(idleDuration = 3) {
|
|
217
|
+
return new RepeaterNode(
|
|
218
|
+
new SequenceNode([
|
|
219
|
+
new WaitNode(idleDuration),
|
|
220
|
+
new ActionNode("lookAround", (ctx) => {
|
|
221
|
+
ctx.lookAngle = Math.random() * Math.PI * 2;
|
|
222
|
+
return "success";
|
|
223
|
+
})
|
|
224
|
+
]),
|
|
225
|
+
-1
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function createInteractBehavior() {
|
|
229
|
+
return new SequenceNode([
|
|
230
|
+
new ConditionNode("hasTarget", (ctx) => !!ctx.interactTarget),
|
|
231
|
+
new ActionNode("approach", (ctx, delta) => {
|
|
232
|
+
ctx.approachProgress = (ctx.approachProgress || 0) + delta;
|
|
233
|
+
if (ctx.approachProgress >= 1.5) {
|
|
234
|
+
ctx.approachProgress = 0;
|
|
235
|
+
return "success";
|
|
236
|
+
}
|
|
237
|
+
return "running";
|
|
238
|
+
}),
|
|
239
|
+
new ActionNode("interact", (ctx) => {
|
|
240
|
+
ctx.interactionCount = (ctx.interactionCount || 0) + 1;
|
|
241
|
+
ctx.interactTarget = null;
|
|
242
|
+
return "success";
|
|
243
|
+
})
|
|
244
|
+
]);
|
|
245
|
+
}
|
|
246
|
+
function createFollowBehavior(minDist = 1.5) {
|
|
247
|
+
return new RepeaterNode(
|
|
248
|
+
new SelectorNode([
|
|
249
|
+
// If close enough, idle
|
|
250
|
+
new SequenceNode([
|
|
251
|
+
new ConditionNode("closeEnough", (ctx) => {
|
|
252
|
+
const dist = ctx.distanceToTarget || 0;
|
|
253
|
+
return dist <= minDist;
|
|
254
|
+
}),
|
|
255
|
+
new WaitNode(0.5)
|
|
256
|
+
]),
|
|
257
|
+
// Otherwise, move toward target
|
|
258
|
+
new ActionNode("moveToTarget", (ctx, delta) => {
|
|
259
|
+
ctx.distanceToTarget = Math.max(0, (ctx.distanceToTarget || 5) - delta * 2);
|
|
260
|
+
return ctx.distanceToTarget <= minDist ? "success" : "running";
|
|
261
|
+
})
|
|
262
|
+
]),
|
|
263
|
+
-1
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function createAlertBehavior() {
|
|
267
|
+
return new SelectorNode([
|
|
268
|
+
// Fight if brave
|
|
269
|
+
new SequenceNode([
|
|
270
|
+
new ConditionNode("isBrave", (ctx) => ctx.courage > 0.5),
|
|
271
|
+
new ConditionNode("hasThreat", (ctx) => !!ctx.threat),
|
|
272
|
+
new ActionNode("fight", (ctx) => {
|
|
273
|
+
ctx.fightCount = (ctx.fightCount || 0) + 1;
|
|
274
|
+
ctx.threat = null;
|
|
275
|
+
return "success";
|
|
276
|
+
})
|
|
277
|
+
]),
|
|
278
|
+
// Flee if threatened
|
|
279
|
+
new SequenceNode([
|
|
280
|
+
new ConditionNode("hasThreat", (ctx) => !!ctx.threat),
|
|
281
|
+
new ActionNode("flee", (ctx, delta) => {
|
|
282
|
+
ctx.fleeProgress = (ctx.fleeProgress || 0) + delta;
|
|
283
|
+
if (ctx.fleeProgress >= 2) {
|
|
284
|
+
ctx.fleeProgress = 0;
|
|
285
|
+
ctx.threat = null;
|
|
286
|
+
return "success";
|
|
287
|
+
}
|
|
288
|
+
return "running";
|
|
289
|
+
})
|
|
290
|
+
]),
|
|
291
|
+
// Default: idle
|
|
292
|
+
new WaitNode(1)
|
|
293
|
+
]);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/behavior/StateMachine.ts
|
|
297
|
+
var StateMachine = class {
|
|
298
|
+
states = /* @__PURE__ */ new Map();
|
|
299
|
+
transitions = [];
|
|
300
|
+
currentStateName = "";
|
|
301
|
+
previousStateName = "";
|
|
302
|
+
context;
|
|
303
|
+
history = [];
|
|
304
|
+
maxHistory = 50;
|
|
305
|
+
constructor(config) {
|
|
306
|
+
this.context = config.context || {};
|
|
307
|
+
for (const state of config.states) {
|
|
308
|
+
this.states.set(state.name, state);
|
|
309
|
+
}
|
|
310
|
+
this.transitions = config.transitions;
|
|
311
|
+
this.enterState(config.initialState);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get the current state name.
|
|
315
|
+
*/
|
|
316
|
+
getCurrentState() {
|
|
317
|
+
return this.currentStateName;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get the previous state name.
|
|
321
|
+
*/
|
|
322
|
+
getPreviousState() {
|
|
323
|
+
return this.previousStateName;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Get the shared context.
|
|
327
|
+
*/
|
|
328
|
+
getContext() {
|
|
329
|
+
return this.context;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Get state transition history.
|
|
333
|
+
*/
|
|
334
|
+
getHistory() {
|
|
335
|
+
return [...this.history];
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Send an event to the state machine. May trigger a transition.
|
|
339
|
+
*/
|
|
340
|
+
send(event) {
|
|
341
|
+
const transition = this.transitions.find(
|
|
342
|
+
(t) => t.from === this.currentStateName && t.event === event && (!t.guard || t.guard(this.context))
|
|
343
|
+
);
|
|
344
|
+
if (!transition) return false;
|
|
345
|
+
this.executeTransition(transition);
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Try to transition based on guards (no event, just check conditions).
|
|
350
|
+
* Called automatically during update, or manually.
|
|
351
|
+
*/
|
|
352
|
+
evaluate() {
|
|
353
|
+
const transition = this.transitions.find(
|
|
354
|
+
(t) => t.from === this.currentStateName && !t.event && t.guard && t.guard(this.context)
|
|
355
|
+
);
|
|
356
|
+
if (!transition) return false;
|
|
357
|
+
this.executeTransition(transition);
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Force a transition to a specific state (bypasses guards).
|
|
362
|
+
*/
|
|
363
|
+
forceTransition(stateName) {
|
|
364
|
+
if (!this.states.has(stateName)) return;
|
|
365
|
+
const currentState = this.states.get(this.currentStateName);
|
|
366
|
+
if (currentState?.onExit) currentState.onExit(this.context);
|
|
367
|
+
this.enterState(stateName);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Update the state machine. Call every frame.
|
|
371
|
+
*/
|
|
372
|
+
update(delta) {
|
|
373
|
+
const state = this.states.get(this.currentStateName);
|
|
374
|
+
if (state?.onUpdate) {
|
|
375
|
+
state.onUpdate(this.context, delta);
|
|
376
|
+
}
|
|
377
|
+
this.evaluate();
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Check if we're in a specific state.
|
|
381
|
+
*/
|
|
382
|
+
isInState(stateName) {
|
|
383
|
+
return this.currentStateName === stateName;
|
|
384
|
+
}
|
|
385
|
+
executeTransition(transition) {
|
|
386
|
+
const fromState = this.states.get(this.currentStateName);
|
|
387
|
+
if (fromState?.onExit) fromState.onExit(this.context);
|
|
388
|
+
if (transition.action) transition.action(this.context);
|
|
389
|
+
this.enterState(transition.to);
|
|
390
|
+
}
|
|
391
|
+
enterState(stateName) {
|
|
392
|
+
this.previousStateName = this.currentStateName;
|
|
393
|
+
this.currentStateName = stateName;
|
|
394
|
+
this.history.push(stateName);
|
|
395
|
+
if (this.history.length > this.maxHistory) {
|
|
396
|
+
this.history.shift();
|
|
397
|
+
}
|
|
398
|
+
const state = this.states.get(stateName);
|
|
399
|
+
if (state?.onEnter) state.onEnter(this.context);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/behavior/StateTrait.ts
|
|
404
|
+
var nodeStateMachines = /* @__PURE__ */ new Map();
|
|
405
|
+
var stateTraitHandler = {
|
|
406
|
+
name: "state",
|
|
407
|
+
defaultConfig: { machine: { initialState: "idle", states: [], transitions: [] } },
|
|
408
|
+
onAttach(node, config, _context) {
|
|
409
|
+
const nodeId = node.id;
|
|
410
|
+
const sm = new StateMachine(config.machine);
|
|
411
|
+
nodeStateMachines.set(nodeId, sm);
|
|
412
|
+
if (node.properties) {
|
|
413
|
+
node.properties._state = sm.getCurrentState();
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
onDetach(node, _config, _context) {
|
|
417
|
+
nodeStateMachines.delete(node.id);
|
|
418
|
+
},
|
|
419
|
+
onUpdate(node, _config, _context, delta) {
|
|
420
|
+
const sm = nodeStateMachines.get(node.id);
|
|
421
|
+
if (!sm) return;
|
|
422
|
+
sm.update(delta);
|
|
423
|
+
if (node.properties) {
|
|
424
|
+
node.properties._state = sm.getCurrentState();
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
function getNodeStateMachine(nodeId) {
|
|
429
|
+
return nodeStateMachines.get(nodeId);
|
|
430
|
+
}
|
|
431
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
432
|
+
0 && (module.exports = {
|
|
433
|
+
ActionNode,
|
|
434
|
+
BehaviorTree,
|
|
435
|
+
ConditionNode,
|
|
436
|
+
InverterNode,
|
|
437
|
+
RepeaterNode,
|
|
438
|
+
SelectorNode,
|
|
439
|
+
SequenceNode,
|
|
440
|
+
StateMachine,
|
|
441
|
+
WaitNode,
|
|
442
|
+
createAlertBehavior,
|
|
443
|
+
createFollowBehavior,
|
|
444
|
+
createIdleBehavior,
|
|
445
|
+
createInteractBehavior,
|
|
446
|
+
createPatrolBehavior,
|
|
447
|
+
getNodeStateMachine,
|
|
448
|
+
stateTraitHandler
|
|
449
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { B as BTNode } from './BehaviorTree-BrBFECv5.cjs';
|
|
2
|
+
export { A as ActionNode, a as BTContext, b as BehaviorTree, C as ConditionNode, I as InverterNode, N as NodeStatus, R as RepeaterNode, S as SelectorNode, c as SequenceNode, W as WaitNode } from './BehaviorTree-BrBFECv5.cjs';
|
|
3
|
+
import { TraitHandler } from '@holoscript/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* BehaviorPresets.ts
|
|
7
|
+
*
|
|
8
|
+
* Pre-built behavior tree patterns for common NPC and object behaviors.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Patrol: Move between waypoints with pauses.
|
|
13
|
+
*/
|
|
14
|
+
declare function createPatrolBehavior(waypointCount?: number, pauseDuration?: number): BTNode;
|
|
15
|
+
/**
|
|
16
|
+
* Idle: Wait, look around, repeat.
|
|
17
|
+
*/
|
|
18
|
+
declare function createIdleBehavior(idleDuration?: number): BTNode;
|
|
19
|
+
/**
|
|
20
|
+
* Interact: Approach target, interact, return to origin.
|
|
21
|
+
*/
|
|
22
|
+
declare function createInteractBehavior(): BTNode;
|
|
23
|
+
/**
|
|
24
|
+
* Follow: Follow a target entity, maintaining distance.
|
|
25
|
+
*/
|
|
26
|
+
declare function createFollowBehavior(minDist?: number): BTNode;
|
|
27
|
+
/**
|
|
28
|
+
* Alert: Check for threats, flee or fight.
|
|
29
|
+
*/
|
|
30
|
+
declare function createAlertBehavior(): BTNode;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* StateMachine.ts
|
|
34
|
+
*
|
|
35
|
+
* Finite State Machine (FSM) for game logic, NPC AI, and UI state management.
|
|
36
|
+
* Supports:
|
|
37
|
+
* - Named states with enter/update/exit callbacks
|
|
38
|
+
* - Guarded transitions (conditions that must be true to transition)
|
|
39
|
+
* - Transition actions (side effects on transition)
|
|
40
|
+
* - Event-driven and tick-driven transitions
|
|
41
|
+
* - State history tracking
|
|
42
|
+
*/
|
|
43
|
+
interface StateConfig {
|
|
44
|
+
name: string;
|
|
45
|
+
onEnter?: (context: Record<string, unknown>) => void;
|
|
46
|
+
onUpdate?: (context: Record<string, unknown>, delta: number) => void;
|
|
47
|
+
onExit?: (context: Record<string, unknown>) => void;
|
|
48
|
+
}
|
|
49
|
+
interface TransitionConfig {
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
event?: string;
|
|
53
|
+
guard?: (context: Record<string, unknown>) => boolean;
|
|
54
|
+
action?: (context: Record<string, unknown>) => void;
|
|
55
|
+
}
|
|
56
|
+
interface StateMachineConfig {
|
|
57
|
+
initialState: string;
|
|
58
|
+
states: StateConfig[];
|
|
59
|
+
transitions: TransitionConfig[];
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
declare class StateMachine {
|
|
63
|
+
private states;
|
|
64
|
+
private transitions;
|
|
65
|
+
private currentStateName;
|
|
66
|
+
private previousStateName;
|
|
67
|
+
private context;
|
|
68
|
+
private history;
|
|
69
|
+
private maxHistory;
|
|
70
|
+
constructor(config: StateMachineConfig);
|
|
71
|
+
/**
|
|
72
|
+
* Get the current state name.
|
|
73
|
+
*/
|
|
74
|
+
getCurrentState(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Get the previous state name.
|
|
77
|
+
*/
|
|
78
|
+
getPreviousState(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the shared context.
|
|
81
|
+
*/
|
|
82
|
+
getContext(): Record<string, unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* Get state transition history.
|
|
85
|
+
*/
|
|
86
|
+
getHistory(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Send an event to the state machine. May trigger a transition.
|
|
89
|
+
*/
|
|
90
|
+
send(event: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Try to transition based on guards (no event, just check conditions).
|
|
93
|
+
* Called automatically during update, or manually.
|
|
94
|
+
*/
|
|
95
|
+
evaluate(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Force a transition to a specific state (bypasses guards).
|
|
98
|
+
*/
|
|
99
|
+
forceTransition(stateName: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Update the state machine. Call every frame.
|
|
102
|
+
*/
|
|
103
|
+
update(delta: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Check if we're in a specific state.
|
|
106
|
+
*/
|
|
107
|
+
isInState(stateName: string): boolean;
|
|
108
|
+
private executeTransition;
|
|
109
|
+
private enterState;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* StateTrait.ts
|
|
114
|
+
*
|
|
115
|
+
* Declarative FSM attachment to HoloScript+ nodes.
|
|
116
|
+
* Allows nodes to define states and transitions as trait config.
|
|
117
|
+
*
|
|
118
|
+
* @trait state
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
interface StateTraitConfig {
|
|
122
|
+
machine: StateMachineConfig;
|
|
123
|
+
}
|
|
124
|
+
declare const stateTraitHandler: TraitHandler<StateTraitConfig>;
|
|
125
|
+
/**
|
|
126
|
+
* Get the StateMachine for a given node (for external event sending).
|
|
127
|
+
*/
|
|
128
|
+
declare function getNodeStateMachine(nodeId: string): StateMachine | undefined;
|
|
129
|
+
|
|
130
|
+
export { BTNode, type StateConfig, StateMachine, type StateMachineConfig, type StateTraitConfig, type TransitionConfig, createAlertBehavior, createFollowBehavior, createIdleBehavior, createInteractBehavior, createPatrolBehavior, getNodeStateMachine, stateTraitHandler };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { B as BTNode } from './BehaviorTree-BrBFECv5.js';
|
|
2
|
+
export { A as ActionNode, a as BTContext, b as BehaviorTree, C as ConditionNode, I as InverterNode, N as NodeStatus, R as RepeaterNode, S as SelectorNode, c as SequenceNode, W as WaitNode } from './BehaviorTree-BrBFECv5.js';
|
|
3
|
+
import { TraitHandler } from '@holoscript/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* BehaviorPresets.ts
|
|
7
|
+
*
|
|
8
|
+
* Pre-built behavior tree patterns for common NPC and object behaviors.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Patrol: Move between waypoints with pauses.
|
|
13
|
+
*/
|
|
14
|
+
declare function createPatrolBehavior(waypointCount?: number, pauseDuration?: number): BTNode;
|
|
15
|
+
/**
|
|
16
|
+
* Idle: Wait, look around, repeat.
|
|
17
|
+
*/
|
|
18
|
+
declare function createIdleBehavior(idleDuration?: number): BTNode;
|
|
19
|
+
/**
|
|
20
|
+
* Interact: Approach target, interact, return to origin.
|
|
21
|
+
*/
|
|
22
|
+
declare function createInteractBehavior(): BTNode;
|
|
23
|
+
/**
|
|
24
|
+
* Follow: Follow a target entity, maintaining distance.
|
|
25
|
+
*/
|
|
26
|
+
declare function createFollowBehavior(minDist?: number): BTNode;
|
|
27
|
+
/**
|
|
28
|
+
* Alert: Check for threats, flee or fight.
|
|
29
|
+
*/
|
|
30
|
+
declare function createAlertBehavior(): BTNode;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* StateMachine.ts
|
|
34
|
+
*
|
|
35
|
+
* Finite State Machine (FSM) for game logic, NPC AI, and UI state management.
|
|
36
|
+
* Supports:
|
|
37
|
+
* - Named states with enter/update/exit callbacks
|
|
38
|
+
* - Guarded transitions (conditions that must be true to transition)
|
|
39
|
+
* - Transition actions (side effects on transition)
|
|
40
|
+
* - Event-driven and tick-driven transitions
|
|
41
|
+
* - State history tracking
|
|
42
|
+
*/
|
|
43
|
+
interface StateConfig {
|
|
44
|
+
name: string;
|
|
45
|
+
onEnter?: (context: Record<string, unknown>) => void;
|
|
46
|
+
onUpdate?: (context: Record<string, unknown>, delta: number) => void;
|
|
47
|
+
onExit?: (context: Record<string, unknown>) => void;
|
|
48
|
+
}
|
|
49
|
+
interface TransitionConfig {
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
event?: string;
|
|
53
|
+
guard?: (context: Record<string, unknown>) => boolean;
|
|
54
|
+
action?: (context: Record<string, unknown>) => void;
|
|
55
|
+
}
|
|
56
|
+
interface StateMachineConfig {
|
|
57
|
+
initialState: string;
|
|
58
|
+
states: StateConfig[];
|
|
59
|
+
transitions: TransitionConfig[];
|
|
60
|
+
context?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
declare class StateMachine {
|
|
63
|
+
private states;
|
|
64
|
+
private transitions;
|
|
65
|
+
private currentStateName;
|
|
66
|
+
private previousStateName;
|
|
67
|
+
private context;
|
|
68
|
+
private history;
|
|
69
|
+
private maxHistory;
|
|
70
|
+
constructor(config: StateMachineConfig);
|
|
71
|
+
/**
|
|
72
|
+
* Get the current state name.
|
|
73
|
+
*/
|
|
74
|
+
getCurrentState(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Get the previous state name.
|
|
77
|
+
*/
|
|
78
|
+
getPreviousState(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the shared context.
|
|
81
|
+
*/
|
|
82
|
+
getContext(): Record<string, unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* Get state transition history.
|
|
85
|
+
*/
|
|
86
|
+
getHistory(): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Send an event to the state machine. May trigger a transition.
|
|
89
|
+
*/
|
|
90
|
+
send(event: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Try to transition based on guards (no event, just check conditions).
|
|
93
|
+
* Called automatically during update, or manually.
|
|
94
|
+
*/
|
|
95
|
+
evaluate(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Force a transition to a specific state (bypasses guards).
|
|
98
|
+
*/
|
|
99
|
+
forceTransition(stateName: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Update the state machine. Call every frame.
|
|
102
|
+
*/
|
|
103
|
+
update(delta: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* Check if we're in a specific state.
|
|
106
|
+
*/
|
|
107
|
+
isInState(stateName: string): boolean;
|
|
108
|
+
private executeTransition;
|
|
109
|
+
private enterState;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* StateTrait.ts
|
|
114
|
+
*
|
|
115
|
+
* Declarative FSM attachment to HoloScript+ nodes.
|
|
116
|
+
* Allows nodes to define states and transitions as trait config.
|
|
117
|
+
*
|
|
118
|
+
* @trait state
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
interface StateTraitConfig {
|
|
122
|
+
machine: StateMachineConfig;
|
|
123
|
+
}
|
|
124
|
+
declare const stateTraitHandler: TraitHandler<StateTraitConfig>;
|
|
125
|
+
/**
|
|
126
|
+
* Get the StateMachine for a given node (for external event sending).
|
|
127
|
+
*/
|
|
128
|
+
declare function getNodeStateMachine(nodeId: string): StateMachine | undefined;
|
|
129
|
+
|
|
130
|
+
export { BTNode, type StateConfig, StateMachine, type StateMachineConfig, type StateTraitConfig, type TransitionConfig, createAlertBehavior, createFollowBehavior, createIdleBehavior, createInteractBehavior, createPatrolBehavior, getNodeStateMachine, stateTraitHandler };
|