@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
|
@@ -12,8 +12,6 @@ import { Login } from "../src/identity/Identity.js";
|
|
|
12
12
|
import { routes } from "../src/routes.js";
|
|
13
13
|
import { inMemory } from "./support/memory.js";
|
|
14
14
|
|
|
15
|
-
// What the wire adds: the real routes, behind their real authentication, answering in memory.
|
|
16
|
-
// No port is opened. The subscriber is the token each client sends, as in production.
|
|
17
15
|
const served = Testing.layer(routes).pipe(Layer.provide(inMemory()));
|
|
18
16
|
|
|
19
17
|
const as = (token: string) => ({
|
|
@@ -26,7 +24,6 @@ describe("the service, over MCP", () => {
|
|
|
26
24
|
"pushes each build a member may see, as a tool call finishes it",
|
|
27
25
|
() =>
|
|
28
26
|
Effect.gen(function* () {
|
|
29
|
-
// A client lists the contracts it uses: the action it calls, the event it watches.
|
|
30
27
|
const ada = yield* ActionMcp.client([FinishBuild], as("ada"));
|
|
31
28
|
const grace = yield* ActionMcp.client([BuildFinished], as("grace"));
|
|
32
29
|
|
|
@@ -34,11 +31,8 @@ describe("the service, over MCP", () => {
|
|
|
34
31
|
.watch(BuildFinished)
|
|
35
32
|
.pipe(Stream.take(1), Stream.runCollect, Effect.forkChild);
|
|
36
33
|
|
|
37
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
38
34
|
yield* TestClock.adjust("0 millis");
|
|
39
35
|
yield* ada.finishBuild({ pipeline: "api", status: "passed" });
|
|
40
|
-
// Each build finished notifies `build.finished`: the server asks the store at once, and
|
|
41
|
-
// pushes what it answers.
|
|
42
36
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
43
37
|
|
|
44
38
|
expect(yield* Fiber.join(watched)).toMatchObject([
|
|
@@ -54,7 +48,6 @@ describe("the service, over MCP", () => {
|
|
|
54
48
|
const ada = yield* ActionMcp.client([RequestDeploy], as("ada"));
|
|
55
49
|
const grace = yield* ActionMcp.client([DeployRequested], as("grace"));
|
|
56
50
|
|
|
57
|
-
// `mode: "poll"` asks with `events/poll`, as a client that cannot hold a stream does.
|
|
58
51
|
const polled = yield* grace
|
|
59
52
|
.watch(
|
|
60
53
|
DeployRequested,
|
|
@@ -72,8 +65,6 @@ describe("the service, over MCP", () => {
|
|
|
72
65
|
|
|
73
66
|
yield* TestClock.adjust("5 seconds");
|
|
74
67
|
|
|
75
|
-
// Between polls, grace stands by: the server holds the subscription hook for 5 minutes
|
|
76
|
-
// after each poll, keyed by grace's principal.
|
|
77
68
|
expect(deploy.approvers).toStrictEqual(["grace"]);
|
|
78
69
|
expect(yield* Fiber.join(polled)).toMatchObject([
|
|
79
70
|
{
|
|
@@ -11,15 +11,12 @@ import { routes } from "../src/routes.js";
|
|
|
11
11
|
import { Rpc } from "../src/Rpc.js";
|
|
12
12
|
import { inMemory } from "./support/memory.js";
|
|
13
13
|
|
|
14
|
-
// Effect's RPC client over HTTP to the real routes in memory, with the serialization the
|
|
15
|
-
// server frames streams with.
|
|
16
14
|
const served = RpcClient.layerProtocolHttp({ url: "/rpc" }).pipe(
|
|
17
15
|
Layer.provide(RpcSerialization.layerNdjson),
|
|
18
16
|
Layer.provide(Testing.layer(routes)),
|
|
19
17
|
Layer.provide(inMemory())
|
|
20
18
|
);
|
|
21
19
|
|
|
22
|
-
// An rpc's credential is its own headers: each call or watch says who is calling.
|
|
23
20
|
const as = (token: string) =>
|
|
24
21
|
RpcClient.withHeaders({ authorization: `Bearer ${token}` });
|
|
25
22
|
|
|
@@ -32,7 +29,6 @@ describe("the service, over RPC", () => {
|
|
|
32
29
|
.watch(BuildFinished)
|
|
33
30
|
.pipe(Stream.take(1), Stream.runCollect, as("grace"), Effect.forkChild);
|
|
34
31
|
|
|
35
|
-
// The watch starts from now: let it take its first position before builds finish.
|
|
36
32
|
yield* TestClock.adjust("0 millis");
|
|
37
33
|
yield* client
|
|
38
34
|
.finishBuild({ pipeline: "api", status: "passed" })
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
|
|
3
3
|
import { CurrentMember } from "../../src/identity/Identity.js";
|
|
4
|
-
import {
|
|
4
|
+
import { demoMembers } from "../../src/identity/members.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Effect.provideService(CurrentMember, members[member]);
|
|
6
|
+
export const as = (member: keyof typeof demoMembers) =>
|
|
7
|
+
Effect.provideService(CurrentMember, demoMembers[member]);
|
|
@@ -12,9 +12,6 @@ import { Approvers } from "../../src/deploys/approvers.js";
|
|
|
12
12
|
|
|
13
13
|
const unreached = async () => new Response(null, { status: 503 });
|
|
14
14
|
|
|
15
|
-
// What the routes need, in memory: the stores, the events announced, and for webhook delivery a client, a resolver
|
|
16
|
-
// and a store for the subscriptions. `subscribers` answers each POST in place of a member's server, and
|
|
17
|
-
// hooks.example.com resolves to a public address: delivery refuses a private or loopback one.
|
|
18
15
|
export const inMemory = <R = never>(
|
|
19
16
|
subscribers: Layer.Layer<HttpClient.HttpClient, never, R> = Testing.layer(
|
|
20
17
|
unreached
|
|
@@ -29,8 +26,6 @@ export const inMemory = <R = never>(
|
|
|
29
26
|
KeyValueStore.layerMemory
|
|
30
27
|
);
|
|
31
28
|
|
|
32
|
-
// Waits for `done` while requests in memory resolve: a subscription made through them runs on
|
|
33
|
-
// promises the test clock does not drive.
|
|
34
29
|
export const settled = <E, R>(done: Effect.Effect<boolean, E, R>) =>
|
|
35
30
|
Effect.repeat(
|
|
36
31
|
Effect.andThen(
|
|
@@ -8,12 +8,8 @@ import { Http } from "../src/Api.js";
|
|
|
8
8
|
import { routes } from "../src/routes.js";
|
|
9
9
|
import { inMemory } from "./support/memory.js";
|
|
10
10
|
|
|
11
|
-
// The subscriber's secret: `whsec_` and 24 to 64 random bytes in base64. The server signs each
|
|
12
|
-
// POST with it, and the subscriber checks each POST it receives against it.
|
|
13
11
|
const secret = `whsec_${Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64")}`;
|
|
14
12
|
|
|
15
|
-
// A subscriber's check, as Standard Webhooks defines it: an HMAC-SHA256 of the id, the
|
|
16
|
-
// timestamp and the body exactly as received, among the space-separated `v1,` signatures.
|
|
17
13
|
const signed = async (request: Request, body: string) => {
|
|
18
14
|
const key = await crypto.subtle.importKey(
|
|
19
15
|
"raw",
|
|
@@ -51,8 +47,6 @@ interface Received {
|
|
|
51
47
|
readonly signed: boolean;
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
// grace's server: it answers the verification POST by echoing its challenge, which proves it
|
|
55
|
-
// asked for these deliveries, and acknowledges each delivery with a 2xx.
|
|
56
50
|
const subscriber =
|
|
57
51
|
(received: Queue.Enqueue<Received>) => async (request: Request) => {
|
|
58
52
|
const text = await request.text();
|
|
@@ -106,20 +100,14 @@ describe("the service, by webhook", () => {
|
|
|
106
100
|
),
|
|
107
101
|
});
|
|
108
102
|
|
|
109
|
-
// The answer names the subscription, which each POST's `x-mcp-subscription-id`
|
|
110
|
-
// carries, and when to subscribe again to keep it: one not refreshed by then ends.
|
|
111
103
|
const subscription = yield* subscribe;
|
|
112
104
|
const verification = yield* Queue.take(received);
|
|
113
105
|
|
|
114
106
|
yield* ada.finishBuild({ pipeline: "api", status: "passed" });
|
|
115
|
-
// Each build finished notifies `build.finished`: the server asks the store at once, and
|
|
116
|
-
// POSTs what it answers.
|
|
117
107
|
yield* ada.finishBuild({ pipeline: "web", status: "passed" });
|
|
118
108
|
|
|
119
|
-
// grace sees only the web pipeline.
|
|
120
109
|
const delivery = yield* Queue.take(received);
|
|
121
110
|
|
|
122
|
-
// The same request again refreshes the subscription, and answers how it is going.
|
|
123
111
|
const refreshed = yield* subscribe;
|
|
124
112
|
|
|
125
113
|
expect(verification).toMatchObject({
|
|
@@ -31,7 +31,7 @@ node --import tsx examples/kitchen-sink/src/agent.ts # the assis
|
|
|
31
31
|
vp test examples/kitchen-sink
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
`HOST`, `PORT`, `ADMIN_PORT`, `PUBLIC_URL` and `MCP_ORIGIN` configure the server; `TRACKER_URL` points the CLI and the seed at it. `stdio.ts` is an MCP server for a local agent to start as a subprocess. `sdk.ts` and `browser.ts` are imported by client code, not run. The OpenAPI document is at `/api/v1/openapi.json`, Swagger UI at `/docs`, the MCP endpoint at `/mcp`, the socket at `/rpc`.
|
|
34
|
+
`HOST`, `PORT`, `ADMIN_PORT`, `PUBLIC_URL` and `MCP_ORIGIN` configure the server; `TRACKER_URL` points the CLI and the seed at it. `stdio.ts` is an MCP server for a local agent to start as a subprocess: from the repository root, register it with `claude mcp add tracker -- "$PWD/node_modules/.bin/tsx" "$PWD/examples/kitchen-sink/src/stdio.ts"`, full paths since the host starts it in a directory of its choosing. `sdk.ts` and `browser.ts` are imported by client code, not run. The OpenAPI document is at `/api/v1/openapi.json`, Swagger UI at `/docs`, the MCP endpoint at `/mcp`, the socket at `/rpc`.
|
|
35
35
|
|
|
36
36
|
| Credential | Who | May |
|
|
37
37
|
| --- | --- | --- |
|
|
@@ -4,10 +4,6 @@ import { WhoAmI } from "./identity/Identity.js";
|
|
|
4
4
|
import { ExportIssues, Issues } from "./issues/Issues.js";
|
|
5
5
|
import { GetStatus } from "./workspaces/Workspaces.js";
|
|
6
6
|
|
|
7
|
-
// Which actions each surface gets. A contract says nothing about where it is served: each
|
|
8
|
-
// surface takes a list, and these are the lists, built from the contracts themselves.
|
|
9
|
-
|
|
10
|
-
/** What a signed-in member may call: every protected action of the public port. */
|
|
11
7
|
export const MemberActions = [
|
|
12
8
|
WhoAmI,
|
|
13
9
|
...Issues,
|
|
@@ -17,10 +13,4 @@ export const MemberActions = [
|
|
|
17
13
|
...Assistant,
|
|
18
14
|
] as const;
|
|
19
15
|
|
|
20
|
-
/**
|
|
21
|
-
* The MCP tools, for the HTTP endpoint and the stdio server alike. `attachImage` is left out:
|
|
22
|
-
* listing it throws, since MCP takes no image as input. So is the assistant: it is a model
|
|
23
|
-
* itself, and its tools are already here. So is `exportIssues`: a tool collects its stream
|
|
24
|
-
* whole before answering, every issue of the workspace at once in a model's context.
|
|
25
|
-
*/
|
|
26
16
|
export const Tools = [GetStatus, WhoAmI, ...Issues, GetAttachment] as const;
|
|
@@ -6,11 +6,6 @@ import { Login, QuotaExceeded } from "./identity/Identity.js";
|
|
|
6
6
|
import { IssueChanged } from "./issues/Issues.js";
|
|
7
7
|
import { GetStatus } from "./workspaces/Workspaces.js";
|
|
8
8
|
|
|
9
|
-
// The members' HTTP binding: every action at `POST /api/v1/<name>`, and `issue.changed` at
|
|
10
|
-
// `POST /api/v1/events/issue.changed`, polled or held open as a stream. It is plain data and
|
|
11
|
-
// imports no server code, so the server, the CLI, the SDK and a test all import this one value.
|
|
12
|
-
// - `authentication`: how the protected actions' caller proves who it is. `getStatus` is public.
|
|
13
|
-
// - `error`: the quota middleware's, so a client decodes its 429 as a typed `QuotaExceeded`.
|
|
14
9
|
export const Http = ActionHttp.make(
|
|
15
10
|
[GetStatus, ...MemberActions, IssueChanged],
|
|
16
11
|
{
|
|
@@ -20,9 +15,6 @@ export const Http = ActionHttp.make(
|
|
|
20
15
|
}
|
|
21
16
|
);
|
|
22
17
|
|
|
23
|
-
// The operators' binding: other actions, another identity, another descriptor, served on a port
|
|
24
|
-
// of its own.
|
|
25
|
-
// The public `getStatus` is bound here too: one contract, one implementation, on both ports.
|
|
26
18
|
export const AdminHttp = ActionHttp.make([GetStatus, ...Admin], {
|
|
27
19
|
prefix: "/admin",
|
|
28
20
|
authentication: OperatorKey,
|
|
@@ -4,10 +4,6 @@ import { MemberActions } from "./Actions.js";
|
|
|
4
4
|
import { QuotaExceeded, Session } from "./identity/Identity.js";
|
|
5
5
|
import { IssueChanged } from "./issues/Issues.js";
|
|
6
6
|
|
|
7
|
-
// The web app's binding: the members' actions as Effect RPC, one native rpc per action, and
|
|
8
|
-
// `issue.changed` as a stream rpc, over one WebSocket. Browser-safe, as the HTTP binding is. It
|
|
9
|
-
// names the other descriptor of the same identity: a page proves who it is with its session
|
|
10
|
-
// cookie, which the browser sends on the socket's upgrade. Its `error` is what the layer's middleware, the quota, fails with.
|
|
11
7
|
export const Rpc = ActionRpc.make([...MemberActions, IssueChanged], {
|
|
12
8
|
authentication: Session,
|
|
13
9
|
error: QuotaExceeded,
|
|
@@ -5,29 +5,21 @@ import { HttpApiSecurity } from "effect/http-api";
|
|
|
5
5
|
|
|
6
6
|
import { Workspace, WorkspaceNotFound } from "../workspaces/Workspaces.js";
|
|
7
7
|
|
|
8
|
-
/** What a verified operator key can name. */
|
|
9
8
|
export interface KeyOperator {
|
|
10
9
|
readonly id: string;
|
|
11
10
|
readonly trusted: false;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
/** What only a host supplies, on its own console. */
|
|
15
13
|
export interface TrustedOperator {
|
|
16
14
|
readonly id: string;
|
|
17
15
|
readonly trusted: true;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
/**
|
|
21
|
-
* The operators' identity, another audience than the members: its own service, its own
|
|
22
|
-
* descriptor, its own port. Typed in two parts, so the trusted one cannot arrive over the wire.
|
|
23
|
-
*/
|
|
24
18
|
export class Operator extends Context.Service<
|
|
25
19
|
Operator,
|
|
26
20
|
KeyOperator | TrustedOperator
|
|
27
21
|
>()("tracker/Operator") {}
|
|
28
22
|
|
|
29
|
-
// How a remote operator proves it: an API key in a header, a native scheme named by
|
|
30
|
-
// `security`. A key cannot step up, and has no OAuth discovery.
|
|
31
23
|
export const OperatorKey = Authentication.make(
|
|
32
24
|
"tracker.OperatorKey",
|
|
33
25
|
Operator,
|
|
@@ -36,7 +28,6 @@ export const OperatorKey = Authentication.make(
|
|
|
36
28
|
}
|
|
37
29
|
);
|
|
38
30
|
|
|
39
|
-
// What the two actions on one workspace share, their input and success included.
|
|
40
31
|
const onWorkspace = {
|
|
41
32
|
caller: Operator,
|
|
42
33
|
input: { workspace: Schema.String },
|
|
@@ -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 },
|