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,148 @@
|
|
|
1
|
+
import { createRequestWindow } from '../../application/scene/RequestWindow.js';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { mkdir, writeFile, readFile, rename, rm } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { HeadlessWorldHost } from './HeadlessWorldHost.js';
|
|
6
|
+
import { SceneObjectForge } from '../../application/object-forge/SceneObjectForge.js';
|
|
7
|
+
import { INLINE_WORLD_BYTES } from './TransferLimits.js';
|
|
8
|
+
export const DEFAULT_MAX_EXPORT_BYTES=INLINE_WORLD_BYTES;
|
|
9
|
+
export class SessionManager {
|
|
10
|
+
constructor({root,maxSessions=4,maxRetiredHosts=maxSessions,ttlMs=900000,cleanupMs=500,maxExportBytes=DEFAULT_MAX_EXPORT_BYTES,hostOptions={},repository=null}={}) {
|
|
11
|
+
this.root=path.resolve(root); this.maxSessions=maxSessions; this.ttlMs=ttlMs; this.maxExportBytes=maxExportBytes; this.hostOptions=hostOptions; this.sessions=new Map(); this.pending=0; this.creating=new Set();
|
|
12
|
+
if(!Number.isSafeInteger(maxRetiredHosts)||maxRetiredHosts<0) throw new RangeError('Invalid retired host budget');
|
|
13
|
+
this.retiredHosts=new Set();
|
|
14
|
+
this.maxRetiredHosts=maxRetiredHosts;
|
|
15
|
+
this.cleanupMs=cleanupMs;
|
|
16
|
+
this.timer=setInterval(()=>this.reap().catch(()=>{}),Math.min(ttlMs,30000)); this.timer.unref();
|
|
17
|
+
this.repository=repository;this.restoreRequests=createRequestWindow({limitCode:'RESTORE_REQUEST_LIMIT'});
|
|
18
|
+
}
|
|
19
|
+
create(owner,options={}) {
|
|
20
|
+
const promise=this.createSession(owner,options);
|
|
21
|
+
this.creating.add(promise);
|
|
22
|
+
promise.then(()=>this.creating.delete(promise),()=>this.creating.delete(promise));
|
|
23
|
+
return promise;
|
|
24
|
+
}
|
|
25
|
+
async createSession(owner,{assetIds=[]}={}) {
|
|
26
|
+
if(this.disposed) throw new Error('MANAGER_CLOSED');
|
|
27
|
+
if(this.sessions.size+this.pending>=this.maxSessions) throw new Error('SESSION_LIMIT');
|
|
28
|
+
if(this.sessions.size+this.pending+this.retiredHosts.size>=this.maxSessions+this.maxRetiredHosts) throw new Error('RETIRED_HOST_BUDGET');
|
|
29
|
+
this.pending++;
|
|
30
|
+
let host,directory;
|
|
31
|
+
try {
|
|
32
|
+
host=await HeadlessWorldHost.create({...this.hostOptions,owner,repository:this.repository,assetIds});
|
|
33
|
+
if(this.disposed) throw new Error('MANAGER_CLOSED');
|
|
34
|
+
const id=randomUUID();directory=path.join(this.root,id); await mkdir(directory,{recursive:true});
|
|
35
|
+
if(this.disposed) throw new Error('MANAGER_CLOSED');
|
|
36
|
+
this.sessions.set(id,{id,owner,host,forge:new SceneObjectForge(),directory,lastUsed:Date.now(),active:null,closing:false,requests:createRequestWindow()});
|
|
37
|
+
return this.status(owner,id);
|
|
38
|
+
} catch(e) { try { host?.close(); } finally { if(directory)await rm(directory,{recursive:true,force:true}); } throw e; } finally { this.pending--; }
|
|
39
|
+
}
|
|
40
|
+
get(owner,id) { const s=this.sessions.get(id); if(!s || s.owner!==owner || s.closing) throw new Error('SESSION_NOT_FOUND'); s.lastUsed=Date.now(); return s; }
|
|
41
|
+
status(owner,id) { const s=this.get(owner,id); return {worldSessionId:id,environmentId:s.host.world.environment.id,tick:s.host.world.simulation.tick,execution:s.active || s.host.world.mutationOwner?'running':'idle',expiresAt:s.lastUsed+this.ttlMs}; }
|
|
42
|
+
async run(owner,id,operation,{requestId,fingerprint,signal}={}) {
|
|
43
|
+
const s=this.get(owner,id);
|
|
44
|
+
const replay=s.requests.replay(requestId,fingerprint);
|
|
45
|
+
if(replay)return replay;
|
|
46
|
+
if(s.active) throw new Error('SESSION_BUSY');
|
|
47
|
+
if(requestId)s.requests.ensureCapacity();
|
|
48
|
+
const controller=new AbortController();
|
|
49
|
+
let deadline,grace;
|
|
50
|
+
const abort=()=>controller.abort(new Error('ACTION_CANCELLED'));
|
|
51
|
+
const interrupted=new Promise((_,reject)=>{
|
|
52
|
+
controller.signal.addEventListener('abort',()=>{
|
|
53
|
+
grace=setTimeout(()=>{
|
|
54
|
+
s.host.isolate();
|
|
55
|
+
reject(controller.signal.reason);
|
|
56
|
+
},this.cleanupMs);
|
|
57
|
+
},{once:true});
|
|
58
|
+
});
|
|
59
|
+
signal?.addEventListener('abort',abort,{once:true});
|
|
60
|
+
if(signal?.aborted) abort();
|
|
61
|
+
deadline=setTimeout(()=>controller.abort(new Error('ACTION_TIMEOUT')),s.host.timeoutMs);
|
|
62
|
+
const work=s.host.track(Promise.resolve().then(()=>{
|
|
63
|
+
controller.signal.throwIfAborted();
|
|
64
|
+
return operation(s,controller.signal);
|
|
65
|
+
}));
|
|
66
|
+
const promise=Promise.race([work,interrupted]).then(value=>{
|
|
67
|
+
controller.signal.throwIfAborted();
|
|
68
|
+
return value;
|
|
69
|
+
},error=>{throw controller.signal.aborted ? controller.signal.reason : error;});
|
|
70
|
+
s.active={controller,promise};
|
|
71
|
+
if(requestId) s.requests.track(requestId,fingerprint,promise);
|
|
72
|
+
try { return await promise; }
|
|
73
|
+
finally {
|
|
74
|
+
clearTimeout(deadline);clearTimeout(grace);
|
|
75
|
+
signal?.removeEventListener('abort',abort);
|
|
76
|
+
s.active=null;s.lastUsed=Date.now();
|
|
77
|
+
if(s.host.closed && !s.closing) await this.close(owner,id);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async export(s) {
|
|
81
|
+
if(s.host.world.mutationOwner) throw new Error('SESSION_BUSY');
|
|
82
|
+
const snapshot=s.host.world.serialize({name:'Remote MCP snapshot'}),json=JSON.stringify(snapshot);
|
|
83
|
+
if(Buffer.byteLength(json)>this.maxExportBytes) throw new Error('EXPORT_LIMIT');
|
|
84
|
+
const name=`snapshot-${randomUUID()}.json`,temporary=path.join(s.directory,`${name}.tmp`),target=path.join(s.directory,name);
|
|
85
|
+
try { await writeFile(temporary,json,{flag:'wx'}); JSON.parse(await readFile(temporary,'utf8')); await rename(temporary,target); }
|
|
86
|
+
finally { await rm(temporary,{force:true}); }
|
|
87
|
+
return {state:'exported',fileName:name,bytes:Buffer.byteLength(json),snapshot,scope:'scene-json-only'};
|
|
88
|
+
}
|
|
89
|
+
async save(owner,s) {
|
|
90
|
+
if(s.host.world.mutationOwner) throw new Error('SESSION_BUSY');
|
|
91
|
+
if(!this.repository)throw new Error('PERSISTENCE_UNAVAILABLE');
|
|
92
|
+
return this.repository.saveWorld(owner,s.host.world.serialize({name:'Saved MCP world'}));
|
|
93
|
+
}
|
|
94
|
+
async restore(owner,saveId,requestId) {
|
|
95
|
+
if(!this.repository)throw new Error('PERSISTENCE_UNAVAILABLE');
|
|
96
|
+
const key=requestId && JSON.stringify([owner,requestId]);
|
|
97
|
+
const replay=this.restoreRequests.replay(key,saveId);
|
|
98
|
+
if(replay)return this.status(owner,(await replay).worldSessionId);
|
|
99
|
+
if(key)this.restoreRequests.ensureCapacity();
|
|
100
|
+
const promise=(async()=>{
|
|
101
|
+
const data=await this.repository.loadWorld(owner,saveId);
|
|
102
|
+
const session=await this.create(owner,{assetIds:data.dependencies.map(d=>d.assetId)});
|
|
103
|
+
try{await this.run(owner,session.worldSessionId,s=>s.host.world.restoreSnapshot(data.snapshot));return this.status(owner,session.worldSessionId);}
|
|
104
|
+
catch(error){await this.close(owner,session.worldSessionId);throw error;}
|
|
105
|
+
})();
|
|
106
|
+
this.restoreRequests.track(key,saveId,promise);return promise;
|
|
107
|
+
}
|
|
108
|
+
async exportAuthoring(s) {
|
|
109
|
+
const document=s.host.session.authoring.export();
|
|
110
|
+
const draft={schema:'agentscape.remote-authoring',schemaVersion:1,sources:s.host.authoringSources,document,promotions:s.host.session.promotion.exportState()};
|
|
111
|
+
const json=JSON.stringify(draft);
|
|
112
|
+
if(Buffer.byteLength(json)>this.maxExportBytes) throw new Error('EXPORT_LIMIT');
|
|
113
|
+
const fileName=`authoring-${randomUUID()}.json`,temporary=path.join(s.directory,`${fileName}.tmp`),target=path.join(s.directory,fileName);
|
|
114
|
+
try {await writeFile(temporary,json,{flag:'wx'});JSON.parse(await readFile(temporary,'utf8'));await rename(temporary,target);}
|
|
115
|
+
finally {await rm(temporary,{force:true});}
|
|
116
|
+
return {state:'exported',fileName,bytes:Buffer.byteLength(json),scope:'authoring-source-and-document-only',draft};
|
|
117
|
+
}
|
|
118
|
+
close(owner,id) {
|
|
119
|
+
const s=this.sessions.get(id);
|
|
120
|
+
if(!s || s.owner!==owner)return Promise.reject(new Error('SESSION_NOT_FOUND'));
|
|
121
|
+
if(s.closePromise)return s.closePromise;
|
|
122
|
+
s.closing=true;
|
|
123
|
+
s.closePromise=Promise.resolve().then(async()=>{
|
|
124
|
+
s.active?.controller.abort(new Error('ACTION_CANCELLED'));
|
|
125
|
+
try { await s.active?.promise.catch(()=>{}); s.host.close(); }
|
|
126
|
+
finally {
|
|
127
|
+
if(s.host.writers?.size) {
|
|
128
|
+
this.retiredHosts.add(s.host);
|
|
129
|
+
Promise.allSettled([...s.host.writers]).then(()=>this.retiredHosts.delete(s.host));
|
|
130
|
+
}
|
|
131
|
+
this.sessions.delete(id); try { await s.archiveStorage?.dispose(); } finally { await rm(s.directory,{recursive:true,force:true}); } }
|
|
132
|
+
return {worldSessionId:id,state:'closed'};
|
|
133
|
+
});
|
|
134
|
+
return s.closePromise;
|
|
135
|
+
}
|
|
136
|
+
async reap() { for(const s of this.sessions.values()) if(s.host.closed || (!s.active && !s.host.world.mutationOwner && Date.now()-s.lastUsed>=this.ttlMs)) await this.close(s.owner,s.id); }
|
|
137
|
+
dispose() {
|
|
138
|
+
if(this.disposePromise)return this.disposePromise;
|
|
139
|
+
this.disposed=true; clearInterval(this.timer);
|
|
140
|
+
this.disposePromise=(async()=>{
|
|
141
|
+
await Promise.allSettled([...this.creating]);
|
|
142
|
+
const results=await Promise.allSettled([...this.sessions.values()].map(s=>this.close(s.owner,s.id)));
|
|
143
|
+
const errors=results.filter(r=>r.status==='rejected').map(r=>r.reason);
|
|
144
|
+
if(errors.length)throw new AggregateError(errors,'SESSION_CLEANUP_FAILED');
|
|
145
|
+
})();
|
|
146
|
+
return this.disposePromise;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { MCP_MESSAGE_BYTES } from './TransferLimits.js';
|
|
2
|
+
const DEFAULT_ORIGINS=[
|
|
3
|
+
'http://127.0.0.1:5173','http://localhost:5173',
|
|
4
|
+
'http://127.0.0.1:4178','http://localhost:4178',
|
|
5
|
+
'http://127.0.0.1:4189','http://localhost:4189'
|
|
6
|
+
];
|
|
7
|
+
const send=(res,status,data,origin)=>{
|
|
8
|
+
res.writeHead(status,{'content-type':'application/json; charset=utf-8',
|
|
9
|
+
'cache-control':'no-store',...(origin?{'access-control-allow-origin':origin,'vary':'Origin'}:{})});
|
|
10
|
+
res.end(JSON.stringify(data));
|
|
11
|
+
};
|
|
12
|
+
const body=async(req,limit)=>{
|
|
13
|
+
const chunks=[];let total=0;
|
|
14
|
+
for await(const chunk of req){
|
|
15
|
+
total+=chunk.length;
|
|
16
|
+
if(total>limit)throw Object.assign(new Error('BRIDGE_BODY_LIMIT'),{status:413});
|
|
17
|
+
chunks.push(chunk);
|
|
18
|
+
}
|
|
19
|
+
try{return JSON.parse(Buffer.concat(chunks).toString('utf8'));}
|
|
20
|
+
catch{throw Object.assign(new Error('BRIDGE_INVALID_JSON'),{status:400});}
|
|
21
|
+
};
|
|
22
|
+
const fail=(code,status=400)=>Object.assign(new Error(code),{status});
|
|
23
|
+
export async function handleStudioBridgeHttp(req,res,bridge,{origins=DEFAULT_ORIGINS,transfers}={}) {
|
|
24
|
+
const endpoint=req.url?.split('?')[0] || '';
|
|
25
|
+
if(!endpoint.startsWith('/studio-bridge/'))return false;
|
|
26
|
+
const host=String(req.headers.host||'').split(':')[0];
|
|
27
|
+
const origin=req.headers.origin;
|
|
28
|
+
if(!['127.0.0.1','localhost'].includes(host))return send(res,403,{code:'BRIDGE_HOST_FORBIDDEN'}),true;
|
|
29
|
+
if(!origin || !origins.includes(origin))return send(res,403,{code:'BRIDGE_ORIGIN_FORBIDDEN'}),true;
|
|
30
|
+
if(req.method==='OPTIONS'){
|
|
31
|
+
res.writeHead(204,{'access-control-allow-origin':origin,'access-control-allow-methods':'POST, OPTIONS',
|
|
32
|
+
'access-control-allow-headers':'content-type,x-studio-session,x-studio-token,x-studio-request','access-control-max-age':'600','vary':'Origin'});
|
|
33
|
+
res.end();return true;
|
|
34
|
+
}
|
|
35
|
+
if(req.method!=='POST')return send(res,405,{code:'METHOD_NOT_ALLOWED'},origin),true;
|
|
36
|
+
try{
|
|
37
|
+
if(endpoint==='/studio-bridge/reply-file'){
|
|
38
|
+
const id=req.headers['x-studio-session'],token=req.headers['x-studio-token'],requestId=req.headers['x-studio-request'];
|
|
39
|
+
const session=bridge.authorized(id,token);
|
|
40
|
+
if(!session.owner || !session.pending.has(requestId))throw fail('STUDIO_REQUEST_NOT_FOUND');
|
|
41
|
+
const {file}=await transfers.createFile(session.owner,async writer=>{
|
|
42
|
+
for await(const chunk of req)await writer.write(chunk);
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
bridge.reply(id,token,{requestId,result:{fileId:file.id,bytes:file.bytes,sha256:file.sha256,contentType:'application/json'}});
|
|
46
|
+
} catch(error){await transfers.cancel(session.owner,file.id,'complete');throw error;}
|
|
47
|
+
send(res,200,{status:'accepted'},origin);return true;
|
|
48
|
+
}
|
|
49
|
+
const input=await body(req,endpoint==='/studio-bridge/reply' ? MCP_MESSAGE_BYTES : 1024*1024);
|
|
50
|
+
let data;
|
|
51
|
+
if(endpoint==='/studio-bridge/auto-register'){
|
|
52
|
+
data=bridge.registerAuto(input.instanceId,input.worldId,input.runtimeId);
|
|
53
|
+
}else if(endpoint==='/studio-bridge/world-change'){
|
|
54
|
+
data=bridge.updateWorld(input.worldSessionId,input.studioToken,input.worldId,input.runtimeId);
|
|
55
|
+
}else if(endpoint==='/studio-bridge/connect'){
|
|
56
|
+
if(typeof input.pairCode!=='string')throw fail('PAIR_CODE_INVALID');
|
|
57
|
+
data=bridge.connect(input.pairCode,input.runtimeId);
|
|
58
|
+
}else if(endpoint==='/studio-bridge/heartbeat'){
|
|
59
|
+
data=bridge.heartbeat(input.worldSessionId,input.studioToken);
|
|
60
|
+
}else if(endpoint==='/studio-bridge/poll'){
|
|
61
|
+
data=await bridge.poll(input.worldSessionId,input.studioToken);
|
|
62
|
+
}else if(endpoint==='/studio-bridge/reply'){
|
|
63
|
+
data=bridge.reply(input.worldSessionId,input.studioToken,input);
|
|
64
|
+
}else if(endpoint==='/studio-bridge/disconnect'){
|
|
65
|
+
bridge.authorized(input.worldSessionId,input.studioToken);
|
|
66
|
+
bridge.disconnect(input.worldSessionId);
|
|
67
|
+
data={status:'disconnected'};
|
|
68
|
+
}else return send(res,404,{code:'BRIDGE_ROUTE_NOT_FOUND'},origin),true;
|
|
69
|
+
send(res,200,data,origin);
|
|
70
|
+
}catch(error){
|
|
71
|
+
const code=/^[A-Z_]+$/.test(error.code||error.message||'') ? error.code||error.message : 'BRIDGE_REQUEST_FAILED';
|
|
72
|
+
send(res,error.status||400,{code},origin);
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { createRequestWindow } from '../../application/scene/RequestWindow.js';
|
|
2
|
+
import { randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
|
|
4
|
+
const issue = (code) => Object.assign(new Error(code), {code});
|
|
5
|
+
const secret = () => randomBytes(32).toString('hex');
|
|
6
|
+
const equal = (left, right) => typeof left === 'string' && typeof right === 'string'
|
|
7
|
+
&& left.length === right.length && timingSafeEqual(Buffer.from(left),Buffer.from(right));
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Ephemeral transport, not a second WorldRuntime.
|
|
11
|
+
* Studio owns the only Runtime; MCP supplies authenticated and bounded commands.
|
|
12
|
+
* Browser pairing requires a human-delivered one-time capability (not the MCP Bearer token).
|
|
13
|
+
*/
|
|
14
|
+
export class StudioLiveBridge {
|
|
15
|
+
// Timing budget: this bridge is loopback-only and the Studio page is the
|
|
16
|
+
// single source of truth. A busy page main thread (software-rendered GLB
|
|
17
|
+
// compiles measured above 30s) must not expire a live session, and one
|
|
18
|
+
// legitimate Studio operation may run longer than 30s; dead-tab detection
|
|
19
|
+
// stays bounded by the same 60s heartbeat.
|
|
20
|
+
constructor({now=()=>Date.now(),pairTtlMs=120000,heartbeatMs=60000,rpcTimeoutMs=60000,recoveryMs=60000}={}) {
|
|
21
|
+
this.now=now;
|
|
22
|
+
this.pairTtlMs=pairTtlMs;
|
|
23
|
+
this.heartbeatMs=heartbeatMs;
|
|
24
|
+
this.rpcTimeoutMs=rpcTimeoutMs;
|
|
25
|
+
this.recoveryMs=recoveryMs;
|
|
26
|
+
this.sessions=new Map();
|
|
27
|
+
this.autoByInstance=new Map();
|
|
28
|
+
this.autoOwnerHistory=new Map(); // Short-lived tab binding across disconnect/reconnect.
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
pair(owner) {
|
|
32
|
+
if(!owner)throw issue('OWNER_REQUIRED');
|
|
33
|
+
for(const [id,entry] of this.sessions)if(!entry.connected&&this.now()>entry.expiresAt)this.disconnect(id,'PAIR_CODE_EXPIRED');
|
|
34
|
+
if([...this.sessions.values()].filter(entry=>entry.owner===owner).length>=4)throw issue('STUDIO_SESSION_LIMIT');
|
|
35
|
+
if(this.sessions.size>=32)throw issue('STUDIO_SESSION_LIMIT');
|
|
36
|
+
const worldSessionId=randomUUID(),pairCode=secret();
|
|
37
|
+
this.sessions.set(worldSessionId,{owner,pairCode,expiresAt:this.now()+this.pairTtlMs,
|
|
38
|
+
token:null,connected:false,lastSeen:0,pending:new Map(),requests:createRequestWindow({now:this.now}),queue:[],pollWaiter:null});
|
|
39
|
+
return {worldSessionId,pairCode,expiresInSeconds:Math.ceil(this.pairTtlMs/1000),status:'awaiting-studio'};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Loopback auto mode: an approved local Studio origin registers a live tab.
|
|
44
|
+
* No MCP bearer is exposed to the browser; all Scene tools still require MCP auth.
|
|
45
|
+
*/
|
|
46
|
+
registerAuto(instanceId,worldId,runtimeId=worldId) {
|
|
47
|
+
if(typeof instanceId!=='string'||!/^[a-f0-9-]{36}$/i.test(instanceId))throw issue('STUDIO_INSTANCE_INVALID');
|
|
48
|
+
if(typeof worldId!=='string'||worldId.length>128||!worldId.length)throw issue('STUDIO_WORLD_INVALID');
|
|
49
|
+
for(const [id,session] of this.sessions) {
|
|
50
|
+
if(session.auto && (!session.connected||this.now()-session.lastSeen>this.heartbeatMs))this.disconnect(id,'STUDIO_DISCONNECTED');
|
|
51
|
+
}
|
|
52
|
+
const previous=this.autoByInstance.get(instanceId);
|
|
53
|
+
for(const [key,entry] of this.autoOwnerHistory)if(entry.expiresAt<=this.now())this.autoOwnerHistory.delete(key);
|
|
54
|
+
const receiptScope=this.sessions.get(previous)?.receiptScope ?? this.autoOwnerHistory.get(instanceId)?.receiptScope ?? randomUUID();
|
|
55
|
+
const previousOwner=(previous?this.sessions.get(previous)?.owner:null)??this.autoOwnerHistory.get(instanceId)?.owner??null;
|
|
56
|
+
if(previous)this.disconnect(previous,'STUDIO_REPLACED');
|
|
57
|
+
if(this.autoByInstance.size>=8)throw issue('STUDIO_TAB_LIMIT');
|
|
58
|
+
const worldSessionId=randomUUID(),token=secret();
|
|
59
|
+
this.sessions.set(worldSessionId,{
|
|
60
|
+
owner:previousOwner,receiptScope,runtimeId,auto:true,instanceId,worldId,pairCode:null,expiresAt:0,
|
|
61
|
+
token,connected:true,lastSeen:this.now(),pending:new Map(),requests:createRequestWindow({now:this.now}),queue:[],pollWaiter:null
|
|
62
|
+
});
|
|
63
|
+
this.autoByInstance.set(instanceId,worldSessionId);
|
|
64
|
+
return {worldSessionId,studioToken:token,heartbeatMs:this.heartbeatMs,status:'connected',mode:'automatic',worldId};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Enumerate live worlds visible to an MCP identity without claiming
|
|
69
|
+
* unowned automatic tabs. Never disclose another identity's sessions.
|
|
70
|
+
*/
|
|
71
|
+
listSessions(owner) {
|
|
72
|
+
const active=[];
|
|
73
|
+
for(const [id,s] of this.sessions){
|
|
74
|
+
if(!s.connected)continue;
|
|
75
|
+
if(this.now()-s.lastSeen>this.heartbeatMs){
|
|
76
|
+
this.disconnect(id,'STUDIO_DISCONNECTED');
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if(s.owner!=null && s.owner!==owner)continue;
|
|
80
|
+
active.push({worldSessionId:id,worldId:s.worldId||null,runtimeId:s.runtimeId||null,
|
|
81
|
+
status:'connected',connected:true,mode:s.auto?'automatic':'paired'});
|
|
82
|
+
}
|
|
83
|
+
return active;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
currentSession(owner=null) {
|
|
87
|
+
// Automatic routing only covers automatic tabs. Paired worlds require an ID.
|
|
88
|
+
const active=this.listSessions(owner).filter(s=>s.mode==='automatic');
|
|
89
|
+
if(!active.length)throw issue('STUDIO_NOT_CONNECTED');
|
|
90
|
+
if(active.length>1)throw issue('STUDIO_MULTIPLE_WORLDS');
|
|
91
|
+
if(owner!=null)this.ownerSession(owner,active[0].worldSessionId);
|
|
92
|
+
return active[0];
|
|
93
|
+
}
|
|
94
|
+
/** Keep stable worldSessionId while Studio switches its active code project. */
|
|
95
|
+
updateWorld(id,token,worldId,runtimeId=worldId) {
|
|
96
|
+
const session=this.authorized(id,token);
|
|
97
|
+
if(typeof worldId!=='string'||!worldId.length||worldId.length>128)throw issue('STUDIO_WORLD_INVALID');
|
|
98
|
+
if(session.runtimeId!==runtimeId || session.worldId!==worldId){
|
|
99
|
+
for(const request of session.queue.splice(0)){
|
|
100
|
+
session.pending.get(request.requestId)?.reject(issue('WORLD_RUNTIME_CHANGED'));
|
|
101
|
+
session.pending.delete(request.requestId);
|
|
102
|
+
}
|
|
103
|
+
session.requests=createRequestWindow({now:this.now});
|
|
104
|
+
}
|
|
105
|
+
session.runtimeId=runtimeId;
|
|
106
|
+
session.worldId=worldId;
|
|
107
|
+
return {worldSessionId:id,worldId,status:'connected'};
|
|
108
|
+
}
|
|
109
|
+
isStudioSession(id) {return this.sessions.has(id);}
|
|
110
|
+
ownerSession(owner,id) {
|
|
111
|
+
const s=this.sessions.get(id);
|
|
112
|
+
if(!s||(s.owner!=null && s.owner!==owner))throw issue('SESSION_NOT_FOUND');
|
|
113
|
+
if(s.auto && s.owner==null){if(!owner)throw issue('OWNER_REQUIRED');s.owner=owner;}
|
|
114
|
+
return s;
|
|
115
|
+
}
|
|
116
|
+
status(owner,id) {
|
|
117
|
+
const s=this.ownerSession(owner,id);
|
|
118
|
+
if(s.connected&&this.now()-s.lastSeen>this.heartbeatMs)this.disconnect(id,'STUDIO_DISCONNECTED');
|
|
119
|
+
return {worldSessionId:id,mode:s.auto?'automatic':'paired',worldId:s.worldId||null,runtimeId:s.runtimeId||null,status:s.connected?'connected':s.pairCode&&this.now()<s.expiresAt?'awaiting-studio':'disconnected',
|
|
120
|
+
connected:s.connected,lastSeen:s.lastSeen||null};
|
|
121
|
+
}
|
|
122
|
+
connect(pairCode,runtimeId=null) {
|
|
123
|
+
const candidate=[...this.sessions.entries()].find(([,s])=>s.pairCode&&equal(s.pairCode,pairCode));
|
|
124
|
+
if(!candidate)throw issue('PAIR_CODE_INVALID');
|
|
125
|
+
const [id,s]=candidate;
|
|
126
|
+
if(this.now()>s.expiresAt) {this.disconnect(id,'PAIR_CODE_EXPIRED');throw issue('PAIR_CODE_EXPIRED');}
|
|
127
|
+
s.runtimeId=runtimeId;
|
|
128
|
+
s.pairCode=null;
|
|
129
|
+
s.token=secret();
|
|
130
|
+
s.connected=true;
|
|
131
|
+
s.lastSeen=this.now();
|
|
132
|
+
return {worldSessionId:id,studioToken:s.token,heartbeatMs:this.heartbeatMs,status:'connected'};
|
|
133
|
+
}
|
|
134
|
+
authorized(id,token) {
|
|
135
|
+
const s=this.sessions.get(id);
|
|
136
|
+
if(!s||!s.connected||!equal(s.token,token))throw issue('STUDIO_AUTH_FAILED');
|
|
137
|
+
if(this.now()-s.lastSeen>this.heartbeatMs) {this.disconnect(id,'STUDIO_DISCONNECTED');throw issue('STUDIO_DISCONNECTED');}
|
|
138
|
+
return s;
|
|
139
|
+
}
|
|
140
|
+
heartbeat(id,token) {
|
|
141
|
+
this.authorized(id,token).lastSeen=this.now();
|
|
142
|
+
return {status:'connected'};
|
|
143
|
+
}
|
|
144
|
+
async poll(id,token) {
|
|
145
|
+
const s=this.authorized(id,token);
|
|
146
|
+
s.lastSeen=this.now();
|
|
147
|
+
if(s.queue.length)return {request:s.queue.shift()};
|
|
148
|
+
// Poll has its own short deadline to allow rapid disconnect and heartbeat.
|
|
149
|
+
if(s.pollWaiter)throw issue('STUDIO_POLL_CONFLICT');
|
|
150
|
+
return new Promise(resolve=>{
|
|
151
|
+
const timer=setTimeout(()=>{
|
|
152
|
+
if(s.pollWaiter?.resolve===resolve)s.pollWaiter=null;
|
|
153
|
+
resolve({request:null});
|
|
154
|
+
},8000);
|
|
155
|
+
timer.unref?.();
|
|
156
|
+
s.pollWaiter={resolve,timer};
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
reply(id,token,{requestId,result,error}) {
|
|
160
|
+
const s=this.authorized(id,token);
|
|
161
|
+
s.lastSeen=this.now();
|
|
162
|
+
const pending=s.pending.get(requestId);
|
|
163
|
+
if(!pending)throw issue('STUDIO_REQUEST_NOT_FOUND');
|
|
164
|
+
s.pending.delete(requestId);
|
|
165
|
+
clearTimeout(pending.timer);
|
|
166
|
+
if(error)pending.reject(issue(typeof error.code==='string'&&/^[A-Z_]+$/.test(error.code)?error.code:'STUDIO_OPERATION_FAILED'));
|
|
167
|
+
else pending.resolve(result);
|
|
168
|
+
return {status:'accepted'};
|
|
169
|
+
}
|
|
170
|
+
async call(owner,id,method,args,{signal,requestId}={}) {
|
|
171
|
+
const s=this.ownerSession(owner,id);
|
|
172
|
+
if(!s.connected||this.now()-s.lastSeen>this.heartbeatMs){
|
|
173
|
+
this.disconnect(id,'STUDIO_DISCONNECTED');
|
|
174
|
+
throw issue('STUDIO_DISCONNECTED');
|
|
175
|
+
}
|
|
176
|
+
const fingerprint=requestId?JSON.stringify([method,args]):null;
|
|
177
|
+
const replay=s.requests.replay(requestId,fingerprint);
|
|
178
|
+
if(replay)return this.waitForReceipt(replay,signal);
|
|
179
|
+
if(requestId)s.requests.ensureCapacity();
|
|
180
|
+
if(s.pending.size>=1)throw issue('STUDIO_BUSY');
|
|
181
|
+
if(signal?.aborted)throw issue('ACTION_CANCELLED');
|
|
182
|
+
const transportId=randomUUID();
|
|
183
|
+
const promise=new Promise((resolve,reject)=>{
|
|
184
|
+
s.pending.set(transportId,{resolve,reject});
|
|
185
|
+
const request={requestId:transportId,runtimeId:s.runtimeId,method,args};
|
|
186
|
+
if(requestId)request.receiptKey=JSON.stringify([s.receiptScope || id, s.runtimeId, requestId]);
|
|
187
|
+
if(s.pollWaiter){
|
|
188
|
+
clearTimeout(s.pollWaiter.timer);
|
|
189
|
+
const waiter=s.pollWaiter;s.pollWaiter=null;
|
|
190
|
+
waiter.resolve({request});
|
|
191
|
+
}else s.queue.push(request);
|
|
192
|
+
});
|
|
193
|
+
if(requestId){
|
|
194
|
+
s.requests.track(requestId,fingerprint,promise);
|
|
195
|
+
}
|
|
196
|
+
return this.waitForReceipt(promise,signal,code=>{
|
|
197
|
+
const index=s.queue.findIndex(item=>item.requestId===transportId);
|
|
198
|
+
if(index<0){
|
|
199
|
+
const pending=s.pending.get(transportId);
|
|
200
|
+
if(pending && !pending.timer){
|
|
201
|
+
pending.timer=setTimeout(()=>this.disconnect(id,'STUDIO_RESULT_UNKNOWN'),this.recoveryMs);
|
|
202
|
+
pending.timer.unref?.();
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
s.queue.splice(index,1);
|
|
207
|
+
s.pending.get(transportId)?.reject(issue(code));
|
|
208
|
+
s.pending.delete(transportId);
|
|
209
|
+
return true;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
waitForReceipt(receipt,signal,cancelQueued) {
|
|
213
|
+
return new Promise((resolve,reject)=>{
|
|
214
|
+
const stop=code=>reject(issue(cancelQueued?.(code)?code:'STUDIO_RESULT_UNKNOWN'));
|
|
215
|
+
const abort=()=>stop('ACTION_CANCELLED');
|
|
216
|
+
const timer=setTimeout(()=>stop('STUDIO_TIMEOUT'),this.rpcTimeoutMs);
|
|
217
|
+
timer.unref?.();
|
|
218
|
+
signal?.addEventListener('abort',abort,{once:true});
|
|
219
|
+
if(signal?.aborted)abort();
|
|
220
|
+
receipt.then(resolve,reject).finally(()=>{
|
|
221
|
+
clearTimeout(timer);
|
|
222
|
+
signal?.removeEventListener('abort',abort);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
disconnect(id,reason='STUDIO_DISCONNECTED') {
|
|
227
|
+
const s=this.sessions.get(id);
|
|
228
|
+
if(!s)return false;
|
|
229
|
+
this.sessions.delete(id);
|
|
230
|
+
if(s.auto && this.autoByInstance.get(s.instanceId)===id)this.autoByInstance.delete(s.instanceId);
|
|
231
|
+
if(s.auto && s.owner!=null){
|
|
232
|
+
this.autoOwnerHistory.delete(s.instanceId);
|
|
233
|
+
this.autoOwnerHistory.set(s.instanceId,{owner:s.owner,receiptScope:s.receiptScope,expiresAt:this.now()+10*60_000});
|
|
234
|
+
while(this.autoOwnerHistory.size>64)this.autoOwnerHistory.delete(this.autoOwnerHistory.keys().next().value);
|
|
235
|
+
}
|
|
236
|
+
s.connected=false;
|
|
237
|
+
if(s.pollWaiter){
|
|
238
|
+
clearTimeout(s.pollWaiter.timer);s.pollWaiter.resolve({request:null});s.pollWaiter=null;
|
|
239
|
+
}
|
|
240
|
+
for(const pending of s.pending.values()){clearTimeout(pending.timer);pending.reject(issue(s.queue.some(item=>s.pending.get(item.requestId)===pending)?reason:'STUDIO_RESULT_UNKNOWN'));}
|
|
241
|
+
s.pending.clear();s.queue.length=0;
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
close(owner,id) {this.ownerSession(owner,id);this.disconnect(id);return {worldSessionId:id,status:'disconnected'};}
|
|
245
|
+
dispose(){for(const id of [...this.sessions.keys()])this.disconnect(id);this.autoOwnerHistory.clear();}
|
|
246
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { projectBridgeArgs } from '../../application/agent/StudioProjectTools.js';
|
|
3
|
+
|
|
4
|
+
const revision=z.number().int().nonnegative();
|
|
5
|
+
const nodePath=z.string().max(256);
|
|
6
|
+
const objectUuid=z.string().min(1).max(128);
|
|
7
|
+
const project=z.record(z.string(),z.unknown());
|
|
8
|
+
const filePath=z.string().min(1).max(180);
|
|
9
|
+
const batchOperations=z.array(z.object({kind:z.enum(['file','resource']),action:z.enum(['create','write','patch','rename','delete','add']),
|
|
10
|
+
path:z.string().min(1).max(180),newPath:z.string().max(180).optional(),
|
|
11
|
+
content:z.string().optional(),oldText:z.string().optional(),newText:z.string().optional(),
|
|
12
|
+
mime:z.string().optional(),base64:z.string().optional()}).strict()).min(1).max(32);
|
|
13
|
+
const inspectionView=z.union([
|
|
14
|
+
z.object({position:z.tuple([z.number().finite(),z.number().finite(),z.number().finite()]),target:z.tuple([z.number().finite(),z.number().finite(),z.number().finite()]),fov:z.number().min(10).max(110).optional()}).strict(),
|
|
15
|
+
z.object({nodePath:z.string().max(256),objectUuid:z.string().min(1).max(128).optional(),direction:z.tuple([z.number().finite(),z.number().finite(),z.number().finite()]).optional(),position:z.tuple([z.number().finite(),z.number().finite(),z.number().finite()]).optional(),target:z.tuple([z.number().finite(),z.number().finite(),z.number().finite()]).optional(),fov:z.number().min(10).max(110).optional(),padding:z.number().min(1.02).max(2.5).optional()}).strict()
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
/** Separate narrow public contracts; all operations use one existing project dispatcher. */
|
|
19
|
+
export function registerStudioProjectTools(add,dispatch,{projectScope}={}){
|
|
20
|
+
const session={worldSessionId:z.uuid().optional(),requestId:z.uuid().optional()};
|
|
21
|
+
const draft={...session,expectedRevision:revision.optional()};
|
|
22
|
+
const live={...session,expectedRevision:revision,expectedRuntimeId:z.uuid().optional(),expectedSceneRevision:revision.optional()};
|
|
23
|
+
const target={nodePath:nodePath.optional(),objectUuid:objectUuid.optional()};
|
|
24
|
+
const geometry={includeMaterials:z.boolean().optional(),includeLights:z.boolean().optional(),visibility:z.boolean().optional()};
|
|
25
|
+
const register=(name,description,shape)=>add(name,description,shape,(a,e)=>{
|
|
26
|
+
const {worldSessionId,requestId,...input}=a;
|
|
27
|
+
return dispatch(a,projectBridgeArgs(name,input),e);
|
|
28
|
+
});
|
|
29
|
+
register('studio_project',projectScope
|
|
30
|
+
? 'Manage the prepared code world: read the guide, source preview and revision; run the edited revision; save the live world. Edit code with studio_files.'
|
|
31
|
+
: 'Manage trusted native Three.js code worlds: read lists projects, guide and revision; create accepts optional name/source/project; create_world takes a world_ ID plus 32 lowercase hex digits; open takes an existing project ID; run activates the draft; save persists live state; close returns to the base world. Edit files with studio_files. Not a sandbox.',{
|
|
32
|
+
...draft,operation:z.enum(projectScope?['read','run','save']:['read','create','create_world','open','run','save','close']),
|
|
33
|
+
...(!projectScope?{id:z.string().optional(),name:z.string().min(1).optional(),source:z.string().min(1).optional(),project:project.optional()}: {})
|
|
34
|
+
});
|
|
35
|
+
register('studio_files','Edit the current project draft, not the running scene. write replaces entry source or a same-ID project; patch replaces a unique fragment (optional path); file_read reads a named file with offset/limit; file creates/writes/patches/renames/deletes; resource adds/deletes binary resources; preview_batch stages up to 32 edits, apply_batch commits atomically, discard_batch discards, undo_batch reverts. Use current expectedRevision for edits, then studio_project run.',{
|
|
36
|
+
...draft,operation:z.enum(['write','patch','file_read','file','resource','preview_batch','apply_batch','discard_batch','undo_batch']),
|
|
37
|
+
source:z.string().min(1).optional(),name:z.string().min(1).optional(),project:project.optional(),
|
|
38
|
+
oldText:z.string().min(1).optional(),newText:z.string().optional(),action:z.enum(['create','write','patch','rename','delete','add']).optional(),
|
|
39
|
+
path:filePath.optional(),newPath:z.string().max(180).optional(),content:z.string().optional(),mime:z.string().optional(),base64:z.string().optional(),
|
|
40
|
+
offset:z.number().int().nonnegative().optional(),limit:z.number().int().min(1).max(65536).optional(),previewId:z.uuid().optional(),operations:batchOperations.optional()
|
|
41
|
+
});
|
|
42
|
+
register('scene_query','Read native Three.js geometry without semantic registration. search by query/objectType/material, inspect a path (empty for root), inspect_batch up to 8 paths (4 with visibility). Include materials/lights and approximate opaque-mesh visibility when needed. Results are bounded evidence, not a visual or physical verdict. Reuse expectedRuntimeId, expectedSceneRevision and objectUuid from search; objectUuids aligns with nodePaths. Stale paths with a mismatched UUID are rejected. physics_candidate requires nodePath and objectUuid; returns conservative per-mesh oriented boxes for explicit source binding, never creates a body or grants actions. For registered semantic entities use scene_observe.',{
|
|
43
|
+
...live,operation:z.enum(['search','inspect','inspect_batch','physics_candidate']),...target,...geometry,
|
|
44
|
+
query:z.string().max(120).optional(),objectType:z.string().max(64).optional(),material:z.string().max(120).optional(),visibleOnly:z.boolean().optional(),includeInternal:z.boolean().optional(),
|
|
45
|
+
nodePaths:z.array(nodePath).min(1).max(8).optional(),objectUuids:z.array(objectUuid).min(1).max(8).optional(),
|
|
46
|
+
offset:z.number().int().nonnegative().optional(),limit:z.number().int().min(1).max(64).optional(),view:inspectionView.optional()
|
|
47
|
+
});
|
|
48
|
+
register('scene_capture','Capture a real JPEG or suggest 2-12 camera views ranked by bounded opaque-mesh ray sampling. capture supports imageMode=mcp (image content) or base64, detached view={position,target,fov} or auto-frame view={nodePath,objectUuid,direction,padding}; isolateNodePath/isolateObjectUuid temporarily isolate the subject. Direct WebGL views exclude custom postprocessing; no simulation step. If a canvas is still initializing, capture waits briefly and returns VISUAL_CANVAS_NOT_READY rather than a tiny image; retry on the same running revision. suggest_views accepts nodePath/objectUuid and optional candidateLimit/grid/directions. Use revisions and UUID from scene_query. Not a visual verdict.',{
|
|
49
|
+
...live,operation:z.enum(['capture','suggest_views']),...target,
|
|
50
|
+
maxWidth:z.number().int().min(128).max(1024).optional(),maxHeight:z.number().int().min(128).max(1024).optional(),imageMode:z.enum(['base64','mcp']).optional(),
|
|
51
|
+
view:inspectionView.optional(),isolateNodePath:nodePath.optional(),isolateObjectUuid:objectUuid.optional(),
|
|
52
|
+
candidateLimit:z.number().int().min(2).max(12).optional(),grid:z.number().int().min(3).max(7).optional(),fov:z.number().min(10).max(110).optional(),padding:z.number().min(1.02).max(2.5).optional(),
|
|
53
|
+
directions:z.array(z.tuple([z.number().finite(),z.number().finite(),z.number().finite()])).min(2).max(12).optional()
|
|
54
|
+
});
|
|
55
|
+
register('scene_timeline','Control the current code world timeline: status, pause, resume, or step 1-120 fixed ticks while paused. Resume before scene_interact. Does not control external timers or user-created render loops.',{
|
|
56
|
+
...live,command:z.enum(['status','pause','resume','step']).default('status'),steps:z.number().int().min(1).max(120).optional()
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { pipeline } from 'node:stream/promises';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
|
|
5
|
+
const createSchema=z.object({bytes:z.number().int().nonnegative(),sha256:z.string().regex(/^[a-f0-9]{64}$/).optional()}).strict();
|
|
6
|
+
const completeSchema=z.object({partIds:z.array(z.string().regex(/^part_[a-f0-9-]{36}$/)).max(1024)}).strict();
|
|
7
|
+
const json=(res,status,data)=>res.writeHead(status,{'content-type':'application/json; charset=utf-8'}).end(JSON.stringify(data));
|
|
8
|
+
export async function handleTransferHttp(req,res,authorize,store){
|
|
9
|
+
const route=/^\/(uploads|files)(?:\/((?:upload|file)_[a-f0-9-]{36}))?(?:\/(parts|complete|cancel|content))?$/.exec(req.url);
|
|
10
|
+
if(!route)return false;
|
|
11
|
+
const [,type,id,action]=route,method=req.method;
|
|
12
|
+
const raw=type==='uploads'&&action==='parts'&&method==='POST';
|
|
13
|
+
const {owner,body}=await authorize(req,{raw,bodyLimit:raw?store.maxPartBytes:65536});
|
|
14
|
+
try{
|
|
15
|
+
if(type==='uploads'){
|
|
16
|
+
if(!id&&method==='POST'&&!action){json(res,201,await store.create(owner,createSchema.parse(body)));return true;}
|
|
17
|
+
if(id&&method==='GET'&&!action){json(res,200,store.metadata(store.get(owner,id,'pending')));return true;}
|
|
18
|
+
if(id&&method==='POST'&&action==='parts'){json(res,201,await store.part(owner,id,req));return true;}
|
|
19
|
+
if(id&&method==='POST'&&action==='complete'){json(res,200,await store.complete(owner,id,completeSchema.parse(body).partIds));return true;}
|
|
20
|
+
if(id&&method==='POST'&&action==='cancel'){json(res,200,await store.cancel(owner,id,'pending'));return true;}
|
|
21
|
+
}else if(id){
|
|
22
|
+
if(method==='GET'&&!action){json(res,200,store.metadata(store.get(owner,id,'complete')));return true;}
|
|
23
|
+
if(method==='DELETE'&&!action){json(res,200,await store.cancel(owner,id,'complete'));return true;}
|
|
24
|
+
if(method==='GET'&&action==='content'){
|
|
25
|
+
const lease=store.lease(owner,id);try{
|
|
26
|
+
res.writeHead(200,{'content-type':'application/octet-stream','content-length':lease.metadata.bytes,'x-content-sha256':lease.metadata.sha256});
|
|
27
|
+
// Keep one chunk of lookahead. All disk reads are closed before sending
|
|
28
|
+
// the last chunk; clients that read Content-Length can immediately delete.
|
|
29
|
+
async function* content(){
|
|
30
|
+
let pending;
|
|
31
|
+
try{for await(const chunk of lease.source()){if(pending)yield pending;pending=chunk;}
|
|
32
|
+
lease.release();if(pending)yield pending;
|
|
33
|
+
}finally{lease.release();}
|
|
34
|
+
}
|
|
35
|
+
await pipeline(Readable.from(content()),res);
|
|
36
|
+
}finally{lease.release();}return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
json(res,405,{error:'METHOD_NOT_ALLOWED'});
|
|
40
|
+
}catch(error){
|
|
41
|
+
if(res.headersSent){res.destroy();return true;}
|
|
42
|
+
if(error instanceof z.ZodError)json(res,400,{error:'INVALID_ARGUMENTS'});
|
|
43
|
+
else if(error.status)json(res,error.status,{error:error.code??'TRANSFER_REJECTED'});
|
|
44
|
+
else throw error;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// OpenAI-inspired transport defaults; independent from asset decoding and activation.
|
|
2
|
+
export const MCP_MESSAGE_BYTES = 10 * 1024 * 1024;
|
|
3
|
+
export const INLINE_WORLD_BYTES = 8 * 1024 * 1024;
|
|
4
|
+
export const TRANSFER_PART_BYTES = 64_000_000;
|
|
5
|
+
export const TRANSFER_FILE_BYTES = 8_000_000_000;
|
|
6
|
+
export const TRANSFER_TTL_MS = 60 * 60 * 1000;
|