@gjermundgaraba/effect-actions 0.24.0 → 0.25.1
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 +2 -2
- package/dist/Action.mjs +2 -2
- package/dist/ActionMcp.d.mts +3 -1
- package/dist/ActionMcp.mjs +7 -4
- package/dist/ActionRpc.mjs +5 -2
- package/dist/ActionToolkit.d.mts +3 -0
- package/dist/ActionToolkit.mjs +13 -2
- package/dist/Webhook.d.mts +3 -1
- package/dist/authentication/provider.d.mts +4 -3
- package/dist/contract/callback.mjs +0 -4
- package/dist/contract/feed.mjs +1 -1
- package/dist/contract/implementation.d.mts +5 -15
- package/dist/contract/lift.mjs +80 -0
- package/dist/contract/log.mjs +1 -1
- package/dist/contract/media.d.mts +3 -2
- package/dist/contract/media.mjs +3 -2
- package/dist/contract/push.mjs +6 -10
- package/dist/contract/status.mjs +13 -2
- package/dist/contract/subscribe.mjs +0 -4
- package/dist/http/events.d.mts +2 -2
- package/dist/http/events.mjs +5 -2
- package/dist/mcp/bridge.mjs +8 -4
- package/dist/mcp/client.mjs +2 -1
- package/dist/mcp/protocol.mjs +2 -79
- package/dist/webhook/attempt.mjs +2 -2
- package/dist/webhook/health.mjs +99 -0
- package/dist/webhook/receiver.mjs +2 -2
- package/dist/webhook/signing.mjs +4 -11
- package/dist/webhook/stored.mjs +23 -13
- package/dist/webhook/subscriptions.mjs +34 -46
- package/docs/Action-failures.md +1 -1
- package/docs/ActionCli.md +1 -1
- package/docs/ActionHttp.md +1 -1
- package/docs/ActionMcp.md +2 -2
- package/docs/ActionRpc.md +0 -4
- package/docs/ActionToolkit.md +1 -0
- package/docs/Authentication-advanced.md +16 -19
- package/docs/Authentication-failures.md +1 -1
- package/docs/Authentication.md +0 -4
- package/docs/README.md +1 -1
- package/docs/Webhook.md +3 -6
- package/docs/setup.md +5 -5
- package/examples/build-events/src/notifier/routes.ts +3 -6
- package/examples/build-events/src/notifier.ts +4 -2
- package/examples/build-events/test/notifier.test.ts +1 -1
- package/examples/kitchen-sink/README.md +3 -3
- package/examples/kitchen-sink/src/identity/authenticate.ts +2 -2
- package/examples/kitchen-sink/src/identity/workspace-header.ts +19 -0
- package/examples/kitchen-sink/src/routes.ts +2 -2
- package/examples/live-rpc/src/chat/room.ts +0 -4
- package/examples/notes-service/src/identity/Identity.ts +0 -4
- package/package.json +2 -2
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -22
package/docs/Authentication.md
CHANGED
|
@@ -22,10 +22,6 @@ export interface User {
|
|
|
22
22
|
readonly scopes: ReadonlyArray<typeof Scope.Type>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Who is calling. A protected action declares it, `caller: CurrentUser`; authentication
|
|
27
|
-
* provides it per request, and a local host, such as the stdio server, provides it itself.
|
|
28
|
-
*/
|
|
29
25
|
export class CurrentUser extends Context.Service<CurrentUser, User>()(
|
|
30
26
|
"notes-service/CurrentUser"
|
|
31
27
|
) {}
|
package/docs/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Where things are, in a project that installs the package: these pages in `node_m
|
|
|
28
28
|
| [ActionMcp.md](ActionMcp.md) | serve MCP tools over HTTP or stdio, describe them to a model, return images, protect them, serve events, allow browser clients, add prompts and resources, send notifications |
|
|
29
29
|
| [ActionRpc.md](ActionRpc.md) | bind actions to Effect rpcs, serve them on a protocol, call them, add native rpcs, send request context with a call |
|
|
30
30
|
| [ActionRpc-events.md](ActionRpc-events.md) | serve and watch events over rpcs, follow what a request names, such as a room |
|
|
31
|
-
| [ActionToolkit.md](ActionToolkit.md) | give a model actions as a native Effect AI `Toolkit`, name the caller, ask for approval |
|
|
31
|
+
| [ActionToolkit.md](ActionToolkit.md) | give a model actions as a native Effect AI `Toolkit`, show it images, name the caller, ask for approval |
|
|
32
32
|
| [ActionCli.md](ActionCli.md) | run actions as local commands, or call a server from commands; watch events; shape flags, input and output; name the caller; add a command of your own |
|
|
33
33
|
| [Webhook.md](Webhook.md) | deliver events to a subscriber's callback by webhook, signed, and watch by webhook |
|
|
34
34
|
| [Authentication.md](Authentication.md) | declare how callers sign in, verify credentials, publish OAuth discovery, step up for a scope |
|
package/docs/Webhook.md
CHANGED
|
@@ -218,23 +218,21 @@ import { Http } from "../Api.js";
|
|
|
218
218
|
import { BuildFinished } from "../builds/Builds.js";
|
|
219
219
|
import { Notices } from "./Notices.js";
|
|
220
220
|
|
|
221
|
-
/** Where build-events is, who the notifier signs in as there, and where it is reached itself. */
|
|
222
221
|
export interface NotifierOptions {
|
|
223
|
-
readonly
|
|
222
|
+
readonly buildEventsUrl: string;
|
|
224
223
|
readonly token: string | Redacted.Redacted;
|
|
225
|
-
/** This process's public https origin, which build-events POSTs to. */
|
|
226
224
|
readonly publicUrl: string;
|
|
227
225
|
}
|
|
228
226
|
|
|
229
227
|
const receiver = Webhook.layerReceiver({ path: "/hooks/builds" });
|
|
230
228
|
|
|
231
|
-
const watcher = ({
|
|
229
|
+
const watcher = ({ buildEventsUrl, token, publicUrl }: NotifierOptions) =>
|
|
232
230
|
Layer.effectDiscard(
|
|
233
231
|
Effect.gen(function* () {
|
|
234
232
|
const notices = yield* Notices;
|
|
235
233
|
|
|
236
234
|
const builds = yield* ActionHttp.client(Http, {
|
|
237
|
-
baseUrl:
|
|
235
|
+
baseUrl: buildEventsUrl,
|
|
238
236
|
transformClient: HttpClient.mapRequest(
|
|
239
237
|
HttpClientRequest.bearerToken(token)
|
|
240
238
|
),
|
|
@@ -265,7 +263,6 @@ const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
|
265
263
|
})
|
|
266
264
|
);
|
|
267
265
|
|
|
268
|
-
/** The notifier's routes: the receiver, and the watch reading from that same receiver. */
|
|
269
266
|
export const notifier = (options: NotifierOptions) =>
|
|
270
267
|
watcher(options).pipe(Layer.provideMerge(receiver));
|
|
271
268
|
```
|
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.1.
|
|
10
|
+
pnpm add @gjermundgaraba/effect-actions effect@~4.1.1
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
| Need | Add |
|
|
14
14
|
| --- | --- |
|
|
15
|
-
| Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.1.
|
|
16
|
-
| Tests | `vitest@^5` and `@effect/vitest@~4.1.
|
|
15
|
+
| Node HTTP server, stdio host or CLI | `@effect/platform-node@~4.1.1` |
|
|
16
|
+
| Tests | `vitest@^5` and `@effect/vitest@~4.1.1`, 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.1.x patches from the oldest whose APIs the package
|
|
21
|
+
The `effect` peer admits the 4.1.x patches from the oldest whose APIs and behavior the package relies on, 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.1.
|
|
23
|
+
Keep the tilde in `package.json`: `^4.1.1`, which npm writes for `effect@4.1.1`, admits a minor release outside the peer range. `npm install effect@~4.1.1` 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
|
|
|
@@ -9,23 +9,21 @@ import { Http } from "../Api.js";
|
|
|
9
9
|
import { BuildFinished } from "../builds/Builds.js";
|
|
10
10
|
import { Notices } from "./Notices.js";
|
|
11
11
|
|
|
12
|
-
/** Where build-events is, who the notifier signs in as there, and where it is reached itself. */
|
|
13
12
|
export interface NotifierOptions {
|
|
14
|
-
readonly
|
|
13
|
+
readonly buildEventsUrl: string;
|
|
15
14
|
readonly token: string | Redacted.Redacted;
|
|
16
|
-
/** This process's public https origin, which build-events POSTs to. */
|
|
17
15
|
readonly publicUrl: string;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
const receiver = Webhook.layerReceiver({ path: "/hooks/builds" });
|
|
21
19
|
|
|
22
|
-
const watcher = ({
|
|
20
|
+
const watcher = ({ buildEventsUrl, token, publicUrl }: NotifierOptions) =>
|
|
23
21
|
Layer.effectDiscard(
|
|
24
22
|
Effect.gen(function* () {
|
|
25
23
|
const notices = yield* Notices;
|
|
26
24
|
|
|
27
25
|
const builds = yield* ActionHttp.client(Http, {
|
|
28
|
-
baseUrl:
|
|
26
|
+
baseUrl: buildEventsUrl,
|
|
29
27
|
transformClient: HttpClient.mapRequest(
|
|
30
28
|
HttpClientRequest.bearerToken(token)
|
|
31
29
|
),
|
|
@@ -56,6 +54,5 @@ const watcher = ({ buildEvents, token, publicUrl }: NotifierOptions) =>
|
|
|
56
54
|
})
|
|
57
55
|
);
|
|
58
56
|
|
|
59
|
-
/** The notifier's routes: the receiver, and the watch reading from that same receiver. */
|
|
60
57
|
export const notifier = (options: NotifierOptions) =>
|
|
61
58
|
watcher(options).pipe(Layer.provideMerge(receiver));
|
|
@@ -10,7 +10,7 @@ import { notifier } from "./notifier/routes.js";
|
|
|
10
10
|
|
|
11
11
|
const server = Layer.unwrap(
|
|
12
12
|
Effect.gen(function* () {
|
|
13
|
-
const
|
|
13
|
+
const buildEventsUrl = yield* Config.String("BUILDS_URL").pipe(
|
|
14
14
|
Config.withDefault("http://127.0.0.1:3000")
|
|
15
15
|
);
|
|
16
16
|
|
|
@@ -23,7 +23,9 @@ const server = Layer.unwrap(
|
|
|
23
23
|
|
|
24
24
|
const port = yield* Config.Port("PORT").pipe(Config.withDefault(3001));
|
|
25
25
|
|
|
26
|
-
return HttpRouter.serve(
|
|
26
|
+
return HttpRouter.serve(
|
|
27
|
+
notifier({ buildEventsUrl, token, publicUrl })
|
|
28
|
+
).pipe(
|
|
27
29
|
Layer.provide(NodeHttpServer.layer(createServer, { host, port })),
|
|
28
30
|
Layer.provide(
|
|
29
31
|
Layer.succeed(HttpServerRequest.MaxBodySize, ByteSize.kibibytes(256))
|
|
@@ -26,7 +26,7 @@ describe("the notifier, by webhook", () => {
|
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
const notifierRoutes = notifier({
|
|
29
|
-
|
|
29
|
+
buildEventsUrl: "http://build-events.internal",
|
|
30
30
|
token: "grace",
|
|
31
31
|
publicUrl: "https://hooks.example.com",
|
|
32
32
|
}).pipe(Layer.provide(handedOver));
|
|
@@ -56,11 +56,11 @@ src/
|
|
|
56
56
|
│ ├── authenticate.ts Authentication.layer for both descriptors, OAuth discovery
|
|
57
57
|
│ ├── authorize.ts the members' rule: readOnly to a scope
|
|
58
58
|
│ ├── quota.ts the request quota, as HTTP and as RPC middleware
|
|
59
|
+
│ ├── workspace-header.ts WorkspaceHeader, the X-Workspace header the bearer verifier reads, and its router middleware
|
|
59
60
|
│ └── handlers.ts
|
|
60
61
|
├── workspaces/ the tenants
|
|
61
62
|
│ ├── Workspaces.ts contract: Workspace, the public getStatus
|
|
62
63
|
│ ├── registry.ts WorkspaceRegistry: the workspaces and their suspension
|
|
63
|
-
│ ├── tenant.ts Tenant, and the router middleware that resolves it per request
|
|
64
64
|
│ └── handlers.ts
|
|
65
65
|
├── issues/
|
|
66
66
|
│ ├── Issues.ts contract: schemas, errors, five actions, exportIssues, issue.changed
|
|
@@ -119,7 +119,7 @@ test/
|
|
|
119
119
|
|
|
120
120
|
| To see | Read |
|
|
121
121
|
| --- | --- |
|
|
122
|
-
| How one request is authenticated, placed in a tenant, authorized | `src/identity/authenticate.ts`, `src/
|
|
122
|
+
| How one request is authenticated, placed in a tenant, authorized | `src/identity/authenticate.ts`, `src/identity/workspace-header.ts`, `src/identity/authorize.ts`, `src/routes.ts` |
|
|
123
123
|
| Two audiences on two ports over one set of services | `src/server.ts`, `src/routes.ts`, `test/routes.test.ts` |
|
|
124
124
|
| Which actions each surface serves, and why one is no tool | `src/Actions.ts` |
|
|
125
125
|
| A limit before decoding and a limit in the handlers | `src/identity/quota.ts`, `src/issues/write-limit.ts` |
|
|
@@ -176,7 +176,7 @@ Each export and option the example uses, and where. A symbol in parentheses is t
|
|
|
176
176
|
| `layer`, a plain verifier | `src/admin/authenticate.ts` |
|
|
177
177
|
| `layer`: `protectedResource`, an Effect over `Config` | `src/identity/authenticate.ts` (`protectedResource`) |
|
|
178
178
|
| `ProtectedResource` | `src/identity/authenticate.ts` |
|
|
179
|
-
| A request service the verifier reads, and its order | `src/
|
|
179
|
+
| A request service the verifier reads, and its order | `src/identity/workspace-header.ts`, `src/routes.ts` (`publicRoutes`) |
|
|
180
180
|
| `protect`, a route of the host's own, by the cookie descriptor | `src/attachments/download.ts` |
|
|
181
181
|
| A trusted identity no verifier returns | `src/admin/Admin.ts`, `src/admin/authenticate.ts`, `src/ops.ts` |
|
|
182
182
|
| A verifier's declared error over MCP | `test/identity/identity.test.ts` |
|
|
@@ -5,10 +5,10 @@ import type { Redacted } from "effect";
|
|
|
5
5
|
|
|
6
6
|
import { publicUrl } from "../config.js";
|
|
7
7
|
import { WorkspaceRegistry } from "../workspaces/registry.js";
|
|
8
|
-
import { Tenant } from "../workspaces/tenant.js";
|
|
9
8
|
import { Directory } from "./directory.js";
|
|
10
9
|
import { Login, scopes, Session } from "./Identity.js";
|
|
11
10
|
import type { Member } from "./Identity.js";
|
|
11
|
+
import { WorkspaceHeader } from "./workspace-header.js";
|
|
12
12
|
|
|
13
13
|
const inService = Effect.gen(function* () {
|
|
14
14
|
const registry = yield* WorkspaceRegistry;
|
|
@@ -53,7 +53,7 @@ export const authenticateBearer = Authentication.layer(
|
|
|
53
53
|
Effect.gen(function* () {
|
|
54
54
|
const memberships = yield* directory.ofToken(token);
|
|
55
55
|
|
|
56
|
-
const member = Option.flatMap(yield*
|
|
56
|
+
const member = Option.flatMap(yield* WorkspaceHeader, (slug) =>
|
|
57
57
|
Array.findFirst(memberships, ({ workspace }) => workspace === slug)
|
|
58
58
|
);
|
|
59
59
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context, Effect, Option } from "effect";
|
|
2
|
+
import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
3
|
+
|
|
4
|
+
export class WorkspaceHeader extends Context.Service<
|
|
5
|
+
WorkspaceHeader,
|
|
6
|
+
Option.Option<string>
|
|
7
|
+
>()("tracker/WorkspaceHeader") {}
|
|
8
|
+
|
|
9
|
+
export const readWorkspaceHeader = HttpRouter.middleware<{
|
|
10
|
+
provides: WorkspaceHeader;
|
|
11
|
+
}>()((route) =>
|
|
12
|
+
Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) =>
|
|
13
|
+
Effect.provideService(
|
|
14
|
+
route,
|
|
15
|
+
WorkspaceHeader,
|
|
16
|
+
Option.fromNullishOr(request.headers["x-workspace"])
|
|
17
|
+
)
|
|
18
|
+
)
|
|
19
|
+
);
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import { identity } from "./identity/handlers.js";
|
|
23
23
|
import { Login } from "./identity/Identity.js";
|
|
24
24
|
import { HttpQuota, quota, RpcQuota } from "./identity/quota.js";
|
|
25
|
+
import { readWorkspaceHeader } from "./identity/workspace-header.js";
|
|
25
26
|
import { layer as assistantTools } from "./issues/assistant.js";
|
|
26
27
|
import { issueEvents } from "./issues/events.js";
|
|
27
28
|
import { exports } from "./issues/export.js";
|
|
@@ -31,7 +32,6 @@ import { IssueChanged } from "./issues/Issues.js";
|
|
|
31
32
|
import { cors, requestPolicy } from "./request-policy.js";
|
|
32
33
|
import { Rpc } from "./Rpc.js";
|
|
33
34
|
import { status } from "./workspaces/handlers.js";
|
|
34
|
-
import { resolveTenant } from "./workspaces/tenant.js";
|
|
35
35
|
import { GetStatus } from "./workspaces/Workspaces.js";
|
|
36
36
|
|
|
37
37
|
const implementations = [
|
|
@@ -91,7 +91,7 @@ export const publicRoutes = Layer.mergeAll(
|
|
|
91
91
|
Layer.provide(Webhook.layer()),
|
|
92
92
|
Layer.provide(assistantTools),
|
|
93
93
|
Layer.provide([authenticateBearer, authenticateSession, quota]),
|
|
94
|
-
Layer.provide(
|
|
94
|
+
Layer.provide(readWorkspaceHeader.layer),
|
|
95
95
|
Layer.provide(cors),
|
|
96
96
|
Layer.provide(requestPolicy)
|
|
97
97
|
);
|
|
@@ -3,10 +3,6 @@ import { RpcMiddleware } from "effect/rpc";
|
|
|
3
3
|
|
|
4
4
|
import { defaultRoom, roomHeader } from "./Chat.js";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* The room a message is about. A request-time service: handlers and `authorize` read it per
|
|
8
|
-
* call, and it has no Layer, because no one value of it is right for a whole server.
|
|
9
|
-
*/
|
|
10
6
|
export class CurrentRoom extends Context.Service<CurrentRoom, string>()(
|
|
11
7
|
"live-rpc/CurrentRoom"
|
|
12
8
|
) {}
|
|
@@ -11,10 +11,6 @@ export interface User {
|
|
|
11
11
|
readonly scopes: ReadonlyArray<typeof Scope.Type>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Who is calling. A protected action declares it, `caller: CurrentUser`; authentication
|
|
16
|
-
* provides it per request, and a local host, such as the stdio server, provides it itself.
|
|
17
|
-
*/
|
|
18
14
|
export class CurrentUser extends Context.Service<CurrentUser, User>()(
|
|
19
15
|
"notes-service/CurrentUser"
|
|
20
16
|
) {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjermundgaraba/effect-actions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "Define Effect action contracts once and project them onto HTTP, MCP, Effect RPC, native Toolkits, and CLIs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"vitest": "5.0.5"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"effect": "~4.1.
|
|
70
|
+
"effect": "~4.1.1"
|
|
71
71
|
},
|
|
72
72
|
"devEngines": {
|
|
73
73
|
"packageManager": {
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Option } from "effect";
|
|
2
|
-
import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The workspace a request addresses, from its `X-Workspace` header. It is request context, not
|
|
6
|
-
* an identity: the verifier reads it to decide which of an account's memberships the caller
|
|
7
|
-
* acts in. Handlers never read it; they read the workspace of the authenticated member.
|
|
8
|
-
*/
|
|
9
|
-
export class Tenant extends Context.Service<Tenant, Option.Option<string>>()(
|
|
10
|
-
"tracker/Tenant"
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
export const resolveTenant = HttpRouter.middleware<{ provides: Tenant }>()(
|
|
14
|
-
(route) =>
|
|
15
|
-
Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) =>
|
|
16
|
-
Effect.provideService(
|
|
17
|
-
route,
|
|
18
|
-
Tenant,
|
|
19
|
-
Option.fromNullishOr(request.headers["x-workspace"])
|
|
20
|
-
)
|
|
21
|
-
)
|
|
22
|
-
);
|