@gjermundgaraba/effect-actions 0.21.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
|
@@ -4,19 +4,15 @@ import { Effect, Redacted } from "effect";
|
|
|
4
4
|
|
|
5
5
|
import { OperatorKey } from "./Admin.js";
|
|
6
6
|
import type { KeyOperator } from "./Admin.js";
|
|
7
|
-
import {
|
|
7
|
+
import { demoOperatorKeys } from "./keys.js";
|
|
8
8
|
|
|
9
|
-
// Typed to return a `KeyOperator`, never the `Operator` union (Admin.ts says why). The verifier
|
|
10
|
-
// receives what its scheme decodes, the header's value, and needs no startup service, so it is
|
|
11
|
-
// passed as it is.
|
|
12
9
|
const verify = (
|
|
13
10
|
key: Redacted.Redacted
|
|
14
11
|
): Effect.Effect<KeyOperator, Action.Unauthenticated> =>
|
|
15
|
-
Effect.fromNullishOr(
|
|
12
|
+
Effect.fromNullishOr(demoOperatorKeys.get(Redacted.value(key))).pipe(
|
|
16
13
|
Effect.mapError(
|
|
17
14
|
() => new Action.Unauthenticated({ message: "Unknown operator key." })
|
|
18
15
|
)
|
|
19
16
|
);
|
|
20
17
|
|
|
21
|
-
// Server only: `OperatorKey`'s provider, which the admin port's routes require.
|
|
22
18
|
export const authenticateOperator = Authentication.layer(OperatorKey, verify);
|
|
@@ -5,9 +5,6 @@ import { Operator } from "./Admin.js";
|
|
|
5
5
|
import { Grants } from "./grants.js";
|
|
6
6
|
import type { Grant } from "./grants.js";
|
|
7
7
|
|
|
8
|
-
// An authorizer built from a startup service, as a handler builder builds handlers: the
|
|
9
|
-
// Effect yields `Grants` once, when the implementation is built, and the function it returns
|
|
10
|
-
// reads the operator on every call.
|
|
11
8
|
export const authorize = Effect.gen(function* () {
|
|
12
9
|
const grants = yield* Grants;
|
|
13
10
|
|
|
@@ -15,7 +12,6 @@ export const authorize = Effect.gen(function* () {
|
|
|
15
12
|
Effect.gen(function* () {
|
|
16
13
|
const operator = yield* Operator;
|
|
17
14
|
|
|
18
|
-
// The one rule admits the console's operator too: no surface has a bypass of its own.
|
|
19
15
|
if (operator.trusted) {
|
|
20
16
|
return;
|
|
21
17
|
}
|
|
@@ -24,7 +20,6 @@ export const authorize = Effect.gen(function* () {
|
|
|
24
20
|
? "workspaces:read"
|
|
25
21
|
: "workspaces:suspend";
|
|
26
22
|
|
|
27
|
-
// No `scopes`: a key cannot be re-authorized, so this is a plain 403.
|
|
28
23
|
if (!(yield* grants.of(operator.id)).includes(grant)) {
|
|
29
24
|
return yield* new Action.Forbidden({
|
|
30
25
|
message: `Requires the ${grant} grant.`,
|
|
@@ -2,15 +2,10 @@ import { Context, Effect, Layer } from "effect";
|
|
|
2
2
|
|
|
3
3
|
export type Grant = "workspaces:read" | "workspaces:suspend";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* What each operator may do. An API key carries no scopes, so the grants are kept here, on the
|
|
7
|
-
* server, and the authorizer looks them up.
|
|
8
|
-
*/
|
|
9
5
|
export class Grants extends Context.Service<
|
|
10
6
|
Grants,
|
|
11
7
|
{ readonly of: (operator: string) => Effect.Effect<readonly Grant[]> }
|
|
12
8
|
>()("tracker/Grants") {
|
|
13
|
-
// DEMO ONLY: fixed grants. A real application reads them from its database.
|
|
14
9
|
static readonly layerDemo = Layer.sync(Grants, () => {
|
|
15
10
|
const grants = new Map<string, readonly Grant[]>([
|
|
16
11
|
["ops", ["workspaces:read", "workspaces:suspend"]],
|
|
@@ -5,8 +5,6 @@ import { WorkspaceRegistry } from "../workspaces/registry.js";
|
|
|
5
5
|
import { Admin } from "./Admin.js";
|
|
6
6
|
import { authorize } from "./authorize.js";
|
|
7
7
|
|
|
8
|
-
// The operators' actions. `authorize` is an Effect that builds the rule, so this
|
|
9
|
-
// implementation owes `Grants` at startup, beside the registry its builder yields.
|
|
10
8
|
export const admin = Action.implement(
|
|
11
9
|
Admin,
|
|
12
10
|
Effect.gen(function* () {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { KeyOperator } from "./Admin.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
// of each key it issued, and looks the operator up by it.
|
|
5
|
-
export const keys = new Map<string, KeyOperator>([
|
|
3
|
+
export const demoOperatorKeys = new Map<string, KeyOperator>([
|
|
6
4
|
["ops-key", { id: "ops", trusted: false }],
|
|
7
5
|
["support-key", { id: "support", trusted: false }],
|
|
8
6
|
]);
|
|
@@ -4,19 +4,13 @@ import { Console, Effect, Layer } from "effect";
|
|
|
4
4
|
|
|
5
5
|
import { demoModel } from "./assistant/demo-model.js";
|
|
6
6
|
import { CurrentMember } from "./identity/Identity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { demoMembers } from "./identity/members.js";
|
|
8
8
|
import { layer, triage } from "./issues/assistant.js";
|
|
9
9
|
import { issues } from "./issues/handlers.js";
|
|
10
10
|
import { IssueStore } from "./issues/store.js";
|
|
11
11
|
import { limiter } from "./memory.js";
|
|
12
12
|
|
|
13
|
-
// Entrypoint: `node --import tsx examples/kitchen-sink/src/agent.ts`.
|
|
14
|
-
// The assistant as a local program: a model calling the issue actions as tools, in process.
|
|
15
|
-
// The server serves the same tools behind a route, a turn per request: assistant/handlers.ts.
|
|
16
|
-
|
|
17
13
|
const program = Effect.gen(function* () {
|
|
18
|
-
// Code of your own calls the implementation typed, with `Action.client`: the same decoding,
|
|
19
|
-
// `authorize` and handler, with no transport. The store is memory, so file an issue first.
|
|
20
14
|
const tracker = yield* Action.client(issues);
|
|
21
15
|
|
|
22
16
|
yield* tracker.createIssue({
|
|
@@ -26,8 +20,6 @@ const program = Effect.gen(function* () {
|
|
|
26
20
|
|
|
27
21
|
const turn = yield* triage("Close what is done.");
|
|
28
22
|
|
|
29
|
-
// The read ran: its result is here. The write did not: it waits for the member's approval,
|
|
30
|
-
// which a host answers in the next turn, as assistant/handlers.ts does.
|
|
31
23
|
for (const { name, encodedResult } of turn.toolResults) {
|
|
32
24
|
yield* Console.log(`${name} answered`, encodedResult);
|
|
33
25
|
}
|
|
@@ -41,13 +33,10 @@ const program = Effect.gen(function* () {
|
|
|
41
33
|
|
|
42
34
|
program.pipe(
|
|
43
35
|
Effect.scoped,
|
|
44
|
-
|
|
45
|
-
// DEMO ONLY: a real host names whoever asked.
|
|
46
|
-
Effect.provideService(CurrentMember, members.ada),
|
|
36
|
+
Effect.provideService(CurrentMember, demoMembers.ada),
|
|
47
37
|
Effect.provide(
|
|
48
38
|
layer.pipe(
|
|
49
39
|
Layer.provideMerge(Layer.merge(IssueStore.layerMemory, limiter)),
|
|
50
|
-
// DEMO ONLY: a scripted model. A real one is a provider's layer, in its place.
|
|
51
40
|
Layer.provideMerge(demoModel)
|
|
52
41
|
)
|
|
53
42
|
),
|
|
@@ -3,17 +3,6 @@ import { Schema } from "effect";
|
|
|
3
3
|
|
|
4
4
|
import { CurrentMember } from "../identity/Identity.js";
|
|
5
5
|
|
|
6
|
-
// The assistant behind a route: a model working on the issues with the tools of
|
|
7
|
-
// issues/assistant.ts, one request per turn of a conversation. A request starts a turn and its
|
|
8
|
-
// answer is the turn's end: the model's text, or the calls that wait for the member's approval.
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* What a turn ended with. A call in `ran` ran in this turn, `failed` where it was refused or
|
|
12
|
-
* failed with a declared error; one the member denied, or one in a reply the provider cut
|
|
13
|
-
* short, did not run and is not listed. A call in `waiting` has not run: `answerAssistant`
|
|
14
|
-
* decides it. `waiting` holds every open request of the conversation: one this turn
|
|
15
|
-
* asked, and one an earlier answer left unanswered, until it is answered.
|
|
16
|
-
*/
|
|
17
6
|
export const Turn = Schema.Struct({
|
|
18
7
|
conversation: Schema.String,
|
|
19
8
|
text: Schema.String,
|
|
@@ -24,13 +13,11 @@ export const Turn = Schema.Struct({
|
|
|
24
13
|
Schema.Struct({
|
|
25
14
|
approvalId: Schema.String,
|
|
26
15
|
tool: Schema.String,
|
|
27
|
-
// The arguments the model gave the call, as JSON text: what the member approves.
|
|
28
16
|
arguments: Schema.String,
|
|
29
17
|
})
|
|
30
18
|
),
|
|
31
19
|
});
|
|
32
20
|
|
|
33
|
-
// Another member's conversation is not found either: an id tells nothing of who holds it.
|
|
34
21
|
export class ConversationNotFound extends Schema.TaggedError<
|
|
35
22
|
ConversationNotFound,
|
|
36
23
|
{ readonly brand: unique symbol }
|
|
@@ -40,8 +27,6 @@ export class ConversationNotFound extends Schema.TaggedError<
|
|
|
40
27
|
{ httpApiStatus: 404 }
|
|
41
28
|
) {}
|
|
42
29
|
|
|
43
|
-
// The model failed in the middle of a turn. The conversation is over: its history holds
|
|
44
|
-
// nothing of that turn, so it no longer says which calls ran.
|
|
45
30
|
export class AssistantFailed extends Schema.TaggedError<
|
|
46
31
|
AssistantFailed,
|
|
47
32
|
{ readonly brand: unique symbol }
|
|
@@ -62,22 +47,20 @@ export const AskAssistant = Action.make("askAssistant", {
|
|
|
62
47
|
caller: CurrentMember,
|
|
63
48
|
});
|
|
64
49
|
|
|
50
|
+
const uniqueApprovalIds = Schema.makeFilter(
|
|
51
|
+
(answers: ReadonlyArray<{ readonly approvalId: string }>) =>
|
|
52
|
+
new Set(answers.map(({ approvalId }) => approvalId)).size ===
|
|
53
|
+
answers.length || "Answer each approvalId once"
|
|
54
|
+
);
|
|
55
|
+
|
|
65
56
|
export const AnswerAssistant = Action.make("answerAssistant", {
|
|
66
57
|
description:
|
|
67
58
|
"Approve or deny the calls a turn of your conversation waits for.",
|
|
68
59
|
input: {
|
|
69
60
|
conversation: Schema.String,
|
|
70
|
-
// Each request once. Effect acts on every answer it is given: an `approvalId` approved
|
|
71
|
-
// twice in one request would run its call twice.
|
|
72
61
|
answers: Schema.Array(
|
|
73
62
|
Schema.Struct({ approvalId: Schema.String, approved: Schema.Boolean })
|
|
74
|
-
).check(
|
|
75
|
-
Schema.makeFilter(
|
|
76
|
-
(answers) =>
|
|
77
|
-
new Set(answers.map(({ approvalId }) => approvalId)).size ===
|
|
78
|
-
answers.length || "Answer each approvalId once"
|
|
79
|
-
)
|
|
80
|
-
),
|
|
63
|
+
).check(uniqueApprovalIds),
|
|
81
64
|
},
|
|
82
65
|
success: Turn,
|
|
83
66
|
error: [ConversationNotFound, AssistantFailed],
|
|
@@ -5,32 +5,17 @@ import type { Member } from "../identity/Identity.js";
|
|
|
5
5
|
import { ConversationNotFound } from "./Assistant.js";
|
|
6
6
|
|
|
7
7
|
interface Conversation {
|
|
8
|
-
/** Effect's `Chat`: the history a model reads, in which an approval's answer finds its request. */
|
|
9
8
|
readonly chat: Chat.Chat;
|
|
10
9
|
readonly lock: Semaphore.Semaphore;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
// A member is a person in a workspace, and an id is unguessable: both are in the key, as
|
|
14
|
-
// JSON, which keeps its three parts apart whatever they hold.
|
|
15
12
|
const keyOf = (owner: Member, id: string) =>
|
|
16
13
|
JSON.stringify([owner.workspace, owner.id, id]);
|
|
17
14
|
|
|
18
|
-
/**
|
|
19
|
-
* Where conversations are kept between requests, each with the member it belongs to. A turn
|
|
20
|
-
* names the member, so only its owner reaches a conversation: an approval is acted on as the
|
|
21
|
-
* turn's caller, and must come from the member who was asked.
|
|
22
|
-
*/
|
|
23
15
|
export class Conversations extends Context.Service<
|
|
24
16
|
Conversations,
|
|
25
17
|
{
|
|
26
|
-
/** Start a conversation of `owner`'s, and return its id. */
|
|
27
18
|
readonly open: (owner: Member) => Effect.Effect<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Run one turn on a conversation's `Chat`. One turn runs at a time, and a turn that fails or
|
|
30
|
-
* is interrupted ends its conversation: the `Chat` records a turn only when it succeeds, so
|
|
31
|
-
* after any other end its history no longer says which calls ran, and an approval answered
|
|
32
|
-
* in that turn would run again.
|
|
33
|
-
*/
|
|
34
19
|
readonly turn: <A, E, R>(
|
|
35
20
|
owner: Member,
|
|
36
21
|
id: string,
|
|
@@ -38,12 +23,9 @@ export class Conversations extends Context.Service<
|
|
|
38
23
|
) => Effect.Effect<A, E | ConversationNotFound, R>;
|
|
39
24
|
}
|
|
40
25
|
>()("tracker/Conversations") {
|
|
41
|
-
// DEMO ONLY: memory, lost when the process stops and never trimmed. A real store keeps each
|
|
42
|
-
// history where every instance reads it, `chat.exportJson` to save and `Chat.fromJson` to load.
|
|
43
26
|
static readonly layerMemory = Layer.sync(Conversations, () => {
|
|
44
27
|
const kept = new Map<string, Conversation>();
|
|
45
28
|
|
|
46
|
-
// Read when it runs, not when it is written: the second lookup of a turn runs under the lock.
|
|
47
29
|
const find = (key: string, id: string) =>
|
|
48
30
|
Effect.suspend(() => Effect.fromNullishOr(kept.get(key))).pipe(
|
|
49
31
|
Effect.mapError(() => new ConversationNotFound({ conversation: id }))
|
|
@@ -63,10 +45,10 @@ export class Conversations extends Context.Service<
|
|
|
63
45
|
turn: (owner, id, run) => {
|
|
64
46
|
const key = keyOf(owner, id);
|
|
65
47
|
|
|
48
|
+
const lookupUnderLock = find(key, id);
|
|
49
|
+
|
|
66
50
|
return Effect.flatMap(find(key, id), ({ lock }) =>
|
|
67
|
-
|
|
68
|
-
// must find its conversation gone, not run on the history that turn left behind.
|
|
69
|
-
Effect.flatMap(find(key, id), ({ chat }) =>
|
|
51
|
+
Effect.flatMap(lookupUnderLock, ({ chat }) =>
|
|
70
52
|
Effect.onError(run(chat), () => Effect.sync(() => kept.delete(key)))
|
|
71
53
|
).pipe(lock.withPermits(1))
|
|
72
54
|
);
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { Layer, Effect, Stream } from "effect";
|
|
2
2
|
import { LanguageModel } from "effect/ai";
|
|
3
3
|
|
|
4
|
-
// DEMO ONLY: a model that needs no API key. Asked by a person, it lists the open issues and
|
|
5
|
-
// closes ACME-1; once its tools have answered, it says so. A real one is a provider's layer,
|
|
6
|
-
// such as `AnthropicLanguageModel.model(...)`, provided in its place. Each call has an id of
|
|
7
|
-
// its own, as a provider's has: Effect finds the call an approval is about by that id, so one
|
|
8
|
-
// used twice in a conversation would run another call than the member was shown, or none.
|
|
9
4
|
export const demoModel = Layer.effect(
|
|
10
5
|
LanguageModel.LanguageModel,
|
|
11
6
|
LanguageModel.make({
|
|
@@ -9,7 +9,6 @@ import { toolkit } from "../issues/assistant.js";
|
|
|
9
9
|
import { AssistantFailed, Assistant } from "./Assistant.js";
|
|
10
10
|
import { Conversations } from "./conversations.js";
|
|
11
11
|
|
|
12
|
-
// A model that keeps calling tools is asked this many times in one turn, and no more.
|
|
13
12
|
const requestsPerTurn = 6;
|
|
14
13
|
|
|
15
14
|
type Response = LanguageModel.GenerateTextResponse<
|
|
@@ -20,9 +19,6 @@ type Response = LanguageModel.GenerateTextResponse<
|
|
|
20
19
|
const approvalsOf = (response: Response) =>
|
|
21
20
|
response.content.filter((part) => part.type === "tool-approval-request");
|
|
22
21
|
|
|
23
|
-
// What Effect gives the model as the result of a call that did not run: one its member denied,
|
|
24
|
-
// or one in a reply the provider cut short. Left out of `ran` below, which lists the calls that
|
|
25
|
-
// ran.
|
|
26
22
|
const didNotRun = Schema.is(
|
|
27
23
|
Schema.Struct({
|
|
28
24
|
type: Schema.Literals(["execution-denied", "execution-interrupted"]),
|
|
@@ -32,12 +28,6 @@ const didNotRun = Schema.is(
|
|
|
32
28
|
const callsToRead = (response: Response) =>
|
|
33
29
|
response.toolCalls.length > 0 && approvalsOf(response).length === 0;
|
|
34
30
|
|
|
35
|
-
// The model loop behind a route. The builder runs once, at startup, and yields what a turn is
|
|
36
|
-
// built from: the tools with their handlers, the model, and where conversations are kept. A
|
|
37
|
-
// handler yielding them would owe them per request, which no route provides. `CurrentMember`
|
|
38
|
-
// is the one per-request service: each tool call of a turn runs as the request's caller,
|
|
39
|
-
// through that tool's own `authorize`. A conversation keeps its owner's id, never the member
|
|
40
|
-
// itself, whose scopes would go stale between requests.
|
|
41
31
|
export const assistant = Action.implement(
|
|
42
32
|
Assistant,
|
|
43
33
|
Effect.gen(function* () {
|
|
@@ -51,11 +41,6 @@ export const assistant = Action.implement(
|
|
|
51
41
|
prompt: Prompt.RawInput
|
|
52
42
|
) =>
|
|
53
43
|
Effect.gen(function* () {
|
|
54
|
-
// One `generateText` is one request to the model: its tool calls run, and their
|
|
55
|
-
// results come back unread. The model is asked again, with nothing new, while it
|
|
56
|
-
// called tools and none of them waits for approval. Continue on tool calls, never on
|
|
57
|
-
// tool results: the turn answering an approval holds the approved call's result and
|
|
58
|
-
// the model's reply to it.
|
|
59
44
|
let response = yield* chat.generateText({ prompt, toolkit: tools });
|
|
60
45
|
const results = [...response.toolResults];
|
|
61
46
|
|
|
@@ -76,10 +61,6 @@ export const assistant = Action.implement(
|
|
|
76
61
|
.filter(({ result }) => !didNotRun(result))
|
|
77
62
|
.map(({ name, isFailure }) => ({ tool: name, failed: isFailure }))
|
|
78
63
|
.toArray(),
|
|
79
|
-
// Every request of the conversation still waiting for an answer, with the call it
|
|
80
|
-
// would run, read from the `Chat`'s history by the rule Effect applies when an answer
|
|
81
|
-
// arrives: one an earlier answer left open is listed in every turn until answered.
|
|
82
|
-
// The arguments are shown as JSON, as the member approves them.
|
|
83
64
|
waiting: ActionToolkit.openApprovals(
|
|
84
65
|
yield* Ref.get(chat.history)
|
|
85
66
|
).map(({ approvalId, name, params }) => ({
|
|
@@ -88,12 +69,8 @@ export const assistant = Action.implement(
|
|
|
88
69
|
arguments: JSON.stringify(params),
|
|
89
70
|
})),
|
|
90
71
|
};
|
|
91
|
-
}).pipe(
|
|
92
|
-
// The model is a startup service, given to each turn here.
|
|
93
|
-
Effect.provideService(LanguageModel.LanguageModel, model)
|
|
94
|
-
);
|
|
72
|
+
}).pipe(Effect.provideService(LanguageModel.LanguageModel, model));
|
|
95
73
|
|
|
96
|
-
// A failed turn says what may have run.
|
|
97
74
|
const turn = (conversation: string, prompt: Prompt.RawInput) =>
|
|
98
75
|
Effect.flatMap(CurrentMember, (member) =>
|
|
99
76
|
conversations.turn(member, conversation, (chat) =>
|
|
@@ -118,10 +95,6 @@ export const assistant = Action.implement(
|
|
|
118
95
|
(opened) => turn(opened, prompt)
|
|
119
96
|
)
|
|
120
97
|
: turn(conversation, prompt),
|
|
121
|
-
// The answers start the next turn, in which an approved call runs, as this request's
|
|
122
|
-
// caller, before the model is asked again. Only the member who was asked reaches the
|
|
123
|
-
// conversation, and a turn that fails ends it, so no answer is left without its result:
|
|
124
|
-
// an `approvalId` that `openApprovals` would not list runs nothing.
|
|
125
98
|
answerAssistant: ({ conversation, answers }) =>
|
|
126
99
|
turn(conversation, [
|
|
127
100
|
{
|
|
@@ -135,7 +108,5 @@ export const assistant = Action.implement(
|
|
|
135
108
|
]),
|
|
136
109
|
};
|
|
137
110
|
}),
|
|
138
|
-
// Any member may ask. What the assistant may do for them is each tool's rule, not this one:
|
|
139
|
-
// a member without the write scope gets the tool's refusal as a result the model reads.
|
|
140
111
|
{ authorize: Action.allowAll }
|
|
141
112
|
);
|
|
@@ -19,8 +19,6 @@ export class AttachmentNotFound extends Schema.TaggedError<
|
|
|
19
19
|
{ readonly brand: unique symbol }
|
|
20
20
|
>()("AttachmentNotFound", { id: Schema.String }, { httpApiStatus: 404 }) {}
|
|
21
21
|
|
|
22
|
-
// `Action.Image` is `{ data: Uint8Array, mimeType: string }`. In an input it is JSON over HTTP,
|
|
23
|
-
// RPC and the CLI, the bytes in base64.
|
|
24
22
|
export const AttachImage = Action.make("attachImage", {
|
|
25
23
|
description: "Attach an image, such as a screenshot, to an issue.",
|
|
26
24
|
input: { issue: Schema.String, name: Schema.String, image: Action.Image },
|
|
@@ -30,8 +28,6 @@ export const AttachImage = Action.make("attachImage", {
|
|
|
30
28
|
caller: CurrentMember,
|
|
31
29
|
});
|
|
32
30
|
|
|
33
|
-
// `Action.Image` as a top-level field of the success, so an MCP tool shows the model the image
|
|
34
|
-
// itself, beside the JSON of `{ attachment }`.
|
|
35
31
|
export const GetAttachment = Action.make("getAttachment", {
|
|
36
32
|
description: "Fetch an attachment: its name and size, and the image itself.",
|
|
37
33
|
input: { id: Schema.String },
|
|
@@ -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.",
|