@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
|
@@ -5,7 +5,7 @@ import { Effect, Ref } from "effect";
|
|
|
5
5
|
import { identity } from "../../src/identity/handlers.js";
|
|
6
6
|
import { CurrentCaller } from "../../src/identity/Identity.js";
|
|
7
7
|
import type { Member, Operator } from "../../src/identity/Identity.js";
|
|
8
|
-
import {
|
|
8
|
+
import { demoMembers } from "../../src/identity/members.js";
|
|
9
9
|
import { Permissions } from "../../src/identity/permissions.js";
|
|
10
10
|
import type { Permission } from "../../src/identity/permissions.js";
|
|
11
11
|
|
|
@@ -19,7 +19,7 @@ describe("identity, in process", () => {
|
|
|
19
19
|
Effect.gen(function* () {
|
|
20
20
|
const client = yield* Action.client(identity);
|
|
21
21
|
|
|
22
|
-
expect(yield* client.whoAmI().pipe(as(
|
|
22
|
+
expect(yield* client.whoAmI().pipe(as(demoMembers.ada))).toStrictEqual({
|
|
23
23
|
id: "ada",
|
|
24
24
|
kind: "member",
|
|
25
25
|
});
|
|
@@ -34,8 +34,6 @@ describe("identity, in process", () => {
|
|
|
34
34
|
Effect.gen(function* () {
|
|
35
35
|
const granted = yield* Ref.make<readonly Permission[]>([]);
|
|
36
36
|
|
|
37
|
-
// The store is a startup service, so it is provided where the client is acquired: the
|
|
38
|
-
// authorizer is built there. No call is given it again.
|
|
39
37
|
const client = yield* Action.client(identity).pipe(
|
|
40
38
|
Effect.provideService(
|
|
41
39
|
Permissions,
|
|
@@ -43,14 +41,16 @@ describe("identity, in process", () => {
|
|
|
43
41
|
)
|
|
44
42
|
);
|
|
45
43
|
|
|
46
|
-
const refusal = yield* Effect.flip(
|
|
44
|
+
const refusal = yield* Effect.flip(
|
|
45
|
+
client.whoAmI().pipe(as(demoMembers.ada))
|
|
46
|
+
);
|
|
47
47
|
|
|
48
48
|
expect(refusal).toBeInstanceOf(Action.Forbidden);
|
|
49
49
|
expect(refusal.message).toBe("Requires tasks:read.");
|
|
50
50
|
|
|
51
51
|
yield* Ref.set(granted, ["tasks:read"]);
|
|
52
52
|
|
|
53
|
-
expect(yield* client.whoAmI().pipe(as(
|
|
53
|
+
expect(yield* client.whoAmI().pipe(as(demoMembers.ada))).toStrictEqual({
|
|
54
54
|
id: "ada",
|
|
55
55
|
kind: "member",
|
|
56
56
|
});
|
|
@@ -2,12 +2,9 @@ import { NodeServices } from "@effect/platform-node";
|
|
|
2
2
|
import { describe, expect, it } from "@effect/vitest";
|
|
3
3
|
import { ConfigProvider, Effect, FileSystem, Layer, Path } from "effect";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { demoTasksFile } from "../../src/platform/tasks-file.js";
|
|
6
6
|
import { TaskStore } from "../../src/tasks/store.js";
|
|
7
7
|
|
|
8
|
-
// The file store, on a file of the test's own: `ASSISTANT_TASKS` is set through a
|
|
9
|
-
// `ConfigProvider`, as the environment sets it for an entrypoint. The directory is removed
|
|
10
|
-
// with the test's scope.
|
|
11
8
|
const fileStore = Effect.gen(function* () {
|
|
12
9
|
const files = yield* FileSystem.FileSystem;
|
|
13
10
|
const path = yield* Path.Path;
|
|
@@ -15,7 +12,7 @@ const fileStore = Effect.gen(function* () {
|
|
|
15
12
|
const tasks = path.join(directory, "tasks.json");
|
|
16
13
|
const config = ConfigProvider.fromUnknown({ ASSISTANT_TASKS: tasks });
|
|
17
14
|
|
|
18
|
-
return
|
|
15
|
+
return demoTasksFile.pipe(Layer.provide(ConfigProvider.layer(config)));
|
|
19
16
|
});
|
|
20
17
|
|
|
21
18
|
describe("the file store", () => {
|
|
@@ -54,7 +51,6 @@ describe("the file store", () => {
|
|
|
54
51
|
tasks.list(undefined)
|
|
55
52
|
);
|
|
56
53
|
|
|
57
|
-
// `local` builds the layer anew for each, as each run of the agent or of a command does.
|
|
58
54
|
const task = yield* add.pipe(Effect.provide(store, { local: true }));
|
|
59
55
|
|
|
60
56
|
expect(
|
|
@@ -4,20 +4,17 @@ import { Effect, Layer } from "effect";
|
|
|
4
4
|
|
|
5
5
|
import { CurrentCaller } from "../../src/identity/Identity.js";
|
|
6
6
|
import type { Member, Operator } from "../../src/identity/Identity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { demoMembers } from "../../src/identity/members.js";
|
|
8
8
|
import { Permissions } from "../../src/identity/permissions.js";
|
|
9
9
|
import { tasks } from "../../src/tasks/handlers.js";
|
|
10
10
|
import { TaskStore } from "../../src/tasks/store.js";
|
|
11
11
|
import { TaskNotFound } from "../../src/tasks/Tasks.js";
|
|
12
12
|
|
|
13
|
-
// What the implementation does, with no model and no command line: `Action.client` runs the
|
|
14
|
-
// same decoding, `authorize` and handler every surface runs. Each call names its caller.
|
|
15
13
|
const as = (caller: Member | Operator) =>
|
|
16
14
|
Effect.provideService(CurrentCaller, caller);
|
|
17
15
|
|
|
18
16
|
const operator: Operator = { kind: "operator", id: "root" };
|
|
19
17
|
|
|
20
|
-
// A test supplies its services as an entrypoint does: here the store is memory.
|
|
21
18
|
const services = Layer.mergeAll(TaskStore.layerMemory, Permissions.layerMemory);
|
|
22
19
|
|
|
23
20
|
describe("tasks, in process", () => {
|
|
@@ -27,21 +24,23 @@ describe("tasks, in process", () => {
|
|
|
27
24
|
|
|
28
25
|
yield* client
|
|
29
26
|
.addTask({ title: "Book the venue", assignee: "ada" })
|
|
30
|
-
.pipe(as(
|
|
27
|
+
.pipe(as(demoMembers.ada));
|
|
31
28
|
yield* client
|
|
32
29
|
.addTask({ title: "Send invitations", assignee: "grace" })
|
|
33
30
|
.pipe(as(operator));
|
|
34
31
|
|
|
35
32
|
const { tasks: listed } = yield* client
|
|
36
33
|
.listTasks()
|
|
37
|
-
.pipe(as(
|
|
34
|
+
.pipe(as(demoMembers.grace));
|
|
38
35
|
|
|
39
36
|
expect(listed.map(({ id, addedBy }) => [id, addedBy])).toStrictEqual([
|
|
40
37
|
["1", "ada"],
|
|
41
38
|
["2", "root"],
|
|
42
39
|
]);
|
|
43
40
|
expect(
|
|
44
|
-
yield* client
|
|
41
|
+
yield* client
|
|
42
|
+
.listTasks({ assignee: "grace" })
|
|
43
|
+
.pipe(as(demoMembers.grace))
|
|
45
44
|
).toMatchObject({
|
|
46
45
|
tasks: [{ title: "Send invitations" }],
|
|
47
46
|
});
|
|
@@ -55,15 +54,15 @@ describe("tasks, in process", () => {
|
|
|
55
54
|
const client = yield* Action.client(tasks);
|
|
56
55
|
const add = client.addTask({ title: "Order lunch", assignee: "guest" });
|
|
57
56
|
|
|
58
|
-
const refusal = yield* Effect.flip(add.pipe(as(
|
|
57
|
+
const refusal = yield* Effect.flip(add.pipe(as(demoMembers.guest)));
|
|
59
58
|
|
|
60
59
|
expect(refusal).toBeInstanceOf(Action.Forbidden);
|
|
61
60
|
expect(refusal.message).toBe("Requires tasks:write.");
|
|
62
|
-
expect(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
61
|
+
expect(
|
|
62
|
+
yield* client.listTasks().pipe(as(demoMembers.guest))
|
|
63
|
+
).toStrictEqual({
|
|
64
|
+
tasks: [],
|
|
65
|
+
});
|
|
67
66
|
}).pipe(Effect.provide(services))
|
|
68
67
|
);
|
|
69
68
|
|
|
@@ -94,7 +93,7 @@ describe("tasks, in process", () => {
|
|
|
94
93
|
const annotate = client.annotateTask({ id: "9", notes: "Urgent." });
|
|
95
94
|
|
|
96
95
|
expect(
|
|
97
|
-
yield* Effect.flip(annotate.pipe(as(
|
|
96
|
+
yield* Effect.flip(annotate.pipe(as(demoMembers.ada)))
|
|
98
97
|
).toStrictEqual(new TaskNotFound({ id: "9" }));
|
|
99
98
|
}).pipe(Effect.provide(services))
|
|
100
99
|
);
|
|
@@ -3,21 +3,18 @@ import { Effect, Layer, Stream } from "effect";
|
|
|
3
3
|
import { Chat, LanguageModel } from "effect/ai";
|
|
4
4
|
|
|
5
5
|
import type { Member } from "../src/identity/Identity.js";
|
|
6
|
-
import {
|
|
6
|
+
import { demoMembers } from "../src/identity/members.js";
|
|
7
7
|
import { Permissions } from "../src/identity/permissions.js";
|
|
8
8
|
import { scripted } from "../src/scripted.js";
|
|
9
9
|
import { TaskStore } from "../src/tasks/store.js";
|
|
10
10
|
import { actingFor, layer, toolkit } from "../src/toolkit.js";
|
|
11
11
|
|
|
12
|
-
// What the toolkit adds to the implementations: a caller per call, and a model's approvals.
|
|
13
|
-
// The handlers run in this process, on a store in memory the tests can read too.
|
|
14
12
|
const tools = layer.pipe(
|
|
15
13
|
Layer.provideMerge(
|
|
16
14
|
Layer.mergeAll(TaskStore.layerMemory, Permissions.layerMemory)
|
|
17
15
|
)
|
|
18
16
|
);
|
|
19
17
|
|
|
20
|
-
// A model's call of `addTask`, as a provider sends it.
|
|
21
18
|
const adding = (id: string, assignee: string) =>
|
|
22
19
|
({
|
|
23
20
|
type: "tool-call",
|
|
@@ -26,7 +23,6 @@ const adding = (id: string, assignee: string) =>
|
|
|
26
23
|
params: { title: "Order lunch", assignee },
|
|
27
24
|
}) as const;
|
|
28
25
|
|
|
29
|
-
// Which calls of a turn ran, and which wait for a person.
|
|
30
26
|
const outcome = (
|
|
31
27
|
response: LanguageModel.GenerateTextResponse<typeof toolkit.tools, "opaque">
|
|
32
28
|
) => ({
|
|
@@ -36,7 +32,6 @@ const outcome = (
|
|
|
36
32
|
),
|
|
37
33
|
});
|
|
38
34
|
|
|
39
|
-
// The model answers each member with the same two calls.
|
|
40
35
|
const plan = (member: Member) =>
|
|
41
36
|
LanguageModel.generateText({
|
|
42
37
|
prompt: "Plan the launch.",
|
|
@@ -54,18 +49,15 @@ describe("the toolkit", () => {
|
|
|
54
49
|
Effect.gen(function* () {
|
|
55
50
|
const { handle } = yield* toolkit;
|
|
56
51
|
|
|
57
|
-
// A call by hand, with the JSON arguments a model sends. The member goes around the whole
|
|
58
|
-
// call, the collecting of its results included.
|
|
59
52
|
const add = handle("addTask", {
|
|
60
53
|
title: "Order lunch",
|
|
61
54
|
assignee: "guest",
|
|
62
55
|
}).pipe(Effect.flatMap(Stream.runCollect));
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
expect(yield* add.pipe(actingFor(members.guest))).toMatchObject([
|
|
57
|
+
expect(yield* add.pipe(actingFor(demoMembers.guest))).toMatchObject([
|
|
66
58
|
{ isFailure: true, result: { message: "Requires tasks:write." } },
|
|
67
59
|
]);
|
|
68
|
-
expect(yield* add.pipe(actingFor(
|
|
60
|
+
expect(yield* add.pipe(actingFor(demoMembers.ada))).toMatchObject([
|
|
69
61
|
{ isFailure: false, result: { id: "1", addedBy: "ada" } },
|
|
70
62
|
]);
|
|
71
63
|
}).pipe(Effect.provide(tools))
|
|
@@ -75,16 +67,15 @@ describe("the toolkit", () => {
|
|
|
75
67
|
"asks for approval before a model adds to a list that is not its caller's",
|
|
76
68
|
() =>
|
|
77
69
|
Effect.gen(function* () {
|
|
78
|
-
expect(yield* plan(
|
|
70
|
+
expect(yield* plan(demoMembers.ada)).toStrictEqual({
|
|
79
71
|
ran: ["for ada"],
|
|
80
72
|
waiting: ["for grace"],
|
|
81
73
|
});
|
|
82
|
-
expect(yield* plan(
|
|
74
|
+
expect(yield* plan(demoMembers.grace)).toStrictEqual({
|
|
83
75
|
ran: ["for grace"],
|
|
84
76
|
waiting: ["for ada"],
|
|
85
77
|
});
|
|
86
78
|
|
|
87
|
-
// A call that waits has not run.
|
|
88
79
|
const store = yield* TaskStore;
|
|
89
80
|
|
|
90
81
|
expect(
|
|
@@ -97,16 +88,14 @@ describe("the toolkit", () => {
|
|
|
97
88
|
"authorizes an approved call too: approval lets no one do what they may not",
|
|
98
89
|
() =>
|
|
99
90
|
Effect.gen(function* () {
|
|
100
|
-
// The `Chat` keeps the request in its history, which the answer is matched against.
|
|
101
91
|
const chat = yield* Chat.empty;
|
|
102
92
|
|
|
103
93
|
const asked = yield* chat
|
|
104
94
|
.generateText({ prompt: "Add lunch to Ada's list.", toolkit })
|
|
105
|
-
.pipe(actingFor(
|
|
95
|
+
.pipe(actingFor(demoMembers.guest));
|
|
106
96
|
|
|
107
97
|
expect(outcome(asked)).toStrictEqual({ ran: [], waiting: ["for ada"] });
|
|
108
98
|
|
|
109
|
-
// The approved call runs in the turn that carries the answer, as that turn's caller.
|
|
110
99
|
const answered = yield* chat
|
|
111
100
|
.generateText({
|
|
112
101
|
prompt: [
|
|
@@ -127,7 +116,7 @@ describe("the toolkit", () => {
|
|
|
127
116
|
],
|
|
128
117
|
toolkit,
|
|
129
118
|
})
|
|
130
|
-
.pipe(actingFor(
|
|
119
|
+
.pipe(actingFor(demoMembers.guest));
|
|
131
120
|
|
|
132
121
|
expect(answered.toolResults).toMatchObject([
|
|
133
122
|
{
|
|
@@ -13,6 +13,8 @@ BUILDS_TOKEN=grace PUBLIC_URL=https://<a tunnel to port 3001> node --import tsx
|
|
|
13
13
|
vp test examples/build-events
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
`WEBHOOKS_DIR` (default `.build-events/webhooks`) is where the server keeps webhook subscriptions, so a restart goes on delivering them. Its files hold each subscriber's secret: give the directory to that server alone, one directory per server process, since the server is the store's only writer.
|
|
17
|
+
|
|
16
18
|
## Layout
|
|
17
19
|
|
|
18
20
|
```text
|
|
@@ -10,9 +10,6 @@ import {
|
|
|
10
10
|
import { DeployRequested, RequestDeploy } from "./deploys/Deploys.js";
|
|
11
11
|
import { Login } from "./identity/Identity.js";
|
|
12
12
|
|
|
13
|
-
// The HTTP binding: each action at `POST /api/<name>`, and each event at
|
|
14
|
-
// `POST /api/events/<name>`, which answers a page of JSON, or, asked for `text/event-stream`,
|
|
15
|
-
// holds a stream open. It imports no server code, so a client imports it with the contracts.
|
|
16
13
|
export const Http = ActionHttp.make(
|
|
17
14
|
[
|
|
18
15
|
FinishBuild,
|
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
import { DeployRequested, RequestDeploy } from "./deploys/Deploys.js";
|
|
11
11
|
import { Login } from "./identity/Identity.js";
|
|
12
12
|
|
|
13
|
-
// The RPC binding: each action an rpc named after it, and each event a stream rpc named after
|
|
14
|
-
// it, which pushes each occurrence as the server reads it. Plain data, as the HTTP binding is.
|
|
15
13
|
export const Rpc = ActionRpc.make(
|
|
16
14
|
[
|
|
17
15
|
FinishBuild,
|
|
@@ -20,8 +20,6 @@ export const Build = Schema.Struct({
|
|
|
20
20
|
|
|
21
21
|
export type Build = typeof Build.Type;
|
|
22
22
|
|
|
23
|
-
// DEMO ONLY: a CI runner reports finished builds; here a member does, so the example can
|
|
24
|
-
// cause the event it watches.
|
|
25
23
|
export const FinishBuild = Action.make("finishBuild", {
|
|
26
24
|
description: "Record that a build of a pipeline finished.",
|
|
27
25
|
input: { pipeline: Pipeline, status: Status },
|
|
@@ -30,10 +28,6 @@ export const FinishBuild = Action.make("finishBuild", {
|
|
|
30
28
|
caller: CurrentMember,
|
|
31
29
|
});
|
|
32
30
|
|
|
33
|
-
// A build run here, which reports each step as it starts, before it answers how the build ended.
|
|
34
|
-
// A caller reads the steps only if it asks, with `onProgress`; each surface carries them its
|
|
35
|
-
// own way. They are a snapshot to show: a caller falling behind misses some, never the answer.
|
|
36
|
-
// What a caller must see every time is the answer, or `build.finished`, which this build causes.
|
|
37
31
|
export const StartBuild = Action.make("startBuild", {
|
|
38
32
|
description:
|
|
39
33
|
"Run a build of a pipeline, reporting each step, and record how it ended.",
|
|
@@ -54,16 +48,11 @@ export const StartBuild = Action.make("startBuild", {
|
|
|
54
48
|
caller: CurrentMember,
|
|
55
49
|
});
|
|
56
50
|
|
|
57
|
-
// A build this member may not see is not found, as one that never ran: its id tells nothing.
|
|
58
51
|
export class BuildNotFound extends Schema.TaggedError<
|
|
59
52
|
BuildNotFound,
|
|
60
53
|
{ readonly brand: unique symbol }
|
|
61
54
|
>()("BuildNotFound", { buildId: Schema.String }, { httpApiStatus: 404 }) {}
|
|
62
55
|
|
|
63
|
-
// An action answering a stream: its handler returns a `Stream` of lines, and every client's
|
|
64
|
-
// call returns one, each line arriving as the server sends it. HTTP, RPC and a command carry a
|
|
65
|
-
// stream; an MCP tool answers one result, the lines collected once the stream ends, so the MCP
|
|
66
|
-
// endpoint in `routes.ts` leaves it out rather than put a whole log in a model's context.
|
|
67
56
|
export const TailLog = Action.make("tailLog", {
|
|
68
57
|
description: "Stream a build's log, line by line.",
|
|
69
58
|
input: {
|
|
@@ -77,8 +66,6 @@ export const TailLog = Action.make("tailLog", {
|
|
|
77
66
|
caller: CurrentMember,
|
|
78
67
|
});
|
|
79
68
|
|
|
80
|
-
// An event type: what a subscription takes, what each occurrence carries, and who may
|
|
81
|
-
// subscribe. Like an action's contract, it imports no server code.
|
|
82
69
|
export const BuildFinished = Event.make("build.finished", {
|
|
83
70
|
description: "A build of a pipeline you may see finished.",
|
|
84
71
|
input: {
|
|
@@ -93,8 +80,6 @@ export const BuildFinished = Event.make("build.finished", {
|
|
|
93
80
|
caller: CurrentMember,
|
|
94
81
|
});
|
|
95
82
|
|
|
96
|
-
// An event whose occurrence is the whole value: how a pipeline's last build ended, `null` before
|
|
97
|
-
// its first. A subscriber is sent it as it is, then again each time a build of it finishes.
|
|
98
83
|
export const PipelineStatus = Event.make("pipeline.status", {
|
|
99
84
|
description:
|
|
100
85
|
"How a pipeline's last build ended: first as it is, then each time one finishes.",
|
|
@@ -5,9 +5,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
5
5
|
import { BuildFinished } from "./Builds.js";
|
|
6
6
|
import { BuildStore } from "./store.js";
|
|
7
7
|
|
|
8
|
-
// A check source: one function answers "what finished since this cursor?" for every
|
|
9
|
-
// subscriber, whether it polls or holds a stream open, on every surface. The builder runs once,
|
|
10
|
-
// at startup; the check runs per subscriber, as that subscriber.
|
|
11
8
|
export const buildEvents = Event.implement(
|
|
12
9
|
BuildFinished,
|
|
13
10
|
Effect.gen(function* () {
|
|
@@ -18,8 +15,6 @@ export const buildEvents = Event.implement(
|
|
|
18
15
|
Effect.gen(function* () {
|
|
19
16
|
const member = yield* CurrentMember;
|
|
20
17
|
|
|
21
|
-
// A first subscription asks with `null`: the store answers the current position, so
|
|
22
|
-
// the subscriber starts from now.
|
|
23
18
|
const page = yield* store.finishedSince(
|
|
24
19
|
member.pipelines,
|
|
25
20
|
cursor,
|
|
@@ -29,7 +24,6 @@ export const buildEvents = Event.implement(
|
|
|
29
24
|
return {
|
|
30
25
|
cursor: page.cursor,
|
|
31
26
|
hasMore: page.hasMore,
|
|
32
|
-
// A cursor the store cannot resume from: the subscriber is sent a gap first.
|
|
33
27
|
truncated: page.truncated,
|
|
34
28
|
events: page.builds
|
|
35
29
|
.filter(
|
|
@@ -38,9 +32,6 @@ export const buildEvents = Event.implement(
|
|
|
38
32
|
.filter(
|
|
39
33
|
(build) => status === undefined || build.status === status
|
|
40
34
|
)
|
|
41
|
-
// The store's own id, within its epoch: a subscriber that sees a build twice,
|
|
42
|
-
// after a reconnect, drops the second, and never drops a build of a restarted store
|
|
43
|
-
// as one it saw before.
|
|
44
35
|
.map((build) => ({
|
|
45
36
|
eventId: `${page.epoch}/${build.id}`,
|
|
46
37
|
data: build,
|
|
@@ -49,6 +40,5 @@ export const buildEvents = Event.implement(
|
|
|
49
40
|
}),
|
|
50
41
|
};
|
|
51
42
|
}),
|
|
52
|
-
// Every member may watch; which builds each sees is the store's check, by pipeline.
|
|
53
43
|
{ authorize: Event.allowAll }
|
|
54
44
|
);
|
|
@@ -11,8 +11,6 @@ import {
|
|
|
11
11
|
import type { Build } from "./Builds.js";
|
|
12
12
|
import { BuildStore } from "./store.js";
|
|
13
13
|
|
|
14
|
-
// DEMO ONLY: each step passes at once. A runner's steps take their time, which is why a caller
|
|
15
|
-
// wants to see them.
|
|
16
14
|
const steps = ["install", "build", "test"];
|
|
17
15
|
|
|
18
16
|
export const builds = Action.implement(
|
|
@@ -21,9 +19,6 @@ export const builds = Action.implement(
|
|
|
21
19
|
const store = yield* BuildStore;
|
|
22
20
|
const events = yield* Event.Events;
|
|
23
21
|
|
|
24
|
-
// `build.finished` is a check source over the store: write the build there first, then wake
|
|
25
|
-
// its subscribers, who read it now rather than at their next poll. `pipeline.status` is a
|
|
26
|
-
// current source: the notify moves its pipeline's revision, so its subscribers alone read it.
|
|
27
22
|
const finished = (build: Effect.Effect<Build>) =>
|
|
28
23
|
Effect.tap(build, ({ pipeline }) =>
|
|
29
24
|
Effect.andThen(
|
|
@@ -35,7 +30,6 @@ export const builds = Action.implement(
|
|
|
35
30
|
return {
|
|
36
31
|
finishBuild: ({ pipeline, status }) =>
|
|
37
32
|
finished(store.finish(pipeline, status, [status])),
|
|
38
|
-
// `progress` never waits for the caller: the build runs at its own pace.
|
|
39
33
|
startBuild: ({ pipeline }, { progress }) =>
|
|
40
34
|
Effect.andThen(
|
|
41
35
|
Effect.forEach(
|
|
@@ -10,21 +10,15 @@ export const logs = Action.implement(
|
|
|
10
10
|
Effect.gen(function* () {
|
|
11
11
|
const store = yield* BuildStore;
|
|
12
12
|
|
|
13
|
-
// The handler returns a `Stream`, run in a scope of its own that closes when the caller
|
|
14
|
-
// stops reading, so what it acquires is released then.
|
|
15
13
|
return ({ buildId }) =>
|
|
16
14
|
Stream.unwrap(
|
|
17
15
|
Effect.gen(function* () {
|
|
18
16
|
const member = yield* CurrentMember;
|
|
19
|
-
// A failure before the first line, `BuildNotFound` here, fails the call as an action
|
|
20
|
-
// answering one value fails, a 404 over HTTP; one after a line ends the stream, the
|
|
21
|
-
// lines before it already read.
|
|
22
17
|
const log = yield* store.logOf(member.pipelines, buildId);
|
|
23
18
|
|
|
24
19
|
return Stream.fromIterable(log.map((line) => ({ line })));
|
|
25
20
|
})
|
|
26
21
|
);
|
|
27
22
|
}),
|
|
28
|
-
// Which builds a member may read is the store's check, by pipeline.
|
|
29
23
|
{ authorize: Action.allowAll }
|
|
30
24
|
);
|
|
@@ -5,9 +5,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
5
5
|
import { PipelineStatus } from "./Builds.js";
|
|
6
6
|
import { BuildStore } from "./store.js";
|
|
7
7
|
|
|
8
|
-
// A current source: the value as it is, which the library sends first and again after each
|
|
9
|
-
// notify reaching the subscriber's key, keeping the revision that tells them apart, so the store
|
|
10
|
-
// keeps no cursor for it. The key is the pipeline: a build of another wakes no one here.
|
|
11
8
|
export const statusEvents = Event.implement(
|
|
12
9
|
PipelineStatus,
|
|
13
10
|
Effect.gen(function* () {
|
|
@@ -23,6 +20,5 @@ export const statusEvents = Event.implement(
|
|
|
23
20
|
key: ({ pipeline }) => pipeline,
|
|
24
21
|
};
|
|
25
22
|
}),
|
|
26
|
-
// Every member may watch; which pipelines each sees is the store's check.
|
|
27
23
|
{ authorize: Event.allowAll }
|
|
28
24
|
);
|
|
@@ -3,19 +3,14 @@ import { Context, Effect, Layer } from "effect";
|
|
|
3
3
|
import { BuildNotFound } from "./Builds.js";
|
|
4
4
|
import type { Build } from "./Builds.js";
|
|
5
5
|
|
|
6
|
-
/** One page of the builds finished since a cursor. */
|
|
7
6
|
export interface Finished {
|
|
8
7
|
readonly builds: readonly Build[];
|
|
9
8
|
readonly cursor: string;
|
|
10
9
|
readonly hasMore: boolean;
|
|
11
|
-
/** Whether builds before the page may be missing: the cursor was not one of this store's. */
|
|
12
10
|
readonly truncated: boolean;
|
|
13
|
-
/** The store's epoch: a build's id is unique within it, and a restarted memory store starts another. */
|
|
14
11
|
readonly epoch: string;
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
// The position a cursor of `epoch` names, among `length` builds; none for another epoch's cursor
|
|
18
|
-
// or one that is not a cursor at all.
|
|
19
14
|
const positionOf = (
|
|
20
15
|
epoch: string,
|
|
21
16
|
cursor: string,
|
|
@@ -32,45 +27,29 @@ const positionOf = (
|
|
|
32
27
|
: undefined;
|
|
33
28
|
};
|
|
34
29
|
|
|
35
|
-
/**
|
|
36
|
-
* Where finished builds are recorded, in the order they finished. Which pipelines a member may
|
|
37
|
-
* see is checked here, in the data access, so no subscription can skip it.
|
|
38
|
-
*/
|
|
39
30
|
export class BuildStore extends Context.Service<
|
|
40
31
|
BuildStore,
|
|
41
32
|
{
|
|
42
|
-
/** Record a build that finished, with the lines its log holds. */
|
|
43
33
|
readonly finish: (
|
|
44
34
|
pipeline: string,
|
|
45
35
|
status: Build["status"],
|
|
46
36
|
log: readonly string[]
|
|
47
37
|
) => Effect.Effect<Build>;
|
|
48
|
-
/** The log of build `buildId`, which must be one of `pipelines`. */
|
|
49
38
|
readonly logOf: (
|
|
50
39
|
pipelines: readonly string[],
|
|
51
40
|
buildId: string
|
|
52
41
|
) => Effect.Effect<readonly string[], BuildNotFound>;
|
|
53
|
-
/**
|
|
54
|
-
* The builds of `pipelines` finished after `cursor`, at most `limit`; a `null` cursor is
|
|
55
|
-
* the current position, with none.
|
|
56
|
-
*/
|
|
57
42
|
readonly finishedSince: (
|
|
58
43
|
pipelines: readonly string[],
|
|
59
44
|
cursor: string | null,
|
|
60
45
|
limit: number
|
|
61
46
|
) => Effect.Effect<Finished>;
|
|
62
|
-
/** How `pipeline`'s last build ended, `null` before any did or where it is not of `pipelines`. */
|
|
63
47
|
readonly statusOf: (
|
|
64
48
|
pipelines: readonly string[],
|
|
65
49
|
pipeline: string
|
|
66
50
|
) => Effect.Effect<Build["status"] | null>;
|
|
67
51
|
}
|
|
68
52
|
>()("build-events/BuildStore") {
|
|
69
|
-
// DEMO ONLY: builds live in this process's memory, so a restart forgets them and numbers them
|
|
70
|
-
// from 1 again. Its cursors carry an epoch of their own, so one from before the restart, or one
|
|
71
|
-
// it never gave, is answered from the start as `truncated`: the subscriber is sent a gap, never
|
|
72
|
-
// a silent loss. In a database the cursor is the position in its own change feed, such as a
|
|
73
|
-
// sequence column, so a subscriber resumes after a restart.
|
|
74
53
|
static readonly layerMemory = Layer.sync(BuildStore, () => {
|
|
75
54
|
const epoch = crypto.randomUUID();
|
|
76
55
|
const finished: Build[] = [];
|
|
@@ -9,8 +9,6 @@ import { Command } from "effect/cli";
|
|
|
9
9
|
|
|
10
10
|
import { commands } from "./commands.js";
|
|
11
11
|
|
|
12
|
-
// Entrypoint: `BUILDS_TOKEN=grace node --import tsx examples/build-events/src/cli.ts watch
|
|
13
|
-
// build.finished`, with server.ts running.
|
|
14
12
|
Command.run(commands, { version: "1.0.0" }).pipe(
|
|
15
13
|
Effect.provide([NodeHttpClient.layerUndici, NodeServices.layer]),
|
|
16
14
|
ActionCli.logToStderr,
|
|
@@ -5,8 +5,6 @@ import { HttpClient, HttpClientRequest } from "effect/http";
|
|
|
5
5
|
|
|
6
6
|
import { Http } from "./Api.js";
|
|
7
7
|
|
|
8
|
-
// The binding's client, connected to where the server is and as which member, both read from
|
|
9
|
-
// config when a command runs.
|
|
10
8
|
const api = Effect.gen(function* () {
|
|
11
9
|
const baseUrl = yield* Config.String("BUILDS_URL").pipe(
|
|
12
10
|
Config.withDefault("http://127.0.0.1:3000")
|
|
@@ -22,11 +20,4 @@ const api = Effect.gen(function* () {
|
|
|
22
20
|
});
|
|
23
21
|
});
|
|
24
22
|
|
|
25
|
-
// A command per action, and `watch <event>` per event type: `builds watch build.finished
|
|
26
|
-
// --pipeline api` holds the event's stream open and prints each occurrence as a line of JSON,
|
|
27
|
-
// its `cursor` included, until it is stopped. `--cursor <cursor>` resumes after that line;
|
|
28
|
-
// omitted, the watch starts from now. The lines pipe into `jq` or a script as they come.
|
|
29
|
-
// `builds start-build --pipeline api` prints each step as a line of JSON on stderr as it
|
|
30
|
-
// starts, and the build on stdout, which a pipe reads alone. `builds tail-log --build-id
|
|
31
|
-
// build-1` prints each line of its log as a line of JSON as it arrives.
|
|
32
23
|
export const commands = ActionCli.remote(Http, { name: "builds", client: api });
|
|
@@ -3,11 +3,9 @@ import type { Scope } from "effect";
|
|
|
3
3
|
|
|
4
4
|
import type { Environment } from "./Deploys.js";
|
|
5
5
|
|
|
6
|
-
/** Who stands by to approve deploys, and to which environment. */
|
|
7
6
|
export class Approvers extends Context.Service<
|
|
8
7
|
Approvers,
|
|
9
8
|
{
|
|
10
|
-
/** Stands `member` by to approve deploys to `environment`, every one where undefined, until the scope closes. */
|
|
11
9
|
readonly standBy: (
|
|
12
10
|
environment: Environment | undefined,
|
|
13
11
|
member: string
|
|
@@ -17,7 +15,6 @@ export class Approvers extends Context.Service<
|
|
|
17
15
|
) => Effect.Effect<readonly string[]>;
|
|
18
16
|
}
|
|
19
17
|
>()("build-events/Approvers") {
|
|
20
|
-
// DEMO ONLY: approvers live in this process's memory, where a real one is a rota in a store.
|
|
21
18
|
static readonly layerMemory = Layer.sync(Approvers, () => {
|
|
22
19
|
const approvers: Array<{
|
|
23
20
|
readonly environment: Environment | undefined;
|
|
@@ -5,11 +5,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
5
5
|
import { Approvers } from "./approvers.js";
|
|
6
6
|
import { DeployRequested } from "./Deploys.js";
|
|
7
7
|
|
|
8
|
-
// A log source, for occurrences nothing else keeps: the library keeps each one `requestDeploy`
|
|
9
|
-
// publishes, for 10 minutes and at most 10,000 of them by default, and gives each subscriber
|
|
10
|
-
// what its `match` accepts. A subscriber resuming from a cursor gets what the log still holds:
|
|
11
|
-
// after a restart, or once its occurrences are dropped, a gap first. An upstream you can ask
|
|
12
|
-
// "what since?", such as a table, is a check source.
|
|
13
8
|
export const deployEvents = Event.implement(
|
|
14
9
|
DeployRequested,
|
|
15
10
|
Effect.gen(function* () {
|
|
@@ -19,9 +14,6 @@ export const deployEvents = Event.implement(
|
|
|
19
14
|
log: {},
|
|
20
15
|
match: ({ environment }, deploy) =>
|
|
21
16
|
environment === undefined || deploy.environment === environment,
|
|
22
|
-
// Set up while each subscription lasts, as the subscriber: a stream's as long as it is
|
|
23
|
-
// read, a poll's until 5 minutes after its last poll. It may run again for one
|
|
24
|
-
// subscription, after a restart, so standing by twice must be harmless.
|
|
25
17
|
subscription: ({ environment }) =>
|
|
26
18
|
Effect.flatMap(CurrentMember, (member) =>
|
|
27
19
|
approvers.standBy(environment, member.id)
|
|
@@ -24,8 +24,6 @@ export const deploys = Action.implement(
|
|
|
24
24
|
approvers: yield* approvers.standingBy(environment),
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// Nothing else keeps a deploy request, so `deploy.requested` is a log source: the
|
|
28
|
-
// library keeps what is published here, and delivers it to each subscriber at once.
|
|
29
27
|
yield* events.publish(DeployRequested, {
|
|
30
28
|
eventId: deploy.id,
|
|
31
29
|
data: deploy,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as Authentication from "@gjermundgaraba/effect-actions/Authentication";
|
|
2
2
|
import { Context, Schema } from "effect";
|
|
3
3
|
|
|
4
|
-
/** A member, and the pipelines whose builds it may see. */
|
|
5
4
|
export const Member = Schema.Struct({
|
|
6
5
|
id: Schema.String,
|
|
7
6
|
pipelines: Schema.Array(Schema.String),
|
|
@@ -9,20 +8,10 @@ export const Member = Schema.Struct({
|
|
|
9
8
|
|
|
10
9
|
export type Member = typeof Member.Type;
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* Who is subscribing or calling. Every event and action here declares it, `caller:
|
|
14
|
-
* CurrentMember`; authentication provides it per request.
|
|
15
|
-
*/
|
|
16
11
|
export class CurrentMember extends Context.Service<CurrentMember, Member>()(
|
|
17
12
|
"build-events/CurrentMember"
|
|
18
13
|
) {}
|
|
19
14
|
|
|
20
|
-
// How a remote caller proves it is a member: a bearer token. Clients import this descriptor
|
|
21
|
-
// with the contracts; its verifier stays on the server. `principal` names a member as one
|
|
22
|
-
// subscriber: a poll arrives as a request among others, and a surface keys what it holds
|
|
23
|
-
// between polls, deploy.requested's standing by, by it. Without it, MCP and HTTP refuse to
|
|
24
|
-
// serve that event, and no event is offered by webhook. `schema` keeps a webhook subscriber's
|
|
25
|
-
// identity, so the deliveries a restart restores run as that member.
|
|
26
15
|
export const Login = Authentication.make("build-events.Login", CurrentMember, {
|
|
27
16
|
principal: (member) => member.id,
|
|
28
17
|
schema: Member,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Member } from "./Identity.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
export const members = {
|
|
3
|
+
export const demoMembers = {
|
|
5
4
|
ada: { id: "ada", pipelines: ["api", "web"] },
|
|
6
5
|
grace: { id: "grace", pipelines: ["web"] },
|
|
7
6
|
} as const satisfies Readonly<Record<string, Member>>;
|