@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
package/docs/Authentication.md
CHANGED
|
@@ -30,8 +30,6 @@ export class CurrentUser extends Context.Service<CurrentUser, User>()(
|
|
|
30
30
|
"notes-service/CurrentUser"
|
|
31
31
|
) {}
|
|
32
32
|
|
|
33
|
-
// How a remote caller proves it is CurrentUser: a bearer token, the default scheme. Clients
|
|
34
|
-
// import this descriptor with the binding; its verifier, in verifier.ts, stays on the server.
|
|
35
33
|
export const Login = Authentication.make("notes-service.Login", CurrentUser);
|
|
36
34
|
|
|
37
35
|
export const WhoAmI = Action.make("whoAmI", {
|
|
@@ -56,27 +54,21 @@ import * as Authentication from "@gjermundgaraba/effect-actions/Authentication";
|
|
|
56
54
|
import { Config, Effect, Redacted } from "effect";
|
|
57
55
|
|
|
58
56
|
import { Login, scopes } from "./Identity.js";
|
|
59
|
-
import {
|
|
57
|
+
import { demoUsers } from "./users.js";
|
|
60
58
|
|
|
61
|
-
const isToken = (token: string): token is keyof typeof
|
|
62
|
-
Object.hasOwn(
|
|
59
|
+
const isToken = (token: string): token is keyof typeof demoUsers =>
|
|
60
|
+
Object.hasOwn(demoUsers, token);
|
|
63
61
|
|
|
64
|
-
// DEMO ONLY: a token is a user's name. A real verifier checks a signed token with your
|
|
65
|
-
// authorization server's library, its audience included. An unknown token is the built-in
|
|
66
|
-
// `Unauthenticated`: a 401 every client decodes.
|
|
67
62
|
const verify = (token: Redacted.Redacted) => {
|
|
68
63
|
const name = Redacted.value(token);
|
|
69
64
|
|
|
70
65
|
return isToken(name)
|
|
71
|
-
? Effect.succeed(
|
|
66
|
+
? Effect.succeed(demoUsers[name])
|
|
72
67
|
: Effect.fail(
|
|
73
68
|
new Action.Unauthenticated({ message: "Unknown demo token." })
|
|
74
69
|
);
|
|
75
70
|
};
|
|
76
71
|
|
|
77
|
-
// Server only: `Login`'s provider. As an OAuth protected resource it also publishes discovery,
|
|
78
|
-
// so an MCP client that gets a 401 finds where to sign in, asking for read first. The resource
|
|
79
|
-
// is the server's public URL, known only at startup, so it is read from config.
|
|
80
72
|
export const authenticate = Authentication.layer(Login, verify, {
|
|
81
73
|
protectedResource: Effect.map(
|
|
82
74
|
Config.String("PUBLIC_URL").pipe(
|
|
@@ -85,7 +77,6 @@ export const authenticate = Authentication.layer(Login, verify, {
|
|
|
85
77
|
(url) =>
|
|
86
78
|
({
|
|
87
79
|
resource: `${url}/mcp`,
|
|
88
|
-
// DEMO ONLY: no server is there. Yours is your authorization server's issuer.
|
|
89
80
|
authorizationServers: ["https://auth.example.com"],
|
|
90
81
|
scopesSupported: [scopes.read, scopes.write],
|
|
91
82
|
scopesRequired: [scopes.read],
|
package/docs/Event.md
CHANGED
|
@@ -31,8 +31,6 @@ export const Build = Schema.Struct({
|
|
|
31
31
|
|
|
32
32
|
export type Build = typeof Build.Type;
|
|
33
33
|
|
|
34
|
-
// DEMO ONLY: a CI runner reports finished builds; here a member does, so the example can
|
|
35
|
-
// cause the event it watches.
|
|
36
34
|
export const FinishBuild = Action.make("finishBuild", {
|
|
37
35
|
description: "Record that a build of a pipeline finished.",
|
|
38
36
|
input: { pipeline: Pipeline, status: Status },
|
|
@@ -41,10 +39,6 @@ export const FinishBuild = Action.make("finishBuild", {
|
|
|
41
39
|
caller: CurrentMember,
|
|
42
40
|
});
|
|
43
41
|
|
|
44
|
-
// A build run here, which reports each step as it starts, before it answers how the build ended.
|
|
45
|
-
// A caller reads the steps only if it asks, with `onProgress`; each surface carries them its
|
|
46
|
-
// own way. They are a snapshot to show: a caller falling behind misses some, never the answer.
|
|
47
|
-
// What a caller must see every time is the answer, or `build.finished`, which this build causes.
|
|
48
42
|
export const StartBuild = Action.make("startBuild", {
|
|
49
43
|
description:
|
|
50
44
|
"Run a build of a pipeline, reporting each step, and record how it ended.",
|
|
@@ -65,16 +59,11 @@ export const StartBuild = Action.make("startBuild", {
|
|
|
65
59
|
caller: CurrentMember,
|
|
66
60
|
});
|
|
67
61
|
|
|
68
|
-
// A build this member may not see is not found, as one that never ran: its id tells nothing.
|
|
69
62
|
export class BuildNotFound extends Schema.TaggedError<
|
|
70
63
|
BuildNotFound,
|
|
71
64
|
{ readonly brand: unique symbol }
|
|
72
65
|
>()("BuildNotFound", { buildId: Schema.String }, { httpApiStatus: 404 }) {}
|
|
73
66
|
|
|
74
|
-
// An action answering a stream: its handler returns a `Stream` of lines, and every client's
|
|
75
|
-
// call returns one, each line arriving as the server sends it. HTTP, RPC and a command carry a
|
|
76
|
-
// stream; an MCP tool answers one result, the lines collected once the stream ends, so the MCP
|
|
77
|
-
// endpoint in `routes.ts` leaves it out rather than put a whole log in a model's context.
|
|
78
67
|
export const TailLog = Action.make("tailLog", {
|
|
79
68
|
description: "Stream a build's log, line by line.",
|
|
80
69
|
input: {
|
|
@@ -88,8 +77,6 @@ export const TailLog = Action.make("tailLog", {
|
|
|
88
77
|
caller: CurrentMember,
|
|
89
78
|
});
|
|
90
79
|
|
|
91
|
-
// An event type: what a subscription takes, what each occurrence carries, and who may
|
|
92
|
-
// subscribe. Like an action's contract, it imports no server code.
|
|
93
80
|
export const BuildFinished = Event.make("build.finished", {
|
|
94
81
|
description: "A build of a pipeline you may see finished.",
|
|
95
82
|
input: {
|
|
@@ -104,8 +91,6 @@ export const BuildFinished = Event.make("build.finished", {
|
|
|
104
91
|
caller: CurrentMember,
|
|
105
92
|
});
|
|
106
93
|
|
|
107
|
-
// An event whose occurrence is the whole value: how a pipeline's last build ended, `null` before
|
|
108
|
-
// its first. A subscriber is sent it as it is, then again each time a build of it finishes.
|
|
109
94
|
export const PipelineStatus = Event.make("pipeline.status", {
|
|
110
95
|
description:
|
|
111
96
|
"How a pipeline's last build ended: first as it is, then each time one finishes.",
|
|
@@ -133,9 +118,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
133
118
|
import { BuildFinished } from "./Builds.js";
|
|
134
119
|
import { BuildStore } from "./store.js";
|
|
135
120
|
|
|
136
|
-
// A check source: one function answers "what finished since this cursor?" for every
|
|
137
|
-
// subscriber, whether it polls or holds a stream open, on every surface. The builder runs once,
|
|
138
|
-
// at startup; the check runs per subscriber, as that subscriber.
|
|
139
121
|
export const buildEvents = Event.implement(
|
|
140
122
|
BuildFinished,
|
|
141
123
|
Effect.gen(function* () {
|
|
@@ -146,8 +128,6 @@ export const buildEvents = Event.implement(
|
|
|
146
128
|
Effect.gen(function* () {
|
|
147
129
|
const member = yield* CurrentMember;
|
|
148
130
|
|
|
149
|
-
// A first subscription asks with `null`: the store answers the current position, so
|
|
150
|
-
// the subscriber starts from now.
|
|
151
131
|
const page = yield* store.finishedSince(
|
|
152
132
|
member.pipelines,
|
|
153
133
|
cursor,
|
|
@@ -157,7 +137,6 @@ export const buildEvents = Event.implement(
|
|
|
157
137
|
return {
|
|
158
138
|
cursor: page.cursor,
|
|
159
139
|
hasMore: page.hasMore,
|
|
160
|
-
// A cursor the store cannot resume from: the subscriber is sent a gap first.
|
|
161
140
|
truncated: page.truncated,
|
|
162
141
|
events: page.builds
|
|
163
142
|
.filter(
|
|
@@ -166,9 +145,6 @@ export const buildEvents = Event.implement(
|
|
|
166
145
|
.filter(
|
|
167
146
|
(build) => status === undefined || build.status === status
|
|
168
147
|
)
|
|
169
|
-
// The store's own id, within its epoch: a subscriber that sees a build twice,
|
|
170
|
-
// after a reconnect, drops the second, and never drops a build of a restarted store
|
|
171
|
-
// as one it saw before.
|
|
172
148
|
.map((build) => ({
|
|
173
149
|
eventId: `${page.epoch}/${build.id}`,
|
|
174
150
|
data: build,
|
|
@@ -177,7 +153,6 @@ export const buildEvents = Event.implement(
|
|
|
177
153
|
}),
|
|
178
154
|
};
|
|
179
155
|
}),
|
|
180
|
-
// Every member may watch; which builds each sees is the store's check, by pipeline.
|
|
181
156
|
{ authorize: Event.allowAll }
|
|
182
157
|
);
|
|
183
158
|
```
|
|
@@ -200,9 +175,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
200
175
|
import { PipelineStatus } from "./Builds.js";
|
|
201
176
|
import { BuildStore } from "./store.js";
|
|
202
177
|
|
|
203
|
-
// A current source: the value as it is, which the library sends first and again after each
|
|
204
|
-
// notify reaching the subscriber's key, keeping the revision that tells them apart, so the store
|
|
205
|
-
// keeps no cursor for it. The key is the pipeline: a build of another wakes no one here.
|
|
206
178
|
export const statusEvents = Event.implement(
|
|
207
179
|
PipelineStatus,
|
|
208
180
|
Effect.gen(function* () {
|
|
@@ -218,7 +190,6 @@ export const statusEvents = Event.implement(
|
|
|
218
190
|
key: ({ pipeline }) => pipeline,
|
|
219
191
|
};
|
|
220
192
|
}),
|
|
221
|
-
// Every member may watch; which pipelines each sees is the store's check.
|
|
222
193
|
{ authorize: Event.allowAll }
|
|
223
194
|
);
|
|
224
195
|
```
|
|
@@ -237,11 +208,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
237
208
|
import { Approvers } from "./approvers.js";
|
|
238
209
|
import { DeployRequested } from "./Deploys.js";
|
|
239
210
|
|
|
240
|
-
// A log source, for occurrences nothing else keeps: the library keeps each one `requestDeploy`
|
|
241
|
-
// publishes, for 10 minutes and at most 10,000 of them by default, and gives each subscriber
|
|
242
|
-
// what its `match` accepts. A subscriber resuming from a cursor gets what the log still holds:
|
|
243
|
-
// after a restart, or once its occurrences are dropped, a gap first. An upstream you can ask
|
|
244
|
-
// "what since?", such as a table, is a check source.
|
|
245
211
|
export const deployEvents = Event.implement(
|
|
246
212
|
DeployRequested,
|
|
247
213
|
Effect.gen(function* () {
|
|
@@ -251,9 +217,6 @@ export const deployEvents = Event.implement(
|
|
|
251
217
|
log: {},
|
|
252
218
|
match: ({ environment }, deploy) =>
|
|
253
219
|
environment === undefined || deploy.environment === environment,
|
|
254
|
-
// Set up while each subscription lasts, as the subscriber: a stream's as long as it is
|
|
255
|
-
// read, a poll's until 5 minutes after its last poll. It may run again for one
|
|
256
|
-
// subscription, after a restart, so standing by twice must be harmless.
|
|
257
220
|
subscription: ({ environment }) =>
|
|
258
221
|
Effect.flatMap(CurrentMember, (member) =>
|
|
259
222
|
approvers.standBy(environment, member.id)
|
package/docs/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
**Arriving with an error?** A message the library throws says its fix; for any other, step 5.
|
|
8
8
|
|
|
9
9
|
1. **Open one page per tool call, with your file-reading tool.** Pages are kept small to reduce truncation. Several in one call, however many commands it runs, can be cut by its output limit, with no mark or with one that understates what is lost. If an output says it was truncated, read that page again alone.
|
|
10
|
-
2. **Start from the example closest to what you are building** ([Examples](#examples)). Its README has a layout tree, and all but quickstart's a "Where to look" table naming the file for each thing. Copy its layout and idioms: the examples are the reference for how code is written, and its
|
|
10
|
+
2. **Start from the example closest to what you are building** ([Examples](#examples)). Its README has a layout tree, and all but quickstart's a "Where to look" table naming the file for each thing. Copy its layout and idioms: the examples are the reference for how code is written, and its code carries the traps it shows. An example shows one way, not the rules or the alternatives: read steps 3 and 4 even when it fits.
|
|
11
11
|
3. **Read [Action.md](Action.md) completely.** Every surface builds on it.
|
|
12
12
|
4. **Read the page of each surface you serve** ([Pages](#pages)), and the example files its task sections link.
|
|
13
13
|
5. **For a compiler diagnostic or Effect's own error, search the `*-failures.md` pages** for a fragment of the message without quotes, your own code's first compile error included: `grep -rnF "<fragment>" node_modules/@gjermundgaraba/effect-actions/docs/*-failures.md`. Each module page has one beside it, such as [Action-failures.md](Action-failures.md).
|
package/docs/Testing-failures.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
What you see when something is wrong, and the fix. Search for a fragment of the message. A missing service's error can start `… with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined'`: search a line beneath it, `is missing the following properties from type 'Scope'`, instead. The tasks are in [Testing.md](Testing.md).
|
|
4
4
|
|
|
5
|
-
- A route answers an empty 500, which a client method reports as `HttpClientError: Decode
|
|
5
|
+
- A route answers an empty 500, which a client method reports as `HttpClientError: Decode: undeclared status code (500 …)`: a defect, or a result that does not encode. `Testing.layer(routes)` logs its cause on the process console, under `it.effect` too: read the test's output, or collect it with a `Logger` provided around the layer.
|
|
6
6
|
- `Type 'Provider<CurrentUser, "notes-service.Login">' is missing the following properties from type 'Scope'` at `it.effect`, or `… is not assignable to type 'never'` at `Effect.runPromise`: the routes serve a protected action without a provider of its descriptor. Provide the real one or a test verifier to the routes; a caller provided around `Testing.layer` does not satisfy them.
|
|
7
7
|
- `Type 'CurrentUser' is missing the following properties from type 'Scope'` at `it.effect`, or `… is not assignable to type 'never'` at `Effect.runPromise`: the test still owes the identity. An `Action.client` call of a protected action takes its caller per call: provide it around the call. Or a public action's handler reads the identity, which no route provides to it: make the action protected. Or, where the caller is provided already, a builder yields it: move that `yield*` into the handler ([Action-failures.md](Action-failures.md#where-an-implementation-is-served)).
|
|
8
8
|
- `Type '<Service>' is missing the following properties from type 'Scope'` at every `it.effect`, for a service that is no identity, such as a store, a limiter or a `LanguageModel`: a builder now yields it, and the routes require it. Provide its layer to `Testing.layer(routes)`, as the entrypoint provides it to the server.
|
package/docs/Testing.md
CHANGED
|
@@ -14,16 +14,13 @@ import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
|
14
14
|
import { Effect } from "effect";
|
|
15
15
|
|
|
16
16
|
import { CurrentUser } from "../../src/identity/Identity.js";
|
|
17
|
-
import {
|
|
17
|
+
import { demoUsers } from "../../src/identity/users.js";
|
|
18
18
|
import { notes } from "../../src/notes/handlers.js";
|
|
19
19
|
import { NoteNotFound } from "../../src/notes/Notes.js";
|
|
20
20
|
import { NoteStore } from "../../src/notes/store.js";
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// provides it per request.
|
|
25
|
-
const as = (user: keyof typeof users) =>
|
|
26
|
-
Effect.provideService(CurrentUser, users[user]);
|
|
22
|
+
const as = (user: keyof typeof demoUsers) =>
|
|
23
|
+
Effect.provideService(CurrentUser, demoUsers[user]);
|
|
27
24
|
|
|
28
25
|
describe("notes, in process", () => {
|
|
29
26
|
it.effect("keeps each user's notes their own", () =>
|
|
@@ -94,7 +91,6 @@ import { Http } from "../src/Api.js";
|
|
|
94
91
|
import { Greet } from "../src/greeting/Greeting.js";
|
|
95
92
|
import { routes } from "../src/routes.js";
|
|
96
93
|
|
|
97
|
-
// The routes answer in memory: no port, and the same code the server runs.
|
|
98
94
|
it.effect("greets over HTTP and as an MCP tool", () =>
|
|
99
95
|
Effect.gen(function* () {
|
|
100
96
|
const http = yield* ActionHttp.client(Http);
|
|
@@ -152,14 +148,12 @@ it.effect(
|
|
|
152
148
|
"delivers each build a member may see as it finishes, as the subscription selects",
|
|
153
149
|
() =>
|
|
154
150
|
Effect.gen(function* () {
|
|
155
|
-
// One client holds both: the action that finishes builds and the event that reports them.
|
|
156
151
|
const client = yield* Action.client([builds, buildEvents]);
|
|
157
152
|
|
|
158
153
|
const failed = yield* client
|
|
159
154
|
.watch(BuildFinished, { status: "failed" })
|
|
160
155
|
.pipe(Stream.take(1), Stream.runCollect, as("grace"), Effect.forkChild);
|
|
161
156
|
|
|
162
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
163
157
|
yield* TestClock.adjust("0 millis");
|
|
164
158
|
yield* client
|
|
165
159
|
.finishBuild({ pipeline: "api", status: "failed" })
|
|
@@ -167,12 +161,10 @@ it.effect(
|
|
|
167
161
|
yield* client
|
|
168
162
|
.finishBuild({ pipeline: "web", status: "passed" })
|
|
169
163
|
.pipe(as("ada"));
|
|
170
|
-
// Each build finished notifies: the watch reads at once, with no wait for its next poll.
|
|
171
164
|
yield* client
|
|
172
165
|
.finishBuild({ pipeline: "web", status: "failed" })
|
|
173
166
|
.pipe(as("ada"));
|
|
174
167
|
|
|
175
|
-
// grace sees only the web pipeline, and asked only for failures.
|
|
176
168
|
expect(yield* Fiber.join(failed)).toMatchObject([
|
|
177
169
|
{
|
|
178
170
|
_tag: "Occurrence",
|
|
@@ -192,8 +184,6 @@ it.effect(
|
|
|
192
184
|
.finishBuild({ pipeline: "web", status: "passed" })
|
|
193
185
|
.pipe(as("ada"));
|
|
194
186
|
|
|
195
|
-
// A cursor of the store before a restart, its offset one this store has too: what it named
|
|
196
|
-
// is gone, so the watch is told.
|
|
197
187
|
const resumed = yield* client
|
|
198
188
|
.watch(BuildFinished, {}, { cursor: "an-earlier-epoch:0" })
|
|
199
189
|
.pipe(Stream.take(2), Stream.runCollect, as("grace"));
|
package/docs/Webhook.md
CHANGED
|
@@ -27,7 +27,6 @@ import { Login } from "./identity/Identity.js";
|
|
|
27
27
|
import { authenticate } from "./identity/verifier.js";
|
|
28
28
|
import { Rpc } from "./Rpc.js";
|
|
29
29
|
|
|
30
|
-
// Every domain's implementation, once: the events beside the actions, in one list.
|
|
31
30
|
const implementations = [
|
|
32
31
|
builds,
|
|
33
32
|
logs,
|
|
@@ -37,17 +36,6 @@ const implementations = [
|
|
|
37
36
|
deployEvents,
|
|
38
37
|
];
|
|
39
38
|
|
|
40
|
-
// The actions as MCP tools and the events as MCP events, at `/mcp`. A client polls with
|
|
41
|
-
// `events/poll`, or holds `events/stream` open and is pushed each occurrence. Both events are
|
|
42
|
-
// protected, so each request needs a member's token, and each subscriber sees what its token
|
|
43
|
-
// lets it. This long-lived process holds the deploy event's `subscription` hook between polls and
|
|
44
|
-
// its log in memory, and pushes each occurrence: a `requestScoped` endpoint would serve the events
|
|
45
|
-
// by poll and webhook alone, and a serverless host, where no process lasts, check sources alone,
|
|
46
|
-
// without `Webhook.layer`.
|
|
47
|
-
//
|
|
48
|
-
// A tool answers one result, so `tailLog` would collect a whole log before answering, all of it
|
|
49
|
-
// in a model's context: its implementation, `logs`, is left out, and the endpoint serves every
|
|
50
|
-
// other action and every event.
|
|
51
39
|
const mcp = ActionMcp.layerHttp(
|
|
52
40
|
[builds, buildEvents, statusEvents, deploys, deployEvents],
|
|
53
41
|
{
|
|
@@ -57,25 +45,13 @@ const mcp = ActionMcp.layerHttp(
|
|
|
57
45
|
}
|
|
58
46
|
);
|
|
59
47
|
|
|
60
|
-
// The same implementations as routes under `/api`, for a client that speaks HTTP rather than
|
|
61
|
-
// MCP: one implementation of each event serves every surface.
|
|
62
48
|
const api = ActionHttp.layer(Http, implementations);
|
|
63
49
|
|
|
64
|
-
// And as Effect RPC at `/rpc`, over HTTP. A watch is a stream rpc that never ends, so the
|
|
65
|
-
// serialization frames each element as it is sent: `layerNdjson` does, where `layerJson` would
|
|
66
|
-
// answer once every stream of the request ended, which a watch never does.
|
|
67
50
|
const rpc = ActionRpc.layer(Rpc, implementations).pipe(
|
|
68
51
|
Layer.provide(RpcServer.layerProtocolHttp({ path: "/rpc" })),
|
|
69
52
|
Layer.provide(RpcSerialization.layerNdjson)
|
|
70
53
|
);
|
|
71
54
|
|
|
72
|
-
// Webhook delivery for MCP and HTTP alike: a member names a callback URL and a secret, with
|
|
73
|
-
// MCP's `events/subscribe` or `POST /api/events/<name>/subscribe`, and each occurrence it may see
|
|
74
|
-
// is POSTed there, signed. One layer holds the subscriptions of both, so either surface refreshes
|
|
75
|
-
// one made over the other. `persist` keeps each in a `KeyValueStore`, so a restart goes on
|
|
76
|
-
// delivering from where it reached, as the subscriber `Login`'s `schema` keeps. It needs an
|
|
77
|
-
// `HttpClient` to POST, `Dns` to check where each callback resolves, and the store, which
|
|
78
|
-
// `server.ts` provides.
|
|
79
55
|
export const routes = Layer.mergeAll(mcp, api, rpc).pipe(
|
|
80
56
|
Layer.provide(authenticate),
|
|
81
57
|
Layer.provide(Webhook.layer({ persist: true }))
|
|
@@ -103,12 +79,8 @@ import { Http } from "../src/Api.js";
|
|
|
103
79
|
import { routes } from "../src/routes.js";
|
|
104
80
|
import { inMemory } from "./support/memory.js";
|
|
105
81
|
|
|
106
|
-
// The subscriber's secret: `whsec_` and 24 to 64 random bytes in base64. The server signs each
|
|
107
|
-
// POST with it, and the subscriber checks each POST it receives against it.
|
|
108
82
|
const secret = `whsec_${Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64")}`;
|
|
109
83
|
|
|
110
|
-
// A subscriber's check, as Standard Webhooks defines it: an HMAC-SHA256 of the id, the
|
|
111
|
-
// timestamp and the body exactly as received, among the space-separated `v1,` signatures.
|
|
112
84
|
const signed = async (request: Request, body: string) => {
|
|
113
85
|
const key = await crypto.subtle.importKey(
|
|
114
86
|
"raw",
|
|
@@ -146,8 +118,6 @@ interface Received {
|
|
|
146
118
|
readonly signed: boolean;
|
|
147
119
|
}
|
|
148
120
|
|
|
149
|
-
// grace's server: it answers the verification POST by echoing its challenge, which proves it
|
|
150
|
-
// asked for these deliveries, and acknowledges each delivery with a 2xx.
|
|
151
121
|
const subscriber =
|
|
152
122
|
(received: Queue.Enqueue<Received>) => async (request: Request) => {
|
|
153
123
|
const text = await request.text();
|
|
@@ -201,20 +171,14 @@ describe("the service, by webhook", () => {
|
|
|
201
171
|
),
|
|
202
172
|
});
|
|
203
173
|
|
|
204
|
-
// The answer names the subscription, which each POST's `x-mcp-subscription-id`
|
|
205
|
-
// carries, and when to subscribe again to keep it: one not refreshed by then ends.
|
|
206
174
|
const subscription = yield* subscribe;
|
|
207
175
|
const verification = yield* Queue.take(received);
|
|
208
176
|
|
|
209
177
|
yield* ada.finishBuild({ pipeline: "api", status: "passed" });
|
|
210
|
-
// Each build finished notifies `build.finished`: the server asks the store at once, and
|
|
211
|
-
// POSTs what it answers.
|
|
212
178
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
213
179
|
|
|
214
|
-
// grace sees only the web pipeline.
|
|
215
180
|
const delivery = yield* Queue.take(received);
|
|
216
181
|
|
|
217
|
-
// The same request again refreshes the subscription, and answers how it is going.
|
|
218
182
|
const refreshed = yield* subscribe;
|
|
219
183
|
|
|
220
184
|
expect(verification).toMatchObject({
|
|
@@ -262,12 +226,8 @@ export interface NotifierOptions {
|
|
|
262
226
|
readonly publicUrl: string;
|
|
263
227
|
}
|
|
264
228
|
|
|
265
|
-
// The route build-events POSTs each failed build to, where the watch below reads them: the
|
|
266
|
-
// watch's delivery appends its path to this process's public URL.
|
|
267
229
|
const receiver = Webhook.layerReceiver({ path: "/hooks/builds" });
|
|
268
230
|
|
|
269
|
-
// A second service, the notifier: it watches build.finished for failures by webhook, the
|
|
270
|
-
// server POSTing each to it, rather than holding a stream open to build-events.
|
|
271
231
|
const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
272
232
|
Layer.effectDiscard(
|
|
273
233
|
Effect.gen(function* () {
|
|
@@ -287,8 +247,6 @@ const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
|
287
247
|
{ status: "failed" },
|
|
288
248
|
{
|
|
289
249
|
mode: Webhook.delivery({ baseUrl: publicUrl }),
|
|
290
|
-
// Where it reached is kept, so a restart resumes there; failures the server no
|
|
291
|
-
// longer keeps arrive as a Gap instead.
|
|
292
250
|
resume: {
|
|
293
251
|
store: yield* KeyValueStore.KeyValueStore,
|
|
294
252
|
key: "failed-builds",
|
|
@@ -296,15 +254,11 @@ const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
|
296
254
|
}
|
|
297
255
|
)
|
|
298
256
|
.pipe(
|
|
299
|
-
// A Gap says failures were missed, which no notice can name: it is logged, for an
|
|
300
|
-
// operator to look the builds up.
|
|
301
257
|
Stream.runForEach((received) =>
|
|
302
258
|
Predicate.isTagged(received, "Occurrence")
|
|
303
259
|
? notices.add(received.data)
|
|
304
260
|
: Effect.logWarning("Failed builds were missed", received)
|
|
305
261
|
),
|
|
306
|
-
// A failure no reconnect outlasts, such as a wrong PUBLIC_URL or a revoked token,
|
|
307
|
-
// ends the watch: it is logged here, for a deployment to alert on or restart by.
|
|
308
262
|
Effect.tapCause(Effect.logError)
|
|
309
263
|
)
|
|
310
264
|
);
|
package/docs/setup-failures.md
CHANGED
|
@@ -8,5 +8,5 @@ What you see when something is wrong, and the fix. Search for a fragment of the
|
|
|
8
8
|
- A page that loads Effect from an import map still bundles a second copy of Effect or of some of its modules, or fails to resolve `effect/Schema` in the browser when its bundler externalizes subpaths, as esbuild's `--external:effect` does: a module of the page imports an Effect specifier the map does not serve. Serve the specifiers [Bundle for a browser](setup.md#bundle-for-a-browser) lists, and import Effect through them in the page's own modules too.
|
|
9
9
|
- A page loading Effect from an import map fails with `Failed to resolve module specifier "effect/Cause"` in Chromium: the map points at Effect's published files and lacks a specifier Effect imports itself. Map `effect/Cause`, `effect/Effect`, `effect/Exit` and `effect/Function` to the same files, or serve Effect from a build that resolves its own imports.
|
|
10
10
|
- A page fails at load with `does not provide an export named …`: it serves only the names it uses of an Effect specifier, from a vendored module or a trimmed bundle, and the package imports another. Serve each specifier whole.
|
|
11
|
-
- Type errors inside `effect/*` modules after install, an unmet peer warning for `effect`, such as `found 4.
|
|
11
|
+
- Type errors inside `effect/*` modules after install, an unmet peer warning for `effect`, such as `found 4.2.0`, or a start failing with `Cannot find module '…/effect/dist/…'` under an `@effect/*` package: more than one Effect release is installed, or one outside the peer range. Install the `effect` range [Install](setup.md#install) names, with every `@effect/*` package at the version `effect` resolved to, such as `@effect/platform-node@4.1.1` beside `effect@4.1.1`.
|
|
12
12
|
- `Cannot find module 'effect/unstable/http'` (or `…/httpapi`, `…/cli`, `…/ai`): these modules are now `effect/http`, `effect/http-api`, `effect/cli` and `effect/ai`.
|
package/docs/setup.md
CHANGED
|
@@ -7,20 +7,20 @@ A message the library throws says its fix; for a compiler diagnostic or Effect's
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
pnpm add @gjermundgaraba/effect-actions effect@~4.0
|
|
10
|
+
pnpm add @gjermundgaraba/effect-actions effect@~4.1.0
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
| Need | Add |
|
|
14
14
|
| --- | --- |
|
|
15
|
-
| Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.0
|
|
16
|
-
| Tests | `vitest@^5` and `@effect/vitest@~4.0
|
|
15
|
+
| Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.1.0` |
|
|
16
|
+
| Tests | `vitest@^5` and `@effect/vitest@~4.1.0`, as dev dependencies |
|
|
17
17
|
| Type checking | `typescript@^7.0.2`, as a dev dependency |
|
|
18
18
|
| Node's types, for `node:` imports | `@types/node`, as a dev dependency |
|
|
19
19
|
| Running a TypeScript entrypoint | `tsx`, as a dev dependency: `node --import tsx <entrypoint>.ts` |
|
|
20
20
|
|
|
21
|
-
The `effect` peer admits the 4.
|
|
21
|
+
The `effect` peer admits the 4.1.x patches from the oldest whose APIs the package uses, and no minor release: a minor release may change the unstable Effect modules the surfaces build on.
|
|
22
22
|
|
|
23
|
-
Keep the tilde in `package.json`: `^4.0
|
|
23
|
+
Keep the tilde in `package.json`: `^4.1.0`, which npm writes for `effect@4.1.0`, admits a minor release outside the peer range. `npm install effect@~4.1.0` keeps it.
|
|
24
24
|
|
|
25
25
|
Node `>=26.12.0`: the package's `engines`, the Node the library is developed and tested on. TypeScript 7 or newer. ESM only. The repository checks the examples with a stricter `tsconfig.json`; this is the minimum a project needs. The package's modules resolve only through its `exports`, which `"module": "nodenext"` reads, as a bundler project's `"moduleResolution": "bundler"` does. `"strict": true` is required, by Effect:
|
|
26
26
|
|
|
@@ -53,8 +53,6 @@ One action, served as a JSON route and as an MCP tool: four declarations, each i
|
|
|
53
53
|
import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
54
54
|
import { Schema } from "effect";
|
|
55
55
|
|
|
56
|
-
// A contract: what the action takes and answers, whether it changes anything, and who may
|
|
57
|
-
// call it. It imports no server code, so any client can import it, a browser page included.
|
|
58
56
|
export const Greet = Action.make("greet", {
|
|
59
57
|
description: "Greet someone by name.",
|
|
60
58
|
input: { name: Schema.String },
|
|
@@ -70,7 +68,6 @@ import { Effect } from "effect";
|
|
|
70
68
|
|
|
71
69
|
import { Greet } from "./Greeting.js";
|
|
72
70
|
|
|
73
|
-
// The implementation: the contract bound to its handler. Every surface takes this one value.
|
|
74
71
|
export const greeting = Action.implement(Greet, ({ name }) =>
|
|
75
72
|
Effect.succeed(`Hello, ${name}!`)
|
|
76
73
|
);
|
|
@@ -81,7 +78,6 @@ import * as ActionHttp from "@gjermundgaraba/effect-actions/ActionHttp";
|
|
|
81
78
|
|
|
82
79
|
import { Greet } from "./greeting/Greeting.js";
|
|
83
80
|
|
|
84
|
-
// The HTTP binding: `POST /api/greet`. The server serves it and the client calls it.
|
|
85
81
|
export const Http = ActionHttp.make([Greet]);
|
|
86
82
|
```
|
|
87
83
|
|
|
@@ -93,7 +89,6 @@ import { Layer } from "effect";
|
|
|
93
89
|
import { Http } from "./Api.js";
|
|
94
90
|
import { greeting } from "./greeting/handlers.js";
|
|
95
91
|
|
|
96
|
-
// One implementation, two surfaces: a JSON route and an MCP tool at `/mcp`.
|
|
97
92
|
export const routes = Layer.mergeAll(
|
|
98
93
|
ActionHttp.layer(Http, greeting),
|
|
99
94
|
ActionMcp.layerHttp(greeting, { name: "greetings", version: "1.0.0" })
|
package/examples/README.md
CHANGED
|
@@ -44,4 +44,10 @@ Every example follows one layout, which is the one we recommend for an applicati
|
|
|
44
44
|
|
|
45
45
|
In a monorepo, the contract files and the binding are the package that the server, the CLI and the website all depend on; the rest is the server.
|
|
46
46
|
|
|
47
|
-
Every token, user and store in these examples is a demo. Each place that must change before a deployment
|
|
47
|
+
Every token, user and store in these examples is a demo. Each place that must change before a deployment says so in its name (`demoMembers`, `layerMemory`, `layerDemo`, `fakeFarm`, `scripted`), except these:
|
|
48
|
+
|
|
49
|
+
- build-events' `finishBuild` action, which a member calls where a CI runner would, and its build steps, which pass at once.
|
|
50
|
+
- notes-service's `verify`, which takes a token as a user's name where a real verifier checks a signed token, and its `https://auth.example.com` authorization server, where no server is.
|
|
51
|
+
- notes-service's `stdio.ts`, whose in-memory store holds notes of its own, not the running server's.
|
|
52
|
+
- quickstart's `client.ts`, whose `baseUrl` a deployed client reads from configuration.
|
|
53
|
+
- kitchen-sink's `seed.ts`, which files a first issue in `acme` as `ada`, since the server's stores start empty.
|
|
@@ -4,23 +4,17 @@ import { Chat, Tool } from "effect/ai";
|
|
|
4
4
|
import type { LanguageModel, Prompt } from "effect/ai";
|
|
5
5
|
|
|
6
6
|
import type { Member } from "./identity/Identity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { demoMembers } from "./identity/members.js";
|
|
8
8
|
import { Permissions } from "./identity/permissions.js";
|
|
9
|
-
import {
|
|
9
|
+
import { demoTasksFile } from "./platform/tasks-file.js";
|
|
10
10
|
import { scripted } from "./scripted.js";
|
|
11
11
|
import { actingFor, layer, toolkit } from "./toolkit.js";
|
|
12
12
|
|
|
13
|
-
// Entrypoint: `node --import tsx examples/assistant/src/agent.ts`.
|
|
14
|
-
// A model working on the team's tasks with tools that run in this process: no server and no
|
|
15
|
-
// port. Every tool call passes through the same `authorize` and handlers as the commands.
|
|
16
|
-
|
|
17
|
-
// What a turn answers with: its text, the calls the model made and what they returned.
|
|
18
13
|
type Response = LanguageModel.GenerateTextResponse<
|
|
19
14
|
typeof toolkit.tools,
|
|
20
15
|
"opaque"
|
|
21
16
|
>;
|
|
22
17
|
|
|
23
|
-
// Printing only.
|
|
24
18
|
const report = (member: Member) => (response: Response) => {
|
|
25
19
|
const waiting = new Set(
|
|
26
20
|
response.content.flatMap((part) =>
|
|
@@ -51,33 +45,21 @@ const report = (member: Member) => (response: Response) => {
|
|
|
51
45
|
);
|
|
52
46
|
};
|
|
53
47
|
|
|
54
|
-
// One turn of a conversation: the model reads the prompt and may call tools. The member is
|
|
55
|
-
// provided around the whole turn, so the approval rule, `authorize` and the handlers of every
|
|
56
|
-
// call in it see that member.
|
|
57
48
|
const turn = (chat: Chat.Chat, member: Member, prompt: Prompt.RawInput) =>
|
|
58
49
|
chat
|
|
59
50
|
.generateText({ prompt, toolkit })
|
|
60
51
|
.pipe(actingFor(member), Effect.tap(report(member)));
|
|
61
52
|
|
|
62
53
|
const conversations = Effect.gen(function* () {
|
|
63
|
-
// A `Chat` keeps the conversation's history, and approval depends on it: an answer is matched
|
|
64
|
-
// to its request by `approvalId` in the prompt. The answer alone, sent through a bare
|
|
65
|
-
// `LanguageModel.generateText`, runs nothing. Without a `Chat`, send again the assistant
|
|
66
|
-
// message holding the call and its request, before the answer.
|
|
67
54
|
const withAda = yield* Chat.empty;
|
|
68
55
|
|
|
69
|
-
// Ada's own task is added at once. The task for Grace is not run: the turn ends with a
|
|
70
|
-
// request for approval in place of that call's result.
|
|
71
56
|
const asked = yield* turn(
|
|
72
57
|
withAda,
|
|
73
|
-
|
|
58
|
+
demoMembers.ada,
|
|
74
59
|
"Add the venue for me, invitations for Grace."
|
|
75
60
|
);
|
|
76
61
|
|
|
77
|
-
|
|
78
|
-
// in which an approved call runs before the model is asked again. It runs as whoever that
|
|
79
|
-
// turn runs as, so the host provides the member who was asked: Ada still.
|
|
80
|
-
yield* turn(withAda, members.ada, [
|
|
62
|
+
yield* turn(withAda, demoMembers.ada, [
|
|
81
63
|
{
|
|
82
64
|
role: "tool",
|
|
83
65
|
content: asked.content.flatMap((part) =>
|
|
@@ -94,10 +76,9 @@ const conversations = Effect.gen(function* () {
|
|
|
94
76
|
},
|
|
95
77
|
]);
|
|
96
78
|
|
|
97
|
-
// The same toolkit, another member. The guest may read, so the write comes back refused.
|
|
98
79
|
yield* turn(
|
|
99
80
|
yield* Chat.empty,
|
|
100
|
-
|
|
81
|
+
demoMembers.guest,
|
|
101
82
|
"What is there to do? Add lunch for me."
|
|
102
83
|
);
|
|
103
84
|
});
|
|
@@ -110,8 +91,7 @@ const adding = (id: string, title: string, assignee: string) =>
|
|
|
110
91
|
params: { title, assignee },
|
|
111
92
|
}) as const;
|
|
112
93
|
|
|
113
|
-
|
|
114
|
-
const model = scripted(
|
|
94
|
+
const demoModel = scripted(
|
|
115
95
|
[
|
|
116
96
|
adding("1", "Book the venue", "ada"),
|
|
117
97
|
adding("2", "Send invitations", "grace"),
|
|
@@ -126,11 +106,8 @@ const model = scripted(
|
|
|
126
106
|
conversations.pipe(
|
|
127
107
|
Effect.provide(
|
|
128
108
|
Layer.mergeAll(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
model,
|
|
132
|
-
// Startup services only: where tasks and permissions are kept.
|
|
133
|
-
layer.pipe(Layer.provide([tasksFile, Permissions.layerMemory]))
|
|
109
|
+
demoModel,
|
|
110
|
+
layer.pipe(Layer.provide([demoTasksFile, Permissions.layerMemory]))
|
|
134
111
|
).pipe(Layer.provideMerge(NodeServices.layer))
|
|
135
112
|
),
|
|
136
113
|
NodeRuntime.runMain()
|
|
@@ -9,22 +9,15 @@ import { commands } from "./commands.js";
|
|
|
9
9
|
import { CurrentCaller } from "./identity/Identity.js";
|
|
10
10
|
import type { Operator } from "./identity/Identity.js";
|
|
11
11
|
import { Permissions } from "./identity/permissions.js";
|
|
12
|
-
import {
|
|
12
|
+
import { demoTasksFile } from "./platform/tasks-file.js";
|
|
13
13
|
|
|
14
|
-
// Entrypoint: `node --import tsx examples/assistant/src/cli.ts list-tasks`.
|
|
15
|
-
// The operator's own tool. No credential arrives at a terminal, so this host names the caller
|
|
16
|
-
// itself: whoever runs the command, as the trusted operator. Being local earns nothing more:
|
|
17
|
-
// `authorize` runs here as for a model's tool call, and admits the operator by its kind.
|
|
18
14
|
const operator: Operator = { kind: "operator", id: userInfo().username };
|
|
19
15
|
|
|
20
16
|
const assistant = commands.pipe(
|
|
21
|
-
Command.provide(Layer.mergeAll(
|
|
17
|
+
Command.provide(Layer.mergeAll(demoTasksFile, Permissions.layerMemory)),
|
|
22
18
|
Command.provideSync(CurrentCaller, operator)
|
|
23
19
|
);
|
|
24
20
|
|
|
25
|
-
// A command's defect, such as a tasks file that does not decode, `runMain` reports on stdout.
|
|
26
|
-
// `logToStderr`, applied last, moves that to stderr, so `assistant list-tasks --json | jq` reads
|
|
27
|
-
// results alone.
|
|
28
21
|
Command.run(assistant, { version: "1.0.0" }).pipe(
|
|
29
22
|
Effect.provide(NodeServices.layer),
|
|
30
23
|
ActionCli.logToStderr,
|
|
@@ -3,15 +3,9 @@ import * as ActionCli from "@gjermundgaraba/effect-actions/ActionCli";
|
|
|
3
3
|
import { identity } from "./identity/handlers.js";
|
|
4
4
|
import { tasks } from "./tasks/handlers.js";
|
|
5
5
|
|
|
6
|
-
// The same implementations as local commands, `assistant <action>`: a command runs the handler
|
|
7
|
-
// in this process, behind the same `authorize`. `add-task` and `who-am-i` are as derived; the
|
|
8
|
-
// others each change their syntax or output.
|
|
9
6
|
export const commands = ActionCli.make([tasks, identity], {
|
|
10
7
|
name: "assistant",
|
|
11
8
|
commands: {
|
|
12
|
-
// `assistant list-tasks -a ada`: a short flag beside `--assignee`. `render` prints a line
|
|
13
|
-
// per task for a person, and adds `--json` for the JSON a script reads. `description` is the
|
|
14
|
-
// command's help, saying what a line holds; the action's stays what a model reads.
|
|
15
9
|
listTasks: {
|
|
16
10
|
description:
|
|
17
11
|
"Print one line per task: [x] when done, then its id, title and assignee.",
|
|
@@ -24,9 +18,7 @@ export const commands = ActionCli.make([tasks, identity], {
|
|
|
24
18
|
)
|
|
25
19
|
.join("\n"),
|
|
26
20
|
},
|
|
27
|
-
// `assistant complete-task 2`: an argument instead of `--id 2`.
|
|
28
21
|
completeTask: { positional: ["id"] },
|
|
29
|
-
// `assistant annotate-task --id 2 < notes.md`: the notes are piped in, not a flag.
|
|
30
22
|
annotateTask: { stdin: "notes" },
|
|
31
23
|
},
|
|
32
24
|
});
|