@gjermundgaraba/effect-actions 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/Action.d.mts +2 -2
- package/dist/Action.mjs +1 -0
- package/dist/ActionCli.mjs +0 -1
- package/dist/ActionHttp.d.mts +1 -1
- package/dist/ActionMcp.d.mts +0 -3
- package/dist/ActionMcp.mjs +0 -5
- package/dist/ActionRpc.d.mts +8 -15
- package/dist/ActionRpc.mjs +29 -54
- package/dist/ActionToolkit.d.mts +0 -2
- package/dist/ActionToolkit.mjs +0 -2
- package/dist/Event.d.mts +0 -23
- package/dist/Testing.mjs +3 -2
- package/dist/Webhook.mjs +2 -2
- package/dist/authentication/refusal.mjs +0 -1
- package/dist/cli/commands.mjs +0 -5
- package/dist/contract/authorizer.mjs +0 -5
- package/dist/contract/call.mjs +0 -23
- package/dist/contract/callback.mjs +0 -1
- package/dist/contract/caller.mjs +0 -11
- package/dist/contract/canonical.mjs +0 -5
- package/dist/contract/codec.d.mts +0 -1
- package/dist/contract/codec.mjs +0 -1
- package/dist/contract/codes.mjs +1 -15
- package/dist/contract/declared.mjs +0 -15
- package/dist/contract/digest.mjs +0 -1
- package/dist/contract/errors.d.mts +0 -4
- package/dist/contract/errors.mjs +0 -4
- package/dist/contract/feed.d.mts +0 -1
- package/dist/contract/feed.mjs +0 -20
- package/dist/contract/hints.mjs +0 -6
- package/dist/contract/hub.mjs +0 -3
- package/dist/contract/idempotency.mjs +0 -4
- package/dist/contract/implementation.d.mts +0 -1
- package/dist/contract/implementation.mjs +0 -27
- package/dist/contract/input-check.mjs +0 -1
- package/dist/contract/lease.mjs +0 -1
- package/dist/contract/listed.mjs +0 -6
- package/dist/contract/log.mjs +0 -8
- package/dist/contract/names.mjs +0 -1
- package/dist/contract/occurrence.mjs +0 -8
- package/dist/contract/pages.mjs +5 -12
- package/dist/contract/progress.mjs +2 -25
- package/dist/contract/push.d.mts +0 -5
- package/dist/contract/push.mjs +1 -24
- package/dist/contract/receiving.mjs +0 -7
- package/dist/contract/reported.mjs +0 -5
- package/dist/contract/serving.mjs +0 -18
- package/dist/contract/status.mjs +0 -3
- package/dist/contract/stream.mjs +0 -2
- package/dist/contract/subscribe.d.mts +0 -2
- package/dist/contract/subscribe.mjs +0 -8
- package/dist/contract/transient.mjs +0 -12
- package/dist/contract/watch.mjs +5 -17
- package/dist/contract/webhooks.mjs +0 -11
- package/dist/http/client.mjs +0 -1
- package/dist/http/events.d.mts +0 -10
- package/dist/http/events.mjs +2 -31
- package/dist/http/placed.d.mts +0 -2
- package/dist/http/streamed.d.mts +0 -1
- package/dist/http/streamed.mjs +4 -32
- package/dist/http/watch.mjs +0 -6
- package/dist/mcp/bridge.mjs +0 -25
- package/dist/mcp/client.d.mts +0 -1
- package/dist/mcp/client.mjs +0 -1
- package/dist/mcp/events.mjs +0 -6
- package/dist/mcp/progress.mjs +0 -7
- package/dist/mcp/protocol.mjs +0 -6
- package/dist/mcp/reply.mjs +0 -11
- package/dist/mcp/request.mjs +0 -1
- package/dist/mcp/watch.mjs +0 -6
- package/dist/rpc/watch.mjs +0 -6
- package/dist/stdio/console.mjs +2 -2
- package/dist/webhook/address.mjs +4 -9
- package/dist/webhook/attempt.mjs +2 -15
- package/dist/webhook/receiver.mjs +2 -8
- package/dist/webhook/signing.mjs +0 -3
- package/dist/webhook/stored.mjs +8 -17
- package/dist/webhook/subscriptions.mjs +19 -23
- package/docs/Action-streams.md +0 -12
- package/docs/Action.md +0 -10
- package/docs/ActionCli.md +2 -26
- package/docs/ActionHttp.md +0 -28
- package/docs/ActionMcp.md +2 -37
- package/docs/ActionRpc-events.md +0 -16
- package/docs/ActionRpc.md +0 -63
- package/docs/ActionToolkit.md +0 -11
- package/docs/Authentication-advanced.md +0 -31
- package/docs/Authentication.md +4 -13
- package/docs/Event.md +0 -37
- package/docs/README.md +1 -1
- package/docs/Testing.md +3 -13
- package/docs/Webhook.md +0 -46
- package/docs/setup.md +0 -5
- package/examples/README.md +7 -1
- package/examples/assistant/src/agent.ts +8 -31
- package/examples/assistant/src/cli.ts +2 -9
- package/examples/assistant/src/commands.ts +0 -8
- package/examples/assistant/src/identity/Identity.ts +0 -10
- package/examples/assistant/src/identity/authorize.ts +0 -4
- package/examples/assistant/src/identity/members.ts +1 -3
- package/examples/assistant/src/identity/permissions.ts +0 -5
- package/examples/assistant/src/platform/tasks-file.ts +1 -6
- package/examples/assistant/src/scripted.ts +0 -4
- package/examples/assistant/src/tasks/Tasks.ts +0 -2
- package/examples/assistant/src/tasks/handlers.ts +0 -3
- package/examples/assistant/src/tasks/store.ts +0 -7
- package/examples/assistant/src/toolkit.ts +0 -11
- package/examples/assistant/test/commands.test.ts +0 -5
- package/examples/assistant/test/identity/identity.test.ts +6 -6
- package/examples/assistant/test/platform/tasks-file.test.ts +2 -6
- package/examples/assistant/test/tasks/tasks.test.ts +13 -14
- package/examples/assistant/test/toolkit.test.ts +7 -18
- package/examples/build-events/README.md +2 -0
- package/examples/build-events/src/Api.ts +0 -3
- package/examples/build-events/src/Rpc.ts +0 -2
- package/examples/build-events/src/builds/Builds.ts +0 -15
- package/examples/build-events/src/builds/events.ts +0 -10
- package/examples/build-events/src/builds/handlers.ts +0 -6
- package/examples/build-events/src/builds/log.ts +0 -6
- package/examples/build-events/src/builds/status.ts +0 -4
- package/examples/build-events/src/builds/store.ts +0 -21
- package/examples/build-events/src/cli.ts +0 -2
- package/examples/build-events/src/commands.ts +0 -9
- package/examples/build-events/src/deploys/approvers.ts +0 -3
- package/examples/build-events/src/deploys/events.ts +0 -8
- package/examples/build-events/src/deploys/handlers.ts +0 -2
- package/examples/build-events/src/identity/Identity.ts +0 -11
- package/examples/build-events/src/identity/members.ts +1 -2
- package/examples/build-events/src/identity/verifier.ts +8 -9
- package/examples/build-events/src/notifier/Notices.ts +0 -3
- package/examples/build-events/src/notifier/routes.ts +0 -10
- package/examples/build-events/src/notifier.ts +0 -8
- package/examples/build-events/src/routes.ts +0 -24
- package/examples/build-events/src/server.ts +0 -14
- package/examples/build-events/test/builds/events.test.ts +0 -6
- package/examples/build-events/test/builds/log.test.ts +0 -1
- package/examples/build-events/test/builds/progress.test.ts +0 -1
- package/examples/build-events/test/commands.test.ts +0 -5
- package/examples/build-events/test/deploys/events.test.ts +0 -1
- package/examples/build-events/test/http.test.ts +0 -4
- package/examples/build-events/test/notifier.test.ts +0 -9
- package/examples/build-events/test/routes.test.ts +0 -9
- package/examples/build-events/test/rpc.test.ts +0 -4
- package/examples/build-events/test/support/as.ts +3 -4
- package/examples/build-events/test/support/memory.ts +0 -5
- package/examples/build-events/test/webhooks.test.ts +0 -12
- package/examples/kitchen-sink/README.md +1 -1
- package/examples/kitchen-sink/src/Actions.ts +0 -10
- package/examples/kitchen-sink/src/Api.ts +0 -8
- package/examples/kitchen-sink/src/Rpc.ts +0 -4
- package/examples/kitchen-sink/src/admin/Admin.ts +0 -9
- package/examples/kitchen-sink/src/admin/authenticate.ts +2 -6
- package/examples/kitchen-sink/src/admin/authorize.ts +0 -5
- package/examples/kitchen-sink/src/admin/grants.ts +0 -5
- package/examples/kitchen-sink/src/admin/handlers.ts +0 -2
- package/examples/kitchen-sink/src/admin/keys.ts +1 -3
- package/examples/kitchen-sink/src/agent.ts +2 -13
- package/examples/kitchen-sink/src/assistant/Assistant.ts +7 -24
- package/examples/kitchen-sink/src/assistant/conversations.ts +3 -21
- package/examples/kitchen-sink/src/assistant/demo-model.ts +0 -5
- package/examples/kitchen-sink/src/assistant/handlers.ts +1 -30
- package/examples/kitchen-sink/src/attachments/Attachments.ts +0 -4
- package/examples/kitchen-sink/src/attachments/download.ts +0 -10
- package/examples/kitchen-sink/src/attachments/handlers.ts +0 -3
- package/examples/kitchen-sink/src/attachments/store.ts +0 -3
- package/examples/kitchen-sink/src/browser.ts +0 -9
- package/examples/kitchen-sink/src/cli.ts +0 -19
- package/examples/kitchen-sink/src/config.ts +3 -11
- package/examples/kitchen-sink/src/identity/Identity.ts +0 -18
- package/examples/kitchen-sink/src/identity/authenticate.ts +3 -14
- package/examples/kitchen-sink/src/identity/authorize.ts +0 -6
- package/examples/kitchen-sink/src/identity/directory.ts +8 -18
- package/examples/kitchen-sink/src/identity/handlers.ts +0 -3
- package/examples/kitchen-sink/src/identity/members.ts +1 -5
- package/examples/kitchen-sink/src/identity/quota.ts +0 -11
- package/examples/kitchen-sink/src/issues/Issues.ts +0 -24
- package/examples/kitchen-sink/src/issues/assistant.ts +0 -10
- package/examples/kitchen-sink/src/issues/events.ts +2 -16
- package/examples/kitchen-sink/src/issues/export.ts +0 -5
- package/examples/kitchen-sink/src/issues/guide.ts +0 -5
- package/examples/kitchen-sink/src/issues/handlers.ts +0 -5
- package/examples/kitchen-sink/src/issues/store.ts +19 -23
- package/examples/kitchen-sink/src/issues/write-limit.ts +0 -12
- package/examples/kitchen-sink/src/memory.ts +0 -9
- package/examples/kitchen-sink/src/ops.ts +0 -6
- package/examples/kitchen-sink/src/request-policy.ts +0 -17
- package/examples/kitchen-sink/src/routes.ts +0 -48
- package/examples/kitchen-sink/src/sdk.ts +0 -12
- package/examples/kitchen-sink/src/seed.ts +0 -10
- package/examples/kitchen-sink/src/server.ts +0 -22
- package/examples/kitchen-sink/src/stdio.ts +2 -12
- package/examples/kitchen-sink/src/workspaces/Workspaces.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/handlers.ts +0 -4
- package/examples/kitchen-sink/src/workspaces/registry.ts +0 -5
- package/examples/kitchen-sink/src/workspaces/tenant.ts +0 -4
- package/examples/kitchen-sink/test/admin/admin.test.ts +0 -1
- package/examples/kitchen-sink/test/assistant/assistant.test.ts +0 -18
- package/examples/kitchen-sink/test/attachments/attachments.test.ts +0 -9
- package/examples/kitchen-sink/test/identity/identity.test.ts +0 -10
- package/examples/kitchen-sink/test/identity/session.test.ts +0 -10
- package/examples/kitchen-sink/test/issues/assistant.test.ts +3 -7
- package/examples/kitchen-sink/test/issues/events.test.ts +2 -9
- package/examples/kitchen-sink/test/issues/export.test.ts +0 -3
- package/examples/kitchen-sink/test/issues/issues.test.ts +6 -12
- package/examples/kitchen-sink/test/request-policy.test.ts +0 -6
- package/examples/kitchen-sink/test/routes.test.ts +0 -6
- package/examples/kitchen-sink/test/support/as.ts +3 -5
- package/examples/kitchen-sink/test/support/scripted.ts +0 -3
- package/examples/kitchen-sink/test/support/services.ts +0 -3
- package/examples/live-rpc/src/Rpc.ts +0 -4
- package/examples/live-rpc/src/browser.ts +0 -24
- package/examples/live-rpc/src/chat/Chat.ts +0 -22
- package/examples/live-rpc/src/chat/authorize.ts +0 -3
- package/examples/live-rpc/src/chat/events.ts +0 -14
- package/examples/live-rpc/src/chat/handlers.ts +0 -5
- package/examples/live-rpc/src/chat/room.ts +0 -6
- package/examples/live-rpc/src/chat/store.ts +0 -9
- package/examples/live-rpc/src/client.ts +0 -6
- package/examples/live-rpc/src/identity/Identity.ts +0 -6
- package/examples/live-rpc/src/identity/members.ts +1 -3
- package/examples/live-rpc/src/identity/verifier.ts +6 -12
- package/examples/live-rpc/src/page.ts +0 -10
- package/examples/live-rpc/src/routes.ts +0 -13
- package/examples/live-rpc/src/server.ts +0 -16
- package/examples/live-rpc/test/browser.test.ts +0 -9
- package/examples/live-rpc/test/chat/chat.test.ts +3 -11
- package/examples/live-rpc/test/routes.test.ts +0 -8
- package/examples/live-rpc/test/server.test.ts +0 -13
- package/examples/mcp-tools/src/instructions.ts +0 -4
- package/examples/mcp-tools/src/platform/fake-farm.ts +0 -6
- package/examples/mcp-tools/src/platform/print-farm.ts +0 -16
- package/examples/mcp-tools/src/printers/Printers.ts +0 -21
- package/examples/mcp-tools/src/printers/farm.ts +0 -5
- package/examples/mcp-tools/src/printers/handlers.ts +0 -6
- package/examples/mcp-tools/src/routes.ts +0 -11
- package/examples/mcp-tools/src/server.ts +0 -9
- package/examples/mcp-tools/src/stdio.ts +1 -13
- package/examples/mcp-tools/test/printers/printers.test.ts +0 -10
- package/examples/mcp-tools/test/routes.test.ts +0 -14
- package/examples/notes-service/src/Api.ts +0 -4
- package/examples/notes-service/src/browser.ts +0 -12
- package/examples/notes-service/src/cli.ts +0 -2
- package/examples/notes-service/src/commands.ts +0 -30
- package/examples/notes-service/src/identity/Identity.ts +0 -2
- package/examples/notes-service/src/identity/authorize.ts +0 -4
- package/examples/notes-service/src/identity/users.ts +1 -3
- package/examples/notes-service/src/identity/verifier.ts +4 -11
- package/examples/notes-service/src/notes/Notes.ts +0 -12
- package/examples/notes-service/src/notes/handlers.ts +0 -4
- package/examples/notes-service/src/notes/store.ts +62 -48
- package/examples/notes-service/src/routes.ts +0 -12
- package/examples/notes-service/src/server.ts +0 -6
- package/examples/notes-service/src/status/Status.ts +0 -1
- package/examples/notes-service/src/status/handlers.ts +0 -1
- package/examples/notes-service/src/stdio.ts +2 -12
- package/examples/notes-service/src/worker.ts +0 -7
- package/examples/notes-service/test/commands.test.ts +0 -20
- package/examples/notes-service/test/notes/as.ts +3 -4
- package/examples/notes-service/test/notes/in-process.test.ts +3 -6
- package/examples/notes-service/test/notes/notes.test.ts +0 -6
- package/examples/notes-service/test/routes.test.ts +0 -5
- package/examples/notes-service/test/worker.test.ts +0 -1
- package/examples/quickstart/src/Api.ts +0 -1
- package/examples/quickstart/src/client.ts +0 -3
- package/examples/quickstart/src/greeting/Greeting.ts +0 -2
- package/examples/quickstart/src/greeting/handlers.ts +0 -1
- package/examples/quickstart/src/routes.ts +0 -1
- package/examples/quickstart/src/server.ts +3 -6
- package/examples/quickstart/test/routes.test.ts +0 -1
- package/package.json +2 -1
|
@@ -34,8 +34,6 @@ import { status } from "./workspaces/handlers.js";
|
|
|
34
34
|
import { resolveTenant } from "./workspaces/tenant.js";
|
|
35
35
|
import { GetStatus } from "./workspaces/Workspaces.js";
|
|
36
36
|
|
|
37
|
-
// Every domain's implementation of the public port's actions and events, once. Each surface
|
|
38
|
-
// below takes this one list and serves what its binding or its `actions` names.
|
|
39
37
|
const implementations = [
|
|
40
38
|
status,
|
|
41
39
|
identity,
|
|
@@ -46,9 +44,6 @@ const implementations = [
|
|
|
46
44
|
assistant,
|
|
47
45
|
];
|
|
48
46
|
|
|
49
|
-
// JSON routes at `/api/v1/<action>`, in two layers of one binding, each naming its `actions`,
|
|
50
|
-
// an event among them: a layer given `actions` serves exactly what it names. The quota requires
|
|
51
|
-
// the caller, and a public route has none, so `getStatus` is served by a layer without it.
|
|
52
47
|
const api = Layer.mergeAll(
|
|
53
48
|
ActionHttp.layer(Http, implementations, { actions: [GetStatus] }),
|
|
54
49
|
ActionHttp.layer(Http, implementations, {
|
|
@@ -57,9 +52,6 @@ const api = Layer.mergeAll(
|
|
|
57
52
|
})
|
|
58
53
|
);
|
|
59
54
|
|
|
60
|
-
// The same actions as MCP tools at `/mcp`: a mixed endpoint, serving the public `getStatus`
|
|
61
|
-
// beside the members' tools, and `issue.changed` as an MCP event, polled, streamed or
|
|
62
|
-
// delivered by webhook.
|
|
63
55
|
const mcp = Layer.unwrap(
|
|
64
56
|
Effect.map(allowedOrigins, (origins) =>
|
|
65
57
|
ActionMcp.layerHttp(implementations, {
|
|
@@ -69,25 +61,15 @@ const mcp = Layer.unwrap(
|
|
|
69
61
|
authentication: Login,
|
|
70
62
|
actions: [...Tools, IssueChanged],
|
|
71
63
|
features,
|
|
72
|
-
// The endpoint's own Origin allowlist, narrower than the request policy, which has
|
|
73
|
-
// already refused a foreign Origin: that policy also lets through a page of any name
|
|
74
|
-
// this host answers to, such as http://127.0.0.1:3000. Not listed here, such a page gets
|
|
75
|
-
// a 403 from the endpoint.
|
|
76
64
|
allowedOrigins: origins,
|
|
77
65
|
})
|
|
78
66
|
)
|
|
79
67
|
);
|
|
80
68
|
|
|
81
|
-
// The members' actions as Effect RPC, for the web app, behind its session cookie and the same
|
|
82
|
-
// quota as native RPC middleware. It still requires its protocol and serialization, chosen by
|
|
83
|
-
// whoever serves it: server.ts gives it a WebSocket, and a test Effect's HTTP protocol, which
|
|
84
|
-
// answers in memory.
|
|
85
69
|
export const rpc = ActionRpc.layer(Rpc, implementations, {
|
|
86
70
|
middleware: [RpcQuota],
|
|
87
71
|
}).pipe(Layer.provide([authenticateSession, quota, assistantTools]));
|
|
88
72
|
|
|
89
|
-
// Effect's own tools read the binding's native `HttpApi`: the OpenAPI document and a Swagger
|
|
90
|
-
// UI, each showing the bearer scheme on every route but `getStatus`.
|
|
91
73
|
const documentation = Layer.mergeAll(
|
|
92
74
|
HttpRouter.add(
|
|
93
75
|
"GET",
|
|
@@ -99,27 +81,6 @@ const documentation = Layer.mergeAll(
|
|
|
99
81
|
|
|
100
82
|
const health = HttpRouter.add("GET", "/healthz", HttpServerResponse.text("ok"));
|
|
101
83
|
|
|
102
|
-
// The public port's HTTP routes: what members reach, but for the rpcs, which server.ts serves
|
|
103
|
-
// beside these. Each `Layer.provide` gives what the layers before it still owe, and is built
|
|
104
|
-
// before them. Two things follow from that order.
|
|
105
|
-
//
|
|
106
|
-
// - `resolveTenant`, in a `Layer.provide` of its own after the authentication, gives the
|
|
107
|
-
// `Tenant` the Bearer verifier reads per request; tenant.ts says why not in one array.
|
|
108
|
-
// - Global middleware runs in the order it registers, and it registers when its layer is
|
|
109
|
-
// built. The request policy, provided last, is built first, so it runs before everything:
|
|
110
|
-
// before CORS, and before the OAuth discovery the Bearer provider registers when it is
|
|
111
|
-
// built. Merged beside the routes instead, it would register after that provider, and a
|
|
112
|
-
// foreign Host could read the discovery document.
|
|
113
|
-
//
|
|
114
|
-
// The assistant's builder yields its tools, so their handlers are provided to the layers
|
|
115
|
-
// serving it, here and on `rpc`: one Layer, built once in the layer graph serving both, where
|
|
116
|
-
// the tools run the issue implementation the routes serve, with no second build of it.
|
|
117
|
-
//
|
|
118
|
-
// Webhook delivery serves MCP's `events/subscribe` and HTTP's
|
|
119
|
-
// `POST /api/v1/events/issue.changed/subscribe`: a member names a callback URL and a secret,
|
|
120
|
-
// and each change it may see is POSTed there, signed. One layer holds the subscriptions of
|
|
121
|
-
// both. It POSTs with an `HttpClient` and checks where each callback resolves with `Dns`, which
|
|
122
|
-
// server.ts provides.
|
|
123
84
|
export const publicRoutes = Layer.mergeAll(
|
|
124
85
|
api,
|
|
125
86
|
mcp,
|
|
@@ -135,20 +96,11 @@ export const publicRoutes = Layer.mergeAll(
|
|
|
135
96
|
Layer.provide(requestPolicy)
|
|
136
97
|
);
|
|
137
98
|
|
|
138
|
-
// The admin port: what operators reach, and nothing else. It is a router of its own, with its
|
|
139
|
-
// own binding, descriptor and provider, so no member's token is even understood here. It
|
|
140
|
-
// serves one implementation the public port serves too, `status`.
|
|
141
99
|
export const adminRoutes = Layer.mergeAll(
|
|
142
100
|
ActionHttp.layer(AdminHttp, [status, admin]),
|
|
143
101
|
health
|
|
144
102
|
).pipe(Layer.provide(authenticateOperator), Layer.provide(requestPolicy));
|
|
145
103
|
|
|
146
|
-
// Every builder as one layer. The two ports are two layer graphs, and each would run the
|
|
147
|
-
// builder of an implementation it serves: `status`, which both serve, twice, each port then
|
|
148
|
-
// reporting an `instance` of its own. Provided above both, with the services, each builder
|
|
149
|
-
// runs once for every surface of both ports. The assistant's, the export's and the event's are
|
|
150
|
-
// left out: the public port alone serves them, and builds each once for its routes and its
|
|
151
|
-
// rpcs.
|
|
152
104
|
export const builders = Action.layer([
|
|
153
105
|
status,
|
|
154
106
|
identity,
|
|
@@ -5,16 +5,11 @@ import { HttpClient, HttpClientRequest } from "effect/http";
|
|
|
5
5
|
import { Http } from "./Api.js";
|
|
6
6
|
import type { Issue } from "./issues/Issues.js";
|
|
7
7
|
|
|
8
|
-
// Entrypoint for code written with promises: an integration, a bot, another product's page.
|
|
9
|
-
// It imports the binding and nothing of the server, so a bundler keeps the contracts and
|
|
10
|
-
// Effect's fetch client, no handler.
|
|
11
8
|
export const connect = (options: {
|
|
12
9
|
readonly url: string;
|
|
13
10
|
readonly token: string;
|
|
14
11
|
readonly workspace: string;
|
|
15
12
|
}) => {
|
|
16
|
-
// Built once, outside any Effect, over `fetch`: its methods require nothing, so each call
|
|
17
|
-
// runs with `Effect.runPromise`.
|
|
18
13
|
const api = ActionHttp.fetchClient(Http, {
|
|
19
14
|
baseUrl: options.url,
|
|
20
15
|
transformClient: HttpClient.mapRequest(
|
|
@@ -26,8 +21,6 @@ export const connect = (options: {
|
|
|
26
21
|
});
|
|
27
22
|
|
|
28
23
|
return {
|
|
29
|
-
// A method takes the action's decoded input, so a field with a decoding default is given
|
|
30
|
-
// here; only a call without any argument sends `{}` and gets the defaults.
|
|
31
24
|
openIssues: async (limit = 20) =>
|
|
32
25
|
await Effect.runPromise(
|
|
33
26
|
Effect.map(
|
|
@@ -36,20 +29,15 @@ export const connect = (options: {
|
|
|
36
29
|
)
|
|
37
30
|
),
|
|
38
31
|
|
|
39
|
-
// A declared error is a typed failure, handled by its tag: a missing issue is `undefined`.
|
|
40
32
|
issue: async (id: string): Promise<Issue | undefined> =>
|
|
41
33
|
await api.getIssue({ id }).pipe(
|
|
42
34
|
Effect.catchTag("IssueNotFound", () => Effect.undefined),
|
|
43
35
|
Effect.runPromise
|
|
44
36
|
),
|
|
45
37
|
|
|
46
|
-
// Left unhandled, a declared error rejects the promise as its decoded value, so a caller's
|
|
47
|
-
// `catch` may test `error instanceof RateLimited`.
|
|
48
38
|
file: async (title: string, body: string) =>
|
|
49
39
|
await Effect.runPromise(api.createIssue({ title, body })),
|
|
50
40
|
|
|
51
|
-
// A stream action's method returns a `Stream`; as an async iterable, `for await` reads each
|
|
52
|
-
// issue as the server sends it.
|
|
53
41
|
exportAll: (): AsyncIterable<Issue> =>
|
|
54
42
|
Stream.toAsyncIterable(api.exportIssues({})),
|
|
55
43
|
};
|
|
@@ -7,12 +7,6 @@ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
|
7
7
|
|
|
8
8
|
import { Http } from "./Api.js";
|
|
9
9
|
|
|
10
|
-
// Entrypoint: `node --import tsx examples/kitchen-sink/src/seed.ts`, with the server running.
|
|
11
|
-
// An Effect program calling the API with the binding's typed client: one method per action,
|
|
12
|
-
// taking its input and answering its decoded success. DEMO ONLY: it files a first issue in
|
|
13
|
-
// `acme` as `ada`, since the server's stores start empty.
|
|
14
|
-
|
|
15
|
-
// A one-pixel PNG stands in for a screenshot.
|
|
16
10
|
const screenshot = Buffer.from(
|
|
17
11
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
|
|
18
12
|
"base64"
|
|
@@ -25,7 +19,6 @@ const seed = Effect.gen(function* () {
|
|
|
25
19
|
|
|
26
20
|
const tracker = yield* ActionHttp.client(Http, {
|
|
27
21
|
baseUrl,
|
|
28
|
-
// Every request of this client: the token, and the header naming the workspace.
|
|
29
22
|
transformClient: HttpClient.mapRequest(
|
|
30
23
|
flow(
|
|
31
24
|
HttpClientRequest.bearerToken("ada"),
|
|
@@ -39,7 +32,6 @@ const seed = Effect.gen(function* () {
|
|
|
39
32
|
body: "Saving an empty draft crashes the editor.",
|
|
40
33
|
});
|
|
41
34
|
|
|
42
|
-
// Over HTTP the image is JSON, its bytes in base64: the client encodes the `Uint8Array`.
|
|
43
35
|
const attachment = yield* tracker.attachImage({
|
|
44
36
|
issue: issue.id,
|
|
45
37
|
name: "crash.png",
|
|
@@ -55,8 +47,6 @@ const seed = Effect.gen(function* () {
|
|
|
55
47
|
issues
|
|
56
48
|
);
|
|
57
49
|
}).pipe(
|
|
58
|
-
// A declared error is a typed failure, the binding's and the verifier's included: each is
|
|
59
|
-
// handled by its tag. Anything else, such as an unreachable server, stays Effect's own.
|
|
60
50
|
Effect.catchTags({
|
|
61
51
|
RateLimited: ({ retryAfterSeconds }) =>
|
|
62
52
|
Console.error(`Write limit reached: retry in ${retryAfterSeconds}s.`),
|
|
@@ -8,12 +8,6 @@ import { RpcSerialization, RpcServer } from "effect/rpc";
|
|
|
8
8
|
import { memory } from "./memory.js";
|
|
9
9
|
import { adminRoutes, builders, publicRoutes, rpc } from "./routes.js";
|
|
10
10
|
|
|
11
|
-
// Entrypoint: `node --import tsx examples/kitchen-sink/src/server.ts`.
|
|
12
|
-
// The entrypoint of the server: two listeners over one set of builders and services.
|
|
13
|
-
|
|
14
|
-
// The web app's rpcs over a WebSocket at `/rpc`: Node's HTTP server answers the upgrade. The
|
|
15
|
-
// protocol is this entrypoint's choice, as the ports are. `rpc` leaves it open, so a test
|
|
16
|
-
// serves the same layer over Effect's HTTP protocol.
|
|
17
11
|
const socket = rpc.pipe(
|
|
18
12
|
Layer.provide(RpcServer.layerProtocolWebsocket({ path: "/rpc" })),
|
|
19
13
|
Layer.provide(RpcSerialization.layerJson)
|
|
@@ -21,7 +15,6 @@ const socket = rpc.pipe(
|
|
|
21
15
|
|
|
22
16
|
const server = Layer.unwrap(
|
|
23
17
|
Effect.gen(function* () {
|
|
24
|
-
// The loopback default serves this machine alone; HOST=0.0.0.0 lets others reach it.
|
|
25
18
|
const host = yield* Config.String("HOST").pipe(
|
|
26
19
|
Config.withDefault("127.0.0.1")
|
|
27
20
|
);
|
|
@@ -40,36 +33,21 @@ const server = Layer.unwrap(
|
|
|
40
33
|
NodeHttpServer.layer(createServer, {
|
|
41
34
|
host,
|
|
42
35
|
port,
|
|
43
|
-
// A message on the WebSocket of `/rpc` is no request body, so the limit below does not
|
|
44
|
-
// bound it: Node's WebSocket server reads one of up to 100 MiB whole unless told
|
|
45
|
-
// otherwise. A larger one closes the socket (1009).
|
|
46
36
|
websocket: { maxPayload: Number(limit) },
|
|
47
37
|
});
|
|
48
38
|
|
|
49
39
|
return Layer.mergeAll(
|
|
50
|
-
// Two audiences, two listeners, each with a router of its own: the public port can only
|
|
51
|
-
// ever reach the members' routes. The socket is merged into the public port's routes, so
|
|
52
|
-
// it is a route of that router: the request policy, global to the router, refuses a
|
|
53
|
-
// foreign Origin's upgrade as it does a request, and the rpcs spend the quota the routes
|
|
54
|
-
// spend, built once.
|
|
55
40
|
HttpRouter.serve(Layer.merge(publicRoutes, socket)).pipe(
|
|
56
41
|
Layer.provide(listen(publicPort))
|
|
57
42
|
),
|
|
58
43
|
HttpRouter.serve(adminRoutes).pipe(Layer.provide(listen(adminPort)))
|
|
59
44
|
).pipe(
|
|
60
|
-
// Request bodies have no size limit unless the host sets one. This covers every route
|
|
61
|
-
// that reads its body whole, on both ports, the MCP endpoint included.
|
|
62
45
|
Layer.provide(Layer.succeed(HttpServerRequest.MaxBodySize, limit)),
|
|
63
|
-
// What both ports share is provided outside both: the builders, as routes.ts says, then
|
|
64
|
-
// the services the verifiers and the quota are built from, so a workspace an operator
|
|
65
|
-
// suspends on one port is refused on the other.
|
|
66
46
|
Layer.provide(builders),
|
|
67
47
|
Layer.provide(memory),
|
|
68
|
-
// Webhook delivery POSTs with fetch, and resolves each callback with the system's resolver.
|
|
69
48
|
Layer.provide([FetchHttpClient.layer, NodeDns.layer])
|
|
70
49
|
);
|
|
71
50
|
})
|
|
72
51
|
);
|
|
73
52
|
|
|
74
|
-
// NodeRuntime handles signals: the scoped layers stop both listeners and release the services.
|
|
75
53
|
Layer.launch(server).pipe(NodeRuntime.runMain());
|
|
@@ -7,36 +7,26 @@ import { Tools } from "./Actions.js";
|
|
|
7
7
|
import { attachments } from "./attachments/handlers.js";
|
|
8
8
|
import { identity } from "./identity/handlers.js";
|
|
9
9
|
import { CurrentMember } from "./identity/Identity.js";
|
|
10
|
-
import {
|
|
10
|
+
import { demoMembers } from "./identity/members.js";
|
|
11
11
|
import { features } from "./issues/guide.js";
|
|
12
12
|
import { issues } from "./issues/handlers.js";
|
|
13
13
|
import { limiter, stores } from "./memory.js";
|
|
14
14
|
import { status } from "./workspaces/handlers.js";
|
|
15
15
|
import { WorkspaceRegistry } from "./workspaces/registry.js";
|
|
16
16
|
|
|
17
|
-
// Entrypoint: an MCP server a local agent starts as a subprocess, such as
|
|
18
|
-
// `claude mcp add tracker -- "$PWD/node_modules/.bin/tsx" "$PWD/examples/kitchen-sink/src/stdio.ts"`
|
|
19
|
-
// from the repository root. The host starts the process in a directory it chooses, so `tsx`
|
|
20
|
-
// and the file are named by full path.
|
|
21
|
-
// It lists the implementations it serves itself, and imports nothing of the HTTP router. They
|
|
22
|
-
// are those of the `/mcp` endpoint, with its tools and features and the same `authorize`.
|
|
23
|
-
// stdio is a local surface: it takes no `authentication`, since no token arrives.
|
|
24
17
|
ActionMcp.runStdio([status, identity, issues, attachments], {
|
|
25
18
|
name: "tracker",
|
|
26
19
|
version: "1.0.0",
|
|
27
20
|
actions: Tools,
|
|
28
21
|
features,
|
|
29
22
|
}).pipe(
|
|
30
|
-
|
|
31
|
-
// started it, from its own login or configuration.
|
|
32
|
-
Effect.provideService(CurrentMember, members.ada),
|
|
23
|
+
Effect.provideService(CurrentMember, demoMembers.ada),
|
|
33
24
|
Effect.provide([
|
|
34
25
|
NodeStdio.layer,
|
|
35
26
|
stores,
|
|
36
27
|
limiter,
|
|
37
28
|
WorkspaceRegistry.layerMemory,
|
|
38
29
|
]),
|
|
39
|
-
// stdout carries the protocol alone, so logs and failures go to stderr.
|
|
40
30
|
ActionCli.logToStderr,
|
|
41
31
|
NodeRuntime.runMain()
|
|
42
32
|
);
|
|
@@ -14,13 +14,9 @@ export class WorkspaceNotFound extends Schema.TaggedError<
|
|
|
14
14
|
{ readonly brand: unique symbol }
|
|
15
15
|
>()("WorkspaceNotFound", { slug: Schema.String }, { httpApiStatus: 404 }) {}
|
|
16
16
|
|
|
17
|
-
// Public: `caller: Action.Anyone`. It answers before anyone has signed in, on every surface,
|
|
18
|
-
// so it tells nothing that depends on the caller.
|
|
19
17
|
export const GetStatus = Action.make("getStatus", {
|
|
20
18
|
description:
|
|
21
19
|
"Report whether the tracker is up, since which start, and how many workspaces it serves.",
|
|
22
|
-
// `instance` names one start of the process: it changes on a restart, and with it the demo's
|
|
23
|
-
// memory stores are empty again.
|
|
24
20
|
success: {
|
|
25
21
|
service: Schema.String,
|
|
26
22
|
instance: Schema.String,
|
|
@@ -4,10 +4,6 @@ import { Effect } from "effect";
|
|
|
4
4
|
import { WorkspaceRegistry } from "./registry.js";
|
|
5
5
|
import { GetStatus } from "./Workspaces.js";
|
|
6
6
|
|
|
7
|
-
// One action, one handler, built once: the builder yields the registry at startup, and names
|
|
8
|
-
// this start of the process. Both ports serve this implementation, so what the builder makes
|
|
9
|
-
// tells whether they share one run of it (see `builders` in routes.ts). A public action takes
|
|
10
|
-
// no `authorize`: nothing would run it.
|
|
11
7
|
export const status = Action.implement(
|
|
12
8
|
GetStatus,
|
|
13
9
|
Effect.gen(function* () {
|
|
@@ -3,10 +3,6 @@ import { Context, Effect, Layer } from "effect";
|
|
|
3
3
|
import { WorkspaceNotFound } from "./Workspaces.js";
|
|
4
4
|
import type { Workspace } from "./Workspaces.js";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* The tenants. Operators list and suspend them on the admin port; authentication reads the
|
|
8
|
-
* suspension on the public one, so both servers must share this one service.
|
|
9
|
-
*/
|
|
10
6
|
export class WorkspaceRegistry extends Context.Service<
|
|
11
7
|
WorkspaceRegistry,
|
|
12
8
|
{
|
|
@@ -18,7 +14,6 @@ export class WorkspaceRegistry extends Context.Service<
|
|
|
18
14
|
) => Effect.Effect<Workspace, WorkspaceNotFound>;
|
|
19
15
|
}
|
|
20
16
|
>()("tracker/WorkspaceRegistry") {
|
|
21
|
-
// DEMO ONLY: two workspaces in memory. A real registry is another Layer of this service.
|
|
22
17
|
static readonly layerMemory = Layer.sync(WorkspaceRegistry, () => {
|
|
23
18
|
const workspaces = new Map<string, Workspace>([
|
|
24
19
|
["acme", { slug: "acme", name: "Acme", suspended: false }],
|
|
@@ -10,10 +10,6 @@ export class Tenant extends Context.Service<Tenant, Option.Option<string>>()(
|
|
|
10
10
|
"tracker/Tenant"
|
|
11
11
|
) {}
|
|
12
12
|
|
|
13
|
-
// Native router middleware. It provides `Tenant` to whatever it is provided to, per request:
|
|
14
|
-
// to the verifier too, when it is provided after the authentication, in a `Layer.provide` of
|
|
15
|
-
// its own: in one array with the authentication it would leave `Tenant` owed, since an array's
|
|
16
|
-
// layers provide to the routes, not to one another.
|
|
17
13
|
export const resolveTenant = HttpRouter.middleware<{ provides: Tenant }>()(
|
|
18
14
|
(route) =>
|
|
19
15
|
Effect.flatMap(HttpServerRequest.HttpServerRequest, (request) =>
|
|
@@ -63,7 +63,6 @@ describe("the operators", () => {
|
|
|
63
63
|
const client = yield* Action.client(admin);
|
|
64
64
|
const suspend = client.suspendWorkspace({ workspace: "globex" });
|
|
65
65
|
|
|
66
|
-
// No grants are stored for either: only the operator a host supplies is trusted.
|
|
67
66
|
expect(
|
|
68
67
|
yield* suspend.pipe(
|
|
69
68
|
Effect.provideService(Operator, { id: "console", trusted: true })
|
|
@@ -15,9 +15,6 @@ import { publicRoutes } from "../../src/routes.js";
|
|
|
15
15
|
import { down, scripted } from "../support/scripted.js";
|
|
16
16
|
import { services } from "../support/services.js";
|
|
17
17
|
|
|
18
|
-
// The assistant as its callers reach it: over HTTP, a request per turn, on the real routes in
|
|
19
|
-
// memory. Each test gives the routes the model it is about, in place of the demo one: the
|
|
20
|
-
// first `Layer.provide` is what the routes get.
|
|
21
18
|
const served = (model: Layer.Layer<LanguageModel.LanguageModel>) =>
|
|
22
19
|
Effect.provide(
|
|
23
20
|
Testing.layer(publicRoutes).pipe(
|
|
@@ -35,7 +32,6 @@ const signedIn = (token: string) => ({
|
|
|
35
32
|
),
|
|
36
33
|
});
|
|
37
34
|
|
|
38
|
-
// Ada may write in acme. Linus, in the same workspace, may only read.
|
|
39
35
|
const asAda = ActionHttp.client(Http, signedIn("ada"));
|
|
40
36
|
|
|
41
37
|
const asLinus = ActionHttp.client(Http, signedIn("linus"));
|
|
@@ -63,7 +59,6 @@ describe("the assistant, behind a route", () => {
|
|
|
63
59
|
body: "On save.",
|
|
64
60
|
});
|
|
65
61
|
|
|
66
|
-
// One request, two requests to the model: the second lets it read its tool's result.
|
|
67
62
|
const read = yield* ada.askAssistant({ prompt: "What is open?" });
|
|
68
63
|
|
|
69
64
|
expect(read).toMatchObject({
|
|
@@ -72,7 +67,6 @@ describe("the assistant, behind a route", () => {
|
|
|
72
67
|
waiting: [],
|
|
73
68
|
});
|
|
74
69
|
|
|
75
|
-
// The same conversation, a request later. The write has not run: the turn ended on it.
|
|
76
70
|
const asked = yield* ada.askAssistant({
|
|
77
71
|
conversation: read.conversation,
|
|
78
72
|
prompt: "Close it.",
|
|
@@ -153,8 +147,6 @@ describe("the assistant, behind a route", () => {
|
|
|
153
147
|
body: "On save.",
|
|
154
148
|
});
|
|
155
149
|
|
|
156
|
-
// Anyone signed in may ask. The tool's own `authorize` then refuses the reader's write,
|
|
157
|
-
// as a result the model reads.
|
|
158
150
|
const asked = yield* linus.askAssistant({ prompt: "Close it." });
|
|
159
151
|
|
|
160
152
|
const answered = yield* linus.answerAssistant({
|
|
@@ -195,13 +187,11 @@ describe("the assistant, behind a route", () => {
|
|
|
195
187
|
answers: approving(asked.waiting),
|
|
196
188
|
});
|
|
197
189
|
|
|
198
|
-
// The approved call ran, then the model failed: the error says so.
|
|
199
190
|
expect(yield* Effect.flip(answer)).toBeInstanceOf(AssistantFailed);
|
|
200
191
|
expect((yield* ada.getIssue({ id })).comments).toStrictEqual([
|
|
201
192
|
{ author: "ada", text: "Fixed." },
|
|
202
193
|
]);
|
|
203
194
|
|
|
204
|
-
// The same answer, sent again, runs nothing: its conversation is gone.
|
|
205
195
|
expect(yield* Effect.flip(answer)).toStrictEqual(
|
|
206
196
|
new ConversationNotFound({ conversation: asked.conversation })
|
|
207
197
|
);
|
|
@@ -310,7 +300,6 @@ describe("the assistant, behind a route", () => {
|
|
|
310
300
|
answers: first === undefined ? [] : [first],
|
|
311
301
|
});
|
|
312
302
|
|
|
313
|
-
// The call left open is listed again, in every turn until it is answered.
|
|
314
303
|
expect(answered).toMatchObject({ ran: [{ tool: "commentOnIssue" }] });
|
|
315
304
|
expect(answered.waiting).toStrictEqual([
|
|
316
305
|
{
|
|
@@ -373,7 +362,6 @@ describe("the assistant, behind a route", () => {
|
|
|
373
362
|
answers: close === undefined ? [] : [close],
|
|
374
363
|
});
|
|
375
364
|
|
|
376
|
-
// Each answer runs its own call: the close ran, the comment still waits.
|
|
377
365
|
expect(closed.ran).toStrictEqual([
|
|
378
366
|
{ tool: "closeIssue", failed: false },
|
|
379
367
|
]);
|
|
@@ -393,8 +381,6 @@ describe("the assistant, behind a route", () => {
|
|
|
393
381
|
)
|
|
394
382
|
);
|
|
395
383
|
|
|
396
|
-
// A provider gives each call an id of its own. Where a model does not, Effect runs the last
|
|
397
|
-
// call with the id an approval names: the list shows that call, not the one first asked.
|
|
398
384
|
it.effect(
|
|
399
385
|
"lists, for a call id a model used twice, the call an approval would run",
|
|
400
386
|
() =>
|
|
@@ -541,8 +527,6 @@ describe("the assistant, behind a route", () => {
|
|
|
541
527
|
})
|
|
542
528
|
);
|
|
543
529
|
|
|
544
|
-
// A double click, or a client's retry. One turn runs at a time, and the one that waited
|
|
545
|
-
// finds its conversation ended by the one that failed.
|
|
546
530
|
const refusals = yield* Effect.all([answer, answer], {
|
|
547
531
|
concurrency: 2,
|
|
548
532
|
});
|
|
@@ -566,7 +550,6 @@ describe("the assistant, behind a route", () => {
|
|
|
566
550
|
it.effect(
|
|
567
551
|
"ends the conversation of a turn that is interrupted after its approved call ran",
|
|
568
552
|
() => {
|
|
569
|
-
// Completed when the model is asked what to say about the approved call's result.
|
|
570
553
|
const thinking = Deferred.makeUnsafe<undefined>();
|
|
571
554
|
|
|
572
555
|
return Effect.gen(function* () {
|
|
@@ -584,7 +567,6 @@ describe("the assistant, behind a route", () => {
|
|
|
584
567
|
answers: approving(asked.waiting),
|
|
585
568
|
});
|
|
586
569
|
|
|
587
|
-
// The client goes away while the model is thinking, after the approved call ran.
|
|
588
570
|
const leaving = yield* Effect.forkChild(answer);
|
|
589
571
|
|
|
590
572
|
yield* Deferred.await(thinking);
|
|
@@ -26,7 +26,6 @@ const as = (token: string, workspace: string) => ({
|
|
|
26
26
|
transformClient: HttpClient.mapRequest(signedIn(token, workspace)),
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
// A one-pixel PNG stands in for a screenshot.
|
|
30
29
|
const screenshot = Buffer.from(
|
|
31
30
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
|
|
32
31
|
"base64"
|
|
@@ -58,15 +57,12 @@ describe("attachments, over HTTP and MCP", () => {
|
|
|
58
57
|
size: 68,
|
|
59
58
|
});
|
|
60
59
|
|
|
61
|
-
// Both clients decode the same success, the bytes a `Uint8Array` again.
|
|
62
60
|
const overHttp = yield* http.getAttachment({ id: attachment.id });
|
|
63
61
|
const overMcp = yield* mcp.getAttachment({ id: attachment.id });
|
|
64
62
|
|
|
65
63
|
expect(Buffer.from(overHttp.image.data).equals(screenshot)).toBe(true);
|
|
66
64
|
expect(overMcp).toStrictEqual(overHttp);
|
|
67
65
|
|
|
68
|
-
// As sent: the tool's result holds the rest of the success as JSON, and the image as a
|
|
69
|
-
// content block of its own, which a model receives as an image.
|
|
70
66
|
const call = yield* HttpClient.execute(
|
|
71
67
|
ActionMcp.request(
|
|
72
68
|
"tools/call",
|
|
@@ -112,7 +108,6 @@ describe("attachments, over HTTP and MCP", () => {
|
|
|
112
108
|
const attachment = yield* attached;
|
|
113
109
|
const ada = yield* ActionHttp.client(Http, as("ada", "acme"));
|
|
114
110
|
|
|
115
|
-
// `attached` spent two writes, an issue and its image. Eight comments spend the rest.
|
|
116
111
|
yield* Effect.forEach(Array.range(1, 8), (n) =>
|
|
117
112
|
ada.commentOnIssue({ id: attachment.issue, text: `Comment ${n}` })
|
|
118
113
|
);
|
|
@@ -155,7 +150,6 @@ describe("attachments, over HTTP and MCP", () => {
|
|
|
155
150
|
expect(mine.headers["cache-control"]).toBe(
|
|
156
151
|
"private, max-age=31536000, immutable"
|
|
157
152
|
);
|
|
158
|
-
// An uploaded image opened by its URL is a document on this origin: it gets no scripts.
|
|
159
153
|
expect([
|
|
160
154
|
mine.headers["content-security-policy"],
|
|
161
155
|
mine.headers["x-content-type-options"],
|
|
@@ -184,15 +178,12 @@ describe("attachments, over HTTP and MCP", () => {
|
|
|
184
178
|
|
|
185
179
|
const withoutScope = yield* HttpClient.execute(withCookie(download));
|
|
186
180
|
|
|
187
|
-
// A cookie scheme has no challenge. A token is no credential on this route.
|
|
188
181
|
expect([
|
|
189
182
|
signedOut.status,
|
|
190
183
|
signedOut.headers["cache-control"],
|
|
191
184
|
]).toStrictEqual([401, "no-store"]);
|
|
192
185
|
expect(signedOut.headers["www-authenticate"]).toBeUndefined();
|
|
193
186
|
expect(withToken.status).toBe(401);
|
|
194
|
-
// kay is signed in, in the right workspace, without the read scope: the route's own
|
|
195
|
-
// `authorize` refuses.
|
|
196
187
|
expect(withoutScope.status).toBe(403);
|
|
197
188
|
expect(yield* withoutScope.json).toMatchObject({
|
|
198
189
|
message: "Requires issues:read.",
|
|
@@ -17,19 +17,14 @@ import {
|
|
|
17
17
|
import { publicRoutes } from "../../src/routes.js";
|
|
18
18
|
import { services } from "../support/services.js";
|
|
19
19
|
|
|
20
|
-
// What authentication adds on the wire: the public port behind its real providers, answering
|
|
21
|
-
// in memory. A caller is the credential its client sends.
|
|
22
20
|
const served = Testing.layer(publicRoutes).pipe(Layer.provide(services()));
|
|
23
21
|
|
|
24
|
-
// A test replaces the one service it is about. Provided before `services`, this layer is the
|
|
25
|
-
// `Directory` the routes are built with; `services` gives them the rest.
|
|
26
22
|
const servedWith = (directory: Layer.Layer<Directory>) =>
|
|
27
23
|
Testing.layer(publicRoutes).pipe(
|
|
28
24
|
Layer.provide(directory),
|
|
29
25
|
Layer.provide(services())
|
|
30
26
|
);
|
|
31
27
|
|
|
32
|
-
// A directory that cannot reach its issuer.
|
|
33
28
|
const issuerDown = Layer.succeed(
|
|
34
29
|
Directory,
|
|
35
30
|
Directory.of({
|
|
@@ -64,7 +59,6 @@ describe("a bearer token", () => {
|
|
|
64
59
|
scopes: ["issues:read"],
|
|
65
60
|
});
|
|
66
61
|
|
|
67
|
-
// A member of acme alone, asking for globex: refused, with no scope to step up to.
|
|
68
62
|
const refused = yield* Effect.flip(elsewhere.whoAmI());
|
|
69
63
|
|
|
70
64
|
expect(refused).toBeInstanceOf(Action.Forbidden);
|
|
@@ -89,7 +83,6 @@ describe("a bearer token", () => {
|
|
|
89
83
|
);
|
|
90
84
|
expect(refused.message).toBe("Requires issues:write.");
|
|
91
85
|
|
|
92
|
-
// The same refusal as sent: the 403 an OAuth client re-authorizes on.
|
|
93
86
|
const response = yield* HttpClientRequest.post(
|
|
94
87
|
"/api/v1/closeIssue"
|
|
95
88
|
).pipe(
|
|
@@ -119,7 +112,6 @@ describe("a bearer token", () => {
|
|
|
119
112
|
scopes_supported: ["issues:read", "issues:write"],
|
|
120
113
|
});
|
|
121
114
|
|
|
122
|
-
// A protected tool's call without a token: the endpoint's own 401, before any tool runs.
|
|
123
115
|
const refused = yield* HttpClient.execute(
|
|
124
116
|
ActionMcp.request("tools/call", { name: "whoAmI", arguments: {} })
|
|
125
117
|
);
|
|
@@ -137,8 +129,6 @@ describe("a bearer token", () => {
|
|
|
137
129
|
Effect.gen(function* () {
|
|
138
130
|
const http = yield* ActionHttp.client(Http, as("ada", "acme"));
|
|
139
131
|
|
|
140
|
-
// Over MCP it is the endpoint's HTTP answer, before any tool runs, not a tool's result: the
|
|
141
|
-
// client decodes it given the descriptor the endpoint serves with.
|
|
142
132
|
const mcp = yield* ActionMcp.client([WhoAmI], {
|
|
143
133
|
...as("ada", "acme"),
|
|
144
134
|
authentication: Login,
|
|
@@ -15,8 +15,6 @@ import { Rpc } from "../../src/Rpc.js";
|
|
|
15
15
|
import { WorkspaceRegistry } from "../../src/workspaces/registry.js";
|
|
16
16
|
import { services } from "../support/services.js";
|
|
17
17
|
|
|
18
|
-
// The web app's rpcs in memory. The server serves them over a WebSocket; here the same layer
|
|
19
|
-
// is given Effect's HTTP protocol, which a client reaches through `Testing.layer`.
|
|
20
18
|
const server = rpc.pipe(
|
|
21
19
|
Layer.provide(RpcServer.layerProtocolHttp({ path: "/rpc" })),
|
|
22
20
|
Layer.provide(RpcSerialization.layerJson)
|
|
@@ -28,19 +26,13 @@ const protocol = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
|
|
|
28
26
|
|
|
29
27
|
const socket = protocol.pipe(Layer.provide(Testing.layer(server)));
|
|
30
28
|
|
|
31
|
-
// `provideMerge`: the test reads the registry the rpcs' verifier reads.
|
|
32
29
|
const served = socket.pipe(Layer.provideMerge(memory));
|
|
33
30
|
|
|
34
|
-
// The rpcs beside the public port's routes under one `Testing.layer`, as server.ts serves them
|
|
35
|
-
// under one router, there over a WebSocket. `provideMerge`: the test calls the JSON routes
|
|
36
|
-
// with the `HttpClient` the rpc client's protocol is given.
|
|
37
31
|
const servedWithHttp = protocol.pipe(
|
|
38
32
|
Layer.provideMerge(Testing.layer(Layer.merge(server, publicRoutes))),
|
|
39
33
|
Layer.provide(services())
|
|
40
34
|
);
|
|
41
35
|
|
|
42
|
-
// Each call carries its caller's session cookie, as a browser attaches it, so one client
|
|
43
|
-
// serves several callers. Authentication is per message.
|
|
44
36
|
const as = (session: string) =>
|
|
45
37
|
RpcClient.withHeaders({ cookie: `tracker_session=${session}` });
|
|
46
38
|
|
|
@@ -116,8 +108,6 @@ describe("a session cookie, over RPC", () => {
|
|
|
116
108
|
),
|
|
117
109
|
});
|
|
118
110
|
|
|
119
|
-
// Sixty requests as ada in acme, half on each surface: each middleware counts, and the
|
|
120
|
-
// next request is refused on either.
|
|
121
111
|
yield* Effect.forEach(Array.range(1, 30), () => http.whoAmI());
|
|
122
112
|
yield* Effect.forEach(Array.range(1, 30), () =>
|
|
123
113
|
rpcs.whoAmI().pipe(as("ada-at-acme"))
|
|
@@ -4,12 +4,11 @@ import { Effect, Layer, Stream } from "effect";
|
|
|
4
4
|
import { LanguageModel } from "effect/ai";
|
|
5
5
|
|
|
6
6
|
import { CurrentMember } from "../../src/identity/Identity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { demoMembers } from "../../src/identity/members.js";
|
|
8
8
|
import { layer, toolkit, triage } from "../../src/issues/assistant.js";
|
|
9
9
|
import { issues } from "../../src/issues/handlers.js";
|
|
10
10
|
import { memory } from "../../src/memory.js";
|
|
11
11
|
|
|
12
|
-
// A model that asks for the same two tools in every turn stands in for a provider's.
|
|
13
12
|
const model = LanguageModel.make({
|
|
14
13
|
generateText: () =>
|
|
15
14
|
Effect.succeed([
|
|
@@ -29,9 +28,8 @@ const model = LanguageModel.make({
|
|
|
29
28
|
streamText: () => Stream.empty,
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
const asAda = Effect.provideService(CurrentMember,
|
|
31
|
+
const asAda = Effect.provideService(CurrentMember, demoMembers.ada);
|
|
33
32
|
|
|
34
|
-
// The toolkit's handlers and a client of the same implementation, over one store.
|
|
35
33
|
const services = layer.pipe(Layer.provideMerge(memory));
|
|
36
34
|
|
|
37
35
|
describe("the assistant's tools", () => {
|
|
@@ -75,13 +73,11 @@ describe("the assistant's tools", () => {
|
|
|
75
73
|
"closeIssue",
|
|
76
74
|
]);
|
|
77
75
|
|
|
78
|
-
// `tools.handle` is a caller that is not a model's turn: it asks no approval, and takes
|
|
79
|
-
// the arguments as JSON. The implementation's `authorize` runs all the same.
|
|
80
76
|
const refused = yield* tools
|
|
81
77
|
.handle("closeIssue", { id: "ACME-1" })
|
|
82
78
|
.pipe(
|
|
83
79
|
Effect.flatMap(Stream.runCollect),
|
|
84
|
-
Effect.provideService(CurrentMember,
|
|
80
|
+
Effect.provideService(CurrentMember, demoMembers.linus)
|
|
85
81
|
);
|
|
86
82
|
|
|
87
83
|
expect(
|