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,128 @@
|
|
|
1
|
+
|
|
2
|
+
export const COMPLETE_OUTCOMES = new Set(['verified', 'accepted']);
|
|
3
|
+
|
|
4
|
+
export const stableValue = (value) => {
|
|
5
|
+
if (Array.isArray(value)) return `[${value.map(stableValue).join(',')}]`;
|
|
6
|
+
if (value && typeof value === 'object') return `{${Object.keys(value).sort().map((key)=>`${JSON.stringify(key)}:${stableValue(value[key])}`).join(',')}}`;
|
|
7
|
+
return JSON.stringify(value);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const EMBODIED_STRING_ARGS = Object.freeze({
|
|
11
|
+
approachAndInteract:['actorId','targetId','action','partName'],
|
|
12
|
+
approachAndPickup:['actorId','targetId'],
|
|
13
|
+
approachAndPlace:['actorId','supportId','targetId','surfaceId']
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const unwrapRedundantQuotedString = (value) => {
|
|
17
|
+
if (typeof value !== 'string') return value;
|
|
18
|
+
const trimmed=value.trim();
|
|
19
|
+
if (trimmed.length < 2 || trimmed[0] !== '"' || trimmed.at(-1) !== '"') return value;
|
|
20
|
+
try {
|
|
21
|
+
const parsed=JSON.parse(trimmed);
|
|
22
|
+
return typeof parsed === 'string' ? parsed : value;
|
|
23
|
+
} catch { return value; }
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const normalizeModelToolCall = (call) => {
|
|
27
|
+
if (!call || typeof call !== 'object') return call;
|
|
28
|
+
const args={...(call.args || {})};
|
|
29
|
+
for (const key of EMBODIED_STRING_ARGS[call.name] || []) {
|
|
30
|
+
if (key in args) args[key]=unwrapRedundantQuotedString(args[key]);
|
|
31
|
+
}
|
|
32
|
+
if (EMBODIED_STRING_ARGS[call.name] && args.actorId == null && args.agentId != null) {
|
|
33
|
+
args.actorId=unwrapRedundantQuotedString(args.agentId);
|
|
34
|
+
delete args.agentId;
|
|
35
|
+
}
|
|
36
|
+
if (call.name === 'approachAndPlace' && args.supportId == null && args.targetId != null) {
|
|
37
|
+
args.supportId=args.targetId;
|
|
38
|
+
delete args.targetId;
|
|
39
|
+
}
|
|
40
|
+
return {...call,args};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const mutationIdentity = (call, result = null) => {
|
|
44
|
+
const args = call.args || {};
|
|
45
|
+
if(call.name==='interactScene')return `interactScene:${stableValue(args.interaction || {})}`;
|
|
46
|
+
const keys = ['actorId','id','targetId','supportId','blockerId','blockerPartName','blockerAction','action','assetId','instanceId','end'];
|
|
47
|
+
const scope = Object.fromEntries(keys.filter((key)=>args[key] != null).map((key)=>[key,args[key]]));
|
|
48
|
+
if (call.name === 'addSceneModel' && args.model?.id != null) scope.modelId = args.model.id;
|
|
49
|
+
const partName = args.partName ?? result?.partName ?? result?.interaction?.part ?? result?.actionSweep?.partName;
|
|
50
|
+
if (partName != null) scope.partName=partName;
|
|
51
|
+
return `${call.name}:${stableValue(scope)}`;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const worldMutationRevisionId=(entry)=>{
|
|
55
|
+
if(entry?.tool==='runWorldPipeline') return entry.args?.plan?.revision?.id || null;
|
|
56
|
+
if(entry?.tool==='recompileWorldRevision') return entry.args?.proposal?.nextRevisionId || null;
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const worldPlanIdentity = (call) => {
|
|
61
|
+
if(call?.name!=='runWorldPipeline') return null;
|
|
62
|
+
const plan=call.args?.plan || {};
|
|
63
|
+
const {revision:_revision,provenance:_provenance,...semanticPlan}=plan;
|
|
64
|
+
return `runWorldPipeline:${stableValue({plan:semanticPlan})}`;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const worldProposalLineageFromExecution = (call,result) => {
|
|
68
|
+
const parentRevisionId=call?.args?.plan?.revision?.id || null;
|
|
69
|
+
if(!parentRevisionId) return null;
|
|
70
|
+
const rejected=result?.status!=='world-ready';
|
|
71
|
+
const revisionContext=result?.pipeline?.state?.artifacts?.revisionContext;
|
|
72
|
+
const acceptanceFindings=result?.pipeline?.state?.artifacts?.acceptanceEvidence?.findings || [];
|
|
73
|
+
const retryFindings=(result?.attempts || []).flatMap((attempt)=>attempt?.retry?.findings || []);
|
|
74
|
+
const evidenceRefs=[
|
|
75
|
+
...(revisionContext?.findingIds || []),
|
|
76
|
+
...acceptanceFindings.map((finding)=>finding?.id),
|
|
77
|
+
...retryFindings.map((finding)=>finding?.id)
|
|
78
|
+
].filter(Boolean);
|
|
79
|
+
return {
|
|
80
|
+
parentRevisionId,
|
|
81
|
+
...(rejected?{reason:result?.reason || result?.admission?.reasons?.[0] || 'world-revision'}:{}),
|
|
82
|
+
...(evidenceRefs.length?{evidenceRefs:[...new Set(evidenceRefs)]}:{})
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const worldRevisionRepairFromExecution=(result)=>{
|
|
87
|
+
if(result?.status!=='world-rejected') return null;
|
|
88
|
+
const baseWorldIR=result?.worldIR || result?.pipeline?.state?.artifacts?.worldIR;
|
|
89
|
+
const revisionContext=result?.pipeline?.state?.artifacts?.revisionContext;
|
|
90
|
+
if(!baseWorldIR||!revisionContext||revisionContext.baseRevisionId!==baseWorldIR.revision?.id) return null;
|
|
91
|
+
return {baseWorldIR:structuredClone(baseWorldIR),revisionContext:structuredClone(revisionContext)};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const identityScope = (identity) => {
|
|
95
|
+
const separator=identity?.indexOf(':') ?? -1;
|
|
96
|
+
if (separator < 0) return {};
|
|
97
|
+
try { return JSON.parse(identity.slice(separator + 1)); } catch { return {}; }
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const recoveryOriginIdentity = (call, unresolvedMutations) => {
|
|
101
|
+
if (!['recoverPickupBlocker','recoverArticulatedBlocker','cleanupRecoveryBlocker'].includes(call.name)) return null;
|
|
102
|
+
const args=call.args || {};
|
|
103
|
+
const matches=[...unresolvedMutations.values()].filter((entry)=>{
|
|
104
|
+
if (entry.tool !== 'approachAndInteract') return false;
|
|
105
|
+
const scope=identityScope(entry.identity);
|
|
106
|
+
return scope.actorId===args.actorId
|
|
107
|
+
&& scope.targetId===args.targetId
|
|
108
|
+
&& (!args.partName || scope.partName===args.partName);
|
|
109
|
+
});
|
|
110
|
+
return matches.at(-1)?.identity || null;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const recoveryMutationIdentity = (call, recoveryOf) => {
|
|
114
|
+
if (!recoveryOf) return mutationIdentity(call);
|
|
115
|
+
const originScope=identityScope(recoveryOf);
|
|
116
|
+
const args={...(call.args || {})};
|
|
117
|
+
if (args.partName == null && originScope.partName != null) args.partName=originScope.partName;
|
|
118
|
+
return mutationIdentity({...call,args});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const replanInstruction = (outcome) => COMPLETE_OUTCOMES.has(outcome?.state)
|
|
122
|
+
? 'World state changed. Replan from the fresh world before any further mutation.'
|
|
123
|
+
: 'This step did not verify completion. Do not advance to a later dependent mutation; diagnose, recover, retry, or report the task incomplete.';
|
|
124
|
+
|
|
125
|
+
export function annotateResult(result, sequence) {
|
|
126
|
+
if (result && typeof result === 'object' && !Array.isArray(result)) return { ...result, _sequence:sequence };
|
|
127
|
+
return { result, _sequence:sequence };
|
|
128
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { COMPLETE_OUTCOMES } from './AgentExecutionRules.js';
|
|
2
|
+
|
|
3
|
+
/** Finalize only from observed/verifiable state, never the model's prose alone. */
|
|
4
|
+
export function finalizeModelResponse({
|
|
5
|
+
response, step, taskAcceptanceBundle, lastMutation, sceneTaskPlan,
|
|
6
|
+
sceneGoalEvidence, unresolvedMutations, execution, log
|
|
7
|
+
}) {
|
|
8
|
+
const proposedFinal = response.message || '任务完成。';
|
|
9
|
+
const unresolved = [...unresolvedMutations.values()].map((entry)=>structuredClone(entry));
|
|
10
|
+
const acceptanceBundle=taskAcceptanceBundle ? structuredClone(taskAcceptanceBundle) : null;
|
|
11
|
+
const acceptanceRequired=acceptanceBundle?.required===true;
|
|
12
|
+
const acceptanceAccepted=!acceptanceRequired || acceptanceBundle?.result?.status==='world-accepted';
|
|
13
|
+
const lastComplete = lastMutation && COMPLETE_OUTCOMES.has(lastMutation.outcome.state);
|
|
14
|
+
const sceneGoalsAccepted=!sceneTaskPlan || sceneGoalEvidence?.status==='world-accepted';
|
|
15
|
+
const taskStatus = sceneTaskPlan ? sceneGoalsAccepted && !unresolved.length && acceptanceAccepted ? 'completed' : 'incomplete'
|
|
16
|
+
: !lastMutation ? 'no-mutation' : lastComplete && !unresolved.length && acceptanceAccepted ? 'completed' : 'incomplete';
|
|
17
|
+
const final = !sceneGoalsAccepted ? `任务未完成:${sceneGoalEvidence?.failedCount ?? sceneTaskPlan.criteria.length} 个目标尚未通过当前世界验证。`
|
|
18
|
+
: sceneTaskPlan && unresolved.length ? `任务未完成:仍有 ${unresolved.length} 项操作失败需要处理。`
|
|
19
|
+
: acceptanceRequired && !acceptanceAccepted
|
|
20
|
+
? `Task incomplete: world acceptance is ${acceptanceBundle?.result?.status || 'missing'}.`
|
|
21
|
+
: proposedFinal;
|
|
22
|
+
if (taskStatus === 'incomplete') {
|
|
23
|
+
const detail = !sceneGoalsAccepted ? `${sceneGoalEvidence?.failedCount || 0} unsatisfied goal(s)` : !acceptanceAccepted ? `world acceptance → ${acceptanceBundle?.result?.status || 'missing'}` : unresolved.length ? `${unresolved.length} unresolved mutation(s)` : `${lastMutation?.tool || 'task'} → ${lastMutation?.outcome.state || 'incomplete'}`;
|
|
24
|
+
log(`sequence: task incomplete · ${detail}`, 'error');
|
|
25
|
+
}
|
|
26
|
+
log(final, 'result');
|
|
27
|
+
return { message:final, steps:step + 1, taskStatus, lastMutation:lastMutation ? structuredClone(lastMutation) : null, unresolvedMutations:unresolved, execution:structuredClone(execution), ...(sceneTaskPlan?{taskPlan:structuredClone(sceneTaskPlan),goalVerification:structuredClone(sceneGoalEvidence)}:{}),...(acceptanceBundle?{acceptanceBundle}:{}) };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Enforce the planning budget without silently dropping unresolved world changes. */
|
|
31
|
+
export function finalizePlanningLimit({
|
|
32
|
+
maxSteps, taskAcceptanceBundle, lastMutation, sceneTaskPlan,
|
|
33
|
+
sceneGoalEvidence, unresolvedMutations, execution, log, recordSequence
|
|
34
|
+
}) {
|
|
35
|
+
if(sceneTaskPlan && sceneGoalEvidence?.status==='world-accepted' && !unresolvedMutations.size && (!taskAcceptanceBundle?.required || taskAcceptanceBundle.result?.status==='world-accepted'))return {
|
|
36
|
+
message:'任务目标已通过当前世界验证。',steps:maxSteps,taskStatus:'completed',taskPlan:structuredClone(sceneTaskPlan),goalVerification:structuredClone(sceneGoalEvidence),
|
|
37
|
+
lastMutation:lastMutation?structuredClone(lastMutation):null,unresolvedMutations:[],execution:structuredClone(execution)
|
|
38
|
+
};
|
|
39
|
+
const unresolved = [...unresolvedMutations.values()].map((entry)=>structuredClone(entry));
|
|
40
|
+
if (unresolved.length || sceneTaskPlan) {
|
|
41
|
+
const message = `Task incomplete: planning limit reached with ${unresolved.length} unresolved world mutation(s).`;
|
|
42
|
+
log(`sequence: ${message}`, 'error');
|
|
43
|
+
recordSequence?.({
|
|
44
|
+
planningStep:maxSteps, executed:false, termination:'planning-limit',
|
|
45
|
+
unresolved:unresolved.length,
|
|
46
|
+
lastMutation:lastMutation ? structuredClone(lastMutation) : null
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
message, steps:maxSteps, taskStatus:'incomplete', termination:'planning-limit',
|
|
50
|
+
lastMutation:lastMutation ? structuredClone(lastMutation) : null,
|
|
51
|
+
unresolvedMutations:unresolved, execution:structuredClone(execution),...(sceneTaskPlan?{taskPlan:structuredClone(sceneTaskPlan),goalVerification:structuredClone(sceneGoalEvidence)}:{})
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`Agent exceeded ${maxSteps} planning steps`);
|
|
55
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { buildAgentSystemPrompt } from '../prompt/index.js';
|
|
2
|
+
import { invokeAgentTool } from './AgentToolInvoker.js';
|
|
3
|
+
import { finalizeModelResponse, finalizePlanningLimit } from './AgentRunResults.js';
|
|
4
|
+
import {
|
|
5
|
+
COMPLETE_OUTCOMES, stableValue, normalizeModelToolCall, mutationIdentity,
|
|
6
|
+
worldMutationRevisionId, worldPlanIdentity, worldProposalLineageFromExecution,
|
|
7
|
+
worldRevisionRepairFromExecution, recoveryOriginIdentity, recoveryMutationIdentity,
|
|
8
|
+
replanInstruction, annotateResult
|
|
9
|
+
} from './AgentExecutionRules.js';
|
|
10
|
+
|
|
11
|
+
/** One execution context per run. Tool and world authority remain in the injected AgentTools. */
|
|
12
|
+
export async function executeAgentRun(agent, text, { signal, actor = agent.tools.actor } = {}) {
|
|
13
|
+
const { tools, gateway:configuredGateway, maxSteps, maxRecoveryReadRounds, maxUnchangedFailures } = agent;
|
|
14
|
+
// Preserve the public logger callback's original Agent receiver.
|
|
15
|
+
const log = (...args) => agent.log(...args);
|
|
16
|
+
tools.beginTask?.(text);
|
|
17
|
+
log(`goal: ${text}`, 'goal');
|
|
18
|
+
let toolDefinitions=tools.definitions();
|
|
19
|
+
const messages = [
|
|
20
|
+
{ role:'system', content:buildAgentSystemPrompt(toolDefinitions) },
|
|
21
|
+
{ role:'user', content:text }
|
|
22
|
+
];
|
|
23
|
+
const gateway = configuredGateway?.isConfigured() ? configuredGateway : null;
|
|
24
|
+
if (!gateway) { const error=new Error('智能体能力不可用'); error.code='AGENT_CAPABILITY_UNAVAILABLE'; throw error; }
|
|
25
|
+
|
|
26
|
+
const execution = [];
|
|
27
|
+
let taskAcceptanceBundle=null;
|
|
28
|
+
const unresolvedMutations = new Map();
|
|
29
|
+
const appliedAuxiliaryRecoveries = new Map();
|
|
30
|
+
const attemptedWorldPlans = new Set();
|
|
31
|
+
// Hidden catalog tools still enforce Runtime proposal gates when discovered later.
|
|
32
|
+
const authoritativeDefinitions=tools.fullDefinitions?.() || toolDefinitions;
|
|
33
|
+
const proposalGateEnabled=authoritativeDefinitions.some((tool)=>tool.name==='proposeWorldIR');
|
|
34
|
+
const revisionProposalGateEnabled=authoritativeDefinitions.some((tool)=>tool.name==='proposeWorldRevision');
|
|
35
|
+
const issuedWorldRevisions=new Set();
|
|
36
|
+
const issuedWorldRevisionProposals=new Map();
|
|
37
|
+
let pendingWorldProposalLineage=null;
|
|
38
|
+
let pendingWorldRevisionRepair=null;
|
|
39
|
+
let lastMutation = null;
|
|
40
|
+
let recoveryReadRounds = 0;
|
|
41
|
+
let sceneTaskPlan=null,sceneGoalEvidence=null;
|
|
42
|
+
const failedSceneAttempts=new Map();
|
|
43
|
+
const hasSceneObservation=toolDefinitions.some(tool=>tool.name==='observeScene');
|
|
44
|
+
const refreshSceneGoals=async()=>{
|
|
45
|
+
if(!sceneTaskPlan)return;
|
|
46
|
+
sceneGoalEvidence=await tools.call('verifyScene',{criteria:sceneTaskPlan.criteria});
|
|
47
|
+
const satisfied=new Set(sceneGoalEvidence.checks.filter(check=>check.verified).map(check=>check.id));
|
|
48
|
+
for(const [identity,pending] of unresolvedMutations)if(pending.tool==='interactScene' && satisfied.has(pending.args.goalId))unresolvedMutations.delete(identity);
|
|
49
|
+
};
|
|
50
|
+
const cancelled = (steps) => ({
|
|
51
|
+
message:'任务已停止;已完成的世界变化已保留。重试将重新观察当前世界。',
|
|
52
|
+
taskStatus:'cancelled', termination:'user-cancelled', steps,
|
|
53
|
+
lastMutation:lastMutation ? structuredClone(lastMutation) : null,
|
|
54
|
+
unresolvedMutations:[...unresolvedMutations.values()].map((entry)=>structuredClone(entry)),
|
|
55
|
+
execution:structuredClone(execution),
|
|
56
|
+
...(taskAcceptanceBundle ? { acceptanceBundle:structuredClone(taskAcceptanceBundle) } : {})
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// OBSERVE -> PLAN: prepare fresh context, then ask the model for a decision.
|
|
60
|
+
async function preparePlanningRound(step) {
|
|
61
|
+
toolDefinitions=tools.definitions();
|
|
62
|
+
messages[0]={role:'system',content:buildAgentSystemPrompt(toolDefinitions)};
|
|
63
|
+
if (signal?.aborted) return { cancelled:cancelled(step) };
|
|
64
|
+
const world = await tools.call('listObjects');
|
|
65
|
+
if (signal?.aborted) return { cancelled:cancelled(step) };
|
|
66
|
+
const scene=hasSceneObservation ? await tools.call('observeScene',actor?{actor}:{}) : null;
|
|
67
|
+
await refreshSceneGoals();
|
|
68
|
+
const unresolved = [...unresolvedMutations.values()].map((entry)=>structuredClone(entry));
|
|
69
|
+
const task = tools.taskObservation?.({ actor,lastMutation:lastMutation ? structuredClone(lastMutation) : null, unresolvedMutations:unresolved }) || null;
|
|
70
|
+
if(task && sceneTaskPlan)task.plan={...structuredClone(sceneTaskPlan),verification:structuredClone(sceneGoalEvidence)};
|
|
71
|
+
if (tools.runtime) tools.runtime.lastTaskObservation = task ? structuredClone(task) : null;
|
|
72
|
+
let response;
|
|
73
|
+
try { response = await gateway.complete({
|
|
74
|
+
messages,
|
|
75
|
+
tools:toolDefinitions,
|
|
76
|
+
context:{
|
|
77
|
+
world:lastMutation ? { count:world.length, index:world.map(({id,asset})=>({id,asset})) } : world,
|
|
78
|
+
...(scene?{scene}:{}),
|
|
79
|
+
...(task ? { task } : {}),
|
|
80
|
+
...(unresolved.length ? { recovery:{
|
|
81
|
+
readOnlyRoundsUsed:recoveryReadRounds,
|
|
82
|
+
readOnlyRoundsRemaining:Math.max(0,maxRecoveryReadRounds-recoveryReadRounds)
|
|
83
|
+
} } : {})
|
|
84
|
+
}
|
|
85
|
+
}, { signal }); }
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (signal?.aborted) return { cancelled:cancelled(step + 1) };
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
if (signal?.aborted) return { cancelled:cancelled(step + 1) };
|
|
91
|
+
response.toolCalls = response.toolCalls.map(normalizeModelToolCall);
|
|
92
|
+
return { response, scene, unresolved };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// COMPLETE: re-check declared goals; the model response alone is not proof.
|
|
96
|
+
// COMPLETE: a model reply is not proof of the requested world state.
|
|
97
|
+
async function finishModelResponse(response, step) {
|
|
98
|
+
await refreshSceneGoals();
|
|
99
|
+
if (signal?.aborted) return cancelled(step + 1);
|
|
100
|
+
return finalizeModelResponse({
|
|
101
|
+
response, step, taskAcceptanceBundle, lastMutation, sceneTaskPlan,
|
|
102
|
+
sceneGoalEvidence, unresolvedMutations, execution, log
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// EXECUTE -> REPLAN: enforce tool sequencing, verification and recovery barriers.
|
|
107
|
+
async function executeToolBatch(response, step, scene) {
|
|
108
|
+
let barrier = null;
|
|
109
|
+
let executedTool = false;
|
|
110
|
+
let mutationExecuted = false;
|
|
111
|
+
for (const call of response.toolCalls) {
|
|
112
|
+
// A running world tool finishes at its own safe boundary. Never drop a
|
|
113
|
+
// held object or roll back a completed action merely to stop planning.
|
|
114
|
+
if (signal?.aborted) return cancelled(step + 1);
|
|
115
|
+
if (barrier) {
|
|
116
|
+
const skipped = {
|
|
117
|
+
status:'not-executed',
|
|
118
|
+
reason:barrier.skipReason || 'REPLAN_REQUIRED_AFTER_WORLD_CHANGE',
|
|
119
|
+
afterTool:barrier.tool,
|
|
120
|
+
afterOutcome:barrier.outcome.state,
|
|
121
|
+
instruction:barrier.instruction || replanInstruction(barrier.outcome),
|
|
122
|
+
_sequence:{ outcome:{state:'skipped',verified:false}, barrier:false, replanRequired:true }
|
|
123
|
+
};
|
|
124
|
+
messages.push({ role:'tool', toolCallId:call.id, name:call.name, content:JSON.stringify(skipped) });
|
|
125
|
+
execution.push({ planningStep:step + 1, tool:call.name, args:structuredClone(call.args || {}), executed:false, outcome:{state:'skipped',verified:false}, reason:skipped.reason });
|
|
126
|
+
tools.recordSequence?.({ planningStep:step + 1, tool:call.name, executed:false, reason:skipped.reason, afterTool:barrier.tool, afterOutcome:barrier.outcome.state });
|
|
127
|
+
log(`skip: ${call.name} · replan after ${barrier.tool}`, 'plan');
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const previewPolicy=tools.executionPolicy?.(call.name,undefined) || {};
|
|
132
|
+
let sceneCallFingerprint=null;
|
|
133
|
+
if(call.name==='planSceneTask' || call.name==='interactScene') {
|
|
134
|
+
if(call.name==='interactScene')await refreshSceneGoals();
|
|
135
|
+
const goal=sceneTaskPlan?.criteria.find(check=>check.id===call.args?.goalId);
|
|
136
|
+
const satisfied=new Set((sceneGoalEvidence?.checks || []).filter(check=>check.verified).map(check=>check.id));
|
|
137
|
+
const identity=mutationIdentity(call),previous=failedSceneAttempts.get(identity);
|
|
138
|
+
const custom = call.args?.interaction?.action === 'custom';
|
|
139
|
+
const fingerprint=scene ? stableValue({objects:scene.objects.map(object=>({id:object.id,state:object.state,transform:{...object.transform,position:object.transform.position.map(value=>Math.round(value*100)/100)}})),environment:scene.affordances.entities.filter(entry=>entry.source==='environment').map(entry=>({id:entry.id,state:entry.state})),project:scene.project?.entities.map(entry=>({id:entry.id,state:entry.state,actions:entry.actions}))}) : null;
|
|
140
|
+
const reason=call.name==='planSceneTask' ? sceneTaskPlan?'TASK_PLAN_IMMUTABLE':null
|
|
141
|
+
: !sceneTaskPlan?'TASK_PLAN_REQUIRED':!goal?'TASK_GOAL_UNKNOWN':!custom&&!actor?'ACTOR_SELECTION_REQUIRED':!custom&&call.args?.interaction?.actor!==actor?'TASK_ACTOR_MISMATCH'
|
|
142
|
+
: (sceneTaskPlan.dependencies[goal.id] || []).some(parent=>!satisfied.has(parent))?'TASK_DEPENDENCY_UNSATISFIED'
|
|
143
|
+
: satisfied.has(goal.id)?'TASK_GOAL_ALREADY_VERIFIED'
|
|
144
|
+
: previous?.fingerprint===fingerprint && previous.count>=maxUnchangedFailures?'UNCHANGED_FAILURE_LIMIT':null;
|
|
145
|
+
if(reason) {
|
|
146
|
+
const skipped={status:'not-executed',reason,instruction:'Choose an unsatisfied goal, inspect fresh affordances, and change the route/action or report incomplete. Do not weaken or replace declared goals.'};
|
|
147
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
148
|
+
execution.push({planningStep:step+1,tool:call.name,args:structuredClone(call.args || {}),executed:false,outcome:{state:'skipped',verified:false},reason});
|
|
149
|
+
barrier={tool:call.name,outcome:{state:'skipped',verified:false},skipReason:reason};continue;
|
|
150
|
+
}
|
|
151
|
+
sceneCallFingerprint=fingerprint;
|
|
152
|
+
}
|
|
153
|
+
if(proposalGateEnabled && call.name==='runWorldPipeline'){
|
|
154
|
+
const revisionId=call.args?.plan?.revision?.id;
|
|
155
|
+
if(!revisionId || !issuedWorldRevisions.has(revisionId)){
|
|
156
|
+
const skipped={
|
|
157
|
+
status:'not-executed',reason:'WORLD_PIPELINE_PROPOSAL_REQUIRED',
|
|
158
|
+
instruction:'Call proposeWorldIR first, observe the compiled Runtime-issued worldIR in a fresh planning round, then submit that exact revision to runWorldPipeline.',
|
|
159
|
+
_sequence:{outcome:{state:'skipped',verified:false},barrier:false,replanRequired:true}
|
|
160
|
+
};
|
|
161
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
162
|
+
execution.push({planningStep:step+1,tool:call.name,args:structuredClone(call.args || {}),executed:false,outcome:{state:'skipped',verified:false},reason:skipped.reason});
|
|
163
|
+
tools.recordSequence?.({planningStep:step+1,tool:call.name,executed:false,reason:skipped.reason,replanRequired:true});
|
|
164
|
+
log(`skip: ${call.name} · compiled World IR proposal required`,'plan');
|
|
165
|
+
barrier={tool:call.name,outcome:{state:'skipped',verified:false},skipReason:'REPLAN_REQUIRED_AFTER_WORLD_PROPOSAL_GATE',instruction:skipped.instruction};
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if(revisionProposalGateEnabled && call.name==='proposeWorldRevision' && !pendingWorldRevisionRepair){
|
|
170
|
+
const skipped={status:'not-executed',reason:'WORLD_REVISION_CONTEXT_REQUIRED',instruction:'No bounded Runtime revision context is available. Use proposeWorldIR for a full semantic revision, or report the task incomplete.',_sequence:{outcome:{state:'skipped',verified:false},barrier:false,replanRequired:true}};
|
|
171
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
172
|
+
execution.push({planningStep:step+1,tool:call.name,args:structuredClone(call.args||{}),executed:false,outcome:{state:'skipped',verified:false},reason:skipped.reason});
|
|
173
|
+
tools.recordSequence?.({planningStep:step+1,tool:call.name,executed:false,reason:skipped.reason,replanRequired:true});
|
|
174
|
+
barrier={tool:call.name,outcome:{state:'skipped',verified:false},skipReason:'REPLAN_REQUIRED_AFTER_WORLD_REVISION_CONTEXT_GATE',instruction:skipped.instruction};
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if(revisionProposalGateEnabled && call.name==='recompileWorldRevision'){
|
|
178
|
+
const proposal=call.args?.proposal;
|
|
179
|
+
const nextRevisionId=proposal?.nextRevisionId;
|
|
180
|
+
const issued=nextRevisionId?issuedWorldRevisionProposals.get(nextRevisionId):null;
|
|
181
|
+
const reason=!issued?'WORLD_REVISION_PROPOSAL_REQUIRED':stableValue(proposal)!==issued.signature?'WORLD_REVISION_PROPOSAL_TAMPERED':null;
|
|
182
|
+
if(reason){
|
|
183
|
+
const skipped={status:'not-executed',reason,instruction:'Call proposeWorldRevision first and submit the returned proposal unchanged in a fresh planning round.',_sequence:{outcome:{state:'skipped',verified:false},barrier:false,replanRequired:true}};
|
|
184
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
185
|
+
execution.push({planningStep:step+1,tool:call.name,args:structuredClone(call.args||{}),executed:false,outcome:{state:'skipped',verified:false},reason});
|
|
186
|
+
tools.recordSequence?.({planningStep:step+1,tool:call.name,executed:false,reason,replanRequired:true});
|
|
187
|
+
barrier={tool:call.name,outcome:{state:'skipped',verified:false},skipReason:'REPLAN_REQUIRED_AFTER_WORLD_REVISION_PROPOSAL_GATE',instruction:skipped.instruction};
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const planIdentity=worldPlanIdentity(call);
|
|
192
|
+
if (planIdentity && attemptedWorldPlans.has(planIdentity)) {
|
|
193
|
+
const skipped={
|
|
194
|
+
status:'not-executed',reason:'WORLD_PIPELINE_PLAN_ALREADY_ATTEMPTED',planIdentity,
|
|
195
|
+
instruction:'This exact World IR semantic plan already ran in the current task. Revise the proposal from the returned rejection findings, or report the task incomplete; do not resubmit unchanged semantics under a new revision.',
|
|
196
|
+
_sequence:{outcome:{state:'skipped',verified:false},barrier:false,replanRequired:true}
|
|
197
|
+
};
|
|
198
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
199
|
+
execution.push({planningStep:step+1,tool:call.name,args:structuredClone(call.args || {}),executed:false,outcome:{state:'skipped',verified:false},reason:skipped.reason,planIdentity});
|
|
200
|
+
tools.recordSequence?.({planningStep:step+1,tool:call.name,executed:false,reason:skipped.reason,planIdentity,replanRequired:true});
|
|
201
|
+
log(`skip: ${call.name} · exact World IR semantics already attempted`, 'plan');
|
|
202
|
+
barrier={tool:call.name,outcome:{state:'skipped',verified:false},skipReason:'REPLAN_REQUIRED_AFTER_WORLD_PLAN_GATE'};
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const recoveryOf=previewPolicy.auxiliary ? recoveryOriginIdentity(call,unresolvedMutations) : null;
|
|
206
|
+
const recoveryIdentity=previewPolicy.auxiliary ? recoveryMutationIdentity(call,recoveryOf) : null;
|
|
207
|
+
if (recoveryOf && appliedAuxiliaryRecoveries.get(recoveryOf)?.has(recoveryIdentity)) {
|
|
208
|
+
const skipped={
|
|
209
|
+
status:'not-executed',reason:'RECOVERY_ALREADY_APPLIED',
|
|
210
|
+
recoveryOf,recoveryIdentity,
|
|
211
|
+
instruction:'This recovery already verified against the current failure evidence. Retry the original failed mutation before applying the same recovery again.',
|
|
212
|
+
_sequence:{outcome:{state:'skipped',verified:false},barrier:false,replanRequired:true}
|
|
213
|
+
};
|
|
214
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
215
|
+
execution.push({
|
|
216
|
+
planningStep:step+1,tool:call.name,args:structuredClone(call.args || {}),executed:false,
|
|
217
|
+
outcome:{state:'skipped',verified:false},reason:skipped.reason,auxiliary:true,recoveryOf
|
|
218
|
+
});
|
|
219
|
+
tools.recordSequence?.({
|
|
220
|
+
planningStep:step+1,tool:call.name,executed:false,reason:skipped.reason,
|
|
221
|
+
auxiliary:true,recoveryOf,recoveryIdentity,replanRequired:true
|
|
222
|
+
});
|
|
223
|
+
log(`skip: ${call.name} · recovery already applied; retry original mutation`, 'plan');
|
|
224
|
+
barrier={
|
|
225
|
+
tool:call.name,outcome:{state:'skipped',verified:false},
|
|
226
|
+
skipReason:'REPLAN_REQUIRED_AFTER_RECOVERY_GATE'
|
|
227
|
+
};
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
log(`plan: ${call.name} ${JSON.stringify(call.args)}`, 'plan');
|
|
232
|
+
if (signal?.aborted) return cancelled(step + 1);
|
|
233
|
+
executedTool = true;
|
|
234
|
+
const invocation = await invokeAgentTool(tools, call, {
|
|
235
|
+
signal, pendingWorldProposalLineage, pendingWorldRevisionRepair, issuedWorldRevisionProposals
|
|
236
|
+
});
|
|
237
|
+
const { safeResult, policy, invocationFailed } = invocation;
|
|
238
|
+
if (invocation.acceptanceChanged) taskAcceptanceBundle = invocation.acceptanceBundle;
|
|
239
|
+
if(call.name==='planSceneTask' && safeResult.status==='scene-task-plan') {
|
|
240
|
+
sceneTaskPlan={criteria:structuredClone(safeResult.criteria),dependencies:structuredClone(safeResult.dependencies)};
|
|
241
|
+
barrier={tool:call.name,outcome:{state:'accepted',verified:null},skipReason:'REPLAN_REQUIRED_AFTER_TASK_PLAN'};
|
|
242
|
+
}
|
|
243
|
+
if(call.name==='interactScene') {
|
|
244
|
+
const identity=mutationIdentity(call),previous=failedSceneAttempts.get(identity);
|
|
245
|
+
if(policy.outcome.verified)failedSceneAttempts.delete(identity);
|
|
246
|
+
else failedSceneAttempts.set(identity,{fingerprint:sceneCallFingerprint,count:previous?.fingerprint===sceneCallFingerprint?previous.count+1:1});
|
|
247
|
+
}
|
|
248
|
+
const proposalRevisionId=call.name==='proposeWorldIR' && safeResult?.status==='world-proposal-ready' ? safeResult.worldIR?.revision?.id : null;
|
|
249
|
+
const boundedRevisionId=call.name==='proposeWorldRevision' && safeResult?.status==='world-revision-proposal-ready' ? safeResult.proposal?.nextRevisionId : null;
|
|
250
|
+
const proposalBarrier=Boolean(proposalRevisionId||boundedRevisionId);
|
|
251
|
+
if(proposalRevisionId){
|
|
252
|
+
issuedWorldRevisionProposals.clear();
|
|
253
|
+
issuedWorldRevisions.add(proposalRevisionId);
|
|
254
|
+
pendingWorldProposalLineage={parentRevisionId:proposalRevisionId};
|
|
255
|
+
pendingWorldRevisionRepair=null;
|
|
256
|
+
}
|
|
257
|
+
if(boundedRevisionId && pendingWorldRevisionRepair){
|
|
258
|
+
issuedWorldRevisionProposals.clear();
|
|
259
|
+
issuedWorldRevisionProposals.set(boundedRevisionId,{signature:stableValue(safeResult.proposal),baseWorldIR:structuredClone(pendingWorldRevisionRepair.baseWorldIR)});
|
|
260
|
+
}
|
|
261
|
+
if(call.name==='runWorldPipeline'){
|
|
262
|
+
issuedWorldRevisionProposals.clear();
|
|
263
|
+
pendingWorldProposalLineage=worldProposalLineageFromExecution(call,safeResult) || pendingWorldProposalLineage;
|
|
264
|
+
pendingWorldRevisionRepair=worldRevisionRepairFromExecution(safeResult);
|
|
265
|
+
}
|
|
266
|
+
if(call.name==='recompileWorldRevision'){
|
|
267
|
+
issuedWorldRevisionProposals.delete(call.args?.proposal?.nextRevisionId);
|
|
268
|
+
pendingWorldRevisionRepair=worldRevisionRepairFromExecution(safeResult);
|
|
269
|
+
}
|
|
270
|
+
const proposalInstruction=boundedRevisionId
|
|
271
|
+
? 'Bounded WorldRevision proposal compiled without mutating Runtime. Replan and submit this exact proposal to recompileWorldRevision.'
|
|
272
|
+
: 'World IR proposal compiled without mutating Runtime. Replan from this issued revision before runWorldPipeline.';
|
|
273
|
+
const sequence = policy.barrier || proposalBarrier ? {
|
|
274
|
+
outcome:policy.outcome,
|
|
275
|
+
barrier:Boolean(policy.barrier),
|
|
276
|
+
...(proposalBarrier?{planningBarrier:true}:{}),
|
|
277
|
+
replanRequired:true,
|
|
278
|
+
instruction:proposalBarrier
|
|
279
|
+
? proposalInstruction
|
|
280
|
+
: replanInstruction(policy.outcome)
|
|
281
|
+
} : null;
|
|
282
|
+
const content = sequence ? annotateResult(safeResult, sequence) : safeResult;
|
|
283
|
+
messages.push({ role:'tool', toolCallId:call.id, name:call.name, content:JSON.stringify(content) });
|
|
284
|
+
const entry = {
|
|
285
|
+
planningStep:step + 1, tool:call.name, args:structuredClone(call.args || {}), executed:true,
|
|
286
|
+
outcome:structuredClone(policy.outcome), mutates:Boolean(policy.mutates), auxiliary:Boolean(policy.auxiliary),
|
|
287
|
+
...(recoveryOf ? { recoveryOf } : {})
|
|
288
|
+
};
|
|
289
|
+
execution.push(entry);
|
|
290
|
+
log(`result: ${call.name} ${JSON.stringify(safeResult)}`, safeResult?.error ? 'error' : 'tool');
|
|
291
|
+
if (planIdentity) attemptedWorldPlans.add(planIdentity);
|
|
292
|
+
if(proposalBarrier){
|
|
293
|
+
barrier={
|
|
294
|
+
tool:call.name,outcome:structuredClone(policy.outcome),
|
|
295
|
+
skipReason:boundedRevisionId?'REPLAN_REQUIRED_AFTER_WORLD_REVISION_PROPOSAL':'REPLAN_REQUIRED_AFTER_WORLD_PROPOSAL',
|
|
296
|
+
instruction:proposalInstruction
|
|
297
|
+
};
|
|
298
|
+
tools.recordSequence?.({...entry,planningBarrier:true,replanRequired:true,...(proposalRevisionId?{worldRevisionId:proposalRevisionId}:{}),...(boundedRevisionId?{worldRevisionProposalId:boundedRevisionId}:{})});
|
|
299
|
+
log(`sequence: ${call.name} → ${proposalRevisionId||boundedRevisionId} · fresh planning round required`,'tool');
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (policy.barrier) {
|
|
303
|
+
mutationExecuted = true;
|
|
304
|
+
const identity = policy.auxiliary && recoveryOf ? recoveryMutationIdentity(call,recoveryOf) : mutationIdentity(call,safeResult);
|
|
305
|
+
barrier = { tool:call.name, outcome:structuredClone(policy.outcome) };
|
|
306
|
+
lastMutation = { planningStep:step + 1, tool:call.name, identity, args:structuredClone(call.args || {}), outcome:structuredClone(policy.outcome) };
|
|
307
|
+
if (policy.tracksUnresolved !== false && (!invocationFailed || call.name==='interactScene')) {
|
|
308
|
+
// Any retry of the original semantic mutation starts a new evidence epoch.
|
|
309
|
+
appliedAuxiliaryRecoveries.delete(identity);
|
|
310
|
+
if (COMPLETE_OUTCOMES.has(policy.outcome.state)) {
|
|
311
|
+
unresolvedMutations.delete(identity);
|
|
312
|
+
if(call.name==='recompileWorldRevision'){
|
|
313
|
+
const baseRevisionId=call.args?.proposal?.baseRevisionId;
|
|
314
|
+
for(const [pendingIdentity,pending] of unresolvedMutations){
|
|
315
|
+
if(baseRevisionId && worldMutationRevisionId(pending)===baseRevisionId) unresolvedMutations.delete(pendingIdentity);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
} else unresolvedMutations.set(identity,{ planningStep:step + 1, tool:call.name, identity, args:structuredClone(call.args || {}), outcome:structuredClone(policy.outcome) });
|
|
319
|
+
} else if (policy.auxiliary && recoveryOf && COMPLETE_OUTCOMES.has(policy.outcome.state)) {
|
|
320
|
+
if (!appliedAuxiliaryRecoveries.has(recoveryOf)) appliedAuxiliaryRecoveries.set(recoveryOf,new Set());
|
|
321
|
+
appliedAuxiliaryRecoveries.get(recoveryOf).add(identity);
|
|
322
|
+
}
|
|
323
|
+
tools.recordSequence?.({ ...entry, identity, barrier:true, replanRequired:true, unresolved:unresolvedMutations.size });
|
|
324
|
+
log(`sequence: ${call.name} → ${policy.outcome.state} · replan required`, COMPLETE_OUTCOMES.has(policy.outcome.state) ? 'tool' : 'error');
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (!unresolvedMutations.size || mutationExecuted) recoveryReadRounds=0;
|
|
329
|
+
else if (executedTool) recoveryReadRounds += 1;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// EXHAUST: do not declare success when the plan still has pending evidence.
|
|
333
|
+
// EXHAUST: budget exhaustion is not proof of completion.
|
|
334
|
+
async function finishAtLimit() {
|
|
335
|
+
if (signal?.aborted) return cancelled(maxSteps);
|
|
336
|
+
await refreshSceneGoals();
|
|
337
|
+
return finalizePlanningLimit({
|
|
338
|
+
maxSteps, taskAcceptanceBundle, lastMutation, sceneTaskPlan,
|
|
339
|
+
sceneGoalEvidence, unresolvedMutations, execution, log,
|
|
340
|
+
recordSequence:tools.recordSequence?.bind(tools)
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
for (let step = 0; step < maxSteps; step++) {
|
|
345
|
+
const planningRound = await preparePlanningRound(step);
|
|
346
|
+
if (planningRound.cancelled) return planningRound.cancelled;
|
|
347
|
+
const { response, scene, unresolved } = planningRound;
|
|
348
|
+
if (!response.toolCalls.length) return finishModelResponse(response, step);
|
|
349
|
+
const worldBuildVerified=lastMutation
|
|
350
|
+
&& ['runWorldPipeline','recompileWorldRevision'].includes(lastMutation.tool)
|
|
351
|
+
&& COMPLETE_OUTCOMES.has(lastMutation.outcome?.state)
|
|
352
|
+
&& !unresolved.length;
|
|
353
|
+
const redundantPostWorldReads=worldBuildVerified
|
|
354
|
+
&& response.toolCalls.every((call)=>!tools.executionPolicy?.(call.name,undefined)?.mutates);
|
|
355
|
+
if(redundantPostWorldReads){
|
|
356
|
+
messages.push({role:'assistant',content:response.message || '',toolCalls:response.toolCalls});
|
|
357
|
+
const instruction='The world build is already Runtime-verified and current task context is fresh. Do not issue read-only confirmation calls. Either perform the next required world mutation from current context or finalize.';
|
|
358
|
+
for(const call of response.toolCalls){
|
|
359
|
+
const skipped={status:'not-executed',reason:'WORLD_READY_REDUNDANT_READ',instruction,_sequence:{outcome:{state:'skipped',verified:false},barrier:false,replanRequired:true}};
|
|
360
|
+
messages.push({role:'tool',toolCallId:call.id,name:call.name,content:JSON.stringify(skipped)});
|
|
361
|
+
execution.push({planningStep:step+1,tool:call.name,args:structuredClone(call.args || {}),executed:false,outcome:{state:'skipped',verified:false},reason:skipped.reason});
|
|
362
|
+
tools.recordSequence?.({planningStep:step+1,tool:call.name,executed:false,reason:skipped.reason,replanRequired:true});
|
|
363
|
+
}
|
|
364
|
+
log('skip: redundant read-only confirmation after verified world build','plan');
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const readOnlyRecovery = unresolved.length && recoveryReadRounds >= maxRecoveryReadRounds
|
|
368
|
+
&& response.toolCalls.every((call)=>!tools.executionPolicy?.(call.name,undefined)?.mutates);
|
|
369
|
+
if (readOnlyRecovery) {
|
|
370
|
+
const message=`Task incomplete: recovery observation limit reached with ${unresolved.length} unresolved world mutation(s).`;
|
|
371
|
+
log(`sequence: ${message}`,'error');
|
|
372
|
+
for (const call of response.toolCalls) execution.push({
|
|
373
|
+
planningStep:step+1,tool:call.name,args:structuredClone(call.args || {}),executed:false,
|
|
374
|
+
outcome:{state:'skipped',verified:false},reason:'RECOVERY_OBSERVATION_LIMIT'
|
|
375
|
+
});
|
|
376
|
+
tools.recordSequence?.({
|
|
377
|
+
planningStep:step+1,executed:false,termination:'recovery-observation-limit',
|
|
378
|
+
recoveryReadRounds,unresolved:unresolved.length,
|
|
379
|
+
lastMutation:lastMutation ? structuredClone(lastMutation) : null
|
|
380
|
+
});
|
|
381
|
+
return {
|
|
382
|
+
message,steps:step+1,taskStatus:'incomplete',termination:'recovery-observation-limit',
|
|
383
|
+
lastMutation:lastMutation ? structuredClone(lastMutation) : null,
|
|
384
|
+
unresolvedMutations:unresolved,execution:structuredClone(execution)
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
messages.push({ role:'assistant', content:response.message || '', toolCalls:response.toolCalls });
|
|
388
|
+
|
|
389
|
+
const batchOutcome = await executeToolBatch(response, step, scene);
|
|
390
|
+
if (batchOutcome) return batchOutcome;
|
|
391
|
+
}
|
|
392
|
+
return finishAtLimit();
|
|
393
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* Runs a single model-selected tool with the original trusted internal context. */
|
|
2
|
+
export async function invokeAgentTool(tools, call, {
|
|
3
|
+
signal, pendingWorldProposalLineage = null, pendingWorldRevisionRepair = null,
|
|
4
|
+
issuedWorldRevisionProposals = new Map()
|
|
5
|
+
} = {}) {
|
|
6
|
+
const acceptanceBefore = tools.runtime?.lastAcceptanceBundle || null;
|
|
7
|
+
let result;
|
|
8
|
+
let invocationFailed = false;
|
|
9
|
+
try {
|
|
10
|
+
let internalContext = call.name === 'interactScene' ? { signal } : null;
|
|
11
|
+
if (call.name === 'proposeWorldIR' && pendingWorldProposalLineage)
|
|
12
|
+
internalContext = { worldProposalLineage: structuredClone(pendingWorldProposalLineage) };
|
|
13
|
+
if (call.name === 'proposeWorldRevision' && pendingWorldRevisionRepair)
|
|
14
|
+
internalContext = { worldRevisionRepair: structuredClone(pendingWorldRevisionRepair) };
|
|
15
|
+
if (call.name === 'recompileWorldRevision') {
|
|
16
|
+
const issued = issuedWorldRevisionProposals.get(call.args?.proposal?.nextRevisionId);
|
|
17
|
+
if (issued) internalContext = { worldRevisionBaseIR: structuredClone(issued.baseWorldIR) };
|
|
18
|
+
}
|
|
19
|
+
result = internalContext
|
|
20
|
+
? await tools.call(call.name, call.args, internalContext)
|
|
21
|
+
: await tools.call(call.name, call.args);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
invocationFailed = true;
|
|
24
|
+
result = { error:error.message, code:error.code || 'TOOL_ERROR',
|
|
25
|
+
...(Array.isArray(error.diagnostics) ? { diagnostics:error.diagnostics.slice(0, 12) } : {}) };
|
|
26
|
+
}
|
|
27
|
+
const acceptanceAfter = tools.runtime?.lastAcceptanceBundle || null;
|
|
28
|
+
const acceptanceChanged = acceptanceAfter !== acceptanceBefore;
|
|
29
|
+
const safeResult = result === undefined ? { ok:true } : result;
|
|
30
|
+
const policy = tools.executionPolicy?.(call.name, safeResult) || {
|
|
31
|
+
mutates:false, barrier:false, batchable:true, batchAcceptable:true,
|
|
32
|
+
outcome:safeResult?.error
|
|
33
|
+
? {state:'error',verified:false,reason:safeResult.code || 'TOOL_ERROR'}
|
|
34
|
+
: {state:'accepted',verified:null}
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
safeResult, policy, invocationFailed, acceptanceChanged,
|
|
38
|
+
acceptanceBundle:acceptanceChanged && acceptanceAfter ? structuredClone(acceptanceAfter) : null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JsonGateway } from '../../../foundation/JsonGateway.js';
|
|
2
|
+
|
|
3
|
+
export class HttpLLMGateway extends JsonGateway {
|
|
4
|
+
constructor(options = {}) { super({ timeoutMs: 180000, label: 'agent capability adapter', ...options }); }
|
|
5
|
+
async complete(request, options) { return normalizeGatewayResponse(await this.post(request, options)); }
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function normalizeGatewayResponse(payload = {}) {
|
|
9
|
+
const toolCalls = Array.isArray(payload.toolCalls) ? payload.toolCalls.map((call, index) => ({
|
|
10
|
+
id: call.id || `call_${index}`,
|
|
11
|
+
name: call.name,
|
|
12
|
+
args: call.args || call.arguments || {}
|
|
13
|
+
})) : [];
|
|
14
|
+
return {
|
|
15
|
+
message: payload.message || payload.content || '',
|
|
16
|
+
final: Boolean(payload.final || (!toolCalls.length && (payload.message || payload.content))),
|
|
17
|
+
toolCalls
|
|
18
|
+
};
|
|
19
|
+
}
|