@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.
Files changed (329) hide show
  1. package/ALL-test-results.json +1 -0
  2. package/CHANGELOG.md +8 -0
  3. package/LICENSE +21 -0
  4. package/ROADMAP.md +175 -0
  5. package/dist/AgentManifest-CB4xM-Ma.d.cts +704 -0
  6. package/dist/AgentManifest-CB4xM-Ma.d.ts +704 -0
  7. package/dist/BehaviorTree-BrBFECv5.d.cts +103 -0
  8. package/dist/BehaviorTree-BrBFECv5.d.ts +103 -0
  9. package/dist/InvisibleWallet-BB6tFvRA.d.cts +1732 -0
  10. package/dist/InvisibleWallet-rtRrBOA8.d.ts +1732 -0
  11. package/dist/OrchestratorAgent-BvWgf9uw.d.cts +798 -0
  12. package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +798 -0
  13. package/dist/agents/index.cjs +4790 -0
  14. package/dist/agents/index.d.cts +1788 -0
  15. package/dist/agents/index.d.ts +1788 -0
  16. package/dist/agents/index.js +4695 -0
  17. package/dist/ai/index.cjs +5347 -0
  18. package/dist/ai/index.d.cts +1753 -0
  19. package/dist/ai/index.d.ts +1753 -0
  20. package/dist/ai/index.js +5244 -0
  21. package/dist/behavior.cjs +449 -0
  22. package/dist/behavior.d.cts +130 -0
  23. package/dist/behavior.d.ts +130 -0
  24. package/dist/behavior.js +407 -0
  25. package/dist/economy/index.cjs +3659 -0
  26. package/dist/economy/index.d.cts +747 -0
  27. package/dist/economy/index.d.ts +747 -0
  28. package/dist/economy/index.js +3617 -0
  29. package/dist/implementations-D9T3un9D.d.cts +236 -0
  30. package/dist/implementations-D9T3un9D.d.ts +236 -0
  31. package/dist/index.cjs +24550 -0
  32. package/dist/index.d.cts +1729 -0
  33. package/dist/index.d.ts +1729 -0
  34. package/dist/index.js +24277 -0
  35. package/dist/learning/index.cjs +219 -0
  36. package/dist/learning/index.d.cts +104 -0
  37. package/dist/learning/index.d.ts +104 -0
  38. package/dist/learning/index.js +189 -0
  39. package/dist/negotiation/index.cjs +970 -0
  40. package/dist/negotiation/index.d.cts +610 -0
  41. package/dist/negotiation/index.d.ts +610 -0
  42. package/dist/negotiation/index.js +931 -0
  43. package/dist/skills/index.cjs +1118 -0
  44. package/dist/skills/index.d.cts +289 -0
  45. package/dist/skills/index.d.ts +289 -0
  46. package/dist/skills/index.js +1079 -0
  47. package/dist/swarm/index.cjs +5268 -0
  48. package/dist/swarm/index.d.cts +2433 -0
  49. package/dist/swarm/index.d.ts +2433 -0
  50. package/dist/swarm/index.js +5221 -0
  51. package/dist/training/index.cjs +2745 -0
  52. package/dist/training/index.d.cts +1734 -0
  53. package/dist/training/index.d.ts +1734 -0
  54. package/dist/training/index.js +2687 -0
  55. package/extract-failures.js +10 -0
  56. package/package.json +82 -0
  57. package/src/__tests__/bounty-marketplace.test.ts +374 -0
  58. package/src/__tests__/delegation.test.ts +144 -0
  59. package/src/__tests__/distributed-claimer.test.ts +147 -0
  60. package/src/__tests__/done-log-audit.test.ts +342 -0
  61. package/src/__tests__/framework.test.ts +865 -0
  62. package/src/__tests__/goal-synthesizer.test.ts +236 -0
  63. package/src/__tests__/presence.test.ts +223 -0
  64. package/src/__tests__/protocol-agent.test.ts +254 -0
  65. package/src/__tests__/revenue-splitter.test.ts +114 -0
  66. package/src/__tests__/scenario-driven-todo.test.ts +197 -0
  67. package/src/__tests__/self-improve.test.ts +349 -0
  68. package/src/__tests__/service-lifecycle.test.ts +237 -0
  69. package/src/__tests__/skill-router.test.ts +121 -0
  70. package/src/agents/AgentManifest.ts +493 -0
  71. package/src/agents/AgentRegistry.ts +475 -0
  72. package/src/agents/AgentTypes.ts +585 -0
  73. package/src/agents/AgentWalletRegistry.ts +83 -0
  74. package/src/agents/AuthenticatedCRDT.ts +388 -0
  75. package/src/agents/CapabilityMatcher.ts +453 -0
  76. package/src/agents/CrossRealityHandoff.ts +305 -0
  77. package/src/agents/CulturalMemory.ts +454 -0
  78. package/src/agents/FederatedRegistryAdapter.ts +429 -0
  79. package/src/agents/NormEngine.ts +450 -0
  80. package/src/agents/OrchestratorAgent.ts +414 -0
  81. package/src/agents/SkillWorkflowEngine.ts +472 -0
  82. package/src/agents/TaskDelegationService.ts +551 -0
  83. package/src/agents/__tests__/AgentManifest.prod.test.ts +134 -0
  84. package/src/agents/__tests__/AgentManifest.test.ts +182 -0
  85. package/src/agents/__tests__/AgentModule.test.ts +864 -0
  86. package/src/agents/__tests__/AgentRegistry.prod.test.ts +125 -0
  87. package/src/agents/__tests__/AgentRegistry.test.ts +148 -0
  88. package/src/agents/__tests__/AgentTypes.test.ts +534 -0
  89. package/src/agents/__tests__/AgentWalletRegistry.test.ts +152 -0
  90. package/src/agents/__tests__/AuthenticatedCRDT.test.ts +558 -0
  91. package/src/agents/__tests__/CapabilityMatcher.prod.test.ts +117 -0
  92. package/src/agents/__tests__/CapabilityMatcher.test.ts +178 -0
  93. package/src/agents/__tests__/CrossRealityHandoff.test.ts +402 -0
  94. package/src/agents/__tests__/CulturalMemory.test.ts +200 -0
  95. package/src/agents/__tests__/FederatedRegistryAdapter.test.ts +409 -0
  96. package/src/agents/__tests__/NormEngine.test.ts +276 -0
  97. package/src/agents/__tests__/OrchestratorAgent.test.ts +182 -0
  98. package/src/agents/__tests__/SkillWorkflowEngine.test.ts +357 -0
  99. package/src/agents/__tests__/TaskDelegationService.test.ts +446 -0
  100. package/src/agents/index.ts +107 -0
  101. package/src/agents/spatial-comms/Layer1RealTime.ts +621 -0
  102. package/src/agents/spatial-comms/Layer2A2A.ts +661 -0
  103. package/src/agents/spatial-comms/Layer3MCP.ts +651 -0
  104. package/src/agents/spatial-comms/ProtocolTypes.ts +543 -0
  105. package/src/agents/spatial-comms/SpatialCommClient.ts +483 -0
  106. package/src/agents/spatial-comms/__tests__/performance-benchmark.test.ts +465 -0
  107. package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +409 -0
  108. package/src/agents/spatial-comms/index.ts +66 -0
  109. package/src/ai/AIAdapter.ts +313 -0
  110. package/src/ai/AICopilot.ts +331 -0
  111. package/src/ai/AIOutputValidator.ts +203 -0
  112. package/src/ai/BTNodes.ts +239 -0
  113. package/src/ai/BehaviorSelector.ts +135 -0
  114. package/src/ai/BehaviorTree.ts +153 -0
  115. package/src/ai/Blackboard.ts +165 -0
  116. package/src/ai/GenerationAnalytics.ts +461 -0
  117. package/src/ai/GenerationCache.ts +265 -0
  118. package/src/ai/GoalPlanner.ts +165 -0
  119. package/src/ai/HoloScriptGenerator.ts +580 -0
  120. package/src/ai/InfluenceMap.ts +180 -0
  121. package/src/ai/NavMesh.ts +168 -0
  122. package/src/ai/PerceptionSystem.ts +178 -0
  123. package/src/ai/PromptTemplates.ts +453 -0
  124. package/src/ai/SemanticSearchService.ts +80 -0
  125. package/src/ai/StateMachine.ts +196 -0
  126. package/src/ai/SteeringBehavior.ts +150 -0
  127. package/src/ai/SteeringBehaviors.ts +244 -0
  128. package/src/ai/TrainingDataGenerator.ts +1082 -0
  129. package/src/ai/UtilityAI.ts +145 -0
  130. package/src/ai/__tests__/AIAdapter.prod.test.ts +259 -0
  131. package/src/ai/__tests__/AIAdapter.test.ts +109 -0
  132. package/src/ai/__tests__/AICopilot.prod.test.ts +341 -0
  133. package/src/ai/__tests__/AICopilot.test.ts +178 -0
  134. package/src/ai/__tests__/AIOutputValidator.prod.test.ts +226 -0
  135. package/src/ai/__tests__/AIOutputValidator.test.ts +138 -0
  136. package/src/ai/__tests__/BTNodes.prod.test.ts +391 -0
  137. package/src/ai/__tests__/BTNodes.test.ts +263 -0
  138. package/src/ai/__tests__/BehaviorSelector.prod.test.ts +129 -0
  139. package/src/ai/__tests__/BehaviorSelector.test.ts +132 -0
  140. package/src/ai/__tests__/BehaviorTree.prod.test.ts +266 -0
  141. package/src/ai/__tests__/BehaviorTree.test.ts +216 -0
  142. package/src/ai/__tests__/Blackboard.prod.test.ts +339 -0
  143. package/src/ai/__tests__/Blackboard.test.ts +183 -0
  144. package/src/ai/__tests__/GenerationAnalytics.prod.test.ts +141 -0
  145. package/src/ai/__tests__/GenerationAnalytics.test.ts +165 -0
  146. package/src/ai/__tests__/GenerationCache.prod.test.ts +144 -0
  147. package/src/ai/__tests__/GenerationCache.test.ts +171 -0
  148. package/src/ai/__tests__/GoalPlanner.prod.test.ts +189 -0
  149. package/src/ai/__tests__/GoalPlanner.test.ts +137 -0
  150. package/src/ai/__tests__/GoalPlannerDepth.prod.test.ts +217 -0
  151. package/src/ai/__tests__/HoloScriptGenerator.test.ts +125 -0
  152. package/src/ai/__tests__/InfluenceMap.prod.test.ts +146 -0
  153. package/src/ai/__tests__/InfluenceMap.test.ts +149 -0
  154. package/src/ai/__tests__/NavMesh.prod.test.ts +141 -0
  155. package/src/ai/__tests__/NavMesh.test.ts +159 -0
  156. package/src/ai/__tests__/PerceptionSystem.prod.test.ts +135 -0
  157. package/src/ai/__tests__/PerceptionSystem.test.ts +250 -0
  158. package/src/ai/__tests__/PromptTemplates.prod.test.ts +313 -0
  159. package/src/ai/__tests__/PromptTemplates.test.ts +146 -0
  160. package/src/ai/__tests__/SemanticSearch.test.ts +37 -0
  161. package/src/ai/__tests__/StateMachine.prod.test.ts +162 -0
  162. package/src/ai/__tests__/StateMachine.test.ts +163 -0
  163. package/src/ai/__tests__/SteeringBehavior.prod.test.ts +251 -0
  164. package/src/ai/__tests__/SteeringBehavior.test.ts +135 -0
  165. package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +133 -0
  166. package/src/ai/__tests__/SteeringBehaviors.test.ts +151 -0
  167. package/src/ai/__tests__/TrainingDataGenerator.prod.test.ts +286 -0
  168. package/src/ai/__tests__/TrainingDataGenerator.test.ts +286 -0
  169. package/src/ai/__tests__/UtilityAI.prod.test.ts +207 -0
  170. package/src/ai/__tests__/UtilityAI.test.ts +155 -0
  171. package/src/ai/__tests__/adapters.prod.test.ts +263 -0
  172. package/src/ai/__tests__/adapters.test.ts +320 -0
  173. package/src/ai/adapters.ts +1585 -0
  174. package/src/ai/index.ts +130 -0
  175. package/src/behavior/BehaviorPresets.ts +140 -0
  176. package/src/behavior/BehaviorTree.ts +236 -0
  177. package/src/behavior/StateMachine.ts +176 -0
  178. package/src/behavior/StateTrait.ts +67 -0
  179. package/src/behavior/index.ts +8 -0
  180. package/src/behavior.ts +8 -0
  181. package/src/board/audit.ts +284 -0
  182. package/src/board/board-ops.ts +336 -0
  183. package/src/board/board-types.ts +302 -0
  184. package/src/board/index.ts +69 -0
  185. package/src/define-agent.ts +46 -0
  186. package/src/define-team.ts +33 -0
  187. package/src/delegation.ts +265 -0
  188. package/src/distributed-claimer.ts +228 -0
  189. package/src/economy/AgentBudgetEnforcer.ts +464 -0
  190. package/src/economy/BountyManager.ts +185 -0
  191. package/src/economy/CreatorRevenueAggregator.ts +460 -0
  192. package/src/economy/InvisibleWallet.ts +82 -0
  193. package/src/economy/KnowledgeMarketplace.ts +193 -0
  194. package/src/economy/PaymentWebhookService.ts +512 -0
  195. package/src/economy/RevenueSplitter.ts +156 -0
  196. package/src/economy/SubscriptionManager.ts +546 -0
  197. package/src/economy/UnifiedBudgetOptimizer.ts +635 -0
  198. package/src/economy/UsageMeter.ts +440 -0
  199. package/src/economy/_core-stubs.ts +219 -0
  200. package/src/economy/index.ts +100 -0
  201. package/src/economy/x402-facilitator.ts +1978 -0
  202. package/src/index.ts +348 -0
  203. package/src/knowledge/__tests__/knowledge-consolidator.test.ts +444 -0
  204. package/src/knowledge/__tests__/knowledge-store-vector.test.ts +291 -0
  205. package/src/knowledge/brain.ts +167 -0
  206. package/src/knowledge/consolidation.ts +581 -0
  207. package/src/knowledge/knowledge-consolidator.ts +510 -0
  208. package/src/knowledge/knowledge-store.ts +616 -0
  209. package/src/learning/MemoryConsolidator.ts +102 -0
  210. package/src/learning/MemoryScorer.ts +69 -0
  211. package/src/learning/ProceduralCompiler.ts +45 -0
  212. package/src/learning/SemanticClusterer.ts +66 -0
  213. package/src/learning/index.ts +8 -0
  214. package/src/llm/llm-adapter.ts +159 -0
  215. package/src/mesh/index.ts +309 -0
  216. package/src/negotiation/NegotiationProtocol.ts +694 -0
  217. package/src/negotiation/NegotiationTypes.ts +473 -0
  218. package/src/negotiation/VotingMechanisms.ts +691 -0
  219. package/src/negotiation/index.ts +49 -0
  220. package/src/protocol/goal-synthesizer.ts +317 -0
  221. package/src/protocol/implementations.ts +474 -0
  222. package/src/protocol/micro-phase-decomposer.ts +299 -0
  223. package/src/protocol/micro-step-decomposer.test.ts +306 -0
  224. package/src/protocol-agent.test.ts +353 -0
  225. package/src/protocol-agent.ts +670 -0
  226. package/src/self-improve/absorb-scanner.ts +252 -0
  227. package/src/self-improve/evolution-engine.ts +149 -0
  228. package/src/self-improve/framework-absorber.ts +214 -0
  229. package/src/self-improve/index.ts +50 -0
  230. package/src/self-improve/prompt-optimizer.ts +212 -0
  231. package/src/self-improve/test-generator.ts +175 -0
  232. package/src/skill-router.ts +186 -0
  233. package/src/skills/index.ts +5 -0
  234. package/src/skills/skill-md-bridge.ts +1699 -0
  235. package/src/swarm/ACOEngine.ts +261 -0
  236. package/src/swarm/CollectiveIntelligence.ts +383 -0
  237. package/src/swarm/ContributionSynthesizer.ts +481 -0
  238. package/src/swarm/LeaderElection.ts +393 -0
  239. package/src/swarm/PSOEngine.ts +206 -0
  240. package/src/swarm/QuorumPolicy.ts +173 -0
  241. package/src/swarm/SwarmCoordinator.ts +335 -0
  242. package/src/swarm/SwarmManager.ts +442 -0
  243. package/src/swarm/SwarmMembership.ts +456 -0
  244. package/src/swarm/VotingRound.ts +255 -0
  245. package/src/swarm/__tests__/ACOEngine.prod.test.ts +164 -0
  246. package/src/swarm/__tests__/ACOEngine.test.ts +117 -0
  247. package/src/swarm/__tests__/CollectiveIntelligence.prod.test.ts +296 -0
  248. package/src/swarm/__tests__/CollectiveIntelligence.test.ts +457 -0
  249. package/src/swarm/__tests__/ContributionSynthesizer.prod.test.ts +269 -0
  250. package/src/swarm/__tests__/ContributionSynthesizer.test.ts +254 -0
  251. package/src/swarm/__tests__/LeaderElection.prod.test.ts +196 -0
  252. package/src/swarm/__tests__/LeaderElection.test.ts +151 -0
  253. package/src/swarm/__tests__/PSOEngine.prod.test.ts +162 -0
  254. package/src/swarm/__tests__/PSOEngine.test.ts +106 -0
  255. package/src/swarm/__tests__/QuorumPolicy.prod.test.ts +216 -0
  256. package/src/swarm/__tests__/QuorumPolicy.test.ts +177 -0
  257. package/src/swarm/__tests__/SwarmCoordinator.prod.test.ts +186 -0
  258. package/src/swarm/__tests__/SwarmCoordinator.test.ts +167 -0
  259. package/src/swarm/__tests__/SwarmManager.prod.test.ts +308 -0
  260. package/src/swarm/__tests__/SwarmManager.test.ts +373 -0
  261. package/src/swarm/__tests__/SwarmMembership.prod.test.ts +273 -0
  262. package/src/swarm/__tests__/SwarmMembership.test.ts +264 -0
  263. package/src/swarm/__tests__/VotingRound.prod.test.ts +233 -0
  264. package/src/swarm/__tests__/VotingRound.test.ts +174 -0
  265. package/src/swarm/analytics/SwarmInspector.ts +476 -0
  266. package/src/swarm/analytics/SwarmMetrics.ts +449 -0
  267. package/src/swarm/analytics/__tests__/SwarmInspector.prod.test.ts +366 -0
  268. package/src/swarm/analytics/__tests__/SwarmInspector.test.ts +454 -0
  269. package/src/swarm/analytics/__tests__/SwarmMetrics.prod.test.ts +254 -0
  270. package/src/swarm/analytics/__tests__/SwarmMetrics.test.ts +370 -0
  271. package/src/swarm/analytics/index.ts +7 -0
  272. package/src/swarm/index.ts +69 -0
  273. package/src/swarm/messaging/BroadcastChannel.ts +509 -0
  274. package/src/swarm/messaging/GossipProtocol.ts +565 -0
  275. package/src/swarm/messaging/SwarmEventBus.ts +443 -0
  276. package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +331 -0
  277. package/src/swarm/messaging/__tests__/BroadcastChannel.test.ts +333 -0
  278. package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +356 -0
  279. package/src/swarm/messaging/__tests__/GossipProtocol.test.ts +437 -0
  280. package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +191 -0
  281. package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +247 -0
  282. package/src/swarm/messaging/index.ts +8 -0
  283. package/src/swarm/spatial/FlockingBehavior.ts +462 -0
  284. package/src/swarm/spatial/FormationController.ts +500 -0
  285. package/src/swarm/spatial/Vector3.ts +170 -0
  286. package/src/swarm/spatial/ZoneClaiming.ts +509 -0
  287. package/src/swarm/spatial/__tests__/FlockingBehavior.prod.test.ts +239 -0
  288. package/src/swarm/spatial/__tests__/FlockingBehavior.test.ts +298 -0
  289. package/src/swarm/spatial/__tests__/FormationController.prod.test.ts +240 -0
  290. package/src/swarm/spatial/__tests__/FormationController.test.ts +297 -0
  291. package/src/swarm/spatial/__tests__/Vector3.prod.test.ts +283 -0
  292. package/src/swarm/spatial/__tests__/Vector3.test.ts +224 -0
  293. package/src/swarm/spatial/__tests__/ZoneClaiming.prod.test.ts +246 -0
  294. package/src/swarm/spatial/__tests__/ZoneClaiming.test.ts +374 -0
  295. package/src/swarm/spatial/index.ts +28 -0
  296. package/src/team.ts +1245 -0
  297. package/src/training/LRScheduler.ts +377 -0
  298. package/src/training/QualityScoringPipeline.ts +139 -0
  299. package/src/training/SoftDedup.ts +461 -0
  300. package/src/training/SparsityMonitor.ts +685 -0
  301. package/src/training/SparsityMonitorTypes.ts +209 -0
  302. package/src/training/SpatialTrainingDataGenerator.ts +1526 -0
  303. package/src/training/SpatialTrainingDataTypes.ts +216 -0
  304. package/src/training/TrainingPipelineConfig.ts +215 -0
  305. package/src/training/constants.ts +94 -0
  306. package/src/training/index.ts +138 -0
  307. package/src/training/schema.ts +147 -0
  308. package/src/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
  309. package/src/training/scripts/generate-spatial-dataset.ts +521 -0
  310. package/src/training/training/data/novel-use-cases.jsonl +153 -0
  311. package/src/training/training/data/spatial-reasoning-10k.jsonl +9354 -0
  312. package/src/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
  313. package/src/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
  314. package/src/training/trainingmonkey/index.ts +26 -0
  315. package/src/training/trait-mappings.ts +157 -0
  316. package/src/types/core-stubs.d.ts +113 -0
  317. package/src/types.ts +304 -0
  318. package/test-output.txt +0 -0
  319. package/test-result.json +1 -0
  320. package/tsc-errors.txt +4 -0
  321. package/tsc_output.txt +0 -0
  322. package/tsconfig.json +14 -0
  323. package/tsup-learning-esm.config.ts +12 -0
  324. package/tsup.config.ts +21 -0
  325. package/typescript-errors-2.txt +0 -0
  326. package/typescript-errors.txt +22 -0
  327. package/vitest-log-utf8.txt +268 -0
  328. package/vitest-log.txt +0 -0
  329. package/vitest.config.ts +8 -0
@@ -0,0 +1,1753 @@
1
+ import { HSPlusCompileResult } from '@holoscript/core';
2
+
3
+ /**
4
+ * @holoscript/core AI Adapter Interface
5
+ *
6
+ * Provider-agnostic AI integration for HoloScript.
7
+ * Users can implement this interface to integrate any AI service.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { AIAdapter, registerAIAdapter } from '@holoscript/core';
12
+ *
13
+ * // Implement your own adapter
14
+ * class MyOpenAIAdapter implements AIAdapter {
15
+ * async generateHoloScript(prompt: string) {
16
+ * const response = await openai.chat.completions.create({...});
17
+ * return { holoScript: response.choices[0].message.content };
18
+ * }
19
+ * }
20
+ *
21
+ * // Register it
22
+ * registerAIAdapter(new MyOpenAIAdapter());
23
+ * ```
24
+ */
25
+ /**
26
+ * Result of HoloScript generation from natural language
27
+ */
28
+ interface GenerateResult {
29
+ /** Generated HoloScript code */
30
+ holoScript: string;
31
+ /** Confidence score (0-1) */
32
+ confidence?: number;
33
+ /** Estimated object count */
34
+ objectCount?: number;
35
+ /** Any warnings or suggestions */
36
+ warnings?: string[];
37
+ /** Provider-specific metadata */
38
+ metadata?: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * Result of HoloScript explanation
42
+ */
43
+ interface ExplainResult {
44
+ /** Human-readable explanation */
45
+ explanation: string;
46
+ /** Line-by-line breakdown */
47
+ breakdown?: Array<{
48
+ line: number;
49
+ code: string;
50
+ description: string;
51
+ }>;
52
+ }
53
+ /**
54
+ * Result of HoloScript optimization
55
+ */
56
+ interface OptimizeResult {
57
+ /** Optimized HoloScript code */
58
+ holoScript: string;
59
+ /** What was improved */
60
+ improvements: string[];
61
+ /** Performance metrics comparison */
62
+ metrics?: {
63
+ before: {
64
+ polygons?: number;
65
+ nodes?: number;
66
+ };
67
+ after: {
68
+ polygons?: number;
69
+ nodes?: number;
70
+ };
71
+ };
72
+ }
73
+ /**
74
+ * Result of HoloScript validation/fixing
75
+ */
76
+ interface FixResult {
77
+ /** Fixed HoloScript code */
78
+ holoScript: string;
79
+ /** Issues that were fixed */
80
+ fixes: Array<{
81
+ line: number;
82
+ issue: string;
83
+ fix: string;
84
+ }>;
85
+ /** Issues that couldn't be fixed automatically */
86
+ remaining?: string[];
87
+ }
88
+ /**
89
+ * Generation options
90
+ */
91
+ interface GenerateOptions {
92
+ /** Style hint: modern, classic, minimal, realistic */
93
+ style?: 'modern' | 'classic' | 'minimal' | 'realistic';
94
+ /** Complexity level */
95
+ complexity?: 'low' | 'medium' | 'high';
96
+ /** Include physics simulation */
97
+ includePhysics?: boolean;
98
+ /** Target platform for optimization */
99
+ targetPlatform?: 'mobile' | 'desktop' | 'vr' | 'ar';
100
+ /** Maximum tokens/length */
101
+ maxTokens?: number;
102
+ /** Temperature for generation (0-1) */
103
+ temperature?: number;
104
+ /** Additional context about the world */
105
+ context?: string;
106
+ }
107
+ /**
108
+ * AI Adapter Interface
109
+ *
110
+ * Implement this interface to integrate any AI provider with HoloScript.
111
+ * All methods are optional - implement only what your provider supports.
112
+ */
113
+ interface AIAdapter {
114
+ /** Unique identifier for this adapter */
115
+ readonly id: string;
116
+ /** Human-readable name */
117
+ readonly name: string;
118
+ /** Whether the adapter is ready to use */
119
+ isReady(): boolean | Promise<boolean>;
120
+ /**
121
+ * Generate HoloScript from natural language
122
+ * @param prompt User's natural language description
123
+ * @param options Generation options
124
+ */
125
+ generateHoloScript?(prompt: string, options?: GenerateOptions): Promise<GenerateResult>;
126
+ /**
127
+ * Explain what HoloScript code does
128
+ * @param holoScript The code to explain
129
+ */
130
+ explainHoloScript?(holoScript: string): Promise<ExplainResult>;
131
+ /**
132
+ * Optimize HoloScript for a target platform
133
+ * @param holoScript The code to optimize
134
+ * @param target Target platform
135
+ */
136
+ optimizeHoloScript?(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
137
+ /**
138
+ * Fix errors in HoloScript code
139
+ * @param holoScript The code to fix
140
+ * @param errors Error messages from parser/validator
141
+ */
142
+ fixHoloScript?(holoScript: string, errors: string[]): Promise<FixResult>;
143
+ /**
144
+ * Complete HoloScript code (autocomplete)
145
+ * @param holoScript Partial code
146
+ * @param cursorPosition Position of cursor
147
+ */
148
+ completeHoloScript?(holoScript: string, cursorPosition: number): Promise<string[]>;
149
+ /**
150
+ * Chat with AI about HoloScript code
151
+ * @param message User message
152
+ * @param holoScript Current code context
153
+ * @param history Previous messages
154
+ */
155
+ chat?(message: string, holoScript?: string, history?: Array<{
156
+ role: 'user' | 'assistant';
157
+ content: string;
158
+ }>): Promise<string>;
159
+ /**
160
+ * Get vector embeddings for text
161
+ * @param text Text to embed
162
+ */
163
+ getEmbeddings?(text: string | string[]): Promise<number[][]>;
164
+ }
165
+ /**
166
+ * Register an AI adapter
167
+ * @param adapter The adapter to register
168
+ * @param setAsDefault Whether to set as the default adapter
169
+ */
170
+ declare function registerAIAdapter(adapter: AIAdapter, setAsDefault?: boolean): void;
171
+ /**
172
+ * Get an AI adapter by ID
173
+ * @param id Adapter ID
174
+ */
175
+ declare function getAIAdapter(id: string): AIAdapter | undefined;
176
+ /**
177
+ * Get the default AI adapter
178
+ */
179
+ declare function getDefaultAIAdapter(): AIAdapter | null;
180
+ /**
181
+ * Set the default AI adapter
182
+ * @param id Adapter ID
183
+ */
184
+ declare function setDefaultAIAdapter(id: string): boolean;
185
+ /**
186
+ * List all registered adapters
187
+ */
188
+ declare function listAIAdapters(): Array<{
189
+ id: string;
190
+ name: string;
191
+ }>;
192
+ /**
193
+ * Unregister an AI adapter
194
+ * @param id Adapter ID
195
+ */
196
+ declare function unregisterAIAdapter(id: string): boolean;
197
+ /**
198
+ * Generate HoloScript from natural language using the default adapter
199
+ */
200
+ declare function generateHoloScript$1(prompt: string, options?: GenerateOptions): Promise<GenerateResult>;
201
+ /**
202
+ * Explain HoloScript code using the default adapter
203
+ */
204
+ declare function explainHoloScript(holoScript: string): Promise<ExplainResult>;
205
+ /**
206
+ * Optimize HoloScript using the default adapter
207
+ */
208
+ declare function optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
209
+ /**
210
+ * Fix HoloScript errors using the default adapter
211
+ */
212
+ declare function fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
213
+
214
+ /**
215
+ * @holoscript/core - Built-in AI Adapters
216
+ *
217
+ * Ready-to-use adapters for popular AI providers.
218
+ * Users just need to provide their API key.
219
+ */
220
+
221
+ interface OpenAIAdapterConfig {
222
+ apiKey: string;
223
+ model?: string;
224
+ baseUrl?: string;
225
+ organization?: string;
226
+ }
227
+ declare class OpenAIAdapter implements AIAdapter {
228
+ readonly id = "openai";
229
+ readonly name = "OpenAI";
230
+ private config;
231
+ private model;
232
+ constructor(config: OpenAIAdapterConfig);
233
+ isReady(): boolean;
234
+ generateHoloScript(prompt: string, options?: GenerateOptions): Promise<GenerateResult>;
235
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
236
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
237
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
238
+ chat(message: string, holoScript?: string, history?: Array<{
239
+ role: 'user' | 'assistant';
240
+ content: string;
241
+ }>): Promise<string>;
242
+ private buildSystemPrompt;
243
+ private extractCode;
244
+ private callAPI;
245
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
246
+ }
247
+ interface AnthropicAdapterConfig {
248
+ apiKey: string;
249
+ model?: string;
250
+ }
251
+ declare class AnthropicAdapter implements AIAdapter {
252
+ readonly id = "anthropic";
253
+ readonly name = "Anthropic Claude";
254
+ private config;
255
+ private model;
256
+ constructor(config: AnthropicAdapterConfig);
257
+ isReady(): boolean;
258
+ generateHoloScript(prompt: string, options?: GenerateOptions): Promise<GenerateResult>;
259
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
260
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
261
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
262
+ chat(message: string, holoScript?: string, history?: Array<{
263
+ role: 'user' | 'assistant';
264
+ content: string;
265
+ }>): Promise<string>;
266
+ private extractCode;
267
+ private callAPI;
268
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
269
+ }
270
+ interface OllamaAdapterConfig {
271
+ baseUrl?: string;
272
+ model?: string;
273
+ }
274
+ declare class OllamaAdapter implements AIAdapter {
275
+ readonly id = "ollama";
276
+ readonly name = "Ollama (Local)";
277
+ private baseUrl;
278
+ private model;
279
+ constructor(config?: OllamaAdapterConfig);
280
+ isReady(): Promise<boolean>;
281
+ generateHoloScript(prompt: string, _options?: GenerateOptions): Promise<GenerateResult>;
282
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
283
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
284
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
285
+ chat(message: string, holoScript?: string, history?: Array<{
286
+ role: 'user' | 'assistant';
287
+ content: string;
288
+ }>): Promise<string>;
289
+ private callAPIWithErrorHandling;
290
+ private extractCode;
291
+ private callAPI;
292
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
293
+ }
294
+ interface LMStudioAdapterConfig {
295
+ baseUrl?: string;
296
+ model?: string;
297
+ }
298
+ /**
299
+ * LM Studio adapter - uses OpenAI-compatible API running locally
300
+ */
301
+ declare class LMStudioAdapter implements AIAdapter {
302
+ readonly id = "lmstudio";
303
+ readonly name = "LM Studio (Local)";
304
+ private openaiAdapter;
305
+ constructor(config?: LMStudioAdapterConfig);
306
+ isReady(): boolean;
307
+ generateHoloScript(prompt: string, options?: GenerateOptions): Promise<GenerateResult>;
308
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
309
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
310
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
311
+ chat(message: string, holoScript?: string, history?: Array<{
312
+ role: 'user' | 'assistant';
313
+ content: string;
314
+ }>): Promise<string>;
315
+ }
316
+ /**
317
+ * Create and register an OpenAI adapter
318
+ */
319
+ declare function useOpenAI(config: OpenAIAdapterConfig): OpenAIAdapter;
320
+ /**
321
+ * Create and register an Anthropic adapter
322
+ */
323
+ declare function useAnthropic(config: AnthropicAdapterConfig): AnthropicAdapter;
324
+ /**
325
+ * Create and register an Ollama adapter (local)
326
+ */
327
+ declare function useOllama(config?: OllamaAdapterConfig): OllamaAdapter;
328
+ /**
329
+ * Create and register an LM Studio adapter (local)
330
+ */
331
+ declare function useLMStudio(config?: LMStudioAdapterConfig): LMStudioAdapter;
332
+ interface GeminiAdapterConfig {
333
+ apiKey: string;
334
+ model?: string;
335
+ /** Embedding model (default: text-embedding-004) */
336
+ embeddingModel?: string;
337
+ }
338
+ declare class GeminiAdapter implements AIAdapter {
339
+ readonly id = "gemini";
340
+ readonly name = "Google Gemini";
341
+ private config;
342
+ private model;
343
+ private embeddingModel;
344
+ constructor(config: GeminiAdapterConfig);
345
+ isReady(): boolean;
346
+ generateHoloScript(prompt: string, options?: GenerateOptions): Promise<GenerateResult>;
347
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
348
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
349
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
350
+ chat(message: string, holoScript?: string, history?: Array<{
351
+ role: 'user' | 'assistant';
352
+ content: string;
353
+ }>): Promise<string>;
354
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
355
+ private extractCode;
356
+ private callAPI;
357
+ }
358
+ interface XAIAdapterConfig {
359
+ apiKey: string;
360
+ model?: string;
361
+ }
362
+ declare class XAIAdapter implements AIAdapter {
363
+ readonly id = "xai";
364
+ readonly name = "xAI Grok";
365
+ private config;
366
+ private model;
367
+ constructor(config: XAIAdapterConfig);
368
+ isReady(): boolean;
369
+ generateHoloScript(prompt: string, _options?: GenerateOptions): Promise<GenerateResult>;
370
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
371
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
372
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
373
+ chat(message: string, holoScript?: string, history?: Array<{
374
+ role: 'user' | 'assistant';
375
+ content: string;
376
+ }>): Promise<string>;
377
+ private extractCode;
378
+ private callAPI;
379
+ }
380
+ interface TogetherAdapterConfig {
381
+ apiKey: string;
382
+ model?: string;
383
+ }
384
+ declare class TogetherAdapter implements AIAdapter {
385
+ readonly id = "together";
386
+ readonly name = "Together AI";
387
+ private config;
388
+ private model;
389
+ constructor(config: TogetherAdapterConfig);
390
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
391
+ isReady(): boolean;
392
+ generateHoloScript(prompt: string, _options?: GenerateOptions): Promise<GenerateResult>;
393
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
394
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
395
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
396
+ chat(message: string, holoScript?: string, history?: Array<{
397
+ role: 'user' | 'assistant';
398
+ content: string;
399
+ }>): Promise<string>;
400
+ private extractCode;
401
+ private callAPI;
402
+ }
403
+ interface FireworksAdapterConfig {
404
+ apiKey: string;
405
+ model?: string;
406
+ }
407
+ declare class FireworksAdapter implements AIAdapter {
408
+ readonly id = "fireworks";
409
+ readonly name = "Fireworks AI";
410
+ private config;
411
+ private model;
412
+ constructor(config: FireworksAdapterConfig);
413
+ isReady(): boolean;
414
+ generateHoloScript(prompt: string, _options?: GenerateOptions): Promise<GenerateResult>;
415
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
416
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
417
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
418
+ chat(message: string, holoScript?: string, history?: Array<{
419
+ role: 'user' | 'assistant';
420
+ content: string;
421
+ }>): Promise<string>;
422
+ private extractCode;
423
+ private callAPI;
424
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
425
+ }
426
+ interface NVIDIAAdapterConfig {
427
+ apiKey: string;
428
+ model?: string;
429
+ baseUrl?: string;
430
+ }
431
+ declare class NVIDIAAdapter implements AIAdapter {
432
+ readonly id = "nvidia";
433
+ readonly name = "NVIDIA NIM";
434
+ private config;
435
+ private model;
436
+ private baseUrl;
437
+ constructor(config: NVIDIAAdapterConfig);
438
+ isReady(): boolean;
439
+ generateHoloScript(prompt: string, _options?: GenerateOptions): Promise<GenerateResult>;
440
+ explainHoloScript(holoScript: string): Promise<ExplainResult>;
441
+ optimizeHoloScript(holoScript: string, target: 'mobile' | 'desktop' | 'vr' | 'ar'): Promise<OptimizeResult>;
442
+ fixHoloScript(holoScript: string, errors: string[]): Promise<FixResult>;
443
+ chat(message: string, holoScript?: string, history?: Array<{
444
+ role: 'user' | 'assistant';
445
+ content: string;
446
+ }>): Promise<string>;
447
+ private extractCode;
448
+ private callAPI;
449
+ getEmbeddings(text: string | string[]): Promise<number[][]>;
450
+ }
451
+ /**
452
+ * Create and register a Gemini adapter
453
+ */
454
+ declare function useGemini(config: GeminiAdapterConfig): GeminiAdapter;
455
+ /**
456
+ * Create and register an xAI (Grok) adapter
457
+ */
458
+ declare function useXAI(config: XAIAdapterConfig): XAIAdapter;
459
+ /** Alias for useXAI */
460
+ declare const useGrok: typeof useXAI;
461
+ /**
462
+ * Create and register a Together AI adapter
463
+ */
464
+ declare function useTogether(config: TogetherAdapterConfig): TogetherAdapter;
465
+ /**
466
+ * Create and register a Fireworks AI adapter
467
+ */
468
+ declare function useFireworks(config: FireworksAdapterConfig): FireworksAdapter;
469
+ /**
470
+ * Create and register an NVIDIA NIM adapter
471
+ */
472
+ declare function useNVIDIA(config: NVIDIAAdapterConfig): NVIDIAAdapter;
473
+
474
+ /**
475
+ * SemanticSearchService
476
+ *
477
+ * Provides vector-based search for HoloScript traits.
478
+ */
479
+
480
+ interface SearchResult<T> {
481
+ item: T;
482
+ score: number;
483
+ }
484
+ declare class SemanticSearchService<T extends {
485
+ name: string;
486
+ description: string;
487
+ }> {
488
+ private adapter;
489
+ private items;
490
+ private embeddings;
491
+ constructor(adapter: AIAdapter, items: T[]);
492
+ /**
493
+ * Pre-calculate embeddings for all items
494
+ */
495
+ initialize(): Promise<void>;
496
+ /**
497
+ * Search for items similar to the query
498
+ */
499
+ search(query: string, limit?: number): Promise<SearchResult<T>[]>;
500
+ /**
501
+ * Calculate cosine similarity between two vectors
502
+ */
503
+ private cosineSimilarity;
504
+ }
505
+
506
+ /**
507
+ * BTNodes.ts
508
+ *
509
+ * Behavior tree node types: composite (sequence, selector, parallel),
510
+ * decorator (inverter, repeater, guard), leaf (action, condition, wait).
511
+ *
512
+ * @module ai
513
+ */
514
+ type BTStatus = 'success' | 'failure' | 'running' | 'ready';
515
+ interface BTContext$1 {
516
+ blackboard: {
517
+ get: (key: string) => unknown;
518
+ set: (key: string, value: unknown) => void;
519
+ };
520
+ deltaTime: number;
521
+ entity: string;
522
+ }
523
+ declare abstract class BTNode {
524
+ name: string;
525
+ status: BTStatus;
526
+ children: BTNode[];
527
+ constructor(name: string);
528
+ abstract tick(ctx: BTContext$1): BTStatus;
529
+ reset(): void;
530
+ }
531
+ declare class SequenceNode extends BTNode {
532
+ private currentIndex;
533
+ constructor(name: string, children: BTNode[]);
534
+ tick(ctx: BTContext$1): BTStatus;
535
+ reset(): void;
536
+ }
537
+ declare class SelectorNode extends BTNode {
538
+ private currentIndex;
539
+ constructor(name: string, children: BTNode[]);
540
+ tick(ctx: BTContext$1): BTStatus;
541
+ reset(): void;
542
+ }
543
+ declare class ParallelNode extends BTNode {
544
+ private requiredSuccesses;
545
+ constructor(name: string, children: BTNode[], requiredSuccesses?: number);
546
+ tick(ctx: BTContext$1): BTStatus;
547
+ }
548
+ declare class InverterNode extends BTNode {
549
+ constructor(name: string, child: BTNode);
550
+ tick(ctx: BTContext$1): BTStatus;
551
+ }
552
+ declare class RepeaterNode extends BTNode {
553
+ private maxRepeats;
554
+ private count;
555
+ constructor(name: string, child: BTNode, repeats?: number);
556
+ tick(ctx: BTContext$1): BTStatus;
557
+ reset(): void;
558
+ }
559
+ declare class GuardNode extends BTNode {
560
+ private condition;
561
+ constructor(name: string, condition: (ctx: BTContext$1) => boolean, child: BTNode);
562
+ tick(ctx: BTContext$1): BTStatus;
563
+ }
564
+ declare class ActionNode extends BTNode {
565
+ private action;
566
+ constructor(name: string, action: (ctx: BTContext$1) => BTStatus);
567
+ tick(ctx: BTContext$1): BTStatus;
568
+ }
569
+ declare class ConditionNode extends BTNode {
570
+ private condition;
571
+ constructor(name: string, condition: (ctx: BTContext$1) => boolean);
572
+ tick(ctx: BTContext$1): BTStatus;
573
+ }
574
+ declare class WaitNode extends BTNode {
575
+ private duration;
576
+ private elapsed;
577
+ constructor(name: string, seconds: number);
578
+ tick(ctx: BTContext$1): BTStatus;
579
+ reset(): void;
580
+ }
581
+
582
+ declare class Blackboard {
583
+ private data;
584
+ private observers;
585
+ private scopes;
586
+ private history;
587
+ private maxHistory;
588
+ set(key: string, value: unknown, scope?: string): void;
589
+ get<T = unknown>(key: string): T | undefined;
590
+ has(key: string): boolean;
591
+ delete(key: string): boolean;
592
+ getByScope(scope: string): Map<string, unknown>;
593
+ clearScope(scope: string): number;
594
+ getScopes(): string[];
595
+ observe(key: string, callback: (key: string, value: unknown, old: unknown) => void): void;
596
+ observeAll(callback: (key: string, value: unknown, old: unknown) => void): void;
597
+ private notifyObservers;
598
+ getEntryCount(): number;
599
+ getKeys(): string[];
600
+ getVersion(key: string): number;
601
+ getHistory(): typeof this.history;
602
+ clear(): void;
603
+ toJSON(): Record<string, unknown>;
604
+ fromJSON(data: Record<string, unknown>, scope?: string): void;
605
+ }
606
+
607
+ /**
608
+ * BehaviorTree.ts
609
+ *
610
+ * Behavior tree runner: tick-based evaluation, status propagation,
611
+ * subtree mounting, conditional abort, and debug tracing.
612
+ *
613
+ * @module ai
614
+ */
615
+
616
+ interface BTContext {
617
+ blackboard: Blackboard;
618
+ deltaTime: number;
619
+ entity: string;
620
+ }
621
+ interface BTTreeDef {
622
+ id: string;
623
+ root: BTNode;
624
+ context: BTContext;
625
+ status: BTStatus;
626
+ tickCount: number;
627
+ aborted: boolean;
628
+ }
629
+ declare class BehaviorTree {
630
+ private trees;
631
+ private subtrees;
632
+ private debugTrace;
633
+ private tracing;
634
+ createTree(id: string, root: BTNode, entity: string, blackboard?: Blackboard): BTTreeDef;
635
+ removeTree(id: string): boolean;
636
+ getTree(id: string): BTTreeDef | undefined;
637
+ registerSubtree(name: string, root: BTNode): void;
638
+ getSubtree(name: string): BTNode | undefined;
639
+ tick(id: string, dt: number): BTStatus;
640
+ tickAll(dt: number): void;
641
+ private tickNode;
642
+ abort(id: string): void;
643
+ enableTracing(): void;
644
+ disableTracing(): void;
645
+ getTrace(): typeof this.debugTrace;
646
+ clearTrace(): void;
647
+ getTreeCount(): number;
648
+ getStatus(id: string): BTStatus;
649
+ }
650
+
651
+ /**
652
+ * StateMachine.ts
653
+ *
654
+ * Hierarchical state machine: states with enter/exit/update hooks,
655
+ * transitions with guards, sub-state machines, and event dispatch.
656
+ *
657
+ * @module ai
658
+ */
659
+ type StateAction = (context: Record<string, unknown>) => void;
660
+ type GuardFn = (context: Record<string, unknown>) => boolean;
661
+ interface StateConfig {
662
+ id: string;
663
+ onEnter?: StateAction;
664
+ onExit?: StateAction;
665
+ onUpdate?: StateAction;
666
+ parent?: string;
667
+ }
668
+ interface TransitionConfig {
669
+ from: string;
670
+ to: string;
671
+ event: string;
672
+ guard?: GuardFn;
673
+ action?: StateAction;
674
+ }
675
+ declare class StateMachine {
676
+ private states;
677
+ private transitions;
678
+ private currentStateId;
679
+ private context;
680
+ private history;
681
+ private maxHistory;
682
+ addState(config: StateConfig): void;
683
+ removeState(id: string): void;
684
+ setInitialState(id: string): void;
685
+ getCurrentState(): string | null;
686
+ addTransition(config: TransitionConfig): void;
687
+ send(event: string): boolean;
688
+ private getTransitionsFor;
689
+ private getStateChain;
690
+ update(): void;
691
+ setContext(key: string, value: unknown): void;
692
+ getContext(key: string): unknown;
693
+ getStateCount(): number;
694
+ getHistory(): string[];
695
+ isInState(id: string): boolean;
696
+ getChildStates(parentId: string): string[];
697
+ }
698
+
699
+ /**
700
+ * SteeringBehavior — Seek/flee/arrive/wander/avoid with weighted blending
701
+ *
702
+ * @version 1.0.0
703
+ */
704
+ interface Vec2 {
705
+ x: number;
706
+ z: number;
707
+ }
708
+ type SteeringType = 'seek' | 'flee' | 'arrive' | 'wander' | 'avoid' | 'pursue' | 'evade';
709
+ interface SteeringAgent$1 {
710
+ position: Vec2;
711
+ velocity: Vec2;
712
+ maxSpeed: number;
713
+ maxForce: number;
714
+ mass: number;
715
+ }
716
+ interface SteeringOutput {
717
+ force: Vec2;
718
+ type: SteeringType;
719
+ weight: number;
720
+ }
721
+ declare class SteeringBehavior {
722
+ /**
723
+ * Seek — steer toward a target
724
+ */
725
+ static seek(agent: SteeringAgent$1, target: Vec2): Vec2;
726
+ /**
727
+ * Flee — steer away from a target
728
+ */
729
+ static flee(agent: SteeringAgent$1, target: Vec2): Vec2;
730
+ /**
731
+ * Arrive — seek with deceleration near target
732
+ */
733
+ static arrive(agent: SteeringAgent$1, target: Vec2, slowRadius?: number): Vec2;
734
+ /**
735
+ * Wander — random jitter-based steering
736
+ */
737
+ static wander(agent: SteeringAgent$1, wanderRadius?: number, wanderDistance?: number, jitter?: number): Vec2;
738
+ /**
739
+ * Obstacle avoidance
740
+ */
741
+ static avoid(agent: SteeringAgent$1, obstacles: {
742
+ position: Vec2;
743
+ radius: number;
744
+ }[], lookAhead?: number): Vec2;
745
+ /**
746
+ * Blend multiple steering outputs by weight
747
+ */
748
+ static blend(outputs: SteeringOutput[], maxForce: number): Vec2;
749
+ }
750
+
751
+ /**
752
+ * SteeringBehaviors.ts
753
+ *
754
+ * Autonomous agent steering: seek, flee, arrive, wander,
755
+ * flock (separation/alignment/cohesion), and obstacle avoidance.
756
+ *
757
+ * @module ai
758
+ */
759
+ interface SteeringAgent {
760
+ position: {
761
+ x: number;
762
+ y: number;
763
+ z: number;
764
+ };
765
+ velocity: {
766
+ x: number;
767
+ y: number;
768
+ z: number;
769
+ };
770
+ maxSpeed: number;
771
+ maxForce: number;
772
+ mass: number;
773
+ }
774
+ interface FlockConfig {
775
+ separationWeight: number;
776
+ alignmentWeight: number;
777
+ cohesionWeight: number;
778
+ neighborRadius: number;
779
+ }
780
+ interface ObstacleCircle {
781
+ center: {
782
+ x: number;
783
+ y: number;
784
+ z: number;
785
+ };
786
+ radius: number;
787
+ }
788
+ type Vec3 = {
789
+ x: number;
790
+ y: number;
791
+ z: number;
792
+ };
793
+ declare class SteeringBehaviors {
794
+ static seek(agent: SteeringAgent, target: Vec3): Vec3;
795
+ static flee(agent: SteeringAgent, threat: Vec3): Vec3;
796
+ static arrive(agent: SteeringAgent, target: Vec3, slowRadius: number): Vec3;
797
+ static wander(agent: SteeringAgent, circleDistance: number, circleRadius: number, angleJitter: number, currentAngle: number): {
798
+ force: Vec3;
799
+ newAngle: number;
800
+ };
801
+ static flock(agent: SteeringAgent, neighbors: SteeringAgent[], config: FlockConfig): Vec3;
802
+ private static separation;
803
+ private static alignment;
804
+ private static cohesion;
805
+ static obstacleAvoidance(agent: SteeringAgent, obstacles: ObstacleCircle[], lookAhead: number): Vec3;
806
+ static applyForce(agent: SteeringAgent, force: Vec3, dt: number): void;
807
+ private static sub;
808
+ private static add;
809
+ private static scale;
810
+ private static vecLength;
811
+ private static distance;
812
+ private static normalize;
813
+ private static truncate;
814
+ }
815
+
816
+ /**
817
+ * NavMesh — Navigation mesh with polygon walk and path smoothing
818
+ *
819
+ * @version 1.0.0
820
+ */
821
+ interface NavPolygon {
822
+ id: number;
823
+ vertices: {
824
+ x: number;
825
+ z: number;
826
+ }[];
827
+ neighbors: number[];
828
+ center: {
829
+ x: number;
830
+ z: number;
831
+ };
832
+ walkable: boolean;
833
+ cost: number;
834
+ }
835
+ interface NavPath {
836
+ waypoints: {
837
+ x: number;
838
+ z: number;
839
+ }[];
840
+ totalCost: number;
841
+ polygonIds: number[];
842
+ }
843
+ declare class NavMesh {
844
+ private polygons;
845
+ private nextId;
846
+ /**
847
+ * Add a navigation polygon
848
+ */
849
+ addPolygon(vertices: {
850
+ x: number;
851
+ z: number;
852
+ }[], walkable?: boolean, cost?: number): number;
853
+ /**
854
+ * Connect two polygons as neighbors
855
+ */
856
+ connect(a: number, b: number): boolean;
857
+ /**
858
+ * Find path using A*
859
+ */
860
+ findPath(startPoly: number, endPoly: number): NavPath | null;
861
+ /**
862
+ * Smooth a path using string-pulling (funnel algorithm simplified)
863
+ */
864
+ smoothPath(path: NavPath): NavPath;
865
+ private reconstructPath;
866
+ private heuristic;
867
+ getPolygon(id: number): NavPolygon | undefined;
868
+ getPolygonCount(): number;
869
+ setWalkable(id: number, walkable: boolean): void;
870
+ }
871
+
872
+ /**
873
+ * PerceptionSystem.ts
874
+ *
875
+ * AI perception: sight/hearing/smell sense cones, stimulus memory,
876
+ * priority scoring, and detection events.
877
+ *
878
+ * @module ai
879
+ */
880
+ type SenseType = 'sight' | 'hearing' | 'smell';
881
+ interface Stimulus {
882
+ id: string;
883
+ type: SenseType;
884
+ sourceId: string;
885
+ position: {
886
+ x: number;
887
+ y: number;
888
+ z: number;
889
+ };
890
+ intensity: number;
891
+ timestamp: number;
892
+ data?: unknown;
893
+ }
894
+ interface SenseConfig {
895
+ type: SenseType;
896
+ range: number;
897
+ fov: number;
898
+ sensitivity: number;
899
+ }
900
+ interface PerceivedStimulus extends Stimulus {
901
+ awareness: number;
902
+ lastSeen: number;
903
+ }
904
+ declare class PerceptionSystem {
905
+ private entities;
906
+ private stimuli;
907
+ registerEntity(id: string, senses: SenseConfig[], memoryDuration?: number): void;
908
+ setEntityTransform(entityId: string, position: {
909
+ x: number;
910
+ y: number;
911
+ z: number;
912
+ }, facing: {
913
+ x: number;
914
+ y: number;
915
+ z: number;
916
+ }): void;
917
+ addStimulus(stimulus: Stimulus): void;
918
+ removeStimulus(id: string): void;
919
+ update(time: number): void;
920
+ getPerceivedStimuli(entityId: string): PerceivedStimulus[];
921
+ getHighestPriority(entityId: string): PerceivedStimulus | null;
922
+ isAwareOf(entityId: string, stimulusId: string): boolean;
923
+ getStimulusCount(): number;
924
+ }
925
+
926
+ /**
927
+ * InfluenceMap.ts
928
+ *
929
+ * Grid-based influence map: propagation, decay, multi-layer
930
+ * support, and spatial queries.
931
+ *
932
+ * @module ai
933
+ */
934
+ interface InfluenceConfig {
935
+ width: number;
936
+ height: number;
937
+ cellSize: number;
938
+ decayRate: number;
939
+ propagationRate: number;
940
+ maxValue: number;
941
+ }
942
+ declare class InfluenceMap {
943
+ private layers;
944
+ private config;
945
+ constructor(config: InfluenceConfig);
946
+ addLayer(name: string): void;
947
+ removeLayer(name: string): void;
948
+ getLayerNames(): string[];
949
+ setInfluence(layer: string, gx: number, gy: number, value: number): void;
950
+ addInfluence(layer: string, gx: number, gy: number, value: number): void;
951
+ stampRadius(layer: string, cx: number, cy: number, radius: number, value: number): void;
952
+ update(): void;
953
+ getInfluence(layer: string, gx: number, gy: number): number;
954
+ getInfluenceAtWorld(layer: string, wx: number, wy: number): number;
955
+ getMaxCell(layer: string): {
956
+ x: number;
957
+ y: number;
958
+ value: number;
959
+ };
960
+ clear(layer: string): void;
961
+ clearAll(): void;
962
+ }
963
+
964
+ /**
965
+ * UtilityAI.ts
966
+ *
967
+ * Utility-based AI: action scoring with consideration curves,
968
+ * weighted selection, cooldowns, and action history.
969
+ *
970
+ * @module ai
971
+ */
972
+ type CurveType = 'linear' | 'quadratic' | 'logistic' | 'step';
973
+ interface Consideration {
974
+ name: string;
975
+ input: () => number;
976
+ curve: CurveType;
977
+ weight: number;
978
+ invert: boolean;
979
+ }
980
+ interface UtilityAction {
981
+ id: string;
982
+ name: string;
983
+ considerations: Consideration[];
984
+ cooldown: number;
985
+ lastExecuted: number;
986
+ bonus: number;
987
+ execute: () => void;
988
+ }
989
+ declare class UtilityAI {
990
+ private actions;
991
+ private history;
992
+ private maxHistory;
993
+ private currentTime;
994
+ addAction(action: UtilityAction): void;
995
+ removeAction(id: string): void;
996
+ scoreAction(action: UtilityAction): number;
997
+ scoreAll(): Array<{
998
+ actionId: string;
999
+ score: number;
1000
+ }>;
1001
+ selectBest(): UtilityAction | null;
1002
+ executeBest(): string | null;
1003
+ setTime(time: number): void;
1004
+ getHistory(): {
1005
+ actionId: string;
1006
+ score: number;
1007
+ timestamp: number;
1008
+ }[];
1009
+ getActionCount(): number;
1010
+ }
1011
+
1012
+ /**
1013
+ * BehaviorSelector.ts
1014
+ *
1015
+ * Behavior selection: weighted random, priority-based, and
1016
+ * conditional behavior picking with fallbacks and lockout timers.
1017
+ *
1018
+ * @module ai
1019
+ */
1020
+ interface Behavior {
1021
+ id: string;
1022
+ name: string;
1023
+ weight: number;
1024
+ priority: number;
1025
+ condition?: () => boolean;
1026
+ action: () => void;
1027
+ lockoutMs: number;
1028
+ lastExecuted: number;
1029
+ }
1030
+ type SelectionMode = 'priority' | 'weighted' | 'sequential';
1031
+ declare class BehaviorSelector {
1032
+ private behaviors;
1033
+ private mode;
1034
+ private currentIndex;
1035
+ private currentTime;
1036
+ private fallback;
1037
+ private history;
1038
+ private maxHistory;
1039
+ constructor(mode?: SelectionMode);
1040
+ addBehavior(behavior: Behavior): void;
1041
+ removeBehavior(id: string): void;
1042
+ setFallback(behavior: Behavior): void;
1043
+ setMode(mode: SelectionMode): void;
1044
+ select(): Behavior | null;
1045
+ private getAvailable;
1046
+ private selectByPriority;
1047
+ private selectByWeight;
1048
+ private selectSequential;
1049
+ execute(): string | null;
1050
+ setTime(time: number): void;
1051
+ getBehaviorCount(): number;
1052
+ getHistory(): {
1053
+ behaviorId: string;
1054
+ timestamp: number;
1055
+ }[];
1056
+ }
1057
+
1058
+ /**
1059
+ * GoalPlanner.ts
1060
+ *
1061
+ * GOAP-style goal planner: goal states, actions with preconditions
1062
+ * and effects, backward chaining plan generation, and plan execution.
1063
+ *
1064
+ * @module ai
1065
+ */
1066
+ type WorldState = Map<string, boolean>;
1067
+ interface PlanAction {
1068
+ id: string;
1069
+ name: string;
1070
+ cost: number;
1071
+ preconditions: Map<string, boolean>;
1072
+ effects: Map<string, boolean>;
1073
+ execute: () => void;
1074
+ }
1075
+ interface Goal {
1076
+ id: string;
1077
+ name: string;
1078
+ conditions: Map<string, boolean>;
1079
+ priority: number;
1080
+ }
1081
+ interface Plan {
1082
+ actions: PlanAction[];
1083
+ totalCost: number;
1084
+ goalId: string;
1085
+ }
1086
+ declare class GoalPlanner {
1087
+ private actions;
1088
+ private goals;
1089
+ addAction(action: PlanAction): void;
1090
+ addGoal(goal: Goal): void;
1091
+ removeAction(id: string): void;
1092
+ removeGoal(id: string): void;
1093
+ plan(currentState: WorldState): Plan | null;
1094
+ private findPlan;
1095
+ private satisfiesGoal;
1096
+ private preconditionsMet;
1097
+ private stateKey;
1098
+ executePlan(plan: Plan): void;
1099
+ getActionCount(): number;
1100
+ getGoalCount(): number;
1101
+ }
1102
+
1103
+ /**
1104
+ * Generation Analytics & Metrics
1105
+ *
1106
+ * Tracks and analyzes generation metrics:
1107
+ * - Success rates by adapter
1108
+ * - Confidence score distributions
1109
+ * - Code quality metrics
1110
+ * - Performance metrics
1111
+ * - User patterns and trends
1112
+ */
1113
+ interface GenerationMetrics {
1114
+ promptLength: number;
1115
+ codeLength: number;
1116
+ confidence: number;
1117
+ parseSuccess: boolean;
1118
+ errorCount: number;
1119
+ wasFixed: boolean;
1120
+ responseTimeMs: number;
1121
+ attemptsNeeded: number;
1122
+ adapterName: string;
1123
+ timestamp: Date;
1124
+ platform?: string;
1125
+ }
1126
+ interface MetricsAggregate {
1127
+ totalGenerations: number;
1128
+ successRate: number;
1129
+ avgConfidence: number;
1130
+ avgResponseTime: number;
1131
+ avgErrorCount: number;
1132
+ avgAttemptsNeeded: number;
1133
+ mostCommonAdapter: string;
1134
+ mostCommonPlatform: string;
1135
+ }
1136
+ interface AdapterMetrics {
1137
+ name: string;
1138
+ generationCount: number;
1139
+ successRate: number;
1140
+ avgConfidence: number;
1141
+ avgResponseTime: number;
1142
+ bestFor: string[];
1143
+ reliabilityScore: number;
1144
+ }
1145
+ interface TimeSeriesMetrics {
1146
+ timestamp: Date;
1147
+ successRate: number;
1148
+ avgConfidence: number;
1149
+ avgResponseTime: number;
1150
+ generationCount: number;
1151
+ }
1152
+ declare class GenerationAnalytics {
1153
+ private metrics;
1154
+ private timeSeriesWindow;
1155
+ /**
1156
+ * Record a generation metric
1157
+ */
1158
+ recordMetric(metric: GenerationMetrics): void;
1159
+ /**
1160
+ * Get all metrics
1161
+ */
1162
+ getAllMetrics(): GenerationMetrics[];
1163
+ /**
1164
+ * Clear metrics
1165
+ */
1166
+ clearMetrics(): void;
1167
+ /**
1168
+ * Get aggregate metrics
1169
+ */
1170
+ getAggregateMetrics(): MetricsAggregate;
1171
+ /**
1172
+ * Get metrics by adapter
1173
+ */
1174
+ getMetricsByAdapter(adapterName: string): AdapterMetrics;
1175
+ /**
1176
+ * Get all adapter metrics
1177
+ */
1178
+ getAllAdapterMetrics(): AdapterMetrics[];
1179
+ /**
1180
+ * Get confidence distribution
1181
+ */
1182
+ getConfidenceDistribution(): {
1183
+ range: string;
1184
+ count: number;
1185
+ percentage: number;
1186
+ }[];
1187
+ /**
1188
+ * Get error patterns
1189
+ */
1190
+ getErrorPatterns(): {
1191
+ errorType: string;
1192
+ frequency: number;
1193
+ percentage: number;
1194
+ }[];
1195
+ /**
1196
+ * Get response time distribution
1197
+ */
1198
+ getResponseTimeDistribution(): {
1199
+ range: string;
1200
+ count: number;
1201
+ percentage: number;
1202
+ }[];
1203
+ /**
1204
+ * Get time series metrics for a window
1205
+ */
1206
+ getTimeSeries(windowMs?: number): TimeSeriesMetrics[];
1207
+ /**
1208
+ * Get recommendations based on metrics
1209
+ */
1210
+ getRecommendations(): string[];
1211
+ /**
1212
+ * Export metrics as JSON
1213
+ */
1214
+ exportMetrics(): string;
1215
+ /**
1216
+ * Create a detailed report
1217
+ */
1218
+ generateReport(): string;
1219
+ }
1220
+ /**
1221
+ * Quick analytics creation
1222
+ */
1223
+ declare function createAnalytics(): GenerationAnalytics;
1224
+
1225
+ /**
1226
+ * Generation Cache System
1227
+ *
1228
+ * Caches generated HoloScript code to avoid redundant API calls.
1229
+ * Implements LRU (Least Recently Used) eviction policy.
1230
+ *
1231
+ * Features:
1232
+ * - Prompt-based caching (hash of prompt + adapter)
1233
+ * - TTL (Time-To-Live) support
1234
+ * - Statistics tracking
1235
+ * - Serialization for persistence
1236
+ */
1237
+ interface CacheEntry {
1238
+ prompt: string;
1239
+ code: string;
1240
+ confidence: number;
1241
+ timestamp: number;
1242
+ ttl?: number;
1243
+ hits: number;
1244
+ adapterName: string;
1245
+ }
1246
+ interface CacheStats {
1247
+ totalHits: number;
1248
+ totalMisses: number;
1249
+ hitRate: number;
1250
+ entriesCount: number;
1251
+ maxSize: number;
1252
+ averageHitCount: number;
1253
+ }
1254
+ declare class GenerationCache {
1255
+ private cache;
1256
+ private maxSize;
1257
+ private ttlMs;
1258
+ private hits;
1259
+ private misses;
1260
+ constructor(options?: {
1261
+ maxSize?: number;
1262
+ ttlMs?: number;
1263
+ });
1264
+ /**
1265
+ * Generate cache key from prompt and adapter
1266
+ */
1267
+ private generateKey;
1268
+ /**
1269
+ * Get cached code if available and valid
1270
+ */
1271
+ get(prompt: string, adapterName: string): CacheEntry | null;
1272
+ /**
1273
+ * Store generated code in cache
1274
+ */
1275
+ set(prompt: string, code: string, confidence: number, adapterName: string): void;
1276
+ /**
1277
+ * Evict least recently used entry
1278
+ */
1279
+ private evictLRU;
1280
+ /**
1281
+ * Clear entire cache
1282
+ */
1283
+ clear(): void;
1284
+ /**
1285
+ * Get cache statistics
1286
+ */
1287
+ getStats(): CacheStats;
1288
+ /**
1289
+ * Export cache as JSON
1290
+ */
1291
+ serialize(): string;
1292
+ /**
1293
+ * Import cache from JSON
1294
+ */
1295
+ deserialize(json: string): void;
1296
+ /**
1297
+ * Get all cache entries
1298
+ */
1299
+ getEntries(): CacheEntry[];
1300
+ /**
1301
+ * Remove specific entry
1302
+ */
1303
+ remove(prompt: string, adapterName: string): boolean;
1304
+ /**
1305
+ * Get cache size in bytes (approximate)
1306
+ */
1307
+ getSize(): number;
1308
+ }
1309
+ interface CachedGenerationResult {
1310
+ code: string;
1311
+ confidence: number;
1312
+ fromCache: boolean;
1313
+ cacheAge?: number;
1314
+ }
1315
+ /**
1316
+ * Wrap generation with caching
1317
+ */
1318
+ declare function cachedGenerate(prompt: string, adapterName: string, cache: GenerationCache, generator: () => Promise<{
1319
+ holoScript: string;
1320
+ aiConfidence: number;
1321
+ }>): Promise<CachedGenerationResult>;
1322
+
1323
+ interface GenerationConfig {
1324
+ /** Maximum attempts to generate valid code */
1325
+ maxAttempts: number;
1326
+ /** Target platform for optimization */
1327
+ targetPlatform: 'mobile' | 'desktop' | 'vr' | 'ar';
1328
+ /** Auto-fix errors if generation is invalid */
1329
+ autoFix: boolean;
1330
+ /** Minimum confidence threshold (0-1) */
1331
+ minConfidence: number;
1332
+ }
1333
+ interface GeneratedCode {
1334
+ /** The generated HoloScript code */
1335
+ holoScript: string;
1336
+ /** Confidence score from AI (0-1) */
1337
+ aiConfidence: number;
1338
+ /** Parse result */
1339
+ parseResult: HSPlusCompileResult;
1340
+ /** Was auto-fixed */
1341
+ wasFixed: boolean;
1342
+ /** Number of attempts before success */
1343
+ attempts: number;
1344
+ /** Explanation of generated code */
1345
+ explanation?: string;
1346
+ }
1347
+ interface GenerationHistory {
1348
+ /** Prompt that was used */
1349
+ prompt: string;
1350
+ /** Generated code */
1351
+ generated: GeneratedCode;
1352
+ /** Timestamp */
1353
+ timestamp: Date;
1354
+ /** Attempt number in session */
1355
+ sessionAttempt: number;
1356
+ }
1357
+ interface GenerationSession {
1358
+ /** Unique session ID */
1359
+ sessionId: string;
1360
+ /** All generations in this session */
1361
+ history: GenerationHistory[];
1362
+ /** AI adapter used */
1363
+ adapter: AIAdapter;
1364
+ /** Configuration */
1365
+ config: GenerationConfig;
1366
+ }
1367
+ declare class HoloScriptGenerator {
1368
+ private parser;
1369
+ private currentSession?;
1370
+ private sessionCounter;
1371
+ private cache;
1372
+ private analytics;
1373
+ private cacheEnabled;
1374
+ constructor(enableCache?: boolean);
1375
+ /**
1376
+ * Create a new generation session
1377
+ */
1378
+ createSession(adapter: AIAdapter, config?: Partial<GenerationConfig>): GenerationSession;
1379
+ /**
1380
+ * Generate HoloScript from a natural language prompt
1381
+ */
1382
+ generate(prompt: string, session?: GenerationSession): Promise<GeneratedCode>;
1383
+ /**
1384
+ * Optimize generated code for a target platform
1385
+ */
1386
+ optimize(code: string, targetPlatform: 'mobile' | 'desktop' | 'vr' | 'ar', session?: GenerationSession): Promise<GeneratedCode>;
1387
+ /**
1388
+ * Fix invalid HoloScript code
1389
+ */
1390
+ fix(code: string, session?: GenerationSession): Promise<GeneratedCode>;
1391
+ /**
1392
+ * Explain generated code
1393
+ */
1394
+ explain(code: string, session?: GenerationSession): Promise<string>;
1395
+ /**
1396
+ * Multi-turn conversation for iterative code generation
1397
+ */
1398
+ chat(message: string, session?: GenerationSession, history?: Array<{
1399
+ role: 'user' | 'assistant';
1400
+ content: string;
1401
+ }>): Promise<string>;
1402
+ /**
1403
+ * Get current generation session
1404
+ */
1405
+ getCurrentSession(): GenerationSession | undefined;
1406
+ /**
1407
+ * Get generation history
1408
+ */
1409
+ getHistory(session?: GenerationSession): GenerationHistory[];
1410
+ /**
1411
+ * Clear history
1412
+ */
1413
+ clearHistory(session?: GenerationSession): void;
1414
+ /**
1415
+ * Get statistics for a session
1416
+ */
1417
+ getStats(session?: GenerationSession): {
1418
+ totalGenerations: number;
1419
+ successCount: number;
1420
+ fixedCount: number;
1421
+ avgAttempts: number;
1422
+ avgConfidence: number;
1423
+ successRate: number;
1424
+ } | null;
1425
+ /**
1426
+ * Get cache statistics
1427
+ */
1428
+ getCacheStats(): CacheStats;
1429
+ /**
1430
+ * Get analytics metrics
1431
+ */
1432
+ getAnalytics(): {
1433
+ aggregateMetrics: MetricsAggregate;
1434
+ adapterMetrics: AdapterMetrics[];
1435
+ confidenceDistribution: {
1436
+ range: string;
1437
+ count: number;
1438
+ percentage: number;
1439
+ }[];
1440
+ responseTimeDistribution: {
1441
+ range: string;
1442
+ count: number;
1443
+ percentage: number;
1444
+ }[];
1445
+ errorPatterns: {
1446
+ errorType: string;
1447
+ frequency: number;
1448
+ percentage: number;
1449
+ }[];
1450
+ recommendations: string[];
1451
+ };
1452
+ /**
1453
+ * Generate analytics report
1454
+ */
1455
+ generateReport(): string;
1456
+ }
1457
+ /**
1458
+ * Quick generation helper
1459
+ */
1460
+ declare function generateHoloScript(prompt: string, adapter: AIAdapter, config?: Partial<GenerationConfig>): Promise<GeneratedCode>;
1461
+ /**
1462
+ * Batch generation helper
1463
+ */
1464
+ declare function generateBatch(prompts: string[], adapter: AIAdapter, config?: Partial<GenerationConfig>): Promise<GeneratedCode[]>;
1465
+ /**
1466
+ * Validate batch of generated code
1467
+ */
1468
+ declare function validateBatch(codes: string[]): Array<{
1469
+ code: string;
1470
+ valid: boolean;
1471
+ errors: number;
1472
+ }>;
1473
+
1474
+ /**
1475
+ * HoloScript AI Training Data Generator
1476
+ *
1477
+ * Generates diverse HoloScript examples for AI model training.
1478
+ * Creates input/output pairs covering all language features.
1479
+ *
1480
+ * @version 1.0.0
1481
+ */
1482
+ interface TrainingExample {
1483
+ id: string;
1484
+ category: TrainingCategory;
1485
+ description: string;
1486
+ holoScript: string;
1487
+ expectedOutput?: {
1488
+ type: 'r3f' | 'visionos' | 'usda';
1489
+ snippet?: string;
1490
+ };
1491
+ tags: string[];
1492
+ complexity: 'basic' | 'intermediate' | 'advanced';
1493
+ }
1494
+ type TrainingCategory = 'geometry' | 'materials' | 'physics' | 'interactions' | 'audio' | 'ui' | 'composition' | 'state' | 'logic' | 'traits' | 'animations' | 'ar_vr' | 'accessibility';
1495
+ interface GeneratorOptions {
1496
+ count?: number;
1497
+ categories?: TrainingCategory[];
1498
+ complexityFilter?: ('basic' | 'intermediate' | 'advanced')[];
1499
+ includeExpectedOutput?: boolean;
1500
+ }
1501
+ declare class TrainingDataGenerator {
1502
+ private allExamples;
1503
+ constructor();
1504
+ /**
1505
+ * Generate training examples based on options
1506
+ */
1507
+ generate(options?: GeneratorOptions): TrainingExample[];
1508
+ /**
1509
+ * Generate all examples
1510
+ */
1511
+ generateAll(): TrainingExample[];
1512
+ /**
1513
+ * Get examples by category
1514
+ */
1515
+ getByCategory(category: TrainingCategory): TrainingExample[];
1516
+ /**
1517
+ * Get examples by complexity
1518
+ */
1519
+ getByComplexity(complexity: 'basic' | 'intermediate' | 'advanced'): TrainingExample[];
1520
+ /**
1521
+ * Get examples by tag
1522
+ */
1523
+ getByTag(tag: string): TrainingExample[];
1524
+ /**
1525
+ * Get category statistics
1526
+ */
1527
+ getStats(): Record<TrainingCategory, number>;
1528
+ /**
1529
+ * Export as JSON for training
1530
+ */
1531
+ exportJSON(): string;
1532
+ /**
1533
+ * Export as JSONL (one JSON per line)
1534
+ */
1535
+ exportJSONL(): string;
1536
+ private shuffleArray;
1537
+ }
1538
+ declare const ALL_CATEGORIES: TrainingCategory[];
1539
+ declare function createTrainingDataGenerator(): TrainingDataGenerator;
1540
+
1541
+ /**
1542
+ * Prompt Templates System
1543
+ *
1544
+ * Provides pre-built prompt templates for common HoloScript generation tasks.
1545
+ * Supports:
1546
+ * - Variable interpolation
1547
+ * - Context-aware suggestions
1548
+ * - Template composition
1549
+ * - Custom template creation
1550
+ */
1551
+ interface PromptTemplate {
1552
+ id: string;
1553
+ name: string;
1554
+ description: string;
1555
+ category: string;
1556
+ template: string;
1557
+ variables: string[];
1558
+ examples: string[];
1559
+ bestFor: string;
1560
+ }
1561
+ interface TemplateContext {
1562
+ [key: string]: string | number | boolean;
1563
+ }
1564
+ declare class PromptTemplateSystem {
1565
+ private customTemplates;
1566
+ /**
1567
+ * Get all available templates
1568
+ */
1569
+ getAvailableTemplates(): PromptTemplate[];
1570
+ /**
1571
+ * Get templates by category
1572
+ */
1573
+ getTemplatesByCategory(category: string): PromptTemplate[];
1574
+ /**
1575
+ * Get a specific template
1576
+ */
1577
+ getTemplate(id: string): PromptTemplate | null;
1578
+ /**
1579
+ * Create a prompt from template with context
1580
+ */
1581
+ createPrompt(templateId: string, context: TemplateContext): string;
1582
+ /**
1583
+ * Validate context against template
1584
+ */
1585
+ validateContext(templateId: string, context: TemplateContext): {
1586
+ valid: boolean;
1587
+ missing: string[];
1588
+ };
1589
+ /**
1590
+ * Register custom template
1591
+ */
1592
+ registerTemplate(template: PromptTemplate): void;
1593
+ /**
1594
+ * Get template suggestions for a category
1595
+ */
1596
+ suggestTemplates(category: string, query?: string): PromptTemplate[];
1597
+ /**
1598
+ * Get all categories
1599
+ */
1600
+ getCategories(): string[];
1601
+ /**
1602
+ * Create a batch of prompts from templates
1603
+ */
1604
+ createBatch(templates: Array<{
1605
+ templateId: string;
1606
+ context: TemplateContext;
1607
+ }>): string[];
1608
+ }
1609
+ /**
1610
+ * Quick prompt creation helpers
1611
+ */
1612
+ declare const QuickPrompts: {
1613
+ /**
1614
+ * Create prompt for a simple object
1615
+ */
1616
+ object(geometry: string, color: string, position: [number, number, number]): string;
1617
+ /**
1618
+ * Create prompt for an interactive object
1619
+ */
1620
+ interactive(color: string, geometry: string, interaction: string, purpose: string): string;
1621
+ /**
1622
+ * Create prompt for a physics object
1623
+ */
1624
+ physics(geometry: string, physics_type: string, mass: number, restitution: number): string;
1625
+ /**
1626
+ * Create prompt for a player controller
1627
+ */
1628
+ player(geometry: string, movement_type: string, health: number, abilities: string): string;
1629
+ /**
1630
+ * Create prompt for networked object
1631
+ */
1632
+ networked(object_type: string, synced_properties: string, sync_rate: number): string;
1633
+ };
1634
+
1635
+ /**
1636
+ * AICopilot.ts
1637
+ *
1638
+ * Editor-aware AI assistant that bridges the existing AIAdapter/HoloScriptGenerator
1639
+ * infrastructure with the runtime and editor for real-time AI assistance.
1640
+ *
1641
+ * @module ai
1642
+ */
1643
+
1644
+ interface CopilotContext {
1645
+ /** Currently selected entity type/id */
1646
+ selectedEntity?: {
1647
+ id: string;
1648
+ type: string;
1649
+ properties?: Record<string, unknown>;
1650
+ };
1651
+ /** Current scene node types */
1652
+ sceneNodeTypes?: string[];
1653
+ /** Active state keys */
1654
+ stateKeys?: string[];
1655
+ /** Recent user actions */
1656
+ recentActions?: string[];
1657
+ }
1658
+ interface CopilotSuggestion {
1659
+ type: 'modify' | 'create' | 'explain' | 'fix';
1660
+ description: string;
1661
+ holoScript?: string;
1662
+ confidence: number;
1663
+ }
1664
+ interface CopilotResponse {
1665
+ text: string;
1666
+ suggestions: CopilotSuggestion[];
1667
+ generatedCode?: GeneratedCode;
1668
+ error?: string;
1669
+ }
1670
+ interface CopilotMessage {
1671
+ role: 'user' | 'assistant';
1672
+ content: string;
1673
+ timestamp: number;
1674
+ }
1675
+ declare class AICopilot {
1676
+ private adapter;
1677
+ private generator;
1678
+ private history;
1679
+ private context;
1680
+ constructor(adapter?: AIAdapter);
1681
+ setAdapter(adapter: AIAdapter): void;
1682
+ getAdapter(): AIAdapter | null;
1683
+ isReady(): boolean;
1684
+ updateContext(context: Partial<CopilotContext>): void;
1685
+ getContext(): CopilotContext;
1686
+ /**
1687
+ * Generate HoloScript from a natural language prompt.
1688
+ * Uses the full HoloScriptGenerator pipeline (generate → validate → auto-fix).
1689
+ */
1690
+ generateFromPrompt(prompt: string, options?: Partial<GenerateOptions>): Promise<CopilotResponse>;
1691
+ /**
1692
+ * Suggest modifications for the currently selected entity.
1693
+ */
1694
+ suggestFromSelection(): Promise<CopilotResponse>;
1695
+ /**
1696
+ * Explain the current scene in natural language.
1697
+ */
1698
+ explainScene(sceneCode: string): Promise<CopilotResponse>;
1699
+ /**
1700
+ * Auto-fix runtime errors using the AI adapter.
1701
+ */
1702
+ autoFix(code: string, errors: string[]): Promise<CopilotResponse>;
1703
+ /**
1704
+ * Chat with the AI about HoloScript code (multi-turn conversation).
1705
+ */
1706
+ chat(message: string): Promise<CopilotResponse>;
1707
+ getHistory(): CopilotMessage[];
1708
+ clearHistory(): void;
1709
+ private addMessage;
1710
+ }
1711
+
1712
+ /**
1713
+ * AI Output Validator
1714
+ *
1715
+ * Validates AI-generated HoloScript code before execution.
1716
+ * Catches structural errors, dangerous patterns, and excessive complexity.
1717
+ *
1718
+ * @module ai
1719
+ */
1720
+ interface ValidationIssue {
1721
+ severity: 'error' | 'warning' | 'info';
1722
+ message: string;
1723
+ line?: number;
1724
+ rule: string;
1725
+ }
1726
+ interface ValidationResult {
1727
+ valid: boolean;
1728
+ issues: ValidationIssue[];
1729
+ confidence: number;
1730
+ stats: {
1731
+ lineCount: number;
1732
+ traitCount: number;
1733
+ dangerousPatternCount: number;
1734
+ maxNesting: number;
1735
+ };
1736
+ }
1737
+ interface ValidatorConfig {
1738
+ maxLines: number;
1739
+ maxNesting: number;
1740
+ maxTraits: number;
1741
+ allowedTraits?: string[];
1742
+ blockDangerousPatterns: boolean;
1743
+ }
1744
+ /**
1745
+ * Validate AI-generated code for safety and correctness.
1746
+ */
1747
+ declare function validateAIOutput(code: string, config?: Partial<ValidatorConfig>): ValidationResult;
1748
+ /**
1749
+ * Quick check — returns true if code passes all error-level checks.
1750
+ */
1751
+ declare function isAISafe(code: string, config?: Partial<ValidatorConfig>): boolean;
1752
+
1753
+ export { type AIAdapter, AICopilot, ALL_CATEGORIES, ActionNode, AnthropicAdapter, type AnthropicAdapterConfig, BTNode, type BTStatus, type BTContext as BTTreeContext, type BTTreeDef, BehaviorSelector, BehaviorTree, Blackboard, ConditionNode, type ExplainResult, FireworksAdapter, type FireworksAdapterConfig, type FixResult, GeminiAdapter, type GeminiAdapterConfig, type GenerateOptions, type GenerateResult, GenerationAnalytics, GenerationCache, GoalPlanner, type GuardFn, GuardNode, HoloScriptGenerator, InfluenceMap, InverterNode, LMStudioAdapter, type LMStudioAdapterConfig, NVIDIAAdapter, type NVIDIAAdapterConfig, NavMesh, OllamaAdapter, type OllamaAdapterConfig, OpenAIAdapter, type OpenAIAdapterConfig, type OptimizeResult, ParallelNode, PerceptionSystem, type PromptTemplate, PromptTemplateSystem, QuickPrompts, RepeaterNode, type SearchResult, SelectorNode, SemanticSearchService, SequenceNode, type StateAction, type StateConfig, StateMachine, SteeringBehavior, SteeringBehaviors, type TemplateContext, TogetherAdapter, type TogetherAdapterConfig, TrainingDataGenerator, type TransitionConfig, UtilityAI, WaitNode, XAIAdapter, type XAIAdapterConfig, cachedGenerate, createAnalytics, createTrainingDataGenerator, explainHoloScript, fixHoloScript, generateBatch, generateHoloScript$1 as generateHoloScript, generateHoloScript as generateHoloScriptWithAdapter, getAIAdapter, getDefaultAIAdapter, isAISafe, listAIAdapters, optimizeHoloScript, registerAIAdapter, setDefaultAIAdapter, unregisterAIAdapter, useAnthropic, useFireworks, useGemini, useGrok, useLMStudio, useNVIDIA, useOllama, useOpenAI, useTogether, useXAI, validateAIOutput, validateBatch };