@gjermundgaraba/effect-actions 0.41.1 → 0.42.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 (100) hide show
  1. package/dist/Action.d.mts +1 -1
  2. package/dist/Action.mjs +1 -1
  3. package/dist/ActionCli.d.mts +3 -3
  4. package/dist/ActionCli.mjs +2 -2
  5. package/dist/ActionEntity.d.mts +4 -4
  6. package/dist/ActionEntity.mjs +4 -4
  7. package/dist/ActionHttp.d.mts +3 -3
  8. package/dist/ActionHttp.mjs +3 -3
  9. package/dist/ActionMcp.d.mts +3 -3
  10. package/dist/ActionMcp.mjs +6 -6
  11. package/dist/ActionRpc.d.mts +4 -4
  12. package/dist/ActionRpc.mjs +3 -3
  13. package/dist/ActionToolkit.d.mts +2 -2
  14. package/dist/ActionToolkit.mjs +2 -2
  15. package/dist/Authentication.d.mts +3 -3
  16. package/dist/Authentication.mjs +3 -3
  17. package/dist/Event.d.mts +1 -1
  18. package/dist/Event.mjs +1 -1
  19. package/dist/Stored.d.mts +2 -2
  20. package/dist/Stored.mjs +3 -3
  21. package/dist/Testing.d.mts +1 -1
  22. package/dist/Testing.mjs +1 -1
  23. package/dist/Webhook.d.mts +3 -3
  24. package/dist/Webhook.mjs +5 -5
  25. package/dist/authentication/provider.d.mts +6 -6
  26. package/dist/authentication/provider.mjs +1 -1
  27. package/dist/authentication/refusal.mjs +2 -2
  28. package/dist/cli/commands.d.mts +2 -2
  29. package/dist/cli/commands.mjs +2 -2
  30. package/dist/contract/authorizer.d.mts +2 -3
  31. package/dist/contract/authorizer.mjs +1 -1
  32. package/dist/contract/call.d.mts +1 -1
  33. package/dist/contract/call.mjs +1 -1
  34. package/dist/contract/caller.d.mts +1 -1
  35. package/dist/contract/codes.mjs +1 -1
  36. package/dist/contract/declared.d.mts +1 -1
  37. package/dist/contract/declared.mjs +1 -1
  38. package/dist/contract/feed.d.mts +1 -1
  39. package/dist/contract/feed.mjs +1 -1
  40. package/dist/contract/hub.d.mts +1 -1
  41. package/dist/contract/hub.mjs +1 -1
  42. package/dist/contract/idempotency.d.mts +1 -1
  43. package/dist/contract/idempotency.mjs +1 -1
  44. package/dist/contract/implementation.d.mts +1 -1
  45. package/dist/contract/implementation.mjs +22 -3
  46. package/dist/contract/lift.mjs +1 -1
  47. package/dist/contract/log.d.mts +1 -1
  48. package/dist/contract/log.mjs +1 -1
  49. package/dist/contract/media.d.mts +1 -1
  50. package/dist/contract/occurrence.d.mts +1 -1
  51. package/dist/contract/pages.d.mts +1 -1
  52. package/dist/contract/pages.mjs +1 -1
  53. package/dist/contract/progress.d.mts +1 -1
  54. package/dist/contract/push.d.mts +1 -1
  55. package/dist/contract/push.mjs +1 -1
  56. package/dist/contract/receiving.d.mts +1 -1
  57. package/dist/contract/receiving.mjs +1 -1
  58. package/dist/contract/stream.d.mts +5 -5
  59. package/dist/contract/stream.mjs +4 -4
  60. package/dist/contract/subscribe.d.mts +1 -1
  61. package/dist/contract/subscribe.mjs +1 -1
  62. package/dist/contract/transient.mjs +2 -2
  63. package/dist/contract/wake.d.mts +1 -1
  64. package/dist/contract/watch.d.mts +1 -1
  65. package/dist/contract/watch.mjs +1 -1
  66. package/dist/contract/webhooks.d.mts +1 -1
  67. package/dist/contract/webhooks.mjs +1 -1
  68. package/dist/entity/forwarded.d.mts +1 -1
  69. package/dist/entity/wakes.mjs +3 -3
  70. package/dist/http/client.d.mts +3 -3
  71. package/dist/http/client.mjs +3 -3
  72. package/dist/http/events.d.mts +2 -2
  73. package/dist/http/events.mjs +3 -3
  74. package/dist/http/schema-errors.mjs +1 -1
  75. package/dist/http/streamed.d.mts +3 -3
  76. package/dist/http/streamed.mjs +3 -3
  77. package/dist/http/unavailable.mjs +1 -1
  78. package/dist/http/watch.mjs +2 -2
  79. package/dist/mcp/bridge.mjs +3 -3
  80. package/dist/mcp/client.d.mts +2 -2
  81. package/dist/mcp/client.mjs +3 -3
  82. package/dist/mcp/events.mjs +2 -2
  83. package/dist/mcp/progress.mjs +1 -1
  84. package/dist/mcp/protocol.mjs +2 -2
  85. package/dist/mcp/reply.d.mts +2 -2
  86. package/dist/mcp/reply.mjs +1 -1
  87. package/dist/mcp/request.mjs +1 -1
  88. package/dist/mcp/watch.mjs +1 -1
  89. package/dist/rpc/erased.d.mts +2 -2
  90. package/dist/rpc/erased.mjs +4 -4
  91. package/dist/rpc/watch.mjs +3 -3
  92. package/dist/testing/memory.d.mts +1 -1
  93. package/dist/webhook/attempt.mjs +1 -1
  94. package/dist/webhook/receiver.mjs +3 -3
  95. package/dist/webhook/signing.mjs +2 -2
  96. package/dist/webhook/stored.mjs +2 -2
  97. package/dist/webhook/subscriptions.mjs +2 -2
  98. package/docs/Action.md +1 -1
  99. package/docs/setup.md +1 -1
  100. package/package.json +7 -7
@@ -1,6 +1,6 @@
1
+ import { Context, Effect, Layer, Schema } from "effect";
1
2
  import "../Action.mjs";
2
3
  import "./implementation.mjs";
3
- import { Context, Effect, Layer, Schema } from "effect";
4
4
  export declare const Kept: Schema.Struct<{
5
5
  readonly input: Schema.String;
6
6
  readonly outcome: Schema.String;
@@ -1,3 +1,4 @@
1
+ import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Option, Predicate, Schema } from "effect";
1
2
  import { CallerKeyed, principalOf } from "./caller.mjs";
2
3
  import { canonicalInput } from "./canonical.mjs";
3
4
  import { projectedErrors } from "./declared.mjs";
@@ -5,7 +6,6 @@ import { sha256Hex } from "./digest.mjs";
5
6
  import { InvalidInput } from "./errors.mjs";
6
7
  import { answered } from "./implementation.mjs";
7
8
  import { declaredStatus, isTransientStatus } from "./status.mjs";
8
- import { Cause, Clock, Context, Deferred, Effect, Exit, Layer, Option, Predicate, Schema } from "effect";
9
9
  // src/contract/idempotency.ts
10
10
  const Kept = Schema.Struct({
11
11
  input: Schema.String,
@@ -1,10 +1,10 @@
1
+ import { Context, Effect, Layer, Stream } from "effect";
1
2
  import { Any } from "../Action.mjs";
2
3
  import { Anyone, Keyed } from "./caller.mjs";
3
4
  import { Refusal } from "./errors.mjs";
4
5
  import { Any as Any$1 } from "../Event.mjs";
5
6
  import { AnyEventImplementation, EventOf } from "./feed.mjs";
6
7
  import { Reporting } from "./progress.mjs";
7
- import { Context, Effect, Layer, Scope, Stream } from "effect";
8
8
  export type ErasedValue = Any["input"]["Type"];
9
9
  export type WrittenHandler<R> = {
10
10
  bivarianceHack(input: ErasedValue, reporting?: Reporting): Effect.Effect<ErasedValue, ErasedValue, R> | Stream.Stream<ErasedValue, ErasedValue, R>;
@@ -1,9 +1,9 @@
1
+ import { Array, Cause, Context, Effect, Exit, Layer, Option, Predicate, References, Schema, Stream } from "effect";
1
2
  import { Anyone, CallerKeyed } from "./caller.mjs";
2
3
  import { projectedErrors } from "./declared.mjs";
3
4
  import { Unauthenticated } from "./errors.mjs";
4
5
  import { reportedTo, streamReportedTo } from "./progress.mjs";
5
6
  import { elementOf } from "./stream.mjs";
6
- import { Array, Cause, Context, Effect, Exit, Layer, Option, Predicate, References, Schema, Stream } from "effect";
7
7
  // src/contract/implementation.ts
8
8
  const uniqueKey = () => Math.random().toString(36).slice(2);
9
9
  const notAStream = /* @__PURE__ */ new Error("A handler answered otherwise than its action's success declares");
@@ -23,6 +23,25 @@ const asDefects = (reason, rejected) => {
23
23
  const trace = Context.makeUnsafe(reason.annotations);
24
24
  return [Cause.makeDieReason(reason.error).annotate(trace), Cause.makeDieReason(Cause.squash(rejected)).annotate(trace)];
25
25
  };
26
+ const failsOnly = (cause) => cause.reasons.every(Cause.isFailReason);
27
+ const noteAnswer = (cause) => {
28
+ const error = Option.getOrUndefined(Cause.findErrorOption(cause));
29
+ return Effect.annotateCurrentSpan("error.type", Predicate.hasProperty(error, "_tag") && Predicate.isString(error._tag) ? error._tag : "_OTHER");
30
+ };
31
+ var Answered = class {
32
+ cause;
33
+ constructor(cause) {
34
+ this.cause = cause;
35
+ }
36
+ };
37
+ const answeredIn = (cause) => failsOnly(cause) ? Effect.as(noteAnswer(cause), new Answered(cause)) : Effect.failCause(cause);
38
+ const unanswered = (value) => value instanceof Answered ? Effect.failCause(value.cause) : Effect.succeed(value);
39
+ const withAnsweringSpan = (name, options) => (stream) => Stream.suspend(() => {
40
+ let answer;
41
+ return stream.pipe(Stream.catchCause((cause) => failsOnly(cause) ? Stream.fromEffectDrain(Effect.andThen(noteAnswer(cause), Effect.sync(() => {
42
+ answer = cause;
43
+ }))) : Stream.failCause(cause)), Stream.withSpan(name, options), Stream.concat(Stream.suspend(() => answer === void 0 ? Stream.empty : Stream.failCause(answer))));
44
+ });
26
45
  const dispatch = (action, handle, before, keyed) => {
27
46
  const actionAttributes = {
28
47
  "action.name": action.name,
@@ -47,12 +66,12 @@ const dispatch = (action, handle, before, keyed) => {
47
66
  return (input, sink) => Effect.succeed(Stream.unwrap(Effect.map(admitted, () => streamReportedTo(action.progress, sink, (reporting) => streamed(handle(input, reporting))))).pipe(Stream.catchCause((cause) => Stream.fromEffect(declaredOrDefect(cause))), Stream.updateService(References.CurrentLogAnnotations, (annotations) => ({
48
67
  ...annotations,
49
68
  ...actionAttributes
50
- })), Stream.withSpan(action.name, {
69
+ })), withAnsweringSpan(action.name, {
51
70
  ...span,
52
71
  ...trace
53
72
  })));
54
73
  }
55
- return (input, sink) => Effect.scoped(admitted.pipe(Effect.andThen(Effect.suspend(() => reportedTo(action.progress, sink, (reporting) => answered(handle(input, reporting))))), Effect.provideService(CallerKeyed, keyed), Effect.catchCause(declaredOrDefect))).pipe(Effect.annotateLogs(actionAttributes), Effect.withSpan(action.name, span, trace));
74
+ return (input, sink) => Effect.scoped(admitted.pipe(Effect.andThen(Effect.suspend(() => reportedTo(action.progress, sink, (reporting) => answered(handle(input, reporting))))), Effect.provideService(CallerKeyed, keyed), Effect.catchCause(declaredOrDefect))).pipe(Effect.annotateLogs(actionAttributes), Effect.catchCause(answeredIn), Effect.withSpan(action.name, span, trace), Effect.flatMap(unanswered));
56
75
  };
57
76
  /**
58
77
  * Actions bound to their handlers and their authorizer: everything one `Action.implement` call
@@ -1,6 +1,6 @@
1
+ import { Predicate, Schema, SchemaAST } from "effect";
1
2
  import { unsuspended } from "./ast.mjs";
2
3
  import { Media, kindOf } from "./media.mjs";
3
- import { Predicate, Schema, SchemaAST } from "effect";
4
4
  // src/contract/lift.ts
5
5
  const isMedia = Schema.is(Media);
6
6
  const isMediaArray = Schema.is(Schema.Array(Media));
@@ -1,4 +1,4 @@
1
- import { Duration, Effect, Stream } from "effect";
1
+ import "effect";
2
2
  /** One entry of a log: what was published, and the key it was published to, if any. */
3
3
  export interface Logged<A> {
4
4
  readonly value: A;
@@ -1,6 +1,6 @@
1
+ import { Cause, Clock, Duration, Effect, Option, Queue, Semaphore, Stream } from "effect";
1
2
  import { uniqueKey } from "./implementation.mjs";
2
3
  import { reported } from "./reported.mjs";
3
- import { Cause, Clock, Duration, Effect, Option, Queue, Semaphore, Stream } from "effect";
4
4
  // src/contract/log.ts
5
5
  const defaultBounds = {
6
6
  maxAge: Duration.minutes(10),
@@ -1,4 +1,4 @@
1
- import { Schema, SchemaAST } from "effect";
1
+ import { Schema } from "effect";
2
2
  /**
3
3
  * An image, a media field of a success: `{ data: Uint8Array, mimeType: string }`, `mimeType` such
4
4
  * as `image/png`. A top-level field of a struct success, one, optional, or a required array, the
@@ -1,5 +1,5 @@
1
+ import { Schema } from "effect";
1
2
  import { Any } from "../Event.mjs";
2
- import { Effect, Schema } from "effect";
3
3
  /**
4
4
  * Occurrences were missed: the cursor resumed from was no longer served, or delivery skipped
5
5
  * some. `cursor` is where delivery continues.
@@ -1,6 +1,6 @@
1
1
  import { Checked, OccurrenceSchema } from "./occurrence.mjs";
2
+ import { Duration, Schema } from "effect";
2
3
  import { Any, Occurrence, Received } from "../Event.mjs";
3
- import { Duration, Effect, Schema, Stream } from "effect";
4
4
  /** One poll's answer, as a surface sends it and a client reads it. */
5
5
  export interface Page {
6
6
  readonly events: ReadonlyArray<Occurrence<Any>>;
@@ -1,5 +1,5 @@
1
- import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
2
1
  import { Duration, Effect, Option, Schema, Stream } from "effect";
2
+ import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
3
3
  // src/contract/pages.ts
4
4
  const pageFields = (occurrence) => ({
5
5
  events: Schema.Array(occurrence),
@@ -1,6 +1,6 @@
1
+ import { Effect } from "effect";
1
2
  import { Codec } from "./codec.mjs";
2
3
  import { ErasedValue } from "./implementation.mjs";
3
- import { Data, Effect, Scope, Stream } from "effect";
4
4
  export interface Reporting {
5
5
  readonly progress: (value: ErasedValue) => Effect.Effect<void>;
6
6
  }
@@ -1,9 +1,9 @@
1
1
  import { OccurrenceSchema } from "./occurrence.mjs";
2
2
  import { Codec } from "./codec.mjs";
3
+ import { Schema } from "effect";
3
4
  import "./errors.mjs";
4
5
  import { Any } from "../Event.mjs";
5
6
  import "./pages.mjs";
6
- import { Cause, Effect, Queue, Schema, Stream } from "effect";
7
7
  export declare const PushedOf: <E extends Any>(event: E) => Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
8
8
  readonly cursor: Schema.NullOr<Schema.String>;
9
9
  }>, Schema.TaggedStruct<"Checked", {
@@ -1,8 +1,8 @@
1
+ import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "effect";
1
2
  import { Refusal } from "./errors.mjs";
2
3
  import { defaultNextPoll } from "./feed.mjs";
3
4
  import { Checked, Gap, OccurrenceOf } from "./occurrence.mjs";
4
5
  import { reported } from "./reported.mjs";
5
- import { Cause, Duration, Effect, Latch, Match, Queue, Schema, Stream } from "effect";
6
6
  // src/contract/push.ts
7
7
  const Failed = Schema.TaggedStruct("Failed", {});
8
8
  const PushedOf = (event) => Schema.Union([
@@ -1,8 +1,8 @@
1
+ import { Context, Effect, Schema, Scope } from "effect";
1
2
  import { SigningSecret } from "./callback.mjs";
2
3
  import "./errors.mjs";
3
4
  import "../Event.mjs";
4
5
  import "./pages.mjs";
5
- import { Context, Effect, Schema, Scope } from "effect";
6
6
  /** A POST a receiver verified, its JSON body: an occurrence, or an envelope. */
7
7
  export interface Delivered {
8
8
  readonly [key: string]: Schema.Json;
@@ -1,7 +1,7 @@
1
+ import { Context, Effect, Option, Schema, Struct } from "effect";
1
2
  import { reasonOf, refusalOf } from "./codes.mjs";
2
3
  import { Forbidden } from "./errors.mjs";
3
4
  import { Gap, untaggedOccurrenceOf } from "./occurrence.mjs";
4
- import { Context, Effect, Option, Schema, Struct } from "effect";
5
5
  // src/contract/receiving.ts
6
6
  const watchParameter = "watch";
7
7
  /**
@@ -1,8 +1,8 @@
1
+ import { Effect, Schema, Stream as Stream$1 } from "effect";
1
2
  import { Codec, CodecOf, Fields } from "./codec.mjs";
2
- import { Data, Effect, Schema, Stream } from "effect";
3
3
  declare const TypeId = "~effect-actions/Stream";
4
4
  /** The success of an action answering a stream: a schema of `Stream`s, holding its element's. */
5
- export interface StreamOf<Element extends Codec> extends Schema.declare<Stream.Stream<Element["Type"]>> {
5
+ export interface StreamOf<Element extends Codec> extends Schema.declare<Stream$1.Stream<Element["Type"]>> {
6
6
  readonly Rebuild: StreamOf<Element>;
7
7
  readonly [TypeId]: typeof TypeId;
8
8
  /** The schema of each element. */
@@ -21,9 +21,9 @@ export interface StreamOf<Element extends Codec> extends Schema.declare<Stream.S
21
21
  * - An element breaking its schema is the call's defect, as an answer breaking `success` is.
22
22
  * - With `progress`, values and elements are each in their order, not against each other: a value may reach `onProgress` after an element yielded after it.
23
23
  */
24
- declare const Stream$1: <const E extends Codec | Fields>(element: E) => StreamOf<CodecOf<E>>;
24
+ export declare const Stream: <const E extends Codec | Fields>(element: E) => StreamOf<CodecOf<E>>;
25
25
  /** What a handler or a call of an action with success `S` answers: a stream, or one value. */
26
- export type Answer<S extends Codec, E, R> = [S] extends [never] ? Effect.Effect<never, E, R> : [S] extends [StreamOf<infer Element>] ? Stream.Stream<Element["Type"], E, R> : Effect.Effect<S["Type"], E, R>;
26
+ export type Answer<S extends Codec, E, R> = [S] extends [never] ? Effect.Effect<never, E, R> : [S] extends [StreamOf<infer Element>] ? Stream$1.Stream<Element["Type"], E, R> : Effect.Effect<S["Type"], E, R>;
27
27
  /**
28
28
  * The success a tool answers for an action with success `S`: an array of the elements of one
29
29
  * answering a stream, collected whole, or `S`.
@@ -31,4 +31,4 @@ export type Answer<S extends Codec, E, R> = [S] extends [never] ? Effect.Effect<
31
31
  export type ToolSuccess<S extends Codec> = [S] extends [StreamOf<infer Element>] ? Schema.$Array<Element> : S;
32
32
  /** What a call of an action with success `S` gives one at a time: an element, or its answer. */
33
33
  export type Each<S extends Codec> = [S] extends [StreamOf<infer Element>] ? Element["Type"] : S["Type"];
34
- export { Stream$1 as Stream };
34
+ export {};
@@ -1,8 +1,8 @@
1
+ import { Data, Predicate, Schema, Stream as Stream$1 } from "effect";
1
2
  import { codecOf } from "./codec.mjs";
2
- import { Data, Predicate, Schema, Stream } from "effect";
3
3
  // src/contract/stream.ts
4
4
  const TypeId = "~effect-actions/Stream";
5
- const streams = Schema.declare(Stream.isStream);
5
+ const streams = Schema.declare(Stream$1.isStream);
6
6
  /**
7
7
  * A success that is a stream of `element`, a schema or struct fields: the handler returns a
8
8
  * `Stream` of them, which may fail with the action's errors, and every client's call returns
@@ -16,7 +16,7 @@ const streams = Schema.declare(Stream.isStream);
16
16
  * - An element breaking its schema is the call's defect, as an answer breaking `success` is.
17
17
  * - With `progress`, values and elements are each in their order, not against each other: a value may reach `onProgress` after an element yielded after it.
18
18
  */
19
- const Stream$1 = (element) => Schema.make(streams.ast, {
19
+ const Stream = (element) => Schema.make(streams.ast, {
20
20
  [TypeId]: TypeId,
21
21
  element: codecOf(element)
22
22
  });
@@ -38,4 +38,4 @@ const toolSuccessOf = (success) => {
38
38
  const element = elementOf(success);
39
39
  return element === void 0 ? success : Schema.Array(element);
40
40
  };
41
- export { Answering, Stream$1 as Stream, answeringOf, elementOf, toolSuccessOf };
41
+ export { Answering, Stream, answeringOf, elementOf, toolSuccessOf };
@@ -1,6 +1,6 @@
1
1
  import { Codec } from "./codec.mjs";
2
- import { Any } from "../Event.mjs";
3
2
  import { Schema } from "effect";
3
+ import { Any } from "../Event.mjs";
4
4
  export declare const WebhookSubscriptionOf: <E extends Any>(event: E) => Schema.Struct<{
5
5
  readonly input: Codec;
6
6
  readonly cursor: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.String>, never>;
@@ -1,7 +1,7 @@
1
+ import { Schema, Struct } from "effect";
1
2
  import { CallbackUrl, WebhookSecret } from "./callback.mjs";
2
3
  import { CallbackCategory, SubscriptionError, Unsupported } from "../Event.mjs";
3
4
  import { SubscriptionOf } from "./push.mjs";
4
- import { Schema, Struct } from "effect";
5
5
  // src/contract/subscribe.ts
6
6
  const deliveryUnsupported = (event, mode) => SubscriptionError.of(event, new Unsupported({
7
7
  feature: "deliveryMode",
@@ -1,7 +1,7 @@
1
- import { readOn } from "./push.mjs";
2
- import { isTransientStatus } from "./status.mjs";
3
1
  import { Cause, Duration, Effect, Function, Match, Predicate, Stream } from "effect";
4
2
  import { HttpClientError } from "effect/http";
3
+ import { readOn } from "./push.mjs";
4
+ import { isTransientStatus } from "./status.mjs";
5
5
  // src/contract/transient.ts
6
6
  const answeredStatus = ({ reason }) => Match.value(reason).pipe(Match.tag("StatusCodeError", "DecodeError", ({ response }) => response.status), Match.orElse(Function.constUndefined));
7
7
  const isTransientReason = (reason) => Match.value(reason).pipe(Match.tag("TransportError", () => true), Match.tag("DecodeError", ({ response }) => response.status < 300 || isTransientStatus(response.status)), Match.tag("StatusCodeError", ({ response }) => isTransientStatus(response.status)), Match.orElse(() => false));
@@ -1,5 +1,5 @@
1
- import { Unavailable } from "./errors.mjs";
2
1
  import { Context, Effect } from "effect";
2
+ import { Unavailable } from "./errors.mjs";
3
3
  declare const Wake_base: Context.ServiceClass<Wake, "effect-actions/Wake", {
4
4
  readonly wakeAt: (at: number) => Effect.Effect<void, Unavailable>;
5
5
  readonly until: (at: number) => Effect.Effect<void>;
@@ -1,8 +1,8 @@
1
+ import "effect";
1
2
  import { Any, WatchOptions, WebhookDelivery } from "../Event.mjs";
2
3
  import "./pages.mjs";
3
4
  import { Receiving } from "./receiving.mjs";
4
5
  import "./subscribe.mjs";
5
- import { Effect, Schema, Stream } from "effect";
6
6
  /**
7
7
  * The arguments of `watch(event, ...)` after the event: its input, which may be left out when
8
8
  * `{}` is a valid encoded input, as for an action's call, and the watch's options `O`, whose
@@ -1,3 +1,4 @@
1
+ import { Cause, Clock, Duration, Effect, Predicate, Queue, Schedule, Schema, Stream } from "effect";
1
2
  import { CallbackUrl } from "./callback.mjs";
2
3
  import { isUnavailable } from "./errors.mjs";
3
4
  import { SubscriptionError } from "../Event.mjs";
@@ -6,7 +7,6 @@ import { paged } from "./pages.mjs";
6
7
  import { watchParameter } from "./receiving.mjs";
7
8
  import { makeRecent } from "./recent.mjs";
8
9
  import { deliveryUnsupported } from "./subscribe.mjs";
9
- import { Cause, Clock, Duration, Effect, Predicate, Queue, Schedule, Schema, Stream } from "effect";
10
10
  // src/contract/watch.ts
11
11
  const reconnectDelay = Duration.seconds(1);
12
12
  const maxReconnectDelay = Duration.seconds(30);
@@ -1,8 +1,8 @@
1
+ import { Context, Effect } from "effect";
1
2
  import { Anyone, Keyed } from "./caller.mjs";
2
3
  import { Any } from "../Event.mjs";
3
4
  import { Feed } from "./feed.mjs";
4
5
  import { AnyWebhookCancellation, AnyWebhookSubscription, Subscribed } from "./subscribe.mjs";
5
- import { Context, Effect, Option } from "effect";
6
6
  /** An event type a surface may offer by webhook: a protected one, its caller an identity. */
7
7
  export type Protected = Any & {
8
8
  readonly caller: Exclude<Any["caller"], typeof Anyone>;
@@ -1,7 +1,7 @@
1
+ import { Context, Effect, Option } from "effect";
1
2
  import { Anyone } from "./caller.mjs";
2
3
  import { acquireFeeds } from "./feed.mjs";
3
4
  import { deliveryUnsupported } from "./subscribe.mjs";
4
- import { Context, Effect, Option } from "effect";
5
5
  // src/contract/webhooks.ts
6
6
  /**
7
7
  * Where a surface's webhook subscriptions are held and delivered from: `Webhook.layer` provides
@@ -1,4 +1,4 @@
1
- import { Effect } from "effect";
1
+ import "effect";
2
2
  import { Headers } from "effect/http";
3
3
  /**
4
4
  * The headers of a request that a call into an entity carries, their names lowercased: every
@@ -1,8 +1,8 @@
1
- import { reported } from "../contract/reported.mjs";
2
- import { Wake } from "../contract/wake.mjs";
3
1
  import { Clock, DateTime, Deferred, Duration, Effect, Schema, Semaphore } from "effect";
4
2
  import { ClusterSchema, DeliverAt } from "effect/cluster";
5
3
  import { Rpc } from "effect/rpc";
4
+ import { reported } from "../contract/reported.mjs";
5
+ import { Wake } from "../contract/wake.mjs";
6
6
  // src/entity/wakes.ts
7
7
  const wakeTag = "effect-actions/wake";
8
8
  var WakeAt = class extends Schema.Class("effect-actions/ActionEntity/WakeAt")({ at: Schema.Int }) {
@@ -19,7 +19,7 @@ const makeWake = (send) => Effect.gen(function* () {
19
19
  const clock = yield* Clock.Clock;
20
20
  const lock = yield* Semaphore.make(1);
21
21
  const pending = /* @__PURE__ */ new Set();
22
- let latest = -Infinity;
22
+ let latest = -1e400;
23
23
  let fired = Deferred.makeUnsafe();
24
24
  const stored = (at, covers) => lock.withPermit(Effect.suspend(() => [...pending].some(covers) ? Effect.void : Effect.uninterruptible(Effect.tap(send(new WakeAt({ at })), () => Effect.sync(() => pending.add(at))))));
25
25
  const slept = (at) => clock.sleep(Duration.millis(Math.max(at - clock.currentTimeMillisUnsafe(), 0)));
@@ -1,3 +1,6 @@
1
+ import { Schema, Stream } from "effect";
2
+ import { HttpClient, HttpClientError } from "effect/http";
3
+ import { HttpApi, HttpApiClient } from "effect/http-api";
1
4
  import { Any, VerifierError } from "../authentication/provider.mjs";
2
5
  import { Any as Any$1, Errors } from "../Action.mjs";
3
6
  import { Call } from "../contract/call.mjs";
@@ -9,9 +12,6 @@ import "../contract/receiving.mjs";
9
12
  import { Answer, StreamOf } from "../contract/stream.mjs";
10
13
  import { WatchArgs, WatchRequirement } from "../contract/watch.mjs";
11
14
  import { sentOf } from "./events.mjs";
12
- import { Effect, Schema, Stream } from "effect";
13
- import { HttpClient, HttpClientError } from "effect/http";
14
- import { HttpApi, HttpApiClient } from "effect/http-api";
15
15
  /**
16
16
  * The native `HttpApiClient.make` options except `transformResponse`, which may change a call's
17
17
  * success, failure or services the method types cannot follow: `baseUrl`, and `transformClient`,
@@ -1,11 +1,11 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { HttpClient, HttpClientRequest } from "effect/http";
3
+ import { HttpApiClient } from "effect/http-api";
1
4
  import { checked, checkedStream, sendingValue, sentInput } from "../contract/call.mjs";
2
5
  import { Answering, answeringOf } from "../contract/stream.mjs";
3
6
  import { watching } from "../contract/watch.mjs";
4
7
  import { readElements, readWithProgress } from "./streamed.mjs";
5
8
  import { transportOf } from "./watch.mjs";
6
- import { Effect, Stream } from "effect";
7
- import { HttpClient, HttpClientRequest } from "effect/http";
8
- import { HttpApiClient } from "effect/http-api";
9
9
  // src/http/client.ts
10
10
  const methodOf = (native, name, what) => {
11
11
  const method = native[name];
@@ -2,13 +2,13 @@ import { OccurrenceSchema } from "../contract/occurrence.mjs";
2
2
  import { Forbidden, Unauthenticated } from "../contract/errors.mjs";
3
3
  import "../contract/codec.mjs";
4
4
  import "../contract/pages.mjs";
5
+ import { Schema } from "effect";
6
+ import { HttpApiSchema } from "effect/http-api";
5
7
  import "../authentication/provider.mjs";
6
8
  import "../Action.mjs";
7
9
  import { Any } from "../Event.mjs";
8
10
  import "../contract/feed.mjs";
9
11
  import "../contract/push.mjs";
10
- import { Effect, Schema, Stream } from "effect";
11
- import { HttpApiEndpoint, HttpApiSchema } from "effect/http-api";
12
12
  export declare const sentOf: <E extends Any>(event: E) => HttpApiSchema.StreamSse<HttpApiSchema.SseEventFromData<Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
13
13
  readonly cursor: Schema.NullOr<Schema.String>;
14
14
  }>, Schema.TaggedStruct<"Checked", {
@@ -1,3 +1,6 @@
1
+ import { Effect, Function, Schema, Stream } from "effect";
2
+ import { HttpServerRequest } from "effect/http";
3
+ import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
1
4
  import { principalOf } from "../contract/caller.mjs";
2
5
  import { assertDistinctTags } from "../contract/declared.mjs";
3
6
  import { Refusal } from "../contract/errors.mjs";
@@ -7,9 +10,6 @@ import { PushedOf, SubscriptionOf, queuedPush } from "../contract/push.mjs";
7
10
  import { declared } from "../contract/status.mjs";
8
11
  import { Subscribed, WebhookCancellationOf, WebhookSubscriptionOf } from "../contract/subscribe.mjs";
9
12
  import { acceptsEventStream } from "./streamed.mjs";
10
- import { Effect, Function, Schema, Stream } from "effect";
11
- import { HttpServerRequest } from "effect/http";
12
- import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
13
13
  // src/http/events.ts
14
14
  const sentOf = (event) => HttpApiSchema.StreamSse({
15
15
  data: PushedOf(event),
@@ -1,6 +1,6 @@
1
- import { InvalidInput } from "../contract/errors.mjs";
2
1
  import { Effect } from "effect";
3
2
  import { HttpApiMiddleware } from "effect/http-api";
3
+ import { InvalidInput } from "../contract/errors.mjs";
4
4
  // src/http/schema-errors.ts
5
5
  const responseEncodingKinds = /* @__PURE__ */ new Set(["Body", "ResponseHeaders"]);
6
6
  var SchemaErrors = class extends HttpApiMiddleware.Service()("effect-actions/http/SchemaErrors", { error: [InvalidInput] }) {};
@@ -1,11 +1,11 @@
1
+ import { Schema } from "effect";
2
+ import "effect/http";
3
+ import { HttpApiSchema } from "effect/http-api";
1
4
  import { Any } from "../Action.mjs";
2
5
  import { Codec } from "../contract/codec.mjs";
3
6
  import "../contract/implementation.mjs";
4
7
  import "../contract/progress.mjs";
5
8
  import { StreamOf } from "../contract/stream.mjs";
6
- import { Effect, Schema, Stream } from "effect";
7
- import { HttpServerRequest } from "effect/http";
8
- import { HttpApiSchema } from "effect/http-api";
9
9
  declare const Sent: Schema.Struct<{
10
10
  readonly event: Schema.Literals<readonly ["progress", "element", "final"]>;
11
11
  readonly data: Schema.Unknown;
@@ -1,9 +1,9 @@
1
- import { elementsOf } from "../contract/implementation.mjs";
2
- import { Progressed, answerFrom, elementsFrom } from "../contract/progress.mjs";
3
- import { concealed } from "../contract/reported.mjs";
4
1
  import { Cause, Duration, Effect, ErrorReporter, Queue, Schema, Stream } from "effect";
5
2
  import { HttpServerRequest } from "effect/http";
6
3
  import { HttpApiSchema } from "effect/http-api";
4
+ import { elementsOf } from "../contract/implementation.mjs";
5
+ import { Progressed, answerFrom, elementsFrom } from "../contract/progress.mjs";
6
+ import { concealed } from "../contract/reported.mjs";
7
7
  // src/http/streamed.ts
8
8
  const Sent = Schema.Struct({
9
9
  event: Schema.Literals([
@@ -1,7 +1,7 @@
1
- import { Unavailable, isUnavailable } from "../contract/errors.mjs";
2
1
  import { Cause, Effect, ErrorReporter, Layer, Schema } from "effect";
3
2
  import { HttpServerResponse } from "effect/http";
4
3
  import { HttpApiMiddleware } from "effect/http-api";
4
+ import { Unavailable, isUnavailable } from "../contract/errors.mjs";
5
5
  // src/http/unavailable.ts
6
6
  const encode = Schema.encodeUnknownSync(Schema.toCodecJson(Unavailable));
7
7
  var RetryAfter = class extends HttpApiMiddleware.Service()("effect-actions/http/RetryAfter") {};
@@ -1,9 +1,9 @@
1
+ import { Effect, Predicate, Stream } from "effect";
2
+ import { HttpClientError } from "effect/http";
1
3
  import { NotServed, SubscriptionError } from "../Event.mjs";
2
4
  import { fedOf } from "../contract/pages.mjs";
3
5
  import { Receiving, webhookFed } from "../contract/receiving.mjs";
4
6
  import { answeredStatus, failingWhenUnanswered, isTransient, receivedFrom } from "../contract/transient.mjs";
5
- import { Effect, Predicate, Stream } from "effect";
6
- import { HttpClientError } from "effect/http";
7
7
  // src/http/watch.ts
8
8
  const isNotFound = Predicate.compose(HttpClientError.isHttpClientError, (error) => answeredStatus(error) === 404);
9
9
  const transportOf = (event, poll, stream, webhook, input) => {
@@ -1,3 +1,6 @@
1
+ import { Cause, Context, Duration, Effect, Exit, Match, Option, Predicate, Result, Schema } from "effect";
2
+ import { McpSchema, McpServer } from "effect/ai";
3
+ import { HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/http";
1
4
  import { asCaller } from "../authentication/refusal.mjs";
2
5
  import { inputParseOptions } from "../contract/call.mjs";
3
6
  import { principalOf } from "../contract/caller.mjs";
@@ -11,9 +14,6 @@ import { deliveryUnsupported } from "../contract/subscribe.mjs";
11
14
  import { Webhooks, subscriberOf, webhookSubscriber } from "../contract/webhooks.mjs";
12
15
  import { Active, EventsError, Failed, Heartbeat, Notifications, Occurred, Requests, Terminated, codes, extension, subscriptionIdKey } from "./events.mjs";
13
16
  import { isObjectSchema, toolJsonSchema } from "./protocol.mjs";
14
- import { Cause, Context, Duration, Effect, Exit, Match, Option, Predicate, Result, Schema } from "effect";
15
- import { HttpEffect, HttpServerRequest, HttpServerResponse } from "effect/http";
16
- import { McpSchema, McpServer } from "effect/ai";
17
17
  // src/mcp/bridge.ts
18
18
  const isGroup = (u) => Predicate.isObjectKeyword(u) && "merge" in u && Predicate.isFunction(u.merge) && "requests" in u && u.requests instanceof Map;
19
19
  const groupOf = (adapter, key) => {
@@ -1,3 +1,5 @@
1
+ import { Effect, Schema, Stream } from "effect";
2
+ import { HttpClient, HttpClientError } from "effect/http";
1
3
  import { Any, VerifierError } from "../authentication/provider.mjs";
2
4
  import { Any as Any$1 } from "../Action.mjs";
3
5
  import { Call } from "../contract/call.mjs";
@@ -6,8 +8,6 @@ import { Any as Any$2, Received, SubscriptionError, WatchOptions } from "../Even
6
8
  import { Answer } from "../contract/stream.mjs";
7
9
  import { WatchArgs, WatchRequirement } from "../contract/watch.mjs";
8
10
  import { McpCallError } from "./reply.mjs";
9
- import { Effect, Schema, Stream } from "effect";
10
- import { HttpClient, HttpClientError } from "effect/http";
11
11
  /**
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`.
@@ -1,3 +1,6 @@
1
+ import { Effect, Option, Schema, Stream } from "effect";
2
+ import { McpSchema } from "effect/ai";
3
+ import { HttpClient } from "effect/http";
1
4
  import { checked, checkedStream, sendingJson, sentInput } from "../contract/call.mjs";
2
5
  import { Anyone } from "../contract/caller.mjs";
3
6
  import { projectedErrors } from "../contract/declared.mjs";
@@ -12,9 +15,6 @@ import { defaultPath, errorKey, isText, unliftedFrom } from "./protocol.mjs";
12
15
  import { NoReply, ProtocolError, StatusError, UndeclaredError, UnexpectedContent, bodyOf, callError, failWith } from "./reply.mjs";
13
16
  import { request } from "./request.mjs";
14
17
  import { transportOf } from "./watch.mjs";
15
- import { Effect, Option, Schema, Stream } from "effect";
16
- import { HttpClient } from "effect/http";
17
- import { McpSchema } from "effect/ai";
18
18
  // src/mcp/client.ts
19
19
  const textOf = (block) => block?.type === "text" ? block.text : void 0;
20
20
  const ToolCallReply = Schema.Union([Schema.Struct({ result: McpSchema.CallToolResult }), Schema.Struct({ error: Schema.Struct({
@@ -1,8 +1,8 @@
1
- import { eventCodes } from "../contract/codes.mjs";
2
- import { Subscribed, WebhookCallback, WebhookTarget, webhookFields } from "../contract/subscribe.mjs";
3
1
  import { ErrorReporter, Schema, Struct } from "effect";
4
2
  import { McpSchema } from "effect/ai";
5
3
  import { Rpc, RpcGroup } from "effect/rpc";
4
+ import { eventCodes } from "../contract/codes.mjs";
5
+ import { Subscribed, WebhookCallback, WebhookTarget, webhookFields } from "../contract/subscribe.mjs";
6
6
  // src/mcp/events.ts
7
7
  const extension = "io.modelcontextprotocol/events";
8
8
  const subscriptionIdKey = "io.modelcontextprotocol/subscriptionId";
@@ -1,6 +1,6 @@
1
- import { progressSink } from "../contract/progress.mjs";
2
1
  import { Effect, Option, Schema } from "effect";
3
2
  import { McpSchema } from "effect/ai";
3
+ import { progressSink } from "../contract/progress.mjs";
4
4
  // src/mcp/progress.ts
5
5
  const progressKey = "io.github.gjermundgaraba.effect-actions/progress";
6
6
  const tokenOf = Schema.decodeUnknownOption(McpSchema.ProgressToken);
@@ -1,7 +1,7 @@
1
- import { isMarked } from "../contract/media.mjs";
2
1
  import { JsonPointer, Predicate, Schema, SchemaAST } from "effect";
3
- import { Base64 } from "effect/encoding";
4
2
  import { McpProtocol, McpSchema } from "effect/ai";
3
+ import { Base64 } from "effect/encoding";
4
+ import { isMarked } from "../contract/media.mjs";
5
5
  // src/mcp/protocol.ts
6
6
  const httpProtocol = McpProtocol.v2026_07_28;
7
7
  const protocols = [
@@ -1,7 +1,7 @@
1
+ import { Schema } from "effect";
2
+ import "effect/http";
1
3
  import "../Action.mjs";
2
4
  import "../contract/progress.mjs";
3
- import { Effect, Schema, Stream } from "effect";
4
- import { HttpClientError } from "effect/http";
5
5
  declare const StatusError_base: Schema.Class<StatusError, Schema.TaggedStruct<"StatusError", {
6
6
  readonly status: Schema.Int;
7
7
  readonly body: Schema.String;
@@ -1,6 +1,6 @@
1
- import { progressOf } from "./progress.mjs";
2
1
  import { Effect, Match, Option, Predicate, Schema, Stream } from "effect";
3
2
  import { Sse } from "effect/encoding";
3
+ import { progressOf } from "./progress.mjs";
4
4
  // src/mcp/reply.ts
5
5
  /** The endpoint answered with an HTTP status other than 200, and a body no declared error decodes. */
6
6
  var StatusError = class extends Schema.TaggedError()("StatusError", {
@@ -1,6 +1,6 @@
1
- import { defaultPath, httpProtocol } from "./protocol.mjs";
2
1
  import { Predicate } from "effect";
3
2
  import { HttpClientRequest } from "effect/http";
3
+ import { defaultPath, httpProtocol } from "./protocol.mjs";
4
4
  // src/mcp/request.ts
5
5
  const statelessRequest = (method, params) => {
6
6
  const { protocolVersion } = httpProtocol;