@gjermundgaraba/effect-actions 0.22.0 → 0.24.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 +9 -3
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -0
- package/dist/ActionCli.d.mts +1 -1
- package/dist/ActionCli.mjs +1 -2
- package/dist/ActionHttp.d.mts +2 -2
- package/dist/ActionMcp.d.mts +20 -20
- package/dist/ActionMcp.mjs +9 -11
- 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 +1 -26
- 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-failures.md +1 -1
- package/docs/ActionHttp.md +0 -28
- package/docs/ActionMcp-failures.md +2 -1
- 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-failures.md +1 -1
- package/docs/Testing.md +3 -13
- package/docs/Webhook.md +0 -46
- package/docs/setup-failures.md +1 -1
- package/docs/setup.md +5 -10
- 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 +6 -6
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
2
2
|
import { Context, Schema } from "effect";
|
|
3
3
|
|
|
4
|
-
/** A teammate: what a sign-in can name. The assistant acts for one in each turn. */
|
|
5
4
|
export interface Member {
|
|
6
5
|
readonly kind: "member";
|
|
7
6
|
readonly id: string;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Whoever runs the machine. Only a host builds one, in its own code: nothing that turns a
|
|
12
|
-
* credential into a caller is typed to return it, so no token can claim to be the operator.
|
|
13
|
-
*/
|
|
14
9
|
export interface Operator {
|
|
15
10
|
readonly kind: "operator";
|
|
16
11
|
readonly id: string;
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
/**
|
|
20
|
-
* Who is calling. A protected action declares it, `caller: CurrentCaller`. Nothing here
|
|
21
|
-
* authenticates anyone: the host provides it around each call, as the member a model acts for
|
|
22
|
-
* or as the operator at the terminal.
|
|
23
|
-
*/
|
|
24
14
|
export class CurrentCaller extends Context.Service<
|
|
25
15
|
CurrentCaller,
|
|
26
16
|
Member | Operator
|
|
@@ -5,16 +5,12 @@ import { CurrentCaller } from "./Identity.js";
|
|
|
5
5
|
import { Permissions } from "./permissions.js";
|
|
6
6
|
import type { Permission } from "./permissions.js";
|
|
7
7
|
|
|
8
|
-
// The one rule, for a model's tool call and for a command alike. The permission store is a
|
|
9
|
-
// startup service, so this Effect gets it; the caller differs per call, so the function it
|
|
10
|
-
// returns reads it.
|
|
11
8
|
export const authorize = Effect.gen(function* () {
|
|
12
9
|
const permissions = yield* Permissions;
|
|
13
10
|
|
|
14
11
|
return Effect.fn("authorize")(function* (action: Action.Any) {
|
|
15
12
|
const caller = yield* CurrentCaller;
|
|
16
13
|
|
|
17
|
-
// The operator is trusted, and has no entry in the store. Only a host can name one.
|
|
18
14
|
if (caller.kind === "operator") {
|
|
19
15
|
return;
|
|
20
16
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Member } from "./Identity.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
// `Member`. Typed as members alone: no entry, and so no sign-in, can be the operator.
|
|
5
|
-
export const members = {
|
|
3
|
+
export const demoMembers = {
|
|
6
4
|
ada: { kind: "member", id: "ada" },
|
|
7
5
|
grace: { kind: "member", id: "grace" },
|
|
8
6
|
guest: { kind: "member", id: "guest" },
|
|
@@ -2,10 +2,6 @@ import { Context, Effect, Layer } from "effect";
|
|
|
2
2
|
|
|
3
3
|
export type Permission = "tasks:read" | "tasks:write";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* What each member may do. Permissions are kept here, not in the identity, so changing one
|
|
7
|
-
* takes effect on the member's next call.
|
|
8
|
-
*/
|
|
9
5
|
export class Permissions extends Context.Service<
|
|
10
6
|
Permissions,
|
|
11
7
|
{
|
|
@@ -14,7 +10,6 @@ export class Permissions extends Context.Service<
|
|
|
14
10
|
) => Effect.Effect<readonly Permission[]>;
|
|
15
11
|
}
|
|
16
12
|
>()("assistant/Permissions") {
|
|
17
|
-
// DEMO ONLY: a fixed table. A real application reads its database or its directory.
|
|
18
13
|
static readonly layerMemory = Layer.sync(Permissions, () => {
|
|
19
14
|
const table = new Map<string, readonly Permission[]>([
|
|
20
15
|
["ada", ["tasks:read", "tasks:write"]],
|
|
@@ -8,11 +8,7 @@ import { Task } from "../tasks/Tasks.js";
|
|
|
8
8
|
|
|
9
9
|
const TasksFile = Schema.fromJsonString(Schema.Array(Task));
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
// process, by the store's lock, but nothing locks the file across processes: the agent and a
|
|
13
|
-
// command writing at once lose a task. A real application uses a database. The agent and the
|
|
14
|
-
// commands are separate processes: this file is what lets one see what the other wrote.
|
|
15
|
-
export const tasksFile = Layer.effect(
|
|
11
|
+
export const demoTasksFile = Layer.effect(
|
|
16
12
|
TaskStore,
|
|
17
13
|
Effect.gen(function* () {
|
|
18
14
|
const files = yield* FileSystem.FileSystem;
|
|
@@ -32,7 +28,6 @@ export const tasksFile = Layer.effect(
|
|
|
32
28
|
const save = (tasks: readonly Task[]) =>
|
|
33
29
|
Schema.encodeEffect(TasksFile)(tasks).pipe(
|
|
34
30
|
Effect.flatMap((json) => files.writeFileString(file, json)),
|
|
35
|
-
// A log, not a result: a command sends its handler's logs to stderr.
|
|
36
31
|
Effect.tap(() => Effect.log(`Saved ${tasks.length} tasks to ${file}.`)),
|
|
37
32
|
Effect.orDie
|
|
38
33
|
);
|
|
@@ -2,10 +2,6 @@ import { Effect, Layer, Ref, Stream } from "effect";
|
|
|
2
2
|
import { LanguageModel } from "effect/ai";
|
|
3
3
|
import type { Response } from "effect/ai";
|
|
4
4
|
|
|
5
|
-
// DEMO ONLY: a model that needs no API key. It answers its first request with the first reply
|
|
6
|
-
// it was given, its second with the second, whatever the prompt says, and with nothing once
|
|
7
|
-
// they run out. It stands exactly where a provider's model layer goes, such as
|
|
8
|
-
// `OpenAiLanguageModel.model(...)` of `@effect/ai-openai`.
|
|
9
5
|
export const scripted = (
|
|
10
6
|
...replies: ReadonlyArray<readonly Response.PartEncoded[]>
|
|
11
7
|
) =>
|
|
@@ -14,7 +14,6 @@ export const Task = Schema.Struct({
|
|
|
14
14
|
|
|
15
15
|
export type Task = typeof Task.Type;
|
|
16
16
|
|
|
17
|
-
// A declared error is part of the contract.
|
|
18
17
|
export class TaskNotFound extends Schema.TaggedError<
|
|
19
18
|
TaskNotFound,
|
|
20
19
|
{ readonly brand: unique symbol }
|
|
@@ -22,7 +21,6 @@ export class TaskNotFound extends Schema.TaggedError<
|
|
|
22
21
|
id: Schema.String,
|
|
23
22
|
}) {}
|
|
24
23
|
|
|
25
|
-
// A field's description is what a model reads beside the tool, and the flag's help text.
|
|
26
24
|
const Id = Schema.String.annotate({
|
|
27
25
|
description: "The id listed beside the task.",
|
|
28
26
|
});
|
|
@@ -6,9 +6,6 @@ import { CurrentCaller } from "../identity/Identity.js";
|
|
|
6
6
|
import { TaskStore } from "./store.js";
|
|
7
7
|
import { Tasks } from "./Tasks.js";
|
|
8
8
|
|
|
9
|
-
// The builder gets the store. `CurrentCaller` is read per call. No handler knows whether a model
|
|
10
|
-
// or a person at a terminal called it, and none checks a permission: `authorize` has run before
|
|
11
|
-
// it.
|
|
12
9
|
export const tasks = Action.implement(
|
|
13
10
|
Tasks,
|
|
14
11
|
Effect.gen(function* () {
|
|
@@ -5,14 +5,10 @@ import { TaskNotFound } from "./Tasks.js";
|
|
|
5
5
|
|
|
6
6
|
type TaskList = readonly Task[];
|
|
7
7
|
|
|
8
|
-
// Every method reads the whole list, and a change writes it back: a layer says only where the
|
|
9
|
-
// list is kept, in memory below or in a file (src/platform/tasks-file.ts).
|
|
10
8
|
const make = (
|
|
11
9
|
load: Effect.Effect<TaskList>,
|
|
12
10
|
save: (tasks: TaskList) => Effect.Effect<void>
|
|
13
11
|
) => {
|
|
14
|
-
// A model's tool calls in one turn run concurrently. Two changes reading the list before
|
|
15
|
-
// either writes it would lose one, so a change holds this lock from its read to its write.
|
|
16
12
|
const lock = Semaphore.makeUnsafe(1);
|
|
17
13
|
|
|
18
14
|
const change = Effect.fn("TaskStore.change")(function* (
|
|
@@ -61,7 +57,6 @@ const make = (
|
|
|
61
57
|
});
|
|
62
58
|
};
|
|
63
59
|
|
|
64
|
-
/** The team's tasks. Its methods require nothing: a layer captures where the tasks are kept. */
|
|
65
60
|
export class TaskStore extends Context.Service<
|
|
66
61
|
TaskStore,
|
|
67
62
|
{
|
|
@@ -78,10 +73,8 @@ export class TaskStore extends Context.Service<
|
|
|
78
73
|
) => Effect.Effect<Task, TaskNotFound>;
|
|
79
74
|
}
|
|
80
75
|
>()("assistant/TaskStore") {
|
|
81
|
-
/** The store over a list kept by `load` and `save`, each change serialized. */
|
|
82
76
|
static readonly make = make;
|
|
83
77
|
|
|
84
|
-
/** Memory, lost with the process: what a test provides. */
|
|
85
78
|
static readonly layerMemory = Layer.effect(
|
|
86
79
|
TaskStore,
|
|
87
80
|
Effect.map(Ref.make<TaskList>([]), (tasks) =>
|
|
@@ -7,12 +7,7 @@ import { CurrentCaller } from "./identity/Identity.js";
|
|
|
7
7
|
import type { Member } from "./identity/Identity.js";
|
|
8
8
|
import { tasks } from "./tasks/handlers.js";
|
|
9
9
|
|
|
10
|
-
// `actions.layer` holds the handlers, and requires the startup services their builders read;
|
|
11
|
-
// neither it nor `actions.toolkit` holds a caller.
|
|
12
10
|
const actions = ActionToolkit.make([tasks, identity], {
|
|
13
|
-
// One rule over every call a model makes, asked before the call runs. A read runs at once. A
|
|
14
|
-
// write waits for a person to approve it, except a task the caller adds to their own list:
|
|
15
|
-
// `call.name` narrows `call.input` to that action's. Without a caller, it asks.
|
|
16
11
|
needsApproval: (call) =>
|
|
17
12
|
!call.action.readOnly &&
|
|
18
13
|
Effect.map(
|
|
@@ -25,8 +20,6 @@ const actions = ActionToolkit.make([tasks, identity], {
|
|
|
25
20
|
),
|
|
26
21
|
});
|
|
27
22
|
|
|
28
|
-
// A title for this assistant's approval display. The model still calls the tool `addTask`.
|
|
29
|
-
// The later definition wins; annotating the generated tool keeps its handler and approval rule.
|
|
30
23
|
export const toolkit = Toolkit.merge(
|
|
31
24
|
actions.toolkit,
|
|
32
25
|
Toolkit.make(actions.toolkit.tools.addTask.annotate(Tool.Title, "Add a task"))
|
|
@@ -34,9 +27,5 @@ export const toolkit = Toolkit.merge(
|
|
|
34
27
|
|
|
35
28
|
export const { layer } = actions;
|
|
36
29
|
|
|
37
|
-
// One toolkit serves every member, so who a turn runs as is provided around that turn. This is
|
|
38
|
-
// how this example names a model's caller, and it takes a `Member`. The tools themselves accept
|
|
39
|
-
// any `CurrentCaller`, so keeping the operator away from a model is this function's doing, and
|
|
40
|
-
// that of every host using it.
|
|
41
30
|
export const actingFor = (member: Member) =>
|
|
42
31
|
Effect.provideService(CurrentCaller, member);
|
|
@@ -10,15 +10,10 @@ import type { Operator } from "../src/identity/Identity.js";
|
|
|
10
10
|
import { Permissions } from "../src/identity/permissions.js";
|
|
11
11
|
import { TaskStore } from "../src/tasks/store.js";
|
|
12
12
|
|
|
13
|
-
// What the commands add to the implementations: their syntax and what they print. The services
|
|
14
|
-
// are provided around a test, not on the command as cli.ts does, so the commands of one test
|
|
15
|
-
// share one store in memory.
|
|
16
13
|
const services = Layer.mergeAll(TaskStore.layerMemory, Permissions.layerMemory);
|
|
17
14
|
|
|
18
15
|
const operator: Operator = { kind: "operator", id: "root" };
|
|
19
16
|
|
|
20
|
-
// Effect's own runner, given arguments instead of the process's, and stdin the text given here.
|
|
21
|
-
// The console of `it.effect` keeps every line printed, so a run returns the lines it added.
|
|
22
17
|
const run = (args: readonly string[], stdin = "") =>
|
|
23
18
|
Effect.gen(function* () {
|
|
24
19
|
const before = (yield* TestConsole.logLines).length;
|
|
@@ -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(
|