heyquilt 0.3.154 → 0.3.155
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 +13 -0
- package/bin/quilt.js +4 -0
- package/package.json +1 -1
- package/src/api/audit.js +13 -2
- package/src/api/composio.js +139 -0
- package/src/api/memory-store.js +47 -0
- package/src/api/routes/connections.js +311 -0
- package/src/api/routes/sessions.js +9 -1
- package/src/api/routes/workspaces.js +43 -3
- package/src/api/server.js +14 -3
- package/src/api/supabase-store.js +43 -0
- package/src/app-tools.js +107 -0
- package/src/control.js +28 -0
- package/src/mcp.js +7 -0
- package/src/presence.js +2 -1
- package/src/relay-mcp.js +14 -0
- package/src/server.js +37 -2
- package/src/ui/agent-guide.js +4 -0
- package/src/ui/app.css +572 -2
- package/src/ui/app.js +42 -23
- package/src/ui/board.js +17 -7
- package/src/ui/common.js +2 -0
- package/src/ui/connections.js +215 -0
- package/src/ui/feed.js +23 -8
- package/src/ui/files.js +65 -20
- package/src/ui/home-view.js +170 -0
- package/src/ui/home.js +95 -6
- package/src/ui/loom-model.js +11 -8
- package/src/ui/loom.css +182 -2
- package/src/ui/loom.js +132 -55
- package/src/ui/palette.js +75 -0
- package/src/ui/people-view.js +116 -0
- package/src/ui/session.js +1026 -69
- package/src/ui/signin.js +1 -0
- package/src/ui/workspaces.js +7 -1
- package/src/ui-server.js +76 -4
package/src/ui/app.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Quilt app: boot, live events, home screen, folder picker and invites.
|
|
2
2
|
// The session workspace lives in session.js. Plain ES modules, no build step.
|
|
3
3
|
import { authorOf } from './chat.js'
|
|
4
|
-
import { TOKEN, I, state, $, esc, basename, ago, toast, api, ask, decodeInvite, remember, recall, startDropdowns, avatar, loadAccessTypes, typeOptions, loadingHtml, loadingNote } from './common.js'
|
|
4
|
+
import { TOKEN, I, state, $, esc, basename, ago, toast, api, ask, decodeInvite, remember, recall, startDropdowns, avatar, loadAccessTypes, typeOptions, loadingHtml, loadingNote, COLORS } from './common.js'
|
|
5
5
|
import { renderShell, joinSessionDialog } from './home.js'
|
|
6
6
|
import { mountSession, sessionUpdated, sessionMessage, sessionFeed, sessionFileChanged, sessionLog, sessionUnmount } from './session.js'
|
|
7
7
|
import { quiltMark } from './mark.js'
|
|
8
|
+
import { paletteSource } from './palette.js'
|
|
8
9
|
import { renderSignIn } from './signin.js'
|
|
9
10
|
import { checkRelease, openReleaseNotes } from './releases.js'
|
|
10
11
|
import { loadWorkspaces, openWorkspace, wsIdOf } from './workspaces.js'
|
|
@@ -48,7 +49,10 @@ async function boot () {
|
|
|
48
49
|
state.loaded = true
|
|
49
50
|
await loadWorkspaces()
|
|
50
51
|
// Secrets (secrets.js): the Secrets card and the bar that asks you to allow a people-only one.
|
|
51
|
-
|
|
52
|
+
const features = await api('GET', '/api/features').catch(() => ({}))
|
|
53
|
+
state.secretsOn = !!features.secrets
|
|
54
|
+
// App connections (connections.js): Session settings → Connections, and approvals in the chat.
|
|
55
|
+
state.connectionsOn = !!features.connections
|
|
52
56
|
if (state.secretsOn) watchSecretAsks()
|
|
53
57
|
clearTimeout(waiting)
|
|
54
58
|
const last = recall('view')
|
|
@@ -317,35 +321,50 @@ export function render () {
|
|
|
317
321
|
}
|
|
318
322
|
|
|
319
323
|
export function renderLocked (msg) {
|
|
324
|
+
// The same card as sign-in (signin.js), so the screens before the app look like the app.
|
|
320
325
|
$('#app').innerHTML = `
|
|
321
|
-
<div class="
|
|
322
|
-
<div class="
|
|
323
|
-
<
|
|
326
|
+
<div class="signin"><div class="signin-card">
|
|
327
|
+
<div class="signin-mark">${quiltMark({ word: false })}</div>
|
|
328
|
+
<h1>${msg ? 'Quilt' : 'Open Quilt from its link'}</h1>
|
|
329
|
+
<p class="signin-lead">${esc(msg || 'Open Quilt using the link printed in your terminal by')} ${msg ? '' : '<code>quilt ui</code>.'}</p>
|
|
324
330
|
</div></div>`
|
|
325
331
|
}
|
|
326
332
|
|
|
333
|
+
// ⌘K everywhere (palette.js): sessions, workspaces and what the app can do.
|
|
334
|
+
paletteSource('app', () => [
|
|
335
|
+
...[...state.sessions.values()].map((x) => {
|
|
336
|
+
const n = [x.status.me, ...(x.status.peers || [])].filter((p) => p && p.agent && p.agent.status === 'working').length
|
|
337
|
+
const ws = (state.workspaces || []).find((w) => w.id === x.workspace)
|
|
338
|
+
return { group: 'Sessions', title: x.status.sessionName || basename(x.dir), sub: [n ? `${n} working` : 'Quiet', ws ? ws.name : '', `~/${basename(x.dir)}`].filter(Boolean).join(' · '), icon: I.grid, run: () => go(x.id) }
|
|
339
|
+
}),
|
|
340
|
+
...(state.workspaces || []).map((w) => ({ group: 'Workspaces', title: w.name, sub: 'Its home: charts, sessions, previews', icon: I.home, run: () => go(`ws:${w.id}`) })),
|
|
341
|
+
{ group: 'Actions', title: 'New session…', sub: 'Share a folder', icon: I.plus, run: () => go('home') },
|
|
342
|
+
{ group: 'Actions', title: 'Join a session…', sub: 'With an invite link', icon: I.link, run: () => joinSessionDialog() },
|
|
343
|
+
{ group: 'Actions', title: 'Agents', sub: 'Your agents and their keys', icon: I.bot, run: () => go('agents') },
|
|
344
|
+
{ group: 'Actions', title: 'Account settings', sub: 'Your defaults for new sessions', icon: I.gear, run: () => go('settings') }
|
|
345
|
+
])
|
|
346
|
+
|
|
327
347
|
export function renderTabs () {
|
|
328
348
|
const el = $('#tabs')
|
|
349
|
+
// In a session the rail switches workspaces: the "…" menu keeps only the session's own actions.
|
|
329
350
|
if (!el) return
|
|
330
|
-
|
|
331
|
-
//
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
351
|
+
if (el.closest('#wb-tools')) { el.hidden = true; return }
|
|
352
|
+
// The top dropdown switches workspaces (projects): each one's page, the one this session is in
|
|
353
|
+
// ticked; + makes a new one on Home. A session's own actions stay below it.
|
|
354
|
+
if (state.workspaces == null && !renderTabs.loading) {
|
|
355
|
+
renderTabs.loading = true
|
|
356
|
+
loadWorkspaces().catch(() => {}).finally(() => { renderTabs.loading = false; renderTabs(); if (state.sessions.has(state.view)) sessionUpdated(state.view) })
|
|
357
|
+
}
|
|
358
|
+
const mine = state.sessions.get(state.view)?.workspace
|
|
359
|
+
const wsList = state.workspaces || []
|
|
335
360
|
el.hidden = false
|
|
336
|
-
el.innerHTML = '<div class="pop-label">
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
<span class="
|
|
341
|
-
<span class="grow">${esc(s.status.sessionName || basename(s.dir))}</span>
|
|
342
|
-
${unread && !on ? `<span class="badge">${unread}</span>` : ''}
|
|
361
|
+
el.innerHTML = '<div class="pop-label">Workspaces</div>' + wsList.map((w) => {
|
|
362
|
+
const on = w.id === mine
|
|
363
|
+
return `<button class="pop-item tab${on ? ' on' : ''}" role="menuitem" data-go="ws:${esc(w.id)}"${on ? ' aria-current="true"' : ''}>
|
|
364
|
+
<span class="ws-swatch" style="background:${esc(COLORS[w.color] || COLORS.lilac)}">${esc([...String(w.name || '?')][0].toUpperCase())}</span>
|
|
365
|
+
<span class="grow">${esc(w.name)}</span>${on ? I.check : ''}
|
|
343
366
|
</button>`
|
|
344
|
-
}).join('') +
|
|
345
|
-
<span class="dot off" title="Not open"></span>
|
|
346
|
-
<span class="grow">${esc(basename(r.dir))}</span>
|
|
347
|
-
<span class="hint">${esc(ago(r.lastUsed))}</span>
|
|
348
|
-
</button>`).join('') + '<div class="pop-sep"></div>'
|
|
367
|
+
}).join('') + '<button class="pop-item tab" role="menuitem" data-go="home"><span class="ws-swatch add">' + I.plus + '</span><span class="grow">New workspace</span></button>'
|
|
349
368
|
const here = state.sessions.get(state.view)
|
|
350
369
|
const dot = $('#sess-dot')
|
|
351
370
|
if (dot && here) {
|
|
@@ -356,7 +375,7 @@ export function renderTabs () {
|
|
|
356
375
|
}
|
|
357
376
|
const badge = $('#sess-badge')
|
|
358
377
|
if (badge) {
|
|
359
|
-
const n =
|
|
378
|
+
const n = [...state.sessions.values()].filter((s) => s.id !== state.view).reduce((a, s) => a + (s.status.unread || 0), 0)
|
|
360
379
|
badge.hidden = !n
|
|
361
380
|
badge.textContent = n
|
|
362
381
|
}
|
package/src/ui/board.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The session task board: four columns. Task ids and titles come from the
|
|
2
2
|
// shared room, so every string is escaped. Column ids match src/tasks.js.
|
|
3
|
-
import { I, esc, ago, colorFor } from './common.js'
|
|
3
|
+
import { I, esc, ago, colorFor, avatar } from './common.js'
|
|
4
|
+
import { toolLabel } from './tool-logo.js'
|
|
4
5
|
import { markdown } from './feed.js'
|
|
5
6
|
import { cronToText } from './schedule.js'
|
|
6
7
|
|
|
@@ -25,7 +26,7 @@ const COLUMNS = [
|
|
|
25
26
|
* `archived` shows the archived tasks in place of the columns. `show` keeps only some tasks:
|
|
26
27
|
* '' everyone's, 'none' unassigned ones, `p:name` a person's, `a:name` that person's AI's.
|
|
27
28
|
*/
|
|
28
|
-
export function renderBoard (tasks, me, people = [], assignTo = '', { archived = false, show = '', closedGroups = [] } = {}) {
|
|
29
|
+
export function renderBoard (tasks, me, people = [], assignTo = '', { archived = false, show = '', closedGroups = [], open = new Set() } = {}) {
|
|
29
30
|
const every = (Array.isArray(tasks) ? tasks : []).filter(Boolean)
|
|
30
31
|
const all = every.filter((t) => showsTask(t, show))
|
|
31
32
|
const list = all.filter((t) => !t.archived)
|
|
@@ -34,7 +35,7 @@ export function renderBoard (tasks, me, people = [], assignTo = '', { archived =
|
|
|
34
35
|
const cols = COLUMNS.map((col) => {
|
|
35
36
|
const cards = list.filter((t) => t && t.column === col.id)
|
|
36
37
|
const body = cards.length
|
|
37
|
-
? cards.map((t) => card(t, col, me, people)).join('')
|
|
38
|
+
? cards.map((t) => card(t, col, me, people, open.has(t.id))).join('')
|
|
38
39
|
: `<p class="board-empty">${col.id === 'todo' ? 'Nothing here yet.' : 'Nothing here.'}</p>`
|
|
39
40
|
const n = cards.length
|
|
40
41
|
// When the board is too narrow for every column, session.js folds some to a strip:
|
|
@@ -77,7 +78,7 @@ export function renderBoard (tasks, me, people = [], assignTo = '', { archived =
|
|
|
77
78
|
|
|
78
79
|
// Folding (session.js lays it out): open columns are BOARD_COL wide at least, a folded
|
|
79
80
|
// one is a BOARD_STRIP-wide strip, BOARD_GAP apart. Match .board-col and .board-cols in app.css.
|
|
80
|
-
export const BOARD_COL =
|
|
81
|
+
export const BOARD_COL = 240
|
|
81
82
|
export const BOARD_STRIP = 44
|
|
82
83
|
export const BOARD_GAP = 10
|
|
83
84
|
// Before you open or fold one yourself, the work in flight stays open first.
|
|
@@ -444,7 +445,7 @@ export function matchesSearch (text, query) {
|
|
|
444
445
|
return words.every((w) => text.includes(w))
|
|
445
446
|
}
|
|
446
447
|
|
|
447
|
-
function card (t, col, me, people) {
|
|
448
|
+
function card (t, col, me, people, open = false) {
|
|
448
449
|
const who = t.by === me ? 'You' : (t.by || '')
|
|
449
450
|
const mine = t.assignee === me && !t.forAi ? ' mine' : t.assignee === me && t.forAi ? ' mine-ai' : ''
|
|
450
451
|
const moves = col.moves.map((m) =>
|
|
@@ -452,16 +453,24 @@ function card (t, col, me, people) {
|
|
|
452
453
|
).join('')
|
|
453
454
|
// An assigned task wears its owner's colour as a corner piece (app.css .task.owned).
|
|
454
455
|
const owner = t.assignee ?` owned" style="--c:${esc(colorFor(t.assignee, people.find((p) => p.name === t.assignee)?.color))}` : ''
|
|
455
|
-
|
|
456
|
+
// Who has it, and their AI on it now (dm06): "Cursor working · 14m".
|
|
457
|
+
const holder = t.assignee ? people.find((p) => p.name === t.assignee) : null
|
|
458
|
+
const whoHtml = t.assignee ? `<div class="task-who">${avatar(t.assignee, holder?.color)}<span>${esc(t.forAi ? assigneeText(t, me).replace(/^your /, 'Your ') : t.assignee === me ? 'You' : t.assignee)}</span></div>` : ''
|
|
459
|
+
const live = t.column === 'doing' && holder && holder.working && (t.forAi || holder.agent)
|
|
460
|
+
? `<div class="task-live"><span class="pulse"></span>${esc(holder.agent ? 'working' : `${toolLabel(t.tool || holder.tool) || 'AI'} working`)}${holder.since ? ` · ${esc(ago(holder.since))}` : ''}</div>`
|
|
461
|
+
: ''
|
|
462
|
+
return `<article class="task${mine}${owner}${open ? ' open' : ''}" draggable="true" data-task="${esc(t.id)}" data-search="${esc(searchText(t, me))}">
|
|
456
463
|
<div class="task-main">
|
|
457
464
|
<div class="task-tools">
|
|
458
465
|
${notesButton(t)}
|
|
459
466
|
${recurButton(t)}
|
|
460
467
|
<button type="button" class="task-icon" data-task-more title="More" aria-label="More for ${esc(t.title)}" aria-haspopup="menu" aria-expanded="false">${I.more}</button>
|
|
461
468
|
</div>
|
|
462
|
-
<p class="task-title" title="Click to rename">${esc(t.title)}</p>
|
|
469
|
+
<p class="task-title" title="${open ? 'Click to rename' : 'Click to open'}">${esc(t.title)}</p>
|
|
463
470
|
</div>
|
|
471
|
+
${whoHtml}${live}
|
|
464
472
|
${noPickupHtml(t)}
|
|
473
|
+
<div class="task-details">
|
|
465
474
|
<select class="task-assign" aria-label="Assign ${esc(t.title)}">${assignOptions(t, me, people)}</select>
|
|
466
475
|
${recurHtml(t)}
|
|
467
476
|
${filesHtml(t.files)}
|
|
@@ -474,5 +483,6 @@ function card (t, col, me, people) {
|
|
|
474
483
|
<span class="task-by">${esc(who)}</span>
|
|
475
484
|
<div class="task-moves">${moves}</div>
|
|
476
485
|
</div>
|
|
486
|
+
</div>
|
|
477
487
|
</article>`
|
|
478
488
|
}
|
package/src/ui/common.js
CHANGED
|
@@ -49,6 +49,7 @@ export const I = {
|
|
|
49
49
|
// A box: someone's unfinished work on a file (boxes.js). Unpack: the same box, opened upwards.
|
|
50
50
|
box: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8 12 3 3 8v8l9 5 9-5z"/><path d="m3 8 9 5 9-5"/><path d="M12 13v8"/></svg>',
|
|
51
51
|
unpack: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8 12 3 3 8v8l9 5 9-5z"/><path d="M12 13V7"/><path d="m9 10 3-3 3 3"/></svg>',
|
|
52
|
+
plug: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 3v5M15 3v5M6 8h12v3a6 6 0 0 1-12 0zM12 17v4"/></svg>',
|
|
52
53
|
lock: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>',
|
|
53
54
|
down: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>',
|
|
54
55
|
check: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>',
|
|
@@ -100,6 +101,7 @@ export const state = {
|
|
|
100
101
|
addingWorkspace: false, // the Add workspace card is showing its form
|
|
101
102
|
workspacesOn: false, // the accounts API has workspaces on
|
|
102
103
|
secretsOn: false, // the accounts API has secrets on (the vault is set up)
|
|
104
|
+
connectionsOn: false, // the accounts API has app connections on (Composio's key is set)
|
|
103
105
|
workspace: null, // the open workspace page's data
|
|
104
106
|
spaceFilter: 'all', // the home grid's Personal / org switch
|
|
105
107
|
filesView: { folder: '', picked: null, mode: 'tiles' }, // the All files view: folder shown, file previewed, tiles or list
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// The Connections card in the app (Session settings → Connections, and the header's Connections
|
|
2
|
+
// button): apps people connect for a session, workspace or team through Composio, which keeps the
|
|
3
|
+
// sign-ins (plans/app-connections.md). Agents use them with quilt_apps / quilt_app_tools /
|
|
4
|
+
// quilt_app_call. Also the approval card an app action waiting for a person draws in the chat.
|
|
5
|
+
import { api, esc, toast, ago, I } from './common.js'
|
|
6
|
+
import { SEARCH_ICON } from './quiltview.js'
|
|
7
|
+
|
|
8
|
+
const views = new Map() // `${type}:${id}` -> the last view, so a redraw shows it at once
|
|
9
|
+
const urlOf = (type, id, rest = '') => `/api/connections/${type}/${encodeURIComponent(id)}${rest}`
|
|
10
|
+
const LEVEL = { session: 'this session', workspace: 'the workspace', org: 'the team' }
|
|
11
|
+
const STATUS = { active: 'Connected', pending: 'Waiting for sign-in', failed: 'Didn\'t connect' }
|
|
12
|
+
|
|
13
|
+
const logoHtml = (a) => a.logo
|
|
14
|
+
? `<img class="cn-logo" src="${esc(a.logo)}" alt="" loading="lazy" referrerpolicy="no-referrer">`
|
|
15
|
+
: `<span class="cn-logo none">${esc(String(a.name || a.app || a.slug || '?').slice(0, 1).toUpperCase())}</span>`
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Draws the card into `root` for one scope ({ type, id }: a session's room, a workspace's id, a
|
|
19
|
+
* team's slug). Answers { refresh, destroy }.
|
|
20
|
+
*/
|
|
21
|
+
export function mountConnections (root, { type, id, page = false, sessions = [], callsRoom = null, me = '' }) {
|
|
22
|
+
const ui = { search: '', apps: null, appsFor: null, more: false, busy: '', error: '', calls: null, confirm: null }
|
|
23
|
+
let view = views.get(`${type}:${id}`) || null
|
|
24
|
+
let alive = true
|
|
25
|
+
let poll = null
|
|
26
|
+
let searchTimer = null
|
|
27
|
+
|
|
28
|
+
// The dm06 connections manager: a card per connected app, then apps to add (search, or the most used).
|
|
29
|
+
function cardHtml (c, own) {
|
|
30
|
+
const what = c.status === 'pending' ? 'Waiting for sign-in in your browser' : c.status === 'failed' ? 'Didn’t connect: connect it again' : c.who === 'people' ? 'People and their own AIs only' : 'People and agents can use it'
|
|
31
|
+
const where = own ? LEVEL[type] : `${LEVEL[c.level] || c.level}${c.levelName ? ` (${c.levelName})` : ''}`
|
|
32
|
+
const sw = c.status === 'active' || page
|
|
33
|
+
? `<label class="cn-sw" title="${c.who === 'people' ? 'Agents can’t use it: switch on to let them' : 'Agents can use it: switch off to keep it to people'}"><input type="checkbox" ${own && c.mayChange && c.status === 'active' ? `data-who-toggle="${esc(c.id)}"` : 'disabled'} ${c.status === 'active' && c.who === 'all' ? 'checked' : ''}><i></i></label>`
|
|
34
|
+
: `<span class="cn-state ${esc(c.status)}">${esc(STATUS[c.status] || c.status)}</span>`
|
|
35
|
+
const manage = own && c.mayChange
|
|
36
|
+
? (ui.confirm === c.id
|
|
37
|
+
? ` · <span class="cn-confirm">Remove it? <button type="button" class="cn-link danger" data-remove="${esc(c.id)}">Remove</button> <button type="button" class="cn-link" data-cancel>Keep</button></span>`
|
|
38
|
+
: ` · <button type="button" class="cn-link" data-ask-remove="${esc(c.id)}">Remove</button>`)
|
|
39
|
+
: ''
|
|
40
|
+
// On the page (dm06): the sessions it reaches as chips, and "Connected by you · Manage".
|
|
41
|
+
const chips = page ? (own ? (type === 'workspace' ? sessions : [sessions[0] || LEVEL[type]]) : [c.levelName || LEVEL[c.level] || c.level]).filter(Boolean) : [where]
|
|
42
|
+
const by = page && me && c.by === me ? 'you' : c.by
|
|
43
|
+
const pageManage = own && c.mayChange
|
|
44
|
+
? (ui.confirm === c.id
|
|
45
|
+
? ` · <span class="cn-confirm">Remove it? <button type="button" class="cn-link danger" data-remove="${esc(c.id)}">Remove</button> <button type="button" class="cn-link" data-cancel>Keep</button></span>`
|
|
46
|
+
: ` · <button type="button" class="cn-link" data-ask-remove="${esc(c.id)}">Manage</button>`)
|
|
47
|
+
: ''
|
|
48
|
+
return `<div class="cn-card${c.status === 'active' && c.who === 'all' ? '' : ' off'}">${logoHtml(c)}<div class="cn-t"><b>${esc(c.name)}</b><small>${esc(what)}</small></div>${sw}
|
|
49
|
+
<div class="cn-where">${chips.map((x) => `<span>${esc(x)}</span>`).join('')}</div><div class="cn-by">Connected by ${esc(by)}${page ? pageManage : ` · ${esc(ago(c.createdAt))}${manage}`}</div></div>`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function suggestHtml (a, connected) {
|
|
53
|
+
const busy = ui.busy === a.slug
|
|
54
|
+
return `<div class="cn-sug">${logoHtml(a)}<b title="${esc(a.description || a.name)}">${esc(a.name)}</b><button type="button" class="btn sm" data-connect="${esc(a.slug)}"${busy ? ' disabled' : ''}>${busy ? 'Opening…' : connected ? 'Add another' : 'Connect'}</button></div>`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function callsHtml () {
|
|
58
|
+
if (!ui.calls || !ui.calls.length) return ''
|
|
59
|
+
const word = { waiting: 'waiting for approval', approved: 'approved', declined: 'declined', ran: 'ran', failed: 'failed' }
|
|
60
|
+
return `<div class="cn-subh">What agents did in apps</div><div class="cn-calls">${ui.calls.slice(0, 20).map((c) => `<div class="cn-call">
|
|
61
|
+
<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>`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function draw () {
|
|
65
|
+
if (!alive) return
|
|
66
|
+
const had = root.contains(document.activeElement) && document.activeElement.matches('[data-search]')
|
|
67
|
+
if (ui.error && !view) { root.innerHTML = `<div class="cn"><p class="hint">${esc(ui.error)}</p></div>`; return }
|
|
68
|
+
if (!view) { root.innerHTML = '<div class="cn"><p class="hint">Loading connections…</p></div>'; return }
|
|
69
|
+
const own = view.connections || []
|
|
70
|
+
const inherited = view.inherited || []
|
|
71
|
+
const ownApps = new Set(own.map((c) => c.app))
|
|
72
|
+
const apps = ui.apps || []
|
|
73
|
+
const picks = ui.search ? apps : apps.filter((a) => !ownApps.has(a.slug) && !inherited.some((c) => c.app === a.slug)).slice(0, ui.more ? 60 : 8)
|
|
74
|
+
const count = own.filter((c) => c.status === 'active').length + inherited.length
|
|
75
|
+
const lead = page
|
|
76
|
+
? (type === 'workspace' ? 'Apps your sessions and their AIs can use, connected once for the whole workspace through Composio' : 'Apps this session and its AIs can use, connected through Composio')
|
|
77
|
+
: `Apps ${esc(LEVEL[type] || type)}’s AIs can use. They read at once and ask a person before they send, change or delete anything; each sign-in stays with Composio, never in Quilt.`
|
|
78
|
+
root.innerHTML = `<div class="cn${page ? ' cn-page' : ''}">
|
|
79
|
+
<div class="cn-h"><div>${page ? `<h2>Connections <i>${count}</i></h2>` : `<h3>Connections <i>${count}</i></h3>`}<small>${lead}</small></div>
|
|
80
|
+
${view.canManage ? `<label class="cn-src">${SEARCH_ICON}<input data-search placeholder="Search thousands of apps" value="${esc(ui.search)}" aria-label="Search apps"></label><button type="button" class="btn primary" data-add-focus>${I.plus}<span>Add a connection</span></button>` : ''}</div>
|
|
81
|
+
${own.length || inherited.length ? `<div class="cn-grid">${own.map((c) => cardHtml(c, true)).join('')}${inherited.map((c) => cardHtml(c, false)).join('')}</div>` : '<p class="hint cn-none">Nothing connected yet: pick an app below, and agents can use it once you sign in.</p>'}
|
|
82
|
+
${view.canManage ? `<div class="cn-subh">${ui.search ? `Apps matching “${esc(ui.search)}”` : `Suggested for ${esc(view.scope.name || LEVEL[type])}`}</div>
|
|
83
|
+
${ui.apps === null ? '<p class="hint">Loading apps…</p>' : picks.length ? `<div class="cn-sugs">${picks.map((a) => suggestHtml(a, ownApps.has(a.slug))).join('')}</div>` : `<p class="hint">No app matches “${esc(ui.search)}”.</p>`}
|
|
84
|
+
${!ui.search && !ui.more && apps.length > 8 ? '<button type="button" class="btn sm ghost cn-more" data-more>More apps</button>' : ''}` : ''}
|
|
85
|
+
${callsHtml()}
|
|
86
|
+
</div>`
|
|
87
|
+
if (had) { const s = root.querySelector('[data-search]'); s.focus(); s.setSelectionRange(s.value.length, s.value.length) }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function load () {
|
|
91
|
+
try {
|
|
92
|
+
view = await api('GET', urlOf(type, id))
|
|
93
|
+
views.set(`${type}:${id}`, view)
|
|
94
|
+
ui.error = ''
|
|
95
|
+
} catch (err) {
|
|
96
|
+
ui.error = err.status === 503 ? 'App connections are not switched on for your account\'s server yet.' : err.message
|
|
97
|
+
view = null
|
|
98
|
+
}
|
|
99
|
+
const room = callsRoom || (type === 'session' ? id : null)
|
|
100
|
+
if (room) ui.calls = (await api('GET', `/api/app-calls/${encodeURIComponent(room)}`).catch(() => ({ calls: null }))).calls
|
|
101
|
+
draw()
|
|
102
|
+
// A connection waiting for its sign-in is looked at again until it lands.
|
|
103
|
+
clearTimeout(poll)
|
|
104
|
+
if (alive && view && (view.connections || []).some((c) => c.status === 'pending' && Date.now() - c.createdAt < 10 * 60 * 1000)) poll = setTimeout(load, 3000)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function loadApps () {
|
|
108
|
+
const q = ui.search
|
|
109
|
+
try {
|
|
110
|
+
const r = await api('GET', `/api/connections/apps?search=${encodeURIComponent(q)}&limit=${q ? 40 : 60}`)
|
|
111
|
+
if (q !== ui.search) return
|
|
112
|
+
ui.apps = r.apps || []
|
|
113
|
+
} catch (err) { ui.apps = []; if (err.status !== 503) toast(err.message) }
|
|
114
|
+
draw()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
root.addEventListener('input', (e) => {
|
|
118
|
+
if (!e.target.matches('[data-search]')) return
|
|
119
|
+
ui.search = e.target.value.trim()
|
|
120
|
+
clearTimeout(searchTimer)
|
|
121
|
+
searchTimer = setTimeout(loadApps, 250)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
root.addEventListener('change', async (e) => {
|
|
125
|
+
const t = e.target.closest('[data-who-toggle]')
|
|
126
|
+
if (!t) return
|
|
127
|
+
try { await api('PATCH', urlOf(type, id, `/${t.dataset.whoToggle}`), { who: t.checked ? 'all' : 'people' }); load() } catch (err) { toast(err.message); load() }
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
root.addEventListener('click', async (e) => {
|
|
131
|
+
const c = e.target.closest('[data-connect]')
|
|
132
|
+
if (c) {
|
|
133
|
+
ui.busy = c.dataset.connect
|
|
134
|
+
draw()
|
|
135
|
+
try {
|
|
136
|
+
const r = await api('POST', urlOf(type, id), { app: c.dataset.connect })
|
|
137
|
+
window.open(r.url, '_blank')
|
|
138
|
+
toast(`Sign in to ${r.connection.name} in your browser.`)
|
|
139
|
+
} catch (err) { toast(err.message) }
|
|
140
|
+
ui.busy = ''
|
|
141
|
+
load()
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
const ask = e.target.closest('[data-ask-remove]')
|
|
145
|
+
if (ask) { ui.confirm = ask.dataset.askRemove; draw(); return }
|
|
146
|
+
if (e.target.closest('[data-cancel]')) { ui.confirm = null; draw(); return }
|
|
147
|
+
const rm = e.target.closest('[data-remove]')
|
|
148
|
+
if (rm) {
|
|
149
|
+
try { await api('DELETE', urlOf(type, id, `/${rm.dataset.remove}`)); toast('Removed.') } catch (err) { toast(err.message) }
|
|
150
|
+
ui.confirm = null
|
|
151
|
+
load()
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
if (e.target.closest('[data-more]')) { ui.more = true; draw() }
|
|
155
|
+
if (e.target.closest('[data-add-focus]')) root.querySelector('[data-search]')?.focus()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
draw()
|
|
159
|
+
load()
|
|
160
|
+
loadApps()
|
|
161
|
+
return {
|
|
162
|
+
refresh: load,
|
|
163
|
+
destroy () { alive = false; clearTimeout(poll); clearTimeout(searchTimer) }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ------------------------------------------------------------------ approvals in the chat --
|
|
168
|
+
|
|
169
|
+
const decided = new Map() // approval id -> what this window says once it answered one here
|
|
170
|
+
let known = { room: null, calls: new Map(), at: 0, mayDecide: false } // the session's recent app calls, by id
|
|
171
|
+
|
|
172
|
+
/** What a call came to, in words: "Approved by Mo · it ran", "Declined by Mo", … */
|
|
173
|
+
function outcome (c) {
|
|
174
|
+
if (!c) return 'Checking…'
|
|
175
|
+
if (c.state === 'waiting') return 'Waiting for approval'
|
|
176
|
+
if (c.state === 'declined') return `Declined by ${c.decidedBy || 'a person'}`
|
|
177
|
+
const by = `Approved by ${c.decidedBy || 'a person'}`
|
|
178
|
+
return c.state === 'ran' ? `${by} · it ran` : c.state === 'failed' ? `${by} · it failed${c.error ? `: ${c.error}` : ''}` : `${by} · running`
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The card under a chat line that asks for an app action's approval. */
|
|
182
|
+
export function approvalCardHtml (m, room) {
|
|
183
|
+
const c = known.room === room ? known.calls.get(m.approval) : null
|
|
184
|
+
const open = !!c && c.state === 'waiting' && known.mayDecide && !decided.has(m.approval)
|
|
185
|
+
const what = decided.get(m.approval) || (known.room === room && known.at && !c ? 'Answered' : outcome(c))
|
|
186
|
+
const actions = open ? `<span class="app-approval-acts"><button class="btn sm" data-approve="${esc(m.approval)}">Approve</button><button class="btn sm ghost" data-decline="${esc(m.approval)}">Decline</button></span>` : ''
|
|
187
|
+
return `<div class="app-approval${open ? ' open' : ''}" data-approval="${esc(m.approval)}"><span class="app-approval-ico">${open ? I.lock : I.check}</span><span class="app-approval-what">${esc(what)}</span>${actions}</div>`
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The session's recent app calls, so each card shows where it stands: looked up when the chat draws (at most every 3 s). */
|
|
191
|
+
export async function refreshApprovals (room, redraw) {
|
|
192
|
+
if (known.room === room && Date.now() - known.at < 3000) return
|
|
193
|
+
known.at = Date.now()
|
|
194
|
+
try {
|
|
195
|
+
const r = await api('GET', `/api/app-calls/${encodeURIComponent(room)}`)
|
|
196
|
+
const calls = new Map((r.calls || []).map((c) => [c.id, c]))
|
|
197
|
+
const sig = (m) => [...m.values()].map((c) => `${c.id}:${c.state}`).join(',')
|
|
198
|
+
const changed = known.room !== room || sig(calls) !== sig(known.calls)
|
|
199
|
+
known = { room, calls, at: Date.now(), mayDecide: !!r.mayDecide }
|
|
200
|
+
if (changed) redraw()
|
|
201
|
+
} catch { known = { room, calls: new Map(), at: Date.now(), mayDecide: false } }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Approve or Decline on a card: runs the action once (approve) and says what came of it. */
|
|
205
|
+
export async function answerApproval (room, id, allow, redraw) {
|
|
206
|
+
decided.set(id, allow ? 'Approving…' : 'Declining…')
|
|
207
|
+
redraw()
|
|
208
|
+
try {
|
|
209
|
+
await api('POST', `/api/app-calls/${encodeURIComponent(room)}/${id}`, { allow })
|
|
210
|
+
decided.delete(id)
|
|
211
|
+
} catch (err) { decided.set(id, err.message) }
|
|
212
|
+
known.at = 0
|
|
213
|
+
await refreshApprovals(room, redraw)
|
|
214
|
+
redraw()
|
|
215
|
+
}
|
package/src/ui/feed.js
CHANGED
|
@@ -3,7 +3,16 @@
|
|
|
3
3
|
// session, a Cursor chat, ...) is its own conversation, picked from a strip
|
|
4
4
|
// at the top; the feed follows the newest one until the reader picks another.
|
|
5
5
|
import { esc, clock, avatar, I } from './common.js'
|
|
6
|
-
import { toolLogo } from './tool-logo.js'
|
|
6
|
+
import { toolLogo, toolLabel } from './tool-logo.js'
|
|
7
|
+
|
|
8
|
+
// How long ago a thread was last active, as its chip says it (dm06): "2h", "yesterday", "3d".
|
|
9
|
+
const since = (ts) => {
|
|
10
|
+
const m = Math.max(0, Math.round((Date.now() - ts) / 60000))
|
|
11
|
+
if (m < 60) return `${Math.max(1, m)}m`
|
|
12
|
+
if (m < 24 * 60) return `${Math.round(m / 60)}h`
|
|
13
|
+
const d = Math.round(m / (24 * 60))
|
|
14
|
+
return d === 1 ? 'yesterday' : `${d}d`
|
|
15
|
+
}
|
|
7
16
|
import { conversations, pickConversation } from './feed-convs.js'
|
|
8
17
|
|
|
9
18
|
/**
|
|
@@ -11,7 +20,7 @@ import { conversations, pickConversation } from './feed-convs.js'
|
|
|
11
20
|
* scroll position unless they were already at the bottom. `convSel` is the
|
|
12
21
|
* pinned conversation id (undefined: follow the newest).
|
|
13
22
|
*/
|
|
14
|
-
export function renderFeed (el, { entries, person, isMe, color, agent, online, convSel }) {
|
|
23
|
+
export function renderFeed (el, { entries, person, isMe, color, agent, online, convSel, head = false, tool = '' }) {
|
|
15
24
|
const scroller = el.querySelector('.feed-scroll')
|
|
16
25
|
const atBottom = !scroller || scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 60
|
|
17
26
|
const prevCount = scroller ? Number(scroller.dataset.count || 0) : 0
|
|
@@ -51,7 +60,8 @@ export function renderFeed (el, { entries, person, isMe, color, agent, online, c
|
|
|
51
60
|
let actions = []
|
|
52
61
|
const flush = () => {
|
|
53
62
|
if (!actions.length) return
|
|
54
|
-
|
|
63
|
+
// "Read src/pages/pricing.tsx": the verb in words, what it read or ran as code (dm06).
|
|
64
|
+
parts.push(`<div class="f-actions">${actions.map((a) => { const m = /^(\S+)\s+(.+)$/s.exec(a.text || ''); return `<div class="f-action"><span class="chev">›</span><span>${m ? `${esc(m[1])} <code>${esc(m[2])}</code>` : esc(a.text)}</span></div>` }).join('')}</div>`)
|
|
55
65
|
actions = []
|
|
56
66
|
}
|
|
57
67
|
for (const e of shown) {
|
|
@@ -67,18 +77,19 @@ export function renderFeed (el, { entries, person, isMe, color, agent, online, c
|
|
|
67
77
|
<div class="head"><b>${esc(who)}</b><span>${esc(clock(e.ts))}</span>${e.summary ? '<span class="tag summary" title="Summarized before sharing">summary</span>' : ''}</div>
|
|
68
78
|
<div class="bubble"><div class="text">${esc(visiblePrompt(e.text))}</div></div></div></div>`)
|
|
69
79
|
} else if (e.kind === 'reply') {
|
|
70
|
-
parts.push(`<div class="f-reply"><div class="head"><span class="ai-badge">${toolLogo(e.tool)}</span><span>${esc(clock(e.ts))}</span>${e.summary ? '<span class="tag summary" title="Summarized before sharing">summary</span>' : ''}</div>
|
|
80
|
+
parts.push(`<div class="f-reply"><div class="head"><span class="ai-badge">${toolLogo(e.tool)}</span><b>${esc(toolLabel(e.tool || tool) || 'AI')}</b><span>${esc(clock(e.ts))}</span>${e.summary ? '<span class="tag summary" title="Summarized before sharing">summary</span>' : ''}</div>
|
|
71
81
|
<div class="md">${markdown(e.text)}</div></div>`)
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
flush()
|
|
75
85
|
if (!sharing) parts.push(`<div class="feed-note">${esc(isMe ? 'You paused sharing' : `${person} paused sharing`)}</div>`)
|
|
76
86
|
body = parts.join('')
|
|
77
|
-
|
|
87
|
+
// The person's view shows their threads as chips even when there is one (dm06); the AI tab only when there are several.
|
|
88
|
+
if (convs.length > 1 || (head && convs.length)) {
|
|
78
89
|
strip = `<div class="feed-convs" role="tablist" aria-label="Conversations">${convs.map((c, i) => {
|
|
79
90
|
const on = c.conv === conv
|
|
80
91
|
const live = working && i === 0
|
|
81
|
-
return `<button class="conv-chip${on ? ' on' : ''}" role="tab" aria-selected="${on}" data-conv="${esc(c.conv)}" title="${esc(c.tool || '')}${c.tool ? ' · ' : ''}${esc(clock(c.ts))}">${live ? '<span class="pulse"></span>' : ''
|
|
92
|
+
return `<button class="conv-chip${on ? ' on' : ''}${live ? ' live' : ''}" role="tab" aria-selected="${on}" data-conv="${esc(c.conv)}" title="${esc(c.tool || '')}${c.tool ? ' · ' : ''}${esc(clock(c.ts))}">${live ? '<span class="pulse"></span>' : head ? '' : `<span class="tool">${toolLogo(c.tool)}</span>`}<span class="nm">${esc(c.label)}</span>${!live && head ? `<i class="ago">${esc(since(c.ts))}</i>` : ''}</button>`
|
|
82
93
|
}).join('')}</div>`
|
|
83
94
|
}
|
|
84
95
|
shownConv = conv
|
|
@@ -86,10 +97,14 @@ export function renderFeed (el, { entries, person, isMe, color, agent, online, c
|
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
const workingHtml = working && liveShown
|
|
89
|
-
? `<div class="f-working"><span class="dots"><i></i><i></i><i></i></span>${esc(isMe ? 'Your AI is working…' : `${whose} AI is working…`)}</div>`
|
|
100
|
+
? `<div class="f-working"><span class="dots"><i></i><i></i><i></i></span>${esc(tool || agent?.tool ? `${toolLabel(tool || agent.tool)} is working…` : isMe ? 'Your AI is working…' : `${whose} AI is working…`)}</div>`
|
|
90
101
|
: ''
|
|
91
102
|
|
|
92
|
-
|
|
103
|
+
// The person's view (dm06): back to the loom, who, their threads as chips, and their direct messages.
|
|
104
|
+
const top = head
|
|
105
|
+
? `<div class="pv-head" style="--c:${esc(color || '')}"><button type="button" class="pv-back" data-pv-back title="Back to everyone" aria-label="Back to everyone">${I.arrowLeft}</button>${avatar(person, color, online)}<div class="pv-who"><b>${esc(who)}</b><small>${esc(tool || (agent && agent.tool) || '')}</small></div>${strip}<span class="pv-sp"></span>${isMe ? '' : `<button type="button" class="btn sm pv-dm" data-pv-dm="${esc(person)}">${I.chat}<span>Messages with ${esc(person)}</span></button>`}</div>`
|
|
106
|
+
: strip
|
|
107
|
+
el.innerHTML = `${top}<div class="feed-scroll" data-count="${entries.length}" data-conv="${esc(shownConv)}"><div class="feed">${body}${workingHtml}</div></div>
|
|
93
108
|
<button class="btn sm new-activity" hidden>${I.down}<span>New activity</span></button>`
|
|
94
109
|
const s = el.querySelector('.feed-scroll')
|
|
95
110
|
const jump = el.querySelector('.new-activity')
|