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,229 @@
1
+ import { recordInteractionEvidence } from '../../modules/world/verification/InteractionEvidence.js';
2
+ import { sceneError, sceneInteractionSchema, diagnostic } from './SceneContracts.js';
3
+ import { resolveCapability } from './CapabilityResolver.js';
4
+ import { legacyPhysicalRequest } from './SceneInteractionAdapters.js';
5
+ import { verifyInteractionResult } from '../../modules/world/runtime/interaction/InteractionContract.js';
6
+
7
+ /** Manages asynchronous Scene actions through one cancellable Job lifecycle. */
8
+ export function createSceneJobController(world, { tools, assertIdle, assertOpen, setBusy, actors, onProjectAction = () => {}, result }) {
9
+ const jobs = new Map();
10
+ // Historical Scene commands remain supported; capability invocation is
11
+ // dispatched by executor, with arbitrary articulated names read from manifests.
12
+ const physicalActions = new Set(['push', 'drag', 'rotate', 'slide', 'rotateJoint']);
13
+ const cancelPending = () => {
14
+ if ([...jobs.values()].some(job => job.status === 'running' && job.cancelled && !job.controller)) {
15
+ world.interactions.cancelPending('SCENE_CANCELLED');
16
+ world.locomotion.cancelAll('SCENE_CANCELLED');
17
+ world.affordances.cancel('SCENE_CANCELLED');
18
+ }
19
+ };
20
+
21
+ const controller = {
22
+ interact(input) {
23
+ const args = sceneInteractionSchema.parse(input);
24
+ assertIdle();
25
+ if (args.action === 'custom') return startProjectAction(args);
26
+ if (args.action === 'invoke') return startInvocation(args);
27
+ return startLegacyAction(args);
28
+ },
29
+ getJob(key) {
30
+ assertOpen();
31
+ const job = getJob(key);
32
+ return structuredClone({ id: job.id, status: job.status, result: job.result });
33
+ },
34
+ async waitJob(key) {
35
+ assertOpen();
36
+ const job = getJob(key);
37
+ await job.promise;
38
+ return controller.getJob(key);
39
+ },
40
+ cancelJob(key) {
41
+ assertOpen();
42
+ const job = getJob(key);
43
+ if (job.status === 'running') {
44
+ job.cancelled = true;
45
+ job.controller?.abort();
46
+ if (!job.controller) cancelPending();
47
+ }
48
+ return { id: job.id, status: job.status, cancellationRequested: Boolean(job.cancelled) };
49
+ }
50
+ };
51
+
52
+ // The historical intent-based API continues to use its existing runtime
53
+ // commands, actor checks, policy and verification semantics unchanged.
54
+ function startLegacyAction(args) {
55
+ const nativeAction = args.action === 'activate';
56
+ if (nativeAction && !actors().agents.some(agent => agent.id === args.actor)) throw sceneError('ACTOR_NOT_AGENT');
57
+ if (nativeAction && !world.environment?.interactions?.some(item =>
58
+ item.id === args.target && typeof item.activate === 'function')) throw sceneError('INTERACTION_UNAVAILABLE');
59
+ const contract = 'target' in args ? world.affordances?.get?.(args.target) : null;
60
+ const worldAction = Boolean(contract) && !nativeAction;
61
+ if (worldAction && !contract.actions.includes(args.action)) throw sceneError('ACTION_UNSUPPORTED');
62
+ if (!contract && ['turn_on', 'turn_off', 'pull_out', 'return', 'write'].includes(args.action)) throw sceneError('ACTION_UNSUPPORTED');
63
+
64
+ const [skill, params] = args.action === 'navigate' ? ['navigateTo', { id:args.actor, end:args.position }]
65
+ : args.action === 'pickup' ? ['approachAndPickup', { actorId:args.actor, targetId:args.target }]
66
+ : args.action === 'place' ? ['approachAndPlace', { actorId:args.actor, supportId:args.target, surfaceId:args.surfaceId }]
67
+ : ['approachAndInteract', { actorId:args.actor, targetId:args.target, action:args.action, partName:args.partName }];
68
+ const physical = physicalActions.has(args.action);
69
+
70
+ return startJob({
71
+ immediate: true, // Keep legacy tools.call synchronous for existing integrations.
72
+ execute: job => nativeAction ? world.mutate('scene:native-activate', () =>
73
+ world.commands.activateEnvironmentInteraction(args.target, { actorId:args.actor, requireReach:true }))
74
+ : worldAction ? world.mutate('scene:world-action:' + args.action, () =>
75
+ world.commands.executeAffordance({
76
+ targetId:args.target, actorId:args.actor, action:args.action, args:args.args || {}
77
+ }, { approach:true }))
78
+ : physical ? world.mutate('scene:' + args.action, async () => {
79
+ const value = await world.interactions.manipulate(args.actor, args.target, args.action, args.args);
80
+ recordInteractionEvidence(world, {
81
+ targetId:args.target, capability:args.action.toUpperCase(), verified:value.verified,
82
+ source:'scene-api', commandId:job.id, result:value
83
+ });
84
+ return value;
85
+ }) : tools.call(skill, params),
86
+ settle: (value, job) => {
87
+ const activated = nativeAction && value.status === 'environment-interaction-activated';
88
+ const outcome = nativeAction
89
+ ? { state:value.verified === true ? 'verified' : activated ? 'unverified' : 'failed', verified:value.verified === true, physicsVerified:false }
90
+ : worldAction
91
+ ? { state:value.status === 'world-action-completed' && value.verified === true ? 'verified' : 'failed', verified:value.status === 'world-action-completed' && value.verified === true, physicsVerified:false }
92
+ : physical ? { state:value.verified ? 'verified' : 'failed', verified:value.verified === true }
93
+ : tools.executionPolicy(skill, value).outcome;
94
+ return {
95
+ status:outcome.verified || activated ? 'succeeded' : 'failed',
96
+ verification:{ status:!job.cancelled && outcome.verified ? 'verified' : 'unverified', evidence:value },
97
+ outcome
98
+ };
99
+ }
100
+ });
101
+ }
102
+
103
+ // Each capability declares an executor; only the legacy adapter translates
104
+ // historical action names. New Code Project, environment and joint names
105
+ // never need a new branch in the Scene dispatcher.
106
+ const invocationExecutors = new Map([
107
+ ['project-action', request => startProjectAction(request)],
108
+ ['world-action', request => {
109
+ if (!request.actor) throw sceneError('ACTOR_REQUIRED');
110
+ return startRuntimeCapability({ ...request, source:'environment' }, () =>
111
+ world.commands.executeAffordance({
112
+ targetId:request.target, actorId:request.actor, action:request.name, args:request.args
113
+ }, { approach:true }),
114
+ value => value?.status === 'world-action-completed' && value.verified === true);
115
+ }],
116
+ ['interaction', (request, capability) => startPhysicalCapability(request, capability)]
117
+ ]);
118
+
119
+ function startInvocation(request) {
120
+ const { capability } = resolveCapability(world, request);
121
+ const executor = invocationExecutors.get(capability.executor);
122
+ if (!executor) throw sceneError('ACTION_EXECUTOR_UNAVAILABLE');
123
+ return executor(request, capability);
124
+ }
125
+
126
+ function startPhysicalCapability(request, capability) {
127
+ const { target, name, actor, args = {} } = request;
128
+ if (!actor) throw sceneError('ACTOR_REQUIRED');
129
+ const record = world.store.get(target);
130
+ // Contract membership, not the verb, identifies a physically articulated
131
+ // action. This includes open/close and previously unknown semantic verbs.
132
+ const contract = capability.partName && world.interactions.interactionContracts(record).contracts.find(item =>
133
+ item.action === name && item.target.partName === capability.partName);
134
+ if (!contract) return controller.interact(legacyPhysicalRequest(request));
135
+ if (Object.keys(args).length) throw sceneError('ACTION_ARGUMENTS_UNSUPPORTED');
136
+ return startRuntimeCapability({ ...request, source:'asset' }, async () => {
137
+ const value = await world.commands.approachAndInteract(actor, target, name, { partName:capability.partName });
138
+ const verified = verifyInteractionResult(contract, { ...value, part:value.partName }).verified;
139
+ return { ...value, verified, physicsVerified:verified, evidenceKind:'joint-motor' };
140
+ }, value => value?.verified === true);
141
+ }
142
+
143
+ function startRuntimeCapability({ target, name, source }, execute, verify) {
144
+ return startJob({
145
+ execute: () => world.mutate('scene:invoke:' + name, execute),
146
+ settle: (value, job) => {
147
+ const verified = !job.cancelled && verify(value) === true;
148
+ if (verified) recordInteractionEvidence(world, {
149
+ targetId:target, capability:name.toUpperCase(), verified:true,
150
+ source: source === 'asset' ? 'physical-articulation' : 'environment',
151
+ commandId:job.id, result:value
152
+ });
153
+ return {
154
+ status:verified ? 'succeeded' : 'failed',
155
+ verification:{ status:verified ? 'verified' : 'unverified', evidence:value },
156
+ outcome:{ state:verified ? 'verified' : 'failed', verified,
157
+ physicsVerified:source === 'asset' && verified && value.physicsVerified === true }
158
+ };
159
+ }
160
+ });
161
+ }
162
+
163
+ function startProjectAction(args) {
164
+ return startJob({
165
+ abortable:true,
166
+ timeoutMs:world.projectCapabilities.timeoutFor(args.target, args.name),
167
+ execute:job => world.projectCapabilities.execute(args, { signal:job.controller.signal }),
168
+ settle:(value, job) => {
169
+ const verified = !job.cancelled && value.verified;
170
+ if (verified) recordInteractionEvidence(world, {
171
+ targetId:args.target, capability:args.name.toUpperCase(), verified:true,
172
+ source:'project-defined', commandId:job.id, result:value
173
+ });
174
+ onProjectAction();
175
+ return {
176
+ status:'succeeded',
177
+ verification:{ status:verified ? 'verified' : 'unverified', evidence:value.evidence },
178
+ outcome:{ state:job.cancelled ? 'unverified' : verified ? 'verified' : value.verificationRequested ? 'unverified' : 'accepted',
179
+ verified, physicsVerified:false }
180
+ };
181
+ }
182
+ });
183
+ }
184
+
185
+ function startJob({ execute, settle, timeoutMs = 60_000, abortable = false, immediate = false }) {
186
+ if (jobs.size >= 128) {
187
+ const terminal = [...jobs].find(([, item]) => item.status !== 'running');
188
+ if (terminal) jobs.delete(terminal[0]);
189
+ else throw sceneError('JOB_LIMIT');
190
+ }
191
+ const job = { id:'job_' + crypto.randomUUID(), status:'running', result:null };
192
+ if (abortable) job.controller = new AbortController();
193
+ jobs.set(job.id, job);
194
+ setBusy(true);
195
+ let pending;
196
+ try {
197
+ pending = immediate ? Promise.resolve(execute(job)) : Promise.resolve().then(() => execute(job));
198
+ } catch (error) {
199
+ pending = Promise.reject(error);
200
+ }
201
+ job.promise = pending.then(value => {
202
+ const completion = settle(value, job);
203
+ job.status = job.cancelled ? 'cancelled' : completion.status;
204
+ job.result = result('interact', value, { ...completion, status:job.status });
205
+ }).catch(error => {
206
+ job.status = job.cancelled ? 'cancelled' : 'failed';
207
+ job.result = result('interact', null, {
208
+ status:job.status,
209
+ ...(abortable ? { verification:{ status:'unverified', evidence:null } } : {}),
210
+ diagnostics:[diagnostic(error)]
211
+ });
212
+ }).finally(() => {
213
+ clearTimeout(job.timer);
214
+ setBusy(false);
215
+ });
216
+ if (timeoutMs != null) {
217
+ job.timer = setTimeout(() => controller.cancelJob(job.id), timeoutMs);
218
+ job.timer.unref?.();
219
+ }
220
+ return { id:job.id, status:job.status };
221
+ }
222
+
223
+ function getJob(key) {
224
+ const job = jobs.get(key);
225
+ if (!job) throw sceneError('JOB_NOT_FOUND');
226
+ return job;
227
+ }
228
+ return { ...controller, cancelPending };
229
+ }
@@ -0,0 +1,57 @@
1
+ import { sceneError } from './SceneContracts.js';
2
+
3
+ const REVISION_EVENTS = ['history.recorded', 'history.applied', 'scene.restored'];
4
+
5
+ /** Owns Scene API lifecycle state shared by mutation, jobs and persistence services. */
6
+ export function createSceneLifecycle(world) {
7
+ let busy = false;
8
+ let closed = false;
9
+ let revision = 0;
10
+ const unsubscribe = REVISION_EVENTS.map(event => world.events.on(event, () => { revision++; }));
11
+
12
+ const assertOpen = () => {
13
+ if (closed) throw sceneError('SCENE_CLOSED');
14
+ };
15
+ const assertIdle = () => {
16
+ assertOpen();
17
+ if (busy || world.mutationOwner) throw sceneError('SCENE_BUSY');
18
+ };
19
+ const exclusive = async operation => {
20
+ assertIdle();
21
+ busy = true;
22
+ try {
23
+ return await operation();
24
+ } finally {
25
+ busy = false;
26
+ }
27
+ };
28
+ const result = (operation, value, extra = {}) => ({
29
+ schema: 'agentscape.scene-result',
30
+ schemaVersion: 1,
31
+ operation,
32
+ status: 'succeeded',
33
+ revision,
34
+ admission: null,
35
+ verification: { status: 'not-requested', evidence: null },
36
+ diagnostics: [],
37
+ value,
38
+ ...extra
39
+ });
40
+
41
+ return {
42
+ getRevision: () => revision,
43
+ incrementRevision: () => { revision++; },
44
+ setBusy: value => { busy = value; },
45
+ assertOpen,
46
+ assertIdle,
47
+ exclusive,
48
+ result,
49
+ close() {
50
+ if (closed) return false;
51
+ assertIdle();
52
+ closed = true;
53
+ unsubscribe.forEach(fn => fn());
54
+ return true;
55
+ }
56
+ };
57
+ }
@@ -0,0 +1,162 @@
1
+ import * as z from 'zod/v4';
2
+ import { parseSceneProject } from './SceneProject.js';
3
+ import { assetDigest, canonicalAssetJson, assertEmbeddedGLB } from '../../modules/asset/model/AssetInputContracts.js';
4
+ import { assetManifests } from '../../modules/asset/registry/manifests/index.js';
5
+ import { createAssetModule } from '../../modules/asset/AssetModule.js';
6
+ import { stylePackSchema } from '../../modules/rendering/style/StylePack.js';
7
+ import { RUNTIME_VERSION } from '../../foundation/version.js';
8
+ import { ArticulationVerifier } from '../../modules/world/verification/ArticulationVerifier.js';
9
+ import { SceneObjectForge } from '../object-forge/SceneObjectForge.js';
10
+
11
+ const hash = z.string().regex(/^[a-f0-9]{64}$/);
12
+ const descriptor = z.object({ id: z.string().min(1).max(100), sha256: hash, bytes: z.string().max(45 * 1024 * 1024), definition: z.record(z.string(), z.unknown()) }).strict();
13
+ const schema = z.object({ schema: z.literal('agentscape.project-bundle'), schemaVersion: z.literal(1),
14
+ project: z.unknown(), snapshot: z.unknown(),
15
+ lock: z.object({ engine: z.enum(['1.34.2', RUNTIME_VERSION]), builtins: hash, content: hash }).strict(),
16
+ assets: z.array(descriptor).max(32),
17
+ editable: z.array(z.object({id:z.string(),assetId:z.string(),revision:z.number().int(),definition:z.unknown(),originAssetId:z.string().optional()}).strict()).max(64).optional(),
18
+ style: stylePackSchema.optional()
19
+ }).strict();
20
+ const builtinHash = () => assetDigest(new TextEncoder().encode(canonicalAssetJson(assetManifests)));
21
+ const encode = bytes => { let text = ''; for (let i = 0; i < bytes.length; i += 8192) text += String.fromCharCode(...bytes.subarray(i, i + 8192)); return btoa(text); };
22
+ const decode = text => {
23
+ if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(text)) throw new Error('INVALID_RESOURCE_ENCODING');
24
+ return Uint8Array.from(atob(text), c => c.charCodeAt(0));
25
+ };
26
+ const digestContent = value => assetDigest(new TextEncoder().encode(canonicalAssetJson(value)));
27
+ const definitionOf = manifest => Object.fromEntries(['type', 'label', 'actions', 'physics', 'parts', 'surfaces', 'receptacles', 'requiredNodes', 'interactionContract', 'capabilityLevel'].filter(key => manifest[key] != null).map(key => [key, structuredClone(manifest[key])]));
28
+
29
+ /** JSON transport for scene.json, lock, runtime snapshot and embedded resources.
30
+ * Directory/ZIP adapters can encode these same bytes without executing sources.
31
+ */
32
+ export async function exportRuntimeState(world, { name = 'Untitled World', readResource = null } = {}) {
33
+ if (world.mutationOwner) throw new Error('SCENE_BUSY');
34
+ const snapshot = world.serialize({ name }), assets = [], assetAliases = {};
35
+ let total = 0;
36
+ for (const manifest of snapshot.assets) {
37
+ let bytes;
38
+ if (manifest.source.kind === 'compiled') bytes = (await world.assetModule.compiledStore.get(manifest.source.key))?.bytes;
39
+ else if (readResource) bytes = await readResource(manifest.source.url, manifest.id);
40
+ else if (manifest.source.kind === 'glb') bytes = await world.assetModule.readAssetBytes(manifest.id);
41
+ if (!(bytes instanceof Uint8Array)) throw new Error('RESOURCE_UNAVAILABLE');
42
+ bytes = bytes.slice(); assertEmbeddedGLB(bytes);
43
+ total += bytes.length; if (total > 64 * 1024 * 1024) throw new Error('RESOURCE_LIMIT');
44
+ const sha256=await assetDigest(bytes),definition=definitionOf(manifest);
45
+ // Portable bundles own the compiled bytes; never write into immutable owner-global pa_ storage.
46
+ const portableId=/^pa_[a-f0-9]{64}$/.test(manifest.id)
47
+ ? 'asset_'+await assetDigest(new TextEncoder().encode(canonicalAssetJson({globalId:manifest.id,sha256,definition})))
48
+ : manifest.id;
49
+ assetAliases[manifest.id]=portableId;
50
+ assets.push({ id:portableId, sha256, bytes: encode(bytes), definition });
51
+ }
52
+ snapshot.objects=snapshot.objects.map(object=>({
53
+ ...object,assetId:assetAliases[object.assetId]||object.assetId
54
+ }));
55
+ snapshot.assets = [];
56
+ return { snapshot, assets, assetAliases };
57
+ }
58
+
59
+ /** Restore into a newly created code-project Runtime, retaining its native environment. */
60
+ export async function restoreRuntimeState(world, { snapshot, assets }) {
61
+ world.serializer.validate(snapshot);
62
+ if (snapshot.assets.length || snapshot.metadata?.environment !== world.environment.id || !Array.isArray(assets)) throw new Error('PROJECT_SNAPSHOT_MISMATCH');
63
+ const ids = new Set(), prepared = []; let total = 0;
64
+ for (const item of assets) {
65
+ if (ids.has(item.id) || assetManifests[item.id]?.source.kind === 'builtin') throw new Error('ASSET_ID_CONFLICT');
66
+ ids.add(item.id);
67
+ const bytes = decode(item.bytes); total += bytes.length;
68
+ if (total > 64 * 1024 * 1024 || await assetDigest(bytes) !== item.sha256) throw new Error('RESOURCE_INTEGRITY_MISMATCH');
69
+ assertEmbeddedGLB(bytes); prepared.push({ ...item, bytes });
70
+ }
71
+ for (const item of prepared) await world.assetModule.importPackageAsset(item);
72
+ await world.restore(snapshot);
73
+ }
74
+
75
+ export async function exportScenePackage(world, { name = 'Untitled World', readResource = null, style = null, editable = undefined } = {}) {
76
+ const { snapshot, assets, assetAliases } = await exportRuntimeState(world, { name, readResource });
77
+ const project = parseSceneProject({ schema: 'agentscape.scene-project', schemaVersion: 1, name,
78
+ environment: { type: 'builtin', id: world.environment.id },
79
+ ...(style ? { style: './styles/current/style.json' } : {}),
80
+ objects: snapshot.objects.map(object => ({ id: object.id,
81
+ asset: assets.some(a=>a.id===object.assetId) ? `./assets/${assets.findIndex(a => a.id === object.assetId)}/model.glb` : `builtin://${object.assetId}`,
82
+ level: assets.find(a=>a.id===object.assetId)?.definition.capabilityLevel
83
+ || (assets.some(a=>a.id===object.assetId) ? 'physical' : world.assetModule.getManifest(object.assetId).capabilityLevel || 'physical'),
84
+ transform: { ...object.transform, scale: object.transform.scale[0] } })) });
85
+ const localEditable=editable?.map(entry=>({...entry,assetId:assetAliases[entry.assetId]||entry.assetId}));
86
+ const checked = editable === undefined ? undefined : SceneObjectForge.validateTransfer(snapshot,localEditable);
87
+ const payload = { project, snapshot, assets, ...(style ? { style: stylePackSchema.parse(style) } : {}),
88
+ ...(checked !== undefined ? { editable:checked } : {}) };
89
+ const content = await digestContent(payload);
90
+ return { schema: 'agentscape.project-bundle', schemaVersion: 1, ...payload,
91
+ lock: { engine: RUNTIME_VERSION, builtins: await builtinHash(), content } };
92
+ }
93
+
94
+ /** Prepare entirely in a fresh Runtime. Failure never mutates the caller's world. */
95
+ /** @param {any} input @param {{container?: HTMLElement|null, assetModule?: any, codeExecutor?: any, codeGLTFLoader?: any, rendererMode?: 'auto'|'webgpu'|'webgl2'|'webgl-legacy', pixelRatioScale?: number}} options */
96
+ export async function openScenePackage(input, { container = null, assetModule = null, codeExecutor = null, codeGLTFLoader, rendererMode = 'auto', pixelRatioScale = 0.75 } = {}) {
97
+ if (typeof input === 'string') {
98
+ if (input.length > 96 * 1024 * 1024) throw new Error('DOCUMENT_LIMIT');
99
+ input = JSON.parse(input);
100
+ }
101
+ const bundle = schema.parse(structuredClone(input)), project = parseSceneProject(bundle.project);
102
+ if (bundle.lock.builtins !== await builtinHash() || bundle.lock.content !== await digestContent({ project: bundle.project, snapshot: bundle.snapshot, assets: bundle.assets, ...(bundle.style ? { style: bundle.style } : {}),...(bundle.editable !== undefined ? {editable:bundle.editable}: {}) })) throw new Error('PROJECT_INTEGRITY_MISMATCH');
103
+ if (Boolean(project.style) !== Boolean(bundle.style)) throw new Error('STYLE_DEPENDENCY_MISSING');
104
+ if (bundle.snapshot?.metadata?.stylePack && canonicalAssetJson(bundle.snapshot.metadata.stylePack) !== canonicalAssetJson(bundle.style)) throw new Error('STYLE_DEPENDENCY_MISMATCH');
105
+ if (!Array.isArray(bundle.snapshot?.objects) || bundle.snapshot.objects.length !== project.objects.length) throw new Error('PROJECT_SNAPSHOT_MISMATCH');
106
+ for (let index = 0; index < project.objects.length; index++) {
107
+ const object = project.objects[index], saved = bundle.snapshot.objects[index];
108
+ const assetIndex = bundle.assets.findIndex(asset => asset.id === saved.assetId);
109
+ const reference = assetIndex < 0 ? `builtin://${saved.assetId}` : `./assets/${assetIndex}/model.glb`;
110
+ if (object.id !== saved.id || object.asset !== reference || canonicalAssetJson(object.transform) !== canonicalAssetJson({ ...saved.transform, scale: saved.transform?.scale?.[0] })) throw new Error('PROJECT_SNAPSHOT_MISMATCH');
111
+ }
112
+ SceneObjectForge.validateTransfer(bundle.snapshot,bundle.editable || []);
113
+ const ids = new Set(); let total = 0;
114
+ const prepared = [];
115
+ for (const item of bundle.assets) {
116
+ if (ids.has(item.id) || assetManifests[item.id]?.source.kind === 'builtin') throw new Error('ASSET_ID_CONFLICT');
117
+ ids.add(item.id);
118
+ const bytes = decode(item.bytes); total += bytes.length;
119
+ if (total > 64 * 1024 * 1024 || await assetDigest(bytes) !== item.sha256) throw new Error('RESOURCE_INTEGRITY_MISMATCH');
120
+ assertEmbeddedGLB(bytes); prepared.push({ ...item, bytes });
121
+ }
122
+ const assets = assetModule || createAssetModule({ volatile: true, manifests: Object.fromEntries(Object.entries(assetManifests).filter(([id]) => !ids.has(id))), manifestStore: null, libraryStore: null });
123
+ assets.configureVerification({articulationVerifier:new ArticulationVerifier({assetRegistry:assets.registry,assetLoader:assets.loader})});
124
+ for (const item of prepared) {
125
+ await assets.importPackageAsset(item);
126
+ }
127
+ const { openScene } = await import('./SceneFacade.js');
128
+ const scene = await openScene({ container, assetModule: assets, codeExecutor, codeGLTFLoader, rendererMode, pixelRatioScale, project: { ...project, objects: [], style: undefined } });
129
+ try { await scene.restoreSnapshot(bundle.snapshot, { prepared: true }); if (bundle.style) await scene.setStyle(bundle.style); return scene; }
130
+ catch (error) { scene.close(); throw error; }
131
+ }
132
+
133
+ /** Validate in an isolated session, then reuse Runtime's own transactional restore. */
134
+ export async function importScenePackageInto(world, input, { applyStyle, getStyle } = {}) {
135
+ const bundle = schema.parse(structuredClone(typeof input === 'string' ? JSON.parse(input) : input));
136
+ const ids = new Set(bundle.assets.map(asset => asset.id));
137
+ const assets = createAssetModule({ volatile: true, manifests: Object.fromEntries(Object.entries(assetManifests).filter(([id]) => !ids.has(id))), manifestStore: null, libraryStore: null });
138
+ if (world.rendering?.renderer) assets.configureRenderer(world.rendering.renderer);
139
+ let staged;
140
+ try {
141
+ staged = await openScenePackage(bundle, { assetModule: assets });
142
+ if (bundle.project.environment.id !== world.environment.id) throw new Error('ENVIRONMENT_MISMATCH');
143
+ SceneObjectForge.validateTransfer(bundle.snapshot,bundle.editable||[]);
144
+ const snapshot = staged.snapshot(), entries = [];
145
+ if (bundle.snapshot.camera) snapshot.camera = structuredClone(bundle.snapshot.camera);
146
+ for (const asset of bundle.assets) {
147
+ const manifest = assets.getManifest(asset.id), stored = await assets.compiledStore.get(manifest.source.key);
148
+ entries.push({ manifest, bytes: stored.bytes, expectedSourceHash: asset.sha256, expectedDefinition: asset.definition });
149
+ }
150
+ const previousStyle = getStyle?.() || null;
151
+ return await world.assetModule.installPreparedAssets(entries, async () => {
152
+ snapshot.assets = snapshot.assets.map(manifest => world.assetModule.getManifest(manifest.id));
153
+ try {
154
+ return await world.mutate('scene:import-project', async () => {
155
+ await world.restoreSnapshot(snapshot);
156
+ await applyStyle?.(bundle.style || null);
157
+ return { status: 'project-imported', objects: snapshot.objects.length, editable:bundle.editable||[] };
158
+ });
159
+ } catch (error) { await applyStyle?.(previousStyle); throw error; }
160
+ });
161
+ } finally { staged?.close(); assets.loader.gltfLoader.dispose?.(); }
162
+ }
@@ -0,0 +1,50 @@
1
+ import { sceneObjectIdSchema as id } from './SceneProject.js';
2
+ import { sceneError } from './SceneContracts.js';
3
+
4
+ /** Scene snapshots, project packages and content-addressed world archives. */
5
+ export function createScenePersistence(world, { name, styles, assertIdle, exclusive, result }) {
6
+ return {
7
+ snapshot() { assertIdle(); return world.serialize({ name }); },
8
+ async save(options = {}) {
9
+ return exclusive(async () => {
10
+ const { exportScenePackage } = await import('./ScenePackage.js');
11
+ return result('save', await exportScenePackage(world, { ...options, name, style: styles.export() }));
12
+ });
13
+ },
14
+ /** Bounded streaming world archive; storage is an injected hash-block backend. */
15
+ async exportWorld(storage, writer, options = {}) {
16
+ return exclusive(async () => {
17
+ const { exportWorld } = await import('./WorldIO.js');
18
+ return result('exportWorld', await exportWorld(world, storage, writer, { name, ...options }));
19
+ });
20
+ },
21
+ async prepareWorld(storage, root, options = {}) {
22
+ assertIdle();
23
+ const { prepareWorld } = await import('./WorldIO.js');
24
+ const prepared = await prepareWorld(storage, root, { active:'bounded', ...options });
25
+ // Never expose the private Runtime simply to commit a validated world.
26
+ return { summary:prepared.summary, commit:()=>exclusive(()=>prepared.commit(world)), dispose:()=>prepared.dispose() };
27
+ },
28
+ async importWorld(storage, source, options = {}) {
29
+ return exclusive(async () => {
30
+ const { importWorld } = await import('./WorldIO.js');
31
+ return result('importWorld', await importWorld(world, storage, source, { active:'bounded', ...options }));
32
+ });
33
+ },
34
+ async restoreSnapshot(snapshot, { prepared = false } = {}) {
35
+ return exclusive(async () => {
36
+ const copy = structuredClone(snapshot); world.serializer.validate(copy);
37
+ if (copy.assets.length || (!prepared && (copy.configuration?.behaviorBundle || copy.configuration?.physicsRequirements || copy.metadata?.environmentState || copy.metadata?.worldRevision))) throw sceneError('UNSUPPORTED_SAVE');
38
+ for (const object of copy.objects) { id.parse(object.id); if (!world.assetModule.hasAsset(object.assetId)) throw sceneError('ASSET_UNAVAILABLE'); }
39
+ await world.restore(copy); return result('restore', { objects: copy.objects.length });
40
+ });
41
+ },
42
+ async setStyle(input, options = {}) { return exclusive(async () => result('setStyle', await styles.set(input, options))); },
43
+ async importProject(input) {
44
+ return exclusive(async () => {
45
+ const { importScenePackageInto } = await import('./ScenePackage.js');
46
+ return result('importProject', await importScenePackageInto(world, input, { getStyle: () => styles.export(), applyStyle: pack => pack ? styles.set(pack) : styles.clear() }));
47
+ });
48
+ },
49
+ };
50
+ }
@@ -0,0 +1,95 @@
1
+ import * as z from 'zod/v4';
2
+ import { BUILTIN_ENVIRONMENT_IDS } from '../../modules/world/content/environments.js';
3
+
4
+ export const sceneObjectIdSchema = z.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/);
5
+ export const sceneVector3Schema = z.tuple([z.number().finite().min(-10000).max(10000), z.number().finite().min(-10000).max(10000), z.number().finite().min(-10000).max(10000)]);
6
+ const quaternionSchema = z.tuple([z.number().finite(), z.number().finite(), z.number().finite(), z.number().finite()])
7
+ .refine(value => Math.abs(Math.hypot(...value) - 1) < 0.0001, 'Quaternion must be normalized');
8
+ const scaleSchema = z.number().finite().min(0.05).max(20);
9
+ export const sceneTransformSchema = z.object({
10
+ position: sceneVector3Schema.default(() => [0, 0, 0]),
11
+ quaternion: quaternionSchema.default(() => [0, 0, 0, 1]),
12
+ scale: scaleSchema.default(1)
13
+ }).strict();
14
+ const builtinAssetSchema = z.string().regex(/^builtin:\/\/[a-zA-Z][a-zA-Z0-9_-]{0,63}$/);
15
+ // Portable package paths only. No URL decoding, drive paths, ADS or traversal.
16
+ export const sceneResourcePathSchema = z.string().max(240).refine(value => {
17
+ if (!value.startsWith('./')) return false;
18
+ return value.slice(2).split('/').every(part =>
19
+ /^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/.test(part) && !part.endsWith('.') &&
20
+ !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part));
21
+ }, 'Expected a portable project-relative resource path');
22
+ export const sceneAssetRefSchema = z.union([builtinAssetSchema, z.string().regex(/^asset:\/\/sha256\/[a-f0-9]{64}$/), sceneResourcePathSchema]);
23
+ const sceneObjectSchema = z.object({
24
+ id: sceneObjectIdSchema,
25
+ asset: sceneAssetRefSchema,
26
+ level: z.enum(['visual', 'physical', 'interactive']),
27
+ transform: sceneTransformSchema.default(() => ({ position: [0, 0, 0], quaternion: [0, 0, 0, 1], scale: 1 }))
28
+ }).strict();
29
+ export const sceneProjectSchema = z.object({
30
+ schema: z.literal('agentscape.scene-project'),
31
+ schemaVersion: z.literal(1),
32
+ name: z.string().trim().min(1).max(100),
33
+ environment: z.object({ type: z.literal('builtin'), id: z.enum(BUILTIN_ENVIRONMENT_IDS) }).strict(),
34
+ style: sceneAssetRefSchema.optional(),
35
+ objects: z.array(sceneObjectSchema)
36
+ }).strict().superRefine((project, ctx) => {
37
+ const used = new Set();
38
+ for (let index = 0; index < project.objects.length; index++) {
39
+ const id = project.objects[index].id;
40
+ if (used.has(id)) ctx.addIssue({ code: 'custom', path: ['objects', index, 'id'], message: 'Duplicate scene object ID' });
41
+ used.add(id);
42
+ }
43
+ });
44
+
45
+ export function parseSceneProject(input) {
46
+ if (typeof input === 'string') {
47
+ if (new TextEncoder().encode(input).byteLength > 256 * 1024) throw projectError('DOCUMENT_LIMIT');
48
+ try { input = JSON.parse(input); } catch { throw projectError('INVALID_DOCUMENT'); }
49
+ }
50
+ if (input?.schema === 'agentscape.scene-project' && input.schemaVersion !== 1) throw projectError('UNSUPPORTED_VERSION');
51
+ const result = sceneProjectSchema.safeParse(input);
52
+ if (!result.success) throw projectError('INVALID_DOCUMENT', result.error.issues.map(issue => ({ path: issue.path, message: issue.message })));
53
+ return result.data;
54
+ }
55
+
56
+ function projectError(code, diagnostics = []) {
57
+ return Object.assign(new Error(code), { code, diagnostics });
58
+ }
59
+
60
+ /** Resolve an already extracted, bounded package of bytes. Never opens host files or URLs.
61
+ * Filesystem/archive adapters must reject links before constructing this Map.
62
+ * This is dependency resolution only, not asset admission or Runtime installation.
63
+ */
64
+ export async function resolveSceneProject(input, { resources = new Map(), builtins = new Map() } = {}) {
65
+ const project = parseSceneProject(input);
66
+ if (!(resources instanceof Map) || !(builtins instanceof Map) || resources.size > 128) throw projectError('INVALID_RESOURCES');
67
+ let total = 0;
68
+ const names = new Set();
69
+ const bytes = new Map();
70
+ for (const [path, value] of resources) {
71
+ if (!sceneResourcePathSchema.safeParse(path).success || names.has(path.toLowerCase())) throw projectError('INVALID_RESOURCE_PATH');
72
+ names.add(path.toLowerCase());
73
+ if (!(value instanceof Uint8Array)) throw projectError('INVALID_RESOURCES');
74
+ total += value.byteLength;
75
+ if (value.byteLength > 32 * 1024 * 1024 || total > 64 * 1024 * 1024) throw projectError('RESOURCE_LIMIT');
76
+ bytes.set(path, value.slice());
77
+ }
78
+ const refs = new Set([`builtin://${project.environment.id}`, ...project.objects.map(object => object.asset), ...(project.style ? [project.style] : [])]);
79
+ const dependencies = [];
80
+ for (const ref of refs) {
81
+ let sha256;
82
+ if (ref.startsWith('builtin://') || ref.startsWith('asset://')) {
83
+ // The host supplies hashes from its versioned built-in resource catalog.
84
+ sha256 = builtins.get(ref);
85
+ if (!/^[a-f0-9]{64}$/.test(sha256 ?? '')) throw projectError('RESOURCE_UNAVAILABLE');
86
+ } else {
87
+ const data = bytes.get(ref);
88
+ if (!data) throw projectError('RESOURCE_UNAVAILABLE');
89
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', data);
90
+ sha256 = Array.from(new Uint8Array(digest), value => value.toString(16).padStart(2, '0')).join('');
91
+ }
92
+ dependencies.push({ ref, sha256 });
93
+ }
94
+ return { project, dependencies };
95
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The Scene API skills kept for the existing Studio tool surface.
3
+ * Keep names independent of SceneFacade construction and the runtime systems.
4
+ */
5
+ export const SCENE_LEGACY_SKILLS = Object.freeze(['spawnAsset', 'moveObject', 'rotateObject', 'scaleObject', 'transformObject', 'removeObject', 'duplicateObject', 'replaceAsset', 'navigateTo', 'approachAndInteract', 'approachAndPickup', 'approachAndPlace', 'evaluateWorldAcceptance', 'pickup', 'drop', 'place', 'open', 'close', 'dropHeld']);