@gjermundgaraba/effect-actions 0.29.0 → 0.31.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 (81) hide show
  1. package/README.md +2 -2
  2. package/dist/Action.d.mts +6 -6
  3. package/dist/Action.mjs +17 -18
  4. package/dist/ActionCli.d.mts +23 -23
  5. package/dist/ActionCli.mjs +4 -4
  6. package/dist/ActionHttp.d.mts +17 -16
  7. package/dist/ActionHttp.mjs +18 -22
  8. package/dist/ActionMcp.d.mts +8 -8
  9. package/dist/ActionMcp.mjs +13 -16
  10. package/dist/ActionRpc.d.mts +24 -23
  11. package/dist/ActionRpc.mjs +58 -72
  12. package/dist/ActionToolkit.d.mts +1 -1
  13. package/dist/ActionToolkit.mjs +6 -5
  14. package/dist/Authentication.d.mts +2 -2
  15. package/dist/Authentication.mjs +44 -46
  16. package/dist/Event.d.mts +4 -4
  17. package/dist/Event.mjs +3 -3
  18. package/dist/Webhook.d.mts +2 -0
  19. package/dist/Webhook.mjs +1 -0
  20. package/dist/authentication/provider.d.mts +15 -15
  21. package/dist/authentication/refusal.mjs +12 -5
  22. package/dist/cli/commands.d.mts +2 -2
  23. package/dist/cli/commands.mjs +13 -13
  24. package/dist/contract/authorizer.d.mts +1 -1
  25. package/dist/contract/call.d.mts +2 -2
  26. package/dist/contract/call.mjs +1 -1
  27. package/dist/contract/callback.mjs +6 -1
  28. package/dist/contract/caller.d.mts +1 -1
  29. package/dist/contract/declared.d.mts +1 -1
  30. package/dist/contract/declared.mjs +1 -1
  31. package/dist/contract/digest.mjs +3 -2
  32. package/dist/contract/feed.d.mts +1 -1
  33. package/dist/contract/feed.mjs +12 -10
  34. package/dist/contract/hub.d.mts +1 -1
  35. package/dist/contract/idempotency.d.mts +1 -1
  36. package/dist/contract/idempotency.mjs +4 -4
  37. package/dist/contract/implementation.d.mts +27 -27
  38. package/dist/contract/implementation.mjs +8 -18
  39. package/dist/contract/input-check.d.mts +3 -3
  40. package/dist/contract/listed.d.mts +1 -1
  41. package/dist/contract/listed.mjs +1 -1
  42. package/dist/contract/pages.d.mts +1 -1
  43. package/dist/contract/push.d.mts +2 -2
  44. package/dist/contract/push.mjs +5 -7
  45. package/dist/contract/receiving.d.mts +2 -2
  46. package/dist/contract/receiving.mjs +1 -1
  47. package/dist/contract/recent.mjs +3 -2
  48. package/dist/contract/serving.mjs +18 -18
  49. package/dist/contract/stream.d.mts +1 -1
  50. package/dist/contract/stream.mjs +14 -2
  51. package/dist/contract/subscribe.mjs +7 -2
  52. package/dist/contract/transient.mjs +1 -1
  53. package/dist/contract/watch.d.mts +1 -1
  54. package/dist/contract/watch.mjs +5 -8
  55. package/dist/contract/webhooks.d.mts +1 -1
  56. package/dist/contract/webhooks.mjs +17 -6
  57. package/dist/http/client.d.mts +9 -9
  58. package/dist/http/client.mjs +6 -4
  59. package/dist/http/events.d.mts +6 -6
  60. package/dist/http/events.mjs +7 -5
  61. package/dist/http/placed.d.mts +3 -3
  62. package/dist/http/placed.mjs +5 -5
  63. package/dist/http/streamed.d.mts +3 -2
  64. package/dist/http/streamed.mjs +11 -6
  65. package/dist/http/watch.mjs +1 -1
  66. package/dist/mcp/bridge.mjs +13 -22
  67. package/dist/mcp/client.d.mts +10 -10
  68. package/dist/mcp/client.mjs +5 -14
  69. package/dist/mcp/events.mjs +1 -1
  70. package/dist/mcp/progress.mjs +11 -1
  71. package/dist/mcp/reply.d.mts +1 -1
  72. package/dist/mcp/watch.mjs +4 -4
  73. package/dist/rpc/watch.mjs +3 -5
  74. package/dist/webhook/health.mjs +25 -28
  75. package/dist/webhook/receiver.mjs +4 -7
  76. package/dist/webhook/stored.mjs +1 -1
  77. package/dist/webhook/subscriptions.mjs +19 -17
  78. package/docs/Action.md +1 -1
  79. package/docs/setup-failures.md +1 -1
  80. package/docs/setup.md +4 -4
  81. package/package.json +11 -12
@@ -1,10 +1,10 @@
1
- import { BuiltIn } from "../contract/errors.mjs";
2
- import { Any, Received, SubscriptionError, WatchOptions } from "../Event.mjs";
1
+ import { Any, VerifierError } from "../authentication/provider.mjs";
2
+ import { Any as Any$1 } from "../Action.mjs";
3
3
  import { Call } from "../contract/call.mjs";
4
+ import { BuiltIn } from "../contract/errors.mjs";
5
+ import { Any as Any$2, Received, SubscriptionError, WatchOptions } from "../Event.mjs";
4
6
  import { Answer } from "../contract/stream.mjs";
5
7
  import { WatchArgs, WatchRequirement } from "../contract/watch.mjs";
6
- import { Any as Any$1 } from "../Action.mjs";
7
- import { Any as Any$2, VerifierError } from "../authentication/provider.mjs";
8
8
  import { McpCallError } from "./reply.mjs";
9
9
  import { Effect, Schema, Stream } from "effect";
10
10
  import { HttpClient, HttpClientError } from "effect/http";
@@ -12,7 +12,7 @@ import { HttpClient, HttpClientError } from "effect/http";
12
12
  * Where `client` sends, through what client, and what the endpoint's authentication declares: the
13
13
  * client `transformClient` returns may fail with `E` and require `R`.
14
14
  */
15
- export interface ClientOptions<D extends Any$2 | undefined = Any$2 | undefined, E = HttpClientError.HttpClientError, R = never> {
15
+ export interface ClientOptions<D extends Any | undefined = Any | undefined, E = HttpClientError.HttpClientError, R = never> {
16
16
  /**
17
17
  * The endpoint, resolved by the `HttpClient`: relative under `Testing.layer`. Defaults to `/mcp`,
18
18
  * the default `layerHttp` path, so a call to an endpoint on another `path` fails with an
@@ -33,15 +33,15 @@ export interface ClientOptions<D extends Any$2 | undefined = Any$2 | undefined,
33
33
  readonly authentication?: D;
34
34
  }
35
35
  type CallError<A extends Any$1, D> = A["error"][number]["Type"] | VerifierError<A, D>["Type"] | BuiltIn | Schema.SchemaError | HttpClientError.HttpClientError | McpCallError;
36
- type WatchError<W extends Any, D> = SubscriptionError | BuiltIn | VerifierError<W, D>["Type"] | Schema.SchemaError | HttpClientError.HttpClientError | McpCallError;
36
+ type WatchError<W extends Any$2, D> = SubscriptionError | BuiltIn | VerifierError<W, D>["Type"] | Schema.SchemaError | HttpClientError.HttpClientError | McpCallError;
37
37
  /**
38
38
  * Every action of `Contracts` as `client.<action>(input)`, calling its tool; one answering a
39
39
  * stream returns a `Stream` of the elements its tool collected. Where it lists event types,
40
40
  * `watch(event, input, options)` subscribes to one. Each call and watch also fails with `E` and
41
41
  * requires `R`, what its `transformClient` adds.
42
42
  */
43
- export type Client<Contracts extends ReadonlyArray<Any$1 | Any>, D = undefined, E = never, R = never> = { readonly [A in Extract<Contracts[number], Any$1> as A["name"]]: Call<A, Answer<A["success"], CallError<A, D> | E, R>>; } & Watching<Extract<Contracts[number], Any>, D, E, R>;
44
- type Watching<Listed extends Any, D, E, R> = [Listed] extends [never] ? unknown : {
43
+ export type Client<Contracts extends ReadonlyArray<Any$1 | Any$2>, D = undefined, E = never, R = never> = { readonly [A in Extract<Contracts[number], Any$1> as A["name"]]: Call<A, Answer<A["success"], CallError<A, D> | E, R>>; } & Watching<Extract<Contracts[number], Any$2>, D, E, R>;
44
+ type Watching<Listed extends Any$2, D, E, R> = [Listed] extends [never] ? unknown : {
45
45
  readonly watch: <W extends Listed, SE = never, const O extends WatchOptions<unknown> = {}>(event: W, ...args: WatchArgs<W, SE, O>) => Stream.Stream<Received<W>, WatchError<W, D> | E | SE, R | WatchRequirement<O>>;
46
46
  };
47
47
  /**
@@ -65,6 +65,6 @@ type Watching<Listed extends Any, D, E, R> = [Listed] extends [never] ? unknown
65
65
  * - A watch reconnects after the transport fails, a status such as 503, or 60 seconds without an answer or a frame, a second later and doubling to 30 seconds, each reconnect logged as a warning; any other failure ends it.
66
66
  * - A call given `onProgress` sends a `progressToken` and reads each `notifications/progress` as its frame arrives; a call without one sends none, so the endpoint sends no progress.
67
67
  */
68
- export declare function client<const Contracts extends ReadonlyArray<Any$1 | Any>, D extends Any$2 | undefined = undefined>(contracts: Contracts, options?: ClientOptions<D>): Effect.Effect<Client<Contracts, D>, never, HttpClient.HttpClient>;
69
- export declare function client<const Contracts extends ReadonlyArray<Any$1 | Any>, E, R, D extends Any$2 | undefined = undefined>(contracts: Contracts, options: ClientOptions<D, E, R>): Effect.Effect<Client<Contracts, D, E, R>, never, HttpClient.HttpClient>;
68
+ export declare function client<const Contracts extends ReadonlyArray<Any$1 | Any$2>, D extends Any | undefined = undefined>(contracts: Contracts, options?: ClientOptions<D>): Effect.Effect<Client<Contracts, D>, never, HttpClient.HttpClient>;
69
+ export declare function client<const Contracts extends ReadonlyArray<Any$1 | Any$2>, E, R, D extends Any | undefined = undefined>(contracts: Contracts, options: ClientOptions<D, E, R>): Effect.Effect<Client<Contracts, D, E, R>, never, HttpClient.HttpClient>;
70
70
  export {};
@@ -1,13 +1,13 @@
1
+ import { checked, checkedStream, sendingJson, watchInput } from "../contract/call.mjs";
1
2
  import { Anyone } from "../contract/caller.mjs";
2
- import { Refusal } from "../contract/errors.mjs";
3
3
  import { projectedErrors } from "../contract/declared.mjs";
4
- import { assertOnce } from "../contract/names.mjs";
5
- import { progressSink } from "../contract/progress.mjs";
6
- import { elementOf } from "../contract/stream.mjs";
7
- import { checked, checkedStream, sendingJson, watchInput } from "../contract/call.mjs";
4
+ import { Refusal } from "../contract/errors.mjs";
8
5
  import { liftOf } from "../contract/lift.mjs";
9
6
  import { split } from "../contract/listed.mjs";
7
+ import { assertOnce } from "../contract/names.mjs";
8
+ import { elementOf } from "../contract/stream.mjs";
10
9
  import { watching } from "../contract/watch.mjs";
10
+ import { decodedSink } from "./progress.mjs";
11
11
  import { defaultPath, unliftedFrom } from "./protocol.mjs";
12
12
  import { NoReply, NoStructuredContent, ProtocolError, StatusError, UndeclaredError, bodyOf, callError, failWith } from "./reply.mjs";
13
13
  import { request } from "./request.mjs";
@@ -22,15 +22,6 @@ const ToolCallReply = Schema.Union([Schema.Struct({ result: McpSchema.CallToolRe
22
22
  message: Schema.String
23
23
  }) })]);
24
24
  const decodeReply = Schema.decodeUnknownOption(Schema.fromJsonString(ToolCallReply));
25
- const decodedSink = (progress, onProgress) => {
26
- const sink = progressSink(onProgress);
27
- if (progress === void 0 || sink === void 0) return;
28
- const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(progress));
29
- return { progress: (json) => Effect.matchEffect(decode(json), {
30
- onFailure: (error) => Effect.logWarning("A progress value did not decode", error),
31
- onSuccess: sink.progress
32
- }) };
33
- };
34
25
  const callTool = (client, url, action, success, refusedWith, input, sink) => {
35
26
  const { name } = action;
36
27
  const lift = liftOf(success);
@@ -133,4 +133,4 @@ const Terminated = Rpc.make("notifications/events/terminated", { payload: {
133
133
  } });
134
134
  const Requests = RpcGroup.make(ListEvents, PollEvents, StreamEvents, SubscribeEvents, UnsubscribeEvents);
135
135
  const Notifications = RpcGroup.make(Active, Occurred, Heartbeat, Failed, Terminated);
136
- export { Active, EventDescriptor, EventsError, Failed, Heartbeat, ListEvents, Notifications, Occurred, PollEvents, Requests, StreamEvents, SubscribeEvents, Terminated, UnsubscribeEvents, WireError, WireOccurrence, codes, extension, subscriptionIdKey };
136
+ export { Active, EventDescriptor, EventsError, Failed, Heartbeat, Notifications, Occurred, PollEvents, Requests, SubscribeEvents, Terminated, UnsubscribeEvents, WireError, WireOccurrence, codes, extension, subscriptionIdKey };
@@ -1,3 +1,4 @@
1
+ import { progressSink } from "../contract/progress.mjs";
1
2
  import { Effect, Option, Schema } from "effect";
2
3
  import { McpSchema } from "effect/ai";
3
4
  // src/mcp/progress.ts
@@ -24,4 +25,13 @@ const Notified = Schema.fromJsonString(Schema.Struct({
24
25
  }));
25
26
  const notifiedOf = Schema.decodeUnknownOption(Notified);
26
27
  const progressOf = (data) => Option.map(notifiedOf(data), (notified) => notified.params._meta[progressKey]);
27
- export { progressKey, progressNotifier, progressOf };
28
+ const decodedSink = (progress, onProgress) => {
29
+ const sink = progressSink(onProgress);
30
+ if (progress === void 0 || sink === void 0) return;
31
+ const decode = Schema.decodeUnknownEffect(Schema.toCodecJson(progress));
32
+ return { progress: (json) => Effect.matchEffect(decode(json), {
33
+ onFailure: (error) => Effect.logWarning("A progress value did not decode", error),
34
+ onSuccess: sink.progress
35
+ }) };
36
+ };
37
+ export { decodedSink, progressNotifier, progressOf };
@@ -1,5 +1,5 @@
1
- import "../contract/progress.mjs";
2
1
  import "../Action.mjs";
2
+ import "../contract/progress.mjs";
3
3
  import { Effect, Schema, Stream } from "effect";
4
4
  import { HttpClientError } from "effect/http";
5
5
  declare const StatusError_base: Schema.Class<StatusError, Schema.TaggedStruct<"StatusError", {
@@ -1,10 +1,10 @@
1
+ import { reasonOf } from "../contract/codes.mjs";
1
2
  import { InvalidInput } from "../contract/errors.mjs";
2
- import { isTransientStatus } from "../contract/status.mjs";
3
- import { Checked, Gap, untaggedOccurrenceOf } from "../contract/occurrence.mjs";
4
3
  import { defaultNextPoll } from "../contract/feed.mjs";
5
- import { reasonOf } from "../contract/codes.mjs";
6
- import { Receiving, webhookFed } from "../contract/receiving.mjs";
4
+ import { Checked, Gap, untaggedOccurrenceOf } from "../contract/occurrence.mjs";
7
5
  import { Failed, readOn } from "../contract/push.mjs";
6
+ import { Receiving, webhookFed } from "../contract/receiving.mjs";
7
+ import { isTransientStatus } from "../contract/status.mjs";
8
8
  import { WebhookCallback, WebhookTarget } from "../contract/subscribe.mjs";
9
9
  import { failingWhenSilent, failingWhenUnanswered, isTransient } from "../contract/transient.mjs";
10
10
  import { Active, Failed as Failed$1, Heartbeat, Occurred, PollEvents, SubscribeEvents, Terminated, UnsubscribeEvents, WireError, codes } from "./events.mjs";
@@ -1,5 +1,6 @@
1
- import { NotServed, SubscriptionError, Unsupported } from "../Event.mjs";
1
+ import { NotServed, SubscriptionError } from "../Event.mjs";
2
2
  import { readOn } from "../contract/push.mjs";
3
+ import { deliveryUnsupported } from "../contract/subscribe.mjs";
3
4
  import { isTransientReason, receivedFrom } from "../contract/transient.mjs";
4
5
  import { Cause, Effect, Match, Predicate, Schema, Stream } from "effect";
5
6
  import { HttpClientError } from "effect/http";
@@ -22,10 +23,7 @@ const transportOf = (event, stream, silenceEnds) => {
22
23
  const unknownTag = isUnknownTag(event.name);
23
24
  return {
24
25
  name: event.name,
25
- poll: () => Effect.fail(SubscriptionError.of(event.name, new Unsupported({
26
- feature: "deliveryMode",
27
- value: "poll"
28
- }))),
26
+ poll: () => Effect.fail(deliveryUnsupported(event.name, "poll")),
29
27
  stream: (cursor) => stream(cursor).pipe(Stream.catchCauseIf(unknownTag, () => notServed), silenceEnds ? receivedFrom("RPC", event.name) : readOn("RPC", event.name)),
30
28
  transient: isRpcTransient
31
29
  };
@@ -1,14 +1,19 @@
1
1
  import { DateTime, Option } from "effect";
2
2
  // src/webhook/health.ts
3
- const deliveryHealth = (retryForMs) => {
3
+ const delivering = {
4
+ _tag: "Delivering",
5
+ lastDeliveryAt: null,
6
+ lastError: null
7
+ };
8
+ const healthTransition = (retryForMs) => {
4
9
  const spent = (failedSince, at) => at - failedSince >= retryForMs;
5
- const transition = (health, event) => {
10
+ return (health, event) => {
6
11
  const { lastDeliveryAt } = health;
7
- switch (health.value) {
12
+ switch (health._tag) {
8
13
  case "Delivering":
9
- if (event.type === "Refreshed") return health;
10
- if (event.type === "Delivered") return {
11
- value: "Delivering",
14
+ if (event._tag === "Refreshed") return health;
15
+ if (event._tag === "Delivered") return {
16
+ _tag: "Delivering",
12
17
  lastDeliveryAt: event.at,
13
18
  lastError: null
14
19
  };
@@ -17,47 +22,39 @@ const deliveryHealth = (retryForMs) => {
17
22
  lastError: event.category
18
23
  };
19
24
  return {
20
- value: spent(event.at, event.at) ? "Suspended" : "Failing",
25
+ _tag: spent(event.at, event.at) ? "Suspended" : "Failing",
21
26
  lastDeliveryAt,
22
27
  lastError: event.category,
23
28
  failedSince: event.at
24
29
  };
25
30
  case "Failing":
26
- if (event.type === "Refreshed") return health;
27
- if (event.type === "Delivered") return {
28
- value: "Delivering",
31
+ if (event._tag === "Refreshed") return health;
32
+ if (event._tag === "Delivered") return {
33
+ _tag: "Delivering",
29
34
  lastDeliveryAt: event.at,
30
35
  lastError: null
31
36
  };
32
37
  if (event.final) return {
33
- value: "Delivering",
38
+ _tag: "Delivering",
34
39
  lastDeliveryAt,
35
40
  lastError: event.category
36
41
  };
37
42
  if (spent(health.failedSince, event.at)) return {
38
43
  ...health,
39
- value: "Suspended",
44
+ _tag: "Suspended",
40
45
  lastError: event.category
41
46
  };
42
47
  return event.category === health.lastError ? health : {
43
48
  ...health,
44
49
  lastError: event.category
45
50
  };
46
- case "Suspended": return event.type === "Refreshed" ? {
47
- value: "Delivering",
51
+ case "Suspended": return event._tag === "Refreshed" ? {
52
+ _tag: "Delivering",
48
53
  lastDeliveryAt,
49
54
  lastError: health.lastError
50
55
  } : health;
51
56
  }
52
57
  };
53
- return {
54
- initialState: {
55
- value: "Delivering",
56
- lastDeliveryAt: null,
57
- lastError: null
58
- },
59
- transition
60
- };
61
58
  };
62
59
  const iso = (millis) => DateTime.formatIso(DateTime.makeUnsafe(millis));
63
60
  const millisOf = (text) => {
@@ -66,13 +63,13 @@ const millisOf = (text) => {
66
63
  };
67
64
  const statusOf = (health) => {
68
65
  const lastDeliveryAt = health.lastDeliveryAt === null ? null : iso(health.lastDeliveryAt);
69
- if (health.value === "Delivering") return {
66
+ if (health._tag === "Delivering") return {
70
67
  active: true,
71
68
  lastDeliveryAt,
72
69
  lastError: health.lastError
73
70
  };
74
71
  return {
75
- active: health.value === "Failing",
72
+ active: health._tag === "Failing",
76
73
  lastDeliveryAt,
77
74
  lastError: health.lastError,
78
75
  failedSince: iso(health.failedSince)
@@ -83,17 +80,17 @@ const healthOf = (status) => Option.gen(function* () {
83
80
  if (status.failedSince === void 0) {
84
81
  if (!status.active) return yield* Option.none();
85
82
  return {
86
- value: "Delivering",
83
+ _tag: "Delivering",
87
84
  lastDeliveryAt,
88
85
  lastError: status.lastError
89
86
  };
90
87
  }
91
88
  return {
92
- value: status.active ? "Failing" : "Suspended",
89
+ _tag: status.active ? "Failing" : "Suspended",
93
90
  lastDeliveryAt,
94
91
  lastError: yield* Option.fromNullOr(status.lastError),
95
92
  failedSince: yield* millisOf(status.failedSince)
96
93
  };
97
94
  });
98
- const failingForMs = (health, now) => health.value === "Failing" ? now - health.failedSince : 0;
99
- export { deliveryHealth, failingForMs, healthOf, statusOf };
95
+ const failingForMs = (health, now) => health._tag === "Failing" ? now - health.failedSince : 0;
96
+ export { delivering, failingForMs, healthOf, healthTransition, iso, statusOf };
@@ -1,12 +1,12 @@
1
+ import { signingSecretOf } from "../contract/callback.mjs";
1
2
  import { watchParameter } from "../contract/receiving.mjs";
2
3
  import { makeRecent } from "../contract/recent.mjs";
3
4
  import { constantTimeEqual, standardWebhooksSignature } from "./signing.mjs";
4
5
  import { Clock, Effect, Option, Predicate, Schema } from "effect";
5
6
  import { HttpServerRequest, HttpServerResponse } from "effect/http";
6
- import { Base64, Base64Url } from "effect/encoding";
7
+ import { Base64Url } from "effect/encoding";
7
8
  // src/webhook/receiver.ts
8
9
  const timestampToleranceSeconds = 300;
9
- const dedupeWindow = 1e3;
10
10
  const Body = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Json));
11
11
  const decodeBody = Schema.decodeUnknownOption(Body);
12
12
  const gone = HttpServerResponse.empty({ status: 410 });
@@ -19,14 +19,11 @@ const makeReceiver = (path) => Effect.sync(() => {
19
19
  places.set(id, {
20
20
  key,
21
21
  deliver,
22
- seen: makeRecent(dedupeWindow)
22
+ seen: makeRecent()
23
23
  });
24
24
  return {
25
25
  id,
26
- secret: {
27
- text: `whsec_${Base64.encode(key)}`,
28
- key
29
- }
26
+ secret: signingSecretOf(key)
30
27
  };
31
28
  }), ({ id }) => Effect.sync(() => places.delete(id)));
32
29
  const handler = Effect.gen(function* () {
@@ -1,5 +1,5 @@
1
- import { reported } from "../contract/reported.mjs";
2
1
  import { CallbackUrl, WebhookSecret } from "../contract/callback.mjs";
2
+ import { reported } from "../contract/reported.mjs";
3
3
  import { DeliveryStatus } from "../contract/subscribe.mjs";
4
4
  import { Cause, Duration, Effect, Option, Queue, Schema, Semaphore } from "effect";
5
5
  import { KeyValueStore } from "effect/persistence";
@@ -1,14 +1,14 @@
1
1
  import { canonicalInput } from "../contract/canonical.mjs";
2
- import { reported } from "../contract/reported.mjs";
3
- import { encodeUntaggedOf } from "../contract/occurrence.mjs";
4
- import { CallbackFailed, NotSubscribed, SubscriptionError } from "../Event.mjs";
5
2
  import { sentError } from "../contract/codes.mjs";
6
- import { randomToken, subscriptionId } from "./signing.mjs";
3
+ import { CallbackFailed, NotSubscribed, SubscriptionError } from "../Event.mjs";
4
+ import { encodeUntaggedOf } from "../contract/occurrence.mjs";
7
5
  import { pushed, refusalIn } from "../contract/push.mjs";
6
+ import { reported } from "../contract/reported.mjs";
8
7
  import { checkedHost } from "./address.mjs";
9
8
  import { attempt, challenged } from "./attempt.mjs";
10
- import { deliveryHealth, failingForMs, healthOf, statusOf } from "./health.mjs";
11
- import { Cause, Clock, Context, DateTime, Deferred, Duration, Effect, Exit, Fiber, FiberMap, Match, Option, RcMap, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
9
+ import { delivering, failingForMs, healthOf, healthTransition, iso, statusOf } from "./health.mjs";
10
+ import { randomToken, subscriptionId } from "./signing.mjs";
11
+ import { Cause, Clock, Context, Deferred, Duration, Effect, Exit, Fiber, FiberMap, Match, Option, RcMap, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
12
12
  import { HttpRouter, HttpServerRequest } from "effect/http";
13
13
  // src/webhook/subscriptions.ts
14
14
  const minTtl = Duration.minutes(1);
@@ -16,7 +16,6 @@ const rotationGrace = Duration.minutes(5);
16
16
  const maxBody = 262144;
17
17
  const encoder = new TextEncoder();
18
18
  const terminatedEnvelopeRetries = Schedule.exponential(Duration.seconds(1)).pipe(Schedule.upTo({ times: 3 }));
19
- const iso = (millis) => DateTime.formatIso(DateTime.makeUnsafe(millis));
20
19
  const grantOf = (ttlMs, policy) => Duration.clamp(ttlMs === null || ttlMs === void 0 ? policy.maxTtl : Duration.millis(ttlMs), {
21
20
  minimum: minTtl,
22
21
  maximum: policy.maxTtl
@@ -52,9 +51,9 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
52
51
  const dropped = (id) => Effect.sync(() => storage?.mark(id, void 0));
53
52
  const verified = /* @__PURE__ */ new Map();
54
53
  const locks = yield* RcMap.make({ lookup: (_id) => Semaphore.make(1) });
55
- const health = deliveryHealth(Duration.toMillis(policy.retryFor));
54
+ const transition = healthTransition(Duration.toMillis(policy.retryFor));
56
55
  const transitioned = (subscription, event) => Effect.suspend(() => {
57
- const next = health.transition(subscription.health, event);
56
+ const next = transition(subscription.health, event);
58
57
  if (next === subscription.health) return Effect.void;
59
58
  subscription.health = next;
60
59
  return kept(subscription);
@@ -65,7 +64,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
65
64
  })));
66
65
  const retrying = (subscription) => ({
67
66
  schedule: waitingAsLongAsFailing(subscription),
68
- while: () => subscription.health.value === "Failing"
67
+ while: () => subscription.health._tag === "Failing"
69
68
  });
70
69
  const locked = (id) => (effect) => Effect.scoped(Effect.flatMap(RcMap.get(locks, id), (lock) => lock.withPermits(1)(effect)));
71
70
  const asSubscriber = (subscription, effect) => Effect.updateContext(effect, () => subscription.context);
@@ -77,16 +76,16 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
77
76
  keys: subscription.previous !== void 0 && now < subscription.previous.until ? [subscription.secret.key, subscription.previous.key] : [subscription.secret.key]
78
77
  }, trusted(subscription.url, policy.allowedCallbacks) ? Effect.void : checkedHost(subscription.url, policy.dns)), built));
79
78
  const delivered = (subscription, webhookId, body) => post(subscription, webhookId, body).pipe(Effect.tapError(({ category, final }) => Effect.flatMap(Clock.currentTimeMillis, (at) => transitioned(subscription, {
80
- type: "AttemptFailed",
79
+ _tag: "AttemptFailed",
81
80
  category,
82
81
  final,
83
82
  at
84
83
  }))), Effect.retry(retrying(subscription)), Effect.matchEffect({
85
84
  onSuccess: () => Effect.as(Effect.flatMap(Clock.currentTimeMillis, (at) => transitioned(subscription, {
86
- type: "Delivered",
85
+ _tag: "Delivered",
87
86
  at
88
87
  })), true),
89
- onFailure: () => subscription.health.value === "Suspended" ? Effect.never : Effect.succeed(false)
88
+ onFailure: () => subscription.health._tag === "Suspended" ? Effect.never : Effect.succeed(false)
90
89
  }));
91
90
  const gapped = (subscription, cursor) => Effect.flatMap(randomToken, (token) => delivered(subscription, `msg_gap_${token}`, JSON.stringify({
92
91
  type: "gap",
@@ -127,7 +126,10 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
127
126
  })).pipe(Effect.retry({
128
127
  schedule: terminatedEnvelopeRetries,
129
128
  while: (failure) => !failure.final
130
- }), Effect.ignore));
129
+ }), Effect.catchIf((failure) => failure.final, () => Effect.void), Effect.ignore({
130
+ log: "Warn",
131
+ message: `Webhook subscription ${subscription.id} ended without its terminated notice delivered`
132
+ })));
131
133
  };
132
134
  const ended = (subscription) => Effect.sync(() => {
133
135
  if (holds(subscription)) held.delete(subscription.id);
@@ -181,7 +183,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
181
183
  key: subscription.secret.key,
182
184
  until: now + Duration.toMillis(rotationGrace)
183
185
  } },
184
- health: health.transition(before, { type: "Refreshed" })
186
+ health: transition(before, { _tag: "Refreshed" })
185
187
  };
186
188
  const confirmation = yield* confirmedAt(watermark);
187
189
  yield* swapHeldWorker(renewed.id, renewed, workerOf(renewed, input, watermark, confirmation));
@@ -250,7 +252,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
250
252
  watermark: record.watermark
251
253
  });
252
254
  const confirmation = yield* confirmedAt(record.watermark);
253
- yield* swapHeldWorker(current, subscription, restoredHealth.value === "Suspended" ? Effect.andThen(expired(subscription), finished(subscription)) : workerOf(subscription, input, record.watermark, confirmation));
255
+ yield* swapHeldWorker(current, subscription, restoredHealth._tag === "Suspended" ? Effect.andThen(expired(subscription), finished(subscription)) : workerOf(subscription, input, record.watermark, confirmation));
254
256
  if (current !== id) yield* kept(subscription);
255
257
  }).pipe(Effect.catchCause(reported));
256
258
  const serve = (feeds, keyed) => Effect.gen(function* () {
@@ -295,7 +297,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
295
297
  url,
296
298
  feed,
297
299
  principal,
298
- health: health.initialState,
300
+ health: delivering,
299
301
  watermark: cursor
300
302
  });
301
303
  yield* verify(subscription, now);
package/docs/Action.md CHANGED
@@ -23,7 +23,7 @@ export const Greet = Action.make("greet", {
23
23
 
24
24
  [notes-service/src/notes/Notes.ts](../examples/notes-service/src/notes/Notes.ts) adds declared errors with their statuses, described fields and the list; [kitchen-sink/src/issues/Issues.ts](../examples/kitchen-sink/src/issues/Issues.ts) uses every option. The rules of each option, `input`'s optional fields and `error`'s tags included, are on `Action.Options`; where an action must be listed to be served, and matching by object identity, are on `Action.make`. The list each surface takes lives in one file beside the contracts ([kitchen-sink/src/Actions.ts](../examples/kitchen-sink/src/Actions.ts)).
25
25
 
26
- - **List an action as a tool only where a model may hold what it takes and returns.** A tool call passes both through the model's context, and `ActionToolkit`, through Effect's toolkit, records its arguments on the current span, a `Schema.Redacted` value included.
26
+ - **List an action as a tool only where a model may hold what it takes and returns.** A tool call passes both through the model's context, and `ActionToolkit`, through Effect's toolkit, records its arguments on the current span, a `Schema.Redacted` value included: always before effect 4.1.3, and from it where `Toolkit.RecordToolArguments` is `true`, which also records an MCP tool call's arguments on its request span.
27
27
 
28
28
  ## Say who may call an action
29
29
 
@@ -8,5 +8,5 @@ What you see when something is wrong, and the fix. Search for a fragment of the
8
8
  - A page that loads Effect from an import map still bundles a second copy of Effect or of some of its modules, or fails to resolve `effect/Schema` in the browser when its bundler externalizes subpaths, as esbuild's `--external:effect` does: a module of the page imports an Effect specifier the map does not serve. Serve the specifiers [Bundle for a browser](setup.md#bundle-for-a-browser) lists, and import Effect through them in the page's own modules too.
9
9
  - A page loading Effect from an import map fails with `Failed to resolve module specifier "effect/Cause"` in Chromium: the map points at Effect's published files and lacks a specifier Effect imports itself. Map `effect/Cause`, `effect/Effect`, `effect/Exit` and `effect/Function` to the same files, or serve Effect from a build that resolves its own imports.
10
10
  - A page fails at load with `does not provide an export named …`: it serves only the names it uses of an Effect specifier, from a vendored module or a trimmed bundle, and the package imports another. Serve each specifier whole.
11
- - Type errors inside `effect/*` modules after install, an unmet peer warning for `effect`, such as `found 4.2.0`, or a start failing with `Cannot find module '…/effect/dist/…'` under an `@effect/*` package: more than one Effect release is installed, or one outside the peer range. Install the `effect` range [Install](setup.md#install) names, with every `@effect/*` package at the version `effect` resolved to, such as `@effect/platform-node@4.1.1` beside `effect@4.1.1`.
11
+ - Type errors inside `effect/*` modules after install, an unmet peer warning for `effect`, such as `found 4.2.0`, or a start failing with `Cannot find module '…/effect/dist/…'` under an `@effect/*` package: more than one Effect release is installed, or one outside the peer range. Install the `effect` range [Install](setup.md#install) names, with every `@effect/*` package at the version `effect` resolved to, such as `@effect/platform-node@4.1.3` beside `effect@4.1.3`.
12
12
  - `Cannot find module 'effect/unstable/http'` (or `…/httpapi`, `…/cli`, `…/ai`): these modules are now `effect/http`, `effect/http-api`, `effect/cli` and `effect/ai`.
package/docs/setup.md CHANGED
@@ -7,20 +7,20 @@ A message the library throws says its fix; for a compiler diagnostic or Effect's
7
7
  ## Install
8
8
 
9
9
  ```sh
10
- pnpm add @gjermundgaraba/effect-actions effect@~4.1.1
10
+ pnpm add @gjermundgaraba/effect-actions effect@~4.1.3
11
11
  ```
12
12
 
13
13
  | Need | Add |
14
14
  | --- | --- |
15
- | Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.1.1` |
16
- | Tests | `vitest@^5` and `@effect/vitest@~4.1.1`, as dev dependencies |
15
+ | Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.1.3` |
16
+ | Tests | `vitest@^5` and `@effect/vitest@~4.1.3`, as dev dependencies |
17
17
  | Type checking | `typescript@^7.0.2`, as a dev dependency |
18
18
  | Node's types, for `node:` imports | `@types/node`, as a dev dependency |
19
19
  | Running a TypeScript entrypoint | `tsx`, as a dev dependency: `node --import tsx <entrypoint>.ts` |
20
20
 
21
21
  The `effect` peer admits the 4.1.x patches from the oldest whose APIs and behavior the package relies on, and no minor release: a minor release may change the unstable Effect modules the surfaces build on.
22
22
 
23
- Keep the tilde in `package.json`: `^4.1.1`, which npm writes for `effect@4.1.1`, admits a minor release outside the peer range. `npm install effect@~4.1.1` keeps it.
23
+ Keep the tilde in `package.json`: `^4.1.3`, which npm writes for `effect@4.1.3`, admits a minor release outside the peer range. `npm install effect@~4.1.3` keeps it.
24
24
 
25
25
  Node `>=26.13.0`: the package's `engines`, the Node the library is developed and tested on. TypeScript 7 or newer. ESM only. The repository checks the examples with a stricter `tsconfig.json`; this is the minimum a project needs. The package's modules resolve only through its `exports`, which `"module": "nodenext"` reads, as a bundler project's `"moduleResolution": "bundler"` does. `"strict": true` is required, by Effect:
26
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjermundgaraba/effect-actions",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Define Effect action contracts once and project them onto HTTP, MCP, Effect RPC, native Toolkits, and CLIs.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -52,23 +52,22 @@
52
52
  "access": "public"
53
53
  },
54
54
  "devDependencies": {
55
- "@clanker-stuff/oxlint-config": "0.2.1",
56
- "@effect/platform-node": "4.1.2",
57
- "@effect/tsgo": "0.63.0",
58
- "@effect/vitest": "4.1.2",
55
+ "@clanker-stuff/oxlint-config": "0.5.0",
56
+ "@effect/platform-node": "4.1.3",
57
+ "@effect/tsgo": "0.67.7",
58
+ "@effect/vitest": "4.1.3",
59
59
  "@modelcontextprotocol/client": "2.4.0",
60
60
  "@types/node": "26.6.6",
61
- "effect": "4.1.2",
62
- "oxfmt": "0.74.0",
61
+ "effect": "4.1.3",
63
62
  "tsx": "4.23.15",
64
63
  "typescript": "7.0.2",
65
- "ultracite": "8.1.0",
66
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
67
- "vite-plus": "1.4.0",
68
- "vitest": "5.0.5"
64
+ "ultracite": "8.1.1",
65
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.5.1",
66
+ "vite-plus": "1.5.1",
67
+ "vitest": "5.1.0"
69
68
  },
70
69
  "peerDependencies": {
71
- "effect": "~4.1.1"
70
+ "effect": "~4.1.3"
72
71
  },
73
72
  "devEngines": {
74
73
  "packageManager": {