@feltdb/feltkit 0.3.37 → 0.5.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/dist/agent-engine.d.ts +93 -0
- package/dist/agent-engine.js +40 -0
- package/dist/agent-engine.js.map +1 -0
- package/dist/app.d.ts +306 -7
- package/dist/app.js +289 -28
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +7 -0
- package/dist/appboundry/build.js +25 -1
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +8 -0
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.d.ts +21 -0
- package/dist/appboundry/host.js +25 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/appboundry/runtime.js +1 -0
- package/dist/appboundry/runtime.js.map +1 -1
- package/dist/boards/index.d.ts +1258 -0
- package/dist/boards/index.js +1410 -0
- package/dist/boards/index.js.map +1 -0
- package/dist/boards/model.d.ts +177 -0
- package/dist/boards/model.js +177 -0
- package/dist/boards/model.js.map +1 -0
- package/dist/boards/react.d.ts +18 -0
- package/dist/boards/react.js +339 -0
- package/dist/boards/react.js.map +1 -0
- package/dist/cli/deploy-appboundry-self-hosted.js +2 -2
- package/dist/cli/deploy.js +19 -6
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +70 -5
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +454 -4
- package/dist/client/index.js +371 -3
- package/dist/client/index.js.map +1 -1
- package/dist/clock.d.ts +24 -0
- package/dist/clock.js +49 -0
- package/dist/clock.js.map +1 -0
- package/dist/cron.d.ts +18 -0
- package/dist/cron.js +67 -0
- package/dist/cron.js.map +1 -0
- package/dist/dashboard/assets/index-iIj7SL77.js +15 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +4 -0
- package/dist/docs.js.map +1 -1
- package/dist/eve/index.d.ts +77 -0
- package/dist/eve/index.js +128 -0
- package/dist/eve/index.js.map +1 -0
- package/dist/event-stage.js +2 -0
- package/dist/event-stage.js.map +1 -1
- package/dist/index.d.ts +17 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/native/build.d.ts +112 -0
- package/dist/native/build.js +472 -0
- package/dist/native/build.js.map +1 -0
- package/dist/native/index.d.ts +67 -0
- package/dist/native/index.js +113 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/instance.d.ts +3 -0
- package/dist/native/instance.js +18 -0
- package/dist/native/instance.js.map +1 -0
- package/dist/policy.d.ts +9 -1
- package/dist/policy.js +16 -3
- package/dist/policy.js.map +1 -1
- package/dist/presence.d.ts +85 -0
- package/dist/presence.js +37 -0
- package/dist/presence.js.map +1 -0
- package/dist/quota.d.ts +72 -0
- package/dist/quota.js +143 -0
- package/dist/quota.js.map +1 -0
- package/dist/react/agent-control.d.ts +191 -0
- package/dist/react/agent-control.js +366 -0
- package/dist/react/agent-control.js.map +1 -0
- package/dist/react/auth.d.ts +15 -1
- package/dist/react/auth.js +28 -5
- package/dist/react/auth.js.map +1 -1
- package/dist/react/hooks.d.ts +88 -0
- package/dist/react/hooks.js +188 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react/index.d.ts +5 -75
- package/dist/react/index.js +4 -145
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/activity.d.ts +8 -0
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent-control.d.ts +28 -0
- package/dist/runtime/agent-control.js +43 -2
- package/dist/runtime/agent-control.js.map +1 -1
- package/dist/runtime/agent-run.d.ts +166 -0
- package/dist/runtime/agent-run.js +431 -0
- package/dist/runtime/agent-run.js.map +1 -0
- package/dist/runtime/agent.d.ts +158 -1
- package/dist/runtime/agent.js +345 -12
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/assemble.js +15 -2
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/authority.d.ts +47 -0
- package/dist/runtime/authority.js +13 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/capabilities.js +2 -1
- package/dist/runtime/capabilities.js.map +1 -1
- package/dist/runtime/changes.d.ts +17 -0
- package/dist/runtime/changes.js +65 -2
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/context.d.ts +123 -0
- package/dist/runtime/contract.js +9 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/events.js +17 -1
- package/dist/runtime/events.js.map +1 -1
- package/dist/runtime/integrations.js +7 -7
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +19 -2
- package/dist/runtime/invocations.js +16 -3
- package/dist/runtime/invocations.js.map +1 -1
- package/dist/runtime/policies.d.ts +5 -2
- package/dist/runtime/policies.js.map +1 -1
- package/dist/runtime/presence-host.d.ts +84 -0
- package/dist/runtime/presence-host.js +303 -0
- package/dist/runtime/presence-host.js.map +1 -0
- package/dist/runtime/providers.d.ts +5 -1
- package/dist/runtime/providers.js +11 -5
- package/dist/runtime/providers.js.map +1 -1
- package/dist/runtime/required-capabilities.d.ts +73 -0
- package/dist/runtime/required-capabilities.js +69 -0
- package/dist/runtime/required-capabilities.js.map +1 -0
- package/dist/runtime/resource-access.d.ts +137 -0
- package/dist/runtime/resource-access.js +177 -0
- package/dist/runtime/resource-access.js.map +1 -0
- package/dist/runtime/runtime.d.ts +143 -1
- package/dist/runtime/runtime.js +853 -44
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/sessions.d.ts +12 -0
- package/dist/runtime/sessions.js +16 -1
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +68 -1
- package/dist/runtime/tenancy.js +150 -0
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +3 -1
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/runtime/workers.d.ts +123 -0
- package/dist/runtime/workers.js +291 -0
- package/dist/runtime/workers.js.map +1 -0
- package/dist/server/eve.d.ts +287 -0
- package/dist/server/eve.js +1071 -0
- package/dist/server/eve.js.map +1 -0
- package/dist/server/index.d.ts +2 -19
- package/dist/server/index.js +102 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.d.ts +15 -22
- package/dist/server/mcp.js +40 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/project.js +26 -8
- package/dist/server/project.js.map +1 -1
- package/dist/server/tenancy.d.ts +9 -0
- package/dist/server/tenancy.js +62 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/server/watch.d.ts +10 -0
- package/dist/server/watch.js +88 -0
- package/dist/server/watch.js.map +1 -0
- package/dist/testing/index.d.ts +4 -5
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-CONTROL.md +166 -4
- package/docs/APPBOUNDRY.md +73 -0
- package/docs/ARCHITECTURE.md +6 -2
- package/docs/AUTH.md +37 -0
- package/docs/COMPONENTS.md +71 -0
- package/docs/EVE-COMPOSITION.md +75 -0
- package/docs/GUARANTEES.md +4 -4
- package/docs/NATIVE-AGENTS.md +353 -0
- package/docs/NATIVE.md +137 -0
- package/docs/PRESENCE-AND-SIGNALING-PROPOSAL.md +152 -0
- package/docs/README.md +6 -2
- package/docs/SECURITY.md +71 -3
- package/docs/TRANSACTIONS.md +48 -0
- package/docs/UPSTREAM-GAPS.md +16 -2
- package/package.json +42 -16
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-agent/SKILL.md +1 -1
- package/skills/feltkit-build/SKILL.md +11 -1
- package/skills/feltkit-data/SKILL.md +1 -1
- package/skills/feltkit-operations/SKILL.md +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
- package/dist/dashboard/assets/index-BhxrvY37.js +0 -15
|
@@ -0,0 +1,1410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boards — durable coordination for people and agents, as an application capability.
|
|
3
|
+
*
|
|
4
|
+
* // feltkit/boards.ts
|
|
5
|
+
* import { defineBoards } from "@feltdb/feltkit/boards";
|
|
6
|
+
* import { app } from "./app.js";
|
|
7
|
+
* export const boards = defineBoards(app);
|
|
8
|
+
*
|
|
9
|
+
* One export gives the application boards, channels, threads (tasks and discussions), messages, claims
|
|
10
|
+
* with leases, dependencies, grants, history, watchers, follow-ups and an integration contract: every
|
|
11
|
+
* operation a function named `boards:<op>`, the agent-facing ones published as AppPort capabilities
|
|
12
|
+
* (`boards.*`, also MCP tools). People use them from `<Boards />` (`@feltdb/feltkit/boards/react`); agents
|
|
13
|
+
* and other applications through AppPort. There is one implementation and one store: what a person does
|
|
14
|
+
* and what an agent does land in the same records.
|
|
15
|
+
*
|
|
16
|
+
* Nothing here is a new mechanism. It is written against FeltKit's public API, and every guarantee is
|
|
17
|
+
* one FeltKit already makes:
|
|
18
|
+
*
|
|
19
|
+
* state FeltDB collections declared with app.collection (schema-validated, tenant-scoped when asked)
|
|
20
|
+
* consistency each operation is one mutation: one FeltDB transaction whose reads are fenced at commit
|
|
21
|
+
* (two agents claiming one task: one wins, the other gets CONFLICT and nothing is written)
|
|
22
|
+
* claims an app.presence collection: leases on the runtime's clock, ended exactly once
|
|
23
|
+
* (left / removed / expired / session-ended), ended leases kept as claim history
|
|
24
|
+
* history an append-only event log ordered by ctx.db.sequence per thread
|
|
25
|
+
* authority roles → each function's `access` (which operations), grants on boards and channels
|
|
26
|
+
* (where); checked in the function, so every interface (HTTP, AppPort, MCP) gets the same answer
|
|
27
|
+
* live updates live queries: a commit by anyone re-runs the queries that read what changed
|
|
28
|
+
* watchers ctx.afterCommit.agent: an app.agent runs after the triggering commit, as itself
|
|
29
|
+
* follow-ups ctx.afterCommit.jobs.enqueue(…, { runAt }): AppPort Services jobs, durable and retried
|
|
30
|
+
* outbound sync ctx.afterCommit.webhooks.emit: signed, retried deliveries to registered endpoints
|
|
31
|
+
*
|
|
32
|
+
* Deterministic rules (status machine, readiness, cycles, access levels) live in ./model.ts.
|
|
33
|
+
*/
|
|
34
|
+
import { functionGroup } from "../app.js";
|
|
35
|
+
import { fail } from "../errors.js";
|
|
36
|
+
import { s } from "../schema.js";
|
|
37
|
+
import { explainAccess, effectiveStatus, atLeast, normalizeLabels, settledReadiness, transition, wouldCycle, GRANT_LEVELS, STATUSES, SYSTEM, TERMINAL, THREAD_KINDS, WORKING, } from "./model.js";
|
|
38
|
+
export * from "./model.js";
|
|
39
|
+
/** Permissions Boards functions check (`access`). Grant them through roles, e.g. `member: ["boards.*"]`. */
|
|
40
|
+
export const BOARD_PERMISSIONS = {
|
|
41
|
+
/** See boards you have access to; read threads, messages, history. */
|
|
42
|
+
read: "boards.read",
|
|
43
|
+
/** Create threads, reply, react. */
|
|
44
|
+
post: "boards.post",
|
|
45
|
+
/** Claim and work tasks. */
|
|
46
|
+
work: "boards.work",
|
|
47
|
+
/** Labels, dependencies, links, status changes. */
|
|
48
|
+
manage: "boards.manage",
|
|
49
|
+
/** Create boards. (Administering one board needs an admin grant on it, which its creator receives.) */
|
|
50
|
+
create: "boards.create",
|
|
51
|
+
/** Board settings, channels, grants, watchers (also needs admin level on the board). */
|
|
52
|
+
admin: "boards.admin",
|
|
53
|
+
/** Import messages from external systems (an integration's principal). */
|
|
54
|
+
integrate: "boards.integrate",
|
|
55
|
+
};
|
|
56
|
+
export const WATCH_EVENTS = ["thread.created", "message.posted", "labels.changed", "status.changed", "task.completed", "task.failed", "task.ready", "followup.due"];
|
|
57
|
+
const ActorSchema = s.object({
|
|
58
|
+
id: s.string(),
|
|
59
|
+
type: s.enum(["user", "agent", "application", "system"]),
|
|
60
|
+
name: s.optional(s.string()),
|
|
61
|
+
onBehalfOf: s.optional(s.object({ id: s.string(), via: s.enum(["delegation", "work-grant"]) })),
|
|
62
|
+
});
|
|
63
|
+
const LinkInput = s.object({ kind: s.string({ minLength: 1, maxLength: 40 }), url: s.string({ minLength: 1, maxLength: 2000 }), title: s.optional(s.string({ maxLength: 200 })), externalId: s.optional(s.string({ maxLength: 200 })) });
|
|
64
|
+
const Json = s.record(s.unknown());
|
|
65
|
+
const open = (shape) => s.object(shape, { additionalProperties: true });
|
|
66
|
+
export function defineBoards(app, options = {}) {
|
|
67
|
+
const prefix = options.prefix ?? "boards";
|
|
68
|
+
if (!/^[a-z][a-z0-9_]{0,30}$/.test(prefix))
|
|
69
|
+
throw new TypeError(`defineBoards: prefix "${prefix}" must be lowercase letters, digits and "_".`);
|
|
70
|
+
const ttlMs = options.claimTtlMs ?? 600_000;
|
|
71
|
+
const tenant = options.tenant ? { tenant: true } : {};
|
|
72
|
+
const followupJob = options.followupJob ?? "boards.followup";
|
|
73
|
+
const schemas = options.schemas ?? {};
|
|
74
|
+
for (const [name, versions] of Object.entries(schemas)) {
|
|
75
|
+
if (!/^[a-z][a-z0-9._-]{0,63}$/.test(name))
|
|
76
|
+
throw new TypeError(`defineBoards: schema name "${name}" must be lowercase letters, digits, ".", "_" or "-".`);
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
for (const v of versions) {
|
|
79
|
+
if (!Number.isInteger(v.version) || v.version < 1 || seen.has(v.version))
|
|
80
|
+
throw new TypeError(`defineBoards: schema ${name} needs distinct positive integer versions.`);
|
|
81
|
+
seen.add(v.version);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const P = BOARD_PERMISSIONS;
|
|
85
|
+
// ---- Collections (FeltDB, the authority) --------------------------------------------------------
|
|
86
|
+
const boards = app.collection(prefix, {
|
|
87
|
+
name: s.string({ minLength: 1, maxLength: 80 }),
|
|
88
|
+
description: s.optional(s.string({ maxLength: 2000 })),
|
|
89
|
+
visibility: s.enum(["open", "restricted"]),
|
|
90
|
+
archived: s.boolean(),
|
|
91
|
+
createdBy: ActorSchema,
|
|
92
|
+
createdAt: s.number(),
|
|
93
|
+
updatedAt: s.number(),
|
|
94
|
+
}, { ...tenant });
|
|
95
|
+
const channels = app.collection(`${prefix}_channels`, {
|
|
96
|
+
boardId: s.ref(boards),
|
|
97
|
+
name: s.string({ minLength: 1, maxLength: 60 }),
|
|
98
|
+
purpose: s.optional(s.string({ maxLength: 500 })),
|
|
99
|
+
restricted: s.boolean(),
|
|
100
|
+
archived: s.boolean(),
|
|
101
|
+
createdBy: ActorSchema,
|
|
102
|
+
createdAt: s.number(),
|
|
103
|
+
}, { ...tenant, unique: [["boardId", "name"]], indexes: [{ fields: ["boardId"] }] });
|
|
104
|
+
const threads = app.collection(`${prefix}_threads`, {
|
|
105
|
+
boardId: s.ref(boards),
|
|
106
|
+
channelId: s.ref(channels),
|
|
107
|
+
kind: s.enum([...THREAD_KINDS]),
|
|
108
|
+
title: s.string({ minLength: 1, maxLength: 200 }),
|
|
109
|
+
body: s.optional(s.string({ maxLength: 20_000 })),
|
|
110
|
+
status: s.enum([...STATUSES]),
|
|
111
|
+
labels: s.array(s.string()),
|
|
112
|
+
metadata: Json,
|
|
113
|
+
manualBlock: s.optional(s.object({ reason: s.string(), by: ActorSchema, at: s.number() })),
|
|
114
|
+
result: s.optional(s.object({ summary: s.string(), data: s.optional(Json), by: ActorSchema, at: s.number(), outcome: s.enum(["completed", "failed"]) })),
|
|
115
|
+
createdBy: ActorSchema,
|
|
116
|
+
createdAt: s.number(),
|
|
117
|
+
updatedAt: s.number(),
|
|
118
|
+
}, { ...tenant, indexes: [{ fields: ["channelId"] }, { fields: ["boardId"] }], search: ["title", "body"] });
|
|
119
|
+
const messages = app.collection(`${prefix}_messages`, {
|
|
120
|
+
threadId: s.ref(threads),
|
|
121
|
+
boardId: s.string(),
|
|
122
|
+
channelId: s.string(),
|
|
123
|
+
seq: s.number(),
|
|
124
|
+
author: ActorSchema,
|
|
125
|
+
text: s.string({ maxLength: 20_000 }),
|
|
126
|
+
kind: s.enum(["message", "progress", "result", "system"]),
|
|
127
|
+
replyTo: s.optional(s.string()),
|
|
128
|
+
structured: s.optional(s.object({ schema: s.string(), version: s.number(), data: s.unknown() })),
|
|
129
|
+
external: s.optional(s.object({ source: s.string(), id: s.string(), updatedAt: s.number(), url: s.optional(s.string()), author: s.optional(s.string()) })),
|
|
130
|
+
externalKey: s.optional(s.string()),
|
|
131
|
+
outbound: s.optional(s.array(s.object({ via: s.string(), outboxId: s.string(), event: s.string(), at: s.number() }))),
|
|
132
|
+
createdAt: s.number(),
|
|
133
|
+
editedAt: s.optional(s.number()),
|
|
134
|
+
deleted: s.boolean(),
|
|
135
|
+
deletedBy: s.optional(ActorSchema),
|
|
136
|
+
}, { ...tenant, unique: [{ fields: ["externalKey"], sparse: true }], indexes: [{ fields: ["threadId"] }, { fields: ["channelId"] }], search: ["text"] });
|
|
137
|
+
const reactions = app.collection(`${prefix}_reactions`, {
|
|
138
|
+
messageId: s.string(),
|
|
139
|
+
threadId: s.string(),
|
|
140
|
+
emoji: s.string({ minLength: 1, maxLength: 32 }),
|
|
141
|
+
actorId: s.string(),
|
|
142
|
+
at: s.number(),
|
|
143
|
+
}, { ...tenant, unique: [["messageId", "emoji", "actorId"]], indexes: [{ fields: ["threadId"] }] });
|
|
144
|
+
const deps = app.collection(`${prefix}_dependencies`, {
|
|
145
|
+
boardId: s.string(),
|
|
146
|
+
taskId: s.string(),
|
|
147
|
+
dependsOn: s.string(),
|
|
148
|
+
createdBy: ActorSchema,
|
|
149
|
+
createdAt: s.number(),
|
|
150
|
+
}, { ...tenant, unique: [["taskId", "dependsOn"]], indexes: [{ fields: ["boardId"] }, { fields: ["dependsOn"] }] });
|
|
151
|
+
const links = app.collection(`${prefix}_links`, {
|
|
152
|
+
threadId: s.string(),
|
|
153
|
+
boardId: s.string(),
|
|
154
|
+
kind: s.string(),
|
|
155
|
+
url: s.string(),
|
|
156
|
+
title: s.optional(s.string()),
|
|
157
|
+
externalId: s.optional(s.string()),
|
|
158
|
+
/** `<kind>:<externalId>`: an external object is linked to one thread. */
|
|
159
|
+
key: s.optional(s.string()),
|
|
160
|
+
createdBy: ActorSchema,
|
|
161
|
+
createdAt: s.number(),
|
|
162
|
+
}, { ...tenant, unique: [{ fields: ["key"], sparse: true }], indexes: [{ fields: ["threadId"] }] });
|
|
163
|
+
const grants = app.collection(`${prefix}_grants`, {
|
|
164
|
+
boardId: s.string(),
|
|
165
|
+
channelId: s.optional(s.string()),
|
|
166
|
+
principal: s.string({ minLength: 1, maxLength: 200 }),
|
|
167
|
+
level: s.enum([...GRANT_LEVELS]),
|
|
168
|
+
grantedBy: ActorSchema,
|
|
169
|
+
grantedAt: s.number(),
|
|
170
|
+
revoked: s.boolean(),
|
|
171
|
+
revokedBy: s.optional(ActorSchema),
|
|
172
|
+
revokedAt: s.optional(s.number()),
|
|
173
|
+
}, { ...tenant, indexes: [{ fields: ["boardId"] }, { fields: ["principal"] }] });
|
|
174
|
+
const events = app.collection(`${prefix}_events`, {
|
|
175
|
+
boardId: s.string(),
|
|
176
|
+
channelId: s.optional(s.string()),
|
|
177
|
+
threadId: s.optional(s.string()),
|
|
178
|
+
seq: s.number(),
|
|
179
|
+
type: s.string(),
|
|
180
|
+
actor: ActorSchema,
|
|
181
|
+
data: Json,
|
|
182
|
+
at: s.number(),
|
|
183
|
+
}, { ...tenant, indexes: [{ fields: ["boardId"] }, { fields: ["threadId"] }] });
|
|
184
|
+
const claims = app.presence(`${prefix}_claims`, {
|
|
185
|
+
threadId: s.string(),
|
|
186
|
+
boardId: s.string(),
|
|
187
|
+
channelId: s.string(),
|
|
188
|
+
actor: ActorSchema,
|
|
189
|
+
note: s.optional(s.string({ maxLength: 500 })),
|
|
190
|
+
/** The claim this one took over after its lease lapsed. */
|
|
191
|
+
recoveredFrom: s.optional(s.string()),
|
|
192
|
+
}, { ttlMs, history: true, ...tenant, indexes: [{ fields: ["threadId"] }, { fields: ["boardId"] }] });
|
|
193
|
+
const watchers = app.collection(`${prefix}_watchers`, {
|
|
194
|
+
boardId: s.string(),
|
|
195
|
+
channelId: s.optional(s.string()),
|
|
196
|
+
on: s.array(s.enum([...WATCH_EVENTS])),
|
|
197
|
+
labels: s.array(s.string()),
|
|
198
|
+
agent: s.string(),
|
|
199
|
+
active: s.boolean(),
|
|
200
|
+
createdBy: ActorSchema,
|
|
201
|
+
createdAt: s.number(),
|
|
202
|
+
}, { ...tenant, indexes: [{ fields: ["boardId"] }] });
|
|
203
|
+
const watchRuns = app.collection(`${prefix}_watch_runs`, {
|
|
204
|
+
watcherId: s.string(),
|
|
205
|
+
boardId: s.string(),
|
|
206
|
+
threadId: s.optional(s.string()),
|
|
207
|
+
eventId: s.string(),
|
|
208
|
+
eventType: s.string(),
|
|
209
|
+
agent: s.string(),
|
|
210
|
+
/** The after-commit record that runs the agent: the execution. Its outcome is the agent's own writes. */
|
|
211
|
+
outboxId: s.string(),
|
|
212
|
+
at: s.number(),
|
|
213
|
+
}, { ...tenant, indexes: [{ fields: ["boardId"] }, { fields: ["threadId"] }] });
|
|
214
|
+
const followups = app.collection(`${prefix}_followups`, {
|
|
215
|
+
boardId: s.string(),
|
|
216
|
+
threadId: s.string(),
|
|
217
|
+
dueAt: s.number(),
|
|
218
|
+
note: s.string({ minLength: 1, maxLength: 1000 }),
|
|
219
|
+
state: s.enum(["scheduled", "fired", "cancelled"]),
|
|
220
|
+
/** Changes on every (re)schedule; a job carrying an older token is a no-op. */
|
|
221
|
+
token: s.string(),
|
|
222
|
+
createdBy: ActorSchema,
|
|
223
|
+
createdAt: s.number(),
|
|
224
|
+
runs: s.array(s.object({ at: s.number(), token: s.string(), outcome: s.enum(["fired", "skipped"]), reason: s.optional(s.string()), outboxId: s.optional(s.string()) })),
|
|
225
|
+
jobs: s.array(s.object({ outboxId: s.string(), token: s.string(), runAt: s.number() })),
|
|
226
|
+
}, { ...tenant, indexes: [{ fields: ["threadId"] }, { fields: ["boardId"] }] });
|
|
227
|
+
const collections = { boards, channels, threads, messages, reactions, deps, links, grants, events, claims, watchers, watchRuns, followups };
|
|
228
|
+
// ---- Helpers ------------------------------------------------------------------------------------
|
|
229
|
+
const now = () => Date.now();
|
|
230
|
+
function actorOf(ctx) {
|
|
231
|
+
const p = ctx.auth.requirePrincipal();
|
|
232
|
+
const type = p.type === "user" ? "user" : p.type === "agent" ? "agent" : "application";
|
|
233
|
+
const actor = { id: p.id, type, ...(p.displayName ? { name: p.displayName } : {}) };
|
|
234
|
+
const delegated = ctx.auth.delegation?.person;
|
|
235
|
+
const verifiedActor = ctx.auth.invocation?.verified?.actor?.id;
|
|
236
|
+
if (typeof delegated === "string" && delegated !== p.id)
|
|
237
|
+
actor.onBehalfOf = { id: delegated, via: "delegation" };
|
|
238
|
+
else if (p.worker && typeof verifiedActor === "string" && verifiedActor !== p.id)
|
|
239
|
+
actor.onBehalfOf = { id: verifiedActor, via: "work-grant" };
|
|
240
|
+
return actor;
|
|
241
|
+
}
|
|
242
|
+
const principalOf = (ctx) => {
|
|
243
|
+
const p = ctx.auth.requirePrincipal();
|
|
244
|
+
return { id: p.id, roles: (p.roles ?? []) };
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Whether the caller may act on someone else's thread, message, claim or follow-up: manage level where it
|
|
248
|
+
* is (scope) AND the manage permission from its roles (operation). Either alone is not enough.
|
|
249
|
+
*/
|
|
250
|
+
const canManage = (ctx, level) => atLeast(level, "manage") && ctx.auth.has(P.manage);
|
|
251
|
+
async function grantsFor(ctx, boardId) {
|
|
252
|
+
return (await ctx.db.find(grants, { boardId }));
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The board (and channel) a call works on and the caller's level there, or a refusal. A board or channel
|
|
256
|
+
* the caller may not read is NOT_FOUND, the same answer as one that does not exist.
|
|
257
|
+
*/
|
|
258
|
+
async function scope(ctx, boardId, channelId, need) {
|
|
259
|
+
const board = (await ctx.db.get(boards, boardId));
|
|
260
|
+
if (!board)
|
|
261
|
+
fail("NOT_FOUND", "No such board.");
|
|
262
|
+
let channel = null;
|
|
263
|
+
if (channelId) {
|
|
264
|
+
channel = (await ctx.db.get(channels, channelId));
|
|
265
|
+
if (!channel || channel.boardId !== boardId)
|
|
266
|
+
fail("NOT_FOUND", "No such channel.");
|
|
267
|
+
}
|
|
268
|
+
const { level } = explainAccess(board, channel, (await grantsFor(ctx, boardId)), principalOf(ctx));
|
|
269
|
+
if (level === "none")
|
|
270
|
+
fail("NOT_FOUND", channelId ? "No such channel." : "No such board.");
|
|
271
|
+
if (!atLeast(level, need))
|
|
272
|
+
fail("FORBIDDEN", `This needs ${need} access ${channelId ? "to the channel" : "to the board"}; you have ${level}.`);
|
|
273
|
+
if (need !== "read" && need !== "admin" && (board.archived || channel?.archived))
|
|
274
|
+
fail("FAILED_PRECONDITION", `The ${board.archived ? "board" : "channel"} is archived.`);
|
|
275
|
+
return { board: board, channel, level };
|
|
276
|
+
}
|
|
277
|
+
async function threadScope(ctx, threadId, need) {
|
|
278
|
+
const thread = (await ctx.db.get(threads, threadId));
|
|
279
|
+
if (!thread)
|
|
280
|
+
fail("NOT_FOUND", "No such thread.");
|
|
281
|
+
const sc = await scope(ctx, thread.boardId, thread.channelId, need).catch((e) => {
|
|
282
|
+
if (e.code === "NOT_FOUND")
|
|
283
|
+
fail("NOT_FOUND", "No such thread.");
|
|
284
|
+
throw e;
|
|
285
|
+
});
|
|
286
|
+
return { ...sc, thread: thread };
|
|
287
|
+
}
|
|
288
|
+
async function readiness(ctx, taskId, thread) {
|
|
289
|
+
const edges = (await ctx.db.find(deps, { taskId }));
|
|
290
|
+
let unmet = 0;
|
|
291
|
+
const upstream = [];
|
|
292
|
+
for (const e of edges) {
|
|
293
|
+
const t = (await ctx.db.get(threads, e.dependsOn));
|
|
294
|
+
if (!t)
|
|
295
|
+
continue;
|
|
296
|
+
upstream.push({ id: t.id, title: t.title, status: t.status });
|
|
297
|
+
if (t.status !== "completed")
|
|
298
|
+
unmet += 1;
|
|
299
|
+
}
|
|
300
|
+
const self = thread ?? (await ctx.db.get(threads, taskId));
|
|
301
|
+
return { unmet, manualBlock: !!self?.manualBlock, upstream };
|
|
302
|
+
}
|
|
303
|
+
async function liveClaim(ctx, threadId) {
|
|
304
|
+
const live = (await ctx.db.find(claims, { threadId }));
|
|
305
|
+
return live[0] ?? null;
|
|
306
|
+
}
|
|
307
|
+
/** Append to the history and fire matching watchers, in this mutation's transaction. */
|
|
308
|
+
async function record(ctx, e) {
|
|
309
|
+
const stream = e.threadId ? `${prefix}:t:${e.threadId}` : `${prefix}:b:${e.boardId}`;
|
|
310
|
+
const seq = await ctx.db.sequence(stream);
|
|
311
|
+
const at = now();
|
|
312
|
+
const id = await ctx.db.insert(events, {
|
|
313
|
+
boardId: e.boardId,
|
|
314
|
+
...(e.channelId ? { channelId: e.channelId } : {}),
|
|
315
|
+
...(e.threadId ? { threadId: e.threadId } : {}),
|
|
316
|
+
seq,
|
|
317
|
+
type: e.type,
|
|
318
|
+
actor: e.actor,
|
|
319
|
+
data: e.data ?? {},
|
|
320
|
+
at,
|
|
321
|
+
});
|
|
322
|
+
if (WATCH_EVENTS.includes(e.type)) {
|
|
323
|
+
for (const w of (await ctx.db.find(watchers, { boardId: e.boardId, active: true }))) {
|
|
324
|
+
if (!w.on.includes(e.type))
|
|
325
|
+
continue;
|
|
326
|
+
if (w.channelId && w.channelId !== e.channelId)
|
|
327
|
+
continue;
|
|
328
|
+
if (w.labels.length && !(e.labels ?? []).some((l) => w.labels.includes(l)))
|
|
329
|
+
continue;
|
|
330
|
+
// An agent's own writes do not wake it again (no loops).
|
|
331
|
+
if (app.agents.get(w.agent)?.principal.id === e.actor.id)
|
|
332
|
+
continue;
|
|
333
|
+
const input = { watcherId: w.id, boardId: e.boardId, channelId: e.channelId ?? null, threadId: e.threadId ?? null, event: { id, type: e.type, seq, actor: e.actor, data: e.data ?? {}, at } };
|
|
334
|
+
const { outboxId } = ctx.afterCommit.agent(w.agent, input);
|
|
335
|
+
await ctx.db.insert(watchRuns, { watcherId: w.id, boardId: e.boardId, ...(e.threadId ? { threadId: e.threadId } : {}), eventId: id, eventType: e.type, agent: w.agent, outboxId, at });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return id;
|
|
339
|
+
}
|
|
340
|
+
async function nextSeq(ctx, threadId) {
|
|
341
|
+
return ctx.db.sequence(`${prefix}:t:${threadId}`);
|
|
342
|
+
}
|
|
343
|
+
async function outbound(ctx, thread, event, payload) {
|
|
344
|
+
if (!options.outboundWebhooks)
|
|
345
|
+
return [];
|
|
346
|
+
const linked = (await ctx.db.find(links, { threadId: thread.id }));
|
|
347
|
+
if (!linked.length)
|
|
348
|
+
return [];
|
|
349
|
+
const { outboxId } = ctx.afterCommit.webhooks.emit(event, {
|
|
350
|
+
boardId: thread.boardId,
|
|
351
|
+
channelId: thread.channelId,
|
|
352
|
+
threadId: thread.id,
|
|
353
|
+
links: linked.map((l) => ({ kind: l.kind, url: l.url, externalId: l.externalId ?? null })),
|
|
354
|
+
...payload,
|
|
355
|
+
});
|
|
356
|
+
return [{ via: "webhooks", outboxId, event, at: now() }];
|
|
357
|
+
}
|
|
358
|
+
async function postInternal(ctx, thread, author, text, kind, extra = {}) {
|
|
359
|
+
const seq = await nextSeq(ctx, thread.id);
|
|
360
|
+
const createdAt = now();
|
|
361
|
+
const id = await ctx.db.insert(messages, { threadId: thread.id, boardId: thread.boardId, channelId: thread.channelId, seq, author, text, kind, createdAt, deleted: false, ...extra });
|
|
362
|
+
return { id, seq, createdAt };
|
|
363
|
+
}
|
|
364
|
+
/** Re-evaluate every task that depends on `taskId` (after it completed or a dependency changed). */
|
|
365
|
+
async function propagate(ctx, taskId, actor) {
|
|
366
|
+
for (const edge of (await ctx.db.find(deps, { dependsOn: taskId }))) {
|
|
367
|
+
const t = (await ctx.db.get(threads, edge.taskId));
|
|
368
|
+
if (!t)
|
|
369
|
+
continue;
|
|
370
|
+
const r = await readiness(ctx, t.id, t);
|
|
371
|
+
const next = settledReadiness(t.status, r);
|
|
372
|
+
if (next !== t.status) {
|
|
373
|
+
await ctx.db.patch(threads, t.id, { status: next, updatedAt: now() });
|
|
374
|
+
await record(ctx, { boardId: t.boardId, channelId: t.channelId, threadId: t.id, type: next === "ready" ? "task.ready" : "status.changed", actor: { ...SYSTEM }, data: { from: t.status, to: next, cause: { task: taskId, by: actor.id } }, labels: t.labels });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async function view(ctx, thread, claimRec) {
|
|
379
|
+
const live = claimRec === undefined ? await liveClaim(ctx, thread.id) : claimRec;
|
|
380
|
+
const r = thread.kind === "task" ? await readiness(ctx, thread.id, thread) : { unmet: 0, manualBlock: false, upstream: [] };
|
|
381
|
+
const eff = effectiveStatus(thread.status, thread.kind, !!live, r);
|
|
382
|
+
return {
|
|
383
|
+
...thread,
|
|
384
|
+
status: eff.status,
|
|
385
|
+
storedStatus: thread.status,
|
|
386
|
+
leaseLapsed: eff.lapsed,
|
|
387
|
+
unmetDependencies: r.unmet,
|
|
388
|
+
claim: live ? { id: live.id, actor: live.actor, holder: live.holder, startedAt: live.startedAt, renewedAt: live.renewedAt, expiresAt: live.expiresAt ?? null, note: live.note ?? null } : null,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function validateStructured(input) {
|
|
392
|
+
if (!input)
|
|
393
|
+
return undefined;
|
|
394
|
+
const versions = schemas[input.schema];
|
|
395
|
+
if (!versions?.length)
|
|
396
|
+
fail("INVALID_ARGUMENT", `No message schema "${input.schema}". Known: ${Object.keys(schemas).join(", ") || "none"}.`);
|
|
397
|
+
const chosen = input.version === undefined ? [...versions].sort((a, b) => b.version - a.version)[0] : versions.find((v) => v.version === input.version);
|
|
398
|
+
if (!chosen)
|
|
399
|
+
fail("INVALID_ARGUMENT", `Schema ${input.schema} has no version ${input.version} (has ${versions.map((v) => v.version).join(", ")}).`);
|
|
400
|
+
const checked = chosen.schema.validate(input.data);
|
|
401
|
+
if (!checked.ok)
|
|
402
|
+
fail("INVALID_ARGUMENT", `Structured data does not match ${input.schema}@${chosen.version}: ${(checked.issues ?? []).map((i) => `${i.path.join(".") || "(root)"} ${i.message}`).join("; ")}`);
|
|
403
|
+
return { schema: input.schema, version: chosen.version, data: checked.value };
|
|
404
|
+
}
|
|
405
|
+
async function transitionTask(ctx, thread, action, actor, extra = {}) {
|
|
406
|
+
const live = await liveClaim(ctx, thread.id);
|
|
407
|
+
const r = await readiness(ctx, thread.id, thread);
|
|
408
|
+
const eff = effectiveStatus(thread.status, thread.kind, !!live, r);
|
|
409
|
+
const t = transition(thread.kind, eff.status, action, action === "unblock" ? { ...r, manualBlock: false } : r);
|
|
410
|
+
if (!t.ok)
|
|
411
|
+
fail("FAILED_PRECONDITION", t.reason);
|
|
412
|
+
const to = t.to;
|
|
413
|
+
await ctx.db.patch(threads, thread.id, { status: to, updatedAt: now(), ...extra });
|
|
414
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "status.changed", actor, data: { action, from: eff.status, to }, labels: thread.labels });
|
|
415
|
+
if (to === "completed" && thread.kind === "task")
|
|
416
|
+
await propagate(ctx, thread.id, actor);
|
|
417
|
+
return { from: eff.status, to, live };
|
|
418
|
+
}
|
|
419
|
+
// ---- Return contracts ---------------------------------------------------------------------------
|
|
420
|
+
const BoardOut = open({ id: s.string(), name: s.string(), visibility: s.string(), archived: s.boolean() });
|
|
421
|
+
const ThreadOut = open({ id: s.string(), boardId: s.string(), channelId: s.string(), kind: s.string(), title: s.string(), status: s.enum([...STATUSES]), labels: s.array(s.string()) });
|
|
422
|
+
const Ok = s.object({ id: s.string() });
|
|
423
|
+
const recId = (id) => ({ id });
|
|
424
|
+
// ---- Boards and channels ------------------------------------------------------------------------
|
|
425
|
+
const listBoards = app.query({
|
|
426
|
+
access: P.read,
|
|
427
|
+
args: { includeArchived: s.optional(s.boolean()) },
|
|
428
|
+
returns: s.array(BoardOut),
|
|
429
|
+
capability: { name: "boards.list", description: "List the boards you can access, with your access level on each." },
|
|
430
|
+
handler: async (ctx, { includeArchived }) => {
|
|
431
|
+
const me = principalOf(ctx);
|
|
432
|
+
const all = (await ctx.db.find(boards, {}, { orderBy: [{ field: "createdAt", direction: "asc" }] }));
|
|
433
|
+
const out = [];
|
|
434
|
+
for (const b of all) {
|
|
435
|
+
if (b.archived && !includeArchived)
|
|
436
|
+
continue;
|
|
437
|
+
const { level } = explainAccess(b, null, (await grantsFor(ctx, b.id)), me);
|
|
438
|
+
if (level !== "none")
|
|
439
|
+
out.push({ ...b, level });
|
|
440
|
+
}
|
|
441
|
+
return out;
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
const getBoard = app.query({
|
|
445
|
+
access: P.read,
|
|
446
|
+
args: { boardId: s.string() },
|
|
447
|
+
returns: open({ board: BoardOut, level: s.string(), channels: s.array(open({ id: s.string(), name: s.string() })), counts: s.record(s.number()) }),
|
|
448
|
+
capability: { name: "boards.get", description: "A board: its channels you can access, your level, and task counts by status." },
|
|
449
|
+
handler: async (ctx, { boardId }) => {
|
|
450
|
+
const { board, level } = await scope(ctx, boardId, null, "read");
|
|
451
|
+
const me = principalOf(ctx);
|
|
452
|
+
const g = await grantsFor(ctx, boardId);
|
|
453
|
+
const visible = [];
|
|
454
|
+
for (const c of (await ctx.db.find(channels, { boardId }, { orderBy: [{ field: "createdAt", direction: "asc" }] }))) {
|
|
455
|
+
const l = explainAccess(board, c, g, me).level;
|
|
456
|
+
if (l !== "none")
|
|
457
|
+
visible.push({ ...c, level: l });
|
|
458
|
+
}
|
|
459
|
+
const visibleIds = new Set(visible.map((c) => c.id));
|
|
460
|
+
const counts = Object.fromEntries(STATUSES.map((st) => [st, 0]));
|
|
461
|
+
const live = new Set((await ctx.db.find(claims, { boardId })).map((c) => c.threadId));
|
|
462
|
+
const allDeps = (await ctx.db.find(deps, { boardId }));
|
|
463
|
+
const all = (await ctx.db.find(threads, { boardId }));
|
|
464
|
+
const byId = new Map(all.map((t) => [t.id, t]));
|
|
465
|
+
for (const t of all) {
|
|
466
|
+
if (!visibleIds.has(t.channelId))
|
|
467
|
+
continue;
|
|
468
|
+
const unmet = allDeps.filter((d) => d.taskId === t.id && byId.get(d.dependsOn)?.status !== "completed").length;
|
|
469
|
+
counts[effectiveStatus(t.status, t.kind, live.has(t.id), { unmet, manualBlock: !!t.manualBlock }).status] += 1;
|
|
470
|
+
}
|
|
471
|
+
return { board, level, channels: visible, counts };
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
const createBoard = app.mutation({
|
|
475
|
+
access: P.create,
|
|
476
|
+
args: { name: s.string({ minLength: 1, maxLength: 80 }), description: s.optional(s.string({ maxLength: 2000 })), visibility: s.optional(s.enum(["open", "restricted"])) },
|
|
477
|
+
returns: Ok,
|
|
478
|
+
retry: { sequenceConflicts: 3 },
|
|
479
|
+
capability: { name: "boards.create", description: "Create a board. Its creator is its admin." },
|
|
480
|
+
handler: async (ctx, { name, description, visibility }) => {
|
|
481
|
+
const actor = actorOf(ctx);
|
|
482
|
+
const at = now();
|
|
483
|
+
const id = await ctx.db.insert(boards, { name: name.trim(), ...(description?.trim() ? { description: description.trim() } : {}), visibility: visibility ?? "open", archived: false, createdBy: actor, createdAt: at, updatedAt: at });
|
|
484
|
+
await ctx.db.insert(grants, { boardId: id, principal: actor.id, level: "admin", grantedBy: actor, grantedAt: at, revoked: false });
|
|
485
|
+
await record(ctx, { boardId: id, type: "board.created", actor, data: { name: name.trim(), visibility: visibility ?? "open" } });
|
|
486
|
+
return recId(id);
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
const updateBoard = app.mutation({
|
|
490
|
+
access: P.admin,
|
|
491
|
+
args: { boardId: s.string(), name: s.optional(s.string({ minLength: 1, maxLength: 80 })), description: s.optional(s.string({ maxLength: 2000 })), visibility: s.optional(s.enum(["open", "restricted"])), archived: s.optional(s.boolean()) },
|
|
492
|
+
returns: Ok,
|
|
493
|
+
retry: { sequenceConflicts: 3 },
|
|
494
|
+
capability: { name: "boards.update", description: "Rename, describe, restrict, archive or unarchive a board (board admins)." },
|
|
495
|
+
handler: async (ctx, { boardId, ...change }) => {
|
|
496
|
+
await scope(ctx, boardId, null, "admin");
|
|
497
|
+
const patch = Object.fromEntries(Object.entries(change).filter(([, v]) => v !== undefined));
|
|
498
|
+
if (typeof patch.name === "string")
|
|
499
|
+
patch.name = patch.name.trim();
|
|
500
|
+
await ctx.db.patch(boards, boardId, { ...patch, updatedAt: now() });
|
|
501
|
+
await record(ctx, { boardId, type: change.archived === true ? "board.archived" : change.archived === false ? "board.unarchived" : "board.updated", actor: actorOf(ctx), data: patch });
|
|
502
|
+
return recId(boardId);
|
|
503
|
+
},
|
|
504
|
+
});
|
|
505
|
+
const createChannel = app.mutation({
|
|
506
|
+
access: P.admin,
|
|
507
|
+
args: { boardId: s.string(), name: s.string({ minLength: 1, maxLength: 60 }), purpose: s.optional(s.string({ maxLength: 500 })), restricted: s.optional(s.boolean()) },
|
|
508
|
+
returns: Ok,
|
|
509
|
+
retry: { sequenceConflicts: 3 },
|
|
510
|
+
capability: { name: "boards.channels.create", description: "Create a channel in a board (board admins). A restricted channel is reachable only through channel grants and board admins." },
|
|
511
|
+
handler: async (ctx, { boardId, name, purpose, restricted }) => {
|
|
512
|
+
await scope(ctx, boardId, null, "admin");
|
|
513
|
+
const clean = name.trim().toLowerCase().replace(/\s+/g, "-");
|
|
514
|
+
if ((await ctx.db.find(channels, { boardId, name: clean })).length)
|
|
515
|
+
fail("FAILED_PRECONDITION", `The board already has a channel named ${clean}.`);
|
|
516
|
+
const actor = actorOf(ctx);
|
|
517
|
+
const id = await ctx.db.insert(channels, { boardId, name: clean, ...(purpose?.trim() ? { purpose: purpose.trim() } : {}), restricted: restricted ?? false, archived: false, createdBy: actor, createdAt: now() });
|
|
518
|
+
await record(ctx, { boardId, channelId: id, type: "channel.created", actor, data: { name: clean, restricted: restricted ?? false } });
|
|
519
|
+
return recId(id);
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
const updateChannel = app.mutation({
|
|
523
|
+
access: P.admin,
|
|
524
|
+
args: { channelId: s.string(), name: s.optional(s.string({ minLength: 1, maxLength: 60 })), purpose: s.optional(s.string({ maxLength: 500 })), restricted: s.optional(s.boolean()), archived: s.optional(s.boolean()) },
|
|
525
|
+
returns: Ok,
|
|
526
|
+
retry: { sequenceConflicts: 3 },
|
|
527
|
+
capability: { name: "boards.channels.update", description: "Rename, re-purpose, restrict or archive a channel (board admins)." },
|
|
528
|
+
handler: async (ctx, { channelId, ...change }) => {
|
|
529
|
+
const channel = (await ctx.db.get(channels, channelId));
|
|
530
|
+
if (!channel)
|
|
531
|
+
fail("NOT_FOUND", "No such channel.");
|
|
532
|
+
await scope(ctx, channel.boardId, null, "admin");
|
|
533
|
+
const patch = Object.fromEntries(Object.entries(change).filter(([, v]) => v !== undefined));
|
|
534
|
+
if (typeof patch.name === "string") {
|
|
535
|
+
patch.name = patch.name.trim().toLowerCase().replace(/\s+/g, "-");
|
|
536
|
+
if ((await ctx.db.find(channels, { boardId: channel.boardId, name: patch.name })).some((c) => c.id !== channelId))
|
|
537
|
+
fail("FAILED_PRECONDITION", `The board already has a channel named ${patch.name}.`);
|
|
538
|
+
}
|
|
539
|
+
await ctx.db.patch(channels, channelId, patch);
|
|
540
|
+
await record(ctx, { boardId: channel.boardId, channelId, type: change.archived === true ? "channel.archived" : "channel.updated", actor: actorOf(ctx), data: patch });
|
|
541
|
+
return recId(channelId);
|
|
542
|
+
},
|
|
543
|
+
});
|
|
544
|
+
// ---- Threads ------------------------------------------------------------------------------------
|
|
545
|
+
const listThreads = app.query({
|
|
546
|
+
access: P.read,
|
|
547
|
+
args: { channelId: s.string(), status: s.optional(s.array(s.enum([...STATUSES]))), labels: s.optional(s.array(s.string())), kind: s.optional(s.enum([...THREAD_KINDS])), text: s.optional(s.string({ maxLength: 200 })), limit: s.optional(s.integer({ minimum: 1, maximum: 500 })) },
|
|
548
|
+
returns: s.array(ThreadOut),
|
|
549
|
+
capability: { name: "boards.threads.list", description: "Threads in a channel, newest activity first, with effective status (a lapsed claim reads as ready), claim, dependency and message counts. Filter by status, labels (any), kind or text." },
|
|
550
|
+
handler: async (ctx, { channelId, status, labels, kind, text, limit }) => {
|
|
551
|
+
const channel = (await ctx.db.get(channels, channelId));
|
|
552
|
+
if (!channel)
|
|
553
|
+
fail("NOT_FOUND", "No such channel.");
|
|
554
|
+
await scope(ctx, channel.boardId, channelId, "read");
|
|
555
|
+
const rows = text?.trim()
|
|
556
|
+
? (await ctx.db.search(threads, { text: text.trim(), where: { channelId }, limit: 100 }))
|
|
557
|
+
: (await ctx.db.find(threads, { channelId }, { orderBy: [{ field: "createdAt", direction: "desc" }] }));
|
|
558
|
+
const live = new Map((await ctx.db.find(claims, { channelId })).map((c) => [c.threadId, c]));
|
|
559
|
+
const msgs = (await ctx.db.find(messages, { channelId }));
|
|
560
|
+
const counts = new Map();
|
|
561
|
+
for (const m of msgs) {
|
|
562
|
+
if (m.deleted)
|
|
563
|
+
continue;
|
|
564
|
+
const c = counts.get(m.threadId) ?? { n: 0, last: 0 };
|
|
565
|
+
c.n += 1;
|
|
566
|
+
c.last = Math.max(c.last, m.createdAt);
|
|
567
|
+
counts.set(m.threadId, c);
|
|
568
|
+
}
|
|
569
|
+
const out = [];
|
|
570
|
+
for (const t of rows) {
|
|
571
|
+
if (kind && t.kind !== kind)
|
|
572
|
+
continue;
|
|
573
|
+
if (labels?.length && !labels.some((l) => t.labels.includes(l.toLowerCase())))
|
|
574
|
+
continue;
|
|
575
|
+
const v = await view(ctx, t, live.get(t.id) ?? null);
|
|
576
|
+
if (status?.length && !status.includes(v.status))
|
|
577
|
+
continue;
|
|
578
|
+
const c = counts.get(t.id);
|
|
579
|
+
out.push({ ...v, messageCount: c?.n ?? 0, lastActivityAt: Math.max(t.updatedAt, c?.last ?? 0) });
|
|
580
|
+
}
|
|
581
|
+
out.sort((a, b) => b.lastActivityAt - a.lastActivityAt);
|
|
582
|
+
return out.slice(0, limit ?? 200);
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
const getThread = app.query({
|
|
586
|
+
access: P.read,
|
|
587
|
+
args: { threadId: s.string() },
|
|
588
|
+
returns: open({ thread: ThreadOut, messages: s.array(open({ id: s.string(), text: s.string() })), events: s.array(open({ type: s.string() })) }),
|
|
589
|
+
capability: { name: "boards.threads.get", description: "A thread's complete record: the request, every message (structured data included), dependencies and dependents, the live claim and every earlier claim, links, follow-ups and the full event history." },
|
|
590
|
+
handler: async (ctx, { threadId }) => {
|
|
591
|
+
const { thread, level, board, channel } = await threadScope(ctx, threadId, "read");
|
|
592
|
+
const msgs = (await ctx.db.find(messages, { threadId }, { orderBy: [{ field: "seq", direction: "asc" }] }));
|
|
593
|
+
const reacts = (await ctx.db.find(reactions, { threadId }));
|
|
594
|
+
const r = thread.kind === "task" ? await readiness(ctx, threadId, thread) : { upstream: [] };
|
|
595
|
+
const dependents = [];
|
|
596
|
+
for (const e of (await ctx.db.find(deps, { dependsOn: threadId }))) {
|
|
597
|
+
const t = (await ctx.db.get(threads, e.taskId));
|
|
598
|
+
if (t)
|
|
599
|
+
dependents.push({ id: t.id, title: t.title, status: t.status });
|
|
600
|
+
}
|
|
601
|
+
const history = (await ctx.presence.history(claims, { threadId })).sort((a, b) => a.startedAt - b.startedAt);
|
|
602
|
+
return {
|
|
603
|
+
board: { id: board.id, name: board.name },
|
|
604
|
+
channel: channel ? { id: channel.id, name: channel.name } : null,
|
|
605
|
+
level,
|
|
606
|
+
thread: await view(ctx, thread),
|
|
607
|
+
messages: msgs.map((m) => ({
|
|
608
|
+
...m,
|
|
609
|
+
text: m.deleted ? "" : m.text,
|
|
610
|
+
...(m.deleted ? { structured: undefined } : {}),
|
|
611
|
+
reactions: Object.entries(reacts.filter((x) => x.messageId === m.id).reduce((acc, x) => ((acc[x.emoji] ??= []).push(x.actorId), acc), {})).map(([emoji, by]) => ({ emoji, by })),
|
|
612
|
+
})),
|
|
613
|
+
dependencies: r.upstream,
|
|
614
|
+
dependents,
|
|
615
|
+
claims: history.map((c) => ({ id: c.id, actor: c.actor, holder: c.holder, startedAt: c.startedAt, renewedAt: c.renewedAt, expiresAt: c.expiresAt ?? null, live: c.live, endedAt: c.endedAt ?? null, endReason: c.endReason ?? null, endedBy: c.endedBy ?? null, recoveredFrom: c.recoveredFrom ?? null, note: c.note ?? null })),
|
|
616
|
+
links: (await ctx.db.find(links, { threadId })),
|
|
617
|
+
followups: (await ctx.db.find(followups, { threadId })),
|
|
618
|
+
watchRuns: (await ctx.db.find(watchRuns, { threadId })),
|
|
619
|
+
events: (await ctx.db.find(events, { threadId }, { orderBy: [{ field: "seq", direction: "asc" }] })),
|
|
620
|
+
};
|
|
621
|
+
},
|
|
622
|
+
});
|
|
623
|
+
const createThread = app.mutation({
|
|
624
|
+
access: P.post,
|
|
625
|
+
args: {
|
|
626
|
+
channelId: s.string(),
|
|
627
|
+
kind: s.optional(s.enum([...THREAD_KINDS])),
|
|
628
|
+
title: s.string({ minLength: 1, maxLength: 200 }),
|
|
629
|
+
body: s.optional(s.string({ maxLength: 20_000 })),
|
|
630
|
+
labels: s.optional(s.array(s.string())),
|
|
631
|
+
metadata: s.optional(Json),
|
|
632
|
+
dependsOn: s.optional(s.array(s.string())),
|
|
633
|
+
},
|
|
634
|
+
returns: Ok,
|
|
635
|
+
retry: { sequenceConflicts: 3 },
|
|
636
|
+
capability: { name: "boards.threads.create", description: "Create a task (default) or a discussion in a channel. A task with unfinished dependencies starts blocked; otherwise ready." },
|
|
637
|
+
handler: async (ctx, { channelId, kind, title, body, labels, metadata, dependsOn }) => {
|
|
638
|
+
const channel = (await ctx.db.get(channels, channelId));
|
|
639
|
+
if (!channel)
|
|
640
|
+
fail("NOT_FOUND", "No such channel.");
|
|
641
|
+
const { level } = await scope(ctx, channel.boardId, channelId, "post");
|
|
642
|
+
const k = kind ?? "task";
|
|
643
|
+
if ((labels?.length || dependsOn?.length) && !canManage(ctx, level))
|
|
644
|
+
fail("FORBIDDEN", "Labels and dependencies need manage access.");
|
|
645
|
+
let clean = [];
|
|
646
|
+
try {
|
|
647
|
+
clean = normalizeLabels(labels ?? []);
|
|
648
|
+
}
|
|
649
|
+
catch (e) {
|
|
650
|
+
fail("INVALID_ARGUMENT", e.message);
|
|
651
|
+
}
|
|
652
|
+
if (k === "discussion" && dependsOn?.length)
|
|
653
|
+
fail("INVALID_ARGUMENT", "Only tasks have dependencies.");
|
|
654
|
+
const actor = actorOf(ctx);
|
|
655
|
+
const at = now();
|
|
656
|
+
let unmet = 0;
|
|
657
|
+
for (const d of dependsOn ?? []) {
|
|
658
|
+
const up = (await ctx.db.get(threads, d));
|
|
659
|
+
if (!up || up.boardId !== channel.boardId || up.kind !== "task")
|
|
660
|
+
fail("INVALID_ARGUMENT", `Dependency ${d} is not a task on this board.`);
|
|
661
|
+
if (up.status !== "completed")
|
|
662
|
+
unmet += 1;
|
|
663
|
+
}
|
|
664
|
+
const id = await ctx.db.insert(threads, {
|
|
665
|
+
boardId: channel.boardId,
|
|
666
|
+
channelId,
|
|
667
|
+
kind: k,
|
|
668
|
+
title: title.trim(),
|
|
669
|
+
...(body?.trim() ? { body: body.trim() } : {}),
|
|
670
|
+
status: k === "discussion" ? "open" : unmet ? "blocked" : "ready",
|
|
671
|
+
labels: clean,
|
|
672
|
+
metadata: metadata ?? {},
|
|
673
|
+
createdBy: actor,
|
|
674
|
+
createdAt: at,
|
|
675
|
+
updatedAt: at,
|
|
676
|
+
});
|
|
677
|
+
for (const d of [...new Set(dependsOn ?? [])])
|
|
678
|
+
await ctx.db.insert(deps, { boardId: channel.boardId, taskId: id, dependsOn: d, createdBy: actor, createdAt: at });
|
|
679
|
+
await record(ctx, { boardId: channel.boardId, channelId, threadId: id, type: "thread.created", actor, data: { kind: k, title: title.trim(), labels: clean, dependsOn: dependsOn ?? [] }, labels: clean });
|
|
680
|
+
return recId(id);
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
const updateThread = app.mutation({
|
|
684
|
+
access: P.post,
|
|
685
|
+
args: { threadId: s.string(), title: s.optional(s.string({ minLength: 1, maxLength: 200 })), body: s.optional(s.string({ maxLength: 20_000 })), metadata: s.optional(Json) },
|
|
686
|
+
returns: Ok,
|
|
687
|
+
retry: { sequenceConflicts: 3 },
|
|
688
|
+
capability: { name: "boards.threads.update", description: "Edit a thread's title, description or structured metadata (its author, or manage access)." },
|
|
689
|
+
handler: async (ctx, { threadId, ...change }) => {
|
|
690
|
+
const { thread, level } = await threadScope(ctx, threadId, "post");
|
|
691
|
+
const actor = actorOf(ctx);
|
|
692
|
+
if (thread.createdBy.id !== actor.id && !canManage(ctx, level))
|
|
693
|
+
fail("FORBIDDEN", "Only the thread's author or someone with manage access edits it.");
|
|
694
|
+
const patch = Object.fromEntries(Object.entries(change).filter(([, v]) => v !== undefined));
|
|
695
|
+
await ctx.db.patch(threads, threadId, { ...patch, updatedAt: now() });
|
|
696
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "thread.updated", actor, data: { fields: Object.keys(patch) }, labels: thread.labels });
|
|
697
|
+
return recId(threadId);
|
|
698
|
+
},
|
|
699
|
+
});
|
|
700
|
+
const transitionThread = app.mutation({
|
|
701
|
+
access: P.manage,
|
|
702
|
+
args: { threadId: s.string(), action: s.enum(["block", "unblock", "cancel", "reopen", "resolve"]), reason: s.optional(s.string({ maxLength: 1000 })) },
|
|
703
|
+
returns: s.object({ id: s.string(), from: s.string(), to: s.string() }),
|
|
704
|
+
retry: { sequenceConflicts: 3 },
|
|
705
|
+
capability: { name: "boards.threads.transition", description: "Block, unblock, cancel or reopen a task; resolve, cancel or reopen a discussion (manage access). Claimed work is completed or failed by its holder (boards.tasks.complete / fail)." },
|
|
706
|
+
handler: async (ctx, { threadId, action, reason }) => {
|
|
707
|
+
const { thread } = await threadScope(ctx, threadId, "manage");
|
|
708
|
+
const actor = actorOf(ctx);
|
|
709
|
+
if (action === "block" && !reason?.trim())
|
|
710
|
+
fail("INVALID_ARGUMENT", "Say why the task is blocked (reason).");
|
|
711
|
+
const extra = action === "block" ? { manualBlock: { reason: reason.trim(), by: actor, at: now() } } : action === "unblock" || action === "reopen" ? { manualBlock: undefined } : {};
|
|
712
|
+
const { from, to, live } = await transitionTask(ctx, thread, action, actor, extra);
|
|
713
|
+
if (live && (to === "cancelled"))
|
|
714
|
+
await ctx.presence.end(claims, live.id);
|
|
715
|
+
if (reason?.trim())
|
|
716
|
+
await postInternal(ctx, thread, actor, `${action}: ${reason.trim()}`, "system");
|
|
717
|
+
return { id: threadId, from, to };
|
|
718
|
+
},
|
|
719
|
+
});
|
|
720
|
+
const setLabels = app.mutation({
|
|
721
|
+
access: P.manage,
|
|
722
|
+
args: { threadId: s.string(), add: s.optional(s.array(s.string())), remove: s.optional(s.array(s.string())) },
|
|
723
|
+
returns: s.object({ id: s.string(), labels: s.array(s.string()) }),
|
|
724
|
+
retry: { sequenceConflicts: 3 },
|
|
725
|
+
capability: { name: "boards.threads.label", description: "Add and remove labels on a thread (manage access)." },
|
|
726
|
+
handler: async (ctx, { threadId, add, remove }) => {
|
|
727
|
+
const { thread } = await threadScope(ctx, threadId, "manage");
|
|
728
|
+
let next = [];
|
|
729
|
+
try {
|
|
730
|
+
const drop = new Set(normalizeLabels(remove ?? []));
|
|
731
|
+
next = normalizeLabels([...thread.labels.filter((l) => !drop.has(l)), ...(add ?? [])]);
|
|
732
|
+
}
|
|
733
|
+
catch (e) {
|
|
734
|
+
fail("INVALID_ARGUMENT", e.message);
|
|
735
|
+
}
|
|
736
|
+
if (next.join() !== thread.labels.join()) {
|
|
737
|
+
await ctx.db.patch(threads, threadId, { labels: next, updatedAt: now() });
|
|
738
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "labels.changed", actor: actorOf(ctx), data: { from: thread.labels, to: next }, labels: next });
|
|
739
|
+
}
|
|
740
|
+
return { id: threadId, labels: next };
|
|
741
|
+
},
|
|
742
|
+
});
|
|
743
|
+
const addLink = app.mutation({
|
|
744
|
+
access: P.post,
|
|
745
|
+
args: { threadId: s.string(), link: LinkInput },
|
|
746
|
+
returns: Ok,
|
|
747
|
+
retry: { sequenceConflicts: 3 },
|
|
748
|
+
capability: { name: "boards.links.add", description: "Link a thread to an external resource (a pull request, an issue, a Slack thread). With externalId, that object is linked to this thread only, so inbound updates find it." },
|
|
749
|
+
handler: async (ctx, { threadId, link }) => {
|
|
750
|
+
const { thread } = await threadScope(ctx, threadId, "post");
|
|
751
|
+
const key = link.externalId ? `${link.kind}:${link.externalId}` : undefined;
|
|
752
|
+
if (key && (await ctx.db.find(links, { key })).length)
|
|
753
|
+
fail("FAILED_PRECONDITION", `${key} is already linked to a thread.`);
|
|
754
|
+
const actor = actorOf(ctx);
|
|
755
|
+
const id = await ctx.db.insert(links, { threadId, boardId: thread.boardId, kind: link.kind, url: link.url, ...(link.title ? { title: link.title } : {}), ...(link.externalId ? { externalId: link.externalId } : {}), ...(key ? { key } : {}), createdBy: actor, createdAt: now() });
|
|
756
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "link.added", actor, data: { kind: link.kind, url: link.url, externalId: link.externalId ?? null } });
|
|
757
|
+
return recId(id);
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
const removeLink = app.mutation({
|
|
761
|
+
access: P.manage,
|
|
762
|
+
args: { linkId: s.string() },
|
|
763
|
+
returns: Ok,
|
|
764
|
+
retry: { sequenceConflicts: 3 },
|
|
765
|
+
capability: { name: "boards.links.remove", description: "Remove a thread's external link (manage access)." },
|
|
766
|
+
handler: async (ctx, { linkId }) => {
|
|
767
|
+
const link = (await ctx.db.get(links, linkId));
|
|
768
|
+
if (!link)
|
|
769
|
+
fail("NOT_FOUND", "No such link.");
|
|
770
|
+
const { thread } = await threadScope(ctx, link.threadId, "manage");
|
|
771
|
+
await ctx.db.delete(links, linkId);
|
|
772
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "link.removed", actor: actorOf(ctx), data: { kind: link.kind, url: link.url } });
|
|
773
|
+
return recId(linkId);
|
|
774
|
+
},
|
|
775
|
+
});
|
|
776
|
+
// ---- Messages -----------------------------------------------------------------------------------
|
|
777
|
+
const postMessage = app.mutation({
|
|
778
|
+
access: P.post,
|
|
779
|
+
args: { threadId: s.string(), text: s.string({ maxLength: 20_000 }), replyTo: s.optional(s.string()), structured: s.optional(s.object({ schema: s.string(), version: s.optional(s.integer({ minimum: 1 })), data: s.unknown() })) },
|
|
780
|
+
returns: s.object({ id: s.string(), seq: s.number() }),
|
|
781
|
+
retry: { sequenceConflicts: 5 },
|
|
782
|
+
capability: { name: "boards.messages.post", description: "Reply in a thread. Optionally attach structured data validated against a registered schema (boards.schemas.list); the text is kept as written." },
|
|
783
|
+
handler: async (ctx, { threadId, text, replyTo, structured }) => {
|
|
784
|
+
const { thread } = await threadScope(ctx, threadId, "post");
|
|
785
|
+
if (!text.trim() && !structured)
|
|
786
|
+
fail("INVALID_ARGUMENT", "A message needs text or structured data.");
|
|
787
|
+
if (replyTo) {
|
|
788
|
+
const parent = (await ctx.db.get(messages, replyTo));
|
|
789
|
+
if (!parent || parent.threadId !== threadId)
|
|
790
|
+
fail("INVALID_ARGUMENT", "replyTo must be a message in this thread.");
|
|
791
|
+
}
|
|
792
|
+
const actor = actorOf(ctx);
|
|
793
|
+
const checked = validateStructured(structured);
|
|
794
|
+
const out = await outbound(ctx, thread, "board.message.posted", { author: actor, text });
|
|
795
|
+
const m = await postInternal(ctx, thread, actor, text, "message", { ...(replyTo ? { replyTo } : {}), ...(checked ? { structured: checked } : {}), ...(out.length ? { outbound: out } : {}) });
|
|
796
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "message.posted", actor, data: { messageId: m.id, replyTo: replyTo ?? null, structured: checked ? `${checked.schema}@${checked.version}` : null }, labels: thread.labels });
|
|
797
|
+
return { id: m.id, seq: m.seq };
|
|
798
|
+
},
|
|
799
|
+
});
|
|
800
|
+
const editMessage = app.mutation({
|
|
801
|
+
access: P.post,
|
|
802
|
+
args: { messageId: s.string(), text: s.string({ minLength: 1, maxLength: 20_000 }) },
|
|
803
|
+
returns: Ok,
|
|
804
|
+
retry: { sequenceConflicts: 3 },
|
|
805
|
+
capability: { name: "boards.messages.edit", description: "Edit a message (its author, or manage access). The edit is recorded in the thread's history." },
|
|
806
|
+
handler: async (ctx, { messageId, text }) => {
|
|
807
|
+
const m = (await ctx.db.get(messages, messageId));
|
|
808
|
+
if (!m || m.deleted)
|
|
809
|
+
fail("NOT_FOUND", "No such message.");
|
|
810
|
+
const { thread, level } = await threadScope(ctx, m.threadId, "post");
|
|
811
|
+
const actor = actorOf(ctx);
|
|
812
|
+
if (m.author.id !== actor.id && !canManage(ctx, level))
|
|
813
|
+
fail("FORBIDDEN", "Only its author or someone with manage access edits a message.");
|
|
814
|
+
if (m.external)
|
|
815
|
+
fail("FAILED_PRECONDITION", `This message mirrors ${m.external.source}; edit it there.`);
|
|
816
|
+
const out = await outbound(ctx, thread, "board.message.edited", { messageId, author: actor, text });
|
|
817
|
+
await ctx.db.patch(messages, messageId, { text, editedAt: now(), ...(out.length ? { outbound: [...(m.outbound ?? []), ...out] } : {}) });
|
|
818
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "message.edited", actor, data: { messageId, previous: m.text } });
|
|
819
|
+
return recId(messageId);
|
|
820
|
+
},
|
|
821
|
+
});
|
|
822
|
+
const deleteMessage = app.mutation({
|
|
823
|
+
access: P.post,
|
|
824
|
+
args: { messageId: s.string() },
|
|
825
|
+
returns: Ok,
|
|
826
|
+
retry: { sequenceConflicts: 3 },
|
|
827
|
+
capability: { name: "boards.messages.delete", description: "Delete a message (its author, or manage access). The thread keeps a tombstone and the history keeps the event." },
|
|
828
|
+
handler: async (ctx, { messageId }) => {
|
|
829
|
+
const m = (await ctx.db.get(messages, messageId));
|
|
830
|
+
if (!m || m.deleted)
|
|
831
|
+
fail("NOT_FOUND", "No such message.");
|
|
832
|
+
const { thread, level } = await threadScope(ctx, m.threadId, "post");
|
|
833
|
+
const actor = actorOf(ctx);
|
|
834
|
+
if (m.author.id !== actor.id && !canManage(ctx, level))
|
|
835
|
+
fail("FORBIDDEN", "Only its author or someone with manage access deletes a message.");
|
|
836
|
+
const out = m.external ? [] : await outbound(ctx, thread, "board.message.deleted", { messageId, author: actor });
|
|
837
|
+
await ctx.db.patch(messages, messageId, { deleted: true, deletedBy: actor, editedAt: now(), ...(out.length ? { outbound: [...(m.outbound ?? []), ...out] } : {}) });
|
|
838
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "message.deleted", actor, data: { messageId } });
|
|
839
|
+
return recId(messageId);
|
|
840
|
+
},
|
|
841
|
+
});
|
|
842
|
+
const react = app.mutation({
|
|
843
|
+
access: P.post,
|
|
844
|
+
args: { messageId: s.string(), emoji: s.string({ minLength: 1, maxLength: 32 }), on: s.boolean() },
|
|
845
|
+
returns: s.object({ id: s.string(), on: s.boolean() }),
|
|
846
|
+
capability: { name: "boards.messages.react", description: "Add (on: true) or remove (on: false) your reaction to a message." },
|
|
847
|
+
handler: async (ctx, { messageId, emoji, on }) => {
|
|
848
|
+
const m = (await ctx.db.get(messages, messageId));
|
|
849
|
+
if (!m || m.deleted)
|
|
850
|
+
fail("NOT_FOUND", "No such message.");
|
|
851
|
+
await threadScope(ctx, m.threadId, "post");
|
|
852
|
+
const actorId = ctx.auth.requirePrincipal().id;
|
|
853
|
+
const [existing] = (await ctx.db.find(reactions, { messageId, emoji, actorId }));
|
|
854
|
+
if (on && !existing)
|
|
855
|
+
await ctx.db.insert(reactions, { messageId, threadId: m.threadId, emoji, actorId, at: now() });
|
|
856
|
+
if (!on && existing)
|
|
857
|
+
await ctx.db.delete(reactions, existing.id);
|
|
858
|
+
return { id: messageId, on };
|
|
859
|
+
},
|
|
860
|
+
});
|
|
861
|
+
// ---- Work: claims, progress, results ------------------------------------------------------------
|
|
862
|
+
const readyTasks = app.query({
|
|
863
|
+
access: P.read,
|
|
864
|
+
args: { boardId: s.optional(s.string()), channelId: s.optional(s.string()), labels: s.optional(s.array(s.string())), limit: s.optional(s.integer({ minimum: 1, maximum: 200 })) },
|
|
865
|
+
returns: s.array(ThreadOut),
|
|
866
|
+
capability: { name: "boards.tasks.ready", description: "Tasks you may claim now: ready, dependencies met, and no live claim (a task whose claim lapsed is included), across the boards and channels you can work in. Oldest first." },
|
|
867
|
+
handler: async (ctx, { boardId, channelId, labels, limit }) => {
|
|
868
|
+
const me = principalOf(ctx);
|
|
869
|
+
const bs = boardId ? [(await ctx.db.get(boards, boardId))].filter(Boolean) : (await ctx.db.find(boards, { archived: false }));
|
|
870
|
+
const out = [];
|
|
871
|
+
for (const b of bs) {
|
|
872
|
+
const g = await grantsFor(ctx, b.id);
|
|
873
|
+
const live = new Set((await ctx.db.find(claims, { boardId: b.id })).map((c) => c.threadId));
|
|
874
|
+
const allDeps = (await ctx.db.find(deps, { boardId: b.id }));
|
|
875
|
+
const all = (await ctx.db.find(threads, { boardId: b.id, kind: "task" }));
|
|
876
|
+
const byId = new Map(all.map((t) => [t.id, t]));
|
|
877
|
+
const chans = new Map((await ctx.db.find(channels, { boardId: b.id })).map((c) => [c.id, c]));
|
|
878
|
+
for (const t of all) {
|
|
879
|
+
if (channelId && t.channelId !== channelId)
|
|
880
|
+
continue;
|
|
881
|
+
const c = chans.get(t.channelId);
|
|
882
|
+
if (!c || c.archived)
|
|
883
|
+
continue;
|
|
884
|
+
if (!atLeast(explainAccess(b, c, g, me).level, "work"))
|
|
885
|
+
continue;
|
|
886
|
+
if (labels?.length && !labels.some((l) => t.labels.includes(l)))
|
|
887
|
+
continue;
|
|
888
|
+
const unmet = allDeps.filter((d) => d.taskId === t.id && byId.get(d.dependsOn)?.status !== "completed").length;
|
|
889
|
+
const eff = effectiveStatus(t.status, t.kind, live.has(t.id), { unmet, manualBlock: !!t.manualBlock });
|
|
890
|
+
if (eff.status === "ready")
|
|
891
|
+
out.push({ ...t, status: eff.status, storedStatus: t.status, leaseLapsed: eff.lapsed, boardName: b.name, channelName: c.name });
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
out.sort((a, b) => a.createdAt - b.createdAt);
|
|
895
|
+
return out.slice(0, limit ?? 50);
|
|
896
|
+
},
|
|
897
|
+
});
|
|
898
|
+
const claimTask = app.mutation({
|
|
899
|
+
access: P.work,
|
|
900
|
+
args: { threadId: s.string(), note: s.optional(s.string({ maxLength: 500 })) },
|
|
901
|
+
returns: s.object({ id: s.string(), claimId: s.string(), expiresAt: s.nullable(s.number()), recoveredFrom: s.nullable(s.string()) }),
|
|
902
|
+
retry: { sequenceConflicts: 3 },
|
|
903
|
+
capability: { name: "boards.tasks.claim", description: `Claim a ready task. The claim is a lease: renew it (boards.tasks.renew) within ${Math.round(ttlMs / 1000)} s or it lapses and the task is claimable again. Two claims for one task: one succeeds, the other is refused.` },
|
|
904
|
+
handler: async (ctx, { threadId, note }) => {
|
|
905
|
+
const { thread } = await threadScope(ctx, threadId, "work");
|
|
906
|
+
if (thread.kind !== "task")
|
|
907
|
+
fail("FAILED_PRECONDITION", "Only tasks are claimed.");
|
|
908
|
+
const live = await liveClaim(ctx, threadId);
|
|
909
|
+
if (live)
|
|
910
|
+
fail("FAILED_PRECONDITION", `The task is claimed by ${live.actor?.name ?? live.holder} until ${new Date(live.expiresAt ?? 0).toISOString()}.`);
|
|
911
|
+
const actor = actorOf(ctx);
|
|
912
|
+
// A task stored as claimed/in progress without a live claim lapsed: recover it, keeping the earlier claim in history.
|
|
913
|
+
const lapsed = WORKING.has(thread.status) ? (await ctx.presence.history(claims, { threadId })).sort((a, b) => b.startedAt - a.startedAt)[0] : undefined;
|
|
914
|
+
const { from } = await transitionTask(ctx, lapsed ? { ...thread, status: "ready" } : thread, "claim", actor);
|
|
915
|
+
const claim = await ctx.presence.join(claims, { threadId, boardId: thread.boardId, channelId: thread.channelId, actor, ...(note?.trim() ? { note: note.trim() } : {}), ...(lapsed ? { recoveredFrom: lapsed.id } : {}) }, { key: threadId });
|
|
916
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: lapsed ? "claim.recovered" : "task.claimed", actor, data: { claimId: claim.id, expiresAt: claim.expiresAt, from, ...(lapsed ? { previous: { claimId: lapsed.id, holder: lapsed.holder, endReason: lapsed.endReason ?? "expired", endedAt: lapsed.endedAt ?? null } } : {}) }, labels: thread.labels });
|
|
917
|
+
return { id: threadId, claimId: claim.id, expiresAt: claim.expiresAt, recoveredFrom: lapsed?.id ?? null };
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
/** The live claim the caller holds. `managerMay`: someone with manage (level and permission) may act on another's claim (release only). */
|
|
921
|
+
async function ownClaim(ctx, threadId, level, managerMay = false) {
|
|
922
|
+
const live = await liveClaim(ctx, threadId);
|
|
923
|
+
if (!live)
|
|
924
|
+
fail("FAILED_PRECONDITION", "The task has no live claim (it was released, completed, or its lease lapsed). Claim it again.");
|
|
925
|
+
const me = ctx.auth.requirePrincipal().id;
|
|
926
|
+
if (live.holder !== me && !(managerMay && canManage(ctx, level)))
|
|
927
|
+
fail("FORBIDDEN", `The task is claimed by ${live.actor?.name ?? live.holder}.`);
|
|
928
|
+
return live;
|
|
929
|
+
}
|
|
930
|
+
const renewClaim = app.mutation({
|
|
931
|
+
access: P.work,
|
|
932
|
+
args: { threadId: s.string() },
|
|
933
|
+
returns: s.object({ id: s.string(), expiresAt: s.nullable(s.number()) }),
|
|
934
|
+
capability: { name: "boards.tasks.renew", description: "Extend your claim on a task by its lease period." },
|
|
935
|
+
handler: async (ctx, { threadId }) => {
|
|
936
|
+
await threadScope(ctx, threadId, "work");
|
|
937
|
+
const live = await liveClaim(ctx, threadId);
|
|
938
|
+
if (!live)
|
|
939
|
+
fail("FAILED_PRECONDITION", "No live claim to renew (it lapsed or was released). Claim the task again.");
|
|
940
|
+
if (live.holder !== ctx.auth.requirePrincipal().id)
|
|
941
|
+
fail("FORBIDDEN", "Only the claim's holder renews it.");
|
|
942
|
+
const r = await ctx.presence.renew(claims, live.id);
|
|
943
|
+
return { id: threadId, expiresAt: r.expiresAt };
|
|
944
|
+
},
|
|
945
|
+
});
|
|
946
|
+
const releaseTask = app.mutation({
|
|
947
|
+
access: P.work,
|
|
948
|
+
args: { threadId: s.string(), note: s.optional(s.string({ maxLength: 1000 })) },
|
|
949
|
+
returns: s.object({ id: s.string(), to: s.string() }),
|
|
950
|
+
retry: { sequenceConflicts: 3 },
|
|
951
|
+
capability: { name: "boards.tasks.release", description: "Give up a claim (yours, or anyone's with manage access). The task returns to ready." },
|
|
952
|
+
handler: async (ctx, { threadId, note }) => {
|
|
953
|
+
const { thread, level } = await threadScope(ctx, threadId, "work");
|
|
954
|
+
const live = await ownClaim(ctx, threadId, level, true);
|
|
955
|
+
const actor = actorOf(ctx);
|
|
956
|
+
const { to } = await transitionTask(ctx, thread, "release", actor);
|
|
957
|
+
const ended = await ctx.presence.end(claims, live.id);
|
|
958
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "task.released", actor, data: { claimId: live.id, holder: live.holder, reason: ended.reason, note: note ?? null }, labels: thread.labels });
|
|
959
|
+
if (note?.trim())
|
|
960
|
+
await postInternal(ctx, thread, actor, note.trim(), "progress");
|
|
961
|
+
return { id: threadId, to };
|
|
962
|
+
},
|
|
963
|
+
});
|
|
964
|
+
const reportProgress = app.mutation({
|
|
965
|
+
access: P.work,
|
|
966
|
+
args: { threadId: s.string(), text: s.string({ minLength: 1, maxLength: 20_000 }), structured: s.optional(s.object({ schema: s.string(), version: s.optional(s.integer({ minimum: 1 })), data: s.unknown() })), renew: s.optional(s.boolean()) },
|
|
967
|
+
returns: s.object({ id: s.string(), messageId: s.string(), expiresAt: s.nullable(s.number()) }),
|
|
968
|
+
retry: { sequenceConflicts: 5 },
|
|
969
|
+
capability: { name: "boards.tasks.progress", description: "Post a progress update on a task you hold. The first update moves it to in progress; renew (default true) extends the claim." },
|
|
970
|
+
handler: async (ctx, { threadId, text, structured, renew }) => {
|
|
971
|
+
const { thread } = await threadScope(ctx, threadId, "work");
|
|
972
|
+
const live = await liveClaim(ctx, threadId);
|
|
973
|
+
if (!live || live.holder !== ctx.auth.requirePrincipal().id)
|
|
974
|
+
fail("FAILED_PRECONDITION", "Report progress on a task you hold a live claim on.");
|
|
975
|
+
const actor = actorOf(ctx);
|
|
976
|
+
if (thread.status === "claimed")
|
|
977
|
+
await transitionTask(ctx, thread, "start", actor);
|
|
978
|
+
const checked = validateStructured(structured);
|
|
979
|
+
const out = await outbound(ctx, thread, "board.message.posted", { author: actor, text, kind: "progress" });
|
|
980
|
+
const m = await postInternal(ctx, thread, actor, text, "progress", { ...(checked ? { structured: checked } : {}), ...(out.length ? { outbound: out } : {}) });
|
|
981
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "message.posted", actor, data: { messageId: m.id, kind: "progress" }, labels: thread.labels });
|
|
982
|
+
const r = renew === false ? { expiresAt: live.expiresAt ?? null } : await ctx.presence.renew(claims, live.id);
|
|
983
|
+
return { id: threadId, messageId: m.id, expiresAt: r.expiresAt };
|
|
984
|
+
},
|
|
985
|
+
});
|
|
986
|
+
const finish = (outcome) => app.mutation({
|
|
987
|
+
access: P.work,
|
|
988
|
+
args: { threadId: s.string(), summary: s.string({ minLength: 1, maxLength: 20_000 }), data: s.optional(Json), links: s.optional(s.array(LinkInput)), structured: s.optional(s.object({ schema: s.string(), version: s.optional(s.integer({ minimum: 1 })), data: s.unknown() })) },
|
|
989
|
+
returns: s.object({ id: s.string(), status: s.string(), unblocked: s.array(s.string()) }),
|
|
990
|
+
retry: { sequenceConflicts: 5 },
|
|
991
|
+
capability: outcome === "completed"
|
|
992
|
+
? { name: "boards.tasks.complete", description: "Complete a task you hold, with a result summary, optional structured data and links (e.g. the pull request). Tasks that depended only on it become ready." }
|
|
993
|
+
: { name: "boards.tasks.fail", description: "Record that a task you hold failed, with what happened. A manager can reopen it." },
|
|
994
|
+
handler: async (ctx, { threadId, summary, data, links: newLinks, structured }) => {
|
|
995
|
+
const { thread, level } = await threadScope(ctx, threadId, "work");
|
|
996
|
+
const live = await ownClaim(ctx, threadId, level);
|
|
997
|
+
const actor = actorOf(ctx);
|
|
998
|
+
const checked = validateStructured(structured);
|
|
999
|
+
const at = now();
|
|
1000
|
+
const before = new Map((await ctx.db.find(deps, { dependsOn: threadId })).map((d) => [d.taskId, true]));
|
|
1001
|
+
const { to } = await transitionTask(ctx, thread, outcome === "completed" ? "complete" : "fail", actor, { result: { summary, ...(data ? { data } : {}), by: actor, at, outcome } });
|
|
1002
|
+
await ctx.presence.end(claims, live.id);
|
|
1003
|
+
for (const l of newLinks ?? []) {
|
|
1004
|
+
const key = l.externalId ? `${l.kind}:${l.externalId}` : undefined;
|
|
1005
|
+
if (key && (await ctx.db.find(links, { key })).length)
|
|
1006
|
+
continue;
|
|
1007
|
+
await ctx.db.insert(links, { threadId, boardId: thread.boardId, kind: l.kind, url: l.url, ...(l.title ? { title: l.title } : {}), ...(l.externalId ? { externalId: l.externalId } : {}), ...(key ? { key } : {}), createdBy: actor, createdAt: at });
|
|
1008
|
+
}
|
|
1009
|
+
const out = await outbound(ctx, thread, `board.task.${outcome}`, { author: actor, summary });
|
|
1010
|
+
await postInternal(ctx, thread, actor, summary, "result", { ...(checked ? { structured: checked } : {}), ...(out.length ? { outbound: out } : {}) });
|
|
1011
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: outcome === "completed" ? "task.completed" : "task.failed", actor, data: { claimId: live.id, summary, links: (newLinks ?? []).map((l) => l.url) }, labels: thread.labels });
|
|
1012
|
+
const unblocked = [];
|
|
1013
|
+
for (const id of before.keys())
|
|
1014
|
+
if ((await ctx.db.get(threads, id))?.status === "ready")
|
|
1015
|
+
unblocked.push(id);
|
|
1016
|
+
return { id: threadId, status: to, unblocked };
|
|
1017
|
+
},
|
|
1018
|
+
});
|
|
1019
|
+
const completeTask = finish("completed");
|
|
1020
|
+
const failTask = finish("failed");
|
|
1021
|
+
// ---- Dependencies -------------------------------------------------------------------------------
|
|
1022
|
+
const addDependency = app.mutation({
|
|
1023
|
+
access: P.manage,
|
|
1024
|
+
args: { taskId: s.string(), dependsOn: s.string() },
|
|
1025
|
+
returns: s.object({ id: s.string(), status: s.string() }),
|
|
1026
|
+
retry: { sequenceConflicts: 3 },
|
|
1027
|
+
capability: { name: "boards.dependencies.add", description: "Make a task depend on another task on the same board. Refused if it would make a cycle, or if the task is being worked." },
|
|
1028
|
+
handler: async (ctx, { taskId, dependsOn }) => {
|
|
1029
|
+
const { thread } = await threadScope(ctx, taskId, "manage");
|
|
1030
|
+
const up = (await ctx.db.get(threads, dependsOn));
|
|
1031
|
+
if (!up || up.boardId !== thread.boardId || up.kind !== "task" || thread.kind !== "task")
|
|
1032
|
+
fail("INVALID_ARGUMENT", "Both must be tasks on the same board.");
|
|
1033
|
+
if ((await ctx.db.find(deps, { taskId, dependsOn })).length)
|
|
1034
|
+
fail("FAILED_PRECONDITION", "That dependency exists.");
|
|
1035
|
+
if (WORKING.has(thread.status) && (await liveClaim(ctx, taskId)) && up.status !== "completed")
|
|
1036
|
+
fail("FAILED_PRECONDITION", "The task is being worked; release it before adding an unfinished dependency.");
|
|
1037
|
+
if (TERMINAL.has(thread.status))
|
|
1038
|
+
fail("FAILED_PRECONDITION", `The task is ${thread.status}.`);
|
|
1039
|
+
// Every edge on the board is read, so a concurrent edge that would close a cycle makes one of the two CONFLICT.
|
|
1040
|
+
const edges = new Map();
|
|
1041
|
+
for (const d of (await ctx.db.find(deps, { boardId: thread.boardId })))
|
|
1042
|
+
edges.set(d.taskId, [...(edges.get(d.taskId) ?? []), d.dependsOn]);
|
|
1043
|
+
const cycle = wouldCycle(edges, taskId, dependsOn);
|
|
1044
|
+
if (cycle)
|
|
1045
|
+
fail("FAILED_PRECONDITION", `That would make a cycle: ${cycle.join(" → ")}.`);
|
|
1046
|
+
const actor = actorOf(ctx);
|
|
1047
|
+
const id = await ctx.db.insert(deps, { boardId: thread.boardId, taskId, dependsOn, createdBy: actor, createdAt: now() });
|
|
1048
|
+
const r = await readiness(ctx, taskId, thread);
|
|
1049
|
+
// readiness() read the new edge through the writer; recompute status for an unclaimed task.
|
|
1050
|
+
const next = settledReadiness(thread.status, r);
|
|
1051
|
+
if (next !== thread.status)
|
|
1052
|
+
await ctx.db.patch(threads, taskId, { status: next, updatedAt: now() });
|
|
1053
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: taskId, type: "dependency.added", actor, data: { dependsOn, title: up.title, status: next }, labels: thread.labels });
|
|
1054
|
+
return { id, status: next };
|
|
1055
|
+
},
|
|
1056
|
+
});
|
|
1057
|
+
const removeDependency = app.mutation({
|
|
1058
|
+
access: P.manage,
|
|
1059
|
+
args: { taskId: s.string(), dependsOn: s.string() },
|
|
1060
|
+
returns: s.object({ id: s.string(), status: s.string() }),
|
|
1061
|
+
retry: { sequenceConflicts: 3 },
|
|
1062
|
+
capability: { name: "boards.dependencies.remove", description: "Remove a dependency. A task left with none unfinished becomes ready." },
|
|
1063
|
+
handler: async (ctx, { taskId, dependsOn }) => {
|
|
1064
|
+
const { thread } = await threadScope(ctx, taskId, "manage");
|
|
1065
|
+
const [edge] = (await ctx.db.find(deps, { taskId, dependsOn }));
|
|
1066
|
+
if (!edge)
|
|
1067
|
+
fail("NOT_FOUND", "No such dependency.");
|
|
1068
|
+
await ctx.db.delete(deps, edge.id);
|
|
1069
|
+
const r = await readiness(ctx, taskId, thread);
|
|
1070
|
+
const next = settledReadiness(thread.status, r);
|
|
1071
|
+
const actor = actorOf(ctx);
|
|
1072
|
+
if (next !== thread.status)
|
|
1073
|
+
await ctx.db.patch(threads, taskId, { status: next, updatedAt: now() });
|
|
1074
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: taskId, type: next === "ready" && thread.status !== "ready" ? "task.ready" : "dependency.removed", actor, data: { dependsOn, status: next }, labels: thread.labels });
|
|
1075
|
+
return { id: edge.id, status: next };
|
|
1076
|
+
},
|
|
1077
|
+
});
|
|
1078
|
+
// ---- Grants -------------------------------------------------------------------------------------
|
|
1079
|
+
const listGrants = app.query({
|
|
1080
|
+
access: P.read,
|
|
1081
|
+
args: { boardId: s.string(), includeRevoked: s.optional(s.boolean()) },
|
|
1082
|
+
returns: s.array(open({ id: s.string(), principal: s.string(), level: s.string() })),
|
|
1083
|
+
capability: { name: "boards.grants.list", description: "The grants on a board and its channels (board admins see all; others see their own)." },
|
|
1084
|
+
handler: async (ctx, { boardId, includeRevoked }) => {
|
|
1085
|
+
const { level } = await scope(ctx, boardId, null, "read");
|
|
1086
|
+
const me = principalOf(ctx);
|
|
1087
|
+
return (await grantsFor(ctx, boardId))
|
|
1088
|
+
.filter((g) => includeRevoked || !g.revoked)
|
|
1089
|
+
.filter((g) => level === "admin" || g.principal === me.id || (g.principal.startsWith("role:") && me.roles.includes(g.principal.slice(5))))
|
|
1090
|
+
.sort((a, b) => a.grantedAt - b.grantedAt);
|
|
1091
|
+
},
|
|
1092
|
+
});
|
|
1093
|
+
const explain = app.query({
|
|
1094
|
+
access: P.read,
|
|
1095
|
+
args: { boardId: s.string(), channelId: s.optional(s.string()), principal: s.optional(s.string()), roles: s.optional(s.array(s.string())) },
|
|
1096
|
+
returns: s.object({ principal: s.string(), level: s.string(), reasons: s.array(s.string()) }),
|
|
1097
|
+
capability: { name: "boards.grants.explain", description: "What level a principal holds on a board or channel, and why. Your own access, or anyone's for board admins." },
|
|
1098
|
+
handler: async (ctx, { boardId, channelId, principal, roles }) => {
|
|
1099
|
+
const { board, level } = await scope(ctx, boardId, null, "read");
|
|
1100
|
+
const me = principalOf(ctx);
|
|
1101
|
+
const subject = principal && principal !== me.id ? { id: principal, roles: roles ?? [] } : me;
|
|
1102
|
+
if (subject !== me && level !== "admin")
|
|
1103
|
+
fail("FORBIDDEN", "Only board admins explain someone else's access.");
|
|
1104
|
+
let channel = null;
|
|
1105
|
+
if (channelId) {
|
|
1106
|
+
channel = (await ctx.db.get(channels, channelId));
|
|
1107
|
+
if (!channel || channel.boardId !== boardId)
|
|
1108
|
+
fail("NOT_FOUND", "No such channel.");
|
|
1109
|
+
}
|
|
1110
|
+
const e = explainAccess(board, channel, (await grantsFor(ctx, boardId)), subject);
|
|
1111
|
+
return { principal: subject.id, level: e.level, reasons: e.reasons };
|
|
1112
|
+
},
|
|
1113
|
+
});
|
|
1114
|
+
const grant = app.mutation({
|
|
1115
|
+
access: P.admin,
|
|
1116
|
+
args: { boardId: s.string(), channelId: s.optional(s.string()), principal: s.string({ minLength: 1, maxLength: 200 }), level: s.enum([...GRANT_LEVELS]) },
|
|
1117
|
+
returns: Ok,
|
|
1118
|
+
retry: { sequenceConflicts: 3 },
|
|
1119
|
+
capability: { name: "boards.grants.grant", description: "Grant a person, agent, application principal, or every holder of a role (\"role:<name>\") a level on a board or one channel (board admins). Replaces that principal's earlier grant on the same scope." },
|
|
1120
|
+
handler: async (ctx, { boardId, channelId, principal, level }) => {
|
|
1121
|
+
await scope(ctx, boardId, null, "admin");
|
|
1122
|
+
if (channelId) {
|
|
1123
|
+
const c = (await ctx.db.get(channels, channelId));
|
|
1124
|
+
if (!c || c.boardId !== boardId)
|
|
1125
|
+
fail("NOT_FOUND", "No such channel.");
|
|
1126
|
+
}
|
|
1127
|
+
const actor = actorOf(ctx);
|
|
1128
|
+
const at = now();
|
|
1129
|
+
for (const g of (await grantsFor(ctx, boardId))) {
|
|
1130
|
+
if (!g.revoked && g.principal === principal && (g.channelId ?? "") === (channelId ?? ""))
|
|
1131
|
+
await ctx.db.patch(grants, g.id, { revoked: true, revokedBy: actor, revokedAt: at });
|
|
1132
|
+
}
|
|
1133
|
+
const id = await ctx.db.insert(grants, { boardId, ...(channelId ? { channelId } : {}), principal, level: level, grantedBy: actor, grantedAt: at, revoked: false });
|
|
1134
|
+
await record(ctx, { boardId, ...(channelId ? { channelId } : {}), type: "grant.created", actor, data: { grantId: id, principal, level, channelId: channelId ?? null } });
|
|
1135
|
+
return recId(id);
|
|
1136
|
+
},
|
|
1137
|
+
});
|
|
1138
|
+
const revokeGrant = app.mutation({
|
|
1139
|
+
access: P.admin,
|
|
1140
|
+
args: { grantId: s.string() },
|
|
1141
|
+
returns: Ok,
|
|
1142
|
+
retry: { sequenceConflicts: 3 },
|
|
1143
|
+
capability: { name: "boards.grants.revoke", description: "Revoke a grant (board admins). The next call that relied on it is refused." },
|
|
1144
|
+
handler: async (ctx, { grantId }) => {
|
|
1145
|
+
const g = (await ctx.db.get(grants, grantId));
|
|
1146
|
+
if (!g)
|
|
1147
|
+
fail("NOT_FOUND", "No such grant.");
|
|
1148
|
+
await scope(ctx, g.boardId, null, "admin");
|
|
1149
|
+
if (g.revoked)
|
|
1150
|
+
return recId(grantId);
|
|
1151
|
+
const actor = actorOf(ctx);
|
|
1152
|
+
const admins = (await grantsFor(ctx, g.boardId)).filter((x) => !x.revoked && !x.channelId && x.level === "admin");
|
|
1153
|
+
if (g.level === "admin" && !g.channelId && admins.length <= 1)
|
|
1154
|
+
fail("FAILED_PRECONDITION", "A board keeps at least one admin grant.");
|
|
1155
|
+
await ctx.db.patch(grants, grantId, { revoked: true, revokedBy: actor, revokedAt: now() });
|
|
1156
|
+
await record(ctx, { boardId: g.boardId, ...(g.channelId ? { channelId: g.channelId } : {}), type: "grant.revoked", actor, data: { grantId, principal: g.principal, level: g.level } });
|
|
1157
|
+
return recId(grantId);
|
|
1158
|
+
},
|
|
1159
|
+
});
|
|
1160
|
+
// ---- History ------------------------------------------------------------------------------------
|
|
1161
|
+
const activity = app.query({
|
|
1162
|
+
access: P.read,
|
|
1163
|
+
args: { boardId: s.string(), channelId: s.optional(s.string()), types: s.optional(s.array(s.string())), limit: s.optional(s.integer({ minimum: 1, maximum: 500 })) },
|
|
1164
|
+
returns: s.array(open({ id: s.string(), type: s.string(), at: s.number() })),
|
|
1165
|
+
capability: { name: "boards.activity", description: "A board's history, newest first: who did what (claims, releases, status changes, messages, grants), with the actor and any principal it acted for." },
|
|
1166
|
+
handler: async (ctx, { boardId, channelId, types, limit }) => {
|
|
1167
|
+
const { board } = await scope(ctx, boardId, channelId ?? null, "read");
|
|
1168
|
+
const me = principalOf(ctx);
|
|
1169
|
+
const g = await grantsFor(ctx, boardId);
|
|
1170
|
+
const readable = new Map();
|
|
1171
|
+
for (const c of (await ctx.db.find(channels, { boardId })))
|
|
1172
|
+
readable.set(c.id, explainAccess(board, c, g, me).level !== "none");
|
|
1173
|
+
const titles = new Map((await ctx.db.find(threads, { boardId })).map((t) => [t.id, t.title]));
|
|
1174
|
+
return (await ctx.db.find(events, { boardId }))
|
|
1175
|
+
.filter((e) => (!channelId || e.channelId === channelId) && (!e.channelId || readable.get(e.channelId)) && (!types?.length || types.includes(e.type)))
|
|
1176
|
+
.sort((a, b) => b.at - a.at || b.seq - a.seq)
|
|
1177
|
+
.slice(0, limit ?? 100)
|
|
1178
|
+
.map((e) => ({ ...e, threadTitle: e.threadId ? titles.get(e.threadId) ?? null : null }));
|
|
1179
|
+
},
|
|
1180
|
+
});
|
|
1181
|
+
// ---- Structured messages ------------------------------------------------------------------------
|
|
1182
|
+
const listSchemas = app.query({
|
|
1183
|
+
access: P.read,
|
|
1184
|
+
returns: s.array(s.object({ name: s.string(), version: s.number(), description: s.optional(s.string()), jsonSchema: s.unknown() })),
|
|
1185
|
+
capability: { name: "boards.schemas.list", description: "The structured message schemas this application accepts, every version, as JSON Schema." },
|
|
1186
|
+
handler: async () => Object.entries(schemas).flatMap(([name, versions]) => versions.map((v) => ({ name, version: v.version, ...(v.description ? { description: v.description } : {}), jsonSchema: v.schema.toJSONSchema() }))),
|
|
1187
|
+
});
|
|
1188
|
+
// ---- Watchers -----------------------------------------------------------------------------------
|
|
1189
|
+
const listWatchers = app.query({
|
|
1190
|
+
access: P.read,
|
|
1191
|
+
args: { boardId: s.string() },
|
|
1192
|
+
returns: s.array(open({ id: s.string(), agent: s.string() })),
|
|
1193
|
+
capability: { name: "boards.watchers.list", description: "A board's watchers: which events run which application agent." },
|
|
1194
|
+
handler: async (ctx, { boardId }) => {
|
|
1195
|
+
await scope(ctx, boardId, null, "read");
|
|
1196
|
+
return (await ctx.db.find(watchers, { boardId }));
|
|
1197
|
+
},
|
|
1198
|
+
});
|
|
1199
|
+
const createWatcher = app.mutation({
|
|
1200
|
+
access: P.admin,
|
|
1201
|
+
args: { boardId: s.string(), channelId: s.optional(s.string()), on: s.array(s.enum([...WATCH_EVENTS]), { minItems: 1 }), labels: s.optional(s.array(s.string())), agent: s.string() },
|
|
1202
|
+
returns: Ok,
|
|
1203
|
+
retry: { sequenceConflicts: 3 },
|
|
1204
|
+
capability: { name: "boards.watchers.create", description: "Run an application agent (app.agent) after matching board events commit — new thread, reply, label or status change, completion, failure, a task becoming ready, a follow-up falling due — optionally only in one channel or for some labels (board admins). The agent runs as itself; a watcher grants it nothing." },
|
|
1205
|
+
handler: async (ctx, { boardId, channelId, on, labels, agent }) => {
|
|
1206
|
+
await scope(ctx, boardId, channelId ?? null, "admin");
|
|
1207
|
+
if (!app.agents.has(agent))
|
|
1208
|
+
fail("INVALID_ARGUMENT", `No application agent "${agent}". Declare it with app.agent.`);
|
|
1209
|
+
const actor = actorOf(ctx);
|
|
1210
|
+
let clean = [];
|
|
1211
|
+
try {
|
|
1212
|
+
clean = normalizeLabels(labels ?? []);
|
|
1213
|
+
}
|
|
1214
|
+
catch (e) {
|
|
1215
|
+
fail("INVALID_ARGUMENT", e.message);
|
|
1216
|
+
}
|
|
1217
|
+
const id = await ctx.db.insert(watchers, { boardId, ...(channelId ? { channelId } : {}), on: [...new Set(on)], labels: clean, agent, active: true, createdBy: actor, createdAt: now() });
|
|
1218
|
+
await record(ctx, { boardId, ...(channelId ? { channelId } : {}), type: "watcher.created", actor, data: { watcherId: id, on, agent, labels: clean } });
|
|
1219
|
+
return recId(id);
|
|
1220
|
+
},
|
|
1221
|
+
});
|
|
1222
|
+
const deleteWatcher = app.mutation({
|
|
1223
|
+
access: P.admin,
|
|
1224
|
+
args: { watcherId: s.string() },
|
|
1225
|
+
returns: Ok,
|
|
1226
|
+
retry: { sequenceConflicts: 3 },
|
|
1227
|
+
capability: { name: "boards.watchers.delete", description: "Stop a watcher (board admins). Runs already recorded keep their history." },
|
|
1228
|
+
handler: async (ctx, { watcherId }) => {
|
|
1229
|
+
const w = (await ctx.db.get(watchers, watcherId));
|
|
1230
|
+
if (!w)
|
|
1231
|
+
fail("NOT_FOUND", "No such watcher.");
|
|
1232
|
+
await scope(ctx, w.boardId, null, "admin");
|
|
1233
|
+
await ctx.db.patch(watchers, watcherId, { active: false });
|
|
1234
|
+
await record(ctx, { boardId: w.boardId, type: "watcher.stopped", actor: actorOf(ctx), data: { watcherId } });
|
|
1235
|
+
return recId(watcherId);
|
|
1236
|
+
},
|
|
1237
|
+
});
|
|
1238
|
+
// ---- Follow-ups ---------------------------------------------------------------------------------
|
|
1239
|
+
const when = (at) => {
|
|
1240
|
+
const ms = typeof at === "number" ? at : Date.parse(at);
|
|
1241
|
+
if (!Number.isFinite(ms))
|
|
1242
|
+
fail("INVALID_ARGUMENT", "at must be a time (ISO 8601 or epoch ms).");
|
|
1243
|
+
return ms;
|
|
1244
|
+
};
|
|
1245
|
+
const scheduleFollowup = app.mutation({
|
|
1246
|
+
access: P.post,
|
|
1247
|
+
args: { threadId: s.string(), at: s.union([s.string(), s.number()]), note: s.string({ minLength: 1, maxLength: 1000 }) },
|
|
1248
|
+
returns: s.object({ id: s.string(), dueAt: s.number(), outboxId: s.string() }),
|
|
1249
|
+
retry: { sequenceConflicts: 3 },
|
|
1250
|
+
capability: { name: "boards.followups.schedule", description: "Schedule a follow-up on a thread (check CI, revisit a blocked task). When it falls due, a system message is posted and `followup.due` watchers run. Durable: it survives restarts and runs once." },
|
|
1251
|
+
handler: async (ctx, { threadId, at, note }) => {
|
|
1252
|
+
const { thread } = await threadScope(ctx, threadId, "post");
|
|
1253
|
+
const dueAt = when(at);
|
|
1254
|
+
const token = await ctx.crypto.token(16);
|
|
1255
|
+
const actor = actorOf(ctx);
|
|
1256
|
+
const id = await ctx.db.insert(followups, { boardId: thread.boardId, threadId, dueAt, note: note.trim(), state: "scheduled", token, createdBy: actor, createdAt: now(), runs: [], jobs: [] });
|
|
1257
|
+
const { outboxId } = ctx.afterCommit.jobs.enqueue(followupJob, { followupId: id, token }, { runAt: new Date(dueAt).toISOString() });
|
|
1258
|
+
await ctx.db.patch(followups, id, { jobs: [{ outboxId, token, runAt: dueAt }] });
|
|
1259
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId, type: "followup.scheduled", actor, data: { followupId: id, dueAt, note: note.trim() } });
|
|
1260
|
+
return { id, dueAt, outboxId };
|
|
1261
|
+
},
|
|
1262
|
+
});
|
|
1263
|
+
const changeFollowup = app.mutation({
|
|
1264
|
+
access: P.post,
|
|
1265
|
+
args: { followupId: s.string(), action: s.enum(["cancel", "reschedule"]), at: s.optional(s.union([s.string(), s.number()])) },
|
|
1266
|
+
returns: s.object({ id: s.string(), state: s.string(), dueAt: s.number() }),
|
|
1267
|
+
retry: { sequenceConflicts: 3 },
|
|
1268
|
+
capability: { name: "boards.followups.change", description: "Cancel or reschedule a follow-up that has not fired (its creator, or manage access). A cancelled or superseded job does nothing when it runs." },
|
|
1269
|
+
handler: async (ctx, { followupId, action, at }) => {
|
|
1270
|
+
const f = (await ctx.db.get(followups, followupId));
|
|
1271
|
+
if (!f)
|
|
1272
|
+
fail("NOT_FOUND", "No such follow-up.");
|
|
1273
|
+
const { thread, level } = await threadScope(ctx, f.threadId, "post");
|
|
1274
|
+
const actor = actorOf(ctx);
|
|
1275
|
+
if (f.createdBy.id !== actor.id && !canManage(ctx, level))
|
|
1276
|
+
fail("FORBIDDEN", "Only its creator or someone with manage access changes a follow-up.");
|
|
1277
|
+
if (f.state !== "scheduled")
|
|
1278
|
+
fail("FAILED_PRECONDITION", `The follow-up has ${f.state === "fired" ? "fired" : "been cancelled"}.`);
|
|
1279
|
+
if (action === "cancel") {
|
|
1280
|
+
await ctx.db.patch(followups, followupId, { state: "cancelled", token: await ctx.crypto.token(16) });
|
|
1281
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "followup.cancelled", actor, data: { followupId } });
|
|
1282
|
+
return { id: followupId, state: "cancelled", dueAt: f.dueAt };
|
|
1283
|
+
}
|
|
1284
|
+
if (at === undefined)
|
|
1285
|
+
fail("INVALID_ARGUMENT", "Rescheduling needs at.");
|
|
1286
|
+
const dueAt = when(at);
|
|
1287
|
+
const token = await ctx.crypto.token(16);
|
|
1288
|
+
const { outboxId } = ctx.afterCommit.jobs.enqueue(followupJob, { followupId, token }, { runAt: new Date(dueAt).toISOString() });
|
|
1289
|
+
await ctx.db.patch(followups, followupId, { dueAt, token, jobs: [...f.jobs, { outboxId, token, runAt: dueAt }] });
|
|
1290
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "followup.rescheduled", actor, data: { followupId, from: f.dueAt, to: dueAt } });
|
|
1291
|
+
return { id: followupId, state: "scheduled", dueAt };
|
|
1292
|
+
},
|
|
1293
|
+
});
|
|
1294
|
+
/** The job handler (`services.jobs.handlers[followupJob]`): runs as the scheduler, once per token. */
|
|
1295
|
+
const runFollowup = app.mutation({
|
|
1296
|
+
access: P.post,
|
|
1297
|
+
visibility: "internal",
|
|
1298
|
+
args: { followupId: s.string(), token: s.string() },
|
|
1299
|
+
returns: s.object({ outcome: s.enum(["fired", "skipped"]), reason: s.optional(s.string()) }),
|
|
1300
|
+
retry: { sequenceConflicts: 5 },
|
|
1301
|
+
handler: async (ctx, { followupId, token }) => {
|
|
1302
|
+
const f = (await ctx.db.get(followups, followupId));
|
|
1303
|
+
if (!f)
|
|
1304
|
+
return { outcome: "skipped", reason: "not found" };
|
|
1305
|
+
const at = now();
|
|
1306
|
+
if (f.state !== "scheduled" || f.token !== token) {
|
|
1307
|
+
const reason = f.state === "cancelled" ? "cancelled" : f.state === "fired" ? "already fired" : "rescheduled";
|
|
1308
|
+
await ctx.db.patch(followups, f.id, { runs: [...f.runs, { at, token, outcome: "skipped", reason }] });
|
|
1309
|
+
return { outcome: "skipped", reason };
|
|
1310
|
+
}
|
|
1311
|
+
const thread = (await ctx.db.get(threads, f.threadId));
|
|
1312
|
+
await postInternal(ctx, thread, { ...SYSTEM }, `Follow-up due: ${f.note}`, "system");
|
|
1313
|
+
await ctx.db.patch(followups, f.id, { state: "fired", runs: [...f.runs, { at, token, outcome: "fired" }] });
|
|
1314
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "followup.due", actor: { ...SYSTEM, onBehalfOf: { id: f.createdBy.id, via: "delegation" } }, data: { followupId: f.id, note: f.note, scheduledBy: f.createdBy }, labels: thread.labels });
|
|
1315
|
+
return { outcome: "fired" };
|
|
1316
|
+
},
|
|
1317
|
+
});
|
|
1318
|
+
// ---- Integrations (inbound) ---------------------------------------------------------------------
|
|
1319
|
+
const importMessage = app.mutation({
|
|
1320
|
+
access: P.integrate,
|
|
1321
|
+
args: {
|
|
1322
|
+
source: s.string({ minLength: 1, maxLength: 40 }),
|
|
1323
|
+
externalId: s.string({ minLength: 1, maxLength: 200 }),
|
|
1324
|
+
/** The thread, or the external object linked to one (boards.links.add with externalId). */
|
|
1325
|
+
threadId: s.optional(s.string()),
|
|
1326
|
+
link: s.optional(s.object({ kind: s.string(), externalId: s.string() })),
|
|
1327
|
+
author: s.object({ id: s.string(), name: s.optional(s.string()) }),
|
|
1328
|
+
text: s.string({ maxLength: 20_000 }),
|
|
1329
|
+
updatedAt: s.number(),
|
|
1330
|
+
deleted: s.optional(s.boolean()),
|
|
1331
|
+
url: s.optional(s.string()),
|
|
1332
|
+
},
|
|
1333
|
+
returns: s.object({ id: s.nullable(s.string()), outcome: s.enum(["created", "updated", "deleted", "duplicate", "stale"]) }),
|
|
1334
|
+
retry: { sequenceConflicts: 5 },
|
|
1335
|
+
capability: { name: "boards.messages.import", description: "Mirror a message from an external system (GitHub, Slack) into its thread. Idempotent per (source, externalId): a repeat delivery is a duplicate, an older version than the stored one is stale, a newer one updates or deletes the mirror. The board stays the record; the mirror keeps its provenance." },
|
|
1336
|
+
handler: async (ctx, { source, externalId, threadId, link, author, text, updatedAt, deleted, url }) => {
|
|
1337
|
+
let tid = threadId;
|
|
1338
|
+
if (!tid && link)
|
|
1339
|
+
tid = ((await ctx.db.find(links, { key: `${link.kind}:${link.externalId}` }))[0]?.threadId);
|
|
1340
|
+
if (!tid)
|
|
1341
|
+
fail("NOT_FOUND", "No thread for this message (pass threadId, or a link registered with boards.links.add).");
|
|
1342
|
+
const { thread } = await threadScope(ctx, tid, "post");
|
|
1343
|
+
const externalKey = `${source}:${externalId}`;
|
|
1344
|
+
const [existing] = (await ctx.db.find(messages, { externalKey }));
|
|
1345
|
+
const actor = { ...actorOf(ctx), name: author.name ?? author.id };
|
|
1346
|
+
if (existing) {
|
|
1347
|
+
if (existing.threadId !== tid)
|
|
1348
|
+
fail("FAILED_PRECONDITION", `${externalKey} is already mirrored in another thread.`);
|
|
1349
|
+
if (updatedAt === existing.external.updatedAt)
|
|
1350
|
+
return { id: existing.id, outcome: "duplicate" };
|
|
1351
|
+
if (updatedAt < existing.external.updatedAt)
|
|
1352
|
+
return { id: existing.id, outcome: "stale" };
|
|
1353
|
+
await ctx.db.patch(messages, existing.id, { text: deleted ? existing.text : text, deleted: !!deleted, editedAt: now(), external: { ...existing.external, updatedAt } });
|
|
1354
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: deleted ? "message.deleted" : "message.edited", actor, data: { messageId: existing.id, source, externalId } });
|
|
1355
|
+
return { id: existing.id, outcome: deleted ? "deleted" : "updated" };
|
|
1356
|
+
}
|
|
1357
|
+
if (deleted)
|
|
1358
|
+
return { id: null, outcome: "stale" };
|
|
1359
|
+
const m = await postInternal(ctx, thread, actor, text, "message", { external: { source, id: externalId, updatedAt, ...(url ? { url } : {}), author: author.name ?? author.id }, externalKey });
|
|
1360
|
+
await record(ctx, { boardId: thread.boardId, channelId: thread.channelId, threadId: thread.id, type: "message.posted", actor, data: { messageId: m.id, source, externalId }, labels: thread.labels });
|
|
1361
|
+
return { id: m.id, outcome: "created" };
|
|
1362
|
+
},
|
|
1363
|
+
});
|
|
1364
|
+
const operations = {
|
|
1365
|
+
listBoards, getBoard, createBoard, updateBoard, createChannel, updateChannel,
|
|
1366
|
+
listThreads, getThread, createThread, updateThread, transitionThread, setLabels, addLink, removeLink,
|
|
1367
|
+
postMessage, editMessage, deleteMessage, react,
|
|
1368
|
+
readyTasks, claimTask, renewClaim, releaseTask, reportProgress, completeTask, failTask,
|
|
1369
|
+
addDependency, removeDependency, listGrants, explain, grant, revokeGrant,
|
|
1370
|
+
activity, listSchemas, listWatchers, createWatcher, deleteWatcher, scheduleFollowup, changeFollowup, importMessage,
|
|
1371
|
+
};
|
|
1372
|
+
/**
|
|
1373
|
+
* Run a Boards operation from inside another handler (an `app.agent` a watcher woke, a mutation of the
|
|
1374
|
+
* application's own) as that handler's caller, through the same rules: the operation's permission is
|
|
1375
|
+
* checked against the caller's roles, its arguments are validated, then its handler runs in the caller's
|
|
1376
|
+
* transaction. A query operation needs a query or mutation context; any other needs a mutation's.
|
|
1377
|
+
*/
|
|
1378
|
+
async function run(ctx, op, args) {
|
|
1379
|
+
const fn = operations[op];
|
|
1380
|
+
if (!fn)
|
|
1381
|
+
fail("INVALID_ARGUMENT", `No Boards operation ${String(op)}.`);
|
|
1382
|
+
if (fn.kind === "mutation" && !("insert" in ctx.db))
|
|
1383
|
+
fail("FAILED_PRECONDITION", `boards.run(${String(op)}) changes state: call it from a mutation or an agent.`);
|
|
1384
|
+
ctx.auth.require(fn.access);
|
|
1385
|
+
const checked = fn.argsSchema.validate(args ?? {});
|
|
1386
|
+
if (!checked.ok)
|
|
1387
|
+
fail("INVALID_ARGUMENT", `boards.run(${String(op)}): ${(checked.issues ?? []).map((i) => `${i.path.join(".") || "(root)"} ${i.message}`).join("; ")}`);
|
|
1388
|
+
return (await fn.handler(ctx, checked.value));
|
|
1389
|
+
}
|
|
1390
|
+
return functionGroup({
|
|
1391
|
+
// boards and channels
|
|
1392
|
+
listBoards, getBoard, createBoard, updateBoard, createChannel, updateChannel,
|
|
1393
|
+
// threads and messages
|
|
1394
|
+
listThreads, getThread, createThread, updateThread, transitionThread, setLabels, addLink, removeLink,
|
|
1395
|
+
postMessage, editMessage, deleteMessage, react,
|
|
1396
|
+
// work
|
|
1397
|
+
readyTasks, claimTask, renewClaim, releaseTask, reportProgress, completeTask, failTask,
|
|
1398
|
+
addDependency, removeDependency,
|
|
1399
|
+
// authority
|
|
1400
|
+
listGrants, explain, grant, revokeGrant,
|
|
1401
|
+
// history, schemas, automation, integration
|
|
1402
|
+
activity, listSchemas, listWatchers, createWatcher, deleteWatcher,
|
|
1403
|
+
scheduleFollowup, changeFollowup, runFollowup, importMessage,
|
|
1404
|
+
/** The collections, for application code that reads board state directly (reports, policies). */
|
|
1405
|
+
collections: collections,
|
|
1406
|
+
options: Object.freeze({ prefix, claimTtlMs: ttlMs, followupJob }),
|
|
1407
|
+
run,
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
//# sourceMappingURL=index.js.map
|