@gjermundgaraba/effect-actions 0.22.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
|
@@ -3,20 +3,19 @@ import * as Authentication from "@gjermundgaraba/effect-actions/Authentication";
|
|
|
3
3
|
import { Effect, Redacted } from "effect";
|
|
4
4
|
|
|
5
5
|
import { Login } from "./Identity.js";
|
|
6
|
-
import {
|
|
6
|
+
import { demoMembers } from "./members.js";
|
|
7
7
|
|
|
8
|
-
const isMember = (token: string): token is keyof typeof
|
|
9
|
-
Object.hasOwn(
|
|
8
|
+
const isMember = (token: string): token is keyof typeof demoMembers =>
|
|
9
|
+
Object.hasOwn(demoMembers, token);
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
// authorization server's library. An unknown token is the built-in `Unauthenticated`, which
|
|
13
|
-
// every client decodes, a watch's included.
|
|
14
|
-
export const authenticate = Authentication.layer(Login, (token) => {
|
|
11
|
+
const demoVerify = (token: Redacted.Redacted) => {
|
|
15
12
|
const name = Redacted.value(token);
|
|
16
13
|
|
|
17
14
|
return isMember(name)
|
|
18
|
-
? Effect.succeed(
|
|
15
|
+
? Effect.succeed(demoMembers[name])
|
|
19
16
|
: Effect.fail(
|
|
20
17
|
new Action.Unauthenticated({ message: "Unknown demo token." })
|
|
21
18
|
);
|
|
22
|
-
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const authenticate = Authentication.layer(Login, demoVerify);
|
|
@@ -2,7 +2,6 @@ import { Context, Effect, Layer } from "effect";
|
|
|
2
2
|
|
|
3
3
|
import type { Build } from "../builds/Builds.js";
|
|
4
4
|
|
|
5
|
-
/** The failed builds the notifier was told of, in the order it was told. */
|
|
6
5
|
export class Notices extends Context.Service<
|
|
7
6
|
Notices,
|
|
8
7
|
{
|
|
@@ -10,8 +9,6 @@ export class Notices extends Context.Service<
|
|
|
10
9
|
readonly all: Effect.Effect<readonly Build[]>;
|
|
11
10
|
}
|
|
12
11
|
>()("build-events/Notices") {
|
|
13
|
-
// DEMO ONLY: notices live in this process's memory; a notifier sends each on, to a chat or a
|
|
14
|
-
// pager, as it arrives.
|
|
15
12
|
static readonly layerMemory = Layer.sync(Notices, () => {
|
|
16
13
|
const notices: Build[] = [];
|
|
17
14
|
|
|
@@ -17,12 +17,8 @@ export interface NotifierOptions {
|
|
|
17
17
|
readonly publicUrl: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// The route build-events POSTs each failed build to, where the watch below reads them: the
|
|
21
|
-
// watch's delivery appends its path to this process's public URL.
|
|
22
20
|
const receiver = Webhook.layerReceiver({ path: "/hooks/builds" });
|
|
23
21
|
|
|
24
|
-
// A second service, the notifier: it watches build.finished for failures by webhook, the
|
|
25
|
-
// server POSTing each to it, rather than holding a stream open to build-events.
|
|
26
22
|
const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
27
23
|
Layer.effectDiscard(
|
|
28
24
|
Effect.gen(function* () {
|
|
@@ -42,8 +38,6 @@ const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
|
42
38
|
{ status: "failed" },
|
|
43
39
|
{
|
|
44
40
|
mode: Webhook.delivery({ baseUrl: publicUrl }),
|
|
45
|
-
// Where it reached is kept, so a restart resumes there; failures the server no
|
|
46
|
-
// longer keeps arrive as a Gap instead.
|
|
47
41
|
resume: {
|
|
48
42
|
store: yield* KeyValueStore.KeyValueStore,
|
|
49
43
|
key: "failed-builds",
|
|
@@ -51,15 +45,11 @@ const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
|
51
45
|
}
|
|
52
46
|
)
|
|
53
47
|
.pipe(
|
|
54
|
-
// A Gap says failures were missed, which no notice can name: it is logged, for an
|
|
55
|
-
// operator to look the builds up.
|
|
56
48
|
Stream.runForEach((received) =>
|
|
57
49
|
Predicate.isTagged(received, "Occurrence")
|
|
58
50
|
? notices.add(received.data)
|
|
59
51
|
: Effect.logWarning("Failed builds were missed", received)
|
|
60
52
|
),
|
|
61
|
-
// A failure no reconnect outlasts, such as a wrong PUBLIC_URL or a revoked token,
|
|
62
|
-
// ends the watch: it is logged here, for a deployment to alert on or restart by.
|
|
63
53
|
Effect.tapCause(Effect.logError)
|
|
64
54
|
)
|
|
65
55
|
);
|
|
@@ -8,21 +8,15 @@ import { KeyValueStore } from "effect/persistence";
|
|
|
8
8
|
import { Notices } from "./notifier/Notices.js";
|
|
9
9
|
import { notifier } from "./notifier/routes.js";
|
|
10
10
|
|
|
11
|
-
// Entrypoint of the second service: `BUILDS_TOKEN=grace PUBLIC_URL=https://<its public name>
|
|
12
|
-
// node --import tsx examples/build-events/src/notifier.ts`, with server.ts running. build-events
|
|
13
|
-
// POSTs only to a globally reachable address, so on one machine give it a tunnel's name.
|
|
14
11
|
const server = Layer.unwrap(
|
|
15
12
|
Effect.gen(function* () {
|
|
16
13
|
const buildEvents = yield* Config.String("BUILDS_URL").pipe(
|
|
17
14
|
Config.withDefault("http://127.0.0.1:3000")
|
|
18
15
|
);
|
|
19
16
|
|
|
20
|
-
// Redacted, so a log or an error printing the configuration never shows the token.
|
|
21
17
|
const token = yield* Config.Redacted("BUILDS_TOKEN");
|
|
22
18
|
const publicUrl = yield* Config.String("PUBLIC_URL");
|
|
23
19
|
|
|
24
|
-
// The loopback default serves this machine alone, which a tunnel reaches; HOST=0.0.0.0 lets
|
|
25
|
-
// build-events reach it directly.
|
|
26
20
|
const host = yield* Config.String("HOST").pipe(
|
|
27
21
|
Config.withDefault("127.0.0.1")
|
|
28
22
|
);
|
|
@@ -31,11 +25,9 @@ const server = Layer.unwrap(
|
|
|
31
25
|
|
|
32
26
|
return HttpRouter.serve(notifier({ buildEvents, token, publicUrl })).pipe(
|
|
33
27
|
Layer.provide(NodeHttpServer.layer(createServer, { host, port })),
|
|
34
|
-
// The receiver's route is public and reads each body whole: a delivery is at most 256 KiB.
|
|
35
28
|
Layer.provide(
|
|
36
29
|
Layer.succeed(HttpServerRequest.MaxBodySize, ByteSize.kibibytes(256))
|
|
37
30
|
),
|
|
38
|
-
// DEMO ONLY: notices and the watch's cursor live in this process's memory.
|
|
39
31
|
Layer.provide([
|
|
40
32
|
Notices.layerMemory,
|
|
41
33
|
KeyValueStore.layerMemory,
|
|
@@ -16,7 +16,6 @@ import { Login } from "./identity/Identity.js";
|
|
|
16
16
|
import { authenticate } from "./identity/verifier.js";
|
|
17
17
|
import { Rpc } from "./Rpc.js";
|
|
18
18
|
|
|
19
|
-
// Every domain's implementation, once: the events beside the actions, in one list.
|
|
20
19
|
const implementations = [
|
|
21
20
|
builds,
|
|
22
21
|
logs,
|
|
@@ -26,17 +25,6 @@ const implementations = [
|
|
|
26
25
|
deployEvents,
|
|
27
26
|
];
|
|
28
27
|
|
|
29
|
-
// The actions as MCP tools and the events as MCP events, at `/mcp`. A client polls with
|
|
30
|
-
// `events/poll`, or holds `events/stream` open and is pushed each occurrence. Both events are
|
|
31
|
-
// protected, so each request needs a member's token, and each subscriber sees what its token
|
|
32
|
-
// lets it. This long-lived process holds the deploy event's `subscription` hook between polls and
|
|
33
|
-
// its log in memory, and pushes each occurrence: a `requestScoped` endpoint would serve the events
|
|
34
|
-
// by poll and webhook alone, and a serverless host, where no process lasts, check sources alone,
|
|
35
|
-
// without `Webhook.layer`.
|
|
36
|
-
//
|
|
37
|
-
// A tool answers one result, so `tailLog` would collect a whole log before answering, all of it
|
|
38
|
-
// in a model's context: its implementation, `logs`, is left out, and the endpoint serves every
|
|
39
|
-
// other action and every event.
|
|
40
28
|
const mcp = ActionMcp.layerHttp(
|
|
41
29
|
[builds, buildEvents, statusEvents, deploys, deployEvents],
|
|
42
30
|
{
|
|
@@ -46,25 +34,13 @@ const mcp = ActionMcp.layerHttp(
|
|
|
46
34
|
}
|
|
47
35
|
);
|
|
48
36
|
|
|
49
|
-
// The same implementations as routes under `/api`, for a client that speaks HTTP rather than
|
|
50
|
-
// MCP: one implementation of each event serves every surface.
|
|
51
37
|
const api = ActionHttp.layer(Http, implementations);
|
|
52
38
|
|
|
53
|
-
// And as Effect RPC at `/rpc`, over HTTP. A watch is a stream rpc that never ends, so the
|
|
54
|
-
// serialization frames each element as it is sent: `layerNdjson` does, where `layerJson` would
|
|
55
|
-
// answer once every stream of the request ended, which a watch never does.
|
|
56
39
|
const rpc = ActionRpc.layer(Rpc, implementations).pipe(
|
|
57
40
|
Layer.provide(RpcServer.layerProtocolHttp({ path: "/rpc" })),
|
|
58
41
|
Layer.provide(RpcSerialization.layerNdjson)
|
|
59
42
|
);
|
|
60
43
|
|
|
61
|
-
// Webhook delivery for MCP and HTTP alike: a member names a callback URL and a secret, with
|
|
62
|
-
// MCP's `events/subscribe` or `POST /api/events/<name>/subscribe`, and each occurrence it may see
|
|
63
|
-
// is POSTed there, signed. One layer holds the subscriptions of both, so either surface refreshes
|
|
64
|
-
// one made over the other. `persist` keeps each in a `KeyValueStore`, so a restart goes on
|
|
65
|
-
// delivering from where it reached, as the subscriber `Login`'s `schema` keeps. It needs an
|
|
66
|
-
// `HttpClient` to POST, `Dns` to check where each callback resolves, and the store, which
|
|
67
|
-
// `server.ts` provides.
|
|
68
44
|
export const routes = Layer.mergeAll(mcp, api, rpc).pipe(
|
|
69
45
|
Layer.provide(authenticate),
|
|
70
46
|
Layer.provide(Webhook.layer({ persist: true }))
|
|
@@ -16,11 +16,8 @@ import { BuildStore } from "./builds/store.js";
|
|
|
16
16
|
import { Approvers } from "./deploys/approvers.js";
|
|
17
17
|
import { routes } from "./routes.js";
|
|
18
18
|
|
|
19
|
-
// Entrypoint: `node --import tsx examples/build-events/src/server.ts`.
|
|
20
|
-
// It chooses the stores, reads the configuration and starts Node's HTTP server.
|
|
21
19
|
const server = Layer.unwrap(
|
|
22
20
|
Effect.gen(function* () {
|
|
23
|
-
// The loopback default serves this machine alone; HOST=0.0.0.0 lets others reach it.
|
|
24
21
|
const host = yield* Config.String("HOST").pipe(
|
|
25
22
|
Config.withDefault("127.0.0.1")
|
|
26
23
|
);
|
|
@@ -33,27 +30,16 @@ const server = Layer.unwrap(
|
|
|
33
30
|
|
|
34
31
|
return HttpRouter.serve(routes).pipe(
|
|
35
32
|
Layer.provide(NodeHttpServer.layer(createServer, { host, port })),
|
|
36
|
-
// Request bodies have no size limit unless the host sets one. This covers every route
|
|
37
|
-
// that reads its body whole, the MCP endpoint and the webhook subscribe routes included.
|
|
38
33
|
Layer.provide(
|
|
39
34
|
Layer.succeed(HttpServerRequest.MaxBodySize, ByteSize.mebibytes(1))
|
|
40
35
|
),
|
|
41
|
-
// DEMO ONLY: builds and approvers live in this process's memory; a deployment provides
|
|
42
|
-
// stores that last.
|
|
43
36
|
Layer.provide([BuildStore.layerMemory, Approvers.layerMemory]),
|
|
44
|
-
// The events this process announces: a notify after a build finishes, and each deploy
|
|
45
|
-
// request published. One for the whole server, which holds every subscriber's connection.
|
|
46
37
|
Layer.provide(Event.layerMemory),
|
|
47
|
-
// Webhook subscriptions are kept as files under WEBHOOKS_DIR, so a restart goes on
|
|
48
|
-
// delivering them; after one, the memory store above sends each a gap first. The files
|
|
49
|
-
// hold each subscriber's secret: give the directory to this server alone, and each server
|
|
50
|
-
// process its own, since the layer is its store's one writer.
|
|
51
38
|
Layer.provide(
|
|
52
39
|
KeyValueStore.layerFileSystem(webhooks).pipe(
|
|
53
40
|
Layer.provide([NodeFileSystem.layer, NodePath.layer])
|
|
54
41
|
)
|
|
55
42
|
),
|
|
56
|
-
// Webhook delivery POSTs with fetch, and resolves each callback with the system's resolver.
|
|
57
43
|
Layer.provide([FetchHttpClient.layer, NodeDns.layer])
|
|
58
44
|
);
|
|
59
45
|
})
|
|
@@ -14,14 +14,12 @@ it.effect(
|
|
|
14
14
|
"delivers each build a member may see as it finishes, as the subscription selects",
|
|
15
15
|
() =>
|
|
16
16
|
Effect.gen(function* () {
|
|
17
|
-
// One client holds both: the action that finishes builds and the event that reports them.
|
|
18
17
|
const client = yield* Action.client([builds, buildEvents]);
|
|
19
18
|
|
|
20
19
|
const failed = yield* client
|
|
21
20
|
.watch(BuildFinished, { status: "failed" })
|
|
22
21
|
.pipe(Stream.take(1), Stream.runCollect, as("grace"), Effect.forkChild);
|
|
23
22
|
|
|
24
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
25
23
|
yield* TestClock.adjust("0 millis");
|
|
26
24
|
yield* client
|
|
27
25
|
.finishBuild({ pipeline: "api", status: "failed" })
|
|
@@ -29,12 +27,10 @@ it.effect(
|
|
|
29
27
|
yield* client
|
|
30
28
|
.finishBuild({ pipeline: "web", status: "passed" })
|
|
31
29
|
.pipe(as("ada"));
|
|
32
|
-
// Each build finished notifies: the watch reads at once, with no wait for its next poll.
|
|
33
30
|
yield* client
|
|
34
31
|
.finishBuild({ pipeline: "web", status: "failed" })
|
|
35
32
|
.pipe(as("ada"));
|
|
36
33
|
|
|
37
|
-
// grace sees only the web pipeline, and asked only for failures.
|
|
38
34
|
expect(yield* Fiber.join(failed)).toMatchObject([
|
|
39
35
|
{
|
|
40
36
|
_tag: "Occurrence",
|
|
@@ -54,8 +50,6 @@ it.effect(
|
|
|
54
50
|
.finishBuild({ pipeline: "web", status: "passed" })
|
|
55
51
|
.pipe(as("ada"));
|
|
56
52
|
|
|
57
|
-
// A cursor of the store before a restart, its offset one this store has too: what it named
|
|
58
|
-
// is gone, so the watch is told.
|
|
59
53
|
const resumed = yield* client
|
|
60
54
|
.watch(BuildFinished, {}, { cursor: "an-earlier-epoch:0" })
|
|
61
55
|
.pipe(Stream.take(2), Stream.runCollect, as("grace"));
|
|
@@ -39,7 +39,6 @@ describe("a build's log", () => {
|
|
|
39
39
|
const rpc = yield* ActionRpc.client(Rpc);
|
|
40
40
|
const { id } = yield* http.startBuild({ pipeline: "api" });
|
|
41
41
|
|
|
42
|
-
// Each call returns a `Stream`: a line is read as the server sends it.
|
|
43
42
|
const lines = [
|
|
44
43
|
yield* Stream.runCollect(http.tailLog({ buildId: id })),
|
|
45
44
|
yield* Stream.runCollect(rpc.tailLog({ buildId: id })).pipe(
|
|
@@ -41,7 +41,6 @@ describe("a build started by a member", () => {
|
|
|
41
41
|
const onProgress = (step: (typeof steps)[number]) =>
|
|
42
42
|
Effect.sync(() => seen.push(step));
|
|
43
43
|
|
|
44
|
-
// A caller asks for the steps by giving `onProgress`; without it, the call answers alone.
|
|
45
44
|
const answers = [
|
|
46
45
|
yield* http.startBuild({ pipeline: "api" }, { onProgress }),
|
|
47
46
|
yield* mcp.startBuild({ pipeline: "api" }, { onProgress }),
|
|
@@ -14,7 +14,6 @@ import { inMemory } from "./support/memory.js";
|
|
|
14
14
|
|
|
15
15
|
const served = Testing.layer(routes).pipe(Layer.provide(inMemory()));
|
|
16
16
|
|
|
17
|
-
// Effect's own runner, given arguments instead of the process's, as the member `token` names.
|
|
18
17
|
const run = (token: string, args: readonly string[]) =>
|
|
19
18
|
Command.runWith(commands, { version: "0" })(args).pipe(
|
|
20
19
|
Effect.provide(
|
|
@@ -29,7 +28,6 @@ describe("the commands", () => {
|
|
|
29
28
|
"print each build a member may see as a line of JSON, until stopped",
|
|
30
29
|
() =>
|
|
31
30
|
Effect.gen(function* () {
|
|
32
|
-
// A watch runs until it is stopped, as Ctrl-C stops it: here, by interrupting it.
|
|
33
31
|
const watching = yield* Effect.forkChild(
|
|
34
32
|
run("grace", ["watch", "build.finished"])
|
|
35
33
|
);
|
|
@@ -47,7 +45,6 @@ describe("the commands", () => {
|
|
|
47
45
|
yield* TestClock.adjust("5 seconds");
|
|
48
46
|
yield* Fiber.interrupt(watching);
|
|
49
47
|
|
|
50
|
-
// Each line carries its cursor: `--cursor` given it resumes after that build.
|
|
51
48
|
const lines = yield* Schema.decodeUnknownEffect(
|
|
52
49
|
Schema.Array(Schema.fromJsonString(Schema.Unknown))
|
|
53
50
|
)(yield* TestConsole.logLines);
|
|
@@ -65,7 +62,6 @@ describe("the commands", () => {
|
|
|
65
62
|
Effect.gen(function* () {
|
|
66
63
|
yield* run("ada", ["start-build", "--pipeline", "api"]);
|
|
67
64
|
|
|
68
|
-
// stdout holds the answer alone, so `builds start-build ... | jq` reads the build.
|
|
69
65
|
expect(yield* TestConsole.logLines).toStrictEqual([
|
|
70
66
|
JSON.stringify(
|
|
71
67
|
{ id: "build-1", pipeline: "api", status: "passed" },
|
|
@@ -94,7 +90,6 @@ describe("the commands", () => {
|
|
|
94
90
|
]);
|
|
95
91
|
yield* run("ada", ["tail-log", "--build-id", "build-1"]);
|
|
96
92
|
|
|
97
|
-
// A line per element, as JSON Lines: `builds tail-log ... | jq -r .line` prints the log.
|
|
98
93
|
expect((yield* TestConsole.logLines).slice(1)).toStrictEqual([
|
|
99
94
|
'{"line":"failed"}',
|
|
100
95
|
]);
|
|
@@ -14,7 +14,6 @@ import { inMemory } from "./support/memory.js";
|
|
|
14
14
|
|
|
15
15
|
const served = Testing.layer(routes).pipe(Layer.provide(inMemory()));
|
|
16
16
|
|
|
17
|
-
// One client of the binding per member: the token is the member, as in production.
|
|
18
17
|
const as = (token: string) =>
|
|
19
18
|
ActionHttp.client(Http, {
|
|
20
19
|
transformClient: HttpClient.mapRequest(
|
|
@@ -30,12 +29,10 @@ describe("the service, over HTTP", () => {
|
|
|
30
29
|
const ada = yield* as("ada");
|
|
31
30
|
const grace = yield* as("grace");
|
|
32
31
|
|
|
33
|
-
// `watch` asks for `text/event-stream`, and the route holds the stream open.
|
|
34
32
|
const watched = yield* grace
|
|
35
33
|
.watch(BuildFinished)
|
|
36
34
|
.pipe(Stream.take(1), Stream.runCollect, Effect.forkChild);
|
|
37
35
|
|
|
38
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
39
36
|
yield* TestClock.adjust("0 millis");
|
|
40
37
|
yield* ada.finishBuild({ pipeline: "api", status: "passed" });
|
|
41
38
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
@@ -53,7 +50,6 @@ describe("the service, over HTTP", () => {
|
|
|
53
50
|
const ada = yield* as("ada");
|
|
54
51
|
const grace = yield* as("grace");
|
|
55
52
|
|
|
56
|
-
// `mode: "poll"` asks for a page at a time, as a client that cannot hold a stream does.
|
|
57
53
|
const polled = yield* grace
|
|
58
54
|
.watch(
|
|
59
55
|
DeployRequested,
|
|
@@ -14,9 +14,6 @@ import { inMemory, settled } from "./support/memory.js";
|
|
|
14
14
|
describe("the notifier, by webhook", () => {
|
|
15
15
|
it.effect("is told of each failed build its member may see", () =>
|
|
16
16
|
Effect.gen(function* () {
|
|
17
|
-
// Both services in memory: build-events POSTs to the notifier's routes, and the notifier
|
|
18
|
-
// calls build-events. Each one's client reaches the other, a cycle no layer builds, so
|
|
19
|
-
// the notifier's client waits for build-events' to be handed over.
|
|
20
17
|
const toBuildEvents = yield* Deferred.make<HttpClient.HttpClient>();
|
|
21
18
|
|
|
22
19
|
const handedOver = Layer.succeed(
|
|
@@ -34,8 +31,6 @@ describe("the notifier, by webhook", () => {
|
|
|
34
31
|
publicUrl: "https://hooks.example.com",
|
|
35
32
|
}).pipe(Layer.provide(handedOver));
|
|
36
33
|
|
|
37
|
-
// The notices and the watch's cursor are provided around both, so the test reads the ones
|
|
38
|
-
// the notifier writes.
|
|
39
34
|
const services = Testing.layer(routes).pipe(
|
|
40
35
|
Layer.provide(inMemory(Testing.layer(notifierRoutes))),
|
|
41
36
|
Layer.provideMerge(
|
|
@@ -49,7 +44,6 @@ describe("the notifier, by webhook", () => {
|
|
|
49
44
|
const notices = yield* Notices;
|
|
50
45
|
const cursors = yield* KeyValueStore.KeyValueStore;
|
|
51
46
|
|
|
52
|
-
// The notifier's watch keeps a position once it is subscribed.
|
|
53
47
|
yield* settled(cursors.has("failed-builds"));
|
|
54
48
|
|
|
55
49
|
const ada = yield* ActionHttp.client(Http, {
|
|
@@ -60,11 +54,9 @@ describe("the notifier, by webhook", () => {
|
|
|
60
54
|
|
|
61
55
|
yield* ada.finishBuild({ pipeline: "api", status: "failed" });
|
|
62
56
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
63
|
-
// Each build finished notifies `build.finished`: it is POSTed at once, no poll awaited.
|
|
64
57
|
yield* ada.finishBuild({ pipeline: "web", status: "failed" });
|
|
65
58
|
yield* settled(Effect.map(notices.all, (all) => all.length > 0));
|
|
66
59
|
|
|
67
|
-
// grace sees the web pipeline alone, and the notifier asked for failures alone.
|
|
68
60
|
expect(yield* notices.all).toStrictEqual([
|
|
69
61
|
{ id: "build-3", pipeline: "web", status: "failed" },
|
|
70
62
|
]);
|
|
@@ -72,7 +64,6 @@ describe("the notifier, by webhook", () => {
|
|
|
72
64
|
yield* ada.finishBuild({ pipeline: "web", status: "failed" });
|
|
73
65
|
yield* settled(Effect.map(notices.all, (all) => all.length > 1));
|
|
74
66
|
|
|
75
|
-
// Once build-4 is read, build-3 is handled: a restart resumes after the third build.
|
|
76
67
|
expect(yield* cursors.get("failed-builds")).toMatch(/:3$/u);
|
|
77
68
|
}).pipe(Effect.provide(services));
|
|
78
69
|
})
|
|
@@ -12,8 +12,6 @@ import { Login } from "../src/identity/Identity.js";
|
|
|
12
12
|
import { routes } from "../src/routes.js";
|
|
13
13
|
import { inMemory } from "./support/memory.js";
|
|
14
14
|
|
|
15
|
-
// What the wire adds: the real routes, behind their real authentication, answering in memory.
|
|
16
|
-
// No port is opened. The subscriber is the token each client sends, as in production.
|
|
17
15
|
const served = Testing.layer(routes).pipe(Layer.provide(inMemory()));
|
|
18
16
|
|
|
19
17
|
const as = (token: string) => ({
|
|
@@ -26,7 +24,6 @@ describe("the service, over MCP", () => {
|
|
|
26
24
|
"pushes each build a member may see, as a tool call finishes it",
|
|
27
25
|
() =>
|
|
28
26
|
Effect.gen(function* () {
|
|
29
|
-
// A client lists the contracts it uses: the action it calls, the event it watches.
|
|
30
27
|
const ada = yield* ActionMcp.client([FinishBuild], as("ada"));
|
|
31
28
|
const grace = yield* ActionMcp.client([BuildFinished], as("grace"));
|
|
32
29
|
|
|
@@ -34,11 +31,8 @@ describe("the service, over MCP", () => {
|
|
|
34
31
|
.watch(BuildFinished)
|
|
35
32
|
.pipe(Stream.take(1), Stream.runCollect, Effect.forkChild);
|
|
36
33
|
|
|
37
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
38
34
|
yield* TestClock.adjust("0 millis");
|
|
39
35
|
yield* ada.finishBuild({ pipeline: "api", status: "passed" });
|
|
40
|
-
// Each build finished notifies `build.finished`: the server asks the store at once, and
|
|
41
|
-
// pushes what it answers.
|
|
42
36
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
43
37
|
|
|
44
38
|
expect(yield* Fiber.join(watched)).toMatchObject([
|
|
@@ -54,7 +48,6 @@ describe("the service, over MCP", () => {
|
|
|
54
48
|
const ada = yield* ActionMcp.client([RequestDeploy], as("ada"));
|
|
55
49
|
const grace = yield* ActionMcp.client([DeployRequested], as("grace"));
|
|
56
50
|
|
|
57
|
-
// `mode: "poll"` asks with `events/poll`, as a client that cannot hold a stream does.
|
|
58
51
|
const polled = yield* grace
|
|
59
52
|
.watch(
|
|
60
53
|
DeployRequested,
|
|
@@ -72,8 +65,6 @@ describe("the service, over MCP", () => {
|
|
|
72
65
|
|
|
73
66
|
yield* TestClock.adjust("5 seconds");
|
|
74
67
|
|
|
75
|
-
// Between polls, grace stands by: the server holds the subscription hook for 5 minutes
|
|
76
|
-
// after each poll, keyed by grace's principal.
|
|
77
68
|
expect(deploy.approvers).toStrictEqual(["grace"]);
|
|
78
69
|
expect(yield* Fiber.join(polled)).toMatchObject([
|
|
79
70
|
{
|
|
@@ -11,15 +11,12 @@ import { routes } from "../src/routes.js";
|
|
|
11
11
|
import { Rpc } from "../src/Rpc.js";
|
|
12
12
|
import { inMemory } from "./support/memory.js";
|
|
13
13
|
|
|
14
|
-
// Effect's RPC client over HTTP to the real routes in memory, with the serialization the
|
|
15
|
-
// server frames streams with.
|
|
16
14
|
const served = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
|
|
17
15
|
Layer.provide(RpcSerialization.layerNdjson),
|
|
18
16
|
Layer.provide(Testing.layer(routes)),
|
|
19
17
|
Layer.provide(inMemory())
|
|
20
18
|
);
|
|
21
19
|
|
|
22
|
-
// An rpc's credential is its own headers: each call or watch says who is calling.
|
|
23
20
|
const as = (token: string) =>
|
|
24
21
|
RpcClient.withHeaders({ authorization: `Bearer ${token}` });
|
|
25
22
|
|
|
@@ -32,7 +29,6 @@ describe("the service, over RPC", () => {
|
|
|
32
29
|
.watch(BuildFinished)
|
|
33
30
|
.pipe(Stream.take(1), Stream.runCollect, as("grace"), Effect.forkChild);
|
|
34
31
|
|
|
35
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
36
32
|
yield* TestClock.adjust("0 millis");
|
|
37
33
|
yield* client
|
|
38
34
|
.finishBuild({ pipeline: "api", status: "passed" })
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
|
|
3
3
|
import { CurrentMember } from "../../src/identity/Identity.js";
|
|
4
|
-
import {
|
|
4
|
+
import { demoMembers } from "../../src/identity/members.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Effect.provideService(CurrentMember, members[member]);
|
|
6
|
+
export const as = (member: keyof typeof demoMembers) =>
|
|
7
|
+
Effect.provideService(CurrentMember, demoMembers[member]);
|
|
@@ -12,9 +12,6 @@ import { Approvers } from "../../src/deploys/approvers.js";
|
|
|
12
12
|
|
|
13
13
|
const unreached = async () => new Response(null, { status: 503 });
|
|
14
14
|
|
|
15
|
-
// What the routes need, in memory: the stores, the events announced, and for webhook delivery a client, a resolver
|
|
16
|
-
// and a store for the subscriptions. `subscribers` answers each POST in place of a member's server, and
|
|
17
|
-
// hooks.example.com resolves to a public address: delivery refuses a private or loopback one.
|
|
18
15
|
export const inMemory = <R = never>(
|
|
19
16
|
subscribers: Layer.Layer<HttpClient.HttpClient, never, R> = Testing.layer(
|
|
20
17
|
unreached
|
|
@@ -29,8 +26,6 @@ export const inMemory = <R = never>(
|
|
|
29
26
|
KeyValueStore.layerMemory
|
|
30
27
|
);
|
|
31
28
|
|
|
32
|
-
// Waits for `done` while requests in memory resolve: a subscription made through them runs on
|
|
33
|
-
// promises the test clock does not drive.
|
|
34
29
|
export const settled = <E, R>(done: Effect.Effect<boolean, E, R>) =>
|
|
35
30
|
Effect.repeat(
|
|
36
31
|
Effect.andThen(
|
|
@@ -8,12 +8,8 @@ import { Http } from "../src/Api.js";
|
|
|
8
8
|
import { routes } from "../src/routes.js";
|
|
9
9
|
import { inMemory } from "./support/memory.js";
|
|
10
10
|
|
|
11
|
-
// The subscriber's secret: `whsec_` and 24 to 64 random bytes in base64. The server signs each
|
|
12
|
-
// POST with it, and the subscriber checks each POST it receives against it.
|
|
13
11
|
const secret = `whsec_${Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64")}`;
|
|
14
12
|
|
|
15
|
-
// A subscriber's check, as Standard Webhooks defines it: an HMAC-SHA256 of the id, the
|
|
16
|
-
// timestamp and the body exactly as received, among the space-separated `v1,` signatures.
|
|
17
13
|
const signed = async (request: Request, body: string) => {
|
|
18
14
|
const key = await crypto.subtle.importKey(
|
|
19
15
|
"raw",
|
|
@@ -51,8 +47,6 @@ interface Received {
|
|
|
51
47
|
readonly signed: boolean;
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
// grace's server: it answers the verification POST by echoing its challenge, which proves it
|
|
55
|
-
// asked for these deliveries, and acknowledges each delivery with a 2xx.
|
|
56
50
|
const subscriber =
|
|
57
51
|
(received: Queue.Enqueue<Received>) => async (request: Request) => {
|
|
58
52
|
const text = await request.text();
|
|
@@ -106,20 +100,14 @@ describe("the service, by webhook", () => {
|
|
|
106
100
|
),
|
|
107
101
|
});
|
|
108
102
|
|
|
109
|
-
// The answer names the subscription, which each POST's `x-mcp-subscription-id`
|
|
110
|
-
// carries, and when to subscribe again to keep it: one not refreshed by then ends.
|
|
111
103
|
const subscription = yield* subscribe;
|
|
112
104
|
const verification = yield* Queue.take(received);
|
|
113
105
|
|
|
114
106
|
yield* ada.finishBuild({ pipeline: "api", status: "passed" });
|
|
115
|
-
// Each build finished notifies `build.finished`: the server asks the store at once, and
|
|
116
|
-
// POSTs what it answers.
|
|
117
107
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
118
108
|
|
|
119
|
-
// grace sees only the web pipeline.
|
|
120
109
|
const delivery = yield* Queue.take(received);
|
|
121
110
|
|
|
122
|
-
// The same request again refreshes the subscription, and answers how it is going.
|
|
123
111
|
const refreshed = yield* subscribe;
|
|
124
112
|
|
|
125
113
|
expect(verification).toMatchObject({
|
|
@@ -31,7 +31,7 @@ node --import tsx examples/kitchen-sink/src/agent.ts # the assis
|
|
|
31
31
|
vp test examples/kitchen-sink
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
`HOST`, `PORT`, `ADMIN_PORT`, `PUBLIC_URL` and `MCP_ORIGIN` configure the server; `TRACKER_URL` points the CLI and the seed at it. `stdio.ts` is an MCP server for a local agent to start as a subprocess. `sdk.ts` and `browser.ts` are imported by client code, not run. The OpenAPI document is at `/api/v1/openapi.json`, Swagger UI at `/docs`, the MCP endpoint at `/mcp`, the socket at `/rpc`.
|
|
34
|
+
`HOST`, `PORT`, `ADMIN_PORT`, `PUBLIC_URL` and `MCP_ORIGIN` configure the server; `TRACKER_URL` points the CLI and the seed at it. `stdio.ts` is an MCP server for a local agent to start as a subprocess: from the repository root, register it with `claude mcp add tracker -- "$PWD/node_modules/.bin/tsx" "$PWD/examples/kitchen-sink/src/stdio.ts"`, full paths since the host starts it in a directory of its choosing. `sdk.ts` and `browser.ts` are imported by client code, not run. The OpenAPI document is at `/api/v1/openapi.json`, Swagger UI at `/docs`, the MCP endpoint at `/mcp`, the socket at `/rpc`.
|
|
35
35
|
|
|
36
36
|
| Credential | Who | May |
|
|
37
37
|
| --- | --- | --- |
|
|
@@ -4,10 +4,6 @@ import { WhoAmI } from "./identity/Identity.js";
|
|
|
4
4
|
import { ExportIssues, Issues } from "./issues/Issues.js";
|
|
5
5
|
import { GetStatus } from "./workspaces/Workspaces.js";
|
|
6
6
|
|
|
7
|
-
// Which actions each surface gets. A contract says nothing about where it is served: each
|
|
8
|
-
// surface takes a list, and these are the lists, built from the contracts themselves.
|
|
9
|
-
|
|
10
|
-
/** What a signed-in member may call: every protected action of the public port. */
|
|
11
7
|
export const MemberActions = [
|
|
12
8
|
WhoAmI,
|
|
13
9
|
...Issues,
|
|
@@ -17,10 +13,4 @@ export const MemberActions = [
|
|
|
17
13
|
...Assistant,
|
|
18
14
|
] as const;
|
|
19
15
|
|
|
20
|
-
/**
|
|
21
|
-
* The MCP tools, for the HTTP endpoint and the stdio server alike. `attachImage` is left out:
|
|
22
|
-
* listing it throws, since MCP takes no image as input. So is the assistant: it is a model
|
|
23
|
-
* itself, and its tools are already here. So is `exportIssues`: a tool collects its stream
|
|
24
|
-
* whole before answering, every issue of the workspace at once in a model's context.
|
|
25
|
-
*/
|
|
26
16
|
export const Tools = [GetStatus, WhoAmI, ...Issues, GetAttachment] as const;
|
|
@@ -6,11 +6,6 @@ import { Login, QuotaExceeded } from "./identity/Identity.js";
|
|
|
6
6
|
import { IssueChanged } from "./issues/Issues.js";
|
|
7
7
|
import { GetStatus } from "./workspaces/Workspaces.js";
|
|
8
8
|
|
|
9
|
-
// The members' HTTP binding: every action at `POST /api/v1/<name>`, and `issue.changed` at
|
|
10
|
-
// `POST /api/v1/events/issue.changed`, polled or held open as a stream. It is plain data and
|
|
11
|
-
// imports no server code, so the server, the CLI, the SDK and a test all import this one value.
|
|
12
|
-
// - `authentication`: how the protected actions' caller proves who it is. `getStatus` is public.
|
|
13
|
-
// - `error`: the quota middleware's, so a client decodes its 429 as a typed `QuotaExceeded`.
|
|
14
9
|
export const Http = ActionHttp.make(
|
|
15
10
|
[GetStatus, ...MemberActions, IssueChanged],
|
|
16
11
|
{
|
|
@@ -20,9 +15,6 @@ export const Http = ActionHttp.make(
|
|
|
20
15
|
}
|
|
21
16
|
);
|
|
22
17
|
|
|
23
|
-
// The operators' binding: other actions, another identity, another descriptor, served on a port
|
|
24
|
-
// of its own.
|
|
25
|
-
// The public `getStatus` is bound here too: one contract, one implementation, on both ports.
|
|
26
18
|
export const AdminHttp = ActionHttp.make([GetStatus, ...Admin], {
|
|
27
19
|
prefix: "/admin",
|
|
28
20
|
authentication: OperatorKey,
|
|
@@ -4,10 +4,6 @@ import { MemberActions } from "./Actions.js";
|
|
|
4
4
|
import { QuotaExceeded, Session } from "./identity/Identity.js";
|
|
5
5
|
import { IssueChanged } from "./issues/Issues.js";
|
|
6
6
|
|
|
7
|
-
// The web app's binding: the members' actions as Effect RPC, one native rpc per action, and
|
|
8
|
-
// `issue.changed` as a stream rpc, over one WebSocket. Browser-safe, as the HTTP binding is. It
|
|
9
|
-
// names the other descriptor of the same identity: a page proves who it is with its session
|
|
10
|
-
// cookie, which the browser sends on the socket's upgrade. Its `error` is what the layer's middleware, the quota, fails with.
|
|
11
7
|
export const Rpc = ActionRpc.make([...MemberActions, IssueChanged], {
|
|
12
8
|
authentication: Session,
|
|
13
9
|
error: QuotaExceeded,
|
|
@@ -5,29 +5,21 @@ import { HttpApiSecurity } from "effect/http-api";
|
|
|
5
5
|
|
|
6
6
|
import { Workspace, WorkspaceNotFound } from "../workspaces/Workspaces.js";
|
|
7
7
|
|
|
8
|
-
/** What a verified operator key can name. */
|
|
9
8
|
export interface KeyOperator {
|
|
10
9
|
readonly id: string;
|
|
11
10
|
readonly trusted: false;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
/** What only a host supplies, on its own console. */
|
|
15
13
|
export interface TrustedOperator {
|
|
16
14
|
readonly id: string;
|
|
17
15
|
readonly trusted: true;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
/**
|
|
21
|
-
* The operators' identity, another audience than the members: its own service, its own
|
|
22
|
-
* descriptor, its own port. Typed in two parts, so the trusted one cannot arrive over the wire.
|
|
23
|
-
*/
|
|
24
18
|
export class Operator extends Context.Service<
|
|
25
19
|
Operator,
|
|
26
20
|
KeyOperator | TrustedOperator
|
|
27
21
|
>()("tracker/Operator") {}
|
|
28
22
|
|
|
29
|
-
// How a remote operator proves it: an API key in a header, a native scheme named by
|
|
30
|
-
// `security`. A key cannot step up, and has no OAuth discovery.
|
|
31
23
|
export const OperatorKey = Authentication.make(
|
|
32
24
|
"tracker.OperatorKey",
|
|
33
25
|
Operator,
|
|
@@ -36,7 +28,6 @@ export const OperatorKey = Authentication.make(
|
|
|
36
28
|
}
|
|
37
29
|
);
|
|
38
30
|
|
|
39
|
-
// What the two actions on one workspace share, their input and success included.
|
|
40
31
|
const onWorkspace = {
|
|
41
32
|
caller: Operator,
|
|
42
33
|
input: { workspace: Schema.String },
|