@gjermundgaraba/effect-actions 0.21.0 → 0.23.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.
- package/README.md +7 -1
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -0
- package/dist/ActionCli.mjs +0 -1
- package/dist/ActionHttp.d.mts +1 -1
- package/dist/ActionMcp.d.mts +0 -3
- package/dist/ActionMcp.mjs +0 -5
- package/dist/ActionRpc.d.mts +8 -15
- package/dist/ActionRpc.mjs +29 -54
- package/dist/ActionToolkit.d.mts +0 -2
- package/dist/ActionToolkit.mjs +0 -2
- package/dist/Event.d.mts +0 -23
- package/dist/Testing.mjs +3 -2
- package/dist/Webhook.mjs +2 -2
- package/dist/authentication/refusal.mjs +0 -1
- package/dist/cli/commands.mjs +0 -5
- package/dist/contract/authorizer.mjs +0 -5
- package/dist/contract/call.mjs +0 -23
- package/dist/contract/callback.mjs +0 -1
- package/dist/contract/caller.mjs +0 -11
- package/dist/contract/canonical.mjs +0 -5
- package/dist/contract/codec.d.mts +0 -1
- package/dist/contract/codec.mjs +0 -1
- package/dist/contract/codes.mjs +1 -15
- package/dist/contract/declared.mjs +0 -15
- package/dist/contract/digest.mjs +0 -1
- package/dist/contract/errors.d.mts +0 -4
- package/dist/contract/errors.mjs +0 -4
- package/dist/contract/feed.d.mts +0 -1
- package/dist/contract/feed.mjs +0 -20
- package/dist/contract/hints.mjs +0 -6
- package/dist/contract/hub.mjs +0 -3
- package/dist/contract/idempotency.mjs +0 -4
- package/dist/contract/implementation.d.mts +0 -1
- package/dist/contract/implementation.mjs +0 -27
- package/dist/contract/input-check.mjs +0 -1
- package/dist/contract/lease.mjs +0 -1
- package/dist/contract/listed.mjs +0 -6
- package/dist/contract/log.mjs +0 -8
- package/dist/contract/names.mjs +0 -1
- package/dist/contract/occurrence.mjs +0 -8
- package/dist/contract/pages.mjs +5 -12
- package/dist/contract/progress.mjs +2 -25
- package/dist/contract/push.d.mts +0 -5
- package/dist/contract/push.mjs +1 -24
- package/dist/contract/receiving.mjs +0 -7
- package/dist/contract/reported.mjs +0 -5
- package/dist/contract/serving.mjs +0 -18
- package/dist/contract/status.mjs +0 -3
- package/dist/contract/stream.mjs +0 -2
- package/dist/contract/subscribe.d.mts +0 -2
- package/dist/contract/subscribe.mjs +0 -8
- package/dist/contract/transient.mjs +0 -12
- package/dist/contract/watch.mjs +5 -17
- package/dist/contract/webhooks.mjs +0 -11
- package/dist/http/client.mjs +0 -1
- package/dist/http/events.d.mts +0 -10
- package/dist/http/events.mjs +2 -31
- package/dist/http/placed.d.mts +0 -2
- package/dist/http/streamed.d.mts +0 -1
- package/dist/http/streamed.mjs +4 -32
- package/dist/http/watch.mjs +0 -6
- package/dist/mcp/bridge.mjs +0 -25
- package/dist/mcp/client.d.mts +0 -1
- package/dist/mcp/client.mjs +0 -1
- package/dist/mcp/events.mjs +0 -6
- package/dist/mcp/progress.mjs +0 -7
- package/dist/mcp/protocol.mjs +0 -6
- package/dist/mcp/reply.mjs +0 -11
- package/dist/mcp/request.mjs +0 -1
- package/dist/mcp/watch.mjs +0 -6
- package/dist/rpc/watch.mjs +0 -6
- package/dist/stdio/console.mjs +2 -2
- package/dist/webhook/address.mjs +4 -9
- package/dist/webhook/attempt.mjs +2 -15
- package/dist/webhook/receiver.mjs +2 -8
- package/dist/webhook/signing.mjs +0 -3
- package/dist/webhook/stored.mjs +8 -17
- package/dist/webhook/subscriptions.mjs +19 -23
- package/docs/Action-streams.md +0 -12
- package/docs/Action.md +0 -10
- package/docs/ActionCli.md +2 -26
- package/docs/ActionHttp.md +0 -28
- package/docs/ActionMcp.md +2 -37
- package/docs/ActionRpc-events.md +0 -16
- package/docs/ActionRpc.md +0 -63
- package/docs/ActionToolkit.md +0 -11
- package/docs/Authentication-advanced.md +0 -31
- package/docs/Authentication.md +4 -13
- package/docs/Event.md +0 -37
- package/docs/README.md +1 -1
- package/docs/Testing.md +3 -13
- package/docs/Webhook.md +0 -46
- package/docs/setup.md +0 -5
- package/examples/README.md +7 -1
- package/examples/assistant/src/agent.ts +8 -31
- package/examples/assistant/src/cli.ts +2 -9
- package/examples/assistant/src/commands.ts +0 -8
- package/examples/assistant/src/identity/Identity.ts +0 -10
- package/examples/assistant/src/identity/authorize.ts +0 -4
- package/examples/assistant/src/identity/members.ts +1 -3
- package/examples/assistant/src/identity/permissions.ts +0 -5
- package/examples/assistant/src/platform/tasks-file.ts +1 -6
- package/examples/assistant/src/scripted.ts +0 -4
- package/examples/assistant/src/tasks/Tasks.ts +0 -2
- package/examples/assistant/src/tasks/handlers.ts +0 -3
- package/examples/assistant/src/tasks/store.ts +0 -7
- package/examples/assistant/src/toolkit.ts +0 -11
- package/examples/assistant/test/commands.test.ts +0 -5
- package/examples/assistant/test/identity/identity.test.ts +6 -6
- package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
- package/examples/assistant/test/tasks/tasks.test.ts +13 -14
- package/examples/assistant/test/toolkit.test.ts +7 -18
- package/examples/build-events/README.md +2 -0
- package/examples/build-events/src/Api.ts +0 -3
- package/examples/build-events/src/Rpc.ts +0 -2
- package/examples/build-events/src/builds/Builds.ts +0 -15
- package/examples/build-events/src/builds/events.ts +0 -10
- package/examples/build-events/src/builds/handlers.ts +0 -6
- package/examples/build-events/src/builds/log.ts +0 -6
- package/examples/build-events/src/builds/status.ts +0 -4
- package/examples/build-events/src/builds/store.ts +0 -21
- package/examples/build-events/src/cli.ts +0 -2
- package/examples/build-events/src/commands.ts +0 -9
- package/examples/build-events/src/deploys/approvers.ts +0 -3
- package/examples/build-events/src/deploys/events.ts +0 -8
- package/examples/build-events/src/deploys/handlers.ts +0 -2
- package/examples/build-events/src/identity/Identity.ts +0 -11
- package/examples/build-events/src/identity/members.ts +1 -2
- package/examples/build-events/src/identity/verifier.ts +8 -9
- package/examples/build-events/src/notifier/Notices.ts +0 -3
- package/examples/build-events/src/notifier/routes.ts +0 -10
- package/examples/build-events/src/notifier.ts +0 -8
- package/examples/build-events/src/routes.ts +0 -24
- package/examples/build-events/src/server.ts +0 -14
- package/examples/build-events/test/builds/events.test.ts +0 -6
- package/examples/build-events/test/builds/log.test.ts +0 -1
- package/examples/build-events/test/builds/progress.test.ts +0 -1
- package/examples/build-events/test/commands.test.ts +0 -5
- package/examples/build-events/test/deploys/events.test.ts +0 -1
- package/examples/build-events/test/http.test.ts +0 -4
- package/examples/build-events/test/notifier.test.ts +0 -9
- package/examples/build-events/test/routes.test.ts +0 -9
- package/examples/build-events/test/rpc.test.ts +0 -4
- package/examples/build-events/test/support/as.ts +3 -4
- package/examples/build-events/test/support/memory.ts +0 -5
- package/examples/build-events/test/webhooks.test.ts +0 -12
- package/examples/kitchen-sink/README.md +1 -1
- package/examples/kitchen-sink/src/Actions.ts +0 -10
- package/examples/kitchen-sink/src/Api.ts +0 -8
- package/examples/kitchen-sink/src/Rpc.ts +0 -4
- package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
- package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
- package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
- package/examples/kitchen-sink/src/admin/grants.ts +0 -5
- package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
- package/examples/kitchen-sink/src/admin/keys.ts +1 -3
- package/examples/kitchen-sink/src/agent.ts +2 -13
- package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
- package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
- package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
- package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
- package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
- package/examples/kitchen-sink/src/attachments/download.ts +0 -10
- package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
- package/examples/kitchen-sink/src/attachments/store.ts +0 -3
- package/examples/kitchen-sink/src/browser.ts +0 -9
- package/examples/kitchen-sink/src/cli.ts +0 -19
- package/examples/kitchen-sink/src/config.ts +3 -11
- package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
- package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
- package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
- package/examples/kitchen-sink/src/identity/directory.ts +8 -18
- package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
- package/examples/kitchen-sink/src/identity/members.ts +1 -5
- package/examples/kitchen-sink/src/identity/quota.ts +0 -11
- package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
- package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
- package/examples/kitchen-sink/src/issues/events.ts +2 -16
- package/examples/kitchen-sink/src/issues/export.ts +0 -5
- package/examples/kitchen-sink/src/issues/guide.ts +0 -5
- package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
- package/examples/kitchen-sink/src/issues/store.ts +19 -23
- package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
- package/examples/kitchen-sink/src/memory.ts +0 -9
- package/examples/kitchen-sink/src/ops.ts +0 -6
- package/examples/kitchen-sink/src/request-policy.ts +0 -17
- package/examples/kitchen-sink/src/routes.ts +0 -48
- package/examples/kitchen-sink/src/sdk.ts +0 -12
- package/examples/kitchen-sink/src/seed.ts +0 -10
- package/examples/kitchen-sink/src/server.ts +0 -22
- package/examples/kitchen-sink/src/stdio.ts +2 -12
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
- package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
- package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
- package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
- package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
- package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
- package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
- package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
- package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
- package/examples/kitchen-sink/test/routes.test.ts +0 -6
- package/examples/kitchen-sink/test/support/as.ts +3 -5
- package/examples/kitchen-sink/test/support/scripted.ts +0 -3
- package/examples/kitchen-sink/test/support/services.ts +0 -3
- package/examples/live-rpc/src/Rpc.ts +0 -4
- package/examples/live-rpc/src/browser.ts +0 -24
- package/examples/live-rpc/src/chat/Chat.ts +0 -22
- package/examples/live-rpc/src/chat/authorize.ts +0 -3
- package/examples/live-rpc/src/chat/events.ts +0 -14
- package/examples/live-rpc/src/chat/handlers.ts +0 -5
- package/examples/live-rpc/src/chat/room.ts +0 -6
- package/examples/live-rpc/src/chat/store.ts +0 -9
- package/examples/live-rpc/src/client.ts +0 -6
- package/examples/live-rpc/src/identity/Identity.ts +0 -6
- package/examples/live-rpc/src/identity/members.ts +1 -3
- package/examples/live-rpc/src/identity/verifier.ts +6 -12
- package/examples/live-rpc/src/page.ts +0 -10
- package/examples/live-rpc/src/routes.ts +0 -13
- package/examples/live-rpc/src/server.ts +0 -16
- package/examples/live-rpc/test/browser.test.ts +0 -9
- package/examples/live-rpc/test/chat/chat.test.ts +3 -11
- package/examples/live-rpc/test/routes.test.ts +0 -8
- package/examples/live-rpc/test/server.test.ts +0 -13
- package/examples/mcp-tools/src/instructions.ts +0 -4
- package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
- package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
- package/examples/mcp-tools/src/printers/Printers.ts +0 -21
- package/examples/mcp-tools/src/printers/farm.ts +0 -5
- package/examples/mcp-tools/src/printers/handlers.ts +0 -6
- package/examples/mcp-tools/src/routes.ts +0 -11
- package/examples/mcp-tools/src/server.ts +0 -9
- package/examples/mcp-tools/src/stdio.ts +1 -13
- package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
- package/examples/mcp-tools/test/routes.test.ts +0 -14
- package/examples/notes-service/src/Api.ts +0 -4
- package/examples/notes-service/src/browser.ts +0 -12
- package/examples/notes-service/src/cli.ts +0 -2
- package/examples/notes-service/src/commands.ts +0 -30
- package/examples/notes-service/src/identity/Identity.ts +0 -2
- package/examples/notes-service/src/identity/authorize.ts +0 -4
- package/examples/notes-service/src/identity/users.ts +1 -3
- package/examples/notes-service/src/identity/verifier.ts +4 -11
- package/examples/notes-service/src/notes/Notes.ts +0 -12
- package/examples/notes-service/src/notes/handlers.ts +0 -4
- package/examples/notes-service/src/notes/store.ts +62 -48
- package/examples/notes-service/src/routes.ts +0 -12
- package/examples/notes-service/src/server.ts +0 -6
- package/examples/notes-service/src/status/Status.ts +0 -1
- package/examples/notes-service/src/status/handlers.ts +0 -1
- package/examples/notes-service/src/stdio.ts +2 -12
- package/examples/notes-service/src/worker.ts +0 -7
- package/examples/notes-service/test/commands.test.ts +0 -20
- package/examples/notes-service/test/notes/as.ts +3 -4
- package/examples/notes-service/test/notes/in-process.test.ts +3 -6
- package/examples/notes-service/test/notes/notes.test.ts +0 -6
- package/examples/notes-service/test/routes.test.ts +0 -5
- package/examples/notes-service/test/worker.test.ts +0 -1
- package/examples/quickstart/src/Api.ts +0 -1
- package/examples/quickstart/src/client.ts +0 -3
- package/examples/quickstart/src/greeting/Greeting.ts +0 -2
- package/examples/quickstart/src/greeting/handlers.ts +0 -1
- package/examples/quickstart/src/routes.ts +0 -1
- package/examples/quickstart/src/server.ts +3 -6
- package/examples/quickstart/test/routes.test.ts +0 -1
- package/package.json +2 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Effect, ErrorReporter } from "effect";
|
|
2
2
|
// src/contract/reported.ts
|
|
3
|
-
/** Logs `cause` and gives it to the request's `ErrorReporter`s, as a failed call's is. */
|
|
4
3
|
const reported = (cause) => Effect.andThen(Effect.logError(cause), ErrorReporter.report(cause));
|
|
5
4
|
var InternalError = class extends Error {
|
|
6
5
|
[ErrorReporter.ignore] = true;
|
|
@@ -8,9 +7,5 @@ var InternalError = class extends Error {
|
|
|
8
7
|
super("Internal server error");
|
|
9
8
|
}
|
|
10
9
|
};
|
|
11
|
-
/**
|
|
12
|
-
* `cause` `reported`, then a defect that says no more than "Internal server error", reported no
|
|
13
|
-
* further: what a surface sends where it would otherwise encode a defect's details.
|
|
14
|
-
*/
|
|
15
10
|
const concealed = (cause) => Effect.andThen(reported(cause), Effect.die(new InternalError()));
|
|
16
11
|
export { concealed, reported };
|
|
@@ -4,10 +4,6 @@ import { Implementation, assertHeld, markingOthers, notHeld, provideBuilders, se
|
|
|
4
4
|
import { eventsOf, feedBuilders, selectEvents } from "./feed.mjs";
|
|
5
5
|
import { selection } from "./listed.mjs";
|
|
6
6
|
// src/contract/serving.ts
|
|
7
|
-
/**
|
|
8
|
-
* What a surface without a binding serves of `served`: the actions and event types `actions`
|
|
9
|
-
* lists, each implementation holding those alone, or every one where it lists none.
|
|
10
|
-
*/
|
|
11
7
|
const selectFrom = (served, actions) => {
|
|
12
8
|
const listed = selection(actions);
|
|
13
9
|
return {
|
|
@@ -15,11 +11,6 @@ const selectFrom = (served, actions) => {
|
|
|
15
11
|
events: selectEvents(eventsOf(served), listed.events)
|
|
16
12
|
};
|
|
17
13
|
};
|
|
18
|
-
/**
|
|
19
|
-
* The event implementations among `served` a binding of `bound` serves, each holding the served
|
|
20
|
-
* event types alone: those `listed` lists, or else every bound one, refusing implementations none
|
|
21
|
-
* of whose event types it binds, as `servedBy` refuses such action implementations.
|
|
22
|
-
*/
|
|
23
14
|
const eventsServedBy = (what, bound, served, listed) => {
|
|
24
15
|
const apps = eventsOf(served);
|
|
25
16
|
if (listed !== void 0) assertHeld(notHeld.byBinding, listed, bound);
|
|
@@ -33,11 +24,6 @@ const eventsServedBy = (what, bound, served, listed) => {
|
|
|
33
24
|
assertOnce("served event", selected.flatMap((app) => app.events), heldOnce);
|
|
34
25
|
return selected;
|
|
35
26
|
};
|
|
36
|
-
/**
|
|
37
|
-
* What `ActionHttp.layer` and `ActionRpc.layer` serve, with the checks they share: the actions
|
|
38
|
-
* and event types `options.actions` lists, or every one of the binding's the implementations
|
|
39
|
-
* hold; `authentication` is the binding's where a served contract is protected.
|
|
40
|
-
*/
|
|
41
27
|
const servingOf = (what, binding, served, options) => {
|
|
42
28
|
const listed = selection(options.actions);
|
|
43
29
|
const apps = servedBy(what, binding.actions, toList(served), listed.actions);
|
|
@@ -55,9 +41,5 @@ const servingOf = (what, binding, served, options) => {
|
|
|
55
41
|
authentication: [...actions, ...eventTypes].some((contract) => contract.caller !== Anyone) ? binding.authentication : void 0
|
|
56
42
|
};
|
|
57
43
|
};
|
|
58
|
-
/**
|
|
59
|
-
* Provide the builders of what `servingOf` selects, the action implementations' and the event
|
|
60
|
-
* implementations', to a surface's layer.
|
|
61
|
-
*/
|
|
62
44
|
const provideServed = (served) => provideBuilders([...served.apps.map((app) => Implementation.layerOf(app)), ...feedBuilders(served.events)]);
|
|
63
45
|
export { provideServed, selectFrom, servingOf };
|
package/dist/contract/status.mjs
CHANGED
|
@@ -9,11 +9,8 @@ const transientStatuses = /* @__PURE__ */ new Set([
|
|
|
9
9
|
503,
|
|
10
10
|
504
|
|
11
11
|
]);
|
|
12
|
-
/** Whether a server answering `status` may answer otherwise once it recovers. */
|
|
13
12
|
const isTransientStatus = (status) => transientStatuses.has(status);
|
|
14
13
|
const statusThroughSuspensions = (ast) => httpApiStatusOf(ast) ?? (SchemaAST.isSuspend(ast) ? statusThroughSuspensions(ast.thunk()) : void 0);
|
|
15
|
-
/** The status an endpoint answers `error` with: its own, through suspensions, 422 without one. */
|
|
16
14
|
const declaredStatus = (error) => statusThroughSuspensions(error.ast) ?? 422;
|
|
17
|
-
/** One error schema, from `errorSchemas`, as an endpoint declares it: with its status, 422 without one. */
|
|
18
15
|
const declared = (error) => httpApiStatusOf(error.ast) === void 0 ? error.annotate({ httpApiStatus: declaredStatus(error) }) : error;
|
|
19
16
|
export { declared, declaredStatus, httpApiStatusOf, isTransientStatus };
|
package/dist/contract/stream.mjs
CHANGED
|
@@ -21,9 +21,7 @@ const Stream$1 = (element) => Schema.make(streams.ast, {
|
|
|
21
21
|
element: codecOf(element)
|
|
22
22
|
});
|
|
23
23
|
const isStreamOf = (success) => Predicate.hasProperty(success, TypeId);
|
|
24
|
-
/** The element schema of an action answering a stream, `undefined` for any other action. */
|
|
25
24
|
const elementOf = (success) => isStreamOf(success) ? success.element : void 0;
|
|
26
|
-
/** The success a tool answers for an action with `success`, as `ToolSuccess` types it. */
|
|
27
25
|
const toolSuccessOf = (success) => {
|
|
28
26
|
const element = elementOf(success);
|
|
29
27
|
return element === void 0 ? success : Schema.Array(element);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Codec } from "./codec.mjs";
|
|
2
2
|
import { Any } from "../Event.mjs";
|
|
3
3
|
import { Schema } from "effect";
|
|
4
|
-
/** What a webhook subscribe to `event` takes: a subscription's input and cursor, and its fields. */
|
|
5
4
|
export declare const WebhookSubscriptionOf: <E extends Any>(event: E) => Schema.Struct<{
|
|
6
5
|
readonly input: Codec;
|
|
7
6
|
readonly cursor: Schema.withDecodingDefaultKey<Schema.NullOr<Schema.String>, never>;
|
|
@@ -16,7 +15,6 @@ export declare const WebhookSubscriptionOf: <E extends Any>(event: E) => Schema.
|
|
|
16
15
|
}>;
|
|
17
16
|
/** A webhook subscribe's request, its input decoded, as a surface reads it whatever its event. */
|
|
18
17
|
export type AnyWebhookSubscription = ReturnType<typeof WebhookSubscriptionOf<Any>>["Type"];
|
|
19
|
-
/** What a webhook unsubscribe from `event` takes: the input and callback it subscribed with. */
|
|
20
18
|
export declare const WebhookCancellationOf: <E extends Any>(event: E) => Schema.Struct<{
|
|
21
19
|
readonly input: Codec;
|
|
22
20
|
readonly delivery: Schema.Struct<{
|
|
@@ -3,24 +3,16 @@ import { CallbackUrl, WebhookSecret } from "./callback.mjs";
|
|
|
3
3
|
import { SubscriptionOf } from "./push.mjs";
|
|
4
4
|
import { Schema, Struct } from "effect";
|
|
5
5
|
// src/contract/subscribe.ts
|
|
6
|
-
/** Where a webhook subscription delivers: its callback, and the secret signing each POST. */
|
|
7
6
|
const WebhookCallback = Schema.Struct({
|
|
8
7
|
url: CallbackUrl,
|
|
9
8
|
secret: WebhookSecret
|
|
10
9
|
});
|
|
11
|
-
/** The callback a webhook unsubscribe names: its URL alone. */
|
|
12
10
|
const WebhookTarget = WebhookCallback.mapFields(Struct.pick(["url"]));
|
|
13
|
-
/**
|
|
14
|
-
* What a webhook subscribe asks beside the subscription it names: its callback, and the lifetime
|
|
15
|
-
* it suggests in milliseconds, `null` asking for none.
|
|
16
|
-
*/
|
|
17
11
|
const webhookFields = {
|
|
18
12
|
delivery: WebhookCallback,
|
|
19
13
|
ttlMs: Schema.optional(Schema.NullOr(Schema.Finite)).annotate({ description: "The lifetime it suggests, in milliseconds; the answer's refreshBefore is the grant." })
|
|
20
14
|
};
|
|
21
|
-
/** What a webhook subscribe to `event` takes: a subscription's input and cursor, and its fields. */
|
|
22
15
|
const WebhookSubscriptionOf = (event) => SubscriptionOf(event).pipe(Schema.fieldsAssign(webhookFields));
|
|
23
|
-
/** What a webhook unsubscribe from `event` takes: the input and callback it subscribed with. */
|
|
24
16
|
const WebhookCancellationOf = (event) => Schema.Struct({
|
|
25
17
|
input: event.input,
|
|
26
18
|
delivery: WebhookTarget
|
|
@@ -3,26 +3,14 @@ import { readOn } from "./push.mjs";
|
|
|
3
3
|
import { Cause, Duration, Effect, Function, Match, Predicate, Stream } from "effect";
|
|
4
4
|
import { HttpClientError } from "effect/http";
|
|
5
5
|
// src/contract/transient.ts
|
|
6
|
-
/** The status a server answered with, where `error` is a failure to read its answer. */
|
|
7
6
|
const answeredStatus = ({ reason }) => Match.value(reason).pipe(Match.tag("StatusCodeError", "DecodeError", ({ response }) => response.status), Match.orElse(Function.constUndefined));
|
|
8
|
-
/** Whether an HTTP client's failure, by its `reason`, is one a reconnect may outlast. */
|
|
9
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));
|
|
10
|
-
/** Whether a remote watch's failure is one a reconnect may outlast. */
|
|
11
8
|
const isTransient = Predicate.or(Cause.isTimeoutError, Predicate.compose(HttpClientError.isHttpClientError, ({ reason }) => isTransientReason(reason)));
|
|
12
9
|
const silentFor = Duration.seconds(60);
|
|
13
|
-
/**
|
|
14
|
-
* `request`, failing with a `TimeoutError`, which `isTransient` admits, when it is unanswered for
|
|
15
|
-
* as long as a stream may be silent, such as a server that holds its status back.
|
|
16
|
-
*/
|
|
17
10
|
const failingWhenUnanswered = (request) => Effect.timeout(request, silentFor);
|
|
18
|
-
/** `stream`, failing with a `TimeoutError`, which `isTransient` admits, once it goes silent. */
|
|
19
11
|
const failingWhenSilent = (stream) => stream.pipe(Stream.timeoutOrElse({
|
|
20
12
|
duration: silentFor,
|
|
21
13
|
orElse: () => Stream.fail(new Cause.TimeoutError("The event stream went silent"))
|
|
22
14
|
}));
|
|
23
|
-
/**
|
|
24
|
-
* What a client reads from a push stream of `surface`'s event `name`: each element but `Failed`,
|
|
25
|
-
* which is logged, the server having read on; failing with a `TimeoutError` once it goes silent.
|
|
26
|
-
*/
|
|
27
15
|
const receivedFrom = (surface, name) => (sent) => sent.pipe(failingWhenSilent, readOn(surface, name));
|
|
28
16
|
export { answeredStatus, failingWhenSilent, failingWhenUnanswered, isTransient, isTransientReason, receivedFrom };
|
package/dist/contract/watch.mjs
CHANGED
|
@@ -10,17 +10,10 @@ const reconnectDelay = Duration.seconds(1);
|
|
|
10
10
|
const maxReconnectDelay = Duration.seconds(30);
|
|
11
11
|
const afterFailures = (transient) => Schedule.min([Schedule.exponential(reconnectDelay), Schedule.spaced(maxReconnectDelay)]).pipe(Schedule.setInputType(), Schedule.while(({ input }) => transient(input)), Schedule.tap(({ input, duration }) => Effect.logWarning(`A watch reconnects in ${Duration.format(duration)} after a failure`, input)));
|
|
12
12
|
const isSubscriptionError = Schema.is(SubscriptionError);
|
|
13
|
-
/** Whether a watch's failure says the server serves its event by poll alone, refusing to push it. */
|
|
14
13
|
const pushRefused = Predicate.compose(isSubscriptionError, ({ reason }) => Predicate.isTagged(reason, "Unsupported") && reason.feature === "deliveryMode" && reason.value === "push");
|
|
15
14
|
const dedupeWindow = 1e3;
|
|
16
15
|
const capacity = 16;
|
|
17
16
|
const unsubscribeTimeout = Duration.seconds(5);
|
|
18
|
-
/**
|
|
19
|
-
* One webhook subscription from `cursor`, read from `received`, where its receiver puts each
|
|
20
|
-
* body: each grant, the subscribe's and each refresh's when half of it is left, is put there too,
|
|
21
|
-
* behind what was accepted before it, so its position is kept in order; a refresh's failure is
|
|
22
|
-
* put there as well, and ends the run where it is read.
|
|
23
|
-
*/
|
|
24
17
|
const delivered = (webhook, request, received, cursor) => {
|
|
25
18
|
let at = cursor;
|
|
26
19
|
const subscribed = Effect.suspend(() => webhook.subscribe({
|
|
@@ -36,11 +29,6 @@ const delivered = (webhook, request, received, cursor) => {
|
|
|
36
29
|
})));
|
|
37
30
|
}));
|
|
38
31
|
};
|
|
39
|
-
/**
|
|
40
|
-
* The occurrences and gaps of one subscription, as every client's `watch` answers them. Each run
|
|
41
|
-
* starts from `options`: what one run saw, the cursor and the ids it deduplicates by, ends with
|
|
42
|
-
* it, and only `resume` carries a cursor to the next.
|
|
43
|
-
*/
|
|
44
32
|
const watching = (transport, { cursor: given, mode, resume } = {}) => {
|
|
45
33
|
const reconnecting = (open, cursor, polled) => {
|
|
46
34
|
const { transient } = transport;
|
|
@@ -76,7 +64,7 @@ const watching = (transport, { cursor: given, mode, resume } = {}) => {
|
|
|
76
64
|
}));
|
|
77
65
|
return Stream.suspend(() => {
|
|
78
66
|
const seen = makeRecent(dedupeWindow);
|
|
79
|
-
let
|
|
67
|
+
let keptOnNextPull = null;
|
|
80
68
|
const keep = (cursor) => cursor === null || resume === void 0 ? Effect.void : resume.store.set(resume.key, cursor);
|
|
81
69
|
const fresh = (eventId) => {
|
|
82
70
|
if (seen.has(eventId)) return false;
|
|
@@ -84,14 +72,14 @@ const watching = (transport, { cursor: given, mode, resume } = {}) => {
|
|
|
84
72
|
return true;
|
|
85
73
|
};
|
|
86
74
|
const handled = Effect.fnUntraced(function* (fed) {
|
|
87
|
-
yield* keep(
|
|
88
|
-
|
|
75
|
+
yield* keep(keptOnNextPull);
|
|
76
|
+
keptOnNextPull = null;
|
|
89
77
|
if (Predicate.isTagged(fed, "Checked")) {
|
|
90
78
|
yield* keep(fed.cursor);
|
|
91
79
|
return [];
|
|
92
80
|
}
|
|
93
81
|
if (Predicate.isTagged(fed, "Gap")) return [fed];
|
|
94
|
-
|
|
82
|
+
keptOnNextPull = fed.cursor;
|
|
95
83
|
return fresh(fed.eventId) ? [fed] : [];
|
|
96
84
|
});
|
|
97
85
|
const start = given !== void 0 || resume === void 0 ? Effect.succeed(given ?? null) : Effect.map(resume.store.get(resume.key), (kept) => kept ?? null);
|
|
@@ -99,7 +87,7 @@ const watching = (transport, { cursor: given, mode, resume } = {}) => {
|
|
|
99
87
|
if (Predicate.isTagged(mode, "WebhookDelivery")) return webhooked(mode, cursor);
|
|
100
88
|
if (mode === "poll") return polled(cursor);
|
|
101
89
|
return reconnecting(transport.stream, cursor, mode === "stream" ? void 0 : polled);
|
|
102
|
-
})).pipe(Stream.rechunk(1), Stream.mapEffect(handled), Stream.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Stream.failCause(cause) : Stream.concat(Stream.fromEffectDrain(keep(
|
|
90
|
+
})).pipe(Stream.rechunk(1), Stream.mapEffect(handled), Stream.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Stream.failCause(cause) : Stream.concat(Stream.fromEffectDrain(keep(keptOnNextPull)), Stream.failCause(cause))), Stream.flattenIterable);
|
|
103
91
|
});
|
|
104
92
|
};
|
|
105
93
|
export { watching };
|
|
@@ -12,13 +12,7 @@ import { Context, Effect, Option } from "effect";
|
|
|
12
12
|
*/
|
|
13
13
|
var Webhooks = class extends Context.Service()("effect-actions/Webhooks") {};
|
|
14
14
|
const isProtected = (event) => event.caller !== Anyone;
|
|
15
|
-
/** Whether a surface offers `event` by webhook: a protected event, its subscribers `keyed`. */
|
|
16
15
|
const offersWebhook = (event, keyed) => isProtected(event) && isNamed(keyed);
|
|
17
|
-
/**
|
|
18
|
-
* Serves the feeds among `feeds` a surface offers by webhook, its subscribers `keyed`, to the
|
|
19
|
-
* `Webhooks` it is given, as it builds: restoring their kept subscriptions, and dying where they
|
|
20
|
-
* cannot be kept. Answers the service, where given, and those feeds.
|
|
21
|
-
*/
|
|
22
16
|
const servedWebhooks = (feeds, keyed) => Effect.gen(function* () {
|
|
23
17
|
const webhooks = yield* Effect.serviceOption(Webhooks);
|
|
24
18
|
const offered = feeds.filter((feed) => offersWebhook(feed.event, keyed));
|
|
@@ -28,11 +22,6 @@ const servedWebhooks = (feeds, keyed) => Effect.gen(function* () {
|
|
|
28
22
|
offered
|
|
29
23
|
};
|
|
30
24
|
});
|
|
31
|
-
/**
|
|
32
|
-
* The webhook subscriber calling a subscribe or unsubscribe of `feed`'s event on a surface given
|
|
33
|
-
* `webhooks`, its subscribers `keyed`; `Unsupported` where the surface does not offer it by
|
|
34
|
-
* webhook.
|
|
35
|
-
*/
|
|
36
25
|
const webhookSubscriber = (feed, keyed, webhooks) => {
|
|
37
26
|
const { event } = feed;
|
|
38
27
|
if (Option.isNone(webhooks) || !isNamed(keyed) || !isProtected(event)) return Effect.fail(SubscriptionError.of(event.name, new Unsupported({
|
package/dist/http/client.mjs
CHANGED
|
@@ -23,7 +23,6 @@ const actionMethodOf = (action, native) => {
|
|
|
23
23
|
if (action.progress === void 0) return checked(action, sendingValue, (payload) => method({ payload }));
|
|
24
24
|
return checked(action, sendingValue, (payload, onProgress) => Effect.flatMap(method({ payload }), (answer) => readWithProgress(answer, onProgress)));
|
|
25
25
|
};
|
|
26
|
-
/** The `Senders` of `http` over `httpClient`: its native clients, built once. */
|
|
27
26
|
const sendersWith = (http, httpClient, baseUrl) => Effect.gen(function* () {
|
|
28
27
|
const native = yield* nativeOf(http, acceptingStreams(httpClient), baseUrl);
|
|
29
28
|
const plain = yield* nativeOf(http, httpClient, baseUrl);
|
package/dist/http/events.d.mts
CHANGED
|
@@ -11,10 +11,6 @@ import "../contract/push.mjs";
|
|
|
11
11
|
import "../contract/webhooks.mjs";
|
|
12
12
|
import { Effect, Option, Schema, Stream } from "effect";
|
|
13
13
|
import { HttpApiEndpoint, HttpApiSchema } from "effect/http-api";
|
|
14
|
-
/**
|
|
15
|
-
* One poll's answer: the occurrences since the cursor, and when to ask again, sent as
|
|
16
|
-
* `nextPollMs`, its milliseconds.
|
|
17
|
-
*/
|
|
18
14
|
export declare const pageOf: <E extends Any>(event: E) => Schema.encodeKeys<Schema.Struct<{
|
|
19
15
|
readonly events: Schema.$Array<OccurrenceSchema<E>>;
|
|
20
16
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
@@ -24,12 +20,6 @@ export declare const pageOf: <E extends Any>(event: E) => Schema.encodeKeys<Sche
|
|
|
24
20
|
}>, {
|
|
25
21
|
readonly nextPoll: "nextPollMs";
|
|
26
22
|
}>;
|
|
27
|
-
/**
|
|
28
|
-
* What a subscription's event stream sends, each as one SSE `message`: a `Checked` with the
|
|
29
|
-
* position it starts from, or a `Gap` where that was no longer served, then each occurrence, a
|
|
30
|
-
* `Gap` where some were missed, a `Checked` every 30 seconds, and a `Failed` where reading
|
|
31
|
-
* failed and resumes. A later refusal ends it, as Effect's stream failure event.
|
|
32
|
-
*/
|
|
33
23
|
export declare const sentOf: <E extends Any>(event: E) => HttpApiSchema.StreamSse<HttpApiSchema.SseEventFromData<Schema.toCodecJson<Schema.Union<readonly [OccurrenceSchema<E>, Schema.TaggedStruct<"Gap", {
|
|
34
24
|
readonly cursor: Schema.NullOr<Schema.String>;
|
|
35
25
|
}>, Schema.TaggedStruct<"Checked", {
|
package/dist/http/events.mjs
CHANGED
|
@@ -7,14 +7,10 @@ import { SubscriptionError } from "../Event.mjs";
|
|
|
7
7
|
import { webhookSubscriber } from "../contract/webhooks.mjs";
|
|
8
8
|
import { PushedOf, SubscriptionOf, queuedPush } from "../contract/push.mjs";
|
|
9
9
|
import { Subscribed, WebhookCancellationOf, WebhookSubscriptionOf } from "../contract/subscribe.mjs";
|
|
10
|
-
import { Effect, Schema, Stream } from "effect";
|
|
10
|
+
import { Effect, Function, Schema, Stream } from "effect";
|
|
11
11
|
import { HttpServerRequest } from "effect/http";
|
|
12
12
|
import { HttpApiEndpoint, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
13
13
|
// src/http/events.ts
|
|
14
|
-
/**
|
|
15
|
-
* One poll's answer: the occurrences since the cursor, and when to ask again, sent as
|
|
16
|
-
* `nextPollMs`, its milliseconds.
|
|
17
|
-
*/
|
|
18
14
|
const pageOf = (event) => Schema.Struct({
|
|
19
15
|
events: Schema.Array(OccurrenceOf(event)),
|
|
20
16
|
cursor: Schema.NullOr(Schema.String),
|
|
@@ -22,34 +18,19 @@ const pageOf = (event) => Schema.Struct({
|
|
|
22
18
|
hasMore: Schema.Boolean,
|
|
23
19
|
nextPoll: Schema.DurationFromMillis
|
|
24
20
|
}).pipe(Schema.encodeKeys({ nextPoll: "nextPollMs" }));
|
|
25
|
-
/**
|
|
26
|
-
* What a subscription's event stream sends, each as one SSE `message`: a `Checked` with the
|
|
27
|
-
* position it starts from, or a `Gap` where that was no longer served, then each occurrence, a
|
|
28
|
-
* `Gap` where some were missed, a `Checked` every 30 seconds, and a `Failed` where reading
|
|
29
|
-
* failed and resumes. A later refusal ends it, as Effect's stream failure event.
|
|
30
|
-
*/
|
|
31
21
|
const sentOf = (event) => HttpApiSchema.StreamSse({
|
|
32
22
|
data: Schema.toCodecJson(PushedOf(event)),
|
|
33
23
|
error: Refusal
|
|
34
24
|
});
|
|
35
|
-
/** What a served subscription's event stream sends: each element's JSON, as `sentOf` encodes it. */
|
|
36
25
|
const servedSent = HttpApiSchema.StreamSse({
|
|
37
26
|
data: Schema.Json,
|
|
38
27
|
error: Refusal
|
|
39
28
|
});
|
|
40
|
-
/**
|
|
41
|
-
* The route of one event type at `path`, its poll answered as JSON and its stream as SSE, as
|
|
42
|
-
* `sent` declares it.
|
|
43
|
-
*/
|
|
44
29
|
const eventEndpointOf = (event, path, errors, sent = sentOf(event)) => HttpApiEndpoint.post(event.name, path, {
|
|
45
30
|
payload: SubscriptionOf(event).pipe(HttpApiSchema.asJson()),
|
|
46
31
|
success: [pageOf(event), sent],
|
|
47
32
|
error: errors.map(declared)
|
|
48
33
|
}).annotate(OpenApi.Description, event.description);
|
|
49
|
-
/**
|
|
50
|
-
* The webhook routes of one protected event type at `path`: `/subscribe`, which starts or
|
|
51
|
-
* refreshes a subscription and answers its grant, and `/unsubscribe`, which ends it.
|
|
52
|
-
*/
|
|
53
34
|
const webhookEndpointsOf = (event, path, errors) => {
|
|
54
35
|
const withWebhooks = [...errors, SubscriptionError];
|
|
55
36
|
assertDistinctTags(`ActionHttp binding of event "${event.name}"'s webhook routes`, withWebhooks);
|
|
@@ -64,10 +45,6 @@ const webhookEndpointsOf = (event, path, errors) => {
|
|
|
64
45
|
error
|
|
65
46
|
}).annotate(OpenApi.Description, `Stop delivering ${event.name} to a webhook.`)];
|
|
66
47
|
};
|
|
67
|
-
/**
|
|
68
|
-
* The handlers of `feed`'s webhook routes, through `webhooks` where the host provided
|
|
69
|
-
* `Webhook.layer`; without it, both fail with `Unsupported`.
|
|
70
|
-
*/
|
|
71
48
|
const webhookAnswers = (feed, authentication, webhooks) => {
|
|
72
49
|
const served = webhookSubscriber(feed, authentication, webhooks);
|
|
73
50
|
return {
|
|
@@ -82,18 +59,12 @@ const webhookAnswers = (feed, authentication, webhooks) => {
|
|
|
82
59
|
}))
|
|
83
60
|
};
|
|
84
61
|
};
|
|
85
|
-
/**
|
|
86
|
-
* Answers a subscription's request to `feed`: a page, or, where it accepts `text/event-stream`,
|
|
87
|
-
* the subscription's stream, each element its JSON. Both admit the subscriber first, so a refusal
|
|
88
|
-
* is the route's error; `authentication`'s principal names a poll's subscriber, for its
|
|
89
|
-
* `subscription` hook.
|
|
90
|
-
*/
|
|
91
62
|
const answering = (feed, authentication) => {
|
|
92
63
|
const encode = Schema.encodeEffect(Schema.toCodecJson(PushedOf(feed.event)));
|
|
93
64
|
return ({ payload: { input, cursor } }) => Effect.gen(function* () {
|
|
94
65
|
if (((yield* HttpServerRequest.HttpServerRequest).headers["accept"] ?? "").includes("text/event-stream")) {
|
|
95
66
|
const open = yield* feed.stream(input);
|
|
96
|
-
return Stream.fromQueue(yield* queuedPush(open, cursor, encode));
|
|
67
|
+
return Stream.fromQueue(yield* queuedPush(open, cursor, encode, { ending: Function.identity }));
|
|
97
68
|
}
|
|
98
69
|
const subscriber = yield* principalOf(feed.event, authentication);
|
|
99
70
|
return yield* feed.poll(input, cursor, { subscriber });
|
package/dist/http/placed.d.mts
CHANGED
|
@@ -5,8 +5,6 @@ import { Any as Any$1 } from "../Action.mjs";
|
|
|
5
5
|
import { AnyHttp } from "./client.mjs";
|
|
6
6
|
import { HttpClient } from "effect/http";
|
|
7
7
|
type Contract<H extends AnyHttp> = H["actions"][number] | H["events"][number];
|
|
8
|
-
/** A call's or a subscription's decoded input, beside its contract, one of `C`. */
|
|
9
|
-
/** What the contracts `C` require per request, by name: nothing. */
|
|
10
8
|
type Nothing<C extends Any$1 | Any> = { readonly [K in C["name"]]: never; };
|
|
11
9
|
/**
|
|
12
10
|
* What `placed` returns: an implementation of the binding's actions where it has some, and one of
|
package/dist/http/streamed.d.mts
CHANGED
|
@@ -5,7 +5,6 @@ import { StreamOf } from "../contract/stream.mjs";
|
|
|
5
5
|
import { Any } from "../Action.mjs";
|
|
6
6
|
import { Effect, Schema, Stream } from "effect";
|
|
7
7
|
import { HttpApiSchema } from "effect/http-api";
|
|
8
|
-
/** One event a route streams: a progress value, an element, or the answer it ends with. */
|
|
9
8
|
interface Sent {
|
|
10
9
|
readonly event: "progress" | "element" | "final";
|
|
11
10
|
readonly data: ErasedValue;
|
package/dist/http/streamed.mjs
CHANGED
|
@@ -10,28 +10,16 @@ const eventOf = (event, data) => Schema.Struct({
|
|
|
10
10
|
event: Schema.Literal(event),
|
|
11
11
|
data: Schema.fromJsonString(Schema.toCodecJson(data))
|
|
12
12
|
});
|
|
13
|
-
/** What a route of an action declaring `progress` answers without its stream: `success`. */
|
|
14
13
|
const answeredWithProgress = (success) => HttpApiSchema.isNoContent(success.ast) ? HttpApiSchema.NoContent : success;
|
|
15
|
-
/**
|
|
16
|
-
* What a route of an action declaring `progress` answers a request accepting
|
|
17
|
-
* `text/event-stream`: a `progress` event for each value its handler reports, then a `final`
|
|
18
|
-
* event with its answer. A declared failure after the first event ends the stream as Effect's
|
|
19
|
-
* stream failure event, and a defect as one saying `Internal server error`.
|
|
20
|
-
*/
|
|
21
14
|
const progressStreamOf = (progress, success, errors) => HttpApiSchema.StreamSse({
|
|
22
15
|
events: Schema.Union([eventOf("progress", progress), eventOf("final", success)]),
|
|
23
16
|
error: Schema.Union(errors)
|
|
24
17
|
});
|
|
25
|
-
/**
|
|
26
|
-
* What a route of an action answering a stream answers: an `element` event for each element,
|
|
27
|
-
* beside a `progress` event for each value its handler reports where it declares `progress`. A
|
|
28
|
-
* declared failure after the first event ends the stream as Effect's stream failure event, and
|
|
29
|
-
* a defect as one saying `Internal server error`.
|
|
30
|
-
*/
|
|
31
18
|
const elementStreamOf = (element, progress, errors) => HttpApiSchema.StreamSse({
|
|
32
19
|
events: Schema.Union(progress === void 0 ? [eventOf("element", element)] : [eventOf("element", element), eventOf("progress", progress)]),
|
|
33
20
|
error: Schema.Union(errors)
|
|
34
21
|
});
|
|
22
|
+
const gatedOnFirst = (sent) => Effect.map(Effect.catchIf(Queue.take(sent), Cause.isDone, () => Effect.undefined), (first) => first === void 0 ? Stream.empty : Stream.concat(Stream.make(first), Stream.fromQueue(sent)));
|
|
35
23
|
const streamed = (answer) => Effect.gen(function* () {
|
|
36
24
|
const sent = yield* Queue.bounded(1);
|
|
37
25
|
let streaming = false;
|
|
@@ -42,23 +30,17 @@ const streamed = (answer) => Effect.gen(function* () {
|
|
|
42
30
|
event: "progress",
|
|
43
31
|
data
|
|
44
32
|
}) };
|
|
45
|
-
const
|
|
33
|
+
const endedReportingMidStream = (cause) => {
|
|
46
34
|
if (Cause.hasDies(cause)) return concealed(cause);
|
|
47
35
|
return streaming ? Effect.andThen(ErrorReporter.report(cause), Effect.failCause(cause)) : Effect.failCause(cause);
|
|
48
36
|
};
|
|
49
|
-
yield* answer(reporting, send).pipe(Effect.catchCause(
|
|
50
|
-
|
|
51
|
-
return first === void 0 ? Stream.empty : Stream.concat(Stream.make(first), Stream.fromQueue(sent));
|
|
37
|
+
yield* answer(reporting, send).pipe(Effect.catchCause(endedReportingMidStream), Queue.into(sent), Effect.forkScoped({ startImmediately: true }));
|
|
38
|
+
return yield* gatedOnFirst(sent);
|
|
52
39
|
});
|
|
53
|
-
/** A check of `schema` failing as a defect, inside the call's boundary. */
|
|
54
40
|
const checkedBy = (schema) => {
|
|
55
41
|
const encode = Schema.encodeUnknownEffect(Schema.toCodecJson(schema));
|
|
56
42
|
return (data) => Effect.orDie(encode(data));
|
|
57
43
|
};
|
|
58
|
-
/**
|
|
59
|
-
* The route handler of an action declaring `progress`: its answer streamed with its progress
|
|
60
|
-
* where the request's `Accept` names `text/event-stream`, its answer alone otherwise.
|
|
61
|
-
*/
|
|
62
44
|
const answeringWithProgress = (success, run) => {
|
|
63
45
|
const check = checkedBy(success);
|
|
64
46
|
return (payload) => Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) => (request.headers["accept"] ?? "").includes("text/event-stream") ? streamed((reporting, send) => run(payload, reporting).pipe(Effect.tap(check), Effect.flatMap((data) => send({
|
|
@@ -66,7 +48,6 @@ const answeringWithProgress = (success, run) => {
|
|
|
66
48
|
data
|
|
67
49
|
})))) : run(payload));
|
|
68
50
|
};
|
|
69
|
-
/** The route handler of an action answering a stream: its elements and its progress, streamed. */
|
|
70
51
|
const answeringElements = (element, run) => {
|
|
71
52
|
const check = checkedBy(element);
|
|
72
53
|
return (payload) => streamed((reporting, send) => Stream.runForEach(elementsOf(run(payload, reporting)), (data) => Effect.andThen(check(data), send({
|
|
@@ -79,16 +60,7 @@ const progressedOf = ({ event, data }) => {
|
|
|
79
60
|
return event === "final" ? Progressed.Final({ value: data }) : Progressed.Element({ value: data });
|
|
80
61
|
};
|
|
81
62
|
const answeredWithout = /* @__PURE__ */ new Error("A route of an action declaring progress or answering a stream answered without its event stream");
|
|
82
|
-
/** The events of a route's answer, as one stream of `Progressed`. */
|
|
83
63
|
const sentFrom = (answer) => Stream.isStream(answer) ? Stream.map(answer, progressedOf) : Stream.die(answeredWithout);
|
|
84
|
-
/**
|
|
85
|
-
* A client's answer from a route of an action declaring `progress`: each `progress` event handed
|
|
86
|
-
* to `onProgress`, where the call gave one, then the `final` event's answer.
|
|
87
|
-
*/
|
|
88
64
|
const readWithProgress = (answer, onProgress) => answerFrom(sentFrom(answer), onProgress);
|
|
89
|
-
/**
|
|
90
|
-
* A client's elements from a route of an action answering a stream: each `element` event's
|
|
91
|
-
* data, each `progress` event's handed to `onProgress`.
|
|
92
|
-
*/
|
|
93
65
|
const readElements = (answer, onProgress) => elementsFrom(sentFrom(answer), onProgress);
|
|
94
66
|
export { answeredWithProgress, answeringElements, answeringWithProgress, elementStreamOf, progressStreamOf, readElements, readWithProgress };
|
package/dist/http/watch.mjs
CHANGED
|
@@ -5,13 +5,7 @@ import { answeredStatus, failingWhenUnanswered, isTransient, receivedFrom } from
|
|
|
5
5
|
import { Effect, Predicate, Stream } from "effect";
|
|
6
6
|
import { HttpClientError } from "effect/http";
|
|
7
7
|
// src/http/watch.ts
|
|
8
|
-
/** Whether `error` is an HTTP client's failure on a 404 answer. */
|
|
9
8
|
const isNotFound = Predicate.compose(HttpClientError.isHttpClientError, (error) => answeredStatus(error) === 404);
|
|
10
|
-
/**
|
|
11
|
-
* The transport of one subscription to `event` over its route, `input` its decoded input: each
|
|
12
|
-
* page from `poll`, the stream from `stream`, and a webhook subscription from `webhook`'s routes
|
|
13
|
-
* where the binding has them, a 404 failing as `NotServed`.
|
|
14
|
-
*/
|
|
15
9
|
const transportOf = (event, poll, stream, webhook, input) => {
|
|
16
10
|
const notServed = Effect.fail(SubscriptionError.of(event.name, new NotServed()));
|
|
17
11
|
const answered = (request) => request.pipe(failingWhenUnanswered, Effect.catchIf(isNotFound, () => notServed));
|
package/dist/mcp/bridge.mjs
CHANGED
|
@@ -21,10 +21,6 @@ const groupOf = (adapter, key) => {
|
|
|
21
21
|
if (!isGroup(group)) throw new Error(`Effect's MCP ${adapter.protocolVersion} adapter holds no ${key} group: effect-actions supports MCP events on effect 4.0.x (install the effect version its peer range names)`);
|
|
22
22
|
return group;
|
|
23
23
|
};
|
|
24
|
-
/**
|
|
25
|
-
* The JSON Schemas `events/list` lists for `event`, refusing an input or a payload that is no
|
|
26
|
-
* object.
|
|
27
|
-
*/
|
|
28
24
|
const eventSchemasOf = (event) => {
|
|
29
25
|
const inputSchema = toolJsonSchema(Schema.toCodecJson(event.input), true);
|
|
30
26
|
if (!isObjectSchema(inputSchema)) throw new Error(`MCP event input must be one object with keys, such as a struct: ${event.name} (wrap a union, an array or a scalar in a field, or omit input for no arguments)`);
|
|
@@ -70,27 +66,11 @@ const servedOf = (feed, delivery) => {
|
|
|
70
66
|
}
|
|
71
67
|
};
|
|
72
68
|
};
|
|
73
|
-
/**
|
|
74
|
-
* Dies with the reason the endpoint of `serving` cannot serve one of its events, run where the
|
|
75
|
-
* endpoint's layer is built: a protected one with a `subscription` hook, under an authentication
|
|
76
|
-
* without a principal to key its polls by.
|
|
77
|
-
*/
|
|
78
69
|
const refuseUnservable = ({ events, authentication }) => authentication === void 0 ? Effect.void : Effect.flatMap(acquireFeeds(events), (feeds) => {
|
|
79
70
|
const refusal = unkeyedHook("MCP", feeds, authentication.principal !== void 0);
|
|
80
71
|
return refusal === void 0 ? Effect.void : Effect.die(new Error(refusal));
|
|
81
72
|
});
|
|
82
|
-
/**
|
|
83
|
-
* Serves the feeds the endpoint of `serving` offers by webhook to `Webhooks`, where it is
|
|
84
|
-
* provided, run where the endpoint's layer is built: it restores their kept subscriptions, and
|
|
85
|
-
* dies where they cannot be kept.
|
|
86
|
-
*/
|
|
87
73
|
const serveWebhooks = (serving) => Effect.asVoid(Effect.flatMap(acquireFeeds(serving.events), (feeds) => servedWebhooks(feeds, serving.authentication)));
|
|
88
|
-
/**
|
|
89
|
-
* One push subscription, as `events/stream` holds it: what the feed's `pushed` sends, as
|
|
90
|
-
* SEP-3415's notifications. Its confirmation is `active`, a later gap a fresh `active`, a
|
|
91
|
-
* position a heartbeat, and a failure it reads on through `error`. A failure before `active` is
|
|
92
|
-
* the request's error; a refusal after it ends the subscription with `terminated`.
|
|
93
|
-
*/
|
|
94
74
|
const delivered = ({ send, clientId, requestId, wire, _meta: resultMeta }, run) => {
|
|
95
75
|
const notify = (rpc, payload) => send("2026-07-28", clientId, {
|
|
96
76
|
tag: rpc._tag,
|
|
@@ -149,11 +129,6 @@ const delivered = ({ send, clientId, requestId, wire, _meta: resultMeta }, run)
|
|
|
149
129
|
};
|
|
150
130
|
});
|
|
151
131
|
};
|
|
152
|
-
/**
|
|
153
|
-
* `base`, the 2026-07-28 adapter, also serving SEP-3415's `events/list`, `events/poll` and
|
|
154
|
-
* `events/stream` for the event implementations of `serving`, and advertising the extension in
|
|
155
|
-
* its discovery.
|
|
156
|
-
*/
|
|
157
132
|
const withEvents = (base, serving) => {
|
|
158
133
|
const { authentication } = serving;
|
|
159
134
|
const asSubscriber = (event, run) => authentication === void 0 || event.caller === Anyone ? run : recordStepUp(promote(authentication, run));
|
package/dist/mcp/client.d.mts
CHANGED
|
@@ -33,7 +33,6 @@ 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
|
-
/** What a watch of `W` may fail with, under the endpoint's descriptor `D`. */
|
|
37
36
|
type WatchError<W extends Any, D> = SubscriptionError | BuiltIn | VerifierError<W, D>["Type"] | Schema.SchemaError | HttpClientError.HttpClientError | McpCallError;
|
|
38
37
|
/**
|
|
39
38
|
* Every action of `Contracts` as `client.<action>(input)`, calling its tool; one answering a
|
package/dist/mcp/client.mjs
CHANGED
|
@@ -21,7 +21,6 @@ const ToolCallReply = Schema.Union([Schema.Struct({ result: McpSchema.CallToolRe
|
|
|
21
21
|
message: Schema.String
|
|
22
22
|
}) })]);
|
|
23
23
|
const decodeReply = Schema.decodeUnknownOption(Schema.fromJsonString(ToolCallReply));
|
|
24
|
-
/** `onProgress` given each `notifications/progress` value decoded, one that does not logged and dropped. */
|
|
25
24
|
const decodedSink = (progress, onProgress) => {
|
|
26
25
|
const sink = progressSink(onProgress);
|
|
27
26
|
if (progress === void 0 || sink === void 0) return;
|
package/dist/mcp/events.mjs
CHANGED
|
@@ -4,9 +4,7 @@ import { ErrorReporter, Schema, Struct } from "effect";
|
|
|
4
4
|
import { McpSchema } from "effect/ai";
|
|
5
5
|
import { Rpc, RpcGroup } from "effect/rpc";
|
|
6
6
|
// src/mcp/events.ts
|
|
7
|
-
/** The extension's identifier, its key in `capabilities.extensions`. */
|
|
8
7
|
const extension = "io.modelcontextprotocol/events";
|
|
9
|
-
/** The `_meta` key a push stream's notifications carry its request id under. */
|
|
10
8
|
const subscriptionIdKey = "io.modelcontextprotocol/subscriptionId";
|
|
11
9
|
const codes = {
|
|
12
10
|
headerMismatch: -32020,
|
|
@@ -17,17 +15,14 @@ const codes = {
|
|
|
17
15
|
const Meta = Schema.optional(Schema.Record(Schema.String, Schema.Json));
|
|
18
16
|
const Arguments = Schema.optional(Schema.Record(Schema.String, Schema.Json));
|
|
19
17
|
const Cursor = Schema.optional(Schema.NullOr(Schema.String));
|
|
20
|
-
/** A JSON-RPC error as an `events/*` request fails with, and a termination carries. */
|
|
21
18
|
const WireError = Schema.Struct({
|
|
22
19
|
code: Schema.Int,
|
|
23
20
|
message: Schema.String,
|
|
24
21
|
data: Schema.optional(Schema.Json)
|
|
25
22
|
});
|
|
26
|
-
/** What an `events/*` handler fails with: the JSON-RPC error it answers. */
|
|
27
23
|
var EventsError = class extends Schema.Error("effect-actions/McpEventsError")(WireError.fields) {
|
|
28
24
|
[ErrorReporter.ignore] = true;
|
|
29
25
|
};
|
|
30
|
-
/** One event type as `events/list` lists it. */
|
|
31
26
|
const EventDescriptor = Schema.Struct({
|
|
32
27
|
name: Schema.String,
|
|
33
28
|
description: Schema.String,
|
|
@@ -39,7 +34,6 @@ const EventDescriptor = Schema.Struct({
|
|
|
39
34
|
inputSchema: McpSchema.ToolJson,
|
|
40
35
|
payloadSchema: McpSchema.ToolOutputJson
|
|
41
36
|
});
|
|
42
|
-
/** An occurrence on the wire: in a poll's `events`, and the params of an event notification. */
|
|
43
37
|
const WireOccurrence = Schema.Struct({
|
|
44
38
|
eventId: Schema.String,
|
|
45
39
|
name: Schema.String,
|
package/dist/mcp/progress.mjs
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { Effect, Option, Schema } from "effect";
|
|
2
2
|
import { McpSchema } from "effect/ai";
|
|
3
3
|
// src/mcp/progress.ts
|
|
4
|
-
/** The `_meta` key a `notifications/progress` carries its value under, as JSON. */
|
|
5
4
|
const progressKey = "effect-actions/progress";
|
|
6
5
|
const tokenOf = Schema.decodeUnknownOption(McpSchema.ProgressToken);
|
|
7
|
-
/**
|
|
8
|
-
* Where a tool call's progress goes: a `notifications/progress` for each value, on the
|
|
9
|
-
* `progressToken` its request carried, `progress` counting from 1, `message` the value's JSON and
|
|
10
|
-
* `_meta` the value; none for a request without a token, so the values are checked and dropped.
|
|
11
|
-
*/
|
|
12
6
|
const progressNotifier = (notifications, progress) => Effect.map(Effect.service(McpSchema.McpRequestContext), ({ requestMetadata }) => {
|
|
13
7
|
const token = tokenOf(requestMetadata?.progressToken);
|
|
14
8
|
if (Option.isNone(token)) return;
|
|
@@ -29,6 +23,5 @@ const Notified = Schema.fromJsonString(Schema.Struct({
|
|
|
29
23
|
params: Schema.Struct({ _meta: Schema.Struct({ [progressKey]: Schema.Json }) })
|
|
30
24
|
}));
|
|
31
25
|
const notifiedOf = Schema.decodeUnknownOption(Notified);
|
|
32
|
-
/** The value a frame's `notifications/progress` carries, or none for another frame. */
|
|
33
26
|
const progressOf = (data) => Option.map(notifiedOf(data), (notified) => notified.params._meta[progressKey]);
|
|
34
27
|
export { progressKey, progressNotifier, progressOf };
|
package/dist/mcp/protocol.mjs
CHANGED
|
@@ -34,7 +34,6 @@ const toolJsonSchema = (schema, strict) => {
|
|
|
34
34
|
$defs: definitions
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
/** The forms an MCP routing header may carry `name` in: as sent, or base64-encoded in its sentinel. */
|
|
38
37
|
const routingFormsOf = (name) => [name, `=?base64?${Base64.encode(name)}?=`];
|
|
39
38
|
const fieldKey = "effect-actions/field";
|
|
40
39
|
const isMedia = Schema.is(Media);
|
|
@@ -143,11 +142,6 @@ const mediaOf = ({ name, kind, many }, result) => {
|
|
|
143
142
|
}] : []);
|
|
144
143
|
return many || values.length > 1 ? values : values[0];
|
|
145
144
|
};
|
|
146
|
-
/**
|
|
147
|
-
* The encoded success a tool result carries, `liftedFrom` undone: its structured content, each
|
|
148
|
-
* lifted field from the blocks whose `_meta` names it, and a success that is media from its
|
|
149
|
-
* blocks alone.
|
|
150
|
-
*/
|
|
151
145
|
const unliftedFrom = (lift, result) => {
|
|
152
146
|
const [whole] = lift.fields;
|
|
153
147
|
if (whole !== void 0 && whole.name === void 0) return mediaOf(whole, result);
|