@gjermundgaraba/effect-actions 0.22.0 → 0.24.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 (276) hide show
  1. package/README.md +9 -3
  2. package/dist/Action.d.mts +2 -2
  3. package/dist/Action.mjs +1 -0
  4. package/dist/ActionCli.d.mts +1 -1
  5. package/dist/ActionCli.mjs +1 -2
  6. package/dist/ActionHttp.d.mts +2 -2
  7. package/dist/ActionMcp.d.mts +20 -20
  8. package/dist/ActionMcp.mjs +9 -11
  9. package/dist/ActionRpc.d.mts +8 -15
  10. package/dist/ActionRpc.mjs +29 -54
  11. package/dist/ActionToolkit.d.mts +0 -2
  12. package/dist/ActionToolkit.mjs +0 -2
  13. package/dist/Event.d.mts +0 -23
  14. package/dist/Testing.mjs +3 -2
  15. package/dist/Webhook.mjs +2 -2
  16. package/dist/authentication/refusal.mjs +0 -1
  17. package/dist/cli/commands.mjs +0 -5
  18. package/dist/contract/authorizer.mjs +0 -5
  19. package/dist/contract/call.mjs +0 -23
  20. package/dist/contract/callback.mjs +0 -1
  21. package/dist/contract/caller.mjs +0 -11
  22. package/dist/contract/canonical.mjs +0 -5
  23. package/dist/contract/codec.d.mts +0 -1
  24. package/dist/contract/codec.mjs +0 -1
  25. package/dist/contract/codes.mjs +1 -15
  26. package/dist/contract/declared.mjs +0 -15
  27. package/dist/contract/digest.mjs +0 -1
  28. package/dist/contract/errors.d.mts +0 -4
  29. package/dist/contract/errors.mjs +0 -4
  30. package/dist/contract/feed.d.mts +0 -1
  31. package/dist/contract/feed.mjs +0 -20
  32. package/dist/contract/hints.mjs +0 -6
  33. package/dist/contract/hub.mjs +0 -3
  34. package/dist/contract/idempotency.mjs +0 -4
  35. package/dist/contract/implementation.d.mts +0 -1
  36. package/dist/contract/implementation.mjs +0 -27
  37. package/dist/contract/input-check.mjs +0 -1
  38. package/dist/contract/lease.mjs +0 -1
  39. package/dist/contract/listed.mjs +0 -6
  40. package/dist/contract/log.mjs +0 -8
  41. package/dist/contract/names.mjs +0 -1
  42. package/dist/contract/occurrence.mjs +0 -8
  43. package/dist/contract/pages.mjs +5 -12
  44. package/dist/contract/progress.mjs +2 -25
  45. package/dist/contract/push.d.mts +0 -5
  46. package/dist/contract/push.mjs +1 -24
  47. package/dist/contract/receiving.mjs +0 -7
  48. package/dist/contract/reported.mjs +0 -5
  49. package/dist/contract/serving.mjs +0 -18
  50. package/dist/contract/status.mjs +0 -3
  51. package/dist/contract/stream.mjs +0 -2
  52. package/dist/contract/subscribe.d.mts +0 -2
  53. package/dist/contract/subscribe.mjs +0 -8
  54. package/dist/contract/transient.mjs +0 -12
  55. package/dist/contract/watch.mjs +5 -17
  56. package/dist/contract/webhooks.mjs +0 -11
  57. package/dist/http/client.mjs +0 -1
  58. package/dist/http/events.d.mts +0 -10
  59. package/dist/http/events.mjs +2 -31
  60. package/dist/http/placed.d.mts +0 -2
  61. package/dist/http/streamed.d.mts +0 -1
  62. package/dist/http/streamed.mjs +4 -32
  63. package/dist/http/watch.mjs +0 -6
  64. package/dist/mcp/bridge.mjs +1 -26
  65. package/dist/mcp/client.d.mts +0 -1
  66. package/dist/mcp/client.mjs +0 -1
  67. package/dist/mcp/events.mjs +0 -6
  68. package/dist/mcp/progress.mjs +0 -7
  69. package/dist/mcp/protocol.mjs +0 -6
  70. package/dist/mcp/reply.mjs +0 -11
  71. package/dist/mcp/request.mjs +0 -1
  72. package/dist/mcp/watch.mjs +0 -6
  73. package/dist/rpc/watch.mjs +0 -6
  74. package/dist/stdio/console.mjs +2 -2
  75. package/dist/webhook/address.mjs +4 -9
  76. package/dist/webhook/attempt.mjs +2 -15
  77. package/dist/webhook/receiver.mjs +2 -8
  78. package/dist/webhook/signing.mjs +0 -3
  79. package/dist/webhook/stored.mjs +8 -17
  80. package/dist/webhook/subscriptions.mjs +19 -23
  81. package/docs/Action-streams.md +0 -12
  82. package/docs/Action.md +0 -10
  83. package/docs/ActionCli.md +2 -26
  84. package/docs/ActionHttp-failures.md +1 -1
  85. package/docs/ActionHttp.md +0 -28
  86. package/docs/ActionMcp-failures.md +2 -1
  87. package/docs/ActionMcp.md +2 -37
  88. package/docs/ActionRpc-events.md +0 -16
  89. package/docs/ActionRpc.md +0 -63
  90. package/docs/ActionToolkit.md +0 -11
  91. package/docs/Authentication-advanced.md +0 -31
  92. package/docs/Authentication.md +4 -13
  93. package/docs/Event.md +0 -37
  94. package/docs/README.md +1 -1
  95. package/docs/Testing-failures.md +1 -1
  96. package/docs/Testing.md +3 -13
  97. package/docs/Webhook.md +0 -46
  98. package/docs/setup-failures.md +1 -1
  99. package/docs/setup.md +5 -10
  100. package/examples/README.md +7 -1
  101. package/examples/assistant/src/agent.ts +8 -31
  102. package/examples/assistant/src/cli.ts +2 -9
  103. package/examples/assistant/src/commands.ts +0 -8
  104. package/examples/assistant/src/identity/Identity.ts +0 -10
  105. package/examples/assistant/src/identity/authorize.ts +0 -4
  106. package/examples/assistant/src/identity/members.ts +1 -3
  107. package/examples/assistant/src/identity/permissions.ts +0 -5
  108. package/examples/assistant/src/platform/tasks-file.ts +1 -6
  109. package/examples/assistant/src/scripted.ts +0 -4
  110. package/examples/assistant/src/tasks/Tasks.ts +0 -2
  111. package/examples/assistant/src/tasks/handlers.ts +0 -3
  112. package/examples/assistant/src/tasks/store.ts +0 -7
  113. package/examples/assistant/src/toolkit.ts +0 -11
  114. package/examples/assistant/test/commands.test.ts +0 -5
  115. package/examples/assistant/test/identity/identity.test.ts +6 -6
  116. package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
  117. package/examples/assistant/test/tasks/tasks.test.ts +13 -14
  118. package/examples/assistant/test/toolkit.test.ts +7 -18
  119. package/examples/build-events/README.md +2 -0
  120. package/examples/build-events/src/Api.ts +0 -3
  121. package/examples/build-events/src/Rpc.ts +0 -2
  122. package/examples/build-events/src/builds/Builds.ts +0 -15
  123. package/examples/build-events/src/builds/events.ts +0 -10
  124. package/examples/build-events/src/builds/handlers.ts +0 -6
  125. package/examples/build-events/src/builds/log.ts +0 -6
  126. package/examples/build-events/src/builds/status.ts +0 -4
  127. package/examples/build-events/src/builds/store.ts +0 -21
  128. package/examples/build-events/src/cli.ts +0 -2
  129. package/examples/build-events/src/commands.ts +0 -9
  130. package/examples/build-events/src/deploys/approvers.ts +0 -3
  131. package/examples/build-events/src/deploys/events.ts +0 -8
  132. package/examples/build-events/src/deploys/handlers.ts +0 -2
  133. package/examples/build-events/src/identity/Identity.ts +0 -11
  134. package/examples/build-events/src/identity/members.ts +1 -2
  135. package/examples/build-events/src/identity/verifier.ts +8 -9
  136. package/examples/build-events/src/notifier/Notices.ts +0 -3
  137. package/examples/build-events/src/notifier/routes.ts +0 -10
  138. package/examples/build-events/src/notifier.ts +0 -8
  139. package/examples/build-events/src/routes.ts +0 -24
  140. package/examples/build-events/src/server.ts +0 -14
  141. package/examples/build-events/test/builds/events.test.ts +0 -6
  142. package/examples/build-events/test/builds/log.test.ts +0 -1
  143. package/examples/build-events/test/builds/progress.test.ts +0 -1
  144. package/examples/build-events/test/commands.test.ts +0 -5
  145. package/examples/build-events/test/deploys/events.test.ts +0 -1
  146. package/examples/build-events/test/http.test.ts +0 -4
  147. package/examples/build-events/test/notifier.test.ts +0 -9
  148. package/examples/build-events/test/routes.test.ts +0 -9
  149. package/examples/build-events/test/rpc.test.ts +0 -4
  150. package/examples/build-events/test/support/as.ts +3 -4
  151. package/examples/build-events/test/support/memory.ts +0 -5
  152. package/examples/build-events/test/webhooks.test.ts +0 -12
  153. package/examples/kitchen-sink/README.md +1 -1
  154. package/examples/kitchen-sink/src/Actions.ts +0 -10
  155. package/examples/kitchen-sink/src/Api.ts +0 -8
  156. package/examples/kitchen-sink/src/Rpc.ts +0 -4
  157. package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
  158. package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
  159. package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
  160. package/examples/kitchen-sink/src/admin/grants.ts +0 -5
  161. package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
  162. package/examples/kitchen-sink/src/admin/keys.ts +1 -3
  163. package/examples/kitchen-sink/src/agent.ts +2 -13
  164. package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
  165. package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
  166. package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
  167. package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
  168. package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
  169. package/examples/kitchen-sink/src/attachments/download.ts +0 -10
  170. package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
  171. package/examples/kitchen-sink/src/attachments/store.ts +0 -3
  172. package/examples/kitchen-sink/src/browser.ts +0 -9
  173. package/examples/kitchen-sink/src/cli.ts +0 -19
  174. package/examples/kitchen-sink/src/config.ts +3 -11
  175. package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
  176. package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
  177. package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
  178. package/examples/kitchen-sink/src/identity/directory.ts +8 -18
  179. package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
  180. package/examples/kitchen-sink/src/identity/members.ts +1 -5
  181. package/examples/kitchen-sink/src/identity/quota.ts +0 -11
  182. package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
  183. package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
  184. package/examples/kitchen-sink/src/issues/events.ts +2 -16
  185. package/examples/kitchen-sink/src/issues/export.ts +0 -5
  186. package/examples/kitchen-sink/src/issues/guide.ts +0 -5
  187. package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
  188. package/examples/kitchen-sink/src/issues/store.ts +19 -23
  189. package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
  190. package/examples/kitchen-sink/src/memory.ts +0 -9
  191. package/examples/kitchen-sink/src/ops.ts +0 -6
  192. package/examples/kitchen-sink/src/request-policy.ts +0 -17
  193. package/examples/kitchen-sink/src/routes.ts +0 -48
  194. package/examples/kitchen-sink/src/sdk.ts +0 -12
  195. package/examples/kitchen-sink/src/seed.ts +0 -10
  196. package/examples/kitchen-sink/src/server.ts +0 -22
  197. package/examples/kitchen-sink/src/stdio.ts +2 -12
  198. package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
  199. package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
  200. package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
  201. package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
  202. package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
  203. package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
  204. package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
  205. package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
  206. package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
  207. package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
  208. package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
  209. package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
  210. package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
  211. package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
  212. package/examples/kitchen-sink/test/routes.test.ts +0 -6
  213. package/examples/kitchen-sink/test/support/as.ts +3 -5
  214. package/examples/kitchen-sink/test/support/scripted.ts +0 -3
  215. package/examples/kitchen-sink/test/support/services.ts +0 -3
  216. package/examples/live-rpc/src/Rpc.ts +0 -4
  217. package/examples/live-rpc/src/browser.ts +0 -24
  218. package/examples/live-rpc/src/chat/Chat.ts +0 -22
  219. package/examples/live-rpc/src/chat/authorize.ts +0 -3
  220. package/examples/live-rpc/src/chat/events.ts +0 -14
  221. package/examples/live-rpc/src/chat/handlers.ts +0 -5
  222. package/examples/live-rpc/src/chat/room.ts +0 -6
  223. package/examples/live-rpc/src/chat/store.ts +0 -9
  224. package/examples/live-rpc/src/client.ts +0 -6
  225. package/examples/live-rpc/src/identity/Identity.ts +0 -6
  226. package/examples/live-rpc/src/identity/members.ts +1 -3
  227. package/examples/live-rpc/src/identity/verifier.ts +6 -12
  228. package/examples/live-rpc/src/page.ts +0 -10
  229. package/examples/live-rpc/src/routes.ts +0 -13
  230. package/examples/live-rpc/src/server.ts +0 -16
  231. package/examples/live-rpc/test/browser.test.ts +0 -9
  232. package/examples/live-rpc/test/chat/chat.test.ts +3 -11
  233. package/examples/live-rpc/test/routes.test.ts +0 -8
  234. package/examples/live-rpc/test/server.test.ts +0 -13
  235. package/examples/mcp-tools/src/instructions.ts +0 -4
  236. package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
  237. package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
  238. package/examples/mcp-tools/src/printers/Printers.ts +0 -21
  239. package/examples/mcp-tools/src/printers/farm.ts +0 -5
  240. package/examples/mcp-tools/src/printers/handlers.ts +0 -6
  241. package/examples/mcp-tools/src/routes.ts +0 -11
  242. package/examples/mcp-tools/src/server.ts +0 -9
  243. package/examples/mcp-tools/src/stdio.ts +1 -13
  244. package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
  245. package/examples/mcp-tools/test/routes.test.ts +0 -14
  246. package/examples/notes-service/src/Api.ts +0 -4
  247. package/examples/notes-service/src/browser.ts +0 -12
  248. package/examples/notes-service/src/cli.ts +0 -2
  249. package/examples/notes-service/src/commands.ts +0 -30
  250. package/examples/notes-service/src/identity/Identity.ts +0 -2
  251. package/examples/notes-service/src/identity/authorize.ts +0 -4
  252. package/examples/notes-service/src/identity/users.ts +1 -3
  253. package/examples/notes-service/src/identity/verifier.ts +4 -11
  254. package/examples/notes-service/src/notes/Notes.ts +0 -12
  255. package/examples/notes-service/src/notes/handlers.ts +0 -4
  256. package/examples/notes-service/src/notes/store.ts +62 -48
  257. package/examples/notes-service/src/routes.ts +0 -12
  258. package/examples/notes-service/src/server.ts +0 -6
  259. package/examples/notes-service/src/status/Status.ts +0 -1
  260. package/examples/notes-service/src/status/handlers.ts +0 -1
  261. package/examples/notes-service/src/stdio.ts +2 -12
  262. package/examples/notes-service/src/worker.ts +0 -7
  263. package/examples/notes-service/test/commands.test.ts +0 -20
  264. package/examples/notes-service/test/notes/as.ts +3 -4
  265. package/examples/notes-service/test/notes/in-process.test.ts +3 -6
  266. package/examples/notes-service/test/notes/notes.test.ts +0 -6
  267. package/examples/notes-service/test/routes.test.ts +0 -5
  268. package/examples/notes-service/test/worker.test.ts +0 -1
  269. package/examples/quickstart/src/Api.ts +0 -1
  270. package/examples/quickstart/src/client.ts +0 -3
  271. package/examples/quickstart/src/greeting/Greeting.ts +0 -2
  272. package/examples/quickstart/src/greeting/handlers.ts +0 -1
  273. package/examples/quickstart/src/routes.ts +0 -1
  274. package/examples/quickstart/src/server.ts +3 -6
  275. package/examples/quickstart/test/routes.test.ts +0 -1
  276. package/package.json +6 -6
@@ -15,9 +15,6 @@ import { publicRoutes } from "../../src/routes.js";
15
15
  import { down, scripted } from "../support/scripted.js";
16
16
  import { services } from "../support/services.js";
17
17
 
18
- // The assistant as its callers reach it: over HTTP, a request per turn, on the real routes in
19
- // memory. Each test gives the routes the model it is about, in place of the demo one: the
20
- // first `Layer.provide` is what the routes get.
21
18
  const served = (model: Layer.Layer<LanguageModel.LanguageModel>) =>
22
19
  Effect.provide(
23
20
  Testing.layer(publicRoutes).pipe(
@@ -35,7 +32,6 @@ const signedIn = (token: string) => ({
35
32
  ),
36
33
  });
37
34
 
38
- // Ada may write in acme. Linus, in the same workspace, may only read.
39
35
  const asAda = ActionHttp.client(Http, signedIn("ada"));
40
36
 
41
37
  const asLinus = ActionHttp.client(Http, signedIn("linus"));
@@ -63,7 +59,6 @@ describe("the assistant, behind a route", () => {
63
59
  body: "On save.",
64
60
  });
65
61
 
66
- // One request, two requests to the model: the second lets it read its tool's result.
67
62
  const read = yield* ada.askAssistant({ prompt: "What is open?" });
68
63
 
69
64
  expect(read).toMatchObject({
@@ -72,7 +67,6 @@ describe("the assistant, behind a route", () => {
72
67
  waiting: [],
73
68
  });
74
69
 
75
- // The same conversation, a request later. The write has not run: the turn ended on it.
76
70
  const asked = yield* ada.askAssistant({
77
71
  conversation: read.conversation,
78
72
  prompt: "Close it.",
@@ -153,8 +147,6 @@ describe("the assistant, behind a route", () => {
153
147
  body: "On save.",
154
148
  });
155
149
 
156
- // Anyone signed in may ask. The tool's own `authorize` then refuses the reader's write,
157
- // as a result the model reads.
158
150
  const asked = yield* linus.askAssistant({ prompt: "Close it." });
159
151
 
160
152
  const answered = yield* linus.answerAssistant({
@@ -195,13 +187,11 @@ describe("the assistant, behind a route", () => {
195
187
  answers: approving(asked.waiting),
196
188
  });
197
189
 
198
- // The approved call ran, then the model failed: the error says so.
199
190
  expect(yield* Effect.flip(answer)).toBeInstanceOf(AssistantFailed);
200
191
  expect((yield* ada.getIssue({ id })).comments).toStrictEqual([
201
192
  { author: "ada", text: "Fixed." },
202
193
  ]);
203
194
 
204
- // The same answer, sent again, runs nothing: its conversation is gone.
205
195
  expect(yield* Effect.flip(answer)).toStrictEqual(
206
196
  new ConversationNotFound({ conversation: asked.conversation })
207
197
  );
@@ -310,7 +300,6 @@ describe("the assistant, behind a route", () => {
310
300
  answers: first === undefined ? [] : [first],
311
301
  });
312
302
 
313
- // The call left open is listed again, in every turn until it is answered.
314
303
  expect(answered).toMatchObject({ ran: [{ tool: "commentOnIssue" }] });
315
304
  expect(answered.waiting).toStrictEqual([
316
305
  {
@@ -373,7 +362,6 @@ describe("the assistant, behind a route", () => {
373
362
  answers: close === undefined ? [] : [close],
374
363
  });
375
364
 
376
- // Each answer runs its own call: the close ran, the comment still waits.
377
365
  expect(closed.ran).toStrictEqual([
378
366
  { tool: "closeIssue", failed: false },
379
367
  ]);
@@ -393,8 +381,6 @@ describe("the assistant, behind a route", () => {
393
381
  )
394
382
  );
395
383
 
396
- // A provider gives each call an id of its own. Where a model does not, Effect runs the last
397
- // call with the id an approval names: the list shows that call, not the one first asked.
398
384
  it.effect(
399
385
  "lists, for a call id a model used twice, the call an approval would run",
400
386
  () =>
@@ -541,8 +527,6 @@ describe("the assistant, behind a route", () => {
541
527
  })
542
528
  );
543
529
 
544
- // A double click, or a client's retry. One turn runs at a time, and the one that waited
545
- // finds its conversation ended by the one that failed.
546
530
  const refusals = yield* Effect.all([answer, answer], {
547
531
  concurrency: 2,
548
532
  });
@@ -566,7 +550,6 @@ describe("the assistant, behind a route", () => {
566
550
  it.effect(
567
551
  "ends the conversation of a turn that is interrupted after its approved call ran",
568
552
  () => {
569
- // Completed when the model is asked what to say about the approved call's result.
570
553
  const thinking = Deferred.makeUnsafe<undefined>();
571
554
 
572
555
  return Effect.gen(function* () {
@@ -584,7 +567,6 @@ describe("the assistant, behind a route", () => {
584
567
  answers: approving(asked.waiting),
585
568
  });
586
569
 
587
- // The client goes away while the model is thinking, after the approved call ran.
588
570
  const leaving = yield* Effect.forkChild(answer);
589
571
 
590
572
  yield* Deferred.await(thinking);
@@ -26,7 +26,6 @@ const as = (token: string, workspace: string) => ({
26
26
  transformClient: HttpClient.mapRequest(signedIn(token, workspace)),
27
27
  });
28
28
 
29
- // A one-pixel PNG stands in for a screenshot.
30
29
  const screenshot = Buffer.from(
31
30
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
32
31
  "base64"
@@ -58,15 +57,12 @@ describe("attachments, over HTTP and MCP", () => {
58
57
  size: 68,
59
58
  });
60
59
 
61
- // Both clients decode the same success, the bytes a `Uint8Array` again.
62
60
  const overHttp = yield* http.getAttachment({ id: attachment.id });
63
61
  const overMcp = yield* mcp.getAttachment({ id: attachment.id });
64
62
 
65
63
  expect(Buffer.from(overHttp.image.data).equals(screenshot)).toBe(true);
66
64
  expect(overMcp).toStrictEqual(overHttp);
67
65
 
68
- // As sent: the tool's result holds the rest of the success as JSON, and the image as a
69
- // content block of its own, which a model receives as an image.
70
66
  const call = yield* HttpClient.execute(
71
67
  ActionMcp.request(
72
68
  "tools/call",
@@ -112,7 +108,6 @@ describe("attachments, over HTTP and MCP", () => {
112
108
  const attachment = yield* attached;
113
109
  const ada = yield* ActionHttp.client(Http, as("ada", "acme"));
114
110
 
115
- // `attached` spent two writes, an issue and its image. Eight comments spend the rest.
116
111
  yield* Effect.forEach(Array.range(1, 8), (n) =>
117
112
  ada.commentOnIssue({ id: attachment.issue, text: `Comment ${n}` })
118
113
  );
@@ -155,7 +150,6 @@ describe("attachments, over HTTP and MCP", () => {
155
150
  expect(mine.headers["cache-control"]).toBe(
156
151
  "private, max-age=31536000, immutable"
157
152
  );
158
- // An uploaded image opened by its URL is a document on this origin: it gets no scripts.
159
153
  expect([
160
154
  mine.headers["content-security-policy"],
161
155
  mine.headers["x-content-type-options"],
@@ -184,15 +178,12 @@ describe("attachments, over HTTP and MCP", () => {
184
178
 
185
179
  const withoutScope = yield* HttpClient.execute(withCookie(download));
186
180
 
187
- // A cookie scheme has no challenge. A token is no credential on this route.
188
181
  expect([
189
182
  signedOut.status,
190
183
  signedOut.headers["cache-control"],
191
184
  ]).toStrictEqual([401, "no-store"]);
192
185
  expect(signedOut.headers["www-authenticate"]).toBeUndefined();
193
186
  expect(withToken.status).toBe(401);
194
- // kay is signed in, in the right workspace, without the read scope: the route's own
195
- // `authorize` refuses.
196
187
  expect(withoutScope.status).toBe(403);
197
188
  expect(yield* withoutScope.json).toMatchObject({
198
189
  message: "Requires issues:read.",
@@ -17,19 +17,14 @@ import {
17
17
  import { publicRoutes } from "../../src/routes.js";
18
18
  import { services } from "../support/services.js";
19
19
 
20
- // What authentication adds on the wire: the public port behind its real providers, answering
21
- // in memory. A caller is the credential its client sends.
22
20
  const served = Testing.layer(publicRoutes).pipe(Layer.provide(services()));
23
21
 
24
- // A test replaces the one service it is about. Provided before `services`, this layer is the
25
- // `Directory` the routes are built with; `services` gives them the rest.
26
22
  const servedWith = (directory: Layer.Layer<Directory>) =>
27
23
  Testing.layer(publicRoutes).pipe(
28
24
  Layer.provide(directory),
29
25
  Layer.provide(services())
30
26
  );
31
27
 
32
- // A directory that cannot reach its issuer.
33
28
  const issuerDown = Layer.succeed(
34
29
  Directory,
35
30
  Directory.of({
@@ -64,7 +59,6 @@ describe("a bearer token", () => {
64
59
  scopes: ["issues:read"],
65
60
  });
66
61
 
67
- // A member of acme alone, asking for globex: refused, with no scope to step up to.
68
62
  const refused = yield* Effect.flip(elsewhere.whoAmI());
69
63
 
70
64
  expect(refused).toBeInstanceOf(Action.Forbidden);
@@ -89,7 +83,6 @@ describe("a bearer token", () => {
89
83
  );
90
84
  expect(refused.message).toBe("Requires issues:write.");
91
85
 
92
- // The same refusal as sent: the 403 an OAuth client re-authorizes on.
93
86
  const response = yield* HttpClientRequest.post(
94
87
  "/api/v1/closeIssue"
95
88
  ).pipe(
@@ -119,7 +112,6 @@ describe("a bearer token", () => {
119
112
  scopes_supported: ["issues:read", "issues:write"],
120
113
  });
121
114
 
122
- // A protected tool's call without a token: the endpoint's own 401, before any tool runs.
123
115
  const refused = yield* HttpClient.execute(
124
116
  ActionMcp.request("tools/call", { name: "whoAmI", arguments: {} })
125
117
  );
@@ -137,8 +129,6 @@ describe("a bearer token", () => {
137
129
  Effect.gen(function* () {
138
130
  const http = yield* ActionHttp.client(Http, as("ada", "acme"));
139
131
 
140
- // Over MCP it is the endpoint's HTTP answer, before any tool runs, not a tool's result: the
141
- // client decodes it given the descriptor the endpoint serves with.
142
132
  const mcp = yield* ActionMcp.client([WhoAmI], {
143
133
  ...as("ada", "acme"),
144
134
  authentication: Login,
@@ -15,8 +15,6 @@ import { Rpc } from "../../src/Rpc.js";
15
15
  import { WorkspaceRegistry } from "../../src/workspaces/registry.js";
16
16
  import { services } from "../support/services.js";
17
17
 
18
- // The web app's rpcs in memory. The server serves them over a WebSocket; here the same layer
19
- // is given Effect's HTTP protocol, which a client reaches through `Testing.layer`.
20
18
  const server = rpc.pipe(
21
19
  Layer.provide(RpcServer.layerProtocolHttp({ path: "/rpc" })),
22
20
  Layer.provide(RpcSerialization.layerJson)
@@ -28,19 +26,13 @@ const protocol = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
28
26
 
29
27
  const socket = protocol.pipe(Layer.provide(Testing.layer(server)));
30
28
 
31
- // `provideMerge`: the test reads the registry the rpcs' verifier reads.
32
29
  const served = socket.pipe(Layer.provideMerge(memory));
33
30
 
34
- // The rpcs beside the public port's routes under one `Testing.layer`, as server.ts serves them
35
- // under one router, there over a WebSocket. `provideMerge`: the test calls the JSON routes
36
- // with the `HttpClient` the rpc client's protocol is given.
37
31
  const servedWithHttp = protocol.pipe(
38
32
  Layer.provideMerge(Testing.layer(Layer.merge(server, publicRoutes))),
39
33
  Layer.provide(services())
40
34
  );
41
35
 
42
- // Each call carries its caller's session cookie, as a browser attaches it, so one client
43
- // serves several callers. Authentication is per message.
44
36
  const as = (session: string) =>
45
37
  RpcClient.withHeaders({ cookie: `tracker_session=${session}` });
46
38
 
@@ -116,8 +108,6 @@ describe("a session cookie, over RPC", () => {
116
108
  ),
117
109
  });
118
110
 
119
- // Sixty requests as ada in acme, half on each surface: each middleware counts, and the
120
- // next request is refused on either.
121
111
  yield* Effect.forEach(Array.range(1, 30), () => http.whoAmI());
122
112
  yield* Effect.forEach(Array.range(1, 30), () =>
123
113
  rpcs.whoAmI().pipe(as("ada-at-acme"))
@@ -4,12 +4,11 @@ import { Effect, Layer, Stream } from "effect";
4
4
  import { LanguageModel } from "effect/ai";
5
5
 
6
6
  import { CurrentMember } from "../../src/identity/Identity.js";
7
- import { members } from "../../src/identity/members.js";
7
+ import { demoMembers } from "../../src/identity/members.js";
8
8
  import { layer, toolkit, triage } from "../../src/issues/assistant.js";
9
9
  import { issues } from "../../src/issues/handlers.js";
10
10
  import { memory } from "../../src/memory.js";
11
11
 
12
- // A model that asks for the same two tools in every turn stands in for a provider's.
13
12
  const model = LanguageModel.make({
14
13
  generateText: () =>
15
14
  Effect.succeed([
@@ -29,9 +28,8 @@ const model = LanguageModel.make({
29
28
  streamText: () => Stream.empty,
30
29
  });
31
30
 
32
- const asAda = Effect.provideService(CurrentMember, members.ada);
31
+ const asAda = Effect.provideService(CurrentMember, demoMembers.ada);
33
32
 
34
- // The toolkit's handlers and a client of the same implementation, over one store.
35
33
  const services = layer.pipe(Layer.provideMerge(memory));
36
34
 
37
35
  describe("the assistant's tools", () => {
@@ -75,13 +73,11 @@ describe("the assistant's tools", () => {
75
73
  "closeIssue",
76
74
  ]);
77
75
 
78
- // `tools.handle` is a caller that is not a model's turn: it asks no approval, and takes
79
- // the arguments as JSON. The implementation's `authorize` runs all the same.
80
76
  const refused = yield* tools
81
77
  .handle("closeIssue", { id: "ACME-1" })
82
78
  .pipe(
83
79
  Effect.flatMap(Stream.runCollect),
84
- Effect.provideService(CurrentMember, members.linus)
80
+ Effect.provideService(CurrentMember, demoMembers.linus)
85
81
  );
86
82
 
87
83
  expect(
@@ -7,7 +7,7 @@ import { HttpClient, HttpClientRequest } from "effect/http";
7
7
  import { RateLimiter } from "effect/persistence";
8
8
  import { TestClock } from "effect/testing";
9
9
 
10
- import type { members } from "../../src/identity/members.js";
10
+ import type { demoMembers } from "../../src/identity/members.js";
11
11
  import { issueEvents } from "../../src/issues/events.js";
12
12
  import { issues } from "../../src/issues/handlers.js";
13
13
  import { IssueChanged } from "../../src/issues/Issues.js";
@@ -22,9 +22,8 @@ const inProcess = Layer.mergeAll(
22
22
  Event.layerMemory
23
23
  );
24
24
 
25
- // The changes a member's watch receives, as data, while `act` changes issues.
26
25
  const watched = <E, R>(
27
- member: keyof typeof members,
26
+ member: keyof typeof demoMembers,
28
27
  input: typeof IssueChanged.input.Type,
29
28
  count: number,
30
29
  act: (
@@ -43,8 +42,6 @@ const watched = <E, R>(
43
42
  Effect.forkChild
44
43
  );
45
44
 
46
- // Lets the forked watch run up to its subscription first: started after `act`, it would wait
47
- // for changes already made.
48
45
  yield* TestClock.adjust("0 millis");
49
46
  yield* act(client);
50
47
 
@@ -107,7 +104,6 @@ describe("issue.changed", () => {
107
104
  .commentOnIssue({ id: filed.id, text: "Seen it." })
108
105
  .pipe(as("ada"));
109
106
  yield* client.closeIssue({ id: filed.id }).pipe(as("ada"));
110
- // Closing it again changes nothing, and nothing is sent.
111
107
  yield* client.closeIssue({ id: filed.id }).pipe(as("ada"));
112
108
  yield* client
113
109
  .commentOnIssue({ id: filed.id, text: "Fixed." })
@@ -152,15 +148,12 @@ describe("issue.changed", () => {
152
148
  );
153
149
  });
154
150
 
155
- // The subscriber's secret: `whsec_` and 24 to 64 random bytes in base64.
156
151
  const secret = `whsec_${Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64")}`;
157
152
 
158
153
  const Delivered = Schema.fromJsonString(
159
154
  Schema.Record(Schema.String, Schema.Json)
160
155
  );
161
156
 
162
- // linus's server: it echoes the verification's challenge, which proves it asked for these
163
- // deliveries, and acknowledges each delivery with a 2xx.
164
157
  const subscriber =
165
158
  (received: Queue.Enqueue<typeof Delivered.Type>) =>
166
159
  async (request: Request) => {
@@ -13,8 +13,6 @@ import { publicRoutes, rpc } from "../../src/routes.js";
13
13
  import { Rpc } from "../../src/Rpc.js";
14
14
  import { services } from "../support/services.js";
15
15
 
16
- // The public port's routes and the web app's rpcs under one `Testing.layer`, as server.ts
17
- // serves them under one router.
18
16
  const served = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
19
17
  Layer.provide(RpcSerialization.layerJson),
20
18
  Layer.provideMerge(
@@ -69,7 +67,6 @@ describe("exportIssues", () => {
69
67
  )
70
68
  );
71
69
 
72
- // The web app's call carries its session cookie, as a browser attaches it.
73
70
  const overRpc = yield* Stream.runCollect(
74
71
  web.exportIssues({ status: "open" })
75
72
  ).pipe(
@@ -3,14 +3,13 @@ import * as Action from "@gjermundgaraba/effect-actions/Action";
3
3
  import { Array, Effect, Layer, References } from "effect";
4
4
  import { RateLimiter } from "effect/persistence";
5
5
 
6
- import { members } from "../../src/identity/members.js";
6
+ import { demoMembers } from "../../src/identity/members.js";
7
7
  import { issues } from "../../src/issues/handlers.js";
8
8
  import { IssueNotFound, Issues, RateLimited } from "../../src/issues/Issues.js";
9
9
  import { IssueStore } from "../../src/issues/store.js";
10
10
  import { status } from "../../src/workspaces/handlers.js";
11
11
  import { as } from "../support/as.js";
12
12
 
13
- // The two startup services the issues' builder yields, and nothing else of the application.
14
13
  const services = Layer.mergeAll(
15
14
  IssueStore.layerMemory,
16
15
  RateLimiter.layer.pipe(Layer.provide(RateLimiter.layerStoreMemory))
@@ -45,9 +44,11 @@ describe("issues, in process", () => {
45
44
  const client = yield* Action.client(issues);
46
45
  const store = yield* IssueStore;
47
46
 
48
- // Written to the store, not through `createIssue`: twenty-one are over its write limit.
49
47
  yield* Effect.forEach(Array.range(1, 21), (n) =>
50
- store.create(members.ada.workspace, { title: `Issue ${n}`, body: "" })
48
+ store.create(demoMembers.ada.workspace, {
49
+ title: `Issue ${n}`,
50
+ body: "",
51
+ })
51
52
  );
52
53
  yield* client.closeIssue({ id: "ACME-2" }).pipe(as("ada"));
53
54
 
@@ -86,12 +87,8 @@ describe("issues, in process", () => {
86
87
  it.effect("keeps both of two comments made at once", () =>
87
88
  Effect.gen(function* () {
88
89
  const store = yield* IssueStore;
89
- const { workspace } = members.ada;
90
+ const { workspace } = demoMembers.ada;
90
91
 
91
- // Asked of the store, not through `commentOnIssue`, whose write limit this would spend.
92
- // A fiber is set aside after every `steps` steps, and two that run at once then take
93
- // turns. Each count sets the first comment aside at another point of its work; under
94
- // three, the two do not finish.
95
92
  const kept = yield* Effect.forEach(Array.range(3, 60), (steps) =>
96
93
  Effect.gen(function* () {
97
94
  const { id } = yield* store.create(workspace, {
@@ -126,7 +123,6 @@ describe("issues, in process", () => {
126
123
  .pipe(as("ada"))
127
124
  );
128
125
 
129
- // Ten writes are spent, by two actions: the eleventh, of a third, is refused.
130
126
  expect(
131
127
  yield* Effect.flip(
132
128
  client.closeIssue({ id: "ACME-1" }).pipe(as("ada"))
@@ -149,8 +145,6 @@ describe("issues, in process", () => {
149
145
  "builds only the implementations whose actions a client lists",
150
146
  () =>
151
147
  Effect.gen(function* () {
152
- // Two implementations are passed, and `actions` selects the issues': `status` is left
153
- // out, unbuilt, so `services` need not hold the registry its builder yields.
154
148
  const client = yield* Action.client([status, issues], {
155
149
  actions: Issues,
156
150
  });
@@ -15,9 +15,6 @@ import { memory } from "../src/memory.js";
15
15
  import { adminRoutes, publicRoutes } from "../src/routes.js";
16
16
  import { services } from "./support/services.js";
17
17
 
18
- // Each port as a web handler, `Request` in and `Response` out: what a platform without
19
- // Effect's server runs, and what a test sends raw requests to. A handler builds its routes
20
- // once; the test owns it, and disposes it when done.
21
18
  const web = HttpRouter.toWebHandler(
22
19
  publicRoutes.pipe(
23
20
  Layer.provide(HttpServer.layerServices),
@@ -163,8 +160,6 @@ describe("the request policy", () => {
163
160
  expect([here.status, foreignHost.status]).toStrictEqual([200, 403]);
164
161
  });
165
162
 
166
- // Behind a proxy ending TLS, Node's server sees `http:`: the public URL's origin is allowed by
167
- // name, not as the request's own, so a page of it is answered whatever the proxy forwards.
168
163
  it.effect("answers the public URL's page behind a proxy ending TLS", () =>
169
164
  Effect.gen(function* () {
170
165
  const client = yield* HttpClient.HttpClient;
@@ -206,7 +201,6 @@ describe("the request policy", () => {
206
201
  )
207
202
  );
208
203
 
209
- // `Testing.layer(handler)` gives the typed clients the same handler the raw requests hit.
210
204
  it.effect(
211
205
  "leaves the typed client, served from the same web handler, alone",
212
206
  () =>
@@ -11,9 +11,6 @@ import { AdminHttp, Http } from "../src/Api.js";
11
11
  import { adminRoutes, builders, publicRoutes } from "../src/routes.js";
12
12
  import { services } from "./support/services.js";
13
13
 
14
- // The host's surfaces, as routes.ts builds them, answering in memory: no port is opened. Each
15
- // port is a `Testing.layer` of its own, and what they share is provided above both, as
16
- // server.ts does.
17
14
  const shared = builders.pipe(Layer.provideMerge(services()));
18
15
 
19
16
  const onPublicPort = Effect.provide(Testing.layer(publicRoutes));
@@ -98,7 +95,6 @@ describe("the public port", () => {
98
95
  "refuses, at the MCP endpoint, a page of this host that is not on its list",
99
96
  () =>
100
97
  Effect.gen(function* () {
101
- // The request policy lets both through: one is the request's own origin, one is listed.
102
98
  const listed = yield* from("/mcp", "http://localhost:6274");
103
99
 
104
100
  const sameHost = yield* from(
@@ -133,8 +129,6 @@ describe("the two ports", () => {
133
129
  (client) => client.getStatus()
134
130
  ).pipe(onAdminPort);
135
131
 
136
- // `status`'s builder names the start it ran in. With `builders` above both ports it ran
137
- // once. Provide `memory` alone instead, and each port runs it: two instances.
138
132
  expect(onAdmin.instance).toBe(onPublic.instance);
139
133
  }).pipe(Effect.provide(shared))
140
134
  );
@@ -1,9 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
 
3
3
  import { CurrentMember } from "../../src/identity/Identity.js";
4
- import { members } from "../../src/identity/members.js";
4
+ import { demoMembers } from "../../src/identity/members.js";
5
5
 
6
- // What the implementation does, with no transport: `Action.client` runs the same decoding,
7
- // `authorize` and handler a server runs. Each call or watch names its caller, as a request would.
8
- export const as = (member: keyof typeof members) =>
9
- Effect.provideService(CurrentMember, members[member]);
6
+ export const as = (member: keyof typeof demoMembers) =>
7
+ Effect.provideService(CurrentMember, demoMembers[member]);
@@ -4,9 +4,6 @@ import type { Response } from "effect/ai";
4
4
 
5
5
  type Reply = readonly Response.PartEncoded[];
6
6
 
7
- // A model for a test: it answers its first request with the first reply it was given, its
8
- // second with the second, whatever the prompt says. A reply is the parts a provider sends, or
9
- // an Effect that makes them: `down` to fail as a provider that is down does, or one that waits.
10
7
  export const scripted = (
11
8
  ...replies: ReadonlyArray<Reply | Effect.Effect<Reply, AiError.AiError>>
12
9
  ) =>
@@ -6,9 +6,6 @@ import { memory } from "../../src/memory.js";
6
6
 
7
7
  const unreached = async () => new Response(null, { status: 503 });
8
8
 
9
- // What the public routes need, in memory: the application's services, and for webhook delivery
10
- // a client and a resolver. `subscribers` answers each POST in place of a member's server, and
11
- // hooks.example.com resolves to a public address: delivery refuses a private or loopback one.
12
9
  export const services = (subscribers = Testing.layer(unreached)) =>
13
10
  Layer.mergeAll(
14
11
  memory,
@@ -3,10 +3,6 @@ import * as ActionRpc from "@gjermundgaraba/effect-actions/ActionRpc";
3
3
  import { ListRooms, MessagePosted, Messages } from "./chat/Chat.js";
4
4
  import { Login } from "./identity/Identity.js";
5
5
 
6
- // The RPC binding: one native rpc per action, named after it, and a stream rpc for
7
- // `MessagePosted`, the protected ones requiring `Login`. It is plain data and imports no server
8
- // code, so the server and a browser page both import this one value. `Rpc.group` is the native
9
- // `RpcGroup`, for Effect's own `RpcClient.make`.
10
6
  export const Rpc = ActionRpc.make([ListRooms, ...Messages, MessagePosted], {
11
7
  authentication: Login,
12
8
  });
@@ -7,37 +7,23 @@ import { Socket } from "effect/socket";
7
7
  import { MessagePosted, roomHeader } from "./chat/Chat.js";
8
8
  import { Rpc } from "./Rpc.js";
9
9
 
10
- // Client module: what a web page imports. It holds the binding and nothing of the server, so a
11
- // bundler gets the contracts and Effect's RPC client, no handler and nothing of Node.
12
-
13
- // Effect's own client protocol: one WebSocket, speaking the server's JSON. This layer owns
14
- // the socket, so a page provides it once, around its whole program, and every call shares
15
- // that one socket. Which WebSocket is left to the host: a page provides
16
- // `Socket.layerWebSocketConstructorGlobal`, the browser's own, and client.ts provides Node's.
17
10
  export const connection = (url: string) =>
18
11
  RpcClient.layerProtocolSocket().pipe(
19
12
  Layer.provide(Socket.layerWebSocket(url)),
20
13
  Layer.provide(RpcSerialization.layerJson)
21
14
  );
22
15
 
23
- // The chat as a page uses it, on the connection provided around it.
24
16
  export const openChat = Effect.gen(function* () {
25
- // One typed method per action of the binding, all on the one connection.
26
17
  const client = yield* ActionRpc.client(Rpc);
27
18
 
28
19
  return {
29
- // The public rpc: no token.
30
20
  rooms: Effect.map(client.listRooms(), ({ rooms }) => rooms),
31
21
 
32
22
  room: (name: string, token: string) => {
33
- // A browser WebSocket cannot set an `Authorization` header on its upgrade, so the token
34
- // travels on each message, and the room beside it. A refreshed token needs no new socket.
35
23
  const headers = { authorization: `Bearer ${token}`, [roomHeader]: name };
36
24
  const here = RpcClient.withHeaders(headers);
37
25
 
38
26
  return {
39
- // What the room holds after the last id the page has. A token may expire while the
40
- // page stays open, so each refusal becomes what the page shows.
41
27
  read: (after: number) =>
42
28
  client.readMessages({ after }).pipe(
43
29
  here,
@@ -58,14 +44,6 @@ export const openChat = Effect.gen(function* () {
58
44
 
59
45
  post: (text: string) => client.postMessage({ text }).pipe(here),
60
46
 
61
- // Each message posted to the room after the last id the page holds: a page opening a
62
- // room reads it, then watches from the last id it read, so a post between the two is
63
- // not lost; 0 sends the room's history first. `watch` connects again after a drop and
64
- // resumes from the last message it delivered, so the page never subscribes by hand; a
65
- // `Gap` says some were missed, or are another run's, so the page reads the room again
66
- // with `read(0)`. The headers go with the
67
- // stream, as `here` puts them on a call, and so with every request it sends again. A
68
- // refusal ends it, as when it connects again with a token that has expired.
69
47
  messages: (after: number) =>
70
48
  client
71
49
  .watch(MessagePosted, {}, { cursor: String(after) })
@@ -76,8 +54,6 @@ export const openChat = Effect.gen(function* () {
76
54
  )
77
55
  ),
78
56
 
79
- // A declared error arrives as the contract's class. A message someone else already
80
- // removed is gone, which is what the page asked for.
81
57
  remove: (id: number) =>
82
58
  client.deleteMessage({ id }).pipe(
83
59
  here,
@@ -4,8 +4,6 @@ import { Schema } from "effect";
4
4
 
5
5
  import { CurrentMember } from "../identity/Identity.js";
6
6
 
7
- // A message's `id` counts up within its room, so a client asks for what came after the last
8
- // one it holds.
9
7
  export const Message = Schema.Struct({
10
8
  id: Schema.Int,
11
9
  author: Schema.String,
@@ -14,35 +12,20 @@ export const Message = Schema.Struct({
14
12
 
15
13
  export type Message = typeof Message.Type;
16
14
 
17
- // A declared error is part of the contract: every client decodes it as this class. Its status
18
- // is for a JSON binding, should these actions be served as one too: an rpc carries no status,
19
- // and an error without one answers 422 over HTTP.
20
15
  export class MessageNotFound extends Schema.TaggedError<
21
16
  MessageNotFound,
22
17
  { readonly brand: unique symbol }
23
18
  >()("MessageNotFound", { id: Schema.Int }, { httpApiStatus: 404 }) {}
24
19
 
25
- // A refusal carries what the caller sent and no more: who wrote the message is for the actions
26
- // that read it, under their own rule.
27
20
  export class NotAuthor extends Schema.TaggedError<
28
21
  NotAuthor,
29
22
  { readonly brand: unique symbol }
30
23
  >()("NotAuthor", { id: Schema.Int }, { httpApiStatus: 403 }) {}
31
24
 
32
- // Which room a call is about is not an input of any action: it travels beside the call, in
33
- // this header, as the token does, because `authorize` sees the action and not its input, and
34
- // the membership rule needs the room. With the room in the input, that check belongs in the
35
- // store, as `MessageStore.remove` takes the author and refuses with `NotAuthor`, never in a
36
- // helper each handler must remember to call. The client sets the header; on the server,
37
- // room.ts reads it. A call without it is about the default room, so `listRooms`, which is
38
- // about none, sends none; yours may refuse such a call instead.
39
25
  export const roomHeader = "x-room";
40
26
 
41
27
  export const defaultRoom = "lobby";
42
28
 
43
- // Public: `caller: Action.Anyone`, so a page shows the rooms before anyone has signed in. It
44
- // tells a signed-out caller every room's name and how many messages it holds, a room appearing
45
- // once someone posts: decide whether yours may.
46
29
  export const ListRooms = Action.make("listRooms", {
47
30
  description:
48
31
  "List the rooms someone has posted in, and how many messages each holds.",
@@ -57,8 +40,6 @@ export const ListRooms = Action.make("listRooms", {
57
40
 
58
41
  const signedIn = { caller: CurrentMember } as const;
59
42
 
60
- // Reads once: a page opening a room reads what is there, then watches `MessagePosted` below from
61
- // the last id it read.
62
43
  export const ReadMessages = Action.make("readMessages", {
63
44
  ...signedIn,
64
45
  description: "Read the room's messages after the given id; 0 reads them all.",
@@ -87,9 +68,6 @@ export const DeleteMessage = Action.make("deleteMessage", {
87
68
 
88
69
  export const Messages = [ReadMessages, PostMessage, DeleteMessage] as const;
89
70
 
90
- // Each message posted to the room, as it is posted: a page watches it on its open socket,
91
- // about the room its header names, as the actions are. Signed-in, so each watch authenticates
92
- // and runs `authorize` as it starts, refused for a member outside the room.
93
71
  export const MessagePosted = Event.make("message.posted", {
94
72
  description: "A message posted to the room.",
95
73
  payload: Message,
@@ -4,9 +4,6 @@ import { Effect } from "effect";
4
4
  import { CurrentMember } from "../identity/Identity.js";
5
5
  import { CurrentRoom } from "./room.js";
6
6
 
7
- // The one rule: a member reads and writes only the rooms they belong to. It runs before every
8
- // protected handler, on every surface, and reads two request-time services: the caller, from
9
- // authentication, and the room, from the middleware.
10
7
  export const authorize = Effect.fn("authorize")(function* () {
11
8
  const member = yield* CurrentMember;
12
9
  const room = yield* CurrentRoom;