heyquilt 0.3.192 → 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 +10 -0
- package/desktop/main.js +21 -4
- package/package.json +1 -1
- package/src/account.js +19 -6
- package/src/api/memory-store.js +31 -0
- package/src/api/routes/connections.js +9 -0
- package/src/api/routes/workspace-chat.js +75 -3
- package/src/api/supabase-store.js +36 -0
- package/src/ui/app.css +64 -19
- package/src/ui/app.js +1 -1
- package/src/ui/connections.js +124 -39
- package/src/ui/home.js +14 -1
- package/src/ui/project-channel.js +69 -21
- package/src/ui/projects.js +58 -15
- package/src/ui/releases.js +30 -5
- package/src/ui/session.js +2 -2
- package/src/ui-server.js +17 -2
package/src/ui/connections.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// Connections in the app (a project's and a codebase's Connections page, and the pop-ups' Connections
|
|
2
|
+
// cards): apps people connect for a session, workspace or team through Composio, which keeps the
|
|
3
3
|
// sign-ins (plans/app-connections.md). Agents use them with quilt_apps / quilt_app_tools /
|
|
4
4
|
// quilt_app_call. Also the approval card an app action waiting for a person draws in the chat.
|
|
5
|
+
// What is connected shows as the same tiles as on a project's Overview (projects.js), each with who
|
|
6
|
+
// may use it; "Connect an app" opens the apps to pick from, in the page.
|
|
5
7
|
// A person's own connections ({ type: 'account', id: 'me' }) are for every project of theirs. A
|
|
6
8
|
// connection is for people and agents, for people only, or for the agents chosen for it.
|
|
7
9
|
import { api, esc, toast, ago, I } from './common.js'
|
|
@@ -9,9 +11,13 @@ import { api, esc, toast, ago, I } from './common.js'
|
|
|
9
11
|
const SEARCH_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>'
|
|
10
12
|
|
|
11
13
|
const views = new Map() // `${type}:${id}` -> the last view, so a redraw shows it at once
|
|
14
|
+
const appInfo = new Map() // an app's slug -> { app, actions } once asked, or { error }: what it is and what agents can do with it
|
|
15
|
+
const ACTS_SHOWN = 8
|
|
16
|
+
const BACK_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m15 18-6-6 6-6"/></svg>'
|
|
12
17
|
const urlOf = (type, id, rest = '') => `/api/connections/${type}/${encodeURIComponent(id)}${rest}`
|
|
13
|
-
|
|
14
|
-
const
|
|
18
|
+
// Where a connection is from, on its tile: the ones made here, and the ones this place gets from above.
|
|
19
|
+
const HERE = { session: 'This codebase', workspace: 'This project', org: 'This team', account: 'Every project' }
|
|
20
|
+
const ABOVE = { workspace: 'This project', org: 'Team', account: 'Every project' }
|
|
15
21
|
|
|
16
22
|
// Your agents, asked once: who a connection can be for. A page that knows more (a project's agents) hands them in.
|
|
17
23
|
let mine = null
|
|
@@ -27,17 +33,20 @@ export function whoWords (c, names = new Map()) {
|
|
|
27
33
|
const STATUS = { active: 'Connected', pending: 'Waiting for sign-in', failed: 'Didn\'t connect' }
|
|
28
34
|
const SHOWN = 12
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
// An app's face: its logo on a white tile, as on a project's Overview; its first letter without one.
|
|
37
|
+
const logoHtml = (a) => `<span class="pj-face md sq">${a.logo
|
|
38
|
+
? `<img src="${esc(a.logo)}" alt="" loading="lazy" referrerpolicy="no-referrer">`
|
|
39
|
+
: `<i class="show">${esc(String(a.name || a.app || a.slug || '?').slice(0, 1).toUpperCase())}</i>`}</span>`
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Draws the card into `root` for one scope ({ type, id }: a session's room, a workspace's id, a
|
|
36
43
|
* team's slug, or 'account' with 'me'). `agents()`: more agents a connection here can be for
|
|
37
|
-
* ([{ id, name }]: a project's), besides your own.
|
|
44
|
+
* ([{ id, name }]: a project's), besides your own. `page`: { title, hint } when it is a page of its
|
|
45
|
+
* own, which then gets its heading with "Connect an app" in it. Answers { refresh, destroy }.
|
|
38
46
|
*/
|
|
39
|
-
export function mountConnections (root, { type, id, agents = () => [] }) {
|
|
40
|
-
|
|
47
|
+
export function mountConnections (root, { type, id, agents = () => [], page = null }) {
|
|
48
|
+
// `adding`: the apps to pick from are open (null: not chosen yet, so open when nothing is connected).
|
|
49
|
+
const ui = { search: '', apps: null, appsFor: null, more: false, busy: '', error: '', calls: null, confirm: null, choosing: null, yours: [], adding: null, entering: false, app: null, allActs: false }
|
|
41
50
|
/** The agents a connection here can be for, once each. */
|
|
42
51
|
const choices = () => { const seen = new Map(); for (const a of [...agents(), ...ui.yours]) if (a && a.id && !seen.has(a.id)) seen.set(a.id, a.name || 'an agent'); return seen }
|
|
43
52
|
let view = views.get(`${type}:${id}`) || null
|
|
@@ -46,61 +55,109 @@ export function mountConnections (root, { type, id, agents = () => [] }) {
|
|
|
46
55
|
let searchTimer = null
|
|
47
56
|
|
|
48
57
|
function connectedHtml (c, own) {
|
|
49
|
-
const status = c.status === 'active' ? '' : `<span class="cn-state ${esc(c.status)}">${esc(STATUS[c.status] || c.status)}</span>`
|
|
50
58
|
const names = choices()
|
|
59
|
+
const mayChange = own && c.mayChange
|
|
60
|
+
const active = c.status === 'active'
|
|
51
61
|
// Chosen agents: the ones it is for are ticked; a tick saves at once, and at least one stays ticked.
|
|
52
|
-
const picking =
|
|
62
|
+
const picking = mayChange && active && (c.who === 'agents' || ui.choosing === c.id)
|
|
53
63
|
const value = picking ? 'agents' : c.who
|
|
54
|
-
const who = own && c.mayChange && c.status === 'active'
|
|
55
|
-
? `<select class="input sm" data-who="${esc(c.id)}" aria-label="Who may use ${esc(c.name)}"><option value="all"${value === 'all' ? ' selected' : ''}>People and agents</option><option value="agents"${value === 'agents' ? ' selected' : ''}>People and chosen agents</option><option value="people"${value === 'people' ? ' selected' : ''}>People only</option></select>`
|
|
56
|
-
: `<span class="hint">${esc(whoWords(c, names))}</span>`
|
|
57
64
|
const chosen = new Set(c.who === 'agents' ? c.agents || [] : [])
|
|
58
65
|
for (const a of chosen) if (!names.has(a)) names.set(a, 'an agent')
|
|
59
|
-
|
|
66
|
+
// Top right: how it stands while it is not connected, else the way to remove it.
|
|
67
|
+
const corner = !active
|
|
68
|
+
? `<span class="cn-state ${esc(c.status)}">${esc(STATUS[c.status] || c.status)}</span>`
|
|
69
|
+
: mayChange && ui.confirm !== c.id ? `<button class="btn sm ghost icon cn-remove" data-ask-remove="${esc(c.id)}" title="Remove ${esc(c.name)}" aria-label="Remove ${esc(c.name)}">${I.trash}</button>` : ''
|
|
70
|
+
const where = own ? HERE[type] || '' : c.level === 'org' ? c.levelName || ABOVE.org : ABOVE[c.level] || c.levelName || ''
|
|
71
|
+
const pills = `${where ? `<span class="pill pj-scope${own ? ' own' : ''}"${!own && c.levelName ? ` title="Connected for ${esc(c.levelName)}"` : ''}>${esc(where)}</span>` : ''}${mayChange && active ? '' : `<span class="pill pj-scope" title="Who may use it">${esc(whoWords(c, names))}</span>`}`
|
|
72
|
+
const who = !(mayChange && active) ? '' : ui.confirm === c.id
|
|
73
|
+
? `<div class="cn-confirm"><span>Remove it?</span><button class="btn sm danger" data-remove="${esc(c.id)}">Remove</button><button class="btn sm ghost" data-cancel>Keep</button></div>`
|
|
74
|
+
: `<div class="cn-who"><select class="input sm" data-who="${esc(c.id)}" aria-label="Who may use ${esc(c.name)}"><option value="all"${value === 'all' ? ' selected' : ''}>People and agents</option><option value="agents"${value === 'agents' ? ' selected' : ''}>People and chosen agents</option><option value="people"${value === 'people' ? ' selected' : ''}>People only</option></select></div>`
|
|
75
|
+
const pick = !picking || ui.confirm === c.id ? '' : `<div class="cn-agents" role="group" aria-label="The agents that may use ${esc(c.name)}">${names.size
|
|
60
76
|
? [...names].map(([aid, name]) => `<label class="cn-agent"><input type="checkbox" data-agent-of="${esc(c.id)}" value="${esc(aid)}"${chosen.has(aid) ? ' checked' : ''}><span>${esc(name)}</span></label>`).join('')
|
|
61
77
|
: '<span class="hint">You have no agents yet.</span>'}${chosen.size ? '' : '<span class="hint">Tick the agents that may use it. Until then it stays as it was.</span>'}</div>`
|
|
62
|
-
|
|
78
|
+
// A connection that waits for its sign-in or did not connect can still be removed.
|
|
79
|
+
const stuck = mayChange && !active
|
|
63
80
|
? (ui.confirm === c.id
|
|
64
|
-
? `<
|
|
65
|
-
: `<button class="btn sm ghost
|
|
81
|
+
? `<div class="cn-confirm"><span>Remove it?</span><button class="btn sm danger" data-remove="${esc(c.id)}">Remove</button><button class="btn sm ghost" data-cancel>Keep</button></div>`
|
|
82
|
+
: `<div class="cn-who"><button class="btn sm ghost" data-ask-remove="${esc(c.id)}">${I.trash}<span>Remove</span></button></div>`)
|
|
66
83
|
: ''
|
|
67
|
-
return `<div class="cn-
|
|
68
|
-
<
|
|
69
|
-
<
|
|
84
|
+
return `<div class="pj-app cn-tile${active ? '' : ' off'}">${logoHtml(c)}<span class="cn-corner">${corner}</span>
|
|
85
|
+
<b title="${esc(c.name)}">${esc(c.name)}</b><span class="hint">${active ? 'Connected' : 'Started'} by ${esc(c.by)}${own ? ` · ${esc(ago(c.createdAt))}` : ''}</span>
|
|
86
|
+
<span class="pj-pills">${pills}</span>${who}${stuck}${pick}</div>`
|
|
70
87
|
}
|
|
71
88
|
|
|
89
|
+
// An app to connect: its name opens what it is and what it does; Connect connects it straight away.
|
|
72
90
|
function appHtml (a, connected) {
|
|
73
91
|
const busy = ui.busy === a.slug
|
|
74
|
-
return `<div class="cn-app"
|
|
75
|
-
<button class="btn sm
|
|
92
|
+
return `<div class="cn-app"><button type="button" class="cn-app-open" data-app="${esc(a.slug)}" title="See what ${esc(a.name)} does">${logoHtml(a)}<b>${esc(a.name)}</b></button>
|
|
93
|
+
<button type="button" class="btn sm ghost cn-go" data-connect="${esc(a.slug)}"${busy ? ' disabled' : ''}>${busy ? 'Opening…' : connected ? 'Add another' : 'Connect'}</button></div>`
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One app, opened from the apps to pick from: what it is, and what agents could do with it once it is connected. */
|
|
97
|
+
function appDetailHtml (ownApps) {
|
|
98
|
+
const slug = ui.app
|
|
99
|
+
const info = appInfo.get(slug)
|
|
100
|
+
const a = (info && info.app) || (ui.apps || []).find((x) => x.slug === slug) || { slug, name: slug }
|
|
101
|
+
const busy = ui.busy === slug
|
|
102
|
+
const acts = (info && info.actions) || []
|
|
103
|
+
const list = (title, hint, items) => {
|
|
104
|
+
const shown = ui.allActs ? items : items.slice(0, ACTS_SHOWN)
|
|
105
|
+
return `<div class="cn-acts"><h4>${title}<i>${items.length}</i></h4><p class="hint">${hint}</p>${items.length
|
|
106
|
+
? `<ul>${shown.map((x) => `<li><b>${esc(x.name)}</b>${x.description ? `<span title="${esc(x.description)}">${esc(x.description)}</span>` : ''}</li>`).join('')}</ul>`
|
|
107
|
+
: '<p class="hint cn-none">None.</p>'}</div>`
|
|
108
|
+
}
|
|
109
|
+
const reads = acts.filter((x) => x.readOnly)
|
|
110
|
+
const asks = acts.filter((x) => !x.readOnly)
|
|
111
|
+
const more = !ui.allActs && (reads.length > ACTS_SHOWN || asks.length > ACTS_SHOWN)
|
|
112
|
+
return `<section class="cn-add cn-detail${ui.entering ? ' enter' : ''}" data-add-panel aria-label="${esc(a.name)}">
|
|
113
|
+
<div class="cn-add-head"><button type="button" class="btn sm ghost cn-back" data-app-back>${BACK_ICON}<span>All apps</span></button><span class="spacer"></span><button type="button" class="btn sm ghost icon" data-add-close title="Close" aria-label="Close">${I.x}</button></div>
|
|
114
|
+
<div class="cn-app-top">${logoHtml(a)}<div class="t"><h3>${esc(a.name)}</h3>${a.description ? `<p class="hint">${esc(a.description)}</p>` : ''}</div>
|
|
115
|
+
<button type="button" class="btn primary" data-connect="${esc(slug)}"${busy ? ' disabled' : ''}>${busy ? 'Opening…' : ownApps.has(slug) ? 'Add another' : 'Connect'}</button></div>
|
|
116
|
+
${!info ? '<p class="hint">Loading what it can do…</p>' : info.error ? `<p class="hint">${esc(info.error)}</p>` : `<div class="cn-acts-grid">
|
|
117
|
+
${list('Reads', 'Agents do these at once.', reads)}${list('Sends, changes or deletes', 'Agents ask a person here first, each time.', asks)}</div>
|
|
118
|
+
${more ? `<button type="button" class="btn sm ghost cn-more" data-all-acts>Show all ${acts.length}${acts.length >= 100 ? '+' : ''} actions</button>` : ''}`}
|
|
119
|
+
</section>`
|
|
76
120
|
}
|
|
77
121
|
|
|
78
122
|
function callsHtml () {
|
|
79
123
|
if (type !== 'session' || !ui.calls || !ui.calls.length) return ''
|
|
80
124
|
const word = { waiting: 'waiting for approval', approved: 'approved', declined: 'declined', ran: 'ran', failed: 'failed' }
|
|
81
|
-
return `<section class="cn-sec"><
|
|
125
|
+
return `<section class="cn-sec"><h3>What agents did in apps</h3><div class="cn-calls">${ui.calls.slice(0, 20).map((c) => `<div class="cn-call">
|
|
82
126
|
<span class="cn-call-state ${esc(c.state)}">${esc(word[c.state] || c.state)}</span><code>${esc(c.tool)}</code><span class="hint">by ${esc(c.by)}${c.decidedBy ? ` · ${c.state === 'declined' ? 'declined' : 'approved'} by ${esc(c.decidedBy)}` : ''} · ${esc(ago(c.at))}</span></div>`).join('')}</div></section>`
|
|
83
127
|
}
|
|
84
128
|
|
|
129
|
+
/** The apps to pick from: a search across the page, then a tile an app. */
|
|
130
|
+
function addHtml (ownApps, first) {
|
|
131
|
+
if (ui.app) return appDetailHtml(ownApps)
|
|
132
|
+
const apps = ui.apps || []
|
|
133
|
+
const shown = ui.more || ui.search ? apps : apps.slice(0, SHOWN)
|
|
134
|
+
return `<section class="cn-add${ui.entering ? ' enter' : ''}" data-add-panel aria-label="Connect an app">
|
|
135
|
+
<div class="cn-add-head"><h3>${first ? 'Connect your first app' : 'Connect an app'}</h3><span class="hint">You sign in to it in your browser. Agents never see the login.</span><span class="spacer"></span>${first ? '' : `<button type="button" class="btn sm ghost icon" data-add-close title="Close" aria-label="Close">${I.x}</button>`}</div>
|
|
136
|
+
<label class="cn-search">${SEARCH_ICON}<input class="input" data-search placeholder="Search thousands of apps" value="${esc(ui.search)}" aria-label="Search apps" autocomplete="off" spellcheck="false"></label>
|
|
137
|
+
${ui.apps === null ? '<p class="hint">Loading apps…</p>' : shown.length ? `<div class="cn-apps">${shown.map((a) => appHtml(a, ownApps.has(a.slug))).join('')}</div>` : `<p class="hint">No app matches "${esc(ui.search)}".</p>`}
|
|
138
|
+
${!ui.search && !ui.more && apps.length > SHOWN ? '<button type="button" class="btn sm ghost cn-more" data-more>Show more apps</button>' : ''}</section>`
|
|
139
|
+
}
|
|
140
|
+
|
|
85
141
|
function draw () {
|
|
86
142
|
if (!alive) return
|
|
87
143
|
const had = root.contains(document.activeElement) && document.activeElement.matches('[data-search]')
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
144
|
+
const canAdd = !!view && view.canManage
|
|
145
|
+
const own = view ? view.connections || [] : []
|
|
146
|
+
const above = view ? view.inherited || [] : []
|
|
147
|
+
const none = !own.length && !above.length
|
|
148
|
+
const adding = canAdd && (ui.adding ?? none)
|
|
149
|
+
const head = page ? `<div class="files-head"><div class="t"><h2 class="crumbs">${esc(page.title)}</h2><p class="hint">${esc(page.hint)}</p></div><span class="spacer"></span>${canAdd && !none ? `<button type="button" class="btn sm primary" data-add aria-expanded="${adding}">${I.plus}<span>Connect an app</span></button>` : ''}</div>` : ''
|
|
150
|
+
if (!view) { root.innerHTML = `<div class="cn">${head}<p class="hint">${esc(ui.error || 'Loading connections…')}</p></div>`; return }
|
|
91
151
|
const ownApps = new Set(own.map((c) => c.app))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
${own.length ? `<section class="cn-sec"><h4>Connected here <i>${own.length}</i></h4><div class="cn-grid">${own.map((c) => connectedHtml(c, true)).join('')}</div></section>` : ''}
|
|
97
|
-
${(view.inherited || []).length ? `<section class="cn-sec"><h4>From above</h4><div class="cn-grid">${view.inherited.map((c) => connectedHtml(c, false)).join('')}</div></section>` : ''}
|
|
98
|
-
${view.canManage ? `<section class="cn-sec"><div class="cn-head"><h4>Add an app</h4><label class="cn-search">${SEARCH_ICON}<input class="input" data-search placeholder="Search thousands of apps" value="${esc(ui.search)}" aria-label="Search apps"></label></div>
|
|
99
|
-
${ui.apps === null ? '<p class="hint">Loading apps…</p>' : shown.length ? `<div class="cn-apps">${shown.map((a) => appHtml(a, ownApps.has(a.slug))).join('')}</div>` : `<p class="hint">No app matches "${esc(ui.search)}".</p>`}
|
|
100
|
-
${!ui.search && !ui.more && apps.length > SHOWN ? '<button class="btn sm ghost" data-more>Show more apps</button>' : ''}</section>` : ''}
|
|
152
|
+
root.innerHTML = `<div class="cn">${head}
|
|
153
|
+
${none ? (canAdd ? '' : '<p class="hint">Nothing is connected here yet.</p>') : `<div class="cn-tiles">${own.map((c) => connectedHtml(c, true)).join('')}${above.map((c) => connectedHtml(c, false)).join('')}
|
|
154
|
+
${canAdd && !adding ? `<button type="button" class="pj-app pj-slot" data-add aria-expanded="false"><span class="pj-plus">${I.plus}</span><span>Connect an app</span></button>` : ''}</div>`}
|
|
155
|
+
${adding ? addHtml(ownApps, none) : ''}
|
|
101
156
|
${callsHtml()}
|
|
157
|
+
<p class="hint cn-note">${I.lock}<span>Agents read at once, and ask a person here before they send, change or delete anything. Composio keeps each sign-in: Quilt never sees it.</span></p>
|
|
102
158
|
</div>`
|
|
103
|
-
|
|
159
|
+
ui.entering = false
|
|
160
|
+
if (had) { const s = root.querySelector('[data-search]'); if (s) { s.focus(); s.setSelectionRange(s.value.length, s.value.length) } }
|
|
104
161
|
}
|
|
105
162
|
|
|
106
163
|
yourAgents().then((list) => { ui.yours = list; if (alive && view) draw() })
|
|
@@ -155,7 +212,22 @@ export function mountConnections (root, { type, id, agents = () => [] }) {
|
|
|
155
212
|
try { await api('PATCH', urlOf(type, id, `/${sel.dataset.who}`), { who: sel.value }); load() } catch (err) { toast(err.message); load() }
|
|
156
213
|
})
|
|
157
214
|
|
|
215
|
+
/** Opens one app: what it is and what it does, asked once. */
|
|
216
|
+
async function openApp (slug) {
|
|
217
|
+
ui.app = slug
|
|
218
|
+
ui.allActs = false
|
|
219
|
+
draw()
|
|
220
|
+
root.querySelector('[data-app-back]')?.focus()
|
|
221
|
+
if (appInfo.has(slug)) return
|
|
222
|
+
try { appInfo.set(slug, await api('GET', `/api/connections/apps/${encodeURIComponent(slug)}`)) } catch (err) { appInfo.set(slug, { error: `Couldn't load what it can do. ${err.message}` }); setTimeout(() => appInfo.delete(slug), 5000) }
|
|
223
|
+
if (ui.app === slug) draw()
|
|
224
|
+
}
|
|
225
|
+
|
|
158
226
|
root.addEventListener('click', async (e) => {
|
|
227
|
+
const open = e.target.closest('[data-app]')
|
|
228
|
+
if (open) return openApp(open.dataset.app)
|
|
229
|
+
if (e.target.closest('[data-app-back]')) { const was = ui.app; ui.app = null; draw(); [...root.querySelectorAll('[data-app]')].find((b) => b.dataset.app === was)?.focus(); return }
|
|
230
|
+
if (e.target.closest('[data-all-acts]')) { ui.allActs = true; draw(); return }
|
|
159
231
|
const c = e.target.closest('[data-connect]')
|
|
160
232
|
if (c) {
|
|
161
233
|
ui.busy = c.dataset.connect
|
|
@@ -179,7 +251,20 @@ export function mountConnections (root, { type, id, agents = () => [] }) {
|
|
|
179
251
|
load()
|
|
180
252
|
return
|
|
181
253
|
}
|
|
182
|
-
if (e.target.closest('[data-more]')) { ui.more = true; draw() }
|
|
254
|
+
if (e.target.closest('[data-more]')) { ui.more = true; draw(); return }
|
|
255
|
+
// "Connect an app" opens the apps to pick from, in the page, with the search ready to type in.
|
|
256
|
+
if (e.target.closest('[data-add]')) {
|
|
257
|
+
ui.adding = !(ui.adding ?? false)
|
|
258
|
+
ui.app = null
|
|
259
|
+
ui.entering = ui.adding
|
|
260
|
+
draw()
|
|
261
|
+
if (ui.adding) { const box = root.querySelector('[data-search]'); box?.focus(); root.querySelector('[data-add-panel]')?.scrollIntoView({ block: 'nearest', behavior: 'smooth' }) }
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
if (e.target.closest('[data-add-close]')) { ui.adding = false; ui.app = null; ui.search = ''; draw(); loadApps() }
|
|
265
|
+
})
|
|
266
|
+
root.addEventListener('keydown', (e) => {
|
|
267
|
+
if (e.key === 'Escape' && e.target.matches('[data-search]') && ui.adding) { ui.adding = false; ui.search = ''; draw(); loadApps(); root.querySelector('[data-add]')?.focus() }
|
|
183
268
|
})
|
|
184
269
|
|
|
185
270
|
draw()
|
package/src/ui/home.js
CHANGED
|
@@ -5,7 +5,7 @@ import { go, pickFolder, signedOutNow, agentInviteHtml } from './app.js'
|
|
|
5
5
|
import { agentPaste } from './invite.js'
|
|
6
6
|
import { openKindMenu, kindLineHtml } from './agent-kinds.js'
|
|
7
7
|
import { quiltMark } from './mark.js'
|
|
8
|
-
import { updateControl } from './releases.js'
|
|
8
|
+
import { updateControl, downloadAhead } from './releases.js'
|
|
9
9
|
import { workspacesHtml, bindWorkspaces, workspacePageHtml, bindWorkspacePage, loadWorkspaces, openWorkspace, wsIdOf, COLORS } from './workspaces.js'
|
|
10
10
|
import { allFilesHtml, bindAllFiles } from './files.js'
|
|
11
11
|
import { invitesHtml, bindInvites } from './invites.js'
|
|
@@ -814,6 +814,7 @@ function settingsHtml (session = null) {
|
|
|
814
814
|
<div class="sec-intro"><h2>About Quilt</h2><p>${state.release?.outOfDate ? `Quilt ${esc(state.release.latest.version)} is out.` : 'The version on this computer.'}</p></div>
|
|
815
815
|
<div class="sec-body">
|
|
816
816
|
<div class="kv"><span>Version</span><span>${esc(state.release?.version || '…')}${state.release?.outOfDate ? ` <span class="pill warn">update available</span>` : state.release ? ' <span class="pill">up to date</span>' : ''}</span></div>
|
|
817
|
+
${window.quiltDesktop?.downloadUpdate && !window.quiltDesktop.dev ? `<div class="row">${toggle('autoUpdate', !!p.autoUpdate, 'Download updates automatically', 'A newer Quilt is downloaded as soon as it is out. You restart when you like: nothing is installed without you.')}</div>` : ''}
|
|
817
818
|
<div class="sec-actions"><span class="hint">Everything that changed, release by release.</span><span class="row">
|
|
818
819
|
${state.release?.outOfDate ? updateControl() : ''}
|
|
819
820
|
<button class="btn" type="button" data-release-notes>${I.sparkle}<span>What's new</span></button></span></div>
|
|
@@ -1025,6 +1026,18 @@ function bindSettings (root, refresh) {
|
|
|
1025
1026
|
}
|
|
1026
1027
|
})
|
|
1027
1028
|
|
|
1029
|
+
// Download updates automatically: saved at once, and a newer Quilt that is already out is fetched now.
|
|
1030
|
+
$('#about-sec [name="autoUpdate"]', root)?.addEventListener('change', async (e) => {
|
|
1031
|
+
const box = e.target
|
|
1032
|
+
try {
|
|
1033
|
+
state.profile = await api('POST', '/api/settings', { autoUpdate: box.checked })
|
|
1034
|
+
if (box.checked) downloadAhead()
|
|
1035
|
+
} catch (err) {
|
|
1036
|
+
box.checked = !box.checked
|
|
1037
|
+
toast(err.message)
|
|
1038
|
+
}
|
|
1039
|
+
})
|
|
1040
|
+
|
|
1028
1041
|
if ($('#agents-sec', root)) bindAgents(root)
|
|
1029
1042
|
|
|
1030
1043
|
const signOut = $('#sign-out', root)
|
|
@@ -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>` : ''}
|
|
@@ -345,7 +351,7 @@ function projectPageHtml (p, view) {
|
|
|
345
351
|
const main = page === 'artifacts' ? artifactsHtml(d)
|
|
346
352
|
: page === 'tasks' ? '<div class="pj-board" data-project-board></div>'
|
|
347
353
|
: page === 'channel' ? '<div class="pj-chanpage" data-project-channel></div>'
|
|
348
|
-
: page === 'connections' ?
|
|
354
|
+
: page === 'connections' ? '<div data-project-connections></div>'
|
|
349
355
|
: codebasesHtml(projectCodebases(d, state.sessions, `person:${state.account?.id}`), { project: p, canAdd: d.access?.access === 'edit' }) +
|
|
350
356
|
projectAgentsHtml(d) + (state.connectionsOn ? appsSectionHtml(appsOf(p.id)) : '')
|
|
351
357
|
return `${sideHtml(p, d, page)}<div class="pj-pmain${page === 'artifacts' ? ' pj-files' : page === 'tasks' ? ' pj-tasks' : page === 'channel' ? ' pj-chat' : ''}">${main}</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) } })
|
|
@@ -472,7 +515,7 @@ export function bindProjectShell (view, { go, rerender, newSessionDialog, joinSe
|
|
|
472
515
|
// The open count beside Tasks follows the board as it changes.
|
|
473
516
|
if (board) mountProjectBoard(board, { d, go, reload, changed: () => { const ct = root.querySelector('[data-page="tasks"] .ct'); if (ct) ct.textContent = projectOpenTasks(state.workspace) } })
|
|
474
517
|
const conns = root.querySelector('[data-project-connections]')
|
|
475
|
-
if (conns) mountConnections(conns, { type: 'workspace', id: p.id, agents: () => ((state.workspace && state.workspace.agents) || []).filter((a) => a.agentId).map((a) => ({ id: a.agentId, name: a.name })) })
|
|
518
|
+
if (conns) mountConnections(conns, { type: 'workspace', id: p.id, page: { title: 'Connections', hint: "Apps this project's agents can use." }, agents: () => ((state.workspace && state.workspace.agents) || []).filter((a) => a.agentId).map((a) => ({ id: a.agentId, name: a.name })) })
|
|
476
519
|
// An agent's switch in this project: one added here keeps its place and changes whether it is invited; one from above gets this project's own setting.
|
|
477
520
|
root.querySelectorAll('[data-agent-here]').forEach((box) => {
|
|
478
521
|
box.onchange = async () => {
|