@aigne/aos 0.2.0-beta

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 (533) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE.md +26 -0
  3. package/dist/agent-dsl.cjs +116 -0
  4. package/dist/agent-dsl.d.cts +31 -0
  5. package/dist/agent-dsl.d.cts.map +1 -0
  6. package/dist/agent-dsl.d.mts +31 -0
  7. package/dist/agent-dsl.d.mts.map +1 -0
  8. package/dist/agent-dsl.mjs +115 -0
  9. package/dist/agent-dsl.mjs.map +1 -0
  10. package/dist/arc-compat.cjs +125 -0
  11. package/dist/arc-compat.d.cts +17 -0
  12. package/dist/arc-compat.d.cts.map +1 -0
  13. package/dist/arc-compat.d.mts +17 -0
  14. package/dist/arc-compat.d.mts.map +1 -0
  15. package/dist/arc-compat.mjs +123 -0
  16. package/dist/arc-compat.mjs.map +1 -0
  17. package/dist/auto-surface/compiler.cjs +36 -0
  18. package/dist/auto-surface/compiler.d.cts +7 -0
  19. package/dist/auto-surface/compiler.d.cts.map +1 -0
  20. package/dist/auto-surface/compiler.d.mts +7 -0
  21. package/dist/auto-surface/compiler.d.mts.map +1 -0
  22. package/dist/auto-surface/compiler.mjs +37 -0
  23. package/dist/auto-surface/compiler.mjs.map +1 -0
  24. package/dist/auto-surface/definition-dsl.cjs +333 -0
  25. package/dist/auto-surface/definition-dsl.d.cts +41 -0
  26. package/dist/auto-surface/definition-dsl.d.cts.map +1 -0
  27. package/dist/auto-surface/definition-dsl.d.mts +41 -0
  28. package/dist/auto-surface/definition-dsl.d.mts.map +1 -0
  29. package/dist/auto-surface/definition-dsl.mjs +332 -0
  30. package/dist/auto-surface/definition-dsl.mjs.map +1 -0
  31. package/dist/auto-surface/fragments.cjs +177 -0
  32. package/dist/auto-surface/fragments.d.cts +23 -0
  33. package/dist/auto-surface/fragments.d.cts.map +1 -0
  34. package/dist/auto-surface/fragments.d.mts +23 -0
  35. package/dist/auto-surface/fragments.d.mts.map +1 -0
  36. package/dist/auto-surface/fragments.mjs +175 -0
  37. package/dist/auto-surface/fragments.mjs.map +1 -0
  38. package/dist/auto-surface/index.d.mts +9 -0
  39. package/dist/auto-surface/layering.cjs +43 -0
  40. package/dist/auto-surface/layering.d.cts +7 -0
  41. package/dist/auto-surface/layering.d.cts.map +1 -0
  42. package/dist/auto-surface/layering.d.mts +7 -0
  43. package/dist/auto-surface/layering.d.mts.map +1 -0
  44. package/dist/auto-surface/layering.mjs +43 -0
  45. package/dist/auto-surface/layering.mjs.map +1 -0
  46. package/dist/auto-surface/projection.cjs +11 -0
  47. package/dist/auto-surface/projection.d.cts +11 -0
  48. package/dist/auto-surface/projection.d.cts.map +1 -0
  49. package/dist/auto-surface/projection.d.mts +11 -0
  50. package/dist/auto-surface/projection.d.mts.map +1 -0
  51. package/dist/auto-surface/projection.mjs +12 -0
  52. package/dist/auto-surface/projection.mjs.map +1 -0
  53. package/dist/auto-surface/projectors/settings-shell.cjs +114 -0
  54. package/dist/auto-surface/projectors/settings-shell.d.cts +10 -0
  55. package/dist/auto-surface/projectors/settings-shell.d.cts.map +1 -0
  56. package/dist/auto-surface/projectors/settings-shell.d.mts +10 -0
  57. package/dist/auto-surface/projectors/settings-shell.d.mts.map +1 -0
  58. package/dist/auto-surface/projectors/settings-shell.mjs +114 -0
  59. package/dist/auto-surface/projectors/settings-shell.mjs.map +1 -0
  60. package/dist/auto-surface/scenario.cjs +38 -0
  61. package/dist/auto-surface/scenario.d.cts +31 -0
  62. package/dist/auto-surface/scenario.d.cts.map +1 -0
  63. package/dist/auto-surface/scenario.d.mts +31 -0
  64. package/dist/auto-surface/scenario.d.mts.map +1 -0
  65. package/dist/auto-surface/scenario.mjs +37 -0
  66. package/dist/auto-surface/scenario.mjs.map +1 -0
  67. package/dist/auto-surface/types.cjs +9 -0
  68. package/dist/auto-surface/types.d.cts +153 -0
  69. package/dist/auto-surface/types.d.cts.map +1 -0
  70. package/dist/auto-surface/types.d.mts +153 -0
  71. package/dist/auto-surface/types.d.mts.map +1 -0
  72. package/dist/auto-surface/types.mjs +9 -0
  73. package/dist/auto-surface/types.mjs.map +1 -0
  74. package/dist/auto-surface/value-dsl.cjs +80 -0
  75. package/dist/auto-surface/value-dsl.d.cts +24 -0
  76. package/dist/auto-surface/value-dsl.d.cts.map +1 -0
  77. package/dist/auto-surface/value-dsl.d.mts +24 -0
  78. package/dist/auto-surface/value-dsl.d.mts.map +1 -0
  79. package/dist/auto-surface/value-dsl.mjs +79 -0
  80. package/dist/auto-surface/value-dsl.mjs.map +1 -0
  81. package/dist/blocklet/activation.cjs +94 -0
  82. package/dist/blocklet/activation.d.cts +30 -0
  83. package/dist/blocklet/activation.d.cts.map +1 -0
  84. package/dist/blocklet/activation.d.mts +30 -0
  85. package/dist/blocklet/activation.d.mts.map +1 -0
  86. package/dist/blocklet/activation.mjs +94 -0
  87. package/dist/blocklet/activation.mjs.map +1 -0
  88. package/dist/blocklet/did-space-registry.cjs +282 -0
  89. package/dist/blocklet/did-space-registry.d.cts +82 -0
  90. package/dist/blocklet/did-space-registry.d.cts.map +1 -0
  91. package/dist/blocklet/did-space-registry.d.mts +82 -0
  92. package/dist/blocklet/did-space-registry.d.mts.map +1 -0
  93. package/dist/blocklet/did-space-registry.mjs +281 -0
  94. package/dist/blocklet/did-space-registry.mjs.map +1 -0
  95. package/dist/blocklet/handlers.cjs +66 -0
  96. package/dist/blocklet/handlers.d.cts +16 -0
  97. package/dist/blocklet/handlers.d.cts.map +1 -0
  98. package/dist/blocklet/handlers.d.mts +16 -0
  99. package/dist/blocklet/handlers.d.mts.map +1 -0
  100. package/dist/blocklet/handlers.mjs +65 -0
  101. package/dist/blocklet/handlers.mjs.map +1 -0
  102. package/dist/blocklet/index.d.mts +7 -0
  103. package/dist/blocklet/manifest.d.cts +2 -0
  104. package/dist/blocklet/manifest.d.mts +2 -0
  105. package/dist/blocklet/manifest.mjs +3 -0
  106. package/dist/blocklet/registry.cjs +447 -0
  107. package/dist/blocklet/registry.d.cts +197 -0
  108. package/dist/blocklet/registry.d.cts.map +1 -0
  109. package/dist/blocklet/registry.d.mts +197 -0
  110. package/dist/blocklet/registry.d.mts.map +1 -0
  111. package/dist/blocklet/registry.mjs +441 -0
  112. package/dist/blocklet/registry.mjs.map +1 -0
  113. package/dist/blocklet/static-render.cjs +183 -0
  114. package/dist/blocklet/static-render.d.cts +55 -0
  115. package/dist/blocklet/static-render.d.cts.map +1 -0
  116. package/dist/blocklet/static-render.d.mts +55 -0
  117. package/dist/blocklet/static-render.d.mts.map +1 -0
  118. package/dist/blocklet/static-render.mjs +181 -0
  119. package/dist/blocklet/static-render.mjs.map +1 -0
  120. package/dist/blocklet/types.d.cts +70 -0
  121. package/dist/blocklet/types.d.cts.map +1 -0
  122. package/dist/blocklet/types.d.mts +70 -0
  123. package/dist/blocklet/types.d.mts.map +1 -0
  124. package/dist/devices/chain.cjs +127 -0
  125. package/dist/devices/chain.d.cts +48 -0
  126. package/dist/devices/chain.d.cts.map +1 -0
  127. package/dist/devices/chain.d.mts +48 -0
  128. package/dist/devices/chain.d.mts.map +1 -0
  129. package/dist/devices/chain.mjs +125 -0
  130. package/dist/devices/chain.mjs.map +1 -0
  131. package/dist/dsl-shared.cjs +290 -0
  132. package/dist/dsl-shared.d.cts +54 -0
  133. package/dist/dsl-shared.d.cts.map +1 -0
  134. package/dist/dsl-shared.d.mts +54 -0
  135. package/dist/dsl-shared.d.mts.map +1 -0
  136. package/dist/dsl-shared.mjs +287 -0
  137. package/dist/dsl-shared.mjs.map +1 -0
  138. package/dist/http/afs-mcp.cjs +85 -0
  139. package/dist/http/afs-mcp.d.cts +14 -0
  140. package/dist/http/afs-mcp.d.cts.map +1 -0
  141. package/dist/http/afs-mcp.d.mts +14 -0
  142. package/dist/http/afs-mcp.d.mts.map +1 -0
  143. package/dist/http/afs-mcp.mjs +86 -0
  144. package/dist/http/afs-mcp.mjs.map +1 -0
  145. package/dist/http/afs-raw.cjs +264 -0
  146. package/dist/http/afs-raw.d.cts +31 -0
  147. package/dist/http/afs-raw.d.cts.map +1 -0
  148. package/dist/http/afs-raw.d.mts +31 -0
  149. package/dist/http/afs-raw.d.mts.map +1 -0
  150. package/dist/http/afs-raw.mjs +264 -0
  151. package/dist/http/afs-raw.mjs.map +1 -0
  152. package/dist/http/afs-rest.cjs +30 -0
  153. package/dist/http/afs-rest.d.cts +21 -0
  154. package/dist/http/afs-rest.d.cts.map +1 -0
  155. package/dist/http/afs-rest.d.mts +21 -0
  156. package/dist/http/afs-rest.d.mts.map +1 -0
  157. package/dist/http/afs-rest.mjs +31 -0
  158. package/dist/http/afs-rest.mjs.map +1 -0
  159. package/dist/http/afs-rpc-wire.cjs +271 -0
  160. package/dist/http/afs-rpc-wire.d.cts +195 -0
  161. package/dist/http/afs-rpc-wire.d.cts.map +1 -0
  162. package/dist/http/afs-rpc-wire.d.mts +195 -0
  163. package/dist/http/afs-rpc-wire.d.mts.map +1 -0
  164. package/dist/http/afs-rpc-wire.mjs +262 -0
  165. package/dist/http/afs-rpc-wire.mjs.map +1 -0
  166. package/dist/http/afs-rpc.cjs +729 -0
  167. package/dist/http/afs-rpc.d.cts +103 -0
  168. package/dist/http/afs-rpc.d.cts.map +1 -0
  169. package/dist/http/afs-rpc.d.mts +103 -0
  170. package/dist/http/afs-rpc.d.mts.map +1 -0
  171. package/dist/http/afs-rpc.mjs +729 -0
  172. package/dist/http/afs-rpc.mjs.map +1 -0
  173. package/dist/http/afs-upload.cjs +116 -0
  174. package/dist/http/afs-upload.d.cts +40 -0
  175. package/dist/http/afs-upload.d.cts.map +1 -0
  176. package/dist/http/afs-upload.d.mts +40 -0
  177. package/dist/http/afs-upload.d.mts.map +1 -0
  178. package/dist/http/afs-upload.mjs +116 -0
  179. package/dist/http/afs-upload.mjs.map +1 -0
  180. package/dist/http/aup-client.cjs +60 -0
  181. package/dist/http/aup-client.d.cts +22 -0
  182. package/dist/http/aup-client.d.cts.map +1 -0
  183. package/dist/http/aup-client.d.mts +22 -0
  184. package/dist/http/aup-client.d.mts.map +1 -0
  185. package/dist/http/aup-client.mjs +59 -0
  186. package/dist/http/aup-client.mjs.map +1 -0
  187. package/dist/http/aup-event.cjs +100 -0
  188. package/dist/http/aup-event.d.cts +38 -0
  189. package/dist/http/aup-event.d.cts.map +1 -0
  190. package/dist/http/aup-event.d.mts +38 -0
  191. package/dist/http/aup-event.d.mts.map +1 -0
  192. package/dist/http/aup-event.mjs +101 -0
  193. package/dist/http/aup-event.mjs.map +1 -0
  194. package/dist/http/auth-context.cjs +66 -0
  195. package/dist/http/auth-context.d.cts +64 -0
  196. package/dist/http/auth-context.d.cts.map +1 -0
  197. package/dist/http/auth-context.d.mts +64 -0
  198. package/dist/http/auth-context.d.mts.map +1 -0
  199. package/dist/http/auth-context.mjs +66 -0
  200. package/dist/http/auth-context.mjs.map +1 -0
  201. package/dist/http/csrf.cjs +50 -0
  202. package/dist/http/csrf.d.cts +8 -0
  203. package/dist/http/csrf.d.cts.map +1 -0
  204. package/dist/http/csrf.d.mts +8 -0
  205. package/dist/http/csrf.d.mts.map +1 -0
  206. package/dist/http/csrf.mjs +49 -0
  207. package/dist/http/csrf.mjs.map +1 -0
  208. package/dist/http/handlers.cjs +106 -0
  209. package/dist/http/handlers.d.cts +39 -0
  210. package/dist/http/handlers.d.cts.map +1 -0
  211. package/dist/http/handlers.d.mts +39 -0
  212. package/dist/http/handlers.d.mts.map +1 -0
  213. package/dist/http/handlers.mjs +104 -0
  214. package/dist/http/handlers.mjs.map +1 -0
  215. package/dist/http/index.d.mts +1 -0
  216. package/dist/http/ingest-facade.cjs +315 -0
  217. package/dist/http/ingest-facade.mjs +314 -0
  218. package/dist/http/ingest-facade.mjs.map +1 -0
  219. package/dist/http/raw-url.cjs +136 -0
  220. package/dist/http/raw-url.d.cts +54 -0
  221. package/dist/http/raw-url.d.cts.map +1 -0
  222. package/dist/http/raw-url.d.mts +54 -0
  223. package/dist/http/raw-url.d.mts.map +1 -0
  224. package/dist/http/raw-url.mjs +136 -0
  225. package/dist/http/raw-url.mjs.map +1 -0
  226. package/dist/http/request-context.cjs +178 -0
  227. package/dist/http/request-context.d.cts +76 -0
  228. package/dist/http/request-context.d.cts.map +1 -0
  229. package/dist/http/request-context.d.mts +76 -0
  230. package/dist/http/request-context.d.mts.map +1 -0
  231. package/dist/http/request-context.mjs +179 -0
  232. package/dist/http/request-context.mjs.map +1 -0
  233. package/dist/index.cjs +197 -0
  234. package/dist/index.d.cts +63 -0
  235. package/dist/index.d.mts +68 -0
  236. package/dist/index.mjs +61 -0
  237. package/dist/mcp/index.cjs +9 -0
  238. package/dist/mcp/index.d.cts +5 -0
  239. package/dist/mcp/index.d.mts +5 -0
  240. package/dist/mcp/index.mjs +6 -0
  241. package/dist/mcp/prompts.cjs +17 -0
  242. package/dist/mcp/prompts.d.cts +8 -0
  243. package/dist/mcp/prompts.d.cts.map +1 -0
  244. package/dist/mcp/prompts.d.mts +8 -0
  245. package/dist/mcp/prompts.d.mts.map +1 -0
  246. package/dist/mcp/prompts.mjs +17 -0
  247. package/dist/mcp/prompts.mjs.map +1 -0
  248. package/dist/mcp/resources.cjs +22 -0
  249. package/dist/mcp/resources.d.cts +8 -0
  250. package/dist/mcp/resources.d.cts.map +1 -0
  251. package/dist/mcp/resources.d.mts +8 -0
  252. package/dist/mcp/resources.d.mts.map +1 -0
  253. package/dist/mcp/resources.mjs +22 -0
  254. package/dist/mcp/resources.mjs.map +1 -0
  255. package/dist/mcp/server.cjs +51 -0
  256. package/dist/mcp/server.d.cts +20 -0
  257. package/dist/mcp/server.d.cts.map +1 -0
  258. package/dist/mcp/server.d.mts +20 -0
  259. package/dist/mcp/server.d.mts.map +1 -0
  260. package/dist/mcp/server.mjs +52 -0
  261. package/dist/mcp/server.mjs.map +1 -0
  262. package/dist/mcp/tools.cjs +218 -0
  263. package/dist/mcp/tools.d.cts +8 -0
  264. package/dist/mcp/tools.d.cts.map +1 -0
  265. package/dist/mcp/tools.d.mts +8 -0
  266. package/dist/mcp/tools.d.mts.map +1 -0
  267. package/dist/mcp/tools.mjs +219 -0
  268. package/dist/mcp/tools.mjs.map +1 -0
  269. package/dist/mcp/utils.cjs +75 -0
  270. package/dist/mcp/utils.mjs +69 -0
  271. package/dist/mcp/utils.mjs.map +1 -0
  272. package/dist/mount/index.cjs +4 -0
  273. package/dist/mount/index.d.cts +3 -0
  274. package/dist/mount/index.d.mts +3 -0
  275. package/dist/mount/index.mjs +3 -0
  276. package/dist/mount/materializer.cjs +167 -0
  277. package/dist/mount/materializer.d.cts +97 -0
  278. package/dist/mount/materializer.d.cts.map +1 -0
  279. package/dist/mount/materializer.d.mts +97 -0
  280. package/dist/mount/materializer.d.mts.map +1 -0
  281. package/dist/mount/materializer.mjs +167 -0
  282. package/dist/mount/materializer.mjs.map +1 -0
  283. package/dist/mount/types.d.cts +90 -0
  284. package/dist/mount/types.d.cts.map +1 -0
  285. package/dist/mount/types.d.mts +90 -0
  286. package/dist/mount/types.d.mts.map +1 -0
  287. package/dist/mount-config.cjs +61 -0
  288. package/dist/mount-config.d.cts +19 -0
  289. package/dist/mount-config.d.cts.map +1 -0
  290. package/dist/mount-config.d.mts +19 -0
  291. package/dist/mount-config.d.mts.map +1 -0
  292. package/dist/mount-config.mjs +61 -0
  293. package/dist/mount-config.mjs.map +1 -0
  294. package/dist/projectors/aup-projector.cjs +190 -0
  295. package/dist/projectors/aup-projector.d.cts +59 -0
  296. package/dist/projectors/aup-projector.d.cts.map +1 -0
  297. package/dist/projectors/aup-projector.d.mts +59 -0
  298. package/dist/projectors/aup-projector.d.mts.map +1 -0
  299. package/dist/projectors/aup-projector.mjs +188 -0
  300. package/dist/projectors/aup-projector.mjs.map +1 -0
  301. package/dist/projectors/index.cjs +6 -0
  302. package/dist/projectors/index.d.cts +2 -0
  303. package/dist/projectors/index.d.mts +2 -0
  304. package/dist/projectors/index.mjs +3 -0
  305. package/dist/scaffold/afs.cjs +195 -0
  306. package/dist/scaffold/afs.d.cts +16 -0
  307. package/dist/scaffold/afs.d.cts.map +1 -0
  308. package/dist/scaffold/afs.d.mts +16 -0
  309. package/dist/scaffold/afs.d.mts.map +1 -0
  310. package/dist/scaffold/afs.mjs +195 -0
  311. package/dist/scaffold/afs.mjs.map +1 -0
  312. package/dist/scaffold/composition.cjs +92 -0
  313. package/dist/scaffold/composition.d.cts +10 -0
  314. package/dist/scaffold/composition.d.cts.map +1 -0
  315. package/dist/scaffold/composition.d.mts +10 -0
  316. package/dist/scaffold/composition.d.mts.map +1 -0
  317. package/dist/scaffold/composition.mjs +92 -0
  318. package/dist/scaffold/composition.mjs.map +1 -0
  319. package/dist/scaffold/dsl-error.cjs +21 -0
  320. package/dist/scaffold/dsl-error.d.cts +11 -0
  321. package/dist/scaffold/dsl-error.d.cts.map +1 -0
  322. package/dist/scaffold/dsl-error.d.mts +11 -0
  323. package/dist/scaffold/dsl-error.d.mts.map +1 -0
  324. package/dist/scaffold/dsl-error.mjs +20 -0
  325. package/dist/scaffold/dsl-error.mjs.map +1 -0
  326. package/dist/scaffold/index.d.mts +12 -0
  327. package/dist/scaffold/manifest-dsl.cjs +188 -0
  328. package/dist/scaffold/manifest-dsl.d.cts +8 -0
  329. package/dist/scaffold/manifest-dsl.d.cts.map +1 -0
  330. package/dist/scaffold/manifest-dsl.d.mts +8 -0
  331. package/dist/scaffold/manifest-dsl.d.mts.map +1 -0
  332. package/dist/scaffold/manifest-dsl.mjs +188 -0
  333. package/dist/scaffold/manifest-dsl.mjs.map +1 -0
  334. package/dist/scaffold/module-dsl.cjs +284 -0
  335. package/dist/scaffold/module-dsl.d.cts +8 -0
  336. package/dist/scaffold/module-dsl.d.cts.map +1 -0
  337. package/dist/scaffold/module-dsl.d.mts +8 -0
  338. package/dist/scaffold/module-dsl.d.mts.map +1 -0
  339. package/dist/scaffold/module-dsl.mjs +284 -0
  340. package/dist/scaffold/module-dsl.mjs.map +1 -0
  341. package/dist/scaffold/resolver.cjs +156 -0
  342. package/dist/scaffold/resolver.d.cts +7 -0
  343. package/dist/scaffold/resolver.d.cts.map +1 -0
  344. package/dist/scaffold/resolver.d.mts +7 -0
  345. package/dist/scaffold/resolver.d.mts.map +1 -0
  346. package/dist/scaffold/resolver.mjs +156 -0
  347. package/dist/scaffold/resolver.mjs.map +1 -0
  348. package/dist/scaffold/runtime.cjs +24 -0
  349. package/dist/scaffold/runtime.d.cts +19 -0
  350. package/dist/scaffold/runtime.d.cts.map +1 -0
  351. package/dist/scaffold/runtime.d.mts +19 -0
  352. package/dist/scaffold/runtime.d.mts.map +1 -0
  353. package/dist/scaffold/runtime.mjs +25 -0
  354. package/dist/scaffold/runtime.mjs.map +1 -0
  355. package/dist/scaffold/shell-dsl.cjs +279 -0
  356. package/dist/scaffold/shell-dsl.d.cts +8 -0
  357. package/dist/scaffold/shell-dsl.d.cts.map +1 -0
  358. package/dist/scaffold/shell-dsl.d.mts +8 -0
  359. package/dist/scaffold/shell-dsl.d.mts.map +1 -0
  360. package/dist/scaffold/shell-dsl.mjs +279 -0
  361. package/dist/scaffold/shell-dsl.mjs.map +1 -0
  362. package/dist/scaffold/surface-dsl.cjs +182 -0
  363. package/dist/scaffold/surface-dsl.d.cts +8 -0
  364. package/dist/scaffold/surface-dsl.d.cts.map +1 -0
  365. package/dist/scaffold/surface-dsl.d.mts +8 -0
  366. package/dist/scaffold/surface-dsl.d.mts.map +1 -0
  367. package/dist/scaffold/surface-dsl.mjs +182 -0
  368. package/dist/scaffold/surface-dsl.mjs.map +1 -0
  369. package/dist/scaffold/surfaces.cjs +84 -0
  370. package/dist/scaffold/surfaces.d.cts +23 -0
  371. package/dist/scaffold/surfaces.d.cts.map +1 -0
  372. package/dist/scaffold/surfaces.d.mts +24 -0
  373. package/dist/scaffold/surfaces.d.mts.map +1 -0
  374. package/dist/scaffold/surfaces.mjs +84 -0
  375. package/dist/scaffold/surfaces.mjs.map +1 -0
  376. package/dist/scaffold/types.d.cts +264 -0
  377. package/dist/scaffold/types.d.cts.map +1 -0
  378. package/dist/scaffold/types.d.mts +265 -0
  379. package/dist/scaffold/types.d.mts.map +1 -0
  380. package/dist/scaffold/workspace-dsl.cjs +339 -0
  381. package/dist/scaffold/workspace-dsl.d.cts +49 -0
  382. package/dist/scaffold/workspace-dsl.d.cts.map +1 -0
  383. package/dist/scaffold/workspace-dsl.d.mts +49 -0
  384. package/dist/scaffold/workspace-dsl.d.mts.map +1 -0
  385. package/dist/scaffold/workspace-dsl.mjs +337 -0
  386. package/dist/scaffold/workspace-dsl.mjs.map +1 -0
  387. package/dist/scope/index.d.mts +3 -0
  388. package/dist/scope/read-blocklet-scope.cjs +29 -0
  389. package/dist/scope/read-blocklet-scope.d.cts +8 -0
  390. package/dist/scope/read-blocklet-scope.d.cts.map +1 -0
  391. package/dist/scope/read-blocklet-scope.d.mts +8 -0
  392. package/dist/scope/read-blocklet-scope.d.mts.map +1 -0
  393. package/dist/scope/read-blocklet-scope.mjs +30 -0
  394. package/dist/scope/read-blocklet-scope.mjs.map +1 -0
  395. package/dist/scope/resolve-scoped-afs.cjs +87 -0
  396. package/dist/scope/resolve-scoped-afs.d.cts +7 -0
  397. package/dist/scope/resolve-scoped-afs.d.cts.map +1 -0
  398. package/dist/scope/resolve-scoped-afs.d.mts +7 -0
  399. package/dist/scope/resolve-scoped-afs.d.mts.map +1 -0
  400. package/dist/scope/resolve-scoped-afs.mjs +88 -0
  401. package/dist/scope/resolve-scoped-afs.mjs.map +1 -0
  402. package/dist/scope/types.d.cts +25 -0
  403. package/dist/scope/types.d.cts.map +1 -0
  404. package/dist/scope/types.d.mts +25 -0
  405. package/dist/scope/types.d.mts.map +1 -0
  406. package/dist/session/backends.cjs +90 -0
  407. package/dist/session/backends.d.cts +35 -0
  408. package/dist/session/backends.d.cts.map +1 -0
  409. package/dist/session/backends.d.mts +35 -0
  410. package/dist/session/backends.d.mts.map +1 -0
  411. package/dist/session/backends.mjs +89 -0
  412. package/dist/session/backends.mjs.map +1 -0
  413. package/dist/session/replication-resolver.cjs +323 -0
  414. package/dist/session/replication-resolver.d.cts +71 -0
  415. package/dist/session/replication-resolver.d.cts.map +1 -0
  416. package/dist/session/replication-resolver.d.mts +71 -0
  417. package/dist/session/replication-resolver.d.mts.map +1 -0
  418. package/dist/session/replication-resolver.mjs +323 -0
  419. package/dist/session/replication-resolver.mjs.map +1 -0
  420. package/dist/session/role-level.cjs +36 -0
  421. package/dist/session/role-level.d.cts +24 -0
  422. package/dist/session/role-level.d.cts.map +1 -0
  423. package/dist/session/role-level.d.mts +24 -0
  424. package/dist/session/role-level.d.mts.map +1 -0
  425. package/dist/session/role-level.mjs +35 -0
  426. package/dist/session/role-level.mjs.map +1 -0
  427. package/dist/session/session-dir-providers.cjs +254 -0
  428. package/dist/session/session-dir-providers.d.cts +32 -0
  429. package/dist/session/session-dir-providers.d.cts.map +1 -0
  430. package/dist/session/session-dir-providers.d.mts +32 -0
  431. package/dist/session/session-dir-providers.d.mts.map +1 -0
  432. package/dist/session/session-dir-providers.mjs +252 -0
  433. package/dist/session/session-dir-providers.mjs.map +1 -0
  434. package/dist/session/session-id.cjs +20 -0
  435. package/dist/session/session-id.d.cts +15 -0
  436. package/dist/session/session-id.d.cts.map +1 -0
  437. package/dist/session/session-id.d.mts +15 -0
  438. package/dist/session/session-id.d.mts.map +1 -0
  439. package/dist/session/session-id.mjs +20 -0
  440. package/dist/session/session-id.mjs.map +1 -0
  441. package/dist/session/session-user-afs.cjs +899 -0
  442. package/dist/session/session-user-afs.d.cts +296 -0
  443. package/dist/session/session-user-afs.d.cts.map +1 -0
  444. package/dist/session/session-user-afs.d.mts +296 -0
  445. package/dist/session/session-user-afs.d.mts.map +1 -0
  446. package/dist/session/session-user-afs.mjs +896 -0
  447. package/dist/session/session-user-afs.mjs.map +1 -0
  448. package/dist/session/settings-cascade.cjs +69 -0
  449. package/dist/session/settings-cascade.d.cts +81 -0
  450. package/dist/session/settings-cascade.d.cts.map +1 -0
  451. package/dist/session/settings-cascade.d.mts +81 -0
  452. package/dist/session/settings-cascade.d.mts.map +1 -0
  453. package/dist/session/settings-cascade.mjs +69 -0
  454. package/dist/session/settings-cascade.mjs.map +1 -0
  455. package/dist/session/settings-resolver.cjs +770 -0
  456. package/dist/session/settings-resolver.d.cts +177 -0
  457. package/dist/session/settings-resolver.d.cts.map +1 -0
  458. package/dist/session/settings-resolver.d.mts +177 -0
  459. package/dist/session/settings-resolver.d.mts.map +1 -0
  460. package/dist/session/settings-resolver.mjs +771 -0
  461. package/dist/session/settings-resolver.mjs.map +1 -0
  462. package/dist/session/settings-schema-store.cjs +0 -0
  463. package/dist/session/settings-schema-store.d.cts +72 -0
  464. package/dist/session/settings-schema-store.d.cts.map +1 -0
  465. package/dist/session/settings-schema-store.d.mts +72 -0
  466. package/dist/session/settings-schema-store.d.mts.map +1 -0
  467. package/dist/session/settings-schema-store.mjs +0 -0
  468. package/dist/session/settings-schema-store.mjs.map +1 -0
  469. package/dist/system-mounts/index.cjs +14 -0
  470. package/dist/system-mounts/index.d.cts +6 -0
  471. package/dist/system-mounts/index.d.mts +6 -0
  472. package/dist/system-mounts/index.mjs +6 -0
  473. package/dist/system-mounts/install.cjs +101 -0
  474. package/dist/system-mounts/install.d.cts +36 -0
  475. package/dist/system-mounts/install.d.cts.map +1 -0
  476. package/dist/system-mounts/install.d.mts +37 -0
  477. package/dist/system-mounts/install.d.mts.map +1 -0
  478. package/dist/system-mounts/install.mjs +102 -0
  479. package/dist/system-mounts/install.mjs.map +1 -0
  480. package/dist/system-mounts/installers.cjs +247 -0
  481. package/dist/system-mounts/installers.d.cts +13 -0
  482. package/dist/system-mounts/installers.d.cts.map +1 -0
  483. package/dist/system-mounts/installers.d.mts +14 -0
  484. package/dist/system-mounts/installers.d.mts.map +1 -0
  485. package/dist/system-mounts/installers.mjs +244 -0
  486. package/dist/system-mounts/installers.mjs.map +1 -0
  487. package/dist/system-mounts/lists.cjs +122 -0
  488. package/dist/system-mounts/lists.d.cts +34 -0
  489. package/dist/system-mounts/lists.d.cts.map +1 -0
  490. package/dist/system-mounts/lists.d.mts +34 -0
  491. package/dist/system-mounts/lists.d.mts.map +1 -0
  492. package/dist/system-mounts/lists.mjs +122 -0
  493. package/dist/system-mounts/lists.mjs.map +1 -0
  494. package/dist/system-mounts/types.d.cts +124 -0
  495. package/dist/system-mounts/types.d.cts.map +1 -0
  496. package/dist/system-mounts/types.d.mts +125 -0
  497. package/dist/system-mounts/types.d.mts.map +1 -0
  498. package/dist/system-mounts/validate.cjs +56 -0
  499. package/dist/system-mounts/validate.d.cts +34 -0
  500. package/dist/system-mounts/validate.d.cts.map +1 -0
  501. package/dist/system-mounts/validate.d.mts +34 -0
  502. package/dist/system-mounts/validate.d.mts.map +1 -0
  503. package/dist/system-mounts/validate.mjs +56 -0
  504. package/dist/system-mounts/validate.mjs.map +1 -0
  505. package/dist/terminal-llm.cjs +90 -0
  506. package/dist/terminal-llm.d.cts +50 -0
  507. package/dist/terminal-llm.d.cts.map +1 -0
  508. package/dist/terminal-llm.d.mts +50 -0
  509. package/dist/terminal-llm.d.mts.map +1 -0
  510. package/dist/terminal-llm.mjs +90 -0
  511. package/dist/terminal-llm.mjs.map +1 -0
  512. package/dist/terminal-repl.cjs +371 -0
  513. package/dist/terminal-repl.d.cts +69 -0
  514. package/dist/terminal-repl.d.cts.map +1 -0
  515. package/dist/terminal-repl.d.mts +69 -0
  516. package/dist/terminal-repl.d.mts.map +1 -0
  517. package/dist/terminal-repl.mjs +370 -0
  518. package/dist/terminal-repl.mjs.map +1 -0
  519. package/dist/transport/idle-timer.cjs +136 -0
  520. package/dist/transport/idle-timer.d.cts +92 -0
  521. package/dist/transport/idle-timer.d.cts.map +1 -0
  522. package/dist/transport/idle-timer.d.mts +92 -0
  523. package/dist/transport/idle-timer.d.mts.map +1 -0
  524. package/dist/transport/idle-timer.mjs +132 -0
  525. package/dist/transport/idle-timer.mjs.map +1 -0
  526. package/dist/web-component-dsl.cjs +153 -0
  527. package/dist/web-component-dsl.d.cts +27 -0
  528. package/dist/web-component-dsl.d.cts.map +1 -0
  529. package/dist/web-component-dsl.d.mts +27 -0
  530. package/dist/web-component-dsl.d.mts.map +1 -0
  531. package/dist/web-component-dsl.mjs +152 -0
  532. package/dist/web-component-dsl.mjs.map +1 -0
  533. package/package.json +81 -0
@@ -0,0 +1,771 @@
1
+ import { cascade } from "./settings-cascade.mjs";
2
+ import { joinURL } from "ufo";
3
+ import { AFSForbiddenError, AFSNotFoundError, makeNsLog } from "@aigne/afs";
4
+
5
+ //#region src/session/settings-resolver.ts
6
+ const log = makeNsLog("aos");
7
+ /** Root of the instance-layer schema tree on the Small World base. */
8
+ const INSTANCE_SETTINGS_ROOT = "/instance/settings";
9
+ /** Root of the per-user override store on the caller's `/user` backing. */
10
+ const USER_SETTINGS_ROOT = "/settings";
11
+ /** Keys that must never be copied out of a parsed wrapper (prototype-pollution + control fields). */
12
+ const DANGEROUS_KEYS = new Set([
13
+ "__proto__",
14
+ "constructor",
15
+ "prototype"
16
+ ]);
17
+ const CONTROL_KEYS = new Set([
18
+ "value",
19
+ "scope",
20
+ "source",
21
+ "overridden",
22
+ "inheritedValue",
23
+ "visible",
24
+ "editable"
25
+ ]);
26
+ /** Strip dangerous keys from a parsed object (prototype pollution defense). */
27
+ function sanitizeObject(obj) {
28
+ const out = {};
29
+ for (const [k, v] of Object.entries(obj)) {
30
+ if (DANGEROUS_KEYS.has(k)) continue;
31
+ out[k] = v;
32
+ }
33
+ return out;
34
+ }
35
+ /**
36
+ * Parse an instance-layer wrapper. Defensive: malformed JSON degrades to a
37
+ * bare `{ value: <raw> }` (scope absent → instance) rather than throwing — a
38
+ * broken file must not take down the whole settings page.
39
+ */
40
+ function parseWrapper(raw) {
41
+ let obj = raw;
42
+ if (typeof raw === "string") try {
43
+ obj = JSON.parse(raw);
44
+ } catch {
45
+ return { value: raw };
46
+ }
47
+ if (obj === null || typeof obj !== "object") return { value: obj };
48
+ return sanitizeObject(obj);
49
+ }
50
+ function sanitizeScope(s) {
51
+ return s === "user" || s === "shared" ? s : "instance";
52
+ }
53
+ /**
54
+ * Coerce a bare user-override value (read back from the per-user fs backing,
55
+ * which stringifies everything) to the type of the instance default. The schema
56
+ * default is the type oracle: a boolean field's "false" → false, a number
57
+ * field's "7" → 7. Strings and already-correct types pass through; an
58
+ * un-coercible value is returned as-is rather than fabricating a wrong type.
59
+ */
60
+ function coerceToSchemaType(raw, schemaValue) {
61
+ if (typeof schemaValue === "boolean") {
62
+ if (raw === true || raw === false) return raw;
63
+ if (raw === "true") return true;
64
+ if (raw === "false") return false;
65
+ return raw;
66
+ }
67
+ if (typeof schemaValue === "number") {
68
+ if (typeof raw === "number") return raw;
69
+ if (typeof raw === "string" && raw.trim() !== "") {
70
+ const n = Number(raw);
71
+ if (Number.isFinite(n)) return n;
72
+ }
73
+ return raw;
74
+ }
75
+ return raw;
76
+ }
77
+ function isNotFound(e) {
78
+ return e instanceof AFSNotFoundError || typeof e === "object" && e !== null && e.code === "AFS_NOT_FOUND";
79
+ }
80
+ function lastSegment(path) {
81
+ return path.split("/").filter(Boolean).pop() ?? "";
82
+ }
83
+ /**
84
+ * Split a resolver-relative path into the wrapper file part and an optional
85
+ * sub-key. Settings fields are always `<name>.json`; anything before the first
86
+ * `.json` segment is the wrapper, anything after is a key inside it
87
+ * (`value`, `label`, …). No `.json` segment → a structure directory.
88
+ *
89
+ * Segment-based, not raw string slicing (CLAUDE.md path rules).
90
+ */
91
+ function splitWrapper(sub) {
92
+ const segs = sub.split("/").filter(Boolean);
93
+ const idx = segs.findIndex((s) => s.endsWith(".json"));
94
+ if (idx === -1) return { wrapperSub: null };
95
+ const wrapperSub = joinURL("/", ...segs.slice(0, idx + 1));
96
+ const rest = segs.slice(idx + 1);
97
+ return {
98
+ wrapperSub,
99
+ subKey: rest.length ? rest.join("/") : void 0
100
+ };
101
+ }
102
+ /**
103
+ * Map a resolver-relative subscribe path to the two underlying layer paths a
104
+ * propBind subscription must watch (§3.6 dual-layer subscribe). Pure — exported
105
+ * for unit testing (T4.1).
106
+ *
107
+ * A field bind like `/cascade/theme.json/value` maps to:
108
+ * - instancePath: `/instance/settings/cascade/theme.json` (base WRAPPER FILE —
109
+ * instance-layer writes land on the whole wrapper, never the `/value`
110
+ * sub-path, so we must watch the file, not the sub-key)
111
+ * - userPath: `/settings/cascade/theme.json` (user bare-value file)
112
+ *
113
+ * A directory / path-less subscribe (`/cascade`, `/`) has no `.json` segment, so
114
+ * `wrapperSub` is null and we watch the directory itself on both layers. The
115
+ * re-emit path is then derived per-event from the underlying path (see
116
+ * `subscribe()`), not from a fixed field path.
117
+ */
118
+ function mapSubscribePaths(relPath) {
119
+ const { wrapperSub } = splitWrapper(relPath);
120
+ const tail = wrapperSub ?? relPath;
121
+ return {
122
+ instancePath: joinURL(INSTANCE_SETTINGS_ROOT, tail),
123
+ userPath: joinURL(USER_SETTINGS_ROOT, tail),
124
+ isField: wrapperSub !== null
125
+ };
126
+ }
127
+ /**
128
+ * On-disk key holding EXPLICIT admin schema-text overrides in a converged
129
+ * (override-only) instance row: `{ value?, overrides?: { label: "...", … } }`.
130
+ * The nesting is the legacy/explicit discriminator (settings-layering §2.D):
131
+ * a LEGACY full wrapper carries its schema keys FLAT and is ignored on read
132
+ * (package schema wins — legacy-no-shadow); keys under `overrides` were
133
+ * deliberately written by an admin through `write()` and DO overlay the
134
+ * package schema.
135
+ */
136
+ const OVERRIDES_KEY = "overrides";
137
+ var SettingsResolver = class {
138
+ name;
139
+ accessMode = "readwrite";
140
+ base;
141
+ userProvider;
142
+ role;
143
+ schema;
144
+ /** Memoized lazy ingest — at most one ensure() flight per session. */
145
+ schemaReady = null;
146
+ /**
147
+ * Outcome of the lazy ingest. `ready` = the package declares settings and
148
+ * the derived index is consumable (STORE MODE: existence/schema come from
149
+ * the package index). `empty` = package declares none; `failed` = store
150
+ * unavailable; `unwired` = no handle. All non-`ready` states resolve in
151
+ * LEGACY MODE (instance rows define existence + schema) — the pre-Phase-2
152
+ * behavior, so blocklets without package settings keep working.
153
+ */
154
+ schemaState = "unwired";
155
+ /**
156
+ * Active render snapshots, insertion-ordered by `beginRender`. Ops resolve
157
+ * against the MOST RECENTLY begun snapshot (walks are sequential per
158
+ * render; concurrent renders each get their own immutable entry).
159
+ */
160
+ snapshots = /* @__PURE__ */ new Map();
161
+ constructor(opts) {
162
+ this.base = opts.base;
163
+ this.userProvider = opts.userProvider;
164
+ this.role = opts.role;
165
+ this.schema = opts.schema ?? null;
166
+ this.name = `settings-resolver:${opts.sessionId}`;
167
+ }
168
+ /**
169
+ * Lazily materialize the package-schema scope (Phase 1c plumbing). Memoized
170
+ * per resolver (per session); the store's own single-flight + completion
171
+ * marker make cross-session work idempotent. BEST-EFFORT in Phase 1: a
172
+ * failed ingest logs and falls back to legacy resolution (Phase 2 will
173
+ * consume the scope for existence/schema and define the hard contract).
174
+ */
175
+ ensureSchemaIngested() {
176
+ if (!this.schema) return Promise.resolve();
177
+ this.schemaReady ??= this.schema.ensure().then((result) => {
178
+ this.schemaState = result.fileCount > 0 ? "ready" : "empty";
179
+ }, (err) => {
180
+ this.schemaState = "failed";
181
+ log.warn(`[settings-resolver] schema ingest failed (legacy resolution continues): ${err instanceof Error ? err.message : err}`);
182
+ });
183
+ return this.schemaReady;
184
+ }
185
+ /** STORE MODE — existence/schema from the derived package index (§1.4). */
186
+ get storeMode() {
187
+ return this.schemaState === "ready";
188
+ }
189
+ /**
190
+ * Begin a render-scoped snapshot. Called by the auto-surface walk entry
191
+ * point (via `SessionUserAFS.beginRender` proxy) with a fresh `renderId`
192
+ * before walking; the resolver builds the WHOLE settings snapshot once
193
+ * (1× derived-index listEntries + instance/user override list + sparse
194
+ * reads) and serves every list/read of that render from memory.
195
+ *
196
+ * Phase 0: contract only — no-op. Phase 2 implements the snapshot builder.
197
+ * Idempotency contract: repeated `beginRender` with the same renderId and
198
+ * `endRender` without a matching begin are both safe no-ops.
199
+ */
200
+ async beginRender(renderId) {
201
+ if (this.snapshots.has(renderId)) return;
202
+ await this.ensureSchemaIngested();
203
+ const [schemas, instance, user] = await Promise.all([
204
+ this.storeMode ? this.loadSchemaMap() : Promise.resolve(null),
205
+ this.loadLayerRows(this.base, INSTANCE_SETTINGS_ROOT, true),
206
+ this.userProvider ? this.loadLayerRows(this.userProvider, USER_SETTINGS_ROOT, false) : Promise.resolve(/* @__PURE__ */ new Map())
207
+ ]);
208
+ this.snapshots.set(renderId, {
209
+ schemas,
210
+ instance,
211
+ user
212
+ });
213
+ }
214
+ /** Discard the render snapshot for `renderId`. See {@link beginRender}. */
215
+ endRender(renderId) {
216
+ this.snapshots.delete(renderId);
217
+ }
218
+ /** The snapshot ops resolve against: the most recently begun, still active. */
219
+ get activeSnapshot() {
220
+ let last = null;
221
+ for (const snap of this.snapshots.values()) last = snap;
222
+ return last;
223
+ }
224
+ /** Bulk-read + parse the derived package schemas (1 store query). */
225
+ async loadSchemaMap() {
226
+ const map = /* @__PURE__ */ new Map();
227
+ if (!this.schema) return map;
228
+ try {
229
+ for (const { path, content } of await this.schema.listSchemas()) map.set(joinURL("/", path), parseWrapper(content));
230
+ } catch (err) {
231
+ log.warn(`[settings-resolver] schema bulk read failed: ${err instanceof Error ? err.message : err}`);
232
+ }
233
+ return map;
234
+ }
235
+ /**
236
+ * Walk one override layer's tree and read every `.json` row. Sparse by
237
+ * design (converged rows: 0-5); legacy instances pay row-count reads ONCE
238
+ * per render — all in-process, replacing the per-field WS round-trips.
239
+ */
240
+ async loadLayerRows(provider, root, parse) {
241
+ const map = /* @__PURE__ */ new Map();
242
+ if (!provider.list || !provider.read) return map;
243
+ const walk = async (dir) => {
244
+ let entries;
245
+ try {
246
+ entries = (await provider.list?.(dir))?.data ?? [];
247
+ } catch {
248
+ return;
249
+ }
250
+ for (const entry of entries) {
251
+ const name = entry.path.split("/").filter(Boolean).pop();
252
+ if (!name || name.startsWith(".")) continue;
253
+ const full = joinURL(dir, name);
254
+ if (name.endsWith(".json")) try {
255
+ const raw = (await provider.read?.(full))?.data?.content;
256
+ if (raw === void 0) continue;
257
+ map.set(full.slice(root.length), parse ? parseWrapper(raw) : raw);
258
+ } catch {}
259
+ else await walk(full);
260
+ }
261
+ };
262
+ await walk(root);
263
+ return map;
264
+ }
265
+ get isAuthed() {
266
+ return this.userProvider != null;
267
+ }
268
+ get isOwnerOrAdmin() {
269
+ return this.role === "owner" || this.role === "admin";
270
+ }
271
+ /** The physical layer this caller reads AND writes for the given scope. */
272
+ resolveWriteLayer(scope) {
273
+ if (scope === "instance") return "instance";
274
+ if (scope === "user") return "user";
275
+ return this.isOwnerOrAdmin ? "instance" : "user";
276
+ }
277
+ /** Presentation hint: should this caller's form render the field at all? */
278
+ visible(scope) {
279
+ if (scope === "instance") return this.isOwnerOrAdmin;
280
+ if (scope === "user") return this.isAuthed;
281
+ return true;
282
+ }
283
+ /** Capability hint + (P1) write-enforcement basis: may this caller edit it? */
284
+ editable(scope) {
285
+ if (scope === "instance") return this.isOwnerOrAdmin;
286
+ if (scope === "user") return this.isAuthed;
287
+ return this.isAuthed;
288
+ }
289
+ /** Normalize an incoming resolver-relative path; reject traversal outright. */
290
+ normalizeSub(path) {
291
+ const p = path.startsWith("/") ? path : `/${path}`;
292
+ if (p.split("/").some((seg) => seg === "..")) throw new AFSForbiddenError(path, "path traversal rejected");
293
+ return p;
294
+ }
295
+ /** Translate an underlying layer path back into the resolver-relative space. */
296
+ underlyingToRelative(fullPath, layer) {
297
+ const root = layer === "instance" ? INSTANCE_SETTINGS_ROOT : USER_SETTINGS_ROOT;
298
+ if (fullPath === root) return "/";
299
+ if (fullPath.startsWith(`${root}/`)) return fullPath.slice(root.length);
300
+ return fullPath;
301
+ }
302
+ baseRead(path, options) {
303
+ if (!this.base.read) throw new Error("base.read not supported");
304
+ return this.base.read(path, options);
305
+ }
306
+ baseStat(path, options) {
307
+ if (!this.base.stat) throw new Error("base.stat not supported");
308
+ return this.base.stat(path, options);
309
+ }
310
+ async loadInstanceWrapper(wrapperSub) {
311
+ const instancePath = joinURL(INSTANCE_SETTINGS_ROOT, wrapperSub);
312
+ let raw;
313
+ try {
314
+ raw = (await this.baseRead(instancePath)).data?.content;
315
+ } catch (e) {
316
+ if (isNotFound(e)) throw new AFSNotFoundError(wrapperSub);
317
+ throw e;
318
+ }
319
+ if (raw === void 0) throw new AFSNotFoundError(wrapperSub);
320
+ const inst = parseWrapper(raw);
321
+ return {
322
+ inst,
323
+ scope: sanitizeScope(inst.scope)
324
+ };
325
+ }
326
+ /** Read the caller's bare override value, or undefined when absent/anonymous. */
327
+ async readUserOverride(wrapperSub) {
328
+ const snap = this.activeSnapshot;
329
+ if (snap) return this.userProvider ? snap.user.get(wrapperSub) : void 0;
330
+ if (!this.userProvider?.read) return void 0;
331
+ try {
332
+ return (await this.userProvider.read(joinURL(USER_SETTINGS_ROOT, wrapperSub))).data?.content;
333
+ } catch (e) {
334
+ if (isNotFound(e)) return void 0;
335
+ throw e;
336
+ }
337
+ }
338
+ /** Parsed package schema for a field, or null (store mode only). */
339
+ async getSchemaWrapper(wrapperSub) {
340
+ const snap = this.activeSnapshot;
341
+ if (snap?.schemas) return snap.schemas.get(wrapperSub) ?? null;
342
+ if (!this.schema) return null;
343
+ const raw = await this.schema.getSchema(wrapperSub);
344
+ return raw === null ? null : parseWrapper(raw);
345
+ }
346
+ /** Parsed raw instance row, or null when absent (never throws not-found). */
347
+ async getInstanceRow(wrapperSub) {
348
+ const snap = this.activeSnapshot;
349
+ if (snap) return snap.instance.get(wrapperSub) ?? null;
350
+ try {
351
+ return (await this.loadInstanceWrapper(wrapperSub)).inst;
352
+ } catch (e) {
353
+ if (isNotFound(e)) return null;
354
+ throw e;
355
+ }
356
+ }
357
+ /**
358
+ * Reduce a raw instance row to its OVERRIDE-ONLY contribution (§2.D):
359
+ * `value` (when present) + keys explicitly written under `overrides`.
360
+ * A LEGACY full wrapper's flat schema keys are deliberately dropped —
361
+ * the package schema is authoritative (legacy-no-shadow).
362
+ */
363
+ stripToOverrideOnly(row) {
364
+ const out = {};
365
+ if (!row) return out;
366
+ if (row.value !== void 0) out.value = row.value;
367
+ const ov = row[OVERRIDES_KEY];
368
+ if (ov && typeof ov === "object" && !Array.isArray(ov)) for (const [k, v] of Object.entries(ov)) {
369
+ if (DANGEROUS_KEYS.has(k) || CONTROL_KEYS.has(k) || k === OVERRIDES_KEY) continue;
370
+ out[k] = v;
371
+ }
372
+ return out;
373
+ }
374
+ /**
375
+ * Load one field through the cascade. Returns null when the field does not
376
+ * exist — store mode: not in the derived package index (orphan instance
377
+ * rows are IGNORED, §5.4.5); legacy mode: no instance row.
378
+ */
379
+ async loadField(wrapperSub) {
380
+ let pkg;
381
+ let instOverride;
382
+ let instRow;
383
+ if (this.storeMode) {
384
+ const schemaWrapper = await this.getSchemaWrapper(wrapperSub);
385
+ if (!schemaWrapper) return null;
386
+ instRow = await this.getInstanceRow(wrapperSub);
387
+ pkg = schemaWrapper;
388
+ instOverride = this.stripToOverrideOnly(instRow);
389
+ } else {
390
+ instRow = await this.getInstanceRow(wrapperSub);
391
+ if (!instRow) return null;
392
+ pkg = instRow;
393
+ instOverride = {};
394
+ }
395
+ const scope = sanitizeScope(pkg.scope);
396
+ const rawUser = this.resolveWriteLayer(scope) === "user" ? await this.readUserOverride(wrapperSub) : void 0;
397
+ const inherited = instOverride.value !== void 0 ? instOverride.value : pkg.value;
398
+ const user = rawUser === void 0 ? void 0 : { value: coerceToSchemaType(rawUser, inherited) };
399
+ const eff = cascade(pkg, instOverride, user);
400
+ const overridden = eff.source === "user";
401
+ const editable = this.editable(scope);
402
+ const visible = this.visible(scope);
403
+ const synth = {
404
+ ...eff.synth,
405
+ source: overridden ? "user" : "instance",
406
+ editable,
407
+ visible
408
+ };
409
+ return {
410
+ scope,
411
+ visible,
412
+ editable,
413
+ overridden,
414
+ eff: eff.value,
415
+ synth,
416
+ instRow,
417
+ fromPackage: this.storeMode
418
+ };
419
+ }
420
+ /** Opaque version of the layer this caller would write — §3.7. */
421
+ async writeTargetVersion(scope, wrapperSub) {
422
+ const layer = this.resolveWriteLayer(scope);
423
+ try {
424
+ if (layer === "instance") return (await this.baseStat(joinURL(INSTANCE_SETTINGS_ROOT, wrapperSub))).data?.meta?.version;
425
+ if (this.userProvider?.stat) return (await this.userProvider.stat(joinURL(USER_SETTINGS_ROOT, wrapperSub))).data?.meta?.version;
426
+ } catch (e) {
427
+ if (!isNotFound(e)) throw e;
428
+ }
429
+ }
430
+ async read(path, options) {
431
+ await this.ensureSchemaIngested();
432
+ const sub = this.normalizeSub(path);
433
+ const { wrapperSub, subKey } = splitWrapper(sub);
434
+ if (!wrapperSub) {
435
+ if (this.storeMode) {
436
+ if (!await this.dirExists(sub)) throw new AFSNotFoundError(sub);
437
+ return { data: {
438
+ id: lastSegment(sub) || "settings",
439
+ path: sub,
440
+ content: `Settings directory: ${sub}`,
441
+ meta: { kind: "directory" }
442
+ } };
443
+ }
444
+ const instancePath = joinURL(INSTANCE_SETTINGS_ROOT, sub);
445
+ let r;
446
+ try {
447
+ r = await this.baseRead(instancePath, options);
448
+ } catch (e) {
449
+ if (isNotFound(e)) throw new AFSNotFoundError(sub);
450
+ throw e;
451
+ }
452
+ if (!r.data) throw new AFSNotFoundError(sub);
453
+ return { data: {
454
+ ...r.data,
455
+ path: sub,
456
+ meta: {
457
+ ...r.data.meta,
458
+ kind: "directory"
459
+ }
460
+ } };
461
+ }
462
+ const field = await this.loadField(wrapperSub);
463
+ if (!field) throw new AFSNotFoundError(wrapperSub);
464
+ const version = this.activeSnapshot ? void 0 : await this.writeTargetVersion(field.scope, wrapperSub);
465
+ const meta = {
466
+ accessMode: field.editable ? "readwrite" : "readonly",
467
+ visible: field.visible,
468
+ editable: field.editable,
469
+ scope: field.scope,
470
+ version
471
+ };
472
+ if (subKey === void 0) return { data: {
473
+ id: lastSegment(wrapperSub),
474
+ path: wrapperSub,
475
+ content: JSON.stringify(field.synth),
476
+ meta
477
+ } };
478
+ const content = subKey === "value" ? field.eff : field.synth[subKey];
479
+ return { data: {
480
+ id: lastSegment(subKey),
481
+ path: joinURL(wrapperSub, subKey),
482
+ content,
483
+ meta
484
+ } };
485
+ }
486
+ /** Store-mode directory existence: any package field lives under `sub`. */
487
+ async dirExists(sub) {
488
+ if (sub === "/") return true;
489
+ const prefix = `${sub}/`;
490
+ for (const key of (await this.schemaMap()).keys()) if (key.startsWith(prefix)) return true;
491
+ return false;
492
+ }
493
+ /**
494
+ * The full schema map (store mode): from the active snapshot when present,
495
+ * else one bulk store query — replacing the legacy per-field N+1 scope peek.
496
+ */
497
+ async schemaMap() {
498
+ const snap = this.activeSnapshot;
499
+ if (snap?.schemas) return snap.schemas;
500
+ return this.loadSchemaMap();
501
+ }
502
+ async list(path, options) {
503
+ await this.ensureSchemaIngested();
504
+ const sub = this.normalizeSub(path);
505
+ if (this.storeMode) {
506
+ const schemas = await this.schemaMap();
507
+ const prefix = sub === "/" ? "/" : `${sub}/`;
508
+ const children = /* @__PURE__ */ new Map();
509
+ for (const key of schemas.keys()) {
510
+ if (!key.startsWith(prefix)) continue;
511
+ const rest = key.slice(prefix.length);
512
+ const seg = rest.split("/")[0];
513
+ if (!seg) continue;
514
+ children.set(seg, children.get(seg) || rest.includes("/"));
515
+ }
516
+ if (children.size === 0 && sub !== "/") throw new AFSNotFoundError(sub);
517
+ const data$1 = [];
518
+ for (const [seg, isDir] of children) {
519
+ const childSub = joinURL(sub, seg);
520
+ if (isDir) {
521
+ data$1.push({
522
+ id: seg,
523
+ path: childSub,
524
+ meta: {
525
+ kind: "directory",
526
+ childrenCount: -1
527
+ }
528
+ });
529
+ continue;
530
+ }
531
+ const scope = sanitizeScope(schemas.get(childSub)?.scope);
532
+ const editable = this.editable(scope);
533
+ const visible = this.visible(scope);
534
+ data$1.push({
535
+ id: seg,
536
+ path: childSub,
537
+ meta: {
538
+ accessMode: editable ? "readwrite" : "readonly",
539
+ scope,
540
+ visible,
541
+ editable
542
+ }
543
+ });
544
+ }
545
+ return { data: data$1 };
546
+ }
547
+ const instanceDir = joinURL(INSTANCE_SETTINGS_ROOT, sub);
548
+ const result = await this.base.list(instanceDir, options);
549
+ const data = await Promise.all((result.data ?? []).map(async (e) => {
550
+ const relPath = this.underlyingToRelative(e.path, "instance");
551
+ if (!relPath.endsWith(".json")) return {
552
+ ...e,
553
+ path: relPath,
554
+ meta: {
555
+ ...e.meta,
556
+ kind: "directory",
557
+ childrenCount: e.meta?.childrenCount ?? -1
558
+ }
559
+ };
560
+ let scope = "instance";
561
+ try {
562
+ const row = await this.getInstanceRow(relPath);
563
+ if (row) scope = sanitizeScope(row.scope);
564
+ } catch {}
565
+ const editable = this.editable(scope);
566
+ const visible = this.visible(scope);
567
+ return {
568
+ ...e,
569
+ path: relPath,
570
+ meta: {
571
+ ...e.meta,
572
+ kind: void 0,
573
+ childrenCount: void 0,
574
+ accessMode: editable ? "readwrite" : "readonly",
575
+ scope,
576
+ visible,
577
+ editable
578
+ }
579
+ };
580
+ }));
581
+ return {
582
+ ...result,
583
+ data
584
+ };
585
+ }
586
+ async stat(path, options) {
587
+ await this.ensureSchemaIngested();
588
+ const sub = this.normalizeSub(path);
589
+ const { wrapperSub, subKey } = splitWrapper(sub);
590
+ if (!wrapperSub) {
591
+ if (this.storeMode) {
592
+ if (!await this.dirExists(sub)) throw new AFSNotFoundError(sub);
593
+ return { data: {
594
+ id: lastSegment(sub) || "settings",
595
+ path: sub,
596
+ meta: {
597
+ kind: "directory",
598
+ childrenCount: -1
599
+ }
600
+ } };
601
+ }
602
+ const instancePath = joinURL(INSTANCE_SETTINGS_ROOT, sub);
603
+ let r;
604
+ try {
605
+ r = await this.baseStat(instancePath, options);
606
+ } catch (e) {
607
+ if (isNotFound(e)) throw new AFSNotFoundError(sub);
608
+ throw e;
609
+ }
610
+ if (!r.data) throw new AFSNotFoundError(sub);
611
+ return { data: {
612
+ ...r.data,
613
+ path: sub,
614
+ meta: {
615
+ ...r.data.meta,
616
+ kind: "directory"
617
+ }
618
+ } };
619
+ }
620
+ const field = await this.loadField(wrapperSub);
621
+ if (!field) throw new AFSNotFoundError(wrapperSub);
622
+ const version = await this.writeTargetVersion(field.scope, wrapperSub);
623
+ const statPath = subKey ? joinURL(wrapperSub, subKey) : wrapperSub;
624
+ return { data: {
625
+ id: lastSegment(statPath),
626
+ path: statPath,
627
+ meta: {
628
+ accessMode: field.editable ? "readwrite" : "readonly",
629
+ visible: field.visible,
630
+ editable: field.editable,
631
+ scope: field.scope,
632
+ version
633
+ }
634
+ } };
635
+ }
636
+ async write(path, content, options) {
637
+ await this.ensureSchemaIngested();
638
+ const { wrapperSub, subKey } = splitWrapper(this.normalizeSub(path));
639
+ if (!wrapperSub) throw new AFSForbiddenError(path, "settings writes must target a field, e.g. .../x.json/value");
640
+ if (subKey === void 0) throw new AFSForbiddenError(path, "settings writes must target a field sub-path (.../x.json/value)");
641
+ const field = await this.loadField(wrapperSub);
642
+ if (!field) throw new AFSNotFoundError(wrapperSub);
643
+ const ifMatch = options?.ifMatch;
644
+ const context = options?.context;
645
+ const instBase = this.storeMode ? this.overrideOnlyDiskShape(field.instRow) : field.instRow ?? {};
646
+ if (subKey !== "value") {
647
+ if (!this.isOwnerOrAdmin) throw new AFSForbiddenError(path, "editing settings schema requires owner/admin");
648
+ if (this.storeMode) {
649
+ const prior = instBase[OVERRIDES_KEY] ?? {};
650
+ return this.writeInstanceWrapper(wrapperSub, instBase, OVERRIDES_KEY, {
651
+ ...prior,
652
+ [subKey]: content.content
653
+ }, {
654
+ ifMatch,
655
+ context
656
+ });
657
+ }
658
+ return this.writeInstanceWrapper(wrapperSub, instBase, subKey, content.content, {
659
+ ifMatch,
660
+ context
661
+ });
662
+ }
663
+ if (this.resolveWriteLayer(field.scope) === "instance") {
664
+ if (!this.isOwnerOrAdmin) throw new AFSForbiddenError(path, "instance-scope settings require owner/admin");
665
+ return this.writeInstanceWrapper(wrapperSub, instBase, "value", content.content, {
666
+ ifMatch,
667
+ context
668
+ });
669
+ }
670
+ if (!this.isAuthed || !this.userProvider?.write) throw new AFSForbiddenError(path, "sign in to personalize this setting");
671
+ return this.userProvider.write(joinURL(USER_SETTINGS_ROOT, wrapperSub), { content: content.content }, this.writeOptions(ifMatch, context));
672
+ }
673
+ /**
674
+ * The ON-DISK override-only shape of an instance row: `{ value?, overrides? }`.
675
+ * Distinct from {@link stripToOverrideOnly} (the flattened READ-side
676
+ * contribution) — this preserves the nested `overrides` object so a write
677
+ * RMW keeps prior explicit schema-text edits.
678
+ */
679
+ overrideOnlyDiskShape(row) {
680
+ const out = {};
681
+ if (!row) return out;
682
+ if (row.value !== void 0) out.value = row.value;
683
+ const ov = row[OVERRIDES_KEY];
684
+ if (ov && typeof ov === "object" && !Array.isArray(ov)) out[OVERRIDES_KEY] = ov;
685
+ return out;
686
+ }
687
+ /** Assemble write options, omitting empties so providers see a clean shape. */
688
+ writeOptions(ifMatch, context) {
689
+ const out = {};
690
+ if (ifMatch != null) out.ifMatch = ifMatch;
691
+ if (context != null) out.context = context;
692
+ return out;
693
+ }
694
+ /**
695
+ * Read-modify-write the FULL instance wrapper so siblings
696
+ * (label/description/options/…) survive — the G0 regression guard. ifMatch
697
+ * (if supplied) is compared by the base provider against the wrapper version;
698
+ * context (if supplied) flows through so the emitted event carries origin.
699
+ */
700
+ writeInstanceWrapper(wrapperSub, inst, key, value, opts) {
701
+ if (!this.base.write) throw new Error("base.write not supported");
702
+ const next = {
703
+ ...inst,
704
+ [key]: value
705
+ };
706
+ return this.base.write(joinURL(INSTANCE_SETTINGS_ROOT, wrapperSub), { content: JSON.stringify(next) }, this.writeOptions(opts.ifMatch, opts.context));
707
+ }
708
+ async delete(path, options) {
709
+ await this.ensureSchemaIngested();
710
+ const { wrapperSub, subKey } = splitWrapper(this.normalizeSub(path));
711
+ if (!wrapperSub) throw new AFSForbiddenError(path, "not a settings field path");
712
+ if (subKey !== void 0 && subKey !== "value") throw new AFSForbiddenError(path, "only a field's value can be reset");
713
+ const field = await this.loadField(wrapperSub);
714
+ if (!field) throw new AFSNotFoundError(wrapperSub);
715
+ if (this.resolveWriteLayer(field.scope) === "instance") throw new AFSForbiddenError(path, "instance settings cannot be deleted; admin edits via write");
716
+ if (!this.isAuthed || !this.userProvider?.delete) throw new AFSForbiddenError(path, "sign in to reset this setting");
717
+ return this.userProvider.delete(joinURL(USER_SETTINGS_ROOT, wrapperSub), options);
718
+ }
719
+ /**
720
+ * Bridge instance-layer + user-layer change events into the
721
+ * `/instance/settings/...` namespace so propBind can react to a cascade write
722
+ * regardless of which physical layer it landed on.
723
+ *
724
+ * For a FIELD subscription (`/cascade/theme.json/value`):
725
+ * - watch the instance WRAPPER FILE on `base` and the bare-value file on
726
+ * `userProvider` (see `mapSubscribePaths`);
727
+ * - re-emit at the EXACT filter path so the bridged event matches what the
728
+ * subscriber (PropBindSubscriber) asked for — SessionUserAFS then
729
+ * re-prefixes the resolver-relative path back to `/instance/settings/...`.
730
+ *
731
+ * Two invariants make echo suppression + reset work:
732
+ * 1. ORIGIN PASSTHROUGH — `{ ...evt }` preserves `origin.sessionId`, so the
733
+ * writer's own session is filtered out by PropBindSubscriber and a
734
+ * different session still receives the patch. (The underlying write
735
+ * carries origin only because `write()` now forwards `options.context`.)
736
+ * 2. TYPE NORMALIZATION — a user-layer DELETE (reset, D-f) is re-emitted as
737
+ * `afs:write` because, from the cascade's point of view, the effective
738
+ * value changed (reverted to the instance default); subscribers re-read
739
+ * either way. We therefore drop the type filter on the underlying
740
+ * subscription so deletes are not missed.
741
+ */
742
+ subscribe(filter, callback) {
743
+ const rawPath = typeof filter.path === "string" ? filter.path || "/" : "/";
744
+ const relPath = this.normalizeSub(rawPath);
745
+ const { instancePath, userPath, isField } = mapSubscribePaths(relPath);
746
+ const emit = (evt, layer) => {
747
+ const path = isField ? relPath : this.underlyingToRelative(evt.path, layer);
748
+ callback({
749
+ ...evt,
750
+ type: "afs:write",
751
+ path
752
+ });
753
+ };
754
+ const unsubs = [];
755
+ if (this.base.subscribe) unsubs.push(this.base.subscribe({ path: instancePath }, (evt) => emit(evt, "instance")));
756
+ if (this.userProvider?.subscribe) unsubs.push(this.userProvider.subscribe({ path: userPath }, (evt) => emit(evt, "user")));
757
+ return () => {
758
+ for (const u of unsubs) try {
759
+ u();
760
+ } catch {}
761
+ };
762
+ }
763
+ setEventSink(sink) {
764
+ this.base.setEventSink?.(sink);
765
+ this.userProvider?.setEventSink?.(sink);
766
+ }
767
+ };
768
+
769
+ //#endregion
770
+ export { SettingsResolver };
771
+ //# sourceMappingURL=settings-resolver.mjs.map