heyquilt 0.3.193 → 0.3.194
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 +4 -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 +5 -0
- package/src/ui/app.js +1 -1
- package/src/ui/project-channel.js +69 -21
- package/src/ui/projects.js +56 -13
- package/src/ui-server.js +12 -2
package/RELEASES.md
CHANGED
|
@@ -11,6 +11,10 @@ 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.194 — 2026-11-23
|
|
15
|
+
|
|
16
|
+
- **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.
|
|
17
|
+
|
|
14
18
|
## 0.3.193 — 2026-11-23
|
|
15
19
|
|
|
16
20
|
- **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
|
@@ -1767,6 +1767,11 @@ body.has-asks .prail { margin-top: calc(var(--update-bar, 0px) + var(--asks-bar)
|
|
|
1767
1767
|
.pj-hash { flex: none; display: inline-grid; place-items: center; width: 16px; font-weight: 600; font-size: 15px; color: var(--muted); }
|
|
1768
1768
|
.pj-side .side-sessions.pj-rooms button.on { background: var(--panel-2); font-weight: 600; }
|
|
1769
1769
|
.pj-side .pj-rooms button.on .pj-hash { color: var(--text); }
|
|
1770
|
+
/* naming a new channel, in the list where it will be */
|
|
1771
|
+
.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); }
|
|
1772
|
+
.pj-newchan:focus-within { box-shadow: inset 0 0 0 1.5px var(--accent); }
|
|
1773
|
+
.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; }
|
|
1774
|
+
.pj-newchan input::placeholder { color: var(--faint); }
|
|
1770
1775
|
.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
1776
|
.ws.pj-cb .ws-body { grid-template-columns: 244px minmax(0, 1fr); transition: grid-template-columns var(--side-slide); }
|
|
1772
1777
|
.ws.pj-cb[data-side="shut"] .ws-body { grid-template-columns: 0px minmax(0, 1fr); }
|
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,102 @@
|
|
|
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 }); 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. */
|
|
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
|
+
if (JSON.stringify([m.list, m.canAdd]) !== was) changed()
|
|
42
|
+
} catch {} // the list stays as it was: the project's own channel does not depend on it
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Makes a channel in a project. Resolves to it ({ id, name }); rejects with what the accounts API said. */
|
|
46
|
+
export async function addChannel (id, name) {
|
|
47
|
+
const r = await api('POST', `/api/workspaces/${encodeURIComponent(id)}/channels`, { name })
|
|
48
|
+
const m = madeIn(id)
|
|
49
|
+
if (!m.list.some((c) => c.id === r.channel.id)) m.list.push({ id: r.channel.id, name: r.channel.name, unread: 0 })
|
|
50
|
+
return r.channel
|
|
51
|
+
}
|
|
52
|
+
|
|
15
53
|
/**
|
|
16
54
|
* Asks for what is new in a project's channel (at most every few seconds; `now` asks at once).
|
|
17
55
|
* `changed()` is called when the count of what is new changes; the open channel draws itself.
|
|
18
56
|
*/
|
|
19
|
-
export async function loadChannel (id, changed = () => {}, { now = false } = {}) {
|
|
20
|
-
const c = chan(id)
|
|
57
|
+
export async function loadChannel (id, changed = () => {}, { now = false, channel = '' } = {}) {
|
|
58
|
+
const c = chan(id, channel)
|
|
59
|
+
const key = keyOf(id, channel)
|
|
60
|
+
// A made channel's count is the one its row in the list shows.
|
|
61
|
+
const mirror = () => { const row = channel && madeIn(id).list.find((x) => x.id === channel); if (row) row.unread = c.unread }
|
|
21
62
|
if (!now && Date.now() - c.asked < ASK_MS) return
|
|
22
63
|
c.asked = Date.now()
|
|
23
64
|
try {
|
|
24
65
|
const after = c.messages.length ? c.messages[c.messages.length - 1].at : 0
|
|
25
|
-
const r = await api('GET',
|
|
66
|
+
const r = await api('GET', `${urlOf(id, channel)}${after ? `?after=${after}` : ''}`)
|
|
26
67
|
const had = c.messages.length; const was = c.unread
|
|
27
68
|
const known = new Set(c.messages.map((m) => m.id))
|
|
28
69
|
for (const m of r.messages) if (!known.has(m.id)) c.messages.push(m)
|
|
29
70
|
c.loaded = true; c.failed = ''
|
|
30
71
|
c.unread = r.unread
|
|
31
|
-
const open = live && live.
|
|
72
|
+
const open = live && live.key === key && live.el.isConnected
|
|
32
73
|
if (open && (c.messages.length !== had || !live.drawn)) live.draw()
|
|
33
74
|
// 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',
|
|
75
|
+
if (open && c.unread && document.hasFocus()) { c.unread = 0; api('POST', `${urlOf(id, channel)}/read`).catch(() => {}) }
|
|
76
|
+
mirror()
|
|
35
77
|
if (c.unread !== was) changed()
|
|
36
78
|
} catch (err) {
|
|
37
79
|
c.failed = err.message
|
|
38
|
-
if (!c.loaded && live && live.
|
|
80
|
+
if (!c.loaded && live && live.key === key && live.el.isConnected) live.draw()
|
|
39
81
|
}
|
|
40
82
|
}
|
|
41
83
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Draws a project's channel into `el` and keeps it working: its own, or with `channel` ({ id, name })
|
|
86
|
+
* one its people made. `changed()`: the count of what is new changed (the sidebar shows it).
|
|
87
|
+
*/
|
|
88
|
+
export function mountChannel (el, { d, changed = () => {}, channel = null }) {
|
|
44
89
|
const id = d.workspace.id
|
|
45
|
-
const
|
|
90
|
+
const cid = channel ? channel.id : ''
|
|
91
|
+
const title = channel ? channel.name : d.workspace.name
|
|
92
|
+
const c = chan(id, cid)
|
|
46
93
|
const me = state.profile?.name || ''
|
|
47
94
|
const names = () => [...new Set([d.owner?.name, ...(d.members || []).map((m) => m.name), ...(d.agents || []).map((a) => a.name)].filter(Boolean))]
|
|
48
95
|
el.innerHTML = `
|
|
49
96
|
<div class="pj-chan">
|
|
50
|
-
<div class="files-head"><div class="t"><h2 class="crumbs"><span class="pj-hash">#</span>${esc(
|
|
97
|
+
<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
98
|
<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(
|
|
99
|
+
<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
100
|
</div>`
|
|
54
101
|
const list = $('[data-chan-list]', el)
|
|
55
102
|
const box = $('textarea', el)
|
|
@@ -62,7 +109,7 @@ export function mountChannel (el, { d, changed = () => {} }) {
|
|
|
62
109
|
if (near || !live.drawn) list.scrollTop = list.scrollHeight
|
|
63
110
|
live.drawn = true
|
|
64
111
|
}
|
|
65
|
-
live = { el, id, draw, drawn: false }
|
|
112
|
+
live = { el, key: keyOf(id, cid), draw, drawn: false }
|
|
66
113
|
draw()
|
|
67
114
|
const grow = () => { box.style.height = 'auto'; box.style.height = `${Math.min(box.scrollHeight, 160)}px` }
|
|
68
115
|
// The page is drawn again when a codebase's state changes: what was being typed is put back.
|
|
@@ -76,15 +123,16 @@ export function mountChannel (el, { d, changed = () => {} }) {
|
|
|
76
123
|
if (!text) return
|
|
77
124
|
box.value = ''; c.draft = ''; grow()
|
|
78
125
|
try {
|
|
79
|
-
const r = await api('POST',
|
|
126
|
+
const r = await api('POST', urlOf(id, cid), { text })
|
|
80
127
|
if (!c.messages.some((m) => m.id === r.message.id)) c.messages.push(r.message)
|
|
81
128
|
draw(); list.scrollTop = list.scrollHeight
|
|
82
129
|
} catch (err) { toast(err.message); if (!box.value) { box.value = text; c.draft = text; grow() } }
|
|
83
130
|
box.focus()
|
|
84
131
|
}
|
|
85
132
|
// Opening it is reading it.
|
|
86
|
-
const
|
|
87
|
-
|
|
133
|
+
const row = () => (cid ? madeIn(id).list.find((x) => x.id === cid) : null)
|
|
134
|
+
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(() => {}) }
|
|
135
|
+
loadChannel(id, changed, { now: true, channel: cid }).then(read)
|
|
88
136
|
// Coming back to the window with the channel open is reading it.
|
|
89
137
|
const onFocus = () => { if (!el.isConnected) return window.removeEventListener('focus', onFocus); read() }
|
|
90
138
|
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'
|
|
@@ -223,7 +223,11 @@ function sideHtml (p, d, page) {
|
|
|
223
223
|
// Channels: the project's own (kept by the accounts API), then one for each codebase open here (its chat).
|
|
224
224
|
const open = list.filter((c) => c.where === 'open')
|
|
225
225
|
const own = channelUnread(p.id)
|
|
226
|
-
|
|
226
|
+
// The channels people made here, after the project's own; the one that is open, by its id.
|
|
227
|
+
const made = projectChannels(p.id)
|
|
228
|
+
const onChannel = page === 'channel' ? (made.list.some((c) => c.id === state.projectChannel) ? state.projectChannel : '') : null
|
|
229
|
+
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)
|
|
230
|
+
const naming = state.newChannel === p.id && made.canAdd
|
|
227
231
|
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
232
|
// Direct messages, across the codebases open here: a row opens that codebase's chat on them.
|
|
229
233
|
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 || '' })))
|
|
@@ -240,9 +244,11 @@ function sideHtml (p, d, page) {
|
|
|
240
244
|
<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
245
|
${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
246
|
<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,
|
|
247
|
+
${label('channels', 'Channels', newHere, made.canAdd ? `<button type="button" class="btn sm ghost icon" data-new-channel title="New channel" aria-label="New channel">${I.plus}</button>` : '')}
|
|
248
|
+
<div class="side-sessions pj-rooms">${isFolded('channels') && page !== 'channel' && !newHere && !naming ? '' : `
|
|
249
|
+
${isFolded('channels') && onChannel !== '' && !own ? '' : room(`data-page="channel" title="Everyone in ${esc(p.name)}"`, p.name, own, onChannel === '')}
|
|
250
|
+
${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('')}
|
|
251
|
+
${naming ? `<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>` : ''}
|
|
246
252
|
${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
253
|
${dms.length ? `${label('dms', 'Direct messages')}
|
|
248
254
|
<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>` : ''}
|
|
@@ -435,6 +441,7 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
|
|
|
435
441
|
b.onclick = () => {
|
|
436
442
|
const page = b.dataset.page
|
|
437
443
|
state.projectPage = page === 'connections' || page === 'tasks' || page === 'channel' ? page : ''
|
|
444
|
+
state.projectChannel = '' // the project's own channel
|
|
438
445
|
const to = page === 'artifacts' ? `wsfiles:${p.id}` : `ws:${p.id}`
|
|
439
446
|
if (to === state.view) rerender(); else go(to)
|
|
440
447
|
}
|
|
@@ -453,17 +460,53 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
|
|
|
453
460
|
// 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
461
|
const newCount = () => {
|
|
455
462
|
if (state.view !== view) return
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
463
|
+
// A channel was made (here or by someone else): the list is drawn again, unless it would take what is being typed.
|
|
464
|
+
const rows = [...root.querySelectorAll('.pj-side [data-channel]')].map((b) => b.dataset.channel).join(' ')
|
|
465
|
+
const typing = root.querySelector('[data-project-channel] textarea')?.value || root.querySelector('[data-new-channel-form] input')
|
|
466
|
+
if (!root.querySelector('[data-project-channel]') || (rows !== made().list.map((c) => c.id).join(' ') && !typing)) return rerender()
|
|
467
|
+
const count = (row, n) => {
|
|
468
|
+
if (!row) return
|
|
469
|
+
row.querySelector('.ct')?.remove()
|
|
470
|
+
if (n) row.insertAdjacentHTML('beforeend', `<span class="ct new">${n > 99 ? '99+' : n}</span>`)
|
|
471
|
+
}
|
|
472
|
+
count(root.querySelector('[data-page="channel"]'), channelUnread(p.id))
|
|
473
|
+
for (const c of made().list) count([...root.querySelectorAll('.pj-side [data-channel]')].find((b) => b.dataset.channel === c.id), c.unread)
|
|
461
474
|
}
|
|
475
|
+
const made = () => projectChannels(p.id)
|
|
476
|
+
// The channel on the page: one someone made, by its id, or the project's own (also when that one is gone).
|
|
477
|
+
const openChannel = () => made().list.find((c) => c.id === state.projectChannel) || null
|
|
478
|
+
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
479
|
clearInterval(channelTimer)
|
|
463
|
-
channelTimer = setInterval(() => { if (state.view !== view || !root.isConnected) return clearInterval(channelTimer);
|
|
464
|
-
|
|
480
|
+
channelTimer = setInterval(() => { if (state.view !== view || !root.isConnected) return clearInterval(channelTimer); ask() }, 4000)
|
|
481
|
+
ask()
|
|
465
482
|
const channel = root.querySelector('[data-project-channel]')
|
|
466
|
-
if (channel) mountChannel(channel, { d, changed: newCount })
|
|
483
|
+
if (channel) mountChannel(channel, { d, changed: newCount, channel: openChannel() })
|
|
484
|
+
// A channel someone made opens as the project's own does.
|
|
485
|
+
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}`) } })
|
|
486
|
+
// 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.
|
|
487
|
+
const plus = root.querySelector('[data-new-channel]')
|
|
488
|
+
if (plus) plus.onclick = () => { if (foldedNow().has('channels')) toggleFolded('channels'); state.newChannel = p.id; state.newChannelDraft = ''; rerender() }
|
|
489
|
+
const naming = root.querySelector('[data-new-channel-form]')
|
|
490
|
+
if (naming) {
|
|
491
|
+
const box = naming.elements.name
|
|
492
|
+
const stop = () => { state.newChannel = null; state.newChannelDraft = ''; rerender() }
|
|
493
|
+
box.focus(); box.setSelectionRange(box.value.length, box.value.length)
|
|
494
|
+
box.oninput = () => { state.newChannelDraft = box.value }
|
|
495
|
+
box.onkeydown = (e) => { if (e.key === 'Escape') { e.preventDefault(); stop() } }
|
|
496
|
+
box.onblur = () => { if (!box.value.trim() && state.newChannel === p.id && root.isConnected && !naming.dataset.busy) setTimeout(() => { if (document.activeElement !== box && box.isConnected) stop() }, 0) }
|
|
497
|
+
naming.onsubmit = async (e) => {
|
|
498
|
+
e.preventDefault()
|
|
499
|
+
const name = box.value.trim()
|
|
500
|
+
if (!name || naming.dataset.busy) return
|
|
501
|
+
naming.dataset.busy = '1'
|
|
502
|
+
try {
|
|
503
|
+
const made = await addChannel(p.id, name)
|
|
504
|
+
state.newChannel = null; state.newChannelDraft = ''
|
|
505
|
+
state.projectPage = 'channel'; state.projectChannel = made.id
|
|
506
|
+
if (state.view === `ws:${p.id}`) rerender(); else go(`ws:${p.id}`)
|
|
507
|
+
} catch (err) { delete naming.dataset.busy; toast(err.message); box.focus() }
|
|
508
|
+
}
|
|
509
|
+
}
|
|
467
510
|
// A codebase's channel, or a direct message in it: the codebase opens on its chat.
|
|
468
511
|
root.querySelectorAll('[data-go-chat]').forEach((b) => { b.onclick = () => { state.openChat = b.dataset.goChat; state.to = ''; go(b.dataset.goChat) } })
|
|
469
512
|
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-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' })
|