agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/AssetCompiler-A99wKf7H.js +2424 -0
- package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
- package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
- package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
- package/dist/AssetRecipe-DCaLLXvG.js +67 -0
- package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53850 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
- package/dist/SceneSerializer-CLCzQjL_.js +350 -0
- package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
- package/dist/StylePack-CD_BC-Mv.js +6317 -0
- package/dist/StylePack-CD_BC-Mv.js.map +1 -0
- package/dist/WorldArchive-dYf1OpSe.js +417 -0
- package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
- package/dist/WorldIO-Dqz4MqTQ.js +149 -0
- package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
- package/dist/blankWorld-OoOvN_IK.js +75 -0
- package/dist/blankWorld-OoOvN_IK.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-B3HCflvO.js +128 -0
- package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
- package/dist/environments-B1WaICAN.js +4197 -0
- package/dist/environments-B1WaICAN.js.map +1 -0
- package/dist/gltfIO-BMK1hc2D.js +9 -0
- package/dist/gltfIO-BMK1hc2D.js.map +1 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +16239 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-DPQi_jh-.js +11019 -0
- package/dist/magicCabin-DPQi_jh-.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-IOLbRZQC.js +403 -0
- package/dist/monumentHall-IOLbRZQC.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
- package/dist/ruinedCourtyard-BtaF_aOi.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 +8 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -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 +72 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
- package/dist/runtime/application/native-scene/CodeProject.js +119 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -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 +79 -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 +45 -0
- package/dist/runtime/application/scene/SceneEditService.js +144 -0
- package/dist/runtime/application/scene/SceneFacade.js +261 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
- package/dist/runtime/application/scene/SceneJobController.js +229 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +162 -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 +87 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +74 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +137 -0
- package/dist/runtime/application/skills/SkillRegistry.js +189 -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 +174 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -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 +132 -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 +150 -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 +80 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -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 +65 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +21 -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/WorldDiskStorage.js +51 -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/foundation/EventBus.js +18 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -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 +399 -0
- package/dist/runtime/modules/asset/README.md +54 -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 +100 -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/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 +47 -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 +245 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -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/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 +80 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -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 +207 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -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 +502 -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 +665 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -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 +305 -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 +222 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -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 +69 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
- package/dist/runtime/package-lock.json +16048 -0
- package/dist/runtime/package.json +105 -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-BWpTl0Wj.js +359 -0
- package/dist/schema-BWpTl0Wj.js.map +1 -0
- package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
- package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# 程序化资产与可信世界恢复 v0.3
|
|
2
|
+
|
|
3
|
+
在现有 `agentscape-world` 中完成:Three.js 源码 → Linux 容器隔离构建 → GLB / 显式 Manifest → AssetModule → WorldCommands → WorldRuntime → 文件保存与恢复。没有第二个 MCP,也没有复制 Three.js 编辑器、物理、导航或场景序列化系统。
|
|
4
|
+
|
|
5
|
+
## 准备隔离环境
|
|
6
|
+
|
|
7
|
+
PC2 使用 Docker Desktop 的 Linux 引擎。先启动 Docker Desktop,准备官方基础镜像,然后构建固定运行镜像:
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
docker pull node:24-alpine
|
|
11
|
+
node dev/build-programmatic-sandbox.mjs
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
构建脚本将基础镜像解析为不可变 RepoDigest。上下文是临时目录,只复制固定 QuickJS 依赖、受信任构建入口及由本项目固定 Three.js 生成的 bundle,不包含仓库、私有配置或凭据。镜像生成后把不可变 image ID 和代码 digest 保存到数据目录的 `sandbox.json`。运行期间禁止自动拉取镜像;镜像缺失、引擎不可达、Linux 不可用、镜像标签或代码 digest 不匹配时返回 `SANDBOX_UNAVAILABLE`,无进程内回退。
|
|
15
|
+
|
|
16
|
+
每次构建通过 stdin 输入,容器采用:`network=none`、只读根文件系统、UID/GID 65534、cap-drop ALL、no-new-privileges、1 CPU、256MiB 内存及相同 swap 上限、64 PID、受限 /tmp tmpfs、无宿主挂载和 Docker socket。创建后读取实际 Docker inspect 并核对这些配置,再启动构建。代码还在容器内部的 QuickJS WASM 中执行,不注入 Node、文件、网络、模块加载或环境变量接口。
|
|
17
|
+
|
|
18
|
+
默认源码执行1500ms、QuickJS分配96MiB、整个容器运行15秒。超时、输出超过4MiB或取消时杀死附着进程并强制删除容器;无法确认清理会报告 `SANDBOX_CLEANUP_FAILED`。不把正则或普通 Worker 当成 OS 隔离。
|
|
19
|
+
|
|
20
|
+
源码/运行入口更新后重新执行镜像构建脚本。容器镜像是隔离构建依赖,不是常驻服务。Docker 未运行时,原有观察和内置世界操作仍可用,所有远程源码构建明确失败关闭。
|
|
21
|
+
|
|
22
|
+
## 输入与工具
|
|
23
|
+
|
|
24
|
+
`asset_build_submit` 接收:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"contract":"agentscape.procedural-asset.v1",
|
|
29
|
+
"source":"export function createAsset(THREE) { /* 返回 Group 或 Mesh */ }",
|
|
30
|
+
"definition":{"id":"box","type":"box","label":"箱子","actions":["move"],"physics":{"body":"fixed","colliders":[{"shape":"box","halfExtents":[0.5,0.5,0.5],"translation":[0,0.5,0]}]}},
|
|
31
|
+
"requestId":"<UUID>"
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
源码必须同步返回有效 Object3D,根变换为单位变换。支持 Mesh/Group、基础 BufferGeometry、Basic/Standard/Physical 材质与有界 RGBA DataTexture。动态脚本、事件/渲染回调、Shader、模型 URL、第三方依赖、灯光相机及蒙皮明确拒绝。源码最多32768字节,Manifest最多24576字符;原有 HTTP 64KiB 总请求限制仍然生效。
|
|
36
|
+
|
|
37
|
+
Manifest 使用既有 `validateAssetManifest()` 格式,另加远程接口字段与资源预算。输入的 `id` 是逻辑名称;`source`、最终不可变 ID、compiler、provenance 和 verification 由服务端生成,不接受客户端自证成功。声明 requiredNodes、surfaces、receptacles、physics、parts/joint/targets 和可选 interactionContract。必需节点必须唯一存在。关节不能仅靠节点命名推断为可交互。
|
|
38
|
+
|
|
39
|
+
| 新增工具 | 用法 |
|
|
40
|
+
|---|---|
|
|
41
|
+
| asset_build_submit | 提交并返回 Build ID;相同 requestId 参数冲突会拒绝 |
|
|
42
|
+
| asset_build_status | 查询 running / succeeded / failed / cancelled / interrupted,以及诊断、资产版本和准入 |
|
|
43
|
+
| asset_build_cancel | 取消自己的任务并终止构建容器 |
|
|
44
|
+
| asset_publish | 发布成功构建;非 ready 默认拒绝,provisional 必须显式选择编辑态 |
|
|
45
|
+
| asset_inspect | 查看自己的源码(可选)、Manifest、哈希和运行验证 |
|
|
46
|
+
| asset_list | 分页查询自己的已发布版本 |
|
|
47
|
+
| world_save | 保存当前会话,返回服务端 saveId |
|
|
48
|
+
| world_restore | 用自己的 saveId 和新 requestId 创建恢复会话,不接受磁盘路径 |
|
|
49
|
+
|
|
50
|
+
原16工具保留,共24工具。`action_execute` 原六种动作保留,新增 `replaceAsset`;`spawnAsset` 仅允许内置资产、当前会话创作资产,或当前身份已发布的资产。新发布资产在使用时注册到现有会话;新会话和恢复会话按需加载,不把整个资产库复制为另一份世界状态。
|
|
51
|
+
|
|
52
|
+
provisional 发布用于保留和审查,不提升准入。当前发布资产的 `spawnAsset` / `replaceAsset` 要求 ready;草稿编辑态继续使用原 authoring 接口。
|
|
53
|
+
|
|
54
|
+
构建不占用某个世界的互斥锁;最多4个并行构建,每身份最多2个。客户端应查询状态而非阻塞一个长 HTTP 请求。同一身份、相同内容的并发普通构建共用任务;不同 requestId 可复用已存在版本。`forceRebuild=true` 强制重建并校验相同版本产物;不一致返回 `BUILD_NONDETERMINISTIC`,保留旧产物。
|
|
55
|
+
|
|
56
|
+
## 实际调用顺序
|
|
57
|
+
|
|
58
|
+
真实示例位于 `apps/mcp-server/examples/procedural-assets.js`,包含箱子、带 top 支撑面的桌子、可开关门的冰箱。
|
|
59
|
+
|
|
60
|
+
1. 使用示例 source/definition 调用 `asset_build_submit`,轮询状态。
|
|
61
|
+
2. 成功后调用 `asset_publish`,取得 `pa_<SHA256>` Asset ID。
|
|
62
|
+
3. 创建会话;通过 `action_execute(skill="spawnAsset",args={assetId,instanceId,position})` 加入世界。
|
|
63
|
+
4. 通过原 navigate / approachAndPickup / approachAndPlace / approachAndInteract 操作。
|
|
64
|
+
5. 通过参数化 `world_verify.criteria` 检查目标实体与物理关系。
|
|
65
|
+
6. `world_save` 保存;服务重启后 `world_restore` 恢复为新的私有会话。
|
|
66
|
+
|
|
67
|
+
资产采用既有 GLB 导出与 AssetCompiler。显式定义替换推断碰撞与语义,仍经过几何、资源预算、Schema 和加载验证。物理注册和关节开/关目标在既有隔离 Rapier 验证器执行,证据写回 Manifest;构建成功、资产准入与世界动作完成依然是三个独立事实。
|
|
68
|
+
|
|
69
|
+
## 不可变版本与升级
|
|
70
|
+
|
|
71
|
+
版本取决于原始源码、规范化 Manifest 和构建环境,包括固定容器 image/digest、Three.js版本、编译/验证源码和依赖锁文件的 digest。逻辑 id 可以相同,版本修改后生成新 Asset ID。不会覆盖 GLB,也不会自动升级世界中的旧实例。
|
|
72
|
+
|
|
73
|
+
显式执行 `action_execute(skill="replaceAsset",args={id,assetId})` 升级实体。保留实例 ID、位置、旋转与缩放,重置交互状态;不支持直接升级 Agent embodiment,不允许替换正在持有的对象。通过 WorldCommands 事务执行,新资产放置或导航检查失败则恢复原实体和物理体。物理形状完全相同的非关节资产保留已有接触,不因求解器接触容差误拒绝纯材质升级。
|
|
74
|
+
|
|
75
|
+
## 持久化与生命周期
|
|
76
|
+
|
|
77
|
+
默认目录 `D:\AgentScapeData\mcp-assets`;CLI 可设置 `AGENTSCAPE_MCP_DATA_ROOT`。测试与其他设备应显式使用独立 dataRoot。单个数据目录由一个 MCP 写入实例管理,不支持多进程共享写入。
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
mcp-assets/
|
|
81
|
+
sandbox.json
|
|
82
|
+
owners/<身份SHA256>/
|
|
83
|
+
assets/pa_<版本>/
|
|
84
|
+
source.js
|
|
85
|
+
asset.glb
|
|
86
|
+
manifest.json
|
|
87
|
+
build.json
|
|
88
|
+
published.json
|
|
89
|
+
builds/<Build-ID>
|
|
90
|
+
requests/<requestId>
|
|
91
|
+
worlds/<saveId>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
资产临时目录写完并复核后原子发布,发布标识与已完成构建分离;不同内容不得覆盖同一版本。读取和恢复时复核源码、定义、GLB 和 Manifest 哈希、身份、格式与当前支持的 Three.js版本。不会执行保存文件中的源码。快照通过现有 SceneSerializer 恢复,资产依赖必须能解析;导入失败关闭新会话,不破坏其他世界。历史交互验收记录不作为恢复后的新动作证据,恢复后重新运行验收或动作。
|
|
95
|
+
|
|
96
|
+
内存世界关闭或TTL到期会释放;已保存资产和世界不会随会话删除。进程退出时构建任务取消;异常退出后遗留 running 记录变为 interrupted,不自动执行旧源码。默认保留所有已发布版本和世界存档,旧版本由快照依赖明确引用,不自动垃圾回收,避免删除仍被存档使用的版本。
|
|
97
|
+
|
|
98
|
+
首版每身份最多128个资产目录、1024个任务、128个存档;配额到达返回明确错误。未发布构建也保留用于审查,占用资产配额。尚未提供在线删除/自动GC接口;维护时应停服备份,再核对所有存档依赖后处理未发布或无引用数据。不能只按创建时间清除旧版本,也不应把数据目录提交到 Git。
|
|
99
|
+
|
|
100
|
+
## 验证
|
|
101
|
+
|
|
102
|
+
```powershell
|
|
103
|
+
# 普通回归;真实 Docker 测试明确标为需环境的集成测试
|
|
104
|
+
npm run test:mcp
|
|
105
|
+
|
|
106
|
+
# PC2 已执行:包含真实隔离容器、安全、物理与服务器重新创建的恢复验收
|
|
107
|
+
$env:AGENTSCAPE_SANDBOX_INTEGRATION='1'
|
|
108
|
+
npm run check
|
|
109
|
+
git diff --check
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
安全测试覆盖宿主 API、环境变量、网络、非法模块、循环、内存与几何超量、非法 Manifest、取消和容器清理。恢复测试重新建立整个 HTTP Server/SessionManager,再读取磁盘资产和场景;PC2 另通过 AgentDock 验证实际部署。没有进行宿主断电、Docker内核漏洞或多进程并发存储验收。
|
|
113
|
+
|
|
114
|
+
本版不实现任意 npm、持久运行的 JS、自定义 Shader 无损迁移、Studio 当前世界实时控制、任意远程资产 URL、自动推断任意可靠关节。接入级别 Visual / Physical / Interactive 与统一 Scene API 属于下一轮接口精简,本分支保留现有引擎系统边界。
|
|
115
|
+
|
|
116
|
+
Docker 参数依据:[官方容器运行文档](https://docs.docker.com/reference/cli/docker/container/run/)。
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { parseDefinition, canonical } from '../../application/programmatic-assets/ProgrammaticAssetContract.js';
|
|
3
|
+
import { assetVersion, hash } from './FileAssetRepository.js';
|
|
4
|
+
|
|
5
|
+
export class ProgrammaticAssets {
|
|
6
|
+
constructor({repository,builder,runner}) {Object.assign(this,{repository,builder,runner});this.running=new Map();this.locks=new Map();this.closed=false;}
|
|
7
|
+
async exclusive(owner,fn) {const previous=this.locks.get(owner)||Promise.resolve();const next=previous.catch(()=>{}).then(fn);this.locks.set(owner,next);try{return await next;}finally{if(this.locks.get(owner)===next)this.locks.delete(owner);}}
|
|
8
|
+
summary(job) {return {buildId:job.buildId,status:job.status,assetId:job.assetId,execution:job.execution || {status:job.status==='running'?'running':'unknown'},admission:job.admission,verification:job.verification || {status:'not-requested'},error:job.error,...(job.diagnostics?{diagnostics:job.diagnostics}:{})};}
|
|
9
|
+
async submit(owner,{source,definition,requestId,forceRebuild=false}) {
|
|
10
|
+
if(this.closed)throw new Error('ASSET_SERVICE_CLOSED');
|
|
11
|
+
if(typeof source!=='string'||!source.trim()||Buffer.byteLength(source)>32768)throw new Error('BUILD_SOURCE_LIMIT');
|
|
12
|
+
definition=definition == null ? null : parseDefinition(definition);
|
|
13
|
+
const environment=await this.runner.environment();
|
|
14
|
+
const version=assetVersion(source,definition,environment),assetId=`pa_${version}`;
|
|
15
|
+
return this.exclusive(owner,async()=>{
|
|
16
|
+
if(this.closed)throw new Error('ASSET_SERVICE_CLOSED');
|
|
17
|
+
const requestFile=this.repository.target(owner,'requests',requestId),fingerprint=hash(canonical({source,definition,environment,forceRebuild}));
|
|
18
|
+
try{const existing=await this.repository.json(requestFile);if(existing.fingerprint!==fingerprint)throw new Error('IDEMPOTENCY_CONFLICT');return this.status(owner,existing.buildId);}catch(e){if(e.code!=='ENOENT')throw e;}
|
|
19
|
+
if(!forceRebuild){
|
|
20
|
+
const matching=[...this.running.entries()].find(([,entry])=>entry.owner===owner&&entry.assetId===assetId);
|
|
21
|
+
if(matching){await this.repository.atomic(requestFile,{fingerprint,buildId:matching[0]});return this.status(owner,matching[0]);}
|
|
22
|
+
}
|
|
23
|
+
if(this.running.size>=4||[...this.running.values()].filter(j=>j.owner===owner).length>=2)throw new Error('BUILD_LIMIT');
|
|
24
|
+
if((await this.repository.ids(owner,'builds')).length>=1024)throw new Error('BUILD_STORAGE_QUOTA');
|
|
25
|
+
const job={buildId:randomUUID(),owner:hash(owner),status:'running',assetId};
|
|
26
|
+
if(!forceRebuild){try{const existing=await this.repository.get(owner,assetId);job.status='succeeded';job.admission=existing.build.admission;job.execution={status:'succeeded'};job.verification=existing.build.validation?.runtime;}catch(e){if(e.code!=='ENOENT')throw e;}}
|
|
27
|
+
const jobFile=this.repository.target(owner,'builds',job.buildId);
|
|
28
|
+
await this.repository.atomic(jobFile,job);await this.repository.atomic(requestFile,{fingerprint,buildId:job.buildId});
|
|
29
|
+
if(job.status==='running'){
|
|
30
|
+
const controller=new AbortController();const entry={owner,assetId,controller,promise:null};this.running.set(job.buildId,entry);
|
|
31
|
+
entry.promise=(async()=>{
|
|
32
|
+
try{
|
|
33
|
+
const built=await this.builder.build({source,definition,assetId},{signal:controller.signal});
|
|
34
|
+
if(controller.signal.aborted)throw new Error('BUILD_CANCELLED');
|
|
35
|
+
if(canonical(built.environment)!==canonical(environment))throw new Error('BUILD_ENVIRONMENT_CHANGED');
|
|
36
|
+
const stored=await this.repository.save(owner,{source,definition,environment,...built});
|
|
37
|
+
job.status='succeeded';job.admission=stored.build.admission;job.execution={status:'succeeded'};job.verification=stored.build.validation.runtime;
|
|
38
|
+
}catch(error){job.status=controller.signal.aborted?'cancelled':'failed';job.execution=error.execution || {status:job.status};job.error=/^[A-Z_]+$/.test(error.message)?error.message:'BUILD_FAILED';if(error.details&&JSON.stringify(error.details).length<=65536)job.diagnostics=error.details;}
|
|
39
|
+
finally{await this.repository.atomic(jobFile,job);this.running.delete(job.buildId);}
|
|
40
|
+
})();
|
|
41
|
+
entry.promise.catch(()=>{});
|
|
42
|
+
}
|
|
43
|
+
return this.summary(job);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async status(owner,buildId) {
|
|
47
|
+
let job;try{job=await this.repository.json(this.repository.target(owner,'builds',buildId));}catch(e){if(e.code==='ENOENT')throw new Error('BUILD_NOT_FOUND');throw e;}if(job.owner!==hash(owner))throw new Error('BUILD_NOT_FOUND');
|
|
48
|
+
if(job.status==='running'&&!this.running.has(buildId)){job.status='interrupted';job.error='BUILD_INTERRUPTED';await this.repository.atomic(this.repository.target(owner,'builds',buildId),job);}
|
|
49
|
+
return this.summary(job);
|
|
50
|
+
}
|
|
51
|
+
async cancel(owner,buildId) {await this.status(owner,buildId);const entry=this.running.get(buildId);if(entry){entry.controller.abort();await entry.promise;}return this.status(owner,buildId);}
|
|
52
|
+
async publish(owner,buildId,allowProvisional=false) {
|
|
53
|
+
const job=await this.status(owner,buildId);if(job.status!=='succeeded')throw new Error('BUILD_NOT_SUCCEEDED');
|
|
54
|
+
const asset=await this.repository.get(owner,job.assetId);
|
|
55
|
+
if(asset.build.admission.status==='rejected'||(asset.build.admission.status!=='ready'&&!allowProvisional))throw new Error('ASSET_NOT_READY');
|
|
56
|
+
await this.repository.publish(owner,job.assetId);return {assetId:job.assetId,version:asset.build.version,admission:asset.build.admission,published:true};
|
|
57
|
+
}
|
|
58
|
+
async inspect(owner,assetId,includeSource=false) {const a=await this.repository.get(owner,assetId);return {assetId,published:a.published,manifest:a.manifest,build:a.build,...(includeSource?{source:a.source}:{})};}
|
|
59
|
+
async close() {this.closed=true;for(const entry of this.running.values())entry.controller.abort();await Promise.allSettled([...this.running.values()].map(j=>j.promise));this.runner.close();}
|
|
60
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# AgentScape Remote MCP v0.3
|
|
2
|
+
|
|
3
|
+
自由代码项目可通过同一 Scene 工具发现并调用 `action:'custom'`、任意项目动作名和 JSON 参数;无验证器也允许执行,证据单列为未验证。现已新增统一 `action:'invoke'`:先 `scene_observe({target})` 读取 `capabilities`,再用 `scene_interact({interaction:{action:'invoke',target,name,actor?,partName?,args?}})` 调用已声明的资产关节、环境或代码项目动作。物理动作仍要求真实 Agent 和关节完成验证;保存重开不继承历史验证结果。代码、Shader、持续逻辑和作品迁移见 [Code Project](../../docs/modules/code-project.md),示例入口 `/examples/code-project/`。源码由本地项目入口显式运行,MCP 不自动执行远端源码。`studio_project` 的 `preview_batch` 可对最多 32 项文件/资源操作预览差异但不发布;`apply_batch` 使用 `previewId` 和 `expectedRevision` 原子持久化,`discard_batch` 放弃预览,`undo_batch` 在无后续编辑时撤销最近一批;预览仅在当前 Studio 会话内有效。
|
|
4
|
+
|
|
5
|
+
新增容器隔离的程序化资产构建/发布、不可变版本与文件存储、可信世界保存恢复。原有 33 个工具继续兼容;新增 4 个 Studio Live Bridge 配对/会话工具,使用同一个 `agentscape-world` 连接。契约、示例、隔离设施和保存边界见 [PROGRAMMATIC-ASSETS.md](./PROGRAMMATIC-ASSETS.md)。
|
|
6
|
+
|
|
7
|
+
新增 scene_object_definition:将 AI 声明与真实 Three.js 节点结构分析结合,并通过 inspect/preview/apply/fork 对单实例进行版本化定点修正。详见 docs/modules/object-forge-refinement.md。当前 MCP 共 42 个工具。
|
|
8
|
+
|
|
9
|
+
Scene 工具为 `scene_thermal`(Asset Forge 材料实验查询、热功率和真实时步)、`scene_observe`、`scene_apply`、`scene_add_model`、`scene_interact`、`scene_job`、`scene_cancel`、`scene_verify`、`scene_save`、`scene_import`、`scene_object_definition`、`scene_set_style`。它们使用与 SDK/Studio 相同的 Scene 应用服务和 Runtime。`scene_interact` 立即返回 JobRef,由宿主推进模拟,调用方轮询任务并分别检查执行状态与验证证据。Recipe 可以直接作为 scene_add_model 的 model.asset 输入,无需生成 JavaScript。
|
|
10
|
+
|
|
11
|
+
外部 GLB 可通过 `scene_add_model` 的 `mode: "prepare"` 生成能力候选(包含 `kinematics.hypotheses`);若希望在不注册资产的情况下做隔离 Rapier 机械测试,可再次调用相同工具并设置 `mode: "screen"`、`model: {asset: 相同的 GLB source, proposalId: 上轮提案 ID, hypothesisIds?: 候选 ID[]}`。筛选逐方向返回 `trials` 和碰撞、稳定性报告,**即便机械测试通过也不会授权语义动作**。最后才使用默认 `mode: "add"`,附明确审核参数进行正式编译、物理验证和注册;配套 URDF 仍复用既有 Compiler Provider。接口、证据边界、Studio 审核入口和传输配额见 [资产交互化流程](../../docs/asset-interaction-pipeline.md)。
|
|
12
|
+
|
|
13
|
+
`scene_observe({ worldSessionId, target, actor? })` 等价于 SDK 的 `scene.inspect(target, { actor })`,返回资产或环境契约的统一能力说明。省略 target 时,场景观察的 `affordances` 包含这些对象的能力列表(最多 100 项,total 为总数)。能力在每次查询时读取当前状态,不额外保存对象状态。
|
|
14
|
+
|
|
15
|
+
每项动作包含 `parameters`、`execution`、`available` 和不可用时的 `reason`。未提供 actor 时,具身动作的 available 为 null,表示未检查可达性;提供后复用当前距离、遮挡及持有能力检查。available 只描述当前检查结果,不能替代执行后的碰撞、放置空间或关节完成验证。
|
|
16
|
+
|
|
17
|
+
`execution: interaction` 的动作统一调用 `scene_interact`;`world-action` 的环境契约现也可通过同一个 `scene_interact` 调用(open/close、turn_on/turn_off、pull_out/return、write),交由 Runtime 的 `WorldCommands.executeAffordance` 执行并核对后置状态。`editor` 使用 `scene_apply`,不代表 Agent 施力。环境契约的 `evidenceKind` 和 `physicsVerified=false` 不得冒充真实物理力学验证。Studio 的同一交互入口与验收边界参见 [统一交互](../../docs/studio-unified-interactions.md)。
|
|
18
|
+
|
|
19
|
+
通用物理操作不要求 Manifest 声明专用动作:动态刚体可发现 push/drag/rotate,真实滑动/旋转关节可发现 slide/rotateJoint。固定、持有、忙碌或缺少物理解算能力的对象会返回具体阻塞原因。物理元数据的 body 为资产声明,currentBody 为查询时的实际刚体类型。
|
|
20
|
+
|
|
21
|
+
| action | args | 执行和验证 |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| push / drag | direction: 非零水平向量;distance: (0, 5] 米;maxForce?: (0, 1000] 牛,默认 100 | 从实际包围盒计算接触代理位置,通过 applyForce 驱动;验证位移、偏移和静止状态 |
|
|
24
|
+
| rotate | axis: 非零世界轴;angle: [-π, π] 弧度且非零;maxTorque?: (0, 1000] 牛米,默认 100 | applyTorque 驱动;验证真实姿态、轴向偏移与角速度 |
|
|
25
|
+
| slide / rotateJoint | part: 部件名;target: 绝对关节坐标,或 distance / angle: 相对变化量(二选一) | 仅驱动真实物理关节,检查限位并复用现有关节稳定、停滞与超时验证 |
|
|
26
|
+
|
|
27
|
+
例如 `scene_interact({ worldSessionId, requestId, interaction: { actor: "agent_01", target: "new_box", action: "push", args: { direction: [1, 0, 0], distance: 1 } } })` 返回 JobRef,随后使用 scene_job 查询结果。成功必须同时有终态 succeeded 和 verification.status=verified。实际证据区分 rigid-body-force、rigid-body-torque 和 joint-motor。
|
|
28
|
+
|
|
29
|
+
这些操作使用现有 1.5 米交互半径内的接触代理,推/拖会选择相应方向的可达站位;执行中持续复核距离、遮挡、持有状态和碰撞。它不是手指抓取,graspVerified 不会被标为 true。遇阻、偏移、超时或取消时保留真实的部分运动,报告未验证;不修改物体坐标来完成目标。箱子推动一米、不同质量、墙体阻挡、椅子拖动、轮子扭矩、滑动/旋转关节及取消均有 Runtime 验收,推动一米还覆盖真实 HTTP MCP 客户端。
|
|
30
|
+
|
|
31
|
+
保存和历史快照从 PhysicsSystem 读取部件的实际姿态及电机目标;恢复时按快照恢复,不另建关节状态缓存。实时物理操作与快照恢复路径分开。
|
|
32
|
+
|
|
33
|
+
注意:Headless MCP 没有渲染画布。调用 `scene_set_style` 成功后,返回的 `status=deferred`、`rendered=false`、`applied=null` 表示 StylePack 已记录到场景配置,**不表示实际画面已经切换或视觉渲染通过验收**。请在 Studio 或带图形渲染器的 SDK 客户端另行验证视觉效果;不要把无渲染器时的 deferred 状态误报为已应用。
|
|
34
|
+
|
|
35
|
+
`scene_import` 接受此前 `scene_save` 导出的完整 `bundle`,在当前私有世界或已连接 Studio 中导入,复用 Scene 的隔离校验、资源哈希和失败回滚;MCP 单次请求受 4 MiB 配额约束。仅导入世界资产与状态,不恢复历史动作已验证证据。`world_save/world_restore` 仍只接受内置资产与同身份已发布的不可变资产;临时 `scene_add_model` 编译资产须使用 `scene_save/scene_import` 完成跨会话恢复。
|
|
36
|
+
|
|
37
|
+
`scene_save` 返回有资源字节和锁定哈希的完整项目包,仍受服务端导出配额限制。旧 world_export 的 JSON-only 语义保留。新版资产引用 `asset://sha256/<版本摘要>` 可以引用同一身份已发布的 pa_ 资产;未发布或其他身份的资产不能借此接入世界。
|
|
38
|
+
|
|
39
|
+
v0.2 的七个草稿接口和参数化 `world_verify` 保留;远程源码执行现已要求同一受限容器,不再仅依赖 Worker/WASM。原草稿工作流见 [AUTHORING.md](./AUTHORING.md)。
|
|
40
|
+
|
|
41
|
+
独立 Node.js 进程,为外部 Agent 提供可观察、可执行、可验证的私有 3D 世界。无需内部 LLM,不调用在线生成。SDK 固定为官方 MCP v2 2.4.0。
|
|
42
|
+
|
|
43
|
+
```mermaid
|
|
44
|
+
flowchart TD
|
|
45
|
+
Client[ChatGPT / Claude / Codex / OpenCode] --> HTTP[MCP Streamable HTTP + Bearer 鉴权]
|
|
46
|
+
HTTP --> Sessions[SessionManager: 身份、TTL、互斥、幂等]
|
|
47
|
+
Sessions --> Host[HeadlessWorldHost: 正式 createSession、固定时步]
|
|
48
|
+
Host --> Tools[AgentTools / SkillRegistry / Policy]
|
|
49
|
+
Tools --> Commands[WorldCommands / Runtime mutation 与 History]
|
|
50
|
+
Commands --> Runtime[WorldRuntime / Physics / Navigation / Interaction]
|
|
51
|
+
Host --> Queries[WorldQueries / WorldObservation / Acceptance]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Windows 启动
|
|
55
|
+
|
|
56
|
+
在独立检出目录执行。Node.js 20+,本次使用本机 Node.js;安装依赖不会加载 Studio 私有配置。
|
|
57
|
+
|
|
58
|
+
```powershell
|
|
59
|
+
cd D:\a_programming_list\A-Python-Project\wk08\AgentScape
|
|
60
|
+
npm ci
|
|
61
|
+
$credential = [Convert]::ToHexString([Security.Cryptography.RandomNumberGenerator]::GetBytes(32))
|
|
62
|
+
$env:AGENTSCAPE_MCP_TOKENS = ConvertTo-Json -Compress -AsArray @{ identity = 'my-agent'; token = $credential }
|
|
63
|
+
npm run mcp:serve
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
客户端请求头配置 `Authorization: Bearer <credential>`,URL 为 `http://127.0.0.1:39015/mcp`。凭据需通过私有配置安全交给客户端。服务不打印凭据。环境变量包含 JSON 数组,可为不同客户端配置不同 identity/token。相同 identity 代表同一访问主体,能够共享该主体创建的世界。不要复用 Studio 或模型 API 密钥。
|
|
67
|
+
|
|
68
|
+
只监听 127.0.0.1,端口冲突直接失败。Ctrl+C 关闭全部世界。默认快照写入当前检出的 `.mcp-sessions/<worldSessionId>/`,不会加载 Studio 存档。工作目录必须是独立检出。
|
|
69
|
+
|
|
70
|
+
## 工具接口
|
|
71
|
+
|
|
72
|
+
| 工具 | 参数 | 结果 |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| session_create | template: monument-hall(默认) | worldSessionId、tick、状态;预置 agent_01 / cabinet_01 / cup_01 / table_01,杯子位于柜内 |
|
|
75
|
+
| session_status | worldSessionId | 世界与执行状态、闲置到期时间 |
|
|
76
|
+
| session_close | worldSessionId | 取消执行并释放 Runtime |
|
|
77
|
+
| world_observe | worldSessionId、offset=0、limit=25(最多50) | 有界对象、Agent、空间关系和分页游标 |
|
|
78
|
+
| object_inspect | worldSessionId、id | 对象与关节、空间证据 |
|
|
79
|
+
| skills_list | worldSessionId | 六个审核动作及各自 JSON Schema |
|
|
80
|
+
| action_execute | worldSessionId、skill、args、requestId(UUID) | state、真实 Runtime result、steps、tick |
|
|
81
|
+
| world_verify | worldSessionId | verified/unverified、逐项验收证据、持物状态 |
|
|
82
|
+
| world_export | worldSessionId | fileName、bytes、snapshot、scope=scene-json-only |
|
|
83
|
+
|
|
84
|
+
### Studio 实时世界的轻量观察与批量编辑
|
|
85
|
+
|
|
86
|
+
Studio 已自动连接时,`scene_observe` 可不传 `worldSessionId`(仅允许一个自动连接的本地世界)。默认返回完整对象、交互能力及空间关系;传入 `target` 则检查单个对象;传入 `limit`(1–1000)和可选 `offset` 则返回轻量 `agentscape.scene-object-page`,包含 `total`、`objects` 和 `nextOffset`,不会展开全局空间关系。`offset` 必须配合 `limit`,且分页参数不能与 `target` 同时使用。
|
|
87
|
+
|
|
88
|
+
批量编辑使用 `scene_apply`,一个 UUID `requestId` 对应最多 32 个 `operations`。Runtime 仍逐条执行,失败时保留已执行操作并返回 `applied`、`failed`、`notRun`;这**不是原子回滚事务**。SceneGraph 在一次批量调用结束后合并关系更新,避免无意义的重复全量重建。大量相同资产推荐先注册资产,再使用 `scene_apply` 按引用批量实例化。
|
|
89
|
+
|
|
90
|
+
场景关系 CPU 基准:`node dev/scripts/benchmark-scene-graph.mjs`。它只测试稀疏对象的 SceneGraph,不能作为 MCP 往返、GPU、物理或导航性能指标。
|
|
91
|
+
|
|
92
|
+
MCP Transport 使用无状态 HTTP;没有 MCP 协议会话 ID,worldSessionId 专属于世界生命周期。每个工具调用仍要求 Bearer 鉴权。SDK 处理协议消息及参数验证;工具执行错误返回 isError 和脱敏错误码。
|
|
93
|
+
|
|
94
|
+
动作白名单:spawnAsset、moveObject、navigateTo、approachAndInteract、approachAndPickup、approachAndPlace。参数完全遵循 skills_list 返回的 Schema;拒绝未知字段。初始资产为本地 agent / cabinet / cup / table,也允许实例化当前会话已编译注册的创作资产。动作接口不能指定 URL 或磁盘目录;Three.js 代码只能通过 authoring_execute 在受限引擎内执行。profile、actor 的授权身份均由服务端固定,actorId 只是世界内对象 ID。
|
|
95
|
+
|
|
96
|
+
按顺序调用(每次动作生成独立 requestId;重试相同动作使用原 ID):
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{"skill":"approachAndInteract","args":{"actorId":"agent_01","targetId":"cabinet_01","action":"open"}}
|
|
100
|
+
{"skill":"approachAndPickup","args":{"actorId":"agent_01","targetId":"cup_01"}}
|
|
101
|
+
{"skill":"approachAndPlace","args":{"actorId":"agent_01","supportId":"table_01","surfaceId":"top"}}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
以上动作参数还需添加 worldSessionId 和 requestId。之后执行 world_verify、world_export、session_close。调用成功不代表动作成功:读取 state(verified / unverified / blocked / failed / requested)和 result 中的最终证据。请求型返回不提升为 verified。
|
|
105
|
+
|
|
106
|
+
单世界只允许一个操作,包括读取、验收和导出;并发返回 SESSION_BUSY。Runtime 负责事务、回滚和 History。requestId 绑定动作和参数,冲突拒绝;会话内最多保存256个动作幂等记录,不丢弃后重放。
|
|
107
|
+
|
|
108
|
+
## 安全与资源
|
|
109
|
+
|
|
110
|
+
默认最多4个世界,空闲15分钟回收;每世界64个对象、256次动作;单动作最多12000个 1/60 秒模拟步和30秒墙钟时间。每12步让出事件循环。取消/超时重复终止 Runtime interaction/locomotion,并给予最多240步清理;无法收敛则关闭该 Host,禁止继续动作。
|
|
111
|
+
|
|
112
|
+
HTTP 请求体最多64 KiB,每身份每分钟120次请求;Host 白名单默认 localhost/127.0.0.1,Origin 默认全部拒绝(无 Origin 的非浏览器客户端可用)。headers 10秒、request 35秒超时。快照最多4 MiB,临时文件 JSON 复核后原子 rename;客户端不能指定路径。快照是 SceneSerializer JSON,不包含完整 GLB/纹理作品包。
|
|
113
|
+
|
|
114
|
+
对象和动作预算限制会话增长;当前 Node.js 同进程承载多个 Runtime,不提供每会话操作系统级硬内存隔离。需要硬内存限制时应采用受限进程/容器部署,不应将本版宣传为任意用户公网沙箱。
|
|
115
|
+
|
|
116
|
+
进程崩溃后内存世界丢失,启动时不会恢复任何旧世界、鉴权所有权或临时快照;旧的快照和未发布 .tmp 文件可能留在私有目录,须由服务拥有者离线清理。v0.1 不支持快照导入,错误导入不构成开放接口。
|
|
117
|
+
|
|
118
|
+
## 远程连接
|
|
119
|
+
|
|
120
|
+
通过可信 TLS 反向代理或隧道转发到 127.0.0.1:39015,保留 Authorization。代理应将上游 Host 设为 localhost;浏览器客户端需由部署代码向 startServer 的 security.origins 传入明确完整 Origin,禁止通配。默认 CLI 不开放跨域浏览器访问。不要暴露本地端口。
|
|
121
|
+
|
|
122
|
+
这是私有 Bearer 部署,不包含 OAuth 授权发现;要求 OAuth 的托管客户端需要额外授权层。已通过 PC2 AgentDock 的真实工具调用验证完整工作流,部署详情见 DEPLOYMENT-PC2.md;其他客户端各自的直连配置尚未验证。
|
|
123
|
+
|
|
124
|
+
## 文件职责与验证
|
|
125
|
+
|
|
126
|
+
- main.mjs:独立 HTTP 启动及关闭、官方 SDK Transport。
|
|
127
|
+
- registerTools.js:九工具、严格动作参数 Schema、调用映射。
|
|
128
|
+
- security.js:私有身份鉴权、Host/Origin、请求体和频率预算。
|
|
129
|
+
- SessionManager.js:所有权、互斥、幂等、TTL、原子导出。
|
|
130
|
+
- HeadlessWorldHost.js:复用 createSession/WorldBuilder/AgentTools,独立模拟驱动、动作证据和释放。
|
|
131
|
+
- tasks.jsonl:阶段任务;acceptance-evidence.json:真实 MCP 验收记录。
|
|
132
|
+
- tests/mcp/:官方 HTTP Client 物理任务、隔离、安全和生命周期自动断言。
|
|
133
|
+
- 根 package.json/lock:固定 MCP 依赖和启动/测试脚本;.gitignore:排除私有会话目录。
|
|
134
|
+
|
|
135
|
+
```powershell
|
|
136
|
+
npm run test:mcp
|
|
137
|
+
npm run check
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
测试覆盖未鉴权、Origin、请求体限制、频率限制、端口冲突、跨身份隔离、未知 Session、非法参数、白名单、幂等冲突、互斥、取消、超时、异常解锁、TTL、关闭释放、导出预算、原子发布和残留文件不恢复。真实任务使用 Rapier、Recast、柜体 GLB;没有在线模型调用。
|
|
141
|
+
|
|
142
|
+
已知语义限制:资产/布局准入仍可能 provisional;这与真实动作及最终支撑关系 verified 是不同证据。pickup 为 kinematic attachment,不证明夹持力。未提供截图、在线生成、Studio 同步、多用户公网账号、完整作品包迁移。
|
|
143
|
+
|
|
144
|
+
机械资产 v1:scene_add_model 的 model.asset 可提交 agentscape.mechanical-draft JSON(几何节点、旋转铰链、滑轨),先经过 GLB 编译与隔离物理验证。详见 [机械资产创建工作台](../../docs/capabilities/mechanical-asset-workbench.md)。
|
|
145
|
+
|
|
146
|
+
Studio Live Bridge:调用 studio_pair_create 取得一次性配对码,然后在本机 Studio 的「MCP 连接」中明确授权;通过返回的 worldSessionId 使用既有 Scene 工具操作浏览器当前世界。切换世界自动撤销连接。完整说明见 [Studio Live Bridge](../../docs/mcp-studio-live-bridge.md)。
|
|
147
|
+
|
|
148
|
+
本机 Studio MCP 自动连接默认开启:打开 Studio 后由浏览器自动注册当前世界,认证 MCP 客户端可省略 Scene 工具的 worldSessionId;手动配对仍可在高级设置中使用。见 [自动连接说明](../../docs/mcp-studio-auto-connect.md)。
|
|
149
|
+
|
|
150
|
+
项目与全局资产:scene_save/scene_import 保存 Object Forge 可编辑声明和 revision;asset_publish_project 发布当前用户全局不可变版本;scene_object_definition 的 fork 从全局资产复制当前项目可编辑定义。详见 docs/modules/project-global-assets.md。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateRemoteAuthoringDocument, remoteAuthoringLimits } from '../../application/code-execution/RemoteAuthoringDocument.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { rolldown } from 'rolldown';
|
|
5
|
+
let cached;
|
|
6
|
+
export function sandboxBundle() {
|
|
7
|
+
cached ||= (async()=>{
|
|
8
|
+
const build=await rolldown({input:fileURLToPath(new URL('./AuthoringSandboxEntry.js',import.meta.url)),platform:'neutral'});
|
|
9
|
+
let code;try{code=(await build.generate({format:'iife',name:'AuthoringSandbox'})).output[0].code;}finally{await build.close();}
|
|
10
|
+
const runner=await readFile(new URL('./sandbox/run.mjs',import.meta.url),'utf8');
|
|
11
|
+
return {code,runner,digest:createHash('sha256').update(code).update(runner).digest('hex')};
|
|
12
|
+
})();return cached;
|
|
13
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, writeFile, readFile, rename, rm } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { HeadlessWorldHost } from './HeadlessWorldHost.js';
|
|
5
|
+
import { SceneObjectForge } from '../../application/object-forge/SceneObjectForge.js';
|
|
6
|
+
export class SessionManager {
|
|
7
|
+
constructor({root,maxSessions=4,ttlMs=900000,maxExportBytes=4194304,hostOptions={},repository=null}={}) {
|
|
8
|
+
this.root=path.resolve(root); this.maxSessions=maxSessions; this.ttlMs=ttlMs; this.maxExportBytes=maxExportBytes; this.hostOptions=hostOptions; this.sessions=new Map(); this.pending=0;
|
|
9
|
+
this.timer=setInterval(()=>this.reap().catch(()=>{}),Math.min(ttlMs,30000)); this.timer.unref();
|
|
10
|
+
this.repository=repository;this.restoreRequests=new Map();
|
|
11
|
+
}
|
|
12
|
+
async create(owner,{assetIds=[]}={}) {
|
|
13
|
+
if(this.disposed) throw new Error('MANAGER_CLOSED');
|
|
14
|
+
if(this.sessions.size+this.pending>=this.maxSessions) throw new Error('SESSION_LIMIT');
|
|
15
|
+
this.pending++;
|
|
16
|
+
let host;
|
|
17
|
+
try {
|
|
18
|
+
host=await HeadlessWorldHost.create({...this.hostOptions,owner,repository:this.repository,assetIds});
|
|
19
|
+
if(this.disposed) throw new Error('MANAGER_CLOSED');
|
|
20
|
+
const id=randomUUID(),directory=path.join(this.root,id); await mkdir(directory,{recursive:true});
|
|
21
|
+
this.sessions.set(id,{id,owner,host,forge:new SceneObjectForge(),directory,lastUsed:Date.now(),active:null,closing:false,requests:new Map()});
|
|
22
|
+
return this.status(owner,id);
|
|
23
|
+
} catch(e) { host?.close(); throw e; } finally { this.pending--; }
|
|
24
|
+
}
|
|
25
|
+
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; }
|
|
26
|
+
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}; }
|
|
27
|
+
async run(owner,id,operation,{requestId,fingerprint,signal}={}) {
|
|
28
|
+
const s=this.get(owner,id);
|
|
29
|
+
if(requestId && s.requests.has(requestId)) {
|
|
30
|
+
const previous=s.requests.get(requestId); if(previous.fingerprint!==fingerprint) throw new Error('IDEMPOTENCY_CONFLICT'); return previous.promise;
|
|
31
|
+
}
|
|
32
|
+
if(s.active) throw new Error('SESSION_BUSY');
|
|
33
|
+
if(requestId && s.requests.size>=256) throw new Error('REQUEST_BUDGET_EXHAUSTED');
|
|
34
|
+
const controller=new AbortController(); const abort=()=>controller.abort(); signal?.addEventListener('abort',abort,{once:true}); if(signal?.aborted) abort();
|
|
35
|
+
const promise=Promise.resolve().then(()=>operation(s,controller.signal)); s.active={controller,promise};
|
|
36
|
+
if(requestId) s.requests.set(requestId,{fingerprint,promise});
|
|
37
|
+
try { return await promise; } finally { signal?.removeEventListener('abort',abort); s.active=null; s.lastUsed=Date.now(); }
|
|
38
|
+
}
|
|
39
|
+
async export(s) {
|
|
40
|
+
if(s.host.world.mutationOwner) throw new Error('SESSION_BUSY');
|
|
41
|
+
const snapshot=s.host.world.serialize({name:'Remote MCP snapshot'}),json=JSON.stringify(snapshot);
|
|
42
|
+
if(Buffer.byteLength(json)>this.maxExportBytes) throw new Error('EXPORT_LIMIT');
|
|
43
|
+
const name=`snapshot-${randomUUID()}.json`,temporary=path.join(s.directory,`${name}.tmp`),target=path.join(s.directory,name);
|
|
44
|
+
try { await writeFile(temporary,json,{flag:'wx'}); JSON.parse(await readFile(temporary,'utf8')); await rename(temporary,target); }
|
|
45
|
+
finally { await rm(temporary,{force:true}); }
|
|
46
|
+
return {state:'exported',fileName:name,bytes:Buffer.byteLength(json),snapshot,scope:'scene-json-only'};
|
|
47
|
+
}
|
|
48
|
+
async save(owner,s) {
|
|
49
|
+
if(s.host.world.mutationOwner) throw new Error('SESSION_BUSY');
|
|
50
|
+
if(!this.repository)throw new Error('PERSISTENCE_UNAVAILABLE');
|
|
51
|
+
return this.repository.saveWorld(owner,s.host.world.serialize({name:'Saved MCP world'}));
|
|
52
|
+
}
|
|
53
|
+
async restore(owner,saveId,requestId) {
|
|
54
|
+
if(!this.repository)throw new Error('PERSISTENCE_UNAVAILABLE');
|
|
55
|
+
const key=JSON.stringify([owner,requestId]);
|
|
56
|
+
const existing=this.restoreRequests.get(key);
|
|
57
|
+
if(existing){if(existing.saveId!==saveId)throw new Error('IDEMPOTENCY_CONFLICT');return existing.promise;}
|
|
58
|
+
if(this.restoreRequests.size>=256)throw new Error('RESTORE_REQUEST_LIMIT');
|
|
59
|
+
const promise=(async()=>{
|
|
60
|
+
const data=await this.repository.loadWorld(owner,saveId);
|
|
61
|
+
const session=await this.create(owner,{assetIds:data.dependencies.map(d=>d.assetId)});
|
|
62
|
+
try{await this.run(owner,session.worldSessionId,s=>s.host.world.restoreSnapshot(data.snapshot));return this.status(owner,session.worldSessionId);}
|
|
63
|
+
catch(error){await this.close(owner,session.worldSessionId);throw error;}
|
|
64
|
+
})();
|
|
65
|
+
this.restoreRequests.set(key,{saveId,promise});return promise;
|
|
66
|
+
}
|
|
67
|
+
async exportAuthoring(s) {
|
|
68
|
+
const document=s.host.session.authoring.export();
|
|
69
|
+
const draft={schema:'agentscape.remote-authoring',schemaVersion:1,sources:s.host.authoringSources,document,promotions:s.host.session.promotion.exportState()};
|
|
70
|
+
const json=JSON.stringify(draft);
|
|
71
|
+
if(Buffer.byteLength(json)>this.maxExportBytes) throw new Error('EXPORT_LIMIT');
|
|
72
|
+
const fileName=`authoring-${randomUUID()}.json`,temporary=path.join(s.directory,`${fileName}.tmp`),target=path.join(s.directory,fileName);
|
|
73
|
+
try {await writeFile(temporary,json,{flag:'wx'});JSON.parse(await readFile(temporary,'utf8'));await rename(temporary,target);}
|
|
74
|
+
finally {await rm(temporary,{force:true});}
|
|
75
|
+
return {state:'exported',fileName,bytes:Buffer.byteLength(json),scope:'authoring-source-and-document-only',draft};
|
|
76
|
+
}
|
|
77
|
+
async close(owner,id) { const s=this.get(owner,id); s.closing=true; s.active?.controller.abort(); try { await s.active?.promise.catch(()=>{}); s.host.close(); } finally { this.sessions.delete(id); } return {worldSessionId:id,state:'closed'}; }
|
|
78
|
+
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); }
|
|
79
|
+
async dispose() { this.disposed=true; clearInterval(this.timer); await Promise.all([...this.sessions.values()].map(s=>this.close(s.owner,s.id))); }
|
|
80
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const DEFAULT_ORIGINS=[
|
|
2
|
+
'http://127.0.0.1:5173','http://localhost:5173',
|
|
3
|
+
'http://127.0.0.1:4178','http://localhost:4178',
|
|
4
|
+
'http://127.0.0.1:4189','http://localhost:4189'
|
|
5
|
+
];
|
|
6
|
+
const send=(res,status,data,origin)=>{
|
|
7
|
+
res.writeHead(status,{'content-type':'application/json; charset=utf-8',
|
|
8
|
+
'cache-control':'no-store',...(origin?{'access-control-allow-origin':origin,'vary':'Origin'}:{})});
|
|
9
|
+
res.end(JSON.stringify(data));
|
|
10
|
+
};
|
|
11
|
+
const body=async(req)=>{
|
|
12
|
+
const chunks=[];let total=0;
|
|
13
|
+
for await(const chunk of req){
|
|
14
|
+
total+=chunk.length;
|
|
15
|
+
if(total>1024*1024)throw Object.assign(new Error('BRIDGE_BODY_LIMIT'),{status:413});
|
|
16
|
+
chunks.push(chunk);
|
|
17
|
+
}
|
|
18
|
+
try{return JSON.parse(Buffer.concat(chunks).toString('utf8'));}
|
|
19
|
+
catch{throw Object.assign(new Error('BRIDGE_INVALID_JSON'),{status:400});}
|
|
20
|
+
};
|
|
21
|
+
const fail=(code,status=400)=>Object.assign(new Error(code),{status});
|
|
22
|
+
export async function handleStudioBridgeHttp(req,res,bridge,{origins=DEFAULT_ORIGINS}={}) {
|
|
23
|
+
const endpoint=req.url?.split('?')[0] || '';
|
|
24
|
+
if(!endpoint.startsWith('/studio-bridge/'))return false;
|
|
25
|
+
const host=String(req.headers.host||'').split(':')[0];
|
|
26
|
+
const origin=req.headers.origin;
|
|
27
|
+
if(!['127.0.0.1','localhost'].includes(host))return send(res,403,{code:'BRIDGE_HOST_FORBIDDEN'}),true;
|
|
28
|
+
if(!origin || !origins.includes(origin))return send(res,403,{code:'BRIDGE_ORIGIN_FORBIDDEN'}),true;
|
|
29
|
+
if(req.method==='OPTIONS'){
|
|
30
|
+
res.writeHead(204,{'access-control-allow-origin':origin,'access-control-allow-methods':'POST, OPTIONS',
|
|
31
|
+
'access-control-allow-headers':'content-type','access-control-max-age':'600','vary':'Origin'});
|
|
32
|
+
res.end();return true;
|
|
33
|
+
}
|
|
34
|
+
if(req.method!=='POST')return send(res,405,{code:'METHOD_NOT_ALLOWED'},origin),true;
|
|
35
|
+
try{
|
|
36
|
+
const input=await body(req);
|
|
37
|
+
let data;
|
|
38
|
+
if(endpoint==='/studio-bridge/auto-register'){
|
|
39
|
+
data=bridge.registerAuto(input.instanceId,input.worldId);
|
|
40
|
+
}else if(endpoint==='/studio-bridge/connect'){
|
|
41
|
+
if(typeof input.pairCode!=='string')throw fail('PAIR_CODE_INVALID');
|
|
42
|
+
data=bridge.connect(input.pairCode);
|
|
43
|
+
}else if(endpoint==='/studio-bridge/poll'){
|
|
44
|
+
data=await bridge.poll(input.worldSessionId,input.studioToken);
|
|
45
|
+
}else if(endpoint==='/studio-bridge/reply'){
|
|
46
|
+
data=bridge.reply(input.worldSessionId,input.studioToken,input);
|
|
47
|
+
}else if(endpoint==='/studio-bridge/disconnect'){
|
|
48
|
+
bridge.authorized(input.worldSessionId,input.studioToken);
|
|
49
|
+
bridge.disconnect(input.worldSessionId);
|
|
50
|
+
data={status:'disconnected'};
|
|
51
|
+
}else return send(res,404,{code:'BRIDGE_ROUTE_NOT_FOUND'},origin),true;
|
|
52
|
+
send(res,200,data,origin);
|
|
53
|
+
}catch(error){
|
|
54
|
+
const code=/^[A-Z_]+$/.test(error.code||error.message||'') ? error.code||error.message : 'BRIDGE_REQUEST_FAILED';
|
|
55
|
+
send(res,error.status||400,{code},origin);
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|