@mostra/runtime 0.10.0 → 0.12.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 (257) hide show
  1. package/dist/bin.js +4178 -310
  2. package/dist/bin.js.map +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/{instance-FExcyENK.js → instance-CBUlOmzG.js} +1892 -85
  6. package/dist/instance-CBUlOmzG.js.map +1 -0
  7. package/dist/reference/cli.md +1432 -0
  8. package/dist/reference/diagnostics.json +1579 -0
  9. package/dist/reference/errors/MOSTRA_A11Y_MINOR.md +23 -0
  10. package/dist/reference/errors/MOSTRA_A11Y_SERIOUS.md +23 -0
  11. package/dist/reference/errors/MOSTRA_ACTION_CANCELLED.md +23 -0
  12. package/dist/reference/errors/MOSTRA_ACTION_EVENT_INVALID.md +23 -0
  13. package/dist/reference/errors/MOSTRA_ACTION_EXPORT_INVALID.md +23 -0
  14. package/dist/reference/errors/MOSTRA_ACTION_INTERRUPTED.md +23 -0
  15. package/dist/reference/errors/MOSTRA_ACTION_PAUSED.md +23 -0
  16. package/dist/reference/errors/MOSTRA_ACTION_RUN_NOT_FOUND.md +23 -0
  17. package/dist/reference/errors/MOSTRA_ACTION_THREW.md +23 -0
  18. package/dist/reference/errors/MOSTRA_ACTION_TOO_LARGE.md +23 -0
  19. package/dist/reference/errors/MOSTRA_ACTION_UNKNOWN_FUNCTION.md +23 -0
  20. package/dist/reference/errors/MOSTRA_ACTION_UNSERIALIZABLE.md +23 -0
  21. package/dist/reference/errors/MOSTRA_ARTIFACT_BUNDLE_INVALID.md +23 -0
  22. package/dist/reference/errors/MOSTRA_ARTIFACT_DIR_NOT_EMPTY.md +23 -0
  23. package/dist/reference/errors/MOSTRA_ARTIFACT_ENTRY_AMBIGUOUS.md +23 -0
  24. package/dist/reference/errors/MOSTRA_ARTIFACT_ID_DROPPED.md +23 -0
  25. package/dist/reference/errors/MOSTRA_ARTIFACT_NOT_FOUND.md +23 -0
  26. package/dist/reference/errors/MOSTRA_ARTIFACT_NO_ENTRY.md +23 -0
  27. package/dist/reference/errors/MOSTRA_ARTIFACT_NO_PAGE.md +23 -0
  28. package/dist/reference/errors/MOSTRA_ARTIFACT_PATCH_REJECTED.md +23 -0
  29. package/dist/reference/errors/MOSTRA_ARTIFACT_PATH_INVALID.md +23 -0
  30. package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_MISSING.md +23 -0
  31. package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_UNREADABLE.md +23 -0
  32. package/dist/reference/errors/MOSTRA_ARTIFACT_TEMPLATE_UNKNOWN.md +23 -0
  33. package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_COLLECTED.md +23 -0
  34. package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_NOT_FOUND.md +23 -0
  35. package/dist/reference/errors/MOSTRA_BUILD_CRASHED.md +23 -0
  36. package/dist/reference/errors/MOSTRA_BUILD_FAILED.md +23 -0
  37. package/dist/reference/errors/MOSTRA_BUILD_TIMEOUT.md +23 -0
  38. package/dist/reference/errors/MOSTRA_BUILD_UNRESOLVED.md +23 -0
  39. package/dist/reference/errors/MOSTRA_CLI_CONFIG_UNWRITABLE.md +23 -0
  40. package/dist/reference/errors/MOSTRA_CLI_UNKNOWN_COMMAND.md +23 -0
  41. package/dist/reference/errors/MOSTRA_CLI_USAGE.md +23 -0
  42. package/dist/reference/errors/MOSTRA_CONSOLE_ERROR.md +23 -0
  43. package/dist/reference/errors/MOSTRA_CONSOLE_WARNING.md +23 -0
  44. package/dist/reference/errors/MOSTRA_DEP_INSTALL_FAILED.md +23 -0
  45. package/dist/reference/errors/MOSTRA_DEP_MISSING.md +23 -0
  46. package/dist/reference/errors/MOSTRA_DEP_NOT_FOUND.md +23 -0
  47. package/dist/reference/errors/MOSTRA_DEP_OFFLINE.md +23 -0
  48. package/dist/reference/errors/MOSTRA_DEP_SPEC_INVALID.md +23 -0
  49. package/dist/reference/errors/MOSTRA_DEP_TIMEOUT.md +23 -0
  50. package/dist/reference/errors/MOSTRA_DEP_WARM_CONFLICT.md +23 -0
  51. package/dist/reference/errors/MOSTRA_ENV_BIND_FAILED.md +23 -0
  52. package/dist/reference/errors/MOSTRA_ENV_BROWSER_MISSING.md +23 -0
  53. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_DOWNLOAD_FAILED.md +23 -0
  54. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_INVALID.md +23 -0
  55. package/dist/reference/errors/MOSTRA_ENV_BUNDLE_UNAVAILABLE.md +23 -0
  56. package/dist/reference/errors/MOSTRA_ENV_HELPER_MISSING.md +23 -0
  57. package/dist/reference/errors/MOSTRA_ENV_NODE_UNSUPPORTED.md +23 -0
  58. package/dist/reference/errors/MOSTRA_ENV_PORT_TAKEN.md +23 -0
  59. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_INSTALLING.md +23 -0
  60. package/dist/reference/errors/MOSTRA_ENV_RUNTIME_MISSING.md +23 -0
  61. package/dist/reference/errors/MOSTRA_ENV_SERVICE_FAILED.md +23 -0
  62. package/dist/reference/errors/MOSTRA_ENV_SHELL_MISSING.md +23 -0
  63. package/dist/reference/errors/MOSTRA_ENV_WARM_MISSING.md +23 -0
  64. package/dist/reference/errors/MOSTRA_FIELD_CONFLICT.md +23 -0
  65. package/dist/reference/errors/MOSTRA_FIELD_DUPLICATE_ID.md +23 -0
  66. package/dist/reference/errors/MOSTRA_FIELD_ID_INVALID.md +23 -0
  67. package/dist/reference/errors/MOSTRA_FIELD_ID_UNSTABLE.md +23 -0
  68. package/dist/reference/errors/MOSTRA_FIELD_MUTATION_ID_REUSED.md +23 -0
  69. package/dist/reference/errors/MOSTRA_FIELD_SHARED.md +23 -0
  70. package/dist/reference/errors/MOSTRA_FIELD_TOO_LARGE.md +23 -0
  71. package/dist/reference/errors/MOSTRA_FIELD_UNBOUND.md +23 -0
  72. package/dist/reference/errors/MOSTRA_HOME_DISK_FULL.md +23 -0
  73. package/dist/reference/errors/MOSTRA_HOME_GC_INCOMPLETE.md +23 -0
  74. package/dist/reference/errors/MOSTRA_HOME_GONE.md +23 -0
  75. package/dist/reference/errors/MOSTRA_HOME_INTEGRITY.md +23 -0
  76. package/dist/reference/errors/MOSTRA_HOME_LEDGER_UNREADABLE.md +23 -0
  77. package/dist/reference/errors/MOSTRA_HOME_LOCKED.md +23 -0
  78. package/dist/reference/errors/MOSTRA_HOME_MISMATCH.md +23 -0
  79. package/dist/reference/errors/MOSTRA_HOME_NETWORK_FILESYSTEM.md +23 -0
  80. package/dist/reference/errors/MOSTRA_HOME_NOT_ALWAYS_ON.md +23 -0
  81. package/dist/reference/errors/MOSTRA_HOME_NOT_OWNED.md +23 -0
  82. package/dist/reference/errors/MOSTRA_HOME_SOCKET_TOO_LONG.md +23 -0
  83. package/dist/reference/errors/MOSTRA_HOME_TOO_NEW.md +23 -0
  84. package/dist/reference/errors/MOSTRA_HOST_CONNECTION_CLOSED.md +23 -0
  85. package/dist/reference/errors/MOSTRA_HOST_CURSOR_COMPACTED.md +23 -0
  86. package/dist/reference/errors/MOSTRA_HOST_IDENTITY_UNAVAILABLE.md +23 -0
  87. package/dist/reference/errors/MOSTRA_HOST_INITIALIZE_ORDER.md +23 -0
  88. package/dist/reference/errors/MOSTRA_HOST_INTERNAL_ERROR.md +23 -0
  89. package/dist/reference/errors/MOSTRA_HOST_INVALID_PARAMS.md +23 -0
  90. package/dist/reference/errors/MOSTRA_HOST_MALFORMED.md +23 -0
  91. package/dist/reference/errors/MOSTRA_HOST_MESSAGE_TOO_LARGE.md +23 -0
  92. package/dist/reference/errors/MOSTRA_HOST_METHOD_UNKNOWN.md +23 -0
  93. package/dist/reference/errors/MOSTRA_HOST_NOTIFICATION_UNSUPPORTED.md +23 -0
  94. package/dist/reference/errors/MOSTRA_HOST_PORT_UNSUPPORTED.md +23 -0
  95. package/dist/reference/errors/MOSTRA_HOST_REQUEST_ID_REUSED.md +23 -0
  96. package/dist/reference/errors/MOSTRA_HOST_REVISION_UNSUPPORTED.md +23 -0
  97. package/dist/reference/errors/MOSTRA_HOST_SHUTDOWN_REFUSED.md +23 -0
  98. package/dist/reference/errors/MOSTRA_HOST_SUBSCRIPTION_UNKNOWN.md +23 -0
  99. package/dist/reference/errors/MOSTRA_HOST_TIMEOUT.md +23 -0
  100. package/dist/reference/errors/MOSTRA_HYGIENE_CONTENT_TYPE.md +23 -0
  101. package/dist/reference/errors/MOSTRA_HYGIENE_CSRF_MISSING.md +23 -0
  102. package/dist/reference/errors/MOSTRA_HYGIENE_FRAME_SESSION.md +23 -0
  103. package/dist/reference/errors/MOSTRA_HYGIENE_HEADERS_TOO_LARGE.md +23 -0
  104. package/dist/reference/errors/MOSTRA_HYGIENE_HOST_REFUSED.md +23 -0
  105. package/dist/reference/errors/MOSTRA_HYGIENE_NOT_SERVED.md +23 -0
  106. package/dist/reference/errors/MOSTRA_HYGIENE_ORIGIN_REFUSED.md +23 -0
  107. package/dist/reference/errors/MOSTRA_HYGIENE_RATE_LIMITED.md +23 -0
  108. package/dist/reference/errors/MOSTRA_HYGIENE_REQUEST_MALFORMED.md +23 -0
  109. package/dist/reference/errors/MOSTRA_HYGIENE_SCOPE_DENIED.md +23 -0
  110. package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_CONFLICT.md +23 -0
  111. package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_MISSING.md +23 -0
  112. package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_INVALID.md +23 -0
  113. package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_REVOKED.md +23 -0
  114. package/dist/reference/errors/MOSTRA_LIVE_SOURCE_FAILED.md +23 -0
  115. package/dist/reference/errors/MOSTRA_LIVE_TOO_LARGE.md +23 -0
  116. package/dist/reference/errors/MOSTRA_MANIFEST_INVALID.md +23 -0
  117. package/dist/reference/errors/MOSTRA_MANIFEST_NOT_LITERAL.md +23 -0
  118. package/dist/reference/errors/MOSTRA_MANIFEST_UNKNOWN_KEY.md +23 -0
  119. package/dist/reference/errors/MOSTRA_NETWORK_EXTERNAL_FAILED.md +23 -0
  120. package/dist/reference/errors/MOSTRA_NETWORK_REQUEST_FAILED.md +23 -0
  121. package/dist/reference/errors/MOSTRA_PLATFORM_UNSUPPORTED.md +23 -0
  122. package/dist/reference/errors/MOSTRA_PUBLISH_ID_CONFLICT.md +23 -0
  123. package/dist/reference/errors/MOSTRA_PUBLISH_SOURCE_CHANGED.md +23 -0
  124. package/dist/reference/errors/MOSTRA_PUBLISH_VERIFY_FAILED.md +23 -0
  125. package/dist/reference/errors/MOSTRA_REGRESSION_ACTION_REMOVED.md +23 -0
  126. package/dist/reference/errors/MOSTRA_REGRESSION_ARIA.md +23 -0
  127. package/dist/reference/errors/MOSTRA_REGRESSION_FIELD_REMOVED.md +23 -0
  128. package/dist/reference/errors/MOSTRA_REGRESSION_LIVE_REMOVED.md +23 -0
  129. package/dist/reference/errors/MOSTRA_REGRESSION_PAGE_REMOVED.md +23 -0
  130. package/dist/reference/errors/MOSTRA_REGRESSION_PIXELS.md +23 -0
  131. package/dist/reference/errors/MOSTRA_REMOTE_CONFIG_INVALID.md +23 -0
  132. package/dist/reference/errors/MOSTRA_REMOTE_HOME_MOVING.md +23 -0
  133. package/dist/reference/errors/MOSTRA_REMOTE_HOME_SUSPENDED.md +23 -0
  134. package/dist/reference/errors/MOSTRA_REMOTE_LIMIT_REACHED.md +23 -0
  135. package/dist/reference/errors/MOSTRA_REMOTE_LOGIN_FAILED.md +23 -0
  136. package/dist/reference/errors/MOSTRA_REMOTE_NOT_OWNER_INSTANCE.md +23 -0
  137. package/dist/reference/errors/MOSTRA_REMOTE_NO_INSTANCE.md +23 -0
  138. package/dist/reference/errors/MOSTRA_REMOTE_OPERATOR_UNAVAILABLE.md +23 -0
  139. package/dist/reference/errors/MOSTRA_REMOTE_OWNER_OFFLINE.md +23 -0
  140. package/dist/reference/errors/MOSTRA_REMOTE_PAUSED_BY_OPERATOR.md +23 -0
  141. package/dist/reference/errors/MOSTRA_REMOTE_QUEUE_FULL.md +23 -0
  142. package/dist/reference/errors/MOSTRA_REMOTE_RATE_LIMITED.md +23 -0
  143. package/dist/reference/errors/MOSTRA_REMOTE_SIGN_IN_REQUIRED.md +23 -0
  144. package/dist/reference/errors/MOSTRA_REMOTE_UNDER_REVIEW.md +23 -0
  145. package/dist/reference/errors/MOSTRA_REMOTE_UNREACHABLE.md +23 -0
  146. package/dist/reference/errors/MOSTRA_RUNTIME_BLANK.md +23 -0
  147. package/dist/reference/errors/MOSTRA_RUNTIME_NOT_READY.md +23 -0
  148. package/dist/reference/errors/MOSTRA_RUNTIME_PAGE_ERROR.md +23 -0
  149. package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_CRASHED.md +23 -0
  150. package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_PARKED.md +23 -0
  151. package/dist/reference/errors/MOSTRA_SECRET_MISSING.md +23 -0
  152. package/dist/reference/errors/MOSTRA_SHARE_NOT_ENABLED.md +23 -0
  153. package/dist/reference/errors/MOSTRA_SHARE_NOT_FOUND.md +23 -0
  154. package/dist/reference/errors/MOSTRA_SHARE_PORTS_EXHAUSTED.md +23 -0
  155. package/dist/reference/errors/MOSTRA_SHARE_TOOL_MISSING.md +23 -0
  156. package/dist/reference/errors/MOSTRA_SHARE_TOOL_NOT_READY.md +23 -0
  157. package/dist/reference/errors/MOSTRA_SHARE_TTL_INVALID.md +23 -0
  158. package/dist/reference/errors/MOSTRA_SHARE_TUNNEL_FAILED.md +23 -0
  159. package/dist/reference/errors/MOSTRA_SMOKE_BUDGET.md +23 -0
  160. package/dist/reference/errors/MOSTRA_SMOKE_NO_EFFECT.md +23 -0
  161. package/dist/reference/errors/MOSTRA_SUBMIT_ALREADY.md +23 -0
  162. package/dist/reference/errors/MOSTRA_SUBMIT_BLOCKED.md +23 -0
  163. package/dist/reference/errors/MOSTRA_SUBMIT_CHANNEL_DENIED.md +23 -0
  164. package/dist/reference/errors/MOSTRA_SUBMIT_NOT_FOUND.md +23 -0
  165. package/dist/reference/errors/MOSTRA_SUBMIT_PAUSED.md +23 -0
  166. package/dist/reference/errors/MOSTRA_SUBMIT_POLICY_NONE.md +23 -0
  167. package/dist/reference/errors/MOSTRA_SUBMIT_REVISION_MOVED.md +23 -0
  168. package/dist/reference/errors/MOSTRA_SUBMIT_SIGNAL_INVALID.md +23 -0
  169. package/dist/reference/errors/MOSTRA_SUBMIT_VIEW_INVALID.md +23 -0
  170. package/dist/reference/errors/MOSTRA_TARGET_UNAVAILABLE.md +23 -0
  171. package/dist/reference/errors/MOSTRA_TEAM_PRESENCE_RATE_LIMITED.md +23 -0
  172. package/dist/reference/errors/MOSTRA_TEAM_ROSTER_POLICY.md +23 -0
  173. package/dist/reference/errors/MOSTRA_TEAM_ROSTER_TOO_LARGE.md +23 -0
  174. package/dist/reference/errors/MOSTRA_TYPE_ERROR.md +23 -0
  175. package/dist/reference/errors/MOSTRA_TYPE_UNTYPED_PACKAGE.md +23 -0
  176. package/dist/reference/errors/MOSTRA_VERIFY_ACTION_SKIPPED.md +23 -0
  177. package/dist/reference/errors/MOSTRA_VERIFY_BASELINE_MISSING.md +23 -0
  178. package/dist/reference/errors/MOSTRA_VERIFY_CRASHED.md +23 -0
  179. package/dist/reference/errors/MOSTRA_VERIFY_LIVE_FAILED.md +23 -0
  180. package/dist/reference/errors/MOSTRA_VERIFY_NO_BASELINE.md +23 -0
  181. package/dist/reference/errors/MOSTRA_VERIFY_SECRET_MISSING.md +23 -0
  182. package/dist/reference/errors/MOSTRA_VERIFY_SKIP_CONSEQUENCE.md +23 -0
  183. package/dist/reference/errors/MOSTRA_VERIFY_TIMEOUT.md +23 -0
  184. package/dist/reference/self-hosting.md +130 -0
  185. package/dist/reference/telemetry.md +84 -0
  186. package/dist/skill/SKILL.md +124 -0
  187. package/dist/skill/assets/examples/dashboard/index.tsx +161 -0
  188. package/dist/skill/assets/examples/dashboard/live.ts +25 -0
  189. package/dist/skill/assets/examples/dashboard/styles.css +125 -0
  190. package/dist/skill/assets/examples/decision/index.tsx +95 -0
  191. package/dist/skill/assets/examples/decision/styles.css +125 -0
  192. package/dist/skill/assets/examples/inbox/actions.ts +23 -0
  193. package/dist/skill/assets/examples/inbox/index.tsx +109 -0
  194. package/dist/skill/assets/examples/inbox/styles.css +125 -0
  195. package/dist/skill/assets/studio.css +125 -0
  196. package/dist/skill/references/answers.md +219 -0
  197. package/dist/skill/references/design.md +154 -0
  198. package/dist/skill/references/libraries.md +167 -0
  199. package/dist/skill/references/long-lived.md +148 -0
  200. package/dist/skill/references/mcp.md +68 -0
  201. package/dist/skill/references/page.md +131 -0
  202. package/dist/skill/references/server.md +146 -0
  203. package/dist/skill/references/sharing.md +123 -0
  204. package/dist/skill/references/teams.md +78 -0
  205. package/dist/skill/references/verify.md +71 -0
  206. package/package.json +10 -5
  207. package/src/gateway/actions.ts +20 -0
  208. package/src/gateway/browser.ts +128 -1
  209. package/src/gateway/capabilities.ts +8 -0
  210. package/src/gateway/http.ts +12 -1
  211. package/src/gateway/index.ts +210 -6
  212. package/src/gateway/listener.ts +31 -6
  213. package/src/gateway/routes.ts +8 -0
  214. package/src/gateway/team.ts +181 -0
  215. package/src/gc/index.ts +5 -0
  216. package/src/instance/index.ts +22 -2
  217. package/src/interaction/ephemeral.ts +21 -0
  218. package/src/interaction/events.ts +17 -0
  219. package/src/interaction/index.ts +325 -20
  220. package/src/interaction/pause.ts +106 -0
  221. package/src/interaction/roster.ts +585 -0
  222. package/src/interaction/submissions.ts +42 -1
  223. package/src/interaction/team.ts +426 -0
  224. package/src/interaction/viewers.ts +34 -1
  225. package/src/interaction/wait.ts +150 -0
  226. package/src/ledger/index.ts +20 -1
  227. package/src/ledger/migrations.ts +86 -0
  228. package/src/link/author.ts +215 -0
  229. package/src/link/hosted.ts +51 -4
  230. package/src/link/http.ts +6 -1
  231. package/src/link/index.ts +3 -1
  232. package/src/link/manager.ts +169 -35
  233. package/src/protocol-server/client.ts +53 -0
  234. package/src/protocol-server/index.ts +1 -1
  235. package/src/server/api.ts +514 -72
  236. package/src/server/auth.ts +600 -74
  237. package/src/server/authorize.ts +816 -0
  238. package/src/server/clients.ts +235 -0
  239. package/src/server/config.ts +7 -0
  240. package/src/server/data.ts +59 -1
  241. package/src/server/directory.ts +91 -0
  242. package/src/server/feed.ts +277 -0
  243. package/src/server/handle.ts +172 -0
  244. package/src/server/hosted-pages.ts +532 -0
  245. package/src/server/hosted.ts +551 -18
  246. package/src/server/index.ts +353 -61
  247. package/src/server/mcp.ts +330 -0
  248. package/src/server/metering.ts +156 -0
  249. package/src/server/oauth-clients.ts +510 -0
  250. package/src/server/operator.ts +557 -0
  251. package/src/server/providers.ts +284 -0
  252. package/src/server/remove.ts +148 -0
  253. package/src/server/routing.ts +275 -0
  254. package/src/share/index.ts +50 -2
  255. package/src/verify/index.ts +7 -0
  256. package/src/verify/runner.ts +27 -2
  257. package/dist/instance-FExcyENK.js.map +0 -1
@@ -7,11 +7,15 @@
7
7
  import {
8
8
  BROWSER_PROTOCOL_REVISIONS,
9
9
  ChooseRequest,
10
+ createDiagnostic,
10
11
  type Diagnostic,
11
12
  type EphemeralMessage,
12
13
  type EventRecord,
13
14
  FieldsRequest,
14
15
  FollowRequest,
16
+ PresenceRequest,
17
+ type Refusal,
18
+ RespondentsRequest,
15
19
  RpcError,
16
20
  refusal,
17
21
  ShellSubmitRequest,
@@ -27,6 +31,7 @@ import {
27
31
  type Interaction,
28
32
  type PageIdentity,
29
33
  SubmitConflict,
34
+ type TeamTraffic,
30
35
  } from "../interaction/index.ts";
31
36
  import type { Log } from "../log.ts";
32
37
  import type { Capabilities } from "./capabilities.ts";
@@ -64,6 +69,10 @@ const STATUS: Readonly<Record<string, number>> = {
64
69
  MOSTRA_HOME_DISK_FULL: 507,
65
70
  MOSTRA_HOME_GONE: 503,
66
71
  MOSTRA_HYGIENE_SCOPE_DENIED: 403,
72
+ // A paused artifact takes no answers (D165 item 14).
73
+ MOSTRA_SUBMIT_PAUSED: 423,
74
+ // A page posting presence faster than its rate (D168).
75
+ MOSTRA_TEAM_PRESENCE_RATE_LIMITED: 429,
67
76
  };
68
77
 
69
78
  /** Options for {@link browserRoutes}. */
@@ -86,6 +95,19 @@ export interface BrowserRoutesOptions {
86
95
  * without an `id`, a poll as its `ephemeral` (LL-04). Absent: neither carries any.
87
96
  */
88
97
  readonly bus?: EphemeralBus;
98
+ /**
99
+ * Respondents and presence for pages (D168): absent, the `respondents` and `presence` routes
100
+ * answer that this gateway serves neither.
101
+ */
102
+ readonly team?: TeamTraffic;
103
+ /**
104
+ * Before a submit, from the frame or the shell (a remote server's, D165 item 13): a refusal (with
105
+ * when to try again) keeps the draft; nothing is recorded. Absent: every submit goes on.
106
+ */
107
+ readonly admitSubmit?: (
108
+ page: PageIdentity,
109
+ context: RouteContext,
110
+ ) => Promise<(Refusal & { readonly retryAfter?: number }) | undefined>;
89
111
  /** Tells a host with a `trustedControls` port that a trusted control was used (D108). */
90
112
  readonly activated: (event: {
91
113
  readonly artifactId: string;
@@ -109,6 +131,20 @@ function malformed(message: string): Response {
109
131
  return answer(refusal("MOSTRA_HYGIENE_REQUEST_MALFORMED", message).diagnostic, 400);
110
132
  }
111
133
 
134
+ /** What an ephemeral message's SSE `data` carries: the message's own payload, by its kind. */
135
+ function ephemeralData(message: EphemeralMessage): unknown {
136
+ switch (message.kind) {
137
+ case "run":
138
+ return message.run;
139
+ case "live":
140
+ return message.live;
141
+ case "respondents":
142
+ return message.respondents;
143
+ case "presence":
144
+ return message.presence;
145
+ }
146
+ }
147
+
112
148
  /** Turns an interaction refusal into its response; anything else is a defect for `onError`. */
113
149
  function failure(error: unknown): Response {
114
150
  if (error instanceof SubmitConflict) {
@@ -180,6 +216,10 @@ export interface BrowserRoutes {
180
216
  /** `events/poll` on the shell origin: the same, without the frame's run and live updates (#119). */
181
217
  readonly shellPoll: Handler;
182
218
  readonly shellSubmit: Handler;
219
+ /** The roster as the page may see it (D168, CO-03, CO-07). */
220
+ readonly respondents: Handler;
221
+ /** The page's presence (D168, CO-04). */
222
+ readonly presence: Handler;
183
223
  /** The shell's trusted Choose (D65, D113), on the shell origin. */
184
224
  readonly choose: Handler;
185
225
  /** "Always follow this artifact" (D63), on the shell origin. */
@@ -208,6 +248,35 @@ export function browserRoutes(options: BrowserRoutesOptions): BrowserRoutes {
208
248
  };
209
249
  };
210
250
 
251
+ /** The answer to a submit the server's rules refused before it reached the ledger. */
252
+ const admit = async (
253
+ context: RouteContext,
254
+ request: { readonly viewId: string; readonly expectedRevision: unknown },
255
+ ): Promise<Response | undefined> => {
256
+ if (!options.admitSubmit) return undefined;
257
+ // A repeat of a recorded submit answers that submission, and one a paused page or a view not
258
+ // the page's refuses is refused before anything is recorded: neither spends the submission
259
+ // rates or asks the operator (Fable review of WP-30, 8). The server's per-IP request rate
260
+ // still bounds them, as it bounds every request (`rateLimits.perIp.requests`).
261
+ const page = pageOf(context);
262
+ if (
263
+ !interaction.wouldRecord(page, {
264
+ viewId: request.viewId,
265
+ expectedRevision: Number(request.expectedRevision),
266
+ })
267
+ ) {
268
+ return undefined;
269
+ }
270
+ const refused = await options.admitSubmit(page, context);
271
+ if (!refused) return undefined;
272
+ return jsonResponse(refused.diagnostic, {
273
+ status: refused.status,
274
+ ...(refused.retryAfter !== undefined
275
+ ? { headers: { "retry-after": String(refused.retryAfter) } }
276
+ : {}),
277
+ });
278
+ };
279
+
211
280
  /** The view a stream or poll is for, checked against the page (D104). */
212
281
  const viewOf = (context: RouteContext, page: PageIdentity): Response | undefined => {
213
282
  const view = new URL(context.request.url).searchParams.get("view");
@@ -252,6 +321,8 @@ export function browserRoutes(options: BrowserRoutesOptions): BrowserRoutes {
252
321
  if (refused) return refused;
253
322
  const request = await body(context, SubmitRequest);
254
323
  if (request instanceof Response) return request;
324
+ const admitted = await admit(context, request);
325
+ if (admitted) return admitted;
255
326
  try {
256
327
  return jsonResponse(
257
328
  interaction.submit(pageOf(context), {
@@ -334,7 +405,7 @@ export function browserRoutes(options: BrowserRoutesOptions): BrowserRoutes {
334
405
  .splice(0)
335
406
  .map(
336
407
  (message) =>
337
- `event: ${message.kind}\ndata: ${JSON.stringify(message.kind === "run" ? message.run : message.live)}\n\n`,
408
+ `event: ${message.kind}\ndata: ${JSON.stringify(ephemeralData(message))}\n\n`,
338
409
  )
339
410
  .join("");
340
411
  const unlisten =
@@ -562,6 +633,8 @@ export function browserRoutes(options: BrowserRoutesOptions): BrowserRoutes {
562
633
  if (refused) return refused;
563
634
  const request = await body(context, ShellSubmitRequest);
564
635
  if (request instanceof Response) return request;
636
+ const admitted = await admit(context, request);
637
+ if (admitted) return admitted;
565
638
  const page = pageOf(context);
566
639
  let submission: SubmissionSummary & { readonly duplicate?: true };
567
640
  try {
@@ -660,6 +733,58 @@ export function browserRoutes(options: BrowserRoutesOptions): BrowserRoutes {
660
733
  }
661
734
  };
662
735
 
736
+ /** A handler of a team route without team traffic: this gateway serves neither (verify's). */
737
+ const noTeam = (): Response =>
738
+ answer(
739
+ refusal("MOSTRA_HYGIENE_NOT_SERVED", "This gateway serves no respondents or presence.", 404)
740
+ .diagnostic,
741
+ 404,
742
+ );
743
+
744
+ /** `respondents` (D168): the roster as the page may see it, followed for a minute. */
745
+ const respondents = async (context: RouteContext): Promise<Response> => {
746
+ const refused = knownRevision(context);
747
+ if (refused) return refused;
748
+ if (!options.team) return noTeam();
749
+ const request = await body(context, RespondentsRequest);
750
+ if (request instanceof Response) return request;
751
+ const page = pageOf(context);
752
+ try {
753
+ interaction.checkView(page, request.viewId);
754
+ return jsonResponse(options.team.respondents(page, request.viewId));
755
+ } catch (error) {
756
+ return failure(error);
757
+ }
758
+ };
759
+
760
+ /** `presence` (D168, CO-04): joins, shares or leaves; never stored. */
761
+ const presence = async (context: RouteContext): Promise<Response> => {
762
+ const refused = knownRevision(context);
763
+ if (refused) return refused;
764
+ if (!options.team) return noTeam();
765
+ const request = await body(context, PresenceRequest);
766
+ if (request instanceof Response) return request;
767
+ const page = pageOf(context);
768
+ try {
769
+ interaction.checkView(page, request.viewId);
770
+ } catch (error) {
771
+ return failure(error);
772
+ }
773
+ const outcome = options.team.presence(page, request);
774
+ if ("limited" in outcome) {
775
+ return jsonResponse(
776
+ createDiagnostic("MOSTRA_TEAM_PRESENCE_RATE_LIMITED", {
777
+ message: "This page sends presence faster than 20 updates a second.",
778
+ }),
779
+ {
780
+ status: 429,
781
+ headers: { "retry-after": String(Math.max(1, Math.ceil(outcome.retryAfterMs / 1000))) },
782
+ },
783
+ );
784
+ }
785
+ return jsonResponse(outcome.state);
786
+ };
787
+
663
788
  return {
664
789
  fields,
665
790
  submit,
@@ -667,6 +792,8 @@ export function browserRoutes(options: BrowserRoutesOptions): BrowserRoutes {
667
792
  stream,
668
793
  poll: pollFor(true),
669
794
  shellPoll: pollFor(false),
795
+ respondents,
796
+ presence,
670
797
  shellSubmit,
671
798
  choose,
672
799
  follow,
@@ -261,6 +261,11 @@ export interface CapabilitiesOptions {
261
261
  * face, a host's): a launch ticket is only minted for a link whose address is served.
262
262
  */
263
263
  readonly servesShell?: (origin: string) => boolean;
264
+ /**
265
+ * Told each token minted, after its row is written (a remote server indexes its hosted homes'
266
+ * links, so its operator's `revokeLink` finds a link's home, WP-30).
267
+ */
268
+ readonly onMinted?: (token: { readonly tokenId: string; readonly artifactId: string }) => void;
264
269
  }
265
270
 
266
271
  /** What a stream ticket opens (D158 item 5). */
@@ -274,6 +279,7 @@ export class Capabilities {
274
279
  readonly #now: () => number;
275
280
  readonly #shellOrigin: () => string;
276
281
  readonly #servesShell: (origin: string) => boolean;
282
+ readonly #onMinted: CapabilitiesOptions["onMinted"];
277
283
  /** Single-use stream and socket tickets (D158 item 5), by the SHA-256 of their secret. */
278
284
  readonly #streamTickets = new Map<
279
285
  string,
@@ -304,6 +310,7 @@ export class Capabilities {
304
310
  this.#now = options.now;
305
311
  this.#shellOrigin = options.shellOrigin;
306
312
  this.#servesShell = options.servesShell ?? ((origin) => origin === this.#shellOrigin());
313
+ this.#onMinted = options.onMinted;
307
314
  }
308
315
 
309
316
  /** Runs `fn` in the caller's transaction, or in a new one. */
@@ -359,6 +366,7 @@ export class Capabilities {
359
366
  input.pinnedVersion ?? null,
360
367
  shellOrigin,
361
368
  );
369
+ this.#onMinted?.({ tokenId, artifactId: input.artifactId });
362
370
  return {
363
371
  tokenId,
364
372
  secret,
@@ -29,6 +29,11 @@ export interface ListenerKind {
29
29
  readonly origin: string;
30
30
  /** The shell's origin: the only page that may frame an artifact (D98 item 4). */
31
31
  readonly shellOrigin: string;
32
+ /**
33
+ * The framers an artifact's documents name, when they are more than its shell: a hosted
34
+ * label's are the shells of its domain an operator also serves it under (INTERFACES §18.6).
35
+ */
36
+ readonly frameAncestors?: string;
32
37
  }
33
38
 
34
39
  /**
@@ -53,6 +58,10 @@ export function documentHeaders(
53
58
  "base-uri 'none'",
54
59
  "form-action 'none'",
55
60
  "object-src 'none'",
61
+ // No string reaches a script sink on the shell: every text a tenant or operator supplies
62
+ // renders as text, and a DOM-injection attempt throws (Trusted Types, HY-09).
63
+ "require-trusted-types-for 'script'",
64
+ "trusted-types 'none'",
56
65
  ].join("; "),
57
66
  "x-frame-options": "DENY",
58
67
  // Popups the artifact frame opens get no opener, so none can navigate this page (D98
@@ -60,7 +69,9 @@ export function documentHeaders(
60
69
  "cross-origin-opener-policy": "same-origin",
61
70
  };
62
71
  }
63
- return { "content-security-policy": `frame-ancestors ${listener.shellOrigin}` };
72
+ return {
73
+ "content-security-policy": `frame-ancestors ${listener.frameAncestors ?? listener.shellOrigin}`,
74
+ };
64
75
  }
65
76
 
66
77
  /** Every header of a request as `[name, value]` pairs, repeats kept. */
@@ -44,6 +44,7 @@ import {
44
44
  FRAME_SESSION_HEADER,
45
45
  type FrameSessionFacts,
46
46
  type FrameTicket,
47
+ type HostedChrome,
47
48
  type IdentityVia,
48
49
  type PortAddressingExternalBaseResult,
49
50
  type Refusal,
@@ -62,7 +63,7 @@ import {
62
63
  import type { Actions } from "../actions/index.ts";
63
64
  import { type Addressing, type FrameMode, hostOf } from "../addressing/index.ts";
64
65
  import { runtimeRoot } from "../deps/index.ts";
65
- import type { EphemeralBus, Interaction } from "../interaction/index.ts";
66
+ import { createTeamTraffic, type EphemeralBus, type Interaction } from "../interaction/index.ts";
66
67
  import {
67
68
  type Ledger,
68
69
  type LedgerDb,
@@ -97,14 +98,20 @@ import {
97
98
  import { type IdentityOutcome, tailnetPerson } from "./identity.ts";
98
99
  import { versionIntegrity } from "./integrity.ts";
99
100
  import { createListener, type Listener } from "./listener.ts";
101
+
102
+ export { resetOnClose } from "./listener.ts";
103
+
100
104
  import { type ListenerChecks, mount, type RouteContext, type RouteSpec, refuse } from "./routes.ts";
101
105
  import { fileResponse, findFile } from "./serve.ts";
106
+ import { rosterMethods } from "./team.ts";
102
107
  import { BOOTSTRAP_PAGE, SERVICE_WORKER_PATH, SERVICE_WORKER_SOURCE } from "./worker.ts";
103
108
 
104
109
  export { Capabilities, capabilityKey } from "./capabilities.ts";
105
110
  export { CONTROLS_POLICY_TIMEOUT_MS, controlsPolicy } from "./controls.ts";
106
111
  export type { DevUpstream } from "./dev.ts";
112
+ export { BASE_HEADERS, documentHeaders, isRefusal, jsonResponse, readJsonObject } from "./http.ts";
107
113
  export { IDENTITY_TIMEOUT_MS, resolveIdentity } from "./identity.ts";
114
+ export type { RouteContext, RouteSpec } from "./routes.ts";
108
115
 
109
116
  /** What the gateway reads about artifacts and versions. */
110
117
  export interface GatewayArtifacts {
@@ -221,6 +228,12 @@ export interface GatewayOptions {
221
228
  readonly live?: Pick<Live, "read">;
222
229
  /** Run and live updates for page streams and polls (WP-08). */
223
230
  readonly bus?: EphemeralBus;
231
+ /**
232
+ * Asks whether `count` new links may be minted for an artifact, throwing to refuse: a remote
233
+ * server's operator `limits` (`link`, D165 item 9). `roster/add` asks it for exactly the
234
+ * personal links it will mint (Opus review 10).
235
+ */
236
+ readonly linkLimit?: (artifactId: string, count: number) => Promise<void>;
224
237
  /** Whether a version's worker is parked (WP-08): its frame ticket tells the shell. */
225
238
  readonly parked?: (versionId: string) => boolean;
226
239
  /**
@@ -255,6 +268,59 @@ export interface HostedAddressing {
255
268
  readonly shellPath: (artifactId: string) => string;
256
269
  /** The origin of an artifact's frames beside a domain's shell: its route's label there. */
257
270
  readonly artifactOrigin: (artifactId: string, shellOrigin: string) => string | undefined;
271
+ /** The client's address of a request, through the server's trusted proxies (D165 item 13). */
272
+ readonly client?: (incoming: IncomingMessage) => string | undefined;
273
+ /**
274
+ * The shell origin a new link of an artifact is minted on (an operator's host for it, D167), or
275
+ * `undefined` for the active domain's apex.
276
+ */
277
+ readonly linkOrigin?: (artifactId: string) => Promise<string | undefined>;
278
+ /**
279
+ * The shells that may frame an artifact's documents at a frame origin: the apex of the domain the
280
+ * frame is served on, and the operator hosts that serve the route's shell with frames there
281
+ * (D167). Space-separated origins, for `frame-ancestors`.
282
+ */
283
+ readonly frameAncestors?: (artifactId: string, frameOrigin: string) => string;
284
+ /**
285
+ * Who a browser is that exchanges a link minted without a viewer (D165 item 8): an anonymous
286
+ * viewer per browser, by the route's derived key (`browser`), or a fresh one when the shell
287
+ * sent none. Sign-in turns a session's viewer into its account's later.
288
+ */
289
+ readonly anonymousViewer?: (browser: string | undefined) => string;
290
+ /**
291
+ * Before a view's frame ticket (WP-30): a quarantined route or version shows the neutral "under
292
+ * review" page, and the operator's `limits` may refuse a view. A refusal, or nothing.
293
+ */
294
+ readonly admitView?: (input: {
295
+ readonly artifactId: string;
296
+ readonly versionId: string;
297
+ readonly tokenId: string;
298
+ readonly client: string | undefined;
299
+ }) => Promise<(Refusal & { readonly retryAfter?: number }) | undefined>;
300
+ /** A version whose files are withheld now (a quarantine): refused even to an open frame. */
301
+ readonly blocked?: (artifactId: string, versionId: string) => Refusal | undefined;
302
+ /** The hosted shell's trusted chrome for a view (D161). */
303
+ readonly chrome?: (input: {
304
+ readonly artifactId: string;
305
+ readonly tokenId: string;
306
+ readonly viewerId: string;
307
+ }) => Promise<HostedChrome>;
308
+ /**
309
+ * Before a submit from the shell or the frame (D165 item 13): sign-in when the artifact asks for
310
+ * it, the per-IP and per-link rates, and the operator's `limits`. A refusal, or nothing.
311
+ */
312
+ readonly admitSubmit?: BrowserRoutesOptions["admitSubmit"];
313
+ /** Shell routes of a hosted home of its own (sign-in, the report control, a viewer's name). */
314
+ readonly shellRoutes?: (helpers: HostedRouteHelpers) => readonly RouteSpec[];
315
+ }
316
+
317
+ /** What a hosted home's own shell routes may use of the gateway. */
318
+ export interface HostedRouteHelpers {
319
+ /** Turns a refusal into the answer every route gives. */
320
+ readonly refuse: (
321
+ refused: Refusal & { readonly retryAfter?: number },
322
+ request: { readonly method: string; readonly path: string; readonly document: boolean },
323
+ ) => Response;
258
324
  }
259
325
 
260
326
  /** The gateway of one instance. */
@@ -436,6 +502,21 @@ function laterArtifactRoutes(
436
502
  auth: "session",
437
503
  ...(acting ? { handler: acting.live } : {}),
438
504
  },
505
+ // WP-31: the roster as the page may see it, and presence; every link may (`view`, D168).
506
+ {
507
+ method: "POST",
508
+ path: "/_mostra/v/:rev/respondents",
509
+ intent: "mutation",
510
+ auth: "session",
511
+ handler: served.respondents,
512
+ },
513
+ {
514
+ method: "POST",
515
+ path: "/_mostra/v/:rev/presence",
516
+ intent: "mutation",
517
+ auth: "session",
518
+ handler: served.presence,
519
+ },
439
520
  // WP-13: single-use tickets for streams, polls and WebSockets that bypass the worker (D70).
440
521
  {
441
522
  method: "POST",
@@ -474,7 +555,12 @@ interface FaceEntry {
474
555
  /** Creates the gateway; nothing is bound until {@link Gateway.start}. */
475
556
  export function createGateway(options: GatewayOptions): Gateway {
476
557
  const { addressing, capabilities, artifacts, log, interaction } = options;
558
+ // Respondents and presence for pages (D168): in memory, over the pages' ephemeral bus.
559
+ const team = options.bus
560
+ ? createTeamTraffic({ bus: options.bus, source: interaction, log })
561
+ : undefined;
477
562
  const served = browserRoutes({
563
+ ...(team ? { team } : {}),
478
564
  interaction,
479
565
  capabilities,
480
566
  log,
@@ -489,6 +575,7 @@ export function createGateway(options: GatewayOptions): Gateway {
489
575
  : undefined;
490
576
  },
491
577
  activated: options.activated,
578
+ ...(options.hosted?.admitSubmit ? { admitSubmit: options.hosted.admitSubmit } : {}),
492
579
  ...(options.revisions ? { revisions: options.revisions } : {}),
493
580
  ...(options.bus ? { bus: options.bus } : {}),
494
581
  });
@@ -888,6 +975,7 @@ export function createGateway(options: GatewayOptions): Gateway {
888
975
 
889
976
  /** Where an artifact's links point: a host's external base when it gives one, else loopback. */
890
977
  const linkBase = async (artifactId: string): Promise<string> => {
978
+ if (hosted?.linkOrigin) return (await hosted.linkOrigin(artifactId)) ?? shellOrigin();
891
979
  const face = await hostFace(artifactId, "shell");
892
980
  return face?.origin ?? shellOrigin();
893
981
  };
@@ -966,6 +1054,7 @@ export function createGateway(options: GatewayOptions): Gateway {
966
1054
  },
967
1055
  // The shell's own stream is refused where streams don't pass, as the frame's is (D158 item 5).
968
1056
  streams: () => way().streams(),
1057
+ ...(hosted?.client ? { client: hosted.client } : {}),
969
1058
  });
970
1059
 
971
1060
  const shellMissing = (): Response =>
@@ -1022,7 +1111,13 @@ export function createGateway(options: GatewayOptions): Gateway {
1022
1111
  const found = await artifactWayFor(way, group, context.artifactId).catch(() => undefined);
1023
1112
  frames = found && !isRefusal(found) ? (found.way.origin() ?? "'none'") : "'none'";
1024
1113
  }
1025
- const html = readFileSync(join(options.shellDir, "index.html"));
1114
+ const file = readFileSync(join(options.shellDir, "index.html"));
1115
+ // A hosted page's link preview is the same for every artifact (D161): an unfurl in a chat
1116
+ // app shows neither its title, text nor images unless its owner opted in to the title.
1117
+ const html =
1118
+ way.by === "hosted"
1119
+ ? hostedPreview(file.toString("utf8"), previewTitle(context.artifactId))
1120
+ : file;
1026
1121
  return new Response(context.request.method === "HEAD" ? null : html, {
1027
1122
  headers: {
1028
1123
  ...BASE_HEADERS,
@@ -1033,6 +1128,16 @@ export function createGateway(options: GatewayOptions): Gateway {
1033
1128
  });
1034
1129
  };
1035
1130
 
1131
+ /** The title a hosted page's preview may show: its own only when the manifest asks (D161). */
1132
+ const previewTitle = (artifactId: string): string | undefined => {
1133
+ try {
1134
+ const detail = artifacts.get({ artifactId });
1135
+ return detail.manifest.hosted?.preview === "title" ? detail.title : undefined;
1136
+ } catch {
1137
+ return undefined;
1138
+ }
1139
+ };
1140
+
1036
1141
  const shellAsset = async (context: RouteContext): Promise<Response> => {
1037
1142
  if (options.shellDir === undefined) return shellMissing();
1038
1143
  const url = new URL(context.request.url);
@@ -1056,8 +1161,16 @@ export function createGateway(options: GatewayOptions): Gateway {
1056
1161
  * 2): the home's local user on loopback; over a tunnel the tailnet person Tailscale Serve
1057
1162
  * named, else the link's own viewer, never the home's local user.
1058
1163
  */
1059
- const defaultViewer = (way: Way, context: RouteContext, grant: Grant): string | undefined => {
1164
+ const defaultViewer = (
1165
+ way: Way,
1166
+ context: RouteContext,
1167
+ grant: Grant,
1168
+ browser: string | undefined,
1169
+ ): string | undefined => {
1060
1170
  if (way.via === "local") return undefined;
1171
+ // On a remote server, one anonymous viewer per browser, by the route's own key (D165 item 8):
1172
+ // a public page answered by thousands needs one draft per person.
1173
+ if (way.by === "hosted" && hosted?.anonymousViewer) return hosted.anonymousViewer(browser);
1061
1174
  if (way.via === "tailnet") {
1062
1175
  const person = tailnetPerson(context.request.headers, context.remote);
1063
1176
  if (person) return interaction.viewerForTailnet(person);
@@ -1150,7 +1263,14 @@ export function createGateway(options: GatewayOptions): Gateway {
1150
1263
  viewerId =
1151
1264
  outcome.kind === "person"
1152
1265
  ? interaction.viewerForHost(outcome.viewer)
1153
- : defaultViewer(way, context, grant);
1266
+ : defaultViewer(
1267
+ way,
1268
+ context,
1269
+ grant,
1270
+ typeof body["browser"] === "string" && browser !== undefined
1271
+ ? body["browser"]
1272
+ : undefined,
1273
+ );
1154
1274
  }
1155
1275
  // Everything is judged again after the await, in one synchronous step with the session's
1156
1276
  // creation: a link revoked or expired meanwhile gets no session (Opus review of WP-12,
@@ -1278,6 +1398,17 @@ export function createGateway(options: GatewayOptions): Gateway {
1278
1398
  // A dev preview has no stored build to check: Vite serves the source (D140 item 12).
1279
1399
  const damage = options.dev ? undefined : await integrity.check(version.id);
1280
1400
  if (damage !== undefined) return damaged(version.number, damage, false, "'none'");
1401
+ // On a remote server: a quarantined route or version, or a view the operator's `limits`
1402
+ // refused, gets no frame; the shell shows why (WP-30).
1403
+ if (hosted?.admitView) {
1404
+ const refused = await hosted.admitView({
1405
+ artifactId,
1406
+ versionId: version.id,
1407
+ tokenId: session.grant.tokenId,
1408
+ client: context.client,
1409
+ });
1410
+ if (refused) return refuse(checks, refused, meta);
1411
+ }
1281
1412
  // The frame opens on the artifact's way in this shell's group: its loopback listener, or
1282
1413
  // the artifact's face at this address (D158 item 1), in the mode the pair needs (D70).
1283
1414
  const found = await artifactWayFor(way, group, artifactId);
@@ -1297,6 +1428,10 @@ export function createGateway(options: GatewayOptions): Gateway {
1297
1428
  // the channels and controls in force for it (D108).
1298
1429
  const controls = await options.controls(detail);
1299
1430
  const viewerId = interaction.viewerOf(session.viewerId);
1431
+ const pause = interaction.pauseOf(artifactId);
1432
+ const chrome = hosted?.chrome
1433
+ ? await hosted.chrome({ artifactId, tokenId: session.grant.tokenId, viewerId })
1434
+ : undefined;
1300
1435
  const viewId = interaction.openView({
1301
1436
  artifactId,
1302
1437
  versionId: version.id,
@@ -1331,6 +1466,15 @@ export function createGateway(options: GatewayOptions): Gateway {
1331
1466
  ...(options.parked?.(version.id) ? { serverParked: true as const } : {}),
1332
1467
  ...(options.dev ? { devPreview: true as const } : {}),
1333
1468
  ...(mode === "worker" ? { mode: "worker" as const } : {}),
1469
+ ...(pause
1470
+ ? {
1471
+ paused: {
1472
+ by: pause.by,
1473
+ ...(pause.reason !== undefined ? { reason: pause.reason } : {}),
1474
+ },
1475
+ }
1476
+ : {}),
1477
+ ...(chrome ? { hosted: chrome } : {}),
1334
1478
  };
1335
1479
  return jsonResponse(answer);
1336
1480
  };
@@ -1428,6 +1572,11 @@ export function createGateway(options: GatewayOptions): Gateway {
1428
1572
  auth: "session",
1429
1573
  scope: () => "review",
1430
1574
  },
1575
+ // A hosted home's own shell routes (sign-in, the report control, a viewer's name), behind
1576
+ // the same checks as every other route (D96).
1577
+ ...(hosted?.shellRoutes?.({
1578
+ refuse: (refused, request) => refuse(checks, refused, request),
1579
+ }) ?? []),
1431
1580
  ];
1432
1581
  };
1433
1582
 
@@ -1442,10 +1591,17 @@ export function createGateway(options: GatewayOptions): Gateway {
1442
1591
  capabilities,
1443
1592
  log,
1444
1593
  cookieName: () => `mostra-${wayOf().port()}`,
1445
- frameAncestors: () => shellOf(wayOf(), group)?.origin() ?? "'none'",
1594
+ frameAncestors: () => {
1595
+ const way = wayOf();
1596
+ if (way.by === "hosted" && hosted?.frameAncestors) {
1597
+ return hosted.frameAncestors(artifactId, way.origin() ?? "") || "'none'";
1598
+ }
1599
+ return shellOf(way, group)?.origin() ?? "'none'";
1600
+ },
1446
1601
  artifactOf: () => artifactId,
1447
1602
  mode: () => modeOf(wayOf(), group),
1448
1603
  streams: () => wayOf().streams(),
1604
+ ...(hosted?.client ? { client: hosted.client } : {}),
1449
1605
  });
1450
1606
 
1451
1607
  const artifactRoutes = (
@@ -1455,12 +1611,15 @@ export function createGateway(options: GatewayOptions): Gateway {
1455
1611
  ): RouteSpec[] => {
1456
1612
  const origin = (): string => wayOf().origin() ?? "";
1457
1613
  const shell = (): string => shellOf(wayOf(), group)?.origin() ?? "";
1614
+ const checks = artifactChecks(artifactId, wayOf, group);
1458
1615
  const kind = (): ListenerKind => ({
1459
1616
  kind: "artifact",
1460
1617
  origin: origin(),
1461
1618
  shellOrigin: shell(),
1619
+ // A hosted label's documents name exactly the framers its refusals do: its domain's shell,
1620
+ // and the outside hosts an operator serves its shell on (D165 item 7, Opus review of WP-28).
1621
+ ...(wayOf().by === "hosted" ? { frameAncestors: checks.frameAncestors() } : {}),
1462
1622
  });
1463
- const checks = artifactChecks(artifactId, wayOf, group);
1464
1623
  const mode = (): FrameMode => modeOf(wayOf(), group);
1465
1624
  const notServed = (context: RouteContext, message: string): Response =>
1466
1625
  refuse(checks, refusal("MOSTRA_HYGIENE_NOT_SERVED", message), {
@@ -1739,6 +1898,9 @@ export function createGateway(options: GatewayOptions): Gateway {
1739
1898
  // again whenever a file changed since (FAILURE_MODEL §3).
1740
1899
  const checked =
1741
1900
  file ?? (context.document ? await findFile(root(versionId), "/index.html") : undefined);
1901
+ // A quarantined version's files are withheld even from a frame that entered it before.
1902
+ const withheld = hosted?.blocked?.(artifactId, from);
1903
+ if (withheld) return refuse(checks, withheld, meta);
1742
1904
  if (checked) {
1743
1905
  const damage = await integrity.serve(from, checked);
1744
1906
  if (damage !== undefined) {
@@ -2045,6 +2207,17 @@ export function createGateway(options: GatewayOptions): Gateway {
2045
2207
  by: entry.spec.by,
2046
2208
  })),
2047
2209
  methods: () => [
2210
+ ...rosterMethods({
2211
+ ledger: options.ledger,
2212
+ interaction,
2213
+ capabilities,
2214
+ artifacts,
2215
+ versionOf,
2216
+ linkBase,
2217
+ link,
2218
+ collected: (number) => new RpcError(collectedDiagnostic(number)),
2219
+ ...(options.linkLimit ? { linkLimit: options.linkLimit } : {}),
2220
+ }),
2048
2221
  handler(viewUrlMethod, async (params) => {
2049
2222
  const detail = artifacts.get(params.artifact);
2050
2223
  const version = versionOf(detail, params.version);
@@ -2151,6 +2324,7 @@ export function createGateway(options: GatewayOptions): Gateway {
2151
2324
  ]),
2152
2325
  ),
2153
2326
  async close() {
2327
+ team?.close();
2154
2328
  await Promise.allSettled([...opening.values(), ...openingFaces.values()]);
2155
2329
  await Promise.all([
2156
2330
  shellListener?.close(),
@@ -2218,3 +2392,33 @@ export function locateShell(env: Environment): string | undefined {
2218
2392
  const dir = env["MOSTRA_SHELL_DIR"] ?? resolve(runtimeRoot(), "..", "shell", "dist");
2219
2393
  return existsSync(join(dir, "index.html")) ? dir : undefined;
2220
2394
  }
2395
+
2396
+ /** The generic preview of every hosted page (D161): one title, one description, no image. */
2397
+ export const HOSTED_PREVIEW = {
2398
+ title: "A page sent with Mostra",
2399
+ description: "Someone sent you this page. Open it to see it.",
2400
+ } as const;
2401
+
2402
+ /** Text for an HTML attribute or element: nothing a tenant writes is ever markup. */
2403
+ function previewText(text: string): string {
2404
+ return text.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`);
2405
+ }
2406
+
2407
+ /**
2408
+ * The hosted shell's page with its link preview (D161): the generic title and description, or
2409
+ * the artifact's title alone when its manifest asks (`hosted.preview: "title"`), never its text or
2410
+ * images, and `noindex`.
2411
+ */
2412
+ function hostedPreview(html: string, title: string | undefined): string {
2413
+ const shown = previewText(title ?? HOSTED_PREVIEW.title);
2414
+ const description = previewText(HOSTED_PREVIEW.description);
2415
+ const tags = [
2416
+ `<meta name="robots" content="noindex, nofollow">`,
2417
+ `<meta name="description" content="${description}">`,
2418
+ `<meta property="og:title" content="${shown}">`,
2419
+ `<meta property="og:description" content="${description}">`,
2420
+ `<meta property="og:site_name" content="Mostra">`,
2421
+ `<meta name="twitter:card" content="summary">`,
2422
+ ].join("\n ");
2423
+ return html.replace(/<title>[^<]*<\/title>/, `<title>${shown}</title>\n ${tags}`);
2424
+ }