heyquilt 0.3.193 → 0.3.195
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 +19 -6
- package/src/api/memory-store.js +31 -0
- package/src/api/routes/workspace-chat.js +75 -3
- package/src/api/supabase-store.js +36 -0
- package/src/ui/app.css +8 -6
- package/src/ui/app.js +1 -1
- package/src/ui/project-channel.js +73 -23
- package/src/ui/projects.js +80 -21
- package/src/ui/session.js +40 -6
- package/src/ui-server.js +12 -2
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.195 — 2026-11-23
|
|
15
|
+
|
|
16
|
+
- **A project's channels inside a codebase.** A codebase's sidebar lists its project's channels after its own, with the plus to make one, and what is new in each. A channel opens on the codebase's page, so you stay where you are.
|
|
17
|
+
- **Hide sidebar is a row at the bottom of the sidebar**, under Team and Invite, in place of the button over its first row.
|
|
18
|
+
- **Fixed: a new, empty channel kept saying "Loading".**
|
|
19
|
+
|
|
20
|
+
## 0.3.194 — 2026-11-23
|
|
21
|
+
|
|
22
|
+
- **Make channels in a project.** A plus beside Channels in a project's sidebar: name the channel in the list and press Enter. Everyone in the project and its agents can read and write it, as with the project's own channel, and its row says how much is new. Anyone who can change the project can make one.
|
|
23
|
+
|
|
14
24
|
## 0.3.193 — 2026-11-23
|
|
15
25
|
|
|
16
26
|
- **The Connections page, redrawn.** A project's and a codebase's Connections page (and the Connections cards in the pop-ups) show what is connected as the same tiles as a project's Overview: the app's logo, who connected it, where it is from, and who may use it. "Connect an app" opens the apps to pick from in the page, with the search across it. With nothing connected yet, the apps are there to pick from straight away.
|
package/package.json
CHANGED
package/src/account.js
CHANGED
|
@@ -351,18 +351,31 @@ export async function moveSessionToWorkspace ({ token, id, room, api = apiUrl(),
|
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
// A project's channel (routes/workspace-chat.js): its messages, saying something, and marking it read.
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
// `channel`: one of the channels people made in the project, by its id; none is the project's own.
|
|
355
|
+
const chan$ = (channel) => (channel ? `/channels/${encodeURIComponent(channel)}` : '')
|
|
356
|
+
export async function workspaceMessages ({ token, id, channel = '', after = 0, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
357
|
+
const r = await call(fetchImpl, api, 'GET', `${ws$(id)}${chan$(channel)}/messages${after ? `?after=${encodeURIComponent(after)}` : ''}`, null, token)
|
|
356
358
|
if (!Array.isArray(r.messages)) throw new Error(BAD_REPLY)
|
|
357
359
|
return r
|
|
358
360
|
}
|
|
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
|
+
export async function sayInWorkspace ({ token, id, channel = '', text, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
362
|
+
const r = await call(fetchImpl, api, 'POST', `${ws$(id)}${chan$(channel)}/messages`, { text }, token)
|
|
361
363
|
if (!r.message) throw new Error(BAD_REPLY)
|
|
362
364
|
return r
|
|
363
365
|
}
|
|
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
|
+
export async function readWorkspaceMessages ({ token, id, channel = '', api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
367
|
+
return call(fetchImpl, api, 'POST', `${ws$(id)}${chan$(channel)}/messages/read`, {}, token)
|
|
368
|
+
}
|
|
369
|
+
// The channels people made in a project: listing them, making one.
|
|
370
|
+
export async function workspaceChannels ({ token, id, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
371
|
+
const r = await call(fetchImpl, api, 'GET', `${ws$(id)}/channels`, null, token)
|
|
372
|
+
if (!Array.isArray(r.channels)) throw new Error(BAD_REPLY)
|
|
373
|
+
return r
|
|
374
|
+
}
|
|
375
|
+
export async function addWorkspaceChannel ({ token, id, name, api = apiUrl(), fetch: fetchImpl = globalThis.fetch }) {
|
|
376
|
+
const r = await call(fetchImpl, api, 'POST', `${ws$(id)}/channels`, { name }, token)
|
|
377
|
+
if (!r.channel) throw new Error(BAD_REPLY)
|
|
378
|
+
return r
|
|
366
379
|
}
|
|
367
380
|
|
|
368
381
|
// Workspace invites: an admin invites a person ({ account } or { email }); they accept in their Quilt.
|
package/src/api/memory-store.js
CHANGED
|
@@ -64,6 +64,7 @@ export function createMemoryStore ({ now = Date.now } = {}) {
|
|
|
64
64
|
// App connections (20261112000000_app_connections.sql).
|
|
65
65
|
const appConnections = new Map(); const appCalls = new Map()
|
|
66
66
|
const workspaceMessages = new Map(); const workspaceReads = new Map() // a project's channel, and each account's place in it
|
|
67
|
+
const workspaceChannels = new Map(); const channelMessages = new Map(); const channelReads = new Map() // the channels people made in a project, their messages, each account's place
|
|
67
68
|
const scopeKey = (scopeType, scopeId) => `${scopeType}\n${scopeId}`
|
|
68
69
|
// A secret as the API's routes see it: never its sealed value (secretSealed reads that, for the vault).
|
|
69
70
|
const secretMeta = (r) => { if (!r) return null; const { sealedValue, ...rest } = copy(r); return rest }
|
|
@@ -993,6 +994,12 @@ export function createMemoryStore ({ now = Date.now } = {}) {
|
|
|
993
994
|
for (const [k, i] of workspaceInvites) if (i.workspaceId === id) workspaceInvites.delete(k)
|
|
994
995
|
for (const [k, m] of workspaceMessages) if (m.workspaceId === id) workspaceMessages.delete(k)
|
|
995
996
|
for (const k of [...workspaceReads.keys()]) if (k.startsWith(`${id}|`)) workspaceReads.delete(k)
|
|
997
|
+
for (const [cid, c] of workspaceChannels) {
|
|
998
|
+
if (c.workspaceId !== id) continue
|
|
999
|
+
workspaceChannels.delete(cid)
|
|
1000
|
+
for (const [k, m] of channelMessages) if (m.channelId === cid) channelMessages.delete(k)
|
|
1001
|
+
for (const k of [...channelReads.keys()]) if (k.startsWith(`${cid}|`)) channelReads.delete(k)
|
|
1002
|
+
}
|
|
996
1003
|
for (const [k, f] of workspaceFiles) {
|
|
997
1004
|
if (f.workspaceId !== id) continue
|
|
998
1005
|
for (const vk of [...workspaceFileVersions.keys()]) if (vk.startsWith(`${f.id}\n`)) workspaceFileVersions.delete(vk)
|
|
@@ -1336,6 +1343,30 @@ export function createMemoryStore ({ now = Date.now } = {}) {
|
|
|
1336
1343
|
async workspaceReadAt (workspaceId, account) { return workspaceReads.get(`${workspaceId}|${account}`) || 0 },
|
|
1337
1344
|
async setWorkspaceReadAt (workspaceId, account, at) { workspaceReads.set(`${workspaceId}|${account}`, Math.max(at, workspaceReads.get(`${workspaceId}|${account}`) || 0)) },
|
|
1338
1345
|
|
|
1346
|
+
// More channels in a project (20261123010000_project_channels.sql).
|
|
1347
|
+
async listWorkspaceChannels (workspaceId) { return all(workspaceChannels, (c) => c.workspaceId === workspaceId).sort((a, b) => a.createdAt - b.createdAt).map(copy) },
|
|
1348
|
+
async addWorkspaceChannel ({ workspaceId, name, createdBy = '' }) {
|
|
1349
|
+
if (!workspaces.has(workspaceId)) throw fkViolation('workspace', 'does not exist')
|
|
1350
|
+
if (all(workspaceChannels, (c) => c.workspaceId === workspaceId && c.name.toLowerCase() === name.toLowerCase()).length) return null
|
|
1351
|
+
const last = Math.max(0, ...all(workspaceChannels, (c) => c.workspaceId === workspaceId).map((c) => c.createdAt))
|
|
1352
|
+
const row = { id: uuid(), workspaceId, name, createdBy, createdAt: Math.max(now(), last + 1) }
|
|
1353
|
+
workspaceChannels.set(row.id, row); return copy(row)
|
|
1354
|
+
},
|
|
1355
|
+
async workspaceChannelById (id) { const c = workspaceChannels.get(id); return c ? copy(c) : null },
|
|
1356
|
+
async addChannelMessage ({ channelId, account, name = '', text }) {
|
|
1357
|
+
if (!workspaceChannels.has(channelId)) throw fkViolation('channel', 'does not exist')
|
|
1358
|
+
const last = Math.max(0, ...all(channelMessages, (m) => m.channelId === channelId).map((m) => m.createdAt))
|
|
1359
|
+
const row = { id: uuid(), channelId, account, name, text, createdAt: Math.max(now(), last + 1) }
|
|
1360
|
+
channelMessages.set(row.id, row); return copy(row)
|
|
1361
|
+
},
|
|
1362
|
+
async listChannelMessages (channelId, { after = 0, limit = 100 } = {}) {
|
|
1363
|
+
const mine = all(channelMessages, (m) => m.channelId === channelId && m.createdAt > after).sort((a, b) => a.createdAt - b.createdAt)
|
|
1364
|
+
return (after ? mine.slice(0, limit) : mine.slice(-limit)).map(copy)
|
|
1365
|
+
},
|
|
1366
|
+
async countChannelMessages (channelId, { after = 0, notBy = '' } = {}) { return all(channelMessages, (m) => m.channelId === channelId && m.createdAt > after && m.account !== notBy).length },
|
|
1367
|
+
async channelReadAt (channelId, account) { return channelReads.get(`${channelId}|${account}`) || 0 },
|
|
1368
|
+
async setChannelReadAt (channelId, account, at) { channelReads.set(`${channelId}|${account}`, Math.max(at, channelReads.get(`${channelId}|${account}`) || 0)) },
|
|
1369
|
+
|
|
1339
1370
|
// App connections (20261112000000_app_connections.sql): Composio holds the tokens.
|
|
1340
1371
|
async addAppConnection (c) {
|
|
1341
1372
|
if (all(appConnections, (r) => r.composioId === c.composioId).length) throw duplicate('connection')
|
|
@@ -4,12 +4,23 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Everyone who reaches the project reads and writes it: its people, and agents placed in it.
|
|
6
6
|
// Each account's place in it (what it has read) is kept, so the app can say how much is new.
|
|
7
|
+
//
|
|
8
|
+
// Beside it, a project has the channels its people make: named, for the same people, made by
|
|
9
|
+
// someone who may change the project. They are kept apart from the project's own channel (their
|
|
10
|
+
// own tables), so that one works whether or not their database change has been applied.
|
|
7
11
|
import { HttpError, needId, stripInvisible } from '../http.js'
|
|
8
12
|
import { workspaceReach, canSeeFiles } from '../workspace-reach.js'
|
|
9
13
|
|
|
10
14
|
export const MAX_MESSAGE = 8000
|
|
11
15
|
const PAGE = 100
|
|
12
16
|
const PER_MINUTE = 30
|
|
17
|
+
export const MAX_CHANNELS = 50
|
|
18
|
+
export const MAX_CHANNEL_NAME = 40
|
|
19
|
+
// The database has no such table yet (the channels' change is not applied): Postgres, or PostgREST's cache.
|
|
20
|
+
const noTable = (err) => !!err && (err.code === '42P01' || err.code === 'PGRST205')
|
|
21
|
+
|
|
22
|
+
/** A channel's name as it is kept: one line, no leading #, at most 40 characters; '' when there is nothing left. */
|
|
23
|
+
export const channelName = (raw) => stripInvisible(String(raw ?? '')).join('').replace(/\s+/g, ' ').replace(/^[#\s]+/, '').trim().slice(0, MAX_CHANNEL_NAME).trim()
|
|
13
24
|
|
|
14
25
|
export function workspaceChatRoutes (ctx) {
|
|
15
26
|
const { store, now = Date.now, workspaces = false } = ctx
|
|
@@ -42,7 +53,70 @@ export function workspaceChatRoutes (ctx) {
|
|
|
42
53
|
if (recent.size > 5000) for (const [k, v] of recent) if (!v.some((t) => at - t < 60_000)) recent.delete(k)
|
|
43
54
|
}
|
|
44
55
|
|
|
56
|
+
/** A channel someone made in this project, or a 404. */
|
|
57
|
+
async function channelIn (ws, cid) {
|
|
58
|
+
const ch = await store.workspaceChannelById(needId(cid, 'channel')).catch((err) => { if (noTable(err)) return null; throw err })
|
|
59
|
+
if (!ch || ch.workspaceId !== ws.id) throw new HttpError(404, 'no such channel')
|
|
60
|
+
return ch
|
|
61
|
+
}
|
|
62
|
+
const said = (body) => {
|
|
63
|
+
const text = String(body.text || '').replace(/\r\n/g, '\n').trim()
|
|
64
|
+
if (!text) throw new HttpError(400, 'Say something.')
|
|
65
|
+
if (text.length > MAX_MESSAGE) throw new HttpError(413, 'That message is too long.')
|
|
66
|
+
return text
|
|
67
|
+
}
|
|
68
|
+
|
|
45
69
|
return [
|
|
70
|
+
// The channels people made in the project, oldest first, each with how much is new for the caller.
|
|
71
|
+
// `canAdd`: the caller may make one. `ready: false`: this server's database cannot keep them yet.
|
|
72
|
+
['GET', /^\/v1\/workspaces\/([^/]+)\/channels$/, gated(async (req, body, [id]) => {
|
|
73
|
+
const r = await inProject(req, id)
|
|
74
|
+
let list
|
|
75
|
+
try { list = await store.listWorkspaceChannels(r.ws.id) } catch (err) { if (noTable(err)) return { channels: [], canAdd: false, ready: false }; throw err }
|
|
76
|
+
const channels = await Promise.all(list.map(async (c) => ({ id: c.id, name: c.name, unread: await store.countChannelMessages(c.id, { after: await store.channelReadAt(c.id, r.me.account), notBy: r.me.account }) })))
|
|
77
|
+
return { channels, canAdd: r.access.access === 'edit' && list.length < MAX_CHANNELS, ready: true }
|
|
78
|
+
})],
|
|
79
|
+
|
|
80
|
+
// A new channel, by someone who may change the project. One of a name, whatever its capitals.
|
|
81
|
+
['POST', /^\/v1\/workspaces\/([^/]+)\/channels$/, gated(async (req, body, [id]) => {
|
|
82
|
+
const r = await inProject(req, id)
|
|
83
|
+
if (r.access.access !== 'edit') throw new HttpError(403, 'Only people who can change this project make channels.')
|
|
84
|
+
const name = channelName(body.name)
|
|
85
|
+
if (!name) throw new HttpError(400, 'Give the channel a name.')
|
|
86
|
+
let list
|
|
87
|
+
try { list = await store.listWorkspaceChannels(r.ws.id) } catch (err) { if (noTable(err)) throw new HttpError(503, 'Channels can\'t be made on this server yet.'); throw err }
|
|
88
|
+
if (list.length >= MAX_CHANNELS) throw new HttpError(400, `A project has at most ${MAX_CHANNELS} channels.`)
|
|
89
|
+
const made = list.some((c) => c.name.toLowerCase() === name.toLowerCase()) ? null : await store.addWorkspaceChannel({ workspaceId: r.ws.id, name, createdBy: r.me.account })
|
|
90
|
+
if (!made) throw new HttpError(409, `There is already a channel called ${name}.`)
|
|
91
|
+
return { channel: { id: made.id, name: made.name, unread: 0 } }
|
|
92
|
+
})],
|
|
93
|
+
|
|
94
|
+
// One of those channels: the same three calls as the project's own channel below.
|
|
95
|
+
['GET', /^\/v1\/workspaces\/([^/]+)\/channels\/([^/]+)\/messages$/, gated(async (req, body, [id, cid], url) => {
|
|
96
|
+
const { me, ws } = await inProject(req, id)
|
|
97
|
+
const ch = await channelIn(ws, cid)
|
|
98
|
+
const u = url || new URL(req.url, 'http://x')
|
|
99
|
+
const messages = await store.listChannelMessages(ch.id, { after: Number(u.searchParams.get('after')) || 0, limit: PAGE })
|
|
100
|
+
const readAt = await store.channelReadAt(ch.id, me.account)
|
|
101
|
+
return { messages: messages.map((m) => view(m, me.account)), readAt, unread: await store.countChannelMessages(ch.id, { after: readAt, notBy: me.account }) }
|
|
102
|
+
})],
|
|
103
|
+
['POST', /^\/v1\/workspaces\/([^/]+)\/channels\/([^/]+)\/messages$/, gated(async (req, body, [id, cid]) => {
|
|
104
|
+
const { me, ws } = await inProject(req, id)
|
|
105
|
+
const ch = await channelIn(ws, cid)
|
|
106
|
+
const text = said(body)
|
|
107
|
+
limit(me.account)
|
|
108
|
+
const m = await store.addChannelMessage({ channelId: ch.id, account: me.account, name: await nameOf(me.account), text })
|
|
109
|
+
await store.setChannelReadAt(ch.id, me.account, m.createdAt)
|
|
110
|
+
return { message: view(m, me.account) }
|
|
111
|
+
})],
|
|
112
|
+
['POST', /^\/v1\/workspaces\/([^/]+)\/channels\/([^/]+)\/messages\/read$/, gated(async (req, body, [id, cid]) => {
|
|
113
|
+
const { me, ws } = await inProject(req, id)
|
|
114
|
+
const ch = await channelIn(ws, cid)
|
|
115
|
+
const at = now()
|
|
116
|
+
await store.setChannelReadAt(ch.id, me.account, at)
|
|
117
|
+
return { readAt: at }
|
|
118
|
+
})],
|
|
119
|
+
|
|
46
120
|
// The channel's messages, oldest first: the newest page, or what came after `after` (a time in ms).
|
|
47
121
|
// `unread`: how many others wrote since the caller last read it; `readAt`: when that was.
|
|
48
122
|
['GET', /^\/v1\/workspaces\/([^/]+)\/messages$/, gated(async (req, body, [id], url) => {
|
|
@@ -56,9 +130,7 @@ export function workspaceChatRoutes (ctx) {
|
|
|
56
130
|
|
|
57
131
|
['POST', /^\/v1\/workspaces\/([^/]+)\/messages$/, gated(async (req, body, [id]) => {
|
|
58
132
|
const { me, ws } = await inProject(req, id)
|
|
59
|
-
const text =
|
|
60
|
-
if (!text) throw new HttpError(400, 'Say something.')
|
|
61
|
-
if (text.length > MAX_MESSAGE) throw new HttpError(413, 'That message is too long.')
|
|
133
|
+
const text = said(body)
|
|
62
134
|
limit(me.account)
|
|
63
135
|
const m = await store.addWorkspaceMessage({ workspaceId: ws.id, account: me.account, name: await nameOf(me.account), text })
|
|
64
136
|
// Whoever writes has read up to here.
|
|
@@ -54,6 +54,8 @@ const SECRET_ASK = 'run_id, secret_id, name, state, asked_at, answered_at'
|
|
|
54
54
|
const SECRET_USE = 'id, secret_id, run_id, room, account, upstream, at'
|
|
55
55
|
// App connections (20261112000000_app_connections.sql).
|
|
56
56
|
const WORKSPACE_MESSAGE = 'id, workspace_id, account, name, text, created_at'
|
|
57
|
+
const WORKSPACE_CHANNEL = 'id, workspace_id, name, created_by, created_at'
|
|
58
|
+
const CHANNEL_MESSAGE = 'id, channel_id, account, name, text, created_at'
|
|
57
59
|
const APP_CONNECTION = 'id, scope_type, scope_id, app, app_name, logo, composio_id, status, who, agents, created_by, created_at, updated_at'
|
|
58
60
|
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'
|
|
59
61
|
// How Quilt wakes each agent (20261025000000_agent_wake.sql).
|
|
@@ -527,6 +529,40 @@ export function createSupabaseStore ({ url, serviceKey, client, fetch: authFetch
|
|
|
527
529
|
async setWorkspaceReadAt (workspaceId, account, at) {
|
|
528
530
|
await one(db.from('workspace_message_reads').upsert({ workspace_id: workspaceId, account, read_at: ts(at) }, { onConflict: 'workspace_id,account' }))
|
|
529
531
|
},
|
|
532
|
+
// More channels in a project (20261123010000_project_channels.sql): the ones people made, their messages, and what each account has read.
|
|
533
|
+
async listWorkspaceChannels (workspaceId) {
|
|
534
|
+
return (await one(db.from('workspace_channels').select(WORKSPACE_CHANNEL).eq('workspace_id', workspaceId).order('created_at'))).map(rowFrom)
|
|
535
|
+
},
|
|
536
|
+
// One of a name in a project (a unique index; a second is a 23505): null then.
|
|
537
|
+
async addWorkspaceChannel ({ workspaceId, name, createdBy = '' }) {
|
|
538
|
+
const { data, error } = await db.from('workspace_channels').insert({ workspace_id: workspaceId, name, created_by: createdBy }).select(WORKSPACE_CHANNEL).single()
|
|
539
|
+
if (error) { if (error.code === '23505') return null; throw error }
|
|
540
|
+
return rowFrom(data)
|
|
541
|
+
},
|
|
542
|
+
async workspaceChannelById (id) {
|
|
543
|
+
const row = await one(db.from('workspace_channels').select(WORKSPACE_CHANNEL).eq('id', id).maybeSingle())
|
|
544
|
+
return row ? rowFrom(row) : null
|
|
545
|
+
},
|
|
546
|
+
async addChannelMessage ({ channelId, account, name = '', text }) {
|
|
547
|
+
return rowFrom(await one(db.from('workspace_channel_messages').insert({ channel_id: channelId, account, name, text }).select(CHANNEL_MESSAGE).single()))
|
|
548
|
+
},
|
|
549
|
+
async listChannelMessages (channelId, { after = 0, limit = 100 } = {}) {
|
|
550
|
+
const q = db.from('workspace_channel_messages').select(CHANNEL_MESSAGE).eq('channel_id', channelId)
|
|
551
|
+
if (after) return (await one(q.gt('created_at', ts(after)).order('created_at').limit(limit))).map(rowFrom)
|
|
552
|
+
return (await one(q.order('created_at', { ascending: false }).limit(limit))).map(rowFrom).reverse()
|
|
553
|
+
},
|
|
554
|
+
async countChannelMessages (channelId, { after = 0, notBy = '' } = {}) {
|
|
555
|
+
const { count, error } = await db.from('workspace_channel_messages').select('id', { count: 'exact', head: true }).eq('channel_id', channelId).gt('created_at', ts(after)).neq('account', notBy)
|
|
556
|
+
if (error) throw error
|
|
557
|
+
return count || 0
|
|
558
|
+
},
|
|
559
|
+
async channelReadAt (channelId, account) {
|
|
560
|
+
const row = await one(db.from('workspace_channel_reads').select('read_at').eq('channel_id', channelId).eq('account', account).maybeSingle())
|
|
561
|
+
return row ? ms(row.read_at) : 0
|
|
562
|
+
},
|
|
563
|
+
async setChannelReadAt (channelId, account, at) {
|
|
564
|
+
await one(db.from('workspace_channel_reads').upsert({ channel_id: channelId, account, read_at: ts(at) }, { onConflict: 'channel_id,account' }))
|
|
565
|
+
},
|
|
530
566
|
|
|
531
567
|
async listWorkspaceInvites (workspaceId) {
|
|
532
568
|
return (await one(db.from('workspace_invites').select(WORKSPACE_INVITE).eq('workspace_id', workspaceId).order('created_at', { ascending: false }).limit(50))).map(rowFrom)
|
package/src/ui/app.css
CHANGED
|
@@ -1612,12 +1612,9 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1612
1612
|
.pj-crumb > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1613
1613
|
.pj-crumb:hover { background: var(--panel-2); }
|
|
1614
1614
|
#pj-side-btn { flex: none; margin-left: 6px; }
|
|
1615
|
-
/* The sidebar
|
|
1616
|
-
|
|
1615
|
+
/* The sidebar closes from its own last row, in its foot. Only while the sidebar is closed is
|
|
1616
|
+
there a button in the header, to open it again. */
|
|
1617
1617
|
:is(.pj-home, .ws.pj-cb):not([data-side="shut"]) #pj-side-btn { display: none; }
|
|
1618
|
-
.pj-side-hide { position: absolute; top: 13px; right: 9px; z-index: 1; color: var(--muted); }
|
|
1619
|
-
.pj-side-hide:hover { color: var(--text); }
|
|
1620
|
-
.pj-side > nav.side-nav > button:first-child { margin-right: 34px; }
|
|
1621
1618
|
.pj-home .ws-top .spacer { flex: 1; }
|
|
1622
1619
|
.pj-home .ws-top .brand .qm-word { transform: translateY(11%); }
|
|
1623
1620
|
.pj-home .page { flex: 1; min-height: 0; padding: 16px 24px 32px; overflow-y: auto; }
|
|
@@ -1767,6 +1764,11 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1767
1764
|
.pj-hash { flex: none; display: inline-grid; place-items: center; width: 16px; font-weight: 600; font-size: 15px; color: var(--muted); }
|
|
1768
1765
|
.pj-side .side-sessions.pj-rooms button.on { background: var(--panel-2); font-weight: 600; }
|
|
1769
1766
|
.pj-side .pj-rooms button.on .pj-hash { color: var(--text); }
|
|
1767
|
+
/* naming a new channel, in the list where it will be */
|
|
1768
|
+
.pj-newchan { display: flex; align-items: center; gap: 10px; height: 28px; margin: 1px 0; padding: 0 10px; border-radius: 4px; background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
|
|
1769
|
+
.pj-newchan:focus-within { box-shadow: inset 0 0 0 1.5px var(--accent); }
|
|
1770
|
+
.pj-newchan input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 13px; }
|
|
1771
|
+
.pj-newchan input::placeholder { color: var(--faint); }
|
|
1770
1772
|
.pj-side .ct.new, .pj-side .side-nav button.on .ct.new, .pj-side .side-nav button:hover .ct.new { background: var(--accent); color: light-dark(#fff, #1d1b2e); }
|
|
1771
1773
|
.ws.pj-cb .ws-body { grid-template-columns: 244px minmax(0, 1fr); transition: grid-template-columns var(--side-slide); }
|
|
1772
1774
|
.ws.pj-cb[data-side="shut"] .ws-body { grid-template-columns: 0px minmax(0, 1fr); }
|
|
@@ -1775,7 +1777,7 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1775
1777
|
.ws.pj-cb .chat-resize, .ws.pj-cb .chat-rail, .ws.pj-cb #collapse-chat { display: none; }
|
|
1776
1778
|
.ws.pj-cb[data-side-page="chat"] .ws-main { display: none; }
|
|
1777
1779
|
.ws.pj-cb[data-side-page="chat"] .ws-chat { display: flex; }
|
|
1778
|
-
.ws.pj-cb:is([data-side-page="connections"], [data-side-page="artifacts"], [data-side-page^="preview:"]) :is(#main, #mainbar) { display: none; }
|
|
1780
|
+
.ws.pj-cb:is([data-side-page="connections"], [data-side-page="artifacts"], [data-side-page^="preview:"], [data-side-page^="channel:"]) :is(#main, #mainbar) { display: none; }
|
|
1779
1781
|
|
|
1780
1782
|
/* ---- Previews of a codebase (preview-page.js): rows in the sidebars, and a preview's page: its head with the
|
|
1781
1783
|
branch picker, and under it the app in a frame, or what it says while it starts. ---- */
|
package/src/ui/app.js
CHANGED
|
@@ -258,7 +258,7 @@ export async function go (view) {
|
|
|
258
258
|
state.pending = []
|
|
259
259
|
state.to = ''
|
|
260
260
|
if (view !== 'home') state.addingWorkspace = false
|
|
261
|
-
if (!isWorkspace(view) || wsIdOf(view) !== state.workspace?.workspace?.id) state.projectPage = '' // another project opens on its overview
|
|
261
|
+
if (!isWorkspace(view) || wsIdOf(view) !== state.workspace?.workspace?.id) { state.projectPage = ''; state.projectChannel = ''; state.newChannel = null } // another project opens on its overview
|
|
262
262
|
drawRail() // where you are going shows on the strip at once, while its page loads
|
|
263
263
|
if (isWorkspace(view)) {
|
|
264
264
|
if (state.workspace?.workspace?.id !== wsIdOf(view)) {
|
|
@@ -1,55 +1,104 @@
|
|
|
1
|
-
// A project's
|
|
2
|
-
// codebase open
|
|
3
|
-
//
|
|
1
|
+
// A project's channels (projects on): its own, one conversation for everyone in the project, there
|
|
2
|
+
// with no codebase open, and the ones its people make (a plus beside Channels in the sidebar). The
|
|
3
|
+
// accounts API keeps them (routes/workspace-chat.js); the app asks for what is new every few
|
|
4
|
+
// seconds while a project's page is open. A codebase's own channel is its chat.
|
|
4
5
|
import { I, state, $, esc, api, toast, avatar, clock } from './common.js'
|
|
5
6
|
import { textHtml } from './chat.js'
|
|
6
7
|
|
|
7
8
|
const ASK_MS = 4000
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
// `channel` everywhere here: the id of a channel someone made, or '' for the project's own.
|
|
10
|
+
const chans = new Map() // project id (then `|` and a made channel's id) -> { messages, unread, asked, loaded, failed }
|
|
11
|
+
const keyOf = (id, channel = '') => (channel ? `${id}|${channel}` : id)
|
|
12
|
+
const chan = (id, channel = '') => { const k = keyOf(id, channel); if (!chans.has(k)) chans.set(k, { messages: [], unread: 0, asked: 0, loaded: false, failed: '', draft: '' }); return chans.get(k) }
|
|
13
|
+
const urlOf = (id, channel = '') => `/api/workspaces/${encodeURIComponent(id)}${channel ? `/channels/${encodeURIComponent(channel)}` : ''}/messages`
|
|
14
|
+
let live = null // the channel on the page: { el, key }
|
|
15
|
+
|
|
16
|
+
// The channels people made in each project, as last heard: project id -> { list: [{ id, name, unread }], canAdd, asked }.
|
|
17
|
+
const made = new Map()
|
|
18
|
+
const madeIn = (id) => { if (!made.has(id)) made.set(id, { list: [], canAdd: false, asked: 0, loaded: false }); return made.get(id) }
|
|
11
19
|
|
|
12
20
|
/** How many messages are new for you in a project's channel, as last heard. */
|
|
13
21
|
export const channelUnread = (id) => chan(id).unread
|
|
14
22
|
|
|
23
|
+
/** The channels people made in a project, oldest first, each with what is new for you ({ id, name, unread }); `canAdd`: you may make one; `loaded`: the server has answered once. */
|
|
24
|
+
export const projectChannels = (id) => madeIn(id)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Asks which channels people made in a project and how much is new in each (at most every few
|
|
28
|
+
* seconds; `now` asks at once). `changed()` is called when the list or a count changed. A server
|
|
29
|
+
* that cannot keep them yet answers none, and nobody is offered to make one.
|
|
30
|
+
*/
|
|
31
|
+
export async function loadChannels (id, changed = () => {}, { now = false } = {}) {
|
|
32
|
+
const m = madeIn(id)
|
|
33
|
+
if (!now && Date.now() - m.asked < ASK_MS) return
|
|
34
|
+
m.asked = Date.now()
|
|
35
|
+
try {
|
|
36
|
+
const r = await api('GET', `/api/workspaces/${encodeURIComponent(id)}/channels`)
|
|
37
|
+
const was = JSON.stringify([m.list, m.canAdd])
|
|
38
|
+
// The one that is open and being read has nothing new, whatever was counted a moment ago.
|
|
39
|
+
m.list = (r.channels || []).map((c) => ({ id: c.id, name: c.name, unread: live && live.key === keyOf(id, c.id) && live.el.isConnected && document.hasFocus() ? 0 : c.unread || 0 }))
|
|
40
|
+
m.canAdd = !!r.canAdd
|
|
41
|
+
const first = !m.loaded
|
|
42
|
+
m.loaded = true
|
|
43
|
+
if (first || JSON.stringify([m.list, m.canAdd]) !== was) changed()
|
|
44
|
+
} catch { if (!m.loaded) { m.loaded = true; changed() } } // the list stays as it was: the project's own channel does not depend on it
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Makes a channel in a project. Resolves to it ({ id, name }); rejects with what the accounts API said. */
|
|
48
|
+
export async function addChannel (id, name) {
|
|
49
|
+
const r = await api('POST', `/api/workspaces/${encodeURIComponent(id)}/channels`, { name })
|
|
50
|
+
const m = madeIn(id)
|
|
51
|
+
if (!m.list.some((c) => c.id === r.channel.id)) m.list.push({ id: r.channel.id, name: r.channel.name, unread: 0 })
|
|
52
|
+
return r.channel
|
|
53
|
+
}
|
|
54
|
+
|
|
15
55
|
/**
|
|
16
56
|
* Asks for what is new in a project's channel (at most every few seconds; `now` asks at once).
|
|
17
57
|
* `changed()` is called when the count of what is new changes; the open channel draws itself.
|
|
18
58
|
*/
|
|
19
|
-
export async function loadChannel (id, changed = () => {}, { now = false } = {}) {
|
|
20
|
-
const c = chan(id)
|
|
59
|
+
export async function loadChannel (id, changed = () => {}, { now = false, channel = '' } = {}) {
|
|
60
|
+
const c = chan(id, channel)
|
|
61
|
+
const key = keyOf(id, channel)
|
|
62
|
+
// A made channel's count is the one its row in the list shows.
|
|
63
|
+
const mirror = () => { const row = channel && madeIn(id).list.find((x) => x.id === channel); if (row) row.unread = c.unread }
|
|
21
64
|
if (!now && Date.now() - c.asked < ASK_MS) return
|
|
22
65
|
c.asked = Date.now()
|
|
23
66
|
try {
|
|
24
67
|
const after = c.messages.length ? c.messages[c.messages.length - 1].at : 0
|
|
25
|
-
const r = await api('GET',
|
|
26
|
-
const had = c.messages.length; const was = c.unread
|
|
68
|
+
const r = await api('GET', `${urlOf(id, channel)}${after ? `?after=${after}` : ''}`)
|
|
69
|
+
const had = c.messages.length; const was = c.unread; const first = !c.loaded
|
|
27
70
|
const known = new Set(c.messages.map((m) => m.id))
|
|
28
71
|
for (const m of r.messages) if (!known.has(m.id)) c.messages.push(m)
|
|
29
72
|
c.loaded = true; c.failed = ''
|
|
30
73
|
c.unread = r.unread
|
|
31
|
-
const open = live && live.
|
|
32
|
-
if (open && (c.messages.length !== had || !live.drawn)) live.draw()
|
|
74
|
+
const open = live && live.key === key && live.el.isConnected
|
|
75
|
+
if (open && (c.messages.length !== had || !live.drawn || first)) live.draw() // the first answer too: an empty channel stops saying it is loading
|
|
33
76
|
// Reading it on the page is reading it: what came in while it is open is not new.
|
|
34
|
-
if (open && c.unread && document.hasFocus()) { c.unread = 0; api('POST',
|
|
77
|
+
if (open && c.unread && document.hasFocus()) { c.unread = 0; api('POST', `${urlOf(id, channel)}/read`).catch(() => {}) }
|
|
78
|
+
mirror()
|
|
35
79
|
if (c.unread !== was) changed()
|
|
36
80
|
} catch (err) {
|
|
37
81
|
c.failed = err.message
|
|
38
|
-
if (!c.loaded && live && live.
|
|
82
|
+
if (!c.loaded && live && live.key === key && live.el.isConnected) live.draw()
|
|
39
83
|
}
|
|
40
84
|
}
|
|
41
85
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Draws a project's channel into `el` and keeps it working: its own, or with `channel` ({ id, name })
|
|
88
|
+
* one its people made. `changed()`: the count of what is new changed (the sidebar shows it).
|
|
89
|
+
*/
|
|
90
|
+
export function mountChannel (el, { d, changed = () => {}, channel = null }) {
|
|
44
91
|
const id = d.workspace.id
|
|
45
|
-
const
|
|
92
|
+
const cid = channel ? channel.id : ''
|
|
93
|
+
const title = channel ? channel.name : d.workspace.name
|
|
94
|
+
const c = chan(id, cid)
|
|
46
95
|
const me = state.profile?.name || ''
|
|
47
96
|
const names = () => [...new Set([d.owner?.name, ...(d.members || []).map((m) => m.name), ...(d.agents || []).map((a) => a.name)].filter(Boolean))]
|
|
48
97
|
el.innerHTML = `
|
|
49
98
|
<div class="pj-chan">
|
|
50
|
-
<div class="files-head"><div class="t"><h2 class="crumbs"><span class="pj-hash">#</span>${esc(
|
|
99
|
+
<div class="files-head"><div class="t"><h2 class="crumbs"><span class="pj-hash">#</span>${esc(title)}</h2><p class="hint">Everyone in ${esc(d.workspace.name)} and its agents. It is here with no codebase open.</p></div></div>
|
|
51
100
|
<div class="messages" data-chan-list aria-live="polite"></div>
|
|
52
|
-
<form class="composer" data-chan-form><div class="box"><textarea rows="1" maxlength="8000" placeholder="Message ${esc(
|
|
101
|
+
<form class="composer" data-chan-form><div class="box"><textarea rows="1" maxlength="8000" placeholder="Message ${esc(title)}…" aria-label="Message ${esc(title)}"></textarea><button type="submit" class="btn primary icon" title="Send" aria-label="Send">${I.send}</button></div></form>
|
|
53
102
|
</div>`
|
|
54
103
|
const list = $('[data-chan-list]', el)
|
|
55
104
|
const box = $('textarea', el)
|
|
@@ -62,7 +111,7 @@ export function mountChannel (el, { d, changed = () => {} }) {
|
|
|
62
111
|
if (near || !live.drawn) list.scrollTop = list.scrollHeight
|
|
63
112
|
live.drawn = true
|
|
64
113
|
}
|
|
65
|
-
live = { el, id, draw, drawn: false }
|
|
114
|
+
live = { el, key: keyOf(id, cid), draw, drawn: false }
|
|
66
115
|
draw()
|
|
67
116
|
const grow = () => { box.style.height = 'auto'; box.style.height = `${Math.min(box.scrollHeight, 160)}px` }
|
|
68
117
|
// The page is drawn again when a codebase's state changes: what was being typed is put back.
|
|
@@ -76,15 +125,16 @@ export function mountChannel (el, { d, changed = () => {} }) {
|
|
|
76
125
|
if (!text) return
|
|
77
126
|
box.value = ''; c.draft = ''; grow()
|
|
78
127
|
try {
|
|
79
|
-
const r = await api('POST',
|
|
128
|
+
const r = await api('POST', urlOf(id, cid), { text })
|
|
80
129
|
if (!c.messages.some((m) => m.id === r.message.id)) c.messages.push(r.message)
|
|
81
130
|
draw(); list.scrollTop = list.scrollHeight
|
|
82
131
|
} catch (err) { toast(err.message); if (!box.value) { box.value = text; c.draft = text; grow() } }
|
|
83
132
|
box.focus()
|
|
84
133
|
}
|
|
85
134
|
// Opening it is reading it.
|
|
86
|
-
const
|
|
87
|
-
|
|
135
|
+
const row = () => (cid ? madeIn(id).list.find((x) => x.id === cid) : null)
|
|
136
|
+
const read = () => { if (!c.unread && !(row() && row().unread)) return; c.unread = 0; if (row()) row().unread = 0; changed(); api('POST', `${urlOf(id, cid)}/read`).catch(() => {}) }
|
|
137
|
+
loadChannel(id, changed, { now: true, channel: cid }).then(read)
|
|
88
138
|
// Coming back to the window with the channel open is reading it.
|
|
89
139
|
const onFocus = () => { if (!el.isConnected) return window.removeEventListener('focus', onFocus); read() }
|
|
90
140
|
window.addEventListener('focus', onFocus)
|
package/src/ui/projects.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { I, state, $, esc, ago, api, toast, ask, avatar, COLORS, loadingHtml } from './common.js'
|
|
6
6
|
import { quiltMark } from './mark.js'
|
|
7
7
|
import { quiltBlock, projectCodebases, looseCodebases, whoLine, readFolded, projectDms } from './project-model.js'
|
|
8
|
-
import { mountChannel, loadChannel, channelUnread } from './project-channel.js'
|
|
8
|
+
import { mountChannel, loadChannel, channelUnread, projectChannels, loadChannels, addChannel } from './project-channel.js'
|
|
9
9
|
import { tileLetter } from './prail-model.js'
|
|
10
10
|
import { loadWorkspaces, openWorkspace, wsIdOf } from './workspaces.js'
|
|
11
11
|
import { openNewProject, openProjectPop } from './project-pop.js'
|
|
@@ -29,9 +29,9 @@ const foldedNow = () => (folded ||= readFolded(saved('quilt.sideFolded')))
|
|
|
29
29
|
/** Whether the sidebar of a project or a codebase is closed (one choice for both, kept on this computer). */
|
|
30
30
|
export const sideShut = () => saved('quilt.projectSide') === 'shut'
|
|
31
31
|
export const toggleSideShut = () => save('quilt.projectSide', sideShut() ? 'open' : 'shut')
|
|
32
|
-
// The sidebar's own
|
|
32
|
+
// The sidebar's own row, the last in its foot, closes it. While it is closed the button that opens
|
|
33
33
|
// it again is in the header, where the sidebar's edge was (the styles show one or the other).
|
|
34
|
-
const sideHideBtn = () => `<button type="button" class="
|
|
34
|
+
const sideHideBtn = () => `<button type="button" class="pj-side-hide" data-side-toggle aria-expanded="true" title="Hide the sidebar">${panelIcon}<span class="nm">Hide sidebar</span></button>`
|
|
35
35
|
const sideShowBtn = () => `<button type="button" class="btn sm ghost icon" id="pj-side-btn" aria-expanded="false" title="Show the sidebar" aria-label="Show the sidebar">${panelIcon}</button>`
|
|
36
36
|
/** Shows the sidebar closed or open, as it was just set: on the page's shell (`ws`), where it slides. The button now showing takes the focus the other had. */
|
|
37
37
|
export function drawSideShut (ws) {
|
|
@@ -41,6 +41,37 @@ export function drawSideShut (ws) {
|
|
|
41
41
|
ws.dataset.side = shut ? 'shut' : 'open'
|
|
42
42
|
if (had) ws.querySelector(shut ? '#pj-side-btn' : '.pj-side [data-side-toggle]')?.focus({ preventScroll: true })
|
|
43
43
|
}
|
|
44
|
+
// The plus beside Channels, in a project's sidebar and a codebase's: a row to name the new one in, in the list.
|
|
45
|
+
const newChannelBtn = `<button type="button" class="btn sm ghost icon" data-new-channel title="New channel" aria-label="New channel">${I.plus}</button>`
|
|
46
|
+
const newChannelRow = () => `<form class="pj-newchan" data-new-channel-form autocomplete="off"><span class="pj-hash">#</span><input name="name" maxlength="40" placeholder="Name the channel" aria-label="The new channel's name" value="${esc(state.newChannelDraft || '')}" spellcheck="false"></form>`
|
|
47
|
+
/** The plus beside Channels was pressed in project `id`: its row to name the new one shows, in an open section. */
|
|
48
|
+
export function startNewChannel (id) { if (foldedNow().has('channels')) toggleFolded('channels'); state.newChannel = id; state.newChannelDraft = '' }
|
|
49
|
+
/**
|
|
50
|
+
* Makes the row a new channel is named in work, when `root` has one: Enter makes it in project `id`
|
|
51
|
+
* and calls `made(channel)`; Escape, or leaving it empty, takes the row away (`redraw` draws the
|
|
52
|
+
* sidebar again). `focus` false leaves the cursor where it is (the sidebar was only drawn again).
|
|
53
|
+
*/
|
|
54
|
+
export function bindNewChannel (root, id, { redraw, made, focus = true }) {
|
|
55
|
+
const naming = root.querySelector('[data-new-channel-form]')
|
|
56
|
+
if (!naming) return
|
|
57
|
+
const box = naming.elements.name
|
|
58
|
+
const stop = () => { state.newChannel = null; state.newChannelDraft = ''; redraw() }
|
|
59
|
+
if (focus) { box.focus(); box.setSelectionRange(box.value.length, box.value.length) }
|
|
60
|
+
box.oninput = () => { state.newChannelDraft = box.value }
|
|
61
|
+
box.onkeydown = (e) => { if (e.key === 'Escape') { e.preventDefault(); stop() } }
|
|
62
|
+
box.onblur = () => { if (!box.value.trim() && state.newChannel === id && root.isConnected && !naming.dataset.busy) setTimeout(() => { if (document.activeElement !== box && box.isConnected) stop() }, 0) }
|
|
63
|
+
naming.onsubmit = async (e) => {
|
|
64
|
+
e.preventDefault()
|
|
65
|
+
const name = box.value.trim()
|
|
66
|
+
if (!name || naming.dataset.busy) return
|
|
67
|
+
naming.dataset.busy = '1'
|
|
68
|
+
try {
|
|
69
|
+
const channel = await addChannel(id, name)
|
|
70
|
+
state.newChannel = null; state.newChannelDraft = ''
|
|
71
|
+
made(channel)
|
|
72
|
+
} catch (err) { delete naming.dataset.busy; toast(err.message); box.focus() }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
44
75
|
/** Folds or unfolds one of the sidebar's sections. */
|
|
45
76
|
export function toggleFolded (k) { const f = foldedNow(); f.has(k) ? f.delete(k) : f.add(k); save('quilt.sideFolded', JSON.stringify([...f])) }
|
|
46
77
|
/**
|
|
@@ -223,7 +254,11 @@ function sideHtml (p, d, page) {
|
|
|
223
254
|
// Channels: the project's own (kept by the accounts API), then one for each codebase open here (its chat).
|
|
224
255
|
const open = list.filter((c) => c.where === 'open')
|
|
225
256
|
const own = channelUnread(p.id)
|
|
226
|
-
|
|
257
|
+
// The channels people made here, after the project's own; the one that is open, by its id.
|
|
258
|
+
const made = projectChannels(p.id)
|
|
259
|
+
const onChannel = page === 'channel' ? (made.list.some((c) => c.id === state.projectChannel) ? state.projectChannel : '') : null
|
|
260
|
+
const newHere = own + made.list.reduce((n, c) => n + c.unread, 0) + open.reduce((n, c) => n + ((state.sessions.get(c.id)?.status.unread) || 0), 0)
|
|
261
|
+
const naming = state.newChannel === p.id && made.canAdd
|
|
227
262
|
const room = (attrs, name, n, on) => `<button type="button" class="${on ? 'on' : ''}" ${attrs}${on ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(name)}</span>${n ? `<span class="ct new">${n > 99 ? '99+' : n}</span>` : ''}</button>`
|
|
228
263
|
// Direct messages, across the codebases open here: a row opens that codebase's chat on them.
|
|
229
264
|
const dms = projectDms(open.map((c) => ({ id: c.id, name: c.name, messages: state.messages.get(c.id) || [], me: state.sessions.get(c.id)?.status.me?.name || '' })))
|
|
@@ -236,19 +271,21 @@ function sideHtml (p, d, page) {
|
|
|
236
271
|
}
|
|
237
272
|
return `
|
|
238
273
|
<aside class="pj-side" aria-label="${esc(p.name)}">
|
|
239
|
-
${sideHideBtn()}
|
|
240
274
|
<nav class="side-nav" aria-label="Pages">${nav('', I.grid, 'Overview')}${nav('tasks', I.board, 'Tasks', projectOpenTasks(d))}${nav('artifacts', I.folder, 'Artifacts', files)}${state.connectionsOn ? nav('connections', I.link, 'Connections') : ''}</nav>
|
|
241
275
|
${label('codebases', 'Codebases', list.length, d.access?.access === 'edit' ? `<button type="button" class="btn sm ghost icon" data-new-codebase title="New codebase" aria-label="New codebase">${I.plus}</button>` : '')}
|
|
242
276
|
<div class="side-sessions">${isFolded('codebases') ? '' : list.map(row).join('')}</div>
|
|
243
|
-
${label('channels', 'Channels', newHere)}
|
|
244
|
-
<div class="side-sessions pj-rooms">${isFolded('channels') && page !== 'channel' && !newHere ? '' : `
|
|
245
|
-
${room(`data-page="channel" title="Everyone in ${esc(p.name)}"`, p.name, own,
|
|
277
|
+
${label('channels', 'Channels', newHere, made.canAdd ? newChannelBtn : '')}
|
|
278
|
+
<div class="side-sessions pj-rooms">${isFolded('channels') && page !== 'channel' && !newHere && !naming ? '' : `
|
|
279
|
+
${isFolded('channels') && onChannel !== '' && !own ? '' : room(`data-page="channel" title="Everyone in ${esc(p.name)}"`, p.name, own, onChannel === '')}
|
|
280
|
+
${made.list.filter((c) => !isFolded('channels') || c.id === onChannel || c.unread).map((c) => room(`data-channel="${esc(c.id)}" title="Everyone in ${esc(p.name)}"`, c.name, c.unread, c.id === onChannel)).join('')}
|
|
281
|
+
${naming ? newChannelRow() : ''}
|
|
246
282
|
${isFolded('channels') ? '' : open.map((c) => room(`data-go-chat="${esc(c.id)}" title="Everyone working in ${esc(c.name)}"`, c.name, (state.sessions.get(c.id)?.status.unread) || 0, false)).join('')}`}</div>
|
|
247
283
|
${dms.length ? `${label('dms', 'Direct messages')}
|
|
248
284
|
<div class="side-sessions pj-rooms">${isFolded('dms') ? '' : dms.map((t) => `<button type="button" data-go-dm="${esc(t.code)}" data-name="${esc(t.name)}" title="You and ${esc(t.name)}, in ${esc(t.codeName)}">${avatar(t.name)}<span class="nm">${esc(t.name)}</span></button>`).join('')}</div>` : ''}
|
|
249
285
|
<div class="side-foot side-nav">
|
|
250
286
|
<button type="button" data-team title="People and agents in this project"><span class="pj-faces sm">${team.slice(0, 3).map((m) => avatar(m.name)).join('')}</span><span class="nm">Team</span><span class="ct">${count}</span></button>
|
|
251
287
|
${d.access?.admin ? `<button type="button" data-invite-project>${I.link}<span class="nm">Invite</span></button>` : ''}
|
|
288
|
+
${sideHideBtn()}
|
|
252
289
|
</div>
|
|
253
290
|
</aside>`
|
|
254
291
|
}
|
|
@@ -266,9 +303,9 @@ export function codeCrumbHtml (project) {
|
|
|
266
303
|
/**
|
|
267
304
|
* The sidebar of a codebase's page. `page`: the row that is on ('loom', 'tasks', 'artifacts', 'chat', 'connections');
|
|
268
305
|
* `tasks`: its open tasks; `artifacts`: how many the project has, once known; `chatNew`: messages in its channel since it was last looked at;
|
|
269
|
-
* `people`: who is in it, you first ({ name, color }).
|
|
306
|
+
* `people`: who is in it, you first ({ name, color }); `channels`: its project's ({ own: what is new in the project's own, list: [{ id, name, unread }], canAdd, naming: the row to name a new one shows }).
|
|
270
307
|
*/
|
|
271
|
-
export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, chatNew = 0, people = [], connections = false, canInvite = true, dms = [], dmOn = '', call = 0, previews = null, canEdit = false }) {
|
|
308
|
+
export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, chatNew = 0, people = [], connections = false, canInvite = true, dms = [], dmOn = '', call = 0, previews = null, canEdit = false, channels = null }) {
|
|
272
309
|
const nav = (v, icon, label, n, attr = `data-code-page="${v}"`) => `<button type="button" class="${page === v ? 'on' : ''}" ${attr}${page === v ? ' aria-current="page"' : ''}>${icon}<span class="nm">${label}</span>${n ? `<span class="ct">${n}</span>` : ''}</button>`
|
|
273
310
|
const isFolded = (k) => foldedNow().has(k)
|
|
274
311
|
const label = (k, text, n, extra = '') => `<div class="side-label pj-side-label"><button type="button" class="pj-fold" data-fold="${k}" aria-expanded="${!isFolded(k)}" title="${isFolded(k) ? 'Show' : 'Hide'} ${text.toLowerCase()}"><span>${text}</span>${I.chevDown}</button>${isFolded(k) && n ? `<span class="ct new">${n}</span>` : ''}${extra}</div>`
|
|
@@ -280,17 +317,22 @@ export function codeSideHtml ({ page, name, project, tasks = 0, artifacts = 0, c
|
|
|
280
317
|
// A folded section keeps the row you are on, what is new, and a call going on.
|
|
281
318
|
const channel = !isFolded('channels') || page === 'chat' || chatNew || call
|
|
282
319
|
const inDm = page === 'chat' ? dmOn : ''
|
|
320
|
+
// Its project's channels, after its own: the project's own, then the ones its people made. They open on this page.
|
|
321
|
+
const ch = project && channels
|
|
322
|
+
const onCh = page.startsWith('channel:') ? page.slice('channel:'.length) : null
|
|
323
|
+
const chNew = ch ? ch.own + ch.list.reduce((n, c) => n + c.unread, 0) : 0
|
|
324
|
+
const room = (id, nm, n) => !isFolded('channels') || onCh === id || n ? `<button type="button" class="${onCh === id ? 'on' : ''}" data-code-page="channel:${esc(id)}" title="Everyone in ${esc(project.name)}"${onCh === id ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(nm)}</span>${n ? `<span class="ct new">${n > 99 ? '99+' : n}</span>` : ''}</button>` : ''
|
|
283
325
|
return `
|
|
284
|
-
${sideHideBtn()}
|
|
285
326
|
<nav class="side-nav" aria-label="Pages">${nav('loom', I.users, 'Loom')}${nav('tasks', I.board, 'Tasks', tasks)}${project ? nav('artifacts', I.folder, 'Artifacts', artifacts) : ''}${connections ? nav('connections', I.link, 'Connections') : ''}</nav>
|
|
286
327
|
${pvHtml}
|
|
287
|
-
${label('channels', 'Channels', chatNew)}
|
|
288
|
-
<div class="side-sessions pj-rooms">${channel ? `<button type="button" class="${page === 'chat' && !inDm ? 'on' : ''}" data-code-page="chat" data-dm="" title="Everyone working in ${esc(name)}"${page === 'chat' && !inDm ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(name)}</span>${call ? `<span class="pj-call" title="${call === 1 ? '1 person is' : `${call} people are`} in a call here">${I.headset}${call}</span>` : ''}${chatNew ? `<span class="ct new">${chatNew > 99 ? '99+' : chatNew}</span>` : ''}</button>` : ''}</div>
|
|
328
|
+
${label('channels', 'Channels', chatNew + chNew, ch && ch.canAdd ? newChannelBtn : '')}
|
|
329
|
+
<div class="side-sessions pj-rooms">${channel ? `<button type="button" class="${page === 'chat' && !inDm ? 'on' : ''}" data-code-page="chat" data-dm="" title="Everyone working in ${esc(name)}"${page === 'chat' && !inDm ? ' aria-current="page"' : ''}><span class="pj-hash">#</span><span class="nm">${esc(name)}</span>${call ? `<span class="pj-call" title="${call === 1 ? '1 person is' : `${call} people are`} in a call here">${I.headset}${call}</span>` : ''}${chatNew ? `<span class="ct new">${chatNew > 99 ? '99+' : chatNew}</span>` : ''}</button>` : ''}${ch ? `${room('', project.name, ch.own)}${ch.list.map((c) => room(c.id, c.name, c.unread)).join('')}${ch.naming && ch.canAdd ? newChannelRow() : ''}` : ''}</div>
|
|
289
330
|
${dms.length ? `${label('dms', 'Direct messages')}
|
|
290
331
|
<div class="side-sessions pj-rooms">${isFolded('dms') && !inDm && !dms.some((t) => t.n || t.call) ? '' : dms.filter((t) => !isFolded('dms') || t.name === inDm || t.n || t.call).map((t) => `<button type="button" class="${t.name === inDm ? 'on' : ''}" data-dm="${esc(t.name)}" title="You and ${esc(t.name)}"${t.name === inDm ? ' aria-current="page"' : ''}>${avatar(t.name)}<span class="nm">${esc(t.name)}</span>${t.call ? `<span class="pj-call" title="${t.call === 1 ? `${esc(t.name)} is calling you` : `You and ${esc(t.name)} are in a call`}">${I.headset}${t.call}</span>` : ''}${t.n ? `<span class="ct new">${t.n > 99 ? '99+' : t.n}</span>` : ''}</button>`).join('')}</div>` : ''}
|
|
291
332
|
<div class="side-foot side-nav">
|
|
292
333
|
<button type="button" data-code-team title="People in this codebase"><span class="pj-faces sm">${people.slice(0, 3).map((m) => avatar(m.name, m.color)).join('')}</span><span class="nm">Team</span><span class="ct">${people.length}</span></button>
|
|
293
334
|
${canInvite ? `<button type="button" data-code-invite>${I.link}<span class="nm">Invite</span></button>` : ''}
|
|
335
|
+
${sideHideBtn()}
|
|
294
336
|
</div>`
|
|
295
337
|
}
|
|
296
338
|
|
|
@@ -435,6 +477,7 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
|
|
|
435
477
|
b.onclick = () => {
|
|
436
478
|
const page = b.dataset.page
|
|
437
479
|
state.projectPage = page === 'connections' || page === 'tasks' || page === 'channel' ? page : ''
|
|
480
|
+
state.projectChannel = '' // the project's own channel
|
|
438
481
|
const to = page === 'artifacts' ? `wsfiles:${p.id}` : `ws:${p.id}`
|
|
439
482
|
if (to === state.view) rerender(); else go(to)
|
|
440
483
|
}
|
|
@@ -453,17 +496,33 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
|
|
|
453
496
|
// What is new changed: the sidebar says so. With the channel itself open only its count is touched, so what is being typed stays.
|
|
454
497
|
const newCount = () => {
|
|
455
498
|
if (state.view !== view) return
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
499
|
+
// A channel was made (here or by someone else): the list is drawn again, unless it would take what is being typed.
|
|
500
|
+
const rows = [...root.querySelectorAll('.pj-side [data-channel]')].map((b) => b.dataset.channel).join(' ')
|
|
501
|
+
const typing = root.querySelector('[data-project-channel] textarea')?.value || root.querySelector('[data-new-channel-form] input')
|
|
502
|
+
if (!root.querySelector('[data-project-channel]') || (rows !== made().list.map((c) => c.id).join(' ') && !typing)) return rerender()
|
|
503
|
+
const count = (row, n) => {
|
|
504
|
+
if (!row) return
|
|
505
|
+
row.querySelector('.ct')?.remove()
|
|
506
|
+
if (n) row.insertAdjacentHTML('beforeend', `<span class="ct new">${n > 99 ? '99+' : n}</span>`)
|
|
507
|
+
}
|
|
508
|
+
count(root.querySelector('[data-page="channel"]'), channelUnread(p.id))
|
|
509
|
+
for (const c of made().list) count([...root.querySelectorAll('.pj-side [data-channel]')].find((b) => b.dataset.channel === c.id), c.unread)
|
|
461
510
|
}
|
|
511
|
+
const made = () => projectChannels(p.id)
|
|
512
|
+
// The channel on the page: one someone made, by its id, or the project's own (also when that one is gone).
|
|
513
|
+
const openChannel = () => made().list.find((c) => c.id === state.projectChannel) || null
|
|
514
|
+
const ask = () => { loadChannel(p.id, newCount); loadChannels(p.id, newCount); const c = openChannel(); if (c && root.querySelector('[data-project-channel]')) loadChannel(p.id, newCount, { channel: c.id }) }
|
|
462
515
|
clearInterval(channelTimer)
|
|
463
|
-
channelTimer = setInterval(() => { if (state.view !== view || !root.isConnected) return clearInterval(channelTimer);
|
|
464
|
-
|
|
516
|
+
channelTimer = setInterval(() => { if (state.view !== view || !root.isConnected) return clearInterval(channelTimer); ask() }, 4000)
|
|
517
|
+
ask()
|
|
465
518
|
const channel = root.querySelector('[data-project-channel]')
|
|
466
|
-
if (channel) mountChannel(channel, { d, changed: newCount })
|
|
519
|
+
if (channel) mountChannel(channel, { d, changed: newCount, channel: openChannel() })
|
|
520
|
+
// A channel someone made opens as the project's own does.
|
|
521
|
+
root.querySelectorAll('.pj-side [data-channel]').forEach((b) => { b.onclick = () => { state.projectPage = 'channel'; state.projectChannel = b.dataset.channel; if (state.view === `ws:${p.id}`) rerender(); else go(`ws:${p.id}`) } })
|
|
522
|
+
// The plus beside Channels: a row to name the new one in, in the list. Enter makes it and opens it; Escape, or leaving it empty, takes the row away.
|
|
523
|
+
const plus = root.querySelector('[data-new-channel]')
|
|
524
|
+
if (plus) plus.onclick = () => { startNewChannel(p.id); rerender() }
|
|
525
|
+
bindNewChannel(root, p.id, { redraw: rerender, made: (c) => { state.projectPage = 'channel'; state.projectChannel = c.id; if (state.view === `ws:${p.id}`) rerender(); else go(`ws:${p.id}`) } })
|
|
467
526
|
// A codebase's channel, or a direct message in it: the codebase opens on its chat.
|
|
468
527
|
root.querySelectorAll('[data-go-chat]').forEach((b) => { b.onclick = () => { state.openChat = b.dataset.goChat; state.to = ''; go(b.dataset.goChat) } })
|
|
469
528
|
root.querySelectorAll('[data-go-preview]').forEach((b) => { b.onclick = () => { state.openPreview = { id: b.dataset.goPreview, preview: b.dataset.preview }; go(b.dataset.goPreview) } })
|
package/src/ui/session.js
CHANGED
|
@@ -27,7 +27,8 @@ import { sessionAgentsHtml } from './agent-place.js'
|
|
|
27
27
|
import { renderCatchUp, bindCatchUp } from './catchup.js'
|
|
28
28
|
import { heldCard } from './session-words.js'
|
|
29
29
|
import { callButtonMarkup, callPinMarkup, screenStageMarkup, mountCall, unmountCall, renderCall, callCards, callCounts, callScope } from './voice.js'
|
|
30
|
-
import { codeSideHtml, codeCrumbHtml, sideShut, toggleSideShut, drawSideShut, foldSection } from './projects.js'
|
|
30
|
+
import { codeSideHtml, codeCrumbHtml, sideShut, toggleSideShut, drawSideShut, foldSection, startNewChannel, bindNewChannel } from './projects.js'
|
|
31
|
+
import { mountChannel, loadChannel, loadChannels, channelUnread, projectChannels } from './project-channel.js'
|
|
31
32
|
import { mountPreview } from './preview-page.js'
|
|
32
33
|
import { dmThreads } from './project-model.js'
|
|
33
34
|
|
|
@@ -269,6 +270,7 @@ export function mountSession (id) {
|
|
|
269
270
|
loadNewPeople(id)
|
|
270
271
|
// Relative times ("4s ago") and recent-edit badges age out.
|
|
271
272
|
timers.push(setInterval(() => { renderTreePane(); renderTop() }, 15000))
|
|
273
|
+
if (pj()) { timers.push(setInterval(askChannels, 4000)); askChannels() }
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
export function sessionUnmount () {
|
|
@@ -418,7 +420,14 @@ function renderCodeSide () {
|
|
|
418
420
|
if (!el || !current || !sum()) return
|
|
419
421
|
const w = ws(current)
|
|
420
422
|
const st = sum().status
|
|
423
|
+
// One of its project's channels on this page ('channel:' and the id of one someone made, or nothing for the project's own).
|
|
424
|
+
// Out of the project, back to the Loom; a channel that is gone, the project's own.
|
|
425
|
+
const p = projectHere()
|
|
426
|
+
const made = p ? projectChannels(p.id) : null
|
|
427
|
+
if ((w.side || '').startsWith('channel:') && !p) w.side = ''
|
|
428
|
+
else if ((w.side || '').startsWith('channel:') && w.side !== 'channel:' && made.loaded && !made.list.some((c) => `channel:${c.id}` === w.side)) w.side = 'channel:'
|
|
421
429
|
const side = w.side || ''
|
|
430
|
+
const onChannel = side.startsWith('channel:') ? side.slice('channel:'.length) : null
|
|
422
431
|
const page = side || (w.mode === 'tasks' ? 'tasks' : 'loom')
|
|
423
432
|
const open = (st.tasks || []).filter((t) => !t.archived && (t.column === 'todo' || t.column === 'doing')).length
|
|
424
433
|
const people = [st.me, ...peopleHere(st)]
|
|
@@ -431,14 +440,23 @@ function renderCodeSide () {
|
|
|
431
440
|
// So does the conversation on screen, before anything is written in it.
|
|
432
441
|
if (side === 'chat' && state.to && !dms.some((t) => t.name === state.to)) dms.unshift({ name: state.to, ts: Date.now(), n: 0, call: 0 })
|
|
433
442
|
if ($('#chat-sub')) $('#chat-sub').textContent = chatSub(st)
|
|
434
|
-
|
|
443
|
+
// The sidebar is drawn again as the codebase changes: a channel being named keeps what was typed, and the cursor if it was there.
|
|
444
|
+
const naming = el.querySelector('[data-new-channel-form] input')
|
|
445
|
+
const caret = naming && document.activeElement === naming ? [naming.selectionStart, naming.selectionEnd] : null
|
|
446
|
+
el.innerHTML = codeSideHtml({ page, name: st.sessionName || basename(sum().dir), project: p, channels: p ? { own: channelUnread(p.id), list: made.list, canAdd: made.canAdd, naming: state.newChannel === p.id } : null, tasks: open, artifacts: (projectData()?.files || []).filter((f) => f.kind !== 'folder').length, chatNew, people, dms, dmOn: state.to || '', connections: !!state.connectionsOn, canInvite: !!st.access?.owner || st.access?.role !== 'viewer', call: calls.channel, previews: state.previewsOn ? st.previews || [] : null, canEdit: st.access?.role !== 'viewer' })
|
|
447
|
+
if (p) {
|
|
448
|
+
bindNewChannel(el, p.id, { focus: !naming || !!caret, redraw: renderCodeSide, made: (c) => showCodePage(`channel:${c.id}`) })
|
|
449
|
+
if (caret) el.querySelector('[data-new-channel-form] input')?.setSelectionRange(caret[0], caret[1])
|
|
450
|
+
}
|
|
435
451
|
const root = $('#ws')
|
|
436
452
|
root.dataset.sidePage = side
|
|
437
453
|
$('#code-crumb').innerHTML = codeCrumbHtml(projectHere())
|
|
438
|
-
// The pages drawn over the middle in their own box: Connections, and the project's
|
|
454
|
+
// The pages drawn over the middle in their own box: Connections, the project's Artifacts, and one of the project's channels.
|
|
439
455
|
// Drawn when the page changes, not every time the sidebar is: an artifact that is running stays as it is.
|
|
440
456
|
const extra = $('#code-extra')
|
|
441
|
-
|
|
457
|
+
// A channel someone made waits for the list of them, to be drawn by its name.
|
|
458
|
+
const boxed = side === 'connections' || side === 'artifacts' || side.startsWith('preview:') ? side : onChannel === null ? '' : onChannel && !made.loaded ? 'channel?' : side
|
|
459
|
+
extra.hidden = !boxed // shown before it is filled: a channel puts the cursor in its box
|
|
442
460
|
if ((extra.dataset.page || '') !== boxed) {
|
|
443
461
|
if (codeConns) { codeConns.destroy(); codeConns = null }
|
|
444
462
|
if (codePreview) { codePreview.destroy(); codePreview = null }
|
|
@@ -446,6 +464,12 @@ function renderCodeSide () {
|
|
|
446
464
|
extra.dataset.page = boxed
|
|
447
465
|
extra.classList.toggle('pj-files', boxed === 'artifacts')
|
|
448
466
|
extra.classList.toggle('pv-view', boxed.startsWith('preview:'))
|
|
467
|
+
extra.classList.toggle('pj-chat', boxed.startsWith('channel:'))
|
|
468
|
+
if (boxed === 'channel?') extra.innerHTML = `<p class="hint">${loadingNote()}</p>`
|
|
469
|
+
if (boxed.startsWith('channel:')) {
|
|
470
|
+
extra.innerHTML = '<div class="pj-chanpage" data-project-channel></div>'
|
|
471
|
+
mountChannel(extra.firstElementChild, { d: projectData() || { workspace: p }, changed: renderCodeSide, channel: made.list.find((c) => c.id === onChannel) || null })
|
|
472
|
+
}
|
|
449
473
|
if (boxed.startsWith('preview:')) {
|
|
450
474
|
const id = current
|
|
451
475
|
if (!pvPick.has(id)) pvPick.set(id, {})
|
|
@@ -466,7 +490,16 @@ function renderCodeSide () {
|
|
|
466
490
|
}
|
|
467
491
|
if (boxed === 'artifacts') { drawCodeArtifacts(); loadCodeArtifacts() }
|
|
468
492
|
} else if (codePreview) codePreview.update()
|
|
469
|
-
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** Asks for what is new in the project's channels (every few seconds while its codebase is open): the sidebar shows it, and the one on the page draws itself. */
|
|
496
|
+
function askChannels () {
|
|
497
|
+
const p = pj() && current && sum() ? projectHere() : null
|
|
498
|
+
if (!p) return
|
|
499
|
+
loadChannel(p.id, renderCodeSide)
|
|
500
|
+
loadChannels(p.id, renderCodeSide)
|
|
501
|
+
const on = (ws(current).side || '').startsWith('channel:') ? ws(current).side.slice('channel:'.length) : ''
|
|
502
|
+
if (on) loadChannel(p.id, renderCodeSide, { channel: on })
|
|
470
503
|
}
|
|
471
504
|
|
|
472
505
|
/** The project's data, when it is the one this codebase is in. */
|
|
@@ -492,7 +525,7 @@ async function loadCodeArtifacts () {
|
|
|
492
525
|
renderCodeSide()
|
|
493
526
|
}
|
|
494
527
|
|
|
495
|
-
/** Shows one of the sidebar's pages: 'loom', 'tasks', the channel ('chat'), 'connections' or the project's '
|
|
528
|
+
/** Shows one of the sidebar's pages: 'loom', 'tasks', the channel ('chat'), 'connections', the project's 'artifacts' or one of the project's channels ('channel:' and its id). */
|
|
496
529
|
function showCodePage (page) {
|
|
497
530
|
const w = ws(current)
|
|
498
531
|
const was = w.side || ''
|
|
@@ -516,6 +549,7 @@ function bindCodeSide () {
|
|
|
516
549
|
// The channel is for everyone; a direct message's row is that person alone.
|
|
517
550
|
if (b.dataset.dm !== undefined) { state.to = b.dataset.dm; showCodePage('chat'); renderRecipients(); updatePlaceholder(); return renderCodeSide() }
|
|
518
551
|
if (b.dataset.codePage) return showCodePage(b.dataset.codePage)
|
|
552
|
+
if (b.hasAttribute('data-new-channel')) { const p = projectHere(); if (p) { startNewChannel(p.id); renderCodeSide() } return }
|
|
519
553
|
if (b.hasAttribute('data-side-toggle')) { toggleSideShut(); return drawSideShut($('#ws')) }
|
|
520
554
|
if (b.dataset.fold) return foldSection(b.dataset.fold, renderCodeSide)
|
|
521
555
|
if (b.dataset.go) return go(b.dataset.go)
|
package/src/ui-server.js
CHANGED
|
@@ -21,7 +21,7 @@ import { autowork, autoConfig, publicConfig, AUTO_MODES } from './autowork.js'
|
|
|
21
21
|
import { migrateDir } from './legacy.js'
|
|
22
22
|
import { writePrivateJson } from './private-file.js'
|
|
23
23
|
import { autoToolFor } from './autowork-tools.js'
|
|
24
|
-
import { workspaceMessages, sayInWorkspace, readWorkspaceMessages } from './account.js'
|
|
24
|
+
import { workspaceMessages, sayInWorkspace, readWorkspaceMessages, workspaceChannels, addWorkspaceChannel } from './account.js'
|
|
25
25
|
import { readAccount, saveAccount, clearAccount, clearAccountIf, resumeAccount, startLink, waitForLink, signUpForLink, confirmSignUpForLink, fetchMe, signOut, revokeToken, accountFromProfile, renameSession, createAgentInvite, listAgents, agentDetails, listAccessTypes, listCollaborators, listGrants, putGrant, deleteGrant, inviteToSession, listSessionInvites, cancelSessionInvite, listWorkspaces, listOrgs, createWorkspace, getWorkspace, updateWorkspace, deleteWorkspace, putWorkspaceMember, removeWorkspaceMember, getAgentPlacement, putAgentPlacement, listOrgAgents, putWorkspaceAgent, deleteWorkspaceAgent, createWorkspaceAgentInvite, excludeSessionAgent, listExcludedSessionAgents, listSessionAgents, includeSessionAgent, setSessionWorkspace, moveSessionToWorkspace, listWorkspaceInvites, inviteToWorkspace, cancelWorkspaceInvite, listMyInvites, answerMyInvite, listMySessions, announceSessionStarted, announceWhenReported, listWorkspaceFiles, createWorkspaceFile, confirmWorkspaceFile, workspaceFileDownload, updateWorkspaceFile, deleteWorkspaceFile, createWorkspaceFolder, listWorkspaceFileVersions, listSandboxKeys, createSandboxKey, rotateSandboxKey, revokeSandboxKey, removeSandboxKey, aiVmFollow, aiVmUnfollow, aiVmStatus, aiVmConnect, aiVmUpdate, aiVmSignIn, aiVmWake, aiVmDisconnect, voiceIce, transcribeVoice, speakVoice, speakVoiceStream, openPreview, apiUrl } from './account.js'
|
|
26
26
|
import { aiName } from './persona.js'
|
|
27
27
|
import { effectiveAccess, builtinType } from './session-access.js'
|
|
@@ -866,6 +866,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
866
866
|
})
|
|
867
867
|
const needInviteId = (id) => { if (!/^[0-9a-f-]{36}$/i.test(String(id || ''))) throw httpError(400, 'Which invite?'); return String(id) }
|
|
868
868
|
const needWorkspaceId = (id) => { if (!/^[0-9a-f-]{36}$/i.test(String(id || ''))) throw httpError(400, 'Which project?'); return id }
|
|
869
|
+
const needChannelId = (id) => { if (!/^[0-9a-f-]{36}$/i.test(String(id || ''))) throw httpError(400, 'Which channel?'); return String(id) }
|
|
869
870
|
const needAgentId = (id) => { if (!/^[0-9a-f-]{36}$/i.test(String(id || ''))) throw httpError(400, 'Which agent?'); return id }
|
|
870
871
|
const needKeyId = (id) => { if (!/^[0-9a-f-]{36}$/i.test(String(id || ''))) throw httpError(400, 'Which key?'); return String(id) }
|
|
871
872
|
/**
|
|
@@ -1192,6 +1193,12 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1192
1193
|
'GET /api/workspaces/:id/messages': (b, id, url) => asAccount((token) => workspaceMessages({ token, id: needWorkspaceId(id), after: Number(url.searchParams.get('after')) || 0 })),
|
|
1193
1194
|
'POST /api/workspaces/:id/messages': (b, id) => asAccount((token) => sayInWorkspace({ token, id: needWorkspaceId(id), text: String(b.text || '').slice(0, 8000) })),
|
|
1194
1195
|
'POST /api/workspaces/:id/messages/read': (b, id) => asAccount((token) => readWorkspaceMessages({ token, id: needWorkspaceId(id) })),
|
|
1196
|
+
// The channels people made in a project, and each one's messages (the same three calls).
|
|
1197
|
+
'GET /api/workspaces/:id/channels': (b, id) => asAccount((token) => workspaceChannels({ token, id: needWorkspaceId(id) })),
|
|
1198
|
+
'POST /api/workspaces/:id/channels': (b, id) => asAccount((token) => addWorkspaceChannel({ token, id: needWorkspaceId(id), name: String(b.name || '').slice(0, 200) })),
|
|
1199
|
+
'GET /api/workspaces/:id/channels/:cid/messages': (b, id, url, cid) => asAccount((token) => workspaceMessages({ token, id: needWorkspaceId(id), channel: needChannelId(cid), after: Number(url.searchParams.get('after')) || 0 })),
|
|
1200
|
+
'POST /api/workspaces/:id/channels/:cid/messages': (b, id, url, cid) => asAccount((token) => sayInWorkspace({ token, id: needWorkspaceId(id), channel: needChannelId(cid), text: String(b.text || '').slice(0, 8000) })),
|
|
1201
|
+
'POST /api/workspaces/:id/channels/:cid/messages/read': (b, id, url, cid) => asAccount((token) => readWorkspaceMessages({ token, id: needWorkspaceId(id), channel: needChannelId(cid) })),
|
|
1195
1202
|
'GET /api/workspaces/:id/files': (b, id, url) => asAccount(async (token) => ({ files: await listWorkspaceFiles({ token, id: needWorkspaceId(id), folder: url.searchParams.get('folder') ?? undefined }) })),
|
|
1196
1203
|
'GET /api/workspaces/:id/files/:fid/versions': (b, id, url, fid) => asAccount(async (token) => ({ versions: await listWorkspaceFileVersions({ token, id: needWorkspaceId(id), fileId: fid }) })),
|
|
1197
1204
|
// The address an HTML artifact's frame loads (serveSealed): asked for by the page, with its token.
|
|
@@ -1502,6 +1509,9 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1502
1509
|
// A workspace's invite, the same way.
|
|
1503
1510
|
const iid = (url.pathname.match(/^\/api\/workspaces\/[^/]+\/invites\/([^/]+)\//) || [])[1]
|
|
1504
1511
|
if (iid) pathKey = pathKey.replace(/^(\/api\/workspaces\/:id\/invites)\/[^/]+/, '$1/:iid')
|
|
1512
|
+
// A channel someone made in a workspace, the same way.
|
|
1513
|
+
const cid = (url.pathname.match(/^\/api\/workspaces\/[^/]+\/channels\/([^/]+)\//) || [])[1]
|
|
1514
|
+
if (cid) pathKey = pathKey.replace(/^(\/api\/workspaces\/:id\/channels)\/[^/]+/, '$1/:cid')
|
|
1505
1515
|
const key = `${req.method} ${pathKey}`
|
|
1506
1516
|
const handler = api[key]
|
|
1507
1517
|
if (!handler) {
|
|
@@ -1513,7 +1523,7 @@ export async function startUi ({ port = 7420, onShutdown, preview = false, repor
|
|
|
1513
1523
|
const body = raw ? JSON.parse(raw) : {}
|
|
1514
1524
|
const startedAt = Date.now()
|
|
1515
1525
|
try {
|
|
1516
|
-
const out = await handler(body, sid, url, fid || aid || iid)
|
|
1526
|
+
const out = await handler(body, sid, url, fid || aid || iid || cid)
|
|
1517
1527
|
// A reply that streams (an agent's speech): straight through as it comes.
|
|
1518
1528
|
if (out && out[STREAMED]) {
|
|
1519
1529
|
res.writeHead(200, { 'content-type': out.type, 'cache-control': 'no-store' })
|