agentscape3d-engine 0.0.0-stage → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js +337 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js.map +1 -0
- package/dist/AssetCompiler-BLj09iu1.js +2424 -0
- package/dist/AssetCompiler-BLj09iu1.js.map +1 -0
- package/dist/AssetModule-DME-XaFS.js +2637 -0
- package/dist/AssetModule-DME-XaFS.js.map +1 -0
- package/dist/AssetRecipe-g8dZBhgJ.js +298 -0
- package/dist/AssetRecipe-g8dZBhgJ.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53856 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/CarryCapability-CXwHU5ay.js +104 -0
- package/dist/CarryCapability-CXwHU5ay.js.map +1 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js +241 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js.map +1 -0
- package/dist/ObjectTransform-BlQUNK7c.js +61 -0
- package/dist/ObjectTransform-BlQUNK7c.js.map +1 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js +3259 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js.map +1 -0
- package/dist/RenderingSystem-WIr1ZuGu.js +1042 -0
- package/dist/RenderingSystem-WIr1ZuGu.js.map +1 -0
- package/dist/ScenePresentation-LsYiDxbm.js +152 -0
- package/dist/ScenePresentation-LsYiDxbm.js.map +1 -0
- package/dist/SceneProject-K7HH1s8o.js +2687 -0
- package/dist/SceneProject-K7HH1s8o.js.map +1 -0
- package/dist/SceneSerializer-zOzbX4jZ.js +932 -0
- package/dist/SceneSerializer-zOzbX4jZ.js.map +1 -0
- package/dist/SimulationProfile-DSYZbBLQ.js +165 -0
- package/dist/SimulationProfile-DSYZbBLQ.js.map +1 -0
- package/dist/StylePack-DcRa_kU0.js +88 -0
- package/dist/StylePack-DcRa_kU0.js.map +1 -0
- package/dist/WorldArchive-BiFGLt--.js +451 -0
- package/dist/WorldArchive-BiFGLt--.js.map +1 -0
- package/dist/WorldCommands-Debj7V4L.js +2207 -0
- package/dist/WorldCommands-Debj7V4L.js.map +1 -0
- package/dist/WorldIO-Ch8QBfKY.js +151 -0
- package/dist/WorldIO-Ch8QBfKY.js.map +1 -0
- package/dist/admission-CVEvsrdz.js +121 -0
- package/dist/admission-CVEvsrdz.js.map +1 -0
- package/dist/blankWorld-B0MW6g7q.js +75 -0
- package/dist/blankWorld-B0MW6g7q.js.map +1 -0
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/disposeObject3D-DIMzy0FA.js +128 -0
- package/dist/disposeObject3D-DIMzy0FA.js.map +1 -0
- package/dist/environments-HOe3sJXH.js +567 -0
- package/dist/environments-HOe3sJXH.js.map +1 -0
- package/dist/gltfIO-BzVKLyaL.js +339 -0
- package/dist/gltfIO-BzVKLyaL.js.map +1 -0
- package/dist/grandUrbanBlock-DRndRZjF.js +515 -0
- package/dist/grandUrbanBlock-DRndRZjF.js.map +1 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +16952 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-CfBZjx2Q.js +11019 -0
- package/dist/magicCabin-CfBZjx2Q.js.map +1 -0
- package/dist/manifests-D0LwbJ36.js +866 -0
- package/dist/manifests-D0LwbJ36.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-awZiGtda.js +403 -0
- package/dist/monumentHall-awZiGtda.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/parts-DrEcfJRl.js +37 -0
- package/dist/parts-DrEcfJRl.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js +696 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js.map +1 -0
- package/dist/runtime/application/AgentTools.js +28 -0
- package/dist/runtime/application/README.md +14 -0
- package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
- package/dist/runtime/application/agent/StudioMcpAllowlist.js +10 -0
- package/dist/runtime/application/agent/StudioProjectTools.js +18 -0
- package/dist/runtime/application/agent/TaskEvidence.js +199 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +50 -0
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +82 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +630 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +215 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +289 -0
- package/dist/runtime/application/native-scene/CodeProject.js +215 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +143 -0
- package/dist/runtime/application/native-scene/ExampleWorldCatalog.js +35 -0
- package/dist/runtime/application/native-scene/NativeArticulation.js +53 -0
- package/dist/runtime/application/native-scene/NativeEditableRegistry.js +150 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +85 -0
- package/dist/runtime/application/native-scene/NativeLightingInspection.js +33 -0
- package/dist/runtime/application/native-scene/NativeMaterialInspection.js +52 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativePhysicsGeometry.js +64 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +406 -0
- package/dist/runtime/application/native-scene/NativeSceneInspection.js +203 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeSceneQuery.js +123 -0
- package/dist/runtime/application/native-scene/NativeSceneReview.js +132 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/native-scene/SceneObserver.js +97 -0
- package/dist/runtime/application/native-scene/VisualCapturePolicy.js +4 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +263 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
- package/dist/runtime/application/scene/CapabilityResolver.js +90 -0
- package/dist/runtime/application/scene/NativeEditableContracts.js +18 -0
- package/dist/runtime/application/scene/RequestWindow.js +54 -0
- package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
- package/dist/runtime/application/scene/SceneContracts.js +49 -0
- package/dist/runtime/application/scene/SceneEditService.js +154 -0
- package/dist/runtime/application/scene/SceneFacade.js +356 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +41 -0
- package/dist/runtime/application/scene/SceneJobController.js +320 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +173 -0
- package/dist/runtime/application/scene/ScenePersistence.js +50 -0
- package/dist/runtime/application/scene/SceneProject.js +95 -0
- package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
- package/dist/runtime/application/scene/StarterScene.js +56 -0
- package/dist/runtime/application/scene/WorldArchive.js +89 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +76 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +155 -0
- package/dist/runtime/application/skills/SkillRegistry.js +193 -0
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
- package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
- package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
- package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
- package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
- package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
- package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
- package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
- package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
- package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
- package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
- package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
- package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
- package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
- package/dist/runtime/application/skills/skillPrimitives.js +4 -0
- package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
- package/dist/runtime/application/tasks.jsonl +67 -0
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +92 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/application/world-authoring/SceneGLBExport.js +88 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +68 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +157 -0
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
- package/dist/runtime/apps/mcp-server/README.md +269 -0
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
- package/dist/runtime/apps/mcp-server/SessionManager.js +148 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +75 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +246 -0
- package/dist/runtime/apps/mcp-server/StudioProjectToolContracts.js +58 -0
- package/dist/runtime/apps/mcp-server/TransferHttp.js +47 -0
- package/dist/runtime/apps/mcp-server/TransferLimits.js +6 -0
- package/dist/runtime/apps/mcp-server/TransferStore.js +134 -0
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
- package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
- package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
- package/dist/runtime/apps/mcp-server/main.mjs +82 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +274 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +23 -0
- package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
- package/dist/runtime/apps/server/README.md +7 -0
- package/dist/runtime/apps/server/WorldRepository.js +338 -0
- package/dist/runtime/apps/server/WorldRepositoryHttp.js +96 -0
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
- package/dist/runtime/apps/server/tasks.jsonl +10 -0
- package/dist/runtime/apps/shared/node/WorldDiskStorage.js +62 -0
- package/dist/runtime/foundation/EventBus.js +26 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -0
- package/dist/runtime/foundation/PngRgba.js +99 -0
- package/dist/runtime/foundation/PolicyEngine.js +21 -0
- package/dist/runtime/foundation/README.md +7 -0
- package/dist/runtime/foundation/TraceRecorder.js +76 -0
- package/dist/runtime/foundation/errors.js +8 -0
- package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
- package/dist/runtime/foundation/version.js +2 -0
- package/dist/runtime/modules/agent/README.md +11 -0
- package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
- package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
- package/dist/runtime/modules/agent/prompt/index.js +52 -0
- package/dist/runtime/modules/agent/tasks.jsonl +94 -0
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
- package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
- package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
- package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
- package/dist/runtime/modules/artifact/README.md +7 -0
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
- package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
- package/dist/runtime/modules/asset/AssetModule.js +416 -0
- package/dist/runtime/modules/asset/README.md +67 -0
- package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +139 -0
- package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
- package/dist/runtime/modules/asset/model/ProceduralTextureContract.js +24 -0
- package/dist/runtime/modules/asset/model/admission.js +117 -0
- package/dist/runtime/modules/asset/model/errors.js +6 -0
- package/dist/runtime/modules/asset/model/parts.js +27 -0
- package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
- package/dist/runtime/modules/asset/model/schema.js +150 -0
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
- package/dist/runtime/modules/asset/production/AssetRecipe.js +91 -0
- package/dist/runtime/modules/asset/production/ProceduralTexture.js +85 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
- package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
- package/dist/runtime/modules/asset/tasks.jsonl +87 -0
- package/dist/runtime/modules/generation/README.md +9 -0
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
- package/dist/runtime/modules/generation/tasks.jsonl +35 -0
- package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +263 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +660 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +414 -0
- package/dist/runtime/modules/rendering/README.md +7 -0
- package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
- package/dist/runtime/modules/rendering/captureStill.js +54 -0
- package/dist/runtime/modules/rendering/createRenderer.js +76 -0
- package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
- package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
- package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
- package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
- package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
- package/dist/runtime/modules/world/README.md +13 -0
- package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
- package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
- package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
- package/dist/runtime/modules/world/content/blankWorld.js +35 -0
- package/dist/runtime/modules/world/content/environments.js +84 -0
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
- package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
- package/dist/runtime/modules/world/content/magicCabin.js +190 -0
- package/dist/runtime/modules/world/content/monumentHall.js +154 -0
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
- package/dist/runtime/modules/world/errors.js +9 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
- package/dist/runtime/modules/world/runtime/CommandHistory.js +111 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +165 -0
- package/dist/runtime/modules/world/runtime/NativeNavigationGeometry.js +84 -0
- package/dist/runtime/modules/world/runtime/NativePhysicsSnapshot.js +245 -0
- package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +240 -0
- package/dist/runtime/modules/world/runtime/SceneExtensions.js +36 -0
- package/dist/runtime/modules/world/runtime/ScenePresentation.js +101 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +281 -0
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
- package/dist/runtime/modules/world/runtime/WorldCommands.js +503 -0
- package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
- package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +806 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +110 -0
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +390 -0
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +244 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +147 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/ManipulationActions.js +7 -0
- package/dist/runtime/modules/world/runtime/interaction/NativePhysicalTarget.js +31 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +134 -0
- package/dist/runtime/modules/world/runtime/semantic/NativePhysicsState.js +89 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +129 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +104 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/simulation/WorldTimeline.js +110 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/spatial/VisualMeshBounds.js +41 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +306 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +39 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +806 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +281 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +561 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1752 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +527 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +402 -0
- package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
- package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
- package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
- package/dist/runtime/modules/world/tasks.jsonl +530 -0
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
- package/dist/runtime/modules/world/verification/Finding.js +105 -0
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +73 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/VisualLayoutAcceptance.js +58 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +176 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +67 -0
- package/dist/runtime/package-lock.json +16071 -0
- package/dist/runtime/package.json +106 -0
- package/dist/runtime/public/assets/cabinet.glb +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
- package/dist/schema-DT7K9NjP.js +165 -0
- package/dist/schema-DT7K9NjP.js.map +1 -0
- package/dist/suzhouGarden-Y3hny8j6.js +6150 -0
- package/dist/suzhouGarden-Y3hny8j6.js.map +1 -0
- package/dist/version-CHc-i8ch.js +5 -0
- package/dist/version-CHc-i8ch.js.map +1 -0
- package/dist/woodlandWorkshop-DsScU-cx.js +483 -0
- package/dist/woodlandWorkshop-DsScU-cx.js.map +1 -0
- package/dist/yuanmingyuan-DsFnPzzR.js +4955 -0
- package/dist/yuanmingyuan-DsFnPzzR.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { recordInteractionEvidence,clearInteractionEvidenceForTarget } 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, quarantine, 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
|
+
const job = getJob(key);
|
|
31
|
+
if(job.status!=='quarantined')assertOpen();
|
|
32
|
+
return structuredClone({ id: job.id, status: job.status, result: job.result });
|
|
33
|
+
},
|
|
34
|
+
async waitJob(key) {
|
|
35
|
+
const job = getJob(key);
|
|
36
|
+
if(job.status!=='quarantined')assertOpen();
|
|
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 && !job.graceTimer) {
|
|
47
|
+
job.graceTimer=setTimeout(()=>{
|
|
48
|
+
if(job.status!=='running')return;
|
|
49
|
+
quarantine?.();
|
|
50
|
+
job.status='quarantined';
|
|
51
|
+
job.result=result('interact',null,{status:job.status,mutation:'unknown',verification:{status:'unverified'},diagnostics:[{code:'PROJECT_RUNTIME_QUARANTINED'}]});
|
|
52
|
+
job.releaseWaiter();
|
|
53
|
+
},250);
|
|
54
|
+
job.graceTimer.unref?.();
|
|
55
|
+
}
|
|
56
|
+
if (!job.controller) cancelPending();
|
|
57
|
+
}
|
|
58
|
+
return { id: job.id, status: job.status, cancellationRequested: Boolean(job.cancelled) };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// The historical intent-based API continues to use its existing runtime
|
|
63
|
+
// commands, actor checks, policy and verification semantics unchanged.
|
|
64
|
+
function startLegacyAction(args) {
|
|
65
|
+
const nativeAction = args.action === 'activate';
|
|
66
|
+
if (nativeAction && !actors().agents.some(agent => agent.id === args.actor)) throw sceneError('ACTOR_NOT_AGENT');
|
|
67
|
+
if (nativeAction && !world.environment?.interactions?.some(item =>
|
|
68
|
+
item.id === args.target && typeof item.activate === 'function')) throw sceneError('INTERACTION_UNAVAILABLE');
|
|
69
|
+
const contract = 'target' in args ? world.affordances?.get?.(args.target) : null;
|
|
70
|
+
const worldAction = Boolean(contract) && !nativeAction;
|
|
71
|
+
if (worldAction && !contract.actions.includes(args.action)) throw sceneError('ACTION_UNSUPPORTED');
|
|
72
|
+
if (!contract && ['turn_on', 'turn_off', 'pull_out', 'return', 'write'].includes(args.action)) throw sceneError('ACTION_UNSUPPORTED');
|
|
73
|
+
|
|
74
|
+
const [skill, params] = args.action === 'navigate' ? ['navigateTo', { id:args.actor, end:args.position }]
|
|
75
|
+
: args.action === 'pickup' ? ['approachAndPickup', { actorId:args.actor, targetId:args.target }]
|
|
76
|
+
: args.action === 'place' ? ['approachAndPlace', { actorId:args.actor, supportId:args.target, surfaceId:args.surfaceId }]
|
|
77
|
+
: ['approachAndInteract', { actorId:args.actor, targetId:args.target, action:args.action, partName:args.partName }];
|
|
78
|
+
const physical = physicalActions.has(args.action);
|
|
79
|
+
const nativePhysical=physical&&world.entities?.get(args.target)?.source==='native';
|
|
80
|
+
const heldId=world.interactions?.heldByAgent?.(args.actor);
|
|
81
|
+
const nativeTarget=world.entities?.get(args.target)?.source==='native';
|
|
82
|
+
const nativeHeld=world.entities?.get(heldId)?.source==='native';
|
|
83
|
+
const nativeCarry=(args.action==='pickup'&&nativeTarget)||
|
|
84
|
+
(args.action==='place'&&(nativeTarget||nativeHeld))||
|
|
85
|
+
(['navigate','drop'].includes(args.action)&&nativeHeld);
|
|
86
|
+
if(args.action==='drop'&&!nativeCarry)throw sceneError('ACTION_UNSUPPORTED');
|
|
87
|
+
if(nativeCarry)return startNativeCarry(args,heldId);
|
|
88
|
+
|
|
89
|
+
return startJob({
|
|
90
|
+
immediate: true, // Keep legacy tools.call synchronous for existing integrations.
|
|
91
|
+
execute: job => nativeAction ? world.mutate('scene:native-activate', () =>
|
|
92
|
+
world.commands.activateEnvironmentInteraction(args.target, { actorId:args.actor, requireReach:true }))
|
|
93
|
+
: worldAction ? world.mutate('scene:world-action:' + args.action, () =>
|
|
94
|
+
world.commands.executeAffordance({
|
|
95
|
+
targetId:args.target, actorId:args.actor, action:args.action, args:args.args || {}
|
|
96
|
+
}, { approach:true }))
|
|
97
|
+
: nativePhysical ? nativeMutation('scene:native-physics:'+args.action,async()=>{
|
|
98
|
+
clearInteractionEvidenceForTarget(world,args.target,{source:'native-physics',capability:args.action,partName:args.args?.part});
|
|
99
|
+
const value=await world.interactions.manipulate(args.actor,args.target,args.action,args.args);
|
|
100
|
+
if(!job.cancelled&&value.verified)recordInteractionEvidence(world,{targetId:args.target,
|
|
101
|
+
capability:args.action.toUpperCase(),verified:true,source:'native-physics',commandId:job.id,result:value,partName:args.args?.part});
|
|
102
|
+
return {...value,source:'native-physics'};
|
|
103
|
+
}) : physical ? world.mutate('scene:' + args.action, async () => {
|
|
104
|
+
const value = await world.interactions.manipulate(args.actor, args.target, args.action, args.args);
|
|
105
|
+
recordInteractionEvidence(world, {
|
|
106
|
+
targetId:args.target, capability:args.action.toUpperCase(), verified:value.verified,
|
|
107
|
+
source:'scene-api', commandId:job.id, result:value
|
|
108
|
+
});
|
|
109
|
+
return value;
|
|
110
|
+
}) : tools.call(skill, params),
|
|
111
|
+
settle: (value, job) => {
|
|
112
|
+
const activated = nativeAction && value.status === 'environment-interaction-activated';
|
|
113
|
+
const outcome = nativeAction
|
|
114
|
+
? { state:value.verified === true ? 'verified' : activated ? 'unverified' : 'failed', verified:value.verified === true, physicsVerified:false }
|
|
115
|
+
: worldAction
|
|
116
|
+
? { state:value.status === 'world-action-completed' && value.verified === true ? 'verified' : 'failed', verified:value.status === 'world-action-completed' && value.verified === true, physicsVerified:false }
|
|
117
|
+
: physical ? { state:!job.cancelled&&value.verified ? 'verified' : 'failed', verified:!job.cancelled&&value.verified === true,
|
|
118
|
+
...(nativePhysical?{physicsVerified:!job.cancelled&&value.physicsVerified===true}:{}) }
|
|
119
|
+
: tools.executionPolicy(skill, value).outcome;
|
|
120
|
+
return {
|
|
121
|
+
status:outcome.verified || activated ? 'succeeded' : 'failed',
|
|
122
|
+
verification:{ status:!job.cancelled && outcome.verified ? 'verified' : 'unverified', evidence:value },
|
|
123
|
+
outcome
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function nativeMutation(label,execute){
|
|
130
|
+
const before=world.history.undoStack.at(-1);
|
|
131
|
+
try{
|
|
132
|
+
const value=await world.mutate(label,execute);
|
|
133
|
+
const recorded=world.history.undoStack.at(-1)!==before;
|
|
134
|
+
return {...value,historyRecorded:recorded};
|
|
135
|
+
}finally{
|
|
136
|
+
if(world.history.undoStack.at(-1)===before)onProjectAction();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function startNativeCarry(args,heldId){
|
|
141
|
+
const {actor,target,action}=args;
|
|
142
|
+
const receiptTarget=action==='navigate'?heldId:target;
|
|
143
|
+
const receiptCapability=action==='navigate'?'CARRY':action.toUpperCase();
|
|
144
|
+
return startJob({
|
|
145
|
+
execute:job=>nativeMutation('scene:native-carry:'+action,async()=>{
|
|
146
|
+
clearInteractionEvidenceForTarget(world,receiptTarget,{source:'native-physics',capability:receiptCapability});
|
|
147
|
+
if(job.cancelled)return {status:'cancelled',verified:false};
|
|
148
|
+
let value,verified=false,physicsVerified=false;
|
|
149
|
+
if(action==='pickup'){
|
|
150
|
+
value=await world.interactions.approachAndPickup(actor,target);
|
|
151
|
+
verified=value.status==='held'&&world.interactions.heldByAgent(actor)===target&&world.physics.manipulationBody(target).body==='kinematic';
|
|
152
|
+
}else if(action==='navigate'){
|
|
153
|
+
value=await world.locomotion.navigate(actor,args.position);
|
|
154
|
+
const carry=world.interactions.carryStatus(actor);
|
|
155
|
+
const anchor=world.physics.anchorPose(actor,world.interactions.holdAnchor(actor));
|
|
156
|
+
const position=world.physics.getPosition(heldId);
|
|
157
|
+
const anchorError=anchor&&position?Math.hypot(...position.map((n,i)=>n-anchor.position[i])):null;
|
|
158
|
+
verified=value.status==='arrived'&&carry.targetId===heldId&&anchorError!=null&&anchorError<=.12;
|
|
159
|
+
value={...value,actorId:actor,heldId,carry,anchorError,evidenceKind:'kinematic-anchor'};
|
|
160
|
+
}else if(action==='place'){
|
|
161
|
+
value=await world.interactions.approachAndPlace(actor,target,{surfaceId:args.surfaceId});
|
|
162
|
+
verified=value.status==='placed'&&value.settled===true&&value.supportVerified===true&&value.support?.contactVerified===true;
|
|
163
|
+
physicsVerified=verified;
|
|
164
|
+
}else if(action==='drop'){
|
|
165
|
+
if(heldId!==target)throw sceneError('NOT_HOLDING_OBJECT');
|
|
166
|
+
value=await world.interactions.dropHeld(actor);
|
|
167
|
+
verified=value.status==='dropped'&&value.released===true&&value.settled===true;
|
|
168
|
+
physicsVerified=verified;
|
|
169
|
+
}
|
|
170
|
+
verified=verified&&!job.cancelled;physicsVerified=physicsVerified&&verified;
|
|
171
|
+
const evidenceKind=action==='place'?'solver-contact+spatial-geometry':action==='drop'?'dynamic-settle':'kinematic-anchor';
|
|
172
|
+
const result={...value,evidenceKind,verified,physicsVerified,graspVerified:false,source:'native-physics'};
|
|
173
|
+
if(verified)recordInteractionEvidence(world,{targetId:receiptTarget,capability:receiptCapability,
|
|
174
|
+
verified,source:'native-physics',commandId:job.id,result});
|
|
175
|
+
return result;
|
|
176
|
+
}),
|
|
177
|
+
settle:(value,job)=>{
|
|
178
|
+
const verified=!job.cancelled&&value.verified===true;
|
|
179
|
+
return {status:verified?'succeeded':'failed',verification:{status:verified?'verified':'unverified',evidence:value},
|
|
180
|
+
outcome:{state:verified?'verified':'failed',verified,physicsVerified:verified&&value.physicsVerified===true}};
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Each capability declares an executor; only the legacy adapter translates
|
|
186
|
+
// historical action names. New Code Project, environment and joint names
|
|
187
|
+
// never need a new branch in the Scene dispatcher.
|
|
188
|
+
const invocationExecutors = new Map([
|
|
189
|
+
['project-action', request => startProjectAction(request)],
|
|
190
|
+
['world-action', request => {
|
|
191
|
+
if (!request.actor) throw sceneError('ACTOR_REQUIRED');
|
|
192
|
+
return startRuntimeCapability({ ...request, source:'environment' }, () =>
|
|
193
|
+
world.commands.executeAffordance({
|
|
194
|
+
targetId:request.target, actorId:request.actor, action:request.name, args:request.args
|
|
195
|
+
}, { approach:true }),
|
|
196
|
+
value => value?.status === 'world-action-completed' && value.verified === true);
|
|
197
|
+
}],
|
|
198
|
+
['interaction', (request, capability) => startPhysicalCapability(request, capability)]
|
|
199
|
+
]);
|
|
200
|
+
|
|
201
|
+
function startInvocation(request) {
|
|
202
|
+
const { capability } = resolveCapability(world, request);
|
|
203
|
+
const executor = invocationExecutors.get(capability.executor);
|
|
204
|
+
if (!executor) throw sceneError('ACTION_EXECUTOR_UNAVAILABLE');
|
|
205
|
+
return executor(request, capability);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function startPhysicalCapability(request, capability) {
|
|
209
|
+
const { target, name, actor, args = {} } = request;
|
|
210
|
+
if (!actor) throw sceneError('ACTOR_REQUIRED');
|
|
211
|
+
if(capability.source==='native-physics'){
|
|
212
|
+
if(capability.partName&&args.part&&args.part!==capability.partName)throw sceneError('ACTION_PART_MISMATCH');
|
|
213
|
+
return controller.interact(legacyPhysicalRequest({...request,partName:capability.partName||request.partName}));
|
|
214
|
+
}
|
|
215
|
+
const record = world.store.get(target);
|
|
216
|
+
// Contract membership, not the verb, identifies a physically articulated
|
|
217
|
+
// action. This includes open/close and previously unknown semantic verbs.
|
|
218
|
+
const contract = capability.partName && world.interactions.interactionContracts(record).contracts.find(item =>
|
|
219
|
+
item.action === name && item.target.partName === capability.partName);
|
|
220
|
+
if (!contract) return controller.interact(legacyPhysicalRequest(request));
|
|
221
|
+
if (Object.keys(args).length) throw sceneError('ACTION_ARGUMENTS_UNSUPPORTED');
|
|
222
|
+
return startRuntimeCapability({ ...request, source:'asset' }, async () => {
|
|
223
|
+
const value = await world.commands.approachAndInteract(actor, target, name, { partName:capability.partName });
|
|
224
|
+
const verified = verifyInteractionResult(contract, { ...value, part:value.partName }).verified;
|
|
225
|
+
return { ...value, verified, physicsVerified:verified, evidenceKind:'joint-motor' };
|
|
226
|
+
}, value => value?.verified === true);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function startRuntimeCapability({ target, name, source }, execute, verify) {
|
|
230
|
+
return startJob({
|
|
231
|
+
execute: () => world.mutate('scene:invoke:' + name, execute),
|
|
232
|
+
settle: (value, job) => {
|
|
233
|
+
const verified = !job.cancelled && verify(value) === true;
|
|
234
|
+
if (verified) recordInteractionEvidence(world, {
|
|
235
|
+
targetId:target, capability:name.toUpperCase(), verified:true,
|
|
236
|
+
source: source === 'asset' ? 'physical-articulation' : 'environment',
|
|
237
|
+
commandId:job.id, result:value
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
status:verified ? 'succeeded' : 'failed',
|
|
241
|
+
verification:{ status:verified ? 'verified' : 'unverified', evidence:value },
|
|
242
|
+
outcome:{ state:verified ? 'verified' : 'failed', verified,
|
|
243
|
+
physicsVerified:source === 'asset' && verified && value.physicsVerified === true }
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function startProjectAction(args) {
|
|
250
|
+
return startJob({
|
|
251
|
+
abortable:true,
|
|
252
|
+
timeoutMs:world.projectCapabilities.timeoutFor(args.target, args.name),
|
|
253
|
+
execute:job => world.projectCapabilities.execute(args, { signal:job.controller.signal }),
|
|
254
|
+
settle:(value, job) => {
|
|
255
|
+
const verified = !job.cancelled && value.verified;
|
|
256
|
+
if (verified) recordInteractionEvidence(world, {
|
|
257
|
+
targetId:args.target, capability:args.name.toUpperCase(), verified:true,
|
|
258
|
+
source:'project-defined', commandId:job.id, result:value
|
|
259
|
+
});
|
|
260
|
+
onProjectAction();
|
|
261
|
+
return {
|
|
262
|
+
status:'succeeded',
|
|
263
|
+
verification:{ status:verified ? 'verified' : 'unverified', evidence:value.evidence },
|
|
264
|
+
outcome:{ state:job.cancelled ? 'unverified' : verified ? 'verified' : value.verificationRequested ? 'unverified' : 'accepted',
|
|
265
|
+
verified, physicsVerified:false }
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function startJob({ execute, settle, timeoutMs = 60_000, abortable = false, immediate = false }) {
|
|
272
|
+
if (jobs.size >= 128) {
|
|
273
|
+
const terminal = [...jobs].find(([, item]) => item.status !== 'running');
|
|
274
|
+
if (terminal) jobs.delete(terminal[0]);
|
|
275
|
+
else throw sceneError('JOB_LIMIT');
|
|
276
|
+
}
|
|
277
|
+
const job = { id:'job_' + crypto.randomUUID(), status:'running', result:null };
|
|
278
|
+
if (abortable) job.controller = new AbortController();
|
|
279
|
+
jobs.set(job.id, job);
|
|
280
|
+
setBusy(true);
|
|
281
|
+
let pending;
|
|
282
|
+
try {
|
|
283
|
+
pending = immediate ? Promise.resolve(execute(job)) : Promise.resolve().then(() => execute(job));
|
|
284
|
+
} catch (error) {
|
|
285
|
+
pending = Promise.reject(error);
|
|
286
|
+
}
|
|
287
|
+
const completionPromise = pending.then(value => {
|
|
288
|
+
if(job.status==='quarantined')return;
|
|
289
|
+
const completion = settle(value, job);
|
|
290
|
+
job.status = job.cancelled ? 'cancelled' : completion.status;
|
|
291
|
+
job.result = result('interact', value, { ...completion, status:job.status });
|
|
292
|
+
}).catch(error => {
|
|
293
|
+
if(job.status==='quarantined')return;
|
|
294
|
+
if(error?.projectMutation)onProjectAction();
|
|
295
|
+
job.status = job.cancelled ? 'cancelled' : 'failed';
|
|
296
|
+
job.result = result('interact', error?.projectMutation || null, {
|
|
297
|
+
status:job.status, ...(error?.projectMutation ? {mutation:error.projectMutation.mutation} : {}),
|
|
298
|
+
...(abortable ? { verification:{ status:'unverified', evidence:null } } : {}),
|
|
299
|
+
diagnostics:[diagnostic(error)]
|
|
300
|
+
});
|
|
301
|
+
}).finally(() => {
|
|
302
|
+
clearTimeout(job.graceTimer);
|
|
303
|
+
clearTimeout(job.timer);
|
|
304
|
+
setBusy(false);
|
|
305
|
+
});
|
|
306
|
+
job.promise=abortable ? Promise.race([completionPromise,new Promise(resolve=>{job.releaseWaiter=resolve;})]) : completionPromise;
|
|
307
|
+
if (timeoutMs != null) {
|
|
308
|
+
job.timer = setTimeout(() => controller.cancelJob(job.id), timeoutMs);
|
|
309
|
+
job.timer.unref?.();
|
|
310
|
+
}
|
|
311
|
+
return { id:job.id, status:job.status };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function getJob(key) {
|
|
315
|
+
const job = jobs.get(key);
|
|
316
|
+
if (!job) throw sceneError('JOB_NOT_FOUND');
|
|
317
|
+
return job;
|
|
318
|
+
}
|
|
319
|
+
return { ...controller, cancelPending };
|
|
320
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { sceneError } from './SceneContracts.js';
|
|
2
|
+
|
|
3
|
+
/** Owns Scene API lifecycle state shared by mutation, jobs and persistence services. */
|
|
4
|
+
export function createSceneLifecycle(world) {
|
|
5
|
+
let busy = false;
|
|
6
|
+
let closed = false;
|
|
7
|
+
const isolated = () => Boolean(world.faultCode);
|
|
8
|
+
world.revision ??= 0;
|
|
9
|
+
|
|
10
|
+
const assertOpen = () => {
|
|
11
|
+
if (isolated() && !closed) throw sceneError('PROJECT_RUNTIME_QUARANTINED');
|
|
12
|
+
if (closed) throw sceneError('SCENE_CLOSED');
|
|
13
|
+
};
|
|
14
|
+
const assertIdle = () => {
|
|
15
|
+
assertOpen();
|
|
16
|
+
if (busy || world.mutationOwner) throw sceneError('SCENE_BUSY');
|
|
17
|
+
};
|
|
18
|
+
const exclusive = async operation => {
|
|
19
|
+
assertIdle();
|
|
20
|
+
busy = true;
|
|
21
|
+
try {
|
|
22
|
+
return await operation();
|
|
23
|
+
} finally {
|
|
24
|
+
busy = false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const result = (operation, value, extra = {}) => ({
|
|
28
|
+
schema: 'agentscape.scene-result',
|
|
29
|
+
schemaVersion: 1,
|
|
30
|
+
operation,
|
|
31
|
+
status: 'succeeded',
|
|
32
|
+
revision:world.revision,
|
|
33
|
+
admission: null,
|
|
34
|
+
verification: { status: 'not-requested', evidence: null },
|
|
35
|
+
diagnostics: [],
|
|
36
|
+
value,
|
|
37
|
+
...extra
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
getState: () => closed ? 'closed' : isolated() ? 'quarantined' : busy || world.mutationOwner ? 'executing' : 'ready',
|
|
42
|
+
quarantine: () => { if (world.quarantine) world.quarantine(); else world.faultCode = 'PROJECT_RUNTIME_QUARANTINED'; world.revision++; },
|
|
43
|
+
getRevision: () => world.revision,
|
|
44
|
+
incrementRevision: () => { world.revision++; },
|
|
45
|
+
setBusy: value => { busy = value; },
|
|
46
|
+
assertOpen,
|
|
47
|
+
assertIdle,
|
|
48
|
+
exclusive,
|
|
49
|
+
result,
|
|
50
|
+
close() {
|
|
51
|
+
if (closed) return false;
|
|
52
|
+
if (!isolated()) assertIdle();
|
|
53
|
+
closed = true;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { parseSceneProject } from './SceneProject.js';
|
|
3
|
+
import { portableAssetDefinition, 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 maxAssets = 32;
|
|
12
|
+
const maxBundleBytes = 96 * 1024 * 1024;
|
|
13
|
+
export function checkDocumentSize(input, limit, code) {
|
|
14
|
+
const text = typeof input === 'string' ? input : JSON.stringify(input);
|
|
15
|
+
if (text.length > limit || new Blob([text]).size > limit) throw Object.assign(new Error(code), {code});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const hash = z.string().regex(/^[a-f0-9]{64}$/);
|
|
19
|
+
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();
|
|
20
|
+
const schema = z.object({ schema: z.literal('agentscape.project-bundle'), schemaVersion: z.literal(1),
|
|
21
|
+
project: z.unknown(), snapshot: z.unknown(),
|
|
22
|
+
lock: z.object({ engine: z.enum(['1.34.2', RUNTIME_VERSION]), builtins: hash, content: hash }).strict(),
|
|
23
|
+
assets: z.array(descriptor).max(maxAssets),
|
|
24
|
+
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(),
|
|
25
|
+
style: stylePackSchema.optional()
|
|
26
|
+
}).strict();
|
|
27
|
+
const builtinHash = () => assetDigest(new TextEncoder().encode(canonicalAssetJson(assetManifests)));
|
|
28
|
+
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); };
|
|
29
|
+
const decode = text => {
|
|
30
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(text)) throw new Error('INVALID_RESOURCE_ENCODING');
|
|
31
|
+
return Uint8Array.from(atob(text), c => c.charCodeAt(0));
|
|
32
|
+
};
|
|
33
|
+
const digestContent = value => assetDigest(new TextEncoder().encode(canonicalAssetJson(value)));
|
|
34
|
+
|
|
35
|
+
/** JSON transport for scene.json, lock, runtime snapshot and embedded resources.
|
|
36
|
+
* Directory/ZIP adapters can encode these same bytes without executing sources.
|
|
37
|
+
*/
|
|
38
|
+
export async function exportRuntimeState(world, { name = 'Untitled World', readResource = null } = {}) {
|
|
39
|
+
if (world.mutationOwner && !world.writesFrozen) throw new Error('SCENE_BUSY');
|
|
40
|
+
const snapshot = world.serialize({ name }), assets = [], assetAliases = {};
|
|
41
|
+
if (snapshot.assets.length > maxAssets) throw new Error('RESOURCE_LIMIT');
|
|
42
|
+
let total = 0;
|
|
43
|
+
for (const manifest of snapshot.assets) {
|
|
44
|
+
let bytes;
|
|
45
|
+
if (manifest.source.kind === 'compiled') bytes = (await world.assetModule.compiledStore.get(manifest.source.key))?.bytes;
|
|
46
|
+
else if (readResource) bytes = await readResource(manifest.source.url, manifest.id);
|
|
47
|
+
else if (manifest.source.kind === 'glb') bytes = await world.assetModule.readAssetBytes(manifest.id);
|
|
48
|
+
if (!(bytes instanceof Uint8Array)) throw new Error('RESOURCE_UNAVAILABLE');
|
|
49
|
+
bytes = bytes.slice(); assertEmbeddedGLB(bytes);
|
|
50
|
+
total += bytes.length; if (total > 64 * 1024 * 1024) throw new Error('RESOURCE_LIMIT');
|
|
51
|
+
const sha256=await assetDigest(bytes),definition=portableAssetDefinition(manifest);
|
|
52
|
+
// Portable bundles own the compiled bytes; never write into immutable owner-global pa_ storage.
|
|
53
|
+
const portableId=/^pa_[a-f0-9]{64}$/.test(manifest.id)
|
|
54
|
+
? 'asset_'+await assetDigest(new TextEncoder().encode(canonicalAssetJson({globalId:manifest.id,sha256,definition})))
|
|
55
|
+
: manifest.id;
|
|
56
|
+
assetAliases[manifest.id]=portableId;
|
|
57
|
+
assets.push(descriptor.parse({ id:portableId, sha256, bytes: encode(bytes), definition }));
|
|
58
|
+
}
|
|
59
|
+
snapshot.objects=snapshot.objects.map(object=>({
|
|
60
|
+
...object,assetId:assetAliases[object.assetId]||object.assetId
|
|
61
|
+
}));
|
|
62
|
+
snapshot.assets = [];
|
|
63
|
+
return { snapshot, assets, assetAliases };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Restore into a newly created code-project Runtime, retaining its native environment. */
|
|
67
|
+
export async function restoreRuntimeState(world, { snapshot, assets }, {deferNativePhysics=false}={}) {
|
|
68
|
+
world.serializer.validate(snapshot);
|
|
69
|
+
if (snapshot.assets.length || snapshot.metadata?.environment !== world.environment.id || !Array.isArray(assets)) throw new Error('PROJECT_SNAPSHOT_MISMATCH');
|
|
70
|
+
if (assets.length > maxAssets) throw new Error('RESOURCE_LIMIT');
|
|
71
|
+
const ids = new Set(), prepared = []; let total = 0;
|
|
72
|
+
for (const item of assets) {
|
|
73
|
+
if (ids.has(item.id) || assetManifests[item.id]?.source.kind === 'builtin') throw new Error('ASSET_ID_CONFLICT');
|
|
74
|
+
ids.add(item.id);
|
|
75
|
+
const bytes = decode(item.bytes); total += bytes.length;
|
|
76
|
+
if (total > 64 * 1024 * 1024 || await assetDigest(bytes) !== item.sha256) throw new Error('RESOURCE_INTEGRITY_MISMATCH');
|
|
77
|
+
assertEmbeddedGLB(bytes); prepared.push({ ...item, bytes });
|
|
78
|
+
}
|
|
79
|
+
for (const item of prepared) await world.assetModule.importPackageAsset(item);
|
|
80
|
+
if(deferNativePhysics){const {nativePhysics,...managed}=snapshot;await world.restore(managed);return nativePhysics;}
|
|
81
|
+
await world.restore(snapshot);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function exportScenePackage(world, { name = 'Untitled World', readResource = null, style = null, editable = undefined } = {}) {
|
|
85
|
+
const { snapshot, assets, assetAliases } = await exportRuntimeState(world, { name, readResource });
|
|
86
|
+
const project = parseSceneProject({ schema: 'agentscape.scene-project', schemaVersion: 1, name,
|
|
87
|
+
environment: { type: 'builtin', id: world.environment.id },
|
|
88
|
+
...(style ? { style: './styles/current/style.json' } : {}),
|
|
89
|
+
objects: snapshot.objects.map(object => ({ id: object.id,
|
|
90
|
+
asset: assets.some(a=>a.id===object.assetId) ? `./assets/${assets.findIndex(a => a.id === object.assetId)}/model.glb` : `builtin://${object.assetId}`,
|
|
91
|
+
level: assets.find(a=>a.id===object.assetId)?.definition.capabilityLevel
|
|
92
|
+
|| (assets.some(a=>a.id===object.assetId) ? 'physical' : world.assetModule.getManifest(object.assetId).capabilityLevel || 'physical'),
|
|
93
|
+
transform: { ...object.transform, scale: object.transform.scale[0] } })) });
|
|
94
|
+
const localEditable=editable?.map(entry=>({...entry,assetId:assetAliases[entry.assetId]||entry.assetId}));
|
|
95
|
+
const checked = editable === undefined ? undefined : SceneObjectForge.validateTransfer(snapshot,localEditable);
|
|
96
|
+
const payload = { project, snapshot, assets, ...(style ? { style: stylePackSchema.parse(style) } : {}),
|
|
97
|
+
...(checked !== undefined ? { editable:checked } : {}) };
|
|
98
|
+
const content = await digestContent(payload);
|
|
99
|
+
const bundle = { schema: 'agentscape.project-bundle', schemaVersion: 1, ...payload,
|
|
100
|
+
lock: { engine: RUNTIME_VERSION, builtins: await builtinHash(), content } };
|
|
101
|
+
checkDocumentSize(bundle,maxBundleBytes,'DOCUMENT_LIMIT');
|
|
102
|
+
return schema.parse(bundle);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Prepare entirely in a fresh Runtime. Failure never mutates the caller's world. */
|
|
106
|
+
/** @param {any} input @param {{container?: HTMLElement|null, assetModule?: any, codeExecutor?: any, codeGLTFLoader?: any, rendererMode?: 'auto'|'webgpu'|'webgl2'|'webgl-legacy', pixelRatioScale?: number}} options */
|
|
107
|
+
export async function openScenePackage(input, { container = null, assetModule = null, codeExecutor = null, codeGLTFLoader, rendererMode = 'auto', pixelRatioScale = 0.75 } = {}) {
|
|
108
|
+
checkDocumentSize(input,maxBundleBytes,'DOCUMENT_LIMIT');
|
|
109
|
+
if (typeof input === 'string') {
|
|
110
|
+
input = JSON.parse(input);
|
|
111
|
+
}
|
|
112
|
+
const bundle = schema.parse(structuredClone(input)), project = parseSceneProject(bundle.project);
|
|
113
|
+
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');
|
|
114
|
+
if (Boolean(project.style) !== Boolean(bundle.style)) throw new Error('STYLE_DEPENDENCY_MISSING');
|
|
115
|
+
if (bundle.snapshot?.metadata?.stylePack && canonicalAssetJson(bundle.snapshot.metadata.stylePack) !== canonicalAssetJson(bundle.style)) throw new Error('STYLE_DEPENDENCY_MISMATCH');
|
|
116
|
+
if (!Array.isArray(bundle.snapshot?.objects) || bundle.snapshot.objects.length !== project.objects.length) throw new Error('PROJECT_SNAPSHOT_MISMATCH');
|
|
117
|
+
for (let index = 0; index < project.objects.length; index++) {
|
|
118
|
+
const object = project.objects[index], saved = bundle.snapshot.objects[index];
|
|
119
|
+
const assetIndex = bundle.assets.findIndex(asset => asset.id === saved.assetId);
|
|
120
|
+
const reference = assetIndex < 0 ? `builtin://${saved.assetId}` : `./assets/${assetIndex}/model.glb`;
|
|
121
|
+
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');
|
|
122
|
+
}
|
|
123
|
+
SceneObjectForge.validateTransfer(bundle.snapshot,bundle.editable || []);
|
|
124
|
+
const ids = new Set(); let total = 0;
|
|
125
|
+
const prepared = [];
|
|
126
|
+
for (const item of bundle.assets) {
|
|
127
|
+
if (ids.has(item.id) || assetManifests[item.id]?.source.kind === 'builtin') throw new Error('ASSET_ID_CONFLICT');
|
|
128
|
+
ids.add(item.id);
|
|
129
|
+
const bytes = decode(item.bytes); total += bytes.length;
|
|
130
|
+
if (total > 64 * 1024 * 1024 || await assetDigest(bytes) !== item.sha256) throw new Error('RESOURCE_INTEGRITY_MISMATCH');
|
|
131
|
+
assertEmbeddedGLB(bytes); prepared.push({ ...item, bytes });
|
|
132
|
+
}
|
|
133
|
+
const assets = assetModule || createAssetModule({ volatile: true, manifests: Object.fromEntries(Object.entries(assetManifests).filter(([id]) => !ids.has(id))), manifestStore: null, libraryStore: null });
|
|
134
|
+
assets.configureVerification({articulationVerifier:new ArticulationVerifier({assetRegistry:assets.registry,assetLoader:assets.loader})});
|
|
135
|
+
for (const item of prepared) {
|
|
136
|
+
await assets.importPackageAsset(item);
|
|
137
|
+
}
|
|
138
|
+
const { openScene } = await import('./SceneFacade.js');
|
|
139
|
+
const scene = await openScene({ container, assetModule: assets, codeExecutor, codeGLTFLoader, rendererMode, pixelRatioScale, project: { ...project, objects: [], style: undefined } });
|
|
140
|
+
try { await scene.restoreSnapshot(bundle.snapshot, { prepared: true }); if (bundle.style) await scene.setStyle(bundle.style); return scene; }
|
|
141
|
+
catch (error) { scene.close(); throw error; }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Validate in an isolated session, then reuse Runtime's own transactional restore. */
|
|
145
|
+
export async function importScenePackageInto(world, input, { applyStyle, getStyle, gltfLoader } = {}) {
|
|
146
|
+
const bundle = schema.parse(structuredClone(typeof input === 'string' ? JSON.parse(input) : input));
|
|
147
|
+
const ids = new Set(bundle.assets.map(asset => asset.id));
|
|
148
|
+
const assets = createAssetModule({ volatile: true, manifests: Object.fromEntries(Object.entries(assetManifests).filter(([id]) => !ids.has(id))), manifestStore: null, libraryStore: null, gltfLoader });
|
|
149
|
+
if (world.rendering?.renderer) assets.configureRenderer(world.rendering.renderer);
|
|
150
|
+
let staged;
|
|
151
|
+
try {
|
|
152
|
+
staged = await openScenePackage(bundle, { assetModule: assets });
|
|
153
|
+
if (bundle.project.environment.id !== world.environment.id) throw new Error('ENVIRONMENT_MISMATCH');
|
|
154
|
+
SceneObjectForge.validateTransfer(bundle.snapshot,bundle.editable||[]);
|
|
155
|
+
const snapshot = staged.snapshot(), entries = [];
|
|
156
|
+
if (bundle.snapshot.camera) snapshot.camera = structuredClone(bundle.snapshot.camera);
|
|
157
|
+
for (const asset of bundle.assets) {
|
|
158
|
+
const manifest = assets.getManifest(asset.id), stored = await assets.compiledStore.get(manifest.source.key);
|
|
159
|
+
entries.push({ manifest, bytes: stored.bytes, expectedSourceHash: asset.sha256, expectedDefinition: asset.definition });
|
|
160
|
+
}
|
|
161
|
+
const previousStyle = getStyle?.() || null;
|
|
162
|
+
return await world.assetModule.installPreparedAssets(entries, async () => {
|
|
163
|
+
snapshot.assets = snapshot.assets.map(manifest => world.assetModule.getManifest(manifest.id));
|
|
164
|
+
try {
|
|
165
|
+
return await world.mutate('scene:import-project', async () => {
|
|
166
|
+
await world.restoreSnapshot(snapshot);
|
|
167
|
+
await applyStyle?.(bundle.style || null);
|
|
168
|
+
return { status: 'project-imported', objects: snapshot.objects.length, editable:bundle.editable||[] };
|
|
169
|
+
});
|
|
170
|
+
} catch (error) { await applyStyle?.(previousStyle); throw error; }
|
|
171
|
+
});
|
|
172
|
+
} finally { staged?.close(); assets.loader.gltfLoader.dispose?.(); }
|
|
173
|
+
}
|
|
@@ -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 world.mutate('scene:setStyle',()=>styles.set(input, options)))); },
|
|
43
|
+
async importProject(input, { gltfLoader } = {}) {
|
|
44
|
+
return exclusive(async () => {
|
|
45
|
+
const { importScenePackageInto } = await import('./ScenePackage.js');
|
|
46
|
+
return result('importProject', await importScenePackageInto(world, input, { gltfLoader, getStyle: () => styles.export(), applyStyle: pack => pack ? styles.set(pack) : styles.clear() }));
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|