@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
@@ -3,11 +3,6 @@ import { Context, Effect, Layer, PubSub, Stream } from "effect";
3
3
  import { IssueNotFound } from "./Issues.js";
4
4
  import type { Comment, Issue, IssueChange, Status } from "./Issues.js";
5
5
 
6
- /**
7
- * Where issues live, each in one workspace. Every method but `changes` takes the workspace, so
8
- * tenant isolation is the data access's: no surface and no handler can skip it, and an issue of
9
- * another workspace is simply not found.
10
- */
11
6
  export class IssueStore extends Context.Service<
12
7
  IssueStore,
13
8
  {
@@ -16,7 +11,6 @@ export class IssueStore extends Context.Service<
16
11
  status: typeof Status.Type | undefined,
17
12
  limit: number
18
13
  ) => Effect.Effect<readonly Issue[]>;
19
- /** Every issue, oldest first. */
20
14
  readonly all: (
21
15
  workspace: string,
22
16
  status: typeof Status.Type | undefined
@@ -42,24 +36,15 @@ export class IssueStore extends Context.Service<
42
36
  workspace: string,
43
37
  id: string
44
38
  ) => Effect.Effect<Issue, IssueNotFound>;
45
- /**
46
- * Every change from now on, in the order the store makes them, of every workspace: whatever
47
- * reads it filters by workspace itself, as `issueEvents`' `match` does.
48
- */
49
39
  readonly changes: Stream.Stream<typeof IssueChange.Type>;
50
40
  }
51
41
  >()("tracker/IssueStore") {
52
- // DEMO ONLY: memory, lost when the process stops. A real store is another Layer of this
53
- // service, chosen by the entrypoint.
54
42
  static readonly layerMemory = Layer.effect(
55
43
  IssueStore,
56
44
  Effect.gen(function* () {
57
45
  const issues = new Map<string, Issue[]>();
58
46
  const changes = yield* PubSub.unbounded<typeof IssueChange.Type>();
59
47
 
60
- // Published in the step of the write, after it, so a subscriber never sees a change the
61
- // store did not make, and sees them in the order they were made. A database publishes
62
- // from its own change feed, or an outbox written in the same transaction.
63
48
  const publish = (
64
49
  workspace: string,
65
50
  issue: Issue,
@@ -98,21 +83,17 @@ export class IssueStore extends Context.Service<
98
83
  return issue;
99
84
  });
100
85
 
101
- // No `yield*` between the read and the write: a fiber may be set aside at one, and two
102
- // changes that each read the issue before either wrote would keep only the second. A
103
- // database does this in one statement or a transaction.
104
- // A change `to` answers with the same issue for is no change, and is not published.
105
- const change = Effect.fn("IssueStore.change")(function* (
86
+ const changedAtomically = (
106
87
  workspace: string,
107
88
  id: string,
108
89
  to: (issue: Issue) => Issue,
109
90
  kind: (typeof IssueChange.Type)["change"],
110
91
  comment?: typeof Comment.Type
111
- ) {
92
+ ): Issue | undefined => {
112
93
  const issue = of(workspace).find((candidate) => candidate.id === id);
113
94
 
114
95
  if (issue === undefined) {
115
- return yield* new IssueNotFound({ id });
96
+ return undefined;
116
97
  }
117
98
 
118
99
  const changed = to(issue);
@@ -130,6 +111,22 @@ export class IssueStore extends Context.Service<
130
111
 
131
112
  publish(workspace, changed, kind, comment);
132
113
 
114
+ return changed;
115
+ };
116
+
117
+ const change = Effect.fn("IssueStore.change")(function* (
118
+ workspace: string,
119
+ id: string,
120
+ to: (issue: Issue) => Issue,
121
+ kind: (typeof IssueChange.Type)["change"],
122
+ comment?: typeof Comment.Type
123
+ ) {
124
+ const changed = changedAtomically(workspace, id, to, kind, comment);
125
+
126
+ if (changed === undefined) {
127
+ return yield* new IssueNotFound({ id });
128
+ }
129
+
133
130
  return changed;
134
131
  });
135
132
 
@@ -138,7 +135,6 @@ export class IssueStore extends Context.Service<
138
135
  Effect.sync(() =>
139
136
  having(workspace, status).toReversed().slice(0, limit)
140
137
  ),
141
- // A database reads it in pages, by id, so an export never holds the workspace whole.
142
138
  all: (workspace, status) =>
143
139
  Stream.suspend(() => Stream.fromIterable(having(workspace, status))),
144
140
  count: (workspace, status) =>
@@ -33,7 +33,6 @@ const limitedBy = Effect.gen(function* () {
33
33
  retryAfterSeconds: Duration.toSeconds(retryAfter),
34
34
  })
35
35
  ),
36
- // Any other reason is the limiter's store failing: a defect, not the caller's.
37
36
  Effect.die
38
37
  )
39
38
  );
@@ -42,15 +41,6 @@ const limitedBy = Effect.gen(function* () {
42
41
  });
43
42
  });
44
43
 
45
- // The write limit: ten writes a minute per member. It is the handlers', not a surface's, so it
46
- // holds wherever they run: HTTP, MCP, RPC, stdio and the assistant's tools all count against
47
- // the one limiter. A builder yields this once and wraps each limited handler in the function
48
- // it gets, which fails with an error those actions' contracts declare; every surface sends it
49
- // as any declared error. The limiter is a service, so its counts are shared wherever it is
50
- // provided: memory.ts provides Effect's own, `RateLimiter.layer` over a store. `consume` counts
51
- // in a fixed window unless given `algorithm: "token-bucket"`: ten writes in each minute, so
52
- // twenty may pass across the boundary between two. A strict limit, ten in any sixty seconds,
53
- // is a service of your own of the same shape, yielded here, never part of the issue store.
54
44
  export const writeLimit = Effect.gen(function* () {
55
45
  const limited = yield* limitedBy;
56
46
 
@@ -58,8 +48,6 @@ export const writeLimit = Effect.gen(function* () {
58
48
  limited("writes", 10, write);
59
49
  });
60
50
 
61
- // The export limit: two exports a minute per member, on the same limiter under a key of its
62
- // own, so exporting spends no write.
63
51
  export const exportLimit = Effect.gen(function* () {
64
52
  const limited = yield* limitedBy;
65
53
 
@@ -10,21 +10,14 @@ import { Directory } from "./identity/directory.js";
10
10
  import { IssueStore } from "./issues/store.js";
11
11
  import { WorkspaceRegistry } from "./workspaces/registry.js";
12
12
 
13
- // DEMO ONLY: the application's services as their memory or fixed-data Layers, lost when the
14
- // process stops. A real entrypoint provides a database-backed Layer per service instead, and a
15
- // test replaces the one it is about.
16
-
17
- /** Both stores. The attachment store is built on the issue store: `provideMerge` keeps it. */
18
13
  export const stores = AttachmentStore.layerMemory.pipe(
19
14
  Layer.provideMerge(IssueStore.layerMemory)
20
15
  );
21
16
 
22
- /** Effect's own limiter, counting in memory. `RateLimiter.layerStoreRedis` counts across processes. */
23
17
  export const limiter = RateLimiter.layer.pipe(
24
18
  Layer.provide(RateLimiter.layerStoreMemory)
25
19
  );
26
20
 
27
- /** Everything the server needs, for both ports. A local entrypoint provides only what it serves. */
28
21
  export const memory = Layer.mergeAll(
29
22
  stores,
30
23
  limiter,
@@ -33,7 +26,5 @@ export const memory = Layer.mergeAll(
33
26
  Grants.layerDemo,
34
27
  Conversations.layerMemory,
35
28
  demoModel,
36
- // The issue changes' log, kept in this process for the subscribers its sockets and streams
37
- // hold.
38
29
  Event.layerMemory
39
30
  );
@@ -9,10 +9,6 @@ import { Grants } from "./admin/grants.js";
9
9
  import { admin } from "./admin/handlers.js";
10
10
  import { WorkspaceRegistry } from "./workspaces/registry.js";
11
11
 
12
- // Entrypoint: `node --import tsx examples/kitchen-sink/src/ops.ts list-workspaces`.
13
- // The operators' console: the admin actions run in this process, on the host's own services,
14
- // with no server and no key.
15
-
16
12
  const operator: TrustedOperator = { id: "console", trusted: true };
17
13
 
18
14
  const ops = ActionCli.make(admin, {
@@ -31,8 +27,6 @@ const ops = ActionCli.make(admin, {
31
27
  resumeWorkspace: { positional: ["workspace"] },
32
28
  },
33
29
  }).pipe(
34
- // Only what these actions are built from. DEMO ONLY: memory, so this console sees its own
35
- // process, not the server's data. A real one provides the database Layers the server does.
36
30
  Command.provide(Layer.merge(WorkspaceRegistry.layerMemory, Grants.layerDemo)),
37
31
  Command.provideSync(Operator, operator)
38
32
  );
@@ -5,13 +5,6 @@ import { allowedOrigins, publicUrl } from "./config.js";
5
5
 
6
6
  const loopback = ["localhost", "127.0.0.1"];
7
7
 
8
- // Which Host and Origin a request may carry: not the library's concern, but every request of
9
- // both ports passes it first. A Host that is neither loopback nor the public URL's is refused,
10
- // against DNS rebinding. The web app signs in with a cookie, which a browser attaches to
11
- // any page's request, so a foreign Origin must be refused before authentication reads it.
12
- // That is why this is global router middleware (`global: true`): it runs before routing, so
13
- // before every route's authentication. As a layer's own `middleware` it would run inside the
14
- // authentication, too late.
15
8
  export const requestPolicy = HttpRouter.middleware(
16
9
  Effect.gen(function* () {
17
10
  const hosts = new Set([...loopback, new URL(yield* publicUrl).hostname]);
@@ -31,10 +24,6 @@ export const requestPolicy = HttpRouter.middleware(
31
24
 
32
25
  const { origin } = request.headers;
33
26
 
34
- // The request's own origin is that of a page served from this port directly. Behind a
35
- // proxy ending TLS it is an `http:` one from Effect 4.0.6, whose `originalUrl` takes the
36
- // scheme of the connection, whatever `X-Forwarded-Proto` says, so the public URL's
37
- // origin is among `origins`.
38
27
  if (
39
28
  origin !== undefined &&
40
29
  origin !== url.value.origin &&
@@ -49,12 +38,6 @@ export const requestPolicy = HttpRouter.middleware(
49
38
  { global: true }
50
39
  );
51
40
 
52
- // CORS for the one cross-origin caller, a browser MCP client. `HttpRouter.cors` is global to
53
- // the router too: it answers the preflight before any route's authentication, and adds its
54
- // headers to refusals as well. An MCP endpoint's `allowedOrigins` is no CORS: it only refuses
55
- // origins. The headers are those an MCP client sends and must be able to read. A client of an
56
- // MCP revision with sessions sends its session's id on each request, reads it from the answer
57
- // that opened the session, and ends the session with a `DELETE`.
58
41
  export const cors = Layer.unwrap(
59
42
  Effect.map(allowedOrigins, (origins) =>
60
43
  HttpRouter.cors({
@@ -34,8 +34,6 @@ import { status } from "./workspaces/handlers.js";
34
34
  import { resolveTenant } from "./workspaces/tenant.js";
35
35
  import { GetStatus } from "./workspaces/Workspaces.js";
36
36
 
37
- // Every domain's implementation of the public port's actions and events, once. Each surface
38
- // below takes this one list and serves what its binding or its `actions` names.
39
37
  const implementations = [
40
38
  status,
41
39
  identity,
@@ -46,9 +44,6 @@ const implementations = [
46
44
  assistant,
47
45
  ];
48
46
 
49
- // JSON routes at `/api/v1/<action>`, in two layers of one binding, each naming its `actions`,
50
- // an event among them: a layer given `actions` serves exactly what it names. The quota requires
51
- // the caller, and a public route has none, so `getStatus` is served by a layer without it.
52
47
  const api = Layer.mergeAll(
53
48
  ActionHttp.layer(Http, implementations, { actions: [GetStatus] }),
54
49
  ActionHttp.layer(Http, implementations, {
@@ -57,9 +52,6 @@ const api = Layer.mergeAll(
57
52
  })
58
53
  );
59
54
 
60
- // The same actions as MCP tools at `/mcp`: a mixed endpoint, serving the public `getStatus`
61
- // beside the members' tools, and `issue.changed` as an MCP event, polled, streamed or
62
- // delivered by webhook.
63
55
  const mcp = Layer.unwrap(
64
56
  Effect.map(allowedOrigins, (origins) =>
65
57
  ActionMcp.layerHttp(implementations, {
@@ -69,25 +61,15 @@ const mcp = Layer.unwrap(
69
61
  authentication: Login,
70
62
  actions: [...Tools, IssueChanged],
71
63
  features,
72
- // The endpoint's own Origin allowlist, narrower than the request policy, which has
73
- // already refused a foreign Origin: that policy also lets through a page of any name
74
- // this host answers to, such as http://127.0.0.1:3000. Not listed here, such a page gets
75
- // a 403 from the endpoint.
76
64
  allowedOrigins: origins,
77
65
  })
78
66
  )
79
67
  );
80
68
 
81
- // The members' actions as Effect RPC, for the web app, behind its session cookie and the same
82
- // quota as native RPC middleware. It still requires its protocol and serialization, chosen by
83
- // whoever serves it: server.ts gives it a WebSocket, and a test Effect's HTTP protocol, which
84
- // answers in memory.
85
69
  export const rpc = ActionRpc.layer(Rpc, implementations, {
86
70
  middleware: [RpcQuota],
87
71
  }).pipe(Layer.provide([authenticateSession, quota, assistantTools]));
88
72
 
89
- // Effect's own tools read the binding's native `HttpApi`: the OpenAPI document and a Swagger
90
- // UI, each showing the bearer scheme on every route but `getStatus`.
91
73
  const documentation = Layer.mergeAll(
92
74
  HttpRouter.add(
93
75
  "GET",
@@ -99,27 +81,6 @@ const documentation = Layer.mergeAll(
99
81
 
100
82
  const health = HttpRouter.add("GET", "/healthz", HttpServerResponse.text("ok"));
101
83
 
102
- // The public port's HTTP routes: what members reach, but for the rpcs, which server.ts serves
103
- // beside these. Each `Layer.provide` gives what the layers before it still owe, and is built
104
- // before them. Two things follow from that order.
105
- //
106
- // - `resolveTenant`, in a `Layer.provide` of its own after the authentication, gives the
107
- // `Tenant` the Bearer verifier reads per request; tenant.ts says why not in one array.
108
- // - Global middleware runs in the order it registers, and it registers when its layer is
109
- // built. The request policy, provided last, is built first, so it runs before everything:
110
- // before CORS, and before the OAuth discovery the Bearer provider registers when it is
111
- // built. Merged beside the routes instead, it would register after that provider, and a
112
- // foreign Host could read the discovery document.
113
- //
114
- // The assistant's builder yields its tools, so their handlers are provided to the layers
115
- // serving it, here and on `rpc`: one Layer, built once in the layer graph serving both, where
116
- // the tools run the issue implementation the routes serve, with no second build of it.
117
- //
118
- // Webhook delivery serves MCP's `events/subscribe` and HTTP's
119
- // `POST /api/v1/events/issue.changed/subscribe`: a member names a callback URL and a secret,
120
- // and each change it may see is POSTed there, signed. One layer holds the subscriptions of
121
- // both. It POSTs with an `HttpClient` and checks where each callback resolves with `Dns`, which
122
- // server.ts provides.
123
84
  export const publicRoutes = Layer.mergeAll(
124
85
  api,
125
86
  mcp,
@@ -135,20 +96,11 @@ export const publicRoutes = Layer.mergeAll(
135
96
  Layer.provide(requestPolicy)
136
97
  );
137
98
 
138
- // The admin port: what operators reach, and nothing else. It is a router of its own, with its
139
- // own binding, descriptor and provider, so no member's token is even understood here. It
140
- // serves one implementation the public port serves too, `status`.
141
99
  export const adminRoutes = Layer.mergeAll(
142
100
  ActionHttp.layer(AdminHttp, [status, admin]),
143
101
  health
144
102
  ).pipe(Layer.provide(authenticateOperator), Layer.provide(requestPolicy));
145
103
 
146
- // Every builder as one layer. The two ports are two layer graphs, and each would run the
147
- // builder of an implementation it serves: `status`, which both serve, twice, each port then
148
- // reporting an `instance` of its own. Provided above both, with the services, each builder
149
- // runs once for every surface of both ports. The assistant's, the export's and the event's are
150
- // left out: the public port alone serves them, and builds each once for its routes and its
151
- // rpcs.
152
104
  export const builders = Action.layer([
153
105
  status,
154
106
  identity,
@@ -5,16 +5,11 @@ import { HttpClient, HttpClientRequest } from "effect/http";
5
5
  import { Http } from "./Api.js";
6
6
  import type { Issue } from "./issues/Issues.js";
7
7
 
8
- // Entrypoint for code written with promises: an integration, a bot, another product's page.
9
- // It imports the binding and nothing of the server, so a bundler keeps the contracts and
10
- // Effect's fetch client, no handler.
11
8
  export const connect = (options: {
12
9
  readonly url: string;
13
10
  readonly token: string;
14
11
  readonly workspace: string;
15
12
  }) => {
16
- // Built once, outside any Effect, over `fetch`: its methods require nothing, so each call
17
- // runs with `Effect.runPromise`.
18
13
  const api = ActionHttp.fetchClient(Http, {
19
14
  baseUrl: options.url,
20
15
  transformClient: HttpClient.mapRequest(
@@ -26,8 +21,6 @@ export const connect = (options: {
26
21
  });
27
22
 
28
23
  return {
29
- // A method takes the action's decoded input, so a field with a decoding default is given
30
- // here; only a call without any argument sends `{}` and gets the defaults.
31
24
  openIssues: async (limit = 20) =>
32
25
  await Effect.runPromise(
33
26
  Effect.map(
@@ -36,20 +29,15 @@ export const connect = (options: {
36
29
  )
37
30
  ),
38
31
 
39
- // A declared error is a typed failure, handled by its tag: a missing issue is `undefined`.
40
32
  issue: async (id: string): Promise<Issue | undefined> =>
41
33
  await api.getIssue({ id }).pipe(
42
34
  Effect.catchTag("IssueNotFound", () => Effect.undefined),
43
35
  Effect.runPromise
44
36
  ),
45
37
 
46
- // Left unhandled, a declared error rejects the promise as its decoded value, so a caller's
47
- // `catch` may test `error instanceof RateLimited`.
48
38
  file: async (title: string, body: string) =>
49
39
  await Effect.runPromise(api.createIssue({ title, body })),
50
40
 
51
- // A stream action's method returns a `Stream`; as an async iterable, `for await` reads each
52
- // issue as the server sends it.
53
41
  exportAll: (): AsyncIterable<Issue> =>
54
42
  Stream.toAsyncIterable(api.exportIssues({})),
55
43
  };
@@ -7,12 +7,6 @@ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
7
7
 
8
8
  import { Http } from "./Api.js";
9
9
 
10
- // Entrypoint: `node --import tsx examples/kitchen-sink/src/seed.ts`, with the server running.
11
- // An Effect program calling the API with the binding's typed client: one method per action,
12
- // taking its input and answering its decoded success. DEMO ONLY: it files a first issue in
13
- // `acme` as `ada`, since the server's stores start empty.
14
-
15
- // A one-pixel PNG stands in for a screenshot.
16
10
  const screenshot = Buffer.from(
17
11
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
18
12
  "base64"
@@ -25,7 +19,6 @@ const seed = Effect.gen(function* () {
25
19
 
26
20
  const tracker = yield* ActionHttp.client(Http, {
27
21
  baseUrl,
28
- // Every request of this client: the token, and the header naming the workspace.
29
22
  transformClient: HttpClient.mapRequest(
30
23
  flow(
31
24
  HttpClientRequest.bearerToken("ada"),
@@ -39,7 +32,6 @@ const seed = Effect.gen(function* () {
39
32
  body: "Saving an empty draft crashes the editor.",
40
33
  });
41
34
 
42
- // Over HTTP the image is JSON, its bytes in base64: the client encodes the `Uint8Array`.
43
35
  const attachment = yield* tracker.attachImage({
44
36
  issue: issue.id,
45
37
  name: "crash.png",
@@ -55,8 +47,6 @@ const seed = Effect.gen(function* () {
55
47
  issues
56
48
  );
57
49
  }).pipe(
58
- // A declared error is a typed failure, the binding's and the verifier's included: each is
59
- // handled by its tag. Anything else, such as an unreachable server, stays Effect's own.
60
50
  Effect.catchTags({
61
51
  RateLimited: ({ retryAfterSeconds }) =>
62
52
  Console.error(`Write limit reached: retry in ${retryAfterSeconds}s.`),
@@ -8,12 +8,6 @@ import { RpcSerialization, RpcServer } from "effect/rpc";
8
8
  import { memory } from "./memory.js";
9
9
  import { adminRoutes, builders, publicRoutes, rpc } from "./routes.js";
10
10
 
11
- // Entrypoint: `node --import tsx examples/kitchen-sink/src/server.ts`.
12
- // The entrypoint of the server: two listeners over one set of builders and services.
13
-
14
- // The web app's rpcs over a WebSocket at `/rpc`: Node's HTTP server answers the upgrade. The
15
- // protocol is this entrypoint's choice, as the ports are. `rpc` leaves it open, so a test
16
- // serves the same layer over Effect's HTTP protocol.
17
11
  const socket = rpc.pipe(
18
12
  Layer.provide(RpcServer.layerProtocolWebsocket({ path: "/rpc" })),
19
13
  Layer.provide(RpcSerialization.layerJson)
@@ -21,7 +15,6 @@ const socket = rpc.pipe(
21
15
 
22
16
  const server = Layer.unwrap(
23
17
  Effect.gen(function* () {
24
- // The loopback default serves this machine alone; HOST=0.0.0.0 lets others reach it.
25
18
  const host = yield* Config.String("HOST").pipe(
26
19
  Config.withDefault("127.0.0.1")
27
20
  );
@@ -40,36 +33,21 @@ const server = Layer.unwrap(
40
33
  NodeHttpServer.layer(createServer, {
41
34
  host,
42
35
  port,
43
- // A message on the WebSocket of `/rpc` is no request body, so the limit below does not
44
- // bound it: Node's WebSocket server reads one of up to 100 MiB whole unless told
45
- // otherwise. A larger one closes the socket (1009).
46
36
  websocket: { maxPayload: Number(limit) },
47
37
  });
48
38
 
49
39
  return Layer.mergeAll(
50
- // Two audiences, two listeners, each with a router of its own: the public port can only
51
- // ever reach the members' routes. The socket is merged into the public port's routes, so
52
- // it is a route of that router: the request policy, global to the router, refuses a
53
- // foreign Origin's upgrade as it does a request, and the rpcs spend the quota the routes
54
- // spend, built once.
55
40
  HttpRouter.serve(Layer.merge(publicRoutes, socket)).pipe(
56
41
  Layer.provide(listen(publicPort))
57
42
  ),
58
43
  HttpRouter.serve(adminRoutes).pipe(Layer.provide(listen(adminPort)))
59
44
  ).pipe(
60
- // Request bodies have no size limit unless the host sets one. This covers every route
61
- // that reads its body whole, on both ports, the MCP endpoint included.
62
45
  Layer.provide(Layer.succeed(HttpServerRequest.MaxBodySize, limit)),
63
- // What both ports share is provided outside both: the builders, as routes.ts says, then
64
- // the services the verifiers and the quota are built from, so a workspace an operator
65
- // suspends on one port is refused on the other.
66
46
  Layer.provide(builders),
67
47
  Layer.provide(memory),
68
- // Webhook delivery POSTs with fetch, and resolves each callback with the system's resolver.
69
48
  Layer.provide([FetchHttpClient.layer, NodeDns.layer])
70
49
  );
71
50
  })
72
51
  );
73
52
 
74
- // NodeRuntime handles signals: the scoped layers stop both listeners and release the services.
75
53
  Layer.launch(server).pipe(NodeRuntime.runMain());
@@ -7,36 +7,26 @@ import { Tools } from "./Actions.js";
7
7
  import { attachments } from "./attachments/handlers.js";
8
8
  import { identity } from "./identity/handlers.js";
9
9
  import { CurrentMember } from "./identity/Identity.js";
10
- import { members } from "./identity/members.js";
10
+ import { demoMembers } from "./identity/members.js";
11
11
  import { features } from "./issues/guide.js";
12
12
  import { issues } from "./issues/handlers.js";
13
13
  import { limiter, stores } from "./memory.js";
14
14
  import { status } from "./workspaces/handlers.js";
15
15
  import { WorkspaceRegistry } from "./workspaces/registry.js";
16
16
 
17
- // Entrypoint: an MCP server a local agent starts as a subprocess, such as
18
- // `claude mcp add tracker -- "$PWD/node_modules/.bin/tsx" "$PWD/examples/kitchen-sink/src/stdio.ts"`
19
- // from the repository root. The host starts the process in a directory it chooses, so `tsx`
20
- // and the file are named by full path.
21
- // It lists the implementations it serves itself, and imports nothing of the HTTP router. They
22
- // are those of the `/mcp` endpoint, with its tools and features and the same `authorize`.
23
- // stdio is a local surface: it takes no `authentication`, since no token arrives.
24
17
  ActionMcp.runStdio([status, identity, issues, attachments], {
25
18
  name: "tracker",
26
19
  version: "1.0.0",
27
20
  actions: Tools,
28
21
  features,
29
22
  }).pipe(
30
- // The host names the caller itself, around every call. DEMO ONLY: a real host reads who
31
- // started it, from its own login or configuration.
32
- Effect.provideService(CurrentMember, members.ada),
23
+ Effect.provideService(CurrentMember, demoMembers.ada),
33
24
  Effect.provide([
34
25
  NodeStdio.layer,
35
26
  stores,
36
27
  limiter,
37
28
  WorkspaceRegistry.layerMemory,
38
29
  ]),
39
- // stdout carries the protocol alone, so logs and failures go to stderr.
40
30
  ActionCli.logToStderr,
41
31
  NodeRuntime.runMain()
42
32
  );
@@ -14,13 +14,9 @@ export class WorkspaceNotFound extends Schema.TaggedError<
14
14
  { readonly brand: unique symbol }
15
15
  >()("WorkspaceNotFound", { slug: Schema.String }, { httpApiStatus: 404 }) {}
16
16
 
17
- // Public: `caller: Action.Anyone`. It answers before anyone has signed in, on every surface,
18
- // so it tells nothing that depends on the caller.
19
17
  export const GetStatus = Action.make("getStatus", {
20
18
  description:
21
19
  "Report whether the tracker is up, since which start, and how many workspaces it serves.",
22
- // `instance` names one start of the process: it changes on a restart, and with it the demo's
23
- // memory stores are empty again.
24
20
  success: {
25
21
  service: Schema.String,
26
22
  instance: Schema.String,
@@ -4,10 +4,6 @@ import { Effect } from "effect";
4
4
  import { WorkspaceRegistry } from "./registry.js";
5
5
  import { GetStatus } from "./Workspaces.js";
6
6
 
7
- // One action, one handler, built once: the builder yields the registry at startup, and names
8
- // this start of the process. Both ports serve this implementation, so what the builder makes
9
- // tells whether they share one run of it (see `builders` in routes.ts). A public action takes
10
- // no `authorize`: nothing would run it.
11
7
  export const status = Action.implement(
12
8
  GetStatus,
13
9
  Effect.gen(function* () {
@@ -3,10 +3,6 @@ import { Context, Effect, Layer } from "effect";
3
3
  import { WorkspaceNotFound } from "./Workspaces.js";
4
4
  import type { Workspace } from "./Workspaces.js";
5
5
 
6
- /**
7
- * The tenants. Operators list and suspend them on the admin port; authentication reads the
8
- * suspension on the public one, so both servers must share this one service.
9
- */
10
6
  export class WorkspaceRegistry extends Context.Service<
11
7
  WorkspaceRegistry,
12
8
  {
@@ -18,7 +14,6 @@ export class WorkspaceRegistry extends Context.Service<
18
14
  ) => Effect.Effect<Workspace, WorkspaceNotFound>;
19
15
  }
20
16
  >()("tracker/WorkspaceRegistry") {
21
- // DEMO ONLY: two workspaces in memory. A real registry is another Layer of this service.
22
17
  static readonly layerMemory = Layer.sync(WorkspaceRegistry, () => {
23
18
  const workspaces = new Map<string, Workspace>([
24
19
  ["acme", { slug: "acme", name: "Acme", suspended: false }],
@@ -10,10 +10,6 @@ export class Tenant extends Context.Service<Tenant, Option.Option<string>>()(
10
10
  "tracker/Tenant"
11
11
  ) {}
12
12
 
13
- // Native router middleware. It provides `Tenant` to whatever it is provided to, per request:
14
- // to the verifier too, when it is provided after the authentication, in a `Layer.provide` of
15
- // its own: in one array with the authentication it would leave `Tenant` owed, since an array's
16
- // layers provide to the routes, not to one another.
17
13
  export const resolveTenant = HttpRouter.middleware<{ provides: Tenant }>()(
18
14
  (route) =>
19
15
  Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) =>
@@ -63,7 +63,6 @@ describe("the operators", () => {
63
63
  const client = yield* Action.client(admin);
64
64
  const suspend = client.suspendWorkspace({ workspace: "globex" });
65
65
 
66
- // No grants are stored for either: only the operator a host supplies is trusted.
67
66
  expect(
68
67
  yield* suspend.pipe(
69
68
  Effect.provideService(Operator, { id: "console", trusted: true })