shapewall 0.3.3 → 0.7.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/CHANGELOG.md +501 -0
- package/README.md +87 -4
- package/THIRD_PARTY.md +15 -0
- package/dist/agent/package-lock.json +594 -2
- package/dist/client/assets/BoardChat-WS8mAIW6.js +27 -0
- package/dist/client/assets/{BuzzDialog-Ix9qJvim.js → BuzzDialog-B-Mlr6wF.js} +1 -1
- package/dist/client/assets/ChecksPanel-Dx1ZLBR6.js +1 -0
- package/dist/client/assets/History-sXhmpcvs.js +1 -0
- package/dist/client/assets/LocalSettings-CtGzz9F3.js +1 -0
- package/dist/client/assets/{Management-NVFDtSZB.js → Management-CGHe8Wt9.js} +1 -1
- package/dist/client/assets/QuickConnect-DEk84E4A.js +1 -0
- package/dist/client/assets/{ShareDialog-By0ETg6n.js → ShareDialog-CGGx-AYK.js} +2 -2
- package/dist/client/assets/{app-update-dialog-RGIw24iZ.js → app-update-dialog-_bVp8hnC.js} +1 -1
- package/dist/client/assets/{circle-x-B6KfScOE.js → circle-x-BWoHA1QY.js} +1 -1
- package/dist/client/assets/index-Bm-Xd3YN.js +37 -0
- package/dist/client/assets/index-C7Ostk3K.css +2 -0
- package/dist/client/assets/play-BzQ3tRTv.js +1 -0
- package/dist/client/assets/{refresh-cw-vkgvCCfR.js → refresh-cw-BYBMyDKT.js} +1 -1
- package/dist/client/assets/{runtime-Bft6x_6E.js → runtime-Bvq10IhH.js} +1 -1
- package/dist/client/assets/ui-CAY6myRA.js +41 -0
- package/dist/client/build-info.json +1 -1
- package/dist/client/index.html +3 -3
- package/dist/client/sw.js +2 -2
- package/dist/console/assets/LocalAccountsApp-CWRguRRL.js +1 -0
- package/dist/console/assets/LocalConsole--I2SaIpr.js +2 -0
- package/dist/console/assets/LocalUsage-BmpCZ36k.js +1 -0
- package/dist/console/assets/app-update-dialog-B8M9plaT.js +1 -0
- package/dist/console/assets/app-version-muKrQqbL.js +1 -0
- package/dist/console/assets/console-CrhTsPbz.css +2 -0
- package/dist/console/assets/console-DxapQ9oS.js +11 -0
- package/dist/console/assets/local-agents-CoqD4dSN.js +6 -0
- package/dist/console/assets/minus-DDQ0ydcM.js +1 -0
- package/dist/console/assets/tailnet-C5Flwl_d.js +2 -0
- package/dist/console/assets/theme-DCd0qh4l.js +1 -0
- package/dist/console/assets/ui-Bry1mnCY.js +41 -0
- package/dist/console/assets/usage-CIPWnHaS.css +1 -0
- package/dist/console/assets/usage-CqVjMb7m.js +5 -0
- package/dist/console/assets/usage-D1G0GgE3.js +56 -0
- package/dist/console/build-info.json +1 -1
- package/dist/console/console.html +8 -2
- package/docs/agent-hardening.md +206 -0
- package/docs/agent-recipes.md +23 -0
- package/docs/agent-workflow.md +5 -0
- package/docs/agents.md +49 -6
- package/docs/architecture.md +10 -4
- package/docs/deployment.md +39 -17
- package/docs/design-system.md +56 -7
- package/docs/hosted.md +1800 -46
- package/docs/images/board-overview.png +0 -0
- package/docs/images/journeys.png +0 -0
- package/docs/images/live-comment.png +0 -0
- package/docs/images/phone-comment.png +0 -0
- package/docs/images/phone-overview.png +0 -0
- package/docs/images/variant.png +0 -0
- package/docs/where-to-run.md +119 -3
- package/package.json +6 -1
- package/src/agent/backends/acp.js +745 -44
- package/src/agent/branch-mode.js +17 -3
- package/src/agent/card-hash.js +65 -0
- package/src/agent/context.js +41 -0
- package/src/agent/exec-paths.js +105 -0
- package/src/agent/routes.js +23 -2
- package/src/agent/run.js +11 -1
- package/src/agent/starter/cli.js +6 -1
- package/src/agent/turn-changes.js +70 -8
- package/src/agent/usage-log.js +251 -0
- package/src/cli/args.js +37 -0
- package/src/cli/commands.js +20 -5
- package/src/cli/help.js +73 -3
- package/src/cli/init.js +2 -1
- package/src/cli/serve.js +20 -5
- package/src/cli.js +8 -0
- package/src/hosted/access-cli.js +99 -1
- package/src/hosted/activity-core.js +232 -0
- package/src/hosted/activity.js +375 -0
- package/src/hosted/admin.js +87 -13
- package/src/hosted/agent-approvals.js +29 -4
- package/src/hosted/agent-link.js +1032 -0
- package/src/hosted/agent-policy.js +10 -3
- package/src/hosted/agent-presence.js +63 -22
- package/src/hosted/agent-routes.js +135 -0
- package/src/hosted/agents.js +1206 -0
- package/src/hosted/app.js +178 -12
- package/src/hosted/auth-routes.js +156 -15
- package/src/hosted/auth.js +123 -20
- package/src/hosted/board-routes.js +129 -5
- package/src/hosted/chat-frames.js +246 -0
- package/src/hosted/chat-job.js +204 -0
- package/src/hosted/chat-permissions.js +203 -0
- package/src/hosted/chat-routes.js +1009 -0
- package/src/hosted/chat-store.js +477 -0
- package/src/hosted/comment-files.js +11 -1
- package/src/hosted/comments.js +1 -1
- package/src/hosted/console-routes.js +122 -34
- package/src/hosted/db.js +295 -0
- package/src/hosted/device-routes.js +88 -10
- package/src/hosted/device.js +54 -4
- package/src/hosted/events.js +3 -3
- package/src/hosted/guards.js +337 -27
- package/src/hosted/http.js +6 -3
- package/src/hosted/membership.js +22 -3
- package/src/hosted/operator-access.js +418 -0
- package/src/hosted/operator.js +106 -2
- package/src/hosted/ops-cli.js +238 -3
- package/src/hosted/pages.js +4 -0
- package/src/hosted/passkey-policy.js +75 -0
- package/src/hosted/permissions.js +52 -6
- package/src/hosted/presence.js +31 -2
- package/src/hosted/projects.js +30 -2
- package/src/hosted/public.js +4 -4
- package/src/hosted/ratelimit.js +14 -0
- package/src/hosted/retention.js +18 -2
- package/src/hosted/server.js +123 -11
- package/src/hosted/shares.js +2 -2
- package/src/hosted/step-up-settings.js +68 -0
- package/src/hosted/step-up.js +135 -0
- package/src/hosted/tailnet-identity.js +24 -0
- package/src/hosted/tailnet-routes.js +342 -0
- package/src/hosted/tailnet.js +220 -0
- package/src/hosted/tailscale.js +75 -9
- package/src/hosted/tenancy.js +66 -1
- package/src/hosted/token-api.js +119 -20
- package/src/hosted/token-events.js +5 -3
- package/src/hosted/tokens.js +29 -6
- package/src/hosted/turn-hub.js +152 -0
- package/src/hosted/usage-core.js +624 -0
- package/src/hosted/usage-layout.js +724 -0
- package/src/hosted/usage-routes.js +375 -0
- package/src/hosted/usage-shape.js +256 -0
- package/src/hosted/usage.js +641 -0
- package/src/remote/agent-connect.js +469 -0
- package/src/remote/agent-fix.js +611 -0
- package/src/remote/agent-job.js +216 -0
- package/src/remote/agent-link.js +906 -0
- package/src/remote/agent-policy-file.js +242 -0
- package/src/remote/credentials.js +35 -1
- package/src/remote/login.js +44 -9
- package/src/remote/share.js +1 -1
- package/src/remote/tailnet-cli.js +547 -0
- package/src/server/app.js +15 -0
- package/src/server/pairing-routes.js +34 -5
- package/src/server/tailscale.js +97 -4
- package/src/tailnet-proof.js +766 -0
- package/dist/client/assets/BoardChat-DxehB761.js +0 -27
- package/dist/client/assets/ChecksPanel-pA_ueIaJ.js +0 -1
- package/dist/client/assets/History-C9N32kCv.js +0 -1
- package/dist/client/assets/LocalSettings-DawtKnvi.js +0 -1
- package/dist/client/assets/QuickConnect-DO1TjS1t.js +0 -1
- package/dist/client/assets/index-CsqLdqGx.css +0 -2
- package/dist/client/assets/index-DnZarJ3U.js +0 -37
- package/dist/client/assets/shield-check-QzwGhz0t.js +0 -1
- package/dist/client/assets/ui-DI-FGWWK.js +0 -41
- package/dist/console/assets/LocalAccountsApp-VOCZg8dg.js +0 -1
- package/dist/console/assets/LocalConsole-CMwAW-mF.js +0 -1
- package/dist/console/assets/app-update-dialog-Cw6UDqNP.js +0 -1
- package/dist/console/assets/console-DgfWmUEx.js +0 -55
- package/dist/console/assets/console-Lis0vvdL.css +0 -2
|
@@ -18,6 +18,8 @@ export const DEFAULT_POLICY = {
|
|
|
18
18
|
onlyMentions: false,
|
|
19
19
|
dailyClaims: 50,
|
|
20
20
|
maxOpenClaims: 3,
|
|
21
|
+
// Chat turns with connected agents, per project and day.
|
|
22
|
+
dailyTurns: 200,
|
|
21
23
|
approveNonAdmin: true,
|
|
22
24
|
}
|
|
23
25
|
export const expandScopes = (scopes) => [...new Set(scopes.flatMap((scope) => (scope === 'comment' ? ['reply', 'status'] : [scope])))]
|
|
@@ -47,6 +49,7 @@ export function cleanPolicy(input) {
|
|
|
47
49
|
for (const [key, max] of [
|
|
48
50
|
['dailyClaims', 10000],
|
|
49
51
|
['maxOpenClaims', 100],
|
|
52
|
+
['dailyTurns', 100000],
|
|
50
53
|
]) {
|
|
51
54
|
if (input[key] !== undefined && (!Number.isInteger(input[key]) || input[key] < 0 || input[key] > max))
|
|
52
55
|
throw new AgentPolicyError(400, 'invalid_policy', `Invalid ${key}.`)
|
|
@@ -133,7 +136,9 @@ export function createAgentPolicy(t, { handleFor = () => null, now = () => new D
|
|
|
133
136
|
function autoVouch(project, board, row, user, role) {
|
|
134
137
|
if (trusted(agentPolicy(t, project, board), user)) vouch(project, board, row, user, { role })
|
|
135
138
|
}
|
|
136
|
-
|
|
139
|
+
// `agent`: the id of the token's agent (src/hosted/agents.js), kept on
|
|
140
|
+
// the claim. Returns the claim's id.
|
|
141
|
+
function claim(project, board, row, token, agent = null) {
|
|
137
142
|
if (!state(project, board, row).dispatchable)
|
|
138
143
|
throw new AgentPolicyError(403, 'not_dispatchable', 'A trusted member must send the current comment to an agent first.')
|
|
139
144
|
const policy = agentPolicy(t, project, board)
|
|
@@ -180,10 +185,12 @@ export function createAgentPolicy(t, { handleFor = () => null, now = () => new D
|
|
|
180
185
|
}).n
|
|
181
186
|
if (daily >= policy.dailyClaims || open >= policy.maxOpenClaims)
|
|
182
187
|
throw new AgentPolicyError(429, 'agent_budget', 'The project agent budget is exhausted. Ask an admin to review Agent policy.')
|
|
188
|
+
const id = randomBytes(16).toString('hex')
|
|
183
189
|
t.run(
|
|
184
|
-
'INSERT INTO agent_claims (workspace_id,id,project_id,board_id,comment_number,token_id,hash,created_at) VALUES (:ws,:id,:project,:board,:number,:token,:hash,:at)',
|
|
185
|
-
{ project, board, number: row.number, token, id
|
|
190
|
+
'INSERT INTO agent_claims (workspace_id,id,project_id,board_id,comment_number,token_id,agent_id,hash,created_at) VALUES (:ws,:id,:project,:board,:number,:token,:agent,:hash,:at)',
|
|
191
|
+
{ project, board, number: row.number, token, agent, id, hash: dispatchHash(row), at },
|
|
186
192
|
)
|
|
193
|
+
return id
|
|
187
194
|
}
|
|
188
195
|
return { state, vouch, autoVouch, claim, trusted }
|
|
189
196
|
}
|
|
@@ -1,40 +1,81 @@
|
|
|
1
|
-
//
|
|
2
|
-
// some machine runs `shapewall watch --remote` (or an MCP client) for
|
|
3
|
-
// project, with a token that has the claim scope.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// Which agents are listening? A comment on a hosted board is only acted on
|
|
2
|
+
// while some machine runs `shapewall watch --remote` (or an MCP client) for
|
|
3
|
+
// its project, with a token that has the claim scope. Each such token is an
|
|
4
|
+
// agent (src/hosted/agents.js). This remembers, per agent, when its token
|
|
5
|
+
// last called the token API or held its event stream open, so the board can
|
|
6
|
+
// say "Builder: online" or "offline since 10:42" for each one.
|
|
7
7
|
//
|
|
8
8
|
// In memory only, on purpose: it is a few seconds of truth, empty after a
|
|
9
|
-
// restart until the next poll
|
|
10
|
-
//
|
|
11
|
-
//
|
|
9
|
+
// restart until the next poll. (The agent's row keeps a last-seen time for
|
|
10
|
+
// "offline since"; src/hosted/agents.js writes it, at most once a minute,
|
|
11
|
+
// when seen() says it is due.) It holds an agent's id and display name and a
|
|
12
|
+
// time, nothing else: no token id, no hash, no address.
|
|
12
13
|
|
|
13
14
|
export const AGENT_PRESENCE_TTL_MS = 90_000
|
|
14
|
-
|
|
15
|
+
// How often an agent's last-seen time is worth writing to the database.
|
|
16
|
+
export const AGENT_SEEN_SAVE_MS = 60_000
|
|
17
|
+
const AGENTS_MAX = 20_000
|
|
15
18
|
|
|
16
19
|
export function createAgentPresence({ now = () => new Date(), ttlMs = AGENT_PRESENCE_TTL_MS } = {}) {
|
|
20
|
+
// agent key -> { workspaceId, projectId, name, at, savedAt }, oldest first.
|
|
17
21
|
const seenAt = new Map()
|
|
18
|
-
|
|
22
|
+
// project key -> the agent key last heard from (the `of` summary).
|
|
23
|
+
const latest = new Map()
|
|
24
|
+
const projectKey = (workspaceId, projectId) => `${workspaceId}:${projectId}`
|
|
25
|
+
const agentKey = (workspaceId, agentId) => `${workspaceId}:${agentId}`
|
|
26
|
+
const fresh = (entry) => Boolean(entry) && !entry.gone && now().getTime() - entry.at <= ttlMs
|
|
19
27
|
return {
|
|
20
|
-
// A claim-scoped token of this project was just heard from.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
// A claim-scoped token of this project was just heard from. Returns
|
|
29
|
+
// { cameOnline, save }: whether the agent was offline until now, and
|
|
30
|
+
// whether its last-seen time is due to be written down.
|
|
31
|
+
seen(workspaceId, projectId, agentId, name) {
|
|
32
|
+
if (!workspaceId || !projectId || !agentId) return { cameOnline: false, save: false }
|
|
33
|
+
const id = agentKey(workspaceId, agentId)
|
|
34
|
+
const before = seenAt.get(id)
|
|
35
|
+
const at = now().getTime()
|
|
36
|
+
const save = !before || at - before.savedAt >= AGENT_SEEN_SAVE_MS
|
|
24
37
|
// Re-inserted, so the map stays in order of last seen (oldest first).
|
|
25
38
|
seenAt.delete(id)
|
|
26
|
-
seenAt.set(id, { name: String(name || 'agent').slice(0, 80), at:
|
|
27
|
-
|
|
39
|
+
seenAt.set(id, { workspaceId, projectId, name: String(name || 'agent').slice(0, 80), at, savedAt: save ? at : before.savedAt })
|
|
40
|
+
latest.set(projectKey(workspaceId, projectId), id)
|
|
41
|
+
if (seenAt.size > AGENTS_MAX) seenAt.delete(seenAt.keys().next().value)
|
|
42
|
+
return { cameOnline: !fresh(before), save }
|
|
28
43
|
},
|
|
29
|
-
//
|
|
30
|
-
//
|
|
44
|
+
// One agent: { online, lastSeenAt }. `lastSeenAt` stays after it goes
|
|
45
|
+
// quiet, until the server restarts.
|
|
46
|
+
ofAgent(workspaceId, agentId) {
|
|
47
|
+
const entry = seenAt.get(agentKey(workspaceId, agentId))
|
|
48
|
+
if (!entry) return { online: false, lastSeenAt: null }
|
|
49
|
+
return { online: fresh(entry), lastSeenAt: new Date(entry.at).toISOString() }
|
|
50
|
+
},
|
|
51
|
+
// The project as a whole, in the shape boards read since 0.3.3
|
|
52
|
+
// (`agentListening`): { online, name, lastSeenAt } of the agent heard
|
|
53
|
+
// from last.
|
|
31
54
|
of(workspaceId, projectId) {
|
|
32
|
-
const entry = seenAt.get(
|
|
55
|
+
const entry = seenAt.get(latest.get(projectKey(workspaceId, projectId)))
|
|
33
56
|
if (!entry) return { online: false, name: null, lastSeenAt: null }
|
|
34
|
-
return { online:
|
|
57
|
+
return { online: fresh(entry), name: entry.name, lastSeenAt: new Date(entry.at).toISOString() }
|
|
58
|
+
},
|
|
59
|
+
// A connected agent's link closed (src/hosted/agent-link.js): it is
|
|
60
|
+
// offline now, not in 90 seconds. Its last-seen time stays.
|
|
61
|
+
gone(workspaceId, agentId) {
|
|
62
|
+
const entry = seenAt.get(agentKey(workspaceId, agentId))
|
|
63
|
+
if (entry) entry.gone = true
|
|
64
|
+
},
|
|
65
|
+
// A revoked agent is not listening any more.
|
|
66
|
+
forgetAgent(workspaceId, agentId) {
|
|
67
|
+
const id = agentKey(workspaceId, agentId)
|
|
68
|
+
const entry = seenAt.get(id)
|
|
69
|
+
seenAt.delete(id)
|
|
70
|
+
if (!entry || latest.get(projectKey(entry.workspaceId, entry.projectId)) !== id) return
|
|
71
|
+
// The project's summary falls back to the agent heard from before it.
|
|
72
|
+
const project = projectKey(entry.workspaceId, entry.projectId)
|
|
73
|
+
latest.delete(project)
|
|
74
|
+
for (const [key, other] of seenAt) if (projectKey(other.workspaceId, other.projectId) === project) latest.set(project, key)
|
|
35
75
|
},
|
|
36
76
|
forget(workspaceId, projectId) {
|
|
37
|
-
seenAt.
|
|
77
|
+
for (const [id, entry] of [...seenAt]) if (entry.workspaceId === workspaceId && entry.projectId === projectId) seenAt.delete(id)
|
|
78
|
+
latest.delete(projectKey(workspaceId, projectId))
|
|
38
79
|
},
|
|
39
80
|
}
|
|
40
81
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// The console API for agents (src/hosted/app.js): the workspace overview,
|
|
2
|
+
// a project's Agents page, and each agent setting. Thin on purpose: every
|
|
3
|
+
// setting is changed by one function in src/hosted/agents.js (setIdentity,
|
|
4
|
+
// setDefault, setAudience, setApprovalRule, revoke), which checks the role,
|
|
5
|
+
// validates, writes and audits. These routes only read the request and call
|
|
6
|
+
// it, so a CLI command or an admin tool can call the same function later.
|
|
7
|
+
//
|
|
8
|
+
// Listing and managing agents is for the people who manage tokens (admins
|
|
9
|
+
// and owners). Widening who may use an agent, and its approval rule, ask
|
|
10
|
+
// for a fresh passkey check, like the agent policy.
|
|
11
|
+
|
|
12
|
+
import { agentPolicy } from './agent-policy.js'
|
|
13
|
+
import { transaction } from './db.js'
|
|
14
|
+
import { HttpError } from './http.js'
|
|
15
|
+
import { AGENT_AUDIENCES, APPROVAL_ROLES, APPROVAL_RULES, NEEDS, roleAtLeast } from './permissions.js'
|
|
16
|
+
import { AGENT_KINDS } from './agents.js'
|
|
17
|
+
|
|
18
|
+
export function mountAgentRoutes(consoleApi, { db, publicOrigin, handle, inWorkspace, inProject, stepUp, auditOf, agentsFor }) {
|
|
19
|
+
const actorOf = (req) => ({
|
|
20
|
+
userId: req.user.id,
|
|
21
|
+
role: req.role,
|
|
22
|
+
audit: (action, target, detail) => auditOf(req, action, target, detail),
|
|
23
|
+
})
|
|
24
|
+
// What the editors offer, so the console never hardcodes a list the
|
|
25
|
+
// server would refuse.
|
|
26
|
+
const options = { audiences: AGENT_AUDIENCES, approvalRules: APPROVAL_RULES, approvalRoles: APPROVAL_ROLES, kinds: AGENT_KINDS }
|
|
27
|
+
|
|
28
|
+
// Every agent of the workspace, with the project each serves.
|
|
29
|
+
consoleApi.get(
|
|
30
|
+
'/workspaces/:ws/agents',
|
|
31
|
+
inWorkspace(NEEDS.tokens),
|
|
32
|
+
handle((req, res) => {
|
|
33
|
+
res.json({ agents: transaction(db, () => agentsFor(req.t).consoleList(null, { audit: actorOf(req).audit })), options })
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
// One project's agents, its default agent, and what the audience editor
|
|
38
|
+
// needs: the members who could be named, and whom the agent policy trusts.
|
|
39
|
+
consoleApi.get(
|
|
40
|
+
'/workspaces/:ws/projects/:pid/agents',
|
|
41
|
+
inWorkspace(NEEDS.tokens),
|
|
42
|
+
inProject,
|
|
43
|
+
handle((req, res) => {
|
|
44
|
+
const agents = agentsFor(req.t)
|
|
45
|
+
const policy = agentPolicy(req.t, req.project.id)
|
|
46
|
+
const members = req.t
|
|
47
|
+
.all(
|
|
48
|
+
'SELECT m.user_id, m.role, u.handle, u.display_name FROM memberships m JOIN users u ON u.id = m.user_id WHERE m.workspace_id = :ws ORDER BY u.display_name, u.handle',
|
|
49
|
+
)
|
|
50
|
+
.filter((row) => roleAtLeast(row.role, 'member'))
|
|
51
|
+
.map((row) => ({
|
|
52
|
+
userId: row.user_id,
|
|
53
|
+
handle: row.handle,
|
|
54
|
+
displayName: row.display_name,
|
|
55
|
+
role: row.role,
|
|
56
|
+
// Whether the agent policy lets this person send work to an agent at all.
|
|
57
|
+
trusted: agents.trusted(req.project.id, null, row.user_id),
|
|
58
|
+
}))
|
|
59
|
+
res.json({
|
|
60
|
+
agents: transaction(db, () => agents.consoleList(req.project.id, { audit: actorOf(req).audit })),
|
|
61
|
+
defaultAgentId: agents.defaultAgent(req.project.id)?.id || null,
|
|
62
|
+
members,
|
|
63
|
+
policy: { trustedRoles: policy.trustedRoles, trustedHandles: policy.trustedHandles },
|
|
64
|
+
connect: { origin: publicOrigin },
|
|
65
|
+
options,
|
|
66
|
+
})
|
|
67
|
+
}),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
// Name, icon, tint, kind: { name?, icon?, tint?, kind? }.
|
|
71
|
+
consoleApi.patch(
|
|
72
|
+
'/workspaces/:ws/projects/:pid/agents/:aid',
|
|
73
|
+
inWorkspace(NEEDS.tokens),
|
|
74
|
+
inProject,
|
|
75
|
+
handle((req, res) => {
|
|
76
|
+
const { name, icon, tint, kind } = req.body || {}
|
|
77
|
+
const agent = transaction(db, () =>
|
|
78
|
+
agentsFor(req.t).setIdentity(actorOf(req), req.project.id, req.params.aid, { name, icon, tint, kind }),
|
|
79
|
+
)
|
|
80
|
+
res.json({ agent })
|
|
81
|
+
}),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
// Who may send it work: { audience, users }.
|
|
85
|
+
consoleApi.put(
|
|
86
|
+
'/workspaces/:ws/projects/:pid/agents/:aid/audience',
|
|
87
|
+
inWorkspace(NEEDS.tokens),
|
|
88
|
+
stepUp('agents'),
|
|
89
|
+
inProject,
|
|
90
|
+
handle((req, res) => {
|
|
91
|
+
const { audience, users } = req.body || {}
|
|
92
|
+
const agent = transaction(db, () => agentsFor(req.t).setAudience(actorOf(req), req.project.id, req.params.aid, { audience, users }))
|
|
93
|
+
res.json({ agent })
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
// The approval rule and who decides: { rule?, changeRole?, answerRole? }.
|
|
98
|
+
consoleApi.put(
|
|
99
|
+
'/workspaces/:ws/projects/:pid/agents/:aid/approval',
|
|
100
|
+
inWorkspace(NEEDS.tokens),
|
|
101
|
+
stepUp('agents'),
|
|
102
|
+
inProject,
|
|
103
|
+
handle((req, res) => {
|
|
104
|
+
const { rule, changeRole, answerRole } = req.body || {}
|
|
105
|
+
const agent = transaction(db, () =>
|
|
106
|
+
agentsFor(req.t).setApprovalRule(actorOf(req), req.project.id, req.params.aid, { rule, changeRole, answerRole }),
|
|
107
|
+
)
|
|
108
|
+
res.json({ agent })
|
|
109
|
+
}),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
// The project's default agent: { agentId } (null: any agent).
|
|
113
|
+
consoleApi.put(
|
|
114
|
+
'/workspaces/:ws/projects/:pid/default-agent',
|
|
115
|
+
inWorkspace(NEEDS.tokens),
|
|
116
|
+
inProject,
|
|
117
|
+
handle((req, res) => {
|
|
118
|
+
const agentId = req.body?.agentId
|
|
119
|
+
if (agentId !== null && typeof agentId !== 'string')
|
|
120
|
+
throw new HttpError(400, 'invalid_agent', 'agentId: an agent id, or null for any agent.')
|
|
121
|
+
const defaultAgentId = transaction(db, () => agentsFor(req.t).setDefault(actorOf(req), req.project.id, agentId))
|
|
122
|
+
res.json({ defaultAgentId })
|
|
123
|
+
}),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
// Revokes the agent's token (the same as revoking it on the Tokens page).
|
|
127
|
+
consoleApi.delete(
|
|
128
|
+
'/workspaces/:ws/projects/:pid/agents/:aid',
|
|
129
|
+
inWorkspace(NEEDS.tokens),
|
|
130
|
+
inProject,
|
|
131
|
+
handle((req, res) => {
|
|
132
|
+
res.json(transaction(db, () => agentsFor(req.t).revoke(actorOf(req), req.project.id, req.params.aid)))
|
|
133
|
+
}),
|
|
134
|
+
)
|
|
135
|
+
}
|