@gjermundgaraba/effect-actions 0.30.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 (40) hide show
  1. package/README.md +2 -2
  2. package/dist/Action.mjs +10 -11
  3. package/dist/ActionHttp.d.mts +1 -0
  4. package/dist/ActionHttp.mjs +14 -18
  5. package/dist/ActionMcp.mjs +7 -10
  6. package/dist/ActionRpc.d.mts +2 -1
  7. package/dist/ActionRpc.mjs +54 -68
  8. package/dist/ActionToolkit.mjs +4 -3
  9. package/dist/Authentication.mjs +43 -45
  10. package/dist/authentication/refusal.mjs +11 -4
  11. package/dist/cli/commands.mjs +8 -8
  12. package/dist/contract/call.mjs +1 -1
  13. package/dist/contract/callback.mjs +6 -1
  14. package/dist/contract/digest.mjs +3 -2
  15. package/dist/contract/feed.mjs +7 -5
  16. package/dist/contract/implementation.mjs +7 -17
  17. package/dist/contract/push.mjs +3 -5
  18. package/dist/contract/recent.mjs +3 -2
  19. package/dist/contract/serving.mjs +17 -17
  20. package/dist/contract/stream.d.mts +1 -1
  21. package/dist/contract/stream.mjs +14 -2
  22. package/dist/contract/subscribe.mjs +7 -2
  23. package/dist/contract/watch.mjs +4 -7
  24. package/dist/contract/webhooks.mjs +17 -6
  25. package/dist/http/client.mjs +6 -4
  26. package/dist/http/events.mjs +3 -1
  27. package/dist/http/streamed.d.mts +1 -0
  28. package/dist/http/streamed.mjs +10 -5
  29. package/dist/mcp/bridge.mjs +11 -20
  30. package/dist/mcp/client.mjs +1 -10
  31. package/dist/mcp/events.mjs +1 -1
  32. package/dist/mcp/progress.mjs +11 -1
  33. package/dist/rpc/watch.mjs +3 -5
  34. package/dist/webhook/health.mjs +25 -28
  35. package/dist/webhook/receiver.mjs +4 -7
  36. package/dist/webhook/subscriptions.mjs +11 -12
  37. package/docs/Action.md +1 -1
  38. package/docs/setup-failures.md +1 -1
  39. package/docs/setup.md +4 -4
  40. package/package.json +8 -8
@@ -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* () {
@@ -6,9 +6,9 @@ import { pushed, refusalIn } from "../contract/push.mjs";
6
6
  import { reported } from "../contract/reported.mjs";
7
7
  import { checkedHost } from "./address.mjs";
8
8
  import { attempt, challenged } from "./attempt.mjs";
9
- import { deliveryHealth, failingForMs, healthOf, statusOf } from "./health.mjs";
9
+ import { delivering, failingForMs, healthOf, healthTransition, iso, statusOf } from "./health.mjs";
10
10
  import { randomToken, subscriptionId } from "./signing.mjs";
11
- import { Cause, Clock, Context, DateTime, Deferred, Duration, Effect, Exit, Fiber, FiberMap, Match, Option, RcMap, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
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",
@@ -184,7 +183,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
184
183
  key: subscription.secret.key,
185
184
  until: now + Duration.toMillis(rotationGrace)
186
185
  } },
187
- health: health.transition(before, { type: "Refreshed" })
186
+ health: transition(before, { _tag: "Refreshed" })
188
187
  };
189
188
  const confirmation = yield* confirmedAt(watermark);
190
189
  yield* swapHeldWorker(renewed.id, renewed, workerOf(renewed, input, watermark, confirmation));
@@ -253,7 +252,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
253
252
  watermark: record.watermark
254
253
  });
255
254
  const confirmation = yield* confirmedAt(record.watermark);
256
- 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));
257
256
  if (current !== id) yield* kept(subscription);
258
257
  }).pipe(Effect.catchCause(reported));
259
258
  const serve = (feeds, keyed) => Effect.gen(function* () {
@@ -298,7 +297,7 @@ const makeWebhooks = (policy) => Effect.gen(function* () {
298
297
  url,
299
298
  feed,
300
299
  principal,
301
- health: health.initialState,
300
+ health: delivering,
302
301
  watermark: cursor
303
302
  });
304
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.30.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",
@@ -53,21 +53,21 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@clanker-stuff/oxlint-config": "0.5.0",
56
- "@effect/platform-node": "4.1.2",
57
- "@effect/tsgo": "0.67.3",
58
- "@effect/vitest": "4.1.2",
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",
61
+ "effect": "4.1.3",
62
62
  "tsx": "4.23.15",
63
63
  "typescript": "7.0.2",
64
64
  "ultracite": "8.1.1",
65
- "vite": "npm:@voidzero-dev/vite-plus-core@1.5.0",
66
- "vite-plus": "1.5.0",
65
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.5.1",
66
+ "vite-plus": "1.5.1",
67
67
  "vitest": "5.1.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "effect": "~4.1.1"
70
+ "effect": "~4.1.3"
71
71
  },
72
72
  "devEngines": {
73
73
  "packageManager": {