@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
package/README.md CHANGED
@@ -76,10 +76,10 @@ Effect.gen(function* () {
76
76
  ## Install
77
77
 
78
78
  ```sh
79
- pnpm add @gjermundgaraba/effect-actions effect@~4.0.5
79
+ pnpm add @gjermundgaraba/effect-actions effect@~4.1.0
80
80
  ```
81
81
 
82
- It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.0.5` to serve or run a CLI from Node, and `@types/node` for its `node:` imports. Every module is a subpath import (`.../Action`, `.../ActionHttp`, ...); there is no package root, so a contracts-only bundle never loads a server.
82
+ It needs TypeScript 7 or newer and is ESM only ([docs/setup.md](docs/setup.md#install)). Add `@effect/platform-node@~4.1.0` to serve or run a CLI from Node, and `@types/node` for its `node:` imports. Every module is a subpath import (`.../Action`, `.../ActionHttp`, ...); there is no package root, so a contracts-only bundle never loads a server.
83
83
 
84
84
  ## Examples
85
85
 
@@ -131,4 +131,10 @@ A few ideas (like the native Toolkit and CLI projections) are inspired by the ex
131
131
 
132
132
  ## Contributing
133
133
 
134
- The rules for changing the library are in [AGENTS.md](https://github.com/gjermundgaraba/effect-actions/blob/main/AGENTS.md). MIT licensed.
134
+ Set up with [Vite+](https://viteplus.dev/guide/): `vp install`, then `vp run ready` runs every check. The rules for changing the library are in [AGENTS.md](https://github.com/gjermundgaraba/effect-actions/blob/main/AGENTS.md). MIT licensed.
135
+
136
+ ## Releasing
137
+
138
+ Bump the version in `package.json` and `packages/cloudflare/package.json`, commit, tag `v<version>` and push the tag. `.github/workflows/npm.yml` then publishes every package whose version npm does not have yet, the core first, through npm trusted publishing. A new package's first version is published by hand with `vp pm publish`, followed by `npm trust github <package> --repo <repo> --file npm.yml` so the workflow can publish the next.
139
+
140
+ `.github/workflows/effect-latest.yml` runs the full check weekly against the newest Effect 4.x, so a minor release that passes can be admitted to the `effect` peer range.
package/dist/Action.d.mts CHANGED
@@ -253,10 +253,10 @@ type NamesOf<T extends Target> = ActionsOf<T>["name"];
253
253
  type KeepsAnswers<T extends Target> = [Extract<ActionsOf<T>, {
254
254
  readonly idempotencyKey: string;
255
255
  }>] extends [never] ? never : Idempotency;
256
- type NoHandler<R> = {
256
+ type InferenceAnchor<R> = {
257
257
  readonly "~list": R;
258
258
  };
259
- type Single<T extends Target, R> = T extends Any ? (input: T["input"]["Type"], ...reporting: ReportingOf<T>) => Answer<T["success"], T["error"][number]["Type"] | BuiltIn, R> : NoHandler<R>;
259
+ type Single<T extends Target, R> = T extends Any ? (input: T["input"]["Type"], ...reporting: ReportingOf<T>) => Answer<T["success"], T["error"][number]["Type"] | BuiltIn, R> : InferenceAnchor<R>;
260
260
  type Several<T extends Target, RequestServices> = { readonly [K in keyof RequestServices]: K extends NamesOf<T> ? Handler<Extract<ActionsOf<T>, {
261
261
  readonly name: K;
262
262
  }>, RequestServices[K]> : never; };
package/dist/Action.mjs CHANGED
@@ -120,6 +120,7 @@ const watcherOf = (feeds) => (event, input, options) => {
120
120
  name: event.name,
121
121
  poll: polledOn("In process", event.name)((cursor) => feed.poll(value, cursor, { subscriber })),
122
122
  stream: (cursor) => Stream$1.unwrap(Effect.flatMap(feed.stream(value), (open) => Effect.map(queuedPush(open, cursor, Effect.succeed, {
123
+ ending: Function.identity,
123
124
  inOrder: true,
124
125
  capacity: 1
125
126
  }), (queue) => Stream$1.fromQueue(queue)))).pipe(readOn("In process", event.name))
@@ -104,7 +104,7 @@ type WatchServices<C, E extends Any> = [E] extends [never] ? never : C extends E
104
104
  * - Each value an action declaring `progress` reports is one line of compact JSON on stderr, as it arrives, so stdout holds the answer alone; `remoteCommand` asks the server for them too.
105
105
  * - An action answering a stream prints each element on stdout as it arrives, one line of compact JSON, or `render`'s text of it; a declared failure ends the command after the elements before it.
106
106
  * - A declared error is its JSON on stderr, under Effect CLI's `ERROR` heading, the command failing with a `UserError` whose `cause` is the error, exit 1 or its `Runtime.errorExitCode`; a refusal as `Action.Unauthenticated` and `Action.Forbidden` say; input that does not decode, in `--input` or a flag's JSON value, is `InvalidInput`'s JSON there, while a missing flag or a rejected choice is Effect CLI's own parse error.
107
- * - Effect CLI styles what it prints, a failure's JSON included, on a terminal and, from Effect 4.0.6, wherever `FORCE_COLOR` forces colour: for plain text there, set `NO_COLOR` or provide `TerminalCapabilities.TerminalCapabilities` with `canColor: false`.
107
+ * - Effect CLI styles what it prints, a failure's JSON included, on a terminal and wherever `FORCE_COLOR` forces colour: for plain text there, set `NO_COLOR` or provide `TerminalCapabilities.TerminalCapabilities` with `canColor: false`.
108
108
  * - A failure no schema encodes, a builder's or an accepted error that does not encode, is a `UserError` printed as its tag or name and its message, then its causes, never its other fields; a defect, an undeclared failure, or a success that does not encode is the command's defect, which `runMain` reports as `logToStderr` says.
109
109
  * - Provide services with `Command.provide` on the command, built when an action runs: provided around `Command.run`, they are built before parsing, so `--help` and a mistyped flag open the database.
110
110
  * - Each run builds the action's implementation, its builder and an authorizer an Effect builds, and releases them after the call, even where the host already built them; implementations passed beside it are not built.
@@ -54,7 +54,6 @@ const overHttp = (binding, action, options, client) => {
54
54
  return Stream.isStream(answer) ? Effect.succeed(answer) : answer;
55
55
  }), options, bindingErrors(action, binding));
56
56
  };
57
- /** The command watching `event` through the `watch` of each client `client` makes as it runs. */
58
57
  const watched = (event, client, errors) => watchCommand(event, (input, cursor) => Stream.unwrap(Effect.map(client, (methods) => methods.watch(event, input, { cursor }))), errors);
59
58
  const aggregateCommand = (name, actions, commands, own, project, watches) => {
60
59
  const derived = [...actions.map((action) => ({
@@ -95,7 +94,7 @@ const checkedCommandsOf = (commands, actions) => {
95
94
  * - Each value an action declaring `progress` reports is one line of compact JSON on stderr, as it arrives, so stdout holds the answer alone; `remoteCommand` asks the server for them too.
96
95
  * - An action answering a stream prints each element on stdout as it arrives, one line of compact JSON, or `render`'s text of it; a declared failure ends the command after the elements before it.
97
96
  * - A declared error is its JSON on stderr, under Effect CLI's `ERROR` heading, the command failing with a `UserError` whose `cause` is the error, exit 1 or its `Runtime.errorExitCode`; a refusal as `Action.Unauthenticated` and `Action.Forbidden` say; input that does not decode, in `--input` or a flag's JSON value, is `InvalidInput`'s JSON there, while a missing flag or a rejected choice is Effect CLI's own parse error.
98
- * - Effect CLI styles what it prints, a failure's JSON included, on a terminal and, from Effect 4.0.6, wherever `FORCE_COLOR` forces colour: for plain text there, set `NO_COLOR` or provide `TerminalCapabilities.TerminalCapabilities` with `canColor: false`.
97
+ * - Effect CLI styles what it prints, a failure's JSON included, on a terminal and wherever `FORCE_COLOR` forces colour: for plain text there, set `NO_COLOR` or provide `TerminalCapabilities.TerminalCapabilities` with `canColor: false`.
99
98
  * - A failure no schema encodes, a builder's or an accepted error that does not encode, is a `UserError` printed as its tag or name and its message, then its causes, never its other fields; a defect, an undeclared failure, or a success that does not encode is the command's defect, which `runMain` reports as `logToStderr` says.
100
99
  * - Provide services with `Command.provide` on the command, built when an action runs: provided around `Command.run`, they are built before parsing, so `--help` and a mistyped flag open the database.
101
100
  * - Each run builds the action's implementation, its builder and an authorizer an Effect builds, and releases them after the call, even where the host already built them; implementations passed beside it are not built.
@@ -138,7 +138,7 @@ export interface Binding<Actions extends readonly Any$1[], E extends Errors = []
138
138
  */
139
139
  export declare function make<const Contracts extends ReadonlyArray<(Any$1 | Any) & {
140
140
  readonly caller: typeof Anyone;
141
- }>>(contracts: Contracts): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
141
+ }>>(contracts: Contracts, options?: Pick<Options$1, "prefix">): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
142
142
  export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>, const O extends Options$1 = {}>(contracts: Contracts, options: O & Required<Contracts[number]> & Matching<Contracts[number], NoInfer<DescriptorOf<O>>> & NoInfer<Known<O, Options$1>>): Binding<Only<Contracts, Any$1>, ErrorsOf<O>, DescriptorOf<O>, Only<Contracts, Any>>;
143
143
  export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>>(contracts: Contracts & PublicOnly<Contracts>): Binding<Only<Contracts, Any$1>, [], undefined, Only<Contracts, Any>>;
144
144
  /**
@@ -168,7 +168,7 @@ export declare function make<const Contracts extends ReadonlyArray<Any$1 | Any>>
168
168
  * - The 415 keeps from every handler what another site's page can send without a CORS preflight, such as a form post carrying the user's cookie; the server's CORS policy decides the rest.
169
169
  * - Router middleware providing a request service `X` is declared `HttpRouter.middleware<{ provides: X }>()`: without the type argument it runs and the layer still owes `X`.
170
170
  * - `HttpRouter.provideRequest(layer)` builds its layer once, at startup, so it never provides an identity or a tenant.
171
- * - A request body is read whole, however large, unless the host provides `HttpServerRequest.MaxBodySize` to `HttpRouter.serve`, limiting every route that reads its body whole, MCP endpoints included; a body a route reads as a stream is not limited. On Node a request over it is an empty 413 from Effect 4.0.6, and before it gets no response, its connection closed; `HttpRouter.toWebHandler` ignores it, so limit bodies in the platform serving the handler.
171
+ * - A request body is read whole, however large, unless the host provides `HttpServerRequest.MaxBodySize` to `HttpRouter.serve`, limiting every route that reads its body whole, MCP endpoints included; a body a route reads as a stream is not limited. A request over it is an empty 413. Under `HttpRouter.toWebHandler` provide it with `HttpRouter.provideRequest`: `Layer.provide` around the routes limits `ActionHttp`'s and no MCP endpoint.
172
172
  * - An `ErrorReporter` the server runs with is given, as `Info`, a handler's declared failure and an input that does not decode, never a refusal or a refused credential: give an error class `override readonly [ErrorReporter.ignore] = true` to keep it out, and drop `Info` for a built-in error, which takes no mark.
173
173
  * - An event's route takes `{ input, cursor }`, a `cursor` omitted or `null` reading from now, and answers a page, `{ events, cursor, truncated, hasMore, nextPollMs }`, or, to a request accepting `text/event-stream`, an SSE stream of `Checked`, `Occurrence`, `Gap` and `Failed` data, a `Checked` every 30 seconds; the stream carries no `id:`, so `Last-Event-ID` resumes nothing: resume from a cursor in the body.
174
174
  * - A subscription is refused as an action's call is, before its stream starts, with the route's 401 or 403; a refusal later ends the stream with Effect's `effect/http-api/stream/failure` event.
@@ -6,15 +6,16 @@ import { Any as Any$2, Matching, ProviderOf, RemoteRequest, Required, ServerBuil
6
6
  import { McpCallError } from "./mcp/reply.mjs";
7
7
  import { Client, ClientOptions, client } from "./mcp/client.mjs";
8
8
  import { Params, RequestOptions, request } from "./mcp/request.mjs";
9
- import { Cause, Effect, Layer, Stdio } from "effect";
9
+ import { Cause, Effect, Layer, Scope, Stdio } from "effect";
10
10
  import { HttpRouter } from "effect/http";
11
11
  import { McpSchema, McpServer } from "effect/ai";
12
12
  /**
13
- * An MCP server, over HTTP or stdio: every native `McpServer.layerStdio` option but `protocols`,
14
- * the server information, `instructions` and `extensions` among them, the actions `A` that are
15
- * its tools and the event types `A` it serves, and the native features it serves beside them.
13
+ * An MCP server, over HTTP or stdio: every native `McpServer.layerStdio` option but `protocols`
14
+ * and `registrations`, the server information, `instructions`, `extensions` and `cacheHints`
15
+ * among them, the actions `A` that are its tools and the event types `A` it serves, and the
16
+ * native features it serves beside them.
16
17
  */
17
- export interface Options<E = never, R = never, A extends Any$1 | Any = Any$1 | Any> extends Omit<Parameters<typeof McpServer.layerStdio>[0], "protocols"> {
18
+ export interface Options<E = never, R = never, A extends Any$1 | Any = Any$1 | Any> extends Omit<Parameters<typeof McpServer.layerStdio>[0], "protocols" | "registrations"> {
18
19
  /**
19
20
  * The actions that are tools and the event types it serves, among the implementations':
20
21
  * `[GetUser, RenameUser, UserRenamed]`, exactly those. Each keeps its implementation's
@@ -27,24 +28,25 @@ export interface Options<E = never, R = never, A extends Any$1 | Any = Any$1 | A
27
28
  readonly actions?: readonly A[] | undefined;
28
29
  /**
29
30
  * Native MCP features served beside the actions' tools, such as `McpServer.resource`,
30
- * `McpServer.prompt` and `McpServer.toolkit` layers merged into one. They register on this
31
- * server's registry and run with the services they were built with, and no `authorize` runs for
32
- * them.
31
+ * `McpServer.prompt` and `McpServer.toolkit` layers merged into one: Effect's `registrations`,
32
+ * registered on this server's registry before it reads a request. No `authorize` runs for them.
33
33
  *
34
34
  * **Gotchas**
35
35
  *
36
- * - Merged beside the endpoint instead of passed here, they register on another registry and are never served, without an error.
37
- * - A service provided to this layer itself is built again for the features alone, so a resource reads another store than the tools write: provide it around the endpoint.
38
- * - They never receive a request's services, so they cannot read the caller: content that depends on the caller is an action.
36
+ * - Merged beside the endpoint instead of passed here, they need an `McpServer` nothing provides: a type error, and `Service not found: effect/ai/McpServer` as the layer builds.
37
+ * - A service a handler reads is a request's, in the endpoint's `Request<"Requires", X>`, as a tool's is: provide it with router middleware, or around `runStdio`. `Layer.provide` does not satisfy it.
38
+ * - A service known at startup is read in a `Layer.unwrap` around the feature, which closes over it: the endpoint then needs it at startup, and shares it with the tools.
39
+ * - A layer provided to this layer itself is built again for the features alone, so a resource reads another store than the tools write: provide it around the endpoint.
40
+ * - They cannot read the caller, which `authentication` gives protected tools alone: content that depends on the caller is an action.
39
41
  */
40
42
  readonly features?: Layer.Layer<never, E, R> | undefined;
41
43
  }
42
44
  /**
43
45
  * One Streamable HTTP MCP endpoint: `Options`, `authentication`, `requestScoped`, and every native
44
- * `McpServer.layerHttp` option, `allowedOrigins` among them, except `protocols` and
45
- * `allowSessionTermination`, which are fixed.
46
+ * `McpServer.layerHttp` option, `allowedOrigins` among them, except `protocols`, `registrations`
47
+ * and `allowSessionTermination`, which are fixed.
46
48
  */
47
- export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any = Any$1 | Any> extends Options<E, R, A>, Omit<Parameters<typeof McpServer.layerHttp>[0], "protocols" | "path" | "allowSessionTermination"> {
49
+ export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any = Any$1 | Any> extends Options<E, R, A>, Omit<Parameters<typeof McpServer.layerHttp>[0], "protocols" | "path" | "allowSessionTermination" | "registrations"> {
48
50
  /** The endpoint's route; defaults to `/mcp`. */
49
51
  readonly path?: HttpRouter.PathInput;
50
52
  /**
@@ -86,12 +88,10 @@ export interface LayerHttpOptions<E = never, R = never, A extends Any$1 | Any =
86
88
  }
87
89
  type ToolRequestContext<R> = Exclude<R, McpSchema.McpRequestContext | McpServer.McpServer>;
88
90
  type HttpToolRequestContext<R> = Exclude<ToolRequestContext<R>, HttpRouter.Provided>;
89
- type Features<R> = Exclude<R, McpServer.McpServer>;
90
- /** The actions and event types an endpoint of `Apps` given the options `O` serves. */
91
+ type Features<R> = Exclude<McpServer.McpRequest.Without<R>, McpServer.McpServer>;
92
+ type FeatureRequest<R> = McpServer.McpRequest.Only<"Requires", R>;
91
93
  type Contracts<Apps extends Served, O> = SelectedOf<O, Apps> | SelectedEventsOf<O, Apps>;
92
- /** What building an endpoint of `Apps` given the options `O` may fail with. */
93
94
  type ServerError<Apps extends Served, O> = BuildError<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventBuildError<HoldingEvents<Member<Apps>, SelectedEventsOf<O, Apps>>, SelectedEventsOf<O, Apps>> | Cause.IllegalArgumentError;
94
- /** What building the event sources of an endpoint of `Apps` given the options `O` needs. */
95
95
  type EventServices<Apps extends Served, O> = EventBuildServices<HoldingEvents<Member<Apps>, SelectedEventsOf<O, Apps>>, SelectedEventsOf<O, Apps>>;
96
96
  type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [Protected<A>] extends [never] ? {
97
97
  readonly authentication?: undefined;
@@ -133,7 +133,7 @@ type Inferring<D, A extends Pick<Any$1, "caller">> = [D] extends [undefined] ? [
133
133
  * - A poll's `maxEvents` caps a log source's page, at most 100, and is not honored for a check source, whose page is answered whole since only its last cursor resumes; `maxAgeMs` is accepted and not honored, a log source keeping what its `log.maxAge` and `log.maxEvents` say.
134
134
  * - A push stream's failure that no refusal explains, such as an upstream's outage, is `notifications/events/error`, its cause logged and reported, and the stream resumes from where it reached after 5 seconds; a refusal ends it with `notifications/events/terminated`. One before `active`, or a poll's, is a JSON-RPC `-32603`, which `client`'s `watch` reconnects after, as after a 5xx.
135
135
  */
136
- export declare function layerHttp<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never, const D extends Any$2 | undefined = undefined>(implementations: Apps, options: LayerHttpOptions<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, LayerHttpOptions<E, R>>> & NoInfer<Required<Contracts<Apps, O>>> & Matching<NoInfer<Contracts<Apps, O>>, NoInfer<D>> & Inferring<D, NoInfer<Contracts<Apps, O>>>): Layer.Layer<never, ServerError<Apps, O> | E, ServerBuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", HttpToolRequestContext<RemoteRequest<Member<Apps>, SelectedOf<O, Apps>> | EventServedRequest<Member<Apps>, SelectedEventsOf<O, Apps>>>> | ProviderOf<D> | Features<R>>;
136
+ export declare function layerHttp<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never, const D extends Any$2 | undefined = undefined>(implementations: Apps, options: LayerHttpOptions<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, LayerHttpOptions<E, R>>> & NoInfer<Required<Contracts<Apps, O>>> & Matching<NoInfer<Contracts<Apps, O>>, NoInfer<D>> & Inferring<D, NoInfer<Contracts<Apps, O>>>): Layer.Layer<never, ServerError<Apps, O> | E, ServerBuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | HttpRouter.HttpRouter | HttpRouter.Request.From<"Requires", HttpToolRequestContext<RemoteRequest<Member<Apps>, SelectedOf<O, Apps>> | EventServedRequest<Member<Apps>, SelectedEventsOf<O, Apps>> | FeatureRequest<R>>> | ProviderOf<D> | Features<R>>;
137
137
  /**
138
138
  * Serve MCP tools through newline-delimited JSON-RPC on standard I/O, speaking MCP
139
139
  * 2026-07-28, 2025-11-25 or 2025-06-18, as the host negotiates: the whole
@@ -150,5 +150,5 @@ export declare function layerHttp<const Apps extends Served, const O extends Sel
150
150
  * - A line that is not JSON goes unanswered, with no `-32700` as over HTTP, and the lines after it are still answered.
151
151
  * - The layers provided around it log to stdout, among the protocol's lines: apply `ActionCli.logToStderr` to the program, last, as its JSDoc says.
152
152
  */
153
- export declare function runStdio<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never>(implementations: Apps, options: Options<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, Options<E, R>>>): Effect.Effect<void, ServerError<Apps, O> | E, BuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | Stdio.Stdio | ToolRequestContext<ServedRequest<Member<Apps>, SelectedOf<O, Apps>> | EventRequestOf<Member<Apps>, SelectedEventsOf<O, Apps>>> | Features<R>>;
153
+ export declare function runStdio<const Apps extends Served, const O extends Selection<ActionOf<Member<Apps>> | EventOf<Member<Apps>>> = {}, E = never, R = never>(implementations: Apps, options: Options<E, R, ActionOf<Member<Apps>> | EventOf<Member<Apps>>> & O & NoInfer<Known<O, Options<E, R>>>): Effect.Effect<void, ServerError<Apps, O> | E, BuildServices<Holding<Member<Apps>, SelectedOf<O, Apps>>, SelectedOf<O, Apps>> | EventServices<Apps, O> | Stdio.Stdio | ToolRequestContext<ServedRequest<Member<Apps>, SelectedOf<O, Apps>> | EventRequestOf<Member<Apps>, SelectedEventsOf<O, Apps>> | Exclude<FeatureRequest<R>, Scope.Scope>> | Features<R>>;
154
154
  export { type Client, type ClientOptions, McpCallError, type Params, type RequestOptions, client, request };
@@ -113,17 +113,12 @@ const registerTools = Effect.fnUntraced(function* (apps, authentication) {
113
113
  });
114
114
  }
115
115
  });
116
- /**
117
- * Refuses event types an endpoint cannot serve as MCP events: one named twice, one named as MCP's
118
- * own, or one whose input or payload is no object.
119
- */
120
116
  const assertEventsServable = (events) => {
121
117
  assertOnce("MCP event", events);
122
118
  const reserved = events.find(({ name }) => name.startsWith("mcp."));
123
119
  if (reserved !== void 0) throw new Error(`MCP event name starts with "mcp.", which MCP keeps for its own events: ${reserved.name} (rename it, or serve it on another surface)`);
124
120
  for (const event of events) eventSchemasOf(event);
125
121
  };
126
- /** The revisions an endpoint speaks, the 2026-07-28 one serving `serving`'s events if any. */
127
122
  const servingEvents = ([stateless, ...rest], serving) => serving.events.length === 0 ? [stateless, ...rest] : [withEvents(stateless, serving), ...rest];
128
123
  const server = (apps, serving, transport, features = Layer.empty) => {
129
124
  const { events, authentication } = serving;
@@ -138,7 +133,7 @@ const server = (apps, serving, transport, features = Layer.empty) => {
138
133
  yield* serveWebhooks(serving);
139
134
  yield* registerTools(apps, authentication);
140
135
  });
141
- return Layer.effectDiscard(register).pipe(Layer.provide(features), Layer.provide(transport), Layer.fresh, provideServed({
136
+ return Layer.empty.pipe(Layer.provide(transport(Layer.effectDiscard(register).pipe(Layer.provide(features)))), Layer.fresh, provideServed({
142
137
  apps,
143
138
  events
144
139
  }));
@@ -188,16 +183,18 @@ function layerHttp(apps, { actions, features, path = defaultPath, authentication
188
183
  events,
189
184
  authentication
190
185
  };
191
- const transport = server(selected, serving, requestScoped === true ? McpServer.layerHttpRequestScoped({
186
+ const transport = server(selected, serving, (registrations) => requestScoped === true ? McpServer.layerHttpRequestScoped({
192
187
  ...options,
193
188
  path,
194
- protocols: servingEvents([httpProtocol], serving)
189
+ protocols: servingEvents([httpProtocol], serving),
190
+ registrations
195
191
  }) : McpServer.layerHttp({
196
192
  ...options,
197
193
  path,
198
194
  protocols: servingEvents(protocols, serving),
199
195
  allowSessionTermination: true,
200
- allowSubscriptions: allowSubscriptions ?? (features !== void 0 || events.length > 0)
196
+ allowSubscriptions: allowSubscriptions ?? (features !== void 0 || events.length > 0),
197
+ registrations
201
198
  }), features);
202
199
  if (authentication === void 0) return transport.pipe(Layer.provide(HttpRouter.middleware(readsItsBody).layer));
203
200
  const required = requiresAuthentication(served, listed);
@@ -216,9 +213,10 @@ function runStdio(apps, { actions, features, ...options }) {
216
213
  events,
217
214
  authentication: void 0
218
215
  };
219
- const transport = server(selected, serving, McpServer.layerStdio({
216
+ const transport = server(selected, serving, (registrations) => McpServer.layerStdio({
220
217
  ...options,
221
- protocols: servingEvents(protocols, serving)
218
+ protocols: servingEvents(protocols, serving),
219
+ registrations
222
220
  }).pipe(Layer.provide(jsonLinesOnly)), features);
223
221
  return Layer.launch(transport).pipe(withStderrConsole, Effect.forkChild, Effect.flatMap(Fiber.await), Effect.flatMap((exit) => Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause) ? Effect.failCause(exit.cause) : Effect.void));
224
222
  }
@@ -17,19 +17,11 @@ import { HttpRouter, HttpServerRequest } from "effect/http";
17
17
  import { Rpc, RpcClient, RpcClientError, RpcGroup, RpcMessage, RpcMiddleware, RpcSchema, RpcServer } from "effect/rpc";
18
18
  type BindingError = Errors[number];
19
19
  type ErrorOf<A extends Any$2, E extends Errors, D> = Schema.Union<ReadonlyArray<A["error"][number] | E[number] | VerifierError<A, D> | BuiltIns>>;
20
- /**
21
- * What the stream rpc of an action declaring `progress` sends: a `Progress` for each value its
22
- * handler reports, then a `Final` with its answer.
23
- */
24
20
  declare const ProgressedOf: <P extends Codec, S extends Codec>(progress: P, success: S) => Schema.Union<readonly [Schema.TaggedStruct<"Progress", {
25
21
  readonly value: P;
26
22
  }>, Schema.TaggedStruct<"Final", {
27
23
  readonly value: S;
28
24
  }>]>;
29
- /**
30
- * What the stream rpc of an action answering a stream sends: an `Element` for each element, and a
31
- * `Progress` for each value its handler reports where it declares `progress`.
32
- */
33
25
  type ElementedOf<Element extends Schema.Constraint, P> = Schema.Union<readonly [Schema.TaggedStruct<"Element", {
34
26
  readonly value: Element;
35
27
  }>, ...(P extends Codec ? [Schema.TaggedStruct<"Progress", {
@@ -40,10 +32,6 @@ type EventRpcOf<V extends Any$1, E extends Errors, D> = V extends Any$1 ? Rpc.Rp
40
32
  declare const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
41
33
  type RefusalOf<E extends Errors> = Schema.Union<ReadonlyArray<typeof Unauthenticated | E[number]>>;
42
34
  declare const authenticatedBrand: unique symbol;
43
- /**
44
- * The middleware authenticating a binding's native rpcs, as Effect's server reads it: what it
45
- * provides their handlers, and what it fails with.
46
- */
47
35
  interface Authenticated<I, E extends Errors = Errors> {
48
36
  readonly [authenticatedBrand]: typeof authenticatedBrand;
49
37
  readonly [RpcMiddleware.TypeId]: {
@@ -308,6 +296,13 @@ export type ClientOptions = Omit<NonNullable<Parameters<typeof RpcClient.make>[1
308
296
  * - A native rpc of the binding's `rpcs` is the native client's method: a stream rpc's is a `Stream`, its headers given as its options' `headers`, since `RpcClient.withHeaders` wraps an Effect.
309
297
  */
310
298
  export declare function client<const B extends Any>(binding: B, options?: ClientOptions): Effect.Effect<Client<B>, never, RpcClient.Protocol | Scope.Scope | Rpc.MiddlewareClient<RpcGroup.Rpcs<B["rpcs"]>>>;
299
+ /**
300
+ * What `reconnectUntil`'s schedule reads of each failure to connect: the `reason` of the
301
+ * `Socket.SocketError` Effect's socket protocol retries after.
302
+ */
303
+ export interface ReconnectReason {
304
+ readonly reason: unknown;
305
+ }
311
306
  /**
312
307
  * A socket client's `retryPolicy`, for `RpcClient.layerProtocolSocket`, that stops connecting
313
308
  * again once the server closes the socket with one of `codes`, such as a refusal of its upgrade:
@@ -321,7 +316,5 @@ export declare function client<const B extends Any>(binding: B, options?: Client
321
316
  * - A client without it connects again after a refusal as after any close, every five seconds for good.
322
317
  * - Any other socket error, a drop included, is retried as Effect's default retries it.
323
318
  */
324
- export declare const reconnectUntil: (...codes: readonly number[]) => Schedule.Schedule<import("effect/Duration").Duration, {
325
- readonly reason: unknown;
326
- }, never, never>;
319
+ export declare const reconnectUntil: (...codes: readonly number[]) => Schedule.Schedule<import("effect/Duration").Duration, ReconnectReason, never, never>;
327
320
  export {};
@@ -2,7 +2,7 @@ import { Anyone } from "./contract/caller.mjs";
2
2
  import { InvalidInput, Unauthenticated } from "./contract/errors.mjs";
3
3
  import { bindingErrors, bindingOf, eventErrors } from "./contract/declared.mjs";
4
4
  import { reservedList, reservedNames } from "./contract/names.mjs";
5
- import { Progressed, answerFrom, elementsFrom } from "./contract/progress.mjs";
5
+ import { answerFrom, elementsFrom } from "./contract/progress.mjs";
6
6
  import { elementOf } from "./contract/stream.mjs";
7
7
  import { acquire, elementsOf } from "./contract/implementation.mjs";
8
8
  import { checked, checkedStream, decodeInput, inputParseOptions, sendingJson, watchInput } from "./contract/call.mjs";
@@ -19,24 +19,18 @@ import { HttpClientRequest, HttpServerRequest } from "effect/http";
19
19
  import { HttpApiBuilder } from "effect/http-api";
20
20
  import { Rpc, RpcClient, RpcGroup, RpcMiddleware, RpcSchema, RpcServer } from "effect/rpc";
21
21
  // src/rpc/ActionRpc.ts
22
- /**
23
- * What the stream rpc of an action declaring `progress` sends: a `Progress` for each value its
24
- * handler reports, then a `Final` with its answer.
25
- */
26
22
  const ProgressedOf = (progress, success) => Schema.Union([Schema.TaggedStruct("Progress", { value: progress }), Schema.TaggedStruct("Final", { value: success })]);
27
23
  const elementedOf = (element, progress) => Schema.Union([Schema.TaggedStruct("Element", { value: element }), ...progress === void 0 ? [] : [Schema.TaggedStruct("Progress", { value: progress })]]);
28
- /** Whether `action`'s rpc is a stream rpc: it answers a stream, or declares `progress`. */
29
24
  const streams = (action) => action.progress !== void 0 || elementOf(action.success) !== void 0;
30
- /** What `action`'s rpc answers, or each element it streams where it is a stream rpc. */
31
- const sentOf = (action) => {
25
+ const streamedOf = (action) => {
32
26
  const element = elementOf(action.success);
33
27
  if (element !== void 0) return elementedOf(element, action.progress);
34
- return action.progress === void 0 ? action.success : ProgressedOf(action.progress, action.success);
28
+ return action.progress === void 0 ? void 0 : ProgressedOf(action.progress, action.success);
35
29
  };
30
+ const sentOf = (action) => streamedOf(action) ?? action.success;
36
31
  const authenticatedKey = "effect-actions/ActionRpc/Authenticated";
37
32
  const nativeOf = (group) => group;
38
33
  const authenticatedOf = (authentication) => RpcMiddleware.Service()(authenticatedKey, { error: Schema.Union([Unauthenticated, ...authentication.error]) });
39
- /** The middleware authenticating `rpc`, wherever among its middleware it runs. */
40
34
  const authenticatedIn = (rpc) => [...rpc.middlewares].find(({ key }) => key === authenticatedKey);
41
35
  function make(contracts, options = {}) {
42
36
  const { actions, events } = listed(contracts);
@@ -64,8 +58,7 @@ function make(contracts, options = {}) {
64
58
  group
65
59
  };
66
60
  }
67
- const withRequestOf = (headers) => (effect) => effect.pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, HttpServerRequest.fromClientRequest(HttpClientRequest.get("/", { headers }))), Effect.provideService(HttpServerRequest.ParsedSearchParams, {}));
68
- /** `call` inside `steps`, the first innermost, each given the call's options. */
61
+ const withSyntheticRequestFromHeaders = (headers) => (effect) => effect.pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, HttpServerRequest.fromClientRequest(HttpClientRequest.get("/", { headers }))), Effect.provideService(HttpServerRequest.ParsedSearchParams, {}));
69
62
  const throughSteps = (steps, call, options) => {
70
63
  let wrapped = call;
71
64
  for (const step of steps) {
@@ -74,10 +67,6 @@ const throughSteps = (steps, call, options) => {
74
67
  }
75
68
  return wrapped;
76
69
  };
77
- /**
78
- * The step authenticating a call with `authentication`'s provider: the identity its verification
79
- * answers is provided to the call, the verification run as `verifying` runs it.
80
- */
81
70
  const authenticatingOf = (authentication) => Effect.map(providerOf(authentication), (provider) => {
82
71
  const verify = Effect.flatMap(HttpApiBuilder.securityDecode(authentication.security), provider.authenticate);
83
72
  return (verifying) => (effect, options) => Effect.flatMap(verifying(verify, options), (actor) => Effect.provideService(effect, authentication.identity, actor));
@@ -119,7 +108,7 @@ const callBoundaryOf = (error) => {
119
108
  return Result.isSuccess(failure) ? encode(failure.success.error).pipe(Effect.matchCauseEffect({
120
109
  onFailure: (unencoded) => concealed(Cause.combine(cause, unencoded)),
121
110
  onSuccess: (encoded) => Effect.fail(new DeclaredFailure(encoded))
122
- })) : Effect.failCause(cause);
111
+ })) : Effect.failCause(failure.failure);
123
112
  });
124
113
  };
125
114
  const handlerOf = (action, run, steps, error) => {
@@ -135,12 +124,6 @@ const handlerOf = (action, run, steps, error) => {
135
124
  return boundary(wrapped);
136
125
  };
137
126
  };
138
- /**
139
- * The handler of the stream rpc of an action declaring `progress` or answering a stream: its call
140
- * authenticates before its stream starts, then runs in the call's scope, what `sending` sends sent
141
- * one at a time, so a caller reading slowly holds up the call, whose progress then drops the
142
- * oldest values. A failure ends the stream as a call's ends it.
143
- */
144
127
  const streamingHandlerOf = (action, sending, steps, error) => {
145
128
  const decode = decodeInput(action);
146
129
  const boundary = callBoundaryOf(error);
@@ -150,7 +133,10 @@ const streamingHandlerOf = (action, sending, steps, error) => {
150
133
  const input = yield* decode(payload);
151
134
  const sent = yield* Queue.bounded(1);
152
135
  const send = (each) => Effect.asVoid(Queue.offer(sent, each));
153
- yield* sending(input, { progress: (value) => Effect.flatMap(Effect.orDie(encodeProgress(value)), (json) => send(Progressed.Progress({ value: json }))) }, send).pipe(boundary, Queue.into(sent), Effect.forkScoped({ startImmediately: true }));
136
+ yield* sending(input, { progress: (value) => Effect.flatMap(Effect.orDie(encodeProgress(value)), (json) => send({
137
+ _tag: "Progress",
138
+ value: json
139
+ })) }, send).pipe(boundary, Queue.into(sent), Effect.forkScoped({ startImmediately: true }));
154
140
  return sent;
155
141
  });
156
142
  const wrapped = throughSteps(steps, call, {
@@ -160,28 +146,27 @@ const streamingHandlerOf = (action, sending, steps, error) => {
160
146
  return boundary(wrapped);
161
147
  };
162
148
  };
163
- /** Each value `run` reports sent as a `Progress`, then its answer as a `Final`. */
164
149
  const sendingAnswer = (success, run) => {
165
150
  const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(success));
166
- return (input, reporting, send) => run(input, reporting).pipe(Effect.flatMap(encode), Effect.flatMap((value) => send(Progressed.Final({ value }))));
151
+ return (input, reporting, send) => run(input, reporting).pipe(Effect.flatMap(encode), Effect.flatMap((value) => send({
152
+ _tag: "Final",
153
+ value
154
+ })));
167
155
  };
168
- /** Each element of the stream `run` answers sent as an `Element`, beside its progress. */
169
156
  const sendingElements = (element, run) => {
170
157
  const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(element));
171
- return (input, reporting, send) => Stream.runForEach(elementsOf(run(input, reporting)), (each) => Effect.flatMap(encode(each), (value) => send(Progressed.Element({ value }))));
158
+ return (input, reporting, send) => Stream.runForEach(elementsOf(run(input, reporting)), (each) => Effect.flatMap(encode(each), (value) => send({
159
+ _tag: "Element",
160
+ value
161
+ })));
172
162
  };
173
163
  /** The key a protocol sets to its `SubscriptionKeeper` on its `RpcServer.Protocol` service. */
174
164
  const subscriptionKeeper = Symbol.for("effect-actions/ActionRpc/subscriptionKeeper");
165
+ const isSubscriptionKeeper = (kept) => Predicate.hasProperty(kept, "keep") && Predicate.isFunction(kept.keep);
175
166
  const keeperOf = (protocol) => {
176
- return Predicate.hasProperty(protocol, subscriptionKeeper) ? protocol[subscriptionKeeper] : void 0;
167
+ const kept = Predicate.hasProperty(protocol, subscriptionKeeper) ? protocol[subscriptionKeeper] : void 0;
168
+ return isSubscriptionKeeper(kept) ? kept : void 0;
177
169
  };
178
- /**
179
- * The handler of one event type's stream rpc: the subscription's request authenticates and is
180
- * admitted before its stream starts, so a refusal fails the call; the feed is then read from the
181
- * call, in its scope, into a bounded queue, each element encoded, and read on through a source's
182
- * failure, before its first `Checked` too. A later refusal ends the stream as a declared failure.
183
- * Over a protocol with a `keeper`, the admitted subscription is kept, and every position sent.
184
- */
185
170
  const subscriptionHandlerOf = (feed, steps, error, keeper) => {
186
171
  const decode = Schema.decodeUnknownEffect(Subscription, inputParseOptions);
187
172
  const decodeEventInput = decodeInput(feed.event);
@@ -228,8 +213,8 @@ const subscriptionHandlerOf = (feed, steps, error, keeper) => {
228
213
  * waits for good.
229
214
  */
230
215
  const unaryProtocol = Symbol.for("effect-actions/ActionRpc/unary");
231
- const verifyingNative = (verify, { headers }) => withRequestOf(headers)(verify).pipe(Effect.catchCauseIf(Cause.hasDies, concealed));
232
- const requested = (effect, { headers }) => withRequestOf(headers)(effect);
216
+ const verifyingNative = (verify, { headers }) => withSyntheticRequestFromHeaders(headers)(verify).pipe(Effect.catchCauseIf(Cause.hasDies, concealed));
217
+ const requested = (effect, { headers }) => withSyntheticRequestFromHeaders(headers)(effect);
233
218
  const isUnary = (protocol) => Predicate.hasProperty(protocol, unaryProtocol) && protocol[unaryProtocol] === true;
234
219
  function layer(binding, served, options = {}) {
235
220
  const selected = servingOf("RPC binding", binding, served, options);
@@ -275,33 +260,23 @@ function layer(binding, served, options = {}) {
275
260
  return RpcServer.layer(jsonGroup.merge(binding.rpcs), { disableFatalDefects: true }).pipe(Layer.provide(handlers));
276
261
  }
277
262
  const isDeclared = (failure) => failure instanceof DeclaredFailure;
278
- /** Fail with the declared failure a wrapper holds, decoded by `error`, or die where it does not. */
279
263
  const failedOf = (error) => {
280
264
  const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(error));
281
265
  return (failure) => Effect.flatMap(Effect.orDie(decode(failure.json)), Effect.fail);
282
266
  };
283
- /**
284
- * A client's method of `action`, calling `method`, its rpc of `erasedOf`, with its input's JSON:
285
- * what the server sends, its answer or each element it streams, and its declared failure, decoded
286
- * by the action's schemas; one that does not decode is a defect, as the native client makes it.
287
- */
288
267
  const actionMethodOf = (action, binding, method) => {
289
- const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(sentOf(action)));
290
268
  const failed = failedOf(Schema.Union(bindingErrors(action, binding)));
291
- const sent = (json) => Effect.orDie(decode(json));
292
- if (!streams(action)) {
269
+ const streamed = streamedOf(action);
270
+ if (streamed === void 0) {
271
+ const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(action.success));
293
272
  const call = method;
294
- return checked(action, sendingJson, (json) => call(json).pipe(Effect.catchIf(isDeclared, failed), Effect.flatMap(sent)));
273
+ return checked(action, sendingJson, (json) => call(json).pipe(Effect.catchIf(isDeclared, failed), Effect.flatMap((sent) => Effect.orDie(decode(sent)))));
295
274
  }
275
+ const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(streamed));
296
276
  const call = method;
297
- const progressed = (json) => call(json).pipe(Stream.catchIf(isDeclared, (failure) => Stream.fromEffect(failed(failure))), Stream.mapEffect(sent));
277
+ const progressed = (json) => call(json).pipe(Stream.catchIf(isDeclared, (failure) => Stream.fromEffect(failed(failure))), Stream.mapEffect((sent) => Effect.orDie(decode(sent))));
298
278
  return elementOf(action.success) === void 0 ? checked(action, sendingJson, (json, onProgress) => answerFrom(progressed(json), onProgress)) : checkedStream(action, sendingJson, (json, onProgress) => elementsFrom(progressed(json), onProgress));
299
279
  };
300
- /**
301
- * A client's subscription to `event`, calling `method`, its stream rpc of `erasedOf`, with its
302
- * input's JSON and the cursor it resumes from: what the server sends, and its declared failure,
303
- * decoded by the event's schemas; one that does not decode is a defect, as for an action.
304
- */
305
280
  const eventMethodOf = (event, binding, method) => {
306
281
  const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(PushedOf(event)));
307
282
  const failed = failedOf(Schema.Union(eventErrors(event, binding)));
@@ -65,13 +65,11 @@ export interface Options<A extends Any> {
65
65
  */
66
66
  readonly needsApproval?: (call: ToolCall<A>, context: Tool.NeedsApprovalContext) => boolean | Effect.Effect<boolean, unknown>;
67
67
  }
68
- /** A value an action reported, as a toolkit's preliminary result holds it. */
69
68
  declare class Reported<A> {
70
69
  readonly _tag = "Progress";
71
70
  readonly value: A;
72
71
  constructor(value: A);
73
72
  }
74
- /** A preliminary result of a tool whose action declares `progress`: one value it reported. */
75
73
  declare const ProgressOf: (progress: Codec) => Schema.decodeTo<Schema.declare<Reported<unknown>, Reported<unknown>>, Schema.TaggedStruct<"Progress", {
76
74
  readonly value: Codec;
77
75
  }>, never, never>;
@@ -14,7 +14,6 @@ const annotateFromContract = (tool, action) => {
14
14
  const hinted = tool.annotate(Tool.Readonly, readOnlyHint).annotate(Tool.Destructive, destructiveHint).annotate(Tool.Idempotent, idempotentHint).annotate(Tool.OpenWorld, openWorldHint);
15
15
  return annotateIfGiven(annotateIfGiven(hinted, Tool.Title, title), Tool.Meta, _meta === void 0 ? void 0 : { ..._meta });
16
16
  };
17
- /** A value an action reported, as a toolkit's preliminary result holds it. */
18
17
  var Reported = class {
19
18
  _tag = "Progress";
20
19
  value;
@@ -22,7 +21,6 @@ var Reported = class {
22
21
  this.value = value;
23
22
  }
24
23
  };
25
- /** A preliminary result of a tool whose action declares `progress`: one value it reported. */
26
24
  const ProgressOf = (progress) => Schema.TaggedStruct("Progress", { value: progress }).pipe(Schema.decodeTo(Schema.declare((input) => input instanceof Reported), {
27
25
  decode: SchemaGetter.transform(({ value }) => new Reported(value)),
28
26
  encode: SchemaGetter.transform((reported) => ({
package/dist/Event.d.mts CHANGED
@@ -105,31 +105,8 @@ export interface Page<E extends Any> {
105
105
  readonly nextPoll?: Duration.Input | undefined;
106
106
  }
107
107
  interface Hooked<E extends Any, R> {
108
- /**
109
- * What a subscription needs set up upstream while it lasts, such as joining a channel: a scoped
110
- * Effect, whose finalizer tears it down, run as the subscriber. A stream's lasts as long as the
111
- * stream, a poll subscription's until `lease` after its last poll, or, watched in process, until
112
- * the watch ends, and a webhook subscription's until it is unsubscribed or lapses, set up again
113
- * as `persist` restores it.
114
- *
115
- * **Gotchas**
116
- *
117
- * - Write it so it may run twice for one subscription: a lease does not outlive the process, so a poll after a restart sets it up again.
118
- * - A poll subscription's runs in its first poll's context, that request included, held until its lease ends, where a webhook subscription's runs without the request: read what it needs from the request in middleware, which provides it as a service.
119
- */
120
108
  readonly subscription?: ((input: E["input"]["Type"]) => Effect.Effect<void, never, R | Scope.Scope>) | undefined;
121
- /** How long a poll subscription's `subscription` lasts after its last poll; defaults to 5 minutes. */
122
109
  readonly lease?: Duration.Input | undefined;
123
- /**
124
- * The key a subscriber of `input` is reached by, run as the subscriber, such as the room it
125
- * follows: `Events.notify` and `Events.publish` given a key reach the subscribers of that key
126
- * alone, and those it answers `undefined` for, who follow every key. Without it, every
127
- * announcement reaches every subscriber.
128
- *
129
- * **Gotchas**
130
- *
131
- * - An occurrence a log's `emit` gives without a `key` reaches every subscriber, whatever key it follows: give each one its key.
132
- */
133
110
  readonly key?: ((input: E["input"]["Type"]) => string | undefined | Effect.Effect<string | undefined, never, R>) | undefined;
134
111
  }
135
112
  /**
package/dist/Testing.mjs CHANGED
@@ -2,7 +2,8 @@ import { clientOf } from "./testing/memory.mjs";
2
2
  import { Cause, Console, Context, Effect, ErrorReporter, FileSystem, Layer, Option, Path } from "effect";
3
3
  import { Etag, HttpEffect, HttpPlatform, HttpRouter } from "effect/http";
4
4
  // src/testing/Testing.ts
5
- const isReported = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && !ErrorReporter.isIgnored(reason.error) || Cause.isDieReason(reason) && !ErrorReporter.isIgnored(reason.defect));
5
+ const reachedRouterUnhandled = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && !ErrorReporter.isIgnored(reason.error) || Cause.isDieReason(reason) && !ErrorReporter.isIgnored(reason.defect));
6
+ const logUnhandledToProcessConsole = (cause) => reachedRouterUnhandled(cause) ? Effect.logError(cause).pipe(Effect.provideService(Console.Console, globalThis.console)) : Effect.void;
6
7
  function layer(routes) {
7
8
  if (!Layer.isLayer(routes)) return clientOf(routes);
8
9
  return Layer.unwrap(Effect.gen(function* () {
@@ -10,7 +11,7 @@ function layer(routes) {
10
11
  const platform = yield* Layer.build(Layer.fresh(Layer.mergeAll(HttpPlatform.layer, Path.layer, Etag.layerWeak).pipe(Layer.provideMerge(Layer.succeed(FileSystem.FileSystem, fileSystem)))));
11
12
  const context = Context.merge(platform, yield* Effect.context());
12
13
  const app = yield* HttpRouter.toHttpEffect(routes).pipe(Effect.provideContext(context));
13
- return clientOf(HttpEffect.toWebHandlerWith(context)(Effect.tapCause(app, (cause) => isReported(cause) ? Effect.logError(cause).pipe(Effect.provideService(Console.Console, globalThis.console)) : Effect.void)));
14
+ return clientOf(HttpEffect.toWebHandlerWith(context)(Effect.tapCause(app, logUnhandledToProcessConsole)));
14
15
  }));
15
16
  }
16
17
  export { layer };
package/dist/Webhook.mjs CHANGED
@@ -2,7 +2,7 @@ import { WebhookDelivery } from "./Event.mjs";
2
2
  import { Receiving } from "./contract/receiving.mjs";
3
3
  import { Webhooks } from "./contract/webhooks.mjs";
4
4
  import { makeReceiver } from "./webhook/receiver.mjs";
5
- import { makeStorage } from "./webhook/stored.mjs";
5
+ import { makeWriteBehindStorage } from "./webhook/stored.mjs";
6
6
  import { makeWebhooks } from "./webhook/subscriptions.mjs";
7
7
  import { Duration, Effect, Layer } from "effect";
8
8
  import { HttpRouter } from "effect/http";
@@ -24,7 +24,7 @@ function layer(options = {}) {
24
24
  const maxTtl = maxTtlOf(options.maxTtl ?? "1 hour");
25
25
  return Layer.effect(Webhooks, Effect.gen(function* () {
26
26
  const dns = options.resolveCallbacks === false ? void 0 : yield* Dns.Dns;
27
- const storage = options.persist === true ? yield* Effect.flatMap(KeyValueStore.KeyValueStore, makeStorage) : void 0;
27
+ const storage = options.persist === true ? yield* Effect.flatMap(KeyValueStore.KeyValueStore, makeWriteBehindStorage) : void 0;
28
28
  return yield* makeWebhooks({
29
29
  maxTtl,
30
30
  allowedCallbacks,
@@ -5,7 +5,6 @@ import { Cause, Context, Effect, Exit, Option, Predicate, Ref, Schema } from "ef
5
5
  import { HttpServerResponse } from "effect/http";
6
6
  // src/authentication/refusal.ts
7
7
  const responseOf = (schema, error) => HttpServerResponse.jsonUnsafe(Schema.encodeUnknownSync(Schema.toCodecJson(schema))(error), { status: httpApiStatusOf(schema.ast) ?? 422 });
8
- /** `error` answered as an endpoint declaring `errors` answers it, if one of them declares it. */
9
8
  const declaredResponse = (errors, error) => {
10
9
  const schema = errorSchemas(errors).map(declared).find((each) => Schema.is(each)(error));
11
10
  return schema === void 0 ? void 0 : responseOf(schema, error);