agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2

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 (396) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/cli.mjs +53 -0
  4. package/dist/AssetCompiler-A99wKf7H.js +2424 -0
  5. package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
  6. package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
  7. package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
  8. package/dist/AssetRecipe-DCaLLXvG.js +67 -0
  9. package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
  10. package/dist/BrowserCodeWorker.js +53850 -0
  11. package/dist/BrowserCodeWorker.js.map +1 -0
  12. package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
  13. package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
  14. package/dist/SceneSerializer-CLCzQjL_.js +350 -0
  15. package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
  16. package/dist/StylePack-CD_BC-Mv.js +6317 -0
  17. package/dist/StylePack-CD_BC-Mv.js.map +1 -0
  18. package/dist/WorldArchive-dYf1OpSe.js +417 -0
  19. package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
  20. package/dist/WorldIO-Dqz4MqTQ.js +149 -0
  21. package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
  22. package/dist/blankWorld-OoOvN_IK.js +75 -0
  23. package/dist/blankWorld-OoOvN_IK.js.map +1 -0
  24. package/dist/core.d.ts +68 -0
  25. package/dist/core.js +209 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/disposeObject3D-B3HCflvO.js +128 -0
  28. package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
  29. package/dist/environments-B1WaICAN.js +4197 -0
  30. package/dist/environments-B1WaICAN.js.map +1 -0
  31. package/dist/gltfIO-BMK1hc2D.js +9 -0
  32. package/dist/gltfIO-BMK1hc2D.js.map +1 -0
  33. package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
  34. package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
  35. package/dist/index.d.ts +275 -0
  36. package/dist/index.js +16239 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/magicCabin-DPQi_jh-.js +11019 -0
  39. package/dist/magicCabin-DPQi_jh-.js.map +1 -0
  40. package/dist/mcp.d.ts +2 -0
  41. package/dist/mcp.js +1 -0
  42. package/dist/monumentHall-IOLbRZQC.js +403 -0
  43. package/dist/monumentHall-IOLbRZQC.js.map +1 -0
  44. package/dist/node.d.ts +16 -0
  45. package/dist/node.js +26 -0
  46. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  47. package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
  48. package/dist/ruinedCourtyard-BtaF_aOi.js.map +1 -0
  49. package/dist/runtime/application/AgentTools.js +28 -0
  50. package/dist/runtime/application/README.md +14 -0
  51. package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
  52. package/dist/runtime/application/agent/StudioMcpAllowlist.js +8 -0
  53. package/dist/runtime/application/buildTaskObservation.js +117 -0
  54. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -0
  55. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
  56. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
  57. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +72 -0
  58. package/dist/runtime/application/createSession.js +66 -0
  59. package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
  60. package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
  61. package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
  62. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
  63. package/dist/runtime/application/native-scene/CodeProject.js +119 -0
  64. package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
  65. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
  66. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
  67. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
  68. package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
  69. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
  70. package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
  71. package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -0
  72. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
  73. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
  74. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
  75. package/dist/runtime/application/scene/CapabilityResolver.js +79 -0
  76. package/dist/runtime/application/scene/RequestWindow.js +54 -0
  77. package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
  78. package/dist/runtime/application/scene/SceneContracts.js +45 -0
  79. package/dist/runtime/application/scene/SceneEditService.js +144 -0
  80. package/dist/runtime/application/scene/SceneFacade.js +261 -0
  81. package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
  82. package/dist/runtime/application/scene/SceneJobController.js +229 -0
  83. package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
  84. package/dist/runtime/application/scene/ScenePackage.js +162 -0
  85. package/dist/runtime/application/scene/ScenePersistence.js +50 -0
  86. package/dist/runtime/application/scene/SceneProject.js +95 -0
  87. package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
  88. package/dist/runtime/application/scene/StarterScene.js +56 -0
  89. package/dist/runtime/application/scene/WorldArchive.js +87 -0
  90. package/dist/runtime/application/scene/WorldDirectory.js +20 -0
  91. package/dist/runtime/application/scene/WorldDocument.js +74 -0
  92. package/dist/runtime/application/scene/WorldIO.js +103 -0
  93. package/dist/runtime/application/scene/WorldStorage.js +137 -0
  94. package/dist/runtime/application/skills/SkillRegistry.js +189 -0
  95. package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
  96. package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
  97. package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
  98. package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
  99. package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
  100. package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
  101. package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
  102. package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
  103. package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
  104. package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
  105. package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
  106. package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
  107. package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
  108. package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
  109. package/dist/runtime/application/skills/skillPrimitives.js +4 -0
  110. package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
  111. package/dist/runtime/application/tasks.jsonl +67 -0
  112. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
  113. package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
  114. package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
  115. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
  116. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
  117. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
  118. package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
  119. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
  120. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
  121. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
  122. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +174 -0
  123. package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
  124. package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
  125. package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -0
  126. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
  127. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
  128. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
  129. package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
  130. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
  131. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
  132. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
  133. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
  134. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
  135. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +132 -0
  136. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
  137. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
  138. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
  139. package/dist/runtime/apps/mcp-server/README.md +150 -0
  140. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
  141. package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
  142. package/dist/runtime/apps/mcp-server/SessionManager.js +80 -0
  143. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
  144. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -0
  145. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
  146. package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
  147. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
  148. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
  149. package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
  150. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
  151. package/dist/runtime/apps/mcp-server/main.mjs +65 -0
  152. package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
  153. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
  154. package/dist/runtime/apps/mcp-server/security.js +21 -0
  155. package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
  156. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
  157. package/dist/runtime/apps/server/README.md +7 -0
  158. package/dist/runtime/apps/server/WorldDiskStorage.js +51 -0
  159. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
  160. package/dist/runtime/apps/server/tasks.jsonl +10 -0
  161. package/dist/runtime/foundation/EventBus.js +18 -0
  162. package/dist/runtime/foundation/JsonGateway.js +47 -0
  163. package/dist/runtime/foundation/PolicyEngine.js +21 -0
  164. package/dist/runtime/foundation/README.md +7 -0
  165. package/dist/runtime/foundation/TraceRecorder.js +76 -0
  166. package/dist/runtime/foundation/errors.js +8 -0
  167. package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
  168. package/dist/runtime/foundation/version.js +2 -0
  169. package/dist/runtime/modules/agent/README.md +11 -0
  170. package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
  171. package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
  172. package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
  173. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
  174. package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
  175. package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
  176. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
  177. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
  178. package/dist/runtime/modules/agent/prompt/index.js +52 -0
  179. package/dist/runtime/modules/agent/tasks.jsonl +94 -0
  180. package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
  181. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
  182. package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
  183. package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
  184. package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
  185. package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
  186. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
  187. package/dist/runtime/modules/artifact/README.md +7 -0
  188. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
  189. package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
  190. package/dist/runtime/modules/asset/AssetModule.js +399 -0
  191. package/dist/runtime/modules/asset/README.md +54 -0
  192. package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
  193. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
  194. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
  195. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
  196. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
  197. package/dist/runtime/modules/asset/model/AssetInputContracts.js +100 -0
  198. package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
  199. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
  200. package/dist/runtime/modules/asset/model/admission.js +117 -0
  201. package/dist/runtime/modules/asset/model/errors.js +6 -0
  202. package/dist/runtime/modules/asset/model/parts.js +27 -0
  203. package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
  204. package/dist/runtime/modules/asset/model/schema.js +150 -0
  205. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
  206. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
  207. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
  208. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
  209. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
  210. package/dist/runtime/modules/asset/production/AssetRecipe.js +47 -0
  211. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
  212. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
  213. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
  214. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
  215. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
  216. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
  217. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
  218. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
  219. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
  220. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
  221. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
  222. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
  223. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
  224. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
  225. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
  226. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
  227. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
  228. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
  229. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
  230. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
  231. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
  232. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
  233. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
  234. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
  235. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
  236. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
  237. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
  238. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
  239. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
  240. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
  241. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
  242. package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
  243. package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
  244. package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
  245. package/dist/runtime/modules/asset/tasks.jsonl +87 -0
  246. package/dist/runtime/modules/generation/README.md +9 -0
  247. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
  248. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
  249. package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
  250. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
  251. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
  252. package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
  253. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
  254. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
  255. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
  256. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
  257. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
  258. package/dist/runtime/modules/generation/tasks.jsonl +35 -0
  259. package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
  260. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +245 -0
  261. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
  262. package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
  263. package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
  264. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -0
  265. package/dist/runtime/modules/rendering/README.md +7 -0
  266. package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
  267. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
  268. package/dist/runtime/modules/rendering/createRenderer.js +76 -0
  269. package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
  270. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
  271. package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
  272. package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
  273. package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
  274. package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
  275. package/dist/runtime/modules/world/README.md +13 -0
  276. package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
  277. package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
  278. package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
  279. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
  280. package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
  281. package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
  282. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
  283. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
  284. package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
  285. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
  286. package/dist/runtime/modules/world/content/blankWorld.js +35 -0
  287. package/dist/runtime/modules/world/content/environments.js +84 -0
  288. package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
  289. package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
  290. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
  291. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
  292. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
  293. package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
  294. package/dist/runtime/modules/world/content/magicCabin.js +190 -0
  295. package/dist/runtime/modules/world/content/monumentHall.js +154 -0
  296. package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
  297. package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
  298. package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
  299. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
  300. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
  301. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
  302. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
  303. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
  304. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
  305. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
  306. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
  307. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
  308. package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
  309. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
  310. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
  311. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
  312. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
  313. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
  314. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
  315. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
  316. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
  317. package/dist/runtime/modules/world/errors.js +9 -0
  318. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
  319. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
  320. package/dist/runtime/modules/world/runtime/CommandHistory.js +80 -0
  321. package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -0
  322. package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
  323. package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
  324. package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
  325. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +207 -0
  326. package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -0
  327. package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
  328. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
  329. package/dist/runtime/modules/world/runtime/WorldCommands.js +502 -0
  330. package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
  331. package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
  332. package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
  333. package/dist/runtime/modules/world/runtime/WorldRuntime.js +665 -0
  334. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -0
  335. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
  336. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
  337. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
  338. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
  339. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
  340. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +305 -0
  341. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
  342. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
  343. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +222 -0
  344. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
  345. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
  346. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
  347. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
  348. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
  349. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
  350. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
  351. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
  352. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
  353. package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
  354. package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
  355. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
  356. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
  357. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
  358. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
  359. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
  360. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -0
  361. package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
  362. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
  363. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
  364. package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
  365. package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
  366. package/dist/runtime/modules/world/tasks.jsonl +530 -0
  367. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
  368. package/dist/runtime/modules/world/verification/Finding.js +105 -0
  369. package/dist/runtime/modules/world/verification/InteractionEvidence.js +69 -0
  370. package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
  371. package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
  372. package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
  373. package/dist/runtime/package-lock.json +16048 -0
  374. package/dist/runtime/package.json +105 -0
  375. package/dist/runtime/public/assets/cabinet.glb +0 -0
  376. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  377. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  378. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  379. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  380. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  381. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  382. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  383. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  384. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  385. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  386. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  387. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  388. package/dist/schema-BWpTl0Wj.js +359 -0
  389. package/dist/schema-BWpTl0Wj.js.map +1 -0
  390. package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
  391. package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
  392. package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
  393. package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
  394. package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
  395. package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
  396. package/package.json +70 -4
@@ -0,0 +1,502 @@
1
+ import { assetAdmission } from '../../asset/model/admission.js';
2
+ import { physicsManifestForUniformScale } from './ObjectTransform.js';
3
+ import { samePhysicalGeometry } from './WorldCollisionSignature.js';
4
+
5
+ const round3 = (value) => Number(value.toFixed(3));
6
+ const vec3Round = (value) => Array.isArray(value) ? value.map(round3) : value;
7
+ const yawFromQuat = ([x, y, z, w]) => Math.atan2(2 * (w * y + x * z), 1 - 2 * (y * y + z * z));
8
+
9
+ export class WorldCommands {
10
+ constructor(runtime) {
11
+ if (!runtime) throw new TypeError('WorldCommands requires a WorldRuntime');
12
+ this.runtime = runtime;
13
+ }
14
+
15
+ assertReady(command) {
16
+ if (this.runtime.ready !== false) return;
17
+ const assembled = this.runtime.sceneGraph
18
+ && this.runtime.history
19
+ && this.runtime.navigation
20
+ && this.runtime.locomotion
21
+ && this.runtime.interactions;
22
+ if (assembled) return;
23
+ const error = new Error(`World command requires an initialized WorldRuntime: ${command}`);
24
+ error.code = 'WORLD_COMMAND_NOT_READY';
25
+ error.command = command;
26
+ throw error;
27
+ }
28
+
29
+ async spawn(assetId, options = {}) {
30
+ this.assertReady('spawn');
31
+ const admission = assetAdmission(this.runtime.assetModule.getManifest(assetId));
32
+ if (admission.status === 'rejected') {
33
+ return { status:'asset-rejected', assetId, admission };
34
+ }
35
+ const id = await this.runtime.spawn(assetId, options);
36
+ return admission.status === 'ready'
37
+ ? id
38
+ : { status:'asset-provisional', id, assetId, admission };
39
+ }
40
+
41
+ async replaceAsset(id, assetId) {
42
+ this.assertReady('replaceAsset');
43
+ const record=this.runtime.store.get(id);
44
+ if(record.state?.heldBy)throw Object.assign(new Error('Put down the object before upgrading its asset'),{code:'ASSET_INSTANCE_HELD'});
45
+ if(record.manifest.type==='agent')throw Object.assign(new Error('Agent embodiment upgrades are not supported'),{code:'ASSET_UPGRADE_AGENT_UNSUPPORTED'});
46
+ const manifest=this.runtime.assetModule.getManifest(assetId);
47
+ if(assetAdmission(manifest).status!=='ready')throw Object.assign(new Error('Asset is not ready'),{code:'ASSET_NOT_READY'});
48
+ const pose={id,position:record.object.position.toArray(),quaternion:record.object.quaternion.toArray(),scale:record.object.scale.x};
49
+ const previousAssetId=record.assetId;
50
+ return this.runtime.mutate('asset:replace',async()=>{
51
+ // An identical collider/joint layout preserves legitimate resting contacts; new physics is still registered.
52
+ const sameCollision=samePhysicalGeometry(manifest,record.manifest);
53
+ const check=sameCollision || manifest.capabilityLevel==='visual'?{checked:true,clear:true}:this.runtime.physics.checkManifestPose(physicsManifestForUniformScale(manifest,pose.scale),pose.position,{quaternion:pose.quaternion,excludeIds:[id]});
54
+ if(!check.checked||!check.clear)throw Object.assign(new Error('New asset does not fit at the current pose'),{code:'ASSET_UPGRADE_PLACEMENT_BLOCKED'});
55
+ this.remove(id);await this.spawn(assetId,pose);
56
+ const navigation=await this.runtime.navigation.ensureCurrent();
57
+ if(!navigation.success || (manifest.capabilityLevel!=='visual' && !this.runtime.physics.getPosition(id)))throw Object.assign(new Error('New entity failed runtime registration'),{code:'ASSET_UPGRADE_FAILED'});
58
+ return {status:'asset-instance-updated',id,assetId,previousAssetId,stateReset:true};
59
+ });
60
+ }
61
+
62
+ transform(id, transform = {}, options = {}) {
63
+ this.assertReady('transform');
64
+ if (this.runtime.store.get(id).state?.heldBy || this.runtime.interactions?.isHeld?.(id) || this.runtime.interactions?.carry?.agentHeld?.has(id)) throw Object.assign(new Error('Put down the object before editing'), { code: 'OBJECT_HELD' });
65
+ return this.runtime.applyObjectTransform(id, transform, options);
66
+ }
67
+
68
+ beginTransform(id) {
69
+ this.assertReady('beginTransform');
70
+ if (this.runtime.store.get(id).state?.heldBy || this.runtime.interactions?.isHeld?.(id) || this.runtime.interactions?.carry?.agentHeld?.has(id)) throw Object.assign(new Error('Put down the object before editing'), { code: 'OBJECT_HELD' });
71
+ return this.runtime.physics.beginTransform(id);
72
+ }
73
+
74
+ endTransform(id) {
75
+ this.assertReady('endTransform');
76
+ return this.runtime.physics.endTransform(id);
77
+ }
78
+
79
+ setHumanViewPose(pose) {
80
+ this.assertReady('setHumanViewPose');
81
+ return this.runtime.interactions.setHumanViewPose(pose);
82
+ }
83
+
84
+ async duplicate(id) {
85
+ this.assertReady('duplicate');
86
+ const source = this.runtime.store.get(id);
87
+ const assetId = source.assetId;
88
+ const admission = assetAdmission(this.runtime.assetModule.getManifest(assetId));
89
+ if (admission.status === 'rejected') {
90
+ return { status:'asset-rejected', assetId, sourceId:id, admission };
91
+ }
92
+ const duplicateId = await this.runtime.duplicate(id);
93
+ return admission.status === 'ready'
94
+ ? duplicateId
95
+ : { status:'asset-provisional', id:duplicateId, assetId, sourceId:id, admission };
96
+ }
97
+
98
+ remove(id, options = {}) {
99
+ this.assertReady('remove');
100
+ if (this.runtime.store.get(id).state?.heldBy || this.runtime.interactions?.isHeld?.(id) || this.runtime.interactions?.carry?.agentHeld?.has(id)) throw Object.assign(new Error('Put down the object before editing'), { code: 'OBJECT_HELD' });
101
+ return this.runtime.remove(id, options);
102
+ }
103
+
104
+ navigate(id, end, options = {}) {
105
+ this.assertReady('navigate');
106
+ return this.runtime.locomotion.navigate(id, end, options);
107
+ }
108
+
109
+ async moveForward(id, { distance = 0.8, speed } = {}) {
110
+ this.assertReady('moveForward');
111
+ if (!this.runtime.store?.has?.(id)) {
112
+ const error = new Error(`Object not found: ${id}`);
113
+ error.code = 'OBJECT_NOT_FOUND';
114
+ throw error;
115
+ }
116
+ if (!Number.isFinite(distance) || distance <= 0 || distance > 4) {
117
+ const error = new Error('moveForward distance must be within (0, 4]');
118
+ error.code = 'MOVE_FORWARD_DISTANCE_INVALID';
119
+ throw error;
120
+ }
121
+ const record = this.runtime.store.get(id);
122
+ if (record.manifest?.type !== 'agent' || !record.manifest.actions?.includes('navigate')) {
123
+ const error = new Error(`Object is not a navigable agent: ${id}`);
124
+ error.code = 'NOT_NAVIGABLE_AGENT';
125
+ throw error;
126
+ }
127
+ if (record.manifest.physics?.body !== 'kinematic') {
128
+ const error = new Error(`Navigable agent must use a kinematic body: ${id}`);
129
+ error.code = 'NAVIGABLE_BODY_INVALID';
130
+ throw error;
131
+ }
132
+ const start = this.runtime.physics?.getPosition?.(id);
133
+ if (!start) {
134
+ const error = new Error(`Physics body not available: ${id}`);
135
+ error.code = 'PHYSICS_BODY_UNAVAILABLE';
136
+ throw error;
137
+ }
138
+ const rotation = this.runtime.physics?.getRotation?.(id);
139
+ if (!Array.isArray(rotation) || rotation.length !== 4 || !rotation.every(Number.isFinite)) {
140
+ const error = new Error(`Agent rotation unavailable: ${id}`);
141
+ error.code = 'AGENT_ROTATION_UNAVAILABLE';
142
+ throw error;
143
+ }
144
+ const yaw = yawFromQuat(rotation);
145
+ // 与 LocomotionSystem.steer 的 character facing 一致:[-sin(yaw), 0, -cos(yaw)]
146
+ const forward = [-Math.sin(yaw), 0, -Math.cos(yaw)];
147
+ const end = [
148
+ start[0] + forward[0] * distance,
149
+ start[1],
150
+ start[2] + forward[2] * distance
151
+ ];
152
+ const result = await this.runtime.locomotion.navigate(id, end, { speed });
153
+ const position = Array.isArray(result?.position) ? result.position : null;
154
+ const moved = position
155
+ ? Math.hypot(position[0] - start[0], position[2] - start[2])
156
+ : (result?.status === 'arrived' ? distance : 0);
157
+ const base = {
158
+ ...result,
159
+ skill: 'moveForward',
160
+ start: vec3Round(start),
161
+ end: vec3Round(end),
162
+ distance,
163
+ yaw: round3(yaw),
164
+ forward: vec3Round(forward),
165
+ moved: round3(moved)
166
+ };
167
+ if (result?.status === 'arrived' && moved < Math.max(0.05, distance * 0.35)) {
168
+ return {
169
+ ...base,
170
+ status: 'blocked',
171
+ reason: 'INSUFFICIENT_FORWARD_DISPLACEMENT'
172
+ };
173
+ }
174
+ return base;
175
+ }
176
+
177
+ activateEnvironmentInteraction(interactionId, { actorId = null, requireReach = true } = {}) {
178
+ this.assertReady('activateEnvironmentInteraction');
179
+ const runtime = this.runtime;
180
+ const interactions = runtime.environment?.interactions || [];
181
+ const item = interactions.find((entry) => entry.id === interactionId);
182
+ if (!item) {
183
+ return { status:'interaction-not-found', interactionId, environmentId:runtime.environment?.id || null };
184
+ }
185
+ if (typeof item.activate !== 'function') {
186
+ return { status:'interaction-not-executable', interactionId, label:item.label || null };
187
+ }
188
+
189
+ const position = (() => {
190
+ const object = item.object;
191
+ if (!object) return null;
192
+ if (object.isObject3D) {
193
+ object.updateWorldMatrix?.(true, false);
194
+ const elements = object.matrixWorld?.elements;
195
+ if (elements) return [elements[12], elements[13], elements[14]];
196
+ }
197
+ return null;
198
+ })();
199
+
200
+ // Formally declared actions use the contract's own reach and postcondition checks.
201
+ // Native object pivots are not authoritative interaction target positions.
202
+ if (item.contractId) {
203
+ const contract = runtime.affordances?.get?.(item.contractId);
204
+ if (contract) {
205
+ const state = contract.read?.() || {};
206
+ let action = null;
207
+ if (contract.kind === 'book') action = state.out ? 'return' : 'pull_out';
208
+ else if (contract.kind === 'switch') action = state.on ? 'turn_off' : 'turn_on';
209
+ else if (state.requestedOpen === true || state.out === true) action = 'close';
210
+ else if (state.requestedOpen === false || state.out === false) action = 'open';
211
+ if (action && contract.actions?.includes(action)) {
212
+ const response = runtime.affordances.execute({ targetId:item.contractId, action, actorId }, {});
213
+ const withNativeId = value => value?.status === 'world-action-blocked'
214
+ ? { ...value, interactionId } : value;
215
+ return response?.then ? response.then(withNativeId) : withNativeId(response);
216
+ }
217
+ }
218
+ }
219
+
220
+ if (requireReach && actorId) {
221
+ const feet = runtime.physics?.getPosition?.(actorId);
222
+ if (!feet) {
223
+ return { status:'world-action-blocked', interactionId, reason:'ACTOR_PHYSICS_UNAVAILABLE', actorId };
224
+ }
225
+ if (!position) {
226
+ return { status:'world-action-blocked', interactionId, reason:'INTERACTION_POSITION_UNAVAILABLE', actorId };
227
+ }
228
+ const distance = Math.hypot(position[0]-feet[0], position[1]-feet[1], position[2]-feet[2]);
229
+ if (distance > 1.5) {
230
+ return {
231
+ status:'world-action-blocked', interactionId, reason:'OUT_OF_REACH',
232
+ actorId, distance:round3(distance), maxDistance:1.5, position:vec3Round(position)
233
+ };
234
+ }
235
+ if (runtime.physics?.hasCapability?.('scene-query') && runtime.physics.raycast) {
236
+ const origin = [feet[0], feet[1] + 1.2, feet[2]];
237
+ const hit = runtime.physics.raycast(origin, position, { excludeId: actorId });
238
+ if (hit && hit.distance < distance - 0.12) {
239
+ return {
240
+ status:'world-action-blocked', interactionId, reason:'OCCLUDED',
241
+ actorId, blocker:hit.provenance || { id:hit.id }, distance:round3(distance)
242
+ };
243
+ }
244
+ }
245
+ }
246
+
247
+ item.activate();
248
+ return {
249
+ status:'environment-interaction-activated',
250
+ interactionId,
251
+ label:item.label || null,
252
+ contractId:item.contractId || null,
253
+ environmentId:runtime.environment?.id || null,
254
+ position:vec3Round(position),
255
+ via:'native-activate',
256
+ provisional:true,
257
+ verification:'native-provisional',
258
+ evidenceKind:'animated-transform',
259
+ physicsVerified:false,
260
+ note:'Native Three.js scene interaction; not force-verified articulated asset physics.'
261
+ };
262
+ }
263
+
264
+ async resolveEnvironmentApproach(target, start, { radii = [0.9, 1.2, 1.5, 1.8], samples = 16, maxSnapDistance = 0.75 } = {}) {
265
+ const runtime = this.runtime;
266
+ const navigation = runtime.navigation;
267
+ if (!navigation?.findPath || !Array.isArray(target) || !Array.isArray(start)) {
268
+ return { reachable:false, reason:'NAVIGATION_UNAVAILABLE', candidates:0 };
269
+ }
270
+ // 整圈采样,不按 agent 距离排序:门关着时「朝 agent」可能是屋内侧,会系统性打偏。
271
+ const candidates = [];
272
+ for (const radius of radii) {
273
+ for (let i = 0; i < samples; i += 1) {
274
+ const angle = (i / samples) * Math.PI * 2;
275
+ candidates.push([target[0] + Math.sin(angle)*radius, target[1], target[2] + Math.cos(angle)*radius]);
276
+ }
277
+ // 明确加轴向外点(门通常有一侧是可站立室外)
278
+ candidates.push([target[0] + radius, target[1], target[2]]);
279
+ candidates.push([target[0] - radius, target[1], target[2]]);
280
+ candidates.push([target[0], target[1], target[2] + radius]);
281
+ candidates.push([target[0], target[1], target[2] - radius]);
282
+ }
283
+ const tried = [];
284
+ const budget = Math.min(candidates.length, 28);
285
+ for (let index = 0; index < budget; index += 1) {
286
+ const end = candidates[index];
287
+ const route = await navigation.findPath(start, end, { maxSnapDistance, endTolerance: 0.6 });
288
+ tried.push({ end: vec3Round(end), reachable: route?.reachable === true, reason: route?.reason || null, cost: route?.cost ?? null });
289
+ if (route?.reachable) {
290
+ return { reachable:true, end, route, tried, candidates:candidates.length };
291
+ }
292
+ }
293
+ return { reachable:false, reason:'NO_APPROACH_POSE', tried, candidates:candidates.length };
294
+ }
295
+
296
+ async findEnvironmentInteractApproach(interactionId, { actorId = null } = {}) {
297
+ this.assertReady('findEnvironmentInteractApproach');
298
+ const runtime = this.runtime;
299
+ const item = (runtime.environment?.interactions || []).find((entry) => entry.id === interactionId);
300
+ if (!item) return { status:'interaction-not-found', interactionId };
301
+ const target = (() => {
302
+ const object = item.object;
303
+ if (!object?.isObject3D) return null;
304
+ object.updateWorldMatrix?.(true, false);
305
+ const elements = object.matrixWorld?.elements;
306
+ return elements ? [elements[12], elements[13], elements[14]] : null;
307
+ })();
308
+ if (!target) return { status:'interaction-position-unavailable', interactionId };
309
+ const start = actorId ? runtime.physics?.getPosition?.(actorId) : null;
310
+ if (!start) return { status:'actor-required-or-unavailable', interactionId, actorId };
311
+ const approach = await this.resolveEnvironmentApproach(target, start);
312
+ return {
313
+ status: approach.reachable ? 'approach-ready' : 'approach-unreachable',
314
+ interactionId,
315
+ label:item.label || null,
316
+ contractId:item.contractId || null,
317
+ actorId,
318
+ start:vec3Round(start),
319
+ target:vec3Round(target),
320
+ approach: approach.reachable ? vec3Round(approach.end) : null,
321
+ distance: round3(Math.hypot(target[0]-start[0], target[1]-start[1], target[2]-start[2])),
322
+ reason: approach.reachable ? null : (approach.reason || 'NO_APPROACH_POSE'),
323
+ tried: approach.tried || []
324
+ };
325
+ }
326
+
327
+ async approachAndActivateEnvironmentInteract(interactionId, { actorId = null, speed } = {}) {
328
+ this.assertReady('approachAndActivateEnvironmentInteract');
329
+ const runtime = this.runtime;
330
+ const skill = 'approachAndActivateEnvironmentInteract';
331
+ const item = (runtime.environment?.interactions || []).find((entry) => entry.id === interactionId);
332
+ if (!item) {
333
+ return { status:'interaction-not-found', skill, interactionId, environmentId:runtime.environment?.id || null };
334
+ }
335
+ if (typeof item.activate !== 'function') {
336
+ return { status:'interaction-not-executable', skill, interactionId, label:item.label || null };
337
+ }
338
+ if (!actorId) {
339
+ return { status:'actor-required', skill, interactionId };
340
+ }
341
+ const start = runtime.physics?.getPosition?.(actorId);
342
+ if (!start) {
343
+ return { status:'world-action-blocked', skill, interactionId, reason:'ACTOR_PHYSICS_UNAVAILABLE', actorId };
344
+ }
345
+ const target = (() => {
346
+ const object = item.object;
347
+ if (!object?.isObject3D) return null;
348
+ object.updateWorldMatrix?.(true, false);
349
+ const elements = object.matrixWorld?.elements;
350
+ return elements ? [elements[12], elements[13], elements[14]] : null;
351
+ })();
352
+ if (!target) {
353
+ return { status:'world-action-blocked', skill, interactionId, reason:'INTERACTION_POSITION_UNAVAILABLE', actorId };
354
+ }
355
+ const distanceToTarget = Math.hypot(target[0]-start[0], target[1]-start[1], target[2]-start[2]);
356
+ if (distanceToTarget <= 1.5) {
357
+ const activation = await this.activateEnvironmentInteraction(interactionId, { actorId });
358
+ runtime.navigation?.invalidate?.('environment-interaction-activated');
359
+ const navigationBuild = runtime.navigation?.ensureBuilt ? await runtime.navigation.ensureBuilt() : null;
360
+ return {
361
+ ...activation,
362
+ skill, phase:'activated', start:vec3Round(start), target:vec3Round(target),
363
+ distance:round3(distanceToTarget), navigated:false,
364
+ navigationInvalidated:true,
365
+ navigationBuild: navigationBuild ? { success:navigationBuild.success === true, buildVersion:navigationBuild.buildVersion ?? null, code:navigationBuild.code || null } : null,
366
+ nextStepHint:item.contractId
367
+ ? 'NavMesh rebuilt after door/path change; call navigateTo/findPath on a fresh planning round before entering or climbing.'
368
+ : 'Native activation does not rebuild NavMesh by itself.'
369
+ };
370
+ }
371
+ const approach = await this.resolveEnvironmentApproach(target, start);
372
+ if (!approach.reachable) {
373
+ return {
374
+ status:'unreachable',
375
+ skill,
376
+ interactionId,
377
+ label:item.label || null,
378
+ actorId,
379
+ start:vec3Round(start),
380
+ target:vec3Round(target),
381
+ distance:round3(distanceToTarget),
382
+ reason:approach.reason || 'NO_PATH_TO_ENVIRONMENT_INTERACTION',
383
+ tried:approach.tried || []
384
+ };
385
+ }
386
+ const end = approach.end;
387
+ const navResult = await runtime.locomotion.navigate(actorId, end, { speed });
388
+ if (navResult?.status !== 'arrived') {
389
+ return {
390
+ ...navResult,
391
+ skill,
392
+ phase:'approach',
393
+ interactionId,
394
+ label:item.label || null,
395
+ target:vec3Round(target),
396
+ approach:vec3Round(end)
397
+ };
398
+ }
399
+ const activation = await this.activateEnvironmentInteraction(interactionId, { actorId });
400
+ runtime.navigation?.invalidate?.('environment-interaction-activated');
401
+ // 门/路径类原生交互后立刻重建 NavMesh,避免下一轮 navigateTo 仍打在关门烘焙结果上。
402
+ const navigationBuild = runtime.navigation?.ensureBuilt ? await runtime.navigation.ensureBuilt() : null;
403
+ return {
404
+ ...activation,
405
+ skill,
406
+ phase:'activated',
407
+ start:vec3Round(start),
408
+ approach:vec3Round(end),
409
+ target:vec3Round(target),
410
+ navigated:true,
411
+ navigationInvalidated:true,
412
+ navigationBuild: navigationBuild ? { success:navigationBuild.success === true, buildVersion:navigationBuild.buildVersion ?? null, code:navigationBuild.code || null } : null,
413
+ nextStepHint:item.contractId
414
+ ? 'NavMesh rebuilt after door/path change; fresh replan then navigateTo/findPath before entering or going upstairs.'
415
+ : 'Native activation does not rebuild NavMesh by itself.'
416
+ };
417
+ }
418
+
419
+ pickup(id) {
420
+ this.assertReady('pickup');
421
+ return this.runtime.interactions.pickup(id);
422
+ }
423
+
424
+ drop(id) {
425
+ this.assertReady('drop');
426
+ return this.runtime.interactions.drop(id);
427
+ }
428
+
429
+ place(id, targetId, options = {}) {
430
+ this.assertReady('place');
431
+ return this.runtime.interactions.place(id, targetId, options);
432
+ }
433
+
434
+ setArticulationAction(id, action, options = {}) {
435
+ this.assertReady('setArticulationAction');
436
+ return this.runtime.interactions.setArticulationAction(id, action, options);
437
+ }
438
+
439
+ approachAndInteract(actorId, targetId, action, options = {}) {
440
+ this.assertReady('approachAndInteract');
441
+ return this.runtime.interactions.approachAndInteract(actorId, targetId, action, options);
442
+ }
443
+
444
+ approachAndPickup(actorId, targetId, options = {}) {
445
+ this.assertReady('approachAndPickup');
446
+ return this.runtime.interactions.approachAndPickup(actorId, targetId, options);
447
+ }
448
+
449
+ approachAndPlace(actorId, supportId, options = {}) {
450
+ this.assertReady('approachAndPlace');
451
+ return this.runtime.interactions.approachAndPlace(actorId, supportId, options);
452
+ }
453
+
454
+ dropHeld(actorId) {
455
+ this.assertReady('dropHeld');
456
+ return this.runtime.interactions.dropHeld(actorId);
457
+ }
458
+
459
+ markRecoveryHeld(actorId, details) {
460
+ this.assertReady('markRecoveryHeld');
461
+ return this.runtime.interactions.markRecoveryHeld(actorId, details);
462
+ }
463
+
464
+ cleanupRecoveryBlocker(actorId, targetId, options = {}) {
465
+ this.assertReady('cleanupRecoveryBlocker');
466
+ return this.runtime.interactions.cleanupRecoveryBlocker(actorId, targetId, options);
467
+ }
468
+
469
+ applyStateTransition(id, stateKey, value, meta = {}) {
470
+ this.assertReady('applyStateTransition');
471
+ return this.runtime.applyStateTransition(id, stateKey, value, meta);
472
+ }
473
+
474
+ executeAffordance(args = {}, options = {}) {
475
+ this.assertReady('executeAffordance');
476
+ return options.approach ? this.runtime.affordances.approachAndExecute(args) : this.runtime.affordances.execute(args, options);
477
+ }
478
+
479
+ repair(report, options = {}) {
480
+ this.assertReady('repair');
481
+ return this.runtime.repair.repair(report, options);
482
+ }
483
+
484
+ syncAssetVerification(assetId, manifest) {
485
+ let updated = 0;
486
+ for (const record of this.runtime.store?.values?.() || []) {
487
+ if (record.assetId !== assetId) continue;
488
+ record.manifest.verification = structuredClone(manifest.verification || {});
489
+ if (manifest.compiler?.quality && record.manifest.compiler) {
490
+ record.manifest.compiler.quality = structuredClone(manifest.compiler.quality);
491
+ }
492
+ if (record.object?.userData?.manifest) {
493
+ record.object.userData.manifest.verification = structuredClone(record.manifest.verification);
494
+ if (record.manifest.compiler?.quality && record.object.userData.manifest.compiler) {
495
+ record.object.userData.manifest.compiler.quality = structuredClone(record.manifest.compiler.quality);
496
+ }
497
+ }
498
+ updated += 1;
499
+ }
500
+ return { status:'asset-verification-synced', assetId, instances:updated };
501
+ }
502
+ }
@@ -0,0 +1,71 @@
1
+ const clone = (value) => value == null ? value : structuredClone(value);
2
+
3
+ export class WorldObservation {
4
+ constructor(runtime) {
5
+ this.runtime = runtime;
6
+ }
7
+
8
+ hasObject(id) {
9
+ return Boolean(id && this.runtime.store?.has(id));
10
+ }
11
+
12
+ object(id) {
13
+ if (!this.hasObject(id)) return null;
14
+ const record = this.runtime.store.get(id);
15
+ const position = this.runtime.physics?.getPosition?.(id) || record.object?.position?.toArray?.() || null;
16
+ return {
17
+ id,
18
+ asset: record.assetId,
19
+ type: record.manifest?.type,
20
+ position: Array.isArray(position) ? [...position] : null
21
+ };
22
+ }
23
+
24
+ relations(ids = [], { limit = 8 } = {}) {
25
+ if (!this.runtime.sceneGraph || !ids.length) return [];
26
+ this.runtime.sceneGraph.update();
27
+ const relevant = new Set(ids);
28
+ const edges = [];
29
+ for (const edge of this.runtime.sceneGraph.list()) {
30
+ if (!relevant.has(edge.subject) && !relevant.has(edge.object)) continue;
31
+ edges.push(clone(edge));
32
+ if (edges.length >= limit) break;
33
+ }
34
+ return edges;
35
+ }
36
+
37
+ actor(id) {
38
+ const object = this.object(id);
39
+ if (!object) return null;
40
+ return {
41
+ id,
42
+ position: object.position,
43
+ navigation: this.runtime.locomotion?.status?.(id) || null,
44
+ carry: this.runtime.interactions?.carryStatus?.(id) || null
45
+ };
46
+ }
47
+
48
+ affordances(ids = [], { actorId = null } = {}) {
49
+ const runtimeAffordances = this.runtime.affordances;
50
+ if (!runtimeAffordances?.list) return null;
51
+ const listing = runtimeAffordances.list({ actorId, limit:1 });
52
+ if (!listing.total) return null;
53
+ return {
54
+ count: listing.total,
55
+ lastResult: clone(runtimeAffordances.lastResult || null),
56
+ focus: ids.map((id) => runtimeAffordances.inspect(id, { actorId })).filter(Boolean)
57
+ };
58
+ }
59
+
60
+ articulation(id) {
61
+ if (!this.hasObject(id)) return null;
62
+ const parts = this.runtime.store.get(id).manifest?.parts || {};
63
+ const supported = Object.values(parts).some((part) => part?.joint && part?.physics && part.joint.type !== 'fixed');
64
+ if (!supported || !this.runtime.interactions?.articulationStatus) return null;
65
+ try {
66
+ return clone(this.runtime.interactions.articulationStatus(id));
67
+ } catch {
68
+ return null;
69
+ }
70
+ }
71
+ }