agentscape3d 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +23 -48
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +10 -229
- package/dist/index.js +192 -15462
- package/dist/index.js.map +1 -1
- package/package.json +16 -40
- package/cli.mjs +0 -27
- package/dist/AssetCompiler-CDFiElji.js +0 -2451
- package/dist/AssetCompiler-CDFiElji.js.map +0 -1
- package/dist/AssetInputContracts-Dy8iU4eT.js +0 -228
- package/dist/AssetInputContracts-Dy8iU4eT.js.map +0 -1
- package/dist/AssetRecipe-DmFpzxr-.js +0 -55
- package/dist/AssetRecipe-DmFpzxr-.js.map +0 -1
- package/dist/BrowserCodeWorker.js +0 -53615
- package/dist/KinematicHypothesisScreen-D-z6qgMB.js +0 -242
- package/dist/KinematicHypothesisScreen-D-z6qgMB.js.map +0 -1
- package/dist/SceneSerializer-DPVOyeRk.js +0 -353
- package/dist/SceneSerializer-DPVOyeRk.js.map +0 -1
- package/dist/StylePack-DNrdLeGI.js +0 -6314
- package/dist/StylePack-DNrdLeGI.js.map +0 -1
- package/dist/WorldArchive-pSBIGxLa.js +0 -420
- package/dist/WorldArchive-pSBIGxLa.js.map +0 -1
- package/dist/WorldIO-wsDfZGM4.js +0 -150
- package/dist/WorldIO-wsDfZGM4.js.map +0 -1
- package/dist/blankWorld-CBWbwJGj.js +0 -76
- package/dist/blankWorld-CBWbwJGj.js.map +0 -1
- package/dist/disposeObject3D-BQ9TyVC_.js +0 -54
- package/dist/disposeObject3D-BQ9TyVC_.js.map +0 -1
- package/dist/environments-DgH66NqV.js +0 -4220
- package/dist/environments-DgH66NqV.js.map +0 -1
- package/dist/gltfIO-B87nJaat.js +0 -10
- package/dist/gltfIO-B87nJaat.js.map +0 -1
- package/dist/grandUrbanBlock-Ob9pN-CB.js +0 -516
- package/dist/grandUrbanBlock-Ob9pN-CB.js.map +0 -1
- package/dist/magicCabin-D64fD1E2.js +0 -11024
- package/dist/magicCabin-D64fD1E2.js.map +0 -1
- package/dist/mcp.d.ts +0 -2
- package/dist/mcp.js +0 -1
- package/dist/monumentHall-BKbs0UOQ.js +0 -404
- package/dist/monumentHall-BKbs0UOQ.js.map +0 -1
- package/dist/node.d.ts +0 -16
- package/dist/node.js +0 -25
- package/dist/ruinedCourtyard-BoZxHldu.js +0 -697
- package/dist/ruinedCourtyard-BoZxHldu.js.map +0 -1
- package/dist/runtime/application/AgentTools.js +0 -25
- package/dist/runtime/application/README.md +0 -14
- package/dist/runtime/application/buildTaskObservation.js +0 -117
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +0 -46
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +0 -35
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +0 -17
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +0 -72
- package/dist/runtime/application/createSession.js +0 -66
- package/dist/runtime/application/createWorldAuthoringContext.js +0 -400
- package/dist/runtime/application/generation/GenerationOrchestrator.js +0 -629
- package/dist/runtime/application/generation/GenerationRuntime.js +0 -214
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +0 -285
- package/dist/runtime/application/native-scene/CodeProject.js +0 -119
- package/dist/runtime/application/native-scene/CodeProjectModules.js +0 -128
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +0 -62
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +0 -127
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +0 -51
- package/dist/runtime/application/native-scene/NativeSceneHost.js +0 -164
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +0 -116
- package/dist/runtime/application/native-scene/NativeThreeModule.js +0 -16
- package/dist/runtime/application/object-forge/SceneObjectForge.js +0 -232
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +0 -54
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +0 -22
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +0 -40
- package/dist/runtime/application/scene/CapabilityResolver.js +0 -79
- package/dist/runtime/application/scene/RequestWindow.js +0 -54
- package/dist/runtime/application/scene/SceneAgentTools.js +0 -21
- package/dist/runtime/application/scene/SceneContracts.js +0 -45
- package/dist/runtime/application/scene/SceneEditService.js +0 -144
- package/dist/runtime/application/scene/SceneFacade.js +0 -267
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +0 -40
- package/dist/runtime/application/scene/SceneJobController.js +0 -229
- package/dist/runtime/application/scene/ScenePackage.js +0 -162
- package/dist/runtime/application/scene/ScenePersistence.js +0 -50
- package/dist/runtime/application/scene/SceneProject.js +0 -95
- package/dist/runtime/application/scene/SceneSkillNames.js +0 -5
- package/dist/runtime/application/scene/StarterScene.js +0 -56
- package/dist/runtime/application/scene/WorldArchive.js +0 -87
- package/dist/runtime/application/scene/WorldDirectory.js +0 -20
- package/dist/runtime/application/scene/WorldDocument.js +0 -74
- package/dist/runtime/application/scene/WorldIO.js +0 -103
- package/dist/runtime/application/scene/WorldStorage.js +0 -137
- package/dist/runtime/application/skills/SkillRegistry.js +0 -163
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +0 -32
- package/dist/runtime/application/skills/packs/affordanceSkills.js +0 -36
- package/dist/runtime/application/skills/packs/assetSkills.js +0 -46
- package/dist/runtime/application/skills/packs/authoringSkills.js +0 -16
- package/dist/runtime/application/skills/packs/batchSkills.js +0 -22
- package/dist/runtime/application/skills/packs/codeSkills.js +0 -106
- package/dist/runtime/application/skills/packs/generationSkills.js +0 -45
- package/dist/runtime/application/skills/packs/interactionSkills.js +0 -46
- package/dist/runtime/application/skills/packs/recoverySkills.js +0 -80
- package/dist/runtime/application/skills/packs/sceneSkills.js +0 -24
- package/dist/runtime/application/skills/packs/spatialSkills.js +0 -35
- package/dist/runtime/application/skills/packs/verificationSkills.js +0 -14
- package/dist/runtime/application/skills/packs/worldSkills.js +0 -45
- package/dist/runtime/application/skills/registerCoreSkills.js +0 -31
- package/dist/runtime/application/skills/skillPrimitives.js +0 -4
- package/dist/runtime/application/tasks/CabinetCupTask.js +0 -76
- package/dist/runtime/application/tasks.jsonl +0 -67
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +0 -42
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +0 -149
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +0 -825
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +0 -109
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +0 -17
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +0 -29
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +0 -118
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +0 -334
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +0 -126
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +0 -144
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +0 -174
- package/dist/runtime/application/world-authoring/ModelRef.js +0 -62
- package/dist/runtime/apps/mcp-server/AUTHORING.md +0 -71
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +0 -1
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +0 -30
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +0 -17
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +0 -71
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +0 -42
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +0 -66
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +0 -159
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +0 -8
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +0 -47
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +0 -132
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +0 -6
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +0 -116
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +0 -60
- package/dist/runtime/apps/mcp-server/README.md +0 -150
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +0 -1
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +0 -13
- package/dist/runtime/apps/mcp-server/SessionManager.js +0 -80
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +0 -58
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +0 -190
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +0 -16
- package/dist/runtime/apps/mcp-server/VALIDATION.md +0 -45
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +0 -332
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +0 -32
- package/dist/runtime/apps/mcp-server/examples/code-house.js +0 -24
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +0 -37
- package/dist/runtime/apps/mcp-server/main.mjs +0 -56
- package/dist/runtime/apps/mcp-server/registerTools.js +0 -215
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +0 -23
- package/dist/runtime/apps/mcp-server/security.js +0 -21
- package/dist/runtime/apps/mcp-server/tasks.jsonl +0 -9
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +0 -157
- package/dist/runtime/apps/server/README.md +0 -7
- package/dist/runtime/apps/server/WorldDiskStorage.js +0 -51
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +0 -278
- package/dist/runtime/apps/server/tasks.jsonl +0 -10
- package/dist/runtime/foundation/EventBus.js +0 -18
- package/dist/runtime/foundation/JsonGateway.js +0 -47
- package/dist/runtime/foundation/PolicyEngine.js +0 -21
- package/dist/runtime/foundation/README.md +0 -7
- package/dist/runtime/foundation/TraceRecorder.js +0 -76
- package/dist/runtime/foundation/errors.js +0 -8
- package/dist/runtime/foundation/simulation/SimulationProfile.js +0 -143
- package/dist/runtime/foundation/version.js +0 -2
- package/dist/runtime/modules/agent/README.md +0 -11
- package/dist/runtime/modules/agent/ToolCallingAgent.js +0 -19
- package/dist/runtime/modules/agent/bootstrapWorld.js +0 -10
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +0 -533
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +0 -127
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +0 -55
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +0 -390
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +0 -39
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +0 -19
- package/dist/runtime/modules/agent/prompt/index.js +0 -46
- package/dist/runtime/modules/agent/tasks.jsonl +0 -94
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +0 -144
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +0 -280
- package/dist/runtime/modules/artifact/ArtifactImporter.js +0 -185
- package/dist/runtime/modules/artifact/ArtifactModule.js +0 -111
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +0 -197
- package/dist/runtime/modules/artifact/IncrementalSha256.js +0 -129
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +0 -115
- package/dist/runtime/modules/artifact/README.md +0 -7
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +0 -67
- package/dist/runtime/modules/artifact/tasks.jsonl +0 -31
- package/dist/runtime/modules/asset/AssetModule.js +0 -399
- package/dist/runtime/modules/asset/README.md +0 -54
- package/dist/runtime/modules/asset/loading/AssetLoader.js +0 -157
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +0 -61
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +0 -95
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +0 -33
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +0 -103
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +0 -95
- package/dist/runtime/modules/asset/model/AssetRef.js +0 -12
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +0 -172
- package/dist/runtime/modules/asset/model/admission.js +0 -117
- package/dist/runtime/modules/asset/model/errors.js +0 -6
- package/dist/runtime/modules/asset/model/parts.js +0 -27
- package/dist/runtime/modules/asset/model/resourceBudget.js +0 -10
- package/dist/runtime/modules/asset/model/schema.js +0 -150
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +0 -78
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +0 -84
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +0 -86
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +0 -81
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +0 -272
- package/dist/runtime/modules/asset/production/AssetRecipe.js +0 -32
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +0 -45
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +0 -590
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +0 -173
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +0 -124
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +0 -56
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +0 -6
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +0 -74
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +0 -63
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +0 -48
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +0 -16
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +0 -30
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +0 -75
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +0 -20
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +0 -34
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +0 -32
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +0 -116
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +0 -84
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +0 -63
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +0 -16
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +0 -23
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +0 -50
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +0 -60
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +0 -93
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +0 -32
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +0 -55
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +0 -203
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +0 -43
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +0 -33
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +0 -60
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +0 -23
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +0 -198
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +0 -72
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +0 -51
- package/dist/runtime/modules/asset/registry/manifests/index.js +0 -173
- package/dist/runtime/modules/asset/tasks.jsonl +0 -87
- package/dist/runtime/modules/generation/README.md +0 -9
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +0 -45
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +0 -169
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +0 -192
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +0 -167
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +0 -179
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +0 -202
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +0 -239
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +0 -99
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +0 -91
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +0 -50
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +0 -304
- package/dist/runtime/modules/generation/tasks.jsonl +0 -35
- package/dist/runtime/modules/navigation/NavigationBackend.js +0 -17
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +0 -245
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +0 -850
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +0 -651
- package/dist/runtime/modules/physics/PhysicsBackend.js +0 -88
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +0 -410
- package/dist/runtime/modules/rendering/README.md +0 -7
- package/dist/runtime/modules/rendering/RendererProbe.js +0 -153
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +0 -140
- package/dist/runtime/modules/rendering/createRenderer.js +0 -76
- package/dist/runtime/modules/rendering/disposeObject3D.js +0 -34
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +0 -74
- package/dist/runtime/modules/rendering/style/StylePack.js +0 -34
- package/dist/runtime/modules/rendering/style/StyleSystem.js +0 -173
- package/dist/runtime/modules/rendering/tasks.jsonl +0 -7
- package/dist/runtime/modules/world/README.md +0 -13
- package/dist/runtime/modules/world/build/WorldBuilder.js +0 -170
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +0 -32
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +0 -43
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +0 -68
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +0 -157
- package/dist/runtime/modules/world/compiler/WorldComposer.js +0 -201
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +0 -76
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +0 -356
- package/dist/runtime/modules/world/compiler/WorldRetry.js +0 -75
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +0 -379
- package/dist/runtime/modules/world/content/blankWorld.js +0 -35
- package/dist/runtime/modules/world/content/environments.js +0 -84
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +0 -189
- package/dist/runtime/modules/world/content/magic-cabin/README.md +0 -28
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +0 -64
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +0 -7078
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +0 -26
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +0 -20
- package/dist/runtime/modules/world/content/magicCabin.js +0 -190
- package/dist/runtime/modules/world/content/monumentHall.js +0 -154
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +0 -196
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +0 -141
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +0 -137
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +0 -491
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +0 -670
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +0 -578
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +0 -127
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +0 -642
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +0 -650
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +0 -280
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +0 -242
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +0 -215
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +0 -192
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +0 -36
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +0 -351
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +0 -490
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +0 -505
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +0 -101
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +0 -435
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +0 -169
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +0 -245
- package/dist/runtime/modules/world/errors.js +0 -9
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +0 -50
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +0 -297
- package/dist/runtime/modules/world/runtime/CommandHistory.js +0 -80
- package/dist/runtime/modules/world/runtime/ObjectStore.js +0 -31
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +0 -62
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +0 -37
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +0 -207
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +0 -246
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +0 -41
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +0 -14
- package/dist/runtime/modules/world/runtime/WorldCommands.js +0 -502
- package/dist/runtime/modules/world/runtime/WorldObservation.js +0 -71
- package/dist/runtime/modules/world/runtime/WorldQueries.js +0 -340
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +0 -78
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +0 -649
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +0 -107
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +0 -130
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +0 -79
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +0 -195
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +0 -70
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +0 -115
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +0 -216
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +0 -214
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +0 -65
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +0 -222
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +0 -130
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +0 -57
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +0 -123
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +0 -120
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +0 -102
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +0 -89
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +0 -99
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +0 -269
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +0 -56
- package/dist/runtime/modules/world/runtime/spatial/ThreeBvhRuntime.js +0 -36
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +0 -728
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +0 -269
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +0 -469
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +0 -1657
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +0 -457
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +0 -284
- package/dist/runtime/modules/world/spec/WorldIR.js +0 -165
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +0 -86
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +0 -51
- package/dist/runtime/modules/world/spec/WorldRevision.js +0 -231
- package/dist/runtime/modules/world/spec/WorldSpec.js +0 -86
- package/dist/runtime/modules/world/tasks.jsonl +0 -530
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +0 -254
- package/dist/runtime/modules/world/verification/Finding.js +0 -105
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +0 -69
- package/dist/runtime/modules/world/verification/RepairEngine.js +0 -49
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +0 -158
- package/dist/runtime/modules/world/verification/WorldValidator.js +0 -65
- package/dist/runtime/package-lock.json +0 -6245
- package/dist/runtime/package.json +0 -91
- 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-Dudvovhu.js +0 -364
- package/dist/schema-Dudvovhu.js.map +0 -1
- package/dist/suzhouGarden-BCx_JeV5.js +0 -6159
- package/dist/suzhouGarden-BCx_JeV5.js.map +0 -1
- package/dist/woodlandWorkshop-BGNWPNdK.js +0 -484
- package/dist/woodlandWorkshop-BGNWPNdK.js.map +0 -1
- package/dist/yuanmingyuan-DAIb1msO.js +0 -4962
- package/dist/yuanmingyuan-DAIb1msO.js.map +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { compileInteractionContract } from '../interaction/InteractionContract.js';
|
|
2
|
-
import { assetAdmission } from '../../../asset/model/admission.js';
|
|
3
|
-
import { inferCarryCapability } from '../interaction/CarryCapability.js';
|
|
4
|
-
|
|
5
|
-
const blocked = reason => ({ available: false, reason });
|
|
6
|
-
const reasonOf = error => error.details?.reason || error.code || 'CAPABILITY_CHECK_FAILED';
|
|
7
|
-
|
|
8
|
-
/** Read-through discovery. ObjectStore and PhysicsSystem remain the state owners. */
|
|
9
|
-
export function inspectObjectAffordances(runtime, id, actorId = null) {
|
|
10
|
-
if (!runtime.store?.has(id)) return null;
|
|
11
|
-
const record = runtime.store.get(id), manifest = record.manifest;
|
|
12
|
-
const registered = Boolean(runtime.physics?.getPosition(id));
|
|
13
|
-
const held = record.state?.heldBy || runtime.interactions?.isHeld?.(id) || runtime.interactions?.carry?.agentHeld?.has(id);
|
|
14
|
-
let access = { available: null, reason: 'ACTOR_REQUIRED_FOR_REACH_CHECK' };
|
|
15
|
-
if (actorId) {
|
|
16
|
-
if (!runtime.store.has(actorId)) access = blocked('ACTOR_NOT_FOUND');
|
|
17
|
-
else if (runtime.store.get(actorId).manifest.type !== 'agent') access = blocked('ACTOR_NOT_AGENT');
|
|
18
|
-
else if (!registered) access = blocked('TARGET_PHYSICS_UNAVAILABLE');
|
|
19
|
-
else if (!runtime.physics.hasCapability('scene-query')) access = blocked('VISIBILITY_UNAVAILABLE');
|
|
20
|
-
else {
|
|
21
|
-
try {
|
|
22
|
-
const reach = runtime.interactions.interactionStatus(actorId, id);
|
|
23
|
-
access = { available: reach.interactable, reason: reach.interactable ? null : reach.inRange ? 'OCCLUDED' : 'OUT_OF_REACH', distance: reach.distance };
|
|
24
|
-
} catch (error) { access = blocked(reasonOf(error)); }
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const actions = [];
|
|
28
|
-
const add = (action, parameters = {}, extra = {}) => {
|
|
29
|
-
const entry={action,parameters,...access,...extra};
|
|
30
|
-
if(entry.execution==='interaction')entry.canApproach=entry.available===false && ['OUT_OF_REACH','OCCLUDED'].includes(entry.reason) && Boolean(runtime.navigation?.findPath && runtime.locomotion?.navigate);
|
|
31
|
-
actions.push(entry);
|
|
32
|
-
};
|
|
33
|
-
// Editor operations are explicitly separate from embodied actions.
|
|
34
|
-
add('inspect', {}, { available: true, reason: null, execution: 'query' });
|
|
35
|
-
add('setTransform', { transform: { type: 'object', required: true } }, {
|
|
36
|
-
available: !held, reason: held ? 'OBJECT_HELD' : null, execution: 'editor'
|
|
37
|
-
});
|
|
38
|
-
const carry = inferCarryCapability(manifest, { scale:record.physicsScale ?? record.object?.scale?.x ?? 1,
|
|
39
|
-
allowProvisional:record.state?.authoringPromotion?.usage === 'movable' });
|
|
40
|
-
if (manifest.actions?.includes('pickup') || carry.eligible) {
|
|
41
|
-
let check = carry.eligible ? {} : blocked(carry.reason);
|
|
42
|
-
if (actorId && runtime.store.has(actorId)) {
|
|
43
|
-
try { runtime.interactions.assertAgentCarryable(actorId, id); }
|
|
44
|
-
catch (error) { check = blocked(reasonOf(error)); }
|
|
45
|
-
}
|
|
46
|
-
add('pickup', {}, { execution: 'interaction',
|
|
47
|
-
capabilitySource:manifest.actions?.includes('pickup') ? 'declared' : 'physical-inference',
|
|
48
|
-
graspVerified:false, ...check });
|
|
49
|
-
}
|
|
50
|
-
if (manifest.surfaces?.length) {
|
|
51
|
-
const held = actorId && runtime.interactions?.heldByAgent?.(actorId);
|
|
52
|
-
add('place', { surfaceId: { type: 'string', enum: manifest.surfaces.map(surface => surface.id), required: false } }, {
|
|
53
|
-
execution: 'interaction', ...(!actorId ? {} : !held ? blocked('NOT_HOLDING_OBJECT') : !runtime.interactions.supports(runtime.store.get(held), 'place') ? blocked('ACTION_UNSUPPORTED') : {})
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
for (const contract of compileInteractionContract(manifest).contracts) {
|
|
57
|
-
const partName = contract.target.partName;
|
|
58
|
-
const live = runtime.physics?.getArticulationState?.(id, partName);
|
|
59
|
-
add(contract.action, { partName: { type: 'string', enum: [partName], required: true } }, {
|
|
60
|
-
execution: 'interaction', partName, contract,
|
|
61
|
-
joint: structuredClone(manifest.parts[partName].joint), state: live,
|
|
62
|
-
...(!live ? blocked('ARTICULATION_PHYSICS_UNAVAILABLE') : {}),
|
|
63
|
-
...(manifest.source?.kind==='compiled' && assetAdmission(manifest).layers.runtime.status!=='ready' ? blocked('RUNTIME_VERIFICATION_REQUIRED') : {}),
|
|
64
|
-
...(runtime.interactions.articulationTasks?.has(`${id}:${partName}`) ? blocked('ACTION_IN_PROGRESS') : {})
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
for (const [partName, part] of Object.entries(manifest.parts || {})) {
|
|
68
|
-
if (!['revolute', 'prismatic'].includes(part.joint?.type)) continue;
|
|
69
|
-
const action = part.joint.type === 'prismatic' ? 'slide' : 'rotateJoint';
|
|
70
|
-
const capability = runtime.interactions?.manipulationCapability?.(id, action, partName) || blocked('EXECUTOR_UNAVAILABLE');
|
|
71
|
-
let partAccess={};
|
|
72
|
-
if(actorId && runtime.store.has(actorId) && runtime.store.get(actorId).manifest.type==='agent') {
|
|
73
|
-
try {
|
|
74
|
-
const aimPoint=runtime.physics.manipulationBody(id,partName,{contacts:true}).contactCandidates[0]?.center;
|
|
75
|
-
if(aimPoint) {const reach=runtime.interactions.interactionStatus(actorId,id,{aimPoint});partAccess={available:reach.interactable,reason:reach.interactable?null:reach.inRange?'OCCLUDED':'OUT_OF_REACH',distance:reach.distance};}
|
|
76
|
-
} catch { /* Keep the root access diagnostic if a part cannot be queried. */ }
|
|
77
|
-
}
|
|
78
|
-
const relative = action === 'slide' ? 'distance' : 'angle';
|
|
79
|
-
add(action, { part: { type: 'string', enum: [partName], required: true },
|
|
80
|
-
target: { type: 'number', required: false, alternative:relative, unit: action === 'slide' ? 'meter' : 'radian', limits: structuredClone(part.joint.limits || null) },
|
|
81
|
-
[relative]: {type:'number', required:false, alternative:'target', relative:true, unit:action === 'slide' ? 'meter' : 'radian'} }, {
|
|
82
|
-
execution: 'interaction', partName, joint: structuredClone(part.joint), state:runtime.physics?.getArticulationState?.(id,partName),
|
|
83
|
-
...partAccess,...(!capability.available ? capability : {}), ...(actorId && runtime.interactions?.heldByAgent?.(actorId) ? blocked('HANDS_FULL') : {})
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (manifest.physics?.colliders?.length) {
|
|
87
|
-
for (const action of ['push', 'drag', 'rotate']) {
|
|
88
|
-
const capability = runtime.interactions?.manipulationCapability?.(id, action) || blocked('EXECUTOR_UNAVAILABLE');
|
|
89
|
-
const parameters = action === 'rotate' ? { axis:{type:'array',length:3,nonzero:true,required:true}, angle:{type:'number',minimum:-Math.PI,maximum:Math.PI,unit:'radian',required:true}, maxTorque:{type:'number',minimum:0,exclusiveMinimum:true,maximum:1000,default:100,unit:'newton-meter'} }
|
|
90
|
-
: { direction:{type:'array',length:3,nonzero:true,horizontal:true,required:true}, distance:{type:'number',minimum:0,exclusiveMinimum:true,maximum:5,unit:'meter',required:true}, maxForce:{type:'number',minimum:0,exclusiveMinimum:true,maximum:1000,default:100,unit:'newton'} };
|
|
91
|
-
add(action, parameters, { execution:'interaction', ...(!capability.available ? capability : {}),
|
|
92
|
-
...(actorId && runtime.interactions?.heldByAgent?.(actorId) ? blocked('HANDS_FULL') : {}) });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
schema: 'agentscape.object-affordances', schemaVersion: 1, id,
|
|
97
|
-
label: manifest.label || manifest.id, kind: manifest.type, source: 'asset',
|
|
98
|
-
position: record.object.position.toArray(), state: structuredClone(record.state || {}),
|
|
99
|
-
physics: { registered, body: manifest.physics?.body || null, currentBody:runtime.physics?.manipulationBody?.(id)?.body ?? null,
|
|
100
|
-
mass: manifest.physics?.mass ?? null, friction: manifest.physics?.friction ?? null,
|
|
101
|
-
colliderCount: manifest.physics?.colliders?.length || 0 },
|
|
102
|
-
actions,
|
|
103
|
-
...(manifest.physics?.body === 'dynamic' && !carry.eligible ? { capabilityCandidates:[{ action:'pickup', executable:false, reason:carry.reason, source:'physical-geometry' }] } : {}),
|
|
104
|
-
evidenceKind: registered ? 'physics-state' : 'visual-state', physicsVerified: false,
|
|
105
|
-
pending: Boolean(runtime.interactions?.physicalTasks?.has(id) || (runtime.interactions?.articulationTasks && [...runtime.interactions.articulationTasks.values()].some(task => task.id === id)))
|
|
106
|
-
};
|
|
107
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { inspectObjectAffordances } from './ObjectAffordances.js';
|
|
3
|
-
|
|
4
|
-
const clone=value=>structuredClone(value);
|
|
5
|
-
const failure=(id,reason,extra={})=>({status:'world-action-blocked',targetId:id,verified:false,reason,...extra});
|
|
6
|
-
|
|
7
|
-
export class WorldAffordances {
|
|
8
|
-
constructor(runtime) {this.runtime=runtime;this.pending=new Map();this.sequence=0;this.lastResult=null;this.epoch=0;}
|
|
9
|
-
contracts() {return this.runtime.environment?.affordances || [];}
|
|
10
|
-
get(id) {return this.contracts().find(entry=>entry.id===id);}
|
|
11
|
-
position(entry) {
|
|
12
|
-
if(entry.position) return [...entry.position];
|
|
13
|
-
const box=new THREE.Box3().setFromObject(entry.object);
|
|
14
|
-
return box.getCenter(new THREE.Vector3()).toArray();
|
|
15
|
-
}
|
|
16
|
-
access(entry,actorId,position=null) {
|
|
17
|
-
const runtime=this.runtime;
|
|
18
|
-
if(!runtime.store?.has(actorId)) return {available:false,reason:'ACTOR_NOT_FOUND'};
|
|
19
|
-
const actor=runtime.store.get(actorId);
|
|
20
|
-
if(actor.manifest?.type!=='agent') return {available:false,reason:'ACTOR_NOT_AGENT'};
|
|
21
|
-
const feet=position || runtime.physics?.getPosition(actorId);
|
|
22
|
-
if(!feet) return {available:false,reason:'ACTOR_PHYSICS_UNAVAILABLE'};
|
|
23
|
-
const target=this.position(entry);
|
|
24
|
-
const origin=[feet[0],feet[1]+1.2,feet[2]];
|
|
25
|
-
const distance=Math.hypot(...target.map((v,i)=>v-origin[i]));
|
|
26
|
-
if(distance>1.5) return {available:false,reason:'OUT_OF_REACH',distance,targetPosition:target,maxDistance:1.5};
|
|
27
|
-
if(!runtime.physics.hasCapability?.('scene-query')) return {available:false,reason:'VISIBILITY_UNAVAILABLE'};
|
|
28
|
-
const hit=runtime.physics.raycast(origin,target,{excludeId:actorId});
|
|
29
|
-
if(hit && hit.distance < distance-.12 && !(entry.colliderId && hit.provenance?.environmentId===entry.colliderId)) return {available:false,reason:'OCCLUDED',blocker:hit.provenance || {id:hit.id},distance};
|
|
30
|
-
return {available:true,distance};
|
|
31
|
-
}
|
|
32
|
-
inspect(id,{actorId=null}={}) {
|
|
33
|
-
const entry=this.get(id);
|
|
34
|
-
if(!entry) return inspectObjectAffordances(this.runtime,id,actorId);
|
|
35
|
-
const access=actorId?this.access(entry,actorId):{available:null,reason:'ACTOR_REQUIRED_FOR_REACH_CHECK'};
|
|
36
|
-
const state=entry.kind==='text' && actorId && !access.available ? {text:null,reason:access.reason} : clone(entry.read());
|
|
37
|
-
return {schema:'agentscape.object-affordances',schemaVersion:1,source:'environment',id:entry.id,label:entry.label,kind:entry.kind,position:this.position(entry),state,
|
|
38
|
-
actions:entry.actions.map(action=>{const reason=entry.precondition?.(action);return {action,parameters:clone(entry.parameters?.[action] || {}),execution:'world-action',...access,
|
|
39
|
-
canApproach:!reason && ['OUT_OF_REACH','OCCLUDED'].includes(access.reason) && Boolean(this.runtime.navigation?.findPath && this.runtime.locomotion?.navigate),
|
|
40
|
-
...(reason?{available:false,reason}:{}),...(this.pending.has(id)?{available:false,reason:'ACTION_IN_PROGRESS',canApproach:false}:{}),...(this.runtime.simulation?.running===false && entry.evidenceKind==='animated-transform'?{available:false,reason:'SIMULATION_PAUSED',canApproach:false}:{})};}),evidenceKind:entry.evidenceKind,
|
|
41
|
-
physicsVerified:false,pending:this.pending.has(id)};
|
|
42
|
-
}
|
|
43
|
-
list({query='',actorId=null,limit=40}={}) {
|
|
44
|
-
const term=String(query).toLocaleLowerCase();
|
|
45
|
-
const entries=[...this.contracts()];
|
|
46
|
-
const ids=new Set(entries.map(entry=>entry.id));
|
|
47
|
-
for(const [id,record] of this.runtime.store?.list?.() || []) if(!ids.has(id)) entries.push({id,label:record.manifest.label || record.manifest.id,kind:record.manifest.type});
|
|
48
|
-
const matches=entries.filter(entry=>`${entry.id} ${entry.label} ${entry.kind}`.toLocaleLowerCase().includes(term));
|
|
49
|
-
return {schema:'agentscape.affordances.v1',total:matches.length,entities:matches.slice(0,Math.min(100,Math.max(1,limit))).map(entry=>this.inspect(entry.id,{actorId}))};
|
|
50
|
-
}
|
|
51
|
-
execute({targetId,action,args={},actorId=null},{editor=false}={}) {
|
|
52
|
-
const entry=this.get(targetId);
|
|
53
|
-
if(!entry) return failure(targetId,'TARGET_NOT_FOUND');
|
|
54
|
-
if(!entry.actions.includes(action)) return failure(targetId,'ACTION_UNSUPPORTED');
|
|
55
|
-
if(!editor) {const access=this.access(entry,actorId);if(!access.available)return failure(targetId,access.reason,{access});}
|
|
56
|
-
const precondition=entry.precondition?.(action);
|
|
57
|
-
if(precondition)return failure(targetId,precondition);
|
|
58
|
-
const invalid=entry.validate?.(action,args);
|
|
59
|
-
if(invalid) return failure(targetId,invalid);
|
|
60
|
-
if(action==='read') return {status:'world-state-read',targetId,state:clone(entry.read()),evidenceKind:entry.evidenceKind};
|
|
61
|
-
if(this.pending.has(targetId)) return failure(targetId,'ACTION_IN_PROGRESS');
|
|
62
|
-
const before=clone(entry.read());
|
|
63
|
-
const commandId=`world-action-${++this.sequence}`;
|
|
64
|
-
const complete=()=>{
|
|
65
|
-
const result={status:'world-action-completed',commandId,targetId,action,verified:true,physicsVerified:false,evidenceKind:entry.evidenceKind,before,after:clone(entry.read())};
|
|
66
|
-
this.lastResult=result;
|
|
67
|
-
this.runtime.events?.emit('world.action.completed',result);
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
if(this.runtime.simulation?.running===false && entry.evidenceKind==='animated-transform') return failure(targetId,'SIMULATION_PAUSED');
|
|
71
|
-
entry.request(action,args);
|
|
72
|
-
if(entry.verify(action,args)) return complete();
|
|
73
|
-
return new Promise(resolve=>{
|
|
74
|
-
const pending={entry,action,args,elapsed:0,resolve,complete,commandId};
|
|
75
|
-
pending.timer=setTimeout(()=>this.finishUnverified(targetId,'SIMULATION_NOT_ADVANCING'),12000);
|
|
76
|
-
pending.timer.unref?.();
|
|
77
|
-
this.pending.set(targetId,pending);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
async approachAndExecute(command) {
|
|
81
|
-
const {targetId,actorId,action,args={}}=command,entry=this.get(targetId),epoch=this.epoch;
|
|
82
|
-
if(!entry)return failure(targetId,'TARGET_NOT_FOUND');
|
|
83
|
-
if(!entry.actions.includes(action))return failure(targetId,'ACTION_UNSUPPORTED');
|
|
84
|
-
if(this.runtime.simulation?.running===false && entry.evidenceKind==='animated-transform')return failure(targetId,'SIMULATION_PAUSED');
|
|
85
|
-
const invalid=entry.precondition?.(action) || entry.validate?.(action,args);
|
|
86
|
-
if(invalid)return failure(targetId,invalid);
|
|
87
|
-
const finish=result=>{
|
|
88
|
-
const changed=['world-action-completed','world-action-unverified'].includes(result.status);
|
|
89
|
-
if(changed)this.runtime.navigation?.invalidate?.('environment-contract-changed');
|
|
90
|
-
return {...result,navigationInvalidated:changed};
|
|
91
|
-
};
|
|
92
|
-
const current=this.access(entry,actorId);
|
|
93
|
-
if(current.available)return finish(await this.execute(command));
|
|
94
|
-
if(!['OUT_OF_REACH','OCCLUDED'].includes(current.reason))return failure(targetId,current.reason);
|
|
95
|
-
const runtime=this.runtime,start=runtime.physics.getPosition(actorId),target=this.position(entry);
|
|
96
|
-
if(!runtime.navigation?.findPath || !runtime.locomotion?.navigate)return failure(targetId,'NAVIGATION_UNAVAILABLE');
|
|
97
|
-
const poses=[];
|
|
98
|
-
for(const height of [...new Set([start[1],target[1]-1.2])]) for(const radius of [.7,1.05,1.3]) for(let i=0;i<8;i++) {
|
|
99
|
-
if(epoch!==this.epoch)return failure(targetId,'ACTION_CANCELLED');
|
|
100
|
-
const angle=i*Math.PI/4,candidate=[target[0]+Math.cos(angle)*radius,height,target[2]+Math.sin(angle)*radius];
|
|
101
|
-
const route=await runtime.navigation.findPath(start,candidate);
|
|
102
|
-
if(!route.reachable || !Array.isArray(route.end?.snapped))continue;
|
|
103
|
-
const position=route.end.snapped;
|
|
104
|
-
if(this.access(entry,actorId,position).available)poses.push({position,cost:route.cost ?? Infinity});
|
|
105
|
-
}
|
|
106
|
-
if(epoch!==this.epoch)return failure(targetId,'ACTION_CANCELLED');
|
|
107
|
-
if(this.get(targetId)!==entry)return failure(targetId,'TARGET_CHANGED');
|
|
108
|
-
poses.sort((a,b)=>a.cost-b.cost);
|
|
109
|
-
if(!poses.length)return failure(targetId,'NO_APPROACH_POSE',{access:current});
|
|
110
|
-
const locomotion=await runtime.locomotion.navigate(actorId,poses[0].position);
|
|
111
|
-
if(epoch!==this.epoch)return failure(targetId,'ACTION_CANCELLED');
|
|
112
|
-
if(this.get(targetId)!==entry)return failure(targetId,'TARGET_CHANGED');
|
|
113
|
-
if(locomotion.status!=='arrived')return failure(targetId,'APPROACH_FAILED',{locomotion});
|
|
114
|
-
return {...finish(await this.execute(command)),approach:poses[0].position,locomotion};
|
|
115
|
-
}
|
|
116
|
-
finishUnverified(id,reason) {
|
|
117
|
-
const item=this.pending.get(id);if(!item)return;
|
|
118
|
-
clearTimeout(item.timer);this.pending.delete(id);
|
|
119
|
-
const result={status:'world-action-unverified',commandId:item.commandId,targetId:id,verified:false,reason,after:clone(item.entry.read())};
|
|
120
|
-
this.lastResult=result;item.resolve(result);
|
|
121
|
-
}
|
|
122
|
-
update(dt) {
|
|
123
|
-
for(const [id,item] of this.pending) {
|
|
124
|
-
item.elapsed+=dt;
|
|
125
|
-
if(item.entry.verify(item.action,item.args)) {clearTimeout(item.timer);this.pending.delete(id);item.resolve(item.complete());}
|
|
126
|
-
else if(item.elapsed>=8)this.finishUnverified(id,'POSTCONDITION_TIMEOUT');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
cancel(reason='WORLD_REPLACED') {this.epoch++;for(const id of [...this.pending.keys()])this.finishUnverified(id,reason);}
|
|
130
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
export const BEHAVIOR_COMMAND_SCHEMA='agentscape.runtime-command';
|
|
2
|
-
export const BEHAVIOR_COMMAND_VERSION=1;
|
|
3
|
-
|
|
4
|
-
const clean=v=>typeof v==='string'?v.trim():'';
|
|
5
|
-
const SUPPORTED_CAPABILITIES=new Set(['OPEN','CLOSE','PICKUP','PLACE','SWITCH']);
|
|
6
|
-
|
|
7
|
-
export function compileInteractionIntent(intent,{worldRevisionId=null}={}){
|
|
8
|
-
if(!intent||typeof intent!=='object'||Array.isArray(intent)) throw new TypeError('Interaction intent must be an object');
|
|
9
|
-
const id=clean(intent.id); const targetId=clean(intent.targetId); const supportId=clean(intent.supportId); const capability=clean(intent.capability).toUpperCase();
|
|
10
|
-
if(!id||!capability) throw new TypeError('Interaction intent requires id and capability');
|
|
11
|
-
if((capability==='OPEN'||capability==='CLOSE'||capability==='PICKUP') && !targetId) throw new TypeError(`${capability} interaction intent requires targetId`);
|
|
12
|
-
if(!SUPPORTED_CAPABILITIES.has(capability)) { const error=new TypeError(`Unsupported interaction capability: ${capability}`); error.code='BEHAVIOR_CAPABILITY_UNSUPPORTED'; throw error; }
|
|
13
|
-
const actorId=clean(intent.actorId)||null;
|
|
14
|
-
const command={
|
|
15
|
-
schema:BEHAVIOR_COMMAND_SCHEMA,schemaVersion:BEHAVIOR_COMMAND_VERSION,
|
|
16
|
-
commandId:`interaction:${id}`,kind:'interaction',capability,...(actorId?{actorId}:{}),
|
|
17
|
-
preconditions:[],effects:[],verifierTarget:{type:'interaction-contract',capability,settledRequired:true},
|
|
18
|
-
source:{interactionId:id,...(worldRevisionId?{worldRevisionId}:{})}
|
|
19
|
-
};
|
|
20
|
-
if(capability==='OPEN'||capability==='CLOSE'){
|
|
21
|
-
command.targetId=targetId;
|
|
22
|
-
command.preconditions=[{kind:'target-supports-capability',targetId,capability}];
|
|
23
|
-
command.effect={kind:'execute-interaction-contract',capability,targetId};
|
|
24
|
-
command.verifierTarget.targetId=targetId;
|
|
25
|
-
} else if(capability==='PICKUP'){
|
|
26
|
-
command.targetId=targetId;
|
|
27
|
-
command.preconditions=[{kind:'target-carryable',targetId}];
|
|
28
|
-
command.effect={kind:'execute-pickup',targetId};
|
|
29
|
-
command.verifierTarget={type:'pickup',targetId,heldRequired:true};
|
|
30
|
-
} else if(capability==='PLACE'){
|
|
31
|
-
const supportId=clean(intent.supportId);
|
|
32
|
-
if(!supportId) throw new TypeError('PLACE interaction intent requires supportId');
|
|
33
|
-
command.supportId=supportId; command.targetId=supportId;
|
|
34
|
-
command.preconditions=[{kind:'actor-holds-object'},{kind:'support-target',supportId}];
|
|
35
|
-
command.effect={kind:'execute-place',supportId};
|
|
36
|
-
command.verifierTarget={type:'place',supportId,supportVerifiedRequired:true,settledRequired:true};
|
|
37
|
-
} else if(capability==='SWITCH'){
|
|
38
|
-
const stateKey=clean(intent.stateKey); if(!stateKey) throw new TypeError('SWITCH interaction intent requires stateKey');
|
|
39
|
-
if(!Object.prototype.hasOwnProperty.call(intent,'value')) throw new TypeError('SWITCH interaction intent requires value');
|
|
40
|
-
if(typeof intent.value!=='string' && typeof intent.value!=='number' && typeof intent.value!=='boolean' && intent.value!==null) throw new TypeError('SWITCH value must be JSON scalar');
|
|
41
|
-
command.targetId=targetId;
|
|
42
|
-
command.stateKey=stateKey; command.value=intent.value;
|
|
43
|
-
command.preconditions=[{kind:'state-target',targetId,stateKey}];
|
|
44
|
-
command.effect={kind:'set-state',targetId,stateKey,value:intent.value};
|
|
45
|
-
command.verifierTarget={type:'state-transition',targetId,stateKey,value:intent.value};
|
|
46
|
-
}
|
|
47
|
-
return command;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function compileBehaviorGraph(interactions=[],opts={}){
|
|
51
|
-
if(!Array.isArray(interactions)) throw new TypeError('Interactions must be an array');
|
|
52
|
-
const commands=interactions.map(item=>compileInteractionIntent(item,opts));
|
|
53
|
-
const ids=new Set();
|
|
54
|
-
for(const command of commands){if(ids.has(command.commandId)) throw new TypeError(`Duplicate runtime command: ${command.commandId}`); ids.add(command.commandId);}
|
|
55
|
-
return {schema:BEHAVIOR_COMMAND_SCHEMA,schemaVersion:BEHAVIOR_COMMAND_VERSION,commands};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function verifyBehaviorCommand(command,result){
|
|
59
|
-
const verifier=command?.verifierTarget;
|
|
60
|
-
if(!verifier) return {verified:false,reason:'VERIFIER_TARGET_MISSING'};
|
|
61
|
-
if(verifier.type==='interaction-contract'){
|
|
62
|
-
const verified=result?.status==='action-completed'&&result?.targetReached===true&&result?.settled===true&&result?.targetId===verifier.targetId&&result?.action?.toUpperCase()===verifier.capability;
|
|
63
|
-
return verified?{verified:true}:{verified:false,reason:'POST_CONDITION_NOT_VERIFIED'};
|
|
64
|
-
}
|
|
65
|
-
if(verifier.type==='pickup') return result?.status==='held' && result?.targetId===verifier.targetId ? {verified:true}:{verified:false,reason:'PICKUP_NOT_VERIFIED'};
|
|
66
|
-
if(verifier.type==='place') return result?.status==='placed' && result?.supportVerified===true && result?.settled===true && result?.targetId===verifier.supportId ? {verified:true}:{verified:false,reason:'PLACE_NOT_VERIFIED'};
|
|
67
|
-
if(verifier.type==='state-transition') return result?.status==='state-transition-applied' && result?.targetId===verifier.targetId && result?.stateKey===verifier.stateKey && Object.is(result?.value,verifier.value) ? {verified:true}:{verified:false,reason:'STATE_TRANSITION_NOT_VERIFIED'};
|
|
68
|
-
return {verified:false,reason:'VERIFIER_TYPE_UNSUPPORTED'};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function executeBehaviorCommand(runtime,command){
|
|
72
|
-
if(command?.schema!==BEHAVIOR_COMMAND_SCHEMA || command.schemaVersion!==BEHAVIOR_COMMAND_VERSION){ const error=new TypeError('Unsupported RuntimeCommand'); error.code='RUNTIME_COMMAND_UNSUPPORTED'; throw error; }
|
|
73
|
-
if(command.kind!=='interaction') { const error=new TypeError(`Unsupported RuntimeCommand kind: ${command.kind}`); error.code='RUNTIME_COMMAND_KIND_UNSUPPORTED'; throw error; }
|
|
74
|
-
if(command.capability==='OPEN'||command.capability==='CLOSE') return runtime.commands?.approachAndInteract ? runtime.commands.approachAndInteract(command.actorId,command.targetId,command.capability.toLowerCase()) : runtime.interactions.approachAndInteract(command.actorId,command.targetId,command.capability.toLowerCase());
|
|
75
|
-
if(command.capability==='PICKUP') return runtime.commands?.approachAndPickup ? runtime.commands.approachAndPickup(command.actorId,command.targetId) : runtime.interactions.approachAndPickup(command.actorId,command.targetId);
|
|
76
|
-
if(command.capability==='PLACE') return runtime.commands?.approachAndPlace ? runtime.commands.approachAndPlace(command.actorId,command.supportId) : runtime.interactions.approachAndPlace(command.actorId,command.supportId);
|
|
77
|
-
if(command.capability==='SWITCH') return runtime.commands?.applyStateTransition ? runtime.commands.applyStateTransition(command.targetId,command.stateKey,command.value,{source:'behavior-command',commandId:command.commandId}) : runtime.applyStateTransition(command.targetId,command.stateKey,command.value,{source:'behavior-command',commandId:command.commandId});
|
|
78
|
-
const error=new TypeError(`Unsupported RuntimeCommand capability: ${command.capability}`); error.code='RUNTIME_COMMAND_CAPABILITY_UNSUPPORTED'; throw error;
|
|
79
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// A declarative, project-owned behavior model. It never creates colliders or
|
|
2
|
-
// claims physics verification: visuals and persistence belong to Code Project.
|
|
3
|
-
const error = code => Object.assign(new Error(code), { code });
|
|
4
|
-
const keyName = value => typeof value === 'string' && /^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(value);
|
|
5
|
-
const scalar = value => value === null || ['string', 'boolean'].includes(typeof value)
|
|
6
|
-
|| (typeof value === 'number' && Number.isFinite(value));
|
|
7
|
-
const plain = value => value && typeof value === 'object' && !Array.isArray(value)
|
|
8
|
-
&& [Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
9
|
-
const assert = value => { if (!value) throw error('PROJECT_MACHINE_DEFINITION_INVALID'); };
|
|
10
|
-
const copy = value => structuredClone(value);
|
|
11
|
-
const ops = new Set(['eq', 'ne', 'lt', 'lte', 'gt', 'gte']);
|
|
12
|
-
const checkCount = (value, max) => Array.isArray(value) && value.length <= max;
|
|
13
|
-
|
|
14
|
-
function compileConditions(conditions, initial) {
|
|
15
|
-
assert(checkCount(conditions, 16));
|
|
16
|
-
return conditions.map(item => {
|
|
17
|
-
assert(plain(item) && keyName(item.field) && Object.hasOwn(initial, item.field) && ops.has(item.op));
|
|
18
|
-
const valueDefined = Object.hasOwn(item, 'value'), otherDefined = Object.hasOwn(item, 'other');
|
|
19
|
-
assert(valueDefined !== otherDefined && Object.keys(item).every(k => ['field', 'op', 'value', 'other'].includes(k)));
|
|
20
|
-
if (otherDefined) assert(keyName(item.other) && Object.hasOwn(initial, item.other));
|
|
21
|
-
else assert(scalar(item.value));
|
|
22
|
-
if (!['eq', 'ne'].includes(item.op)) {
|
|
23
|
-
assert(typeof initial[item.field] === 'number');
|
|
24
|
-
assert(otherDefined ? typeof initial[item.other] === 'number' : typeof item.value === 'number');
|
|
25
|
-
}
|
|
26
|
-
return copy(item);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function compileEffects(effects, initial) {
|
|
31
|
-
assert(checkCount(effects, 16) && effects.length > 0);
|
|
32
|
-
const fields = new Set();
|
|
33
|
-
return effects.map(item => {
|
|
34
|
-
assert(plain(item) && keyName(item.field) && Object.hasOwn(initial, item.field) && !fields.has(item.field));
|
|
35
|
-
assert(['set', 'add'].includes(item.op) && scalar(item.value));
|
|
36
|
-
assert(Object.keys(item).every(k => ['field', 'op', 'value'].includes(k)));
|
|
37
|
-
if (item.op === 'add') assert(typeof initial[item.field] === 'number' && typeof item.value === 'number');
|
|
38
|
-
else assert(typeof initial[item.field] === typeof item.value
|
|
39
|
-
&& (initial[item.field] !== null || item.value === null));
|
|
40
|
-
fields.add(item.field);
|
|
41
|
-
return copy(item);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function compileProjectStateMachine({ initialState, transitions, timers = [], ranges = {} }) {
|
|
46
|
-
assert(plain(initialState) && Object.keys(initialState).length > 0 && Object.keys(initialState).length <= 64);
|
|
47
|
-
for (const [key, value] of Object.entries(initialState)) assert(keyName(key) && scalar(value));
|
|
48
|
-
assert(plain(ranges) && Object.keys(ranges).every(key => Object.hasOwn(initialState, key)));
|
|
49
|
-
const limits = {};
|
|
50
|
-
for (const [key, range] of Object.entries(ranges)) {
|
|
51
|
-
assert(typeof initialState[key] === 'number' && plain(range) && Object.keys(range).every(k=>['min','max'].includes(k)));
|
|
52
|
-
assert(Number.isFinite(range.min) && Number.isFinite(range.max) && range.min <= range.max);
|
|
53
|
-
limits[key] = copy(range);
|
|
54
|
-
}
|
|
55
|
-
assert(checkCount(transitions, 64) && transitions.length > 0);
|
|
56
|
-
const compiled = new Map();
|
|
57
|
-
const knownValues = new Map(Object.entries(initialState)
|
|
58
|
-
.filter(([,value]) => typeof value !== 'number')
|
|
59
|
-
.map(([key,value]) => [key, new Set([value])]));
|
|
60
|
-
for (const item of transitions) {
|
|
61
|
-
assert(plain(item) && keyName(item.name) && !compiled.has(item.name)
|
|
62
|
-
&& (item.description == null || typeof item.description === 'string')
|
|
63
|
-
&& (item.expose == null || typeof item.expose === 'boolean'));
|
|
64
|
-
assert(Object.keys(item).every(k=>['name','description','expose','when','effects'].includes(k)));
|
|
65
|
-
const effects = compileEffects(item.effects, initialState);
|
|
66
|
-
for (const effect of effects) if (effect.op === 'set' && knownValues.has(effect.field)) {
|
|
67
|
-
knownValues.get(effect.field).add(effect.value);
|
|
68
|
-
}
|
|
69
|
-
compiled.set(item.name, { name:item.name, description:item.description || '', expose:item.expose !== false,
|
|
70
|
-
when:compileConditions(item.when || [], initialState), effects });
|
|
71
|
-
}
|
|
72
|
-
assert(checkCount(timers, 16));
|
|
73
|
-
const usedTimerFields = new Set();
|
|
74
|
-
const clocks = timers.map(item => {
|
|
75
|
-
assert(plain(item) && keyName(item.field) && !usedTimerFields.has(item.field));
|
|
76
|
-
assert(typeof initialState[item.field] === 'number' && Number.isFinite(item.rate) && item.rate > 0
|
|
77
|
-
&& Number.isFinite(item.max) && item.max >= initialState[item.field]);
|
|
78
|
-
assert(Object.keys(item).every(k=>['field','rate','max','when','onComplete'].includes(k)));
|
|
79
|
-
if (item.onComplete != null) assert(compiled.has(item.onComplete) && compiled.get(item.onComplete).expose === false);
|
|
80
|
-
usedTimerFields.add(item.field);
|
|
81
|
-
return {field:item.field,rate:item.rate,max:item.max,
|
|
82
|
-
when:compileConditions(item.when || [], initialState),onComplete:item.onComplete || null};
|
|
83
|
-
});
|
|
84
|
-
const definition = { initial:copy(initialState), transitions:compiled, timers:clocks, ranges:limits, knownValues };
|
|
85
|
-
validateProjectMachineState(definition, initialState);
|
|
86
|
-
return definition;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function validateProjectMachineState(definition, state) {
|
|
90
|
-
if (!plain(state)) throw error('PROJECT_MACHINE_STATE_INVALID');
|
|
91
|
-
const initial = definition.initial;
|
|
92
|
-
if (Object.keys(state).length !== Object.keys(initial).length) throw error('PROJECT_MACHINE_STATE_INVALID');
|
|
93
|
-
for (const [field, original] of Object.entries(initial)) {
|
|
94
|
-
const value = state[field];
|
|
95
|
-
if (!Object.hasOwn(state, field) || !scalar(value) || typeof value !== typeof original
|
|
96
|
-
|| (original === null && value !== null)) throw error('PROJECT_MACHINE_STATE_INVALID');
|
|
97
|
-
const range = definition.ranges[field];
|
|
98
|
-
if (range && (value < range.min || value > range.max)) throw error('PROJECT_MACHINE_STATE_INVALID');
|
|
99
|
-
if (definition.knownValues.has(field) && !definition.knownValues.get(field).has(value)) {
|
|
100
|
-
throw error('PROJECT_MACHINE_STATE_INVALID');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return copy(state);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function eligible(when, state) {
|
|
107
|
-
return when.every(c => {
|
|
108
|
-
const value = c.other ? state[c.other] : c.value;
|
|
109
|
-
switch (c.op) {
|
|
110
|
-
case 'eq': return Object.is(state[c.field], value);
|
|
111
|
-
case 'ne': return !Object.is(state[c.field], value);
|
|
112
|
-
case 'lt': return state[c.field] < value;
|
|
113
|
-
case 'lte': return state[c.field] <= value;
|
|
114
|
-
case 'gt': return state[c.field] > value;
|
|
115
|
-
case 'gte': return state[c.field] >= value;
|
|
116
|
-
default: return false;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function step(definition, transition, state) {
|
|
122
|
-
if (!eligible(transition.when, state)) throw error('PROJECT_MACHINE_GUARD_FAILED');
|
|
123
|
-
const next = copy(state);
|
|
124
|
-
for (const effect of transition.effects) {
|
|
125
|
-
next[effect.field] = effect.op === 'add' ? next[effect.field] + effect.value : effect.value;
|
|
126
|
-
}
|
|
127
|
-
return validateProjectMachineState(definition, next);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export class ProjectStateMachine {
|
|
131
|
-
constructor(config) {
|
|
132
|
-
this.definition = compileProjectStateMachine(config);
|
|
133
|
-
this.state = copy(this.definition.initial);
|
|
134
|
-
this.object = config.object || null;
|
|
135
|
-
this.onChange = config.onChange || null;
|
|
136
|
-
this.verifyVisual = config.verifyVisual || null;
|
|
137
|
-
assert(this.onChange == null || typeof this.onChange === 'function');
|
|
138
|
-
assert(this.verifyVisual == null || typeof this.verifyVisual === 'function');
|
|
139
|
-
this.sync(this.state, this.state, { kind:'initialize' });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
read() { return copy(this.state); }
|
|
143
|
-
available(name) {
|
|
144
|
-
const action = this.definition.transitions.get(name);
|
|
145
|
-
return Boolean(action?.expose && eligible(action.when, this.state));
|
|
146
|
-
}
|
|
147
|
-
sync(next, previous, meta) {
|
|
148
|
-
const payload = copy(next), prior = copy(previous);
|
|
149
|
-
const returned = this.onChange?.(payload, prior, meta);
|
|
150
|
-
if (returned && typeof returned.then === 'function') throw error('PROJECT_MACHINE_ASYNC_CALLBACK_UNSUPPORTED');
|
|
151
|
-
const check = this.verifyVisual?.(copy(next), {object:this.object,kind:meta.kind});
|
|
152
|
-
if (check && typeof check.then === 'function') throw error('PROJECT_MACHINE_ASYNC_CALLBACK_UNSUPPORTED');
|
|
153
|
-
if (this.verifyVisual && check !== true) throw error('PROJECT_MACHINE_VISUAL_UNVERIFIED');
|
|
154
|
-
}
|
|
155
|
-
commit(next, meta) {
|
|
156
|
-
const previous = this.state;
|
|
157
|
-
if (JSON.stringify(next) === JSON.stringify(previous)) return {changed:false,state:this.read()};
|
|
158
|
-
try { this.sync(next, previous, meta); }
|
|
159
|
-
catch (failure) {
|
|
160
|
-
try { this.onChange?.(copy(previous), copy(next), {kind:'rollback'}); } catch { /* Preserve original error. */ }
|
|
161
|
-
throw failure;
|
|
162
|
-
}
|
|
163
|
-
this.state = copy(next);
|
|
164
|
-
return {changed:true,state:this.read()};
|
|
165
|
-
}
|
|
166
|
-
execute(name) {
|
|
167
|
-
const action = this.definition.transitions.get(name);
|
|
168
|
-
if (!action?.expose) throw error('PROJECT_MACHINE_ACTION_UNAVAILABLE');
|
|
169
|
-
const next = step(this.definition, action, this.state);
|
|
170
|
-
return {transition:name,...this.commit(next,{kind:'action',name})};
|
|
171
|
-
}
|
|
172
|
-
advance(seconds) {
|
|
173
|
-
if (!Number.isFinite(seconds) || seconds < 0 || seconds > 60) throw error('PROJECT_MACHINE_CLOCK_INVALID');
|
|
174
|
-
if (seconds === 0) return {changed:false,state:this.read()};
|
|
175
|
-
let next = this.read(), completed = [];
|
|
176
|
-
for (const timer of this.definition.timers) {
|
|
177
|
-
if (!eligible(timer.when, next)) continue;
|
|
178
|
-
const previous = next[timer.field];
|
|
179
|
-
next[timer.field] = Math.min(timer.max, Number((previous + seconds * timer.rate).toFixed(9)));
|
|
180
|
-
if (timer.onComplete && previous < timer.max && next[timer.field] >= timer.max) {
|
|
181
|
-
next = step(this.definition, this.definition.transitions.get(timer.onComplete), next);
|
|
182
|
-
completed.push(timer.onComplete);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
validateProjectMachineState(this.definition, next);
|
|
186
|
-
return {...this.commit(next,{kind:'clock',seconds,completed}),completed};
|
|
187
|
-
}
|
|
188
|
-
validate(state) { return validateProjectMachineState(this.definition, state); }
|
|
189
|
-
restore(state) {
|
|
190
|
-
return this.commit(this.validate(state),{kind:'restore'});
|
|
191
|
-
}
|
|
192
|
-
listedActions() {
|
|
193
|
-
return [...this.definition.transitions.values()].filter(action=>action.expose);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const SCHEMA='agentscape.rule-graph';
|
|
2
|
-
const VERSION=1;
|
|
3
|
-
const allowedEffectKinds=new Set(['set-state']);
|
|
4
|
-
const clean=v=>typeof v==='string'?v.trim():'';
|
|
5
|
-
const scalar=v=>v===null||typeof v==='string'||typeof v==='number'||typeof v==='boolean';
|
|
6
|
-
|
|
7
|
-
export function compileRuleGraph(rules=[]){
|
|
8
|
-
if(!Array.isArray(rules)) throw new TypeError('Rules must be an array');
|
|
9
|
-
const ids=new Set();
|
|
10
|
-
const compiled=rules.map((rule,index)=>{
|
|
11
|
-
if(!rule||typeof rule!=='object'||Array.isArray(rule)) throw new TypeError(`Rule[${index}] must be an object`);
|
|
12
|
-
const id=clean(rule.id),event=clean(rule.event),effect=rule.effect;
|
|
13
|
-
if(!id||ids.has(id)) throw new TypeError(`Rule[${index}] requires unique id`); ids.add(id);
|
|
14
|
-
if(!event) throw new TypeError(`Rule[${index}] requires event`);
|
|
15
|
-
if(!effect||typeof effect!=='object'||allowedEffectKinds.has(effect.kind)===false) throw new TypeError(`Rule[${index}] unsupported effect`);
|
|
16
|
-
const targetId=clean(effect.targetId),stateKey=clean(effect.stateKey);
|
|
17
|
-
if(!targetId||!stateKey||!Object.prototype.hasOwnProperty.call(effect,'value')||!scalar(effect.value)) throw new TypeError(`Rule[${index}] set-state effect requires targetId/stateKey/scalar value`);
|
|
18
|
-
const condition=rule.condition?compileCondition(rule.condition,`Rule[${index}] condition`):null;
|
|
19
|
-
return {id,event,condition,effect:{kind:'set-state',targetId,stateKey,value:effect.value},description:clean(rule.description)||undefined};
|
|
20
|
-
});
|
|
21
|
-
return {schema:SCHEMA,schemaVersion:VERSION,rules:compiled};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function compileCondition(condition,label){
|
|
25
|
-
if(!condition||typeof condition!=='object'||Array.isArray(condition)) throw new TypeError(`${label} must be an object`);
|
|
26
|
-
const kind=clean(condition.kind);
|
|
27
|
-
if(kind==='equals'){
|
|
28
|
-
if(!clean(condition.targetId)||!clean(condition.stateKey)||!Object.prototype.hasOwnProperty.call(condition,'value')||!scalar(condition.value)) throw new TypeError(`${label} equals requires targetId/stateKey/value`);
|
|
29
|
-
return {kind:'equals',targetId:clean(condition.targetId),stateKey:clean(condition.stateKey),value:condition.value};
|
|
30
|
-
}
|
|
31
|
-
if(kind==='not-equals'){
|
|
32
|
-
if(!clean(condition.targetId)||!clean(condition.stateKey)||!Object.prototype.hasOwnProperty.call(condition,'value')||!scalar(condition.value)) throw new TypeError(`${label} not-equals requires targetId/stateKey/value`);
|
|
33
|
-
return {kind:'not-equals',targetId:clean(condition.targetId),stateKey:clean(condition.stateKey),value:condition.value};
|
|
34
|
-
}
|
|
35
|
-
throw new TypeError(`${label} unsupported kind: ${kind}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function evaluateRuleGraph(graph,event,stateReader){
|
|
39
|
-
if(graph?.schema!==SCHEMA||graph.schemaVersion!==VERSION) throw new TypeError('Unsupported rule graph');
|
|
40
|
-
if(typeof stateReader!=='function') throw new TypeError('stateReader must be a function');
|
|
41
|
-
const matches=[];
|
|
42
|
-
for(const rule of graph.rules){
|
|
43
|
-
if(rule.event!==event) continue;
|
|
44
|
-
if(rule.condition&&!evaluateCondition(rule.condition,stateReader)) continue;
|
|
45
|
-
matches.push(structuredClone(rule.effect));
|
|
46
|
-
}
|
|
47
|
-
return matches;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function evaluateCondition(condition,stateReader){
|
|
51
|
-
const value=stateReader(condition.targetId,condition.stateKey);
|
|
52
|
-
return condition.kind==='equals' ? Object.is(value,condition.value) : !Object.is(value,condition.value);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function executeRuleEffects(runtime,effects,{source='rule-graph',eventId=null,ruleCascadeDepth=null}={}){
|
|
56
|
-
if(!Array.isArray(effects)) throw new TypeError('Rule effects must be an array');
|
|
57
|
-
if(!effects.length) return Promise.resolve({status:'no-rule-match',effects:[]});
|
|
58
|
-
return runtime.mutate(`rule:${eventId||source}`,async()=>{
|
|
59
|
-
const applied=[];
|
|
60
|
-
for(const effect of effects){
|
|
61
|
-
if(effect.kind!=='set-state') { const error=new TypeError(`Unsupported rule effect: ${effect.kind}`); error.code='RULE_EFFECT_UNSUPPORTED'; throw error; }
|
|
62
|
-
const result=runtime.applyStateTransition(effect.targetId,effect.stateKey,effect.value,{source:'rule-graph',event:eventId,...(ruleCascadeDepth == null ? {} : {ruleCascadeDepth})});
|
|
63
|
-
if(result?.status!=='state-transition-applied') throw new Error(`Rule state transition rejected: ${effect.targetId}.${effect.stateKey}`);
|
|
64
|
-
applied.push(result);
|
|
65
|
-
}
|
|
66
|
-
return {status:'rule-effects-applied',effects:applied};
|
|
67
|
-
}, ruleCascadeDepth == null ? {} : {ruleCascadeDepth});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export {SCHEMA as RULE_GRAPH_SCHEMA,VERSION as RULE_GRAPH_VERSION};
|