@astrale-os/shell 0.1.1 → 0.2.0

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 (284) hide show
  1. package/LICENSE +202 -0
  2. package/dist/application/apps.d.ts +18 -0
  3. package/dist/application/apps.d.ts.map +1 -0
  4. package/dist/application/apps.js +35 -0
  5. package/dist/application/namespaces.d.ts +21 -0
  6. package/dist/application/namespaces.d.ts.map +1 -0
  7. package/dist/application/namespaces.js +12 -0
  8. package/dist/application/session/open.d.ts +19 -0
  9. package/dist/application/session/open.d.ts.map +1 -0
  10. package/dist/application/session/open.js +46 -0
  11. package/dist/application/session/session.d.ts +41 -0
  12. package/dist/application/session/session.d.ts.map +1 -0
  13. package/dist/application/session/session.js +9 -0
  14. package/dist/application/session/token.d.ts +24 -0
  15. package/dist/application/session/token.d.ts.map +1 -0
  16. package/dist/application/session/token.js +51 -0
  17. package/dist/application/spaces.d.ts +17 -0
  18. package/dist/application/spaces.d.ts.map +1 -0
  19. package/dist/application/spaces.js +30 -0
  20. package/dist/application/user.d.ts +20 -0
  21. package/dist/application/user.d.ts.map +1 -0
  22. package/dist/application/user.js +26 -0
  23. package/dist/application/view.d.ts +20 -0
  24. package/dist/application/view.d.ts.map +1 -0
  25. package/dist/application/view.js +18 -0
  26. package/dist/{application/channels/children-channel.d.ts → channel/children.d.ts} +4 -4
  27. package/dist/channel/children.d.ts.map +1 -0
  28. package/dist/channel/listeners.d.ts +8 -0
  29. package/dist/channel/listeners.d.ts.map +1 -0
  30. package/dist/{adapters/message-port.transport.d.ts → channel/message-port.d.ts} +2 -2
  31. package/dist/channel/message-port.d.ts.map +1 -0
  32. package/dist/{application/channels → channel}/observer.d.ts +2 -1
  33. package/dist/channel/observer.d.ts.map +1 -0
  34. package/dist/{application/channels/parent-channel.d.ts → channel/parent.d.ts} +4 -4
  35. package/dist/channel/parent.d.ts.map +1 -0
  36. package/dist/{application/channels/parent-channel.js → channel/parent.js} +1 -1
  37. package/dist/channel/transport.d.ts +8 -0
  38. package/dist/channel/transport.d.ts.map +1 -0
  39. package/dist/index.d.ts +56 -41
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +23 -20
  42. package/dist/{domain/intent → intent}/middleware/capabilities.d.ts +2 -2
  43. package/dist/intent/middleware/capabilities.d.ts.map +1 -0
  44. package/dist/intent/middleware/logging.d.ts.map +1 -0
  45. package/dist/{domain/intent → intent}/middleware/rate-limit.d.ts +1 -1
  46. package/dist/intent/middleware/rate-limit.d.ts.map +1 -0
  47. package/dist/{application/intent/pipeline-runner.d.ts → intent/pipeline.d.ts} +3 -3
  48. package/dist/intent/pipeline.d.ts.map +1 -0
  49. package/dist/intent/policy.d.ts +40 -0
  50. package/dist/intent/policy.d.ts.map +1 -0
  51. package/dist/intent/policy.js +15 -0
  52. package/dist/{application/intent → intent}/request.d.ts +5 -14
  53. package/dist/intent/request.d.ts.map +1 -0
  54. package/dist/{application/intent → intent}/request.js +6 -20
  55. package/dist/intent/router.d.ts +31 -0
  56. package/dist/intent/router.d.ts.map +1 -0
  57. package/dist/{application/intent → intent}/router.js +1 -15
  58. package/dist/kernel/client.d.ts +33 -0
  59. package/dist/kernel/client.d.ts.map +1 -0
  60. package/dist/kernel/credential.d.ts +35 -0
  61. package/dist/kernel/credential.d.ts.map +1 -0
  62. package/dist/kernel/credential.js +43 -0
  63. package/dist/kernel/delegated.d.ts +17 -0
  64. package/dist/kernel/delegated.d.ts.map +1 -0
  65. package/dist/kernel/delegated.js +29 -0
  66. package/dist/{application/windowing/token-refresh.d.ts → kernel/delegation/refresh.d.ts} +2 -2
  67. package/dist/kernel/delegation/refresh.d.ts.map +1 -0
  68. package/dist/{application/windowing/token-refresh.js → kernel/delegation/refresh.js} +1 -1
  69. package/dist/{domain/identity/delegation.d.ts → kernel/delegation/token.d.ts} +1 -1
  70. package/dist/kernel/delegation/token.d.ts.map +1 -0
  71. package/dist/{adapters/kernel-client.adapter.d.ts → kernel/session.d.ts} +15 -12
  72. package/dist/kernel/session.d.ts.map +1 -0
  73. package/dist/{adapters/kernel-client.adapter.js → kernel/session.js} +10 -15
  74. package/dist/message/ctrl.d.ts +34 -0
  75. package/dist/message/ctrl.d.ts.map +1 -0
  76. package/dist/message/error.d.ts +9 -0
  77. package/dist/message/error.d.ts.map +1 -0
  78. package/dist/{application/windowing/protocol.d.ts → message/init.d.ts} +1 -1
  79. package/dist/message/init.d.ts.map +1 -0
  80. package/dist/{domain/message/registries.d.ts → message/intent.d.ts} +45 -37
  81. package/dist/message/intent.d.ts.map +1 -0
  82. package/dist/message/message.d.ts +10 -0
  83. package/dist/message/message.d.ts.map +1 -0
  84. package/dist/shell/access.d.ts +10 -0
  85. package/dist/shell/access.d.ts.map +1 -0
  86. package/dist/shell/access.js +19 -0
  87. package/dist/shell/build.d.ts +28 -0
  88. package/dist/shell/build.d.ts.map +1 -0
  89. package/dist/shell/build.js +58 -0
  90. package/dist/shell/config.d.ts +29 -0
  91. package/dist/shell/config.d.ts.map +1 -0
  92. package/dist/shell/create.d.ts +4 -0
  93. package/dist/shell/create.d.ts.map +1 -0
  94. package/dist/shell/create.js +5 -0
  95. package/dist/{application/windowing/child-init.d.ts → shell/sandboxed/boot.d.ts} +5 -5
  96. package/dist/shell/sandboxed/boot.d.ts.map +1 -0
  97. package/dist/{application/windowing/child-init.js → shell/sandboxed/boot.js} +5 -6
  98. package/dist/shell/sandboxed/guarded.d.ts +13 -0
  99. package/dist/shell/sandboxed/guarded.d.ts.map +1 -0
  100. package/dist/shell/sandboxed/guarded.js +28 -0
  101. package/dist/shell/sandboxed/pending.d.ts +14 -0
  102. package/dist/shell/sandboxed/pending.d.ts.map +1 -0
  103. package/dist/shell/sandboxed/pending.js +30 -0
  104. package/dist/shell/sandboxed/sandboxed.d.ts +4 -0
  105. package/dist/shell/sandboxed/sandboxed.d.ts.map +1 -0
  106. package/dist/shell/sandboxed/sandboxed.js +100 -0
  107. package/dist/shell/shell.d.ts +36 -0
  108. package/dist/shell/shell.d.ts.map +1 -0
  109. package/dist/shell/standalone.d.ts +4 -0
  110. package/dist/shell/standalone.d.ts.map +1 -0
  111. package/dist/shell/standalone.js +85 -0
  112. package/dist/{domain/window/config.d.ts → window/capabilities.d.ts} +3 -3
  113. package/dist/window/capabilities.d.ts.map +1 -0
  114. package/dist/{ports/shell-adapter.d.ts → window/embed/adapter.d.ts} +3 -2
  115. package/dist/window/embed/adapter.d.ts.map +1 -0
  116. package/dist/{adapters/iframe.shell-adapter.d.ts → window/embed/iframe.d.ts} +2 -2
  117. package/dist/window/embed/iframe.d.ts.map +1 -0
  118. package/dist/{application/windowing/lifecycle-controller.d.ts → window/lifecycle/states.d.ts} +4 -3
  119. package/dist/window/lifecycle/states.d.ts.map +1 -0
  120. package/dist/{application/windowing/lifecycle-controller.js → window/lifecycle/states.js} +1 -1
  121. package/dist/{domain/window/lifecycle.d.ts → window/lifecycle/transition.d.ts} +3 -3
  122. package/dist/window/lifecycle/transition.d.ts.map +1 -0
  123. package/dist/{domain/window/lifecycle.js → window/lifecycle/transition.js} +1 -1
  124. package/dist/window/mount/close.d.ts +27 -0
  125. package/dist/window/mount/close.d.ts.map +1 -0
  126. package/dist/window/mount/close.js +74 -0
  127. package/dist/window/mount/credential.d.ts +41 -0
  128. package/dist/window/mount/credential.d.ts.map +1 -0
  129. package/dist/window/mount/credential.js +74 -0
  130. package/dist/window/mount/handshake.d.ts.map +1 -0
  131. package/dist/{application/windowing → window/mount}/handshake.js +1 -1
  132. package/dist/{application/windowing/mount-controller.d.ts → window/mount/mount.d.ts} +7 -7
  133. package/dist/window/mount/mount.d.ts.map +1 -0
  134. package/dist/window/mount/mount.js +143 -0
  135. package/dist/window/mount/params.d.ts +73 -0
  136. package/dist/window/mount/params.d.ts.map +1 -0
  137. package/dist/window/mount/params.js +1 -0
  138. package/dist/window/mount/plain.d.ts +20 -0
  139. package/dist/window/mount/plain.d.ts.map +1 -0
  140. package/dist/window/mount/plain.js +46 -0
  141. package/dist/{domain/window → window}/window.d.ts +1 -1
  142. package/dist/window/window.d.ts.map +1 -0
  143. package/dist/window/window.js +1 -0
  144. package/package.json +11 -6
  145. package/src/application/apps.ts +60 -0
  146. package/src/application/namespaces.ts +38 -0
  147. package/src/application/session/open.ts +73 -0
  148. package/src/application/session/session.ts +46 -0
  149. package/src/application/session/token.ts +87 -0
  150. package/src/application/spaces.ts +52 -0
  151. package/src/application/user.ts +54 -0
  152. package/src/application/view.ts +42 -0
  153. package/src/{application/channels/children-channel.ts → channel/children.ts} +3 -3
  154. package/src/{application/channels/types.ts → channel/listeners.ts} +2 -7
  155. package/src/{adapters/message-port.transport.ts → channel/message-port.ts} +2 -2
  156. package/src/{application/channels → channel}/observer.ts +2 -1
  157. package/src/{application/channels/parent-channel.ts → channel/parent.ts} +4 -4
  158. package/src/{ports → channel}/transport.ts +2 -1
  159. package/src/index.ts +80 -88
  160. package/src/{domain/intent → intent}/middleware/capabilities.ts +2 -3
  161. package/src/{domain/intent → intent}/middleware/logging.ts +1 -1
  162. package/src/{domain/intent → intent}/middleware/rate-limit.ts +1 -1
  163. package/src/{application/intent/pipeline-runner.ts → intent/pipeline.ts} +3 -2
  164. package/src/intent/policy.ts +46 -0
  165. package/src/{application/intent → intent}/request.ts +14 -34
  166. package/src/{application/intent → intent}/router.ts +12 -49
  167. package/src/kernel/client.ts +33 -0
  168. package/src/kernel/credential.ts +78 -0
  169. package/src/kernel/delegated.ts +49 -0
  170. package/src/{application/windowing/token-refresh.ts → kernel/delegation/refresh.ts} +2 -2
  171. package/src/{adapters/kernel-client.adapter.ts → kernel/session.ts} +26 -33
  172. package/src/message/ctrl.ts +25 -0
  173. package/src/{domain/message/errors.ts → message/error.ts} +8 -0
  174. package/src/message/intent.ts +98 -0
  175. package/src/message/message.ts +11 -0
  176. package/src/shell/access.ts +26 -0
  177. package/src/shell/build.ts +95 -0
  178. package/src/shell/config.ts +32 -0
  179. package/src/shell/create.ts +9 -0
  180. package/src/{application/windowing/child-init.ts → shell/sandboxed/boot.ts} +10 -11
  181. package/src/shell/sandboxed/guarded.ts +32 -0
  182. package/src/shell/sandboxed/pending.ts +52 -0
  183. package/src/shell/sandboxed/sandboxed.ts +131 -0
  184. package/src/shell/shell.ts +37 -0
  185. package/src/shell/standalone.ts +97 -0
  186. package/src/{domain/window/config.ts → window/capabilities.ts} +2 -2
  187. package/src/{ports/shell-adapter.ts → window/embed/adapter.ts} +2 -1
  188. package/src/{adapters/iframe.shell-adapter.ts → window/embed/iframe.ts} +2 -2
  189. package/src/{application/windowing/lifecycle-controller.ts → window/lifecycle/states.ts} +3 -2
  190. package/src/{domain/window/lifecycle.ts → window/lifecycle/transition.ts} +2 -2
  191. package/src/window/mount/close.ts +111 -0
  192. package/src/window/mount/credential.ts +101 -0
  193. package/src/{application/windowing → window/mount}/handshake.ts +3 -2
  194. package/src/window/mount/mount.ts +185 -0
  195. package/src/window/mount/params.ts +64 -0
  196. package/src/window/mount/plain.ts +68 -0
  197. package/src/{domain/window → window}/window.ts +1 -1
  198. package/dist/adapters/iframe.shell-adapter.d.ts.map +0 -1
  199. package/dist/adapters/kernel-client.adapter.d.ts.map +0 -1
  200. package/dist/adapters/message-port.transport.d.ts.map +0 -1
  201. package/dist/application/channels/children-channel.d.ts.map +0 -1
  202. package/dist/application/channels/observer.d.ts.map +0 -1
  203. package/dist/application/channels/parent-channel.d.ts.map +0 -1
  204. package/dist/application/channels/types.d.ts +0 -12
  205. package/dist/application/channels/types.d.ts.map +0 -1
  206. package/dist/application/intent/pipeline-runner.d.ts.map +0 -1
  207. package/dist/application/intent/request.d.ts.map +0 -1
  208. package/dist/application/intent/router.d.ts +0 -56
  209. package/dist/application/intent/router.d.ts.map +0 -1
  210. package/dist/application/kernel-facade.d.ts +0 -33
  211. package/dist/application/kernel-facade.d.ts.map +0 -1
  212. package/dist/application/kernel-facade.js +0 -77
  213. package/dist/application/shell.d.ts +0 -100
  214. package/dist/application/shell.d.ts.map +0 -1
  215. package/dist/application/shell.js +0 -256
  216. package/dist/application/windowing/child-init.d.ts.map +0 -1
  217. package/dist/application/windowing/handshake.d.ts.map +0 -1
  218. package/dist/application/windowing/lifecycle-controller.d.ts.map +0 -1
  219. package/dist/application/windowing/mount-controller.d.ts.map +0 -1
  220. package/dist/application/windowing/mount-controller.js +0 -277
  221. package/dist/application/windowing/protocol.d.ts.map +0 -1
  222. package/dist/application/windowing/token-refresh.d.ts.map +0 -1
  223. package/dist/domain/identity/delegation.d.ts.map +0 -1
  224. package/dist/domain/identity/path.d.ts +0 -11
  225. package/dist/domain/identity/path.d.ts.map +0 -1
  226. package/dist/domain/identity/path.js +0 -13
  227. package/dist/domain/identity/resolve-self.d.ts +0 -21
  228. package/dist/domain/identity/resolve-self.d.ts.map +0 -1
  229. package/dist/domain/identity/resolve-self.js +0 -36
  230. package/dist/domain/intent/middleware/capabilities.d.ts.map +0 -1
  231. package/dist/domain/intent/middleware/logging.d.ts.map +0 -1
  232. package/dist/domain/intent/middleware/rate-limit.d.ts.map +0 -1
  233. package/dist/domain/intent/pipeline.d.ts +0 -3
  234. package/dist/domain/intent/pipeline.d.ts.map +0 -1
  235. package/dist/domain/intent/router.d.ts +0 -6
  236. package/dist/domain/intent/router.d.ts.map +0 -1
  237. package/dist/domain/message/errors.d.ts +0 -2
  238. package/dist/domain/message/errors.d.ts.map +0 -1
  239. package/dist/domain/message/registries.d.ts.map +0 -1
  240. package/dist/domain/message/types.d.ts +0 -30
  241. package/dist/domain/message/types.d.ts.map +0 -1
  242. package/dist/domain/window/config.d.ts.map +0 -1
  243. package/dist/domain/window/lifecycle.d.ts.map +0 -1
  244. package/dist/domain/window/window.d.ts.map +0 -1
  245. package/dist/ports/kernel-client.d.ts +0 -33
  246. package/dist/ports/kernel-client.d.ts.map +0 -1
  247. package/dist/ports/shell-adapter.d.ts.map +0 -1
  248. package/dist/ports/transport.d.ts +0 -7
  249. package/dist/ports/transport.d.ts.map +0 -1
  250. package/src/application/kernel-facade.ts +0 -143
  251. package/src/application/shell.ts +0 -433
  252. package/src/application/windowing/mount-controller.ts +0 -335
  253. package/src/domain/identity/path.ts +0 -14
  254. package/src/domain/identity/resolve-self.ts +0 -38
  255. package/src/domain/intent/pipeline.ts +0 -3
  256. package/src/domain/intent/router.ts +0 -6
  257. package/src/domain/message/registries.ts +0 -76
  258. package/src/domain/message/types.ts +0 -32
  259. package/src/ports/kernel-client.ts +0 -32
  260. /package/dist/{application/channels/children-channel.js → channel/children.js} +0 -0
  261. /package/dist/{application/channels/types.js → channel/listeners.js} +0 -0
  262. /package/dist/{adapters/message-port.transport.js → channel/message-port.js} +0 -0
  263. /package/dist/{application/channels → channel}/observer.js +0 -0
  264. /package/dist/{ports → channel}/transport.js +0 -0
  265. /package/dist/{domain/intent → intent}/middleware/capabilities.js +0 -0
  266. /package/dist/{domain/intent → intent}/middleware/logging.d.ts +0 -0
  267. /package/dist/{domain/intent → intent}/middleware/logging.js +0 -0
  268. /package/dist/{domain/intent → intent}/middleware/rate-limit.js +0 -0
  269. /package/dist/{application/intent/pipeline-runner.js → intent/pipeline.js} +0 -0
  270. /package/dist/{domain/intent/pipeline.js → kernel/client.js} +0 -0
  271. /package/dist/{domain/identity/delegation.js → kernel/delegation/token.js} +0 -0
  272. /package/dist/{domain/intent/router.js → message/ctrl.js} +0 -0
  273. /package/dist/{domain/message/errors.js → message/error.js} +0 -0
  274. /package/dist/{application/windowing/protocol.js → message/init.js} +0 -0
  275. /package/dist/{domain/message/registries.js → message/intent.js} +0 -0
  276. /package/dist/{domain/message/types.js → message/message.js} +0 -0
  277. /package/dist/{domain/window → shell}/config.js +0 -0
  278. /package/dist/{domain/window/window.js → shell/shell.js} +0 -0
  279. /package/dist/{ports/kernel-client.js → window/capabilities.js} +0 -0
  280. /package/dist/{ports/shell-adapter.js → window/embed/adapter.js} +0 -0
  281. /package/dist/{adapters/iframe.shell-adapter.js → window/embed/iframe.js} +0 -0
  282. /package/dist/{application/windowing → window/mount}/handshake.d.ts +0 -0
  283. /package/src/{domain/identity/delegation.ts → kernel/delegation/token.ts} +0 -0
  284. /package/src/{application/windowing/protocol.ts → message/init.ts} +0 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Astrale
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,18 @@
1
+ import type { BoundNode, DefOf, NodeRefInput } from '@astrale-os/kernel-client';
2
+ import type { KernelClient } from '../kernel/client';
3
+ import type { AppSession } from './session/session';
4
+ import type { ShellDomainView, ShellSchema } from './view';
5
+ /** An installed `Application` node. */
6
+ export type ApplicationNode = BoundNode<DefOf<ShellSchema, 'Application'>, ShellSchema>;
7
+ export interface AppsNamespace {
8
+ /** `Application.install(target, space)`, bound as the resulting `Application`. */
9
+ install(target: string, space: NodeRefInput): Promise<ApplicationNode>;
10
+ /** The apps installed in `space` (`installed_in` in-edges). */
11
+ in(space: NodeRefInput): Promise<ApplicationNode[]>;
12
+ /** Resolve the app node and open its {@link AppSession}. */
13
+ open(app: NodeRefInput): Promise<AppSession>;
14
+ }
15
+ export declare function createAppsNamespace(kernel: KernelClient, v: ShellDomainView, deps?: {
16
+ readonly now?: () => number;
17
+ }): AppsNamespace;
18
+ //# sourceMappingURL=apps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../src/application/apps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAK/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAI1D,uCAAuC;AACvC,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,EAAE,WAAW,CAAC,CAAA;AAEvF,MAAM,WAAW,aAAa;IAC5B,kFAAkF;IAClF,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACtE,+DAA+D;IAC/D,EAAE,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAA;IACnD,4DAA4D;IAC5D,IAAI,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CAC7C;AAKD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,CAAC,EAAE,eAAe,EAClB,IAAI,CAAC,EAAE;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAAE,GACrC,aAAa,CA6Bf"}
@@ -0,0 +1,35 @@
1
+ import { D } from '@astrale-domains/workspace-schema';
2
+ import { normalizeRef } from '@astrale-os/kernel-client';
3
+ import { openAppSession } from './session/open';
4
+ /** The `installed_in` edge class — traversed to list a space's apps. */
5
+ const INSTALLED_IN_EDGE = D.installed_in.path.class.raw;
6
+ export function createAppsNamespace(kernel, v, deps) {
7
+ return {
8
+ async install(target, space) {
9
+ const created = (await v
10
+ .view()('Application')
11
+ .install({
12
+ target,
13
+ space: normalizeRef(space),
14
+ }));
15
+ const app = await v.view().node('Application', `@${created.id}`);
16
+ if (!app)
17
+ throw new Error(`Application.install: app @${created.id} is not readable`);
18
+ return app;
19
+ },
20
+ async in(space) {
21
+ const page = await kernel.neighbors(normalizeRef(space), INSTALLED_IN_EDGE, 'in');
22
+ const nodes = await page.all();
23
+ return nodes.flatMap((n) => {
24
+ const app = v.bindAs('Application', n);
25
+ return app ? [app] : [];
26
+ });
27
+ },
28
+ async open(app) {
29
+ const node = await v.view().node('Application', app);
30
+ if (!node)
31
+ throw new Error(`apps.open: application ${normalizeRef(app)} is not readable`);
32
+ return openAppSession({ kernel, ...(deps?.now ? { now: deps.now } : {}) }, node.id);
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The OS-plane namespaces on the Shell — `shell.user` / `shell.spaces` /
3
+ * `shell.apps`. Framework-free: the shell-react hooks (§12.2) layer over
4
+ * exactly these. Pure closures over a lazy typed view — constructing this
5
+ * touches no kernel (safe before a sandboxed shell's `init()`).
6
+ */
7
+ import type { KernelClient } from '../kernel/client';
8
+ import type { AppsNamespace } from './apps';
9
+ import type { SpacesNamespace } from './spaces';
10
+ import type { UserNamespace } from './user';
11
+ export interface OsNamespaces {
12
+ readonly user: UserNamespace;
13
+ readonly spaces: SpacesNamespace;
14
+ readonly apps: AppsNamespace;
15
+ }
16
+ export interface CreateOsNamespacesDeps {
17
+ /** Injected clock, threaded into opened `AppSession`s (tests). */
18
+ readonly now?: () => number;
19
+ }
20
+ export declare function createOsNamespaces(kernel: KernelClient, deps?: CreateOsNamespacesDeps): OsNamespaces;
21
+ //# sourceMappingURL=namespaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespaces.d.ts","sourceRoot":"","sources":["../../src/application/namespaces.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAO3C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAA;CAC7B;AAED,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAC5B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,IAAI,CAAC,EAAE,sBAAsB,GAC5B,YAAY,CAOd"}
@@ -0,0 +1,12 @@
1
+ import { createAppsNamespace } from './apps';
2
+ import { createSpacesNamespace } from './spaces';
3
+ import { createUserNamespace } from './user';
4
+ import { createShellDomainView } from './view';
5
+ export function createOsNamespaces(kernel, deps) {
6
+ const v = createShellDomainView(kernel);
7
+ return {
8
+ user: createUserNamespace(kernel, v),
9
+ spaces: createSpacesNamespace(kernel, v),
10
+ apps: createAppsNamespace(kernel, v, deps),
11
+ };
12
+ }
@@ -0,0 +1,19 @@
1
+ import type { KernelClient } from '../../kernel/client';
2
+ import type { AppSession } from './session';
3
+ export interface OpenAppSessionDeps {
4
+ /** The shell kernel — dispatches AS THE USER, whose signature the delegate step needs. */
5
+ readonly kernel: KernelClient;
6
+ /** Injected clock (tests). */
7
+ readonly now?: () => number;
8
+ }
9
+ /**
10
+ * Open an app session: run `app::open` for the entry view + first recipe, then
11
+ * return an {@link AppSession}. The first token mints LAZILY — opening the view
12
+ * costs no token; `token()` (or `credential.refresh()`) runs the first
13
+ * delegate/getAccessToken cycle on demand. The {@link MountCredential} is driven
14
+ * by the mount machinery via `refresh` (no internal timer).
15
+ */
16
+ export declare function openAppSession(deps: OpenAppSessionDeps, app: {
17
+ id: string;
18
+ } | string): Promise<AppSession>;
19
+ //# sourceMappingURL=open.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/application/session/open.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,WAAW,CAAA;AAYpD,MAAM,WAAW,kBAAkB;IACjC,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAC5B;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,kBAAkB,EACxB,GAAG,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAC3B,OAAO,CAAC,UAAU,CAAC,CAuCrB"}
@@ -0,0 +1,46 @@
1
+ import { createTokenCycle } from './token';
2
+ /**
3
+ * Open an app session: run `app::open` for the entry view + first recipe, then
4
+ * return an {@link AppSession}. The first token mints LAZILY — opening the view
5
+ * costs no token; `token()` (or `credential.refresh()`) runs the first
6
+ * delegate/getAccessToken cycle on demand. The {@link MountCredential} is driven
7
+ * by the mount machinery via `refresh` (no internal timer).
8
+ */
9
+ export async function openAppSession(deps, app) {
10
+ const appId = typeof app === 'string' ? app : app.id;
11
+ const { kernel } = deps;
12
+ const now = deps.now ?? Date.now;
13
+ const opened = (await kernel.call(`@${appId}::open`, {}));
14
+ const tokens = createTokenCycle({ kernel, appId, initialRecipe: opened.delegation, now });
15
+ let disposed = false;
16
+ async function token() {
17
+ if (disposed)
18
+ throw new Error('AppSession is disposed');
19
+ if (tokens.needsRefresh())
20
+ return (await tokens.refresh()).token;
21
+ return tokens.current().token;
22
+ }
23
+ const credential = {
24
+ get token() {
25
+ return tokens.current()?.token ?? '';
26
+ },
27
+ get expiresAt() {
28
+ return tokens.current()?.expiresAt ?? 0;
29
+ },
30
+ refresh: async () => {
31
+ if (disposed)
32
+ throw new Error('AppSession is disposed');
33
+ const next = await tokens.refresh();
34
+ return { token: next.token, expiresAt: next.expiresAt };
35
+ },
36
+ };
37
+ return {
38
+ app: appId,
39
+ view: opened.view,
40
+ credential,
41
+ token,
42
+ dispose() {
43
+ disposed = true;
44
+ },
45
+ };
46
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `AppSession` — the client half of the three-call app-opening protocol
3
+ * (`app::open` → user-signed `auth.delegate` → `app::getAccessToken`). The
4
+ * server contract lives in the workspace domain's `Application` methods
5
+ * (`runtime/application/{open,get-access-token}`).
6
+ */
7
+ import type { MountCredential } from '../../window/mount/params';
8
+ /** The entry view returned by `app::open`, described for mounting. */
9
+ export interface AppView {
10
+ readonly id: string;
11
+ readonly path: string;
12
+ readonly url?: string;
13
+ readonly handshake?: string;
14
+ }
15
+ /**
16
+ * A live app session: the entry view (mount-ready), a mount-compatible
17
+ * credential, and an on-demand `token()`. `dispose()` is idempotent; after it,
18
+ * `token()` and `credential.refresh()` reject.
19
+ */
20
+ export interface AppSession {
21
+ /** The app node id this session speaks to. */
22
+ readonly app: string;
23
+ /** The entry view (from `app::open`), or `null` when the app pins none. */
24
+ readonly view: AppView | null;
25
+ /** Shell.mount-compatible credential — `token`/`expiresAt` track the live app token. */
26
+ readonly credential: MountCredential;
27
+ /** The current app token; refreshes when within the margin of expiry. Single-flight. */
28
+ token(): Promise<string>;
29
+ /** Idempotent teardown. */
30
+ dispose(): void;
31
+ }
32
+ /** Which protocol step a refresh cycle failed at — carried on {@link AppSessionRefreshError}. */
33
+ export type RefreshStep = 'delegate' | 'getAccessToken';
34
+ /** A refresh cycle that failed, naming the step; prior session state is preserved. */
35
+ export declare class AppSessionRefreshError extends Error {
36
+ readonly step: RefreshStep;
37
+ constructor(step: RefreshStep, app: string, options?: {
38
+ cause?: unknown;
39
+ });
40
+ }
41
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/application/session/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAEhE,sEAAsE;AACtE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;IAC7B,wFAAwF;IACxF,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAA;IACpC,wFAAwF;IACxF,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IACxB,2BAA2B;IAC3B,OAAO,IAAI,IAAI,CAAA;CAChB;AAED,iGAAiG;AACjG,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,gBAAgB,CAAA;AAEvD,sFAAsF;AACtF,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,YAAY,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIxE;CACF"}
@@ -0,0 +1,9 @@
1
+ /** A refresh cycle that failed, naming the step; prior session state is preserved. */
2
+ export class AppSessionRefreshError extends Error {
3
+ step;
4
+ constructor(step, app, options) {
5
+ super(`AppSession token refresh failed at '${step}' for @${app}`, options);
6
+ this.name = 'AppSessionRefreshError';
7
+ this.step = step;
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ import type { UnresolvedIdentityExpr } from '@astrale-os/kernel-core';
2
+ import type { KernelClient } from '../../kernel/client';
3
+ /** The current token, plus the recipe that mints its successor. */
4
+ export interface TokenSlot {
5
+ readonly token: string;
6
+ readonly expiresAt: number;
7
+ readonly recipe: UnresolvedIdentityExpr;
8
+ }
9
+ /** The app token's lifecycle: lazy first mint, single-flight refresh. */
10
+ export interface TokenCycle {
11
+ current(): TokenSlot | null;
12
+ needsRefresh(): boolean;
13
+ /** Advance the slot via one delegate → getAccessToken exchange. Single-flight. */
14
+ refresh(): Promise<TokenSlot>;
15
+ }
16
+ export declare function createTokenCycle(opts: {
17
+ /** The shell kernel — dispatches AS THE USER, whose signature the delegate step needs. */
18
+ kernel: KernelClient;
19
+ appId: string;
20
+ /** `app::open`'s first ready-to-mint recipe. */
21
+ initialRecipe: UnresolvedIdentityExpr;
22
+ now: () => number;
23
+ }): TokenCycle;
24
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/application/session/token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAcvD,mEAAmE;AACnE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAA;CACxC;AAED,yEAAyE;AACzE,MAAM,WAAW,UAAU;IACzB,OAAO,IAAI,SAAS,GAAG,IAAI,CAAA;IAC3B,YAAY,IAAI,OAAO,CAAA;IACvB,kFAAkF;IAClF,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;CAC9B;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,0FAA0F;IAC1F,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,gDAAgD;IAChD,aAAa,EAAE,sBAAsB,CAAA;IACrC,GAAG,EAAE,MAAM,MAAM,CAAA;CAClB,GAAG,UAAU,CAgDb"}
@@ -0,0 +1,51 @@
1
+ import { REFRESH_WINDOW_MS } from '../../kernel/delegation/token';
2
+ import { AppSessionRefreshError } from './session';
3
+ export function createTokenCycle(opts) {
4
+ const { kernel, appId, now } = opts;
5
+ let slot = null;
6
+ let inFlight = null;
7
+ // One delegate → getAccessToken exchange, minting the NEXT token from the last
8
+ // recipe. On failure `slot` is untouched (the throw carries the failed step).
9
+ async function cycle() {
10
+ const recipe = slot?.recipe ?? opts.initialRecipe;
11
+ let envelope;
12
+ try {
13
+ envelope = await kernel.auth.delegate({ delegation: recipe });
14
+ }
15
+ catch (cause) {
16
+ throw new AppSessionRefreshError('delegate', appId, { cause });
17
+ }
18
+ let access;
19
+ try {
20
+ access = (await kernel.call(`@${appId}::getAccessToken`, {
21
+ delegation: envelope,
22
+ }));
23
+ }
24
+ catch (cause) {
25
+ throw new AppSessionRefreshError('getAccessToken', appId, { cause });
26
+ }
27
+ return { token: access.credential, expiresAt: access.expiresAt, recipe: access.delegation };
28
+ }
29
+ // Single-flight: concurrent callers share one in-flight cycle; the slot is
30
+ // only advanced on success.
31
+ function refresh() {
32
+ if (inFlight)
33
+ return inFlight;
34
+ const run = cycle()
35
+ .then((next) => {
36
+ slot = next;
37
+ return next;
38
+ })
39
+ .finally(() => {
40
+ if (inFlight === run)
41
+ inFlight = null;
42
+ });
43
+ inFlight = run;
44
+ return run;
45
+ }
46
+ return {
47
+ current: () => slot,
48
+ needsRefresh: () => slot === null || slot.expiresAt - now() - REFRESH_WINDOW_MS <= 0,
49
+ refresh,
50
+ };
51
+ }
@@ -0,0 +1,17 @@
1
+ import type { BoundNode, DefOf, NodeRefInput } from '@astrale-os/kernel-client';
2
+ import type { KernelClient } from '../kernel/client';
3
+ import type { ShellDomainView, ShellSchema } from './view';
4
+ /** A workspace `Space` node. */
5
+ export type SpaceNode = BoundNode<DefOf<ShellSchema, 'Space'>, ShellSchema>;
6
+ export interface SpacesNamespace {
7
+ /** Children of the spaces directory — exactly the caller-readable spaces. */
8
+ list(): Promise<SpaceNode[]>;
9
+ /** One space by ref, or `null` when missing / masked / not a space. */
10
+ get(ref: NodeRefInput): Promise<SpaceNode | null>;
11
+ /** `Space.create` — creates the space (and selects it). */
12
+ create(opts?: {
13
+ name?: string;
14
+ }): Promise<SpaceNode>;
15
+ }
16
+ export declare function createSpacesNamespace(kernel: KernelClient, v: ShellDomainView): SpacesNamespace;
17
+ //# sourceMappingURL=spaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaces.d.ts","sourceRoot":"","sources":["../../src/application/spaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAI/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAE1D,gCAAgC;AAChC,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAA;AAE3E,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;IAC5B,uEAAuE;IACvE,GAAG,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IACjD,2DAA2D;IAC3D,MAAM,CAAC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;CACrD;AAKD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,eAAe,GAAG,eAAe,CA6B/F"}
@@ -0,0 +1,30 @@
1
+ import { normalizeRef } from '@astrale-os/kernel-client';
2
+ /** The spaces directory (mirrors the workspace domain's `SPACES_DIR`). */
3
+ const SPACES_DIR = '/spaces';
4
+ export function createSpacesNamespace(kernel, v) {
5
+ return {
6
+ async list() {
7
+ const page = await kernel.children(SPACES_DIR);
8
+ const nodes = await page.all();
9
+ return nodes.flatMap((n) => {
10
+ const space = v.bindAs('Space', n);
11
+ return space ? [space] : [];
12
+ });
13
+ },
14
+ async get(ref) {
15
+ const node = await kernel.get(normalizeRef(ref));
16
+ return node ? v.bindAs('Space', node) : null;
17
+ },
18
+ async create(opts) {
19
+ // `Space.create`'s params are all-optional, so the typed dispatch collapses
20
+ // to `(opts?)`; the runtime still forwards a params object (resolveCallArgs),
21
+ // so pass `{ name }` through a create-shaped view of the same thunk.
22
+ const create = v.view()('Space').create;
23
+ const created = await create(opts?.name !== undefined ? { name: opts.name } : undefined);
24
+ const space = await v.view().node('Space', `@${created.id}`);
25
+ if (!space)
26
+ throw new Error(`Space.create: created space @${created.id} is not readable`);
27
+ return space;
28
+ },
29
+ };
30
+ }
@@ -0,0 +1,20 @@
1
+ import type { BoundNode, DefOf, NodeRefInput } from '@astrale-os/kernel-client';
2
+ import type { KernelClient } from '../kernel/client';
3
+ import type { SpaceNode } from './spaces';
4
+ import type { ShellDomainView, ShellSchema } from './view';
5
+ /** Self as the shell-domain `User` — typed `firstName`/`lastName`/`email`. */
6
+ export type UserNode = BoundNode<DefOf<ShellSchema, 'User'>, ShellSchema>;
7
+ /** A `Role` a user holds. */
8
+ export type RoleNode = BoundNode<DefOf<ShellSchema, 'Role'>, ShellSchema>;
9
+ export interface UserNamespace {
10
+ /** `whoami`, bound as the shell-domain `User`. */
11
+ me(): Promise<UserNode>;
12
+ /** The `selected_space` edge target, or `null` when none is selected. */
13
+ currentSpace(): Promise<SpaceNode | null>;
14
+ /** `user::switchSpace` — validate + repoint the `selected_space` edge. Idempotent. */
15
+ switchSpace(ref: NodeRefInput): Promise<void>;
16
+ /** The `has_role` out-edges of self. */
17
+ roles(): Promise<RoleNode[]>;
18
+ }
19
+ export declare function createUserNamespace(kernel: KernelClient, v: ShellDomainView): UserNamespace;
20
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/application/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAI/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAI1D,8EAA8E;AAC9E,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,CAAA;AACzE,6BAA6B;AAC7B,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,CAAA;AAEzE,MAAM,WAAW,aAAa;IAC5B,kDAAkD;IAClD,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAA;IACvB,yEAAyE;IACzE,YAAY,IAAI,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IACzC,sFAAsF;IACtF,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7C,wCAAwC;IACxC,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;CAC7B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,eAAe,GAAG,aAAa,CA2B3F"}
@@ -0,0 +1,26 @@
1
+ import { normalizeRef } from '@astrale-os/kernel-client';
2
+ import { asArray } from './view';
3
+ export function createUserNamespace(kernel, v) {
4
+ async function me() {
5
+ return v.view().bind('User', await kernel.auth.whoami());
6
+ }
7
+ return {
8
+ me,
9
+ async currentSpace() {
10
+ const self = await me();
11
+ const first = asArray(await self.out('selected_space'))[0];
12
+ return first ? v.bindAs('Space', first.raw) : null;
13
+ },
14
+ async switchSpace(ref) {
15
+ const self = await me();
16
+ await self.call.switchSpace({ space: normalizeRef(ref) });
17
+ },
18
+ async roles() {
19
+ const self = await me();
20
+ return asArray(await self.out('has_role')).flatMap((r) => {
21
+ const role = v.bindAs('Role', r.raw);
22
+ return role ? [role] : [];
23
+ });
24
+ },
25
+ };
26
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The typed plane the OS namespaces speak: `kernel.withSchema(schema)` over the
3
+ * workspace domain (`@astrale-domains/workspace-schema`). The bound view is built LAZILY
4
+ * (first call) so the sandboxed shell's "init() first" kernel guard applies
5
+ * uniformly — constructing namespaces touches no kernel.
6
+ */
7
+ import type { BoundNode, DefOf, SchemaBoundView } from '@astrale-os/kernel-client';
8
+ import type { Node } from '@astrale-os/kernel-core';
9
+ import { schema } from '@astrale-domains/workspace-schema';
10
+ import type { KernelClient } from '../kernel/client';
11
+ export type ShellSchema = typeof schema;
12
+ export interface ShellDomainView {
13
+ view(): SchemaBoundView<ShellSchema>;
14
+ /** Bind `node` as `type` when its concrete class satisfies it, else `null`. */
15
+ bindAs<T extends 'User' | 'Space' | 'Application' | 'Role'>(type: T, node: Node): BoundNode<DefOf<ShellSchema, T>, ShellSchema> | null;
16
+ }
17
+ export declare function createShellDomainView(kernel: KernelClient): ShellDomainView;
18
+ /** Normalize a typed traversal result (single | array | null) to an array. */
19
+ export declare function asArray<T>(result: T | readonly T[] | null): T[];
20
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/application/view.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAClF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,MAAM,WAAW,GAAG,OAAO,MAAM,CAAA;AAEvC,MAAM,WAAW,eAAe;IAC9B,IAAI,IAAI,eAAe,CAAC,WAAW,CAAC,CAAA;IACpC,+EAA+E;IAC/E,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,MAAM,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,IAAI,GACT,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAI,CAAA;CACxD;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,eAAe,CAW3E;AAED,8EAA8E;AAC9E,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,CAG/D"}