@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
|
@@ -7,32 +7,22 @@ import { CurrentMember, Session } from "../identity/Identity.js";
|
|
|
7
7
|
import { GetAttachment } from "./Attachments.js";
|
|
8
8
|
import { AttachmentStore } from "./store.js";
|
|
9
9
|
|
|
10
|
-
// A route of the host's own: `GET /attachments/<id>` answers the image's bytes, for an `<img>`
|
|
11
|
-
// of the web app, which no action can (an action answers JSON), behind
|
|
12
|
-
// `Authentication.protect(Session)`: the page's cookie, which the web app's rpcs use. A token
|
|
13
|
-
// holder has no use for it: `getAttachment` gives an API client the same image.
|
|
14
10
|
export const download = Layer.unwrap(
|
|
15
11
|
Effect.map(AttachmentStore, (store) =>
|
|
16
12
|
HttpRouter.add(
|
|
17
13
|
"GET",
|
|
18
14
|
"/attachments/:id",
|
|
19
15
|
Effect.gen(function* () {
|
|
20
|
-
// The rule of the action it mirrors.
|
|
21
16
|
yield* authorize(GetAttachment);
|
|
22
17
|
|
|
23
18
|
const member = yield* CurrentMember;
|
|
24
19
|
const { id = "" } = yield* HttpRouter.params;
|
|
25
20
|
const { image } = yield* store.get(member.workspace, id);
|
|
26
21
|
|
|
27
|
-
// An attachment never changes, but it is one workspace's: `private`.
|
|
28
22
|
return HttpServerResponse.uint8Array(image.data, {
|
|
29
23
|
contentType: image.mimeType,
|
|
30
24
|
headers: {
|
|
31
25
|
"cache-control": "private, max-age=31536000, immutable",
|
|
32
|
-
// What a member uploaded is served from the application's own origin, and an image
|
|
33
|
-
// can be a document: an SVG opened by its URL, not in an `<img>`, runs its scripts
|
|
34
|
-
// as the member reading it. `sandbox` gives it no origin and no scripts, and
|
|
35
|
-
// `nosniff` keeps the browser to the type stated.
|
|
36
26
|
"content-security-policy": "sandbox",
|
|
37
27
|
"x-content-type-options": "nosniff",
|
|
38
28
|
},
|
|
@@ -11,14 +11,11 @@ export const attachments = Action.implement(
|
|
|
11
11
|
Attachments,
|
|
12
12
|
Effect.gen(function* () {
|
|
13
13
|
const store = yield* AttachmentStore;
|
|
14
|
-
// The issues' write limit: an attachment counts against the same ten writes a minute.
|
|
15
14
|
const limited = yield* writeLimit;
|
|
16
15
|
|
|
17
16
|
return {
|
|
18
17
|
attachImage: ({ issue, name, image }) =>
|
|
19
18
|
Effect.gen(function* () {
|
|
20
|
-
// Input that decodes but cannot be served is `InvalidInput`; its `issues` name the
|
|
21
|
-
// field, as the library's own do for input that does not decode.
|
|
22
19
|
if (!image.mimeType.startsWith("image/")) {
|
|
23
20
|
const message = "Expected an image MIME type.";
|
|
24
21
|
|
|
@@ -13,7 +13,6 @@ interface Stored {
|
|
|
13
13
|
readonly image: Image;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/** Images attached to issues, each in its issue's workspace, as `IssueStore` keeps issues. */
|
|
17
16
|
export class AttachmentStore extends Context.Service<
|
|
18
17
|
AttachmentStore,
|
|
19
18
|
{
|
|
@@ -29,8 +28,6 @@ export class AttachmentStore extends Context.Service<
|
|
|
29
28
|
) => Effect.Effect<Stored, AttachmentNotFound>;
|
|
30
29
|
}
|
|
31
30
|
>()("tracker/AttachmentStore") {
|
|
32
|
-
// DEMO ONLY: memory. A service captures what it depends on when it is built, here the issue
|
|
33
|
-
// store, so its methods require nothing.
|
|
34
31
|
static readonly layerMemory = Layer.effect(
|
|
35
32
|
AttachmentStore,
|
|
36
33
|
Effect.gen(function* () {
|
|
@@ -5,8 +5,6 @@ import { Socket } from "effect/socket";
|
|
|
5
5
|
|
|
6
6
|
import { Rpc } from "./Rpc.js";
|
|
7
7
|
|
|
8
|
-
// Entrypoint of the web app, an Effect program in a page. It imports the RPC binding and
|
|
9
|
-
// nothing of the server. Its client has the methods of `ActionHttp.client`, over one socket.
|
|
10
8
|
export const board = Effect.gen(function* () {
|
|
11
9
|
const tracker = yield* ActionRpc.client(Rpc);
|
|
12
10
|
|
|
@@ -16,10 +14,6 @@ export const board = Effect.gen(function* () {
|
|
|
16
14
|
return { me, issues };
|
|
17
15
|
});
|
|
18
16
|
|
|
19
|
-
// Effect's own client protocol: a WebSocket speaking the server's JSON. The page sends no
|
|
20
|
-
// credential itself: the browser attaches the session cookie to the upgrade, and the server
|
|
21
|
-
// authenticates every message with it. A client that cannot rely on a cookie, such as a script,
|
|
22
|
-
// sends a header on each message instead, with `RpcClient.withHeaders`.
|
|
23
17
|
export const protocol = (url: string) =>
|
|
24
18
|
RpcClient.layerProtocolSocket().pipe(
|
|
25
19
|
Layer.provide(Socket.layerWebSocket(url)),
|
|
@@ -29,9 +23,6 @@ export const protocol = (url: string) =>
|
|
|
29
23
|
])
|
|
30
24
|
);
|
|
31
25
|
|
|
32
|
-
// `open("wss://tracker.example.com/rpc")`: one run on a socket of its own, closed when it ends.
|
|
33
|
-
// A page that stays connected builds the protocol's Layer once, such as in a `ManagedRuntime`,
|
|
34
|
-
// and runs its programs in it.
|
|
35
26
|
export const open = async (url: string) =>
|
|
36
27
|
await Effect.runPromise(
|
|
37
28
|
board.pipe(Effect.scoped, Effect.provide(protocol(url)))
|
|
@@ -13,19 +13,9 @@ import { Http } from "./Api.js";
|
|
|
13
13
|
|
|
14
14
|
const unchanged = (request: HttpClientRequest.HttpClientRequest) => request;
|
|
15
15
|
|
|
16
|
-
// Entrypoint: `node --import tsx examples/kitchen-sink/src/cli.ts list-issues`.
|
|
17
|
-
// The members' CLI: a command per action of the binding, a flag per input field, each calling
|
|
18
|
-
// the server over HTTP. It imports the binding alone and runs nothing locally: the server
|
|
19
|
-
// authenticates and authorizes, as for any client. The binding's event adds `tracker watch
|
|
20
|
-
// issue.changed --status open`, printing each change of the member's workspace as a line of
|
|
21
|
-
// JSON as it happens; `--cursor` resumes from the last one's.
|
|
22
16
|
const tracker = ActionCli.remote(Http, {
|
|
23
17
|
name: "tracker",
|
|
24
|
-
// Each command's options, keyed by its action's name and typed by that action.
|
|
25
18
|
commands: {
|
|
26
|
-
// `tracker list-issues -n 5 -s open`: short flags, and text instead of JSON (`--json` gives
|
|
27
|
-
// the JSON back). Its help says so: the action's description, which HTTP and MCP keep, says
|
|
28
|
-
// what the JSON holds.
|
|
29
19
|
listIssues: {
|
|
30
20
|
description:
|
|
31
21
|
"List your workspace's issues, newest first, one line each: id, status, title.",
|
|
@@ -35,7 +25,6 @@ const tracker = ActionCli.remote(Http, {
|
|
|
35
25
|
.map(({ id, status, title }) => `${id} ${status} ${title}`)
|
|
36
26
|
.join("\n"),
|
|
37
27
|
},
|
|
38
|
-
// `tracker get-issue ACME-1`: the id is an argument, not a flag.
|
|
39
28
|
getIssue: {
|
|
40
29
|
positional: ["id"],
|
|
41
30
|
render: (issue) =>
|
|
@@ -45,26 +34,18 @@ const tracker = ActionCli.remote(Http, {
|
|
|
45
34
|
...issue.comments.map(({ author, text }) => `- ${author}: ${text}`),
|
|
46
35
|
].join("\n"),
|
|
47
36
|
},
|
|
48
|
-
// `tracker create-issue --title Crash < report.md`: the body is piped in.
|
|
49
37
|
createIssue: { stdin: "body" },
|
|
50
38
|
commentOnIssue: { name: "comment", positional: ["id"], stdin: "text" },
|
|
51
39
|
closeIssue: { name: "close", positional: ["id"] },
|
|
52
|
-
// An action answering a stream: `render` takes each issue, printed as it arrives, one line
|
|
53
|
-
// each; `--json` prints each as a line of JSON instead, so `tracker export-issues --json >
|
|
54
|
-
// issues.jsonl` writes JSON Lines.
|
|
55
40
|
exportIssues: {
|
|
56
41
|
render: ({ id, status, title }) => `${id} ${status} ${title}`,
|
|
57
42
|
},
|
|
58
|
-
// `render` receives the decoded success, the image's bytes a `Uint8Array`.
|
|
59
43
|
getAttachment: {
|
|
60
44
|
positional: ["id"],
|
|
61
45
|
render: ({ attachment, image }) =>
|
|
62
46
|
`${attachment.name}: ${image.mimeType}, ${image.data.byteLength} bytes`,
|
|
63
47
|
},
|
|
64
48
|
},
|
|
65
|
-
// The connection. The token and the workspace are optional: `tracker get-status` is public
|
|
66
|
-
// and needs neither, and any other command without a token gets the server's 401, and without
|
|
67
|
-
// a workspace its 403.
|
|
68
49
|
client: Effect.gen(function* () {
|
|
69
50
|
const baseUrl = yield* Config.String("TRACKER_URL").pipe(
|
|
70
51
|
Config.withDefault("http://127.0.0.1:3000")
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { Config } from "effect";
|
|
2
2
|
|
|
3
|
-
// What a deployment sets. A `Config` is only a description: each is read where a layer is
|
|
4
|
-
// built, so importing this file reads nothing, and a test runs on the defaults.
|
|
5
|
-
|
|
6
|
-
/** Where callers reach the public port: the OAuth resource, and a Host the server answers to. */
|
|
7
3
|
export const publicUrl = Config.String("PUBLIC_URL").pipe(
|
|
8
4
|
Config.withDefault("http://localhost:3000")
|
|
9
5
|
);
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* and one other, a browser MCP client's.
|
|
14
|
-
*/
|
|
7
|
+
const demoInspectorOrigin = "http://localhost:6274";
|
|
8
|
+
|
|
15
9
|
export const allowedOrigins = Config.all([
|
|
16
10
|
publicUrl,
|
|
17
|
-
|
|
18
|
-
// passes the request policy and CORS, so a deployment names its own client's.
|
|
19
|
-
Config.String("MCP_ORIGIN").pipe(Config.withDefault("http://localhost:6274")),
|
|
11
|
+
Config.String("MCP_ORIGIN").pipe(Config.withDefault(demoInspectorOrigin)),
|
|
20
12
|
]).pipe(Config.map(([url, mcp]) => [new URL(url).origin, mcp]));
|
|
@@ -7,23 +7,16 @@ export const scopes = { read: "issues:read", write: "issues:write" } as const;
|
|
|
7
7
|
|
|
8
8
|
export const Scope = Schema.Literals([scopes.read, scopes.write]);
|
|
9
9
|
|
|
10
|
-
/** A person acting in one workspace, with the scopes their credential holds there. */
|
|
11
10
|
export interface Member {
|
|
12
11
|
readonly id: string;
|
|
13
12
|
readonly workspace: string;
|
|
14
13
|
readonly scopes: ReadonlyArray<typeof Scope.Type>;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
/**
|
|
18
|
-
* Who is calling. A protected action declares it, `caller: CurrentMember`; authentication
|
|
19
|
-
* provides it per request, and a local host (stdio, the assistant, a test) provides it itself.
|
|
20
|
-
*/
|
|
21
16
|
export class CurrentMember extends Context.Service<CurrentMember, Member>()(
|
|
22
17
|
"tracker/CurrentMember"
|
|
23
18
|
) {}
|
|
24
19
|
|
|
25
|
-
// What a verifier may fail with besides a refusal: the issuer it checks tokens with is down.
|
|
26
|
-
// It is not the caller's fault, so it is no 401: signing in again cannot help.
|
|
27
20
|
export class IssuerUnavailable extends Schema.TaggedError<
|
|
28
21
|
IssuerUnavailable,
|
|
29
22
|
{ readonly brand: unique symbol }
|
|
@@ -33,25 +26,15 @@ export class IssuerUnavailable extends Schema.TaggedError<
|
|
|
33
26
|
{ httpApiStatus: 503 }
|
|
34
27
|
) {}
|
|
35
28
|
|
|
36
|
-
// How an API client, the CLI and an MCP client prove they are CurrentMember: a bearer token,
|
|
37
|
-
// the default scheme. `principal` names one subscriber, for what MCP and HTTP hold between its
|
|
38
|
-
// requests, such as its webhook subscriptions: a member of two workspaces is two subscribers,
|
|
39
|
-
// so it names the workspace too, encoded so no two pairs spell one principal.
|
|
40
29
|
export const Login = Authentication.make("tracker.Login", CurrentMember, {
|
|
41
30
|
error: IssuerUnavailable,
|
|
42
31
|
principal: (member) => JSON.stringify([member.workspace, member.id]),
|
|
43
32
|
});
|
|
44
33
|
|
|
45
|
-
// How the web app proves the same identity: the session cookie its sign-in page set. It is
|
|
46
|
-
// named by what accepts it: `Rpc`, the web app's socket, and the route its pages load an
|
|
47
|
-
// attachment's image from.
|
|
48
34
|
export const Session = Authentication.make("tracker.Session", CurrentMember, {
|
|
49
35
|
security: HttpApiSecurity.apiKey({ in: "cookie", key: "tracker_session" }),
|
|
50
36
|
});
|
|
51
37
|
|
|
52
|
-
// What the API's request quota answers with. It is the bindings' error, not an action's:
|
|
53
|
-
// middleware sends it on any action's route, before its input is decoded. Only HTTP and RPC
|
|
54
|
-
// have that middleware.
|
|
55
38
|
export class QuotaExceeded extends Schema.TaggedError<
|
|
56
39
|
QuotaExceeded,
|
|
57
40
|
{ readonly brand: unique symbol }
|
|
@@ -61,7 +44,6 @@ export class QuotaExceeded extends Schema.TaggedError<
|
|
|
61
44
|
{ httpApiStatus: 429 }
|
|
62
45
|
) {}
|
|
63
46
|
|
|
64
|
-
// An action without input: its client method takes no argument, its command no flag.
|
|
65
47
|
export const WhoAmI = Action.make("whoAmI", {
|
|
66
48
|
description:
|
|
67
49
|
"Show who the credential identifies, in which workspace, with which scopes.",
|
|
@@ -10,8 +10,6 @@ import { Directory } from "./directory.js";
|
|
|
10
10
|
import { Login, scopes, Session } from "./Identity.js";
|
|
11
11
|
import type { Member } from "./Identity.js";
|
|
12
12
|
|
|
13
|
-
// What both verifiers check once a credential has named a member: an operator may have
|
|
14
|
-
// suspended the workspace. Checked here, it holds on every remote surface.
|
|
15
13
|
const inService = Effect.gen(function* () {
|
|
16
14
|
const registry = yield* WorkspaceRegistry;
|
|
17
15
|
|
|
@@ -21,8 +19,6 @@ const inService = Effect.gen(function* () {
|
|
|
21
19
|
Effect.orElseSucceed(() => true)
|
|
22
20
|
);
|
|
23
21
|
|
|
24
|
-
// No scopes named: signing in again grants nothing, so this is a plain 403, never a
|
|
25
|
-
// challenge sending an OAuth client back to its authorization server.
|
|
26
22
|
if (suspended) {
|
|
27
23
|
return yield* new Action.Forbidden({
|
|
28
24
|
message: "This workspace is suspended.",
|
|
@@ -33,24 +29,20 @@ const inService = Effect.gen(function* () {
|
|
|
33
29
|
});
|
|
34
30
|
});
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
const demoAuthorizationServer = "https://auth.example.com";
|
|
33
|
+
|
|
38
34
|
const protectedResource = Effect.map(
|
|
39
35
|
publicUrl,
|
|
40
36
|
(url) =>
|
|
41
37
|
({
|
|
42
38
|
resource: `${url}/mcp`,
|
|
43
|
-
|
|
44
|
-
authorizationServers: ["https://auth.example.com"],
|
|
39
|
+
authorizationServers: [demoAuthorizationServer],
|
|
45
40
|
scopesSupported: [scopes.read, scopes.write],
|
|
46
41
|
scopesRequired: [scopes.read],
|
|
47
42
|
resourceName: "Tracker",
|
|
48
43
|
}) satisfies Authentication.ProtectedResource
|
|
49
44
|
);
|
|
50
45
|
|
|
51
|
-
// Server only: `Login`'s provider. The Effect is a builder, as `Action.implement` takes one:
|
|
52
|
-
// it yields the startup services once, and returns the verifier, which runs per request and
|
|
53
|
-
// may read request services, here the `Tenant` router middleware provides.
|
|
54
46
|
export const authenticateBearer = Authentication.layer(
|
|
55
47
|
Login,
|
|
56
48
|
Effect.gen(function* () {
|
|
@@ -78,9 +70,6 @@ export const authenticateBearer = Authentication.layer(
|
|
|
78
70
|
{ protectedResource }
|
|
79
71
|
);
|
|
80
72
|
|
|
81
|
-
// `Session`'s provider: the same identity from another credential. Its verifier receives what
|
|
82
|
-
// its scheme decodes, the cookie's value. A session belongs to one workspace, so it reads no
|
|
83
|
-
// `Tenant`.
|
|
84
73
|
export const authenticateSession = Authentication.layer(
|
|
85
74
|
Session,
|
|
86
75
|
Effect.gen(function* () {
|
|
@@ -4,15 +4,9 @@ import { Effect } from "effect";
|
|
|
4
4
|
|
|
5
5
|
import { CurrentMember, scopes } from "./Identity.js";
|
|
6
6
|
|
|
7
|
-
// The members' rule, read from each contract: a read needs the read scope, anything else the
|
|
8
|
-
// write scope. The implementations of issues and attachments state it, so every surface serving
|
|
9
|
-
// them runs it before the handler: HTTP, MCP, RPC, stdio, the assistant's tools and a test alike.
|
|
10
|
-
// For a bearer token, naming the missing scope turns the 403 into the challenge an OAuth client
|
|
11
|
-
// re-authorizes on.
|
|
12
7
|
export const authorize = Effect.fn("authorize")(function* (
|
|
13
8
|
contract: Action.Any | Event.Any
|
|
14
9
|
) {
|
|
15
|
-
// A subscription to an event reads, as a `readOnly` action does.
|
|
16
10
|
const scope =
|
|
17
11
|
Event.isEvent(contract) || contract.readOnly ? scopes.read : scopes.write;
|
|
18
12
|
|
|
@@ -2,44 +2,34 @@ import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
|
2
2
|
import { Context, Effect, Layer, Redacted } from "effect";
|
|
3
3
|
|
|
4
4
|
import type { IssuerUnavailable, Member } from "./Identity.js";
|
|
5
|
-
import {
|
|
5
|
+
import { demoMembers } from "./members.js";
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Who a credential names. It is a startup service: the verifiers yield it once, when their
|
|
9
|
-
* layer is built, and call it per request.
|
|
10
|
-
*/
|
|
11
7
|
export class Directory extends Context.Service<
|
|
12
8
|
Directory,
|
|
13
9
|
{
|
|
14
|
-
/** Every membership of the account an access token was issued to. */
|
|
15
10
|
readonly ofToken: (
|
|
16
11
|
token: Redacted.Redacted
|
|
17
12
|
) => Effect.Effect<
|
|
18
13
|
readonly Member[],
|
|
19
14
|
Action.Unauthenticated | IssuerUnavailable
|
|
20
15
|
>;
|
|
21
|
-
/** The member a web session was opened for: a session belongs to one workspace. */
|
|
22
16
|
readonly ofSession: (
|
|
23
17
|
session: Redacted.Redacted
|
|
24
18
|
) => Effect.Effect<Member, Action.Unauthenticated>;
|
|
25
19
|
}
|
|
26
20
|
>()("tracker/Directory") {
|
|
27
|
-
// DEMO ONLY: a token is an account's name (`ada`, `linus`, `kay`, `grace`) and a session a fixed
|
|
28
|
-
// string. A real directory checks a signed token with the authorization server's library,
|
|
29
|
-
// its audience included, failing with `IssuerUnavailable` when it cannot reach its keys, and
|
|
30
|
-
// reads sessions from their store.
|
|
31
21
|
static readonly layerDemo = Layer.sync(Directory, () => {
|
|
32
22
|
const accounts = new Map<string, readonly Member[]>([
|
|
33
|
-
["ada", [
|
|
34
|
-
["linus", [
|
|
35
|
-
["kay", [
|
|
36
|
-
["grace", [
|
|
23
|
+
["ada", [demoMembers.ada, demoMembers.adaAtGlobex]],
|
|
24
|
+
["linus", [demoMembers.linus]],
|
|
25
|
+
["kay", [demoMembers.kay]],
|
|
26
|
+
["grace", [demoMembers.grace]],
|
|
37
27
|
]);
|
|
38
28
|
|
|
39
29
|
const sessions = new Map<string, Member>([
|
|
40
|
-
["ada-at-acme",
|
|
41
|
-
["kay-at-acme",
|
|
42
|
-
["grace-at-globex",
|
|
30
|
+
["ada-at-acme", demoMembers.ada],
|
|
31
|
+
["kay-at-acme", demoMembers.kay],
|
|
32
|
+
["grace-at-globex", demoMembers.grace],
|
|
43
33
|
]);
|
|
44
34
|
|
|
45
35
|
return Directory.of({
|
|
@@ -2,9 +2,6 @@ import * as Action from "@gjermundgaraba/effect-actions/Action";
|
|
|
2
2
|
|
|
3
3
|
import { CurrentMember, WhoAmI } from "./Identity.js";
|
|
4
4
|
|
|
5
|
-
// `Action.allowAll`: verification is the whole policy here. Any authenticated member may ask
|
|
6
|
-
// who they are, whatever their scopes, so there is no rule to state. It must still be said:
|
|
7
|
-
// an implementation of a protected action without `authorize` does not compile.
|
|
8
5
|
export const identity = Action.implement(WhoAmI, () => CurrentMember, {
|
|
9
6
|
authorize: Action.allowAll,
|
|
10
7
|
});
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { scopes } from "./Identity.js";
|
|
2
2
|
import type { Member } from "./Identity.js";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
// such table: its directory reads a member from a signed token or a stored session. A local
|
|
6
|
-
// host names its caller with one of these, and so does a test.
|
|
7
|
-
export const members = {
|
|
4
|
+
export const demoMembers = {
|
|
8
5
|
ada: { id: "ada", workspace: "acme", scopes: [scopes.read, scopes.write] },
|
|
9
6
|
adaAtGlobex: { id: "ada", workspace: "globex", scopes: [scopes.read] },
|
|
10
7
|
linus: { id: "linus", workspace: "acme", scopes: [scopes.read] },
|
|
11
|
-
// Invited to acme, granted nothing yet.
|
|
12
8
|
kay: { id: "kay", workspace: "acme", scopes: [] },
|
|
13
9
|
grace: {
|
|
14
10
|
id: "grace",
|
|
@@ -5,26 +5,16 @@ import { RpcMiddleware } from "effect/rpc";
|
|
|
5
5
|
|
|
6
6
|
import { CurrentMember, QuotaExceeded } from "./Identity.js";
|
|
7
7
|
|
|
8
|
-
// The API's request quota: 60 requests a minute per member. It is a surface's own middleware,
|
|
9
|
-
// not a handler's check, because it must count before the input is decoded: a request whose
|
|
10
|
-
// body does not decode counts too. It runs inside authentication, so it may require the
|
|
11
|
-
// caller. HTTP and RPC each have their native middleware; an MCP endpoint takes none.
|
|
12
|
-
|
|
13
|
-
/** Listed in `ActionHttp.layer`'s `middleware`. It fails only with an error the binding declares. */
|
|
14
8
|
export class HttpQuota extends HttpApiMiddleware.Service<
|
|
15
9
|
HttpQuota,
|
|
16
10
|
{ requires: CurrentMember }
|
|
17
11
|
>()("tracker/HttpQuota", { error: QuotaExceeded }) {}
|
|
18
12
|
|
|
19
|
-
/** Listed in `ActionRpc.layer`'s `middleware`: the same quota, counted per message. */
|
|
20
13
|
export class RpcQuota extends RpcMiddleware.Service<
|
|
21
14
|
RpcQuota,
|
|
22
15
|
{ requires: CurrentMember }
|
|
23
16
|
>()("tracker/RpcQuota", { error: QuotaExceeded }) {}
|
|
24
17
|
|
|
25
|
-
// What both middleware do before a call. Each middleware's layer builds this for itself, so it
|
|
26
|
-
// runs twice; the count is one all the same, because both yield the one `RateLimiter` the
|
|
27
|
-
// entrypoint provides and spend under the same key.
|
|
28
18
|
const spend = Effect.map(RateLimiter.RateLimiter, (limiter) =>
|
|
29
19
|
Effect.gen(function* () {
|
|
30
20
|
const member = yield* CurrentMember;
|
|
@@ -46,7 +36,6 @@ const spend = Effect.map(RateLimiter.RateLimiter, (limiter) =>
|
|
|
46
36
|
retryAfterSeconds: Duration.toSeconds(retryAfter),
|
|
47
37
|
})
|
|
48
38
|
),
|
|
49
|
-
// Any other reason is the limiter's store failing: a defect, never the caller's.
|
|
50
39
|
Effect.die
|
|
51
40
|
)
|
|
52
41
|
);
|
|
@@ -22,8 +22,6 @@ export const Issue = Schema.Struct({
|
|
|
22
22
|
|
|
23
23
|
export type Issue = typeof Issue.Type;
|
|
24
24
|
|
|
25
|
-
// A declared error is part of the contract: every client decodes it as this class, and its
|
|
26
|
-
// status is what HTTP answers with. Without `httpApiStatus` it would be a 422.
|
|
27
25
|
export class IssueNotFound extends Schema.TaggedError<
|
|
28
26
|
IssueNotFound,
|
|
29
27
|
{ readonly brand: unique symbol }
|
|
@@ -38,20 +36,11 @@ export class RateLimited extends Schema.TaggedError<
|
|
|
38
36
|
{ httpApiStatus: 429 }
|
|
39
37
|
) {}
|
|
40
38
|
|
|
41
|
-
// A shared error list: what any write to an existing issue may fail with. Each such action
|
|
42
|
-
// names this one array as its `error`, here and in attachments/Attachments.ts, so an error
|
|
43
|
-
// added to the list is declared by all of them.
|
|
44
39
|
export const IssueWriteErrors = [IssueNotFound, RateLimited] as const;
|
|
45
40
|
|
|
46
|
-
// An option bundle. What the two actions changing an issue share is one constant object spread
|
|
47
|
-
// into `Action.make`, typed as if written inline. `readOnly` and `description` stay on each
|
|
48
|
-
// action.
|
|
49
41
|
const change = {
|
|
50
42
|
caller: CurrentMember,
|
|
51
43
|
error: IssueWriteErrors,
|
|
52
|
-
// MCP hints, in MCP's names. They tell a model what a tool does and enforce nothing; the
|
|
53
|
-
// read-only hint is `readOnly` itself. A write is destructive unless it only adds, as a
|
|
54
|
-
// comment does: closing is not stated `false`.
|
|
55
44
|
mcp: { openWorldHint: false },
|
|
56
45
|
} as const;
|
|
57
46
|
|
|
@@ -61,10 +50,7 @@ export const ListIssues = Action.make("listIssues", {
|
|
|
61
50
|
description:
|
|
62
51
|
"List your workspace's issues, newest first, without bodies or comments.",
|
|
63
52
|
input: {
|
|
64
|
-
// Optional: left out, issues of every status are listed.
|
|
65
53
|
status: Schema.optional(Status),
|
|
66
|
-
// Defaulted: left out, the handler receives 20. A field description is also the help text
|
|
67
|
-
// of its CLI flag and the description in the tool's schema.
|
|
68
54
|
limit: Schema.Int.check(
|
|
69
55
|
Schema.isBetween({ minimum: 1, maximum: 100 })
|
|
70
56
|
).pipe(
|
|
@@ -130,11 +116,6 @@ export const Issues = [
|
|
|
130
116
|
CloseIssue,
|
|
131
117
|
] as const;
|
|
132
118
|
|
|
133
|
-
// An action answering a stream: its handler returns a `Stream` of issues, and every client's
|
|
134
|
-
// call returns one, each issue read as the server sends it. It reports how far it is, too.
|
|
135
|
-
// `Issues` leaves it out, so MCP's `Tools` and the assistant's tools do: a tool answers one
|
|
136
|
-
// result, so it would collect the whole export before answering, every issue at once in a
|
|
137
|
-
// model's context. HTTP, RPC and the CLI serve it.
|
|
138
119
|
export const ExportIssues = Action.make("exportIssues", {
|
|
139
120
|
description:
|
|
140
121
|
"Stream every issue of your workspace, oldest first, with bodies and comments.",
|
|
@@ -152,25 +133,20 @@ export const ExportIssues = Action.make("exportIssues", {
|
|
|
152
133
|
description: "How many the export holds.",
|
|
153
134
|
}),
|
|
154
135
|
},
|
|
155
|
-
// An export is costly, so it is limited too: refused before its first issue, a 429.
|
|
156
136
|
error: RateLimited,
|
|
157
137
|
readOnly: true,
|
|
158
138
|
caller: CurrentMember,
|
|
159
139
|
});
|
|
160
140
|
|
|
161
|
-
/** What changed about an issue, as `issue.changed` carries it. */
|
|
162
141
|
export const IssueChange = Schema.Struct({
|
|
163
142
|
workspace: Schema.String,
|
|
164
143
|
id: Schema.String,
|
|
165
144
|
title: Schema.String,
|
|
166
145
|
status: Status,
|
|
167
146
|
change: Schema.Literals(["filed", "commented", "closed"]),
|
|
168
|
-
// The comment a change added; a subscriber asking `comments: false` receives none.
|
|
169
147
|
comment: Schema.optional(Comment),
|
|
170
148
|
});
|
|
171
149
|
|
|
172
|
-
// An event type: what a subscription takes, what each occurrence carries, and who may
|
|
173
|
-
// subscribe. `input` both filters the occurrences, by `status`, and shapes them, by `comments`.
|
|
174
150
|
export const IssueChanged = Event.make("issue.changed", {
|
|
175
151
|
description: "An issue in your workspace was filed, commented on or closed.",
|
|
176
152
|
input: {
|
|
@@ -4,22 +4,12 @@ import { LanguageModel } from "effect/ai";
|
|
|
4
4
|
import { issues } from "./handlers.js";
|
|
5
5
|
import { CloseIssue, CommentOnIssue, GetIssue, ListIssues } from "./Issues.js";
|
|
6
6
|
|
|
7
|
-
// The actions a model may call, listed here, where they are served. Filing issues is left to
|
|
8
|
-
// people.
|
|
9
7
|
const tools = [ListIssues, GetIssue, CommentOnIssue, CloseIssue] as const;
|
|
10
8
|
|
|
11
|
-
// Some of the issue actions as a model's tools: Effect's native `Toolkit`, in process, with no
|
|
12
|
-
// server between. `toolkit` holds the tool definitions and `layer` their handlers, the same
|
|
13
|
-
// implementation every other surface serves, behind the same `authorize` and write limit.
|
|
14
9
|
export const { toolkit, layer } = ActionToolkit.make(issues, {
|
|
15
10
|
actions: tools,
|
|
16
|
-
// One rule over every call a model makes, before the call runs: a write ends the turn with
|
|
17
|
-
// an approval request instead of a result. Approval is not authorization: `authorize` still
|
|
18
|
-
// runs for an approved call, as for any other.
|
|
19
11
|
needsApproval: (call) => !call.action.readOnly,
|
|
20
12
|
});
|
|
21
13
|
|
|
22
|
-
// One turn of the assistant. The caller provides the model, and the member it acts for around
|
|
23
|
-
// the whole turn: `authorize` and the handlers read that one caller.
|
|
24
14
|
export const triage = (prompt: string) =>
|
|
25
15
|
LanguageModel.generateText({ prompt, toolkit });
|
|
@@ -6,10 +6,6 @@ import { CurrentMember } from "../identity/Identity.js";
|
|
|
6
6
|
import { IssueChanged } from "./Issues.js";
|
|
7
7
|
import { IssueStore } from "./store.js";
|
|
8
8
|
|
|
9
|
-
// A log source fed by a stream: the store pushes every change, of every workspace, and the
|
|
10
|
-
// library consumes the stream once, from startup, keeping what it produced lately for
|
|
11
|
-
// subscribers resuming from a cursor. `key`, `match` and `transform` run per subscriber, as the
|
|
12
|
-
// subscriber.
|
|
13
9
|
export const issueEvents = Event.implement(
|
|
14
10
|
IssueChanged,
|
|
15
11
|
Effect.gen(function* () {
|
|
@@ -17,30 +13,20 @@ export const issueEvents = Event.implement(
|
|
|
17
13
|
|
|
18
14
|
return {
|
|
19
15
|
log: {
|
|
20
|
-
// No `eventId`: the library gives each change one, kept on every replay. An id of the
|
|
21
|
-
// store's would have to stay unique across restarts, as a subscriber drops a repeated
|
|
22
|
-
// one. Each change is keyed by its workspace, which reaches that workspace's
|
|
23
|
-
// subscribers alone.
|
|
24
16
|
emit: Stream.map(store.changes, (data) => ({
|
|
25
17
|
data,
|
|
26
18
|
key: data.workspace,
|
|
27
19
|
})),
|
|
28
|
-
// One log holds every workspace's changes: a subscriber resuming within an hour, and
|
|
29
|
-
// within the last thousand changes of all workspaces, misses nothing; one resuming
|
|
30
|
-
// later receives a gap first, then what is kept. A busy workspace shortens a quiet
|
|
31
|
-
// one's hour.
|
|
32
20
|
maxAge: "1 hour",
|
|
33
21
|
maxEvents: 1000,
|
|
34
22
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
key: () => Effect.map(CurrentMember, (member) => member.workspace),
|
|
23
|
+
key: (): Effect.Effect<string, never, CurrentMember> =>
|
|
24
|
+
Effect.map(CurrentMember, (member) => member.workspace),
|
|
38
25
|
match: ({ status }, change) =>
|
|
39
26
|
status === undefined || change.status === status,
|
|
40
27
|
transform: ({ comments }, change) =>
|
|
41
28
|
comments === false ? Struct.omit(change, ["comment"]) : change,
|
|
42
29
|
};
|
|
43
30
|
}),
|
|
44
|
-
// The members' rule, as for the actions: a subscription needs the read scope.
|
|
45
31
|
{ authorize }
|
|
46
32
|
);
|
|
@@ -12,17 +12,12 @@ export const exports = Action.implement(
|
|
|
12
12
|
const store = yield* IssueStore;
|
|
13
13
|
const limited = yield* exportLimit;
|
|
14
14
|
|
|
15
|
-
// The handler returns a `Stream`. The limit is spent before the first issue, so a refused
|
|
16
|
-
// export fails as an action answering one value does, a 429 over HTTP; a failure after an
|
|
17
|
-
// issue would end the stream instead, the issues before it already sent.
|
|
18
15
|
return ({ status }, { progress }) =>
|
|
19
16
|
Stream.unwrap(
|
|
20
17
|
limited((member) =>
|
|
21
18
|
Effect.map(store.count(member.workspace, status), (total) =>
|
|
22
19
|
store.all(member.workspace, status).pipe(
|
|
23
20
|
Stream.zipWithIndex,
|
|
24
|
-
// `progress` never waits for the caller, dropping the oldest values a slow one has not taken:
|
|
25
|
-
// `exported` may skip numbers, so it says how far the export is, not what arrived.
|
|
26
21
|
Stream.mapEffect(([issue, index]) =>
|
|
27
22
|
Effect.as(progress({ exported: index + 1, total }), issue)
|
|
28
23
|
)
|
|
@@ -11,13 +11,8 @@ const guide = `# Triage
|
|
|
11
11
|
- Writes are limited to ten a minute. When refused, wait as long as the error says.
|
|
12
12
|
`;
|
|
13
13
|
|
|
14
|
-
// The contracts keyed by name, each its exact contract. The prompt below names its tools through
|
|
15
|
-
// them, so renaming an action is a compile error here, not a stale instruction to a model.
|
|
16
14
|
const tools = Action.byName(Issues);
|
|
17
15
|
|
|
18
|
-
// Effect's own MCP resources and prompts, served beside the actions' tools as an endpoint's
|
|
19
|
-
// `features`: native, not actions. This guide is the same for every caller, so it reads no
|
|
20
|
-
// caller, which `features` never receive.
|
|
21
16
|
export const features = Layer.mergeAll(
|
|
22
17
|
McpServer.resource({
|
|
23
18
|
uri: "tracker://guides/triage",
|
|
@@ -7,10 +7,6 @@ import { Issues } from "./Issues.js";
|
|
|
7
7
|
import { IssueStore } from "./store.js";
|
|
8
8
|
import { writeLimit } from "./write-limit.js";
|
|
9
9
|
|
|
10
|
-
// Several actions sharing one builder. It runs once, at startup, however many surfaces serve
|
|
11
|
-
// these actions, and yields the startup services: the store, and the write limit built on the
|
|
12
|
-
// limiter. `CurrentMember` is a per-request service: each handler reads it per call, so one
|
|
13
|
-
// build serves every caller. No handler checks a scope: `authorize` has run before it.
|
|
14
10
|
export const issues = Action.implement(
|
|
15
11
|
Issues,
|
|
16
12
|
Effect.gen(function* () {
|
|
@@ -35,7 +31,6 @@ export const issues = Action.implement(
|
|
|
35
31
|
Effect.flatMap(CurrentMember, (member) =>
|
|
36
32
|
store.get(member.workspace, id)
|
|
37
33
|
),
|
|
38
|
-
// One function wraps every limited handler, and gives it the member it counted.
|
|
39
34
|
createIssue: (draft) =>
|
|
40
35
|
limited((member) => store.create(member.workspace, draft)),
|
|
41
36
|
commentOnIssue: ({ id, text }) =>
|