@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
@@ -0,0 +1,60 @@
1
+ import type { BoundNode, DefOf, NodeRefInput } from '@astrale-os/kernel-client'
2
+
3
+ import { D } from '@astrale-domains/workspace-schema'
4
+ import { normalizeRef } from '@astrale-os/kernel-client'
5
+
6
+ import type { KernelClient } from '../kernel/client'
7
+ import type { AppSession } from './session/session'
8
+ import type { ShellDomainView, ShellSchema } from './view'
9
+
10
+ import { openAppSession } from './session/open'
11
+
12
+ /** An installed `Application` node. */
13
+ export type ApplicationNode = BoundNode<DefOf<ShellSchema, 'Application'>, ShellSchema>
14
+
15
+ export interface AppsNamespace {
16
+ /** `Application.install(target, space)`, bound as the resulting `Application`. */
17
+ install(target: string, space: NodeRefInput): Promise<ApplicationNode>
18
+ /** The apps installed in `space` (`installed_in` in-edges). */
19
+ in(space: NodeRefInput): Promise<ApplicationNode[]>
20
+ /** Resolve the app node and open its {@link AppSession}. */
21
+ open(app: NodeRefInput): Promise<AppSession>
22
+ }
23
+
24
+ /** The `installed_in` edge class — traversed to list a space's apps. */
25
+ const INSTALLED_IN_EDGE = D.installed_in.path.class.raw
26
+
27
+ export function createAppsNamespace(
28
+ kernel: KernelClient,
29
+ v: ShellDomainView,
30
+ deps?: { readonly now?: () => number },
31
+ ): AppsNamespace {
32
+ return {
33
+ async install(target, space) {
34
+ const created = (await v
35
+ .view()('Application')
36
+ .install({
37
+ target,
38
+ space: normalizeRef(space),
39
+ })) as { id: string }
40
+ const app = await v.view().node('Application', `@${created.id}`)
41
+ if (!app) throw new Error(`Application.install: app @${created.id} is not readable`)
42
+ return app
43
+ },
44
+
45
+ async in(space) {
46
+ const page = await kernel.neighbors(normalizeRef(space), INSTALLED_IN_EDGE, 'in')
47
+ const nodes = await page.all()
48
+ return nodes.flatMap((n) => {
49
+ const app = v.bindAs('Application', n)
50
+ return app ? [app] : []
51
+ })
52
+ },
53
+
54
+ async open(app) {
55
+ const node = await v.view().node('Application', app)
56
+ if (!node) throw new Error(`apps.open: application ${normalizeRef(app)} is not readable`)
57
+ return openAppSession({ kernel, ...(deps?.now ? { now: deps.now } : {}) }, node.id)
58
+ },
59
+ }
60
+ }
@@ -0,0 +1,38 @@
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
+
12
+ import { createAppsNamespace } from './apps'
13
+ import { createSpacesNamespace } from './spaces'
14
+ import { createUserNamespace } from './user'
15
+ import { createShellDomainView } from './view'
16
+
17
+ export interface OsNamespaces {
18
+ readonly user: UserNamespace
19
+ readonly spaces: SpacesNamespace
20
+ readonly apps: AppsNamespace
21
+ }
22
+
23
+ export interface CreateOsNamespacesDeps {
24
+ /** Injected clock, threaded into opened `AppSession`s (tests). */
25
+ readonly now?: () => number
26
+ }
27
+
28
+ export function createOsNamespaces(
29
+ kernel: KernelClient,
30
+ deps?: CreateOsNamespacesDeps,
31
+ ): OsNamespaces {
32
+ const v = createShellDomainView(kernel)
33
+ return {
34
+ user: createUserNamespace(kernel, v),
35
+ spaces: createSpacesNamespace(kernel, v),
36
+ apps: createAppsNamespace(kernel, v, deps),
37
+ }
38
+ }
@@ -0,0 +1,73 @@
1
+ import type { UnresolvedIdentityExpr } from '@astrale-os/kernel-core'
2
+
3
+ import type { KernelClient } from '../../kernel/client'
4
+ import type { MountCredential } from '../../window/mount/params'
5
+ import type { AppSession, AppView } from './session'
6
+
7
+ import { createTokenCycle } from './token'
8
+
9
+ /** The wire shape of `app::open`. */
10
+ interface OpenResult {
11
+ readonly view: AppView | null
12
+ readonly appCredential: string
13
+ readonly delegation: UnresolvedIdentityExpr
14
+ readonly expiresAt: number
15
+ }
16
+
17
+ export interface OpenAppSessionDeps {
18
+ /** The shell kernel — dispatches AS THE USER, whose signature the delegate step needs. */
19
+ readonly kernel: KernelClient
20
+ /** Injected clock (tests). */
21
+ readonly now?: () => number
22
+ }
23
+
24
+ /**
25
+ * Open an app session: run `app::open` for the entry view + first recipe, then
26
+ * return an {@link AppSession}. The first token mints LAZILY — opening the view
27
+ * costs no token; `token()` (or `credential.refresh()`) runs the first
28
+ * delegate/getAccessToken cycle on demand. The {@link MountCredential} is driven
29
+ * by the mount machinery via `refresh` (no internal timer).
30
+ */
31
+ export async function openAppSession(
32
+ deps: OpenAppSessionDeps,
33
+ app: { id: string } | string,
34
+ ): Promise<AppSession> {
35
+ const appId = typeof app === 'string' ? app : app.id
36
+ const { kernel } = deps
37
+ const now = deps.now ?? Date.now
38
+
39
+ const opened = (await kernel.call(`@${appId}::open`, {})) as OpenResult
40
+
41
+ const tokens = createTokenCycle({ kernel, appId, initialRecipe: opened.delegation, now })
42
+ let disposed = false
43
+
44
+ async function token(): Promise<string> {
45
+ if (disposed) throw new Error('AppSession is disposed')
46
+ if (tokens.needsRefresh()) return (await tokens.refresh()).token
47
+ return tokens.current()!.token
48
+ }
49
+
50
+ const credential: MountCredential = {
51
+ get token() {
52
+ return tokens.current()?.token ?? ''
53
+ },
54
+ get expiresAt() {
55
+ return tokens.current()?.expiresAt ?? 0
56
+ },
57
+ refresh: async () => {
58
+ if (disposed) throw new Error('AppSession is disposed')
59
+ const next = await tokens.refresh()
60
+ return { token: next.token, expiresAt: next.expiresAt }
61
+ },
62
+ }
63
+
64
+ return {
65
+ app: appId,
66
+ view: opened.view,
67
+ credential,
68
+ token,
69
+ dispose() {
70
+ disposed = true
71
+ },
72
+ }
73
+ }
@@ -0,0 +1,46 @@
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
+
9
+ /** The entry view returned by `app::open`, described for mounting. */
10
+ export interface AppView {
11
+ readonly id: string
12
+ readonly path: string
13
+ readonly url?: string
14
+ readonly handshake?: string
15
+ }
16
+
17
+ /**
18
+ * A live app session: the entry view (mount-ready), a mount-compatible
19
+ * credential, and an on-demand `token()`. `dispose()` is idempotent; after it,
20
+ * `token()` and `credential.refresh()` reject.
21
+ */
22
+ export interface AppSession {
23
+ /** The app node id this session speaks to. */
24
+ readonly app: string
25
+ /** The entry view (from `app::open`), or `null` when the app pins none. */
26
+ readonly view: AppView | null
27
+ /** Shell.mount-compatible credential — `token`/`expiresAt` track the live app token. */
28
+ readonly credential: MountCredential
29
+ /** The current app token; refreshes when within the margin of expiry. Single-flight. */
30
+ token(): Promise<string>
31
+ /** Idempotent teardown. */
32
+ dispose(): void
33
+ }
34
+
35
+ /** Which protocol step a refresh cycle failed at — carried on {@link AppSessionRefreshError}. */
36
+ export type RefreshStep = 'delegate' | 'getAccessToken'
37
+
38
+ /** A refresh cycle that failed, naming the step; prior session state is preserved. */
39
+ export class AppSessionRefreshError extends Error {
40
+ readonly step: RefreshStep
41
+ constructor(step: RefreshStep, app: string, options?: { cause?: unknown }) {
42
+ super(`AppSession token refresh failed at '${step}' for @${app}`, options)
43
+ this.name = 'AppSessionRefreshError'
44
+ this.step = step
45
+ }
46
+ }
@@ -0,0 +1,87 @@
1
+ import type { UnresolvedIdentityExpr } from '@astrale-os/kernel-core'
2
+
3
+ import type { KernelClient } from '../../kernel/client'
4
+
5
+ import { REFRESH_WINDOW_MS } from '../../kernel/delegation/token'
6
+ import { AppSessionRefreshError } from './session'
7
+
8
+ /** The wire shape of `app::getAccessToken`. */
9
+ interface AccessTokenResult {
10
+ readonly credential: string
11
+ readonly expiresAt: number
12
+ /** The next ready-to-mint recipe (re-armed with the fresh app credential). */
13
+ readonly delegation: UnresolvedIdentityExpr
14
+ readonly appCredential: string
15
+ }
16
+
17
+ /** The current token, plus the recipe that mints its successor. */
18
+ export interface TokenSlot {
19
+ readonly token: string
20
+ readonly expiresAt: number
21
+ readonly recipe: UnresolvedIdentityExpr
22
+ }
23
+
24
+ /** The app token's lifecycle: lazy first mint, single-flight refresh. */
25
+ export interface TokenCycle {
26
+ current(): TokenSlot | null
27
+ needsRefresh(): boolean
28
+ /** Advance the slot via one delegate → getAccessToken exchange. Single-flight. */
29
+ refresh(): Promise<TokenSlot>
30
+ }
31
+
32
+ export function createTokenCycle(opts: {
33
+ /** The shell kernel — dispatches AS THE USER, whose signature the delegate step needs. */
34
+ kernel: KernelClient
35
+ appId: string
36
+ /** `app::open`'s first ready-to-mint recipe. */
37
+ initialRecipe: UnresolvedIdentityExpr
38
+ now: () => number
39
+ }): TokenCycle {
40
+ const { kernel, appId, now } = opts
41
+
42
+ let slot: TokenSlot | null = null
43
+ let inFlight: Promise<TokenSlot> | null = null
44
+
45
+ // One delegate → getAccessToken exchange, minting the NEXT token from the last
46
+ // recipe. On failure `slot` is untouched (the throw carries the failed step).
47
+ async function cycle(): Promise<TokenSlot> {
48
+ const recipe = slot?.recipe ?? opts.initialRecipe
49
+ let envelope: string
50
+ try {
51
+ envelope = await kernel.auth.delegate({ delegation: recipe })
52
+ } catch (cause) {
53
+ throw new AppSessionRefreshError('delegate', appId, { cause })
54
+ }
55
+ let access: AccessTokenResult
56
+ try {
57
+ access = (await kernel.call(`@${appId}::getAccessToken`, {
58
+ delegation: envelope,
59
+ })) as AccessTokenResult
60
+ } catch (cause) {
61
+ throw new AppSessionRefreshError('getAccessToken', appId, { cause })
62
+ }
63
+ return { token: access.credential, expiresAt: access.expiresAt, recipe: access.delegation }
64
+ }
65
+
66
+ // Single-flight: concurrent callers share one in-flight cycle; the slot is
67
+ // only advanced on success.
68
+ function refresh(): Promise<TokenSlot> {
69
+ if (inFlight) return inFlight
70
+ const run = cycle()
71
+ .then((next) => {
72
+ slot = next
73
+ return next
74
+ })
75
+ .finally(() => {
76
+ if (inFlight === run) inFlight = null
77
+ })
78
+ inFlight = run
79
+ return run
80
+ }
81
+
82
+ return {
83
+ current: () => slot,
84
+ needsRefresh: () => slot === null || slot.expiresAt - now() - REFRESH_WINDOW_MS <= 0,
85
+ refresh,
86
+ }
87
+ }
@@ -0,0 +1,52 @@
1
+ import type { BoundNode, DefOf, NodeRefInput } from '@astrale-os/kernel-client'
2
+
3
+ import { normalizeRef } from '@astrale-os/kernel-client'
4
+
5
+ import type { KernelClient } from '../kernel/client'
6
+ import type { ShellDomainView, ShellSchema } from './view'
7
+
8
+ /** A workspace `Space` node. */
9
+ export type SpaceNode = BoundNode<DefOf<ShellSchema, 'Space'>, ShellSchema>
10
+
11
+ export interface SpacesNamespace {
12
+ /** Children of the spaces directory — exactly the caller-readable spaces. */
13
+ list(): Promise<SpaceNode[]>
14
+ /** One space by ref, or `null` when missing / masked / not a space. */
15
+ get(ref: NodeRefInput): Promise<SpaceNode | null>
16
+ /** `Space.create` — creates the space (and selects it). */
17
+ create(opts?: { name?: string }): Promise<SpaceNode>
18
+ }
19
+
20
+ /** The spaces directory (mirrors the workspace domain's `SPACES_DIR`). */
21
+ const SPACES_DIR = '/spaces'
22
+
23
+ export function createSpacesNamespace(kernel: KernelClient, v: ShellDomainView): SpacesNamespace {
24
+ return {
25
+ async list() {
26
+ const page = await kernel.children(SPACES_DIR)
27
+ const nodes = await page.all()
28
+ return nodes.flatMap((n) => {
29
+ const space = v.bindAs('Space', n)
30
+ return space ? [space] : []
31
+ })
32
+ },
33
+
34
+ async get(ref) {
35
+ const node = await kernel.get(normalizeRef(ref))
36
+ return node ? v.bindAs('Space', node) : null
37
+ },
38
+
39
+ async create(opts) {
40
+ // `Space.create`'s params are all-optional, so the typed dispatch collapses
41
+ // to `(opts?)`; the runtime still forwards a params object (resolveCallArgs),
42
+ // so pass `{ name }` through a create-shaped view of the same thunk.
43
+ const create = v.view()('Space').create as (params?: {
44
+ name?: string
45
+ }) => Promise<{ id: string }>
46
+ const created = await create(opts?.name !== undefined ? { name: opts.name } : undefined)
47
+ const space = await v.view().node('Space', `@${created.id}`)
48
+ if (!space) throw new Error(`Space.create: created space @${created.id} is not readable`)
49
+ return space
50
+ },
51
+ }
52
+ }
@@ -0,0 +1,54 @@
1
+ import type { BoundNode, DefOf, NodeRefInput } from '@astrale-os/kernel-client'
2
+
3
+ import { normalizeRef } from '@astrale-os/kernel-client'
4
+
5
+ import type { KernelClient } from '../kernel/client'
6
+ import type { SpaceNode } from './spaces'
7
+ import type { ShellDomainView, ShellSchema } from './view'
8
+
9
+ import { asArray } from './view'
10
+
11
+ /** Self as the shell-domain `User` — typed `firstName`/`lastName`/`email`. */
12
+ export type UserNode = BoundNode<DefOf<ShellSchema, 'User'>, ShellSchema>
13
+ /** A `Role` a user holds. */
14
+ export type RoleNode = BoundNode<DefOf<ShellSchema, 'Role'>, ShellSchema>
15
+
16
+ export interface UserNamespace {
17
+ /** `whoami`, bound as the shell-domain `User`. */
18
+ me(): Promise<UserNode>
19
+ /** The `selected_space` edge target, or `null` when none is selected. */
20
+ currentSpace(): Promise<SpaceNode | null>
21
+ /** `user::switchSpace` — validate + repoint the `selected_space` edge. Idempotent. */
22
+ switchSpace(ref: NodeRefInput): Promise<void>
23
+ /** The `has_role` out-edges of self. */
24
+ roles(): Promise<RoleNode[]>
25
+ }
26
+
27
+ export function createUserNamespace(kernel: KernelClient, v: ShellDomainView): UserNamespace {
28
+ async function me(): Promise<UserNode> {
29
+ return v.view().bind('User', await kernel.auth.whoami())
30
+ }
31
+
32
+ return {
33
+ me,
34
+
35
+ async currentSpace() {
36
+ const self = await me()
37
+ const first = asArray(await self.out('selected_space'))[0]
38
+ return first ? v.bindAs('Space', first.raw) : null
39
+ },
40
+
41
+ async switchSpace(ref) {
42
+ const self = await me()
43
+ await self.call.switchSpace({ space: normalizeRef(ref) })
44
+ },
45
+
46
+ async roles() {
47
+ const self = await me()
48
+ return asArray(await self.out('has_role')).flatMap((r) => {
49
+ const role = v.bindAs('Role', r.raw)
50
+ return role ? [role] : []
51
+ })
52
+ },
53
+ }
54
+ }
@@ -0,0 +1,42 @@
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
+
10
+ import { schema } from '@astrale-domains/workspace-schema'
11
+
12
+ import type { KernelClient } from '../kernel/client'
13
+
14
+ export type ShellSchema = typeof schema
15
+
16
+ export interface ShellDomainView {
17
+ view(): SchemaBoundView<ShellSchema>
18
+ /** Bind `node` as `type` when its concrete class satisfies it, else `null`. */
19
+ bindAs<T extends 'User' | 'Space' | 'Application' | 'Role'>(
20
+ type: T,
21
+ node: Node,
22
+ ): BoundNode<DefOf<ShellSchema, T>, ShellSchema> | null
23
+ }
24
+
25
+ export function createShellDomainView(kernel: KernelClient): ShellDomainView {
26
+ let bound: SchemaBoundView<ShellSchema> | null = null
27
+ const view = (): SchemaBoundView<ShellSchema> => (bound ??= kernel.withSchema(schema))
28
+
29
+ return {
30
+ view,
31
+ bindAs(type, node) {
32
+ const v = view()
33
+ return v.bindAny(node).is(type) ? v.bind(type, node) : null
34
+ },
35
+ }
36
+ }
37
+
38
+ /** Normalize a typed traversal result (single | array | null) to an array. */
39
+ export function asArray<T>(result: T | readonly T[] | null): T[] {
40
+ if (result === null) return []
41
+ return Array.isArray(result) ? [...result] : [result as T]
42
+ }
@@ -1,8 +1,8 @@
1
- import type { ShellMessage } from '../../domain/message/types'
2
- import type { Transport } from '../../ports/transport'
1
+ import type { MessageOf, MessageType, ShellMessage } from '../message/message'
3
2
  import type { MessageObserver } from './observer'
4
- import type { MessageOf, MessageType } from './types'
3
+ import type { Transport } from './transport'
5
4
 
5
+ /** Multiplexed channels down to child windows, keyed by windowId. */
6
6
  export interface ChildrenChannel {
7
7
  send(windowId: string, message: ShellMessage): void
8
8
  on<T extends MessageType>(
@@ -1,11 +1,6 @@
1
- import type { ShellMessage } from '../../domain/message/types'
2
-
3
- export type MessageHandler<M extends ShellMessage = ShellMessage> = (message: M) => void
4
-
5
- export type MessageType = ShellMessage['type']
6
-
7
- export type MessageOf<T extends MessageType> = Extract<ShellMessage, { type: T }>
1
+ import type { MessageHandler, MessageOf, MessageType, ShellMessage } from '../message/message'
8
2
 
3
+ /** Per-message-type listener registry — the fan-out primitive channels share. */
9
4
  export interface MessageListeners {
10
5
  on<T extends MessageType>(type: T, handler: MessageHandler<MessageOf<T>>): () => void
11
6
  dispatch(message: ShellMessage): void
@@ -1,5 +1,5 @@
1
- import type { ShellMessage } from '../domain/message/types'
2
- import type { Transport } from '../ports/transport'
1
+ import type { ShellMessage } from '../message/message'
2
+ import type { Transport } from './transport'
3
3
 
4
4
  export type MessagePortTransportConfig = {
5
5
  port: MessagePort
@@ -1,9 +1,10 @@
1
- import type { ShellMessage } from '../../domain/message/types'
1
+ import type { ShellMessage } from '../message/message'
2
2
 
3
3
  export type MessageDirection = 'inbound' | 'outbound'
4
4
 
5
5
  export type ObserverHandler = (message: ShellMessage, direction: MessageDirection) => void
6
6
 
7
+ /** Tap on every message crossing this shell, in both directions (`shell.onMessage`). */
7
8
  export interface MessageObserver {
8
9
  notify(direction: MessageDirection, message: ShellMessage): void
9
10
  subscribe(handler: ObserverHandler): () => void
@@ -1,10 +1,10 @@
1
- import type { ShellMessage } from '../../domain/message/types'
2
- import type { Transport } from '../../ports/transport'
1
+ import type { MessageHandler, MessageOf, MessageType, ShellMessage } from '../message/message'
3
2
  import type { MessageObserver } from './observer'
4
- import type { MessageHandler, MessageOf, MessageType } from './types'
3
+ import type { Transport } from './transport'
5
4
 
6
- import { createMessageListeners } from './types'
5
+ import { createMessageListeners } from './listeners'
7
6
 
7
+ /** The child's single channel up to its parent shell. */
8
8
  export interface ParentChannel {
9
9
  send(message: ShellMessage): void
10
10
  on<T extends MessageType>(type: T, handler: MessageHandler<MessageOf<T>>): () => void
@@ -1,5 +1,6 @@
1
- import type { ShellMessage } from '../domain/message/types'
1
+ import type { ShellMessage } from '../message/message'
2
2
 
3
+ /** The pipe a channel rides: one peer, ordered delivery, no reply semantics. */
3
4
  export interface Transport {
4
5
  send(message: ShellMessage): void
5
6
  onMessage(handler: (message: ShellMessage) => void): void