heyquilt 0.3.183 → 0.3.185
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/RELEASES.md +10 -0
- package/package.json +1 -1
- package/src/account.js +15 -0
- package/src/api/memory-store.js +22 -1
- package/src/api/routes/connections.js +54 -13
- package/src/api/routes/workspace-chat.js +77 -0
- package/src/api/routes/workspaces.js +2 -0
- package/src/api/server.js +2 -1
- package/src/api/supabase-store.js +25 -1
- package/src/app-tools.js +2 -2
- package/src/app-workspaces.js +21 -0
- package/src/ui/app.css +27 -7
- package/src/ui/connections.js +48 -8
- package/src/ui/home.js +8 -3
- package/src/ui/loom.js +3 -17
- package/src/ui/project-channel.js +93 -0
- package/src/ui/project-model.js +27 -0
- package/src/ui/project-pop.js +1 -1
- package/src/ui/projects.js +83 -25
- package/src/ui/session.js +25 -17
- package/src/ui/voice.js +8 -5
- package/src/ui-server.js +27 -4
package/RELEASES.md
CHANGED
|
@@ -11,6 +11,16 @@ Format: `## <version> — <YYYY-MM-DD>`, an optional one-line summary, then bull
|
|
|
11
11
|
Lead each bullet with a short bold phrase. Inline `code` and **bold** are rendered;
|
|
12
12
|
nothing else is.
|
|
13
13
|
|
|
14
|
+
## 0.3.185 — 2026-11-23
|
|
15
|
+
|
|
16
|
+
- **A simpler Loom.** The three switches above the Loom are gone: Chat and Tasks, Detailed and Compact, Lanes and One column. The Loom always shows chat and tasks, every card in full, and a lane for each person (one column when the window is narrow).
|
|
17
|
+
|
|
18
|
+
## 0.3.184 — 2026-11-22
|
|
19
|
+
|
|
20
|
+
Connections for the agents you choose.
|
|
21
|
+
|
|
22
|
+
- **A connection for chosen agents.** In Connections, an app you connected can be for **People and chosen agents**: tick the agents that may use it. An agent that was not chosen does not see the app and cannot run its actions; people in the codebase always can.
|
|
23
|
+
|
|
14
24
|
## 0.3.183 — 2026-11-22
|
|
15
25
|
|
|
16
26
|
What you code in together is now called a codebase.
|
package/package.json
CHANGED
package/src/account.js
CHANGED
|
@@ -350,6 +350,21 @@ export async function moveSessionToWorkspace ({ token, id, room, api = apiUrl(),
|
|
|
350
350
|
return { session: r.session, added: Array.isArray(r.added) ? r.added : [], peopleNeedAdmin: !!r.peopleNeedAdmin }
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
+
// A project's channel (routes/workspace-chat.js): its messages, saying something, and marking it read.
|
|
354
|
+
export async function workspaceMessages ({ token, id, after = 0, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
355
|
+
const r = await call(fetchImpl, api, 'GET', `${ws$(id)}/messages${after ? `?after=${encodeURIComponent(after)}` : ''}`, null, token)
|
|
356
|
+
if (!Array.isArray(r.messages)) throw new Error(BAD_REPLY)
|
|
357
|
+
return r
|
|
358
|
+
}
|
|
359
|
+
export async function sayInWorkspace ({ token, id, text, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
360
|
+
const r = await call(fetchImpl, api, 'POST', `${ws$(id)}/messages`, { text }, token)
|
|
361
|
+
if (!r.message) throw new Error(BAD_REPLY)
|
|
362
|
+
return r
|
|
363
|
+
}
|
|
364
|
+
export async function readWorkspaceMessages ({ token, id, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
365
|
+
return call(fetchImpl, api, 'POST', `${ws$(id)}/messages/read`, {}, token)
|
|
366
|
+
}
|
|
367
|
+
|
|
353
368
|
// Workspace invites: an admin invites a person ({ account } or { email }); they accept in their Quilt.
|
|
354
369
|
export async function listWorkspaceInvites ({ token, id, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
355
370
|
const r = await call(fetchImpl, api, 'GET', `${ws$(id)}/invites`, null, token)
|
package/src/api/memory-store.js
CHANGED
|
@@ -62,6 +62,7 @@ export function createMemoryStore ({ now = Date.now } = {}) {
|
|
|
62
62
|
const secretTickets = new Map(); const secretRuns = new Map(); const secretAsks = new Map(); const secretUses = []
|
|
63
63
|
// App connections (20261112000000_app_connections.sql).
|
|
64
64
|
const appConnections = new Map(); const appCalls = new Map()
|
|
65
|
+
const workspaceMessages = new Map(); const workspaceReads = new Map() // a project's channel, and each account's place in it
|
|
65
66
|
const scopeKey = (scopeType, scopeId) => `${scopeType}\n${scopeId}`
|
|
66
67
|
// A secret as the API's routes see it: never its sealed value (secretSealed reads that, for the vault).
|
|
67
68
|
const secretMeta = (r) => { if (!r) return null; const { sealedValue, ...rest } = copy(r); return rest }
|
|
@@ -989,6 +990,8 @@ export function createMemoryStore ({ now = Date.now } = {}) {
|
|
|
989
990
|
for (const s of relaySessions.values()) if (s.workspaceId === id) s.workspaceId = null
|
|
990
991
|
for (const [k, m] of workspaceMembers) if (m.workspaceId === id) workspaceMembers.delete(k)
|
|
991
992
|
for (const [k, i] of workspaceInvites) if (i.workspaceId === id) workspaceInvites.delete(k)
|
|
993
|
+
for (const [k, m] of workspaceMessages) if (m.workspaceId === id) workspaceMessages.delete(k)
|
|
994
|
+
for (const k of [...workspaceReads.keys()]) if (k.startsWith(`${id}|`)) workspaceReads.delete(k)
|
|
992
995
|
for (const [k, f] of workspaceFiles) {
|
|
993
996
|
if (f.workspaceId !== id) continue
|
|
994
997
|
for (const vk of [...workspaceFileVersions.keys()]) if (vk.startsWith(`${f.id}\n`)) workspaceFileVersions.delete(vk)
|
|
@@ -1296,10 +1299,28 @@ export function createMemoryStore ({ now = Date.now } = {}) {
|
|
|
1296
1299
|
return secretUses.filter((u) => secretIds.includes(u.secretId)).sort((a, b) => b.at - a.at).slice(0, limit).map(copy)
|
|
1297
1300
|
},
|
|
1298
1301
|
|
|
1302
|
+
// A project's channel (20261122010000_project_channel.sql): its messages, and what each account has read.
|
|
1303
|
+
async addWorkspaceMessage ({ workspaceId, account, name = '', text }) {
|
|
1304
|
+
if (!workspaces.has(workspaceId)) throw fkViolation('workspace', 'does not exist')
|
|
1305
|
+
// Two messages never share a time: the order they were written in is the order they are read in.
|
|
1306
|
+
const last = Math.max(0, ...all(workspaceMessages, (m) => m.workspaceId === workspaceId).map((m) => m.createdAt))
|
|
1307
|
+
const row = { id: uuid(), workspaceId, account, name, text, createdAt: Math.max(now(), last + 1) }
|
|
1308
|
+
workspaceMessages.set(row.id, row); return copy(row)
|
|
1309
|
+
},
|
|
1310
|
+
async listWorkspaceMessages (workspaceId, { after = 0, limit = 100 } = {}) {
|
|
1311
|
+
const mine = all(workspaceMessages, (m) => m.workspaceId === workspaceId && m.createdAt > after).sort((a, b) => a.createdAt - b.createdAt)
|
|
1312
|
+
return (after ? mine.slice(0, limit) : mine.slice(-limit)).map(copy)
|
|
1313
|
+
},
|
|
1314
|
+
async countWorkspaceMessages (workspaceId, { after = 0, notBy = '' } = {}) {
|
|
1315
|
+
return all(workspaceMessages, (m) => m.workspaceId === workspaceId && m.createdAt > after && m.account !== notBy).length
|
|
1316
|
+
},
|
|
1317
|
+
async workspaceReadAt (workspaceId, account) { return workspaceReads.get(`${workspaceId}|${account}`) || 0 },
|
|
1318
|
+
async setWorkspaceReadAt (workspaceId, account, at) { workspaceReads.set(`${workspaceId}|${account}`, Math.max(at, workspaceReads.get(`${workspaceId}|${account}`) || 0)) },
|
|
1319
|
+
|
|
1299
1320
|
// App connections (20261112000000_app_connections.sql): Composio holds the tokens.
|
|
1300
1321
|
async addAppConnection (c) {
|
|
1301
1322
|
if (all(appConnections, (r) => r.composioId === c.composioId).length) throw duplicate('connection')
|
|
1302
|
-
const row = { id: uuid(), appName: '', logo: '', status: 'pending', who: 'all', ...copy(c), createdAt: now(), updatedAt: now() }
|
|
1323
|
+
const row = { id: uuid(), appName: '', logo: '', status: 'pending', who: 'all', agents: [], ...copy(c), createdAt: now(), updatedAt: now() }
|
|
1303
1324
|
appConnections.set(row.id, row)
|
|
1304
1325
|
return copy(row)
|
|
1305
1326
|
},
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
// App connections (plans/app-connections.md): apps a team, workspace or
|
|
1
|
+
// App connections (plans/app-connections.md): apps a team, workspace, session or person connected through
|
|
2
2
|
// Composio (composio.js), and the agents' use of them (quilt_apps, quilt_app_tools, quilt_app_call
|
|
3
3
|
// in app-tools.js). People connect at a scope, as with secrets; Composio holds the tokens. An
|
|
4
4
|
// action that only reads runs at once; anything else waits for a person in the session, whose
|
|
5
5
|
// approval runs it once. Every call is kept (app_calls): the approvals, the session's record of
|
|
6
6
|
// what agents did in other apps, and the daily cap.
|
|
7
|
+
// A person's own connections (scope 'account') reach every project that person owns and their
|
|
8
|
+
// codebases in no project. A connection is for people and agents ('all'), people only, or only
|
|
9
|
+
// the agents chosen for it ('agents', with their ids).
|
|
7
10
|
import { HttpError, Raw, needId } from '../http.js'
|
|
8
11
|
import { orgAccess } from '../org-access.js'
|
|
9
12
|
import { workspaceReach } from '../workspace-reach.js'
|
|
@@ -12,7 +15,11 @@ import { sessionMember, roomLevels, workspaceLevels, LEVEL_WORDS } from '../secr
|
|
|
12
15
|
import { composioUser } from '../composio.js'
|
|
13
16
|
|
|
14
17
|
const ROOM = /^[A-Za-z0-9_-]{1,64}$/
|
|
15
|
-
const SCOPE = '(org|workspace|session)'
|
|
18
|
+
const SCOPE = '(org|workspace|session|account)'
|
|
19
|
+
const AGENT_ID = /^[0-9a-f-]{36}$/i
|
|
20
|
+
const MAX_CHOSEN = 100
|
|
21
|
+
// What each level is called (secrets have the first three; a person's own connections are for every project).
|
|
22
|
+
const WORDS = { ...LEVEL_WORDS, account: 'Every project' }
|
|
16
23
|
const APP = /^[a-z0-9_-]{1,64}$/
|
|
17
24
|
const TOOL = /^[A-Za-z0-9_-]{1,120}$/
|
|
18
25
|
const DAY_MS = 24 * 60 * 60 * 1000
|
|
@@ -61,21 +68,44 @@ export function connectionRoutes (ctx) {
|
|
|
61
68
|
return { account: `person:${p.userId}`, kind: 'person', userId: p.userId, agent: null }
|
|
62
69
|
}
|
|
63
70
|
|
|
71
|
+
/** The level of a person's own connections: theirs reach every project they own. */
|
|
72
|
+
const accountLevel = async (userId) => ({ type: 'account', id: userId, name: (await store.profile(userId))?.name || '' })
|
|
73
|
+
/** A workspace's levels for connections: itself, its team, and (a person's own project) its owner's own. */
|
|
74
|
+
async function levelsOfWorkspace (ws) {
|
|
75
|
+
const levels = await workspaceLevels(store, ws)
|
|
76
|
+
if (ws.ownerUserId) levels.push(await accountLevel(ws.ownerUserId))
|
|
77
|
+
return levels
|
|
78
|
+
}
|
|
79
|
+
/** A session's levels for connections: as for secrets, then the own connections of whoever owns its project, or owns it when it is in none. */
|
|
80
|
+
async function levelsOfRoom (room) {
|
|
81
|
+
const found = await roomLevels(store, room)
|
|
82
|
+
if (!found) return null
|
|
83
|
+
const ws = found.session.workspaceId ? await store.workspaceById(found.session.workspaceId) : null
|
|
84
|
+
const owner = ws ? ws.ownerUserId : String(found.session.ownerAccount || '').startsWith('person:') ? found.session.ownerAccount.slice(7) : null
|
|
85
|
+
return owner ? { ...found, levels: [...found.levels, await accountLevel(owner)] } : found
|
|
86
|
+
}
|
|
87
|
+
|
|
64
88
|
/** One scope as a person reaches it, as for secrets: { type, id, name, levels, canManage, me }. */
|
|
65
89
|
async function scopeOf (req, type, rawId) {
|
|
66
90
|
const me = await whoCalls(req)
|
|
67
91
|
if (me.kind !== 'person') throw new HttpError(403, 'People connect apps; agents use them with quilt_app_call.')
|
|
92
|
+
if (type === 'account') {
|
|
93
|
+
// Only your own: "me", or your own id.
|
|
94
|
+
if (rawId !== 'me' && rawId !== me.userId) throw new HttpError(404, 'no such account')
|
|
95
|
+
const level = await accountLevel(me.userId)
|
|
96
|
+
return { type, id: me.userId, name: level.name, levels: [level], canManage: true, me }
|
|
97
|
+
}
|
|
68
98
|
if (type === 'org') {
|
|
69
99
|
const a = await orgAccess(store, me.userId, rawId)
|
|
70
100
|
return { type, id: a.org.id, name: a.org.name, levels: [{ type, id: a.org.id, name: a.org.name }], canManage: a.can('org', 'u'), me }
|
|
71
101
|
}
|
|
72
102
|
if (type === 'workspace') {
|
|
73
103
|
const r = await reach(req, needId(rawId, 'project'))
|
|
74
|
-
return { type, id: r.ws.id, name: r.ws.name, levels: await
|
|
104
|
+
return { type, id: r.ws.id, name: r.ws.name, levels: await levelsOfWorkspace(r.ws), canManage: !!r.access.admin, me }
|
|
75
105
|
}
|
|
76
106
|
const room = String(rawId)
|
|
77
107
|
if (!ROOM.test(room)) throw new HttpError(404, 'no such codebase')
|
|
78
|
-
const found = await
|
|
108
|
+
const found = await levelsOfRoom(room)
|
|
79
109
|
if (!found || !(await sessionMember(store, room, me.account))) throw new HttpError(404, 'no such codebase')
|
|
80
110
|
// Anyone in the session connects apps for it (the owner removes any; others their own).
|
|
81
111
|
return { type, id: room, name: found.session.name || '', levels: found.levels, canManage: true, owner: found.session.ownerAccount === me.account, me, session: found.session }
|
|
@@ -95,10 +125,22 @@ export function connectionRoutes (ctx) {
|
|
|
95
125
|
}
|
|
96
126
|
|
|
97
127
|
const view = async (c, level, extra = {}) => ({
|
|
98
|
-
id: c.id, app: c.app, name: c.appName || c.app, logo: c.logo, status: c.status, who: c.who,
|
|
128
|
+
id: c.id, app: c.app, name: c.appName || c.app, logo: c.logo, status: c.status, who: c.who, agents: c.who === 'agents' ? (c.agents || []) : [],
|
|
99
129
|
level: level.type, levelName: level.name || '', by: await nameOf(c.createdBy), createdAt: c.createdAt, ...extra
|
|
100
130
|
})
|
|
101
131
|
|
|
132
|
+
/** Who may use a connection, from a request: { who, agents }. 'agents' names the agents chosen for it by id. */
|
|
133
|
+
function whoFrom (body, fallback = null) {
|
|
134
|
+
const who = body.who === undefined && fallback ? fallback : body.who
|
|
135
|
+
if (who !== 'all' && who !== 'people' && who !== 'agents') throw new HttpError(400, 'who is "all", "people" or "agents"')
|
|
136
|
+
if (who !== 'agents') return { who, agents: [] }
|
|
137
|
+
const agents = [...new Set(Array.isArray(body.agents) ? body.agents.map(String) : [])]
|
|
138
|
+
if (!agents.length || agents.length > MAX_CHOSEN || !agents.every((a) => AGENT_ID.test(a))) throw new HttpError(400, 'Say which agents may use it: agents is a list of their ids.')
|
|
139
|
+
return { who, agents }
|
|
140
|
+
}
|
|
141
|
+
/** Whether an agent may use a connection: one for everyone, or one that chose it. */
|
|
142
|
+
const agentMay = (c, agentId) => c.who === 'all' || (c.who === 'agents' && !!agentId && (c.agents || []).includes(agentId))
|
|
143
|
+
|
|
102
144
|
/** Every connection a session (or workspace) reaches, nearest level first: [{ connection, level }]. */
|
|
103
145
|
async function reachable (levels) {
|
|
104
146
|
const out = []
|
|
@@ -124,14 +166,14 @@ export function connectionRoutes (ctx) {
|
|
|
124
166
|
if (!ROOM.test(room)) throw new HttpError(404, 'no such codebase')
|
|
125
167
|
const me = await whoCalls(req)
|
|
126
168
|
if (!(await sessionMember(store, room, me.account, { agent: me.agent }))) throw new HttpError(404, 'no such codebase')
|
|
127
|
-
const found = await
|
|
169
|
+
const found = await levelsOfRoom(room)
|
|
128
170
|
if (!found) throw new HttpError(404, 'no such codebase')
|
|
129
171
|
return { me, found }
|
|
130
172
|
}
|
|
131
173
|
|
|
132
174
|
/** The connections the caller may use in the session, nearest level first. */
|
|
133
175
|
async function usable (me, found) {
|
|
134
|
-
return (await reachable(found.levels)).filter(({ connection: c }) => c.status === 'active' && (me.kind === 'person' || c.
|
|
176
|
+
return (await reachable(found.levels)).filter(({ connection: c }) => c.status === 'active' && (me.kind === 'person' || agentMay(c, me.agent && me.agent.id)))
|
|
135
177
|
}
|
|
136
178
|
|
|
137
179
|
const capKey = (session) => session.workspaceId ? `workspace:${session.workspaceId}` : `session:${session.room || ''}`
|
|
@@ -201,18 +243,17 @@ export function connectionRoutes (ctx) {
|
|
|
201
243
|
if (!APP.test(app)) throw new HttpError(400, 'Say which app to connect.')
|
|
202
244
|
const t = await composio.toolkit(app)
|
|
203
245
|
const l = await composio.link({ user: composioUser(s.type, s.id), app, callbackUrl: `${apiUrl}/v1/connections/done` })
|
|
204
|
-
const c = await store.addAppConnection({ scopeType: s.type, scopeId: s.id, app, appName: String(t.name || app).slice(0, 120), logo: String(t.logo || '').slice(0, 500), composioId: l.composioId, status: 'pending',
|
|
246
|
+
const c = await store.addAppConnection({ scopeType: s.type, scopeId: s.id, app, appName: String(t.name || app).slice(0, 120), logo: String(t.logo || '').slice(0, 500), composioId: l.composioId, status: 'pending', ...whoFrom(body, 'all'), createdBy: s.me.account })
|
|
205
247
|
return { url: l.url, connection: await view(c, s.levels[0]) }
|
|
206
248
|
}],
|
|
207
249
|
|
|
208
|
-
// Who may use it: 'all' (people and agents) or '
|
|
250
|
+
// Who may use it: 'all' (people and agents), 'people', or 'agents' with the ids of the agents chosen.
|
|
209
251
|
['PATCH', new RegExp(`^/v1/connections/${SCOPE}/([^/]+)/([^/]+)$`), async (req, body, [type, id, cid]) => {
|
|
210
252
|
const s = await scopeOf(req, type, id)
|
|
211
253
|
const c = await store.appConnectionById(needId(cid, 'connection'))
|
|
212
254
|
if (!c || c.scopeType !== s.type || c.scopeId !== s.id) throw new HttpError(404, 'no such connection')
|
|
213
255
|
if (!mayChange(s, c)) throw new HttpError(403, 'Only whoever connected it, or the codebase\'s owner, changes it.')
|
|
214
|
-
|
|
215
|
-
return view(await store.updateAppConnection(c.id, { who: body.who }), s.levels[0])
|
|
256
|
+
return view(await store.updateAppConnection(c.id, whoFrom(body)), s.levels[0])
|
|
216
257
|
}],
|
|
217
258
|
|
|
218
259
|
['DELETE', new RegExp(`^/v1/connections/${SCOPE}/([^/]+)/([^/]+)$`), async (req, body, [type, id, cid]) => {
|
|
@@ -267,7 +308,7 @@ export function connectionRoutes (ctx) {
|
|
|
267
308
|
const call = await store.addAppCall({ room, capKey: key, connectionId: pick.connection.id, app: t.app, tool: t.slug, args, readOnly: t.readOnly, state: 'waiting', account: me.account })
|
|
268
309
|
if (t.readOnly) return answer(await run(call, pick.connection))
|
|
269
310
|
const who = await nameOf(me.account)
|
|
270
|
-
await sayInRoom(room, { approval: call.id, text: `${who} asks to run ${t.slug} on ${pick.connection.appName || t.app} (${
|
|
311
|
+
await sayInRoom(room, { approval: call.id, text: `${who} asks to run ${t.slug} on ${pick.connection.appName || t.app} (${WORDS[pick.level.type].toLowerCase()} connection): ${argsLine(args)}. A person in the codebase approves or declines it here.` }).catch((err) => log(`connections: tell ${room}: ${err.message}`))
|
|
271
312
|
return answer(await waitFor(call.id) || call, pick.connection.appName)
|
|
272
313
|
}],
|
|
273
314
|
|
|
@@ -294,7 +335,7 @@ export function connectionRoutes (ctx) {
|
|
|
294
335
|
let ended = decided
|
|
295
336
|
if (allow) {
|
|
296
337
|
const c = call.connectionId ? await store.appConnectionById(call.connectionId) : null
|
|
297
|
-
const still = c && c.status === 'active' && (await usable(
|
|
338
|
+
const still = c && c.status === 'active' && (await usable(call.account.startsWith('person:') ? { kind: 'person' } : { kind: 'agent', agent: { id: call.account.slice('agent:'.length) } }, found)).some((x) => x.connection.id === c.id)
|
|
298
339
|
ended = still ? await run(decided, c) : (await store.updateAppCall(call.id, { state: 'failed', error: 'That connection was removed.', ranAt: now() }, { from: 'approved' })) || decided
|
|
299
340
|
}
|
|
300
341
|
const what = allow ? (ended.state === 'ran' ? 'ran it' : `it failed: ${String(ended.error || '').slice(0, 200)}`) : 'declined it'
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// A project's channel: one conversation for everyone in a project (a workspace), kept by the
|
|
2
|
+
// accounts API so people can talk with no codebase open. A codebase's own channel is its
|
|
3
|
+
// session's chat, on the relay; this is only the project's.
|
|
4
|
+
//
|
|
5
|
+
// Everyone who reaches the project reads and writes it: its people, and agents placed in it.
|
|
6
|
+
// Each account's place in it (what it has read) is kept, so the app can say how much is new.
|
|
7
|
+
import { HttpError, needId, stripInvisible } from '../http.js'
|
|
8
|
+
import { workspaceReach, canSeeFiles } from '../workspace-reach.js'
|
|
9
|
+
|
|
10
|
+
export const MAX_MESSAGE = 8000
|
|
11
|
+
const PAGE = 100
|
|
12
|
+
const PER_MINUTE = 30
|
|
13
|
+
|
|
14
|
+
export function workspaceChatRoutes (ctx) {
|
|
15
|
+
const { store, now = Date.now, workspaces = false } = ctx
|
|
16
|
+
const { reach } = workspaceReach(ctx)
|
|
17
|
+
const gated = (fn) => (...args) => {
|
|
18
|
+
if (!workspaces) throw new HttpError(404, 'not found')
|
|
19
|
+
return fn(...args)
|
|
20
|
+
}
|
|
21
|
+
const nameOf = async (account) => {
|
|
22
|
+
const [kind, id] = String(account || '').split(':')
|
|
23
|
+
const raw = kind === 'agent' ? (await store.agentById(id).catch(() => null))?.name : kind === 'person' ? (await store.profile(id))?.name : ''
|
|
24
|
+
return stripInvisible(raw || '').join('').trim()
|
|
25
|
+
}
|
|
26
|
+
const view = (m, me) => ({ id: m.id, by: m.name || 'Someone', kind: String(m.account).startsWith('agent:') ? 'agent' : 'person', mine: m.account === me, text: m.text, at: m.createdAt })
|
|
27
|
+
|
|
28
|
+
/** The project, for someone who is in it: an org member who only sees its page (Workspaces: Read alone) is not. */
|
|
29
|
+
async function inProject (req, id) {
|
|
30
|
+
const r = await reach(req, needId(id, 'project'))
|
|
31
|
+
if (!canSeeFiles(r.access)) throw new HttpError(403, 'Only people in this project read its channel.')
|
|
32
|
+
return r
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// How fast one account may write here, counted in this process: a channel is for people talking.
|
|
36
|
+
const recent = new Map()
|
|
37
|
+
function limit (account) {
|
|
38
|
+
const at = now()
|
|
39
|
+
const list = (recent.get(account) || []).filter((t) => at - t < 60_000)
|
|
40
|
+
if (list.length >= PER_MINUTE) throw new HttpError(429, 'That is a lot of messages in a minute. Wait a moment.')
|
|
41
|
+
list.push(at); recent.set(account, list)
|
|
42
|
+
if (recent.size > 5000) for (const [k, v] of recent) if (!v.some((t) => at - t < 60_000)) recent.delete(k)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return [
|
|
46
|
+
// The channel's messages, oldest first: the newest page, or what came after `after` (a time in ms).
|
|
47
|
+
// `unread`: how many others wrote since the caller last read it; `readAt`: when that was.
|
|
48
|
+
['GET', /^\/v1\/workspaces\/([^/]+)\/messages$/, gated(async (req, body, [id], url) => {
|
|
49
|
+
const { me, ws } = await inProject(req, id)
|
|
50
|
+
const u = url || new URL(req.url, 'http://x')
|
|
51
|
+
const after = Number(u.searchParams.get('after')) || 0
|
|
52
|
+
const messages = await store.listWorkspaceMessages(ws.id, { after, limit: PAGE })
|
|
53
|
+
const readAt = await store.workspaceReadAt(ws.id, me.account)
|
|
54
|
+
return { messages: messages.map((m) => view(m, me.account)), readAt, unread: await store.countWorkspaceMessages(ws.id, { after: readAt, notBy: me.account }) }
|
|
55
|
+
})],
|
|
56
|
+
|
|
57
|
+
['POST', /^\/v1\/workspaces\/([^/]+)\/messages$/, gated(async (req, body, [id]) => {
|
|
58
|
+
const { me, ws } = await inProject(req, id)
|
|
59
|
+
const text = String(body.text || '').replace(/\r\n/g, '\n').trim()
|
|
60
|
+
if (!text) throw new HttpError(400, 'Say something.')
|
|
61
|
+
if (text.length > MAX_MESSAGE) throw new HttpError(413, 'That message is too long.')
|
|
62
|
+
limit(me.account)
|
|
63
|
+
const m = await store.addWorkspaceMessage({ workspaceId: ws.id, account: me.account, name: await nameOf(me.account), text })
|
|
64
|
+
// Whoever writes has read up to here.
|
|
65
|
+
await store.setWorkspaceReadAt(ws.id, me.account, m.createdAt)
|
|
66
|
+
return { message: view(m, me.account) }
|
|
67
|
+
})],
|
|
68
|
+
|
|
69
|
+
// The caller has read the channel up to now.
|
|
70
|
+
['POST', /^\/v1\/workspaces\/([^/]+)\/messages\/read$/, gated(async (req, body, [id]) => {
|
|
71
|
+
const { me, ws } = await inProject(req, id)
|
|
72
|
+
const at = now()
|
|
73
|
+
await store.setWorkspaceReadAt(ws.id, me.account, at)
|
|
74
|
+
return { readAt: at }
|
|
75
|
+
})]
|
|
76
|
+
]
|
|
77
|
+
}
|
|
@@ -83,6 +83,8 @@ export function workspaceRoutes (ctx) {
|
|
|
83
83
|
access: access.access,
|
|
84
84
|
admin: access.admin,
|
|
85
85
|
via: access.via,
|
|
86
|
+
// The codebases in it, so an app knows which of the folders on its computer belong here.
|
|
87
|
+
rooms: sessions.map((s) => s.room),
|
|
86
88
|
// files: the row's count, kept by every upload, delete and sweep (setWorkspaceUsage).
|
|
87
89
|
counts: { sessions: sessions.length, members: members.length, open: sessions.filter((s) => isOpen(s, t)).length, files: ws.fileCount ?? 0 }
|
|
88
90
|
}
|
package/src/api/server.js
CHANGED
|
@@ -36,6 +36,7 @@ import { workspaceRoutes } from './routes/workspaces.js'
|
|
|
36
36
|
import { workspaceFileRoutes } from './routes/workspace-files.js'
|
|
37
37
|
import { workspaceAgentRoutes } from './routes/workspace-agents.js'
|
|
38
38
|
import { workspaceInviteRoutes } from './routes/workspace-invites.js'
|
|
39
|
+
import { workspaceChatRoutes } from './routes/workspace-chat.js'
|
|
39
40
|
import { HOSTED_RELAY } from '../settings.js'
|
|
40
41
|
import { roomAccessFrom } from './access.js'
|
|
41
42
|
import { joiningRoom, sessionArg } from '../mcp-room.js'
|
|
@@ -449,7 +450,7 @@ export function startApi ({ port = 0, host = '127.0.0.1', store, verifyUser, sit
|
|
|
449
450
|
// Always routed: with the flag off each answers a plain 404 of its own, so the app's
|
|
450
451
|
// check at every launch isn't filed as a missing route.
|
|
451
452
|
// Only these take a hosted agent's pass (workspaceReach), so they alone get the pass key.
|
|
452
|
-
routes.push(...workspaceRoutes({ ...ctx, workspaces, passKey, policyChanged }), ...workspaceInviteRoutes({ ...ctx, workspaces, passKey }), ...workspaceAgentRoutes({ ...ctx, workspaces, passKey, relayUrl, webhookFetch, webhookLookup, allowLocalWebhooks, trackDelivery, limitAnnounce }))
|
|
453
|
+
routes.push(...workspaceRoutes({ ...ctx, workspaces, passKey, policyChanged }), ...workspaceInviteRoutes({ ...ctx, workspaces, passKey }), ...workspaceChatRoutes({ ...ctx, workspaces, passKey }), ...workspaceAgentRoutes({ ...ctx, workspaces, passKey, relayUrl, webhookFetch, webhookLookup, allowLocalWebhooks, trackDelivery, limitAnnounce }))
|
|
453
454
|
const wsFiles = workspaceFileRoutes({ ...ctx, workspaces, passKey })
|
|
454
455
|
routes.push(...wsFiles.routes)
|
|
455
456
|
// Secrets (routes/secrets.js): off until the vault is set up (QUILT_VAULT_SECRET).
|
|
@@ -52,7 +52,8 @@ const SECRET_RUN = 'id, token_hash, room, account, kind, label, created_at, expi
|
|
|
52
52
|
const SECRET_ASK = 'run_id, secret_id, name, state, asked_at, answered_at'
|
|
53
53
|
const SECRET_USE = 'id, secret_id, run_id, room, account, upstream, at'
|
|
54
54
|
// App connections (20261112000000_app_connections.sql).
|
|
55
|
-
const
|
|
55
|
+
const WORKSPACE_MESSAGE = 'id, workspace_id, account, name, text, created_at'
|
|
56
|
+
const APP_CONNECTION = 'id, scope_type, scope_id, app, app_name, logo, composio_id, status, who, agents, created_by, created_at, updated_at'
|
|
56
57
|
const APP_CALL = 'id, room, cap_key, connection_id, app, tool, args, read_only, state, account, decided_by, result, error, created_at, decided_at, ran_at'
|
|
57
58
|
// How Quilt wakes each agent (20261025000000_agent_wake.sql).
|
|
58
59
|
const AGENT_WAKE = 'agent_id, method, detail, pending, updated_at'
|
|
@@ -503,6 +504,29 @@ export function createSupabaseStore ({ url, serviceKey, client, fetch: authFetch
|
|
|
503
504
|
.insert({ workspace_id: workspaceId, email, account, account_name: accountName, access, invited_by: invitedBy, expires_at: ts(expiresAt) })
|
|
504
505
|
.select(WORKSPACE_INVITE).single()))
|
|
505
506
|
},
|
|
507
|
+
// A project's channel (20261122010000_project_channel.sql).
|
|
508
|
+
async addWorkspaceMessage ({ workspaceId, account, name = '', text }) {
|
|
509
|
+
return rowFrom(await one(db.from('workspace_messages').insert({ workspace_id: workspaceId, account, name, text }).select(WORKSPACE_MESSAGE).single()))
|
|
510
|
+
},
|
|
511
|
+
async listWorkspaceMessages (workspaceId, { after = 0, limit = 100 } = {}) {
|
|
512
|
+
const q = db.from('workspace_messages').select(WORKSPACE_MESSAGE).eq('workspace_id', workspaceId)
|
|
513
|
+
// What came after a time, oldest first; with no time, the newest page (read back into the order it was written in).
|
|
514
|
+
if (after) return (await one(q.gt('created_at', ts(after)).order('created_at').limit(limit))).map(rowFrom)
|
|
515
|
+
return (await one(q.order('created_at', { ascending: false }).limit(limit))).map(rowFrom).reverse()
|
|
516
|
+
},
|
|
517
|
+
async countWorkspaceMessages (workspaceId, { after = 0, notBy = '' } = {}) {
|
|
518
|
+
const { count, error } = await db.from('workspace_messages').select('id', { count: 'exact', head: true }).eq('workspace_id', workspaceId).gt('created_at', ts(after)).neq('account', notBy)
|
|
519
|
+
if (error) throw error
|
|
520
|
+
return count || 0
|
|
521
|
+
},
|
|
522
|
+
async workspaceReadAt (workspaceId, account) {
|
|
523
|
+
const row = await one(db.from('workspace_message_reads').select('read_at').eq('workspace_id', workspaceId).eq('account', account).maybeSingle())
|
|
524
|
+
return row ? ms(row.read_at) : 0
|
|
525
|
+
},
|
|
526
|
+
async setWorkspaceReadAt (workspaceId, account, at) {
|
|
527
|
+
await one(db.from('workspace_message_reads').upsert({ workspace_id: workspaceId, account, read_at: ts(at) }, { onConflict: 'workspace_id,account' }))
|
|
528
|
+
},
|
|
529
|
+
|
|
506
530
|
async listWorkspaceInvites (workspaceId) {
|
|
507
531
|
return (await one(db.from('workspace_invites').select(WORKSPACE_INVITE).eq('workspace_id', workspaceId).order('created_at', { ascending: false }).limit(50))).map(rowFrom)
|
|
508
532
|
},
|
package/src/app-tools.js
CHANGED
|
@@ -38,13 +38,13 @@ export const APP_INPUTS = {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const LEVEL = { session: 'this codebase', workspace: 'the project', org: 'the team' }
|
|
41
|
+
const LEVEL = { session: 'this codebase', workspace: 'the project', org: 'the team', account: 'every project of its owner' }
|
|
42
42
|
|
|
43
43
|
/** quilt_apps' answer. */
|
|
44
44
|
export function describeApps (b) {
|
|
45
45
|
if (!b.apps || !b.apps.length) return 'No apps are connected for this codebase yet. A person connects one in Codebase settings → Connections (or for the whole project or team), and then you can use it here.'
|
|
46
46
|
const lines = ['Apps you can use here (quilt_app_tools finds an action, quilt_app_call runs it):']
|
|
47
|
-
for (const a of b.apps) lines.push(`- ${a.name} (app: "${a.app}", connection: "${a.id}") — connected for ${LEVEL[a.level] || a.level}${a.levelName ? ` (${a.levelName})` : ''} by ${a.by}${a.who === 'people' ? '; people and their own AIs only' : ''}`)
|
|
47
|
+
for (const a of b.apps) lines.push(`- ${a.name} (app: "${a.app}", connection: "${a.id}") — connected for ${LEVEL[a.level] || a.level}${a.levelName ? ` (${a.levelName})` : ''} by ${a.by}${a.who === 'people' ? '; people and their own AIs only' : a.who === 'agents' ? '; for the agents chosen for it only' : ''}`)
|
|
48
48
|
lines.push('', `Actions that only read run at once; anything else waits for a person to approve it in the codebase's chat. At most ${b.callsPerDay} app calls a day.`)
|
|
49
49
|
return lines.join('\n')
|
|
50
50
|
}
|
package/src/app-workspaces.js
CHANGED
|
@@ -2,3 +2,24 @@
|
|
|
2
2
|
// app, its agents' workspace tools and `quilt workspace` act as if the accounts API had them off,
|
|
3
3
|
// whatever the API says. QUILT_APP_WORKSPACES=1 brings them back (tests, and when they return).
|
|
4
4
|
export const appWorkspaces = (env = process.env) => /^(1|true)$/i.test(env.QUILT_APP_WORKSPACES || '')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The folders on this computer whose codebase is in a project the folder doesn't know about:
|
|
8
|
+
* someone who joined a project's codebase with an invite, or whose partner moved it into a
|
|
9
|
+
* project, has no project in the folder's own settings. `workspaces`: the account's projects as
|
|
10
|
+
* the API lists them (each with its `rooms`); `folders`: [{ dir, room, workspace }]. Returns
|
|
11
|
+
* [{ dir, workspace }] to save. A folder whose room no listed project has is left as it is.
|
|
12
|
+
*/
|
|
13
|
+
export function projectsToLearn (workspaces = [], folders = []) {
|
|
14
|
+
const of = new Map()
|
|
15
|
+
for (const w of workspaces) for (const room of (w && w.rooms) || []) if (!of.has(room)) of.set(room, w.id)
|
|
16
|
+
const out = []
|
|
17
|
+
const seen = new Set()
|
|
18
|
+
for (const f of folders) {
|
|
19
|
+
const id = f && f.room ? of.get(f.room) : ''
|
|
20
|
+
if (!id || f.workspace === id || seen.has(f.dir)) continue
|
|
21
|
+
seen.add(f.dir)
|
|
22
|
+
out.push({ dir: f.dir, workspace: id })
|
|
23
|
+
}
|
|
24
|
+
return out
|
|
25
|
+
}
|
package/src/ui/app.css
CHANGED
|
@@ -1694,7 +1694,9 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1694
1694
|
.pj-app .toggle { grid-area: 1 / 2; align-self: start; }
|
|
1695
1695
|
.pj-app b { grid-area: 3 / 1 / 4 / 3; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1696
1696
|
.pj-app .hint { grid-area: 4 / 1 / 5 / 3; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1697
|
-
.pj-app .
|
|
1697
|
+
.pj-app .pj-pills { grid-area: 5 / 1 / 6 / 3; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; min-width: 0; }
|
|
1698
|
+
.pj-app .pj-pills:empty { display: none; }
|
|
1699
|
+
.pj-app .pj-pills .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1698
1700
|
.pj-slot { display: flex; align-items: center; justify-content: center; gap: 8px; border: 1.5px dashed var(--border-strong); background: none; color: var(--muted); font: 500 13px var(--sans); cursor: pointer; }
|
|
1699
1701
|
.pj-slot:hover { color: var(--text); border-color: var(--muted); }
|
|
1700
1702
|
.pj-slot svg { width: 15px; height: 15px; }
|
|
@@ -1763,14 +1765,20 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1763
1765
|
.ws.pj-cb[data-side-page="chat"] .ws-chat { display: flex; }
|
|
1764
1766
|
.ws.pj-cb:is([data-side-page="connections"], [data-side-page="artifacts"]) :is(#main, #mainbar) { display: none; }
|
|
1765
1767
|
.ws.pj-cb .ws-main > .pj-pmain { flex: 1; }
|
|
1766
|
-
/* a call
|
|
1767
|
-
.ws.pj-cb
|
|
1768
|
-
.ws.pj-cb[data-side
|
|
1769
|
-
.ws.pj-cb
|
|
1768
|
+
/* a call is in the channel: a screen someone shares there sits in the middle, the channel beside it */
|
|
1769
|
+
.ws.pj-cb[data-side-page="chat"]:has(#screen-stage:not([hidden])) .ws-main { display: flex; }
|
|
1770
|
+
.ws.pj-cb[data-side-page="chat"] .ws-body:has(#screen-stage:not([hidden])) { grid-template-columns: 244px minmax(0, 1fr) 380px; }
|
|
1771
|
+
.ws.pj-cb[data-side="shut"][data-side-page="chat"] .ws-body:has(#screen-stage:not([hidden])) { grid-template-columns: minmax(0, 1fr) 380px; }
|
|
1772
|
+
.ws.pj-cb[data-side-page="chat"] .ws-body:has(#screen-stage:not([hidden])) .ws-chat { border-left: 1px solid var(--border); }
|
|
1773
|
+
/* a call going on shows on its channel's row */
|
|
1774
|
+
.pj-side .pj-call { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; color: var(--ok); }
|
|
1775
|
+
.pj-side .pj-call svg { width: 13px; height: 13px; color: inherit; }
|
|
1770
1776
|
@media (max-width: 900px) {
|
|
1771
|
-
.ws.pj-cb .ws-body
|
|
1777
|
+
.ws.pj-cb .ws-body { grid-template-columns: minmax(0, 1fr); }
|
|
1772
1778
|
.ws.pj-cb .pj-side { position: absolute; top: 0; bottom: 0; left: 0; z-index: 5; width: min(244px, 80vw); max-height: none; border-right: 1px solid var(--border); border-bottom: 0; box-shadow: var(--shadow-pop); }
|
|
1773
|
-
|
|
1779
|
+
/* too narrow for both: the screen takes the page, and Hide puts the channel back */
|
|
1780
|
+
.ws.pj-cb[data-side-page="chat"] .ws-body:has(#screen-stage:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
|
|
1781
|
+
.ws.pj-cb[data-side-page="chat"] .ws-body:has(#screen-stage:not([hidden])) .ws-chat { display: none; }
|
|
1774
1782
|
}
|
|
1775
1783
|
|
|
1776
1784
|
/* ---- Artifacts (files.js artifactsHtml): tiles across the page; an open artifact takes the page
|
|
@@ -1827,6 +1835,15 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1827
1835
|
.pj-preview .hint { margin: 8px 0 0; }
|
|
1828
1836
|
@media (max-width: 760px) { .pj-add-row { flex-direction: column; } .pj-preview { grid-template-columns: minmax(0, 1fr); } }
|
|
1829
1837
|
|
|
1838
|
+
/* A project's channel: the chat a codebase has, across the page. */
|
|
1839
|
+
.pj-pmain.pj-chat { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
|
|
1840
|
+
.pj-chanpage, .pj-chan { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
|
1841
|
+
.pj-chan .files-head { flex: none; margin: 0; padding: 16px 24px 12px; border-bottom: 1px solid var(--border); }
|
|
1842
|
+
.pj-chan .files-head .pj-hash { margin-right: 6px; color: var(--muted); }
|
|
1843
|
+
.pj-chan .messages { padding: 18px 24px; }
|
|
1844
|
+
.pj-chan .composer { flex: none; padding: 12px 24px 20px; }
|
|
1845
|
+
.pj-rooms button .avatar { width: 18px; height: 18px; font-size: 9px; flex: none; }
|
|
1846
|
+
|
|
1830
1847
|
/* A project's task board: the board a codebase has, with a row of chips to narrow it to one codebase and each card wearing its codebase. */
|
|
1831
1848
|
.pj-pmain.pj-tasks { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 24px; }
|
|
1832
1849
|
.pj-board { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
|
|
@@ -3037,6 +3054,9 @@ label.radio:has(input:disabled) { cursor: default; opacity: .75; }
|
|
|
3037
3054
|
.cn-state { font-size: 11.5px; font-weight: 600; color: var(--warn); white-space: nowrap; } .cn-state.failed { color: var(--bad); }
|
|
3038
3055
|
.cn-foot { display: flex; align-items: center; gap: 8px; } .cn-foot .spacer { flex: 1; }
|
|
3039
3056
|
.cn-confirm { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
|
|
3057
|
+
.cn-agents { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 10px; border-top: 1px solid var(--border); }
|
|
3058
|
+
.cn-agent { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
|
|
3059
|
+
.cn-agents .hint { flex-basis: 100%; }
|
|
3040
3060
|
.cn-apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
|
|
3041
3061
|
.cn-app { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); min-width: 0; }
|
|
3042
3062
|
.cn-app b { flex: 1; min-width: 0; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
package/src/ui/connections.js
CHANGED
|
@@ -2,13 +2,28 @@
|
|
|
2
2
|
// button): apps people connect for a session, workspace or team through Composio, which keeps the
|
|
3
3
|
// sign-ins (plans/app-connections.md). Agents use them with quilt_apps / quilt_app_tools /
|
|
4
4
|
// quilt_app_call. Also the approval card an app action waiting for a person draws in the chat.
|
|
5
|
+
// A person's own connections ({ type: 'account', id: 'me' }) are for every project of theirs. A
|
|
6
|
+
// connection is for people and agents, for people only, or for the agents chosen for it.
|
|
5
7
|
import { api, esc, toast, ago, I } from './common.js'
|
|
6
8
|
|
|
7
9
|
const SEARCH_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>'
|
|
8
10
|
|
|
9
11
|
const views = new Map() // `${type}:${id}` -> the last view, so a redraw shows it at once
|
|
10
12
|
const urlOf = (type, id, rest = '') => `/api/connections/${type}/${encodeURIComponent(id)}${rest}`
|
|
11
|
-
const LEVEL = { session: 'this codebase', workspace: 'the project', org: 'the team' }
|
|
13
|
+
const LEVEL = { session: 'this codebase', workspace: 'the project', org: 'the team', account: 'every project of yours' }
|
|
14
|
+
const FROM = { ...LEVEL, account: 'every project' }
|
|
15
|
+
|
|
16
|
+
// Your agents, asked once: who a connection can be for. A page that knows more (a project's agents) hands them in.
|
|
17
|
+
let mine = null
|
|
18
|
+
const yourAgents = () => (mine ||= api('GET', '/api/agents').then((r) => (r.agents || []).map((a) => ({ id: a.id, name: a.name })), () => []))
|
|
19
|
+
|
|
20
|
+
/** Who a connection is for, in a few words. `names`: agent id -> name. */
|
|
21
|
+
export function whoWords (c, names = new Map()) {
|
|
22
|
+
if (c.who === 'people') return 'People only'
|
|
23
|
+
if (c.who !== 'agents') return 'People and agents'
|
|
24
|
+
const list = (c.agents || []).map((id) => names.get(id) || 'an agent')
|
|
25
|
+
return `Only ${list.length > 3 ? `${list.slice(0, 3).join(', ')} and ${list.length - 3} more` : list.join(', ')}`
|
|
26
|
+
}
|
|
12
27
|
const STATUS = { active: 'Connected', pending: 'Waiting for sign-in', failed: 'Didn\'t connect' }
|
|
13
28
|
const SHOWN = 12
|
|
14
29
|
|
|
@@ -18,10 +33,13 @@ const logoHtml = (a) => a.logo
|
|
|
18
33
|
|
|
19
34
|
/**
|
|
20
35
|
* Draws the card into `root` for one scope ({ type, id }: a session's room, a workspace's id, a
|
|
21
|
-
* team's slug).
|
|
36
|
+
* team's slug, or 'account' with 'me'). `agents()`: more agents a connection here can be for
|
|
37
|
+
* ([{ id, name }]: a project's), besides your own. Answers { refresh, destroy }.
|
|
22
38
|
*/
|
|
23
|
-
export function mountConnections (root, { type, id }) {
|
|
24
|
-
const ui = { search: '', apps: null, appsFor: null, more: false, busy: '', error: '', calls: null, confirm: null }
|
|
39
|
+
export function mountConnections (root, { type, id, agents = () => [] }) {
|
|
40
|
+
const ui = { search: '', apps: null, appsFor: null, more: false, busy: '', error: '', calls: null, confirm: null, choosing: null, yours: [] }
|
|
41
|
+
/** The agents a connection here can be for, once each. */
|
|
42
|
+
const choices = () => { const seen = new Map(); for (const a of [...agents(), ...ui.yours]) if (a && a.id && !seen.has(a.id)) seen.set(a.id, a.name || 'an agent'); return seen }
|
|
25
43
|
let view = views.get(`${type}:${id}`) || null
|
|
26
44
|
let alive = true
|
|
27
45
|
let poll = null
|
|
@@ -29,17 +47,26 @@ export function mountConnections (root, { type, id }) {
|
|
|
29
47
|
|
|
30
48
|
function connectedHtml (c, own) {
|
|
31
49
|
const status = c.status === 'active' ? '' : `<span class="cn-state ${esc(c.status)}">${esc(STATUS[c.status] || c.status)}</span>`
|
|
50
|
+
const names = choices()
|
|
51
|
+
// Chosen agents: the ones it is for are ticked; a tick saves at once, and at least one stays ticked.
|
|
52
|
+
const picking = own && c.mayChange && c.status === 'active' && (c.who === 'agents' || ui.choosing === c.id)
|
|
53
|
+
const value = picking ? 'agents' : c.who
|
|
32
54
|
const who = own && c.mayChange && c.status === 'active'
|
|
33
|
-
? `<select class="input sm" data-who="${esc(c.id)}" aria-label="Who may use ${esc(c.name)}"><option value="all"${
|
|
34
|
-
: `<span class="hint">${c
|
|
55
|
+
? `<select class="input sm" data-who="${esc(c.id)}" aria-label="Who may use ${esc(c.name)}"><option value="all"${value === 'all' ? ' selected' : ''}>People and agents</option><option value="agents"${value === 'agents' ? ' selected' : ''}>People and chosen agents</option><option value="people"${value === 'people' ? ' selected' : ''}>People only</option></select>`
|
|
56
|
+
: `<span class="hint">${esc(whoWords(c, names))}</span>`
|
|
57
|
+
const chosen = new Set(c.who === 'agents' ? c.agents || [] : [])
|
|
58
|
+
for (const a of chosen) if (!names.has(a)) names.set(a, 'an agent')
|
|
59
|
+
const pick = !picking ? '' : `<div class="cn-agents" role="group" aria-label="The agents that may use ${esc(c.name)}">${names.size
|
|
60
|
+
? [...names].map(([aid, name]) => `<label class="cn-agent"><input type="checkbox" data-agent-of="${esc(c.id)}" value="${esc(aid)}"${chosen.has(aid) ? ' checked' : ''}><span>${esc(name)}</span></label>`).join('')
|
|
61
|
+
: '<span class="hint">You have no agents yet.</span>'}${chosen.size ? '' : '<span class="hint">Tick the agents that may use it. Until then it stays as it was.</span>'}</div>`
|
|
35
62
|
const remove = own && c.mayChange
|
|
36
63
|
? (ui.confirm === c.id
|
|
37
64
|
? `<span class="cn-confirm">Remove ${esc(c.name)}? <button class="btn sm danger" data-remove="${esc(c.id)}">Remove</button><button class="btn sm ghost" data-cancel>Keep</button></span>`
|
|
38
65
|
: `<button class="btn sm ghost icon" data-ask-remove="${esc(c.id)}" title="Remove ${esc(c.name)}" aria-label="Remove ${esc(c.name)}">${I.trash}</button>`)
|
|
39
66
|
: ''
|
|
40
67
|
return `<div class="cn-card${c.status === 'active' ? '' : ' off'}">
|
|
41
|
-
<div class="cn-top">${logoHtml(c)}<div class="cn-what"><b>${esc(c.name)}</b><small>${own ? `${c.status === 'active' ? 'Connected' : 'Started'} by ${esc(c.by)} · ${esc(ago(c.createdAt))}` : `From ${esc(
|
|
42
|
-
<div class="cn-foot">${who}<span class="spacer"></span>${remove}</div
|
|
68
|
+
<div class="cn-top">${logoHtml(c)}<div class="cn-what"><b>${esc(c.name)}</b><small>${own ? `${c.status === 'active' ? 'Connected' : 'Started'} by ${esc(c.by)} · ${esc(ago(c.createdAt))}` : `From ${esc(FROM[c.level] || c.level)}${c.levelName ? ` (${esc(c.levelName)})` : ''} · by ${esc(c.by)}`}</small></div>${status}</div>
|
|
69
|
+
<div class="cn-foot">${who}<span class="spacer"></span>${remove}</div>${pick}</div>`
|
|
43
70
|
}
|
|
44
71
|
|
|
45
72
|
function appHtml (a, connected) {
|
|
@@ -76,6 +103,8 @@ export function mountConnections (root, { type, id }) {
|
|
|
76
103
|
if (had) { const s = root.querySelector('[data-search]'); s.focus(); s.setSelectionRange(s.value.length, s.value.length) }
|
|
77
104
|
}
|
|
78
105
|
|
|
106
|
+
yourAgents().then((list) => { ui.yours = list; if (alive && view) draw() })
|
|
107
|
+
|
|
79
108
|
async function load () {
|
|
80
109
|
try {
|
|
81
110
|
view = await api('GET', urlOf(type, id))
|
|
@@ -110,8 +139,19 @@ export function mountConnections (root, { type, id }) {
|
|
|
110
139
|
})
|
|
111
140
|
|
|
112
141
|
root.addEventListener('change', async (e) => {
|
|
142
|
+
const box = e.target.closest('[data-agent-of]')
|
|
143
|
+
if (box) {
|
|
144
|
+
const cid = box.dataset.agentOf
|
|
145
|
+
const ids = [...root.querySelectorAll(`[data-agent-of="${cid}"]:checked`)].map((b) => b.value)
|
|
146
|
+
if (!ids.length) { box.checked = true; return toast('At least one agent: or pick People only.') }
|
|
147
|
+
try { await api('PATCH', urlOf(type, id, `/${cid}`), { who: 'agents', agents: ids }); ui.choosing = null; load() } catch (err) { toast(err.message); load() }
|
|
148
|
+
return
|
|
149
|
+
}
|
|
113
150
|
const sel = e.target.closest('[data-who]')
|
|
114
151
|
if (!sel) return
|
|
152
|
+
// Chosen agents is saved with the first agent ticked, never as an empty list.
|
|
153
|
+
if (sel.value === 'agents') { ui.choosing = sel.dataset.who; return draw() }
|
|
154
|
+
ui.choosing = null
|
|
115
155
|
try { await api('PATCH', urlOf(type, id, `/${sel.dataset.who}`), { who: sel.value }); load() } catch (err) { toast(err.message); load() }
|
|
116
156
|
})
|
|
117
157
|
|