agentscape3d-engine 0.0.0-stage → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js +337 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js.map +1 -0
- package/dist/AssetCompiler-BLj09iu1.js +2424 -0
- package/dist/AssetCompiler-BLj09iu1.js.map +1 -0
- package/dist/AssetModule-DME-XaFS.js +2637 -0
- package/dist/AssetModule-DME-XaFS.js.map +1 -0
- package/dist/AssetRecipe-g8dZBhgJ.js +298 -0
- package/dist/AssetRecipe-g8dZBhgJ.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53856 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/CarryCapability-CXwHU5ay.js +104 -0
- package/dist/CarryCapability-CXwHU5ay.js.map +1 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js +241 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js.map +1 -0
- package/dist/ObjectTransform-BlQUNK7c.js +61 -0
- package/dist/ObjectTransform-BlQUNK7c.js.map +1 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js +3259 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js.map +1 -0
- package/dist/RenderingSystem-WIr1ZuGu.js +1042 -0
- package/dist/RenderingSystem-WIr1ZuGu.js.map +1 -0
- package/dist/ScenePresentation-LsYiDxbm.js +152 -0
- package/dist/ScenePresentation-LsYiDxbm.js.map +1 -0
- package/dist/SceneProject-K7HH1s8o.js +2687 -0
- package/dist/SceneProject-K7HH1s8o.js.map +1 -0
- package/dist/SceneSerializer-zOzbX4jZ.js +932 -0
- package/dist/SceneSerializer-zOzbX4jZ.js.map +1 -0
- package/dist/SimulationProfile-DSYZbBLQ.js +165 -0
- package/dist/SimulationProfile-DSYZbBLQ.js.map +1 -0
- package/dist/StylePack-DcRa_kU0.js +88 -0
- package/dist/StylePack-DcRa_kU0.js.map +1 -0
- package/dist/WorldArchive-BiFGLt--.js +451 -0
- package/dist/WorldArchive-BiFGLt--.js.map +1 -0
- package/dist/WorldCommands-Debj7V4L.js +2207 -0
- package/dist/WorldCommands-Debj7V4L.js.map +1 -0
- package/dist/WorldIO-Ch8QBfKY.js +151 -0
- package/dist/WorldIO-Ch8QBfKY.js.map +1 -0
- package/dist/admission-CVEvsrdz.js +121 -0
- package/dist/admission-CVEvsrdz.js.map +1 -0
- package/dist/blankWorld-B0MW6g7q.js +75 -0
- package/dist/blankWorld-B0MW6g7q.js.map +1 -0
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/disposeObject3D-DIMzy0FA.js +128 -0
- package/dist/disposeObject3D-DIMzy0FA.js.map +1 -0
- package/dist/environments-HOe3sJXH.js +567 -0
- package/dist/environments-HOe3sJXH.js.map +1 -0
- package/dist/gltfIO-BzVKLyaL.js +339 -0
- package/dist/gltfIO-BzVKLyaL.js.map +1 -0
- package/dist/grandUrbanBlock-DRndRZjF.js +515 -0
- package/dist/grandUrbanBlock-DRndRZjF.js.map +1 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +16952 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-CfBZjx2Q.js +11019 -0
- package/dist/magicCabin-CfBZjx2Q.js.map +1 -0
- package/dist/manifests-D0LwbJ36.js +866 -0
- package/dist/manifests-D0LwbJ36.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-awZiGtda.js +403 -0
- package/dist/monumentHall-awZiGtda.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/parts-DrEcfJRl.js +37 -0
- package/dist/parts-DrEcfJRl.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js +696 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js.map +1 -0
- package/dist/runtime/application/AgentTools.js +28 -0
- package/dist/runtime/application/README.md +14 -0
- package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
- package/dist/runtime/application/agent/StudioMcpAllowlist.js +10 -0
- package/dist/runtime/application/agent/StudioProjectTools.js +18 -0
- package/dist/runtime/application/agent/TaskEvidence.js +199 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +50 -0
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +82 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +630 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +215 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +289 -0
- package/dist/runtime/application/native-scene/CodeProject.js +215 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +143 -0
- package/dist/runtime/application/native-scene/ExampleWorldCatalog.js +35 -0
- package/dist/runtime/application/native-scene/NativeArticulation.js +53 -0
- package/dist/runtime/application/native-scene/NativeEditableRegistry.js +150 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +85 -0
- package/dist/runtime/application/native-scene/NativeLightingInspection.js +33 -0
- package/dist/runtime/application/native-scene/NativeMaterialInspection.js +52 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativePhysicsGeometry.js +64 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +406 -0
- package/dist/runtime/application/native-scene/NativeSceneInspection.js +203 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeSceneQuery.js +123 -0
- package/dist/runtime/application/native-scene/NativeSceneReview.js +132 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/native-scene/SceneObserver.js +97 -0
- package/dist/runtime/application/native-scene/VisualCapturePolicy.js +4 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +263 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
- package/dist/runtime/application/scene/CapabilityResolver.js +90 -0
- package/dist/runtime/application/scene/NativeEditableContracts.js +18 -0
- package/dist/runtime/application/scene/RequestWindow.js +54 -0
- package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
- package/dist/runtime/application/scene/SceneContracts.js +49 -0
- package/dist/runtime/application/scene/SceneEditService.js +154 -0
- package/dist/runtime/application/scene/SceneFacade.js +356 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +41 -0
- package/dist/runtime/application/scene/SceneJobController.js +320 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +173 -0
- package/dist/runtime/application/scene/ScenePersistence.js +50 -0
- package/dist/runtime/application/scene/SceneProject.js +95 -0
- package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
- package/dist/runtime/application/scene/StarterScene.js +56 -0
- package/dist/runtime/application/scene/WorldArchive.js +89 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +76 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +155 -0
- package/dist/runtime/application/skills/SkillRegistry.js +193 -0
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
- package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
- package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
- package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
- package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
- package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
- package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
- package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
- package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
- package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
- package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
- package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
- package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
- package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
- package/dist/runtime/application/skills/skillPrimitives.js +4 -0
- package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
- package/dist/runtime/application/tasks.jsonl +67 -0
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +92 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/application/world-authoring/SceneGLBExport.js +88 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +68 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +157 -0
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
- package/dist/runtime/apps/mcp-server/README.md +269 -0
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
- package/dist/runtime/apps/mcp-server/SessionManager.js +148 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +75 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +246 -0
- package/dist/runtime/apps/mcp-server/StudioProjectToolContracts.js +58 -0
- package/dist/runtime/apps/mcp-server/TransferHttp.js +47 -0
- package/dist/runtime/apps/mcp-server/TransferLimits.js +6 -0
- package/dist/runtime/apps/mcp-server/TransferStore.js +134 -0
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
- package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
- package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
- package/dist/runtime/apps/mcp-server/main.mjs +82 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +274 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +23 -0
- package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
- package/dist/runtime/apps/server/README.md +7 -0
- package/dist/runtime/apps/server/WorldRepository.js +338 -0
- package/dist/runtime/apps/server/WorldRepositoryHttp.js +96 -0
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
- package/dist/runtime/apps/server/tasks.jsonl +10 -0
- package/dist/runtime/apps/shared/node/WorldDiskStorage.js +62 -0
- package/dist/runtime/foundation/EventBus.js +26 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -0
- package/dist/runtime/foundation/PngRgba.js +99 -0
- package/dist/runtime/foundation/PolicyEngine.js +21 -0
- package/dist/runtime/foundation/README.md +7 -0
- package/dist/runtime/foundation/TraceRecorder.js +76 -0
- package/dist/runtime/foundation/errors.js +8 -0
- package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
- package/dist/runtime/foundation/version.js +2 -0
- package/dist/runtime/modules/agent/README.md +11 -0
- package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
- package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
- package/dist/runtime/modules/agent/prompt/index.js +52 -0
- package/dist/runtime/modules/agent/tasks.jsonl +94 -0
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
- package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
- package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
- package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
- package/dist/runtime/modules/artifact/README.md +7 -0
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
- package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
- package/dist/runtime/modules/asset/AssetModule.js +416 -0
- package/dist/runtime/modules/asset/README.md +67 -0
- package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +139 -0
- package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
- package/dist/runtime/modules/asset/model/ProceduralTextureContract.js +24 -0
- package/dist/runtime/modules/asset/model/admission.js +117 -0
- package/dist/runtime/modules/asset/model/errors.js +6 -0
- package/dist/runtime/modules/asset/model/parts.js +27 -0
- package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
- package/dist/runtime/modules/asset/model/schema.js +150 -0
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
- package/dist/runtime/modules/asset/production/AssetRecipe.js +91 -0
- package/dist/runtime/modules/asset/production/ProceduralTexture.js +85 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
- package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
- package/dist/runtime/modules/asset/tasks.jsonl +87 -0
- package/dist/runtime/modules/generation/README.md +9 -0
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
- package/dist/runtime/modules/generation/tasks.jsonl +35 -0
- package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +263 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +660 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +414 -0
- package/dist/runtime/modules/rendering/README.md +7 -0
- package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
- package/dist/runtime/modules/rendering/captureStill.js +54 -0
- package/dist/runtime/modules/rendering/createRenderer.js +76 -0
- package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
- package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
- package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
- package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
- package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
- package/dist/runtime/modules/world/README.md +13 -0
- package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
- package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
- package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
- package/dist/runtime/modules/world/content/blankWorld.js +35 -0
- package/dist/runtime/modules/world/content/environments.js +84 -0
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
- package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
- package/dist/runtime/modules/world/content/magicCabin.js +190 -0
- package/dist/runtime/modules/world/content/monumentHall.js +154 -0
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
- package/dist/runtime/modules/world/errors.js +9 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
- package/dist/runtime/modules/world/runtime/CommandHistory.js +111 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +165 -0
- package/dist/runtime/modules/world/runtime/NativeNavigationGeometry.js +84 -0
- package/dist/runtime/modules/world/runtime/NativePhysicsSnapshot.js +245 -0
- package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +240 -0
- package/dist/runtime/modules/world/runtime/SceneExtensions.js +36 -0
- package/dist/runtime/modules/world/runtime/ScenePresentation.js +101 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +281 -0
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
- package/dist/runtime/modules/world/runtime/WorldCommands.js +503 -0
- package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
- package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +806 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +110 -0
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +390 -0
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +244 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +147 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/ManipulationActions.js +7 -0
- package/dist/runtime/modules/world/runtime/interaction/NativePhysicalTarget.js +31 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +134 -0
- package/dist/runtime/modules/world/runtime/semantic/NativePhysicsState.js +89 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +129 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +104 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/simulation/WorldTimeline.js +110 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/spatial/VisualMeshBounds.js +41 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +306 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +39 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +806 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +281 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +561 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1752 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +527 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +402 -0
- package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
- package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
- package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
- package/dist/runtime/modules/world/tasks.jsonl +530 -0
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
- package/dist/runtime/modules/world/verification/Finding.js +105 -0
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +73 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/VisualLayoutAcceptance.js +58 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +176 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +67 -0
- package/dist/runtime/package-lock.json +16071 -0
- package/dist/runtime/package.json +106 -0
- package/dist/runtime/public/assets/cabinet.glb +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
- package/dist/schema-DT7K9NjP.js +165 -0
- package/dist/schema-DT7K9NjP.js.map +1 -0
- package/dist/suzhouGarden-Y3hny8j6.js +6150 -0
- package/dist/suzhouGarden-Y3hny8j6.js.map +1 -0
- package/dist/version-CHc-i8ch.js +5 -0
- package/dist/version-CHc-i8ch.js.map +1 -0
- package/dist/woodlandWorkshop-DsScU-cx.js +483 -0
- package/dist/woodlandWorkshop-DsScU-cx.js.map +1 -0
- package/dist/yuanmingyuan-DsFnPzzR.js +4955 -0
- package/dist/yuanmingyuan-DsFnPzzR.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ArtifactContractError, requireSafeArtifactId } from './ArtifactDescriptor.js';
|
|
2
|
+
import { artifactContentNeedsFullBytes, validateArtifactContent } from './ArtifactContentGate.js';
|
|
3
|
+
import { IncrementalSha256 } from './IncrementalSha256.js';
|
|
4
|
+
|
|
5
|
+
let fallbackId=0;
|
|
6
|
+
const defaultIdFactory=(kind)=>{
|
|
7
|
+
const uuid=globalThis.crypto?.randomUUID?.();
|
|
8
|
+
return `${kind}_${uuid ? uuid.replaceAll('-','') : `${Date.now()}_${++fallbackId}`}`;
|
|
9
|
+
};
|
|
10
|
+
const nowIso=(now)=>new Date(now()).toISOString();
|
|
11
|
+
const header=(response,name)=>response?.headers?.get?.(name) ?? response?.headers?.get?.(name.toLowerCase()) ?? null;
|
|
12
|
+
const normalizeContentType=(value)=>String(value||'').split(';',1)[0].trim().toLowerCase();
|
|
13
|
+
const concat=(chunks,total)=>{
|
|
14
|
+
const out=new Uint8Array(total);
|
|
15
|
+
let offset=0;
|
|
16
|
+
for (const chunk of chunks) { out.set(chunk,offset); offset+=chunk.byteLength; }
|
|
17
|
+
return out;
|
|
18
|
+
};
|
|
19
|
+
const asChunk=(value)=>{
|
|
20
|
+
if (value instanceof Uint8Array) return value;
|
|
21
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
22
|
+
if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer,value.byteOffset,value.byteLength);
|
|
23
|
+
throw new ArtifactContractError('ARTIFACT_STREAM_INVALID','Artifact response stream yielded a non-byte chunk');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function contentLength(response) {
|
|
27
|
+
const raw=header(response,'content-length');
|
|
28
|
+
if (raw==null||raw==='') return null;
|
|
29
|
+
if (!/^\d+$/.test(String(raw).trim())) throw new ArtifactContractError('ARTIFACT_LENGTH_INVALID','Artifact Content-Length is invalid');
|
|
30
|
+
const n=Number(raw);
|
|
31
|
+
if (!Number.isSafeInteger(n)||n<0) throw new ArtifactContractError('ARTIFACT_LENGTH_INVALID','Artifact Content-Length is outside safe integer range');
|
|
32
|
+
return n;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class ArtifactImporter {
|
|
36
|
+
constructor({
|
|
37
|
+
registry,
|
|
38
|
+
connectorArtifactClient,
|
|
39
|
+
byteStore,
|
|
40
|
+
maxBytes=256*1024*1024,
|
|
41
|
+
maxStructuredBytes=16*1024*1024,
|
|
42
|
+
maxJsonDepth=64,
|
|
43
|
+
maxJsonNodes=100000,
|
|
44
|
+
maxChunks=65536,
|
|
45
|
+
now=()=>Date.now(),
|
|
46
|
+
idFactory=defaultIdFactory
|
|
47
|
+
}={}) {
|
|
48
|
+
if (!registry?.get||!registry?.verifyIntegrity||!registry?.acquireLease) throw new ArtifactContractError('ARTIFACT_IMPORTER_INVALID','ArtifactImporter requires ArtifactRegistry');
|
|
49
|
+
if (!connectorArtifactClient?.open) throw new ArtifactContractError('ARTIFACT_IMPORTER_INVALID','ArtifactImporter requires ConnectorArtifactClient');
|
|
50
|
+
const limit=Number(maxBytes);
|
|
51
|
+
if (!Number.isSafeInteger(limit)||limit<0) throw new ArtifactContractError('ARTIFACT_BYTES_LIMIT','ArtifactImporter maxBytes must be a non-negative safe integer');
|
|
52
|
+
const structuredLimit=Number(maxStructuredBytes);
|
|
53
|
+
if (!Number.isSafeInteger(structuredLimit)||structuredLimit<0) throw new ArtifactContractError('ARTIFACT_STRUCTURE_LIMIT','ArtifactImporter maxStructuredBytes must be a non-negative safe integer');
|
|
54
|
+
this.registry=registry;
|
|
55
|
+
this.connectorArtifactClient=connectorArtifactClient;
|
|
56
|
+
this.byteStore=byteStore;
|
|
57
|
+
const jsonDepth=Number(maxJsonDepth),jsonNodes=Number(maxJsonNodes),chunkLimit=Number(maxChunks);
|
|
58
|
+
if (!Number.isSafeInteger(jsonDepth)||jsonDepth<1) throw new ArtifactContractError('ARTIFACT_STRUCTURE_LIMIT','ArtifactImporter maxJsonDepth must be a positive safe integer');
|
|
59
|
+
if (!Number.isSafeInteger(jsonNodes)||jsonNodes<1) throw new ArtifactContractError('ARTIFACT_STRUCTURE_LIMIT','ArtifactImporter maxJsonNodes must be a positive safe integer');
|
|
60
|
+
if (!Number.isSafeInteger(chunkLimit)||chunkLimit<1) throw new ArtifactContractError('ARTIFACT_STREAM_LIMIT','ArtifactImporter maxChunks must be a positive safe integer');
|
|
61
|
+
if (!byteStore?.begin||!byteStore?.remove) throw new ArtifactContractError('ARTIFACT_IMPORTER_INVALID','ArtifactImporter byteStore requires begin/remove transaction APIs');
|
|
62
|
+
this.maxBytes=limit;
|
|
63
|
+
this.maxStructuredBytes=Math.min(structuredLimit,limit);
|
|
64
|
+
this.maxJsonDepth=jsonDepth;
|
|
65
|
+
this.maxJsonNodes=jsonNodes;
|
|
66
|
+
this.maxChunks=chunkLimit;
|
|
67
|
+
this.now=now;
|
|
68
|
+
this.idFactory=idFactory;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async import(artifactId) {
|
|
72
|
+
const id=requireSafeArtifactId(artifactId);
|
|
73
|
+
const descriptor=this.registry.get(id);
|
|
74
|
+
if (!descriptor) throw new ArtifactContractError('ARTIFACT_NOT_FOUND','Artifact does not exist',{id});
|
|
75
|
+
const source=descriptor.locations.find((location)=>
|
|
76
|
+
location.kind==='connector' && location.state==='available' &&
|
|
77
|
+
location.access?.kind==='connector-artifact' && location.access.artifactId===id
|
|
78
|
+
);
|
|
79
|
+
if (!source) throw new ArtifactContractError('ARTIFACT_SOURCE_UNAVAILABLE','Artifact has no available Connector source',{id});
|
|
80
|
+
if (descriptor.bytes>this.maxBytes) throw new ArtifactContractError('ARTIFACT_BYTES_LIMIT','Artifact declared bytes exceed importer maxBytes',{bytes:descriptor.bytes,maxBytes:this.maxBytes});
|
|
81
|
+
if (artifactContentNeedsFullBytes(descriptor.mime) && descriptor.bytes>this.maxStructuredBytes) {
|
|
82
|
+
throw new ArtifactContractError('ARTIFACT_STRUCTURE_LIMIT','Artifact requiring bounded full-byte validation exceeds maxStructuredBytes',{
|
|
83
|
+
bytes:descriptor.bytes,maxStructuredBytes:this.maxStructuredBytes,mime:descriptor.mime
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const leaseId=requireSafeArtifactId(this.idFactory('lease',descriptor),'leaseId');
|
|
88
|
+
const cacheKey=requireSafeArtifactId(this.idFactory('cache',descriptor),'cacheKey');
|
|
89
|
+
const locationId=requireSafeArtifactId(this.idFactory('loc',descriptor),'locationId');
|
|
90
|
+
let writer=null;
|
|
91
|
+
let reader=null;
|
|
92
|
+
let committed=null;
|
|
93
|
+
let locationAdded=false;
|
|
94
|
+
let leaseHeld=false;
|
|
95
|
+
try {
|
|
96
|
+
this.registry.acquireLease(id,{
|
|
97
|
+
id:leaseId,holder:{kind:'transfer',id:leaseId},reason:'artifact-import',createdAt:nowIso(this.now)
|
|
98
|
+
});
|
|
99
|
+
leaseHeld=true;
|
|
100
|
+
const response=await this.connectorArtifactClient.open(id,{accept:descriptor.mime,expectedConnector:source.access.connector});
|
|
101
|
+
const encoding=String(header(response,'content-encoding')||'').trim().toLowerCase();
|
|
102
|
+
if (encoding && encoding!=='identity') throw new ArtifactContractError('ARTIFACT_CONTENT_ENCODING_UNSUPPORTED','Artifact transfer must not use transparent content encoding',{encoding});
|
|
103
|
+
const responseType=normalizeContentType(header(response,'content-type'));
|
|
104
|
+
if (responseType && responseType!==descriptor.mime) {
|
|
105
|
+
throw new ArtifactContractError('ARTIFACT_CONTENT_TYPE_MISMATCH','Artifact Content-Type does not match descriptor MIME',{expected:descriptor.mime,actual:responseType});
|
|
106
|
+
}
|
|
107
|
+
const declaredLength=contentLength(response);
|
|
108
|
+
if (declaredLength!=null) {
|
|
109
|
+
if (declaredLength>this.maxBytes) throw new ArtifactContractError('ARTIFACT_BYTES_LIMIT','Artifact Content-Length exceeds importer maxBytes',{bytes:declaredLength,maxBytes:this.maxBytes});
|
|
110
|
+
if (declaredLength!==descriptor.bytes) throw new ArtifactContractError('ARTIFACT_LENGTH_MISMATCH','Artifact Content-Length does not match descriptor bytes',{expected:descriptor.bytes,actual:declaredLength});
|
|
111
|
+
}
|
|
112
|
+
if (!response.body?.getReader) throw new ArtifactContractError('ARTIFACT_STREAM_UNAVAILABLE','Artifact response must provide a readable byte stream');
|
|
113
|
+
|
|
114
|
+
writer=this.byteStore.begin({artifactId:id,maxBytes:this.maxBytes});
|
|
115
|
+
reader=response.body.getReader();
|
|
116
|
+
const hasher=new IncrementalSha256();
|
|
117
|
+
const prefix=new Uint8Array(Math.min(64,descriptor.bytes));
|
|
118
|
+
let prefixLength=0;
|
|
119
|
+
const fullChunks=artifactContentNeedsFullBytes(descriptor.mime)?[]:null;
|
|
120
|
+
let total=0;
|
|
121
|
+
let chunkCount=0;
|
|
122
|
+
try {
|
|
123
|
+
while (true) {
|
|
124
|
+
const {done,value}=await reader.read();
|
|
125
|
+
if (done) break;
|
|
126
|
+
chunkCount++;
|
|
127
|
+
if (chunkCount>this.maxChunks) throw new ArtifactContractError('ARTIFACT_STREAM_LIMIT','Artifact stream exceeded maxChunks',{maxChunks:this.maxChunks});
|
|
128
|
+
const chunk=asChunk(value);
|
|
129
|
+
total+=chunk.byteLength;
|
|
130
|
+
if (total>this.maxBytes) throw new ArtifactContractError('ARTIFACT_BYTES_LIMIT','Artifact stream exceeded importer maxBytes',{maxBytes:this.maxBytes});
|
|
131
|
+
if (total>descriptor.bytes) throw new ArtifactContractError('ARTIFACT_LENGTH_MISMATCH','Artifact stream exceeded descriptor bytes',{expected:descriptor.bytes,actualAtLeast:total});
|
|
132
|
+
if (prefixLength<prefix.byteLength) {
|
|
133
|
+
const take=Math.min(prefix.byteLength-prefixLength,chunk.byteLength);
|
|
134
|
+
prefix.set(chunk.subarray(0,take),prefixLength);
|
|
135
|
+
prefixLength+=take;
|
|
136
|
+
}
|
|
137
|
+
if (fullChunks) fullChunks.push(new Uint8Array(chunk));
|
|
138
|
+
hasher.update(chunk);
|
|
139
|
+
await writer.write(chunk);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
try { await reader.cancel?.(); } catch {}
|
|
143
|
+
if (error instanceof ArtifactContractError) throw error;
|
|
144
|
+
throw new ArtifactContractError('ARTIFACT_STREAM_FAILED','Artifact stream failed before integrity verification',{recoverable:true});
|
|
145
|
+
} finally {
|
|
146
|
+
try { reader.releaseLock?.(); } catch {}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (total!==descriptor.bytes) throw new ArtifactContractError('ARTIFACT_LENGTH_MISMATCH','Artifact stream length does not match descriptor bytes',{expected:descriptor.bytes,actual:total});
|
|
150
|
+
const actualHash=hasher.digestArtifactHash();
|
|
151
|
+
if (actualHash!==descriptor.hash) throw new ArtifactContractError('ARTIFACT_HASH_MISMATCH','Artifact SHA-256 does not match descriptor',{expected:descriptor.hash,actual:actualHash});
|
|
152
|
+
const fullBytes=fullChunks?concat(fullChunks,total):null;
|
|
153
|
+
validateArtifactContent(descriptor,{
|
|
154
|
+
prefix:prefix.subarray(0,prefixLength),totalBytes:total,fullBytes,
|
|
155
|
+
maxJsonDepth:this.maxJsonDepth,maxJsonNodes:this.maxJsonNodes
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
committed=await writer.commit({key:cacheKey,hash:actualHash,mime:descriptor.mime,bytes:total});
|
|
159
|
+
const verifiedAt=nowIso(this.now);
|
|
160
|
+
this.registry.updateLocation(id,{
|
|
161
|
+
id:locationId,kind:'local-cache',scope:'application',state:'available',
|
|
162
|
+
verifiedAt,access:{kind:'cache-key',key:committed.key}
|
|
163
|
+
});
|
|
164
|
+
locationAdded=true;
|
|
165
|
+
const artifact=this.registry.verifyIntegrity(id,{
|
|
166
|
+
hash:actualHash,bytes:total,mime:descriptor.mime,verifiedAt,method:'stream-sha256-v1'
|
|
167
|
+
});
|
|
168
|
+
return {artifact,cache:{key:committed.key,locationId},hash:actualHash,bytes:total,mime:descriptor.mime};
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (writer?.state==='open') await writer.abort();
|
|
171
|
+
if (leaseHeld) { this.registry.releaseLease(leaseId); leaseHeld=false; }
|
|
172
|
+
if (locationAdded) {
|
|
173
|
+
try {
|
|
174
|
+
const removed=this.registry.removeLocation(id,locationId);
|
|
175
|
+
if (removed.removed && committed) this.byteStore.remove(committed.key);
|
|
176
|
+
} catch {}
|
|
177
|
+
} else if (committed) {
|
|
178
|
+
this.byteStore.remove(committed.key);
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
} finally {
|
|
182
|
+
if (leaseHeld) this.registry.releaseLease(leaseId);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ArtifactRegistry } from './ArtifactRegistry.js';
|
|
2
|
+
import { ArtifactContractError } from './ArtifactDescriptor.js';
|
|
3
|
+
import { sha256ArtifactHash } from './IncrementalSha256.js';
|
|
4
|
+
import { MemoryArtifactByteStore } from './MemoryArtifactByteStore.js';
|
|
5
|
+
import { IndexedDbArtifactStore } from './storage/IndexedDbArtifactStore.js';
|
|
6
|
+
|
|
7
|
+
const localCacheLocations = (descriptor) => (descriptor.locations || []).filter((location) =>
|
|
8
|
+
location.kind === 'local-cache' &&
|
|
9
|
+
location.state === 'available' &&
|
|
10
|
+
location.access?.kind === 'cache-key'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const persistedEntryFor = (descriptor, entriesByKey) => {
|
|
14
|
+
const locations = localCacheLocations(descriptor);
|
|
15
|
+
for (const location of locations) {
|
|
16
|
+
const entry = entriesByKey.get(location.access.key);
|
|
17
|
+
if (entry) return { location, entry };
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const assertVerifiedPersistence = (descriptor, entry) => {
|
|
23
|
+
const mismatches = [];
|
|
24
|
+
if (!(entry?.data instanceof Uint8Array)) mismatches.push('data');
|
|
25
|
+
if (entry?.artifactId !== descriptor.id) mismatches.push('artifactId');
|
|
26
|
+
if (entry?.hash !== descriptor.hash) mismatches.push('hash');
|
|
27
|
+
if (entry?.mime !== descriptor.mime) mismatches.push('mime');
|
|
28
|
+
if (entry?.bytes !== descriptor.bytes || entry?.data?.byteLength !== descriptor.bytes) mismatches.push('bytes');
|
|
29
|
+
if (!mismatches.length && sha256ArtifactHash([entry.data]) !== descriptor.hash) mismatches.push('contentHash');
|
|
30
|
+
if (mismatches.length) {
|
|
31
|
+
throw new ArtifactContractError(
|
|
32
|
+
'ARTIFACT_PERSISTENCE_INTEGRITY_MISMATCH',
|
|
33
|
+
'Persisted Artifact bytes do not match the verified descriptor',
|
|
34
|
+
{ artifactId: descriptor.id, mismatches }
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function createArtifactModule({
|
|
40
|
+
registry = null,
|
|
41
|
+
byteStore = null,
|
|
42
|
+
persistentStore = undefined,
|
|
43
|
+
now = () => Date.now()
|
|
44
|
+
} = {}) {
|
|
45
|
+
const artifactRegistry = registry || new ArtifactRegistry({ now });
|
|
46
|
+
const artifactByteStore = byteStore || new MemoryArtifactByteStore();
|
|
47
|
+
const durableStore = persistentStore === undefined
|
|
48
|
+
? (globalThis.indexedDB ? new IndexedDbArtifactStore() : null)
|
|
49
|
+
: persistentStore;
|
|
50
|
+
let hydrated = false;
|
|
51
|
+
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
registry: artifactRegistry,
|
|
54
|
+
byteStore: artifactByteStore,
|
|
55
|
+
persistentStore: durableStore,
|
|
56
|
+
|
|
57
|
+
async hydrate() {
|
|
58
|
+
if (hydrated) return { artifacts: artifactRegistry.list().length, restored: false };
|
|
59
|
+
if (!durableStore?.load) {
|
|
60
|
+
hydrated = true;
|
|
61
|
+
return { artifacts: artifactRegistry.list().length, restored: false };
|
|
62
|
+
}
|
|
63
|
+
const snapshot = await durableStore.load();
|
|
64
|
+
const entriesByKey = new Map((snapshot.entries || []).map((entry) => [entry.key, entry]));
|
|
65
|
+
for (const descriptor of snapshot.descriptors || []) {
|
|
66
|
+
const integrity = descriptor.integrity || { state: 'declared' };
|
|
67
|
+
const nonLocalLocations = (descriptor.locations || []).filter((location) => location.kind !== 'local-cache');
|
|
68
|
+
let verifiedPersistence = null;
|
|
69
|
+
if (integrity.state === 'verified') {
|
|
70
|
+
verifiedPersistence = persistedEntryFor(descriptor, entriesByKey);
|
|
71
|
+
if (!verifiedPersistence) {
|
|
72
|
+
throw new ArtifactContractError(
|
|
73
|
+
'ARTIFACT_PERSISTENCE_INTEGRITY_MISMATCH',
|
|
74
|
+
'Verified persisted Artifact has no matching local byte entry',
|
|
75
|
+
{ artifactId: descriptor.id }
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
assertVerifiedPersistence(descriptor, verifiedPersistence.entry);
|
|
79
|
+
}
|
|
80
|
+
artifactRegistry.register({
|
|
81
|
+
...descriptor,
|
|
82
|
+
locations: nonLocalLocations,
|
|
83
|
+
integrity: { state: 'declared' }
|
|
84
|
+
});
|
|
85
|
+
if (integrity.state === 'verified') {
|
|
86
|
+
artifactByteStore.restore(verifiedPersistence.entry);
|
|
87
|
+
artifactRegistry.updateLocation(descriptor.id, verifiedPersistence.location);
|
|
88
|
+
artifactRegistry.verifyIntegrity(descriptor.id, {
|
|
89
|
+
hash: sha256ArtifactHash([verifiedPersistence.entry.data]),
|
|
90
|
+
bytes: verifiedPersistence.entry.data.byteLength,
|
|
91
|
+
mime: verifiedPersistence.entry.mime,
|
|
92
|
+
verifiedAt: new Date(now()).toISOString(),
|
|
93
|
+
method: 'persisted-sha256-v1'
|
|
94
|
+
});
|
|
95
|
+
} else if (integrity.state === 'rejected' && integrity.rejection) {
|
|
96
|
+
artifactRegistry.rejectIntegrity(descriptor.id, integrity.rejection);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
hydrated = true;
|
|
100
|
+
return { artifacts: (snapshot.descriptors || []).length, entries: (snapshot.entries || []).length, restored: true };
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
async persistArtifact(artifactId, cacheKey) {
|
|
104
|
+
if (!durableStore?.putArtifact) return false;
|
|
105
|
+
const descriptor = artifactRegistry.get(artifactId);
|
|
106
|
+
const entry = artifactByteStore.get(cacheKey);
|
|
107
|
+
if (!descriptor || !entry) return false;
|
|
108
|
+
return durableStore.putArtifact(descriptor, entry);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ARTIFACT_LEASE_HOLDER_KINDS,
|
|
3
|
+
ArtifactContractError,
|
|
4
|
+
artifactImmutableSignature,
|
|
5
|
+
normalizeArtifactDescriptor,
|
|
6
|
+
normalizeArtifactHash,
|
|
7
|
+
normalizeArtifactLocation,
|
|
8
|
+
requireSafeArtifactId
|
|
9
|
+
} from './ArtifactDescriptor.js';
|
|
10
|
+
|
|
11
|
+
const HOLDER_KIND_SET=new Set(ARTIFACT_LEASE_HOLDER_KINDS);
|
|
12
|
+
const SAFE_REASON=/^[A-Za-z0-9][A-Za-z0-9 ._:-]{0,199}$/;
|
|
13
|
+
const SAFE_CODE=/^[A-Z0-9][A-Z0-9._:-]{0,119}$/i;
|
|
14
|
+
const UNSAFE_REASON_RE=/https?:\/\/|Bearer\s+/i;
|
|
15
|
+
const clone=(value)=>value == null ? value : structuredClone(value);
|
|
16
|
+
|
|
17
|
+
function normalizeTime(value,field,{required=false}={}) {
|
|
18
|
+
if (value==null||value==='') {
|
|
19
|
+
if (required) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID',`Artifact lease requires ${field}`,{field});
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const time=Date.parse(String(value));
|
|
23
|
+
if (!Number.isFinite(time)) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID',`Artifact lease has invalid ${field}`,{field});
|
|
24
|
+
return new Date(time).toISOString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeLease(value={},artifactId) {
|
|
28
|
+
if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID','Artifact lease must be an object');
|
|
29
|
+
const holder=value.holder;
|
|
30
|
+
if (!holder || typeof holder!=='object' || Array.isArray(holder)) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID','Artifact lease requires holder');
|
|
31
|
+
const holderKind=String(holder.kind||'');
|
|
32
|
+
if (!HOLDER_KIND_SET.has(holderKind)) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID',`Unsupported artifact lease holder kind: ${holderKind}`);
|
|
33
|
+
const reason=String(value.reason||'').trim();
|
|
34
|
+
if (!SAFE_REASON.test(reason) || UNSAFE_REASON_RE.test(reason)) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID','Artifact lease reason is invalid');
|
|
35
|
+
const createdAt=normalizeTime(value.createdAt,'createdAt',{required:true});
|
|
36
|
+
const expiresAt=normalizeTime(value.expiresAt,'expiresAt');
|
|
37
|
+
if (expiresAt && Date.parse(expiresAt)<=Date.parse(createdAt)) throw new ArtifactContractError('ARTIFACT_LEASE_INVALID','Artifact lease expiry must be after creation');
|
|
38
|
+
return {
|
|
39
|
+
id:requireSafeArtifactId(value.id,'lease.id'),
|
|
40
|
+
artifactId,
|
|
41
|
+
locationId:value.locationId==null?null:requireSafeArtifactId(value.locationId,'lease.locationId'),
|
|
42
|
+
holder:{kind:holderKind,id:requireSafeArtifactId(holder.id,'lease.holder.id')},
|
|
43
|
+
reason,
|
|
44
|
+
createdAt,
|
|
45
|
+
expiresAt
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ArtifactRegistry {
|
|
50
|
+
#now;
|
|
51
|
+
#artifacts=new Map();
|
|
52
|
+
#hashIndex=new Map();
|
|
53
|
+
#leases=new Map();
|
|
54
|
+
|
|
55
|
+
constructor({now=()=>Date.now()}={}) {
|
|
56
|
+
this.#now=now;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
register(payload) {
|
|
60
|
+
const descriptor=normalizeArtifactDescriptor(payload);
|
|
61
|
+
const previous=this.#artifacts.get(descriptor.id);
|
|
62
|
+
if (previous) {
|
|
63
|
+
if (artifactImmutableSignature(previous)!==artifactImmutableSignature(descriptor)) {
|
|
64
|
+
throw new ArtifactContractError('ARTIFACT_IDENTITY_CONFLICT','Artifact ID already exists with different immutable identity',{id:descriptor.id});
|
|
65
|
+
}
|
|
66
|
+
return this.get(descriptor.id);
|
|
67
|
+
}
|
|
68
|
+
this.#artifacts.set(descriptor.id,descriptor);
|
|
69
|
+
if (!this.#hashIndex.has(descriptor.hash)) this.#hashIndex.set(descriptor.hash,new Set());
|
|
70
|
+
this.#hashIndex.get(descriptor.hash).add(descriptor.id);
|
|
71
|
+
return this.get(descriptor.id);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
has(id) { return this.#artifacts.has(id); }
|
|
75
|
+
|
|
76
|
+
get(id) {
|
|
77
|
+
const artifact=this.#artifacts.get(id);
|
|
78
|
+
return artifact?clone(artifact):null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
list() {
|
|
82
|
+
return [...this.#artifacts.values()].map(clone).sort((a,b)=>Date.parse(b.createdAt)-Date.parse(a.createdAt)||a.id.localeCompare(b.id));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
findByHash(hash) {
|
|
86
|
+
const canonical=normalizeArtifactHash(hash);
|
|
87
|
+
return [...(this.#hashIndex.get(canonical)||[])].sort();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
updateLocation(id,locationPayload) {
|
|
91
|
+
const artifactId=requireSafeArtifactId(id);
|
|
92
|
+
const artifact=this.#artifacts.get(artifactId);
|
|
93
|
+
if (!artifact) throw new ArtifactContractError('ARTIFACT_NOT_FOUND','Artifact does not exist',{id:artifactId});
|
|
94
|
+
const location=normalizeArtifactLocation(locationPayload,artifactId);
|
|
95
|
+
const next=clone(artifact);
|
|
96
|
+
const index=next.locations.findIndex((item)=>item.id===location.id);
|
|
97
|
+
if (index===-1) {
|
|
98
|
+
next.locations.push(location);
|
|
99
|
+
} else {
|
|
100
|
+
const previous=next.locations[index];
|
|
101
|
+
const accessConflict=previous.access && location.access && JSON.stringify(previous.access)!==JSON.stringify(location.access);
|
|
102
|
+
if (previous.kind!==location.kind || previous.scope!==location.scope || accessConflict) {
|
|
103
|
+
throw new ArtifactContractError('ARTIFACT_LOCATION_IDENTITY_CONFLICT','Artifact location ID cannot change kind, scope, or active access identity',{
|
|
104
|
+
id:artifactId,locationId:location.id
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
next.locations[index]=location;
|
|
108
|
+
}
|
|
109
|
+
this.#artifacts.set(artifactId,next);
|
|
110
|
+
return this.get(artifactId);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
removeLocation(id,locationId) {
|
|
114
|
+
const artifactId=requireSafeArtifactId(id);
|
|
115
|
+
const locationKey=requireSafeArtifactId(locationId,'locationId');
|
|
116
|
+
const artifact=this.#artifacts.get(artifactId);
|
|
117
|
+
if (!artifact) throw new ArtifactContractError('ARTIFACT_NOT_FOUND','Artifact does not exist',{id:artifactId});
|
|
118
|
+
if (!artifact.locations.some((item)=>item.id===locationKey)) return {removed:false,artifact:this.get(artifactId)};
|
|
119
|
+
if (this.isLeased(artifactId,{locationId:locationKey})) {
|
|
120
|
+
throw new ArtifactContractError('ARTIFACT_LOCATION_LEASED','Artifact location is protected by an active lease',{id:artifactId,locationId:locationKey});
|
|
121
|
+
}
|
|
122
|
+
const next=clone(artifact);
|
|
123
|
+
next.locations=next.locations.filter((item)=>item.id!==locationKey);
|
|
124
|
+
this.#artifacts.set(artifactId,next);
|
|
125
|
+
return {removed:true,artifact:this.get(artifactId)};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
verifyIntegrity(id,evidence={}) {
|
|
129
|
+
const artifactId=requireSafeArtifactId(id);
|
|
130
|
+
const artifact=this.#artifacts.get(artifactId);
|
|
131
|
+
if (!artifact) throw new ArtifactContractError('ARTIFACT_NOT_FOUND','Artifact does not exist',{id:artifactId});
|
|
132
|
+
const hash=normalizeArtifactHash(evidence.hash,'integrity.hash');
|
|
133
|
+
const bytes=Number(evidence.bytes);
|
|
134
|
+
if (!Number.isSafeInteger(bytes)||bytes<0) throw new ArtifactContractError('ARTIFACT_INTEGRITY_INVALID','Integrity evidence bytes are invalid');
|
|
135
|
+
const mime=String(evidence.mime||'').trim().toLowerCase();
|
|
136
|
+
if (hash!==artifact.hash||bytes!==artifact.bytes||mime!==artifact.mime) {
|
|
137
|
+
throw new ArtifactContractError('ARTIFACT_INTEGRITY_MISMATCH','Integrity evidence does not match the declared descriptor',{id:artifactId});
|
|
138
|
+
}
|
|
139
|
+
const verifiedAt=normalizeTime(evidence.verifiedAt,'verifiedAt',{required:true});
|
|
140
|
+
const method=String(evidence.method||'').trim();
|
|
141
|
+
if (!method || !SAFE_CODE.test(method)) throw new ArtifactContractError('ARTIFACT_INTEGRITY_INVALID','Integrity verification method must be a stable safe identifier');
|
|
142
|
+
const next=clone(artifact);
|
|
143
|
+
next.integrity={state:'verified',verifiedAt,method,rejection:null};
|
|
144
|
+
this.#artifacts.set(artifactId,next);
|
|
145
|
+
return this.get(artifactId);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
rejectIntegrity(id,evidence={}) {
|
|
149
|
+
const artifactId=requireSafeArtifactId(id);
|
|
150
|
+
const artifact=this.#artifacts.get(artifactId);
|
|
151
|
+
if (!artifact) throw new ArtifactContractError('ARTIFACT_NOT_FOUND','Artifact does not exist',{id:artifactId});
|
|
152
|
+
const code=String(evidence.code||'').trim();
|
|
153
|
+
if (!code || !SAFE_CODE.test(code)) throw new ArtifactContractError('ARTIFACT_INTEGRITY_INVALID','Integrity rejection code must be a stable safe identifier');
|
|
154
|
+
const checkedAt=normalizeTime(evidence.checkedAt,'checkedAt',{required:true});
|
|
155
|
+
const next=clone(artifact);
|
|
156
|
+
next.integrity={state:'rejected',verifiedAt:null,method:null,rejection:{code,checkedAt}};
|
|
157
|
+
this.#artifacts.set(artifactId,next);
|
|
158
|
+
return this.get(artifactId);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
acquireLease(artifactId,leasePayload) {
|
|
162
|
+
const id=requireSafeArtifactId(artifactId);
|
|
163
|
+
const artifact=this.#artifacts.get(id);
|
|
164
|
+
if (!artifact) throw new ArtifactContractError('ARTIFACT_NOT_FOUND','Artifact does not exist',{id});
|
|
165
|
+
const lease=normalizeLease(leasePayload,id);
|
|
166
|
+
if (lease.expiresAt && Date.parse(lease.expiresAt)<=this.#now()) {
|
|
167
|
+
throw new ArtifactContractError('ARTIFACT_LEASE_INVALID','Artifact lease is already expired',{leaseId:lease.id});
|
|
168
|
+
}
|
|
169
|
+
if (lease.locationId && !artifact.locations.some((location)=>location.id===lease.locationId)) {
|
|
170
|
+
throw new ArtifactContractError('ARTIFACT_LEASE_INVALID','Artifact lease references an unknown location',{id,locationId:lease.locationId});
|
|
171
|
+
}
|
|
172
|
+
const previous=this.#leases.get(lease.id);
|
|
173
|
+
if (previous && JSON.stringify(previous)!==JSON.stringify(lease)) throw new ArtifactContractError('ARTIFACT_LEASE_CONFLICT','Artifact lease ID already exists with different semantics',{leaseId:lease.id});
|
|
174
|
+
this.#leases.set(lease.id,lease);
|
|
175
|
+
return clone(lease);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
releaseLease(leaseId) {
|
|
179
|
+
const id=requireSafeArtifactId(leaseId,'leaseId');
|
|
180
|
+
return this.#leases.delete(id);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
leasesFor(artifactId,{includeExpired=false}={}) {
|
|
184
|
+
const id=requireSafeArtifactId(artifactId);
|
|
185
|
+
const now=this.#now();
|
|
186
|
+
return [...this.#leases.values()]
|
|
187
|
+
.filter((lease)=>lease.artifactId===id && (includeExpired || !lease.expiresAt || Date.parse(lease.expiresAt)>now))
|
|
188
|
+
.map(clone)
|
|
189
|
+
.sort((a,b)=>a.id.localeCompare(b.id));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
isLeased(artifactId,{locationId=null}={}) {
|
|
193
|
+
const id=requireSafeArtifactId(artifactId);
|
|
194
|
+
const location=locationId==null?null:requireSafeArtifactId(locationId,'locationId');
|
|
195
|
+
return this.leasesFor(id).some((lease)=>lease.locationId==null || location==null || lease.locationId===location);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const K=new Uint32Array([
|
|
2
|
+
0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
|
|
3
|
+
0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
|
|
4
|
+
0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
|
|
5
|
+
0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
|
|
6
|
+
0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
|
|
7
|
+
0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
|
|
8
|
+
0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
|
|
9
|
+
0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const INITIAL=new Uint32Array([
|
|
13
|
+
0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,
|
|
14
|
+
0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19
|
|
15
|
+
]);
|
|
16
|
+
const rotr=(x,n)=>(x>>>n)|(x<<(32-n));
|
|
17
|
+
const asBytes=(value)=>{
|
|
18
|
+
if (value instanceof Uint8Array) return value;
|
|
19
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
20
|
+
if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer,value.byteOffset,value.byteLength);
|
|
21
|
+
throw new TypeError('SHA-256 update requires Uint8Array or ArrayBuffer data');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class IncrementalSha256 {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.state=new Uint32Array(INITIAL);
|
|
27
|
+
this.buffer=new Uint8Array(64);
|
|
28
|
+
this.bufferLength=0;
|
|
29
|
+
this.bytesHashed=0;
|
|
30
|
+
this.finished=false;
|
|
31
|
+
this.words=new Uint32Array(64);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
update(value) {
|
|
35
|
+
if (this.finished) throw new Error('SHA-256 digest is already finalized');
|
|
36
|
+
const bytes=asBytes(value);
|
|
37
|
+
if (!bytes.byteLength) return this;
|
|
38
|
+
if (!Number.isSafeInteger(this.bytesHashed+bytes.byteLength)) throw new Error('SHA-256 input exceeds safe byte count');
|
|
39
|
+
this.bytesHashed+=bytes.byteLength;
|
|
40
|
+
let offset=0;
|
|
41
|
+
if (this.bufferLength) {
|
|
42
|
+
const take=Math.min(64-this.bufferLength,bytes.byteLength);
|
|
43
|
+
this.buffer.set(bytes.subarray(0,take),this.bufferLength);
|
|
44
|
+
this.bufferLength+=take;
|
|
45
|
+
offset+=take;
|
|
46
|
+
if (this.bufferLength===64) {
|
|
47
|
+
this.#process(this.buffer,0);
|
|
48
|
+
this.bufferLength=0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
while (offset+64<=bytes.byteLength) {
|
|
52
|
+
this.#process(bytes,offset);
|
|
53
|
+
offset+=64;
|
|
54
|
+
}
|
|
55
|
+
if (offset<bytes.byteLength) {
|
|
56
|
+
this.buffer.set(bytes.subarray(offset),0);
|
|
57
|
+
this.bufferLength=bytes.byteLength-offset;
|
|
58
|
+
}
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
digestBytes() {
|
|
63
|
+
if (!this.finished) this.#finish();
|
|
64
|
+
const out=new Uint8Array(32);
|
|
65
|
+
const view=new DataView(out.buffer);
|
|
66
|
+
for (let i=0;i<8;i++) view.setUint32(i*4,this.state[i],false);
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
digestHex() {
|
|
71
|
+
return [...this.digestBytes()].map((byte)=>byte.toString(16).padStart(2,'0')).join('');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
digestArtifactHash() { return `sha256:${this.digestHex()}`; }
|
|
75
|
+
|
|
76
|
+
#finish() {
|
|
77
|
+
const block=new Uint8Array(128);
|
|
78
|
+
block.set(this.buffer.subarray(0,this.bufferLength),0);
|
|
79
|
+
block[this.bufferLength]=0x80;
|
|
80
|
+
const padLength=this.bufferLength<56?64:128;
|
|
81
|
+
const high=Math.floor(this.bytesHashed/0x20000000)>>>0;
|
|
82
|
+
const low=(this.bytesHashed*8)>>>0;
|
|
83
|
+
const view=new DataView(block.buffer);
|
|
84
|
+
view.setUint32(padLength-8,high,false);
|
|
85
|
+
view.setUint32(padLength-4,low,false);
|
|
86
|
+
this.#process(block,0);
|
|
87
|
+
if (padLength===128) this.#process(block,64);
|
|
88
|
+
this.finished=true;
|
|
89
|
+
this.bufferLength=0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#process(bytes,offset) {
|
|
93
|
+
const w=this.words;
|
|
94
|
+
for (let i=0;i<16;i++) {
|
|
95
|
+
const j=offset+i*4;
|
|
96
|
+
w[i]=((bytes[j]<<24)|(bytes[j+1]<<16)|(bytes[j+2]<<8)|bytes[j+3])>>>0;
|
|
97
|
+
}
|
|
98
|
+
for (let i=16;i<64;i++) {
|
|
99
|
+
const x=w[i-15],y=w[i-2];
|
|
100
|
+
const s0=(rotr(x,7)^rotr(x,18)^(x>>>3))>>>0;
|
|
101
|
+
const s1=(rotr(y,17)^rotr(y,19)^(y>>>10))>>>0;
|
|
102
|
+
w[i]=(w[i-16]+s0+w[i-7]+s1)>>>0;
|
|
103
|
+
}
|
|
104
|
+
let [a,b,c,d,e,f,g,h]=this.state;
|
|
105
|
+
for (let i=0;i<64;i++) {
|
|
106
|
+
const S1=(rotr(e,6)^rotr(e,11)^rotr(e,25))>>>0;
|
|
107
|
+
const ch=((e&f)^((~e)&g))>>>0;
|
|
108
|
+
const t1=(h+S1+ch+K[i]+w[i])>>>0;
|
|
109
|
+
const S0=(rotr(a,2)^rotr(a,13)^rotr(a,22))>>>0;
|
|
110
|
+
const maj=((a&b)^(a&c)^(b&c))>>>0;
|
|
111
|
+
const t2=(S0+maj)>>>0;
|
|
112
|
+
h=g; g=f; f=e; e=(d+t1)>>>0; d=c; c=b; b=a; a=(t1+t2)>>>0;
|
|
113
|
+
}
|
|
114
|
+
this.state[0]=(this.state[0]+a)>>>0;
|
|
115
|
+
this.state[1]=(this.state[1]+b)>>>0;
|
|
116
|
+
this.state[2]=(this.state[2]+c)>>>0;
|
|
117
|
+
this.state[3]=(this.state[3]+d)>>>0;
|
|
118
|
+
this.state[4]=(this.state[4]+e)>>>0;
|
|
119
|
+
this.state[5]=(this.state[5]+f)>>>0;
|
|
120
|
+
this.state[6]=(this.state[6]+g)>>>0;
|
|
121
|
+
this.state[7]=(this.state[7]+h)>>>0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function sha256ArtifactHash(chunks) {
|
|
126
|
+
const hash=new IncrementalSha256();
|
|
127
|
+
for (const chunk of chunks) hash.update(chunk);
|
|
128
|
+
return hash.digestArtifactHash();
|
|
129
|
+
}
|