agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/cli.mjs +53 -0
  4. package/dist/AssetCompiler-A99wKf7H.js +2424 -0
  5. package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
  6. package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
  7. package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
  8. package/dist/AssetRecipe-DCaLLXvG.js +67 -0
  9. package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
  10. package/dist/BrowserCodeWorker.js +53850 -0
  11. package/dist/BrowserCodeWorker.js.map +1 -0
  12. package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
  13. package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
  14. package/dist/SceneSerializer-CLCzQjL_.js +350 -0
  15. package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
  16. package/dist/StylePack-CD_BC-Mv.js +6317 -0
  17. package/dist/StylePack-CD_BC-Mv.js.map +1 -0
  18. package/dist/WorldArchive-dYf1OpSe.js +417 -0
  19. package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
  20. package/dist/WorldIO-Dqz4MqTQ.js +149 -0
  21. package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
  22. package/dist/blankWorld-OoOvN_IK.js +75 -0
  23. package/dist/blankWorld-OoOvN_IK.js.map +1 -0
  24. package/dist/core.d.ts +68 -0
  25. package/dist/core.js +209 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/disposeObject3D-B3HCflvO.js +128 -0
  28. package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
  29. package/dist/environments-B1WaICAN.js +4197 -0
  30. package/dist/environments-B1WaICAN.js.map +1 -0
  31. package/dist/gltfIO-BMK1hc2D.js +9 -0
  32. package/dist/gltfIO-BMK1hc2D.js.map +1 -0
  33. package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
  34. package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
  35. package/dist/index.d.ts +275 -0
  36. package/dist/index.js +16239 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/magicCabin-DPQi_jh-.js +11019 -0
  39. package/dist/magicCabin-DPQi_jh-.js.map +1 -0
  40. package/dist/mcp.d.ts +2 -0
  41. package/dist/mcp.js +1 -0
  42. package/dist/monumentHall-IOLbRZQC.js +403 -0
  43. package/dist/monumentHall-IOLbRZQC.js.map +1 -0
  44. package/dist/node.d.ts +16 -0
  45. package/dist/node.js +26 -0
  46. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  47. package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
  48. package/dist/ruinedCourtyard-BtaF_aOi.js.map +1 -0
  49. package/dist/runtime/application/AgentTools.js +28 -0
  50. package/dist/runtime/application/README.md +14 -0
  51. package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
  52. package/dist/runtime/application/agent/StudioMcpAllowlist.js +8 -0
  53. package/dist/runtime/application/buildTaskObservation.js +117 -0
  54. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -0
  55. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
  56. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
  57. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +72 -0
  58. package/dist/runtime/application/createSession.js +66 -0
  59. package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
  60. package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
  61. package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
  62. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
  63. package/dist/runtime/application/native-scene/CodeProject.js +119 -0
  64. package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
  65. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
  66. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
  67. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
  68. package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
  69. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
  70. package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
  71. package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -0
  72. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
  73. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
  74. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
  75. package/dist/runtime/application/scene/CapabilityResolver.js +79 -0
  76. package/dist/runtime/application/scene/RequestWindow.js +54 -0
  77. package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
  78. package/dist/runtime/application/scene/SceneContracts.js +45 -0
  79. package/dist/runtime/application/scene/SceneEditService.js +144 -0
  80. package/dist/runtime/application/scene/SceneFacade.js +261 -0
  81. package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
  82. package/dist/runtime/application/scene/SceneJobController.js +229 -0
  83. package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
  84. package/dist/runtime/application/scene/ScenePackage.js +162 -0
  85. package/dist/runtime/application/scene/ScenePersistence.js +50 -0
  86. package/dist/runtime/application/scene/SceneProject.js +95 -0
  87. package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
  88. package/dist/runtime/application/scene/StarterScene.js +56 -0
  89. package/dist/runtime/application/scene/WorldArchive.js +87 -0
  90. package/dist/runtime/application/scene/WorldDirectory.js +20 -0
  91. package/dist/runtime/application/scene/WorldDocument.js +74 -0
  92. package/dist/runtime/application/scene/WorldIO.js +103 -0
  93. package/dist/runtime/application/scene/WorldStorage.js +137 -0
  94. package/dist/runtime/application/skills/SkillRegistry.js +189 -0
  95. package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
  96. package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
  97. package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
  98. package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
  99. package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
  100. package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
  101. package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
  102. package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
  103. package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
  104. package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
  105. package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
  106. package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
  107. package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
  108. package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
  109. package/dist/runtime/application/skills/skillPrimitives.js +4 -0
  110. package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
  111. package/dist/runtime/application/tasks.jsonl +67 -0
  112. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
  113. package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
  114. package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
  115. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
  116. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
  117. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
  118. package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
  119. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
  120. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
  121. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
  122. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +174 -0
  123. package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
  124. package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
  125. package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -0
  126. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
  127. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
  128. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
  129. package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
  130. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
  131. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
  132. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
  133. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
  134. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
  135. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +132 -0
  136. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
  137. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
  138. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
  139. package/dist/runtime/apps/mcp-server/README.md +150 -0
  140. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
  141. package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
  142. package/dist/runtime/apps/mcp-server/SessionManager.js +80 -0
  143. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
  144. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -0
  145. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
  146. package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
  147. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
  148. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
  149. package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
  150. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
  151. package/dist/runtime/apps/mcp-server/main.mjs +65 -0
  152. package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
  153. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
  154. package/dist/runtime/apps/mcp-server/security.js +21 -0
  155. package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
  156. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
  157. package/dist/runtime/apps/server/README.md +7 -0
  158. package/dist/runtime/apps/server/WorldDiskStorage.js +51 -0
  159. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
  160. package/dist/runtime/apps/server/tasks.jsonl +10 -0
  161. package/dist/runtime/foundation/EventBus.js +18 -0
  162. package/dist/runtime/foundation/JsonGateway.js +47 -0
  163. package/dist/runtime/foundation/PolicyEngine.js +21 -0
  164. package/dist/runtime/foundation/README.md +7 -0
  165. package/dist/runtime/foundation/TraceRecorder.js +76 -0
  166. package/dist/runtime/foundation/errors.js +8 -0
  167. package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
  168. package/dist/runtime/foundation/version.js +2 -0
  169. package/dist/runtime/modules/agent/README.md +11 -0
  170. package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
  171. package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
  172. package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
  173. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
  174. package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
  175. package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
  176. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
  177. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
  178. package/dist/runtime/modules/agent/prompt/index.js +52 -0
  179. package/dist/runtime/modules/agent/tasks.jsonl +94 -0
  180. package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
  181. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
  182. package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
  183. package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
  184. package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
  185. package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
  186. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
  187. package/dist/runtime/modules/artifact/README.md +7 -0
  188. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
  189. package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
  190. package/dist/runtime/modules/asset/AssetModule.js +399 -0
  191. package/dist/runtime/modules/asset/README.md +54 -0
  192. package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
  193. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
  194. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
  195. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
  196. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
  197. package/dist/runtime/modules/asset/model/AssetInputContracts.js +100 -0
  198. package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
  199. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
  200. package/dist/runtime/modules/asset/model/admission.js +117 -0
  201. package/dist/runtime/modules/asset/model/errors.js +6 -0
  202. package/dist/runtime/modules/asset/model/parts.js +27 -0
  203. package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
  204. package/dist/runtime/modules/asset/model/schema.js +150 -0
  205. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
  206. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
  207. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
  208. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
  209. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
  210. package/dist/runtime/modules/asset/production/AssetRecipe.js +47 -0
  211. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
  212. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
  213. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
  214. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
  215. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
  216. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
  217. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
  218. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
  219. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
  220. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
  221. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
  222. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
  223. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
  224. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
  225. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
  226. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
  227. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
  228. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
  229. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
  230. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
  231. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
  232. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
  233. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
  234. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
  235. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
  236. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
  237. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
  238. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
  239. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
  240. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
  241. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
  242. package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
  243. package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
  244. package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
  245. package/dist/runtime/modules/asset/tasks.jsonl +87 -0
  246. package/dist/runtime/modules/generation/README.md +9 -0
  247. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
  248. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
  249. package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
  250. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
  251. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
  252. package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
  253. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
  254. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
  255. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
  256. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
  257. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
  258. package/dist/runtime/modules/generation/tasks.jsonl +35 -0
  259. package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
  260. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +245 -0
  261. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
  262. package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
  263. package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
  264. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -0
  265. package/dist/runtime/modules/rendering/README.md +7 -0
  266. package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
  267. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
  268. package/dist/runtime/modules/rendering/createRenderer.js +76 -0
  269. package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
  270. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
  271. package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
  272. package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
  273. package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
  274. package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
  275. package/dist/runtime/modules/world/README.md +13 -0
  276. package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
  277. package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
  278. package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
  279. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
  280. package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
  281. package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
  282. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
  283. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
  284. package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
  285. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
  286. package/dist/runtime/modules/world/content/blankWorld.js +35 -0
  287. package/dist/runtime/modules/world/content/environments.js +84 -0
  288. package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
  289. package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
  290. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
  291. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
  292. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
  293. package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
  294. package/dist/runtime/modules/world/content/magicCabin.js +190 -0
  295. package/dist/runtime/modules/world/content/monumentHall.js +154 -0
  296. package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
  297. package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
  298. package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
  299. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
  300. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
  301. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
  302. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
  303. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
  304. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
  305. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
  306. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
  307. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
  308. package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
  309. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
  310. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
  311. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
  312. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
  313. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
  314. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
  315. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
  316. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
  317. package/dist/runtime/modules/world/errors.js +9 -0
  318. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
  319. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
  320. package/dist/runtime/modules/world/runtime/CommandHistory.js +80 -0
  321. package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -0
  322. package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
  323. package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
  324. package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
  325. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +207 -0
  326. package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -0
  327. package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
  328. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
  329. package/dist/runtime/modules/world/runtime/WorldCommands.js +502 -0
  330. package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
  331. package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
  332. package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
  333. package/dist/runtime/modules/world/runtime/WorldRuntime.js +665 -0
  334. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -0
  335. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
  336. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
  337. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
  338. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
  339. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
  340. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +305 -0
  341. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
  342. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
  343. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +222 -0
  344. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
  345. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
  346. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
  347. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
  348. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
  349. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
  350. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
  351. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
  352. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
  353. package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
  354. package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
  355. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
  356. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
  357. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
  358. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
  359. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
  360. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -0
  361. package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
  362. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
  363. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
  364. package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
  365. package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
  366. package/dist/runtime/modules/world/tasks.jsonl +530 -0
  367. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
  368. package/dist/runtime/modules/world/verification/Finding.js +105 -0
  369. package/dist/runtime/modules/world/verification/InteractionEvidence.js +69 -0
  370. package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
  371. package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
  372. package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
  373. package/dist/runtime/package-lock.json +16048 -0
  374. package/dist/runtime/package.json +105 -0
  375. package/dist/runtime/public/assets/cabinet.glb +0 -0
  376. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  377. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  378. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  379. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  380. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  381. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  382. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  383. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  384. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  385. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  386. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  387. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  388. package/dist/schema-BWpTl0Wj.js +359 -0
  389. package/dist/schema-BWpTl0Wj.js.map +1 -0
  390. package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
  391. package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
  392. package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
  393. package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
  394. package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
  395. package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
  396. package/package.json +70 -4
@@ -0,0 +1,280 @@
1
+ const HASH_RE=/^sha256:[0-9a-f]{64}$/;
2
+ const SAFE_ID=/^[A-Za-z0-9_-]{1,160}$/;
3
+ const SAFE_SLUG=/^[a-z0-9][a-z0-9._-]{0,95}$/i;
4
+ const SAFE_SCHEMA_ID=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
5
+ const MIME_RE=/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i;
6
+ const CONTROL_RE=/[\u0000-\u001f\u007f]/;
7
+ const UNSAFE_TEXT_RE=/https?:\/\/|Bearer\s+|(?:^|\s)(?:[A-Za-z]:\\|\/)[^\s]+/i;
8
+ const FORBIDDEN_KEY=/(authorization|api[-_]?key|access[-_]?token|refresh[-_]?token|secret|credential|signed[-_]?url|volume[-_]?path|file[-_]?path|(^|[_-])path($|[_-])|(^|[_-])url($|[_-])|traceback|stack|prompt|image[-_]?bytes|base64|remote[-_]?.*id|function[-_]?call[-_]?id)/i;
9
+
10
+ export const ARTIFACT_INTEGRITY_STATES=Object.freeze(['declared','verified','rejected']);
11
+ export const ARTIFACT_LOCATION_KINDS=Object.freeze(['connector','local-cache','compiled-store','legacy']);
12
+ export const ARTIFACT_LOCATION_SCOPES=Object.freeze(['session','job','project','application']);
13
+ export const ARTIFACT_LOCATION_STATES=Object.freeze(['available','unavailable','expired','evicted']);
14
+ export const ARTIFACT_RETENTION_CLASSES=Object.freeze(['ephemeral','session','project','favorite','persistent']);
15
+ export const ARTIFACT_LINEAGE_RELATIONS=Object.freeze(['derived_from','input','preview_of','compiled_from']);
16
+ export const ARTIFACT_LEASE_HOLDER_KINDS=Object.freeze(['job','project','viewer','transfer','favorite','application']);
17
+
18
+ const LOCATION_KIND_SET=new Set(ARTIFACT_LOCATION_KINDS);
19
+ const LOCATION_SCOPE_SET=new Set(ARTIFACT_LOCATION_SCOPES);
20
+ const LOCATION_STATE_SET=new Set(ARTIFACT_LOCATION_STATES);
21
+ const RETENTION_SET=new Set(ARTIFACT_RETENTION_CLASSES);
22
+ const LINEAGE_RELATION_SET=new Set(ARTIFACT_LINEAGE_RELATIONS);
23
+
24
+ const clone=(value)=>value == null ? value : structuredClone(value);
25
+
26
+ export class ArtifactContractError extends Error {
27
+ constructor(code,message,details={}) {
28
+ super(message);
29
+ this.name='ArtifactContractError';
30
+ this.code=code;
31
+ this.details=clone(details);
32
+ }
33
+ }
34
+
35
+ const requiredText=(value,field,max=200)=>{
36
+ const text=String(value ?? '').trim();
37
+ if (!text) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID',`Artifact descriptor requires ${field}`,{field});
38
+ if (text.length>max || CONTROL_RE.test(text)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID',`Artifact descriptor has invalid ${field}`,{field});
39
+ return text;
40
+ };
41
+ const optionalText=(value,field,max=200)=>value==null||value===''?null:requiredText(value,field,max);
42
+
43
+ const safeUiText=(value,field,max=200)=>{
44
+ const text=requiredText(value,field,max);
45
+ if (UNSAFE_TEXT_RE.test(text)) throw new ArtifactContractError('ARTIFACT_FORBIDDEN_VALUE',`Artifact ${field} contains unsafe transport/path text`,{field});
46
+ return text;
47
+ };
48
+ const optionalSafeUiText=(value,field,max=200)=>value==null||value===''?null:safeUiText(value,field,max);
49
+
50
+ export function requireSafeArtifactId(value,field='id') {
51
+ const raw=String(value ?? '');
52
+ const id=raw.trim();
53
+ if (!id || raw!==id || id.length>160 || CONTROL_RE.test(id) || !SAFE_ID.test(id)) {
54
+ throw new ArtifactContractError('ARTIFACT_ID_INVALID','Artifact ID must be an opaque URL-safe identifier',{field});
55
+ }
56
+ return id;
57
+ }
58
+
59
+ export function normalizeArtifactHash(value,field='hash') {
60
+ const hash=requiredText(value,field,80);
61
+ if (!HASH_RE.test(hash)) throw new ArtifactContractError('ARTIFACT_HASH_INVALID','Artifact hash must be canonical sha256:<64 lowercase hex>',{field});
62
+ return hash;
63
+ }
64
+
65
+ function assertNoForbiddenFields(value,path='artifact') {
66
+ if (!value || typeof value!=='object') return;
67
+ if (Array.isArray(value)) {
68
+ value.forEach((item,index)=>assertNoForbiddenFields(item,`${path}[${index}]`));
69
+ return;
70
+ }
71
+ for (const [key,item] of Object.entries(value)) {
72
+ if (FORBIDDEN_KEY.test(key)) {
73
+ throw new ArtifactContractError('ARTIFACT_FORBIDDEN_FIELD','Artifact descriptor contains a forbidden trust-boundary field',{path:`${path}.${key}`});
74
+ }
75
+ assertNoForbiddenFields(item,`${path}.${key}`);
76
+ }
77
+ }
78
+
79
+ function normalizeTime(value,field,{required=false}={}) {
80
+ if (value==null||value==='') {
81
+ if (required) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID',`Artifact descriptor requires ${field}`,{field});
82
+ return null;
83
+ }
84
+ const time=Date.parse(String(value));
85
+ if (!Number.isFinite(time)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID',`Artifact descriptor has invalid ${field}`,{field});
86
+ return new Date(time).toISOString();
87
+ }
88
+
89
+ function normalizeVersionedRef(value,field) {
90
+ if (value==null) return null;
91
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID',`Artifact ${field} must be a versioned reference`);
92
+ return {
93
+ id:optionalText(value.id,`${field}.id`,120),
94
+ version:optionalText(value.version,`${field}.version`,80),
95
+ revision:optionalText(value.revision,`${field}.revision`,120)
96
+ };
97
+ }
98
+
99
+ function normalizeProducer(value={}) {
100
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact producer must be an object');
101
+ const provider=requiredText(value.provider,'producer.provider',120);
102
+ const operation=requiredText(value.operation,'producer.operation',180);
103
+ if (!operation.startsWith(`${provider}.`) || !/\.v\d+$/.test(operation)) {
104
+ throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact producer operation must be a stable provider-scoped operation ID',{provider,operation});
105
+ }
106
+ const attempt=Number(value.attempt ?? 1);
107
+ if (!Number.isSafeInteger(attempt)||attempt<1) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact producer attempt must be a positive integer');
108
+ const stage=optionalText(value.stage,'producer.stage',100);
109
+ if (stage && !SAFE_SLUG.test(stage)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact producer stage must be a stable slug');
110
+ return {
111
+ jobId:requireSafeArtifactId(value.jobId,'producer.jobId'),
112
+ provider,
113
+ operation,
114
+ stage,
115
+ attempt,
116
+ revision:optionalText(value.revision,'producer.revision',120),
117
+ model:normalizeVersionedRef(value.model,'producer.model'),
118
+ workflow:normalizeVersionedRef(value.workflow,'producer.workflow')
119
+ };
120
+ }
121
+
122
+ function normalizeLineage(value={},selfId) {
123
+ if (value==null) return {parents:[]};
124
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact lineage must be an object');
125
+ const parents=Array.isArray(value.parents)?value.parents:[];
126
+ const seen=new Set();
127
+ const normalized=parents.map((parent)=>{
128
+ if (!parent || typeof parent!=='object' || Array.isArray(parent)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact lineage parent must be an object');
129
+ const artifactId=requireSafeArtifactId(parent.artifactId,'lineage.parents[].artifactId');
130
+ if (artifactId===selfId) throw new ArtifactContractError('ARTIFACT_LINEAGE_INVALID','Artifact cannot derive from itself',{artifactId});
131
+ const relation=requiredText(parent.relation,'lineage.parents[].relation',64);
132
+ if (!LINEAGE_RELATION_SET.has(relation)) throw new ArtifactContractError('ARTIFACT_LINEAGE_INVALID',`Unsupported artifact lineage relation: ${relation}`);
133
+ const key=`${artifactId}:${relation}`;
134
+ if (seen.has(key)) throw new ArtifactContractError('ARTIFACT_LINEAGE_INVALID','Duplicate artifact lineage edge',{artifactId,relation});
135
+ seen.add(key);
136
+ return {artifactId,hash:normalizeArtifactHash(parent.hash,'lineage.parents[].hash'),relation};
137
+ });
138
+ return {parents:normalized};
139
+ }
140
+
141
+ function normalizeAccess(value,locationKind,artifactId) {
142
+ if (value==null) return null;
143
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Artifact location access must be an object');
144
+ const kind=requiredText(value.kind,'locations[].access.kind',80);
145
+ if (locationKind==='connector') {
146
+ if (kind!=='connector-artifact') throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Connector location must use connector-artifact access');
147
+ const accessArtifactId=requireSafeArtifactId(value.artifactId,'locations[].access.artifactId');
148
+ if (accessArtifactId!==artifactId) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Connector access artifactId must match descriptor identity');
149
+ if (!value.connector || typeof value.connector!=='object' || Array.isArray(value.connector)) {
150
+ throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Connector artifact access requires connector identity');
151
+ }
152
+ return {
153
+ kind,
154
+ artifactId:accessArtifactId,
155
+ connector:{
156
+ id:requireSafeArtifactId(value.connector.id,'locations[].access.connector.id'),
157
+ instance:requireSafeArtifactId(value.connector.instance,'locations[].access.connector.instance')
158
+ }
159
+ };
160
+ }
161
+ if (locationKind==='local-cache') {
162
+ if (kind!=='cache-key') throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Local cache location must use cache-key access');
163
+ return {kind,key:requireSafeArtifactId(value.key,'locations[].access.key')};
164
+ }
165
+ if (locationKind==='compiled-store') {
166
+ if (kind!=='compiled-key') throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Compiled location must use compiled-key access');
167
+ return {kind,key:requireSafeArtifactId(value.key,'locations[].access.key')};
168
+ }
169
+ if (value) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Legacy location access is intentionally opaque and unavailable to browser code');
170
+ return null;
171
+ }
172
+
173
+ export function normalizeArtifactLocation(value={},artifactId) {
174
+ assertNoForbiddenFields(value,'location');
175
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Artifact location must be an object');
176
+ const kind=requiredText(value.kind,'locations[].kind',64);
177
+ const scope=requiredText(value.scope,'locations[].scope',64);
178
+ const state=requiredText(value.state,'locations[].state',64);
179
+ if (!LOCATION_KIND_SET.has(kind)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID',`Unsupported artifact location kind: ${kind}`);
180
+ if (!LOCATION_SCOPE_SET.has(scope)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID',`Unsupported artifact location scope: ${scope}`);
181
+ if (!LOCATION_STATE_SET.has(state)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID',`Unsupported artifact location state: ${state}`);
182
+ const verifiedAt=normalizeTime(value.verifiedAt,'locations[].verifiedAt');
183
+ const expiresAt=normalizeTime(value.expiresAt,'locations[].expiresAt');
184
+ if (verifiedAt && expiresAt && Date.parse(expiresAt)<Date.parse(verifiedAt)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Artifact location expires before it was verified');
185
+ const access=normalizeAccess(value.access,kind,artifactId);
186
+ if (state==='available' && kind!=='legacy' && !access) {
187
+ throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Available artifact location requires a safe access handle',{kind});
188
+ }
189
+ return {
190
+ id:requireSafeArtifactId(value.id,'locations[].id'),
191
+ kind,
192
+ scope,
193
+ state,
194
+ verifiedAt,
195
+ expiresAt,
196
+ access
197
+ };
198
+ }
199
+
200
+ function normalizeRetention(value={}) {
201
+ if (value==null) value={};
202
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact retention must be an object');
203
+ const retentionClass=String(value.class || 'ephemeral');
204
+ if (!RETENTION_SET.has(retentionClass)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID',`Unsupported artifact retention class: ${retentionClass}`);
205
+ return {
206
+ class:retentionClass,
207
+ expiresAt:normalizeTime(value.expiresAt,'retention.expiresAt')
208
+ };
209
+ }
210
+
211
+ function normalizeWarnings(value=[]) {
212
+ if (!Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact warnings must be an array');
213
+ return [...new Set(value.map((warning,index)=>safeUiText(warning,`warnings[${index}]`,240)))];
214
+ }
215
+
216
+ function normalizeSchema(value={}) {
217
+ if (!value || typeof value!=='object' || Array.isArray(value)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact schema must be an object');
218
+ const id=requiredText(value.id,'schema.id',128);
219
+ if (!SAFE_SCHEMA_ID.test(id)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact schema id is invalid');
220
+ return {id,version:requiredText(value.version,'schema.version',64)};
221
+ }
222
+
223
+ export function normalizeArtifactDescriptor(payload={}) {
224
+ if (!payload || typeof payload!=='object' || Array.isArray(payload)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact descriptor must be an object');
225
+ assertNoForbiddenFields(payload);
226
+ const id=requireSafeArtifactId(payload.id);
227
+ const role=requiredText(payload.role,'role',96);
228
+ const type=requiredText(payload.type,'type',96);
229
+ const format=requiredText(payload.format,'format',64);
230
+ if (!SAFE_SLUG.test(role)||!SAFE_SLUG.test(type)||!SAFE_SLUG.test(format)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact role/type/format must use stable slugs');
231
+ const mime=requiredText(payload.mime,'mime',120).toLowerCase();
232
+ if (!MIME_RE.test(mime)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact MIME is invalid');
233
+ const bytes=Number(payload.bytes);
234
+ if (!Number.isSafeInteger(bytes)||bytes<0) throw new ArtifactContractError('ARTIFACT_BYTES_INVALID','Artifact bytes must be a non-negative safe integer');
235
+ const createdAt=normalizeTime(payload.createdAt,'createdAt',{required:true});
236
+ const expiresAt=normalizeTime(payload.expiresAt,'expiresAt');
237
+ if (expiresAt && Date.parse(expiresAt)<Date.parse(createdAt)) throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact expires before it was created');
238
+ if (payload.integrity?.state && payload.integrity.state!=='declared') {
239
+ throw new ArtifactContractError('ARTIFACT_INTEGRITY_EVIDENCE_REQUIRED','Untrusted descriptor cannot self-promote integrity beyond declared');
240
+ }
241
+ const locations=Array.isArray(payload.locations)?payload.locations.map((location)=>normalizeArtifactLocation(location,id)):[];
242
+ const locationIds=new Set();
243
+ for (const location of locations) {
244
+ if (locationIds.has(location.id)) throw new ArtifactContractError('ARTIFACT_LOCATION_INVALID','Duplicate artifact location ID',{locationId:location.id});
245
+ locationIds.add(location.id);
246
+ }
247
+ return {
248
+ id,
249
+ role,
250
+ type,
251
+ schema:normalizeSchema(payload.schema),
252
+ displayName:optionalSafeUiText(payload.displayName,'displayName',160),
253
+ mime,
254
+ format,
255
+ bytes,
256
+ hash:normalizeArtifactHash(payload.hash),
257
+ producer:normalizeProducer(payload.producer),
258
+ lineage:normalizeLineage(payload.lineage,id),
259
+ createdAt,
260
+ expiresAt,
261
+ integrity:{state:'declared',verifiedAt:null,method:null,rejection:null},
262
+ warnings:normalizeWarnings(payload.warnings || []),
263
+ retention:(()=>{
264
+ const retention=normalizeRetention(payload.retention);
265
+ if (retention.expiresAt && Date.parse(retention.expiresAt)<Date.parse(createdAt)) {
266
+ throw new ArtifactContractError('ARTIFACT_DESCRIPTOR_INVALID','Artifact retention expires before artifact creation');
267
+ }
268
+ return retention;
269
+ })(),
270
+ locations
271
+ };
272
+ }
273
+
274
+ export function artifactImmutableSignature(descriptor) {
275
+ return JSON.stringify({
276
+ id:descriptor.id,role:descriptor.role,type:descriptor.type,schema:descriptor.schema,
277
+ mime:descriptor.mime,format:descriptor.format,bytes:descriptor.bytes,hash:descriptor.hash,
278
+ producer:descriptor.producer,lineage:descriptor.lineage,createdAt:descriptor.createdAt
279
+ });
280
+ }
@@ -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
+ }